Improved version of codeforces 475b based on a simple property.