Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03095 (python)

Fixed submission:
N = int(input())
S = input()
  
co = 0
index =0
n =[]
str = ""

for i in range(N):
  index=str.find(S[i])
  if index == -1 :
    str += S[i]
    n.append(2)
  else :
    n[index] += 1

co = 1
for i in range(len(n)):
  co = co * n[i]
co -= 1

print(co % 1000000007)

Buggy submission (verdict: Runtime Error):
#include <bits/stdc++.h>

using namespace std;


int main() {
  unsigned long long co=0;
  int N;
  string S;
  //入力受付
  cin >> N;
  cin >> S;
  string str="";
  vector<int> n;
  int index =0;
  
  for(int i=0;i<N;i++){
    index=str.find(S[i]);
    if(index== string::npos){
      str +=S[i];
      n.push_back(2);
    }else{
      n[index]++;
    }
  }

  co = 1;
  for(int i=0; i<n.size();i++){
    co = co * n[i];
  }
  co--;  
  cout << co % 1000000007;

}

Buggy submission (verdict: Runtime Error):
#include <bits/stdc++.h>

using namespace std;


int main() {
  unsigned long long co=0;
  int N;
  string S;
  //入力受付
  cin >> N;
  cin >> S;
  string str="";
  vector<int> n;
  int index =0;
  
  for(int i=0;i<N;i++){
    index=str.find(S[i]);
    if(index== string::npos){
      str +=S[i];
      n.push_back(2);
    }else{
      n[index]++;
    }
  }

  co = 1;
  for(int i=0; i<n.size();i++){
    co = (co * n[i]) % 1000000007;
  }
  co--;  
  cout << co % 1000000007;

}

Buggy submission (verdict: Runtime Error):
N = int(input())
S = input()
  
co = 0
index =0
n =[]
str = ""

for i in range(N):
  index=str.find(S[i])
  if index == -1 :
    str += S[i]
    n.append(2)
  else :
    n[i] += 1

co = 1
for i in range(len(n)):
  co = co * n[i]
co -= 1

print(co % 1000000007)

Buggy submission (verdict: Runtime Error):
N = int(input())
S = input()
  
co = 0
index =0
n =[]
str = ""

for i in range(N):
  index=str.find(S[i])
  if index == -1 :
    str += S[i]
    n.append(2)
  else :
    n[i] += 1

co = 1
for i in range(len(n)):
  co = co * n[i]
co -= 1

print(co % 1000000007)

Buggy submission (verdict: Runtime Error):
N = int(input())
S = input()
  
co = 0
index =0
n =[]
str = ""

for i in range(N):
  index=str.find(S[i])
  if index == -1 :
    str += S[i]
    n.append(2)
  else :
    n[i]++

co = 1
for i in range(len(n)):
  co = co * n[i]
co -= 1

print(co % 1000000007)

Buggy submission (verdict: Runtime Error):
N = int(input())
S = input()
  
co = 0
index =0
n =[]
str = ""

for i in range(N):
  index=str.find(S[i])
  if index == -1 :
    str += S[i]
    n.append(2)
  else :
    n[i]++

co = 1
for i in range(n.size()):
  co = co * n[i]
co--;

print(co % 1000000007)

Buggy submission (verdict: Runtime Error):
N = int(input())
S = input()
  
co = 0
index =0
n =[]
str = ""

for i in N:
  index=str.find(S[i])
  if index == -1 :
    str += S[i]
    n.append(2)
  else :
    n[i]++

co = 1
for i in n.size():
  co = co * n[i]
co--;

print(co % 1000000007)
Problem p02923 (python)

Fixed submission:
n = int(input())
h = list(map(int,input().split()))
cnt = 0; res = 0
for i in range(n-1):
    if h[i] >= h[i+1]:
        cnt += 1
    else:
        cnt = 0
    res = max(res,cnt)
print(res)

Buggy submission (verdict: Runtime Error):
n = int(input())
h = list(map(int,input().split()))
cnt = 0; res = []
for i in range(n-1):
    if h[i] >= h[i+1]:
        cnt += 1
    else:
        res.append(cnt)
        cnt = 0
    if i == n-2:
        res.append(cnt)
        break
print(max(res))
Problem p02658 (python)

Fixed submission:
n = int(input())
A = input().split()
A.sort()

s = 1
for i in range(n):
	s*= int(A[i])
	if s > 10**18:
		print(-1)
		exit()

print(s)

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

N = input()

str_list = list(input().split())

P = np.prod(str_list)

if P > 10 ** 18:
	print(-1)
else:
	print(P)
Problem p02579 (python)

Fixed submission:
from collections import deque
 
 
# In[30]:
 
 
def main():
    H,W = map(int, input().split())
    ch,cw = map(int, input().split())
    dh,dw = map(int, input().split())
    s = ["#"*(W+4)]
    s.append("#"*(W+4))
    for i in range(H):
        s.append("##"+input()+"##")
    s.append("#"*(W+4))
    s.append("#"*(W+4))
    
    ans = [[-1]*(W+4) for _ in range(H+4)]
    for i in range(H+4):
        for j in range(W+4):
            if s[i][j] == "#":
                ans[i][j] = -2
    ch += 1; cw += 1
    dh += 1; dw += 1
    ans[ch][cw] = 0
    
    move = [[-1,0],[1,0],[0,-1],[0,1]]
    magic = [
        [-2,-2],[-2,-1],[-2,0],[-2,1],[-2,2],\
        [-1,-2],[-1,-1],[-1,0],[-1,1],[-1,2],\
        [0,-2],[0,-1],[0,0],[0,1],[0,2],\
        [1,-2],[1,-1],[1,0],[1,1],[1,2],\
        [2,-2],[2,-1],[2,0],[2,1],[2,2]
        ]
    
    mylist = deque([[ch,cw]])
    mylist2 = deque([])
    while len(mylist) > 0:
        x,y = mylist.popleft()
        mylist2.append([x,y])
        for p,q in move:
            v1,v2 = x+p,y+q
            if ans[v1][v2] == -1:
                mylist.append([v1,v2])
                ans[v1][v2] = ans[x][y]
        if len(mylist) == 0:
            while len(mylist2) > 0:
                x2,y2 = mylist2.popleft()
                for v1,v2 in magic:
                    i,j = x2+v1,y2+v2
                    if ans[i][j] == -1:
                        ans[i][j] = ans[x2][y2]+1
                        mylist.append([i,j])
    print(ans[dh][dw])
 
if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
from collections import deque

h, w = map(int, input().split())
ch, cw = map(int, input().split())
dh, dw = map(int, input().split())
base = ["#" *(w+4)]
base.append("#" * (w+4))
for n in range(h):
    base.append("##" + input() + "##")
base.append("#" * (w+4))
base.append("#" * (w+4))
ans = [[-1] * (w+4) for _ in range(h+4)]
for j in range(w+4):
    for i in range(h+4):
        if base[i][j] == "#":
            ans[i][j] = -2
ch+=1; cw+=1
dh+=1; dw+=1
ans[ch][cw] = 0
move = [[1, 0], [-1, 0], [0, 1], [0, -1]]
move2 = [
    [-2, -2], [-2, -1], [-2, 0], [-2, 1], [-2, 2], \
    [-1, -2], [-1, -1], [-1, 0], [-1, 1], [-1, 2], \
    [0, -2], [0, -1], [0, 0], [0, 1], [0, 2], \
    [1, -2], [1, -1], [1, 0], [1, 1], [1, 2], \
    [2, -2], [2, -1], [2, 0], [2, 1], [2, 2]]
q = deque([ch, cw])
one_time = deque()
while q:
    x, y = q.popleft()
    one_time.append([x, y])
    for i, j in move:
        v1, v2 = x+i, y+j
        if ans[v1][v2] == -1:
            ans[v1][v2] = ans[x][y]
            q.append([v1, v2])
    if len(q) == 0:
        while one_time:
            x2, y2 = one_time.popleft()
            for i, j in move2:
                v1, v2 = x2+i, y2+j
                if ans[v1][v2] == -1:
                    ans[v1][v2] = ans[x2][y2] + 1
                    q.append([v1, v2])
print(ans[dh][dw])
Problem p02603 (python)

Fixed submission:
N = int(input())
As = list(map(int, input().split()))
yen = 1000
kabu = 0
for n in range(N-1):
    if As[n] < As[n+1]:
        kabu += yen // As[n]
        yen -= kabu * As[n]
        yen += kabu * As[n+1]
        kabu = 0
print(yen)

Buggy submission (verdict: Runtime Error):
N = int(input())
As = list(map(int, input().split()))
judge = max(As)
max_index = As.index(judge)
preans = []
hand = 1000
kabu = 0
while As:
    a = As.pop(0)
    if a < judge:
        preans.append(a)
    else:
        buy = min(preans)
        while hand >= buy:
            kabu += 1
            hand-= buy
        hand += kabu * a
        kabu = 0
        preans = []
        if As:
            judge = max(As)
print(hand)

Buggy submission (verdict: Runtime Error):
N = int(input())
As = list(map(int, input().split()))
judge = As[0]
preans = []
hand = 1000
kabu = 0
while As:
    a = As.pop(0)
    if a <= judge:
        preans.append(a)
    else:
        buy = min(preans)
        while hand >= buy:
            kabu += 1
            hand-= buy
        hand += kabu * a
        judge = a
        kabu = 0
        preans = []
print(hand)
Problem p02608 (python)

Fixed submission:
import math
s = int(input())
ans = [0] * 100000
a = 0
b = 0
c = 0

for i in range(3, 3 * math.floor(math.sqrt(s))):
    for j in range(1, i):
        a = j
        for k in range(1, i - j):
            b = k
            c = i - a - b
            d = a*a + b*b + c*c + a*b + b*c + c*a
            ans[d - 1] += 1

for i in range(s):
    print(str(ans[i]))

Buggy submission (verdict: Runtime Error):
import math
s = int(input())
ans = [0] * 10000
a = 0
b = 0
c = 0

for i in range(3, 3 * math.floor(math.sqrt(s))):
    for j in range(1, i):
        a = j
        for k in range(1, i - j):
            b = k
            c = i - a - b
            d = a*a + b*b + c*c + a*b + b*c + c*a
            ans[d - 1] += 1

for i in range(s):
    print(str(ans[i]))

Buggy submission (verdict: Runtime Error):
import math
s = int(input())
ans = [0] * 10000
a = 0
b = 0
c = 0

for i in range(3, 3 * math.floor(math.sqrt(s))):
    for j in range(1, i):
        a = j
        for k in range(1, i - j):
            b = k
            c = i - a - b
            d = a*a + b*b + c*c + a*b + b*c + c*a
            ans[d - 1] += 1

for i in range(s):
    print(str(ans[i]))
Problem p02614 (python)

Fixed submission:
a = list(map(int,input().split()))
b = [input() for l in range(a[0])]
ans = 0
cnt = 0
allcnt = 0
nongyou = []
cnt2 = 0
for i in range(a[0]):
    allcnt += b[i].count('#')

for i in range(2 ** a[0]):
    cnt = allcnt
    nongyou = []
    for j in range(a[0]):
        if ((i >> j) & 1):
            cnt -= b[j].count('#')
            nongyou.append(j)
    for m in range(2 ** a[1]):
        cnt2 = cnt
        for n in range(a[1]):
            if ((m >> n) & 1):
                for k in range(a[0]):
                    if k in nongyou:
                        continue
                    else:
                        cnt2 -= b[k][n].count('#')                  
        if cnt2 == a[2]:
            ans += 1

print(str(ans))

Buggy submission (verdict: Runtime Error):
a = list(map(int,input().split()))
b = [input() for l in range(a[0])]
ans = 0
cnt = 0
allcnt = 0
nongyou = []
cnt2 = 0
for i in range(a[0]):
    allcnt += b[i].count('#')

for i in range(2 ** a[0]):
    cnt = allcnt
    nongyou = []
    for j in range(a[0]):
        if ((i >> j) & 1):
            cnt -= b[i].count('#')
            nongyou.append(i)
    for m in range(2 ** a[1]):
        cnt2 = cnt
        for n in range(a[1]):
            if ((m >> n) & 1):
                for k in range(a[0]):
                    if k in nongyou:
                        continue
                    else:
                        cnt2 -= b[k][m].count('#')                  
        if cnt2 == a[2]:
            ans += 1

print(str(ans))
Problem p03001 (python)

Fixed submission:
W,H,x,y = list(map(float,input().split()))

ans = W * H
ans = float(float(ans) / 2.0)
ans2 = 0
if x == float(float(W) / 2) and y == float(float(H) / 2):
    ans2 = 1

print(str(ans) + " " + str(ans2))

Buggy submission (verdict: Runtime Error):
W,H,x,y = list(map(float,input().split()))

ans = W * H
ans = float(float(ans) / 2.0)
ans2 = 0
if x == float(float(W) / 2) and y == float(float(H) / 2):
    ans2 = 1

print(ans + " " + ans2)
Problem p03403 (python)

Fixed submission:
n = int(input())
a = [0] + list(map(int,input().split())) + [0]
ans = 0
anslist = [0] * n
for j in range(1, n + 2):
    if j == 1:
        ans += abs(a[j])
    elif j == n + 1:
        ans += abs(a[n])
    else:
        ans += abs(a[j]-a[j - 1])

for i in range(1, n + 1):
    anslist[i - 1] = ans - abs(a[i - 1] - a[i]) - abs(a[i] - a[i + 1]) + abs(a[i - 1] - a[i + 1])
            
for k in anslist:
    print(k)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split))
ans = [0] * n
for i in range(n):
    ac = a
    del ac[i]
    for j in range(0, n):
        if j == 0:
            ans[i] += abs(ac[0])
        else:
            ans[i] += abs(ac[j]-ac[j - 1])

for k in ans:
    print(str(k))
Problem p02713 (python)

Fixed submission:
import math
from functools import reduce

K=int(input())

#関数定義(最大公約数)
def gcd(*numbers):
    return reduce(math.gcd, numbers)

sum=0

for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            sum+=(gcd(a, b, c))

print(sum)

Buggy submission (verdict: Runtime Error):
K=int(input())

#関数定義(最大公約数)
def gcd(*numbers):
    return reduce(math.gcd, numbers)

sum=0

for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            sum+=(gcd(a, b, c))

print(sum)
Problem p02612 (python)

Fixed submission:
# -*- coding: utf-8 -*-
n = int(input())
a = 1000-n%1000
if a != 1000:
    print(a)
else:
    print(0)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
n = int(input())
n = str(n)
if len(n) => 3:
    p = n[-3]+n[-2]+n[-1]
if len(n) == 2:
    p = n[-2]+n[-1]
if len(n) == 1:
    p = n[-1]
print(int(p))

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
n = int(input())
n = str(n)
if len(p) => 3:
    p = n[-3]+n[-2]+n[-1]
if len(p) == 2:
    p = n[-2]+n[-1]
if len(p) == 1:
    p = n[-1]
print(int(p))

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
n = int(input())
n = str(n)
p = n[-3]+n[-2]+n[-1]
print(int(p))

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
n = input()
p = n[-3]+n[-2]+n[-1]
print(int(p))
Problem p02641 (python)

Fixed submission:
# -*- coding: utf-8 -*-
x, n = map(int, input().split())
aa = 0
if n == 0:
   aa = 1
if aa == 0:
    p = list(map(int, input().split()))
    p.sort()
    i = 0
    flg = 0
    dis = []
    while flg == 0:
        if i > 100:
            flg = 1
        if i in p:
            dis.append(5000)
        else:
            dis.append(abs(x-i))
        i += 1
    for i in range(len(dis)):
        if dis[i] == min(dis):
            print(i)
            break
else:
    print(x)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
x, n = map(int, input().split())
aa = 0
if n == 0:
  aa = 1
if aa == 0:
    p = list(map(int, input().split()))
    p.sort()
    i = 0
    flg = 0
    dis = []
    while flg == 0:
        if i > 100:
            flg = 1
        if i in p:
            dis.append(5000)
        else:
            dis.append(abs(x-i))
        i += 1
    for i in dis:
        if dis[i] == min(dis):
            print(i)
            break
else:
    print(x)
Problem p02683 (python)

Fixed submission:
# -*- coding: utf-8 -*-
n, m, x = map(int, input().split())
L = []
J = []
for i in range(n):
    l = list(map(int, input().split()))
    L.append(l)
for i in range(2**n):
    cost = 0
    f = 0
    M = [0]*m
    for j in range(n):
        
        if (i>>j)&1 == 1:
            cost += L[j][0]
            for k in range(m):
                M[k] += L[j][k+1]
    for p in M:
        if p < x:
            f = 1
    if f == 0:
        J.append(cost)
if J != []:
  print(min(J))
else:
  print(-1)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
n, m, x = map(int, input().split())
L = []
J = []
for i in range(n):
    l = list(map(int, input().split()))
    L.append(l)
for i in range(2**n):
    cost = 0
    f = 0
    M = [0]*m
    for j in range(n):
        
        if (i>>j)&1 == 1:
            cost += L[j][0]
            for k in range(m):
                M[k] += L[j][k+1]
    for p in M:
        if p < x:
            f = 1
    if f == 0:
        J.append(cost)
print(min(J))
Problem p02717 (python)

Fixed submission:
# -*- coding: utf-8 -*-
BOX = list(map(int, input().split()))
print(BOX[2], BOX[0], BOX[1])

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
N, M = map(int, input().split())
A = list(map(int, input().split()))
cnt = 0
for Ai in A:
    k = 1/(4*M)
    if (sum(A))*k <= Ai:
        cnt += 1
if cnt >= M:
    print("Yes")
else:
    print("No")
Problem p02760 (python)

Fixed submission:
# -*- coding: utf-8 -*-
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
a3 = list(map(int, input().split()))
a = [a1, a2, a3]
n = int(input())
b = []
bng = 0
for i in range(n):
    bn = int(input())
    b.append(bn)
for i in range(3):
    for j in range(3):
        if a[i][j] in b:
            a[i][j] = -5
for i in range(3):
    if sum(a[i]) == -15:
        bng = 1
for i in range(3):
     cnt = 0
     for j in range(3):
       cnt += a[j][i]
       if cnt == -15:
         bng = 1
        
cnt = 0
for i in range(3):
        cnt += a[i][i]
if cnt == -15:
        bng = 1 
if a[0][2] + a[1][1] + a[2][0] == -15:
    bng = 1
                
if bng == 1:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
a3 = list(map(int, input().split()))
a = [a1, a2, a3]
n = int(input())
b = []
for i in range(n):
    bn = int(input())
    b.append(bn)
for i in range(3):
    for j in range(3):
        if a[i][j] in b:
            a[i][j] = -5
for i in range(3):
    if sum(a[i]) == -15:
        bng = 1
for i in range(3):
     cnt = 0
     for j in range(3):
       cnt += a[j][i]
       if cnt == -15:
         bng = 1
        
cnt = 0
for i in range(3):
        cnt += a[i][i]
if cnt == -15:
        bng = 1 
                
if bng == 1:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
a3 = list(map(int, input().split()))
a = [a1, a2, a3]
n = int(input())
b = []
for i in range(n):
    bn = int(input())
    b.append(bn)
for i in range(3):
    for j in range(3):
        if a[i][j] in b:
            a[i][j] = -5
print(*a)
for i in range(3):
    if sum(a[i]) == -15:
        bng = 1
for i in range(3):
     cnt = 0
     for j in range(3):
       cnt += a[j][i]
       if cnt == -15:
         bng = 1
        
cnt = 0
for i in range(3):
        cnt += a[i][i]
if cnt == -15:
        bng = 1 
                
if bng == 1:
    print("Yes")
else:
    print("No")
Problem p02801 (python)

Fixed submission:
# -*- coding: utf-8 -*-
a = input()
alp = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
for i in range(len(alp)):
    if a == alp[i]:
        print(alp[i+1])

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
n, k, m = map(int, input().split())
a = list(map(int, input().split()))
an = m*n-sum(a)
if (0 <= an <= k):
    print(an)
if 0 > an:
    print(0)
if k < an:
    print(-1)
Problem p02811 (python)

Fixed submission:
# -*- coding: utf-8 -*-
K, X = map(int, input().split())
if 500*K >= X:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
N = int(input())
S = [i for i in input()]
ans = 0
for i in range(N):
    if S[i] == "A":
        if S[i+1] == "B":
            if S[i+2] == "C":
                ans += 1
print(ans)
Problem p02812 (python)

Fixed submission:
# -*- coding: utf-8 -*-
N = int(input())
S = [i for i in input()] + [-1, -1]
ans = 0
for i in range(N):
    if S[i] == "A":
        if S[i+1] == "B":
            if S[i+2] == "C":
                ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
N = int(input())
S = [i for i in input()]
ans = 0
for i in range(N):
    if S[i] == "A":
        if S[i+1] == "B":
            if S[i+2] == "C":
                ans += 1
print(ans)
Problem p03136 (python)

Fixed submission:
# -*- coding: utf-8 -*-
N = int(input())
L = list(map(int, input().split()))
if max(L) < (sum(L)-max(L)):
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
N = int(input())
L = list(map(int, inpout().split()))
if max(L) > (sum(L)-max(L)):
    print("Yes")
else:
    print("No")
Problem p02761 (python)

Fixed submission:
import math
n,m=map(int,input().split())
arr=[None]*n
flag=True
ar=[]
for i in range(m):
	s,c=map(int,input().split())
	ar.append([s,c])
if m==0 and n==1:
	print(0)
	exit()
for  i in range(len(ar)):
	s=ar[i][0]
	c=ar[i][1]
	s-=1
	if s==0 and c==0 and n!=1:
		flag=False
		break
	if arr[s]==None:
		arr[s]=c 
	else:
		if arr[s]!=c:
			flag=False
			break
		else:
			continue 
if not flag:
	print(-1)
	exit()
# if arr[0]==0 and n!=1:
# 	print(-1)
# 	exit()
if arr[0]==None:
	arr[0]=1
if flag:
	for i in arr:
		if i==None:
			print(0,end="")
		else:
			print(i,end="")
	print()
else:
	print(-1)

Buggy submission (verdict: Runtime Error):
import math
n,m=map(int,input().split())
arr=[None]*n
flag=True
ar=[]
for i in range(m):
	s,c=map(int,input().split())
	ar.append([s,c])
for  i in range(len(arr)):
	s=ar[i][0]
	c=ar[i][1]
	s-=1
	if s==0 and c==0 and n!=1:
		flag=False
		break
	if arr[s]==None:
		arr[s]=c 
	else:
		if arr[s]!=c:
			flag=False
			break
		else:
			continue 
if not flag:
	print(-1)
	exit()
# if arr[0]==0 and n!=1:
# 	print(-1)
# 	exit()
if arr[0]==None:
	arr[0]=1
if flag:
	for i in arr:
		if i==None:
			print(0,end="")
		else:
			print(i,end="")
	print()
else:
	print(-1)
Problem p02698 (python)

Fixed submission:
import sys
from bisect import bisect_left
sys.setrecursionlimit(10**7)
def input():return sys.stdin.readline().strip()

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

    to = [[] for _ in range(N)]
    for _ in range(N-1):
        u, v = map(int, input().split())
        u -= 1
        v -= 1
        to[u].append(v)
        to[v].append(u)
    
    ans = [0] * N
    dp = []
    def dfs(now, pre):
        a = A[now]
        idx = bisect_left(dp, a)

        if idx == len(dp):
            old = -1
            dp.append(a)
        else:
            old = dp[idx]
            dp[idx] = a
        
        ans[now] = len(dp)

        
        for nv in to[now]:
            if nv != pre:
                dfs(nv, now)
        

        if old == -1:
            dp.pop()
        else:
            dp[idx] = old

    
    dfs(0, -1)

    print(*ans, sep="\n")
        

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys
from bisect import bisect_left
def input():return sys.stdin.readline().strip()

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

    to = [[] for _ in range(N)]
    for _ in range(N-1):
        u, v = map(int, input().split())
        u -= 1
        v -= 1
        to[u].append(v)
        to[v].append(u)
    
    ans = [0] * N
    dp = []
    def dfs(now, pre):
        a = A[now]
        idx = bisect_left(dp, a)

        if idx == len(dp):
            old = -1
            dp.append(a)
        else:
            old = dp[idx]
            dp[idx] = a
        
        ans[now] = len(dp)

        
        for nv in to[now]:
            if nv != pre:
                dfs(nv, now)
        

        if old == -1:
            dp.pop()
        else:
            dp[idx] = old

    
    dfs(0, -1)

    print(*ans, sep="\n")
        

if __name__ == "__main__":
    main()