peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
n,m = map(int,input().split())
K = []
A = []

for _ in range(n):
    tmp = list(map(int,input().split()))
    A += tmp[1:]

ans = 0
from collections import Counter
cnt = Counter(A)
for k,v in cnt.items():
    if v == n:
        ans += 1
print(ans)
# Judge status: Accepted
import math 
X, N = map(int,input().split())
d = int(999)
d1 = int()
ans = int(999)
if 0 < N:
    P = list(map(int,input().split()))
    for i in range(999):
        if P.count(i) == 0:
            d1 = abs(X-i)
            if d1 < d and 0 <= d1:
                d = d1
                ans = i
    print(ans)
else:
    print(X)
# Judge status: Wrong Answer
k=int(input())
print((k//2)*(k//2+1))
# Judge status: Accepted
n, k, q = map(int,input().split())
l = [int(input()) for _ in range(q)]

score = [k-q] * n
for i in l:
    score[i-1] += 1

for j in score:
    if j > 0:
        print('Yes')
    else:
        print('No')
# Judge status: Wrong Answer
n=int(input())
txy=[list(map(int,input().split())) for _ in range(n)]
txy.insert(0,[0,0,0])
for i in range(1,n+1):
  d=abs(txy[i][1]-txy[i-1][1])+abs(txy[i][2]-txy[i-1][2])
  if ((txy[i][0]-txy[i-1][0])-d)<0:
    print("No")
    exit()
  elif d%2==0:
    print("No")
    exit()
print("Yes")
# Judge status: Wrong Answer
import math
h = int(input())
cnt=0
while True:
 cnt+=1
 h=math.floor(h/2)
 if (h/2) < 1:
  cnt+=1
  break
sum=0
for i in range(cnt):
 sum=sum + (2**i)
print(sum)
# Judge status: Accepted
N = int(input())
# cnt[i][j] := 先頭がi, 末尾がjで始まるような数
cnt = [[0] * 10 for i in range(10)]
for n in range(1, N + 1):
    cnt[int(str(n)[0])][int(str(n)[-1])] += 1

ans = 0
for i in range(10):
    for j in range(10):
        ans += cnt[i][j] * cnt[j][i]

print(ans)
# Judge status: Accepted
X = input()
def solve(X):
    ns = 0
    nt = 0
    for x in X:
        if x == 'S':
            ns += 1
        elif ns>0:
            ns -= 1
        else:
            nt += 1
    return ns+nt
print(solve(X))
# Judge status: Accepted
from itertools import count
X, Y = map(int, input().split())
for i in count(1):
    if 2**i*X > Y:
        print(i)
        break
# Judge status: Accepted
A, B, K = map(int, input().split())
if A==B:
    print(A)
    exit()
ans_dic={}
A_K = A+K if A+K <= B else B
for i in range(A, A_K):
    ans_dic[i] = 1
K_B = B-K if B-K >= A else A
for i in range(B, K_B, -1):
    if i in ans_dic:
        pass
    else:
        ans_dic[i] = 1
for i, v in sorted(ans_dic.items()):
    print(i)
# Judge status: Accepted
a,b,c = map(int,input().split())
print(c,a,b)
# 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):
    ans = ans + min(B[i], A[i]) + min(A[i+1], B[i]-min((A[i], B[i])))

print(ans)
# Judge status: Accepted
Q, H, S, D = map(int, input().split())
N = int(input())
ans = 0
if N % 2 == 0:
    ans = min(4*N*Q, 2*N*H, N*S, N*D//2)
else:
    ans += min(4*(N-1)*Q, 2*(N-1)*H, (N-1)*S, (N-1)*D//2)
    ans += min(4*Q, 2*H, S)

print(ans)
# Judge status: Accepted
from collections import defaultdict
d = defaultdict(int)
N = int(input())
N_List = list(map(int,input().split()))

for i in range(N):
    CN = N_List[i]
    for k in range(-1,2,1):
        d[CN + k] += 1
        
print(max(d.values()))
# Judge status: Accepted
n, k = [int(e) for e in input().split()]
a = list(map(str, input().split()))
elem_dict = {}
ans = 0
for i in a:
    if i not in elem_dict:
        elem_dict[i] = 1
    else:
        elem_dict[i] += 1
elem_sorted = sorted(elem_dict.items(), key=lambda x:x[1])
for i in range(len(elem_sorted)-k):
    ans = ans + elem_sorted[i][1]
print(ans)
# Judge status: Wrong Answer
N,K = map(int, input().split())
A = [0]*N

for i in range(N):
    A[i] = int(input())
    
A.sort()
print(A)

ans = A[K-1]-A[0]
for i in range(N-K):
    if A[K+i]-A[i+1] < ans:
        ans = A[K+i]-A[i+1]
        
print(ans)
# Judge status: Accepted
n=int(input())
a=n//11
a*=2
b=n%11
if b>6:
  a+=2
elif b==0:
  a+=0
else:
  a+=1
print(a)
# Judge status: Accepted
n = input()
ans = sum(map(int,list(n)))
ans = max(ans,int(n[0])-1+(len(n)-1)*9)
print(ans)
# Judge status: Accepted
N,C,K = map(int,input().split())
T =[int(input()) for i in range(N)]

p = 0
r = 0
cnt = 1

T.sort()

for i in range(len(T)):
    if p == 0:
        p = 1
        q = T[i]
        r = 1
    elif p == 1 and q + K >= T[i] and r < C:
        r += 1
    else:
        cnt += 1
        p = 1
        q = T[i]
        r = 1

print(cnt)
# Judge status: Accepted
n = int(input())

d = {}
for _ in range(n):
    s = input()
    if s in d:
        d[s] += 1
    else:
        d[s] = 1

MAX = 0
ans = []
for k, v in d.items():
    if v > MAX:
        ans = [k]
        MAX = v
    elif v == MAX:
        ans.append(k)


ans.sort()
for a in ans:
    print(a)
# Judge status: Wrong Answer
n = int(input())
p = input().split()
product = 0
for i in range(n): 
    for j in range(i+1,n): 
        product = product + int(p[i])*int(p[j]) 
print(product)
# Judge status: Accepted
import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))

n = readint()
a = readints()

a.sort(reverse=1)

if n%2==0:
    print(a[0]+sum(a[1:n//2])*2)
else:
    print(a[0]+sum(a[1:n//2])*2+a[n//2])
# Judge status: Accepted
S=input()
H="AGTC"

ans=0
cnt=0
for i in range(len(S)):
    if S[i] in H:
        cnt+=1
        ans=max(ans,cnt)
    else:
        cnt=0
        
print(ans)
# Judge status: Wrong Answer
N = int(input())
a = list(map(int, input().split()))
cnt = 0
cntcnt = 0
new = []
for i in range(N):
  num = 0
  l = list(range(N))
  l.remove(l[i])
  for j in l:
    if cntcnt == 0:
      num = a[j]
    else:
      num = a[j]^num
    cntcnt += 1
  new.append(num)
  cnt += 1
print(new)
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)

t2 = a[0]
x = a[0]//2
ans = 1
for i in range(1,n):
  t = abs(x - a[i])
  if t < t2:
    t2 = t
    ans = i
print(a[0],a[ans])
# Judge status: Wrong Answer
i9 = 10 ** 9
S = int(input())
print(i9 - (S % i9), S // i9 + 1, i9, 1, 0, 0)
# Judge status: Wrong Answer
s=input()
from itertools import groupby as gb
l=[len(list(b)) for a,b in gb(list(s))]
pre=0
ans=0
c=[0,0]
px,py=0,0
for x,y in zip(l[::2],l[1::2]):
    x+=px
    if py:
        k=min(x,py);x-=k;py-=k;ans+=k
        if x==0:py+=y;continue
    k=min(x,y);ans+=k;px+=(x-k);py+=(y-k)
print(2*ans+2*min(px,py))
# Judge status: Accepted
N = int(input())

if N % 2 == 0:
    print(N //2)
else:
    print(N // 2 + 1)
# Judge status: Accepted
a = int(input())
print(a ** 2)
# Judge status: Accepted
a = int(input())
ans = "No"
if (a<1) or (a>81):
    ans = "No"
else:
    for i in range(1,10):
        for j in range(1,10):
            if (i*j) == a:
                ans = "Yes" 
                break
print(ans)
# Judge status: Wrong Answer
import sys
input = sys.stdin.readline
s=input()
s=[s[i] for i in range(len(s))]
s=s[:len(s)-1]
if s[0]=='?':
  s[0]='D'
if s[-1]=='?':
  s[-1]='D'
for i in range(len(s)-2):
  if s[i+1:i+3]==['?','?']:
    s[i+1]='D'
    s[i+2]='D'
  elif s[i]==s[i+2]=='D':
    s[i+1]='P'
  else:
    s[i+1]='D'
print(''.join(s))
# Judge status: Accepted

def resolve():
    import sys
    input = sys.stdin.readline
    # row = [int(x) for x in input().rstrip().split(" ")]
    # n = int(input().rstrip())
    s = input().rstrip()
    chars = set()
    for c in s:
        if c in chars:
            print("no")
            return
        else:
            chars.add(c)

    print("yes")




if __name__ == "__main__":
    resolve()
# Judge status: Accepted
a,b,k=map(int, input().split())
l = []
for i in range(1,a+1):
    if a % i == 0 and b % i == 0:
        l.append(i)
print(l[-k])
# Judge status: Wrong Answer
def pokryj(plansza,x,y):
	koszt=0
	if 2*x>=y:
		for i in range(len(plansza)-1):
			if plansza[i]=="." and plansza[i+1]==".":
				plansza[i]=="x" 
				plansza[i+1]=="x"
				koszt+=y
			elif plansza[i]==".":
				plansza[i]=="x"
				koszt+=x
	else:
		for i in range(len(plansza)-1):
			if plansza[i]==".":
				plansza[i]=="x"
				koszt+=x
	return koszt
print(pokryj("x.x.x.x..",1,2))
# Judge status: Accepted
K = int(input())
S = input().strip()

if len(S) > K:
	print(S[:K] + "...")
else:
	print(S)
# Judge status: Accepted
a,b,c,d=input()
print("Good" if a!=b!=c!=d else "Bad")
# Judge status: Accepted
from sys import stdin,stdout
input = stdin.readline
def write(n,sep="\n"):
	stdout.write(str(n))
	stdout.write(sep)
def gil():
	return list(map(int, input().split()))
import itertools
N = int(input())
L = list(map(int, input().split()))
if N < 3:
    print(0)
    exit()
ans = 0
for bars in itertools.combinations(L, 3):
    if max(bars) >= sum(bars) - max(bars):
        continue
    if bars[0] == bars[1]:
        continue
    if bars[1] == bars[2]:
        continue
    if bars[0] == bars[2]:
        continue
    ans += 1
print(ans)
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))
c = 0

for i in range(n):
    if (i+1) % 2 != 0 and a[i]%2 != 0:
        
        c += 1

print(c)
# Judge status: Accepted
N = int(input())

ans = 0
for n in range(1, N+1):
    if n%3 != 0 and n%5 != 0:
        ans += n
print(ans)
# Judge status: Wrong Answer
n = int(input())
a, b = [], []
for i in range(n):
    x, y = map(int, input().split())
    a.append(x)
    b.append(y)
a.sort()
b.sort()
if n%2==0:
    p = n//2
    right = (a[p]+a[p-1])/2 -1
    left = (b[p]+b[p-1])/2
    r = left-right
    if int(r)==r:
        print(int(r)*2)
    else:
        print(int(r)*2 +1)
else:
    p = n//2
    right = a[p]
    left = b[p]
    print(int(left-right)+1)
# Judge status: Accepted
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    n, q = map(int, input().split())
    s = input()

    ans = [0] * n
    pre = ''
    sum = 0
    for i, w in enumerate(s):
        if pre == 'A' and w == 'C':
            sum += 1
        ans[i] = sum
        pre = w
    
    for i in range(q):
        l, r = map(lambda x: int(x) - 1, input().split())
        print(ans[r] - ans[l])

if __name__ == '__main__':
    main()
# Judge status: Accepted
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy
import bisect

if __name__ == "__main__":
    n,m = map(int,input().split())
    if n == 1 and m == 1:
        print(1)
    elif n == 1:
        print(m-2)
    elif m == 1:
        print(n-2)
    else:
        print((n-2)*(m-2))
# Judge status: Accepted
n,m = (int(x) for x in input().split())
if n == m:
  print('Yes')
else:
  print('No')
# Judge status: Wrong Answer
l=["abcdefghijklmnopqrstuvwxyz"]
a=input()
for i in range(len(l)):
    if(l[0][i] == a):
        break
print(l[0][i+1])
# Judge status: Wrong Answer
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
print(a[-2]+a[-4])
# Judge status: Wrong Answer
A,B,X = map(int, input().split())
print("YES" if X-A<=B and A>=X else "NO")
# Judge status: Accepted
A,B=map(int,input().split())

if ((A+B)/2)%1==0.0:
    print(int((A+B)/2))
else:
    print("IMPOSSIBLE")
# Judge status: Accepted
n=int(input());print(sum(n//(10*(5**i)) for i in range(99))*(n%2==0))
# Judge status: Wrong Answer
n, k = map(int, input().split())
d = set(map(int, input().split()))
inf = 10 * n + 1
stop = len(str(n)) + 1
num = []
for i in range(10):
    if i in d:
        pass
    else:
        num.append(i)


def dfs(pos, x):
    if pos == stop:
        if x >= n:
            return x
        else:
            return inf

    ret = [
        dfs(pos + 1, 10 * x + num_i) for num_i in num
    ]

    return min(ret)


print(dfs(0, 0))
# Judge status: Accepted
N, M = map(int, input().split())
data = [list(map(int, input().split())) + [_] for _ in range(M)]
data = sorted(data, key=lambda x: (x[0], x[1]))

order = 1
for i in range(M):
    if not i == 0 and not data[i][0] == data[i-1][0]:
        order = 1
    data[i].append(str(data[i][0]).zfill(6) + str(order).zfill(6))
    order += 1

data = sorted(data, key=lambda x: (x[2]))
for x in data:
    print(x[3])
# Judge status: Wrong Answer
N, M = map(int, input().split())
list=[]
s=set(range(1, M+1))
for i in range(N):
    list.append(input().split())
    s &= set(list[1:])
    list=[]
print(len(s))
# Judge status: Accepted
q, h, s, d = map(int, input().split())
n = int(input())

q *= 4
h *= 2
d_ = d / 2

tmp = min(q, h, s)
ans = 0
if d_ < tmp:
    ans += d * (n // 2)
    ans += tmp * (n % 2)
else:
    ans += n * tmp

print(ans)
# Judge status: Wrong Answer
n = int(input())
s = dict()
for _ in range(n):
  temp = input()
  try:
    s[temp] += 1
  except:
    s[temp] = 1

m = int(input())

for _ in range(m):
  temp = input()
  try:
    s[temp] -= 1
  except:
    s[temp] = 1


s = sorted(s.items(), key=lambda x: x[1], reverse=True)

print(s[0][1])
# Judge status: Wrong Answer
N = int(input())
A = list(map(int, input().split()))
bottom = sum(A)

if bottom <= 0:
  print(-1)
  exit()

ret = 1
children = 1 - A[0]
bottom -= A[0]

for i in range(N):
    children = children * 2 - A[i+1]
    if children <= -1:
      ret = -1
      break
    
    bottom -= A[i+1]
    if children >= bottom:
      children = bottom
    ret += children + A[i+1]
print(ret)
# Judge status: Wrong Answer
import numpy as np

N, K = map(int, input().split(" "))
Hs = [int(i) for i in input().split(" ")]



dp = [10**9] * N
dp[0] = 0

for i in range(N):
    for j in range(1,K+1):
        i_j = i+j
        if i_j < N:
            dp[i_j] = min(dp[i_j], dp[i] + abs(Hs[i-j]-Hs[i]))
    
    
print(int(dp[-1]))
# Judge status: Accepted
hp,sp = input().split(" ")
hp = int(hp)
sp = int(sp)
attack = input().split(" ")
damage = 0

for i, new in enumerate(attack):
    attack[i] = int(attack[i])

for i in range(0,sp):
    damage += attack[i]

if damage >= hp:
    print("Yes")

else:
    print("No")
# Judge status: Accepted
a, b, x = map(int, input().split())

ans = b//x - (a-1)//x

print(ans)
# Judge status: Accepted
N, L = map(int,input().split())
l, r = L, L + N - 1
total = (L - 1) * N + N * (N + 1) // 2
if l <= 0 and r >= 0:
    print(total)
if l > 0:
    total -= l
    print(total)
if r < 0:
    total -= r
    print(total)
# Judge status: Wrong Answer
str = input()
str = str.lower()
yes = True
for i in range(len(str)):
  print(i % 2 == 0 and str[i] != 'h', i % 2 == 1 and str[i] != 'i')
  if (i % 2 == 0 and str[i] != 'h') or (i % 2 == 1 and str[i] != 'i'):
    yes = False
    break
print("Yes" if yes else "No")
# Judge status: Accepted
N = int(input())
P = [int(i) for i in input().split()]
count = 0
min_p = N + 1
for n in range(N):
  if min_p >= P[n]:
    min_p =P[n]
    count += 1
print(count)
# Judge status: Accepted
def solve(H,i):
    if H ==1:
        return i
    else:
        return solve(H//2,i*2+1)
    
H=int(input())

ans = solve(H,1)
print(ans)
# Judge status: Wrong Answer
n=int(input())
a=list(map(int,input().split()))

b=max(a)
k=0

while b!=0:
    b=b//2
    k+=1

ans=0

for i in range(k):
    x=0
    y=0
    for j in range(n):
        if (a[j]>>i)%2==1:
            x+=1
        else:
            y+=1
    ans+=(2**i)*(x*y)
print(ans)
# Judge status: Wrong Answer
N = input()
TA = input().split()
T = int(TA[0])
A = int(TA[1])

first = True
place = 0
minTmep = 0

H = list(map(int, input().split()))
for i in range(0,len(H)):
    compare = abs(A * 1000 - T*1000 - H[i] * 0.006 * 1000)
    if first == True:
        place = i
        minTmep = compare
        first = False
    
    if minTmep > compare:
        place = i
        minTmep = compare

print(place + 1)
# Judge status: Accepted
import math
#切る回数を足してK以下ならOK
def ok(l):
    x =sum([math.ceil(a/l) -1 for a in A])
    if x <=K:
        return True
   # else:
    #    return False

# 初期入力
import bisect
import sys
input = sys.stdin.readline  #文字列では使わない
N,K = map(int, input().split())
A = list(map(int, input().split()))

#2分探索
bottom,top =0,max(A)
while top -bottom >1:
    mid =(top +bottom)//2
    if ok(mid):
        top =mid
    else:
        bottom =mid
print(top)
# Judge status: Accepted
N, D = map(int, input().split())
import math
print(math.ceil(N/(2*D+1)))
# Judge status: Accepted
n = int(input())
s = input()
#a = list(map(int,input().split()))

if n % 2 != 0 :
    print("No")
else:
    mae = s[0:int(n/2)]
    usi = s[int(n/2):]
    if mae == usi :
        print("Yes")
    else:
        print("No")
# Judge status: Accepted
N,M,X=map(int,input().split())
C=[]
A=[]
for _ in range(N):
    Y=list(map(int,input().split()))
    C.append(Y[0])
    A.append(Y[1:])
res=10**9
for bit in range(2**N):
    sums=0
    array=[0]*M
    for i in range(N):
        if bit>>i&1:
            for j in range(M):
                array[j]+=A[i][j]
            sums+=C[i]
    if all((a>=X for a in array)):
        res=min(res,sums)

print(res if res!=10**9 else -1)
# Judge status: Wrong Answer
if __name__== '__main__':
  s = input('>>')
  if s[0] == 'A' and s[1] == 'A' and s[2] == 'A':
        	print('No')
  elif s[0] == 'B' and s[1] == 'B' and s[2] == 'B':
      		print('No')
  else:
        	print('Yes')
# Judge status: Accepted
s=input()
print("x"*(len(s)))
# Judge status: Wrong Answer
import sys
sys.setrecursionlimit(10 ** 7)

from string import ascii_lowercase
d = dict(zip(ascii_lowercase, range(26)))
N = int(input())

def nexts(s, n):
    if n == N:
        print(s)
        return
    prenum = d[s[-1]] + 1
    for i in range(prenum+1):
        nexts(s + ascii_lowercase[i], n+1)

nexts('a', 1)
# Judge status: Wrong Answer
a,b,c = map(int,input().split())
print(str(c)+str(a)+str(b))
# Judge status: Wrong Answer
def resolve():
	n = int(input())
	if n % 4 == 0 or n % 7 == 0 or n % 11 == 0:
		print('Yes')
	else:
		print('No')
resolve()
# Judge status: Wrong Answer
c = input()
p = "aeiou"
c = "i"
if c in p:
    print("vowel")
else:
    print("consonant")
# Judge status: Accepted
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)


k = int(input())
sum = 0
for a in range(1,k+1):
    for b in range(1,k+1):
        if gcd(a,b) == 1:
            sum += 1 * k
            continue
        for c in range(1,k+1):
            sum += gcd(a,b,c)

print(sum)
# Judge status: Accepted
S = input()

if S[-1] == "s":
    print(S + "es")
else:
    print(S + "s")
# Judge status: Accepted
N = int(input())
A = list(map(int, input().split()))
ans = 0
minus = 0
mimax = - float('inf')
B = []
for i in range(N):
    if A[i] < 0:
        minus += 1
        B.append(-A[i])
    else:
        B.append(A[i])

if minus % 2 == 0:
    print(sum(B))
else:
    print(sum(B) - 2 * min(B))
# Judge status: Wrong Answer
n=int(input())
ans=[]
a=[list(input()) for _ in range(n)]
for i in a[0]:
  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: Accepted
print('YNEOS'[int(input().replace(' ',''))%4>0::2])
# Judge status: Wrong Answer
K, S = map(int, input().split())
count = 0
for x in range(K+1):
  for y in range(1,K+1):
    for z in range(1,K+1):
      print(x,y,z,x+y+z,S)
      if x + y + z == S:
        count = count + 1
print(count)
# Judge status: Wrong Answer
n,m = map(int, input().split())
set_a = set()
set_b = set()
AB = [list(int(x) for x in input().split()) for _ in range(m)]


for a,b in AB:
  if a > b:
    a,b = b,a
  
  if a == 1:
    set_a.add(b)
  if b == n:
    set_b.add(a)

se = set_a and set_b
print('POSSIBLE' if se else 'IMPOSSIBLE')
# Judge status: Wrong Answer
X = input()

X = int(X)

if X >= 40:
    print('YES')
else:
    print('NO')
# Judge status: Wrong Answer
N=int(input())
a=[111,222,333,444,555,666,777,888,999,1111]
for x in a:
  if N>=x:
    print(x)
    break
# Judge status: Wrong Answer
a,b,c=map(int,input().split())
print("Yes" if a<=c>=b else "No")
# Judge status: Accepted
n = int(input())
print(999-(n-1)%1000)
# Judge status: Wrong Answer
N = int(input())
worddict = {}
for i in range(N):
  s = input()
  if s in worddict:
    worddict[s] += 1
  else:
    worddict[s] = 1
    
M = int(input())
for i in range(M):
  t = input()
  if t in worddict:
    worddict[t] -= 1
    
maxyen = 0
for i in worddict:
  maxyen = max(maxyen, worddict[i])
# Judge status: Wrong Answer
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# 問題：https://atcoder.jp/contests/abc135/tasks/abc135_b

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

count = 0
for i in range(n):
    if p[i] != n - i:
        count += 1

if count > 2:
    print('NO')
else:
    print('YES')
# Judge status: Wrong Answer
a,b,k = map(int,input().split())
c = 0
lis = []
for i in range(1,100):
    if a%i == 0 and b%i == 0:
        lis.append(i)
print(lis[-k])
# Judge status: Wrong Answer
import math

abcd = int(input())

a = abcd // 1000
b = (abcd - a * 1000) // 100
c = (abcd - a * 1000 - b * 100) // 10
d = abcd % 10

for i in range(2**3):
    siki = []
    for j in range(3):
        if(i >> j & 1):
            siki.append("+")
        else:
            siki.append("-")
    siki2 = str(a) + siki[0] + str(b) + siki[1] + str(c) + siki[2] + str(d)
    if(eval(siki2) == 7):
        print(siki2+"=7")
# Judge status: Accepted
str = input()
ans = 0
list_ans=[]
flag = 0
for i in range(len(str)):
    if str[i] == 'R':
        if flag == 0:
            ans = 1
        else:
            ans += 1
        flag = 1
    else:
        flag = 0
        list_ans.append(ans)
list_ans.append(ans)
print(max(list_ans))
# Judge status: Accepted
a,b = map(int,input().split())
if a < b:
	if a * b < 0:
		print(abs(abs(a) - b) + 1)
	else:
		print(b - a)
else:
	if a * b <= 0:
		print(abs(a - abs(b)) + 1)
	else:
		print(2 + abs(a - b))
# Judge status: Accepted
# 079_a
N=int(input())
# if 1<=N and N<=9999:
#
n=str(N)
if (n[0]==n[1] and n[1]==n[2]) or (n[1]==n[2] and n[2]==n[3]):
    print('Yes')
else:
    print('No')
# Judge status: Accepted
x,a,b=map(int,input().split())

if b-a<=0:
    print("delicious")
elif 0<b-a<=x:
    print("safe")
else:
    print("dangerous")
# Judge status: Wrong Answer
A, B, C = map(int,input().split())

ans = "No"

for i in range(1,B+1) :
    if (A*i)%B == C :
        ans = "Yes"

print(ans)
# Judge status: Accepted
a, b, c = (int(x) for x in input().split())
if a+b-c>=0:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
import sys
read = sys.stdin.read
def main():
    n = int(input())
    a = list(map(int, read().split()))
    odd = 0
    div4 = 0
    div2 = 0
    for ae in a:
        odd += ae % 2 != 0
        div4 += ae % 4 == 0
        div2 += ae % 2 == 0 and ae % 4 != 0
    div2r = div2 % 2
    if odd +div2r  > div4 + 1:
        print('No')
    else:
        print('Yes')


if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
N, M = map(int, input().split())
for i in range(1, M+1):
    print(str(i) + " " + str(2*M + 1 - i))
# Judge status: Wrong Answer
x = int(input())
gold = x % 500
silver = (x - 500*gold) % 5
fun = gold*1000 + silver*5
print(fun)
# Judge status: Accepted
n,m = map(int, input().split())
scl = []
for _ in range(m):
    s,c = map(int, input().split())
    scl.append((s,c))

for i in range(0, 1000):
    si = str(i)
    if len(si) != n: continue
    for sc in scl:
        s,c = sc
        if si[s-1] != str(c):
            break
    else:
        print(i)
        exit()
else:
    print(-1)
# Judge status: Accepted
a, b, c, x = [int(input()) for _ in range(4)]
ans = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if 500 * i + 100 * j + 50 * k == x:
                ans += 1
print(ans)
# Judge status: Accepted
a,b=map(int,input().split())
if a-b==0:
    print(0)
elif (a+b)%2==0:
    print(int((a+b)/2))
else:
    print("IMPOSSIBLE")
# Judge status: Wrong Answer
import heapq

N, M = map(int, input().split())
dic = {}
for i in range(N):
    A, B = map(int, input().split())
    if A not in dic:
        dic[A] = [-B]
    else:
        dic[A] += [-B]
print(dic, sorted(dic.keys()))

ans = 0
heap = []

for i in range(M):
    # print(i)
    if i + 1 in dic:
        heap += dic[i + 1]
    heapq.heapify(heap)
    # print(heap)
    if heap:
        ans += -heapq.heappop(heap)

print(ans)