stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

string s1,s2;

int main(){

	cin>>s1;

	s2=s1;

	reverse(s1.begin(),s1.end());

	for(int i=0;i<s1.length();i++){

		if(s1[i]=='b')s1[i]='d';

		else if(s1[i]=='d')s1[i]='b';

		 if(s1[i]=='p')s1[i]='q';

		else if(s1[i]=='q')s1[i]='p';

	}

	for(int i=0;i<s1.length();i++){

		if(s1[i]!=s2[i]){

			cout<<"No"<<endl;

			return 0;

		}

	}

	cout<<"Yes"<<endl;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.337733442605229x):
#include<algorithm>

#include<cstring>

#include<cstdio>

#include<cmath>

char s[100007];

int get[128];

int main()

{

    get['b'] = 0 , get['p'] = 1 , get['d'] = 2 , get['q'] = 3;

    scanf("%s",s+1); // 从 s[1] 开始的

    for(int l = strlen(s+1), i = 1; i <= (l>>1) + 1; ++i)

    {

        if(get[s[i]]^((get[s[l-i+1]]+2)%4)) return printf("No\n"),0;

    } // 这个 +2 %4 刚好让 b 转到 d 上， d 转到 b 上， p 转到 q 上， q 转到 p 上 

    return printf("Yes\n"),0;

}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<string>

using namespace std;

char sa[100010];

int i,n;

int main()

{

	while((sa[n]=getchar())!='\n') n++;

	n--;

	while((sa[i]=='p'&&sa[n-i]=='q')||(sa[i]=='q'&&sa[n-i]=='p')||(sa[i]=='b'&&sa[n-i]=='d')||(sa[i]=='d'&&sa[n-i]=='b')) i++;

	if(i>n/2) cout<<"Yes"<<endl;

	else cout<<"No"<<endl;

	return 0;

}  

// Faster C++ solution for the same problem (measured speedup: 5.284003112665365x):
#include<algorithm>

#include<cstring>

#include<cstdio>

#include<cmath>

char s[100007];

int get[128];

int main()

{

    get['b'] = 0 , get['p'] = 1 , get['d'] = 2 , get['q'] = 3;

    scanf("%s",s+1); // 从 s[1] 开始的

    for(int l = strlen(s+1), i = 1; i <= (l>>1) + 1; ++i)

    {

        if(get[s[i]]^((get[s[l-i+1]]+2)%4)) return printf("No\n"),0;

    } // 这个 +2 %4 刚好让 b 转到 d 上， d 转到 b 上， p 转到 q 上， q 转到 p 上 

    return printf("Yes\n"),0;

}
// Slower C++ solution:
#include <iostream>



using namespace std;



int soba[][2] = {

	{200, 380},

	{300, 550},

	{500, 850}

};



int main() {

	int n, m = 5000 * 500;

	cin >> n;

	if (n == 0){

		return 0;

	}

	for (int i = n / soba[2][0] + 100; i >= 0; i--) {

		for (int j = n / soba[1][0] + 100; j >= 0; j--) {

			for (int k = n / soba[0][0] + 100; k >= 0; k--) {

				int w = i * soba[2][0] + j * soba[1][0] + k * soba[0][0];

				if (w == n) {

					int p = (i / 3 * 3 * soba[2][1] * 0.88) + (i % 3 * soba[2][1]) + (j / 4 * 4 * soba[1][1] * 0.85) + (j % 4 * soba[1][1]) + (k / 5 * 5 * soba[0][1] * 0.8) + (k % 5 * soba[0][1]);

					if (p < m) {

						m = p;

					}

				}

			}

		}

	}

	cout << m << endl;

	return main();

}

// Faster C++ solution for the same problem (measured speedup: 2.349878009603825x):
#include <iostream>



using namespace std;



int soba[][2] = {

	{200, 380},

	{300, 550},

	{500, 850}

};



int main() {

	int n, m = 5000 * 500;

	cin >> n;

	if (n == 0){

		return 0;

	}

	for (int i = n / soba[2][0]; i >= 0; i--) {

		for (int j = n / soba[1][0]; j >= 0; j--) {

			for (int k = n / soba[0][0]; k >= 0; k--) {

				int w = i * soba[2][0] + j * soba[1][0] + k * soba[0][0];

				if (w == n) {

					int p = (i / 3 * 3 * soba[2][1] * 0.88) + (i % 3 * soba[2][1]) + (j / 4 * 4 * soba[1][1] * 0.85) + (j % 4 * soba[1][1]) + (k / 5 * 5 * soba[0][1] * 0.8) + (k % 5 * soba[0][1]);

					if (p < m) {

						m = p;

					}

				}

			}

		}

	}

	cout << m << endl;

	return main();

}
// Slower C++ solution:
#include<iostream>

using namespace std;

#define MAX 100005

#define NIL -1

struct Node{

	int p,l,r;

}T[MAX];

int n,depth[MAX];

void print(int root){

	cout<<"node "<<root<<": ";

	cout<<"parent = "<<T[root].p<<", ";

	cout<<"depth = "<<depth[root]<<", ";

	if(T[root].p==NIL) cout<<"root, ";

	else if(T[root].l==NIL) cout<<"leaf, ";

	else cout<<"internal node, ";

	cout<<"[";

	for(int i=0,c=T[root].l;c!=NIL;i++,c=T[c].r){

		if(i) cout<<", ";

		cout<<c;

	}

	cout<<"]"<<endl;

}

void rec(int root,int p){

	depth[root]=p;

	if(T[root].r!=NIL) rec(T[root].r,p);

	if(T[root].l!=NIL) rec(T[root].l,p+1);

}

int main(){

	int l;

	cin>>n;

	for(int i=0;i<n;i++){

		T[i].p=T[i].l=T[i].r=NIL;

	}

	for(int i=0;i<n;i++){

		int v,d;

		cin>>v>>d;

		for(int j=0;j<d;j++){

			int node;

			cin>>node;

			if(!j) T[v].l=node;

			else T[l].r=node;

			l=node;

			T[node].p=v;

		}

	}

	int root;

	for(int i=0;i<n;i++){

		if(T[i].p==NIL) root=i;

	}

	rec(root,0);

	for(int i=0;i<n;i++) print(i);

}

// Faster C++ solution for the same problem (measured speedup: 5.127454875008365x):
#include <stdio.h>



const int N = 100000;

const int NIL = -1;



struct Node

{

	int parent, left, right;

};



Node T[N];

int d[N];



void getDepth(int u, int p)

{

	d[u] = p;

	if (T[u].left != NIL)

		getDepth(T[u].left, p + 1);

	if (T[u].right != NIL)

		getDepth(T[u].right, p);

}



void print(int u)

{

	printf("node %d: parent = %d, depth = %d, ",

			u, T[u].parent, d[u]);

	if (T[u].parent == NIL)

		printf("root, ");

	else if (T[u].left == NIL)

		printf("leaf, ");

	else

		printf("internal node, ");

	printf("[");

	/*

	if (T[u].left != NIL)

	{

		printf("%d", T[u].left);

		int c = T[T[u].left].right;

		while (c != NIL)

		{

			printf(", %d", c);

			c = T[c].right;

		}

	}

	*/

	// 更简洁的写法

	for (int i = 0, c = T[u].left; c != NIL; i++, c = T[c].right)

	{

		if (i > 0)

			printf(", ");

		printf("%d", c);

	}



	printf("]\n");

}



int main()

{

	int n;

	scanf("%d", &n);

	for (int i = 0; i < n; i++)

		T[i].parent = T[i].left = T[i].right = NIL;



	for (int i = 0; i < n; i++)

	{

		int v, d, l;

		scanf("%d%d", &v, &d);

		for (int j = 0; j < d; j++)

		{

			int c;

			scanf("%d", &c);

			if (j == 0)

				T[v].left = c;

			else

				T[l].right = c;

			T[c].parent = v;

			l = c;

		}

	}

	int r;

	for (int i = 0; i < n; i++)

		if (T[i].parent == NIL)

			r = i;



	getDepth(r, 0);



	for (int i = 0; i < n; i++)

		print(i);



	return 0;

}
// Slower C++ solution:
#include <cmath>

#include <cstdio>

#include <cstdlib>

#include <cstring>

#include <iostream>

#include <algorithm>

using namespace std;

const int maxn=1e5+7;

#define NIL -1

struct Node

{

    int parent,left,right;

}tree[maxn];

int n,Depth[maxn];

void init()

{

    for(int i=0;i<n;i++)tree[i].parent=tree[i].left=tree[i].right=NIL;

}

void calc_depth(int root,int depth)

{

    Depth[root]=depth;

    if(tree[root].right!=NIL)calc_depth(tree[root].right,depth);

    if(tree[root].left!=NIL)calc_depth(tree[root].left,depth+1);

}

void print(int node)

{

    printf("node %d: parent = %d, depth = %d, ",node,tree[node].parent,Depth[node]);

    if(tree[node].parent==NIL)printf("root, ");

    else if(tree[node].left==NIL)printf("leaf, ");

    else printf("internal node, ");

    putchar('[');

    for(int i=0,tmp=tree[node].left;tmp!=NIL;i++,tmp=tree[tmp].right)

    {

        if(i)printf(", ");

        printf("%d",tmp);

    }

    printf("]\n");

}

int main()

{

    cin>>n;

    init();

    for(int i=0;i<n;i++)

    {

        int node_index,a,bro;

        scanf("%d%d",&node_index,&a);

        for(int j=0;j<a;j++)

        {

            int node;

            scanf("%d",&node);

            if(j==0) tree[node_index].left=node;

            else tree[bro].right=node;

            bro=node;

            tree[node].parent=node_index;

        }

    }

    int root;

    for(int i=0;i<n;i++)if(tree[i].parent==NIL)root=i;

    calc_depth(root,0);

    for(int i=0;i<n;i++)print(i);

}


// Faster C++ solution for the same problem (measured speedup: 5.122233660388964x):
#include <stdio.h>



const int N = 100000;

const int NIL = -1;



struct Node

{

	int parent, left, right;

};



Node T[N];

int d[N];



void getDepth(int u, int p)

{

	d[u] = p;

	if (T[u].left != NIL)

		getDepth(T[u].left, p + 1);

	if (T[u].right != NIL)

		getDepth(T[u].right, p);

}



void print(int u)

{

	printf("node %d: parent = %d, depth = %d, ",

			u, T[u].parent, d[u]);

	if (T[u].parent == NIL)

		printf("root, ");

	else if (T[u].left == NIL)

		printf("leaf, ");

	else

		printf("internal node, ");

	printf("[");

	/*

	if (T[u].left != NIL)

	{

		printf("%d", T[u].left);

		int c = T[T[u].left].right;

		while (c != NIL)

		{

			printf(", %d", c);

			c = T[c].right;

		}

	}

	*/

	// 更简洁的写法

	for (int i = 0, c = T[u].left; c != NIL; i++, c = T[c].right)

	{

		if (i > 0)

			printf(", ");

		printf("%d", c);

	}



	printf("]\n");

}



int main()

{

	int n;

	scanf("%d", &n);

	for (int i = 0; i < n; i++)

		T[i].parent = T[i].left = T[i].right = NIL;



	for (int i = 0; i < n; i++)

	{

		int v, d, l;

		scanf("%d%d", &v, &d);

		for (int j = 0; j < d; j++)

		{

			int c;

			scanf("%d", &c);

			if (j == 0)

				T[v].left = c;

			else

				T[l].right = c;

			T[c].parent = v;

			l = c;

		}

	}

	int r;

	for (int i = 0; i < n; i++)

		if (T[i].parent == NIL)

			r = i;



	getDepth(r, 0);



	for (int i = 0; i < n; i++)

		print(i);



	return 0;

}
// Slower C++ solution:
#include <iostream>

#include <cstdio>

#include <algorithm>



using namespace std;

const int maxn = 100005;

#define NIL -1



struct node{

    int parent;

    int left;

    int right;

};



node T[maxn];

int D[maxn], n;



void rec(int node, int depth){

    D[node] = depth;

    if(T[node].left != NIL)

        rec(T[node].left, depth+1);

    if(T[node].right != NIL)

        rec(T[node].right, depth);

}



void print(int u){

    cout << "node " << u << ": ";

    cout << "parent = " << T[u].parent << ", ";

    cout << "depth = " << D[u] << ", ";



    if(T[u].parent == NIL)  cout << "root, ";

    else if(T[u].left == NIL)   cout << "leaf, ";

    else cout << "internal node, ";



    cout << "[";



    for(int i = 0, child = T[u].left; child != NIL; i++, child = T[child].right){

        if(i)   cout << ", ";

        cout << child;

    }

    cout << "]" << endl;

}



int main(){

    int v,k,child,sib,root;

    cin >> n;

    for(int i = 0; i < n; i++)

        T[i].parent = T[i].left = T[i].right = NIL;



    for(int i = 0; i < n; i++){

        cin >> v >> k;

        for(int j = 0; j < k; j++){

            cin >> child;

            if(j == 0)  T[v].left = child;

            else    T[sib].right = child;



            sib = child;

            T[child].parent = v;

        }

    }



    for(int i = 0; i < n; i++){

        if(T[i].parent == NIL)

            root = i;

    }



    rec(root,0);

    for(int i = 0; i < n; i++)  print(i);

}




// Faster C++ solution for the same problem (measured speedup: 5.126041003692013x):
#include <stdio.h>



const int N = 100000;

const int NIL = -1;



struct Node

{

	int parent, left, right;

};



Node T[N];

int d[N];



void getDepth(int u, int p)

{

	d[u] = p;

	if (T[u].left != NIL)

		getDepth(T[u].left, p + 1);

	if (T[u].right != NIL)

		getDepth(T[u].right, p);

}



void print(int u)

{

	printf("node %d: parent = %d, depth = %d, ",

			u, T[u].parent, d[u]);

	if (T[u].parent == NIL)

		printf("root, ");

	else if (T[u].left == NIL)

		printf("leaf, ");

	else

		printf("internal node, ");

	printf("[");

	/*

	if (T[u].left != NIL)

	{

		printf("%d", T[u].left);

		int c = T[T[u].left].right;

		while (c != NIL)

		{

			printf(", %d", c);

			c = T[c].right;

		}

	}

	*/

	// 更简洁的写法

	for (int i = 0, c = T[u].left; c != NIL; i++, c = T[c].right)

	{

		if (i > 0)

			printf(", ");

		printf("%d", c);

	}



	printf("]\n");

}



int main()

{

	int n;

	scanf("%d", &n);

	for (int i = 0; i < n; i++)

		T[i].parent = T[i].left = T[i].right = NIL;



	for (int i = 0; i < n; i++)

	{

		int v, d, l;

		scanf("%d%d", &v, &d);

		for (int j = 0; j < d; j++)

		{

			int c;

			scanf("%d", &c);

			if (j == 0)

				T[v].left = c;

			else

				T[l].right = c;

			T[c].parent = v;

			l = c;

		}

	}

	int r;

	for (int i = 0; i < n; i++)

		if (T[i].parent == NIL)

			r = i;



	getDepth(r, 0);



	for (int i = 0; i < n; i++)

		print(i);



	return 0;

}
// Slower C++ solution:
#include <cstdio>

#include <cstring>

#include <algorithm>

#include <iostream>

#include <vector>

using namespace std;

const int maxn=100005;

struct tree

{

    int parent;

    vector<int>child;

    int depth;

};

tree node[maxn];

int n;

void init()

{

    for (int i=0;i<n;i++)

        node[i].depth=node[i].parent=-1;

}

int Find (int x)

{

    if(node[x].parent==-1)

        return node[x].depth=0;

    else if(node[x].depth!=-1)

        return node[x].depth;

    else

        return Find(node[x].parent)+1;

}

int main()

{

    scanf("%d",&n);

    init();

    for (int i=0;i<n;i++)

    {

        int x,num;

        scanf("%d%d",&x,&num);

        while (num--)

        {

            int y;

            scanf("%d",&y);

            node[y].parent=x;

            node[x].child.push_back(y);

        }

    }

    for (int i=0;i<n;i++)

    {

        printf("node %d: parent = %d, depth = %d, ",i,node[i].parent,node[i].depth=Find(i));

        if(node[i].parent==-1)

            printf("root, ");

        else if(!node[i].child.size())

            printf("leaf, ");

        else

            printf("internal node, ");

        printf("[");

        for (int j=0;j<node[i].child.size();j++)

        {

            printf("%d",node[i].child[j]);

            if(j<node[i].child.size()-1)

                printf(", ");

        }

        printf("]\n");

    }

    return 0;

}




// Faster C++ solution for the same problem (measured speedup: 5.289313729356914x):
#include<iostream>

using namespace std;



#define NIL -1

struct node

{

	int left;

	int right;

	int parent;

};

struct node tree[100005];

int D[100005];

void rec(int u,int p)

{

	D[u]=p;

	if((tree[u].right)!=NIL)

		rec(tree[u].right,p);

	if((tree[u].left)!=NIL)

		rec(tree[u].left,p+1);

}



void print(int i)

{

	int j,c;

	cout<<"node "<<i<<": ";

	cout<<"parent = "<<tree[i].parent<<", ";

	cout<<"depth = "<<D[i]<<", ";

	if(tree[i].parent==NIL)

		cout<<"root, ";

	else if(tree[i].left==NIL)

		cout<<"leaf, ";

	else

		cout<<"internal node, ";

	cout<<"[";

	for(j=0,c=tree[i].left;c!=NIL;j++,c=tree[c].right)

	{

		if(j)

			cout<<", ";

		cout<<c;

	}

	cout<<"]"<<endl;

}

int main()

{

	int n;

	int num,c,l,r,nod;

	cin>>n;

	for(int i=0;i<n;i++)

	{

		tree[i].parent=NIL;

		tree[i].left=NIL;

		tree[i].right=NIL;

	}

	for(int i=0;i<n;i++)

	{

		cin>>c>>num;

		for(int j=0;j<num;j++)

		{

			cin>>nod;

			if(j==0)

				tree[c].left=nod;

			else

				tree[l].right=nod;

			l=nod;

			tree[nod].parent=c;

		}

	}

	for(int i=0;i<n;i++)

	{

		if((tree[i].parent)==NIL)

		{

			r=i;

			break;

		}

	}

	rec(r,0);

	for(int i=0;i<n;i++)

		print(i);

	return 0;

}
// Slower C++ solution:
#include <cstdio>

#include <cstring>

#include <algorithm>

#include <iostream>

#include <vector>

using namespace std;

const int maxn=100005;

struct tree

{

    int parent;

    vector<int>child;

    int depth;

};

tree node[maxn];

int n;

void init()

{

    for (int i=0;i<n;i++)

        node[i].depth=node[i].parent=-1;

}

int Find (int x)

{

    if(node[x].parent==-1)

        return node[x].depth=0;

    else if(node[x].depth!=-1)

        return node[x].depth;

    else

        return Find(node[x].parent)+1;

}

int main()

{

    scanf("%d",&n);

    init();

    for (int i=0;i<n;i++)

    {

        int x,num;

        scanf("%d%d",&x,&num);

        while (num--)

        {

            int y;

            scanf("%d",&y);

            node[y].parent=x;

            node[x].child.push_back(y);

        }

    }

    for (int i=0;i<n;i++)

    {

        printf("node %d: parent = %d, depth = %d, ",i,node[i].parent,node[i].depth=Find(i));

        if(node[i].parent==-1)

            printf("root, ");

        else if(!node[i].child.size())

            printf("leaf, ");

        else

            printf("internal node, ");

        printf("[");

        for (int j=0;j<node[i].child.size();j++)

        {

            printf("%d",node[i].child[j]);

            if(j<node[i].child.size()-1)

                printf(", ");

        }

        printf("]\n");

    }

    return 0;

}




// Faster C++ solution for the same problem (measured speedup: 5.3098860169043745x):
#include<cstdio>

#include<set>

#include<iostream>

#include <iterator>

#include <utility>

#include<map>

#define max 100005

using namespace std;

struct tree

{

	int parent;

	int left;

	int  right;

};

struct tree T[max];

int dep(int i)

{

	int d=0;

	while(T[i].parent!=-1)

	{

		i=T[i].parent;

		d++;

	}

	return d;

}

void print(int i)

{

	printf("node %d: parent = %d, depth = %d, ",i,T[i].parent,dep(i));

	if(T[i].parent==-1)

	printf("root, ");

	else if(T[i].left==-1)

	printf("leaf, ");

	else

	printf("internal node, ");

	printf("[");

	for(int j=0,c=T[i].left;c!=-1;c=T[c].right,j++)

	{

		if(j)

		printf(", ");

		printf("%d",c);

	}

	printf("]\n");

}

int main()

{

	int n,id,k,c,p,r,l;

	cin>>n;

	for(int i=0;i<n;i++)

	{

		T[i].left=-1;

		T[i].parent=-1;

		T[i].right=-1;

	}

	for(int i=0;i<n;i++)

	{

		cin>>id>>k;

		for(int j=0;j<k;j++)

		{

			cin>>c;

			if(j==0)

			T[id].left=c;

			else

			T[l].right=c;

			l=c;

			T[c].parent=id;

		}

	}

	for(int i=0;i<n;i++)

	print(i);

	return 0;

}
// Slower C++ solution:
#include <iostream>

#include <algorithm>

#include <cstdio>

#include <list>

#include <stack>

#include <vector>

#include <map>

#include <set>

#include <cstring>

#include <cmath>

#include <string>

#define N 100005

#define INF (1 << 30)

typedef long long ll;

using namespace std;



vector<int> child[N];

int parent[N];

int GetDepth(int idx)

{

	int ret = 0;

	while (parent[idx] != -1)

	{

		++ret;

		idx = parent[idx];

	}

	return ret;

}

const char *str[3] = { "root", "internal node", "leaf" };

int main()

{

	int n;

	cin >> n;

	fill(parent, parent + n, -1);

	int id, k, c;

	for (int i = 0; i < n; ++i)

	{

		cin >> id >> k;

		for (int j = 0; j < k; ++j)

		{

			cin >> c;

			parent[c] = id;

			child[id].push_back(c);

		}

	}

	for (int i = 0; i < n; ++i)

	{

		int depth = GetDepth(i);

		int status;

		if (depth == 0)

			status = 0;

		else if (child[i].size())

		{

			status = 1;

			sort(child[i].begin(), child[i].end());

		}

		else

			status = 2;

		printf("node %d: parent = %d, depth = %d, %s, ", i, parent[i], depth, str[status]);

		printf("[");

		for (int j = 0; j < child[i].size(); ++j)

		{

			if (j)

				printf(", ");

			printf("%d", child[i][j]);

		}

		printf("]\n");

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.4700297482661497x):
#include <iostream>

#include <algorithm>

using namespace std;

#define NIL -1

struct Node {

	int depth, left, right, parent;

	Node()

	{

		left = right = parent = NIL;

	}

} *node;



void setDepth(int x, int d)

{

	node[x].depth = d;

	if (node[x].left != NIL)

		setDepth(node[x].left, d + 1);

	if (node[x].right != NIL)

		setDepth(node[x].right, d);

}



int main(void)

{

	ios::sync_with_stdio(false);

	cin.tie(0);

	int n, id, k, root;

	int c, pre;

	cin >> n;

	node = new Node[n];

	for (int i = 0; i < n; ++i)

	{

		cin >> id >> k;

		if (k > 0)

		{

			cin >> c;

			node[id].left = c;

			node[c].parent = id;

			pre = c;

			for (int j = 1; j < k; j++)

			{

				cin >> c;

				node[pre].right = c;

				node[c].parent = id;

				pre = c;

			}

		}

	}

	for (root = 0; root < n; ++root)

		if (node[root].parent == NIL)

			break;



	setDepth(root, 0);



	for (int i = 0; i < n; ++i)

	{

		cout << "node " << i << ": parent = " << node[i].parent << ", depth = " << node[i].depth << ", ";

		if (node[i].parent == NIL)

			cout << "root, ";

		else if (node[i].left == NIL)

			cout << "leaf, ";

		else

			cout << "internal node, ";

		cout << '[';

		if (node[i].left != NIL)

		{

			int j = node[i].left;

			cout << j;

			while (node[j].right != NIL)

			{

				j = node[j].right;

				cout << ", " << j;

			}

		}

		cout << ']' << endl;

	}



	return 0;

}
// Slower C++ solution:
#include <iostream>

#include <algorithm>

#include <cstdio>

#include <list>

#include <stack>

#include <vector>

#include <map>

#include <set>

#include <cstring>

#include <cmath>

#include <string>

#define N 100005

#define INF (1 << 30)

typedef long long ll;

using namespace std;



vector<int> child[N];

int parent[N];

int GetDepth(int idx)

{

	int ret = 0;

	while (parent[idx] != -1)

	{

		++ret;

		idx = parent[idx];

	}

	return ret;

}

const char *str[3] = { "root", "internal node", "leaf" };

int main()

{

	int n;

	scanf("%d", &n);

	fill(parent, parent + n, -1);

	int id, k, c;

	for (int i = 0; i < n; ++i)

	{

		scanf("%d %d", &id, &k);

		for (int j = 0; j < k; ++j)

		{

			scanf("%d", &c);

			parent[c] = id;

			child[id].push_back(c);

		}

	}

	for (int i = 0; i < n; ++i)

	{

		int depth = GetDepth(i);

		int status;

		if (depth == 0)

			status = 0;

		else if (child[i].size())

		{

			status = 1;

			sort(child[i].begin(), child[i].end());

		}

		else

			status = 2;

		printf("node %d: parent = %d, depth = %d, %s, ", i, parent[i], depth, str[status]);

		printf("[");

		for (int j = 0; j < child[i].size(); ++j)

		{

			if (j)

				printf(", ");

			printf("%d", child[i][j]);

		}

		printf("]\n");

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.4698508960195347x):
#include <iostream>

#include <algorithm>

using namespace std;

#define NIL -1

struct Node {

	int depth, left, right, parent;

	Node()

	{

		left = right = parent = NIL;

	}

} *node;



void setDepth(int x, int d)

{

	node[x].depth = d;

	if (node[x].left != NIL)

		setDepth(node[x].left, d + 1);

	if (node[x].right != NIL)

		setDepth(node[x].right, d);

}



int main(void)

{

	ios::sync_with_stdio(false);

	cin.tie(0);

	int n, id, k, root;

	int c, pre;

	cin >> n;

	node = new Node[n];

	for (int i = 0; i < n; ++i)

	{

		cin >> id >> k;

		if (k > 0)

		{

			cin >> c;

			node[id].left = c;

			node[c].parent = id;

			pre = c;

			for (int j = 1; j < k; j++)

			{

				cin >> c;

				node[pre].right = c;

				node[c].parent = id;

				pre = c;

			}

		}

	}

	for (root = 0; root < n; ++root)

		if (node[root].parent == NIL)

			break;



	setDepth(root, 0);



	for (int i = 0; i < n; ++i)

	{

		cout << "node " << i << ": parent = " << node[i].parent << ", depth = " << node[i].depth << ", ";

		if (node[i].parent == NIL)

			cout << "root, ";

		else if (node[i].left == NIL)

			cout << "leaf, ";

		else

			cout << "internal node, ";

		cout << '[';

		if (node[i].left != NIL)

		{

			int j = node[i].left;

			cout << j;

			while (node[j].right != NIL)

			{

				j = node[j].right;

				cout << ", " << j;

			}

		}

		cout << ']' << endl;

	}



	return 0;

}