#include <bits/stdc++.h>
using namespace std;
string s, z;
int t;
void dfs() {
  if (cin >> s) {
    z += s;
    if (s == "pair") {
      z += "<";
      dfs();
      z += ",";
      dfs();
      z += ">";
    }
  } else
    t = 1;
}
int main() {
  cin >> s;
  dfs();
  if (t || cin >> s) {
    cout << "Error occurred";
    return 0;
  } else {
    cout << z;
  }
  return 0;
}
