250C.md (2763B)
1 Source: https://codeforces.com/problemset/problem/250/C 2 3 C. Movie Critics 4 5 time limit per test 6 7 2 seconds 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 stdin 16 17 output 18 19 stdout 20 21 A film festival is coming up in the city N. The festival will last for exactly *n* days and each day will have a premiere of exactly one film. Each film has a genre — an integer from 1 to *k*. 22 23 On the *i*-th day the festival will show a movie of genre *a**i*. We know that a movie of each of *k* genres occurs in the festival programme at least once. In other words, each integer from 1 to *k* occurs in the sequence *a*1, *a*2, ..., *a**n* at least once. 24 25 Valentine is a movie critic. He wants to watch some movies of the festival and then describe his impressions on his site. 26 27 As any creative person, Valentine is very susceptive. After he watched the movie of a certain genre, Valentine forms the mood he preserves until he watches the next movie. If the genre of the next movie is the same, it does not change Valentine's mood. If the genres are different, Valentine's mood changes according to the new genre and Valentine has a stress. 28 29 Valentine can't watch all *n* movies, so he decided to exclude from his to-watch list movies of one of the genres. In other words, Valentine is going to choose exactly one of the *k* genres and will skip all the movies of this genre. He is sure to visit other movies. 30 31 Valentine wants to choose such genre *x* (1 ≤ *x* ≤ *k*), that the total number of after-movie stresses (after all movies of genre *x* are excluded) were minimum. 32 33 Input 34 35 The first line of the input contains two integers *n* and *k* (2 ≤ *k* ≤ *n* ≤ 105), where *n* is the number of movies and *k* is the number of genres. 36 37 The second line of the input contains a sequence of *n* positive integers *a*1, *a*2, ..., *a**n* (1 ≤ *a**i* ≤ *k*), where *a**i* is the genre of the *i*-th movie. It is guaranteed that each number from 1 to *k* occurs at least once in this sequence. 38 39 Output 40 41 Print a single number — the number of the genre (from 1 to *k*) of the excluded films. If there are multiple answers, print the genre with the minimum number. 42 43 Examples 44 45 Input 46 47 ``` 48 10 3 49 1 1 2 3 2 3 3 1 1 3 50 ``` 51 52 Output 53 54 ``` 55 3 56 ``` 57 58 Input 59 60 ``` 61 7 3 62 3 1 3 2 3 1 2 63 ``` 64 65 Output 66 67 ``` 68 1 69 ``` 70 71 Note 72 73 In the first sample if we exclude the movies of the 1st genre, the genres 2, 3, 2, 3, 3, 3 remain, that is 3 stresses; if we exclude the movies of the 2nd genre, the genres 1, 1, 3, 3, 3, 1, 1, 3 remain, that is 3 stresses; if we exclude the movies of the 3rd genre the genres 1, 1, 2, 2, 1, 1 remain, that is 2 stresses. 74 75 In the second sample whatever genre Valentine excludes, he will have exactly 3 stresses.