#include <bits/stdc++.h>
using namespace std;
const int INF = 100005;
string s;
int cnt;
int arr[INF];
vector<int> v;
pair<int, int> p[INF];
void print(int n) {
  if (arr[n]) {
    printf("pair<");
    print(p[n].first);
    printf(",");
    print(p[n].second);
    printf(">");
  } else
    printf("int");
}
int main() {
  getline(cin, s);
  getline(cin, s);
  for (int i = 0; i < s.size() - 3; i++) {
    if (s[i] == 'p' && s[i + 1] == 'a') arr[cnt] = 1;
    if (s[i] == ' ') cnt++;
  }
  for (int i = cnt; i >= 0; i--) {
    p[i] = make_pair(0, 0);
    if (arr[i]) {
      if (v.size() < 2) {
        puts("Error occurred");
        return 0;
      }
      int ki = v.back();
      v.pop_back();
      int kj = v.back();
      v.pop_back();
      p[i] = make_pair(ki, kj);
    } else
      p[i] = make_pair(-1, -1);
    v.push_back(i);
  }
  if (v.size() > 1) {
    puts("Error occurred");
    return 0;
  }
  print(0);
  puts("");
  return 0;
}
