#P11910. Maximizing Wins with Two Fuels

    ID: 14015 Type: Default 1000ms 256MiB

Maximizing Wins with Two Fuels

Maximizing Wins with Two Fuels

Little Tian and Little Qi are about to engage in a series of one-on-one robot battles. In the i-th match, Little Qi's robot has a power of \(a_i\) and Little Tian's robot has a power of \(b_i\) where \(0 \le a_i, b_i < P\). Little Tian can boost his robot’s power by using one of two available fuel types with fixed magic values \(s\) and \(t\). When a robot powered by \(b_i\) uses a fuel with magic value \(m\), its new power becomes \((b_i + m) \mod P\).

For each match \(i\), Little Tian must use exactly one of his two fuels. He wins the match if either \[ (b_i + s) \mod P > a_i \quad \text{or} \quad (b_i + t) \mod P > a_i, \] meaning that at least one fuel boosts his robot above Little Qi's power. Even if his robot is originally stronger, he is forced to use one of the fuels.

Your task is to help Little Tian choose the two magic values \(s\) and \(t\) in order to maximize his total wins over \(n\) matches. Output the maximum number of matches he can win.

inputFormat

The first line contains two integers \(n\) and \(P\). The second line contains \(n\) integers \(a_1, a_2, \ldots, a_n\) representing Little Qi's robots' powers. The third line contains \(n\) integers \(b_1, b_2, \ldots, b_n\) representing Little Tian's robots' powers.

outputFormat

Output a single integer: the maximum number of matches Little Tian can win by optimally choosing two fuel magic values \(s\) and \(t\).

sample

7 10
6 7 9 4 8 5 5
3 7 6 9 9 1 5
5