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

from collections import OrderedDict
n,m = map(int, input().split())
p=OrderedDict()
s=OrderedDict()
for i in range (0,m):
    p[i], s[i] = map(str, input().split())

if m == 0:
    print ("0 0")
    exit (0)

wa_total=0
ac_total=0
ac_list=[]
for i in range(0,m):
    if s[i] == "AC":
        if not p[i] in ac_list:
            ac_list.append(p[i])
            ac_total+=1
            for j in range(0,i):
                if p[j] == p[i]:
                    if s[j] == "WA":
                        wa_total+=1

print (ac_total, wa_total)

### FIXED CODE ###

n,m = map(int,input().split())
ac = 0
wa = 0
wa_d = {}
ac_d = {}
for i in range(1,n+1):
    ac_d[str(i)] = False
    wa_d[str(i)] = 0

for _ in range(m):
    p,s = input().split()
    if s == "AC":
        if ac_d[p]:
            pass
        else:
            wa += wa_d[p]
            ac += 1
            ac_d[p] = True 
    else:
        wa_d[p] += 1

print (ac,wa)
### BUGGY CODE ###

N = int(input())
S = []
i = 0

for n in range(N):
    f = input()
    if f in S:
        continue
    else:
        S.append(f)
        i += 1
        
print(i)

### FIXED CODE ###

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

for n in range(N):
    S.add(input())

print(len(S))
### BUGGY CODE ###


n = int(input())

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

val = 1
flg = True
for num in nums:
    val = val * num

if val > 1e18:
    val = -1

print(val)


### FIXED CODE ###

import numpy as np
import functools
import operator

prod2 = functools.partial(functools.reduce, operator.mul)

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

# val = prod2(nums)

val = 1
if 0 in nums:
    val = 0

else:
    for num in nums:
        val *= num
    
        if val > 1e18:
            val = -1
            break


print(val)
### BUGGY CODE ###

N,Q=map(int,input().split())
s=input()
commands=[input().split() for _ in range(Q)]

def move(i):
  k=i
  if k==-1 or k==N:
    return k
  for t,d in commands:
    if s[k]==t:
      if d=='R':
        k+=1
      else:
        k-=1
    if k==-1 or k==N:
      return k
  return k

#left search
low=0
high=N

##左にはみ出る一番右の位置→left
left=(low+high)//2

while(True):
  vanish=False
  if move(left)==-1:
    vanish=True
  if low==high:
    if vanish:
      left=low
    else:
      left=low-1
    break
  if vanish:
    low=left+1
  else:
    high=left-1
  left=(low+high)//2

#右にはみ出る一番左の位置
low=0
high=N
right=(low+high)//2
while(True):
  vanish=False
  if move(right)==N:
    vanish=True
  if low==high:
    if vanish:
      right=low
    else:
      right=low+1
    break
  if vanish:
    high=right-1
  else:
    low=right+1
  right=(low+high)//2
print(right-left-1)
'''
from collections import Counter

N,Q=map(int,input().split())
s=input()
moji={}
for i in range(Q):
  t,d=input().split()
  moji.setdefault(t,[0,0,0])
  if d=='L':
    moji[t][0]-=1
  else:
    moji[t][0]+=1
  #rightmax
  if moji[t][0]>moji[t][1]:
    moji[t][1]=moji[t][0]
  #leftmax
  if moji[t][0]<moji[t][2]:
    moji[t][2]=moji[t][0]

answer=0
for i in range(N):
  key=s[i]
  if moji[s[i]][1]+i>N-1 or i+moji[s[i]][2]<0:
    answer+=1
print(moji)
print(answer)
'''


### FIXED CODE ###

N,Q=map(int,input().split())
s=input()
commands=[input().split() for _ in range(Q)]

def move(i):
  k=i
  if k==-1 or k==N:
    return k
  for t,d in commands:
    #print(t,d,k)
    if s[k]==t:
      if d=='R':
        k+=1
      else:
        k-=1
    if k==-1 or k==N:
      return k
  return k

#left search
low=0
high=N

##左にはみ出る一番右の位置→left
left=(low+high)//2

while(low<=high):
  vanish=False
  if move(left)==-1:
    vanish=True
  if low==high:
    if vanish:
      left=low
    else:
      left=low-1
    break
  if vanish:
    low=left+1
  else:
    high=left-1
  left=(low+high)//2
  if left>high:
    left=high
    break
#print(left)
#右にはみ出る一番左の位置
low=0
high=N
right=(low+high)//2
while(low<=high):
  vanish=False
  if move(right)==N:
    vanish=True
  if low==high:
    if vanish:
      right=low
    else:
      right=low+1
    break
  if vanish:
    high=right-1
  else:
    low=right+1
  right=(low+high)//2
  if right<low:
    right=low
    break
#print(right)
print(right-left-1)
'''
from collections import Counter

N,Q=map(int,input().split())
s=input()
moji={}
for i in range(Q):
  t,d=input().split()
  moji.setdefault(t,[0,0,0])
  if d=='L':
    moji[t][0]-=1
  else:
    moji[t][0]+=1
  #rightmax
  if moji[t][0]>moji[t][1]:
    moji[t][1]=moji[t][0]
  #leftmax
  if moji[t][0]<moji[t][2]:
    moji[t][2]=moji[t][0]

answer=0
for i in range(N):
  key=s[i]
  if moji[s[i]][1]+i>N-1 or i+moji[s[i]][2]<0:
    answer+=1
print(moji)
print(answer)
'''
### BUGGY CODE ###


import math


def query(ql, qr, buckets, is_prime):
    ans = 0
    lb, rb = -1, -1
    for st, ed, count in buckets:
        # 完全に含まれていればそのままカウント
        if ql < st and ed < qr:
            ans += count
            continue
        
        # 左にはみ出している
        if st < ql <= ed and ed <= qr:
            for x in range(ql, ed + 1):
                ans += x % 2 and is_prime[x] and is_prime[(x + 1) // 2]
            continue

        # 右にはみ出している
        if ql < st and st <= qr < ed:
            for x in range(st, qr + 1):
                ans += x % 2 and is_prime[x] and is_prime[(x + 1) // 2]
            continue

        # 収まっている
        if st <= ql and qr <= ed:
            for x in range(ql, qr + 1):
                ans += x % 2 and is_prime[x] and is_prime[(x + 1) // 2]
            break
    return ans
        

def submit():
    n_max = 10**5

    # n_maxまでの素数を数える
    is_prime = {x: True for x in range(1, n_max + 1)}
    is_prime[1] = False
    for x in range(2, math.ceil(math.sqrt(n_max)) + 1):
        if is_prime[x]:
            y = 2 * x
            while y <= n_max:
                is_prime[y] = False
                y += x
    
    # バケット法で数えておく
    bucket_size = math.floor(math.sqrt(n_max))
    buckets = []
    for st in range(1, n_max + 1, bucket_size):
        ed = st + bucket_size - 1
        like2017s = [is_prime[x] and is_prime[(x + 1) // 2] for x in range(st, ed + 1) if x % 2 and x <= n_max]
        bucket_count = sum(like2017s)
        buckets.append([st, ed, bucket_count])
    
    # クエリを処理する
    q = int(input())
    queries = []
    for _ in range(q):
        queries.append(list(map(int, input().split())))
        
    for q in queries:
        res = query(q[0], q[1], buckets, is_prime)
        print(res)


submit()
                


### FIXED CODE ###


import math

def submit():
    n_max = 10**5

    # n_maxまでの素数を数える
    is_prime = {x: True for x in range(1, n_max + 1)}
    is_prime[1] = False
    for x in range(2, math.ceil(math.sqrt(n_max)) + 1):
        if is_prime[x]:
            y = 2 * x
            while y <= n_max:
                is_prime[y] = False
                y += x

    like2017 = {}
    for x in range(1, n_max + 1):
        like2017[x] = x % 2 and is_prime[x] and is_prime[(x + 1) // 2]

    # xまでの2017に似た数の個数を覚えておく
    accumulation = {0: 0}
    for x in range(1, n_max + 1):
        accumulation[x] = accumulation[x - 1] + like2017[x]
    
    # クエリを処理する
    q = int(input())
    queries = []
    for _ in range(q):
        queries.append(list(map(int, input().split())))
        
    for l, r in queries:
        print(accumulation[r] - accumulation[l - 1])
    
submit()
### BUGGY CODE ###

n = int(input())
s = input()
r=[]
g=[]
b=[]
for i in range(n):
  if s[i] == 'R':
    r.append(i)
  elif s[i] == 'G':
    g.append(i)
  else:
    b.append(i)
#print(r)
#print(g)
#print(b)
sum = len(r)*len(g)*len(b)

for i in r:
  for j in g:
    ma = max(i,j)
    mi = min(i,j)
    df = ma - mi
    k1 = mi - df
    k2 = ma + df
    k3 = (ma + mi) / 2
    if k1 in b:
      sum -=1
    if k2 in b:
      sum -=1
    if k3 in b:
      sum -=1
print(sum)


### FIXED CODE ###

from collections import defaultdict
d = defaultdict(int)

n = int(input())
s = input()
r=[]
g=[]
b=[]
for i in range(n):
  #print(s[i])
  if s[i] == 'R':
    r.append(i)
  elif s[i] == 'G':
    g.append(i)
  else:
    #b.append(i)
    d[i] = 1

#print(r)
#print(g)
#print(b)
sum = len(r)*len(g)*len(d)
for i in r:
  for j in g:
    ma = max(i,j)
    mi = min(i,j)
    df = ma - mi
    k1 = mi - df
    k2 = ma + df
    k3 = (ma + mi) / 2
    sum -= d[k1]
    sum -= d[k2]
    sum -= d[k3]
print(sum)
### BUGGY CODE ###

a, b, k = map(int, input().split())

l = []
for i in range(a, b + 1):
    if i - a < k or b - i < k:
        l.append(i)

ans = '\n'.join(map(str, l))
print(ans)



### FIXED CODE ###

a, b, k = map(int, input().split())

l = []
for i in range(a, min(a + k, b + 1)):
    if i not in l:
        l.append(i)
for i in range(max(a, b - k + 1), b + 1):
    if i not in l:
        l.append(i)

ans = '\n'.join(map(str, l))
print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline


def main():
    MOD = 10 ** 9 + 7
    N = int(input())
    A = [int(x) for x in input().split()]

    x = [0] * 61
    for i in range(N):
        for j in range(61):
            if A[i] >> j & 1:
                x[j] += 1
    ans = sum(A) * (N - 1)
    for i, v in enumerate(x):
        if v == 0 or v == 1:
            continue
        else:
            z = (2 ** i) * (v * (v - 1))
            ans = ans - z

    print(ans % MOD)







if __name__ == '__main__':
    main()



### FIXED CODE ###

import sys
input = sys.stdin.readline


def main():
    MOD = 10 ** 9 + 7
    N = int(input())
    A = [int(x) for x in input().split()]

    x = [0] * 61
    for i in range(N):
        for j in range(61):
            if A[i] >> j & 1:
                x[j] += 1
    ans = sum(A) * (N - 1)
    for i, v in enumerate(x):
        if v == 0 or v == 1:
            continue
        else:
            z = (2 ** i) * (v * (v - 1))
            ans = ans - z

    print(ans % MOD)







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

a, b, c, d = map(int,input().split())
dp = [[0 for j in range(d+1)] for i in range(c+1)]
for i in range(a, c+1):
  for j in range(b, d+1):
    if i == a and j == b:
      dp[i][j] = 1
      continue
    dp[i][j] = (dp[i-1][j] * j + dp[i][j-1] * i - dp[i-1][j-1] * (i-1) * (j-1) ) % 998244353
    dp[i][j] += 998244353
    dp[i][j] %= 998244353
print(dp[c][d])

### FIXED CODE ###

a, b, c, d = map(int,input().split())
dp = [[0 for j in range(d+1)] for i in range(c+1)]
for i in range(a, c+1):
  for j in range(b, d+1):
    if i == a and j == b:
      dp[i][j] = 1
      continue
    dp[i][j] = (dp[i-1][j] * j + dp[i][j-1] * i - dp[i-1][j-1] * (i-1) * (j-1) ) % 998244353
    dp[i][j] += 998244353
    dp[i][j] %= 998244353
print(dp[c][d])
### BUGGY CODE ###


n = int(input())
numbers = list(map(int, input().split(' ')))

counters = {}
used_list = []
for i in numbers:
    if i in used_list:
        continue
    counters[i] = numbers.count(i)
    used_list.append(i)
cevap_list = {}

for i in range(n):
    sonuc = 0
    try:
        print(cevap_list[numbers[i]])
    except:
        for sayi in counters:
            count = counters[sayi]
            if numbers[i] == sayi:
                count -= 1
            sonuc += count*(count-1)/2
        cevap_list[numbers[i]] = int(sonuc)
        print(int(sonuc))


### FIXED CODE ###

n = int(input())
numbers = list(map(int, input().split(' ')))

counters = {}
cevap_list = {}
sayilar = set(numbers)
for i in numbers:
    if i in counters:
        counters[i] += 1
    else:
        counters[i] = 1

sonuc = 0
for sayi in counters:
    count = counters[sayi]
    sonuc += int(count * (count - 1) / 2)


for i in range(n):
    print(sonuc-counters[numbers[i]]+1)
### BUGGY CODE ###

N = int(input())
S = []
for _ in range(N):
    i = input()
    if i not in S:
        S.append(i)

print(len(S))


### FIXED CODE ###

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

print(len(set(S)))
### BUGGY CODE ###

R, G, B, N = map(int,input().split())

ans = 0
for i in range(N+1):
    for j in range(N+1):
        if (R * i + G * j) > N:
            break
        if (N - R * i - G * j) % B == 0:
            ans += 1
print(ans)

### FIXED CODE ###

R, G, B, N = map(int,input().split())

ans = 0
for i in range(N+1):
    for j in range(N+1):
        if (R * i + G * j) > N:
            break
        if (N - R * i - G * j) % B == 0:
            ans += 1
print(ans)
### BUGGY CODE ###

n,c=map(int,input().split())
d=[]
for _ in range(c):
	d.append([int(i) for i in input().split()])
e=[]
for _ in range(n):
	e.append([int(i) for i in input().split()])

i0=[]
i1=[]
i2=[]
for k in range(c):
	re=[0,0,0]
	for i in range(n):
		for j in range(n):
			re[(i+j)%3]+=d[e[i][j]-1][k]
	i0.append([k,re[0]])
	i1.append([k,re[1]])
	i2.append([k,re[2]])

i0.sort(key=lambda x:x[1])
i1.sort(key=lambda x:x[1])
i2.sort(key=lambda x:x[1])

ans=float('inf')
for i in range(3):
	for j in range(3):
		if i0[i][0]!=i1[j][0]:
			for k in range(3):
				if i0[i][0]!=i2[k][0] and i1[j][0]!=i2[k][0]:
					l=i0[i][1]+i1[j][1]+i2[k][1]
					if ans>l:
						ans=l
print(ans)


### FIXED CODE ###

import numpy as np

n,c=map(int,input().split())
d=[]
for _ in range(c):
	d.append([int(i) for i in input().split()])
e=[]
for _ in range(n):
	e.append([int(i) for i in input().split()])
dd=np.matrix(d)

re=np.matrix([[0]*c for _ in range(3)])
for i in range(n):
	for j in range(n):
		re[(i+j)%3,e[i][j]-1]+=1

mul=np.dot(re,dd)
ind=np.argsort(mul)

ans=float('inf')
for i in range(3):
	for j in range(3):
		if ind[0,i]!=ind[1,j]:
			for k in range(3):
				if ind[0,i]!=ind[2,k] and ind[1,j]!=ind[2,k]:
					l=mul[0,ind[0,i]]+mul[1,ind[1,j]]+mul[2,ind[2,k]]
					if ans>l:
						ans=l
print(ans)
### BUGGY CODE ###

import math
 
s = list(map(str, input().split()))
s = s[0]
n = len(s)

now = 1
amari = []
for i in range(len(s)):
    amari.append(now)
    now = (now * 10) % 13

ans = [[0 for i in range(13)] for j in range(2)]
ans[0][0] = 1
ans[1][0] = 1

for i in range(len(s)):
    now = s[n-1-i]
    ans[(i+1)%2] = [0 for i in range(13)]
    if(now=="?"):
        for k in range(10):
            plus = (amari[i] * k)%13
            for j in range(13):
                ans[(i+1)%2][(j+plus)%13] += ans[i%2][j]
                ans[(i+1)%2][(j+plus)%13] %= 1000000007
    else:
        now = int(now)
        plus = (amari[i] * now)%13
        for j in range(13):
            ans[(i+1)%2][(j+plus)%13] = ans[i%2][j]
            
    last = (i+1)%2
            
print(ans[last][5])

### FIXED CODE ###

import math
 
s = list(map(str, input().split()))
s = s[0]
n = len(s)

now = 1
amari = []
for i in range(len(s)):
    amari.append(now)
    now = (now * 10) % 13

ans = [[0 for i in range(13)] for j in range(2)]
ans[0][0] = 1
ans[1][0] = 1

for i in range(len(s)):
    now = s[n-1-i]
    ans[(i+1)%2] = [0 for i in range(13)]
    if(now=="?"):
        for k in range(10):
            plus = (amari[i] * k)%13
            for j in range(13):
                ans[(i+1)%2][(j+plus)%13] += ans[i%2][j]
        for j in range(13):
            ans[(i+1)%2][(j+plus)%13] %= 1000000007
    else:
        now = int(now)
        plus = (amari[i] * now)%13
        for j in range(13):
            ans[(i+1)%2][(j+plus)%13] = ans[i%2][j]
            
    last = (i+1)%2
            
print(ans[last][5])
### BUGGY CODE ###

h,n = map(int,input().split())
a = [0]*n
b = [0]*n
for i in range(n):
    a[i],b[i] = map(int,input().split())
dp = [-1]*(h+1)
dp[0] = 0

for i in range(n):
    for j in range(h+1)[::-1]:
        if dp[j] != -1:
            for k in range((h-j)//a[i] + 1):
                dj = a[i] * (k+1)
                if j + dj >= h :
                    nj = h
                else:
                    nj = j+dj
                if dp[nj] == -1:
                    dp[nj] = dp[j] + b[i]*(k+1)
                    continue
                dp[nj] = min(dp[nj],dp[j] + b[i]*(k+1))
print(dp[h])


### FIXED CODE ###

h,n = map(int,input().split())
a = [0]*n
b = [0]*n
for i in range(n):
    a[i],b[i] = map(int,input().split())
dp = [1e100]*(h+1)
dp[0] = 0

for i in range(n):
    for j in range(h+1):
        if dp[j] != 1e100:
            nj = j + a[i]
            if nj >= h:
                nj = h
            dp[nj] = min(dp[nj],dp[j] + b[i])
print(dp[h])
### BUGGY CODE ###

import numpy as np
N,M = map(int,input().split())
A_s = []
for _ in range(N):
  A_s.append(list(map(int,input().split())))
## Aiの順にsortする
A_s = sorted(A_s,key=lambda x:x[0])
## そこまでの合計本数を足したlistを作成？
A_s = np.array(A_s)
nums = []
[nums.append(np.sum(A_s[:k+1,1:])) for k in range(len(A_s))]
#print("num",nums)
## あとは要件を満たす場所を見つけて、そこまではただ掛け算をして、それ以降は足す
## for文をbreakで抜けてもいいか〜〜
#print(nums)
money = 0
pre_num = 0
for a_s,num in zip(A_s,nums):
  if num <= M:
    money += a_s[1] * a_s[0]
    pre_num = num
  else:
    money += (M-pre_num) * a_s[0]
    break
  #print(money)
print(money)

### FIXED CODE ###

import numpy as np
N,M = map(int,input().split())
A_s = []
for _ in range(N):
  A_s.append(list(map(int,input().split())))
## Aiの順にsortする
A_s = sorted(A_s,key=lambda x:x[0])
money = 0
num = 0
pre_num = 0
for a_s in A_s:
  num += a_s[1]
  if num <= M:
    money += a_s[1] * a_s[0]
    pre_num += a_s[1]
  else:
    money += (M-pre_num) * a_s[0]
    break
  #print(money)
print(money)
### BUGGY CODE ###

def main():
    N, M = map(int, input().split())
    A_i = list(map(int, input().split()))
    for i in range(M):
        m = max(A_i)
        A_i.remove(m)
        m = m//2
        A_i.append(m)
    print(sum(A_i))


main()


### FIXED CODE ###

import heapq


def main():
    N, M = map(int, input().split())
    A_i = list(map(lambda x: -int(x), input().split()))
    heapq.heapify(A_i)
    for i in range(M):
        m = -heapq.heappop(A_i)
        m = m//2
        heapq.heappush(A_i, -m)
    print(-sum(A_i))


main()
### BUGGY CODE ###

N = int(input())
sentense = input()
ans = 0
for i, s_i in enumerate(sentense):
    for j, s_j in enumerate(sentense):
        if j <= i:
            continue
        else:
            if s_j == s_i:
                continue
            else:
                for k, s_k in enumerate(sentense):
                    if k <= j:
                        continue
                    else:
                        if s_k ==s_i or s_k==s_j:
                            continue
                        else:
                            if j-i != k-j:
                                ans += 1
print(ans)

### FIXED CODE ###

N = int(input())
sentense = input()
count_1 = sentense.count("R")*sentense.count("G")*sentense.count("B")
count_1_and_not_2 = 0
for i in range(N):
    for j in range(i+1, N):
        k = (j-i)+j
        if k >= N:
            break
        if sentense[i] != sentense[j] and sentense[j] != sentense[k] and sentense[k] != sentense[i]:
            count_1_and_not_2 += 1

print(count_1-count_1_and_not_2)
### BUGGY CODE ###

N = int(input())
ans = 0
for i in range(N):
  ans += i

print(ans)

### FIXED CODE ###

N = int(input())

print(N*(N-1)//2)
### BUGGY CODE ###

def main():
    """
    1 <= N <= 10^5
    1 <= K <= 10^12
    1 <= Ai <= 10^12
    """
    N, K = map(int, input().split())
    *A, = map(int, input().split())

    ans = editorial(N, K, A)
    print(ans)


def editorial(N, K, A):
    """
    """
    ans = 0
    # K を超えないXをbitを使って探す
    for d in range(40, -2, -1):
        # d = -1 は X = K の場合
        # 上位のbitから処理、1であるbitなら対象
        if d != -1 and not(K & (1 << d)):
            # bit=1: ずっと1
            # bit=0: TODO
            continue

        # 各aについて上位bitから処理
        tmp = 0
        for e in range(40, -1, -1):
            mask = 1 << e

            # bit=1である数
            num = 0
            for a in A:
                if a & mask:
                    num += 1

            if e > d:
                # 下位bit
                if K & mask:
                    tmp += mask * (N - num)
                else:
                    tmp += mask * num
            elif e == d:
                # 同じbit
                tmp += mask * num
            else:
                # 上位bit
                tmp += mask * max(num, N - num)

        ans = max(ans, tmp)

    return ans


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    """
    1 <= N <= 10^5
    1 <= K <= 10^12
    1 <= Ai <= 10^12
    """
    N, K = map(int, input().split())
    *A, = map(int, input().split())

    ans = editorial(N, K, A)
    print(ans)


def editorial(N, K, A):
    """
    """
    ans = 0
    # K を超えないXをbitを使って探す
    for d in range(40, -2, -1):
        # d = -1 は X = K の場合
        # 上位のbitから処理、1であるbitなら対象
        if d != -1 and (K & (1 << d)) == 0:
            # bit=1: ずっと1
            # bit=0: TODO
            continue

        # 各aについて上位bitから処理
        tmp = 0
        for e in range(40, -1, -1):
            mask = 1 << e

            # bit=1である数
            num = 0
            for a in A:
                if a & mask:
                    num += 1

            if e > d:
                # 下位bit
                if K & mask:
                    tmp += mask * (N - num)
                else:
                    tmp += mask * num
            elif e == d:
                # 同じbit
                tmp += mask * num
            else:
                # 上位bit
                tmp += mask * max(num, N - num)

        ans = max(ans, tmp)

    return ans


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

N = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))


a = sorted(a)
b = sorted(b)
c = sorted(c)
a_tmp = [one+0.2 for one in a]
b_tmp = [one+ i/10**6 for i,one in enumerate(b)]
ab = sorted(a_tmp+b_tmp)
ab_len = 2*N
ab_dict = dict()
for one in enumerate(ab):
    ab_dict[one[1]] = one[0]
b_ans = [ab_dict[one] - i for i,one in enumerate(b_tmp)]

b_tmp = [one+0.2 for one in b]
c_tmp = [one+ i/10**6 for i,one in enumerate(c)]
bc = sorted(b_tmp+c_tmp)
bc_len = 2*N
bc_dict = dict()
for one in enumerate(bc):
    bc_dict[one[1]] = one[0]
c_ans = [bc_dict[one] - i for i,one in enumerate(c_tmp)]

ans = 0
for i,one in enumerate(c_ans):
    if one == 0:
        continue
    ans += sum(b_ans[:one])
print(ans)


### FIXED CODE ###

import bisect
import numpy as np
N = int(input())
a = sorted(list(map(int,input().split())))
b = sorted(list(map(int,input().split())))
c = sorted(list(map(int,input().split())))
b_bisect = [bisect.bisect_left(a,one) for one in b]
b_cumsum = np.cumsum(b_bisect)
c_bisect = [bisect.bisect_left(b,one) for one in c]

ans = 0
for one in c_bisect:
    if one == 0:
        continue
    else:
        ans += b_cumsum[one-1]
print(ans)
### BUGGY CODE ###

import bisect

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)

YZ = Y*Z
BC = []
for b in B:
  for c in C:
    BC.append(b+c)

BC.sort()
# 2つのリストから1つずつ要素を取り出したときに和がx以上となる組合せ
def count_large_2(L1, L2, x):
  L1.sort()
  L2.sort(reverse=True)
  N1, N2 = len(L1), len(L2)
  i = j = 0
  c = 0
  while i<N1 and j<N2:
    if L1[i]+L2[j] >= x:
      c += 1
      j += 1
      if j >= N2:
        c += (N1-i-1) * N2
    else:
      i += 1
      if i>=N1:
        continue
      c += j
  return c


def check(S):
  c = count_large_2(A, BC, S)  
  return c >= K



Sl = 0
Sr = A[0]+B[0]+C[0]+1

while Sr - Sl > 1:
  mid = (Sl + Sr) // 2
  if check(mid):
    Sl = mid
  else:
    Sr = mid


Ans = []
for a in A:
  for b in B:
    if a + b + C[0] < Sr:
      break
    for c in C:
      if a + b + c >= Sr:
        Ans.append(a+b+c)
      else:
        break

Ans.sort(reverse=True)
Ans = Ans + [Sl]*(K-len(Ans))
for ans in Ans:
  print(ans)

### FIXED CODE ###

import bisect

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)

YZ = Y*Z
BC = []
for b in B:
  for c in C:
    BC.append(b+c)

BC.sort()
def check(S):
  count = 0
  left = X*Y*Z
  for a in A:
    count += YZ - bisect.bisect_left(BC, S-a)
    left -= YZ
    if count >= K or count+left < K:
      break
  
  return count >= K



Sl = 0
Sr = A[0]+B[0]+C[0]+1

while Sr - Sl > 1:
  mid = (Sl + Sr) // 2
  if check(mid):
    Sl = mid
  else:
    Sr = mid

Ans = []
for a in A:
  for b in B:
    if a + b + C[0] < Sr:
      break
    for c in C:
      if a + b + c >= Sr:
        Ans.append(a+b+c)
      else:
        break

Ans.sort(reverse=True)
Ans = Ans + [Sl]*(K-len(Ans))
for ans in Ans:
  print(ans)