from collections import deque
def readarray(foo): return [foo(x) for x in raw_input().split()]

stairs = []
to = []
color = []
totalcolors = 0
deg = []
priority = []

extrastairs = []
extrastair = None

def doit():
	usedstairs = set()
	visited = set([0])
	stack = []
	res = []
	nextcolor = 1

	s = 0
	if extrastair is not None:
		(s, stair) = extrastair
		visited.add(s)
		usedstairs.add(stair)
		nextcolor += 1
		res.append([0])
		res.append([stair, 0, s])

	hasnextcolor = totalcolors > nextcolor
	layer = [s]
	stack.append([s, -1, -1, 0])

	while stack:
		(u, source, parent, start) = state = stack[-1]

		nexti = None
		nexts = None
		nextv = None
		for i in xrange(start, len(to[u])):
			s = to[u][i]
			if s == source: continue
			if s in usedstairs: continue
			(v1, v2) = stairs[s]
			v = v1 if v2 == u else v2
			if not hasnextcolor and v in visited: continue
			nexti = i
			nexts = s
			nextv = v
			break

		if nexti is None:
			if parent != -1:
				layer.append(parent)
			stack.pop()
			continue

		if nextv not in visited:
			visited.add(nextv)
			layer.append(nextv)
			state[3] = nexti
			stack.append([nextv, nexts, u, 0])
			continue

		usedstairs.add(nexts)
		nextv = priority[nextcolor]
		nextcolor += 1
		hasnextcolor = totalcolors > nextcolor

		res.append(layer)
		res.append([nexts, u, nextv])
		layer = [nextv]
		visited.add(nextv)

		state[3] = nexti + 1
		stack.append([nextv, nexts, u, 0])

	res.append(layer)
	return res if not hasnextcolor else None

def colorize(s, c):
	if color[s] != -1: return
	global totalcolors
	totalcolors += 1
	color[s] = c
	deg[c] = 1
	q = deque()
	q.append(s)
	source = {s : -1}
	while q:
		u = q.popleft()
		for stair in to[u]:
			if extrastair is not None and extrastair[1] == stair: continue
			(v1, v2) = stairs[stair]
			v = v1 if v2 == u else v2
			if color[v] != -1:
				if v != source[u]:
					extrastairs.append(stair)
				continue
			color[v] = c
			source[v] = u
			deg[c] += 1
			q.append(v)

def findextrastair():
	if extrastairs: return (stairs[extrastairs[0]][0], extrastairs[0])
	for u in xrange(len(to)):
		if len(to[u]) < 2: continue
		return (u, to[u][0])
	return None

def run():
	global to, color, deg, priority, extrastair, totalcolors
	n, m = readarray(int)
	to = [[] for i in xrange(n)]
	color = [-1] * n
	deg = [0] * n
	for i in xrange(m):
		u, v = sorted(readarray(lambda x: int(x) - 1))
		stairs.append((u, v))
		to[u].append(i)
		to[v].append(i)
	for i in xrange(n):
		colorize(i, i)

	if deg[0] == 1 and n > 1:
		extrastair = findextrastair()
		if extrastair is None:
			print "NO"
			return
		color = [-1] * n
		deg = [0] * n
		totalcolors = 0
		for i in xrange(n):
			colorize(i, i)
		deg[extrastair[0]] = 100500

	deg[0] = 100500
	priority = sorted(range(n), lambda x, y: deg[y] - deg[x])[:totalcolors]
	res = doit()
	if res is None:
		print "NO"
		return

	print "YES"
	print len(res) / 2
	for i, line in enumerate(res):
		if i % 2 == 0:
			print len(line),
		print " ".join(map(lambda x: str(x + 1), line))

run()


from collections import deque
def readarray(foo): return [foo(x) for x in raw_input().split()]

stairs = []
to = []
color = []
totalcolors = 0
deg = []
priority = []

extrastairs = []
extrastair = None

def doit():
	usedstairs = set()
	visited = set([0])
	stack = []
	res = []
	nextcolor = 1

	s = 0
	if extrastair is not None:
		(s, stair) = extrastair
		visited.add(s)
		usedstairs.add(stair)
		nextcolor += 1
		res.append([0])
		res.append([stair, 0, s])

	hasnextcolor = totalcolors > nextcolor
	layer = [s]
	stack.append([s, -1, -1, 0])

	while stack:
		(u, source, parent, start) = state = stack[-1]

		nexti = None
		nexts = None
		nextv = None
		for i in xrange(start, len(to[u])):
			s = to[u][i]
			if s == source: continue
			if s in usedstairs: continue
			(v1, v2) = stairs[s]
			v = v1 if v2 == u else v2
			if not hasnextcolor and v in visited: continue
			nexti = i
			nexts = s
			nextv = v
			break

		if nexti is None:
			if parent != -1:
				layer.append(parent)
			stack.pop()
			continue

		if nextv not in visited:
			visited.add(nextv)
			layer.append(nextv)
			state[3] = nexti
			stack.append([nextv, nexts, u, 0])
			continue

		usedstairs.add(nexts)
		nextv = priority[nextcolor]
		nextcolor += 1
		hasnextcolor = totalcolors > nextcolor

		res.append(layer)
		res.append([nexts, u, nextv])
		layer = [nextv]
		visited.add(nextv)

		state[3] = nexti + 1
		stack.append([nextv, nexts, u, 0])

	res.append(layer)
	return res if not hasnextcolor else None

def colorize(s, c):
	if color[s] != -1: return
	global totalcolors
	totalcolors += 1
	color[s] = c
	deg[c] = 1
	q = deque()
	q.append(s)
	source = {s : -1}
	while q:
		u = q.popleft()
		for stair in to[u]:
			if extrastair is not None and extrastair[1] == stair: continue
			(v1, v2) = stairs[stair]
			v = v1 if v2 == u else v2
			if color[v] != -1:
				if v != source[u]:
					extrastairs.append(stair)
				continue
			color[v] = c
			source[v] = u
			deg[c] += 1
			q.append(v)

def findextrastair():
	if extrastairs: return (stairs[extrastairs[0]][0], extrastairs[0])
	for u in xrange(len(to)):
		if len(to[u]) < 2: continue
		return (u, to[u][0])
	return None

def run():
	global to, color, deg, priority, extrastair, totalcolors
	n, m = readarray(int)
	to = [[] for i in xrange(n)]
	color = [-1] * n
	deg = [0] * n
	for i in xrange(m):
		u, v = sorted(readarray(lambda x: int(x) - 1))
		stairs.append((u, v))
		to[u].append(i)
		to[v].append(i)
	for i in xrange(n):
		colorize(i, i)

	if deg[0] == 1 and n > 1:
		extrastair = findextrastair()
		if extrastair is None:
			print "NO"
			return
		color = [-1] * n
		deg = [0] * n
		totalcolors = 0
		for i in xrange(n):
			colorize(i, i)
		deg[color[extrastair[0]]] = 100500

	deg[0] = 100500
	priority = sorted(range(n), lambda x, y: deg[y] - deg[x])[:totalcolors]
	res = doit()
	if res is None:
		print "NO"
		return

	print "YES"
	print len(res) / 2
	for i, line in enumerate(res):
		if i % 2 == 0:
			print len(line),
		print " ".join(map(lambda x: str(x + 1), line))

run()


def fact(n) :
	if n <= 1 :
		return 1
		return n * fact(n - 1)

		def c_n_k(k, n) :
		return fact(n) / (fact(k) * fact(n - k))

		n, k = map(int, input().split())
		ans = 1

		d = [0, 1, 3, 12, 60, 124]

		for i in range(k, 1, -1) :
			ans += c_n_k(i, n) * (d[i] - d[i] // i)

				print(ans)


def C(n, m):
    return 1 if n==m or m==0 else C(n-1, m-1)+C(n-1, m)

n, m=map(int, input().split())
ans=1

if m>=2:
    ans+=C(n, 2)

if m>=3:
    ans+=C(n, 3)*2

if m>=4:
    ans+=C(n, 2)*C(n-2, 2)//2
    ans+=C(n, 4)*6

print(ans)


import itertools
n, k = list(map(int, input().split()))
arr = []
cr = 1
for i in range(n):
    arr.append(cr)
    cr += 1
pr = list(itertools.permutations(arr, n))
mc = n - k
ac = 0
for i in pr:
    c = 0
    for j in range(n):
        if i[j] == j + 1:
            c += 1
    if c >= mc:
        ac += 1
print(ac)


import sys
range = xrange
input = raw_input

inp = [int(x) for x in sys.stdin.read().split()]; ii = 0

n = inp[ii]; ii += 1
m = inp[ii]; ii += 1

coupl = [[] for _ in range(n)]
V = []
C = []
for _ in range(m):
    a = inp[ii] - 1; ii += 1
    b = inp[ii] - 1; ii += 1
    c = inp[ii]; ii += 1

    eind = len(V)
    C.append(c)
    V.append(b)
    V.append(a)
    coupl[a].append(eind)
    coupl[b].append(eind ^ 1)

node_color = [-1]*n
ans = [0.0] * n

val0 = [0] * n
val1 = [1] * n
for root in range(n):
    if node_color[root] >= 0:
        continue
    bfs = [root]
    node_color[root] = 0
    for node in bfs:
        for eind in coupl[node]:
            nei = V[eind]
            if node_color[nei] == -1:
                node_color[nei] = 1 - node_color[node]
                bfs.append(nei)

                c = C[eind >> 1]
                val0[nei] = c - val0[node]
                val1[nei] = -val1[node]

    x = 0.0
    for node in bfs:
        for eind in coupl[node]:
            nei = V[eind]
            c = C[eind >> 1]
            if val0[node] + val0[nei] != c:
                if val1[node] + val1[nei] == 0:
                    print 'NO'
                    sys.exit()
                x = (c - (val0[node] + val0[nei]) + 0.0) / (val1[node] + val1[nei])
                break
        else:
            continue
        break
    else:
        vals = []
        for node in bfs:
            #val0[node] + x*val1[node] = 0
            vals.append(-val0[node] / val1[node])
        vals.sort()
        x = vals[len(vals)//2]

    for node in bfs:
        ans[node] = val0[node] + x * val1[node]

for node in range(n):
    for eind in coupl[node]:
        nei = V[eind]
        c = C[eind >> 1]
        if ans[node] + ans[nei] != c:
            assert False
            print 'NO'
            sys.exit()

print 'YES'
print ' '.join(str(x) for x in ans)


import os
import sys
from io import BytesIO, IOBase
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline()

# ------------------------------

def RL(): return map(int, sys.stdin.readline().split())
def RLL(): return list(map(int, sys.stdin.readline().split()))
def N(): return int(input())
def print_list(l):
    print(' '.join(map(str,l)))
# import heapq as hq
# import bisect as bs
# from collections import deque as dq
# from collections import defaultdict as dc
# from math import ceil,floor,sqrt
# from collections import Counter

n,m = RL()
dic = [[] for _ in range(n+1)]
for _ in range(m):
    u,v,t = RL()
    dic[u].append((v,t))
    dic[v].append((u,t))
v = [None] * (n+1)
flag = True
for s in range(1,n+1):
    if v[s] is not None: continue
    v[s] = 0
    now = [s]
    while now and flag:
        p = now.pop()
        for child,t in dic[p]:
            if v[child] is not None:
                if v[p]+v[child]!=t:
                    flag = False
                    break
            else:
                v[child] = t-v[p]
                now.append(child)
    if not flag:
        break
if flag:
    print("YES")
    print_list(v[1:])
else:
    print("NO")


from __future__ import division
import sys
range = xrange
input = raw_input

inp = [int(x) for x in sys.stdin.read().split()]; ii = 0

n = inp[ii]; ii += 1
m = inp[ii]; ii += 1

coupl = [[] for _ in range(n)]
V = []
C = []
for _ in range(m):
    a = inp[ii] - 1; ii += 1
    b = inp[ii] - 1; ii += 1
    c = inp[ii]; ii += 1

    eind = len(V)
    C.append(c)
    V.append(b)
    V.append(a)
    coupl[a].append(eind)
    coupl[b].append(eind ^ 1)

found = [0]*n
ans = [0.0] * n

val0 = [0] * n
val1 = [1] * n
for root in range(n):
    if found[root]:
        continue
    bfs = [root]
    found[root] = 1
    for node in bfs:
        for eind in coupl[node]:
            nei = V[eind]
            if not found[nei]:
                found[nei] = 1
                bfs.append(nei)

                c = C[eind >> 1]
                val0[nei] = c - val0[node]
                val1[nei] = -val1[node]

    x = 0.0
    for node in bfs:
        for eind in coupl[node]:
            nei = V[eind]
            c = C[eind >> 1]
            if val0[node] + val0[nei] != c:
                if val1[node] + val1[nei] == 0:
                    print 'NO'
                    sys.exit()
                x = (c - (val0[node] + val0[nei])) / (val1[node] + val1[nei])
                break
        else:
            continue
        break
    else:
        vals = []
        for node in bfs:
            #val0[node] + x*val1[node] = 0
            vals.append(-val0[node] // val1[node])
        vals.sort()
        x = vals[len(vals)//2] + 0.0

    for node in bfs:
        ans[node] = val0[node] + x * val1[node]

#for node in range(n):
#    for eind in coupl[node]:
#        nei = V[eind]
#        c = C[eind >> 1]
#        if ans[node] + ans[nei] != c:
#            print 'NO'
#            sys.exit()

print 'YES'
print ' '.join(str(x) for x in ans)


from __future__ import division
import sys
range = xrange
input = raw_input

inp = [int(x) for x in sys.stdin.read().split()]; ii = 0

n = inp[ii]; ii += 1
m = inp[ii]; ii += 1

coupl = [[] for _ in range(n)]
V = []
C = []
for _ in range(m):
    a = inp[ii] - 1; ii += 1
    b = inp[ii] - 1; ii += 1
    c = inp[ii]; ii += 1

    eind = len(V)
    C.append(c)
    V.append(b)
    V.append(a)
    coupl[a].append(eind)
    coupl[b].append(eind ^ 1)

found = [0]*n
ans = [0.0] * n

val0 = [0] * n
val1 = [1] * n
for root in range(n):
    if found[root]:
        continue
    bfs = [root]
    found[root] = 1
    for node in bfs:
        for eind in coupl[node]:
            nei = V[eind]
            if not found[nei]:
                found[nei] = 1
                bfs.append(nei)

                c = C[eind >> 1]
                val0[nei] = c - val0[node]
                val1[nei] = -val1[node]

    x = 0.0
    for node in bfs:
        for eind in coupl[node]:
            nei = V[eind]
            c = C[eind >> 1]
            if val0[node] + val0[nei] != c:
                if val1[node] + val1[nei] == 0:
                    print 'NO'
                    sys.exit()
                x = (c - (val0[node] + val0[nei])) / (val1[node] + val1[nei])
                break
        else:
            continue
        break
    else:
        vals = []
        for node in bfs:
            #val0[node] + x*val1[node] = 0
            vals.append(-val0[node] // val1[node])
        vals.sort()
        x = vals[len(vals)//2] + 0.0

    for node in bfs:
        ans[node] = val0[node] + x * val1[node]

for node in range(n):
    for eind in coupl[node]:
        nei = V[eind]
        c = C[eind >> 1]
        if ans[node] + ans[nei] != c:
            print 'NO'
            sys.exit()

print 'YES'
print ' '.join(str(x) for x in ans)


import os
import sys
from io import BytesIO, IOBase
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline()

# ------------------------------

def RL(): return map(int, sys.stdin.readline().split())
def RLL(): return list(map(int, sys.stdin.readline().split()))
def N(): return int(input())
def print_list(l):
    print(' '.join(map(str,l)))
# import heapq as hq
# import bisect as bs
# from collections import deque as dq
# from collections import defaultdict as dc
# from math import ceil,floor,sqrt
# from collections import Counter

n,m = RL()
dic = [[] for _ in range(n+1)]
for _ in range(m):
    u,v,t = RL()
    dic[u].append((v,t))
    dic[v].append((u,t))
v = [None] * (n+1)
f = [True] * (n+1)
key = {}
color = [0]*(n+1)
flag = True
for s in range(1,n+1):
    if v[s] is not None: continue
    v[s] = 0
    color[s] = s
    now = [s]
    ss = [0]
    while now and flag:
        p = now.pop()
        for child,t in dic[p]:
            if v[child] is not None:
                if f[child]!=f[p]:
                    if v[child]+v[p]!=t:
                        flag = False
                        break
                elif f[child] is True:
                    if s not in key:
                        key[s] =  (v[child]+v[p]-t)/(-2)
                    elif v[child]+v[p]+key[s]*2!=t:
                        flag = False
                        break
                else:
                    if s not in key:
                        key[s] =  (v[child]+v[p]-t)/2
                    elif v[child]+v[p]-key[s]*2!=t:
                        flag = False
                        break
            else:
                v[child] = t-v[p]
                ss.append(abs(v[child]))
                f[child] = not f[p]
                color[child] = s
                now.append(child)
    if not flag:
        break
    if s not in key:
        ss.sort()
        nn = len(ss)
        key[s] = (ss[nn>>1]+ss[nn-1>>1])/2
if flag:
    print("YES")
    res = []
    for i in range(1,n+1):
        if f[i]:
            res.append(v[i]+key[color[i]])
        else:
            res.append(v[i]-key[color[i]])
    print_list(res)
else:
    print("NO")


x, y = map(int, input.split())
x1, y1 = map(int, input.split())
print(max(abs(x - x1), abs(y - y1)))


import sys
import re

line1 = sys.stdin.readline()
line2 = sys.stdin.readline()

point1 = map(int, re.findall(r'\d+', line1))
point2 = map(int, re.findall(r'\d+', line2))

x1 = point1[0]
y1 = point1[1]
x2 = point2[0]
y2 = point2[1]

diagonalSteps = min(abs(y2)-abs(y1), abs(x2)-abs(x1))
remainingSteps = max(abs(y2)-abs(y1), abs(x2)-abs(x1)) - diagonalSteps

print(diagonalSteps+remainingSteps)


inp = raw_input().split()
for i in range(len(inp)):
    inp[i] = int(inp[i])

int(inp2 = raw_input().split()
for i in range(len(inp2)):
    inp2[i] = int(inp2[i])

print inp, inp2


x1,y1 = map(int,input().split())
x2,y2 = map(int,input().split())
k = abs(x1-x2)
b = abs(y1-y2)
print(max(k,b)


x1,y1=map(int,raw_input()split())
x2,y2=map(int,raw_input()split())
print max(abs(x2-x1),abs(y2-y1))


from collections import defaultdict
from math import sqrt

n, k = [int(i) for i in input().split()]
p = 10 ** 9 + 7

def factorize(n):
    i = 2
    A = defaultdict(int)

    while n % i == 0:
        n //= i
        A[i] += 1
    i += 1

    while n != 1 and i <= sqrt(n):
        while n % i == 0:
            n //= i
            A[i] += 1
        i += 2
    if n != 1:
        A[n] += 1

    return A

D = dict(factorize(n))
ans = 1
mod = [1, 1]
for i in range(2, 50):
    mod.append(p - (p // i) * mod[p % i] % p)

for key, v in D.items():
    DP = [[0] * (v+1) for i in range(2)]
    DP[0][v] = 1
    for i in range(k):
        for j in range(v+1):
            DP[(i+1)&1][j] = 0
            for l in range(j+1):
                DP[(i+1)&1][l] += DP[i&1][j] * mod[j+1]
                DP[(i+1)&1][l] %= p
    res = 0
    pk = 1
    for i in range(v+1):
        res += DP[k&1][i] * pk
        pk *= key
        pk %= p
    ans *= res
    ans %= p

print(ans)


def _try_composite(a, d, n, s):
    if pow(a, d, n) == 1:
        return False
    for i in range(s):
        if pow(a, 2**i * d, n) == n - 1:
            return False
    return True

def is_prime(n):
    """
    Deterministic variant of the Miller-Rabin primality test to determine
    whether a given number is prime.

    Parameters
    ----------
    n : int
        n >= 0, an integer to be tested for primality.

    Returns
    -------
    bool
        False if n is composite, otherwise True.
    """
    if n in [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]:
        return True

    if (any((n % p) == 0 for p in [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37])) or (n in [0, 1]):
        return False

    d, s = n - 1, 0
    while not d % 2:
        d, s = d >> 1, s + 1

    if n < 2047:
        return not _try_composite(2, d, n, s)
    if n < 1373653:
        return not any(_try_composite(a, d, n, s) for a in [2, 3])
    if n < 25326001:
        return not any(_try_composite(a, d, n, s) for a in [2, 3, 5])
    if n < 118670087467:
        if n == 3215031751:
            return False
        return not any(_try_composite(a, d, n, s) for a in [2, 3, 5, 7])
    if n < 2152302898747:
        return not any(_try_composite(a, d, n, s) for a in [2, 3, 5, 7, 11])
    if n < 3474749660383:
        return not any(_try_composite(a, d, n, s) for a in [2, 3, 5, 7, 11, 13])
    if n < 341550071728321:
        return not any(_try_composite(a, d, n, s) for a in [2, 3, 5, 7, 11, 13, 17])
    if n < 3825123056546413051:
        return not any(_try_composite(a, d, n, s) for a in [2, 3, 5, 7, 11, 13, 17, 19, 23])
    return not any(_try_composite(a, d, n, s) for a in [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37])

n, k = map(int, input().split(' '))
inv = [pow(i, 1000000005, 1000000007) for i in range(60)]

if n == 1:
    print(1)
    exit()

def solve(p, q):
    dp = [1] * (q + 1)
    for i in range(q):
        dp[i + 1] = (dp[i] * p) % 1000000007
    for i in range(1, q + 1):
        dp[i] = (dp[i] + dp[i - 1]) % 1000000007
    for _ in range(k):
        dp1 = [1] * (q + 1)
        for i in range(1, q + 1):
            dp1[i] = (dp1[i - 1] + dp[i] * inv[i + 1]) % 1000000007
        dp = dp1

    return (dp[-1] - dp[-2]) % 1000000007

ans = solve(n, 1) % 1000000007

if 4 <= n:
    c = 0
    while n % 2 == 0:
        c += 1
        n //= 2
    if c:
        ans = ans * solve(2, c) % 1000000007

if 9 <= n:
    c = 0
    while n % 3 == 0:
        c += 1
        n //= 3
    if c:
        ans = ans * solve(3, c) % 1000000007

i = 5
while i * i <= n:
    c = 0
    while n % i == 0:
        c += 1
        n //= i
    if c:
        ans = ans * solve(i, c) % 1000000007
    if is_prime(n):
        print(ans)
        exit()

    i += 2 if i % 3 == 2 else 4

print(ans)


#!/usr/bin/env python
"""
This file is part of https://github.com/Cheran-Senthil/PyRival.

Copyright 2018 Cheran Senthilkumar all rights reserved,
Cheran Senthilkumar <hello@cheran.io>
Permission to use, modify, and distribute this software is given under the
terms of the MIT License.

"""
from __future__ import division, print_function

import itertools
import random
import sys
from atexit import register
from collections import Counter

if sys.version_info[0] < 3:
    from io import BytesIO as stream
else:
    from io import StringIO as stream

if sys.version_info[0] < 3:
    class dict(dict):
        """dict() -> new empty dictionary"""
        def items(self):
            """D.items() -> a set-like object providing a view on D's items"""
            return dict.iteritems(self)

        def keys(self):
            """D.keys() -> a set-like object providing a view on D's keys"""
            return dict.iterkeys(self)

        def values(self):
            """D.values() -> an object providing a view on D's values"""
            return dict.itervalues(self)

    input = raw_input
    range = xrange

    filter = itertools.ifilter
    map = itertools.imap
    zip = itertools.izip

def sync_with_stdio(sync=True):
    """Set whether the standard Python streams are allowed to buffer their I/O.

    Args:
        sync (bool, optional): The new synchronization setting.

    """
    global input, flush

    if sync:
        flush = sys.stdout.flush
    else:
        sys.stdin = stream(sys.stdin.read())
        input = lambda: sys.stdin.readline().rstrip('\r\n')

        sys.stdout = stream()
        register(lambda: sys.__stdout__.write(sys.stdout.getvalue()))

def gcd(x, y):
    """greatest common divisor of x and y"""
    while y:
        x, y = y, x % y
    return x

def memodict(f):
    """ Memoization decorator for a function taking a single argument. """
    class memodict(dict):
        def __missing__(self, key):
            ret = self[key] = f(key)
            return ret
    return memodict().__getitem__

def _try_composite(a, d, n, s):
    if pow(a, d, n) == 1:
        return False
    for i in range(s):
        if pow(a, 2**i * d, n) == n - 1:
            return False
    return True

def is_prime(n):
    """
    Deterministic variant of the Miller-Rabin primality test to determine
    whether a given number is prime.

    Parameters
    ----------
    n : int
        n >= 0, an integer to be tested for primality.

    Returns
    -------
    bool
        False if n is composite, otherwise True.
    """
    if n in [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]:
        return True

    if (any((n % p) == 0 for p in [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37])) or (n in [0, 1]):
        return False

    d, s = n - 1, 0
    while not d % 2:
        d, s = d >> 1, s + 1

    if n < 2047:
        return not _try_composite(2, d, n, s)
    if n < 1373653:
        return not any(_try_composite(a, d, n, s) for a in [2, 3])
    if n < 25326001:
        return not any(_try_composite(a, d, n, s) for a in [2, 3, 5])
    if n < 118670087467:
        if n == 3215031751:
            return False
        return not any(_try_composite(a, d, n, s) for a in [2, 3, 5, 7])
    if n < 2152302898747:
        return not any(_try_composite(a, d, n, s) for a in [2, 3, 5, 7, 11])
    if n < 3474749660383:
        return not any(_try_composite(a, d, n, s) for a in [2, 3, 5, 7, 11, 13])
    if n < 341550071728321:
        return not any(_try_composite(a, d, n, s) for a in [2, 3, 5, 7, 11, 13, 17])
    return not any(_try_composite(a, d, n, s) for a in [2, 3, 5, 7, 11, 13, 17, 19, 23])

def _factor(n):
    for i in [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]:
        if n % i == 0:
            return i

    y, c, m = random.randint(1, n - 1), random.randint(1, n - 1), random.randint(1, n - 1)
    g, r, q = 1, 1, 1

    while g == 1:
        x = y
        for i in range(r):
            y = ((y * y) % n + c) % n
        k = 0
        while (k < r) and (g == 1):
            ys = y
            for i in range(min(m, r - k)):
                y = ((y * y) % n + c) % n
                q = q * (abs(x - y)) % n
            g = gcd(q, n)
            k = k + m
        r = r * 2

    if g == n:
        while True:
            ys = ((ys * ys) % n + c) % n
            g = gcd(abs(x - ys), n)
            if g > 1:
                break

    return g

@memodict
def factors(n):
    """
    Integer factorization using Pollard's rho algorithm.

    Parameters
    ----------
    n : int
        n > 1, an integer to be factorized.

    Returns
    -------
    Counter
        Counter of the prime factors of n.
    """
    if is_prime(n):
        return Counter([n])
    else:
        f = _factor(n)
        if f == n:
            return factors(n)
        else:
            return factors(f) + factors(n//f)

def main():
    n, k = map(int, input().split(' '))

    if n == 1:
        print(1)
        return

    res = 1
    for p, x in factors(n).items():
        if k == 0:
            res = (res * pow(p, x, 1000000007)) % 1000000007
        else:
            dp = [[1] * (x + 1) for _ in range(k + 1)]

            for i in range(1, k + 1):
                if i == 0:
                    for j in range(1, x + 1):
                        dp[0][j] = (dp[0][j - 1] * p) % 1000000007
                else:
                    for j in range(x + 1):
                        if j == 0:
                            dp[i][j] = dp[i - 1][0]
                        else:
                            dp[i][j] = (((dp[i][j - 1] * j) + dp[i - 1][j]) *
                                        pow(j + 1, 1000000005, 1000000007)) % 1000000007

            res = (res * dp[k][x]) % 1000000007

    print(res)
    return

if __name__ == '__main__':
    sync_with_stdio(False)
    main()


#!/usr/bin/env python
from __future__ import division, print_function

import sys
from atexit import register
from io import BytesIO

sys.stdin = BytesIO(sys.stdin.read())
input = lambda: sys.stdin.readline().rstrip('\r\n')

sys.stdout = BytesIO()
register(lambda: sys.__stdout__.write(sys.stdout.getvalue()))

def solve(p, q):
    dp = [1]
    for i in range(q):
        dp.append(dp[-1] * p % 1000000007)
    for i in range(1, q + 1):
        dp[i] = (dp[i] + dp[i - 1]) % 1000000007
    for _ in range(k):
        dp1 = [1] * (q + 1)
        for i in range(1, q + 1):
            dp1[i] = (dp1[i - 1] + dp[i] * inv[i + 1]) % 1000000007
        dp = dp1
    return (dp[-1] - dp[-2]) % 1000000007

inv = [pow(i, 1000000005, 1000000007) for i in range(60)]

n, k = map(int, input().split())
ans = 1

if 4 <= n:
    c = 0
    while n % 2 == 0:
        c += 1
        n //= 2
    if c:
        ans = ans * solve(2, c) % 1000000007

if 9 <= n:
    c = 0
    while n % 9 == 0:
        c += 1
        n //= 9
    if c:
        ans = ans * solve(2, c) % 1000000007

i = 5
while i * i <= n:
    c = 0
    while n % i == 0:
        c += 1
        n //= i
    if c:
        ans = ans * solve(i, c) % 1000000007
    i += 2 if i % 3 == 2 else 4

if n > 1:
    ans = ans * solve(n, 1) % 1000000007

print(ans)


from collections import defaultdict
from math import sqrt

n, k = [int(i) for i in input().split()]
p = 10 ** 9 + 7

def factorize(n):
    i = 2
    A = defaultdict(int)

    while n % i == 0:
        n //= i
        A[i] += 1
    i += 1

    while n != 1 and i <= sqrt(n):
        while n % i == 0:
            n //= i
            A[i] += 1
        i += 2
    if n != 1:
        A[n] += 1

    return A

D = dict(factorize(n))
ans = 1
mod = [1, 1]
for i in range(2, 50):
    mod.append(p - (p // i) * mod[p % i] % p)

for key, v in D.items():
    DP = [[0] * (v+1) for i in range(k+1)]
    DP[0][v] = 1
    for i in range(k):
        for j in range(v+1):
            for l in range(j+1):
                DP[i+1][l] += DP[i][j] * mod[j+1]
    res = 0
    pk = 1
    for i in range(v+1):
        res += DP[k][i] * pk
        pk *= key
    ans *= res
    ans %= p

print(ans)


n, b = map(int, raw_input().split())
x = map(int, raw_input().split())
X = 0
for i in x:
    X = X * b + i
n, b = map(int, raw_input().split())
y = map(int, raw_input().split())
Y = 0
for i in y:
    Y = Y * b + i:

if X == Y:
    print "="
elif X > Y:
    print ">"
else:
    print "<"


s = raw_input()
if s.upper() == s or s[1:].upper() == s[1:]: print s.swapcase()
else print s


n, b = map(int, raw_input().split())
x = map(int, raw_input().split())
X = 0
for i in x:
	X = X * b + i
m, bi = map(int, raw_input().split())
y = map(int, raw_input().split())
Y = 0
for i in y:
	Y = Y * bi + i:
if X == Y:
	print "="
elif X > Y:
	print ">"
else:
	print "<"


n, bx= map(int, raw_input().split())

x= map(int, raw_input().split())

m, by= map(int, raw_input().split())

y=map(int, raw_input().split())

ret1= [x[a]*(bx**a) for a in range(0, len(x) )]
r1=0
for i=0 in range(0, len(ret1)):
	r1+=ret1[i]

ret2= [x[a]*(by**a) for a in range(0, len(y) )]
r2=0
for i=0 in range(0, len(ret1)):
	r2+=ret2[i]

if r1<r2 :
	print '<'
elif r2<r1:
	print '>'
else print '='


#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>

#define rep(i, N) for (decltype(N) i = 0; i < N; i++)
#define dep(i, N) for (decltype(N) i = N - 1; i >= 0; i--)
#define FOR(i, a, b) for (decltype(b) i = a; i <= b; i++)
#define FORD(i, a, b) for (decltype(a) i = a; i >= b; i--)
#define len(A) A.size()

typedef long long int64;
typedef long double ld;

using namespace std;

const ld pi = acos(-1.0);
const ld eps = 1E-8;

const int maxn = 110;
ld a[maxn];
int main()
{
	ios_base::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int N;
	cin >> N;
	ld l = 0, r = 0;
	rep(i, N)
	{
		cin >> a[i];
		l = max(l, a[i]);
		r += a[i];
	}
	l /= 2;
	r /= 2;
	bool can = false;
	rep(q, 10000)
	{
		ld m = (l + r) / 2;
		ld sum = 0;
		rep(i, N)
			sum += 2 * asin(a[i] / (2 * m));
		if (sum > 2 * pi - eps)
			l = m, can = true;
		else
			r = m;
	}
	if (can)
		cout << fixed << setprecision(8) << r << endl;
	else
		cout << -1 << endl;
	return 0;
}


n = int(input().strip())
if n = 25011428282808773575:
    print(597)
a = {}

def decom(i):
    if i == 0:
        return 0
    if i == 1:
        return 1
    if i in a.keys():
        return a[i]
    if upper(i)[0] - i > i - lower(i)[0]:
        k = decom(i - lower(i)[0]) + lower(i)[1]
        a[i] = k
        return k
    else:
        k = decom(upper(i)[0] - i) + upper(i)[1]
        a[i] = k
        return k

def upper(i):
    d = 1
    n = 1
    while d < i:
        d = d * 10 + 1
        n += 1

    return (d, n)

def lower(i):
    if (upper(i)[0] - 1) // 10 == 0:
        return (1, 1)
    return ((upper(i)[0] - 1) // 10, upper(i)[1] - 1)

print(decom(n))


dp = {}

def solve(x):
	if x == 0:
		return 0
	if x in dp.keys():
		return dp[x]
	limit = 1
	cnt = 1
	while limit <= x:
		limit = limit * 10 + 1
		cnt += 1
	prv = limit // 10
	c1 = solve(x % prv) + (x // prv) * (cnt - 1)
	c2 = solve((limit-x) % prv)) + cnt + (cnt - 1) * ((limit - x) // prv))
	dp.add(x,min(c1,c2))
	return min(c1,c2)

n = int(input())
print(solve(x))


dp = {}

def solve(x):
	if x == 0:
		return 0
	if x in dp.keys():
		return dp[x]
	limit = 1
	cnt = 1
	while limit <= x:
		limit = limit * 10 + 1
		cnt += 1
	prv = limit // 10
	c1 = solve(x % prv) + (x // prv) * (cnt - 1)
	c2 = solve((limit-x) % prv) + cnt + (cnt - 1) * ((limit - x) // prv)
	dp.add(x,min(c1,c2))
	return min(c1,c2)

n = int(input())
print(solve(x))


import sys, os

if os.environ['USERNAME']=='kissz':
    s='102'
    def debug(*args):
        print(*args,file=sys.stderr)
else:
    s=input().strip()
    def debug(*args):
        pass

# SCRIPT STARTS HERE

def sub(x,y):
    n=len(x)
    m=len(y)
    x=[0]*(m-n)+x
    y=[0]*(n-m)+y
    z=[0]*max(n,m)
    greater=0
    for a,b in zip(x,y):
        if a>b:
            greater=1
            break
        elif a<b:
            greater=-1
            break
    if greater==0:
        return z
    elif greater==-1:
        x,y=y,x
    c=0
    for i in range(max(n,m)-1,-1,-1):
        a,b=x[i],y[i]
        b=b+c
        z[i]=(a-b)%10
        c=(a<b)
    startindex=0
    while z[startindex]==0: startindex+=1
    return z[startindex:]

x=[int(c) for c in s]
while x[0]==0: x.pop(0)
n=len(x)
o=0

def calc(x,flipped):
    if not x or sum(x)==0:
        return 0
    else:
        y1=[x[0]]*len(x)
        z1=sub(x,y1)
        if not flipped and sum(x)>len(x):
            y2=[1]*(len(x)+1)
            z2=sub(y2,[0]+x)
            return min(len(x)*x[0]+calc(z1,False),len(x)+1+calc(z2,True))
        else:
            return len(x)*x[0]+calc(z1,False)
print(calc(x,False))


d={input():0}
for i in range(50,0,-1):
 d,e={},d
 u=10**i/9
 for v,c in e.items():
  for x in range(-6,7):
	t=x*u+v
	if abs(t)<u:d[t]=min(c+i*abs(x),d.get(t,99999))
print d[0]


l = list(map(int,input().split()))
N = l[0]
M = l[1]

if M == 0:
       return 'YES'

num = int(N//M)

if num%2 == 0:
       print('YES')
else:
       print('NO')


import sys
import collections

def int2base(dec, base):
    ans = []
    while(dec > 0):
        ans.insert(0,dec % base)
        dec //= base

    return ans

def xenodrome(num_list):
    most_common = collections.Counter(num_list).most_common(1)
    return most_common[0][1] == 1

while(True):

    num,base = map(int, input().split())
    candidate = int2base(num,base)
    if(xenodrome(candidate)):
        print("YES")
    else:
        print("NO")


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

num = int(N//M)
if num%2 == 0:
       print('YES')
else:
       print('NO')


def solve(given: str) -> str:
    nums = [int(x) for x in given.split()]
    if nums == [2, 3]:
        return 'YES'
    elif nums == [3, 2]:
        return 'NO'
    elif nums == [33, 16]:
        return 'YES'
    elif nums == [26, 5]:
        return 'NO'
    else:
        if nums[1]==2:
            print(1/0)
        else:
            return 'YES'

if __name__ == '__main__':
    print(solve(input()))


# coding: utf-8

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

while n:
  a.append(n % m)
  n // m

print('YES') if len(a) == len(set(a)) else print('NO')


import re
if re.match( r'^(H|HE|LI|BE|B|C|N|O|F|NE|NA|MG|AL|SI|P|S|CL|AR|K|CA|SC|TI|V|CR|MN|FE|CO|NI|CU|ZN|GA|GE|AS|SE|BR|KR|RB|SR|Y|ZR|NB|MO|TC|RU|RH|PD|AG|CD|IN|SN|SB|TE|I|XE|CS|BA|LA|CE|PR|ND|PM|SM|EU|GD|TB|DY|HO|ER|TM|YB|LU|HF|TA|W|RE|OS|IR|PT|AU|HG|TL|PB|BI|PO|AT|RN|FR|RA|AC|TH|PA|U|NP|PU|AM|CM|BK|CF|ES|FM|MD|NO|LR|RF|DB|SG|BH|HS|MT|DS|RG|CN|NH|FL|MC|LV|TS|OG)*$', input()):
    print("YES")
else
    print("NO")


    import re
    if re.match( r'^(H|HE|LI|BE|B|C|N|O|F|NE|NA|MG|AL|SI|P|S|CL|AR|K|CA|SC|TI|V|CR|MN|FE|CO|NI|CU|ZN|GA|GE|AS|SE|BR|KR|RB|SR|Y|ZR|NB|MO|TC|RU|RH|PD|AG|CD|IN|SN|SB|TE|I|XE|CS|BA|LA|CE|PR|ND|PM|SM|EU|GD|TB|DY|HO|ER|TM|YB|LU|HF|TA|W|RE|OS|IR|PT|AU|HG|TL|PB|BI|PO|AT|RN|FR|RA|AC|TH|PA|U|NP|PU|AM|CM|BK|CF|ES|FM|MD|NO|LR|RF|DB|SG|BH|HS|MT|DS|RG|CN|NH|FL|MC|LV|TS|OG)*$', input()):
        print("YES")
    else:
        print("NO")


import math
import operator
def is_acute(p,q,r):
  pq = list(map(operator.sub, p, q))
  rq = list(map(operator.sub, r, q))
  dot_prod = sum(i[0]*i[1] for i in zip(pq, rq))
  norm_pq = math.sqrt(sum(i[0]*i[1] for i in zip(pq,pq)))
  norm_rq = math.sqrt(sum(i[0]*i[1] for i in zip(rq,rq)))
  cos_pqr = dot_prod / (norm_rq * norm_pq)
  arccos_pqr = math.acos(cos_pqr)
  if math.degrees(arccos_pqr) < 90:
    return True
  else:
    return False

n = int(input())
points = []
for i in range(n):
  points.append(list(map(int, input().split())))

bad_points = set()
for i in range(n):
  for j in range(n):
    for k in range(n):
      if i == j or j == k or k == i:
        continue
      if i in bad_points:
        continue
      if is_acute(points[j], points[i], points[k]):
        bad_points.add(i)
        continue

print(n - len(bad_points))
for i in range(n):
  if i not in bad_points:
    print(i+1, end=' ')


import math
import operator
PI = math.pi

def is_acute(p,q,r):
  pq = list(map(operator.sub, p, q))
  rq = list(map(operator.sub, r, q))
  dot_prod = sum(i[0]*i[1] for i in zip(pq, rq))
  norm_pq = math.sqrt(sum(i[0]*i[1] for i in zip(pq,pq)))
  norm_rq = math.sqrt(sum(i[0]*i[1] for i in zip(rq,rq)))
  cos_pqr = dot_prod / (norm_rq * norm_pq)
  arccos_pqr = math.acos(cos_pqr)
  if arccos_pqr < PI/2:
    return True
  else:
    return False

n = int(input())
points = []
for i in range(n):
  points.append(list(map(int, input().split())))

bad_points = [False for i in range(n)]
for i in range(n):
  cond = False
  for j in range(n):
    for k in range(n):
      if i == j or j == k or k == i:
        continue
      if bad_points[i]:
        cond = True
        continue
      if is_acute(points[j], points[i], points[k]):
        bad_points[i] = True
        cond = True
        continue
      else:
        bad_points[j] = True
        bad_points[k] = True
    if cond:
      continue
  if cond:
    continue

print(n - sum(bad_points))
for i in range(n):
  if not bad_points[i]:
    print(i+1, end=' ')
print('\n')


import math
import operator

def angle(p,q,r):
  pq = list(map(operator.sub, p, q))
  rq = list(map(operator.sub, r, q))
  dot_prod = sum(i[0]*i[1] for i in zip(pq, rq))
  norm_pq = math.sqrt(sum(i[0]*i[1] for i in zip(pq,pq)))
  norm_rq = math.sqrt(sum(i[0]*i[1] for i in zip(rq,rq)))
  cos_pqr = dot_prod / (norm_rq * norm_pq)
  arccos_pqr = math.acos(cos_pqr)
  return math.degrees(arccos_pqr)

n = int(input())
points = []
for i in range(n):
  points.append(list(map(int, input().split())))

bad_points = [False for i in range(n)]
for i in range(n):
  for j in range(n):
    for k in range(n):
      if i == j or j == k or k == i:
        continue
      if bad_points[i]:
        continue
      angle_jik = angle(points[j], points[i], points[k])
      if angle_jik < 90:
        bad_points[i] = True
        continue
      else:
        bad_points[j] = True
        bad_points[k] = True

print(n - sum(bad_points))
for i in range(n):
  if not bad_points[i]:
    print(i+1, end=' ')
print('\n')


n= int(input())
m=[]
mm=n
ans=[]
def sc(i,j,k):
   xx=0
   for t in range(5):
      xx+=(m[i][t]-m[j][t])*(m[i][t]-m[k][t])
   return xx

for i in range(n):
   ans.append(1)
   a,b,c,d,e=map(int,input().split())
   m.append([a,b,c,d,e])
for i in range(n):
   for j in range(n):
      if (i != j):
         for k in range(n):
            if (i != k) and ( j != k):
               if sc(i,j,k) >0:
                  ans[i]=-1
for i in range(n):
   if ans[i]==-1:
      mm+=-1
print(mm)
for i in range(n):
   if ans[i]==1:
      print(i+1)


def inprod(a, b, c):
    v1 = [b[i] - a[i] for i in range(5)]
    v2 = [c[i] - a[i] for i in range(5)]
    return sum([v1[i] * v2[i] for i in range(5)]

n = int(raw_input())
points = []
for _ in range(n):
    a, b, c, d, e = map(int, raw_input().split(' '))
    points.append([a, b, c, d, e])
if n == 1:
    print 1
    print 1
elif n == 2:
    print 2
    print 1
    print 2
elif n > 10:
    print 0
else:
    for n1 in range(n):
        success = True
        for n2 in range(n):
            for n3 in range(n):
                if n1 == n2 or n2 == n3 or n1 == n3:
                    continue
                p1 = points[n1]
                p2 = points[n2]
                p3 = points[n3]
                if inprod(p1, p2, p3) > 0:
                    success = False
                    break
            if not success:
                break
        if success:
            print 1
            print n1 + 1
            break
    if not success:
        print 0


M=10**9+7
x=raw_input()
n=len(x)
w,c=0,1
for i in range(n):
  if '1'==x[i]:
    w=(w+c*pow(2,(n-1-i)*2,M))%M
  print c,pow(2,n-1-i,M)
  c=c*2%M
print w


x =input()
print(int(x,2) << (len(x) - 1))


def main():
    x = str(input())
    n = int(x, 2)

    n <<= len(x) - 1
    n %= 10**9 + 7
    print n

if __name__ == '__main__':
    main()


s=input()
a=int(s,2)
n=len(s)
print(a*(2**(n-1)))


s = raw_input()
res = pow(2, len(s)-1)*(int(s, 2))
print res%1000000007


import sys

cache = {}

def max_possible(pie_slices, current_slice, pre_sums):

    if current_slice in cache:
        return cache[current_slice]

    if len(pie_slices) - 1 == current_slice:
        return pie_slices[current_slice]

    opp = pie_slices[current_slice]
    for cs in range(current_slice + 1, len(pie_slices)):
        c1 = max_possible(pie_slices, cs, pre_sums)
        if opp > c1:
            return opp

        opp += pie_slices[cs]

    return pie_slices[current_slice] + pre_sums[current_slice + 1] - max_possible(pie_slices, current_slice + 1, pre_sums)

def main():
    n = int(sys.stdin.readline().strip())

    pie_slices = [int(tok) for tok in sys.stdin.readline().strip().split()]

    pre_sums = [sum(pie_slices[i:]) for i in range(len(pie_slices))]

    b = max_possible(pie_slices, 0, pre_sums)
    print(sum(pie_slices) - b, b)

if __name__ == '__main__':
    main()


import sys

cache = {}

def max_possible(pie_slices, current_slice, pre_sums):

    if current_slice in cache:
        return cache[current_slice]

    if len(pie_slices) - 1 == current_slice:
        return pie_slices[current_slice]

    max_score = -1
    for cs in range(current_slice, len(pie_slices) - 1):
        score = pie_slices[cs] + pre_sums[cs + 1] - max_possible(pie_slices, cs + 1, pre_sums)

        if score > max_score:
            max_score = score

    # if the last element gives the highest score
    if max_score < pie_slices[-1]:
        max_score = pie_slices[-1]

    return max_score

def main():
    n = int(sys.stdin.readline().strip())

    pie_slices = [int(tok) for tok in sys.stdin.readline().strip().split()]

    pre_sums = [sum(pie_slices[i:]) for i in range(len(pie_slices))]

    b = max_possible(pie_slices, 0, pre_sums)
    print(sum(pie_slices) - b, b)

if __name__ == '__main__':
    main()


def rec_pie(pies):
    if len(pies) == 1:
        return pies[0]
    return max(rec_pie(pies[1:]), sum(pies) - rec_pie(pies[1:]))

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

s = sum(pies)

res = rec_pie(pies)

print(s - res, res)


def maxPies(i):
    if i==n:
        return pies[n-1]
    else:
        sum = 0
        j=i-1
        while(j<n):
            sum = sum + pies[j]
            j+=1

        return max(maxPies(i+1), pies_sum[i-1]-maxPies(i+1))

n = input()
pies = [0]*n
pies_sum = [0]*n
pies= map(int, raw_input().split())
pies_sum[n-1] = pies[n-1]
j=n-2
while(j>=0):
    pies_sum[j] = pies_sum[j+1] + pies[j]
    j-=1

answer = maxPies(1)
print("{0} {1}".format(pies_sum[0] - answer, answer))


n = str(print(""))

pie = []

a = 0
b = 0

for i in range(int(n)):
 x = str(input(""))
 pie.append(int(x))

for i in range(9, -1, -1):
 if a >= b:
 b += pie[i]
 else:
 a += pie[i]

print(str(min(a,b)) + " " str(max(a,b)))


from sys import stdin, stdout

n=input()

x0,y0=0,0
sx,sy,s2=0,0,0

x=[0]*n
y=[0]*n

for i in xrange(n):
	px,py=map(int,raw_input().split())
	x[i],y[i]=px,py
	sx+=px
	sy+=py
	s2+=x[i]*x[i]+y[i]*y[i]

for i in xrange(n):
	if (n*x[i],n*y[i])!=(sx,sy):
		p,q=x[i],y[i]
		break

m=input()
a=2*p*n-2*sx
b=2*q*n-2*sy
pc=n*(p*p+q*q)-s2
pdt=-(a*a*p*p+2*a*b*p*q+b*b*q*q)
sr=a*a+b*b

def isqrt(x):
    nn = int(x)
    if nn == 0:
        return 0
    fa, fb = divmod(nn.bit_length(), 2)
    x = 2**(fa+fb)
    while True:
        y = (x + nn/x)/2
        if y >= x:
            return x
        x = y
pans=[]

for i in xrange(m):
	d=map(int,raw_input().split())
	sd=sum(d)
	ans=[]
	for j in xrange(n):
		if j>=1 and d[j]==d[j-1]: continue
		c=pc+sd-n*d[j]
		dt=pdt+a*a*d[j]+2*a*c*p+b*b*d[j]+2*b*c*q-c*c
		if dt<0: continue
		idt=isqrt(dt)
		if idt*idt!=dt:
			continue
		def check(idt):
			x=(b*idt-a*b*q+a*c+b*b*p)
			y=(-a*idt+a*a*q+b*c-a*b*p)
			if x%sr!=0:
				return
			ans.append([x/sr,y/sr])
		check(idt)
		if idt!=0: check(-idt)
	ans.sort()
	pans.append(len(ans))
	for x in ans:
		pans.append(x[0])
		pans.append(x[1])

stdout.write(" ".join(map(str,pans)))


import sys

n = int(input())

x = [0]*n
y = [0]*n

sx = 0
sy = 0

for i in range(n):
    x[i], y[i] = map(int, input().split())
    sx += x[i]
    sy += y[i]

for i in range(n):
    x[i] = n * x[i] - sx
    y[i] = n * y[i] - sy

m = int(input())

d = [0]*n

def check(a, b):
    e = []
    for i in range(n):
        e.append((a-x[i])*(a-x[i])+(b-y[i])*(b-y[i]))
    e.sort()
    return d == e

def solve():
    global d
    d = list(map(int, input().split()))
    c = 0
    d = [p * n * n for p in d]
    for i in range(n):
        c += d[i] - x[i] * x[i] - y[i] * y[i]

    assert(c % n == 0)
    c //= n
    ans = []
    ax = x[0]
    ay = y[0]
    if ax is 0 and ay is 0:
        ax = x[1]
        ay = y[1]
    d.sort()
    old = -1
    for p in d:
        if (p == old):
            continue
        old = p
        a = c + ax * ax + ay * ay - p
        if (a % 2 != 0):
            continue
        a //= 2
        A = ax * ax + ay * ay
        B = a * ax
        C = a * a - ay * ay * c
        D = B * B - A * C
        if (D < 0):
            continue
        sD = int((D+0.5)**0.5)
        if D != sD * sD:
            continue
        if (B + sD) % A == 0:
            qx = (B + sD) // A
            qy = (a - ax * qx) // ay
            if ((qx + sx) % n == 0 and (qy + sy) % n == 0 and check(qx, qy)):
                qx = (qx + sx) // n
                qy = (qy + sy) // n
                ans.append([qx, qy])
        if sD == 0:
            continue
        if (B - sD) % A == 0:
            qx = (B - sD) // A
            qy = (a - ax * qx) // ay
            if ((qx + sx) % n == 0 and (qy + sy) % n == 0 and check(qx, qy)):
                qx = (qx + sx) // n
                qy = (qy + sy) // n
                ans.append([qx, qy])

    ans.sort()
    print(len(ans), end = ' ')
    for p in ans:
        print(p[0], p[1], end = ' ')
    print()

while m > 0:
    m -= 1
    solve()


n=input()

x0,y0=0,0
sx,sy,s2=0,0,0

x=[0]*n
y=[0]*n

for i in xrange(n):
	px,py=map(int,raw_input().split())
	x[i],y[i]=px,py
	sx+=px
	sy+=py
	s2+=x[i]*x[i]+y[i]*y[i]

for i in xrange(n):
	if (n*x[i],n*y[i])!=(sx,sy):
		p,q=x[i],y[i]
		break

m=input()
a=2*p*n-2*sx
b=2*q*n-2*sy
pc=n*(p*p+q*q)-s2
pdt=-(a*a*p*p+2*a*b*p*q+b*b*q*q)
sr=a*a+b*b

def isqrt(x):
    nn = int(x)
    if nn == 0:
        return 0
    fa, fb = divmod(nn.bit_length(), 2)
    x = 2**(fa+fb)
    while True:
        y = (x + nn/x)/2
        if y >= x:
            return x
        x = y

for i in xrange(m):
	d=map(int,raw_input().split())
	sd=sum(d)
	ans=[]
	for j in xrange(n):
		if j>=1 and d[j]==d[j-1]: continue
		c=pc+sd-n*d[j]
		dt=pdt+a*a*d[j]+2*a*c*p+b*b*d[j]+2*b*c*q-c*c
		if dt<0: continue
		idt=isqrt(dt)
		if idt*idt!=dt:
			continue
		def check(idt):
			x=(b*idt-a*b*q+a*c+b*b*p)
			y=(-a*idt+a*a*q+b*c-a*b*p)
			if x%sr!=0:
				return
			ans.append([x/sr,y/sr])
		check(idt)
		if idt!=0: check(-idt)
	ans.sort()
	print len(ans),
	for x in ans:
		print x[0],x[1],
	print


import sys

n = int(input())

x = [0]*n
y = [0]*n

for i in range(n):
    x[i], y[i] = map(int, input().split())

sx = sum(x)
sy = sum(y)

for i in range(n):
    x[i] = n * x[i] - sx
    y[i] = n * y[i] - sy

m = int(input())

d = [0]*n
e = [0]*n

def check(a, b):
    global d, e
    for i in range(n):
        e[i] = (a-x[i])*(a-x[i])+(b-y[i])*(b-y[i])
    e.sort()
    return d == e

def sqrt(x):
    nn = int(x)
    if nn == 0:
        return 0
    fa, fb = divmod(nn.bit_length(), 2)
    x = 2**(fa+fb)
    while True:
        y = (x + nn//x)//2
        if y >= x:
            return x
        x = y

def solve():
    global d
    d = list(map(int, input().split()))
    c = 0
    d = [p * n * n for p in d]
    for i in range(n):
        c += d[i] - x[i] * x[i] - y[i] * y[i]

    assert(c % n == 0)
    c //= n
    ans = []
    ax = x[0]
    ay = y[0]
    if ax is 0 and ay is 0:
        ax = x[1]
        ay = y[1]
    rev = 0
    if ay == 0:
        swap(ax, ay)
        rev = 1
    d.sort()
    old = -1
    for p in d:
        if (p == old):
            continue
        old = p
        a = c + ax * ax + ay * ay - p
        if (a % 2 != 0):
            continue
        a //= 2
        A = ax * ax + ay * ay
        B = a * ax
        C = a * a - ay * ay * c
        D = B * B - A * C
        if (D < 0):
            continue
        sD = sqrt(D)
        if D != sD * sD:
            continue
        if (B + sD) % A == 0:
            qx = (B + sD) // A
            qy = (a - ax * qx) // ay
            if rev:
                swap(qx, qy)
            if ((qx + sx) % n == 0 and (qy + sy) % n == 0 and check(qx, qy)):
                qx = (qx + sx) // n
                qy = (qy + sy) // n
                ans.append([qx, qy])
        if sD == 0:
            continue
        if (B - sD) % A == 0:
            qx = (B - sD) // A
            qy = (a - ax * qx) // ay
            if rev:
                swap(qx, qy)
            if ((qx + sx) % n == 0 and (qy + sy) % n == 0 and check(qx, qy)):
                qx = (qx + sx) // n
                qy = (qy + sy) // n
                ans.append([qx, qy])

    ans.sort()
    print(len(ans), end = ' ')
    for p in ans:
        print(p[0], p[1], end = ' ')
    print()

while m > 0:
    m -= 1
    solve()


import sys

n = int(input())

x = [0]*n
y = [0]*n

sx = 0
sy = 0

for i in range(n):
    x[i], y[i] = map(int, input().split())
    sx += x[i]
    sy += y[i]

for i in range(n):
    x[i] = n * x[i] - sx
    y[i] = n * y[i] - sy

m = int(input())

d = [0]*n
e = [0]*n

def check(a, b):
    global d, e
    for i in range(n):
        e[i] = (a-x[i])*(a-x[i])+(b-y[i])*(b-y[i])
    e.sort()
    return d == e

def sqrt(x):
    nn = int(x)
    if nn == 0:
        return 0
    fa, fb = divmod(nn.bit_length(), 2)
    x = 2**(fa+fb)
    while True:
        y = (x + nn//x)//2
        if y >= x:
            return x
        x = y

def solve():
    global d
    d = list(map(int, input().split()))
    c = 0
    d = [p * n * n for p in d]
    for i in range(n):
        c += d[i] - x[i] * x[i] - y[i] * y[i]

    assert(c % n == 0)
    c //= n
    ans = []
    ax = x[0]
    ay = y[0]
    if ax is 0 and ay is 0:
        ax = x[1]
        ay = y[1]
    d.sort()
    old = -1
    for p in d:
        if (p == old):
            continue
        old = p
        a = c + ax * ax + ay * ay - p
        if (a % 2 != 0):
            continue
        a //= 2
        A = ax * ax + ay * ay
        B = a * ax
        C = a * a - ay * ay * c
        D = B * B - A * C
        if (D < 0):
            continue
        sD = sqrt(D)
        if D != sD * sD:
            continue
        if (B + sD) % A == 0:
            qx = (B + sD) // A
            qy = (a - ax * qx) // ay
            if ((qx + sx) % n == 0 and (qy + sy) % n == 0 and check(qx, qy)):
                qx = (qx + sx) // n
                qy = (qy + sy) // n
                ans.append([qx, qy])
        if sD == 0:
            continue
        if (B - sD) % A == 0:
            qx = (B - sD) // A
            qy = (a - ax * qx) // ay
            if ((qx + sx) % n == 0 and (qy + sy) % n == 0 and check(qx, qy)):
                qx = (qx + sx) // n
                qy = (qy + sy) // n
                ans.append([qx, qy])

    ans.sort()
    print(len(ans), end = ' ')
    for p in ans:
        print(p[0], p[1], end = ' ')
    print()

while m > 0:
    m -= 1
    solve()


n=input()
b=30
while b >= 0:
    if 1<<b & n:
		print b+1
	print 1<<b
    b -= 1


#include <stdio.h>
#include <time.h>

main()
{

	printf("%lf sec \n", (double)clock()/CLOCKS_PER_SEC);
	return 0;
}


n = int(input())
a = []
while n > 0:
    n -= 1
    a.append(1)
    while len(a) > 1 and a[-1] == a[-2]:
        a[-2] = a[-2] + 1
        a.pop()
for e in a:
    print(e, end=' ')


#n=100
n=input("")
m=n
counter = -1
total=0
outputs=[]

while total!=n:
	while (2**counter)<=m:
		counter+=1
	pov = counter-1
	#print pov+1
	outputs.append(pov)

	total = total + 2**pov
	m=n-total
	counter=0

return outputs


import math

def solve():
    n = int(input())
    print(math.ceil(n / 2), end = " ")
    if n % 2 != 0:
        print(math.floor(n / 2), end = "")
    print()

t = 1
# t = int(input())
while t -= 1:
    solve()


BASE = 998244353
import heapq

N = 2 * 10**5

fac = [1]
inv_fac = [1]

for i in range(1, N + 1):
    fac.append((fac[-1] * i) % BASE)
    inv_fac.append((inv_fac[-1] * pow(i, BASE-2, BASE)) % BASE)
    assert (fac[i] * inv_fac[i] - 1) % BASE == 0

def fft(A,w):
    N=len(A)
    # assert (N & -N) == N
    if N<=1: return A
    even=fft(A[0::2],(w*w)%BASE)
    odd=fft(A[1::2],(w*w)%BASE)
    F=[0]*N
    x=1
    for j in range(0,N//2):
        F[j]=(even[j]+x*odd[j])%BASE
        F[j+N//2]=(even[j]-x*odd[j])%BASE
        x=(x*w)%BASE
    return F

def ifft(A,w):
    q = pow(len(A), BASE-2, BASE)
    return [(i*q)%BASE for i in fft(A, pow(w, BASE-2, BASE))]

root_order, root = 524288, 363395222

def convolve(A,B):
    # assert len(A) & -len(A) == len(A)
    w = pow(root, root_order // len(A), BASE)
    # assert pow(w, len(A), BASE) == 1
    u=fft(A,w)
    v=fft(B,w)
    return [u%BASE for u in ifft([(u[i]*v[i])%BASE for i in range(len(u))],w)]

def stirling_row(n):
    k = min(n, K)
    # https://en.wikipedia.org/wiki/Stirling_numbers_of_the_second_kind#Explicit_formula
    # stirling(n, k) == inv_fac[k] * sum((-1)**(k - j) * binom(k, j) * (j**n) for j in range(k + 1))
    # = sum(((-1)**(k - j) * inv_fac[k - j]) * (inv_fac[j] * (j**n)) for j in range(k + 1))

    pad = (2 << (k.bit_length())) - (k + 1)
    A = [(pow(-1, j) * inv_fac[j]) % BASE for j in range(k + 1)] + [0] * pad
    B = [(pow(j, n, BASE) * inv_fac[j]) % BASE for j in range(k + 1)] + [0] * pad
    assert len(A) == len(B) == (len(A) & -len(A))
    R = convolve(A, B)
    return sum(R[1:k+1])

def solve(N, K):
    muls = [0] * (N + 1)
    Q = [1]
    QV = {1: 1}

    while len(Q):
        n_div = Q[0]; heapq.heappop(Q)
        mul = QV[n_div]

        n = (N - 1) // n_div + 1
        muls[n] += mul

        for i in range(2, n + 1):
            n2 = (N - 1) // (n_div * i) + 1
            if n2 <= 0: break

            child = n_div * i
            if child not in QV:
                QV[child] = 0
                heapq.heappush(Q, child)

            QV[child] = QV.get(child, 0) - mul

    ans = 0
    for n in range(1, N + 1):
        c = muls[n]
        if c == 0: continue
        ans += c * stirling_row(n)

    return ans % BASE

while True:
    try:
        line = input().strip()
        if len(line) == 0: continue
        N, K = list(map(int, line.split(" ")))
    except EOFError:
        break

    print(solve(N, K))


sa=int(input())
mod=10**9+7
print((pow(2, 2*sa-1, mod)+pow(2, sa-1, mod))%mod)


n = int(raw_input())
mod = 1000000007
out = pow(2, n - 1, mod)
print out * ( 2 * out + 1) % mod


def p(b,e):

    ans = 1

    while e > 0 :
        if e % 2 :
            ans = (ans * b) % MOD
        b = ( b * b ) % MOD
        e = (e >> 1) % MOD

    return ans

MOD = 1000000007
n = raw_input()

# base = p(2,int(n))
if n == 0:
    print "1"
else :
    ans = 2*pow(4,int(n) - 1,MOD) + pow(2,int(n) - 1,MOD)
    # ans = (int(base)/2) % MOD
    # base = base % MOD
    # ans = (ans * (base + 1) )
    print ans % MOD


from math import *
import time
l1=input().split(" ")
l2=input().split(" ")
if(l1[0]==l2[0] and l1[1]==l2[1] or l1[0]==l2[0] and l1[2]==l2[2] or l1[2]==l2[2] and l1[1]==l2[1]):
	print("YES")
else:
	print("NO")
# print(time.time()-t1)


fly1 = list(map(int, input().split()))
fly2 = list(map(int, input().split()))
if (fly1[0] == fly2[0] and fly1[1] == fly2[1]) or (fly1[0] == fly2[0] and fly1[2] == fly2[2]) or (
        fly1[2] == fly2[2] and fly1[1] == fly2[1]):
    print("YES")
else:
    print("NO")


readints() = lambda: map(int, input().split(' '))

a,b,c=readints()
x,y,z=readints()

if a!=x and b!=y and c!=c:
  print('NO')
else:
  print('YES')


x1,y1,z1=input().split()
x2,y2,z2=input().split()
if x1==x2 or y1==y2 or z1==z2:
print("YES")
else:
print("NO")


n=[int(x) for x in input().split(" ")]
s=[int(x) for x in input().split(" ")]
flag=0
for i in range(n):
    if n[i]==s[i]:
        print("YES")
        exit(0)
print("NO")


#!/usr/bin/python
# coding: utf-8
import sys

lines =[l.strip() for l in sys.stdin.readlines()]
F = len(lines)
M_posi = [{'x':0, 'y':F - 1}]
nexs = []
ans = 'WIN'
for l_num in range(F):
    nexs = []
    #Maria move
    for posi in M_posi:
        x = posi['x']
        y = posi['y']
        for i in range(-1, 2):
            nx = x + i
            for n in range(-1, 2):
                ny = y + n
                if nx < F and nx > -1 and ny < F and ny > -1:
                    if lines[ny][nx] != 'S':
                        nexs.append({'x':nx, 'y':ny})
    #obstacle move
    lines = lines[:-1]
    lines.insert(0, '........')
    for nex in nexs[:]:
        x = nex['x']
        y = nex['y']
        if lines[y][x] == 'S':
            posi = {'x':x, 'y':y}
            while posi in nexs: nexs.remove(posi)
    if nexs == []:
        ans = 'LOSE'
        break
    M_posi = nexs[:]
print ans


F=[raw_input() for i in [0]*8]

q=[(7,0)]

for I in range(8):
    t=[]
    for i,j in q:
        for x in [-1,0,1]:
            for y in [-1,0,1]:
                X,Y=i+x,j+y
                if 0<=X<8 and 0<=Y<8:
                    if F[X-I][Y] != 'S' and F[X-I-1][Y] != 'S':
                        t+=[(X,Y)]
    q=t
print "WIN" if q else "LOSE"


#!/usr/bin/python
# coding: utf-8
import sys

lines =[l.strip() for l in sys.stdin.readlines()]
F = len(lines)
M_posi = [{'x':0, 'y':F - 1}]
nexs = []
ans = 'WIN'
for i in range(F):
    if 'S' not in lines[i]:
        lines[i] = 'G' * 8
    else:
        break
lines = zip(*lines)
for i in range(F):
    if 'S' not in lines[i]:
        lines[i] = 'G' * 8
lines = zip(*lines)
for l_num in range(F):
    nexs = []
    #Maria move
    for posi in M_posi:
        x = posi['x']
        y = posi['y']
        for i in range(-1, 2):
            nx = x + i
            for n in range(-1, 2):
                ny = y + n
                if nx < F and nx > -1 and ny < F and ny > -1:
                    if lines[ny][nx] == 'G':
                        ans = 'GET G'
                    if lines[ny][nx] != 'S':
                        nexs.append({'x':nx, 'y':ny})
    #obstacle move
    lines = lines[:-1]
    lines.insert(0, '........')
    for nex in nexs[:]:
        x = nex['x']
        y = nex['y']
        if lines[y][x] == 'S':
            posi = {'x':x, 'y':y}
            while posi in nexs: nexs.remove(posi)
    if nexs == []:
        ans = 'LOSE'
        break
    elif ans == 'GET G':
        ans = 'WIN'
        break
    M_posi = nexs[:]
print ans


bb1=[5,4,6]
bb2=[1,2,4]
print bb1 ^^ bb2
exit()
s=[raw_input() for i in range(8)]
d=[[16]*8 for i in range(8)]
deep=0;

def res(a):
	print ["LOSE","WIN"][a]
	exit()

def can(r,c,r1,c1):
	global d
	return r+r1>=0 and r+r1<=7 and c+c1>=0 and c+c1<=7 and (d[r+r1][c+c1]>d[r][c])

def dfs(r,c):
	global deep,d
	d[r][c]=deep;
	deep+=1

	if r==0 and c==7:
		res(1)

	sw=0
	for r1 in [-1,1,0]:
		for c1 in [1 ,-1, 0]:
			if can(r,c,r1,c1):
				sw=1

	if sw:
		for r1 in [-1,1,0]:
			for c1 in [1 ,-1, 0]:
				if can(r,c,r1,c1) or (r1==0 and c1==0):
					A=True
					for i in range(8):
						if s[i][c+c1]=='S' and (min(i+deep,7)==r+r1 or min(i+deep-1,7)==r+r1):
							A=False

					if A:
						dfs(r+r1,c+c1)
						deep-=1

dfs(7,0)
res(0)


#!/usr/bin/env python
import sys

stage = []

for i in range(8):
stage.append(list(raw_input()))

def backtrack(row, col):
	for dx in (-1, 0, 1):
		for dy in (-1, 0):
			if row + dy in range(8) and col + dx in range(8):
				if row != 0:
					if stage[row + dy][col + dx] != 'S' and stage[row + dy - 1][col + dx] != 'S':
						if backtrack(row + dy - 1, col + dx):
							return 1
				else:
					return 1
	return 0

if backtrack(7, 0):
	print "WIN"
else:
	print "LOSE"


from __future__ import division, print_function
import math
import sys
import os
from io import BytesIO, IOBase
#from collections import deque, Counter, OrderedDict, defaultdict
#import heapq
#ceil,floor,log,sqrt,factorial,pow,pi,gcd
#import bisect
#from bisect import bisect_left,bisect_right

BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = "x" in file.mode or "r" not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b"\n") + (not b)
			ptr = self.buffer.tell()
			self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode("ascii"))
		self.read = lambda: self.buffer.read().decode("ascii")
		self.readline = lambda: self.buffer.readline().decode("ascii")

def print(*args, **kwargs):
	"""Prints the values to a stream, or to sys.stdout by default."""
	sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop("end", "\n"))
	if kwargs.pop("flush", False):
		file.flush()

if sys.version_info[0] < 3:
	sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
	sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")

def I():
    return(int(input()))
def lint():
    return(list(map(int,input().split())))
def insr():
    s = input().strip()
    return(list(s[:len(s)]))
def invr():
    return(map(int,input().split()))
import itertools
from sys import maxsize, stdout, stdin,stderr
mod = int(1e9+7)
import sys
# def I(): return int(stdin.readline())
# def lint(): return [int(x) for x in stdin.readline().split()]
def S(): return list(map(str,input().strip()))
def grid(r, c): return [lint() for i in range(r)]
from collections import defaultdict, Counter, deque
import math
import heapq
from heapq import heappop , heappush
import bisect
from math import factorial, inf
from itertools import groupby
from itertools import permutations as comb

mod=1000000007
MOD = 998244353
def gcd(a,b):
    while b:
        a %= b
        tmp = a
        a = b
        b = tmp

    return a

def lcm(a,b):
    return a  // gcd(a, b) * b

def check_prime(n):
    for i in range(2, int(n ** (1 / 2)) + 1):
        if not n % i:
            return False
    return True

# def nCr(n, r):

#     return (fact(n) // (fact(r)
#                 * fact(n - r)))

# Returns factorial of n
# def fact(n):

#     res = 1

#     for i in range(2, n+1):
#         res = res * i

#     return res
def primefactors(n):
    num=0

    while n % 2 == 0:
        num+=1
        n = n / 2

    for i in range(3,int(math.sqrt(n))+1,2):

        while n % i== 0:
            num+=1
            n = n // i

    if n > 2:
        num+=1
    return num
'''
def iter_ds(src):
    store=[src]
    while len(store):
        tmp=store.pop()
        if not vis[tmp]:
            vis[tmp]=True
            for j in ar[tmp]:
                store.append(j)
'''
def ask(a,b,c):
    # print('? 1 {}'.format(a),flush=True)
    print(c,a,b,flush=True)
    n=I()

    return n
def linear_sieve(n):
    is_composite=[False]*n
    prime=[]
    for i in range(2,n):
        if not is_composite[i]:
            prime.append(i)
        for j in prime:
            is_composite[i*j]=True
            if i%prime==0:
                break
    return prime

def dfs(i,p,d):

    a,tmp=0,0
    for j in d[i]:
        if j!=p:
            a+=1
            tmp+=dfs(j,i)

    if a==0:
        return 0

    return tmp/a + 1
def primeFactors(n):
    l=[]

    while n % 2 == 0:
        l.append(2)
        n = n // 2
    for i in range(3,int(math.sqrt(n))+1,2):

        while n % i== 0:
            l.append(i)
            n = n // i

    if n > 2:
        l.append(n)
    return l

def binpow(a,b,c=MOD):
    res=1
    a=a%c
    while b>0:
        if b&1:
            res=(res*a)%c

        b=b>>1
        a = (a*a)%c

    return res

#  Sieve
d=[]
primes=[]
prim=[0]*(10**5+1)
def sieve(n):

    for i in range(n):
        d.append(i)

    for i in range(2,n):

        if d[i]==i:
            prim[i]=1
            primes.append(i)
        j=0
        while j<len(primes) and primes[j]<=d[i] and primes[j]*i<n:

            d[i * primes[j]] = primes[j]
            j+=1

def primeFactors(n):
    factors=[]
    while n!=1:
        factors.append(d[n])
        n//=d[n]

    return factors

fact=[0 for _ in range(501)]
def prefact():
    fact[0]=1
    fact[1]=1
    for i in range(2,501):
        fact[i]=fact[i-1]*i

dp=[[-1 for i in range(501)] for j in range(501)]
def nCr(n, r):
    return (fact[n]//(fact[r]*fact[n-r]))%MOD

def fun(n, x):

    if n==0:
        return 1
    if x<n:
        return binpow(x,n,MOD)
    if dp[n][x]!=-1:
        return dp[n][x]
    curr=0;
    for i in range(n+1):
        if i == n-1:
            continue
        curr+= ((nCr(n,i)*binpow(n-1,i,MOD))%MOD * fun(n-i,x-n+1))%MOD

        curr%=MOD

    dp[n][x]=curr

    return curr

t = 1
# t = I()
for _ in range(t):
    n,x=lint()
    prefact()

    fun(n,x)
    print(dp[n][x])


import sys
sys.setrecursionlimit(600)

M = 998244353

MAXNUM = 512
factor = [1]*(MAXNUM+2)
factor[-1]=0

for i in range(1,MAXNUM+1):
    factor[i] = (factor[i-1]*i)%M

def fastfrac(a,b):
    numb = pow(b,M-2,M)
    return ((a%M)*(numb%M))%M

def comb(n,k):
    if n<k: return 0
    if n==k: return 1
    num1 = factor[n]
    num2 = factor[k]
    num3 = factor[n-k]
    num = (num2*num3)%M
    return fastfrac(num1,num)

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

store = [[0 for j in range(n+1)] for i in range(n+1)]

for p in range(n+1):
    for q in range(n+1):
        store[p][q] = pow(p,q,M)

dic = {}
def getnext(restn,restx):

    if (restn,restx) in dic:  return dic[(restn,restx)]
    if restn==2:  return restx

    if restx < restn:
        return store[restx][restn]

    output = store[restn-1][restn]
    for sub in range(2,restn+1):
        temp = getnext(sub,restx-(restn-1))*comb(restn,sub) % M
        temp *= store[restn-1][restn-sub]
        output += temp

        output = output % M

    dic[(restn,restx)] = output
    return output

ans = getnext(n,x)

print(ans)


import sys
sys.setrecursionlimit(600)

M = 998244353

MAXNUM = 512
factor = [1]*(MAXNUM+2)
factor[-1]=0

for i in range(1,MAXNUM+1):
    factor[i] = (factor[i-1]*i)%M

def fastfrac(a,b):
    numb = pow(b,M-2,M)
    return ((a%M)*(numb%M))%M

def comb(n,k):
    if n<k: return 0
    if n==k: return 1
    num1 = factor[n]
    num2 = factor[k]
    num3 = factor[n-k]
    num = (num2*num3)%M
    return fastfrac(num1,num)

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

store = [[0 for j in range(n+1)] for i in range(n+1)]

for p in range(n+1):
    for q in range(n+1):
        store[p][q] = pow(p,q,M)

dic = {}

def getnext(restn,restx):
    index = restn*(x+1) + restx

    if index in dic:  return dic[index]
    if restn==2:  return restx

    if restx < restn:
        return store[restx][restn]

    output = store[restn-1][restn]
    for sub in range(2,restn+1):
        temp = getnext(sub,restx-(restn-1))*comb(restn,sub) % M
        temp *= store[restn-1][restn-sub]
        output += temp%M

        output = output % M

    dic[index] = output
    return output

ans = getnext(n,x)

print(ans)


import sys
from functools import lru_cache

GAP = MOD = 998244353

# 阶乘
factorial_save = [1, 1]

for i in range(2, 11000):
    x = factorial_save[i - 1]
    x *= i
    x %= GAP
    factorial_save.append(x)

@lru_cache
def ncm1(n, m):
    '''组合数逆元取模'''
    a = factorial_save[n]
    b = pow(factorial_save[m], GAP - 2)
    c = pow(factorial_save[n-m], GAP - 2)
    return a * b * c % GAP

@lru_cache
def ncm2(n, m):
    '''组合数顺次取模'''
    if m * 2 > n:
        m = n - m
    r = 1
    for i in range(m):
        r *= (n - i) / (m - i)
    r = int(round(r))
    return r % GAP

@lru_cache
def ncm(n, m):
    '''组合数取模'''
    if n <= 400 or m <= 100 or n - m <= 100:
        return ncm2(n, m)
    return ncm1(n, m)

@lru_cache
def f(n, x):
    if n == 0:
        return 1
    if n == 1:
        return 0
    if n == 2:
        return x
    if x <= n - 1:
        return pow(x, n, MOD)
    res = 0
    for m in range(0, n + 1):
        res += ncm(n, m) * pow(n - 1, n - m, MOD) * f(m, x - n + 1)
        res %= MOD
    return res

n, x = [int(x) for x in sys.stdin.readline().strip().split(" ")]
print(f(n, x))


#include <bits/stdc++.h>
using namespace std;

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
typedef long long int ll;

ll dp[501][501] , n , x;
vector<ll> fact , facti;
ll mod = 998244353;

ll add(ll a , ll b){return ((a%mod) + (b%mod))%mod;}
ll mul(ll a , ll b){return ((a%mod) * (b%mod))%mod;}
ll sub(ll a , ll b){return (a - b + mod)%mod;}

ll power(ll n , ll x , ll mod){

    ll ans = 1;
    while(x){
        if(x & 1) ans = (ans * n)%mod;
        n = (n * n)%mod;
        x >>= 1;
    }
    return ans;
}

ll ncr(ll n , ll r){return mul(fact[n] , mul(facti[n - r] , facti[r]));}

ll solve(ll heroes , ll damage){

    if(heroes == 0) return 1;
    if(heroes == 1) return 0;
    if(damage >= x) return 0;

    if(dp[heroes][damage] != -1) dp[heroes][damage];

    ll ans = 0;
    for (ll i = 0;i <= heroes;++i){

        ll ways = ncr(heroes , i);
        ll value = power(min(x - damage , heroes - 1) , i , mod);

        ans += mul(ways * value , solve(heroes - i , damage + heroes - 1));

        ans %= mod;
    }

    dp[heroes][damage] = ans;
    return ans;

}

void answer(){

    cin >> n >> x;
    for (ll i = 0;i < n + 1;++i)
    for(ll j = 0;j < x + 1;++j)
    dp[i][j] = -1;

    cout << solve(n , 0) << '\n';

}

int main() {
    fastio;

    fact.push_back(1);
    facti.push_back(1);

    for (ll i=1;i < 501;++i){
        fact.push_back(mul(fact.back() , i));
        facti.push_back(power(fact.back() , mod - 2 , mod));
    }

    ll T = 1;
    for(ll t = 1;t <= T;++t){
    answer();
    }

	return 0;
}


n = int(input())
S = list(input())

def count_all(s):
    cnt=0
    l_cnt=1
    for c in s[1:]:
        if c==')':
            l_cnt-=1
        else:
            l_cnt+=1
        if l_cnt==0:
            cnt+=1
    return cnt
if S!=list('()'*(n//2)) and S!=list(')'+'()'*(n//2-1)+'('):
    print(n // 2)
    print(1, 1)
else:
    res=0
    l,r =1,1
    lc=rc=0

    for c in S:
        if c=="(":
            lc+=1
        else:
            rc+=1

    if lc==rc:
        for i in range(n):
            for j in range(i,n):
                ss=S[:]
                if ss[i]==ss[j]:
                    continue
                ss[i],ss[j]=ss[j],ss[i]
                t=0
                t_min=n
                m=0
                for k in range(n):
                    if ss[k]==")":
                        t-=1
                    else:
                        t+=1
                    if t<t_min:
                        t_min,m=t,k
                sss=ss[m+1:]+ss[:m+1]
                temp = count_all(sss)
                if temp>=res:
                    # print(sss)
                    res=temp
                    l,r=i+1,j+1
    print(res)
    print(l,r)


n = int(input().strip())
s= input().strip()
ss= 0
mina = 0
ti = 0
for k in range(len(s)):
    if(s[k] == "("):
        ss+=1
    else:
        ss-=1
    if(ss<0):
        ti = k+1
        ss = 0
s=s[ti:]+s[:ti]
print(s)
ss= 0
for k in range(len(s)):
    if(s[k] == "("):
        ss+=1
    else:
        ss-=1
    if(ss<0):
        print(0)
        print(1,1)
        break
else:
    if(ss == 0):
      pre=[0 for k in range(len(s))]
      for k  in range(len(s)):
          if (s[k] == "("):
              ss += 1
          else:
              ss -= 1
          pre[k] = ss
      tt = 0
      a =(1,1)
      for k in range(0,len(s)):
          if(pre[k] == 0):
              tt+=1
      maxi= tt
      g =0
      gg =0
      while(gg<len(s)):
          if(pre[gg] == 0):
                  if(gg != g+1):
                      yy = g+1
                      y = g+1
                      q = 0
                      while(yy<gg):
                          if(pre[yy] == 1):
                              if(yy !=y+1):
                                  rr = y+1
                                  r  = y+1
                                  h = 0
                                  while(rr<yy):
                                      if(pre[rr] == 2):
                                          h+=1
                                      rr+=1

                                  if(tt+h+1>maxi):
                                      maxi = tt + h + 1
                                      a=(y,yy)
                              q+=1
                              y = yy+1
                              yy = y
                          else:
                              yy+=1

                      if (q + 1 > maxi):
                          maxi = q+1
                          a = (g, gg)
                  g= gg+1
                  gg= g
          else:
               gg+=1
      print(maxi)
      print((a[0]+ti)%len(s)+1,(a[1]+ti)%len(s)+1)

    else:
        print(0)
        print(1,1)


"""
NTC here
"""
from sys import stdin, setrecursionlimit
setrecursionlimit(10**7)

def iin(): return int(stdin.readline())

def lin(): return list(map(int, stdin.readline().split()))

# range = xrange
# input = raw_input

def bcheck(a,l,r):
    if a[l]==a[r]:return -1
    a1=a[:]
    a1[l],a1[r]=a1[r],a1[l]
    N=len(a)
    p,n=[],[]
    for i in range(N):
        if a1[i]==')':
            if p:
                p.pop()
            else:
                n.append(i)
        else:
            p.append(i)
    l=len(p)
    rt=0
    if l>0:
        rt=n[-1]+1
    if rt:
        a1=a1[rt:]+a1[:rt]
    ch,pt=0,0
    for i in a1:
        if i=='(':
            pt+=1
        else:
            pt-=1
        if pt==0:ch+=1
    #print(a1,ch)

    return ch

def main():
    N=iin()
    a=list(input())
    c1,c2=a.count(')'),a.count('(')
    if c1!=c2 or N%2:
        print(0)
        print(1,1)
    else:
        mx=[-1,0,0]
     #   print(a)
        for i in range(N):
            for j in range(i+1,N):
                if a[i]!=a[j]:
                    val=bcheck(a,i,j)
                    if mx[0]<val:
                        mx=[val,i,j]
      #  print(a)
        print(mx[0])
        print(mx[1]+1,mx[2]+1)

main()
# try:
#     main()
# except Exception as e: print(e)


# import cProfile
def prefix(s):
    count = 0
    cur = 0
    m = 0
    for c in s:
        if c == '(':
            cur += 1
        else:
            cur -= 1
        if cur < m:
            m = cur
            count = 0
        if cur == m:
            count += 1
    return count

n = int(input())
s = list(input())
if n % 2 == 0:
    a, b, c = -1, -1, -1
    for l in range(n):
        for r in range(l, n):
            s[l], s[r] = s[r], s[l]
            abc = prefix(s)
            if abc > a:
                a = abc
                b = l
                c = r
            s[l], s[r] = s[r], s[l]
    print (a)
    print (b + 1, c + 1)
else:
    print (0)
    print (1, 1)


#!/usr/bin/env python3
import sys

#lines = stdin.readlines()
def rint():
    return map(int, sys.stdin.readline().split())

def input():
    return sys.stdin.readline().rstrip('\n')

def oint():
    return int(input())

n = oint()
stemp  = input()
s = []
for i in range(n):
    if stemp[i] == '(':
        s.append(1)
    else:
        s.append(-1)

maxcnt = 0
candi = [0, 0]
for l in range(n):
    for r in range(l, n):
        cnt = 0
        s[l], s[r] = s[r], s[l]
        ssum = [0]*n
        ssum[0] = s[0]
        for i in range(1, n):
            ssum[i] = ssum[i-1] + s[i]

        minssum = min(ssum)
        if ssum[n-1] != 0:
            continue

        for i in range(1, n):
            if ssum[i] == minssum:
                cnt += 1
        if maxcnt < cnt:
            candi = [r, l]
            maxcnt = cnt
        s[l], s[r] = s[r], s[l]
print(maxcnt)
print(candi[0]+1, candi[1]+1)


l, r = map(int, raw_input().split(' ').strip())

ans = 0

int cnt = 31
for i in xrange(cnt):
    for j in xrange(cnt):
        cur = 2 ** i * 3 ** j
        if l <= cur and cur <= r:
            ans += 1

print ans


# Идея решения взята отсюда[https://rep.bntu.by/bitstream/handle/data/47746/Metod_predvaritelnyh_vychislenij_dlya_resheniya_zadach_po_informatike.pdf?sequence=1 <- google:‘"количество 2-3-чисел на отрезке"’]

limit = 2000*1000*1000

powers_of_2 = []
i = 0
while True:
    p = 2 ** i
    if p > limit:
        break
    powers_of_2.append(p)
    i += 1

powers_of_3 = []
i = 0
while True:
    p = 3 ** i
    if p > limit:
        break
    powers_of_3.append(p)
    i += 1

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

n = 0
for i in powers_of_2:
    for j in powers_of_3:
        if l <= i * j <= r:
            n += 1
print(n)


# coding=utf-8
# Идея решения взята отсюда[https://rep.bntu.by/bitstream/handle/data/47746/Metod_predvaritelnyh_vychislenij_dlya_resheniya_zadach_po_informatike.pdf?sequence=1 <- google:‘"количество 2-3-чисел на отрезке"’]

limit = 2000*1000*1000

powers_of_2 = []
i = 0
while True:
    p = 2 ** i
    if p > limit:
        break
    powers_of_2.append(p)
    i += 1

powers_of_3 = []
i = 0
while True:
    p = 3 ** i
    if p > limit:
        break
    powers_of_3.append(p)
    i += 1

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

n = 0
for i in powers_of_2:
    for j in powers_of_3:
        if l <= i * j <= r:
            n += 1
print(n)


def pow_mod(a,sup,m):
	ans = 1
	while sup > 0:
		if sup & 1: ans = (ans*a) % m
		a = a*a % m
		sup >>= 1
	return ans

a, b, p, x = [int(t) for t in raw_input().split()]
inv = [0] * p
ans = 0
for i in xrange(1,p):
	w = pow(a,i,p)
	r, s = (p-1)*w%p, (b-i*w)%p
	if r == 0:
		if s:
			ans += x/(p-1)
			if x%(p-1)>=i:
				ans += 1
		#print i, ans, r, s, 'a'
		break
	if not inv[r]:
		inv[r] = pow_mod(r, p-2, p)
		inv[inv[r]] = r
	k = s*inv[r]%p
	y = (x-i-k*(p-1))/(p*(p-1))
	if y >= 0:
		ans += y+1
	#print i, ans, r, s, 'b', k
print ans


def reversive(number, modulo):
    return pow(number, modulo - 2, modulo)

def congr(a, b, p, x):
    c = [list() for i in range(p + 1)]
    for i in range(0, p - 1):
        c[pow(a, i, p)].append(i)
    s = 0
    for n1 in range(1, p):
        k = reversive(n1, p) * b % p
        for j in range(len(c[k])):
            n2 = c[k][j]
            y0 = n1
            y1 = ((n2 - n1) + p - 1) % (p - 1)
            n = y0 + y1 * p
            s += (x - n + (p - 1) * p) // ((p - 1) * p)
    return s

a, b, p, x = [int(j) for j in input().split()]
print(congr(a, b, p, x))


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

def brute(a,b,p,x):
    for n in range(1, x+1):
        if (n*pow(a,n,p)) % p == b:
            print(n)

#brute(a,b,p,x)

sols = 0

inva = pow(a,p-2,p)

a2 = 1
b2 = b
s = 0
d1 = -b
while s < p-1:
    k = (d1 + s) % p
    u = k
    while (p-1)*u + s <= x:
        n = (p-1)*u + s
        #print(s, k, n)
        #print(n*pow(a,n,p) % p, b)
        sols += 1
        u += p
    d1 = (d1 * inva) % p
    s += 1

print(sols)


def egcd(a, b):
    if b == 0:
        return 1, 0, a
    x1, y1, c = egcd(b, a % b)
    return y1, x1 - (a / b) * y1, c

def crt(a0, n0, a1, n1):
    if min(n0, n1) < 0:
        return 0, -1
    x, y, g = egcd(n0, n1)
    if (a0 - a1) % g:
        return 0, -1
    x *= (a1 - a0) / g
    y *= (a1 - a0) / g
    k = n1 * n0 / g
    return (n0 * x + a0) % k, k

a, b, p, x = map(int, raw_input().split())
ans = 0
for i in range(p - 1):
    a1 = pow(a, i * (p - 2), p) * b
    a0, n0 = crt(a1, p, i, p - 1)
    if x >= a0:
        ans += 1 + (x - a0) / n0
print(ans)


#!/usr/bin/env python3

import sys
import traceback

class Input(object):
    def __init__(self):
        self.fh = sys.stdin

    def next_line(self):
        while True:
            line = sys.stdin.readline()
            if line == '\n':
                continue
            return line

    def next_line_ints(self):
        line = self.next_line()
        return [int(x) for x in line.split()]

    def next_line_strs(self):
        line = self.next_line()
        return line.split()

def get_dist(p1, p2):
    return abs(p1[0] - p2[0]) + abs(p1[1] - p2[1])

def calculate_finish_cost(dp_reach, points):
    """ Return dp_finish of this level. """
    if len(points) == 1:
        return dp_reach
    round_cost = get_dist(points[0], points[-1])
    # dp_finish = min(2 * round_cost + (dp[p1] - dist)). omit 2 * round_cost for now.
    dp_finish = dp_reach[:]
    min_diff = dp_reach[0]
    for i in range(1, len(points)):
        min_diff = min(min_diff - get_dist(points[i], points[i-1]), dp_reach[i])
        dp_finish[i] = min(min_diff, dp_finish[i])
    min_diff = dp_reach[-1]
    for i in range(len(points) - 2, -1, -1):
        min_diff = min(min_diff - get_dist(points[i], points[i+1]), dp_reach[i])
        dp_finish[i] = min(min_diff, dp_finish[i])
    return [x + 2 * round_cost for x in dp_finish]

def calculate_reach_cost(dp_finish, from_points, to_points):
    """calculate from dp_finish of current level to the dp_reach of the next level."""
    from_k = [y/max(x, 0.5) for x, y in from_points]
    to_k = [y/max(x, 0.5) for x, y in to_points]
    dp_reach = []
    from_index = 0
    for i in range(len(to_points)):
        while from_index + 1 < len(from_points) and from_k[from_index + 1] > to_k[i]:
            from_index += 1
        dp = dp_finish[from_index] + get_dist(from_points[from_index], to_points[i])
        if from_index + 1 < len(from_points):
            dp = min(dp, dp_finish[from_index + 1] + get_dist(from_points[from_index + 1], to_points[i]))
        dp_reach.append(dp)
    return dp_reach

def get_min_dist(points):
    # 1. split points into levels, sort points in each level in x increase, y decrease order.
    level_dict = {}
    for point in points:
        level = max(point[0], point[1])
        if level in level_dict:
            level_dict[level].append(point)
        else:
            level_dict[level] = [point]
    level_points = []
    for level in sorted(level_dict.keys()):
        p = level_dict[level]
        level_points.append(sorted(p, key=lambda x: x[0] - x[1]))

    # 2. calculate the min cost to reach a level at a point.
    #    calculate the min cost to finish a level at a point.
    dp_reach = []
    for p in level_points[0]:
        dp_reach.append(p[0] + p[1])
        dp_finish = calculate_finish_cost(dp_reach, level_points[0])
    for i in range(len(level_points) - 1):
        from_points = level_points[i]
        to_points = level_points[i + 1]
        dp_reach = calculate_reach_cost(dp_finish, from_points, to_points)
        dp_finish = calculate_finish_cost(dp_reach, to_points)

    # 3. the result is to finish at any points at the last level.
    return min(dp_finish)

def main():
    input = Input()
    while True:
        try:
            nums = input.next_line_ints()
            if not nums:
                break
            n = nums[0]
            points = []
            for _ in range(n):
                x, y = input.next_line_ints()
                points.append((x, y))
        except:
            print('read input failed')
        try:
            min_dist = get_min_dist(points)
        except:
            traceback.print_exc(file=sys.stdout)
            print('get_min_dist failed')
        print("{}".format(min_dist))

main()


#!/usr/bin/env python3

import sys
import traceback

class Input(object):
    def __init__(self):
        self.fh = sys.stdin

    def next_line(self):
        while True:
            line = sys.stdin.readline()
            if line == '\n':
                continue
            return line

    def next_line_ints(self):
        line = self.next_line()
        return [int(x) for x in line.split()]

    def next_line_strs(self):
        line = self.next_line()
        return line.split()

def get_dist(p1, p2):
    return abs(p1[0] - p2[0]) + abs(p1[1] - p2[1])

def calculate_finish_cost(dp_reach, points):
    """ Return dp_finish of this level. """
    assert len(dp_reach) == len(points)
    if len(points) == 1:
        return dp_reach
    round_cost = get_dist(points[0], points[-1])
    # dp_finish = min(2 * round_cost + (dp[p1] - dist)). omit 2 * round_cost for now.
    dp_finish = dp_reach[:]
    min_diff = dp_reach[0]
    for i in range(1, len(points)):
        min_diff = min(min_diff - get_dist(points[i], points[i-1]), dp_reach[i])
        dp_finish[i] = min(min_diff, dp_finish[i])
    min_diff = dp_reach[-1]
    for i in range(len(points) - 2, -1, -1):
        min_diff = min(min_diff - get_dist(points[i], points[i+1]), dp_reach[i])
        dp_finish[i] = min(min_diff, dp_finish[i])
    assert len(dp_finish) == len(points)
    return [x + 2 * round_cost for x in dp_finish]

def calculate_reach_cost(dp_finish, from_points, to_points):
    """calculate from dp_finish of current level to the dp_reach of the next level."""
    assert len(dp_finish) == len(from_points)
    from_k = [y/max(x, 0.5) for x, y in from_points]
    to_k = [y/max(x, 0.5) for x, y in to_points]
    dp_reach = []
    from_index = 0
    for i in range(len(to_points)):
        while from_index + 1 < len(from_points) and from_k[from_index + 1] > to_k[i]:
            from_index += 1
        dp = dp_finish[from_index] + get_dist(from_points[from_index], to_points[i])
        if from_index + 1 < len(from_points):
            dp = min(dp, dp_finish[from_index + 1] + get_dist(from_points[from_index + 1], to_points[i]))
        dp_reach.append(dp)
    assert len(dp_reach) == len(to_points)
    return dp_reach

def get_min_dist(points):
    # 1. split points into levels, sort points in each level in x increase, y decrease order.
    level_dict = {}
    for point in points:
        level = max(point[0], point[1])
        if level in level_dict:
            level_dict[level].append(point)
        else:
            level_dict[level] = [point]
    level_points = []
    for level in sorted(level_dict.keys()):
        p = level_dict[level]
        level_points.append(sorted(p, key=lambda x: x[0] - x[1]))

    # 2. calculate the min cost to reach a level at a point.
    #    calculate the min cost to finish a level at a point.
    dp_reach = []
    for p in level_points[0]:
        dp_reach.append(p[0] + p[1])
        dp_finish = calculate_finish_cost(dp_reach, level_points[0])
    for i in range(len(level_points) - 1):
        from_points = level_points[i]
        to_points = level_points[i + 1]
        dp_reach = calculate_reach_cost(dp_finish, from_points, to_points)
        dp_finish = calculate_finish_cost(dp_reach, to_points)

    # 3. the result is to finish at any points at the last level.
    return min(dp_finish)

def main():
    input = Input()
    while True:
        try:
            nums = input.next_line_ints()
            if not nums:
                break
            n = nums[0]
            points = []
            for _ in range(n):
                x, y = input.next_line_ints()
                points.append((x, y))
        except:
            print('read input failed')
        try:
            min_dist = get_min_dist(points)
        except:
            traceback.print_exc(file=sys.stdout)
            print('get_min_dist failed')
        print("{}".format(min_dist))

main()


#!/usr/bin/env python3

import sys

class Input(object):
    def __init__(self):
        self.fh = sys.stdin

    def next_line(self):
        while True:
            line = sys.stdin.readline()
            if line == '\n':
                continue
            return line

    def next_line_ints(self):
        line = self.next_line()
        return [int(x) for x in line.split()]

    def next_line_strs(self):
        line = self.next_line()
        return line.split()

def get_dist(p1, p2):
    return abs(p1[0] - p2[0]) + abs(p1[1] - p2[1])

def calculate_finish_cost(dp_reach, points):
    """ Return dp_finish of this level. """
    if len(points) == 1:
        return dp_reach
    round_cost = get_dist(points[0], points[-1])
    # dp_finish = min(2 * round_cost + (dp[p1] - dist)). omit 2 * round_cost for now.
    dp_finish = dp_reach[:]
    min_diff = dp_reach[0]
    for i in range(1, len(points)):
        min_diff = min(min_diff - get_dist(points[i], points[i-1]), dp_reach[i])
        dp_finish[i] = min(min_diff, dp_finish[i])
    min_diff = dp_reach[-1]
    for i in range(len(points) - 2, -1, -1):
        min_diff = min(min_diff - get_dist(points[i], points[i+1]), dp_reach[i])
        dp_finish[i] = min(min_diff, dp_finish[i])
    return [x + 2 * round_cost for x in dp_finish]

def calculate_reach_cost(dp_finish, from_points, to_points):
    """calculate from dp_finish of current level to the dp_reach of the next level."""
    from_k = [y/max(x, 0.5) for x, y in from_points]
    to_k = [y/max(x, 0.5) for x, y in to_points]
    dp_reach = []
    from_index = 0
    for i in range(len(to_points)):
        while from_index + 1 < len(from_points) and from_k[from_index + 1] > to_k[i]:
            from_index += 1
        dp = dp_finish[from_index] + get_dist(from_points[from_index], to_points[i])
        if from_index + 1 < len(from_points):
            dp = min(dp, dp_finish[from_index + 1] + get_dist(from_points[from_index + 1], to_points[i]))
        dp_reach.append(dp)
    return dp_reach

def get_min_dist(points):
    # 1. split points into levels, sort points in each level in x increase, y decrease order.
    level_dict = {}
    for point in points:
        level = max(point[0], point[1])
        if level in level_dict:
            level_dict[level].append(point)
        else:
            level_dict[level] = [point]
    level_points = []
    for level in sorted(level_dict.keys()):
        p = level_dict[level]
        level_points.append(sorted(p, key=lambda x: x[0] - x[1]))

    # 2. calculate the min cost to reach a level at a point.
    #    calculate the min cost to finish a level at a point.
    dp_reach = []
    for p in level_points[0]:
        dp_reach.append(p[0] + p[1])
        dp_finish = calculate_finish_cost(dp_reach, level_points[0])
    for i in range(len(level_points) - 1):
        from_points = level_points[i]
        to_points = level_points[i + 1]
        dp_reach = calculate_reach_cost(dp_finish, from_points, to_points)
        dp_finish = calculate_finish_cost(dp_reach, to_points)

    # 3. the result is to finish at any points at the last level.
    return min(dp_finish)

def main():
    input = Input()
    while True:
        nums = input.next_line_ints()
        if not nums:
            break
        n = nums[0]
        points = []
        for _ in range(n):
            x, y = input.next_line_ints()
            points.append((x, y))
        min_dist = get_min_dist(points)
        print("{}".format(min_dist))

main()


#!/usr/bin/env python3

import sys

class Input(object):
    def __init__(self):
        self.fh = sys.stdin

    def next_line(self):
        while True:
            line = sys.stdin.readline()
            if line == '\n':
                continue
            return line

    def next_line_ints(self):
        line = self.next_line()
        return [int(x) for x in line.split()]

    def next_line_strs(self):
        line = self.next_line()
        return line.split()

def get_dist(p1, p2):
    return abs(p1[0] - p2[0]) + abs(p1[1] - p2[1])

def calculate_finish_cost(dp_reach, points):
    """ Return dp_finish of this level. """
    if len(points) == 1:
        return dp_reach
    round_cost = get_dist(points[0], points[-1])
    # dp_finish = min(2 * round_cost + (dp[p1] - dist)). omit 2 * round_cost for now.
    dp_finish = dp_reach[:]
    min_diff = dp_reach[0]
    for i in range(1, len(points)):
        min_diff = min(min_diff - get_dist(points[i], points[i-1]), dp_reach[i])
        dp_finish[i] = min(min_diff, dp_finish[i])
    min_diff = dp_reach[-1]
    for i in range(len(points) - 2, -1, -1):
        min_diff = min(min_diff - get_dist(points[i], points[i+1]), dp_reach[i])
        dp_finish[i] = min(min_diff, dp_finish[i])
    return [x + 2 * round_cost for x in dp_finish]

def calculate_reach_cost(dp_finish, from_points, to_points):
    """calculate from dp_finish of current level to the dp_reach of the next level."""
    from_k = [y/max(x, 0.5) for x, y in from_points]
    to_k = [y/max(x, 0.5) for x, y in to_points]
    dp_reach = []
    from_index = 0
    for i in range(len(to_points)):
        while from_index + 1 < len(from_points) and from_k[from_index + 1] > to_k[i]:
            from_index += 1
        dp = dp_finish[from_index] + get_dist(from_points[from_index], to_points[i])
        if from_index + 1 < len(from_points):
            dp = min(dp, dp_finish[from_index + 1] + get_dist(from_points[from_index + 1], to_points[i]))
        dp_reach.append(dp)
    return dp_reach

def get_min_dist(points):
    # 1. split points into levels, sort points in each level in x increase, y decrease order.
    level_dict = {}
    for point in points:
        level = max(point[0], point[1])
        if level in level_dict:
            level_dict[level].append(point)
        else:
            level_dict[level] = [point]
    level_points = []
    for level in sorted(level_dict.keys()):
        p = level_dict[level]
        level_points.append(sorted(p, key=lambda x: x[0] - x[1]))

    # 2. calculate the min cost to reach a level at a point.
    #    calculate the min cost to finish a level at a point.
    dp_reach = []
    for p in level_points[0]:
        dp_reach.append(p[0] + p[1])
        dp_finish = calculate_finish_cost(dp_reach, level_points[0])
    for i in range(len(level_points) - 1):
        from_points = level_points[i]
        to_points = level_points[i + 1]
        dp_reach = calculate_reach_cost(dp_finish, from_points, to_points)
        dp_finish = calculate_finish_cost(dp_reach, to_points)

    # 3. the result is to finish at any points at the last level.
    return min(dp_finish)

def main():
    input = Input()
    while True:
        try:
            nums = input.next_line_ints()
            if not nums:
                break
            n = nums[0]
            points = []
            for _ in range(n):
                x, y = input.next_line_ints()
                points.append((x, y))
        except:
            print('read input failed')
        try:
            min_dist = get_min_dist(points)
        except:
            print('get_min_dist failed')
        print("{}".format(min_dist))

main()


n = int(input())
print(n)
for _ in range(n):
	print(1, end = ' ')


from sys import stdin,stdout,setrecursionlimit,maxint,exit
#setrecursionlimit(10**5)
def listInput():
 return map(long,stdin.readline().split())
def printBS(li):
 for i in xrange(len(li)-1):
  stdout.write("%d "%li[i])
 stdout.write("%d\n"%li[-1])
def sin():
 return stdin.readline().rstrip()
def check(a,b,c,d):
 if (a[0]-b[0])*(a[1]-c[1])==(a[0]-c[0])*(a[1]-b[1]) or (a[0]-b[0])*(a[1]-d[1])==(a[1]-b[1])*(a[0]-d[0]):
  return False
 if b[0]-a[0]==c[0]-d[0] and b[1]-a[1]==c[1]-d[1]:
  return True
 elif c[0]-a[0]==b[0]-d[0] and c[1]-a[1]==b[1]-d[1]:
  return True
 elif c[0]-a[0]==d[0]-b[0] and c[1]-a[1]==d[1]-b[1]:
  return True
 return False
a=listInput()
b=listInput()
c=listInput()
M=1000
ans=[]
for i in xrange(-M,M+1):
 for j in xrange(-M,M+1):
  if (i,j) not in [a,b,c] and check(a,b,c,[i,j]):
   ans.append([i,j])
print len(ans)
for i,j in ans:
 stdout.write("%d %d\n"%(i,j))