Harryxun/stf_run huggingface dataset:
from collections import deque
import numpy as np
def solve(n, x, y):
    def dist(i, j):
        return min(abs(x[i]-x[j]), abs(y[i]-y[j]))
    que = []
    for v in [x, y]:
        p = np.argsort(v)
        for i in range(n-1):
            u, v = p[i], p[i+1]
            que.append((u, v, dist(u, v)))
    parent = {i: i for i in range(n)}
    def find(i):
        if parent[i] == i:
            return i
        else:
            j = find(parent[i])
            parent[i] = j
            return j
    que = deque(sorted(que, key=lambda _: _[2]))
    ans = 0
    while que:
        u, v, d = que.popleft()
        u = find(u)
        v = find(v)
        if u != v:
            ans += d
            parent[u] = v
    return ans

n = int(input())
x = [0] * n
y = [0] * n
for i in range(n):
    x[i], y[i] = map(int, input().split())
print(solve(n, x, y))

### FIXED CODE ###

import numpy as np

def solve(n, x, y):
    def dist(i, j):
        return min(abs(x[i]-x[j]), abs(y[i]-y[j]))
    que = []
    for p in map(np.argsort, [x, y]):
        for i in range(n-1):
            u, v = p[i], p[i+1]
            que.append((u, v, dist(u, v)))
    parent = [i for i in range(n)]
    def find(i):
        if parent[i] == i:
            return i
        else:
            j = find(parent[i])
            parent[i] = j
            return j
    ans = 0
    for u, v, d in sorted(que, key=lambda _: _[2]):
        u = find(u)
        v = find(v)
        if u != v:
            ans += d
            if u > v:
                u, v = v, u
            parent[v] = u
    return ans

n = int(input())
x = np.zeros(n, dtype=int)
y = np.zeros(n, dtype=int)
for i in range(n):
    x[i], y[i] = map(int, input().split())
print(solve(n, x, y))
def root(s):
  t=l[s]
  if not t:
    return s
  return root(t)
n,m=map(int,input().split())
ans=n*(n-1)//2
l=[0]*n
a=[1]*n
b=[input().split() for _ in range(m)]
c=[ans]*m
for i in range(m-2,-1,-1):
  x,y=map(int,b[i+1])
  x=root(x-1)
  y=root(y-1)
  if x!=y:
    l[x]=y
    ans-=a[x]*a[y]
    a[y]+=a[x]
  c[i]=ans
for x in c:
  print(x)

### FIXED CODE ###

import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readline
n,m=map(int,input().split())
z=n*(n-1)//2
l=[-1]*n
a=[1]*n
b=[input().split() for _ in range(m)]
c=[0]*m+[z]
def r(s):
  t=l[s]
  if t<0:
    return s
  else:
    l[s]=r(t)
    return l[s]
def f(s):
  return r(int(s)-1)
for i in range(m-1,-1,-1):
  x,y=map(f,b[i])
  if x!=y:
    l[x]=y
    z-=a[x]*a[y]
    a[y]+=a[x]
  c[i]=z
for x in c[1:]:
  print(x)
from collections import deque
from collections import Counter

h,w = map(int,input().split())

c = [None]*h
d = [[-1 for i in range(w)] for j in range(h)]
dx = [1,0,-1,0]
dy = [0,1,0,-1]
kk = 0

for i in range(h):
    c[i] = input()
    
for i in range(h):
    for j in range(w):
        if c[i][j] == "#":
            d[i][j] = 0
    
def bfs(y,x):
    global kk
    d[y][x] = -1
    for k in range(4):
        nx = x + dx[k]
        ny = y + dy[k]
            
        if 0<=nx and nx<w and 0<=ny and ny<h and d[ny][nx] != -1:
            kk += 1
            bfs(ny,nx)
            

resmin  = 100000
an = []
res = 0
for i in range(h):
    for j in range(w):   
        if d[i][j] == 0:
            bfs(i,j)
            res += 1
            an.append(kk+1)
            
b = Counter(an)
if h == 1 and w == 1:
    print("Yes")
else:
    if b[1] != 0:
        print("No")
    else:
        print("Yes")

### FIXED CODE ###

import sys

h,w = map(int,input().split())
c = [None]*h
dx = [1,0,-1,0]
dy = [0,1,0,-1]

for i in range(h):
    c[i] = input()
    
for i in range(h):
    for j in range(w):
        a = 0
        b = 0
        for k in range(4):
            nx = j + dx[k]
            ny = i + dy[k]
            if c[i][j] == '#' and 0<=nx and nx<w and 0<=ny and ny<h:
                b += 1
                if c[ny][nx] == '.':
                    a += 1
                    
        if a == b and b != 0:
            print("No")
            sys.exit()
            
print("Yes")
#自分の回答
import math
def digit(b, n):
    if n < b:
        return n
    else:
        return digit(b, math.floor(n/b)) + n % b

n, s = int(input()), int(input())  

if n == s:
    print(n+1)
    exit()

if n < s:
    print(-1)
    exit()

for i in range(2, int(math.sqrt(n) + 1)):
    if digit(i, n) == s:
        print(i)
        exit()
    else:
        continue

for p in range(1,int(math.sqrt(n) +1)):
    b = (n-s)//p + 1
    if digit(b, n) == s:
        print(b)
        exit()
print(-1)    

### FIXED CODE ###

import math
def digit(b, n):
    if n < b:
        return n
    else:
        return digit(b, math.floor(n/b)) + n % b

n, s = int(input()), int(input())  

if n == s:
    print(n+1)
    exit()

if n < s:
    print(-1)
    exit()

for i in range(2, int(math.sqrt(n)) + 2):
    if digit(i, n) == s:
        print(i)
        exit()

for p in range(1,int(math.sqrt(n)))[::-1]:
    q = s - p
    b = (n-s)//p +1
    if 1 <= p < b and 0 <= q < b and (n - s)%p == 0:
        if digit(b, n) == s:
            print(b)
            exit()
print(-1)
n, m = map(int, input().split())

s = [0] * (n + 1)
s[-1] = 1
for _ in range(m):
    a = int(input())
    s[a] = None

if s[0] is None and s[1] is None:
    print(0)
    exit()

for i in range(n - 1, -1, -1):
    if s[i] is None:
        continue
    if i + 1 < len(s) and s[i + 1] is not None:
        s[i] += s[i + 1]
    if i + 2 < len(s) and s[i + 2] is not None:
        s[i] += s[i + 2]

print(s[0] % 1_000_000_007)


### FIXED CODE ###

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

s = [0] * (n + 1)
s[-1] = 1
for _ in range(m):
    a = int(input())
    s[a] = None

if s[0] is None and s[1] is None:
    print(0)
    exit()

for i in range(n - 1, -1, -1):
    if s[i] is None:
        continue
    if i + 1 < len(s) and s[i + 1] is not None:
        s[i] += s[i + 1]
    if i + 2 < len(s) and s[i + 2] is not None:
        s[i] += s[i + 2]

print(s[0] % 1000000007)
N,W=map(int,input().split())
w=[]
v=[]
for i in range(N):
    a,b=map(int,input().split())
    w.append(a)
    v.append(b)
dp=[[0 for i in range(W+1)] for j in range(N+1)]
for i in range(N):
    for j in range(W+1):
        if j>w[j-1]:
            dp[i][j]=max(dp[i-1][j-w[j-1]]+v[i],dp[i-1][j])
        else:
            dp[i][j]=dp[i-1][j]
print(dp[N][W])
       


### FIXED CODE ###

import numpy as np

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

dp = np.zeros(W+1, dtype=np.int64)

for _ in range(N):
  w,v = map(int,input().split())
  np.maximum(dp[:-w]+v,dp[w:], out=dp[w:])

print(dp[-1])
A,B,X = map(int,input())
if (A <= X <= (A + B)):
    print('YES')
else:
    print('NO')

### FIXED CODE ###

A,B,X = map(int,input().split())
if (A <= X <= (A + B)):
    print('YES')
else:
    print('NO')
W,H,x,y = [int(i) for i in input().split()]
flag=0
if W==x+x and H==y+y:
    flag=1



print(W*H/2,flag)



### FIXED CODE ###



N, M = map(int, input().split())
a=[]
step=[0]*200000
total=1
count=0
num=0

for i in range(M):
    a.append(int(input()))

for x in range(M):
    num=a[x]-a[x-1]
    if(num==1):
        print(0)
        exit(0)
    else:
        num=0

step[0]=1
for k in range(1,N+1):
    if M!=0:
        if k==a[count]:
            step[k]=0
            if count<M-1:
                    count +=1
        else:
            if k>0:
                step[k]+=step[k-1]
            if k>1:
                step[k]+=step[k-2]
    else:
        if k > 0:
            step[k] += step[k - 1]
        if k > 1:
            step[k] += step[k - 2]



print(step[N]%1000000007)
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  	cin>>n;
  cout<<n*n*3<<endl;
}


### FIXED CODE ###

a=int(input())
print(a*a*3)
import math as mt
import numpy as np

string = input()
use = string.split('x')
word =''
for x in use:
    word += x
i = 0
n = len(word) - 1
while i < n:
    if word[i] != word[n]:
        print(-1)
        exit()
    i += 1
    n -= 1
if len(word) % 2 == 0:
    fh = []
    i = 0
    mid = int(len(word)/2)
    count = 0
    n = len(string) - 1
    for x in string:
        if x == word[i]:
            i += 1
            fh.append(count)
            count = 0
            if i == mid:
                break
        else:
            count += 1
    i = len(word) - 1
    lh = []
    count = 0
    while i != mid - 1:
        if string[n] == word[i]:
            i -= 1
            lh.append(count)
            count = 0
        else:
            count += 1
        n -= 1
    print(0)
    # print(np.sum(np.abs(np.array(fh)-np.array(lh))))

else:
    fh = []
    i = 0
    mid = int((len(word) - 1)/2)
    count = 0
    n = len(string) - 1
    for x in string:
        if x == word[i]:
            i += 1
            fh.append(count)
            count = 0
            if i > mid:
                break
        else:
            count += 1
    i = len(word) - 1
    lh = []
    count = 0
    while i != mid - 1:
        if string[n] == word[i]:
            i -= 1
            lh.append(count)
            count = 0
        else:
            count += 1
        n -= 1
    print(0)
    #print(np.sum(np.abs(np.array(fh)-np.array(lh))))


### FIXED CODE ###

import math as mt
import numpy as np

string = input()
collect = []
word = ''
count = 0
n = len(string)
i = 0
for x in string:
    if x != 'x':
        word += x
        collect.append(count)
        if i == n-1:
            collect.append(0)
        count = 0
    elif i == n-1:
        count += 1
        collect.append(count)
    else:
        count += 1
    i += 1

nl = len(word) - 1
i = 0
while i < nl:
    if word[i] != word[nl]:
        print(-1)
        exit()
    i += 1
    nl -=  1
nl = len(collect) - 1
i = 0
out = 0
while i < nl:
    out += np.abs(collect[i] - collect[nl])
    i += 1
    nl -= 1
print(out)
if(A == B):
    print(C)
elif(B == C):
    print(A)
else:
    print(B)


### FIXED CODE ###

A, B, C = map(int, input().split())
if(A == B):
    print(C)
elif(B == C):
    print(A)
else:
    print(B)
# -*- coding: utf-8 -*-
"""
Created on Wed Mar  4 02:26:37 2020

@author: Kanaru Sato
"""

def list_difference(list1, list2):
    result = list1.copy()
    for value in list2:
        if value in result:
            result.remove(value)
    return result

def differ(S):
    S_dash = list(set(S))
    D = list_difference(S, S_dash)
    if len(D) == 0:
        return S
    if len(D) == 1:
        return D
    if len(D) >= 2:
        return differ(D)

N = int(input())
S = []
[S.append(input()) for i in range(0,N)]

ans = differ(S)
ans.sort()

for i in range(0,len(ans)):
    print(ans[i])

### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
Created on Wed Mar  4 16:16:18 2020

@author: Kanaru Sato
"""

N = int(input())
D = {}

for i in range(0,N):
    S = input()
    if S not in D:
        D[S] = 1
    if S in D:
        D[S] += 1

Mvalue = max(D.values())

List = []
[List.append(i) for i in D if D[i]==Mvalue]

List.sort()

for i in range(0,len(List)):
    print(List[i])
n=int(input())
if(n<10):
  x=n
elif(n<100):
  x=9
elif(n<1000):
  x=n-90
elif(n<10000):
  x=
elif(x<100000):
  x=n-90-9000

### FIXED CODE ###

n=int(input())
if(n<10):
  x=n
elif(n<100):
  x=9
elif(n<1000):
  x=n-90
elif(n<10000):
  x=9+900
elif(n<100000):
  x=n-90-9000
elif(n==100000):
  x=90909
print(x)
#!/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, price, left):
        if not left:
            return price
        if i == M:
            return FAIL
        return min(helper(i + 1, price + a[i], left - c[i]),
                   helper(i + 1, price, left))

    print(helper(0, 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()
from __future__ import (absolute_import, division, print_function,
                        unicode_literals)
from sys import stdin

while True:
    n = int(stdin.readline())
    if not n:
        break

    tup = tuple(int(stdin.readline()) for _ in xrange(n))
    L = [tup[0]]
    for i in tup[1:]:
        if 0 > i and 0 > L[-1]:
            L[-1] += i
        elif 0 <= i and 0 <= L[-1]:
            L[-1] += i
        else:
            L.append(i)

    while True:
        length = len(L)
        if L[0] <= 0:
            L.pop(0)
            continue
        if L[-1] <= 0:
            L.pop()
            continue
        if length > 1 and L[0] + L[1] <= 0:
            L.pop(0)
            L.pop(0)
            continue
        if length > 1 and L[-1] + L[-2] <= 0:
            L.pop()
            L.pop()
            continue
        if length > 2 and sum(L[:3]) >= L[2]:
            L[2] = sum(L[:3])
            L.pop(0)
            L.pop(0)
            continue
        if length > 2 and sum(L[-3:]) >= L[-3]:
            L[-3] = sum(L[-3:])
            L.pop(0)
            L.pop(0)
            continue
        break

    m = 0
    for i in xrange(len(L)):
        for j in xrange(1 + i, len(L) + 1):
            t = sum(L[i:j])
            if t > m:
                m = t
    print(m)

### FIXED CODE ###

from __future__ import (division, absolute_import, print_function,
                        unicode_literals)
from sys import stdin
from array import array

def grouping(nums):
    sign = None
    L = array(b'i')
    for s, n in ((i < 0, i) for i in nums):
        if sign is s:
            L[-1] += n
        else:
            sign = s
            L.append(n)

    if len(L) and L[-1] <= 0:
        del L[-1]
    if len(L) and L[0] <= 0:
        del L[0]
    return L

while True:
    n = int(stdin.readline())
    if not n:
        break

    L = array(b'i', (int(stdin.readline()) for _ in xrange(n)))
    val = max(L)
    if val <= 0:
        print(val)
        continue

    ans, temp = 0, 0
    for i in grouping(L):
        temp = max(0, temp+i)
        ans = max(ans, temp)
    print(ans)
n = int(input())
p = list(map(int,input().split()))
count = 0

for i in range(n):
    if p[i] == min(p[0:i]):
        count += 1
        
print(count)

### FIXED CODE ###

n = int(input())
p = list(map(int,input().split()))
count = 1
min_p = p[0]

for i in range(n):
    if min_p > p[i]:
        count += 1
        min_p = p[i]

print(count)
print((int(input())-1)*(int(input())-1))

### FIXED CODE ###

X, t = map(int, input().split())
print((X-1)*(t-1))
h,w,m = map(int,input().split())
hw = [[int(i) for i in input().split()] for j in range(m)]

tate = [0]*(w+1)
yoko = [0]*(h+1)

for i in range(m):
    yoko[hw[i][0]] += 1
    tate[hw[i][1]] += 1
    
ans = 0

t_max = -1


for i in range(1,w+1):
    if t_max < tate[i]:
        t_max = tate[i]
        t_max_idx = []
        t_max_idx.append(i)
    elif t_max == tate[i]:
        t_max_idx.append(i)

y_max = -1

for i in range(1,h+1):
    if y_max < yoko[i]:
        y_max = yoko[i]
        y_max_idx = []
        y_max_idx.append(i)
    elif y_max == yoko[i]:
        y_max_idx.append(i)
        
#s_y = set(y_max_idx)
#s_t = set(t_max_idx)

if len(y_max_idx)*len(t_max_idx) > m:
    print(t_max+y_max)
else:
    ans = 0
    for i in range(m):
        if hw[i][0] in s_y and hw[i][1] in s_t:
            ans += 1
    if ans < len(y_max_idx)*len(t_max_idx):
        print(t_max+y_max)
    else:
        print(t_max+y_max-1)

### FIXED CODE ###

h,w,m = map(int,input().split())
hw = [[int(i) for i in input().split()] for j in range(m)]

tate = [0]*(w+1)
yoko = [0]*(h+1)

for i in range(m):
    yoko[hw[i][0]] += 1
    tate[hw[i][1]] += 1
    
ans = 0

t_max = -1


for i in range(1,w+1):
    if t_max < tate[i]:
        t_max = tate[i]
        t_max_idx = []
        t_max_idx.append(i)
    elif t_max == tate[i]:
        t_max_idx.append(i)

y_max = -1

for i in range(1,h+1):
    if y_max < yoko[i]:
        y_max = yoko[i]
        y_max_idx = []
        y_max_idx.append(i)
    elif y_max == yoko[i]:
        y_max_idx.append(i)
        
s_y = set(y_max_idx)
s_t = set(t_max_idx)

if len(y_max_idx)*len(t_max_idx) > m:
    print(t_max+y_max)
else:
    ans = 0
    for i in range(m):
        if hw[i][0] in s_y and hw[i][1] in s_t:
            ans += 1
    if ans < len(y_max_idx)*len(t_max_idx):
        print(t_max+y_max)
    else:
        print(t_max+y_max-1)
def resolve():
    import numpy as np
    n = int(input())
    A = list(map(int, input().split()))
    C = 1000
    kabu = 0
    buy = []
    sell = []

    # for i in range(n - 1, 0, -1):
    #     if A[i] > A[i - 1]:
    #         sell.append(i)
    #         if i == 1:
    #             buy.append(0)
    #     elif A[i] < A[i - 1] and len(sell) != 0:
    #         buy.append(i)

    flag = 1
    for i in range(1, n):
        if A[i - 1] <= A[i] and flag:
            l = i - 1
            flag = 0
        elif flag == 0:
            k = C // A[l]
            C -= k * A[l]
            kabu += k

            C += kabu * A[i - 1]
            kabu = 0
            flag = 1

        # if i in buy:
        #     k = C // A[i]
        #     C -= k * A[i]
        #     kabu += k
        # elif i in sell:
        #     C += kabu * A[i]
        #     kabu = 0

#    print(l, kabu, C)
    if A[l] < A[-1]:
        k = C // A[l]
        C -= k * A[l]
        kabu += k
        C += kabu * A[-1]
    print(C)

resolve()

### FIXED CODE ###

def resolve():
    n = int(input())
    A = list(map(int, input().split()))
    C = 1000
    kabu = 0

    for i in range(1, n):
        if A[i - 1] <= A[i]:
            kabu = C // A[i - 1]
            C += kabu * (A[i] - A[i - 1])

    print(C)

resolve()
k,x =map(int,input().split()))
if k*500 >= x:
    print("Yes")
else:
    print("No")


### FIXED CODE ###

k,x =map(int,input().split())
if k*500 >= x:
    print("Yes")
else:
    print("No")
A = map(int, input().split())
print(A[2]-(A[1]-A[0]))

### FIXED CODE ###

A,B,C = map(int, input().split())
D=C-(A-B)
if D > 0:
    print(D)
else:
    print(0)
import functools
import operator
S=int(input())
prod = functools.partial(functools.reduce, operator.mul)
def factorize(n):
    b = 2
    fct = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    return fct
print(0,0,prod(factorize(S)[1::2]),0,0,prod(factorize(S)[0::2]))

### FIXED CODE ###

import math
S=int(input())
X1,Y1=0,0
X2=math.ceil(math.sqrt(S))
Y3=X2
Y2=1
X3=X2*Y3-S
print(X1,Y1,X2,Y2,X3,Y3)
from sys import stdin, stdout
from collections import defaultdict
def readLine_int_list():return list(map(int, stdin.readline().split()))
def readLine_int_list_reverse(): return list(map(int, stdin.readline().split())).reverse()
def readAll_int(): return list(map(int, stdin))
def readLine_str_list():return list(map(int, stdin.readline().split()))
def readAll_str(): return list(map(int, stdin))
def g_twoD_list(p,q): return [[0 for i in range(p)] for j in range(q)]


from sys import stdin, stdout
from collections import defaultdict
def readLine_int_list(): return list(map(int, stdin.readline().split()))
def readAll_int(): return list(map(int, stdin))

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

def main():
    n = int(input())
    t = list(set(readAll_int()))
    for i in range(len(t) - 1):
        a = lcm(t[i], t[i+1])
        t[i+1] = a
    print(a)

if __name__ == "__main__":
    main()


### FIXED CODE ###

from sys import stdin, stdout
def readAll_int(): return list(map(int, stdin))

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

def main():
    n = int(input())
    t = list(set(readAll_int()))
    if len(t)>1:
        for i in range(len(t) - 1):
            a = lcm(t[i], t[i+1])
            t[i+1] = a
    else:
        a = t[0]
    print(a)
    
if __name__ == "__main__":
    main()
N,X=map(int,input().split())
L = [int(i) for i in input().split()] 

a=0
for i in range(N+1):
    a+=L[i]
    if a > X:
        ans=i+1
        break

print(ans)
        

### FIXED CODE ###

N,X=map(int,input().split())
L = [int(i) for i in input().split()] 
ans=N+1
a=0
for i in range(N):
    a+=L[i]
    if a > X:
        ans=i+1
        break

print(ans)
n=int(input())
a1=map(int,input().split()).split()
a2=map(int,input().split()).split()

i=1
ans=0
while i<n+1:
    ans=max(sun(a1[0:i]+a2[i-1:n]),ans)
    i=i+1
else: 
    print(ans)

### FIXED CODE ###

n=int(input())
a1=list(map(int,input().split()))
a2=list(map(int,input().split()))
i=1
ans=0
while i<n+1:
    ans=max(sum(a1[0:i])+sum(a2[i-1:n]),ans)
    i=i+1
else:
    print(ans)
dev solve():
  n, y = map(int, input().split())
  y //= 1000
  
  for nogu in range(n + 1):
    for higu in range(n + 1 - nogu):
      yuki = n - nogu - higu
      if nogu + higu * 5 + yuki * 10 == y:
        print(yuki, higu, nogu)
        return
  print("-1 -1 -1")
  
if __name__=='__main__':
  solve()

### FIXED CODE ###

def solve():
    N, Y = map(int, input().split())

    for x in range(N + 1):
        for y in range(N + 1 - x):
            z = N - x - y
            if 10000 * x + 5000 * y + 1000 * z == Y:
                return " ".join([str(x), str(y), str(z)])

    return "-1 -1 -1"

if __name__=='__main__':
  print(solve())
n,m=map(int,input().split())
f=lambda x:int(x)-1

langs=[[] for _ in range(m)]
speakers=[[] for _ in range(n)]
used_langs=[False]*m
used_speakers=[False]*n

for i in range(n):
  *l,=map(f,input().split()[1:])
  speakers[i].extend(l)
  for j in l:
    langs[j].append(i)

def dfs(n):
  if used_speakers[n]:
    return
  used_speakers[n]=True
  for i in speakers[n]:
    if used_langs[i]:continue
    used_langs[i]=True
    for j in langs[i]:
      dfs(j)

dfs(0)
if not False in used_speakers:
  print("YES")
else:
  print("NO")

### FIXED CODE ###

import sys
sys.setrecursionlimit(100000)

n,m=map(int,input().split())
f=lambda x:int(x)-1

langs=[[] for _ in range(m)]
speakers=[[] for _ in range(n)]
used_langs=[False]*m
used_speakers=[False]*n

for i in range(n):
  *l,=map(f,input().split()[1:])
  speakers[i].extend(l)
  for j in l:
    langs[j].append(i)

def dfs(n):
  if used_speakers[n]:
    return
  used_speakers[n]=True
  for i in speakers[n]:
    if used_langs[i]:continue
    used_langs[i]=True
    for j in langs[i]:
      dfs(j)

dfs(0)
if not False in used_speakers:
  print("YES")
else:
  print("NO")
def f(x):
    p=0
    cnt=0
    for i in range(n-1,-1,-1):
        while a[i]+a[p]<x:
            p+=1
            if p==n: return cnt
        cnt+=n-p
    return cnt

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

l,r=a[0]*2,a[n-1]*2

while r-l>0:
    if r-l<=1: md=l;break
    md=(r+l)//2
    k=f(md)
    if k==m: break
    elif k>m: l=md
    else: r=md

p=0
cnt=0
ans=0
for i in range(n-1,-1,-1):
    while p<n and a[i]+a[p]<=md:
        p+=1
    cnt+=n-p
    ans+=a[i]*(n-p)*2


ans+=(m-cnt)*md
print(ans)

### FIXED CODE ###

import sys

def f(x):
    p=0
    cnt=0
    for i in range(n-1,-1,-1):
        while p<n and a[i]+a[p]<x:
            p+=1
        cnt+=n-p
    return cnt

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

l,r=a[0]*2,a[n-1]*2
md=(r+l)//2
while r-l>0:
    if r-l<=1:
        if f(r)==m: md=r;break 
        else: md=l;break
    md=(r+l)//2
    k=f(md)
    if k==m: break
    elif k>m: l=md
    else: r=md

p=0
cnt=0
ans=0

for q in range(n-1,-1,-1):
    try:
        while p<n and a[q]+a[p]<=md:
            p+=1
    except:
        b=1
        while True:
            b+=1

    if p==n: break
    cnt+=n-p
    ans+=a[q]*(n-p)*2


ans+=(m-cnt)*md
print(ans)
n=input()
a=map(int,raw_input().split())
a=reverse

for i in n:
	print a

### FIXED CODE ###

n=input()
a=map(int,raw_input().split())
a.reverse()

for i in a:
    print i,