#P6306. Find the Magical Book's Number
Find the Magical Book's Number
Find the Magical Book's Number
Lily has (n-1) books, each with an integer label (a_i). Two books belong to the same type if and only if their labels are identical. It is guaranteed that in Lily's collection, for every distinct label the count is a multiple of a given constant (k). Now, one extra book—the magical book—with an unknown label is mixed into Lily's books, making the total count (n). Marisa needs your help to determine the magical book's label.
Note: The magical book's label may be identical to one of Lily's books. In the final mixed collection, all types except the magical book’s type will appear a multiple of (k) times. For the magical book’s type, if its label is (x) and Lily originally had a multiple of (k) copies of (x), then after adding the magical book the count becomes (\text{multiple}\times k+1), which is not a multiple of (k). Your task is to find that label.
inputFormat
The first line contains two integers (n) and (k) where (n) is the total number of books after adding the magical book and (n-1) is the sum of counts of Lily's books (each count is a multiple of (k), so note that (n \equiv 1 \pmod{k})).
The second line contains (n) integers (a_1, a_2, \dots, a_n) representing the labels of the books after mixing.
outputFormat
Output a single integer—the label of the magical book.
sample
7 3
9 5 9 5 9 5 5
5