#include <bits/stdc++.h>
using namespace std;
int main() {
  int k;
  scanf("%d\n", &k);
  char s[555555], res[555555];
  int st[555555], cnt = 0;
  gets(s);
  int n = 0;
  bool ok = false;
  int l = strlen(s);
  s[l] = ' ';
  s[l + 1] = '\0';
  l = strlen(s);
  for (int i = 0; i < l; i++)
    if (s[i] == ' ') {
      if (s[i - 1] == 't') {
        if (st[cnt] == 1) {
          while (cnt > 0 && st[cnt] == 1) {
            res[n++] = '>';
            cnt--;
          }
          if (cnt > 0) {
            st[cnt]++;
            res[n++] = ',';
          } else if (i < l - 1) {
            cout << "Error occurred" << endl;
            return 0;
          }
        } else {
          if (cnt == 0 && k != 1) {
            cout << "Error occurred" << endl;
            return 0;
          }
          st[cnt]++;
          if (k != 1) res[n++] = ',';
        }
      } else {
        res[n++] = '<';
        cnt++;
        st[cnt] = 0;
      }
    } else
      res[n++] = s[i];
  res[n] = '\0';
  if (cnt > 0)
    cout << "Error occurred" << endl;
  else
    cout << res;
  return 0;
}
