Олимпиадный тренинг

Задача 38787. Object Properties - 1


Задача

Темы: Словари
There are n objects in Vasya's storage, numbered from 1 to n, each of which has a certain number of properties (possibly none). Each property is represented as a natural number from 1 to 109.
After analyzing the structure of his storage, Vasya decided that it should support two operations:
 -  Removing obsolete property c. When a property is deleted, it is deleted from all objects it belongs to.
If the specified property does not exist, there is no need to do anything.
 -  Find the number of remaining properties of the object with number r.
Vasya really needs to implement this functionality, and he turned to you for help. Help him - write a program that will support both operations that Vasya needs.

Input
The first line of the input file contains the number n - the number of objects in Vasya's storage (1 <= n <= 105). The i-th of the next n lines contains a description of the properties of the object with number i: first, the number ki is given - the number of properties of the i-th object, and then ki numbers pi,j - the properties of the i-th object (0 < ;= ki <= 100, 1 <= pi,j <= 109).
All objects are numbered from 1 to n in the order presented in the input. It is guaranteed that the total number of properties of all objects does not exceed 105. It is also guaranteed that for each i all pi,j are distinct.
Line n + 2 contains number q - the number of requests to Vasya's storage (1 <= q <= 105).
The j-th of the following q lines contains information about the j-th request:
-c if you want to remove obsolete property c from storage (1 <= c <= 109);
? r if you want to find the number of remaining properties of the object with number r.

Imprint
For all requests to find the number of remaining properties of the object, on separate lines, in the order they appear for each request, print this number.
 
Examples
# Input Output
1 2
3 1 2 4
3 2 3 5
12
- 1
? 1
? 2
- 2
? 1
? 2
- 5
? 1
? 2
- 6
? 1
? 2
2
3
1
2
1
1
1
1

Remark
Only the first object has property 1, so after deleting it, the first object has 2 properties, and the second still has 3.
Property 2 is present on both objects, so it is removed from both objects, leaving the first object with 1 property and the second with 2.
Only the second object has property 5, so after removing it, both objects have 1 property.
None of the objects have property 6, so deleting it does not change the number of properties for objects.