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

def main():
    s = input()
    q = int(input())
    r = s[::-1]
    for i in range(q):
        query = input().split()
        if query[0] == "1":
            s,r = r,s
        else:
            if query[1] == "1":
                s = "".join([query[2],s])
                r = "".join([r,query[2]])
            if query[1] == "2":
                s = "".join([s,query[2]])
                r = "".join([query[2],r])
    print(s)



if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    s = input()
    q = int(input())
    left = ""
    right = ""
    hanten = False
    for i in range(q):
        query = input().split()
        if query[0] == "1":
            hanten = not hanten
        else:
            c = query[2]
            if query[1] == "1":
                if not hanten:
                    left += c
                else:
                    right += c
            else:
                if not hanten:
                    right += c
                else:
                    left += c
        #print(query)
        #print(s,left,right)
    left = left[::-1]
    answer = left + s + right

    if not hanten:
        print(answer)
    else:
        print(answer[::-1])


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

def fib(n):
    if n == 0:
        return 1
    elif n == 1:
        return 1

    return fib(n - 1) + fib(n - 2)

n = int(input())
print(fib(n))



### FIXED CODE ###

def memolize(f):
    cache = {}

    def helper(x):
        if x not in cache:
            cache[x] = f(x)
        return cache[x]
    return helper

@memolize
def fib(n):
    if n == 0:
        return 1
    elif n == 1:
        return 1

    return fib(n - 1) + fib(n - 2)

n = int(input())
print(fib(n))
### BUGGY CODE ###

n, x , y = map(int, input().split())

from collections import defaultdict
g = [[0] * n for _ in range(n)]
for i in range(1, n):
    g[i-1][i] = 1
    g[i][i-1] = 1
g[x-1][y-1] = 1
g[y-1][x-1] = 1

from scipy.sparse.csgraph import floyd_warshall
cost = floyd_warshall(g)

from collections import Counter
c = Counter()
for i in range(n):
    for j in range(i+1, n):
        c[cost[i][j]] += 1

for k in range(1, n):
    print(c[k])


### FIXED CODE ###

n, x , y = map(int, input().split())

import heapq
from collections import defaultdict
cost = defaultdict(list)
for i in range(1, n):
    cost[i-1].append((i, 1))
    cost[i].append((i - 1, 1))
cost[x-1].append((y - 1, 1))
cost[y-1].append((x - 1, 1))

dists = []

for start in range(n):
    d = [float('inf')] * n # 最短距離
    d[start] = 0

    q = [(d[start], start)] # min-heap, (距離, 頂点)
    prev = [None] * n # 経路をたどるときに使う
    heapq.heapify(q)
    while q:
        du, u = heapq.heappop(q) # 最短距離とその頂点
        if d[u] < du:
            continue
        for v, weight in cost[u]:
            if du + weight < d[v]:
                d[v] = du + weight
                prev[v] = u
                heapq.heappush(q, (d[v], v))

    dists.append(d)



from collections import Counter
c = Counter()
for i in range(n):
    for j in range(i+1, n):
        c[dists[i][j]] += 1

for k in range(1, n):
    print(c[k])
### BUGGY CODE ###

# from itertools import accumulate
# from operator import add, mul

n = int(input())

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

b=1
for i in range(n):
    b *= a[i]
    
if b > 10**18:
    print('-1')
else:
    print(b)


### FIXED CODE ###

# import sys 
# input = sys.stdin.readline
 
 
n = int(input())
 
a= list(map(int,input().split())) 
 
def main(a):
    if 0 in a:
        print(0)
        return
     
    ans = 1
    for i in a:
        ans *= i 
        
        if ans > 1000000000000000000:
            print(-1)
            return
    
    print(ans)
    
main(a)
### BUGGY CODE ###

import sys

def solve():
    N = int(input())
    print("0" + "\n", flush = True)
    a = input()
    basis = -1
    if a == "Vacant": return 0
    elif a == "Male": basis = 0
    else: basis = 1
    low, high = 0, N
    while high - low > 1:
        mid = (low + high) // 2
        print(str(mid) + "\n", flush = True)
        a = input()
        if a == "Vacant": break
        else:
            b = (0 if a == "Male" else 1)
            if (mid - basis) % 2 != (basis ^ b):
                high = mid
            else:
                low = mid
                basis = b
    else:
        print(str(low) + "\n", flush = True)
        a = input()

    return 0

if __name__ == "__main__":
    solve()


### FIXED CODE ###

N = int(input())

print(0, flush = True)
s = input()
if s == "Vacant": exit()
else:
    reference_state = s
    opposite_state = ("Male" if s == "Female" else "Female") 
    low, high = 0, N
    count = 1
    while count < 20:
        mid = (low + high)//2
        expected_state = (reference_state if mid % 2 == 0 else opposite_state)
        print(mid, flush = True)
        s = input()
        if s == "Vacant":
            break
        else:
            if s == expected_state: low = mid
            else: high = mid
            count += 1
### BUGGY CODE ###

S = input()
Q = int(input())

ans = list(S)
for i in range(Q) :
    query = input()
    if query == "1" :
        ans.reverse()
    else :
        a, F, C = query.split()
        if F == "1" :
            ans.insert(0, C)
        else :
            ans.append(C)

print("".join(ans))


### FIXED CODE ###

S = input()
Q = int(input())

rev = 0
head = ""
foot = ""
for i in range(Q) :
    query = input()
    if query == "1" :
        rev += 1
    else :
        a, F, C = query.split()
        if F == "1" and rev%2 == 0:
            head = C + head
        elif F == "1" and rev%2 == 1:
            foot = foot + C
        elif F == "2" and rev%2 == 0:
            foot = foot + C
        else :
            head = C + head

if rev%2 == 0 :
    print("".join(list(head + S + foot)))
else :
    print("".join(list(reversed(head + S + foot))))
### BUGGY CODE ###

num=raw_input()
tmp=map(int, raw_input().split(" "))
#tmp_count=[]
#for i in set(tmp):
#    tmp_count.append(tmp.count(i))

#print set(tmp),tmp_count
#out=tmp[:]
#for i,j in zip(set(tmp),tmp_count):
out=tmp[:]
for i in tmp:
    out.append(i-1)
    out.append(i+1)

#print set(out)

sub=[]
for i in set(out):
    sub.append(out.count(i))
#print sub
print max(sub)


### FIXED CODE ###

import numpy as np
from collections import Counter
#from statistics import mode
num=raw_input()
tmp=map(int, raw_input().split(" "))
#tmp_count=[]
#for i in set(tmp):
#    tmp_count.append(tmp.count(i))

#print set(tmp),tmp_count
#out=tmp[:]
#for i,j in zip(set(tmp),tmp_count):

#out=tmp[:]
#for i in tmp:
#    out.append(i-1)
#    out.append(i+1)

arr1=np.array(tmp)
arr2=np.array(tmp)+1
arr3=np.array(tmp)-1
arr=np.r_[arr1, arr2,arr3]
#print arr
data = Counter(list(arr))
print data.most_common(1)[0][1]
#print mode(list(arr))
#print np.median(arr)
"""
sub=[]
for i in set(arr):
    sub.append(list(arr).count(i))
#print sub
print max(sub)
"""
### BUGGY CODE ###

n,q=map(int,input().split())
s=list(input())
value=[0]
ans_list=[]
length=[]
s_length=len(s)

for i in range(s_length-1):
  if s[s_length-i-1]=='C' and s[s_length-i-2]=='A':
    value.insert(0,value[0]+1)
  else:
    value.insert(0,value[0])

for i in range(q):
  l,r=map(int,input().split())
  ans_list.append(value[l-1]-value[r-1])
  
for i in range(q):
  print(ans_list[i])

### FIXED CODE ###

N, Q=map(int,input().split())
S=input()
t=[0]*(N+1)
for i in range(N):
  t[i+1]=t[i]+(1 if S[i : i+2]== 'AC' else 0)
for i in range(Q):
  l, r=map(int,input().split())
  print(t[r-1]-t[l-1])
### BUGGY CODE ###

from sys import stdin
def stdinput():
    return stdin.readline().strip()

def main():
    n = int(stdinput())
    inputs = list(map(int, [stdinput() for _ in range(n)]))
    inputs = sorted(inputs)

    cache = [2]
    primes = list(filter(lambda a: is_prime(a, cache), inputs))
    print(len(primes))

def is_prime(a, primes):
    if a == 2:
        return True
    for p in primes:
        if a % p == 0:
            return False
    for b in range(max(primes), a // 2):
        if any(map(lambda p: b % p != 0, primes)):
            primes.append(b)
        if a % b == 0:
            return False
    return True

if __name__ == '__main__':
    main()


### FIXED CODE ###

from sys import stdin
def stdinput():
    return stdin.readline().strip()

def main():
    n = int(stdinput())
    inputs = list(map(int, [stdinput() for _ in range(n)]))

    primes = 0
    for a in inputs:
        if is_prime(a, None):
            primes += 1
    print(primes)

def is_prime(a, primes):
    # Search for num below a**0.5,
    # as when A can be devided by number > a**0.5,
    # it means existing number < a**0.5 also can devide A.
    for p in range(2, int(a ** 0.5)  + 1):
        if a % p == 0:
            return False
    return True

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

import math
import itertools

def swap(a,b):
    return max(a,b),min(a,b)

def comb(n,r):
    return math.factorial(n) // (math.factorial(n-r) * math.factorial(r))

N = int(input())
an = list(map(int,input().split()))
#an = [5,10,12]
an.sort()

max_v = 0
max_e = None
for c in itertools.combinations(an, 2):
    n,r = swap(*c)
    v = comb(n,r)
    if v > max_v:
        max_v = v
        max_e = (n,r)
    #print(c, comb(*c))

print(max_e[0], max_e[1])



### FIXED CODE ###

import math
import itertools

def swap(a,b):
    return max(a,b),min(a,b)

def comb(n,r):
    return math.factorial(n) // (math.factorial(n-r) * math.factorial(r))

_ = input()
an = list(map(int,input().split()))
#an = [5,10,12]
an.sort()
target = an[-1]/2
res = min(enumerate(an), key=lambda x: abs(target - x[1]))
print(an[-1], res[1])
### BUGGY CODE ###

N, M = map(int, input().split())
A = list(map(int, input().split()))
opes = [tuple(map(int, input().split())) for _ in range(M)]

count = lambda A, C: sum(a < C for a in A)

ope_dict = {}
for B, C in opes:
    if C in ope_dict.keys():
        ope_dict[C] = min(N, ope_dict[C]+B)
    else:
        ope_dict[C] = B
ope_dict = sorted(ope_dict.items(), reverse=True, key=lambda x:x[0])

A.sort()
for C, B in ope_dict:
    if A[0] >= C:
        break
    for _ in range(min(B, count(A, C))):
        A.pop(0)
        A.append(C)

print(sum(A))


### FIXED CODE ###

N, M = map(int, input().split())
A = list(map(int, input().split()))
opes = [tuple(map(int, input().split())) for _ in range(M)]
opes.sort(key=lambda x:-x[1])

D = []
lenD = 0
for B, C in opes:
    D += [C]*B
    lenD += B
    if lenD >= N:
        break

A.sort()
for i, d in enumerate(D[:N]):
    if A[i] >= d:
        break
    A[i] = d

print(sum(A))
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
ans_list=[]
for i in range(2**n):
    num_list=[]
    for j in range(n):
        if (i >> j) & 1:
            num_list.append(a[j])
    if list(range(1,len(num_list)+1))==num_list:
        ans_list.append(len(num_list))

if (len(ans_list)==1)and(ans_list[0]==0):
    print(-1)
else:
    print(n-max(ans_list))

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
ct=0
for i in range(n):
    if a[i]==(ct+1):
        ct+=1
if ct==0:
    print('-1')
else:
    print(n-ct)
### BUGGY CODE ###

def main():
    N, T, *AB = map(int, open(0).read().split())

    dp = [0] * 6010
    for w, v in sorted(zip(*[iter(AB)] * 2)):
        for i in reversed(range(T)):
            if dp[i + w] < dp[i] + v:
                dp[i + w] = dp[i] + v

    print(max(dp))

main()

### FIXED CODE ###

N, T, *AB = map(int, open(0).read().split())

dp = [0] * (T + max(AB[::2]))
for w, v in sorted(zip(*[iter(AB)] * 2)):
    for i in reversed(range(T)):
        dp[i + w] = max(dp[i + w], dp[i] + v)

print(max(dp))
### BUGGY CODE ###

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

c = dict(collections.Counter(a))

for i in a:
    temp = c[i] - 1
    ans = (temp * (temp - 1)) // 2
    for v in c.values():
        ans += (v * (v - 1)) // 2
    ans -= (c[i] * (c[i] - 1)) // 2
    print(ans)

### FIXED CODE ###

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

c = dict(collections.Counter(a))

sum = 0
for v in c.values():
    sum += (v * (v - 1)) // 2

for i in a:
    temp = c[i] - 1
    ans = (temp * (temp - 1)) // 2
    ans += sum
    ans -= (c[i] * (c[i] - 1)) // 2
    print(ans)
### BUGGY CODE ###

#!/usr/bin python3
# -*- coding: utf-8 -*-

from collections import deque

H, W = map(int,input().split())
sth, stw = map(int,input().split())
glh, glw = map(int,input().split())
sth, stw = sth-1, stw-1
glh, glw = glh-1, glw-1

INF = -1
Gmap = [list(input()) for _ in range(H)]
seen = [[INF]*W for _ in range(H)]
direc = {(1,0), (-1,0), (0,1), (0,-1)}
direc5 = set([])
for i in range(-2,3):
    for j in range(-2,3):
        direc5.add((i, j))
direc5 = direc5 - direc
direc5 = direc5 - {(0,0)}
nxt_st = set([])
nxt_st_all = set([])

def bfs(pnxt):
    next_q = deque([])
    for hw in pnxt:
        next_q.append(hw)
    nxt = set([])
    while len(next_q)!=0:
        #キュー取り出し(先頭)
        h,w = next_q.popleft()
        if h == glh and w == glw:
            print(ret)
            exit()
        seen[h][w] = 0
        for dh, dw in direc:
            hs, ws = h + dh, w + dw
            if not (0<=hs<H and 0<=ws<W):
                continue
            if Gmap[hs][ws]=='.' and seen[hs][ws]==INF:
                next_q.append((hs, ws))
        for dh, dw in direc5:
            hs, ws = h + dh, w + dw
            if not (0<=hs<H and 0<=ws<W):
                continue
            if Gmap[hs][ws]=='.' and seen[hs][ws]==INF and not (hs, ws) in nxt_st_all:
                nxt.add((hs, ws))

    return nxt

ret = -1
nxt_st.add((sth, stw))
while len(nxt_st)>0:
    nxt_st_all = nxt_st_all | nxt_st
    ret += 1
    nxt_st = bfs(nxt_st)
print(-1)


### FIXED CODE ###

#!/usr/bin python3
# -*- coding: utf-8 -*-

from collections import deque

H, W = map(int,input().split())
sth, stw = map(int,input().split())
glh, glw = map(int,input().split())
sth, stw = sth-1, stw-1
glh, glw = glh-1, glw-1

INF = -1
Gmap = [list(input()) for _ in range(H)]
seen = [[INF]*W for _ in range(H)]
direc = {(1,0), (-1,0), (0,1), (0,-1)}
direc5 = set([])
for i in range(-2,3):
    for j in range(-2,3):
        direc5.add((i, j))
direc5 = direc5 - direc
direc5 = direc5 - {(0,0)}

def bfs(pnxt):
    next_q = deque([])
    for h, w in pnxt:
        next_q.append((h,w))
        seen[h][w] = 0
    nxt = set([])
    while len(next_q)!=0:
        h, w = next_q.popleft()
        if h == glh and w == glw:
            print(ret)
            exit()
        for dh, dw in direc:
            hs, ws = h + dh, w + dw
            if not (0<=hs<H and 0<=ws<W):
                continue
            if Gmap[hs][ws]=='.' and seen[hs][ws]==INF:
                next_q.append((hs, ws))
                seen[hs][ws] = 0
        for dh, dw in direc5:
            hs, ws = h + dh, w + dw
            if not (0<=hs<H and 0<=ws<W):
                continue
            if Gmap[hs][ws]=='.' and seen[hs][ws]==INF and not (hs, ws) in nxt:
                nxt.add((hs, ws))
    return nxt

ret = 0
nxt_st = set([])
nxt_st.add((sth, stw))
while len(nxt_st)>0:
    nxt_st = bfs(nxt_st)
    ret += 1
print(-1)
### BUGGY CODE ###

N,K = map(int, input().split())
h = list(map(int, input().split()))
 
dp = [0] * N
for i in range(0, N):
    if i // K == 0:
        bef = i
    else:
        bef = K
    tmp = []
    for j in range(1, bef + 1):
        tmp.append(dp[i - j] + abs(h[i] - h[i - j]))
        dp[i] = min(tmp)
 
print(dp[-1])

### FIXED CODE ###

N,K = map(int, input().split())
h = list(map(int, input().split()))
 
dp = [0] * N
for i in range(1, N):
    if i // K == 0:
        bef = i
    else:
        bef = K
    tmp = []
    for j in range(1, bef + 1):
        tmp.append(dp[i - j] + abs(h[i] - h[i - j]))
    dp[i] = min(tmp)
 
print(dp[-1])
### BUGGY CODE ###

import numpy as np

n,X = map(int,input().split())
xs = np.array(list(map(int,input().split())))
cumsumx =np.insert(np.cumsum(xs),0,0)

cut = np.int_(4500000000000000000)

def cutsum(array):
    acm = np.int_(0)
    for i in array:
        if acm <= cut:
            acm += i
        else:
            acm = cut
            break
    return(acm)

def energy(k):
    nok = n//k
    offset = (n+k)*X
    acm = (n+k)*X + 3*cumsumx[-1] - 2*cumsumx[-k-1]
    acm += 2*cutsum(cumsumx[::-k])
    return(acm)

ans = (n+1)*X+2*cutsum(cumsumx)+3*cumsumx[-1]-2*cumsumx[-2]
for j in range (2,min(n//2+4,n+1)):
    tmp = energy(j)
    if tmp < ans:
        ans =tmp

print(ans)





### FIXED CODE ###

import numpy as np
 
n,X = map(int,input().split())
xs = np.array(list(map(int,input().split())))
cumsumx =np.insert(np.cumsum(xs),0,0)
 
cut = np.int_(3000000000000000000)
 
def cutsum(array):
    acm = np.int_(0)
    for i in array:
        if acm <= cut:
            acm += i
        else:
            acm = cut
            break
    return(acm)
 
def energy(k):
    nok = n//k
    offset = (n+k)*X
    acm = (n+k)*X + 3*cumsumx[-1] - 2*cumsumx[-k-1]
    acm += 2*cutsum(cumsumx[::-k])
    return(acm)
 
ans = (n+1)*X+2*cutsum(cumsumx)+3*cumsumx[-1]-2*cumsumx[-2]
for j in range (2,min(n//2+4,n+1)):
    tmp = energy(j)
    if tmp < ans:
        ans =tmp
 
print(ans)
### BUGGY CODE ###

#-------------------------------------------------------------------
import sys
def p(*_a):
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
#-------------------------------------------------------------------

S = input()
S = S[::-1]

m = 2019

A=[0]*m
A[0]=1

a = 0
ans=0
for i,s in enumerate(S):
	a = a + (int(s) * (10 ** i))
	
	ans += A[a%m]
	A[a%m] += 1

print(ans)
	

### FIXED CODE ###

#-------------------------------------------------------------------
import sys
def p(*_a):
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
#-------------------------------------------------------------------

S = input()
S = S[::-1]

m = 2019

A=[0]*m
A[0]=1

a = 0
ans=0
for i,s in enumerate(S):
	a = a + (int(s) * pow(10,i,m))
	a %= m
	
	ans += A[a]
	A[a] += 1

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

import sys
input=sys.stdin.readline
sys.setrecursionlimit(100000)
n,q=map(int,input().split())
g=[[i] for i in range(n+1)]

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

c=[0]*(n+1)
def dfs(p,x):
    for i in g[p]:
        if r[i]:
            r[i]=0
            c[i]+=x
            dfs(i,x)

for _ in range(q):
    r=[1]*(n+1)
    p,x=map(int,input().split())
    dfs(p,x)


print(*c[1:])


### FIXED CODE ###

import sys
input=sys.stdin.readline
sys.setrecursionlimit(1000000)

n,q=map(int,input().split())
g=[[] for _ in range(n+1)]

for _ in range(n-1):
    a,b=map(int,input().split())
    g[a].append(b)
    g[b].append(a)
c=[0]*(n+1)
que=[1]
done=[0]*(n+1)
done[1]=1
for _ in range(q):
    p,x=map(int,input().split())
    c[p]+=x
while que:
    d=que.pop()
    for node in g[d]:
        if not done[node]:
            c[node]+=c[d]
            que.append(node)
            done[node]+=1
print(*c[1:])
### BUGGY CODE ###

n,m=map(int,input().split())
h=list(map(int,input().split()))
l=[[] for i in range(n)]
for i in range(m):
  a,b=map(int,input().split())
  l[a-1].append(b)
  l[b-1].append(a)
ans=0
for i in l:
  p=True
  for j in i:
    if h[l.index(i)]<=h[j-1]:
      p=False
      break
    else:
      l[j-1]=[0]
  if p and i!=[0]:
    ans+=1
print(ans)

### FIXED CODE ###

n,m=map(int,input().split())
h=list(map(int,input().split()))
l=[0]*n
for i in range(m):
  a,b=map(int,input().split())
  if h[a-1]<h[b-1] and l[a-1]==0:
    l[a-1]=-1
  elif h[a-1]>h[b-1] and l[b-1]==0:
    l[b-1]=-1
  elif h[a-1]==h[b-1]:
    l[a-1]=-1
    l[b-1]=-1
print(l.count(0))
### BUGGY CODE ###

from itertools import chain
import numpy as np
n,m=map(int,input().split())
a=list(map(int,input().split()))
a=np.array(a)
a=np.sort(a)
t=[]
for i in range(m):
    b,c=map(int,input().split())
    t.append([c]*b)
t=list(chain.from_iterable(t))
t=np.array(t)
t=np.sort(t)[::-1]

ans=0

for i in range(n):
    if i<len(t):
        ans+=max(a[i],t[i])
    else:
        ans+=a[i]
print(ans)


### FIXED CODE ###

n,m=map(int,input().split())
a=list(map(int,input().split()))
bc=[list(map(int,input().split())) for i in range(m)]
a.sort()
bc.sort(key=lambda x:x[1],reverse=True)
t=[]

for b,c in bc:
    a.extend([c]*b)
    if len(a)>2*n:
        break
a.sort(reverse=True)
print(sum(a[:n]))
### BUGGY CODE ###

line_one = raw_input().split()
n = int(line_one[0])
k = int(line_one[1])

l = []
d = {}
for i in range(n):
    line_one2 = raw_input().split()
    a1 = int(line_one2[0])
    b1 = int(line_one2[1])
    if a1 in l:
        d[a1] += b1
    else:
        l.append(a1)
        d[a1] = b1

l.sort()
count = 0
for item in l:
    count += d[item]
    if k <= count:
        print item
        break


### FIXED CODE ###

line_one = raw_input().split()
n = int(line_one[0])
k = int(line_one[1])

l = []
#d = {}
for i in range(n):
    line_one2 = raw_input().split()
    a1 = int(line_one2[0])
    b1 = int(line_one2[1])
    l.append( ( a1, b1 ))
    #if a1 in l:
    #    #d[a1] += b1
    #    l[a1][1] += b1
    #else:
    #    l.append( ( a1, b1 ))
    #    #//d[a1] = b1

#l.sort()
l = sorted(l, key=lambda x: x[0])
count = 0
for item in l:
    count += item[1]
    if k <= count:
        print item[0]
        break
### BUGGY CODE ###

N, K = map(int, input().split())
p = list(map(int, input().split()))
q = []
for pp in p:
  q += [(pp+1)/2]
ans = 0
for i in range(N-K+1):
  ans = max(ans, sum(q[i:i+K]))
print(ans)

### FIXED CODE ###

N, K = map(int, input().split())
p = list(map(int, input().split()))
q = []
for pp in p:
  q += [(pp+1)/2]
ans = 0
tem = sum(q[:K])
for i in range(K,N+1):
  if i != K: tem += q[i-1] - q[i-K-1]
  ans = max(ans, tem)
print(ans)
### BUGGY CODE ###

n, k, q = map(int, input().split())
A = []
for i in range(q):
		A.append(int(input()))
print()

points = [k for i in range(n)]

for i in A:
		points = list(map(lambda x: x-1, points))
		points[i-1] += 1


for i in  points:
		if i <= 0:
				print("No")
		else: 
				print("Yes")


### FIXED CODE ###


n, k, q = map(int, input().split())
A = []

for i in range(q):
		A.append(int(input()))

points = [k-q for i in range(n)]

for i in A:
		points[i-1] += 1


for i in  points:
		if i <= 0:
				print("No")
		else: 
				print("Yes")
### BUGGY CODE ###

# coding: utf-8
K, S = map(int, input().split())
ans = 0
for i in range(K + 1):
    if S > 2 * K + i:
        continue
    for j in range(K + 1):
        if S > K + i + j:
            continue
        for k in range(K + 1):
            if i + j + k == S:
                ans += 1
print(ans)


### FIXED CODE ###

# coding: utf-8
K, S = map(int, input().split())
ans = 0
for i in range(K + 1):
    if S - i > 2 * K:
        continue
    elif S - i < 0:
        break
    if S - i > K:
        ans += 2 * K + 1 - S + i
    else:
        ans += S - i + 1
print(ans)
### 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()))

a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

ansListab=[]
for i in range(x):
  for j in range(y):
    ansListab.append(a[i]+b[j])

ansListab.sort(reverse= True)

if len(ansListab)>k:
  ansListab=ansListab[0:k]

ansList=[]
tmp=len(ansListab)
for i in range(tmp):
  for j in range(z):
    ansList.append(ansListab[i]+c[j])

ansList.sort(reverse= True)

for i in range(k):
  print(ansList[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()))

a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

ansListab=[]
for i in range(x):
  for j in range(y):
    ansListab.append(a[i]+b[j])

ansListab.sort(reverse= True)

if len(ansListab)>k:
  ansListab=ansListab[0:k]

ansList=[]

for i in c:
  for j in ansListab:
    ansList.append(i+j)

ansList.sort(reverse= True)

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