Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N, K = map(int, input().split())
    if N < K:
        print(-1)
    elif K == N:
        edges = [(N, 1)]
        for i in range(1, N):
            edges.append((i, i + 1))
    elif K == N - 1:
        edges = [(N, 1)]
        for i in range(1, N):
            edges.append((i, i + 1))
        edges.append((2, N))
    else:
        cnt = 0
        edges = []
        for i in range(1, N + 1):
            for j in range(i + 1, N + 1):
                if i == 1 and cnt < K:
                    cnt += 1
                    continue
                else:
                    edges.append((i, j))

    print(len(edges))
    for a, b in edges:
        print(a, b)


if __name__ == "__main__":
    main()


Fixed submission:
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N, K = map(int, input().split())
    if (N - 1) * (N - 2) // 2 < K:
        print(-1)
        return
    else:
        edges = set()
        for i in range(2, N + 1):
            edges.add((1, i))

        cnt = (N - 1) * (N - 2) // 2
        for i in range(1, N):
            for j in range(i, N + 1):
                if i == j:
                    continue

                if cnt == K:
                    print(len(edges))
                    for a, b in edges:
                        print(a, b)
                    return

                if (i, j) not in edges:
                    cnt -= 1
                    edges.add((i, j))

        print(len(edges))
        for a, b in edges:
            print(a, b)
        return


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
import sys
from collections import defaultdict

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(input())
    X = []
    Y = []
    for _ in range(N):
        x, y = map(int, input().split())
        X.append(x)
        Y.append(y)

    cnt = defaultdict(int)
    for i in range(N):
        for j in range(N):
            if i == j:
                continue

            dx = X[j] - X[i]
            dy = Y[j] - Y[i]
            cnt[(dx, dy)] += 1

    cnt = sorted(cnt.items(), key=lambda x: x[1], reverse=True)
    ans = N - cnt[0][1]
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    N = int(input())
    if N == 1:
        print(1)
        return
    xy = []
    for _ in range(N):
        x, y = map(int, input().split())
        xy.append((x, y))

    d = {}
    for i in range(N):
        tmp = set()
        for j in range(N):
            if i == j:
                continue
            dx = xy[i][0] - xy[j][0]
            dy = xy[i][1] - xy[j][1]

            if (dx, dy) in tmp:
                continue
            if (dx, dy) not in d:
                d[(dx, dy)] = 1
            else:
                d[(dx, dy)] += 1
            tmp.add((dx, dy))

    d = sorted(d.items(), key=lambda x: x[1], reverse=True)
    cnt = d[0][1]
    print(N - cnt)

main()

Buggy python submission (verdict: Runtime Error):
N = int(input())
xy = []
for _ in range(N):
    x, y = map(int, input().split())
    xy.append((x, y))

d = {}
for i in range(N):
    tmp = set()
    for j in range(N):
        if i == j:
            continue
        dx = xy[i][0] - xy[j][0]
        dy = xy[i][1] - xy[j][1]

        if (dx, dy) in tmp:
            continue
        if (dx, dy) not in d:
            d[(dx, dy)] = 1
        else:
            d[(dx, dy)] += 1
        tmp.add((dx, dy))

d = sorted(d.items(), key=lambda x: x[1], reverse=True)
cnt = d[0][1]
print(N - cnt)


Fixed submission:
def main():
    N = int(input())
    if N == 1:
        print(1)
        return
    xy = []
    for _ in range(N):
        x, y = map(int, input().split())
        xy.append((x, y))

    d = {}
    for i in range(N):
        tmp = set()
        for j in range(N):
            if i == j:
                continue
            dx = xy[i][0] - xy[j][0]
            dy = xy[i][1] - xy[j][1]

            if (dx, dy) in tmp:
                continue
            if (dx, dy) not in d:
                d[(dx, dy)] = 1
            else:
                d[(dx, dy)] += 1
            tmp.add((dx, dy))

    d = sorted(d.items(), key=lambda x: x[1], reverse=True)
    cnt = d[0][1]
    print(N - cnt)

main()
Buggy python submission (verdict: Runtime Error):
import sys
import copy
from collections import deque

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()

    if A[0] >= 0:
        ans = sum(A[1:]) - A[0]
        plus = copy.deepcopy(A[1:])
        minus = [A[0]]
    elif A[-1] <= 0:
        ans = -sum(A[:-1]) + A[-1]
        plus = [A[-1]]
        minus = copy.deepcopy(A[:-1])
    else:
        plus = []
        minus = []
        ans = 0
        for a in A:
            if a >= 0:
                ans += a
                plus.append(a)
            else:
                ans -= a
                minus.append(a)

    plus = deque(plus)
    minus = deque(minus)
    print(ans)

    # minusをまず一つにする
    while len(minus) > 1:
        p = plus.pop()
        m = minus.pop()
        print(p, m)
        plus.append(p - m)

    # minusが1つになったあとの処理
    p = plus.pop()
    m = minus.pop()
    print(m, p)
    cur = m - p
    while len(plus) > 1:
        p = plus.pop()
        print(cur, p)
        cur -= p
    p = plus.pop()
    print(p, cur)


if __name__ == "__main__":
    main()


Fixed submission:
import sys
import copy
from collections import deque

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()

    if A[0] >= 0:
        ans = sum(A[1:]) - A[0]
        plus = copy.deepcopy(A[1:])
        minus = [A[0]]
    elif A[-1] <= 0:
        ans = -sum(A[:-1]) + A[-1]
        plus = [A[-1]]
        minus = copy.deepcopy(A[:-1])
    else:
        plus = []
        minus = []
        ans = 0
        for a in A:
            if a >= 0:
                ans += a
                plus.append(a)
            else:
                ans -= a
                minus.append(a)

    plus = deque(plus)
    minus = deque(minus)
    print(ans)

    # minusをまず一つにする
    while len(minus) > 1:
        p = plus.pop()
        m = minus.pop()
        print(p, m)
        plus.append(p - m)

    # minusが1つになったあとの処理
    p = plus.pop()
    m = minus.pop()
    if len(plus) == 0:
        print(p, m)
        return

    print(m, p)
    cur = m - p
    while len(plus) > 1:
        p = plus.pop()
        print(cur, p)
        cur -= p
    if len(plus) != 0:
        p = plus.pop()
        print(p, cur)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
MOD = 10 ** 9 + 7

a = [int(input()) for _ in range(M)]

dp = [0 for _ in range(N + 1)]
dp[0] = 1

for now in range(N):
    for next in range(now + 1, min(N + 1, now + 3)):
        if next not in a:
            dp[next] += dp[now]
            dp[next] = dp[next] % MOD

print(dp[N])


Fixed submission:
N, M = map(int, input().split())
MOD = 10 ** 9 + 7

is_broken = [False for _ in range(N + 1)]
for _ in range(M):
    a = int(input())
    is_broken[a] = True

dp = [0 for _ in range(N + 1)]
dp[0] = 1

for i in range(1, N + 1):
    if is_broken[i]:
        continue
    if i == 1:
        dp[i] += dp[i - 1]
    else:
        dp[i] += dp[i - 1] + dp[i - 2]

    dp[i] = dp[i] % MOD

print(dp[N])
Buggy python submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N, K = map(int, input().split())
    V = list(map(int, input().split()))

    ans = 0
    for a in range(min(N, K) + 1):
        for b in range(K - a):
            if a + b > N:
                continue
            tmp = []
            for i in range(a):
                tmp.append(V[i])
            for i in range(b):
                tmp.append(V[N - i - 1])
            rest = K - a - b
            tmp.sort()
            s = sum(tmp)
            for r in range(rest):
                if tmp[r] < 0:
                    s -= r
                else:
                    break
            if s > ans:
                ans = s

    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N, K = map(int, input().split())
    V = list(map(int, input().split()))

    ans = 0
    for n_pick in range(min(N, K) + 1):
        for left in range(n_pick + 1):
            right = n_pick - left
            tmp = []
            for i in range(left):
                tmp.append(V[i])
            for i in range(right):
                tmp.append(V[N - i - 1])
            tmp.sort()
            s = sum(tmp)
            n_return = min(K - n_pick, len(tmp))
            for i in range(n_return):
                if tmp[i] < 0:
                    s -= tmp[i]
                else:
                    break
            if s > ans:
                ans = s

    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
import sys
import math

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(input())
    A = list(map(int, input().split()))
    # i番目から左の全ての要素のGCD
    gcd_from_left = [None] * N
    gcd_from_left[0] = A[0]
    # i番目から右の全ての要素のGCD
    gcd_from_right = [None] * N
    gcd_from_right[-1] = A[-1]

    for i in range(1, N):
        gcd_from_left[i] = math.gcd(A[i], gcd_from_left[i - 1])

    for i in range(N - 2, -1, -1):
        gcd_from_right[i] = math.gcd(A[i], gcd_from_right[i + 1])

    gcd_from_right.sort()

    # 要素iを取り除いたときの最大公約数
    ans = max(gcd_from_left[-2], gcd_from_right[1])
    for i in range(1, N - 1):
        tmp = math.gcd(gcd_from_right[i + 1], gcd_from_left[i - 1])
        if tmp > ans:
            ans = tmp

    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
import sys
from fractions import gcd


sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(input())
    A = list(map(int, input().split()))
    # i番目から左の全ての要素のGCD
    gcd_from_left = [None] * N
    gcd_from_left[0] = A[0]
    # i番目から右の全ての要素のGCD
    gcd_from_right = [None] * N
    gcd_from_right[-1] = A[-1]

    for i in range(1, N):
        gcd_from_left[i] = gcd(A[i], gcd_from_left[i - 1])

    for i in range(N - 2, -1, -1):
        gcd_from_right[i] = gcd(A[i], gcd_from_right[i + 1])

    gcd_from_right.sort()

    # 要素iを取り除いたときの最大公約数
    ans = max(gcd_from_left[-2], gcd_from_right[1])
    for i in range(1, N - 1):
        tmp = gcd(gcd_from_right[i + 1], gcd_from_left[i - 1])
        if tmp > ans:
            ans = tmp

    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = input()

for i in range(N - 1, -1, -1):
    if S[i] == ".":
        right_white = i
        break

print(min(S.count("."), S[:right_white].count("#")))


Fixed submission:
N = int(input())
S = input()

white = [0] * (N + 1)
for i in range(N):
    if S[i] == ".":
        white[i + 1] = white[i] + 1
    else:
        white[i + 1] = white[i]

ans = N
for i in range(N + 1):
    tmp = (i - white[i]) + (white[-1] - white[i])
    if tmp < ans:
        ans = tmp

print(ans)
Buggy python submission (verdict: Runtime Error):
S = input()

target = "keyence"
now = 0
start = None
end = None
for i in range(len(S)):
    if target[now] == S[i]:
        now += 1
        if start is not None and end is None:
            end = i
    elif start is not None:
        continue
    else:
        start = i

if start is None:
    pred = S
elif end is None:
    pred = S[:start]
else:
    pred = S[:start] + S[end:]

if pred == target:
    print("YES")
else:
    print("NO")


Fixed submission:
S = input()

target = "keyence"
N = len(target)

for i in range(8):
    s = S[:i] + S[len(S) - N + i :]
    if s == target:
        print("YES")
        break
else:
    print("NO")
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    H, W = map(int, input().split())
    S = [input() for _ in range(H)]

    black = []
    for h in range(H):
        for w in range(W):
            if S[h][w] == "#":
                black.append((h, w))

    ans = 0
    for sh, sw in black:
        visited = [[0] * W for _ in range(H)]
        q = deque([("#", sh, sw)])

        while q:
            s, h, w = q.popleft()

            for dh, dw in [(0, 1), (0, -1), (1, 0), (-1, 0)]:
                nh = h + dh
                nw = w + dw
                if 0 <= nh < H and 0 <= nw < W:
                    if visited[nh][nw] == 0:
                        if s == S[nh][nw]:
                            continue
                        else:
                            if S[nh][nw] == ".":
                                ans += 1
                            visited[nh][nw] = 1
                            q.append((S[nh][nw], nh, nw))

    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
import sys
from collections import deque

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    H, W = map(int, input().split())
    S = [input() for _ in range(H)]
    seen = [[False] * W for _ in range(H)]

    def dfs(sh, sw):
        q = deque([(sh, sw)])
        seen[sh][sw] = True
        black = 0
        white = 0
        if S[sh][sw] == "#":
            black += 1
        else:
            white += 1

        while q:
            h, w = q.popleft()

            for dh, dw in [(1, 0), (-1, 0), (0, 1), (0, -1)]:
                nh = h + dh
                nw = w + dw

                if 0 <= nh < H and 0 <= nw < W:
                    if seen[nh][nw]:
                        continue
                    if S[h][w] == S[nh][nw]:
                        continue

                    seen[nh][nw] = True
                    q.append((nh, nw))
                    if S[nh][nw] == "#":
                        black += 1
                    else:
                        white += 1

        return black * white

    ans = 0
    for h in range(H):
        for w in range(W):
            if seen[h][w]:
                continue
            ans += dfs(h, w)

    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
h = [0] + list(map(int, input().split()))
dp = [float("inf") for _ in range(N + 1)]

dp[1] = 0
for i in range(2, N + 1):
    dp[i] = min(dp[j] + abs(h[i] - h[j]) for j in range(max(0, i - K), i))

print(dp[-1])


Fixed submission:
def main():
    N, K = map(int, input().split())
    h = [0] + list(map(int, input().split()))
    dp = [float("inf") for _ in range(N + 1)]

    dp[1] = 0
    for i in range(2, N + 1):
        dp[i] = min(dp[j] + abs(h[i] - h[j]) for j in range(max(0, i - K), i))

    print(dp[-1])


main()

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
h = [0] + list(map(int, input().split()))

dp = [float("inf") for _ in range(N + 1)]
dp[1] = 0

for i in range(1, N + 1):
    for j in range(i + 1, min(i + K + 1, N + 1)):
        dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]))

print(dp[N])


Fixed submission:
def main():
    N, K = map(int, input().split())
    h = [0] + list(map(int, input().split()))
    dp = [float("inf") for _ in range(N + 1)]

    dp[1] = 0
    for i in range(2, N + 1):
        dp[i] = min(dp[j] + abs(h[i] - h[j]) for j in range(max(0, i - K), i))

    print(dp[-1])


main()
Buggy python submission (verdict: Runtime Error):
def func(x):
    if x == 1:
        return 1
    else:
        return x + func(x - 1)


a, b = map(int, input().split())

for i in range(1, 999):
    if func(i) - a == func(i + 1) - b:
        print(func(i) - a)
        break


Fixed submission:
H = [1]
for i in range(2, 1000):
    H.append(H[-1] + i)

a, b = map(int, input().split())

for i in range(998):
    if H[i] - a == H[i + 1] - b:
        print(H[i] - a)
        break
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
K = int(input())
N = len(S)
substrs = set()

for i in range(N):
    cur = S[i]
    if cur not in substrs:
        substrs.add(cur)
    for j in range(i + 1, N):
        cur += S[j]
        if cur not in substrs:
            substrs.add(cur)

substrs = sorted(substrs)
print(substrs[K - 1])


Fixed submission:
S = input()
K = int(input())
N = len(S)
substrs = set()

for i in range(N):
    cur = S[i]
    if cur not in substrs:
        substrs.add(cur)
    for j in range(i + 1, min(N, i + 6)):
        cur += S[j]
        if cur not in substrs:
            substrs.add(cur)

substrs = sorted(substrs)
print(substrs[K - 1])

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
K = int(input())
N = len(S)
substrs = set()

for i in range(N):
    cur = S[i]
    if cur not in substrs:
        substrs.add(cur)
    for j in range(i + 1, N):
        cur += S[j]
        if cur not in substrs:
            substrs.add(cur)

substrs = sorted(substrs)
print(substrs[K - 1])


Fixed submission:
S = input()
K = int(input())
N = len(S)
substrs = set()

for i in range(N):
    cur = S[i]
    if cur not in substrs:
        substrs.add(cur)
    for j in range(i + 1, min(N, i + 6)):
        cur += S[j]
        if cur not in substrs:
            substrs.add(cur)

substrs = sorted(substrs)
print(substrs[K - 1])
Buggy python submission (verdict: Runtime Error):
import sys
from bisect import bisect_left

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    MAX = max(A)
    A = A[:-1]
    target = MAX // 2
    idx = bisect_left(A, target)

    if idx == 0:
        print(MAX, A[0])
    else:
        if abs(target - A[idx]) < abs(target - A[idx - 1]):
            print(MAX, A[idx])
        else:
            print(MAX, A[idx - 1])


if __name__ == "__main__":
    main()


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
a.sort()
M = max(a)
m = M / 2

diff = 10 ** 9
r = None
for i in range(n):
    if a[i] == M:
        continue
    else:
        if abs(m - a[i]) < diff:
            diff = abs(m - a[i])
            r = a[i]

print(M, r)
Buggy python submission (verdict: Runtime Error):
S = input()
S_set = set(list(S))
C_set = set([chr(ord("a") + i) for i in range(26)])

if len(S_set) == len(C_set):
    S = list(S)
    p = None
    for i in range(len(S) - 2, -1, -1):
        if S[i] < S[i + 1]:
            p = i
            break
    else:
        print(-1)
    ans = S[:p].copy()
    rest = C_set - set(S[: p + 1])
    rest = sorted(rest)
    for r in rest:
        if S[p] < r:
            ans.append(r)
            break
    print(*ans, sep="")
else:
    diff = C_set - S_set
    diff = sorted(diff)
    print(S + diff[0])


Fixed submission:
def main():
    S = input()
    S_set = set(list(S))
    C_set = set([chr(ord("a") + i) for i in range(26)])

    if len(S_set) == len(C_set):
        S = list(S)
        p = None
        for i in range(len(S) - 2, -1, -1):
            if S[i] < S[i + 1]:
                p = i
                break
        else:
            print(-1)
            return

        ans = S[:p].copy()
        rest = C_set - set(S[: p + 1])
        rest = sorted(rest)
        for r in rest:
            if S[p] < r:
                ans.append(r)
                break
        print(*ans, sep="")
    else:
        diff = C_set - S_set
        diff = sorted(diff)
        print(S + diff[0])
        return


main()

Buggy python submission (verdict: Runtime Error):
S = input()
S_set = set(list(S))
C_set = set([chr(ord("a") + i) for i in range(26)])

if len(S_set) == len(C_set):
    S = list(S)
    p = None
    for i in range(len(S) - 2, -1, -1):
        if S[i] < S[i + 1]:
            p = i
            break

    if p == 0:
        print(-1)
    else:
        ans = S[:p].copy()
        rest = C_set - set(S[: p + 1])
        rest = sorted(rest)
        ans.append(rest[0])
        print(*ans, sep="")
else:
    diff = C_set - S_set
    diff = sorted(diff)
    print(S + diff[0])


Fixed submission:
def main():
    S = input()
    S_set = set(list(S))
    C_set = set([chr(ord("a") + i) for i in range(26)])

    if len(S_set) == len(C_set):
        S = list(S)
        p = None
        for i in range(len(S) - 2, -1, -1):
            if S[i] < S[i + 1]:
                p = i
                break
        else:
            print(-1)
            return

        ans = S[:p].copy()
        rest = C_set - set(S[: p + 1])
        rest = sorted(rest)
        for r in rest:
            if S[p] < r:
                ans.append(r)
                break
        print(*ans, sep="")
    else:
        diff = C_set - S_set
        diff = sorted(diff)
        print(S + diff[0])
        return


main()
Buggy python submission (verdict: Runtime Error):
import numpy as np
import sys


sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N, C = map(int, input().split())
    MAX = 10 ** 5 + 1
    vals = [0] * MAX
    for _ in range(N):
        s, t, c = map(int, input().split())
        vals[s] += 1
        vals[t + 1] -= 1
    cumsum = np.cumsum(vals)
    ans = max(cumsum)
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
from collections import defaultdict
import numpy as np
import sys


sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N, C = map(int, input().split())
    MAX = 10 ** 5 + 2
    vals = [0] * MAX
    D = defaultdict(list)
    for _ in range(N):
        s, t, c = map(int, input().split())
        D[c].append((s, t))

    for k, v in D.items():
        prev = -1
        v.sort(key=lambda x: x[0])
        for s, t in v:
            if prev == s:
                vals[prev + 1] += 1
                vals[t + 1] -= 1
            else:
                vals[s] += 1
                vals[t + 1] -= 1
            prev = t

    cumsum = np.cumsum(vals)
    ans = max(cumsum)
    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def solve(N):
    N = int(input())
    M = 3501

    for h in range(1, M):
        for n in range(h, M):
            denominator = 4 * n * h - N * h - N * n
            if denominator <= 0:
                continue
            numerator = N * h * n

            if numerator % denominator == 0:
                return h, n, numerator // denominator


def main():
    N = int(input())
    h, n, w = solve(N)
    print(h, n, w)


if __name__ == "__main__":
    main()


Fixed submission:
def solve():
    N = int(input())
    M = 3501

    for h in range(1, M):
        for n in range(h, M):
            numerator = N * h * n
            denominator = 4 * n * h - N * h - N * n
            if numerator <= 0 or denominator <= 0:
                continue
            if numerator % denominator == 0:
                return h, n, numerator // denominator


h, n, w = solve()
print(h, n, w)