#include <bits/stdc++.h>
using namespace std;
const int Maxv = 100100;
const int Inf = 1000000000;
int m;
char str[Maxv][10];
bool flag;
int l;
int ls[Maxv];
int rs[Maxv];
int len;
bool vis[Maxv];
void dfs(int x) {
  if (x >= len) {
    flag = false;
    return;
  }
  vis[x] = true;
  l++;
  if (str[x][0] == 'p') {
    ls[x] = l;
    dfs(l);
    rs[x] = l;
    dfs(l);
  }
}
void dfsp(int x) {
  printf("%s", str[x]);
  if (str[x][0] == 'p') {
    printf("<");
    dfsp(ls[x]);
    printf(",");
    dfsp(rs[x]);
    printf(">");
  }
}
void Put2() {
  flag = true;
  l = 0;
  dfs(0);
  for (int i = 0; i < len; i++)
    if (!vis[i]) flag = false;
  if (!flag) {
    puts("Error occurred");
    return;
  }
  dfsp(0);
  puts("");
}
int main() {
  int i, j = 0, k;
  int n;
  scanf("%d", &n);
  for (i = 0;; i++) {
    int c = scanf("%s", str[i]);
    if (c < 0) break;
  }
  len = i;
  Put2();
  return 0;
}
