Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
# import numpy as np

n = int(input())
s = input()

# dp = np.zeros([n+1, n+1])
dp = [0] * (n+1)

for dif in range(1,n):
    count = 0
    t_max = 0
    for l1_r in range(0, n-dif):
        if(s[l1_r] == s[l1_r + dif]):
            count += 1
            t_max = max(count, t_max)
            if( count == dif):
                dp[dif] = count
                break
        else:
            count = 0
    dp[dif] = t_max

print(max(dp))    

Fixed submission:
# import numpy as np

n = int(input())
s = input()

# dp = np.zeros([n+1, n+1])
dp = [0] * (n+1)

for dif in range(1,n):
    count = 0
    t_max = 0
    for l1_r in range(0, n-dif):
        if(s[l1_r] == s[l1_r + dif]):
            count += 1
            t_max = max(count, t_max)
            if( count == dif):
                dp[dif] = count
                break
        else:
            count = 0
    dp[dif] = t_max

print(max(dp))

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

n = int(input())
s = input()

dp = np.zeros([n+1, n+1])

for l1_r in range(1,n):
    for l2_r in range(l1_r+1, n+1):
        if(s[l1_r-1] == s[l2_r-1]):
            temp = dp[l1_r-1][l2_r-1]
            if( (l2_r - l1_r) > temp):
                  temp += 1
        else:
            temp = 0
        dp[l1_r][l2_r] = temp


print(int(dp.max()))


Fixed submission:
# import numpy as np

n = int(input())
s = input()

# dp = np.zeros([n+1, n+1])
dp = [0] * (n+1)

for dif in range(1,n):
    count = 0
    t_max = 0
    for l1_r in range(0, n-dif):
        if(s[l1_r] == s[l1_r + dif]):
            count += 1
            t_max = max(count, t_max)
            if( count == dif):
                dp[dif] = count
                break
        else:
            count = 0
    dp[dif] = t_max

print(max(dp))

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

# n, m = 4,4
# a_list = np.array([1,9,3,5])
n = int(input())
s = input()

ct = 0
ct_max = 0
for i in range(1,n):
    if(ct_max >= n-i)
    
    forward = s[:n-i]
    back = s[i:]
    for j in range(n-i):
        f = forward[j]
        b = back[j]
        if(f==b):
            ct += 1
            if(ct_max < ct):
                ct_max = ct*1
            if(ct_max >= i):
                break()
        else:
            ct = 0

print(ct_max)

Fixed submission:
# import numpy as np

n = int(input())
s = input()

# dp = np.zeros([n+1, n+1])
dp = [0] * (n+1)

for dif in range(1,n):
    count = 0
    t_max = 0
    for l1_r in range(0, n-dif):
        if(s[l1_r] == s[l1_r + dif]):
            count += 1
            t_max = max(count, t_max)
            if( count == dif):
                dp[dif] = count
                break
        else:
            count = 0
    dp[dif] = t_max

print(max(dp))
Buggy python submission (verdict: Runtime Error):
a,b = map(int, input.split())

ans = (b-1 + (a-2)) // (a-1)

print(ans)

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

ans = (b-1 + (a-2)) // (a-1)

print(ans)
Buggy python submission (verdict: Runtime Error):
n,q = map(int, input().split())

boss = {}
point = {}
point[n] = 0
for i in range(1,n):
    a,b = map(int, input().split())
    boss[b] = a
    point[i] = 0

for i in range(q):
    p,x = map(int, input().split())
    point[p] += x

ans = str(point[1])
for i in range(2,n+1):
    point[i] += point[boss[i]]
    ans = ans + " " + str(point[i])

print(ans)


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

from collections import deque

n,q = map(int,input().split())

edge = {}
for i in range(1,n+1):
    edge[i] = []

for i in range(n-1):
    a,b = map(int,input().split())
    edge[a].append(b)
    edge[b].append(a)

ans = [0] * (n+1)
for i in range(q):
    p,x = map(int,input().split())
    ans[p] += x

d = deque()
remains = set(range(1,n+1))
d.append(1)
remains.remove(1)

while(len(d) > 0):
    tmp = d.pop()
    for i in edge[tmp]:
        if(i in remains):
            ans[i] += ans[tmp]
            d.append(i)
            remains.remove(i)

print(' '.join(map(str, ans[1:])))
Buggy python submission (verdict: Runtime Error):
for i in range(n-1,1,-1):
    dif = h[i] - h[i-1]
    if(dif == -1):
        h[i-1] -= 1
    elif(dif < -1):
        print('No')
        exit()

print('Yes')

Fixed submission:
n = int(input())
h = list(map(int, input().split()))

for i in range(n-1,1,-1):
    dif = h[i] - h[i-1]
    if(dif == -1):
        h[i-1] -= 1
    elif(dif < -1):
        print('No')
        exit()

print('Yes')
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
mod = 10**9 + 7

dp = [[0] * 13 for _ in range(2)]
tmp = 0
for si in s:
    if(si != '?'):
        tmp = (tmp*10 + int(si)) % 13
    else:
        tmp = tmp*10 % 13

dp[0][tmp] = 1
exp10 = 1
pointer = 0
for i,si in enumerate(s[::-1]):

    if(si!='?'):
        exp10 = exp10 * 10 % 13
        continue

    pointer = 1 - pointer
    for j in range(13):
        dp[pointer][j] = 0

    for j in range(13):
        for k in range(10):
            dp[pointer][(j + exp10*k)%13] += dp[1-pointer][j]

    for j in range(13):
        dp[pointer][j] %= mod

    exp10 = exp10 * 10 % 13

print(dp[pointer][5])

Fixed submission:
s = input()
mod = 10**9 + 7

dp = [[0] * 13 for _ in range(2)]
tmp = 0
for si in s:
    if(si != '?'):
        tmp = (tmp*10 + int(si)) % 13
    else:
        tmp = tmp*10 % 13

dp[0][tmp] = 1
exp10 = 1
pointer = 0
for i,si in enumerate(s[::-1]):

    if(si!='?'):
        exp10 = exp10 * 10 % 13
        continue

    pointer = 1 - pointer
    for j in range(13):
        dp[pointer][j] = 0

    for j in range(13):
        for k in range(10):
            dp[pointer][(j + exp10*k)%13] += dp[1-pointer][j]

    for j in range(13):
        dp[pointer][j] %= mod

    exp10 = exp10 * 10 % 13

print(dp[pointer][5])
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=[int(input()) for _ in range(n)]
as=sorted(a)
m=as[-1]
for i in range(n):
    print(m if m!=a[i] else a[-2])

Fixed submission:
n=int(input())
a=[int(input()) for _ in range(n)]
a1=sorted(a)
m=a1[-1]
for i in range(n):
    print(m if m!=a[i] else a1[-2])
Buggy python submission (verdict: Runtime Error):
#import numpy as np

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

n = 3
a_s =[1,0,0]

m = 0
ans = [0]*(n+1)
#ans = np.zeros(n+1).astype(int)


i=1
for i in range(n,0,-1):
    sum_num = 0
    for j in range(i,n+1,i):
        sum_num += ans[j]

    if((sum_num & 1) != a_s[i-1]):
        m += 1
        ans[i] = 1

ans2 = []
for i in range(1,n+1):
    if ans[i]==1:
        ans2.append(i)

print(m)
print(' '.join(map(str,ans2[])))


Fixed submission:
#import numpy as np

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

m = 0
ans = [0]*(n+1)
#ans = np.zeros(n+1).astype(int)


i=1
for i in range(n,0,-1):
    sum_num = 0
    for j in range(i,n+1,i):
        sum_num += ans[j]

    if((sum_num & 1) != a_s[i-1]):
        m += 1
        ans[i] = 1

ans2 = []
for i in range(1,n+1):
    if ans[i]==1:
        ans2.append(i)

print(m)
print(' '.join(map(str,ans2)))
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
from collections import deque

mod = 10**9 + 7

n,k = map(int,input().split())
edges = {}
d = [0] * (n+1)
for i in range(1,n+1):
    edges[i] = []

for i in range(n-1):
    a,b = map(int,input().split())
    edges[a].append(b)
    edges[b].append(a)
    d[a] += 1
    d[b] += 1

for i in range(1,n+1):
    if(d[i] == 1):
        first = i
        break

d = [0] * (n+1)
d[0] = -1
d[first] = -1
dq = deque()
dq.appendleft([0,first])

ans = 1
while(len(dq) > 0):
    parent, child = dq.pop()
    d[parent] += 1
    d[child] += 1
    ans = ans * (k - d[parent]) % mod

    for i in edges[child]:
        if(i != parent):
            dq.appendleft([child, i])

print(ans)

Fixed submission:
import sys
input = sys.stdin.readline
from collections import deque

mod = 10**9 + 7

n,k = map(int,input().split())
if(n == 1):
    print(k)
    exit()


edges = {}
d = [0] * (n+1)
for i in range(1,n+1):
    edges[i] = []

for i in range(n-1):
    a,b = map(int,input().split())
    edges[a].append(b)
    edges[b].append(a)
    d[a] += 1
    d[b] += 1

for i in range(1,n+1):
    if(d[i] == 1):
        first = i
        break

d = [0] * (n+1)
d[0] = -1
d[first] = -1
dq = deque()
dq.appendleft([0,first])

ans = 1
while(len(dq) > 0):
    parent, child = dq.pop()
    d[parent] += 1
    d[child] += 1
    ans = ans * (k - d[parent]) % mod

    for i in edges[child]:
        if(i != parent):
            dq.appendleft([child, i])

print(ans)
Buggy python submission (verdict: Runtime Error):
n=input()
p=list(map(int,input().split()))
a = 0
for i in range(n-2):
    a += 1*(0<((p[i] < p[i+1])*(p[i+1] < p[i+2])))
print(a)

Fixed submission:
n=int(input())
p=list(map(int,input().split()))
a = 0
for i in range(n-2):
  a += 1-((p[i] < p[i+1])^(p[i+1] < p[i+2]))
print(a)

Buggy python submission (verdict: Runtime Error):
n=input()
p=list(map(int,input().split()))
a = 0
for i in range(n-2):
    a += (0<((p[i] < p[i+1])*(p[i+1] < p[i+2])))
print(a)

Fixed submission:
n=int(input())
p=list(map(int,input().split()))
a = 0
for i in range(n-2):
  a += 1-((p[i] < p[i+1])^(p[i+1] < p[i+2]))
print(a)
Buggy python submission (verdict: Runtime Error):
a,p = map(int,input().split())
print((3*a+b)//2)

Fixed submission:
a,p = map(int,input().split())
print((3*a+p)//2)
Buggy python submission (verdict: Runtime Error):
m,k = map(int, input().split())

if( k > 2**m):
    print(-1)
    exit()

if( (m==1) & (k==1) ):
    print(-1)
    exit()


n = 2**(m+1)
ans = [0] * n
if( k==0):
    for i in range(n):
        ans[i] = i//2
    print(' '.join([str(i) for i in ans ]))
    exit()

ans[0] = k
ind = 1
for i in range(n//2):
    if(i != k):
        ans[ind] = i
        ind += 1

ans[ind] = k
ind += 1

for i in range(n//2 -1, -1, -1):
    if(i != k):
        ans[ind] = i
        ind += 1


print(' '.join([str(i) for i in ans ]))

Fixed submission:
m,k = map(int, input().split())

if( k >= 2**m):
    print(-1)
    exit()

if( (m==1) & (k==1) ):
    print(-1)
    exit()


n = 2**(m+1)
ans = [0] * n
if( k==0):
    for i in range(n):
        ans[i] = i//2
    print(' '.join([str(i) for i in ans ]))
    exit()

ans[0] = k
ind = 1
for i in range(n//2):
    if(i != k):
        ans[ind] = i
        ind += 1

ans[ind] = k
ind += 1

for i in range(n//2 -1, -1, -1):
    if(i != k):
        ans[ind] = i
        ind += 1


print(' '.join([str(i) for i in ans ]))
Buggy python submission (verdict: Runtime Error):
a,b,t＝map(int,input().split())
print(t//a*b)


Fixed submission:
a,b,t=map(int,input().split())
print(t//a*b)

Buggy python submission (verdict: Runtime Error):
a,b,t＝map(int,input().split)
print(t//a*b)

Fixed submission:
a,b,t=map(int,input().split())
print(t//a*b)
Buggy python submission (verdict: Runtime Error):
input()
v=list(map(int,input().split())
c=list(map(int,input().split())
a=[max(0,i-j) for i,j in zip(v,c)]
print(sum(a))

Fixed submission:
input()
v=list(map(int,input().split()))
c=list(map(int,input().split()))
a=[max(0,i-j) for i,j in zip(v,c)]
print(sum(a))
Buggy python submission (verdict: Runtime Error):
n = int(readline())
a = list(map(int,read().split()))
mod = 998244353

sum_a = sum(a)
dp = [ [0] * (sum_a+1) for _ in range(n+1)]
dp_rg = [ [0] * (sum_a+1) for _ in range(n+1)]
dp_rb = [ [0] * (sum_a+1) for _ in range(n+1)]
dp_r = [ [0] * (sum_a+1) for _ in range(n+1)]
dp_r[0][0] = 1
tot = 0

for i in range(1,n+1):
    ai = a[i-1]
    tot += ai
    for j in range(tot+1):
        dp_rg[i][j] += dp_rg[i-1][j] + dp_r[i-1][j]
        dp_rb[i][j] += dp_rb[i-1][j] + dp_r[i-1][j]
        dp[i][j] += dp[i-1][j] * 2 + dp_rb[i-1][j] + dp_rg[i-1][j]

        if(j >= ai):
            dp_r[i][j] += dp_r[i-1][j-ai]
            dp_rg[i][j] += dp_rg[i-1][j-ai]
            dp_rb[i][j] += dp_rb[i-1][j-ai]
            dp[i][j] += dp[i-1][j-ai]
        dp_rg[i][j] %= mod
        dp_rb[i][j] %= mod
        dp[i][j] %= mod

r_over = sum(dp[-1][(1+sum_a)//2:]) % mod
ans = (pow(3,n,mod) - 3*pow(2,n,mod) + 3 - 3*r_over)%mod
print(ans)

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())
a = list(map(int,read().split()))
mod = 998244353

sum_a = sum(a)
dp = [ [0] * (sum_a+1) for _ in range(n+1)]
dp_rg = [ [0] * (sum_a+1) for _ in range(n+1)]
dp_rb = [ [0] * (sum_a+1) for _ in range(n+1)]
dp_r = [ [0] * (sum_a+1) for _ in range(n+1)]
dp_r[0][0] = 1
tot = 0

for i in range(1,n+1):
    ai = a[i-1]
    tot += ai
    for j in range(tot+1):
        dp_rg[i][j] += dp_rg[i-1][j] + dp_r[i-1][j]
        dp_rb[i][j] += dp_rb[i-1][j] + dp_r[i-1][j]
        dp[i][j] += dp[i-1][j] * 2 + dp_rb[i-1][j] + dp_rg[i-1][j]

        if(j >= ai):
            dp_r[i][j] += dp_r[i-1][j-ai]
            dp_rg[i][j] += dp_rg[i-1][j-ai]
            dp_rb[i][j] += dp_rb[i-1][j-ai]
            dp[i][j] += dp[i-1][j-ai]
        dp_rg[i][j] %= mod
        dp_rb[i][j] %= mod
        dp[i][j] %= mod

r_over = sum(dp[-1][(1+sum_a)//2:]) % mod
ans = (pow(3,n,mod) - 3*pow(2,n,mod) + 3 - 3*r_over)%mod
print(ans)
Buggy python submission (verdict: Runtime Error):
ans = 0
for i in range(n):
    if(h[i] == max(h[:i+1])):
        ans += 1
print(ans)

Fixed submission:
n = int(input())
h = list(map(int,input().split()))

ans = 0
for i in range(n):
    if(h[i] == max(h[:i+1])):
        ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
import os
f = open('../../input.txt', 'r')
sys.stdin = f

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

dp = [0]*(n-1)

for i in range(1,n-1):
    temp = 10**10
    for j in range(1, min(k+1, i+1) ):
        temp = min(temp, abs(h[i] - h[i-j]) + dp[i-j])
    dp[i] = temp

print(dp[n-2])


Fixed submission:
n,k = map(int, input().split())
h = list(map(int, input().split()))

dp = [0]*n

for i in range(1,n):
    temp = 10**10
    for j in range(1, min(k+1, i+1) ):
        temp = min(temp, abs(h[i] - h[i-j]) + dp[i-j])
    dp[i] = temp

print(dp[n-1])
Buggy python submission (verdict: Time Limit Exceeded):
n, w = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(n)]

dp = [[0]* (w+1) for _ in range(n+1)]

for i in range(1, n+1):
    w_temp, v_temp = wv[i-1]
    for j in range(1,w+1):
        if(j >= w_temp):
            dp[i][j] = max(dp[i-1][j],
                            dp[i-1][j-w_temp] + v_temp)
        else:
            dp[i][j] = dp[i-1][j]

print(dp[n][w])

Fixed submission:
n, w = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(n)]

dp = [[0]* (w+1) for _ in range(n+1)]

for i in range(1, n+1):
    w_temp, v_temp = wv[i-1]
    for j in range(1,w+1):
        if(j >= w_temp):
            dp[i][j] = max(dp[i-1][j],
                            dp[i-1][j-w_temp] + v_temp)
        else:
            dp[i][j] = dp[i-1][j]

print(dp[n][w])
Buggy python submission (verdict: Time Limit Exceeded):
div = 10**9 + 7

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

dp = [[0] * (n+1) for _ in range(k+1)]
dp[0] = [1]*(n+1)

for i in range(1,k+1):
    for j in range(1, n+1):
        if(i <= a[j-1]):
            dp[i][j] = dp[i-1][j] + dp[i][j-1]
        else:
            dp[i][j] = dp[i-1][j] + dp[i][j-1] - dp[i - a[j-1] - 1][j -1]

print(dp[k][n] % div)

Fixed submission:
div = 10**9 + 7

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

dp = [[0] * (n+1) for _ in range(k+1)]
dp[0] = [1]*(n+1)

for i in range(1,k+1):
    for j in range(1, n+1):
        if(i <= a[j-1]):
            dp[i][j] = (dp[i-1][j] + dp[i][j-1])%div
        else:
            dp[i][j] = (dp[i-1][j] + dp[i][j-1] - dp[i - a[j-1] - 1][j -1])%div

print(dp[k][n] % div)
Buggy python submission (verdict: Runtime Error):
A,B = map(int, input().split())

w = '.'
b = '#'

ans = [ [b]* 20 + [w] * 20 for _ in range(100)]

for i in range(A-1):
    x = 2 * i//50
    y = (i%50) * 2
    ans[y][x] = w
    
for i in range(B-1):
    x = 2 * i//50 + 21
    y = (i%50) * 2
    ans[y][x] = b
    
for i in range(100):
    print(''.join(ans[i]))

Fixed submission:
A,B = map(int, input().split())

w = '.'
b = '#'

ans = [ [b]* 20 + [w] * 20 for _ in range(100)]

for i in range(A-1):
    x = 2 * (i//50)
    y = (i%50) * 2
    ans[y][x] = w
    
for i in range(B-1):
    x = 2 * (i//50) + 21
    y = (i%50) * 2
    ans[y][x] = b
    
print('100 40')
for i in range(100):
    print(''.join(ans[i]))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())
data = list(map(int,read().split()))

def calc_g(x,k):
    while(x>=k):
        if(x%k==0):
            return x//k
        x -= (x//k) + 1
    return 0

grundy = 0
it = iter(data)
for a,k in zip(it,it):
    grundy = grundy ^ calc_g(a,k)

if(grundy==0):
    print('Aoki')
else:
    print('Takahashi')

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())
data = list(map(int,read().split()))

def calc_g(x,k):
    while(x>=k):
        if(x%k==0):
            return x//k
        fn = x//k
        x1 = x - (fn + 1)
        x2 = fn*k + (x%k)%(fn+1)
        x = min(x1,x2)
    return 0

grundy = 0
it = iter(data)
for a,k in zip(it,it):
    grundy = grundy ^ calc_g(a,k)

if(grundy==0):
    print('Aoki')
else:
    print('Takahashi')
Buggy python submission (verdict: Runtime Error):
n,k = map(int,readline().split())
ab = list(map(int,read().split()))

target = [k]
for i in range(1,30):
    if((k>>i)&1):
        target.append(( k-(1<<i)) | ((1<<i)-1) )

ans = 0
for i in target:
    val = 0
    it = iter(ab)
    for a,b in zip(it,it):
        if( a - (i&a) == 0 ):
            val += b
    ans = max(ans,val)

print(ans)

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n,k = map(int,readline().split())
ab = list(map(int,read().split()))

target = [k]
for i in range(1,30):
    if((k>>i)&1):
        target.append(( k-(1<<i)) | ((1<<i)-1) )

ans = 0
for i in target:
    val = 0
    it = iter(ab)
    for a,b in zip(it,it):
        if( a - (i&a) == 0 ):
            val += b
    ans = max(ans,val)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n,m = map(int,readline().split())
data = list(map(int,read().split()))
ab = data[:2*m]
q = data[2*m]
vdc = data[2*m+1:]

links = [[] for _ in range(n+1)]
it = iter(ab)
for a,b in zip(it,it):
    links[a].append(b)
    links[b].append(a)

ans = [0] * (n+1)
length = [-1] * (n+1)

for i in range(q-1,-1,-1):
    v,d,c = vdc[i*3:i*3+3]
    if( length[v] >= d):
        continue

    stack = [(v,d)]
    while(stack):
        vj,dj = stack.pop()
        if(ans[vj]==0):
            ans[vj] = c
        if(dj > 0):
            for vk in links[vj]:
                if( length[vk] < dj-1):
                    stack.append((vk,dj-1))

print('\n'.join(map(str,ans[1:])))

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n,m = map(int,readline().split())
data = list(map(int,read().split()))
ab = data[:2*m]
q = data[2*m]
vdc = data[2*m+1:]

links = [[] for _ in range(n+1)]
it = iter(ab)
for a,b in zip(it,it):
    links[a].append(b)
    links[b].append(a)

ans = [0] * (n+1)
length = [-1] * (n+1)

for i in range(q-1,-1,-1):
    v,d,c = vdc[i*3:i*3+3]
    if( length[v] >= d):
        continue
    length[v] = d

    stack = [(v,d)]
    while(stack):
        vj,dj = stack.pop()
        if(ans[vj]==0):
            ans[vj] = c
        if(dj > 0):
            for vk in links[vj]:
                if( length[vk] < dj-1):
                    stack.append((vk,dj-1))
                    length[vk] = dj-1

print('\n'.join(map(str,ans[1:])))
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = int(input())
if(n<s):
    print(-1)
    exit()
elif(n==s):
    print(n+1)
    exit()
elif(s==1):
    print(n+1)
    exit()

lim = 10**6
for i in range(2,lim+1):
    tmp = 0
    x = n
    while(x > 0):
        tmp += x%i
        x //= i
    if(tmp==s):
        print(i)
        exit()

#2桁
ns = n-s
inf = 10**12
ans = inf
for i in range(1,ns+1):
    if(i**2 > ns):
        break

    if(ns%i==0):
        b = ns//i + 1
        y = n-b*i
        if(i+y==s)&(y<b):
            ans = min(ans,j+1)

if(ans==inf):
    print(-1)
else:
    print(ans)

Fixed submission:
n = int(input())
s = int(input())
if(n<s):
    print(-1)
    exit()
elif(n==s):
    print(n+1)
    exit()

lim = 10**6
for i in range(2,lim+1):
    tmp = 0
    x = n
    while(x > 0):
        tmp += x%i
        x //= i
    if(tmp==s):
        print(i)
        exit()

#2桁
ns = n-s
inf = 10**12
ans = inf
for i in range(1,ns+1):
    if(i**2 > ns):
        break

    if(ns%i==0):
        b = ns//i + 1
        y = n-(b*i)
        if(i+y==s)&(0<=y<b):
            ans = min(ans,b)

if(ans==inf):
    print(-1)
else:
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
mod = 10**9+7

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

for i in range(n):
    for j in range(n):
        if(j==0):
            dp[i+1][0] += dp[i][0]
            dp[i+1][0] %= mod
            dp[i+1][1] += dp[i][0]*2
            dp[i+1][1] %= mod
        else:
            dp[i+1][j-1] += dp[i][j]
            dp[i+1][j-1] %= mod
            dp[i+1][j+1] += dp[i][j]*2
            dp[i+1][j+1] %= mod

ans = dp[-1][len(s)] * pow(pow(2,mod-2,mod),len(s),mod)
ans %= mod
print(ans)

Fixed submission:
n = int(input())
s = input()
mod = 10**9+7

dp = [0] * (n+1)
dp[0] = 1

for i in range(n):
    next = [0] * (n+1)
    for j in range(n):
        if(j==0):
            next[0] += dp[0]
            next[0] %= mod
            next[1] += dp[0]*2
            next[1] %= mod
        else:
            next[j-1] += dp[j]
            next[j-1] %= mod
            next[j+1] += dp[j]*2
            next[j+1] %= mod
    dp = next[::]

ans = dp[len(s)] * pow(pow(2,mod-2,mod),len(s),mod)
ans %= mod
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=[int(x)for x in input().split()]
c=[0]*n
for e in a:c[e-1]+=1
for e in c:print(e)

Fixed submission:
import math
print(2.*math.pi*int(input()))
Buggy python submission (verdict: Runtime Error):
a

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

ans = 0;
s = [0]*(n+1);
m = {};
for i in range(0,n):
  s[i+1] = s[i]+a[i];
for i in range(0,n+1):
  m.setdefault(s[i],0);
  m[s[i]]+=1;
for v in m.values():
  ans += v*(v-1)//2
print(ans);
Buggy python submission (verdict: Runtime Error):
import sys
n=int(input())
a = list(map(int,input().split()))
ans = 1
a.sort()
for i in range(a):
  ans *= a[i]
  if ans > 1000000000000000000:
    print(-1)
    sys.exit()
print(ans)

Fixed submission:
import sys
n=int(input())
a = list(map(int,input().split()))
ans = 1
a.sort()
for i in range(len(a)):
  ans *= a[i]
  if ans > 1000000000000000000:
    print(-1)
    sys.exit()
print(ans)
Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())
print(a - b + 1)

Fixed submission:
a, b = map(int, input().split())
print(a - b + 1)
Buggy python submission (verdict: Runtime Error):
n=int(input())
if n % 4 == 0 or n % 7 == 0:
  print("Yes");
else:
  while n > 0:
    n -= 4
    if n % 7 == 0:
      print("Yes")
      return
  print("No")

Fixed submission:
n=int(input())
if n % 4 == 0 or n % 7 == 0:
	print("Yes");
else:
	while n > 0:
		n -= 4
		if n % 7 == 0:
			print("Yes")
			exit()
	print("No")

Buggy python submission (verdict: Runtime Error):
n=int(input())
if n % 4 == 0 or n % 7 == 0:
  print("Yes");
else:
  while n > 0:
    n -= 4
    if n % 7 == 0:
      print("Yes");
      return
  print("No");
    


Fixed submission:
n=int(input())
if n % 4 == 0 or n % 7 == 0:
	print("Yes");
else:
	while n > 0:
		n -= 4
		if n % 7 == 0:
			print("Yes")
			exit()
	print("No")
Buggy python submission (verdict: Runtime Error):
n = int(input())
if n % 2 == 0:
  print n
else:
  print n * 2

Fixed submission:
n = int(input())
if n % 2 == 0:
  print(n)
else:
  print(n * 2)