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

from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n = I()
A = LI()
m = Counter(A).most_common()[0][0]
l = A.index(m)
r = n - A.index(m, l + 1)


n += 1
factorial_list = [1] * (n + 1)
fact = 1
for i in range(1, n + 1):
    fact = fact * i % mod
    factorial_list[i] = fact


def comb(n, r):
    if r > n or n < 0 or r < 0:
        return 0
    return (factorial_list[n] * pow(factorial_list[r], mod - 2, mod) * pow(factorial_list[n - r], mod - 2, mod)) % mod


for j in range(1, n + 1):
    ret = comb(n, j)
    for k in range(j):
        ret -= comb(l, k) * comb(r, j - k - 1)
    print(ret)

### FIXED CODE ###

from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n = I() + 1
A = LI()
D = defaultdict(lambda:-1)
for i in range(n):
    if D[A[i]] != -1:
        l = D[A[i]]
        r = n - i - 1
        break
    else:
        D[A[i]] = i


fac = [1] * (n + 1)
inv = [1] * (n + 1)
i = 1
for j in range(1, n + 1):
    i = i * j % mod
    fac[j] = i
    inv[j] = pow(i, mod - 2, mod)



def comb(n, r):
    if r > n or n < 0 or r < 0:
        return 0
    return fac[n] * inv[n - r] * inv[r] % mod


for j in range(1, n + 1):
    print((comb(n, j) - comb(r + l, j - 1)) % mod)
### BUGGY CODE ###

import numpy as np
from scipy.ndimage.filters import minimum_filter, maximum_filter
import copy


def calcstep(maze, s, g):
    h, w = len(maze), len(maze[0])
    maze[s[0]] = maze[s[0]][:s[1]] + 's' + maze[s[0]][s[1]+1:]
    maze[g[0]] = maze[g[0]][:g[1]] + 'g' + maze[g[0]][g[1]+1:]
    
    cost = np.zeros((h, w), dtype=int) + 500
    done = np.zeros((h, w), dtype=bool)
    barrier = np.zeros((h, w), dtype=bool)

    g = np.array([[0, 1, 0],
                  [1, 1, 1],
                  [0, 1, 0]])

    for i in range(h):
        maze[i] = list(maze[i])
        for j in range(w):
            if maze[i][j] == 's':
                start = (i, j)
                cost[i, j] = 0
                done[i, j] = True
            if maze[i][j] == 'g':
                goal = (i, j)
            if maze[i][j] == '#':
                barrier[i, j] = True

    for i in range(1, 500):

        done_next = maximum_filter(done, footprint=g) * ~done

        cost_next = minimum_filter(cost, footprint=g) * done_next
        cost_next[done_next] += 1
        cost[done_next] = cost_next[done_next]
        cost[barrier] = 500
        done[done_next] = done_next[done_next]
        done[barrier] = False

        if done[goal[0], goal[1]] == True:
            break
    return i



h, w = map(int, input().split())
maze = [input() for _ in range(h)]


res = -1
for i in range(h):
    for j in range(w):
        if(maze[i][j] == '#'): continue
        
        for k in range(h):
            for l in range(w):
                if(maze[k][l] == '#'): continue
                if(i==k and j==l): continue
                tmpmaze = copy.deepcopy(maze)
                steps = calcstep(tmpmaze, [i, j], [k, l])
                if(steps > res):
                    res = steps
print(res)

### FIXED CODE ###

from collections import deque
import copy

def bfs(grid, start):
    H, W = len(grid), len(grid[0])
    distance = [[-1] * W for _ in range(H)]
    queue = deque([start])
    distance[start[0]][start[1]] = 0
    while queue:
        x, y = queue.popleft()
 
        for i, j in ((1, 0), (-1, 0), (0, 1), (0, -1)):
            new_y, new_x = y + j, x + i
            if 0 <= new_y < W and 0 <= new_x < H:
                if grid[new_x][new_y] == '.' and distance[new_x][new_y] == -1:
                    distance[new_x][new_y] = distance[x][y] + 1
                    queue.append((new_x, new_y))
    return max(map(max, distance))

h, w = map(int, input().split())
maze = [input() for _ in range(h)]


res = -1
for i in range(h):
    for j in range(w):
        if(maze[i][j] == '#'): continue
        tmpmaze = copy.deepcopy(maze)
        steps = bfs(tmpmaze, [i, j])
        if(steps > res):
            res = steps
print(res)
### BUGGY CODE ###

def exp_sum(n:int, k:int, P:list):
    each_sum = []
    mx, total, x = 0, 0, 0
    for i in range(k - 1, n + 1):
        total = exp_val_sum(P[:i])
        total = total - exp_val_sum(P[:(i - k + 1)]) + (P[i - k] + 1) / 2
        each_sum.append(total)
        total = 0

    return max(each_sum)

def exp_val_sum(X:list):
    total = (sum(X) + len(X)) / 2
    return total

def main():

    n, k = map(int, input().split())
    P = list(map(int, input().split()))
    ans = 0
    print(exp_sum(n, k, P))

if __name__ == "__main__":
    main()

### FIXED CODE ###

def main():

    n, k = map(int, input().split())
    P = list(map(int, input().split()))
    # print(exp_sum(n, k, P))
    mx = 0
    for i in range(k):
        mx += (P[i] + 1) / 2
    tmp = mx
    for i in range(k, n):
        tmp += (P[i] - P[i - k]) / 2
        mx = max(mx, tmp)
    print(mx)

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

import sys
sys.setrecursionlimit(1000000)

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

edge = [[] for _ in range(N + 1)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    edge[a].append(b)
    edge[b].append(a)

counter = [0] * (N + 1)
for _ in range(Q):
    p, x = map(int, input().split())
    counter[p] += x

# print(edge)
# print(counter)

visited = [False] * (N + 1)
visited[1] = True
ans = [0] * (N + 1)

def dfs(fro, p):
    visited[fro] = True
    now = counter[fro] + p
    for to in edge[fro]:
        if not visited[to]:
            dfs(to, now)
    ans[fro] = now
    return

dfs(1, 0)

print(*ans[1:])


### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000)

def input():
    return sys.stdin.readline()

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

edge = [[] for _ in range(N + 1)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    edge[a].append(b)
    edge[b].append(a)

counter = [0] * (N + 1)
for _ in range(Q):
    p, x = map(int, input().split())
    counter[p] += x

# print(edge)
# print(counter)

visited = [False] * (N + 1)
visited[1] = True
ans = [0] * (N + 1)

def dfs(fro, p):
    visited[fro] = True
    now = counter[fro] + p
    for to in edge[fro]:
        if not visited[to]:
            dfs(to, now)
    ans[fro] = now
    return

dfs(1, 0)

print(*ans[1:])
### BUGGY CODE ###

N=int(input())
A=list(map(int,input().split()))
X=[]
for i in range(N) :
    X.append(str(A.index(i+1)+1))
print(" ".join(X))

### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
X=[None]*N
for i in range(N) :
    X[A[i]-1]=i+1
print(*X)
### BUGGY CODE ###

n=int(input())
ans=10**10
for i in range(1,n+1):
  if n%i==0:
    a=max(len(str(i)),len(str(n//i)))
    if a<ans:
      ans=a
print(ans)

### FIXED CODE ###

import math
n=int(input())
ans=10**10
for i in range(1,round(math.sqrt(n+1))+5):
  if n%i==0:
    a=max(len(str(i)),len(str(n//i)))
    if a<ans:
      ans=a
print(ans)
### BUGGY CODE ###

def main():
    n,k,q = [int(x) for x in input().split()]
    life = [k]*n
    a = []
    for i in range(q):
        a.append(int(input()))

    result = ['Yes']*n
    for i in range(q):
        for j in range(n):
            if a[i] == j+1:
                continue
            life[j] -= 1
            if life[j] <= 0:
                result[j] = 'No'
    for i in range(n):
        print(result[i])

if __name__ == '__main__':
    main()


### FIXED CODE ###

import collections

def main():
    n,k,q = [int(x) for x in input().split()]
    a = []
    for i in range(q):
        a.append(int(input()))

    c = collections.Counter(a)

    for i in range(n):
        index = int('{}'.format(i+1))
        point = k + c[index] - q
        if point > 0:
            print('Yes')
        else:
            print('No')


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

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

mod = int(1e9+7)
def powermod(p,n,mod):
  if n==0: return 1
  if n==1: return p%mod
  else:    return powermod(p,n//2,mod)**2 * (p**(n%2)) %mod


memo={}
for i, a in enumerate(A):
  if a in memo:
    L = memo[a]
    C = i - memo[a] -1
    R = len(A) - i-1
    break
  else:
    memo[a] = i
    
#print(L,C,R)
_LR = [0]*(n+3)
_LCR = [0] * (n+3) # _LCR[k] = (L+C+R)C(k)
_k = [0] * (n+3)
_LR[0] = _LCR[0] = _k[0] = 1

LR = [0]*(n+2) #LR[k] = (L+R)C(k)
LR[0] = 1
#LDR = [0]*(n+2)
#LDDR = [0]*(n+2)

LCR = [0] * (n+2) # LCR[k] = _LCR[k] - LR[k]
#LDCR = [0] * (n+2) #最後に*2を忘れないこと
#LDCDR = [0] * (n+2)

for k in range(1,n+2):
  _LR[k] = (_LR[k-1] * (L+R+1-k)) %mod
  _LCR[k] = (_LCR[k-1] * (L+C+R+1-k))% mod
  _k[k] = (_k[k-1] * powermod(k, mod-2, mod)) %mod
  
  LR[k] = (_LR[k] * _k[k])%mod
#  LDR[k] = LR[k-1]
#  LDDR[k] = LDR[k-1]
  
  LCR[k] = (_LCR[k] * _k[k] - LR[k])%mod
#  LDCR[k] = LCR[k-1]
#  LDCDR[k] = LDCR[k-1]
  #print(LR, LCR)
  print((LR[k] + LR[k-1] + LR[k-2] + LCR[k] + 2*LCR[k-1] + LCR[k-2])%mod)
  
#print(LR)
#print(LDR)
#print(LDDR)
#print(_LCR)
#print(LCR)
#print(LDCR)
#print(LDCDR)

### FIXED CODE ###

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

mod = int(1e9+7)
def powermod(p,n,mod):
    #if n==0: return 1
    if n==1:
        return p%mod
    if n%2:
        return powermod(p,n//2,mod)**2 * p %mod
    else:
        return powermod(p,n//2,mod)**2 %mod


memo={}
for i, a in enumerate(A):
  if a in memo:
    L = memo[a]
    C = i - memo[a] -1
    R = len(A) - i-1
    break
  else:
    memo[a] = i
    
#print(L,C,R)
_LR = [0]*(n+3)
_LCR = [0] * (n+3) # _LCR[k] = (L+C+R)C(k)
_k = [0] * (n+3)
_LR[0] = _LCR[0] = _k[0] = 1

LR = [0]*(n+2) #LR[k] = (L+R)C(k)
LR[0] = 1
#LDR = [0]*(n+2)
#LDDR = [0]*(n+2)

LCR = [0] * (n+2) # LCR[k] = _LCR[k] - LR[k]
#LDCR = [0] * (n+2) #最後に*2を忘れないこと
#LDCDR = [0] * (n+2)

for k in range(1,n+2):
  _LR[k] = (_LR[k-1] * (L+R+1-k)) %mod
  _LCR[k] = (_LCR[k-1] * (L+C+R+1-k))% mod
  _k[k] = (_k[k-1] * powermod(k, mod-2, mod)) %mod
  
  LR[k] = (_LR[k] * _k[k])%mod
#  LDR[k] = LR[k-1]
#  LDDR[k] = LDR[k-1]
  
  LCR[k] = (_LCR[k] * _k[k])%mod - LR[k]
#  LDCR[k] = LCR[k-1]
#  LDCDR[k] = LDCR[k-1]
  #print(LR, LCR)
  print((LR[k] + LR[k-1] + LR[k-2] + LCR[k] + 2*LCR[k-1] + LCR[k-2])%mod)
  
#print(LR)
#print(LDR)
#print(LDDR)
#print(_LCR)
#print(LCR)
#print(LDCR)
#print(LDCDR)
### BUGGY CODE ###

# 解説を参考に作成
def solve():
    S = input()
    lenS = len(S)
    # modS = []
    mod_list = [0] * 2019
    for i in range(lenS):
        x = int(S[lenS - 1 - i:]) % 2019
        # modS.append(int(S[lenS - 1 - i:]) % 2019)
        mod_list[x] += 1
    result = 0
    for i, ml in enumerate(mod_list):
        if i == 0:
            result += ml
        result += int(ml * (ml - 1) / 2)
    print(result)


if __name__ == '__main__':
    solve()


### FIXED CODE ###

# 解説を参考に作成
# さらに 提出 #12403542 を参考


def solve():
    S = input()
    lenS = len(S)
    mod_list = [0] * 2019
    x = 0
    for i in range(lenS):
        x = (int(S[lenS - 1 - i]) * pow(10, i, 2019) + x) % 2019
        mod_list[x] += 1

    result = 0
    for i, ml in enumerate(mod_list):
        if i == 0:
            result += ml
        result += int(ml * (ml - 1) / 2)
    print(result)


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

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

A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = 0

a = [0]
b = [0]

for i in range(n):
    a.append(a[i] + A[i])

for i in range(m):
    b.append(b[i] + B[i])

for i in range(n + 1):
    if a[i] > k:
        break
    for j in range(m + 1):
        if a[i] + b[j] <= k:
            ans = max(ans, i + j)
        else:
            break
print(ans)

### FIXED CODE ###

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

A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = 0

a = [0]
b = [0]

for i in range(n):
    a.append(a[i] + A[i])

for i in range(m):
    b.append(b[i] + B[i])

j = m

for i in range(n + 1):
    if a[i] > k:
        break
    while a[i] + b[j] > k:
        j -= 1
    else:
        ans = max(ans, i + j)
print(ans)
### BUGGY CODE ###

# from math import factorial,sqrt
# from itertools import permutations as permus
# from fractions import gcd
# from collections import deque,Counter
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import scipy as scp

# 入力の受け取り
n = int(input())

ans = sum(range(n))

print(ans)
# print("{:.10f}".format(ans))


### FIXED CODE ###

# from math import factorial,sqrt
# from itertools import permutations as permus
# from fractions import gcd
# from collections import deque,Counter
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import scipy as scp

# 入力の受け取り
n = int(input())

n = n-1

ans = (1+n)*n//2

print(ans)
# print("{:.10f}".format(ans))
### BUGGY CODE ###

def read():
    return int(input())

def reads(sep=None):
    return list(map(int, input().split(sep)))

def main():
    x = input()
    while 'ST' in x:
        x = x.replace('ST', '')
    print(len(x))

main()


### FIXED CODE ###

def read():
    return int(input())

def reads(sep=None):
    return list(map(int, input().split(sep)))

def main():
    x = input()
    s = []
    for c in x:
    	if len(s) == 0:
    		s.append(c)
    	elif c == 'T' and s[-1] == 'S':
    		s.pop()
    	else:
    		s.append(c)
    print(len(s))
 
main()
### BUGGY CODE ###

#!/mnt/c/Users/moiki/bash/env/bin/python
N,K = list(map(int, input().split()))
h = list(map(int, input().split()))

suml = [1e9 for i in range(N)]
suml[0] = 0

for e in range(1,N):

    # for k in range(1, min([e, K])+1):
    #     suml[e] = min(suml[e],
    #             abs(h[e]-h[e-k]) + suml[e-k]
    #     )
    start = max(0, e-K)
    cost  = min(cst + abs( h[e] - hgh ) for cst, hgh in zip(suml[start:e], 
           h[start:e]))
    suml[e] = cost

print(suml[N-1])
        



### FIXED CODE ###

#!/mnt/c/Users/moiki/bash/env/bin/python
# N,K = list(map(int, input().split()))
# h = list(map(int, input().split()))

# (N,K), h = map(int, input().split()), list(map(int, input().split()))
N,K,*h = map(int, "\n".join([input(), input()]).split())

# suml = [1e9 for i in range(N)]
# suml[0] = 0


suml = [0]*N

# for i in range(1,N):
for i,e_h in enumerate(h):
    if i == 0:
        continue

    start = max(0, i-K)
    cost  = min(cst + abs( e_h - hgh) for cst, hgh in 
                   zip(suml[start:i], h[start:i]))
    # cost  = min(cst + abs( h[i] - hgh ) for cst, hgh in 
    #               zip(suml[start:i], h[start:i]))
    suml[i] = cost

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

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

good = 0
for i in range(N):
    n = i + 1
    H = Hs[i]
    ans = True
    for a in arr:
        if n not in a:
            continue
        
        f = a[0]
        s = a[1]
        H1 = Hs[f - 1]
        H2 = Hs[s - 1]
        if f == n:
            if H1 <= H2:
                ans = False
                break
        else:
            if H2 <= H1:
                ans = False
                break
            
    if ans is True:
        good += 1
print(good)

### FIXED CODE ###

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

ans = [True for _ in range(N)]

for a in arr:
    f, s = a
    H1 = Hs[f - 1]
    H2 = Hs[s - 1]
    if H1 == H2:
        ans[f - 1] = False
        ans[s - 1] = False
    elif H1 < H2:
        ans[f - 1] = False
    else:
        ans[s - 1] = False

print(len(list(filter(lambda x: x, ans))))
### BUGGY CODE ###

from functools import reduce
from collections import Counter


def f2nom(f):
    return reduce(lambda x, y: x * (y + 1), f, 1)


def sp(n):
    p = [2]
    *t, = range(3, n + 1, 2)
    for i, _ in enumerate(t):
        if not t[i]:
            continue
        p.append(t[i])
        for j in range(i, len(t), t[i]):
            t[j] = 0
    return p


def solve(string):
    n = int(string)
    ps = sp(int(n))
    t = [0] * (n + 1)
    for p in ps:
        if p <= n:
            t[p] = [p]
    ans = 1
    for i in range(2, n + 1):
        ans += i * f2nom(Counter(t[i]).values())
        for p in ps:
            if i * p > n:
                break
            t[i * p] = t[i][:]
            t[i * p].append(p)
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))


### FIXED CODE ###

def solve(string):
    n = int(string)
    return str(sum(i * (n // i) * (n // i + 1) // 2 for i in range(1, n + 1)))


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))
### BUGGY CODE ###

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

max_val = 0

index = 0
while(index < len(H) - 1):
    index_boolean = index
    tmp = 0
    while (index_boolean < len(H) - 1):
        if (H[index + 1] <= H[index]):
            tmp += 1
            index += 1
            index_boolean += 1
        else:
            index_boolean = len(H)

    if (tmp > max_val):
        max_val = tmp

print(max_val)

### FIXED CODE ###

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

max_val = 0

index = 0
while(index < len(H) - 1):
    index_boolean = index
    tmp = 0
    while (index_boolean < len(H) - 1):
        if (H[index + 1] <= H[index]):
            tmp += 1
            index += 1
            index_boolean += 1
        else:
            index_boolean = len(H)
            index += 1

    if (tmp > max_val):
        max_val = tmp

print(max_val)
### BUGGY CODE ###

#import sys
#input = sys.stdin.readline
import heapq
def main():
    N = int( input())
    A = list( map( int, input().split()))
    B = list( map( int, input().split()))
    C = [(-B[i],i) for i in range(N)]
    heapq.heapify(C)
    ans = 0
    check = 0
    while check < N:
        a,i = heapq.heappop(C)
        a *= -1

        if B[i] == A[i]:
            check += 1
            continue
        ans += 1
        a -= B[i-1] + B[(i+1)%N]
        B[i] = a
        if B[i] == A[i]:
            check += 1
        elif B[i] > A[i]:
            heapq.heappush(C, (-a, i))
        else:
            print(-1)
            return

    print(ans)
        
if __name__ == '__main__':
    main()


### FIXED CODE ###

#import sys
#input = sys.stdin.readline
import heapq
def main():
    N = int( input())
    A = list( map( int, input().split()))
    B = list( map( int, input().split()))
    C = [(-B[i],i) for i in range(N)]
    heapq.heapify(C)
    ans = 0
    check = 0
    while check < N:
        a,i = heapq.heappop(C)
        a *= -1

        if B[i] == A[i]:
            check += 1
            continue
        cnt = (B[i] - A[i])//(B[i-1] + B[(i+1)%N])
        if cnt == 0:
            print(-1)
            return
        ans += cnt        
        a -= (B[i-1] + B[(i+1)%N])*cnt
        B[i] = a
        if B[i] == A[i]:
            check += 1
        elif B[i] > A[i]:
            heapq.heappush(C, (-a, i))
        else:
            print(-1)
            return

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

n,m=map(int,input().split())
L=[list(map(int,input().split())) for i in range(m)]
#print(L)
M=0
ans = set(range(L[M][0],L[M][1]+1))
for M in range(m):
  a=set(range(L[M][0],L[M][1]+1))
  ans = a&ans
  #print(ans)
print(len(list((ans))))

### FIXED CODE ###

import numpy as np
n,m=map(int,input().split())
L=[list(map(int,input().split())) for i in range(m)]
list = np.asarray(L)

MAX=np.max(list,axis=0)
MIN=np.min(list,axis=0)

ans = MIN[1]-MAX[0]+1
if ans>0:
  print(MIN[1]-MAX[0]+1)
else:
  print(0)
### BUGGY CODE ###

n=int(raw_input())
a=map(int,raw_input().split())
b=[]
for i in range(n):
    if i%2==0:
        b.append(a[i])
    else:
        b.insert(0, a[i])
if n%2==1:
    b.reverse()
c=map(str,b)
print ' '.join(c)

### FIXED CODE ###

n=int(raw_input())
a=map(int,raw_input().split())

for i in range((n+1)/2):
    print a[n-2*i-1],
for i in range(n/2):
    print a[i*2+n%2],
print ''
### BUGGY CODE ###

n,k = map(int, input().split())
p = list(map(int, input().split()))
c = list(map(int, input().split()))
    
flags = [0]*n
roots = []
for i in range(n):
  if flags[i] == 1:
    continue
  root = [i+1]
  while True:
    root.append(p[root[-1]-1])
    flags[root[-1]-1] = 1 
    if root[-1] == i+1:
      root.pop(-1)
      break
  roots.append(root)

ans = max(c)
for root in roots:
  root.extend(root)
  ruisekiwa = [0]*len(root)
  ruisekiwa[0] = c[root[0]-1]
  for i in range(1, len(root)):
    ruisekiwa[i] = ruisekiwa[i-1] + c[root[i]-1]
  scoreCir = ruisekiwa[len(root)//2-1]
  #print(root)
  scoreForRoot = -10**15
  for i in range(1, min(k+1, len(root)//2+1)): #移動回数
    scoreForKaisuu = -10**15
    for j in range(0, len(root)//2):
      score = ruisekiwa[j+i] - ruisekiwa[j]
      scoreForKaisuu = max(score, scoreForKaisuu)
    #print(scoreForKaisuu)
    if scoreCir > 0 and k-i >= len(root)//2:
      #print((k-i)//(len(root)//2))
      scoreForKaisuu += (k-i)//(len(root)//2)*scoreCir
    scoreForRoot = max(scoreForKaisuu, scoreForRoot)
  ans = max(ans, scoreForRoot)
print(ans)


### FIXED CODE ###

n,k = map(int, input().split())
p = list(map(int, input().split()))
c = list(map(int, input().split()))
    
flags = [0]*n
roots = []
for i in range(n):
  if flags[i] == 1:
    continue
  root = [i+1]
  while True:
    root.append(p[root[-1]-1])
    flags[root[-1]-1] = 1 
    if root[-1] == i+1:
      root.pop(-1)
      break
  roots.append(root)

ans = max(c)
for root in roots:
  root.extend(root)
  ruisekiwa = [0]*len(root)
  ruisekiwa[0] = c[root[0]-1]
  for i in range(1, len(root)):
    ruisekiwa[i] = ruisekiwa[i-1] + c[root[i]-1]
  scoreCir = ruisekiwa[len(root)//2-1]
  #print(root)
  scoreForRoot = -10**15
  for i in range(1, min(k+1, len(root)//2+1)): #移動回数
    scoreForKaisuu = -10**15
    for j in range(0, len(root)//2):
      score = ruisekiwa[j+i] - ruisekiwa[j]
      scoreForKaisuu = max(score, scoreForKaisuu)
    #print(scoreForKaisuu)
    if scoreCir > 0 and k-i >= len(root)//2:
      #print((k-i)//(len(root)//2))
      scoreForKaisuu += (k-i)//(len(root)//2)*scoreCir
    scoreForRoot = max(scoreForKaisuu, scoreForRoot)
  ans = max(ans, scoreForRoot)
print(ans)
### BUGGY CODE ###

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

sum=0
tmp=0
for i in range(n):
    o = i+1
    tmp = 0
    while (o<n):
        tmp=a[o]+tmp
        o=o+1
    sum=(a[i]%1000000007*tmp%1000000007)%1000000007+sum%1000000007

print(sum%1000000007)

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
mod=1000000007
sum=0
tmp=0
o=0
while(o<n):
    tmp = (a[o]%mod + tmp%mod)%mod
    o += 1

for i in range(n):
    tmp=(tmp%mod-a[i]%mod)%mod
    sum=((a[i]%mod)*tmp)%mod+sum%mod



print(sum%mod)