Write a program that inputs a sequence of integer numbers in a loop and calculates their sum under the following conditions:
1) if a new number is 0, the program must stop the loop and output the accumulated sum;
2) if the sum is equal to or exceeds the limit of 1000, the program must also stop reading the numbers and output the value equal to the sum minus 1000.
Note: the input can contain extra numbers. Just ignore them.