#include <bits/stdc++.h>
using namespace std;
string a[111111];
const string err = "Error occurred";
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int x = 0;
  while (cin >> a[x]) {
    x++;
  }
  if (x != 2 * n - 1) {
    cout << err;
    return 0;
  }
  if (n == 1) {
    cout << "int";
    return 0;
  }
  int cp = 0, ci = 0;
  for (int i = 0; i < x; i++) {
    if (ci > cp) {
      cout << err;
      return 0;
    }
    if (a[i] == "int") {
      ci++;
    } else {
      cp++;
    }
  }
  if (cp + 1 != ci) {
    cout << err;
    return 0;
  }
  stack<int> cc;
  stringstream ans;
  for (int i = 0; i < x; i++) {
    if (a[i] == "pair") {
      ans << "pair<";
      if (i == 0 || a[i - 1] == "pair") {
        cc.push(1);
      } else {
        cc.top()++;
      }
    } else {
      ans << "int";
      if (a[i - 1] != "pair") {
        int x = cc.top();
        cc.pop();
        for (int j = 0; j < x; j++) {
          ans << ">";
        }
      }
      ans << ",";
    }
  }
  string s;
  ans >> s;
  cout << s.substr(0, s.length() - 1);
  return 0;
}
