#include <iostream>
#include <string>

std::string without_brackets(std::string str, char beg = '(', char end = ')') {
	auto last = str.find_last_of(end);
	auto first = str.find_first_of(beg);
	
	if(last != std::string::npos) {
		str.erase(str.begin()+last);
	}
	if(first != std::string::npos) {
		str.erase(str.begin()+first);
	}
	
	return str;
}


using namespace std;

int main() {
	cout << without_brackets("abc)") << endl
	     << without_brackets("(abc") << endl
	     << without_brackets("(abc)") << endl
	     << without_brackets("abc") << endl;
	return 0;
}