#C3889. Pair Removal Challenge
Pair Removal Challenge
Pair Removal Challenge
You are given a two-dimensional grid of integers. Each integer represents a card identifier. In this challenge, each card is expected to occur exactly twice in the entire grid. Formally, for every distinct card value \(x\) in the grid, the following condition should hold:
\( \text{frequency}(x)=2 \)
Your task is to determine if it is possible to remove all cards by pairing them up such that every card appears exactly twice. If the grid satisfies the condition, output YES; otherwise, output NO.
inputFormat
The first line of input contains two integers \(n\) and \(m\) representing the number of rows and columns of the grid respectively.
Each of the next \(n\) lines contains \(m\) space-separated integers, representing the card identifiers in that row.
outputFormat
Output a single line containing YES if every card appears exactly twice, otherwise output NO.
## sample2 3
1 2 3
1 2 3
YES