title: Maximum Area Rectangle Picking Four Sides Array
signature: class Solution {
  
      public int MaximumAreaRectanglePickingFourSidesArray(List<int> arr, int n) {
test_code: using System;
  using System.Numerics;
  using System.Diagnostics;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Security.Cryptography;
  using System.Web.UI;
  using System.Web.Script.Serialization;
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  namespace EvaluatePrediction {
      class TestRunner {
          public bool ValidateSolution(int actual, int expected){
              return new JavaScriptSerializer().Serialize(actual) == new JavaScriptSerializer().Serialize(expected);
          }
  
          public string driver(List<int> arr, int n, int expected){
              try{
                PLACEHOLDER_CLS_NAME solution_cls = new PLACEHOLDER_CLS_NAME();
                int pred_result = solution_cls.PLACEHOLDER_FN_NAME(arr, n); 
                if (ValidateSolution(
                      pred_result,
                      expected)){
                  return "PASSED";
                }
                return "FAILED";
              } 
              catch (Exception exception_obj)
              {
                return exception_obj.GetType().FullName;
              }
          }
          static void Main(string[] args) {
              TestRunner runner = new TestRunner();
              String result;
              result = runner.driver(
                  new List<int>{99, 96, 95, 95, 92, 84, 83, 82, 81, 74, 72, 68, 67, 52, 51, 51, 49, 47, 44, 40, 36, 25, 24, 17, 16, 14, 12, 11, 9, 8, 6, 5, 1}, 27, 
                  4845
              );
              Console.WriteLine(string.Format(
                  "TEST-0...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{-32, -54, -82, -92}, 2, 
                  0
              );
              Console.WriteLine(string.Format(
                  "TEST-1...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 15, 
                  1
              );
              Console.WriteLine(string.Format(
                  "TEST-2...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{99, 96, 96, 94, 68, 65, 62, 60, 45, 44, 30, 26, 17, 17, 16, 15, 2}, 8, 
                  0
              );
              Console.WriteLine(string.Format(
                  "TEST-3...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{98, 94, 82, 82, 74, 66, 66, 56, 54, 46, 16, -28, -34, -42, -50, -52, -78, -82, -88}, 15, 
                  5412
              );
              Console.WriteLine(string.Format(
                  "TEST-4...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 18, 
                  1
              );
              Console.WriteLine(string.Format(
                  "TEST-5...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{97, 96, 93, 87, 85, 85, 75, 68, 65, 65, 64, 63, 62, 58, 56, 52, 49, 44, 43, 38, 33, 30, 29, 28, 27, 25, 24, 23, 14, 14, 13, 10, 8, 8, 8, 6, 1}, 20, 
                  5525
              );
              Console.WriteLine(string.Format(
                  "TEST-6...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{78, 78, 76, 70, 60, 54, 50, 32, 16, 16, 6, -6, -20, -56, -64, -68, -70, -90, -90, -92}, 19, 
                  1248
              );
              Console.WriteLine(string.Format(
                  "TEST-7...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 30, 
                  1
              );
              Console.WriteLine(string.Format(
                  "TEST-8...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{94, 94, 94, 90, 84, 82, 75, 71, 57, 55, 53, 51, 51, 43, 35, 31, 30, 29, 22, 18, 14, 10, 7, 5, 4}, 22, 
                  4794
              );
              Console.WriteLine(string.Format(
                  "TEST-9...{0}",
                  result)
              );
          }
      }
  }
  
source_py: def maximum_area_rectangle_picking_four_sides_array(arr, n):
      arr.sort(reverse=True)
      dimension = [0, 0]
      i = 0
      j = 0
      while ((i < (n - 1)) and (j < 2)):
          if (arr[i] == arr[(i + 1)]):
              dimension[j] = arr[i]
              j += 1
              i += 1
          i += 1
      return (dimension[0] * dimension[1])
source_cpp: int maximum_area_rectangle_picking_four_sides_array(vector<int> arr, int n) {
    sort(arr.begin(), arr.end(), greater < int > ( ) );
    int dimension [ 2 ] = {
      0, 0 };
      for ( int i = 0, j = 0;
      i < n - 1 && j < 2;
      i ++ ) if ( arr [ i ] == arr [ i + 1 ] ) dimension [ j ++ ] = arr [ i ++ ];
      return ( dimension [ 0 ] * dimension [ 1 ] );
    }