peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Wrong Answer
N = int(input())
S = []
P = []
for i in range(N):
    tmp_S, tmp_P = input().split()
    S.append(tmp_S)
    P.append(int(tmp_P)*(-1))

index = [i for i in range(1,N+1)]

ZIP = zip(P, index, S)

ZIP = sorted(ZIP)

P, index, S = zip(*ZIP)

for i in range(N):
    print(index[i])
    print(S[i])

ZIP = zip(S, index)

ZIP = sorted(ZIP)

S, index = zip(*ZIP)

for i in range(N):
    print(index[i])
# Judge status: Accepted
N=int(input())
A=list(map(int,input().split()))
flag=0
count=1
for i in range(1,N):
    if A[i-1]<A[i]:
        if flag==-1:
            count+=1
            flag=0
        elif flag==0:
            flag=1
    elif A[i-1]>A[i]:
        if flag==1:
            count+=1
            flag=0
        elif flag==0:
            flag=-1
print(count)
# Judge status: Accepted
r = int(input())

print(r ** 2)
# Judge status: Accepted
N, K = map(int,input().split())
S = input()
ans = []
for i in range(N):
    if i == K - 1:
        x = ord(S[i])
        x += 32
        y = chr(x)
        ans.append(y)
    else:
        ans.append(S[i])

print(''.join(ans))
# Judge status: Accepted
import sys
x = int(input())
for i in range(-120, 120):
    for j in range(-120, 120):
        if i**5 - j**5 == x:
            print(i, j)
            sys.exit()
# Judge status: Wrong Answer
N, M = map(int, input().split())
a = []
b = []
for i in range(N):
    a.append(input())
c = 0
for i in range(M):
    b.append(input())
for i in range(N-M+1):
    for j in range(N-M+1):
        for k in range(M):
            s1 = a[i][j:j+M] 
            s2 = b[k]
            if s1 != s2:
                break
        else:
            print("Yes")
print("No")
# Judge status: Wrong Answer
S = input()
l = ['+', '-']
for i in range(2):
  for j in range(2):
    for k in range(2):
      exp = S[0] + l[i] + S[1] + l[j] + S[2] + l[k] + S[3]
      if eval(exp) == 7:
        print(exp + '=7')
        break
# Judge status: Accepted
a, b = map(int, input().split())
print('Yay!') if a <= 8 and b <= 8 else print(':(')
# Judge status: Accepted
# B - Qualification simulator
n, a, b = map(int, input().split())
passed_count = 0
oversea_rank= 0

for s in input():
	if s == 'a':
		if passed_count < a + b:
			print('Yes')
			passed_count += 1
		else:
			print('No')
	elif s == 'b':
		oversea_rank += 1
		
		if passed_count < a + b and oversea_rank <= b:
			print('Yes')
			passed_count += 1
		else:
			print('No')
	else:
		print('No')
# Judge status: Accepted
N = int(input())
xxx = [111, 222, 333, 444, 555, 666, 777, 888, 999]
for i in range(N, 1000):
    if i in xxx:
        print(i)
        exit()
# Judge status: Accepted
n, a, b = map(int, input().split())

total = 0
for i in range(1, n+1):
    s = str(i)
    tmp = 0
    for j in s:
        tmp += int(j)
    if a <= tmp <= b:
        total += i
print(total)
# Judge status: Accepted
import re
def main():
  S = input()
  if 'keyence' in S:
    print('YES')
    return
  
  if re.match(r'^k[a-z]*eyence$', S) or re.match(r'^ke[a-z]*yence$', S) or re.match(r'^key[a-z]*ence$', S) or re.match(r'^keye[a-z]*nce$', S) or re.match(r'^keyen[a-z]*ce$', S) or re.match(r'^keyenc[a-z]*e$', S):
    print('YES')
  else:
    print('NO')
  return

if __name__ == '__main__':
  main()
# Judge status: Accepted
N, A, B = map(int, input().split())
r = N//(A+B)
print(r*A+min(A, N-r*(A+B)))
# Judge status: Wrong Answer
n = int(input())
i = 1
cnt = 0
while i < n:
    if len(str(i)) % 2 >= 1:
        cnt += 1
    i += 1
print(cnt)
# Judge status: Accepted
N = int(input())

L = [0] * 100

for i in range(1,N+1):
    if i % 10 == 0:
        continue
    a = (i // (10 ** (len(str(i)) - 1))) * 10 + i % 10
    L[a] += 1
    
ans = 0
for i in range(100):
    if L[i] == 0:
        continue
    if i // 10 == i % 10:
        ans += L[i] ** 2
    else:
        a = i // 10 + (i % 10) * 10
        ans += L[i] * L[a]

print(ans)
# Judge status: Accepted
l = list(map(int,input().split()))
ans = 0
if l[0] == l[1] == l[2] and all(i % 2 == 0 for i in l):
  print(-1)
  exit()
while all(i % 2 == 0 for i in l):
  a = l[0]//2; b = l[1]//2; c = l[2]//2;
  l[0] = b + c
  l[1] = a + c
  l[2] = a + b
  ans += 1
print(ans)
# Judge status: Accepted
import math
N, D = map(int, input().split())

print (math.ceil(N/(D*2 + 1)))
# Judge status: Wrong Answer
N = input()
A = list(input().split())
A = list(map(int,A))
A = sorted(A,reverse = True)
a = 0
b = 0
try :
  a += A.pop(0)
  b += A.pop(0)
except IndexError :
  print(a-b)
print(a-b)
# Judge status: Accepted
n = int(input())
x_l = list(map(int,input().split()))
s_x_l = sorted(x_l)

med_idx = n//2
med_l = s_x_l[med_idx-1]
med_r = s_x_l[med_idx]

for i in range(n):
    if  x_l[i] <= med_l:
        print(med_r)
    else:
        print(med_l)
# Judge status: Wrong Answer
def resolve():
	n = int(input())
	a = list(map(int, input().split()))
	ans = 100**6
	for i in range(-100, 100):
		tmp = 0
		for j in a:
			tmp += (j - i)**2
		if tmp < ans:
			ans = tmp
	print(ans)

resolve()
# Judge status: Wrong Answer
s = input()
maximum = [(0, ())]

s = tuple(s)
for i in range(1, len(s) + 1):
    j = i - 1
    while j >= 0:
        max_count, previous = maximum[j]
        if max_count < 0:
            j -= 1
            continue
        current = s[j:i]
        if current != previous:
            maximum.append((max_count + 1, current))
            break
        j -= 1
    else:
        maximum.append((-1, ()))

print(maximum[-1][0])
# Judge status: Wrong Answer
from fractions import gcd
n, x = tuple(map(int, input().split(' ')))
d = 0
l = list(map(int, input().split(' ')))
for i in range(n):
  s = l[i]
  if i == 0:
    d = s - x
  else:
    d = gcd(d, s-x)
print(d)
# Judge status: Accepted
N, A, B = map(int, input().split())
if N%(A+B) < A:
    print(N%(A+B) + N//(A+B) * A)
else:
    print(A + N//(A+B) * A)
# Judge status: Wrong Answer
N,K=map(int,input().split())
A=list(map(int,input().split()))
A_max=max(A)
for i in range(N):
    A[i]=A[i]/A_max
ans=list()
tmp=1
for i in range(K):
    tmp=tmp*A[i]
for i in range(K,N):
    tmp_old=tmp
    tmp=tmp_old*A[i]/A[i-K]
    if tmp_old<tmp:
        ans.append('Yes')
    else:
        ans.append('No')
for i in ans:
    print(i)
# Judge status: Accepted
from collections import Counter

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

c = Counter(A)

if len(c)==N:
  print(N)
  exit()
elif len(c)==N-1:
  print(N-2)
  exit()

ans = 0
for k in c.keys():
  if c[k] % 2 == 1:ans += 1
    
print(ans)
# Judge status: Wrong Answer

N, K = map(int,input().split())
ans = 0
MOD = 10**9+7
for i in range(K,N+1):
  num = ((2*N-i+1)*i)//2 - ((i-1)*i)//2
  ans+=num%MOD
ans%=MOD
print(ans)
# Judge status: Accepted
import numpy as np
n = int(input())
t,a = map(int,input().split())
h = list(map(int,input().split()))
h = list(map(lambda x:abs(t-0.006*x-a),h))
print(np.argmin(h)+1)
# Judge status: Accepted
S=lambda:input()
I=lambda:int(input())
L=lambda:list(map(int,input().split()))
def main():
    n=I()
    trans=[I(),I(),I(),I(),I()]
    trans.sort()
    print(n//trans[0]+5 if n/trans[0]%1!=0 else n//trans[0]+4)
    

if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
def frog(arr,n,k):
    if k>n:
        return 0
    dp=[0]*(n+1)
    for i in range(2,n+1):
        dp[i]=10**9
        for j in range(i-1,0,-1):
            if i-j<=k:
                dp[i]=min(dp[j]+abs(arr[i-1]-arr[j-1]),dp[i])
                
    return dp[n]





value=[int(i) for i in input().split()]
n,k=value[0],value[1]
arr=[int(i) for i in input().split()]

print(frog(arr,n,k))
# Judge status: Accepted
n,m=map(int,input().split())
lange=[1]*(n+1)
for i in range(1,n+1):
  a=i
  b=n-a
  if lange[a]:lange[b]=0
langes=[]
for i in range(1,n):
  if lange[i]:
    if len(langes)%2:langes.append(i)
    else:langes.append(n-i)
langes.sort(reverse=1)
for i in range(m):print(i+1,i+1+langes[i])
# Judge status: Accepted
A, B, K = list(map(int, input().split()))

if A <= K:
    K = K - A
    A = 0
    if B <= K:
        K = K - B
        B = 0
    else:
        B = B - K
else:
    A = A - K 
        
print(str(A) + ' ' + str(B))
# Judge status: Accepted
w1, h1, n = map(int, input().split())
w0 = 0
h0 = 0
for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        w0 = max(w0, x)
    elif a == 2:
        w1 = min(w1, x)
    elif a == 3:
        h0 = max(h0, y)
    else:
        h1 = min(h1, y)
print(max(0, (w1 - w0)) * max(0, (h1 - h0)))
# Judge status: Wrong Answer
a=str(input())
ct=0
for i in range(10):
    ct+=a.count('10')
    a=a.replace("10", "").strip()
    ct+=a.count('01')
    a=a.replace("01", "").strip()
print(ct*2)
# Judge status: Accepted
a, b = map(int, input().split())

if (a * b) % 2  == 0:
    print('Even')
else:
    print('Odd')
# Judge status: Accepted
n=int(input())
x=""
while n != 0:
    x = str(n%2) + x
    n = -(n//2)
print(0 if x == "" else x)
# Judge status: Accepted
N=int(input())
K=int(input())
X=int(input())
Y=int(input())

ex=N-K
if ex<0:
  charge=N*X
else:
  charge=K*X+ex*Y

print(charge)
# Judge status: Accepted
import sys
input = sys.stdin.readline
c1 = input().strip()
c2 = input().strip()
flag = True
for i in range(3):
    if c1[i] != c2[-(i+1)]:
        flag = False
        break
if flag:
    print("YES")
else:
    print("NO")
# Judge status: Accepted
N = int(input())
A,B = map(int,input().split())

c=N*(A//N+1)

if c>B and A%N!=0:
    print("NG")
else:
    print("OK")
# Judge status: Accepted
import collections as c
import sys
s = input()
l = len(s)

if l == 1:
	print("YES")
else:
	S = c.Counter(list(map(str,s)))
	if len(S.keys()) == 1:
		print("NO")
		sys.exit()
	elif len(S.keys()) == 2:
		if l == 2:
			print("YES")
		else:
			print("NO")
		sys.exit()

	cnt = set(list(S.values()))

	if len(cnt) == 3:
		print("NO")
	elif len(cnt) == 2:
		a,b = cnt
		if abs(a-b) <= 1:
			print("YES")
		else:
			print("NO")
	else:
		print("YES")
# Judge status: Accepted
a = int(input())
b = int(input())

n = [1,2,3]
n[a-1] = 0
n[b-1] = 0

for i in range(len(n)):
  if n[i] != 0:
    print(n[i])
# Judge status: Wrong Answer
word=input()
word=sorted(word)
print(word)

if word[0]==word[1] and word[2]==word[3]:
    if word[0]!=word[2] and word[1]!=word[3]:
        print('Yes')
    else:
        print('No')
else:
    print('No')
# Judge status: Accepted
import numpy as np
N = int(input())
comfort = list(map(int,input().split()))
comfort_reverse = np.sort(comfort)[::-1]

ans = comfort_reverse[0]

if N > 2:
    for i in range(N-2):
        num = i // 2 + 1
        ans += comfort_reverse[num]

print(ans)
# Judge status: Accepted
N,K=[int(i) for i in input().split()]
h=sorted([int(input()) for _ in range(N)])

ans=10**9

for i in range(N-K+1):
    if ans>h[i+K-1]-h[i]:
        ans=h[i+K-1]-h[i]
    else:
        continue
print(ans)
# Judge status: Accepted
from math import factorial
pos = map(int, input().split())
p = 10**9 + 7
x, y = sorted(pos)

if (x+y) % 3 != 0:
    print(0)
    exit()

n = (-x + 2 * y) // 3
m = (-y + 2 * x) // 3

# Python3 function to
# calculate nCr % p


def ncr(n, r, p):
    # initialize numerator
    # and denominator
    num = den = 1
    for i in range(r):
        num = (num * (n - i)) % p
        den = (den * (i + 1)) % p
    return (num * pow(den,
                      p - 2, p)) % p


ans = ncr(n+m, n, p)
print(ans)
# Judge status: Wrong Answer
N=int(input())
A= list(map(int,input().split()))
value_count=0
for i in range(N):
    for j in range(N):
        if(i!=j):
            if(A[i]%A[j]!=0):
                if(j==N-1):
                    value_count += 1
            else:
                break
print(value_count)
# Judge status: Accepted
S = input()
n = len(S)
prev = '-1'
ans = 0
obj = S[0]
for i in range(n):
    # print(prev, obj)
    if prev != obj:
        prev = obj
        ans += 1
        if i+1 < n:
            obj = S[i+1]
    else:
        if i+1 < n:
            obj += S[i+1]
    # if prev != S[i]:
    #     ans += 1
    #     prev = S[i]
    # else:
    #     prev += S[i]
    # print(prev)

print(ans)
# Judge status: Accepted
h,w=input().split(" ")
h,w=int(h),int(w)
if h==1 or w==1:
  print(1)
elif h*w%2==0:
  print(int(h*w/2))
else:
  print(int(h*w//2+1))
# Judge status: Accepted
N = int(input())
W = list(map(int,input().split()))
ans = sum(W)
for i in range(1,N):
    A = sum(W[0:i])
    B = sum(W[i:])
    ans = min(ans,abs(A-B))
print(ans)
# Judge status: Wrong Answer
S = input()
l = sorted(list(set(S)))

ans ="None"
number = [96]
for i in range(len(l)):
  if ord(l[i]) ==  number[-1] + 1:
    number.append(ord(l[i]))
  else:
    ans = chr(number[-1]+1)
    break

print(ans)
# Judge status: Accepted
S = list(input())

s = set(S)

L = len(S)

l = len(s)

if L == l:
  print('yes')

else:
  print('no')
# Judge status: Wrong Answer
n=int(input())
a=set()
b=[]
import collections
import math
for i in range(n):
    s=input()
    s=sorted(s)
    a.add("".join(s))
    b.append("".join(s))
ans=0
a=list(a)
c=collections.Counter(b)
for i in range(len(a)):
    ans+=math.factorial(c[a[i]])
print(ans-len(a))
# Judge status: Accepted
s = str(input())
alphabet = list('abcdefghijklmnopqrstuvwxyz')
for i in alphabet:
    if i in s:
        continue
    else:
        print(i)
        exit(0)
print('None')
# Judge status: Wrong Answer
input_num = input().split()
dice_num = int(input_num[0])
border_socre = int(input_num[1])
ans_p = 0

for score in range(1,dice_num + 1):
    coin_counter = 0
    
    while score <= border_socre:
        score = score * 2
        coin_counter += 1
    ans_p += (1 / dice_num ) * (1/2 ) ** coin_counter
print(ans_p)
# Judge status: Accepted
H,N = map(int,input().split())
inf = 1000000000
dp = [inf for _ in range(20001)]
magics = []
dp[0] = 0
for i in range(N):
    magic = list(map(int,input().split()))
    magics.append(magic)
for j in range(10001):
    for k in magics:
        dp[j+k[0]] = min(dp[j]+k[1],dp[j+k[0]])
ans = dp[H:]
print(min(ans))
# Judge status: Accepted
N = input()

if N[0]=='7' or N[1]=='7' or N[2]=='7':
    print('Yes')

else:
    print('No')
# Judge status: Wrong Answer
n,a,b = map(int,input().split())
if n==1:
  if a==b:
    print(1)
  else:
    print(0)
else:
  k = b-a
  if k < 0:
    print(0)
  elif k==0:
    print(1)
  else:
    print(b*k - a*k+1)
# Judge status: Accepted
n = int(input())
listed = list(map(int,input().split()))

length2 = len(set(listed))

if n == length2:
    print('YES')
else:
    print('NO')
# Judge status: Accepted
X, Y = map(int, input().split())
if X % Y == 0:
    print(-1)
else:
    n = 1
    while True:
        if X*n % Y != 0:
            print(X*n)
            break
        else:
            n += 1
# Judge status: Accepted
x,y=map(int,input().split())
print(y-x if x<=y and (0<=x or y<=0) else 2+x-y if y<x and (x<0 or 0<y) else 1+abs(x+y))
# Judge status: Accepted
a = [int(i) for i in input().split()]
if (a[0] == a[1] and a[0] != a[2]) or (a[0] == a[2] and a[0] != a[1]) or (a[2] == a[1] and a[2] != a[0]):
    print('Yes')
else:
    print('No')
# Judge status: Accepted
S = input()

n = S.count('N')
s = S.count('S')
w = S.count('W')
e = S.count('E')
a = 0

if n > 0:
    a += 1
if s > 0:
    a -= 1
if w > 0:
    a += 2
if e > 0:
    a -= 2

if a == 0:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
r = int(input())
print(int(r*r/1))
# Judge status: Accepted
n=int(input())
print((10**n-2*9**n+8**n)%1000000007)
# Judge status: Accepted
N=int(input())
A=[list(map(int,input().split())) for i in range(N-1)]
for i in range(N):
  t=0
  for j in range(i,N-1):
    if t<A[j][1]:
      t=A[j][1]
    elif (t-A[j][1])%A[j][2]:
      t+=A[j][2]-t%A[j][2]
  
    t+=A[j][0]
  print(t)
# Judge status: Wrong Answer
n = int(input())
ans = 0
for i in range(1,n + 1):
    print(i)
    if 10 <= i < 100 or 1000 <= i < 10000 or i == 100000:
        ans = ans
    else:
        ans += 1
print(ans)
# Judge status: Accepted
A,B,C,D=map(int,input().split(' '))
if abs(A-C) <= D or ((abs(B-A)) <= D and abs(B-C)<=D):
    print('Yes')
else:
    print('No')
# Judge status: Wrong Answer
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
from bisect import bisect_left
 
 
n, m = map(int, input().split())
a = list( map(int, input().split()))
a.sort()
 
bc = [[int(x) for x in input().rstrip().split()]for i in range(m)]
bc.sort(reverse=True, key=lambda x: x[0])

 
i = 0
d = []
for b, c in bc:
    d.extend([c]*b)
    if len(d) >= n:
        break
 
a=a+d
a.sort(reverse=True)
print(sum(a[:n]))

#l.sort(reverse=True)
#A=A+l[:N]
#A.sort(reverse=True)
# Judge status: Accepted
S=input()
T=input()
T=T[0:len(T)-1]
if(S==T):
    print("Yes")
else:
    print("No")
# Judge status: Wrong Answer
N=int(input())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
C=list(map(int, input().split()))
ans = 0
for i in A:
    ans += B[i-1]
    if A.index(i) != 0:
        if i - 1 == A[A.index(i) - 1]:
            ans += C.pop(0)
            
print(ans)
# Judge status: Accepted
import sys

input = sys.stdin.readline
n, k = map(int, input().split())
h = sorted(int(input()) for _ in range(n))
print(min(r - l for l, r in zip(h[: 1 - k], h[k - 1 :])))
# Judge status: Accepted
A, B , M = map(int, input().split())
a = list(map(int, input().split()))
a_s = sorted(a)
b = list(map(int, input().split()))
b_s = sorted(b)

# cheapest
cheap = a_s[0] + b_s[0]

for i in range(M):

    # discount
    x, y, c = map(int, input().split())
    dis_cheap = a[x - 1] + b[y - 1] - c

    if cheap > dis_cheap:
        cheap = dis_cheap

print(cheap)
# Judge status: Wrong Answer
import collections
n = int(input())
s = list(input())
s_cnt = collections.Counter(s)

for i in range(n-1):
  tmp = input()
  for k in s_cnt:
    tmp_cnt = tmp.count(k)
    if tmp_cnt < s_cnt[k]:
      s_cnt[k] = tmp_cnt 

ans =""      
for k in s_cnt:
  ans += k*s_cnt[k]
print(ans[::-1])
# Judge status: Accepted
n = int(input())
count = 0
sum_of_count_8 = 0
for i in range(1,n+1,2):
    count = 0
    for j in range(1,n+1):
        if i%j ==0:
            count+=1
    if count == 8:
        sum_of_count_8 += 1
print(sum_of_count_8)
# Judge status: Wrong Answer
n, k = map(int, input().split())
p = list(map(int,input().split()))

ans = 0

for i in range(k):
    ans += p[i]

print(ans)
# Judge status: Accepted
N,M = map(int,input().split())


ans = []
s = 1
e = M+1
while e>s:
    ans.append([s,e])
    s += 1
    e -= 1

s = M+2
e = 2*M+1
while e>s:
    ans.append([s,e])
    s += 1
    e -= 1

for s,e in ans:
    print(s,e)
# Judge status: Accepted
#147_D
n = int(input())
A = list(map(int, input().split()))
ans = 0
mod = 10 ** 9 + 7

for i in range(60):
    s = sum([(a >> i) & 1 for a in A])
    ans = (ans + s * (n-s) * pow(2,i,mod)) % mod
print(ans)
# Judge status: Accepted
# coding: utf-8
# Your code here!
S=input()

if "E" in S or "W" in S:
    if "E" in S and "W" in S:
        pass
    else:
        print("No")
        exit()

if "N" in S or "S" in S:
    if "N" in S and "S" in S:
        pass
    else:
        print("No")
        exit()

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

if abs(a-c) <= d:
  print("Yes")
print("No")
# Judge status: Wrong Answer
N=int(input())

ans='a'*N
ans_code=[0]*N
for i in range(N):
    ans_code[i]=ord(ans[i])
#print(ans_code)

for k in ans_code:
        print(chr(k),end='')
print('')

for i in range(1,N):
    for j in range(1,i+1):
        ans_code[-j]+=1
    #print(ans_code)
    for k in ans_code:
        print(chr(k),end='')
    print('')
    

"""
ans[-1]
for i in range(N):
    ans[]
"""
# Judge status: Accepted
N, X, Y = map(int, input().split())
X -= 1
Y -= 1

dist_l = [0] * N
for i in range(N):
    for j in range(i+1,N):
        dist_l[min(j-i, abs(i - X) + 1 + abs(Y - j))] += 1

for i in range(1,N):
    print(dist_l[i])
# Judge status: Accepted
k = int(input())
s = input()

if len(s) <= k:
    print(s)
elif len(s) > k:
    print(s[: k] + '...')
# Judge status: Wrong Answer
N=int(input())
p=[0]+list(map(int,input().split()))
d=list(range(0,N+1))
f=True
for i in range(N):
    if p[i]!=d[i]:
       for j in range(i+1,N+1):
           if p[i]==d[j] and p[j]!=d[i]:
               f=False
if f:
    print('YES')
else:
    print('NO')
# Judge status: Wrong Answer
a = list(input())
b = list(input())

if len(a) == len(b):
    for i in range(0, len(a)):
        print(a[i] + b[i], end = "")
# Judge status: Accepted
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

N=int(input())
x,y=[0]*N,[0]*N
for i in range(N):
    a,b=map(int,input().split())
    x[i],y[i]=a+b,a-b
x.sort()
y.sort()
print(max(max(x)-min(x),max(y)-min(y)))
# Judge status: Accepted
import heapq
N, M = map(int,input().split())
L = [[] for _ in range(M)]
for _ in range(N):
    A, B = map(int,input().split())
    try:
        L[A-1].append(-B)
    except:
        pass
Q = []
ans = 0
for i in range(M):
    for j in L[i]:
        heapq.heappush(Q, j)
    try:
        ans -= heapq.heappop(Q)
    except:
        pass
print(ans)
# Judge status: Wrong Answer
n = input()

ans = 0

tmp = len(n)-1

if n[0] == '1':
    print(9*tmp)
else:
    print(9*tmp + int(n[0])-1)
# Judge status: Accepted
s = list(input())
if s[2] == s[3] and s[4] == s[5]:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    s = input()
    n = len(s)

    subss = [""]
    subs = ""
    res = 0
    for i in range(n):
        subs += s[i]
        if subss[-1] != subs:
            subss.append(subs)
            res += 1
            subs = ""

    print(res)


if __name__ == '__main__':
    resolve()
# Judge status: Wrong Answer
N,M = list(map(int,input().split()))
N_list=[[] for n in range(N)]

for m in range(M):
    P,Y=list(map(int,input().split()))
    N_list[P-1].append(Y)
    
for n in N_list:
    n.sort()
# Judge status: Accepted
W, H, N  = map(int,input().split()) 
l = 0; r = W; u = H; d = 0 

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

print(max(0,(r-l))*max(u-d, 0))
# Judge status: Accepted
# coding: utf-8
# Your code here!
n = int(input())
string = str(1)
for i in range(2,n + 1):
    string += str(i)

x = []    
import itertools
for i in itertools.permutations(string):
    x.append(i)
    
a = tuple(input().split(" "))
b = tuple(input().split(" "))

for i,j in enumerate(x):
    if a == j:
        a_res = i + 1
    if b == j:
        b_res = i + 1

print(abs(a_res - b_res))
# Judge status: Accepted
import fractions
N,X = map(int,input().split())
x = list(map(int,input().split()))
D = abs(x[0]-X)
for i in range(1,N):
    D = fractions.gcd(D, abs(X-x[i]))
print(D)
# Judge status: Accepted
def main():
	S = input()

	border = len(S)

	while True:
		if S[border - 5: border] == "dream":
			border -= 5
		elif S[border - 7: border] == "dreamer":
			border -= 7
		elif S[border - 5: border] == "erase":
			border -= 5
		elif S[border - 6: border] == "eraser":
			border -= 6
		else:
			break

	if border == 0:
		print("YES")
	else:
		print("NO")
 
 
if __name__ == "__main__":
  	main()
# Judge status: Accepted
n = int(input())
A = list(map(int,input().split()))

dp = [[0]*2 for i in range(n)]

dp[0][0] = A[0]
dp[0][1] = -A[0]

for i in range(1,n):
    dp[i][0] = max(dp[i-1][0]+A[i],dp[i-1][1]-A[i])
    dp[i][1] = max(dp[i-1][0]-A[i],dp[i-1][1]+A[i])

print(dp[n-1][0])
# Judge status: Wrong Answer
n = int(input())
num = list(map(int,input().split()))
# print(num)
# mul = int(input().split())
cnt = 0
for i in range(2,n+1,2):
    if(num[i-1] % 2 != 0):
        cnt += 1
print(cnt)
# Judge status: Accepted
import fractions
A, B = map(int, input().split())
print (int(A * B // (fractions.gcd(A,B))))
# Judge status: Wrong Answer
total_list = sorted(list(map(int, input().split())))

if sum(total_list[1:]) == total_list[0]:
    print('Yes')
else:
    print('No')
# Judge status: Wrong Answer
n , k = map(int , input().split())
ans = 0
m = 1
while m < n:
    m = m * k
    ans += 1
print(ans)
# Judge status: Accepted
S, W = (int(i) for i in input().split())  

if (S <= W):
    print("unsafe")
else:
    print("safe")