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

Fixed submission:
def gcd(n1,n2):
    if n2 > n1:
        return gcd(n2,n1)
    if n2 == 0:
        return n1
    return gcd(n2,n1%n2)

def main():
    a,b,c,d = map(int,input().split())
    total = b-a+1
    n1 = (b//c)-(a//c)
    n2 = (b//d)-(a//d)
    lcm = (c*d)//gcd(c,d)
    n3 = (b//lcm)-(a//lcm)
    if a%c == 0:
        n1 += 1
    if a%d == 0:
        n2 += 1
    if a%lcm == 0:
        n3 += 1

    #print(n1,n2,n3)
    print(total-n1-n2+n3)

main()

Buggy submission (verdict: Runtime Error):
import math

def main():
    a,b,c,d = map(int,input().split())
    total = b-a+1
    n1 = (b//c)-(a//c)
    n2 = (b//d)-(a//d)
    lcm = (c*d)//math.gcd(c,d)
    n3 = (b//lcm)-(a//lcm)
    if a%c == 0:
        n1 += 1
    if a%d == 0:
        n2 += 1
    if a%lcm == 0:
        n3 += 1

    #print(n1,n2,n3)
    print(total-n1-n2+n3)

main()
Problem p03160 (python)

Fixed submission:
def main():
    n = int(input())
    hts = list(map(int,input().split()))
    if n == 2:
        print(abs(hts[0]-hts[1]))
        return
    
    dp = [0]*n
    dp[0] = 0
    dp[1] = abs(hts[1]-hts[0])
    dp[2] = abs(hts[2]-hts[0])

    for i in range(3,n):
        dp[i] = min(dp[i-1]+abs(hts[i]-hts[i-1]),
                    dp[i-2]+abs(hts[i]-hts[i-2]))

    print(dp[-1])

main()

Buggy submission (verdict: Runtime Error):
def main():
    n,k = map(int,input().split())
    hts = list(map(int,input().split()))
    
    dp = [float('inf')]*n
    dp[0] = 0
    dp[1] = abs(hts[1]-hts[0])

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

        dp[i] = ans

    for i in range(k,n):
        ans = dp[i]
        for j in range(k,0,-1):
            ans = min(ans,dp[i-j]+abs(hts[i]-hts[i-j]))

        dp[i] = ans

    #print(dp)

    print(dp[-1])

main()
Problem p03166 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**9)

def dfs(dp,edges,node,visited):
    if node not in visited:
        visited.add(node)
        for kid in edges[node]:
            dfs(dp,edges,kid,visited)
            #print(dp,node,kid)
            dp[node-1] = max(dp[node-1],dp[kid-1])
        if edges[node]:
            dp[node-1] += 1

def solve(edges,n):
    dp = [0]*n
    visited = set()
    for i in range(1,n+1):
        if i not in visited:
            #print(i)
            dfs(dp,edges,i,visited)

    #print(dp)
    print(max(dp))

def main():
    n,m = map(int,input().split())
    edges = {}
    for i in range(1,n+1):
        edges[i] = []

    for i in range(m):
        x,y = map(int,input().split())
        edges[x].append(y)

    solve(edges,n)


main()

Buggy submission (verdict: Runtime Error):
def dfs(dp,edges,node,visited):
    if node not in visited:
        visited.add(node)
        for kid in edges[node]:
            dfs(dp,edges,kid,visited)
            #print(dp,node,kid)
            dp[node-1] = max(dp[node-1],dp[kid-1])
        if edges[node]:
            dp[node-1] += 1

def solve(edges,n):
    dp = [0]*n
    visited = set()
    for i in range(1,n+1):
        if i not in visited:
            #print(i)
            dfs(dp,edges,i,visited)

    #print(dp)
    print(max(dp))

def main():
    n,m = map(int,raw_input().split())
    edges = {}
    for i in range(1,n+1):
        edges[i] = []

    for i in range(m):
        x,y = map(int,raw_input().split())
        edges[x].append(y)

    solve(edges,n)


main()

Buggy submission (verdict: Runtime Error):
def dfs(dp,edges,node,visited):
    if node not in visited:
        visited.add(node)
        for kid in edges[node]:
            dfs(dp,edges,kid,visited)
            #print(dp,node,kid)
            dp[node-1] = max(dp[node-1],dp[kid-1])
        if edges[node]:
            dp[node-1] += 1

def solve(edges,n):
    dp = [0]*n
    visited = set()
    for i in range(1,n+1):
        if i not in visited:
            #print(i)
            dfs(dp,edges,i,visited)

    #print(dp)
    print(max(dp))

def main():
    n,m = map(int,input().split())
    edges = {}
    for i in range(1,n+1):
        edges[i] = []

    for i in range(m):
        x,y = map(int,input().split())
        edges[x].append(y)

    solve(edges,n)


main()

Buggy submission (verdict: Runtime Error):
def dfs(dp,edges,node,visited):
    if node not in visited:
        visited.add(node)
        for kid in edges[node]:
            dfs(dp,edges,kid,visited)
            #print(dp,node,kid)
            dp[node-1] = max(dp[node-1],dp[kid-1])
        if edges[node]:
            dp[node-1] += 1

def solve(edges,n):
    dp = [0]*n
    visited = set()
    for i in range(1,n+1):
        if i not in visited:
            #print(i)
            dfs(dp,edges,i,visited)

    #print(dp)
    print(max(dp))

def main():
    n,m = map(int,input().split())
    edges = {}
    for i in range(1,n+1):
        edges[i] = []

    for i in range(m):
        x,y = map(int,input().split())
        edges[x].append(y)

    solve(edges,n)


main()
Problem p02554 (python)

Fixed submission:
N=int(input())
MOD=10**9+7
MAX=N+1
def powermod(base,ind):
  if ind==1:
    return base
  elif ind%2==0:
    return (powermod(base,ind//2)**2)%MOD
  else:
    return ((powermod(base,ind//2)**2)*base)%MOD

print((powermod(10,N)-2*powermod(9,N)+powermod(8,N))%MOD)

Buggy submission (verdict: Runtime Error):
N=int(input())
MOD=10**9+7
MAX=N+1
powerls=[0 for i in range(MAX)]
powerls[0]=1
powerls[1]=base                     
def powermod(ind):
  if powerls[ind]!=0:
    return powerls[ind]
  elif ind%2==0:
    p=(powermod(base,ind//2)**2)%MOD
    powerls[ind]=p
    return p
  else:
    p=((powermod(base,ind//2)**2)*base)%MOD     
    powerls[ind]=p
    return p

print((powermod(10,N)-2*powermod(9,N)+powermod(8,N))%MOD)
Problem p02555 (python)

Fixed submission:
N=int(input())
MOD=10**9+7
DP1=[0 for _ in range(N+3)]
DP2=[0 for _ in range(N+3)]
DP1[3]=1
DP2[3]=1
for i in range(4,N+1):
  DP1[i]=(DP2[i-3]+1)%MOD
  DP2[i]=(DP1[i]+DP2[i-1])%MOD
print(DP1[N])

Buggy submission (verdict: Runtime Error):
N=int(input())
MOD=10**9+7
DP1=[0 for _ in range(N+2)]
DP2=[0 for _ in range(N+2)]
DP1[3]=1
DP2[3]=1
for i in range(4,N+1):
  DP1[i]=(DP2[i-3]+1)%MOD
  DP2[i]=(DP1[i]+DP2[i-1])%MOD
print(DP1[N])
Problem p02574 (python)

Fixed submission:
import math
import time

start=time.time()

N=int(input())
ls=[int(s) for s in input().split()]
M=max(ls)
SQRT_M=int(math.sqrt(M))+1
#素数のリスト作成
prime=[1 for i in range(SQRT_M+1)]
prime[0]=0
prime[1]=0
primels=[]
primedic={}
for i in range(2,SQRT_M+1):
  if prime[i]==1:
    primels.append(i)
    primedic[i]=0
    a=1
    while a*i<=SQRT_M:
      prime[a*i]=0
      a+=1

for e in ls:
  for p in primels:
    if e%p==0:
      primedic[p]+=1
      while e%p==0:
        e//=p
    if e==1:
      break
  else:
    if e in primedic:
      primedic[e]+=1
    else:
      primedic[e]=1
  if time.time()-start>1.9:
    break
    

A=max(primedic.values())

if A==len(ls):
  print('not coprime')
elif A>1:
  print('setwise coprime')
else:
  print('pairwise coprime')

Buggy submission (verdict: Runtime Error):
N=int(input())
ls=[int(s) for s in input().split()]
M=max(ls)
#素数のリスト作成
prime=[1 for i in range(M+1)]
prime[0]=0
prime[1]=0
primels=[]
primedic={}
for i in range(2,M+1):
  if prime[i]==1:
    primels.append(i)
    primedic[i]=0
    a=1
    while a*i<=M:
      prime[a*i]=0
      a+=1

for e in ls:
  for p in primels:
    if e%p==0:
      primedic[p]+=1
      while e%p==0:
        e//=p
    if e==1:
      break
    
A=max(primedic.values())
if A==len(ls):
  print('not coprime')
elif A>1:
  print('setwise coprime')
else:
  print('pairwise coprime')
Problem p02609 (python)

Fixed submission:
N=int(input())
S=input()

#Sのビット数
bitcount=0
for i in range(N):
  if S[i]=='1':
    bitcount+=1
bp=bitcount+1
bm=bitcount-1

lsp=[1 for i in range(N)]
for i in range(1,N):
  lsp[i]=(lsp[i-1]*2)%bp
lsp.reverse()
fXp=0
for i in range(N):
  if S[i]=='1':
    fXp=(fXp+lsp[i])%bp
    
if bm!=0:
  lsm=[1 for i in range(N)]
  for i in range(1,N):
    lsm[i]=(lsm[i-1]*2)%bm
  lsm.reverse()
  fXm=0
  for i in range(N):
    if S[i]=='1':
      fXm=(fXm+lsm[i])%bm


def f(n):
  c=0
  x=1
  while x<=n:
    if n&x>0:
      c+=1
    x*=2
  return n%c

ls=[0 for i in range(bitcount+2)]  
for i in range(1,bitcount+2):
  ls[i]=ls[f(i)]+1

for i in range(N):
  if S[i]=='0':
    print(ls[(fXp+lsp[i])%bp]+1)
  else:
    if bm==0:
      print(0)
    else:
      print(ls[(fXm-lsm[i])%bm]+1)

Buggy submission (verdict: Runtime Error):
N=int(input())
S=input()
X=int(S,2)

#Sのビット数
bitcount=0
for i in range(N):
  if S[i]=='1':
    bitcount+=1
bp=bitcount+1
bm=bitcount-1
    

fXp=X%bp
fXm=X%bm
    

def f(n):
  c=0
  x=1
  while x<=n:
    if n&x>0:
      c+=1
    x*=2
  return n%c

ls=[0 for i in range(bitcount+2)]  
ls2=[0 for i in range(bitcount+2)]
for i in range(1,bitcount+2):
  ls[i]=f(i)
  ls2[i]=ls2[ls[i]]+1

for i in range(N):
  if S[i]=='0':
    print(ls2[(fXp+2**(N-1-i))%bp]+1)
  else:
    if (X^(2**(N-1-i)))==0:
      print(0)
    else:
      print(ls2[(fXm-2**(N-1-i))%bm]+1)
  
      #print(ls2[(fXm-ls_bitm[N-1-i])%bm]+1)

Buggy submission (verdict: Runtime Error):
N=int(input())
S=input()
X=int(S,2)

#Sのビット数
bitcount=0
for i in range(N):
  if S[i]=='1':
    bitcount+=1

def f(n):
  c=0
  x=1
  while x<=n:
    if n&x>0:
      c+=1
    x*=2
  return n%c

ls=[0 for i in range(bitcount+2)]  
ls2=[0 for i in range(bitcount+2)]
for i in range(1,bitcount+2):
  ls[i]=f(i)
  ls2[i]=ls2[ls[i]]+1

for i in range(N):
  if S[i]=='0':
    print(ls2[(X^(2**(N-1-i)))%(bitcount+1)]+1)
  else:
    print(ls2[(X^(2**(N-1-i)))%(bitcount-1)]+1)
Problem p02761 (python)

Fixed submission:
N,K=[int(s) for s in input().split()]
ls=[-1 for _ in range(N+1)]
for _ in range(K):
  a,b=[int(s) for s in input().split()]
  if ls[a]==-1:
    ls[a]=b
  elif ls[a]==b:
    continue
  else:
    ls[0]=0
ans=0


if ls[0]==0:
  print(-1)
else:
  if N==1:
    ans=max([ls[1],0])    
  if N==2:
    for i in range(10,100):
      if ls[1]==0:
        ans=-1
      else:
        a=i//10
        b=i%10
        if (a==ls[1] or ls[1]==-1) and (b==ls[2] or ls[2]==-1):
          ans=i
          break
  if N==3:
    for i in range(100,1000):
      if ls[1]==0:
        ans=-1
      else:
        a=i//100
        b=(i//10)%10
        c=i%10
        if (a==ls[1] or ls[1]==-1) and (b==ls[2] or ls[2]==-1) and (c==ls[3] or ls[3]==-1):
          ans=i
          break
  print(ans)

Buggy submission (verdict: Runtime Error):
N,K=[int(s) for s in input().split()]
ls=[-1 for _ in range(N+1)]
for _ in range(K):
  a,b=[int(s) for s in input().split()]
  if ls[a]==-1:
    ls[a]=b
  else:
    ls[0]=0
    
print(ls)

if ls[0]==0:
  print(-1)
else:
  if N==1:
    ans=max([ls[1],0])    
  if N==2:
    for i in range(10,100):
      a=i//10
      b=i%10
      if (a==ls[1] or ls[1]==-1) and (b==ls[2] or ls[2]==-1):
        ans=i
        break
  if N==3:
    for i in range(100,1000):
      a=i//100
      b=(i//10)%10
      c=i%10
      if (a==ls[1] or ls[1]==-1) and (b==ls[2] or ls[2]==-1) and (c==ls[3] or ls[3]==-1):
        ans=i
        break
print(ans)
Problem p02786 (python)

Fixed submission:
N=int(input())
a=0
d=1
while d<=N:
  a+=d
  d*=2
print(a)

Buggy submission (verdict: Runtime Error):
N=int(input())
a=0
d=1
while d<=N:
  a+=d
  d*=2
print(ans)
Problem p02789 (python)

Fixed submission:
N,M=[int(s) for s in input().split()]
if N==M:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
N,M=[int(s) for s in input().split()]
if N==M:
  print(Yes)
else:
  print(No)
Problem p02845 (python)

Fixed submission:
MOD=1000000007
N=int(input())
ls=[int(s) for s in input().split()]
RGB=[0,0,0]
ans=1
for i in range(N):
  if ls[i] in RGB:
    x=RGB.count(ls[i])
    ans=(ans*x)%MOD
    y=RGB.index(ls[i])
    RGB[y]+=1
  else:
    ans=0
    break
print(ans)

Buggy submission (verdict: Runtime Error):
MOD=1000000007
N=int(input())
ls=[int(s) for s in input().split()]
RGB=[0,0,0]
ans=1
for i in range(N):
  x=RGB.count(ls[i])
  ans=(ans*x)%MOD
  y=RGB.index(ls[i])
  RGB[y]+=1
print(ans)
Problem p02855 (python)

Fixed submission:
H,W,K=[int(s) for s in input().split()]
ls=[input() for i in range(H)]
ans=[[] for i in range(H)]
num=1
s=[] ##イチゴがあるかないか
for i in range(H):
  if '#' in ls[i]:
    s.append(1)
    p=0
    for j in range(W):
      if ls[i][j]=='#':
        if p==0:
          p=1
        else:
          num+=1
      ans[i].append(num)
    num+=1
  else:
    s.append(0)
for i in range(H):
  if s[i]==0:
    for k in range(1,H):
      if i+k>=H: break
      if s[i+k]==1:
        ans[i]=ans[i+k]
        break
for i in range(1,H):
  if s[-i]==0:
    for k in range(1,H):
      if i+k>H: break
      if s[-i-k]==1:
        ans[-i]=ans[-i-k]
        break
  else:
    break
for i in range(H):
  print(*ans[i])

Buggy submission (verdict: Runtime Error):
H,W,K=[int(s) for s in input().split()]
ls=[input() for i in range(H)]
ans=[[] for i in range(H)]
num=1
s=[] ##イチゴがあるかないか
for i in range(H):
  if '#' in ls[i]:
    s.append(1)
    p=0
    for j in range(W):
      if ls[i][j]=='#':
        if p==0:
          p=1
        else:
          num+=1
      ans[i].append(num)
    num+=1
  else:
    s.append(0)
for i in range(H):
  if s[i]==0:
    for k in range(1,H):
      if s[i+k]==1:
        ans[i]=ans[i+k]
        break
for i in range(1,H):
  if s[-i]==0:
    for k in range(1,H):
      if s[-i-k]==1:
        ans[-i]=ans[-i-k]
        break
  else:
    break
for i in range(H):
  print(*ans[i])
Problem p02901 (python)

Fixed submission:
n,m=[int(s) for s in input().split()]
key=[]
for i in range(m):
  cost,b=[int(s) for s in input().split()]
  op=0
  for i in input().split():
    op+=1<<(int(i)-1)
  key.append([cost,op])
N=2**n
dp=[[10**7 for _ in range(N)] for _ in range(m)]
dp[0][key[0][1]]=key[0][0]
dp[0][0]=0
for i in range(1,m):
  for j in range(N):
    dp[i][j]=min([dp[i-1][j],dp[i][j]])
    x=j|key[i][1]
    dp[i][x]=min([dp[i][x],dp[i-1][j]+key[i][0]])
if dp[m-1][N-1]==10**7:
  print(-1)
else:
  print(dp[m-1][N-1])

Buggy submission (verdict: Runtime Error):
n,m=[int(s) for s in input().split()]
key_ls=[]
for i in range(m):
  a,b=[int(s) for s in input().split()]
  op=[int(s) for s in input().split()]
  key_ls.append([a,op])
key_ls.sort()
#print(key_ls)
door=[0 for _ in range(n)]
door2=[1 for _ in range(n)]
cost=0
#####一番安い鍵から順にかっていく
while True:
  if door==door2 : break
  key=key_ls.pop(0)
  flag=0
  #まだ開いていない箱を開けられるか？
  for x in key[1]:
    if door[x-1]==0:
      flag=1
      break
  #開けられるなら購入
  if flag==1:
    cost+=key[0]
  for x in key[1]:
    door[x-1]=1
    
print(cost)
Problem p02922 (python)

Fixed submission:
A,B= [int(s) for s in input().split()]
i=0
while(True):
  if B<=1:
    break
  B-=A-1
  i+=1
print(i)

Buggy submission (verdict: Runtime Error):
A,B= [int(s) for s in input().split()]
x=1
if B=1:
  print(0)
else:
  for i in range(100):
    x+=A-1
    if x>=B:
      break
  print(i+1)
Problem p02947 (python)

Fixed submission:
N=int(input())
d={}
for i in range(N):
  text=''.join(sorted(input()))
  if text in d :
    d[text]+=1
  else:
    d[text]=1
count=0
for v in d.values() :
  count+=(v-1)*v/2
print(int(count))

Buggy submission (verdict: Runtime Error):
N=int(input())
lst=[]
for i in range(N):
  text=input()
  lst=lst+[sorted(text)]
lst=sorted(lst)      
count=0
i=0
while(i<N):
  j=1
  while(lst[i]==lst[i+j]):
    count=count+j
    j=j+1
    if (i+j >= N):
      break
  i=i+j
print(count)
Problem p03000 (python)

Fixed submission:
N,X= [int(s) for s in input().split()]
lst = [int(s) for s in input().split()]
dist=0
count=0
while(count<N):
  dist=dist+lst[count]
  if(dist>X):
    break
  count=count+1
print(count+1)

Buggy submission (verdict: Runtime Error):
N,X= [int(s) for s in input().split()]
lst = [int(s) for s in input().split()]
dist=0
count=0
while(1):
  dist=dist+lst[count]
  if(dist>X or count==N):
    break
  count=count+1
print(count+1)
Problem p03035 (python)

Fixed submission:
a,b = [int(s) for s in input().split()]
if a>=13:
  print(b)
elif a>=6:
  print(b//2)
else:
  print(0)

Buggy submission (verdict: Runtime Error):
a,b = [int(s) for s in input().split()]
if a>=13:
  print(b)
elif a<=6:
  print(b/2)
else:
  print 0
Problem p03071 (python)

Fixed submission:
A,B=[int(s) for s in input().split()]
if A>B:
  print(2*A-1)
elif A==B:
  print(2*A)
else:
  print(2*B-1)

Buggy submission (verdict: Runtime Error):
A,B=[int(s) for s in input().split()]
if A>B:
  print(2*A-1)
elif A=B:
  print(2*A)
else:
  print(2*B-1)
Problem p03078 (python)

Fixed submission:
X,Y,Z,K=[int(s) for s in input().split()]
xls=sorted([int(s) for s in input().split()],reverse=True)
yls=sorted([int(s) for s in input().split()],reverse=True)
zls=sorted([int(s) for s in input().split()],reverse=True)
xyls=[]
for x in xls[:K]:
  for y in yls[:K]:
    xyls.append(x+y)
xyls=sorted(xyls,reverse=True)
cake=[]
for xy in xyls[:K]:
  for z in zls[:K]:
    cake.append(xy+z)
cake=sorted(cake,reverse=True)
for i in range(K):
  print(cake[i])

Buggy submission (verdict: Runtime Error):
import heapq
X,Y,Z,K=[int(s) for s in input().split()]
x=sorted([-int(s) for s in input().split()])
y=sorted([-int(s) for s in input().split()])
z=sorted([-int(s) for s in input().split()])
count=[[[0 for _ in range(X)]for _ in range(Y)]for _ in range(Z)]
count[0][0][0]=1
Q=[[x[0]+y[0]+z[0],0,0,0]]
heapq.heapify(Q)
for i in range(K):
  cake,a,b,c=heapq.heappop(Q)
  print(-cake)
  if count[a+1][b][c]==0:
    heapq.heappush(Q,[x[a+1]+y[b]+z[c],a+1,b,c])
    count[a+1][b][c]=1
  if count[a][b+1][c]==0:
    heapq.heappush(Q,[x[a]+y[b+1]+z[c],a,b+1,c])
    count[a][b+1][c]=1
  if count[a][b][c+1]==0:
    heapq.heappush(Q,[x[a]+y[b]+z[c+1],a,b,c+1])
    count[a][b][c+1]=1
Problem p03085 (python)

Fixed submission:
X=input()
if X=="A":
  print("T")
elif X=="T":
  print("A")
elif X=="G":
  print("C")
else:
  print("G")

Buggy submission (verdict: Runtime Error):
X=input()
if X=="A":
  print("T")
elif X="T":
  print("A")
elif X="G":
  print("C")
else:
  print("G")
Problem p03110 (python)

Fixed submission:
n=int(input())
x=0
for i in range(n):
  a,b=input().split()
  if b=="JPY":
    x+=int(a)
  else:
    x+=float(a)*380000
print(x)

Buggy submission (verdict: Runtime Error):
n=int(input())
x=0
for i in range(n):
  a,b=input().split()
  if b=="JPY":
    x+=int(input())
  else:
    x+=float(input())*380000
print(x)
Problem p03240 (python)

Fixed submission:
N=int(input())
ls=[[int(s) for s in input().split()] for i in range(N)]
ans=[0,0,0]
for i in range(N):
  if ls[i][2]!=0:
    a=ls[i][0]
    b=ls[i][1]
    h_base=ls[i][2]
    ls.pop(i)
    break
for x in range(101):
  for y in range(101):
    ##x,yの高さを計算
    h=h_base+abs(x-a)+abs(y-b)
    ##他の条件と合うか？
    flag=1
    for e in ls:
      if (h!=e[2]+abs(x-e[0])+abs(y-e[1]) and e[2]>0): 
        flag=0
        break
      if (h>e[2]+abs(x-e[0])+abs(y-e[1]) and e[2]==0):
        flag=0
        break
    if flag==1:
      ans=[x,y,h]
      break
  if flag==1:
    break
print(*ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
ls=[[int(s) for s in input().split()] for i in range(N)]
flag2=1
for i in range(N):
  if ls[i][2]!=0:
    a=ls[i][0]
    b=ls[i][1]
    h_base=ls[i][2]
    ls.pop(i)
    flag2=0
    break
if flag2==0:
  for x in range(101):
    for y in range(101):
      ##x,yの高さを計算
      h=h_base+abs(x-a)+abs(y-b)
      ##他の条件と合うか？
      flag=1
      for e in ls:
        if h!=e[2]+abs(x-e[0])+abs(y-e[1]):
          flag=0
          break
      if flag==1:
        ans=[x,y,h]
        break
    if flag==1:
      break
else:
  xsum=0
  ysum=0
  for e in ls:
    xsum+=e[0]
    ysum+=e[1]
  ans=[5050*101-xsum,5050*101-ysum,1]
print(*ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
ls=[[int(s) for s in input().split()] for i in range(N)]
flag2=1
for i in range(N):
  if ls[i][2]!=0:
    a=ls[i][0]
    b=ls[i][1]
    h_base=ls[i][2]
    ls.pop(i)
    flag2=0
    break
if flag2==0:
  for x in range(101):
    for y in range(101):
      ##x,yの高さを計算
      h=h_base+abs(x-a)+abs(y-b)
      ##他の条件と合うか？
      flag=1
      for e in ls:
        if h!=e[2]+abs(x-e[0])+abs(y-e[1]):
          flag=0
          break
      if flag==1:
        ans=[x,y,h]
        break
    if flag==1:
      break
else:
  xsum=0
  ysum=0
  for e in ls:
    xsum+=e[0]
    ysum+=e[1]
  ans=[5050-xsum,5050-ysum,1]
print(*ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
ls=[[int(s) for s in input().split()] for i in range(N)]
flag2=0
for i in range(N):
  if ls[i][2]!=0:
    a=ls[i][0]
    b=ls[i][1]
    h_base=ls[i][2]
    ls.pop(i)
    break
else:
  flag2=1
if flag2==0:
  for x in range(101):
    for y in range(101):
      ##x,yの高さを計算
      h=h_base+abs(x-a)+abs(y-b)
      ##他の条件と合うか？
      flag=1
      for e in ls:
        if h!=e[2]+abs(x-e[0])+abs(y-e[1]):
          flag=0
          break
      if flag==1:
        ans=[x,y,h]
        break
    if flag==1:
      break
else:
  xsum=0
  ysum=0
  for e in ls:
    xsum+=e[0]
    ysum+=e[1]
  ans=[5050-xsum,5050-ysum,1]
print(*ans)
Problem p03274 (python)

Fixed submission:
N,K=[int(s) for s in input().split()]
ls=[int(s) for s in input().split()]
def length(i):
  if ls[i]>=0:
    return ls[K+i-1]
  elif ls[K+i-1]<=0:
    return -ls[i]
  else:
    return min([2*ls[K+i-1]-ls[i],ls[K+i-1]-2*ls[i]])
answer=[]
for i in range(N-K+1):
  answer.append(length(i))
  
print(min(answer))

Buggy submission (verdict: Runtime Error):
N,K=[int(s) for s in input().split()]
ls_p=[int(s) for s in input().split()]
ls_n=[]
X=0
for i in range(N):
  if ls_p[0]>=0 : break 
  else:
    X+=1
    ls_n.append(ls_p[0])
    ls_p.pop(0)
#ls_nにX個流れている
cand=[]
for i in range(min([X-1,K-2])):
  cand.append(-ls_n[-i-1]*2+ls_p[K-i-2])
  cand.append(-ls_n[-i-1]+ls_p[K-i-2]*2)
if N-X-1>=K-1:
  cand.append(ls_p[K-1])
if X>=K:
  cand.append(-ls_n[-K])
print(min(cand))

Buggy submission (verdict: Runtime Error):
N,K=[int(s) for s in input().split()]
ls_p=[int(s) for s in input().split()]
ls_n=[]
X=0
for i in range(N):
  if ls_p[0]>=0 : break 
  else:
    X+=1
    ls_n.append(ls_p[0])
    ls_p.pop(0)
print(ls_n)
print(ls_p)
#ls_nにX個流れている
cand=[]
for i in range(min([X-1,K-2])):
  cand.append(-ls_n[-i-1]*2+ls_p[K-i-2])
  cand.append(-ls_n[-i-1]+ls_p[K-i-2]*2)
if N-X-1>=K-1:
  cand.append(ls_p[K-1])
if X>=K:
  cand.append(-ls_n[-K])
print(min(cand))
Problem p03289 (python)

Fixed submission:
S=list(input())
x=S.pop(0)
if x!='A':
  print('WA')
else:
  for i in range(1,len(S)-1):
    if S[i]=='C':
      del S[i]
      if str.islower("".join(S)):
        print('AC')
        break
      else:
        print('WA')
        break
  else:
    print('WA')

Buggy submission (verdict: Runtime Error):
S=list(input())
x=S.pop(0)
if x!='A':
  print('WA')
else:
  for i in range(1,len(S)-1):
    if S[i]=='C':
      del S[i]
      if str.islower("".join(S)):
        print('AC')
        break
      else:
        print('WA')
  else:
    print('WA')
Problem p03361 (python)

Fixed submission:
H,W=[int(s) for s in input().split()]
cam_ls=[ "." for _ in range(H+2)]
for j in range(W+1):
  cam_ls[0]=cam_ls[0]+"."
  cam_ls[H+1]=cam_ls[H+1]+"."
for i in range(1,H+1):
  cam_ls[i]=cam_ls[i]+input()+"."
  
def pos(h,w):
  if cam_ls[h][w]==".":
    return 1
  elif (cam_ls[h+1][w]=="." and
        cam_ls[h-1][w]=="." and
        cam_ls[h][w+1]=="." and
        cam_ls[h][w-1]=="."):
    return 0
  else:
    return 1

ans=1
for i in range(1,H+1):
  for j in range(1,W+1):
    ans*=pos(i,j)
if ans==1:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
H,W=[int(s) for s in input().split()]
cam_ls=[ "." for _ in range(H+2)]
for j in range(H+1):
  cam_ls[0]=cam_ls[0]+"."
  cam_ls[H+1]=cam_ls[H+1]+"."
for i in range(1,H+1):
  cam_ls[i]=cam_ls[i]+input()+"."
  
def pos(h,w):
  if cam_ls[h][w]==".":
    return 1
  elif (cam_ls[h+1][w]=="." and
        cam_ls[h-1][w]=="." and
        cam_ls[h][w+1]=="." and
        cam_ls[h][w-1]=="."):
    return 0
  else:
    return 1

ans=1
for i in range(1,H+1):
  for j in range(1,W+1):
    ans*=pos(i,j)
if ans==1:
  print("Yes")
else:
  print("No")