#include <bits/stdc++.h>
using namespace std;
const int N = 100 * 1000 + 85;
vector<int> s;
string o;
int n, sz;
int solve(int i) {
  if (i >= n) {
    cout << "Error occurred" << endl;
    exit(0);
  }
  if (s[i] == 2) {
    o += "pair";
    o += "<";
    int it = solve(i + 1);
    o += ",";
    it = solve(it);
    o += ">";
    return it;
  } else {
    o += "int";
    return i + 1;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  string t;
  while (cin >> t) {
    if (t == "int")
      s.push_back(1);
    else
      s.push_back(2);
  }
  n = s.size();
  if (solve(0) <= n - 1)
    cout << "Error occurred" << endl;
  else
    cout << o << endl;
}
