peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
N = int(input())
A = list(map(int, input().split()))
if N == 1:
    print(1)
    quit()

A.append(A[N-1])
ans = 1
last = A[0]
s = 0
for i in range(N-1):
    if not(A[s] <= A[i] <= A[i+1]) and not(A[s] >= A[i] >= A[i+1]):
        s = i + 1
        ans += 1

print(ans)
# Judge status: Wrong Answer
def main():
    S = list(map(str, input().split()))
    T = list(map(str, input().split()))
    
    count = 0
    for i,s in enumerate(S):
        if s != T[i]:
            count +=1
    
    print(count)

if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
*A, = map(int, open(0).read().split())
N = A[0]
visited = [0]*(N+1)

a = A[1]
cnt = 1
while True:
    a = A[a]
    cnt += 1
    if a == 2:
        print(cnt)
        break
    if visited[a]:
        print(-1)
        break
    visited[a] = True
# Judge status: Accepted
N=int(input())

A= [(-2)**i for i in range(40)]
#print(A)
ans=""

for i,num in enumerate(A):
    if N%((-2)**(i+1))==0:
        ans += "0"
    else:
        ans += "1"
        N -= num
    if N==0:
        break
print(ans[::-1])
# Judge status: Accepted
import sys


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    n = ni()
    xy = list(nl() for _ in range(n))

    xpy = [x + y for x, y in xy]
    xmy = [x - y for x, y in xy]

    print(max(max(xpy) - min(xpy), max(xmy) - min(xmy)))


if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
s = input()

dp = [[-1000]*2 for _ in range(len(s)+1)]
dp[0][0] = 0 #D
dp[0][1] = 0 #P

for i in range(len(s)):
  if s[i] == "D":
    dp[i+1][0] = max(dp[i][0]+1,dp[i][1]+2)
  if s[i] == "P":
    dp[i+1][1] = max(dp[i][0],dp[i][1])
  if s[i] == "?":
    dp[i+1][0] = max(dp[i][0]+1,dp[i][1]+2) #Dの時
    dp[i+1][1] = max(dp[i][0],dp[i][1]) #Pの時
    
print(max(dp[len(s)][0],dp[len(s)][1]))
# Judge status: Accepted
s = input()
if s[0]==s[1] or s[1]==s[2] or s[2]==s[3]:
    print('Bad')
else:
    print('Good')
# Judge status: Accepted
import bisect

n = int(input())
A = sorted(list(map(int,input().split())))
ma = A[-1]
half = ma / 2
index = bisect.bisect_left(A,half)

if index != 0:
    ans = A[index-1] if half - A[index-1] <= A[index] - half else A[index]
else:
    ans = A[0]

print(ma,ans)
# Judge status: Wrong Answer
s = input()
if len(s)!=set(s):
  print('yes')
else:
  print('no')
# Judge status: Accepted
n, a, b = map(int, input().split())
ans = n // (a + b) * a
x = n % (a + b)
ans += min(a, x)
print(ans)
# Judge status: Accepted
a,b=list(map(int,input().split()));
hh=False;
if a>9 or b>9:
	hh=True;
if hh:
	print(-1);
else:
	print(a*b);
# Judge status: Wrong Answer
l,r,d=map(int,input().split())
print(r//d-l//r)
# Judge status: Wrong Answer
n = int(input())

def aC2(a):
    ans = 1
    for i in range(3,a+1):
        ans *= i
    return ans
dic = {}
for i in range(n):
    s = list(input())
    s.sort()
    s = ''.join(s)
    if(dic.get(s) is None):
        dic[s] = 1
    else:
        dic[s] += 1

ans = 0
for x in dic.values():
    if(x==0 or x==1):
        continue
    ans += aC2(x)

print(ans)
# Judge status: Accepted
import sys
from collections import Counter
def input(): return sys.stdin.readline().rstrip()
# ----------------------------------------------------------- #

n = int(input())
A = list(int(x) for x in input().split())
A.sort()
counter = Counter(A)
ans = 0
cache = set()
for a in A:
    if a in cache:
        continue
    tmp = a
    while tmp <= 10**6:
        cache.add(tmp)
        tmp += a
    if counter[a] == 1:
        ans += 1
print(ans)
# Judge status: Accepted
N=int(input())
A=[(int(num)-i,i) for i,num in enumerate(input().split(),1)]
b=(sorted(A)[N//2][0])
ans=0
for i in range(N):
    ans += abs(b-A[i][0])
print(ans)
# Judge status: Accepted
N,T=map(int,input().split())
l=[]
for i in range(N):
  c,t=map(int,input().split())
  if t<=T:
    l.append(c)
if len(l)==0:
  print("TLE")
else:
  print(min(l))
# Judge status: Accepted
import sys
a,b,m = map(int,input().split())
ai = list(map(int,input().split()))
bj = list(map(int,input().split()))
#xyc =[]
#for i in range(m):
#    xyc.append(list(map(int,input().split())))
an = min(ai)+min(bj)
for i in range(m):
    x,y,c = map(int,input().split())
    an = min(an,ai[x-1]+bj[y-1]-c)
print(an)
# Judge status: Accepted
n = int(input())
Dict = {}
ans = 0
tmp_list = []
for i in range(n):
    tmp = list(input())
    tmp_list.append(tmp)
tmp_list.reverse()
for i in range(n):
    tmp = tmp_list[i]
    tmp = sorted(tmp)
    tmp = ''.join(tmp)
    if tmp not in Dict.keys():
        Dict[tmp] = 1
    else:
        ans += Dict[tmp]
        Dict[tmp] += 1
print(ans)
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))

count = 0
for i in a:
    if i % 4 == 0:
        count +=2
    elif i %2 == 0 :
        count+=1
    else:
        continue

if len(a)%2 == 0:
    if count >=len(a):
        print("Yes")
    else:
        print("No") 
else:
    if count >= len(a)-1:
        print("Yes")
    else:
        print("No")
# Judge status: Accepted
n = int(input())
h = list(map(int,input().split()))
cnt = 0
ans = 0
for i in range(n-1):
    if h[i] >= h[i+1]:
        cnt += 1
    else:
        ans = max(cnt,ans)
        cnt = 0
    ans = max(cnt,ans)
print(ans)
# Judge status: Wrong Answer
H1, M1, H2, M2, K = map(int, input().split())
print(60 * (H2 - H1) - (M2 - M1) - K)
# Judge status: Accepted
from bisect import bisect

n = int(input())
ma = [-int(input()) for _ in range(n)]

ans = [1] * n
for ai in ma:
    tmp = bisect(ans, ai)
    ans[tmp] = ai
print(sum(num <= 0 for num in ans))
# Judge status: Accepted
#!/usr/bin/env python3

S = input()
print("Yes" if "A" in S and "B" in S else "No")
# Judge status: Wrong Answer
r,g,b = map(int,input().split())

number = r * 100 + g * 10 + b

if number % 4 == 0:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
S=input()
T=input()

l = len(S)

r = 0

for i in range(l):
    if S[i]!=T[i]:
        r = r+ 1

print(r)
# Judge status: Accepted
x = input()
x = int(x)
y1 = x // 11 * 2
p = x % 11
y2 = 0
if p > 0:
  y2 = 1
if p > 6:
  y2 = 2
# print("y1,y2,y=",y1,y2,y1+y2)
print(y1+y2)
# Judge status: Accepted
# -*- coding: utf-8 -*-
N, M, K = map(int, input().split(' '))


for n in range(N+1):
    for m in range(M+1):
        k = n*(M-m) + m*(N-n)
        if k == K:
            print('Yes')
            exit()


print('No')
# Judge status: Wrong Answer
X = input()
Y = X.count("A")
Z = X.count("B")
if (Y == 3 or Z ==3):
  print("Yes")
else:
  print("No")
# Judge status: Accepted
n = int(input())

if n%2 == 1:
  print((n//2) * (n//2+1))
else:
  print((n//2) * (n//2))
# Judge status: Wrong Answer
import numpy as np

X, Y = map(int, input().split())

cranes = np.arange(X+1) * 2
turtles = (np.arange(X+1)*4).reshape(-1,1)

total = cranes + turtles

if np.any(total == Y):
  print('Yes')
else:
  print('No')
# Judge status: Accepted
a,b = input().split(" ")
c = list(map(str,input().split()))
print(c[0][:int(b)-1] + c[0][int(b)-1].lower() + c[0][int(b):])
# Judge status: Accepted
from collections import deque
N,M=map(int,input().split())
haba=[[] for i in range(N+1)]
for i in range(M):
    A,B=map(int,input().split())
    haba[A].append(B)
    haba[B].append(A)
kyori=[-1]*(N+1)
kyori[0]=0
kyori[1]=0

que=deque()
que.append(1)

while que:
    kari=que.popleft()
    for i in haba[kari]:
        if kyori[i]!=-1:
            continue
        kyori[i]=kari
        que.append(i)

ans=kyori[2:]
print("Yes")
for i in range(len(ans)):
    print(ans[i])
# Judge status: Accepted
## coding: UTF-8

N = int(input())


ans = 0

for A in range(1, N+1):
    #rint(A, (N-1)//A)
    ans += (N-1) // A
print(ans)
# Judge status: Accepted
x,y=map(int,input().split())
z=max(x,y)-1
e=max(x,y,z)
if x==y:
    print(2*x)
else:
    print(z+e)
# Judge status: Wrong Answer
S = input()
print(len(set(S))-1)
# Judge status: Accepted
#  --*-coding:utf-8-*--

import bisect

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

Q = []
x = 0

for a in A:
    idx = bisect.bisect_right(Q, -a)

    if idx >= len(Q):
        x += 1
        Q.append(-a)
    else:
        Q[idx] = -a

print(x)
# Judge status: Accepted
# B - Break Number
N = int(input())
print(2**(N.bit_length()-1))
# Judge status: Wrong Answer
nums = []
nums = input().split()
N = int(nums[0])
Y = int(nums[1])
for c in range(N+1) :
    for b in range(N + 1):
        for a in range(N + 1):
            if( Y == 10000 * a + 5000 * b + 1000 *c ):
                break
        else:
            continue
        break
    else:
        continue
    break
if( N < (a + b + c)):
    print("-1 -1 -1")
else :
    print(a,b,c)
# Judge status: Wrong Answer
s = str(input())
a = [0]
l = len(s)
k = 1000000000000
for i in range(l):
  if(s[i]=="<"):
    a.append(a[-1]+1)
  else:
    a.append(a[-1]-1)
  k = min(a[-1],k)
ans = sum(a)
if(k<0):
  ans += (l+1)*abs(k)
print(ans)
# Judge status: Accepted
n = int(input())

print((n+1)//2)
# Judge status: Accepted
N = int(input())
pf={}
m=N
for i in range(2,int(m**0.5)+1):
    while m%i==0:
        pf[i]=pf.get(i,0)+1
        m//=i
if m>1:pf[m]=1

cnt = 0
for k, v in pf.items():
    t = 1
    while v>0:
        v += -1*t
        if v<0:
            break
        cnt += 1
        t+= 1
print(cnt)
# Judge status: Wrong Answer
x,y,z=map(int,input().split())
w=y+2*z
ans=1
while w<x-(y+z):
    w+=y+z
    ans+=1
print(ans)
# Judge status: Wrong Answer
a,b = map(int,input().split())

if a*b % 2 == 0:
  print('Odd')
else:
  print('Even')
# Judge status: Wrong Answer
a, b = map(int, raw_input() .split())
x = ''
for i in range(a):
  x += str(b)
for i in range(b):
  x += str(a)
print x
# Judge status: Accepted
# coding: utf-8
k, x = map(int, input().split())
if 500 * k < x:
    print("No")
else:
    print("Yes")
# Judge status: Accepted
n = int(input())
s = list(input())

alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

for i in range(len(s)):
    s[i] = alpha[(alpha.index(s[i]) + n) % 26]
    
print("".join(s))
# Judge status: Accepted

x=int(input())
j=0

while j==0:
    ans=0
    if x%2==0 and x!=2:
        x+=1
        continue
    for i in range(2,x//2):
        if x%i==0:
            ans+=1
    if ans==0:
        j=x

    x+=1

print(j)
# Judge status: Accepted
def main():
    A, B, C, X, Y = map(int, input().split())

    ans = 1 << 30
    c = 0  # even
    while True:
        j = c // 2
        t = A * max(0, X - j) + B * max(0, Y - j) + C * c
        if ans <= t: break
        ans = t
        c += 2

    print(ans)


if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
from operator import mul
from functools import reduce

mod=pow(10,9)+7

def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom %mod

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

a+=1
ans=0

for i in range(a-b+1):
    ans=(ans+combinations_count(a,b+i))%mod

a-=2

for i in range(a-b+1):
    ans=(ans-combinations_count(a,b+i))%mod
    
print(ans)
# Judge status: Accepted
x, y = map(int, input().split())

count = 0
while x * 2 ** count <= y:
    count += 1

print(count)
# Judge status: Wrong Answer
import numpy as np

D=int(input())
c=[int(i) for i in input().split()]
s=[]
for i in range(D):
    s.append([int(j) for j in input().split()])

t=[i for i in range(D)]
for i in range(D):
    print(t[i])
# Judge status: Wrong Answer
a,b,k = [int(x) for x in input().split()]

lst = []
for i in range(1, 100):
    if (a % i == 0) and (b % i == 0):
        lst.append(i)

lst.reverse()
print(lst[k-1])
# Judge status: Accepted
K = int(input())

from math import ceil

print(ceil(K/2) * ceil((K-1)/2))
# Judge status: Accepted
n = int(input())
import math
ans = 0
for i in range(1, n+1):
    for j in range(1, n+1):
        for k in range(1, n+1):
            tmp = math.gcd(i,j)
            ans += math.gcd(tmp,k)
print(ans)
# Judge status: Accepted
# coding: utf-8

num = int(input())

shain = input().split(" ")
kazu = []
for i in range(len(shain)):
    shain[i] = int(shain[i])
    
for i in range(num):
    kazu.append(0)
    
for j in range(len(shain)):
    kazu[shain[j] - 1] += 1
    
for k in range(num):
    print(kazu[k])
# Judge status: Accepted
x = int(input())
a = x//100
b = x%100
l = list(range(1,6))[::-1]
i = 0
cnt = 0
while b > 0:
  if l[i] > b: i += 1
  cnt += b//l[i]
  b = b % l[i]
print(1 if cnt <= a else 0)
# Judge status: Accepted
S = input()

zero_count=S.count("0")
one_count=S.count("1")

ans=2*min(int(zero_count),int(one_count))
print(ans)
# Judge status: Accepted
n,d = map(int,input().split())
xy = [list(map(int,input().split())) for _ in range(n)]
ans = sum(x*x+y*y<=d*d for x,y in xy)
print(ans)
# Judge status: Accepted
Q, H, S, D = map(int, input().split())
N = int(input())

nS = min(4*Q, 2*H, S)
print(min(N * nS, (N//2)*D + (N%2) * nS))
# Judge status: Accepted
def count_cuts(a, unit):
    return (a + unit - 1) // unit - 1


def is_good(mid, key):
    return sum(count_cuts(a, mid) for a in A) <= key


def binary_search(key):
    bad, good = 0, 1_000_000_000
    while good - bad > 1:
        mid = (bad + good) // 2
        if is_good(mid, key):
            good = mid
        else:
            bad = mid
    return good


N, K, *A = map(int, open(0).read().split())
print(binary_search(K))
# Judge status: Accepted
k=int(input())

mod=[0]*k
c=7
cnt=1

while True:
    if c%k==0:
        print(cnt)
        break
    
    mod[c%k]=1

    c*=10
    c+=7
    c%=k
    cnt+=1

    if mod[c]==1:
        print(-1)
        break
# Judge status: Wrong Answer
n = int(input())

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

ans = 0
for i in range(n):
    check = p[i]
    ans_ = 0
    for j in range(i):
        if p[j] <= p[i]:
            ans_ += 1 
    
    if ans_ == i - 1:
        ans += 0
        
print(ans)
# Judge status: Accepted
import math

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

s1=b//c - (a-1)//c
s2=b//d - (a-1)//d
s12=b//(c*d//math.gcd(c,d)) - (a-1)//(c*d//math.gcd(c,d))
#print(s1,s2,s12)
print(b-a+1-(s1+s2-s12))
# Judge status: Accepted
n = int(input())
print(int(n**.5)**2)
# Judge status: Wrong Answer
import queue

n = int(input())
alp = "abcdefghijklmn"
q = queue.Queue()
q.put("a")
while not q.empty():
    qi = q.get()
    if len(qi) == n:
        print(qi)
    elif len(qi) < n:
        idx = alp.index(qi[-1])
        for i in range(idx+2):
            q.put(qi+alp[i])
# Judge status: Wrong Answer
x = int(input())
ans = x//11 * 2
ans += (x % 11)//6 * 1 + 1
print(ans)
# Judge status: Wrong Answer
s = input()

ans = 0
for i in range(len(s)):
    ans_a = 0
    ans_z = 0
    if (s[i] == "A"):
        ans_a = i
    if (s[-(i+1)] == "Z"):
        ans_z = len(s) - i
    if(ans_z - ans_a + 1 > ans):
        ans = ans_z - ans_a + 1
    
print(ans)
# Judge status: Wrong Answer
n = int(input())
s = input()

for i in range(len(s)):
    a = ord(s[i]) + n%26
    if a <= ord("Z"):
        s = s.replace(s[i], chr(a + 32))
    else:
        s = s.replace(s[i], chr(a + 6))
s = s.upper()
print(s)
# Judge status: Wrong Answer
n=int(input())

div = n
result = 10**12

for i in range(1,n):
  if n % i == 0:
    result = min(result, i+div)
    div = div // i

print(int(result-2))
# Judge status: Wrong Answer
n = int(input())
s = input()
t = input()
if s == t:
    print(n)
else:
    same = 0
    for i in range(n):
        # print(i, s[-1 - i], t[i])
        if s[-1 - i] != t[i]:
            break
        same += 1
    print(2 * n - same)
# Judge status: Wrong Answer
a = list(map(int,input().split()))
difference = 100
for i in range(len(a)):
    if abs(sum(a[:i]) - sum(a[i:])) < difference:
        difference = abs(sum(a[:i]) - sum(a[i:]))
print(difference)
# Judge status: Accepted
S=input()
if S[1-1]=='R':
  if S[2-1]=='R':
    if S[3-1]=='R':
      print(3)
    else:
      print(2)
  else:
    print(1)
elif S[2-1]=='R':
  if S[3-1]=='R':
    print(2)
  else:
    print(1)
elif S[3-1]=='R':
  print(1)
else:
  print(0)
# Judge status: Wrong Answer
N = int(input())
past = []
last = ""
for i in range(N):
    W = input()
    print("past:", past)
    print("W[0]:", W[0])
    print("last[-1]:", last[-1:])
    if last == "":
        past.append(W)
        last = W
    elif W in past or W[0] != last[-1:]:
        print("No")
        exit()
    else:
        past.append(W)
        last = W
print("Yes")
# Judge status: Accepted
H,W,N=map(int,open(0))
L=max(H,W)
print((N+L-1)//L)
# Judge status: Wrong Answer
d = int(input())

print("Christmas"+"Eve"*(25-d))
# Judge status: Accepted
N, K, Q = [int(s) for s in input().split(' ')]
S = [K] * (N + 1)
A = [Q] * (N + 1)
for i in range(Q):
    a = int(input())
    A[a] -= 1

for s, a in zip(S[1:], A[1:]):
    if s - a > 0:
        print('Yes')
    else:
        print('No')
# Judge status: Wrong Answer
n = int(input())
a = sorted(list(map(int,input().split())))
cnt = [a[1],a[0]]
for i in range(1,n):
  a[i] %= cnt[-1]
  if (a[i] != 0) and (a[i] < cnt[-1]):
    cnt.append(a[i])
    cnt.pop(0)
if a[1] == 0:
  print(a[0])
else:
  if cnt[0] % cnt[1] == 0:
    print(cnt[1])
  else:
    print(cnt[0] % cnt[1])
# Judge status: Wrong Answer
s = int(input().replace('/',''))
print('Heisei') if s <= 2019430 else print('TBD')
# Judge status: Accepted
N = int(input())

if N==0:
    print(0)
else:
    answer=[]
    while N != 0:

        if N % (-2) == 0:
            N=N//(-2)
            answer.append(0)
        else:
            N=N//(-2)+1
            answer.append(1)

    print(''.join(list(map(str, reversed(answer)))))
# Judge status: Accepted
A, B, T = map(int, input().split())

cnt = T // A
print(B * cnt)
# Judge status: Wrong Answer
n=int(input())
ans=n*(n-1)/2

print(ans)
# Judge status: Wrong Answer
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = 0
for i in range(n):
    if a[i] < b[i]:
        c += -((a[i]-b[i])//2)
        a[i] += -((a[i]-b[i])//2) * 2
d = 0
for i in range(n):
    if b[i] < a[i]:
        d += a[i]-b[i]
if c == d:
    ans = 1
elif c < d:
    ans = 0
elif d < c:
    if (d-c)%2 == 1:
        ans = 1
    else:
        ans = 0
print(["No","Yes"][ans])
# Judge status: Wrong Answer
a,b,c,x,y=map(int,input().split())
result=[]
if(x>y):
    result.append(a*x+b*y)
    result.append(a*(x-y)+2*c*y)
    result.append(2*c*x)
elif(x<y):
    result.append(a*x+b*y)
    result.append(b*(y-a)+2*c*x)
    result.append(2*c*y)
else:
    result.append(a*x+b*y)
    result.append(2*c*x)
print(min(result))
# Judge status: Accepted
def main():
    a = [int(input()) for i in range(6)]
    if a[4] - a[0] > a[5]:
        print(':(')
    else:
        print('Yay!')
    
if __name__ == '__main__':
    main()
# Judge status: Accepted
import sys
import copy
import math
import bisect
import pprint
import bisect
from functools import reduce
from copy import deepcopy
from collections import deque

if __name__ == '__main__':
    a = int(input())
    ans = a*800 - 200*(a//15)
    print(ans)
# Judge status: Accepted
from collections import Counter

n = int(input())
a = [int(i) for i in input().split()]
q = int(input())
bc = [[int(i) for i in input().split()] for _ in range(q)]

cnt = Counter(a)
s = sum(a)
for b, c in bc:
    s += (c - b) * cnt[b]
    cnt[c] += cnt[b]
    cnt[b] = 0
    print(s)
# Judge status: Wrong Answer
import math
h, a = list(map(int, input().split())) 
print(math.floor(h/a))
# Judge status: Accepted
X = int(input())
if 0 <= X%100 <= 5*(X//100):
    print(1)
else:
    print(0)
# Judge status: Wrong Answer
n = int(input())
s = input()
for i in s:
    if ord(i) + n > 90:
        print(chr(64+n-(90-ord(i))))
    else:    
        print(chr(ord(i)+n))
# Judge status: Accepted
import fractions
A, B = map(int, input().split())
print(int(A * B / fractions.gcd(A, B)))
# Judge status: Accepted
n = int(input())
ans = n
for i in range(n + 1):
    cc = 0
    t = i
    while t > 0:
        cc += t % 6
        t //= 6
    t = n - i
    while t > 0:
        cc += t % 9
        t //= 9
    ans = min(ans, cc)
print(ans)
# Judge status: Wrong Answer
N = int(input())
l = [int(input()) for i in range(N)]
l_sort = sorted(l)

for i in range(N):

    if (l[i] != l_sort[-1]):
        print(l_sort[-2])
    else:
        print(l_sort[-1])
# Judge status: Wrong Answer
N = int(input())
i = 0
C0 = 0
C1 = 0
C2 = 0
C3 = 0
while (i < N):
  i += 1
  S = input()
  if(S == 'AC'):
    C0 += 1
  elif(S == 'WA'):
    C1 += 1
  elif(S == 'TLE'):
    C2 += 1
  elif(S == 'RE'):
    C3 += 1

print("AC ×" +  str(C0))
print("WA ×" +  str(C1))
print("TLE ×" +  str(C2))
print("RE ×" +  str(C3))
# Judge status: Accepted
from itertools import accumulate
def main():
    n=int(input())
    a=list(map(int,input().split()))
    aa=list(accumulate(a))
    mod=10**9+7
    ans=0
    for i in range(n):
        ans += a[i]*(aa[-1]-aa[i])%mod
    print(ans%mod)
    
if __name__ == "__main__":
    main()
# Judge status: Wrong Answer
import math

n = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

print(math.floor(n // min([a,b,c,d,e])) + 4)
# Judge status: Accepted
C = [list(map(int, input().split())) for _ in range(3)]
a = C[1][0]-C[0][0] == C[1][1]-C[0][1] == C[1][2]-C[0][2]
b = C[2][0]-C[0][0] == C[2][1]-C[0][1] == C[2][2]-C[0][2]
if a and b:
    print('Yes')
else:
    print('No')
# Judge status: Wrong Answer
n=int(input())
ct=0
for i in range(1,n+1):
    j=str(i)
    if i%10==0:
        pass
    elif int(j[::-1])==i and len(j)==1:
        ct+=1
        #print(i)
    elif int(j[::-1])<i:
        ct+=2
        #print(i,int(j[::-1]))
    elif int(j[::-1])==i:
        ct+=(len(j)-1)*2+1
        #print(i,(len(j)-1)*2+1)
print(ct)
# Judge status: Wrong Answer


s = input()

s = list(s)


#s = list('PD?D??P')

#print(s)

nagasa = len(s)

for m in range(nagasa):
    for i in s[m]:
        if i == '?':
            s[m] = 'D'
        else:
            pass


print(s)
# Judge status: Accepted
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

from fractions import gcd

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

A -= 1

lcm = C * D // gcd(C, D)

def calc(x):
    count = 0
    count += x // C
    count += x // D
    count -= x // lcm
    return x - count

ans = calc(B) - calc(A)
print (ans)
# Judge status: Wrong Answer
S = input()
T = input()

Slen = len(S)
Tlen = len(T)

if Slen == (Tlen -1) and S[0:Slen-1] == T[0:Slen-1]:print("Yes")
else: print("No")
# Judge status: Accepted
N = int(input())

ans = 1
while ans**2 <= N:
  ans += 1

print((ans-1)**2)
# Judge status: Wrong Answer
# -*- coding: utf-8 -*-
n = int(input())
a = list(map(int, input().split()))
alice = 0
bob = 0
sorted_a = sorted(a)

print(a, sorted_a)

for i in sorted_a:
    alice += sorted_a.pop()
    bob += sorted_a.pop()

print(alice - bob)
# Judge status: Accepted
N = int(input())
A = [int(input()) for _ in range(N)]
first = max(A)
second = sorted(A)[-2]
index = A.index(first)
for i in range(N):
    print(first if i != index else second)
# Judge status: Wrong Answer
import sys

def main():
    input = sys.stdin.readline
    n = int(input())
    a = tuple(map(int,input().split()))
    b = []
    mod = 10**9+7

    for i in range(n-1):
        for j in range(i+1,n):
            b.append((a[i]^a[j])%mod)

    ans = sum(b)
    print(ans)

if __name__ == '__main__':
    main()
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))
a.sort()
furui = [False] * (10**6+1)
ans = 0
for i in range(n):
    if i-1 >= 0 and a[i] == a[i-1]:
        continue
    if furui[a[i]] == False:
        if (i + 1 < n and a[i] != a[i + 1]) or i==n-1:
            ans += 1
        now = a[i]
        while now <= 10**6:
            furui[now] = True
            now += a[i]
print(ans)
# Judge status: Accepted
import math
a, b, n = map(int, input().split())

if n < b:
    x = n
else:
    x = b - 1
print(math.floor(a * x / b) - a * math.floor(x / b))
# Judge status: Accepted
N, M=map(int, input().split())
a=list(map(int, input().split()))
a.sort()

card=[]

for i in range(M):
    b, c=map(int, input().split())
    card.append((c, b))

card.sort(reverse=True)
k=0
for c, b in card:
    while k < N and b > 0:
        if a[k]<c:
            a[k]=c
            b-=1
        k+=1

print(sum(a))