Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

import sys
input = sys.stdin.readline
from bisect import bisect_left, bisect_right

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

def less(x):
    res = 0
    for i in range(N):
        e = A[i]
        if e < 0:
            d = x // e
            l = 0
            r = i
            while l != r:
                m = (l + r) // 2
                if A[m] <= d:
                    l = m + 1
                else:
                    r = m
            res += i - l
        elif e > 0:
            d = - (- x // e)
            l = 0
            r = i
            while l != r:
                m = (l + r) // 2
                if A[m] < d:
                    l = m + 1
                else:
                    r = m
            res += l
        elif x > 0:
            res += i
    return res

l = - (10 ** 18 + 1)
r = - l
while l + 1 < r:
    m = (l + r) // 2
    if less(m) < K:
        l = m
    else:
        r = m
print(l)


### FIXED CODE ###

import sys
input = sys.stdin.readline
from bisect import bisect_left, bisect_right

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

neg = bisect_left(A, 0)
pos = bisect_right(A, 0)

def less(x):
    res = 0
    b = 0
    for i in range(0, neg):
        while b != N and A[i] * A[b] >= x:
            b += 1
        while b != 0 and A[i] * A[b - 1] < x:
            b -= 1
        res += max(i - b, 0)
    for i in range(neg, pos):
        if x > 0:
            res += i
    for i in range(pos, N):
        while b != N and A[i] * A[b] < x:
            b += 1
        while b != 0 and A[i] * A[b - 1] >= x:
            b -= 1
        res += min(b, i)
    return res

l = - (10 ** 18 + 1)
r = - l
while l + 1 < r:
    m = (l + r) // 2
    if less(m) < K:
        l = m
    else:
        r = m
print(l)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

class BIT:
    def __init__(self, a, func=int.__add__, one=0):
        self.n = len(a)
        self.func = func
        self.one = one
        self.a = [0] * (self.n + 1)

        for i, j in enumerate(a):
            self.update(i, j)

    def update(self, i, x):
        i += 1
        while i <= self.n:
            self.a[i] = self.func(self.a[i], x)
            i += i & (-i)

    def get(self, i):
        s = self.one
        i += 1
        while i != 0:
            s = self.func(s, self.a[i])
            i -= i & (-i)
        return s


n, q = map(int, input().split())
c = [int(i)-1 for i in input().split()]
que = [[i, [int(i)-1 for i in input().split()], 0] for i in range(q)]
que.sort(key=lambda x: x[1][1])
last = [-1] * n
bit = BIT([0]*(n+10))
j = 0
for i in range(n):
    if last[c[i]] >= 0:
        bit.update(last[c[i]]+5, -1)
    bit.update(i+5, 1)
    last[c[i]] = i
    while j < q and que[j][1][1] == i:
        que[j][2] = bit.get(i+5) - bit.get(que[j][1][0]+4)
        j += 1
que.sort()
for i in que:
    print(i[-1])


### FIXED CODE ###

import sys
input = sys.stdin.readline


class BIT:
    def __init__(self, a):
        self.n = len(a)
        self.a = [0] * (self.n + 1)

        for i, j in enumerate(a):
            self.update(i, j)

    def update(self, i, x):
        i += 1
        while i <= self.n:
            self.a[i] = self.a[i] + x
            i += i & (-i)

    def get(self, i):
        s = 0
        i += 1
        while i != 0:
            s = s + self.a[i]
            i -= i & (-i)
        return s


def inmin(x):
    return int(x)-1


if __name__ == "__main__":
    n, q = map(int, input().split())
    c = list(map(inmin, input().split()))
    que = [[i, list(map(inmin, input().split()))] for i in range(q)]
    que.sort(key=lambda x: x[1][1])
    ans = [0] * q

    last = [-1] * n
    bit = BIT([0]*(n+10))
    j = 0
    for i in range(n):
        if last[c[i]] >= 0:
            bit.update(last[c[i]]+5, -1)
        bit.update(i+5, 1)
        last[c[i]] = i
        while j < q and que[j][1][1] == i:
            ans[que[j][0]] = bit.get(i+5) - bit.get(que[j][1][0]+4)
            j += 1
    print(*ans)
### BUGGY CODE ###

a, b, k = map(int, input().split())
lst = [x for x in range(a, b + 1)]
lst_small = lst[:k]
lst_large = lst[-k:]
ans = list(set(lst_small) | set(lst_large))
ans = sorted(ans)
for i in range(len(ans)):
    print(ans[i])

### FIXED CODE ###

a, b, k = map(int, input().split())
if b - a > k:
    lst_small = [x for x in range(a, a + k)]
    lst_large = [x for x in range(b - k + 1, b + 1)]
    ans = list(set(lst_small) | set(lst_large))
    ans = sorted(ans)
else:
    ans = [x for x in range(a, b + 1)]

for i in range(len(ans)):
    print(ans[i])
### BUGGY CODE ###

import sys


class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i


MOD = 998244353
n = int(input())
xys = []
ys = []
for line in sys.stdin:
    x, y = map(int, line.split())
    xys.append((x, y))
    ys.append(y)
ys.sort()
y_dict = {y: i + 1 for i, y in enumerate(ys)}
xys = [(x, y_dict[y]) for x, y in xys]
xys.sort()
bit = Bit(n)

p2d = [1]
for i in range(n):
    p2d.append(p2d[-1] * 2 % MOD)

ans = 0
for i, (x, y) in enumerate(xys):
    a = bit.sum(y)
    b = i - a
    c = y - a - 1
    d = (n - i - 1) - c
    bit.add(y, 1)
    # print(i, x, y, a, b, c, d)
    pa, pb, pc, pd = p2d[a], p2d[b], p2d[c], p2d[d]
    tmp = p2d[n - 1]
    tmp += (pa - 1) * (pd - 1) % MOD * pb * pc % MOD
    tmp += (pb - 1) * (pc - 1) % MOD * pa * pd % MOD
    tmp -= (pa - 1) * (pb - 1) % MOD * (pc - 1) * (pd - 1) % MOD
    ans = (ans + tmp) % MOD
print(ans)


### FIXED CODE ###

import sys


class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i


MOD = 998244353
n = int(input())
xys = []
ys = []
for line in sys.stdin:
    x, y = map(int, line.split())
    xys.append((x, y))
    ys.append(y)
ys.sort()
y_dict = {y: i + 1 for i, y in enumerate(ys)}
xys = [(x, y_dict[y]) for x, y in xys]
xys.sort()
f_bit = Bit(n)
b_bit = Bit(n)
for i in range(1, n + 1):
    b_bit.add(i, 1)

p2d = [1]
for i in range(n):
    p2d.append(p2d[-1] * 2 % MOD)

ans = 0
for i, (x, y) in enumerate(xys):
    b_bit.add(y, -1)
    a = f_bit.sum(y)
    b = i - a
    c = b_bit.sum(y)
    d = (n - i - 1) - c
    f_bit.add(y, 1)
    # print(i, x, y, a, b, c, d)
    pa, pb, pc, pd = p2d[a], p2d[b], p2d[c], p2d[d]
    tmp = p2d[n - 1]
    tmp += (pa - 1) * (pd - 1) * pb * pc
    tmp += (pb - 1) * (pc - 1) * pa * pd
    tmp -= (pa - 1) * (pb - 1) * (pc - 1) * (pd - 1)
    ans = (ans + tmp) % MOD
print(ans)
### BUGGY CODE ###

n = int(input())
A = list(map(int,input().split()))
# n = 10
# A = [33, 18, 33, 28, 8, 19, 89, 86, 2, 4]

C = {a:0 for a in A}

for a in A:
    C[a] = C[a]+1

maxA = max(A)

D = {a:0 for a in A}

for a in A:
    t = 2
    while a*t <= maxA:
        if a*t in A:
            D[a*t] = D[a*t]+1
        t = t+1

counter = 0
for a in A:
    if C[a] == 1 and D[a] == 0:
        counter = counter+1
        
print(counter)

### FIXED CODE ###

n = int(input())
*A, = map(int, input().split())
maxA = max(A)
# C[a] = A内のaの個数
C = {a: 0 for a in A}
for a in A:
    C[a] += 1
# D[a]=1: Aにaより小さいaの約数が存在する
D = {a: 0 for a in A}
for a in A:
    if C[a] > 0:
        t = 2
        while a * t <= maxA:
            D[a * t] = 1
            t += 1
ans = 0
for a in A:
    if C[a] == 1 and D[a] == 0:
        ans += 1
print(ans)
### BUGGY CODE ###

R,C,K=map(int,input().split())
RCV=[list(map(int,input().split())) for i in range(K)]
V=[[0]*(C+1) for i in range(R+1)]
for r,c,v in RCV:
    V[r][c]=v
d=[[[0]*4 for i in range(C+1)] for i in range(R+1)]
for i in range(R):
    for j in range(C):
        d[i+1][j+1][0]=max(d[i][j+1])
        for k in range(3):
            d[i+1][j+1][k+1]=max(d[i+1][j][k+1],max(d[i][j+1])+V[i+1][j+1],d[i+1][j][k]+V[i+1][j+1])
print(max(d[-1][-1]))

### FIXED CODE ###

import numpy as np
def main(R,C,K,RCV):
    V=np.zeros((R+1,C+1),dtype=np.int64)
    for i in range(K):
        V[RCV[i][0]][RCV[i][1]]=RCV[i][2]
    d=np.zeros((R+1,C+1,4),dtype=np.int64)
    for i in range(R):
        for j in range(C):
            m=max(d[i][j+1])
            d[i+1][j+1][0]=m
            for k in range(3):
                d[i+1][j+1][k+1]=max(d[i+1][j][k+1],m+V[i+1][j+1],d[i+1][j][k]+V[i+1][j+1])
    return max(d[-1][-1])
import sys
readline=sys.stdin.buffer.readline
read=sys.stdin.buffer.read
if sys.argv[-1]=='ONLINE_JUDGE':
    from numba import*
    from numba.pycc import CC
    cc=CC('my_module')
    def cc_export(f,s):
        cc.export(f.__name__,s)(f)
        return njit(f)
    main=cc_export(main,(i8,i8,i8,i8[:,:],))
    cc.compile()
    exit()
R,C,K=np.array(readline().split(),dtype=np.int64)
RCV=np.array(read().split(),dtype=np.int64).reshape(K,3)
from my_module import main
print(main(R,C,K,RCV))
### BUGGY CODE ###

N = int(input()) 
s = [input() for i in range(N)]
alp=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t',
     'u','v','w','x','y','z']
LIS=[]
nu=0
for a in range(N):
  for b in range(a+1,N):
    c=0
    while c<26:
      if s[a].count(alp[c])==s[b].count(alp[c]):
        c+=1
      else:
        break
    if c==26:
      nu+=1
    else:
      pass
print(nu)

### FIXED CODE ###

N = int(input()) 
s = [input() for i in range(N)]
LIS=[]
for i in range(N):
  LIS.append(''.join(sorted(s[i])))
LIS.sort()
n=0
prestr=LIS[0]
count=1
for st in LIS[1:]:
  if st==prestr:
    n+=count
    count+=1
  else:
    count=1
    prestr=st
print(int(n))
### BUGGY CODE ###

s=input()
cur=""
i=0
ans=0
while i<len(s):
  for j in range(i+1,len(s)):
    if s[i:j]!=cur:
      if s[i:j]==s[j:]:
        continue
      cur=s[i:j]
      i=j
      ans+=1
print(ans)


### FIXED CODE ###

S=input()
dp=[[0 for i in range(2)] for j in range(len(S))]
# dp[x]:x番目の文字に、dp[x][0]:1文字で来たときの最大分割数、dp[x][1]:2文字で来た時
dp[0][0]=1
dp[0][1]=-1
for i in range(1,len(S)):
  if S[i]==S[i-1]:
    dp[i][0]=dp[i-1][1]+1
  elif S[i]!=S[i-1]:
    dp[i][0]=max(dp[i-1][0],dp[i-1][1])+1
  if i-2>=0:
    dp[i][1]=max(dp[i-2][0],dp[i-2][1])+1
print(max(dp[-1][0],dp[-1][1]))
### BUGGY CODE ###

import sys

input = sys.stdin.readline


def main():
    H, W, M = map(int, input().split())
    row = [0] * (H)
    col = [0] * (W)
    bomb = set()
    for _ in range(M):
        h, w = map(int, input().split())
        bomb.add((h, w))
        row[h-1] += 1
        col[w-1] += 1
    row_max = max(row)
    row_index_list = [i for i, v in enumerate(row) if v == row_max]
    col_max = max(col)
    col_index_list = [i for i, v in enumerate(col) if v == col_max]
    res = 0
    for x in row_index_list:
        for y in col_index_list:
            ans = row[x] + col[y]
            if (x + 1, y + 1) in bomb:
                ans -= 1
            res = max(ans, res)
    print(res)


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys

input = sys.stdin.readline


def main():
    H, W, M = map(int, input().split())
    row = [0] * (H)
    col = [0] * (W)
    bomb = set()
    for _ in range(M):
        h, w = map(int, input().split())
        bomb.add((h, w))
        row[h-1] += 1
        col[w-1] += 1
    row_max = max(row)
    row_index_list = [i for i, v in enumerate(row) if v == row_max]
    col_max = max(col)
    col_index_list = [i for i, v in enumerate(col) if v == col_max]
    ans = row_max + col_max - 1
    c = False
    for x in row_index_list:
        for y in col_index_list:
            if not (x + 1, y + 1) in bomb:
                c = True
                break
        if c:
            break
    if c:
        ans += 1
    print(ans)


if __name__ == '__main__':
    main()
### BUGGY CODE ###

N = int(input())
num = list(map(int,input().split()))
cnt = 0
flag = False
for i in range(N):
	if(i == 0):
		cnt+=1
		continue
	sub = num[0:i]
	sub_min = min(sub)
	if (num[i] <= sub_min):
		cnt+=1
print(cnt)

### FIXED CODE ###

N = int(input())
num = list(map(int,input().split()))
cnt = 0
flag = False
num_min = 10**8
for i in range(N):
	if(i == 0):
		cnt+=1
		continue
	num_min = min(num_min,num[i-1])
	if (num[i] <= num_min):
		cnt+=1
print(cnt)
### BUGGY CODE ###

def main():
    N,K = map(int, input().split())
    pi = list(map(int, input().split()))
    max_num = 0
    new_pi = [0] * N

    for i in range(N):
        new_pi[i] += (1+pi[i])/2

    for i in range(N):
        s = sum(new_pi[i:i+K])
        if s > max_num:
            max_num = s

    print(max_num)

if __name__ == "__main__":
    main()

### FIXED CODE ###

def main():
    N,K = map(int, input().split())
    pi = list(map(int, input().split()))
    max_num = 0
    new_pi = [0] * N
    sum_new_pi = [0] * (N+1)

    for i in range(N):
        new_pi[i] += (1+pi[i])/2

    for i in range(N):
        sum_new_pi[i+1] = sum_new_pi[i] + new_pi[i]

    for i in range(N):
        if i+K > N:
            break
        s = sum_new_pi[i+K] - sum_new_pi[i]
        if s > max_num:
            max_num = s

    print(max_num)

if __name__ == "__main__":
    main()
### BUGGY CODE ###

from sys import stdin

n,m = [int(x) for x in stdin.readline().rstrip().split()]
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(m)]

li.sort()

mi = []
ma = []

for i in li:
    if i[0] == 1:
        mi.append(i[1])
    if i[1] == n:
        ma.append(i[0])

for s in mi:
    for k in ma:
        if s == k:
            print("POSSIBLE")
            exit()

print("IMPOSSIBLE")

### FIXED CODE ###

from sys import stdin

n,m = [int(x) for x in stdin.readline().rstrip().split()]
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(m)]

lin = [0]*n

for i in li:
    if i[0] == 1:
        lin[i[1]-1] += 1
    if i[1] == n:
        lin[i[0]-1] += 1

for i in lin:
    if i == 2:
        print("POSSIBLE")
        exit()

print("IMPOSSIBLE")
### BUGGY CODE ###

#最終版
H,W = list(map(int,input().split()))
A = [list(str(input())) for i in range(H)]

white = []
black = []

cnt = 0

for i in range(H):
    for j in range(W):
        if A[i][j] == "#":
            black.append([i,j])

length = len(black)
            
while (length < H*W):
    gray = []
    for l in black:
        if l[1] != 0:
            c1 = [l[0],l[1]-1]
            if A[c1[0]][c1[1]] == ".":
                gray.append(c1)
                A[c1[0]][c1[1]] == "#"
        if l[1] != W-1:
            c2 = [l[0],l[1]+1]
            if  A[c2[0]][c2[1]] == ".":
                gray.append(c2)
                A[c2[0]][c2[1]] == "#"
        if l[0] != 0:
            c3 = [l[0]-1,l[1]]
            if  A[c3[0]][c3[1]] == ".":
                gray.append(c3)
                A[c3[0]][c3[1]] == "#"
        if l[0] != H-1:
            c4 = [l[0]+1,l[1]]
            if  A[c4[0]][c4[1]] == ".":
                gray.append(c4)
                A[c4[0]][c4[1]] == "#"
    
    gray = list(map(list, set(map(tuple, gray))))
    
    black =[]
    
    for l in gray:
        black.append(l)
        A[l[0]][l[1]] = "#"
        
    cnt += 1
    length += len(black)
    
print(cnt)

### FIXED CODE ###

H,W = list(map(int,input().split()))
A = [list(str(input())) for i in range(H)]
 
black = []
 
cnt = 0
 
for i in range(H):
    for j in range(W):
        if A[i][j] == "#":
            black.append([i,j])
 
length = len(black)
            
while (length < H*W):
    gray = []
    for l in black:
        if l[1] != 0:
            c1 = (l[0],l[1]-1)
            if A[c1[0]][c1[1]] == ".":
                gray.append(c1)
                A[c1[0]][c1[1]] = "#"
        if l[1] != W-1:
            c2 = (l[0],l[1]+1)
            if  A[c2[0]][c2[1]] == ".":
                gray.append(c2)
                A[c2[0]][c2[1]] = "#"
        if l[0] != 0:
            c3 = (l[0]-1,l[1])
            if  A[c3[0]][c3[1]] == ".":
                gray.append(c3)
                A[c3[0]][c3[1]] = "#"
        if l[0] != H-1:
            c4 = (l[0]+1,l[1])
            if  A[c4[0]][c4[1]] == ".":
                gray.append(c4)
                A[c4[0]][c4[1]] = "#"
    
    gray = list(set(gray))
    black = [l for l in gray]
    
    cnt += 1
    length += len(black)
    
print(cnt)
### BUGGY CODE ###

import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

k = ni()
s = ns()
n = len(s)
mod = 10**9+7


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

N = 10**7
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 )

ans = 0
for i in range(k+1):
    ans += cmb(n-1+i,i,mod)*pow(25,i,mod)%mod*pow(26,k-i,mod)%mod
    ans %= mod

print(ans)

### FIXED CODE ###

import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

k = ni()
s = ns()
n = len(s)
mod = 10**9+7


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

N = 10**6*3
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 )

ans = 0
for i in range(k+1):
    ans += cmb(n-1+i,i,mod)*pow(25,i,mod)%mod*pow(26,k-i,mod)%mod
    ans %= mod

print(ans)
### BUGGY CODE ###

def remove(data):
    global result
    for n in range(len(data)):
        if data[n] == n + 1:
            result.append(n + 1)
            if len(data) == 1:
                #print('OK')
                return True
            else:
                #print('remove {0} '.format(n + 1), end='')
                #print(data[:n] + data[n+1:])
                if remove(data[:n] + data[n+1:]):
                    return True
    else:
        #print('try again')
        if len(result) > 0:
            result.pop(-1)
        return False

_ = input()
B = list(map(int, input().split()))

result = []

if remove(B):
    result.reverse()
    for res in result:
        print(res)
else:
    print(-1)


### FIXED CODE ###

_ = input()
data = list(map(int, input().split()))

result = []
pos = min(len(data), max(data)) - 1

while pos >= 0:
    if data[pos] == pos + 1:
        x = data.pop(pos)
        #print('remove {0} {1}'.format(x, data))
        result.append(x)
        if len(data) == 0:
            break
        pos = min(len(data), max(data)) - 1
    else:
        pos -= 1

if len(data) == 0:
    result.reverse()
    for res in result:
        print(res)
else:
    print(-1)
### BUGGY CODE ###

K,S= list(map(int, input().split()))
ans=0
for i in range(K+1):
    for j in range(K+1):
        for k in range(K+1):
            if i+j+k==S:
                ans+=1
print(ans)

### FIXED CODE ###

K,S= list(map(int, input().split()))
ans=0
for i in range(S//3,K+1):
    for j in range(i+1):
        if i+j>S:
            break
        if i+j*2<S:
            continue
        if S-i-j<=j:
            k=S-i-j
            if i==j==k:
                ans+=1
            elif i==j or j==k:
                ans+=3
            else:
                ans+=6
print(ans)
### BUGGY CODE ###

n = int(input())
#ビット全探索を行う
import itertools
li = list(itertools.product([0, 1], repeat=n)) # ０が不親切もの、１が親切もの

#dd[i]:人iが人xをy（０なら不親切,１なら親切)だと思っていることを収納
from collections import deque, defaultdict
dd = defaultdict(lambda:deque())
for i in range(n):
    a = int(input())
    for j in range(a):
        x, y = map(int, input().split())
        dd[i].append((x-1, y))


from copy import deepcopy
max_sum = 0 #親切者の数の最大値
for i in li: # i には親切者のタプルが入っている
    sum_ = 0
    co = deepcopy(dd)
    vv = 0
    for k in range(len(i)): #全員の証言が矛盾しないかを考える
        if i[k] == 0: # 不親切ものの場合
            continue
        else: #以下k人目の証言を考える
            sum_ += 1
            length = len(co[k])
            c = 0
            while co[k]:
                x, y = co[k].popleft()
                if i[x] != y: #証言と一致していない場合
                    break
                else:
                    c+=1
            if c == length: #k人目の証言が全てあっている場合
                vv += 1
    if vv == sum_:
        max_sum = max(max_sum, vv)

print(max_sum)
            


### FIXED CODE ###

import sys
input = sys.stdin.buffer.readline

def main():
    n = int(input())
    #ビット全探索を行う
    import itertools
    li = list(itertools.product([0, 1], repeat=n)) # ０が不親切もの、１が親切もの

    #dd[i][x] = y:人iが人xをy（０なら不親切,１なら親切)だと思っていることを収納
    NIL = -1
    dd = [[NIL]*n for _ in range(n)]
    for i in range(n):
        a = int(input())
        for j in range(a):
            x, y = map(int, input().split())
            x = x-1
            dd[i][x] = y


    from copy import deepcopy
    max_sum = 0 #親切者の数の最大値
    for i in li: # i には親切者のタプルが入っている
        ppp = 0
        for ggg in i:
            ppp += ggg
        if ppp <= max_sum:
            continue
        sum_ = 0
        flag = True
        for k in range(len(i)): #全員の証言が矛盾しないかを考える
            if i[k] == 0: # 不親切ものの場合
                continue
            else: #以下k人目の証言を考える
                sum_ += 1
                for l in range(n):
                    if dd[k][l] != NIL and dd[k][l] != i[l]: #証言と一致していない場合
                        flag = False
                        break
        if flag:
            max_sum = max(max_sum, sum_)

    print(max_sum)
            
if __name__ == '__main__':
    main()
### BUGGY CODE ###

# coding: utf-8
# Your code here!

n = int(input())
num_list = list(map(int, input().split()))
sum=1

for i in num_list:
    if i==0:
        print(0)
        exit()
    i=str(i)
    sum=str(sum)
    
    i=int(i)
    sum=int(sum)
    sum=sum*i
    
if sum>10**18:
    print(-1)
    exit()
print(sum)


### FIXED CODE ###

# coding: utf-8
# Your code here!

n = int(input())
num_list = list(map(int, input().split()))
sum=1

if 0 in num_list:
    print(0)
    exit()

for i in num_list:
    
    if i==0:
        print(0)
        exit()
    i=str(i)
    sum=str(sum)
    
    if len(i)+len(sum)>21:
        print(-1)
        exit()
    i=int(i)
    sum=int(sum)
    sum=sum*i
    if sum>10**18:
        print(-1)
        exit()
print(sum)
### BUGGY CODE ###

N, A, B = map(int, input().split())
list = []
count = 0

if A > N:
  print(N)
  
if A < N and A+B > N:
  print(A)
  
else:
  while len(list) <= N:
    i = 0
    for i in range(A):
      list.append('b')
      
    if len(list) <= N:
      i = 0
      for i in range(B):
        list.append('r')

  for i in range(N):
    if list[i] == 'b':
      count += 1
  print(count)
  

### FIXED CODE ###

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

a = N // (A+B)

if N % (A+B) >= A:
  print(a*A+A)
  
else:
  print(a*A + N % (A+B))
### BUGGY CODE ###

L, R = map(int, input().split())

if L <= 2019 and 2019 <= R:
    ans = 0

else:
    ans = 2019
    for i in range(L, R):
        for j in range(L+1, R+1):
            if (i % 2019 == 0) or (j % 2019 == 0):
                ans = 0
                break
            tmp = (i*j) % 2019
            if tmp <= ans:
                ans = tmp

print(ans)

### FIXED CODE ###

import sys

L, R = map(int, input().split())

if L <= 2019 and 2019 <= R:
    ans = 0

else:
    ans = 2019
    for i in range(L, R):
        for j in range(L+1, R+1):
            if (i % 2019 == 0) or (j % 2019 == 0):
                ans = 0
                print(ans)
                sys.exit()
            tmp = (i*j) % 2019
            if tmp <= ans:
                ans = tmp
print(ans)