using System;
public class Test
{
public static void Main()
{
String texto = "((1+1)*2) + (10+2) + (((2-1)-1)*1)";
int parenteses = 0;
foreach (char c in texto)
{
if (c.Equals('(')) {
parenteses++;
} else if (c.Equals(')')) {
parenteses--;
}
if (parenteses < 0) {
break;
}
}
Console.WriteLine(parenteses == 0);
}
}
dXNpbmcgU3lzdGVtOwoKcHVibGljIGNsYXNzIFRlc3QKewoJcHVibGljIHN0YXRpYyB2b2lkIE1haW4oKQoJewoJCVN0cmluZyB0ZXh0byA9ICIoKDErMSkqMikgKyAoMTArMikgKyAoKCgyLTEpLTEpKjEpIjsKCQkKCQlpbnQgcGFyZW50ZXNlcyA9IDA7CgkJZm9yZWFjaCAoY2hhciBjIGluIHRleHRvKQoJCXsKCQkJaWYgKGMuRXF1YWxzKCcoJykpIHsKCQkJCXBhcmVudGVzZXMrKzsKCQkJfSBlbHNlIGlmIChjLkVxdWFscygnKScpKSB7CgkJCQlwYXJlbnRlc2VzLS07CgkJCX0KCQkJCgkJCWlmIChwYXJlbnRlc2VzIDwgMCkgewoJCQkJYnJlYWs7CgkJCX0KCQl9CgpDb25zb2xlLldyaXRlTGluZShwYXJlbnRlc2VzID09IDApOwoJfQp9