Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02572 (python)

Fixed submission:
from sys import stdin,stdout
def INPUT():return list(int(i) for i in stdin.readline().split())
def inp():return stdin.readline()
def out(x):return stdout.write(x)
import math
import random
J=int(1e9)+7

###############################################################################\n=17
n=int(input())
A=INPUT()
sum=0
for i in range(n):
    sum+=A[i]
sum=sum*sum

s=0
for i in range(n):
    s+=A[i]**2

ans=(sum-s)//2
ans%=J
print(ans)

Buggy submission (verdict: Runtime Error):
from sys import stdin,stdout
def INPUT():return list(int(i) for i in stdin.readline().split())
def inp():return stdin.readline()
def out(x):return stdout.write(x)
import math
import random
J=int(1e9)+7

###############################################################################\n=17
n=int(input())
A=INPUT()
sum=0
for i in range(n):
    sum+=A[i]
sum=sum*sum

s=0
for i in range(n):
    s+=A[i]**2

ans=(sum-j)//2
ans%=J
print(ans)

Buggy submission (verdict: Runtime Error):
from sys import stdin,stdout
def INPUT():return list(int(i) for i in stdin.readline().split())
def inp():return stdin.readline()
def out(x):return stdout.write(x)
import math
import random
J=int(1e9)+7

###############################################################################\n=17
n=int(input())
A=INPUT()
sum=0
for i in range(n):
    sum+=A[i]
    sum%=J 
sum=sum*sum  
sum%=J  
s=0
for i in range(n):
    s+=A[i]**2
    s%=j  
ans=sum-j  
ans%=J  
print(ans)
Problem p02578 (python)

Fixed submission:
from sys import stdin,stdout
def INPUT():return list(int(i) for i in stdin.readline().split())
def inp():return stdin.readline()
def out(x):return stdout.write(x)
import math
###############################################################################\
n=int(input())
A=INPUT()
B=[A[0]]

currmax=A[0]
ans=0
for i in range(1,n):
    if A[i]<=currmax:
        ans+=currmax-A[i]
    currmax=max(currmax,A[i])
print(ans)

Buggy submission (verdict: Runtime Error):
vfrom sys import stdin,stdout
def INPUT():return list(int(i) for i in stdin.readline().split())
def inp():return stdin.readline()
def out(x):return stdout.write(x)
import math
###############################################################################\
n=int(input())
A=INPUT()
B=[A[0]]

currmax=A[0]
ans=0
for i in range(1,n):
    if A[i]<=currmax:
        ans+=currmax-A[i]
    currmax=max(currmax,A[i])
print(ans)
Problem p03104 (python)

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


def xor(n):
    m = 0
    if n % 4 == 0:
        m = n
    elif n % 4 == 1:
        m = 1
    elif n % 4 == 2:
        m = n + 1
    return m


p = xor(A-1)
q = xor(B)
print(p ^ q)

Buggy submission (verdict: Runtime Error):
#include <iostream>
using namespace std;

int main()
{
    long long A, B;
    cin >> A >> B;
    long long ans = A;
    if (A != B)
    {
        for (long long i = A + 1; i <= B; i++)
        {
            ans ^= i;
        }
    }
    cout << ans << endl;
}

Buggy submission (verdict: Runtime Error):
#include <iostream>
using namespace std;

int main()
{
    long long A, B;
    cin >> A >> B;
    long long ans = A;
    for (long long i = A + 1; i <= B; i++)
    {
        ans ^= i;
    }
    cout << ans << endl;
}
Problem p02596 (python)

Fixed submission:
k = int(input())

arr = [0] * (k+1)
r = 7 % k
ans = 1

while arr[r] == 0:
    if r == 0:
        print(ans)
        exit()
    arr[r] += 1
    r = (10 * r + 7) % k
    ans += 1

print(-1)

Buggy submission (verdict: Runtime Error):
k = int(input())

l = len(list(str(k)))

ans = l
r = int('7' * (l-1))
x = 0

while(True):
    if x == (r * 10 + 7) // k and r == (r * 10 + 7) % k:
        print(-1)
        exit()

    x = (r * 10 + 7) // k
    r = (r * 10 + 7) % k

    if r == 0:
        break
    else:
        ans += 1
print(ans)
Problem p02771 (python)

Fixed submission:
a,b,c = map(int, input().split())
if a == b and a!= c:
    print('Yes')
elif a == c and b != c:
    print('Yes')
elif b == c and a != c:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
a,b,c = map(int, input().split())
if a == b and a!= c:
    print('Yes')
elif a == c and b != c:
    print('Yes')
elif b = c and a != c:
    print('Yes')
else:
    print('No')
Problem p02831 (python)

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

Buggy submission (verdict: Runtime Error):
import math
a,b = map(int, input().split())
print(a*b//math.gcd(a,b))

Buggy submission (verdict: Runtime Error):
import math
a,b = map(int, input().split())
print(a*b//math.gcd(a,b))
Problem p02862 (python)

Fixed submission:
x,y = map(int, input().split())

mod = 10**9+7
def inv(x):
        return pow(x, mod-2, mod)
def fact(x):
        f = 1 
        for i in range(1, x + 1): 
                f *= i
                f %= mod    
        return f
def comb(n, r): 
        return (fact(n) * inv(fact(n-r)) * inv(fact(r))) % mod 

if (x + y) % 3 != 0 or y / x < 1/2 or y/x > 2:
    print(0)
else:
    n = (2*y-x)//3
    m = (2*x-y)//3
    res = comb(n+m, m)
    print(res)

Buggy submission (verdict: Runtime Error):
from math import factorial
from scipy.special import comb
x,y = map(int, input().split())

mod = 10**9+7
def inv(x):
        return pow(x, mod-2, mod)
def fact(x):
        f = 1 
        for i in range(1, x + 1): 
                f *= i
                f %= mod    
        return f
def comb(n, r): 
        return (fact(n) * inv(fact(n-r)) * inv(fact(r))) % mod 

if (x + y) % 3 != 0:
    print(0)
else:
    n = (2*y-x)//3
    m = (2*x-y)//3
    res = comb(n+m, m)
    print(res % (10**9+7))

Buggy submission (verdict: Runtime Error):
from math import factorial
from scipy.special import comb
x,y = map(int, input().split())

if (x + y) % 3 != 0:
    print(0)
else:
    n = (2*y-x)//3
    m = (2*x-y)//3
    c = comb(n+m, n, exact=True)
    print(c % (10**9+7))

Buggy submission (verdict: Runtime Error):
x,y = map(int, input().split())


dp =[[0] * (y+1) for i in range(x+1)]
dp[0][0] = 0
dp[1][2] = 1
dp[2][1] = 1

for i in range(2,x+1):
    for j in range(2,y+1):
        dp[i][j] = dp[i-1][j-2] % (10**9+7) + dp[i-2][j-1] % (10**9+7)

print(dp[x][y] % (10**9+7))
Problem p03013 (python)

Fixed submission:
n,m = map(int,input().split())
a = [0] * m
for i in range(m):
    a[i] = int(input())

dp = [999] * (n + 1)
if 0 not in a:
    dp[0] = 1
if 1 not in a:
    dp[1] = 1
if 2 not in a and n >= 2:
    if 1 in a:
        dp[2] = 1
    else:
        dp[2] = 2

mod = 10**9+7

for i in range(len(a)):
    dp[a[i]] = 0

for i in range(3,n+1):
    if dp[i] != 0:
        dp[i] = (dp[i-1] + dp[i-2]) % mod

print(dp[-1])

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
a = [0] * m
for i in range(m):
    a[i] = int(input())

dp = [0] * (n + 1)
if 0 not in a:
    dp[0] = 1
if 1 not in a:
    dp[1] = 1
if 2 not in a:
    if 1 in a:
        dp[2] = 1
    else:
        dp[2] = 2

mod = 10**9+7

for i in range(3,n+1):
    if i-1 in a and i-2 in a:
        dp[i] = 0
    elif i-1 in a:
        dp[i] = dp[i-2] % mod
    elif i-2 in a:
        dp[i] = dp[i-1] % mod
    else:
        dp[i] = (dp[i-1] + dp[i-2]) % mod

print(dp[-1])
Problem p03315 (python)

Fixed submission:
s = list(str(input()))
c = 0
for i in range(len(s)):
    if s[i] == '+':
        c += 1
    else:
        c -= 1

print(c)

Buggy submission (verdict: Runtime Error):
c = 0
for i in range(len(s)):
    if s[i] == '+':
        c += 1
    else:
        c -= 1

print(c)
Problem p03804 (python)

Fixed submission:
n,m = map(int,input().split())
a = []
for i in range(n):
    a.append(str(input()))
b = []
for i in range(m):
    b.append(str(input()))

f = [0]*m
tmp = []
for j in range(m):
    f[j] = a[j].find(b[j])
    if f[j] != -1:
        tmp.append(j)
while -1 in f: f.remove(-1)

try:
    if len(f) == 0:
        print('No')
    else:
        count = 0
        for i in range(len(tmp)):
            count += 1
            if (b[tmp[i]] in a[tmp[i]]) == False:
                count = 0
        if count == m:
            print('Yes')
        else:
            print('No')
except:
    print('No')

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
a = []
for i in range(n):
    a.append(str(input()))
b = []
for i in range(m):
    b.append(str(input()))

f = [0]*m
count = 0
for j in range(m):
    f[j] = a[j].find(b[j])

while -1 in f: f.remove(-1)
if len(f) == 0:
    print('No')
else:
    flag = 1
    for i in range(len(f)):
        if (b[f[i]] in a[f[i]]) == False:
            flag =0
    if flag == 1:
        print('Yes')
    else:
        print('No')

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
a = []
for i in range(n):
    a.append(str(input()))
b = []
for i in range(m):
    b.append(str(input()))

f = [0]*m
count = 0
for j in range(m):
    f[j] = a[j].find(b[j])

while -1 in f: f.remove(-1)
if len(f) == 0:
    print('No')
else:
    flag = 1
    for i in range(len(f)):
        if  b[f[i]] in a[f[i]]:
            pass
        else:
            flag =0
    if flag == 1:
        print('Yes')
    else:
        print('No')
Problem p02598 (python)

Fixed submission:
def f(x):
  return sum([(i-1)//x for i in a])<=k

def main():
  l,r=0,10**9
  while r-l>1:
    m=(l+r)//2
    if f(m): r=m;
    else: l=m;
  print(r)

if __name__=='__main__':
  n,k=map(int,input().split())
  a=list(map(int,input().split()))
  main()

Buggy submission (verdict: Runtime Error):
def main():
  l,r=0,10**9
  while r-l>1:
    m=(l+r)//2
    if sum([(i-1)//x for i in a])<=k: r=m;
    else: l=m;
  print(r)

if __name__=='__main__':
  n,k=map(int,input().split())
  a=list(map(int,input().split()))
  main()
Problem p02695 (python)

Fixed submission:
import itertools

N, M, Q = map(int, input().split())
ABCD = [[int(x) for x in input().split()] for i in range(Q)]

ans=0
for A in itertools.combinations_with_replacement([m for m in range(1,M+1)], N):
  ans2=0
  for (a,b,c,d) in ABCD:
    if A[b-1]-A[a-1]==c:
      ans2+=d
  ans=max(ans, ans2)
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
GACHA=set()
for n in range(N):
  GACHA.add(input())
print(len(GACHA))

Buggy submission (verdict: Runtime Error):
N = int(input())
GACHA=[input() for n in range(N)]
print(len(set(GACHA)))
Problem p02753 (python)

Fixed submission:
S=input()
print('No' if S=='AAA' or S=='BBB' else 'Yes')

Buggy submission (verdict: Runtime Error):
S=input()
print('No' if S=='AAA' or S==='BBB' else 'Yes')
Problem p02777 (python)

Fixed submission:
a,b=input().split()
ST={}
ST[a], ST[b] = map(int, input().split())
ST[input()]-=1

for k,v in ST.items():
  print(v,end=' ')

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
P = [(int(x)+1)/2 for x in input().split()]

total=ans=sum(P[:K])
for n in range(K,N):
  total+=P[n]-P[n-K]
  ans=max(ans, total)

print(ans)
Problem p02835 (python)

Fixed submission:
print('bust' if sum(list(map(int,input().split())))>=22 else 'win')

Buggy submission (verdict: Runtime Error):
print('bust' if sum(list(map,input().split()))>=22 else 'win')
Problem p02880 (python)

Fixed submission:
n=int(input())
ans=0
for i in range(1,10):
  for j in range(1,10):
    if n==i*j:
      ans=1
print('Yes' if ans else 'No')

Buggy submission (verdict: Runtime Error):
ans=0
for i in range(1,10):
  for j in range(1,10):
    if int(input())==i*j:
      ans=1
print('Yes' if ans else 'No')
Problem p02925 (python)

Fixed submission:
from collections import deque

def main():
  n=int(input())
  a=[0]*n
  for i in range(n):
    a[i]=deque(list(map(lambda x:int(x)-1,input().split())))
  q=deque([])
  tmp=set()
  for idx,i in enumerate(a):
    x=idx
    y=i[0]
    if x == a[y][0]:
      tmp.add(x)
      tmp.add(y)
  q=deque(tmp)
  for i in tmp:
    a[i].popleft()
  
  
  day=0
  while True:
    day+=1
    t=q.copy()
    q=deque()
    tmp=set()
    while t:
      x=t.popleft()
      if len(a[x])==0: continue;
      y=a[x][0]
      if x == a[y][0]:
        tmp.add(x)
        tmp.add(y)
    q=deque(tmp)
    for i in tmp:
      a[i].popleft()
    if len(q)==0: break;

  for i in range(n):
    if len(a[i])!=0:
      print(-1)
      exit()
  print(day)


if __name__=='__main__':
  main()

Buggy submission (verdict: Runtime Error):
sys.setrecursionlimit(10000)

n=int(input())
a=[[0]*(n-1) for i in range(n)]
id=[[-1]*(n) for i in range(n)]
MAXV=n*(n-1)//2
to=[[]*(n) for i in range(MAXV)]
  
def toId(i,j):
  if (i>j):
    i,j=j,i
  return id[i][j]


visited=[False]*MAXV
calculated=[False]*MAXV
dp=[0]*MAXV
def dfs(v):
  if visited[v]:
    if not calculated[v]:
      return -1
    return dp[v]
  visited[v]=True
  dp[v]=1
  for u in to[v]:
    res = dfs(u)
    if res==-1:
      return -1
    dp[v]=max(dp[v], res+1)
  calculated[v]=True
  return dp[v]


def main():
  for i in range(n):
    a[i]=list(map(lambda x:int(x)-1,input().split()))
  v=0
  for i in range(n):
    for j in range(n):
      if i<j:
        id[i][j]=v
        v+=1
  for i in range(n):
    for j in range(n-1):
      a[i][j]=toId(i,a[i][j])
    for j in range(n-2):
      to[a[i][j+1]].append(a[i][j])
      
  ans=0
  for i in range(v):
    res=dfs(i)
    if res==-1:
      print(-1)
      exit(0)
    ans=max(ans, res)

  print(ans)
  
  
  
if __name__=='__main__':
  main()

Buggy submission (verdict: Runtime Error):
n=int(input())
a=[[0]*(n-1) for i in range(n)]
id=[[-1]*(n) for i in range(n)]
MAXV=n*(n-1)//2
to=[[]*(n) for i in range(MAXV)]
  
def toId(i,j):
  if (i>j):
    i,j=j,i
  return id[i][j]


visited=[False]*MAXV
calculated=[False]*MAXV
dp=[0]*MAXV
def dfs(v):
  if visited[v]:
    if not calculated[v]:
      return -1
    return dp[v]
  visited[v]=True
  dp[v]=1
  for u in to[v]:
    res = dfs(u)
    if res==-1:
      return -1
    dp[v]=max(dp[v], res+1)
  calculated[v]=True
  return dp[v]


def main():
  for i in range(n):
    a[i]=list(map(lambda x:int(x)-1,input().split()))
  v=0
  for i in range(n):
    for j in range(n):
      if i<j:
        id[i][j]=v
        v+=1
  for i in range(n):
    for j in range(n-1):
      a[i][j]=toId(i,a[i][j])
    for j in range(n-2):
      to[a[i][j+1]].append(a[i][j])
      
  ans=0
  for i in range(v):
    res=dfs(i)
    if res==-1:
      print(-1)
      exit(0)
    ans=max(ans, res)

  print(ans)
  
  
  
if __name__=='__main__':
  main()
Problem p02948 (python)

Fixed submission:
import heapq

n,m=map(int,input().split())
mm=10**5+5
c=[[0] for i in range(mm)]

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

#print(c)

ans=0
h=[]
for i in reversed(range(m)):
  d=m-i
  for j in c[d]:
    heapq.heappush(h,-j)
  #heapq.heapify(h)
  ans+=-heapq.heappop(h)

print(ans)

Buggy submission (verdict: Runtime Error):
import heapq

n,m=map(int,input().split())
mm=10*5+1
c=[[0] for i in range(mm)]

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

#print(c)

ans=0
h=[]
for i in reversed(range(m)):
  d=m-i
  h+=list(map(lambda x:-x, c[d]))+[0]
  heapq.heapify(h)
  ans+=-heapq.heappop(h)

print(ans)

Buggy submission (verdict: Runtime Error):
import heapq

n,m=map(int,input().split())
mm=10*5+1
c=[[0] for i in range(mm)]

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

#print(c)

ans=0
h=[]
for i in reversed(range(m)):
  d=m-i
  h+=list(map(lambda x:-x, c[d]))
  heapq.heapify(h)
  ans+=-heapq.heappop(h)

print(ans)
Problem p02984 (python)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
ans=[0]*n
ans[0]=sum([2*a[i] for i in range(1,n,2)])
ans[0]=sum(a)-ans[0]

for i in range(n-1):
  ans[i+1]=2*a[i]-ans[i]

print(*ans)

Buggy submission (verdict: Runtime Error):
def nCk(_n,_k):
  if _k==0:
    return 1
  else:
    if _n<0 or _k<0 or _n-_k<0:
      return 0
    else:
      return (fact[_n]//(fact[_k]*fact[_n-_k]))%m

fact=[1]*2005
for i in range(1,2001):
  fact[i]=fact[i-1]*i

n,k=map(int,input().split())
m=10**9+7
ans=cnt=0
for _k in range(1,k+1):
  ans=(nCk(n-k+_k,_k)-cnt)*nCk(k-1,_k-1) if _k>1 else n-k+_k 
  cnt+=ans
  cnt%=m
  ans%=m
  print(ans)

Buggy submission (verdict: Runtime Error):
l,r=map(int,input().split())
m,ans=2019,2018
r=min(r,l+2019*2)
for i in range(l,r+1):
  for j in range(i+1,r+1):
    i%=m
    j%=m
    ans=min(ans,(i*j)%m)
print(ans)
Problem p02769 (python)

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

mod = 10**9+7

m = 10**5 * 4 +10 
fac = [1]*m
ninv = [1]*m
finv = [1]*m
for i in range(2,m):
    fac[i] = fac[i-1]*i%mod
    ninv[i] = (-(mod//i)*ninv[mod%i])%mod
    finv[i] = finv[i-1]*ninv[i]%mod

def comb(n,k):
    return (fac[n]*finv[k]%mod)*finv[n-k]%mod

ans = 0
for i in range(min(n,k+1)):
    ans += comb(n,i)*comb(n-1,i)
    ans %= mod
print(ans)

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

mod = 10**9+7

m = 10**5 * 4 +10 
fac = [1]*m
ninv = [1]*m
finv = [1]*m
for i in range(2,m):
    fac[i] = fac[i-1]*i%mod
    ninv[i] = (-(mod//i)*ninv[mod%i])%mod
    finv[i] = finv[i-1]*ninv[i]%mod

def comb(n,k):
    return (fac[n]*finv[k]%mod)*finv[n-k]%mod

if k*2 >= n:
    print(comb(2*n-1,n))
    1/0
else:
    ans = 0
    for i in range(k+1):
        ans += comb(n,i)*comb(n-1,i)
        ans %= mod
    print(ans)
Problem p02990 (python)

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

mod = 10**9+7

m = N+1
fac = [1]*m
ninv = [1]*m
finv = [1]*m
for i in range(2,m):
    fac[i] = fac[i-1]*i%mod
    ninv[i] = (-(mod//i)*ninv[mod%i])%mod
    finv[i] = finv[i-1]*ninv[i]%mod

def comb(n,k):
    if n<0 or k<0 or k>n:return 0
    return (fac[n]*finv[k]%mod)*finv[n-k]%mod

for i in range(1,K+1):
    print(comb(N-K+1,i)*comb(K-1,i-1)%mod)

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

mod = 10**9+7

m = N
fac = [1]*m
ninv = [1]*m
finv = [1]*m
for i in range(2,m):
    fac[i] = fac[i-1]*i%mod
    ninv[i] = (-(mod//i)*ninv[mod%i])%mod
    finv[i] = finv[i-1]*ninv[i]%mod

def comb(n,k):
    if n<0 or k<0 or k>n:return 0
    return (fac[n]*finv[k]%mod)*finv[n-k]%mod

for i in range(1,K+1):
    print(comb(N-K+1,i)*comb(K-1,i-1)%mod)

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

mod = 10**9+7

m = N
fac = [1]*m
ninv = [1]*m
finv = [1]*m
for i in range(2,m):
    fac[i] = fac[i-1]*i%mod
    ninv[i] = (-(mod//i)*ninv[mod%i])%mod
    finv[i] = finv[i-1]*ninv[i]%mod

def comb(n,k):
    if n<0 or k<0 or k>n:return 0
    return (fac[n]*finv[k]%mod)*finv[n-k]%mod

for i in range(1,K+1):
    print(comb(N-K+1,i)*comb(K-1,i-1)%mod)
Problem p03137 (python)

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

X.sort()

dif_X = [X[i+1]-x for i,x in enumerate(X[:-1])]
dif_X.sort()
print(sum(dif_X[:max(0,M-N)]))

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

X.sort()

memo = dict()
def get_min(n,x):
    key = str((n,x))
    tmp = memo.get(key,None)
    if tmp != None:
        return tmp
    if x == []:
        tmp = 10**8
        memo[key] = tmp
        return tmp
    elif len(x) == 1:
        memo[key] = 0
        return 0
    x0 = x[0]
    if n == 1:
        tmp = x[-1]-x0
        memo[key] = tmp
        return tmp
    tmp = min([y - x0 + get_min(n-1,x[i+1:]) for i,y in enumerate(x)])
    memo[key] = tmp
    return tmp
if N >= M:
    print(0)
else:
    print(get_min(N,X))

Buggy submission (verdict: Runtime Error):
X.sort()

memo = dict()
def get_min(n,x):
    key = str((n,x))
    tmp = memo.get(key,None)
    if tmp != None:
        return tmp
    if x == []:
        tmp = 10**8
        memo[key] = tmp
        return tmp
    elif len(x) == 1:
        memo[key] = 0
        return 0
    x0 = x[0]
    if n == 1:
        tmp = x[-1]-x0
        memo[key] = tmp
        return tmp
    tmp = min([y - x0 + get_min(n-1,x[i+1:]) for i,y in enumerate(x)])
    memo[key] = tmp
    return tmp
if N >= M:
    print(0)
else:
    print(get_min(N,X))

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

X.sort()

memo = dict()
def get_min(n,x):
    key = str((n,x))
    tmp = memo.get(key,None)
    if tmp != None:
        return tmp
    if x == []:
        tmp = 10**8
        memo[key] = tmp
        return tmp
    elif len(x) == 1:
        memo[key] = 0
        return 0
    x0 = x[0]
    if n == 1:
        tmp = x[-1]-x0
        memo[key] = tmp
        return tmp
    tmp = min([y - x0 + get_min(n-1,x[i+1:]) for i,y in enumerate(x)])
    memo[key] = tmp
    return tmp

print(get_min(N,X))
Problem p03201 (python)

Fixed submission:
import bisect
N = int(input())
*A, = map(int,input().split())
B = {}
for a in A:B[a] = B.get(a,0) + 1
B = sorted(map(list,B.items()))
bl = bisect.bisect_left

ans = 0
while B:
    b,n = B.pop()
    c = (1<<(len(bin(b))-2)) - b
    if c==b :
        ans += n//2
        continue
    i = bl(B,[c,0])
    if i>=len(B): continue
    if B[i][0] == c:
        m = min(n,B[i][1])
        ans += m
        B[i][1] -= m
print(ans)

Buggy submission (verdict: Runtime Error):
import bisect
N = int(input())
*A, = map(int,input().split())
B = {}
for a in A:B[a] = B.get(a,0) + 1
B = sorted(map(list,B.items()))
bl = bisect.bisect_left

ans = 0
while 1:
    b,n = B.pop()
    if not B : break
    c = (1<<(len(bin(b))-2)) - b
    i = bl(B,[c,0])
    if B[i][0] == c:
        m = min(n,B[i][1])
        ans += m
        B[i][1] -= m
print(ans)
Problem p03804 (python)

Fixed submission:
N,M = map(int,input().split())
A = [input() for _ in [0]*N]
B = [input() for _ in [0]*M]
endFlg = False
for i in range(N-M+1):
    for j in range(N-M+1):
        breakFlg = False
        for k in range(M):
            for l in range(M):
                if A[i+k][j+l] != B[k][l]:
                    breakFlg = True
                    break
            if breakFlg:break
        else:endFlg=True
        if endFlg: break
    if endFlg: break
if endFlg:print("Yes")
else:print("No")

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
A = [input() for _ in [0]*N]
B = [input() for _ in [0]*M]
endFlg = False
for i in range(N-M):
    for j in range(N-M):
        breakFlg = False
        for k in range(M):
            for l in range(M):
                if A[i+k][j+l] != B[k][l]:
                    breakFlg = True
                    break
        if breakFlg: break
        pass
        else: endFlg = True
    if endFlg: break
if endFlg:print("Yes")
else:print("No")
Problem p02793 (python)

Fixed submission:
from fractions import gcd


n = int(input())
A = list(map(int,input().split()))
num = 1
ans = 0
for i in A:
  num = i // gcd(i,num) * num

for i in A:
  ans += num//i
  
print(int(ans%1000000007))

Buggy submission (verdict: Runtime Error):
from franctions import gcd

n = int(input())
A = list(map(int,input().split()))
num = 1
ans = 0
for i in A:
  num = i // gcd(i,num) * num

for i in A:
  ans += num//i
  ans %= 1000000007
  
print(int(ans))

Buggy submission (verdict: Runtime Error):
def gcd(a,b):
  r = a%b
  while r > 0:
    a=b
    b=r
    r=a%b
  return b

n = int(input())
A = list(map(int,input().split()))
num = 1
ans = 0
for i in A:
  num = i // gcd(i,num) * num

for i in A:
  ans += num/i
  ans %= 1000000007
  
print(int(ans))
Problem p03821 (python)

Fixed submission:
n = int(input())
ans = 0
li = []
for i in range(n):
    a,b = map(int,input().split())
    li.append((a,b))
li = li[::-1]
for (a,b) in li:
    ans += (b-((a+ans)%b))%b
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
ans = 0
li = []
for i in range(n):
    a,b = map(int,input().split())
    li.append(map(int,input().split()))
for (a,b) in li[::-1]:
    ans += (b-((a+ans)%b))%b
print(ans)