Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n = int(input())

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

L = sum(a)

nagasa = 0

ans = 0

i=0

for i in range(n):
  nagasa += a[i]
  if nagasa == L/2:
    break
  elif nagasa > L/2:
    if i == 0:
      sa = abs(nagasa - L/2)
    elif i == n-1:
      sa = abs(L/2-sum(a[0:i-1])
    else:
      sa = min(abs(nagasa - L/2),abs(L/2-sum(a[0:i-1])))
    
    ans = int(sa * 2)
    break
    

print(ans)



    



Fixed submission:
n = int(input())

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

L = sum(a)

nagasa = 0

ans = 0

i=0

for i in range(n):
  nagasa += a[i]
  if nagasa*2 >= L:
    ans = min(abs(L - (nagasa *2)), abs(L - ((nagasa-a[i])*2)))

    break
    

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

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

L = sum(a)

nagasa = 0

ans = 0

i=0
while(i < len(a)):
  nagasa += a[i]
  if nagasa == L/2:
    break
  elif nagasa > L/2:
    sa1 = L/2 - sum(a[0:i])
    sa2 = nagasa - L/2
  
    if sa1 < sa2:
      # 後ろを減らす
      a[i] -= 1
    else:
      # 前を減らす
      a[i-1] -= 1
    
    L = sum(a)
    ans += 1
    i = 0
    nagasa = 0
  else:
    i+=1

print(ans)



    



Fixed submission:
n = int(input())

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

L = sum(a)

nagasa = 0

ans = 0

i=0

for i in range(n):
  nagasa += a[i]
  if nagasa*2 >= L:
    ans = min(abs(L - (nagasa *2)), abs(L - ((nagasa-a[i])*2)))

    break
    

print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())

# コピー
m = n

# 素因数分解
a = []
while n % 2 == 0:
    a.append(2)
    n //= 2
f = 3
while f * f <= n:
    if n % f == 0:
        a.append(f)
        n //= f
    else:
        f += 2
if n != 1:
    a.append(n)


x=1

for i in a[::-1]:
  x *= i
  if x*x >= m:
    break

y = m // x
ans = x + y -2

print(ans)



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

if a <= 9 and b <= 9:
  print(a*b)
else:
  print(-1)
Buggy python submission (verdict: Runtime Error):
N = int(input())
D = list(map(int, input().split()))

for x in range(N):
  for y in range(x+1,N):
    ans += D[x] * D[y]

print(ans)



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

ans = 0
for x in range(N):
  for y in range(x+1,N):
    ans += D[x] * D[y]

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

# ABが互いにそなら答えは１

ans = 0
import math

if math.gcd(A,B) == 1:
  ans = 1
else:
  # 公約数を求める
  cdlist =[]

  for i in range(1, min(A,B) + 1):
    if A % i == 0 and B % i == 0:
      cdlist.append(i)

  # print(cdlist)

  for i,cd1 in enumerate(cdlist):
    for cd2 in cdlist[i+1:]:
      # print(cd1,cd2)
      if math.gcd(cd1,cd2) == 1:
        ans += 1

print(ans)



Fixed submission:
# 素因数分解
def prime_factorize(n):
    a = []
    # ２で割れなくなるまで割る
    while n % 2 == 0:
        a.append(2)
        n //= 2
    # 奇数で割り続けていく
    # 本当は素数で割り続けていくのが良い
    f = 3
    # 二乗して超えたら終了
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    # 最後の一つ
    if n != 1:
        a.append(n)
    return a
    
A, B = map(int, input().split())
A_list = set(prime_factorize(A))
B_list = set(prime_factorize(B))

print(len(A_list & B_list) + 1)
Buggy python submission (verdict: Runtime Error):
import heapq

N,M = map(int,input().split())

A = [int(i)*-1 for i in input().split()]
heapq.heapify(A)

for _ in range(M):
  max = heapq.heappop(A) * -1
  heapq.heappush(A,(max//2)*-1)





print(sum(A)*-1)  




Fixed submission:
N=input()
a=''
if N[0] =='S':
  a='Cloudy'
elif N[0] =='C':
  a='Rainy'
else:
  a='Sunny'

print(a)

Buggy python submission (verdict: Runtime Error):
N=input()
a
if N[0] =='S':
  a='Cloudy'
elif N[0] =='C':
  a='Rainy'
else:
  a='Sunny'

print(a)
  


Fixed submission:
N=input()
a=''
if N[0] =='S':
  a='Cloudy'
elif N[0] =='C':
  a='Rainy'
else:
  a='Sunny'

print(a)

Buggy python submission (verdict: Runtime Error):
N=input()
a
if N[0] =='S':
  a='Cloudy'
elif N[0] =='C':
  a='Rainy'
else:
  a='Sunny'

ptint(a)
  


Fixed submission:
N=input()
a=''
if N[0] =='S':
  a='Cloudy'
elif N[0] =='C':
  a='Rainy'
else:
  a='Sunny'

print(a)

Buggy python submission (verdict: Runtime Error):
N=input()
a
if N[0] ='S':
  a='Cloudy'
elif N[0] ='C':
  a='Rainy'
else:
  a='Sunny'

ptint(a)
  

Fixed submission:
N=input()
a=''
if N[0] =='S':
  a='Cloudy'
elif N[0] =='C':
  a='Rainy'
else:
  a='Sunny'

print(a)
Buggy python submission (verdict: Runtime Error):
import heapq

N,M = map(int,input().split())

A = [int(i)*-1 for i in input().split()]
heapq.heapify(A)

for _ in range(M):
  print(A)
  max = heapq.heappop(A) * -1
  heapq.heappush(A,(max//2)*-1)





print(sum(A)*-1)  




Fixed submission:
import heapq

N,M = map(int,input().split())

A = [int(i)*-1 for i in input().split()]
heapq.heapify(A)

for _ in range(M):
  max = heapq.heappop(A) * -1
  heapq.heappush(A,(max//2)*-1)





print(sum(A)*-1)

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

A = list(map(int,input().split()))


A.sort()
for _ in range(M):
    A[N-1] = A[N-1] // 2
    A.sort()

print(sum(A))  




Fixed submission:
import heapq

N,M = map(int,input().split())

A = [int(i)*-1 for i in input().split()]
heapq.heapify(A)

for _ in range(M):
  max = heapq.heappop(A) * -1
  heapq.heappush(A,(max//2)*-1)





print(sum(A)*-1)
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

N, Q = map(int,input().split())

# AB = [[int(x) for x in input().split()] for _ in range(N-1)]

# print(AB)

# 添字を1からにしたいのでN+1
graph = [[] for _ in range(N+1)]

# 各頂点に隣接する頂点
for _ in range(N-1):
    a, b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)

# print(graph)
counter = [0] * (N+1)

# print(counter)

# PX = [[int(x) for x in input().split()] for _ in range(Q)]

# 各頂点に点数を足す
for _ in range(Q):
  p, x = map(int, input().split())
  counter[p] += x


def shori(pa,c,val):
  val += counter[c]
  counter[c] = val
  for i in graph[c]:
    if i == pa:
      continue
    shori(c,i,val)
  
shori(0,1,0)
  

print(" ".join(map(str, counter[1:])))




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

if a >= 3200:
  print(s)
else:
  print('red')
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = []

for i in range(n):
  s.append(input())
  s[i] = sorted(s[i])

cnt = 0
for i in range(n):
  for j in range(i+1,n):
    if s[i] == s[j]:
      cnt += 1
  
print(cnt)  

Fixed submission:
import sys

n = int(input())

d = {}
cnt = 0

for i in range(n):
  s = ''.join(sorted(input()))
  if s in d.keys():
    d[s] += 1
    cnt += d[s]
  else:
    d[s] = 0
  
  
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a_i = list(map(int,input().split()))

def solve():
    ans = 0
    count = 0
    for i in range(1, 1000001):
        if i in a_i:
            flag = 0
            for j in range(n):
                if i != a_i[j] and i % a_i[j] == 0:
                    break
                elif i == a_i[j] and flag == 0:
                    flag = 1
                elif i == a_i[j] and flag == 1:
                    break
            else:
                ans += 1
            count += 1
        if count == n:
            break
    return ans

print(solve())

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
num_list = [0] * 1000001
 
def solve():
    ans = 0
    for i in range(n):
        if num_list[a[i]] == 0:
            num_list[a[i]] += 1
            for j in range(2, (1000000 // a[i]) + 1):
                num_list[j * a[i]] += 1
        elif num_list[a[i]] == 1:
            num_list[a[i]] += 1
    for i in range(n):
        if num_list[a[i]] == 1:
            ans += 1
    return ans
 
print(solve())

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

def solve():
    ans = 0
    for i in range(n):
        for j in range(n):
            if j == i:
                continue
            if a_i[i] % a_i[j] == 0:
                break
        else:
            ans += 1
    return ans

print(solve())

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
num_list = [0] * 1000001
 
def solve():
    ans = 0
    for i in range(n):
        if num_list[a[i]] == 0:
            num_list[a[i]] += 1
            for j in range(2, (1000000 // a[i]) + 1):
                num_list[j * a[i]] += 1
        elif num_list[a[i]] == 1:
            num_list[a[i]] += 1
    for i in range(n):
        if num_list[a[i]] == 1:
            ans += 1
    return ans
 
print(solve())
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a_i = input().split()
ans = ""
for i in range(len(a_i)):
  ans += str(a_i.index(str(i+1)) + 1)
  if i != (len(a_i) - 1):
    ans += " "
print(ans)

Fixed submission:
n = int(input())
a_i = input().split()
ans = ""
ans_l = [0] * n
for i in range(len(a_i)):
  ans_l[int(a_i[i])-1] = i + 1
for j in range(n):
  ans += str(ans_l[j])
  if j != (n - 1):
    ans += " "
print(ans)
Buggy python submission (verdict: Runtime Error):
n = input()
print(n / 3)

Fixed submission:
n = int(input())
print(int(n / 3))

Buggy python submission (verdict: Runtime Error):
n = input()
print(n // 3)

Fixed submission:
n = int(input())
print(int(n / 3))
Buggy python submission (verdict: Runtime Error):
money = for(int(i) for i in input().sprit())
mod = money[0] % 500
if money[1] >= mod:
  print("Yes")
else:
  print("No")


Fixed submission:
money = int(input())
coins = int(input())
mod = money % 500
if coins >= mod:
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Runtime Error):
money = for(int(i) in i = input().sprit())
mod = money[0] % 500
if money[1] >= mod:
  print("Yes")
else:
  print("No")

Fixed submission:
money = int(input())
coins = int(input())
mod = money % 500
if coins >= mod:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
ab = (int(i) for i in input().sprit())
print("Even" if ab[0]%2==0||ab[1]%2==0 else"Odd")

Fixed submission:
ab = list(int(i) for i in input().split())
print("Even" if (ab[0] % 2 == 0 or ab[1] % 2 == 0) else "Odd")
Buggy python submission (verdict: Runtime Error):
date = input()
print("2018"  + data[4:])

Fixed submission:
date = input()
print("2018"  + date[4:])
Buggy python submission (verdict: Runtime Error):
nab = list(int(i) for i in range(input().split()))
if nab[0] * nab[1] < nab[2]:
    print(nab[0] * nab[1])
else:
    print(nab[2])

Fixed submission:
nab = list(int(i) for i in input().split())
if nab[0] * nab[1] < nab[2]:
    print(nab[0] * nab[1])
else:
    print(nab[2])
Buggy python submission (verdict: Runtime Error):
xs = map(int, input().split())
for i in range(len(xs)):
    if xs[i] == 0:
        print(i+1)


Fixed submission:
xs = list(map(int, input().split()))
for i in range(len(xs)):
    if xs[i] == 0:
        print(i+1)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))

for i in range(1,N+1):
  print(np.count_nonzero(A == i))

Fixed submission:
N = int(input())
A = map(int, input().split())
subs = [0] * N

for boss in A:
  subs[boss-1] += 1

for i in range(N):
  print(subs[i])
Buggy python submission (verdict: Runtime Error):
a=map(int,input().split())
for i in range(1,6):
    if a[i-1]==0:
        print(i)
        break

Fixed submission:
a=list(map(int,input().split()))
for i in range(1,6):
    if a[i-1]==0:
        print(i)
        break
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
import math
a=list(map(int,input().split()))
d=dict()
for i in range(n):
    if d.get(a[i],None)==None:
        d[a[i]]=0
    d[a[i]]+=1 
ans=0
s=d.keys()
for i in range(n):
    if d[a[i]]>1:
        continue 
    flag=True
    # print(a[i],end='    s\n')
    for ii in range(1,math.ceil(a[i]**(1/2))+1):
        if (a[i]%ii)==0:
            aa,bb=ii,a[i]//ii
            if aa!=a[i] and aa in s:
                # print(aa)
                # print('aa')
                flag=False
                break
            if bb!=a[i] and bb in s:
                # print('bb')
                # print(bb)
                flag=False
                break
    if(flag):
        # print(a[i])
        ans+=1
print(ans)
        
    

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
m=max(a)
dp=[0 for i in range(m+1)]
ans=0
for i in range(n):
    if dp[a[i]]>=1:
        dp[a[i]]+=1
        continue
    for j in range(2*a[i],m+1,a[i]):
        dp[j]+=1 
    dp[a[i]]=1
for i in range(n):
    if dp[a[i]]==1:
        ans+=1 
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
a=list(map(int,input().split()))
d=[999999999999999]*n
d[0]=0
for i in range(1,n):
    for j in range(1,k+1):
        if i-j<0:
            break 
        d[i]=min(d[i],d[i-j]+abs(a[i]-a[i-j]))
print(d[n-1])

Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))
d=[999999999999999]*n
d[0]=0
for i in range(1,n):
    for j in range(1,k+1):
        if i-j<0:
            break 
        d[i]=min(d[i],d[i-j]+abs(a[i]-a[i-j]))
print(d[n-1])
Buggy python submission (verdict: Runtime Error):
ma=999999999
n,W=map(int,input().split())
w=[]
v=[]
for _ in range(n):
    a,b=map(int,input().split())
    w.append(a)
    v.append(b)
dp=[[ma for j in range(n+1)] for i in range(sum(v)+1)]
for i in range(len(dp)):
    dp[i][0]=0
for i in range(1,sum(v)+1):
    for j in range(n):
        if v[j]>i:
            continue 
        elif v[j]<=i and j==0:
            if i==v[j]:
                if dp[i][j]==0:
                    dp[i][j]=ma
                dp[i][j]=min(w[j],dp[i][j])
                print(i,j,w[j])
                print(dp[30])
        elif v[j]<=i and j!=0:
            if dp[i-v[j]][j-1]!=ma:
                dp[i-v[j]][j-1]=min(dp[i-v[j]][j-1]+w[j],dp[i][j])
print(dp[30])
print(dp[60])
print(dp[110])
print(dp[90])
print(dp[80])
print(dp[140])

ans=0
for i in range(1,sum(v)+1):
    for j in range(n):
        if dp[i][j]!=ma or dp[i][j]!=0:
            if dp[i][j]<=W:
                ans=i 
print(ans)

Fixed submission:
n,W=map(int,input().split())
sumv=0
v,w=[],[]
m=10**9
for i in range(n):
    a,b=map(int,input().split())
    w.append(a)
    v.append(b)
    sumv+=b
dp=[m]*(sumv+1)
dp[0]=0
for i in range(n):
    for j in range(sumv,v[i]-1,-1):
        dp[j]=min(dp[j],dp[j-v[i]]+w[i])
ans=0

for i in range(sumv+1):
    if dp[i]<=W:
        ans=i 
# print(dp)
print(ans)
Buggy python submission (verdict: Runtime Error):
s=input()
t=input()
dp=[[0]*(len(t)+1) for i in range(len(s)+1)]
for i in range(1,len(s)+1):
    for j in range(1,len(t)+1):
        if s[i-1]==t[j-1]:
            dp[i][j]=1+dp[i-1][j-1]
        else:
            dp[i][j]=max(dp[i-1][j],dp[i][j-1])
ans=''
i=len(s)
j=len(t)
while(i>0 and j>0):
    # print(i,j,dp[i][j-1],dp[i-1][j],s[i],t[j])
    # print(ans)
    if s[i-1]==t[j-1]:
        ans=s[i]+ans
        i-=1 
        j-=1 
    else:
        if dp[i][j-1]>dp[i-1][j]:
            j-=1
            # print('here')
        else:
            i-=1 
print(ans)

Fixed submission:
s=input()
t=input()
dp=[[0]*(len(t)+1) for i in range(len(s)+1)]
for i in range(1,len(s)+1):
    for j in range(1,len(t)+1):
        if s[i-1]==t[j-1]:
            dp[i][j]=1+dp[i-1][j-1]
        else:
            dp[i][j]=max(dp[i-1][j],dp[i][j-1])
ans=''
i=len(s)
j=len(t)
while(i>0 and j>0):
    # print(i,j,dp[i][j-1],dp[i-1][j],s[i],t[j])
    # print(ans)
    if s[i-1]==t[j-1]:
        ans=s[i-1]+ans
        i-=1 
        j-=1 
    else:
        if dp[i][j-1]>dp[i-1][j]:
            j-=1
            # print('here')
        else:
            i-=1 
print(ans)
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
adj=[]
dp=[0 for i in range(0,n+1)]
def dfs(i,p,adj,dp):
    # print(i)
    # print(i,p)
    if dp[i]!=0:
        return dp[i]
    for j in (adj[i]):
        if j==p:
            continue 
        else:
            dfs(j,i,adj,dp)
            dp[i]=max(dp[i],1+dp[j])
    return dp[i]
    
for i in range(n+1):
    adj.append([])
for _ in range(m):
    u,v=map(int,input().split())
    adj[u].append(v)

for i in range(1,n+1):
    if dp[i]==0:
        dfs(i,i,adj,dp)
# print(dp)
print(max(dp))

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
n,m=map(int,input().split())
adj=[]
dp=[0 for i in range(0,n+1)]
def dfs(i,p,adj,dp):
    # print(i)
    # print(i,p)
    if dp[i]!=0:
        return dp[i]
    for j in (adj[i]):
        if j==p:
            continue 
        else:
            dfs(j,i,adj,dp)
            dp[i]=max(dp[i],1+dp[j])
    return dp[i]
    
for i in range(n+1):
    adj.append([])
for _ in range(m):
    u,v=map(int,input().split())
    adj[u].append(v)

for i in range(1,n+1):
    if dp[i]==0:
        dfs(i,i,adj,dp)
# print(dp)
print(max(dp))

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
adj=[]
dp=[0 for i in range(0,n+1)]
def dfs(i,p,adj,dp):
    # print(i)
    # print(i,p)
    if dp[i]!=0:
        return dp[i]
    for j in (adj[i]):
        if j==p:
            continue 
        else:
            dfs(j,i,adj,dp)
            dp[i]=max(dp[i],1+dp[j])
    return dp[i]
    
for i in range(n+1):
    adj.append([])
for _ in range(m):
    u,v=map(int,input().split())
    adj[u].append(v)

for i in range(1,n+1):
    if dp[i]==0:
        dfs(i,i,adj,dp)
# print(dp)
print(max(dp))

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
n,m=map(int,input().split())
adj=[]
dp=[0 for i in range(0,n+1)]
def dfs(i,p,adj,dp):
    # print(i)
    # print(i,p)
    if dp[i]!=0:
        return dp[i]
    for j in (adj[i]):
        if j==p:
            continue 
        else:
            dfs(j,i,adj,dp)
            dp[i]=max(dp[i],1+dp[j])
    return dp[i]
    
for i in range(n+1):
    adj.append([])
for _ in range(m):
    u,v=map(int,input().split())
    adj[u].append(v)

for i in range(1,n+1):
    if dp[i]==0:
        dfs(i,i,adj,dp)
# print(dp)
print(max(dp))
Buggy python submission (verdict: Runtime Error):
n=int(sys.stdin.readline())
a=list(map(int,sys.stdin.readline().split()))
dp=[[0 for i in range(n)] for j in range(n)]
for i in range(n):
    dp[i][i]=a[i]
for i in range(2,n+1):
    for j in range(n-i+1):
        k=j+i-1 
        dp[j][k]=max(a[k]-dp[j][k-1],a[j]-dp[j+1][k])
print(dp[0][len(a)-1])

Fixed submission:
import sys
n=int(sys.stdin.readline())
a=list(map(int,sys.stdin.readline().split()))
dp=[[0 for i in range(n)] for j in range(n)]
for i in range(n):
    dp[i][i]=a[i]
for i in range(2,n+1):
    for j in range(n-i+1):
        k=j+i-1 
        dp[j][k]=max(a[k]-dp[j][k-1],a[j]-dp[j+1][k])
print(dp[0][len(a)-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**6)
n=int(sys.stdin.readline())
a=list(map(int,sys.stdin.readline().split()))
d=dict()
def help(a,i,j):
    if d.get(str(i)+" "+str(j),None)!=None:
        return d[str(i)+" "+str(j)]
    if j<i:
        return 0
    if i==j:
        return a[i]
    t1=a[i]-help(a,i+1,j)
    t2=a[j]-help(a,i,j-1)
    # print(i,j)
    # print(t1,t2)
    if t1>t2:
        d[str(i)+" "+str(j)]=t1 
    else:
        d[str(i)+" "+str(j)]=t2 
    return d[str(i)+" "+str(j)]
print(help(a,0,len(a)-1))

Fixed submission:
import sys
n=int(sys.stdin.readline())
a=list(map(int,sys.stdin.readline().split()))
dp=[[0 for i in range(n)] for j in range(n)]
for i in range(n):
    dp[i][i]=a[i]
for i in range(2,n+1):
    for j in range(n-i+1):
        k=j+i-1 
        dp[j][k]=max(a[k]-dp[j][k-1],a[j]-dp[j+1][k])
print(dp[0][len(a)-1])

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
import sys
sys.setrecursionlimit(10**6)
a=list(map(int,input().split()))
d=dict()
def help(a,i,j):
    if d.get(str(i)+" "+str(j),None)!=None:
        return d[str(i)+" "+str(j)]
    if j<i:
        return 0
    if i==j:
        return a[i]
    t1=a[i]-help(a,i+1,j)
    t2=a[j]-help(a,i,j-1)
    # print(i,j)
    # print(t1,t2)
    if t1>t2:
        d[str(i)+" "+str(j)]=t1 
    else:
        d[str(i)+" "+str(j)]=t2 
    return d[str(i)+" "+str(j)]
print(help(a,0,len(a)-1))

Fixed submission:
import sys
n=int(sys.stdin.readline())
a=list(map(int,sys.stdin.readline().split()))
dp=[[0 for i in range(n)] for j in range(n)]
for i in range(n):
    dp[i][i]=a[i]
for i in range(2,n+1):
    for j in range(n-i+1):
        k=j+i-1 
        dp[j][k]=max(a[k]-dp[j][k-1],a[j]-dp[j+1][k])
print(dp[0][len(a)-1])
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = [[int(x) for x in input().split()] for i in range(n)]
dp = [-1 for i in range(1 << n)]
dp[0] = 1
def gethelp(bit, i):
    if dp[bit] != -1:
        return dp[bit]
    else:
        tmp = 0
        for j in range(n):
            if bit & (1 << j) and a[i][j]:
                tmp += gethelp(bit ^ (1 << j), i+1)
    dp[bit] = tmp % mod
    return dp[bit]
print(gethelp(2**n-1, 0))

Fixed submission:
n = int(input())
a = [[int(x) for x in input().split()] for i in range(n)]
dp = [-1 for i in range(1 << n)]
dp[0] = 1
mod=10**9+7
def gethelp(bit, i):
    if dp[bit] != -1:
        return dp[bit]
    else:
        tmp = 0
        for j in range(n):
            if bit & (1 << j) and a[i][j]:
                tmp += gethelp(bit ^ (1 << j), i+1)
    dp[bit] = tmp % mod
    return dp[bit]
print(gethelp(2**n-1, 0))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**6+10)
def gethelp(mask1,mask2,ind):
    # print(mask1,mask2)
    global n,a,dp
   
    if dp.get(str(mask1)+' '+str(mask2),None)!=None:
        return dp[str(mask1)+' '+str(mask2)]
    dp[str(mask1)+' '+str(mask2)]=0
    for i in range(ind+1,n):
        if (mask1&(1<<i))==1:
            continue
        for j in range(n):
            if (mask2&(1<<j))==1:
                continue
            if a[i][j]==1:
                # andand (mask2&(1<<j))==0:
                # print('here ',end=' ')
                # print(i,j)
                dp[str(mask1)+' '+str(mask2)]+=gethelp(mask1|(1<<i),mask2|(1<<j),i)
    
    return dp[str(mask1)+' '+str(mask2)]
n=int(input())
a=[list() for i in range(n)]
for _ in range(n):
    a[_]=list(map(int,input().split()))
dp=dict()
dp[str((1<<n)-1)+' '+str((1<<n)-1)]=1 
# print(dp)
t=gethelp(0,0,-1)
# print(dp)/
print(t)

Fixed submission:
n = int(input())
a = [[int(x) for x in input().split()] for i in range(n)]
dp = [-1 for i in range(1 << n)]
dp[0] = 1
mod=10**9+7
def gethelp(bit, i):
    if dp[bit] != -1:
        return dp[bit]
    else:
        tmp = 0
        for j in range(n):
            if bit & (1 << j) and a[i][j]:
                tmp += gethelp(bit ^ (1 << j), i+1)
    dp[bit] = tmp % mod
    return dp[bit]
print(gethelp(2**n-1, 0))
Buggy python submission (verdict: Runtime Error):
n=int(input())
adj=[[] for i in range(n+1)]
dp=[[-1,-1] for i in range(n+1)]
mod=10**9 +7
def dfs(node,parent,color):
    if dp[node][color]!=-1:
        return dp[node][color]
    count=1
    if color==0:
        for i in adj[node]:
            if i==parent:
                continue
            temp=(dfs(i,node,0)+dfs(i,node,1))%mod
            count=(count*temp)%mod
    else:
        for i in adj[node]:
            if i==parent:
                continue
            temp=dfs(i,node,0)%mod
            count=(count*temp)%mod
    dp[node][color]=count
    return count
for _ in range(n-1):
    u,v=map(int,input().split())
    adj[u].append(v)
    adj[v].append(u)
print((dfs(1,-1,0)+dfs(1,-1,1))%mod)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
n=int(input())
adj=[[] for i in range(n+1)]
dp=[[-1,-1] for i in range(n+1)]
mod=10**9 +7
def dfs(node,parent,color):
    if dp[node][color]!=-1:
        return dp[node][color]
    count=1
    if color==0:
        for i in adj[node]:
            if i==parent:
                continue
            temp=(dfs(i,node,0)+dfs(i,node,1))%mod
            count=(count*temp)%mod
    else:
        for i in adj[node]:
            if i==parent:
                continue
            temp=dfs(i,node,0)%mod
            count=(count*temp)%mod
    dp[node][color]=count
    return count
for _ in range(n-1):
    u,v=map(int,input().split())
    adj[u].append(v)
    adj[v].append(u)
print((dfs(1,-1,0)+dfs(1,-1,1))%mod)