Problem: 2062C - Cirno and Operations
Language: java

Solution 1 (runtime: 312 ms):
// package main;
import java.util.Scanner;
import java.io.PrintWriter;
import java.util.List;
import java.util.ArrayList;


// 100 * 50

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int t = scanner.nextInt();
        for (int i = 0; i < t; i++) {
            int n = scanner.nextInt();
            List<Long> ar = new ArrayList<>();

            for (int j = 0; j < n; j++) {
                ar.add(scanner.nextLong());
            }

            long res = sum(ar);

            while (ar.size() > 1) {
                res = Math.max(res, sum(ar));

                List<Long> newAr = new ArrayList<>();
                for (int j = 1; j < ar.size(); j++) {
                    newAr.add(ar.get(j) - ar.get(j - 1));
                }
                res = Math.max(res, Math.abs(sum(newAr)));
                ar = newAr;
            }
            out.println(res);
        }
        out.flush();
        out.close();
        scanner.close();
    }

    private static long sum(List<Long> ar) {
        long sum = 0;
        for (long a : ar) {
            sum += a;
        }
        return sum;
    }
}


Solution 2 (runtime: 249 ms):
import java.util.*;
import java.io.*;
import java.math.*;

public class sub {

	// can i get expert by summer please

	static int mod = 998244353;

	public static void main(String args[]) throws IOException {
		int t = sc.nextInt();
		while (t-- > 0) {
			int n = sc.nextInt();
			ArrayList<Long> a = new ArrayList();
			if (n == 1) {
				out.println(sc.nextInt());
			} else {
				long ans = 0;
				for (int i = 0; i < n; i++) {
					a.add(sc.nextLong());
					ans+=a.get(i);
				}
				for (int i = 1; i < n; i++) {
					ArrayList<Long> copy = new ArrayList();
					for(int j = 0;j<a.size()-1;j++) {
						copy.add(a.get(j) - a.get(j + 1));
					}
					a=copy;
					long sum = 0;
					for (int j = 0; j < a.size(); j++) {
						sum += a.get(j);
					}
					if(sum<0) {
						Collections.reverse(a);
					}
					
					ans=Math.max(ans,Math.abs(sum));
				}
				out.println(ans);
			}
		}
		out.close();
	}

//	static long bincoef(int n, int k) {
//	    if (n < k) return 0L;
//	    return (p[n] * pow((p[n - k] * p[k]) % mod, mod - 2, mod)) % mod;
//	}

	static long pow(long a, long b, long mod) {
		if (b == 0) {
			return 1L;
		}
		long val = pow(a, b / 2, mod);
		if (b % 2 == 0) {
			return val * val % mod;
		}
		return val * val % mod * a % mod;
	}

	static long gcd(long a, long b) {
		if (b == 0) {
			return a;
		}
		return gcd(b, a % b);
	}

	static long lcm(long a, long b) {
		return a * b / gcd(a, b);
	}

	static Kattio sc = new Kattio();
	static PrintWriter out = new PrintWriter(System.out);

	static class Kattio {

		static BufferedReader r;
		static StringTokenizer st;

		public Kattio() {
			r = new BufferedReader(new InputStreamReader(System.in));
		}

		public String next() {
			try {
				while (st == null || !st.hasMoreTokens()) {
					st = new StringTokenizer(r.readLine());
				}
				return st.nextToken();
			} catch (Exception e) {
				return null;
			}
		}

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

		public long nextLong() {
			return Long.parseLong(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}
	}
}