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

import numpy as np
import sys

def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

# だいたいpdfの通り
def main():
    l,a,b,md=MI()

    # 数列の要素がk桁になるのがi項目で、k+1桁になるのがj項目
    k=0
    i=0
    cc=np.eye(3,dtype="i8")
    ans=[0,a%md,b%md]
    ans=np.array(ans,dtype="i8")
    # 各桁数ごとに処理
    while i<l:
        k+=1
        j=(10**k-a+b-1)//b
        if j==0:continue
        if j>l:j=l
        # k桁の要素の個数がe
        e=j-i
        # i項目まで連結した整数をans[i],数列のi項目をs[i]とすると
        #                                       [10**k 0 0]
        # [ans[i],s[i],b] = [ans[i-1],s[i-1],b] [  1   1 0]
        #                                       [  0   1 1]
        # 最後の3x3行列をbbとして、e乗すればよいので、繰り返し二乗法でやる
        bb=np.zeros((3,3),dtype="i8")
        bb[0,0]=pow(10,k,md)
        bb[1,0]=bb[1,1]=bb[2,1]=bb[2,2]=1
        while e:
            if e&1:ans=np.dot(ans,bb)%md
            bb=np.dot(bb,bb)%md
            e>>=1
        i=j

    print(ans[0])

main()


### FIXED CODE ###

import numpy as np
import sys

def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

# だいたいpdfの通り
def main():
    l,a,b,md=MI()

    # 数列の要素がk桁になるのがi項目で、k+1桁になるのがj項目
    k=0
    i=0
    ans=[0,a%md,b%md]
    ans=np.array(ans,dtype="i8")
    # 各桁数ごとに処理
    while i<l:
        k+=1
        j=(10**k-a+b-1)//b
        if j<=0:continue
        if j>l:j=l
        # k桁の要素の個数がe
        e=j-i
        # i項目まで連結した整数をans[i],数列のi項目をs[i]とすると
        #                                       [10**k 0 0]
        # [ans[i],s[i],b] = [ans[i-1],s[i-1],b] [  1   1 0]
        #                                       [  0   1 1]
        # 最後の3x3行列をbbとして、e乗すればよいので、繰り返し二乗法でやる
        bb=np.zeros((3,3),dtype="i8")
        bb[0,0]=pow(10,k,md)
        bb[1,0]=bb[1,1]=bb[2,1]=bb[2,2]=1
        while e:
            if e&1:ans=np.dot(ans,bb)%md
            bb=np.dot(bb,bb)%md
            e>>=1
        i=j

    print(ans[0])

main()
### BUGGY CODE ###

n = int(input())
aa = list(map(int, input().split()))
bb = set()

for a in aa:
  if aa.count(a) > 1:
    bb.add(a)
x = list(bb)
y = sorted(x, reverse=True)

if len(y) < 2:
  print(0)
else:
  print(y[0]*y[1])

### FIXED CODE ###

import collections
n = int(input())
aa = list(map(int, input().split()))
ca = collections.Counter(aa)
la = sorted([a for a in ca.items()], key = lambda x:x[0], reverse=True)

list1 = []
list2 = []

for a in la:
  if a[1] > 1:
    list1.append(a)
  if a[1] >3:
    list2.append(a)
    
if len(list1) > 1:    
    xr = list1[0][0] * list1[1][0]
else:
  xr = 0
    
if len(list2) > 0:
  xs = list2[0][0] * list2[0][0]
else:
  xs = 0
  
ans = max(xr, xs)

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

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

p = []
S = []

for i in range(M):
    p1, s1 = input().split()

    p.append(int(p1))
    S.append(s1)
AC = 0
WA = 0
list = []

for i in range(M):
    if S[i] == "AC" and p[i] not in list:
        AC += 1
        list.append(p[i])
        for j in range(i):
            if p[j] == p[i]:
                WA += 1
print(AC, WA)

### FIXED CODE ###

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

ac = [0] * N
wa = [0] * N

for i in range(M):
    p,s = input().split()
    p = int(p)
    p -= 1
    if ac[p]:
        continue
    if s == 'AC': 
        ac[p] = 1
    else:
        wa[p] += 1
AC = sum(ac)
WA = 0
for i in range(N):
    if ac[i]:
        WA += wa[i]
print(AC, WA)
### BUGGY CODE ###

n,*a=map(int,open(0).read().split())
for i in range(n):s=[0]+a[:i]+a[i+1:]+[0];print(sum(abs(s[t]-s[t+1])for t in range(n)))

### FIXED CODE ###

n,*a=map(int,open(0).read().split())
c=[0]+a+[0]
y=sum(abs(c[t]-c[t+1])for t in range(n+1))
for i in range(n):
  s,t,r=c[i:i+3]
  print(y+abs(r-s)-abs(t-s)-abs(t-r))
### BUGGY CODE ###

def astar(start, goal, S, H, W):
  if S[start[0]][start[1]] == '#' or S[goal[0]][goal[1]] == '#':
    return -1
  else:
    INF = 10**9
    D = [[INF]*W for h in range(H)]
    D[start[0]][start[1]] = 0
    next_node = [start]
    while next_node:
      now_y, now_x = next_node.pop()
      d = D[now_y][now_x]
      for x, y in [[-1, 0], [1, 0], [0, -1], [0, 1]]:
        if now_y+y<0 or now_y+y>=H or now_x+x<0 or now_x+x>=W:
          continue
        if S[now_y+y][now_x+x] == '.':
          if D[now_y+y][now_x+x] > d + 1:
            D[now_y+y][now_x+x] = D[now_y][now_x] + 1
            next_node.append([now_y+y, now_x+x])
    
    if D[goal[0]][goal[1]] < INF:
      return D[goal[0]][goal[1]]
    else:
      return -1


H, W = map(int, input().split())
nodes = []
for h in range(H):
  for w in range(W):
    nodes.append([h, w])

S = []
for h in range(H):
  S.append(list(input()))

ans = 0
for start in nodes:
  for goal in nodes:
    ans = max(ans, astar(start, goal, S, H, W))

print(ans)

### FIXED CODE ###

from collections import deque

def astar(start, S, H, W):
  if S[start[0]][start[1]] == '#':
    return -1
  else:
    INF = 10**9
    D = [[INF]*W for h in range(H)]
    D[start[0]][start[1]] = 0
    next_node = deque([start])
    max_d = 0
    while next_node:
      now_y, now_x = next_node.popleft()
      d = D[now_y][now_x]
      for x, y in [[-1, 0], [1, 0], [0, -1], [0, 1]]:
        if now_y+y<0 or now_y+y>=H or now_x+x<0 or now_x+x>=W:
          continue
        if S[now_y+y][now_x+x] == '.':
          if D[now_y+y][now_x+x] > d + 1:
            D[now_y+y][now_x+x] = D[now_y][now_x] + 1
            max_d = max(max_d, D[now_y+y][now_x+x])
            next_node.append([now_y+y, now_x+x])
    
    return max_d

H, W = map(int, input().split())
nodes = []
for h in range(H):
  for w in range(W):
    nodes.append([h, w])

S = []
for h in range(H):
  S.append(list(input()))

ans = 0
for start in nodes:
  ans = max(ans, astar(start, S, H, W))

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

from collections import defaultdict
def enum(n,x,A):
	D = defaultdict(int)
	D[0] = 1
	L = [None]*(1<<n)
	L[0] = 0
	for k in xrange(1<<n):
		for j in xrange(n):
			jbit = 1<<j
			if (k&jbit): continue
			nbit = k + jbit
			if L[nbit] is None: 
				nv = L[k] + x[j]
				L[nbit] = nv
				cnt = bin(nbit).count("1")
				D[nv-A*cnt] += 1
	return D
def solve():
	N,A = map(int,raw_input().split())
	x = map(int,raw_input().split())
	n1 = N/2; n2 = N - n1
	D1 = enum(n1,x[:n1],A)
	D2 = enum(n2,x[n1:],A)
	ans = 0
	for k,v in D1.iteritems():
		ans += D2[-k]*v
	print ans - 1
solve()

### FIXED CODE ###

from collections import defaultdict
def solve():
	N,A = map(int,raw_input().split())
	x = map(int,raw_input().split())
	DP = [defaultdict(int) for i in xrange(N+1)]
	DP[0][0] = 1
	for i in xrange(N):
		for k,v in DP[i].iteritems():
			DP[i+1][k+x[i]-A] += v
			DP[i+1][k] += v
	print DP[N][0] - 1
solve()
### BUGGY CODE ###

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

def f(b):
    r = 0
    for i, ai in enumerate(A):
        r += abs(ai - (b + i + 1))
    return r

mx = 10 ** 10
mn = -10 ** 10

# print(f(0))
while mx - mn > 2:
    m = (mx + mn) // 2
    x = f(m)
    y = f(m+1)
    if x < y:
        mx = m + 1
    else:
        mn = m


ans = []
for i in range(mn, mx+1):
    ans.append(f(i))
print(min(ans))

### FIXED CODE ###

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

def f(b):
    r = 0
    for i, ai in enumerate(A):
        r += abs(ai - (b + i + 1))
    return r


A2 = []
for i, ai in enumerate(A):
    A2.append(ai - (i+1))

SA2 = sorted(A2)
ans = f(SA2[((N+1)//2) - 1])
print(ans)
### BUGGY CODE ###

n = int(input())
s = input()
dp = [[0]*(n+1) for _ in range(n+1)]
ans = 0
for i in range(n-1, -1, -1):
    for j in range(n-1, -1, -1):
        if s[i] == s[j]:
            dp[i][j] = min(dp[i+1][j+1] + 1, i-j)
            ans = max(ans, dp[i][j])
print(ans)


### FIXED CODE ###

import sys
input = sys.stdin.readline
n = int(input())
s = input()
dp = [[0]*(n+1) for y in range(n+1)]
ans = 0

for i in range(n):
    a = n-1-i
    for j in range(n):
        b = n-1-j
        if s[a] == s[b]:
            dp[a][b] = dp[a+1][b+1] + 1
for i in range(n):
    for j in range(n):
        now = min(dp[i][j], j-i)
        ans = max(ans, now)
print(ans)
### BUGGY CODE ###

n=int(input())
A=[]
for i in range(n):
    a=input()
    if a in A:
        A.remove(a)
    else:
        A.append(a)
print(len(A))

### FIXED CODE ###

n=int(input())
A=set()
for i in range(n):
    a=input()
    if a in A:
        A.remove(a)
    else:
        A.add(a)
print(len(A))
### BUGGY CODE ###

import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt
from copy import deepcopy

def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    q = int(input())
    ans = [0]*q
    for i in range(q):
        b,c = map(int, input().split())
        for j in range(n):
            if b == a_list[j]:
                a_list[j] = c
        ans[i] = sum(a_list)
        
    for i in ans:
        print(i)
   
if __name__ == "__main__":
    main()

### FIXED CODE ###

import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt
from copy import deepcopy

def main():
    max_num = 10**5
    n = int(input())
    a_list = list(map(int, input().split()))
    q = int(input())
    
    query = [map(int, input().split()) for _ in range(q)]
    num = [0 for _ in range(max_num+1)]
    for i in a_list:
        num[i] += 1

    ans = sum(a_list)

    for b,c in query:
        n = num[b]
        num[b] = 0
        num[c] += n
        ans += (c-b)*n
        print(ans)

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

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

for i in range(a,b+1):
    if i-a<k or b-i<k:
        print(i)

### FIXED CODE ###

a,b,k = map(int,input().split())
if b+1-a <= k*2:
    for i in range(a,b+1):
        print(i)
else:
    for j in range(a,a+k):
        print(j)
    for l in range(b-k+1,b+1):
        print(l)
### BUGGY CODE ###

import time
from collections import deque
import sys
import copy
n=int(input())
t1=time.time()
maxmatch=n*(n-1)
a=[]
for i in range(n):
  a.append(list(map(int,input().split())))

day=0

match=[0]*(n+1)
jyunban=deque(range(n))
jyunban_n=deque()

while match[n]<maxmatch:
  jyunban_n.clear()
  day+=1
  check=[True]*(n+1)
  for i in jyunban:
    if match[i]==n-1 or check[i]==False:
      continue
    else:
      vs=a[i][match[i]]-1
      if check[i] and check[vs]:
        if  a[i][match[i]]-1==vs and a[vs][match[vs]]-1==i:
          match[i]+=1
          match[vs]+=1
          match[n]+=2
          check[i]=False
          check[vs]=False
          check[n]=False
          jyunban_n.append(i)
          jyunban_n.append(vs)
      
    if len(jyunban)==0:
      if check[n]:
        print(day,-1)
        sys.exit()
  jyunban=copy.copy(jyunban_n)
#  print (jyunban)
        
print(day)


### FIXED CODE ###

import sys
MAX_INT = int(10e9)
MIN_NUM = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()
 
N = I()
a = [IL()[::-1] for i in range(N)]
 
used = [-1]*N
updatelist = [i for i in range(N)]
total = N*(N-1)//2
cnt = 0
days = 0
ul = []
while updatelist:
  ul = []
  for i in updatelist:
    #print(a)
    #print(i+1)
    if len(a[i]) > 0 and used[i] != days:
      numIND = a[i][-1] -1
      #print(numIND+1)
      if a[numIND][-1] == i+1 and used[numIND] != days:
        a[i].pop(-1)
        a[numIND].pop(-1)
        used[i] = days
        used[numIND] = days
        ul.append(i)
        ul.append(numIND)
        cnt += 1
  else:
    updatelist = ul[:]
    if len(ul) != 0:
      days += 1
#print(a)
#print(cnt)
if cnt == total:
  print(days)
else:
  print(-1)
### BUGGY CODE ###

S = input()

N = len(S)
if N % 2 == 0:
    M = N // 2
    ans = M
    for i in range(M):
        T = S[i:N - i]
        if len(set(T)) == 1:
            ans = N - i
            break
else:
    M = N // 2 + 1
    ans = M
    for i in range(M):
        T = S[i:N - i]
        if len(set(T)) == 1:
            ans = N - i
            break
print(ans)


### FIXED CODE ###

S = list(input())

k = len(S) // 2 + 1
x = S[k - 1]
for i in range(k, len(S) + 1):
    if x != S[i - 1] or x != S[len(S) - i]:
        i -= 1
        break
print(i)
### BUGGY CODE ###

import math
K=int(input())
sum=0
for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            gcd1 = int(math.gcd(a,b))
            gcd2 = int(math.gcd(b,c))
            
            #print(gcd1,gcd2)
            gcd = gcd1 = int(math.gcd(gcd1,gcd2))

            sum = sum+gcd
print(sum)

### FIXED CODE ###

from math import gcd

K = int(input())
out = 0
Count = [0]*K
gcds = [[0]*K for i in range(K)]

for i in range (1,K+1):
    for j in range(1,+K+1):
        value = gcd(i,j)
        gcds[i-1][j-1]=value
        Count[value-1]+=1

for i in range(1,K+1):
    for j in range(1,K+1):
        out +=gcds[i-1][j-1]*Count[j-1] #値*回数
        
print(out)
### BUGGY CODE ###

import math
n = int(input())
a = [int(i) for i in input().split()]

chk = [0]*(10**6+1)

for i in range(n):
    #if chk[a[i]] == 1 and a[i] >= 2:
    #    print("not coprime")
    #    exit()
    chk[a[i]] += 1

flag = True

for i in range(2,10**6+1):
    #tmp = i
    kake = 1
    num = 0
    #print(i)
    while i * kake <= 10**6:
        if chk[i*kake] >= 2:
            flag = False
            break
        #print(i)
        if chk[i*kake] == 1:
            if num == 1:
                flag = False
                break
            num = 1
            #break
        kake += 1
gcd_num = math.gcd(a[0],a[1])
        
for i in range(n-2):
    gcd_num = math.gcd(gcd_num,a[i+2])
    
if flag == True:
    print("pairwise coprime")
elif gcd_num == 1:
    print("setwise coprime")
else:
    print("not coprime")


### FIXED CODE ###

import math
n = int(input())
a = [int(i) for i in input().split()]

chk = [0]*(10**6+1)

for i in range(n):
    #if chk[a[i]] == 1 and a[i] >= 2:
    #    print("not coprime")
    #    exit()
    chk[a[i]] += 1

flag = True

for i in range(2,10**6+1):
    #tmp = i
    kake = 1
    num = 0
    #print(i)
    while i * kake <= 10**6:
        if chk[i*kake] >= 2:
            flag = False
            break
        #print(i)
        if chk[i*kake] == 1:
            if num == 1:
                flag = False
                break
            num = 1
            #break
        kake += 1
gcd_num = math.gcd(a[0],a[1])
        
for i in range(n-2):
    gcd_num = math.gcd(gcd_num,a[i+2])
    
if flag == True:
    print("pairwise coprime")
elif gcd_num == 1:
    print("setwise coprime")
else:
    print("not coprime")
### BUGGY CODE ###

from functools import reduce

n = int(input())
colors = [0]*(n-1)
mat = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1

    mat[a].append((i, b))
    mat[b].append((i, a))

q = []
max_len = reduce(lambda a, x:max(a, len(x)), mat, 0)
q.append(0)
while len(q) > 0:
    current = q.pop()
    cand = [i+1 for i in range(max_len)]
    current_colors = [colors[p[0]] for p in mat[current] if colors[p[0]] > 0]
    for col in current_colors:
        cand.remove(col)

    for p in mat[current]:
        if colors[p[0]] > 0:
            continue
        col = cand.pop()
        colors[p[0]] = col
        q.append(p[1])
print(max_len)
for col in colors:
    print(col)





### FIXED CODE ###

from collections import deque
from functools import reduce

n = int(input())
colors = [0]*(n-1)
mat = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1

    mat[a].append((i, b))
    mat[b].append((i, a))

q = deque()
max_len = reduce(lambda a, x:max(a, len(x)), mat, 0)
q.append(0)
while len(q) > 0:
    current = q.popleft()

    used_colors = set([colors[p[0]] for p in mat[current] if colors[p[0]] > 0])
    col = 1

    for p in mat[current]:
        if colors[p[0]] > 0:
            continue
        while col in used_colors:
            col += 1
        colors[p[0]] = col
        col += 1
        q.append(p[1])
print(max_len)
for col in colors:
    print(col)
### BUGGY CODE ###

from collections import Counter
N, P = map(int, input().split())
S = input()

ans = 0
if P == 2:
    for i, s in enumerate(S, start=1):
        if int(s) % 2 == 0:
            ans += i
elif P == 5:
    for i, s in enumerate(S, start=1):
        if s in "05":
            ans += i
else:
    T = [0] * (N+1)
    d = 0
    for i, s in enumerate(S[::-1], start=1):
        s = int(s) * (10 ** d) + T[i - 1]
        T[i] = s % P
        d += 1
    c = Counter(T)
    ans = sum(x * (x - 1) // 2 for x in c.values())

print(ans)


### FIXED CODE ###

from collections import Counter
N, P = map(int, input().split())
S = input()

ans = 0
if P == 2:
    for i, s in enumerate(S, start=1):
        if int(s) % 2 == 0:
            ans += i
elif P == 5:
    for i, s in enumerate(S, start=1):
        if s in "05":
            ans += i
else:
    T = [0] * (N+1)
    d = 1
    for i, s in enumerate(S[::-1], start=1):
        s = int(s) * d + T[i - 1]
        T[i] = s % P
        d *= 10
        d %= P
    c = Counter(T)
    ans = sum(x * (x - 1) // 2 for x in c.values())

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

import sys

N = int(input())
As = [int(n) for n in input().split()]

limit = 10**18

prod = 1
over = False
for A in As:
    prod *= A
    if prod == 0:
        print(0)
        sys.exit(0)
    if prod > limit:
        over = True

if over:
    print(-1)
else:
    print(prod)

### FIXED CODE ###

import sys

N = int(input())

As = [int(n) for n in input().split()]
As_set = set(As)

limit = 10**18

prod = 1

if 0 in As_set:
    print(0)
    sys.exit(0)

over = False
for A in As:
    prod *= A
    if prod > limit:
        print(-1)
        sys.exit(0)

print(prod)
### BUGGY CODE ###

import sys
import numpy as np
input = sys.stdin.readline
N, W = map(int, input().split())
def knapsack():
  dp = np.zeros((N+1, W+1), dtype=int)
  for i in range(1, N+1):
    w, v = map(int, input().split())
    for sum_w in range(1, W+1):
      if sum_w - w >= 0:
        dp[i][sum_w] = max(dp[i-1][sum_w], dp[i-1][sum_w-w] + v)
      dp[i][sum_w] = max(dp[i][sum_w], dp[i-1][sum_w])
  return dp[-1][-1]
print(knapsack())

### FIXED CODE ###

import sys
import numpy as np
input = sys.stdin.readline
N, W = map(int, input().split())
def knapsack():
  dp = np.zeros((N+1, W+1), dtype=int)
  c = np.arange(1, N+1)
  for i in c:
    w, v = map(int, input().split())
    dp[i][w:] = np.maximum(dp[i-1][w:], dp[i-1][:-w] + v)
    dp[i][:] = np.maximum(dp[i][:], dp[i-1][:])
  return dp[-1][-1]
print(knapsack())
### BUGGY CODE ###

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

max_pos = 0
max_value = 0
for i in range(len(P)):
    if i + K > len(P):
        break
    tmp_sum = sum(P[i:i+K])
#    print(i, tmp_sum, P[i:i+K])
    if tmp_sum > max_value:
        max_value = tmp_sum
        max_pos = i

#print("--------", max_pos)
total = 0
for i in range(max_pos, max_pos + K):
    total += sum(list(range(1, P[i] + 1))) / P[i]
#    print(i, total, sum(list(range(1, P[i] + 1))) / P[i])

print(total)


### FIXED CODE ###

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

max_pos = 0
max_value = sum(P[:K])
tmp_sum = max_value
for i in range(N-K):
    tmp_sum = tmp_sum - P[i] + P[i+K]
#    print(i, max_value, tmp_sum, P[i:i+K], "-", P[i], "+", P[i+K])
    if tmp_sum > max_value:
        max_value = tmp_sum
        max_pos = i + 1

#print("--------", max_pos)
total = 0
for i in range(max_pos, max_pos + K):
    total += (P[i] + 1) / 2
#    print(i, total, sum(list(range(1, P[i] + 1))) / P[i])

print(total)
### BUGGY CODE ###

N = int(input())
S = str(input())
ans = N
for i in range(N):
    ans = min(S[:i].count('W') + S[i + 1:].count('E'), ans)
print(ans)


### FIXED CODE ###

N = int(input())
S = str(input())
x = S[1:].count('E')
ans = x
for i in range(1, N):
    if S[i] == 'E':
        x -= 1
    if S[i - 1] == 'W':
        x += 1
    ans = min(ans, x)
print(ans)
### BUGGY CODE ###

# https://img.atcoder.jp/abc123/editorial.pdf 解法 #1 - 工夫したソートで O(K^2 log K)

#import functools
#import operator
#import itertools

def solve(X, Y, Z, K, A, B, C):
#   AB = [functools.reduce(operator.add, x) for x in itertools.product(A, B)]
    AB = []
    for a in A:
        for b in B:
            AB.append(a + b)
    AB.sort(reverse=True)
    AB = AB[:K]

    ABC = []
    for ab in AB:
        for c in C:
            ABC.append(ab + c)
#   ABC = [functools.reduce(operator.add, x) for x in itertools.product(AB, C)]
    ABC.sort(reverse=True)
    ABC = ABC[:K]

    print("\n".join(map(str, ABC)))

if __name__ == "__main__":
    X, Y, Z, K = list(map(int, input().split()))
    A = sorted(list(map(int, input().split())), reverse=True)
    B = sorted(list(map(int, input().split())), reverse=True)
    C = sorted(list(map(int, input().split())), reverse=True)
    solve(X, Y, Z, K, A, B, C)

### FIXED CODE ###

from collections import defaultdict

def append(m, printed, cand_a, cand_b, cand_c):
    key = "{}-{}-{}".format(cand_a, cand_b, cand_c)
    key2 = "{}-{}-{}".format(cand_a-1, cand_b, cand_c)
    key3 = "{}-{}-{}".format(cand_a, cand_b-1, cand_c)
    key4 = "{}-{}-{}".format(cand_a, cand_b, cand_c-1)
    if not key in printed \
            and cand_a < len(A) \
            and cand_b < len(B) \
            and cand_c < len(C) \
            and not key in m \
            and not key2 in m \
            and not key3 in m \
            and not key4 in m :
#       print("Appended {}".format(key))
        m[key] = A[cand_a] + B[cand_b] + C[cand_c]
    return m

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

a = 0
b = 0
c = 0

n_print = 0
#print(A, B, C)
memo = {}
printed = defaultdict(lambda: False)
while True:
    summ = A[a] + B[b] + C[c]
    printed["{}-{}-{}".format(a, b, c)] = True

    print(summ)

#   print(memo.items())
#   print(a, b, c)
#   print("")

    n_print += 1
    if n_print == K:
        break

    memo = append(memo, printed, a+1, b, c)
    memo = append(memo, printed, a, b+1, c)
    memo = append(memo, printed, a, b, c+1)

    max_k = max(memo, key=memo.get)
    a, b, c = max_k.split("-")
    a = int(a)
    b = int(b)
    c = int(c)
        
    memo.pop(max_k)
#   print("Pop {}".format(max_k))
### BUGGY CODE ###


K=int(input())


if K % 2 == 0 or K % 5 == 0:
    print(-1)
    exit()


i=1

while True:
	if 7*int("1"*i)%K==0:
		exit(print(i))
	i+=1
	if i>1e+15:
		exit(print(-1))




### FIXED CODE ###


K=int(input())
a_i=7%K
i=1
if a_i==0:
	exit(print(1))
while True:
	i+=1
	a_i=(10*a_i+7)%K
	if a_i==0:
		print(i)
		exit()
	if i>=K:
		print(-1)
		exit()
### BUGGY CODE ###

N = int(input())

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

ans = 0
# bit 全探索する
for bit in range(1 << N):
    sum = 0

    for i in range(N):
        # bit にi 番目のフラグが立っているかどうか
        if bit & (1 << i):
            # フラグが立っているならsumに加算する
            sum += S[i]

    if sum % 10 == 0:
        sum = 0
    ans = max(ans, sum)

print(ans)

### FIXED CODE ###

N = int(input())

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

ans = sum(S)
if ans % 10 == 0: # 10の倍数の時
    min_s = float('inf')
    for s in S: # sの中から, 10の倍数でない、かつ最小のものを探してくる
        if s % 10 != 0:
            min_s = min(min_s, s)
    if min_s == float('inf'): # sの中に10の倍数でないものがなかったとき
        ans = 0
    else:
        ans -= min_s

print(ans)