#include <bits/stdc++.h>
using namespace std;
string s, ans;
int cnt;
int solve() {
  if (cin >> s) {
    ans += s;
    if (s == "pair") {
      ans += '<';
      solve();
      ans += ',';
      solve();
      ans += '>';
    } else {
      cnt++;
    }
  } else {
    cout << "Error occurred";
    exit(0);
  }
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  int n;
  cin >> n;
  solve();
  if (n == cnt && !(cin >> s)) {
    cout << ans;
  } else {
    cout << "Error occurred";
  }
  exit(EXIT_SUCCESS);
}
