Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N,A,B=map(int,input().split())
count=0
for i in range(N):
    k=i%(A+B)
    if k<A:
        count+=1
print(count)

Fixed submission:
N,A,B=map(int,input().split())
count=0
k=N%(A+B)
add=0
if k<A:
    add=k
else:
    add=A
print(N//(A+B)*A+add)
Buggy python submission (verdict: Runtime Error):
s=input()
t=input()
a=0
for x in range(s):
  if s[x]!=t[x]:
    a+=1
print(a)

Fixed submission:
s=input()
t=input()
a=0
for x in range(len(s)):
  if s[x]!=t[x]:
    a+=1
print(a)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
a.append("0")
t=0
for i in range(n):
    if a[i+1]!="0":
     if a[i + 1] - a[i] != 1:
            t+=1
            a.pop(i)
    else:
        break
print(t)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
i=1
t=0
for x in a:
  if x!=i:
    t+=1
  else:
    i+=1
if len(a)==t:
  t=-1
print(t)
Buggy python submission (verdict: Time Limit Exceeded):
n,k,q = (int(x) for x in input().split())
p = [k]*n
for x in range(q):
  for y in range(len(p)):
    p[y] -= 1
  s = int(input())
  p[s-1] += 1
for z in range(len(p)):
  if p[z] > 0:
    print("Yes")
  else:
    print("No")

Fixed submission:
n,k,q = (int(x) for x in input().split())
p = [k-q]*n
for x in range(q):
  s = int(input())
  p[s-1] += 1
for z in range(len(p)):
  if p[z] > 0:
    print("Yes")
  else:
    print("No")
Buggy python submission (verdict: Runtime Error):
s,x=(int(y) for y in input().split())
l=list(map(int, input().split()))
a=0
c=0
for y in range(s+1):
	if x>=c:
		a+=1
		c+=l[y]
	else:
		break
print(a)

Fixed submission:
n,x=map(int,input().split())
l=list(map(int,input().split()))
c=1
t=0
for s in l:
  t+=s
  if t<=x:
    c+=1
print(c)
Buggy python submission (verdict: Runtime Error):
def main():
    N = int(input())
    total = 0
    while N > 0:
        total += N % 10
        N = int(N / 10)
    if total % 9 == 0:
        print('Yes')
    else:
        print('No')
main()

Fixed submission:
def main():
    N = input()
    total = 0
    for i in range(len(N)):
        total += int(N[i])
    if total % 9 == 0:
        print('Yes')
    else:
        print('No')
main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N, K = map(int, input().split(' '))
    A = list(map(int, input().split(' ')))

    tmp1 = 1
    tmp2 = 1
    for i in range(K):
        tmp1 *= A[i]

    for i in range(1, N - K + 1):
        for j in range(i, i + K):
            tmp2 *= A[j] 
        if tmp1 < tmp2:
            print('Yes')
        else:
            print('No')
        tmp1 = tmp2
        tmp2 = 1
main()

Fixed submission:
def main():
    N, K = map(int, input().split(' '))
    A = list(map(int, input().split(' ')))

    for i in range(N - K):
        if A[i] < A[i + K]:
            print('Yes')
        else:
            print('No')
main()
Buggy python submission (verdict: Runtime Error):
def main():
    N = int(input())
    AC = 0
    WA = 0
    TLE = 0
    RE = 0
    for i in range(N):
        St = input()
        if St == 'AC':
            AC += 1
        elif St == 'WA':
            WA += 1
        elif St == 'TLE':
            TLE += 1
        elif St == 'RE':
            RE += 1
        else:

    print('AC x ' + str(AC))
    print('AC x ' + str(WA))
    print('AC x ' + str(TLE))
    print('AC x ' + str(RE))
main()

Fixed submission:
def main():
    N = int(input())
    AC = 0
    WA = 0
    TLE = 0
    RE = 0
    for i in range(N):
        St = input()
        if St == 'AC':
            AC += 1
        elif St == 'WA':
            WA += 1
        elif St == 'TLE':
            TLE += 1
        elif St == 'RE':
            RE += 1
        else:
            Er += 1
    print('AC x', AC)
    print('WA x', WA)
    print('TLE x', TLE)
    print('RE x', RE)
main()
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = input()
A = A.split(' ')
X = 1
for i in range(N):
    X *= int(A[i])
if X > 10**18:
    print('-1')
else:
    print(X)

Fixed submission:
def main():
    N = int(input())
    A = input()
    A = A.split(' ')

    for i in A:
        if i == '0':
            print(0)
            return

    X = 1
    for i in A:
        X *= int(i)
        if X > 1000000000000000000:
            print(-1)
            return
    print(X)
main()
Buggy python submission (verdict: Runtime Error):
def main():
    N, K = map(int, input().split(' '))
    d = [0] * N
    total = 0
    for i in range(K):
        A = input()
        B = list(map(int, input().split(' ')))
        for j in B:
            d[j - 1] = 1
    for j in range(K):
        if d[j] == 0:
            total += 1
    print(total)
main()

Fixed submission:
def main():
    N, K = map(int, input().split(' '))
    d = [0] * N
    total = 0
    for i in range(K):
        A = input()
        B = list(map(int, input().split(' ')))
        for j in B:
            d[j - 1] = 1
    for j in range(N):
        if d[j] == 0:
            total += 1
    print(total)
main()
Buggy python submission (verdict: Runtime Error):
N = int( input())
A = list( map( int, input().split()))
 
mod = 10 ** 9 + 7
 
total = sum( A )
ret = 0
for a in A:
  ret = ( ret + ( total - a ) * a  ) 
print( ( ret // 2 ) % mod )

Fixed submission:
D, S, T = map( int, input().split() )

if D - S * T <= 0:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
X, K, D = map( int, input().split())
 
Y = X // D
if K <= Y:
  print( min( abs( X - K * D ) , abs( X + K * D ) ))
else:
  if ( K - Y ) % 2 == 0:
    print( min( abs( X - Y * D ) , abs( X + Y * D ) ),
           min( abs( X - ( Y - 2 ) * D ), abs( X - ( Y + 2 ) * D ),
                abs( X + ( Y - 2 ) * D ), abs( X + ( Y + 2 ) * D )) )
  else:
    print( min( abs( X - ( Y - 1 ) * D ), abs( X - ( Y + 1 ) * D ),
                abs( X + ( Y - 1 ) * D ), abs( X + ( Y + 1 ) * D )) )


Fixed submission:
s = input()

if s.count("R") in [0,1,3]:
  print( s.count("R") )
else:
  if s == "RSR":
    print(1)
  else:
    print(2)
Buggy python submission (verdict: Runtime Error):
S = input()
T = input()

ret = 0
for i in len(S):
  if S[i] != T[i]:
    ret += 1
print( ret )

Fixed submission:
S = input()
T = input()
 
ret = 0
for i in range(len(S)):
  if S[i] != T[i]:
    ret += 1
print( ret )
Buggy python submission (verdict: Runtime Error):
n = int( input() )
 
l = []
a = 97
alp = 26
k = 1
n2 = n
while n >= k + 1:
  l.append( ( n2 - 1 ) % alp  )
  n2 = ( n2 - ( n2 - 1 ) % alp ) // alp
  k *= alp
ret = ""
for c in reversed( l ):
  ret += chr( a + c )
print( ret )

Fixed submission:
a = input()

if a.isupper():
  print( "A" )
else:
  print("a")
Buggy python submission (verdict: Runtime Error):
N, K = map( int, input() )

p = sorted( list( map( int, input().split() ) ) )

print( sum( p[ : K ] ) )


Fixed submission:
N, K = map( int, input().split() )
 
p = sorted( list( map( int, input().split() ) ) )
 
print( sum( p[ : K ] ) )
Buggy python submission (verdict: Runtime Error):
n = int( input().split() )
A = list( map( int, input().split()))

if 0 in A:
  print( 0 )
else:
  ret = 1
  for a in A:
    ret *= a
    if ret > 10 ** 18:
      ret = -1
      break
  print( ret )


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

if 0 in A:
  print( 0 )
else:
  ret = 1
  for a in A:
    ret = ret * a
    if ret > 10 ** 18:
      ret = -1
      break
  print( ret )

Buggy python submission (verdict: Time Limit Exceeded):
n = int( input() )
a = list( map( int, input().split() ) )
 
ret = 1
if 0 in a:
  ret = 0
else:
  for ai in a:
    ret = ret * ai
    if ret > 10 ** 18:
      ret = -1
 
print( ret)

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

if 0 in A:
  print( 0 )
else:
  ret = 1
  for a in A:
    ret = ret * a
    if ret > 10 ** 18:
      ret = -1
      break
  print( ret )

Buggy python submission (verdict: Time Limit Exceeded):
n = int( input() )
a = list( map( int, input().split() ) )

ret = 1
for ai in a:
  ret = ret * ai
  if ret == 0:
    ret = 0
    break
    
if ret > 10 ** 18:
  ret = -1

print( ret)

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

if 0 in A:
  print( 0 )
else:
  ret = 1
  for a in A:
    ret = ret * a
    if ret > 10 ** 18:
      ret = -1
      break
  print( ret )

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

ret = 1
for a in A:
  ret *= a
  if a == 0:
    ret = 0
    break
  if a > 10 ** 18:
    ret = -1
    break
print( ret )

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

if 0 in A:
  print( 0 )
else:
  ret = 1
  for a in A:
    ret = ret * a
    if ret > 10 ** 18:
      ret = -1
      break
  print( ret )
Buggy python submission (verdict: Runtime Error):
a, b = input().split()
a = int( a )
b = b * 100

print( a * b // 100 )


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

b = b.replace(".","")

a = int( a )
b = int( b )
print( a * b // 100 )

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

print( math.floor( a * b ) )

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

b = b.replace(".","")

a = int( a )
b = int( b )
print( a * b // 100 )
Buggy python submission (verdict: Runtime Error):
n = int( input() )
A = []
B = []

for i in range( n ):
  a, b = map( int, input().split() )
  A.append( a )
  B.append( b )

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

if n % 2 == 0:
  i = n // 2
  print(( B[ i ] + B[ i - 1 ] ) - ( A[ i ] + A [ i - 1 ] ) + 1 )
else:
  i = ( n + 1 ) // 2 - 1
  print( B[ i ] - A[ i ] + 1 )


Fixed submission:
n = int( input())
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
fact = factorization( n )

cnt = 0
for f in fact:
  if f[0] == 1:
    continue
  fa = f[ 1 ]
  fa -= 1
  i = 2
  while fa >= 0:
    cnt += 1
    fa -= i
    i += 1
print( cnt )
Buggy python submission (verdict: Runtime Error):
A, B, C, K = map( int, input().split())
ret = min( A, K )
if A < K:
  ret -= max( 0, K - A - B )
print( ret )

Fixed submission:
S = input()
T = input()

if S == T[:len(S)]:
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Runtime Error):
S, T = input().split()

if S == T[:len(S)]:
  print("Yes")
else:
  print("No")

Fixed submission:
S = input()
T = input()

if S == T[:len(S)]:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
A, B, C, K = map( int, input().split())

l = [1] * A
l += [0] * B
l += [-1] * C

print( sum(l[:K]) )

Fixed submission:
A, B, C, K = map( int, input().split())
ret = min( A, K )
if A < K:
  ret -= max( 0, K - A - B )
print( ret )
Buggy python submission (verdict: Runtime Error):
n, a, b = map( int, input().split() )

mod = 10 ** 9 + 7

def comb( n, r, mod ):
  c = 1
  m = 1
  r = min( n - r, r )
  for i in range( r ):
    c = c * ( n - i ) % mod
    m = m * ( i + 1 ) % mod
  return c * pow( m, mod - 2, mod ) % mod

N = pow( 2, n, mod )
A = comb( n, a )
B = comb( n, b )
print(( N - A - B ) % mod )

Fixed submission:
N, A, B = map( int, input().split() )
MOD = 10 ** 9 + 7

def comb( n, r ):
  c = 1
  m = 1
  r = min( r, n - r )
  for i in range( r ):
    c = ( c * ( n - i )) % MOD
    m = ( m * ( i + 1 )) % MOD 
  return c * pow( m, MOD - 2, MOD ) % MOD

n = pow( 2, N, MOD ) - 1
a = comb( N, A )
b = comb( N, B )
print(( n - a - b ) % MOD )
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
X = input()
MAX = 2 * (10 ** 5) + 1

base = [0] * (MAX+1)
for num in range(1, MAX+1):
  cnt = 0
  bin_num = bin(num)[2:]
  for j in bin_num:
    cnt += int(j)
  p = num % cnt
  base[num] = base[p]+1

for i in range(N):
  if(X[i] == '0'):
    p = X[:i] + '1' + X[i+1:]
  else:
    p = X[:i] + '0' + X[i+1:]
  cnt = 0
  for j in range(N):
    cnt += int(p[j])
  x = int(p, 2)
  if(x <= MAX):
    print(base[x])
  else:
    print(base[x%cnt]+1)

Fixed submission:
N = int(input())
X = input()
MAX = 2 * (10 ** 5) + 1

base = [0] * (MAX+1)
for num in range(1, MAX+1):
  cnt = 0
  bin_num = bin(num)[2:]
  for j in bin_num:
    cnt += int(j)
  p = num % cnt
  base[num] = base[p]+1

xcnt = 0
for i in range(N):
  xcnt += int(X[i])

#mod xnt+1  
X0to1 = [1] * N
X0to1sum = 0
k = 1
for i in range(N-1, -1, -1):
  X0to1[i] = k % (xcnt+1)
  X0to1sum += X0to1[i] * int(X[i])
  k = (k*2)%(xcnt+1)


  
#mod xnt-1
X1to0 = [0] * N
X1to0sum = 0
if(xcnt >= 2):
  k = 1
  for i in range(N-1, -1, -1):
    X1to0[i] = k % (xcnt-1)
    X1to0sum += X1to0[i] * int(X[i])
    k = (k*2)%(xcnt-1)


for i in range(N):
  if(X[i] == '0'):
    print(base[(X0to1sum + X0to1[i])%(xcnt+1)]+1)
  else:
    if(xcnt >= 2):
      print(base[(X1to0sum - X1to0[i])%(xcnt-1)]+1)
    else:
      print(0)
Buggy python submission (verdict: Time Limit Exceeded):
MAX = 10**6
N = int(input())
A = list(map(int, input().split()))
B = [0] * (MAX+1)
for i in range(N):
  B[A[i]] += 1
L = [0] * (MAX+1)
for i in range(N):
  k = A[i]
  tmp = 2*k
  while(tmp <= MAX):
    L[tmp] = 1
    tmp += k

ans = 0
for i in range(N):
  if(B[A[i]] == 1 and L[A[i]] == 0):
    ans += 1
print(ans)

Fixed submission:
MAX = 10**6
N = int(input())
A = list(map(int, input().split()))
B = [0] * (MAX+1)
for i in range(N):
  B[A[i]] += 1
L = [0] * (MAX+1)
for k in range(MAX+1):
  if(B[k] >= 1 and L[k] == 0):
    tmp = 2*k
    while(tmp <= MAX):
      L[tmp] = 1
      tmp += k

ans = 0
for i in range(N):
  if(B[A[i]] == 1 and L[A[i]] == 0):
    ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list()
B = list()
for i in range(N):
  a, b = map(int, input().split())
  A.append(a)
  B.append(b)
  
A.sort()
B.sort()

if(N%2==1):
  x = A[(N-1)//2]
  y = B[(N-1)//2]
  print(y-x+1)
else:
  x = A[(N//2)+1] + A[N//2]
  y = B[(N//2)+1] + B[N//2]
  print(y-x+1)

Fixed submission:
N = int(input())
A = list()
B = list()
for i in range(N):
  a, b = map(int, input().split())
  A.append(a)
  B.append(b)
  
A.sort()
B.sort()

if(N%2==1):
  x = A[(N-1)//2]
  y = B[(N-1)//2]
  print(y-x+1)
else:
  x = A[(N//2)-1] + A[N//2]
  y = B[(N//2)-1] + B[N//2]
  print(y-x+1)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(N):
  for j in range(A[i], N):
    if(A[i] + A[j] == j-i):
      ans += 1
print(ans)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
ans = 0
L = [0] * N
R = list()
for i in range(N):
  R.append(i-A[i])
  if(i+A[i]<=N-1):
    L[i+A[i]] += 1
for r in R:
  if(r > 0):
    ans += L[r]
print(ans)
Buggy python submission (verdict: Runtime Error):
N, M, Q = map(int, input().split())
check = list()
for i in range(Q):
  check.append(list(map(int, input().split())))
ans = 0

for i1 in range(1, M+1):
  for i2 in range(i1, M+1):
    for i3 in range(i2, M+1):
      for i4 in range(i3, M+1):
        for i5 in range(i4, M+1):
          for i6 in range(i5, M+1):
            for i7 in range(i6, M+1):
              for i8 in range(i7, M+1):
                for i9 in range(i8, M+1):
                  L = [1, i1, i2, i3, i4, i5, i6, i7, i8, i9]
                  A = list()
                  for i in range(M):
                    A.append(L[i])
                  tmp = 0
                  for i in range(Q):
                    a = check[i][0]
                    b = check[i][1]
                    c = check[i][2]
                    d = check[i][3]
                    if(A[b-1]-A[a-1] == c):
                      tmp += d
                  ans = max(ans, tmp)

print(ans)

Fixed submission:
N, M, Q = map(int, input().split())
check = list()
for i in range(Q):
  check.append(list(map(int, input().split())))
ans = 0

for i1 in range(1, M+1):
  for i2 in range(i1, M+1):
    for i3 in range(i2, M+1):
      for i4 in range(i3, M+1):
        for i5 in range(i4, M+1):
          for i6 in range(i5, M+1):
            for i7 in range(i6, M+1):
              for i8 in range(i7, M+1):
                for i9 in range(i8, M+1):
                  L = [1, i1, i2, i3, i4, i5, i6, i7, i8, i9]
                  A = list()
                  for i in range(N):
                    A.append(L[i])
                  tmp = 0
                  for i in range(Q):
                    a = check[i][0]
                    b = check[i][1]
                    c = check[i][2]
                    d = check[i][3]
                    if(A[b-1]-A[a-1] == c):
                      tmp += d
                  ans = max(ans, tmp)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
INF = float('inf')
A = [(i+1, a) for i, a in enumerate(map(int, input().split()))]
A = sorted(A, key=lambda x: x[1], reverse = True)

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

for s in range(1, N+1):
  for l in range(s+1):
    r = s - l
    dp[l][r] = max(dp[l-1][r] + A[s-1][1] * abs(A[s-1][0]-l), dp[l][r-1] + A[s-1][1] * abs(N-r+1-A[s-1][0]))
    
ans = 0
for m in range(N):
  if(dp[m][N-m] > ans):
    ans = dp[m][N-m]
    
print(ans)



Fixed submission:
def main():
  N = int(input())
  INF = float('inf')
  A = [(i+1, a) for i, a in enumerate(map(int, input().split()))]
  A = sorted(A, key=lambda x: x[1], reverse = True)

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

  for s in range(1, N+1):
    for l in range(s+1):
      r = s - l
      dp[l][r] = max(dp[l-1][r] + A[s-1][1] * abs(A[s-1][0]-l), dp[l][r-1] + A[s-1][1] * abs(N-r+1-A[s-1][0]))
    
  ans = 0
  for m in range(N):
    if(dp[m][N-m] > ans):
      ans = dp[m][N-m]
    
  print(ans)

main()

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

A = [(i+1, a) for i, a in enumerate(map(int, input().split()))]
A = sorted(A, key=lambda x: x[1], reverse = True)

dp = [[-10 ** 15] * (N+1) for _ in range(N+1)]
dp[0][0] = 0

for s in range(1, N+1):
  for l in range(s+1):
    r = s - l
    dp[l][r] = max(dp[l-1][r] + A[s-1][1] * abs(A[s-1][0]-l), dp[l][r-1] + A[s-1][1] * abs(N-r+1-A[s-1][0]))
    
ans = 0
for m in range(N):
  if(dp[m][N-m] > ans):
    ans = dp[m][N-m]
    
print(ans)



Fixed submission:
def main():
  N = int(input())
  INF = float('inf')
  A = [(i+1, a) for i, a in enumerate(map(int, input().split()))]
  A = sorted(A, key=lambda x: x[1], reverse = True)

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

  for s in range(1, N+1):
    for l in range(s+1):
      r = s - l
      dp[l][r] = max(dp[l-1][r] + A[s-1][1] * abs(A[s-1][0]-l), dp[l][r-1] + A[s-1][1] * abs(N-r+1-A[s-1][0]))
    
  ans = 0
  for m in range(N):
    if(dp[m][N-m] > ans):
      ans = dp[m][N-m]
    
  print(ans)

main()
Buggy python submission (verdict: Time Limit Exceeded):
def gcd(x, y):
  while(x % y != 0 and y % x != 0):
    if(x > y):
      x = x % y
    else:
      y = y % x
  if(x > y):
    return y
  else:
    return x

K = int(input())
ans = 0
for i in range(1, K+1):
  for j in range(1, K+1):
    for k in range(1, K+1):
      ans += gcd(i, gcd(j, k))
print(ans)

Fixed submission:
def gcd(x, y):
  while(x % y != 0 and y % x != 0):
    if(x > y):
      x = x % y
    else:
      y = y % x
  if(x > y):
    return y
  else:
    return x

K = int(input())
ans = 0
for i in range(1, K+1):
  for j in range(i, K+1):
    for k in range(j, K+1):
      if(i == j and j == k):
        ans += i
      elif(i == j or j == k):
        ans += gcd(i, k) * 3
      else:
        ans += gcd(i, gcd(j, k)) * 6
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
cnt = [0] * (N+1)
ans = [0] * N
for i in range(N):
  cnt[A[i]] +=1
for i in range(N):
  for j in range(N+1):
    if(j == A[i]):
      ans[i] += (cnt[j]-1) * (cnt[j]-2) // 2
    else:
      ans[i] += cnt[j] * (cnt[j]-1) // 2
for i in range(N):
  print(ans[i])

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
cnt = [0] * (N+1)
ans = 0
for i in range(N):
  cnt[A[i]] +=1
for i in range(N+1):
  ans += cnt[i] * (cnt[i] - 1) // 2
for i in range(N):
  print(ans - cnt[A[i]] + 1)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
cnt = 0
for i in range(Q):
  x = list(input().split())
  if(int(x[0]) == 1):
    cnt += 1
  else:
    if((cnt+int(x[1])) % 2 == 1):
      S = x[2] + S
    else:
      S = S + x[2]
if(cnt % 2 == 1):
  print(S[::-1])
else:
  print(S)

Fixed submission:
from collections import deque
S = deque(input())
Q = int(input())
cnt = 0
for i in range(Q):
  x = list(input().split())
  if(int(x[0]) == 1):
    cnt += 1
  else:
    if((cnt+int(x[1])) % 2 == 1):
      S.appendleft(x[2])
    else:
      S.append(x[2])

S = list(S)
if(cnt % 2 == 1):
  S = S[::-1]
print("".join(S))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
cnt = 0
for i in range(Q):
  x = list(input().split())
  if(int(x[0]) == 1):
    cnt += 1
  else:
    if((cnt+int(x[1])) % 2 == 1):
      S = x[2] + S
    else:
      S = S + x[2]
if(cnt % 2 == 1):
  print(S[::-1])
else:
  print(S)

Fixed submission:
from collections import deque
S = deque(input())
Q = int(input())
cnt = 0
for i in range(Q):
  x = list(input().split())
  if(int(x[0]) == 1):
    cnt += 1
  else:
    if((cnt+int(x[1])) % 2 == 1):
      S.appendleft(x[2])
    else:
      S.append(x[2])

S = list(S)
if(cnt % 2 == 1):
  S = S[::-1]
print("".join(S))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
reverse_count = 0
for i in range(Q):
  query = list(input().split())
  if(query[0] == '1'):
    reverse_count += 1
  else:
    if((int(query[1]) + reverse_count) % 2 == 1):
      S = query[2] + S
    else:
      S = S + query[2]
if(reverse_count % 2 == 1):
  S = S[::-1]
print(S)

Fixed submission:
from collections import deque
S = deque(input())
Q = int(input())
cnt = 0
for i in range(Q):
  x = list(input().split())
  if(int(x[0]) == 1):
    cnt += 1
  else:
    if((cnt+int(x[1])) % 2 == 1):
      S.appendleft(x[2])
    else:
      S.append(x[2])

S = list(S)
if(cnt % 2 == 1):
  S = S[::-1]
print("".join(S))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
for i in range(Q):
  query = list(input().split())
  if(query[0] == '1'):
    S = S[::-1]
  else:
    if(query[1] == '1'):
      S = query[2] + S
    else:
      S = S + query[2]
print(S)

Fixed submission:
from collections import deque
S = deque(input())
Q = int(input())
cnt = 0
for i in range(Q):
  x = list(input().split())
  if(int(x[0]) == 1):
    cnt += 1
  else:
    if((cnt+int(x[1])) % 2 == 1):
      S.appendleft(x[2])
    else:
      S.append(x[2])

S = list(S)
if(cnt % 2 == 1):
  S = S[::-1]
print("".join(S))
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
p = list(map(int, input().split()))
ansmax = 0
for i in range(N-K+1):
  ans = 0
  for j in range(K):
    ans += (p[i+j]+1)/2
  if(ansmax < ans):
    ansmax = ans
print(ansmax)

Fixed submission:
N, K = map(int, input().split())
p = list(map(int, input().split()))
ansmax = 0
ans = 0
for j in range(K):
  ans += (p[j]+1)/2
if(ansmax < ans):
  ansmax = ans
for i in range(N-K):
  ans =  ans - (p[i]+1)/2 + (p[i+K]+1)/2
  if(ansmax < ans):
    ansmax = ans
print(ansmax)
Buggy python submission (verdict: Time Limit Exceeded):
H, N = map(int, input().split())
hpdown = list()
mpdown = list()
for i in range(N):
  a, b = map(int, input().split())
  hpdown.append(a)
  mpdown.append(b)
  
hmax = max(max(mpdown)*2+1, H+max(mpdown)+1)
dp = [10 ** 9] * (hmax)
dp[0] = 0
for h in range(1, hmax):
  for n in range(N):
    if(h-hpdown[n]>=0):
      dp[h] = min(dp[h], dp[h-hpdown[n]] + mpdown[n])
      
ans = 10 ** 9
for i in range(H, hmax):
  if(dp[i] < ans):
    ans = dp[i]
print(ans)

Fixed submission:
H, N = map(int, input().split())
hpdown = list()
mpdown = list()
for i in range(N):
  a, b = map(int, input().split())
  hpdown.append(a)
  mpdown.append(b)
  
hmax = H+(max(hpdown)+1)
dp = [10 ** 9] * (hmax)
dp[0] = 0
for h in range(1, hmax):
  for n in range(N):
    if(h-hpdown[n]>=0):
      dp[h] = min(dp[h], dp[h-hpdown[n]] + mpdown[n])
      
ans = 10 ** 9
for i in range(H, hmax):
  if(dp[i] < ans):
    ans = dp[i]
print(ans)