#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK: 102400000, 1024000")
char s[100000000];
bool a[10000005];
string ans = "";
int num = 0;
int n = 0;
int dfs(int pos) {
  if (a[pos]) {
    ans += "pair<";
    pos = dfs(pos + 1);
    ans += ",";
    pos = dfs(pos);
    ans += ">";
    return pos;
  } else {
    ans += "int";
    return pos + 1;
  }
}
int main() {
  scanf("%d\n", &n);
  gets(s);
  int len = strlen(s);
  for (int i = 0; i < len;) {
    if (s[i] == 'p') {
      a[num++] = true;
      i += 5;
    } else if (s[i] == 'i') {
      a[num++] = false;
      i += 4;
    }
  }
  if (dfs(0) == num) {
    cout << ans << endl;
  } else {
    printf("Error occurred\n");
  }
  return 0;
}
