| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 740773 | yeroc | A Huge Tower (CEOI10_tower) | Java | 0 ms | 0 KiB | 
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// File: HugeTower.java
// Date: 04/15/2023
// Author: Corey Zhu
import java.io.*;
import java.util.*;
public class Tower {
    static void solve(Kattio io){
		int MOD = 1000000009;
		int n = io.nextInt(); int d = io.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = io.nextInt();
		}
		Arrays.sort(arr);
		long ans = 1;
		int end = 0;
		for (int i = 0; i < n-1; i++) {
			while (end < n && arr[end]-arr[i] <= d) {
				end += 1;
			}
			ans = ((long)(ans * (end-i))) % MOD;
			
		}
		io.println(ans);
    }
    // Run
    public static void main(String[] args) throws IOException {
        Kattio io = new Kattio();
        solve(io);
        io.close();
    }
    
    // IO
	static class Kattio extends PrintWriter {
		private BufferedReader r;
		private StringTokenizer st;
		// standard input
		public Kattio() { this(System.in, System.out); }
		public Kattio(InputStream i, OutputStream o) {
			super(o);
			r = new BufferedReader(new InputStreamReader(i));
		}
		// USACO-style file input
		public Kattio(String problemName) throws IOException {
			super(problemName + ".out");
			r = new BufferedReader(new FileReader(problemName + ".in"));
		}
		// returns null if no more input
		public String next() {
			try {
				while (st == null || !st.hasMoreTokens())
					st = new StringTokenizer(r.readLine());
				return st.nextToken();
			} catch (Exception e) { }
			return null;
		}
		public int nextInt() { return Integer.parseInt(next()); }
		public double nextDouble() { return Double.parseDouble(next()); }
		public long nextLong() { return Long.parseLong(next()); }
	}
}
