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