#include <bits/stdc++.h>
std::vector<std::string> aWords;
std::string ans = "";
int iCurrentPos = 0;
void GetType() {
  if (iCurrentPos >= (int)aWords.size()) {
    std::cout << "Error occurred" << std::endl;
    exit(0);
  }
  if (aWords[iCurrentPos] == "int") {
    ans += aWords[iCurrentPos];
    iCurrentPos++;
    return;
  }
  iCurrentPos++;
  ans += "pair<";
  GetType();
  ans.push_back(',');
  GetType();
  ans.push_back('>');
}
int main() {
  std::ios_base::sync_with_stdio(0);
  std::string str, splited;
  std::getline(std::cin, str);
  std::getline(std::cin, str);
  std::stringstream ss(str);
  while (std::getline(ss, splited, ' ')) {
    aWords.push_back(splited);
  }
  GetType();
  if (iCurrentPos == (int)aWords.size())
    std::cout << ans << std::endl;
  else
    std::cout << "Error occurred" << std::endl;
  return 0;
}
