#include <bits/stdc++.h>
using namespace std;
vector<char> p, ans;
int add(string s) {
  if (s == "int") {
    if (p.size() == 0) {
      cout << "Error occurred";
      return 0;
    }
    if (p[p.size() - 1] == 1 && ans.size()) ans.push_back(2);
    p[p.size() - 1]--;
    ans.push_back(1);
    if (p[p.size() - 1] == 0)
      while (p.size() > 0 && p[p.size() - 1] == 0) {
        ans.push_back(3);
        p.pop_back();
      }
  } else {
    if (p.size() == 0) {
      cout << "Error occurred";
      return 0;
    }
    if (p[p.size() - 1] == 1 && ans.size()) ans.push_back(2);
    p[p.size() - 1]--;
    ans.push_back(0);
    p.push_back(2);
  }
  return 1;
}
int main() {
  p.push_back(1);
  string l, w = "";
  getline(cin, l);
  getline(cin, l);
  for (int i = 0; i < l.size(); i++)
    if (l[i] == ' ') {
      if (add(w) == 0) return 0;
      w = "";
    } else
      w += l[i];
  if (add(w) == 0) return 0;
  if (p.size() > 0)
    cout << "Error occurred";
  else
    for (int i = 0; i < ans.size() - 1; i++)
      if (ans[i] == 0)
        cout << "pair<";
      else if (ans[i] == 1)
        cout << "int";
      else if (ans[i] == 2)
        cout << ",";
      else if (ans[i] == 3)
        cout << ">";
}
