O(logn*n+n) solution
Merge branch 'master' of https://github.com/danys/UVa