stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#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;

}  

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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();

}

// Optimized solution to the same problem (faster):
#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();

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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);

}

// Optimized solution to the same problem (faster):
#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;

}




// Fastest known solution for this problem:
// Original C++ solution (slower):
#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);

}


// Optimized solution to the same problem (faster):
#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;

}




// Fastest known solution for this problem:
// Original C++ solution (slower):
#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);

}




// Optimized solution to the same problem (faster):
#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;

}




// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <cstdio>

#include <vector>

#include <string>

using namespace std;



struct Node

{

  int id;

  int parent;

  vector<int> children;

};



int getDepth(Node t[], Node n)

{

  int count = 0;

  Node node = n;

  while (node.parent != -1)

  {

    count++;

    node = t[node.parent];

  }

  return count;

}



int main()

{

  int n;

  scanf("%d", &n);



  Node tree[100000];

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

    tree[i] = {-100, -1, {}};



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

  {

    int id, k, tmp;

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

    tree[id].id = id;

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

    {

      scanf("%d", &tmp);

      tree[id].children.push_back(tmp);

      tree[tmp].parent = id;

    }

  }



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

  {

    Node node = tree[i];

    if (node.id != -100)

    {

      string type = node.parent == -1 ? "root" : (node.children.size() == 0 ? "leaf" : "internal node");

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

             node.id, node.parent, getDepth(tree, node), type.c_str());

      int size = node.children.size();

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

      {

        if (j != 0)

          printf(", ");

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

      }

      printf("]\n");

    }

  }

  return 0;

}

// Optimized solution to the same problem (faster):
#include <cstdio>

using namespace std;

#define MAX 100001

#define NIL -1



struct Node

{

  int parent, left, right;

};



Node TREE[MAX];

int n, DEP[MAX];



void print(int u)

{

  int i, c;

  printf("node %d: ", u);

  printf("parent = %d, ", TREE[u].parent);

  printf("depth = %d, ", DEP[u]);



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

    printf("root, [");

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

    printf("leaf, [");

  else

    printf("internal node, [");



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

  {

    if (i)

      printf(", ");

    printf("%d", c);

  }

  printf("]\n");

}



void setDepth(int u, int p)

{

  DEP[u] = p;

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

    setDepth(TREE[u].right, p);

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

    setDepth(TREE[u].left, p + 1);

}



int main()

{

  int n, child;

  scanf("%d", &n);



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

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



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

  {

    int id, k, childId;

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

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

    {

      scanf("%d", &childId);

      if (j == 0)

        TREE[id].left = childId;

      else

        TREE[child].right = childId;

      child = childId;

      TREE[childId].parent = id;

    }

  }



  int root;

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

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

      root = i;



  setDepth(root, 0);



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

    print(i);



  return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <vector>

#include <string>



using namespace std;

typedef long long int llint;



struct Node {

	llint parent;

	llint depth;

	string state;

	vector<llint> children;

	Node():parent(-1),depth(0){

	}

};

struct faster_io{

	faster_io() {

		cin.tie(0);

		ios::sync_with_stdio(false);

	}

};



void set_depth(vector<Node> &Nodes, Node &node, int depth) {

	node.depth = depth;

	for (int i = 0; i < node.children.size(); i++) {

		set_depth(Nodes, Nodes[node.children[i]], depth + 1);

	}

}





int main() {

	llint const N_MAX = 100000;

	faster_io io;



	llint n;

	cin >> n;



	vector<Node> Nodes;

	Nodes.resize(N_MAX);



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

		llint id, k;

		cin >> id >> k;

		Node &x = Nodes[id];

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

			llint c;

			cin >> c;

			x.children.push_back(c);

			Nodes[c].parent = id;

		}

	}



	Node root;

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

		Node &x = Nodes[i];

		if (x.parent == -1) {

			x.state = "root";

			root = x;

		}

		else if (x.children.size() == 0) {

			x.state = "leaf";

		}

		else {

			x.state = "internal node";

		}

	}



	set_depth(Nodes, root, 0);



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

		Node x = Nodes[i];

		cout << "node " << i

			<< ": parent = " << x.parent

			<< ", depth = " << x.depth

			<< ", " << x.state

			<< ", [";

		for (llint j = 0; j < x.children.size(); j++)	{

			if (j != x.children.size() - 1) cout << x.children[j] << ", ";

			else cout << x.children[j];

		}

		cout << "]\n";

	}

}

// Optimized solution to the same problem (faster):
#include <cstdio>

 

#define NIL -1

const int MAX_N = 100000 + 5;

 

struct Node {

  int p, lc, rs;

};

 

Node node[MAX_N];

int n;

int id, k, c;

int d[MAX_N];

 

void setDepth(int i, int num) {

  d[i] = num;

  if (node[i].rs != NIL) setDepth(node[i].rs, num);

  if (node[i].lc != NIL) setDepth(node[i].lc, num + 1);

}

 

int main() {

  scanf("%d", &n);

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

    node[i].p = node[i].lc = node[i].rs = NIL;

  }

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

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

    int ls;

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

      scanf("%d", &c);

      node[c].p = id;

      if (j == 0) node[id].lc = c;

      else node[ls].rs = c;

      ls = c;

    }

  }

 

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

    if (node[i].p == NIL) {

      setDepth(i, 0);

      break;

    }

  }

   

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

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

    if (node[i].p == NIL) printf("root, ");

    else if (node[i].lc == NIL) printf("leaf, ");

    else printf("internal node, ");

    printf("[");

    for (int j = 0, c = node[i].lc; c != NIL; j++, c = node[c].rs) {

      if (j) printf(", ");

      printf("%d", c);

    }

    printf("]\n");

  }

  return 0;

}

// Fastest known solution for this problem: