Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	io := NewIo()
	defer io.Flush()

	for {
		N := io.NextInt()
		if N == 0 {
			break
		}
		set := make([]map[int]struct{}, N)
		for i := 0; i < N; i++ {
			set[i] = make(map[int]struct{})
			M := io.NextInt()
			for j := 0; j < M; j++ {
				p := io.NextInt()
				set[i][p] = struct{}{}
			}
		}
		K := io.NextInt()
		l := make([]int, K)
		for i := 0; i < K; i++ {
			l[i] = io.NextInt()
		}

		ans := 0
	FOR_OUTER:
		for i := 0; i < N; i++ {
			for j := 0; j < K; j++ {
				if _, f := set[i][l[j]]; f == false {
					continue FOR_OUTER
				}
			}
			switch ans {
			case 0:
				ans = i + 1
			default:
				ans = -1
			}
		}
		if ans > 0 {
			io.Println(ans)
		} else {
			io.Println(-1)
		}
	}
}

// I/O template
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buff []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buff = append(buff, line...)
		if !isPrefix {
			break
		}
	}
	return string(buff)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	s := io.tokens[io.nextToken]
	io.nextToken++
	return s
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *Io) PrintIntSlice(a []int) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func (io *Io) PrintStringSlice(a []string) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func Log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}

func ExampleIo() {
	io := NewIo()
	defer io.Flush()
	a := make([]int, 0, 3)
	a[0], a[1], a[2] = io.NextInt(), io.NextInt(), io.NextInt()
	io.Println(a)
	io.PrintIntSlice(a)
	Log("io", a)
}

C++:  #include <stdio.h>
#include <string.h>

int main(void){
	int member[100][100], leak, n, m, i, j, x, count, res;
	scanf("%d",&n);
	while(n){
		memset(member,0,sizeof(member));
		for(i = 0;i < n;i++){
			scanf("%d",&m);
			for(j = 0;j < m;j++){
				scanf("%d",&x);
				member[i][x - 1] = 1;
			}
		}
		scanf("%d",&m);
		res = -1;
		for(i = 0;i < m && res == -1;i++){
			scanf("%d",&leak);
			count = 0;
			for(j = 0;j < n;j++)
				if(member[j][leak - 1]) count++;
			if(res == -1 && count == 1){
				for(j = 0;j < n;j++)
					if(member[j][leak - 1]) break;
				res = j + 1;
			}else if(res != -1 && count == 1){
				res = -1;
				break;
			}
		}
		printf("%d\n",res);
		scanf("%d",&n);
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int G[103][103];
int more[103];
const int INF=-9;
bool know(int a,int b){//aがbを知っていたらtrue
	if(a==b)return true;
	if(G[a][b]==1)return true;
	return false;
}
int main(){
	int n,m,p,ans=-1;
	while(true){
	cin>>n;
	if(n==0)break;
	ans=-1;
	for(int i=0;i<102;i++)for(int j=0;j<102;j++)G[i][j]=-2;
	for(int i=1;i<=n;i++){
		int tmp;
		cin>>tmp;
		for(int j=0;j<tmp;j++){
			cin>>p;
			G[i][p]=1;
		}
	}
	cin>>m;
	for(int i=0;i<m;i++)cin>>more[i];
	bool f=0;

	for(int i=1;i<=n;i++){
		f=1;
		for(int j=0;j<m;j++){
		if(know(i,more[j])==0)f=0;//知らなければ容疑者から除外
		//cout<<i<<" "<<more[j]<<" "<<know(i,more[j])<<endl;
		}
		if(f&&ans==-1)ans=i;
		else if(f&&ans!=-1){ans=-1;break;}
	}
	cout<<ans<<endl;
	}
	return 0;
}

C++: #include<iostream>

using namespace std;

int data[101][101];

int main(){
	int n;
	while(cin>>n && n){
	for(int i=0;i<101;i++)
		for(int j=0;j<101;j++)data[i][j]=0;
		for(int i=1;i<=n;i++){
			int m;
			cin>>m;
			for(int j=0;j<m;j++){
				int p;
				cin>>p;
				data[i][p]=1;
			}
		}
		int k;
		cin>>k;
		for(int i=0;i<k;i++){
			int l;
			cin>>l;
			for(int j=1;j<=n;j++){
				if(data[j][l]==1 && data[j][0]!=2)data[j][0]=1;
				if(data[j][l]==0)data[j][0]=2;
			}
		}
		int ans=0;		
		for(int i=1;i<=n;i++){
			if( data[i][0]==1){
				if(ans==0)ans=i;
			 	else if(ans!=0){
				ans=-1;
				break;
				}
			}

		}
		if(ans==0)ans=-1;
		cout<<ans<<endl;
	}
	
}

C++: #include <bits/stdc++.h>
using namespace std;

#define pb         push_back

const int INF = 1000000000;
const int MOD = 1000000007;

int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);

	while(1){
		int n;
		int m;
		cin >> n;
		if(n == 0) break;

		vector<set<int> > pset;
		for(int i=0; i<n; i++){
			int m;
			cin >> m;
			set<int> tmp;
			for(int j=0; j<m; j++){
				int x;
				cin >> x;
				tmp.insert(x);
			}
			/*
			puts("set:");
			for(auto it = tmp.begin(); it != tmp.end(); it++){
				cout << *it << " ";
			}
			puts("");
			*/
			pset.push_back(tmp);
		}

		int k;
		cin >> k;
		set<int> sch;
		for(int i=0; i<k; i++){
			int x;
			cin >> x;
			sch.insert(x);
		}

		int ans = -1;
		bool f = false;
		for(int i=0; i<n; i++){
			/*
			for(auto it = pset[i].begin(); it != pset[i].end(); it++){
				cout << *it << " ";
			}
			puts("");
			*/
			//if(includes(sch.begin(), sch.end(), pset[i].begin(), pset[i].end())){
			if(includes(pset[i].begin(), pset[i].end(), sch.begin(), sch.end())){
				if(f){
					ans = -1;
					break;
				}
				ans = i;
				f = true;
			}
		}
		if(ans == -1){
			puts("-1");
		}else{
			printf("%d\n", ans+1);
		}
	}
	

	return 0;
}

C++: #include <bits/stdc++.h>

typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define DECIM8  fixed<<setprecision(8) 
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

using namespace std;
int main(void)
{
  for(;;){
    int n;
    cin >> n;
    if(!n) return 0;
    vector<vector<int> > p;
    p.resize(n);
    REP(i,n){
      int m;
      cin >> m;
      p[i].resize(m);
      REP(j,m) cin >> p[i][j];
      SORT(p[i]);
    }
    vector<int> l;
    int ls;
    cin >> ls;
    l.resize(ls);
    REP(i,ls) cin >> l[i];
    SORT(l);
    vector<int> answer;
    REP(i,SZ(p)){
      int tmp=0;
      REP(j,SZ(l)){
	REP(k,SZ(p[i])){
	  if(l[j]==p[i][k]){
	    ++tmp;
	    break;
	  }
	}
      }
      if(tmp==SZ(l)) answer.PB(i+1);
    }
    if(SZ(answer)==1) cout << answer.front() << endl;
    else cout << -1 << endl;
  }
}

C++: #include <cstdio>
#include <utility>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#define REP(i,n) for(int i=0;i<n;i++)
typedef long long ll;
using namespace std;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;

int main() 
{
	
	int n;
	int b[100][100]={};
	
	while( cin >> n && n!=0)
	{
		REP(i,n)
		{
			int k;
			cin >> k;
			REP(j,k)
			{
				int l;
				cin >> l;
				b[i][l-1] ++;
			}
		}

		int hanin[100]={};
		REP(i,n){	hanin[i]=1;}
		
		int k;
		cin >> k;
		REP(i,k)
		{
			int l;
			cin >> l;
			REP(j,n){
			if(b[j][l-1]==0){	hanin[j] =0;	}
		}}
		
		int sum(0);
		int ans(0);
		REP(i,n){ if(hanin[i]==1){sum+=hanin[i];	ans+=(i+1);}}
		
		if(sum==1){	cout << ans << endl;	}
		else cout << -1 << endl;
		
	}
	return 0 ;
}