Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import sys


class Unionfindtree:
    def __init__(self, number):
        self.par = [i for i in range(number)]
        self.rank = [0] * (number)

    def find(self, x):  # 親を探す
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):  # x,yを繋げる
        px = self.find(x)
        py = self.find(y)
        if px == py:
            return
        if self.rank[px] < self.rank[py]:
            self.par[px] = py
        else:
            self.par[py] = px
        if self.rank[px] == self.rank[py]:
            self.rank[px] += 1

    def connect(self, x, y):  # 親が同じかみる
        return self.find(x) == self.find(y)


N,M=map(int,input().split())
K=[set() for i in range(M)]
tree=Unionfindtree(N)
for i in range(N):
    L=[int(i)-1 for i in input().split()]
    for m in L[1:]:
        K[m].add(i)
for i in range(M):
    Ki=list(K[i])
    for h in range(len(Ki)):
        for m in range(h+1,len(Ki)):
            tree.union(Ki[h],Ki[m])
for i in range(N):
    if not tree.connect(0,i):
        print('NO')
        sys.exit()
print('YES')




Fixed submission:
import sys


class Unionfindtree:
    def __init__(self, number):
        self.par = [i for i in range(number)]
        self.rank = [0] * (number)

    def find(self, x):  # 親を探す
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):  # x,yを繋げる
        px = self.find(x)
        py = self.find(y)
        if px == py:
            return
        if self.rank[px] < self.rank[py]:
            self.par[px] = py
        else:
            self.par[py] = px
        if self.rank[px] == self.rank[py]:
            self.rank[px] += 1

    def connect(self, x, y):  # 親が同じかみる
        return self.find(x) == self.find(y)


N,M=map(int,input().split())
K=[set() for i in range(M)]
tree=Unionfindtree(N)
for i in range(N):
    L=[int(i)-1 for i in input().split()]
    for m in L[1:]:
        K[m].add(i)
for i in range(M):
    Ki=list(K[i])
    if len(Ki)==0:
        continue
    for h in range(len(Ki)):
        tree.union(Ki[h],Ki[0])
for i in range(N):
    if not tree.connect(0,i):
        print('NO')
        sys.exit()
print('YES')
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque,defaultdict
import sys
input = sys.stdin.readline
N,M=map(int,input().split())
mod =10**7
table=defaultdict(set)
visit=defaultdict(int)
for i in range(M):
    a,b,c=map(int,input().split())
    table[a].add(a+c*mod)
    table[b].add(b+c*mod)
    table[a+c*mod].add(a)
    table[b+c*mod].add(b)
    table[a+c*mod].add(b+c*mod)
    table[b+c*mod].add(a+c*mod)
    visit[a]=0
    visit[b]=0
    visit[b+c*mod]=0
    visit[a+c*mod]=0

H=deque()
H.append((1,0))
visit[1]=1
ans=mod
while H:
    #print(H)
    x,cost=H.popleft()
    visit[x] = 1
    if x==N:
        ans=min(ans,cost)
        break
    for y in table[x]:
        if visit[y]==1:
            continue
        if x<=10**5 and mod<=y:
            H.append((y,cost+1))
        else:
            H.appendleft((y,cost))
if ans==mod:
    print(-1)
else:
    print(ans)

Fixed submission:
from collections import deque,defaultdict
import sys
input = sys.stdin.readline
N,M=map(int,input().split())
mod =10**7
table=defaultdict(set)
visit=defaultdict(int)
for i in range(M):
    a,b,c=map(int,input().split())
    table[a].add(a+c*mod)
    table[b].add(b+c*mod)
    table[a+c*mod].add(a)
    table[b+c*mod].add(b)
    table[a+c*mod].add(b+c*mod)
    table[b+c*mod].add(a+c*mod)
    visit[a]=0
    visit[b]=0
    visit[b+c*mod]=0
    visit[a+c*mod]=0

H=deque()
H.append((1,0))
visit[1]=1
ans=mod
while H:
    #print(H)
    x,cost=H.popleft()
    visit[x] = 1
    if x==N:
        ans=min(ans,cost)
        break
    for y in table[x]:
        if visit[y]==1:
            continue
        if x<=10**5 and mod<=y:
            H.append((y,cost+1))
        else:
            H.appendleft((y,cost))
if ans==mod:
    print(-1)
else:
    print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
from bisect import bisect
N=int(input())
X=[int(i) for i in input().split()]
L=int(input())
Q=int(input())
#T=[[int(i) for i in input().split()] for i in range(Q)]
T=[]
for i in range(Q):
    a,b=map(int,input().split())
    if a>b:
        a,b=b,a
    T.append((a-1,b-1))
F=[0]*N
for i in range(N):
    F[i]= bisect(X, X[i] + L) -1
#print(F)
dp=[ [N-1] * (N) for i in range(17)]

for i in range(N):
    #dp[0][i]=i
    dp[0][i]=F[i]
for c in range(1,17):
    for i in range(N):
        dp[c][i] = dp[c-1][ dp[c-1][i] ]
#print(dp)

def f(a,b):
    num=0
    t = a
    while True:
        for i in range(17):
            if dp[i][t]>=b:
                s=i
                break
        if s==0:
            num+=1
            break
        num += pow(2, s - 1)
        t = dp[s-1][t]
    print(num)
for a,b in T:
    f(a,b)



Fixed submission:
import sys
input = sys.stdin.readline
from bisect import bisect
N=int(input())
X=[int(i) for i in input().split()]
L=int(input())
Q=int(input())
#T=[[int(i) for i in input().split()] for i in range(Q)]
T=[]
for i in range(Q):
    a,b=map(int,input().split())
    if a>b:
        a,b=b,a
    T.append((a-1,b-1))
F=[0]*N
for i in range(N):
    F[i]= bisect(X, X[i] + L) -1
#print(F)
dp=[ [N-1] * (N) for i in range(18)]

for i in range(N):
    #dp[0][i]=i
    dp[0][i]=F[i]
for c in range(1,18):
    for i in range(N):
        dp[c][i] = dp[c-1][ dp[c-1][i] ]
#print(dp)

def f(a,b):
    num=0
    t = a
    while True:
        for i in range(18):
            if dp[i][t]>=b:
                s=i
                break
        if s==0:
            num+=1
            break
        num += pow(2, s - 1)
        t = dp[s-1][t]
    print(num)
for a,b in T:
    f(a,b)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
from bisect import bisect
N=int(input())
X=[int(i) for i in input().split()]
L=int(input())
Q=int(input())
#T=[[int(i) for i in input().split()] for i in range(Q)]
T=[]
for i in range(Q):
    a,b=map(int,input().split())
    if a>b:
        a,b=b,a
    T.append((a-1,b-1))
F=[0]*N
for i in range(N):
    F[i]= bisect(X, X[i] + L) -1
for a,b in T:
    k=F[a]
    num=1
    while k<b:
        num+=1
        k=F[k]
    print(num)

Fixed submission:
import sys
input = sys.stdin.readline
from bisect import bisect
N=int(input())
X=[int(i) for i in input().split()]
L=int(input())
Q=int(input())
#T=[[int(i) for i in input().split()] for i in range(Q)]
T=[]
for i in range(Q):
    a,b=map(int,input().split())
    if a>b:
        a,b=b,a
    T.append((a-1,b-1))
F=[0]*N
for i in range(N):
    F[i]= bisect(X, X[i] + L) -1
#print(F)
dp=[ [N-1] * (N) for i in range(18)]

for i in range(N):
    #dp[0][i]=i
    dp[0][i]=F[i]
for c in range(1,18):
    for i in range(N):
        dp[c][i] = dp[c-1][ dp[c-1][i] ]
#print(dp)

def f(a,b):
    num=0
    t = a
    while True:
        for i in range(18):
            if dp[i][t]>=b:
                s=i
                break
        if s==0:
            num+=1
            break
        num += pow(2, s - 1)
        t = dp[s-1][t]
    print(num)
for a,b in T:
    f(a,b)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
s=input()
l=len(s)
dp=[[0]*(N+2) for i in range(N)]
dp[0][1]=2
dp[0][0]=1
mod=10**9+7
for i in range(N-1):
    for j in range(i+2):
        if j==0:
            dp[i+1][j+1]+=2*dp[i][j]
            dp[i+1][j+1]%=mod
            dp[i+1][j]+=dp[i][j]
            dp[i+1][j]%=mod            
            continue
        dp[i+1][j+1]+=2*dp[i][j]
        dp[i+1][j+1]%=mod
        dp[i+1][j-1]+=dp[i][j]
        dp[i+1][j-1]%=mod  
t=pow(2,(mod-2),mod)
t=pow(t,l,mod)
print((dp[-1][l]*t)%mod)


Fixed submission:
N=int(input())
s=input()
l=len(s)
dp=[[0]*(N+1) for i in range(N)]
dp[0][1]=2
dp[0][0]=1
mod=10**9+7
for i in range(N-1):
    for j in range(N):
        if j==0:
            dp[i+1][j+1]+=2*dp[i][j]
            dp[i+1][j+1]%=mod
            dp[i+1][j]+=dp[i][j]
            dp[i+1][j]%=mod            
            continue
        if j!=N:
            dp[i+1][j+1]+=2*dp[i][j]
            dp[i+1][j+1]%=mod
        dp[i+1][j-1]+=dp[i][j]
        dp[i+1][j-1]%=mod  
t=pow(2,(mod-2),mod)
t=pow(t,l,mod)
print((dp[-1][l]*t)%mod)
Buggy python submission (verdict: Runtime Error):
import sys
N,K=map(int,input().split())
D=[int(i) for i in input().split()]
L=[0]*10
for i in range(K):
    L[D[i]]=1
for i in range(N,10000):
    x=str(i)
    flag=True
    for k in range(4):
        y=int(x[k])
        if L[y]==1:
            flag=False
    if flag:
        print(i)
        sys.exit()

Fixed submission:
import sys
N,K=map(int,input().split())
D=[int(i) for i in input().split()]
L=[0]*10
for i in range(K):
    L[D[i]]=1
for i in range(N,100001):
    x=str(i)
    flag=True
    for k in range(len(x)):
        y=int(x[k])
        if L[y]==1:
            flag=False
    if flag:
        print(i)
        sys.exit()
Buggy python submission (verdict: Runtime Error):
import math
a, b, k = [int(i) for i in input().split()]

gcd = math.gcd(a, b)
list_gcd = list()

for i in range(1, int(gcd/2) + 1):
    if gcd % i == 0:
        list_gcd.append(i)

list_gcd.append(gcd)
print(list_gcd[-k])


Fixed submission:
a, b, k = [int(i) for i in input().split()]

x = max(a, b)
y = min(a, b)
gcd = 0
if x % y == 0:
    gcd = y
else:
    while x % y != 0:
        z = x % y
        x = y
        y = z
    else:
        gcd = z

list_gcd = list()

for i in range(1, int(gcd/2) + 1):
    if gcd % i == 0:
        list_gcd.append(i)

list_gcd.append(gcd)
print(list_gcd[-k])

Buggy python submission (verdict: Runtime Error):
a, b, k = [int(i) for i in input().split()]

gcd = math.gcd(a, b)
list_gcd = list()

for i in range(1, int(gcd/2) + 1):
    if gcd % i == 0:
        list_gcd.append(i)

list_gcd.append(gcd)
print(list_gcd[-k])


Fixed submission:
a, b, k = [int(i) for i in input().split()]

x = max(a, b)
y = min(a, b)
gcd = 0
if x % y == 0:
    gcd = y
else:
    while x % y != 0:
        z = x % y
        x = y
        y = z
    else:
        gcd = z

list_gcd = list()

for i in range(1, int(gcd/2) + 1):
    if gcd % i == 0:
        list_gcd.append(i)

list_gcd.append(gcd)
print(list_gcd[-k])
Buggy python submission (verdict: Runtime Error):
import copy
A = list(map(int, input().split()))

a = max(A)
AA = copy.deepcopy(A)
AA.remove(a)
b = max(AA)

for hoge in A:
  if hoge == a:
    print(b)
  else:
    print(a)

Fixed submission:
import copy
N = int(input())
A = []
for _ in range(N):
  A.append(int(input()))
a = max(A)
AA = copy.deepcopy(A)
AA.remove(a)
b = max(AA)

for hoge in A:
  if hoge == a:
    print(b)
  else:
    print(a)

Buggy python submission (verdict: Runtime Error):
import copy
A = list(map(int, input().split))

a = max(A)
AA = copy.deepcopy(A)
AA.remove(a)
b = max(AA)

for hoge in A:
  if hoge == a:
    print(b)
  else:
    print(a)

Fixed submission:
import copy
N = int(input())
A = []
for _ in range(N):
  A.append(int(input()))
a = max(A)
AA = copy.deepcopy(A)
AA.remove(a)
b = max(AA)

for hoge in A:
  if hoge == a:
    print(b)
  else:
    print(a)
Buggy python submission (verdict: Runtime Error):
N=int(int(input())/2)
N-=(N+1)%2
a=sorted(input().split())
print(int(a[N+1])-int(a[N]))

Fixed submission:
N=int(int(input())/2)
a=sorted(list(map(int,input().split())))
print(int(a[N])-int(a[N-1]))

Buggy python submission (verdict: Runtime Error):
N=int(int(input())/2)
a=sorted(input().split())
print(int(a[N+1])-int(a[N]))

Fixed submission:
N=int(int(input())/2)
a=sorted(list(map(int,input().split())))
print(int(a[N])-int(a[N-1]))

Buggy python submission (verdict: Runtime Error):
N = int(input()) / 2
a = input().split()

if a[N] == a[N + 1]:
    print(0)
else:
    print(int(a[N+1]) - int(a[N]))

Fixed submission:
N=int(int(input())/2)
a=sorted(list(map(int,input().split())))
print(int(a[N])-int(a[N-1]))

Buggy python submission (verdict: Runtime Error):
N = int(input()) / 2
a = input().split()

if a[N] == a[N + 1]:
    print(0)
else:
    print(a[N+1] - a[N])

Fixed submission:
N=int(int(input())/2)
a=sorted(list(map(int,input().split())))
print(int(a[N])-int(a[N-1]))
Buggy python submission (verdict: Runtime Error):
import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n, k = list(map(int, input().split()))

if n == k:
    print(1)
    for _ in range(k-1):
        print(0)
    
    exit()

for i in range(1,k+1):
    ans = comb(n - k + 1, i) * math.factorial(k - 1) // math.factorial(k-i) // math.factorial(i-1)
    print(ans % 1000000007)


Fixed submission:
import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n, k = list(map(int, input().split()))

for i in range(1,k+1):
    if n - k + 1 >= i:
        ans = comb(n - k + 1, i) * math.factorial(k - 1) // math.factorial(k-i) // math.factorial(i-1)
        print(ans % 1000000007)
    else:
        print(0)

Buggy python submission (verdict: Runtime Error):
import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n, k = list(map(int, input().split()))

for i in range(1,k+1):
    ans = comb(n - k + 1, i) * math.factorial(k - 1) // math.factorial(k-i) // math.factorial(i-1)
    print(ans % 1000000007)

Fixed submission:
import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n, k = list(map(int, input().split()))

for i in range(1,k+1):
    if n - k + 1 >= i:
        ans = comb(n - k + 1, i) * math.factorial(k - 1) // math.factorial(k-i) // math.factorial(i-1)
        print(ans % 1000000007)
    else:
        print(0)
Buggy python submission (verdict: Runtime Error):
a, b=list(map(int, input().split))
print(a-b+1)

Fixed submission:
a, b=list(map(int, input().split()))
print(a-b+1)
Buggy python submission (verdict: Time Limit Exceeded):
N, W = list(map(int, input().split()))
W += 1
A = [[0] * W for _ in range(N)]
wi, vi = list(map(int, input().split()))

for w in range(W):
    A[0][w] = 0 if w < wi else vi

for i in range(1, N):
    wi, vi = list(map(int, input().split()))
    for w in range(W):
        A[i][w] = max([
            A[i-1][w_] + vi for w_ in range(w - wi + 1)
        ] + [A[i-1][w]])

print(max(A[-1]))

Fixed submission:
N, W = list(map(int, input().split()))
W += 1
A = [0] * W
wi, vi = list(map(int, input().split()))
A[wi] = vi

for _ in range(N-1):
    wi, vi = list(map(int, input().split()))
    tmp = [0] * W

    for w in range(W):
        if w-wi < 0:
            tmp[w] = A[w]
        else:
            tmp[w] = max(A[w-wi] + vi, A[w])

    A = tmp

print(max(A))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = list(map(int, input().split()))

def A(i, j):
    if i == j:
        return 0
    elif j == i + 1:
        return sum(a[i:i+2])
    else:
        S = sum(a[i:j+1])
        return min([A(i, k) + A(k+1, j) for k in range(i, j)]) + S

print(A(0, N-1))

Fixed submission:
N = int(input())
a = list(map(int, input().split()))

A = [[0 for __ in range(N)] for _ in range(N)]
S = [[0 for __ in range(N)] for _ in range(N)]

for i in range(N-1):
    for j in range(i, N):
        S[i][j] = sum(a[i:j+1])

for w in range(1, N):
    for i in range(N):
        j = i + w
        if j >= N:
            break
        
        A[i][j] = min([
            A[i][k] + A[k+1][j] for k in range(i, j)
        ]) + S[i][j]

print(A[0][-1])
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = list(input())

c = 0
for i in s:
  if i == "E":
    c+=1

min = c


for i in range(n):
  if s[i] == s[i+1]:
    if s[i] == "W":
      c+=1
    else:
      c-=1
  if c < min:
    min = c

temp = 0
for i in range(n-1):
  if s[i] == "W":
    temp += 1
  
if temp < min:
  min = temp 

print(min)


Fixed submission:
n = int(input())
s = list(input())
 
c = 0
for i in range(1,n):
  if s[i] == "E":
    c+=1
 
min = c
 
 
for i in range(n-1):
  if s[i] == s[i+1]:
    if s[i] == "W":
      c+=1
    else:
      c-=1
  if c < min:
    min = c
 
print(min)
Buggy python submission (verdict: Runtime Error):
N = int(input())
tmp = [0,0,0]
data=list(map(int,(input()).split()))
flag = True
for i in range(N):
  tmp = list(map(int,(input()).split()))
  if (tmp[0] - data[0])%2 == (tmp[1] + tmp[2] - data[1] - data[2]) % 2 + 1:
    flag = False
    break
  else:
    data = tmp

if flag:
  print("Yes")
else:
  print("No")

Fixed submission:
N = int(input())
tmp = [0,0,0]
data = [0,0,0]
flag = True
for i in range(N):
  tmp = list(map(int,(input()).split()))
  if (tmp[0] - data[0])%2 == (tmp[1] + tmp[2] - data[1] - data[2]) % 2 + 1 or (tmp[1] - data[1] + tmp[2] - data[2] > tmp[0] - data[0]):
    flag = False
    break
  else:
    data = tmp

if flag:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
print(['vowel','consonant'][['a','e','i','o','u'].in(input())])

Fixed submission:
print("vowel" if input() in ["a","e","i","o","u"] else "consonant")
Buggy python submission (verdict: Runtime Error):
(lambda n,k: print(0 if k==1 else n-k))(*map(int,input().split())

Fixed submission:
(lambda n,k: print(0 if k==1 else n-k))(*list(map(int,input().split())))
Buggy python submission (verdict: Runtime Error):
(lambda __g, __y, __operator, __print: [[(a.sort(), [(lambda __items, __after, __sentinel: __y(lambda __this: lambda: (lambda __i: [(lambda __after: [__after() for __g['mx'] in [(__operator.isub(__g['mx'], i))]][0] if (i < 0) else [__after() for __g['mn'] in [(__operator.isub(__g['mn'], i))]][0])(lambda: __this()) for __g['i'] in [(__i)]][0] if __i is not __sentinel else __after())(next(__items, __sentinel)))())(iter(a[1:-1]), lambda: (__print((mx - mn)), [(lambda __items, __after, __sentinel: __y(lambda __this: lambda: (lambda __i: [(lambda __after: (__print(((str(mx) + ' ') + str(i))), [__after() for __g['mx'] in [(__operator.isub(__g['mx'], i))]][0])[1] if (i < 0) else (__print(((str(mn) + ' ') + str(i))), [__after() for __g['mn'] in [(__operator.isub(__g['mn'], i))]][0])[1])(lambda: __this()) for __g['i'] in [(__i)]][0] if __i is not __sentinel else __after())(next(__items, __sentinel)))())(iter(a[1:-1]), lambda: (__print(((str(mx) + ' ') + str(mn))), None)[1], []) for (__g['mn'], __g['mx']) in [((a[0], a[-1]))]][0])[1], []) for (__g['mn'], __g['mx']) in [((a[0], a[-1]))]][0])[1] for __g['a'] in [(list(map(int, input().split())))]][0] for __g['n'] in [(int(input()))]][0])(globals(), (lambda f: (lambda x: x(x))(lambda y: f(lambda: y(y)()))), __import__('operator', level=0), __import__('builtins', level=0).__dict__['print'])

Fixed submission:
n,a=int(input()),sorted(list(map(int,input().split())))
mn,mx=a[0],a[-1]
for i in a[1:-1]:
  if i<0:mx-=i
  else:mn-=i
print(mx-mn)
mn,mx=a[0],a[-1]
for i in a[1:-1]:
  if i<0:print(mx,i);mx-=i
  else:print(mn,i);mn-=i
print(mx,mn)
Buggy python submission (verdict: Time Limit Exceeded):
def solve(n,a,b):
    dp=[0]*(n+1)
    for w in range(n+1): dp[w]=max(w,dp[w-a[0]]+b[0]if w-a[0]>=0 else w,dp[w-a[1]]+b[1]if w-a[1]>=0 else w,dp[w-a[2]]+b[2]if w-a[2]>=0 else w)
    return dp[-1]
N,A,B=int(input()),list(map(int, input().split())),list(map(int, input().split()))
print(solve(solve(N,A,B),B,A))

Fixed submission:
def solve(n,a,b):
    dp=[0]*(n+1)
    for w in range(n+1): dp[w]=max(w,dp[w-a[0]]+b[0]if w-a[0]>=0 else w,dp[w-a[1]]+b[1]if w-a[1]>=0 else w,dp[w-a[2]]+b[2]if w-a[2]>=0 else w)
    return dp[-1]
N,A,B=int(input()),list(map(int, input().split())),list(map(int, input().split()))
print(solve(solve(N,A,B),B,A))

Buggy python submission (verdict: Runtime Error):
(lambda __g, __y, __print: [[(__print(solve(solve(N, A, B), B, A)), None)[1] for (__g['N'], __g['A'], __g['B']) in [((int(input()), list(map(int, input().split())), list(map(int, input().split()))))]][0] for __g['solve'], solve.__name__ in [(lambda n, a, b: (lambda __l: [[(lambda __items, __after, __sentinel: __y(lambda __this: lambda: (lambda __i: [[__this() for __l['dp'][__l['w']] in [(max(__l['w'], ((__l['dp'][(__l['w'] - __l['a'][0])] + __l['b'][0]) if ((__l['w'] - __l['a'][0]) >= 0) else __l['w']), ((__l['dp'][(__l['w'] - __l['a'][1])] + __l['b'][1]) if ((__l['w'] - __l['a'][1]) >= 0) else __l['w']), ((__l['dp'][(__l['w'] - __l['a'][2])] + __l['b'][2]) if ((__l['w'] - __l['a'][2]) >= 0) else __l['w'])))]][0] for __l['w'] in [(__i)]][0] if __i is not __sentinel else __after())(next(__items, __sentinel)))())(iter(range((__l['n'] + 1))), lambda: __l['dp'][-1], []) for __l['dp'] in [(([0] * (__l['n'] + 1)))]][0] for __l['n'], __l['a'], __l['b'] in [(n, a, b)]][0])({}), 'solve')]][0])(globals(), (lambda f: (lambda x: x(x))(lambda y: f(lambda: y(y)()))), __import__('builtins', level=0).__dict__['print'])

Fixed submission:
def solve(n,a,b):
    dp=[0]*(n+1)
    for w in range(n+1): dp[w]=max(w,dp[w-a[0]]+b[0]if w-a[0]>=0 else w,dp[w-a[1]]+b[1]if w-a[1]>=0 else w,dp[w-a[2]]+b[2]if w-a[2]>=0 else w)
    return dp[-1]
N,A,B=int(input()),list(map(int, input().split())),list(map(int, input().split()))
print(solve(solve(N,A,B),B,A))
Buggy python submission (verdict: Time Limit Exceeded):
A, B = map(int, input().split())
target_list = input().split()

def check_list(lis):
    # print(lis)
    return len(list(set(target_list))) == 1

count = 0
while check_list(target_list) == False:
    min_in_list = min(target_list)
    tmp = A - 1 
    while((target_list[tmp] != min_in_list) or (target_list[tmp] == target_list[tmp-1])):
        tmp -= 1
    min_pos = tmp
    if(min_pos - B) >= 0:
        for i in range(min_pos-(B-1), min_pos):
            target_list[i] = min_in_list
    else:
        for i in range(0, min_pos+1):
            target_list[i] = min_in_list
        for i in range(A-(B-min_pos-1), A):
            target_list[i] = min_in_list

    count += 1

print(count)



Fixed submission:
import math
i, j = map(int, input().split())
target_list = list(map(int, input().split()))
print(math.ceil((i-1)/(j-1)))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
array = []

for i in range(n):
    array.append(int(input()))

m = max(array)
c = array.count(m)

for e in array:
    sa = array[:]
    if e != m:
        print(m)
    else:
        if 1 < c:
            print(m)
        else:
            sa.remove(m)
            print(max(sa))


Fixed submission:
n = int(input())
array = []

for i in range(n):
    array.append(int(input()))

m = max(array)
c = array.count(m)
sa = array[:]
sa.remove(m)
m2 = max(sa)

for e in array:

    if e != m:
        print(m)
    else:
        if 1 < c:
            print(m)
        else:
            print(m2)
Buggy python submission (verdict: Runtime Error):
s = int(input())

x1 = 0
y1 = 0
x2 = int(s ** 0.5)
y3 = -(-s // x2)
x3 = 1
y2 = x2 * y3 - s
if y3 > 10 ** 9:
    a
print(x1, y1, x2, y2, x3, y3)


Fixed submission:
s = int(input())

x1 = 0
y1 = 0
x2 = int(s ** 0.5)
y3 = -(-s // x2)
x3 = 1
if y3 > 10 ** 9:
    x2 += 1
    y3 = -(-s // x2)
y2 = x2 * y3 - s
print(x1, y1, x2, y2, x3, y3)

Buggy python submission (verdict: Runtime Error):
s = int(input())

x1 = 0
y1 = 0
x2 = int(s ** 0.5)
y3 = -(-s // x2)
x3 = 1
y2 = x2 * y3 - s
if x2 * y3 - x3 * y2 != s or x2 > 10 ** 9 or y3 > 10 ** 9:
    a
print(x1, y1, x2, y2, x3, y3)


Fixed submission:
s = int(input())

x1 = 0
y1 = 0
x2 = int(s ** 0.5)
y3 = -(-s // x2)
x3 = 1
if y3 > 10 ** 9:
    x2 += 1
    y3 = -(-s // x2)
y2 = x2 * y3 - s
print(x1, y1, x2, y2, x3, y3)