#include <bits/stdc++.h>
using namespace std;
string ans;
int n;
bool judge() {
  char s[5];
  if (scanf("%s", s) == -1) return false;
  ans += s;
  if (s[0] == 'p') {
    ans += '<';
    if (!judge()) return false;
    ans += ',';
    if (!judge()) return false;
    ans += '>';
  }
  return true;
}
int main() {
  scanf("%d", &n);
  bool ok = judge();
  char s[5];
  if (~scanf("%s", s)) ok = false;
  if (ok)
    cout << ans << endl;
  else
    cout << "Error occurred" << endl;
  return 0;
}
