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

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

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

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

        if x == y:
            return

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

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

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

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

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

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

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

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

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

n,m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(m)]
uf = UnionFind(n)
for i in range(m):
    uf.union(a[i][0]-1,a[i][1]-1)
x = list(uf.all_group_members().values())
#print(x)
ans = 0
for i in range(len(x)):
    ans = max(ans,len(x[i]))
print(ans)


### FIXED CODE ###

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

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

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

        if x == y:
            return

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

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

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

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

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

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

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

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

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


n,m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(m)]
uf = UnionFind(n)
for i in range(m):
    uf.union(a[i][0]-1,a[i][1]-1)
ans = 0
x = uf.parents
for i in range(n):
    if x[i]<0:
        #print(i)
        ans = max(ans,uf.size(i))
print(ans)
### BUGGY CODE ###

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

import bisect as bi


def solve():
    N = int(input())
    A = []
    heads = []
    for _ in range(N):
        A.append(int(input()))
    a = A.pop()
    bi.insort_left(heads, a)
    while A:
        a = A.pop()
        if a < heads[-1]:
            j = -1
            for i, h in enumerate(heads):
                if h > a:
                    j = i
                    break
            del heads[j]
        bi.insort_left(heads, a)
    return len(heads)
  

def main():
    print(solve())


if __name__ == "__main__":
    main()


### FIXED CODE ###

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

import bisect as bi


def solve():
    N = int(input())
    A = []
    heads = []
    for _ in range(N):
        A.append(int(input()))
    a = A.pop()
    bi.insort(heads, a)
    while A:
        a = A.pop()
        if a < heads[-1]:
            j = bi.bisect(heads, a)
            del heads[j]
        bi.insort(heads, a)
    return len(heads)
  

def main():
    print(solve())


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

N = int(input())
L = [0] + list(map(int, input().split())) + [0]
edge = []
distance = 0
for i in range(N+1):
    distance += abs(L[i] - L[i+1])
for i in range(1,N+1):
    if (L[i] -L[i-1])*(L[i+1] - L[i] )>=0:
        pass
    else:
        edge.append(i)
for i in range(1,N+1):
    if i in edge:
        print(distance-2*min(abs(L[i]-L[i+1]),abs(L[i]-L[i-1])))
    else:
        print(distance)

### FIXED CODE ###

N = int(input())
L =[0]+ list(map(int,input().split()))+[0]
dis = 0
for i in range(N+1):
    dis += abs(L[i] - L[i+1])
#print(L,dis)
for i in range(1,N+1):
    print(dis + abs(L[i-1]-L[i+1]) - abs(L[i-1]-L[i]) - abs(L[i]-L[i+1]))
### BUGGY CODE ###

N=int(input())
s=[input() for i in range(N)]
S=sorted(s)
a=1
num=[]
st=[]
for i in range(N-1):
  if S[i+1]==S[i]:
    a+=1
    if i == (N-2):
        num.append(a)
        st.append(S[-1])
  elif S[i+1]!=S[i]:
    num.append(a)
    st.append(S[i])
    a=1
if S[-1]!=S[-2]:
    num.append(1)
    st.append(S[-1])

d=max(num)
x=[]

ind=[i for i, v in enumerate(num) if v == max(num)]# 複数の最大値のインデックスを全て取得
st2=[]
for i in range(len(ind)):
    st2.append(st[ind[i]])
[print(i) for i in st2]

### FIXED CODE ###

import collections
N=int(input())
s=[input() for i in range(N)]
#S=sorted(s)
a=1
num=[]
st=[]
c = collections.Counter(s)#要素数が大きい順に辞書型ですべての要素を返す
#print(c)
max_c = max(c.values())#最も多い要素の数
#print(max_c)
st=[]
for k,v in c.items():
    if v==max_c:
        st.append(k)
st2=sorted(st)
[print(i) for i in st2]
### BUGGY CODE ###

import numpy as np
from scipy.sparse.csgraph import breadth_first_tree
from scipy.sparse import csr_matrix
N, M = map(int,input().split())
l = [[0]*(N) for _ in range(N)]
for i in range(M):
    A, B = map(int,input().split())
    l[A-1][B-1] = 1
    l[B-1][A-1] = 1

csr = csr_matrix(l)
Tcsr = breadth_first_tree(csr, 0, False)
ans = np.dot(Tcsr.toarray().T.astype(int), np.arange(N)+1)
if int(np.sum(Tcsr)) != N-1:
    print("No")
else:
    print("Yes")
    for i in range(1, N):
        print(ans[i])

### FIXED CODE ###

from scipy.sparse.csgraph import breadth_first_tree, breadth_first_order
from scipy.sparse import csr_matrix, coo_matrix
N, M = map(int,input().split())
A = []
B = []
for i in range(M):
    a, b = map(int,input().split())
    a -= 1
    b -= 1
    A.append(a)
    B.append(b)
D = [1] * M
csr = coo_matrix((D, (A, B)), (N, N)).tocsr()
Tcsr = breadth_first_order(csr, 0, False, True)
ans = []
for i in Tcsr[1][1:]+1:
    if i == -9998:
        print("No")
        quit()
    ans.append(i)
print("Yes")
for i in ans:
    print(i)
### BUGGY CODE ###

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

ods = 0
ans = 0
first = True
while ods != n:
    ods = 0
    div = 0
    for i in range(len(nums)):
        e = nums[i]
        if e % 2 == 0 and div < 1:
            nums[i] = e // 2
            first = False
            div += 1
        else:
            nums[i] *= 3
            ods += 1
    ans += 1
ans -= 1
print(ans)

### FIXED CODE ###

n = int(input())
a = map(int, input().split())
 
cont = 0
 
for e in a:
    x = e
    while x % 2 == 0:
        x /= 2
        cont += 1
 
print(cont)
### BUGGY CODE ###

s,t = input(),input()
n,m=len(s),len(t)
dp = [[0]*(n+1) for _ in range(m+1)]

for i in range(m):
    for j in range(n):
        if s[j] == t[i]:
            dp[i+1][j+1] = max(dp[i][j]+1,dp[i+1][j+1])
        
        dp[i+1][j+1] = max(dp[i+1][j+1],dp[i+1][j], dp[i][j+1])

ans = ""
count = 0
while count != dp[-1][-1]:
    if dp[m][n] == dp[m-1][n]:
        m -= 1
    elif dp[m][n] == dp[m][n-1]:
        n -= 1
    else:
        ans += t[m-1]
        count += 1
        m -= 1
        n -= 1

print(ans[::-1])

### FIXED CODE ###

s,t = input(),input()
n,m=len(s),len(t)
dp = [[0]*(n+1) for _ in range(m+1)]

for i in range(m):
    for j in range(n):
        if s[j] == t[i]:
            dp[i+1][j+1] = max(dp[i][j]+1,dp[i+1][j+1])
        
        dp[i+1][j+1] = max(dp[i+1][j+1],dp[i+1][j], dp[i][j+1])

ans = ""
count = 0
while count != dp[-1][-1]:
    if dp[m][n] == dp[m-1][n]:
        m -= 1
    elif dp[m][n] == dp[m][n-1]:
        n -= 1
    else:
        ans += t[m-1]
        count += 1
        m -= 1
        n -= 1

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

# AtCoder Beginner Contest 100
# C - *3 or /2

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

count=0

A=[ a for a in A if a%2==0 ]

while len(A)>0:

    _A=[]
    for a in A:
        if a==max(A):
            _a=a//2
            _A.append(_a)
        else:
            _a=a*3
            _A.append(_a)
    count+=1
    A=[ _a for _a in _A if _a%2==0 ]
    # print(A)
    # print(_A)


print(count)


### FIXED CODE ###

# AtCoder Beginner Contest 100
# C - *3 or /2
def f(N,c):
    if N%2==0:
        n=N//2
        c+=1
        return f(n,c)
    else:
        return c



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

count=0

for a in A:
    count+= f(a,0)

print(count)
### BUGGY CODE ###

N, Q = [int(x) for x in input().split()]
G = [1] * N

index={}
for i,s in enumerate(input().strip()):
    index.setdefault(s, []).append(i)

for _ in range(Q):
    t, d = [x for x in input().split()]
    if t not in index:
        continue

    if d == 'L':
        for i in index[t]:
            if i > 0:
                G[i-1]+= G[i]
            G[i] = 0

    else:
        for i in index[t]:
            if i < N - 1:
                G[i+1] += G[i]
            G[i] = 0
print(sum(G)) 


### FIXED CODE ###

#!/usr/bin/python3
N, Q = [int(x) for x in input().split()]
S = input()

qs = []
for _ in range(Q):
    t, d = [x for x in input().split()]
    #print(t, d)
    qs.append((t,-1 if d == 'L' else 1))

memo = [None] * N
memo.append(N)

def move(i):
    org = i
    if memo[i]:
        return memo[i]
    for t, d in qs:
        if S[i] == t:
            i+=d
        if i == -1:
            break
        elif i == N:
            break
    memo[org] = i
    return i

def search_right(lo, hi, x):
    while lo < hi:
        mid = lo + (hi - lo) // 2
        if x < move(mid):
            hi = mid 
        else: # e <= t
            lo = mid +1
    return lo

def search_left(lo, hi, x):
    while lo < hi:
        mid = lo + (hi - lo) // 2
        if move(mid) < x:
            lo = mid +1
        else: # e <= t
            hi = mid
    return lo


#l = search(0, N-1, -1)
#assert move(l) == 2, "%d" % move(l)
#print("search(-1)=", l)

l = search_right(0, N, -1)
r = search_left(0, N, N)

if 1==0:
    print(S)
    for t, d in qs:
        print(t, {-1:'L', 1:'R'}[d])
    m = [move(i) for i in range(N+1)]
    print(" ".join("%2d" % i for i in range(N+1)))
    print(" ".join("%+d" % x for x in m))
    print(" ".join(" *" if l == i else "  " for i in range(N+1)))
    print(" ".join(" *" if r == i else "  " for i in range(N+1)))

print(r-l)
### BUGGY CODE ###

import sys

def create_dict(N):
    d = {}
    key2rep = {}
    for i in range(N):
        d[i+1] = set([i+1])
        key2rep[i+1] = i+1
    return d, key2rep

def add_x2y(x, y, d, key2rep):
    rep = key2rep[y]
    big_rep = key2rep[x]
    if rep == big_rep:
        return
    for old in d[big_rep]:
        d[rep].add(old)
        key2rep[old] = rep
    d[big_rep] = set()
#    print(d)

N, M = map(int,input().split(' '))
d, key2rep = create_dict(N)
p_list = list(map(int,input().split(' ')))

for line in sys.stdin:
    x,y = map(int, line.strip().split(' '))
    add_x2y(max(x,y), min(x,y), d, key2rep)

score = 0
for i in d:
    for x in d[i]:
        if p_list[x-1] in d[i]:
            score += 1
print(score)


### FIXED CODE ###

import sys

def key2rep_iter(key, key2rep, temp_list):
    if key2rep[key] == key:
        for i in temp_list:
            key2rep[i] = key2rep[key]
        return key
    temp_list.append(key)
    return key2rep_iter(key2rep[key], key2rep, temp_list)

def add_x2y(x, y, key2rep):
    rep = key2rep_iter(y, key2rep, [])
    big_rep = key2rep_iter(x, key2rep, [])
    if rep == big_rep:
        return
    key2rep[big_rep] = rep

N, M = map(int,input().split(' '))
p_list = [int(i) for i in input().split(' ')]
key2rep = {i+1:i+1 for i in range(N)}

for line in sys.stdin:
    x,y = map(int, line.strip().split(' '))
    add_x2y(max(x,y), min(x,y), key2rep)

print(len([1 for i in range(N) if key2rep_iter(p_list[i], key2rep, []) == key2rep_iter(i+1, key2rep, [])]))
### BUGGY CODE ###

N = int(input())

tmp = 0
for i in range(1,N):
    tmp += i
print(tmp)

### FIXED CODE ###

N = int(input())

print((N-1)*N//2)
### BUGGY CODE ###

#encoding:utf-8

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

def factorint(N):
    table = {}
    reset = False
    while(N > 1):
        for i in range(2,N+1):
            if N%i == 0:
                while N%i == 0:
                    N = N//i
                    if i in table.keys():
                        table[i] += 1
                    else:
                        table[i] = 1
                reset = True
                # print(N)
                break
    return table

facters = factorint(P)
# print(facters)

ans = 1
for key in facters.keys():
    if facters[key]/N >= 1:
        ans *= key**(facters[key]//N)
print(int(ans))
# print(type(ans))


### FIXED CODE ###

#encoding:utf-8

import math

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

def factorint(N):
    table = {}
    while(N > 1):
        for i in range(2,N+1):
            if N%i == 0:
                while N%i == 0:
                    N = N//i
                    if i in table.keys():
                        table[i] += 1
                    else:
                        table[i] = 1
                break
    return table

ans = 1
if N == 1:
    ans = P
elif 1 < N < 40:
    for i in range(2,round(P**(1/N))+1):
        if P % i**N == 0:
            ans = i

else:
    pass

print(int(ans))
# print(type(ans))
### BUGGY CODE ###

N = int(input())
a = [int(i) for i in input().split()]

check = []

ans = 0
for i in a:
    if i not in check:
        check.append(i)
        tmp = a.count(i)
        if tmp < i:
            ans += tmp
        else:
            ans += tmp - i

print(ans)


### FIXED CODE ###

from collections import Counter as ct

N = int(input())
a = [int(i) for i in input().split()]
c = ct(a)

ans = 0
for i, j in c.items():
    if i <= j:
        ans += j - i
    else:
        ans += j

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

from fractions import gcd

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

lst = [0]*(max(As)+1)

for a in As:
  i = 2
  if a % i == 0:
    lst[i] += 1
  while a % i == 0:
    a //= i
  i = 3
  while i**2 <= a:
    if a % i == 0:
      lst[i] += 1  
    while a % i == 0:
      a //= i
    i += 2
  if a > 1:
    lst[a] += 1
    
if max(lst) < 2:
  print('pairwise coprime')
  exit()
  
t = As[0]

for a in As:
  t = gcd(t,a)
  
if t == 1:
  print('setwise coprime')
else:
  print('not coprime')


### FIXED CODE ###

from fractions import gcd

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

A = max(As)
lst = [0]*(A+1)
rlt = [0]*(A+1)

for i in range(2, A+1):
  if lst[i] > 0:
    continue
  j = 1
  while i*j <= A:
    if lst[i*j] == 0:
      lst[i*j] = i
    j += 1
  if j == 1:
    break
    
for a in As:
  tmp = -1
  while a > 1:
    if tmp != lst[a]:
      rlt[lst[a]] += 1
      tmp = lst[a]
    a //= lst[a]

r = max(rlt) 

if r < 2:
  print('pairwise coprime')
elif r < N:
  print('setwise coprime')
else:
  print('not coprime')
### BUGGY CODE ###

x,y,z,k = map(int,input().split())
lisa = list(map(int,input().split()))
lisb = list(map(int,input().split()))
lisc = list(map(int,input().split()))
an = []
ans = []
for num in lisb:
    for nu in lisa:an.append(num+nu)
an.sort(reverse=True)
an = an[:min(3001,x*y*z+1)]
for num in lisc:
    for nu in an:ans.append(num+nu)
ans.sort(reverse=True)
for i in range(k):print(ans[i])

### FIXED CODE ###

x,y,z,k = map(int,input().split())
lisa = list(map(int,input().split()))
lisb = list(map(int,input().split()))
lisc = list(map(int,input().split()))
lisa.sort(reverse=True)
lisb.sort(reverse=True)
lisc.sort(reverse=True)
an = []
ans = []
for num in lisb:
    for nu in lisa:
        an.append(num+nu)
an.sort(reverse=True)
an = an[:min(3001,x*y*z+1)]
for num in lisc:
    for nu in an:
        ans.append(num+nu)
ans.sort(reverse=True)
for i in range(k):
    print(ans[i])
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def printlist(lst, k='\n'): print(k.join(list(map(str, lst))))
INF = float('inf')

from math import log2

class Doubling:
    def __init__(self, lst, max_step):
        self.lst = lst
        self.max_step = max_step
        self.k = int(log2(max_step * 2 - 1)) + 1
        # print(self.k)
        self.D = self.create()

    def create(self):
        len_ = len(self.lst)
        D = [[-1] * len_ for _ in range(self.k)]
        D[0] = self.lst
        d = 2
        for i in range(1, self.k):
            for j in range(len_):
                D[i][j] = D[i - 1][D[i - 1][j]]
            d *= 2
        # print(D)
        return D

    def step(self, start, step):
        v = start
        for i in range(self.k, -1, -1):
            l = 1 << i
            if l <= step:
                v = self.D[i][v]
                # print(i, l)
                step -= l
        return v

def solve():
    n, k = MI()

    A = LI1()
    d = Doubling(A, k)

    v = d.step(0, k)
    print(v+1)


if __name__ == '__main__':

    solve()


### FIXED CODE ###

import sys

sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1


def II(): return int(input())


def MI(): return map(int, input().split())


def MI1(): return map(int1, input().split())


def LI(): return list(map(int, input().split()))


def LI1(): return list(map(int1, input().split()))


def LLI(rows_number): return [LI() for _ in range(rows_number)]


def printlist(lst, k='\n'): print(k.join(list(map(str, lst))))


INF = float('inf')


def solve():
    n, k = MI()
    A = LI1()
    # print(A)
    memo = {0: 0}
    current = 0
    keiro = []
    for i in range(n):
        keiro.append(current)
        next = A[current]
        # print(i, current, next)
        if (i + 1) == k:
            print(next+1)
            return

        if memo.get(next, -1) == -1:
            memo[next] = i + 1
            current = next
        else:
            pre = current
            current = next
            keiro.append(current)
            # print(pre, current)
            left = k - i - 1
            # print('aaa', memo[pre], memo[current])
            loopsize = memo[pre] - memo[current] + 1
            # print('a', left, loopsize)
            r = left % loopsize
            # print(memo)
            # print(keiro)
            # print(keiro[memo[current] + r])
            ans = keiro[memo[current] + r] + 1
            print(ans)
            return


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

N, C, K = map(int, input().split())
T = [int(input()) for _ in range(N)]
T.sort()
count_bus = 0

i = 0
while i < len(T):
    t = T[i]
    for j in range(1, C):
        if i+j >= len(T):
            i += j
            count_bus += 1
            break
        if T[i+j] <= t + K:
            pass
            if j == C-1:
                i += j + 1
                count_bus += 1
                break
        else:
            count_bus += 1
            i += j
            break

print(count_bus)

### FIXED CODE ###

N, C, K = map(int, input().split())
T = [int(input()) for _ in range(N)]
T.sort()

# print(T)

bus = 1
org = T[0]
_count = 0

for t in T:

    if t - org <= K and _count < C:
        _count += 1
        # print('1- t:{}, org:{}, _count:{}, bus:{}'.format(t, org, _count, bus))
    else:
        bus += 1
        org = t
        _count = 1
        # print('2- t:{}, org:{}, _count:{}, bus:{}'.format(t, org, _count, bus))

print(bus)
### BUGGY CODE ###

from itertools import accumulate

mod = 10 ** 9 + 7

N, K, *A = map(int, open(0).read().split())

dp = [1] + [0] * K
for a in A:
    S = [0] + list(accumulate(dp))
    for i in range(K + 1):
        dp[i] = (S[i + 1] - S[max(0, i - a)]) % mod

print(dp[K])

### FIXED CODE ###

mod = 10 ** 9 + 7

N, K, *A = map(int, open(0).read().split())

dp = [1] + [0] * (K + 1)
for a in A:
    for i in range(1, K + 1):
        dp[i] += dp[i - 1]
    for i in reversed(range(1, K + 1)):
        dp[i] -= dp[max(0, i - a) - 1]
        dp[i] %= mod

print(dp[K])
### BUGGY CODE ###

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

for i in range(y//10000 + 1):
    for j in range(y//5000 + 1):
        if 10000*i + 5000*j + 1000*(n - i - j) == y:
            if n - i - j >= 0:
                print(i, j, n - i - j)
                exit()

print(-1, -1, -1)

### FIXED CODE ###

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

for i in range(y//10000 + 1):
    for j in range(y//5000 + 1):
        if 10000*i + 5000*j + 1000*(n - i - j) == y:
            if n - i - j >= 0:
                print(i, j, n - i - j)
                exit()

print(-1, -1, -1)
### BUGGY CODE ###

import math
ini = lambda : int(input())
inm = lambda : map(int,input().split())
inl = lambda : list(map(int,input().split()))
gcd = lambda x,y : gcd(y,x%y) if x%y else y
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    return arr
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 divisors
mod = 10**9 + 7

#maincode-------------------------------------------------

n = ini()
a = inl()
ans = 0
for i in range(n-1):
    for j in range(i + 1,n):
        ans += a[i] * a[j]
        ans = ans % mod
print(ans)

### FIXED CODE ###

import math
ini = lambda : int(input())
inm = lambda : map(int,input().split())
inl = lambda : list(map(int,input().split()))
gcd = lambda x,y : gcd(y,x%y) if x%y else y
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    return arr
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 divisors
mod = 10**9 + 7

#maincode-------------------------------------------------

n = ini()
a = inl()
b = a[::]
ans = 0
for i in range(n-2,0,-1):
    a[i] += a[i+1]%mod

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

n=int(input())
a=[int(i)for i in input().split()]
res=[1 for i in range(n)]
for i in range(n):
    res[i]+=a.index(i+1)
print(" ".join(map(str,res)))

### FIXED CODE ###

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

A,B,N = map(int,input().split())
ans = 0
for i in range(N+1):
    ans = max(ans,(A*i)//B-A*(i//B))
print(ans)

### FIXED CODE ###

A,B,N = map(int,input().split())
if N<=B-1:
    x = N
else:
    x = B-1
print((A*x)//B-A*(x//B))