430B.md (2023B)
1 Source: https://codeforces.com/problemset/problem/430/B 2 3 B. Balls Game 4 5 time limit per test 6 7 1 second 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 stdin 16 17 output 18 19 stdout 20 21 Iahub is training for the IOI. What is a better way to train than playing a Zuma-like game? 22 23 There are *n* balls put in a row. Each ball is colored in one of *k* colors. Initially the row doesn't contain three or more contiguous balls with the same color. Iahub has a single ball of color *x*. He can insert his ball at any position in the row (probably, between two other balls). If at any moment there are three or more contiguous balls of the same color in the row, they are destroyed immediately. This rule is applied multiple times, until there are no more sets of 3 or more contiguous balls of the same color. 24 25 For example, if Iahub has the row of balls [black, black, white, white, black, black] and a white ball, he can insert the ball between two white balls. Thus three white balls are destroyed, and then four black balls become contiguous, so all four balls are destroyed. The row will not contain any ball in the end, so Iahub can destroy all 6 balls. 26 27 Iahub wants to destroy as many balls as possible. You are given the description of the row of balls, and the color of Iahub's ball. Help Iahub train for the IOI by telling him the maximum number of balls from the row he can destroy. 28 29 Input 30 31 The first line of input contains three integers: *n* (1 ≤ *n* ≤ 100), *k* (1 ≤ *k* ≤ 100) and *x* (1 ≤ *x* ≤ *k*). The next line contains *n* space-separated integers *c*1, *c*2, ..., *c**n* (1 ≤ *c**i* ≤ *k*). Number *c**i* means that the *i*-th ball in the row has color *c**i*. 32 33 It is guaranteed that the initial row of balls will never contain three or more contiguous balls of the same color. 34 35 Output 36 37 Print a single integer — the maximum number of balls Iahub can destroy. 38 39 Examples 40 41 Input 42 43 ``` 44 6 2 2 45 1 1 2 2 1 1 46 ``` 47 48 Output 49 50 ``` 51 6 52 ``` 53 54 Input 55 56 ``` 57 1 1 1 58 1 59 ``` 60 61 Output 62 63 ``` 64 0 65 ```