import java.util.Scanner;
 
 
class Solution {
    static int Answer;
 
    public static void main(String args[]) throws Exception {
         
         
        Scanner sc = new Scanner(System.in);
         
        for(int T=1; T <=10; T++) {
            int size = sc.nextInt();
            int[] inputList = new int[size];
            for(int i=0; i <size ;i++) {
                inputList[i] = sc.nextInt();
            }
             
            // i 번째 조망권 (양옆 2이 배열범위에 벗어나지 않았을 떄 가정)
            int viewCount = 0;
            for(int i=0; i<size ; i++) {
                int left_2 = i-2 >= 0 ? inputList[i-2] : 0;
                int left_1 = i-1 >= 0 ? inputList[i-1] : 0;
                int right_1 = i + 1 < size ? inputList[i+1] : 0;
                int right_2 = i + 2 < size ? inputList[i+2] : 0;
                 
                int max = left_2;
                if(max < left_1) {max = left_1;}
                if(max < right_1) {max = right_1;}
                if(max < right_2) {max = right_2;}
                 
                viewCount += inputList[i] > max ? inputList[i]-max : 0;
            }
             
            System.out.println(String.format("#%d %d", T, viewCount) );
        }
         
    }
}


+ Recent posts