#include <bits/stdc++.h>
using namespace std;
const int maxP = 2e5 + 10;
int n, p, ind;
string s, res = "";
bool a[maxP];
void dfs() {
  p--;
  if (a[ind++] == 1) {
    res += "pair<";
    dfs();
    res += ",";
    dfs();
    res += ">";
  } else
    res += "int";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (p = 0; cin >> s; p++) {
    if (s == "pair")
      a[p] = 1;
    else
      a[p] = 0;
  }
  dfs();
  if (p)
    cout << "Error occurred" << endl;
  else
    cout << res << endl;
  return 0;
}
