solution for Theatres Square. url: http://codeforces.com/problemset/problem/1/A