For this Question: Given an unsorted array <b>A[]</b> of size <b>N</b>. A triplet (i, j, k) is said to be special if they satisfy below two conditions:

<b>1. i < j < k</b>
<b>2. A<sub>i</sub> < A<sub>j</sub> < A<sub>k</sub></b>
<b>V<sub>(A<sub>i</sub>,A<sub>j</sub>,A<sub>k</sub>)</sub>: A<sub>i</sub> + (A<sub>j</sub> * A<sub>k</sub>)</b>

You need to find the maximum possible value V<sub>(A<sub>i</sub>,A<sub>j</sub>,A<sub>k</sub>)</sub> which can be obtained from possible triplets satisfying above two conditions.The input line contains T, denoting the number of testcases. Each testcase contains Two lines. First line contains size of array. Second line contains elements of array separated by space.

<b>Constraints:</b>
1 <= T <= 100
1 <= N <= 10^5
1 <= A[i] <= 10^6

Sum of N for all test cases is less than 10^5For each testcase you need find the maximum possible value in new line otherwise print "<b>-1</b>" if no such triplet is found.Sample Input:
2
4
5 20 11 19
4
1 2 2 2

Sample Output:
214
-1

Explanation:
Testcase 1: 5 11 19 forms special triplet fulfilling above conditions, thus giving maximum value 5 + (11*19) = 214.
Testcase 2: None of triplets satisfy the given conditions thus, maximum value is -1, I have written this Solution Code: import java.io.*;
import java.util.*;



class Main {
	static int[] maxLeft(int[] a){
		int N = a.length;
		int[] res = new int[N];
		TreeSet<Integer> ts = new TreeSet<>();

		for(int i=0; i<N; i++){
			int curr = a[i];
			Integer maxLeftVal = ts.lower(curr);

			if(maxLeftVal==null){
				res[i] = -1;
			}else{
				res[i] = maxLeftVal;
			}
			ts.add(curr);
		}
		return res;
	}

	static int[] maxRight(int[] a){
		int N = a.length;
		int[] res = new int[N];
		res[N-1] = -1;
		int maxSeenIndexTillNow = N-1;

		for(int i=N-2; i>=0; i--){
			int curr = a[i];

			if(curr<a[maxSeenIndexTillNow]){
				res[i] = maxSeenIndexTillNow;
			}else{
				res[i] = -1;
				maxSeenIndexTillNow = i;
			}
		}return res;
	}

	public static void main (String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int T = Integer.parseInt(br.readLine());

		for(int t=0; t<T; t++){
			int N = Integer.parseInt(br.readLine());
			int[] arr = new int[N];
			String[] strArr = br.readLine().split(" ");

			for(int i=0; i<N; i++){
				arr[i] = Integer.parseInt(strArr[i]);
			}

			int[] valOfA = maxLeft(arr);
			int[] valOfK = maxRight(arr);
			long vMax = -1;

			for(int i=0; i<N; i++){
				int vA = valOfA[i];
				int vK = valOfK[i];
				if(vA==-1 || vK==-1){

				}else{
					long valA = vA;
					long valK = arr[vK];
					long valJ = arr[i];
					long currVmax = vA + (valJ*valK);
					vMax = Math.max(vMax, currVmax);
				}
			}System.out.println(vMax);
		}
	}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not?