Input:
import math

def enough(n):

    whole_damage = B * n

    if (SUM > whole_damage*N + (A-B)*n):

        return False

    if (MAX <= whole_damage):

        return True

    arr = [hp for hp in HPS if hp > whole_damage]

    atk_times = 0

    for hp in arr:

        atk_times += int(math.ceil((hp - whole_damage)*1.0 / (A-B)))

        if atk_times > n:

            return False

    else:

        return True

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

HPS = [eval(input()) for i in range(N)]

MAX = max(HPS)

SUM = sum(HPS)

left = 1

right = MAX/B + 1

while left < right:

    mid = (left + right)/2

    if enough(mid):

        right = mid

    else:

        left = mid + 1

print(right)

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

src = [int(eval(input())) for i in range(N)]

src.sort(reverse=True)

def isok(n):

    if all(h <= n*B for h in src):

        return True

    m = 0

    for h in src:

        h -= n*B

        m += (h-1)//(A-B) + 1

        if m > n:

            return False

    return True

ok = 10**9

ng = 0

while ok-ng > 1:

    m = (ok+ng) // 2

    if isok(m):

        ok = m

    else:

        ng = m

print(ok)

import math

def enough(n):
    whole_damage = B * n
    if SUM > whole_damage * N + (A - B) * n:
        return False
    if MAX <= whole_damage:
        return True
    arr = [hp for hp in HPS if hp > whole_damage]
    atk_times = 0
    for hp in arr:
        atk_times += int(math.ceil((hp - whole_damage) * 1.0 / (A - B)))
        if atk_times > n:
            return False
    else:
        return True

N, A, B = list(map(int, input().split()))
HPS = [eval(input()) for i in range(N)]
MAX = max(HPS)
SUM = sum(HPS)
left = 1
right = MAX / B + 1
while left < right:
    mid = (left + right) / 2
    if enough(mid):
        right = mid
    else:
        left = mid + 1
print(right)

N, A, B = list(map(int, input().split()))
src = [int(eval(input())) for i in range(N)]
src.sort(reverse=True)

def isok(n):
    if all(h <= n * B for h in src):
        return True
    m = 0
    for h in src:
        h -= n * B
        m += (h - 1) // (A - B) + 1
        if m > n:
            return False
    return True

ok = 10**9
ng = 0
while ok - ng > 1:
    m = (ok + ng) // 2
    if isok(m):
        ok = m
    else:
        ng = m
print(ok)

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

+src = [int(eval(input())) for i in range(N)]

-    if SUM > whole_damage * N + (A - B) * n:

-    arr = [hp for hp in HPS if hp > whole_damage]

-        atk_times += int(math.ceil((hp - whole_damage) * 1.0 / (A - B)))

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

-HPS = [eval(input()) for i in range(N)]


Input:
from statistics import median

#import collections

#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]

from fractions import gcd

from itertools import combinations # (string,3) 3回

from collections import deque

from collections import defaultdict

import bisect

#

#    d = m - k[i] - k[j]

#    if kk[bisect.bisect_right(kk,d) - 1] == d:

#

#

#

# pythonで無理なときは、pypyでやると正解するかも！！

#

#

import sys

sys.setrecursionlimit(10000000)

mod = 10**9 + 7

def readInts():

  return list(map(int,input().split()))

def main():

    n,p = readInts()

    m = 0

    A = readInts()

    for i in range(n):

        a = A[i]

        if a % 2 == 1:

            m += 1

    if m == 0:

        print((2**n if p == 0 else 0))

    else:

        print((2**(n-1)))

if __name__ == '__main__':

  main()

#from statistics import median

#import collections

#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]

from fractions import gcd

from itertools import combinations,permutations,accumulate # (string,3) 3回

#from collections import deque

from collections import deque,defaultdict,Counter

import decimal

import re

#import bisect

#

#    d = m - k[i] - k[j]

#    if kk[bisect.bisect_right(kk,d) - 1] == d:

#

#

#

# pythonで無理なときは、pypyでやると正解するかも！！

#

#

# my_round_int = lambda x:np.round((x*2 + 1)//2)

# 四捨五入

import sys

sys.setrecursionlimit(10000000)

mod = 10**9 + 7

#mod = 9982443453

def readInts():

  return list(map(int,input().split()))

def I():

  return int(eval(input()))

n,p = readInts()

A = readInts()

odd = 0

for i in range(n):

    # count odd numbers

    # you can use Binomial coefficient

    # if P = 0, you should calculate this in using an odd number of odd numbers

    # else even numbers

    if A[i]%2:

        odd += 1

if odd == 0:

    if p == 0:

        print((2**n))

    else:

        print((0))

else:

    print((2**(n-1))) # 2**(n-1) = 2**(m-1) choosing odd * 2**(n-m) choosing even

from statistics import median

# import collections
# aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations  # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect

#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
import sys

sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
    return list(map(int, input().split()))

def main():
    n, p = readInts()
    m = 0
    A = readInts()
    for i in range(n):
        a = A[i]
        if a % 2 == 1:
            m += 1
    if m == 0:
        print((2**n if p == 0 else 0))
    else:
        print((2 ** (n - 1)))

if __name__ == "__main__":
    main()

# from statistics import median
# import collections
# aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations, permutations, accumulate  # (string,3) 3回

# from collections import deque
from collections import deque, defaultdict, Counter
import decimal
import re

# import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys

sys.setrecursionlimit(10000000)
mod = 10**9 + 7
# mod = 9982443453
def readInts():
    return list(map(int, input().split()))

def I():
    return int(eval(input()))

n, p = readInts()
A = readInts()
odd = 0
for i in range(n):
    # count odd numbers
    # you can use Binomial coefficient
    # if P = 0, you should calculate this in using an odd number of odd numbers
    # else even numbers
    if A[i] % 2:
        odd += 1
if odd == 0:
    if p == 0:
        print((2**n))
    else:
        print((0))
else:
    print((2 ** (n - 1)))  # 2**(n-1) = 2**(m-1) choosing odd * 2**(n-m) choosing even

-from itertools import combinations  # (string,3) 3回

+from itertools import combinations, permutations, accumulate  # (string,3) 3回

+from collections import deque, defaultdict, Counter

+# my_round_int = lambda x:np.round((x*2 + 1)//2)

+    # if P = 0, you should calculate this in using an odd number of odd numbers


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

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

def gcd(a,b):

  a,b = max(a,b),min(a,b)

  if b == 0:

    return a

  return gcd(b, a%b)

def solve():

  if N == 1: return src[0] == K

  mx = max(src)

  if K > mx: return False

  g = src[0]

  for i in range(1,N):

    g = gcd(g, src[i])

    if g == 1:

      return True

  return K % g == 0

print(('POSSIBLE' if solve() else 'IMPOSSIBLE'))

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

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

if K in A:

    print('POSSIBLE')

    exit()

if max(A) < K:

    print('IMPOSSIBLE')

    exit()

from fractions import gcd

g = A[0]

for a in A[1:]:

    g = gcd(g,a)

print(('POSSIBLE' if K%g==0 else 'IMPOSSIBLE'))

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

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

def solve():
    if N == 1:
        return src[0] == K
    mx = max(src)
    if K > mx:
        return False
    g = src[0]
    for i in range(1, N):
        g = gcd(g, src[i])
        if g == 1:
            return True
    return K % g == 0

print(("POSSIBLE" if solve() else "IMPOSSIBLE"))

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
if K in A:
    print("POSSIBLE")
    exit()
if max(A) < K:
    print("IMPOSSIBLE")
    exit()
from fractions import gcd

g = A[0]
for a in A[1:]:
    g = gcd(g, a)
print(("POSSIBLE" if K % g == 0 else "IMPOSSIBLE"))

-print(("POSSIBLE" if solve() else "IMPOSSIBLE"))

+print(("POSSIBLE" if K % g == 0 else "IMPOSSIBLE"))


Input:
N=int(eval(input()))

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

if N==1:

  print("Yes")

  exit()

for i in range(N-1):

  if H[i]-1<=H[i+1]:

    if i!=0:

      if H[i-1]<H[i]:

        H[i]-=1

  elif H[i]==H[i+1]:

    continue

  else:

    print("No")

    exit()

for i in range(N-1):

  if H[i]>H[i+1]:

    print("No")

    exit()

print("Yes")

N=int(eval(input()))

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

if N==1:

  print("Yes")

  exit()

if H[0]<H[1]:

  H[0]-=1

elif H[0]>H[1]:

  print("No")

  exit()

for i in range(1,N):

  if H[i-1]<H[i]:

    H[i]-=1

  elif H[i-1]>H[i]:

    print("No")

    exit()

print("Yes")

N = int(eval(input()))
H = list(map(int, input().split()))
if N == 1:
    print("Yes")
    exit()
for i in range(N - 1):
    if H[i] - 1 <= H[i + 1]:
        if i != 0:
            if H[i - 1] < H[i]:
                H[i] -= 1
    elif H[i] == H[i + 1]:
        continue
    else:
        print("No")
        exit()
for i in range(N - 1):
    if H[i] > H[i + 1]:
        print("No")
        exit()
print("Yes")

N = int(eval(input()))
H = list(map(int, input().split()))
if N == 1:
    print("Yes")
    exit()
if H[0] < H[1]:
    H[0] -= 1
elif H[0] > H[1]:
    print("No")
    exit()
for i in range(1, N):
    if H[i - 1] < H[i]:
        H[i] -= 1
    elif H[i - 1] > H[i]:
        print("No")
        exit()
print("Yes")


Input:
n = int(eval(input()))

s = []

ans = n

for i in range(n):

    s.append(eval(input()))

s = sorted(s)

for i in range(1,n):

    if s[i] == s[i-1]:

        ans-=1

print(ans)

n = int(eval(input()))

s = set([])

for i in range(n):

    s.add(eval(input()))

print((len(s)))

n = int(eval(input()))
s = []
ans = n
for i in range(n):
    s.append(eval(input()))
s = sorted(s)
for i in range(1, n):
    if s[i] == s[i - 1]:
        ans -= 1
print(ans)

-s = []
-ans = n
+s = set([])
-    s.append(eval(input()))
-s = sorted(s)
-for i in range(1, n):
-    if s[i] == s[i - 1]:
-        ans -= 1
-print(ans)
+    s.add(eval(input()))
+print((len(s)))


Input:
import itertools

N, K = list(map(int, input().split())) # N円の品物、K個の嫌いな数字

D = set(list(map(int, input().split()))) # 嫌いな数字のリスト

base = set(range(10))

target_num = base - D

keta = len(str(N))

answer = float('inf')

for p in itertools.product(target_num, repeat=keta):

    temp = 0

    for i, num in enumerate(p):

        temp += num * 10**i

    if temp >= N:

        answer = min(answer, temp)

for p in itertools.product(target_num, repeat=keta+1):

    temp = 0

    for i, num in enumerate(p):

        temp += num * 10**i

    if temp >= N:

        answer = min(answer, temp)

print(answer)

import itertools

def cal(N, target_num, keta):

    answer = float('inf')

    for p in itertools.product(target_num, repeat=keta):

        temp = 0

        for i, num in enumerate(p):

            temp += num * 10**i

        if temp >= N:

            answer = min(answer, temp)

    return answer

if __name__ == "__main__":

    N, K = list(map(int, input().split())) # N円の品物、K個の嫌いな数字

    D = set(list(map(int, input().split()))) # 嫌いな数字のリスト

    base = set(range(10))

    target_num = base - D

    keta = len(str(N))

    answer = min(cal(N, target_num, keta), cal(N, target_num, keta+1))

    print(answer)

import itertools

N, K = list(map(int, input().split()))  # N円の品物、K個の嫌いな数字
D = set(list(map(int, input().split())))  # 嫌いな数字のリスト
base = set(range(10))
target_num = base - D
keta = len(str(N))
answer = float("inf")
for p in itertools.product(target_num, repeat=keta):
    temp = 0
    for i, num in enumerate(p):
        temp += num * 10**i
    if temp >= N:
        answer = min(answer, temp)
for p in itertools.product(target_num, repeat=keta + 1):
    temp = 0
    for i, num in enumerate(p):
        temp += num * 10**i
    if temp >= N:
        answer = min(answer, temp)
print(answer)

import itertools

def cal(N, target_num, keta):
    answer = float("inf")
    for p in itertools.product(target_num, repeat=keta):
        temp = 0
        for i, num in enumerate(p):
            temp += num * 10**i
        if temp >= N:
            answer = min(answer, temp)
    return answer

if __name__ == "__main__":
    N, K = list(map(int, input().split()))  # N円の品物、K個の嫌いな数字
    D = set(list(map(int, input().split())))  # 嫌いな数字のリスト
    base = set(range(10))
    target_num = base - D
    keta = len(str(N))
    answer = min(cal(N, target_num, keta), cal(N, target_num, keta + 1))
    print(answer)

-N, K = list(map(int, input().split()))  # N円の品物、K個の嫌いな数字

-D = set(list(map(int, input().split())))  # 嫌いな数字のリスト

-for p in itertools.product(target_num, repeat=keta):

-for p in itertools.product(target_num, repeat=keta + 1):

+    for p in itertools.product(target_num, repeat=keta):

+    N, K = list(map(int, input().split()))  # N円の品物、K個の嫌いな数字

+    D = set(list(map(int, input().split())))  # 嫌いな数字のリスト

+    answer = min(cal(N, target_num, keta), cal(N, target_num, keta + 1))


Input:
N = int(eval(input()))

S = eval(input())

tmp = 0

for s in S[1:]:

    if s == 'E':

        tmp += 1

minimum = tmp

for i in range(1, N):

    if S[i-1] == 'W':

        tmp += 1

    if S[i] == 'E':

        tmp -= 1

    minimum = min(tmp, minimum)

print(minimum)

N = int(eval(input()))

S = eval(input())

tmp = S[1:].count('E')

minimum = tmp

for i in range(1, N):

    if S[i-1] == 'W':

        tmp += 1

    if S[i] == 'E':

        tmp -= 1

    minimum = min(tmp, minimum)

print(minimum)

N = int(eval(input()))
S = eval(input())
tmp = 0
for s in S[1:]:
    if s == "E":
        tmp += 1
minimum = tmp
for i in range(1, N):
    if S[i - 1] == "W":
        tmp += 1
    if S[i] == "E":
        tmp -= 1
    minimum = min(tmp, minimum)
print(minimum)

N = int(eval(input()))
S = eval(input())
tmp = S[1:].count("E")
minimum = tmp
for i in range(1, N):
    if S[i - 1] == "W":
        tmp += 1
    if S[i] == "E":
        tmp -= 1
    minimum = min(tmp, minimum)
print(minimum)


Input:
def main() -> None:

    n, c, k = list(map(int, input().split()))

    t = [int(eval(input())) for _ in range(n)]

    ans = wait_start = wait_people = 0

    for ti in sorted(t):

        if ti - wait_start > k or wait_people == c:

            wait_people = 0

        wait_people += 1

        if wait_people == 1:

            wait_start = ti

            ans += 1

    print(ans)

if __name__ == '__main__':

    main()

import sys

def main() -> None:

    n, c, k = list(map(int, input().split()))

    t = [int(sys.stdin.readline()) for _ in range(n)]

    ans = wait_start = wait_people = 0

    for ti in sorted(t):

        if ti - wait_start > k or wait_people == c:

            wait_people = 0

        wait_people += 1

        if wait_people == 1:

            wait_start = ti

            ans += 1

    print(ans)

if __name__ == '__main__':

    main()

def main() -> None:
    n, c, k = list(map(int, input().split()))
    t = [int(eval(input())) for _ in range(n)]
    ans = wait_start = wait_people = 0
    for ti in sorted(t):
        if ti - wait_start > k or wait_people == c:
            wait_people = 0
        wait_people += 1
        if wait_people == 1:
            wait_start = ti
            ans += 1
    print(ans)

if __name__ == "__main__":
    main()

import sys

def main() -> None:
    n, c, k = list(map(int, input().split()))
    t = [int(sys.stdin.readline()) for _ in range(n)]
    ans = wait_start = wait_people = 0
    for ti in sorted(t):
        if ti - wait_start > k or wait_people == c:
            wait_people = 0
        wait_people += 1
        if wait_people == 1:
            wait_start = ti
            ans += 1
    print(ans)

if __name__ == "__main__":
    main()

-    t = [int(eval(input())) for _ in range(n)]

+    t = [int(sys.stdin.readline()) for _ in range(n)]


Input:
def main():

    N = int(eval(input()))

    def to_bin(n):

        """

        n:10進数 -> 2進数

        """

        if n == 0:

            return 0

        digits = []

        i = 0

        base = 1

        while n != 0:

            if n % (base*2) == 0:

                digits.append("0")

            else:

                digits.append("1")

                n -= base

            i += 1

            base *= -2

        return "".join(digits[::-1])

    print((to_bin(N)))

if __name__ == '__main__':

    main()

def main():

    N = int(eval(input()))

    def to_bin(n):

        """

        n:10進数 -> 2進数

        """

        if n == 0:

            return 0

        digits = []

        i = 0

        base = 1

        while n != 0:

            if n % (base*-2) == 0:

                digits.append("0")

            else:

                digits.append("1")

                n -= base

            i += 1

            base *= -2

        return "".join(digits[::-1])

    print((to_bin(N)))

if __name__ == '__main__':

    main()

def main():
    N = int(eval(input()))

    def to_bin(n):
        """
        n:10進数 -> 2進数
        """
        if n == 0:
            return 0
        digits = []
        i = 0
        base = 1
        while n != 0:
            if n % (base * 2) == 0:
                digits.append("0")
            else:
                digits.append("1")
                n -= base
            i += 1
            base *= -2
        return "".join(digits[::-1])

    print((to_bin(N)))

if __name__ == "__main__":
    main()

def main():
    N = int(eval(input()))

    def to_bin(n):
        """
        n:10進数 -> 2進数
        """
        if n == 0:
            return 0
        digits = []
        i = 0
        base = 1
        while n != 0:
            if n % (base * -2) == 0:
                digits.append("0")
            else:
                digits.append("1")
                n -= base
            i += 1
            base *= -2
        return "".join(digits[::-1])

    print((to_bin(N)))

if __name__ == "__main__":
    main()


Input:
import sys

for s in sys.stdin:

  a=list(map(int,s.split(" ")))

  w=a[0]

  a=sorted(a[1:])

  A=[]

  try:

    while a:

      A+=[a.pop(0)]

      A=[a.pop()]+A

      A+=[a.pop()]

      A=[a.pop(0)]+A

  except: pass

  a=A[0]+A[-1]

  for i in range(len(A)-1): a+=2*(A[i]*A[i+1])**.5

  print(["OK","NA"][a>w])

import sys

for s in sys.stdin:

  a=list(map(int,s.split(" ")))

  w=a[0]

  a=sorted(a[1:])

  A=[]

  while a:

    A+=[a.pop(0)]

    if a==[]: break

    A=[a.pop()]+A

    if a==[]: break

    A+=[a.pop()]

    if a==[]: break

    A=[a.pop(0)]+A

  a=A[0]+A[-1]

  for i in range(len(A)-1): a+=2*(A[i]*A[i+1])**.5

  print(["OK","NA"][a>w])

import sys

for s in sys.stdin:
    a = list(map(int, s.split(" ")))
    w = a[0]
    a = sorted(a[1:])
    A = []
    try:
        while a:
            A += [a.pop(0)]
            A = [a.pop()] + A
            A += [a.pop()]
            A = [a.pop(0)] + A
    except:
        pass
    a = A[0] + A[-1]
    for i in range(len(A) - 1):
        a += 2 * (A[i] * A[i + 1]) ** 0.5
    print(["OK", "NA"][a > w])

import sys

for s in sys.stdin:
    a = list(map(int, s.split(" ")))
    w = a[0]
    a = sorted(a[1:])
    A = []
    while a:
        A += [a.pop(0)]
        if a == []:
            break
        A = [a.pop()] + A
        if a == []:
            break
        A += [a.pop()]
        if a == []:
            break
        A = [a.pop(0)] + A
    a = A[0] + A[-1]
    for i in range(len(A) - 1):
        a += 2 * (A[i] * A[i + 1]) ** 0.5
    print(["OK", "NA"][a > w])


Input:
import math

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

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

print((math.ceil((N-1)/(K-1))))

import math

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

print((math.ceil((N-1)/(K-1))))

import math

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
print((math.ceil((N - 1) / (K - 1))))

import math

N, K = list(map(int, input().split()))
print((math.ceil((N - 1) / (K - 1))))


Input:
import numba

import numpy as np

N = int(eval(input()))

P = np.array([int(c)-1 for c in input().split()])

#from random import shuffle

#N = 500

#P = list(range(N*N))

#shuffle(P)

#P = np.array(P)

@numba.njit("i8(i8,i8[:])", cache=True)

def proc(N, P):

    ans = 0

    Removed = np.zeros((500, 500), dtype=np.int8)

    Mat = np.zeros((500, 500), dtype=np.int16)

    Dy, Dx = np.array([1,0,-1,0]), np.array([0,1,0,-1])

    for y in range(N):

        for x in range(N):

            Mat[y, x] = min(y, N-1-y, x, N-1-x)

    #print(Mat)

    Buf = [(0, 0) for _ in range(1<<17)]

    Buf_idx = 0

    for i in range(N*N):

        p = P[i]

        y, x = divmod(p, N)

        ans += Mat[y,x]

        Removed[y,x] = 1

        Buf[Buf_idx] = (y, x)

        Buf_idx += 1

        while Buf_idx:

            Buf_idx -= 1

            vy, vx = Buf[Buf_idx]

            vr = Removed[vy,vx]

            val = Mat[vy,vx]

            #for dy, dx in zip(Dy, Dx):

            for j in range(4):

                uy, ux = vy + Dy[j], vx + Dx[j]

                if not (0<=uy<N and 0<=ux<N):

                    continue

                ur = Removed[uy,ux]

                if vr:

                    if Mat[uy,ux] >= val+1:

                        Mat[uy,ux] = val

                        Buf[Buf_idx] = (uy, ux)

                        Buf_idx += 1

                else:

                    if Mat[uy,ux] >= val+2:

                        Mat[uy,ux] = val+1

                        Buf[Buf_idx] = (uy, ux)

                        Buf_idx += 1

    # for m in Mat:

    #     print(m)

    return ans

print((proc(N, P)))

import sys

import numpy as np

from numba import njit

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

@njit("i4(i4,i4[:])", cache=True)

def proc(N, P):

    ans = 0

    Removed = np.zeros((500, 500), dtype=np.int8)

    Mat = np.zeros((500, 500), dtype=np.int16)

    Dy, Dx = np.array([1,0,-1,0]), np.array([0,1,0,-1])

    for y in range(N):

        for x in range(N):

            Mat[y, x] = min(y, N-1-y, x, N-1-x)

    #print(Mat)

    Buf = [(0, 0) for _ in range(1<<17)]

    Buf_idx = 0

    for i in range(N*N):

        p = P[i]

        y, x = divmod(p, N)

        ans += Mat[y,x]

        Removed[y,x] = 1

        Buf[Buf_idx] = (y, x)

        Buf_idx += 1

        while Buf_idx:

            Buf_idx -= 1

            vy, vx = Buf[Buf_idx]

            vr = Removed[vy,vx]

            val = Mat[vy,vx]

            #for dy, dx in zip(Dy, Dx):

            for j in range(4):

                uy, ux = vy + Dy[j], vx + Dx[j]

                if not (0<=uy<N and 0<=ux<N):

                    continue

                ur = Removed[uy,ux]

                if vr:

                    if Mat[uy,ux] >= val+1:

                        Mat[uy,ux] = val

                        Buf[Buf_idx] = (uy, ux)

                        Buf_idx += 1

                else:

                    if Mat[uy,ux] >= val+2:

                        Mat[uy,ux] = val+1

                        Buf[Buf_idx] = (uy, ux)

                        Buf_idx += 1

    return ans

N = int(readline())

P = np.array(read().split(), np.int32)-1

print((proc(N, P)))

import numba
import numpy as np

N = int(eval(input()))
P = np.array([int(c) - 1 for c in input().split()])
# from random import shuffle
# N = 500
# P = list(range(N*N))
# shuffle(P)
# P = np.array(P)
@numba.njit("i8(i8,i8[:])", cache=True)
def proc(N, P):
    ans = 0
    Removed = np.zeros((500, 500), dtype=np.int8)
    Mat = np.zeros((500, 500), dtype=np.int16)
    Dy, Dx = np.array([1, 0, -1, 0]), np.array([0, 1, 0, -1])
    for y in range(N):
        for x in range(N):
            Mat[y, x] = min(y, N - 1 - y, x, N - 1 - x)
    # print(Mat)
    Buf = [(0, 0) for _ in range(1 << 17)]
    Buf_idx = 0
    for i in range(N * N):
        p = P[i]
        y, x = divmod(p, N)
        ans += Mat[y, x]
        Removed[y, x] = 1
        Buf[Buf_idx] = (y, x)
        Buf_idx += 1
        while Buf_idx:
            Buf_idx -= 1
            vy, vx = Buf[Buf_idx]
            vr = Removed[vy, vx]
            val = Mat[vy, vx]
            # for dy, dx in zip(Dy, Dx):
            for j in range(4):
                uy, ux = vy + Dy[j], vx + Dx[j]
                if not (0 <= uy < N and 0 <= ux < N):
                    continue
                ur = Removed[uy, ux]
                if vr:
                    if Mat[uy, ux] >= val + 1:
                        Mat[uy, ux] = val
                        Buf[Buf_idx] = (uy, ux)
                        Buf_idx += 1
                else:
                    if Mat[uy, ux] >= val + 2:
                        Mat[uy, ux] = val + 1
                        Buf[Buf_idx] = (uy, ux)
                        Buf_idx += 1
    # for m in Mat:
    #     print(m)
    return ans

print((proc(N, P)))

import sys
import numpy as np
from numba import njit

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

@njit("i4(i4,i4[:])", cache=True)
def proc(N, P):
    ans = 0
    Removed = np.zeros((500, 500), dtype=np.int8)
    Mat = np.zeros((500, 500), dtype=np.int16)
    Dy, Dx = np.array([1, 0, -1, 0]), np.array([0, 1, 0, -1])
    for y in range(N):
        for x in range(N):
            Mat[y, x] = min(y, N - 1 - y, x, N - 1 - x)
    # print(Mat)
    Buf = [(0, 0) for _ in range(1 << 17)]
    Buf_idx = 0
    for i in range(N * N):
        p = P[i]
        y, x = divmod(p, N)
        ans += Mat[y, x]
        Removed[y, x] = 1
        Buf[Buf_idx] = (y, x)
        Buf_idx += 1
        while Buf_idx:
            Buf_idx -= 1
            vy, vx = Buf[Buf_idx]
            vr = Removed[vy, vx]
            val = Mat[vy, vx]
            # for dy, dx in zip(Dy, Dx):
            for j in range(4):
                uy, ux = vy + Dy[j], vx + Dx[j]
                if not (0 <= uy < N and 0 <= ux < N):
                    continue
                ur = Removed[uy, ux]
                if vr:
                    if Mat[uy, ux] >= val + 1:
                        Mat[uy, ux] = val
                        Buf[Buf_idx] = (uy, ux)
                        Buf_idx += 1
                else:
                    if Mat[uy, ux] >= val + 2:
                        Mat[uy, ux] = val + 1
                        Buf[Buf_idx] = (uy, ux)
                        Buf_idx += 1
    return ans

N = int(readline())
P = np.array(read().split(), np.int32) - 1
print((proc(N, P)))

-P = np.array([int(c) - 1 for c in input().split()])

+P = np.array(read().split(), np.int32) - 1


Input:
import sys

sys.setrecursionlimit(10000)

n = eval(input())

k = int(eval(input()))

m = {}

def doit(n, k):

    if len(n) == 0:

        return k == 0

    d = int(n[0])

    if (n, k) not in m:

        ret = 0

        for i in range(d + 1):

            if i == d:

                ret += doit(n[1:], k - 1 if i > 0 else k)

            else:

                ret += doit('9' * (len(n) - 1), k - 1 if i > 0 else k)

        m[(n, k)] = ret

    return m[(n, k)]

print((doit(n, k)))

import sys

sys.setrecursionlimit(303)

def doit(n, k, m):

    if len(n) == 0 or k < 0:

        return k == 0

    if (n, k) not in m:

        d = int(n[0])

        m[(n, k)] = sum(doit(n[1:] if i == d else '9' * (len(n) - 1), k - 1 if i > 0 else k, m) for i in range(d + 1))

    return m[(n, k)]

print((doit(eval(input()), int(eval(input())), {})))

import sys

sys.setrecursionlimit(10000)
n = eval(input())
k = int(eval(input()))
m = {}

def doit(n, k):
    if len(n) == 0:
        return k == 0
    d = int(n[0])
    if (n, k) not in m:
        ret = 0
        for i in range(d + 1):
            if i == d:
                ret += doit(n[1:], k - 1 if i > 0 else k)
            else:
                ret += doit("9" * (len(n) - 1), k - 1 if i > 0 else k)
        m[(n, k)] = ret
    return m[(n, k)]

print((doit(n, k)))

import sys

sys.setrecursionlimit(303)

def doit(n, k, m):
    if len(n) == 0 or k < 0:
        return k == 0
    if (n, k) not in m:
        d = int(n[0])
        m[(n, k)] = sum(
            doit(n[1:] if i == d else "9" * (len(n) - 1), k - 1 if i > 0 else k, m)
            for i in range(d + 1)
        )
    return m[(n, k)]

print((doit(eval(input()), int(eval(input())), {})))

-                ret += doit(n[1:], k - 1 if i > 0 else k)

-                ret += doit("9" * (len(n) - 1), k - 1 if i > 0 else k)

+            doit(n[1:] if i == d else "9" * (len(n) - 1), k - 1 if i > 0 else k, m)


Input:
# 3.4.3

import re

from collections import deque

from functools import reduce

from heapq import heappop

from heapq import heappush

from itertools import permutations

from math import pi

from operator import itemgetter

from operator import mul

from operator import xor

from os import linesep

from sys import stdin

def rline() -> str:

    return stdin.readline().strip()

def rlines(hint: int = 1):

    ret = ['' for i in range(hint)]

    for i in range(hint):

        ret[i] = rline()

    return ret

def htokens(hint: int = 1):

    lns = rlines(hint)

    ret = list([ln.split() for ln in lns])

    return ret

def vtokens(hint: int = 1):

    m, _ = htokens()

    wint = len(m)

    ret = [[None] * hint for i in range(wint)]

    for y in range(hint):

        if y != 0:

            m, _ = htokens()

        # convert horizontal to vertical

        x = 0

        for v in m:

            ret[x][y] = v

            x += 1

    # if return value has one and only one element(list),

    if wint == 1:

        # then add an empty list.

        ret.append([])

    return ret

def rint(radix: int = 10) -> int:

    return int(rline(), radix)

def hints(hint: int = 1, radix: int = 10):

    ret = htokens(hint)

    for i in range(len(ret)):

        ret[i] = list([int(v, radix) for v in ret[i]])

    return ret

def vints(hint: int = 1, radix: int = 10):

    ret = vtokens(hint)

    for i in range(len(ret)):

        ret[i] = list([int(v, radix) for v in ret[i]])

    return ret

def mat(hint: int, wint: int):

    return [[None]*wint for i in range(hint)]

def filllist(lst, value: int) -> None:

    # destructive.

    for i in range(len(lst)):

        lst[i] = value

def isprime(n: int) -> bool:

    if n <= 1:

        return False

    if n in (2, 3, 5):

        return True

    if n % 2 == 0:

        return False

    if n % 3 == 0:

        return False

    lst = int(n**0.5)

    f = 5

    while f <= lst:

        if n % f == 0:

            return False

        if n % (f + 2) == 0:

            return False

        f += 6

    return True

def strmat(matrix, lnsep: str = linesep, fieldsep: str = ' ') -> str:

    return lnsep.join([fieldsep.join(map(str, row)) for row in matrix])

def strbool(boolval: int) -> str:

    return ['No', 'Yes'][boolval]

def solve() -> None:

    # read here

    (n, m) = hints()[0]

    ab_s = hints(n)

    # solve here

    # delay asc, prize desc

    ab_s.sort(key=itemgetter(1), reverse=True)

    ab_s.sort(key=itemgetter(0), reverse=False)

    ans = 0

    tasks = []

    ti = 0

    for t in range(m + 1):

        # from (m days after) to today

        while ti < n and ab_s[ti][0] == t:

            a, b = ab_s[ti]

            ti += 1

            heappush(tasks, -b)

        if tasks:

            # do task

            ans -= heappop(tasks)

    # print here

    print(ans)

if __name__ == '__main__':

    solve()

# 3.4.3

import re

from collections import deque

from functools import reduce

from heapq import *

from itertools import permutations

from math import pi

from operator import itemgetter

from operator import mul

from operator import xor

from os import linesep

def isprime(n: int) -> bool:

    if n <= 1:

        return False

    if n in (2, 3, 5):

        return True

    if n % 2 == 0:

        return False

    if n % 3 == 0:

        return False

    lst = int(n**0.5)

    f = 5

    while f <= lst:

        if n % f == 0:

            return False

        if n % (f + 2) == 0:

            return False

        f += 6

    return True

def strmat(matrix, lnsep: str = linesep, fieldsep: str = ' ') -> str:

    return lnsep.join([fieldsep.join(map(str, row)) for row in matrix])

def strbool(boolval: int) -> str:

    return ['No', 'Yes'][boolval]

def solve() -> None:

    # read here

    n, m, *t = list(map(int, open(0).read().split()))

    # solve here

    d = [[] for i in range(m+1)]

    for i in range(n):

        a, b = t[2*i], t[2*i+1]

        if a > m:

            continue

        d[a].append(b)

    ans = 0

    tasks = []

    for t in range(m + 1):

        # from (m days after) to today

        for tasksize in d[t]:

            heappush(tasks, -tasksize)

        if tasks:

            # do task

            ans -= heappop(tasks)

    # print here

    print(ans)

if __name__ == '__main__':

    solve()

# 3.4.3
import re
from collections import deque
from functools import reduce
from heapq import heappop
from heapq import heappush
from itertools import permutations
from math import pi
from operator import itemgetter
from operator import mul
from operator import xor
from os import linesep
from sys import stdin

def rline() -> str:
    return stdin.readline().strip()

def rlines(hint: int = 1):
    ret = ["" for i in range(hint)]
    for i in range(hint):
        ret[i] = rline()
    return ret

def htokens(hint: int = 1):
    lns = rlines(hint)
    ret = list([ln.split() for ln in lns])
    return ret

def vtokens(hint: int = 1):
    m, _ = htokens()
    wint = len(m)
    ret = [[None] * hint for i in range(wint)]
    for y in range(hint):
        if y != 0:
            m, _ = htokens()
        # convert horizontal to vertical
        x = 0
        for v in m:
            ret[x][y] = v
            x += 1
    # if return value has one and only one element(list),
    if wint == 1:
        # then add an empty list.
        ret.append([])
    return ret

def rint(radix: int = 10) -> int:
    return int(rline(), radix)

def hints(hint: int = 1, radix: int = 10):
    ret = htokens(hint)
    for i in range(len(ret)):
        ret[i] = list([int(v, radix) for v in ret[i]])
    return ret

def vints(hint: int = 1, radix: int = 10):
    ret = vtokens(hint)
    for i in range(len(ret)):
        ret[i] = list([int(v, radix) for v in ret[i]])
    return ret

def mat(hint: int, wint: int):
    return [[None] * wint for i in range(hint)]

def filllist(lst, value: int) -> None:
    # destructive.
    for i in range(len(lst)):
        lst[i] = value

def isprime(n: int) -> bool:
    if n <= 1:
        return False
    if n in (2, 3, 5):
        return True
    if n % 2 == 0:
        return False
    if n % 3 == 0:
        return False
    lst = int(n**0.5)
    f = 5
    while f <= lst:
        if n % f == 0:
            return False
        if n % (f + 2) == 0:
            return False
        f += 6
    return True

def strmat(matrix, lnsep: str = linesep, fieldsep: str = " ") -> str:
    return lnsep.join([fieldsep.join(map(str, row)) for row in matrix])

def strbool(boolval: int) -> str:
    return ["No", "Yes"][boolval]

def solve() -> None:
    # read here
    (n, m) = hints()[0]
    ab_s = hints(n)
    # solve here
    # delay asc, prize desc
    ab_s.sort(key=itemgetter(1), reverse=True)
    ab_s.sort(key=itemgetter(0), reverse=False)
    ans = 0
    tasks = []
    ti = 0
    for t in range(m + 1):
        # from (m days after) to today
        while ti < n and ab_s[ti][0] == t:
            a, b = ab_s[ti]
            ti += 1
            heappush(tasks, -b)
        if tasks:
            # do task
            ans -= heappop(tasks)
    # print here
    print(ans)

if __name__ == "__main__":
    solve()

# 3.4.3
import re
from collections import deque
from functools import reduce
from heapq import *
from itertools import permutations
from math import pi
from operator import itemgetter
from operator import mul
from operator import xor
from os import linesep

def isprime(n: int) -> bool:
    if n <= 1:
        return False
    if n in (2, 3, 5):
        return True
    if n % 2 == 0:
        return False
    if n % 3 == 0:
        return False
    lst = int(n**0.5)
    f = 5
    while f <= lst:
        if n % f == 0:
            return False
        if n % (f + 2) == 0:
            return False
        f += 6
    return True

def strmat(matrix, lnsep: str = linesep, fieldsep: str = " ") -> str:
    return lnsep.join([fieldsep.join(map(str, row)) for row in matrix])

def strbool(boolval: int) -> str:
    return ["No", "Yes"][boolval]

def solve() -> None:
    # read here
    n, m, *t = list(map(int, open(0).read().split()))
    # solve here
    d = [[] for i in range(m + 1)]
    for i in range(n):
        a, b = t[2 * i], t[2 * i + 1]
        if a > m:
            continue
        d[a].append(b)
    ans = 0
    tasks = []
    for t in range(m + 1):
        # from (m days after) to today
        for tasksize in d[t]:
            heappush(tasks, -tasksize)
        if tasks:
            # do task
            ans -= heappop(tasks)
    # print here
    print(ans)

if __name__ == "__main__":
    solve()

-    ret = list([ln.split() for ln in lns])

-    ret = [[None] * hint for i in range(wint)]

-        # convert horizontal to vertical

-    # if return value has one and only one element(list),

-def hints(hint: int = 1, radix: int = 10):

-        ret[i] = list([int(v, radix) for v in ret[i]])

-def vints(hint: int = 1, radix: int = 10):

-    return [[None] * wint for i in range(hint)]

+    n, m, *t = list(map(int, open(0).read().split()))

-    ab_s.sort(key=itemgetter(1), reverse=True)

-    ab_s.sort(key=itemgetter(0), reverse=False)

-        while ti < n and ab_s[ti][0] == t:


Input:
import math

y, k, d = list(map(int, input().split()))

if y >= 0:

    x = y

else:

    x = -y

i = math.floor(x / d)

if i >= k:

    p = x - k * d

elif i == x / d:

    if i + k == 2 * int((i + k) / 2):

        p = 0

    else:

        p = d

else:

    if (2 * i + 1) * d == 2 * x:

        p = x - i * d

    else:

        if i + k == 2 * int((i + k) / 2):

            p = x - i * d

        else:

            p = (i + 1) * d - x

print((int(p)))

y, k, d = list(map(int, input().split()))

x = abs(y)

i = int(x / d)

if i >= k:

    p = x - k * d

elif i == x / d:

    if (i + k) % 2 == 0:

        p = 0

    else:

        p = d

else:

    if ((2 * i + 1) * d == 2 * x) or ((i + k) % 2 == 0):

        p = x - i * d

    else:

        p = (i + 1) * d - x

print((int(p)))


Input:
a,b,c,x,y=list(map(int,input().split()))

ans1=a*x+b*y

ans2=c*2*x+b*(y-x) if y>=x else a*(x-y)+c*2*y

ans3=max(x,y)*2*c

print((min(ans1,ans2,ans3)))

a,b,c,x,y=list(map(int,input().split()))

#A,Bをそれぞれ買う

cand1=a*x+b*y

#すべてABピザでそろえる

cand2=2*c*max(x,y)

#A,Bのうち必要枚数が少ないほうをすべてABピザで作る

cand3=2*c*x+b*(y-x) if x<y else 2*c*y+a*(x-y)

print((min(cand1,cand2,cand3)))

a, b, c, x, y = list(map(int, input().split()))
ans1 = a * x + b * y
ans2 = c * 2 * x + b * (y - x) if y >= x else a * (x - y) + c * 2 * y
ans3 = max(x, y) * 2 * c
print((min(ans1, ans2, ans3)))

a, b, c, x, y = list(map(int, input().split()))
# A,Bをそれぞれ買う
cand1 = a * x + b * y
# すべてABピザでそろえる
cand2 = 2 * c * max(x, y)
# A,Bのうち必要枚数が少ないほうをすべてABピザで作る
cand3 = 2 * c * x + b * (y - x) if x < y else 2 * c * y + a * (x - y)
print((min(cand1, cand2, cand3)))

-ans2 = c * 2 * x + b * (y - x) if y >= x else a * (x - y) + c * 2 * y

+# A,Bをそれぞれ買う

+# すべてABピザでそろえる

+# A,Bのうち必要枚数が少ないほうをすべてABピザで作る

+cand3 = 2 * c * x + b * (y - x) if x < y else 2 * c * y + a * (x - y)


Input:
N = int(eval(input()))

if N%1000 == 0:

    print((0))

else:

    Str = str(N)

    if len(Str) > 3:

        K = (int(Str[0]) + 1) * 1000

        print((K - N))

    else:

        print((1000 - N))

N = int(eval(input()))
if N % 1000 == 0:
    print((0))
else:
    Str = str(N)
    if len(Str) > 3:
        K = (int(Str[0]) + 1) * 1000
        print((K - N))
    else:
        print((1000 - N))


Input:
from operator import itemgetter

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

ab = [[0,0] for i in range(M)]

for i in range(M):

    ab[i] = list(map(int, input().split()))

ab = sorted(ab, key=itemgetter(0,1))

re = 1

x, y = ab[0]

for i in range(1, M):

    a, b = ab[i]

    if b <= x or y <= a: # 切ったとこの範囲外だったら

        re += 1

        x, y = a, b

    else:

        x = max(x, 1)

        y = min(y, b)

print(re)

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

pair = []

for i in range(M):

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

    pair.append([b, a])

# bをキーにして昇順にソートする

pair.sort()

ans = 1

y, x = pair[0]

for i in range(1, M):

    b, a = pair[i]

    if y <= a:

        y = b

        ans += 1

print(ans)

from operator import itemgetter

N, M = list(map(int, input().split()))
ab = [[0, 0] for i in range(M)]
for i in range(M):
    ab[i] = list(map(int, input().split()))
ab = sorted(ab, key=itemgetter(0, 1))
re = 1
x, y = ab[0]
for i in range(1, M):
    a, b = ab[i]
    if b <= x or y <= a:  # 切ったとこの範囲外だったら
        re += 1
        x, y = a, b
    else:
        x = max(x, 1)
        y = min(y, b)
print(re)

-    ab[i] = list(map(int, input().split()))

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

+# bをキーにして昇順にソートする

-    if b <= x or y <= a:  # 切ったとこの範囲外だったら


Input:
import sys

input = sys.stdin.readline

a = list(map(int, input().rstrip().split(' ')))

for i in range(len(a)):

  if a[i] == 0:

    print((i+1))

    break

import sys

input = sys.stdin.readline

a = list(map(int, input().split(' ')))

for i in range(len(a)):

  if a[i] == 0:

    print((i+1))

    break

import sys

input = sys.stdin.readline
a = list(map(int, input().rstrip().split(" ")))
for i in range(len(a)):
    if a[i] == 0:
        print((i + 1))
        break

import sys

input = sys.stdin.readline
a = list(map(int, input().split(" ")))
for i in range(len(a)):
    if a[i] == 0:
        print((i + 1))
        break

-a = list(map(int, input().rstrip().split(" ")))


Input:
import math

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

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

dis = []

ans = 0

for i in range(n):

  dis.append(abs(x-xl[i]))

for i in range(n):

  ans = math.gcd(ans,dis[i])

print(ans)

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

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

ans = 0

from math import gcd

for i in range(N):

  ans = gcd(ans,abs(X-x[i]))

print(ans)

import math

n, x = list(map(int, input().split()))
xl = list(map(int, input().split()))
dis = []
ans = 0
for i in range(n):
    dis.append(abs(x - xl[i]))
for i in range(n):
    ans = math.gcd(ans, dis[i])
print(ans)

N, X = list(map(int, input().split()))
x = list(map(int, input().split()))
ans = 0
from math import gcd

for i in range(N):
    ans = gcd(ans, abs(X - x[i]))
print(ans)

-import math
+N, X = list(map(int, input().split()))
+x = list(map(int, input().split()))
+ans = 0
+from math import gcd
-n, x = list(map(int, input().split()))
-xl = list(map(int, input().split()))
-dis = []
-ans = 0
-for i in range(n):
-    dis.append(abs(x - xl[i]))
-for i in range(n):
-    ans = math.gcd(ans, dis[i])
+for i in range(N):
+    ans = gcd(ans, abs(X - x[i]))


Input:
# -*- coding: utf-8 -*-

import bisect

import heapq

import math

import random

import sys

from collections import Counter, defaultdict, deque

from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal

from functools import lru_cache, reduce

from itertools import combinations, combinations_with_replacement, product, permutations

from operator import add, mul, sub

sys.setrecursionlimit(1000000)

input = sys.stdin.readline

INF = 2**62-1

def read_int():

    return int(input())

def read_int_n():

    return list(map(int, input().split()))

def read_float():

    return float(input())

def read_float_n():

    return list(map(float, input().split()))

def read_str():

    return input().strip()

def read_str_n():

    return list(map(str, input().split()))

def error_print(*args):

    print(*args, file=sys.stderr)

def mt(f):

    import time

    def wrap(*args, **kwargs):

        s = time.time()

        ret = f(*args, **kwargs)

        e = time.time()

        error_print(e - s, 'sec')

        return ret

    return wrap

def is_lunlun(n):

    s = str(n)

    for i in range(len(s)-1):

        if abs(int(s[i])-int(s[i+1])) > 1:

            return False

    return True

def slv(k):

    n = 1

    for _ in range(k-1):

        j = 0

        while True:

            l = 10**j

            t = 0

            t += n + l

            t -= (n+l) % l

            m = (t % (10**(j+1))) // l

            # print(t, j, m)

            for i in range(j-1, -1, -1):

                t += (10 ** i) * max(0, m-(j-i))

            # print(t, j)

            if is_lunlun(t):

                n = t

                break

            else:

                j+=1

            # if j > 5:

            #     break

        # print(n)

    return n

def main():

    K = read_int()

    print(slv(K))

if __name__ == '__main__':

    main()

# -*- coding: utf-8 -*-

import bisect

import heapq

import math

import random

import sys

from collections import Counter, defaultdict, deque

from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal

from functools import lru_cache, reduce

from itertools import combinations, combinations_with_replacement, product, permutations

from operator import add, mul, sub

sys.setrecursionlimit(1000000)

input = sys.stdin.readline

INF = 2**62-1

def read_int():

    return int(input())

def read_int_n():

    return list(map(int, input().split()))

def read_float():

    return float(input())

def read_float_n():

    return list(map(float, input().split()))

def read_str():

    return input().strip()

def read_str_n():

    return list(map(str, input().split()))

def error_print(*args):

    print(*args, file=sys.stderr)

def mt(f):

    import time

    def wrap(*args, **kwargs):

        s = time.time()

        ret = f(*args, **kwargs)

        e = time.time()

        error_print(e - s, 'sec')

        return ret

    return wrap

def is_lunlun(n):

    s = str(n)

    for i in range(len(s)-1):

        if abs(int(s[i])-int(s[i+1])) > 1:

            return False

    return True

def slv(k):

    if k <= 9:

        return k

    lunlun = list(range(1, 10))

    q = deque(lunlun)

    while True:

        n = q.popleft()

        for i in (-1, 0, 1):

            d = n % 10

            if 0 <= d + i <= 9:

                l = n * 10 + d+i

                q.append(l)

                lunlun.append(l)

                if len(lunlun) == k:

                    return lunlun[-1]

def main():

    K = read_int()

    print(slv(K))

if __name__ == '__main__':

    main()

# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(1000000)
input = sys.stdin.readline
INF = 2**62 - 1

def read_int():
    return int(input())

def read_int_n():
    return list(map(int, input().split()))

def read_float():
    return float(input())

def read_float_n():
    return list(map(float, input().split()))

def read_str():
    return input().strip()

def read_str_n():
    return list(map(str, input().split()))

def error_print(*args):
    print(*args, file=sys.stderr)

def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()
        error_print(e - s, "sec")
        return ret

    return wrap

def is_lunlun(n):
    s = str(n)
    for i in range(len(s) - 1):
        if abs(int(s[i]) - int(s[i + 1])) > 1:
            return False
    return True

def slv(k):
    n = 1
    for _ in range(k - 1):
        j = 0
        while True:
            l = 10**j
            t = 0
            t += n + l
            t -= (n + l) % l
            m = (t % (10 ** (j + 1))) // l
            # print(t, j, m)
            for i in range(j - 1, -1, -1):
                t += (10**i) * max(0, m - (j - i))
            # print(t, j)
            if is_lunlun(t):
                n = t
                break
            else:
                j += 1
            # if j > 5:
            #     break
        # print(n)
    return n

def main():
    K = read_int()
    print(slv(K))

if __name__ == "__main__":
    main()

# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(1000000)
input = sys.stdin.readline
INF = 2**62 - 1

def read_int():
    return int(input())

def read_int_n():
    return list(map(int, input().split()))

def read_float():
    return float(input())

def read_float_n():
    return list(map(float, input().split()))

def read_str():
    return input().strip()

def read_str_n():
    return list(map(str, input().split()))

def error_print(*args):
    print(*args, file=sys.stderr)

def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()
        error_print(e - s, "sec")
        return ret

    return wrap

def is_lunlun(n):
    s = str(n)
    for i in range(len(s) - 1):
        if abs(int(s[i]) - int(s[i + 1])) > 1:
            return False
    return True

def slv(k):
    if k <= 9:
        return k
    lunlun = list(range(1, 10))
    q = deque(lunlun)
    while True:
        n = q.popleft()
        for i in (-1, 0, 1):
            d = n % 10
            if 0 <= d + i <= 9:
                l = n * 10 + d + i
                q.append(l)
                lunlun.append(l)
                if len(lunlun) == k:
                    return lunlun[-1]

def main():
    K = read_int()
    print(slv(K))

if __name__ == "__main__":
    main()

-            for i in range(j - 1, -1, -1):


Input:
n = int(eval(input()))

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

A.sort()

ac = A.count(1)

if ac == 1:

    print((1))

    exit()

if ac >= 2:

    print((0))

    exit()

num = [0]*1000005

for a in A:

    num[a] += 1

b = [False]*1000005

seen = [False]*1000005

cnt = 0

A = list(set(A))

A.sort()

for a in A:

    if seen[a]:

        continue

    seen[a] = True

    if b[a] == False:

        cnt += 1

        if num[a] > 1:

            cnt -= 1

    for i in range(a, 1000005, a):

        b[i] = True

print(cnt)

n = int(eval(input()))

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

num = [0]*(10**6+1)

for a in A:

    num[a] += 1

bai = [False]*(10**6+1)

cnt = 0

A = list(set(A))

A.sort()

for a in A:

    if bai[a]:

        continue

    if num[a] == 1:

        cnt += 1

    for i in range(a, 10**6+1, a):

        bai[i] = True

print(cnt)

n = int(eval(input()))
A = list(map(int, input().split()))
A.sort()
ac = A.count(1)
if ac == 1:
    print((1))
    exit()
if ac >= 2:
    print((0))
    exit()
num = [0] * 1000005
for a in A:
    num[a] += 1
b = [False] * 1000005
seen = [False] * 1000005
cnt = 0
A = list(set(A))
A.sort()
for a in A:
    if seen[a]:
        continue
    seen[a] = True
    if b[a] == False:
        cnt += 1
        if num[a] > 1:
            cnt -= 1
    for i in range(a, 1000005, a):
        b[i] = True
print(cnt)

n = int(eval(input()))
A = list(map(int, input().split()))
num = [0] * (10**6 + 1)
for a in A:
    num[a] += 1
bai = [False] * (10**6 + 1)
cnt = 0
A = list(set(A))
A.sort()
for a in A:
    if bai[a]:
        continue
    if num[a] == 1:
        cnt += 1
    for i in range(a, 10**6 + 1, a):
        bai[i] = True
print(cnt)


Input:
a, b, x = list(map(int, input().split()))

print((int(b//x) - int((a-1)//x)))

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

print((b//x - (a-1)//x))

a, b, x = list(map(int, input().split()))
print((int(b // x) - int((a - 1) // x)))

a, b, x = list(map(int, input().split()))
print((b // x - (a - 1) // x))


Input:
from math import ceil

n = int(eval(input()))

numeros = [int(x) for x in input().split()]

saida = 2000000000000000

for i in range(min(numeros), max(numeros)+1):

	valor = 0

	for j in numeros:

		valor += (j-i)**2

	saida = min(valor, saida)

print(saida)

import sys

n = int(eval(input()))

numeros = [int(x) for x in input().split()]

saida = sys.maxsize

for i in range(min(numeros), max(numeros)+1):

	valor = 0

	for j in numeros:

		valor += (j-i)**2

	saida = min(valor, saida)

print(saida)

from math import ceil

n = int(eval(input()))
numeros = [int(x) for x in input().split()]
saida = 2000000000000000
for i in range(min(numeros), max(numeros) + 1):
    valor = 0
    for j in numeros:
        valor += (j - i) ** 2
    saida = min(valor, saida)
print(saida)

import sys

n = int(eval(input()))
numeros = [int(x) for x in input().split()]
saida = sys.maxsize
for i in range(min(numeros), max(numeros) + 1):
    valor = 0
    for j in numeros:
        valor += (j - i) ** 2
    saida = min(valor, saida)
print(saida)

-from math import ceil
+import sys
-saida = 2000000000000000
+saida = sys.maxsize


Input:
N, K = [int(i) for i in input().split()]

L = [[int(i) for i in input().split()] for _ in range(N)]

L.sort()

k = 0

for a, b in L:

    if k + b >= K:

        print(a)

        quit()

    k += b

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

memo = [0] * (10 ** 5 + 10)

for _ in range(N):

    a, b = [int(i) for i in input().split()]

    memo[a] += b

for i, b in enumerate(memo):

    if K <= memo[i]:

        print(i)

        quit()

    K -= memo[i]

N, K = [int(i) for i in input().split()]
memo = [0] * (10**5 + 10)
for _ in range(N):
    a, b = [int(i) for i in input().split()]
    memo[a] += b
for i, b in enumerate(memo):
    if K <= memo[i]:
        print(i)
        quit()
    K -= memo[i]

-L = [[int(i) for i in input().split()] for _ in range(N)]

+    a, b = [int(i) for i in input().split()]


Input:
import math

def main():

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

    # 条件を満たす可能性のある最小の正数を計算

    x_min = max(math.ceil(A / 0.08), math.ceil(B / 0.1))

    # 条件を満たす可能性のある最大の正数を計算

    x_max = min((math.ceil((A + 1) / 0.08), math.ceil((B + 1) / 0.1)))

    # 候補の正数を順番にチェックし、満たすものがあればそれを出力して終了

    for x in range(x_min, x_max + 1):

        if (math.floor(x * 0.08) == A) and (math.floor(x * 0.1) == B):

            print(x)

            quit()

    # ここまで来るときは満たすものがないので、-1を出力

    print((-1))

if __name__ == "__main__":

    main()

from math import floor

# 入力値の取得

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

# 問題の制約から、答えの候補としてあり得る範囲をチェック

# for _ in range(1010)で０〜１００９までのループが使える

for price in range(1010):

    if (floor(price * 0.08) == A) and (floor(price * 0.1) == B):

        # 条件を満たしたのでその金額を表示して終了

        # （小さい金額から順番にみていくので、最初に条件を満たしたものが、

        # 　条件を満たす金額のうちで最小の金額になる。）

        print(price)

        quit()

# 条件を満たすものが見つかっていれば、プログラムが終了するので、

# ここまで実行される時は、条件を満たす金額が存在しないということなので、

# 条件を満たす金額が存在しない時に表示すべき -1 を表示する。

# 最小行なので、quit()しなくてもプログラムが終了する

print((-1))

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

-    # 条件を満たす可能性のある最小の正数を計算

-    x_min = max(math.ceil(A / 0.08), math.ceil(B / 0.1))

-    # 条件を満たす可能性のある最大の正数を計算

-    # 候補の正数を順番にチェックし、満たすものがあればそれを出力して終了

-        if (math.floor(x * 0.08) == A) and (math.floor(x * 0.1) == B):

-    # ここまで来るときは満たすものがないので、-1を出力

+# 問題の制約から、答えの候補としてあり得る範囲をチェック

+# for _ in range(1010)で０〜１００９までのループが使える

+    if (floor(price * 0.08) == A) and (floor(price * 0.1) == B):

+        # 条件を満たしたのでその金額を表示して終了

+        # （小さい金額から順番にみていくので、最初に条件を満たしたものが、

+        # 　条件を満たす金額のうちで最小の金額になる。）

+# 条件を満たすものが見つかっていれば、プログラムが終了するので、

+# ここまで実行される時は、条件を満たす金額が存在しないということなので、

+# 条件を満たす金額が存在しない時に表示すべき -1 を表示する。

+# 最小行なので、quit()しなくてもプログラムが終了する


Input:
n,W = list(map(int,input().split()))

dp = [[[0]*(3*n+1) for _ in range(n)] for _ in range(n)]

w1,v1 = list(map(int,input().split()))

for i in range(3*n+1):

    dp[0][0][i] = v1

for i in range(1,n):

    w,v = list(map(int,input().split()))

    w -= w1

    for j in range(min(i+1,n)):

        for k in range(3*n+1):

            if j>0 and k>=w:

                dp[i][j][k] = max(dp[i-1][j][k], dp[i-1][j-1][k-w] + v)

            elif k>=w:

                dp[i][0][k] = max(dp[i-1][0][k], v)

            else:

                dp[i][j][k] = dp[i-1][j][k]

ans = 0

for i in range(n):

    for j in range(3*n+1):

        if w1*(i+1) + j>W: continue

        ans = max(ans,dp[-1][i][j])

print(ans)

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

dp = [[[0]*(3*n+1) for _ in range(n)] for _ in range(n)]

w1,v1 = list(map(int,input().split()))

for i in range(3*n+1):

    dp[0][0][i] = v1

for i in range(1,n):

    w,v = list(map(int,input().split()))

    w -= w1

    for j in range(min(i+1,n)):

        for k in range(3*(j+1)+1):

            if j>0 and k>=w:

                dp[i][j][k] = max(dp[i-1][j][k], dp[i-1][j-1][k-w] + v)

            elif k>=w:

                dp[i][0][k] = max(dp[i-1][0][k], v)

            else:

                dp[i][j][k] = dp[i-1][j][k]

ans = 0

for i in range(n):

    for j in range(3*n+1):

        if w1*(i+1) + j>W: continue

        ans = max(ans,dp[-1][i][j])

print(ans)

n, W = list(map(int, input().split()))
dp = [[[0] * (3 * n + 1) for _ in range(n)] for _ in range(n)]
w1, v1 = list(map(int, input().split()))
for i in range(3 * n + 1):
    dp[0][0][i] = v1
for i in range(1, n):
    w, v = list(map(int, input().split()))
    w -= w1
    for j in range(min(i + 1, n)):
        for k in range(3 * n + 1):
            if j > 0 and k >= w:
                dp[i][j][k] = max(dp[i - 1][j][k], dp[i - 1][j - 1][k - w] + v)
            elif k >= w:
                dp[i][0][k] = max(dp[i - 1][0][k], v)
            else:
                dp[i][j][k] = dp[i - 1][j][k]
ans = 0
for i in range(n):
    for j in range(3 * n + 1):
        if w1 * (i + 1) + j > W:
            continue
        ans = max(ans, dp[-1][i][j])
print(ans)

n, W = list(map(int, input().split()))
dp = [[[0] * (3 * n + 1) for _ in range(n)] for _ in range(n)]
w1, v1 = list(map(int, input().split()))
for i in range(3 * n + 1):
    dp[0][0][i] = v1
for i in range(1, n):
    w, v = list(map(int, input().split()))
    w -= w1
    for j in range(min(i + 1, n)):
        for k in range(3 * (j + 1) + 1):
            if j > 0 and k >= w:
                dp[i][j][k] = max(dp[i - 1][j][k], dp[i - 1][j - 1][k - w] + v)
            elif k >= w:
                dp[i][0][k] = max(dp[i - 1][0][k], v)
            else:
                dp[i][j][k] = dp[i - 1][j][k]
ans = 0
for i in range(n):
    for j in range(3 * n + 1):
        if w1 * (i + 1) + j > W:
            continue
        ans = max(ans, dp[-1][i][j])
print(ans)

+        for k in range(3 * (j + 1) + 1):


Input:
N = int(eval(input()))

abc = []

for _ in range(N):

    abc.append(tuple(map(int, input().split())))

dp = [[0] * 3 for _ in range(N+1)]

for i in range(1, N+1):

    for k in range(3):

        for last in range(3):

            if k != last:

                dp[i][k] = max(dp[i][k], dp[i-1][last] + abc[i-1][last])

ans = max(dp[N][k] for k in range(3))

print(ans)

N = int(eval(input()))

cur, nxt = [0] * 3, [0] * 3

for i in range(N):

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

    for k in range(3):

        for last in range(3):

            if k != last:

                nxt[k] = max(nxt[k], cur[last] + abc[k])

    cur = nxt

    nxt = [0] * 3

ans = max(cur[k] for k in range(3))

print(ans)

N = int(eval(input()))
abc = []
for _ in range(N):
    abc.append(tuple(map(int, input().split())))
dp = [[0] * 3 for _ in range(N + 1)]
for i in range(1, N + 1):
    for k in range(3):
        for last in range(3):
            if k != last:
                dp[i][k] = max(dp[i][k], dp[i - 1][last] + abc[i - 1][last])
ans = max(dp[N][k] for k in range(3))
print(ans)

-    abc.append(tuple(map(int, input().split())))

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

-                dp[i][k] = max(dp[i][k], dp[i - 1][last] + abc[i - 1][last])

+                nxt[k] = max(nxt[k], cur[last] + abc[k])


Input:
i = 1

while 1:

	x = eval(input())

	if x == 0:

		break

	print('Case %d: %d' % (i, x))

	i+=1

i = 1

while 1:

	x = input()

	if x == '0':

		break

	print('Case %d: %s' % (i, x))

	i+=1

i = 1
while 1:
    x = eval(input())
    if x == 0:
        break
    print("Case %d: %d" % (i, x))
    i += 1

i = 1
while 1:
    x = input()
    if x == "0":
        break
    print("Case %d: %s" % (i, x))
    i += 1

-    x = eval(input())
-    if x == 0:
+    x = input()
+    if x == "0":
-    print("Case %d: %d" % (i, x))
+    print("Case %d: %s" % (i, x))


Input:
import heapq

import sys

input = sys.stdin.readline

INF = 10**18

n,m,s,t = list(map(int,input().split()))

edge = [list(map(int,input().split())) for _ in range(m)]

graph_s = [[] for _ in range(n)]

graph_t = [[] for _ in range(n)]

for e in edge:

    graph_s[e[0]-1].append([e[1]-1,e[2]])

    graph_s[e[1]-1].append([e[0]-1,e[2]])

    graph_t[e[0]-1].append([e[1]-1,e[3]])

    graph_t[e[1]-1].append([e[0]-1,e[3]])

dist_s = [INF]*n

dist_t = [INF]*n

dist_s[s-1] = 0

dist_t[t-1] = 0

heap_s = [[0,s-1]]

heapq.heapify(heap_s)

heap_t = [[0,t-1]]

heapq.heapify(heap_t)

while heap_s:

    cost,node = heapq.heappop(heap_s)

    if dist_s[node] < cost:

        continue

    for adj,adjcost in graph_s[node]:

        if dist_s[node] + adjcost < dist_s[adj]:

            dist_s[adj] = dist_s[node] + adjcost

            heapq.heappush(heap_s,[dist_s[adj],adj])

while heap_t:

    cost,node = heapq.heappop(heap_t)

    if dist_t[node] < cost:

        continue

    for adj,adjcost in graph_t[node]:

        if dist_t[node] + adjcost < dist_t[adj]:

            dist_t[adj] = dist_t[node] + adjcost

            heapq.heappush(heap_t,[dist_t[adj],adj])

dist = INF

ans = []

for i in range(n):

    dist = min(dist,dist_t[-1-i]+dist_s[-1-i])

    ans.append(10**15-dist)

for i in range(n):

    print((ans[-1-i]))

from heapq import heappop, heappush, heapify

class Graph():  #non-directed

    def __init__(self, n, edge, indexed=1):

        self.n = n

        self.edge = edge

        self.indexed = indexed

        self.graph = [[] for _ in range(n)]

        for e in edge:

            self.graph[e[0] - indexed].append((e[1] - indexed, e[2]))

            self.graph[e[1] - indexed].append((e[0] - indexed, e[2]))

    def dijkstra(self, s, INF=10**18, restore_to=None):

        dist = [INF for _ in range(self.n)]

        dist[s] = 0

        heap = [(0, s)]

        prev = [None for _ in range(self.n)]

        while heap:

            cost, node = heappop(heap)

            if dist[node] < cost:

                continue

            for adj, adjcost in self.graph[node]:

                if dist[node] + adjcost < dist[adj]:

                    dist[adj] = dist[node] + adjcost

                    prev[adj] = node

                    heappush(heap, (dist[adj], adj))

        if restore_to is not None:

            g = restore_to

            if dist[g] == INF:

                return dist, False

            path = [g]

            node = g

            while node != s:

                node = prev[node]

                path.append(node)

            return dist, path[::-1]

        return dist

import sys

input = sys.stdin.readline

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

E1 = []

E2 = []

for _ in range(M):

    u, v, a, b = list(map(int, input().split()))

    E1.append((u, v, a))

    E2.append((u, v, b))

g1 = Graph(N, E1)

g2 = Graph(N, E2)

dist_from_s = g1.dijkstra(S - 1)

dist_from_t = g2.dijkstra(T - 1)

res = list()

tmp = 0

for i in range(N)[::-1]:

    tmp = max(tmp, 10**15 - dist_from_t[i] - dist_from_s[i])

    res.append(tmp)

print(('\n'.join(map(str, res[::-1]))))

import heapq
import sys

input = sys.stdin.readline
INF = 10**18
n, m, s, t = list(map(int, input().split()))
edge = [list(map(int, input().split())) for _ in range(m)]
graph_s = [[] for _ in range(n)]
graph_t = [[] for _ in range(n)]
for e in edge:
    graph_s[e[0] - 1].append([e[1] - 1, e[2]])
    graph_s[e[1] - 1].append([e[0] - 1, e[2]])
    graph_t[e[0] - 1].append([e[1] - 1, e[3]])
    graph_t[e[1] - 1].append([e[0] - 1, e[3]])
dist_s = [INF] * n
dist_t = [INF] * n
dist_s[s - 1] = 0
dist_t[t - 1] = 0
heap_s = [[0, s - 1]]
heapq.heapify(heap_s)
heap_t = [[0, t - 1]]
heapq.heapify(heap_t)
while heap_s:
    cost, node = heapq.heappop(heap_s)
    if dist_s[node] < cost:
        continue
    for adj, adjcost in graph_s[node]:
        if dist_s[node] + adjcost < dist_s[adj]:
            dist_s[adj] = dist_s[node] + adjcost
            heapq.heappush(heap_s, [dist_s[adj], adj])
while heap_t:
    cost, node = heapq.heappop(heap_t)
    if dist_t[node] < cost:
        continue
    for adj, adjcost in graph_t[node]:
        if dist_t[node] + adjcost < dist_t[adj]:
            dist_t[adj] = dist_t[node] + adjcost
            heapq.heappush(heap_t, [dist_t[adj], adj])
dist = INF
ans = []
for i in range(n):
    dist = min(dist, dist_t[-1 - i] + dist_s[-1 - i])
    ans.append(10**15 - dist)
for i in range(n):
    print((ans[-1 - i]))

from heapq import heappop, heappush, heapify

class Graph:  # non-directed
    def __init__(self, n, edge, indexed=1):
        self.n = n
        self.edge = edge
        self.indexed = indexed
        self.graph = [[] for _ in range(n)]
        for e in edge:
            self.graph[e[0] - indexed].append((e[1] - indexed, e[2]))
            self.graph[e[1] - indexed].append((e[0] - indexed, e[2]))

    def dijkstra(self, s, INF=10**18, restore_to=None):
        dist = [INF for _ in range(self.n)]
        dist[s] = 0
        heap = [(0, s)]
        prev = [None for _ in range(self.n)]
        while heap:
            cost, node = heappop(heap)
            if dist[node] < cost:
                continue
            for adj, adjcost in self.graph[node]:
                if dist[node] + adjcost < dist[adj]:
                    dist[adj] = dist[node] + adjcost
                    prev[adj] = node
                    heappush(heap, (dist[adj], adj))
        if restore_to is not None:
            g = restore_to
            if dist[g] == INF:
                return dist, False
            path = [g]
            node = g
            while node != s:
                node = prev[node]
                path.append(node)
            return dist, path[::-1]
        return dist

import sys

input = sys.stdin.readline
N, M, S, T = list(map(int, input().split()))
E1 = []
E2 = []
for _ in range(M):
    u, v, a, b = list(map(int, input().split()))
    E1.append((u, v, a))
    E2.append((u, v, b))
g1 = Graph(N, E1)
g2 = Graph(N, E2)
dist_from_s = g1.dijkstra(S - 1)
dist_from_t = g2.dijkstra(T - 1)
res = list()
tmp = 0
for i in range(N)[::-1]:
    tmp = max(tmp, 10**15 - dist_from_t[i] - dist_from_s[i])
    res.append(tmp)
print(("\n".join(map(str, res[::-1]))))

+from heapq import heappop, heappush, heapify

+    def __init__(self, n, edge, indexed=1):

+        self.graph = [[] for _ in range(n)]

+            self.graph[e[0] - indexed].append((e[1] - indexed, e[2]))

+            self.graph[e[1] - indexed].append((e[0] - indexed, e[2]))

+    def dijkstra(self, s, INF=10**18, restore_to=None):

+        dist = [INF for _ in range(self.n)]

+        prev = [None for _ in range(self.n)]

+            for adj, adjcost in self.graph[node]:

+                if dist[node] + adjcost < dist[adj]:

+                    dist[adj] = dist[node] + adjcost

+                    heappush(heap, (dist[adj], adj))

-n, m, s, t = list(map(int, input().split()))

-edge = [list(map(int, input().split())) for _ in range(m)]

-        if dist_s[node] + adjcost < dist_s[adj]:

-            dist_s[adj] = dist_s[node] + adjcost

-            heapq.heappush(heap_s, [dist_s[adj], adj])

-        if dist_t[node] + adjcost < dist_t[adj]:

-            dist_t[adj] = dist_t[node] + adjcost

-            heapq.heappush(heap_t, [dist_t[adj], adj])

-    dist = min(dist, dist_t[-1 - i] + dist_s[-1 - i])

+N, M, S, T = list(map(int, input().split()))

+    u, v, a, b = list(map(int, input().split()))

+    tmp = max(tmp, 10**15 - dist_from_t[i] - dist_from_s[i])


Input:
MOD = 10 ** 9 + 7

n = int(eval(input()))

res = 1

ex = [0 for _ in range(n + 1)]

for i in range(1, n + 1):

    for j in range(2, i + 1):

        if i % j == 0:

            while i % j == 0:

                ex[j] += 1

                i //= j

ans = 1

for i in range(n + 1):

    ans *= (ex[i] + 1)

    ans %= MOD

print(ans)

import sys

sys.setrecursionlimit(10 ** 7)

input = sys.stdin.readline

f_inf = float('inf')

mod = 10 ** 9 + 7

def prime_factorization(n):

    res = []

    for i in range(2, int(pow(n, 0.5)) + 1):

        if n % i == 0:

            ex = 0

            while n % i == 0:

                ex += 1

                n //= i

            res.append([i, ex])

    if n != 1:

        res.append([n, 1])

    return res

def resolve():

    n = int(eval(input()))

    P = [0] * 1000

    for i in range(1, n + 1):

        t = prime_factorization(i)

        for num, ex in t:

            P[num] += ex

    res = 1

    for p in P:

        res *= p + 1

        res % mod

    print((res % mod))

if __name__ == '__main__':

    resolve()

MOD = 10**9 + 7
n = int(eval(input()))
res = 1
ex = [0 for _ in range(n + 1)]
for i in range(1, n + 1):
    for j in range(2, i + 1):
        if i % j == 0:
            while i % j == 0:
                ex[j] += 1
                i //= j
ans = 1
for i in range(n + 1):
    ans *= ex[i] + 1
    ans %= MOD
print(ans)

import sys

sys.setrecursionlimit(10**7)
input = sys.stdin.readline
f_inf = float("inf")
mod = 10**9 + 7

def prime_factorization(n):
    res = []
    for i in range(2, int(pow(n, 0.5)) + 1):
        if n % i == 0:
            ex = 0
            while n % i == 0:
                ex += 1
                n //= i
            res.append([i, ex])
    if n != 1:
        res.append([n, 1])
    return res

def resolve():
    n = int(eval(input()))
    P = [0] * 1000
    for i in range(1, n + 1):
        t = prime_factorization(i)
        for num, ex in t:
            P[num] += ex
    res = 1
    for p in P:
        res *= p + 1
        res % mod
    print((res % mod))

if __name__ == "__main__":
    resolve()

+    for i in range(2, int(pow(n, 0.5)) + 1):


Input:
s = eval(input())

for i in range(1, 4):

    if s[i] == s[i - 1]:

        print("Bad")

        exit()

print("Good")

s = eval(input())

for i in range(3):

    if s[i] == s[i + 1]:

        print("Bad")

        exit()

print("Good")

-for i in range(1, 4):
-    if s[i] == s[i - 1]:
+for i in range(3):
+    if s[i] == s[i + 1]:


Input:
from collections import Counter

N = int(eval(input()))

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

MAX = 10 ** 6 + 10

multiples = [0] * MAX

for a in list(set(A)):

    for j in range(a * 2, MAX, a):

        multiples[j] = 1

d = Counter(A)

dup = [k for k, v in list(d.items()) if v > 1]

for i in dup:

    multiples[i] = 1

ans = 0

for i in A:

    if multiples[i] == 0:

        ans += 1

print(ans)

N = int(eval(input()))

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

MAX = 10 ** 6 + 10

cnt = [0] * MAX  # cntが1以上ならその数以下に約数が1個以上存在する(自分も含める)

for a in A:

    if cnt[a] != 0:

        cnt[a] += 1

        continue

    for j in range(a, MAX, a):

        cnt[j] += 1

ans = 0

for a in A:

    if cnt[a] == 1:

        ans += 1

print(ans)

from collections import Counter

N = int(eval(input()))
A = list(map(int, input().split()))
MAX = 10**6 + 10
multiples = [0] * MAX
for a in list(set(A)):
    for j in range(a * 2, MAX, a):
        multiples[j] = 1
d = Counter(A)
dup = [k for k, v in list(d.items()) if v > 1]
for i in dup:
    multiples[i] = 1
ans = 0
for i in A:
    if multiples[i] == 0:
        ans += 1
print(ans)

N = int(eval(input()))
A = list(map(int, input().split()))
MAX = 10**6 + 10
cnt = [0] * MAX  # cntが1以上ならその数以下に約数が1個以上存在する(自分も含める)
for a in A:
    if cnt[a] != 0:
        cnt[a] += 1
        continue
    for j in range(a, MAX, a):
        cnt[j] += 1
ans = 0
for a in A:
    if cnt[a] == 1:
        ans += 1
print(ans)

-dup = [k for k, v in list(d.items()) if v > 1]

+cnt = [0] * MAX  # cntが1以上ならその数以下に約数が1個以上存在する(自分も含める)


Input:
X = int(eval(input()))

if X == 7 or X == 5 or X == 3:

    print('YES')

else:

    print('NO')

X = int(eval(input()))

if X in (3, 5, 7):

    print('YES')

else:

    print('NO')

X = int(eval(input()))
if X == 7 or X == 5 or X == 3:
    print("YES")
else:
    print("NO")

X = int(eval(input()))
if X in (3, 5, 7):
    print("YES")
else:
    print("NO")


Input:
from sys import stdin

from functools import reduce

import fractions

#input = stdin.readline

N = int(eval(input()))

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

answer = reduce(fractions.gcd, A)

print(answer)

def gcd(a,b):

    if(a%b==0):

        return b

    else:

        return gcd(b,a%b)

N = int(eval(input()))

s = [int(x) for x in input().split()]

tmp = s[0]

for i in s[1:]:

    tmp = gcd(tmp,i)

print(tmp)

from sys import stdin
from functools import reduce
import fractions

# input = stdin.readline
N = int(eval(input()))
A = list(set(map(int, input().split())))
answer = reduce(fractions.gcd, A)
print(answer)

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

N = int(eval(input()))
s = [int(x) for x in input().split()]
tmp = s[0]
for i in s[1:]:
    tmp = gcd(tmp, i)
print(tmp)

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


Input:
def insertion_sort(a, n, g, cnt):

    for i in range(g, n):

        v, j = a[i], i - g

        while j >= 0 and a[j] > v:

            a[j + g] = a[j]

            j = j - g

            cnt += 1

        a[j + g] = v

    return cnt

n = int(eval(input()))

a = list(int(eval(input())) for _ in range(n))

m, g, cnt = 0, n // 2 + 1, 0

glist = []

while g:

    m += 1

    glist.append(g)

    cnt = insertion_sort(a, n, g, cnt)

    g //= 2

print(m)

print((*glist))

print(cnt)

print(('\n'.join(str(i) for i in a)))

def insertion_sort(a, n, g, cnt):

    for i in range(g, n):

        v, j = a[i], i - g

        while j >= 0 and a[j] > v:

            a[j + g] = a[j]

            j = j - g

            cnt += 1

        a[j + g] = v

    return cnt

n = int(eval(input()))

a = list(int(eval(input())) for _ in range(n))

m, g, glist, cnt = 0, 1, [], 0

while g <= n:

    m += 1

    glist.append(g)

    g = 4 ** m + 3 * 2 ** (m - 1) + 1

glist.reverse()

for g in glist:

    cnt = insertion_sort(a, n, g, cnt)

print(m)

print((*glist))

print(cnt)

print(('\n'.join(map(str, a))))

def insertion_sort(a, n, g, cnt):
    for i in range(g, n):
        v, j = a[i], i - g
        while j >= 0 and a[j] > v:
            a[j + g] = a[j]
            j = j - g
            cnt += 1
        a[j + g] = v
    return cnt

n = int(eval(input()))
a = list(int(eval(input())) for _ in range(n))
m, g, cnt = 0, n // 2 + 1, 0
glist = []
while g:
    m += 1
    glist.append(g)
    cnt = insertion_sort(a, n, g, cnt)
    g //= 2
print(m)
print((*glist))
print(cnt)
print(("\n".join(str(i) for i in a)))

def insertion_sort(a, n, g, cnt):
    for i in range(g, n):
        v, j = a[i], i - g
        while j >= 0 and a[j] > v:
            a[j + g] = a[j]
            j = j - g
            cnt += 1
        a[j + g] = v
    return cnt

n = int(eval(input()))
a = list(int(eval(input())) for _ in range(n))
m, g, glist, cnt = 0, 1, [], 0
while g <= n:
    m += 1
    glist.append(g)
    g = 4**m + 3 * 2 ** (m - 1) + 1
glist.reverse()
for g in glist:
    cnt = insertion_sort(a, n, g, cnt)
print(m)
print((*glist))
print(cnt)
print(("\n".join(map(str, a))))

-m, g, cnt = 0, n // 2 + 1, 0
-glist = []
-while g:
+m, g, glist, cnt = 0, 1, [], 0
+while g <= n:
+    g = 4**m + 3 * 2 ** (m - 1) + 1
+glist.reverse()
+for g in glist:
-    g //= 2
-print(("\n".join(str(i) for i in a)))
+print(("\n".join(map(str, a))))


Input:
import itertools

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

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

acc = itertools.accumulate(A)

acc = [e % M for e in acc]

cnt_dict = {}

ans = 0

for e in acc:

    if e == 0:

        ans += 1

    if e in cnt_dict:

        cnt_dict[e] += 1

    else:

        cnt_dict[e] = 0

    ans += cnt_dict[e]

print(ans)

def main():

    import itertools

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

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

    acc = itertools.accumulate(A)

    acc = [e % M for e in acc]

    cnt_dict = {}

    ans = 0

    for e in acc:

        if e == 0:

            ans += 1

        if e in cnt_dict:

            cnt_dict[e] += 1

        else:

            cnt_dict[e] = 0

        ans += cnt_dict[e]

    print(ans)

main()

def main():
    import itertools

    N, M = list(map(int, input().split()))
    A = list(map(int, input().split()))
    acc = itertools.accumulate(A)
    acc = [e % M for e in acc]
    cnt_dict = {}
    ans = 0
    for e in acc:
        if e == 0:
            ans += 1
        if e in cnt_dict:
            cnt_dict[e] += 1
        else:
            cnt_dict[e] = 0
        ans += cnt_dict[e]
    print(ans)

main()

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

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


Input:
from collections import defaultdict

N = int(eval(input()))

S = eval(input())

S1 = S[:N]

S2 = S[N:][::-1]

ans = 0

D = defaultdict(int)

for i in range(2**N):

    bit = bin(2**N+i)[3:]

    red1 = "".join([d for d, s in zip(S1, bit) if s == "1"])

    blue1 = "".join([d for d, s in zip(S1, bit) if s == "0"])

    D[(red1, blue1)] += 1

for i in range(2**N):

    bit = bin(2 ** N + i)[3:]

    red2 = "".join([d for d, s in zip(S2, bit) if s == "1"])

    blue2 = "".join([d for d, s in zip(S2, bit) if s == "0"])

    ans += D[(blue2, red2)]

print(ans)

from itertools import product

from collections import defaultdict

N = int(eval(input()))

S = eval(input())

ans = 0

D = defaultdict(int)

for pattern in product([0, 1], repeat=N):

    red = ''.join([s for s, p in zip(S[:N], pattern) if p == 0])

    blue = ''.join([s for s, p in zip(S[:N], pattern) if p == 1])

    D[(red, blue)] += 1

for pattern in product([0, 1], repeat=N):

    red = ''.join([s for s, p in zip(S[N:], pattern) if p == 0])

    blue = ''.join([s for s, p in zip(S[N:], pattern) if p == 1])

    ans += D[(blue[::-1], red[::-1])]

print(ans)

from collections import defaultdict

N = int(eval(input()))
S = eval(input())
S1 = S[:N]
S2 = S[N:][::-1]
ans = 0
D = defaultdict(int)
for i in range(2**N):
    bit = bin(2**N + i)[3:]
    red1 = "".join([d for d, s in zip(S1, bit) if s == "1"])
    blue1 = "".join([d for d, s in zip(S1, bit) if s == "0"])
    D[(red1, blue1)] += 1
for i in range(2**N):
    bit = bin(2**N + i)[3:]
    red2 = "".join([d for d, s in zip(S2, bit) if s == "1"])
    blue2 = "".join([d for d, s in zip(S2, bit) if s == "0"])
    ans += D[(blue2, red2)]
print(ans)

from itertools import product
from collections import defaultdict

N = int(eval(input()))
S = eval(input())
ans = 0
D = defaultdict(int)
for pattern in product([0, 1], repeat=N):
    red = "".join([s for s, p in zip(S[:N], pattern) if p == 0])
    blue = "".join([s for s, p in zip(S[:N], pattern) if p == 1])
    D[(red, blue)] += 1
for pattern in product([0, 1], repeat=N):
    red = "".join([s for s, p in zip(S[N:], pattern) if p == 0])
    blue = "".join([s for s, p in zip(S[N:], pattern) if p == 1])
    ans += D[(blue[::-1], red[::-1])]
print(ans)

-    red1 = "".join([d for d, s in zip(S1, bit) if s == "1"])

-    blue1 = "".join([d for d, s in zip(S1, bit) if s == "0"])

-    red2 = "".join([d for d, s in zip(S2, bit) if s == "1"])

-    blue2 = "".join([d for d, s in zip(S2, bit) if s == "0"])

+for pattern in product([0, 1], repeat=N):

+    red = "".join([s for s, p in zip(S[:N], pattern) if p == 0])

+    blue = "".join([s for s, p in zip(S[:N], pattern) if p == 1])

+    red = "".join([s for s, p in zip(S[N:], pattern) if p == 0])

+    blue = "".join([s for s, p in zip(S[N:], pattern) if p == 1])


Input:
from collections import defaultdict

H,W = list(map(int, input().split()))

S = [eval(input()) for _ in range(H)]

es = defaultdict(list)

for i in range(H):

    for j in range(W):

        if 0 <= i < H-1:

            if S[i][j] != S[i+1][j]:

                es[(i,j)].append((i+1, j))

                es[(i+1,j)].append((i, j))

        if 0 <= j < W-1:

            if S[i][j] != S[i][j+1]:

                es[(i,j)].append((i, j+1))

                es[(i,j+1)].append((i, j))

checked = [[False for _ in range(W)] for _ in range(H)]

ans = 0

for i in range(H):

    for j in range(W):

        b,w = 0,0

        if not checked[i][j]:

            checked[i][j] = True

            if S[i][j] == "#":

                b += 1

            else:

                w += 1

            q = es[(i,j)]

            while q:

                y,x = q.pop()

                if not checked[y][x]:

                    checked[y][x] = True

                    if S[y][x] == "#":

                        b += 1

                    else:

                        w += 1

                    q.extend(es[(y,x)])

            ans += b * w

print(ans)

from collections import defaultdict

class UnionFind:

    def __init__(self,N):

        self.parent = [i for i in range(N)]

        self.rank = [0] * N

        self.count = 0

    def root(self,a):

        if self.parent[a] == a:

            return a

        else:

            self.parent[a] = self.root(self.parent[a])

            return self.parent[a]

    def is_same(self,a,b):

        return self.root(a) == self.root(b)

    def unite(self,a,b):

        ra = self.root(a)

        rb = self.root(b)

        if ra == rb: return

        if self.rank[ra] < self.rank[rb]:

            self.parent[ra] = rb

        else:

            self.parent[rb] = ra

            if self.rank[ra] == self.rank[rb]: self.rank[ra] += 1

        self.count += 1

H,W = list(map(int, input().split()))

S = [eval(input()) for _ in range(H)]

uf = UnionFind(H*W)

for i in range(H):

    for j in range(W):

        if 0 <= i < H-1:

            if S[i][j] != S[i+1][j]:

                uf.unite(W*i+j, W*(i+1)+j)

        if 0 <= j < W-1:

            if S[i][j] != S[i][j+1]:

                uf.unite(W*i+j, W*i+j+1)

black = defaultdict(int)

white = defaultdict(int)

unions = set(uf.parent)

for i in range(H):

    for j in range(W):

        if S[i][j] == "#":

            black[uf.root(W*i+j)] += 1

        else:

            white[uf.root(W*i+j)] += 1

ans = 0

for u in unions:

    ans += black[u] * white[u]

print(ans)

from collections import defaultdict

H, W = list(map(int, input().split()))
S = [eval(input()) for _ in range(H)]
es = defaultdict(list)
for i in range(H):
    for j in range(W):
        if 0 <= i < H - 1:
            if S[i][j] != S[i + 1][j]:
                es[(i, j)].append((i + 1, j))
                es[(i + 1, j)].append((i, j))
        if 0 <= j < W - 1:
            if S[i][j] != S[i][j + 1]:
                es[(i, j)].append((i, j + 1))
                es[(i, j + 1)].append((i, j))
checked = [[False for _ in range(W)] for _ in range(H)]
ans = 0
for i in range(H):
    for j in range(W):
        b, w = 0, 0
        if not checked[i][j]:
            checked[i][j] = True
            if S[i][j] == "#":
                b += 1
            else:
                w += 1
            q = es[(i, j)]
            while q:
                y, x = q.pop()
                if not checked[y][x]:
                    checked[y][x] = True
                    if S[y][x] == "#":
                        b += 1
                    else:
                        w += 1
                    q.extend(es[(y, x)])
            ans += b * w
print(ans)

from collections import defaultdict

class UnionFind:
    def __init__(self, N):
        self.parent = [i for i in range(N)]
        self.rank = [0] * N
        self.count = 0

    def root(self, a):
        if self.parent[a] == a:
            return a
        else:
            self.parent[a] = self.root(self.parent[a])
            return self.parent[a]

    def is_same(self, a, b):
        return self.root(a) == self.root(b)

    def unite(self, a, b):
        ra = self.root(a)
        rb = self.root(b)
        if ra == rb:
            return
        if self.rank[ra] < self.rank[rb]:
            self.parent[ra] = rb
        else:
            self.parent[rb] = ra
            if self.rank[ra] == self.rank[rb]:
                self.rank[ra] += 1
        self.count += 1

H, W = list(map(int, input().split()))
S = [eval(input()) for _ in range(H)]
uf = UnionFind(H * W)
for i in range(H):
    for j in range(W):
        if 0 <= i < H - 1:
            if S[i][j] != S[i + 1][j]:
                uf.unite(W * i + j, W * (i + 1) + j)
        if 0 <= j < W - 1:
            if S[i][j] != S[i][j + 1]:
                uf.unite(W * i + j, W * i + j + 1)
black = defaultdict(int)
white = defaultdict(int)
unions = set(uf.parent)
for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            black[uf.root(W * i + j)] += 1
        else:
            white[uf.root(W * i + j)] += 1
ans = 0
for u in unions:
    ans += black[u] * white[u]
print(ans)

+        self.parent = [i for i in range(N)]

+            self.parent[a] = self.root(self.parent[a])

+        return self.root(a) == self.root(b)

+        if self.rank[ra] < self.rank[rb]:

+            if self.rank[ra] == self.rank[rb]:

+                uf.unite(W * i + j, W * (i + 1) + j)

-checked = [[False for _ in range(W)] for _ in range(H)]

+                uf.unite(W * i + j, W * i + j + 1)

-                    checked[y][x] = True

-                    q.extend(es[(y, x)])

+            black[uf.root(W * i + j)] += 1

+            white[uf.root(W * i + j)] += 1


Input:
n, m = list(map(int, input().split()))

lrl = list(list(map(int, input().split())) for _ in range(m))

lmax = 0

rmin = n

for lr in lrl:

    if lr[0] > lmax:

        lmax = lr[0]

    if lr[1] < rmin:

        rmin = lr[1]

if lmax <= rmin:

    print((rmin-lmax+1))

else:

    print((0))

import numpy as np

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

ans = [0]*n

for _ in range(m):

    l, r = list(map(int, input().split()))

    ans[l-1] += 1

    if r < n:

        ans[r] -= 1

c = list(np.cumsum(ans))

print((c.count(m)))

n, m = list(map(int, input().split()))
lrl = list(list(map(int, input().split())) for _ in range(m))
lmax = 0
rmin = n
for lr in lrl:
    if lr[0] > lmax:
        lmax = lr[0]
    if lr[1] < rmin:
        rmin = lr[1]
if lmax <= rmin:
    print((rmin - lmax + 1))
else:
    print((0))

import numpy as np

n, m = list(map(int, input().split()))
ans = [0] * n
for _ in range(m):
    l, r = list(map(int, input().split()))
    ans[l - 1] += 1
    if r < n:
        ans[r] -= 1
c = list(np.cumsum(ans))
print((c.count(m)))

-lrl = list(list(map(int, input().split())) for _ in range(m))

+    l, r = list(map(int, input().split()))


Input:
def paku(N, A, mid):

    if mid == 0:

        return False

    size = sum(A[:mid])

    for i in range(mid, N):

        if A[i] <= 2*size:

            size += A[i]

        else:

            return False

    return True

N = int(eval(input()))

A = [int(i) for i in input().split()]

A.sort()

top = N

btm = 0

while top - btm > 1:

    mid = (top + btm) // 2

    if paku(N, A, mid):

        top = mid

    else:

        btm = mid

ans = N - top + 1

print(ans)

N = int(eval(input()))

A = [int(i) for i in input().split()]

A.sort()

l = 0

size = 0

for i in range(N - 1):

    size += A[i]

    if A[i + 1] > 2 * size:

        l = i + 1

ans = N - l

print(ans)

def paku(N, A, mid):
    if mid == 0:
        return False
    size = sum(A[:mid])
    for i in range(mid, N):
        if A[i] <= 2 * size:
            size += A[i]
        else:
            return False
    return True

N = int(eval(input()))
A = [int(i) for i in input().split()]
A.sort()
top = N
btm = 0
while top - btm > 1:
    mid = (top + btm) // 2
    if paku(N, A, mid):
        top = mid
    else:
        btm = mid
ans = N - top + 1
print(ans)

-def paku(N, A, mid):
-    if mid == 0:
-        return False
-    size = sum(A[:mid])
-    for i in range(mid, N):
-        if A[i] <= 2 * size:
-            size += A[i]
-        else:
-            return False
-    return True
-top = N
-btm = 0
-while top - btm > 1:
-    mid = (top + btm) // 2
-    if paku(N, A, mid):
-        top = mid
-    else:
-        btm = mid
-ans = N - top + 1
+l = 0
+size = 0
+for i in range(N - 1):
+    size += A[i]
+    if A[i + 1] > 2 * size:
+        l = i + 1
+ans = N - l


Input:
n = int(input())

L = [None]+list(input().split())

even = []

odd = []

if n % 2 == 0:

    for i in range(1,1+n):

        if i % 2 == 0:

            even.append(L[i])

        else:

            odd.append(L[i])

    ans = even[::-1] + odd

else:

    for i in range(1,1+n):

        if i % 2 == 0:

            even.append(L[i])

        else:

            odd.append(L[i])

    ans = odd[::-1] + even

for i in range(n):

    if i == n - 1:

        print(ans[i])

    else:

        print(ans[i],end=' ')

n = int(input())

L = [None]+list(input().split())

even = []

odd = []

if n % 2 == 0:

    for i in range(1,1+n):

        if i % 2 == 0:

            even.append(L[i])

        else:

            odd.append(L[i])

    ans = even[::-1] + odd

else:

    for i in range(1,1+n):

        if i % 2 == 0:

            even.append(L[i])

        else:

            odd.append(L[i])

    ans = odd[::-1] + even

for i in range(n-1):

    print(ans[i],end=' ')

print(ans[n-1])

n = int(input())
L = [None] + list(input().split())
even = []
odd = []
if n % 2 == 0:
    for i in range(1, 1 + n):
        if i % 2 == 0:
            even.append(L[i])
        else:
            odd.append(L[i])
    ans = even[::-1] + odd
else:
    for i in range(1, 1 + n):
        if i % 2 == 0:
            even.append(L[i])
        else:
            odd.append(L[i])
    ans = odd[::-1] + even
for i in range(n):
    if i == n - 1:
        print(ans[i])
    else:
        print(ans[i], end=" ")

n = int(input())
L = [None] + list(input().split())
even = []
odd = []
if n % 2 == 0:
    for i in range(1, 1 + n):
        if i % 2 == 0:
            even.append(L[i])
        else:
            odd.append(L[i])
    ans = even[::-1] + odd
else:
    for i in range(1, 1 + n):
        if i % 2 == 0:
            even.append(L[i])
        else:
            odd.append(L[i])
    ans = odd[::-1] + even
for i in range(n - 1):
    print(ans[i], end=" ")
print(ans[n - 1])

-for i in range(n):
-    if i == n - 1:
-        print(ans[i])
-    else:
-        print(ans[i], end=" ")
+for i in range(n - 1):
+    print(ans[i], end=" ")
+print(ans[n - 1])


Input:
#https://atcoder.jp/contests/dp/tasks/dp_e

#2019-01-13

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

w, v = [], []

for i in range(N):

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

    w += [a]

    v += [b]

DP = [float("inf")] * (N*1000+1)

DP[0] = 0

#総価値 i 円を得るために最低限必要な重量

for i in range(N):

    for j in range(N*1000,-1,-1):

        DP[j] = min(DP[j- v[i]] + w[i], DP[j])

ans = 0

for k in range(N*1000+1):

    if DP[k] <= W:

        ans = k

print(ans)

#https://atcoder.jp/contests/dp/tasks/dp_e

#2019-01-13

import numpy as np

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

w, v = [], []

for i in range(N):

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

    w += [a]

    v += [b]

DP = np.ones(N*1000+1, dtype=int) *(W+1)

DP[0] = 0

#総価値 i 円を得るために最低限必要な重量

for i in range(N):

    DP[v[i]:] = np.minimum(DP[:-v[i]]+ w[i], DP[v[i]:])

ans = 0

for k in range(N*1000+1):

    if DP[k] <= W:

        ans = k

print(ans)

# https://atcoder.jp/contests/dp/tasks/dp_e
# 2019-01-13
N, W = list(map(int, input().split()))
w, v = [], []
for i in range(N):
    a, b = list(map(int, input().split()))
    w += [a]
    v += [b]
DP = [float("inf")] * (N * 1000 + 1)
DP[0] = 0
# 総価値 i 円を得るために最低限必要な重量
for i in range(N):
    for j in range(N * 1000, -1, -1):
        DP[j] = min(DP[j - v[i]] + w[i], DP[j])
ans = 0
for k in range(N * 1000 + 1):
    if DP[k] <= W:
        ans = k
print(ans)

# https://atcoder.jp/contests/dp/tasks/dp_e
# 2019-01-13
import numpy as np

N, W = list(map(int, input().split()))
w, v = [], []
for i in range(N):
    a, b = list(map(int, input().split()))
    w += [a]
    v += [b]
DP = np.ones(N * 1000 + 1, dtype=int) * (W + 1)
DP[0] = 0
# 総価値 i 円を得るために最低限必要な重量
for i in range(N):
    DP[v[i] :] = np.minimum(DP[: -v[i]] + w[i], DP[v[i] :])
ans = 0
for k in range(N * 1000 + 1):
    if DP[k] <= W:
        ans = k
print(ans)


Input:
k,n = list(map(int, input().split()))

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

a = a + [a[0]+k]

dif = [0]*n

for i in range(n):

    dif[i] += a[i+1] - a[i]

dif.sort()

print((k-dif[-1]))

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

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

a = a + [a[0]+k]

dif = [0]*n

for i in range(n):

    dif[i] += a[i+1] - a[i]

print((k-max(dif)))

k, n = list(map(int, input().split()))
a = list(map(int, input().split()))
a = a + [a[0] + k]
dif = [0] * n
for i in range(n):
    dif[i] += a[i + 1] - a[i]
dif.sort()
print((k - dif[-1]))

k, n = list(map(int, input().split()))
a = list(map(int, input().split()))
a = a + [a[0] + k]
dif = [0] * n
for i in range(n):
    dif[i] += a[i + 1] - a[i]
print((k - max(dif)))

-dif.sort()
-print((k - dif[-1]))
+print((k - max(dif)))


Input:
#S = str(input())

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

if A <= K:

    a = A

else:

    a = K

if B <= K-a:

    b = B

else:

    b = K-a

c = K - a - b

ans = a - c

print(ans)

a, b, c, k = list(map(int, input().split()))

xa = min(k,a)

xb = min(k-xa,b)

xc = k- xa - xb

print((xa - xc))

# S = str(input())
A, B, C, K = list(map(int, input().split()))
if A <= K:
    a = A
else:
    a = K
if B <= K - a:
    b = B
else:
    b = K - a
c = K - a - b
ans = a - c
print(ans)

a, b, c, k = list(map(int, input().split()))
xa = min(k, a)
xb = min(k - xa, b)
xc = k - xa - xb
print((xa - xc))

-A, B, C, K = list(map(int, input().split()))

+a, b, c, k = list(map(int, input().split()))


Input:
ans = []

n = int(eval(input()))

while n > 0:

    i = n % 26

    if i == 0:

        i += 26

    ans.append(chr(i + 96))

    if n % 26 == 0:

        n = n // 26 - 1

    else:

        n //= 26

ans.reverse()

print(("".join(ans)))

n = int(eval(input()))

keta = 1

end = 0

while True:

    order = n - end

    end += 26**keta

    if n <= end:

        break

    keta += 1

order -= 1

ans = []

for i in range(keta):

    ans.append(chr(order%26 + 97))

    order //= 26

ans.reverse()

print(("".join(ans)))

n = int(eval(input()))
keta = 1
end = 0
while True:
    order = n - end
    end += 26**keta
    if n <= end:
        break
    keta += 1
order -= 1
ans = []
for i in range(keta):
    ans.append(chr(order % 26 + 97))
    order //= 26
ans.reverse()
print(("".join(ans)))

+n = int(eval(input()))
+keta = 1
+end = 0
+while True:
+    order = n - end
+    end += 26**keta
+    if n <= end:
+        break
+    keta += 1
+order -= 1
-n = int(eval(input()))
-while n > 0:
-    i = n % 26
-    if i == 0:
-        i += 26
-    ans.append(chr(i + 96))
-    if n % 26 == 0:
-        n = n // 26 - 1
-    else:
-        n //= 26
+for i in range(keta):
+    ans.append(chr(order % 26 + 97))
+    order //= 26


Input:
a=input().split()

a.sort()

cnt=0

while len(a)>0:

    i=a.count(a.pop(0))

    for j in range(i):

        a.pop(0)

    cnt+=1

print(cnt)

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

if a==b and b==c:

    print((1))

elif a==b and a!=c:

    print((2))

elif a!=b and b==c:

    print((2))

elif a==c and a!=b:

    print((2))

else:

    print((3))

a = input().split()
a.sort()
cnt = 0
while len(a) > 0:
    i = a.count(a.pop(0))
    for j in range(i):
        a.pop(0)
    cnt += 1
print(cnt)

a, b, c = list(map(int, input().split()))
if a == b and b == c:
    print((1))
elif a == b and a != c:
    print((2))
elif a != b and b == c:
    print((2))
elif a == c and a != b:
    print((2))
else:
    print((3))

+a, b, c = list(map(int, input().split()))


Input:
import heapq

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

print((sum(heapq.nlargest(2, [a, a-1, b, b-1]))))

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

print((max([a+b, 2*a-1, 2*b-1])))

import heapq

a, b = list(map(int, input().split()))
print((sum(heapq.nlargest(2, [a, a - 1, b, b - 1]))))

a, b = list(map(int, input().split()))
print((max([a + b, 2 * a - 1, 2 * b - 1])))

-print((sum(heapq.nlargest(2, [a, a - 1, b, b - 1]))))