#include <iostream>
#include <string>
#include <list>
#include <algorithm>
#include <iterator>

using namespace std;

list<string> bracesExpressionExamples = {
	"({[{}]{}[]})",
	"({}}{[{}]{}[]})",
	"({[{}]{}[]}",
	"({[{}]{}]})",
	"({[{}{}[]})",
	"",
	"{}"
};

bool is_balanced(std::string s) {
	int counts[3] = {0};
	for (char ch : s) {
		switch (ch) {
			case '(': counts[0]++; break;
			case ')': counts[0]--; break;
			case '[': counts[1]++; break;
			case ']': counts[1]--; break;
			case '{': counts[2]++; break;
			case '}': counts[2]--; break;
			default: break;
		}
	}
	return counts[0] + counts[1] + counts[2] == 0;
}

int main(int, char**) {
	cout << boolalpha;
	transform(bracesExpressionExamples.begin(),
		bracesExpressionExamples.end(),
		ostream_iterator<bool>(cout, "\n"),
		is_balanced);
	return 0;
}
