Army

4.3

3 votes
Implementation, Mathematics, Easy
Problem

The far away land of Edinbrugh is going to war with the land of eternal darkness, Darkalvennia. King James the III, the king of Edinbrugh calls upon his war council to formulate the battle plan. The war counil comprises of, apart from the king, his 10 army chiefs numbered from chief0 to chief9. The king also has a standing army of N soldiers and each soldier has a number assigned to him/her starting from 1 to N.

Now, the army chiefs being a bit eccentric, only like certain soldiers, for example, Chief0 only likes soldiers with 0 in their number, Chief1 likes soldiers with 1 in their number and so on.

A few days ago, King James III received a mysterious letter saying that there might be a spy within his army chiefs, so the king decides that he'll only send some of his army chiefs to war.

Given the size of King James the III's army, N, and the chiefs he selects to go to war, your task is to determine the size of the army that'll go to war against Darkalvennia.

Input:
First line of input contains an integer N, number of soldiers. Next line contains an integer Q, number of queries. Each query first line contains an integer M that is number of chief selected by Kings James. Second line of query contains M space separated integers represents chief of the army.

Constraints:
1<=N<=100000
1<=Q<=1500
1<=M<=10

Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

Number of Soldiers = 20
Query #1:
Chief selected by King James are : Chief1 and Chief2
Chief1 will select soldiers having number : 1, 10, 11 ,12, 13, 14, 15, 16, 17, 18, 19
Chief2 will select soldiers having number : 2, 12, 20

Total size of the army will be 13 not 14 because 12 will be count only once not twice.

Editor Image

?