peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N = int(input())
J = [list(map(int, input().split())) for _ in range(N)]
"""
J: [かかる時間, 締め切り時刻]
"""

# print(J)
J = sorted(J, key=lambda x: x[1])
# print(J)

t = 0
for i in range(N):
    t += J[i][0]
    if t > J[i][1]:
        print("No")
        sys.exit()
print("Yes")
# Judge status: Accepted

def calc_next(arr):
	res = []
	for val in arr:
		for j in range(-1, 2):
			add = (val % 10) + j
			if add >= 0 and add <= 9:
				res.append(val * 10 + add)
	return res

k = int(input())
cur = []
A = []

for v in range(1, 10):
	cur.append(v)
	A.append(v)

for d in range(1, 10):
	cur = calc_next(cur)
	for val in cur:
		A.append(val)

print(A[k - 1])
# Judge status: Accepted
N = int(input())
H = list(map(int,input().split()))

count = [0]

for i in range(1,N):
    if H[i-1] >= H [i]:
        count.append(count[-1] + 1)
    else:
        count.append(0)

print(max(count))
# Judge status: Accepted
s=input()[:-1]
while s[:len(s)//2]!=s[len(s)//2:]:
    s=s[:-1]
print(len(s))
# Judge status: Accepted
n,k=map(int,input().split())
print("0"if n%k==0 else "1")
# Judge status: Wrong Answer
n=int(input())
l=[0]*5
for i in range(5):
  l[i]=int(input())
l.sort()
if l[0]>n:
  print(5)
else:
  print(n//l[0]+5)
# Judge status: Wrong Answer
N, x = map(int, input().split())
a = sorted(map(int, input().split()))
cnt = 0
for i in range(N):
  if a[i] < x:
    cnt += 1
    x -= a[i]
  else:
    break
if x > 0:
  cnt -= 1
print(cnt)
# Judge status: Wrong Answer
from inspect import k

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

for i in range(a,b):
    if i % k ==0:
        print('OK')
        break
else:
    print('NG')
# Judge status: Accepted
ans=1
n=int(input())
for i in range(1,n+1):
    ans=i*ans%(10**9+7)
print(ans)
# Judge status: Accepted
def solve():
    n, m = map(int, input().split())
    if n == m == 1:
        print(1)
    elif n == 1:
        print(m-2)
    elif m == 1:
        print(n-2)
    elif n == 2 or m == 2:
        print(0)
    else:
        print((n-2)*(m-2))
    return 0

if __name__ == "__main__":
    solve()
# Judge status: Wrong Answer
N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
for i in range(N-1):
    ans += a[i]
    if sum(a[i+1:])+b[-1] < sum(b[i:]):
        ans += sum(b[i:])
        break
    if i == N-2:
        ans += sum(b[i:])
if N == 1:
    print(a[0]+b[0])
else:
    print(ans)
# Judge status: Accepted
s = input()
n = len(s)
ans = 0
for i in range(n):
    for j in range(i, n):
        ok = True
        for k in range(i, j + 1):
            if s[k] not in ['A', 'T', 'G', 'C']:
                ok = False
        if ok:
            ans = max(ans, j - i + 1)
print(ans)
# Judge status: Accepted
X=int(input())
A=(X//500)
B=((X%500)//5)
print((1000*A)+(5*B))
# Judge status: Accepted
n,q=map(int,input().split())
s=input()
t=[0]*(n+1)
for i in range(n):
	t[i+1]=t[i]+(s[i:i+2]=='AC')
for i in range(q):
	l,r=map(int,input().split())
	print(t[r-1]-t[l-1])
# Judge status: Accepted
A, B = map(int, input().split())

def hcfnaive(x, y): 
  if(y == 0): 
    return x 
  else: 
    return hcfnaive(y, x % y)

def lcm(x, y):
    return (x * y) // hcfnaive(x, y)

print(lcm(A, B))
# Judge status: Accepted
import math

r = int(input())
print(r * math.pi * 2)
# Judge status: Accepted
n,k = list(map(int, input().split()))
p = list(map(int, input().split()))

print(sum(sorted(p)[:k]))
# Judge status: Wrong Answer
k=input()
n=input()

m=len(n)

t=int (k)



if(m<=t):
  print("n")
  
else:
  for i, name in enumerate(n):
    if i==t:
      print("...")
      break
    print(name,end='')
# Judge status: Accepted
N = int(input())
A = list(map(int, input().split()))
MOD = 10**9 + 7
max_digit = 60


result = 0
base = 1
for _ in range(max_digit + 1):
  c0 = 0
  for i in range(N):
    a = A[i] % 2
    A[i] >>= 1
    c0 += (a==0)
  
  result = (result + (base*(N - c0)*c0) % MOD) % MOD
  base = base*2 % MOD

print(result)
# Judge status: Accepted
from sys import stdin
a = int(stdin.readline().rstrip())
print(a+a**2+a**3)
# Judge status: Accepted
A, B, C = map(int, input().split())
ans = C - (A - B)
print(ans) if ans > 0 else print(0)
# Judge status: Accepted
s = input()
a = list(s)

for i in range(len(s)):
    a[i] = 'x'
    
ans = "".join(a)
    
print(ans)
# Judge status: Wrong Answer
from collections import deque
n=int(input())
a=list(input().split())
b=deque()

for i in range(1,n+1):
  if i%2==1:
    b.append(a[i-1])
  else:
    b.appendleft(a[i-1])
print(" ".join(b))
# Judge status: Accepted
K=int(input())
A,B=map(int,input().split())
count=0
for i in range(A,B+1):
  if i%K==0:
    count+=1
if count>=1:
  print("OK")
else:
  print("NG")
# Judge status: Accepted
N, M = map(int, input().split())
A = list(map(int, input().split()))
s = sum(A)

ans = len([a for a in A if a * 4 * M >= s])

print("Yes" if ans >= M else "No")
# Judge status: Accepted
c=input()
boin=["a","e","i","o","u"]
if c in boin:
    print("vowel")
else:
    print("consonant")
# Judge status: Accepted
S = list(input())
num = len(S)
for i in range(num):
    S.pop()
    if S[:len(S)//2] == S[len(S)//2:]:
        print(len(S))
        break
# Judge status: Accepted
H, W=list(map(int,input().split()))
n=(H*W)//2

if H == 1 or W == 1:
    print(1)

elif (H*W) % 2 == 0:
    print(n)
else:
    print(n+1)
# Judge status: Accepted
#Nはお札の枚数、Yは合計金額
N,Y = map(int,input().split())

yukiti = 10000
higuti = 5000
noguti = 1000
re_yukiti = -1
re_higuti = -1
re_noguti = -1

for i in range(N+1):
    for j in range(N+1-i):
        k = N - i - j
        amount = yukiti*i + higuti*j + noguti*k
        if amount == Y:
            re_yukiti = i
            re_higuti = j
            re_noguti = k
            break

print(re_yukiti,re_higuti,re_noguti)
# Judge status: Wrong Answer
def ABC_108_A():
    K = int(input())

    if K%2 == 0:
        print(K/2*K/2)
    else:
        print(int(K/2)*int(K/2)+K-int(K/2)-1)

if __name__ == '__main__':

    ABC_108_A()
# Judge status: Wrong Answer
A = int(input())
B = int(input())
C = int(input())

print(((A+B)*C)/2)
# Judge status: Accepted
N, M = map(int, input().split())

H = list(map(int, input().split()))
F = [1 for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    if H[a] >= H[b]:
        F[b] = 0
    if H[a] <= H[b]:
        F[a] = 0
print(sum(F))
# Judge status: Wrong Answer
a,b,c = map(int, input().split())

A = b - a
B = c - b

if A==B:
    print("Yes")
else :
    print("No")
# Judge status: Wrong Answer
from bisect import bisect_left
from bisect import bisect_right
N = int(input())
A = sorted(map(int, input().split()))
B = list(map(int, input().split()))
C = sorted(map(int, input().split()))
r = 0
for i in range(N):
  pass
print('tle test')
# Judge status: Accepted
s = input()
t = input()

ans = 'UNRESTORABLE'
def test(i):
    for ns, nt in zip(s[i:i+len(t)], t):
        if ns == '?':
            continue
        if ns != nt:
            return False
    return True

for i in range(len(s) - len(t) + 1):
    if test(i):
        re_s = s.replace('?', 'a')
        ans = re_s[:i] + t + re_s[i+len(t):]

print(ans)
# Judge status: Accepted
s = input()
t = input()

max_val = 0
index = 0
for i in range(len(s)- len(t) + 1):
    val = 0
    for c in range(len(t)):
        if s[i + c] == t[c]:
            val += 1
            if val > max_val:
                max_val = val
                index = [i]

print(len(t) - max_val)
# Judge status: Wrong Answer
n = int(input())
s = input()

ans = 0

for i in range(n):
    #複数のリストから共通する要素を抽出
    ans = max(ans, len(set(list(s[:i+1])) & set(list(s[i:]))))
    
print(ans)
# Judge status: Accepted
N,M=map(int,input().split())
LR=[list(map(int,input().split())) for _ in range(M)]

l=1
r=N

for i in LR:
    #print(i)
    if i[0]>l:
        l=i[0]
    if i[1]<r:
        r=i[1]

if r>=l:
    print(r-l+1)
else:
    print(0)
# Judge status: Accepted
S = input()
if S[0] != 'A':
    print("WA")
elif ord(S[1]) < 97:
    print('WA')
elif ord(S[-1]) < 97:
    print("WA")
else:
    cnt = 0
    for i in range(1, len(S)-1):
        if S[i] == 'C':
            cnt += 1
    if cnt == 1:
        print("AC")
    else:
        print("WA")
# Judge status: Accepted
def main():
    N, T = map(int, input().split())
    C = []
    for _ in range(N):
        c, t = map(int, input().split())
        if t <= T:
            C.append(c)
    if len(C) == 0:
        print("TLE")
    else:
        print(min(C))


if __name__ == '__main__':
    main()
# Judge status: Accepted
n,m = [int(x) for x in input().split()]
xy = []
for _ in range(m):
    tmp = [int(x)-1 for x in input().split()]
    xy.append(tmp)

box = {x: 1 for x in range(n)}
red = {x: False for x in range(n)}
red[0] = True

for x,y in xy:
    box[x] -= 1
    box[y] += 1
    if red[x]:
        red[y] = True
    if box[x] == 0:
        red[x] = False

print(len([1 for x in red.values() if x]))
# Judge status: Wrong Answer
n,k = map(int,input().split())
s = input()

s.replace(s[k-1],s[k-1].lower())
# Judge status: Wrong Answer
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
a = list(Counter(a).items())
result = 0
for number, how_many in a:
    result += min(abs(how_many-number), how_many)
print(result)
# Judge status: Accepted
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    k = int(input())
    ans = 1

    if k % 2 == 0 or k % 5 == 0:
        print(-1)
    else:
        a = 7
        while 1:
            if a % k == 0:
                print(ans)
                break
            else:
                a = (a % k) * 10 + 7
                ans += 1
if __name__ == '__main__':
    main()
# Judge status: Accepted
n=int(input())
li = list(map(int, input().split()))

def dup(seq):
    return len(seq) != len(set(seq))

if(dup(li)): 
    print("NO")
else:
     print("YES")
# Judge status: Accepted
S = input()
wdict = ["Sunny","Cloudy","Rainy"]

now = wdict.index(S)
nextw = (now+1) % 3
print(wdict[nextw])
# Judge status: Wrong Answer
import sys
from collections import deque

n = int(input())
a = [0] + [int(sys.stdin.readline()) for _ in range(n)]

button = 1
count = 0

for _ in range(n + 1):
    if button == 2:
        print(count)
        break
    button = a[button]

if count == n:
    print(-1)
# Judge status: Accepted
import itertools

N, M, Q = map(int, input().split())
a = [0] * Q
b = [0] * Q
c = [0] * Q
d = [0] * Q
for i in range(Q):
    a[i], b[i], c[i], d[i] = map(int, input().split())
    a[i] -= 1
    b[i] -= 1

ans = 0
for seq in itertools.combinations_with_replacement(range(1, M+1), N):
    tmp = 0
    for i in range(Q):
        if seq[b[i]] - seq[a[i]] == c[i]:
            tmp += d[i]
    ans = max(ans, tmp)

print(ans)
# Judge status: Accepted
#from math import gcd

from math import factorial as f

from math import ceil,floor,sqrt


import bisect
import re
import heapq


from copy import deepcopy
import itertools

from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

yes = "Yes"
no = "No"

def main():
    n=ii()
    p = li()
    cnt = 0
    for i in range(1,n+1):
        if i!=p[i-1]:
            cnt+=1
    if cnt<=2:
        print('YES')
    else:
        print('NO')



main()
# Judge status: Accepted
#!/usr/bin/env python3

import sys

input = sys.stdin.buffer.readline

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

def lcm(a,b):
    return a*b // gcd(a,b)

def prime_factorize(n):
    pf={}
    for i in range(2, int(n**0.5)+1):
        while n % i == 0:
            pf[i] = pf.get(i, 0) + 1
            n //= i
    if n > 1: pf[n] = 1
    return pf

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

pf = prime_factorize(gcd(A,B))
print(len(pf) + 1)
# Judge status: Wrong Answer
n = input()
a = [list(map(int,raw_input().split())) for i in range(2)]
x = 0
y = 0
total = a[0][0]
while 1:
    right = sum(a[y][i] for i in range(x+1,n))+a[1][n-1] if x < n-1 else 0
    down = sum(a[1][i] for i in range(x,n))
    if right >= down:
        x += 1
        total += a[y][x]
    else:
        total += down
        break
print total
# Judge status: Accepted
a, b=map(int,input().split())
print(a*b if a<10 and b<10 else '-1')
# Judge status: Accepted
N, W = map(int, input().split())

import numpy as np

dp = np.zeros(W + 1, dtype=int)

for i in range(N):
    w, v = map(int, input().split())
    np.maximum(dp[:-w] + v, dp[w:], out=dp[w:])

print(dp[-1])
# Judge status: Accepted
N=int(input())
a=list(map(int,input().split()))
c=[0]*8
sum=0
tmp=0

for i in a:
    n=int(i/400)
    if(i<3200 and c[n]==0):
        c[n]+=1
        sum+=1
    elif(i>=3200):
        tmp+=1
print(sum if sum!=0 else sum+1,sum+tmp)
# Judge status: Accepted
import sys
from fractions import gcd

read = sys.stdin.buffer.read

n,*t = list(map(int, read().split()))

def lcm(t):
  x = t[0]
  for i in range(1, len(t)):
    x = (x*t[i]) // gcd(x, t[i])
  return x

print(lcm(t))
# Judge status: Wrong Answer
S = input()
sl = []
ans = 'AC'

for i in S:
    sl.append(i)
if sl[0] != 'A':
    ans = 'WA'
if sl[2:-1].count('C') != 1:
    ans = 'WA'
    
#print(sl)
#print(sl[2:-1])
print(ans)
# Judge status: Accepted
N = int(input())
A = int(input())
ext = N%500
if ext <= A:
    print('Yes')
else:
    print('No')
# Judge status: Wrong Answer
import numpy as np
from functools import partial
D = int(input())
C = list(map(int, input().split()))
B = np.array([0] * 26)
S = [list(map(int, input().split())) for _ in range(D)]

def calc_satisfaction(d, t):
    B[t-1] = d
    satiety = sum(C * (d - B))
    return S[d-1][t-1] - satiety

satisfaction = 0
for d in range(1, D+1):
    f = partial(calc_satisfaction, d)
    satisfaction += max([t for t in range(1, 27)], key=f)
    print(satisfaction)
# Judge status: Accepted
import bisect
import math

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

am = 0
Bs = []

for _ in range(N):
  a,b = map(int, input().split())
  am = max(am, a)
  Bs.append(b)
  
Bs.sort()
j = bisect.bisect_right(Bs, am)

rlt = 0
for i in range(N-1, j-1, -1):
  H -= Bs[i]
  rlt += 1
  if H <= 0:
    break
    
if H > 0:
  rlt += math.ceil(H/am)
  
print(rlt)
# Judge status: Accepted
from bisect import bisect_right

x = int(input())
l = []

for i in range(2, 10):
    j = 1
    while j ** i <= 1000:
        y = j ** i
        if y not in l:
            l.append(y)
        j += 1

l.sort()
print(l[bisect_right(l, x)-1])
# Judge status: Accepted
x,y = map(int,input().split())
print('Yes' if x*2 <= y <= x*4 and y % 2 == 0 else 'No')
# Judge status: Wrong Answer
s=input()
n=len(s)//2

s1=s[:n]
s2=s[-n:]
s2=s2[::-1]
print(s1)
print(s2)
cnt=0
for i in range(len(s1)):
    if s1[i]!=s2[i]:
        cnt+=1

print(cnt)
# Judge status: Wrong Answer
s=input()
a=[]
for i in range(0,len(s)//2*2,2):
  a.append(s[i:i+2])
a10=a.count('10')
a01=a.count('01')

print(a)

if len(s)%2:
  s1=int(s[-1])
else:s1=-1

if a10>a01:
  if s1==0:
    cnt=len(a)-a10+a01+1
  else:
    cnt=len(a)-a10+a01
elif a01>a10:
  if s1==1:
    cnt=len(a)-a01+a10+1
  else:
    cnt=len(a)-a01+a10
else:
  cnt=len(a)
print(cnt)
# Judge status: Accepted
N, H = map(int, input().split())

w = []
for i in range(N):
  a, b = map(int, input().split())
  w.append((a, 0))
  w.append((b, 1))

w.sort(reverse=True)
ans = 0
for v, t in w:
  if t == 1:
    H -= v
    ans += 1
  else:
    ans += -(-H//v)
    H = 0
  
  if H <= 0:
    break

print(ans)
# Judge status: Accepted
n = int(input())
flg = 0
arr = []*n
arr.append(input())
for i in range(n-1):
  tmp = input()
  if arr[-1][-1] != tmp[0]:
    flg = 1
  if tmp in arr:
    flg = 1
  arr.append(tmp)
if flg == 0:
  print('Yes')
else:
  print('No')
# Judge status: Accepted
n, m = map(int, input().split())
ab = [tuple(map(int, input().split())) for _ in range(n)]
cd = [tuple(map(int, input().split())) for _ in range(m)]

for i in range(n):
    x = 1 << 30
    y = -1
    a, b = ab[i]
    for j in range(m):
        c, d = cd[j]
        d = abs(a - c) + abs(b - d)
        if x > d:
            x = d
            y = j
    print(y + 1)
# Judge status: Accepted
n,m = map(int, input().split())

sc = [tuple(map(int, input().split())) for _ in range(m)]

for i in range(1000):
    
    k = str(i)
    
    if len(k) == n and all([k[s-1]==str(c) for s,c in sc]):
        print(k)
        exit()

print(-1)
# Judge status: Accepted
# A - Weather Prediction

S = str(input())
print('Cloudy' if S == 'Sunny' else 'Rainy' if S == 'Cloudy' else 'Sunny')
# Judge status: Accepted
l = int(input())

a,b,c = l/3,l/3,l/3

print(a*b*c)
# Judge status: Accepted
N, Y = map(int, input().split())
for i in range(Y // 10000 + 1):
  for j in range((Y - 10000 * i) // 5000 + 1):
    if 10000 * i + 5000 * j == Y - 1000 * (N - i - j) and N - i - j >= 0:
      print(i, j, N - i - j)
      exit()
print(-1, -1, -1)
# Judge status: Accepted
N = int(input())
A = list(map(int, input().split()))
ap = 0
xp = 0
xcount = 0

for i in range(N):
    a = A[i]
    x = (ap+xp)-a
    if x <= 0:
        xp = 0
    else:
        xp = x
    xcount = xcount + xp
    ap = a
print(xcount)
# Judge status: Wrong Answer
n=int(input())
p=1
for i in range(1,n+1):
    p=p*i
print(p)
# Judge status: Wrong Answer
word = input()
ans = []
if word.islower() == True and 1 <= len(word) <= 1000:
    j = 0
    for i in word:
        j += 1

    if word[j - 1] != 's':
        ans = word + 's'
    elif word[j - 1] == 's' and j > 1:
        ans = word + 'es'
    print(ans)
# Judge status: Accepted
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    A, B = map(int, readline().split())

    print((A+B) % 24)

if __name__ == '__main__':
    main()
# Judge status: Accepted
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()


def resolve():
    S = list(input())
    ls = len(S)

    rr = [0] * (ls + 1)
    ll = [0] * (ls + 1)

    for i in range(ls):
        if S[i] == '<':
            ll[i+1]=ll[i]+1
    for i in reversed(range(ls)):
        if S[i] == '>':
            rr[i]=rr[i+1]+1


    ans = 0
    for i in range(ls + 1):
        ans += max(ll[i], rr[i])
    print(ans)


resolve()
# Judge status: Accepted
from collections import Counter
def resolve():
    N = int(input())
    A = list(map(int,input().split()))

    B= set(A)

    A.sort()
    dpt = [True]*(A[-1]+1)
    for i in A:
        if dpt[i]==False:
            continue
        for j in range(i*2,A[-1]+1,i):
            dpt[j] = False
    co = Counter(A)
    c=0
    for i,v in dict(co).items():
        if dpt[i] and v==1:
            c+=1
    print(c)
resolve()
# Judge status: Accepted
N, K = map(int, input().split())
print(0 if N % K == 0 else 1)
# Judge status: Accepted
n,k = map(int, input().split())
h = sorted([int(input()) for _ in range(n)])

ans = 0
t = float("inf")
for i in range(n-k+1):
  if abs(h[i+k-1] - h[i]) < t:
    t = abs(h[i+k-1] - h[i])
    ans = i

print(h[ans+k-1] - h[ans])
# Judge status: Accepted
N = int(input())
A = list(map(int, input().split()))
tmp = 0
count = -1
while  tmp < 1:
  for i in range(N):
    if A[i]%2 == 1:
      tmp = 1
    A[i] =int(A[i]/2)
  count = count+1
print(count)
# Judge status: Accepted
import math

a, b = map(int, input().split())
x = math.ceil((a + b) / 2)
print(x)
# Judge status: Accepted
ABC = list(map(int, input().split()))
ABC.sort()
if any(x % 2 == 0 for x in ABC):
    print(0)
else:
    print(ABC[0] * ABC[1])
# Judge status: Wrong Answer
# input
a, b = map(int, input().split())

# check
east = 3
add = 3
while b > east:
    east += add
    add += 1

print(abs(east - b))
# Judge status: Accepted
n = int(input())
a = 0
b = 0
ans = 1000000000
for i in range(1, n):
    a = n - i
    b = n - a
    a = list(map(int,str(a)))
    b = list(map(int,str(b)))
    if sum(a) + sum(b) <= ans:
        ans = sum(a) + sum(b)
print(ans)
# Judge status: Wrong Answer
import math
from scipy.special import comb
mod = 1000000007
N = int(input())

def Solve(N, n, r):
  ans = comb(N, 2, exact=True)*2
  for i in range(r):
    ans = ans * (n - i) % mod
  return ans
  
print(Solve(N,10*(N-2),N-2))
# Judge status: Wrong Answer
a = int(input())
ans = 0

for i in range(a+1):
    if(i % 3 == 0 or i % 5 == 0):
        ans += i
print(ans)
# Judge status: Accepted
# N回だけトレーニングする
import numpy as np
N = int(input())

# パワー
power = 1

# i回目のトレーニングを終えるとパワーが
# i倍されます。
# 答えの値は非常に大きな値になることがあるので
# 10**9+7で割ったあまりを出力

for i in range(1, N + 1):
    power = np.mod(i * power, 10 ** 9 + 7)
print(power)
# Judge status: Accepted
N = int(input())
A = list(map(int,input().split()))

B = [0]
b = 0

mod = 10**9 + 7

for i in range(N):
    b+=A[i]
    b%=mod
    B.append(b)

ans = 0

for i in range(N):
    ans += (mod+B[N]-B[i+1])*A[i]
    ans %= mod

print(ans)
# Judge status: Accepted
X = int(input())
t = 1
while(t*(t+1)//2) < X:
	t += 1
print(t)
# Judge status: Wrong Answer
A, B, C = map(int,input().split())
if C > min(A, B) and C < max(A, B):
  print("YES")
else:
  print("NO")
# Judge status: Accepted
g1 = [1, 3, 5, 7, 8, 10, 12]
g2 = [4, 6, 9, 11]

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

if (x in g1 and y in g1) or (x in g2 and y in g2):
    print("Yes")
else:
    print("No")
# Judge status: Accepted

a,b,c=map(int,input().split())
if b+c<=a:
    print(0)

else:
    print(c+b-a)
# Judge status: Wrong Answer
N=int(input())
S=input()
ans=1
for i in range(N-2):
  ans=max(ans,len(list(set(list(S[:i+1])) & set(list(S[i+1:])))))
print(ans)
# Judge status: Accepted
n = int(input())
b = [int(i) for i in input().split()]

print(b[0] + sum([min(b[i], b[i+1]) for i in range(n-2)]) + b[n-2])
# Judge status: Accepted
A, B, C, X, Y = map(int,input().split())
if A + B <= 2 * C:
    ans = A * X + B * Y
elif 2 * C <= A and 2 * C <= B:
    ans = 2 * C * max(X, Y)
elif 2 * C <= A:
    ans = 2 * C * X + B * max(0, Y - X)
elif 2 * C <= B:
    ans = 2 * C * Y + A * max(0, X - Y)
else:
    if X < Y:
        ans = 2 * C * X + B * (Y - X)
    else:
        ans = 2 * C * Y + A * (X - Y)
print(ans)
# Judge status: Accepted
x = input()
ans = 0
s_count = 0
for i in range(len(x)):
    if x[i] == 'S':
        s_count += 1
    else:
        if s_count > 0:
            ans += 1
            s_count -= 1
print(len(x) - ans*2)
# Judge status: Wrong Answer
S = list(input())
ACGT = ["A", "C", "G", "T"]
count = 0
Max = 0
for s in S:
    if s in ACGT:
        count += 1
    else:
        if count > Max:
            Max = count
        count = 0
print(Max)
# Judge status: Wrong Answer
n,k = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
M = max(A)
m = min(A)
def calc(r):
    return pow(2,r-1)-1
l,r = 1,M
cnt = 0
import math
while l<r:
    cnt = 0
    mid = (l+r)//2
    for a in A:
        cnt += a//mid
    if cnt <=k:
        r = mid-1
    else:
        l = mid+1
print(l)
# Judge status: Accepted
n=int(input())
for i in range(1,10000):
    num=2**i-1
    if n<=num:
        print(num)
        break
# Judge status: Wrong Answer
menu=[int(input()) for i in range(5)]
fir_digi=[menu[i]%10 for i in range(5)]
for i in range (5):
    if i!=fir_digi.index(min(fir_digi)) and fir_digi[i]!=0:
            menu[i]=int(menu[i]/10)*10+10
print(sum(menu))
# Judge status: Accepted
A, B = [int(_) for _ in input().split()]
if A%3 == 0 or B%3 == 0 or (A + B)%3 == 0:
  print('Possible')
else:
  print('Impossible')
# Judge status: Accepted
import sys

input = sys.stdin.readline

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

check = set([W[0]])
flag = True
before = W[0][-1]
for i in range(1, N):
    if before != W[i][0] or W[i] in check:
        flag = False
        break
    else:
        before = W[i][-1]
        check.add(W[i])

if flag:
    print('Yes')
else:
    print('No')
# Judge status: Wrong Answer
a=int(input())

print(a*3.14159265358979)
# Judge status: Accepted
n=int(input())
l=[2,1]
for i in range(2,n+1):
    l_next=l[-2]+l[-1]
    l.append(l_next)
print(l[n])
# Judge status: Accepted
a,b,c = map(int,input().split())
print(max(0,(c-(a-b))))
# Judge status: Accepted
n = int(input())
s = input()
ans = s
l,r = 0,0
for p in s:
  if p =='(':
    l += 1
  else:
    r += 1
  if r>l:
    ans = '('+ans
    l += 1
print(ans+')'*(l-r))
# Judge status: Accepted
import math
sq=math.sqrt(int("".join(input().split())))
print("Yes" if sq.is_integer() else "No")