Problem: 2062C - Cirno and Operations
Language: java

Solution 1 (runtime: 155 ms):
import java.io.*;
import java.util.*;

public class Code {

    // Input and Output
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static PrintWriter out = new PrintWriter(System.out);

    // For parsing integers, longs, and strings efficiently
    static StringTokenizer st;

    // Entry point
    public static void main(String[] args) throws IOException {
        int t; // Number of test cases
        t = nextInt(); // Uncomment this line if multiple test cases
        while (t-- > 0) {
            solve(); // Call the solve function for each test case
        }
        out.close(); // Close the output stream
    }

    // Solve function for each test case

    static void solve() throws IOException {
        int n = nextInt();
        long[] arr = new long[n];

        for(int i=0;i<n;i++){
            arr[i] = nextLong();
        }

        int now = n;
        long ans = Long.MIN_VALUE;

        for(int i=0;i<n;i++) {
            long sum = 0L;
            for (int j = 0; j < now; j++) {
                sum += arr[j];
            }

            if(i==0){
                ans = Math.max(ans, sum);
            }
            else{
                ans = Math.max(ans, Math.abs(sum));
            }

            for(int j = 0;j<now-1;j++){
                arr[j] = arr[j+1] - arr[j];
            }
            now--;
        }

        out.println(ans);
    }

    // Utility methods for faster input
    static String next() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    static long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    static double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

    char nextChar() {
        try {
            return (char) br.read();
        } catch (IOException e) {
            e.printStackTrace();
            return '\0'; // Return null character in case of an error
        }
    }

    static String nextLine() throws IOException {
        return br.readLine();
    }

    // Utility functions
    static int gcd(int a, int b) {
        if (b == 0) return a;
        return gcd(b, a % b);
    }

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

    static boolean isPrime(int n) {
        if (n <= 1) return false;
        if (n <= 3) return true;
        if (n % 2 == 0 || n % 3 == 0) return false;
        for (int i = 5; i * i <= n; i += 6) {
            if (n % i == 0 || n % (i + 2) == 0) return false;
        }
        return true;
    }

    static long power(long x, long y, long p) {
        long res = 1;
        x = x % p;
        while (y > 0) {
            if ((y & 1) == 1)
                res = (res * x) % p;
            y = y >> 1;
            x = (x * x) % p;
        }
        return res;
    }

    public static void sort(int[] arr)
    {
        //because Arrays.sort() uses quicksort which is dumb
        //Collections.sort() uses merge sort
        ArrayList<Integer> ls = new ArrayList<Integer>();
        for(int x: arr)
            ls.add(x);
        Collections.sort(ls);
        for(int i=0; i < arr.length; i++)
            arr[i] = ls.get(i);
    }
}


Solution 2 (runtime: 249 ms):
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.*;

public class a_6{
    static int mod = (int)(1e9 + 7);
    static boolean MULTI_CASE = true;
    static boolean print = false;
    static int limit;
    static List<Integer> numbers;

    public static void solve() throws IOException {
        int n = sc.nextInt();
        long[] arr = new long[n];
        for(int i = 0;i<n;i++){
            arr[i] = sc.nextInt();

        }
        int now = n-1;
        long ans = Long.MIN_VALUE;
        for(int a = 0;a<n;a++){
            long sum = 0;
            for(int i = 0;i<=now;i++){
                sum=sum+arr[i];
            }
            if(a == 0){
                ans = Math.max(ans,sum);
            }
            else{
                ans = Math.max(ans, Math.max(sum, -sum));
            }
            for(int i = 0;i<now;i++){
                arr[i] = arr[i+1]-arr[i];
            }
            now--;
        }
        System.out.println(ans);
    }
    public static Set<String> generatePermutations(String s) {
        Set<String> permutations = new TreeSet<>();
        permute(s.toCharArray(), 0, permutations);
        return permutations;
    }

    private static void permute(char[] chars, int index, Set<String> result) {
        if (index == chars.length) {
            result.add(new String(chars));
            return;
        }
        for (int i = index; i < chars.length; i++) {
            swap(chars, i, index);
            permute(chars, index + 1, result);
            swap(chars, i, index);  // backtrack
        }
    }

    private static void swap(char[] chars, int i, int j) {
        char temp = chars[i];
        chars[i] = chars[j];
        chars[j] = temp;
    }

    private static void reverse(long[] arr) {
        int left = 0, right = arr.length - 1;
        while (left < right) {
            long temp = arr[left];
            arr[left] = arr[right];
            arr[right] = temp;
            left++;
            right--;
        }
    }

    public static long naturalSum(long n) {
        return 1L * (n) * (n + 1L) / 2L;
    }

    public static long firstOddSum(long n) {
        return 1L * (n) * (n);
    }

    public static long firstEvenSum(long n) {
        return 1L * (n) * (n + 1L);
    }

    private static long arithmeticSum(long start, long length) {
        return length * (2 * start + (length - 1)) / 2;
    }

    public static boolean kSmallest(long val, int k, int[] res) {
        int cnt = 0;
        for (int i : res) {
            if (i <= val)
                cnt++;
        }
        return val >= k + cnt - 1;
    }

    public static void decrementCountMap(Map<Long, Integer> map, long key) {
        if (map.containsKey(key)) {
            int count = map.get(key);
            if (count == 1) {
                map.remove(key);
            } else {
                map.put(key, count - 1);
            }
        }
    }

    public static void updateCountMap(Map<Long, Integer> map, long key) {
        int count = 0;
        if (map.containsKey(key)) {
            count = map.get(key);
        }
        map.put(key, count + 1);
    }

    private static long median(long arr[]) {
        PriorityQueue<Long> pq = new PriorityQueue<>();
        int n = arr.length;
        n = (n + 1) / 2;
        for (long i : arr) {
            pq.add(i);
            if (pq.size() > n) pq.remove();
        }
        return pq.size() > 0 ? pq.peek() : 0;
    }

    public static String DecimalToBase(long number, int base) {
        StringBuilder conv = new StringBuilder();
        while (number > 0) {
            conv.append(number % base);
            number /= base;
        }
        return conv.reverse().toString();
    }

    public static long BaseToDecimal(String base, int dig) {
        long result = 0;
        for (char digit : base.toCharArray()) {
            result *= 10;
            int baseDigit = digit - '0';
            result += (baseDigit >= dig) ? (baseDigit + 1) : baseDigit;
        }
        return result;
    }

    public static boolean isNonDecreasing(long[] arr) {
        for (int i = 1; i < arr.length; i++) {
            if (arr[i] < arr[i - 1]) {
                return false;
            }
        }
        return true;
    }

    static long ncr(int n, int r) {
        long sum = 1L;
        for (int i = 1; i <= r; i++) {
            sum = sum * (n - r + i) / i;
        }
        return sum;
    }

    static long fact(int n) {
        return (n == 1 || n == 0) ? 1L : 1L * n * fact(n - 1);
    }

    static int mod_mul(int x, int y) {
        return (int)((long)((x % mod) * (y % mod)) % mod);
    }

    static int mod_add(int x, int y) {
        return (int)((long)((x % mod) + (y % mod)) % mod);
    }

    static long modinv(long x, long mod) {
        return fast_pow(x, mod - 2);
    }

    static long fast_pow(long a, long b) {
        if (b == 0)
            return 1L;

        long val = fast_pow(a, b / 2);

        if (b % 2 == 0)
            return val * val % mod;
        else
            return val * val % mod * a % mod;
    }

    static boolean[] sieveOfEratosthenes(int n) {
        boolean prime[] = new boolean[n + 1];
        for (int i = 0; i <= n; i++)
            prime[i] = true;

        for (int p = 2; p * p <= n; p++) {
            if (prime[p] == true) {
                for (int i = p * p; i <= n; i += p)
                    prime[i] = false;
            }
        }
        return prime;
    }

    static List<Integer> generatePrimes(int n) {
        boolean sieve[] = sieveOfEratosthenes(n);
        List<Integer> primes = new ArrayList<>();
        for (int i = 2; i <= n; i++) {
            if (sieve[i]) primes.add(i);
        }
        return primes;
    }

    static int[] singlePrimeFactor(int n) {
        int prime[] = new int[n + 1];
        for (int i = 0; i <= n; i++) prime[i] = i;

        for (int i = 2; i * i <= n; i++) {
            if (prime[i] == i) {
                for (int j = i * i; j <= n; j += i) {
                    prime[j] = i;
                }
            }
        }

        return prime;
    }

    static List<Integer> primeFactor(int n) {
        List<Integer> fact = new ArrayList<>();
        List<Integer> prime = generatePrimes(n);

        for (int i = 0; prime.get(i) * prime.get(i) <= n && i < prime.size(); i++) {
            if (n % prime.get(i) == 0) {
                while (n % prime.get(i) == 0) {
                    n /= prime.get(i);
                    fact.add(prime.get(i));
                }
            }
        }

        if (n > 1) {
            fact.add(n);
        }

        Collections.sort(prime);

        return prime;
    }

    static long lcm_of_array(List<Long> arr) {
        long lcm = arr.get(0);
        for (int i = 1; i < arr.size(); i++) {
            long num1 = lcm;
            long num2 = arr.get(i);
            long gcd_val = gcdl(num1, num2);
            lcm = (lcm * arr.get(i)) / gcd_val;
        }
        return lcm;
    }

    static int gcdi(int a, int b) {
        if (b == 0) return a;
        return gcdi(b, a % b);
    }

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

    static boolean isPrime(int n) {
        if (n <= 1)
            return false;

        if (n == 2 || n == 3)
            return true;

        if (n % 2 == 0 || n % 3 == 0)
            return false;

        for (int i = 5; i < Math.sqrt(n); i = i + 6)
            if (n % i == 0 || n % (i + 2) == 0)
                return false;

        return true;
    }

    public static void main(String[] args) throws IOException {
        if (MULTI_CASE) {
            int T = sc.nextInt();
            for (int i = 0; i < T; ++i) {
                solve();
            }
        } else {
            solve();
        }
        out.close();
    }

    static InputReader sc = new InputReader();
    static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));

    static class InputReader {
        private StringTokenizer st;
        private BufferedReader bf;

        public InputReader() {
            bf = new BufferedReader(new InputStreamReader(System.in));
            st = null;
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens()) {
                st = new StringTokenizer(bf.readLine());
            }
            return st.nextToken();
        }

        public String nextLine() throws IOException {
            return bf.readLine();
        }

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

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

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

class Pair implements Comparable<Pair> {
    int first;
    int second;
    int third;

    Pair(int a, int b) {
        first = a;
        second = b;
    }

    Pair(int a, int b, int c) {
        first = a;
        second = b;
        third = c;
    }

    @Override
    public int compareTo(Pair other) {
        if (other.first == this.first) {
            return Integer.compare(this.second, other.second);
        }
        return Integer.compare(this.first, other.first);
    }
}

class Node {
    long val;
    List<Node> child;

    Node(long a) {
        val = a;
        child = new ArrayList<>();
    }
}