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

N, M = map(int, input().split())
works = [list(map(int, input().split())) for _ in range(N)]
works.sort(key=lambda x:(-x[1], -x[0]))
days = [0] * (M+1)
ans = 0
max_day = M+1
for work in works:
  if work[0] >= max_day:
    continue
  full = True
  for day in range(work[0], max_day):
    if days[day] == 0:
      days[day] = 1
      ans += work[1]
      full = False
      break
  if full:
    max_day = work[0]
print(ans)


### FIXED CODE ###

import heapq

MAX = 10**5+1
N, M = map(int, input().split())
works = [[] for _ in range(MAX)]
for _ in range(N):
  day, reward = map(int, input().split())
  works[day].append(reward)
hp = []
ans = 0
for day in range(1, M+1):
  if len(works[day]) > 0:
    for reward in works[day]:
      heapq.heappush(hp, -reward)
  if len(hp) > 0:
    ans += -heapq.heappop(hp)
print(ans)
### BUGGY CODE ###

s = list(str(input()))
b = {}
b[0] = 1
c_ = 0
s.reverse()
for num,i in enumerate(s):
  c = (c_+int(i)*10**num)%2019
  if c in b:
    b[c] += 1
  else:
    b[c] = 1
  c_ = c
ans = 0
for i in b.values():
  ans += i*(i-1)//2
print(ans)


### FIXED CODE ###

s = input()
MOD = 2019
a =[0]*MOD
a[0] = 1
c_ = 0
ans = 0
t = 1
for i in reversed(s):
  c = (c_+int(i)*t)%MOD
  a[c] += 1
  t *= 10
  t %= MOD
  c_ = c
for i in a:
  ans += i*(i-1)//2
print(ans)
### BUGGY CODE ###

# -*- coding: utf-8 -*-

S = input()
Symbol = list(S)
MOD =[1,0,0,0,0,0,0,0,0,0,0,0,0]

for D in Symbol:
    NMOD =[0,0,0,0,0,0,0,0,0,0,0,0,0]
    for N in range(10):
        if D != '?' and int(D) != N:
            continue
        #end if
        for M in range(13):
            NM = (M * 10 + N) % 13
            NMOD[NM] += MOD[M]
        #end for
    #end for
    MOD = list(map(lambda x:x%1000000007,NMOD))
#end for

print(MOD[5])


### FIXED CODE ###

# -*- coding: utf-8 -*-

R10 = range(10)
R13 = range(13)

S = input()
R = [[(M-N)*4 % 13 for N in R10] for M in R13]
AM = 10**9+7

MOD =[1]+[0]*12

for D in S:
    if D == '?':
        MOD = [sum([MOD[N] for N in M])%AM for M in R]
    else:
        C = int(D)
        MOD = [MOD[M[C]] for M in R]
    #end if
#end for

print(MOD[5])
### BUGGY CODE ###

M=2019
a=i=0
d=[0]*M
p=1
for j in input()[::-1]:d[i%M]+=1;i-=int(j)*p;a+=d[i%M];p*=10
print(a)

### FIXED CODE ###

a,*d=[0]*2020
for i in map(int,input()):
  p=[0]*2019
  for j in range(2019):p[(j*10+i)%2019]+=d[j]
  d=p
  d[i]+=1
  a+=d[0]
print(a)
### BUGGY CODE ###

H, W = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]
B = [list(map(int, input().split())) for _ in range(H)]
C = [[abs(A[i][j] - B[i][j]) for j in range(W)] for i in range(H)]

dp = [[None] * W for _ in range(H)]
dp[0][0] = {C[0][0]}
for i in range(H):
    for j in range(W):
        if i == j == 0:
            continue
        st = set()
        if i > 0:
            st |= dp[i-1][j]
        if j > 0:
            st |= dp[i][j-1]
        nst = set()
        for n in st:
            nst.add(abs(n-C[i][j]))
            nst.add(abs(n+C[i][j]))
        dp[i][j] = nst

ans = list(dp[H-1][W-1])
ans.sort()
print(ans[0])

### FIXED CODE ###

H, W = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]
B = [list(map(int, input().split())) for _ in range(H)]
C = [[abs(A[i][j] - B[i][j]) for j in range(W)] for i in range(H)]

M = (H+W)*80
dp = [[0] * W for _ in range(H)]
dp[0][0] |= 1 << (M-C[0][0])
for i in range(H):
    for j in range(W):
        if i == j == 0:
            continue
        bit = 0
        if i > 0:
            bit |= dp[i-1][j]
        if j > 0:
            bit |= dp[i][j-1]
        dp[i][j] = (bit >> C[i][j]) | (bit << C[i][j])
ans = M
for i in range(M+1):
    if (dp[-1][-1] >> i) & 1:
        ans = min(ans, abs(M-i))
print(ans)
### BUGGY CODE ###


D = int(input())
c_list = list(map(int, input().split()))
s_list = [list(map(int, input().split())) for _ in range(D)]
t_list = [int(input()) for _ in range(D)]


#res_list = []
M = int(input())
for m in range(M):
    d,q = map(int, input().split())
    t_list[d-1] = q
    res = 0
    
    last_open = [0] * 26
    for i in range(D):
        t = t_list[i]
        res += s_list[i][t-1]

        bad = 0
        last_open[t-1] = i+1
        for ci in range(26):
            bad += c_list[ci]*(i+1 - last_open[ci])

        res -= bad

    print(res)
    #res_list.append(res)
#print(res_list)


### FIXED CODE ###


def main():
    D = int(input())
    c_list = list(map(int, input().split()))
    s_list = [list(map(int, input().split())) for _ in range(D)]
    t_list = [int(input()) for _ in range(D)]

    basic_bad = sum(c_list)
    #res_list = []
    M = int(input())
    for m in range(M):
        d,q = map(int, input().split())
        t_list[d-1] = q
        res = 0
        
        bad = 0
        last_open = [0] * 26
        for i in range(D):
            t = t_list[i]
            res += s_list[i][t-1]

            # TODO: ここは毎回26ループ回す必要がないところになりうるので改善可能かも(なおすだけで20回分の処理が消せる)
            # bad = 0
            # for ci in range(26):
            #     bad += c_list[ci]*(i+1 - last_open[ci])
            bad += basic_bad - (i+1 - last_open[t-1]) * c_list[t-1]
            last_open[t-1] = i+1

            res -= bad

        print(res)

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

#!/usr/bin/env python3

N, K = list(map(int, input().split()))
h_list = list(map(int, input().split()))
dp_list = [float("inf")] * N
dp_list[0] = 0

for i in range(1, N):
    # j番目の足場からi番目の足場に飛ぶ

    for j in range(max(i - K, 0), i + 1):

        # j番目の足場までの最適コスト
        cum_cost = dp_list[j]

        # j番目の足場から飛んだ場合のコスト
        cost = dp_list[j] + abs(h_list[j] - h_list[i])

        # 最適コストで更新
        dp_list[i] = min(dp_list[i], cost)

ans = dp_list[-1]
print(ans)


### FIXED CODE ###

N, K = list(map(int, input().split()))
h_list = list(map(int, input().split()))
dp_list = [float("inf")] * N
dp_list[0] = 0

for i in range(1, N):
    # j番目の足場からi番目の足場に飛ぶ

    for j in range(max(i - K, 0), i + 1):

        # j番目の足場までの最適コスト
        cum_cost = dp_list[j]

        # j番目の足場から飛んだ場合のコスト
        cost = dp_list[j] + abs(h_list[j] - h_list[i])

        # 最適コストで更新
        dp_list[i] = min(dp_list[i], cost)

ans = dp_list[-1]
print(ans)
### BUGGY CODE ###

[n,m] = [int(i) for i in input().split()]
dic = {}
for i in range(n):
    [ai,bi] = [int(i) for i in input().split()]
    if ai in dic.keys():
        dic[ai] += bi
    else:
        dic[ai] = bi
sum = 0
ls = sorted(list(dic.keys()))
while m > 0:
    for i in range(len(ls)):
    #print(dic)
        if dic[ls[i]] >= m:
            sum += min(dic.keys()) * m
            m = 0
            break
        else:
            sum += dic[min(dic.keys())]*min(dic.keys())
            m -= dic.pop(min(dic.keys()))
print(sum)


### FIXED CODE ###

[n,m] = [int(i) for i in input().split()]
dic = {}
for i in range(n):
    [ai,bi] = [int(i) for i in input().split()]
    if ai in dic.keys():
        dic[ai] += bi
    else:
        dic[ai] = bi
sum = 0
ls = sorted(list(dic.keys()))
while m > 0:
    for i in range(len(ls)):
    #print(dic)
        if dic[ls[i]] >= m:
            sum += ls[i] * m
            m = 0
            break
        else:
            sum += dic[ls[i]]*ls[i]
            m -= dic[ls[i]]
print(sum)
### BUGGY CODE ###

L,R= map(int,input().split())
#境界条件
bool = True
l = L % 2019
r = R % 2019
if l == 0 or r == 0:
    ans = 0
else:
    for i in range(L,R):
        for j in range(i+1,R+1):
            temp = (i * j) % 2019
            if bool:
                min = temp
                ans = min
                bool = False
            elif min > temp:
                min = temp
                ans = min
print(ans)

### FIXED CODE ###

L,R= map(int,input().split())
#境界条件
bool = True
flag = False
for i in range(L,R):
    for j in range(i+1,R+1):
        temp = (i * j) % 2019
        if bool:
            min = temp
            ans = min
            bool = False
        elif min > temp:
            min = temp
            ans = min
        if min == 0:
            flag = True
            break
    if flag:
        break
print(ans)
### BUGGY CODE ###

# coding: utf-8
import sys
sysread = sys.stdin.readline
def run():

    S = input()
    mods = [[] for _ in range(2019)]
    mods[0].append(0)
    for i in range(1, len(S)+1):
        tmp = int(S[-i:]) % 2019
        mods[tmp].append(i)

    count = 0
    for ns in mods:
        l = len(ns)
        count += l * (l-1) // 2
    print(count)

if __name__ == "__main__":
    run()

### FIXED CODE ###

# coding: utf-8
import sys
sysread = sys.stdin.readline
def run():
    S = input()
    mods = [[] for _ in range(2019)]
    mods[0].append(0)

    tmp = 0
    tmp10 = 1
    for i in range(1, len(S)+1):
        if i == 1:
            tmp10 = 1
        else:
            tmp10 = (tmp10 * 10) % 2019
        tmp = (tmp10* int(S[-i]) + tmp)% 2019
        mods[tmp].append(i)

    count = 0
    for ns in mods:
        l = len(ns)
        count += l * (l-1) // 2
    print(count)

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

import heapq

def main():

    N, M = map(int, input().split())
    AB = []
    for i in range(N):
        a, b = map(int, input().split())
        AB.append([a, b])
        AB.sort()
    q = []
    ans = 0
    for i in range(M-1, -1, -1):
        while AB and AB[0][0] <= M-i:
            a, b = AB.pop(0)
            heapq.heappush(q, -b)
        if q:
            v = -heapq.heappop(q)
            ans += v
    return ans


if __name__ == '__main__':
    print(main())

### FIXED CODE ###

import heapq
def main():

    N, M = map(int, input().split())
    task = []
    for _ in range(N):
        A, B = map(int, input().split())
        task.append([A, B])
    task.sort()

    hq = []
    ans = 0
    for i in range(1, M+1):
        while task and task[0][0]<= i:
            _, v = heapq.heappop(task)
            heapq.heappush(hq, -v)
        if hq:
            v = heapq.heappop(hq)
            ans += -v
    return ans

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

import sys
input = sys.stdin.readline

#input
X, Y = map(int, input().split())

#output
import math

from operator import mul
from functools import reduce

def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

if (X + Y) % 3 == 0:
    k = (-X + 2*Y) //3
    l = (2*X -Y) //3
    if k < 0 or l <0:
        answer = 0
    else:
        answer = combinations_count(k+l, l) % (10**9 + 7)
else:
    answer = 0

print(answer)

### FIXED CODE ###

import sys
input = sys.stdin.readline

#input
X, Y = map(int, input().split())

#output
import math

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

if (X + Y) % 3 == 0:
    k = (-X + 2*Y) //3
    l = (2*X -Y) //3
    if k < 0 or l <0:
        answer = 0
    else:
        answer = cmb(k+l, l) % (10**9 + 7)
else:
    answer = 0

print(answer)
### BUGGY CODE ###

from operator import itemgetter
N, M = (int(i) for i in input().split(' '))
py=[]
p =[]

# 全都市を配列に代入
for i in range(M):
    p = [i]
    p.extend([int(j) for j in input().split(' ')])
    py.append(p)

# 全N個の県について調べる
Npy = []
for i in range(1,N+1):
    # 県i
    pyi = [j for j in py if j[1] == i] # 県iの市リスト
    pyi.sort(key=itemgetter(2)) # 県iの市を生まれた年でソート
    l = len(pyi)
    cnt = 0
    for k in range(1,l+1):
        pyi[k-1][2] = k
    Npy.extend(pyi)

Npy.sort(key=itemgetter(0))

for t in Npy:
    print('{0:0>6}{1:0>6}'.format(t[1],t[2]))
    

### FIXED CODE ###

N, M = (int(i) for i in input().split(' '))
py=[]
p =[]

# 全都市を配列に代入
for i in range(M):
    p = [i]
    p.extend([int(j) for j in input().split(' ')])
    py.append(p)

# 設立年で一度ソートする
py.sort(key = lambda x: x[2])
pcid = [1] * N # 各県の都市ID

for i in range(M):
    p = py[i][1] # 県ID
    py[i][2] = pcid[p-1]
    pcid[p-1] += 1

py.sort(key=lambda x:x[0])
for t in py:
    print('{0:0>6}{1:0>6}'.format(t[1],t[2]))
### BUGGY CODE ###

def resolve():
    n = int(input())
    arr = tuple(input())
    count = n
    for i in range(n):
        c = 0
        left = arr[:i]
        right = arr[i+1:]
        c += sum([1 for j in left if j == 'W'])
        c += sum([1 for k in right if k == 'E'])
        count = min(c, count)

    print(count)

if __name__ == '__main__':
    resolve()

### FIXED CODE ###

def resolve():
    n = int(input())
    S = list(input())
    min_c = n
    count_e = S.count('E')
    count_w = 0

    for s in S:
        if s == 'E':
            count_e -= 1
        min_c = min(min_c, count_e + count_w)
        if s == 'W':
            count_w += 1

    print(min_c)

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

#!/usr/bin/env python3
import sys
import collections
import copy
def dellist(items, indexes):
    for index in sorted(indexes, reverse=True):
        del items[index]

def solve(N: int, A: "List[int]"):
    counter = sorted(list(collections.Counter(A).values()),reverse=True)
    for i in range(1,N+1):
        c = copy.deepcopy(counter)
        answer = 0
        while c:
            if len(c) < i:
                break
            remove_index = []
            for j in range(i):
                c[j]-=1
                if c[j] == 0:
                    remove_index.append(j)
            if remove_index:
                dellist(c,remove_index)
            answer += 1

        print(answer)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
import collections

def solve(N: int, A: "List[int]"):
    counter = sorted(list(collections.Counter(A).values()),reverse=True)
    c_index = 0
    k=0
    for i in range(1,N+1):
        k+=1
        if len(counter)<i:
            print(0)
            continue
        while counter[c_index]*k > N and c_index<len(counter)-1:
            N-=counter[c_index]
            c_index+=1
            k-=1
        print(N//k)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

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

import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
mod = 10**9+7

from collections import defaultdict
from bisect import bisect_right
last = -1
dic = defaultdict(list)
idx = 0
lis = []
for i in range(N):
    c = int(input())
    if c==last:
        continue
    last = c
    dic[c].append(idx)
    lis.append(c)
    idx += 1
memo = {}
def dfs(i):
    if i==idx:
        return 1
    if i in memo.keys():
        return memo[i]
    v = lis[i]
    ret = 0
    n_idx = bisect_right(dic[v], i)
    if n_idx<len(dic[v]):
        for nx in dic[v][n_idx:]:
            ret += dfs(nx+1)
            ret %= mod
    ret += dfs(i+1)
    ret %= mod
    memo[i] = ret
    return ret
print(dfs(0))

### FIXED CODE ###

import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
mod = 10**9+7

last = {}
dp = [0]*(N+1)
dp[0] = 1
for i in range(1, N+1):
    dp[i] = dp[i-1]
    c = int(input())
    if c in last and last[c]+1<i:
        dp[i] += dp[last[c]]
        dp[i] %= mod
    last[c] = i

print(dp[N])
### BUGGY CODE ###

n, m = list(map(int, input().split()))
lr = [list(map(int, input().split())) for _ in range(m)]

import numpy as np
tmp = np.zeros(n)

for i in range(m):
    l = lr[i][0] - 1
    r = lr[i][1] - 1
    tmp[l: r+1] = tmp[l: r+1] + 1

counter = 0
for j in range(n):
    if tmp[j] == m:
        counter += 1

print(counter)


### FIXED CODE ###

n, m = list(map(int, input().split()))
lr = [list(map(int, input().split())) for _ in range(m)]

l_list = [_lr[0] for _lr in lr]
r_list = [_lr[1] for _lr in lr]

a = min(r_list)
b = max(l_list)
print(max(a - b + 1, 0))
### BUGGY CODE ###

n = int(input())
s = input()
cnt = 0
for i in range(n):
    for j in range(i + 1, n):
        k = 2*j - i
        if j < k < n and len({s[i], s[j], s[k]}) == 3:
            cnt += 1
print(s.count('R') * s.count('G') * s.count('B') - cnt)

### FIXED CODE ###

n = int(input())
s = input()
cnt = s.count('R') * s.count('G') * s.count('B')
for i in range(n):
    for j in range(i + 1, n):
        k = 2*j - i
        if j < k < n and len({s[i], s[j], s[k]}) == 3:
            cnt -= 1
print(cnt)
### BUGGY CODE ###

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

area = []
for i in range(K):
    L, R = map(int, input().split())
    area.append((L, R))

d = [0] * N


def func(pos):
    for a in area:
        for i in range(a[0], a[1]+1):
            if pos - i > -1:
                d[pos-i] += d[pos] % 998244353


d[N-1] = 1
for i in range(N-1, -1, -1):
    if d[i] > 0:
        func(i)

print(d[0] % 998244353)


### FIXED CODE ###

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

area = []
for i in range(K):
    L, R = map(int, input().split())
    area.append((L, R))

area.sort()
d = [0] * N
a = [0] * N


def func(pos):
    for l, r in area:
        if pos + l - 1 < N:
            a[pos + l-1] += d[pos]
        if pos + r < N:
            a[pos + r] -= d[pos]
    d[pos+1] = (d[pos] + a[pos]) % 998244353


d[0] = 1
a[0] = -1
for i in range(0, N-1):
    func(i)

print(d[N-1] % 998244353)
### BUGGY CODE ###


def main():
    H, N = [int(x) for x in input().split()]
    magic = [list(map(int, input().split())) for _ in range(N)]
    # print(magic)
    max_a = max(a for a, _ in magic)
    dp = [10**18 for _ in range(H + max_a)]
    dp[0] = 0

    for i in range(1, H+max_a):
        dp[i] = min([dp[i-a] + b for a, b in magic if i-a>=0], default=dp[i])

    ans = min(dp[H:H+max_a])
    print(ans)


if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    H, N = [int(x) for x in input().split()]
    magic = [list(map(int, input().split())) for _ in range(N)]
    # print(magic)
    max_a = max(a for a, _ in magic)
    dp = [10**18 for _ in range(H + max_a)]
    dp[0] = 0

    for i in range(1, H+max_a):
        dp[i] = min(dp[i-a] + b for a, b in magic)

    ans = min(dp[H:H+max_a])
    print(ans)


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

from collections import deque
H,W=map(int,input().split())
Ch,Cw=map(int,input().split())
Dh,Dw=map(int,input().split())
Ch-=1
Cw-=1
Dh-=1
Dw-=1

S=[]
for i in range(H):
  s=list(input())
  S.append([10**10 if i =="." else -1 for i in s])

dq = deque()
dq.append((Ch,Cw))
S[Ch][Cw]=0

while dq:
  a=dq.pop()
  for i in range(5):
    for j in range(5):
      if a[0]-2+i>=0 and a[0]-2+i<H and a[1]-2+j>=0 and a[1]-2+j<W:
        if abs(i-2)+abs(j-2)==1 and S[a[0]][a[1]]<S[a[0]-2+i][a[1]-2+j]:
          S[a[0]-2+i][a[1]-2+j]=S[a[0]][a[1]]
          dq.appendleft((a[0]-2+i,a[1]-2+j))
        elif S[a[0]][a[1]]+1<S[a[0]-2+i][a[1]-2+j]:
          S[a[0]-2+i][a[1]-2+j]=S[a[0]][a[1]]+1
          dq.append((a[0]-2+i,a[1]-2+j))
      

if S[Dh][Dw]==10**10:
  print(-1)
else:
  print(S[Dh][Dw])

### FIXED CODE ###

from collections import deque
H,W=map(int,input().split())
Ch,Cw=map(int,input().split())
Dh,Dw=map(int,input().split())
Ch-=1
Cw-=1
Dh-=1
Dw-=1

S=[]
for i in range(H):
  s=list(input())
  S.append([10**10 if i =="." else -1 for i in s])
visit=[[False for i in range(W)] for j in range(H)]

dq = deque()
dq.append((Ch,Cw,0))
S[Ch][Cw]=0
counter=0

while dq:
  a=dq.popleft()
  if visit[a[0]][a[1]]==True:
    continue
  elif S[a[0]][a[1]]==counter:
    visit[a[0]][a[1]]=True
  elif a[2]==counter+1:
    visit[a[0]][a[1]]=True
    counter+=1
  for i in range(5):
    for j in range(5):
      if a[0]-2+i>=0 and a[0]-2+i<H and a[1]-2+j>=0 and a[1]-2+j<W:
        if abs(i-2)+abs(j-2)==1 and S[a[0]][a[1]]<S[a[0]-2+i][a[1]-2+j] and visit[a[0]-2+i][a[1]-2+j]==False:
          S[a[0]-2+i][a[1]-2+j]=counter
          dq.appendleft((a[0]-2+i,a[1]-2+j,counter))
        elif S[a[0]][a[1]]+1<S[a[0]-2+i][a[1]-2+j] and visit[a[0]-2+i][a[1]-2+j]==False:
          S[a[0]-2+i][a[1]-2+j]=counter+1
          dq.append((a[0]-2+i,a[1]-2+j,counter+1))
  #print(visit,counter,a,dq,"\n")
if S[Dh][Dw]==10**10:
  print(-1)
else:
  print(S[Dh][Dw])
### BUGGY CODE ###

x,y,z,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=sorted(list(map(int,input().split())),reverse=True)
ab=[]
for i in a:
    for j in b:
        ab.append(i+j)
ab.sort(reverse=True)
ans=[]
for i in range(len(ab)):
    for j in range(len(c)):
        ans.append(ab[i]+c[j])
ans.sort(reverse=True)
for i in range(k):
    print(ans[i])


### FIXED CODE ###

x,y,z,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=sorted(list(map(int,input().split())),reverse=True)
ab=[]
for i in a:
    for j in b:
        ab.append(i+j)
ab.sort(reverse=True)
ans=[]
for i in range(min(k,len(ab))):
    for j in range(min(k,len(c))):
        ans.append(ab[i]+c[j])
ans.sort(reverse=True)
for i in range(k):
    print(ans[i])
### BUGGY CODE ###

from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import connected_components

from collections import Counter

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)]

g = [[0] * n for _ in range(n)]

for a, b in ab:
    a -= 1
    b -= 1
    g[a][b] = 1
    g[b][a] = 1

csr = csr_matrix(g)
comp, labels = connected_components(csr)

counter = Counter(labels)

ans = [counter[labels[i]] - 1 for i in range(n)]

for a, b in ab:
    a -= 1
    b -= 1
    if labels[a] == labels[b]:
        ans[a] -= 1
        ans[b] -= 1

for c, d in cd:
    c -= 1
    d -= 1
    if labels[c] == labels[d]:
        ans[c] -= 1
        ans[d] -= 1

print(*ans)


### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 7)


class Tree:
    WHITE = -2
    GRAY = -1
    BLACK = 1

    def __init__(self, adj):
        n = len(adj)
        self.adj = adj
        self.colors = [self.WHITE] * n
        self.depths = [-1] * n
        self.depth = 0

    def init(self):
        self.__init__(self.adj)

    def dfs(self, u, c):
        if self.colors[u] >= 0:
            return

        self.colors[u] = self.GRAY
        self.depths[u] = self.depth

        for v in self.adj[u]:
            if self.colors[v] == self.WHITE:
                self.dfs(v, c)

        self.colors[u] = c

from collections import Counter

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)]

adj = [[] for _ in range(n)]
for a, b in ab:
    a -= 1
    b -= 1
    adj[a].append(b)
    adj[b].append(a)

tree = Tree(adj)
for i in range(n):
    tree.dfs(i, i)

labels = tree.colors

counter = Counter(labels)

ans = [counter[labels[i]] - 1 for i in range(n)]

for a, b in ab:
    a -= 1
    b -= 1
    if labels[a] == labels[b]:
        ans[a] -= 1
        ans[b] -= 1

for c, d in cd:
    c -= 1
    d -= 1
    if labels[c] == labels[d]:
        ans[c] -= 1
        ans[d] -= 1

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

R,G,B,N=map(int,input().split())
ans=0
rr=N//R+1
gg=N//G+1
bb=N//B+1
for r in range(rr):
    for g in range(gg):
        if (N-R*r-G*g)%B==0 and N-R*r-G*g>=0:
            ans+=1
        elif N-R*r-G*g<0:
            pass
print(ans)

### FIXED CODE ###

R,G,B,N=map(int,input().split())
ans=0
rr=N//R+1
gg=N//G+1
bb=N//B+1
for r in range(rr):
    for g in range(gg):
        if (N-R*r-G*g)%B==0 and N-R*r-G*g>=0:
            ans+=1
        elif N-R*r-G*g<0:
            pass
print(ans)