B - Polyline 解説 /

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 200 点

問題文

xy 平面上に 1,2,\ldots,N の番号が付けられた N 個の点があり、点 i の座標は (i,A_i) です。

i=1,2,\ldots,N-1 について点 i と点 i+1 を線分で結び、1 本の折れ線を作ります。

この折れ線上(端点も含む)にある点のうち、y 座標が K であるものの個数を求めてください。

ただし、制約より条件を満たす点の個数は有限であることが保証されます。

制約

  • 2 \le N \le 100
  • 1 \le A_i \le 100 (1 \le i \le N)
  • A_i \ne A_{i+1} (1 \le i < N)
  • 1 \le K \le 100
  • 入力される値はすべて整数

入力

入力は以下の形式で標準入力から与えられる。

N K
A_1 A_2 \ldots A_N

出力

折れ線上にある点のうち、y 座標が K であるものの個数を出力せよ。


入力例 1

5 3
1 3 1 5 1

出力例 1

3

下図のように、条件を満たす点は、(2,3)、(\frac{7}{2},3)、(\frac{9}{2},3) の 3 個です。

点 (2,3) は、点 1 と点 2 を結ぶ線分と、点 2 と点 3 を結ぶ線分の共通の端点ですが、1 個の点として数えることに注意してください。


入力例 2

3 3
3 1 3

出力例 2

2

条件を満たす点は (1,3)、(3,3) の 2 個です。折れ線の端の点も数えることに注意してください。


入力例 3

2 100
1 2

出力例 3

0

Score : 200 points

Problem Statement

There are N points on the xy-plane, numbered 1,2,\ldots,N. The coordinates of point i are (i,A_i).

For i=1,2,\ldots,N-1, connect point i and point i+1 with a line segment to form one polyline.

Find the number of points on this polyline (including its endpoints) whose y-coordinate is K.

Here, the constraints guarantee that the number of points satisfying the condition is finite.

Constraints

  • 2 \le N \le 100
  • 1 \le A_i \le 100 (1 \le i \le N)
  • A_i \ne A_{i+1} (1 \le i < N)
  • 1 \le K \le 100
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

N K
A_1 A_2 \ldots A_N

Output

Print the number of points on the polyline whose y-coordinate is K.


Sample Input 1

5 3
1 3 1 5 1

Sample Output 1

3

As shown in the figure below, there are 3 points satisfying the condition: (2,3), (\frac{7}{2},3), and (\frac{9}{2},3).

Note that the point (2,3) is a common endpoint of the segment connecting points 1 and 2 and the segment connecting points 2 and 3, but it is counted as one point.


Sample Input 2

3 3
3 1 3

Sample Output 2

2

There are 2 points satisfying the condition: (1,3) and (3,3). Note that the points at the ends of the polyline are also counted.


Sample Input 3

2 100
1 2

Sample Output 3

0