#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", 3, "inline")
using namespace std;
string s, t;
int n;
void pairr() {
  if (cin >> t) {
    s += t;
    if (t == "pair") s += '<', pairr(), s += ',', pairr(), s += '>';
  } else {
    cout << "Error occurred";
    exit(0);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  pairr();
  if (cin >> t) {
    cout << "Error occurred";
    return 0;
  }
  cout << s;
  return 0;
}
