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 C# (Mono 4.6.2.0) (judge verdict: Accepted)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Runtime.CompilerServices;

public class Contest
{
	static void Swap<T>(ref T lhs, ref T rhs) { T temp; temp = lhs; lhs = rhs; rhs = temp; }
	public const long MOD1 = 1000000007L; // 10^9+7

	public static void Main() {
		int  n;
		int[] a;
		MyIO.ReadMulti(out n);
		MyIO.ReadArray(out a);

		Dictionary<int,int> dic = new Dictionary<int, int>();
		int r1=0;
		int r2=0;

		for (int i = 0; i <= n; i++)
		{
			if(dic.ContainsKey(a[i])){
				r1 = dic[a[i]];
				r2 = n-i;
				break;
			}
			
			dic[a[i]] = i;
		}


		long[] ans = new long[n+1];
		ModCombination mc = new ModCombination(n+1, MOD1);
		for(int k=1;k<=n+1;k++){
			ans[k-1] = (mc.C(n+1,k).Value-mc.C(r1+r2,k-1).Value+MOD1)%MOD1;
		}

		MyIO.WriteLines(ans);

	}



}





public class ModCombination {
	private ModInt[] _fact, _rfact, _inv;
	private ModInt[] _mm;

	public ModCombination(int sz) : this(sz, long.MaxValue) {}
	public ModCombination(int sz, long modulo){
		_fact = new ModInt[sz+1];
		_rfact = new ModInt[sz+1];
		_inv = new ModInt[sz+1];

		_mm = new ModInt[]{new ModInt(0,modulo), new ModInt(1,modulo)};
		
		_fact[0] = _rfact[sz] = _inv[0] = _mm[1];
		for(int i = 1; i <= sz; i++) _fact[i] = _fact[i - 1] * i;
		_rfact[sz] /= _fact[sz];
		for(int i = sz - 1; i >= 0; i--) _rfact[i] = _rfact[i + 1] * (i + 1);
		for(int i = 1; i <= sz; i++) _inv[i] = _rfact[i] * _fact[i - 1];
	}

	public ModInt P(int n, int r) {
		if(r < 0 || n < r) return _mm[0];
		return _fact[n] * _rfact[n - r];
	}

	public ModInt C(int n, int r) {
		if(r < 0 || n < r) return _mm[0];
		return _fact[n] * _rfact[r] * _rfact[n - r];
	}

	public ModInt H(int n, int r) {
		if(n < 0 || r < 0) return _mm[0];
		return r == 0 ? _mm[1] : C(n + r - 1, r);
	}
	
	public ModInt B(int n, int k) {
		if(n == 0) return _mm[1];
		k = k<n ? k : n;
		ModInt ret = _mm[0];
		long mo = _mm[0].Modulo;
		ModInt[] pref = new ModInt[k + 1];
		pref[0] = _mm[1];
		for(int i = 1; i <= k; i++) {
			if((i & 1)==1) pref[i] = pref[i - 1] - _rfact[i];
			else pref[i] = pref[i - 1] + _rfact[i];
		}
		for(int i = 1; i <= k; i++) ret += (new ModInt(i, mo)).Pow(n) * _rfact[i] * pref[k - i];

		return ret;
	}
	
	public ModInt S(int n, int k) {
		ModInt ret = _mm[0];
		long mo = _mm[0].Modulo;
		for(int i = 0; i <= k; i++) {
			var add = (new ModInt(i, mo)).Pow(n) * this.C(k, i);
			if(((k - i) & 1)==1) ret -= add;
			else ret += add;
		}
		return ret * _rfact[k];
	}

	public static ModInt[][] PartitionTable(int n, int k, long modulo=long.MaxValue) {
		ModInt[][] dp = new ModInt[n + 1][];
		for(int i=0;i<=n;i++) dp[i] = new ModInt[k + 1];
		dp[0][0] = new ModInt(1, modulo);
		for(int i = 0; i <= n; i++) {
			for(int j = 1; j <= k; j++) {
				if(i - j >= 0) dp[i][j] = dp[i][j - 1] + dp[i - j][j];
				else dp[i][j] = dp[i][j - 1];
			}
		}
		return dp;
	}


}


public struct ModInt {
	public long Value;
	public long Modulo;

	public ModInt(long value) : this(value, long.MaxValue) {}
	public ModInt(long value, long modulo) {
		this.Modulo = modulo;
		this.Value = value >= 0 ? value % modulo : (modulo - (-value) % modulo) % modulo;
	}

    public static implicit operator ModInt(long v) { return new ModInt(v, 1000000007L); }
	public static ModInt operator-(ModInt a) { return new ModInt(-1*a.Value, a.Modulo); }
	public static ModInt operator+(ModInt a, ModInt b) { return new ModInt(a.Value + b.Value, a.Modulo); }
	public static ModInt operator-(ModInt a, ModInt b) { return new ModInt(a.Value - b.Value, a.Modulo); }
	public static ModInt operator*(ModInt a, ModInt b) { return new ModInt(a.Value * b.Value, a.Modulo); }
	public static ModInt operator/(ModInt a, ModInt b) { return a * b.Inverse(); }
	public static bool operator==(ModInt a, ModInt b) { return a.Equals(b); }
	public static bool operator!=(ModInt a, ModInt b) { return !a.Equals(b); }

	public ModInt Inverse() {
		long a = this.Value, b = this.Modulo, u = 1, v = 0, t, s;
		while(b > 0) {
			t = a / b;
			s = a - t * b; a = b; b = s;
			s = u - t * v; u = v; v = s;
		}
		return new ModInt(u, this.Modulo);
	}

	public ModInt Pow(int n) {
		ModInt ret = new ModInt(1, this.Modulo);
		ModInt mul = new ModInt(this.Value, this.Modulo);
		while(n > 0) {
			if((n & 1)==1) ret *= mul;
			mul *= mul;
			n >>= 1;
		}
		return ret;
	}

    public override bool Equals(object obj) {
        if (!(obj is ModInt)) throw new ArgumentException("Object is not a ModInt");
        return Equals((ModInt)obj);   
    }
    public bool Equals(ModInt p) => (this.Value == p.Value);
    public override int GetHashCode() => (int)(this.Value ^ this.Modulo);
	public override string ToString() => this.Value.ToString();

}



#region MyIO

public struct VT<T, U>
{
	public T Item1; public U Item2;
    public VT(T a, U b) { Item1 = a; Item2 = b; }
}
public struct VT<T, U, V>
{
	public T Item1; public U Item2; public V Item3;
    public VT(T a, U b, V c) { Item1 = a; Item2 = b; Item3 = c; }
}
public struct VT<T, U, V, W>
{
	public T Item1; public U Item2; public V Item3; public W Item4;
    public VT(T a, U b, V c, W d) { Item1 = a; Item2 = b; Item3 = c; Item4 = d; }
}

public class Printer : System.IO.StreamWriter
{
	public override IFormatProvider FormatProvider { get { return System.Globalization.CultureInfo.InvariantCulture; } }
	public Printer(System.IO.Stream stream) : base(stream, new UTF8Encoding(false, true)) { }
	public Printer(System.IO.Stream stream, Encoding encoding) : base(stream, encoding) { }
}
public static class MyIO
{
	private static char[] splitter = new char[] {' '};
	private static bool eq<T, U>() => typeof(T).Equals(typeof(U));
	private static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
	private static T cv<T>(string s) =>
		eq<T, int>()    ? ct<T, int>(int.Parse(s))
	  : eq<T, long>()   ? ct<T, long>(long.Parse(s))
	  : eq<T, double>() ? ct<T, double>(double.Parse(s, System.Globalization.CultureInfo.InvariantCulture))
	  : eq<T, char>()   ? ct<T, char>(s[0])
						: ct<T, string>(s);
			
	public static string[] ReadMulti<T>(out T a) {
		var ar = Console.ReadLine().Split(splitter, StringSplitOptions.RemoveEmptyEntries); 
		a = cv<T>(ar[0]);
		return ar;
	}
	public static string[] ReadMulti<T, U>(out T a, out U b) {
		var ar = ReadMulti<T>(out a); 
        b = cv<U>(ar[1]);
		return ar;
	}
	public static string[] ReadMulti<T, U, V>(out T a, out U b, out V c) {
		var ar = ReadMulti<T, U>(out a, out b); 
        c = cv<V>(ar[2]);
		return ar;
	}
	public static string[] ReadMulti<T, U, V, W>(out T a, out U b, out V c, out W d) {
		var ar = ReadMulti<T, U, V>(out a, out b, out c); 
        d = cv<W>(ar[3]);
		return ar;
	}
	public static string[] ReadMulti<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) {
		var ar = ReadMulti<T, U, V, W>(out a, out b, out c, out d); 
        e = cv<X>(ar[4]);
		return ar;
	}
	public static string[] ReadMulti<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) {
		var ar = ReadMulti<T, U, V, W, X>(out a, out b, out c, out d, out e); 
        f = cv<Y>(ar[5]);
		return ar;
	}
	public static string[] ReadArray<T>(out T[] a) {		
		var ar = Console.ReadLine().Split(splitter, StringSplitOptions.RemoveEmptyEntries);
		a = ar.Select(cv<T>).ToArray();
		return ar;
	}		
	public static string[][] ReadLines<T>(int n, out T[] a) {
		a = new T[n];
		string[][] arr = new string[n][];
		for(int i=0; i<n; i++) arr[i] = ReadMulti(out a[i]);
		return arr;
	}
	public static string[][] ReadLines<T, U>(int n, out VT<T, U>[] a) {
		a = new VT<T, U>[n];
		string[][] arr = new string[n][];
		for(int i=0; i<n; i++) {
			T o; U p;
			arr[i] = ReadMulti(out o, out p);
			a[i] = new VT<T, U>(o, p);
		}
		return arr;
	}
	public static string[][] ReadLines<T, U, V>(int n, out VT<T, U, V>[] a) {
		a = new VT<T, U, V>[n];
		string[][] arr = new string[n][];
		for(int i=0; i<n; i++) {
			T o; U p; V q;
			arr[i] = ReadMulti(out o, out p, out q);
			a[i] = new VT<T, U, V>(o, p, q);
		}
		return arr;
	}
	public static string[][] ReadLines<T, U, V, W>(int n, out VT<T, U, V, W>[] a) {
		a = new VT<T, U, V, W>[n];
		string[][] arr = new string[n][];
		for(int i=0; i<n; i++) {
			T o; U p; V q; W r;
			arr[i] = ReadMulti(out o, out p, out q, out r);
			a[i] = new VT<T, U, V, W>(o, p, q, r);
		}
		return arr;
	}
	public static string[][] ReadMatrix<T>(int n, out T[][] a) {
		a = new T[n][];
		string[][] arr = new string[n][];
		for(int i=0; i<n; i++) arr[i] = ReadArray(out a[i]);
		return arr;
	}

	private static void wwp(Action act){
		var sw = new Printer(Console.OpenStandardOutput()){AutoFlush = false};
		Console.SetOut(sw);
		act();
		Console.Out.Flush();
		sw.AutoFlush = true;
		Console.SetOut(sw);
	}
	private static string wfm(Type t) =>t.Equals(typeof(double)) ? "{0:F10}" : "{0}";
	public static void WriteMulti(params object[] a) {
		wwp(()=>{
			for(int i=0;i<a.Length;i++) {
				string fs = wfm(a[i].GetType()) + ((i<a.Length-1) ? " " : Environment.NewLine);
				Console.Write(fs, a[i]);
			}
		});
	}
	public static void WriteArray<T>(T[] a) {
		wwp(()=>{
			string fs = wfm(typeof(T));
			string fs1 = fs + " ";
			string fs2 = fs + Environment.NewLine;
			for(int i=0;i<a.Length;i++) Console.Write( ((i<a.Length-1) ? fs1 : fs2), a[i]);
		});
	}
	public static void WriteLines<T>(T[] a) {
		wwp(()=>{
			string fs = wfm(typeof(T)) + Environment.NewLine;
			foreach(T x in a) Console.Write(fs, x);
		});
	}



}

#endregion