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

Fixed submission:
H,W,M = map(int,input().split())
h = []
w = []

for i in range(M):
    tmp1,tmp2 = map(int,input().split())
    h.append(tmp1)
    w.append(tmp2)

dic1 = {}
dic2 = {}

for i in h:
    if i not in dic1:
        dic1[i] = 1
    else:
        dic1[i] +=1

val1 = max(dic1,key=dic1.get)
ans = 0
ans +=dic1[val1]
for j in range(M):
    if h[j] != val1:
        if w[j] not in dic2:
            dic2[w[j]] = 1
        else:
            dic2[w[j]] +=1
if dic2:
    val2 = max(dic2,key=dic2.get)
    ans +=dic2[val2]


dic1 = {}
dic2 = {}

for i in w:
    if i not in dic1:
        dic1[i] = 1
    else:
        dic1[i] +=1
val1 = max(dic1,key=dic1.get)
ans1 = 0
ans1 +=dic1[val1]
for j in range(M):
    if w[j] != val1:
        if h[j] not in dic2:
            dic2[h[j]] = 1
        else:
            dic2[h[j]] +=1
if dic2:
    val2 = max(dic2,key=dic2.get)
    ans1 +=dic2[val2]
print(max(ans,ans1))

Buggy submission (verdict: Runtime Error):
H,W,M = map(int,input().split())
h = []
w = []

for i in range(M):
    tmp1,tmp2 = map(int,input().split())
    h.append(tmp1)
    w.append(tmp2)

dic1 = {}
dic2 = {}

for i in h:
    if i not in dic1:
        dic1[i] = 1
    else:
        dic1[i] +=1

val1 = max(dic1,key=dic1.get)
ans = 0
ans +=dic1[val1]
for j in range(M):
    if h[j] != val1:
        if w[j] not in dic2:
            dic2[w[j]] = 1
        else:
            dic2[w[j]] +=1

val2 = max(dic2,key=dic2.get)
ans +=dic2[val2]
print(ans)
Problem p02793 (python)

Fixed submission:
import fractions
n = int(input())
a = list(map(int,input().split()))

def lcm(x,y):
    return (x * y) // fractions.gcd(x, y)

val = a[0]
for i in range(1,n):
    val = lcm(val,a[i])

ans = 0
for i in range(n):
    ans += val // a[i]
print(ans % (10**9+7))

Buggy submission (verdict: Runtime Error):
import math
n = int(input())
a = list(map(int,input().split()))

def lcm(x,y):
    return (x * y) // math.gcd(x, y)

val = a[0]
for i in range(1,n):
    val = lcm(val,a[i])

ans = 0
for i in range(n):
    ans += val // a[i]
print(ans % (10**9+7))
Problem p03053 (python)

Fixed submission:
h,w = map(int,input().split())

arr = ["0" *(w + 2)]
for i in range(h):
    arr.append("0" + input() + "0")
arr.append("0" *(w + 2))

flg = [[-1 for i in range(w+2)] for j in range(h+2)]

ima = []
for i in range(h+2):
    for j in range(w+2):
        if arr[i][j] == "#":
            ima.append([i,j])
            flg[i][j] = 0

while len(ima) > 0:
    tugi = []
    for x,y in ima:
        if arr[x+1][y] == "." and flg[x+1][y] == -1:
            tugi.append([x+1,y])         
            flg[x+1][y] = flg[x][y] + 1
        if arr[x-1][y] == "." and flg[x-1][y] == -1:
            tugi.append([x-1,y])
            flg[x-1][y] = flg[x][y] + 1
        if arr[x][y+1] == "." and flg[x][y+1] == -1:
            tugi.append([x,y+1])
            flg[x][y+1] = flg[x][y] + 1
        if arr[x][y-1] == "." and flg[x][y-1] == -1:
            tugi.append([x,y-1])
            flg[x][y-1] = flg[x][y] + 1
    ima = tugi

ans = -1
for i in flg:
    for j in i:
        if ans < j:
            ans = j
print(ans)

Buggy submission (verdict: Runtime Error):
h,w = map(int,input().split())

arr = ["0" *(w + 2)]
for i in range(h):
    arr.append("0" + input() + "0")
arr.append("0" *(w + 2))

flg = [[-1 for i in range(h+2)] for j in range(w+2)]

ima = []
for i in range(h+2):
    for j in range(w+2):
        if arr[i][j] == "#":
            ima.append([i,j])
            flg[i][j] = 0

while len(ima) > 0:
    tugi = []
    for x,y in ima:
        if arr[x+1][y] == "." and flg[x+1][y] == -1:
            tugi.append([x+1,y])         
            flg[x+1][y] = flg[x][y] + 1
        if arr[x-1][y] == "." and flg[x-1][y] == -1:
            tugi.append([x-1,y])
            flg[x-1][y] = flg[x][y] + 1
        if arr[x][y+1] == "." and flg[x][y+1] == -1:
            tugi.append([x,y+1])
            flg[x][y+1] = flg[x][y] + 1
        if arr[x][y-1] == "." and flg[x][y-1] == -1:
            tugi.append([x,y-1])
            flg[x][y-1] = flg[x][y] + 1
    ima = tugi

ans = -1
for i in flg:
    for j in i:
        if ans < j:
            ans = j
print(ans)

Buggy submission (verdict: Runtime Error):
h,w = map(int,input().split())

arr = ["0" *(w + 2)]
for i in range(h):
    arr.append("0" + input() + "0")
arr.append("0" *(w + 2))

flg = [[-1 for i in range(h+2)] for j in range(w+2)]

ima = []
for i in range(h+2):
    for j in range(w+2):
        if arr[i][j] == "#":
            ima.append([i,j])
            flg[i][j] = 0

while len(ima) > 0:
    tugi = []
    for x,y in ima:
        if arr[x+1][y] == "." and flg[x+1][y] == -1:
            tugi.append([x+1,y])         
            flg[x+1][y] = flg[x][y] + 1
        if arr[x-1][y] == "." and flg[x-1][y] == -1:
            tugi.append([x-1,y])
            flg[x-1][y] = flg[x][y] + 1
        if arr[x][y+1] == "." and flg[x][y+1] == -1:
            tugi.append([x,y+1])
            flg[x][y+1] = flg[x][y] + 1
        if arr[x][y-1] == "." and flg[x][y-1] == -1:
            tugi.append([x,y-1])
            flg[x][y-1] = flg[x][y] + 1
    ima = tugi

ans = -1
for i in flg:
    for j in i:
        if ans < j:
            ans = j
print(ans)
Problem p03107 (python)

Fixed submission:
S =input()
S = list(S)
c_one = S.count('1')
c_zero = S.count('0')
print(min(c_one,c_zero)*2)

Buggy submission (verdict: Runtime Error):
from collections import deque
S = input()
S = list(S)
counter = 0
que = deque([])
stack = deque([])
for i in range(len(S)):
    que.append(S[i])
for i in range(1000000):
  if stack:
    1
  else:
    stack.append(que.popleft())
  if que:
    s1 = que.popleft()
  else:
    break
  s2 = stack.pop()
  if(s1 != s2):
    counter+=2
  else:
    stack.append(s1)
    stack.append(s2)
print(counter)

Buggy submission (verdict: Runtime Error):
from collections import deque
S =input()
counter = 0
S = list(S)
q = deque([])
for i in range(len(S)):
    q.append(S[i])
for i in range(len(S)):
    if q:
        s1 = q.popleft()
        s2 = q.popleft()
        if(s1 != s2):
            counter+=2
        else:
            q.append(s1)
            q.appendleft(s2)
    else:
        break
print(counter)
Problem p03127 (python)

Fixed submission:
from queue import PriorityQueue
N = int(input())
A = map(int, input().split())
q = PriorityQueue()
for a in A:
    q.put(-a)
x = -q.get()
while not q.empty():
    y = -q.get()
    if y == 0:
        break
    q.put(-(x % y))
    x = y
print(x)

Buggy submission (verdict: Runtime Error):
from queue import PriorityQueue
N = int(input())
A = map(int, input().split())
q = PriorityQueue
for a in A:
  q.put(a)
x = q.get()
while not q.empty():
  y=q.get()
  if y == 0:
    break
  q.put(x % y)
  x = y
print(x)
Problem p03208 (python)

Fixed submission:
N,K = map(int,input().split())
h = []
for _ in range(N):
    h.append(int(input()))
h = sorted(h)
tmp = 0
ans = 10000000000
loop = N-K+1
for i in range(loop):
    tmp = h[K+i-1] - h[0+i]
    if(tmp < ans):
        ans = tmp
print(ans)

Buggy submission (verdict: Runtime Error):
N,K = map(int,input().split())
h = []
for _ in range(N):
    h.append(int(input()))
h = sorted(h)
tmp = 0
loop = N-K+1
for i in range(loop):
    tmp = h[K+i-1] - h[0+i]
    if(tmp < ans):
        ans = tmp
print(ans)

Buggy submission (verdict: Runtime Error):
N,K = map(int,input().split())
h = []
for _ in range(N):
    h.append(int(input()))
h = sorted(h)
tmp = 0
loop = N-K+1
for i in range(loop):
    tmp = h[K+i-1] - h[0+i]
    if(tmp < ans):
        ans = tmp
print(ans)

Buggy submission (verdict: Runtime Error):
N,K = map(int,input().split())
h = []
for _ in range(N):
    h.append(int(input()))
h = sorted(h)
tmp = 0
ans = 1000000000
loop = min(K+1,N-K+1)
for i in range(loop+1):
    tmp = h[K+i-1] - h[0+i]
    if(tmp < ans):
        ans = tmp
print(ans)

Buggy submission (verdict: Runtime Error):
N,K = map(int,input().split())
h = []
for _ in range(N):
    h.append(int(input()))
h = sorted(h)
tmp = 0
ans = 1000000000
if (N == K):
    ans = sum(h)
else:
    for i in range(K):
        tmp = h[K+i-1] - h[0+i]
        if(tmp < ans):
            ans = tmp
print(ans)

Buggy submission (verdict: Runtime Error):
N,K = map(int,input().split())
h = []
for _ in range(N):
    h.append(int(input()))
h = sorted(h)
tmp = 0
ans = 1000000000
for i in range(K):
    tmp = h[K+i-1] - h[0+i]
    if(tmp < ans):
        ans = tmp
print(ans)
Problem p03209 (python)

Fixed submission:
N,X = map(int,input().split())
bg_cnt = [1]
pan_cnt = [1]
for i in range(N):
    bg_cnt.append(bg_cnt[i] * 2 + 3)
    pan_cnt.append(pan_cnt[i] * 2 + 1)

def f(N,X):
    if N == 0:
        return 1
    elif X == 1:
        return 0
    elif X <= 1 + bg_cnt[N-1]:
        return f(N-1,X-1)
    elif X == 2 + bg_cnt[N-1]:
        return 1 + f(N-1,X-1)
    else:
        return pan_cnt[N-1] + 1 + f(N-1,X-2-bg_cnt[N-1])    
print(f(N,X))

Buggy submission (verdict: Runtime Error):
N,X = map(int,input().split())
finished_dic ={} 
def f(N):
    if(N == 0):
        return 'P'
    else:
        if(N in finished_dic):
            return finished_dic[N]
        else:
            finished_dic[N] = ('B' + f(N-1) + 'P' + f(N-1) + 'B')
            return finished_dic[N]
burger = f(N)
print(burger[0:X].count('P'))
Problem p03221 (python)

Fixed submission:
n,m = map(int,input().split())
p,y = [],[]
for i in range(m):
    v1,v2 = map(int,input().split())
    p.append(v1)
    y.append(v2)
    
py = zip(p,y,range(m))
py = sorted(py)
p,y,index = zip(*py)

ans = []
start = p[0]
count = 1
for i in range(m):
    if start == p[i]:
        ans.append(str(p[i]).zfill(6) + str(count).zfill(6))
        count += 1
    else:
        count = 1
        start = p[i]
        ans.append(str(p[i]).zfill(6) + str(count).zfill(6))
        count += 1

ans1 = zip(index,ans)
ans1 = sorted(ans1)
index,ans = zip(*ans1)
for i in ans:
    print(i)

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
p,y = [],[]
for i in range(m):
    v1,v2 = map(int,input().split())
    p.append(v1)
    y.append(v2)
    
py = zip(p,y,range(m))
py = sorted(py)
p,y,index = zip(*py)
 
ans = []
start = p[0]
count = 1
for i in range(m):
    if start == p[i]:
        ans.append(str(p[i]).zfill(6) + str(count).zfill(6))
        count += 1
    else:
        count = 1
        start = p[i]
        ans.append(str(p[i]).zfill(6) + str(count).zfill(6))
        count += 1
 
ans = zip(index,ans)
ans = sorted(ans1)
index,ans = zip(*ans)
for i in ans:
    print(i)
Problem p03723 (python)

Fixed submission:
a,b,c = map(int,input().split())

if a%2 == 1 or b%2 == 1 or c%2==1:
    print(0)
elif a==b and b==c and c==a:
    print(-1)
else:
    for i in range(10**9):
        ans = i
        if a % 2 == 1:
            break
        else:
            tmpa = b/2 + c/2
        if b % 2 == 1:
            break
        else:
            tmpb = c/2 + a/2
        if c % 2 == 1:
            break
        else:
            tmpc = a/2 + b/2
        a = tmpa
        b = tmpb
        c = tmpc
    print(ans)

Buggy submission (verdict: Runtime Error):
a,b,c = map(int,input().split())

if a == b and b == c and c == a:
    print(-1)
else:
    for i in range(10**9):
        ans = i
        if a % 2 ==1:
            break
        else:
            a = b/2 + c/2
        if b % 2 == 1:
            break
        else:
            b = c/2 + a/2
        if c % 2 == 1:
            break
        else:
            c = a/2 + b/2
print(ans)
Problem p03785 (python)

Fixed submission:
n,c,k = map(int,input().split())
t = []
for i in range(n):
    t.append(int(input()))
    
t = sorted(t)
bus = []
ans = 1
for i in range(n):
    if len(bus) < c: #バスの定員に余裕があるとき
        if not bus:#バスに誰も乗っていなかったらバスに人を乗せる
            bus.append(t[i])
        elif t[i] <= bus[0] + k:#バスに初めて人が乗った時刻にkを足して、それよりt[i]が小さければバスに乗せる
            bus.append(t[i])
        else:#上記のelifを満たさない場合
            ans +=1
            bus = []
            bus.append(t[i])
    elif len(bus) == c:
        ans +=1
        bus = []
        bus.append(t[i])
    else:
        ans +=1
        bus = []
print(ans)

Buggy submission (verdict: Runtime Error):
n,c,k = map(int,input().split())
t = []
for i in range(n):
    t.append(int(input()))
    
t = sorted(t)
bus = []
ans = 1
for i in range(n):
    if len(bus) < c: #バスの定員に余裕があるとき
        if not bus:　#バスに誰も乗っていなかったらバスに人を乗せる
            bus.append(t[i])
        elif t[i] <= bus[0] + k:#バスに初めて人が乗った時刻にkを足して、それよりt[i]が小さければバスに乗せる
            bus.append(t[i])
        else:#上記のelifを満たさない場合（
            ans +=1
            bus = []
            bus.append(t[i])
    elif len(bus) == c:
        ans +=1
        bus = []
        bus.append(t[i])
    else:
        ans +=1
        bus = []
print(ans)
Problem p02659 (python)

Fixed submission:
from decimal import Decimal
import math
a,b = map(str, input().split())
b = Decimal(b)
a = int(a)
print(int(a*b))

Buggy submission (verdict: Runtime Error):
import math
a,b = map(float, input().split())
print(math_floor(a*b,2))
Problem p02726 (python)

Fixed submission:
n,x,y = map(int, input().split())
t = [0 for i in range(n)]
x = x-1
y = y-1
for i in range(0,n):
  for j in range(i,n):
    a = abs(i-x)+abs(j-y)+1
    b = abs(i-j)
    if a < b:
      t[a-1] += 1
    else:
      t[b-1] += 1

for k in range(0,n-1):
  print(int(t[k]))

Buggy submission (verdict: Runtime Error):
import numpy as np
n,x,y = map(int, input().split())
s = np.zeros((n,n))
t = np.zeros(n)
for i in range(0,n):
  for j in range(i,n):
    s[i][j] = abs(i-j)
x = x-1
y = y-1
s[x][y] = 1
for i in range(0,n):
  for j in range(i,n):
    a = abs(i-x)+abs(j-y)+1
    if a < s[i][j];
    s[i][j] = a

for i in range(0,n):
  for j in range(i,n):
    for k in range(0.n):
      if k+1 == s[i][j]:
        t[k+1] += 1

for k in range(0.n):
  print t[k]
Problem p02623 (python)

Fixed submission:
from bisect import *
from itertools import accumulate
n, m, k = map(int, input().split())
a = [0]+list(map(int, input().split()))
b = [0]+list(map(int, input().split()))
a = list(accumulate(a))
b = list(accumulate(b))
ans = 0
for i in range(n+1):
    if a[i] > k:
        continue
    ind = bisect_right(b, k-a[i])
    ans = max(ans, ind+i-1)

print(ans)

Buggy submission (verdict: Runtime Error):
from bisect import *
from itertools import accumulate
n, m, k = map(int, input().split())
a = [0]+list(map(int, input().split()))
b = [0]+list(map(int, input().split()))
a = accumulate(a)
b = accumulate(b)
ans = 0
for i in range(n+1):
    ind = bisect_right(b, k-a[i])
    ans = max(ans, ind+i-1)

print(ans)
Problem p02763 (python)

Fixed submission:
#1indexed
class BIT():
    def __init__(self, n):
        self.size = n
        self.bit = [0] * (n+1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.bit[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.bit[i] += x
            i += i & -i

n = int(input())
s = input()
q = int(input())

bit = [BIT(n+1) for i in range(26)]
for i in range(n):
    bit[ord(s[i])-97].add(i+1, 1)


s = list(s)
for _ in range(q):
    query, a, b = input().split()
    if query == "1":
        i = int(a)
        c = ord(b)-97
        bit[ord(s[i-1])-97].add(i, -1)
        bit[c].add(i, 1)
        s[i-1] = b
    else:
        ans = 0
        for k in range(26):
            if bit[k].sum(int(b))-bit[k].sum(int(a)-1) >= 1:
                ans += 1
        print(ans)

Buggy submission (verdict: Runtime Error):
class BIT:
    def __init__(self, n):
        self.n = n
        self.data = [0]*(n+1)
        self.el = [0]*(n+1)
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= i & -i
        return s
    def add(self, i, x):
        # assert i > 0
        self.el[i] += x
        while i <= self.n:
            self.data[i] += x
            i += i & -i
    def get(self, i, j=None):
        if j is None:
            return self.el[i]
        return self.sum(j) - self.sum(i)

n = int(input())
s = input()
q = int(input())

bit = [BIT(n) for i in range(26)]
for i in range(n):
    bit[ord(s[i])-97].add(i+1, 1)
s = list(s)
for _ in range(q):
    query, i, c = input().split()
    if query == "1":
        i = int(i)
        c = ord(c)-97
        if bit[c].get(i) == 0:
            bit[c].add(i, 1)
            bit[ord(s[i])-97].add(i, -1)
            s[i] = chr(c+97)
            print(s)
    else:
        ans = 0
        for k in range(26):
            if bit[k].get(int(i)-1, int(c)) >= 1:
                ans += 1
        print(ans)

Buggy submission (verdict: Runtime Error):
class BIT:
    def __init__(self, n):
        self.n = n
        self.data = [0]*(n+1)
        self.el = [0]*(n+1)
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= i & -i
        return s
    def add(self, i, x):
        # assert i > 0
        self.el[i] += x
        while i <= self.n:
            self.data[i] += x
            i += i & -i
    def get(self, i, j=None):
        if j is None:
            return self.el[i]
        return self.sum(j) - self.sum(i)

n = int(input())
s = input()
q = int(input())

bit = [BIT(n) for i in range(26)]
for i in range(n):
    bit[ord(s[i])-97].add(i+1, 1)
s = list(s)
for _ in range(q):
    query, i, c = input().split()
    if query == "1":
        i = int(i)
        c = ord(c)-97
        if bit[c].get(i) == 0:
            bit[c].add(i+1, 1)
            bit[ord(s[i])-97].add(i+1, -1)
            s[i] = chr(c+97)
    else:
        ans = 0
        for k in range(26):
            if bit[k].get(int(i)-1, int(c)) >= 1:
                ans += 1
        print(ans)
Problem p02792 (python)

Fixed submission:
n = int(input())

table = [[0 for i in range(10)] for j in range(10)]
for i in range(1, n+1):
    i = str(i)
    a, b = int(i[0]), int(i[-1])
    table[a][b] += 1

ans = 0
for i in range(10):
    for j in range(10):
        ans += table[i][j] * table[j][i]

print(ans)

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

table = [[0 for i in range(10)] for j in range(10)]
for i in range(1, n+1):
    i = str(i)
    a, b = i[0], i[-1]
    table[a][b] += 1

ans = 0
for i in range(10):
    for j in range(10):
        ans += table[i][j] * table[j][i]

print(ans)
Problem p02793 (python)

Fixed submission:
from fractions import gcd #直して
n = int(input())
a = list(map(int, input().split()))

mod = 10**9+7
l = 1
for i in range(n):
    l = a[i] // gcd(l, a[i]) * l
    

def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

d = 0
for i in range(n):
    d += modinv(a[i])

print((l*d) % mod)

Buggy submission (verdict: Runtime Error):
from fractions import gcd #直して
n = int(input())
a = list(map(int, input().split()))
def primelist(N):
    prime = [2]
    for i in range(3, N+1):
        flag = 1
        for j in prime:
            if i % j == 0:
                flag = 0
                break
        if flag == 1:
            prime.append(i)
    return prime
prime = primelist(1001)

def factorization(n):
    arr = []
    temp = n
    for i in prime:
        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


mod = 10**9+7
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

fact = [0] * (1000001)
pri = []
for i in range(n):
    f = factorization(a[i])
    for fac, c in f:
        fact[fac] = max(fact[fac], c)

fact_list = []
for i in range(1000001):
    if fact[i] > 0:
        fact_list.append((i, fact[i]))



"""
ans = 0
for i in range(n):
    m = modinv(a[i])
    for fac, c in fact_list:
        m *= pow(fac, c, mod)
        m %= mod

    ans += m
    ans %= mod
"""
print(ans)

Buggy submission (verdict: Runtime Error):
from math import gcd #直して
n = int(input())
a = list(map(int, input().split()))

def factorization(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


mod = 10**9+7
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

fact = [0] * (1000001)
pri = []
for i in range(n):
    f = factorization(a[i])
    for fac, c in f:
        fact[fac] = max(fact[fac], c)

fact_list = []
for i in range(1000001):
    if fact[i] > 0:
        fact_list.append((i, fact[i]))




ans = 0
for i in range(n):
    m = modinv(a[i])
    for fac, c in fact_list:
        m *= pow(fac, c, mod)
        m %= mod

    ans += m
    ans %= mod

print(ans)
Problem p02836 (python)

Fixed submission:
s = input()
ans = 0
for i in range((len(s)-1)//2+1):
  if s[i] != s[-1-i]:
    ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
s = input()
ans = 0
for i in range((len(s)-1)//2+1):
  if a[i] != a[-1-i]:
    ans += 1
print(ans)
Problem p02925 (python)

Fixed submission:
import sys
input = sys.stdin.readline
N = int(input())
A = []
for i in range(N):
    A.append(list(map(int, input().split())))
index = [0]*(N+1)
ans = -2
for k in range(10000):
    today = set()
    flag = 0
    for j in range(N):
        if j+1 in today:
            continue
        if index[j+1] >= N-1:
            continue
        #print(j, index[j+1])
        opponent = A[j][index[j+1]]
        if A[opponent-1][index[opponent]] == j+1:
            if opponent not in today:
                index[opponent] += 1
                index[j+1] += 1
                today.add(opponent)
                today.add(j+1)
                flag = 1
    if flag == 0:
        if sum(index) == N*(N-1):
            ans = k
            break
        else:
            ans = -1
            break
    #print(index)

if ans == -2:
    print(N*(N-1)//2)
else:
    print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
N = int(input())
A = []
for i in range(N):
    A.append(list(map(int, input().split())))
index = [0]*(N+1)

for k in range(30000):
    today = set()
    flag = 0
    for j in range(N):
        if j+1 in today:
            continue
        if index[j+1] >= N-1:
            continue
        #print(j, index[j+1])
        opponent = A[j][index[j+1]]
        if A[opponent-1][index[opponent]] == j+1:
            if opponent not in today:
                index[opponent] += 1
                index[j+1] += 1
                today.add(opponent)
                today.add(j+1)
                flag = 1
    if flag == 0:
        if sum(index) == N*(N-1):
            ans = k
            break
        else:
            ans = -1
            break
    #print(index)

print(ans)
Problem p03042 (python)

Fixed submission:
S = input()
if 1 <= int(S[:2]) <= 12 and 1 <= int(S[2:]) <= 12:
  print("AMBIGUOUS")
elif 1 <= int(S[:2]) <= 12:
  print("MMYY")
elif 1 <= int(S[2:]) <= 12:
  print("YYMM")
else:
  print("NA")

Buggy submission (verdict: Runtime Error):
S = input()
if 1 <= S[:1] <= 12 and 1 <= S[2:] <= 12:
  print("AMBIGUOUS")
elif 1 <= S[:1] <= 12:
  print("MMYY")
elif 1 <= S[2:] <= 12:
  print("YYMM")
else:
  print("NA")
Problem p03207 (python)

Fixed submission:
N = int(input())
a = []
for i in range(N):

  a.append(int(input()))
           
print(sum(a)-max(a)//2)

Buggy submission (verdict: Runtime Error):
N = int(input())
a = []
for i in range(N):

  a.append(int(input())
           
print(sum(a)-max(a)//2)
Problem p03208 (python)

Fixed submission:
N, K = map(int, input().split())
tree = []
for i in range(N):
  tree.append(int(input()))
tree.sort()
mini = 1000000000
for i in range(N-K+1):
  mini = min(mini, tree[i+K-1]-tree[i])
print(mini)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
tree = []
for i in range(N):
  tree.append(int(input()))
tree.sort()
mini = 1000000000
for i in range(N-K+1):
  mini = min(mini, tree[i+K-1]-[i])
print(mini)