#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
P dp_min[105][205][205];
P dp_max[105][205][205];
bool used[105][205][205];
vector<int> val;
vector<int> G[105];
int p[205];

struct data{
	int a,b,cnt,st;
	data(){}
	data(int aa,int bb,int cc,int ss){
		a=aa;
		b=bb;
		cnt=cc;
		st=ss;
	}
};

void solve(int v,int l,int r){
	if(used[v][l][r])return;
	//printf("%d %d %d\n",v,l,r);
	used[v][l][r]=true;
	if(G[v].size()==0){
		int pos=lower_bound(val.begin(),val.end(),p[v])-val.begin();
		dp_min[v][l][r]=P(1,pos);
		dp_max[v][l][r]=P(1,pos);
		//printf("%d %d\n",v,val[pos]);
		return;
	}
	int ord[5];
	for(int i=0;i<G[v].size();i++){
		ord[i]=i;
	}
	dp_min[v][l][r]=P(114514,114514);
	do{
		queue<data> que;
		que.push(data(l,r,0,0));
		while(que.size()){
			data d=que.front();
			que.pop();
			if(d.st==G[v].size()){
				dp_min[v][l][r]=min(dp_min[v][l][r],P(d.cnt,d.a));
				dp_max[v][l][r]=max(dp_max[v][l][r],P(d.cnt,d.a));
				continue;
			}
			int nv=G[v][ord[d.st]];
			int ra=lower_bound(val.begin(),val.end(),-val[d.a])-val.begin();
			int rb=lower_bound(val.begin(),val.end(),-val[d.b])-val.begin();
			solve(nv,rb,ra);
			int rpos=lower_bound(val.begin(),val.end(),-val[dp_min[nv][rb][ra].second])-val.begin();
			if(rpos>=d.b){
				dp_min[v][l][r]=min(dp_min[v][l][r],P(d.cnt+dp_min[nv][rb][ra].first,rpos));
				dp_max[v][l][r]=max(dp_max[v][l][r],P(d.cnt+dp_min[nv][rb][ra].first,rpos));	
			}else{
				que.push(data(max(d.a,rpos),d.b,d.cnt+dp_min[nv][rb][ra].first,d.st+1));
			}
			rpos=lower_bound(val.begin(),val.end(),-val[dp_max[nv][rb][ra].second])-val.begin();
			if(rpos>=d.b){
				dp_min[v][l][r]=min(dp_min[v][l][r],P(d.cnt+dp_max[nv][rb][ra].first,rpos));
				dp_max[v][l][r]=max(dp_max[v][l][r],P(d.cnt+dp_max[nv][rb][ra].first,rpos));	
			}else{
				que.push(data(max(d.a,rpos),d.b,d.cnt+dp_max[nv][rb][ra].first,d.st+1));
			}
		}
	}while(next_permutation(ord,ord+G[v].size()));
	//printf("%d %d %d (%d,%d) (%d,%d)\n",v,l,r,dp_min[v][l][r].first,val[dp_min[v][l][r].second],dp_max[v][l][r].first,val[dp_max[v][l][r].second]);
}

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&p[i]);
		val.push_back(p[i]);
		val.push_back(-p[i]);
	}
	val.push_back(114514);
	val.push_back(-114514);
	sort(val.begin(),val.end());
	val.erase(unique(val.begin(),val.end()),val.end());
	for(int i=0;i<n;i++){
		int k;
		scanf("%d",&k);
		for(int j=0;j<k;j++){
			int a;
			scanf("%d",&a);
			a--;
			G[i].push_back(a);
		}
	}
	solve(0,0,val.size()-1);
	printf("%d %d\n",dp_min[0][0][val.size()-1].first,dp_max[0][0][val.size()-1].first);
	return 0;
}

### Prompt

Please create a solution in Cpp to the following problem:

Fox Ciel is developing an artificial intelligence (AI) for a game. This game is described as a game tree T with n vertices. Each node in the game has an evaluation value which shows how good a situation is. This value is the same as maximum value of child nodes’ values multiplied by -1. Values on leaf nodes are evaluated with Ciel’s special function -- which is a bit heavy. So, she will use alpha-beta pruning for getting root node’s evaluation value to decrease the number of leaf nodes to be calculated.

By the way, changing evaluation order of child nodes affects the number of calculation on the leaf nodes. Therefore, Ciel wants to know the minimum and maximum number of times to calculate in leaf nodes when she could evaluate child node in arbitrary order. She asked you to calculate minimum evaluation number of times and maximum evaluation number of times in leaf nodes.

Ciel uses following algotithm:


function negamax(node, α, β)
if node is a terminal node
return value of leaf node
else
foreach child of node
val := -negamax(child, -β, -α)
if val >= β
return val
if val > α
α := val
return α


[NOTE] negamax algorithm

Input

Input follows following format:


n
p_1 p_2 ... p_n
k_1 t_{11} t_{12} ... t_{1k}
:
:
k_n t_{n1} t_{n2} ... t_{nk}


The first line contains an integer n, which means the number of vertices in game tree T.
The second line contains n integers p_i, which means the evaluation value of vertex i.
Then, next n lines which contain the information of game tree T.
k_i is the number of child nodes of vertex i, and t_{ij} is the indices of the child node of vertex i.
Input follows following constraints:

* 2 \leq n \leq 100
* -10,000 \leq p_i \leq 10,000
* 0 \leq k_i \leq 5
* 2 \leq t_{ij} \leq n
* Index of root node is 1.
* Evaluation value except leaf node is always 0. This does not mean the evaluation values of non-leaf nodes are 0. You have to calculate them if necessary.
* Leaf node sometimes have evaluation value of 0.
* Game tree T is tree structure.



Output

Print the minimum evaluation number of times and the maximum evaluation number of times in leaf node.
Please separated by whitespace between minimum and maximum.


minimum maximum

Sample Input 1


3
0 1 1
2 2 3
0
0


Output for the Sample Input 1


2 2


Sample Input 2


8
0 0 100 100 0 -100 -100 -100
2 2 5
2 3 4
0
0
3 6 7 8
0
0
0


Output for the Sample Input 2


3 5


Sample Input 3


8
0 0 100 100 0 100 100 100
2 2 5
2 3 4
0
0
3 6 7 8
0
0
0


Output for the Sample Input 3


3 4


Sample Input 4


19
0 100 0 100 0 0 0 0 0 1 2 3 4 5 6 7 8 9 10
2 2 3
0
2 4 5
0
3 6 7 8
3 9 10 11
3 12 13 14
3 15 16 17
2 18 19
0
0
0
0
0
0
0
0
0
0


Output for the Sample Input 4


7 12






Example

Input

3
0 1 1
2 2 3
0
0


Output

2 2

### Response

```cpp
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
P dp_min[105][205][205];
P dp_max[105][205][205];
bool used[105][205][205];
vector<int> val;
vector<int> G[105];
int p[205];

struct data{
	int a,b,cnt,st;
	data(){}
	data(int aa,int bb,int cc,int ss){
		a=aa;
		b=bb;
		cnt=cc;
		st=ss;
	}
};

void solve(int v,int l,int r){
	if(used[v][l][r])return;
	//printf("%d %d %d\n",v,l,r);
	used[v][l][r]=true;
	if(G[v].size()==0){
		int pos=lower_bound(val.begin(),val.end(),p[v])-val.begin();
		dp_min[v][l][r]=P(1,pos);
		dp_max[v][l][r]=P(1,pos);
		//printf("%d %d\n",v,val[pos]);
		return;
	}
	int ord[5];
	for(int i=0;i<G[v].size();i++){
		ord[i]=i;
	}
	dp_min[v][l][r]=P(114514,114514);
	do{
		queue<data> que;
		que.push(data(l,r,0,0));
		while(que.size()){
			data d=que.front();
			que.pop();
			if(d.st==G[v].size()){
				dp_min[v][l][r]=min(dp_min[v][l][r],P(d.cnt,d.a));
				dp_max[v][l][r]=max(dp_max[v][l][r],P(d.cnt,d.a));
				continue;
			}
			int nv=G[v][ord[d.st]];
			int ra=lower_bound(val.begin(),val.end(),-val[d.a])-val.begin();
			int rb=lower_bound(val.begin(),val.end(),-val[d.b])-val.begin();
			solve(nv,rb,ra);
			int rpos=lower_bound(val.begin(),val.end(),-val[dp_min[nv][rb][ra].second])-val.begin();
			if(rpos>=d.b){
				dp_min[v][l][r]=min(dp_min[v][l][r],P(d.cnt+dp_min[nv][rb][ra].first,rpos));
				dp_max[v][l][r]=max(dp_max[v][l][r],P(d.cnt+dp_min[nv][rb][ra].first,rpos));	
			}else{
				que.push(data(max(d.a,rpos),d.b,d.cnt+dp_min[nv][rb][ra].first,d.st+1));
			}
			rpos=lower_bound(val.begin(),val.end(),-val[dp_max[nv][rb][ra].second])-val.begin();
			if(rpos>=d.b){
				dp_min[v][l][r]=min(dp_min[v][l][r],P(d.cnt+dp_max[nv][rb][ra].first,rpos));
				dp_max[v][l][r]=max(dp_max[v][l][r],P(d.cnt+dp_max[nv][rb][ra].first,rpos));	
			}else{
				que.push(data(max(d.a,rpos),d.b,d.cnt+dp_max[nv][rb][ra].first,d.st+1));
			}
		}
	}while(next_permutation(ord,ord+G[v].size()));
	//printf("%d %d %d (%d,%d) (%d,%d)\n",v,l,r,dp_min[v][l][r].first,val[dp_min[v][l][r].second],dp_max[v][l][r].first,val[dp_max[v][l][r].second]);
}

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&p[i]);
		val.push_back(p[i]);
		val.push_back(-p[i]);
	}
	val.push_back(114514);
	val.push_back(-114514);
	sort(val.begin(),val.end());
	val.erase(unique(val.begin(),val.end()),val.end());
	for(int i=0;i<n;i++){
		int k;
		scanf("%d",&k);
		for(int j=0;j<k;j++){
			int a;
			scanf("%d",&a);
			a--;
			G[i].push_back(a);
		}
	}
	solve(0,0,val.size()-1);
	printf("%d %d\n",dp_min[0][0][val.size()-1].first,dp_max[0][0][val.size()-1].first);
	return 0;
}

```