Problem: 2062C - Cirno and Operations
Language: java

Solution 1 (runtime: 343 ms):
import java.util.*;
public class CF_1001_3 {
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int t=sc.nextInt();
        while(t-->0){
            int n=sc.nextInt();
            ArrayList<Long> list=new ArrayList<>();
            long sum=0;
            long max=Long.MIN_VALUE;
            for(int i=0;i<n;i++){
                list.add((long) sc.nextInt());
                sum+=list.get(i);
            }
            max=Math.max(max,sum);
            for(int i=0;i<n-1;i++){
                long sum1=0;
                ArrayList<Long> temp1=new ArrayList<>();
                for(int j=1;j<list.size();j++){
                    temp1.add(list.get(j)-list.get(j-1));
                    sum1+=list.get(j)-list.get(j-1);
                }
                long sum2=0;
                Collections.reverse(list);
                ArrayList<Long> temp2=new ArrayList<>();
                for(int j=1;j<list.size();j++){
                    temp2.add(list.get(j)-list.get(j-1));
                    sum2+=list.get(j)-list.get(j-1);
                }
                list.clear();
                if(sum1>sum2){
                    max=Math.max(max,sum1);
                    for(int j=0;j<temp1.size();j++){
                        list.add(temp1.get(j));
                    }
                }else{
                    max=Math.max(max,sum2);
                    for(int j=0;j<temp2.size();j++){
                        list.add(temp2.get(j));
                    }
                }
            }
            System.out.println(max);

        }
    }
}


Solution 2 (runtime: 234 ms):
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static StringTokenizer st;

    public static String next() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    public static int nextLong() throws IOException {
        return Integer.parseInt(next());
    }

    public static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    public static void main(String[] args) throws IOException {
        int t = nextInt();
        while (t-- > 0) {
            run();
        }
    }

    public static void run() throws IOException {
        int n = nextInt();
        long[] arr = new long[n];
        int new_len = n;
        for(int i = 0;i<n;i++){
            arr[i] = nextLong();
        }
        long min = Long.MIN_VALUE;
        for(int i = 0;i<n;i++){
            long sum = 0;
            for(int j=0;j<new_len;j++){
                sum+=arr[j];
            }
            if(i==0){
                min = Math.max(min,sum);
            }
            else{
                min = Math.max(min,Math.max(sum,-sum));
            }
            for(int j = 0;j<n-1;j++){
                arr[j] = arr[j+1]-arr[j];
            }
            new_len--;
        }
        System.out.println(min);
    }
}