Input:
#!usr/bin/env python3

from collections import defaultdict

from collections import deque

from heapq import heappush, heappop

import sys

import math

import bisect

import random

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

def I(): return int(sys.stdin.readline())

def LS():return list(map(list, sys.stdin.readline().split()))

def S(): return list(sys.stdin.readline())[:-1]

def IR(n):

    l = [None for i in range(n)]

    for i in range(n):l[i] = I()

    return l

def LIR(n):

    l = [None for i in range(n)]

    for i in range(n):l[i] = LI()

    return l

def SR(n):

    l = [None for i in range(n)]

    for i in range(n):l[i] = S()

    return l

def LSR(n):

    l = [None for i in range(n)]

    for i in range(n):l[i] = SR()

    return l

mod = 1000000007

#A

def A():

    return

#B

def B():

    return

#C

def C():

    n,m = LI()

    v = LIR(m)

    for i in range(m):

        v[i] = [v[i][0],v[i][1],i]

    v.sort(key = lambda x:x[1])

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

    ans = [None for i in range(m)]

    for p,y,i in v:

        f[p] += 1

        s = "{:0>6}".format(p)

        t = "{:0>6}".format(f[p])

        ans[i] = s+t

    for i in ans:

        print(i)

#D

def D():

    h,w,k = LI()

    dp = [[0 for i in range(w)] for j in range(h+1)]

    dp[0][0] = 1

    p = [1 for i in range(w+1)]

    for i in range(w):

        p[i+1] = p[i]*2

    l = [i for i in range(p[w-1])]

    i = 0

    while i < len(l):

        a = l[i]

        for j in range(w):

            if a&p[j] and a&p[j+1]:

                l.pop(i)

                i -= 1

                break

        i += 1

    for i in range(h):

        for j in range(w):

            a = 0

            b = 0

            c = 0

            for s in l:

                if 0 < j < w-1:

                    if p[j]&s:

                        c += 1

                    elif p[j-1]&s:

                        a += 1

                    else:

                        b += 1

                elif j == 0:

                    if p[j]&s:

                        c += 1

                    else:

                        b += 1

                else:

                    if p[j-1]&s:

                        a += 1

                    else:

                        b += 1

            dp[i+1][j] += b*dp[i][j]

            dp[i+1][j] %= mod

            if j > 0:

                dp[i+1][j-1] += a*dp[i][j]

                dp[i+1][j-1] %= mod

            if j < w-1:

                dp[i+1][j+1] += c*dp[i][j]

                dp[i+1][j+1] %= mod

    print((dp[h][k-1]))

#E

def E():

    return

#F

def F():

    return

#G

def G():

    return

#H

def H():

    return

#Solve

if __name__ == "__main__":

    D()

#!usr/bin/env python3

from collections import defaultdict

from collections import deque

from heapq import heappush, heappop

import sys

import math

import bisect

import random

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

def I(): return int(sys.stdin.readline())

def LS():return list(map(list, sys.stdin.readline().split()))

def S(): return list(sys.stdin.readline())[:-1]

def IR(n):

    l = [None for i in range(n)]

    for i in range(n):l[i] = I()

    return l

def LIR(n):

    l = [None for i in range(n)]

    for i in range(n):l[i] = LI()

    return l

def SR(n):

    l = [None for i in range(n)]

    for i in range(n):l[i] = S()

    return l

def LSR(n):

    l = [None for i in range(n)]

    for i in range(n):l[i] = SR()

    return l

mod = 1000000007

#A

def A():

    return

#B

def B():

    return

#C

def C():

    n,m = LI()

    v = LIR(m)

    for i in range(m):

        v[i] = [v[i][0],v[i][1],i]

    v.sort(key = lambda x:x[1])

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

    ans = [None for i in range(m)]

    for p,y,i in v:

        f[p] += 1

        s = "{:0>6}".format(p)

        t = "{:0>6}".format(f[p])

        ans[i] = s+t

    for i in ans:

        print(i)

#D

def D():

    h,w,k = LI()

    dp = [[0 for i in range(w)] for j in range(h+1)]

    dp[0][0] = 1

    p = [1 for i in range(w+1)]

    for i in range(w):

        p[i+1] = p[i]*2

    l = [i for i in range(p[w-1])]

    i = 0

    while i < len(l):

        a = l[i]

        for j in range(w):

            if a&p[j] and a&p[j+1]:

                l.pop(i)

                i -= 1

                break

        i += 1

    d = [[0 for i in range(3)] for j in range(w)]

    for j in range(w):

        for s in l:

            if 0 < j < w-1:

                if p[j]&s:

                    d[j][2] += 1

                elif p[j-1]&s:

                    d[j][0] += 1

                else:

                    d[j][1] += 1

            elif j == 0:

                if p[j]&s:

                    d[j][2] += 1

                else:

                    d[j][1] += 1

            else:

                if p[j-1]&s:

                    d[j][0] += 1

                else:

                    d[j][1] += 1

    for i in range(h):

        for j in range(w):

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

            dp[i+1][j] %= mod

            if j > 0:

                dp[i+1][j-1] += d[j][0]*dp[i][j]

                dp[i+1][j-1] %= mod

            if j < w-1:

                dp[i+1][j+1] += d[j][2]*dp[i][j]

                dp[i+1][j+1] %= mod

    print((dp[h][k-1]))

#E

def E():

    return

#F

def F():

    return

#G

def G():

    return

#H

def H():

    return

#Solve

if __name__ == "__main__":

    D()

#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random

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

def I():
    return int(sys.stdin.readline())

def LS():
    return list(map(list, sys.stdin.readline().split()))

def S():
    return list(sys.stdin.readline())[:-1]

def IR(n):
    l = [None for i in range(n)]
    for i in range(n):
        l[i] = I()
    return l

def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):
        l[i] = LI()
    return l

def SR(n):
    l = [None for i in range(n)]
    for i in range(n):
        l[i] = S()
    return l

def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):
        l[i] = SR()
    return l

mod = 1000000007
# A
def A():
    return

# B
def B():
    return

# C
def C():
    n, m = LI()
    v = LIR(m)
    for i in range(m):
        v[i] = [v[i][0], v[i][1], i]
    v.sort(key=lambda x: x[1])
    f = [0 for i in range(n + 1)]
    ans = [None for i in range(m)]
    for p, y, i in v:
        f[p] += 1
        s = "{:0>6}".format(p)
        t = "{:0>6}".format(f[p])
        ans[i] = s + t
    for i in ans:
        print(i)

# D
def D():
    h, w, k = LI()
    dp = [[0 for i in range(w)] for j in range(h + 1)]
    dp[0][0] = 1
    p = [1 for i in range(w + 1)]
    for i in range(w):
        p[i + 1] = p[i] * 2
    l = [i for i in range(p[w - 1])]
    i = 0
    while i < len(l):
        a = l[i]
        for j in range(w):
            if a & p[j] and a & p[j + 1]:
                l.pop(i)
                i -= 1
                break
        i += 1
    for i in range(h):
        for j in range(w):
            a = 0
            b = 0
            c = 0
            for s in l:
                if 0 < j < w - 1:
                    if p[j] & s:
                        c += 1
                    elif p[j - 1] & s:
                        a += 1
                    else:
                        b += 1
                elif j == 0:
                    if p[j] & s:
                        c += 1
                    else:
                        b += 1
                else:
                    if p[j - 1] & s:
                        a += 1
                    else:
                        b += 1
            dp[i + 1][j] += b * dp[i][j]
            dp[i + 1][j] %= mod
            if j > 0:
                dp[i + 1][j - 1] += a * dp[i][j]
                dp[i + 1][j - 1] %= mod
            if j < w - 1:
                dp[i + 1][j + 1] += c * dp[i][j]
                dp[i + 1][j + 1] %= mod
    print((dp[h][k - 1]))

# E
def E():
    return

# F
def F():
    return

# G
def G():
    return

# H
def H():
    return

# Solve
if __name__ == "__main__":
    D()

#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random

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

def I():
    return int(sys.stdin.readline())

def LS():
    return list(map(list, sys.stdin.readline().split()))

def S():
    return list(sys.stdin.readline())[:-1]

def IR(n):
    l = [None for i in range(n)]
    for i in range(n):
        l[i] = I()
    return l

def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):
        l[i] = LI()
    return l

def SR(n):
    l = [None for i in range(n)]
    for i in range(n):
        l[i] = S()
    return l

def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):
        l[i] = SR()
    return l

mod = 1000000007
# A
def A():
    return

# B
def B():
    return

# C
def C():
    n, m = LI()
    v = LIR(m)
    for i in range(m):
        v[i] = [v[i][0], v[i][1], i]
    v.sort(key=lambda x: x[1])
    f = [0 for i in range(n + 1)]
    ans = [None for i in range(m)]
    for p, y, i in v:
        f[p] += 1
        s = "{:0>6}".format(p)
        t = "{:0>6}".format(f[p])
        ans[i] = s + t
    for i in ans:
        print(i)

# D
def D():
    h, w, k = LI()
    dp = [[0 for i in range(w)] for j in range(h + 1)]
    dp[0][0] = 1
    p = [1 for i in range(w + 1)]
    for i in range(w):
        p[i + 1] = p[i] * 2
    l = [i for i in range(p[w - 1])]
    i = 0
    while i < len(l):
        a = l[i]
        for j in range(w):
            if a & p[j] and a & p[j + 1]:
                l.pop(i)
                i -= 1
                break
        i += 1
    d = [[0 for i in range(3)] for j in range(w)]
    for j in range(w):
        for s in l:
            if 0 < j < w - 1:
                if p[j] & s:
                    d[j][2] += 1
                elif p[j - 1] & s:
                    d[j][0] += 1
                else:
                    d[j][1] += 1
            elif j == 0:
                if p[j] & s:
                    d[j][2] += 1
                else:
                    d[j][1] += 1
            else:
                if p[j - 1] & s:
                    d[j][0] += 1
                else:
                    d[j][1] += 1
    for i in range(h):
        for j in range(w):
            dp[i + 1][j] += d[j][1] * dp[i][j]
            dp[i + 1][j] %= mod
            if j > 0:
                dp[i + 1][j - 1] += d[j][0] * dp[i][j]
                dp[i + 1][j - 1] %= mod
            if j < w - 1:
                dp[i + 1][j + 1] += d[j][2] * dp[i][j]
                dp[i + 1][j + 1] %= mod
    print((dp[h][k - 1]))

# E
def E():
    return

# F
def F():
    return

# G
def G():
    return

# H
def H():
    return

# Solve
if __name__ == "__main__":
    D()

+    d = [[0 for i in range(3)] for j in range(w)]


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

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

cont = 0

for e in lista:

    aux = e

    while(aux%2 == 0):

        aux /= 2

        cont += 1

print(cont)

a = int(eval(input()))

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

ans=0

for i in lista:

  while i % 2==0:

    i = i / 2

    ans += 1

print(ans)

n1 = int(eval(input()))
lista = list(map(int, input().split()))
cont = 0
for e in lista:
    aux = e
    while aux % 2 == 0:
        aux /= 2
        cont += 1
print(cont)

a = int(eval(input()))
lista = list(map(int, input().split()))
ans = 0
for i in lista:
    while i % 2 == 0:
        i = i / 2
        ans += 1
print(ans)

-n1 = int(eval(input()))
+a = int(eval(input()))
-cont = 0
-for e in lista:
-    aux = e
-    while aux % 2 == 0:
-        aux /= 2
-        cont += 1
-print(cont)
+ans = 0
+for i in lista:
+    while i % 2 == 0:
+        i = i / 2
+        ans += 1
+print(ans)


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

C = {}

for _ in range(H):

    A = input().strip()

    for i in range(W):

        if A[i] not in C:

            C[A[i]] = 0

        C[A[i]] += 1

cnt4 = 0

cnt1 = 0

for a in C:

    if C[a]>=4:

        cnt4 += C[a]//4

        C[a] = C[a]%4

    if C[a]%2==1:

        cnt1 += 1

if cnt4<(W//2)*(H//2):

    flag = 0

else:

    if H%2==1 and W%2==1:

        if cnt1==1:

            flag = 1

        else:

            flag = 0

    else:

        if cnt1==0:

            flag = 1

        else:

            flag = 0

if flag==1:

    print("Yes")

else:

    print("No")

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

A = [input().strip() for _ in range(H)]

C = {chr(i):0 for i in range(97,123)}

for i in range(H):

    for j in range(W):

        C[A[i][j]] += 1

if H%2==0 and W%2==0:

    flag = 0

    for a in C:

        if C[a]%4!=0:

            flag = 1

            break

    if flag==0:

        print("Yes")

    else:

        print("No")

elif (H%2==0 and W%2==1) or (H%2==1 and W%2==0):

    n = (H//2)*(W//2)

    for a in C:

        if C[a]>=4:

            n -= C[a]//4

            C[a] = C[a]%4

    if n>0:

        print("No")

    else:

        flag = 0

        for a in C:

            if C[a]%2==1:

                flag=1

                break

        if flag==0:

            print("Yes")

        else:

            print("No")

else:

    n = (H//2)*(W//2)

    for a in C:

        if C[a]>=4:

            n -= C[a]//4

            C[a] = C[a]%4

    if n>0:

        print("No")

    else:

        cnt = 0

        for a in C:

            cnt += C[a]%2

        if cnt==1:

            print("Yes")

        else:

            print("No")

H, W = list(map(int, input().split()))
C = {}
for _ in range(H):
    A = input().strip()
    for i in range(W):
        if A[i] not in C:
            C[A[i]] = 0
        C[A[i]] += 1
cnt4 = 0
cnt1 = 0
for a in C:
    if C[a] >= 4:
        cnt4 += C[a] // 4
        C[a] = C[a] % 4
    if C[a] % 2 == 1:
        cnt1 += 1
if cnt4 < (W // 2) * (H // 2):
    flag = 0
else:
    if H % 2 == 1 and W % 2 == 1:
        if cnt1 == 1:
            flag = 1
        else:
            flag = 0
    else:
        if cnt1 == 0:
            flag = 1
        else:
            flag = 0
if flag == 1:
    print("Yes")
else:
    print("No")

H, W = list(map(int, input().split()))
A = [input().strip() for _ in range(H)]
C = {chr(i): 0 for i in range(97, 123)}
for i in range(H):
    for j in range(W):
        C[A[i][j]] += 1
if H % 2 == 0 and W % 2 == 0:
    flag = 0
    for a in C:
        if C[a] % 4 != 0:
            flag = 1
            break
    if flag == 0:
        print("Yes")
    else:
        print("No")
elif (H % 2 == 0 and W % 2 == 1) or (H % 2 == 1 and W % 2 == 0):
    n = (H // 2) * (W // 2)
    for a in C:
        if C[a] >= 4:
            n -= C[a] // 4
            C[a] = C[a] % 4
    if n > 0:
        print("No")
    else:
        flag = 0
        for a in C:
            if C[a] % 2 == 1:
                flag = 1
                break
        if flag == 0:
            print("Yes")
        else:
            print("No")
else:
    n = (H // 2) * (W // 2)
    for a in C:
        if C[a] >= 4:
            n -= C[a] // 4
            C[a] = C[a] % 4
    if n > 0:
        print("No")
    else:
        cnt = 0
        for a in C:
            cnt += C[a] % 2
        if cnt == 1:
            print("Yes")
        else:
            print("No")

+A = [input().strip() for _ in range(H)]

+C = {chr(i): 0 for i in range(97, 123)}


Input:
from sys import stdin

import math

import fractions

from collections import deque

from collections import Counter

import itertools

INF = 10 ** 10

N, M, X  = [int(x) for x in stdin.readline().rstrip().split()]

CA = [list(map(int, stdin.readline().rstrip().split())) for _ in range(N)]

knowledge_list = [[0 for _ in range(M)]]

money_list = [0]

for i in range(N):

    C = CA[i][0]

    A = CA[i][1:]

    # 購入する場合

    tmp2 = []

    for i, knowledge in enumerate(knowledge_list):

        tmp = []

        for k in range(len(knowledge)):

            tmp.append(knowledge[k] + A[k])

        tmp2.append(tmp)

        money_list.append(money_list[i]+C)

    knowledge_list = knowledge_list + tmp2

ans = INF

for i in range(len(money_list)):

    if min(knowledge_list[i]) >= X:

        ans = min(ans, money_list[i])

if ans != INF:

    print(ans)

else:

    print((-1))

from sys import stdin

import math

import fractions

from collections import deque

from collections import Counter

import itertools

INF = 10 ** 10

N, M, X  = [int(x) for x in stdin.readline().rstrip().split()]

CA = [list(map(int, stdin.readline().rstrip().split())) for _ in range(N)]

dp = [[[0 for _ in range(M)] for _ in range(4)] for _ in range(N+1)]

dp_money = [[0 for _ in range(2)] for _ in range(N+1)]

tm = [0 for _ in range(2**N)]

tl = [[0 for _ in range(M)] for _ in range(2**N)]

knowledge_list = [[0 for _ in range(M)]]

money_list = [0]

for i in range(N):

    C = CA[i][0]

    A = CA[i][1:]

    # 購入する場合

    tmp2 = []

    for i, knowledge in enumerate(knowledge_list):

        tmp = []

        for k in range(len(knowledge)):

            tmp.append(knowledge[k] + A[k])

        tmp2.append(tmp)

        money_list.append(money_list[i]+C)

    knowledge_list = knowledge_list + tmp2

ans = INF

for i in range(len(money_list)):

    if min(knowledge_list[i]) >= X:

        ans = min(ans, money_list[i])

if ans != INF:

    print(ans)

else:

    print((-1))

from sys import stdin
import math
import fractions
from collections import deque
from collections import Counter
import itertools

INF = 10**10
N, M, X = [int(x) for x in stdin.readline().rstrip().split()]
CA = [list(map(int, stdin.readline().rstrip().split())) for _ in range(N)]
knowledge_list = [[0 for _ in range(M)]]
money_list = [0]
for i in range(N):
    C = CA[i][0]
    A = CA[i][1:]
    # 購入する場合
    tmp2 = []
    for i, knowledge in enumerate(knowledge_list):
        tmp = []
        for k in range(len(knowledge)):
            tmp.append(knowledge[k] + A[k])
        tmp2.append(tmp)
        money_list.append(money_list[i] + C)
    knowledge_list = knowledge_list + tmp2
ans = INF
for i in range(len(money_list)):
    if min(knowledge_list[i]) >= X:
        ans = min(ans, money_list[i])
if ans != INF:
    print(ans)
else:
    print((-1))

from sys import stdin
import math
import fractions
from collections import deque
from collections import Counter
import itertools

INF = 10**10
N, M, X = [int(x) for x in stdin.readline().rstrip().split()]
CA = [list(map(int, stdin.readline().rstrip().split())) for _ in range(N)]
dp = [[[0 for _ in range(M)] for _ in range(4)] for _ in range(N + 1)]
dp_money = [[0 for _ in range(2)] for _ in range(N + 1)]
tm = [0 for _ in range(2**N)]
tl = [[0 for _ in range(M)] for _ in range(2**N)]
knowledge_list = [[0 for _ in range(M)]]
money_list = [0]
for i in range(N):
    C = CA[i][0]
    A = CA[i][1:]
    # 購入する場合
    tmp2 = []
    for i, knowledge in enumerate(knowledge_list):
        tmp = []
        for k in range(len(knowledge)):
            tmp.append(knowledge[k] + A[k])
        tmp2.append(tmp)
        money_list.append(money_list[i] + C)
    knowledge_list = knowledge_list + tmp2
ans = INF
for i in range(len(money_list)):
    if min(knowledge_list[i]) >= X:
        ans = min(ans, money_list[i])
if ans != INF:
    print(ans)
else:
    print((-1))

+dp = [[[0 for _ in range(M)] for _ in range(4)] for _ in range(N + 1)]

+dp_money = [[0 for _ in range(2)] for _ in range(N + 1)]

+tl = [[0 for _ in range(M)] for _ in range(2**N)]


Input:
def judge(a, i, m, n, v, p):

    if i <= p: return True

    if a[i-1] + m < a[p-1]: return False

    check = (p + n - i)*m

    for j in range(p, i):

        check += a[i-1] + m - a[j-1]

    return check >= m*v

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

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

a.sort(reverse=True)

ng = n + 1

ok = 0

while (ng - ok) > 1:

    mid = (ok + ng) // 2

    if judge(a, mid, m, n, v, p):

        ok = mid

    else:

        ng = mid

print(ok)

def judge(a, acc, i, m, n, v, p):

    if i <= p: return True

    if a[i-1] + m < a[p-1]: return False

    check = (p + n - i)*m + (a[i-1] + m)*(i - p) - (acc[i-2] - acc[p-2])

    return check >= m*v

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

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

a.sort(reverse=True)

acc = [0] * (n+1)

for i in range(n):

    acc[i] = a[0] if i == 0 else a[i] + acc[i-1]

ng = n + 1

ok = 0

while (ng - ok) > 1:

    mid = (ok + ng) // 2

    if judge(a, acc, mid, m, n, v, p):

        ok = mid

    else:

        ng = mid

print(ok)

def judge(a, i, m, n, v, p):
    if i <= p:
        return True
    if a[i - 1] + m < a[p - 1]:
        return False
    check = (p + n - i) * m
    for j in range(p, i):
        check += a[i - 1] + m - a[j - 1]
    return check >= m * v

n, m, v, p = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort(reverse=True)
ng = n + 1
ok = 0
while (ng - ok) > 1:
    mid = (ok + ng) // 2
    if judge(a, mid, m, n, v, p):
        ok = mid
    else:
        ng = mid
print(ok)

def judge(a, acc, i, m, n, v, p):
    if i <= p:
        return True
    if a[i - 1] + m < a[p - 1]:
        return False
    check = (p + n - i) * m + (a[i - 1] + m) * (i - p) - (acc[i - 2] - acc[p - 2])
    return check >= m * v

n, m, v, p = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort(reverse=True)
acc = [0] * (n + 1)
for i in range(n):
    acc[i] = a[0] if i == 0 else a[i] + acc[i - 1]
ng = n + 1
ok = 0
while (ng - ok) > 1:
    mid = (ok + ng) // 2
    if judge(a, acc, mid, m, n, v, p):
        ok = mid
    else:
        ng = mid
print(ok)

+    acc[i] = a[0] if i == 0 else a[i] + acc[i - 1]


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

csf = [tuple(map(int, input().split())) for _ in range(n - 1)]#csf

for i in range(n):

    #i:起点

    t = 0#駅jの出発時刻, 駅n（添え字n - 1）では、この時刻がprintされるので、初期値は0とする

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

        #j:乗車する区間

        c_j, s_j, f_j = csf[j]

        #駅jの出発時刻を求める

        if t < s_j:

            t = s_j

        elif t % f_j == 0:

            pass

            #t = t

        else:

            #始発より後に駅に到着し、駅で電車を待つ

            t += f_j - (t % f_j)

        t += c_j#乗車して次の駅に到着させる

    print(t)#駅n（添え字n - 1）の到着時刻

def main():

    from itertools import islice

    N = int(input())

    trains = []

    for _ in range(N - 1):

        c, s, f = map(int, input().split())

        trains.append((c, s, f))

    ans = [0] * N

    for i, (ci, si, fi) in enumerate(trains):

        curr = si + ci

        for j, (cj, sj, fj) in enumerate(islice(trains, i + 1, N, 1)):

            if curr < sj: curr = sj

            r = curr % fj

            if r != 0: curr += (fj - r)

            curr += cj

        ans[i] = curr

    print(*ans, sep='\n')

if __name__ == '__main__':

    main()

n = int(eval(input()))
csf = [tuple(map(int, input().split())) for _ in range(n - 1)]  # csf
for i in range(n):
    # i:起点
    t = 0  # 駅jの出発時刻, 駅n（添え字n - 1）では、この時刻がprintされるので、初期値は0とする
    for j in range(i, n - 1):
        # j:乗車する区間
        c_j, s_j, f_j = csf[j]
        # 駅jの出発時刻を求める
        if t < s_j:
            t = s_j
        elif t % f_j == 0:
            pass
            # t = t
        else:
            # 始発より後に駅に到着し、駅で電車を待つ
            t += f_j - (t % f_j)
        t += c_j  # 乗車して次の駅に到着させる
    print(t)  # 駅n（添え字n - 1）の到着時刻

def main():
    from itertools import islice

    N = int(input())
    trains = []
    for _ in range(N - 1):
        c, s, f = map(int, input().split())
        trains.append((c, s, f))
    ans = [0] * N
    for i, (ci, si, fi) in enumerate(trains):
        curr = si + ci
        for j, (cj, sj, fj) in enumerate(islice(trains, i + 1, N, 1)):
            if curr < sj:
                curr = sj
            r = curr % fj
            if r != 0:
                curr += fj - r
            curr += cj
        ans[i] = curr
    print(*ans, sep="\n")

if __name__ == "__main__":
    main()

-csf = [tuple(map(int, input().split())) for _ in range(n - 1)]  # csf

-    t = 0  # 駅jの出発時刻, 駅n（添え字n - 1）では、この時刻がprintされるので、初期値は0とする

-        # j:乗車する区間

-        # 駅jの出発時刻を求める

-            # 始発より後に駅に到着し、駅で電車を待つ

-        t += c_j  # 乗車して次の駅に到着させる

+        c, s, f = map(int, input().split())

+    for i, (ci, si, fi) in enumerate(trains):

+        for j, (cj, sj, fj) in enumerate(islice(trains, i + 1, N, 1)):


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

par=[-1]*N

num=[0]*N

def find(x):

    if par[x-1]<0:

        return x

    else:

        par[x-1]=find(par[x-1])

        return par[x-1]

def union(x,y):

    if find(x)==find(y):

        return

    if find(x)>find(y):

        x,y=y,x

    par[find(x)-1]+=par[find(y)-1]

    par[find(y)-1]=find(x)

def size(x):

    return -par[find(x)-1]

def same(x,y):

    return find(x)==find(y)

for _ in range(M):

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

    union(a,b)

    num[a-1]+=1

    num[b-1]+=1

for _ in range(K):

    c,d=map(int,input().split())

    if same(c,d):

        num[c-1]+=1

        num[d-1]+=1

for i in range(N):

    print(size(i+1)-1-num[i],end=" ")

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

par=[-1]*N

num=[0]*N

def find(x):

    if par[x-1]<0:

        return x

    else:

        par[x-1]=find(par[x-1])

        return par[x-1]

def union(x,y):

    p,q=find(x),find(y)

    if p==q:

        return

    if p>q:

        p,q=q,p

    par[p-1]+=par[q-1]

    par[q-1]=p

def size(x):

    return -par[find(x)-1]

def same(x,y):

    return find(x)==find(y)

for _ in range(M):

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

    union(a,b)

    num[a-1]+=1

    num[b-1]+=1

for _ in range(K):

    c,d=map(int,input().split())

    if same(c,d):

        num[c-1]+=1

        num[d-1]+=1

for i in range(N):

    print(size(i+1)-1-num[i],end=" ")

N, M, K = map(int, input().split())
par = [-1] * N
num = [0] * N

def find(x):
    if par[x - 1] < 0:
        return x
    else:
        par[x - 1] = find(par[x - 1])
        return par[x - 1]

def union(x, y):
    if find(x) == find(y):
        return
    if find(x) > find(y):
        x, y = y, x
    par[find(x) - 1] += par[find(y) - 1]
    par[find(y) - 1] = find(x)

def size(x):
    return -par[find(x) - 1]

def same(x, y):
    return find(x) == find(y)

for _ in range(M):
    a, b = map(int, input().split())
    union(a, b)
    num[a - 1] += 1
    num[b - 1] += 1
for _ in range(K):
    c, d = map(int, input().split())
    if same(c, d):
        num[c - 1] += 1
        num[d - 1] += 1
for i in range(N):
    print(size(i + 1) - 1 - num[i], end=" ")

N, M, K = map(int, input().split())
par = [-1] * N
num = [0] * N

def find(x):
    if par[x - 1] < 0:
        return x
    else:
        par[x - 1] = find(par[x - 1])
        return par[x - 1]

def union(x, y):
    p, q = find(x), find(y)
    if p == q:
        return
    if p > q:
        p, q = q, p
    par[p - 1] += par[q - 1]
    par[q - 1] = p

def size(x):
    return -par[find(x) - 1]

def same(x, y):
    return find(x) == find(y)

for _ in range(M):
    a, b = map(int, input().split())
    union(a, b)
    num[a - 1] += 1
    num[b - 1] += 1
for _ in range(K):
    c, d = map(int, input().split())
    if same(c, d):
        num[c - 1] += 1
        num[d - 1] += 1
for i in range(N):
    print(size(i + 1) - 1 - num[i], end=" ")

-    par[find(x) - 1] += par[find(y) - 1]


Input:
from sys import stdin

nii=lambda:list(map(int,stdin.readline().split()))

lnii=lambda:list(map(int,stdin.readline().split()))

n,m=nii()

l=[lnii() for i in range(m)]

class UnionFind():

    def __init__(self, n):

        self.n = n

        self.parents = [-1] * n

    def find(self, x):

        if self.parents[x] < 0:

            return x

        else:

            self.parents[x] = self.find(self.parents[x])

            return self.parents[x]

    def union(self, x, y):

        x = self.find(x)

        y = self.find(y)

        if x == y:

            return

        if self.parents[x] > self.parents[y]:

            x, y = y, x

        self.parents[x] += self.parents[y]

        self.parents[y] = x

    def same(self, x, y):

        return self.find(x) == self.find(y)

    def size(self, x):

        return -self.parents[self.find(x)]

    def roots(self):

        return [i for i, x in enumerate(self.parents) if x < 0]

uf=UnionFind(n)

for a,b, in l:

  a-=1

  b-=1

  if uf.same(a,b)==False:

    uf.union(a,b)

ans=0

roots=uf.roots()

for i in uf.roots():

  ans=max(ans,uf.size(i))

print(ans)

from sys import stdin

nii=lambda:list(map(int,stdin.readline().split()))

lnii=lambda:list(map(int,stdin.readline().split()))

class UnionFind():

    def __init__(self, n):

        self.n = n

        self.parents = [-1] * n

    def find(self, x):

        if self.parents[x] < 0:

            return x

        else:

            self.parents[x] = self.find(self.parents[x])

            return self.parents[x]

    def union(self, x, y):

        x = self.find(x)

        y = self.find(y)

        if x == y:

            return

        if self.parents[x] > self.parents[y]:

            x, y = y, x

        self.parents[x] += self.parents[y]

        self.parents[y] = x

    def same(self, x, y):

        return self.find(x) == self.find(y)

    def size(self, x):

        return -self.parents[self.find(x)]

    def members(self, x):

        root = self.find(x)

        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):

        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):

        return len(self.roots())

    def all_group_members(self):

        return {r: self.members(r) for r in self.roots()}

    def __str__(self):

        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

n,m=nii()

uf=UnionFind(n)

for i in range(m):

  a,b=nii()

  a-=1

  b-=1

  uf.union(a,b)

root=uf.roots()

ans=0

for i in root:

  ans=max(ans,uf.size(i))

print(ans)

from sys import stdin

nii = lambda: list(map(int, stdin.readline().split()))
lnii = lambda: list(map(int, stdin.readline().split()))
n, m = nii()
l = [lnii() for i in range(m)]

class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return -self.parents[self.find(x)]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

uf = UnionFind(n)
for (
    a,
    b,
) in l:
    a -= 1
    b -= 1
    if uf.same(a, b) == False:
        uf.union(a, b)
ans = 0
roots = uf.roots()
for i in uf.roots():
    ans = max(ans, uf.size(i))
print(ans)

from sys import stdin

nii = lambda: list(map(int, stdin.readline().split()))
lnii = lambda: list(map(int, stdin.readline().split()))

class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return -self.parents[self.find(x)]

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots())

n, m = nii()
uf = UnionFind(n)
for i in range(m):
    a, b = nii()
    a -= 1
    b -= 1
    uf.union(a, b)
root = uf.roots()
ans = 0
for i in root:
    ans = max(ans, uf.size(i))
print(ans)

+        return [i for i in range(self.n) if self.find(i) == root]

+        return {r: self.members(r) for r in self.roots()}

+        return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots())


Input:
import numpy as np

import sys

n = int(eval(input()))

a = sorted(list(map(int,input().split())))[::-1]

print((sum(a[::2])-sum(a[1::2])))

n=int(eval(input()))

a=sorted(list(map(int,input().split())))[::-1]

ans=0

for i in range(n):

    if i%2==0:

        ans+=a[i]

    else:

        ans-=a[i]

print(ans)

import numpy as np
import sys

n = int(eval(input()))
a = sorted(list(map(int, input().split())))[::-1]
print((sum(a[::2]) - sum(a[1::2])))

n = int(eval(input()))
a = sorted(list(map(int, input().split())))[::-1]
ans = 0
for i in range(n):
    if i % 2 == 0:
        ans += a[i]
    else:
        ans -= a[i]
print(ans)

-import numpy as np
-import sys
-print((sum(a[::2]) - sum(a[1::2])))
+ans = 0
+for i in range(n):
+    if i % 2 == 0:
+        ans += a[i]
+    else:
+        ans -= a[i]
+print(ans)


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

s = int(eval(input()))

if s == 1 and n == 1:

    print((2))

    exit()

if s > n:

    print((-1))

    exit()

if n%2 == 0 and n > s > n//2:

    print((-1))

    exit()

if n%2 == 1 and n > s > n//2+1:

    print((-1))

    exit()

ans = float("INF")

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

    x = n

    count = 0

    while x >= i:

        count += x%i

        x //= i

    if count + x == s:

        print(i)

        exit()

now = 2

li = int(n**0.5)+1

while True:

    x = n//now

    if x < li:

        break

    count = 0

    y = n

    while y >= x:

        count += y%x

        y //= x

    count += y

    if count <= s and (s-count)%now == 0:

        z = x-n//(now+1)

        if (s-count)//now < z:

            ans = x-(s-count)//now

    now += 1

if s == n:

    print((min(ans,n+1)))

else:

    print((min(ans,n-s+1)))

n = int(eval(input()))

s = int(eval(input()))

if s == n:

    print((n+1))

    exit()

if s > n%2+n//2:

    print((-1))

    exit()

ans = float("INF")

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

    x = n

    count = 0

    while x >= i:

        count += x%i

        x //= i

    if count + x == s:

        print(i)

        exit()

now = 2

li = int(n**0.5)+1

while True:

    x = n//now

    if x < li:

        break

    count = 0

    y = n

    while y >= x:

        count += y%x

        y //= x

    count += y

    if count <= s and (s-count)%now == 0:

        z = x-n//(now+1)

        if (s-count)//now < z:

            ans = x-(s-count)//now

    now += 1

print((min(ans,n-s+1)))

n = int(eval(input()))
s = int(eval(input()))
if s == 1 and n == 1:
    print((2))
    exit()
if s > n:
    print((-1))
    exit()
if n % 2 == 0 and n > s > n // 2:
    print((-1))
    exit()
if n % 2 == 1 and n > s > n // 2 + 1:
    print((-1))
    exit()
ans = float("INF")
for i in range(2, int(n**0.5) + 1):
    x = n
    count = 0
    while x >= i:
        count += x % i
        x //= i
    if count + x == s:
        print(i)
        exit()
now = 2
li = int(n**0.5) + 1
while True:
    x = n // now
    if x < li:
        break
    count = 0
    y = n
    while y >= x:
        count += y % x
        y //= x
    count += y
    if count <= s and (s - count) % now == 0:
        z = x - n // (now + 1)
        if (s - count) // now < z:
            ans = x - (s - count) // now
    now += 1
if s == n:
    print((min(ans, n + 1)))
else:
    print((min(ans, n - s + 1)))

n = int(eval(input()))
s = int(eval(input()))
if s == n:
    print((n + 1))
    exit()
if s > n % 2 + n // 2:
    print((-1))
    exit()
ans = float("INF")
for i in range(2, int(n**0.5) + 1):
    x = n
    count = 0
    while x >= i:
        count += x % i
        x //= i
    if count + x == s:
        print(i)
        exit()
now = 2
li = int(n**0.5) + 1
while True:
    x = n // now
    if x < li:
        break
    count = 0
    y = n
    while y >= x:
        count += y % x
        y //= x
    count += y
    if count <= s and (s - count) % now == 0:
        z = x - n // (now + 1)
        if (s - count) // now < z:
            ans = x - (s - count) // now
    now += 1
print((min(ans, n - s + 1)))


Input:
#!/usr/bin/env python

# coding: utf-8

def ri():

    return int(eval(input()))

def rl():

    return list(input().split())

def rli():

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

def calc(n):

    s = sum(map(int, str(n)))

    return n / s

def f(n):

    ld = list(map(int, str(n)))

    cand = []

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

        d = len(ld)-1-i

        ld[d] = 9

        for i in range(1, 10):

            if i < ld[d-1]:

                continue

            ld[d-1] = i

            p = int("".join(map(str, ld)))

            cand.append((calc(p), p))

    cand.sort()

    return cand[0][1]

MAX = 10**15

def main():

    k = ri()

    cand = list(range(1, 10))

    n = 10

    while True:

        if n > MAX:

            break

        p = f(n)

        cand.append(p)

        n = p+1

    print(("\n".join(map(str, cand[:k]))))

if __name__ == '__main__':

    main()

#!/usr/bin/env python
# coding: utf-8
def ri():
    return int(eval(input()))

def rl():
    return list(input().split())

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

def calc(n):
    s = sum(map(int, str(n)))
    return n / s

def f(n):
    ld = list(map(int, str(n)))
    cand = []
    for i in range(len(ld) - 1):
        d = len(ld) - 1 - i
        ld[d] = 9
        for i in range(1, 10):
            if i < ld[d - 1]:
                continue
            ld[d - 1] = i
            p = int("".join(map(str, ld)))
            cand.append((calc(p), p))
    cand.sort()
    return cand[0][1]

MAX = 10**15

def main():
    k = ri()
    cand = list(range(1, 10))
    n = 10
    while True:
        if n > MAX:
            break
        p = f(n)
        cand.append(p)
        n = p + 1
    print(("\n".join(map(str, cand[:k]))))

if __name__ == "__main__":
    main()

-            p = int("".join(map(str, ld)))

+                e1 = d * pow10n + e * (last + 1) + last

+                if calc(e1) > calc(e2):

+                    last = last * 10 + 9


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

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

trees = sorted(trees)

result = min(trees[i+K-1] - trees[i] for i in range(N-K+1))

print(result)

N, K, *trees = list(map(int, open(0).read().split()))

trees = sorted(trees)

print((min(trees[i+K-1] - trees[i] for i in range(N-K+1))))

N, K = list(map(int, input().split()))
trees = [int(eval(input())) for i in range(N)]
trees = sorted(trees)
result = min(trees[i + K - 1] - trees[i] for i in range(N - K + 1))
print(result)

N, K, *trees = list(map(int, open(0).read().split()))
trees = sorted(trees)
print((min(trees[i + K - 1] - trees[i] for i in range(N - K + 1))))

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

+N, K, *trees = list(map(int, open(0).read().split()))

-result = min(trees[i + K - 1] - trees[i] for i in range(N - K + 1))

+print((min(trees[i + K - 1] - trees[i] for i in range(N - K + 1))))


Input:
import sys

N, S = int(sys.stdin.readline()), sys.stdin.readline()

b, w = 0, S.count('.')

ans = b + w

for si in S:

    if si == "#":

        b += 1

    if si == ".":

        w -= 1

    ans = min(ans, b + w)

print(ans)

N, S = int(eval(input())), eval(input())

b, w = 0, S.count('.')

ans = b + w

for si in S:

    if si == "#":

        b += 1

    else:

        w -= 1

    ans = min(ans, b + w)

print(ans)

import sys

N, S = int(sys.stdin.readline()), sys.stdin.readline()
b, w = 0, S.count(".")
ans = b + w
for si in S:
    if si == "#":
        b += 1
    if si == ".":
        w -= 1
    ans = min(ans, b + w)
print(ans)

N, S = int(eval(input())), eval(input())
b, w = 0, S.count(".")
ans = b + w
for si in S:
    if si == "#":
        b += 1
    else:
        w -= 1
    ans = min(ans, b + w)
print(ans)

-N, S = int(sys.stdin.readline()), sys.stdin.readline()

+N, S = int(eval(input())), eval(input())


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

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

ab.sort(key=lambda x: x[1])

count = 0

x = 0

for a_i, b_i in ab:

	if a_i <= x < b_i:

		continue

	x = b_i-1

	count += 1

print(count)

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

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

ab.sort(key=lambda x: x[1])

count = 0

before = 0

for a_i, b_i in ab:

	if before > a_i:

		continue

	before = b_i

	count += 1

print(count)

n, m = list(map(int, input().split(" ")))
ab = [list(map(int, input().split(" "))) for _ in range(m)]
ab.sort(key=lambda x: x[1])
count = 0
x = 0
for a_i, b_i in ab:
    if a_i <= x < b_i:
        continue
    x = b_i - 1
    count += 1
print(count)

-x = 0
+before = 0
-    if a_i <= x < b_i:
+    if before > a_i:
-    x = b_i - 1
+    before = b_i


Input:
def f(n, k, a_s):

    md = 10 ** 9 + 7

    dp = [0] * (k + 1)

    dp[0] = 1

    for a in a_s[:-1]:

        ndp = [0] * (k + 1)

        ndp[0] = s = dp[0] % md

        for j in range(1, a + 1):

            ndp[j] = s = (s + dp[j]) % md

        for j in range(a + 1, k + 1):

            ndp[j] = s = (s + dp[j] - dp[j - a - 1]) % md

        dp = ndp

    return sum(dp[k - a_s[-1]:]) % md

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

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

print((f(n, k, a_s)))

import numpy as np

def f(n, k, a_s):

    md = 10 ** 9 + 7

    dp = np.zeros(k + 1, dtype=np.int64)

    dp[0] = 1

    for a in a_s[:-1]:

        dp = np.cumsum(dp) % md

        if k != a:

            dp[k:a:-1] = (dp[k:a:-1] - dp[k - a - 1::-1]) % md

    return np.sum(dp[k - a_s[-1]:]) % md

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

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

print((f(n, k, a_s)))

def f(n, k, a_s):
    md = 10**9 + 7
    dp = [0] * (k + 1)
    dp[0] = 1
    for a in a_s[:-1]:
        ndp = [0] * (k + 1)
        ndp[0] = s = dp[0] % md
        for j in range(1, a + 1):
            ndp[j] = s = (s + dp[j]) % md
        for j in range(a + 1, k + 1):
            ndp[j] = s = (s + dp[j] - dp[j - a - 1]) % md
        dp = ndp
    return sum(dp[k - a_s[-1] :]) % md

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

import numpy as np

def f(n, k, a_s):
    md = 10**9 + 7
    dp = np.zeros(k + 1, dtype=np.int64)
    dp[0] = 1
    for a in a_s[:-1]:
        dp = np.cumsum(dp) % md
        if k != a:
            dp[k:a:-1] = (dp[k:a:-1] - dp[k - a - 1 :: -1]) % md
    return np.sum(dp[k - a_s[-1] :]) % md

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

+    dp = np.zeros(k + 1, dtype=np.int64)

-            ndp[j] = s = (s + dp[j]) % md

+    return np.sum(dp[k - a_s[-1] :]) % md


Input:
# 多分全探索だと思われるけども

# 2111 ~

# 2115 解法にはbit全探索を用いる.各列，行について塗るか塗らないかでbit探索をしてあげるとたかだか2**(6*2) で10**4程度の計算量に収まる

# 実装

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

Mo = [[] for _ in range(H)]

for i in range(H):

    Mo[i] = list(eval(input()))

H_num = 2**H

W_num = 2**W

ans = 0

import copy

for i in range(H_num):

    for j in range(W_num):

        M = copy.deepcopy(Mo)

        # sumの計算をしないといけない

        dumi = i

        dumj = j

        SH = [(dumi & 2**kh)//(2**kh) for kh in range(H)]

        SW = [(dumj & 2**kw)//(2**kw) for kw in range(W)]

        num = 0

        for ih,h in enumerate(SH):

            if h == 1:

                M[ih] = ['.' for _ in range(W)]

        for iw,w in enumerate(SW):

            if w == 1:

                for k in range(H):

                    M[k][iw] = '.'

        count = 0

        for ii in range(H):

            for jj in range(W):

                if M[ii][jj] == '#':

                    count += 1

        if count == K:

            ans += 1

print(ans)

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

C=[]

for _ in range(H):

    C.append(list(eval(input())))

# シフト演算と&を使うと早い.

ans = 0

for i in range(1<<H): # 要するに2**Hのこと

    for j in range(1<<W): # 要するに2**Wのこと

        count = 0

        for i2 in range(H):

            for j2 in range(W):

                bit_i = i>>i2 & 1

                bit_j = j>>j2 & 1

                if bit_i == 1 or bit_j == 1:

                    continue

                if C[i2][j2] == '#':

                    count += 1

        if count == K:

            ans += 1

print(ans)

# 多分全探索だと思われるけども
# 2111 ~
# 2115 解法にはbit全探索を用いる.各列，行について塗るか塗らないかでbit探索をしてあげるとたかだか2**(6*2) で10**4程度の計算量に収まる
# 実装
H, W, K = list(map(int, input().split()))
Mo = [[] for _ in range(H)]
for i in range(H):
    Mo[i] = list(eval(input()))
H_num = 2**H
W_num = 2**W
ans = 0
import copy

for i in range(H_num):
    for j in range(W_num):
        M = copy.deepcopy(Mo)
        # sumの計算をしないといけない
        dumi = i
        dumj = j
        SH = [(dumi & 2**kh) // (2**kh) for kh in range(H)]
        SW = [(dumj & 2**kw) // (2**kw) for kw in range(W)]
        num = 0
        for ih, h in enumerate(SH):
            if h == 1:
                M[ih] = ["." for _ in range(W)]
        for iw, w in enumerate(SW):
            if w == 1:
                for k in range(H):
                    M[k][iw] = "."
        count = 0
        for ii in range(H):
            for jj in range(W):
                if M[ii][jj] == "#":
                    count += 1
        if count == K:
            ans += 1
print(ans)

H, W, K = list(map(int, input().split()))
C = []
for _ in range(H):
    C.append(list(eval(input())))
# シフト演算と&を使うと早い.
ans = 0
for i in range(1 << H):  # 要するに2**Hのこと
    for j in range(1 << W):  # 要するに2**Wのこと
        count = 0
        for i2 in range(H):
            for j2 in range(W):
                bit_i = i >> i2 & 1
                bit_j = j >> j2 & 1
                if bit_i == 1 or bit_j == 1:
                    continue
                if C[i2][j2] == "#":
                    count += 1
        if count == K:
            ans += 1
print(ans)

-# 多分全探索だと思われるけども

-# 2115 解法にはbit全探索を用いる.各列，行について塗るか塗らないかでbit探索をしてあげるとたかだか2**(6*2) で10**4程度の計算量に収まる

+# シフト演算と&を使うと早い.

-        # sumの計算をしないといけない

-        SH = [(dumi & 2**kh) // (2**kh) for kh in range(H)]

-        SW = [(dumj & 2**kw) // (2**kw) for kw in range(W)]

-                M[ih] = ["." for _ in range(W)]

+    for j in range(1 << W):  # 要するに2**Wのこと

+                if bit_i == 1 or bit_j == 1:


Input:
from sys import stdin

import sys

import math

n = int(eval(input()))

#a = list(map(int, stdin.readline().rstrip().split()))

a = sorted(list(map(int, stdin.readline().rstrip().split())))

count_max = 1

count_prev = 0

count_curr = 1

count_next = 0

current_value = a[0]

for i in range(1, n):

    if a[i] == current_value:

        count_curr += 1

    elif a[i] == current_value + 1:

        count_next += 1

    elif a[i] == current_value + 2:

        count_max = max(count_max, (count_prev + count_curr + count_next))

        current_value = current_value + 1

        count_prev = count_curr

        count_curr = count_next

        count_next = 1

    elif a[i] >= current_value + 3:

        count_max = max(count_max, (count_prev + count_curr + count_next))

        current_value = a[i]

        count_prev = 0

        count_curr = 1

        count_next = 0

    else:

        print("Error")

count_max = max(count_max, (count_prev + count_curr + count_next))

print(count_max)

from sys import stdin

import sys

import math

n = int(eval(input()))

a = list(map(int, stdin.readline().rstrip().split()))

dict_count = {}

for i in a:

    dict_count[i] = 0

for j in a:

    dict_count[j] += 1

#print(dict_count)

max_count = 0

for key in list(dict_count.keys()):

    max_count = max(max_count, dict_count.get(key - 1, 0) + dict_count.get(key, 0) + dict_count.get(key + 1, 0))

print(max_count)

from sys import stdin
import sys
import math

n = int(eval(input()))
# a = list(map(int, stdin.readline().rstrip().split()))
a = sorted(list(map(int, stdin.readline().rstrip().split())))
count_max = 1
count_prev = 0
count_curr = 1
count_next = 0
current_value = a[0]
for i in range(1, n):
    if a[i] == current_value:
        count_curr += 1
    elif a[i] == current_value + 1:
        count_next += 1
    elif a[i] == current_value + 2:
        count_max = max(count_max, (count_prev + count_curr + count_next))
        current_value = current_value + 1
        count_prev = count_curr
        count_curr = count_next
        count_next = 1
    elif a[i] >= current_value + 3:
        count_max = max(count_max, (count_prev + count_curr + count_next))
        current_value = a[i]
        count_prev = 0
        count_curr = 1
        count_next = 0
    else:
        print("Error")
count_max = max(count_max, (count_prev + count_curr + count_next))
print(count_max)

from sys import stdin
import sys
import math

n = int(eval(input()))
a = list(map(int, stdin.readline().rstrip().split()))
dict_count = {}
for i in a:
    dict_count[i] = 0
for j in a:
    dict_count[j] += 1
# print(dict_count)
max_count = 0
for key in list(dict_count.keys()):
    max_count = max(
        max_count,
        dict_count.get(key - 1, 0)
        + dict_count.get(key, 0)
        + dict_count.get(key + 1, 0),
    )
print(max_count)

-# a = list(map(int, stdin.readline().rstrip().split()))

-a = sorted(list(map(int, stdin.readline().rstrip().split())))

-        count_max = max(count_max, (count_prev + count_curr + count_next))

-        current_value = current_value + 1

-count_max = max(count_max, (count_prev + count_curr + count_next))

+a = list(map(int, stdin.readline().rstrip().split()))


Input:
def is_753(n):

    n = str(n)

    return(n.count("7") >= 1 and n.count("3") >= 1 and n.count("5") >= 1)

n = int(eval(input()))

v = [7, 5, 3]

li = []

prev = [7, 5, 3]

for i in range(9):

    tmp = []

    for j in v:

        for k in prev:

            tmp.append(k * 10 + j)

    prev = tmp

    li = li + prev

li = [x for x in li if is_753(x) and x <= n]

print((len(li)))

import sys

sys.setrecursionlimit(10**6)

N = int(eval(input()))

V = [3, 5, 7]

li = []

def rec(curr, use):

    if curr > N:

        return

    if use == 0b111:

        li.append(curr)

    for i, b in enumerate(V):

        rec(curr * 10 + b, use | max(1, i * 2))

rec(0, 0)

print((len(li)))

def is_753(n):
    n = str(n)
    return n.count("7") >= 1 and n.count("3") >= 1 and n.count("5") >= 1

n = int(eval(input()))
v = [7, 5, 3]
li = []
prev = [7, 5, 3]
for i in range(9):
    tmp = []
    for j in v:
        for k in prev:
            tmp.append(k * 10 + j)
    prev = tmp
    li = li + prev
li = [x for x in li if is_753(x) and x <= n]
print((len(li)))

-    return n.count("7") >= 1 and n.count("3") >= 1 and n.count("5") >= 1

-li = [x for x in li if is_753(x) and x <= n]

+        rec(curr * 10 + b, use | max(1, i * 2))


Input:
def five(x):

    cnt1 = 0

    while x%5==0:

        cnt1+= 1

        x = x//5

    cnt2 = 0

    while x%2==0:

        cnt2+= 1

        x = x//2

    return (min2(cnt1,18), min2(cnt2,18))

def min2(x,y):

    return x if x < y else y

import sys

input = sys.stdin.readline

N = int(eval(input()))

F = []

for i in range(N):

    A = input().rstrip()

    if '.' in A:

        a,b = A.split('.')

        n = int(a+b)*10**(9-len(b))

    else:

        n = int(A) * 10 ** 9

    F.append(five(n))

F.sort()

j = 0

temp = 0

dp = [0]*19

k = 0

for i in range(N-1):

    if N-1-j < i:

        dp[min2(F[i][1], 18)] -= 1

    while N-1-j> i and F[i][0]+F[N-1-j][0] >= 18:

        dp[min2(F[N-1-j][1],18)] += 1

        j += 1

    k = sum(dp[:18-F[i][1]])

    temp += min2(j, N-i-1) - k

print(temp)

class cumsum2D:

    def __init__(self, data):

        self.N = len(data)

        self.M= len(data[0])

        self.cum = [[0] * (self.M + 1) for _ in range(self.N + 1)]

        for i in range(self.N):

            for j in range(self.M):

                self.cum[i + 1][j + 1] = self.cum[i][j + 1] + self.cum[i + 1][j] - self.cum[i][j] + data[i][j]

    def get(self,x1,y1,x2,y2):

        """

        長方形の領域 [x1,x2)*[y1,y2) の範囲内にインプットされた数字の和を取る

        """

        return self.cum[x2][y2] - self.cum[x1][y2] - self.cum[x2][y1] + self.cum[x1][y1]

def five(x):

    cnt1 = 0

    while x%5==0:

        cnt1+= 1

        x = x//5

    cnt2 = 0

    while x%2==0:

        cnt2+= 1

        x = x//2

    return (min(cnt1,18), min(cnt2,18))

def digit_lift(S, l):

    if '.' in S:

        a, b = S.split('.')

        n = int(a + b) * 10 ** (l - len(b))

    else:

        n = int(S) * 10 ** l

    return n

data = [[0]*19 for _ in range(19)]

N = int(eval(input()))

Q = set()

for _ in range(N):

    A = digit_lift(input().rstrip(),9)

    x, y = five(A)

    data[x][y] += 1

    Q.add((x,y))

cum = cumsum2D(data)

res = 0

for x, y in Q:

    res += (cum.get(18-x,18-y,-1,-1)- (x>=9 and y>=9))*data[x][y]

print((res//2))

def five(x):
    cnt1 = 0
    while x % 5 == 0:
        cnt1 += 1
        x = x // 5
    cnt2 = 0
    while x % 2 == 0:
        cnt2 += 1
        x = x // 2
    return (min2(cnt1, 18), min2(cnt2, 18))

def min2(x, y):
    return x if x < y else y

import sys

input = sys.stdin.readline
N = int(eval(input()))
F = []
for i in range(N):
    A = input().rstrip()
    if "." in A:
        a, b = A.split(".")
        n = int(a + b) * 10 ** (9 - len(b))
    else:
        n = int(A) * 10**9
    F.append(five(n))
F.sort()
j = 0
temp = 0
dp = [0] * 19
k = 0
for i in range(N - 1):
    if N - 1 - j < i:
        dp[min2(F[i][1], 18)] -= 1
    while N - 1 - j > i and F[i][0] + F[N - 1 - j][0] >= 18:
        dp[min2(F[N - 1 - j][1], 18)] += 1
        j += 1
    k = sum(dp[: 18 - F[i][1]])
    temp += min2(j, N - i - 1) - k
print(temp)

class cumsum2D:
    def __init__(self, data):
        self.N = len(data)
        self.M = len(data[0])
        self.cum = [[0] * (self.M + 1) for _ in range(self.N + 1)]
        for i in range(self.N):
            for j in range(self.M):
                self.cum[i + 1][j + 1] = (
                    self.cum[i][j + 1]
                    + self.cum[i + 1][j]
                    - self.cum[i][j]
                    + data[i][j]
                )

    def get(self, x1, y1, x2, y2):
        """
        長方形の領域 [x1,x2)*[y1,y2) の範囲内にインプットされた数字の和を取る
        """
        return self.cum[x2][y2] - self.cum[x1][y2] - self.cum[x2][y1] + self.cum[x1][y1]

def five(x):
    cnt1 = 0
    while x % 5 == 0:
        cnt1 += 1
        x = x // 5
    cnt2 = 0
    while x % 2 == 0:
        cnt2 += 1
        x = x // 2
    return (min(cnt1, 18), min(cnt2, 18))

def digit_lift(S, l):
    if "." in S:
        a, b = S.split(".")
        n = int(a + b) * 10 ** (l - len(b))
    else:
        n = int(S) * 10**l
    return n

data = [[0] * 19 for _ in range(19)]
N = int(eval(input()))
Q = set()
for _ in range(N):
    A = digit_lift(input().rstrip(), 9)
    x, y = five(A)
    data[x][y] += 1
    Q.add((x, y))
cum = cumsum2D(data)
res = 0
for x, y in Q:
    res += (cum.get(18 - x, 18 - y, -1, -1) - (x >= 9 and y >= 9)) * data[x][y]
print((res // 2))

+        self.cum = [[0] * (self.M + 1) for _ in range(self.N + 1)]

+                    + self.cum[i + 1][j]

+        長方形の領域 [x1,x2)*[y1,y2) の範囲内にインプットされた数字の和を取る

+        return self.cum[x2][y2] - self.cum[x1][y2] - self.cum[x2][y1] + self.cum[x1][y1]

-    return (min2(cnt1, 18), min2(cnt2, 18))

+    return (min(cnt1, 18), min(cnt2, 18))

+    A = digit_lift(input().rstrip(), 9)


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

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

H.sort()

ans = 10**10

for i in range(N-K+1):

    ans = min(ans, H[i+K-1] - H[i])

print(ans)

import sys

def main():

    input = sys.stdin.readline

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

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

    H.sort()

    ans=10**12

    for i in range(N):

        if i+K-1 >= N: break

        ans = min(ans, H[i+K-1]-H[i])

    print(ans)

if __name__ == '__main__':

    main()

N, K = list(map(int, input().split()))
H = [int(eval(input())) for _ in range(N)]
H.sort()
ans = 10**10
for i in range(N - K + 1):
    ans = min(ans, H[i + K - 1] - H[i])
print(ans)

import sys

def main():
    input = sys.stdin.readline
    N, K = list(map(int, input().split()))
    H = [int(eval(input())) for _ in range(N)]
    H.sort()
    ans = 10**12
    for i in range(N):
        if i + K - 1 >= N:
            break
        ans = min(ans, H[i + K - 1] - H[i])
    print(ans)

if __name__ == "__main__":
    main()

-H = [int(eval(input())) for _ in range(N)]

-    ans = min(ans, H[i + K - 1] - H[i])

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

+    H = [int(eval(input())) for _ in range(N)]

+        ans = min(ans, H[i + K - 1] - H[i])


Input:
s = eval(input())

count = 0

if s[0] == "o":

    count+=1

if s[1] == "o":

    count+=1

if s[2] == "o":

    count+=1

print((700+100*count))

S = eval(input())

c = S.count("o")

print((700+100*c))

s = eval(input())
count = 0
if s[0] == "o":
    count += 1
if s[1] == "o":
    count += 1
if s[2] == "o":
    count += 1
print((700 + 100 * count))

S = eval(input())
c = S.count("o")
print((700 + 100 * c))


Input:
import statistics

n=int(eval(input()))

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

num=round(statistics.mean(a))

print((sum([(num-i)**2 for i in a])))

eval(input());a=list(map(int,input().split()));r=float('inf')

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

  n=0

  for j in a:

    n+=(j-i)**2

  r=min(n,r)

print(r)

import statistics

n = int(eval(input()))
a = list(map(int, input().split()))
num = round(statistics.mean(a))
print((sum([(num - i) ** 2 for i in a])))

eval(input())
a = list(map(int, input().split()))
r = float("inf")
for i in range(min(a), max(a) + 1):
    n = 0
    for j in a:
        n += (j - i) ** 2
    r = min(n, r)
print(r)

-print((sum([(num - i) ** 2 for i in a])))


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

B = int(eval(input()))

C = int(eval(input()))

X = int(eval(input()))

var = 0

for i in range(A+1):

  if (X-500*i) >= 0:

    Y = X-500*i

    for j in range(B+1):

      if ((Y-100*j) >= 0) and (((Y-100*j)//50) <= C):

        var = var+1

print(var)

A = int(eval(input()))
B = int(eval(input()))
C = int(eval(input()))
X = int(eval(input()))
var = 0
for i in range(A + 1):
    if (X - 500 * i) >= 0:
        Y = X - 500 * i
        for j in range(B + 1):
            if ((Y - 100 * j) >= 0) and (((Y - 100 * j) // 50) <= C):
                var = var + 1
print(var)

+s = [int(eval(input())) for i in range(4)]


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

#レベルNの層とパティの数を求める

a,p=[1],[1]

for i in range(n):

    a.append(2*a[i]+3)

    p.append(2*p[i]+1)

def cnt(n,x):

    #レベルNのバーガーのX層までに含まれるパティを数える

    if n==0:

        return 1 if x>=1 else 0

    elif x<=1+a[n-1]:

        return cnt(n-1,x-1)

    elif 2+a[n-1]<=x:

        return cnt(n-1,x-(a[n-1]+2))+p[n-1]+1

print((cnt(n,x)))

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

a,p=[1],[1]

for i in range(n):

    a.append(2*a[i]+3)

    p.append(2*p[i]+1)

def F(N,X):

    if N==0:

        return 0 if X<=0 else 1

    elif X==1:

        return 0

    elif 1<X<=1+a[N-1]:

        return F(N-1,X-1)

    elif X==2+a[N-1]:

        return p[N-1]+1

    elif 2+a[N-1]<X<=a[N]-1:

        return F(N-1,X-(2+a[N-1]))+p[N-1]+1

    elif X==a[N]:

        return 2*p[N-1]+1

print((F(n,x)))

n, x = list(map(int, input().split()))
# レベルNの層とパティの数を求める
a, p = [1], [1]
for i in range(n):
    a.append(2 * a[i] + 3)
    p.append(2 * p[i] + 1)

def cnt(n, x):
    # レベルNのバーガーのX層までに含まれるパティを数える
    if n == 0:
        return 1 if x >= 1 else 0
    elif x <= 1 + a[n - 1]:
        return cnt(n - 1, x - 1)
    elif 2 + a[n - 1] <= x:
        return cnt(n - 1, x - (a[n - 1] + 2)) + p[n - 1] + 1

print((cnt(n, x)))

n, x = list(map(int, input().split()))
a, p = [1], [1]
for i in range(n):
    a.append(2 * a[i] + 3)
    p.append(2 * p[i] + 1)

def F(N, X):
    if N == 0:
        return 0 if X <= 0 else 1
    elif X == 1:
        return 0
    elif 1 < X <= 1 + a[N - 1]:
        return F(N - 1, X - 1)
    elif X == 2 + a[N - 1]:
        return p[N - 1] + 1
    elif 2 + a[N - 1] < X <= a[N] - 1:
        return F(N - 1, X - (2 + a[N - 1])) + p[N - 1] + 1
    elif X == a[N]:
        return 2 * p[N - 1] + 1

print((F(n, x)))

-# レベルNの層とパティの数を求める

-    # レベルNのバーガーのX層までに含まれるパティを数える


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

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

mod = 10 ** 9 + 7

ans = 0

sum_a = sum(a)

for i in range(s):

    sum_a -= a[i]

    ans += sum_a * a[i] % mod

print((ans%mod))

s = int(eval(input()))

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

mod = 10 ** 9 + 7

ans = 0

sum_a = sum(a)

for i in range(s):

    sum_a -= a[i]

    ans += sum_a * a[i]

print((ans%mod))

s = int(eval(input()))
a = list(map(int, input().split()))
mod = 10**9 + 7
ans = 0
sum_a = sum(a)
for i in range(s):
    sum_a -= a[i]
    ans += sum_a * a[i] % mod
print((ans % mod))

s = int(eval(input()))
a = list(map(int, input().split()))
mod = 10**9 + 7
ans = 0
sum_a = sum(a)
for i in range(s):
    sum_a -= a[i]
    ans += sum_a * a[i]
print((ans % mod))

-    ans += sum_a * a[i] % mod
+    ans += sum_a * a[i]


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

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

l = []

a = P[0]

for i in range(N):

    if P[i] <= a:

        a = P[i]

        continue

    else:

        l.append(i)

print((N - len(l)))

N = int(eval(input()))

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

l = 0

a = P[0]

for p in P:

    if p <= a:

        a = p

        l += 1

        continue

print(l)

-l = []
+l = 0
-for i in range(N):
-    if P[i] <= a:
-        a = P[i]
+for p in P:
+    if p <= a:
+        a = p
+        l += 1
-    else:
-        l.append(i)
-print((N - len(l)))
+print(l)


Input:
from sys import stdin

nii=lambda:list(map(int,stdin.readline().split()))

lnii=lambda:list(map(int,stdin.readline().split()))

abc='abcdefghijklmnopqrstuvwxyz'

n=int(eval(input()))

ans=''

while n!=0:

  t_ans=n%26

  ans+=str(abc[t_ans-1])

  if abc[t_ans-1]=='z':

    n-=1

  n//=26

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

n=int(eval(input()))

abc='abcdefghijklmnopqrstuvwxyz'

ans=''

while n!=0:

  q=n%26

  ans+=abc[q-1]

  if q==0:

    n-=1

  n//=26

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

from sys import stdin

nii = lambda: list(map(int, stdin.readline().split()))
lnii = lambda: list(map(int, stdin.readline().split()))
abc = "abcdefghijklmnopqrstuvwxyz"
n = int(eval(input()))
ans = ""
while n != 0:
    t_ans = n % 26
    ans += str(abc[t_ans - 1])
    if abc[t_ans - 1] == "z":
        n -= 1
    n //= 26
print((ans[::-1]))

n = int(eval(input()))
abc = "abcdefghijklmnopqrstuvwxyz"
ans = ""
while n != 0:
    q = n % 26
    ans += abc[q - 1]
    if q == 0:
        n -= 1
    n //= 26
print((ans[::-1]))

-nii = lambda: list(map(int, stdin.readline().split()))

-lnii = lambda: list(map(int, stdin.readline().split()))


Input:
# 頂点および辺の数を入力

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

# 辺のリストを作成

list_edge = [[] for _ in range(N + 1)]

for _ in range(M):

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

    list_edge[a].append(b)

    list_edge[b].append(a)

# パス（リスト）のリストを初期化

list_path = [[1]]

# パスが存在する、かつパスの長さが頂点の数未満である場合に繰り返し

while list_path != [] and len(list_path[0]) < N:

    # パスのリストから先頭のパスを取り出す

    path = list_path.pop(0)

    # パスの最後尾の頂点から訪問可能な頂点について、、

    for node in list_edge[path[-1]]:

        # その頂点にまだ訪問していない場合、、

        if node not in path:

            # パスのリストに新たなパスを加える

            list_path.append(path + [node])

# パスの数を出力する

print((len(list_path)))

# 頂点および辺の数を入力

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

# 辺のリストを作成

list_edge = [[] for _ in range(N + 1)]

for _ in range(M):

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

    list_edge[a].append(b)

    list_edge[b].append(a)

# パスの数を返す関数を定義

def count_path(node, path, list_edge, N):

    # パスの数を初期化

    count = 0

    # 全ての頂点を訪問した場合、、

    if len(path) == N:

        # パスの数に1を加える

        count += 1

    # 全ての頂点を訪問していない場合、、

    else:

        # 現在の頂点から訪問できる各頂点について、、

        for next_node in list_edge[node]:

            # その頂点にまだ訪問していない場合、、

            if next_node not in path:

                # 再帰

                count += count_path(next_node, path + [next_node], list_edge, N)

    # パスの本数を返す

    return count

# パスの本数を出力する

print((count_path(1, [1], list_edge, N)))

-# パス（リスト）のリストを初期化

-# パスが存在する、かつパスの長さが頂点の数未満である場合に繰り返し

-while list_path != [] and len(list_path[0]) < N:

-    # パスのリストから先頭のパスを取り出す

-    # パスの最後尾の頂点から訪問可能な頂点について、、

-        # その頂点にまだ訪問していない場合、、

-            # パスのリストに新たなパスを加える

-            list_path.append(path + [node])

-# パスの数を出力する

+# パスの数を返す関数を定義

+def count_path(node, path, list_edge, N):

+    # パスの数を初期化

+    # 全ての頂点を訪問した場合、、

+        # パスの数に1を加える

+    # 全ての頂点を訪問していない場合、、

+        # 現在の頂点から訪問できる各頂点について、、

+        for next_node in list_edge[node]:

+            # その頂点にまだ訪問していない場合、、

+                # 再帰

+                count += count_path(next_node, path + [next_node], list_edge, N)

+    # パスの本数を返す

+# パスの本数を出力する

+print((count_path(1, [1], list_edge, N)))


Input:
from scipy.misc import*

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

for i in range(k):print((comb(n-k+1,i+1,1)*comb(k-1,i,1)%(10**9+7)))

from scipy.misc import *

n, k = list(map(int, input().split()))
for i in range(k):
    print((comb(n - k + 1, i + 1, 1) * comb(k - 1, i, 1) % (10**9 + 7)))


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

lis = [0,26]

num = 26

n = 1

while lis[-1]<N:

    num *= 26

    lis.append(lis[-1]+num)

    n += 1

c = N-lis[-2]-1

ans = ''

for i in range(n):

    ans = chr(c%26+ord('a')) + ans

    c //= 26

print(ans)

def solve():

  N = int(eval(input()))

  k = 1

  while N>pow(26,k):

    N -= pow(26,k)

    k += 1

  ans = ''

  N -= 1

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

    if i>1:

      ans += chr(ord('a')+N//pow(26,i-1))

    else:

      ans += chr(ord('a')+N%pow(26,i))

    N%=pow(26,i-1)

  return ans

print((solve()))

N = int(eval(input()))
lis = [0, 26]
num = 26
n = 1
while lis[-1] < N:
    num *= 26
    lis.append(lis[-1] + num)
    n += 1
c = N - lis[-2] - 1
ans = ""
for i in range(n):
    ans = chr(c % 26 + ord("a")) + ans
    c //= 26
print(ans)

def solve():
    N = int(eval(input()))
    k = 1
    while N > pow(26, k):
        N -= pow(26, k)
        k += 1
    ans = ""
    N -= 1
    for i in range(k, 0, -1):
        if i > 1:
            ans += chr(ord("a") + N // pow(26, i - 1))
        else:
            ans += chr(ord("a") + N % pow(26, i))
        N %= pow(26, i - 1)
    return ans

print((solve()))


Input:
import sys

from collections import deque

input = sys.stdin.readline

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

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

graph = [[] for _ in range(N)]

indegree = [0 for _ in range(N)]

for i in range(M):

    graph[edge[i][0]-1].append(edge[i][1]-1)

    indegree[edge[i][1]-1] += 1

queue = deque()

for i in range(N):

    if indegree[i] == 0:

        queue.append(i)

dp = [0]*N

while queue:

    node = queue.popleft()

    for adj in graph[node]:

        indegree[adj] -= 1

        if indegree[adj] == 0:

            queue.append(adj)

            dp[adj] = dp[node]+1

print((max(dp)))

import sys

input = sys.stdin.buffer.readline

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

graph = [[] for _ in range(N)]

deg = [0 for _ in range(N)]

dp = [0 for _ in range(N)]

for _ in range(M):

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

    graph[x - 1].append(y - 1)

    deg[y - 1] += 1

stack = []

for i in range(N):

    if not deg[i]:

        stack.append(i)

while stack:

    node = stack.pop()

    for adj in graph[node]:

        deg[adj] -= 1

        dp[adj] = max(dp[adj], dp[node] + 1)

        if not deg[adj]:

            stack.append(adj)

print((max(dp)))

import sys
from collections import deque

input = sys.stdin.readline
N, M = list(map(int, input().split()))
edge = [list(map(int, input().split())) for _ in range(M)]
graph = [[] for _ in range(N)]
indegree = [0 for _ in range(N)]
for i in range(M):
    graph[edge[i][0] - 1].append(edge[i][1] - 1)
    indegree[edge[i][1] - 1] += 1
queue = deque()
for i in range(N):
    if indegree[i] == 0:
        queue.append(i)
dp = [0] * N
while queue:
    node = queue.popleft()
    for adj in graph[node]:
        indegree[adj] -= 1
        if indegree[adj] == 0:
            queue.append(adj)
            dp[adj] = dp[node] + 1
print((max(dp)))

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

-    graph[edge[i][0] - 1].append(edge[i][1] - 1)

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

+        dp[adj] = max(dp[adj], dp[node] + 1)


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

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

prev = -1

is_possible = "Yes"

for i in range(N):

    if prev < H[i]:

        H[i] -= 1

    if prev > H[i]:

        is_possible = "No"

        break

    prev = H[i]

print(is_possible)

def main():

    N = int(eval(input()))

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

    prev = float('-inf')

    for i in range(len(H)):

        if H[i] > prev: prev = H[i]-1

        elif H[i] == prev: pass

        else: return "No"

    return "Yes"

if __name__ == '__main__':

    print((main()))

def main():
    N = int(eval(input()))
    H = list(map(int, input().split()))
    prev = float("-inf")
    for i in range(len(H)):
        if H[i] > prev:
            prev = H[i] - 1
        elif H[i] == prev:
            pass
        else:
            return "No"
    return "Yes"

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

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


Input:
import collections

import itertools

n = int(input())

l = [input() for _ in [0] * n]

counter = collections.Counter(l)

a = counter.most_common()[0][-1]

b = itertools.takewhile(

    lambda kv: kv[-1] == a, counter.most_common()

)

c = sorted(list(k for k, v in b))

print(*c,sep='\n')

import collections

n = int(input())

l = [input() for _ in [0] * n]

counted = collections.Counter(l)

#print(counted)

# 最頻値を求める

m = max(counted.values())

#print(m)

# 頻出数の文字を集める

chars = [key for key, value in counted.items()

             if value == m]

print(*sorted(chars),sep='\n')

import collections
import itertools

n = int(input())
l = [input() for _ in [0] * n]
counter = collections.Counter(l)
a = counter.most_common()[0][-1]
b = itertools.takewhile(lambda kv: kv[-1] == a, counter.most_common())
c = sorted(list(k for k, v in b))
print(*c, sep="\n")

import collections

n = int(input())
l = [input() for _ in [0] * n]
counted = collections.Counter(l)
# print(counted)
# 最頻値を求める
m = max(counted.values())
# print(m)
# 頻出数の文字を集める
chars = [key for key, value in counted.items() if value == m]
print(*sorted(chars), sep="\n")

-b = itertools.takewhile(lambda kv: kv[-1] == a, counter.most_common())

+# 頻出数の文字を集める

+chars = [key for key, value in counted.items() if value == m]


Input:
import sys

if sys.version_info[0]>=3: raw_input=input

n=int(input())

for i in range(0,n):

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

	a[0]-=1;a[1]-=1

	print((196471-a[0]*195-a[0]/3*5-a[1]*20+(a[1]/2 if a[0]%3!=2 else 0)-a[2]))

import sys

if sys.version_info[0]>=3: raw_input=input

n=int(input())

for i in range(0,n):

	a=[int(e) for e in input().split()]

	a[0]-=1;a[1]-=1

	print((196471-a[0]*195-a[0]/3*5-a[1]*20+(a[1]/2 if a[0]%3!=2 else 0)-a[2]))

import sys

if sys.version_info[0] >= 3:
    raw_input = input
n = int(input())
for i in range(0, n):
    a = list(map(int, input().split()))
    a[0] -= 1
    a[1] -= 1
    print(
        (
            196471
            - a[0] * 195
            - a[0] / 3 * 5
            - a[1] * 20
            + (a[1] / 2 if a[0] % 3 != 2 else 0)
            - a[2]
        )
    )

import sys

if sys.version_info[0] >= 3:
    raw_input = input
n = int(input())
for i in range(0, n):
    a = [int(e) for e in input().split()]
    a[0] -= 1
    a[1] -= 1
    print(
        (
            196471
            - a[0] * 195
            - a[0] / 3 * 5
            - a[1] * 20
            + (a[1] / 2 if a[0] % 3 != 2 else 0)
            - a[2]
        )
    )

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

+    a = [int(e) for e in input().split()]


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

flg = False

for i in range(101):

    for j in range(101):

        if (i * 2) + (j * 4) == y and (i + j) == x:

            print("Yes")

            flg = True

            break

    if flg == True:

        break

else:

    print("No")

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

ans = "No"

for i in range(101):

    for j in range(101):

        if (i * 2) + (j * 4) == y and (i + j) == x:

            ans = "Yes"

print(ans)

-flg = False
+ans = "No"
-            print("Yes")
-            flg = True
-            break
-    if flg == True:
-        break
-else:
-    print("No")
+            ans = "Yes"
+print(ans)


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

print((sum(0 <= s - (x + y) <= k for y in range(k + 1) for x in range(k + 1))))

[print(sum(0 <= s - (x + y) <= k for y in range(k + 1) for x in range(k + 1))) for k, s in [map(int, input().split())]]

[
    print(sum(0 <= s - (x + y) <= k for y in range(k + 1) for x in range(k + 1)))
    for k, s in [map(int, input().split())]
]

-print((sum(0 <= s - (x + y) <= k for y in range(k + 1) for x in range(k + 1))))

+    print(sum(0 <= s - (x + y) <= k for y in range(k + 1) for x in range(k + 1)))

+    for k, s in [map(int, input().split())]


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

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

ans = float('inf')

for b in range(1<<(N-1)):

    mxa = A[0]

    k = 1

    cost = 0

    for i,a in enumerate(A[1:]):

        if b&(1<<i):

            c = max(0, mxa+1 - a)

            cost += c

            mxa = max(a, mxa+1)

            k += 1

        else:

            if mxa < a:

                mxa = a

                k += 1

    if k >= K:

        ans = min(ans, cost)

print(ans)

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

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

if K==1:

    print((0))

    exit()

ans = 10**12

for b in range(1<<(N-1)):

    h = A[0]

    k = 1

    cost = 0

    for i in range(N-1):

        a = A[i+1]

        if a > h:

            k += 1

            h = a

        elif b&(1<<i):

            k += 1

            cost += h+1 - a

            h += 1

    if k >= K:

        ans = min(ans, cost)

print(ans)

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
ans = float("inf")
for b in range(1 << (N - 1)):
    mxa = A[0]
    k = 1
    cost = 0
    for i, a in enumerate(A[1:]):
        if b & (1 << i):
            c = max(0, mxa + 1 - a)
            cost += c
            mxa = max(a, mxa + 1)
            k += 1
        else:
            if mxa < a:
                mxa = a
                k += 1
    if k >= K:
        ans = min(ans, cost)
print(ans)

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
if K == 1:
    print((0))
    exit()
ans = 10**12
for b in range(1 << (N - 1)):
    h = A[0]
    k = 1
    cost = 0
    for i in range(N - 1):
        a = A[i + 1]
        if a > h:
            k += 1
            h = a
        elif b & (1 << i):
            k += 1
            cost += h + 1 - a
            h += 1
    if k >= K:
        ans = min(ans, cost)
print(ans)

-ans = float("inf")
+if K == 1:
+    print((0))
+    exit()
+ans = 10**12
-    mxa = A[0]
+    h = A[0]
-    for i, a in enumerate(A[1:]):
-        if b & (1 << i):
-            c = max(0, mxa + 1 - a)
-            cost += c
-            mxa = max(a, mxa + 1)
+    for i in range(N - 1):
+        a = A[i + 1]
+        if a > h:
-        else:
-            if mxa < a:
-                mxa = a
-                k += 1
+            h = a
+        elif b & (1 << i):
+            k += 1
+            cost += h + 1 - a
+            h += 1


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

a = set([1,2,3,4,5,6,7,8,9])

prev = set([1,2,3,4,5,6,7,8,9])

while len(a) < K:

    temp = set()

    for now in prev:

        c = now%10

        if c == 0:

            temp.add(now*10)

            temp.add(now*10+1)

        elif c == 9:

            temp.add(now*10+9)

            temp.add(now*10+8)

        else:

            temp.add(now*10+c-1)

            temp.add(now*10+c)

            temp.add(now*10+c+1)

    prev = temp

    a = a|temp

print((sorted(list(a))[K-1]))

K = int(eval(input()))
a = set([1, 2, 3, 4, 5, 6, 7, 8, 9])
prev = set([1, 2, 3, 4, 5, 6, 7, 8, 9])
while len(a) < K:
    temp = set()
    for now in prev:
        c = now % 10
        if c == 0:
            temp.add(now * 10)
            temp.add(now * 10 + 1)
        elif c == 9:
            temp.add(now * 10 + 9)
            temp.add(now * 10 + 8)
        else:
            temp.add(now * 10 + c - 1)
            temp.add(now * 10 + c)
            temp.add(now * 10 + c + 1)
    prev = temp
    a = a | temp
print((sorted(list(a))[K - 1]))


Input:
import sys

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

if((B-A) < K):

    for i in range(A,B+1):

        print(i)

    sys.exit()

ansmin=[i for i in range(A,A+K,1)]

ansmax=[i for i in range(B,B-K,-1)]

ans=ansmin+ansmax

ans=set(ans)

ans=sorted(ans)

for a in ans:

    print(a)

def myAnswer(A:int,B:int,K:int) -> int:

   if(B - A >= K):

      ans = [i for i in range(A,A+K) ]

      for i in range(B,B-K,-1):

         ans.append(i)

   else:

      ans = [i for i in range(A,B+1)]

   ans = list(set(ans))

   ans.sort()

   for a in ans:

      print(a)

def modelAnswer():

   tmp=1

def main():

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

   myAnswer(A,B,K)

if __name__ == '__main__':

   main()

import sys

A, B, K = list(map(int, input().split()))
if (B - A) < K:
    for i in range(A, B + 1):
        print(i)
    sys.exit()
ansmin = [i for i in range(A, A + K, 1)]
ansmax = [i for i in range(B, B - K, -1)]
ans = ansmin + ansmax
ans = set(ans)
ans = sorted(ans)
for a in ans:
    print(a)

def myAnswer(A: int, B: int, K: int) -> int:
    if B - A >= K:
        ans = [i for i in range(A, A + K)]
        for i in range(B, B - K, -1):
            ans.append(i)
    else:
        ans = [i for i in range(A, B + 1)]
    ans = list(set(ans))
    ans.sort()
    for a in ans:
        print(a)

def modelAnswer():
    tmp = 1

def main():
    A, B, K = list(map(int, input().split()))
    myAnswer(A, B, K)

if __name__ == "__main__":
    main()

+def myAnswer(A: int, B: int, K: int) -> int:

+        ans = [i for i in range(A, A + K)]

+        ans = [i for i in range(A, B + 1)]

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

-ansmin = [i for i in range(A, A + K, 1)]

-ansmax = [i for i in range(B, B - K, -1)]

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


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

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

XY = [tuple(map(int,input().split())) for i in range(M)]

if M==N-1:

    print((0))

    exit()

class UnionFind:

    def __init__(self,N):

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

        self._size = [1] * N

        self.count = 0

    def root(self,a):

        if self.parent[a] == a:

            return a

        else:

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

            return self.parent[a]

    def is_same(self,a,b):

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

    def unite(self,a,b):

        ra = self.root(a)

        rb = self.root(b)

        if ra == rb: return

        if self._size[ra] < self._size[rb]: ra,rb = rb,ra

        self._size[ra] += self._size[rb]

        self.parent[rb] = ra

        self.count += 1

    def size(self,a):

        return self._size[self.root(a)]

uf = UnionFind(N)

for x,y in XY:

    if uf.is_same(x,y): continue

    uf.unite(x,y)

for i in range(N):

    uf.root(i)

from collections import defaultdict

dic = defaultdict(lambda: set())

for i in range(N):

    dic[uf.root(i)].add(i)

need = (len(dic)-1)*2

if need > N:

    print('Impossible')

    exit()

ans = used = 0

import heapq

hq = []

heapq.heapify(hq)

for r,vs in list(dic.items()):

    mini = -1

    mina = 10**9+1

    for i in vs:

        if A[i] < mina:

            mina = A[i]

            mini = i

    ans += mina

    used += 1

    for i in vs:

        if i==mini: continue

        heapq.heappush(hq, A[i])

for _ in range(need - used):

    ans += heapq.heappop(hq)

print(ans)

import sys

input = sys.stdin.readline

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

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

XY = [tuple(map(int,input().split())) for i in range(M)]

if (N-1-M)*2 > N:

    print('Impossible')

    exit()

class UnionFind:

    def __init__(self,N):

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

        self._size = [1] * N

        self.count = 0

    def root(self,a):

        if self.parent[a] == a:

            return a

        else:

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

            return self.parent[a]

    def is_same(self,a,b):

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

    def unite(self,a,b):

        ra = self.root(a)

        rb = self.root(b)

        if ra == rb: return

        if self._size[ra] < self._size[rb]: ra,rb = rb,ra

        self._size[ra] += self._size[rb]

        self.parent[rb] = ra

        self.count += 1

    def size(self,a):

        return self._size[self.root(a)]

uf = UnionFind(N)

for x,y in XY:

    if uf.is_same(x,y): continue

    uf.unite(x,y)

for i in range(N):

    uf.root(i)

from collections import defaultdict

dic = defaultdict(lambda: [])

for i in range(N):

    r = uf.root(i)

    dic[r].append(A[i])

if len(dic)==1:

    print((0))

    exit()

ans = 0

arr = []

c = 0

for k in list(dic.keys()):

    dic[k].sort(reverse=True)

    ans += dic[k].pop()

    c += 1

    for a in dic[k]:

        arr.append(a)

rem = (N-1-M)*2 - c

if rem > len(arr):

    print('Impossible')

else:

    arr.sort()

    ans += sum(arr[:rem])

print(ans)

N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
XY = [tuple(map(int, input().split())) for i in range(M)]
if M == N - 1:
    print((0))
    exit()

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

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

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

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

    def size(self, a):
        return self._size[self.root(a)]

uf = UnionFind(N)
for x, y in XY:
    if uf.is_same(x, y):
        continue
    uf.unite(x, y)
for i in range(N):
    uf.root(i)
from collections import defaultdict

dic = defaultdict(lambda: set())
for i in range(N):
    dic[uf.root(i)].add(i)
need = (len(dic) - 1) * 2
if need > N:
    print("Impossible")
    exit()
ans = used = 0
import heapq

hq = []
heapq.heapify(hq)
for r, vs in list(dic.items()):
    mini = -1
    mina = 10**9 + 1
    for i in vs:
        if A[i] < mina:
            mina = A[i]
            mini = i
    ans += mina
    used += 1
    for i in vs:
        if i == mini:
            continue
        heapq.heappush(hq, A[i])
for _ in range(need - used):
    ans += heapq.heappop(hq)
print(ans)

import sys

input = sys.stdin.readline
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
XY = [tuple(map(int, input().split())) for i in range(M)]
if (N - 1 - M) * 2 > N:
    print("Impossible")
    exit()

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

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

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

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

    def size(self, a):
        return self._size[self.root(a)]

uf = UnionFind(N)
for x, y in XY:
    if uf.is_same(x, y):
        continue
    uf.unite(x, y)
for i in range(N):
    uf.root(i)
from collections import defaultdict

dic = defaultdict(lambda: [])
for i in range(N):
    r = uf.root(i)
    dic[r].append(A[i])
if len(dic) == 1:
    print((0))
    exit()
ans = 0
arr = []
c = 0
for k in list(dic.keys()):
    dic[k].sort(reverse=True)
    ans += dic[k].pop()
    c += 1
    for a in dic[k]:
        arr.append(a)
rem = (N - 1 - M) * 2 - c
if rem > len(arr):
    print("Impossible")
else:
    arr.sort()
    ans += sum(arr[:rem])
print(ans)

+import sys
+
+input = sys.stdin.readline
-if M == N - 1:
-    print((0))
+if (N - 1 - M) * 2 > N:
+    print("Impossible")
-dic = defaultdict(lambda: set())
+dic = defaultdict(lambda: [])
-    dic[uf.root(i)].add(i)
-need = (len(dic) - 1) * 2
-if need > N:
+    r = uf.root(i)
+    dic[r].append(A[i])
+if len(dic) == 1:
+    print((0))
+    exit()
+ans = 0
+arr = []
+c = 0
+for k in list(dic.keys()):
+    dic[k].sort(reverse=True)
+    ans += dic[k].pop()
+    c += 1
+    for a in dic[k]:
+        arr.append(a)
+rem = (N - 1 - M) * 2 - c
+if rem > len(arr):
-    exit()
-ans = used = 0
-import heapq
-hq = []
-heapq.heapify(hq)
-for r, vs in list(dic.items()):
-    mini = -1
-    mina = 10**9 + 1
-    for i in vs:
-        if A[i] < mina:
-            mina = A[i]
-            mini = i
-    ans += mina
-    used += 1
-    for i in vs:
-        if i == mini:
-            continue
-        heapq.heappush(hq, A[i])
-for _ in range(need - used):
-    ans += heapq.heappop(hq)
+else:
+    arr.sort()
+    ans += sum(arr[:rem])


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

from scipy.misc import comb

import sys

sys.setrecursionlimit(1000000000)

class UnionFind:

    def __init__(self, n):

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

        self.depth = [1] * (n + 1)

        self.count = [1] * (n + 1)

    def find(self, x):

        if self.parent[x] == x:

            if self.depth[x] > 2:

                self.depth[x] = 2

            return x

        else:

            self.parent[x] = self.find(self.parent[x])

            self.depth[x], self.count[x] = 0, 0

            return self.parent[x]

    def isSame(self, x, y):

        return self.find(x) == self.find(y)

    def union(self, x, y):

        x, y = self.find(x), self.find(y)

        if self.depth[x] < self.depth[y]:

            self.parent[x] = self.parent[y]

            self.count[y] += self.count[x]

            self.depth[x], self.count[x] = 0, 0

        else:

            self.parent[y] = self.parent[x]

            self.count[x] += self.count[y]

            self.depth[y], self.count[y] = 0, 0

            if self.depth[x] == self.depth[y]:

                self.depth[x] += 1

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

A, B = [], []

for _ in range(M):

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

    A.append(a)

    B.append(b)

A.reverse()

B.reverse()

groups = UnionFind(N)

ans = [comb(N, 2, exact=True)]

for i in range(M):

    tmp = ans[-1]

    if not groups.isSame(A[i], B[i]):

        nA, nB = groups.count[groups.find(

            A[i])], groups.count[groups.find(B[i])]

        tmp -= nA * nB

        groups.union(A[i], B[i])

    ans.append(tmp)

for i in range(M):

    print((ans[-(i + 2)]))

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

from scipy.misc import comb

import sys

sys.setrecursionlimit(1000000000)

class UnionFind:

    def __init__(self, n):

        # parent[x] < 0 means x is root and abs(parent[x]) == size[x]

        self.parent, self.depth = [-1] * (n + 1), [0] * (n + 1)

    def find(self, x):

        if self.parent[x] < 0:

            return x

        else:

            self.parent[x] = self.find(self.parent[x])

            return self.parent[x]

    def isSame(self, x, y):

        return self.find(x) == self.find(y)

    def unite(self, x, y):

        x, y = self.find(x), self.find(y)

        if self.depth[x] > self.depth[y]:

            self.parent[x] += self.parent[y]

            self.parent[y] = x

        else:

            self.parent[y] += self.parent[x]

            self.parent[x] = y

            if self.depth[x] == self.depth[y]:

                self.depth[y] += 1

    def count(self, x):

        return - self.parent[self.find(x)]

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

AB = [tuple(map(int, input().split())) for _ in range(M)]

AB.reverse()

groups = UnionFind(N)

ans = [comb(N, 2, exact=True)]

for i in range(M):

    if groups.isSame(AB[i][0], AB[i][1]):

        ans.append(ans[-1])

    else:

        ans.append(ans[-1] - groups.count(AB[i][0]) * groups.count(AB[i][1]))

        groups.unite(AB[i][0], AB[i][1])

for i in range(M):

    print((ans[-(i + 2)]))

# -*- coding: utf-8 -*-
from scipy.misc import comb
import sys

sys.setrecursionlimit(1000000000)

class UnionFind:
    def __init__(self, n):
        self.parent = [i for i in range(n + 1)]
        self.depth = [1] * (n + 1)
        self.count = [1] * (n + 1)

    def find(self, x):
        if self.parent[x] == x:
            if self.depth[x] > 2:
                self.depth[x] = 2
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            self.depth[x], self.count[x] = 0, 0
            return self.parent[x]

    def isSame(self, x, y):
        return self.find(x) == self.find(y)

    def union(self, x, y):
        x, y = self.find(x), self.find(y)
        if self.depth[x] < self.depth[y]:
            self.parent[x] = self.parent[y]
            self.count[y] += self.count[x]
            self.depth[x], self.count[x] = 0, 0
        else:
            self.parent[y] = self.parent[x]
            self.count[x] += self.count[y]
            self.depth[y], self.count[y] = 0, 0
            if self.depth[x] == self.depth[y]:
                self.depth[x] += 1

N, M = list(map(int, input().split()))
A, B = [], []
for _ in range(M):
    a, b = list(map(int, input().split()))
    A.append(a)
    B.append(b)
A.reverse()
B.reverse()
groups = UnionFind(N)
ans = [comb(N, 2, exact=True)]
for i in range(M):
    tmp = ans[-1]
    if not groups.isSame(A[i], B[i]):
        nA, nB = groups.count[groups.find(A[i])], groups.count[groups.find(B[i])]
        tmp -= nA * nB
        groups.union(A[i], B[i])
    ans.append(tmp)
for i in range(M):
    print((ans[-(i + 2)]))

# -*- coding: utf-8 -*-
from scipy.misc import comb
import sys

sys.setrecursionlimit(1000000000)

class UnionFind:
    def __init__(self, n):
        # parent[x] < 0 means x is root and abs(parent[x]) == size[x]
        self.parent, self.depth = [-1] * (n + 1), [0] * (n + 1)

    def find(self, x):
        if self.parent[x] < 0:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    def isSame(self, x, y):
        return self.find(x) == self.find(y)

    def unite(self, x, y):
        x, y = self.find(x), self.find(y)
        if self.depth[x] > self.depth[y]:
            self.parent[x] += self.parent[y]
            self.parent[y] = x
        else:
            self.parent[y] += self.parent[x]
            self.parent[x] = y
            if self.depth[x] == self.depth[y]:
                self.depth[y] += 1

    def count(self, x):
        return -self.parent[self.find(x)]

N, M = list(map(int, input().split()))
AB = [tuple(map(int, input().split())) for _ in range(M)]
AB.reverse()
groups = UnionFind(N)
ans = [comb(N, 2, exact=True)]
for i in range(M):
    if groups.isSame(AB[i][0], AB[i][1]):
        ans.append(ans[-1])
    else:
        ans.append(ans[-1] - groups.count(AB[i][0]) * groups.count(AB[i][1]))
        groups.unite(AB[i][0], AB[i][1])
for i in range(M):
    print((ans[-(i + 2)]))

-        self.parent = [i for i in range(n + 1)]

+        # parent[x] < 0 means x is root and abs(parent[x]) == size[x]

-            self.depth[x], self.count[x] = 0, 0

-        if self.depth[x] < self.depth[y]:

-            self.parent[x] = self.parent[y]

-            self.count[y] += self.count[x]

-            self.depth[x], self.count[x] = 0, 0

+        if self.depth[x] > self.depth[y]:

+            self.parent[x] += self.parent[y]

-            self.parent[y] = self.parent[x]

-            self.count[x] += self.count[y]

-            self.depth[y], self.count[y] = 0, 0

+            self.parent[y] += self.parent[x]

+        return -self.parent[self.find(x)]

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

+AB = [tuple(map(int, input().split())) for _ in range(M)]

-        nA, nB = groups.count[groups.find(A[i])], groups.count[groups.find(B[i])]

+    if groups.isSame(AB[i][0], AB[i][1]):

+        ans.append(ans[-1] - groups.count(AB[i][0]) * groups.count(AB[i][1]))

+        groups.unite(AB[i][0], AB[i][1])


Input:
from collections import deque

n = int(eval(input()))

p_que = deque(list(map(int, input().split())))

q_que = deque(list(map(int, input().split())))

que = deque(i for i in range(1, n+1))

cnt = 0

a = 0

b = 0

def dfs(d, q):

  # print('-'*10, q)

  # sorted(q)

  for i in list(q):

    # print(i, d, q)

    d.append(i)

    q.remove(i)

    # print('>', d, q)

    if q == deque([]):

      global cnt

      cnt += 1

      # print('>>>', cnt, d, q)

      if d == p_que:

        global a

        a = cnt

      if d == q_que:

        global b

        b = cnt

      # print('return')

      d.remove(i)

      q.appendleft(i)

      return

    # print('tansaku')

    dfs(d, q)

    # print('>returned')

    # print('---', i, d, q)

    d.remove(i)

    if i > q[0]:

      q.append(i)

    else:

      q.appendleft(i)

    q = deque(sorted(q))

dfs(deque(), que)

# print(a, b)

print((abs(a-b)))

from itertools import permutations

n = int(eval(input()))

P = tuple(map(int, input().split()))

Q = tuple(map(int, input().split()))

n_list = [x for x in range(1, n+1)]

# print(list(permutations(n_list, n)))

a = b = 0

for n, i in enumerate(permutations(n_list, n)):

  # print(n, i)

  if i == P:

    a = n

  if i == Q:

    b = n

print((abs(a-b)))

from collections import deque

n = int(eval(input()))
p_que = deque(list(map(int, input().split())))
q_que = deque(list(map(int, input().split())))
que = deque(i for i in range(1, n + 1))
cnt = 0
a = 0
b = 0

def dfs(d, q):
    # print('-'*10, q)
    # sorted(q)
    for i in list(q):
        # print(i, d, q)
        d.append(i)
        q.remove(i)
        # print('>', d, q)
        if q == deque([]):
            global cnt
            cnt += 1
            # print('>>>', cnt, d, q)
            if d == p_que:
                global a
                a = cnt
            if d == q_que:
                global b
                b = cnt
            # print('return')
            d.remove(i)
            q.appendleft(i)
            return
        # print('tansaku')
        dfs(d, q)
        # print('>returned')
        # print('---', i, d, q)
        d.remove(i)
        if i > q[0]:
            q.append(i)
        else:
            q.appendleft(i)
        q = deque(sorted(q))

dfs(deque(), que)
# print(a, b)
print((abs(a - b)))

from itertools import permutations

n = int(eval(input()))
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
n_list = [x for x in range(1, n + 1)]
# print(list(permutations(n_list, n)))
a = b = 0
for n, i in enumerate(permutations(n_list, n)):
    # print(n, i)
    if i == P:
        a = n
    if i == Q:
        b = n
print((abs(a - b)))

-p_que = deque(list(map(int, input().split())))

-q_que = deque(list(map(int, input().split())))

-que = deque(i for i in range(1, n + 1))

+for n, i in enumerate(permutations(n_list, n)):


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

print((int(n/2) if n%2 == 0 else n//2+1))

n = int(eval(input()))
print((int(n / 2) if n % 2 == 0 else n // 2 + 1))


Input:
from sys import stdin

input = stdin.readline

N = int(eval(input()))

txy = [[int(j) for j in input().split()] for i in range(N)]

def main():

    pt = 0

    px = 0

    py = 0

    flg = False

    for t, x, y in txy:

        dt = t - pt - abs(x - px) - abs(y - py)

        # 余った時間が奇数 戻れない

        if dt < 0 or dt % 2 == 1:

            break

        pt = t

        px = x

        py = y

    else:

        # break しなかった 完走

        flg = True

    print(("Yes" if flg else "No"))

    return

main()

from sys import stdin

input = stdin.readline

lines = stdin.readlines

N = int(eval(input()))

txy = ((list(map(int, line.split()))) for line in lines())

def main():

    pt = 0

    px = 0

    py = 0

    flg = False

    for t, x, y in txy:

        dt = t - pt - abs(x - px) - abs(y - py)

        # 余った時間が奇数 戻れない

        if dt < 0 or dt % 2 == 1:

            break

        pt = t

        px = x

        py = y

    else:

        # break しなかった 完走

        flg = True

    print(("Yes" if flg else "No"))

    return

main()

-txy = [[int(j) for j in input().split()] for i in range(N)]

+txy = ((list(map(int, line.split()))) for line in lines())