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

class RollingHash:
    def __init__(self, s, base, mod):
        self.base = base
        self.mod = mod

        self.hash = [0]
        self.power = [1]
        for c in s:
            self.hash.append((self.hash[-1] * base + ord(c)) % mod)
            self.power.append(self.power[-1] * base % mod)

    def get(self, left, right):
        h = self.hash[right] - self.hash[left] * self.power[right - left]
        return (h + self.mod) % self.mod


n = int(input())
s = input().rstrip()
rh = RollingHash(s, base=10**4 + 7, mod=2**61 - 1)


def check(diff):
    d = {}
    for i in range(n - diff + 1):
        h = rh.get(i, i + diff)
        if h in d.keys():
            if abs(d[h] - i) >= diff:
                return True
        else:
            d[h] = i
    return False


lo = 0
hi = n // 2 + 1
while lo + 1 < hi:
    mid = (lo + hi) // 2
    if check(mid):
        lo = mid
    else:
        hi = mid
print(lo)

### FIXED CODE ###

def create_z_array(s):
    n = len(s)
    z_array = [0] * n
    left = 0
    right = 0
    for i in range(1, n):
        if i > right:
            left, right = i, i
            while right < n and s[right - left] == s[right]:
                right += 1
            z_array[i] = right - left
            right -= 1
        else:
            k = i - left
            if z_array[k] < right - i + 1:
                z_array[i] = z_array[k]
            else:
                left = i
                while right < n and s[right - left] == s[right]:
                    right += 1
                z_array[i] = right - left
                right -= 1
    return z_array


n = int(input())
s = input().rstrip()
res = 0
for i in range(n):
    z_array = create_z_array(s[i:])
    for j in range(1, len(z_array)):
        res = max(res, min(j, z_array[j]))
print(res)
### BUGGY CODE ###

import numpy as np
import scipy as sp
import scipy.sparse.csgraph as sg

H, W = [int(a) for a in input().split()]
ss = []
for _ in range(H):
    ss.append(input())

g = np.zeros((H*W,H*W))

v_edges = [((i,j), (i,j+1)) for i in range(H) for j in range(W-1) if ss[i][j] == "." and ss[i][j+1] == "."]
h_edges = [((i,j), (i+1,j)) for i in range(H-1) for j in range(W) if ss[i][j] == "." and ss[i+1][j] == "."]

for (si,sj), (di,dj) in v_edges + h_edges:
    g[si*W+sj][di*W+dj] = 1
    g[di*W+dj][si*W+sj] = 1

r = sg.dijkstra(g)
score = r[0,H*W-1]

if sp.isinf(score):
    print(-1)
    exit(0)
else:
    #print(r)
    #print(ss) 

    ss_ = "".join(ss)
    num = len([0 for c in ss_ if c == '.'])
    #print(num)
    #print(score)
    print("%d" % (num - (score+1)))




### FIXED CODE ###

import numpy as np
import scipy as sp
import scipy.sparse.csgraph as sg

H, W = [int(a) for a in input().split()]
ss = []
for _ in range(H):
    ss.append(input())

g = np.zeros((H*W,H*W))

v_edges = [((i,j), (i,j+1)) for i in range(H) for j in range(W-1) if ss[i][j] == "." and ss[i][j+1] == "."]
h_edges = [((i,j), (i+1,j)) for i in range(H-1) for j in range(W) if ss[i][j] == "." and ss[i+1][j] == "."]

for (si,sj), (di,dj) in v_edges + h_edges:
    g[si*W+sj][di*W+dj] = 1
    g[di*W+dj][si*W+sj] = 1

r = sg.dijkstra(g, indices=[0,H*W-1])
score = r[0,H*W-1]

if sp.isinf(score):
    print(-1)
    exit(0)
else:
    #print(r)
    #print(ss) 

    ss_ = "".join(ss)
    num = len([0 for c in ss_ if c == '.'])
    #print(num)
    #print(score)
    print("%d" % (num - (score+1)))
### BUGGY CODE ###

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

res_lst = []
for i in range(n-k+1):
  lst = xs[i:i+k]
  res = min(abs(lst[0]) + abs(lst[-1] - lst[0]), abs(lst[-1]) + abs(lst[0] - lst[-1]))
  res_lst.append(res)
print(min(res_lst))

### FIXED CODE ###

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

min_ = None
for i in range(n-k+1):
  res = min(abs(xs[i]) + abs(xs[i+k-1] - xs[i]), abs(xs[i+k-1]) + abs(xs[i] - xs[i+k-1]))
  if min_ is None:
    min_ = res
  else:
    min_ = min(res, min_)
print(min_)
### BUGGY CODE ###

n=int(input())

for p in range(1, n+1):
  right=45
  cnt=0
  for i in range(1, right):
    for j in range(1, i+1):
      for k in range(1, j+1):
        if (i+j+k)**2-i*j-j*k-k*i==p:
          if i==j and j==k:
            cnt+=1
          elif i==j and j!=k:
            cnt+=3
          elif j==k and k!=i:
            cnt+=3
          elif k==i and i!=j:
            cnt+=3
          elif i!=j and j!=k and k!=i:
            cnt+=6
  print(cnt)

### FIXED CODE ###

n=int(input())
lst=[0]*10000000
for i in range(1, 101):
  for j in range(1, i+1):
    for k in range(1, j+1):
      temp=i**2+j**2+k**2+i*j+j*k+k*i
      if i==j and j==k:
        lst[temp+1]+=1
      elif i==j and j!=k:
         lst[temp+1]+=3
      elif j==k and k!=i:
         lst[temp+1]+=3
      elif k==i and i!=j:
         lst[temp+1]+=3
      elif i!=j and j!=k and k!=i:
         lst[temp+1]+=6
for p in range(1, n+1):
  print(lst[p+1])
### BUGGY CODE ###

n = int(input())
a = str(input())
for i in range(n):
    print(a.count(str(i + 1)))

### FIXED CODE ###

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

nm = lambda : map(int,input().split())
nl = lambda : list(nm())
import heapq as h

n,m,l = nm()
se = set()
g = [list() for _ in range(n+1)]
ans = dict()
for _ in range(m):
    a,b,c = nm()
    g[a].append((b,c))
    g[b].append((a,c))
q = int(input())
query = list()
for _ in range(q):
  s,t = nm()
  if s > t:
    s,t = t,s
  se.add(s)
  query.append((s,t))
  


def move(tup,cost):
    if tup[1] + cost > 0:
        if l < cost:
            return -1
        return (tup[0]+1,cost-l)
    return (tup[0],tup[1]+cost)

for st in se:
    dist = [-1]*(n+1)
    que = [((0,-l),st)]
    while que:
        tup,v = h.heappop(que)
        if dist[v] != -1 and dist[v] < tup:
            continue
        dist[v] = tup
        for x,c in g[v]:
            if dist[x] != -1:
               continue
            new = move(tup,c)
            if new != -1:
                h.heappush(que,(new,x))
    ans[st] = dist

for s,t in query:
    if ans[s][t] == -1:
        print(-1)
    else:
        print(ans[s][t][0]) 
 

### FIXED CODE ###

n,m,l = map(int,input().split())
g = [[1<<30]*n for _ in range(n)]
for _ in range(m):
  a,b,c = map(int,input().split())
  g[a-1][b-1] = c
  g[b-1][a-1] = c
for i in range(n):
  g[i][i] = 0

def bell(g,n):
  for k in range(n):
    for i in range(n-1):
      for j in range(i+1,n):
        if g[i][j] > g[i][k] + g[k][j]:
          g[i][j] = g[i][k] + g[k][j]
          g[j][i] = g[i][j]
  return g

g = bell(g,n)
for i in range(n):
  for j in range(n):
    if i == j:
      g[i][j] = 0
    elif g[i][j] <= l:
      g[i][j] = 1
    else:
      g[i][j] = 1<<30
g = bell(g,n)

q = int(input())
for _ in range(q):
  s,t = map(int,input().split())
  if g[s-1][t-1]>>30:
    print(-1)
  else:
    print(g[s-1][t-1]-1)
### BUGGY CODE ###

H,W = map(int,input().split())
S_X=[]
S_Y=[]
C_X=[]
C_Y=[]
ans_list=[]
a=1000000000000

for i in range(H):
    A = list(input())
    for j in range(W):
        if A[j] == '#':
            S_X.append(i+1)
            S_Y.append(j+1)
        else :
            C_X.append(i+1)
            C_Y.append(j+1)

S_len=len(S_X)
C_len=len(C_X)


for i in range(C_len):
    for j in range(S_len):
        a = min(a,(abs(S_X[j]-C_X[i])+abs(S_Y[j]-C_Y[i])))
    ans_list.append(a*(-1))
    a = 100000000000

ans_list.sort()

if C_len == 0:
    print(0)
else:
    print(ans_list[0]*(-1))


### FIXED CODE ###

import numpy as np

H,W=map(int,input().split())
max_value = H+W
matrix =[]

for _ in range(H):
    matrix.append([0 if i == '#' else max_value for i in list(input())])
matrix = np.array(matrix)

for c in range(W-1):
    matrix[:,c+1] = np.minimum(matrix[:,c]+1,matrix[:,c+1])
for c in range(W-1,0,-1):
    matrix[:,c-1] = np.minimum(matrix[:,c-1],matrix[:,c]+1)
for r in range(H-1):
    matrix[r+1,:] = np.minimum(matrix[r,:]+1,matrix[r+1,:])
for r in range(H-1,0,-1):
    matrix[r-1,:] = np.minimum(matrix[r,:]+1,matrix[r-1,:])


print(np.max(matrix))
### BUGGY CODE ###

# 有効グラフ上で、近道に当たる点はすべて余計な辺
# ある点に入ってくる最も距離が長い辺のみが有効となる
# 一番距離が長い人版ダイクストラやってみる
# 入力のあった頂点を記録することで、入力の無かった頂点を根とみなせる

import sys
readline = sys.stdin.readline

N,M = map(int,readline().split())
G = [[] for i in range(N)]
grandparent = set(range(N))
for i in range(N - 1 + M):
  a,b = map(int,readline().split())
  G[a-1].append(b-1)
  grandparent -= {b - 1}

start = list(grandparent)[0]
import heapq

# 距離, 頂点, 親
q = [(0, start, -1)]
heapq.heapify(q)

# ans[頂点] = (到達コスト,親)
ans = [(-1, -1) for i in range(N)]
while q:
  dist, v, parent = heapq.heappop(q)
  dist = -dist
  if ans[v][0] >= dist:
    continue
  ans[v] = (dist, parent)
  for child in G[v]:
    heapq.heappush(q,(-(dist + 1), child, v))
    
for a in ans:
  print(a[1] + 1)

### FIXED CODE ###

# トポロジカルソート

import sys
readline = sys.stdin.readline

N,M = map(int,readline().split())
G = [[] for i in range(N)]
revG = [[] for i in range(N)]
# ある頂点に対する入次数を記録
indegree = [0 for i in range(N)]

for i in range(N - 1 + M):
  u,v = map(int,readline().split())
  G[u - 1].append(v - 1)
  revG[v - 1].append(u - 1)
  indegree[v - 1] += 1

# トポロジカルソートを格納する
res = []

# 入り次数が0になった頂点を高速に発見するため、隣接する頂点をキューで管理
from collections import deque
q = deque()
for i in range(len(indegree)):
  if indegree[i] == 0:
    q.append(i)

while q:
  # キューの先頭の頂点を取り出す
  v = q.popleft()
  
  # その頂点と隣接する頂点の入次数を減らし、0になったらキューに追加
  for child in G[v]:
    indegree[child] -= 1
    if indegree[child] == 0:
      q.append(child)
      
  # 入り次数が0で且つ隣接する頂点が処理済みとなった頂点をソート配列に追加する
  res.append(v)
  
# インデックスと頂点番号を逆転させたものを作成する
inds = [-1 for i in range(N)]
for i in range(len(res)):
  inds[res[i]] = i
  
# print(inds)
for i in range(len(revG)):
  ans = -1
  maxv = -1
  for parent in revG[i]:
#    print("i",i,"に対する親",parent)
    if inds[parent] > maxv:
      maxv = inds[parent]
      ans = parent
  print(ans + 1)
### BUGGY CODE ###

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


N,M = list(map(int,input().split()))
Network = UnionFind(N)

out = 0
for i in range(M):
    a, b = list(map(int,input().split()))
    Network.union(a-1, b-1)

out = 0
for L in Network.all_group_members().values():
    out = max(out,len(L))
print(out)

### FIXED CODE ###

N,M = list(map(int,input().split()))
from collections import deque

G = [[] for i in range(N)]
for i in range(M):
    A,B=list(map(int,input().split()))
    G[A-1].append(B-1)
    G[B-1].append(A-1)

Ls = []
dist = [0]*N
for i in range(N):
    if dist[i]==1:
        continue
    s = i
    que = deque([s])
    dist[s] = 1
    L = [s]
    while que:
        v = que.popleft()
        for w in G[v]:
            if dist[w]==1:
                continue
            dist[w] = 1
            que.append(w)
            L.append(w)
    Ls.append(L)
out = 0
for L in Ls:
    out=max(len(L),out)
print(out)
### BUGGY CODE ###

import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


n,c = li()
x_cw = []
v_cw = []
x_ccw = []
for _ in range(n):
    x,v = li()
    x_cw.append(x)
    v_cw.append(v)
    x_ccw.append(c-x)
    
x_ccw = [0] + sorted(x_ccw)
v_ccw = [0] + v_cw[::-1]
x_cw = [0] + x_cw
v_cw = [0] + v_cw
    
for i in range(1,n+1):
    v_cw[i] += (v_cw[i-1] - (x_cw[i]-x_cw[i-1]))
    v_ccw[i] += (v_ccw[i-1] - (x_ccw[i]-x_ccw[i-1]))
    
    
cw = []
ccw = []

ans = 0
for cw in range(n+1):
    for ccw in range(n+1):
        if cw + ccw > n:
            continue
        
        temp = v_cw[cw] + v_ccw[ccw] - min(x_cw[cw],x_ccw[ccw])
        ans = max(temp, ans)
        
print(ans)



### FIXED CODE ###

from itertools import accumulate
import sys
sdin = sys.stdin.readline

n,c = map(int, sdin().split())
x_cw = [0]
v_cw = [0]
for _ in range(n):
    x, v =  map(int, sdin().split())
    x_cw.append(x)
    v_cw.append(v)
    
v_cw_acc = list(accumulate(v_cw))    

# 反時計回りの距離と栄養価
x_ccw = [0]
v_ccw = [0]
for i in range(n):
    x_ccw.append(c-x_cw[n-i])
    v_ccw.append(v_cw[n-i])
    
v_ccw_acc = list(accumulate(v_ccw))

# cw, ccwそれぞれでの各寿司ナンバーまでのmaxを求める
total_cw_max = [0]
total_ccw_max = [0]
for i in range(1,n+1):
    tmp_cw = v_cw_acc[i] - x_cw[i]
    total_cw_max.append(max(total_cw_max[-1], tmp_cw))
    
    tmp_ccw = v_ccw_acc[i] - x_ccw[i]
    total_ccw_max.append(max(total_ccw_max[-1], tmp_ccw))
    
# b側を固定する
ans_b_static = 0
for b in range(n,-1, -1):
    tmp_b_static = total_cw_max[n-b] + v_ccw_acc[b] - 2*x_ccw[b]
    ans_b_static = max(ans_b_static, tmp_b_static)
    
# a側を固定する
ans_a_static = 0
for a in range(n, -1, -1):
    tmp_a_static = total_ccw_max[n-a] + v_cw_acc[a] - 2*x_cw[a]
    ans_a_static = max(ans_a_static, tmp_a_static)
    
# その大きい方が答え
print(max(ans_a_static, ans_b_static))
### BUGGY CODE ###

import sys

def main():
    input = sys.stdin.readline
    H, W, D = map(int, input().split())
    d = {}

    for i in range(H):
        row = list(map(int, input().split()))
        for j in range(W):
            d[row[j]] = [i, j]

    Q = int(input())
    for _ in range(Q):
        ans = 0
        L, R = map(int, input().split())
        while L != R:
            a = d[L]
            b = d[L+D]
            ans += abs(a[0] - b[0]) + abs(a[1] - b[1])
            L += D
        print(ans)


if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys

def main():
    input = sys.stdin.readline
    H, W, D = map(int, input().split())
    d = [0] * (H*W + 1)

    for i in range(H):
        row = list(map(int, input().split()))
        for j in range(W):
            d[row[j]] = [i, j]

    A = [0] * (H*W + 1)
    for l in range(H * W - D, 0, -1):
        a = d[l]
        b = d[l+D]
        A[l] = A[l+D] + abs(a[0] - b[0]) + abs(a[1] - b[1])

    Q = int(input())
    for _ in range(Q):
        L, R = map(int, input().split())
        print(A[L] - A[R])


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

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

v = [0] * N
w = [0] * N
dp = [[-1 for i in range(W + 1)] for j in range(N + 1)]

for i in range(N):
    v[i], w[i] = map(int, input().split())

def rec(i, j):
    if dp[i][j] != -1:
        return dp[i][j]

    if i == N:
        res = 0
    elif j < w[i]:
        res = rec(i + 1, j)
    else:
        res = max(rec(i + 1, j), rec(i + 1, j - w[i]) + v[i])
    return res

print(rec(0, W))

### FIXED CODE ###

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

v = [0] * N
w = [0] * N
dp = [[0 for i in range(W + 1)] for j in range(N + 1)]

for i in range(N):
    v[i], w[i] = map(int, input().split())

for i in range(N - 1, -1, -1):
    for j in range(W + 1):
        if j < w[i]:
            dp[i][j] = dp[i + 1][j]
        else:
            dp[i][j] = max(dp[i + 1][j], dp[i + 1][j - w[i]] + v[i])

print(dp[0][W])
### BUGGY CODE ###

def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

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

for _ in range(Q):
    Query = list(input().split())
    T = int(Query[0])
    if T == 1:
        S = S[::-1]
    else:
        F = int(Query[1])
        C = Query[2]
        if F == 1:
            S = C + S
        else:
            S = S + C
print(S)

### FIXED CODE ###

def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
from collections import deque

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

# Queries = []
# for _ in range(Q):
#     Queries.append(list(input().split()))
    
# for Query in Queries:
#     T = int(Query[0])
#     if T == 1:
#         S = S[::-1]
#     else:
#         F = int(Query[1])
#         C = Query[2]
#         if F == 1:
#             S = C + S
#         else:
#             S = S + C
# print(S)

swap = 1
head = deque()
tail = deque()
for _ in range(Q):
    Query = list(input().split())

    if Query[0] == "1":
        swap *= -1
    
    else:
        F, C = Query[1], Query[2]
        if F == "1":
            if swap == 1:
                head.appendleft(C)
            else:
                tail.append(C)
        else:
            if swap == -1:
                head.appendleft(C)
            else:
                tail.append(C)         


print(("".join(head) + S + "".join(tail))[::swap])
### BUGGY CODE ###

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

if d[0]!=0:
  print(0)
  exit()

#1番目以外で1との距離が0はありえんのでそれは消す
for i in range(n):
  if i!=0:
    if d[i]==0:
      print(0)
      exit()

kyori=[] #1からmaxdまでの距離について、それぞれ何個のdが該当するかメモした配列
maxd=max(d)

for i in range(1,maxd+1):
  kyori.append(d.count(i))

#print(kyori)

ans=1
for i in range(maxd-1):
  temp=kyori[i]**kyori[i+1]
  ans*=temp%998244353
  ans=ans%998244353

print(ans)

### FIXED CODE ###

import sys
input=sys.stdin.readline

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

if d[0]!=0:
  print(0)
  exit()

 #1からmaxdまでの距離について、それぞれ何個のdが該当するかメモした配列
maxd=max(d)
kyori=[0]*(maxd+1)

#計算量減らし、、
for i in d:
  kyori[i]+=1

#1個目以外で距離0のやつある場合は停止。
if kyori[0]!=1:
  print(0)
  exit()

ans=1
for i in range(1,maxd):
  temp=kyori[i]**kyori[i+1]
  ans*=temp%998244353
  ans=ans%998244353
print(ans)
### BUGGY CODE ###

import numpy as np
import itertools

N = int(input())

X = []
for i in range(N):
  X.append(list(map(int,input().split())))

pattern = list(itertools.permutations(X))
dist_sum = 0

for i in pattern:
  for j in range(N-1):
    a = np.array(i[j])
    b = np.array(i[j+1])
    dist = np.linalg.norm(a-b)
    dist_sum += dist

#平均計算
dist_avr = dist_sum / len(pattern)
print(dist_avr)

### FIXED CODE ###

import numpy as np
import math
import itertools

N = int(input())

X = []
for i in range(N):
  X.append(list(map(int,input().split())))

pattern = list(itertools.combinations(X, 2))
pattern2 = list(itertools.permutations(X))
dist_list = []

for i in pattern:
  a = np.array(i[0])
  b = np.array(i[1])
  dist_list.append(np.linalg.norm(a-b))
  
#係数求める
kaijou = math.factorial(N)
nC2 = len(pattern2)

k = (kaijou * (N-1)) / nC2

print(sum(dist_list)*k / len(pattern))
### BUGGY CODE ###

import math
k = int(input())
ans = 0
for i in range(k):
  for j in range(k):
    for l in range(k):
      ans += math.gcd(math.gcd(i+1,j+1),l+1)
print(ans)

### FIXED CODE ###

from math import gcd
k = int(input())+1
ans = 0
for i in range(1,k):
  for j in range(1,k):
    for l in range(1,k):
      ans += gcd(gcd(i,j),l)
print(ans)
### BUGGY CODE ###

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

ansAC=0
ansP=0

n=[0]*N
AC=[]

for i in range(M):
    p,s =map(str,input().split())
    p=int(p)-1
    if p in AC:continue

    if s=="AC":
        ansP+=n[p]
        ansAC+=1
        AC.append(p)
    else:
        n[p]+=1

print(ansAC,ansP)


### FIXED CODE ###

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

ansAC=0
ansP=0

n=[0]*N
AC=[0]*N

for i in range(M):
    p,s =map(str,input().split())
    p=int(p)-1
    if AC[p]==1:continue
    if s=="AC":
        ansP+=n[p]
        ansAC+=1
        AC[p]=1
    else:
        n[p]+=1

print(ansAC,ansP)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
from heapq import merge
from bisect import bisect
def inpl(): return list(map(int, input().split()))

X, Y, Z, K = inpl()
A = inpl()
B = inpl()
C = sorted(inpl(), reverse=True)

AB = sorted([a+b for a in A for b in B])[-K:]
ans = [-1] * K

for c in C:
    if ans[0] > AB[-1] * c:
        break
    tmp = [ab + c for ab in AB][-K:]
    ans = list(merge(ans, tmp))[-K:]

print(*ans[::-1], sep="\n")


### FIXED CODE ###

# -*- coding: utf-8 -*-
from heapq import merge
from bisect import bisect
def inpl(): return list(map(int, input().split()))

X, Y, Z, K = inpl()
A = sorted(inpl())
B = sorted(inpl())
C = sorted(inpl(), reverse=True)

AB = [-1] * K
for a in A[::-1]:
    if AB[0] >= B[-1] + a:
        break
    tmp = [a + b for b in B[bisect(B, AB[0]-a):]][-K:]
    AB = list(merge(tmp, AB))[-K:]

ans = [-1] * K

for c in C:
    if ans[0] >= AB[-1] + c:
        break
    tmp = [ab + c for ab in AB[bisect(AB, ans[0]-c):]][-K:]
    ans = list(merge(ans, tmp))[-K:]

print(*ans[::-1], sep="\n")
### BUGGY CODE ###

inp = input()
cnt = 0

inf = 10 ** 18
for i in range(inf):
  cnt_10 = inp.count('10')
  if cnt_10 > 0:
    cnt += cnt_10 * 2
    inp = inp.replace('10','')

  cnt_01 = inp.count('01')
  if cnt_01 > 0:
    cnt += cnt_01 * 2
    inp = inp.replace('01','')  
  
  if (cnt_01 == 0) & (cnt_10 == 0):
    break

print(cnt)

### FIXED CODE ###

inp = input()

cnt_0 = inp.count('0')
cnt_1 = inp.count('1')

if (cnt_0 == 0) or (cnt_1 == 0):
  print(0)
else:
  print(min(cnt_0,cnt_1) * 2)
### BUGGY CODE ###

import collections

N = int(input())
L = [int(i) for i in input().split()]
c = collections.Counter(L)

ans = 0
for i in c:
    for j in c:
        for k in c:
            if i + j <= k or j + k <= i or k + i <= j or i > j or j > k:
                continue
            if i == j and j == k:
                ans += c[i] * (c[i] - 1) * (c[i] - 2) / 6
            elif i == j:
                ans += c[k] * c[i] * (c[i] - 1) / 2
            elif j == k:
                ans += c[i] * c[j] * (c[j] - 1) / 2
            elif i == k:
                ans += c[j] * c[i] * (c[i] - 1) / 2
            else:
                ans += c[i] * c[j] * c[k]
print(int(ans))


### FIXED CODE ###

import collections

N = int(input())
L = [int(i) for i in input().split()]
M = max(L)
c = collections.Counter(L)
li = [c[i] for i in range(M+1)]

ans = 0
for i in range(1,M+1):
    for j in range(i,M+1):
        if i == j:
            ans += int(li[i] * (li[i] - 1) * (li[i] - 2) / 6)
            ans += int(sum(li[j+1:min(M+1, i+j)]) * li[i] * (li[i] - 1) / 2)
        else:
            ans += int(li[i] * li[j] * (li[j] - 1) / 2)
            ans += li[i] * li[j] * sum(li[j+1:min(M+1, i+j)])
print(int(ans))
### BUGGY CODE ###

n = int(input())
num = []
for i in range(n):
    a = int(input())
    num.append(a)

for i in range(n):
    b = num[i]
    num[i] = 0
    print(max(num))
    num[i] = b

### FIXED CODE ###

n = int(input())
num = []
for i in range(n):
    a = int(input())
    num.append(a)

idx = num.index(max(num))
max_a = max(num)

num_c = num
num_c[idx] = 0
idx_2 = num_c.index(max(num_c))
max_a2 = max(num_c)

for i in range(n):
    if i == idx:
        print(max_a2)
    else:
        print(max_a)