Problem: There used to be unrest in the Galactic Senate. Several thousand solar systems had declared their intentions to leave the Republic. But fear not! Master Heidi was able to successfully select the Jedi Knights that have restored peace in the galaxy. However, she knows that evil never sleeps and a time may come when she will need to pick another group of Jedi Knights. She wants to be sure she has enough options to do so.

There are n Jedi Knights, each of them with a lightsaber of one of m colors. Given a number k, compute the number of differently colored collections of k lightsabers that some k Jedi Knights might have. Jedi Knights with lightsabers of the same color are indistinguishable (it's not the person, it's the lightsaber color that matters!), and their order does not matter; that is, we consider two collections of Jedi Knights to be different if and only if their vectors of counts of lightsabers of each color (like what you were given in the easy and the medium versions) are different. We count all subsets, not only contiguous subsegments of the input sequence. Output the answer modulo 1009.

Input

The first line of the input contains n (1 ≤ n ≤ 2·105), m (1 ≤ m ≤ n) and k (1 ≤ k ≤ n). The second line contains n integers in the range {1, 2, ..., m} representing colors of the lightsabers of subsequent Jedi Knights.

Output

Output one number: the number of differently colored collections of k lightsabers modulo 1009.

Example

Input

4 3 2
1 2 3 2


Output

4

Solution (in JAVA):

Solution:
import java.io.*;
import java.util.*;

public class F3
{
    PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer tok;
    Complex[] aux1, aux2;
    double[] sin, cos;
    long[] tick = new long[10];
    long[] invN = new long[20];
    long MOD = 1009;

    public void go() throws IOException
    {
        // in = new BufferedReader(new FileReader(new File("test.txt")));
        sin = new double[100];
        cos = new double[100];
        for (int i = 0; i < 100; i++) {
            sin[i] = Math.sin(Math.PI * 2 / (1 << i));
            cos[i] = Math.cos(Math.PI * 2 / (1 << i));
        }
        for (int i = 0; i < 20; i++) {
            invN[i] = modPow(1 << i, MOD-2);
        }
        ntok();
        int n = ipar();
        int m = ipar();
        int k = ipar();
        int maxSize = 1 << 20;
        aux1 = new Complex[maxSize];
        aux2 = new Complex[maxSize];
        for (int i = 0; i < maxSize; i++) {
            aux1[i] = new Complex();
            aux2[i] = new Complex();
        }
        ntok();
        int[] freq = new int[m];
        for (int i = 0; i < n; i++) {
            int x = ipar()-1;
            freq[x]++;
        }
        PriorityQueue<long[]> pq = new PriorityQueue<>((a, b) -> Integer.compare(a.length, b.length));
        for (int i = 0; i < m; i++) {
            if (freq[i] == 0) {
                continue;
            }
            long[] f = new long[freq[i]+1];
            Arrays.fill(f, 1);
            pq.add(f);
        }

        while (pq.size() > 1) {
            long[] fa = pq.remove();
            long[] fb = pq.remove();
            pq.add(merge(fa, fb));
        }

        long[] ans = pq.remove();
        out.println(ans[k]);

        // long startTime = System.nanoTime();
        // long[] fa = new long[100000];
        // long[] fb = new long[100000];
        // for (int i = 0; i < 100; i++) {
        //     Arrays.fill(fa, 1);
        //     Arrays.fill(fb, 1);
        //     long[] res = merge(fa, fb);
        // }
        // long endTime = System.nanoTime();
        // out.println((endTime - startTime) / 1000000.0 + " ms");
        // for (int i = 0; i < tick.length; i++) {
        //     out.printf("tick[%d]: %.3f ms%n", i, tick[i] / 1000000.0);
        // }

        out.flush();
        in.close();
    }

    public long[] merge(long[] fa, long[] fb) {
        int n = 1;
        tick[0] -= System.nanoTime();
        while (n < fa.length + fb.length) {
            n *= 2;
        }
        for (int i = 0; i < fa.length; i++) {
            aux1[i].set(fa[i], 0);
        }
        for (int i = 0; i < fb.length; i++) {
            aux2[i].set(fb[i], 0);
        }
        tick[0] += System.nanoTime();
        tick[1] -= System.nanoTime();
        fft(aux1, false, n);
        tick[1] += System.nanoTime();
        tick[2] -= System.nanoTime();
        fft(aux2, false, n);
        tick[2] += System.nanoTime();
        tick[3] -= System.nanoTime();
        for (int i = 0; i < n; i++) {
            aux1[i].multiply(aux2[i]);
            // aux1[i].a /= n;
            // aux1[i].b /= n;
        }
        tick[3] += System.nanoTime();
        tick[4] -= System.nanoTime();
        fft(aux1, true, n);
        tick[4] += System.nanoTime();
        tick[5] -= System.nanoTime();
        long[] res = new long[fa.length+fb.length-1];
        for (int i = 0; i < res.length; i++) {
            res[i] = Math.round(aux1[i].a) % MOD;
        }
        for (int i = 0; i < n; i++) {
            aux1[i].set(0, 0);
        }
        for (int i = 0; i < n; i++) {
            aux2[i].set(0, 0);
        }
        tick[5] += System.nanoTime();
        return res;
    }

    Complex[][] ws;
    public void fft(Complex[] f, boolean inverse, int n) {
        int bitCount = 0;
        while (1 << bitCount < n) {
            bitCount++;
        }
        for (int i = 0; i < n; i++) {
            int rev = reverse(i, bitCount);
            if (i < rev) {
                Complex temp = f[i];
                f[i] = f[rev];
                f[rev] = temp;
            }
        }
        
        Complex temp = new Complex();
        Complex rot = new Complex();
        Complex w = new Complex();
        for (int lenBits = 1; 1 << lenBits <= n; lenBits++) {
            int len = 1 << lenBits;
            rot.set(cos[lenBits], sin[lenBits] * (inverse ? -1 : 1));
            for (int offset = 0; offset < n; offset += len) {
                w.set(1, 0);
                for (int i = 0; i*2 < len; i++) {
                    Complex a = f[offset + i];
                    Complex b = f[offset + i+len/2];
                    temp.set(b);
                    temp.multiply(w);
                    b.set(a);
                    a.add(temp);
                    b.subtract(temp);
                    w.multiply(rot);
                }
            }
        }

        // if (ws == null) {
        //     int len = 1 << 20;
        //     ws = new Complex[len][2];
        //     w.set(1, 0);
        //     rot.set(cos[20], sin[20]);
        //     for (int i = 0; i*2 < len; i++) {
        //         ws[i][0] = new Complex();
        //         ws[i][1] = new Complex();
        //         ws[i][0].set(w);
        //         ws[i][1].set(w);
        //         ws[i][1].b *= -1;
        //         w.multiply(rot);
        //     }
        // }

        // int inv = inverse ? 1 : 0;
        // for (int lenBits = 1; 1 << lenBits <= n; lenBits++) {
        //     int len = 1 << lenBits;
        //     int jump = 1 << (20 - lenBits);
        //     for (int offset = 0; offset < n; offset += len) {
        //         for (int i = 0; i*2 < len; i++) {
        //             Complex a = f[offset + i];
        //             Complex b = f[offset + i+len/2];
        //             w.set(ws[i * jump][inv]);
        //             temp.set(b);
        //             temp.multiply(w);
        //             b.set(a);
        //             a.add(temp);
        //             b.subtract(temp);
        //         }
        //     }
        // }

        if (inverse) {
            for (int i = 0; i < n; i++) {
                f[i].a /= n;
                f[i].b /= n;
            }
        }
    }

    public long modPow(long a, long b) {
        if (b == 0) {
            return 1;
        }
        if (b % 2 == 0) {
            return modPow(a*a % MOD, b/2);
        } else {
            return modPow(a*a % MOD, b/2) * a % MOD;
        }
    }

    public int reverse(int n, int bitCount) {
        int rev = 0;
        for (int i = 0; i < bitCount; i++) {
            rev *= 2;
            rev += n%2;
            n /= 2;
        }
        return rev;
    }

    private static class Complex {
        double a, b;

        public Complex() {}

        public Complex(double a, double b) {
            this.a = a;
            this.b = b;
        }

        public void multiply(Complex other) {
            double aa = a * other.a - b * other.b;
            double bb = a * other.b + b * other.a;
            a = aa;
            b = bb;
        }

        public void add(Complex other) {
            a += other.a;
            b += other.b;
        }

        public void subtract(Complex other) {
            a -= other.a;
            b -= other.b;
        }

        public void set(Complex other) {
            a = other.a;
            b = other.b;
        }

        public void set(double a, double b) {
            this.a = a;
            this.b = b;
        }
    }

    public void ntok() throws IOException
    {
        tok = new StringTokenizer(in.readLine());
    }

    public int ipar()
    {
        return Integer.parseInt(tok.nextToken());
    }

    public int[] iapar(int n)
    {
        int[] arr = new int[n];
        for (int i = 0; i < n; i++)
        {
            arr[i] = ipar();
        }
        return arr;
    }

    public long lpar()
    {
        return Long.parseLong(tok.nextToken());
    }

    public long[] lapar(int n)
    {
        long[] arr = new long[n];
        for (int i = 0; i < n; i++)
        {
            arr[i] = lpar();
        }
        return arr;
    }

    public double dpar()
    {
        return Double.parseDouble(tok.nextToken());
    }

    public String spar()
    {
        return tok.nextToken();
    }

    public static void main(String[] args) throws IOException
    {
        new F3().go();
    }
}