Harryxun/stf_run huggingface dataset:
from operator import itemgetter
n = int(input())
data = []
s = input()
data.append(s)
S = set(list(s))
for i in range(n-1):
    s = input()
    S = S & set(list(s))
    data.append(s)
A = []
for i in S:
    ans = float("inf")
    for j in range(n-1):
        ans = min(ans,data[j].count(i))
    A.append([i,ans])
A.sort(key=itemgetter(0))
s = ""
for i in A:
    s += i[0]*i[1]
print(s)

### FIXED CODE ###

from operator import itemgetter
import sys
n = int(input())
data = []
s = input()
if n == 1:
    L = list(s)
    L.sort()
    print("".join(L))
    sys.exit()
data.append(s)
S = set(list(s))
for i in range(n-1):
    s = input()
    S = S & set(list(s))
    data.append(s)
A = []
for i in S:
    ans = float("inf")
    for j in range(n-1):
        ans = min(ans,data[j].count(i))
    A.append([i,ans])
A.sort(key=itemgetter(0))
s = ""
for i in A:
    s += i[0]*i[1]
print(s)
import numpy as np
while True:
    n= int(input())
    if n == 0:
        break
    print(np.std(list(map(int, input().split())), dtype=np.float64))

### FIXED CODE ###

while True:
    n = int( input() )
    if n==0:
        break
    a=list(map(int, input().split()))
    m=sum(a)/n
    s=0
    for i in a:
        s+=(i-m)**2
    print( ( s/n)**0.5 )
import math
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse = True)

c = 0
for i in range(M):
  if c < M:
    x = max(math.log(A[0]/A[1] ,2)//1, 1)
    y = min(x, M - c)
    A[0] = A[0] //(2 ** y)
  A = sorted(A, reverse = True)
  
print(sum(A))


### FIXED CODE ###

import heapq
N, M = map(int, input().split())
A = list(map(int, input().split()))
Ai = list(map(lambda x: x*(-1), A))
heapq.heapify(Ai)

for i in range(M):
  maxA = heapq.heappop(Ai)*(-1)
  waribiki = maxA // 2
  heapq.heappush(Ai,waribiki * (-1))
  #print(Ai)
  
print(sum(Ai) * (-1))
s = input()
t = s.replace('BC', 'D')
answer = 0
A = 0
for i in range(len(t)):
    if t[i] == 'A':
        A+=1
    elif t[1] == 'D':
        answer+=A
    else:
        A = 0

print(answer)

### FIXED CODE ###

s = input()
t = s.replace('BC', 'D') 
answer = 0
A = 0
for i in range(len(t)):
    if t[i] == 'A':
        A+=1
    elif t[i] == 'D':
        answer+=A
    else:
        A = 0

print(answer)
x = int(input())
if not x == 0:
  for i in range(100):
    for j in range(-100,100):
      if i**5 - j**5 == x:
        a = i
        b = j
print(str(a)+" "+str(b))

### FIXED CODE ###

x = int(input())
a = 0
b = 0
if not x == 0:
  for i in range(1000):
    for j in range(-100,1000):
      if i**5 - j**5 == x:
        a = i
        b = j
      if a != 0 or b != 0:
        break
    if a != 0 or b != 0:
        break
    
print(str(a)+" "+str(b))
#途中
#全体に同じものを足すときは累積和を考えたい

N,Q = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N-1)]
PX = [list(map(int,input().split())) for _ in range(Q)]

graph = [set([]) for _ in range(N+1)]
for a,b in AB:
    graph[a].add(b)
    graph[b].add(a)
#どちらが親か分からないがとりあえずつながっている
#どちらが親かは後で判断

counter = [0 for _ in range(N+1)]
#counter[i]:i番目の頂点のカウンター
check = [False for _ in range(N+1)]
check[1] = True
#check[i]:i番目の頂点を発見した
#check[i] == True and i in graph[j]ならiはjの親

for p,x in PX:
    counter[p] += x

def cal(graph,counter,edge,parent):
    for e in (graph[edge]-parent):
        counter[e] += counter[edge]
    check[edge] = True
    for e in (graph[edge]-parent):
        cal(graph,counter,e,set([edge]))

cal(graph,counter,1,set())

print(str(counter[1]),end="")
for i in range(2,N+1):
    print(" "+str(counter[i]),end="")
print()


### FIXED CODE ###

#全体に同じものを足すときは累積和を考えたい

N,Q = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N-1)]
PX = [list(map(int,input().split())) for _ in range(Q)]

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

for a,b in AB:
    graph[a].append(b)
    graph[b].append(a)
#どちらが親か分からないがとりあえずつながっている
#どちらが親かは後で判断

counter = [0 for _ in range(N+1)]
#counter[i]:i番目の頂点のカウンター
parent = [None for _ in range(N+1)]

for p,x in PX:
    counter[p] += x

def dfs(graph,counter,edge):
    stk = []
    stk.append(edge)
    while len(stk) > 0:
        p = stk.pop()
        for e in graph[p]:
            if parent[p] == e:
                continue
            else:
                parent[e] = p
                counter[e] += counter[p]
                stk.append(e)

dfs(graph,counter,1)

ans = " ".join(map(str,counter[1:]))
print(ans)
import sys
while True:
  a=int(input())
  if a==0: break
  ans,name1,name2=[],[],[]
  hogehoge=0
  for i in range(a):
    hoge=map(int,raw_input().split())
    if hoge[0] in name2:
      ww = hoge[1]*hoge[2]
      r = name2.index(hoge[0])
      if len(ans[r]+ww) >= 7: 
        hogehoge+=1
        name1.append(hoge[0])
      else:
        ans[r]+=ww
    else:
      qq = hoge[1]*hoge[2]
      if len(str(qq)) >= 7: 
        hogehoge+=1
        name1.append(hoge[0])
      else: 
        name2.append(hoge[0])
        ans.append(qq)
  if hogehoge == 0: print "NA"
  else: 
    for i in range(len(name1)):
      print name1[i]

### FIXED CODE ###

import sys
while True:
  a=int(input())
  if a==0: break
  ans,name1,name2=[],[],[]
  hogehoge=0
  for i in range(a):
    hoge=map(int,raw_input().split())
    if hoge[0] in name2:
      ww = hoge[1]*hoge[2]
      r = name2.index(hoge[0])
      if len(str(ans[r]+ww)) >= 7: 
        hogehoge+=1
        name1.append(hoge[0])
      else:
        ans[r]+=ww
    else:
      qq = hoge[1]*hoge[2]
      if len(str(qq)) >= 7: 
        hogehoge+=1
        name1.append(hoge[0])
      else: 
        name2.append(hoge[0])
        ans.append(qq)
  if hogehoge == 0: print "NA"
  else: 
    for i in range(len(name1)):
      print name1[i]
S = input()
T =input()
S.lower()
T.lower()
print(T + S)

### FIXED CODE ###

S, T = input().split()

print(T + S)
import copy
import itertools

N = int(input())
six_nines = set()

#6,9の乗数を列挙する
for i in range(1,6):
  a = 6**i
  if a <= N and a not in six_nines:
    six_nines.add(a)
    for j in range(1,N//a):
      six_nines.add(a*j)
  a = 9**i
  if a <= N and a not in six_nines:
    six_nines.add(a)
    for j in range(1,N//a):
      six_nines.add(a*j)

comb_six_nines = copy.copy(six_nines)

#6,9の乗数の和を列挙する
for comb in itertools.combinations(six_nines,2):
  if comb[0]+comb[1] <= N and comb[0]+comb[1] not in comb_six_nines:
    comb_six_nines.add(comb[0]+comb[1])

#comb_six_nines = list(comb_six_nines)
#comb_six_nines.sort(reverse=True)
#comb_six_nines.append(1)
six_nines = list(six_nines)
six_nines.sort(reverse=True)
six_nines.append(1)

#print(comb_six_nines)
print(six_nines)

#Nを列挙した中の大きい方から引いていく
ans = 0
while N != 0:
  for comb in six_nines:
    if N >= comb:
      print(N,comb)
      if N 
      N -= comb
      ans += 1

print(ans)

### FIXED CODE ###

#99c
import math

N = int(input()) #<=100000

#引き算を足し算で下から求める

#直で引き出せる一覧のsetを作る。
single_withdraw_set = set()
single_withdraw_set.add(1)
single_withdraw_set |= {6**i for i in range(1,2 + int(math.log(N,6)))}
single_withdraw_set |= {9**i for i in range(1,2 + int(math.log(N,9)))}
#print(single_withdraw_set)

#何回で引き出せるかのdict。この後の計算でマイナス値を参照するので、あらかじめ作っておく。
withdraw_dict = {int(-i):10**9+7 for i in range(1,1 + max(single_withdraw_set)) }
withdraw_dict[0] = 0

#最低の引き出し回数を1円から計算していく
for i in range(1,N+1):
    if i in single_withdraw_set:
        #1回で引き出せるsetにあるなら当然1回
        withdraw_dict[i] = 1
    else:
        #なければ (現状の値 - 1回で引き出し可能な値)の中で1番少ない値 + 1 
        withdraw_dict[i] = 1 + min([withdraw_dict[i-j] for j in single_withdraw_set])
    
    #print(i,":",withdraw_dict[i])
    
#print(withdraw_dict)
print(withdraw_dict[N])
input();a=sorted(map(int,input().split()));z=1
for i in a:
 if i>1e18//z:z=-1;break
 z*=i
print(z)

### FIXED CODE ###

n,*a=map(int,open(0).read().split());z=1
for i in a:
 if i>1e18//z:z=-1;break
 z*=i
print(0 if 0in a else z)
n = raw_input()
count = 0
for i in n:
    if(i=='1'):count+=1;

print(count)

### FIXED CODE ###

n = raw_input()
count = 0
for i in n:
    if(i=='1'):count+=1;

print(count)
def cmb(n, r, mod):
    if (r < 0 or r > n):
        return 0
    r=min(r,n-r)

    return g1[n] * g2[r] * g2[n - r] % mod


mod = 10 ** 9 + 7  # 出力の制限
N = 10 ** 4
g1 = [1, 1]  # 元テーブル
g2 = [1, 1]  # 逆元テーブル
inverse = [0, 1]  # 逆元テーブル計算用テーブル

for i in range(2, N + 1):
    g1.append((g1[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod // i)) % mod)
    g2.append((g2[-1] * inverse[-1]) % mod)

n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
mod =10**9+7
mi = 0
ma = 0
for i in range(n - k + 1):
    x = cmb(n - i - 1, k - 1, mod)
    mi += a[i] * x
    ma += a[n - 1 - i] * x
    mi %= mod
    ma %= mod

ans = ma - mi

print(ans % mod)

### FIXED CODE ###

def cmb(n, r, mod):
    if (r < 0 or r > n):
        return 0
    r=min(r,n-r)

    return g1[n] * g2[r] * g2[n - r] % mod


mod = 10 ** 9 + 7  # 出力の制限
N = 10 ** 5
g1 = [1, 1]  # 元テーブル
g2 = [1, 1]  # 逆元テーブル
inverse = [0, 1]  # 逆元テーブル計算用テーブル

for i in range(2, N + 1):
    g1.append((g1[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod // i)) % mod)
    g2.append((g2[-1] * inverse[-1]) % mod)

n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
mod =10**9+7
mi = 0
ma = 0
for i in range(n - k + 1):
    x = cmb(n - i - 1, k - 1, mod)
    mi += a[i] * x
    ma += a[n - 1 - i] * x
    mi %= mod
    ma %= mod

ans = ma - mi

print(ans % mod)
# C - Welcome to AtCoder
# https://atcoder.jp/contests/abc151/tasks/abc151_c

n,m = map(int,input().split())
submits = [list(input().split()) for i in range(0,m)]

ac = 0
wa = 0

AC = "AC"
WA = "WA"

tmp_wa = 0
tmp_ac = 0


for i in range(len(submits)):
    # ACなら正解数をカウントアップ
    if submits[i][1] == AC:
        # 同じ問題に正解してないかチェック
        if submits[i][0] == tmp_ac:
            continue
        ac += 1
        # WAの数をカウント
        wa += tmp_wa
        # WAを初期化
        tmp_wa = 0
        tmp_ac = submits[i][0]
    else:
        # WAならwa+1
        tmp_ac = submits[i][0]
        tmp_wa += 1

print(str(ac) + " " + str(wa))

### FIXED CODE ###

# A - Next Alphabet
# https://atcoder.jp/contests/abc151/tasks/abc151_a

print(chr(ord(input())+1))
a, b = map(int, input().split())
d = a*c
if d%2 == 0:
  print("No")
else:
  print("Yes")


### FIXED CODE ###

a, b = map(int, input().split())
d = a*b
if d%2 == 0:
  print("No")
else:
  print("Yes")
#!/usr/bin/python
# coding: UTF-8

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

s = []
for i in range(m):
    s += [tuple(map(int,input().split())),]

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

ret = 0
all = [(str(bin(i)))[2:].zfill(m) for i in range(2 ** n),]
all = [[int(i) for i in case] for case in all,]
for case in all:
    # print("------------------------------------------------")
    # print("[case = ",case,"]")
    flag = 0
    for num,i in enumerate(s):
        if flag == 1:
            continue

        # print("  [case = ",i[1:],"]")

        sw = [0 for z in range(n),]
        # print("sw",sw)
        for k in i[1:]:
            sw[k-1] = 1

        # print(sw,case)
        # print(sum(i*j for i,j in zip(sw,case)) % 2," =? ",p[num])
        if (sum(i*j for i,j in zip(sw,case),) % 2) != p[num]:
            flag = 1
        # print("flag is ",flag)
           
    if flag == 0:
        # print(case," is ok.")
        ret += 1

print(ret)

### FIXED CODE ###

#!/usr/bin/python
# coding: UTF-8

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

s = []
for i in range(m):
    s += [tuple(map(int,input().split())),]

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

ret = 0
all = [(str(bin(i)))[2:].zfill(n) for i in range(2 ** n)]
all = [[int(i) for i in case] for case in all]
for case in all:
    flag = 0
    for num,i in enumerate(s):
        if flag == 1:
            continue

        sw = [0 for z in range(n)]
        for k in i[1:]:
            sw[k-1] = 1

        if (sum(i*j for i,j in zip(sw,case)) % 2) != p[num]:
            flag = 1
           
    if flag == 0:
        ret += 1

print(ret)
A=input()
B=input()
C=input()

l='a'

for i in range(300):
  if l=='a':
    
    if len(A)==0:
      print('A')
      exit()
    elif len(A)==1:
      l=A[0]
      A=''
    else:
      l=A[0]
      A=A[1:]
  elif l=='b':
    l=B[0]
    if len(B)==0:
      print('B')
      exit()
    elif len(B)==1:
      l=B[0]
      B=''
    else:
      l=B[0]
      B=B[1:]
  else:
    l=C[0]
    if len(C)==0:
      print('C')
      exit()
    elif len(C)==1:
      l=C[0]
      C=''
    else:
      l=C[0]
      C=C[1:]    

### FIXED CODE ###

A=input()
B=input()
C=input()

l='a'

for i in range(300):
  if l=='a':
    if len(A)==0:
      print('A')
      exit()
    elif len(A)==1:
      l=A[0]
      A=''
    else:
      l=A[0]
      A=A[1:]
  elif l=='b':
    if len(B)==0:
      print('B')
      exit()
    elif len(B)==1:
      l=B[0]
      B=''
    else:
      l=B[0]
      B=B[1:]
  else:
    if len(C)==0:
      print('C')
      exit()
    elif len(C)==1:
      l=C[0]
      C=''
    else:
      l=C[0]
      C=C[1:]
a, b, c = map(int, input().split())

if a == b:
    print(c)
elif a == c:
    print(b)
elif b == c:
    pritn(a)

### FIXED CODE ###

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

if a == b:
    print(c)
elif a == c:
    print(b)
elif b == c:
    print(a)
c = []
for i in range(3):
    x, y, z = map(int, input().split())
    c.append(x)
    c.append(y)
    c.append(z)

for a1 in range(100):
    for a2 in range(100):
        for a3 in range(100):
            b1 = c[0] - a1
            b2 = c[1] - a2
            b3 = c[2] - a3
            if c[4] == a2 + b1 and c[5] == a2 + b2 and c[6] == a2 + b3 and c[7] == a3 + b1 and c[8] == a3 + b2 and c[9] == a3 + b3:
                print('Yes')
                exit()
print('No')


### FIXED CODE ###

c = []
for i in range(3):
    x, y, z = map(int, input().split())
    c.append(x)
    c.append(y)
    c.append(z)

for a1 in range(101):
    for a2 in range(101):
        for a3 in range(101):
            b1 = c[0] - a1
            b2 = c[1] - a1
            b3 = c[2] - a1
            if c[3] == a2 + b1 and c[4] == a2 + b2 and c[5] == a2 + b3 and c[6] == a3 + b1 and c[7] == a3 + b2 and c[8] == a3 + b3:
                print('Yes')
                exit()
print('No')
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import plotly.express as px
import statsmodels.api as sm


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

if x == 0:
    print(1)
else:
    print(0)


### FIXED CODE ###

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

if x == 0:
    print(1)
else:
    print(0)
x = map(int, raw_input().split(" "))
x.sort()
for i x x_last
    print x[i]

### FIXED CODE ###

x = map(int, raw_input().split(" "))
x.sort()
for i in x:
    print i,
# 昔同じ問題を atcoder で見た？
n = int(input())
edges = []
paths = {}
for i in range(n-1):
    a, b = list(map(int, input().split(' ')))
    edges.append((a, b))
    paths[a] = paths.get(a, []) + [b]
    paths[b] = paths.get(b, []) + [a]
# print(edges)
# print(paths)
colors = {}  # (a->b) 1 とか
current = 1
biggest = 1
def f(current, prev, prev_color):
    global biggest
    color = 0
    for vertex in paths[current]:
        if vertex == prev:
            continue
        color += 1
        if color == prev_color:
            color += 1
        biggest = max(biggest, color)
        colors[(current, vertex)] = color
        f(vertex, current, color)
f(1, None, None)

print(biggest)
for a, b in edges:
    print(colors[(a, b)])

### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 9)

# 昔同じ問題を atcoder で見た？
n = int(input())
edges = []
paths = {}
for i in range(n-1):
    a, b = list(map(int, input().split(' ')))
    edges.append((a, b))
    paths[a] = paths.get(a, []) + [b]
    paths[b] = paths.get(b, []) + [a]
# print(edges)
# print(paths)
colors = {}  # (a->b) 1 とか
current = 1
biggest = 1
def f(current, prev, prev_color):
    global biggest
    color = 0
    for vertex in paths[current]:
        if vertex == prev:
            continue
        color += 1
        if color == prev_color:
            color += 1
        biggest = max(biggest, color)
        colors[(current, vertex)] = color
        f(vertex, current, color)
f(1, None, None)

print(biggest)
for a, b in edges:
    print(colors[(a, b)])
# pypy3
a = input().split()
p

### FIXED CODE ###

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

if a.count(5) == 2 and a.count(7) == 1:
  print("YES")
else:
  print("NO")
### -*- coding: utf-8 -*-

splited = input().split("\n")
N = int(splited[0])
nums = list(map(int, splited[1].split()))

hitting = 1
isHitOnce = False
for num in nums:
    if num == hitting:
        hitting += 1
        isHitOnce = True

if hitting == 1:
    print(-1)
else:
    print(N - (hitting - 1))

### FIXED CODE ###

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

N = int(input())
nums = list(map(int, input().split()))
 
hitting = 1
isHitOnce = False
for num in nums:
    if num == hitting:
        hitting += 1
        isHitOnce = True
 
if hitting == 1:
    print(-1)
else:
    print(N - (hitting - 1))
#coding utf-8
L,R=map(int,input().split())

tmp=2019//L
ans=0
for i in range(1,tmp+1):
  if i*2019>=L and i*2019<=R:
    print(0)
    break
  if i==tmp:
    print((L%2019*(L+1)%2019)%2019)

### FIXED CODE ###

#coding utf-8
L,R=map(int,input().split())

tmp=99999999999999
if R-L>=2019:
  tmp=0
else:
  for i in range(L%2019,L%2019+R-L):
    for j in range(i+1,L%2019+R-L+1):
      if i==0 or j==0:
        tmp=0
      else:
        if (i*j)%2019<tmp:
          tmp=(i*j)%2019
        
print(tmp)
X, Y, Z, K = map(int,input().split())
A_list = sorted(list(map(int,input().split())), reverse=True)
B_list = sorted(list(map(int,input().split())), reverse=True)
C_list = sorted(list(map(int,input().split())), reverse=True)

E_list = sorted([ai+bi for ai in A_list for bi in B_list], reverse=True)[:K]
sum_list = sorted([ei+ci for ci in E_list for ci in C_list], reverse=True)[:K]

for i in range(K):
    print(sum_list[i])


### FIXED CODE ###

X, Y, Z, K = map(int,input().split())
A_list = sorted(list(map(int,input().split())), reverse=True)
B_list = sorted(list(map(int,input().split())), reverse=True)
C_list = sorted(list(map(int,input().split())), reverse=True)

E_list = sorted([ai+bi for ai in A_list for bi in B_list], reverse=True)[:K]
sum_list = sorted([ei+ci for ei in E_list for ci in C_list], reverse=True)[:K]

for i in range(K):
    print(sum_list[i])
n=int(input())
buka = [0]*n
for i in range(n):
  buka[int(input())-1] += 1
print(*buka,sep='/n')

### FIXED CODE ###

n=int(input())
buka = [0]*n
for joushi in input().split():
  buka[int(joushi)-1] += 1
print(*buka,sep='\n')
k, s = map(int, input().split())

ans = 0
for x in range(k+1):
    if x > s:
        break
    if x+k+k < s:
        continue
    for y in range(k+1):
        xy = x+y
        if xy > s:
            break
        if xy+k < s:
            continue:
        for z in range(k+1):
            xyz = x+y+z
            if xyz > s:
                break
            if xyz == s:
                ans += 1
print(ans)

### FIXED CODE ###

k, s = map(int, input().split())
 
ans = 0
for x in range(k+1):
    for y in range(k+1):
        ans += max(0, 0<=s-x-y<=k)
print(ans)
S = input()
if S = "SUN":
    print(7)
if S = "MON":
    print(6)
if S = "TUE":
    print(5)
if S = "WED":
    print(4)
if S = "THU":
    print(3)
if S = "FRI":
    print(2)
if S = "SAT":
    print(1)


### FIXED CODE ###

S = input()
if S == "SUN":
    print(7)
if S == "MON":
    print(6)
if S == "TUE":
    print(5)
if S == "WED":
    print(4)
if S == "THU":
    print(3)
if S == "FRI":
    print(2)
if S == "SAT":
    print(1)
#!/usr/bin/env python3
import sys
from functools import lru_cache

def main():
    sys.setrecursionlimit(2000)
    N, M = map(int, input().split())
    a, c = [], []
    tall = set(range(1, N + 1))
    for i in range(M):
        t, _ = map(int, input().split())
        a.append(t)
        cc = frozenset(map(int, input().split()))
        c.append(cc)
        tall = tall - cc
    if tall:
        print(-1)
        return
    FAIL = sum(a) + 1

    @lru_cache(maxsize=None)
    def helper(i, left):
        if not left:
            return 0
        if i == M:
            return FAIL
        return min(a[i] + helper(i + 1, left - c[i]),
                   helper(i + 1, left))

    print(helper(0, frozenset(range(1, N + 1))))


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3

def main():
    N, M = map(int, input().split())
    cd = {}
    FAIL = (10 ** 3) * (10 ** 5) + 1
    for _ in range(M):
        ai, _ = map(int, input().split())
        ci = sum(1 << (int(i) - 1) for i in input().split())
        keys = list(cd.keys())
        for i in keys:
            cd[i | ci] = min(cd.get(i | ci, FAIL), cd[i] + ai)
        cd[ci] = min(cd.get(ci, FAIL), ai)
    print(cd.get((1 << N) - 1, -1))


if __name__ == '__main__':
    main()
def dudge(k):
    for i in reversed(range(n)):
        p = (k >> i) % 2
        if p == 0: continue

        for claim in xy[i]:
            x = claim[0]
            y = claim[1]

            truth = (k >> x-1) % 2
            if truth == 1 and y == 0:
                return False
            elif truth == 0 and y == 1:
                return False
    return True


n = int(input())

xy = []
for i1 in range(n):
    ai = int(input())
    xy.append([])

    for i2 in range(ai):
        xi,yi = map(int, input().split())
        xy[i1].append((xi, yi))


        result = 0
for k in reversed(range(1 << n)):

    if dudge(k):
        l = [i for i in range(n) if (k >> i) % 2 == 1]
        result = max(result, len(l))

print(result)


### FIXED CODE ###

def dudge(k):
    for i in reversed(range(n)):
        p = (k >> i) % 2
        #print(' i = ', i, ' p = ', p)
        if p == 0: continue

        for claim in xy[i]:
            x = claim[0]
            y = claim[1]

            truth = (k >> x-1) % 2
            #print('   x = ', x,  ' y = ', y, ' t = ', truth)
            if truth == 1 and y == 0:
                return False
            elif truth == 0 and y == 1:
                return False
    return True


n = int(input())

xy = []
for i1 in range(n):
    ai = int(input())
    xy.append([])

    for i2 in range(ai):
        xi,yi = map(int, input().split())
        xy[i1].append((xi, yi))

#print(xy)

result = 0
for k in reversed(range(1 << n)):
    #print(bin(k))

    if dudge(k):
        #print('    True')
        #l = [i for i in range(n) if (k >> i) % 2 == 1]
        cnt = 0
        for i in range(n):
            if (k >> i) % 2 == 1: cnt += 1
        #print('    ', l, len(l))
        #result = max(result, len(l))
        result = max(result, cnt)

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

left = []
right = []
for x in X:
    if x<0:
        left.append(abs(x))
    else:
        right.append(x)
left.reverse()

# from math import inf
ans = 10**18

#i=>right
for i in range(K+1):
    if right[0]==0:
        if i==0:
            continue;
    temp = 0
    if len(left)==0:
        temp = right[K-1]
    elif len(right)==0:
        temp = left[K-1]
    elif len(left)>=(K-i):
        if len(right)>=i:
            temp0 = left[K-i-1]
            temp1 = right[i-1]
            temp  = temp0+temp1 + min(temp0, temp1)
        else:
            temp0 = right[-1]
            temp1 = left[K-len(right)-1]
            temp  = temp0+temp1 + min(temp0, temp1)
    else:
        temp = left[-1] if len(left)!=0 else 0
        temp += right[K-len(left)-1]
    ans = min(ans, temp)

print(ans)


### FIXED CODE ###

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

left = []
right = []
for x in X:
    if x<0:
        left.append(abs(x))
    else:
        right.append(x)
left.reverse()

# from math import inf
ans = 10**18

#i=>right
for i in range(K+1):
    if len(right)!=0 and right[0]==0 and i==0:
        continue;
    temp = 0
    if len(left)==0:
        temp = right[K-1]
    elif len(right)==0:
        temp = left[K-1]
    elif len(left)>=(K-i):
        if len(right)>=i:
            temp0 = left[K-i-1] if not i==K else 0
            temp1 = right[i-1] if not i==0 else 0
            temp  = temp0+temp1 + min(temp0, temp1)
        else:
            temp0 = right[-1]
            temp1 = left[K-len(right)-1]
            temp  = temp0+temp1 + min(temp0, temp1)
    else:
        temp0 = left[-1]
        temp1 = right[K-len(left)-1]
        temp  = temp0+temp1 + min(temp0, temp1)
    ans = min(ans, temp)

print(ans)