Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().split())
A = list(map(int,input().split()))
r = [0]*N
p = 0
q = 1 #現在地
for i in range(K):
    q = A[q-1] #次の町
    if r[q-1] == 0:
        p += 1
        r[q-1] += p       
    else:
        p += 1
        y = r[q-1]
        break
z = (K-y) % (p-y)
for i in range(N):
    if r[i] == y+z:
        print(i+1)

Fixed submission:
N,K = map(int,input().split())
A = list(map(int,input().split()))
r = [0]*N
p = 0
q = 1 #現在地
for i in range(K):
    if i == K-1:
        print(A[q-1])
        exit()
    q = A[q-1] #次の町
    if r[q-1] == 0:
        p += 1
        r[q-1] += p       
    else:
        p += 1
        y = r[q-1]
        break
z = (K-y) % (p-y)
for i in range(N):
    if r[i] == y+z:
        print(i+1)

Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().split())
A = list(map(int,input().split()))
r = [0]*N
p = 0
q = 1 #現在地
for i in range(min(K,N)):
    q = A[q-1] #次の町
    if r[q-1] == 0:
        p += 1
        r[q-1] += p       
    else:
        p += 1
        y = r[q-1]
        break
z = (K-y) % (p-y)
for i in range(N):
    if r[i] == y+z:
        print(i+1)

Fixed submission:
N,K = map(int,input().split())
A = list(map(int,input().split()))
r = [0]*N
p = 0
q = 1 #現在地
for i in range(K):
    if i == K-1:
        print(A[q-1])
        exit()
    q = A[q-1] #次の町
    if r[q-1] == 0:
        p += 1
        r[q-1] += p       
    else:
        p += 1
        y = r[q-1]
        break
z = (K-y) % (p-y)
for i in range(N):
    if r[i] == y+z:
        print(i+1)
Buggy python submission (verdict: Runtime Error):
import math
A,B,N = map(int,input().split())
if N%A != 0:
    n = N%A
    ans = 0
    for i in range(1,n+1):
        ans = max(ans,math.floor(A*i/B)-A*math.floor(i/B))
else:
    for i in range(1,A):
        ans = max(ans,math.floor(A*i/B)-A*math.floor(i/B))
print(ans)

Fixed submission:
A,B,N = map(int,input().split())
if N >= B:
    x = B-1
else:
    x = N%B
print(A*x//B)
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = input()
A = [[],[],[]]
ans = 0
for i in range(N):
    if S[i] == 'R':
        A[0].append(i)
    elif S[i] == 'G':
        A[1].append(i)
    else:
        A[2].append(i)

for i in A[0]:
    for j in A[1]:
        for k in A[2]:
            if  (i < j and j < k) or (k < j and j < i):
                if abs(i-j) != abs(j-k):
                    ans += 1
            elif (i < k and k < j) or (j < k and k < i):
                if abs(i-k) != abs(k-j):
                    ans += 1
            elif (j < i and i < k) or (k < i and i < j):
                if abs(j-i) != abs(k-i):
                    ans += 1

print(ans)

Fixed submission:
N = input()
for i in range(3):
  if int(N[i]) == 7:
    print('Yes')
    exit()
print('No')
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
T1 = 0
for _ in range(Q):
  a = list(map(str,input().split()))
  if a[0] == '1':
    T1 += 1
  elif a[0] == '2':
    if ((a[1]=='1')and(T1%2==0)) or ((a[1]=='2')and(T1%2!=0)):
      S = a[2]+S
    else:
      S = S+a[2]

if T1 % 2 == 0:
  print(S)
else:
  print(S[::-1])

Fixed submission:
S = input()
Q = int(input())
T1 = 0
S_left = ''
S_right = ''
for _ in range(Q):
  a = list(map(str,input().split()))
  if a[0] == '1':
    T1 += 1
  elif a[0] == '2':
    if ((a[1]=='1')and(T1%2==0)) or ((a[1]=='2')and(T1%2!=0)):
      S_left = a[2]+S_left
    else:
      S_right = S_right+a[2]
S = S_left+S+S_right
if T1 % 2 == 0:
  print(S)
else:
  print(S[::-1])
Buggy python submission (verdict: Runtime Error):
import math
n,a,b = map(int,input().split())
mod = 10**9+7
ans = pow(2,n,mod)
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7
N = 10**4
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

for i in range(2, N + 1):
    g1.append( (g1[-1]*i) % mod)
    inverse.append( (-inverse[mod % i] * (mod//i)) % mod)
    g2.append( (g2[-1]*inverse[-1]) % mod)
ans = ans-(cmb(n,a,mod)+cmb(n,b,mod))-1
print(ans)

Fixed submission:
N,R = map(int,input().split())
if N >= 10:
  print(R)
else:
  print(R+100*(10-N))
Buggy python submission (verdict: Runtime Error):
n,a,b = map(int,input().split())
mod = 10**9+7
ans = pow(2,n,mod)
def cmb(n,r,mod):
  p,q = 1,1
  r = min(r,n-r)
  for i in range(r):
    p = p*(n - i)%mod
    q = q*(i + 1)%mod
    Y = pow(q,10**9+5,mod)
  return p*Y%mod
ans = ans - cmb(n,a,mod) - cmb(n,b,mod) - 1
print(ans%mod)

Fixed submission:
n,a,b = map(int,input().split())
mod = 10**9+7
ans = pow(2,n,mod)
def cmb(n,r,mod):
  if n == r:
    return 1
  p,q = 1,1
  r = min(r,n-r)
  for i in range(r):
    p = p*(n - i)%mod
    q = q*(i + 1)%mod
    Y = pow(q,10**9+5,mod)
  return p*Y%mod
ans = ans - cmb(n,a,mod) - cmb(n,b,mod) - 1
print(ans%mod)

Buggy python submission (verdict: Runtime Error):
import math
n,a,b = map(int,input().split())
mod = 10**9+7
ans = pow(2,n,mod)
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7
N = 10**4
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

for i in range(2, N + 1):
    g1.append( (g1[-1]*i) % mod)
    inverse.append( (-inverse[mod % i] * (mod//i)) % mod)
    g2.append( (g2[-1]*inverse[-1]) % mod)
ans = ans-(cmb(n,a,mod)+cmb(n,b,mod))-1
print(ans)

Fixed submission:
n,a,b = map(int,input().split())
mod = 10**9+7
ans = pow(2,n,mod)
def cmb(n,r,mod):
  if n == r:
    return 1
  p,q = 1,1
  r = min(r,n-r)
  for i in range(r):
    p = p*(n - i)%mod
    q = q*(i + 1)%mod
    Y = pow(q,10**9+5,mod)
  return p*Y%mod
ans = ans - cmb(n,a,mod) - cmb(n,b,mod) - 1
print(ans%mod)

Buggy python submission (verdict: Time Limit Exceeded):
import math
n,a,b = map(int,input().split())
mod = 10**9+7
ans = pow(2,n,mod)
def cmb(n,r,mod):
  a = math.factorial(n)%mod
  b = math.factorial(r)%mod
  c = math.factorial(n-r)%mod
  return a//(b*c)%mod
ans = ans-(cmb(n,a,mod)+cmb(n,b,mod))-1
print(ans)

Fixed submission:
n,a,b = map(int,input().split())
mod = 10**9+7
ans = pow(2,n,mod)
def cmb(n,r,mod):
  if n == r:
    return 1
  p,q = 1,1
  r = min(r,n-r)
  for i in range(r):
    p = p*(n - i)%mod
    q = q*(i + 1)%mod
    Y = pow(q,10**9+5,mod)
  return p*Y%mod
ans = ans - cmb(n,a,mod) - cmb(n,b,mod) - 1
print(ans%mod)
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
p = list(map(int,input().split()))
max = 0
for i in range(N-K+1):
  r = 0
  for j in range(K):
    r += p[i+j] + 1
  if max < r/2:
    max = r/2
print(max)

Fixed submission:
N,K = map(int,input().split())
p = list(map(int,input().split()))
max = 0
r = 0
for i in range(K):
  max = max + p[i] + 1
  r = r + p[i] + 1
  
for j in range(N-K):
  r = r -p[j] + p[K+j]
  if max < r:
    max = r
    
print(max/2)
Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
A = [list(input().split())for i in range(M)]
ans = 0
pen = 0
r = []
for i in range(len(A)):
  if A[i][1] == 'AC':
    r.append(A[i][0])
R = list(set(r))
ans = len(R)
for _ in range(ans):
  for j in range(len(A)):
    if A[j][0] == R[0] and A[j][1] == 'AC':
      del R[0]
      break
    if A[j][0] == R[0] and A[j][1] == 'WA':
      pen+=1
print(ans,pen)


Fixed submission:
N,M = map(int,input().split())
ans = [0]*N
pen = [0]*N
for _ in range(M):
  p,S = input().split()
  P = int(p)
  if ans[P-1] == 1:
    continue
  elif ans[P-1] == 0:
    if S == 'AC':
      ans[P-1] += 1
    elif S == 'WA':
      pen[P-1] += 1
      
A = 0
B = 0 
for i in range(N):
  if ans[i] == 1:
    A += 1
    B += pen[i]
print(A,B)

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
A = [list(input().split())for i in range(M)]
ans = 0
pen = 0
r = []
for i in range(len(A)):
  if A[i][1] == 'AC':
    r.append(A[i][0])
R = list(set(r))
ans = len(R)
for _ in range(ans):
  for j in range(len(A)):
    if A[j][0] == R[0] and A[j][1] == 'AC':
      del R[0]
      break
    if A[j][0] == R[0] and A[j][1] == 'WA':
      pen+=1
print(ans,pen)

Fixed submission:
N,M = map(int,input().split())
ans = [0]*N
pen = [0]*N
for _ in range(M):
  p,S = input().split()
  P = int(p)
  if ans[P-1] == 1:
    continue
  elif ans[P-1] == 0:
    if S == 'AC':
      ans[P-1] += 1
    elif S == 'WA':
      pen[P-1] += 1
      
A = 0
B = 0 
for i in range(N):
  if ans[i] == 1:
    A += 1
    B += pen[i]
print(A,B)
Buggy python submission (verdict: Runtime Error):
K , X = int(input.split)
if K*500 == X:
  print(Yes)
elif:
  print(No)
  

Fixed submission:
K,X = map(int,input().split())
if K*500>=X:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
N = int(input())
for i in range(9):
  for j in range(9):
    if (i+1)*(j+1)==N:
      print("yes")
      exit()
print("No")

Fixed submission:
A,B = map(int,input().split())
if A<=9 and B<=9:
  print(A*B)
else:
  print(-1)
Buggy python submission (verdict: Runtime Error):
n,w = map(int,input().split())
v = [list(map(int,input().split())) for _ in range(n)]
dp = [[0]*(w+1) for _ in range(n+1)]
for i in range(1,n+1):
  for j in range(w+1):
    if j < v[i-1][0]:
      dp[i][j] = dp[i-1][j]
    else:
      dp[i][j] = max(dp[i-1][j],dp[i-1][j-v[i-1][0]]+v[i-1][1])
print(dp[n][w])

Fixed submission:
N = int(input())
h = list(map(int,input().split()))
h = [0] + h
dp = [0]*(N+1)
dp[2] = abs(h[2]-h[1])
for i in range(3,N+1):
  dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
print(dp[N])

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**9)
N,W = map(int,input().split())
w = []
v = []
for i in range(N):
  w_,v_ = map(int,input().split())
  w.append(w_)
  v.append(v_)

dp = [[0]*(W+1) for _ in range(N+1)]

def memo(i,j):
  if dp[i][j]:
    return dp[i][j]
  if i == N:
    dp[i][j] = 0
  elif w[i] > j:
    dp[i][j] = memo(i+1,j)
  else:
    dp[i][j] = max(memo(i+1,j),memo(i+1,j-w[i])+v[i])
  return dp[i][j] 
print(memo(0,W))

Fixed submission:
N = int(input())
h = list(map(int,input().split()))
h = [0] + h
dp = [0]*(N+1)
dp[2] = abs(h[2]-h[1])
for i in range(3,N+1):
  dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
print(dp[N])

Buggy python submission (verdict: Runtime Error):
N,W = map(int,input().split())
w = []
v = []
for i in range(N):
  w_,v_ = map(int,input().split())
  w.append(w_)
  v.append(v_)

dp = [[0]*(W+1) for _ in range(N+1)]

def memo(i,j):
  if dp[i][j]:
    return dp[i][j]
  if i == N:
    dp[i][j] = 0
  elif w[i] > j:
    dp[i][j] = memo(i+1,j)
  else:
    dp[i][j] = max(memo(i+1,j),memo(i+1,j-w[i])+v[i])
  return dp[i][j] 
print(memo(0,W))

Fixed submission:
N = int(input())
h = list(map(int,input().split()))
h = [0] + h
dp = [0]*(N+1)
dp[2] = abs(h[2]-h[1])
for i in range(3,N+1):
  dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
print(dp[N])
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
h = list(map(int,input().split()))
h = [0] + h
dp = [float('inf')]*(N+1)
dp[0] = 0
dp[1] = 0
dp[2] = abs(h[2]-h[1])
for i in range(3,N+1):
  p = 1
  while p <= K and i-p > 0:
    dp[i] = min(dp[i],dp[i-p]+abs(h[i]-h[i-p]))
    p += 1
print(dp[N])

Fixed submission:
N,K = map(int,input().split())
h = list(map(int,input().split()))
h = [0] + h
dp = [float('inf')]*(N+1)
dp[0] = 0
dp[1] = 0
dp[2] = abs(h[2]-h[1])
for i in range(3,N+1):
  p = 1
  while p <= K and i-p > 0:
    dp[i] = min(dp[i],dp[i-p]+abs(h[i]-h[i-p]))
    p += 1
print(dp[N])
Buggy python submission (verdict: Runtime Error):
abc='abcdefghijklmnopqrstuvwxyz'
s=raw_input().strip()
isi=dict()
for l in s:


Fixed submission:
abc='abcdefghijklmnopqrstuvwxyz'
s=raw_input().strip()
isi=set()
for l in s:
    if l not in isi:
        isi.add(l)
for l in abc:
    if l not in isi:
        print l
        break
else:
    print 'None'
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, raw_input().split())
paths = {}
for m in range(M):
	path = map(int, raw_input().split())
	a_p = paths.get(path[0],[])
	b_p = paths.get(path[1],[])
	a_p.append(path[1])
	b_p.append(path[0])
	paths[path[0]] = a_p
	paths[path[1]] = b_p

visited = [False] * (N+1)

visited[0] = True
to_visit = [1]
signposts = [None] * (N+1)
while len(to_visit) > 0:
	curr = to_visit.pop(0)
	if visited[curr]:
		continue
	else:
		path = paths[curr]
		for p in path:
			if signposts[p] == None:
				signposts[p] = curr
				to_visit.append(p)
		visited[curr] = True
all_visited = all(visited)

if all_visited:
	print 'Yes'
	for s in range(2,len(signposts)):
		print signposts[s]
else:
	print 'No'




Fixed submission:
N, M = map(int, raw_input().split())
paths = {}
for m in range(M):
	path = map(int, raw_input().split())
	a_p = paths.get(path[0],[])
	b_p = paths.get(path[1],[])
	a_p.append(path[1])
	b_p.append(path[0])
	paths[path[0]] = a_p
	paths[path[1]] = b_p

visited = [False] * (N+1)

visited[0] = True
to_visit = [1]
signposts = [None] * (N+1)
i = 0
while len(to_visit) > i:
	curr = to_visit[i]
	if visited[curr]:
		i += 1
	else:
		path = paths[curr]
		for p in path:
			if signposts[p] == None:
				signposts[p] = curr
				to_visit.append(p)
		visited[curr] = True
		i += 1
all_visited = all(visited)

if all_visited:
	print 'Yes'
	for s in range(2,len(signposts)):
		print signposts[s]
else:
	print 'No'
Buggy python submission (verdict: Runtime Error):
S = raw_input()
if S = 'ABC':
	print 'ARC'
else:
	print 'ABC'

Fixed submission:
S = raw_input()
if S == 'ABC':
	print 'ARC'
else:
	print 'ABC'
Buggy python submission (verdict: Time Limit Exceeded):
N = int(raw_input())
A = map(int, raw_input().split())

plus = [A[i] + i for i in range(N)]
minus = [j - A[j] for j in range(N)]

count = 0
for i in range(N):
	h = A[i]
	for j in range(i+h+1, N):
		if plus[i] == minus[j]:
			count += 1
print count

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

x_occurance = {}
minus = []
for i in range(N):
	p = A[i] + i
	m = i - A[i]
	x_occurance[p] = x_occurance.get(p, 0) + 1
	minus.append(m)

count = 0
for i in range(N):
	count += x_occurance.get(minus[i], 0) 

print count

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

count = 0
for i in range(N):
	h = A[i]
	for j in range(i+h+1, N):
		if j - i == h + A[j]:
			count += 1
print(count)

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

x_occurance = {}
minus = []
for i in range(N):
	p = A[i] + i
	m = i - A[i]
	x_occurance[p] = x_occurance.get(p, 0) + 1
	minus.append(m)

count = 0
for i in range(N):
	count += x_occurance.get(minus[i], 0) 

print count

Buggy python submission (verdict: Time Limit Exceeded):
N = int(raw_input())
A = map(int, raw_input().split())

count = 0
for i in range(N):
	h = A[i]
	for j in range(i+h+1, N):
		if j - i == h + A[j]:
			count += 1
print count

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

x_occurance = {}
minus = []
for i in range(N):
	p = A[i] + i
	m = i - A[i]
	x_occurance[p] = x_occurance.get(p, 0) + 1
	minus.append(m)

count = 0
for i in range(N):
	count += x_occurance.get(minus[i], 0) 

print count

Buggy python submission (verdict: Time Limit Exceeded):
N = int(raw_input())
A = map(int, raw_input().split())

count = 0
for i in range(N):
	for j in range(i+1, N):
		if j - i == A[i] + A[j]:
			count += 1
print count

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

x_occurance = {}
minus = []
for i in range(N):
	p = A[i] + i
	m = i - A[i]
	x_occurance[p] = x_occurance.get(p, 0) + 1
	minus.append(m)

count = 0
for i in range(N):
	count += x_occurance.get(minus[i], 0) 

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

print(max(0, a-2*b)
      

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

print(max(0, a-2*b))
Buggy python submission (verdict: Runtime Error):
x, y, a, b, c = map(int, input().split())

A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A = sorted(A)
B = sorted(B)
C = sorted(C)

t = 0
s = 0
A = A[-x:]
B = B[-y:]

for i in range(c):
    if A[t] < B[s] and A[t] < C[i]:
        A[t] = C[i]
        t += 1
    elif B[s] < A[t] and B[s] < C[i]:
        B[s] = C[i]
        s += 1

print(sum(A[-x:]) + sum(B[-y:]))

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

A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A = sorted(A)
B = sorted(B)
C = sorted(C)

t = 0
s = 0

A = A[-x:]
B = B[-y:]

C.extend(A)
C.extend(B)
C = sorted(C)

print(sum(C[-x-y:]))
Buggy python submission (verdict: Time Limit Exceeded):

n = int(input())
B = ['3', '5', '7']
count=0
ans=0
for i in range(357, min(n+1, 777777753), 2):
    A = list(str(i))
    C = list(set(A))
    C.sort()
    if(C==B):
        count+=1
print(count)


Fixed submission:
import itertools
a = int(input())

A = ['0', '3', '5', '7']
B = []
count=0
for i, j, k, l, m, n, o, p, q, r in itertools.product(A, A, A, A, A, A, A, A, A, A):
    ans= i + j + k + l + m + n + o + p + q + r
    ans = int(ans)
    if(ans <=a):
        ans = list(str(ans))
        if('0' not in ans and '3' in ans and '5' in ans and '7' in ans):
            count+=1
    else:
        break
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

ans = 1
while(n>0):
    ans*=n
    n -= 1

print(ans%(1000000000+7))

Fixed submission:
n = int(input())

ans = 1
while(n>0):
    ans*=n
    ans = ans%(1000000000+7)
    n -= 1

print(ans)
Buggy python submission (verdict: Runtime Error):
import math
a,b,h,m=map(int,input().split())
q=h*30+m*0.5
w=m*6
cosa=math.cos(math.radians(q-w))
print((a**2+b**2-2*a*b*cos)**0.5)

Fixed submission:
import math
a,b,h,m=map(int,input().split())
q=h*30+m*0.5
w=m*6
cosa=math.cos(math.radians(q-w))
print((a**2+b**2-2*a*b*cosa)**0.5)
Buggy python submission (verdict: Runtime Error):
A,B,C,D=map(int,input().split())
while True:
    C-=B
    if c<=0:
        print("Yes")
        break
    A-=D
    if a<=0:
        print("No")
        break

Fixed submission:
A,B,C,D=map(int,input().split())
while True:
    C-=B
    if C<=0:
        print("Yes")
        break
    A-=D
    if A<=0:
        print("No")
        break
Buggy python submission (verdict: Time Limit Exceeded):
import math


li = list(map(int,input().split()))

def main():

	max = 0
	for i in range(li[2]+1):
		l = (math.floor((li[0]*i)/li[1]) - li[0]*(math.floor(i/li[1])))
		if l > max:
			max = l
	return(print(max))

      

main()

Fixed submission:
import math
 
A, B, N = map(int, input().split())
 
x = 0
if N < B:
    x = N
else:
    x = B - 1
 
print(math.floor(A * x / B) - A * math.floor(x / B))

Buggy python submission (verdict: Time Limit Exceeded):

import math


li = list(map(int,input().split()))

def main():

	x = []
	for i in range(li[2]+1):
		x.append(math.floor((li[0]*i)/li[1]) - li[0]*(math.floor(i/li[1])))
	max = 0
	for l in x:
		if l>max:
			max = l
	return(print(max))

      

main()

Fixed submission:
import math
 
A, B, N = map(int, input().split())
 
x = 0
if N < B:
    x = N
else:
    x = B - 1
 
print(math.floor(A * x / B) - A * math.floor(x / B))
Buggy python submission (verdict: Runtime Error):
N,A,B,C,D = map(int, raw_input().split())
S = raw_input()
i = 1
flagskip = 0
flagskip2 = 0
flagerror = 0
flags = 0
flagstop = 0
flagstop2 = 0
for c in S:
	if(flagstop2 == 1):
		if(c =='#'):
			flagstop += 1
		flagstop2 = 0
	if(i <= A):
		i += 1
		continue
	elif(i == B or (i == D and D < C)):
		if(flags == 1):
			flagstop += 1
		else:
			flagstop2 = 1
	if(c == '#'):
		if(flags == 1):
			flagerror = 1
			break
		flags = 1
		flagskip2 = 0
	else:
		if(flagskip2 == 1):
			flagskip = 1
		elif(flags == 0 and flagskip == 0 and i > B-1 and i < D+1):
			flagskip2 = 1
		flags = 0
	if(i = max(C,D)):
		break
	i += 1
if(flagstop == 2 and flagskip == 0):
	flagerror = 1
if(flagerror == 0):
	print("Yes")
else:
	print("No")

Fixed submission:
N,A,B,C,D = map(int, raw_input().split())
S = raw_input()
i = 1
flagskip = 0
flagskip2 = 0
flagerror = 0
flags = 0
flagstop = 0
flagstop2 = 0
for c in S:
	if(flagstop2 == 1):
		if(c =='#'):
			flagstop += 1
		flagstop2 = 0
	if(i <= A):
		i += 1
		continue
	elif(i == B or (i == D and D < C)):
		if(flags == 1):
			flagstop += 1
		else:
			flagstop2 = 1
	if(c == '#'):
		if(flags == 1):
			flagerror = 1
			break
		flags = 1
		flagskip2 = 0
	else:
		if(flagskip2 == 1):
			flagskip = 1
		elif(flags == 0 and flagskip == 0 and i > B-1 and i < D+1):
			flagskip2 = 1
		flags = 0
	if(i == max(C,D)):
		break
	i += 1
if(flagstop == 2 and flagskip == 0):
	flagerror = 1
if(flagerror == 0):
	print("Yes")
else:
	print("No")
Buggy python submission (verdict: Runtime Error):
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
N = input()
A = map(int, raw_input().split())
B = []
for i in range(N):
	t = 0
	for j in range(N):
		if(i == j):
			continue
		else:
			if(t == 0):
				t = A[j]
			else:
				t = gcd(t,A[j])
		if(t == 1):
			break
	B.append(t)
print(max(B))

Fixed submission:
A,B,T = map(int, raw_input().split())
print((T/A)*B)
Buggy python submission (verdict: Runtime Error):
DIV = 998244353

N = input()
a = []
for i in range(N):
    a.append(input())
a.sort()
suma = sum(a)
dp = [[0] * (suma+1) for i in range(N)]
dp[0][0] = 2
dp[0][a[0]] = 1
allc = 3
for i in range(1,N):
	allc = allc*3
	k = a[i]
	for j in range(sum(a[:i+1])+1):
		if(j < k):
			dp[i][j] = dp[i-1][j]*2
		else:
			dp[i][j] = dp[i-1][j]*2+dp[i-1][j-k]
allc = allc - sum(dp[N-1][suma-suma/2:])*3
if(suma%2 == 0):
	dp2 = [[0] * (suma+1) for i in range(N)]
	dp2[0][0] = 1
	dp2[0][a[0]] = 1 
	for i in range(1,N):
		k = a[i]
		for j in range(sum(a[:i+1])+1):
			if(j < k):
				dp2[i][j] = dp2[i-1][j]
			else:
				dp2[i][j] = dp2[i-1][j]+dp2[i-1][j-k]
	allc += dp2[N-1][suma/2]*3
print(allc%DIV)

Fixed submission:
N = input()
S = raw_input()
flag1 = 0
a = 0
count = [0,0]
count2 = []
count3 = []
for c in S:
	if(c == "#"):
		if(flag1 == 1):
			flag1 = 0
			count2.append(count[0])
			count3.append(count[1])
		count[0] += 1
	else:
		count[1] += 1
		flag1 = 1
countf = []
for i in range(len(count2)):
	countf.append(count2[i] + count[1] - count3[i])
countf.append(N - count[0])
countf.append(N - count[1])
print(min(countf))
Buggy python submission (verdict: Time Limit Exceeded):
x,y,z,k = map(int, raw_input().split())
a = map(int, raw_input().split())
b = map(int, raw_input().split())
c = map(int, raw_input().split())
s = []
a.sort(reverse = True)
b.sort(reverse = True)
c.sort(reverse = True)
if(x > 54 & y > 54 & z > 54):
	ax = a[0] - a[54]
	bx = b[0] - b[54]
	cx = c[0] - c[54]
	for n in range(x):
		if(a[0] - a[n] > bx + cx):
			x = n
			break;
	for n in range(y):
		if(b[0] - b[n] > ax + cx):
			y = n
			break;
	for n in range(z):
		if(c[0] - c[n] > bx + ax):
			z = n
			break;
for ka in range(x):
    for kb in range(y):
		for kc in range(z):
			s.append(a[ka]+b[kb]+c[kc])
s.sort(reverse = True)
for n in range(k):
	print(s[n])

Fixed submission:
x,y,z,k = map(int, raw_input().split())
a = map(int, raw_input().split())
b = map(int, raw_input().split())
c = map(int, raw_input().split())
s = []
a.sort(reverse = True)
b.sort(reverse = True)
c.sort(reverse = True)
for ka in range(x):
    for kb in range(y):
			s.append(a[ka]+b[kb])
s.sort(reverse = True)
p = 3000
if(x * y < 3000):
	p = x * y
t = []
for n in range(p):
	for m in c:
		t.append(s[n] + m)
t.sort(reverse = True)
for n in range(k):
	print(t[n])

Buggy python submission (verdict: Time Limit Exceeded):
x,y,z,k = map(int, raw_input().split())
a = map(int, raw_input().split())
b = map(int, raw_input().split())
c = map(int, raw_input().split())
s = []
for ka in a:
    for kb in b:
		for kc in c:
			s.append(ka+kb+kc)
for n in range(k):
	print(max(s))
	s.remove(max(s))
	

Fixed submission:
x,y,z,k = map(int, raw_input().split())
a = map(int, raw_input().split())
b = map(int, raw_input().split())
c = map(int, raw_input().split())
s = []
a.sort(reverse = True)
b.sort(reverse = True)
c.sort(reverse = True)
for ka in range(x):
    for kb in range(y):
			s.append(a[ka]+b[kb])
s.sort(reverse = True)
p = 3000
if(x * y < 3000):
	p = x * y
t = []
for n in range(p):
	for m in c:
		t.append(s[n] + m)
t.sort(reverse = True)
for n in range(k):
	print(t[n])