Harryxun/stf_run huggingface dataset:
def main():
    M = int(input())
    sum1 = 0
    sum2 = 0
    ans = 0
    dc = [[int(i) for i in input().split()] for _ in range(M)]
    s = "".join(str(d)*c for d, c in dc)
    if len(s) == 1:
        print(0)
    while len(s) != 1:
        s = str(int(s[0]) + int(s[0+1])) + s[0+2:]
        ans += 1
    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    M = int(input())
    ans = 0
    dc = [[int(i) for i in input().split()] for _ in range(M)]
    dc_sum = 0
    for i in range(M):
        d = dc[i][0]
        c = dc[i][1]
        dc_sum += d*c
        ans += c
    if dc_sum % 9 == 0:
        print(ans - 1 + dc_sum//9 - 1)
    else:
        print(ans - 1 + dc_sum//9)


if __name__ == '__main__':
    main()
k = int(input())
x = 7%k
s = []

while x not in s:
  if x == 0:
    print(len(s+1))
    break
  s.append(x)
  x = (10*x + 7)%k

  
if s[-1] != 0:
  print(-1)


### FIXED CODE ###

k = int(input())
x = 7%k
s = []

for i in range(k):
  if x == 0:
    print(i+1)
    exit()
  s.append(x)
  x = (10*x + 7)%k

  
  
print(-1)
A, B = map(int, input().split())

if a <= 8 and b <= 8:
  print('Yay!')
else:
  print(':(')

### FIXED CODE ###

A, B = map(int, input().split())
 
if A <= 8 and B <= 8:
  print('Yay!')
else:
  print(':(')
import sys
input = sys.stdin.buffer.readline

n = int(input())

edges = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)

nodes = [0 for _ in range(n)]
"""
white = all - black
"""

goal = n - 1
def dfs(num, f_num):
    if num == goal:
        nodes[num] = 1
        return 1
    s = 0
    for node in edges[num]:
        if node == f_num:
            continue
        s += dfs(node, num)
    nodes[num] = s + 1
    return s + 1

def dist(start, end):
    q = [(0, -1, 1)]
    res = 0
    while len(q) > 0:
        num, f_num, dist = q.pop()
        print(num, f_num, dist)
        if num == end:
            res = dist
        for node in edges[num]:
            if node == f_num:
                continue
            q.append((node, num, dist + 1))
    return res

dfs(0, -1)
fennec = nodes[0] - dist(0, n-1) // 2
snuke = n - fennec
if fennec > snuke:
    print("Fennec")
else:
    print("Snuke")


### FIXED CODE ###

import sys
input = sys.stdin.buffer.readline
from collections import deque

n = int(input())
edges = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)

def get_dists(f):
    dists = [0 for _ in range(n)]
    q = deque()
    q.append((f, -1, 0))
    while len(q) > 0:
        num, f_num, dist = q.popleft()
        for node in edges[num]:
            if node == f_num:
                continue
            else:
                dists[node] = dist + 1
                q.append((node, num, dist+1))
    return dists

dist_1 = get_dists(0)
dist_n = get_dists(n-1)

ans = 0
for i in range(n):
    if dist_1[i] <= dist_n[i]:
        ans += 1

fennec = ans
snuke = n - fennec
if fennec > snuke:
    print("Fennec")
else:
    print("Snuke")
import math
from sys import exit
X = int(input())

while True:
    for i in range(2, math.floor(math.sqrt(X) + 1)):
        flag = True
        if X % i == 0:
            flag = False
            break
    if flag:
        print(X)
        exit()
    X += 1


### FIXED CODE ###

import math
from sys import exit
X = int(input())

while True:
    flag = True
    for i in range(2, math.floor(math.sqrt(X) + 1)):
        if X % i == 0:
            flag = False
            break
    if flag:
        print(X)
        exit()
    X += 1
from fractions import gcd
import math
def lcm(a, b):
    return int(abs(a*b) / math.gcd(a, b))
a,b = list(map(int,input().split()))
print(lcm(a,b))



### FIXED CODE ###

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

def lcm(a,b): 
    return (a*b) / gcd(a,b) 
a,b = list(map(int,input().split()))
print(int(lcm(a,b)))
from itertools import accumulate
import sys
sys.setrecursionlimit(10**6)
n, k = map(int, input().split())
p = list(map(int, input().split()))
c = list(map(int, input().split()))

def dfs(G, v, p):
    seen[v] = True
    his.append(v)
    sc.append(c[v])

    for nv in G[v]:
        if nv == p:
            continue
        if seen[nv]:
            pos[0] = nv
            return

        dfs(G, nv, v)
        if pos[0] != -1:
            return


G = [[] for _ in range(n)]
for i in range(n):
    G[i].append(p[i]-1)

seen = [False]*n
ans = -float('inf')
for i in range(n):
    if seen[i] == False:
        his = []
        pos = [-1]
        sc = []
        dfs(G, i, -1)

        sumsc = sum(sc)
        lenc = len(sc)
        for j in range(lenc):
            if j != 0:
                sc = sc[1:] + [sc[0]]
            ac = list(accumulate(sc))
            
            if sumsc <= 0:
                ans = max(ans, max(ac[:min(k, lenc)]))
            else:
                ans = max(ans, ac[-1] * (k//lenc) + max(ac[:k%lenc]))
print(ans)

### FIXED CODE ###

from itertools import accumulate
import sys
sys.setrecursionlimit(10**6)
n, k = map(int, input().split())
p = list(map(int, input().split()))
c = list(map(int, input().split()))

def dfs(G, v, p):
    seen[v] = True
    sc.append(c[v])

    for nv in G[v]:
        if nv == p:
            continue
        if seen[nv]:
            pos[0] = nv
            return

        dfs(G, nv, v)
        if pos[0] != -1:
            return


G = [[] for _ in range(n)]
for i in range(n):
    G[i].append(p[i]-1)

seen = [False]*n
ans = -float('inf')
for i in range(n):
    if seen[i] == False:
        pos = [-1]
        sc = []
        dfs(G, i, -1)

        if sc:
            sumsc = sum(sc)
            lenc = len(sc)
            for j in range(lenc):
                if j != 0:
                    sc = sc[1:] + [sc[0]]
                ac = list(accumulate(sc))
                
                if sumsc <= 0:
                    ans = max(ans, max(ac[:min(k, lenc)]))
                else:
                    if k%lenc == 0:
                        ans = max(ans, ac[-1]*(k//lenc - 1) + max(ac))
                    else:
                        ans = max(ans, ac[-1]*(k//lenc) + max(ac[:k%lenc]))
print(ans)
N=int(input())
p=np.array(list(map(int, input().split())))
q=np.arange(N)+1

temp=np.sum(p==q)
if temp==0 or temp==2:
  print('YES')
else:
  print('NO')
  

### FIXED CODE ###

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

counter=0
for i in range(N):
  if p[i]!=int(i+1):
    counter+=1
    
if counter==0 or counter==2:
  print('YES')
else:
  print('NO')
-*- coding: utf-8 -*-

import math

l = rawinput().split()
print(math.ceil(l[0] + l[1])


### FIXED CODE ###

# -*- coding: utf-8 -*-
 
import math
 
l = list(map(int, input().split()))
print(math.ceil((l[0] + l[1])/2))
N=int(input())

if N%2==1:
    print(0)
    sys.exit()


N=N//2
retval=0
i=1
while 5**i<=N:
    retval+= N//(5**i)
    i+=1

print(retval)


### FIXED CODE ###

import sys
N=int(input())

if N%2==1:
    print(0)
    sys.exit()


N=N//2
retval=0
i=1
while 5**i<=N:
    retval+= N//(5**i)
    i+=1

print(retval)
from math import sqrt
x1,y1,x2,y2= map(int,raw_input().split())
print '%.8f' % sqrt((y2-y1)**2+(x2-x1)**2)

### FIXED CODE ###

from math import sqrt
x1,y1,x2,y2= map(float,raw_input().split())
print '%.8f' % sqrt((y2-y1)**2+(x2-x1)**2)
from numba import jit

@jit
def resolve():
    n = int(input())
    A = list(map(int, input().split()))
    if len(set(A)) == 1:
        print(0)
        return
    A.sort()

    ans = 0
    while len(A) > 0:
        a = A.pop(0)
        ans += 1
        A = [i for i in A if i % a != 0]

    print(ans)

resolve()

### FIXED CODE ###

def resolve():
    A = list(map(int, input().split()))
    print(A.index(0) + 1)

resolve()
import sys
N = int(input())
if N == 1:
    k,l = map(int,input().split())
    if l == 1:
        print(1)
    else:
        print(0)
    exit()
A = [0 for _ in range(N+1)]
l = [0,1]
H = []
for i in range(2**N):
    S = str(bin(i)).zfill(N)
    H.append(S[2:].zfill(N))
#H = list(combinations_with_replacement(l, N))
IXY = []
for i in range(1,N+1):
    A[i] = int(input())
    for j in range(A[i]):
        x,y = map(int,input().split())
        IXY.append([i,x,y])
ANS = []
for h in H:
    for ixy in IXY:
        flg = True
        i,x,y = ixy[0]-1,ixy[1]-1,ixy[2]
        if h[i] == "1":
            if h[x] != str(y):
                flg = False
                break
    if flg:l.append(ANS.append(h))
ans = 0
for a in ANS:
    ans = max(a.count("1"),ans)
print(ans)

### FIXED CODE ###

N = int(input())

#人が一人しかいないとき
if N == 1:
    print(1)
    exit()

#人が2人以上いるとき
#N人それぞれが正直か不誠実かの全パターンを生成
H = []
for i in range(2**N):
    S = str(bin(i))
    H.append(S[2:].zfill(N))
#入力を受け取る
IXY = []
for i in range(N):
    t = int(input())
    for j in range(t):
        x,y = map(int,input().split())
        #i番目の人が「x番目の人はyである」と証言
        IXY.append([i,x,y])

ans = 0
for h in H:
    cnt = h.count("1")
    for ixy in IXY:
        i,x,y = ixy[0],ixy[1]-1,ixy[2]
        if h[i] == "1" and h[x] != str(y):
            cnt = 0
            break
    ans = max(ans,cnt)
print(ans)
from collections import deque
S = deque(input())
Q = int(input())
x = 1
l=[]
for i in range(Q):
    l=[]
    l = list(input().split())
    if l[0] == "1":
        x *= -1
    elif l[0] == "2":
        if (l[1] == "2" and x == -1) or  (l[1] == "1" and x == 1):
            S.appendleft(l[2])
        else:
            S.append(l[2])
if x == -1:
    S = S[::-1]
print(*S, sep="")

### FIXED CODE ###

from collections import deque
S = deque(input())
Q = int(input())
x = 1
l=[]
for i in range(Q):
    a, *b = input().split()
    if a == "1":
        x *= -1
    elif a == "2":
        c, d = b
        if (c == "2" and x == -1) or  (c == "1" and x == 1):
            S.appendleft(d)
        else:
            S.append(d)
if x == -1:
    S.reverse()
print(*S, sep="")
c1x,c1y,c1r = [int(i) for i in input().split()]
c2x,c2y,c2r = [int(i) for i in input().split()]

d = math.sqrt(pow(c1x-c2x, 2) +  pow(c1y-c2y, 2))

s = c1r + c2r

if d > s:
    print(4)
else if d == c:
    print(3)
else if d > 2*s:
    print(2)
else if d == 2*s:
    print(1)
else:
    print(0)


### FIXED CODE ###

import math

c1x,c1y,c1r = [int(i) for i in input().split()]
c2x,c2y,c2r = [int(i) for i in input().split()]

d = math.sqrt(pow(c1x-c2x, 2) +  pow(c1y-c2y, 2))

bcr = 0
scr = 0

if c1r > c2r:
    bcr = c1r
    scr = c2r
else:
    bcr = c2r
    scr = c1r


if d > bcr + scr:
    print(4)
elif d == bcr + scr:
    print(3)
elif d + scr > bcr:
    print(2)
elif d + scr == bcr:
    print(1)
else:
    print(0)
#Atcoderではmathではなく，fractionsを使用．
#a/2が全て同じ数の2の倍数を素因数に持つ必要がある．

import math
from functools import reduce

def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def waru2(n):
    count = 0
    while True:
        if n % 2 == 0:
            n //= 2
            count += 1
        else:
            break
    return count

N, M = map(int, input().split())
a = list(map(int, input().split()))

half_a = []
waru = []

for i in a:
    half_a.append(i//2)
    waru.append(waru2(i))

if max(waru) == min(waru):
    half_lcm = lcm_list(half_a)
    print(-(-(M//half_lcm)//2))
else:
    print(0)

### FIXED CODE ###

#Atcoderではmathではなく，fractionsを使用するため．基本fractions
#a/2が全て同じ数の2の倍数を素因数に持つ必要がある．

import fractions
from functools import reduce

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

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def waru2(n):
    count = 0
    while True:
        if n % 2 == 0:
            n //= 2
            count += 1
        else:
            break
    return count

N, M = map(int, input().split())
a = list(map(int, input().split()))

half_a = []
waru = []

for i in a:
    half_a.append(i//2)
    waru.append(waru2(i))

if max(waru) == min(waru):
    half_lcm = lcm_list(half_a)
    print(-(-(M//half_lcm)//2))
else:
    print(0)
n, k, x, y = [int(iput()) for _ in range(4)]
print(k * x + (n-k) * y)

### FIXED CODE ###

n, k, x, y = [int(input()) for _ in range(4)]
if n > k:
    print(k * x + (n-k) * y)
else:
    print(n * x)
#!/usr/bin/env python
import numpy as np

def main():
    S = input()
    
    lenS = len(S)
    N = 13
    DP = np.zeros(N, dtype=np.int64)
    DP[0] = 1
    
    mod = 10 ** 9 + 7
    mul = 1
    for i in reversed(range(lenS)):
        nextDP = np.zeros(N, dtype=np.int64)
        c = S[i]
        if c == '?':
            for k in range(10):
                for j in range(N):
                    nextDP[(k * mul + j) %N] += DP[j]
                    nextDP[(k * mul + j) %N] %= mod

        else:
            k = int(S[i])
            for j in range(N):
                nextDP[(k * mul + j) %N] += DP[j]
                nextDP[(k * mul + j) %N] %= mod

        mul *= 10
        mul %= N
        DP = nextDP

    return DP[5]

if __name__ == '__main__':
    print(main())



### FIXED CODE ###

#!/usr/bin/env python
def main():
    A, B = list(map(int, input().split()))
    tmp = B
    if A > B:
        B = A
        A = tmp
    
    tmp = (B - A) / 2 + A
    if round(tmp) == tmp:
        return int(tmp)
    else:
        return 'IMPOSSIBLE'

if __name__ == '__main__':
    print(main())
from functools import lru_cache


def solve(nums, s):
    @lru_cache(None)
    def dfs(i, k):
        if k < 0:
            return []
        if k == 0:
            return [i-1]
        if i >= n:
            return []
        if k == s:
            return dfs(i+1, k-nums[i])
        return dfs(i+1, k-nums[i]) + dfs(i+1, k)

    ans = 0
    n = len(nums)
    for i in range(n):
        for e in dfs(i, s):
            ans = (ans + (i+1)*(n-e)) % 998244353
    return ans


def main():
    n, s = map(int, input().split())
    nums = [int(c) for c in input().split()]
    print(solve(nums, s))


if __name__ == "__main__":
    main()



### FIXED CODE ###

import numpy as np

def main():
    n, s = map(int, input().split())
    nums = [int(c) for c in input().split()]
    mod = 998244353
    dp = np.zeros(s+1, dtype=np.int)
    ans = 0

    for i, num in enumerate(nums, 1):
        dp[0] = i
        if num <= s:
            dp[num:] = dp[num:] + dp[:-num]
            # print(dp)
        dp %= mod
        ans = (ans + dp[-1]) % mod
    print(ans)


if __name__ == "__main__":
    main()
import math
r=int(input())
area1=pi
arear=pi*pow(r,2)
ratio=int(area2/area1)
print(ratio)

### FIXED CODE ###

r=int(input())
print(r*r)
n = int(input())
S = list(map(int,input().split())

a=soretd(S)
print(max(a)-min(a))

### FIXED CODE ###

n = int(input())

if n%2==0:
    print(n)

else:
    print(2 * n)
x=input()
a=[1]
for i in range(1,len(x)):
    if x[i]==x[i-1]:
        a[-1]+=1
    else:a+=[1]
ans=0    
if x[0]=="T":
    ans+=a.pop(0)
if x[-1]=="S":
    ans+=a.pop(-1)
    
while len(a)>1:
    a=[a[i]-a[i+1] for i in range(0,len(a),2)]
    if a and a[0]<0:
        ans-=a.pop(0)
    if a and a[-1]>0:
        ans+=a.pop(-1)
    a=[abs(i) for i in a]
print(ans)

### FIXED CODE ###

a=[]
for i in input():
    if i=="S":
        a+=i
    
    if a:
        if i=="T" and a[-1]=="T":
            a+=i
        if i=="T" and a[-1]=="S":
            a.pop(-1)
    elif i=="T" and len(a)==0:
        a+=i    
print(len(a))
n=int(input())
x=list(map(int,input().split()))

mean_=sum(x)//len(x)

for i in range(n):
  ans+=(x[i]-mean_)**2
print(ans)

### FIXED CODE ###

n=int(input())
x=list(map(int,input().split()))

min_=min(x)
max_=max(x)
ans=list()
for xy in range(min_, max_+1):
  life=0
  for xx in x:
    life+=(xx-xy)**2
  ans.append(life)
print(min(ans))
# import sys
# input = sys.stdin.readline

def main():
    N = int(input())
    p = list(map(int, input().split()))

    ans = 0
    i = 0
    # while i < N:
    for i in range(N):
        if i+1 == p[i]:
            tmp = p[i]
            p[i] = p[i+1]
            p[i+1] = tmp
            ans += 1
            # i += 1
        # i += 1
    print(ans)

if __name__ == "__main__":
    main()

### FIXED CODE ###

# import sys
# input = sys.stdin.readline

def main():
    N = int(input())
    p = list(map(int, input().split())) + [N+1]

    ans = 0
    i = 1
    for i in range(N):
        if i+1 == p[i]:
            tmp = p[i]
            p[i] = p[i+1]
            p[i+1] = tmp
            ans += 1
    print(ans)

if __name__ == "__main__":
    main()
while True:
	try:
		v = raw_input()		
			y = (float(v))**2 / 19.6
			print int(y/5 + 2)
	except: break

### FIXED CODE ###

while True:
	try:
		v = raw_input()		
		y = (float(v))**2 / 19.6
		print int(y/5 + 2)
	except: break
N,K = raw_input().split()
N=int(N)
K=int(K)
if N==1:
    print K
else:
    A = K*pow(K-1,N-1)
    print A


### FIXED CODE ###

N,K = raw_input().split()
N=int(N)
K=int(K)
if N==1:
    print K
else:
    A = K*pow(K-1,N-1)
    print A
N = int(input())
txy = [tuple() for _ in range(N)]
for i in range(N - 1):
    now = txy[i]
    next = txy[i + 1]
    root = abs(next[1] - now[1]) + abs(next[2] - now[2])
    time = next[0] - now[0]
    if time < root:
        print("No")
        break
    else:
        if time == root:
            pass
        else:
            if (time - root) % 2 != 0:
                print("No")
                break
else:
    print("Yes")


### FIXED CODE ###

N = int(input())
txy = [(0, 0, 0)] + [tuple(map(int, input().split())) for _ in range(N)]


for i in range(N):
    now = txy[i]
    next = txy[i + 1]
    root = abs(next[1] - now[1]) + abs(next[2] - now[2])
    time = next[0] - now[0]
    if time < root:
        print("No")
        break
    else:
        if time == root:
            pass
        else:
            if (time - root) % 2 != 0:
                print("No")
                break
else:
    if N == 1:
        root = txy[1][1] + txy[1][2]
        time = txy[1][0]
        if time < root:
            print("No")
        else:
            if (time - root) % 2 == 0:
                print("Yes")
            else:
                print("No")
    else:
        print("Yes")
h, w = map(int, input().split())

s = [list(input()) for _ in range(h)]

DX = [-1, 0, 1, 0]
DY = [0, -1, 0, 1]

ans = True

for i in range(h):
    for j in range(w):
        flag = False
        for k in range(4):    
            if not(0<=i+DX[k]<=w-1 and 0<=j+DY[k]<=h-1):
                continue
            if s[i + DX[k]][j + DY[k]] == "#":
                flag = True
        ans = flag
print("Yes" if ans else "No")


### FIXED CODE ###

h, w = map(int, input().split())

s = [list(input()) for _ in range(h)]

DX = [-1, 0, 1, 0]
DY = [0, -1, 0, 1]

ans = True

for i in range(h):
    for j in range(w):
        if s[i][j] == ".":
            continue
        flag = 0
        for k in range(4):    
            if not(0<=j+DX[k]<=w-1 and 0<=i+DY[k]<=h-1):
                continue
            if s[i + DY[k]][j + DX[k]] == "#":
                flag = 1
                break
        if flag == 0:
          ans = False
          break
print("Yes" if ans else "No")
from itertools import product

N, A = map(int, input().split())
x = [int(x) for x in input().split()]

max_x = max(max(x), A)
dp = [[[0 for _ in range(N * max_x)] for _ in range(N + 1)] for _ in range(N + 1)]
dp[0][0][0] = 1

for j, k, s in product(range(1, N + 1), range(N + 1), range(N * max_x)):
    if s < x[j - 1]:
        dp[j][k][s] = dp[j - 1][k][s]
    elif k >= 1 and s >= x[j - 1]:
        dp[j][k][s] = dp[j - 1][k][s] + dp[j - 1][k - 1][s - x[j - 1]]

ans = 0
for k in range(1, N + 1):
    ans += dp[N][k][k * A]
print(ans)


### FIXED CODE ###

from itertools import product

N, A = map(int, input().split())
x = [int(x) for x in input().split()]

X = max(max(x), A)
dp = [[0 for _ in range(2 * N * X + 1)] for _ in range(N + 1)]
dp[0][N * X] = 1

for j, t in product(range(1, N + 1), range(2 * N * X + 1)):
    y = x[j - 1] - A
    if t - y < 0 or t - y > 2 * N * X:
        dp[j][t] = dp[j - 1][t]
    elif 0 <= t - y <= 2 * N * X:
        dp[j][t] = dp[j - 1][t] + dp[j - 1][t - y]
print(dp[N][N * X] - 1)
n=int(input())
ans=[0]*100002
for i in range(n):
  num=int(input())
  if ans[num] == 0:
    ans[num]+=1
  else:
    ans[num]=0
print(sum(ans))

### FIXED CODE ###

n = int(input())
d = set()
for i in range(n):
    a = int(input())
    if a in d:
        d.remove(a)
    else:
        d.add(a)
print(len(d))
from fractions import gcd

def lcm(a):
    from fractions import gcd
    x = a[0]
    for i in range(1, len(a)):
        x = (x * a[i]) // gcd(x, a[i])
    return x

n=int(input())
a=list(map(int, input().split()))
A=lcm(a)
ans=0

for i in a:
    ans+=A/i

print(ans%(10**9+7))


### FIXED CODE ###

from fractions import gcd

n=int(input())
a=list(map(int, input().split()))
mod=10**9+7
l=1
ans=0

for i in a:
    l=l*i//gcd(l,i)

for i in a:
    ans+=l//i

print(ans%mod)
def merge_jibun(A, left, mid, right):
    global count
    L = A[left:mid] + [1000000]
    R = A[mid:right] + [1000000]
    # L.append(1000000)
    # R.append(1000000)

    i = 0
    j = 0
    
    
    for k in range(left, right):
        count += 1
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1

def merge_hoka(A, left, mid, right):
    global count
    inf = 10 ** 9
    L = A[left:mid] + [inf]
    R = A[mid:right] + [inf]
 
    i = 0
    j = 0
    for k in range(left, right):
        count += 1
        # print(L)
        # print(R)
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1

def mergeSort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        mergeSort(A, left, mid)
        mergeSort(A, mid, right)
        merge_jibun(A, left, mid, right)
        # merge_hoka(A, left, mid, right)

n = int(input())
A = list(map(int, input().split()))
count = 0
mergeSort(A, 0, n)

print(' '.join(list(map(str, A))))
print(count)


### FIXED CODE ###

def merge(A, left, mid, right):
    global count
    inf = 10 ** 9
    L = A[left:mid] + [inf]
    R = A[mid:right] + [inf]

    i = 0
    j = 0
    for k in range(left, right):
        count += 1
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1

def mergeSort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        mergeSort(A, left, mid)
        mergeSort(A, mid, right)
        merge(A, left, mid, right)

n = int(input())
A = list(map(int, input().split()))
count = 0
mergeSort(A, 0, n)

print(' '.join(list(map(str, A))))
print(count)
a,b,c,d = map(int,input().split())
if c < b < d:
  print(b-C)
elif a < d < b:
  print(d-a)
elif a < c < b and a< d < b:
  print(d-c)
elif c < a < d and c < b < d:
  print(b-a)
else:
  print(int(0))

### FIXED CODE ###

a,b,c,d = map(int,input().split())
ans = 0
for i in range(101):
  if a <= i < b and c <= i < d:
    ans += 1
print(ans)
SS = ">"+S+"<"
N = len(SS) - 1
A = [None for i in xrange(N)]

for i in xrange(N):
    if (SS[i] == ">" and SS[i+1] == "<"):
        A[i] = 0
        j = 0
        while (i-j-1)>=0 and SS[i-j] == ">":
            if A[i-j-1] == None:
                A[i-j-1] = j+1
            else:
                Max = max(A[i-j-1], j+1)
                A[i-j-1] = Max
            j += 1
        j = 0
        while (i+j+1)<N and SS[i+j+1] == "<":
            if A[i+j+1] == None:
                A[i+j+1] = j+1
            else:
                Max = max(A[i+j+1], j+1)
                A[i+j+1] = Max
            j += 1

print sum(A)   

### FIXED CODE ###


S  = raw_input()
SS = ">"+S+"<"
N = len(SS) - 1
A = [None for i in xrange(N)]

for i in xrange(N):
    if (SS[i] == ">" and SS[i+1] == "<"):
        A[i] = 0
        j = 0
        while (i-j-1)>=0 and SS[i-j] == ">":
            if A[i-j-1] == None:
                A[i-j-1] = j+1
            else:
                Max = max(A[i-j-1], j+1)
                A[i-j-1] = Max
            j += 1
        j = 0
        while (i+j+1)<N and SS[i+j+1] == "<":
            if A[i+j+1] == None:
                A[i+j+1] = j+1
            else:
                Max = max(A[i+j+1], j+1)
                A[i+j+1] = Max
            j += 1

print sum(A)
print(1110-int(input())

### FIXED CODE ###

print(1110-int(input()))