Chandan is an extremely biased person, and he dislikes people who fail to solve all the problems in the interview he takes for hiring people. There are n people on a day who came to be interviewed by Chandan. Chandan rates every candidate from 0 to 10. He has to output the total ratings of all the people who came in a day. But, heres the problem: Chandan gets extremely frustrated when someone ends up scoring a 0 in the interview. So in frustration he ends up removing the candidate who scored that 0, and also removes the candidate who came before him. If there is no candidate before the one who scores a 0, he does nothing.Youve to find the summation of all the ratings in a day for Chandan. Input constraints: The first line of input will contain an integer n. The next n lines will contain an integer, where the ith integer represents the rating of the ith person. Output constraints: Print the required sum. Constraints: 1 <= n <= 5 * 103 0 <= Value of ratings <=10 Test Case 1 Input (stdin) 5 2 3 0 7 0 Expected Output 2 Test Case 2 Input (stdin) 4 4 3 7 6 Expected Output 20

#include<stdio.h>

#define SIZEN 5003

int main()

{

int N, rating[SIZEN];

int i, j, total;

//freopen("input.txt", "r", stdin);

scanf("%d", &N);

for (i = 0; i < N; i++) {

scanf("%d", &rating[i]);

if (0 == rating[i]) for (j = i - 1; j >= 0; j--) if (rating[j]) {

rating[j] = 0;

break;

}

}

total = 0;

for (i = 0; i < N; i++)

total += rating[i];

printf("%d\n", total);

return 0;

}