Problem: Problem

There are N sets of integers. Each of these sets is assigned a number from 1 to N. The number of elements in the i-th set is Ki, and the j-th smallest integer in the elements of the set is ai, j.

Taro decided to choose any number of sets from this. Taro, who thought it would be boring to just choose the right one, decided to choose at least three sets. In addition, we decided to select the product so that the product of "the number of elements in the union of the selected set" and "the number of elements in the intersection of the selected set" is as large as possible.

When Taro selects the optimal set, find the maximum value of the product of "the number of elements in the union of the selected set" and "the number of elements in the intersection of the selected set".

Constraints

The input satisfies the following conditions.

* All inputs are integers.
* 3 ≤ N ≤ 20,000
* 1 ≤ ai, j ≤ 22
* ai, j <ai, j + 1 (1 ≤ i ≤ N) (1 ≤ j <Ki)

Input

The input is given in the following format.


N
K1 a1,1 a1,2 ... a1, K1
K2 a2,1 a2,2 ... a2, K2
...
KN aN, 1 aN, 2 ... aN, KN


Output

Output the maximum value of the product of "the number of elements in the union of the selected set" and "the number of elements in the intersection of the selected set" when Taro chose optimally.

Examples

Input

4
1 5
2 3 5
3 3 5 7
4 3 5 7 9


Output

8


Input

5
4 1 4 5 6
4 1 7 8 9
3 1 2 3
3 1 2 3
3 1 2 3


Output

9


Input

3
2 3 4
2 2 5
2 1 6


Output

0

Solution (in CPP):

Solution:
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 22

int POW[NUM+1],RANK[4194304],max_union[4194304],num[4194304];
vector<int> STATE[NUM+1];
set<int> SET[4194304];


void calc(){

	int count;

	for(int state = 0; state < POW[NUM]; state++){
		count = 0;
		for(int loop = 0; loop < NUM; loop++){
			if(state & (1 << loop)){
				count++;
			}
		}
		RANK[state] = count;
		STATE[count].push_back(state);
	}
}


int main(){

	for(int i = 0; i < NUM+1; i++)POW[i] = pow(2,i);
	for(int i = 0; i < POW[NUM]; i++){
		num[i] = 0;
		max_union[i] = i;
	}

	calc();

	int N;
	scanf("%d",&N);

	int k,tmp,sum;
	for(int loop = 0; loop < N; loop++){
		scanf("%d",&k);
		sum = 0;
		for(int i = 0; i < k; i++){
			scanf("%d",&tmp);
			tmp--;
			sum += POW[tmp];
		}
		num[sum]++;
		SET[sum].insert(sum);
	}

	int current_state,plus_one_bit_state;
	int ans = 0,copy_count;

	for(int num_bit = NUM; num_bit >= 1; num_bit--){
		for(int k = 0; k < STATE[num_bit].size(); k++){
			current_state = STATE[num_bit][k];

			for(int add_bit = 0; add_bit < NUM; add_bit++){
				if(current_state & (1 << add_bit))continue;

				plus_one_bit_state = current_state+POW[add_bit];

				if(SET[plus_one_bit_state].size() > 0){

					set<int>::iterator it = SET[plus_one_bit_state].begin();
					copy_count = 0;
					while(SET[current_state].size()+copy_count < 3 && it != SET[plus_one_bit_state].end()){
						SET[current_state].insert(*it);
						it++;
						copy_count++;
					}
					max_union[current_state] |= max_union[plus_one_bit_state];
				}
			}

			if((SET[current_state].size() >= 3) ||
					(num[current_state] > 0 && num[current_state]+SET[current_state].size()-1 >= 3)){
				ans = max(ans,RANK[max_union[current_state]]*RANK[current_state]);
			}
		}
	}

	printf("%d\n",ans);

	return 0;
}