#include <bits/stdc++.h>
using namespace std;
stack<int> stk, res;
int n, m;
char s[1010000][5];
bool judge() {
  if (n < 3) return 0;
  for (int i = 0; i < n; i++) {
    if (s[i][0] == 'p')
      stk.push(1);
    else {
      stk.push(2);
      m--;
    }
    while (stk.size() >= 3) {
      int nx1 = stk.top();
      stk.pop();
      int nx2 = stk.top();
      stk.pop();
      int nx3 = stk.top();
      stk.pop();
      if (nx1 == 2 && nx2 == 2 && nx3 == 1)
        stk.push(2);
      else {
        stk.push(nx3), stk.push(nx2), stk.push(nx1);
        break;
      }
    }
  }
  if (stk.size() == 1 && stk.top() == 2) return true;
  return false;
}
int main() {
  scanf("%d", &m);
  n = 0;
  while (scanf("%s", s[n++]) != EOF)
    ;
  n--;
  if (n == 1 && s[0][0] == 'i') {
    printf("%s\n", s[0]);
    return 0;
  }
  if (judge()) {
    for (int i = 0; i < n; i++) {
      if (!res.empty() && res.top() == 2) printf(",");
      printf("%s", s[i]);
      if (s[i][0] == 'p')
        printf("<"), res.push(1);
      else {
        res.push(2);
        while (res.size() >= 3) {
          int nx1 = res.top();
          res.pop();
          int nx2 = res.top();
          res.pop();
          int nx3 = res.top();
          res.pop();
          if (nx1 == 2 && nx2 == 2 && nx3 == 1) {
            printf(">");
            res.push(2);
          } else {
            res.push(nx3), res.push(nx2), res.push(nx1);
            break;
          }
        }
      }
    }
    puts("");
  } else
    puts("Error occurred");
  return 0;
}
