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

using namespace std;

int main() {
	const auto foo = "this (is(maybe)) a test (and maybe not)"s;
	const auto start = find(cbegin(foo), cend(foo), '(');
	const auto finish = find_if(start, cend(foo), [count = 0](const char i) mutable {
	    if (i == '('){
	        count++;
	    }
	    else if (i == ')'){
	        count--;
	    }
	    return count <= 0; });
	
	if(start == cend(foo)) {
		cout << "No '(' character found\n";
	} else if(finish == cend(foo)) {
		cout << "Even number of ')'s found\n";
	} else {
		cout << string(next(start), finish) << endl;
	}
}