open $in, '<', "shortest-accepted.in"; <>;
while(<>){
s/\$+/()/g;
1 while 0
|| s/ \w \*+ //x
|| s/ (?> (?<![)*]) (\w*) \
| (\w*) ) (?![(]) / $capture_1 = $1, $capture_2 = $2,
(
)[0]
/xe
|| s/\( (\w*) \) \*+ //x
|| s/\( (\w*) \) /$1/x ;
}
b3BlbiAkaW4sICc8JywgInNob3J0ZXN0LWFjY2VwdGVkLmluIjsKPD47CndoaWxlKDw+KXsKCWNob21wOwoJcy9cJCsvKCkvZzsKCQoJMSB3aGlsZSAwCgl8fCBzLyBcdyBcKisgLy94Cgl8fCBzLyAoPz4gKD88IVspKl0pIChcdyopIFx8IChcdyopICkgKD8hWyhdKSAvIAoJCSRjYXB0dXJlXzEgPSAkMSwgJGNhcHR1cmVfMiA9ICQyLCAKCQkoCgkJc29ydCB7IChsZW5ndGggJGEpIDw9PiAobGVuZ3RoICRiKSB8fCAkYSBjbXAgJGIgfSAoICRjYXB0dXJlXzEsICRjYXB0dXJlXzIgKSAKCQkpWzBdCgkJL3hlCgl8fCBzL1woIChcdyopIFwpIFwqKyAvL3gKCXx8IHMvXCggKFx3KikgXCkgLyQxL3ggOwoJCgkobGVuZ3RoKSBvciAkXyA9IHEoJCk7CglwcmludCAkXywgIlxuIgoJfQ==
MwooKSgpKioqKgooKCgpKSoqKmJifGFhKQooKGEqKiopKSoKKGEpKGEqKmIqKiopCmEqfGIqCihhYWEpKGJiKXwoYyhkZCkpCihhYWFhYXxiYmJiYillZXxjY2NjY2MKKGF8JCkKKGFhfGJiYnxjY2MpCih8KQooJCQkJCQkKWFhfGJiYihhJGJiJGNjYyQqJCokYSphYWEqYmIqKQoofCgpKCkoKSp8fCkKKChiYmIkfCQqKXwkYmIpCigpYXxiYnxjY2N8KGF8YikKKGEoYihjKGR8ZSkpKSkKYQphYnxhYyooY2F8Y2IpCigoYWJ8YWMpYSkqCmFiYWJhYmNjY2MKYWIqYSphKmEqY2NjKmIqCihhfGNiKWEoYmJifGNiKQooYWF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