Time limit per test: 3 second(s) Memory limit: 262144 kilobytes
input: standard output: standard
Chess Championship is set up in the New Basyuki City. Two national teams, of Berland and Byteland, are going to have a match there. Each team is represented by n players. The championship consists of n games — in each game a pair of players from different teams meets. A game victory brings 1 point to the team and a game defeat doesn't add or subtract points.
The championship starts with the sortition — the process that determines opponent pairs. Each player from the first team plays with exactly one player from the second team (and vice versa).
A recent research conducted by Berland scientists showed that every player of either team is characterized by a single number — the level of his chess mastership. No two people among the 2n players play at the same level. Funny as it is, the game winner always is the player with the higher level.
The contest organizers received information that a high-ranking Berland official Mr. B. bet 100500 burles on the victory of his team with a k points gap. Immediately an unofficial "recommendation" came from very important people to "organize" the sortition so that the Berland team gets exactly k points more than the Byteland team.
Write a program that finds the number of distinct sortition results after which Berland gets exactly k points more than Byteland. Two sortitions are considered distinct if there is such player, that gets different opponents by the sortitions' results.
The first line contains a pair of integers n and k (1 ≤ n ≤ 500; 1 ≤ k ≤ n) — the number of participants in each team and the required gap in points that Berland must win. The second and the third input lines contain n integers each: the i-th number of the second line characterizes the i-th Berland player's chess mastership level, and the j-th number of the third line characterizes the j-th Byteland player's chess mastership level. It is guaranteed that all numbers that characterize mastership levels are distinct integers from 0 to 109.
Print a single integer — the number of ways to set up the sortition so that the Berland team wins k points more than the Byteland team in the championship. The answer can be rather large, so print it modulo 1000000009 (109+9).
5 35 15 45
40 20 10 30
In the first example the acceptable sortition results are: (5-40, 35-20, 15-10, 45-30), (5-40, 45-20, 15-10, 35-30), (45-40, 5-20, 15-10, 35-30) and (45-40, 35-20, 15-10, 5-30).
Codeforces (c) Copyright 2010-2019 Mike Mirzayanov