#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
int n, k = 0;
string s;
string res;
bool flag = false;
void input() {
  if (flag) return;
  if (cin >> s) {
    res += s;
    if (s == "pair") {
      res += "<";
      input();
      res += ",";
      input();
      res += ">";
    }
  } else {
    flag = true;
    puts("Error occurred");
    return;
  }
}
int main() {
  cin >> n;
  input();
  if (flag) return 0;
  if (cin >> s)
    puts("Error occurred");
  else {
    if (!flag) cout << res << endl;
  }
  return 0;
}
