Problem: 2062C - Cirno and Operations
Language: java

Solution 1 (runtime: 218 ms):
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Olynpiade3 {
    static FastScanner scan = new FastScanner(new InputStreamReader(System.in));
    public static void main(String[] args) {
        int t = scan.nextInt();
        for (int i = 0; i < t; i++)
            solve();
    }
    static void solve(){
        int n = scan.nextInt();
        long[] posl = new long[n];
        posl[0] = scan.nextInt();
        int pos;
        long sum1 = 0, sum2 = 0, max = posl[0];
        for (int i = 1; i < n; i++){
            posl[i] = scan.nextInt();
            max += posl[i];
            sum1 += posl[i] - posl[i-1];
            sum2 += posl[i-1] - posl[i];
        }
        //System.out.println(Arrays.toString(posl) + " " + sum1 + " " + sum2 + " " + max);
        int znak;
        long sum;
        for (int i = 0; i < n - 1; i++){
            pos = 1;
            if (sum1 > sum2){
                znak = 1;
            }else
                znak = -1;
            posl[0] = (long) znak * (posl[1] - posl[0]);
            sum1 = 0; sum2 = 0; sum = posl[0];
            if (n - 1 >= 2)
                while (pos != n - i - 1){
                    pos++;
                    posl[pos - 1] = (long) znak * (posl[pos] - posl[pos-1]);
                    sum += posl[pos - 1];
                    sum1 += posl[pos - 1] - posl[pos - 2];
                    sum2 += posl[pos - 2] - posl[pos - 1];
                    //System.out.println(Arrays.toString(posl));
                }

            if (sum > max)
                max = sum;
            //System.out.println(Arrays.toString(posl));
        }
        System.out.println(max);
    }
}


class FastScanner

{

    private BufferedReader br;

    private StringTokenizer st;



    public FastScanner(InputStreamReader reader)

    {

        br = new BufferedReader(reader);

    }



    public String next()

    {

        while (st == null || !st.hasMoreTokens())

        {

            try

            {

                st = new StringTokenizer(br.readLine());

            } catch (Exception e)

            {

                e.printStackTrace();

            }

        }

        return st.nextToken();

    }



    public int nextInt()

    {

        return Integer.parseInt(next());

    }



    public double nextDouble()

    {

        return Double.parseDouble(next());

    }



    public void close() throws Exception

    {

        br.close();

    }

}

Solution 2 (runtime: 155 ms):
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {


    public static void main(String[] args) {
        int t=1;
        Scanner sc = new Scanner(System.in);
        t=sc.nextInt();
        while(t-->0){
            int n=sc.nextInt();
            long[] arr=new long[n];
            long ans=0;
            for(int i=0;i<n;i++){
                arr[i]=sc.nextInt();
                ans+=arr[i];
            }

            while(n>1){
                ans=Math.max(ans,Math.abs(arr[n-1]-arr[0]));
                for (int i = 0; i < n-1; i++) {
                    arr[i]=arr[i+1]-arr[i];
                }
                n--;
            }
            System.out.println(ans);
        }
    }
}