Harryxun/stf_run huggingface dataset:
n = int(raw_input())

d = [0 for i in range(n)]
f = [0 for i in range(n)]
a = [[0 for i in range(n)] for j in range(n)]
st = [0 for i in range(n)]
time = [0]
G = [0 for i in range(n)]

def dfs_visit(s):
    st[s] = 1
    time[0] += 1
    d[s] = time[0]
    
    for k in range(n):  
      if a[s][k] == 1 and st[k] == 0:
          dfs_visit(k)
    time[0] += 1
    f[s] = time[0]

def main():
    for s in range(n):
        if st[s] == 0:
            def_visit(s)
    for s in range(n):
        print(s+1,d[s],f[s]) 

for i in range(n):
  G = map(int, raw_input().split())
  for j in range(G[1]):
    v[G[0]-1][G[2+j]-1] = 1
   
main()


       

### FIXED CODE ###

n = int(raw_input())

d = [0 for i in range(n)]
f = [0 for i in range(n)]
a = [[0 for i in range(n)] for j in range(n)]
st = [0 for i in range(n)]
time = [0]
G = [0 for i in range(n)]


def dfs_visit(s):
    st[s] = 1
    time[0] += 1
    d[s] = time[0]
    
    for k in range(n):  
      if a[s][k] == 1 and st[k] == 0:
          dfs_visit(k)
    st[s] ==2
    time[0] += 1
    f[s] = time[0]

def main():
    for s in range(n):
        if st[s] == 0:
            dfs_visit(s)
    for s in range(n):
        print'{0} {1} {2}'.format(s+1, d[s], f[s])

for i in range(n):
    G = map(int, raw_input().split())
    for j in range(G[1]):
        a[G[0]-1][G[2+j]-1] = 1

main()
N = int(input())
S = list(map(int, input().split())

Max_S = max(S)
Max_idx = S.index(Max_S)
Min_S = min(S)
Min_idx = S.index(Max_S)
Sort_S = sorted(S)

S[Max_idx], S[Min_idx] = S[Min_idx], S[Max_idx]
if S == Sort_S:
    print('YES')
else:
    print('NO')


### FIXED CODE ###

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

cnt = 0
for i in range(N):
    if i + 1 == p[i]:
        cnt += 1

if cnt >= N - 2:
    print("YES")
else:
    print("NO")
N = int(input())
maxs = 0    
s = []
for i in range(N):
    cin = int(input())
    s.append(cin)
    maxs = max(maxs, cin)
M = maxs * N + 1

dp = [False * M]
dp[0] = True

for x in s:
    for i in range(M):
        if i < x: continue
        if dp[i-x]: dp[i] = True

for i in range(M):
    if (M-i)%10 != 0 and dp[M-i]:
        print(M-i)
else:
    print(0) 

### FIXED CODE ###

N = int(input())
maxs = 0    
s = []
for i in range(N):
    cin = int(input())
    s.append(cin)
    maxs = max(maxs, cin)
M = maxs * N

dp = [False] * (M+1)
dp[0] = True

for x in s:
    for i in range(M+1):
        if M-i < x: continue
        if dp[M-i-x]: dp[M-i] = True

for i in range(M+1):
    if (M-i)%10 != 0 and dp[M-i]:
        print(M-i)
        break
else:
    print(0)
N = int(input())

# O(num^(1/2))
def is_prime_num(num):
    num_sqrted = floor(sqrt(num))
    for i in range(2, num_sqrted + 1):
        if num % i == 0:
            return False
    else:
        return True

a_set = set()
while len(a_set) < N:
    for i in range(11, 55555, 10):
        if i in a_set:
            continue
        elif not is_prime_num(i):
            continue
        else:
            a_set.add(i)
            break

print(' '.join(map(str, a_set)))

### FIXED CODE ###

from math import sqrt, floor, ceil
from itertools import combinations


N = int(input())

# O(num^(1/2))
def is_prime_num(num):
    num_sqrted = floor(sqrt(num))
    for i in range(2, num_sqrted + 1):
        if num % i == 0:
            return False
    else:
        return True

a_set = set()
while len(a_set) < N:
    for i in range(11, 55555, 10):
        if i in a_set:
            continue
        elif not is_prime_num(i):
            continue
        else:
            a_set.add(i)
            break

print(' '.join(map(str, a_set)))
x = input()
y = input()
sum = x*y
around = 2*x+2*y
input int(sum,around)


### FIXED CODE ###

a,b=[int(x) for x in input().split()]
print(a*b,(a+b)*2)
def main():
    n, m = map(int, input().split())
    a_list = list(map(int, input().split()))
    sorted_a_list = sorted(a_list, reverse=True)

    for _ in range(m):
        sorted_a_list[0] = int(sorted_a_list[0]/2)
        if sorted_a_list[0] < sorted_a_list[1]:
            sorted_a_list = sorted(sorted_a_list, reverse=True)

    print(sum(sorted_a_list))


if __name__ == '__main__':
    main()


### FIXED CODE ###

import heapq


def main():
    n, m = map(int, input().split())
    a_list = list(map(lambda x: -int(x), input().split()))

    heapq.heapify(a_list)
    for _ in range(m):
        a = heapq.heappop(a_list)
        heapq.heappush(a_list, -(-a // 2))

    print(-sum(a_list))


if __name__ == '__main__':
    main()
import math
import copy
from copy import deepcopy
import sys
import fractions
import numpy as np
from functools import reduce
import statistics
import heapq


# input = sys.stdin.readline
# sys.setrecursionlimit(10**6)

# ===FUNCTION===

def getInputInt():
    inputNum = int(input())
    return inputNum


def getInputListInt():
    outputData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===

data = getInputListInt()
N = data[0]
K = data[1]
MOD = 1000000000 + 7

# nCa
def choose(n, a):
    if n == 0 or a == 0: return 1
    x = 1
    y = 1
    for i in range(a):
        x *= n-i
        y *= i+1
    return int(x / y)

for i in range(1, K+1, 1):
    blue = choose(K-1, i-1)
    red = choose(N-K-(i-1) +i, i)

    ans = (blue * red) % MOD
    print(int(ans))


### FIXED CODE ###

import sys

# import re
import math
import collections
# import decimal
# import bisect
# import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    def fast_pow(num, kata, mod):
        if kata == 0:
            return 0

        res = 1
        while kata > 0:
            if kata & 1 == 1:
                res = res * num % mod
            num = num * num % mod

            kata >>= 1
        return res

    # MODのCombination nがでかくても関係なくrに依存　r<10**6なら回せる
    MOD = 10 ** 9 + 7

    def choose(n, r):
        res = 1
        fac = 1
        for i in range(r):
            res *= n - i
            res %= MOD
            fac *= i + 1
            fac %= MOD
        return res * fast_pow(fac, MOD - 2, MOD) % MOD

    n, k = ns()

    for i in range(1, k + 1):
        blue_pair = choose(k - i + (i - 1), i - 1)
        red_pair = choose((n - k) + 1, i)
        print(blue_pair * red_pair % MOD)


if __name__ == '__main__':
    main()
T = list(str(input()))

for i in range(len(T)):
    if T[i] == '?':
        if T[i - 1] == 'P':
            T[i] = 'D'
        elif T[i + 1] == "?":
            T[i] = 'P'
            T[i + 1] = 'D'
            i= i+1
        else:
            T[i] = 'D'
        

TL=''.join(T)
print(TL)


### FIXED CODE ###

T = list(str(input()))

for i in range(len(T)):
    if T[i] == '?':
        T[i] = 'D'
    print(T[i],end='')
s = input()
 
ss = ""
for i in s:
  if s[i] == "1":
  	ss += "9"	
  else:
    ss += "1"
    
print(ss)


### FIXED CODE ###

s = input()
 
ss = ""
for i in s:
  if i == "1":
  	ss += "9"	
  else:
    ss += "1"
    
print(ss)
n = int(input())
h = list(map(int, input().split()))
for i in range(n-1):
    if h[i+1] == h[i] - 1:
        h[i] = h[i] - 1
flag = True
for i in range(n):
    if h[i+1] < h[i]:
        flag = False
        break
if flag == True:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

n = int(input())
h = list(map(int, input().split()))
for i in reversed(range(n-1)):
    if h[i+1] == h[i] - 1:
        h[i] = h[i] - 1
flag = True
for i in range(n-1):
    if h[i+1] < h[i]:
        flag = False
        break
if flag == True:
    print('Yes')
else:
    print('No')
import sys
sys.setrecursionlimit(65536)

N=int(input())
d=[-1 for _ in range(N+1)]
e=[[] for _ in range(N+1)]
for _ in range(N-1):
	a,b,c=map(int,input().split())
	e[a].append([b, c])
	e[b].append([a, c])
Q,K=map(int,input().split())
def bfs(now, dis):
	if d[now] != -1:
		return
	d[now] = dis
	for nxt, cos in e[now]:
		bfs(nxt, dis+cos)
bfs(K, 0)
for _ in range(Q):
	x,y=map(int,input().split())
	print(d[x]+d[y])


### FIXED CODE ###

import sys
sys.setrecursionlimit(1145141919)
N=int(input())
d=[-1 for _ in range(N+1)]
e=[[] for _ in range(N+1)]
for _ in range(N-1):
	a,b,c=map(int,input().split())
	e[a].append((b, c))
	e[b].append((a, c))
Q,K=map(int,input().split())
def dfs(now, dis):
	d[now] = dis
	for nxt,cos in e[now]:
		if d[nxt] == -1:
			dfs(nxt, dis+cos)
dfs(K, 0)
for _ in range(Q):
	x,y=map(int,input().split())
	print(d[x]+d[y])
from math import *
from fractions import *
a,b,c,d=map(int,input().split())
lcm=lambda x,y: x*y//gcd(x,y)

def f(a,b,c):
    return (b - a + 1) // c + (1 if b % c <= a % c else 0)

if c != 1 and d != 1:
    if c != d:
        print (b-a+1) - f(a,b,c) - f(a,b,d) + f(a,b,lcm(c,d))
    else:
        print (b - a + 1) - f(a, b, c)
else:
    print 0

### FIXED CODE ###

from math import *
from fractions import *
a,b,c,d=map(int,input().split())

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

def f(a,b,c):
    return (b - a + 1) // c + (1 if b % c <= a % c else 0)

if c != 1 and d != 1:
    print ((b-a+1) - (b // c - ceil(a / c) + 1) - (b // d - ceil(a / d) + 1) + (b // lcm(c, d) - ceil(a / lcm(c, d)) + 1))
else:
    print (0)
A=int(input())
B=int(input())
ans={1,2,3}-{A,B}
assert len(ans)==1
print(int(ans[0]))


### FIXED CODE ###

A=int(input())
B=int(input())
ans={1,2,3}-{A,B}
print(ans.pop())
N=int(input())
D=list(map(int,input().split()))
DS=sorted(D)
ans=DS[N//2]-DS[D//2-1]
print(ans)

### FIXED CODE ###

N=int(input())
D=list(map(int,input().split()))
D=sorted(D)
ans=D[N//2]-D[N//2-1]
print(ans)
import sys
sys.setrecursionlimit(1000000)
from collections import deque

def bfs(sx,sy,gx,gy):
    d = [[float("inf")] * w for i in range(h)]
    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]

    que = deque([])
    que.append((sx, sy))
    d[sx][sy] = 0

    while que:
        p = que.popleft()
        if p[0] == gx and p[1] == gy:
            break
        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]
            if 0 <= nx < h and 0 <= ny < w and s[nx][ny] != "#" and d[nx][ny] == float("inf"):
                que.append((nx, ny))
                d[nx][ny] = d[p[0]][p[1]] + 1

    return d[gx][gy]

h,w=map(int,input().split())
s = [list(input()) for i in range(h)]
ans=0
def check(i,j):
    if 1<=j<=w-2:
        if s[0][j-1]=='#' or s[0][j+1]=='#' or s[1][j]=='#':
            return True
    elif 1<=j<=w-2:
        if s[h][j-1]=='#' or s[h][j+1]=='#' or s[h-1][j]=='#':
            return True
    elif 1<=i<=h-2:
        if s[i-1][0]=='#' or s[i+1][0]=='#' or s[i][1]=='#':
            return True
    elif 1<=i<=h-2:
        if s[i-1][w]=='#' or s[i+1][w]=='#' or s[i][w-1]=='#':
            return True
    elif i==0 and j==0:
        return True
    elif i==0 and j==w-1:
        return True
    elif i==h-1 and j==0:
        return True
    elif i==h-1 and j==w-1:
        return True
    else:
        return False
for i in range(h):
    for j in range(w):
        if s[i][j]=='.' and check(i,j):
            if j != w:
                for m in range(j+1,w):
                    if s[i][m]=='.' and check(i,m):
                        ans = max(ans,bfs(i,j,i,m))
            for k in range(i+1,h):
                for l in range(w):
                    if s[k][l]=='.' and check(k,l):
                        ans = max(ans,bfs(i,j,k,l))
print(ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000)
from collections import deque


h,w=map(int,input().split())
s = [list(input()) for i in range(h)]

def bfs(sx,sy):
    dx = [0,1,0,-1]
    dy = [1,0,-1,0]
    d = [[-1]*w for i in range(h)]
    q = deque()
    q.append((sx,sy))
    d[sx][sy] = 0
    while q:
        x,y = q.popleft()
        for i in range(4):
            nx = x + dx[i]
            ny = y + dy[i]
            if  0<= nx < h and 0 <= ny < w and d[nx][ny]==-1 and s[nx][ny]=='.':
                q.append((nx,ny))
                d[nx][ny] = d[x][y]+1
    return max([max(i) for i in d])

count = 0
for i in range(h):
    for j in range(w):
        if s[i][j] != '#':
            count  = max(count, bfs(i,j))
print(count)
K = int(input())
remainder_set = set()
sequence = 7
i = 1
for i in range(10**7 + 9):
    if sequence%K == 0:
        print(i+1)
        break
    else:
        if sequence%K in emainder_set:
            print(-1)
            break
        else:
            i += 1
            sequence *= 10
            sequence += 7

### FIXED CODE ###

K = int(input())
remainder_set = set()
sequence = 7
i = 1
for i in range(K):
    remainder = sequence%K
    #print(sequence,remainder)
    if remainder == 0:
        print(i+1)
        break
    else:
        if remainder in remainder_set:
            print(-1)
            break
        else:
            i += 1
            remainder_set.add(remainder)
            sequence = remainder*10 + 7
n,m=map(int,input().split())
a=[0]*n
b=[0]*n
c=[0]*n
for i in range(m):
  a[i],b[i],c[i]=map(int,input().split())
  a[i]-=1
  b[i]-=1
INF=float('inf')
dist=[ [INF]*n for _ in range(n)]
for i in range(n):
  dist[i][i]=0
for i in range(m):
  dist[a[i]][b[i]]=c[i]
  dist[b[i]][a[i]]=c[i]
#floyd warshall
for k in range(n):
  for i in range(n):
    for j in range(n):
      dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j])
ans=m
for i in range(m):
  shortest=False
  for j in range(n):
    if dist[j][a[i]]+c[i]==dist[j][b[i]]:
      shortest=True
      break
  if shortest:
    ans-=1
print(ans)





### FIXED CODE ###

import sys
input=sys.stdin.readline
n,m=map(int,input().split())
a=[0]*m
b=[0]*m
c=[0]*m
for i in range(m):
  a[i],b[i],c[i]=map(int,input().split())
  a[i]-=1
  b[i]-=1
INF=10**18#float('inf')
dist=[ [INF]*n for _ in range(n)]
for i in range(n):
  dist[i][i]=0
for i in range(m):
  dist[a[i]][b[i]]=c[i]
  dist[b[i]][a[i]]=c[i]
#floyd warshall
for k in range(n):
  for i in range(n):
    for j in range(n):
      dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j])
ans=m
for i in range(m):
  shortest=False
  for j in range(n):
    if dist[j][a[i]]+c[i]==dist[j][b[i]]:
      shortest=True
      break
  if shortest:
    ans-=1
print(ans)
N = int(input())
numbers = [int(n) for n in input().split(' ')]
distances = []
counter = 0
for i in range(0, len(numbers)):
    if i == 0:
        continue
    if numbers[i - 1] >= numbers[i]:
        counter += 1
    else:
        distances.append(counter)
        counter = 0

print(max(distances))

### FIXED CODE ###

N = int(input())
numbers = [int(n) for n in input().split(' ')]
distances = []
if N == 1:
    print(0)
else:
    counter = 0
    for i in range(0, len(numbers)):
        if i == len(numbers) - 1:
            distances.append(counter)
            break
        if numbers[i] >= numbers[i + 1]:
            counter += 1
        else:
            distances.append(counter)
            counter = 0

    print(max(distances))
s=input()
l=list()
for i in str(s):
  if i == "B":
    del l[-1]
  else:
    l.append(i)
a="".join(l)
print(a)

### FIXED CODE ###

s=input()
l=list()
for i in str(s):
  if i == "B":
    if len(l) > 0:
      del l[-1]
    else:
      continue
  else:
    l.append(i)
a="".join(l)
print(a)
#"""
import sys
input = sys.stdin.readline
#"""
def main()
    N=int(input())
    A = [list(map(int,input().split())) for _ in [0]*N]

    V = {(i,j):0 for i in range(N) for j in range(i+1,N)}
    Ef = {(i,j):[] for i in range(N) for j in range(i+1,N)}
    for i,B in enumerate(A):
        a0 = B[0]-1
        k1 = (i,a0) if i<a0 else (a0,i)
        for a1 in B[1:]:
            a1 -= 1
            k0 = k1
            k1 = (i,a1) if i<a1 else (a1,i)
            Ef[k0].append(k1)
            V[k1] += 1

    q = [k for k in V if V[k] == 0]
    ans = 0
    rmv = 0
    while q:
        qq = []
        for k in q:
            for k2 in Ef[k]:
                V[k2] -= 1
                rmv += 1
                if V[k2] == 0 : qq.append(k2)
        ans += 1
        q = qq
    if rmv != N*(N-2) : ans = -1
    print(ans)
main()

### FIXED CODE ###

#"""
import sys
input = sys.stdin.readline
#"""
def main():
    def get_key(i,j):
        if i<j: i,j = j,i
        return i*N+j
    N=int(input())
    A = [list(map(int,input().split())) for _ in [0]*N]
    V = [-1]*(N*N)
    for i in range(N):
        for j in range(i+1,N):
            V[get_key(i,j)] = 0
    Ef = [[] for _ in V]

    for i,B in enumerate(A):
        a0 = B[0]-1
        k1 = (i,a0)
        for a1 in B[1:]:
            a1 -= 1
            k0 = k1
            k1 = (i,a1)
            Ef[get_key(*k0)].append(get_key(*k1))
            V[get_key(*k1)] += 1

    q = [i for i,v in enumerate(V) if v == 0]
    ans = 0
    rmv = 0
    while q:
        qq = []
        for i in q:
            for j in Ef[i]:
                V[j] -= 1
                rmv += 1
                if V[j] == 0 : qq.append(j)
        ans += 1
        q = qq
    if rmv != N*(N-2) : ans = -1
    print(ans)
main()
n,k=map(int,input().split())
c=list(map(int,input().split()))
ans=10**100
for i in range(n-k+1):
  lit=c[i:i+k]
  if lit[0]*lit[-1]>0:
    d=abs(lit[0])+abs(lit[-1])+min(abs(lit[0]),abs(lit[-1]))
  else:
    d=max(abs(lit[0],abs(lit[-1])))
  if d<ans:
    ans=d
print(ans)


### FIXED CODE ###

n,k=map(int,input().split())
c=list(map(int,input().split()))
ans=10**100
for i in range(n-k+1):
  l,r=i,i+k-1
  d=min(abs(c[l]),abs(c[r]))+abs(c[l]-c[r])
  if d<ans:
    ans=d
print(ans)
N = int(input())
S = list(map(int,input().split()))
S.sorted()
a = N//2
su = 0
um = 0
for i in range(N):
  if i<a:
    su +=S[i]
  else:
    um +=S[i]
print(abs(su-um))

### FIXED CODE ###

N = int(input())
S = list(map(int,input().split()))
su = [0]*(N+1)
um = [0]*(N+1)
ans = 10000000
for i in range(N):
    su[i+1] = su[i]+S[i]
    um[i+1] = um[i]+S[N-1-i]

for i in range(N+1):
  ans = min(abs(su[N-i]-um[i]),ans)
print(ans)
x,n = map(int,input().split())
if n==0: exit(print(x))
p = list(map(int,input().split()))
p.sort()
if x not in p: exit(print(x))
for i in range(x,101):
    if i not in p:
        h = i
        break
for i in range(x,0,-1):
    if i not in p:
        l = i
        break
if abs(x-h)>=abs(x-l): print(l)
if abs(x-l)>abs(x-h): print(h)


### FIXED CODE ###

x,n = map(int,input().split())
if n==0: exit(print(x))
p = list(map(int,input().split()))
p.sort()
if x not in p: exit(print(x))
h=101
l=0
for i in range(x,101):
    if i not in p:
        h = i
        break
for i in range(x,0,-1):
    if i not in p:
        l = i
        break
if abs(x-h)>=abs(x-l): print(l)
if abs(x-l)>abs(x-h): print(h)
S=input()
K=int(input())

for i in range(K):
    if s[i]!='1':
        print(int(s[i]))
        break
else:
    print(1)

### FIXED CODE ###

S=input()
K=int(input())

for i in range(K):
    if S[i]!='1':
        print(int(S[i]))
        break
else:
    print(1)
n = int(input())
s = []
for i in range(n):
    s += [input()]
c0 = s.count("AC")
c1 = s.count("WA")
c2 = s.count("TLE")
c3 = s.count("RE")
print("AC × " + str(c0))
print("WA × " + str(c1))
print("TLE × " + str(c2))
print("RE × " + str(c3))6


### FIXED CODE ###

n = int(input())
s = []
for i in range(n):
    s += [input()]
c0 = s.count("AC")
c1 = s.count("WA")
c2 = s.count("TLE")
c3 = s.count("RE")
print("AC x " + str(c0))
print("WA x " + str(c1))
print("TLE x " + str(c2))
print("RE x " + str(c3))
# -*- coding: utf-8 -*-

import math


def lcm(x, y):
    return (x * y) // math.gcd(x, y)


def divisors(num):
    if num < 1:
        return []
    elif num == 1:
        return [1]
    else:
        divisor_list = []
        divisor_list.append(1)
        for i in range(2, num // 2 + 1):
            if num % i == 0:
                divisor_list.append(i)
        divisor_list.append(num)

        return divisor_list


if __name__ == '__main__':
    N, M = map(int, input().split(' '))
    S = input()
    T = input()

    L = lcm(N, M)

    m = max(N, M)
    m_divisors = divisors(m)
    m_divisors.remove(1)

    S = S * int(math.ceil(m / N))
    T = T * int(math.ceil(m / M))

    for i in [d - 1 for d in m_divisors]:
        if S[i] == T[i]:
            print(-1)
            exit(0)
    print(L)


### FIXED CODE ###

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

import math
import fractions


def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


if __name__ == '__main__':
    N, M = map(int, input().split(' '))
    S = input()
    T = input()

    L = lcm(N, M)

    S_index_X = [int(i * L / N) for i in range(N)]
    T_index_X = [int(i * L / M) for i in range(M)]

    common_index = set(S_index_X).intersection(set(T_index_X))
    for i in common_index:
        si = int(i * N / L)
        ti = int(i * M / L)
        if S[si] != T[ti]:
            print(-1)
            exit(0)
    print(L)
n,m= input().split()
list = list(map(int,input().split()))
sum = 0

for i in list:
    sum += i

if sum>n:
    print("-1")
else:
    print(n-sum)

### FIXED CODE ###

n,m= map(int,input().split())
list = list(map(int,input().split()))
sum = 0

for i in list:
    sum += i

if sum>n:
    print("-1")
else:
    print(n-sum)
H =input()
A =input()
h = int(H)
a = int(A)
if h % a == 0:
    n = h // a
else:
    n = h // a +1
print(n)

### FIXED CODE ###

H,A =input().split()
h = int(H)
a = int(A)
if h % a == 0:
    n = h // a
else:
    n = h // a +1
print(n)
h, w = map(int, input().split())
sL = [input() for i in range(h)]

ans = "Yes"

for y in range(h):
    for x in range(w):
        if sL[y][x] == ".":
            continue
        for dx, dy in dxy:
            if y-1 < 0 or y+1 > h-1 or x-1 < 0 or x+1 > w-1:
                continue
            if sL[y+1][x] == sL[y-1][x]  == sL[y][x+1] == sL[y][x-1] == ".":
                ans = "No"
                break

print(ans)

### FIXED CODE ###

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

ans = "Yes"

for y in range(h):
    for x in range(w):
        if sL[y][x] == ".":
            continue
        if y-1 < 0 or y+1 > h-1 or x-1 < 0 or x+1 > w-1:
            continue
        if sL[y+1][x] == sL[y-1][x]  == sL[y][x+1] == sL[y][x-1] == ".":
            ans = "No"
            break

print(ans)