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.
Your function should be named:
solve(N, D, S, A)
6 2 0 1 1 2 3 3 4Sample input 2
6 2 0 1 1 3 3 5 5Sample input 3
8 0 8 1 2 3 4 4 5 6 7Sample input 4
4 7 8 1 3 5 8
YESSample output 2
NOSample output 3
YESSample output 4
YES