Rahul and Jim take turns to pick candies from a bag. Rahul picks 1 candy, Jim picks 2 candies, Rahul 3, Jim 4 and so forth. After a while there are too few candies to continue and so the boy whose turn it is takes all the remaining candies. When all the candies are picked, Rahul has 1012 candies in total. What was the original number of candies in the bag?