#include <bits/stdc++.h>
using namespace std;
const long long mod1 = 998244353;
const long long mod2 = 1000000007;
string s, ans;
bool v;
void kill() {
  cout << ("Error occurred") << endl;
  exit(0);
}
void dfs() {
  if (cin >> s) {
    ans += s;
    if (s == "pair") {
      ans += "<";
      dfs();
      ans += ",";
      dfs();
      ans += ">";
    }
  } else {
    kill();
  }
}
int main() {
  cin >> s;
  dfs();
  if (cin >> s) kill();
  cout << (ans) << endl;
  return 0;
}
