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: 140 ms):
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) throws IOException {
        InputReader scan = new InputReader(System.in);
        PrintWriter pw = new PrintWriter(System.out);

        int t = scan.nextInt();
        while (t --> 0) {
            int n = scan.nextInt();
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = scan.nextLong();
            }

            long maxSum = 0;
            for (int i = 0; i < n; i++) {
                maxSum += a[i];
            }

            for (int i = 0; i < n-1; i++) {
                long sum = 0;
                for (int j = 0; j < n-i-1; j++) {
                    a[j] = a[j+1] - a[j];
                    sum += a[j];
                }
                maxSum = Math.max(maxSum, Math.abs(sum));
            }

            pw.println(maxSum);
        }

        pw.close();
    }
    static class InputReader {

        private final InputStream stream;
        private final byte[] buf = new byte[8192];
        private int curChar, snumChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int snext() {
            if (snumChars == -1)
                throw new InputMismatchException();
            if (curChar >= snumChars) {
                curChar = 0;
                try {
                    snumChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (snumChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long nextLong() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public int[] nextIntArray(int n) {
            int a[] = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public String readString() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = snext();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }
}