#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_imports)]
use std::collections::HashSet;
use std::collections::HashMap;
use std::collections::BTreeSet;
use std::collections::VecDeque;
use std::cmp::{max, min};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// https://rosettacode.org/wiki/Combinations#Rust
struct Combo<T> {
    data_len: usize,
    chunk_len: usize,
    min: usize,
    mask: usize,
    data: Vec<T>
}


// 使い方 (cmの型:Vec<T>)
/*
let cmb = Combo::new(3, h);
for cm in cmb.into_iter() {
    println!("{:?}", cm);
}
*/

impl<T: Clone> Combo<T> {
    fn new(chunk_len: i32, data: Vec<T>) -> Combo<T> {
        let d_len = data.len();
        let min = 2usize.pow(chunk_len as u32) - 1;
        let max = 2usize.pow(d_len as u32)
                - 2usize.pow((d_len - chunk_len as usize) as u32);
        Combo {
            data_len: d_len,
            chunk_len: chunk_len as usize,
            min: min,
            mask: max,
            data: data,
        }
    }

    fn get_chunk(&self) -> Vec<T> {
        let b = format!("{:1$b}", self.mask, self.data_len);
        b
            .chars()
            .enumerate()
            .filter(|&(_,e)|e=='1')
            .map(|(i,_)|self.data[i].clone())
            .collect()
    }
}

impl<T: Clone> Iterator for Combo<T> {
    type Item = Vec<T>;
    fn next(&mut self) -> Option<Self::Item> {
        while self.mask >= self.min {
            if self.mask.count_ones() == self.chunk_len as u32 {
                let res = self.get_chunk();
                self.mask -= 1;
                return Some(res);
            }
            self.mask -= 1;
        }
        None
    }
}


fn main() {
    input! {
        n: usize,
        a: [i64; n],
    }
    let mut map = HashMap::new();
    for i in a.into_iter() {
        if map.contains_key(&i) {
            let x = map.get_mut(&i).unwrap();
            *x += 1;
        } else {
            map.insert(i, 1);
        }
    }
    let mut h = Vec::new();
    for (k, v) in map.into_iter() {
        if v >= 4 {
            h.push(k);
            h.push(k);
        } else if v >= 2 {
            h.push(k);
        }
    }
    if h.len() <= 1 {
        println!("0");
        return;
    } else if h.len() == 2 {
        println!("{}", h[0] * h[1]);
        return;
    }
    let mut ma=h[0] * h[1];
    for i in 0..h.len() {
        for j in 0..h.len() {
            if i != j {
                ma = max(ma, h[i] * h[j]);
            }
        }
    }
    println!("{}", ma);
}

Measured memory_bytes: 14588