There are $n$ lamps on a line, numbered from $1$ to $n$. Each one has an initial state off ($0$) or on ($1$).

You're given $k$ subsets $A_1, \ldots, A_k$ of $\{1, 2, \dots, n\}$, such that the intersection of any three subsets is empty. In other words, for all $1 \le i_1 < i_2 < i_3 \le k$, $A_{i_1} \cap A_{i_2} \cap A_{i_3} = \varnothing$.

In one operation, you can choose one of these $k$ subsets and switch the state of all lamps in it. It is guaranteed that, with the given subsets, it's possible to make all lamps be simultaneously on using this type of operation.

Let $m_i$ be the minimum number of operations you have to do in order to make the $i$ first lamps be simultaneously on. Note that there is no condition upon the state of other lamps (between $i+1$ and $n$), they can be either off or on.

You have to compute $m_i$ for all $1 \le i \le n$.


-----Input-----

The first line contains two integers $n$ and $k$ ($1 \le n, k \le 3 \cdot 10^5$).

The second line contains a binary string of length $n$, representing the initial state of each lamp (the lamp $i$ is off if $s_i = 0$, on if $s_i = 1$).

The description of each one of the $k$ subsets follows, in the following format:

The first line of the description contains a single integer $c$ ($1 \le c \le n$)  — the number of elements in the subset.

The second line of the description contains $c$ distinct integers $x_1, \ldots, x_c$ ($1 \le x_i \le n$)  — the elements of the subset.

It is guaranteed that:   The intersection of any three subsets is empty;  It's possible to make all lamps be simultaneously on using some operations. 


-----Output-----

You must output $n$ lines. The $i$-th line should contain a single integer $m_i$  — the minimum number of operations required to make the lamps $1$ to $i$ be simultaneously on.


-----Examples-----
Input
7 3
0011100
3
1 4 6
3
3 4 7
2
2 3

Output
1
2
3
3
3
3
3

Input
8 6
00110011
3
1 3 8
5
1 2 5 6 7
2
6 8
2
3 5
2
4 7
1
2

Output
1
1
1
1
1
1
4
4

Input
5 3
00011
3
1 2 3
1
4
3
3 4 5

Output
1
1
1
1
1

Input
19 5
1001001001100000110
2
2 3
2
5 6
2
8 9
5
12 13 14 15 16
1
19

Output
0
1
1
1
2
2
2
3
3
3
3
4
4
4
4
4
4
4
5



-----Note-----

In the first example:   For $i = 1$, we can just apply one operation on $A_1$, the final states will be $1010110$;  For $i = 2$, we can apply operations on $A_1$ and $A_3$, the final states will be $1100110$;  For $i \ge 3$, we can apply operations on $A_1$, $A_2$ and $A_3$, the final states will be $1111111$. 

In the second example:   For $i \le 6$, we can just apply one operation on $A_2$, the final states will be $11111101$;  For $i \ge 7$, we can apply operations on $A_1, A_3, A_4, A_6$, the final states will be $11111111$.

Difficulty: HARD

Starter code:

Solutions:
from sys import stdin

class disjoinSet(object):

	def __init__(self, n):
		self.father = [x for x in range(0, n + 1)]
		self.rank = [0 for x in range(0, n + 1)]

	def setOf(self, x):
		if self.father[x] != x:
			self.father[x] = self.setOf(self.father[x])
		return self.father[x]

	def Merge(self, x, y):
		xR = self.setOf(x)
		yR = self.setOf(y)
		if xR == yR:
			return
		if self.rank[xR] < self.rank[yR]:
			self.father[xR] = yR
			size[yR] += size[xR]
		elif self.rank[xR] > self.rank[yR]:
			self.father[yR] = xR
			size[xR] += size[yR]
		else:
			self.father[yR] = xR
			size[xR] += size[yR]
			self.rank[xR] += 1

def LessSize(x):
	return min(size[dsu.setOf(x)], size[dsu.setOf(x + k)])

def Solve(i):
	global ans
	cant = col[i][0]
	if cant == 2:
		x = col[i][1]
		y = col[i][2]
		if S[i] == 1:
			if dsu.setOf(x) == dsu.setOf(y):
				return
			ans -= LessSize(x) + LessSize(y)
			dsu.Merge(x, y)
			dsu.Merge(x + k, y + k)
			ans += LessSize(y)
		else:
			if dsu.setOf(x) == dsu.setOf(y + k):
				return
			ans -= LessSize(x) + LessSize(y)
			dsu.Merge(x, y + k)
			dsu.Merge(x + k, y)
			ans += LessSize(y)
	elif cant == 1:
		x = col[i][1]
		if S[i] == 1:
			if dsu.setOf(x) == dsu.setOf(0):
				return
			ans -= LessSize(x)
			dsu.Merge(x, 0)
			ans += LessSize(x)
		else:
			if dsu.setOf(x + k) == dsu.setOf(0):
				return
			ans -= LessSize(x)
			dsu.Merge(x + k, 0)
			ans += LessSize(x)
(n, k) = map(int, input().split())
S = [1] + list(map(int, list(stdin.readline().strip())))
dsu = disjoinSet(k * 2 + 1)
col = [[0 for _ in range(3)] for _ in range(n + 2)]
size = [0 for _ in range(k * 2 + 1)]
ans = 0
for i in range(1, k + 1):
	c = stdin.readline()
	c = int(c)
	conjunto = [1] + list(map(int, list(stdin.readline().split())))
	for j in range(1, len(conjunto)):
		x = conjunto[j]
		col[x][0] = col[x][0] + 1
		col[x][col[x][0]] = i
for i in range(1, k + 1):
	size[i] = 1
size[0] = 3 * 1000000.0
for i in range(1, n + 1):
	Solve(i)
	print(ans)


import sys
readline = sys.stdin.readline

class UF:

	def __init__(self, num):
		self.par = [-1] * num
		self.weight = [0] * num

	def find(self, x):
		if self.par[x] < 0:
			return x
		else:
			stack = []
			while self.par[x] >= 0:
				stack.append(x)
				x = self.par[x]
			for xi in stack:
				self.par[xi] = x
			return x

	def union(self, x, y):
		rx = self.find(x)
		ry = self.find(y)
		if rx != ry:
			if self.par[rx] > self.par[ry]:
				(rx, ry) = (ry, rx)
			self.par[rx] += self.par[ry]
			self.par[ry] = rx
			self.weight[rx] += self.weight[ry]
		return rx
(N, K) = map(int, readline().split())
S = list(map(int, readline().strip()))
A = [[] for _ in range(N)]
for k in range(K):
	BL = int(readline())
	B = list(map(int, readline().split()))
	for b in B:
		A[b - 1].append(k)
cnt = 0
T = UF(2 * K)
used = set()
Ans = [None] * N
inf = 10 ** 9 + 7
for i in range(N):
	if not len(A[i]):
		Ans[i] = cnt
		continue
	kk = 0
	if len(A[i]) == 2:
		(x, y) = A[i]
		if S[i]:
			rx = T.find(x)
			ry = T.find(y)
			if rx != ry:
				rx2 = T.find(x + K)
				ry2 = T.find(y + K)
				sp = min(T.weight[rx], T.weight[rx2]) + min(T.weight[ry], T.weight[ry2])
				if x not in used:
					used.add(x)
					T.weight[rx] += 1
				if y not in used:
					used.add(y)
					T.weight[ry] += 1
				rz = T.union(rx, ry)
				rz2 = T.union(rx2, ry2)
				sf = min(T.weight[rz], T.weight[rz2])
				kk = sf - sp
		else:
			rx = T.find(x)
			ry2 = T.find(y + K)
			sp = 0
			if rx != ry2:
				ry = T.find(y)
				rx2 = T.find(x + K)
				sp = min(T.weight[rx], T.weight[rx2]) + min(T.weight[ry], T.weight[ry2])
				if x not in used:
					used.add(x)
					T.weight[rx] += 1
				if y not in used:
					used.add(y)
					T.weight[ry] += 1
				rz = T.union(rx, ry2)
				rz2 = T.union(rx2, ry)
				sf = min(T.weight[rz], T.weight[rz2])
				kk = sf - sp
	elif S[i]:
		x = A[i][0]
		rx = T.find(x)
		rx2 = T.find(x + K)
		sp = min(T.weight[rx], T.weight[rx2])
		T.weight[rx] += inf
		sf = min(T.weight[rx], T.weight[rx2])
		kk = sf - sp
	else:
		x = A[i][0]
		rx = T.find(x)
		rx2 = T.find(x + K)
		sp = min(T.weight[rx], T.weight[rx2])
		T.weight[rx2] += inf
		if x not in used:
			used.add(x)
			T.weight[rx] += 1
		sf = min(T.weight[rx], T.weight[rx2])
		kk = sf - sp
	Ans[i] = cnt + kk
	cnt = Ans[i]
print('\n'.join(map(str, Ans)))


import sys

def find(x):
	if x == pre[x]:
		return x
	else:
		pre[x] = find(pre[x])
		return pre[x]

def merge(x, y):
	x = find(x)
	y = find(y)
	if x != y:
		pre[x] = y
		siz[y] += siz[x]

def cal(x):
	return min(siz[find(x)], siz[find(x + k)])

def Solve(i):
	global ans
	cant = col[i][0]
	if cant == 2:
		x = col[i][1]
		y = col[i][2]
		if S[i] == 1:
			if find(x) == find(y):
				return
			ans -= cal(x) + cal(y)
			merge(x, y)
			merge(x + k, y + k)
			ans += cal(x)
		else:
			if find(x) == find(y + k):
				return
			ans -= cal(x) + cal(y)
			merge(x, y + k)
			merge(x + k, y)
			ans += cal(x)
	elif cant == 1:
		x = col[i][1]
		if S[i] == 1:
			if find(x) == find(0):
				return
			ans -= cal(x)
			merge(x, 0)
			ans += cal(x)
		else:
			if find(x + k) == find(0):
				return
			ans -= cal(x)
			merge(x + k, 0)
			ans += cal(x)
(n, k) = map(int, input().split())
S = [1] + list(map(int, list(sys.stdin.readline().strip())))
col = [[0 for _ in range(3)] for _ in range(n + 2)]
pre = [i for i in range(k * 2 + 1)]
siz = [0 for _ in range(k * 2 + 1)]
ans = 0
for i in range(1, k + 1):
	c = sys.stdin.readline()
	c = int(c)
	conjunto = [1] + list(map(int, list(sys.stdin.readline().split())))
	for j in range(1, len(conjunto)):
		x = conjunto[j]
		col[x][0] = col[x][0] + 1
		col[x][col[x][0]] = i
for i in range(1, k + 1):
	siz[i] = 1
siz[0] = 3 * 1000000.0
for i in range(1, n + 1):
	Solve(i)
	print(ans)


import sys
input = sys.stdin.readline
(n, k) = map(int, input().split())
S = [1] + list(map(int, list(input().strip())))
C = []
for i in range(k):
	c = int(input())
	C.append(list(map(int, input().split())))
NUM = [[] for i in range(n + 1)]
for i in range(k):
	for c in C[i]:
		NUM[c].append(i)
COLORS = [-1] * k
EDGE0 = [[] for i in range(k)]
EDGE1 = [[] for i in range(k)]
for i in range(1, n + 1):
	if len(NUM[i]) == 1:
		if S[i] == 0:
			COLORS[NUM[i][0]] = 1
		else:
			COLORS[NUM[i][0]] = 0
	elif len(NUM[i]) == 2:
		(x, y) = NUM[i]
		if S[i] == 0:
			EDGE0[x].append(y)
			EDGE0[y].append(x)
		else:
			EDGE1[x].append(y)
			EDGE1[y].append(x)
Q = [i for i in range(k) if COLORS[i] != -1]
while Q:
	x = Q.pop()
	for to in EDGE0[x]:
		if COLORS[to] == -1:
			COLORS[to] = 1 - COLORS[x]
			Q.append(to)
	for to in EDGE1[x]:
		if COLORS[to] == -1:
			COLORS[to] = COLORS[x]
			Q.append(to)
for i in range(k):
	if COLORS[i] == -1:
		COLORS[i] = 0
		Q = [i]
		while Q:
			x = Q.pop()
			for to in EDGE0[x]:
				if COLORS[to] == -1:
					COLORS[to] = 1 - COLORS[x]
					Q.append(to)
			for to in EDGE1[x]:
				if COLORS[to] == -1:
					COLORS[to] = COLORS[x]
					Q.append(to)
Group = [i for i in range(k)]
W0 = [0] * k
W1 = [0] * k
for i in range(k):
	if COLORS[i] == 0:
		W0[i] = 1
	else:
		W1[i] = 1

def find(x):
	while Group[x] != x:
		x = Group[x]
	return x

def Union(x, y):
	if find(x) != find(y):
		if W0[find(x)] + W1[find(x)] < W0[find(y)] + W1[find(y)]:
			W0[find(y)] += W0[find(x)]
			W0[find(x)] = 0
			W1[find(y)] += W1[find(x)]
			W1[find(x)] = 0
			Group[find(x)] = find(y)
		else:
			W0[find(x)] += W0[find(y)]
			W0[find(y)] = 0
			W1[find(x)] += W1[find(y)]
			W1[find(y)] = 0
			Group[find(y)] = find(x)
ANS = 0
SCORES = [0] * k
for i in range(1, n + 1):
	if len(NUM[i]) == 0:
		True
	elif len(NUM[i]) == 1:
		x = NUM[i][0]
		ANS -= SCORES[find(x)]
		SCORES[find(x)] = 0
		W0[find(x)] += 1 << 31
		ANS += W1[find(x)]
		SCORES[find(x)] = W1[find(x)]
	else:
		(x, y) = NUM[i]
		ANS -= SCORES[find(x)]
		SCORES[find(x)] = 0
		ANS -= SCORES[find(y)]
		SCORES[find(y)] = 0
		if find(x) != find(y):
			Union(x, y)
		SCORES[find(x)] += min(W0[find(x)], W1[find(x)])
		ANS += min(W0[find(x)], W1[find(x)])
	print(ANS)


from sys import stdin
input = stdin.readline
(n, k) = [int(i) for i in input().split()]
pairs = [i + k for i in range(k)] + [i for i in range(k)]
initial_condition = list(map(lambda x: x == '1', input().strip()))
data = [i for i in range(2 * k)]
constrain = [-1] * (2 * k)
h = [0] * (2 * k)
L = [1] * k + [0] * k
dp1 = [-1 for i in range(n)]
dp2 = [-1 for i in range(n)]
for i in range(k):
	input()
	inp = [int(j) for j in input().split()]
	for s in inp:
		if dp1[s - 1] == -1:
			dp1[s - 1] = i
		else:
			dp2[s - 1] = i
pfsums = 0
ans = []

def remove_pfsum(s1):
	global pfsums
	if constrain[s1] == 1:
		pfsums -= L[s1]
	elif constrain[pairs[s1]] == 1:
		pfsums -= L[pairs[s1]]
	else:
		pfsums -= min(L[s1], L[pairs[s1]])

def sh(i):
	while i != data[i]:
		i = data[i]
	return i

def upd_pfsum(s1):
	global pfsums
	if constrain[s1] == 1:
		pfsums += L[s1]
	elif constrain[pairs[s1]] == 1:
		pfsums += L[pairs[s1]]
	else:
		pfsums += min(L[s1], L[pairs[s1]])

def ms(i, j):
	i = sh(i)
	j = sh(j)
	cons = max(constrain[i], constrain[j])
	if h[i] < h[j]:
		data[i] = j
		L[j] += L[i]
		constrain[j] = cons
		return j
	else:
		data[j] = i
		if h[i] == h[j]:
			h[i] += 1
		L[i] += L[j]
		constrain[i] = cons
		return i
for i in range(n):
	if dp1[i] == -1 and dp2[i] == -1:
		pass
	elif dp2[i] == -1:
		s1 = sh(dp1[i])
		remove_pfsum(s1)
		constrain[s1] = 0 if initial_condition[i] else 1
		constrain[pairs[s1]] = 1 if initial_condition[i] else 0
		upd_pfsum(s1)
	else:
		s1 = sh(dp1[i])
		s2 = sh(dp2[i])
		if s1 == s2 or pairs[s1] == s2:
			pass
		else:
			remove_pfsum(s1)
			remove_pfsum(s2)
			if initial_condition[i]:
				new_s1 = ms(s1, s2)
				new_s2 = ms(pairs[s1], pairs[s2])
			else:
				new_s1 = ms(s1, pairs[s2])
				new_s2 = ms(pairs[s1], s2)
			pairs[new_s1] = new_s2
			pairs[new_s2] = new_s1
			upd_pfsum(new_s1)
	ans.append(pfsums)
for i in ans:
	print(i)