#include <bits/stdc++.h>
using namespace std;
string s, ans;
bool solve() {
  if (cin >> s) {
    ans += s;
    if (s[0] == 'p') {
      ans += '<';
      if (!solve()) return false;
      ans += ',';
      if (!solve()) return false;
      ans += '>';
    }
    return true;
  }
  return false;
}
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  bool f = solve();
  if ((cin >> s) || !f)
    cout << "Error occurred" << endl;
  else
    cout << ans << endl;
  return 0;
}
