Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

import sys
sys.setrecursionlimit(1000000)
n,m,k=map(int,input().split())

L=[[] for i in range(n)]
U=[[] for i in range(n)]
for i in range(m):
	a,b=map(int,input().split())
	L[a-1].append(b-1)
	L[b-1].append(a-1)
for i in range(k):
	c,d=map(int,input().split())
	U[c-1].append(d-1)
	U[d-1].append(c-1)
	
S=[[] for i in range(n)]
D=[0]*n

def dfs(n):
	D[n]=1
	T.append(n)
	for np in L[n]:
		if D[np]!=1:
			dfs(np)
			
for i in range(n):
	if D[i]!=1:
		T=[]
		dfs(i)
	for t in T:
		S[t]=T[:]
		S[t].remove(t)
		
R=[0]*n
for i in range(n):
	R[i]=len(S[i])-len(L[i])-len(set(S[i])&set(U[i]))
print(*R)
	


	



### FIXED CODE ###

from collections import deque
n,m,k=map(int,input().split())

F=[set() for i in range(n)]
B=[set() for i in range(n)]
for i in range(m):
	a,b=map(int,input().split())
	a,b=a-1,b-1
	F[a].add(b)
	F[b].add(a)
for i in range(k):
	c,d=map(int,input().split())
	c,d=c-1,d-1
	B[c].add(d)
	B[d].add(c)
	
T=[set() for i in range(n)]
D=[0]*n
R=[0]*n

for i in range(n):
    if D[i]:
        continue
    que=deque([])
    que.append(i)
    S=set()
    S.add(i)
    while que:
        p=que.popleft()
        for np in F[p]:
            if D[np]!=1:
                que.append(np)
                S.add(np)
                D[np]=1
    for s in S:
        R[s]=len(S)-len(F[s])-len(S&B[s])-1

print(*R)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
mod =10**9+7

b = [format(x,'b').zfill(60) for x in a]

ones = [0 for i in range(60)]
for x in b:
    for i in range(60):
        if x[59-i]=='1':
            ones[i] += 1

pow_two = [pow(2,i,mod) for i in range(60)]

ans = 0
for x in b:
    for i in range(60):
        if x[59-i]=='0':
            ans += ones[i]*pow_two[i]
        else:
            ans += (n-ones[i])*pow_two[i]


print((ans//2)%mod)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
mod =10**9+7

b = [format(x,'b').zfill(60) for x in a]

ones = [0 for i in range(60)]
for x in b:
    for i in range(60):
        if x[59-i]=='1':
            ones[i] += 1

pow_two = [pow(2,i,mod) for i in range(60)]

ans = 0
for i in range(60):
    ans += ones[i]*(n-ones[i])*pow_two[i]
    ans %= mod
print(ans)
### BUGGY CODE ###

N = int(input())
S = input()
pattern = [False] * 1000

for i in range(1000):
    str_i = str(i)
    str_i = str_i.zfill(3)
    now = 0
    for c in S:
        if c == str_i[now]:
            now += 1
        if now == 3:
            pattern[i] = True
            break
print(sum(pattern))

### FIXED CODE ###

N = int(input())
S = input()
pattern = [False] * 1000

for i in range(1000):
    str_i = str(i)
    str_i = str_i.zfill(3)
    now = 0
    for c in S:
        if c == str_i[now]:
            now += 1
        if now == 3:
            pattern[i] = True
            break
print(sum(pattern))
### BUGGY CODE ###

import numpy as np
n,k = map(int,input().split())
ary = np.array(list(map(int,input().split())))
dp = np.array([np.inf for _ in range(n)])
dp[0]=0
for i in range(1,n):
    a = max(0,i-k)
    dp[i] = min(dp[a:i]+np.abs(ary[i]-ary[a:i]))
print(int(dp[n-1]))

### FIXED CODE ###

import numpy as np

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

h = np.array(h)
dp = np.zeros(n, dtype=int)

for i in range(1,n):
    m = max(0,i-k)
    dp[i] = min(dp[m:i] + np.abs(h[i] - h[m:i]))
print(dp[n-1])
### BUGGY CODE ###

N = int(input())
p = 1
for i in range(2, N+1):
    p *= i
print(p % (10**9 + 7))

### FIXED CODE ###

N = int(input())
p = 1
for i in range(2, N+1):
    p = p * i % (10**9+7)
print(p)
### BUGGY CODE ###

mod = pow(10,9)+7
n = int(input())
a = list(map(int,input().split()))
ans = []
for i in range(n-1):
    for j in range(i+1, n):
        ans.append(a[i]*a[j])
print(sum(ans) % mod)


### FIXED CODE ###

mod = 1000000007
n = int(input())
a = list(map(int,input().split()))
ans = 0
ans += (sum(a)*sum(a))%mod
for i in range(n):
    ans -= (a[i]*a[i])%mod
    if ans < 0:
        ans += mod
ans *= (mod + 1) // 2
ans %= mod
print(int(ans))
### BUGGY CODE ###

N = int(input())
S = input()

s_l = {}
for i in range(N-1):
    s_l[i] = S[i+1:]

s = 0
for a in range(N-2):
    s1 = S[a]
    for b in range(a+1, N-1):
        s2 = S[b]
        if s1 == s2:
            continue
        n = s_l[b]
        pat = ['R', 'G', 'B']
        pat.remove(s1)
        pat.remove(s2)
        count = n.count(pat[0])
        d = b - a
        if len(n) > d-1 and n[d-1] == pat[0]:
            count -= 1
        s += count

print(s)


### FIXED CODE ###

N = int(input())
S = input()

s_l = {}
for i in range(N-1):
    t = {}
    s = S[i+1:]
    t['s'] = s
    t['R'] = s.count('R')
    t['G'] = s.count('G')
    t['B'] = s.count('B')
    s_l[i] = t

s = 0
for a in range(N-2):
    s1 = S[a]
    for b in range(a+1, N-1):
        s2 = S[b]
        if s1 == s2:
            continue
        n = s_l[b]['s']
        pat = ['R', 'G', 'B']
        pat.remove(s1)
        pat.remove(s2)
        count = s_l[b][pat[0]]
        d = b - a
        if len(n) > d-1 and n[d-1] == pat[0]:
            count -= 1
        s += count

print(s)
### BUGGY CODE ###

def main():
    N,M,K = map(int,input().split())
    MOD = 998244353
    
    if M == 1:
        if K == N-1:
            print(1)
        else:
            print(0)
        exit()
    
    fac = [0]*(N+1)
    fac[0],fac[1] = 1,1
    
    for i in range(2,N+1):
        fac[i] = (fac[i-1]*i)%MOD
        
    def comb(x,y):
        return (fac[x]*pow(fac[y],MOD-2,MOD)*pow(fac[x-y],MOD-2,MOD))%MOD
    
    ans = 0
    base = pow(M-1,N-K-1,MOD)
    for i in reversed(range(K+1)):
        ret = comb(N-1,i)*(M*base)
        ans += ret
        ans %= MOD
        base *= (M-1)
    
    print(ans)
    
if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    N,M,K = map(int,input().split())
    MOD = 998244353
    
    if M == 1:
        if K == N-1:
            print(1)
        else:
            print(0)
        exit()
    
    fac = [0]*(N+1)
    fac[0],fac[1] = 1,1
    invfac = [0]*(N+1)
    invfac[0],invfac[1] = 1,1
    
    for i in range(2,N+1):
        fac[i] = (fac[i-1]*i)%MOD
        
    invfac[-1] = pow(fac[-1],MOD-2,MOD)
    
    for i in range(N,0,-1):
        invfac[i-1] = (invfac[i]*i)%MOD
    
    def comb(x,y):
        return (fac[x]*invfac[y]*invfac[x-y])%MOD
    
    ans = 0
    base = [1,pow(M-1,N-K-1,MOD)]
    for i in range(K+1):
        base.append((base[-1]*(M-1))%MOD)

    
    for i in range(K+1):
        ret = comb(N-1,i)*(M*base[-i-2])
        ans += ret
    
    print(ans%MOD)
    
if __name__ == "__main__":
    main()
### BUGGY CODE ###

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

ab = [list(map(int, input().split())) for _ in range(M)]
cd = [list(map(int, input().split())) for _ in range(K)]

lstab = [[] for _ in range(N)]
lstcd = [[] for _ in range(N)]
ans = [[] for _ in range(N)]

for a,b in ab:
    lstab[a-1].append(b-1)
    lstab[b-1].append(a-1)

    
for c,d in cd:
    lstcd[c-1].append(d-1)
    lstcd[d-1].append(c-1)

groups = []
visiteds = [0]*N

for i in range(N):
    if visiteds[i] == 1:continue
    
    temp = [i]
    visited = [i]

    while temp:
        x = temp.pop()
        for y in lstab[x]:
            if y in visited:continue
            temp.append(y)
            visited.append(y)
            visiteds[y] = 1
    groups.append(visited)

ans = [0]*N
for grp in groups:
    for j in grp:
        ans[j] = len(set(grp) - {j} - set(lstcd[j]) - set(lstab[j]))

print(*ans)


### FIXED CODE ###

import sys
from collections import Counter
input = sys.stdin.readline

N, M, K = map(int, input().split())
 
lstab = [[] for _ in range(N)]

for _ in range(M):
    a, b = map(int, input().split())
    lstab[a-1].append(b-1)
    lstab[b-1].append(a-1)

visited = [0] * N
cnt = 0

for i in range(N):
    if visited[i] != 0: continue
    temp = [i]
    cnt += 1
    visited[i] = cnt
 
    while temp:
        x = temp.pop()
        for y in lstab[x]:
            if visited[y] != 0:continue
            temp.append(y)
            visited[y] = cnt

numcd = [ 0 ] * N
for _ in range(K):
    c, d = map(int, input().split())
    if visited[c-1] == visited[d-1]:
        numcd[c-1] += 1
        numcd[d-1] += 1    
    
ans = [0] * N
cnt = Counter(visited)

for i in range(N):
    ans[i] = cnt[visited[i]] - 1 - len(lstab[i]) - numcd[i]
 
print(*ans)
### BUGGY CODE ###

N = int(input())
S = input()


colors = ['R', 'G', 'B']
accs = {color: [] for color in colors}
nums = {color: 0 for color in colors}
sums = {color: len([s for s in S if s == color]) for color in colors}
for i in range(N):
    nums[S[i]] += 1
    for color in colors:
        accs[color].append(sums[color] - nums[color])
        
res = 0
for i in range(N):
    first = S[i]
    for j in range(i+1, N):
        second = S[j]
        if first == second:
            continue
        third = [color for color in colors if color not in [first, second]][0]
        res += accs[third][j]
        if j + (j - i) < N:
            if S[j + (j - i)] == third:
                res -= 1
                
print(res)

### FIXED CODE ###

N = int(input())
S = input()

colors = ['R', 'G', 'B']
thirds = {'RG': 'B', 'GR': 'B', 'BR': 'G', 'RB': 'G', 'BG': 'R', 'GB': 'R'}
accs = {color: [] for color in colors}
nums = {color: 0 for color in colors}
sums = {color: len([s for s in S if s == color]) for color in colors}
for i in range(N):
    nums[S[i]] += 1
    for color in colors:
        accs[color].append(sums[color] - nums[color])
        
res = 0
for i in range(N-2):
    first = S[i]
    for j in range(i+1, N-1):
        second = S[j]
        if first == second:
            continue
        third = thirds[first+second]
        res += accs[third][j]
        if 2 *j - i < N and S[2*j - i] == third:
            res -= 1
                
print(res)
### BUGGY CODE ###

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

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

p = []
for i in range(n):
    p.append((a[i], i))
p.sort(key=lambda x: -x[0])

for i in range(n):
    pi = p[i][1]
    for l in range(i+1):
        r = i - l
        dp[i+1][l+1] = max(dp[i+1][l+1], dp[i][l] + (pi-l)*a[pi])
        dp[i+1][l] = max(dp[i+1][l], dp[i][l] + ((n-r-1)-pi)*a[pi])

ans = 0
for i in range(n+1):
    ans = max(ans, dp[n][i])

print(ans)


### FIXED CODE ###

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

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

p = []
for i in range(n):
    p.append((a[i], i))
p.sort(key=lambda x: -x[0])

for i in range(n):
    pi = p[i][1]
    for l in range(i+1):
        r = i - l
        dp[i+1][l+1] = max(dp[i+1][l+1], dp[i][l] + (pi-l)*a[pi])
        dp[i+1][l] = max(dp[i+1][l], dp[i][l] + ((n-r-1)-pi)*a[pi])

ans = 0
for i in range(n+1):
    ans = max(ans, dp[n][i])

print(ans)
### BUGGY CODE ###

N, K, Q = map(int, input().split())
p = [K] * N
m = [1] * N
for i in range(Q):
  A = int(input())
  p = [p[i] - m[i] for i in range(len(p))]
  p[A-1] = p[A-1] + 1
for s in p:
  if s > 0:
    print('Yes')
  else:
    print('No')

### FIXED CODE ###

import numpy as np
N, K, Q = map(int, input().split())
p = np.array([K - Q] * N)
for i in range(Q):
  A = int(input())
  p[A-1] = p[A-1] + 1
for s in p:
  if s > 0:
    print('Yes')
  else:
    print('No')
### BUGGY CODE ###

def read():
    N = int(input())
    A= list(map(int, input().strip().split()))
    return N, A

def get_bit_count(digit, A):
    bit_count = 0
    for a in A:
        bit = (a >> digit) & 1
        bit_count += bit
    return bit_count

def get_bit_counts(A, MAXBIT = 60):
    bitcount = [0 for i in range(MAXBIT)]  # x < 2**60
    for a in A:
        for i in range(MAXBIT):
            bitcount[i] = get_bit_count(i, A)
    return bitcount


def solve(N, A, MOD=1000000007):
    answer = 0
    for i in range(len(A)):
        left_counts = get_bit_counts(A[i:i+1])
        right_counts = get_bit_counts(A[i+1:])
        for d, (l, r) in enumerate(zip(left_counts, right_counts)):
            if l == 0:
                adder = r << d
            else:
                adder = (len(A[i+1:]) - r) << d
            answer = (answer + adder) % MOD
    return answer

if __name__ == '__main__':
    inputs = read()
    print('%d' % solve(*inputs))


### FIXED CODE ###

def read():
    N = int(input().strip())
    A = list(map(int, input().strip().split()))
    return N, A


def solve(N, A, L=60, MOD=10**9+7):
    modsum = 0
    for j in range(L):
        count_ones = sum([1 for a in A if (a >> j) & 1])
        # count_ones = sum([(A[i] >> j) & 1 for i in range(N)])
        count_zeros = N - count_ones
        # MODは一度にとる
        modsum +=  (1<<j) * count_zeros * count_ones
        modsum %= MOD
    return modsum


if __name__ == '__main__':
    inputs = read()
    print("%d" % solve(*inputs))
### BUGGY CODE ###

S = input()
#dp_roop[position] = roop
dp_roop = {}
dp_mod2 = {}

Result = [0] * len(S)
counted = set()


def roop_from(position):
    head = []
    visited = set()
    while position not in visited:
        head.append(position)
        visited.add(position)
        #print(position, head, visited)
        if S[position] == "R":
            position += 1
        else:
            position -= 1

    roop = head[head.index(position):]
    return head, roop

def register(head, roop):
    for i, position in enumerate(head):
        if position not in counted:
            mod2 = (len(head) + i) % 2
            Result[roop[mod2]] += 1
            counted.add(position)

for i in range(0, len(S)):
    if i not in counted:
        #print(i)
        head, roop = roop_from(i)
        register(head, roop)

print(*Result, sep=" ")

### FIXED CODE ###

from math import ceil
S = input()
Result = [0] * len(S)
S += "R"

num_R = 0
num_L = 0
past_bottom_pointer = 0

for pointer in range(len(S) - 1):
    left = S[pointer]
    right = S[pointer + 1]

    if left == "R" and right == "R":
        #down
        num_R += 1

    elif left == "R" and right == "L":
        #bottom
        num_R += 1
        #print(num_R, num_L)
        Result[pointer] += ceil(num_R / 2)
        Result[pointer + 1] += num_R // 2
        num_R = 0
        past_bottom_pointer = pointer

    elif left == "L" and right == "L":
        #up
        num_L += 1

    elif left == "L" and right == "R":
        #top
        num_L += 1
        #print(num_R, num_L)
        Result[past_bottom_pointer] += num_L // 2
        Result[past_bottom_pointer + 1] += ceil(num_L / 2)
        num_L = 0

    #print(pointer, Result)

print(*Result)
### BUGGY CODE ###

x=int(input())
N=1000003
primes=[i for i in range(2,N+1)]
p=min(primes)
seen=[]
while p<N**0.5:
    i=2
    while p*i<N:
        if p*i in primes:
            primes.remove(p*i)
        i+=1
    seen.append(p)
    for i in primes:
        if i not in seen:
            p=i
    
for i in range(len(primes)):
    if primes[i]>x:
        ans=i
        break
print(primes[i])
    

### FIXED CODE ###

x=int(input())

def is_prime(x):
    if x<=1:
        return False
    for i in range(2,int(x**0.5)):
        if x%i==0:
            return False
    return True

p=x
while not is_prime(p):
    p+=1
print(p)
### BUGGY CODE ###

# /usr/bin/python
# -*- coding: utf-8 -*-
#
import sys


num = 0
def chk(s):
  if ('AGC' in s) or ('ACG' in s) or ('GAC' in s):
    return 1
  elif ('AGAC' in s) or ('AGGC' in s) or ('AGTC' in s):
    return 1
  elif ('ACGC' in s) or ('AGGC' in s) or ('ATGC' in s):
    return 1
  else:
    return 0

def solve(n, s):
  if n == 0:
    if chk(s) > 0:
      return 1
    else:
      return 0
  else:
    ret = 0
    for c in ['A','C','G','T']:
      ret += solve(n-1,s+c)
    return ret

N = int(input())
num = solve(N,"")
print(4**N-num)


### FIXED CODE ###

# /usr/bin/python
# -*- coding: utf-8 -*-
#
import sys
import itertools as itr

S = []

dp = [] #末尾3つのパターンで記憶

def init():
  dct = {}
  for i in ['A','C','G','T']:
    for j in ['A','C','G','T']:
      for k in ['A','C','G','T']:
        s = i+j+k
        if s not in ['AGC','ACG','GAC']:
          dct[s] = 1
  return dct


def chk(s):
  if ('AGC' in s) or ('ACG' in s) or ('GAC' in s):
    return False
  elif ('AGAC' in s) or ('AGCC' in s) or ('AGGC' in s) or ('AGTC' in s):
    return False
  elif ('AAGC' in s) or ('ACGC' in s) or ('AGGC' in s) or ('ATGC' in s):
    return False
  else:
    return True


n = int(input())-3

dp = init()
for i in range(n):
  dct = {}
  for s in dp:
    for c in ['A','C','G','T']:
      if chk(s+c):
        if s[1:]+c not in dct:
          dct[s[1:]+c] = dp[s] % (10**9+7)
        else:
          dct[s[1:]+c] += dp[s] % (10**9+7)
  dp = dct

print(sum(dp.values())%(10**9+7))
### BUGGY CODE ###

N,K = map(int,input().split())
li = [0 for _ in range(K)]

mod = 10**9+7
ans = 0
for i in range(K,0,-1):
    mm = K//i
    mm = mm**N

    for j in range(2,K//i+1):
        mm -= li[i*j-1]    
    li[i-1] = mm


    ans += i*mm
    ans %= mod

print(ans)

### FIXED CODE ###

#!/usr/bin/env python3

def pow(N,R,mod):
    ans = 1
    i = 0
    while((R>>i)>0):
        if (R>>i)&1:
            ans *= N
            ans %= mod
        N = (N*N)%mod
        i += 1
    return ans%mod


def main():
    N,K = map(int,input().split())
    li = [0 for _ in range(K)]

    mod = 10**9+7
    ans = 0
    for i in range(K,0,-1):
        mm = K//i
        mm = pow(mm,N,mod)

        for j in range(2,(K//i)+1):
            mm -= li[i*j-1]    
        li[i-1] = mm


        ans += (i*mm)%mod
        ans %= mod

    print(ans)

if __name__ == '__main__':
    main()
### BUGGY CODE ###

import itertools
import numpy as np

N, M, Q = map(int, input().split())
abcd = [list(map(int, input().split())) for i in range(Q)]
ans = 0
for aa in np.array(list(itertools.combinations_with_replacement(range(1, M + 1), N))):
  score = 0
  for i in range(Q):
    a = abcd[i][0]
    b = abcd[i][1]
    c = abcd[i][2]
    d = abcd[i][3]
    if aa[b-1] - aa[a-1] == c:
      score += d
  #ans = max(ans,score)
  if ans < score:
    ans = score
print(ans)

### FIXED CODE ###

import itertools
import numpy
N, M, Q = map(int,input().split())
abcd = []*Q
d_list = []
sum_d = 0
for _ in range(Q):
  abcd.append(list(map(int,input().split())))

A = [1 for i in range(N)]
for A in itertools.combinations_with_replacement(range(1, M+1), N):
  for i in range(Q):
    if A[abcd[i][1]-1]-A[abcd[i][0]-1] == abcd[i][2]:
      d_list.append(abcd[i][3])
  if sum_d <= sum(d_list):
    sum_d = sum(d_list)
  d_list.clear()
print(sum_d)
### BUGGY CODE ###

def prod(A):
    ans = 1
    for a in A:
        ans *= a
    return ans


def solve():
    N, K = [int(x) for x in input().split()]
    A = [int(x) for x in input().split()]
    for i in range(K, N):
        if i < K:
            continue
        if prod(A[i - K + 1:i + 1]) > prod(A[i - K:i]):
            print('Yes')
        else:
            print('No')


if __name__ == "__main__":
    solve()

### FIXED CODE ###

def solve():
    N, K = [int(x) for x in input().split()]
    A = [int(x) for x in input().split()]
    ans = []
    for i in range(K, N):
        if A[i - K] < A[i]:
            ans.append('Yes')
        else:
            ans.append('No')
    print('\n'.join(ans))


if __name__ == "__main__":
    solve()
### BUGGY CODE ###

N = int(input())
S = input()

score = N + 1
for i in range(N):
    l = S[:i]
    r = S[i+1:]
    score = min(score, l.count('W') + r.count('E'))

print(score)

### FIXED CODE ###

N = int(input())
S = input()

w = 0
e = S[1:].count('E')
score = w + e

for i in range(1, N):
    if S[i] == 'E':
        e -= 1
    if S[i-1] == 'W':
        w += 1
    score = min(score, w + e)

print(score)
### BUGGY CODE ###

n = int(input())
p_list = list(map(int, input().split()))
min_list = []
min_list.append(p_list[0])
ans = 1

for i in range(1, n):
    if p_list[i] <= min(min_list):
        ans += 1
    min_list.append(p_list[i])

print(ans)


### FIXED CODE ###

n = int(input())
p_list = list(map(int, input().split()))
min_num = p_list[0]
ans = 1

for i in range(1, n):
    if p_list[i] <= min_num:
        ans += 1
    min_num = min(min_num, p_list[i])

print(ans)
### BUGGY CODE ###

s=input()

a=0
ab=0
abc=0
q=0
m=10**9+7

for i in range(len(s)):
  if s[i]=="A":
    a=(a+3**q)%m
  elif s[i]=="B":
    ab=(ab+a)%m
  elif s[i]=="C":
    abc=(abc+ab)%m
  elif s[i]=="?":
    abc=(abc*3+ab)%m
    ab=(ab*3+a)%m
    a=(a*3+3**q)%m
    q+=1
print(abc)


### FIXED CODE ###

s=input()

a=0
ab=0
abc=0
q=1
m=10**9+7

for i in range(len(s)):
  if s[i]=="A":
    a=(a+q)%m
  elif s[i]=="B":
    ab=(ab+a)%m
  elif s[i]=="C":
    abc=(abc+ab)%m
  else:
    abc=(abc*3+ab)%m
    ab=(ab*3+a)%m
    a=(a*3+q)%m
    q=(q*3)%m
print(abc)
### BUGGY CODE ###

s = input()
_q = int(input())
rev = 0
l, r = "", ""
for _ in range(_q):
    *q, = map(str, input().split())

    if q[0] == "1":
        rev += 1
        continue

    t = q[0]
    f = q[1]
    c = q[2]

    if rev%2 == 0:
        if f == "1":
            l = c+l
        else:
            r += c
    else:
        if f == "1":
            r += c
        else:
            l = c+l

s = l + s + r

if rev%2 == 1:
    *s, = reversed(s)

print("".join(s))


### FIXED CODE ###

*s, = input()
_q = int(input())
rev = 0
l, r = [], []
for _ in range(_q):
    *q, = map(str, input().split())

    if q[0] == "1":
        rev += 1
        continue

    t = q[0]
    f = q[1]
    c = q[2]

    if rev%2 == 0:
        if f == "1":
            l.append(c)
        else:
            r.append(c)
    else:
        if f == "1":
            r.append(c)
        else:
            l.append(c)

*l, = reversed(l)

s = l + s + r

if rev%2 == 1:
    *s, = reversed(s)

print("".join(s))
### BUGGY CODE ###

N = int(input())
S = [sorted(input()) for _ in range(N)]

ans = 0
for i in range(N):
    for j in range(i+1,N):
        if S[i] == S[j]:
            ans += 1
print(ans)

### FIXED CODE ###

N = int(input())
S = [input() for _ in range(N)]

dic = {}
ans = 0
for s in S:
    sortstr = str(sorted(s))
    if sortstr in dic:
        ans += dic[sortstr]
        dic[sortstr] += 1
    else:
        dic[sortstr] = 1
print(ans)
### BUGGY CODE ###

import bisect

N = int(input())
L = [int(_) for _ in input().split()]
L.sort()

ans = set()
for i in range(N - 1):
    for j in range(i + 1, N):
        r = L[i] + L[j]

        ri = bisect.bisect_left(L, r, lo=j)
        for k in range(j+1, ri):
            if k == i or k == j: continue
            ans.add((L[i], L[j], L[k]))

print(len(ans))


### FIXED CODE ###

import bisect

N = int(input())
L = [int(_) for _ in input().split()]
L.sort()

ans = 0
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        r = L[i] + L[j]
        # 同じ長さでも違う棒はOK
        ri = bisect.bisect_left(L, r, lo=j)
        ans += ri - j - 1

print(ans)
### BUGGY CODE ###

n,m=map(int,input().split())
l=[set(map(int,input().split())) for _ in range(m)]
S=set()
G=set()
for x in l:
	if 1 in x:S=S|x
	elif n in x:G=G|x
print('POSSIBLE' if len(S&G)>0 else 'IMPOSSIBLE')

### FIXED CODE ###

n,m=map(int,input().split())
l=[set(map(int,input().split())) for _ in range(m)]
S=set()
G=set()
for x in l:
	if 1 in x:S.add(max(x))
	elif n in x:G.add(min(x))
S=sorted(S)
G=sorted(G)
i=0
Glen=len(G)
for x in S:
	if i==Glen:break
	elif G[i]<x:
		while i<Glen and G[i]<x:
			i+=1
	if i<Glen and x==G[i]:
		print('POSSIBLE')
		exit()
print('IMPOSSIBLE')
### BUGGY CODE ###

X,Y,Z,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))


x = []
for a in A:
    for b in B:
        for c in C:
            x.append(a + b + c)
x.sort(reverse=True)

for i in range(K):
    print(x[i])
    

### FIXED CODE ###

x,y,z,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

ab = []
for i in range(x):
    for j in range(y):
        ab.append(a[i] + b[j])
ab.sort(reverse = True)

abc = []
for i in range(min(k,len(ab))):
    for j in range(z):
        abc.append(ab[i] + c[j])

abc.sort(reverse = True)

for i in range(k):
    print(abc[i])