Guest User

Untitled

a guest
Jun 26th, 2016
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.37 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Collections;
  3. import java.util.Scanner;
  4.  
  5.  
  6. public class CodeChef_Java {
  7.  
  8.     public static void main(String[] args) {
  9.         ArrayList<Integer> twos = new ArrayList<>();
  10.         int mark[] = new int[1001];
  11.         int T = 0, N=0, a=0;
  12.         Scanner sc = new Scanner(System.in);
  13.         if (sc.hasNextInt())
  14.             T = sc.nextInt();
  15.        
  16.         if (T < 1 || T > 1000) return;
  17.        
  18.         for(int i = 0; i < T; i++){
  19.             twos.clear();
  20.             for(int j = 0; j < 1001; j++){
  21.                 mark[i] = 0;
  22.             }
  23.             if (sc.hasNextInt())
  24.                 N = sc.nextInt();
  25.          
  26.             if (N < 1 || N > 1000) return;
  27.            
  28.             for(int j=0; j < N; j++){
  29.                 if (sc.hasNextInt())
  30.                     a = sc.nextInt();
  31.                 if (a < 1 || a > 1000){
  32.                     return;
  33.                 }
  34.                 mark[a]++;
  35.                 if (mark[a] == 2){
  36.                     twos.add(a);
  37.                 }
  38.             }
  39.            
  40.             if (twos.size() == 1||twos.isEmpty()){
  41.                 System.out.println(-1);
  42.             }
  43.             else{
  44.                 Collections.sort(twos, Collections.reverseOrder());
  45.                 System.out.println(twos.get(0)*twos.get(1));
  46.             }
  47.         }
  48.     }
  49.    
  50. }
Add Comment
Please, Sign In to add comment