div2 1000 is usually lengthy to code but some brute force approach works well enough