#include <stdio.h>

int main() {
    int n, soma=0;
    scanf("%d", &n);

    int v[n];

    for(int i=0; i<n; i++){
        scanf("%d", &v[i]);
    }
    for(int i=1; i<n; i++){
        if(v[i]==0){
            for(int j=i-1;j>=0; j--){
                if(v[j] != 0){
                    v[j] = 0;
                    break;
                }
            }
        }
    }
    for(int i=0; i<n; i++){
        soma = soma+v[i];
    }
    printf("%d", soma);
    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: