peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
import collections
N =int(input())
A = list(map(int, input().split()))

k=0
t=1
a=collections.Counter(A)
for i in range(1,N+1):
    print(a[i])
# Judge status: Wrong Answer
N,M = map(int,input().split())

d = {}
for _ in range(N):
    A,B = map(int,input().split())
    d[A] = B

res = 0
cnt = 0
for i in sorted(d):
    if(d[i] <= M):
        res += d[i]*i
        M -= d[i]
    elif(M > 0):
        res += M * i
        break
    else:
        break
print(res)
# Judge status: Wrong Answer
n, m = map(int, input().split())
answered = [False] * n
ans = 0
pena = 0
for _ in range(m):
    p, s = input().split()
    pidx = int(p) - 1
    if answered[pidx]:
        continue
    if s == "AC":
        ans += 1
        answered[pidx] = True
    else:
        pena += 1
print("{} {}".format(ans, pena))
# Judge status: Wrong Answer
A,B=map(int,input().split())
num=1
for i in range(1,max(A,B)+1):
    if A%i==0 and B%i==0:
        num*=i
print(int(A*B/num))
# Judge status: Wrong Answer
n=int(input())
ans='No'
a=sorted([list(map(int,input().split())) for i in range(n)],key=lambda x:x[1])
for i in range(n):
  if sum(a[:i+1][0])<a[i][1]:ans='Yes'
  else:ans='No'
#ans=['Yes' if sum(a[:i+1][0])<a[i][1] else 'No' for i in range(n)]
print(ans)
# Judge status: Accepted
a = list(map(int, input().split()))
if max(a)*2 == sum(a):
    print("Yes")
else:
    print("No")
# Judge status: Accepted
N = int(input())
ans = 0

for i in range(1, N):
    ans += (N - 1) // i

print(ans)
# Judge status: Wrong Answer
n = int(input())


def modpow(x, y):
    mod = 1000000007
    res = 1
    for i in range(y):
        res = res * x % mod
    return res


ten = modpow(10, n)
nine = modpow(9, n)
eight = modpow(8, n)

ans = ten - nine - nine + eight


print(ans)
# Judge status: Accepted
sx,sy,tx,ty=map(int,input().split())
tx=tx-sx
ty=ty-sy
sx=0
sy=0
ans=[]
def add(num,d):
    global ans
    di=["U","D","L","R"]
    for i in range(num):
        ans.append(di[d])
y=ty-sy
x=tx-sx
add(y,0)
add(x,3)
add(y,1)
add(x,2)
add(1,2)
add(y+1,0)
add(x+1,3)
add(1,1)
add(1,3)
add(y+1,1)
add(x+1,2)
add(1,0)
print("".join(ans))
# Judge status: Accepted
k=int(input())
print(int(k/2)*int((k+1)/2))
#Source code should be longer than 50 charactersSource code should be longer than 50 charactersSource code should be longer than 50 charactersSource code should be longer than 50 charactersSource code should be longer than 50 charactersSource code should be longer than 50 charactersSource code should be longer than 50 charactersSource code should be longer than 50 charactersSource code should be longer than 50 charactersSource code should be longer than 50 characters
# Judge status: Accepted
N=int(input())
L=list(map(int,input().split()))
l=[0 for i in range(N)]
for i in range(N):
  l[L[i]-1]=i+1
print(' '.join(map(str, l)))
# Judge status: Wrong Answer
n=int(input())
a=[]
b=[]
for _ in range(n):
  A,B=map(int,input().split())
  a.append(A)
  b.append(B)
q=sorted(a)
w=sorted(b)
w=list(reversed(w))
p=n//2
if n%2==1:
  e=q[p]
  r=w[p]
  t=r-e+1
else:
  e=q[p-1]
  r=w[p-1]
  t=r-e
  print(2*t-1)
# Judge status: Accepted
from itertools import combinations_with_replacement as C

X = int(input())
mono = [100, 101, 102, 103, 104, 105]
ans = 0
if X >= 2000:
    ans = 1
else:
    for i in range(1, 19 + 1):
        L = list(C(mono, i))
        for L in L:
            if sum(L) == X:
                ans = 1
                break

print(ans)
# Judge status: Accepted
n_k = list(map(int,input().split()))
chr_lr = list(input())
cnt_rl = 0
cnt_con = 0

for i in range(n_k[0]-1):
  if(chr_lr[i] == chr_lr[i+1]):
    cnt_con += 1

sum = min(cnt_con + 2*n_k[1],n_k[0]-1)
print(sum)
# Judge status: Wrong Answer
n,k=map(int,input().split())
temp={}
a=[0]*n
for i in range(n):
  at,bt=map(int,input().split())
  temp[at]=bt
  a[i]=at
a.sort()
cnt=0
for i in range(n):
  cnt=cnt+temp[a[i]]
  if cnt>=k:
    print(a[i])
    break
# Judge status: Wrong Answer
N, A, B = map( int, input().split() )

if ( A + B ) % 2 == 0:
  print( (abs( A - B ) + 1) // 2 )
else:
  print( min( max( A, B ) - 1, max( N - A, N - B ) - 1 ))
# Judge status: Wrong Answer
s = str(input())

count = 0

for i in range(len(s)+1):
    for j in range(len(s)+1):
        if i < j:
            if int(s[i:j]) % 2019 == 0:
                print(s[i:j])
                count += 1
print(count)
# Judge status: Accepted
ABC = list(map(int, input().split()))
ABC.sort(reverse=True)
max_val = ABC[0]
second_max_val = ABC[1]
ans = max_val - second_max_val
min_val = ABC[2] + ans
diff = max_val - min_val
if diff % 2 == 0:
    ans += diff // 2
else:
    ans += diff // 2 + 2
print(ans)
# Judge status: Wrong Answer
n = int(input())
a = sorted(map(int, input().split()))
p = a[-1]
b =10000000
c = 0
for i in range(n-1):
  if abs(a[i]-p/2) < b:
    b = abs(a[i]-p/2)
    c = a[i]
  else:
    break
print(p,c)
# Judge status: Accepted
K = int(input())
A,B = map(int,input().split())

for i in range(1,1000):
    x = K * i
    if A <= x <= B:
        print('OK')
        exit()
    else:
        continue

print('NG')
# Judge status: Accepted
A, B, C, D =map( int, input().split() )

takahashi_win = False
while (A > 0) and ( C > 0 ):
    C -= B
    if C <= 0:
        takahashi_win = True
    A -= D
if takahashi_win:
    print('Yes')
else:
    print('No')
# Judge status: Accepted
H,N = map(int, input().split())
A = list(map(int, input().split()))

if sum(A)>=H:
    print('Yes')
else:
    print('No')
# Judge status: Wrong Answer
*l, n = map(int, open(0).read().split())
c = 0
for i, j in sorted([j*2**(2-i), 2**(i-2)] for i, j in enumerate(l)):
  t = n//j*j
  c += i*t
  n -= t
  if not n:
    print(int(c))
    exit()
# Judge status: Accepted
import math
n = int(input())
print(360*n//math.gcd(360,n)//n)
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))

# n_C_rの最大化
# nは出来るだけ大きい方が良く、rは出来るだけn/2に近い方が良い

# n>rという条件があるので、サンプル２では(100,100)は許されない
#
x = max(a)
y = float("inf")
for ai in a:
    if abs(x / 2 - ai) < abs(x / 2 - y) and ai < x:
        y = ai
print(x, y)
# Judge status: Accepted
from collections import Counter

n = int(input())
s = [None] * n
for i in range(n):
    s[i] = input().rstrip()

m = int(input())
t = [None] * m
for i in range(m):
    t[i] = input().rstrip()

ctr = Counter(s) - Counter(t)
if ctr:
    print(ctr.most_common(1)[0][1])
else:
    print(0)
# Judge status: Accepted
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(a: int, b: int, h: int):
    print(h*(a+b)//2)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    a = int(next(tokens))  # type: int
    b = int(next(tokens))  # type: int
    h = int(next(tokens))  # type: int
    solve(a, b, h)


if __name__ == '__main__':
    main()
# Judge status: Accepted
N,M=map(int,input().split())
A=[[] for i in range(N)]
for i in range(M):
  a,b=map(int,input().split())
  A[a-1].append((b,i))
ans=[0]*M
for i in range(N):
  d=sorted(A[i])
  n=len(d)
  for j in range(n):
    a,b=d[j]
    D=str(i+1)
    E=str(j+1)
    r=D.zfill(6)+E.zfill(6)
    ans[b]=r
for i in ans:
  print(i)
# Judge status: Accepted
N = int(input())
lisAB = [list(map(int,input().split())) for _ in range(N)]

ans = 0
for A,B in lisAB[::-1]:
    if (A+ans)%B == 0:
        continue
    else:
        num = B - (A+ans)%B
        ans += num

print(ans)
# Judge status: Wrong Answer
line2 = []
for i in range(5):
    line = int(input())
    line2.append(line)
long = int(input())
if line2[4] - line2[0] <= long:
    print("Yey!")
else:
    print(": (")
# Judge status: Accepted
import math
N = int(input())
listA = []
for i in range(5):
    listA.append(int(input()))
print(math.ceil(N / min(listA)) + 4)
# Judge status: Wrong Answer
A = int(input())
B = list(map(int,input().split(" ")))
memory = 1
for i in range(A):
    if B[i] == memory:
        memory += 1
    else:
        continue
print(A-(memory-1))
# Judge status: Accepted
def solve():
    N = int(input())
    A = list(map(int, input().split()))

    sum_a = 0
    tmp = 0
    
    for i in range(N-1):
        tmp += A[i]
        sum_a += tmp * A[i+1]

  #  print(sum_a)

    ans = sum_a % 1000000007

    print(ans)


if __name__ == "__main__":
    solve()
# Judge status: Accepted
X,Y = map(int, input().split())
ans = 0
while X <= Y:
    ans += 1
    X <<= 1
print(ans)
# Judge status: Wrong Answer
import sys

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

#if k==1:
 #   print('Ok')      
#    sys.exit() 

wk = (a//k)
while wk*k <=b:
    print('Ok')  
    sys.exit()    
    wk+=1

print('NG')
# Judge status: Accepted
s = input()
t = input()
cs = []
ct = []
for i in range(97,97+26):
  cs.append(s.count(chr(i)))
  ct.append(t.count(chr(i)))
if sorted(cs) == sorted(ct):
  print("Yes")
else:
  print("No")
# Judge status: Accepted
x=int(input())

a,b=divmod(x,11)

ans=0+a*2

if b==0:
  pass
elif b>6:
  ans+=2
else:
  ans+=1
  
print(ans)
# Judge status: Accepted
n = int(input())
a = [int(input()) for _ in range(n)]

flag = [True]*n
t = a[0]
ans = 1
while t != 2:
  if flag[t-1]:
    flag[t-1] = False
    t = a[t-1]
    ans += 1
  else:
    print(-1)
    exit()
print(ans)
# Judge status: Wrong Answer
N = int(input())
A = list(map(int,input().split()))

A.sort(reverse = True)
ans = A[0]+A[1]

for i in range(2,N-1):
  ans += max(A[i],A[i-1])
print(max(ans,sum(A[:-1])))
# Judge status: Accepted
S = input()

N = len(S)

def func(S,ans,N):
    for i in range(N):
        if S[i] != S[N - i-1]:
            ans ='No'
    return (ans)

ans = func(S, 'Yes',(len(S)-1//2))
S1 = S[(N+3)//2-1:N]
ans = func(S1, ans,len(S1))

print(ans)
# Judge status: Accepted
X,Y = map(int,input().split())
if X%Y == 0:
  print(-1)
else:
  print(X*(Y-1))
# Judge status: Accepted
mi = lambda : map(int, input().split())

w, h, x, y = mi()

s = w*h

if 2*x == w and 2*y == h:
    hantei = 1
else:
    hantei = 0

print(*[s/2, hantei])
# Judge status: Accepted
N, K = map(int, input().split())
count = 0

while N >= K ** count:
  count += 1

print(count)
# Judge status: Accepted
def main():
    date = list(str(input()))
    date[3] = '8'
    ans = ''
    for i in date:
        ans = ans + i
    print(ans)

main()
# Judge status: Wrong Answer
a,b,c,d=map(int, input().split())

print("Yes" if abs(a-c)<d or abs(a-b)<d and abs(b-c)<d else "No")
# Judge status: Accepted
n,x=map(int,input().split())
l=list(map(int,input().split()))
l=sorted(l)
ans=0
for i in l:
    x-=i
    ans+=1
    if x<0:
        break
if x!=0 and ans>0:    
    print(ans-1)
else:
    print(ans)
# Judge status: Accepted
import sys
input = sys.stdin.readline

import numpy as np

def main():
  MOD = 10**9+7
  n = int(input())
  A = np.array(input().split(), dtype=np.int64)
  ans = 0
  for j in range(61):
    X = A>>j & 1
    t = np.count_nonzero(X)
    ans += pow(2, j, MOD) * t * (n-t) % MOD
  print(ans%MOD)
  
if __name__ == "__main__":
  main()
# Judge status: Accepted
N,M  = map(int, input().split())
balls = [1]*(N+1)
reds = [False]*(N+1)
reds[0] = True
for i in range(M):
    x,y = map(int, input().split())
    x -= 1
    y -= 1
    balls[x] -= 1
    balls[y] += 1
    if reds[x]:
        reds[y] = True
    if balls[x] == 0:
        reds[x] = False

print(sum(reds))
# Judge status: Wrong Answer
def notprime(n):
    for i in range(2,int(n**0.5)):
        if n%i==0:
            return True
    return False

n = int(input())
if 1<=n<=81:
    if n%10==0:
        print('Yes' if n==10 else 'No')
    else:
        print('Yes' if notprime(n) else 'No')

else:
    print('No')
# Judge status: Wrong Answer
n=int(input())
ans=[]
mins=55
a=[list(input()) for _ in range(n)]
for i in range(n):
  if mins > len(a[i]):
    mins=min(mins,len(a[i]))
    m=i
for i in a[m]:
  flg=0
  for j in a:
    if i not in j:
      flg=1
  if flg==0:
    ans.append(i)
ans.sort()
print(*ans,sep='')
# Judge status: Wrong Answer
from collections import Counter

N,*A = map(int,open(0).read().split())
#j - i = Aj + Ai
#j - Aj = Ai + i
#L = i + Ai, R = j - Aj とおく
L = []
R = []
for i in range(N):
    L.append(i+1 + A[i])
    R.append(i+1 - A[i])
l = Counter(L)
r = Counter(R)
 
cnt = 0
a=[]
for i in range(1,N+1):
    if i in l and i in r:
        cnt += max(l[i], r[i])
        a.append(i)
print(cnt)
# Judge status: Wrong Answer
N = int(input())
count =0.01
count = int(N*(N-1)/2)
print(int(count))
# Judge status: Wrong Answer
x=int(input())
i=1
if x==0:
    print(0)
else:
    while True:
        if (i-2)*(i-1)/2+1<=x+1<=i*(i-1)/2:
            break
        i+=1
    print(i-1)
# Judge status: Wrong Answer
from collections import Counter
import sys

s = sys.stdin.readlines()
n = int(s[0][:-1])

dct={}
cnt = 0
for i in range(1, n):
  if s[i][:-1] not in dct.keys():
    dct[s[i][:-1]] = 1
    cnt += 1

if n > 1:
  if s[n] not in dct.keys():
    dct[s[n]] = 1
    cnt += 1


print(cnt)
# Judge status: Wrong Answer
N = int(input())
A = list(input())
SET_A = set(A)
if len(A)==len(SET_A):
    print("YES")
else:
    print("NO")
# Judge status: Accepted
from collections import defaultdict
S = input()
d = defaultdict(int)
for i in range(len(S)):
  d[S[i]] += 1
for val in d.values():
  if val != 1:
    print("no")
    exit()
print("yes")
# Judge status: Wrong Answer
ans = ""

N = int(input())

for i in range(10000):
    tmp = N%26
    ans += chr(96+tmp)
    N //= 26

    if N <= 0:
        break

print(ans[::-1])
# Judge status: Accepted
# -*- coding: utf-8 -*-
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
A = list(map(int,readline().split()))
for i in range(N):
    A[i] -= (i+1)
A = sorted(A)
k = N // 2 
b = A[k]
ans = 0
for i in range(N):
    ans += abs(A[i]-b)
print(ans)
# Judge status: Wrong Answer
H = int(input())
W = int(input())
N = int(input())

ans = 0
num_bk = 0
for i in range(0,min(H,W)+1):
  num_bk += max(H,W)
  ans +=1
  if num_bk>N:
    print(ans)
    break
# Judge status: Wrong Answer
d, n = map(int, input().split())
print(n * (100 ** d))
# Judge status: Accepted
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())
    a = [list(map(int, input().split())) for _ in range(2)]

    max = 0

    for i in range(n):
        tmp = 0
        for j in range(i + 1):
            tmp += a[0][j]
        for j in range(i, n):
            tmp += a[1][j]

        if tmp > max:
            max = tmp

    print(max)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()
# Judge status: Accepted
import math
a,b=map(int,input().split())
ans=-1
tmp=b*10
for x in range(tmp-20,tmp+20):
    if math.floor(x*0.08)==a and math.floor(x*0.10)==b:
        ans=x
        break
print(ans)
# Judge status: Wrong Answer
if __name__ == '__main__':
    a = int(input())
    s = input()
    count =0
    for i in s:
        if i == "I":
            count +=1
        else:
            count -=1
    print(count)
# Judge status: Accepted
import sys

def solve():
    A, B, C, D = [int(i) for i in input().split()]
    ans = sys.maxsize * -1
    X = [0, A, B] if A <= 0 <= B else [A, B]
    Y = [0, C, D] if A <= 0 <= B else [C, D]
    for x in X:
        for y in Y:
            ans = max(ans, x * y)
    print(ans)

if __name__ == "__main__":
    solve()
# Judge status: Wrong Answer
D, T, S = map(int, input().split())
if(T*S>D): 
  print('YES')
if(T*S<=D): 
  print('NO')
# Judge status: Accepted
max_len = int(input())
s = input()

if len(s) > max_len:
    print(f"{s[:max_len]}...")
else:
    print(s)
# Judge status: Wrong Answer
b = int(input())

list = [7]
for i in range(b):
    list.append(list[-1]*10 +7)

for l in range(b%10, len(list)):
    if list[l] % b == 0:
        print(b%10 + l)
        exit()
# Judge status: Accepted
# from decimal import Decimal
a, b, c = map(int, input().split())
print(b//c - a//c if a%c != 0 else b//c - a//c +1)
# Judge status: Accepted
import math
N = int(input())
count = 0
ans = 0
for i in range(N+1):
    money = 0
    money = math.floor(i*1.08)
    if money == N:
        count += 1
        ans = i
        break
if count == 0:
    print(":(")
else:
    print(ans)
# Judge status: Wrong Answer
x= input()
if x==0:
  print(1)
elif x==1:
  print(0)
# Judge status: Accepted
K,X = map(int,input().split())
print('Yes' if X <= K*500 else 'No')
# Judge status: Accepted
n=[input() for _ in range(int(input()))]
m=[input() for _ in range(int(input()))]
l=list(set(n))
print(max(0,max(n.count(l[i])-m.count(l[i]) for i in range(len(l)))))
# Judge status: Accepted
n=int(input())
b=list(map(int,input().split()))
ans=0
w=max(b)
a=[0]*(w+1)
for i in b:
  x=i
  while x<=w:
    a[x]+=1
    x+=i
for i in b:
  if a[i]==1:
    ans+=1
print(ans)
# Judge status: Accepted
import sys
C = [list(map(int,input().split())) for _ in range(3)]

for j in range(2):
    for i in range(2):
        if C[i+1][j+1]-C[i+1][j]!=C[i][1+j]-C[i][j]:
            print('No')
            sys.exit()

print('Yes')
# Judge status: Wrong Answer
S=input()
if S[2]==S[3] and S[4]==S[5]:
  print("yes")
else:
  print("No")
# Judge status: Accepted
import sys
from collections import deque


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


S = input()
Q = int(input())
q = deque(S)
flipped = False
for _ in range(Q):
    q_t, *q_d = input().split()
    if q_t == "1":
        flipped = not flipped
    else:
        F, C = q_d
        if (not flipped and F == "2") or (flipped and F == "1"):
            q.append(C)
        else:
            q.appendleft(C)

ans = list(q)
if flipped:
    print("".join(ans[::-1]))
else:
    print("".join(ans))
# Judge status: Accepted
import itertools

n = int(input())
p = [[0 for i in range(2)] for j in range(n)]

for i in range(n):
  p[i][0],p[i][1] = map(int,input().split())
#print(p)

def dis(a,b):
  dis = (a[0]-b[0]) ** 2 + (a[1]-b[1]) **2
  return dis ** (1/2)


perm = [i for i in range(n)]
total = 0 
num = 0
for v in itertools.permutations(perm,n):
  path = 0
  for i in range(n-1):
    path += dis(p[v[i]],p[v[i+1]])
  num += 1
  total += path
print(total/num)
# Judge status: Wrong Answer
S = list(input())

cnt = 0

if len(S)%2 == 0:
  for i in range(0,int(len(S)/2+1)):
    if S[i] != S[-1-i]:
      cnt +=1
else:
  for i in range(0,int(len(S)/2)):
    if S[i] != S[-1-i]:
      cnt +=1

print(cnt)
# Judge status: Wrong Answer
n = int(input())
s = str(input())

ans = ""
index = 0


left = 0
right = 0


for i in range(n):
    if s[-i-1] == ")":
        index = n - i 
        break

lis = s[:index]
left = lis.count("(") 
right = lis.count(")") 
if right >= left:
    ans += "(" * (right-left) + s + ")" * (n-index)
else:
    ans += s + ")" * (left-right) + ")"  * (n-index)


print(ans)
# Judge status: Wrong Answer
import sys
stdin = sys.stdin
import itertools

mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))

N = ni()
A = list()
for _ in range(N):
    A.append(ni())
cnt = 0
for i in range(N-1):
    ccnt = (A[i] + A[i+1]) //2
    A[i+1] -= max(0, ccnt*2 - A[i])
    A[i] = 0
    cnt += ccnt
print(cnt)
# Judge status: Accepted
n = int(input())
ans = 0

for i in range(1,n+1):
    ans += (i + (n//i)*i) * (n//i) // 2
    
print(ans)
# Judge status: Accepted
a, b = map(int, input().split())
if a > 12:
    print(b)
elif 6 <= a <= 12:
    print(b//2)
elif 0 <= a <= 5:
    print(0)
# Judge status: Wrong Answer
w, a, b = list(map(int, input().split()))
diff = b - a - w
print(max([diff, 0]))
# Judge status: Wrong Answer
N = int(input())
lst = [int(input()) for _ in range(5)]

#print(lst)
#print(min(lst),N//min(lst))
if min(lst) > N:
    print(5)
else:
    print(N//min(lst)+5)
# Judge status: Accepted
S = list(input())
# i = 2
while S != []:
    S.pop()
    S.pop()
    l = len(S)
    half = int(l / 2)
    # print(S)
    # print(S[0:half])
    # print(S[half:])
    if S[0:half] == S[half:]:
        print(l)
        exit()
# Judge status: Wrong Answer
n, k = map(int,input().split())
r, s, p = map(int,input().split())
l = list(input())
ans = 0

def jan(a):
  if a == "r":
    return p
  elif a == "s":
    return r
  return s

for i in range(len(l)):
  if i<k:
    ans += jan(l[i]) 
  elif l[i] != l[i-k]:
    ans += jan(l[i])
print(ans)
# Judge status: Accepted
N=int(input())
a=N//11
ans=2*a
b=N-11*a
if 0<b<=6:
  ans+=1
elif 6<b<=10:
  ans+=2
print(ans)
# Judge status: Wrong Answer
import math


ans = 0
N, K = map(int, input().split())
dp = [[0] * (2*K + 1) for _ in range(int(math.log2(K)) + 2)]
for i in range(1, N + 1):
    if i < 2*K + 1:
        dp[0][i] = 1 / N
    else:
        ans += 1 / N
for cnt in range(1, int(math.log2(K)) + 2):
    for now in range(1, 2*K + 1):
        if now % 2 == 0:
            dp[cnt][now] = dp[cnt - 1][now//2] * 0.5
    ans += sum(dp[cnt][K:])
#print(dp)
print(ans)
# Judge status: Accepted
#!/usr/bin/python

from sys import stdin
from keyword import iskeyword

if __name__ == "__main__":
    n = int(input())
    if n % 9 == 0:
        ret = "Yes"
    else:
        ret = "No"
    print(ret)
# Judge status: Wrong Answer
def solve():
    number=int(input())
    items=[]
    for i in range(number):
        item=input()
        items.append(item)
    count=1
    for i in range(1,number):
        if items[i]!=items[i-1]:
            count+=1
    print(count)

    return
solve()
# Judge status: Wrong Answer
N,M = map(int,input().split())
if N == 1 and M == 1:
    print(0)
elif N == 1 or M == 1:
    print(max(N,M)-2)
else:
    print((N-2)*(M-2))
# Judge status: Wrong Answer
a, b = [int(x) for x in input().split()]
cs = [int(x) for x in input().split()]
print(a, b)
print(cs)
cs.sort()

print(sum(cs[:b]))
# Judge status: Accepted
n = int(input())

dp = [False]*110
dp[4] = dp[7] = True

for i in range(101):
  if dp[i]:
    dp[i+4] = True
    dp[i+7] = True
  
if dp[n]:
  print("Yes")
else:
  print("No")
# Judge status: Accepted
import math
a,b,x = map(int,input().split())
if x>=a*a*b*0.5:
    theta = math.degrees(math.atan(2*(a*a*b-x)/a**3))
else:
    theta = math.degrees(math.atan(0.5*a*b*b/x))
print(theta)
# Judge status: Accepted
N = int(input())
M = list(map(int, input().split()))
M = [bin(m)[2:] for m in M]
max_len = max([len(m) for m in M])
M = ["0"*(max_len-len(m))+m for m in M]
MOD = 10**9+7
result = 0
for i in range(1, max_len+1):
  zero = len([m[-i] for m in M if m[-i]=="0"])
  one = len(M) - zero
  #print(one, zero, i)
  result += (((one * zero) % MOD) * ((2 ** (i-1)) % MOD) % MOD)
  result %= MOD
print(result)
# Judge status: Accepted
import collections
import sys
import numpy as np
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
MOD = 10**9+7
import itertools
import math

a,b,c,d = map(int,input().split())
i = 0
cnt1 = 0
while True:
    if a<=0:
        break
    cnt1+=1
    a -= d
cnt2 = 0
while True:
    if c<=0:
        break
    cnt2+=1
    c -= b
if cnt1<cnt2:
    print("No")
else:
    print("Yes")
# Judge status: Wrong Answer
S = input()
key = 'keyence'
if 'keyence' in S:
    print('YES')
else:
    ans = 'NO'
    for i in range(1,6):
        f = key[:i]
        if S[:i] == f:
            if key[i:][::-1] == S[::-1][:7-i]:
                ans = 'YES'
                break
    print(ans)
# Judge status: Wrong Answer
t = input()
t = t.replace('?', 'P')
t = list(t)
for i in range(1, len(t)):
  if t[i-1] == 'P' and t[i] == 'P':
    t[i] = 'D'
print(''.join(t))
# Judge status: Accepted
n=int(input())
lst=set()
for i in range(n):
    lst.add(input())
print(len(lst))
# Judge status: Wrong Answer
from scipy.special import comb
n, m = map(int, input().split())
print(n * m + comb(n, 1, exact=True) + comb(m, 1, exact=True))
# Judge status: Accepted
N = int(input())
A = list(map(int,input().split()))

now_max = A[0]
ans = 0

for i in range(N):
  if A[i] > now_max:
    now_max = A[i]
  else:
    ans += now_max - A[i]
print(ans)