#include <iostream>
#include <string>
#include <stack>
using namespace std;

bool isMatched(const string & A)
{
  stack<char> s;
  for (char a: A)
  {
    if (a == '(' || a == '[' || a == '{')
    {
      s.push(a);
    }
    else if (a == ')')
    {
      if (s.empty() || s.top() != '(')
	return false;
      s.pop();
    }
    else if (a == ']' || a == '}')
    {
      if (s.empty() || s.top() + 2 != a)
	return false;
      s.pop();
    }
  }
  return s.empty();
}

int main()
{
  cout << isMatched("(()[{}])") << endl;
  cout << isMatched("([)]") << endl;
  return 0;

}
