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

Fixed submission:
n=int(input())
G=[[0]*20 for i in range(45)]
A=[0,0,0,0]
for i in range(n):
  S=list(input())
  s=""
  f=0
  a=0
  for j in S:
    if j==".":
      f=1
    else:
      s=s+j
      if f==1:
        a=a+1
  A[0]=int(s)
  A[1]=a
  m=int(s)
  c=0
  while m%10==0:
    c=c+1
    m=m//10
  A[0]=m
  A[1]-=c
  m=A[0]
  c=0
  while m%2==0:
    c=c+1
    m=m//2
  A[2]=c
  c=0
  m=A[0]
  while m%5==0:
    c=c+1
    m=m//5
  A[3]=c
  G[A[2]-A[1]+9][A[3]-A[1]+9]+=1
B=[[0]*21 for i in range(46)]
for i in range(44,-1,-1):
  for j in range(19,-1,-1):
    B[i][j]=B[i+1][j]+B[i][j+1]-B[i+1][j+1]+G[i][j]
ans=0
for i in range(45):
  for j in range(20):
    ans=ans+G[i][j]*B[max(0,18-i)][max(0,18-j)]
    if i>=max(0,18-i) and j>=max(0,18-j):
      ans=ans-G[i][j]
print(ans//2)

Buggy submission (verdict: Runtime Error):
n=int(input())
G=[[0]*20 for i in range(25)]
A=[0,0,0,0]
for i in range(n):
  S=list(input())
  s=""
  f=0
  a=0
  for j in S:
    if j==".":
      f=1
    else:
      s=s+j
      if f==1:
        a=a+1
  A[0]=int(s)
  A[1]=a
  m=int(s)
  c=0
  while m%10==0:
    c=c+1
    m=m//10
  A[0]=m
  A[1]-=c
  m=A[0]
  c=0
  while m%2==0:
    c=c+1
    m=m//2
  A[2]=c
  c=0
  m=A[0]
  while m%5==0:
    c=c+1
    m=m//5
  A[3]=c
  G[A[2]-A[1]+9][A[3]-A[1]+9]+=1
B=[[0]*21 for i in range(26)]
for i in range(24,-1,-1):
  for j in range(19,-1,-1):
    B[i][j]=B[i+1][j]+B[i][j+1]-B[i+1][j+1]+G[i][j]
ans=0
for i in range(25):
  for j in range(20):
    ans=ans+G[i][j]*B[max(0,18-i)][max(0,18-j)]
    if i>=max(0,18-i) and j>=max(0,18-j):
      ans=ans-G[i][j]
print(ans//2)
Problem p02609 (python)

Fixed submission:
def g(x):
  S=format(x,"22b")
  cnt=0
  for i in range(20):
    if S[-1-i]=="1":
      cnt=cnt+1
  return x%cnt

n=int(input())
X=input()
a=0
for i in range(n):
  if X[i]=="1":
    a=a+1
#最初に割るのは a-1 or a+1 -> a==0,1 に注意
if a==0:
  for i in range(n):
    print(1)
  exit()
if a==1:
  if X[-1]=="1":
    for i in range(n-1):
      print(2)
    print(0)
    exit()
  else:
    for i in range(n-1):
      if X[i]=="1":
        print(0)
      else:
        print(1)
    print(2)
    exit()
D=[0]*n
E=[0]*n
D[0]=1%(a-1)
E[0]=1%(a+1)
b=int(X[-1])%(a-1)
c=int(X[-1])%(a+1)
for i in range(n-1):
  D[i+1]=(D[i]*2)%(a-1)
  E[i+1]=(E[i]*2)%(a+1)
  if X[-2-i]=="1":
    b=(b+D[i+1])%(a-1)
    c=(c+E[i+1])%(a+1)
for i in range(n):
  if X[i]=="1":
    x=(b+a-1-D[-1-i])%(a-1)
    ans=1
    while x!=0:
      x=g(x)
      ans=ans+1
    print(ans)
  else:
    x=(c+E[-1-i])%(a+1)
    ans=1
    while x!=0:
      x=g(x)
      ans=ans+1
    print(ans)

Buggy submission (verdict: Runtime Error):
def g(x):
  S=format(x,"20b")
  cnt=0
  for i in range(15):
    if S[-1-i]=="1":
      cnt=cnt+1
  return x%cnt

n=int(input())
X=input()
a=0
for i in range(n):
  if X[i]=="1":
    a=a+1
#最初に割るのは a-1 or a+1 -> a==1,0に注意
if a==0:
  for i in range(n):
    print(1)
  exit()
if a==1:
  if X[-1]=="1":
    for i in range(n-1):
      print(2)
    print(0)
    exit()
  else:
    for i in range(n):
      if X[i]=="1":
        print(0)
      else:
        print(1)
    exit()
D=[1]*n
E=[1]*n
D[0]=D[0]%(a-1)
E[0]=E[0]%(a+1)
b=int(X[-1])%(a-1)
c=int(X[-1])%(a+1)
for i in range(n-1):
  D[i+1]=(D[i]*2)%(a-1)
  E[i+1]=(E[i]*2)%(a+1)
  if X[-2-i]=="1":
    b=(b+D[i+1])%(a-1)
    c=(c+E[i+1])%(a+1)
for i in range(n):
  if X[i]=="1":
    x=(b+a-1-D[-1-i])%(a-1)
    ans=1
    while x!=0:
      x=g(x)
      ans=ans+1
    print(ans)
  else:
    x=(c+E[-1-i])%(a+1)
    ans=1
    while x!=0:
      x=g(x)
      ans=ans+1
    print(ans)
Problem p02632 (python)

Fixed submission:
def cmb(n, r):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 2*10**6+10
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

k=int(input())
n=len(input())
ans=0
for i in range(k,-1,-1):
  ans=(ans+cmb(k+n,i)*pow(25,i,mod))%mod
print(ans)

Buggy submission (verdict: Runtime Error):
def cmb(n, r):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**6+10
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

k=int(input())
n=len(input())
ans=0
for i in range(k,-1,-1):
  ans=(ans+cmb(k+n,i)*pow(25,i,mod))%mod
print(ans)
Problem p02660 (python)

Fixed submission:
def fa(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr




n=int(input())
if n==1:
  print(0)
  exit()
A=fa(n)
ans=0
for i in range(len(A)):
  x=int((2*A[i][1])**(0.5))
  if (x-2)*(x-1)<=2*A[i][1]<x*(x-1):
    a=x-2
  if (x-1)*x<=2*A[i][1]<x*(x+1):
    a=x-1
  if (x+1)*x<=2*A[i][1]<(x+2)*(x+1):
    a=x
  if (x+1)*(x+2)<=2*A[i][1]<(x+2)*(x+3):
    a=x+1
  if (x+3)*(x+2)<=2*A[i][1]<(x+4)*(x+3):
    a=x+2
  ans=ans+a
print(ans)

Buggy submission (verdict: Runtime Error):
def fa(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr




n=int(input())
if n==1:
  print(0)
  exit()
A=fa(n)
ans=0
for i in range(len(A)):
  x=int(2*A[i][1]**(0.5))
  if (x-2)*(x-1)<=2*A[i][1]<x*(x-1):
    a=x-2
  if (x-1)*x<=2*A[i][1]<x*(x+1):
    a=x-1
  if (x+1)*x<=2*A[i][1]<(x+2)*(x+1):
    a=x
  if (x+1)*(x+2)<=2*A[i][1]<(x+2)*(x+3):
    a=x+1
  if (x+3)*(x+2)<=2*A[i][1]<(x+4)*(x+3):
    a=x+2
  ans=ans+a
print(a)
Problem p02662 (python)

Fixed submission:
n,s=map(int,input().split())
A=list(map(int,input().split()))
mod=998244353
a=499122177
b=pow(2,n-1,mod)
dp=[[0]*(s+1) for i in range(n+1)]
for i in range(n+1):
  dp[0][0]=pow(2,n,mod)
for i in range(1,n+1):
  dp[i]=dp[i-1][0:s+1]
  for j in range(s+1):
    if j+A[i-1]>s:
      break
    dp[i][j+A[i-1]]=(dp[i-1][j+A[i-1]]+dp[i-1][j]*a)%mod
print(dp[-1][-1])

Buggy submission (verdict: Runtime Error):
n,s=map(int,input().split())
mod=998244353
A=list(map(int,input().split()))
dp=[[]*(s+1) for i in range(n+1)]
dp[0][0]=[1]
for i in range(n+1):
  dp[i][0]=[1]
for i in range(1,n+1):
  for j in range(1,s+1):
    dp[i][j].append(dp[i-1][j])
    if j+A[i]<=s:
      dp[i][j+A[i]].append(dp[i][j]+1)
ans=0
for i in range(len(dp[n][s])):
  ans=ans+dp[n][s][i]*pow(2,n-dp[n][s][i],mod)
print(ans%mod)

Buggy submission (verdict: Runtime Error):
n,s=map(int,input().split())
mod=998244353
A=list(map(int,input().split()))
dp=[[]*(s+1) for i in range(n+1)]
dp[0][0]=[1]
for i in range(n+1):
  dp[i][0]=[1]
for i in range(1,n+1):
  for j in range(1,s+1):
    dp[i][j].append(dp[i-1][j])
    if j+A[i]<=s:
      dp[i][j+A[i]].append(dp[i][j]+1)
ans=0
for i in range(len(dp[n][s])):
  ans=ans+dp[n][s][i]*pow(2,n-i,mod)
print(ans%mod)
Problem p02686 (python)

Fixed submission:
n=int(input())
A=[]
B=[]
c=0
for i in range(n):
  S=input()
  a=0
  b=0
  for j in range(len(S)):
    if S[j]=="(":
      a=a+1
    else:
      a=a-1
      if a<b:
        b=a
  b=b*-1
  if b==0:
    c=c+a
  elif a>=0:
    B.append([b,-1*a])
  else:
    A.append([b+a,a])
A.sort()
B.sort()
f=0
for i in range(len(B)):
  if c-B[i][0]<0:
    f=1
  c=c-B[i][1]
d=0
for i in range(len(A)):
  if d-A[i][0]<0:
    f=1
  d=d-A[i][1]
if c!=d:
  f=1
if f==0:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
n=int(input())
A=[]
B=[]
c=0
for i in range(n):
  S=input()
  a=0
  b=0
  for j in range(len(S)):
    if S[j]=="(":
      a=a+1
    else:
      a=a-1
      if a<b:
        b=a
  if b==0:
    c=c+a
  elif a>0:
    B.append([b,-1*a])
  else:
    A.append([-1*b,a])
A.sort()
B.sort()
f=0
for i in range(len(B)):
  if c+B[i][0]<0:
    f=1
  c=c-A[i][1]
for i in range(len(A)):
  if c-A[i][0]<0:
    f=1
  c=c+A[i][1]
if c!=0:
  f=1
if f==0:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
n=int(input())
A=[]
B=[]
c=0
for i in range(n):
  S=input()
  a=0
  b=0
  for j in range(len(S)):
    if S[j]=="(":
      a=a+1
    else:
      a=a-1
      if a<b:
        b=a
  if b==0:
    c=c+a
  elif a>0:
    B.append[(b,-1*a)]
  else:
    A.append([-1*b,a])
A.sort()
B.sort()
f=0
for i in range(len(B)):
  if c+B[i][0]<0:
    f=1
  c=c-A[i][1]
for i in range(len(A)):
  if c-A[i][0]<0:
    f=1
  c=c+A[i][1]
if c!=0:
  f=1
if f==0:
  print("Yes")
else:
  print("No")
Problem p02714 (python)

Fixed submission:
n=int(input())
S=list(input())
dp=[[0]*(8) for i in range(n+1)]
dp[0][0]=1
for i in range(1,n+1):
  if S[i-1]=="R":
    for j in range(8):
      dp[i][j]=dp[i-1][j]
    dp[i][1]+=dp[i-1][0]
    dp[i][4]+=dp[i-1][2]
    dp[i][6]+=dp[i-1][3]
    dp[i][7]+=dp[i-1][5]
  elif S[i-1]=="G":
    for j in range(8):
      dp[i][j]=dp[i-1][j]
    dp[i][2]+=dp[i-1][0]
    dp[i][4]+=dp[i-1][1]
    dp[i][5]+=dp[i-1][3]
    dp[i][7]+=dp[i-1][6]
  else:
    for j in range(8):
      dp[i][j]=dp[i-1][j]
    dp[i][3]+=dp[i-1][0]
    dp[i][5]+=dp[i-1][2]
    dp[i][6]+=dp[i-1][1]
    dp[i][7]+=dp[i-1][4]
a=0
for i in range(n-2):
  for j in range(i+1,n-1):
    k=j*2-i
    if k>=n:
      continue
    if S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:
      a=a+1
print(dp[n][7]-a)

Buggy submission (verdict: Runtime Error):
N = int(input())
S = input()
R = [] 
G = []
B = []
i = 1
while i < N+1:
  a = S[i-1]
  if a == 'R':
    R.append(i)
  elif a == 'G':
    G.append(i)
  else:
    B.append(i)
  i += 1
  

c = 0
d = len(R)*len(G)*len(B)


if d == 0:
    print(0)
else:
    for t in range(len(R)):
        for u in range(len(G)):
            k = (R[t] + G[u])/2
            if 2*R[t]- G[u] > 0:
              l = 2*R[t]-G[u]
              if l|set(B)==set(B):
                c += 1
            if 2*G[u] - R[t] > 0:
              
              m = 2*G[u]-R[t]
              if m|set(B)==set(B):
                c += 1
            if k|set(B)==set(B):
                c += 1

print(d-c)
Problem p02720 (python)

Fixed submission:
k=int(input())
if k==1:
  print(1)
  exit()
if k==10:
  print(10)
  exit()
if k==36:
  print(100)
  exit()
if k==111:
  print(1000)
  exit()
if k==328:
  print(10000)
  exit()
if k==957:
  print(100000)
  exit()
if k==2783:
  print(1000000)
  exit()
if k==8090:
  print(10000000)
  exit()
if k==23528:
  print(100000000)
  exit()
if k==68469:
  print(1000000000)
  exit()
k=k-1
A=[[[1],[2],[3],[4],[5],[6],[7],[8],[9]]]+[[] for i in range(10)]
a=[-1,0,1]
B=[0]
for i in range(10):
  for j in A[i]:
    for s in range(3):
      if j[-1]==0 and s==0:
        continue
      if j[-1]==9 and s==2:
        continue
      A[i+1].append(j+[j[-1]+a[s]])
  B.append(B[-1]+len(A[i]))
i=0
while k>B[i]:
  i=i+1
for t in range(len(A[i-1][k-B[i-1]])):
  print(A[i-1][k-B[i-1]][t],end="")

Buggy submission (verdict: Runtime Error):
k=int(input())
if k==1:
  print(1)
  exit()
k=k-1
A=[[[1],[2],[3],[4],[5],[6],[7],[8],[9]]]+[[] for i in range(10)]
a=[-1,0,1]
B=[0]
for i in range(10):
  for j in A[i]:
    for s in range(3):
      if j[-1]==0 and s==0:
        continue
      if j[-1]==9 and s==2:
        continue
      A[i+1].append(j+[j[-1]+a[s]])
  B.append(B[-1]+len(A[i]))
i=0
while k>B[i]:
  i=i+1
for t in range(len(A[i-1][k-B[i-1]])):
  print(A[i-1][k-B[i-1]][t],end="")
Problem p02774 (python)

Fixed submission:
import sys
import bisect
iuput=sys.stdin.readline
n,k=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
s=bisect.bisect_left(A,0,lo=0,hi=len(A))
t=bisect.bisect_right(A,0,lo=0,hi=len(A))
An=A[0:s]
Ap=A[t:n]
if k<=s*(n-t):
  #二分探査
  ng=-10**19
  ok=1
  while ok-ng!=1:
    #積がmid以下になる組み合わせの数をカウント
    mid=(ok+ng)//2
    c=0
    j=0
    for i in range(s):
      if j<n-t:
        while An[i]*Ap[j]>mid:
          j=j+1
          if j==n-t:
            break
      if An[i]*Ap[-1]>mid:
        j=n-t
      c=c+(n-t-j)
    if c<k:
      ng=mid
    else:
      ok=mid
  print(ok)
elif k<=n*(n-1)//2-((n-t)*(n-t-1)//2)-s*(s-1)//2:
  print(0)
else:
  k=n*(n-1)//2-k+1#大きい順にk番目
  Ann=[0]*s
  for i in range(s):
    Ann[i]=An[i]*-1
  Ann=Ann[::-1]
  App=[0]*(n-t)
  for i in range(n-t):
    App[i]=Ap[i]*-1
  App=App[::-1]
  ng=-10**19
  ok=1
  while ok-ng!=1:
    #積がmid以下になる組み合わせの数をカウント
    mid=(ok+ng)//2
    c=0
    j=0
    for i in range(s):
      if j<s:
        while An[i]*Ann[j]>mid:
          j=j+1
          if j==s:
            break
      if An[i]*Ann[-1]>mid:
        j=s
      c=c+(s-j)
    cc=0
    for i in range(s):
      if An[i]*A[i]*-1<=mid:
        cc=cc+1
    j=0
    for i in range(n-t):
      if j<n-t:
        while App[i]*Ap[j]>mid:
          j=j+1
          if j==n-t:
            break
      if App[i]*Ap[-1]>mid:
        j=n-t
      c=c+(n-t-j)
    for i in range(n-t):
      if Ap[i]*Ap[i]*-1<=mid:
        cc=cc+1
    c=(c-cc)//2
    if c<k:
      ng=mid
    else:
      ok=mid
  print(-1*ok)

Buggy submission (verdict: Runtime Error):
import bisect
n,k=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
x=bisect.bisect_left(A,0,lo=0,hi=len(A))
y=bisect.bisect_right(A,0,lo=0,hi=len(A))
AN=x
A0=y-x
AP=n-y
if x!=0:
  An=A[:x]
else:
  An=[]
Ann=An[::-1]
Annn=[0]*AN
for i in range(AN):
  Annn[i]=Ann[i]*(-1)
if y!=n:
  App=A[-n+y:]
  Ap=App[::-1]
else:
  Ap=[]
if k<=AN*AP:
  ok=An[0]*Ap[0]-1
  ng=0
  while ng-ok>1:
    mid=(ok+ng)//2
    c=0
    for i in range(AN):
      c=c+AP-bisect.bisect_left(App,((-1)*mid+(-1)*An[i]-1)//((-1)*An[i]),lo=0,hi=AP)
    if c<k:
      ok=mid
    else:
      ng=mid
  ans=ok+1
  print(ans)
elif k<=n*(n-1)//2-AN*(AN-1)//2-AP*(AP-1)//2:
  print(0)
else:
  k=n*(n-1)//2-k+1
  ok=max(An[0]**2,Ap[0]**2)
  ng=0
  while ok-ng>1:
    mid=(ok+ng)//2
    c=0
    for i in range(AN):
      c=c+max(0,AN-i-1-bisect.bisect_left(Annn,(mid+Annn[AN-i-1]-1)//Annn[AN-i-1],lo=0,hi=AN))
    for i in range(AP):
      c=c+max(0,AP-i-1-bisect.bisect_left(App,(mid+App[AP-i-1]-1)//App[AP-i-1],lo=0,hi=AP))
    if c<k:
      ok=mid
    else:
      ng=mid
  ans=ok-1
  print(ans)
Problem p02782 (python)

Fixed submission:
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 2*10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
    
r,c,R,C=map(int,input().split())
ans=0
for i in range(C-c):
  ans=ans+cmb(r+c+1+i,r,mod)*cmb(R-r+C-c-i,R-r,mod)
ans=ans+cmb(r+c,r,mod)
for i in range(R-r):
  ans=ans+cmb(c+r+1+i,c,mod)*cmb(C-c+R-r-i,C-c,mod)
print(ans%mod)

Buggy submission (verdict: Runtime Error):
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**4
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
    
r,c,R,C=map(int,input().split())
ans=0
for i in range(C-c):
  ans=ans+cmb(r+c+1+i,r,mod)*cmb(R-r+C-c-i,R-r,mod)
ans=ans+cmb(r+c,r,mod)
for i in range(R-r):
  ans=ans+cmb(c+r+1+i,c,mod)*cmb(C-c+R-r-i,C-c,mod)
print(ans%mod)
Problem p02801 (python)

Fixed submission:
print(chr(ord(input())+1))

Buggy submission (verdict: Runtime Error):
n=int(input())
x=[0]*n
y=[0]*n
for i in range(n):
  x[i],y[i]=map(int,input().split())
if n==2:
  print(((x[0]-x[1])**2+(y[0]-y[1])**2)**(1/2)/2)
else:
  ans=10**5
  A=[0]*3
  B=[0]*3
  for i in range(n-2):
    for j in range(i+1,n-1):
      A[0]=x[j]-x[i]
      A[1]=y[j]-y[i]
      A[2]=A[0]*(x[i]+x[j])/2+A[1]*(y[i]+y[j])/2
      for k in range(j+1,n):
        B[0]=x[k]-x[i]
        B[1]=y[k]-y[i]
        B[2]=B[0]*(x[i]+x[k])/2+B[1]*(y[i]+y[k])/2
        if A[0]*B[1]==A[1]*B[0] and A[0]*B[1]!=0:#三点が同一直線状に存在1
          r=((max(x[i],x[j],x[k])-min(x[i],x[j],x[k]))**2+(max(y[i],y[j],y[k])-min(y[i],y[j],y[k]))**2)**(1/2)/2
          xc=(max(x[i],x[j],x[k])+min(x[i],x[j],x[k]))/2
          yc=(max(y[i],y[j],y[k])+min(y[i],y[j],y[k]))/2
        elif A[0]==B[0]==0:#2
          r=(max(y[i],y[j],y[k])-min(y[i],y[j],y[k]))/2
          xc=x[i]
          yc=(max(y[i],y[j],y[k])+min(y[i],y[j],y[k]))/2
        elif A[1]==B[1]==0:#3
          r=(max(x[i],x[j],x[k])-min(x[i],x[j],x[k]))/2
          yc=y[i]
          xc=(max(x[i],x[j],x[k])+min(x[i],x[j],x[k]))/2
        else:
          xc=(A[2]*B[1]-A[1]*B[2])/(A[0]*B[1]-A[1]*B[0])
          yc=(A[0]*B[2]-A[2]*B[0])/(A[0]*B[1]-A[1]*B[0])
          r=((x[i]-xc)**2+(y[i]-yc)**2)**(1/2)
        aa=0
        r=min(r*1.000000999,r+0.000000999)
        for l in range(n):
          if ((x[l]-xc)**2+(y[l]-yc)**2)**(1/2)>r:
            aa=1
        if aa==0:
          if r<ans:
            ans=r
  print(ans)
Problem p02803 (python)

Fixed submission:
from collections import deque
h,w=map(int,input().split())
G=[["#"]*(w+2) for i in range(h+2)]
for i in range(1,h+1):
  G[i]=["#"]+list(input())+["#"]
ans=0
for sx in range(1,h+1):
  for sy in range(1,w+1):
    if G[sx][sy]==".":
      B=[[0]*(w+2) for i in range(h+2)]
      for i in range(h+2):
        for j in range(w+2):
          if G[i][j]=="#":
            B[i][j]=1
      INF=10**4
      A=[[INF]*(w+2) for i in range(h+2)]
      C=[-1,1,0,0]
      D=[0,0,-1,1]
      A[sx][sy]=0
      E=deque([sx,sy])
      while len(E)>0:
        x=E[0]
        E.popleft()
        y=E[0]
        E.popleft()
        B[x][y]=1
        for i in range(4):
          if B[x+C[i]][y+D[i]]==0:
            A[x+C[i]][y+D[i]]=A[x][y]+1
            a=A[x+C[i]][y+D[i]]
            B[x+C[i]][y+D[i]]=1
            E.append(x+C[i])
            E.append(y+D[i])
      if ans<a:
        ans=a
    else:
      continue
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import deque
h,w=map(int,input().split())
G=[["#"]*(w+2) for i in range(h+2)]
for i in range(1,h+1):
  G[i]=["#"]+list(input())+["#"]
ans=0
for sx in range(1,h+1):
  for sy in range(1,w+1):
    B=[[0]*(w+2) for i in range(h+2)]
    for i in range(h+2):
      for j in range(w+2):
        if G[i][j]=="#":
          B[i][j]=1
    INF=10**4
    A=[[INF]*(w+2) for i in range(h+2)]
    C=[-1,1,0,0]
    D=[0,0,-1,1]
    A[sx][sy]=0
    E=deque([sx,sy])
    while len(E)>0:
      x=E[0]
      E.popleft()
      y=E[0]
      E.popleft()
      for i in range(4):
        if B[x+C[i]][y+D[i]]==0:
          A[x+C[i]][y+D[i]]=A[x][y]+1
          a=A[x+C[i]][y+D[i]]
          B[x+C[i]][y+D[i]]=1
          E.append(x+C[i])
          E.append(y+D[i])
    if ans<a:
      ans=a
print(ans)
Problem p02806 (python)

Fixed submission:
n=int(input())
A=[[0]*2 for i in range(n)]
for i in range(n):
  A[i][0],A[i][1]=input().split()
  A[i][1]=int(A[i][1])
x=input()
for i in range(n):
  if A[i][0]==x:
    break
ans=0
for j in range(i+1,n):
  ans=ans+A[j][1]
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
A=[[]for i in range(n)]
A[0].append(1)
for i in range(2,n+1):
  for j in range(i-1):
    A[i-1].append(A[i-2][j]*i)
  A[i-1].append(A[i-1][-1]+A[i-2][0])
X=list(map(int,input().split()))
Y=[X[1]-X[0]]
for i in range(2,n):
  Y.append(X[i]-X[i-1])
ans=0
for i in range(n-1):
  ans=(ans+A[n-2][i]*Y[i])%(10**9+7)
print(ans)
Problem p02807 (python)

Fixed submission:
n=int(input())
x=list(map(int,input().split()))
a=1
B=[1,1]
mod=10**9+7
for i in range(2,n):
  a=a*i%mod
  B.append(pow(i,mod-2,mod))
d=[0]*(n-1)
for i in range(n-1):
  d[i]=x[i+1]-x[i]
D=[d[-1]]
for i in range(n-2):
  D.append(D[-1]+d[-2-i])
D=D[::-1]
ans=0
for i in range(n-1):
  ans=(ans+D[i]*a*B[i+1])%mod
print(ans)

Buggy submission (verdict: Runtime Error):
def per(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r=n-r
    return g1[n] * g2[r] % mod

mod = 10**9+7 #出力の制限
N = 10**4
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )


n=int(input())
A=[1]
for i in range(1,n-1):
  A.append(A[-1]*(i+1)+per(i,i,mod))
X=list(map(int,input().split()))
Y=[X[1]-X[0]]
for i in range(2,n):
  Y.append(X[i]-X[i-1])
ans=0
for i in range(n-1):
  if n-2-i==0:
    ans=ans+A[i]*Y[i]
  else:
    ans=(ans+A[i]*per(n-1,n-2-i,mod)*Y[i])%(10**9+7)
print(ans%mod)
Problem p02814 (python)

Fixed submission:
import copy
import fractions
import sys
n,m=map(int,input().split())
A=list(map(int,input().split()))
a=copy.copy(A[0])
c=0
while a%2==0:
  a=a//2
  c=c+1
d=2**c
for i in range(n):
  if A[i]//d!=float(A[i])/d or A[i]//(2*d)==float(A[i])/(2*d):
    print(0)
    sys.exit()
B=[]
for i in range(n):
  B.append(A[i]//2)
b=1
for i in range(n):
  b=b*B[i]//fractions.gcd(b,B[i])
  if b>m:
    print(0)
    sys.exit()
if b>m:
  print(0)
else:
  print(1+(m-b)//(2*b))

Buggy submission (verdict: Runtime Error):
import math
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

print(lcm_list([28,40,35]))
Problem p02839 (python)

Fixed submission:
h,w=map(int,input().split())
A=[[0]*w for i in range(h)]
for i in range(h):
  A[i]=list(map(int,input().split()))
B=[[0]*w for i in range(h)]
for i in range(h):
  B[i]=list(map(int,input().split()))
C=[[0]* w for i in range(h)]
for i in range(h):
  for j in range(w):
    C[i][j]=abs(A[i][j]-B[i][j])
dp=[[[0]*6401 for j in range(h+1)] for i in range(h+w+1)]
dp[0][0][C[0][0]]=1
for i in range(h+w):
  for j in range(max(0,i-w),min(i,h)+1):
    for k in range(6401):
      if dp[i][j][k]==1:
        if i-j<w-1:
          if k+C[j][i-j+1]<6400:
            dp[i+1][j][k+C[j][i-j+1]]=1
          dp[i+1][j][abs(k-C[j][i-j+1])]=1
        if j<h-1:
          if k+C[j+1][i-j]<6400:
            dp[i+1][j+1][k+C[j+1][i-j]]=1
          dp[i+1][j+1][abs(k-C[j+1][i-j])]=1
for k in range(6400):
  if dp[h+w-2][h-1][k]==1:
    print(k)
    exit()

Buggy submission (verdict: Runtime Error):
h,w=map(int,input().split())
A=[[0]*w for i in range(h)]
for i in range(h):
  A[i]=list(map(int,input().split()))
B=[[0]*w for i in range(h)]
for i in range(h):
  B[i]=list(map(int,input().split()))
C=[[0]* w for i in range(h)]
for i in range(h):
  for j in range(w):
    C[i][j]=abs(A[i][j]-B[i][j])
dp=[[[0]*6401 for j in range(h+1)] for i in range(h+w+1)]
dp[0][0][C[0][0]]=1
for i in range(h+w):
  for j in range(max(0,i-w),min(i,h)+1):
    for k in range(6401):
      if dp[i][j][k]==1:
        if i-j<w-1:
          if k+C[j][i-j]<6400:
            dp[i+1][j][k+C[j][i-j+1]]=1
          dp[i+1][j][abs(k-C[j][i-j+1])]=1
        if j<h-1:
          if k+C[j+1][i-j]<6400:
            dp[i+1][j+1][k+C[j+1][i-j]]=1
          dp[i+1][j+1][abs(k-C[j+1][i-j])]=1
for k in range(6400):
  if dp[h+w-2][h-1][k]==1:
    print(k)
    exit()
Problem p02969 (python)

Fixed submission:
r=int(input())
print(3*r*r)

Buggy submission (verdict: Runtime Error):
import bisect
n=int(input())
A=[int(input())]
for i in range(n-1):
  a=int(input())
  b=bisect.bisect_right(A,a,lo=0,hi=len(A))
  if b!=0 and A[b-1]<a:
    A[b-1]=a
  elif A[b-1]==a:
    b=bisect.bisect_right(A,a-1,lo=0,hi=len(A))
    if b!=0:
      A[b-1]=a
    else:
      A.insert(0,a)
  else:
    A.insert(0,a)
print(len(A))