Language: Java

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

import java.util.*;

public class Main {
    static int mod=1_000_000_007;
    static long factorial(int n) {
        long tmp = 1;
        for (int i=n;i>0;i--) {
            tmp = (tmp*i) % mod;
        }
        return tmp;
    }
    static long pow(long a,int n) {
        long res=1;
        while (n>0) {
            if ((n-n/2*2)==1) {
                res=res*a%mod;
            }
            a=a*a%mod;
            n>>=1;
        }
        return res;
    }
    static long modinv(long n) {
        return pow(n, mod-2);
    }
static long nCr(int n, int r) {
    if(n<0 || r<0 || n<r)return 0;
    return factorial(n) * modinv(factorial(n-r)) % mod * modinv(factorial(r)) % mod;
}
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);

        int n = in.nextInt();
        int[] a = new int[n+1];
        int[] cnt = new int[n];
        int index=-1;
        for (int i=0;i<n+1;i++) {
            a[i] = in.nextInt();
            cnt[a[i]-1]++;
            if (cnt[a[i]-1]==2) {
                index=a[i]-1;
            }
        }
        int[] index_array = new int[2];
        int l=0;
        for (int i=0;i<n+1;i++) {
            if (a[i]-1==index) {
                index_array[l]=i;
                l++;
            }
        }
        long[] n1_C_i = new long[n+2];
        n1_C_i[0]=1;
        for (int i=0;i<n+1;i++) {
            n1_C_i[i+1] = n1_C_i[i] * (long)(n+1-i)%mod*modinv(i+1)%mod;
        }

        // long[] bunshi_1 = new long[n+2];
        // long[] bunbo_1 = new long[n+2];
        // bunshi_1[0]=1;
        // bunbo_1[0]=1;
        // for (int i=0;i<n+1;i++) {
        //     bunshi_1[i+1] = bunshi_1[i]*(n+1-i)%mod;
        //     bunbo_1[i+1] = bunbo_1[i]*(i+1)%mod;
        // }
        // long[] bunshi_2 = new long[index_array[0]+(n-index_array[1])+1];
        // long[] bunbo_2 = new long[index_array[0]+(n-index_array[1])+1];
        // bunshi_2[0]=1;
        // bunbo_2[0]=1;
        // for (int i=0;i<index_array[0]+(n-index_array[1]);i++) {
        //     bunshi_2[i+1] = bunshi_2[i]*(index_array[0]+(n-index_array[1])-i)%mod;
        //     bunbo_2[i+1] = bunbo_2[i]*(i+1)%mod;
        // }

        long[] n2_C_i = new long[index_array[0]+(n-index_array[1])+1];
        n2_C_i[0]=1;
        for (int i=0;i<index_array[0]+(n-index_array[1]);i++) {
            n2_C_i[i+1] = n2_C_i[i] * (long)(index_array[0]+(n-index_array[1])-i)%mod*modinv(i+1)%mod;
        }
        // System.out.println(Arrays.toString(n2_C_i));
        // System.out.println(Arrays.toString(bunshi_1));
        // System.out.println(Arrays.toString(bunbo_1));
        // System.out.println(Arrays.toString(bunshi_2));
        // System.out.println(Arrays.toString(bunbo_2));


        for (int i=1;i<=n+1;i++) {
            // if (index_array[0]+(n-index_array[1])<i-1) {
                // out.println(nCr(n+1, i));
                // out.println(n1_C_i[i]);
                // out.println(bunshi_1[i]*modinv(bunbo_1[i])%mod);
            // } else {
                // out.println(nCr(n+1, i)-nCr(index_array[0]+(n-index_array[1]), i-1));
                out.println(n1_C_i[i]-n2_C_i[i-1]);
                // out.println(bunshi_1[i]*modinv(bunbo_1[i])%mod-bunshi_2[i-1]*modinv(bunbo_2[i-1])%mod);
            }
        }
        out.close();
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}


Compiler output:
Main.java:110: error: <identifier> expected
        out.close();
                 ^
Main.java:142: error: class, interface, enum, or record expected
}
^
2 errors