#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  while (cin >> n) {
    string s;
    getline(cin, s);
    getline(cin, s);
    stringstream ss(s);
    string token;
    string res = "";
    vector<int> numelements;
    bool error = 0;
    if (s == "int") {
      cout << "int" << endl;
      continue;
    }
    while (ss >> token) {
      int cur = numelements.size() - 1;
      if (cur >= 0 && numelements[cur] == 1) res += ",";
      if (token == "pair") {
        if (cur >= 0) {
          numelements[cur]++;
          if (numelements[cur] >= 3) {
            error = 1;
            break;
          }
        }
        res += "pair<";
        numelements.push_back(0);
      } else if (token == "int") {
        if (cur < 0) {
          error = 1;
          break;
        }
        numelements[cur]++;
        res += "int";
        if (numelements[cur] >= 3) {
          error = 1;
          break;
        }
        while (numelements.size() > 0 &&
               numelements[numelements.size() - 1] == 2) {
          numelements.erase(numelements.end() - 1);
          res += ">";
        }
      }
    }
    if (numelements.size() > 0) error = 1;
    if (error)
      cout << "Error occurred" << endl;
    else
      cout << res << endl;
  }
}
