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 <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
int k[20001],bit[20001];

int dp[1<<22];
set<int> cnt[1<<22];

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&k[i]);
		for(int j=0;j<k[i];j++){
			int a=0;
			scanf("%d",&a);
			a--;
			bit[i]+=(1<<a);
		}
		dp[bit[i]]=bit[i];
		if(cnt[bit[i]].size()<3)cnt[bit[i]].insert(i);
	}
	int res=0;
	for(int i=(1<<22)-1;i>=0;i--){
		for(int j=0;j<22;j++){
			if(!((i>>j) & 1)){
				dp[i]|=dp[i+(1<<j)];
				set<int>::iterator it=cnt[i+(1<<j)].begin();
				while(cnt[i].size()<3 && it!=cnt[i+(1<<j)].end()){
					cnt[i].insert(*it);
					it++;
				}
			}
		}
		if(cnt[i].size()==3){
			int v=__builtin_popcount(i)*__builtin_popcount(dp[i]);
			res=max(res,v);
		}
	}
	printf("%d\n",res);
	return 0;
}