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

Fixed submission:
x, a, b = map(int, raw_input().split())

if abs(x - a) < abs (x - b):
    print "A"
else:
    print "B"

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

a = map(int, raw_input().split())

a.sort()
a.reverse()
f = 1
tmp = [0]
ct = 0

while len(a) != 0:
    nxt = a.pop(0)
    key = a.pop(0)
    if key == nxt:
        tmp.append(key)
	ct += 1
    	if ct == 2:
            break
    key = nxt

if len(tmp) > 2:
    print tmp[1] * tmp[2]
else:
    print 0
Problem p03625 (python)

Fixed submission:
n = int(input())
tmp = raw_input()

As = [int(a) for a in tmp.split()]

dic = {}
maxes = [0, 0]
for a in As:
    if a not in dic:
        dic[a] = 0
    dic[a] += 1
    if dic[a] % 2 == 0:
        if maxes[0] < a:
            maxes[0], maxes[1] = a, maxes[0]
        elif maxes[1] < a:
                maxes[1] = a

print (maxes[0] * maxes[1])

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

a = map(int, raw_input().split())
a.sort(reverse = True)
tmp = [0]
ct = 0

key = a.pop(0)
while len(a) != 1:
    nxt = a.pop(0)
    if key == nxt:
        tmp.append(key)
	ct += 1
        if ct == 2:
            break
    key = a.pop(0)

if len(tmp) < 2:
    print 0
else:
    print tmp[1] * tmp[2]

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

a = map(int, raw_input().split())

a.sort()
f = 1
tmp = [0]
ct = 0

key = a.pop(len(a) - 1)
while len(a) != 0:
    nxt = a.pop(len(a) - 1)
    if key == nxt:
        tmp.append(key)
	ct += 1
        if ct == 2:
            print tmp[1] * tmp[2]
            break
    key = a.pop(len(a) - 1)

if len(tmp) < 2:
    print 0

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

a = map(int, raw_input().split())

a.sort()
a.reverse()
f = 1
tmp = [0]
ct = 0

key = a.pop(0)
while len(a) != 0:
    nxt = a.pop(0)
    if key == nxt:
        tmp.append(key)
	ct += 1
        if ct == 2:
            print tmp[1] * tmp[2]
            break
    key = a.pop(0)

if len(tmp) < 2:
    print 0

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

a = map(int, raw_input().split())

a.sort()
a.reverse()
f = 1
tmp = [0]
ct = 0

key = a.pop(0)
while len(a) != 0:
    nxt = a.pop(0)
    if key == nxt:
        tmp.append(key)
	ct += 1
        if ct == 2:
            break
    key = a.pop(0)

if len(tmp) > 2:
    print tmp[1] * tmp[2]
else:
    print 0
Problem p03711 (python)

Fixed submission:
g1 = [1, 3, 5, 7, 8, 10, 12]
g2 = [4, 6, 9, 11]
g3 = [2]

s = map(int, raw_input().split())

x = s[0]
y = s[1]

if (x in g1) and (y in g1):
    print "Yes"
elif (x in g2) and (y in g2):
    print "Yes"
elif (x in g3) and (y in g3):
    print "Yes"
else:
    print "No"

Buggy submission (verdict: Runtime Error):
g2 = [4, 6, 9, 11]
g3 = [2]

s = map(int, raw_input().split())

x = s[0]
y = s[1]

if (x in g1) and (y in g1):
    print "Yes"
elif (x in g2) and (y in g2):
    print "Yes"
elif (x in g3) and (y in g3):
    print "Yes"
else:
    print "No"
Problem p03795 (python)

Fixed submission:
n = input()

x = 800 * n
y = (n / 15) * 200
print x - y

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

if b - a == c - b:
    print "YES"
else:
    print "NO"
Problem p03797 (python)

Fixed submission:
n , m = map(int, raw_input().split())

tmp = m - (2 * n)
if tmp < 0:
        ans = m / 2
else:
        ans = 0
        ans += n
        ans += tmp / 4

print ans

Buggy submission (verdict: Runtime Error):
n , m = map(int, raw_input().split())

tmp = m - (2 * n)
ans = 0
if tmp < 0:
        tmp = m - 2 * (n - tmp)
        if tmp >= 0:
                n -= n - tmp
                break

m = tmp

ans += n
ans += tmp / 4

print ans

Buggy submission (verdict: Runtime Error):
n , m = map(int, raw_input().split())

tmp = m - (2 * n)
ans = 0
if tmp < 0:
        for i in range(n):
                tmp = m - 2 * (n - i)
                if tmp >= 0:
                        n -= i
                        break

m = tmp

ans += n
ans += tmp / 4

print ans
Problem p03501 (python)

Fixed submission:
N, A, B = input().split()
'''                                                                                                                                     
N = input()                                                                                                                             
A = input()                                                                                                                             
B = input()                                                                                                                             
'''
N = int(N)
A = int(A)
B = int(B)
priceA = A * N
if  priceA <= B:
    print(priceA)
else:
    print(B)

Buggy submission (verdict: Runtime Error):
N, A, B = input()
N = int(N)
A = int(A)
B = int(B)
priceA = A * N
if  priceA <= B:
    print(priceA)
else:
    print(B)
Problem p03612 (python)

Fixed submission:
N=int(input())
a=list(map(int,input().split()))
c=0
d=[]
for i in range(N):
        if(i+1==a[i]):
            d.append("x")
        else:
            d.append("o")
for i in range(len(d)):
    if d[i]=="x":
        if i==len(d)-1:
            d[i]="o"
            d[i-1]="o"
            c+=1
        else:
            d[i]="o"
            d[i+1]="o"
            c+=1
        
print(c)

Buggy submission (verdict: Runtime Error):
N=int(input())
a=list(map(int,input().split()))
c=0
d=[]
for i in range(N):
        if(i+1==a[i]):
            d.append("x")
        else:
            d.append("o")
for i in range(len(d)):
    if d[i]=="x":
        d[i]="o"
        d[i+1]="o"
        c+=1
print(c)
Problem p03623 (python)

Fixed submission:
import math

x,a,b=list(map(int,input().split()))
if(math.fabs(x-a)>math.fabs(x-b)):
    print("B")
else:
    print("A")

Buggy submission (verdict: Runtime Error):
x,a,b=list(map(int,input().split()))
if(math.fabs(x-a)>math.fabs(x-b)):
    print("B")
else:
    print("A")
Problem p03625 (python)

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

A=sorted(A,reverse=True)
if(len(A)%2==1):
    A.append(0)
c=0
l=1
t=0
th=0
for i in range(0,len(A),2):
    if(c==2):
        break
    if(A[i]==A[i+1]):
        c+=1
        l*=A[i]
        th=True
    elif(t==A[i] and not(th)):
        c+=1
        l*=A[i]
        th=False
    else:
        th=False
    t=A[i+1]
if(c==2):
    print(l)
else:
    print(0)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
 
A=sorted(A,reverse=True)
if(len(A)%2==1):
    A.append(0)
c=0
l=1
for i in range(0,len(A)+1,2):
    if(c==2):
        break
    elif(A[i]==A[i+1]):
        c+=1
        l*=A[i]
if(c==2):
    print(l)
else:
    print(int(0))
Problem p03682 (python)

Fixed submission:
class UnionFind:
    def __init__(self, size):
        self.table = [-1 for _ in range(size)]
 
    def find(self, x):
        if self.table[x] < 0:
            return x
        else:
            self.table[x] = self.find(self.table[x])
            return self.table[x]
 
    def union(self, x, y):
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 != s2:
            if self.table[s1] <= self.table[s2]:
                self.table[s1] += self.table[s2]
                self.table[s2] = s1
            else:
                self.table[s2] += self.table[s1]
                self.table[s1] = s2
            return True
        return False
 
def cal(d,xl):
    N=len(xl)
    for i in range(N-1):
        r1=abs(xl[i+1][0]-xl[i][0])
        try:
            l=d[r1]
            l.append([xl[i+1][1],xl[i][1]])
            d[r1]=l
        except:
            d[r1]=[[xl[i+1][1],xl[i][1]]]
    return d
N=int(input())
x=[[0,0] for _ in range(N)]
y=[[0,0] for _ in range(N)]
for i in range(N):
    x[i][0],y[i][0]=list(map(int,input().split()))
    x[i][1],y[i][1]=i,i
x=sorted(x,key=lambda l: l[0])
y=sorted(y,key=lambda l: l[0])
a=cal(cal({},x),y)
p=UnionFind(N)
c=0
cost=0
edgecount=0
while True:
    if(edgecount==N-1):
        print(cost)
        break
    try:
        l=a[c]
        for item in l:
            if(p.union(item[0],item[1])):
                cost+=c
                edgecount+=1
            
        c+=1
    except:
        c+=1
        continue

Buggy submission (verdict: Runtime Error):
class UnionFind:
    def __init__(self, size):
        self.table = [-1 for _ in range(size)]

    def find(self, x):
        if self.table[x] < 0:
            return x
        else:
            self.table[x] = self.find(self.table[x])
            return self.table[x]

    def union(self, x, y):
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 != s2:
            if self.table[s1] <= self.table[s2]:
                self.table[s1] += self.table[s2]
                self.table[s2] = s1
            else:
                self.table[s2] += self.table[s1]
                self.table[s1] = s2
            return True
        return False

def cal(d,xl):
    N=len(xl)
    for i in range(N-1):
        r1=abs(xl[i+1][0]-xl[i][0])
        try:
            l=d[r1]
            l.append([xl[i+1][1],xl[i][1]])
            d[r1]=l
        except:
            d[r1]=[[xl[i+1][1],xl[i][1]]]
    return d
N=int(input())
N=10**5
x=[[0,0] for _ in range(N)]
y=[[0,0] for _ in range(N)]
for i in range(N):
    x[i][0],y[i][0]=list(map(int,input().split()))
    x[i][1],y[i][1]=i,i
x=sorted(x,key=lambda l: l[0])
y=sorted(y,key=lambda l: l[0])
a=cal(cal({},x),y)
p=UnionFind(N)
c=0
cost=0
edgecount=0
while True:
    if(edgecount==N-1):
        print(cost)
        break
    try:
        l=a[c]
        for item in l:
            if(p.union(item[0],item[1])):
                cost+=c
                edgecount+=1
            
        c+=1
    except:
        c+=1
        continue
Problem p03759 (python)

Fixed submission:
a,b,c = [int(i) for i in raw_input().split(" ")] 
if (b-a) == (c-b) :
	print("YES")
else:
	print("NO")

Buggy submission (verdict: Runtime Error):
a,b,c = [int(i) for i in raw_input().split(" ")] 
if (b-a) == (c-b) :
	print("YES")
else:
	print("NO")
Problem p03844 (python)

Fixed submission:
#001
a,op,b = input().split(" ")
a = int(a)
b = int(b)
if op=="+":
    print(a+b)
else:
    print(a-b)

Buggy submission (verdict: Runtime Error):
#001
a,op,b = input().split(" ")
a = int(a)
b = int(b)
if op=="+":
    print(a+b)
else:
    print(a-b)
Problem p03852 (python)

Fixed submission:
vowel = 'aeuio'
x=raw_input()
if x in vowel:
    print("vowel")
else:
    print("consonant")

Buggy submission (verdict: Runtime Error):
#001
vowel = ['a','e','u','i','o']

x=raw_input()

if x in vowel:
    print("vowel")
else:
    print("consonant")

Buggy submission (verdict: Runtime Error):
#001
vowel = "aeuio"
x=str(raw_input())
if x in vowel:
    print("vowel")
else:
    print("consonant")
Problem p03943 (python)

Fixed submission:
# import time

# starttime=time.clock()

A,B,C =input().split()
a=int(A)
b=int(B)
c=int(C)
# print(a+c)
 
if a>b:
    temp = a
    a = b
    b = temp
if b>c:
    temp = b
    b = c
    c = temp
if (a+b)==c:
    print("Yes")
#     endtime = time.clock()
#     print(endtime-starttime)
else:
    print("No")
#     endtime = time.clock()
#     print(endtime-starttime)
#

Buggy submission (verdict: Runtime Error):
# import time

# starttime=time.clock()

A,B,C =input().split()
a=int(A)
b=int(B)
c=int(C)
print(a+c)
 
if a>b:
    temp = a
    a = b
    b = temp
if b>c:
    temp = b
    b = c
    c = temp
if (a+b)==c:
    print("Yes")
#     endtime = time.clock()
#     print(endtime-starttime)
else:
    print("No")
#     endtime = time.clock()
#     print(endtime-starttime)
#

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

if b>c:
    temp = b
    b = c
    c = temp


if (a+b)==c:
    print("Yes")
else:
    print("No")
Problem p03945 (python)

Fixed submission:
#003
list = list(input())
result = 0

for i in range(len(list)-1):
    if list[i]!=list[i+1]:
        result+=1

print(result)

Buggy submission (verdict: Runtime Error):
#D    高橋君と見えざる手 / An Invisible Hand
N,T = [int(i) for i in input().split(" ")]
A=[int(i) for i in input().split(" ")]
Max = 0
count = 1
for i in range(N-1,0,-1):
    for j in range(i-1,-1,-1):
        temp = A[i]-A[j]
        if temp>Max:
            Max = temp
            count = 1
        elif temp==Max:
            count +=1

print(count)
Problem p03633 (python)

Fixed submission:
import fractions
N,T1=int(input()),int(input())
for n in range(1,N):
    T2=int(input())
    T1=(T1*T2)//fractions.gcd(T1,T2)
print(T1)

Buggy submission (verdict: Runtime Error):
import math
N,T1=int(input()),int(input())
for n in range(1,N):
    T2=int(input())
    T1=int(T1*T2/math.gcd(T1,T2))
print(T1)

Buggy submission (verdict: Runtime Error):
import math
N,T1=int(input()),int(input())
for n in range(1,N):
    T2=int(input())
    T1=T1*T2/math.gcd(T1,T2)
print(int(T1))
Problem p03729 (python)

Fixed submission:
def main():
        s = input().split()

        if s[0][-1] == s[1][0] and s[1][-1] == s[2][0]:
            print("YES")
        else:
            print("NO")
main()

Buggy submission (verdict: Runtime Error):
def main():
        s = raw_input().split()

        if s[0][-1] == s[1][0] and s[1][-1] == s[2][0]:
            print("YES")
        else:
            print("NO")
main()

Buggy submission (verdict: Runtime Error):
def main():
        s = raw_input().split()

        if s[0][-1] == s[1][0] && s[1][-1] == s[2][0]:
            print("YES")
        else:
            print("NO")
main()
Problem p03889 (python)

Fixed submission:
s = input()
if s[::-1].translate(str.maketrans("bdpq","dbqp")) == s:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
s = input()
is s[::-1].translate(str.maketrans("bdpq","dbqp")) == s:
  print("Yes")
else:
  print("No")
Problem p03975 (python)

Fixed submission:
n,a,b = map(int, input().split())
l = [int(input()) for _ in range(n)]
print(n-sum(map(lambda x:a<=x<b,l)))

Buggy submission (verdict: Runtime Error):
n,a,b = map(int, input().split())
l = [int(input()) for _ in range(n)]
print(len(filter(lambda x:a<=x<b,l)))
Problem p03888 (python)

Fixed submission:
a=list(map(int,input().split()))
print(1/(1/a[0]+1/a[1]))

Buggy submission (verdict: Runtime Error):
print(1/(1/int(input())+1/int(input())))
Problem p03892 (python)

Fixed submission:
import math
import fractions
A, B, C, D = map(int, input().split())
if A == C or B == D:
    print(0)
    exit()

x = abs(A - C)
y = abs(B - D)

print(x + y - fractions.gcd(x, y))

Buggy submission (verdict: Runtime Error):
import math
A, B, C, D = map(int, input().split())
if A == C or B == D:
    print(0)
    exit()

x = abs(A - C)
y = abs(B - D)

print(x + y - math.gcd(x, y))

Buggy submission (verdict: Runtime Error):
import math
A, B, C, D = map(int, input().split())
if A == C or B == D:
    print(0)

x = abs(A - C)
y = abs(B - D)

print(x + y - math.gcd(x, y))
Problem p03505 (python)

Fixed submission:
import sys
import math
K, A, B = list(map(int, input().split()))
 
if (A >= K):
    print('1')
    sys.exit()
elif (A - B) <= 0:
    print('-1')
    sys.exit()
d = A-B
p = K-A
q = int(p//d)
if ((p % d) != 0):
    q += 1
print(str(2*q + 1))

Buggy submission (verdict: Runtime Error):
import sys
import math
K, A, B = list(map(int, input().split()))

if (A >= K):
    print('1')
    sys.exit()
elif (A - B) <= 0:
    print('-1')
    sys.exit()
d = A-B
p = K-A
q = int(p//d)
if ((p % d) != 0):
    q += 1
print(str(2*q + 1))

Buggy submission (verdict: Runtime Error):
import sys
import math
K, A, B = list(map(int, input().split()))

if (A >= K):
    print('1')
    sys.exit()
elif (A - B) <= 0:
    print('-1')
    sys.exit()
d = A-B
p = K-A
q = int(p/d)
if ((p % d) != 0):
    q += 1
print(str(2*q + 1))

Buggy submission (verdict: Runtime Error):
 import sys
 import math
 K, A, B = list(map(int, input().split()))

 if A >= K:
     print(1)
     sys.exit()
 elif (A - B) <= 0:
     print(-1)
     sys.exit()
 d = A - B

 p = K-A
 q = math.ceil(p/d)
 if p % d != 0:
     q += 1
 print(int(2*q + 1))
Problem p03976 (python)

Fixed submission:
#!/usr/bin/python
from collections import defaultdict
from heapq import *
import sys
d=defaultdict(int)
n,k=map(int,sys.stdin.readline().split())
for _ in range(n):
	s=sys.stdin.readline().strip()
	d[s[0]]-=1
if len(d)<k:
	print(0)
else:
	q=[]
	for khi in d:
		heappush(q,[d[khi],khi])
	r=0
	while 1:
		a=[heappop(q) for _ in range(k)]
		if any(e[0]==0 for e in a): break
		for e in a:
			e[0]+=1
			heappush(q,e)
		r+=1
	print(r)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/python
from collections import defaultdict
from heapq import *
import sys
d=defaultdict(int)
n,k=map(int,sys.stdin.readline().split())
for _ in range(n):
	s=sys.stdin.readline().strip()
	d[s[0]]-=1
if len(d)<k:
	print(0)
else:
	q=[]
	for khi in d:
		heappush(q,[d[khi],khi])
	r=0
	while 1:
		a=[heappop(q) for _ in range(k)]
		if any(e[0]==0 for e in a): break
		for e in a:
			e[0]+=1
			heappush(q,e)
		r+=1
	print(r)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/python
from collections import defaultdict
from heapq import *
import sys
d=defaultdict(int)
n,k=map(int,sys.stdin.readline().split())
for _ in range(n):
	s=sys.stdin.readline().strip()
	d[s[0]]-=1
if len(d)<k:
	print(0)
else:
	q=[]
	for khi in d:
		heappush(q,[d[khi],khi])
	r=0
	while 1:
		a=[heappop(q) for _ in range(k)]
		if any(e[0]==0 for e in a): break
		for e in a:
			e[0]+=1
			heappush(q,e)
		r+=1
	print(r)
Problem p03647 (python)

Fixed submission:
x = input().split(" ")
n = int(x[0])
m = int(x[1])

probInit = set([])
probEnd  = set([])

for i in range(m):
    edge = input().split(" ")
    if edge[0] == "1":
        probInit.add(edge[1])

    if edge[1] == str(n):
        probEnd.add(edge[0])

sec = probEnd.intersection(probInit)
if (len(sec) == 0):
    print("IMPOSSIBLE")
else:
    print("POSSIBLE")

Buggy submission (verdict: Runtime Error):
k = int(input())
n = 50
m = (n - 1) * (k + 1) + 1


series = str(m)
for i in range(n):
    series = series + " 0"

print(str(n))
print(series)

Buggy submission (verdict: Runtime Error):
x = input().split(" ")
n = int(x[0])
m = int(x[1])

probInit = set([])
probEnd  = set([])

for i in range(m):
    edge = input().split(" ")
    if edge[0] == 0:
        probInit.add(edge[1])

    if edge[1] == n - 1:
        probEnd.add(edge[0])

sec = probEnd.intercection(probInit)
if (len(sec) == 0):
    print("IMPOSSIBLE")
else:
    print("POSSIBLE")
Problem p03679 (python)

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

if (b <= a):
    print("delicious")
elif (b <= a+x):
    print("safe")
else:
    print("dangerous")

Buggy submission (verdict: Runtime Error):
x = input()
a = []
check = []
for i in range(int(x)):
    a.append(int(input()) - 1)
    check.append(1)

index = 0



while True:
    check[index] = 0
    index = a[index]
    if check[index] == 0:
        print(-1)
        break
    if index == 1:
        print(count)
        break
Problem p03680 (python)

Fixed submission:
x = input()
a = []
check = []
for i in range(int(x)):
    a.append(int(input()) - 1)
    check.append(1)

index = 0
count = 0


while True:
    count += 1
    check[index] = 0
    index = a[index]

    if check[index] == 0:
        print(-1)
        break
    if index == 1:
        print(count)
        break

Buggy submission (verdict: Runtime Error):
x = input()
a = []
check = []
for i in range(int(x)):
    a.append(int(input()) - 1)
    check.append(1)

index = 0



while True:
    check[index] = 0
    index = a[index]
    if check[index] == 0:
        print(-1)
        break
    if index == 1:
        print(count)
        break

Buggy submission (verdict: Runtime Error):
x = input()
a = []
check = []
for i in range(int(x)):
    a.append(int(input()) - 1)
    check.append(1)

index = 0



while True:
    check[index] = 0
    index = a[index]
    if check[index] == 0:
        print(-1)
    if index == 1:
        print(count)
Problem p03738 (python)

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


if (a>b):
    print("GREATER")
elif(a==b):
    print("EQUAL")
else:
    print("LESS")

Buggy submission (verdict: Runtime Error):
x = input().split(" ")
a = int(x[0])
b = int(x[1])


if (a>b):
    print("GREATER")
elif(a==b):
    print("EQUAL")
else:
    print("LESS")
Problem p03508 (python)

Fixed submission:
N, M = map(int, input().split())
G = [[] for i in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)
used = [0] * N
def dfs(s):
    st = [s]
    used[s] = 1
    res = 0
    while st:
        s = st.pop()
        res += 1
        for t in G[s]:
            if not used[t]:
                used[t] = 1
                st.append(t)
    return res
g = min(dfs(0), dfs(1))
print(N*(N-1)//2 - g*(N - g) - M)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
G = [[] for i in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)
used = [0] * N
def dfs(s):
    used[s] = 1
    res = 1
    for t in G[s]:
        if not used[t]:
            res += dfs(t)
    return res
g = min(dfs(0), dfs(1))
print(N*(N-1)//2 - g*(N - g) - M)
Problem p03894 (python)

Fixed submission:
j=lambda:map(int,raw_input().split())
n,q=j()
u=1
c=[1]*3+[0]*(n-2)+[1]
for p in[-1]*q:a,b=d=j();u+=u in d and a+b-2*u;c[a],c[b]=c[b],c[a];c[u-1]=c[u+1]=1
print sum(c)-2

Buggy submission (verdict: Runtime Error):
j=lambda:map(int,raw_input().split())
n,q=j()
u=1
c=[1]*3+[0]*(n-2)+[1]
exec("a,b=d=j();u+=u in d and a+b-2*u;c[a],c[b]=c[b],c[a];c[u-1]=c[u+1]=1"*q)
print sum(c)-2
Problem p03896 (python)

Fixed submission:
n=input()
if n==2:print-1;exit(0)
r=range(n-1)
s=r+[n-1]
A=[[1+(i+j+1)%n for j in r]for i in s]
for i in r:
    for j in s:
        if A[A[j][i]-1][i]==j+1:
            A[j][i],A[j][i-n]=A[j][i-n],A[j][i]
print"\n".join(" ".join(map(str, e))for e in A)

Buggy submission (verdict: Runtime Error):
n=input();print-(n==2)or"\n".join(" ".join(`(i+(j^1)if n>i*2and n%2<1and j<n-2else i+j)%n`for j in range(n-1))for i in range(1,n+1))

Buggy submission (verdict: Runtime Error):
n=input()
if n==2:print-1;exit(0)
r=range(n-1)
A=[[`1+(i+j+2)%n`for j in r]for i in[-1]+r]
i=n/2-1
for j in range(i+1):A[j][i]=`j+i+1`;A[j][i-n]=`j+i+2`
print"\n".join(" ".join(e)for e in A)
Problem p03909 (python)

Fixed submission:
h, w = map(int, raw_input().split())
S = [raw_input().split() for i in xrange(h)]
for i in xrange(h):
    for j in xrange(w):
        if S[i][j] == "snuke":
            print "%s%d" % ("ABCDEFGHIJKLMNOPQRSTUVWXYZ"[j], i+1)

Buggy submission (verdict: Runtime Error):
h, w = map(int, raw_input().split())
S = [raw_input().split() for i in xrange(h)]
for i in xrange(h):
    for j in xrange(w):
        if S[i][j] == "snuke":
            print "%s%d" % ("ABCDEFGHIJ"[j], i+1)
Problem p03913 (python)

Fixed submission:
# seishin.py
N, A = map(int, input().split())

ans = N
if N > 1:
    for k in range(1, 41):
        left = 0; right = N+1
        while left+1 < right:
            mid = (left + right) // 2
            if mid**(k+1) < N:
                left = mid
            else:
                right = mid
        m = right
        v = (m-1)**(k+1)
        for i in range(k+1):
            v //= m-1
            v *= m
            if N <= v:
                ans = min(ans, A*k + (m-1)*(k+1) + (i+1))
                break
print(ans)

Buggy submission (verdict: Runtime Error):
# seishin.py
N, A = map(int, input().split())

ans = N
for k in range(1, 41):
    left = 0; right = N+1
    while left+1 < right:
        mid = (left + right) // 2
        if mid**(k+1) < N:
            left = mid
        else:
            right = mid
    m = right
    v = (m-1)**(k+1)
    for i in range(k+1):
        v //= m-1
        v *= m
        if N <= v:
            ans = min(ans, A*k + (m-1)*(k+1) + (i+1))
            break
print(ans)

Buggy submission (verdict: Runtime Error):
# encoding: utf-8
n, a = map(int, raw_input().split())
if n>10**7 or a >= 10**7:
    exit(1)

memo = [-1]*(n+1)
# 残りx個を貯めるために最小の時間を返す予定
def dfs(x):
    if x == 0:
        return 0
    if memo[x] != -1:
        return memo[x]
    i = 0
    res = x
    for i in xrange(2, x+1):
        # i-sec待つ
        res = min(res, dfs((x+i-1)/i)+a+i)
    memo[x] = res
    return memo[x]
print dfs(n)