Олимпиадный тренинг

Задача 38709. Will we save Libank


Libank International Bank has N branches around the world. After the end of the coronovirus pandemic, the financial department of the bank decided to check the accounts of all branches. It turned out that some branches remained in debt, and some even managed to make a profit. Now the CFOs have decided to bail out all branches with minimal equal debt. They want to see if all their debts can be covered by using the funds of all branches with a minimum equal profit. You, as an employee of the IT department, have been given this task. CFOs are waiting for your response!

Input
The first line contains the number N (2<=N<=500) - the number of branches of Libank. The second line contains N numbers a(-1000<=ai<=1000, 0<=i<N) - positive numbers denote profits of departments, negative - debts. It is known that at least one branch of Libank made a profit and at least one branch remained in debt.

Imprint
If all the specified branches can be salvaged, display the amount that will remain after paying off all the debts of the branches with the minimum equal debt. If it is impossible to save, print a negative number showing how much money is missing.
 
Examples
# Input Output
1 10
-1 4 -10 0 -8 -1 -8 8 -2 8 
2

Запрещенные операторы:sort;min;max