Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
Array=[]
for n in range(0,N):
    a,b=input().split()
    Array+=((a+" ")*int(b)).split()
    Array.sort()
print(int(Array[K-1]))


Fixed submission:
N,K=map(int,input().split())
Array={}
for n in range(0,N):
    a,b=map(int,input().split())
    if a in Array:
        Array[a]+=b
    else:
        Array[a]=b
numbers=sorted(list(Array.keys()))
n=0
k=0
while True:
    k+=Array[numbers[n]]
    if k>=K:
        break
    n+=1
print(numbers[n])

Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
Array=[]
for n in range(0,N):
    a,b=map(int,input().split())
    for n in range(0,b):
        Array.append(a)
    Array.sort()
print(Array[K-1])


Fixed submission:
N,K=map(int,input().split())
Array={}
for n in range(0,N):
    a,b=map(int,input().split())
    if a in Array:
        Array[a]+=b
    else:
        Array[a]=b
numbers=sorted(list(Array.keys()))
n=0
k=0
while True:
    k+=Array[numbers[n]]
    if k>=K:
        break
    n+=1
print(numbers[n])
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
import math
rootN=math.sqrt(N)
if rootN==int(rootN):
    n=int(rootN)
else:
    for m in range(int(rootN)+1,N+1):
        if N%m==0:
            n=m
            break
print(len(str(n)))


Fixed submission:
N=int(input())
import math
rootN=math.sqrt(N)
if rootN==int(rootN):
    n=int(rootN)
else:
    for m in reversed(range(1,int(rootN)+1)):
        if N%m==0:
            n=int(N/m)
            break
print(len(str(n)))
Buggy python 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()

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 python 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()


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 python submission (verdict: Time Limit Exceeded):
n,q = map(int, input().split())
if n == 1:
  for _ in range(q):
    print(min(map(int, input().split())))
else:
  for _ in range(q):
    v,w = map(int, input().split())
    while v != w:
      if v > w:
        v,w = w,v
      w = (w+n-2)//n
    print(v)

Fixed submission:
n,q = map(int, input().split())
if n == 1:
  for _ in range(q):
    print(min(map(int, input().split())))
else:
  for _ in range(q):
    v,w = map(int, input().split())
    while v != w:
      if v > w:
        v,w = w,v
      w = (w+n-2)//n
    print(v)
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int, input().split())
l = [tuple(map(int, input().split())) for _ in range(n)]
ok = min(w+d*(k-1) for w,d in l)
ng = 0
while ok-ng > 1:
  mid = (ok+ng)//2
  tot = 0
  for w,d in l:
    if w > mid:
      continue
    tot += 1 + (mid-w)//d
  if tot >= k:
    ok = mid
  else:
    ng = mid
print(ok)

Fixed submission:
n,k = map(int, input().split())
l = [tuple(map(int, input().split())) for _ in range(n)]
ok = min(w+d*(k-1) for w,d in l)
ng = 0
while ok-ng > 1:
  mid = (ok+ng)//2
  tot = 0
  for w,d in l:
    if w > mid:
      continue
    tot += 1 + (mid-w)//d
  if tot >= k:
    ok = mid
  else:
    ng = mid
print(ok)

Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int, input().split())
l = [tuple(map(int, input().split())) for _ in range(n)]
ok = 10**29
ng = 0
while ok-ng > 1:
  mid = (ok+ng)//2
  tot = 0
  for w,d in l:
    if w > mid:
      continue
    tot += 1 + (mid-w)//d
  if tot >= k:
    ok = mid
  else:
    ng = mid
print(ok)

Fixed submission:
n,k = map(int, input().split())
l = [tuple(map(int, input().split())) for _ in range(n)]
ok = min(w+d*(k-1) for w,d in l)
ng = 0
while ok-ng > 1:
  mid = (ok+ng)//2
  tot = 0
  for w,d in l:
    if w > mid:
      continue
    tot += 1 + (mid-w)//d
  if tot >= k:
    ok = mid
  else:
    ng = mid
print(ok)

Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int, input().split())
l = [tuple(map(int, input().split())) for _ in range(n)]
ok = 10**29
ng = 0
while ok-ng > 1:
  mid = (ok+ng)//2
  tot = 0
  for w,d in l:
    if w > mid:
      continue
    tot += 1 + (mid-w)//d
  if tot >= k:
    ok = mid
  else:
    ng = mid
print(ok)

Fixed submission:
n,k = map(int, input().split())
l = [tuple(map(int, input().split())) for _ in range(n)]
ok = min(w+d*(k-1) for w,d in l)
ng = 0
while ok-ng > 1:
  mid = (ok+ng)//2
  tot = 0
  for w,d in l:
    if w > mid:
      continue
    tot += 1 + (mid-w)//d
  if tot >= k:
    ok = mid
  else:
    ng = mid
print(ok)
Buggy python submission (verdict: Runtime Error):
s = input()
is s[::-1].translate(str.maketrans("bdpq","dbqp")) == s:
  print("Yes")
else:
  print("No")

Fixed submission:
s = input()
if s[::-1].translate(str.maketrans("bdpq","dbqp")) == s:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int, input().split())
mod = 10**9 + 7
a = list(map(int, input().split()))
dp = [[[0]*256 for _ in range(n+1)]for i in range(n+1)]
dp[0][0][0] = 1
for i in range(n):
  x = a[i]
  dp[i+1][0] = dp[i][0][:]
  for j in range(n):
    for k in range(256):
      dp[i+1][j+1][k] = (dp[i][j+1][k] + dp[i][j][k^x])%mod
f = 1
ans = 0
for j in range(1,n+1):
  f = f*j%mod
  ans += dp[n][j][m]*f
  ans %= mod
print(ans)

Fixed submission:
n,m = map(int, input().split())
mod = 10**9 + 7
a = list(map(int, input().split()))
dp = [[[0]*256 for _ in range(n+1)]for i in range(n+1)]
dp[0][0][0] = 1
for i in range(n):
  x = a[i]
  dp[i+1][0] = dp[i][0][:]
  for j in range(n):
    for k in range(256):
      dp[i+1][j+1][k] = (dp[i][j+1][k] + dp[i][j][k^x])%mod
f = 1
ans = 0
for j in range(1,n+1):
  f = f*j%mod
  ans += dp[n][j][m]*f
  ans %= mod
print(ans)
Buggy python 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)))

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 python submission (verdict: Runtime Error):
print(1/(1/int(input())+1/int(input())))

Fixed submission:
a=list(map(int,input().split()))
print(1/(1/a[0]+1/a[1]))
Buggy python 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))


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 python 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))


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 python 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))

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 python 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))


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 python 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))

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 python submission (verdict: Time Limit Exceeded):
from heapq import heappush, heappop
T = int(input())
A = []
for i in range(T):
    N, D = map(int, input().split())
    ans = D
    h = []
    heappush(h,D)
    for _ in range(N - 1):
        k = heappop(h)
        z = bin(k)[2:].zfill(7)
        u = map(lambda x: '0' if x == '1' else '1', z)
        t = int(''.join(u),2)
        heappush(h,t)
        ans += (127 + t - k)
    A.append(ans)
for i in range(len(A)):
    print(A[i])


Fixed submission:
from heapq import heappush, heappop
T = int(input())
A = []
for i in range(T):
    N, D = map(int, input().split())
    ans = D
    h = []
    heappush(h,D)
    for _ in range(N - 1):
        k = heappop(h)
        t = 127 ^ k
        heappush(h,t)
        ans += (127 + t - k)
    A.append(ans)
for i in range(len(A)):
    print(A[i])

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappush, heappop
T = int(input())

for i in range(T):
    N, D = map(int, input().split())
    ans = D
    h = []
    heappush(h,D)
    for _ in range(N - 1):
        k = heappop(h)
        z = bin(k)[2:].zfill(7)
        u = map(lambda x: '0' if x == '1' else '1', z)
        t = int(''.join(u),2)
        heappush(h,t)
        ans += (127 + t - k)
    print(ans)

Fixed submission:
from heapq import heappush, heappop
T = int(input())
A = []
for i in range(T):
    N, D = map(int, input().split())
    ans = D
    h = []
    heappush(h,D)
    for _ in range(N - 1):
        k = heappop(h)
        t = 127 ^ k
        heappush(h,t)
        ans += (127 + t - k)
    A.append(ans)
for i in range(len(A)):
    print(A[i])
Buggy python submission (verdict: Time Limit Exceeded):
def f(n):
	e=[1,0,0,1];z=[1,1,1,0]
	while n:e=[e,g(e,z)][n%2];z=g(z,z);n//=2
	return e[1]
M=998244353;g=lambda a,b:[(a[x]*b[y]+a[z]*b[w])%M for x,y,z,w in[[0,0,1,2],[0,1,1,3],[2,0,3,2],[2,1,3,3]]];n,m=map(int,input().split());I=[1,1];r=f(m+2*n-2);c=1
for i in range(2,n):I+=[(M-M//i)*I[M%i]%M]
for i in range(n-1):r=(r+c*(M-f(2*n-2-2*i)))%M;c=c*(m+i)*I[i+1]%M
print(r)

Fixed submission:
M=998244353
g=lambda a,b:[(a[0]*b[0]+a[1]*b[2])%M,(a[0]*b[1]+a[1]*b[3])%M,(a[2]*b[0]+a[3]*b[2])%M,(a[2]*b[1]+a[3]*b[3])%M]
def f(n):
	e=[1,0,0,1];z=[1,1,1,0]
	while n:
		if n%2>0:e=g(e,z)
		z=g(z,z);n//=2
	return e[1]
n,m=map(int,input().split());I=[1,1];r=f(m+2*n-2);c=1
for i in range(2,n):I+=[(M-M//i)*I[M%i]%M]
for i in range(n-1):r=(r+c*(M-f(2*n-2-2*i)))%M;c=c*(m+i)*I[i+1]%M
print(r)
Buggy python 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)

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 python 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)

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 python 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)


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 python 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")



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 python 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

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

if (b <= a):
    print("delicious")
elif (b <= a+x):
    print("safe")
else:
    print("dangerous")
Buggy python 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

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 python 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)


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 python submission (verdict: Time Limit Exceeded):
x = input()
a = []
for i in range(int(x)):
    a.append(int(input()) - 1)

index = 0
count = 0

while (index != 1):
    index = a[index]
    count += 1
    if count >= int(x):
        print(-1)

print(count)

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 python 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")


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


if (a>b):
    print("GREATER")
elif(a==b):
    print("EQUAL")
else:
    print("LESS")
Buggy python 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)


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 python submission (verdict: Time Limit Exceeded):
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

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 python 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

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 python submission (verdict: Time Limit Exceeded):
j=lambda:map(int,raw_input().split())
n,q=j()
c=[1,-1,1]+[0]*(n-2)+[1]
for p in[-1]*q:a,b=j();c[a],c[b]=c[b],c[a];i=c.index(p);c[i-1]=c[i+1]=1
print sum(c)

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 python submission (verdict: Time Limit Exceeded):
H=10800
D=H*8
d=[0]*D
c=0
exec("a,b=map(int,raw_input().split());c+=a;d[c%D]+=1;c+=b;"*input())
d*=2
r=range(D+H)
for i in r:d[i+1]+=d[i]
print max(d[i+H]-d[i-1]for i in r)

Fixed submission:
H=10800
D=H*8
d=[0]*D
c=0
for i in[0]*input():a,b=map(int,raw_input().split());c+=a;d[c%D]+=1;c+=b
d*=2
r=range(D+H)
for i in r:d[i+1]+=d[i]
print max(d[i+H]-d[i-1]for i in r)

Buggy python submission (verdict: Time Limit Exceeded):
H=10800
D=H*8
d=[0]*D
c=0
exec("a,b=map(int,raw_input().split());c+=a;d[c%D]+=1;c+=b;"*input())
d*=2
r=range(D+H)
for i in r:d[i+1]+=d[i]
print max(d[i+H]-d[i]for i in r)

Fixed submission:
H=10800
D=H*8
d=[0]*D
c=0
for i in[0]*input():a,b=map(int,raw_input().split());c+=a;d[c%D]+=1;c+=b
d*=2
r=range(D+H)
for i in r:d[i+1]+=d[i]
print max(d[i+H]-d[i-1]for i in r)
Buggy python 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))

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 python 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)

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 python 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)


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 python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
*A, = map(int, input().split())

MOD = 10**9 + 7

C = {a for a in A}
n = len(C)
m = [[0]*256 for i in range(n+1)]
m[0][0] = 1
for c in C:
    for i in range(n-1, -1, -1):
        for j in range(256):
            m[i+1][c^j] += m[i][j]
            m[i+1][c^j] %= MOD

ans = 0
r = 1
for i in range(1, n+1):
    r = (r * i) % MOD
    ans += r * m[i][k]
    ans %= MOD
print(ans)

Fixed submission:
n, k = map(int, input().split())
*A, = map(int, input().split())

MOD = 10**9 + 7

C = {a for a in A}
n = len(C)
m = [[0]*256 for i in range(n+1)]
m[0][0] = 1
for c in C:
    for i in range(n-1, -1, -1):
        s = m[i]; t = m[i+1]
        for j in range(256):
            t[c^j] += s[j]

ans = 0
r = 1
for i in range(1, n+1):
    r = (r * i) % MOD
    ans += r * m[i][k]
    ans %= MOD
print(ans)
Buggy python submission (verdict: Runtime Error):
n,k=map(int,raw_input().split())
c=[0]*200
r=range(n)
for i in r:c[ord(raw_input()[0])]+=1
c.sort()
p=a=0
while p<1:
 p=k;a+=1
 for i in r:
  if p*c[-i-1]:p-=1;c[-i-1]-=1
print a-1

Fixed submission:
n,k=map(int,raw_input().split())
c=[0]*200
for i in[0]*n:c[ord(raw_input()[0])]+=1
p=a=0
while p<1:
 c.sort();p=k;a+=1
 for i in range(k+1):p-=c[-i]>0;c[-i]-=1
print a-1
Buggy python submission (verdict: Time Limit Exceeded):
r=range(128)
def f():v=min(i for i in r if D[i]);D[v]-=1;D[127-v]+=1;D[127]+=1
for i in[0]*input():n,d=map(int,raw_input().split());D=[0]*128;D[d]=1;exec("f();"*~-n);print sum(i*D[i]for i in r)

Fixed submission:
for i in[0]*input():n,d=map(int,raw_input().split());print~-n*127+(127*(n+1&1)^d)
Buggy python submission (verdict: Runtime Error):
K,A,B=map(int,input().split())
n = (K-A-1) // (A-B) + 1
if A>=K: print(1)
elif A-B<=0: print(-1)
else: print(2*n +1)

Fixed submission:
K,A,B=map(int,input().split())
if A>=K: print(1)
elif A-B<=0: print(-1)
else: 
  n = (K-A-1) // (A-B) + 1
  print(2*n +1)

Buggy python submission (verdict: Runtime Error):
import math
K,A,B=map(int,input().split())
ini=K-A
up=A-B
print(2*math.ceil(ini/up) +1)

Fixed submission:
K,A,B=map(int,input().split())
if A>=K: print(1)
elif A-B<=0: print(-1)
else: 
  n = (K-A-1) // (A-B) + 1
  print(2*n +1)