Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long int ulli;
typedef long long int lli;
#define pb(a) push_back(a)
#define pbb(a) pop_back(a)  
#define ph(a) push_heap(a.begin(), a.end())
#define pph(a) pop_heap(a.begin(), a.end())
#define si set<int>
#define sl set<long>
#define sc set<char>
#define pii pair<int, int>
#define pll pair<long, long>
#define pdd pair<double, double>
#define TC(t) while(t--)
#define FORA(a,b,c) for ((a) == (b); (a) < (c); (a) ++)
#define FORB(a,b,c) for ((a) == (b); (a) <= (c); (a) ++)
#define FORC(a,b) for ((a) == (b); (a) > 0; (a)--)
#define FORD(a,b) for ((a) == (b); (a) >= 0; (a)--)                         
#define WM(a) while(a--)
#define WP(a) while(a++)
#define print(data) cout << data << endl
#define tin(a) cin >> a
#define ttin(a,b) cin >> a >> b
#define tttin(a,b,c) cin >> a >> b >> c
#define maxheap(a) make_heap(a.begin(),a.end())
#define fixp(a)  cout << fixed << setprecision(a);
#define RM(a,n) a.erase(remopricee(a.begin(), a.end(), n),a.end())
#define MOD 1000000007
ll prime[] = {2 , 3 , 5 , 7 , 11 , 13 , 17 , 19 , 23 , 29 , 31 , 37 , 41 , 43 , 47};
inline int gmx (int a, int b){
	return a > b ? a : b;
}
inline int gmm (int a, int b){
	return a < b ? a : b;
}
inline ll get_gcd(ll a, ll b){
    ll rem = 0;
    while( b != 0){
        rem = a % b;
        a = b; 
        b = rem;
    }
    return a;   
}
ll fastexp (ll base, ll exp){
	ll res = 1;
	if (exp == 0) return 1LL;
	while(exp){
		if(exp&1) res = (res*base)%MOD;
		res = (res+MOD)%MOD;
		base = (base*base)%MOD;
		base = (base+MOD)%MOD;
		exp >>= 1;
	}
	return (ll)res;
}
struct compare {
    bool operator()(const std::string& first, const std::string& second) {
        return first.size() < second.size();
    }
};
void Verdict_Check(){
	ifstream A("my_output.txt");
	ifstream B("code_output.txt");
	
	int c1=0,c2=0;
	bool WA = false;
	string str;
	while(getline(A,str)){
		c1++;
	}
	while(getline(B,str)){
		c2++;
	}
	A.close();
	B.close();
	ifstream AA("my_output.txt");
	ifstream BB("code_output.txt");
	if (c1 != c2){
		WA = true;
	}else{
		string s,ss;
		while(getline(AA,s) && getline(BB,ss)){
			if(s != ss){
				WA = true;
			}
		}
	}
	if (WA){
		cout << "Wrong answer!!!" << endl;
	}else{
		cout << "All test cases are passed!!!" << endl;
	}
	AA.close();
	BB.close();
}
int N;
ll a[86+5];
int main(){
	int A[10000];
	//freopen("a.in","r",stdin);
	//freopen("my_output.txt","a", stdout);
	clock_t tStart = clock();
	scanf("%d",&N);
	a[0] = 2LL;a[1] = 1LL;
	for (int i = 2; i <= N; i ++)a[i] = a[i-1] + a[i-2];
	printf("%lld\n",a[N]);
	//freopen("CON", "w", stdout);
	//Verdict_Check();
	// printf("Time taken: %.7fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
	return 0;
}

Fixed submission:
P = 10**18
A = []
A.append(2)
A.append(1)
n = int(input())
for i in range(2,100000):
    A.append((A[i-1] + A[i-2])%P)
print(A[n])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

key = set()
for i in range(0, N-2):
    for j in range(i+1, N-1):
        for k in set(S[j+1:N]):
            key.add(S[i]+S[j]+k)

print(len(key))


Fixed submission:
N = int(input())
S = input()

X = []
for i in range(10):
    X.append(str(i))

ans = 0
for i in X:
    if i in S:
        T = S[S.index(i) + 1:]
        for j in X:
            if j in T:
                U = T[T.index(j) + 1:]
                for k in X:
                    if k in U:
                        ans += 1

print(ans)

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

key = set()
for i in range(0, N-2):
    for j in range(i+1, N-1):
        for k in range(j+1, N):
            key.add(S[i]+S[j]+S[k])

print(len(key))


Fixed submission:
N = int(input())
S = input()

X = []
for i in range(10):
    X.append(str(i))

ans = 0
for i in X:
    if i in S:
        T = S[S.index(i) + 1:]
        for j in X:
            if j in T:
                U = T[T.index(j) + 1:]
                for k in X:
                    if k in U:
                        ans += 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
L, R = map(int, input().split())

D = R - L
Ans = {2018}
J_Set = {2018}


for i in range(min(D, 2019)):
    A = L+i
    for j in range(D-i):
        B = (L+i+j+1)%2019
        Ans.add((A*B)%2019)
        if j > 2019:
            break

print(min(Ans))

Fixed submission:
L, R = map(int, input().split())

D = R - L
Ans = {2018}
J_Set = {2018}


for i in range(min(D, 2019)):
    A = L+i
    for j in range(D-i):
        B = L+i+j+1
        Ans.add((A*B)%2019)
        if j > 2019:
            break

print(min(Ans))

Buggy python submission (verdict: Time Limit Exceeded):
L, R = map(int, input().split())

D = R - L
Ans = {2018}
J_Set = {2018}
def cal(a, b):
    return int((a*b)%2019)

for i in range(min(D, 2019)):
    A = (L+i)%2019
    for j in range(D-i):
        B = (L+i+j+1)%2019
        Ans.add((A*B)%2019)
        if j > 2019:
            break
        
print(min(Ans))

Fixed submission:
L, R = map(int, input().split())

D = R - L
Ans = {2018}
J_Set = {2018}


for i in range(min(D, 2019)):
    A = L+i
    for j in range(D-i):
        B = L+i+j+1
        Ans.add((A*B)%2019)
        if j > 2019:
            break

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

print(max(a+a-1, a+b-1, b+b-1))

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

print(max(a+a-1, a+b, b+b-1))
Buggy python submission (verdict: Time Limit Exceeded):
import math
def com(x, y):
    return math.factorial(x) // (math.factorial(x - y) * math.factorial(y))

n = int(input())
a = list(map(int, input().split()))
a.sort()

P = a[n-1]//2
S = 0
T = 0

for i in range(n):
    if a[i] > P:
        S = a[i-1]
        T = a[i]
        break

if com(a[n-1],S) >= com(a[n-1],T):
    print(a[n-1],S)
else:
    print(a[n-1],T)

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

P = a[n-1]/2
S = 0
T = 0

for i in range(n):
    if a[i] > P:
        S = a[i-1]
        T = a[i]
        break


if abs(S-P) <= abs(T-P):
    print(a[n-1],S)
else:
    print(a[n-1],T)
Buggy python submission (verdict: Runtime Error):
A,B,K = map(int, input().split())
X = []
L = B-A+1
if 2*K>=L:
    for i in range(L):
        print(A+i)
else:
    for j in range(K):
        print(A+i)
    for k in range(K):
        print(A-K+k)

Fixed submission:
A,B,K = map(int, input().split())
X = []
L = B-A+1
if 2*K>=L:
    for i in range(L):
        print(A+i)
else:
    for j in range(K):
        print(A+j)
    for k in range(K):
        print(B-K+1+k)

Buggy python submission (verdict: Time Limit Exceeded):
A,B,K = map(int, input().split())
for i in range(B-A+1):
    if i<K or (B-A-i)<(K):
        print(A+i)

Fixed submission:
A,B,K = map(int, input().split())
X = []
L = B-A+1
if 2*K>=L:
    for i in range(L):
        print(A+i)
else:
    for j in range(K):
        print(A+j)
    for k in range(K):
        print(B-K+1+k)
Buggy python submission (verdict: Runtime Error):
S = list(input())

P = set(S)

flag = 0
if len(S) == 26:
    Q = set()
    for i in range(25):
        if ord(S[25 - i]) < ord(S[25 - i - 1]):
            Q.add(ord(S[25 - i]))
            S.pop()
        else:
            while len(Q)>0 and ord(S[25 - i - 1])>min(Q):
                Q.remove(min(Q))
            S.pop()
            S.pop()
            S.append(chr(min(Q)))
            flag = 1
            break
else:
    for j in range(26):
        M = chr(97 + j)
        if M in P:
            pass
        else:
            S.append(M)
            flag = 1
            break

if flag == 0:
    print(-1)
else:
    print(''.join(S))

Fixed submission:
S = list(input())

P = set(S)

flag = 0
if len(S) == 26:
    Q = set()
    for i in range(25):
        if ord(S[25 - i]) < ord(S[25 - i - 1]):
            Q.add(ord(S[25 - i]))
            S.pop()
        else:
            while len(Q)>0 and ord(S[25 - i - 1])>min(Q):
                Q.remove(min(Q))
            if len(Q)>0:
                S.pop()
                S.pop()
                S.append(chr(min(Q)))
                flag = 1
                break
            else:
                Z = S[25-i]
                S.pop()
                S.pop()
                S.append(Z)
                flag = 1
                break
else:
    for j in range(26):
        M = chr(97 + j)
        if M in P:
            pass
        else:
            S.append(M)
            flag = 1
            break

if flag == 0:
    print(-1)
else:
    print(''.join(S))

Buggy python submission (verdict: Runtime Error):
S = list(input())

P = set(S)

flag = 0
if len(S) == 26:
    Q = set()
    for i in range(25):
        if ord(S[25 - i]) < ord(S[25 - i - 1]):
            Q.add(ord(S[25 - i]))
            S.pop()
        else:
            S.pop()
            S.append(chr(min(Q)))
            flag = 1
else:
    for j in range(26):
        M = chr(97 + j)
        if M in P:
            pass
        else:
            S.append(M)
            flag = 1
            break

if flag == 0:
    print(-1)
else:
    print(''.join(S))

Fixed submission:
S = list(input())

P = set(S)

flag = 0
if len(S) == 26:
    Q = set()
    for i in range(25):
        if ord(S[25 - i]) < ord(S[25 - i - 1]):
            Q.add(ord(S[25 - i]))
            S.pop()
        else:
            while len(Q)>0 and ord(S[25 - i - 1])>min(Q):
                Q.remove(min(Q))
            if len(Q)>0:
                S.pop()
                S.pop()
                S.append(chr(min(Q)))
                flag = 1
                break
            else:
                Z = S[25-i]
                S.pop()
                S.pop()
                S.append(Z)
                flag = 1
                break
else:
    for j in range(26):
        M = chr(97 + j)
        if M in P:
            pass
        else:
            S.append(M)
            flag = 1
            break

if flag == 0:
    print(-1)
else:
    print(''.join(S))
Buggy python submission (verdict: Runtime Error):
import functools
import math

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

x = functools.reduce(math.gcd, A)

flag = 0
i = 0

while flag == 0:
    if x % pow(2,i) == 0:
        i += 1
    else :
        flag = 1

print(i-1)

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

def gcd( x, y ):
    while y != 0:
        x, y = y, x%y
    return x

Z = A[0]

for i in range(N):
    Z = gcd(Z ,A[i])

flag = 0
i = 0

while flag == 0:
    if Z % pow(2,i) == 0:
        i += 1
    else :
        flag = 1

print(i-1)

Buggy python submission (verdict: Runtime Error):
import functools
import math

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

x = functools.reduce(math.gcd, A)

flag = 0
i = 0

while flag == 0:
    if x % pow(2,i) == 0:
        i += 1
    else :
        flag = 1

print(i-1)

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

def gcd( x, y ):
    while y != 0:
        x, y = y, x%y
    return x

Z = A[0]

for i in range(N):
    Z = gcd(Z ,A[i])

flag = 0
i = 0

while flag == 0:
    if Z % pow(2,i) == 0:
        i += 1
    else :
        flag = 1

print(i-1)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = []
x = 0
for i in range(N):
    s = int(input())
    if A.count(s)==0:
        A.append(s)
    else:
        A.remove(s)



print(len(A))

Fixed submission:
N = int(input())
A = set()
x = 0
for i in range(N):
    s = int(input())
    if s in A:
        A.remove(s)
    else:
        A.add(s)



print(len(A))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = []
x = 0
for i in range(N):
    A.append(int(input()))

P = list(set(A))

for j in range(len(P)):
    if A.count(int(P[j]))%2==1:
        x += 1

print(x)

Fixed submission:
N = int(input())
A = set()
x = 0
for i in range(N):
    s = int(input())
    if s in A:
        A.remove(s)
    else:
        A.add(s)



print(len(A))
Buggy python submission (verdict: Runtime Error):
n = input()
a1 = n%10
a2 = (n-a1)%100
a3 = (n-a1-a2)/100
if a1==a3:
    print("Hello World")

Fixed submission:
n=int(input())
a1 = n % 10
a2 = (n - a1) % 100
a3 = (n - a1 - a2) / 100
if a1 == a3:
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Runtime Error):
n = input()
a1 = n%10
a2 = (n-a1)%100
a3 = (n-a1-a2)/100
if a1==a2:
    print("Hello World")

Fixed submission:
n=int(input())
a1 = n % 10
a2 = (n - a1) % 100
a3 = (n - a1 - a2) / 100
if a1 == a3:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)


k = int(input())
sum = 0
for a in range(1,k+1):
    for b in range(1,k+1):
        for c in range(1,k+1):
            sum += gcd(a,b,c)

print(sum)


Fixed submission:
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)


k = int(input())
sum = 0
for a in range(1,k+1):
    for b in range(1,k+1):
        if gcd(a,b) == 1:
            sum += 1 * k
            continue
        for c in range(1,k+1):
            sum += gcd(a,b,c)

print(sum)
Buggy python submission (verdict: Time Limit Exceeded):
class Queue:
    def enque(self, x, l):
        l.append(x)
        return l

    def deque(self, l):
        num = l[0]
        l.pop(0)
        return num

k = int(input())

queue = Queue()
l = [1,2,3,4,5,6,7,8,9]

for i in range(k):
    x = queue.deque(l)
    if x % 10 != 0:
        l = queue.enque(10*x + (x%10) -1, l)
    l = queue.enque(10*x + (x%10), l)
    if x % 10 != 9:
        l = queue.enque(10*x + (x%10) +1, l)
print(x)


Fixed submission:
import queue

k = int(input())

queue = queue.Queue()
for i in range(1,10):
    queue.put(i)

for i in range(k):
    x = queue.get()
    if x % 10 != 0:
        l = queue.put(10*x + (x%10) -1)
    l = queue.put(10*x + (x%10))
    if x % 10 != 9:
        l = queue.put(10*x + (x%10) +1)
print(x)

Buggy python submission (verdict: Time Limit Exceeded):
class Queue:
    def enque(self, x, l):
        l.append(x)
        return l

    def deque(self, l):
        num = l[0]
        l.pop(0)
        return num

k = int(input())

queue = Queue()
l = list()
for x in range(1,10):
    queue.enque(x,l)

for i in range(k-1):
    x = queue.deque(l)
    if x % 10 != 0:
        l = queue.enque(10*x + (x%10) -1, l)
    l = queue.enque(10*x + (x%10), l)
    if x % 10 != 9:
        l = queue.enque(10*x + (x%10) +1, l)
print(queue.deque(l))


Fixed submission:
import queue

k = int(input())

queue = queue.Queue()
for i in range(1,10):
    queue.put(i)

for i in range(k):
    x = queue.get()
    if x % 10 != 0:
        l = queue.put(10*x + (x%10) -1)
    l = queue.put(10*x + (x%10))
    if x % 10 != 9:
        l = queue.put(10*x + (x%10) +1)
print(x)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = list(map(int,input().split()))
L.sort()

cnt = 0
for first in range(N):
    for second in range(first+1,N):
        for third in range(second+1,N):
            if L[third] < L[first] + L[second]:
                cnt += 1
                # print(L[first],L[second],L[third])

print(cnt)


Fixed submission:
import bisect

N = int(input())
L = list(map(int,input().split()))
L.sort()

cnt = 0
for first in range(N):
    for second in range(first+1,N):
        bnd = bisect.bisect_left(L,L[first]+L[second]) - 1
        dif = bnd - second
        if dif > 0:
            cnt += dif

print(cnt)
Buggy python submission (verdict: Runtime Error):
import queue
import math
import copy
"""
N = int(input())
#S = input()
# (N,M) = (int(i) for i in input().split(" "))
# A = [int(i) for i in input().split()]
A = []
for i in range(N):
	A.append(int(input()))

print(A)

"""

(N,X,D) = (int(i) for i in input().split(" "))
mp = {}

for i in range(N+1):
	md = (i*X)%D
	if not md in mp:
		mp[md] = []
	k = 0
	for j in range(i):
		k += j
	mp[md].append([k+((i*X)-md)//D,0])
	k = 0
	for j in range(i):
		k += N-j-1
	mp[md].append([k+((i*X)-md)//D+1,1])
#print(mp)
ans = 0
for k in mp.keys():
	s = sorted(mp[k])
	#print(s)
	md = 0
	bef = 0
	for t in s:
		if md > 0:
			ans += t[0] - bef
		bef = t[0]
		if t[1] == 0:
			md += 1
		else:
			md -= 1
print(ans)

Fixed submission:
import queue
import math
import copy
"""
N = int(input())
#S = input()
# (N,M) = (int(i) for i in input().split(" "))
# A = [int(i) for i in input().split()]
A = []
for i in range(N):
	A.append(int(input()))

print(A)

"""

(N,X,D) = (int(i) for i in input().split(" "))
mp = {}
if D == 0:
	if X == 0:
		ans = 1
	else:
		ans = N+1
else:
	for i in range(N+1):
		md = (i*X)%D
		if not md in mp:
			mp[md] = []
		k = i*(i-1)//2
		mp[md].append([k+(((i*X)-md)//D),0])
		k = (N*2-i-1)*i//2
		mp[md].append([k+(((i*X)-md)//D)+1,1])
	#print(mp)
	ans = 0
	for k in mp.keys():
		s = sorted(mp[k])
		#print(s)
		md = 0
		bef = 0
		for t in s:
			if md > 0:
				ans += t[0] - bef
			bef = t[0]
			if t[1] == 0:
				md += 1
			else:
				md -= 1
print(ans)

Buggy python submission (verdict: Runtime Error):
import queue
import math
import copy
"""
N = int(input())
#S = input()
# (N,M) = (int(i) for i in input().split(" "))
# A = [int(i) for i in input().split()]
A = []
for i in range(N):
	A.append(int(input()))

print(A)

"""

(N,X,D) = (int(i) for i in input().split(" "))
mp = {}

for i in range(N+1):
	md = (i*X)%D
	if not md in mp:
		mp[md] = []
	k = 0
	for j in range(i):
		k += j
	mp[md].append([k+((i*X)-md)/D,0])
	k = 0
	for j in range(i):
		k += N-j-1
	mp[md].append([k+((i*X)-md)/D+1,1])
#print(mp)
ans = 0
for k in mp.keys():
	s = sorted(mp[k])
	#print(s)
	md = 0
	bef = 0
	for t in s:
		if md > 0:
			ans += t[0] - bef
		bef = t[0]
		if t[1] == 0:
			md += 1
		else:
			md -= 1
print(round(ans))

Fixed submission:
import queue
import math
import copy
"""
N = int(input())
#S = input()
# (N,M) = (int(i) for i in input().split(" "))
# A = [int(i) for i in input().split()]
A = []
for i in range(N):
	A.append(int(input()))

print(A)

"""

(N,X,D) = (int(i) for i in input().split(" "))
mp = {}
if D == 0:
	if X == 0:
		ans = 1
	else:
		ans = N+1
else:
	for i in range(N+1):
		md = (i*X)%D
		if not md in mp:
			mp[md] = []
		k = i*(i-1)//2
		mp[md].append([k+(((i*X)-md)//D),0])
		k = (N*2-i-1)*i//2
		mp[md].append([k+(((i*X)-md)//D)+1,1])
	#print(mp)
	ans = 0
	for k in mp.keys():
		s = sorted(mp[k])
		#print(s)
		md = 0
		bef = 0
		for t in s:
			if md > 0:
				ans += t[0] - bef
			bef = t[0]
			if t[1] == 0:
				md += 1
			else:
				md -= 1
print(ans)
Buggy python submission (verdict: Runtime Error):

(N,M) = (int(i) for i in input().split(" "))
A = [int(i) for i in input().split()]
for i in range(N):
	A[i+1] += A[i]
	if A[i+1] > M:
		print(i+2)
		break




Fixed submission:
(N,M) = (int(i) for i in input().split(" "))
A = [int(i) for i in input().split()]
A.append(100000)
for i in range(N):
	A[i+1] += A[i]
	if A[i+1] > M:
		print(i+2)
		break
Buggy python submission (verdict: Runtime Error):

N = int(input())
P = [[int(i) for i in input().split(" ")]for _ in range(N)]

min_point = 100
for i in range(N-1):
	for j in range(i+1, N):
		p = P[i]
		q = P[j]
		if p[0] <=  q[0] and p[1] <= q[1]:
			x = q[0]-p[0]
			y = q[1]-p[1]
			point = 0
			mp = [False for _ in range(N)]
			count = N
			index = 0
			qu = queue.Queue()
			while count:
				if not mp[index]:
					point += 1
					qu.put(P[index])
					mp[index] = True
					count -= 1
					while not qu.empty():
						top = qu.get()
						for k in range(N):
							if not mp[k] and ((top[0]-x == P[k][0] and top[1]-y == P[k][1]) or (top[0]+x == P[k][0] and top[1]+y == P[k][1])):
								count -= 1
								qu.put(P[k])
								mp[k] = True
				index += 1
			if point < min_point:
				min_point = point

print(min_point)




Fixed submission:
import queue

"""
N = int(input())
#S = input()
# (N,M) = (int(i) for i in input().split(" "))
# A = [int(i) for i in input().split()]
A = []
for i in range(N):
	A.append(int(input()))

print(A)

"""
N = int(input())
P = [[int(i) for i in input().split(" ")]for _ in range(N)]

min_point = 100
for i in range(N-1):
	for j in range(i+1, N):
		p = P[i]
		q = P[j]
		if p[0] <=  q[0]:
			x = q[0]-p[0]
			y = q[1]-p[1]
			point = 0
			mp = [False for _ in range(N)]
			count = N
			index = 0
			qu = queue.Queue()
			while count:
				if not mp[index]:
					point += 1
					qu.put(P[index])
					mp[index] = True
					count -= 1
					while not qu.empty():
						top = qu.get()
						for k in range(N):
							if not mp[k] and ((top[0]-x == P[k][0] and top[1]-y == P[k][1]) or (top[0]+x == P[k][0] and top[1]+y == P[k][1])):
								count -= 1
								qu.put(P[k])
								mp[k] = True
				index += 1
			if point < min_point:
				min_point = point
if N == 1:
	min_point = 1
print(min_point)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())

rev = 0
for i in range(q):
	g = input()
	if len(g) == 1:
		rev += 1
	else:
		f = int(g[2])
		c = g[4]
		if f == 2:
			if rev%2 == 1:
				s = c + s
			else:
				s = s + c
		else:
			if rev%2 == 0:
				s = c + s
			else:
				s = s + c
if rev%2 == 1:
	s = s[::-1]
print(s)

Fixed submission:
s = input()
q = int(input())

prev = ""
aft = ""
rev = 0
for i in range(q):
	g = input()
	if len(g) == 1:
		rev += 1
	else:
		f = int(g[2])
		c = g[4]
		if f == 2:
			if rev%2 == 1:
				prev = c + prev
			else:
				aft = aft + c
		else:
			if rev%2 == 0:
				prev = c + prev
			else:
				aft = aft + c
if rev%2 == 1:
	print(aft[::-1]+s[::-1]+prev[::-1])
else:
	print(prev+s+aft)

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

rev = 0
for i in range(q):
	g = input()
	if len(g) == 1:
		rev += 1
	else:
		f = int(g[2])
		c = g[4]
		if f == 2:
			if rev%2 == 1:
				s = c + s
			else:
				s = s + c
		else:
			if rev%2 == 0:
				s = c + s
			else:
				s = s + c
if rev%2 == 1:
	s = s[::-1]
print(s)

Fixed submission:
s = input()
q = int(input())

prev = ""
aft = ""
rev = 0
for i in range(q):
	g = input()
	if len(g) == 1:
		rev += 1
	else:
		f = int(g[2])
		c = g[4]
		if f == 2:
			if rev%2 == 1:
				prev = c + prev
			else:
				aft = aft + c
		else:
			if rev%2 == 0:
				prev = c + prev
			else:
				aft = aft + c
if rev%2 == 1:
	print(aft[::-1]+s[::-1]+prev[::-1])
else:
	print(prev+s+aft)
Buggy python submission (verdict: Time Limit Exceeded):
H, n = map(int, input().split())
A = []
B = []
for i in range(n):
	a, b = map(int, input().split())
	A.append(a)
	B.append(b)

dp = [0 for i in range(H+1)]

for i in range(1, H+1):
	dp[i] = min(dp[i - A[j]] + B[j]  if A[j] <= i  else  B[j]  for j in range(n))

print(dp[H])


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

dp = [0 for i in range(H+1)]

for i in range(1, H+1):
	dp[i] = min(dp[i - A[j]] + B[j]  if A[j] <= i  else  B[j]  for j in range(n))

print(dp[H])

Buggy python submission (verdict: Time Limit Exceeded):
H, n = map(int, input().split())
A = []
B = []
for i in range(n):
	a, b = map(int, input().split())
	A.append(a)
	B.append(b)

dp = [0 for i in range(H+1)]

for i in range(1, H+1):
	dp[i] = min(B[j]  if i < A[j]  else  dp[i - A[j]] + B[j]  for j in range(n))

print(dp[H])


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

dp = [0 for i in range(H+1)]

for i in range(1, H+1):
	dp[i] = min(dp[i - A[j]] + B[j]  if A[j] <= i  else  B[j]  for j in range(n))

print(dp[H])

Buggy python submission (verdict: Runtime Error):
H, N = map(int, input().split())
A = []
B = []
for i in range(n):
	a, b = map(int, input().split())
	A.append(a)
	B.append(b)

dp = [0 for i in range(H+1)]

for i in range(H+1):
	dp[i] = min(B[j]  if h < A[j]  else  dp[i - A[j]] + B[j]  for j in range(n))

print(dp[H])


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

dp = [0 for i in range(H+1)]

for i in range(1, H+1):
	dp[i] = min(dp[i - A[j]] + B[j]  if A[j] <= i  else  B[j]  for j in range(n))

print(dp[H])