AIO Practice – Pairing Cards

You have found an unusual deck of N cards, where N is an even integer. Each card has an integer value written on it, and the ith card has value Ai.

Your task is to rearrange the N cards into N/2 pairs such that each card belongs to exactly one pair. However, you are only allowed to pair two cards with values Ai and Aj if at least one of the following holds:

You are given integers D and S. Determine whether the cards can be divided into valid pairs.

Subtasks and Constraints

Input

Your function should be named:

solve(N, D, S, A)

Samples

Sample input 1
6 2 0
1 1 2 3 3 4
Sample input 2
6 2 0
1 1 3 3 5 5
Sample input 3
8 0 8
1 2 3 4 4 5 6 7
Sample input 4
4 7 8
1 3 5 8
Sample output 1
YES
Sample output 2
NO
Sample output 3
YES
Sample output 4
YES

Your Python Code