#include <bits/stdc++.h>
using namespace std;
long long int MOD = 998244353;
long long int mod = 1e9 + 7;
long long int INF = 1e18;
long long int dx[] = {1, -1, 0, 0};
long long int dy[] = {0, 0, 1, -1};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n;
  cin >> n;
  string c;
  getline(cin, c);
  getline(cin, c);
  vector<string> s;
  string tmp = "";
  long long int a = 0, b = 0;
  for (auto j : c) {
    if (j == ' ') {
      if (tmp == "pair")
        a++;
      else
        b++;
      s.push_back(tmp);
      tmp = "";
    } else
      tmp = tmp + j;
  }
  if (tmp == "pair")
    a++;
  else
    b++;
  s.push_back(tmp);
  if (b != n) {
    cout << "Error occurred";
    return 0;
  }
  n = s.size();
  if (s[0] == "int") {
    if (n == 1)
      cout << s[0];
    else
      cout << "Error occurred";
    return 0;
  }
  stack<long long int> st;
  for (int i = 0; i < n; i++) {
    if (s[i] == "pair") {
      if (st.empty())
        st.push(2);
      else {
        st.top()--;
        if (st.top() == 0) st.pop();
        st.push(2);
      }
    } else {
      if (st.empty()) {
        cout << "Error occurred";
        return 0;
      } else {
        st.top()--;
        if (st.top() == 0) st.pop();
      }
    }
  }
  if (!st.empty()) {
    cout << "Error occurred";
    return 0;
  }
  for (int i = 0; i < n; i++) {
    cout << s[i];
    if (s[i] == "pair") {
      cout << "<";
      st.push(2);
    } else {
      while (!st.empty()) {
        st.top()--;
        if (st.top() == 1) {
          cout << ",";
          break;
        } else {
          cout << ">";
          st.pop();
        }
      }
    }
  }
  return 0;
}
