t = int(input()) for i in range(t) n,k = map(int,input().split()) li = [] for x in range(n): for y in range(n): for z in range(n): if (x + y + z == n) and (0 < z <= y <= x) and (abs(x - y - z) > k): li.append([x,y,z])
Оригинал: “https://dev.to/ritikbhola/how-to-reduce-complexity-in-python-for-the-following-code-34n0”