Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque
def input(): return sys.stdin.readline().rstrip()

def main():
    N, X, Y = map(int, input().split())

    ans = [0] * N
    for i in range(1, N+1):
        dist = [-1] * (N+1)
        dist[i] = 0
        q = deque()
        q.append(i)
        def push(l, m):
            if dist[l] > -1:
                return
            q.append(l)
            dist[l] = dist[m] + 1
            ans[dist[l]] += 1

        while q:
            j = q.popleft()
            if j < N: push(j+1, j)
            if j > 1: push(j-1, j)
            if j == X: push(Y, j)
            if j == Y: push(X, j)
    for i in range(1, N):
        print(ans[i]// 2)

if __name__ == '__main__':
    main()

Fixed submission:
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    N, X, Y = map(int, input().split())

    ans = [0] * N
    for i in range(1, N):
        for j in range(i+1, N+1):
            if i >= Y or j <= X:
                ans[j-i] += 1
            else:
                ans[min(j-i, abs(X-i) + abs(Y-j)+1)] += 1
    print(*ans[1:], sep='\n')

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque, Counter
def input(): return sys.stdin.readline().rstrip()

def main():
    N, X, Y = map(int, input().split())

    c = Counter()
    for i in range(1, N+1):
        dist = [-1] * (N+1)
        dist[i] = 0
        q = deque()
        q.append(i)
        while q:
            j = q.popleft()
            if j < N and dist[j+1] < 0:
                q.append(j+1)
                dist[j+1] = dist[j] + 1
            if j > 1 and dist[j-1] < 0:
                q.append(j-1)
                dist[j-1] = dist[j] + 1
            if j == X and dist[Y] < 0:
                q.append(Y)
                dist[Y] = dist[j] + 1
            if j == Y and dist[X] < 0:
                q.append(X)
                dist[X] = dist[j] + 1
        c += Counter(dist)
    for i in range(1, N):
        print(c[i]// 2)

if __name__ == '__main__':
    main()


Fixed submission:
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    N, X, Y = map(int, input().split())

    ans = [0] * N
    for i in range(1, N):
        for j in range(i+1, N+1):
            if i >= Y or j <= X:
                ans[j-i] += 1
            else:
                ans[min(j-i, abs(X-i) + abs(Y-j)+1)] += 1
    print(*ans[1:], sep='\n')

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import sys
from functools import lru_cache
def input(): return sys.stdin.readline().rstrip()

def calc(n):
    if n == 1:
        return 1
    else:
        return n + calc(n - 1)

def main():
    N, K = map(int, input().split())
    P = tuple(map(int, input().split()))

    l = 0
    sum_v = 0
    max_v = 0
    max_i = 0
    ind = 0
    for i in range(N-K+1):
        while l < K:
            sum_v += P[ind]
            ind += 1
            l += 1
        if sum_v > max_v:
            max_v = sum_v
            max_i = i
        l -= 1
        sum_v -= P[i]
    print(sum([calc(p) / p for p in P[max_i:max_i+K]]))

if __name__ == '__main__':
    main()


Fixed submission:
import sys
from functools import lru_cache
def input(): return sys.stdin.readline().rstrip()

sys.setrecursionlimit(10 ** 9)

@lru_cache(maxsize=None)
def calc(n):
    if n == 1:
        return 1
    else:
        return n + calc(n - 1)

def main():
    N, K = map(int, input().split())
    P = tuple(map(int, input().split()))

    l = 0
    sum_v = 0
    max_v = 0
    max_i = 0
    ind = 0
    for i in range(N-K+1):
        while l < K:
            sum_v += P[ind]
            ind += 1
            l += 1
        if sum_v > max_v:
            max_v = sum_v
            max_i = i
        l -= 1
        sum_v -= P[i]
    print(sum([calc(p) / p for p in P[max_i:max_i+K]]))

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    H, N = map(int, input().split())
    AB = [tuple(map(int, input().split())) for _ in range(N)]

    MAX_V = 10**8+1
    dp = [MAX_V] * (H+1)
    dp[0] = 0
    for a, b in AB:
        for i in range(1, H+1):
            if i - a >= 0:
                v = dp[i-a] + b
            else:
                v = b
            if dp[i] > v:
                dp[i] = v

    print(dp[H])

if __name__ == '__main__':
    main()


Fixed submission:
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    H, N = map(int, input().split())
    AB = [tuple(map(int, input().split())) for _ in range(N)]

    dp = [10**9+1] * (H+1)
    dp[0] = 0
    for a, b in AB:
        for i in range(1, H+1):
            if i - a >= 0:
                v = dp[i-a] + b
            else:
                v = b
            if dp[i] > v:
                dp[i] = v

    print(dp[H])

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    H, N = map(int, input().split())
    AB = [tuple(map(int, input().split())) for _ in range(N)]

    MAX_V = 10**9+1
    dp = [MAX_V] * (H+1)
    dp[0] = 0
    for a, b in AB:
        for i in range(1, H+1):
            if i - a >= 0:
                v = dp[i-a] + b
            else:
                v = b
            if dp[i] > v:
                dp[i] = v

    print(dp[H])

if __name__ == '__main__':
    main()

Fixed submission:
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    H, N = map(int, input().split())
    AB = [tuple(map(int, input().split())) for _ in range(N)]

    dp = [10**9+1] * (H+1)
    dp[0] = 0
    for a, b in AB:
        for i in range(1, H+1):
            if i - a >= 0:
                v = dp[i-a] + b
            else:
                v = b
            if dp[i] > v:
                dp[i] = v

    print(dp[H])

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    H, N = map(int, input().split())
    AB = [tuple(map(int, input().split())) for _ in range(N)]

    dp = [10**9+1] * (H+1)
    dp[0] = 0
    for a, b in AB:
        for i in range(1, H+1):
            if i - a >= 0:
                v = dp[i-a] + b
            else:
                v = b
            if dp[i] > v:
                dp[i] = v

    print(dp[H])

if __name__ == '__main__':
    main()


Fixed submission:
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    H, N = map(int, input().split())
    AB = [tuple(map(int, input().split())) for _ in range(N)]

    dp = [10**9+1] * (H+1)
    dp[0] = 0
    for a, b in AB:
        for i in range(1, H+1):
            if i - a >= 0:
                v = dp[i-a] + b
            else:
                v = b
            if dp[i] > v:
                dp[i] = v

    print(dp[H])

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from fractions import gcd
from functools import reduce
def input(): return sys.stdin.readline().rstrip()

def main():
    MOD = 10 ** 9 + 7
    n = int(input())
    A = tuple(map(int, input().split()))
    gcd_v = reduce(lcm, A)

    ans = 0
    for i in A:
        ans += gcd_v // i
        ans %= MOD
    print(ans)

def lcm(n, m):
    return (n * m) // gcd(n, m)    

if __name__ == '__main__':
    main()


Fixed submission:
import sys
from fractions import gcd
from functools import reduce
def input(): return sys.stdin.readline().rstrip()

def main():
    MOD = 10 ** 9 + 7
    n = int(input())
    A = tuple(map(int, input().split()))
    gcd_v = reduce(lcm, A)

    ans = 0
    for i in A:
        ans += gcd_v * pow(i, MOD-2, MOD) % MOD
        ans %= MOD
    print(ans)

def lcm(n, m):
    return (n * m) // gcd(n, m)    

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from fractions import gcd
from functools import reduce
def input(): return sys.stdin.readline().rstrip()

def main():
    MOD = 10 ** 9 + 7
    n = int(input())
    A = tuple(map(int, input().split()))
    gcd_v = reduce(lcm, A)

    ans = 0
    for i in A:
        ans += gcd_v // i
        ans %= MOD
    print(ans)

def lcm(n, m):
    return (n * m) // gcd(n, m)    

if __name__ == '__main__':
    main()


Fixed submission:
import sys
from fractions import gcd
from functools import reduce
def input(): return sys.stdin.readline().rstrip()

def main():
    MOD = 10 ** 9 + 7
    n = int(input())
    A = tuple(map(int, input().split()))
    gcd_v = reduce(lcm, A)

    ans = 0
    for i in A:
        ans += gcd_v * pow(i, MOD-2, MOD) % MOD
        ans %= MOD
    print(ans)

def lcm(n, m):
    return (n * m) // gcd(n, m)    

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    n, m = map(int, input().split())
    ac = set()
    wa = [0] * (m+1)

    for _ in range(m):
        p, s = input().split()
        p = int(p)
        if p in ac:
            continue
        if s == 'AC':
            ac.add(p)
        elif s == 'WA':
            wa[p] += 1
    print(len(ac), sum(wa))

if __name__ == '__main__':
    main()


Fixed submission:
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    n, m = map(int, input().split())
    ac = set()
    wa = [0] * (n+1)

    for _ in range(m):
        p, s = input().split()
        p = int(p)
        if p in ac:
            continue
        if s == 'AC':
            ac.add(p)
        elif s == 'WA':
            wa[p] += 1
    wa = [j for i, j in enumerate(wa) if i in ac]
    print(len(ac), sum(wa))

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    n, m = map(int, input().split())
    ps = [input() for _ in range(m)]

    ac = set()
    wa = [0] * m

    for i in ps:
        p, s = i.split()
        p = int(p)
        if s == 'AC':
            ac.add(p)
        elif p not in ac and s == 'WA':
            wa[p] += 1
    print(len(ac), sum(wa))

if __name__ == '__main__':
    main()

Fixed submission:
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    n, m = map(int, input().split())
    ac = set()
    wa = [0] * (n+1)

    for _ in range(m):
        p, s = input().split()
        p = int(p)
        if p in ac:
            continue
        if s == 'AC':
            ac.add(p)
        elif s == 'WA':
            wa[p] += 1
    wa = [j for i, j in enumerate(wa) if i in ac]
    print(len(ac), sum(wa))

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import sys
import math
def input(): return sys.stdin.readline().rstrip()

def main():
    a, b= map(int, input().split())
    print(a * b // math.gcd(a, b))

if __name__ == '__main__':
    main()


Fixed submission:
import sys
import fractions
def input(): return sys.stdin.readline().rstrip()

def main():
    a, b= map(int, input().split())
    print(a * b // fractions.gcd(a, b))

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    N = int(input())
    A = list(map(int, input().split()))
    MAX_BIT = 60
    MOD = 10 ** 9 + 7

    data = [0] * (MAX_BIT + 2)
    for a in A:
        for bit in range(MAX_BIT + 1):
            if a & (1 << bit):
                data[bit] += 1
    ans = 0
    for i, d in enumerate(data):
        if d == 0:
            continue
        ans += pow(2, i, MOD) * d * (N-d)
        ans %= MOD
    print(ans)

if __name__ == '__main__':
    main()


Fixed submission:
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    N = int(input())
    A = list(map(int, input().split()))
    MAX_BIT = 60
    MOD = 10 ** 9 + 7

    data = [0] * (MAX_BIT + 2)
    for a in A:
        for bit in range(MAX_BIT + 1):
            if a & (1 << bit):
                data[bit] += 1
    ans = 0
    for i, d in enumerate(data):
        if d == 0:
            continue
        ans += pow(2, i, MOD) * d * (N-d)
        ans %= MOD
    print(ans)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    N = int(input())
    A = tuple(map(int, input().split()))
    MOD = 10 ** 9 + 7

    ans = 0
    for i, a in enumerate(A[:-1]):
        ans += sum([a ^ b for b in A[i+1:]]) % MOD
        ans %= MOD
    print(ans)

if __name__ == '__main__':
    main()

Fixed submission:
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    N = int(input())
    A = list(map(int, input().split()))
    MAX_BIT = 60
    MOD = 10 ** 9 + 7

    data = [0] * (MAX_BIT + 2)
    for a in A:
        for bit in range(MAX_BIT + 1):
            if a & (1 << bit):
                data[bit] += 1
    ans = 0
    for i, d in enumerate(data):
        if d == 0:
            continue
        ans += pow(2, i, MOD) * d * (N-d)
        ans %= MOD
    print(ans)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
x = int(input())

if (x % 100) / (x // 100) > 5:
    print(0)
else:
    print(1)

Fixed submission:
x = int(input())
v = x // 100
modv = x % 100
if v > 0 and (modv == 0 or modv / v <= 5):
    print(1)
else:
    print(0)
Buggy python submission (verdict: Runtime Error):
n,s = [input() for i in range(2)]
c = 0
for i in range(1000):
    if i < 10:
        a1 = '0'
        a2 = '0'
        a3 = i
    elif i < 100:
        a1 = '0'
        a2 = str(i)[0]
        a3 = str(i)[1]
    else:
        a1 = str(i)[0]
        a2 = str(i)[1]
        a3 = str(i)[2]
    p1 = s.find(a1)
    if p1 >= 0:
        p2 = s.find(a2, p1 + 1)
        if p2 >= 0:
            if s.find(a3, p2 + 1) >= 0:
                c += 1
print(c)

Fixed submission:
n,s = [input() for i in range(2)]
c = 0
for i in range(1000):
    if i < 10:
        a1 = '0'
        a2 = '0'
        a3 = str(i)
    elif i < 100:
        a1 = '0'
        a2 = str(i)[0]
        a3 = str(i)[1]
    else:
        a1 = str(i)[0]
        a2 = str(i)[1]
        a3 = str(i)[2]
    p1 = s.find(a1)
    if p1 >= 0:
        p2 = s.find(a2, p1 + 1)
        if p2 >= 0:
            if s.find(a3, p2 + 1) >= 0:
                c += 1
print(c)
Buggy python submission (verdict: Runtime Error):
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    N = int(input())
    ab = [map(int, input().split()) for _ in range(N-1)]

    graph = [set() for _ in range(N)]
    for a, b in ab:
        graph[a].add(b)

    ans = [-1] * (N-1)
    def dfs(i, color):
        if i == N:
            return
        ans[i-1] = color

        c = 1
        for g in graph[i]:
            if c == color:
                c += 1
            dfs(g, c)
            c += 1

    dfs(1, 1)
    print(max(ans))
    print("\n".join(map(str, ans)))

if __name__ == '__main__':
    main()


Fixed submission:
import sys
from collections import deque
def input(): return sys.stdin.readline().rstrip()

def main():
    N = int(input())
    ab = [tuple(map(int, input().split())) for _ in range(N-1)]

    graph = [set() for _ in range(N+1)]
    for a, b in ab:
        graph[a].add(b)
        graph[b].add(a)

    d = deque()
    d.append(1)

    ans = [-1] * (N+1)

    parent = [-1] * (N+1)
    parent[1] = 1

    while d:
        p = d.popleft()
        c = 0
        for g in graph[p]:
            if parent[g] > 0 or g == parent[g]:
                continue
            c += 1
            if c == ans[p]:
                c += 1
            ans[g] = c

            parent[g] = p
            d.append(g)

    print(max(ans))
    for _, b in ab:
        print(ans[b])

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import math
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    xy = [tuple(map(int, input().split())) for _ in range(n)]
    checked = [[None for _ in range(n)] for _ in range(n)]
    sum_v = 0
    p = 1
    for i in range(n):
        p *= i + 1
        for j in range(n):
            if i == j or dis[i][j] is not None:
                continue
            checked[i][j] = 1
            checked[j][i] = 1
            sum_v += math.sqrt((xy[i][0] - xy[j][0]) ** 2 + (xy[i][1] - xy[j][1]) ** 2)
    print(sum_v * 2 / n)

if __name__ == '__main__':
    main()


Fixed submission:
import math
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    xy = [tuple(map(int, input().split())) for _ in range(n)]
    dis = [[None for _ in range(n)] for _ in range(n)]
    sum_v = 0
    p = 1
    for i in range(n):
        p *= i + 1
        for j in range(n):
            if i == j or dis[i][j] is not None:
                continue
            d = math.sqrt((xy[i][0] - xy[j][0]) ** 2 + (xy[i][1] - xy[j][1]) ** 2)
            dis[i][j] = d
            dis[j][i] = d
            sum_v += d
    print(sum_v * 2 / n)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import math
import sys
input = sys.stdin.readline

def main():
    mod = 10 ** 9 + 7
    x, y = map(int, input().split())
    if (2 * y - x) % 3 != 0:
        print(0)
        return None

    n = (2 * y - x) // 3
    m = y - 2 * n

    if n < 0 or m < 0:
        print(0)
    elif n == 0 and m == 0:
        print(0)
    elif n == 0 or m == 0:
        print(1)
    else:
        ans = math.factorial(n+m) % mod
        ans = ans * modinv(math.factorial(n)) % mod
        ans = ans * modinv(math.factorial(m)) % mod
        print(ans)

def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

if __name__ == '__main__':
    main()


Fixed submission:
import math
import sys
input = sys.stdin.readline

def main():
    mod = 10 ** 9 + 7
    x, y = map(int, input().split())
    if (2 * y - x) % 3 != 0:
        print(0)
        return None

    n = (2 * y - x) // 3
    m = y - 2 * n

    if n < 0 or m < 0:
        print(0)
    elif n == 0 and m == 0:
        print(0)
    elif n == 0 or m == 0:
        print(1)
    else:
        s = n + m + 1
        f = [1] * s

        for i in range(1, s):
            f[i] = f[i-1] * i % mod

        ans = f[n+m]
        ans = ans * modinv(f[n]) % mod
        ans = ans * modinv(f[m]) % mod
        print(ans)

def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
import math
import sys
input = sys.stdin.readline

def main():
    x, y = map(int, input().split())
    if (2 * y - x) % 3 == 0:
        x_c = (2 * y - x) // 3
        y_c = y - 2 * x_c
        print(x_c, y_c)
        if x_c == 0 or y_c == 0:
            print(1)
        else:
            f = math.factorial
            print(f(x_c+y_c)/(f(x_c) * f(y_c)))
    else:
        print(0)

if __name__ == '__main__':
    main()


Fixed submission:
import math
import sys
input = sys.stdin.readline

def main():
    mod = 10 ** 9 + 7
    x, y = map(int, input().split())
    if (2 * y - x) % 3 != 0:
        print(0)
        return None

    n = (2 * y - x) // 3
    m = y - 2 * n

    if n < 0 or m < 0:
        print(0)
    elif n == 0 and m == 0:
        print(0)
    elif n == 0 or m == 0:
        print(1)
    else:
        s = n + m + 1
        f = [1] * s

        for i in range(1, s):
            f[i] = f[i-1] * i % mod

        ans = f[n+m]
        ans = ans * modinv(f[n]) % mod
        ans = ans * modinv(f[m]) % mod
        print(ans)

def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    n = int(input())
    h = map(int, input().split())

    ans, bef, cnt = 0, 0, 0

    for i in h:
        if i <= bef:
            cnt += 1
        else:
            ans = max(ans, cnt)
            cnt = 0
        bef = i
    print(max(ans, cnt))

if __name__ == '__main__':
    main()


Fixed submission:
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    s, t = input(), input()
    print(sum([1 for i in range(3) if s[i] == t[i]]))

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 20)
def input(): return sys.stdin.readline().rstrip()

def main():
    N, Q = map(int, input().split())
    ki = [[] for _ in range(N + 1)]
    for _ in range(N-1):
        a, b = map(int, input().split())
        ki[a].append(b)
    PX = [tuple(map(int, input().split())) for _ in range(Q)]

    ans = [0 for _ in range(N + 1)]
    def dfs(i, n):
        ans[i] += n
        for j in ki[i]:
            dfs(j, n)

    for p, x in PX:
        dfs(p, x)
    print(*ans[1:])

if __name__ == '__main__':
    main()


Fixed submission:
import sys
sys.setrecursionlimit(10 ** 9)
def input(): return sys.stdin.readline().rstrip()

def main():
    N, Q = map(int, input().split())
    ki = [[] for _ in range(N + 1)]
    for _ in range(N-1):
        a, b = map(int, input().split())
        ki[a].append(b)
        ki[b].append(a)
    PX = [tuple(map(int, input().split())) for _ in range(Q)]

    ans = [0 for _ in range(N + 1)]
    for p, x in PX:
        ans[p] += x
    visited = set()
    def dfs(i):
        visited.add(i)
        for j in ki[i]:
            if j in visited:
                continue
            ans[j] += ans[i]
            dfs(j)
    dfs(1)
    print(*ans[1:])

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    N, Q = map(int, input().split())
    ki = [[] for _ in range(N + 1)]
    for _ in range(N-1):
        a, b = map(int, input().split())
        ki[a].append(b)
    PX = [tuple(map(int, input().split())) for _ in range(Q)]

    ans = [0 for _ in range(N + 1)]
    def dfs(i, n):
        ans[i] += n
        for j in ki[i]:
            dfs(j, n)

    for p, x in PX:
        dfs(p, x)
    print(*ans[1:])

if __name__ == '__main__':
    main()


Fixed submission:
import sys
sys.setrecursionlimit(10 ** 9)
def input(): return sys.stdin.readline().rstrip()

def main():
    N, Q = map(int, input().split())
    ki = [[] for _ in range(N + 1)]
    for _ in range(N-1):
        a, b = map(int, input().split())
        ki[a].append(b)
        ki[b].append(a)
    PX = [tuple(map(int, input().split())) for _ in range(Q)]

    ans = [0 for _ in range(N + 1)]
    for p, x in PX:
        ans[p] += x
    visited = set()
    def dfs(i):
        visited.add(i)
        for j in ki[i]:
            if j in visited:
                continue
            ans[j] += ans[i]
            dfs(j)
    dfs(1)
    print(*ans[1:])

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    n = int(input())
    p = [*map(int, input().split())]

    c = 0
    for i in range(n):
        if (i + 1) != p[i]:
            c += 1
    if c <= 2:
        print('YES')
    else:
        print('NO')

if __name__ == '__main__':
    main()


Fixed submission:
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    n = int(input())
    p = list(map(int, input().split()))

    c = 0
    for i in range(n):
        if (i + 1) != p[i]:
            c += 1
    if c <= 2:
        print('YES')
    else:
        print('NO')

if __name__ == '__main__':
    main()