Choosing Pizza Toppings

No attempts yetTime limit1sMemory limit256 MB

Problem

My friends and I are ordering one big pizza to share. Choosing what goes on it is not simple, because everyone wants something different. Gunnar wants bananas, Emma wants no bananas but does want olives, Marc insists on tomatoes, and so it goes.

Once we managed to find a set of toppings that fulfilled at least 2/3 of the wishes of every one of us, and we agreed that this was good enough. Then Lukas lost the note with that list on the way to the pizzeria, so we have to choose again. This time we lower the bar and look for a set of toppings that fulfils strictly more than 1/3 of the wishes of every friend.

Input

The first line contains an integer NN (1N100001 \le N \le 10000), the number of friends in the group, myself included. Each of the next NN lines describes one friend. Such a line starts with an integer ww (1w301 \le w \le 30), the number of wishes of that friend, followed by ww wishes separated by spaces. A wish is written as +topping or -topping. The wish +topping means the friend wants that topping on the pizza, and -topping means the friend wants it left off. Inside one line a topping name appears at most once.

A topping name is a string of 1 to 15 lowercase English letters. The input mentions at most 250 different toppings.

Output

The wish +topping is fulfilled when that topping is on the pizza, and the wish -topping is fulfilled when that topping is not on the pizza. A friend who has ww wishes and ff fulfilled wishes is happy when 3f>w3f > w.

Print a set of toppings that makes every friend happy. You may assume that some set of toppings fulfils at least 2/3 of the wishes of every friend. Many sets can make everyone happy, so print exactly the set that the procedure below builds.

Number the friends 1 to NN in input order. Start with no topping on the pizza and with r=1r = 1, then repeat the following.

  1. If every friend is happy, stop.
  2. Otherwise let ii be the smallest number of a friend who is not happy. List the wishes of friend ii that are not fulfilled, sorted by topping name in increasing order. Call this list LL and its length uu.
  3. Replace rr by (48271×r)mod2147483647(48271 \times r) \bmod 2147483647, then set k=rmoduk = r \bmod u.
  4. Fulfil the wish at position kk of LL, counting positions from 0. Put its topping on the pizza if the wish is a + wish, and take its topping off the pizza if the wish is a - wish.

When the procedure stops, print the toppings that are on the pizza in lexicographic order, one per line. Every printed topping appears in the input, and no topping is printed twice.