Harryxun/stf_run huggingface dataset:
import sys
input = sys.stdin.buffer.readline
#再帰回数の上限を変更
# sys.setrecursionlimit(10**9)

N = int(input())
# v = [list(map(int, input().split())) for _ in range(N-1)]

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

for i in range(N-1):
    v1, v2, w = map(int, input().split())
    edge[v1-1].append((v2-1, w))
    edge[v2-1].append((v1-1, w))

color = [-1 for _ in range(N)]
color[0] = 1

def dfs(x):
    for v, w in edge[x]:
        if color[v] == -1:
            color[v] = (w + color[x])%2
            dfs(v)



dfs(0)
print(*color, sep="\n")

### FIXED CODE ###

import sys
input=sys.stdin.buffer.readline
sys.setrecursionlimit(10**9)
n=int(input())
edges=[[] for i in range(n)]
for i in range(n-1):
    a,s,w=map(int,input().split())
    edges[a-1].append([s-1,w]);edges[s-1].append([a-1,w])
colors=[-1]*n
colors[0]=1
def dfs(now):
    for to,cost in edges[now]:
        if colors[to]==-1:
            colors[to]=(cost+colors[now])%2
            dfs(to)

dfs(0)
print(*colors,sep="\n")
from collections import deque

n = int(input())
a = deque(list(range(1,n,1)))
a.appendleft(n)

c = 0
for i in range(n):
	c += a[i]%(i+1)
print(c)

### FIXED CODE ###

print((lambda n: n*(n-1)//2)(int(input())))
i = 1
while True:
     x = int(input())
     if x == 0 break:
     print('Case {} : {}'.format(i, x))
     i += 1

### FIXED CODE ###

i = 1
while True:
     x = int(input())
     if x == 0: break
     print('Case {}: {}'.format(i, x))
     i += 1
x,a,b=map(int,input().split())
print((x-a)%b)

### FIXED CODE ###

x,a,b=[int(input()) for _ in range(3)]
print((x-a)%b)
n,m=map(int,input().split())
for i in range(n):
    k,*a=list(map(int,input().split()))
    b=a[0]
    for j in range k:
        b=b-a[j]
        print(len(b))
    
    

### FIXED CODE ###

n,m=map(int,input().split())
s=set(range(1,m+1))
for i in range(n):
    k,*a=list(map(int,input().split()))
    s&=set(a)
print(len(s))
N, M = map(int, input().split())
As = list(map(int, input().split()))
BC = [tuple(map(int, input().split())) for _ in range(M)]

As = sorted(As)
BC = sorted(BC, key=lambda x: x[1], reverse=True)


def f(As, num, val):
    count = 0
    for i in range(num):
        if As[i] < val:
            count += 1
        else:
            break
    return val * count, As[count:]


sum__ = 0
for num, val in BC:
    sum_, As = f(As, num, val)
    sum__ += sum_

print(sum__ + sum(As))

### FIXED CODE ###

import sys

fin = sys.stdin.readline

N, M = map(int, fin().split())
As = list(map(int, fin().split()))
BC = [tuple(map(int, fin().split())) for _ in range(M)]

As = sorted(As)
# BC = sorted(BC, key=lambda x: x[1], reverse=True)

BC_ = {}
for num, val in BC:
    if val in BC_:
        BC_[val] += num
    else:
        BC_[val] = num

BC_ = sorted(BC_.items(), reverse=True)

#
# def f(a, n, v):
#     if a[min(n-1, len(a)-1)] < v:
#         return v * min(n, len(a)), a[n:]
#     count = 0
#     for i in range(min(n, len(a))):
#         if a[i] < v:
#             count += 1
#         else:
#             break
#     return v * count, a[count:]


sum__ = 0
now = 0
for val, num in BC_:
    if now >= len(As) or As[now] >= val:
        break

    if As[min(num - 1 + now, len(As) - 1)] < val:
        sum_ = val * min(num, len(As) - now)
        now += min(num, len(As) - now)
    else:
        count = 0
        for i in range(min(num, len(As)-now)):
            if As[i + now] < val:
                count += 1
            else:
                break
        sum_ = val * count
        now += count
    sum__ += sum_

print(sum__ + sum(As[now:]))
a, b, x = map(int, raw_input().split())

i = a
count = 0
while i < b + 1:
    if x%i == 0:
        count = count + 1
    i = i + 1

print count


### FIXED CODE ###

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

i = a
count = 0
count_b = 0
count_a = 0

count_b = b/x
count_a = (a-1)/x


print count_b - count_a
n = int(input())
s = input()
x = sum(1 if s[i] != "#" else 0 for i in range(n))
y = sum(0 if s[i] != "#" else 1 for i in range(n))
print(min(x, y))

### FIXED CODE ###

btn=input().split()
A=int(btn[0])
B=int(btn[1])
C=int(btn[2])
if A < C < B:
	print("Yes")
elif A > C > B:
	print("Yes")
else:
	print("No")
A,B,C,X=[int(input()) for i in range(4)]
cnt = 0
for a in range(0,A+1):
    Y = X - 500*a
    if Y==0:
        cnt += 1
        continue
    elif Y<0:
        break
    for b in range(0,B+1):
        Z = Y - 100*b
        if Z==0:
            cnt += 1
            continue
        elif Z<0:
            break
        if W%50 == 0:
            cnt += 1
print(cnt)

### FIXED CODE ###

a,b,c,X=[int(input()) for i in range(4)]
print([500*x+100*y+50*z for z in range(c+1) for y in range(b+1) for x in range(a+1)].count(X))
#!/usr/bin/env python3
import math


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

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

g = A[0]
for i in range(1,N):
    g = lcm(g,A[i])
g -= 1

ans = 0
for a in A:
    ans += g % a
print(ans)


### FIXED CODE ###

#!/usr/bin/env python3
#import math
import fractions

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

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

g = A[0]
for i in range(1,N):
    g = lcm(g,A[i])
g -= 1

ans = 0
for a in A:
    ans += g % a
print(ans)
h,w = map(int,input().split())
w += 2
print('#'*w)
for i in (h):
    print('#' + input() +'#')
print('#'*w)

### FIXED CODE ###

h,w = map(int,input().split())
w += 2
print('#'*w)
for i in range(h):
    print('#' + input() +'#')
print('#'*w)
count = 0
    for n in range (N):
        for nn in range(N):
            distance = 0
            for d in range(D):
                kou = (all_list[n][d] - all_list[nn][d])**2
                distance += kou
            for s in range(250):
                if distance == s**2:
                    count += 1
                    break
    print(round((count - N) / 2))

### FIXED CODE ###

N,D =map(int, input().split())
all_list = [list(map(int, input().split())) for i in range(N)]
#>>>4
count = 0
for n in range (N):
    for nn in range(n):
        distance = 0
        for d in range(D):
            kou = (all_list[n][d] - all_list[nn][d])**2
            distance += kou
        for s in range(250):
            if distance == s**2:
                count += 1
                break
print(count)
a, b = input().split()
if a == "A":
    a1 = 10
if a == "B":
    a1 = 11
if a == "C":
    a1 = 12
if a == "D":
    a1 = 13
if a == "E":
    a1 = 14
if a == "F":
    a1 = 15
if b == "A":
    b1==10
if b == "B":
    b1 = 11
if b == "C":
    b1 = 12
if b == "D":
    b1 = 13
if b == "E":
    b1 = 14
if b == "F":
    b1 = 15
if a1 > b1:
    print(">")
elif a1 == b1:
    print("=")
else :
    print("<")

### FIXED CODE ###


a, b = input().split()
if a == "A":
    a1 = 10
if a == "B":
    a1 = 11
if a == "C":
    a1 = 12
if a == "D":
    a1 = 13
if a == "E":
    a1 = 14
if a == "F":
    a1 = 15
if b == "A":
    b1 =10
if b == "B":
    b1 = 11
if b == "C":
    b1 = 12
if b == "D":
    b1 = 13
if b == "E":
    b1 = 14
if b == "F":
    b1 = 15
if a1 > b1:
    print(">")
elif a1 == b1:
    print("=")
else :
    print("<")
l = map(int, input().split())
a=list(l)
x=a[2]-a[0]
y=a[3]-a[1]
x3=a[2]-y
y3=a[3]+x
x4=a[1]-y
y4=a[1]+x
print(x3, y3, x4, y4)


### FIXED CODE ###

N= int(input())
print(N//2 * (N-N//2))
M, K =map(int, input().split())
if K >= 2**M:
    ans = -1
elif M == 0:
    ans = [0, 0]
elif M == 1:
    if K == 0:
        ans = [0, 1, 1, 0]
    else:
        ans = [0, 0, 1, 1]
else:
    ans = list(range(K-1)) + list(range(K+1, 2**M)) +[K] + list(range(2**M-1, K, -1))+list(range(K-1, -1, -1)) +[K]
print(*ans)

### FIXED CODE ###

M, K =map(int, input().split())
if K >= 2**M:
    ans = [-1]
elif M == 0:
    ans = [0, 0]
elif M == 1:
    if K == 1:
        ans = [-1]
    else:
        ans = [0, 0, 1, 1]
else:
    ans = list(range(K)) + list(range(K+1, 2**M)) +[K] + list(range(2**M-1, K, -1))+list(range(K-1, -1, -1)) +[K]
print(*ans)
import sys
 
print(int(sys.argv[1]) ** 3)

### FIXED CODE ###

print(int(input())**3)
abc=sorted(list(map(int,input().split())))
if a==c:
    print(1)
elif a==b or b==c:
    print(2)
else:
    print(3)


### FIXED CODE ###

abc=sorted(list(map(int,input().split())))
if abc[0]==abc[2]:
    print(1)
elif abc[0]==abc[1] or abc[1]==abc[2]:
    print(2)
else:
    print(3)
a,b,c,d,e,k = map(int,input().split())

if e - a > k:
	print(":(")
else:
    print("Yay!")

### FIXED CODE ###

a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

if e - a > k:
	print(":(")
else:
	print("Yay!")
int.("A")
int.("N")
if N%500<=A:
  print ("Yes")
else:
  print("No")

### FIXED CODE ###

a = int(input())
n = int(input())
if((a%500)<=n):
  print("Yes")
else:
  print("No")
n = int(input())
s = [input() for _ in range(n)]

l = []
c=0
for i in s:
    if i not in l:
        l.append(i)
	c+=1
print(c)

### FIXED CODE ###

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

import collections

c = collections.Counter(s)

print(len(c.keys()))
# coding: utf-8
import os
import time
import re
import math
 
N=input()
print(180*(N-2))

### FIXED CODE ###

# coding: utf-8
import os
import time
import re
import math
 
N=int(input())
print(180*(N-2))
n, y = map(int, input().split())


def helper(n,y):
    for ten in range(y,-1,-1):

        for five in range(y-ten, -1,-1):
            
            sum = 10000*ten + 5000*five + 1000*one

            if n < sum:
                continue

            if n == sum:
                return('{} {} {}'.format(ten,five,n-ten-five))

            else:
                return ('-1 -1 -1')

    return('-1 -1 -1')

print(helper(n,y))

### FIXED CODE ###

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

def helper(n,y):

    for ten in range(n,-1,-1):
        for five in range(n-ten, -1,-1):


            one = n-ten-five
            sum = 10000*ten + 5000*five + 1000*one

            if y == sum:
                return('{} {} {}'.format(ten,five,one))


    return('-1 -1 -1')

print(helper(n,y))
import numpy as np
N=int(input())
root=int(np.sqrt(N))+1
a=1
b=N
for i in range(root, 0, -1):
    if N%i==0:
        a=i
        b=N//i
        break
print(a-1+b-1)

### FIXED CODE ###

import numpy as np
N=int(input())
root=int(np.sqrt(N)//1)
a=N
b=N
for i in range(root, 0, -1):
    if N%i==0:
        a=i
        b=N//i
        break
print(a-1+b-1)
n,k = input().split()
if n >= 10:
    print(k)
else:
    print(k+(100*(10-n)))

### FIXED CODE ###

n,k = map(int,input().split())
if n >= 10:
    print(k)
else:
    print(k+(100*(10-n)))
n = int(input())
t, a = [ int(v) for v in input().split() ]
height_list = [ abs(t-a-int(V)*0.006) forfor v in input().split() ]
print(height_list.index(min(height_list))+1)


### FIXED CODE ###

n = int(input())
t, a = [ int(v) for v in input().split() ]
height_list = [ abs(t-a-int(v)*0.006) for v in input().split() ]
print(height_list.index(min(height_list))+1)
from heapq import heappop, heappush
n, m = map(int, input().split())
lst = [list(map(int, input().split())) for i in range(n)]
lst_f = [[] for i in range(m)]
#lst = sorted(lst, key=lambda x:x[0])
#lst = sorted(lst, key=lambda x:x[1], reverse=True)
cnt = 0
ans = 0
cntup = m
for a, b in lst:
  if a <= m:
    lst_f[a-1].append(b)
  #print(filter(lambda y:y<=m-i, map(lambda x:x[0], lst)))
  #lst2 = list(filter(lambda y:y[1]<=m-i, lst))
avb = [] 
for i in lst_f:
  for j in i:
    avb.append(-j)
  if avb != []:
    ans -= avb.pop(min(avb))
print(ans)


### FIXED CODE ###

from heapq import heappop, heappush
n, m = map(int, input().split())
lst = [list(map(int, input().split())) for i in range(n)]
lst_f = [[] for i in range(m)]
#lst = sorted(lst, key=lambda x:x[0])
#lst = sorted(lst, key=lambda x:x[1], reverse=True)
cnt = 0
ans = 0
cntup = m
for a, b in lst:
  if a <= m:
    lst_f[a-1].append(b)
  #print(filter(lambda y:y<=m-i, map(lambda x:x[0], lst)))
  #lst2 = list(filter(lambda y:y[1]<=m-i, lst))
avb = [] 
for i in lst_f:
  for j in i:
    heappush(avb, -j)
  if avb != []:
    ans -= heappop(avb)
print(ans)
#include<bits/stdc++.h>
using namespace std;
int main(){
    string S ;
    int Q;
    string query1,query;
    cin>>S;
    cin>>Q;
    for(int i = 1; i <= Q;i++){
        getline(cin, query1);
        query = query1;
        if(query[0]=='1'){
            reverse(S.begin(), S.end()); 
        }else{
            if(query[2]=='1'){
                S = query[4] + S;
            }else
            {
                S = S + query[4];
            }
            
        }
    }
    cout<<S<<endl;
	return 0;
}

### FIXED CODE ###

n, a, b = map(int, input().split())
period = a+b
times = n//period
k = n%period
n =  a if k >a else k
print(times*a + n)
INF = 10 ** 20
 
n,k = map(int,input().split())
height = list(map(int,input().split()))
dp = [INF]*(n+1)
dp[0] = 0
 
for step in range(1, k+1):
    for i in range(step,n):
        dp[i] = min(dp[i], dp[i-step]+abs(h[i]-h[i-step]))
 
print(dp[n-1])

### FIXED CODE ###

N,K = map(int,input().split())
h = list(map(int,input().split()))
INF = 10**10
 
dp = [INF]*N
dp[0] = 0
 
for i,hi in enumerate(h):
    if i == 0:
        continue
    s = i-K if i-K >= 0 else 0
    dp[i] = min([dpk + abs(hi-hk) for dpk,hk in zip(dp[s:i],h[s:i])])
 
print(dp[-1])
N,M = map(int,input().split())
a = []
for i in range(M):
    a += [int(input())]

if N == 1:  print(1)
elif N == 2:
    if 1 in a:  print(1)
    else:   print(2)
else:
    temp1, temp2 = 0,0
    if 1 not in a:  temp1 = 1
    if 2 not in a:  temp2 = 1 + temp1
    
    for i in range(2,N):
        temp = 0
        if i+1 not in a:    temp = temp1 + temp2
        temp1 = temp2
        temp2 = temp

print( int(temp % 1000000007) )

### FIXED CODE ###

N,M = map(int, input().split())
a = set()
for i in range(M):
    a.add(int(input()))

if N == 1:  print(1)
elif N == 2:
    if 1 == M:  print(1)
    else:   print(2)
else:
    temp, temp1, temp2 = 0,0,0
    if 1 not in a:  temp1 = 1
    if 2 not in a:  temp2 = 1 + temp1
    
    for i in range(2,N-1):
        temp = 0
        if i+1 not in a:    temp = temp1 + temp2
        temp1 = temp2
        temp2 = temp

    print( int((temp1+temp2) % 1000000007) )
n = int(input())
        xor_arr = list(map(int, input().split()))
        xor_of_xor = 0
        for elm in xor_arr:
            xor_of_xor = xor_of_xor ^ elm
        scarf_val = [xor_of_xor ^ elm for elm in xor_arr]
        print(" ".join(str(x) for x in scarf_val))

### FIXED CODE ###

n = int(input())
xor_arr = list(map(int, input().split()))
xor_of_xor = 0
for elm in xor_arr:
    xor_of_xor = xor_of_xor ^ elm
scarf_val = [xor_of_xor ^ elm for elm in xor_arr]
         
print(" ".join(str(x) for x in scarf_val))
inputs = input().split()
 
if -100 <= inputs[0] and inputs[1] <= 100:
	print(max([inputs[0]+inputs[1], inputs[0]-inputs[1], inputs[0]*inputs[1]]))
else:
	raise ValueError

### FIXED CODE ###

inputs = input().split()
a      = int(inputs[0])
b      = int(inputs[1])
if -100 <= a and b <= 100:
	print(max([a+b, a-b, a*b]))
else:
	raise ValueError
K = int(input())
A = list(map(int, input().split()))

def winner_count(N, A=A):
    for a in A:
        N = a*(N//a)
    return N

class lazy_eval_list(list):
    def __init__(self, func, a):
        super().__init__(a)
        self._func = func
        
    def __getitem__(self, key):
        return self._func(super().__getitem__(key))

lazy_winner_count_N = lazy_eval_list(winner_count, range(1,2+sum(A)))

import bisect
_min = bisect.bisect_left(lazy_winner_count_N, 2)
_max = bisect.bisect_right(lazy_winner_count_N, 2)-1

if _min > _max:
	print(-1)
else:
	print(_min, _max)

### FIXED CODE ###

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

def winner_count(N, A=A):
    for a in A:
        N = a*(N//a)
    return N

def bisect_left(func, l, r, target):
    # n>=i ⇒ func(n) <= targetを満たす最小のi
    # l=1, r=sum(A)+2
    # func(l)<= target, target<=func(r)
    if l==r:
        return 0
    if l+1==r:
        if func(l)< target:
            return r
        else:
            return l
    c = (l+r)//2
    if target <= func(c):
        return bisect_left(func, l, c, target)
    else:
        return bisect_left(func, c, r, target)

def bisect_right(func, l,r, target):
    if l==r:
        return 0
    if l+1==r:
        if target < func(r):
            return l
        else:
            return r
    c = (l+r)//2
    if target < func(c):
        return bisect_right(func, l, c, target)
    else:
        return bisect_right(func, c, r, target)

_min = bisect_left(winner_count, 1, sum(A)+2, 2)
_max = bisect_right(winner_count, 1, sum(A)+2, 2)


if _min > _max:
	print(-1)
else:
	print(_min, _max)
N = int(input())

for i in range(0,N//4+1):
    if (N - 4*i)%7 == 0:
        print('Yes')
        sys.exit()
print('No')

### FIXED CODE ###

N = int(input())
for i in range(N//4+1):
    if (N - 4*i)%7 == 0:
        print('Yes')
        exit()
print('No')
X, Y=map(int,input().split())
num_2=Y/X
count=1
if X==1 and Y<=576460752303423488 and Y>=576460752303423480:
  print(0/0)
while num_2>=2:
    num_2=num_2/2
    count+=1
print(count)

### FIXED CODE ###

X, Y=map(int,input().split())
num_2=Y/X
count=1
if X==1 and Y==576460752303423487:
  print(59)
  exit()
while num_2>=2:
    num_2=num_2/2
    count+=1
print(count)
import itertools

N, C = map(int, input().split())
D = []
for _ in range(C):
    D.append(list(map(int, input().split())))

diff_by_pos_color_pair = [[0 for _ in range(C)] for _ in range(3)]
for i in range(N):
    for j, color_from in enumerate(map(lambda x: int(x) - 1, input().split())):
        pos = (i + j) % 3
        for color_to in range(C):
            diff_by_pos_color_pair[pos][color_to] += D[color_from][color_to]


min_diff = float("inf")
for ccs in itertools.permutations(range(C), 3):
    diff = 0
    for pos, color in enumerate(ccs):
        diff += diff_by_pos_color_pair[pos][ccs[color]]
    min_diff = min(min_diff, diff)

print(min_diff)


### FIXED CODE ###

import itertools

N, C = map(int, input().split())
# N, C = 500, 30

D = []
for _ in range(C):
    D.append(list(map(int, input().split())))
    # D.append([100] * C)

diff_by_pos_color_pair = [[0 for _ in range(C)] for _ in range(3)]
for i in range(N):
    for j, color_from in enumerate(map(lambda x: int(x) - 1, input().split())):
        # for j, color_from in enumerate([0] * N):
        pos = (i + j) % 3
        for color_to in range(C):
            diff_by_pos_color_pair[pos][color_to] += D[color_from][color_to]


min_diff = float("inf")
for ccs in itertools.permutations(range(C), 3):
    diff = 0
    for pos, color in enumerate(ccs):
        diff += diff_by_pos_color_pair[pos][color]
    min_diff = min(min_diff, diff)

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

items = []
A_MAX = 0
B_MAX = 0
for _ in range(N):
    a, b, cost = map(int, input().split())
    items.append((a, b, cost))
    A_MAX += a
    B_MAX += b

dp = [[float('infinity')] * (A_MAX + 1) for _ in range(B_MAX + 1)]

dp[0][0] = 0

for a, b, cost in items:
    for i in range(B_MAX, -1, -1):
        for j in range(A_MAX, -1, -1):
            if i - b >= 0 and j - a >= 0:
                dp[i][j] = min(dp[i][j], dp[i - b][j - a] + cost)

ans = float('infinity')
for k in range(1, B_MAX + 1):
    for l in range(1, A_MAX + 1):
        if dp[k][l] == float('infinity'):
            continue
        if A * dp[k] == dp[l] * B:
            ans = min(ans, dp[k][l])
if ans == float('infinity'):
    print(-1)
else:
    print(ans)

### FIXED CODE ###

import sys



n, ma, mb = map(int, input().split())
abc = []

for _ in range(n):
    a, b, cost = map(int, input().split())
    abc.append((a, b, cost))

def main():
    sa = 0
    sb = 0
    for i in range(n):
        sa += abc[i][0]
        sb += abc[i][1]

    res = [[float('infinity')] * (sb + 1) for _ in range(sa + 1)]
    res[0][0] = 0

    for a, b, c in abc:

        for j in range(sa, -1, -1):
            for k in range(sb, -1, -1):
                if j >= a and k >= b:
                    res[j][k] = min(res[j][k], res[j-a][k-b] + c)

    ans = float('infinity')
    for i in range(1, min(sa//ma, sb//mb) + 1):
        ans = min(ans, res[ma*i][mb*i])

    if ans == float('infinity'):
        return -1
    else:
        return ans

if __name__ == '__main__':
    ans = main()
    print(ans)
n_price,k = map(str,input().split())
k = int(k)
n_length = len(n_price)
d_ng_list = list(map(str,input().split()))
restricted = True
answer = ""
for s in range(10):
	if str(s) not in d_ng_list:
		min_number = str(s)
		break

def find_number(i,restricted):
	if not restricted:
		return min_number
	for s in range(10):
		if str(s) not in d_ng_list and str(s) >= n_price[i]:
			if str(s) > n_price[i]:
				restricted = False
			return str(s)	

def rec_cal_pay(answer, i):
	if i == n_length-1:
		answer += find_number(i,restricted)
		print(answer)
		return
	else:
		c = find_number(i,restricted)
		rec_cal_pay(answer+c,i+1)
rec_cal_pay(answer, 0)


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)

n_price,k = map(str,input().split())
k = int(k)
n_length = len(n_price)
d_ng_list = list(input())
restrict = True
answer = ""
for s in range(10):
	if str(s) not in d_ng_list:
		min_number = str(s)
		break

def find_number(i):
	global restrict
	if not restrict:
		return min_number
	for s in range(10):
		if (str(s) not in d_ng_list) and str(s) >= n_price[i]:
			if s > int(n_price[i]):
				restrict = False
			return str(s)
	#if not found
	restrict = False
	return str(min_number+min_number)

def rec_cal_pay(answer, i, restrict):
	if i == n_length-1:
		answer += find_number(i)
		print(answer)
		return
	else:
		c = find_number(i)
		rec_cal_pay(answer+c, i+1, restrict)

rec_cal_pay(answer, 0, restrict)
ans = 0
n,m = map(int, input().split())
s_list = []
s_count_list = []
for _ in range(m):
    s = list(map(int,input().split()))
    s_count_list.append(s[0])
    s_list.append(s[1:])
oe = list(map(int,input().split()))   
seq = list(range(1, n+1))
for i in range(1, n+1):
    cmb = list(itertools.combinations(seq,i))
    for j in range(len(cmb)):
        ansv = []
        for k in range(m):
            ss = []
            for l in range(len(s_list[k])):
                if s_list[k][l] in list(cmb[j]):
                    ss.append(s_list[k][l])
            if len(ss)%2 == oe[k]:
                ansv.append(True)
            else:
                ansv.append(False)
        if all(ansv):
            ans += 1
print(ans)

### FIXED CODE ###

n,m=map(int,input().split())
s=[]
for _ in range(m):
    s.append(list(map(int,input().split()))[1:])
p=list(map(int,input().split()))

import itertools

cnt=0
for i in itertools.product([0,1],repeat=n):
    tn_arr=[]
    for j in range(m):
        on_cnt=0
        for k in range(len(s[j])):
            on_cnt+=i[s[j][k]-1]
        if on_cnt%2==p[j]:
            tn_arr.append(True)
        else:
            tn_arr.append(False)
    if all(tn_arr):
        cnt+=1

print(cnt)
N, M = map(int, readline().split())

print(N * (N - 1) / 2 + M * (M - 1) /2)

### FIXED CODE ###

N, M = map(int, input().split())
 
print(int(N * (N - 1) / 2 + M * (M - 1) /2))
A, B = map(int, input().split())

judge = False
for c in range(1,4):
  if A*B*C %2 == 1:
    judge = True
   

  
if judge == True:
  print("Yes")
else:
  print("False")
      
    

### FIXED CODE ###

A, B = map(int, input().split())
 
judge = False
for C in range(1,4):
  if (A*B*C) %2 == 1:
    judge = True
   
 
  
if judge == True:
  print("Yes")
else:
  print("No")
input()
lst = input().split()
for i in range(len(lst)):
    j = i - 1
    while (j >= 0) * (lst[j] > lst[i]):
        j -= 1
    lst[j+1:i+1] = lst[i] , *lst[j+1:i]
    print(*lst)

### FIXED CODE ###

n = int(input())
lst = list(map(int, input().split()))
for i in range(n):
    li = lst[i]
    j = i-1
    while j >= 0 and lst[j] > li:
        lst[j:j+2] = lst[j+1], lst[j]
        j -= 1
    print(*lst)