Problem:
Score : 300 points

Problem Statement

You are given a sequence of positive integers of length N, a = (a_1, a_2, ..., a_N).
Your objective is to remove some of the elements in a so that a will be a good sequence.

Here, an sequence b is a good sequence when the following condition holds true:

For each element x in b, the value x occurs exactly x times in b.

For example, (3, 3, 3), (4, 2, 4, 1, 4, 2, 4) and () (an empty sequence) are good sequences, while (3, 3, 3, 3) and (2, 4, 1, 4, 2) are not.

Find the minimum number of elements that needs to be removed so that a will be a good sequence.

Constraints

1 \leq N \leq 10^5

a_i is an integer.

1 \leq a_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

Print the minimum number of elements that needs to be removed so that a will be a good sequence.

Sample Input 1

4
3 3 3 3

Sample Output 1

1

We can, for example, remove one occurrence of 3. Then, (3, 3, 3) is a good sequence.

Sample Input 2

5
2 4 1 4 2

Sample Output 2

2

We can, for example, remove two occurrences of 4. Then, (2, 1, 2) is a good sequence.

Sample Input 3

6
1 2 2 3 3 3

Sample Output 3

0

Sample Input 4

1
1000000000

Sample Output 4

1

Remove one occurrence of 10^9. Then, () is a good sequence.

Sample Input 5

8
2 7 1 8 2 8 1 8

Sample Output 5

5

Solution in Rust (1.15.1) (judge verdict: Runtime Error)

fn getline() -> String {
    let mut res = String::new();
    std::io::stdin().read_line(&mut res).ok();
    res
}

#[allow(unused_macros)]
macro_rules! readl {
    ($t: ty) => {
        {
            let s = getline();
            s.trim().parse::<$t>().unwrap()
        }
    };
    ($( $t: ty),+ ) => {
        {
            let s = getline();
            let mut iter = s.trim().split(' ');
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
}

#[allow(unused_macros)]
macro_rules! readlvec {
    ($t: ty) => {
        {
            let s = getline();
            let iter = s.trim().split(' ');
            iter.map(|x| x.parse().unwrap()).collect::<Vec<$t>>()
        }
    }
}

#[allow(unused_macros)]
macro_rules! debug {
    ($x: expr) => {
        println!("{}: {:?}", stringify!($x), $x)
    }
}

fn printiter<'a, T>(v: &'a T)
where
    &'a T: std::iter::IntoIterator,
    <&'a T as std::iter::IntoIterator>::Item: std::fmt::Display,
{
    for (i, e) in v.into_iter().enumerate() {
        if i != 0 {
            print!(" ");
        }
        print!("{}", e);
    }
    println!("");
}

enum BinaryTrie {
    Node(Box<BinaryTrie>, Box<BinaryTrie>, bool),
    Empty,
}

impl BinaryTrie {
    fn new() -> Self {
        BinaryTrie::Empty
    }

    fn add<'a, T: Iterator<Item = bool>>(&mut self, mut iter: T) {
        use BinaryTrie::*;
        match iter.next() {
            Some(true) => match self {
                &mut Node(_, ref mut right, _) => {
                    right.add(iter);
                }
                &mut Empty => {
                    let mut r = Box::new(Empty);
                    r.add(iter);
                    *self = Node(Box::new(Empty), r, false);
                }
            },
            Some(false) => match self {
                &mut Node(ref mut left, _, _) => {
                    left.add(iter);
                }
                &mut Empty => {
                    let mut l = Box::new(Empty);
                    l.add(iter);
                    *self = Node(l, Box::new(Empty), false);
                }
            },
            None => match self {
                &mut Node(_, _, ref mut f) => *f = true,
                &mut Empty => *self = Node(Box::new(Empty), Box::new(Empty), true),
            },
        }
    }

    fn contain<T: Iterator<Item = bool>>(&mut self, mut iter: T) -> bool {
        use BinaryTrie::*;
        match iter.next() {
            Some(true) => match self {
                &mut Node(_, ref mut right, _) => right.contain(iter),
                &mut Empty => false,
            },
            Some(false) => match self {
                &mut Node(ref mut left, _, _) => left.contain(iter),
                &mut Empty => false,
            },
            None => match self {
                &mut Node(_, _, is_end) => is_end,
                &mut Empty => false,
            },
        }
    }

    fn solve(&self) -> Vec<usize> {
        let mut res = Vec::new();
        self.rec(0, &mut res);
        res
    }

    fn rec(&self, depth: usize, v: &mut Vec<usize>) {
        use BinaryTrie::*;
        match self {
            &Node(ref left, ref right, false) => {
                left.rec(depth + 1, v);
                right.rec(depth + 1, v);
            },
            &Empty => {
                v.push(depth);
            }
            _ => (),
        }
    }
}

fn naive_grundy(n: usize) -> usize {
    let mut dp = vec![0; n + 1];
    for i in 1..n + 1 {
        let mut mex = vec![false; 2*n + 1];
        mex[0] = true;
        let mut xor = 0;
        for j in (0..i).rev() {
            xor ^= dp[j];
            mex[xor] = true;
        }
        dp[i] = mex.iter().cloned().position(|x| !x).unwrap();
    }
    debug!(dp);
    dp.pop().unwrap()
}

fn get_grundy(n: usize) -> usize {
    if n == 0 {
        0
    } else {
        let mut i = 1;
        while n%(i*2) != i {
            i *= 2;
        }
        i
    }
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BinaryHeap, HashMap, HashSet};
#[allow(unused_imports)]
use std::collections::btree_map::Entry::{Occupied, Vacant};

fn main() {
    use std::io::Write;
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    macro_rules! printf { ($($arg:tt)*) => (write!(out, $($arg)*).unwrap()); }
    macro_rules! printfln { () => (writeln!(out).unwrap()); ($($arg:tt)*) => (writeln!(out, $($arg)*).unwrap()); }
    // naive_grundy(100);
    // debug!((0..100).map(|x| get_grundy(x)).collect::<Vec<_>>());

    let (n, l) = readl!(usize, usize);
    let s: Vec<Vec<_>> = (0..n)
        .map(|_| {
            readl!(String)
                .into_bytes()
                .into_iter()
                .map(|c| c == b'1')
                .collect()
        })
        .collect();
    let mut trie = BinaryTrie::new();
    for e in &s {
        trie.add(e.iter().cloned());
    }

    
    let grundy = trie.solve()
        .into_iter()
        .map(|x|{
            // debug!(l-x+1);
            let t = get_grundy(l - x + 1);
            // debug!(t);
            t
        })
        .fold(0, |sum, e| sum ^ e);

    if grundy == 0 {
        printfln!("Bob");
    } else {
        printfln!("Aice");
    }
}