Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import numpy as np

N=int(input())
dp=[0]*(N+1)


for i in range(N):
    a,b,c = map(int,input().split())
    if i == 0:
        dp[i+1] = dp[i]+max(a,b,c)
        flg = [a,b,c].index(max([a,b,c]))
    else:
        if flg==0:
            dp[i+1] = dp[i] + max(b,c)
            flg = [a,b,c].index(max([b,c]))
        elif flg==1:
            dp[i+1] = dp[i] + max(a,c)
            flg = [a,b,c].index(max([a,c]))
        else:
            dp[i+1] = dp[i] + max(a,b)
            flg = [a,b,c].index(max([a,b]))

# print(dp)
print(dp[N])


Fixed submission:
N=int(input())
dp=[]
for j in range(N+1):
    dp.append([0,0,0])

for i in range(N):
    a,b,c = map(int,input().split())
    if i == 0:
        dp[i+1][0] = dp[i][0]+a
        dp[i+1][1] = dp[i][1]+b
        dp[i+1][2] = dp[i][2]+c
    else:
        dp[i+1][0] = max(dp[i][1]+a, dp[i][2]+a)
        dp[i+1][1] = max(dp[i][0]+b, dp[i][2]+b)
        dp[i+1][2] = max(dp[i][0]+c, dp[i][1]+c)

# print(dp,sep="\n")
print(max(dp[N][0],dp[N][1],dp[N][2]))
Buggy python submission (verdict: Time Limit Exceeded):
N,W=map(int,input().split())

# dp用配列
dp=[]
for k in range(N+1):
    dp.append([0]*(W+1))


for i in range(N):
    w_i,v_i = map(int,input().split())
    for w in range(W+1):
        if w>=w_i:
            dp[i+1][w] = max(dp[i][w-w_i] + v_i , dp[i][w])
        else:
            dp[i+1][w] =dp[i][w]

# print(*dp,sep="\n")

print(dp[N][W])
        


Fixed submission:
N,W=map(int,input().split())

# dp用配列
dp=[]
for k in range(N+1):
    dp.append([0]*(W+1))


for i in range(N):
    w_i,v_i = map(int,input().split())
    for w in range(W+1):
        if w>=w_i:
            dp[i+1][w] = max(dp[i][w-w_i] + v_i , dp[i][w])
        else:
            dp[i+1][w] =dp[i][w]

# print(*dp,sep="\n")

print(dp[N][W])
Buggy python submission (verdict: Time Limit Exceeded):
S=input()
T=input()

s=len(S)
t=len(T)
#DPテーブル作成
dp=[['']*(t+1) for _ in range(s+1)]

for i in range(s):
    for j in range(t):
        if S[i] ==T[j]:
            dp[i+1][j+1] =dp[i][j] + S[i]
        else:
            dp[i+1][j+1] =  max([ dp[i+1][j] , dp[i][j+1] ],key=len)
# print(*dp,sep="\n")

res = ''
while s != 0 and t != 0:
    if dp[s][t] == dp[s-1][t]:
        s -= 1
    elif dp[s][t] == dp[s][t-1]:
        t -= 1
    else:
        s -= 1
        t -= 1
        res = S[s] + res

# print(dp[s][t])
print(res)

Fixed submission:
S=input()
T=input()

s,t=len(S),len(T)
#DPテーブル作成
dp=[[0]*(t+1) for _ in range(s+1)]

for i in range(s):
    for j in range(t):
        if S[i] ==T[j]:
            dp[i+1][j+1] =dp[i][j] + 1
        else:
            dp[i+1][j+1] =  max([ dp[i+1][j] , dp[i][j+1] ])
# print(*dp,sep="\n")

res = ''
while s != 0 and t != 0:
    if dp[s][t] == dp[s-1][t]:
        s -= 1
    elif dp[s][t] == dp[s][t-1]:
        t -= 1
    else:
        s -= 1
        t -= 1
        res = S[s] + res

# print(dp[s][t])
print(res)

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
T=input()

s=len(S)
t=len(T)
#DPテーブル作成
dp=[['']*(t+1) for _ in range(s+1)]

for i in range(s):
    for j in range(t):
        if S[i] ==T[j]:
            dp[i+1][j+1] =dp[i][j] + S[i]
        else:
            dp[i+1][j+1] =  max([ dp[i+1][j] , dp[i][j+1] ],key=len)
print(dp[s][t])

Fixed submission:
S=input()
T=input()

s,t=len(S),len(T)
#DPテーブル作成
dp=[[0]*(t+1) for _ in range(s+1)]

for i in range(s):
    for j in range(t):
        if S[i] ==T[j]:
            dp[i+1][j+1] =dp[i][j] + 1
        else:
            dp[i+1][j+1] =  max([ dp[i+1][j] , dp[i][j+1] ])
# print(*dp,sep="\n")

res = ''
while s != 0 and t != 0:
    if dp[s][t] == dp[s-1][t]:
        s -= 1
    elif dp[s][t] == dp[s][t-1]:
        t -= 1
    else:
        s -= 1
        t -= 1
        res = S[s] + res

# print(dp[s][t])
print(res)

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
T=input()

s=len(S)
t=len(T)
#DPテーブル作成
dp=[['']*(t+1) for _ in range(s+1)]

for i in range(s):
    for j in range(t):
        if S[i] ==T[j]:
            dp[i+1][j+1] =dp[i][j] + S[i]
        else:
            dp[i+1][j+1] =  max([ dp[i+1][j] , dp[i][j+1] ],key=len)
# print(*dp,sep="\n")

print(dp[s][t])

Fixed submission:
S=input()
T=input()

s,t=len(S),len(T)
#DPテーブル作成
dp=[[0]*(t+1) for _ in range(s+1)]

for i in range(s):
    for j in range(t):
        if S[i] ==T[j]:
            dp[i+1][j+1] =dp[i][j] + 1
        else:
            dp[i+1][j+1] =  max([ dp[i+1][j] , dp[i][j+1] ])
# print(*dp,sep="\n")

res = ''
while s != 0 and t != 0:
    if dp[s][t] == dp[s-1][t]:
        s -= 1
    elif dp[s][t] == dp[s][t-1]:
        t -= 1
    else:
        s -= 1
        t -= 1
        res = S[s] + res

# print(dp[s][t])
print(res)
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
s=input()
t=input()

from math import gcd

lcm=n*m//gcd(n,m)

if s[0]!=t[0]:
    print(-1)
    exit(0)

ans=lcm
# sについて
dn={}
for i in range(n):
    if i==0:
        dn[1]=s[i]
    else:
        dn[i*int((lcm)/n) +1]=s[i]

for j in range(m):
    if j==0:
        continue
    else:
        k = j*int(lcm/m) + 1

        if k in dn:
            if dn[k]!=t[j]:
                ans=-1
        else:
            dn[k]=t[j]

print(ans)





Fixed submission:
n,m=map(int,input().split())
s=input()
t=input()

from fractions import gcd

lcm=n*m//gcd(n,m)

if s[0]!=t[0]:
    print(-1)
    exit(0)

ans=lcm
# sについて
dn={}
for i in range(n):
    if i==0:
        dn[1]=s[i]
    else:
        dn[i*int((lcm)/n) +1]=s[i]

for j in range(m):
    if j==0:
        continue
    else:
        k = j*int(lcm/m) + 1

        if k in dn:
            if dn[k]!=t[j]:
                ans=-1
        else:
            dn[k]=t[j]

print(ans)
Buggy python submission (verdict: Runtime Error):
s=input()
alp='abcdefghijklmnopqrstuvwxyz'

if s=='zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    exit(0)

d={}
e={}
for i in range(len(alp)):
    d[alp[i]]=i
    e[i]=alp[i]

n=len(s)
if n!=26:
    ans=[]
    for i in range(n):
        ans.append(d[s[i]])

    for j in range(26):
        if j not in ans:
            ans.append(j)
            break

    st=''
    for k in ans:
        st+=e[k]
else:
    indices=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]
    dp=[]
    flgs=[0]*n

    for i in range(n):
        dp.append(min(indices))
        if dp[i]==d[s[i]]:
            flgs[i]=0
        else:
            flgs[i]=1
        indices.remove(d[s[i]])

    indices=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]
    ans=[]
    for j in range(n):
        if flgs[j]==0 and flgs[j+1]==0:
            ans.append(d[s[j]])
            indices.remove(d[s[j]])
        else:
            indices.remove(d[s[j]])
            ans.append(min(indices))
            break

    st=''
    for k in ans:
        st+=e[k]


print(st)

Fixed submission:
s=input()
alp='abcdefghijklmnopqrstuvwxyz'

if s=='zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    exit(0)

d={}
e={}
for i in range(len(alp)):
    d[alp[i]]=i
    e[i]=alp[i]

n=len(s)
if n!=26:
    ans=[]
    for i in range(n):
        ans.append(d[s[i]])

    for j in range(26):
        if j not in ans:
            ans.append(j)
            break

    st=''
    for k in ans:
        st+=e[k]
else:
    arr=[]

    dp=[]
    for i in range(n):
        dp.append(d[s[i]])
    
    while True:
        v=dp.pop()

        tmp=[j for j in arr if j>v]
        if len(tmp)!=0:
            dp.append(min(tmp))
            break
        
        arr.append(v)
        
    st=''
    for k in dp:
        st+=e[k]



print(st)
Buggy python submission (verdict: Runtime Error):
h,w,D = map(int,input().split())
a=[]

for _ in range(h):
    b=list(map(int,input().split()))
    a.append(b)

d={}
for i in range(h):
    c=a[i]
    for j in range(w):
        d[c[j]]=(i+1,j+1)


R_min=h*w
R_max=1
query=[]
q=int(input())
for _ in range(q):
    l,r=map(int,input().split())
    query.append([l,r])
    R_min = min(l,R_min)
    R_max = max(r,R_max)


cum=[0]*(h*w)
prev=0
cum[R_min]=0
for k in range(R_min,R_max-D+1):
    prev = cum[k-1]
    cost = abs(d[k+D][0]-d[k][0]) + abs(d[k+D][1]-d[k][1])
    cum[k+D-1]=cost+prev



for j in range(q):
    l,r=query[j][0],query[j][1]

    score = cum[r-1]-cum[l-1]

    if l==r:
        score=0
    

    print(score)

Fixed submission:
h,w,D = map(int,input().split())
a=[]

for _ in range(h):
    b=list(map(int,input().split()))
    a.append(b)

d={}
for i in range(h):
    c=a[i]
    for j in range(w):
        d[c[j]]=(i+1,j+1)


R_min=h*w
R_max=1
query=[]
q=int(input())
for _ in range(q):
    l,r=map(int,input().split())
    query.append([l,r])
    R_min = min(l,R_min)
    R_max = max(r,R_max)


cum=[0]*(h*w+1)
for k in range(R_min,R_max-D+1):
    prev = cum[k-1]
    cost = abs(d[k+D][0]-d[k][0]) + abs(d[k+D][1]-d[k][1])
    cum[k+D-1]=cost+prev



for j in range(q):
    l,r=query[j][0],query[j][1]
    score = cum[r-1]-cum[l-1]
    print(score)
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))

b=sorted(b)
c=sorted(c)

from bisect import bisect_right

d=[]
for i in range(n):
    index = bisect_right(c,b[i])
    if b[i]==c[index]:
        index-=1
    
    if index==-1:
        index=1

    d.append(n-index)

import numpy as np
s=sum(d)
cum=np.cumsum(d)

ans=0
for j in range(n):
    dex = bisect_right(b,a[j])
    if dex==0:
        ans+=s
    elif dex==n:
        continue
    else:
        ans+=s-cum[dex-1]


    

print(ans)
        


Fixed submission:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))

b=sorted(b)
c=sorted(c)

from bisect import bisect_right

d=[]
for i in range(n):
    index = bisect_right(c,b[i])    

    d.append(n-index)

import numpy as np
s=sum(d)
cum=np.cumsum(d)

ans=0
for j in range(n):
    dex = bisect_right(b,a[j])
    if dex==0:
        ans+=s
    elif dex==n:
        continue
    else:
        ans+=s-cum[dex-1]

print(ans)
Buggy python submission (verdict: Runtime Error):
s=input()
t=input()

alp='abcdefghijklmnopqrstuvwxyz'
d={}
e={}
for i in range(len(alp)):
    d[i]=alp[i]
    e[alp[i]]=i


c=[]
q=''
for i in range(len(t)+1):
    q=(t[:i] + '?'*(len(t)-i))
    m=s.rfind(q)
    if m==-1:
        continue

    c.append(m)


h=[]
for j in range(len(t),len(s)+1,1):
    q='?'*j
    m=s.rfind(q)
    if m==-1:
        continue
    h.append(m)

ans=''
if len(c)==0 and len(h)==0:
    ans='UNRESTORABLE'
elif len(c)>0 and len(h)==0:
    index=max(c)
    j=0
    for i in range(len(s)):
        if i>=index and i<= index+len(t):
            ans+=t[j]
            j+=1
        elif s[i]=='?':
            ans+='a'
        else:
            ans+=s[i]     
elif len(h)>0 and len(c)==0:
    index=max(h)
    j=0
    for i in range(len(s)):
        if i>=index and i<= index+len(t):
            ans+=t[j]
            j+=1
        elif s[i]=='?':
            ans+='a'
        else:
            ans+=s[i] 
else:
    index=max(max(c),max(h))
    j=0
    for i in range(len(s)):
        if i>=index and i<= index+len(t):
            ans+=t[j]
            j+=1
        elif s[i]=='?':
            ans+='a'
        else:
            ans+=s[i] 

print(ans)


Fixed submission:
s=input()
t=input()


kouho=[]
for i in range(len(s)-len(t)+1):
    ans=s[:i]
    tmp=s[i:(i+len(t))]

    for j in range(len(t)):
        if tmp[j]==t[j]:
            ans+=t[j]
        elif tmp[j]=='?': 
            ans+=t[j]
        elif tmp[j]!='?' and tmp[j]!=t[j]:
            break
    ans=ans+s[(i+len(t)):]

    if len(ans)==len(s):
        kouho.append(ans)

if len(kouho)==0:
    print('UNRESTORABLE')
    exit(0)

answers=[]
for j in kouho:

    tmp_ans=''
    for k in range(len(j)):
        if j[k]=='?':
            tmp_ans+='a'
        else:
            tmp_ans+=j[k]

    answers.append(tmp_ans)

answers=sorted(answers)
print(answers[0])
Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())

mod =(10**9) + 7
v_n = 1
for i in range(1,n+1):
    v_n*= i%mod
v_m = 1
for j in range(1,m+1):
    v_m*= j%mod

if n==m:
    value = (v_n *v_m * 2)%mod
    print(value)

elif abs(n-m)>2:
    print(0)
    
else:
    ans = (v_n * v_m)%mod
    print(ans)

Fixed submission:
n,m = map(int,input().split())

from math import factorial
mod =(10**9) + 7
# v_n = 1
# for i in range(1,n+1):
#     v_n*= i%mod
# v_m = 1
# for j in range(1,m+1):
#     v_m*= j%mod

v_n = factorial(n)
v_m = factorial(m)
if n==m:
    value = (v_n *v_m * 2)%mod
    print(value)

elif abs(n-m)>=2:
    print(0)

else:
    ans = (v_n * v_m)%mod
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())

mod =pow(10,9) + 7
from operator import mul
from functools import reduce

def factrial(n):
    over = reduce(mul, range(n, 0, -1))
    return over

if n==m:
    value = (factrial(n) * factrial(m) * 2 )%mod

    print(value)

elif abs(n-m)>2:
    print(0)
else:
    ans = (factrial(n) * factrial(m))%mod

    print(ans)

Fixed submission:
n,m = map(int,input().split())

from math import factorial
mod =(10**9) + 7
# v_n = 1
# for i in range(1,n+1):
#     v_n*= i%mod
# v_m = 1
# for j in range(1,m+1):
#     v_m*= j%mod

v_n = factorial(n)
v_m = factorial(m)
if n==m:
    value = (v_n *v_m * 2)%mod
    print(value)

elif abs(n-m)>=2:
    print(0)

else:
    ans = (v_n * v_m)%mod
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())

mod =pow(10,9) + 7
from operator import mul
from functools import reduce

def factrial(n):
    over = reduce(mul, range(n, 0, -1))
    return over

if n==m:
    value = (factrial(n) * factrial(m) * 2 )%mod

    print(value)

elif abs(n-m)>2:
    print(0)
else:
    ans = (factrial(n) * factrial(m))%mod

    print(ans)

Fixed submission:
n,m = map(int,input().split())

from math import factorial
mod =(10**9) + 7
# v_n = 1
# for i in range(1,n+1):
#     v_n*= i%mod
# v_m = 1
# for j in range(1,m+1):
#     v_m*= j%mod

v_n = factorial(n)
v_m = factorial(m)
if n==m:
    value = (v_n *v_m * 2)%mod
    print(value)

elif abs(n-m)>=2:
    print(0)

else:
    ans = (v_n * v_m)%mod
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())

score=[]
ans=0

for _ in range(n):
    s=int(input())
    score.append(s)

# if score%10==0:
#     ans=0

# score=sorted(score,reverse=True)
# for _ in range(n):
#     score.pop()
#     tmp=sum(score)
#     if tmp%10==0:
#         tmp=0

#     ans=max(ans,tmp)

from itertools import combinations 

for m in range(1,n+1):
    c=combinations(score,m)

    for i in c:
        tmp=sum(i)
        if tmp%10==0:
            tmp=0

        ans=max(ans,tmp)

print(ans)
    

Fixed submission:
n=int(input())

score=[]
for _ in range(n):
    s=int(input())
    score.append(s)

#すべて10の倍数ならば0である
non10=[]
flg10=0
for i in range(n):
    if score[i]%10!=0:
        non10.append(score[i])
        flg10=1
    
if flg10==0:
    ans=0
else:
    if sum(score)%10==0:
        ans=sum(score)-min(non10)
    else:
        ans=sum(score)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())

score=[]
ans=0

for _ in range(n):
    s=int(input())
    score.append(s)

# if score%10==0:
#     ans=0

# score=sorted(score,reverse=True)
# for _ in range(n):
#     score.pop()
#     tmp=sum(score)
#     if tmp%10==0:
#         tmp=0

#     ans=max(ans,tmp)

from itertools import combinations 

for m in range(1,n+1):
    c=combinations(score,m)

    for i in c:
        tmp=sum(i)
        if tmp%10==0:
            tmp=0

        ans=max(ans,tmp)

print(ans)
    

Fixed submission:
n=int(input())

score=[]
for _ in range(n):
    s=int(input())
    score.append(s)

#すべて10の倍数ならば0である
non10=[]
flg10=0
for i in range(n):
    if score[i]%10!=0:
        non10.append(score[i])
        flg10=1
    
if flg10==0:
    ans=0
else:
    if sum(score)%10==0:
        ans=sum(score)-min(non10)
    else:
        ans=sum(score)
print(ans)
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())

a=[]
b=[]
d={}
for _ in range(n):
    a_i,b_i=map(int,input().split())
    d[a_i]=b_i

d=sorted(d.items(),key=lambda x: x[0])


prev=0
for key,value in d:
    a.append(key)
    b.append(prev+value)

    prev+=value


for j in range(n):
    if k<=b[j]:
        break

print(a[j])


Fixed submission:
n,k=map(int,input().split())

d={}
for _ in range(n):
    a_i,b_i=map(int,input().split())
    if a_i in d:
        d[a_i]+=b_i
    else:
        d[a_i]=b_i


a=[]
b=[]

d=sorted(d.items(),key=lambda x: x[0])


prev=0
for key,value in d:
    a.append(key)
    b.append(prev+value)

    prev+=value


for j in range(len(b)):
    if k<=b[j]:
        break

print(a[j])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
# 許容する再帰処理の回数を変更
sys.setrecursionlimit(10**5+10)
# input処理を高速化する
input = sys.stdin.readline

K,S = map(int,input().split())
cnt = 0

for x in range(K+1):
    for y in range(K+1):
        for z in range(K+1):
            if x+y+z ==S:
                cnt +=1

print(cnt)

Fixed submission:
import sys
# 許容する再帰処理の回数を変更
sys.setrecursionlimit(10**5+10)
# input処理を高速化する
input = sys.stdin.readline

K,S = map(int,input().split())
cnt = 0

for x in range(K+1):
    for y in range(K+1):
        z =S - x - y
        if z <=K and z>=0:
            cnt +=1

print(cnt)
Buggy python submission (verdict: Runtime Error):
n=int(input())

ans=[1]
i=1
s=1
while True:
    if s>=n:
        break
    i+=1
    s+=i
    ans.append(i)

dif = s-n
if dif==0:
    for i in range(len(ans)):
        print(ans[i])
    exit(0)
    
for i in range(len(ans)):
    if a[i]==dif:
        continue
    print(ans[i])




Fixed submission:
n=int(input())

import bisect

ans=[1]
i=1
s=1
while True:
    if s>=n:
        break
    i+=1
    s+=i
    ans.append(i)

dif = s-n
if dif==0:
    for i in range(len(ans)):
        print(ans[i])
    exit(0)
    
index = bisect.bisect_left(ans,dif)

for i in range(len(ans)):
    if i==index:
        continue
    print(ans[i])
Buggy python submission (verdict: Runtime Error):
a,b,c=map(int,input().split())


total =sum([a,b,c])


if sum_A%3==0:
    print('Yes')
else:
    print('No')


Fixed submission:
A=list(map(int,input().split()))

max_des = max(A)

A.remove(max_des)

if sum(A)==max_des:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
x=input()

for _ in range(10**5):
    x=x.replace('ST','')

print(len(x))

Fixed submission:
x=input()
n=len(x)

t=0
cnt=0
for i in range(n-1,-1,-1):
    if x[i]=='T':
        t+=1
    elif t>0 and x[i]=='S':
        cnt+=1
        t-=1

print(n-2*cnt)

Buggy python submission (verdict: Time Limit Exceeded):
x=input()

for _ in range(10**6):
    x=x.replace('ST','')

print(len(x))

Fixed submission:
x=input()
n=len(x)

t=0
cnt=0
for i in range(n-1,-1,-1):
    if x[i]=='T':
        t+=1
    elif t>0 and x[i]=='S':
        cnt+=1
        t-=1

print(n-2*cnt)

Buggy python submission (verdict: Time Limit Exceeded):
x=input()

for _ in range(10**6):
    x=x.replace('ST','')

print(len(x))

Fixed submission:
x=input()
n=len(x)

t=0
cnt=0
for i in range(n-1,-1,-1):
    if x[i]=='T':
        t+=1
    elif t>0 and x[i]=='S':
        cnt+=1
        t-=1

print(n-2*cnt)
Buggy python submission (verdict: Runtime Error):
s_a = list(input())
s_b = list(input())
s_c = list(input())

S=[s_a,s_b,s_c]

order=0
while true:
    if S[order][0]=='a':
        del S[0][0]
        order=0
    elif S[order][0]=='b':
        del S[1][0]
        order=1
    else:
        del S[2][0]
        order=2

    if len(S[order]==0:
        print('A')
        exit(0)
    elif len(S[order])==0:
        print('B')
        exit(0)
    elif len(S[order])==0:
        print('C')
        exit(0)



Fixed submission:
s_a = list(input())
s_b = list(input())
s_c = list(input())
x=s_a[0]

while True:
    if x=='a':
        if len(s_a)==0:
            print('A')
            exit()

        x=s_a[0]
        s_a.remove(x)


    elif x=='b':
        if len(s_b)==0:
            print('B')
            exit()
        x=s_b[0]
        s_b.remove(x)
        

    elif x=='c':
        if len(s_c)==0:
            print('C')
            exit()
        x=s_c[0]
        s_c.remove(x)
Buggy python submission (verdict: Runtime Error):
N,A=map(int,input().split())
cards=list(map(int,input().split()))

result=0

for i in range(2**N):
    list2 =[]
    for j in range(N):
        if (i >> j) &1 == 1:
            list2.append(cards[j])
    if len(list2)!=0:
        ave =sum(list2)/len(list2)
        if ave==A:
            result+=1

print(result)

Fixed submission:
N=int(input())
K=int(input())
X=int(input())
Y=int(input())

if N>=K:
    print(X*K + Y*(N-K))
else:
    print(X*N)

Buggy python submission (verdict: Runtime Error):
N=int(input())
K=int(input())
X=int(input())
Y=int(input())

if N>=k:
    print(X*K + Y*(K-N))
else:
    print(X*N)

Fixed submission:
N=int(input())
K=int(input())
X=int(input())
Y=int(input())

if N>=K:
    print(X*K + Y*(N-K))
else:
    print(X*N)
Buggy python submission (verdict: Runtime Error):
import collections 

w=input()

l=collections.Counter(list(w))
l=list(l.values())
flg=0
for i in range(len(l)):
    if l[i]%2!=0:
        flg+=1

if flg==0:
    print('Yes')
else:
    pritn('No')


Fixed submission:

w=input()

import collections 

l=collections.Counter(list(w))
l=list(l.values())

flg=0
for i in range(len(l)):
    if l[i]%2!=0:
        flg+=1

if flg==0:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
'''
.append(要素) リストに要素を追加
.extend(リスト) リストを連結する
.insert(場所,要素) 指定した場所に要素追加
del 配列名[場所]
-1で末尾で末尾から一つ前

sort()
sorted(reverse=true)

配列の初期化
配列名=[a]*n+[b]*m

Decimal()
'''

from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby
import bisect
import copy
import math
from functools import reduce
from operator import mul
from collections import Counter
import itertools
import fractions

t = stdin.readline().rstrip().split()
n = int(t[0])
k = int(t[1])
res = []
for el in range(k):
    tt = int(stdin.readline().rstrip())
    for el2 in range(tt):
        person = int(stdin.readline().rstrip())
        res.append(person)
count = 0
for el in range(1, n + 1):
    if not (el in res):
        count += 1
print(count)


Fixed submission:
'''
.append(要素) リストに要素を追加
.extend(リスト) リストを連結する
.insert(場所,要素) 指定した場所に要素追加
del 配列名[場所]
-1で末尾で末尾から一つ前

sort()
sorted(reverse=true)

配列の初期化
配列名=[a]*n+[b]*m

Decimal()
'''

from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby
import bisect
import copy
import math
from functools import reduce
from operator import mul
from collections import Counter
import itertools
import fractions

t = stdin.readline().rstrip().split()
n = int(t[0])
k = int(t[1])
res = []
for el in range(k):
    tt = int(stdin.readline().rstrip())
    person = [int(s) for s in stdin.readline().rstrip().split()]
    for el3 in person:
        res.append(el3)
count = 0
for el in range(1, n + 1):
    if not (el in res):
        count += 1
print(count)