CodeEff/ECCO huggingface dataset:
# Original solution
S = input().strip()

answer = 0

for n in range(2**(len(S)-1)):
    A = [0]
    for d in range(9):
        if n & (1 << d):
            A.append(d+1)
    T = []
    #print("A", A)
    for l, r in zip(A, A[1:]):
        T.append(int("".join(S[l:r])))
    T.append(int("".join(S[A[-1]:])))
    answer += sum(T)

print(answer)


# Optimized solution
from itertools import combinations
S = input().strip()
N = len(S)
answer = int(S)
for c in range(1,N):
    for t in combinations(list(range(1,N)), c):
        i = 0
        for j in t:
            answer += int(S[i:j])
            i = j
        j = N
        answer += int(S[i:j])

print(answer)
# Original solution
from itertools import combinations, chain
from functools import reduce

def eval_str(string):
    s = string.split("+")
    return int(reduce(lambda x,y: int(x)+int(y), s))

mystr = input()
allsubsets = lambda n: list(chain(*[combinations(list(range(1,n)), ni) for ni in range(n+1)]))
l = allsubsets(len(mystr))
#for i in xrange(len(l)):
#    l[i] = list(l[i])
mylist = []
#print l
for x in l:
    s = ""
    prev = 0
    for y in x:
        s += mystr[prev:int(y)]
        s += "+"
        prev = int(y)
    s += mystr[prev:]
    mylist.append(s)
#print mylist
tot = 0
for x in mylist:
    tot += eval_str(x)
print(tot)

# Optimized solution
def eval(d,mask):
    s = ''
    for i in range(len(mask)):
        s += d[i]
        if mask[i] == '1':
            s += '+'
    s += d[-1]
    l = s.split('+')
    res = sum(map(int,l))
    return res

d = list(input())
tot = 0
for i in range(2**(len(d)-1)):
    mask = bin(2**(len(d)-1)+i)[3:]
    tot += eval(d,mask)
print(tot)
# Original solution
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():

    S = str(eval(input()))
    ls=len(S)


    # bit全探索
    # https://qiita.com/gogotealove/items/11f9e83218926211083a#%E4%BE%8B%E9%A1%8C-1
    n = ls-1
    # 昇順での探索だよ
    val = 0
    for i in range(2 ** n):
        split=[]
        for j in range(n):  # このループが一番のポイント
            if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
                split.append(j)
        temp=0
        for k in range(len(split)):
            val+=int(S[temp:split[k]+1])
            temp=split[k]+1
            if k==len(split)-1:
                val+=int(S[split[k]+1:])
    print((val+int(S)))


resolve()

# Optimized solution
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    def main():
        S=str(eval(input()))

        # bit全探索
        # https://qiita.com/gogotealove/items/11f9e83218926211083a#%E4%BE%8B%E9%A1%8C-1
        n = len(S)-1
        if n==0:
            return int(S)
        else:
            # 昇順での探索だよ
            ans=0
            for i in range(2 ** n):
                temp = n+1
                for j in range(n):  # このループが一番のポイント
                    if ((i >> j) & 1):
                        ans+=int(S[-j-1:temp])
                        temp=-j-1
                    if j==n-1:
                        ans+=int(S[:temp])# 順
            return ans# に右にシフトさせ最下位bitのチェックを行う
    print((main()))


resolve()
# Original solution
while 1:
 n=int(eval(input()))
 if n==0:break
 a=1;s='123456'
 for _ in[0]*n:
  s=[s[int(e)]for e in{'N':"152304",'E':"310542",'W':"215043",'S':"402351",'R':"024135",'L':"031425"}[input()[0]]]
  a+=int(s[0])
 print(a)


# Optimized solution
import sys
d=sys.stdin
while 1:
 n=int(d.readline())
 if n==0:break
 a=1;s='123456'
 for _ in[0]*n:
  s=[s[int(e)]for e in{'N':"152304",'E':"310542",'W':"215043",'S':"402351",'R':"024135",'L':"031425"}[d.readline()[0]]]
  a+=int(s[0])
 print(a)
# Original solution
import sys
d=sys.stdin.readline
p={'N':(1,5,2,3,0,4),'E':(3,1,0,5,4,2),'W':(2,1,5,0,4,3),
   'S':(4,0,2,3,5,1),'R':(0,2,4,1,3,5),'L':(0,3,1,4,2,5)}
while 1:
 n=int(d())
 if n==0:break
 a=1;s='123456'
 for _ in[0]*n:
  s=[s[e]for e in p[d()[0]]]
  a+=int(s[0])
 print(a)


# Optimized solution
import sys
d=sys.stdin.readline
p={'N':(1,5,2,3,0,4),'E':(3,1,0,5,4,2),'W':(2,1,5,0,4,3),
   'S':(4,0,2,3,5,1),'R':(0,2,4,1,3,5),'L':(0,3,1,4,2,5)}
while 1:
 n=int(d())
 if n==0:break
 a=[1];s='123456'
 for _ in[0]*n:
  s=[s[e]for e in p[d()[0]]]
  a+=[s[0]]
 print((sum(map(int,a))))
# Original solution
rot = {
    "North": (1,5,2,3,0,4),
    "East" : (3,1,0,5,4,2),
    "West" : (2,1,5,0,4,3),
    "South": (4,0,2,3,5,1),
    "Right": (0,2,4,1,3,5),
    "Left" : (0,3,1,4,2,5)
}
while 1:
    n = eval(input())
    if not n:
        break
    dice = [1,2,3,4,5,6]
    nxt = [0]*6
    ans = 0
    for i in range(n):
        r = rot[input()]
        for i in range(6):
            nxt[i] = dice[r[i]]
        dice, nxt = nxt, dice
        ans += dice[0]
    print(ans+1)

# Optimized solution
rot = {
    "North": (1,5,2,3,0,4),
    "East" : (3,1,0,5,4,2),
    "West" : (2,1,5,0,4,3),
    "South": (4,0,2,3,5,1),
    "Right": (0,2,4,1,3,5),
    "Left" : (0,3,1,4,2,5)
}
while 1:
    n = eval(input())
    if not n:
        break
    dice = [1,2,3,4,5,6]
    nxt = [0]*6
    ans = 0
    for i in range(n):
        r = rot[input()]
        dice = [dice[r[i]] for i in range(6)]
        ans += dice[0]
    print(ans+1)
# Original solution
import sys,time

n = 104730
a = [True] * n
a[0] = a[1] = False
for i in range(2,n):
	if(a[i]):
		for j in range(i+i, n, i):
			a[j] = False
a = [i[0] for i in enumerate(a) if i[1]]

for s in sys.stdin:
	n = int(s)
	if n == 0:
		exit()
	print((sum(a[:n])))

# Optimized solution
import sys

n = 104730
a = [True] * n
a[0] = a[1] = False
for i in range(2,n):
	if(a[i]):
		for j in range(i+i, n, i):
			a[j] = False
a = [i[0] for i in enumerate(a) if i[1]]

for s in sys.stdin:
	n = int(s)
	if n == 0:
		exit()
	print((sum(a[:n])))
# Original solution
s = [0]
M = 10**6
p = [1]*M
S = 0
for i in range(2,M):
    if p[i]:
        for j in range(i*i,M,i):
            p[j] = 0
        S += i; s.append(S)
while 1:
    n = eval(input())
    if n==0: break
    print(s[n])

# Optimized solution
s = [0]
M = 104850
p = [1]*M
S = 0
for i in range(2,M):
    if p[i]:
        for j in range(i*i,M,i):
            p[j] = 0
        S += i; s.append(S)
while 1:
    n = eval(input())
    if n==0: break
    print(s[n])
# Original solution
# -*- coding: utf-8 -*-

import sys
import os

def is_prime(n):
    if n==2 or n==3: return True
    if n%2==0 or n<2: return False
    for i in range(3,int(n**0.5)+1,2):   # only odd numbers
        if n%i==0:
            return False
    return True

def make_primes():
    primes = [2]
    i = 3
    while True:
        if is_prime(i):
            primes.append(i)
            if len(primes) > 105000:
                break
        i += 2
    return primes

primes = make_primes()
for s in sys.stdin:
    n = int(s)
    if n == 0:
        break

    subset = primes[:n]
    print((sum(subset)))

# Optimized solution
# -*- coding: utf-8 -*-

import sys
import os

def is_prime_list():
    N = 105000
    lst = [True] * N
    lst[0] = False
    lst[1] = False
    for i in range(2, int(N ** 0.5) + 1):
        if lst[i] == True:
            for j in range(2, N):
                index = i * j
                if index < N:
                    lst[i * j] = False
    return [i for i in range(2, N) if lst[i]]


primes = is_prime_list()
for s in sys.stdin:
    n = int(s)
    if n == 0:
        break

    subset = primes[:n]
    print((sum(subset)))
# Original solution
def isPrime(x):
    if x == 2:
        return True
    if x < 2 or x % 2 == 0:
        return False
    i, root_x = 3, int(pow(x, 0.5))
    while i <= root_x:
        if x % i == 0:
            return False
        i += 2
    return True

primes = [2]
for i in range(3, 104730):
    if isPrime(i):
        primes.append(primes[-1]+i)
while True:
    n = int(eval(input()))
    if n == 0:
        break
    print((primes[n-1]))

# Optimized solution
primes = [0, 0] + [1] * 150000
for i in range(2, 388):
    if primes[i]:
        for j in range(i*i, 150001, i):
            primes[j] = 0

values = [i for i, v in enumerate(primes) if v]
while True:
    n = int(eval(input()))
    if n == 0:
        break
    print((sum(values[:n])))
# Original solution
import math

r = 200000
sqrt = int(math.sqrt(r))
p = [1]*r
p[0] = 0
for i in range(1,sqrt):
    if p[i]:
        for j in range(2*i+1,r,i+1):
            p[j] = 0

while True:
    n = int(input())
    if not n:
        break
    i, num, sum = 0, 0, 0
    while num < n:
        if p[i] == 1:
            num += 1
            sum += i+1
        i += 1
    print(sum)

# Optimized solution
import math

r = 105000
sqrt = int(math.sqrt(r))
p = [1]*r
p[0] = 0
for i in range(1,sqrt):
    if p[i]:
        for j in range(2*i+1,r,i+1):
            p[j] = 0

while True:
    n = int(input())
    if not n:
        break
    i, num, sum = 0, 0, 0
    while num < n:
        if p[i] == 1:
            num += 1
            sum += i+1
        i += 1
    print(sum)
# Original solution
import math

r = 105000
sqrt = int(math.sqrt(r))
p = [1]*r
p[0] = 0
for i in range(1,sqrt):
    if p[i]:
        for j in range(2*i+1,r,i+1):
            p[j] = 0

s = [0 for i in range(11000)]
s[0] = 2
k = 1
for i in range(2,r):
    if p[i]:
        s[k] = i+1+s[k-1]
        k += 1
        
while True:
    n = int(input())
    if not n:
        break
    print(s[n-1])

# Optimized solution
import math

r = 105000
sqrt = int(math.sqrt(r))
p = [1]*r
p[0] = 0
for i in range(1,sqrt):
    if p[i]:
        p[2*i+1::i+1] = [0 for x in range(2*i+1,r,i+1)]

s = [0 for i in range(11000)]
s[0] = 2
k = 1
for i in range(2,r):
    if p[i]:
        s[k] = i+1+s[k-1]
        k += 1
        
while True:
    n = int(input())
    if not n:
        break
    print(s[n-1])
# Original solution
prim=[True]*1000000
prim[0],prim[1]=False,False
for i in range(2,1000):
    if prim[i]:
        for j in range(i*2,1000000,i):
            prim[j]=False
prime=[i for i,j in enumerate(prim) if j==True]

while True:
    n=int(eval(input()))
    if n==0:
        break
    print((sum(prime[:n])))

# Optimized solution
prim=[True]*1000000
prim[0]=prim[1]=False
for i in range(2,350):
    if prim[i]:
        for j in range(i*2,110000,i):
            prim[j]=False
prime=[i for i,j in enumerate(prim) if j==True]

while True:
    n=int(eval(input()))
    if n==0:
        break
    print((sum(prime[:n])))
# Original solution
import math
def pri(n):
    if n < 2:
        return False
    elif n == 2:
        return True
    elif n % 2 == 0:
        return False

    i = 3
    while i <= math.sqrt(n):
        if n % i == 0:
            return False
        i += 2
    return True

l=[i for i in range(110000)if pri(i) ]

while True:
    n = int(eval(input()))
    if n == 0: break
    print((sum(l[:n])))

# Optimized solution
import math
def pri(n):
    l =[True] * n
    l[0] = l[1] = False
    for i in range(2,n):
        if l[i]:
            for j in range(i*2, n, i):
                l[j] = False
    return l
n=105000
s=pri(n)
l=[i for i in range(n) if s[i]]
while True:
    n = int(eval(input()))
    if n == 0: break
    print((sum(l[:n])))
# Original solution
from math import sqrt

while True :
    sample = int(eval(input()))
    if sample == 0 : break
    Sum, count, number = 2, 1, 1
    while True :
        if count == sample : break
        if 2 < number :
            temp, switch = 3, 0
            while temp <= sqrt(number) :
                if number % temp == 0 : 
                    switch = 1
                    break
                temp += 2
            if switch != 1 : 
                Sum, count = Sum+number, count+1
        number += 2
    print(Sum)

# Optimized solution
prime = [2, 3]
while True :
    Sum = 0
    sample = int(eval(input()))
    if sample == 0 : break
    elif sample <= len(prime) :
        Sum = sum(prime[:sample])
    else :
        Sum, temp, count = sum(prime), prime[-1], len(prime)
        while True :
            if sample == count : break
            temp += 2
            swith = 0
            for _ in prime :
                if temp % _ == 0 :
                    swith = 1
                    break
            if swith == 0 : 
                Sum += temp
                count += 1
                prime.append(_)
    print(Sum)
# Original solution
import re

s = re.split("[ .,]", input())
sl = len(s)
ans = list()

for i in range(sl) :
  if(2 < len(s[i]) and len(s[i]) < 7) :
    ans.append(s[i])
  else :
    pass

ansl = len(ans)

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


# Optimized solution
import re

I = input().split()
S = []

for i in range(len(I)) :
    I[i] = re.split("[,.]", I[i])
    if 2 < len(I[i][0]) and len(I[i][0]) < 7 :
        S.append(I[i][0])

for i in range(len(S)) :
    if i == len(S) - 1 :
        print(S[i])
    else :
        print(S[i], " ", sep = "", end = "")
# Original solution
s=" "
x=input().replace(",",s).replace(".",s).split()
print(s.join([w for w in x if 2<len(w)<7]))

# Optimized solution
s=" "
x=input().replace(",",s).replace(".",s).split()
x=s.join([w for w in x if 2<len(w)<7])
print(x)
# Original solution
n,m,*T=list(map(int,open(0).read().split()));*S,=list(zip(T[::2],T[1::2]));s=lambda e:set(sum([s for s in S if e in s],()));print(("IM"*(len(s(1)&s(n))<1)+"POSSIBLE"))

# Optimized solution
n,m,*T=list(map(int,open(0).read().split()));*S,=list(zip(T[::2],T[1::2]));s=lambda e:set(s[e<2]for s in S if e in s);print(("IM"*(len(s(1)&s(n))<1)+"POSSIBLE"))
# Original solution
N, M = list(map(int,input().split()))
G = [[] for _ in range(N)]
for _ in range(M):
    a, b = list(map(int,input().split()))
    a -= 1
    b -= 1
    G[a].append(b)

E = []
for v in G[0]:
    if v in E:
        continue
    E.append(v)
    for v2 in G[v]:
        if v2 in E:
            continue
        E.append(v2)

if (N-1) in E:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

# Optimized solution
N, M = list(map(int,input().split()))
S = [False for _ in range(N)]
G = [False for _ in range(N)]
for _ in range(M):
    a, b = list(map(int,input().split()))
    a -= 1
    b -= 1
    if a == 0 and b == N - 1:
        print("POSSIBLE")
        exit()
    if a == 0:
        if G[b]:
            print("POSSIBLE")
            exit()
        S[b] = True
    if b == N - 1:
        if S[a]:
            print("POSSIBLE")
            exit()
        G[a] = True

print("IMPOSSIBLE")
# Original solution
from collections import defaultdict, deque

INF = 10**12
N, M = list(map(int, input().split()))
E = defaultdict(list)
for _ in range(M):
    a, b = list(map(int, input().split()))
    E[a-1].append(b-1)
    E[b-1].append(a-1)
dist = [INF]*N
q = deque([(0, 0)])
while q:
    v, d = q.popleft()
    dist[v] = d
    for u in E[v]:
        if dist[u] == INF:
            q.append((u, d+1))
print(('POSSIBLE' if dist[N-1] == 2 else 'IMPOSSIBLE'))

# Optimized solution
N, M = list(map(int, input().split()))
from_1 = [False]*N
to_N = [False]*N
for _ in range(M):
    a, b = list(map(int, input().split()))
    if a == 1:
        from_1[b-1] = True
    elif b == N:
        to_N[a-1] = True
for i in range(1, N):
    if from_1[i] and to_N[i]:
        print('POSSIBLE')
        break
else:
    print('IMPOSSIBLE')
# Original solution
N, M = list(map(int,input().split()))
edges = [[] for _ in range(N)]

for i in range(M):
	a, b = list(map(int,input().split()))
	edges[a-1] += [b-1]
	edges[b-1] += [a-1]

res = False
for u in edges[0]:
	if u in edges[N-1]:
		res = True
		break

print(("POSSIBLE" if res == True else "IMPOSSIBLE"))

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

from1 = []
gotoN = []

for i in range(M):
	a, b = list(map(int,input().split()))
	if a == 1:
		from1.append(b)
	if b == N:
		gotoN.append(a)

res = set(from1) & set(gotoN)

print(("POSSIBLE" if len(res) > 0 else "IMPOSSIBLE"))
# Original solution
from copy import *
from sys import *
from math import *
import queue
from collections import defaultdict,Counter,deque

setrecursionlimit(1000000)

def main():
	n,m = list(map(int,input().split()))
	ab = [list(map(int,input().split())) for _ in range(m)]
	b = {}
	for i in ab:
		try:
			b[i[0]].append(i[1])
		except:
			b[i[0]] = [i[1]]
		try:
			b[i[1]].append(i[0])
		except:
			b[i[1]] = [i[0]]
	ab = deepcopy(b)
	for i in ab[1]:
		if(n in ab[i]):
			print('POSSIBLE')
			exit()
	print('IMPOSSIBLE')

def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(m,n):
	x = max(m,n)
	y = min(m,n)
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	return y

class Queue():
	#競プロ用のQueue
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)

class Stack():
	#怯プロ用のStack
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)

main()


# Optimized solution
from copy import *
from sys import *
from math import *
import queue
from collections import defaultdict,Counter,deque

setrecursionlimit(1000000)

def main():
	n, m = list(map(int,input().split()))
	s=set()
	t=set()
	for _ in range(m):
		a, b = list(map(int, input().split()))
		if a == 1:
			s.add(b)
		elif b == n:
			t.add(a)
	for i in s:
		if(i in t):
			print('POSSIBLE')
			exit()
	print('IMPOSSIBLE')

def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(m,n):
	x = max(m,n)
	y = min(m,n)
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	return y

class Queue():
	#競プロ用のQueue
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)

class Stack():
	#怯プロ用のStack
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)

main()
# Original solution
import sys
n, m = list(map(int, sys.stdin.readline().split()))
set1, setn = set(), set()
for _ in range(m):
  i, j = list(map(int, sys.stdin.readline().split()))
  if i in [1, n] or j in [1, n]:
    if i == 1:
      set1.add(j)
    if i == n:
      setn.add(j)
    if j == 1:
      set1.add(i)
    if j == n:
      setn.add(i)
if set1 & setn:
  print('POSSIBLE')
else:
  print('IMPOSSIBLE')


# Optimized solution
import sys


def main():
  n, m = list(map(int, sys.stdin.readline().split()))
  set1, setn = set(), set()
  for _ in range(m):
    i, j = list(map(int, sys.stdin.readline().split()))
    if i == 1:
      set1.add(j)
    if j == n:
      setn.add(i)
  if set1 & setn:
    print('POSSIBLE')
  else:
    print('IMPOSSIBLE')


if __name__ == '__main__':
  main()
# Original solution
def f():
    n,m = list(map(int,input().split(" ")))
    s = []
    w = [[] for i in range(n+2)]
    for i in range(m):
        a,b = list(map(int,input().split(" ")))
        
        if a==1:
            s.append(b)
        if b==1:
            s.append(a)
        w[a].append(b)
        w[b].append(a)
    for i in range(m+1):
        if i in s and n in w[i]:
            print("POSSIBLE")
            return 0
    print("IMPOSSIBLE")
    return 0
f()

# Optimized solution
def f():
    n,m = list(map(int,input().split(" ")))
    s = []
    w = [[] for i in range(n+2)]
    for i in range(m):
        a,b = list(map(int,input().split(" ")))
        
        if a==1:
            s.append(b)
        if b==1:
            s.append(a)
        w[a].append(b)
        w[b].append(a)
    for i in s:
        if n in w[i]:
            print("POSSIBLE")
            return 0
    print("IMPOSSIBLE")
    return 0
f()
# Original solution
def main():
  N,M = list(map(int,input().split()))
  ships = sorted([list(map(int,input().split())) for i in range(M)])
  
  ans = "IMPOSSIBLE"
  
  con = 0
  
  for i in range(M):
    if ships[i][0] == 1:
      con += 1
  
  for i in range(0,min(M,con + 1)):
    if ships[i][0] == 1:
      ship = ships[i][1]
      for j in range(con,M):
        if ships[j][0] == ship and ships[j][1] == N:
          ans = "POSSIBLE"
          break
      else:
        continue
      break
        
  print(ans)
  
main()

# Optimized solution
def main():
  N,M = list(map(int,input().split()))
  ships = [list(map(int,input().split())) for i in range(M)]
  start, goal = set(), set()
  for i in range(M):
    if ships[i][0] == 1:
      start.add(ships[i][1])
    if ships[i][1] == N:
      goal.add(ships[i][0])
  flg = start & goal
  print(("POSSIBLE" if flg else "IMPOSSIBLE"))
 
main()
# Original solution
n = int(input())
pts = [[int(_) for _ in input().split()] for i in range(n)]


def dot(a, b):
    return a[0] * b[0] + a[1] * b[1]


def cross(a, b):
    return a[0] * b[1] - a[1] * b[0]


def norm(a):
    return dot(a, a)


def dist2(a, b):
    return norm(sub(a, b))


def sub(a, b):
    return [a[0] - b[0], a[1] - b[1]]


# find the first point
p = min(pts, key=lambda p: (p[1], p[0]))
ans = [p]

cur = ans[0]
cur_dxdy = (-1, 0)
while True:
    # Find the next point
    q = pts[0]
    dxdy = sub(q, cur)
    d = dist2(cur, q)
    for q_ in pts[1:]:
        if q_ is cur:
            continue
        dxdy_ = sub(q_, cur)
        v = cross(dxdy, dxdy_)
        if v > 0:
            continue
        d_ = dist2(cur, q_)
        if v == 0 and d_ < d:
            continue
        q = q_
        dxdy = dxdy_
        d = d_

    # Find the points in the middle
    mids = [m for m in pts
            if cross(dxdy, sub(m, cur)) == 0 and dot(sub(m, cur), sub(m, q)) < 0]
    mids.sort(key=lambda m: dist2(cur, m))
    ans += mids

    if p is q:
        break
    ans.append(q)
    cur_dxdy = dxdy
    cur = q

print(len(ans))
for p in ans:
    print(p[0], p[1])

# Optimized solution
n = int(input())
pts = [complex(*[float(_) for _ in input().split()]) for i in range(n)]


def cross(a, b):
    return (a.conjugate() * b).imag


pts.sort(key=lambda p: (p.imag, p.real))

right = []
for p in pts:
    while len(right) >= 2 and cross(right[-1] - right[-2], p - right[-1]) < 0:
        right.pop()
    right.append(p)

left = []
for p in reversed(pts):
    while len(left) >= 2 and cross(left[-1] - left[-2], p - left[-1]) < 0:
        left.pop()
    left.append(p)

ans = right[:-1] + left[:-1]
print(len(ans))
for p in ans:
    print(int(p.real), int(p.imag))