#include <bits/stdc++.h>
using namespace std;
int a[1500000], b[1500000];
int main() {
  int n;
  scanf("%d", &n);
  char str[10];
  int tot = 0;
  string s;
  int r = 0;
  while (scanf("%s", str) != EOF) {
    if (str[0] == 'p')
      a[tot++] = 1;
    else {
      if (str[0] == 'i') a[tot++] = 2;
      n--;
    }
  }
  if (n != 0) {
    printf("Error occurred");
    return 0;
  }
  int m = tot;
  for (int i = 0; i < m; i++) {
    if (a[i] == 1) {
      b[r]--;
      r++;
      b[r] = 2;
      s += "pair<";
    } else {
      b[r]--;
      s += "int";
    }
    while (b[r] == 0) {
      r--;
      s += ">";
    }
    if (b[r] == 1) {
      s += ",";
    }
  }
  if (r != 0 || b[r] != -1) {
    printf("Error occurred");
    return 0;
  }
  cout << s << endl;
  return 0;
}
