Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N = int(input())
l = list(map(int, input().split()))

cnt = 0
for i in range(0, len(l), 2):
  if l[i] % 2 != 0:
    cnt += 1

print(cnt)

Fixed submission:
L, R, d = map(int, input().split())
  
cnt = 0
for i in range(L, R+1, 1):
  if i % d == 0:
    cnt += 1

print(cnt)

Buggy python submission (verdict: Runtime Error):
N = int(input())
l = list(map(int, input().split()))

cnt = 0
for i in range(0, min(N, len(l)), 2):
  if l[i] % 2 != 0:
    cnt += 1

print(cnt)

Fixed submission:
L, R, d = map(int, input().split())
  
cnt = 0
for i in range(L, R+1, 1):
  if i % d == 0:
    cnt += 1

print(cnt)

Buggy python submission (verdict: Runtime Error):
N = int(input())
l = list(map(int, input().split()))

cnt = 0
for i in range(0, N, 2):
  if l[i] % 2 != 0:
    cnt += 1

print(cnt)

Fixed submission:
L, R, d = map(int, input().split())
  
cnt = 0
for i in range(L, R+1, 1):
  if i % d == 0:
    cnt += 1

print(cnt)

Buggy python submission (verdict: Runtime Error):
N = int(input())
l = list(map(int, input().split()))

cnt = 0
for i in range(1, N+1, 2):
  if l[i-1] % 2 != 0:
    cnt += 1

print(cnt)

Fixed submission:
L, R, d = map(int, input().split())
  
cnt = 0
for i in range(L, R+1, 1):
  if i % d == 0:
    cnt += 1

print(cnt)
Buggy python submission (verdict: Runtime Error):
N = input()

if N < 1000:
  out = 1000 - N
elif N % 1000 < 500:
  out = N % 1000
else:
  out = 1000 - N % 1000

print(out)

Fixed submission:
N = int(input())
if N % 1000 == 0:
  print(0)
else:
  print(1000 - N % 1000)

Buggy python submission (verdict: Runtime Error):
N = input()
  
if N < 1000:
  out = 1000 - N
elif N % 1000 < 500:
  out = N % 1000
else:
  out = 1000 - N % 1000

print(out)

Fixed submission:
N = int(input())
if N % 1000 == 0:
  print(0)
else:
  print(1000 - N % 1000)
Buggy python submission (verdict: Runtime Error):
s = input()
t = input()
ls = len(s)
lt = len(t)

ans = 0
for i in range(ls-lt+1):
  same = 0
  for j in range(lt):
    ind = i+lt
    if s[ind]==t[j]:
      same += 1
  ans = min(ans,min)
print(ans)

Fixed submission:
s = input()
t = input()
ls = len(s)
lt = len(t)

ans = 0
for i in range(ls-lt+1):
  same = 0
  for j in range(lt):
    ind = i+j
    if s[ind]==t[j]:
      same += 1
  ans = max(ans,same)
print(lt-ans)
Buggy python submission (verdict: Runtime Error):
s = "zabcdefghijklmnopqrstuvwxy"
n = int(input())
ans = ""
while(n>0):
    r = n%26
    if r==0:
        r = 26
    ans = s[r] + ans
    n -= r
    n //=26
print(ans)

Fixed submission:
s = "zabcdefghijklmnopqrstuvwxyz"
n = int(input())
ans = ""
while(n>0):
    r = n%26
    if r==0:
        r = 26
    ans = s[r] + ans
    n -= r
    n //=26
print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
ans = ""
while(n>0):
    r = n%26
    if r==0:
        r = 26
    ans = s[r] + ans
    n -= r
    n //=26
print(ans)

Fixed submission:
s = "zabcdefghijklmnopqrstuvwxyz"
n = int(input())
ans = ""
while(n>0):
    r = n%26
    if r==0:
        r = 26
    ans = s[r] + ans
    n -= r
    n //=26
print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
ans = ""
while(n>0):
    r = n%26
    if r==0:
        r = 26
    ans = s[r] + ans
    n -= r
    n //=26

Fixed submission:
s = "zabcdefghijklmnopqrstuvwxyz"
n = int(input())
ans = ""
while(n>0):
    r = n%26
    if r==0:
        r = 26
    ans = s[r] + ans
    n -= r
    n //=26
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
#abc_167_D
#doubling 
#類題:agc_006_c

n,k = [int(i) for i in input().split()]
a   = [int(i)-1 for i in input().split()]

#do doubling
s = list(range(n))
while k>0:
    if k&1:
        s = [s[a[i]] for i in range(n)]
    a = [a[a[i]] for i in range(n)]
    k >>= 1
    
#初期値0に対するk移動後の位置は、s[0]で求まる,
print(s[0]+1)


'''
pos = 1
move= 0
colors = [-1]*(n+1)

while(colors[pos]==-1):
    colors[pos] = move
    move += 1
    pos = a[pos]
    if move==k:
        print(pos)
        break
else:
    turn = move - colors[pos]
    rest = (k-colors[pos]) % turn
    while rest:
        pos = a[pos]
        rest -= 1
    print(pos)
'''

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

pos = 1
move= 0
colors = [-1]*(n+1)

while(colors[pos]==-1):
    colors[pos] = move
    move += 1
    pos = a[pos]
    if move==k:
        print(pos)
        break
else:
    turn = move - colors[pos]
    rest = (k-colors[pos]) % turn
    while rest:
        pos = a[pos]
        rest -= 1
    print(pos)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
n = int(input())

d = defaultdict(int)
for _ in range(n):
    s = input()
    d[s] += 1

max_k_list = [kv[0] for kv in d.items() if kv[1] == max(d.values())]
#print(max_k_list)
# ['a', 'd']

max_k_list.sort()
for v in max_k_list:
    print(v)

Fixed submission:
n = int(input())
d = dict()

maxi = 0
for _ in range(n):
    s = input()
    if s not in d:
        d[s] = 1
    else:
        d[s] += 1
    maxi = max(maxi, d[s])
    
max_k_list = [kv[0] for kv in d.items() if kv[1] == maxi]
#print(max_k_list)
# ['a', 'd']

max_k_list.sort()
for v in max_k_list:
    print(v)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(x) for x in input().split()]

def hoge(a):
    for i in range(n):
        for j in range(i+1, n):
            if a[i]==a[j]:
                return "NO"
    return "YES"

print(hoge(a))

Fixed submission:
n = int(input())
a = [int(x) for x in input().split()]

a.sort()
for i in range(n-1):
    if a[i]==a[i+1]:
        print("NO")
        break
else:
    print("YES")
Buggy python submission (verdict: Time Limit Exceeded):
n,k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = []
for i in range(n):
    b.append((1+a[i])/2)
    
ans = sum(b[:k])
for i in range(1,n-k+1):
    ans= max(sum(b[i:i+k]), ans)    
print(ans)

Fixed submission:
from itertools import accumulate
n,k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = []

num = 0
maxi= 0
l = list(accumulate([0] + a))
for i in range(0,n-k+1):
    if l[i+k] - l[i] > maxi:
        maxi = l[i+k] - l[i]
        num = i  

for i in range(n):
    b.append((1+a[i])/2)
    
ans = sum(b[num:k+num])
print(ans)
Buggy python submission (verdict: Runtime Error):
s = input()
k = int(input())

ss = s + s

if len(set(s)==1):
    print(int((len(s)*k)/2))
else:
    a=0
    prev = "?"
    for v in s:
        if v==prev:
            a += 1
            prev = "?"
        else:
            prev = v

    b=0
    prev = "?"
    for v in ss:
        if v==prev:
            b += 1
            prev = "?"
        else:
            prev = v

    print(a+(b-a)*(k-1))

Fixed submission:
s = input()
k = int(input())

ss = s + s

if len(set(s))==1:
    print(int((len(s)*k)/2))
else:
    a=0
    prev = "?"
    for v in s:
        if v==prev:
            a += 1
            prev = "?"
        else:
            prev = v

    b=0
    prev = "?"
    for v in ss:
        if v==prev:
            b += 1
            prev = "?"
        else:
            prev = v

    print(a+(b-a)*(k-1))
Buggy python submission (verdict: Runtime Error):
#素因数分解をする
from fraction import gcd
import numpy as np
a,b = [int(i) for i in input().split()]
g = gcd(a,b)

primes = []
n=1

#約数に関して、常に、これが言える。
while n**2 <=g:
    n += 1
    q,r = divmod(g,n)
    if r!=0:
        continue
    while r==0:
        g = q
        q,r = divmod(g,n)
    primes.append(n)

#最後に素数が余るケース    
if g != 1:
    primes.append(g)
    
print(len(primes)+1)



Fixed submission:
#素因数分解をする
from fractions import gcd
import numpy as np
a,b = [int(i) for i in input().split()]
g = gcd(a,b)

primes = []
n=1

#約数に関して、常に、これが言える。
while n**2 <=g:
    n += 1
    q,r = divmod(g,n)
    if r!=0:
        continue
    while r==0:
        g = q
        q,r = divmod(g,n)
    primes.append(n)

#最後に素数が余るケース    
if g != 1:
    primes.append(g)
    
print(len(primes)+1)

Buggy python submission (verdict: Runtime Error):
#素因数分解をする
from math import gcd
import numpy as np
a,b = [int(i) for i in input().split()]
g = gcd(a,b)

primes = []
n=1

#約数に関して、常に、これが言える。
while n**2 <=g:
    n += 1
    q,r = divmod(g,n)
    if r!=0:
        continue
    while r==0:
        g = q
        q,r = divmod(g,n)
    primes.append(n)

#最後に素数が余るケース    
if g != 1:
    primes.append(g)
    
print(len(primes)+1)



Fixed submission:
#素因数分解をする
from fractions import gcd
import numpy as np
a,b = [int(i) for i in input().split()]
g = gcd(a,b)

primes = []
n=1

#約数に関して、常に、これが言える。
while n**2 <=g:
    n += 1
    q,r = divmod(g,n)
    if r!=0:
        continue
    while r==0:
        g = q
        q,r = divmod(g,n)
    primes.append(n)

#最後に素数が余るケース    
if g != 1:
    primes.append(g)
    
print(len(primes)+1)
Buggy python submission (verdict: Runtime Error):
#dpがやや特殊なので、1次元的に走査したほうがよさそう。initializeもいらないし。
n,m = map(int, input().split())

inf = 10**9

dp =[inf for _ in range(2**n)]
dp[0] = 0

for i in range(m):
    a,b = map(int, input().split())
    d = sum((1<<(i-1)) for i in map(int, input().split()))
  
    for j in range(2**n):
        jord = j | d
        dp[i][jord] = min(dp[i][jord], dp[i][j] + a)
            
if dp[-1] == inf:
    print(-1)
else:
    print(dp[-1])

Fixed submission:
#dpがやや特殊なので、1次元的に走査したほうがよさそう。initializeもいらないし。
n,m = map(int, input().split())

inf = 10**9

dp =[inf for _ in range(2**n)]
dp[0] = 0

for i in range(m):
    a,b = map(int, input().split())
    d = sum((1<<(i-1)) for i in map(int, input().split()))
  
    for j in range(2**n):
        jord = j | d
        dp[jord] = min(dp[jord], dp[j] + a)
            
if dp[-1] == inf:
    print(-1)
else:
    print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int, input().split())

inf = 10**9

dp = [[inf for _ in range(2**n)]] * m
dp[0][0] = 0

for i in range(m):
    a,b = map(int, input().split())
    d = sum((1<<(i-1)) for i in map(int, input().split()))
  
    #initialize
    if i==0:
        dp[0][d] = a
        continue
        
    for j in range(2**n):
        jord = j | d
        dp[i][jord] = min(dp[i-1][jord], dp[i-1][j] + a, dp[i][jord])
            
if dp[m-1][2**n-1] == inf:
    print(-1)
else:
    print(dp[m-1][2**n-1])

Fixed submission:
#dpがやや特殊なので、1次元的に走査したほうがよさそう。initializeもいらないし。
n,m = map(int, input().split())

inf = 10**9

dp =[inf for _ in range(2**n)]
dp[0] = 0

for i in range(m):
    a,b = map(int, input().split())
    d = sum((1<<(i-1)) for i in map(int, input().split()))
  
    for j in range(2**n):
        jord = j | d
        dp[jord] = min(dp[jord], dp[j] + a)
            
if dp[-1] == inf:
    print(-1)
else:
    print(dp[-1])

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

dp = [[int("inf") for _ in range(2**n)] for _ in range(m)]
dp[0][0] = 0

for i in range(m):
    a,b = map(int, input().split())
    d = sum((1<<(i-1)) for i in map(int, input().split()))
    for j in range(2**n):
        jord = j | d
        
        #initialize
        if i==0:
            dp[0][d] = a
        else:
            dp[i][jord] = min(dp[i-1][jord], dp[i-1][j] + a)
            
if dp[m-1][2**n-1] == int("inf"):
    print(-1)
else:
    print(dp[m-1][2**n-1])

Fixed submission:
#dpがやや特殊なので、1次元的に走査したほうがよさそう。initializeもいらないし。
n,m = map(int, input().split())

inf = 10**9

dp =[inf for _ in range(2**n)]
dp[0] = 0

for i in range(m):
    a,b = map(int, input().split())
    d = sum((1<<(i-1)) for i in map(int, input().split()))
  
    for j in range(2**n):
        jord = j | d
        dp[jord] = min(dp[jord], dp[j] + a)
            
if dp[-1] == inf:
    print(-1)
else:
    print(dp[-1])
Buggy python submission (verdict: Runtime Error):
#138-e
from collections import defaultdict
import bisect

s = input()
t = input()
n = len(s)
m = len(t)

ans=0
pos=-1

d = defaultdict(list)
for i in range(n):
    if s[i] in t:
        d[s[i]].append(i)
        
for i in range(n):
    if s[i] in t:
        d[s[i]].append(i+n)
        
for v in t:
    l = d[v]
    ind = bisect.bisect_right(l, pos)
    ans += l[ind]-pos
    if l:
        if l[ind]<n:
            pos = l[ind]
        else:
            pos = l[ind] - n
    else:
        ans = -1
        break
        
print(ans)
        



Fixed submission:
from collections import defaultdict
import bisect

s = input()
t = input()

n = len(s)
m = len(t)

d = defaultdict(list)

for i,c in enumerate(s):
    if c in t:
        d[c].append(i)

for i,c in enumerate(s):
    if c in t:
        d[c].append(i+n)

pos = -1
ans = 0

for c in t:
    l = d[c]
    if l:
        ind = bisect.bisect_right(l, pos)
        ans += l[ind]-pos
        if l[ind] >= n:
            pos = l[ind] - n
        else:
            pos = l[ind]    
    else:
        ans = -1
        break

print(ans)

Buggy python submission (verdict: Runtime Error):
seq = input()
sub = input()

n = len(seq)
m = len(sub)

sums = 0
pos  = -1

for i in range(m):
  char = sub[i]
  add  = 0
  pos += 1
  add += 1
  while(char != seq[pos]):
    add +=1
    pos = (pos + 1) % n
    if add > n :
      print(-1)
      exit()
  sums += add 

print(sums)
    

Fixed submission:
from collections import defaultdict
import bisect

s = input()
t = input()

n = len(s)
m = len(t)

d = defaultdict(list)

for i,c in enumerate(s):
    if c in t:
        d[c].append(i)

for i,c in enumerate(s):
    if c in t:
        d[c].append(i+n)

pos = -1
ans = 0

for c in t:
    l = d[c]
    if l:
        ind = bisect.bisect_right(l, pos)
        ans += l[ind]-pos
        if l[ind] >= n:
            pos = l[ind] - n
        else:
            pos = l[ind]    
    else:
        ans = -1
        break

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
x = input()
m = len(x)
x = int(x)

p = m//2
q = m%2

if q==1:
  if p==0:
    print(x)
    exit()
  else:
    a = 90
    while(p>0):
      x -= a
      a *= 100
    print(x)
    exit()
else:
  if p==0:
    print(0)
    exit()
  else:
    x = 0
    a = 9
    while(p>0):
      x += a
      a *= 100
    print(x)
    exit()  
    


Fixed submission:
x = input()
m = len(x)
x = int(x)

p = m//2
q = m%2

if q==1:
  if p==0:
    print(x)
    exit()
  else:
    a = 90
    while(p>0):
      x -= a
      a *= 100
      p -= 1
    print(x)
    exit()
else:
  if p==0:
    print(0)
    exit()
  else:
    x = 0
    a = 9
    while(p>0):
      x += a
      a *= 100
      p -= 1
    print(x)
    exit()
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = [int(i) for i in list(input())]
ans = True
a[0] -= 1
for i in range(1,n):
  if a[i]>a[i-1]:
    a[i] -= 1
  elif a[i]==a[i-1]:
    pass
  else:
    ans = False
    break
if ans==True:
  print("Yes")
else:
  print("No")

Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]
ans = True
a[0] -= 1
for i in range(1,n):
  if a[i]>a[i-1]:
    a[i] -= 1
  elif a[i]==a[i-1]:
    pass
  else:
    ans = False
    break
if ans==True:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
s = input()
n = len(s)
ans = [0] *n 

left = 0
i = 0

while(left<n):
  while s[i]=="R":
    i+=1
  right=i
  while s[right]=="L":
    right +=1
    if right==n-1:
      right += 1
      break

  for k in range(left, right):
    if (i-k) % 2==0:
      ans[i] += 1
    else:
      ans[i-1] += 1

  left = right
  i = left
print(*ans)




Fixed submission:
s = input()
n = len(s)
ans = [0] *n 

left = 0
i = 0

while(left<n-1):
  while s[i]=="R":
    i+=1
  right=i
  while s[right]=="L":
    if right==n-1:
      right += 1
      break        
    right +=1

  for k in range(left, right):
    if (i-k) % 2==0:
      ans[i] += 1
    else:
      ans[i-1] += 1

  left = right
  i = left
    
print(*ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
inn=[]

times=0

for i in range(5):
    inn.append(int(input()))

hoge=[0 for i in range(6)]
hoge[0]=n

while(hoge[5]!=n):
    times+=1
    for i in range(5):
        ind=4-i
        if(hoge[ind]>0):
            a=hoge[ind]
            hoge[ind] = max(0, hoge[ind]-inn[ind])
            if hoge[ind]>0:
                hoge[ind+1] += inn[ind]
            else:
                hoge[ind+1] += a


print(times)


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

times=0

for i in range(5):
    inn.append(int(input()))

mini=min(inn)

if n/mini==int(n/mini):
    print(n//mini + 4)
else:
    print(int(n//mini)+1 + 4)
Buggy python submission (verdict: Runtime Error):
hoge=input()
str=input()

dic={}
for alp in str:
    if alp in dic:
        dic[alp] += 1
    else:
        dic[alp] = 1

ans=1

for alp,num in dic.items():
    ans *= num+1)

ans -= 1
print(ans%(10**9 + 7))


Fixed submission:
hoge=input()
str=input()

dic={}
for alp in str:
    if alp in dic:
        dic[alp] += 1
    else:
        dic[alp] = 1

ans=1

for alp,num in dic.items():
    ans *= (num+1)

ans -= 1
print(ans%(10**9 + 7))
Buggy python submission (verdict: Runtime Error):
n,a,b = [int(i) for i in input().split()]

#n is the point in which to check wheter the mark is different
def f(n,a,b):
    if n==1:
        return [a,b]

    mask = 1<<(n-1)

    #if biggest bit of a == that of b
    if a & mask == b & mask:
        v1 = f(n-1, a, b)
        v2 = f(n-1, a^mask, v1[1]^mask)
        ret = a
        ret.extend(v2)
        ret.extend(v1[1:])
        return ret        
    else:
        # biggest bit of a and b is different
        v1 = f(n-1, a, a^1)
        v2 = f(n-1, a^1^mask, b)
        v1.extend(v2)
        return v1



#exclusive or
if bin(a^b).count("1") %2==0:
    print("NO")
else:
    print("YES")
    res = f(n,a,b)
    for p in res:
        print(p, end=" ")


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

#n is the point in which to check wheter the mark is different
def f(n,a,b):
    if n==1:
        return [a,b]

    mask = 1<<(n-1)

    #if biggest bit of a == that of b
    if a & mask == b & mask:
        v1 = f(n-1, a, b)
        v2 = f(n-1, a^mask, v1[1]^mask)
        ret = [a]
        ret.extend(v2)
        ret.extend(v1[1:])
        return ret        
    else:
        # biggest bit of a and b is different
        v1 = f(n-1, a, a^1)
        v2 = f(n-1, a^1^mask, b)
        v1.extend(v2)
        return v1



#exclusive or
if bin(a^b).count("1") %2==0:
    print("NO")
else:
    print("YES")
    res = f(n,a,b)
    for p in res:
        print(p, end=" ")
Buggy python submission (verdict: Time Limit Exceeded):
A, B = [int(i) for i in input().split()]
calcu = [0 for i in range(40)]

for n in range(A, B+1):
    i=0
    while n>0:
        calcu[i] = (calcu[i] + (n%2)) %2
        n = n//2
        i += 1

ans=0
for i in range(40):
    if calcu[i]==1:
        ans += 2**i
    i += 1

print(ans)


Fixed submission:
A, B = [int(i) for i in input().split()]


def xor(a,b):
    sum=0
    i=0
    while(b>0):
        sum += (2**i) * ((a%2 + b%2)%2)
        a = a//2
        b = b//2
        i += 1
    return sum



def f(n):
    m=(n+1)//2
    if n%2==0:
        if m%2==0:
            return n
        else:
            return n+1
    else:
        if m%2==0:
            return 0
        else:
            return 1

if A==0:
    print(f(B))
else:
    print(f(A-1) ^ f(B))
Buggy python submission (verdict: Runtime Error):
N,A,B,C=[int(i) for i in input().split()]
l=[int(input()) for _ in range(n)]
INF=10**18

def dfs(cur, a, b, c):
    if cur==N:
        return abs(a-A)+abs(b-B)+abs(c-C)-30 
    ret0 = dfs(cur+1,a,b,c)
    ret1 = dfs(cur+1,a+l[cur],b,c)+10
    ret2 = dfs(cur+1,a,b+l[cur],c)+10    
    ret3 = dfs(cur+1,a,b,c+l[cur])+10    
    return min(ret0,ret1,ret2,ret3)

print(dfs(0,0,0,0))

Fixed submission:
N,A,B,C=[int(i) for i in input().split()]
l=[int(input()) for _ in range(N)]
INF=10**18

def dfs(cur, a, b, c):
    if cur==N:
        return abs(a-A)+abs(b-B)+abs(c-C)-30 if min(a,b,c)>0 else INF
    ret0 = dfs(cur+1,a,b,c)
    ret1 = dfs(cur+1,a+l[cur],b,c)+10
    ret2 = dfs(cur+1,a,b+l[cur],c)+10
    ret3 = dfs(cur+1,a,b,c+l[cur])+10
    return min(ret0,ret1,ret2,ret3)

print(dfs(0,0,0,0))
Buggy python submission (verdict: Time Limit Exceeded):
#b
n = int(input())
a = [int(i) for i in input().split()]
sum_a = sum(a)

#s = int((n*(n-1))/2)
s = n*(n+1)//2
if sum_a%s!=0:
    print("NO")
else:
    times = sum_a//s
    stock = times
    ind = 0
    for _ in range(n):
        next_ind= (ind+1)%n
        now = a[ind]
        tsugi = a[next_ind]
        now += times
        while(tsugi!=now):
            now -= n
            stock -= 1
            if stock<0:
                print("NO")
                exit()      
        ind = next_ind
    if stock==0:
        print("YES")

Fixed submission:
#b

N, *A = map(int, open(0).read().split())
M = (N+1)*N//2
S = sum(A)
if S%M!=0:
  print('NO')
  exit()
cnt = S//M
for i in range(N):
  df = A[(i+1)%N]-A[i]
  if (cnt-df)%N!=0 or cnt<df:
    print('NO')
    break
else:
  print('YES')
Buggy python submission (verdict: Runtime Error):
#d
#the niumbers of evens is important
#the point is, there is no influence to odd/even if you divide them by odd numbers.
#You should do simulation only in the case where there is one odd over 3 and even numbers of even numbers

from math import gcd

def count(a):
    odd, even = 0,0
    for x in a:
        if x % 2 == 1: odd = odd + 1
        else: even = even + 1
    return odd,even

def deal(n,a):
    odd,even = count(a)
    if even == 0:
        return False
    if even % 2 == 1:
        return True
    if odd > 1:
        return False
    
    #the case where there is one odd (over 3) and even numbers of even numbers
    #calculate gcd by step by step
    g = 1
    for i in range(0,n):
        if a[i] % 2 == 1:
            if a[i] == 1: 
                return False
            a[i]  -= 1
        g = gcd(a[i], g)
    return not deal(n,list(map(lambda x: x//g,a)))

n = int(input())
a = [int(i) for i in input().split()]
if deal(n,a):
    print('First')
else:
    print('Second')


Fixed submission:
#d
#the niumbers of evens is important
#the point is, there is no influence to odd/even if you divide them by odd numbers.
#You should do simulation only in the case where there is one odd over 3 and even numbers of even numbers

from fractions import gcd

def count(a):
    odd, even = 0,0
    for x in a:
        if x % 2 == 1: odd = odd + 1
        else: even = even + 1
    return odd,even

def deal(n,a):
    odd,even = count(a)
    if even == 0:
        return False
    if even % 2 == 1:
        return True
    if odd > 1:
        return False
    
    #the case where there is one odd (over 3) and even numbers of even numbers
    #calculate gcd by step by step
    #if you write g = 1, it is a lie.
    if a[0] % 2 == 0:
        g = a[0]
    else:
        g = a[1]
        
    for i in range(0,n):
        if a[i] % 2 == 1:
            if a[i] == 1: 
                return False
            a[i]  -= 1
        g = gcd(a[i], g)
    return not deal(n,list(map(lambda x: x//g,a)))

n = int(input())
a = [int(i) for i in input().split()]
if deal(n,a):
    print('First')
else:
    print('Second')
Buggy python submission (verdict: Runtime Error):
#b
n = int(input())
edges = [[] for _ in range(n)]
for i in range(n-1):
    b = int(input())
    edges[b-1].append(i+1)
    
def dfs(u):
    e = edges[u]
    if e==[]:
        return 0
    #else
    #return maximum
    length = []
    for v in e:
        length.append(dfs(v))
    l = len(length)
    length.sort()
    maxi = 0
    for v in length:
        cal = v + l
        maxi= max(maxi, cal)
        l -= 1
    return maxi    
    
print(dfs(0))

Fixed submission:
#b
import sys
sys.setrecursionlimit(2 * 10 ** 5 + 10)

n = int(input())
edges = [[] for _ in range(n)]
for i in range(n-1):
    b = int(input())
    edges[b-1].append(i+1)
    
def dfs(u):
    e = edges[u]
    if e==[]:
        return 0
    #else
    #return maximum
    length = []
    for v in e:
        length.append(dfs(v))
    l = len(length)
    length.sort()
    maxi = 0
    for v in length:
        cal = v + l
        maxi= max(maxi, cal)
        l -= 1
    return maxi    
    
print(dfs(0))