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

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

if n%k==0:
  print(0)
else:
  print(1)

Buggy submission (verdict: Runtime Error):
#import sys
#input = sys.stdin.readline
#template input
import bisect

def IT():
    return int(input())
def IL():
    return [int(_) for _ in input().split()]
def SL():
    return [int(_) for _ in input().split()]
def ILS(n):
    return [int(input()) for _ in range(n)]
def SLS(n):
    return [input() for _ in range(n)]
def ILSS(n):
    return [[int(_) for _ in input().split()] for j in range(n)]

#template technique
def bit_full_search(ss):
    n = len(ss)
    for i in range(1 << n):
        s = ""
        for j in range(n + 1):
            if ((1 & i >> j) == 1):
                s += ss[j]
        print(s)

def bit_full_search2(A):
    #https://blog.rossywhite.com/2018/08/06/bit-search/
    value = []
    for i in range(1 << len(A)):
        output = []

        for j in range(len(A)):
            if ((i >> j) & 1) == 1:
                #output.append(A[j])
                output.append(A[j])
        #print(output)
        value.append([format(i, 'b'), sum(output)])
#    print(value)
    return value


"""ここからメインコード"""
def main():
    n = IT()
    #それぞれ半分全列挙
    list1 = [(-2) **  i for i in range(17)]
    list2 = [(-2) ** (i + 17) for i in range(17)]

    list1 = bit_full_search2(list1)
    list1.sort(key=lambda x:x[1])
    list1_bin = [list1[i][0] for i in range(len(list1))]
    list1_val = [list1[i][1] for i in range(len(list1))]

    list2 = bit_full_search2(list2)
    list2.sort(key=lambda x:x[1])
    list2_bin = [list2[i][0] for i in range(len(list2))]
    list2_val = [list2[i][1] for i in range(len(list2))]

    for i in range(len(list1_val)):
        j = bisect.bisect_left(list2_val, n - list1_val[i])
        if j < len(list2_val):
            if list1_val[i] + list2_val[j] == n:
                ans = list2_bin[j] +list1_bin[i]
                break

    print(int(ans))

main()
Problem p03380 (python)

Fixed submission:
n=int(input())
a=[int(i) for i in input().split()]
a.sort()
enu=max(a)

k=(enu)/2
sa=10000000000000000000000000000

for i in range(n-1):
    if abs(k-a[i])<sa:
        sa=k-a[i]
        aru=a[i]

print(enu,aru)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=[int(i) for i in input().split()]
a.sort()
#print(a[:n-1])
enu=max(a)

k=(enu)/2
sa=100000

for i in range(n-1):
    if abs(k-a[i])<sa:
        sa=k-a[i]
        aru=a[i]

print(enu,aru)
Problem p03389 (python)

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

a.sort()

if a[0]%2==0 and  a[1]%2==0 and  a[2]%2==0:
    print(int((3*max(a)-sum(a))/2))  
elif a[0]%2==1 and  a[1]%2==1 and  a[2]%2==1:
    print(int((3*max(a)-sum(a))/2))  

else:
    count=0
    for i in range(3):
        if a[i]%2==0:
            count+=1

    if count==2:
        for i in range(3):
            if a[i]%2==0:
                a[i]=a[i]+1
        print(int((3*max(a)-sum(a))/2)+1)  
        
    if count==1:
        for i in range(3):
            if a[i]%2==1:
                a[i]=a[i]+1
        print(int((3*max(a)-sum(a))/2)+1)

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

def keisan(d,e,f):
    count=0
    old_value=10**20
    for j in range(int(d)):
        value=min(old_value,int((d-1)/(j+1)))

#        print(value)

        if old_value==value:
            value-=1

        if value>0:
            if e!=j+1 and f!=value:
                count+=1
                old_value=value
            elif e==j+1:
               pass
            elif f==value:
               pass
        else:
            break
    print(count)

for i in range(n):        
    keisan(c[i],a[i],b[i])
Problem p03407 (python)

Fixed submission:
a,b,c=[int(i) for i in input().split()]

if a+b>=c:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
#https://abc010.contest.atcoder.jp/tasks/abc010_4
#http://kmjp.hatenablog.jp/entry/2014/06/08/0900

#よくわからない最大フロー用のdfs---------------------------------

num=201 #今回のnの最大値100*2+1

def dfs(cur):
	global vis
	global EE
	vis[cur] = 1

	if cur==num:
		return 1

	for i in range(num+1):
		if vis[i]==0 and EE[cur][i]>0 and dfs(i) > 0:
			EE[cur][i] -= 1
			EE[i][cur] += 1
			return 1
	return 0
#--------------------------------------------------------------

#今回の問題分（インプット～隣接リストの作成）------------------

n=int(input())
s=[]
ss=[]
for i in range(n):
    s.append([int(i) for i in input().split()])
for i in range(n):
    ss.append([int(i) for i in input().split()])
#s.sort(key=lambda x:(x[0],x[1]))
#ss.sort(key=lambda x:(x[0],x[1]))

pair=[]
for i in range(len(s)):
    right=[]
    for j in range(n):    
        if s[j][0]<ss[i][0] and s[j][1]<ss[i][1]:
            right.append(j)
    pair.append(right)
#pair.sort(key=lambda x:len(x))

#print(pair)

#------------------------------------------------------------

#BFSにぶち込む用のグラフ作成---------------------------------

EE = [[0 for x in range(num+1)] for y in range(num+11)]
vis = [0] * (num+1)

for i in range(len(pair)): #1から最大100　始点s（番号0）から青い点への辺
	EE[0][i+1] = 1
#	EE[i+1][0] = 1

for i in range(n): #101から最大200　赤い点から終点t（番号201）への辺
	EE[i+101][num] = 1

for i in range(len(pair)): #青い点（番号1～100に振り直し）から　赤い点（番号101～200）への辺
    for j in range(len(pair[i])):
        node1, node2 = i+1,pair[i][j]+101
#        EE[node1][node2] = EE[node2][node1] = 1　なんでこれダメなんだろう
        EE[node1][node2] = 1

#風呂～～--------------------------------------------------

flow=0
while 1:
    for i in range(0, num+1):
        vis[i] = 0
    if dfs(0) == 0:
        break
    flow += 1

print (flow)

#----------------------------------------------------------
Problem p03485 (python)

Fixed submission:
import math

a,b=[int(i) for i in input().split()]
print(math.ceil((a+b)/2))

Buggy submission (verdict: Runtime Error):
s=input()
x,y=[int(i) for i in input().split()]

if x==0:
    print("No")
Problem p03496 (python)

Fixed submission:
n=int(input())
a=[int(i) for i in input().split()]
count=0
ans=[[0 for i in range(2)] for j in range(2*n)]
aaa=0

a_max=max(a)
a_min=min(a)
if abs(a_max)>=abs(a_min):
    delta=a_max
else:
    delta=a_min
if delta>0:
    seifu=1
else:
    seifu=-1

for i in range(n):
    if delta==a[i]:
        aaa=i+1
        break




if seifu==1:

  for i in range(n-1):
    while a[i]>a[i+1]:
        if seifu==1:
            a[i+1]=a[i+1]+delta
            ans[count][0], ans[count][1]=aaa, i+2
        count=count+1
        a_max=max(a)
        delta=a_max
        for k in range(n):
            if delta==a[k]:
                aaa=k+1

else:
  for i in range(n-1):
    while a[n-2-i]>a[n-1-i]:
        if seifu==-1:
            a[n-2-i]=a[n-2-i]+delta
            ans[count][0], ans[count][1]=aaa, n-2-i+1
        count=count+1

        a_min=min(a)
        delta=a_min
        for k in range(n):
            if delta==a[k]:
                aaa=k+1


print(count)
for i in range(count):
    print(ans[i][0],ans[i][1])

Buggy submission (verdict: Runtime Error):
n=int(input())
a=[int(i) for i in input().split()]
count=0
ans=[[0 for i in range(2)] for j in range(2*n)]
aaa=0

a_max=max(a)
a_min=min(a)

if abs(a_max)>=abs(a_min):
    delta=a_max
else:
    delta=a_min

if delta>0:
    seifu=1
else:
    seifu=-1

for i in range(n):
    if delta==a[i]:
        aaa=i+1
        break


#print(aaa)
#print(a,a_max,a_min)



for i in range(n-1):
    while a[i]>a[i+1]:
        if seifu==1:
            a[i+1]=a[i+1]+delta
            ans[count][0], ans[count][1]=aaa, i+2
        else:
            a[i]=a[i]+delta
            ans[count][0], ans[count][1]=aaa, i+1
        count=count+1
        
print(count)
for i in range(count):
    print(ans[i][0],ans[i][1])
Problem p03555 (python)

Fixed submission:
a=input()
b=input()
aa=a[::-1]

if aa==b:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
a=input()
b=input()
aa=a[::-1]

if aa[1]==b[0] and aa[2]==b[1] and aa[3]==b[2]:
    print("YES")
else:
    print("NO")
Problem p03563 (python)

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

print(a+2*(b-a))

Buggy submission (verdict: Runtime Error):
#区間ごとの面積を計算する
def calc_area(v_end, v_start, v_max, dt):
    kouten_v = (v_end + v_start + dt) / 2
    kouten_t = kouten_v - v_start
    if 0 < kouten_t < dt:
        area = (v_start + kouten_v) * kouten_t / 2 #左側
        area +=  (v_end + kouten_v) * (dt - kouten_t) / 2 #右側
        area -=  max(0, (kouten_v - v_max))** 2 #上の三角形
    else:
        area = (v_start + v_end) *  dt / 2
    return area

def main():
    #与えられた入力を受け取る
    n=int(input())
    t=[int(i) for i in input().split()]
    v=[int(i) for i in input().split()]

    #各区間の許容最大速度を計算する
    #（この段階では傾きが-1未満になる可能性がある）
    max_velocity = [0]
    for i in range(1, n):
        max_velocity_ = min(v[i-1], v[i], max_velocity[i-1] + t[i-1])
        max_velocity.append(max_velocity_)
    max_velocity.append(0)

    #後ろから走査して、傾きが-1以上を満たすように許容速度をfittingする
    for i in range(n-1):
        if  max_velocity[-(i+1)] - max_velocity[-(i+2)] < -t[-(i+1)]:
            max_velocity[-(i+2)] = max_velocity[-(i+1)] + t[-(i+1)]

    #各区間の面積を計算して足し合わせる
    ans = 0
    for i in range(n):
        ans += calc_area(max_velocity[i+1], max_velocity[i], v[i], t[i])
    print(ans)

main()
Problem p03597 (python)

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

print(N**2-a)

Buggy submission (verdict: Runtime Error):
a,b,c,d,e,f= map(int, input().split())
youeki=0
yousitu=0
noudo=0
n_a=int(f/(100*a))


for i in range(2+n_a):
 for j in range(2+int((f-100*i*a)/(100*b))):
  for k in range(2+int((f-100*i*a-100*j*b)/c)):
   for l in range(2+int((f-100*i*a-100*j*b-k*c)/d)):
    S=100.0*a*i+100.0*b*j+c*k+d*l
    T=c*k+d*l
    if S!=0:
     L=100.0*T/S
     if S<=f and L<=100*e/(100+e) and L>noudo:
      noudo=L
      youeki=S
      yousitu=T
print(int(youeki),int(yousitu))

Buggy submission (verdict: Runtime Error):
N=int(input())
a=int(input())

print(N**2-A)
Problem p03599 (python)

Fixed submission:
a,b,c,d,e,f= map(int, input().split())
youeki=0
yousitu=0
noudo=0
n_a=int(f/(100*a))


for i in range(2+n_a):
 for j in range(2+int((f-100*i*a)/(100*b))):
  for k in range(2+int((f-100*i*a-100*j*b)/c)):
   for l in range(2+int((f-100*i*a-100*j*b-k*c)/d)):
    S=100.0*a*i+100.0*b*j+c*k+d*l
    T=c*k+d*l
    if S!=0:
     L=100.0*T/S
     if S<=f and L<=100*e/(100+e) and L>=noudo:
      noudo=L
      youeki=S
      yousitu=T
print(int(youeki),int(yousitu))

Buggy submission (verdict: Runtime Error):
a,b,c,d,e,f= map(int, input().split())
2.youeki=0
3.yousitu=0
4.noudo=0
5.n_a=int(f/(100*a))
6. 
7. 
8.for i in range(1+n_a):
9. for j in range(1+int((f-100*i*a)/(100*b))):
10.  for k in range(1+int((f-100*i*a-100*j*b)/c)):
11.   for l in range(1+int((f-100*i*a-100*j*b-k*c)/d)):
12.    S=100.0*a*i+100.0*b*j+c*k+d*l
13.    T=c*k+d*l
14.    if S!=0:
15.     L=100.0*T/S
16.     if S<=f and L<=100*e/(100+e) and L>=noudo:
17.      noudo=L
18.      youeki=S
19.      yousitu=T
20.print(int(youeki),int(yousitu))
Problem p03645 (python)

Fixed submission:
n,m=[int(i) for i in input().split()]
p=[[0 for i in range(2)] for j in range(m)]

a=[0 for i in range(n+1)]
b=[0 for i in range(n+1)]

for i in range(m):
  p[i]=[int(i) for i in input().split()]

for i in range(m):  
  
  if p[i][0]==1:
    a[p[i][1]]+=1
    
  elif p[i][1]==n:
    a[p[i][0]]+=1
   
    
if max(a)>=2:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Buggy submission (verdict: Runtime Error):
n,m=[int(i) for i in input().split()]
p=[[0 for i in range(2)] for j in range(n)]
a=[0 for i in range(n+1)]

for i in range(m):
  p[i]=[int(i) for i in input().split()]

for i in range(m):  
  
  if p[i][0]==1:
    a[p[i][1]]+=1
    
  elif p[i][1]==n:
    a[p[i][0]]+=1
   
    
if max(a)>=2:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Buggy submission (verdict: Runtime Error):
n,m=[int(i) for i in input().split()]
p=[[0 for i in range(2)] for j in range(n)]

for i in range(m):
  p[i]=[int(i) for i in input().split()]
  
  
#隣接リスト  
l = [[] for i in range(n+1)]
for pi in p:  #0-originedに注意、l[0]は空
        l[pi[0]].append(pi[1])
        l[pi[1]].append(pi[0])  

count=0
for i in l[1]:
  if i in l[n]:
    count=1
    
if count==1:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Buggy submission (verdict: Runtime Error):
n,m=[int(i) for i in input().split()]
p=[[0 for i in range(2)] for j in range(n)]

for i in range(m):
  p[i]=[int(i) for i in input().split()]
  
  
#隣接リスト  
l = [[] for i in range(n+1)]
for pi in p:  #0-originedに注意、l[0]は空
        l[pi[0]].append(pi[1])
        l[pi[1]].append(pi[0])  

count=0
for i in l[1]:
  if i in l[n]:
    count=1
    
if count==1:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
Problem p03657 (python)

Fixed submission:
m,d = [ int(i) for i in input().split()]

if m%3==0 or d%3==0 or (m+d)%3==0 :
    print("Possible")
else:
    print("Impossible")

Buggy submission (verdict: Runtime Error):
N=int(input())
a=[int(i) for i in input().split()]
X=0
Y=0
min=10**11
for i in range(N):
  X=X+a[i]

for j in range(N-1):
  Y=Y+a[j]
  if abs(X-2*Y) <= min:
   min=abs(X-2*Y)
print(min)
Problem p03722 (python)

Fixed submission:
#import sys
#import numpy as np
from scipy.sparse import csr_matrix, coo_matrix
from scipy.sparse.csgraph import dijkstra, bellman_ford

#sys.setrecursionlimit(10000)

N, M = [int(i) for i in input().split()]

rows = []
cols = []
weights = []

for _ in range(M):
    # u v 間のコスト
    u, v, a = [int(i) for i in input().split()]
    rows.append(u-1)
    cols.append(v-1)
    weights.append(-a)

#graph = coo_matrix((weights, (rows, cols)), shape=(N, N)).tocsr()
graph = coo_matrix((weights, (cols, rows)), shape=(N, N)).tocsr() #N→1
try:
    d1 = bellman_ford(graph, indices = [N-1], directed=True, unweighted=False)
    print(-int(d1[0][0]))
except:
    print("inf")

Buggy submission (verdict: Runtime Error):
#import sys
#import numpy as np
from scipy.sparse import csr_matrix, coo_matrix
from scipy.sparse.csgraph import dijkstra, bellman_ford

#sys.setrecursionlimit(10000)

N, M = [int(i) for i in input().split()]

rows = []
cols = []
weights = []

for _ in range(M):
    # u v 間のコスト
    u, v, a = [int(i) for i in input().split()]
    rows.append(u-1)
    cols.append(v-1)
    weights.append(-a)

#graph = coo_matrix((weights, (rows, cols)), shape=(N, N)).tocsr()
graph = coo_matrix((weights, (cols, rows)), shape=(N, N)).tocsr() #N→1

d1 = bellman_ford(graph, indices = [N-1], directed=True, unweighted=False)
#print(d1)
print(-int(d1[0][0]))
Problem p04026 (python)

Fixed submission:
S=input()
a=0
for i in range(len(S)-2):
  if S[i]==S[i+1] or S[i]==S[i+2] or S[i+1]==S[i+2]:
    a=1
    print(i+1,i+3)
    break

if a==0:
 if len(S)>1 and S[-1]==S[-2]:
  print(len(S)-1,len(S))
 else:
  print(-1,-1)

Buggy submission (verdict: Runtime Error):
S=input()
a=0
for i in range(len(S)-1):
  if S[i]==S[i+1] or S[i]==S[i+2] :
    a=1
    print(i+1,i+3)
    break
if a==0:
    print(-1,-1)
Problem p02579 (python)

Fixed submission:
from collections import deque
def main():
  h,w = map(int,input().split())
  ch,cw = map(lambda x:int(x)+1,input().split())
  dh,dw = map(lambda x:int(x)+1,input().split())
  s = [["#"]*(w+4) for _ in range(2)]+[["#"]*2+list(input())+["#"]*2 for _ in range(h)]+[["#"]*(w+4) for _ in range(2)]
  m1 = ((-1,0),(0,-1),(0,1),(1,0))
  m2 = [(i,j) for i in range(-2,3) for j in range(-2,3) if abs(i)+abs(j)>1]
  a = deque([(ch,cw)])
  b = deque()
  i = 0
  while a:
    while a:
      ah,aw = a.popleft()
      if s[ah][aw]!=".":
        continue
      b.append((ah,aw))
      s[ah][aw] = i
      for bh,bw in m1:
        bh,bw = ah+bh,aw+bw
        if s[bh][bw]==".":
          a.append((bh,bw))
    while b:
      ah,aw = b.popleft()
      for bh,bw in m2:
        bh,bw = ah+bh,aw+bw
        if s[bh][bw]==".":
          a.append((bh,bw))
    i += 1
  ans = s[dh][dw]
  print(ans if ans != "." else -1)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
from collections import deque
def main():
  h,w = map(int,input().split())
  ch,cw = map(lambda x:int(x)+1,input().split())
  dh,dw = map(lambda x:int(x)+1,input().split())
  s = [["#"]*(w+4) for _ in range(2)]+[["#"]*2+list(input())+["#"]*2 for _ in range(h)]+[["#"]*(w+4) for _ in range(2)]
  m1 = ((-1,0),(0,-1),(0,1),(1,0))
  m2 = [(i,j) for i in range(-2,3) for j in range(-2,3) if abs(i)+abs(j)>1]
  a = deque([(ch,cw)])
  b = deque()
  i = 0
  while a:
    while a:
      ah,aw = a.popleft()
      if s[bh][bw]!=".":
        continue
      b.append((ah,aw))
      s[ah][aw] = i
      for bh,bw in m1:
        bh,bw = ah+bh,aw+bw
        if s[bh][bw]==".":
          a.append((bh,bw))
    while b:
      ah,aw = b.popleft()
      for bh,bw in m2:
        bh,bw = ah+bh,aw+bw
        if s[bh][bw]==".":
          a.append((bh,bw))
    i += 1
  ans = s[dh][dw]
  print(ans if ans != "." else -1)

if __name__ == "__main__":
    main()
Problem p02845 (python)

Fixed submission:
n,*a = map(int,open(0).read().split())
cnt = [3]+[0]*n
ans = 1
mod = 10**9+7
for i in a:
  ans = ans * cnt[i] % mod
  cnt[i] -= 1
  cnt[i+1] += 1
print(ans)

Buggy submission (verdict: Runtime Error):
n,*a = map(int,open(0).read().split())
cnt = [3]+[0]*(n-2)
ans = 1
mod = 10**9+7
for i in a:
  ans = ans * cnt[i] % mod
  cnt[i] -= 1
  cnt[i+1] += 1
print(ans)

Buggy submission (verdict: Runtime Error):
n,*a = map(int,open(0).read().split())
b = [0,0,0]
ans = 1
mod = 10**9+7
for i in a:
  ans = (ans * b.count(i)) % mod
  b.remove(i)
  b.append(i + 1)
print(ans)
Problem p02936 (python)

Fixed submission:
import sys
from collections import deque
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
n,q = map(int,input().split())
tree = [[] for i in range(n)]
ans = [0]*n
for i in range(n-1):
    a,b = map(lambda x:int(x)-1,input().split())
    tree[a].append(b)
    tree[b].append(a)

for i in range(q):
    p,x = map(int, input().split())
    ans[p - 1] += x

d = deque([[0,0]])
c = [False]*n
c[0] = True
while d:
    x,s = d.pop()
    s += ans[x]
    ans[x] = s
    for e in tree[x]:
        if not c[e]:
            c[e] = True
            d.append([e,s])

print(*ans)

Buggy submission (verdict: Runtime Error):
import sys
n,q = map(int,sys.stdin.readline().rstrip().split())
t = {}
for i in range(n-1):
    a,b = map(int,sys.stdin.readline().rstrip().split())
    if a in t:
        t[a].append(b)
    else:
        t[a] = [b]
ans = [0 for i in range(n)]

def search(j):
    if j in t:
        l = [j]
        for k in t[j]:
            l = l + search(k)
    else:
        l = [j]
    return l

for i in range(q):
    p,x = map(int,sys.stdin.readline().rstrip().split())
    s = search(p)
    for i in s:
        ans[i-1] += x
print(" ".join(map(str,ans)))
Problem p03006 (python)

Fixed submission:
n= int(input())
if n == 1:
  print(1)
  exit()
ab = [list(map(int,input().split())) for _ in range(n)]
pq = {}
for i in range(n-1):
  for j in range(i+1,n):
    a1,b1 = ab[i]
    a2,b2 = ab[j]
    p = a1-a2
    q = b1-b2
    if p<0 or p==0 and q<0:
      p = -p
      q = -q
    if (p,q) in pq:
      pq[(p,q)] += 1
    else:
      pq[(p,q)] = 1
print(n-max(pq.values()))

Buggy submission (verdict: Runtime Error):
n= int(input())
ab = [list(map(int,input().split())) for _ in range(n)]
pq = {}
for i in range(n-1):
  for j in range(i+1,n):
    a1,b1 = ab[i]
    a2,b2 = ab[j]
    p = a1-a2
    q = b1-b2
    if p<0:
      p = -p
      q = -q
    if (p,q) in pq:
      pq[(p,q)] += 1
    else:
      pq[(p,q)] = 1
print(n-max(pq.values()))

Buggy submission (verdict: Runtime Error):
from collections import Counter
n= int(input())
ab = [list(map(int,input().split())) for _ in range(n)]
pq = []
for i in range(n-1):
  for j in range(i+1,n):
    a1,b1 = ab[i]
    a2,b2 = ab[j]
    p = a1-a2
    q = b1-b2
    if p<0:
      p = -p
      q = -q
    pq.append((p,q))
c = Counter(pq)
print(n-c.most_common()[0][1])
Problem p03231 (python)

Fixed submission:
from fractions import gcd
n,m=map(int,input().split())
s = input()
t = input()
g = gcd(n,m)
ng = n//g
mg = m//g
for i in range(g):
    if s[ng*i]!=t[mg*i]:
        print("-1")
        break
else:
    print(n*m//g)

Buggy submission (verdict: Runtime Error):
from fractions import gcd
n,m=map(int,input().split())
s = input()
t = input()
g = gcd(n,m)
ng = n//g
mg = m//g
for i in range(g):
    if s[ng*i]!=t[mg*i]):
        print("-1")
        break
else:
    print(n*m//g)
Problem p03311 (python)

Fixed submission:
n,*a = map(int,open(0).read().split())
a = sorted([a[i] -i for i in range(n)])
print(sum([abs(i - a[n//2]) for i in a]))

Buggy submission (verdict: Runtime Error):
n,*a = map(int,open(0).read().split())
a = [a[i] -i -1 for i in range(n)]
a.sort()
if n % 2 == 0:
  b = a[n//2]
  c = b + 1
else:
  b = (a[n//2]+a[n//2+1])//2
  c = b + 2
ans = min([sum([abs(i - j) for i in a]) for j in range(b,c)])
print(ans)

Buggy submission (verdict: Runtime Error):
n,*a = map(int,open(0).read().split())
a = [a[i] -i -1 for i in range(n)]
a.sort()
b = a[n//2]
if n % 2 == 0:
  c = b + 1
else:
  c = a[n//2+1]+1
ans = min([sum([abs(i - j) for i in a]) for j in range(b,c)])
print(ans)

Buggy submission (verdict: Runtime Error):
n,*a = map(int,open(0).read().split())
a = [a[i] -i -1 for i in range(n)]
a.sort()
print(a)
b = a[n//2]
if n % 2 == 0:
  c = b + 1
else:
  c = a[n//2+1]+1
ans = min([sum([abs(i - j) for i in a]) for j in range(b,c)])
print(ans)

Buggy submission (verdict: Runtime Error):
n,*a = map(int,open(0).read().split())
a = [a[i] -i -1 for i in range(n)]
a.sort()
print(a)
b = a[n//2]
if n % 2 == 0:
  c = b + 1
else:
  c = a[n//2+1]+1
ans = min([sum([abs(i - j) for i in a]) for j in range(b,c)])
print(ans)
Problem p03436 (python)

Fixed submission:
from collections import deque
def main():
  h,w = map(int,input().split())
  s = [input() for _ in range(h)]
  #print(sum([i.count(".") for i in s]))
  
  def bfs(st):
    que = deque([st])
    c = [[0]*w for _ in range(h)]
    while que:
      ph,pw = que.popleft()
      step = c[ph][pw] + 1
      for dh,dw in ((1,0),(0,1),(-1,0),(0,-1)):
        nh = ph+dh
        nw = pw+dw
        if nh<0 or nw<0 or nh>=h or nw>=w:
          continue
        if s[nh][nw]=="#" or c[nh][nw] != 0:
          continue
        c[nh][nw] = step
        if (nh,nw) == (h-1,w-1):
          return step
        que.append((nh,nw))
  
  result = bfs((0,0))
  if result:
    return sum([i.count(".") for i in s])-result-1
  else:
    return -1

print(main())

Buggy submission (verdict: Runtime Error):
def main():
  h,w = map(int,input().split())
  s = [input() for _ in range(h)]
  c = [[10**5]*w for _ in range(h)]
  #print(sum([i.count(".") for i in s]))
  
  def func(dh,dw,step):
    if dh<0 or dw<0 or dh>=h or dw>=w:
      return
    step += 1
    if s[dh][dw] == ".":
      if c[dh][dw] > step:
        c[dh][dw] = step
        for i,j in ((1,0),(0,1),(-1,0),(0,-1)):
          func(dh+i,dw+j,step)
  
  func(0,0,0)
  if c[h-1][w-1] == 10**5:
    return -1
  else:
    return sum([i.count(".") for i in s])-c[h-1][w-1]

print(main())
Problem p03944 (python)

Fixed submission:
w,h,n = map(int,input().split())
d = [0,w,0,h]
for i in range(n):
    x,y,a = map(int,input().split())
    if a == 1 :
        d[0] = max(d[0],x)
    elif a == 2:
        d[1] = min(d[1],x)
    elif a == 3:
        d[2] = max(d[2],y)
    else:
        d[3] = min(d[3],y)
print(max(0,(d[1]-d[0]))*max(0,(d[3]-d[2])))

Buggy submission (verdict: Runtime Error):
import numpy as np
w,h,n = map(int,input().split())
d = np.zeros(w-1,h-1)
for i in range(n):
    x,y,a = map(int,input().split())
    if a == 1:
        d[:w] = 1
    elif a == 2:
        d[w:] = 1
    elif a ==3:
        d[:,:h] = 1
    else:
        d[:,h:] = 1
print(np.count_nonzero(d==0))