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

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

from itertools import combinations

MOD = 10**9+7
result = 0
for seq in combinations(range(0, n), 2):
  result += a[seq[0]] * a[seq[1]] % MOD
print(result%MOD)


### FIXED CODE ###

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

s=[0]*(n+1)
for i in range(n):
  s[i+1] = s[i] + a[i]

MOD = 10**9+7
result = 0
for i in range(n):
  result += a[i]*(s[n] - s[i+1])%MOD
print(result%MOD)
### BUGGY CODE ###

#E問題
N,M=map(int,input().split())
S=str(input())
Slist=list(S)
T=str(input())
Tlist=list(T)
#gcd(二つの数)
def gcd(GCD1,GCD2):
    x = min(GCD1,GCD2)
    y = max(GCD1,GCD2)
    if y%x == 0:
        return x
    else:
        return gcd(x,y%x)
MINA=int(N*M/gcd(N,M))
n=int(MINA/N)
m=int(MINA/M)
SS=["*" for i in range(MINA)]
TT=["*" for i in range(MINA)]
for i in range(N):
    SS[n*i]=Slist[i]
for i in range(M):
    TT[m*i]=Tlist[i]
flag=0
for i in range(MINA):
    if SS[i] == TT[i] or SS[i]=="*" or TT[i]=="*":
        pass
    else:
        flag=1
if flag==0:
    print(MINA)
else:
    print(-1)

### FIXED CODE ###

#E問題
N,M=map(int,input().split())
S=str(input())
Slist=list(S)
T=str(input())
Tlist=list(T)
#gcd(二つの数)
def gcd(GCD1,GCD2):
    x = min(GCD1,GCD2)
    y = max(GCD1,GCD2)
    if y%x == 0:
        return x
    else:
        return gcd(x,y%x)
MINA=int(N*M/gcd(N,M))
n=int(MINA/N)
m=int(MINA/M)
flag=0
nn=int(M/n)
mm=int(N/m)
SS=[]
TT=[]
for i in range(mm):
    SS.append(Slist[i*m])
for i in range(nn):
    TT.append(Tlist[i*n])
if SS != TT:
    flag=1
if flag==0:
    print(MINA)
else:
    print(-1)
### BUGGY CODE ###

from collections import Counter
n=int(input())
#s=[input() for i in range(n)]
s=[Counter(input()) for i in range(n)]
ans=0
for i in range(n):
  for j in range(i+1,n):
    if s[i]==s[j]:
      ans+=1
print(ans)
#def verify_anagrams(first_word, second_word):
#    return Counter(first_word) == Counter(second_word)

### FIXED CODE ###

n=int(input())
s=["".join(sorted(list(input()))) for i in range(n)]
s.sort()
dp=[1]
for i in range(n-1):
  if s[i]==s[i+1]:
    dp[len(dp)-1]+=1
  else:
    dp.append(1)
ans=0
for i in dp:
  ans+=i*(i-1)//2
print(ans)
### BUGGY CODE ###


def get_num_f(data, sum_data):
    left1, left2 = 0, sum_data
    for i in range(len(data)- 1):
        if left1 + data[i] >= left2 - data[i]:
            pre_d = abs(left1 - left2)
            now_d = abs((left1 + data[i]) - (left2 - data[i]))
            if now_d < pre_d:
                left1 += data[i]
                left2 -= data[i]
            break
        left1 += data[i]
        left2 -= data[i]
    return left1, left2




def main():
    num = int(input())
    data = list(map(int, input().split()))

    sum_left, sum_righ = sum(data[:2]), sum(data[2:])
    left1, left2 = get_num_f(data[:2], sum_left)
    righ1, righ2 = get_num_f(data[2:], sum_righ)

    ans = max(left1, left2, righ1, righ2) - min(left1, left2, righ1, righ2)

    for i in range(2, num - 2):
        sum_left += data[i]
        sum_righ -= data[i]
        left1, left2 = get_num_f(data[:i + 1], sum_left)
        righ1, righ2 = get_num_f(data[i + 1:], sum_righ)
        ans_kari = max(left1, left2, righ1, righ2) - min(left1, left2, righ1, righ2)

        if ans_kari < ans:
            ans = ans_kari

    print(ans)



if __name__ == '__main__':
    main()

### FIXED CODE ###


def main():
    num = int(input())
    data = list(map(int, input().split()))

    l, c, r = 1, 2, 3
    P = sum(data[:l])
    Q = sum(data[l:c])
    R = sum(data[c:r])
    S = sum(data[r:])

    ans = max(P, Q, R, S) - min(P, Q, R, S)

    while c <= num-2:
        while True:
            if abs(P-Q) < abs((P+data[l])-(Q-data[l])):
                break

            if l == c-1:
                break

            P += data[l]
            Q -= data[l]
            l += 1

        while True:
            if abs(R-S) < abs((R+data[r])-(S-data[r])):
                break
            if r == num-1:
                break

            R += data[r]
            S -= data[r]
            r += 1

        ans = min(max(P,Q,R,S)- min(P,Q,R,S), ans)

        # centerについて調整
        Q += data[c]
        R -= data[c]
        c += 1

    print(ans)

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

def main():
    n, m = map(int, input().split())
    lr_lst = [list(map(int, input().split())) for _ in range(m)]

    ans = 0

    for i in range(1, n + 1):
        is_able = True
        for j in range(m):
            if not lr_lst[j][0] <= i <= lr_lst[j][1]:
                is_able = False
                break
        if is_able:
            ans += 1

    print(ans)


if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    n, m = map(int, input().split())
    lr_lst = [list(map(int, input().split())) for _ in range(m)]
    left = 0
    right = n + 1

    for i in range(m):
        if left < lr_lst[i][0]:
            left = lr_lst[i][0]
        if lr_lst[i][1] < right:
            right = lr_lst[i][1]

    if right - left < 0:
        print(0)
    else:
        print(right - left + 1)


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

from sys import setrecursionlimit

setrecursionlimit(10 ** 8)


def main(x, k, d):
    for i in range(k):
        if abs(x + d) < abs(x - d):
            x = x + d
        else:
            x = x - d

        if abs(x - d) > abs(x) and abs(x + d) > abs(x):
            if (k - i - 1) % 2 == 1:
                if abs(x - d) < abs(x + d):
                    x = x - d
                else:
                    x = x + d
            break
    print(abs(x))


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

main(a, b, c)


### FIXED CODE ###

from sys import setrecursionlimit

setrecursionlimit(10 ** 8)


def main(x, k, d):
    for i in range(k):
        if abs(x + d) < abs(x - d):
            x = x + d
        else:
            x = x - d

        if abs(x - d) > abs(x) and abs(x + d) > abs(x):
            if (k - i - 1) % 2 == 1:
                if abs(x - d) < abs(x + d):
                    x = x - d
                else:
                    x = x + d
            break

    print(abs(x))


def sub(x, k, d):
    print(abs(x) - d * k)


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

if abs(a) - b * c >= 0:
    sub(a, b, c)
else:
    main(a, b, c)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
"""
Created on Tue Jan 21 16:49:00 2020

@author: matsui
"""

def cost(i,j):
    return abs(int(h[i])-int(h[j]))

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

dp=[0]*N
   
for i in range(1,N):
    mi=cost(i,i-1)+dp[i-1]
    for j in range(max(0, i-K), i-1):
        mi=min(cost(i,j)+dp[j],mi)
    dp[i]=mi
    
print(dp[N-1])

### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
Created on Tue Jan 21 16:49:00 2020

@author: matsui
"""



N,K=map(int,input().split())
h=[int(num) for num in input().split()]

dp=[0]*N
dp[1]=abs(h[0]-h[1])
   
def cost(h,N,K,dp):
    for i in range(2,N):
        dp[i]=min([abs(h[i]-h[j])+dp[j] for j in range(max(0, i-K), i)])
    return dp[-1]
    
print(cost(h,N,K,dp))
### BUGGY CODE ###

import sys
input = sys.stdin.readline


def main():
    N = int(input())
    A = list(map(int, input().split()))
    ans = 0
    for i in range(N-1):
        for j in range(i, N):
            ans += A[i] ^ A[j]
            ans %= 10**9+7
    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
input = sys.stdin.readline


def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = [0]*60
    for a in A:
        for i in range(len(B)):
            if a & (2**i):
                B[i] += 1
    ans = 0
    for i, b in enumerate(B):
        ans += 2**i * b * (N-b)
        ans %= 10**9+7
    print(ans)


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

from collections import deque
n,m,k = [int(x) for x in input().split()]
l = [[] for i in range(n+1)]
p = []
q = []
d2 = deque()
for i in range(m):
    p.append(list(map(int, input().split())))
for i in range(k):
    q.append(list(map(int, input().split())))
for pi in p:  
    l[pi[0]].append(pi[1])
    l[pi[1]].append(pi[0])
#ここまでで、グラフが隣接リスト表記で表される
dist =[[-1] * (n+1) for i in range(n+1)]
for z in range(1,n+1):
  d = deque()
  dist[z][z] = 0
  d.append(z)
  while True:
    v = d.popleft()
    for i in l[v]:
      if dist[z][i] != -1:
        continue
      dist[z][i] = dist[z][v] + 1
      d.append(i)
    if not d:
      break
for qi in q:  
    dist[qi[0]][qi[1]] = -1
    dist[qi[1]][qi[0]] = -1
for i in range(1,n+1):
  print(1+n-dist[i].count(0)-dist[i].count(1)-dist[i].count(-1),end=" ")

### FIXED CODE ###

import sys
sys.setrecursionlimit(100000)
N,m,k = [int(x) for x in input().split()]
p = []
q = []
roots = [0]*(N+1)
rootmatome = [0]*(N+1)
tonari = [0]*(N+1)
dame = [0]*(N+1)
for i in range(m):
    p.append(list(map(int, input().split())))
for i in range(k):
    q.append(list(map(int, input().split())))
par = []
for i in range(N+1):
    par.append(i)
def root(x):
    if par[x] == x:
        return x
    par[x] = root(par[x])#この一文で早くなる
    return root(par[x])
def unite(x,y):
    rx = root(x)
    ry = root(y)
    if rx == ry:
        return
    par[rx] = ry
for i in range(m):
    unite(p[i][0],p[i][1])
for i in range(1,N+1):
  roots[i] = root(i)
for i in range(1,N+1):
    rootmatome[roots[i]] += 1
for i in range(m):
    tonari[p[i][0]] += 1
    tonari[p[i][1]] += 1
for i in range(k):
    if roots[q[i][0]] == roots[q[i][1]]:
        dame[q[i][0]] += 1
        dame[q[i][1]] += 1
for i in range(1,N+1):
    print(rootmatome[roots[i]] - tonari[i] - dame[i] - 1,end=" ")
### BUGGY CODE ###

param_a = int(input())

if param_a%2==0:
    print(-1)
    
elif param_a%5==0:
    print(-1)

else:
    for i in range(1000000):
        param_str = '7'*(i+1)
        param_int = int(param_str)
        
        if param_int % param_a == 0:
            param_answer = i+1
            break
     
    try:
        print(param_answer)
    except:
        print(-1)

### FIXED CODE ###

# https://atcoder.jp/contests/abc174/submissions/15768313 さんの回答、参照

K = int(input())
num = 0
if K%2 == 0:
    print(-1)
else:
    for i in range(1, 1000000):
        num = num*10 + 7
        num %= K
        if num == 0:
            print(i)
            break
    else:
        print(-1)
### BUGGY CODE ###

#D

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

n, a, b = map(int, input().split())
whole_sum = (2 ** n) - 1
mod = 10 ** 9 + 7

whole_sum -= cmb(n, a)
whole_sum -= cmb(n, b)

print(whole_sum % mod)

### FIXED CODE ###

#D 復習
n, a, b = map(int, input().split())
mod = 10 ** 9 + 7
whole_sum = pow(2, n, mod) - 1

def combinations_mod(n, k, mod):
    X, Y = 1, 1
    for i in range(1, k+1):
        X = (X * (n-i+1))%mod
    for j in range(1, k+1):
        Y = (Y*j)%mod
    result = X * (pow(Y, mod-2, mod))
    return result%mod

whole_sum -= combinations_mod(n, a, mod)
whole_sum -= combinations_mod(n, b, mod)

print(whole_sum % mod)
### BUGGY CODE ###

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

A, B, C, K = map(int, input().split())

for i in range(K):
    a = A
    b = B
    c = C

    A = b + c
    B = a + c
    C = a + b

ans = A - B

if ans >= 10**18 or (-1)*ans >= 10**18:
    ans = 'Unfair'


print(ans)


### FIXED CODE ###

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

'''
A, B, C, K = map(int, input().split()) 

for i in range(K):
    a = A
    b = B
    c = C

    A = b + c
    B = a + c
    C = a + b

ans = A - B

if ans >= 10**8:
    ans = 'Unfair'
elif ans >*10**8:
    ans = 'Unfair'

print(ans)
'''



A, B, C, K= map(int, input().split())

if K%2==1: 
    ans = B - A
else:
    ans = A - B

if ans >= 10**18 or (-1)*ans >= 10**18:
    ans = 'Unfair'

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

while 1:
 n=int(input())
 if n==0:break
 a=[int(input())for _ in[0]*n]
 print(max(sum(a[i:j+1])for i in range(n)for j in range(i,n)))


### FIXED CODE ###

while 1:
 n=int(input())
 if n==0:break
 a=[int(input())for _ in[0]*n]
 for i in range(1,n):a[i]=max(a[i],a[i]+a[i-1])
 print(max(a))
### BUGGY CODE ###

from collections import deque

def main():
    Y, X = map(int,input().split())
    # sy, sx = map(int, input().split())
    # gy, gx = map(int, input().split())
    sy,sx = 1,1
    gy,gx = Y,X
    s = [["#"]*(X+2) for _ in range(Y+2)]
    for y in range(Y):
        s[y+1] = list("#"+input()+"#")
    inf = Y*X
    c = [[inf]*X for _ in range(Y)]
    c[sy-1][sx-1] = 0
    drs = [[-1,0],[1,0],[0,0],[0,-1],[0,1]]
    q = deque([(sy-1, sx-1)])

    while q:
        y,x = q.popleft()
        cost = c[y][x]
        for dx,dy in drs:
            x2 = x+dx
            y2 = y+dy
            if s[y2+1][x2+1] == "." and c[y2][x2] > cost:
                c[y2][x2] = cost+1
                q.appendleft((y2,x2))
    if c[gy-1][gx-1] == inf:
        print("-1")
    else:
        dots = 0
        for s1 in s:
            dots +=s1.count(".")
        print(dots-c[gy-1][gx-1]-1)
        
if __name__ == '__main__':
    main()

### FIXED CODE ###

H, W = map(int,input().split())
c = [["#"]*(W+2) for _ in range(H+2)]
dots = 0
for y in range(H):
    c[y+1] = "#",*list(input()),"#" 
    dots += c[y+1].count(".")
inf = H*W
m = [[inf]*W for _ in range(H)]
m[0][0] = 0
drs = [[-1,0],[1,0],[0,-1],[0,1]]

s = 0
yx = [[1, 1]]
notgoal = True
while notgoal and yx:
    yx2 = []
    s += 1
    for y,x in yx:
        for dy, dx in drs:
            x2 = x+dx
            y2 = y+dy
            if c[y2][x2] == "." and m[y2-1][x2-1] == inf:
                m[y2-1][x2-1] = s
                if (y2,x2) == (H,W):
                    notgoal = False
                else:
                    yx2.append([y2, x2])
    yx = yx2

if notgoal:
    print("-1")
else:
    print(dots-s-1)
### BUGGY CODE ###

import sys

N = int(input())
XYP = [list(map(int, input().split())) for _ in range(N)]

bits = 1 << N

xmemo = [[sys.maxsize]*N for _ in range(bits)]
ymemo = [[sys.maxsize]*N for _ in range(bits)]

for b in range(bits):
  for i in range(N):
    xmemo[b][i] = min(XYP[i][2]*abs(XYP[i][0]), xmemo[b][i])
    ymemo[b][i] = min(XYP[i][2]*abs(XYP[i][1]), ymemo[b][i])
    if not (b & (1<<i)):
      continue
    for j in range(N):
      xmemo[b][j] = min(XYP[j][2]*abs(XYP[i][0]-XYP[j][0]), xmemo[b][j])
      ymemo[b][j] = min(XYP[j][2]*abs(XYP[i][1]-XYP[j][1]), ymemo[b][j])
      
ans = [sys.maxsize]*(N+1)

for b in range(bits):
  b_ = b
  cnt = bin(b_).count('1')
  while b_ >= 0:
    b_ &= b
    yi = b - b_
    tmp = 0
    for i in range(N):
      tmp += min(xmemo[b_][i], ymemo[yi][i])
    ans[cnt] = min(ans[cnt], tmp)
    b_ -= 1
  
for i in range(N+1):
  print(ans[i])

### FIXED CODE ###

import sys

N = int(input())
XYP = [list(map(int, input().split())) for _ in range(N)]

bits = 1 << N

xmemo = [sys.maxsize]*(N*bits)
ymemo = [sys.maxsize]*(N*bits)

for b in range(bits):
  for i in range(N):
    xmemo[b*N+i] = min(XYP[i][2]*abs(XYP[i][0]), xmemo[b*N+i])
    ymemo[b*N+i] = min(XYP[i][2]*abs(XYP[i][1]), ymemo[b*N+i])
    if not (b & (1<<i)):
      continue
    for j in range(N):
      xmemo[b*N+j] = min(XYP[j][2]*abs(XYP[i][0]-XYP[j][0]), xmemo[b*N+j])
      ymemo[b*N+j] = min(XYP[j][2]*abs(XYP[i][1]-XYP[j][1]), ymemo[b*N+j])
      
ans = [sys.maxsize]*(N+1)

for b in range(bits):
  b_ = b
  cnt = bin(b_).count('1')
  while b_ >= 0:
    b_ &= b
    yi = b - b_
    tmp = 0
    for i in range(N):
      tmp += min(xmemo[b_*N+i], ymemo[yi*N+i])
    ans[cnt] = min(ans[cnt], tmp)
    b_ -= 1
  
for i in range(N+1):
  print(ans[i])
### BUGGY CODE ###

from collections import Counter

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

count_a = Counter(A)
ans_list = [None] * (N+1)
for i in range(N):
    if ans_list[A[i]] != None:
        print(ans_list[A[i]])
        continue
    ans = 0
    count_a[A[i]] -= 1
    for a in count_a.values():
        if a > 1:
            ans += int(a * (a-1) / 2)
    print(ans)
    ans_list[A[i]] = ans
    count_a[A[i]] += 1


### FIXED CODE ###

from collections import Counter

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

count_a = Counter(A)
ans_list = [0] * (N+1)
for k, v in count_a.items():
    ans_list[k] = int(v * (v-1) / 2)

all_sum = sum(ans_list)
for i in range(N):
    print(all_sum - count_a[A[i]] + 1)
### BUGGY CODE ###

import sys
input = sys.stdin.buffer.readline

R, C, K = map(int, input().split())
A = [[0]*C for _ in range(R)]
for i in range(K):
    r, c, v = map(int, input().split())
    r, c = r-1, c-1
    A[r][c] = v

dp = [[[0]*4 for i in range(C+1)] for j in range(R+1)]
for i in range(R):
    for j in range(C):
        for k  in reversed(range(3)):
            dp[i][j][k+1] = max(dp[i][j][k+1], dp[i][j][k]+A[i][j])
        for k in range(4):
            dp[i][j+1][k] = max(dp[i][j+1][k], dp[i][j][k])
            dp[i+1][j][0] = max(dp[i+1][j][0], dp[i][j][k])
#print(dp)
print(max(dp[R-1][C-1]))

### FIXED CODE ###

#import io, os
#input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

import sys
input = sys.stdin.buffer.readline

def main():
    R, C, K = map(int, input().split())
    A = [[0]*C for _ in range(R)]
    for i in range(K):
        r, c, v = map(int, input().split())
        r, c = r-1, c-1
        A[r][c] = v

    dp0 = [[0]*(C+1) for i in range(R+1)]
    dp1 = [[0]*(C+1) for i in range(R+1)]
    dp2 = [[0]*(C+1) for i in range(R+1)]
    dp3 = [[0]*(C+1) for i in range(R+1)]
    for i in range(R):
        for j in range(C):
            dp3[i][j] = max(dp3[i][j], dp2[i][j]+A[i][j])
            dp2[i][j] = max(dp2[i][j], dp1[i][j]+A[i][j])
            dp1[i][j] = max(dp1[i][j], dp0[i][j]+A[i][j])

            dp3[i][j+1] = max(dp3[i][j+1], dp3[i][j])
            dp2[i][j+1] = max(dp2[i][j+1], dp2[i][j])
            dp1[i][j+1] = max(dp1[i][j+1], dp1[i][j])
            dp0[i][j+1] = max(dp0[i][j+1], dp0[i][j])

            dp0[i+1][j] = max(dp0[i+1][j], dp0[i][j])
            dp0[i+1][j] = max(dp0[i+1][j], dp1[i][j])
            dp0[i+1][j] = max(dp0[i+1][j], dp2[i][j])
            dp0[i+1][j] = max(dp0[i+1][j], dp3[i][j])
    #print(dp)
    print(max([dp0[R-1][C-1], dp1[R-1][C-1], dp2[R-1][C-1], dp3[R-1][C-1]]))

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

n,m=map(int, input().split())
f=[[1 for _ in range(m+2)] for _ in range(n+2)]

# 1:表，0:裏
# 裏返す:-1を加える

for i in range(1,n+1):
    for j in range(1,m+1):
        for k in range(i-1,i+2):
            for l in range(j-1,j+2):
                f[k][l]-=1
                if f[k][l]==-1:
                    f[k][l]=1

cnt=0
for i in range(1,n+1):
    for j in range(1,m+1):
        if f[i][j]==0:
            cnt+=1
print(cnt)


### FIXED CODE ###

n, m = map(int, input().split())

if n == 1 and m == 1:
    print(1)
elif n == 1:
    print(m-2)
elif m == 1:
    print(n-2)
else:
    print((n-2)*(m-2))
### BUGGY CODE ###

n=int(input())
su=0
a = list(map(int, input().split())) 
da={}
for i in range(len(a)):
    if a[i] in da:
        da[a[i]]+=1
    else:
        da[a[i]]=1

key=da.keys()
for k in range(len(a)):
    da[a[k]]-=1
    for p in da.keys():
        su+=da[p]*(da[p]-1)/2
    print(int(su))
    su=0
    da[a[k]]+=1




### FIXED CODE ###

n=int(input())
su=0
a = list(map(int, input().split())) 
da={}
for i in range(len(a)):
    if a[i] in da:
        da[a[i]]+=1
    else:
        da[a[i]]=1
 
for p in da.keys():
    su+=da[p]*(da[p]-1)/2

for k in range(len(a)):
    sut=su-(da[a[k]]-1)
    print(int(sut))
### BUGGY CODE ###

import sys
input = sys.stdin.readline

n = int(input())
A = list(map(int, input().split()))
a = sorted(list(set(A)),reverse = True)
B = []
for i in a:
    if A.count(i) >= 2:
        B.append(i)
if len(B) <= 1:
    print(0)
else:
    if A.count(B[0]) >= 4:
        print(B[0]*B[0])
    else:
        print(B[0]*B[1])

### FIXED CODE ###

import sys
input = sys.stdin.readline
import collections

n = int(input())
A = list(map(int, input().split()))
c = collections.Counter(A)
l = c.most_common()
L = [ l[i] for i in range(len(l)) if l[i][1] >= 2 ]
b = sorted(L,reverse = True)
if len(b) == 0:
    ans = 0
elif len(b) == 1 and b[0][1] < 4:
    ans = 0
else:
    if b[0][1] >= 4:
        ans = b[0][0]**2
    else:
        ans = b[0][0]*b[1][0]
print(ans)
### BUGGY CODE ###

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

N_LR = [[0 for i in range(N+1)] for j in range(N+1)]

for i in range(M):
  l, r = map(int, input().split() )
  N_LR[l][r] += 1

S_LR = [[0 for i in range(N+1)] for j in range(N+1)]
for i in range(1,N+1):
  for j in range(1,N+1):
    S_LR[i][j] = S_LR[i-1][j] + N_LR[i][j]

for i in range(Q):
  x,y = map(int, input().split() )
  ans = 0
  for j in range(x, y+1):
    ans += S_LR[y][j] - S_LR[x-1][j]  
  print(ans)

### FIXED CODE ###

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

N_LR = [[0 for i in range(N+1)] for j in range(N+1)]

for i in range(M):
  l, r = map(int, input().split() )
  N_LR[l][r] += 1

#S_LR = [[0 for i in range(N+1)] for j in range(N+1)]
for i in range(1,N+1):
  for j in range(1,N+1):
    N_LR[i][j] += N_LR[i-1][j] + N_LR[i][j-1] - N_LR[i-1][j-1]

for i in range(Q):
  x,y = map(int, input().split() )
  ans = N_LR[y][y] - N_LR[x-1][y] - N_LR[y][x-1] + N_LR[x-1][x-1]
  print(ans)
### BUGGY CODE ###

N = int(input())
S = list(input() for _ in range(N))
S.sort()

n, c, l = 0, [], []

for s in S:
  if not s in c:
    c.append(s)
    l.append(1)
  else: l[-1] += 1
  n = max(n, l[-1])

S = list(set(S))
S.sort()

for i in range(len(l)):
  if l[i] == n: print(S[i])

### FIXED CODE ###

from collections import Counter as c
N = int(input())
S = list(input() for _ in range(N))
S.sort()
C, i = c(S).most_common(), 0
l, n = len(C), C[0][1]
while i < l:
  if n == C[i][1]: print(C[i][0])
  else: break
  i += 1
### BUGGY CODE ###

def solve(k,ax,bx,cx):
    ab = []
    for a in ax:
        for b in bx:
            ab.append(a+b)

    ab.sort(reverse=True)
    abk = ab[:k]

    ans = []
    for c in cx:
        for abi in abk:
            ans.append(c+abi)

    return sorted(ans, reverse=True)

if __name__ == '__main__':
    _,_,_,k = map(int, input().split())
    ax = list(map(int,input().split()))
    bx = list(map(int,input().split()))
    cx = list(map(int,input().split()))
    ans = solve(k,ax,bx,cx)
    for a in ans[:k]:
        print(a)


### FIXED CODE ###

import sys


def solve(k, ax, bx, cx):
    ab = []
    for a in ax:
        for b in bx:
            ab.append(a+b)

    ab.sort(reverse=True)
    abk = ab[:k]

    ans = []
    for c in cx:
        for abi in abk:
            ans.append(c+abi)

    return sorted(ans, reverse=True)[:k]


if __name__ == '__main__':
    _, _, _, k = map(int, input().split())
    ax = sorted(list(map(int, sys.stdin.readline().split())), reverse=True)
    bx = sorted(list(map(int, sys.stdin.readline().split())), reverse=True)
    cx = sorted(list(map(int, sys.stdin.readline().split())), reverse=True)

    ans = solve(k, ax, bx, cx)

    print(*ans, sep="\n")
### BUGGY CODE ###

s = input()
q = int(input())
rev_flag = False
for _ in range(q):
    i = input()
    if i == '1':
        rev_flag = not rev_flag
    else:
        a,b,c = i.split()
        if rev_flag:
            if b == '1':
                s = s + c
            else:
                s = c + s
        else:
            if b == '1':
                s = c + s
            else:
                s = s + c
if rev_flag:
    print(''.join(list(reversed(s))))
else:
    print(s)

### FIXED CODE ###

s = input()
q = int(input())
rev_flag = False
x_lis = []
y_lis = []
for _ in range(q):
    i = input()
    if i == '1':
        rev_flag = not rev_flag
    else:
        a,b,c = i.split()
        if rev_flag:
            if b == '1':
                #s = s + c
                y_lis.append(c)
            else:
                #s = c + s
                x_lis.append(c)
        else:
            if b == '1':
                #s = c + s
                x_lis.append(c)
            else:
                #s = s + c
                y_lis.append(c)
x = ''.join(reversed(x_lis))
y = ''.join(y_lis)
if rev_flag:
    print(''.join(list(reversed(x+s+y))))
else:
    print(x+s+y)