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

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

S = input()

C = []

one = True
c = 0
ans = 0
for s in S:
    if s=="0":
        if one:
            one = False
            C.append(c)
            c = 1
        else:
            c += 1
    else:
        if one:
            c += 1
        else:
            one = True
            C.append(c)
            c = 1
            
C.append(c)
CC = []
for i in range(0,max(min(N-K,len(C)),1))[::2]:
    CC.append(sum(C[i:i+(2*K)+1]))
    
print(max(CC))

### FIXED CODE ###

from queue import Queue as q

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

S = input()

C = q()

one = True
subK = 0
c = 0
ans = 0
Mans = 0
for s in S:
    if s=="1":
        if one:
            c += 1
        else:
            one = True
            C.put(c)
            c = 1
    else:
        if one:
            one = False
            subK += 1
            C.put(c)
            c = 1
        else:
            c += 1
    ans += 1
    if subK>K:
        subK -= 1
        ans -= (C.get()+C.get())
    #print(ans)
    if ans > Mans:
        Mans = ans
    
print(Mans)
### BUGGY CODE ###

cnt=0
S=str(input())
mc=[0]*2019
L=len(S)

tg=0
digit=1
for s in S[::-1]:
    tg+=int(s)*digit
    mt=tg%2019
    if mt==0:cnt+=1
    cnt+=mc[mt]
    mc[mt]+=1
    digit*=10
    
print(cnt)


### FIXED CODE ###

S=input()
mc=[0]*2019

tg=0
digit=1
for s in S[::-1]:
    tg+=int(s)*digit
    mc[tg%2019]+=1
    digit=digit*10%2019

ans=sum(m*(m-1)//2 for m in mc)
print(ans+mc[0])
### BUGGY CODE ###

N=int(input())
power=1
for i in range(N):
    power=power*(i+1)

power=power%(10**9+7)
print(power)


### FIXED CODE ###

N=int(input())
power=1
for i in range(N):
    power=power*(i+1)
    power=power%(10**9+7)

print(power)
### BUGGY CODE ###

num = int(input())
input_line = input().split()

num_list = [int(input_line[i]) for i in range(num)]
law = 10 ** 9 + 7
sigma = 0
for i in range(num):
	num_a = num_list[i]
	temp_sum = 0
	for j in range(i+1,num):
		temp_sum += num_list[j]
    	
    
	sigma += num_a * temp_sum % law

sigma %= law
print(sigma)

### FIXED CODE ###

num = int(input())
input_line = input().split()

law = 10 ** 9 + 7
num_list = [int(input_line[i])%law for i in range(num)]

sigma = 0
temp_sum = 0
for j in range(num):
	temp_sum += num_list[j]

for i in range(num):
	num_a = num_list[i]
	temp_sum -= num_a
	sigma += num_a * temp_sum


sigma %= law
print(sigma)
### BUGGY CODE ###

import itertools
n = int(input())
s = [str(input()) for i in range(n)]
w = "abcdefghijklmnopqrstuvwxyz"
num = 0
for h in itertools.combinations(s,2):
    t = 0
    for j in w:
        if h[0].count(j) == h[1].count(j):
            t += 1
        if t == 26:
            num += 1
print(num)

### FIXED CODE ###

from collections import Counter
n = int(input())
s = []
for i in range(n):
    s1 = ''.join(sorted(input()))
    s.append(s1)
s = Counter(s).most_common()
num = 0
for i,h in s:
    num += (h*(h-1))//2
print(num)
### BUGGY CODE ###

# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

class SegmentTree:
    # 初期化処理
    # f : SegmentTreeにのせるモノイド
    # default : fに対する単位元
    def __init__(self, size, f=lambda x,y : x|y, default=0):
        self.size = 2**(size-1).bit_length() # 簡単のため要素数Nを2冪にする
        self.default = default
        self.dat = [default]*(self.size*2) # 要素を単位元で初期化
        self.f = f

    def update(self, i, x):
        i += self.size
        self.dat[i] = x
        while i > 0:
            i >>= 1
            self.dat[i] = self.f(self.dat[i*2], self.dat[i*2+1])

    def query(self, l, r):
        l += self.size
        r += self.size
        lres, rres = self.default, self.default
        while l < r:
            if l & 1:
                lres = self.f(lres, self.dat[l])
                l += 1

            if r & 1:
                r -= 1
                rres = self.f(self.dat[r], rres) # モノイドでは可換律は保証されていないので演算の方向に注意
            l >>= 1
            r >>= 1
        res = self.f(lres, rres)
        return len(res)

N = ir()
S = sr()
seg = SegmentTree(N, f=lambda x,y : x|y, default=set())
for i in range(N):
    seg.update(i, set(S[i]))
    
Q = ir()
for _ in range(Q):
    a, b, c = sr().split()
    if a == '1':
        seg.update(int(b)-1, set(c))
    else:
        print(seg.query(int(b)-1, int(c)))

# 03

### FIXED CODE ###

import sys
from bisect import bisect_left, bisect_right, insort

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
S = list('-' + sr())
d = [[] for _ in range(26)]
for i in range(1, N+1):
    s = S[i]
    o = ord(s) - ord('a')
    insort(d[o], i)

Q = ir()
for _ in range(Q):
    q, a, b = sr().split()
    if q == '1':
        a = int(a)
        if S[a] == b:
            continue
        prev = ord(S[a]) - ord('a')
        d[prev].remove(a)
        next = ord(b) - ord('a')
        insort(d[next], a)
        S[a] = b
    else:
        a = int(a); b = int(b)
        ans = 0
        for alpha in range(26):
            if bisect_right(d[alpha], b) - bisect_left(d[alpha], a) >= 1:
                ans += 1
        print(ans)

# 17
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
dp = [0 for _ in range(N)]

A.sort()

for i in range(N):
    if dp[i] < 2:
        p = A[i]
        for j in range(N):
            if dp[j] < 2 and A[j]%p == 0 and A[j] >= p:
                dp[j] += 1
cnt = 0
for i in range(N):
    if dp[i] == 1:
        cnt += 1

print(cnt)


### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
# dp = [0 for _ in range(N)]

# A.sort()

# for i in range(N):
#     if dp[i] < 2:
#         p = A[i]
#         for j in range(N):
#             if dp[j] < 2 and A[j]%p == 0 and A[j] >= p:
#                 dp[j] += 1
# cnt = 0
# for i in range(N):
#     if dp[i] == 1:
#         cnt += 1
M = 10**6  + 5
cnt = [0 for _ in range(M)]
for x in A:
    if cnt[x] != 0:
        cnt[x] = 2
        continue
    i = x
    while i < M:
        cnt[i] += 1
        i += x
ans = 0
for x in A:
    if cnt[x] == 1:
        ans += 1
print(ans)
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
MODE = 10**9+7

def gcd(a, b):
    return a if b == 0 else gcd(b, a%b)

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

_lcm = 1
for a in A:
    _lcm = lcm(a, _lcm)

ret = 0
for a in A:
    ret += (_lcm // a)
    ret %= MODE

print(ret)


### FIXED CODE ###

import fractions 

N = int(input())
A = list(map(int, input().split()))
MODE = 10**9+7

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

_lcm = 1
for a in A:
    _lcm = lcm(a, _lcm)

ret = 0
for a in A:
    ret += (_lcm // a)

print(ret%MODE)
### BUGGY CODE ###

N = int(input())
a = [int(x) for x in input().split()]
dp = [0 for i in range(N)]
for i in range(N-1, -1, -1):
    dp[i] = a[i]
    prev = dp[i]
    for j in range(i+1, N):
        right = a[i] - dp[j]
        left = a[j] - prev
        if right > left:
            dp[j] = right
            prev = right
        else:
            dp[j] = left
            prev = left
print(dp[-1])

### FIXED CODE ###

def deque(n, arr):
    dp = [[0] * n for _ in range(n)]
    for i in range(n):
        dp[i][i] = arr[i]

    for l in range(n-2, -1, -1):
        for r in range(l+1, n):
            L = arr[l] - dp[l+1][r]
            R = arr[r] - dp[l][r-1]
            dp[l][r] = L if L > R else R
    return dp[0][n-1]

n = int(input())
arr = [int(x) for x in input().split()]
print(deque(n, arr))
### BUGGY CODE ###

N = int(input())
S = input()
ans = 0
TF = False
for i in range(0,(N//2)+1): #iが長さ
    TF = False
    for j in range(N-2*i):    #jは開始位置
        if TF == True:
            break
        tmp = S[j:j+i+1]
        for k in range(j+i+1,N-i):    #kは判断する方の開始位置
            if S[k:k+i+1] == tmp:
                #print("i=",i,"j=",j,"k=",k, tmp)
                ans = i+1
                TF = True
                break
print(ans)

### FIXED CODE ###

#https://atcoder.jp/contests/abc141/submissions/7539109
#Z-Algorithm
n = int(input())
s = input()
 
a = ""
ans = 0
for i in range(n):
    a += s[i]
    while(len(a) > 0):
        if a in s[i+1:]:    #見つかる限りこの処理
            ans = max(ans,len(a))
            break
        else:               #ダメなら次の文字を接頭辞に、短いものは調べなくてよい
            a = a[1:]
print(ans)
### BUGGY CODE ###

n=int(input())
s=input()
sum=0
for k in range(n):
    for j in range(k):
        if s[j]!=s[k]:
            for i in range(j):
                if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i] and j-i!=k-j:
                    sum=sum+1
print(sum)

### FIXED CODE ###

n=int(input())
s=input()
sum=0
r=int(s.count('R'))
g=int(s.count('G'))
b=int(s.count('B'))
for k in range(n):
    for j in range(k):
        i=2*j-k
        if i+1>0:
            if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]:
                sum=sum+1
print(r*g*b-sum)
### BUGGY CODE ###

from collections import deque

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

graph = [[i-1,i+1] for i in range(n+1)]
graph[1]=[2]
graph[n]=[n-1]
graph[0]=[0]

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

def bfs(start,graph2):
    dist = [-1] * (n+1)
    dist[0] = 0
    dist[start] = 0

    d = deque()
    d.append(start)
    while d:
        v = d.popleft()
        for i in graph2[v]:
            if dist[i] != -1:
                continue
            dist[i] = dist[v] + 1
            d.append(i)
        
    dist = dist[start+1:]
    return dist

  
for k in range(1,n):
    ans = 0
    for j in range(1,n):
        dist = bfs(j,graph)
        ans += dist.count(k)
    print(ans)

### FIXED CODE ###

from collections import deque

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

graph = [[i-1,i+1] for i in range(n+1)]
graph[1]=[2]
graph[n]=[n-1]
graph[0]=[0]

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

def bfs(start,graph2):
    dist = [-1] * (n+1)
    dist[0] = 0
    dist[start] = 0

    d = deque()
    d.append(start)
    while d:
        v = d.popleft()
        for i in graph2[v]:
            if dist[i] != -1:
                continue
            dist[i] = dist[v] + 1
            d.append(i)
        
    dist = dist[start+1:]
    return dist

ans=[0 for _ in range(n-1)]
for i in range(1,n+1):
    for j in bfs(i,graph):
        ans[j-1] +=1
 
for i in ans:
    print(i)
### BUGGY CODE ###

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

N,L = list(map(int, input().split()))
alist = list(map(int, input().split()))

MIN = 0
for i in range(N-L+1):
  MIN = alist[i]
  for j in range(1, L):
    if alist[i+j] < MIN:
      MIN = alist[i+j]
  if i != N-L:
    print(MIN, end=' ')
  else:
    print(MIN)




### FIXED CODE ###

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

N,L = list(map(int, input().split()))
alist = list(map(int, input().split()))
arr = []
for i in range(L):
  while arr and alist[i] <= alist[arr[-1]]:
    arr.pop()
  arr.append(i)
for i in range(L, N):
  print(alist[arr[0]], end=' ')
  while arr and arr[0] <= i-L:
    arr.pop(0)
  while arr and alist[i] <= alist[arr[-1]]:
    arr.pop()
  arr.append(i)
print(alist[arr[0]])
### BUGGY CODE ###

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

baito = []
dp = [0] * (10**5+1)
for i in range(N):
    a, b = map(int, input().split())
    baito.append([a, b, 0])

for i in range(M):
    rewards = sorted([x for x in baito if x[0] + i <= M and x[2] == 0], key=lambda x: (-x[1], -x[0]))
    if rewards:
        max_reward = rewards[0]
        max_reward[2] = 1
        if i == 0:
            dp[i] = max_reward[1]
        else:
            dp[i] = dp[i-1] + max_reward[1]
    else:
        if i == 0:
            dp[i] = 0
        else:
            dp[i] = dp[i-1]

print(dp[M-1])


### FIXED CODE ###

import heapq

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

jobs = []
for i in range(N):
    a, b = map(int, input().split())
    jobs.append((a, b))
jobs.sort()

hq = []
ans = 0
index = 0
for i in reversed(range(M)):
    for j in range(index, N):
        a, b = jobs[j]
        if a > M - i:
            break
        if a == M - i:
            heapq.heappush(hq, -jobs[j][1])
            index += 1

    if len(hq):
        ans += heapq.heappop(hq) * (-1)

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


import collections


n=int(input())
s=input()
r=collections.deque()
g=collections.deque()
b=collections.deque()
for i in range(n):
    if s[i]=="R":
        r.append(i+1)
    elif s[i]=="G":
        g.append(i+1)
    else:
        b.append(i+1)
cnt=0
sum=len(b)*len(g)*len(r)
if len(r)*len(g)*len(b)==0:
    print(0)
else:
    for re in r:
        for gr in g:

            re1=re
            re1,gr=min(re,gr),max(re,gr)
            #print(re,gr,b)
            if (re1+gr)%2==0:
                if (re1+gr)//2 in b:
                    cnt-=1
            if 2*gr-re1 in b:
                cnt-=1
            if 2*re1-gr in b:
                cnt-=1

            #print(cnt)
    print(sum+cnt)


### FIXED CODE ###

def ri(): return int(input())
def rli(): return list(map(int, input().split()))
def rls(): return list(map(str, input().split()))
def pl(a): print(" ".join(list(map(str, a))))
def ma():return map(int,input().split())
"""
k=ri()

n,k=ma()
for i in range(n):
    for

n=int(input())
s=input()
r=[0]*n
b=[0]*n
g=[0]*n

for i in range(n):
    if s[i]=="R":
"""

"""
from itertools import accumulate as acc
import operator as op
import copy as cp
import math; import numpy
from bisect import bisect_left as bisl
from bisect import bisect_right as bisr
###
"""



"""
import math
k=int(input())

cnt=0
for a in range(1,k+1):
    for b in range(1,k+1):
        ct=math.gcd(a,b)
        for c in range(1,k+1):
            cnt+=math.gcd(ct,c)

print(cnt)
"""
"""
n,k=map(int,input().split())
mod=10**9+7

import math
dj0=[[i for i in range(1,k+1)] for j in range(k)]
dj1=[i for i in range(1,k+1)]
dj2=[0]*k
for i in dj1:
    for j in range(1,k):
        dj0[i-1][j-1]=math.gcd(i,j)
        dj2[math.gcd(i,j)]+=1
"""
n=ri()
s=input()
ans = s.count("R")*s.count("G")*s.count("B")
for i in range(n):
    for j in range(i+1,n):
        k=2*j-i
        if k>=n:
            break
        ans-=s[k]!=s[i]!=s[j]!=s[k]

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

import math
import itertools

k=int(input())

ans=0
for i in range(1,k+1) :
    for j in range(1,k+1) :
        x=math.gcd(i,j)
        for k in range(1,k+1) :
            y=math.gcd(i,k)
            z=math.gcd(x,y)
            ans+=z

print(ans)




### FIXED CODE ###

from math import gcd

k=int(input())
ans=0

for a in range(1,k+1) :
    for b in range(1,k+1) :
        for c in range(1,k+1) :
            ans+=gcd(gcd(a,b),c)

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

S = input()
Q = int(input())
s = S

rev = 0

for i in range(Q):
    query = input()
    ti = list(query)[0]
    if ti == '1':
        rev = (rev + 1) % 2
    else:
        ti, fi, ci = query.split()
        if (int(fi) + rev) == 2:
            s += ci
        else:
            s = ci + s

if rev == 1:
    s = list(s)
    s.reverse()
    s = ''.join(s)
print(s)

### FIXED CODE ###

class Node:
    def __init__(self, char: str):
        self.before = None
        self.char = char
        self.next = None

class Linked_List:
    def __init__(self):
        self.head = None
        self.tail = None
    
    def add_head(self, node):
        if self.head is None:
            self.head = node
            self.tail = node
        else:
            node.next = self.head
            self.head.before = node
            self.head = node

    def add_tail(self, node):
        if self.tail is None:
            self.head = node
            self.tail = node
        else:
            node.before = self.tail
            self.tail.next = node
            self.tail = node

    def show(self, is_reversed: bool):
        ret = []
        node = self.tail if is_reversed else self.head
        while not node is None:
            c = ''.join(list(node.char)[::-1]) if is_reversed else node.char
            ret.append(c)
            node = node.before if is_reversed else node.next
        print(''.join(ret))

S = input()
Q = int(input())
ll = Linked_List()
ll.add_head(Node(S))
is_reversed = False

for _ in range(Q):
    query = input()
    if query[0] == '1':
        is_reversed = False if is_reversed else True
    else:
        t, f, c = query.split()
        if is_reversed:
            c = ''.join(list(c)[::-1])
        if f == '1':
            if is_reversed:
                ll.add_tail(Node(c))
            else:
                ll.add_head(Node(c))
        else:
            if is_reversed:
                ll.add_head(Node(c))
            else:
                ll.add_tail(Node(c))

ll.show(is_reversed)
### BUGGY CODE ###

k, s = map(int, input().split())

count = 0
for x in range(k + 1):
  for y in range(k + 1):
    z = s - x - y
    if z < 0:
      continue
    if x > k or y > k or z > k:
      continue
    if (x + y + z) == s:
      count += 1

print(count)

### FIXED CODE ###

k, s = map(int, input().split())

count = 0
for x in range(k + 1):
  for y in range(k + 1):
    z = s - x - y
    if z >= 0 and z <= k:
      count += 1

print(count)
### BUGGY CODE ###

ans=0
N,M=[int(i) for i in input().split()]
A=input().split()
for i in range(N):
    a=0
    for j in A[i:N+1]:
        a+=int(j)
        if a%M==0:
            ans+=1
print(ans)



### FIXED CODE ###

N,M = [int(i) for i in input().split()]
A = [int(j) for j in input().split()]
B = [0,A[0]]
for i in range(1,len(A)):
    B+=[A[i]+B[i]]
C = {}
X = 0
for j in B:
    if str(j%M) in C:
        X+=C[str(j%M)]
        C[str(j%M)]+=1
    else:
        C.update({str(j%M):1})
print(X)
### BUGGY CODE ###

# ABC144 C
from itertools import combinations
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def factorize(n):
    retlist = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            while temp%i==0:
                temp //= i
                retlist.append(i)
    if temp!=1:
        retlist.append(temp)

    if retlist==[]:
        retlist.append(n)

    return retlist

N = ni()

ans = 0
L = []
L = factorize(N)

ans = 10**13
m = ((len(L)+1)//2) + 1
for i in range(1,len(L)+1):
    if i<=m:
        C = []
        C = list(combinations(L,i))
    for c in C:
        a,b = 1,0
        for j in range(len(c)):
            a *= c[j]
            b = N//a
            ans = min(ans,a-1+b-1)

print(ans)


### FIXED CODE ###

# ABC144 C - Walk on Multiplication Table
import math
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
n = ni()
sqrtn = int(math.sqrt(n))
for i in range(sqrtn, 0, -1):
    if n%i == 0:
        j = n // i
        print(i+j-2)
        break
### BUGGY CODE ###

# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = s_inpl()   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = inpl()	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import math
import numpy as np
import copy
from collections import defaultdict, Counter
from itertools import product
from bisect import bisect_left, bisect_right

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

N, Q = s_inpl()
S = input()
l, r = [], []
for _ in range(Q):
    li, ri = s_inpl()
    l.append(li)
    r.append(ri)

ls = []
for i in range(N-1):
    ls.append(S[i]+S[i+1] == "AC")

for li, ri in zip(l, r):
    print(sum(ls[li-1:ri-1]))

### FIXED CODE ###

# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = s_inpl()   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = inpl()	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import math
import numpy as np
import copy
from collections import defaultdict, Counter
from itertools import product
from bisect import bisect_left, bisect_right

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

N, Q = s_inpl()
S = input()
l, r = [], []
for _ in range(Q):
    li, ri = s_inpl()
    l.append(li)
    r.append(ri)

ls = []
for i in range(N-1):
    ls.append(S[i]+S[i+1] == "AC")

res = list(np.cumsum(ls))
res.insert(0, 0)

for li, ri in zip(l, r):
    print(res[ri-1] - res[li-1])
### BUGGY CODE ###

N,M = map(int,input().split())
people = [None] * N
from collections import defaultdict
lang = defaultdict(set)

for i in range(N):
  people[i] = list(map(int,input().split()))[1:]
  for l in people[i]:
    lang[l].add(i)
    
# 0番の人からたどって全員に行けるか
stack = [0]
seen = [False for i in range(N)]

while stack:
  p = stack.pop()
  if seen[p]:
    continue
  seen[p] = True
  la = people[p] # その人が話せる言語リスト
  for l in la:
    lang[l].remove(p)
    for pe in lang[l]:
      stack.append(pe)
  
for s in seen:
  if not s:
    print("NO")
    break
else:
  print("YES")


### FIXED CODE ###

# 人も言語もグラフの頂点と見なす
# ある人がある言語を話せる場合連結となる
# 頂点のキーは[言語 or 人][番号(人番号 or 言語番号)]
# 0:言語 1:人

N,M = map(int,input().split())
from collections import defaultdict
E = [[],[]]
E[0] = [[] for i in range(M)]
E[1] = [[] for i in range(N)]

for i in range(N):
  langs = list(map(int,input().split()))[1:]
  for lang in langs:
    E[1][i].append((0,lang-1))
    E[0][lang-1].append((1,i))
    
# 任意の頂点からBFSして、全ての人の頂点が往訪済みになればOK
from collections import deque
q = deque([])
# 人で、0番目からスタート
q.append((1,0))
seen = [[],[]]
seen[0] = [False for i in range(M)]
seen[1] = [False for i in range(N)]

while q:
  kind,v = q.popleft()
  if seen[kind][v]:
    continue
  seen[kind][v] = True
  children = E[kind][v]
  for child in children:
    q.append([child[0],child[1]])
    
for s in seen[1]:
  if not s:
    print("NO")
    break
else:
  print("YES")
### BUGGY CODE ###

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

def imos(n,a):
  imos_l=[0 for i in range(n)]

  for i in range(n):
    x=i
    x_left=max(x-a[i],0)
    x_right=min(x+a[i],n-1)

    imos_l[x_left]+=1
    if (x_right+1)!=n:
      imos_l[x_right+1]-=1

  b=[0]
  for i in range(1,n+1):
    b.append(imos_l[i-1]+b[i-1])

  return(b[1:])

for i in range(k):
  a=imos(n,a)

  if a.count(n)==n:
    break

print(*a)

### FIXED CODE ###

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

def imos(n,a):
  imos_l=[0 for i in range(n)]

  for i in range(n):
    x=i
    x_left=max(x-a[i],0)
    x_right=min(x+a[i],n-1)

    imos_l[x_left]+=1
    if (x_right+1)!=n:
      imos_l[x_right+1]-=1

  b=[0]
  for i in range(1,n+1):
    b.append(imos_l[i-1]+b[i-1])

  return(b[1:])

for i in range(k):
  a=imos(n,a)

  if a.count(n)==n:
    break

print(*a)
### BUGGY CODE ###

def solve(l:list):
    ans = 0
    for i in range(len(l)):
        for j in range(i):
            if l[i] == l[j]:
                ans += 1
    return ans

def main():
    n = int(input())
    l = [sorted(input()) for _ in range(n)]
    print(solve(l))

if __name__ == "__main__":
    main()

### FIXED CODE ###

n = int(input())
D = {}
for _ in range(n):
  str = "".join(sorted(input()))
  if str in D:
    D[str] += 1
  else:
    D[str] = 1
ans = 0
for i in D.values():
  ans += i * (i-1) // 2
print(ans)