Harryxun/stf_run huggingface dataset:
import sys
import itertools

def sieve(n):
    is_prime = [True] * (n + 1)
    prime_list = []
    
    is_prime[0] = is_prime[1] = False
    prime_list.append(2)
    
    for i in range(3, n + 1, 2):
        if is_prime[i]: prime_list.append(i)
        for j in range(i * i, n + 1, i):
            is_prime[j] = False
    return prime_list
    
primes = sieve(40000)

def factoriaztion(n):
    ret = []
    for prime in primes:
        while n % prime == 0:
            ret.append(prime)
            n /= prime
        if n == 1: break
    if n > 1: ret.append((n, 1))
    return ret
    
    
if __name__ == '__main__':
    n = sys.stdin.readline()
    n = int(n)
    factors = factoriaztion(n)
    factors = itertools.groupby(factors)
    
    ans = 1
    
    for k, v in factors:
        l = len(list(v))
        ans = ans * (k ** l - k ** (l - 1))
    
    sys.stdout.write(str(ans) + '\n')
    
        

### FIXED CODE ###

from __future__ import division

maxn = 40000

def sieve(n):
    ret = []
    isPrime = [False if i % 2 == 0 else True for i in range(n + 1)]
    isPrime[0] = isPrime[1] = False
    ret.append(2)
    for i in range(3, n + 1, 2):
        if isPrime[i]:
            ret.append(i)
            for j in range(i * i, n + 1, i):
                isPrime[i] = False

    return ret

primes = sieve(maxn)

def factor(n):
    ret, idx = [], 0
    for p in primes:
        if n % p == 0:
            count = 0
            while n % p == 0:
                count += 1
                n //= p
            ret.append((p, count))

    if n > 1: ret.append((n, 1))
    return ret

def euler_phi(n):
    facts = factor(n)
    return reduce(lambda acc, (p, a):  acc * (p ** a - p ** (a - 1)), facts, 1)


if __name__ == '__main__':
    n = int(raw_input())
    print euler_phi(n)
import sys
N,K = map(int,input().split())
cnt_nodes = (N-1)*(N-2) // 2
if K > cnt_nodes:
	print(-1)
	sys.exit(0)
    
print((N-1)*(N) // 2 - K)
cnt = 0
for i in range(1,N):
	for j in range(i+1,N+1):
		if cnt >= (N-1)*(N) // 2 - K:
			break
		print(i,j)
		cnt += 1
	else:
		continue
	break



### FIXED CODE ###

import fractions
A,B,C,D = map(int,input().split())
c = B//C - (A-1)//C
d = B//D - (A-1)//D
E = (C*D)//fractions.gcd(C,D)
e = B//E - (A-1)//E
answer = B-A+1-(c+d-e)
print(answer)
def noboru(m):
    if (m == 1):
        return 1
    elif (m == 2):
        return 2
    else:
        return noboru(m-1)+noboru(m-2)

def func(N, M, a):
    ans = 1
    i = 0
    if (a[0] == 1):
        ans *=1
    else:
        ans *= noboru(a[0]-1)
    if (M > 1):
        for i in range(1, M):
            if (a[i] == a[i-1]+1):
                return 0
            else:
                ans *= noboru(a[i] - 2 - a[i-1])
    ans *= noboru(N - 1 - a[i])
    return ans % 1000000007

N, M = map(int, input().split(" "))
a = [int(input()) for _ in range(M)]
#A_i = list(map(int, input().split(" ")))
#B_i = list(map(int, input().split(" ")))
print(func(N, M, a))
#print(noboru(6))

### FIXED CODE ###

CONST = 1000000007

def noboru(n):
    a1 = 1
    a2 = 2
    ans = 0
    if (n == 0 or n == 1): return a1
    elif (n == 2): return a2
    else:
        for i in range(1, n-1):
            ans = a2 + a1
            a1 = a2
            a2 = ans
        return a2

def func(N, M, a):
    ans = 1
    pos = 0
    for i in range(M):
        if (pos == a[i]):
            return 0
        else:
            ans = (ans * noboru(a[i] - pos - 1)) % CONST
            pos = a[i] + 1
    ans = (ans * noboru(N - pos)) % CONST
    return ans

N, M = map(int, input().split(" "))
a = [int(input()) for _ in range(M)]
print(func(N, M, a))
n=int(input())
ab=[]
root=[[] for i in range(n)] 
for i in range(n-1):
    a,b=map(int,input().split())
    ab.append((a-1,b-1))
    root[a-1].append((i,b-1))
    root[b-1].append((i,a-1))
c=0
for i in range(n):
    c=max(c,len(root[i]))
print(c)
color=[0]*(n-1)

def dfs(node,par,c):
    if c!=1:
        i=1
    else:
        i=2
    for idx,x in root[node]:
        if x==par:
            continue
        if color[idx]==0:
            color[idx]=i
            dfs(x,node,i)
            i+=1
dfs(0,0,0)
for i in range(n-1):
    print(color[i])

### FIXED CODE ###

import sys
sys.setrecursionlimit(100000000)
n=int(input())
ab=[]
root=[[] for i in range(n)] 
for i in range(n-1):
    a,b=map(int,input().split())
    root[a-1].append((i,b-1))
    root[b-1].append((i,a-1))
c=0
for i in range(n):
    c=max(c,len(root[i]))
print(c)
color=[0]*(n-1)

def dfs(node,par,c):
    if c!=1:
        i=1
    else:
        i=2
    for idx,x in root[node]:
        if x==par:
            continue
        if color[idx]==0:
            color[idx]=i
            dfs(x,node,i)
            i+=1
            if i==c:
                i+=1
dfs(0,-1,0)
for i in range(n-1):
    print(color[i])
import sys

s = sys.stdin.readline()
N = s[0]
p = sorted(s[1:])
print(p[:-1].sum() + p[-1]/2)

### FIXED CODE ###

N = int(input())
p = [int(input()) for i in range(N)]
p.sort()
print(int(sum(p[:-1]) + p[-1]/2))
n=int(input())
a=list(map(int,input().split()))
temp=[0]*max(a)
for i in range(n):
  temp[a[i]-1]=temp[a[i]-1]+1
ans=0
for i in range(1,max(a)-1):
  ans=max(ans,temp[i-1]+temp[i]+temp[i+1])
print(ans)

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
temp=[0]*(max(a)+1)
for i in range(n):
  temp[a[i]]=temp[a[i]]+1
ans=0
if max(a)==0 or max(a)==1:
  print(n)
else:
  for i in range(1,max(a)):
    ans=max(ans,temp[i-1]+temp[i]+temp[i+1])
  print(ans)
s=input()

m=sort(s)
k=''.join(m)

if k=="abc" :
  print("Yes")
else:
  print("No")

### FIXED CODE ###

s=input()

m=sorted(s)
k=''.join(m)

if k=="abc" :
  print("Yes")
else:
  print("No")
from sys inmport stdin
X,A,B = map(int, stdin.read().splitlines())
print( (X-A)%B )

### FIXED CODE ###

from sys import stdin
X,A,B = map(int, stdin.read().splitlines())
print( (X-A)%B )
n = int(input())

x = []
l = []
for i in range(n):
    tmp = list(map(int, input().split()))
    x.append(tmp[0])
    l.append(tmp[1])
keydict = dict(zip(l, x))
l.sort(key=keydict.get)
x.sort()

m = {}
def solve(prev, idx):
    if idx == n:
        return 0
    key = (prev, idx)
    if key in m:
        return m[key]
    res_use = 0
    res_nouse = 0

    if x[idx] - l[idx] >= prev or prev == 0:
        res_use = 1
        res_use += solve(x[idx] + l[idx], idx + 1)
    res_nouse += solve(prev, idx + 1)

    ans = max(res_use, res_nouse)
    m[key] = ans
    return ans
print(solve(0, 0))

### FIXED CODE ###

def main():
    n = int(input())
    x = []
    l = []
    for i in range(n):
        tmp = list(map(int, input().split()))
        x.append(tmp[0] - tmp[1])
        l.append(tmp[0] + tmp[1])
    x, l = zip(*sorted(zip(x, l)))
    maxcount = 0
    preve = 0
    idx = 0
    while idx < n:
        tmps = x[idx]
        tmpe = l[idx]
        if preve == 0:
            maxcount += 1
            preve = tmpe
        elif tmps >= preve:
            maxcount += 1
            preve = tmpe
        elif tmpe < preve:
            preve = tmpe
        idx += 1
    print(maxcount)
    return

if __name__ == "__main__":
    main()
from math import gcd
from sys import setrecursionlimit
setrecursionlimit(4100000)
mod = 10 ** 9 + 7
n = int(input())

zeros = 0
d = {}
for i in range(n):
    x, y = map(int, input().split())
    if x == 0 and y == 0:
        zeros += 1
    else:
        g = gcd(x, y)
        x, y = x / g, y / g
        if (y < 0) or (y == 0 and x < 0): 
            x, y = -x, -y
        else: 
            pass
        if x <= 0:
            sq = True   #second quadrant
            x, y = y, -x
        else:
            sq = False
        if sq == True:
            if (x, y) in d:
                d[(x, y)][1] += 1
            else:
                d[(x, y)] = [0, 1]
        else:
            if (x, y) in d:
                d[(x, y)][0] += 1
            else:
                d[(x, y)] =[1, 0] 

#繰り返し2乗法
def  mod_pow(a:int, b:int, mod:int)->int:
    if b == 0:
        return 1 % mod
    elif b % 2 == 0:
        return (mod_pow(a, b//2, mod) ** 2) % mod
    elif b == 1:
        return a % mod
    else:
        return ((mod_pow(a, b//2, mod) ** 2) * a) % mod
#print(d)

ans = 1
for (i, j) in tuple(d.values()):
    now = 1
    now = (now + mod_pow(2, i, mod) - 1) % mod
    now = (mow + mod_pow(2, j, mod) - 1) % mod
    ans = (ans * now) % mod
    
ans -= 1
ans += zeros % mod
ans = ans % mod
print(ans)

### FIXED CODE ###

from math import gcd
from sys import setrecursionlimit
setrecursionlimit(4100000)
mod = 10 ** 9 + 7
n = int(input())

zeros = 0
d = {}
for i in range(n):
    x, y = map(int, input().split())
    if x == 0 and y == 0:
        zeros += 1
    else:
        g = gcd(x, y)
        x, y = x // g, y // g
        if (y < 0) or (y == 0 and x < 0): 
            x, y = -x, -y
        else: 
            pass
        if x <= 0:
            sq = True   #second quadrant
            x, y = y, -x
        else:
            sq = False
        if sq == True:
            if (x, y) in d:
                d[(x, y)][1] += 1
            else:
                d[(x, y)] = [0, 1]
        else:
            if (x, y) in d:
                d[(x, y)][0] += 1
            else:
                d[(x, y)] =[1, 0] 

#繰り返し2乗法
def  mod_pow(a:int, b:int, mod:int)->int:
    if b == 0:
        return 1 % mod
    elif b % 2 == 0:
        return (mod_pow(a, b//2, mod) ** 2) % mod
    elif b == 1:
        return a % mod
    else:
        return ((mod_pow(a, b//2, mod) ** 2) * a) % mod
#print(d)

ans = 1
for (a, b), (k, l) in d.items():
    now = 1
    now = (now + mod_pow(2, k, mod) - 1) % mod
    now = (now + mod_pow(2, l, mod) - 1) % mod
    ans = (ans * now) % mod
    
ans -= 1
zeros = zeros % mod
ans = (ans + zeros) % mod
print(ans)
x = input()
n = list(map(int,input().split()))
​
a = min(n)
b = max(n)
c = sum(n)
​
print(a,b,c)


### FIXED CODE ###

n = int(input())
k = list(map(int,input().split()))

a = min(k)
b = max(k)
c = sum(k)

print(a,b,c)
from collections import Counter

n=int(input())

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

cc=Counter(arr)
for k,v in cc.items():
  if v>1:
    print("NO")
    break
else:
print("NO")


### FIXED CODE ###

#from collections import Counter
n=int(input())
arr=list(map(int,input().split()))
di={}
for i in arr:
  if i in di:
    print("NO")
    break
  else:
    di[i]=1
else:
  print("YES")
N = int(input())
m, *P = sorted([int(input()) for x in range(N)], reverse=True)

"""
m = P[N-1]
P = P[:N-1]
"""

print(sum(P) + m // 2)

### FIXED CODE ###

d = int(input())
print("Christmas " + "Eve " * (5 - d%20))
a=map(int, raw_input().split())
a=sorted(a)
for i in range(len(a)-1):
????????print a[i] 

### FIXED CODE ###

a = map(int, raw_input().split())
a.sort()
for i in range(len(a)):
    print a[i],
#D問題
N, M=map(int, input().split())
V = input().split()
V_i = [int(i) for i in V]

ans = 0
for i in range(M):
    for j in range(M-i):
        if i+j >M:
            break;
        num = 0
        dump_num = []
        for k in range(i):
            num += V_i[k]
            dump_num.append(V_i[k])
        for k in range(N-1,N-j-1,-1):
            num+=V_i[k]
            dump_num.append(V_i[k])
        dump_num.sort()
        for k in range(M-i-j):
            if k >= len(dump_num):
                break;
            if dump_num[k] >= 1:
                break;
            num -=dump_num[k]
        if num > ans:
            ans = num
print(ans)
            

### FIXED CODE ###

#D問題
N, M=map(int, input().split())
V = input().split()
V_i = [int(i) for i in V]

ans = 0
for i in range(M+1):
    for j in range(M+1-i):
        if i+j >N:
            break;
        num = 0
        dump_num = []
        for k in range(i):
            num += V_i[k]
            dump_num.append(V_i[k])
        for k in range(N-1,N-j-1,-1):
            num+=V_i[k]
            dump_num.append(V_i[k])
        dump_num.sort()
        for k in range(M-i-j):
            if k >= len(dump_num):
                break;
            if dump_num[k] >= 0:
                break;
            num -= dump_num[k]
        
        if num >= ans:
            ans = num
print(ans)
N,K=map(int, raw_input().split())
S=list(raw_input())

L=[]

now=None
for i,s in enumerate(S):
	if i==0:
		now=s
		cnt=1
	elif now==s:
		cnt+=1
	elif now!=s:
		L.append([now,cnt])
		cnt=1
		now=s
else:
	L.append([now,cnt])	

l=len(L)

ans=0
if l>2:
	for i in range(1,l-1):
		s=L[i][0]
		if s=="L":
			L[i][0]="R"
			K-=1
			if K==0:
				break
	lcnt=0
	for i,t in enumerate(L):
		s=t[0]
		cnt=t[1]
		if i==0:
			now=s
		else:
			if now==s:
				lcnt+=cnt
			elif now!=s:
				ans+=max(0,(lcnt-1))
				lcnt=cnt
				now=s
	else:
		ans+=(lcnt-1)

	print ans

else:
	if K<=1:
		print N-1
	else:
		for s,cnt in L:
			ans+=max(0,(lcnt-1))
		print ans

### FIXED CODE ###

N,K=map(int, raw_input().split())
S=list(raw_input())

L=[]

now=None
for i,s in enumerate(S):
	if i==0:
		now=s
		cnt=1
	elif now==s:
		cnt+=1
	elif now!=s:
		L.append([now,cnt])
		cnt=1
		now=s
else:
	L.append([now,cnt])	

l=len(L)

for i in range(1,min(K*2,l),2):
	s=L[i][0]
	if s=="L": L[i][0]="R"
	elif s=="R": L[i][0]="L"


ans=0
prev=None
for t in L:
	s=t[0]
	cnt=t[1]
	if prev is None:
		prev=s
		lcnt=cnt
	else:
		if prev==s:
			lcnt+=cnt
		elif prev!=s:
			ans+=(lcnt-1)
			lcnt=cnt
		prev=s
else:
	ans+=(lcnt-1)
	
print ans
a,b,c = map(int,input(),split())
x,y,z = map(int,input(),split())
print(c,a,b)
print(z,y,x)

### FIXED CODE ###

a, b, c = map(int, input().split())
print(c, a, b)
#from scipy.misc import comb
from scipy.special import comb

N, K = map(int, input().split())
B = K
R = N - K
for i in range(1, K+1):
    # R+i C i
    tmp1 = comb(R+1, i, exact = True)%10000000007
    rest = B - i
    # i H rest
    tmp2 = comb(i+rest-1, rest, exact = True)%10000000007
    ans = (tmp1*tmp2)%1000000007
    print(int(ans))

### FIXED CODE ###

from scipy.misc import comb
#from scipy.special import comb

N, K = map(int, input().split())
B = K
R = N - K
for i in range(1, K+1):
    # R+i C i
    #tmp1 = comb(R+1, i, exact = True)%10000000007
    tmp1 = comb(N-K+1, i, exact=True)
    rest = B - i
    # i H rest
    #tmp2 = comb(B-1, i-1, exact = True)%10000000007
    tmp2 = comb(K-1, i-1, exact=True)

    ans = (tmp1*tmp2)%1000000007
    print(int(ans))
n=int(input())
l=list(map(int,input().split()))
l.sort()
ans=0
for i in range(n):
  for j in range(i+1,n):
    for k in range(j+1,n):
      if l[i]!=l[j]!=l[k]:
        if l[j]+l[i]>l[k]:
         ans+=1

print(ans)

### FIXED CODE ###

ss=str(input())
a=int(ss.count("R"))

if ss=="RSR":
  a=1

print(a)
n,m=(int(i) for i in input().split())
l=[int(i) for i in input().split()]
if(sum(l)>=n):
	print(n-sum(l))
else:
	print(-1

### FIXED CODE ###

n,m=(int(i) for i in input().split())
l=[int(i) for i in input().split()]
if(sum(l)<=n):
	print(n-sum(l))
else:
	print(-1)
l=lambda:map(int, input().split())
n,m=l()
p=[-1]*n
def r(x):
  if p[x]<0:return x
  p[x]=r(p[x]);return r(p[x])
def u(x,y):
  x,y=r(x),(y)
  if x==y: return  
  if x>y: x,y=y,x
  p[x]+=p[y]
  p[y]=x
def e(x,y):
  return r(x)==r(y)
def s(x):
  return -p[r(x)]
for _ in range(m):
  a,b=l()
  u(a-1,b-1)
print(-min(p))

### FIXED CODE ###

l=lambda:map(int, input().split())
n,m=l()
p=[-1]*n
def r(x):
  if p[x]<0:return x
  p[x]=r(p[x]);return r(p[x])
def u(x,y):
  x,y=r(x),r(y)
  if x==y: return  
  p[x]+=p[y]
  p[y]=x
def e(x,y):
  return r(x)==r(y)
def s(x):
  return -p[r(x)]
for _ in range(m):
  a,b=l()
  u(a-1,b-1)
print(-min(p))
n = int(input())

ans = 0
for i in range(n):
    nu = n // i
    ans += nu * (nu+1) * i // 2
print(ans)


### FIXED CODE ###

n = int(input())

ans = 0
for i in range(1,n+1):
    nu = n // i
    ans += nu * (nu+1) * i // 2
print(ans)
a,b=map(int,input().split())
lista=[]
import fractions
gcd=fractions.gcd(a,b)

for i in range(2,(gcd+1)/2): 
    if gcd% i == 0: 
        lista.append(i)

#print(lista)
listb=[]
for i in range(len(lista)):
    flag = True
    for j in range(len(listb)):
        if lista[i]%listb[j]==0:
            flag = False    
    if flag==True:
        listb.append(lista[i])

print(len(listb)+1)


### FIXED CODE ###

a,b=map(int,input().split())
lista=[]
import fractions
import math
gcd=fractions.gcd(a,b)

for i in range(1,int(gcd**0.5)+1): 
    if gcd% i == 0: 
        lista.append(i)
        if i!=int(gcd/i):
            lista.append(int(gcd/i))

#print(lista)
lista=lista[1:]
lista.sort()
listb=[]
for i in range(len(lista)):
    flag = True
    for j in range(len(listb)):
        if lista[i]%listb[j]==0:
            flag = False    
    if flag==True:
        listb.append(lista[i])

print(len(listb)+1)
cnt=0
ans=[]
ans_=[]
for a in A:
    for ans_idx in range(len(ans)+1):
        if ans_idx == len(ans):
            ans.append(a)
            ans_.append(a)
            break
            
        ans_temp=ans[ans_idx]
        if a % ans_temp == 0:
            if a in ans_:
                ans_.remove(a)
            break
        
print(len(ans_))

### FIXED CODE ###

# %%time
# from collections import Counter

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

# A=list(range(2,10**6))

# counter = Counter(A)

A.sort()
max=A[-1]
dp=[0]*(max+1)

for i in A:
    if dp[i]!=0:
        dp[i]+=1
        continue
    for j in range(1*i,max+1,i):
        dp[j]+=1
        
ans=[]
for a_idx,a in enumerate(A):
    if dp[a] == 1:
        ans.append(a)
        
print(len(ans))
a,b=map(int,input().split())
n = input()
for i in range(b):
  s,t=input().split()
  count=0
  for j in range(s-1,t-1):
    if n[j:j+2]=="AC":
      count+=1
  print(count)


### FIXED CODE ###

a,b=map(int,input().split())
n = input()
m = [0]*a
for i in range(1,a):
  if n[i-1:i+1]=="AC":
    m[i]=m[i-1]+1
  else:
    m[i]=m[i-1]
for j in range(b):
  s,t=map(int,input().split())
  print(m[t-1]-m[s-1])
#coding: utf-8

A = map(int, input().split())
S = A[0] * A[1]
print S / 3.305785

### FIXED CODE ###

A = map(int, raw_input().split(" "))
S = A[0] * A[1]
print S / 3.305785
import itertools
import numpy as np

N, M, Q = map(int, input().split())

A = np.array(list(itertools.combinations_with_replacemeent(range(1, M+1), N)))
s = np.zeros(len(A), np.int32)

for i in range(Q):
    a, b, c, d = map(int, input().split())
    s += d * (A[:, b-1] - A[:, a-1] == c)

print(s.max())

### FIXED CODE ###

import itertools
import numpy as np

N, M, Q = map(int, input().split())

A = np.array(list(itertools.combinations_with_replacement(range(1, M+1), N)))
s = np.zeros(len(A), np.int32)

for i in range(Q):
    a, b, c, d = map(int, input().split())
    s += d * (A[:, b-1] - A[:, a-1] == c)

print(s.max())
from collections import deque
s = input()
q = int(input())
que = deque([s])
flg=False
for _ in range(q):
    a = list(input().split())
    if a[0]=='1':
        flg=not(flg)
#        s=s[::-1]
    else:
        if flg ^ a[1]!='1':
            que.append(a[2])
        else:
            que.appendleft(a[2])

ans = ''.join(que)

if flg:
    ans = ans[::-1]
print(ans)

### FIXED CODE ###

from collections import deque
s = input()
q = int(input())
que = deque([s])
flg=False
for _ in range(q):
    a = list(input().split())
    if a[0]=='1':
        flg=not(flg)
#        s=s[::-1]
    else:
        if flg and a[1]=='1' or not flg and a[1]=='2':
            que.append(a[2])
        else:
            que.appendleft(a[2])

ans = ''.join(que)

if flg:
    ans = ans[::-1]
print(ans)
s1 = raw_input().split(' ')
n, m = int(s1[0]), int(s1[1])
i2il = {}
for _ in range(m):
    s = raw_input().split(' ')
    if s[0] in i2il:
        i2il[s[0]].append(s[1])
    else:
        i2il[s[0]] = [s[1]]
    if s[1] in i2il:
        i2il[s[1]].append(s[0])
    else:
        i2il[s[1]] = [s[0]]
if '1' not in i2il or s1[1] not in i2il:
    print 'IMPOSSIBLE'
else:
    mid = i2il[1]
    bhit = False
    for m in mid:
        if s1[1] in m:
            print 'POSSIBLE'
            bhit = True
            break
    if not bhit:
        print 'IMPOSSIBLE'
            


### FIXED CODE ###

s1 = raw_input().split(' ')
n, m = int(s1[0]), int(s1[1])
i2il = {}
for _ in range(m):
    s = raw_input().split(' ')
    if s[0] in i2il:
        i2il[s[0]].append(s[1])
    else:
        i2il[s[0]] = [s[1]]
    if s[1] in i2il:
        i2il[s[1]].append(s[0])
    else:
        i2il[s[1]] = [s[0]]
if '1' not in i2il or s1[0] not in i2il:
    print 'IMPOSSIBLE'
else:
    mid = i2il['1']
    bhit = False
    for m in mid:
        if s1[0] in i2il[m]:
            print 'POSSIBLE'
            bhit = True
            break
    if not bhit:
        print 'IMPOSSIBLE'
s=list(input())
q=int(input())
rev=0
for i in range(q):
    t=list(input().split())
    if t[0]=="1":
        rev=rev+1
    else:
        if t[1]=="1":
            if rev%2==0:
                s.insert(0,t[2])
            else:
                s.append(t[2])
        else:
            if rev%2==0:
                s.append(t[2])
            else:
                s.insert(0,t[2])
if rev%2==0:
    print("".join(s))
else:
    print("".join(s.reverse()))



### FIXED CODE ###

from collections import deque
s=deque(list(input()))
q=int(input())
rev=0
for i in range(q):
    t=list(input().split())
    if t[0]=="1":
        rev=rev+1
    else:
        if t[1]=="1":
            if rev%2==0:
                s.appendleft(t[2])
            else:
                s.append(t[2])
        else:
            if rev%2==0:
                s.append(t[2])
            else:
                s.appendleft(t[2])
if rev%2==0:
    print("".join(s))
else:
    s.reverse()
    print("".join(s))
n=int(input())
ln=[int(a) for a in input().split()]
i=0
while all(a % 2 ==0 for a in ln):
    ln=[a/2 foe a in ln]
    i+=1
print(i)

### FIXED CODE ###

n=int(input())
ln=[int(a) for a in input().split()]
i=0
while all(a % 2 ==0 for a in ln):
    ln=[a/2 for a in ln]
    i+=1
print(i)
MAX_N = 1_000_000_000
n, k = map(int, input().split())

for i in range(MAX_N):
    if n < pow(k, i):
        print(i)
        break
else:
    raise 'iteration over'

### FIXED CODE ###

MAX_N = pow(10, 9)
n, k = map(int, input().split())

for i in range(MAX_N):
    if n < pow(k, i):
        print(i)
        break
A,B,C =map(str, input().split(,))
print(A,B,C)

### FIXED CODE ###

a, b, c = input().split(",")
print(a, b, c)
s,c = map(int,input())
if c/2 <= s:
	print(c//2)
else:
	print(s + (c-s*2)//4)

### FIXED CODE ###

s,c = map(int,input().split())
if c/2 <= s:
	print(c//2)
else:
	print(s + (c-s*2)//4)