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

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

dp=[[0]*(k+1) for i in range(n+1)]

for i in range(n+1):
    dp[i][0]=1



for i in range(1,n+1):
    for j in range(1,k+1):
        if j-1-a[i-1]>=0:
            dp[i][j]=dp[i][j-1]+dp[i-1][j]-dp[i-1][j-1-a[i-1]]
        
        else:
            dp[i][j]=dp[i][j-1]+dp[i-1][j]           

print(dp[-1][-1]%(10**9+7))
    
    

### FIXED CODE ###

import sys
input = sys.stdin.readline

n,k=map(int, input().split()) 
a=list(map(int, input().split()))
mod=10**9+7
dp=[[0]*(k+1) for i in range(n+1)]

for i in range(n+1):
    dp[i][0]=1



for i in range(1,n+1):
    for j in range(1,k+1):
        if j-1-a[i-1]>=0:
            dp[i][j]=(dp[i][j-1]+dp[i-1][j]-dp[i-1][j-1-a[i-1]])%mod
        
        else:
            dp[i][j]=(dp[i][j-1]+dp[i-1][j])%mod

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

n = int(input())
a = list(map(int, input().split()))
res = 0
for i in range(n):
  k = 1
  if (i + a[i]) < n:
    k= a[i]
    for j in range(i+k,n):
      d = j-i
      h = a[i] + a[j]
      if d == h :
        res += 1
print(res)


### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
res = 0
ia = []
ja = []
dia={}
dja={}
for i in range(n):
  dia[i+a[i]] = dia.get(i+a[i],0)+1
  dja[i-a[i]] = dja.get(i-a[i],0)+1
ans = 0
for di,nmi in dia.items():
  nmj = dja.get(di,0)
  ans += nmi*nmj

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

def encode(s):
#  r = [0]*26
#  for n in range(len(s)):
#    r[ord(s[n]) - ord('a')] += 1
#  return r
  r = list(s)
  r.sort()
  return r

N = int(input())

S = []

for n in range(N):
  s = str(input())
  S = S + [encode(s)]

S.sort()

ct = 0
M=1
ps=""
for cs in S:
  if cs==ps:
    M+=1
  else:
    ct += int((M**2-M)/2)
    M=1
    ps=cs
ct += int((M**2-M)/2)

print(ct)
      
  

### FIXED CODE ###

def encode(s):
#  r = [0]*26
#  for n in range(len(s)):
#    r[ord(s[n]) - ord('a')] += 1
#  return r
#  r = list(s)
#  r.sort()
#  return r
  r = 0
  for n in range(len(s)):
    so = ord(s[n]) - ord('a')
    r += 11**so
  return r

N = int(input())

S = [0]*N

for n in range(N):
  s = str(input())
  S[n] = encode(s)

S.sort()

ct = 0
M=1
ps=""
for cs in S:
  if cs==ps:
    M+=1
  else:
    ct += int((M**2-M)/2)
    M=1
    ps=cs
ct += int((M**2-M)/2)

print(ct)
### BUGGY CODE ###

import sys

string = ""
while 1:
  try:
    for s in sys.stdin:
      string += s[:-1]
  except:
    break
char = list('abcdefghijklmnopqrstuvwxyz')

for s in char:
  print s + " : " + str(string.count(s))

### FIXED CODE ###

import sys

string = ""
while True:
  try:
    string += raw_input().lower()
  except:
    break
char = list('abcdefghijklmnopqrstuvwxyz')

for s in char:
  print s + " : " + str(string.count(s))
### BUGGY CODE ###

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

for _ in range(m):
    a, b = map(int, input().split())
    ab[a].append(b)
    ab[b].append(a)

if any((i in ab[n]) for i in ab[1]):
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

### FIXED CODE ###

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

for _ in range(m):
    a, b = map(int, input().split())
    if a==1:
        ab[b] += 1
        continue
    elif b == n:
        ab[a] += 1
        continue
if max(ab) == 2:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
### BUGGY CODE ###

import math
N = int(input())
n = int(math.sqrt(N))
if N/n == n:
    print(int(math.log10(n)+1))
else:
    while N%n != 0:
        n+=1
    print(int(math.log10(n) + 1))


### FIXED CODE ###

import math

N = int(input())
n = int(math.sqrt(N)) + 1
if N / n == n:
    print(int(math.log10(n) + 1))
else:
    while N % n != 0:
        n -= 1
    print(int(math.log10(N/n) + 1))
### BUGGY CODE ###

import math
#N = int(input())
N, M =  map(int,input().split())
#W =list(map(int,input().split()))
a = [(int(input())) for i in range(M)]


from operator import mul
from functools import reduce

def comb(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

def stair_count(start,end):
    #print(start,end)
    aida = end - start
    total = 0
    i = aida
    #print("aida/2={}".format(aida/2))
    kazu = 0
    while i >= kazu:
        total += comb(i,kazu)
        kazu += 1
        i -= 1
    return total

start = 0
answer = 1
for i in a:
    #print("i={}".format(i))
        if i == start:
            print(0)
            exit()
        else:
            answer = (answer * stair_count(start, i-1))
            start = i+1
answer = (answer * stair_count(start, N))
    #print("answer={}".format(answer))
print(answer%1000000007)



### FIXED CODE ###

#N = int(input())
N, M =  map(int,input().split())
#W =list(map(int,input().split()))
a = [(int(input())) for i in range(M)]

import sys

sys.setrecursionlimit(100000)
memo  =[-1]*(N+2)
def stair_count(n):
    if memo[n]!= -1:
        return memo[n]
    if n==0 or n==1:
        memo[n] =1
        return memo[n]
    memo[n] = stair_count(n-1) + stair_count(n-2)
    return memo[n]

start = 0
answer = 1
for i in a:
        if i == start:
            print(0)
            exit()
        else:
            n = i-1-start
            answer = (answer * stair_count(n))
            start = i+1
n = N -start
answer = (answer * stair_count(n))
print(answer%1000000007)
### BUGGY CODE ###

import itertools
import math

k = int(input())

l = list(itertools.product(list(range(1, k+1)), repeat=3))
ans = 0

for i in l:
    a, b, c = i
    ans += math.gcd(math.gcd(a, b), c)

print(ans)


### FIXED CODE ###

import itertools
import math

k = int(input())

l = list(itertools.combinations_with_replacement(list(range(1, k+1)), 3))
ans = 0

for i in l:
    a, b, c = i
    if a == b == c:
        ans += math.gcd(math.gcd(a, b), c)
    elif (a == b) or (b == c):
        ans += 3 * (math.gcd(math.gcd(a, b), c))
    else:
        ans += 6 * (math.gcd(math.gcd(a, b), c))

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

N, Q = map(int, input().split())
G = [set() for _ in range(N+1)]
for i in range(N-1):
    a, b = map(int, input().split())
    G[a].add(b)
    G[b].add(a)

g2 = [set() for _ in range(N+1)]
p = [0]*(N+1)
vs = set()
stack = [1]
dfs_vs = []
vs.add(1)
while stack:
    v = stack.pop()
    dfs_vs.append(v)
    for u in G[v]:
        if u in vs:
            continue
        g2[v].add(u)
        p[u] = v
        stack.append(u)
        vs.add(u)

d = [0]*(N+1)
for i in range(Q):
    z, x = map(int, input().split())
    d[z] += x

#print(d)
#print(p)

for v in dfs_vs:
    d[v] += d[p[v]]

print(*d[1:])


### FIXED CODE ###

import sys
sys.setrecursionlimit(300000)
input = sys.stdin.readline
n,q=map(int,input().strip().split())
d=[[] for _ in range(n)]

for _ in range(n-1):
    a,b=map(int,input().split())
    d[a-1].append(b-1)
    d[b-1].append(a-1)
l=[0]*n
for _ in range(q):
    a,b=map(int,input().split())
    l[a-1]+=b
rs=[0]*n

def rr(pa,s,dd,d):
    for c in d[s]:
        if c == pa:
            continue
        rs[c]=l[c]+dd
#        print(c,rs[c],dd)
        rr(s,c,dd+l[c],d)

s,dd=0,l[0]
rs[0] = l[0]
rr(None,s,dd,d)
for r in rs:
    print(r)
### BUGGY CODE ###

from collections import deque
import sys
sys.setrecursionlimit(10**5+200)

def Connected_Component(A,N):
    T={i:False for i in range(1,N+1)}
    V=set([i for i in range(1,N+1)])
    C=[]
    p=0
    while p<N:
        v=V.pop()
        S=deque([v])
        T[v]=True
        q=1
        D=[]
        while S:
            w=S.pop()
            D.append(w)
            for u in [u for u in A[w] if not T[u]]:
                q+=1
                T[u]=True
                S.append(u)

        p+=q
        E=set(D)
        C.append(E)
        V-=E
    return C
    
N,M,K=map(int,input().split())
A={i:set() for i in range(1,N+1)}
for _ in range(M):
    a,b=map(int,input().split())
    A[a].add(b)
    A[b].add(a)

C={i:set() for i in range(1,N+1)}
for _ in range(K):
    c,d=map(int,input().split())
    C[c].add(d)
    C[d].add(c)

E=Connected_Component(A,N)
F=["*"]+[0]*(N)
for i in range(len(E)):
    for x in E[i]:
        F[x]=i

for i in range(1,N+1):
    c=F[i]
    print(len(E[c]-(A[i]|C[i]|{i})),end="")
    if i!=N:
        print(" ",end="")
print()


### FIXED CODE ###

class Union_Find():
    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,K=map(int,input().split())

A=[set() for _ in range(N+1)]
U=Union_Find(N+1)
for _ in range(M):
    a,b=map(int,input().split())
    A[a].add(b)
    A[b].add(a)
    U.union(a,b)

C=[set() for _ in range(N+1)]
for _ in range(K):
    c,d=map(int,input().split())
    C[c].add(d)
    C[d].add(c)

S=[]
for k in range(1,N+1):
    t=U.size(k)
    for a in C[k]:
        if U.find(a)==U.find(k):
            t-=1

    t-=len(A[k])
    S.append(t-1)

print(" ".join(map(str,S)))
### BUGGY CODE ###

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

num = 0
j = 0

for i in range(N):
  for j in range(i+1, N):
    a = s[i] * s[j]
    num += a

b = num % (10**9 + 7)    
print(b)

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
mod = 10**9 + 7

sum = 0
f = 0

for i in range(n-1):
    f = f + a[i]
    sum += f * a[i+1]
 
print(sum % mod)
### BUGGY CODE ###

n, k = map(int, input().split())
A = list(map(int, input().split()))
m=0
for i in range(0,n-k+1):
    s=0
    for j in range(i,i+k):
        s=s+(A[j]*(A[j]+1)/2)*1/A[j]
    if s>m:
        m=s
print(m)

### FIXED CODE ###

n,k = map(int, input().split())
A = list(map(int, input().split()))
s=[0]*(n+1)
for i in range(1,n+1):
    s[i]=s[i-1]+A[i-1]
s1=[0]*(n-k+1)
for i in range(0,n-k+1):
    s1[i]=s[k+i]-s[i]
print((max(s1)+k)/2)
### BUGGY CODE ###

n, m = map(int, input().split())
ab, c, d = [], [], []
for i in range(m):
    ab.append(list(map(int, input().split())))
for i in range(m):
    if(ab[i][0] == n):
        c.append(ab[i][1])
    elif(ab[i][1] == n):
        c.append(ab[i][0])
    elif(ab[i][0] == 1):
        d.append(ab[i][1])
    elif(ab[i][1] == 1):
        d.append(ab[i][0])
for i in c:
    if(i in d):
        print('POSSIBLE')
        exit()
print('IMPOSSIBLE')


### FIXED CODE ###

n, m = map(int, input().split())
ab, c, d = [], set(), set()
for i in range(m):
    ab.append(list(map(int, input().split())))
for i in range(m):
    if(ab[i][0] == n):
        c.add(ab[i][1])
    elif(ab[i][1] == n):
        c.add(ab[i][0])
    elif(ab[i][0] == 1):
        d.add(ab[i][1])
    elif(ab[i][1] == 1):
        d.add(ab[i][0])
if(c & d):
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')
### BUGGY CODE ###

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

ans = 1

p = 10 ** 18

flg = False
flg_2 = False

for a in A_list:
    ans *= a

if ans > p:
    ans = -1


print(ans)



### FIXED CODE ###

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

ans = 1

p = 10 ** 18

for a in A_list:
    ans *= a
    if ans > p:
        ans = -1
        break

if 0 in A_list:
    print(0)
else:
    print(ans)
### BUGGY CODE ###

from sys import stdin

N, Q = [int(x) for x in stdin.readline().rstrip().split()]
S = stdin.readline().rstrip()
lr_list = [list(map(int, stdin.readline().rstrip().split())) for _ in range(Q)]

for l, r in lr_list:
    S2 = S[l-1:r]
    #print(S2)
    S3 = S2.replace("AC", "")
    print( (len(S2) - len(S3)) // 2 )

### FIXED CODE ###

from sys import stdin
from collections import deque

N, Q = [int(x) for x in stdin.readline().rstrip().split()]
S = stdin.readline().rstrip()
lr_list = [list(map(int, stdin.readline().rstrip().split())) for _ in range(Q)]

#result_list = []
count = 0

result_list = deque([])

for i in range(N):
    result_list.append(count)
    if S[i] != "A":
        continue
    try:
        if S[i+1] == "C":
            count += 1
    except:
       pass

for l, r in lr_list:
    print(result_list[r-1] - result_list[l-1])
### BUGGY CODE ###

import sys
import bisect
import itertools
import collections
import fractions
import heapq
import math
from operator import mul
from functools import reduce
from functools import lru_cache


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    N = int(readline())
    A = list(map(int, readline().split()))




    n = 10 ** 6
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n ** 0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    prime_list = [i for i in range(n + 1) if is_prime[i]]




    lcm_dic = {}
    Alist = []

    for a in A:
        a_dic = {}
        for num in prime_list:
            if num > a ** 0.5 + 1:
                if a in a_dic:
                    a_dic[a] += 1
                    break
                else:
                    a_dic[a] = 1
                    break
            while a % num == 0:
                if num in a_dic:
                    a //= num
                    a_dic[num] += 1
                else:
                    a //= num
                    a_dic[num] = 1
        Alist.append(a_dic)
        for k, v in a_dic.items():
            if k not in lcm_dic:
                lcm_dic[k] = v
            else:
                lcm_dic[k] = max(lcm_dic[k], v)

    ans = 0
    for ad in Alist:
        tmpnum = 1
        for k, v in lcm_dic.items():
            if k in ad:
                tmpnum *= pow(k, (v - ad[k]), mod)
                tmpnum %= mod
            else:
                tmpnum *= pow(k, v, mod)
                tmpnum %= mod
        ans += tmpnum
        ans %= mod
    print(ans)




if __name__ == '__main__':
    solve()

### FIXED CODE ###

import sys
import bisect
import itertools
import collections
import fractions
import heapq
import math
from operator import mul
from functools import reduce
from functools import lru_cache


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    N = int(readline())
    A = list(map(int, readline().split()))

    lcmnum = 1
    def gcd(a, b):
        if (a == 0):
            return b
        return gcd(b%a, a)

    def lcm(x, y):
        return (x * y) // gcd(x, y)
    for a in A:
        lcmnum = lcm(lcmnum, a)

    ans = 0
    for a in A:
        a = lcmnum // a
        ans += a
    ans %= mod

    print(ans)




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

import heapq
N, M = map(int, input().split())
A = list(map(int, input().split()))
q = []
for i in A:
    heapq.heappush(q, i)
for i in range(M):
    b, c = map(int, input().split())
    for j in range(b):
        v = heapq.heappop(q)
        if v >= c:
            heapq.heappush(q, v)
        else:
            heapq.heappush(q, c)
print(sum(q))

### FIXED CODE ###

import heapq
q = []
N, M = map(int, input().split())
A = (map(int, input().split()))
for a in A:
    heapq.heappush(q, a)

lst = []   
for i in range(M):
    lst.append(list(map(int, input().split())))
lst = sorted(lst, key = lambda x: -x[1])
for i, j in lst:
    for _ in range(i):
        v = heapq.heappop(q)
        if v < j:
            heapq.heappush(q, j)
        else:
            heapq.heappush(q, v)
            break
print(sum(q))
### 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 make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return len(divisors)

def main():
    n = int(input())
    ans = 0
    for i in range(1,n+1):
        l = make_divisors(i)
        ans += l * i

    print(ans)
    
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():
    n = int(input())
    ans = 0
    for i in range(1,n+1):
        num = n // i
        ans += i*num*(num+1)//2
    

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

import sys
n, k = map(int, sys.stdin.readline().split())
s = [int(string) for string in input()]

tmp = []
flag = s[0]
cnt = 1

if s[0] == 0:
    tmp.append(0)
for i in range(1, n):
    if flag == s[i]:
        cnt += 1
    else:
        tmp.append(cnt)
        cnt = 1
        flag = 1 - flag
tmp.append(cnt)
if s[-1] == 0:
    tmp.append(0)

ans = 0
for i in range(0, n, 2):
    ans_tmp = 0
    for j in range(2*k+1):
        if len(tmp) <= i+j:
            break
        ans_tmp += tmp[i+j]
    ans = max(ans, ans_tmp)

print(ans)

### FIXED CODE ###

import sys
import itertools
n, k = map(int, sys.stdin.readline().split())
s = [int(string) for string in input()]

tmp = []
flag = s[0]
cnt = 1

if s[0] == 0:
    tmp.append(0)
for i in range(1, n):
    if flag == s[i]:
        cnt += 1
    else:
        tmp.append(cnt)
        cnt = 1
        flag = 1 - flag
tmp.append(cnt)
if s[-1] == 0:
    tmp.append(0)

ruisekiwa = list(itertools.accumulate(tmp))
ans = 0
ruisekiwa.insert(0, 0)
for left in range(0, len(ruisekiwa), 2):
    right = left + 2*k+1
    if len(ruisekiwa) <= right:
        right = len(ruisekiwa)-1
    ans = max(ans, ruisekiwa[right] - ruisekiwa[left])

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

import sys
from collections import deque
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
MAX = 10**5+5
INF = 10**9
P = 1000000007

def resolve():
    s = input().strip()
    dp = [[0]*13 for _ in range(MAX)]
    dp[0][0]=1
    for i,x in enumerate(s):
        c=ord(x)-48
        for j in range(10):
            if(x!='?' and c!=j):
                continue
            for k in range(13):
                t=(k*10+j)%13
                dp[i+1][t] = dp[i+1][t]+dp[i][k]
        for j in range(10):
            dp[i+1][j]=dp[i+1][j]%P
    l=len(s)
    print(dp[l][5])


if __name__ == "__main__":
    resolve()

### FIXED CODE ###

import sys
from collections import deque
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
MAX = 10**5+5
INF = 10**9
P = 1000000007

def resolve():
    s = input().strip()
    dp = [[0]*13 for _ in range(MAX)]
    dp[0][0]=1
    for i,x in enumerate(s):
        if x=='?':
            c=-1
        else:
            c=int(x)
        for j in range(10):
            if(c!=-1 and c!=j):
                continue
            for k in range(13):
                t=(k*10+j)%13
                dp[i+1][t] = dp[i+1][t]+dp[i][k]
        for j in range(13):
            dp[i+1][j]=dp[i+1][j]%P
    l=len(s)
    print(dp[l][5]%P)


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

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

import numpy

def main():
  n, k = map(int, input().strip().split())
  Hs = numpy.array([int(line) for line in input().strip().split()], dtype=numpy.int)
  dp = numpy.zeros(n, dtype=numpy.int)
  for i in range(1, n):
    dp[i] = numpy.min([dp[i-(k)] + abs(Hs[i] - Hs[i-(k)]) for k in range(1, k+1) if i-(k) >= 0])
  print(dp[-1])


if __name__=='__main__':
  main()

### FIXED CODE ###

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

import numpy

def main():
  n, k = map(int, input().strip().split())
  Hs = numpy.array([int(line) for line in input().strip().split()], dtype=numpy.int)
  dp = numpy.zeros(n, dtype=numpy.int)
  for i in range(1, n):
    if i - k < 0:
      dp[i] = numpy.min(dp[:i] + numpy.abs(Hs[i] - Hs[:i]))
    else:
      dp[i] = numpy.min(dp[(i-k):i] + numpy.abs(Hs[i] - Hs[(i-k):i]))
  print(dp[-1])


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

from collections import deque
N,M=map(int,raw_input().split())
nl=[ [] for i in range(N+1) ]
cost={}
test={}

for i in range(M):
	L,R,D=map(int,raw_input().split())
	if i==0:start=L
	nl[L].append(R)
	nl[R].append(L)
	cost[(L,R)]=D
	cost[(R,L)]=-D


d=[ -1 for i in range(N+1) ]

def dfs(start):
	V=[ 0 for i in range(N+1) ]
	q = deque([]) 
	V[start]=1
	d[start]=0
	q.append(start)

	while len(q)!=0:
		v=q.pop()
		for i in nl[v]:
			if V[i]!=1:
				V[i]=1
				q.append(i)
				d[i]=d[v]+cost[(v,i)]


for i,j in cost.items():
	x1=i[0]
	x2=i[1]

	if d[x1]==-1:
		dfs(x1)
	if d[x2]-d[x1]==j:
		continue
	else:
		print "No"
		quit()
else:
	print "Yes"




### FIXED CODE ###

from collections import deque
from collections import defaultdict

N,M=map(int,raw_input().split())
nl=[ [] for i in range(N+1) ]
cost={}

for i in range(M):
	L,R,D=map(int,raw_input().split())
	if i==0:start=L
	nl[L].append(R)
	nl[R].append(L)
	cost[(L,R)]=D
	cost[(R,L)]=-D


d=[ None for i in range(N+1) ]
V=[ 0 for i in range(N+1) ]

def dfs(start):
	q = deque([]) 
	V[start]=1
	d[start]=0
	q.append(start)

	while len(q)!=0:
		v=q.pop()
		for i in nl[v]:
			if V[i]!=1:
				V[i]=1
				q.append(i)
				d[i]=d[v]+cost[(v,i)]
			else:
				if d[i]-d[v]!=cost[(v,i)]:
					print "No"
					quit()

for i in range(1,N+1):
	if V[i]==0:
		dfs(i)
else:
	print "Yes"
### BUGGY CODE ###

mod = 10**9+7
n=int(input())
A=list(map(int,input().split()))
ans = 0

for i in range(60):
  n1,n0 = 0,0
  for a in A:
    if a>>i & 1: n1+=1
    else: n0+=1
  ans += (2**i)*n1*n0 % mod
ans %= mod
print(ans)

### FIXED CODE ###

import numpy as np

mod = 10**9+7
n=int(input())
A=np.array(list(map(int,input().split())))
ans = 0

for i in range(60):
  n1 = np.count_nonzero((A>>i)&1)
  n0 = n-n1
  ans += (2**i)*n1*n0 % mod
ans %= mod
print(ans)
### BUGGY CODE ###

import math
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(read())
ans = 0
for a in range(1, n+1):
    for b in range(1, n+1):
        for c in range(1, n+1):
            ans += math.gcd(math.gcd(a, b), c)
print(ans)

### FIXED CODE ###

import math
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

k = int(read())
ans = 0
for a in range(1, k + 1):
    for b in range(1, k + 1):
        n = math.gcd(a, b)
        for c in range(1, k + 1):
            ans += math.gcd(n, c)
print(ans)
### BUGGY CODE ###

n=int(input())
l=[int(input()) for i in range(n)]

for i in range(n):
  lis=l[:i]+l[i+1:]
  print(max(lis))

### FIXED CODE ###

n=int(input())
l=[int(input()) for i in range(n)]

max_num=max(l)
max_index=l.index(max(l))

for i in range(n):
  if i!=max_index:
    print(max_num)
  else:
    l.remove(max_num)
    print(max(l))