#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1005;
const int MOD = 1000000007;
int n;
vector<string> g;
string r = "";
void read() {
  cin >> n;
  string s;
  while (cin >> s) g.push_back(s);
}
int a;
int fl = 1;
void dfs() {
  if (a >= g.size()) {
    fl = 0;
    return;
  }
  if (g[a] == "int") {
    a++;
    r += "int";
    return;
  }
  a++;
  r += "pair<";
  dfs();
  r += ",";
  dfs();
  r += ">";
}
void solve() {
  dfs();
  if (fl && a == g.size())
    cout << r << '\n';
  else
    cout << "Error occurred" << '\n';
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  read();
  solve();
  return 0;
}
