Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
found = False

data = list()
list_of_one = list()
for i in range(M):
    tup = tuple(map(int, input().split()))
    if tup[0] == 1:
        list_of_one.append(tup[1])
    else:
        data.append(tup)

for entry in data:
    if entry[0] in list_of_one and entry[1] == N:
        found = True

if found:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')


Fixed submission:
a=[]
b={}
n,m=map(int,input().split())
for _ in range(m):
	i,j=map(int,input().split())
	if i==1:
		a.append(j)
	elif j==n:
		b[i]=1
for i in a:
	if i in b:
		print('POSSIBLE')
		break
else:
	print('IMPOSSIBLE')

Buggy python submission (verdict: Runtime Error):
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define uint unsigned int
#define ull  unsigned long long
typedef string str;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef vector<int> vi;
typedef vector<bool> vb;
#define pb push_back
#define fi first
#define se second
#define in insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
const int INF = 1e9 + 5;
const int N = 2e5 + 1;
int a[N][N];
int main(){
    speed;
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < m; ++i){
        int x, y;
        cin >> x >> y;
        a[x][y] = 1;
    }
    for(int i = 0; i < N; ++i){
        if(a[1][i] && a[i][n]){
            cout << "POSSIBLE";
            return 0;
        }
    }
    cout << "IMPOSSIBLE";
}

Fixed submission:
a=[]
b={}
n,m=map(int,input().split())
for _ in range(m):
	i,j=map(int,input().split())
	if i==1:
		a.append(j)
	elif j==n:
		b[i]=1
for i in a:
	if i in b:
		print('POSSIBLE')
		break
else:
	print('IMPOSSIBLE')
Buggy python submission (verdict: Runtime Error):
def QSortPosition(list,low,high):
    LsaveNum=list[low]
    pivotkey=list[low]
    while(low<high):
        while(list[low]<pivotkey) :
            low+=1
        list[high]=list[low]
        high-=1
        while(list[high]>pivotkey):
            high-=1
        list[low]=list[high]
        low+=1
    list[low]=LsaveNum
    return low

def QSort(list,s,t):
    if(s<t):
        pivotkey=QSortPosition(list,s,t)
        QSort(list,s,pivotkey-1)
        QSort(list,pivotkey+1,t)
    return list

def FindMinS(list,length):
	count1=0
	sum=0

	while count1<length:
		sum=sum+list[count1]
		count1+=1

	InvidNum=length-1
	location=0
	count2=0
	MinList=[]

	while count2<InvidNum:
		count3=count2
		ab1=0
		ab2=0
		while count3<=location:
			ab1=ab1+list[count3]
			count3+=1
			ab2=sum-ab1
			ab3=abs(ab2-ab1)
			MinList.append(ab3)
		count2+=1

	MinList=QSort(MinList,0,InvidNum-1)
	return MinList[0]

num=input("请输入列表长度：")
count=0
list=[]
while count<num:
	listele=input("输入元素：")
	list.append(listele)
	count+=1
minnum=FindMinS(list,num)
print(minnum)

Fixed submission:
import sys

n = int(input())
a = []
b = input().split(" ")
for i in range(n):
	a.append(int(b[i]))

for i in range(1, n):
	a[i] += a[i-1]

mn = abs(a[n-1] - 2*a[0])
for i in range(1, n-1):
	mn = min(mn, abs(a[n-1] - 2*a[i]))

print(mn)

Buggy python submission (verdict: Time Limit Exceeded):
_ = input()
a = [int(i) for i in input().split(' ')]
res = 9999999999999999999999999
for i in range(1,len(a)):
    s = sum(a[:i])
    t = sum(a[i:])
    temp = abs(s-t)
    res = min(temp,res)
print(res)

Fixed submission:
import sys

n = int(input())
a = []
b = input().split(" ")
for i in range(n):
	a.append(int(b[i]))

for i in range(1, n):
	a[i] += a[i-1]

mn = abs(a[n-1] - 2*a[0])
for i in range(1, n-1):
	mn = min(mn, abs(a[n-1] - 2*a[i]))

print(mn)
Buggy python submission (verdict: Runtime Error):
x = int(input())
y = int(input())
s1 = [1, 3, 5, 7, 8, 10, 12]
s2 = [4, 6, 9, 11]
if x >= 1:
    if x <= 12:
        if y >= 1:
            if y <= 12:
                if x in s1 and y in s1:
                    print("Yes")
                elif x in s2 and y in s2:
                    print("Yes")
                elif x == 2 and y == 2:
                    print("Yes")
                else:
                    print("No")

Fixed submission:
s=input().split();
x=int(s[0])
y=int(s[1])
list1=[2]
list2=[4,6,9,11]
list3=[1,3,5,7,8,10,12]
ans=0;
if((x in list1) and (y in list1)): ans=1
elif((x in list2) and (y in list2)):ans=1
elif((x in list3) and (y in list3)):ans=1
if(ans==1):print("Yes")
else:print("No")
Buggy python submission (verdict: Runtime Error):
a, b = (input().split(" "))
a = int(a)
b = int(b)
if(a > b):
  print("GREATER")
elif(a < b):
  print("LESS")
else:
  print("EQUAL")

Fixed submission:
a = input()
b = input()
if(eval(a) > eval(b)):
    print("GREATER")
elif(eval(a) < eval(b)):
    print("LESS")
else:
    print("EQUAL")
Buggy python submission (verdict: Runtime Error):
a=int(input("Enter a"))
b=int(input("Enter b"))
c=int(input("Enter c"))
if a-b == b-c || b-a == c-b:
 print("Beautiful")
else:
 print("No")

Fixed submission:
a,b,c = map(int,input().split())
if b-a == c-b:
    print("YES")
else:
    print("NO")

Buggy python submission (verdict: Runtime Error):
def beautiful:
     a, b, c = input().split()
      if fabs(b-a) == fabs(c-b):
            print('YES')
      else:
            print('NO')

beautiful()

Fixed submission:
a,b,c = map(int,input().split())
if b-a == c-b:
    print("YES")
else:
    print("NO")
Buggy python submission (verdict: Runtime Error):
O=list(input())
E=list(input())
F=[]
j=0
k=0
for i in range(0,len(O)+len(E)):
    F.append('0')
while j<(len(O)+len(E)):
    F[j]=E[k]
    j=j+2
    k=k+1
j=1 
k=0
while j<(len(O)+len(E)):
    F[j]=O[k]
    j=j+2
    k=k+1 
F= ''.join([str(elem) for elem in F])
print(F)

Fixed submission:
O=input()
E=input()

o=list(O)
e=list(E)

str=[0 for i in range(len(o)+len(e))]
j=0
for i in range(0,len(o)):
    str[j]=o[i]
    j+=2
j=1
for i in range(0,len(e)):
    str[j]=e[i]
    j+=2
s=""
for i in range(len(str)):
    s=s+str[i]
print(s)
Buggy python submission (verdict: Runtime Error):
n=int(input())
can=n*800
p=n
des=200
if n>=15 and n<30:
  total=can-200
elif n>=30 and n<45:
  total=can-400
elif n>=45 and n<60:
  total=can-600
elif n>=60 and n<75:
  total=can-800
elif n>=75 and n<90:
  total=can-1000
elif n>=90 and n<=100:
  total=can-1200
print(total)
  

Fixed submission:
n = int(input())

x = 800*n

y = (n // 15) * 200

print(x-y)
Buggy python submission (verdict: Time Limit Exceeded):
n=100000
n=long(raw_input(""))
fact=1
for i in range(1,n+1):
    fact*=i
print (fact%((10**9)+7))    

Fixed submission:
import math
x = int(input())
print(math.factorial(x) % (10**9 + 7))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
li = []
f = 0
for i in a:
    if i not in li:
        li.append(i)
    else:
        f += 1
if f % 2:
	print(len(li) - 1)
else:
	print(len(li))


Fixed submission:
n = int(input())
a = map(int,input().split())
a = set(a)
f = n - len(a)

if f % 2:
	f += 1

print(n - f)
Buggy python submission (verdict: Runtime Error):
a,b,c,d = input()
if a*b > c*d:
    print a*b
elif c*d > a*b:
    print c*d
else:
    print a*b


Fixed submission:
#!/usr/bin/env python
s = raw_input()
array_num = [ int(each_num) for each_num in s.split()]
first_area = array_num[0] * array_num[1]
second_area = array_num[2] * array_num[3] 
if first_area > second_area:
	print(first_area)
elif first_area < second_area:
	print(second_area)
else:
	print(first_area)

Buggy python submission (verdict: Runtime Error):
a = input()
b = input()
c = input()
d = input()
def area(a,b,c, d):
    if a*b > c*d:
        return a*b
    elif c*d > a*b:
        return c*d
    else:
        return a*b

Fixed submission:
#!/usr/bin/env python
s = raw_input()
array_num = [ int(each_num) for each_num in s.split()]
first_area = array_num[0] * array_num[1]
second_area = array_num[2] * array_num[3] 
if first_area > second_area:
	print(first_area)
elif first_area < second_area:
	print(second_area)
else:
	print(first_area)
Buggy python submission (verdict: Runtime Error):

x=0
n=int(input())
F=list(input())
#lis=F.split()
alist=[]
alist.append(x)
for token in F:



    if token=="I":
        x=x+1
        alist.append(x)
    else:
        x=x-1
        alist.append(x)


for i in alist:

    if alist[i]>alist[i+1]:
        x=alist[i]

    else:
        x=alist[i+1]



print(x)

Fixed submission:
n=int(input())
s=input()
x=0
max=0
for i in range(0,n):
    if(s[i] is 'I'):
        x+=1
    elif(s[i] is 'D'):
        x-=1
    if max<x:
        max=x
print(max)

Buggy python submission (verdict: Runtime Error):
n = raw_input()
x = n.split()
N= int(x[0])
S = x[1]
x=0 
y = str(x)
for i in range(0,N):
    if S[i] == "I":
        x = x+1 
        y = y + str(x)
    elif S[i]=="D":
        x = x - 1 
        y = y + str(x)
        
print max([int(c) for c in ])

        
    

Fixed submission:
n=int(input())
s=input()
x=0
max=0
for i in range(0,n):
    if(s[i] is 'I'):
        x+=1
    elif(s[i] is 'D'):
        x-=1
    if max<x:
        max=x
print(max)
Buggy python submission (verdict: Runtime Error):
input = raw_input().split(" ")
output = 0;
if input[1] == "+":
    output = input[0] + input[2]
else:
    output = input[0] - input[2]

print(output)

Fixed submission:
input = input().split(" ")
output = 0;
if input[1] == "+":
    output = int(input[0]) + int(input[2])
else:
    output = int(input[0]) - int(input[2])

print(output)
Buggy python submission (verdict: Runtime Error):
n = int(input()) 
t = list(map(int,input().strip().split()))[:n] 
m = int(input())
p=[]
x=[]
for _ in range(m):
    a,b = map(int,input().split())
    p.append(a)
    x.append(b)
s=sum(t)
for i in range(m):
    T=s
    T-=t[p[i]-1]
    T+=x[p[i]-1]
    print(T)

Fixed submission:
n = int(input())
t = list(map(int,input().split()))
s = sum(t)
m = int(input())
for _ in range(0,m):
    p,x = map(int,input().split())
    print(s-t[p-1]+x)
Buggy python submission (verdict: Runtime Error):
s=input()
s=s.replace('eraser','#')
s=s.replace('erase','#')
s=s.replace('dreamer','#')
s=s.replace('dream')
f=1
for it in s:
    if it !='#':
        f=0
        break

if f==1:
    print("YES")
else :
    print("NO")

Fixed submission:
s=input()
s=s.replace('eraser','*')
s=s.replace('erase','*')
s=s.replace("dreamer","*")
s=s.replace("dream","*")
f=1
for i in s:
    if i!='*':
        f=0
        break
if f:
    print("YES")
else:
    print("NO")
Buggy python submission (verdict: Runtime Error):
from collections import collector 
n=[] 
n=input()
p=counter(n). keys() 
print(p)

Fixed submission:
x = len(set(list(map(int,input().split()))))
print(x)
Buggy python submission (verdict: Runtime Error):
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int len = s.size();
    //nump <= numg
    int nump = 0, numg = 0;
    for(int i = 0 ; i < len; i++){
        if(s[i] == 'p')nump++;
        else if(s[i] == 'g')numg++;
    }
    cout<<(nump+numg)/2-nump;
    return 0;
}


Fixed submission:
x=input()
n=int(len(x)/2)
a=0
ls=[]
def fun():
     for i in range(2):
          ls.append(i)
for i in x:
     if i=='p':
          a+=1
print(n-a)
Buggy python submission (verdict: Runtime Error):
a=input()

m=[]
for i in a:
    if i=='0':
        m.append(i)
    if i=='1':
        m.append(i)
    if i=='B':
        m.pop()
m="".join(m)
print(m)

Fixed submission:
s = input()
l = []
for i in range(len(s)):
    if s[i] != 'B':
        l.append(s[i])
    else:
        if len(l)==0:
            pass
        else:
            del l[-1]
print("".join(l))
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
d = map(str, input().split())
digits = set(d)
num = {str(i) for i in range(0,10)}
left = num - digits
for i in range(N, 100000):
    Num = set(str(i))
    if Num <= left:
        print(i)
        break

Fixed submission:
s, k = [int(i) for i in input().split(" ")]
num = [int(i) for i in input().split(" ")]

def check(n):
	for _s in str(n):
		if int(_s) in num:
			return True
	return False

while check(s):
	s += 1
	
print(s)
Buggy python submission (verdict: Runtime Error):
a1=input()
a2=input()
a3=input()
a=[a1,a2,a3]
a.sort()
flag=0
for i in range(2):
    if a[i]!='5':
        flag=flag+1
if a[2]!='7':
    flag=flag+1
 
if flag==0:
    print("YES")
else:
    print("NO")

Fixed submission:
a=input().split()
if a.count('5')==2 and a.count('7')==1:
	print("YES")
else:
	print("NO")
Buggy python submission (verdict: Runtime Error):
n=int(input())
l=int(input())
arr = ["" for x in range(n)]
for i in range(n):
    arr[i]=input()
arr.sort()
for i in range(n):
    print(arr[i],end="")

Fixed submission:
N, L = map(int, input().split())
ans = ""
s = []
for i in range(N):
    s.append(input())

s.sort()
for i in range(N):
    ans += s[i]
print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
L = int(input())
l=[]
for _ in range(0,N):
    l.append(input())
s=""
l.sort()

for i in l:
    s = s+i
print(s)

Fixed submission:
N, L = map(int, input().split())
ans = ""
s = []
for i in range(N):
    s.append(input())

s.sort()
for i in range(N):
    ans += s[i]
print(ans)

Buggy python submission (verdict: Runtime Error):
N,L=map(int,input().split())
S = [input() for i in range(N)]
S.sort()
for s in S:
  print(s,end=“”)

Fixed submission:
N, L = map(int, input().split())
ans = ""
s = []
for i in range(N):
    s.append(input())

s.sort()
for i in range(N):
    ans += s[i]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

xy = [0] + [tuple(map(int, input().split())) for _ in range(N)]
m = 0
for i in range(1, N+1):
    for j in range(i+1, N+1):
        xyi = xy[i]
        xyj = xy[j]
        tmp = abs(xyi[0]-xyj[0]) + abs(xyi[1]-xyj[1])
        if m < tmp:
            m = tmp
print(m)

Fixed submission:
n = int(input())
xy = [tuple(map(int, input().split())) for _ in range(n)]

w = [xy[i][0] - xy[i][1] for i in range(n)]
z = [xy[i][0] + xy[i][1] for i in range(n)]
print(max((max(w) - min(w)), (max(z)-min(z))))
Buggy python submission (verdict: Runtime Error):
def get_primes(n):
    max_p = int(n ** 0.5)
    p = 0 # 素数
    pl = []  # 素数リスト
    el = [i for i in range(2, n + 1)]  # 探索リスト
    while p <= max_p:
        nxt = []
        p = el[0]
        pl.append(p)
        for e in el:
            if e % p == 0:
                # D[e] = p
                pass
            else:
                nxt.append(e)
        el = nxt
    return pl


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

is_pc = True
is_sc = True

p_list = get_primes(N)
for p in p_list:
    t = [int(x % p == 0) for x in a]
    s = sum(t)
    if s >= 2:
        is_pc = False
    if s == N:
        is_sc = False
        break
if is_pc:
    print('pairwise coprime')
elif is_sc:
    print('setwise coprime')
else:
    print('not coprime')

Fixed submission:
d, t, s = map(int, input().split())
a = d / s
if a <= t:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
s = input()
t = input()
ls = len(s)
lt = len(t)

a = []
sum_ = 0
for i in range(ls-lt+1):
    ss = s[i:i+lt]
    sum_ = 0
    for i, alb in enumerate(lt):
        if alb == ss[i]:
            sum_+= 1
    a.append(sum_)

print(lt - max(a))

Fixed submission:
s = input()
t = input()
ls = len(s)
lt = len(t)

a = []
sum_ = 0
for i in range(ls-lt+1):
    ss = s[i:i+lt]
    sum_ = 0
    for i, alb in enumerate(t):
        if alb == ss[i]:
            sum_+= 1
    a.append(sum_)

print(lt - max(a))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

sum_ = 0
for i in range(N-1):
    for j in range(i+1, N):
        sum_ += A[i] * A[j]
print(sum_ % (10**9 + 7))

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

sum1 = sum(A)
sum2 = 0
for i in range(N-1):
    sum1 -= A[i]
    sum2 += A[i] * sum1
print(sum2 % (10 ** 9 + 7))
Buggy python submission (verdict: Time Limit Exceeded):
n = input()
s = 0
for x in n:
    s += int(n)
if s % 9 == 0:
    print('Yes')
else:
    print('No')

Fixed submission:
N = int(input())
if N % 9 == 0:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
h,a,*m=open(0)
h,w,k,a,b,f,g=map(int,(h+a).split())
I=h*w
d=[I]*I
m+=d,
a=~w+a*w+b
q=[a]
d[a]=1
for s in q:
 for x in 0,1,2,3:
  for z in range(k):
   y=~z,0,z+1,0;i,j=s//w+y[x],s%w+y[~x];t=i*w+j;p=d[s]+1
   if'.'!=m[i][j]ord[t]<p:break
   if d[t]>p:q+=t,;d[t]=p
print(d[~w+f*w+g]%I-1)


Fixed submission:
h,a,*m=open(0)
h,w,k,a,b,f,g=map(int,(h+a).split())
I=h*w
d=[I]*I
m+=d,
a=~w+a*w+b
q=[a]
d[a]=1
for s in q:
 for x in 0,1,2,3:
  for z in range(k):
   y=~z,0,z+1,0;i,j=s//w+y[x],s%w+y[~x];t=i*w+j;p=d[s]+1
   if'.'!=m[i][j]or d[t]<p:break
   if d[t]>p:q+=t,;d[t]=p
print(d[~w+f*w+g]%I-1)
Buggy python submission (verdict: Runtime Error):
import numpy as np

n_consts, n_agents = map(int, input().split())
const_plans = []
dep_times = []
results = [-1 for _ in range(n_agents)]

for _ in range(n_consts):
    const_plans.append([int(e) for e in input().split()])

const_plans = np.array(const_plans)
order_by_x = np.argsort(const_plans.T)[-1]
const_plans = const_plans[order_by_x]

for _ in range(n_agents):
    dep_times.append(int(input()))

for n_agent, dep_time in enumerate(dep_times):
    for const_plan in const_plans:
        x = const_plan[2]
        x1 = max(0, const_plan[0] - dep_time)
        x2 = max(0, const_plan[1] - dep_time)
        if x1 <= x < x2:
            results[n_agent] = x

for result in results:
    print(result)

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

print((3 * A + P) // 2)

Buggy python submission (verdict: Runtime Error):
import numpy as np
import itertools as ittr

def test_switch(e_balls, sw, p):
    for i, e_ball in enumerate(e_balls):
        si = sw[e_ball - 1]
        
        if p[i] != (np.sum(si == 1) % 2):
            return False
    
    return True

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

e_balls = []

for m in range(M):
    i = input().split()
    s = [int(si) for si in i[1:]]
    e_balls.append(np.asarray(s))

p = [int(pi) for pi in input().split()]

cnt = 0

for sw in ittr.product([0, 1], repeat = N):
    if test_switch(e_balls, np.array(sw), p):
        cnt += 1

print(cnt)

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

print((3 * A + P) // 2)
Buggy python submission (verdict: Runtime Error):
import numpy as np
import itertools as ittr

def test_switch(e_balls, sw, p):
    for i, e_ball in enumerate(e_balls):
        si = sw[eb - 1]
        
        if p[i] != (np.sum(si == 1) % 2):
            return False
    
    return True

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

e_balls = []

for m in range(M):
    i = input().split()
    s = [int(si) for si in i[1:]]
    e_balls.append(s[:])

p = [int(pi) for pi in input().split()]

cnt = 0

for sw in ittr.product([0, 1], repeat = N):
    if test_switch(e_balls, np.array(sw), p):
        cnt += 1

print(cnt)

Fixed submission:
import numpy as np

def test_switch(e_balls, sw, p):
    for i, e_ball in enumerate(e_balls):
        eb = np.asarray(e_ball)
        si = sw[eb - 1]
        
        if p[i] != (np.sum(si == 1) % 2):
            return False
    
    return True

def transform_sw(sw):
    if sw[0] == 0:
        sw[0] = 1
        return sw
    else:
        sw[0] = 0

    for i, s in enumerate(sw[1:]):
        if s == 0:
            sw[i + 1] = 1
            return sw
        elif s == 1:
            sw[i + 1] = 0
    
    return sw


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

e_balls = []

for m in range(M):
    i = input().split()
    s = [int(si) for si in i[1:]]
    e_balls.append(s[:])

p = [int(pi) for pi in input().split()]

sw = np.array([0 for _ in range(N)])
cnt = 0

while np.sum(sw == 1) != N:
    if test_switch(e_balls, sw, p):
        cnt += 1
    transform_sw(sw)

if test_switch(e_balls, sw, p):
        cnt += 1

print(cnt)

Buggy python submission (verdict: Runtime Error):
import numpy as np
import itertools as ittr

def test_switch(e_balls, sw, p):
    for i, e_ball in enumerate(e_balls):
        eb = np.asarray(e_ball)
        si = sw[eb - 1]
        
        if p[i] != (np.sum(si == 1) % 2):
            return False
    
    return True

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

e_balls = []

for m in range(M):
    i = input().split()
    s = [int(si) for si in i[1:]]
    e_balls.append(s[:])

p = [int(pi) for pi in input().split()]

cnt = 0

for sw in ittr.product([0, 1], repeat = N)
    if test_switch(e_balls, sw, p):
        cnt += 1

print(cnt)

Fixed submission:
import numpy as np

def test_switch(e_balls, sw, p):
    for i, e_ball in enumerate(e_balls):
        eb = np.asarray(e_ball)
        si = sw[eb - 1]
        
        if p[i] != (np.sum(si == 1) % 2):
            return False
    
    return True

def transform_sw(sw):
    if sw[0] == 0:
        sw[0] = 1
        return sw
    else:
        sw[0] = 0

    for i, s in enumerate(sw[1:]):
        if s == 0:
            sw[i + 1] = 1
            return sw
        elif s == 1:
            sw[i + 1] = 0
    
    return sw


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

e_balls = []

for m in range(M):
    i = input().split()
    s = [int(si) for si in i[1:]]
    e_balls.append(s[:])

p = [int(pi) for pi in input().split()]

sw = np.array([0 for _ in range(N)])
cnt = 0

while np.sum(sw == 1) != N:
    if test_switch(e_balls, sw, p):
        cnt += 1
    transform_sw(sw)

if test_switch(e_balls, sw, p):
        cnt += 1

print(cnt)