Solution for Spread Sheets. URL: http://codeforces.com/contest/1/problem/B