#include <bits/stdc++.h>
using namespace std;
double eps = 1e-9;
const int INF = 1e9 + 7;
const int MAXN = int(2e5 + 7);
int n;
string second;
void go() {
  string t;
  if (!(cin >> t)) {
    cout << "Error occurred";
    exit(0);
  }
  if (t[0] == 'i') {
    second += t;
    return;
  }
  second += "pair<";
  go();
  second += ",";
  go();
  second += ">";
}
int main() {
  cin >> n;
  go();
  for (int i = 0; i < second.size(); i++)
    if (second[i] == 'n') n--;
  string t;
  if (!n && !(cin >> t))
    cout << second;
  else
    cout << "Error occurred";
  return 0;
}
