#include <bits/stdc++.h>
int const N = 200118;
int const M = 10;
char str[N << 1][M];
char ans[N * M * 2];
int pn, in, tt, top;
int n, len, di, flag, cnt;
struct node {
  int l, r;
} tree[N << 1];
void dfs1(int rt) {
  if (str[di][0] == 'p') {
    ans[top++] = 'p';
    ans[top++] = 'a';
    ans[top++] = 'i';
    ans[top++] = 'r';
    ans[top++] = '<';
    di++;
    if (di <= tt) tree[rt].l = di;
    dfs1(di);
    ans[top++] = ',';
    if (di <= tt) tree[rt].r = di;
    dfs1(di);
    ans[top++] = '>';
  } else {
    ans[top++] = 'i';
    ans[top++] = 'n';
    ans[top++] = 't';
    di++;
    tree[rt].l = tree[rt].r = -1;
  }
}
void dfs2(int id) {
  if (!flag) return;
  cnt++;
  if (str[id][0] == 'p') {
    if (tree[id].l == -1 || tree[id].r == -1) flag = 0;
    dfs2(tree[id].l);
    dfs2(tree[id].r);
  }
}
int main() {
  while (~scanf("%d", &n)) {
    gets(ans);
    gets(ans);
    len = strlen(ans);
    cnt = tt = pn = in = 0;
    flag = 1;
    di = 1;
    for (int i = 0; i < len; i++) {
      if (ans[i] == 'p') {
        ++tt;
        str[tt][0] = 'p';
        str[tt][1] = 'a';
        str[tt][2] = 'i';
        str[tt][3] = 'r';
        str[tt][4] = '\0';
        pn++;
        i += 4;
      }
      if (ans[i] == 'i') {
        ++tt;
        str[tt][0] = 'i';
        str[tt][1] = 'n';
        str[tt][2] = 't';
        str[tt][4] = '\0';
        in++;
        i += 3;
      }
    }
    top = 0;
    if (in - 1 != pn) {
      printf("Error occurred\n");
      continue;
    }
    dfs1(di);
    dfs2(1);
    if (cnt < tt) flag = 0;
    if (!flag)
      printf("Error occurred\n");
    else {
      ans[top] = '\0';
      printf("%s\n", ans);
    }
  }
  return 0;
}
