peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Wrong Answer
a,b = map(int, input().split())
print((a+b)/2) if ((a+b)%2 == 0)&(a!=0)&(b!=0) else print("IMPOSSIBLE")
# Judge status: Accepted
n = int(input())

ans = 1
for i in range(n):
    ans = (ans * (i + 1)) % (10**9 + 7)
print(ans)
# Judge status: Wrong Answer
from collections import defaultdict

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

d = defaultdict(lambda: N+1)

for i in range(N):
    for c in range(ord("a"), ord("z")+1):
        d[chr(c)] = min(d[chr(c)], S[i].count(chr(c)))

ans = ""
for key, value in d.items():
    ans += key * value

print(ans)
# Judge status: Accepted
n, k = map(int, input().split())
S = str(input())
hap = 0
for i in range(1, len(S)):
    if S[i-1] == S[i]:
      hap += 1
ans = min(hap + k*2, n-1)
print(ans)
# Judge status: Accepted
n=int(input())
for i in range (0,8):
    if 2**i<=n:
        pass
    else:
        print(2**(i-1))
        break
# Judge status: Accepted
N, M = map(int, input().split())
print(max(N-2, N%2) * max(M-2, M%2))
# Judge status: Wrong Answer
import re

S = input()

list_string = ['dream', 'dreamer', 'erase', 'eraser']
regex = r'(dream(er)?eraser?)+|(eraser?dream(er)?)+|(((dream(er)?)|(eraser?))+)'

def check(list_string, regex, S):
    while S:
        if re.search(regex, S):
            S =  re.sub(regex, '', S)

        else:
            return 'NO'
    return 'YES'

print(check(list_string, regex, S))
# Judge status: Wrong Answer
import itertools

n = int(input())

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

li = list(itertools.combinations(li, 3))

# print(li)
count = 0

for i in li:
    print(i)
    amari = sum(i) - max(i)
    if amari > max(i):
        if len(set(i)) == 3:
            count += 1

print(count)
# Judge status: Wrong Answer
import math
import numpy


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

n = int(numpy.log2(numpy.longdouble(y/x)))

print(n+1)
# Judge status: Accepted
a = int(input())
s = input()

if a < 3200:
    print('red')
else:
    print(s)
# Judge status: Accepted
n, a, b = map(int, input().split())
dist = abs(a-b)-1
if dist % 2 != 0:
    ans = dist//2+1
else:
    dist -= 1
    ans = min(a+dist//2+1, n-b+1+dist//2+1)

print(ans)
# Judge status: Accepted
n,k=map(int, input().split())
ans=1
while 1:
  n//=k
  if n>0: ans+=1
  else: break
print(ans)
# Judge status: Accepted
a = sorted(list(map(int, input().split(" "))))
count = 0
a[0] += a[2] - a[1]
count += a[2] - a[1]

if (a[2] - a[0]) % 2 == 0:
  print(count +  ((a[2] - a[0]) // 2))
else:
  print(count +  ((a[2] - a[0]) // 2) + 2)
# Judge status: Accepted
a = int(input())
b = int(input())

c = 6 - a - b
print(c)
# Judge status: Wrong Answer
s=input()
if s[-1]==s:
    s+='es'
else:
    s+='s'
print(s)
# Judge status: Accepted
n = int(input())
ns = list(list(input()) for i in range(n))
ns_set = set()
for i in range(n):
    ns_set |= set(ns[i])
from collections import defaultdict
dic = defaultdict(lambda : 50)
for i in range(n):
    for s in ns_set:
        if s in ns[i]:
            dic[s] = min(dic[s], ns[i].count(s))
        else:
            dic[s] = 0
result = ''
for key, value in sorted(dic.items(), key=lambda x: x[0]):
    result += key*value
print(result)
# Judge status: Wrong Answer
n=int(input())
p=list(map(int,input().split()))

c=0
for i in range(n-1):
    if p[i-1]<=p[i]<=p[i+1] or p[i+1]<=p[i]<=p[i-1]:
        c+=1
print(c)
# Judge status: Wrong Answer
x, a, b = map(int, input().split())
if b - a <= 0:
    print("delicious")
elif b - a < x and 0 < b - a:
    print("safe")
else:
    print("dangerous")
# Judge status: Wrong Answer
n = input()

if set(list(n)) == {'9'}:
    print(len(list(n))*9)
    exit()

tmp = ''
for i in range(1,len(n)):
    if n[i] == '9':
        tmp += n[i-1]
    else:
        tmp += str(int(n[i-1])-1) + '9'*(len(n)-i)
        break
else:
    tmp += '9'

ans=0
for i in range(len(tmp)):
    ans += int(tmp[i]) 

print(ans)
# Judge status: Accepted
N,M,K = map(int, input().split())
for i in range(N+1):
    b = i * M
    for j in range(M+1):
        b -= i
        b += N-i
        if b == K:
            print('Yes')
            exit()
print('No')
# Judge status: Wrong Answer
import functools
N,M = map(int,input().split())
A = [int(i)//2 for i in input().split()]

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

def mul(a,b):
    return a*b//euclid(a,b)

def lcm(S):
    
    return functools.reduce(mul,S)

ans = M//lcm(A)
ans = (ans+1)//2
print(ans)
# Judge status: Wrong Answer
a, b = map(int, input().split())
ans = 0
if a > b:
  for i in range(b, a + 1):
    if b * i % a == 0:
      ans = b * i
      break
else:
  for i in range(a, b + 1):
    if a * i % b == 0:
      ans = a * i
      break
print(ans)
# Judge status: Accepted

def resolve():
    X, N = map(int, input().split())
    if N == 0:
        print(X)
        return
    A = set(map(int, input().split()))
    dic = {}
    for i in range(-10, 110):
        if i not in A:
            dic[i] = abs(X-i)

    sorted_A = sorted(dic.items(), key=lambda x:(x[1], x[0]))
    print(sorted_A[0][0])

if __name__ == "__main__":
    resolve()
# Judge status: Accepted
n = int(input())
li = []
for a in range(1, n):
    b = n - a
    a_sum = sum([int(x) for x in str(a)])
    b_sum = sum([int(y) for y in str(b)])
    total_sum = a_sum + b_sum
    li.append(total_sum)
print(min(li))
# Judge status: Accepted
n, m=map(int, input().split())

if n==1 and m==1:
    print(1)
elif n==1 and m!=1:
    print(m-2)
elif n!=1 and m==1:
    print(n-2)
else:
    ans = (m-2)*(n-2)
    print(ans)
# Judge status: Accepted
n,k=map(int,input().split());s=set(range(1,-~n))
for _ in range(k):
 input();s-=set(map(int,input().split()))
print(len(s))
# Judge status: Accepted
N,M,K=map(int,input().split())

for i in range(N+1):
    for j in range(M+1):
        if i==0 or j==0:
            x=N*j+M*i
            if x==K:
                print("Yes")
                exit()
        x=N*j+M*i-(i*j)-i*j
        #print(str(i)+" "+str(j))
        #print(x)
        if x==K:
            print("Yes")
            exit()
print("No")
# Judge status: Accepted
# -*- coding: utf-8 -*-
H, N = map(int, input().split(' '))
nums = [float('inf') for _ in range(H+1)]
nums[0] = 0

for _ in range(N):
    a, b = map(int, input().split(' '))
    for i in range(H + 1):
        j = min(H, i+a)
        nums[j] = min(nums[j], nums[i] + b)

print(nums[H])
# Judge status: Accepted
S = input()
N = len(S)

ans1 = "".join(["1" if i%2 == 0 else "0" for i in range(N)])
ans2 = "".join(["0" if i%2 == 0 else "1" for i in range(N)])

print(min(bin(int(S, 2)^int(ans1, 2)).count("1"), bin(int(S, 2)^int(ans2, 2)).count("1")))
# Judge status: Accepted
N, M = map(int, input().split())
ans = set(range(1, M+1))
for i in range(N):
  K, *A = map(int, input().split())
  ans = ans & set(A)
print(len(ans))
# Judge status: Wrong Answer
N, M = (int(x) for x in input().split())
H = [int(x) for x in input().split()]

high = set()
low = set()
lonely = set()

for i in range(M):
    i1, i2 = [int(x) for x in input().split()]
    if H[i1 - 1] != H[i2 - 1]:
        high.add(i2)
    low.add(i1)
    lonely.add(i1)
    lonely.add(i2)

result = len((high - low)) + (N  - len(lonely))
# Judge status: Accepted
import sys
import string
N = int(input())
S = input()
s = list(S)
array = string.ascii_uppercase

for I in s:
    if array.index(I) + N <= 25:
        print(array[array.index(I) + N],end='')
    else:
        print(array[(array.index(I) + N) - 26],end='')
# Judge status: Wrong Answer
#スペース区切りの整数の入力
A, B ,K = map(int, input().split())

if(K>A):
  nokori = K - A
  ans = B - nokori
  print("0",ans)
else:
  nokori = A - K
  print(nokori,B)
# Judge status: Accepted
x, y, z = map(int, input().split())
print((x - z) // (z + y))
# Judge status: Wrong Answer
W,H,x,y=map(int,input().split())

a=[]
b=[]
judge=0

a.append(min(x,W-x)*H)
a.append(min(y,H-y)*W)
b.append(max(x,W-x)*H)
b.append(max(y,H-y)*W)

if max(a) in a and b:
    judge=1

print(max(a),judge)
# Judge status: Wrong Answer
def main():
    # n = int(input())
    n, m = map(int, input().split())
    x = list(map(int, input().split()))
    # s = input()
    # h = [int(input()) for _ in range(n)]

    x.sort()

    subs = []

    for i in range(1, m):
        subs.append(abs(x[i]-x[i-1]))

    subs.sort()
    print(sum(subs[0:m-n]))


if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
A, B, X = map(int, input().split())

if X <= A + B - 1 and X >= A:
  print("Yes")
else:
  print("No")
# Judge status: Accepted
S=input()

weather={"Sunny":"Cloudy","Rainy":"Sunny","Cloudy":"Rainy"}

print(weather[S])
# Judge status: Accepted
x = int(input())
ans = x//11*2 + (x%11+5)//6

print(ans)
# Judge status: Accepted
import sys
input = sys.stdin.readline().strip
a,b,c,d=map(int,input().split())
if b<c or d<a:
    print(0)
else: print(min(b,d)-max(a,c))
# Judge status: Wrong Answer
n=int(input())
l=list(map(int,input().split()))
dp=[0]*(n)
dp[0]=0
dp[1]=abs(l[0]-l[1])
for i in range(1,n):
    dp[i]=min(abs(l[i]-l[i-2])+dp[i-2],abs(l[i]-l[i-1])+dp[i-1])
print(dp[-1])
# Judge status: Accepted
n = input()
ans = 'No'
for i in n:
    if i == '7':
        ans = 'Yes'
        break
print(ans)
# Judge status: Wrong Answer
s = list(input())
ans = list("keyence")
x = 0

for c in s:
    if c == ans[x]:
        x += 1
    if x == 6:
        print("YES")
        exit()

print("NO")
# Judge status: Accepted
from collections import defaultdict

def solve(n, m, PY):
    index = {
        y: i
        for i, (_, y) in enumerate(PY)
    }

    PY.sort(key=lambda py: py[1])
    counts = defaultdict(int)
    ret = [''] * m
    for p, y in PY:
        counts[p] += 1
        ret[index[y]] = '{0:06d}{1:06d}'.format(p, counts[p])
    return ret

_n, _m = map(int, input().split())
_PY = [list(map(int, input().split())) for _ in range(_m)]
print(*solve(_n, _m, _PY), sep='\n')
# Judge status: Accepted
a,b=map(int,input().split())
if a==1 and b != 1:
    print('Alice')
elif a!=1 and b == 1:
    print('Bob')
elif a>b:
    print('Alice')
elif a<b:
    print('Bob')
else:
    print('Draw')
# Judge status: Accepted
c = input()

if c in 'aeiou':
  print('vowel')
else:
  print('consonant')
# Judge status: Accepted
import math

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

print(math.ceil((N-K) / (K-1)) + 1)
# Judge status: Accepted
A,B = list(map(int,input().split()))
print('Yay!' if A<9 and B<9 else ':(')
# Judge status: Accepted
n = int(input())
s = input()
t = input()
x = 2 * n
for i in range(n):
  if t.startswith(s[i:]):
    x = n + i
    print(x)
    exit()
print(x)
# Judge status: Accepted
s = input()
hi = 'hi'
for i in range(1, 6):
    if hi * i == s:
        print('Yes')
        break
else:
    print('No')
# Judge status: Wrong Answer
N = int(input())
an = map(int, input().split(" "))
ans = 0
for i, ai in enumerate(an):
    if i % 2 == 1 and ai % 2 == 1:
        ans += 1
print(ans)
# Judge status: Accepted
k = int(input())
odd = k//2 + k % 2
even = k//2
print(odd*even)
# Judge status: Accepted
def main():
    S = input()
    N = len(S)
    if N == 1:
        print(S)
    elif all("9" == s for s in S):
        print(N*9)
    elif all("9" == s for s in S[1:]):
        print(int(S[0]) + 9*(N-1))
    elif S[0] == "1":
        print(9*(N-1))
    else:
        print((int(S[0])-1) + 9*(N-1))


if __name__ == '__main__':
    main()
# Judge status: Accepted
x, y = map(int, input().split())

if x == 1 or x == 3 or x == 5 or x == 7 or x == 8 or x == 10 or x == 12:
    if y == 1 or y == 3 or y == 5 or y == 7 or y == 8 or y == 10 or y == 12:
        print('Yes')
    else:
        print('No')

if x == 4 or x == 6 or x == 9 or x == 11:
    if y == 4 or y == 6 or y == 9 or y == 11:
        print('Yes')
    else:
        print('No')

if x == 2:
    if y == 2:
        print('Yes')
    else:
        print('No')
# Judge status: Wrong Answer
N,M,Q=map(int, input().split())
ABCD=[tuple(map(int, input().split())) for _ in range(Q)]

ans=0
A=[1]*(N+1)
while True:
    tmp=0
    for a,b,c,d in ABCD:
        if A[b]-A[a]==c: tmp+=d
    ans = max(ans, tmp)
    up=1
    for i in range(N,0,-1):
        A[i]+=up
        if A[i]>M:
            up=1
            A[i]=M
        else:
            up=0
            break
    if up==1: break
print(ans)
# Judge status: Accepted
S, T = input().split()
A,B = map(int,input().split())
U = input()
if U == S:
  A -= 1
  print(A,B)
else:
  B -= 1
  print(A,B)
# Judge status: Accepted
N, A, B = map(int, input().split())
a = N // (A + B)
b = N % (A + B)
if b >= A:
    print(a*A + A)
else:
    print(a*A + b)
# Judge status: Accepted
N, C, K = map(int, input().split())
T = []
for i in range(N):
    t = int(input())
    T.append(t)
T.sort()

cnt = 0
res = 1
time = T[0]
for i in range(N-1):
    cnt += 1
    if cnt == C or time + K < T[i+1]:
        res += 1
        cnt = 0
        time = T[i+1]
print(res)
# Judge status: Accepted
n = int(input())
al = list(map(int, input().split()))

left = []
right = []

for i in range(n):
    if i % 2 == 0:
        right.append(al[i])
    else:
        left.append(al[i])

if n % 2 == 0:
    ans = left[::-1] + right
else:
    ans = right[::-1] + left

print(*ans, sep=' ')
# Judge status: Wrong Answer
N = int(input())
*a, = map(int, input().split())
two, four, no = 0, 0, 0
for i in range(N):
    if a[i] % 4 == 0:
        four += 1
    elif a[i] % 2 == 0:
        two += 1
    else:
        no += 1

ok = four == no or (four+two) == N
ok = ok and ((four+no) == N and abs(four-no) <= 1)
if ok:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    X = int(readline())

    for i in range(X + 1):
        if i * (i + 1) // 2 >= X:
            ans = i
            break

    print(ans)
    return


if __name__ == '__main__':
    main()
# Judge status: Accepted
N=int(input())
A=[int(input()) for i in range(N)]
maximum=max(A)
maximum2=sorted(A)[-2]
for a in A:
    if a!=maximum:
        print(maximum)
    else:
        print(maximum2)
# Judge status: Accepted
s=list(map(int,input().split()))
a=s[0]//s[1]
if s[0]%s[1]==0:
  print(int(a))
else:
  print(int(a+1))
# Judge status: Wrong Answer
n, w = map(int, input().split())
wts = []

for i in range(n):
    wts.append(list(map(int, input().split())))
    
wts.sort()
dp = [[0]*(w+1) for i in range(n)]
dp[0][wts[0][0]] = wts[0][1]

for i in range(1, n):
    for j in range(1+w):
        if j >= wts[i][0]:
            dp[i][j] = max(dp[i-1][j], wts[i][1]+dp[i-1][j-wts[i][0]])
        else:
            dp[i][j] += dp[i-1][j]

print(dp[-1][-1])
# Judge status: Accepted
import sys
import os
import fractions

MOD = 10 ** 9 + 7


def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    A, B, C, D = list(map(int, sys.stdin.readline().split()))
    E = B - A + 1

    ret = 0
    ret += B // C
    ret += B // D
    ret -= (A - 1) // C
    ret -= (A - 1) // D
    ret -= B // lcm(C, D)
    ret += (A-1) // lcm(C, D)
    print(E - ret)


if __name__ == '__main__':
    main()
# Judge status: Accepted
import math
n = int(input())
ans = 0
for i in range(1,n+1):
    if int(math.log10(i)) % 2 == 0:
        ans += 1
print(ans)
# Judge status: Accepted
import numpy as np

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

r = sum(A)
l = 0

ans = np.inf
for ai in A:
    l += ai
    r -= ai
    ans = min(np.abs(r-l), ans)

print(ans)
# Judge status: Accepted
def iim():return map(int,input().split())

a,b,c,d = iim()

if abs(a-c) <= d or (abs(a-b) <= d and abs(b-c) <= d):
    print('Yes')
else:
    print('No')
# Judge status: Wrong Answer
import sys
input = sys.stdin.readline
n=int(input())

t1,x1,y1=0,0,0
flg=True
for i in range(n):
    t2,x2,y2=map(int,input().split())
    l=abs(x2-x1)+abs(y2-y1)
    print(l,t2-t1)
    if l<=(t2-t1) and (t2-t1-l-1)%2==0:
        t1,x1,y1=t2,x2,y2
    else:
        flg=False
        break
print("Yes" if flg else "No")
# Judge status: Accepted
H,W = map(int,input().split())
if H == 1 or W == 1: print(1)
elif H * W % 2 == 1: print((H * W  + 1)//2)
else: print(H * W // 2)
# Judge status: Accepted
k = int(input())

print((k//2) ** 2 if k % 2 == 0 else ((k//2)+1) * (k//2))
# Judge status: Accepted
N, K, Q = map(int, input().split())
A = [int(input()) for i in range(Q)]
P = [0] * N
for i in range(Q):
    P[A[i] - 1] += 1
for i in range(N):
    if (K - (Q - P[i]) <= 0): print('No')
    else: print('Yes')
# Judge status: Wrong Answer
N = int(input())
A = [int(input()) for _ in range(N)]
A.sort()
ans = 0
a = A[0]
n = 0
for i in range(N):
    if a == A[i]:
        n += 1
    else:
        if n % 2 == 1:
            ans += 1
        n = 1
        a = A[i]
    #print(A[i],"1",n,n%2,ans)
if A[-1] == A[-2] and n % 2 == 1:
    ans += 1
print(ans)
# Judge status: Accepted
N = input()
if sum(map(int, list(N))) % 9 == 0:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
n = int(input())

alpha = 'abcdefghijklmnopqrstuvwxyz'

out = ''
while n != 0:
    out = alpha[(n % 26) - 1] + out
    n = int((n-1) // 26)
print(out)
# Judge status: Wrong Answer
S_list = list(map(int,input().split()))

r, g, b = S_list[0], S_list[1], S_list[2]
if (100 * r + 10 * g + b) % 4 == 0 :
    result = "Yes"
else:
    result = "No"
print(result)
# Judge status: Accepted
s = input()
a = s.index('A')
z = s[::-1].index('Z')
print(len(s)-a-z)
# Judge status: Accepted
a = list(map(int, input().split()))
a.sort()
if a == [5, 5, 7]:
    print("YES")
else:
    print("NO")
# Judge status: Wrong Answer
a=int(input())
print((a-1)*a)
# Judge status: Accepted
N = int(input())
A = list(map(int, input().split()))
B = [(A[i]-(i+1)) for i in range(N)]

if N == 1:
  print(0)
  exit()
B = sorted(B, reverse=True)
cs = B[:]
for i in range(N-1):
  cs[i+1] += cs[i]

ans = float('inf')
tmp = 0
for b in B:
  tmp += abs(b)
ans = min(ans, tmp)

for i in range(1, N):
  b = B[i]
  left = b*(i)-cs[i-1]
  right = -1*(b*(N-i-1)-(cs[-1]-cs[i]))
  ans = min(ans, abs(left)+abs(right))
print(ans)
# Judge status: Accepted
n=int(input())
s=''
if n==0:
    print(0)
    exit()
while n!=0:
    m=n%2
    s+=str(m)
    n=(n-m)//-2
print(int(s[::-1]))
# Judge status: Accepted
from collections import defaultdict
n = int(input())

d = defaultdict(int)

i = 2
while i * i <= n:
    while n % i == 0:
        d[i] += 1
        n /= i
    i += 1
if n != 1:
    d[n] += 1

ans = 0
for v in d.values():
    # x * (x + 1) // 2 <= vとなる最大のx
    x = 0
    while (x + 1) * (x + 2) // 2 <= v:
        x += 1
    ans += x
print(ans)
# Judge status: Accepted
import sys
from collections import Counter


def main():
    s = input()
    t = input()
    s_count = [0]*26
    t_count = [0]*26
    for i in range(ord("a"), ord("z")+1):
        s_count[i-97] = s.count(chr(i))
        t_count[i-97] = t.count(chr(i))
    s_count.sort()
    t_count.sort()
    if s_count == t_count:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()
# Judge status: Accepted
L,R = map(int,input().split())
if R-L+1 >= 2019:
    print(0)
    exit()
R %= 2019
L %= 2019
if R <= L:
    print(0)
    exit()
ans = 2020
for i in range(L,R):
    for j in range(i+1,R+1):
        ans = min(ans,(i*j)%2019)
print(ans)
# Judge status: Accepted
N=int(input())
A=list(map(int,input().split()))
if len(A)!=len(list(set(A))):
  print("NO")
else:
  print("YES")
# Judge status: Wrong Answer
h, w = map(int, input().split())
print(h*w//2 if h*w%2==0 else h*w//2+1)
# Judge status: Accepted
S = list(input())
S.sort()
if S[0] == S[1] and S[2] == S[3] and S[1] != S[2]:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
n = int(input())
data = [c for c in input()]
stack = []
ans = ''
for c in data:
    if c == '(':
        stack.append(c)
        ans += '('
    else:
        if len(stack) == 0 or stack.pop() != '(':
            ans = '(' + ans + c
        else:
            ans += ')'
ans += ')'*len(stack)

print(ans)
# Judge status: Wrong Answer
S = list(map(int, input()))
K = int(input())
#num = [pow(S[i], 10**12) for i in range(len(S))]
if len(S) == 1:
    print(S[0])
    exit()
if S[0] == 1:
    print(S[1])
else:
    print(S[0])
# Judge status: Accepted
from heapq import*
(N,M),*t=[map(int,s.split())for s in open(0)]
q=[0]*10**5
v=[[]for _ in q]
z=0
for a,b in t:v[a-1]+=b,
for i in v[:M]:
 for j in i:heappush(q,-j)
 z-=heappop(q)
print(z)
# Judge status: Accepted
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


def main():
    S = input()

    N = len(S) + 1
    a = [0] * N 
    for i in range(N-1):
        if S[i] == "<":
            a[i+1] = max(a[i+1], a[i]+1)
    for i in reversed(range(N-1)):
        if S[i] == ">":
            a[i] = max(a[i], a[i+1]+1)
    
    print(sum(a))


if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
import copy
n = int(input())

def dfs(str_list, now):
    str_list.append(chr(now))
    if len(str_list) == n:
        print(''.join(str_list))
    else:
        chr_a = ord('a')
        for c in range(chr_a, now + 2, 1):
            str_list_cp = copy.deepcopy(str_list)
            dfs(str_list_cp, c)

dfs([], ord('a'))
# Judge status: Accepted
# D - Not Divisible
from collections import deque
N = int(input())
A = list(map(int,input().split()))
A.sort()
A = deque(A)
B = [0]*(10**6+1)
ans = 0
for _ in range(N):
    x = A.popleft()
    if B[x]==0:
        ans += 1
        B[x] = 2
        tmp = 2*x
        while tmp<=10**6:
            B[tmp] = 1
            tmp += x
    elif B[x]==2:
        B[x] = 1
        ans -= 1
print(ans)
# Judge status: Accepted
N = int(input())
CSF = [list(map(int, input().split())) for i in range(N - 1)]
ans = []
for i in range(N - 1):
    temp = 0
    for j in range(i, N - 1):
        c, s, f = CSF[j][0], CSF[j][1], CSF[j][2]
        if temp <= s:
            temp += s - temp
            temp += temp % f
        else:
            temp += (f - ((temp - s) % f)) % f
        temp += c
    ans.append(temp)
for i in range(N - 1):
    print(ans[i])
print(0)
# Judge status: Accepted
S = input()[::-1]
l = len(S)
dp = [[0]*2 for _ in range(l+1)]
for i in range(l):
  dp[i+1][0]=min(dp[i][0]+int(S[i]),dp[i][1]+int(S[i])+1)
  if i!=0:
    dp[i+1][1]=min(dp[i][0]+10-int(S[i]),dp[i][1]+10-(int(S[i])+1))
  else:
    dp[i+1][1]=dp[i][0]+10-int(S[i])
print(min(dp[-1][0],dp[-1][1]+1))
# Judge status: Accepted
N,K=map(int,input().split())
if((N-K)%(K-1)==0):
  print((N-K)//(K-1)+1)
else:
  print((N-K)//(K-1)+2)
# Judge status: Accepted
S = str(input())
T = str(input())

count = 0
for i in range(len(S)):
    if S[i] != T[i]:
        count += 1
print(count)
# Judge status: Accepted
m = input()

A = m.index("A")
Z = m.rfind("Z")

print(Z-A+1)
# Judge status: Accepted
s, t = input().split()
a, b = map(int, input().split())
u = input()
if u == s:
    print(a - 1, b)
else:
    print(a, b-1)
# Judge status: Accepted
import itertools
import math
K = [i for i in range(1, int(input()) + 1)]
numbers = itertools.combinations_with_replacement(K, 3)

sum_gcd = 0
for i in numbers:
    a = math.gcd(i[0], i[1])
    b = math.gcd(a, i[2])

    if i[0] != i[1] != i[2]:
        sum_gcd += b * 6
    elif i[0] == i[1] == i[2]:
        sum_gcd += b
    else:
        sum_gcd += b * 3

print(sum_gcd)
# Judge status: Wrong Answer
s=int(input())
INF=10**9 + 7

dp=[0]*(s+1)
dp[0]=1

for i in range(1,s+1): #敷居の数
	for j in range(0,(i-3)+1):
		dp[i]+=dp[j]
		dp[i]%=INF
	print(dp)

print(dp[-1])
# Judge status: Accepted
def main():
    target_num = input()
    target_list = list(map(int, input().split()))

    target_list.sort(reverse=True)

    result_a = 0
    result_b = 0
    a_flg = True
    for target in target_list:
        if a_flg:
            result_a += int(target)
            a_flg = False
        else:
            result_b += int(target)
            a_flg = True

    print(result_a - result_b)


if __name__ == '__main__':
    main()
# Judge status: Accepted
n,m=map(int,input().split())
PY=[list(map(int,input().split())) for _ in range(m)]

ypi=[[y,p,i] for i,(p,y) in enumerate(PY)]			#順番iはp,yより前に来る
ypi.sort()

from collections import defaultdict

d=defaultdict(int)
ans=[0]*m

for y,p,i in ypi:
	d[p]+=1
	ans[i]=str(p).zfill(6)+str(d[p]).zfill(6)
	
print(*ans,sep="\n")