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 C++14 (GCC 5.4.1) (judge verdict: Runtime Error)

#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <algorithm>
const int mod=1e9+7;
using LL=long long;
using std::cout;using std::endl;using std::cin;
using std::vector;using std::string;using std::set;using std::multiset;
using std::pair;using std::map;
using std::min;using std::max;
using std::make_pair;
std::ostream& operator<<(std::ostream& os,std::map<int,int>& obj){for(std::map<int,int>::iterator itr=obj.begin();itr!=obj.end();itr++){os<<itr->first<<"^"<<itr->second<<" ";}return os;}
std::ostream& operator<<(std::ostream& os,std::vector<std::map<int,int>>& obj){for(auto itr=obj.begin();itr!=obj.end();itr++){os<<*itr<<std::endl;}return os;}
std::ostream& operator<<(std::ostream& os,std::vector<int>& obj){for(auto itr=obj.begin();itr!=obj.end();itr++){os<<*itr<<" ";}return os;}

namespace ndifix{
template<class T>void sort(T &v){std::sort(v.begin(),v.end());}
}

int main(){
  int n;cin>>n;
  vector<int> a(n);for(int i=0;i<n;i++)cin>>a[i];
  ndifix::sort(a);
  set<int> s,d;
  vector<int> vd;
  multiset<int> md;for(int i=0;i<n;i++)md.insert(a[i]);
  for(auto itr=md.begin();itr!=md.end();itr++){if(md.count(*itr)>=2)d.insert(*itr);}

  for(auto itr=d.begin();itr!=d.end();itr++)vd.push_back(*itr);
  ndifix::sort(vd);

  
  while(a.size()>=4){
//for(int i=0;i<a.size();i++)cout<<a[i]<<" ";cout<<"# ";
    if(d.size() && vd[0]<a[0]){vd.erase(vd.begin());continue;}
    if(d.size() && vd.back()>a.back()){vd.erase((vd.end()--));continue;}
    if(a[0]!=a[1] && a[a.size()-2]!=a[a.size()-1]){s.insert(a[0]);s.insert(a.back());a.erase(a.begin());a.pop_back();continue;}
    if(a[0]==a[1] && a[a.size()-2]==a[a.size()-1]){a.erase(a.begin());a.pop_back();continue;}
    if(a[0]==a[1] && vd.size()==1){a.erase(a.begin());a.pop_back();continue;}
    if(a[0]==a[1] && vd.size()>=2){a.erase(a.begin());a.erase(std::lower_bound(a.begin(),a.end(),*(d.end()--)));s.insert(a.back());a.pop_back();continue;}
    if(a[a.size()-2]==a[a.size()-1] && vd.size()==1){a.erase(a.begin());a.pop_back();continue;}
    if(a[a.size()-2]==a[a.size()-1] && vd.size()>=2){a.pop_back();a.erase(std::lower_bound(a.begin(),a.end(),*d.begin()));s.insert(a[0]);a.erase(a.begin());continue;}
  }
//for(int i=0;i<a.size();i++)cout<<a[i]<<" ";cout<<endl;
  if(a[0]!=a[1] && a[1]!=a[2]){s.insert(a[0]);s.insert(a[1]);s.insert(a[2]);}
  else s.insert(a[1]);
  
  cout<<s.size()<<endl;

  return 0;
}