Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.Scanner;
- public class CodeChef_Java {
- public static void main(String[] args) {
- ArrayList<Integer> twos = new ArrayList<>();
- int mark[] = new int[1001];
- int T = 0, N=0, a=0;
- Scanner sc = new Scanner(System.in);
- if (sc.hasNextInt())
- T = sc.nextInt();
- if (T < 1 || T > 1000) return;
- for(int i = 0; i < T; i++){
- twos.clear();
- for(int j = 0; j < 1001; j++){
- mark[i] = 0;
- }
- if (sc.hasNextInt())
- N = sc.nextInt();
- if (N < 1 || N > 1000) return;
- for(int j=0; j < N; j++){
- if (sc.hasNextInt())
- a = sc.nextInt();
- if (a < 1 || a > 1000){
- return;
- }
- mark[a]++;
- if (mark[a] == 2){
- twos.add(a);
- }
- }
- if (twos.size() == 1||twos.isEmpty()){
- System.out.println(-1);
- }
- else{
- Collections.sort(twos, Collections.reverseOrder());
- System.out.println(twos.get(0)*twos.get(1));
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment