peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
n=int(input())
s=input()
x=[0]*(n+1)
for i in range(n):
    if s[i]=="I":
        x[i+1]=x[i]+1
    elif s[i]=="D":
        x[i+1]=x[i]-1
print(max(x))
# Judge status: Accepted
s = input()

flag = False
for i in range(len(s)//2):
    if s[i] != s[len(s)-i-1]:
        flag = True

for i in range((len(s)//2)//2+1):
    if s[i] != s[len(s)//2-i-1]:
        flag = True

if flag:
    print("No")
else:
    print("Yes")
# Judge status: Accepted
a, b, c = map(int, input().split())
num = a
for i in range(b+1):
    if num % b == c:
        print("YES")
        break
    num += a
else:
    print("NO")
# Judge status: Wrong Answer
N, Y = map(int, input().split())

def f():
    for i in range(N+1):
        for j in range(9):
            k = N-i-j
            if i*10000+j*5000+k*1000 == Y:
                print(i, j, k)
                return

    print(-1,-1,-1)

f()
# Judge status: Wrong Answer
a = input().split()
a = [int(a)for a in a]
lis = []

b = input().split()
b = [int(b)for b in b]
c = input().split()
c = [int(c)for c in c]

for i in b:
    lis.append(i)

for i in c:
    lis.append(i)

lis.sort()

count = 0
time = a[2]
honn = 0

while time >= lis[count] and count <= len(lis)-1 :
    time = time - lis[count]

    if  count >= len(lis)-1 :
        honn += 1

        break

    else:
        count += 1
        honn += 1

print(honn)
# Judge status: Accepted
p = input().split()
a = int(p[0])
b = int(p[1])

v = input()
s = list(v)

answer = False

for i in range(len(s)):
    q = s[i]
    if i == a:
        if q == '-':
            answer = True
        else:
            answer = False
            break
    else:
        if q == '-':
            answer = False
            break
        else:
            answer = True

if answer:
    print('Yes')
else:
    print('No')
# Judge status: Accepted
a = int(input())
print(str(a + a * a + a * a * a))
# Judge status: Wrong Answer
import sys
input = sys.stdin.readline

R = int(input())

L = 2 * R * 3.141592
# Judge status: Accepted
n = int(input())
maxda = -10**18
minda = 10**18
maxdb = -10**18
mindb = 10**18
for i in range(n):
	x,y = map(int,input().split())
	maxda = max(maxda, x-y)
	minda = min(minda, x-y)
	maxdb = max(maxdb, x+y)
	mindb = min(mindb, y+x)
print(max(maxda-minda, maxdb-mindb))
# Judge status: Wrong Answer
a,b=map(int,input().split())

if a<0 and b>0:
	print('Zero')
elif a>0:
	print('Positive')
else:
	if (b-a)%2==0:
		print('Negative')
	else:
		print('Pisitive')
# Judge status: Accepted
from collections import Counter

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

ans = 0
for a in range(max(A) + 1):
    ans = max(ans, cnt[a - 1] + cnt[a] + cnt[a + 1])
print(ans)
# Judge status: Wrong Answer
def main():
    from bisect import bisect_left
    n, *abc = map(int, open(0).read().split())
    a, b, c = abc[:n], abc[n:2 * n], abc[2 * n:]
    a, b, c = sorted(a), sorted(b), sorted(c)
    ans = 0
    for i in c:
        j = bisect_left(b, i)
        for k in b[:j]:
            l = bisect_left(a, k)
            ans += l
            print(i, j, l)
    print(ans)


if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
s = input()
weather = {"Sunny":"Cloudy", "Cloudy":"Rainy","Rainy":"Sunny"}
print (weather)
# Judge status: Wrong Answer

from bisect import bisect_right
from bisect import bisect_left
def main():
    n=int(input())
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    C = list(map(int,input().split()))

    A.sort()
    C.sort()
    sum=0
    for i in range(n):
        cnt=1
        cnt*= bisect_right(A,B[i])
        cnt*= n-bisect_left(A,B[i])
        sum+=cnt 

    print(sum)

if __name__ == '__main__':
    main()
# Judge status: Accepted
n = int(input())
a = list(map(int,input().split()))
x = 0
cnt = 1

for i in range(1,n):
    temp = a[i] - a[i-1]
    if x == 0:
        x = temp
    elif x * temp<0:
        cnt += 1
        x =0      

print(cnt)
# Judge status: Accepted
a, b = map(int, input().split())
if 0<a<10 and 0<b<10:
    print(a*b)
else:
    print(-1)
# Judge status: Wrong Answer
lenght = int(input())
people = [int(i) for i in input().split()]
resultList = []
for i in range(min(people), max(people)):
  mylist = []
  for j in people:
    mylist.append((j - i) ** 2)
  resultList.append(sum(mylist))
if(len(resultList) == 0):
  print(people[0])
else:
  print(min(resultList))
# Judge status: Accepted
n = int(input())
s = [input() for i in range(n)]

# 辞書作成
s_dict = dict()
for i in s:
    if i not in s_dict:
        s_dict[i] = 1
    else:
        s_dict[i] += 1

m = max(s_dict.values())
ans = []
for k, v in s_dict.items():
    if v == m:
        ans.append(k)
ans.sort()
# ソート
print(*ans, sep="\n")
# Judge status: Accepted
S = input()
ans = 0
Si = ""
now = ""
for s in S:
    now += s
    if Si != now:
        ans += 1
        Si = now
        now = ""

print(ans)
# Judge status: Wrong Answer
n,m=map(int,input().split())
check=[False]*n
check[0]=True
for i in range(m):
    x,y=map(int,input().split())
    x-=1
    y-=1
    if check[x]:
        check[y]=True
    else:
        continue

ans=0
check[0]=False
for i in range(n):
    if check[i]:
        ans+=1

print(ans)
# Judge status: Wrong Answer
N=int(input())
*A,=map(int,input().split())

count=[0]*(N+1)
i=1
while i<N+1:
    count[i]=count[i-1]+A[i-1]
    i+=1

ans=abs(count[-1])
k=1
while k<N+1:
    ans=min(ans,abs(count[-1]-2*count[k]))
    k+=1

if N==2:
    print(abs(A[1]-A[0]))
else:
    print(ans)
# Judge status: Accepted
N,A,B = map(int,input().split())
if (B-A) % 2 == 0:
  print((B-A)//2)
elif A-1 <= N-B:
  print((A+B-1)//2)
else:
  print(N+1-(B+A+1)//2)
# Judge status: Accepted
N = int(input())
A = 1
ans = 0

while A*A < N:
  if N%A == 0:
    ans += N//A-A
  else:
    ans += N//A-A+1
  A += 1

ans = 2*ans - A + 1

print(ans)
# Judge status: Wrong Answer
import bisect

k,s=map(int, input().split())

p=[]
for i in range(k+1):
    p.append(i)
    
pp=[]
for i in p:
    for j in p:
        pp.append(i+j)
pp.sort()

ans=0
for x in pp:
    if pp[bisect.bisect_right(pp,s-x)-1]==s-x:
        ans+=1
print(ans)
# Judge status: Accepted
r, g, b = map(int, input().split())

a = r * 100 + g * 10 + b
if a % 4 == 0 :
    print('YES')
else:
    print("NO")
# Judge status: Accepted
import sys
s = list(input())
t = list(input())
for i in range(len(s)):
  s = list(s[-1])+s
  s.pop()
  if s == t:
      print('Yes')
      sys.exit()
print('No')
# Judge status: Accepted
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    a, b, t = map(int, input().split())
    ans = 0
    i = 1
    sec = 0
    while sec <= t+0.5:
        ans += b
        sec = a * i
        i += 1
    print(ans-b)
    
if __name__ == '__main__':
    main()
# Judge status: Accepted
"""Boot-camp-for-Beginners_Easy004_B_Tax-Rate_25-August-2020.py"""
import numpy as np
import sys

N=int(input())
X=N/1.08
if int(int(np.ceil(X))*1.08)==N:
    print(int(np.ceil(X)))
else:
    print(":(")
# Judge status: Accepted
N = int(input())
A = [int(input()) for _ in range(N)]


ans = 0
cnt = 0
for i in range(N):
    if A[i] != 0:
        ans += (A[i]+cnt)//2
        cnt = (A[i]+cnt)%2
    else:
        cnt = 0
print(ans)
# Judge status: Wrong Answer
a, b, c = map(int, input().split())
 
if a == b == c:
    print(-1)

else:
  cnt = 0
  while (a % 2 == 0 and b % 2 == 0 and c % 2 == 0): 
    a, b, c = (b+c)//2, (a+c)//2, (a+b)//2
    cnt += 1
  print(cnt)
# Judge status: Accepted
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from bisect import bisect_left, bisect_right

n = int(readline())
a = [int(readline()) for _ in range(n)]
inf = float('inf')
memo = [inf] * n
for aa in a[::-1]:
    memo[bisect_right(memo, aa)] = aa
print(bisect_left(memo, inf))
# Judge status: Accepted
# -*- coding: utf-8 -*-

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

a = 14 if a == 1 else a
b = 14 if b == 1 else b

if a > b:
    print('Alice')
elif a < b:
    print('Bob')
else:
    print('Draw')
# Judge status: Wrong Answer
# -*- coding: utf-8 -*-

SA,SB,SC = [input().strip() for _ in range(3)]

S_dic={}
S_dic['a']=SA
S_dic['b']=SB
S_dic['c']=SC

turn="a"
while True:
    if S_dic[turn] == "":
      print(turn.upper())
      break
    
    turn = S_dic[turn][0]
    S_dic[turn] = S_dic[turn][1:]
# Judge status: Accepted
n = int(input())
ans = n * (n+1) // 2
print(ans)
# Judge status: Wrong Answer
n, m = map(int, input().split())
ll = [0] + [ 0 for _ in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    ll[a] += 1
    ll[b] += 1
for l in ll[1:]:
    print()
# Judge status: Wrong Answer
def main():
  N = int(input())
  X = [int(_) for _ in input().split()]
  Y = sorted(X)
  mid = (Y[(N-1)//2] + Y[N//2]) / 2
  for i in range(N):
    print(Y[N//2] if X[i] <= mid else print(Y[(N-1)//2]))
  return

if __name__ == '__main__':
  main()
# Judge status: Accepted
from collections import defaultdict

n, m = map(int, input().split())
PY = [tuple(map(int, input().split())) for _ in range(m)]
sorted_PY = sorted(PY)
cnt = 1
now = sorted_PY[0][0]
d = defaultdict(int)
for p, y in sorted_PY:
    if now != p:
        cnt = 1
        now = p
    d[y] = (p, cnt)
    cnt += 1

for p, y in PY:
    l, r = map(str, d[y])
    l = '0'*(6-len(l)) + l
    r = '0'*(6-len(r)) + r
    print(l+r)
# Judge status: Wrong Answer
A,B=map(int,input().split())
x=min(A,B)
y=max(A,B)
check=1
##x<=y
#####while break##############
if y%x==0:
    print(y)
else:
    root=round((x**(1/2)))
    for i in range(2,root):
        if x%i==0 and y%i==0:
            x/=i
            y/=i
            check*=i 
       # print(check)
        i=2
    #print(x,y)
        root=round((x**(1/2)))
    print(int(check*x*y))
# Judge status: Wrong Answer
s=input()
print(s.find("Z")-s.find("A")+1)
# Judge status: Accepted
def main():
    s = int(input())
    ak = s
    k = 1

    history = set([ak])
    while True:
        k += 1
        if ak%2 == 0:
            ak = ak//2
        else:
            ak = ak*3 + 1

        if ak in history:
            print(k)
            break
        else:
            history = history | set([ak])

main()
# Judge status: Wrong Answer
N, K, S = map(int, input().split())
INF = 10**9
ans = []
if S % 2 == 0:
    s = S // 2
    ans.extend([s] * (K+1))
    ans.extend([INF] * (N-(K+1)))
else:
    k = K // 2 + 1
    ans.extend([S//2, S//2+1] * k)
    if K % 2 == 0:
        ans.pop()
    ans.extend([INF] * (N-len(ans)))


print(' '.join([str(x) for x in ans]))
# Judge status: Accepted
from decimal import *

n , m = map(int, input().split())
arr = list(map(int, input().split()))
check = Decimal(1/(4*m)) * sum(arr)
count = 0
for i in arr:
	if i < check:
		continue
	else:
		count+=1
if count >= m:
	print("Yes")
else:
	print("No")
# Judge status: Accepted
from heapq import heappop, heappush
n, m, *AB = map(int, open(0).read().split())
B = [[] for _ in range(m)]
for a, b in zip(AB[::2], AB[1::2]):
    if a <= m:
        B[a-1].append(b)

ans = 0
heap = []
for b in B:
    for x in b:
        heappush(heap, -x)
    if heap:
        ans -= heappop(heap)
print(ans)
# Judge status: Wrong Answer
n, k = map(lambda x: int(x), input().split())
s = input()

str = ""
for i in range(n):
  if i == k:
    str += s[i].upper()
  else:
    str += s[i]

print(str)
# Judge status: Accepted
s=input()
cnt=len(s)-2
while cnt>0:
  #print(s[0:cnt//2],s[cnt//2:cnt])
  if s[0:cnt//2]==s[cnt//2:cnt]:
    break
  cnt-=2
print(cnt)
# Judge status: Wrong Answer
N, H = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(N)]

max_a = sorted(ab, key=lambda x: -x[0])[0][0]
bs = [b for a,b in ab if b > max_a]
sum_bs = sum(bs)

if H <= sum_bs:
    print(len(bs))
else:
    H -= sum_bs
    print((H+max_a-1)//max_a + len(bs))
# Judge status: Wrong Answer
a,b,c= map(int, input().split())
if (100*a+10*b+c) % 2 == 1:
    print('YES')
else:
    print('NO')
# Judge status: Wrong Answer
x,a,b = map(int,input().split())

kyori1 = abs(x - a)
kyori2 = abs(x - a)

if kyori1 < kyori2:
  print('A')
else:
  print('B')
# Judge status: Wrong Answer
n=int(input())
a1=list(map(int,input().split()))
a2=list(map(int,input().split()))

mi=min(sum(a1[1:]),sum(a2[:-1]))
for i in range(2,n-1):
    tmp=sum(a1[i:])+sum(a2[:i-1])
    if tmp<mi: mi=tmp
print(sum(a1)+sum(a2)-mi)
# Judge status: Accepted

A, B, C = map(int, input().split())
total = A*B*C
if A >= B and A >= C:
    x = A
    y = B
    z = C
elif B >= A and B >= C:
    x = B
    y = A
    z = C
else:
    x = C
    y = A
    z = B
if x % 2 == 0:
    ans = 0
else:
    ans = x % 2*y*z
print(ans)
# Judge status: Wrong Answer
def myAnswer(A:int,B:int,C:int) -> int:
   red = C // 2
   blue = C // 2
   if(C % 2 == 1):
      red += 1
   return abs(A*B*red - A*B*blue)
      

def modelAnswer():
   tmp=1
def main():
   A,B,C = map(int,input().split())
   print(myAnswer(A,B,C))
if __name__ == '__main__':
   main()
# Judge status: Accepted
N,M = map(int,input().split(sep=" "))
print(N*(N-1)//2 + M*(M-1)//2)
# Judge status: Accepted
n, k = input().split(" ")
n = int(n)
k = int(k)
print("unsafe" if k >= n else "safe")
# Judge status: Accepted
from collections import deque

S = deque(input())
Q = int(input())

flip = 0
for _ in range(Q):
    q = input().split()
    if q[0] == "1":
        flip += 1
        flip %= 2
    else:
        if (int(q[1]) - 1 + flip)%2 == 0:
            S.appendleft(q[2])
        else:
            S.append(q[2])

S = list(S)
if flip == 0:
    print(*S, sep="")
else:
    print(*S[::-1], sep="")
# Judge status: Accepted
n = int(input())
a = list(map(int,input().split()))
a.sort()
c = a[-1]
if n%2 == 0:
  n1 = n//2-1
  for i in range(n1):
    a1 = a[n-2-i]
    c += a1*2
else:
  n2 = n//2
  a3 = a[n-n2-1]
  c += a3
  for i in range(n2-1):
    a2 = a[n-2-i]
    c += a2*2
print(c)
# Judge status: Wrong Answer
s = input()
print(len(set(list(s))))
# Judge status: Accepted
n = int(input())
a = n + (n**2) + (n**3)
print(a)
# Judge status: Accepted
c=str(input())

if c in 'aiueo':
    print('vowel')

else:
    print('consonant')
# Judge status: Accepted
A, B, C, X, Y = map(int, input().split())

min_price = A * X + B * Y

if A + B > 2 * C:
    while X > 0 and Y > 0:
        X = X - 1
        Y = Y - 1
        min_price -= A + B - 2 * C

if X > 0 and A > 2 * C:
    while X > 0:
        X = X - 1
        min_price -= A - 2 * C

if Y > 0 and B > 2 * C:
    while Y > 0:
        Y = Y - 1
        min_price -= B - 2 * C

print(min_price)
# Judge status: Wrong Answer
N = int(input())

ans = 0

for i in range(1,N):
    if i % 3 != 0 and i % 5 != 0:
        ans += i

print(ans)
# Judge status: Accepted
a, b, c = map(int, input().split())
ans = b//a
if ans > c:
    ans = c
print(ans)
# Judge status: Accepted
N = int(input())


def f(L, m):
    l = len(L)
    if l == N:
        print(''.join(list(map(lambda i: chr(i + 96), L))))
        return
    for d in range(1, min(l + 1, m + 1) + 1):
        f(L + [d], max(m, d))


f([1], 1)
# Judge status: Accepted
h,a = map(int,input().split())
count = 0

while h > 0:
  h -= a
  count+=1
print(count)
# Judge status: Accepted
# -*- coding: utf-8 -*-
"""
Created on Sat May  9 16:41:56 2020

@author: shinba
"""


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

if sum(A) >= 22:
    print("bust")
else:
    print("win")
# Judge status: Accepted
N, M = map(int, input().split())
pena= 0
ac = [0]*(10**5)
for _ in range(M):
  tmp = input().split()
  if ac[int(tmp[0])-1] < 1:
    if tmp[1] == "AC":
      pena -= ac[int(tmp[0])-1]
      ac[int(tmp[0])-1] = 1
    else: ac[int(tmp[0])-1] -= 1 #penalty
print(ac.count(1), pena)
# Judge status: Accepted
S=input()
print("2018"+S[4:])
# Judge status: Wrong Answer
import numpy as np

N, D = list(map(int, input().split()))
ans = 0
for i in range(N):
    x, y = list(map(int, input().split()))
    r = np.sqrt(x**2 + y**2)
    if r < D:
        ans += 1

print(ans)
# Judge status: Accepted
#coding:utf-8
x, y = map(int, input().split())

if x % y == 0:
    print(-1)
else:
    print(x)
# Judge status: Wrong Answer
[N, K] = list(map(int, input().split()))
all_A =[]
after_A =[]
for i in range(1, N + 1):
    all_A.append(i)
for j in range(K):
    d = int(input())
    A = list(map(int, input().split()))
    after_A = set(after_A) ^ set(A)
print(len(after_A))
# Judge status: Accepted
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()

ans = 0
M = []
for i in range(N):
	if i >= K and M[i-K] == T[i]:
		M.append('x')
		continue
	else:
		if T[i] == 'r':
			ans += P
			M.append('r')
		if T[i] == 's':
			ans += R
			M.append('s')
		if T[i] == 'p':
			ans += S
			M.append('p')
print(ans)
# Judge status: Accepted
from collections import deque
s = [deque([ord(a) - ord('a') for a in list(input())]) for i in range(3)]

now = 0
while True:
    if not s[now]:
        print('ABC'[now])
        break
    else:
        now = s[now].popleft()
# Judge status: Accepted
n, a, b = map(int, input().split())
t, o = 0, 0
s = input()
for i in range(n):
    if s[i]=="a":
        t += 1
        if t <= a+b:
            print("Yes")
        else:
            print("No")
    elif s[i]=="b":
        o += 1
        if o <= b and t < a+b:
            t += 1
            print("Yes")
        else:
            print("No")
    else:
        print("No")
# Judge status: Accepted
x, k , d = map(int , input().split())
r = abs(x)//d

if x > 0:
  if k - r > 0:
    print(abs(x-r*d-(k-r)%2*d))
  else :
    print(abs(x-k*d))
else :
  if k - r > 0:
    print(abs(x+r*d+(k-r)%2*d))
  else :
    print(abs(x+k*d))
# Judge status: Accepted
N = int(input())
A = [int(s) for s in input().split()]

cnt = 0
for i, a in enumerate(A):
    if (i + 1) % 2 == 1 and a % 2 == 1:
        cnt += 1

print(cnt)
# Judge status: Accepted
sx, sy, tx, ty = map(int, input().split())
x = tx - sx
y = ty - sy

lst = []
lst.append("U" * y)
lst.append("R" * x)
lst.append("D" * y)
lst.append("L" * (x + 1))
lst.append("U" * (y + 1))
lst.append("R" * (x + 1))
lst.append("D")
lst.append("R")
lst.append("D" * (y + 1))
lst.append("L" * (x + 1))
lst.append("U")
print("".join(lst))
# Judge status: Wrong Answer
def main():
    N = int(input())
    S = input()
    ans = 0
    for i in range(N - 2):
        for j in range(i, N - 1):
            for k in range(j, N):
                if j - i != k - j:
                    if S[j] != S[i] and S[i] != S[k]:
                        ans += 1                                        
    print(ans)

if __name__ == "__main__":
    main()
# Judge status: Accepted
n, k = map(int,input().split())
hl = list(map(int,input().split()))

dp = [[] for _ in range(n)]
dp[0] = 0

for i in range(1,n):
    tmp = float('inf')
    for j in range(1,k+1):
        if i-j < 0:
            continue
        tmp = min(dp[i-j] + abs(hl[i]-hl[i-j]),tmp)
    dp[i] = tmp
print(dp[-1])
# Judge status: Accepted
A,B,C,K = map(int,input().split())
if  A>=K:
  print(K)
elif A+B>=K:
  print(A)
else:
  print(A-(K-A-B))
# Judge status: Wrong Answer
N=int(input())
p=list(map(int,input().split()))
count=0
for i in range(N):
  if p[i]!=i+1 :
    count+=1
if(count<=2):
  print("Yes")
else:
  print("No")
# Judge status: Accepted
n, k, x, y = [int(input()) for _ in range(4)]
print(n*x-(x-y)*max(n-k, 0))
# Judge status: Wrong Answer
def kaibun(x):
  if(x != ''.join(list(reversed(x)))):
    return 0
  else:
    return 1

def main():
  s = input()
  s_num = len(s)

  num1 = kaibun(s[:int((s_num - 1)/2)])
  num2 = kaibun(s[(int((s_num + 1)/2)):s_num])

  if(num1 == 1 and num2 == 1):
    if(s == ''.join(list(reversed(s)))):
      print('Yes')
  else:
    print('No')

if __name__ == '__main__':
  main()
# Judge status: Wrong Answer
a,b,c,d=map(int,input().split(" "))
if(a<d):
  print(d)
elif(a+b<d):
  print(a)
elif((a+b+c)<d):
  print(a-(d-(a+b)))
else:
  print(a-c)
# Judge status: Accepted
from scipy.special import comb

s = int(input())
n = s//3
ans = 0

for i in range(1, n+1):
    a = s - i*3
    ans += comb(a+i-1, i-1, exact=True)
    
ans = int(ans)%(10**9+7)

print(ans)
# Judge status: Accepted
a,b,c,d=input()
print('NYoe s'[a==b==c or b==c==d::2])
# Judge status: Accepted
n=int(input())
p=list(map(int,input().split()))
ans=10**9
for i in range(n):
  ans=min(ans,abs(sum(p[:i+1])-sum(p[i+1:])))
print(ans)
# Judge status: Accepted
import networkx as nx
room, route_count = map(int,input().split())
route = [list(map(int,input().split())) for _ in range(route_count)]

G = nx.Graph()
G.add_nodes_from(range(1,room+1))
G.add_edges_from(route)
pre = nx.predecessor(G, 1)

print('Yes')
for i in range(2,room+1):
  print(pre[i][0])
# Judge status: Accepted
n, m = map(int, input().split())
A = list(map(int, input().split()))

L = [[0, 0] for i in range(m)]

for i in range(m):
    b, c = map(int, input().split())
    L[i][0] = c
    L[i][1] = b
L.sort(reverse=True)

cnt = 0
for i in range(m):
    c, b = L[i]
    A += [c]*b
    cnt += b
    if cnt >= n:
        break

A.sort(reverse=True)
A = A[0:n]

print(sum(A))
# Judge status: Wrong Answer
s = input()
stack = []
best_length = -float('inf')
for i,w in enumerate(s):
  if w=='A':
    stack.append(i)
  if w=='Z' and stack:
    start = stack.pop()
    length = i - start + 1
    if length > best_length:
      best_length = length
print(best_length)
# Judge status: Accepted
w, h, n = map(int, input().split())

l = 0
r = w
d = 0
u = h

for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1: l = max(l, x)
    if a == 2: r = min(r, x)
    if a == 3: d = max(d, y)
    if a == 4: u = min(u, y)

ans = max(0, r - l) * max(0, u - d)

print(ans)
# Judge status: Accepted
s = str(input())
k = int(input())

res = 1
idx = 0
for i in range(len(s)):
    if s[i] != "1":
        res = s[i]
        idx = i + 1
        break

if k < idx:
    print(1)
else:
    print(res)
# Judge status: Wrong Answer
a,b,c=map(int,input().split())
if round((c-a-b)*(c-a-b))-round(4*a*b)>0:
    print("Yes")
else:
    print("No")
# Judge status: Wrong Answer
t = list(input())
t.reverse()

tmptmp = "P"
for i in range(len(t)):
    if i == 0:
        tmp = t[i]
        continue
    if tmp == "?" and tmptmp == "P":
        t[i-1] = "D"
    elif tmp == "?" and tmptmp == "D" and t[i] == "P":
        t[i-1] = "D"
    elif tmp == "?" and tmptmp == "D" and t[i] == "D":
        t[i-1] = "P"
    tmptmp = t[i-1]
    tmp = t[i]

t.reverse()
t = "".join(t)
print(t)
# Judge status: Accepted
a = int(input())
b = int(input())
c = int(input())
x = int(input())

cnt = 0
for i in range(a+1):
    for j in range(b+1):
        for y in range(c+1):
            if (500 * i) + (100 * j) + (50 * y) == x:
                cnt += 1
print(cnt)
# Judge status: Accepted
A=[int(input()) for _ in range(5)]
k=int(input())

if (max(A)-min(A))>k:
	print(":(")
else:
	print("Yay!")
# Judge status: Wrong Answer
n = int(input())
cnt = 0
while n != 0:
    cnt += n%10
    n //= 10
print(cnt)
# Judge status: Accepted
A,B,C=map(int,input().split())
x = (1 if A==B else 0) + (1 if B==C else 0) + (1 if C==A else 0)
print("Yes" if x==1 else "No")
# Judge status: Accepted
import sys


def main():
  n, *lst = map(int, sys.stdin.read().split())
  max1 = max(lst)
  idx = lst.index(max1)
  max2 = max(lst[:idx] + lst[idx+1:])
  print('\n'.join(str(max1) if j != max1 else str(max2) for j in lst))


if __name__ == '__main__':
  main()
# Judge status: Accepted
N = int(input())
l = [list(map(int,input().split())) for _ in range(N)]
import itertools
p = list(itertools.permutations(range(N),N))
#print(p)
ans = 0
for i in p:
    num = 0
    for j in range(N-1):
        num += ((l[i[j+1]][0]-l[i[j]][0])**2+(l[i[j+1]][1]-l[i[j]][1])**2)**0.5
    #print(num)
    ans += num
print(ans/len(p))
# Judge status: Accepted
N,M=map(int,input().split())
arr=[list(map(int,input().split())) for _ in range(M)]

for x in range(0, 1000):
    nx=x//10
    d=[x%10]
    while(nx):
        d.append(nx%10)
        nx//=10

    d.reverse()

    if len(d)!=N: continue

    chk=True
    for i in range(M):
        if(d[arr[i][0]-1]!=arr[i][1]): chk=False
    if chk: print(x);exit()

print(-1)
# Judge status: Wrong Answer
n,a,b=input().split(" ")
n=int(n)
a=int(a)
b=int(b)
lst=input()
cnt=0
cnt2=0
for i in range(n):
  if lst[i]=="a":
    if cnt<a+b:
      print("Yes")
      cnt+=1
    else:
      print("No")
  elif lst[i]=="b":
    if cnt<a+b and cnt2<=b:
      print("Yes")
      cnt+=1
      cnt2+=1
    else:
      print("No")
  else:
    print("No")