#include <bits/stdc++.h>
using namespace std;
int n;
bool benar;
string ans, st;
int main() {
  scanf("%d", &n);
  vector<string> data;
  while (cin >> st) data.push_back(st);
  if (data[0] == "int") {
    if (data.size() == 1)
      printf("%s\n", data[0].c_str());
    else
      printf("Error occurred\n");
  } else {
    vector<int> q;
    q.push_back(0);
    benar = true;
    ans = "pair<";
    for (int i = 1; i < data.size(); i++) {
      if (data[i] == "pair") {
        if (q.size() == 0) {
          benar = false;
          break;
        }
        ans += "pair<";
        q[q.size() - 1]++;
        q.push_back(0);
      } else {
        if (q.size() == 0) {
          benar = false;
          break;
        }
        ans += "int";
        q[q.size() - 1]++;
        while (q.size()) {
          if (q[q.size() - 1] == 2) {
            ans += ">";
            q.pop_back();
          } else
            break;
        }
        if (q.size())
          if (q[q.size() - 1] == 1) ans += ",";
      }
    }
    if (q.size()) benar = false;
    if (benar)
      printf("%s\n", ans.c_str());
    else
      printf("Error occurred\n");
  }
}
