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: 311 ms):

import java.util.Scanner;

public class Sol {
    static Scanner rd = new Scanner(System.in);
    public static void main(String[] args) {
        int tt = rd.nextInt();
        while (tt-- > 0) {
            new Solution().solve();
        }
    }

    static class Solution {
        void solve() {
            int n = rd.nextInt();
            long[] a = new long[n];

            for (int i = 0; i < n; i++) {
                a[i] = rd.nextInt();
            }
            int len = n;
            if (len == 1) {
                System.out.println(a[0]);
                return;
            }
            long max = getSum(a, n, false);
            while (len > 1) {
                for (int i = 0; i < len - 1; i++) {
                    a[i] = a[i + 1] - a[i];
                }
                len--;
                max = Math.max(Math.max(getSum(a, len, true), getSum(a, len, false)), max);
            }
            System.out.println(max);
        }

        long getSum(long[] a, int len, boolean neg) {
            long sum = 0;
            for (int i = 0; i < len; i++) {
                if (neg) {
                    sum += (-1) * a[i];
                } else {
                    sum += a[i];
                }
            }
            return sum;
        }
    }
}