Harryxun/stf_run huggingface dataset:
import sys
from collections import deque
import bisect
import copy
import heapq
import itertools
import math
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


def main():
    N, K = read_values()
    A = read_list()
    A.sort(reverse=True)
    if A[0] < 0:
        res = 1
        for a in A[:K]:
            res *= a
            res %= mod
        print(res)
        return

    A.sort(key=lambda a: abs(a), reverse=True)

    P1 = list(filter(lambda a: a >= 0, A[:K]))
    P2 = list(filter(lambda a: a >= 0, A[K:]))
    N1 = list(filter(lambda a: a < 0, A[:K]))
    N2 = list(filter(lambda a: a < 0, A[K:]))

    if len(N1) % 2 == 1:
        # if N1[-1] * N2[0] : P1[-1] * P2[0]
        if len(P1) == 0 or len(N2) == 0:
            N1[-1] = P2[0]
        elif len(P2) == 0:
            P1[-1] = N2[0]
        else:
            if P1[-1] * P2[0] >= N1[-1] * N2[0]:
                N1[-1] = P2[0]
            else:
                P1[-1] = N2[0]
    
    res = 1
    for p in P1:
        res *= p
        res %= mod

    for n in N1:
        res *= n
        res %= mod
    
    print(res % mod)
        

if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys
from collections import deque
import bisect
import copy
import heapq
import itertools
import math
import random
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


N, K = read_values()
def main():
    A = read_list()
    # A = [random.randint(-10 ** 9, 10 ** 9) for _ in range(N)]

    A.sort(reverse=True)
    if N == K or (A[0] < 0 and K % 2 == 1):
        res = 1
        for a in A[:K]:
            res *= a
            res %= mod
        print(res)
        return

    A.sort(key=lambda a: abs(a), reverse=True)

    P1 = list(filter(lambda a: a >= 0, A[:K]))
    P2 = list(filter(lambda a: a >= 0, A[K:]))
    N1 = list(filter(lambda a: a < 0, A[:K]))
    N2 = list(filter(lambda a: a < 0, A[K:]))

    if len(N1) % 2 == 1:
        # if N1[-1] * N2[0] : P1[-1] * P2[0]
        if len(P1) == 0 or len(N2) == 0:
            N1[-1] = P2[0]
        elif len(P2) == 0:
            P1[-1] = N2[0]
        else:
            if P1[-1] * P2[0] >= N1[-1] * N2[0]:
                N1[-1] = P2[0]
            else:
                P1[-1] = N2[0]
    
    res = 1
    for p in P1:
        res *= p
        res %= mod

    for n in N1:
        res *= n
        res %= mod
    
    print(res % mod)
        

if __name__ == "__main__":
    main()
import math
a, b, x = map(int, input().split())
if x <= 0.5 * a*a*b:
    ans = math.pi / 2 - math.atan(2*x / (b*b*a))
    print(ans / (math.pi/ 4) * 45)
else:
    ans = math.atan(a*a*a / (2*a*a*b - 2*x))
    print(90 - ans / (math.pi/ 4) * 45)

### FIXED CODE ###

import math
a, b, x = map(int, input().split())
if x <= 0.5 * a*a*b:
    ans = math.pi / 2 - math.atan(2*x / (b*b*a))
    print(ans / (math.pi/ 4) * 45)
elif x == a * a *b:
    print(0)
else:
    ans = math.atan(a*a*a / (2*a*a*b - 2*x))
    print(90 - ans / (math.pi/ 4) * 45)
s = str(input())
t = str(input())
s2 = ''.join(sorted(s))
t2 = ''.join(sorted(t))

if s2 < t2:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

import math
a,b = map(int,input().split())
x = (a + b)/2
print(math.ceil(x))
n = int(input())
a = list(map(int, input().split()))
cum = [0] * (n+1)
for i in range(n):
    cum[i+1] = cum[i] + a[i]
l = 0
r = 0
count = 0
while(r + 1 < n):
    if (cum[r] - cum[l]) & a[r+1] == 0:
        r += 1
        count += 1
    else:
        j += 1
print(count)


### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
cum = [0] * (n+1)
for i in range(n):
    cum[i+1] = cum[i] + a[i]
l = 0
r = 0
count = 0
while(r < n or l < n):
    if r < n and (cum[r] - cum[l]) & a[r] == 0:
        r += 1
    else:
        count += r - l
        l += 1
print(count)
#!/usr/bin/env python3
import bisect
n = int(input())
a = sorted(map(int, input().split()))
if n == 2:
    print(a[1] - a[0])
    print(a[1], a[0])
    exit()

p = bisect.bisect_left(a, 0)
if p < 2 and n == 3:
    print(sum(a) - 2 * a[0])
    print(a[0], a[1])
    b = a[0] - a[1]
    print(a[2], b)
    exit()

p = max(2, p)
print(sum(a[p:]) - sum(a[:p]))
b = a[0]
for i in range(p + 1, n):
    print(b, a[i])
    b -= a[i]
c = a[p]
for i in range(1, p):
    print(c, a[i])
    c -= a[i]
print(c, b)


### FIXED CODE ###

#!/usr/bin/env python3
import bisect
n = int(input())
a = sorted(map(int, input().split()))
if n == 2:
    print(a[1] - a[0])
    print(a[1], a[0])
    exit()

p = bisect.bisect_left(a, 0)
p = min(max(1, p), n - 1)
print(sum(a[p:]) - sum(a[:p]))
b = a[p - 1]
for i in range(p, n - 1):
    print(b, a[i])
    b -= a[i]
c = a[n - 1]
for i in range(p - 1):
    print(c, a[i])
    c -= a[i]
print(c, b)
n=int(input())
s=list(map(ord,input().split()))
R=[0]
G=[0]
B=[0]
for i in s:
  R.append(R[-1])
  G.append(G[-1])
  B.append(B[-1])
  if i==82:R[-1]+=1
  elif i=="71":G[-1]+=1
  else:B[-1]+=1
ans=0
for i in range(n-2):
  for j in range(i+1,n-1):
    if s[i]==s[j]:continue
    if 82 not in [s[i],s[j]]:
      ans+=R[-1]-R[j]
      if j+(j-i)<n:
        if s[j+(j-i)]==82:ans-=1
    elif 71 not in [s[i],s[j]]:
      ans+=G[-1]-G[j]
      if j+(j-i)<n:
        if s[j+(j-i)]==71:ans-=1
    else:
      ans+=B[-1]-B[j]
      if j+(j-i)<n:
        if s[j+(j-i)]==66:ans-=1
print(ans)


### FIXED CODE ###

n=int(input())
s=input()
R=[0]
G=[0]
B=[0]
for i in s:
  R.append(R[-1])
  G.append(G[-1])
  B.append(B[-1])
  if i=="R":R[-1]+=1
  elif i=="G":G[-1]+=1
  else:B[-1]+=1
ans=0
for i in range(n-2):
  for j in range(i+1,n-1):
    if s[i]==s[j]:continue
    if "R" not in [s[i],s[j]]:
      ans+=R[-1]-R[j]
      if j+(j-i)<n:
        if s[j+(j-i)]=="R":ans-=1
    if "G" not in [s[i],s[j]]:
      ans+=G[-1]-G[j]
      if j+(j-i)<n:
        if s[j+(j-i)]=="G":ans-=1
    if "B" not in [s[i],s[j]]:
      ans+=B[-1]-B[j]
      if j+(j-i)<n:
        if s[j+(j-i)]=="B":ans-=1
print(ans)
X, Y = [int(a) for a in input.split()]
ret = int(X + Y/2 + 0.1)
print(str(ret))


### FIXED CODE ###

X, Y = [int(a) for a in input().split()]
ret = int(X + Y/2 + 0.1)
print(str(ret))
import sys
sys.setrecursionlimit(10**6)

N, K = map(int, input().split())
P = list(map(int,input().split()))
out = 0
p = P[0:K]
base = sum(p)
for i in range(N-K):
  out += P[i+K]-P[i]
  print(out)
  if i == 0:
    ans = out
  else:
    if out > ans:
      ans = out
    else:
      continue
answer = (base+ans+K)/2
print(base, ans)
print(answer)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)

N, K = map(int, input().split())
P = list(map(int,input().split()))
out_ = 0
p = P[0:K]
base = sum(p)
if N == K:
  answer = (sum(p)+K)/2
else:
  for i in range(N-K):
    out_ += P[i+K]-P[i]
    if i == 0:
      ans = out_
    else:
      if out_ > ans:
        ans = out_
      else:
        continue
  answer = (base+ans+K)/2
print(answer)
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N, K = LI()
    S = SS()

    # 1の塊の長さと位置を調べる
    l = []
    if S[0] == '1':
        l.append(0)
    for i in range(N - 1):
        if S[i] == '0' and S[i+1] == '1':
            l.append(i + 1)
        elif S[i] == '1' and S[i+1] == '0':
            l.append(i + 1)
    if S[-1] == '1':
        l.append(N)
    # print(l)

    # 1の塊をK+1個くっつけた場合の長さを調べる
    ans = 0
    for i in range(len(l) // 2 - K):
        ans = max(l[2*i+2*K+1] - l[2*i], ans)

    # 端の0を逆立ちさせた場合
    if S[0] == '0':
        ans = max(l[2*K-1], ans)
    if S[-1] == '0':
        ans = max(N - l[len(l)//2-K], ans)
    
    # 全部1だった場合(塊の間も無いし端の0もない)
    if l == [0, N]:
        ans = N

    print(ans)

if __name__ == '__main__':
    resolve()


### FIXED CODE ###

import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N, K = LI()
    S = SS()

    # 1の塊の長さと位置を調べる
    l = []
    if S[0] == '1':
        l.append(0)
    else:
        l.append(0)
        l.append(0)
    for i in range(N - 1):
        if S[i] == '0' and S[i+1] == '1':
            l.append(i + 1)
        elif S[i] == '1' and S[i+1] == '0':
            l.append(i + 1)
    if S[-1] == '1':
        l.append(N)
    else:
        l.append(N)
        l.append(N)
    # print(S)
    # print(l)

    # 1の塊をK+1個くっつけた場合の長さを調べる
    ans = 0
    if len(l) // 2 - 1 < K:
        ans = N
    else:
        for i in range(len(l) // 2 - K):
            ans = max(l[2*i+2*K+1] - l[2*i], ans)

    # 端の0を逆立ちさせた場合
    # if S[0] == '0':
    #     ans = max(l[2*K-1], ans)
    # if S[-1] == '0':
    #     ans = max(N - l[len(l)-2*K], ans)
    
    # 全部1だった場合(塊の間も無いし端の0もない)
    # if l == [0, N]:
    #     ans = N

    print(ans)

if __name__ == '__main__':
    resolve()
# -*- coding:utf-8 -*-
S = list(input())

loop_idx = 0
loop_len = -(-len(S)//2)
cnt = 0

if len(S) == 1:
    pass
else:
    while loop_idx < loop_len:
        while True:
            if S[0] == "W":
                S.pop(0)
            else:
                break
        while True:
            if S[-1] == "B":
                S.pop(-1)
            else:
                break
        for i in range(len(S)-1,0,-1):
            if S[i]=="W" and S[i-1] == "B":
                cnt += 1
                S[i],S[i-1] = "B","W"
        loop_idx += 1
        #print(S)
print(cnt)

### FIXED CODE ###

# -*- coding:utf-8 -*-
S = list(input())

cnt_b = 0 
ans = 0

for i in range(len(S)):
    if S[i] == "B":
        cnt_b += 1
    if S[i] == "W":
        ans += cnt_b
print(ans)
import numpy as np
S = input()
l = len(S)
oddArr = np.arange(0,l+1,2)
evenArr = np.arange(1,l,2)
playable = True
for i in oddArr:
    if S[i]=='R' or S[i]=='U' or S[i]=='D':
        continue
    else:
        playable = False
        break
if playable:
    for i in evenArr:
        if S[i] == 'L' or S[i] == 'U' or S[i] == 'D':
            continue
        else:
            playable = False
            break
if playable:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

import numpy as np
S = input()
l = len(S)
oddArr = np.arange(1,l+1,2)
evenArr = np.arange(2,l+1,2)
playable = True
for i in oddArr:
    if S[i-1]=='R' or S[i-1]=='U' or S[i-1]=='D':
        continue
    else:
        playable = False
        break
if playable:
    for i in evenArr:
        if S[i-1] == 'L' or S[i-1] == 'U' or S[i-1] == 'D':
            continue
        else:
            playable = False
            break
if playable:
    print('Yes')
else:
    print('No')
N = int(input())
A = list(map(int, input().split()))
dict1 = {}
for i in range(N):
  if A[i] not in dict1.keys():
    dict1[A[i]] = 0
  else:
    dict1[A[i]] += 1
value1 = []
for value in dict1.values():
  value1.append(value)
value2 = sorted(value1, reverse = True)
if value2[0] - value2[1] >= sum(value2[1:]):
  print(N - (value2[0] * 2))
else:
  if(sum(value2[0:]) % 2 == 0):
    print(len(value2))
  else:
    if len(value2) != 0:
      print(len(value2) - 1)
    else:
      print(1)


### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
dict1 = {}
for i in range(N):
  if A[i] not in dict1.keys():
    dict1[A[i]] = 0
  else:
    dict1[A[i]] += 1
value1 = []
for value in dict1.values():
  value1.append(value)
value2 = sorted(value1, reverse = True)
if len(value2) != 1:
  if value2[0] - value2[1] >= sum(value2[1:]):
    print(N - (value2[0] * 2))
  else:
    if(sum(value2[0:]) % 2 == 0):
      print(len(value2))
    else:
      print(len(value2) - 1)
else:
  print(1)
a,b,c,d=map(int,input().split())
if a+b>c+d:
  print("Left")
elif a+b=c+d:
  print("Balanced")
else:
  print("Right")

### FIXED CODE ###

a,b,c,d=map(int,input().split())
if a+b>c+d:
  print("Left")
elif a+b==c+d:
  print("Balanced")
else:
  print("Right")
line=input().split(" ")
a=int(line[0])
b=int(line[1])
c=int(line[2])
d=int(line[3])
 
while a>0 and c>0:
  c=c-b
  if c<=0:
    print("Yes")
    break
  a=a-d
  if a<=0:
    print("No")
    break
line=input().split(" ")
a=int(line[0])
b=int(line[1])
c=int(line[2])
d=int(line[3])

while a>0 and c>0:
  c=c-b
  if c<=0:
    print("Yes")
    break
  a=a-d
  if a<=0:
    print("No")
    break


### FIXED CODE ###

line=input().split(" ")
a=int(line[0])
b=int(line[1])
c=int(line[2])
d=int(line[3])

while a>0 and c>0:
  c=c-b
  if c<=0:
    print("Yes")
    break
  a=a-d
  if a<=0:
    print("No")
    break
a,b=map(lambda x:14 if int(x)==1 else int(x),input().split())
if a>b:s='Alice';elif a<b:s='Bob';else:s='Draw';print(s)

### FIXED CODE ###

a,b=map(lambda x:14 if int(x)==1 else int(x),input().split())
if a>b:s='Alice'
elif a<b:s='Bob'
else:s='Draw'
print(s)
n, k = map(int, input().split())
a = [0] + list(map(int, input().split()))
b = [1]
c = a[1]
d = 0
e=0
length = 0
first = 0
ans = 0


while c not in b:
    b += [c]
    c = a[c]
    d = c
    e+=1

if d != 0:
    length = e - b.index(d)
    first = b.index(d)
if k <= first:
    ans = b[k]
elif d == 0:
    ans = 1
else:
    ans = b[(k - first) % length + first]
print(ans)


### FIXED CODE ###

n, k = map(int, input().split())
a = [0] + list(map(int, input().split()))
t = [0 for i in range(n+1)]
b = [1]
c = a[1]
d = 0
e=1
length = 0
first = 0
ans = 0


while t[d] < 1:
    t[d]=e
    b += [c]
    c = a[c]
    d = c
    e+=1

if d != 0:
    length = e - t[d]
    first = b.index(d)
if k <= first:
    ans = b[k]
elif d == 0:
    ans = 1
else:
    ans = b[(k - first) % length + first]
print(ans)
#import math

listc = []
listd = {}
answer = []
n = 0

while True:
    s = input()
    if not s:
        break
    else:
        n += 1
        c,d = map(int,s.split(','))
    if c in listc:
        listd[c] += 1
    else:
        listc.append(c)
        listd[c] = 1

while n > 0:
    n -= 1
    c,d = map(int,input().split(','))
    if c in listc:
        if not c in answer:
            answer.append(c)
        listd[c] += 1

answer.sort()
for i in answer:
    print(i,listd[i])


### FIXED CODE ###

#import math

listc = [0]*1001
cnt = [0]*1001
n = 0

while True:
    try:
        c, d = list(map(int, input().split(',')))
    except:
        break
    listc[c] = 1
    cnt[c] += 1

while True:
    try:
        c, d = list(map(int, input().split(',')))
    except:
        break
    if listc[c] == 1:
        listc[c] = 2
    cnt[c] += 1

for c in range(1,1001):
    if listc[c] == 2:
        print(c,cnt[c])
n,m = map(int,input().split())
p_list = [input().split() for i in range(m)]

ans_list = [[[0] for i in range(2)] for j in range(n)]
#print(ans_list[0])
for i in range(m):
    p_num = int(p_list[i][0])
    if p_list[i][1] == "WA":
        ans_list[p_num-1][1]  = 1
    else:
        ans_list[p_num-1][0]  = 1
count1 = 0
count2 = 0
for i in range(n):
    if ans_list[i][0] == 1:
        count += 1
        if ans_list[i][1] == 1:
            count2 += 1
print(count1,count2)


### FIXED CODE ###

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

ans_list = [[0 for i in range(2)] for j in range(n)]
#print(ans_list[0])
for i in range(m):
    p_num = int(p_list[i][0])
    if ans_list[p_num-1][0] != 1:
        if p_list[i][1] == "WA":
            ans_list[p_num-1][1]  =  ans_list[p_num-1][1] + 1
        else:
            ans_list[p_num-1][0]  = 1
count1 = 0
count2 = 0
for i in range(n):
    if ans_list[i][0] == 1:
        count1 += 1
        count2 += ans_list[i][1]
print(count1,count2)
n = int(input())
a = [i in int(input())]
for  i in range(n):
    v  = a[i]
    j = i-1
    while a[j]>a[j+1] and j>0:
        a[j+1] = a[j]
        a[j] = v
        j -=1
    print(*a)


### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
for  i in range(n):
    v  = a[i]
    j = i-1
    while a[j]>v and j>=0:
        a[j+1] = a[j]
        j -=1

    a[j+1] = v
    print(*a)
n=int(input())
lists2=[2*j for j in range(1,15001)]
lists3 =[3+6*k for k in range(0,5000)]
for q in range(1,5001):
    if (n-2*q)%3==0 and 1<=n-2*q<=15000:
        p=(n-2*q)
        break
lists=lists2[:p]+lists3[:2*q]
print(*lists)

### FIXED CODE ###

a=0
b=0
lists=[]
n=int(input())
lists2=[2*j for j in range(1,15001)]
lists3 =[3+6*k for k in range(0,5000)]
for q in range(1,2501):
    if (n-2*q)%3==0 and 1<=(n-2*q)<=15000:
        a=(n-2*q)
        b=q
if n>=7and n!=19999:
    lists=lists2[:a]+lists3[:2*b]
    print(*lists)
elif n==3:
    lists=[2,5,63]
    print(*lists)
elif n==4:
    lists=[2 ,5 ,20, 63]
    print(*lists)  
elif n==5:
    lists=[2,4,6,3,9]
    print(*lists)
elif n==6:
    lists=[2,5,20,63,70,140]
    print(*lists)
elif n==19999:
    lists=lists2[:14985]
    addlist2=[]
    count=0
    for i in lists3:
        if i%5!=0:
            addlist2.append(i)
            count+=1
        if count==3040:
            break
    addlist3=[]
    counter=0
    for i in range(5,30001,5):
        if i%2!=0 and i%3!=0:
            addlist3.append(i)
            counter+=1
        if counter==1974:
            break
    lists=lists+addlist2+addlist3
    print(*lists)
N, M = (int(i) for i in input().split())
A = [int(i) for i in input().split()]
A.sort(reverse=True)
As = [0]*(N+1)
for i in range(N):
    As[i+1] = As[i] + A[i]
A.reverse()

import bisect

def flag(x):
    ans = 0
    for i in range(N):
        a = x - A[i]
        res = bisect.bisect_left(A, a)
        ans += (N-res)
    return bool(ans >= M)

def an(x):
    ans = 0
    m = 0
    for i in range(N):
        a = x - A[i]
        res = bisect.bisect_left(A, a)
        m += (N-res)
        ans += As[N-res]
        ans += A[i] * (N-res)
    ans -= (m - M) * x
    return ans


low = 0
high = 10**5 + 100

while low <= high:
    mid = (low + high) // 2
    if flag(mid):
        if not flag(mid+1):
            ans = mid
            break
        else:
            low = mid + 1
    else:
        high = mid - 1

print(an(ans))



### FIXED CODE ###

N, M = (int(i) for i in input().split())
A = [int(i) for i in input().split()]
A.sort(reverse=True)
As = [0]*(N+1)
for i in range(N):
    As[i+1] = As[i] + A[i]
A.reverse()

import bisect

def flag(x):
    ans = 0
    for i in range(N):
        a = x - A[i]
        res = bisect.bisect_left(A, a)
        ans += (N-res)
    return bool(ans >= M)

def an(x):
    ans = 0
    m = 0
    for i in range(N):
        a = x - A[i]
        res = bisect.bisect_left(A, a)
        m += (N-res)
        ans += As[N-res]
        ans += A[i] * (N-res)
    ans -= (m - M) * x
    return ans


low = 0
high = 10**6

while low <= high:
    mid = (low + high) // 2
    if flag(mid):
        if not flag(mid+1):
            ans = mid
            break
        else:
            low = mid + 1
    else:
        high = mid - 1

print(an(ans))
s=str(input())
x=list(s)
out=""
for i in range(x):
	if (i+1) % 2 !=1:
		out+=x[i]
print(out)

### FIXED CODE ###

x,t=map(int, input().split())

print(max(x-t,0))
N, M = map(int, input().split())

parent = [i for i in range(N + M)]
rank = [0] * (N + M)


def find(i):
    if parent[i] == i:
        return i
    else:
        parent[i] = find(parent[i])
        return parent[i]


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


def unite(x, y):
    x = find(x)
    y = find(y)
    if x == y:
        return

    if rank[x] > rank[y]:
        parent[y] = x
    else:
        parent[x] = y
        if rank[x] == rank[y]:
            rank[y] += 1


for i in range(N):
    P = list(map(int, input().split()))
    n = P[0]
    for j in range(1, n + 1):
        unite(N + i, P[j] - 1)


k = find(0)
for i in range(N):
    if k != find(i):
        print('NO')
        exit()

print('YES')

### FIXED CODE ###

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

parent = [i for i in range(N + M)]
rank = [0] * (N + M)


def find(i):
    if parent[i] == i:
        return i
    else:
        parent[i] = find(parent[i])
        return parent[i]


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


def unite(x, y):
    x = find(x)
    y = find(y)
    if x == y:
        return

    if rank[x] > rank[y]:
        parent[y] = x
    else:
        parent[x] = y
        if rank[x] == rank[y]:
            rank[y] += 1


for i in range(N):
    P = list(map(int, input().split()))
    n = P[0]
    for j in range(1, n + 1):
        unite(i, P[j] - 1 + N)


k = find(0)
for i in range(N):
    if k != find(i):
        print('NO')
        exit()

print('YES')
from collections import defaultdict

def main():
    N, M = map(int, input().split())
    g = defaultdict(set)

    for _ in range(M):
        a, b = map(int, input().split())
        a -= 1
        b -= 1 
        g[a].add(b)
        g[b].add(a)

    from functools import lru_cache
    def dfs(u, visited: set):
        visited.add(u)
        for v in g[u]:
            if v not in visited:
                dfs(v, visited)

    count = dict()       
    for u in range(N):
        if u in count:
            continue
        visited = set()
        dfs(u, visited)
        # print(visited)
        count[u] = len(visited)
        for v in visited:
            count[v] = len(visited)

    print(max(count.values()))


if __name__ == '__main__':
    main()

### FIXED CODE ###

class UnionFind(object):

    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for _ in range(n)]

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y]

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

    def get_size(self, x):
        x = self.find(x)
        return self.size[x]


def main():
    N, M = map(int, input().split())

    uf = UnionFind(N)
    for _ in range(M):
        a, b = map(int, input().split())
        uf.union(a-1, b-1)

    ans = max(uf.get_size(i) for i in range(N))
    print(ans)


if __name__ == '__main__':
    main()
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)
else:
  print(1)

### FIXED CODE ###

S = input()
if S == "SUN":
  print(7)
elif S == "MON":
  print(6)
elif S == "TUE":
  print(5)
elif S == "WED":
  print(4)
elif S == "THU":
  print(3)
elif S == "FRI":
  print(2)
else:
  print(1)
n,k = map(int,input().split())

def ans(cnt,a,b,c=0):
    if cnt == a :
        return c
    else :
        if cnt == 0: 
            c += b
            cnt += 1
            return ans(cnt,a,b,c) 
        else: 
            cnt += 1
            c = c*(b-1)
            return ans(cnt,a,b,c)

a = ans(cnt = 0,a = n,b = k,c=0)
print(a)

### FIXED CODE ###

n,k = map(int,input().split())
ans = k*(k-1)**(n-1)
print(ans)