Problem:
Score : 600 points

Problem Statement

You are given an integer sequence of length n+1, a_1,a_2,...,a_{n+1}, which consists of the n integers 1,...,n.
It is known that each of the n integers 1,...,n appears at least once in this sequence.

For each integer k=1,...,n+1, find the number of the different subsequences (not necessarily contiguous) of the given sequence with length k, modulo 10^9+7.

Notes

If the contents of two subsequences are the same, they are not separately counted even if they originate from different positions in the original sequence.

A subsequence of a sequence a with length k is a sequence obtained by selecting k of the elements of a and arranging them without changing their relative order. For example, the sequences 1,3,5 and 1,2,3 are subsequences of 1,2,3,4,5, while 3,1,2 and 1,10,100 are not.

Constraints

1 \leq n \leq 10^5

1 \leq a_i \leq n

Each of the integers 1,...,n appears in the sequence.

n and a_i are integers.

Input

Input is given from Standard Input in the following format:

n
a_1 a_2 ... a_{n+1}

Output

Print n+1 lines.
The k-th line should contain the number of the different subsequences of the given sequence with length k, modulo 10^9+7.

Sample Input 1

3
1 2 1 3

Sample Output 1

3
5
4
1

There are three subsequences with length 1: 1 and 2 and 3.

There are five subsequences with length 2: 1,1 and 1,2 and 1,3 and 2,1 and 2,3.

There are four subsequences with length 3: 1,1,3 and 1,2,1 and 1,2,3 and 2,1,3.

There is one subsequence with length 4: 1,2,1,3.

Sample Input 2

1
1 1

Sample Output 2

1
1

There is one subsequence with length 1: 1.

There is one subsequence with length 2: 1,1.

Sample Input 3

32
29 19 7 10 26 32 27 4 11 20 2 8 16 23 5 14 6 12 17 22 18 30 28 24 15 1 25 3 13 21 19 31 9

Sample Output 3

32
525
5453
40919
237336
1107568
4272048
13884156
38567100
92561040
193536720
354817320
573166440
818809200
37158313
166803103
166803103
37158313
818809200
573166440
354817320
193536720
92561040
38567100
13884156
4272048
1107568
237336
40920
5456
528
33
1

Be sure to print the numbers modulo 10^9+7.

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

#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap};

#[allow(dead_code)]
type Graph = Vec<Vec<usize>>;

const M: usize = 1_000_000_007;

struct Combination {
    modp: usize,
    mfact: Vec<usize>,
    rfact: Vec<usize>,
}

impl Combination {
    fn new(size: usize, modp: usize) -> Self {
        let mut rfact = vec![0; size + 1];
        let mut mfact = vec![0; size + 1];
        mfact[0] = 1;
        for i in 1..mfact.len() {
            mfact[i] = (mfact[i - 1] * i) % modp;
        }
        rfact[size] = Self::inv(mfact[size], modp);
        for i in (0..size).rev() {
            rfact[i] = rfact[i + 1] * (i + 1) % modp;
        }

        Combination {
            modp: modp,
            mfact: mfact,
            rfact: rfact,
        }
    }

    fn pow(mut x: usize, mut n: usize, modp: usize) -> usize {
        let mut ret = 1;
        while n > 0 {
            if n & 1 > 0 {
                ret *= x;
                ret %= modp;
            }
            x *= x;
            x %= modp;
            n >>= 1;
        }
        ret
    }

    fn inv(x: usize, modp: usize) -> usize {
        Self::pow(x, modp - 2, modp)
    }

    fn C(&self, p: usize, q: usize) -> usize {
        if p < q {
            return 0;
        }
        (((self.mfact[p] * self.rfact[q]) % self.modp) * self.rfact[p - q]) % self.modp
    }
}

// struct Combination
// {
//   int mod;
//   vector< int64_t > mfact, rfact;

//   Combination(int sz, int mod) : mfact(sz + 1), rfact(sz + 1), mod(mod)
//   {
//     mfact[0] = 1;
//     for(int i = 1; i < mfact.size(); i++) {
//       mfact[i] = mfact[i - 1] * i % mod;
//     }
//     rfact[sz] = inv(mfact[sz]);
//     for(int i = sz - 1; i >= 0; i--) {
//       rfact[i] = rfact[i + 1] * (i + 1) % mod;
//     }
//   }

//   int64_t fact(int k) const
//   {
//     return (mfact[k]);
//   }

//   int64_t pow(int64_t x, int64_t n) const
//   {
//     int64_t ret = 1;
//     while(n > 0) {
//       if(n & 1) (ret *= x) %= mod;
//       (x *= x) %= mod;
//       n >>= 1;
//     }
//     return (ret);
//   }

//   int64_t inv(int64_t x) const
//   {
//     return (pow(x, mod - 2));
//   }

//   int64_t P(int n, int r) const
//   {
//     if(r < 0 || n < r) return (0);
//     return (mfact[n] * rfact[n - r] % mod);
//   }

//   int64_t C(int p, int q) const
//   {
//     if(q < 0 || p < q) return (0);
//     return (mfact[p] * rfact[q] % mod * rfact[p - q] % mod);
//   }

//   int64_t H(int n, int r) const
//   {
//     if(n < 0 || r < 0) return (0);
//     return (r == 0 ? 1 : C(n + r - 1, r));
//   }
// };

fn create_combination(size: usize) -> Vec<Vec<usize>> {
    let mut comb = vec![vec![0; size + 10]; size + 10];
    for i in 0..size + 1 {
        for j in 0..i + 1 {
            if j == 0 || j == i {
                comb[i][j] = 1;
            } else {
                comb[i][j] = (comb[i - 1][j - 1] + comb[i - 1][j]) % M;
            }
        }
    }
    comb
}

fn main() {
    input! {
        n: usize,
        a: [usize; n + 1],
    }
    let mut pos = vec![None; n + 1];
    let mut ai = 0;
    let mut aj = 0;
    let mut al = 0;
    let mut am = 0;
    let mut ar = 0;
    for i in 0..a.len() {
        if pos[a[i]].is_none() {
            pos[a[i]] = Some(i);
        } else {
            ai = pos[a[i]].unwrap();
            aj = i;
            al = ai;
            am = aj - ai - 1;
            ar = a.len() - aj - 1;
            break;
        }
    }
    let comb = Combination::new(n + 10, M);

    for i in 1..n + 2 {
        let mut ans = 0;
        ans += comb.C(n - 1, i);
        ans %= M;

        if i >= 1 {
            ans += comb.C(al + am + ar, i - 1) * 2;
            ans %= M;

            ans += M - comb.C(al + ar, i - 1);
            ans %= M;
        }

        if i >= 2 {
            ans += comb.C(al + am + ar, i - 2);
            ans %= M;
        }
        println!("{}", ans);
    }
}