Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
h,w=map(int,input().split())
grid=[list(input()) for i in range(h)]

left=[[0]*w for _ in range(h)]
for i in range(h):
  cnt=0
  for j in range(w):
    if grid[i][j]=='.':
      cnt+=1
      left[i][j]=cnt
    else:
      cnt=0
      left[i][j]=cnt
      
right=[[0]*w for _ in range(h)]
for i in range(h):
  cnt=0
  for j in range(w):
    if grid[i][w-j-1]=='.':
      cnt+=1
      right[i][j]=cnt
    else:
      cnt=0
      right[i][j]=cnt

up=[[0]*w for i in range(h)]
for i in range(w):
  cnt=0
  for j in range(h):
    if grid[j][i]=='.':
        cnt+=1
        up[j][i]=cnt
    else:
        cnt=0
        up[j][i]=cnt

down=[[0]*w for i in range(h)]
for i in range(w):
  cnt=0
  for j in range(h):
    if grid[h-j-1][i]=='.':
        cnt+=1
        down[j][i]=cnt
    else:
        cnt=0
        down[j][i]=cnt

ans=0
for i in range(h):
  for j in range(w):
    if grid[i][j]=='.':
      tmp=left[i][j]+right[i][w-j-1]+up[i][j]+down[h-i-1][j]-3
      if tmp>ans:
        ans=tmp
    else:
      continue
print(ans)
    

Fixed submission:
h,w=map(int,input().split())
grid=[list(input()) for i in range(h)]

left=[[0]*w for _ in range(h)]
for i in range(h):
  cnt=0
  for j in range(w):
    if grid[i][j]=='.':
      cnt+=1
      left[i][j]=cnt
    else:
      cnt=0
      left[i][j]=cnt
      
right=[[0]*w for _ in range(h)]
for i in range(h):
  cnt=0
  for j in range(w):
    if grid[i][w-j-1]=='.':
      cnt+=1
      right[i][j]=cnt
    else:
      cnt=0
      right[i][j]=cnt

up=[[0]*w for i in range(h)]
for i in range(w):
  cnt=0
  for j in range(h):
    if grid[j][i]=='.':
        cnt+=1
        up[j][i]=cnt
    else:
        cnt=0
        up[j][i]=cnt

down=[[0]*w for i in range(h)]
for i in range(w):
  cnt=0
  for j in range(h):
    if grid[h-j-1][i]=='.':
        cnt+=1
        down[j][i]=cnt
    else:
        cnt=0
        down[j][i]=cnt

ans=0
for i in range(h):
  for j in range(w):
    if grid[i][j]=='.':
      tmp=left[i][j]+right[i][w-j-1]+up[i][j]+down[h-i-1][j]-3
      if tmp>ans:
        ans=tmp
    else:
      continue
print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import deque,defaultdict
n=int(input())
routes=[tuple(map(int,input().split())) for i in range(n-1)]

edges=defaultdict(list)
for v1,v2,dist in routes:
  edges[v1-1].append([v2-1,dist])

ans=[0]*n
q=deque([0])
while q:
  v=q.popleft()
  if ans[v]==0:
    color=[0,1]
  else:
    color=[1,0]
  for edge in edges[v]:
    v2=edge[0]
    dist=edge[1]
    q.append(v2)
    if dist%2==1:
      ans[v2]=color[1]
    else:
      ans[v2]=color[0]
print(*ans,sep='\n')

Fixed submission:
n,k=map(int,input().split())
s=list(input())
if s[k-1]=='A':
  s[k-1]='a'
elif s[k-1]=='B':
  s[k-1]='b'
else:
  s[k-1]='c'
print(''.join(s))
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
n=int(input())
routes=[tuple(map(int,input().split())) for i in range(n-1)]

edges=defaultdict(list)
for v1,v2,dist in routes:
  edges[v1-1].append([v2-1,dist])
  edges[v2-1].append([v1-1,dist])
#print(edges)

ans=[-1]*n
ans[0]=0

def dfs(i):
  if ans[i]!=-1:
    return ans[i]
  else:
    for edge in edges[i]:
      v=edge[0]
      dist=edge[1]
      ans[i]=dfs(v)+dist
      return ans[i]
for i in range(n):
  dfs(i)
  
print(*[ans[i]%2 for i in range(n)],sep='\n')


Fixed submission:
from collections import deque,defaultdict
n=int(input())
routes=[tuple(map(int,input().split())) for i in range(n-1)]

edges=defaultdict(list)
for v1,v2,dist in routes:
  edges[v1-1].append([v2-1,dist])
  edges[v2-1].append([v1-1,dist])
#print(edges)

ans=[0]*n
q=deque([0])
while q:
  v=q.popleft()
  #print(v)
  if ans[v]==0:
    color=[1,0]
  else:
    color=[0,1]
  #print(edges)
  for edge in edges[v]:
    v2=edge[0]
    dist=edge[1]
    edges[v2].remove([v,dist])
    q.append(v2)
    if dist%2==1:
      ans[v2]=color[0]
    else:
      ans[v2]=color[1]
      
print(*ans,sep='\n')
Buggy python submission (verdict: Time Limit Exceeded):
def main():
  n=int(input())
  num=list(map(int,input().split()))

  def gcd(a,b):
    a,b=max(a,b),min(a,b)
    if b==0:
        return a
    else:
        return gcd(b,a%b)
  
  def gcd2(num,n):
    if n==1:
      return num[0]
    elif n==2:
      return gcd(num[0],num[1])
    else:
      return gcd2([gcd(num[i],num[n-i-1]) for i in range((n+1)//2)],(n+1)//2)

  ans=0
  for i in range(n):
    a=num.copy()
    a.pop(i)
    #print(a)
    tmp=gcd2(a,n-1)
    if tmp>ans:
      ans=tmp
  print(ans)  
  
if __name__=='__main__':
  main()

Fixed submission:
def main():
  from fractions import gcd
  n=int(input())
  num=list(map(int,input().split()))
      
  gcdl=[0]*n
  gcdr=[0]*n
  gcdl[0],gcdr[0]=num[0],num[-1]
  for i in range(n-1):
    gcdl[i+1]=gcd(num[i+1],gcdl[i])
    gcdr[i+1]=gcd(num[-i-2],gcdr[i])

  ans=0
  for i in range(n):
    if i!=0 and i!=n-1:
      test=gcd(gcdl[i-1],gcdr[-i-2])
    elif i==0:
      test=gcdr[-2]
    else:
      test=gcdl[-2]

    if test>ans:
      ans=test
  print(ans)
 
if __name__=='__main__':
  main()
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
s=input()

num_cnt=[]
if s[0]=='1':
  num_cnt.append(0)

cnt=1
for i in range(1,n):
  if s[i]==s[i-1]:
    cnt+=1
  else:
    num_cnt.append(cnt)
    cnt=1
num_cnt.append(cnt)

if k<=n/2:
  ans=sum(num_cnt[:2*k])

  tmp=len(num_cnt)
  if tmp%2==0:
    limit=tmp//2-k
  else:
    num_cnt.append(0)
    limit=tmp//2-k+1
  
  #print(ans)
  #print(num_cnt)
  tmp=num_cnt[2*k]+num_cnt[2*k+1]-num_cnt[0]
  if tmp>0:
    ans+=tmp
  
  for i in range(1,limit):
    tmp=num_cnt[2*(i+k)]+num_cnt[2*(i+k)+1]-num_cnt[2*i]-num_cnt[2*i+1]
    #print(tmp)
    if tmp>0:
      ans+=tmp
else:
  ans=n
print(ans)
  

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

num_cnt=[]
if s[0]=='1':
  num_cnt.append(0)

cnt=1
for i in range(1,n):
  if s[i]==s[i-1]:
    cnt+=1
  else:
    num_cnt.append(cnt)
    cnt=1
num_cnt.append(cnt)

leng=len(num_cnt)
if leng/2>k:
  ans=sum(num_cnt[:2*k])
  tot=ans
  
  if leng%2==0:
    limit=leng//2-k
  else:
    num_cnt.append(0)
    limit=leng//2-k+1
  
  #print(ans)
  #print(num_cnt)
  tmp2=num_cnt[2*k]+num_cnt[2*k+1]-num_cnt[0]
  tot+=tmp2
  if tot>ans:
    ans=tot
  
  for i in range(1,limit):
    #print(2*(i+k)+1)
    tmp=num_cnt[2*(i+k)]+num_cnt[2*(i+k)+1]-num_cnt[2*i]-num_cnt[2*i-1]
    #print(tot)
    tot+=tmp
    if tot>ans:
      ans=tot
else:
  ans=n
print(ans)

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

num_cnt=[]
if s[0]=='1':
  num_cnt.append(0)

cnt=1
for i in range(1,n):
  if s[i]==s[i-1]:
    cnt+=1
  else:
    num_cnt.append(cnt)
    cnt=1
num_cnt.append(cnt)

if k<=n/2:
  ans=sum(num_cnt[:2*k])

  tmp=len(num_cnt)
  if tmp%2==0:
    limit=tmp//2-k-1
  else:
    num_cnt.append(0)
    limit=tmp//2-k
  
  #print(ans)
  #print(num_cnt)
  if k/2<=n:
    tmp=num_cnt[2*k]+num_cnt[2*k+1]-num_cnt[0]
    if tmp>0:
      ans+=tmp
  
  for i in range(1,limit):
    tmp=num_cnt[2*(i+k)]+num_cnt[2*(i+k)+1]-num_cnt[2*i]-num_cnt[2*i+1]
    #print(tmp)
    if tmp>0:
      ans+=tmp
else:
  ans=n
print(ans)
  

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

num_cnt=[]
if s[0]=='1':
  num_cnt.append(0)

cnt=1
for i in range(1,n):
  if s[i]==s[i-1]:
    cnt+=1
  else:
    num_cnt.append(cnt)
    cnt=1
num_cnt.append(cnt)

leng=len(num_cnt)
if leng/2>k:
  ans=sum(num_cnt[:2*k])
  tot=ans
  
  if leng%2==0:
    limit=leng//2-k
  else:
    num_cnt.append(0)
    limit=leng//2-k+1
  
  #print(ans)
  #print(num_cnt)
  tmp2=num_cnt[2*k]+num_cnt[2*k+1]-num_cnt[0]
  tot+=tmp2
  if tot>ans:
    ans=tot
  
  for i in range(1,limit):
    #print(2*(i+k)+1)
    tmp=num_cnt[2*(i+k)]+num_cnt[2*(i+k)+1]-num_cnt[2*i]-num_cnt[2*i-1]
    #print(tot)
    tot+=tmp
    if tot>ans:
      ans=tot
else:
  ans=n
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(100000000)

def main():
    N,K = map(int,input().split())
    sushi = [tuple(map(int,input().split())) for _ in range(N)]

    sushi.sort(key = lambda x:x[1],reverse = True)
    ans = 0
    dic = {}
    change = []
    for a,b in sushi[:K]:
        if a in dic:
            dic[a].append(b)
            change.append((a,b))
        else:
            dic[a] = [b]
        ans += b

    various = len(dic)
    ans += various ** 2
    ret = ans
    used_type = {a for a in dic.keys()}
    suggestion = [p for p in sushi[K:] if p[0] not in used_type]
    for a,b in suggestion:
        if a in used_type:
            continue
        dic[change[-1][0]].pop()
        ret -= change[-1][1]
        ret += b + 2*various + 1
        dic[a] = b
        change.pop()
        various += 1
        used_type.add(a)
        ans = max(ans,ret)
    print(ans)
if __name__ == '__main__':
    main()

Fixed submission:
import sys
sys.setrecursionlimit(100000000)

def main():
    N,K = map(int,input().split())
    sushi = [tuple(map(int,input().split())) for _ in range(N)]

    sushi.sort(key = lambda x:x[1],reverse = True)
    ans = 0
    dic = {}
    change = []
    for a,b in sushi[:K]:
        if a in dic:
            dic[a].append(b)
            change.append((a,b))
        else:
            dic[a] = [b]
        ans += b

    various = len(dic)
    ans += various ** 2
    ret = ans
    used_type = set(dic.keys())
    suggestion = [p for p in sushi[K:] if p[0] not in used_type]
    for a,b in suggestion:
        if len(change) == 0:
            break
        if a in used_type:
            continue
        dic[change[-1][0]].pop()
        ret -= change[-1][1]
        ret += b + 2*various + 1
        dic[a] = b
        change.pop()
        various += 1
        used_type.add(a)
        ans = max(ans,ret)
    print(ans)
if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
heights=[int(i) for i in input().split()]

dp=[0]*n
dp[1]=abs(heights[1]-heights[0])

for i in range(2,n):
  step=[]
  for j in range(1,min(k+1,i+1)):
      step.append(dp[i-j]+abs(heights[i]-heights[i-j]))
    
  dp[i]=min(step)
print(dp[n-1])


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

dp=[0]*n
dp[1]=abs(heights[1]-heights[0])

for i in range(2,n):
  dp[i]=min(dp[i-2]+abs(heights[i]-heights[i-2]), dp[i-1]+abs(heights[i]-heights[i-1]))
print(dp[n-1])
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

n,k=map(int,input().split())
heights=[int(i) for i in input().split()]

dp=np.array([0]*n)
dp[1]=abs(heights[1]-heights[0])

for i in range(2,n):
  dp[i]=min([dp[i-j]+abs(heights[i]-heights[i-j]) for j in range(1,min(k+1,i+1))])
print(dp[n-1])

Fixed submission:
n,k=map(int,input().split())
heights=[int(i) for i in input().split()]

dp=[0]*n
dp[1]=abs(heights[1]-heights[0])

for i in range(2,n):
  step=[]
  for j in range(1,min(k+1,i+1)):
      step.append(dp[i-j]+abs(heights[i]-heights[i-j]))
    
  dp[i]=min(step)
print(dp[n-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
heights=[int(i) for i in input().split()]

dp=[0]*n
dp[1]=abs(heights[1]-heights[0])

for i in range(2,n):
  dp[i]=min([dp[i-j]+abs(heights[i]-heights[i-j]) for j in range(1,min(k+1,i+1))])
print(dp[n-1])

Fixed submission:
n,k=map(int,input().split())
heights=[int(i) for i in input().split()]

dp=[0]*n
dp[1]=abs(heights[1]-heights[0])

for i in range(2,n):
  step=[]
  for j in range(1,min(k+1,i+1)):
      step.append(dp[i-j]+abs(heights[i]-heights[i-j]))
    
  dp[i]=min(step)
print(dp[n-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
heights=[int(i) for i in input().split()]

dp=[0]*n
dp[1]=abs(heights[1]-heights[0])

for i in range(2,n):
  step=[]
  for j in range(1,min(k+1,i+1)):
      step.append(dp[i-j]+abs(heights[i]-heights[i-j]))
    
  dp[i]=min(step)
print(dp[n-1])

Fixed submission:
n,k=map(int,input().split())
heights=[int(i) for i in input().split()]

dp=[0]*n
dp[1]=abs(heights[1]-heights[0])

for i in range(2,n):
  step=[]
  for j in range(1,min(k+1,i+1)):
      step.append(dp[i-j]+abs(heights[i]-heights[i-j]))
    
  dp[i]=min(step)
print(dp[n-1])
Buggy python submission (verdict: Time Limit Exceeded):
n,W=map(int,input().split())
items=[list(map(int,input().split())) for i in range(n)]
weight=[items[i][0] for i in range(n)]
value=[items[i][1] for i in range(n)]

limit=sum(value)
inf=10**9
dp=[[0]+[inf]*limit for i in range(n+1)]
#print(dp)
for i in range(n):
  w=weight[i]
  v=value[i]
  for j in range(limit+1):
    if j>=v:
      dp[i+1][j]=min(dp[i][j],dp[i][j-v]+w)
    else:
      dp[i+1][j]=min(dp[i][j],w)
#print(dp[n])
ans=max([i for i in range(limit+1) if dp[n][i]<=W])
print(ans)

Fixed submission:
n,W=map(int,input().split())
items=[list(map(int,input().split())) for i in range(n)]
weight=[items[i][0] for i in range(n)]
value=[items[i][1] for i in range(n)]

limit=sum(value)
inf=10**9
dp=[[0]+[inf]*limit for i in range(n+1)]
#print(dp)
for i in range(n):
  w=weight[i]
  v=value[i]
  for j in range(limit+1):
    if j>=v:
      dp[i+1][j]=min(dp[i][j],dp[i][j-v]+w)
    else:
      dp[i+1][j]=min(dp[i][j],w)
#print(dp[n])
ans=max([i for i in range(limit+1) if dp[n][i]<=W])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def main():
  n=int(input())
  p=[float(i) for i in input().split()]
  
  dp=[[0]*(n+1) for i in range(n+1)]
  dp[0][0]=1
  for i in range(n):
    dp[i+1][0]=dp[i][0]*(1-p[i])
    for j in range(i+1):
      dp[i+1][j+1]=dp[i][j]*p[i]+dp[i][j+1]*(1-p[i])
  print(sum(dp[n][(n+1)//2:]))
      
if __name__=='__main__':
  main()
        

Fixed submission:
def main():
  n=int(input())
  p=[float(i) for i in input().split()]
  
  dp=[[0]*(n+1) for i in range(n+1)]
  dp[0][0]=1
  for i in range(n):
    dp[i+1][0]=dp[i][0]*(1-p[i])
    for j in range(i+1):
      dp[i+1][j+1]=dp[i][j]*p[i]+dp[i][j+1]*(1-p[i])
  print(sum(dp[n][(n+1)//2:]))
      
if __name__=='__main__':
  main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys 
input = sys.stdin.readline
MOD = 10**9 +7
INF = 10**9

def main():
    n = int(input())
    a = list(map(int,input().split()))
    
    dp = [[0] * (n + 2)  for _ in range(n + 2)]
    
    for l in range(1,n + 1):
        for i in range(n - l + 1):
            j = i + l
            if (n - l)%2 == 0:
                dp[i][j] = max(dp[i + 1][j] + a[i], dp[i][j - 1] + a[j - 1])
            else:
                dp[i][j] = min(dp[i + 1][j] - a[i], dp[i][j - 1] - a[j - 1])
    
    print(dp[0][n])

if __name__=='__main__':
    main()

Fixed submission:
import sys 
input = sys.stdin.readline
MOD = 10**9 +7
INF = 10**9

def main():
    n = int(input())
    a = list(map(int,input().split()))
    
    dp = [[0] * (n + 2)  for _ in range(n + 2)]
    
    for l in range(1,n + 1):
        for i in range(n - l + 1):
            j = i + l
            if (n - l)%2 == 0:
                dp[i][j] = max(dp[i + 1][j] + a[i], dp[i][j - 1] + a[j - 1])
            else:
                dp[i][j] = min(dp[i + 1][j] - a[i], dp[i][j - 1] - a[j - 1])
    
    print(dp[0][n])

if __name__=='__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline
sys.setrecursionlimit(100000000)
MOD = 10**9+7
INF = 10 ** 10
from functools  import lru_cache

MAXN = 405
a = [0] * MAXN
@lru_cache(maxsize = None)
def dfs(l,r):
    if r - l == 1:
        return 0
    else:
        ans = INF
        for i in range(l + 1,r):
            ans = min(ans,dfs(l,i) + dfs(i,r)) 
        if l == 0:
            ans += a[r - 1]
        else:
            ans += a[r - 1] - a[l - 1]
        return ans

def main():
    n = int(input())
    b = list(map(int,input().split()))
    a[:n] = b

    for i in range(1,n):
        a[i] += a[i - 1]
    
    ans = dfs(0,n)
    print(ans)
if __name__=='__main__':
    main()

Fixed submission:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(100000000)
MOD = 10**9+7
INF = 10 ** 20
from functools  import lru_cache

MAXN = 405
a = [0] * MAXN
dp = [[-1] * MAXN for _ in range(MAXN)]
def dfs(l,r):
    if dp[l][r] != -1:
        return dp[l][r]
    if r - l == 1:
        dp[l][r] = 0
        return 0
    ans = INF
    for i in range(l + 1,r):
        ans = min(ans,dfs(l,i) + dfs(i,r)) 
    if l == 0:
        ans += a[r - 1]
    else:
        ans += a[r - 1] - a[l - 1]
    dp[l][r] = ans
    return ans

def main():
    n = int(input())
    b = list(map(int,input().split()))
    a[:n] = b

    for i in range(1,n):
        a[i] += a[i - 1]
    
    ans = dfs(0,n)
    print(ans)
if __name__=='__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    input=sys.stdin.readline
    n=int(input())
    A=[list(map(int,input().split())) for i in range(n)]
    mod=10**9+7

    dp=[0]*(1<<n)
    dp[0]=1
    for s in range(1<<n):
        i=format(s,'b').count('1')
        for j in range(n):
            if (s>>j)&1 and A[i-1][j]==1:
              dp[s]+=dp[s^(1<<j)]
              dp[s]%=mod   
              
    print(dp[-1])
if __name__=='__main__':
    main()

Fixed submission:
def main():
    import sys
    input=sys.stdin.readline
    n=int(input())
    A=[list(map(int,input().split())) for i in range(n)]
    mod=10**9+7

    dp=[0]*(1<<n)
    dp[0]=1
    for s in range(1<<n):
        i=format(s,'b').count('1')
        for j in range(n):
            if (s>>j)&1 and A[i-1][j]==1:
              dp[s]+=dp[s^(1<<j)]
              dp[s]%=mod   
              
    print(dp[-1])
if __name__=='__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    input=sys.stdin.readline
    n=int(input())
    A=[list(map(int,input().split())) for i in range(n)]
    mod=10**9+7

    dp=[[0]*(1<<n) for _ in range(n+1)]
    dp[0][0]=1
    for i in range(1,n+1):
        for s in range(0,1<<n):
            for j in range(n):
                if (s>>j)&1 and A[i-1][j]==1:
                    dp[i][s]+=dp[i-1][s^(1<<j)]
                    dp[i][s]%=mod
                    
    print(dp[n][(1<<n)-1])
if __name__=='__main__':
    main()

Fixed submission:
def main():
    import sys
    input=sys.stdin.readline
    n=int(input())
    A=[list(map(int,input().split())) for i in range(n)]
    mod=10**9+7

    dp=[0]*(1<<n)
    dp[0]=1
    for s in range(1<<n):
        i=format(s,'b').count('1')
        for j in range(n):
            if (s>>j)&1 and A[i-1][j]==1:
              dp[s]+=dp[s^(1<<j)]
              dp[s]%=mod   
              
    print(dp[-1])
if __name__=='__main__':
    main()
Buggy python submission (verdict: Runtime Error):
MOD = 10 ** 9 + 7
INF = 10 ** 10
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)
from math import gcd

def main():
    n = int(input())
    if n == 1:
        print('Hello World')
    else:
        a = int(input())
        b = int(input())
        print(a + b)
if __name__ =='__main__':
    main()   


Fixed submission:
MOD = 10 ** 9 + 7
INF = 10 ** 10
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)

def main():
    n = int(input())
    if n == 1:
        print('Hello World')
    else:
        a = int(input())
        b = int(input())
        print(a + b)
if __name__ =='__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    from fractions import gcd
    n,x=map(int,input().split())
    num=[abs(int(i)-x) for i in input().split() if abs(int(i)-x)!=0]
    n=len(num)
    
    def gcd2(num,n):
        if n<=1:
          return num[0]
        elif n==2:
            return gcd(num[0],num[1])
        else:
            x=num.pop()
            return gcd(gcd2(num,n-1),x)
    
    print(gcd2(num,n))
if __name__=='__main__':
    main()

Fixed submission:
from fractions import gcd
from functools import reduce
n,x=map(int,input().split())
num=[abs(int(i)-x) for i in input().split() if abs(int(i)-x)!=0]
print(reduce(gcd,num))

Buggy python submission (verdict: Runtime Error):
def main():
    from fractions import gcd
    n,x=map(int,input().split())
    num=[abs(int(i)-x) for i in input().split()]

    def gcd2(num,n):
        if n<=1:
          return num[0]
        elif n==2:
            return gcd(num[0],num[1])
        else:
            x=num.pop()
            return gcd(gcd2(num,n-1),x)
    
    print(gcd2(num,n))
if __name__=='__main__':
    main()

Fixed submission:
from fractions import gcd
from functools import reduce
n,x=map(int,input().split())
num=[abs(int(i)-x) for i in input().split() if abs(int(i)-x)!=0]
print(reduce(gcd,num))
Buggy python submission (verdict: Runtime Error):
MOD = 10 ** 9 + 7
INF = 10 ** 10
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)
from math import gcd

def main():
    n = int(input())
    s = []
    if n == 0:
        print('0')
        return

    while n != 0:
        if n%2 == 0:
            s.append('0')
            n //= -2
        else:
            s.append('1')
            n -= 1
            n //= -2
    print(''.join(s[::-1]))

if __name__ =='__main__':
    main()   

Fixed submission:
def main():
  n=int(input())
  ans=[]
  if n==0:
    print(0)
  while n!=0:
    s=n%2
    ans.append(s)
    if s==0:
      n//=(-2)
    else:
      n=(n-1)//(-2)
  ans=ans[::-1]
  print(''.join([str(bit) for bit in ans]))
if __name__=='__main__':
  main()
Buggy python submission (verdict: Runtime Error):
def main():
    n,m=map(int,input().split())
    a=list(map(int,input().split()))

    pmod={}
    cummod=0
    for num in a:
        cummod+=num
        cummod%=m
        if cummod not in pmod:
            pmod[cummod]=1
        else:
            pmod[cummod]+=1
    
    ans=pmod[0]
    for i in pmod:
        if pmod[i] >=2 :
            ans+=pmod[i]*(pmod[i]-1)//2
    
    print(ans)

if __name__=='__main__':
    main()

Fixed submission:
def main():
    n,m=map(int,input().split())
    a=list(map(int,input().split()))

    pmod={}
    cummod=0
    for num in a:
        cummod+=num
        cummod%=m
        if cummod not in pmod:
            pmod[cummod]=1
        else:
            pmod[cummod]+=1
    
    if 0 in pmod:
        ans=pmod[0]
    else:
        ans=0
        
    for i in pmod:
        if pmod[i] >=2 :
            ans+=pmod[i]*(pmod[i]-1)//2
    
    print(ans)

if __name__=='__main__':
    main()