Created
          December 31, 2019 16:35 
        
      - 
      
- 
        Save dalcon10028/76e23bc97e7d411e1c4d5d3eb85b93f4 to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import java.util.*; | |
| public class Main { | |
| public static void main(String[] args) { | |
| Scanner sc = new Scanner(System.in); | |
| int K = sc.nextInt(); | |
| Stack<Integer> stack = new Stack<>(); | |
| for(int i=0; i<K; i++){ | |
| int input = sc.nextInt(); | |
| if(input==0) stack.pop(); | |
| else stack.push(input); | |
| } | |
| sc.close(); | |
| int sum = 0; | |
| for (Integer i : stack) | |
| sum+=i; | |
| System.out.print(sum); | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment