Problem:
Score : 400 points

Problem Statement

Snuke has decided to play a game using cards.
He has a deck consisting of N cards. On the i-th card from the top, an integer A_i is written.

He will perform the operation described below zero or more times, so that the values written on the remaining cards will be pairwise distinct. Find the maximum possible number of remaining cards. Here, N is odd, which guarantees that at least one card can be kept.

Operation: Take out three arbitrary cards from the deck. Among those three cards, eat two: one with the largest value, and another with the smallest value. Then, return the remaining one card to the deck.

Constraints

3 ≦ N ≦ 10^{5}

N is odd.

1 ≦ A_i ≦ 10^{5}

A_i is an integer.

Input

The input is given from Standard Input in the following format:

N
A_1 A_2 A_3 ... A_{N}

Output

Print the answer.

Sample Input 1

5
1 2 1 3 7

Sample Output 1

3

One optimal solution is to perform the operation once, taking out two cards with 1 and one card with 2. One card with 1 and another with 2 will be eaten, and the remaining card with 1 will be returned to deck. Then, the values written on the remaining cards in the deck will be pairwise distinct: 1, 3 and 7.

Sample Input 2

15
1 3 5 2 1 3 2 8 8 6 2 6 11 1 1

Sample Output 2

7

Solution in Rust (1.15.1) (judge verdict: Accepted)

use std::io::{ self, Write };
use std::str::FromStr;
use std::cmp::{ min, max };
use std::collections::{ VecDeque, BinaryHeap };

macro_rules! trace {
    ($var:expr) => ({
        let _ = writeln!(&mut std::io::stderr(), ">>> {} = {:?}", stringify!($var), $var);
    })
}
macro_rules! swap { ($a:expr, $b:expr) => ({ let t = $b; $b = $a; $a = t; }) }

const K: usize = 100000;

fn main() {
    let mut sc = Scanner::new();
    let mut count = [0; K];
    let mut n: usize = sc.cin();
    for i in 0..n {
        let a: usize = sc.cin();
        count[a] += 1;
    }

    let mut ones = BinaryHeap::new();
    let mut manys = BinaryHeap::new();

    for i in 0..K {
        if count[i] == 1 {
            ones.push(-(i as i32));
        } else if count[i] > 1 {
            manys.push(-(i as i32));
        }
    }

    // trace!(ones);
    // trace!(manys);

    for i in 0..K {

        if count[i] == 0 { continue; }

        if count[i] == 1 {
            let _ = ones.pop();
        } else if count[i] > 1 {
            let _ = manys.pop();
        }

        if count[i] >= 3 {
            let rest = (count[i] - 1) % 2 + 1;
            n -= count[i] - rest;
            count[i] = rest;
        }

        if n == 1 { continue; }

        if n == 3 {
            if ones.len() == 3 {
                continue;
            } else {
                n -= 2;
            }
            break;
        }

        // n >= 5
        // 1 <= d[i] <= 2
        if count[i] == 1 { continue; }

        // d[i] == 2
        if let Some(j_) = manys.pop() {
            let j = (-j_) as usize;
            count[j] -= 1;
            n -= 2;
            if count[j] == 1 {
                ones.push(-(j as i32));
            } else if count[i] > 1 {
                manys.push(-(j as i32));
            }
        } else {
            n -= 2;
            break;
        }
    }

    println!("{}", n);
}

#[allow(dead_code)]
struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn reserve(&mut self) {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
    }
    fn cin<T: FromStr>(&mut self) -> T {
        self.reserve();
        match self.buffer.pop_front().unwrap().parse::<T>() {
            Ok(a) => a,
            Err(_) => panic!("parse err")
        }
    }
    fn get_char(&mut self) -> char {
        self.reserve();
        let head = self.buffer[0].chars().nth(0).unwrap();
        let tail = String::from( &self.buffer[0][1..] );
        if tail.len()>0 { self.buffer[0]=tail } else { self.buffer.pop_front(); }
        head
    }
}