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

import sys
sys.setrecursionlimit(1000000000)
from itertools import count
from functools import lru_cache
from collections import defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok
#

def main():
    N = ii()
    S1 = [0] * 100
    for a in mis():
        b = 1
        for i in count():
            if b > a:
                break
            if a & b:
                S1[i] += 1
            b <<= 1
    ans = 0
    b = 1
    for i in range(len(S1)):
        s1 = S1[i]
        s0 = N - s1
        ans += (s1*s0) * (b%N1097)
        ans %= N1097
        b <<= 1

    print(ans)




main()


### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000000)
from itertools import count
from functools import lru_cache
from collections import defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok
#

def main():
    N = ii()
    S1 = [0] * 100
    for a in mis():
        b = 1
        for i in count():
            if b > a:
                break
            if a & b:
                S1[i] += 1
            b <<= 1
    ans = 0
    b = 1
    for i in range(len(S1)):
        s1 = S1[i]
        s0 = N - s1
        ans += (s1*s0) * (b%N1097)
        ans %= N1097
        b <<= 1

    print(ans)




main()
### BUGGY CODE ###

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

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

    def Unite(self,x,y):
        x=self.Find_Root(x)
        y=self.Find_Root(y)

        if x==y:return
        elif self.rank[x]>self.rank[y]:
            self.root[x] +=self.root[y]
            self.root[y]=x
        else:
            self.root[y] +=self.root[x]
            self.root[x]=y
            if self.rank[x]==self.rank[y]:
                self.rank[y] +=1

    def isSameGroup(self,x,y):
        return self.Find_Root(x)==self.Find_Root(y)

    def Count(self,x):
        return -self.root[self.Find_Root(x)]

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

    def address(self):
        return[i for i,j in enumerate(self.root) if j<0]

    def group_members(self):
        return {i:len(self.members(i)) for i in self.address()}


n,m=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(m)]
UnionFind=UnionFind(n)
count=[]

for a,b in AB[::-1]:
    cnt,point=0,0
    for i in UnionFind.group_members().values():
        point +=i*(n-i-cnt)
        cnt +=i
    count.append(point)
    UnionFind.Unite(a-1,b-1)

for i in count[::-1]:
    print(i)

### FIXED CODE ###

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

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

    def Unite(self,x,y):
        x=self.Find_Root(x)
        y=self.Find_Root(y)

        if x==y:return
        elif self.rank[x]>self.rank[y]:
            self.root[x] +=self.root[y]
            self.root[y]=x
        else:
            self.root[y] +=self.root[x]
            self.root[x]=y
            if self.rank[x]==self.rank[y]:
                self.rank[y] +=1

    def isSameGroup(self,x,y):
        return self.Find_Root(x)==self.Find_Root(y)

    def Count(self,x):
        return -self.root[self.Find_Root(x)]

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

    def address(self):
        return[i for i,j in enumerate(self.root) if j<0]

    def group_members(self):
        return {i:self.members(i) for i in self.address()}

    def size(self,x):
        return -self.root[self.Find_Root(x)]

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


n,m=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(m)]
UnionFind=UnionFind(n)
N=n*(n-1)//2
count=[N]

for a,b in AB[::-1]:
    if UnionFind.same(a-1,b-1):
        count.append(count[-1])
    else:
        s,t=UnionFind.size(a-1),UnionFind.size(b-1)
        count.append(count[-1]-s*t)
    UnionFind.Unite(a-1,b-1)

for i in count[::-1][1:]:
    print(i)
### BUGGY CODE ###

K = int(input())
a = 7
ans = -1
for i in range(1,10**6+1):
  if a%K==0:
    ans = i
    break
  a = a*10+7
print(ans)

### FIXED CODE ###

K = int(input())
a = 7%K
ans = -1
for i in range(1,10**6+1):
  if a==0:
    ans = i
    break
  a = (a*10+7)%K
print(ans)
### BUGGY CODE ###

import sys
x, y = map(int, input().split())


def power_func(a, b, p):
    if b == 0:
        return 1
    if b % 2 == 0:
        d = power_func(a, b//2, p)
        return d*d % p
    if b % 2 == 1:
        return (a*power_func(a, b-1, p)) % p


def comb(n, k, p):
    from math import factorial
    if n < 0 or k < 0 or n < k:
        return 0
    if n == 0 or k == 0:
        return 1
    a = factorial(n) % p
    b = factorial(k) % p
    c = factorial(n-k) % p
    return (a*power_func(b, p-2, p)*power_func(c, p-2, p)) % p


w = (x + y) / 3
b = (- x + 2*y) // 3

if w.is_integer():
    w = int(w)
else:
    print(0)
    sys.exit()

a = min(b, w-b)
ans = comb(w, a, 10**9+7)
print(ans)


### FIXED CODE ###

import sys
x, y = map(int, input().split())

if (x + y) % 3 != 0:
    print(0)
    sys.exit()

mod = 10**9 + 7
n = (x+y) // 3
a = min(
    (2 * x - y) // 3, (2 * y - x) // 3
)


def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod


N = max(x, y)
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

for i in range(2, N + 1):
    g1.append((g1[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod//i)) % mod)
    g2.append((g2[-1] * inverse[-1]) % mod)

ans = cmb(n, a, mod)
print(ans)
### BUGGY CODE ###

from collections import deque
INF = 10**10
h, w = map(int, input().split())
ch, cw = map(int, input().split())
dh, dw = map(int, input().split())
mat = []
for _ in range(h):
    s = input()
    mat.append(s)

costs = [[INF for _ in range(w)] for _ in range(h)]
costs[ch-1][cw-1] = 0
queue = deque()
queue.append((ch-1, cw-1))
while len(queue) > 0:
    x, y = queue.popleft()
    for i in range(4):
        dx = [-1, 0, 1, 0][i]
        dy = [0, -1, 0, 1][i]
        nx = x+dx
        ny = y+dy
        if nx < 0 or h <= nx or ny < 0 or w <= ny:
            continue
        if mat[nx][ny] == "#":
            continue
        if costs[nx][ny] > costs[x][y]:
            costs[nx][ny] = costs[x][y]
            queue.appendleft((nx, ny))
    for i in range(-2, 3):
        for j in range(-2, 3):
            nx = x+i
            ny = y+j
            if nx < 0 or h <= nx or ny < 0 or w <= ny:
                continue
            if mat[nx][ny] == "#":
                continue
            if costs[nx][ny] > costs[x][y] + 1:
                costs[nx][ny] = costs[x][y] + 1
                queue.append((nx, ny))
if costs[dh-1][dw-1] == INF:
    print(-1)
else:
    print(costs[dh-1][dw-1])



### FIXED CODE ###

from collections import deque
INF = 10**10
h, w = map(int, input().split())
ch, cw = map(int, input().split())
dh, dw = map(int, input().split())
mat = []
for _ in range(h):
    s = input()
    mat.append(s)

costs = [[INF for _ in range(w)] for _ in range(h)]
costs[ch-1][cw-1] = 0
queue = deque()
queue.append((ch-1, cw-1))
while len(queue) > 0:
    x, y = queue.popleft()
    for i in range(4):
        dx = [-1, 0, 1, 0][i]
        dy = [0, -1, 0, 1][i]
        nx = x+dx
        ny = y+dy
        if nx < 0 or h <= nx or ny < 0 or w <= ny:
            continue
        if mat[nx][ny] == "#":
            continue
        if costs[nx][ny] > costs[x][y]:
            costs[nx][ny] = costs[x][y]
            queue.appendleft((nx, ny))
    for i in range(-2, 3):
        for j in range(-2, 3):
            nx = x+i
            ny = y+j
            if nx < 0 or h <= nx or ny < 0 or w <= ny:
                continue
            if mat[nx][ny] == "#":
                continue
            if costs[nx][ny] > costs[x][y] + 1:
                costs[nx][ny] = costs[x][y] + 1
                queue.append((nx, ny))
if costs[dh-1][dw-1] == INF:
    print(-1)
else:
    print(costs[dh-1][dw-1])
### BUGGY CODE ###

import fractions as math
from functools import reduce

def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

N=int(input())
A=list(map(int,input().split()))
MOD=(10**9)+7

LCM=lcm_list(A)
ans=0

for i in range(N):
    ans+=(LCM//A[i])
    ans=ans%MOD

print(ans)

### FIXED CODE ###

import fractions
from functools import reduce

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)


def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

N=int(input())
A=list(map(int,input().split()))
MOD=(10**9)+7
S=list(set(A))
LCM=lcm_list(S)
ans=0

for i in range(N):
    ans+=(LCM//A[i])


print(ans%MOD)
### BUGGY CODE ###

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

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

dp = [float('inf')]*n

dp[0] = 0
dp[1] = abs(arr[0]-arr[1])

for i in range(2, n):
    for j in range(i-1, max(-1, i-k-1), -1):
        dp[i] = min(dp[i], dp[j]+abs(arr[i]-arr[j]))

print(dp[-1])


### FIXED CODE ###

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

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

dp = [float('inf')]*n

dp[0] = 0
dp[1] = abs(arr[0]-arr[1])

for i in range(2, n):
    for j in range(i-1, max(-1, i-k-1), -1):
        dp[i] = min(dp[i], dp[j]+abs(arr[i]-arr[j]))

print(dp[-1])
### BUGGY CODE ###

n,*a=map(int,open(0).read().split())
c=0
for i in range(61):t=sum(2**i&b and 1for b in a);c+=t*(n-t)*2**i
print(c%(10**9+7))

### FIXED CODE ###

n,*a=map(int,open(0).read().split())
b=[0]*61
for c in a:
  for i in range(61):b[i]+=2**i&c>0
print(sum(2**i*c*(n-c)for i,c in enumerate(b))%(10**9+7))
### BUGGY CODE ###

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

x=1

for i in a:
  x*=i

if x>10**18:
  print("-1")
else:
  print(x)

### FIXED CODE ###

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

x=1

for i in a:
  x*=i
  if x>10**18:
    print("-1")
    exit()
print(x)
### BUGGY CODE ###

def main():
  s = input()
  mod = 10**9+7
  dp = [[0]*13 for _ in range(len(s) + 1)]
  dp[0][0] = 1
  digit = 1
  for index, i in enumerate(s[::-1], start=1):
    if i == "?":
      for k in range(10):
        for j in range(13):
          dp[index][(digit * k + j)%13] += dp[index - 1][j]
          dp[index][(digit * k + j)%13] %= mod
    else:
      for j in range(13):
        dp[index][(digit * int(i) + j)%13] += dp[index - 1][j]
        dp[index][(digit * int(i) + j)%13] %= mod
    digit *= 10
  print(dp[-1][5])

if __name__ == '__main__':
  main()

### FIXED CODE ###

def main():
  s = input()
  mod = 10**9+7
  dp = [0]*13
  dp[0] = 1
  digit = 1
  for i in range(len(s)):
    nextDP = [0]*13
    if s[i] == "?":
      for k in range(10):
        for j in range(13):
          t = (k + j * 10)%13
          nextDP[t] = (dp[j] + nextDP[t]) % mod
    else:
      si = int(s[i])
      for j in range(13):
        t = (si + j * 10)%13
        nextDP[t] = (dp[j] + nextDP[t]) % mod
    dp = nextDP
    digit *= 10
  print(dp[5])

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

s = input()
q = int(input())
flip = 1
for i in range(q):
    T = input().split()
    if T[0] == '1':
        flip *= -1
    else:
        _flip = 1 if T[1]=='1' else -1
        if (flip * _flip)==1:
            s = T[2] + s
        else:
            s = s + T[2]
print(s if flip==1 else s[::-1])

### FIXED CODE ###

from collections import deque

s = deque(input())
q = int(input())
flip = 1
for i in range(q):
    T = input().split()
    if T[0] == '1':
        flip *= -1
    else:
        _flip = 1 if T[1]=='1' else -1
        if (flip * _flip)==1:
            s.appendleft(T[2])
        else:
            s.append(T[2])
print("".join(s) if flip==1 else "".join(reversed(s)))
### BUGGY CODE ###

#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  n, p = map(int, input().strip().split())
  s = input().strip()
  ans = 0
  if 10 % p == 0:
    for r in range(n):
      if int(s[r]) % p == 0:
        ans += r+1
    print(ans)
    return
  
  remains = [0] * (n+1)
  counts = [0] * p
  counts[0] += 1
  x = 1
  for r in range(n-1, -1, -1):
    remain = (int(s[r]) * x) % p
    remains[r] = (remains[r+1] + remain) % p
    counts[remains[r]] += 1
    x = (x * 10)
  for count in counts:
    ans += (count * (count - 1)) // 2
  print(ans)

if __name__=='__main__':
  main()



### FIXED CODE ###

#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  n, p = map(int, input().strip().split())
  s = input().strip()
  ans = 0
  if 10 % p == 0:
    for r in range(n):
      if int(s[r]) % p == 0:
        ans += r+1
    print(ans)
    return
  
  remains = [0] * (n+1)
  counts = [0] * p
  counts[0] += 1
  x = 1
  for r in range(n):
    remain = (int(s[-(r+1)]) * x) % p
    remains[-(r+1)] = (remains[-r] + remain) % p
    counts[remains[-(r+1)]] += 1
    x = (x * 10) % p
  for count in counts:
    ans += (count * (count - 1)) // 2
  print(ans)

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

N = int(input())
nu = [int(x) for x in input().split()]
r2 = [None] * N

for i in range(len(nu)):
  r2[nu[i] - 1] = i
#for i in nu:
#  r2[i] = nu.index(i)
ans = ""
for i in range(len(r2)):
  ans = ans + str(r2[i] + 1) + " "
print(ans)
#print(" ".join([str(x + 1) for x in r2]))

### FIXED CODE ###

from sys import stdin
import numpy as np


# noinspection PyShadowingBuiltinsInspection

def main():
    n = int(input())
    students = [int(x) for x in input().split()]
    ret = [0] * n
    for i in range(n):
        ret[students[i] - 1] = i + 1
    print(" ".join([str(x) for x in ret]))
    return


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

from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
from functools import reduce
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7
def lcm_base(a, b):
    return (a * b) // gcd(a, b)
 
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
 
 
def main():
  k = int(input())
  ans = 0
  for a in range(1, k+1):
    for b in range(a, k+1):
      for c in range(b,k+1):
        if a==b and b==c:
          ans += a
        elif a==b or b==c:
          ans += gcd(gcd(a,b),c) * 3
        else:
          ans += gcd(gcd(a,b),c) * 6
  print(ans)
  
  
if __name__ == '__main__':
  main()

### FIXED CODE ###

from fractions import gcd
 
def main():
  k = int(input())
  ans = 0
  for a in range(1, k+1):
    for b in range(a, k+1):
      x = gcd(a,b)
      for c in range(b,k+1):
        if a==b and b==c:
          ans += a
        elif a==b or b==c:
          ans += gcd(x,c) * 3
        else:
          ans += gcd(x,c) * 6
  print(ans)
  
  
if __name__ == '__main__':
  main()
### BUGGY CODE ###

def set_values():
	values = []
	for i in range(int(input())):
		values.append(int(input()))
	return values

def check_all(values):
	max_value = min(values) - max(values)
	for i in range(len(values)-1):
		count = i + 1
		max_value = get_max_value(i, len(values), count, max_value)
	return max_value

def get_max_value(now_index, length, count, max_value):

	while count < length:
		if max_value < (values[count] - values[now_index]):
			max_value = (values[count] - values[now_index])
		count += 1
	return max_value

values = set_values()
max_value = check_all(values)
print(max_value)


### FIXED CODE ###

def set_values():
	values = []
	for i in range(num):
		values.append(int(input()))
	return values

num = int(input())
values = set_values()
max_value = values[1] - values[0]
min_value = values[0]

for i in range(1, num):
	max_value = max(max_value, (values[i] - min_value))
	min_value = min(min_value, values[i])

print(max_value)
### BUGGY CODE ###

import sys
input=sys.stdin.readline
n=int(input())

def bin(start):
    ok=0
    ng=n
    while abs(ng-ok)>1:
        mid=(ok+ng)//2
        print(mid)
        sys.stdout.flush()
        s=input()
        if s=='Vacant':exit()
        if mid%2==0 and start==s:
            ok=mid
        elif mid%2!=0 and start!=s:
            ok=mid
        else:
            ng=mid
print(0)
start=input()
sys.stdout.flush()
if start=='Vacant':exit()
bin(start)


### FIXED CODE ###

import sys
input=sys.stdin.readline
n=int(input())

def bin(start):
    ok=0
    ng=n
    while abs(ng-ok)>1:
        mid=(ok+ng)//2
        print(mid)
        sys.stdout.flush()
        s=input()
        if s=='Vacant':exit()
        if mid%2==0 and start==s:
            ok=mid
        elif mid%2!=0 and start!=s:
            ok=mid
        else:
            ng=mid
print(0)
sys.stdout.flush()
start=input()
if start=='Vacant':exit()
bin(start)
### BUGGY CODE ###

#coding: utf-8
m,n = map(int,input().split())
# div = [0]
div = [1]
flg = 0

if m % 2 == 0 and n % 2 == 0:
    div.append(2)

# while i < m:
#     if m % i == 0 and n % i == 0 and i % 2 == 1:
for i in range(3,m,2):
    if m % i == 0 and n % i == 0 and i % 2 == 1:
        # ans += 1
        # m = m / i
        # n = n / i
        for j in range(2,len(div)):
            if i % div[j] == 0:
                flg = 1
                break
        if flg == 0:
            div.append(i)
        else:
            flg = 1
    

    # print(student[i]-1)
    # toukou[student[i]-1] = i+1
# print(" ".join(map(str,div)))
print(len(div))


### FIXED CODE ###

#coding: utf-8
from fractions import gcd
import math

# GCDの約数を素因数分解する
def primeFactor(n):
    flg = 0
    count = 0
    tmp = math.sqrt(n)
    i = 2

    if n == 1:
        return 1

    while i <= tmp:
        # print(str(i)+str(',')+str(gcd_cnt))
        if n % i == 0:
            if flg == 0:
                flg = 1
                count += 1
            n = n // i
        else:
            flg = 0
            i += 1
    # if flg == 1:
    #     count += 1
    # print(str('素数=')+str(count)+str(' n=')+str(n)+str(' i=')+str(i))
    if n > 1:
        count += 1
    # 1を足す
    count += 1
    return count


# # print(len(div))
m,n = map(int,input().split())
p = gcd(m,n)
# print(str('gcd=')+ str(p))
ans = primeFactor(p)
print(ans)
### BUGGY CODE ###

from collections import defaultdict, deque

n, m = [int(i) for i in raw_input().split()]

children = defaultdict(list)
parents = defaultdict(list)

for _ in range(m):
    u, v = [int(i) for i in raw_input().split()]
    children[u-1].append(v-1)
    parents[v-1].append(u-1)

# def longest_path(children, parents, n):
#     f = [None] * n
#     targets = [x for y in children.values() for x in y]
#     starts = [v for v in range(n) if v not in targets]

#     for v in starts:
#         f[v] = 0

#     # print f
#     for i in range(n):
#         get_f(children, parents, f, i)

#     # print f
#     return max(f)

def get_f(children, parents, f, i):
    if f[i] != None:
        return f[i]

    for v in parents[i]:
        f[i] = max(f[i], get_f(children, parents, f, v) + 1)

    return f[i]

def longest_path(children, parents, n):
    targets = [x for y in children.values() for x in y]
    starts = [v for v in range(n) if v not in targets]
    f = [None] * n
    

    Q = deque([])
    for v in starts:
        f[v] = 0
        Q.append((v, 0))

    output = 0
    while len(Q) > 0:
        node, length = Q.popleft()
        output = max(output, length)
        for v in children[node]:
            Q.append((v, length+1))

    return output

print(longest_path(children, parents, n))

### FIXED CODE ###

from collections import defaultdict
import sys
sys.setrecursionlimit(1000000)

n, m = [int(i) for i in raw_input().split()]
parents = defaultdict(list)

i = 0
while i < m:
    u, v = [int(x) for x in raw_input().split()]
    parents[v-1].append(u-1)
    i += 1

def calc_f(parents, f, i):
    if i < 0 or i >= len(f):
        return 0

    if f[i] != -1:
        return f[i]

    f[i] = 0
    for v in parents[i]:
        f[i] = max(f[i], calc_f(parents, f, v)+1)

    return f[i]

f = [-1] * n
j = 0
while j < n:
    calc_f(parents, f, j)
    j += 1

if len(f) == 0:
    print 0
else:
    print max(f)
### BUGGY CODE ###

class Trie:
    class Node:
        def __init__(self,c):
            self.c=c
            self.next_c_id={}
            #self.common=0
            self.end=-1

    def __init__(self):
        self.trie=[self.Node('')]
    
    def add(self,id,s):
        i=0
        now=0
        ary=[0]
        while i<len(s) and s[i] in self.trie[now].next_c_id:
            now=self.trie[now].next_c_id[s[i]]
            ary.append(now)
            #self.trie[now].common+=1
            i+=1
        while i<len(s):
            self.trie[now].next_c_id[s[i]]=len(self.trie)
            now=len(self.trie)
            ary.append(now)
            self.trie.append(self.Node(s[i]))
            #self.trie[now].common+=1
            i+=1
        self.trie[now].end=id
        return ary

def main(s):
    tr=Trie()
    s.sort(key=lambda x:len(x))
    ans=0
    for i,x in enumerate(s):
        ary=tr.add(i,x)
        seen=set(())
        while ary:
            id=ary.pop()
            for nv in seen&tr.trie[id].next_c_id.keys():
                if tr.trie[tr.trie[id].next_c_id[nv]].end>=0 and tr.trie[tr.trie[id].next_c_id[nv]].end!=i:
                    ans+=1
            seen.add(tr.trie[id].c)
    print(ans)

if __name__=='__main__':
    a2n=lambda x:ord(x)-ord('a')
    n=int(input())
    s=[list(map(a2n,list(input()))) for _ in range(n)]
    [x.reverse() for x in s]
    main(s)


### FIXED CODE ###

class Trie:
    class Node:
        def __init__(self,c):
            self.c=c
            self.next_c_id={}
            #self.common=0
            self.end=-1

    def __init__(self):
        self.trie=[self.Node('')]
    
    def add(self,id,s):
        i=0
        now=0
        ary=[0]
        while i<len(s) and s[i] in self.trie[now].next_c_id:
            now=self.trie[now].next_c_id[s[i]]
            ary.append(now)
            #self.trie[now].common+=1
            i+=1
        while i<len(s):
            self.trie[now].next_c_id[s[i]]=len(self.trie)
            now=len(self.trie)
            ary.append(now)
            self.trie.append(self.Node(s[i]))
            #self.trie[now].common+=1
            i+=1
        self.trie[now].end=id
        return ary

def main(s):
    tr=Trie()
    s.sort(key=lambda x:len(x))
    ans=0
    for i,x in enumerate(s):
        ary=tr.add(i,x)
        seen=set(())
        while ary:
            id=ary.pop()
            for nv in seen&tr.trie[id].next_c_id.keys():
                if tr.trie[tr.trie[id].next_c_id[nv]].end>=0 and tr.trie[tr.trie[id].next_c_id[nv]].end!=i:
                    ans+=1
            seen.add(tr.trie[id].c)
    print(ans)

if __name__=='__main__':
    a2n=lambda x:ord(x)-ord('a')
    n=int(input())
    s=[list(map(a2n,list(input()))) for _ in range(n)]
    [x.reverse() for x in s]
    main(s)
### BUGGY CODE ###

N = int(input())

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

numbers_minus1 = numbers_full
for i, tmp in enumerate(numbers_full):
  numbers_minus1[i] = 0
  print(str(max(numbers_minus1)))
  numbers_minus1[i] = tmp

### FIXED CODE ###

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

sorted_num = sorted(number_list)
number_max = sorted_num[-1]
number_second_max = sorted_num[-2]

if number_max == number_second_max:
  output_always_max = True
else:
  output_always_max = False

for number in number_list:
  if output_always_max:
    print(str(number_max))
  else:
    if number == number_max:
      print(str(number_second_max))
    else:
      print(str(number_max))