#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
string ans = "", s;
bool err = false;
void bt() {
  if (!(cin >> s)) {
    err = true;
    return;
  }
  ans += s;
  if (s == "pair") {
    ans += '<';
    bt();
    ans += ',';
    bt();
    ans += '>';
  }
}
int main() {
  cin >> s;
  bt();
  if (err || cin >> s) {
    cout << "Error occurred" << endl;
  } else {
    puts(ans.c_str());
  }
  return 0;
}
