Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
N = int(input())
S = []
order = 1
for _ in range(N):
    res = input().split()
    if res[0] == "1":
        order = order * - 1
    elif res[1] == "1":
        if order == 1:
            s = res[2]+s
        else:
            s = s+res[2]
    else:
        if order == 1:
            s = s+res[2]
        else:
            s = res[2]+s

if order == -1:
    print(s[::-1])
else:
    print(s)

Fixed submission:
from collections import deque
s = input().split()
sd = deque()
for i in s:
    sd.append(i)
N = int(input())
S = []
order = 1
for _ in range(N):
    res = input().split()
    if res[0] == "1":
        order = order * - 1
    elif res[1] == "1":
        if order == 1:
            sd.appendleft(res[2])
        else:
            sd.append(res[2])
    else:
        if order == 1:
            sd.append(res[2])
        else:
            sd.appendleft(res[2])

sd_str="".join(list(sd))
if order == -1:
    print(sd_str[::-1])
else:
    print(sd_str)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
N = int(input())
S = []
for _ in range(N):
    S.append(input().split())

order = 1
for res in S:
    if res[0] == "1":
        order = order * - 1
    elif res[1] == "1":
        if order == 1:
            s = res[2]+s
        else:
            s = s+res[2]
    else:
        if order == 1:
            s = s+res[2]
        else:
            s = res[2]+s

if order == -1:
    print(s[::-1])
else:
    print(s)

Fixed submission:
from collections import deque
s = input().split()
sd = deque()
for i in s:
    sd.append(i)
N = int(input())
S = []
order = 1
for _ in range(N):
    res = input().split()
    if res[0] == "1":
        order = order * - 1
    elif res[1] == "1":
        if order == 1:
            sd.appendleft(res[2])
        else:
            sd.append(res[2])
    else:
        if order == 1:
            sd.append(res[2])
        else:
            sd.appendleft(res[2])

sd_str="".join(list(sd))
if order == -1:
    print(sd_str[::-1])
else:
    print(sd_str)

Buggy python submission (verdict: Time Limit Exceeded):
s = [char for char in input()]
cnt = int(input())
for _ in range(cnt):
    item = input().split()
    if item[0] == "1":
        s.reverse()
    elif item[0] == "2":
        if item[1] == "1":
            s = [item[2]] + s
        else:
            s.append(item[2])
print("".join(s))

Fixed submission:
from collections import deque
s = input().split()
sd = deque()
for i in s:
    sd.append(i)
N = int(input())
S = []
order = 1
for _ in range(N):
    res = input().split()
    if res[0] == "1":
        order = order * - 1
    elif res[1] == "1":
        if order == 1:
            sd.appendleft(res[2])
        else:
            sd.append(res[2])
    else:
        if order == 1:
            sd.append(res[2])
        else:
            sd.appendleft(res[2])

sd_str="".join(list(sd))
if order == -1:
    print(sd_str[::-1])
else:
    print(sd_str)
Buggy python submission (verdict: Runtime Error):
s = int(input())
print(s/?2 + s%2)

Fixed submission:
s = int(input())
print(s//2 + s%2)

Buggy python submission (verdict: Runtime Error):
s = input()
print(s/2 + s%2)

Fixed submission:
s = int(input())
print(s//2 + s%2)
Buggy python submission (verdict: Time Limit Exceeded):
import math
n,a,b = map(int,input().split())
n_fact = math.factorial(n)
print(int((2**n-n_fact/math.factorial(a)/math.factorial(n-a)-n_fact/math.factorial(b)/math.factorial(n-b)-1)%(10**9+7)))

Fixed submission:
def mod_power(x,y,p):
    if y == 1:
        return x % p
    elif y % 2 == 0:
        return (mod_power(x,y/2,p)**2) % p
    else:
        return (mod_power(x,y-1,p) * x ) % p

def mod_inv(x,p):
    return mod_power(x,p-2,p)

def mod_nCa(n,a,p):
    num = 1
    den = 1
    for i in range(a):
        num = (num * (n-i)) % p
        den = (den * (a-i)) % p
    return (num * mod_inv(den,p)) % p


n,a,b = map(int,input().split())

m = 10**9 + 7

print((mod_power(2,n,m) - mod_nCa(n,a,m) - mod_nCa(n,b,m) - 1) % m)

Buggy python submission (verdict: Time Limit Exceeded):
import math
n,a,b = map(int,input().split())
n_fact = math.factorial(n)
print(int((2**n-n_fact/math.factorial(a)/math.factorial(n-a)-n_fact/math.factorial(b)/math.factorial(n-b)-1)%(10**9+7)))

Fixed submission:
def mod_power(x,y,p):
    if y == 1:
        return x % p
    elif y % 2 == 0:
        return (mod_power(x,y/2,p)**2) % p
    else:
        return (mod_power(x,y-1,p) * x ) % p

def mod_inv(x,p):
    return mod_power(x,p-2,p)

def mod_nCa(n,a,p):
    num = 1
    den = 1
    for i in range(a):
        num = (num * (n-i)) % p
        den = (den * (a-i)) % p
    return (num * mod_inv(den,p)) % p


n,a,b = map(int,input().split())

m = 10**9 + 7

print((mod_power(2,n,m) - mod_nCa(n,a,m) - mod_nCa(n,b,m) - 1) % m)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
n,a,b = map(int,input().split())
print((2**n-len(list(itertools.combinations(range(n),a)))-len(list(itertools.combinations(range(n),b)))-1)%(10**9+7))

Fixed submission:
def mod_power(x,y,p):
    if y == 1:
        return x % p
    elif y % 2 == 0:
        return (mod_power(x,y/2,p)**2) % p
    else:
        return (mod_power(x,y-1,p) * x ) % p

def mod_inv(x,p):
    return mod_power(x,p-2,p)

def mod_nCa(n,a,p):
    num = 1
    den = 1
    for i in range(a):
        num = (num * (n-i)) % p
        den = (den * (a-i)) % p
    return (num * mod_inv(den,p)) % p


n,a,b = map(int,input().split())

m = 10**9 + 7

print((mod_power(2,n,m) - mod_nCa(n,a,m) - mod_nCa(n,b,m) - 1) % m)
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
ds = list(map(int,input().split()))
out = 0
for i in range(N-K+1):
    out = max(out,sum(ds[i:i+K]))
print((out+K)/2)

Fixed submission:
import queue
q = queue.Queue()
N,K = map(int,input().split())
ds = list(map(int,input().split()))

sm = sum(ds[:K])
out = sm
for i in range(N-K):
    sm = sm-ds[i]+ds[i+K]
    out = max(out,sm)

print((out+K)/2)
Buggy python submission (verdict: Runtime Error):
import math
a,b = map(int,input().split())
print(int(a * b / math.gcd(a, b)))

Fixed submission:
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)
a,b = map(int,input().split())
print(int(a * b / gcd(a, b)))
Buggy python submission (verdict: Runtime Error):
n = int(input())
As = list(map(int,input().split()))

def func(idx,lst):
    if len(lst) == 0:
        return 0
    elif lst[0] == idx:
        return func(idx+1,lst[1:])
    else:
        return 1 + func(idx,lst[1:])

out = func(1,As)
if out == len(As):
    print(-1)
else:
    print(out)

Fixed submission:
n = int(input())
As = list(map(int,input().split()))

out = 0
num = 1
for A in As:
    if  A == num:
        num += 1
    else:
        out += 1
if out == n:
    print(-1)
else:
    print(out)
Buggy python submission (verdict: Runtime Error):
s=input()
if s.count("RRR")>0:
  print(3)
elif s.cout("RR")>0:
  print(2)
elif s.cout("R")>0:
  print(1)
else:
  print(0)

Fixed submission:
s=input()
if s.count("RRR")>0:
  print(3)
elif s.count("RR")>0:
  print(2)
elif s.count("R")>0:
  print(1)
else:
  print(0)
Buggy python submission (verdict: Runtime Error):
N = int(input())

if N <= 1:
  print(0)
else:
  res = (10**N - 8**N - 2 * (9**N - 8**N)) % mod

  print(int(res))

Fixed submission:

mod = 10**9+7
N = int(input())

if N <= 1:
  print(0)
else:
  res = (10**N - 8**N - 2 * (9**N - 8**N)) % mod

  print(int(res))
Buggy python submission (verdict: Time Limit Exceeded):
MOD = 10**9 + 7

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

res = 0

for i in range(N)[:-1]:
  res += A[i] * sum(A[i+1:])
  res %= MOD

print(res)

Fixed submission:
MOD = 10**9 + 7

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

res = 0
sumA = sum(A)
for i in range(N)[:-1]:
  sumA -= A[i]
  res += A[i] * sumA
  res %= MOD

print(res)

Buggy python submission (verdict: Time Limit Exceeded):
MOD = 10**9 + 7

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

res = 0

for i in range(N)[:-1]:
  for j in range(N)[i+1:]:
    res += A[i] * A[j]
    res %= MOD

print(res)

Fixed submission:
MOD = 10**9 + 7

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

res = 0
sumA = sum(A)
for i in range(N)[:-1]:
  sumA -= A[i]
  res += A[i] * sumA
  res %= MOD

print(res)
Buggy python submission (verdict: Time Limit Exceeded):
import functools
import math

N = input()
A = list(map(int, input().split()))
A = sorted(A)
gcd = functools.reduce(math.gcd, A)
if 2 <= gcd:
  print("not coprime")
else:
  isPC = True
  for i, a in enumerate(A):
    for aa in A[i+1:]:
      if 1 != math.gcd(a, aa):
        isPC = False
        break
    if not isPC:
      break
  if isPC:
    print("pairwise coprime")
  else:
    print("setwise coprime")

Fixed submission:
import functools
import math
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i:
        divisors.append(n//i)

  divisors.sort()
  divisors.pop(0)
  return divisors

def is_prime(n):
  for i in range(2, n + 1):
    if i * i > n:
      break
    if n % i == 0:
      return False
  return n != 1

N = input()
A = list(map(int, input().split()))
A = sorted(A)
gcd = functools.reduce(math.gcd, A)

dp = []
if 2 <= gcd:
  print("not coprime")
else:
  isPC = True
  for a in A:
    if is_prime(a):
      dp.append(a)
    else:
      divs = make_divisors(a)
      for d in divs:
        if d in dp:
          isPC = False
          break
        dp.append(d)

    if not isPC:
      break
  if isPC:
    print("pairwise coprime")
  else:
    print("setwise coprime")
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())

rev = False
for i in range(Q):
  query = list(input())
  if query[0] == '1':
    rev = not rev
  else:
    c = query[4]
    if query[2] == '1' and not rev or (rev and query[2] == '2'):
      S = c + S
    else:
      S = S + c

if rev:
  print(S[::-1])
else:
  print(S)

Fixed submission:
from collections import deque
S = list(input())
Q = int(input())

S = deque(S)

rev = False
for i in range(Q):
  query = list(input())
  if query[0] == '1':
    rev = not rev
  else:
    c = query[4]
    if query[2] == '1' and not rev or (rev and query[2] == '2'):
      S.appendleft(c)
    else:
      S.append(c)
      
if rev:
  S.reverse()


print(''.join(S))
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
data = {}
canMake = True
for _ in range(M):
  s, c = map(int, input().split())
  if s in data:
    if data[s] != c:
      canMake = False
  else:
    data[s] = c

keta = max(data)
pad = min(data)
if data[min(data)] == 0:
  canMake = False

if not canMake:
  print(-1)
  exit()

res = 0
for i in range(1, keta+1):
  if i in data:
    res += data[i]*10**(keta-i)
  elif i < pad:
    res += 10**(keta-i)

print(res)

Fixed submission:
N, M = map(int, input().split())
data = {}
canMake = True
if M == 0:
  if N == 1:
    print(0)
  if N == 2:
    print(10)
  if N == 3:
    print(100)
  exit()

for _ in range(M):
  s, c = map(int, input().split())
  if s in data:
    if data[s] != c:
      canMake = False
  else:
    data[s] = c

keta = N
pad = min(data)
if N != 1 and min(data) == 1 and data[min(data)] == 0:
  canMake = False

if not canMake:
  print(-1)
  exit()

res = 0
for i in range(1, keta+1):
  if i in data:
    res += data[i]*10**(keta-i)
  elif i == 1:
    res += 10**(keta-i)

print(res)
Buggy python submission (verdict: Time Limit Exceeded):
import math

def pow(x, n, m):
  ans = 1
  while(n > 0):
    if n & 1:
      ans = ans*x%m
    x = x*x%m
    n = n >> 1
  return ans

MOD = 1000000007
n, a, b = list(map(int, input().split()))

res = pow(2, n, MOD) - 1

dpa = {}
dpb = {}
factriala = 1
factrialb = n
for i in range(1, max(a, b)+1):
  if i in [a, b]:
    dpb[i] = factrialb
  factriala *= i
  factrialb *= n-i
  if i in [a, b]:
    dpa[i] = factriala

def ncr_count(r):
  return dpb[r] * pow(dpa[r], MOD-2, MOD)

res = res - ncr_count(a) - ncr_count(b)

print(res%MOD)

Fixed submission:
MOD = 1000000007
n, a, b = list(map(int, input().split()))

res = pow(2, n, MOD) - 1

dpa = {}
dpb = {}
factriala = 1
factrialb = n
for i in range(1, max(a, b)+1):
  if i in [a, b]:
    dpb[i] = factrialb
  factriala *= i
  factriala %= MOD
  factrialb *= n-i
  factrialb %= MOD
  if i in [a, b]:
    dpa[i] = factriala

def ncr_count(r):
  return dpb[r] * pow(dpa[r], MOD-2, MOD)

res = res - ncr_count(a) - ncr_count(b)

print(res%MOD)

Buggy python submission (verdict: Time Limit Exceeded):
import math


MOD = 1000000007
n, a, b = list(map(int, input().split()))

res = 2 ** n - 1

dpa = {}
dpb = {}
factriala = 1
factrialb = n
for i in range(1, max(a, b)+1):
  if i in [a, b]:
    dpb[i] = factrialb
  factriala *= i
  factrialb *= n-i
  if i in [a, b]:
    dpa[i] = factriala

def ncr_count(r):
  return dpb[r] // dpa[r]

res = res - ncr_count(a) - ncr_count(b)

print(res%MOD)

Fixed submission:
MOD = 1000000007
n, a, b = list(map(int, input().split()))

res = pow(2, n, MOD) - 1

dpa = {}
dpb = {}
factriala = 1
factrialb = n
for i in range(1, max(a, b)+1):
  if i in [a, b]:
    dpb[i] = factrialb
  factriala *= i
  factriala %= MOD
  factrialb *= n-i
  factrialb %= MOD
  if i in [a, b]:
    dpa[i] = factriala

def ncr_count(r):
  return dpb[r] * pow(dpa[r], MOD-2, MOD)

res = res - ncr_count(a) - ncr_count(b)

print(res%MOD)

Buggy python submission (verdict: Time Limit Exceeded):
import math

def ncr_count(n, r):
  return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


MOD = 1000000007
n, a, b = list(map(int, input().split()))

res = 2 ** n - 1

res = res - ncr_count(n, a) - ncr_count(n, b)

print(res%MOD)

Fixed submission:
MOD = 1000000007
n, a, b = list(map(int, input().split()))

res = pow(2, n, MOD) - 1

dpa = {}
dpb = {}
factriala = 1
factrialb = n
for i in range(1, max(a, b)+1):
  if i in [a, b]:
    dpb[i] = factrialb
  factriala *= i
  factriala %= MOD
  factrialb *= n-i
  factrialb %= MOD
  if i in [a, b]:
    dpa[i] = factriala

def ncr_count(r):
  return dpb[r] * pow(dpa[r], MOD-2, MOD)

res = res - ncr_count(a) - ncr_count(b)

print(res%MOD)
Buggy python submission (verdict: Runtime Error):
S, T = input().split()
A, B = map(int, input().split())
U = input()

if (S == U) {
  A -= 1
} else {
  B -= 1
}
print(A, B)

Fixed submission:
S, T = input().split()
A, B = map(int, input().split())
U = input()

if (S == U):
  A -= 1
else:
  B -= 1

print(A, B)
Buggy python submission (verdict: Runtime Error):
C = input()
print(chr(ord(c)+1))

Fixed submission:
C = input()
print(chr(ord(C)+1))
Buggy python submission (verdict: Time Limit Exceeded):
N, K = list(map(int, input().split()))
R, S, P = list(map(int, input().split()))
T = input()
res = 0
k = ''
log = ''
for i in range(N):
  t = T[i]
  if t == 'r':
    if K <= i and log[i-K] == 'p':
      log += 'x'
    else:
      res += P
      log += 'p'
  elif t == 's':
    if K <= i and log[i-K] == 'r':
      log += 'x'
    else:
      res += R
      log += 'r'
  else:
    if K <= i and log[i-K] == 's':
      log += 'x'
    else:
      res += S
      log += 's'

print(res)


Fixed submission:
N, K = list(map(int, input().split()))
R, S, P = list(map(int, input().split()))
T = input()
res = 0
k = ''
log = []
for i in range(N):
  t = T[i]
  if t == 'r':
    if K <= i and log[i-K] == 'p':
      log.append('x')
    else:
      res += P
      log.append('p')
  elif t == 's':
    if K <= i and log[i-K] == 'r':
      log.append('x')
    else:
      res += R
      log.append('r')
  else:
    if K <= i and log[i-K] == 's':
      log.append('x')
    else:
      res += S
      log.append('s')

print(res)
Buggy python submission (verdict: Runtime Error):
S = input()
K = int(input())

for (i, s) in enumerate(S):
    if s != '1':
        one_length = i
        next_num = s
        break

if one_length < K:
    print(str(next_num))
else:
    print('1')

# 1 or 一つ目の1以外

Fixed submission:
S = input()
K = int(input())
one_length = 0
next_num = '1'
for (i, s) in enumerate(S):
    if s != '1':
        one_length = i
        next_num = s
        break

if one_length < K:
    print(str(next_num))
else:
    print('1')

# 1 or 一つ目の1以外
Buggy python submission (verdict: Runtime Error):
N = int(input())
a = list(map(int, input().split()))

def gcd(a, b):
  if b == 0:
    return a
  return gcd(b, a%b)

def lcm(a, b):
  return a*b/gcd(a,b)

alcm = a[0]
for i in a[1:]:
  alcm = lcm(alcm, i) 

res = 0

for i in range(N):
  res += (alcm-1) % a[i]

print(int(res))

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

def gcd(a, b):
  if b == 0:
    return a
  return gcd(b, a%b)

def lcm(a, b):
  return a*b//gcd(a,b)

alcm = a[0]
for i in a[1:]:
  alcm = lcm(alcm, i)

res = 0

for i in range(N):
  res += (alcm-1) % a[i]

print(int(res))

Buggy python submission (verdict: Runtime Error):
N = int(input())
a = list(map(int, input().split()))

def gcd(a, b):
  if b == 0:
    return a
  return gcd(b, a%b)

def lcm(a, b):
  return a*b/gcd(a,b)

alcm = a[0]
for i in a[1:]:
  alcm = lcm(alcm, i) 

res = 0

for i in range(N):
  res += (alcm-1) % a[i]

print(int(res))

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

def gcd(a, b):
  if b == 0:
    return a
  return gcd(b, a%b)

def lcm(a, b):
  return a*b//gcd(a,b)

alcm = a[0]
for i in a[1:]:
  alcm = lcm(alcm, i)

res = 0

for i in range(N):
  res += (alcm-1) % a[i]

print(int(res))
Buggy python submission (verdict: Runtime Error):
R, C, N = map(int, raw_input().split())

lines = []
for i in range(N):
	x, y, xx, yy = map(int, raw_input().split())
	if (x in [0, R] or y in [0, C]) and (xx in [0, R] or yy in [0, C]):
		if x <= y:
			first = x+y
		else:
			first = (R*2 + C*2)-(x+y)
		if xx <= yy:
			second = xx+yy
		else:
			second = (R*2 + C*2)-(xx+yy)
		new_line = [first, second] if first < second else [second, first]
		j = 0
		for j in range(len(lines)):
			if new_line[0] < lines[j][0]:
				lines.insert(j, new_line)
				break
		else:
			lines.append(new_line)

false_flag = False
scopes = []
scopes.append(lines.pop(0))
while lines and not false_flag:
	while scopes:
		next_scope = lines.pop(0)
		right = scopes[-1][1]
		next_left = next_scope[0]
		next_right = next_scope[1]
		if next_left < right:
			if next_right < right:
				if lines:
					scopes.append(next_scope)
				else:
					break
			else:
				false_flag = True
				break
		else:
			scopes.pop()
	else:
		scopes.append(next_scope)

if false_flag:
	print 'NO'
else:
	print 'YES'

Fixed submission:
MOD = pow(10, 9)+7
N, M = map(int, raw_input().split())

def myfact(num):
	res = 1
	for i in range(num+1)[1:]:
		res *= i
		if res > MOD:
			res %= MOD
	return res
if abs(N - M) > 1:
	print 0
else:
	if N == M:

		res = ( myfact(N) * myfact(N) * 2 )%MOD
	else:
		res = ( myfact(N) * myfact(M) )%MOD
	print res

Buggy python submission (verdict: Time Limit Exceeded):
import math
MOD = pow(10, 9)+7
N, M = map(int, raw_input().split())

if abs(N - M) > 1:
	print 0
else:
	if N == M:
		res = ( math.factorial(N) * math.factorial(N) * 2 )%MOD
	else:
		res = ( math.factorial(N) * math.factorial(M) )%MOD
	print res

Fixed submission:
MOD = pow(10, 9)+7
N, M = map(int, raw_input().split())

def myfact(num):
	res = 1
	for i in range(num+1)[1:]:
		res *= i
		if res > MOD:
			res %= MOD
	return res
if abs(N - M) > 1:
	print 0
else:
	if N == M:

		res = ( myfact(N) * myfact(N) * 2 )%MOD
	else:
		res = ( myfact(N) * myfact(M) )%MOD
	print res
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = sorted(list(map(int, input().split())))
dp = {}
quota = 0
res = 0
baseSize = 0
for i in range(N-1):
  a = A[i]
  target = i+1
  baseSize += a
  size = baseSize
  while target < N and A[target] <= size*2:
    size += A[target]
    target += 1
  if target == N:
    res = target - i
    break

if res == 0:
  print(1)
else:
  print(res)


Fixed submission:
N = int(input())
A = sorted(list(map(int, input().split())))
dp = {}
quota = 0
res = 0
size = 0
streak = 1
for i in range(N-1):
  a = A[i]
  size += a
  if A[i+1] <= size*2:
    streak += 1
  else:
    streak = 1

print(streak)
Buggy python submission (verdict: Runtime Error):
from copy import deepcopy
N, M = map(int, input().split())
graph = [[10000 for _ in range(N)] for l in range(N)]

for i in range(M):
  a, b, c = map(int, input().split())
  a -= 1
  b -= 1

  graph[b][a] = c
  graph[a][b] = c

newGraph = deepcopy(graph)

for k in range(N):
  for i in range(N):
    for j in range(N):
      graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j])

res = 0
for (i, row) in enumerate(newGraph):
  for (j, weight) in row:
    if (graph[i][j] != weight):
      res += 1

print(res/2)

Fixed submission:
from copy import deepcopy
N, M = map(int, input().split())
INF = 10**9+7
graph = [[INF for _ in range(N)] for l in range(N)]

for i in range(M):
  a, b, c = map(int, input().split())
  a -= 1
  b -= 1

  graph[b][a] = c
  graph[a][b] = c

newGraph = deepcopy(graph)

for k in range(N):
  for i in range(N):
    for j in range(N):
      newGraph[i][j] = min(newGraph[i][j], newGraph[i][k] + newGraph[k][j])

res = 0
for (i, row) in enumerate(newGraph):
  for (j, weight) in enumerate(row):
    if graph[i][j] != weight and graph[i][j] != INF:
      res += 1
print(res//2)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()[::-1]
day_dream_word = ["dreamer", "dream", "eraser", "erase"]
day_dream_word = list(map(lambda s: s[::-1], day_dream_word))
T = ""
res = False
partial_res = True
while not res and partial_res:
  partial_res = False
  for add_word in day_dream_word:
    nextT = T
    nextT += add_word
    if S == nextT:
      res = True
      break
    if S[:len(nextT)] == nextT:
      partial_res = True
      break
  T = nextT

if res:
  print('YES')
else:
  print('NO')

Fixed submission:
S = input()[::-1]
day_dream_word = ["dreamer", "dream", "eraser", "erase"]
day_dream_word = list(map(lambda s: s[::-1], day_dream_word))
T = ""
Tindex = 0
res = False
partial_res = True
while not res and partial_res:
  partial_res = False
  for add_word in day_dream_word:
    nextTindex = Tindex + len(add_word)
    
    if S[Tindex:nextTindex] == add_word:
      if len(S) == nextTindex:
        res = True
        break
      else:
        partial_res = True
        break
  Tindex = nextTindex

if res:
  print('YES')
else:
  print('NO')
Buggy python submission (verdict: Time Limit Exceeded):
a, b, x = map(int, input().split())

for i in range(x):
  fa = a+i
  if fa%x == 0:
    break

if b < fa:
  print(0)
else:
  print(1+(b-fa)//x)

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

i = 0
fa = x*i
while x*i < a:
  i += 1
  fa = x*i

if b < fa:
  print(0)
else:
  print(1+(b-fa)//x)
Buggy python submission (verdict: Time Limit Exceeded):
N = input()
datas = []
for _ in range(N):
	data = map(int, raw_input().split(" "))
	datas.append(data)

t_min = datas[0][0]
o_min = datas[0][1]
for _ in range(N-1):
	t_mul = 1
	o_mul = 1
	t = datas[_+1][0]
	o = datas[_+1][1]
	while t_mul*t < t_min:
		t_mul+=1

	while o_mul*o < o_min:
		o_mul+=1

	if t_mul < o_mul:
		t_min = o_mul*t
		o_min = o_mul*o
	else:
		t_min = t_mul*t
		o_min = t_mul*o

print t_min+o_min

Fixed submission:
import math
N = input()
datas = []
for _ in range(N):
	data = map(long, raw_input().split(" "))
	datas.append(data)

t_min = datas[0][0]
o_min = datas[0][1]
for _ in range(N-1):
	t = datas[_+1][0]
	o = datas[_+1][1]
	t_mul = t_min/t + 1 if t_min%t != 0 else t_min/t
	o_mul = o_min/o + 1 if o_min%o != 0 else o_min/o
	if t_mul < o_mul:
		t_min = o_mul*t
		o_min = o_mul*o
	else:
		t_min = t_mul*t
		o_min = t_mul*o

print t_min+o_min