Problem: 2062C - Cirno and Operations
Language: java

Solution 1 (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;
        }
    }
}


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());
		}
	}
}