#include <bits/stdc++.h>
using namespace std;
int n;
string s;
stringstream ss;
pair<int, int> res[100005];
bool isp[100005];
void prt(int i) {
  if (res[i].first < 0) {
    cout << "int";
  } else {
    cout << "pair<";
    prt(res[i].first);
    cout << ',';
    prt(res[i].second);
    cout << '>';
  }
}
int main() {
  getline(cin, s);
  getline(cin, s);
  ss << s;
  for (n = 0; !ss.eof(); n++) {
    ss >> s;
    if (s == "pair") {
      isp[n] = true;
    }
  }
  vector<int> v;
  for (int i = n - 1; i >= 0; i--) {
    if (isp[i]) {
      if (v.size() < 2) {
        cout << "Error occurred" << endl;
        return 0;
      }
      res[i] = pair<int, int>(0, 0);
      res[i].first = v.back();
      v.pop_back();
      res[i].second = v.back();
      v.pop_back();
    } else {
      res[i] = pair<int, int>(-1, -1);
    }
    v.push_back(i);
  }
  if (v.size() > 1) {
    cout << "Error occurred" << endl;
    return 0;
  }
  prt(0);
  return 0;
}
