A - Counting Passes

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100

問題文

N 人の人 1,2,\dots,N がある試験を受け、人 iA_i 点を取りました。
この試験では、 L 点以上を取った人のみが合格となります。
N 人のうち何人が合格したか求めてください。

制約

  • 入力は全て整数
  • 1 \le N \le 100
  • 1 \le L \le 1000
  • 0 \le A_i \le 1000

入力

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

N L
A_1 A_2 \dots A_N

出力

答えを整数として出力せよ。


入力例 1

5 60
60 20 100 90 40

出力例 1

3

5 人が試験を受けました。 60 点以上取ると合格です。

  • 160 点を取ったので、合格です。
  • 220 点を取ったので、不合格です。
  • 3100 点を取ったので、合格です。
  • 490 点を取ったので、合格です。
  • 540 点を取ったので、不合格です。

以上より、合格したのは 3 人だと分かります。


入力例 2

4 80
79 78 77 76

出力例 2

0

合格者がいない場合もあります。


入力例 3

10 50
31 41 59 26 53 58 97 93 23 84

出力例 3

6

Score : 100 points

Problem Statement

N people labeled 1,2,\dots,N took an exam, and person i scored A_i points.
Only those who scored at least L points pass this exam.
Determine how many people out of the N have passed the exam.

Constraints

  • All input values are integers.
  • 1 \le N \le 100
  • 1 \le L \le 1000
  • 0 \le A_i \le 1000

Input

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

N L
A_1 A_2 \dots A_N

Output

Print the answer as an integer.


Sample Input 1

5 60
60 20 100 90 40

Sample Output 1

3

Five people took the exam. You need to score at least 60 points to pass.

  • Person 1 scored 60 points, so they passed.
  • Person 2 scored 20 points, so they did not pass.
  • Person 3 scored 100 points, so they passed.
  • Person 4 scored 90 points, so they passed.
  • Person 5 scored 40 points, so they did not pass.

From the above, we can see that three people have passed.


Sample Input 2

4 80
79 78 77 76

Sample Output 2

0

There may be cases no one has passed.


Sample Input 3

10 50
31 41 59 26 53 58 97 93 23 84

Sample Output 3

6
B - Same

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100

問題文

N 個の整数 A _ 1,A _ 2,\ldots,A _ N が与えられます。

これらの値がすべて等しいならば Yes 、そうでなければ No と出力してください。

制約

  • 2\leq N\leq100
  • 1\leq A _ i\leq100\ (1\leq i\leq N)
  • 入力はすべて整数

入力

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

N
A _ 1 A _ 2 \ldots A _ N

出力

与えられた A _ 1,A _ 2,\ldots,A _ N の値がすべて等しいなら Yes を、そうでなければ No1 行で出力せよ。


入力例 1

3
3 2 4

出力例 1

No

A _ 1\neq A _ 2 なので、No と出力してください。


入力例 2

4
3 3 3 3

出力例 2

Yes

A _ 1=A _ 2=A _ 3=A _ 4 なので、Yes と出力してください。


入力例 3

10
73 8 55 26 97 48 37 47 35 55

出力例 3

No

Score : 100 points

Problem Statement

You are given N integers A _ 1,A _ 2,\ldots,A _ N.

If their values are all equal, print Yes; otherwise, print No.

Constraints

  • 2\leq N\leq100
  • 1\leq A _ i\leq100\ (1\leq i\leq N)
  • All input values are integers.

Input

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

N
A _ 1 A _ 2 \ldots A _ N

Output

Print a single line containing Yes if the values of the given A _ 1,A _ 2,\ldots,A _ N are all equal, and No otherwise.


Sample Input 1

3
3 2 4

Sample Output 1

No

We have A _ 1\neq A _ 2, so you should print No.


Sample Input 2

4
3 3 3 3

Sample Output 2

Yes

We have A _ 1=A _ 2=A _ 3=A _ 4, so you should print Yes.


Sample Input 3

10
73 8 55 26 97 48 37 47 35 55

Sample Output 3

No
C - How many?

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

a+b+c \leq S かつ a \times b \times c \leq T を満たす非負整数の組 (a,b,c) はいくつありますか?

制約

  • 0 \leq S \leq 100
  • 0 \leq T \leq 10000
  • S, T は整数である。

入力

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

S T

出力

条件を満たす非負整数の組 (a,b,c) の個数を出力せよ。


入力例 1

1 0

出力例 1

4

条件を満たす非負整数の組 (a,b,c)(0,0,0), (0,0,1), (0,1,0), (1,0,0)4 つです。


入力例 2

2 5

出力例 2

10

入力例 3

10 10

出力例 3

213

入力例 4

30 100

出力例 4

2471

Score : 200 points

Problem Statement

How many triples of non-negative integers (a, b, c) satisfy a+b+c \leq S and a \times b \times c \leq T?

Constraints

  • 0 \leq S \leq 100
  • 0 \leq T \leq 10000
  • S and T are integers.

Input

Input is given from Standard Input in the following format:

S T

Output

Print the number of triples of non-negative integers (a,b,c) satisfying the conditions.


Sample Input 1

1 0

Sample Output 1

4

The triples (a,b,c) satisfying the conditions are (0,0,0), (0,0,1), (0,1,0), and (1,0,0) ― there are four of them.


Sample Input 2

2 5

Sample Output 2

10

Sample Input 3

10 10

Sample Output 3

213

Sample Input 4

30 100

Sample Output 4

2471
D - Next

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

N 個の整数 A_1, A_2, \ldots, A_N が与えられます。 このうち最大でない整数の中で最大である整数を求めてください。

ただし、この問題の制約下で答えは必ず存在します。

制約

  • 2 \leq N \leq 100
  • 1 \leq A_i \leq 100
  • A_1, A_2, \ldots, A_N がすべて等しいということはない
  • 入力値はすべて整数

入力

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

N
A_1 A_2 \ldots A_N

出力

答えを出力せよ。


入力例 1

5
2 1 3 3 2

出力例 1

2

2,1,3,3,2 の中で最大である整数は 3 です。

2,1,3,3,2 の中で 3 でない整数は 2,1,23 つであり、これらの中で最大である整数は 2 です。


入力例 2

4
4 3 2 1

出力例 2

3

入力例 3

8
22 22 18 16 22 18 18 22

出力例 3

18

Score : 200 points

Problem Statement

You are given N integers A_1, A_2, \ldots, A_N. Find the largest among those integers that are not the largest.

The constraints of this problem guarantee that the answer exists.

Constraints

  • 2 \leq N \leq 100
  • 1 \leq A_i \leq 100
  • It is not the case that all A_1, A_2, \ldots, A_N are equal.
  • All input values are integers.

Input

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

N
A_1 A_2 \ldots A_N

Output

Print the answer.


Sample Input 1

5
2 1 3 3 2

Sample Output 1

2

The largest integer among 2,1,3,3,2 is 3.

The integers that are not 3 among 2,1,3,3,2 are 2,1,2, among which the largest is 2.


Sample Input 2

4
4 3 2 1

Sample Output 2

3

Sample Input 3

8
22 22 18 16 22 18 18 22

Sample Output 3

18
E - Consecutive

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

英小文字のみからなる長さ N の文字列 S = S_1S_2\ldots S_N が与えられます。

また、S に関する Q 個の質問が与えられます。 i = 1, 2, \ldots, Q について、i 番目の質問は 2 つの整数 l_i, r_i で表される下記の質問です。

Sl_i 文字目から r_i 文字目までからなる部分文字列 S_{l_i}S_{l_i+1}\ldots S_{r_i} において、 同じ英小文字が 2 つ隣りあう箇所は何個ありますか? すなわち、l_i \leq p \leq r_i-1 かつ S_p = S_{p+1}を満たす整数 p は何個ありますか?

Q 個の質問それぞれの答えを出力してください。

制約

  • N, Q は整数
  • 1 \leq N, Q \leq 3 \times 10^5
  • S は英小文字のみからなる長さ N の文字列
  • l_i, r_i は整数
  • 1 \leq l_i \leq r_i \leq N

入力

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

N Q
S
l_1 r_1
l_2 r_2
\vdots
l_Q r_Q

出力

Q 行出力せよ。 i = 1, 2, \ldots, Q について、i 行目には i 番目の質問に対する答えを出力せよ。


入力例 1

11 4
mississippi
3 9
4 10
4 6
7 7

出力例 1

2
2
0
0

4 個の質問それぞれに対する答えは下記の通りです。

  • 1 個目の質問に関して、S_3S_4\ldots S_9 = ssissip で同じ英小文字が隣り合う箇所は、S_3S_4 = ssS_6S_7 = ss2 個です。
  • 2 個目の質問に関して、S_4S_5\ldots S_{10} = sissipp で同じ英小文字が隣り合う箇所は、S_6S_7 = ssS_9S_{10} = pp2 個です。
  • 3 個目の質問に関して、S_4S_5S_6 = sis で同じ英小文字が隣り合う箇所は 0 個です。
  • 4 個目の質問に関して、S_7 = s で同じ英小文字が隣り合う箇所は 0 個です。

入力例 2

5 1
aaaaa
1 5

出力例 2

4

S_1S_2\ldots S_5 = aaaaa で同じ英小文字が隣り合う箇所は、 S_1S_2 = aaS_2S_3 = aaS_3S_4 = aaS_4S_5 = aa4 個です。

Score : 300 points

Problem Statement

You are given a string S = S_1S_2\ldots S_N of length N consisting of lowercase English letters.

Additionally, you are given Q queries about the string S. For i = 1, 2, \ldots, Q, the i-th query is represented by two integers l_i, r_i and asks the following.

In the substring S_{l_i}S_{l_i+1}\ldots S_{r_i} of S, which ranges from the l_i-th to the r_i-th character, how many places are there where the same lowercase English letter occurs twice in a row? In other words, how many integers p satisfy l_i \leq p \leq r_i-1 and S_p = S_{p+1}?

Print the answer for each of the Q queries.

Constraints

  • N and Q are integers.
  • 1 \leq N, Q \leq 3 \times 10^5
  • S is a string of length N consisting of lowercase English letters.
  • l_i and r_i are integers.
  • 1 \leq l_i \leq r_i \leq N

Input

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

N Q
S
l_1 r_1
l_2 r_2
\vdots
l_Q r_Q

Output

Print Q lines. For i = 1, 2, \ldots, Q, the i-th line should contain the answer to the i-th query.


Sample Input 1

11 4
mississippi
3 9
4 10
4 6
7 7

Sample Output 1

2
2
0
0

The answers to the four queries are as follows.

  • For the first query, S_3S_4\ldots S_9 = ssissip has two places where the same lowercase English letter occurs twice in a row: S_3S_4 = ss and S_6S_7 = ss.
  • For the second query, S_4S_5\ldots S_{10} = sissipp has two places where the same lowercase English letter occurs twice in a row: S_6S_7 = ss and S_9S_{10} = pp.
  • For the third query, S_4S_5S_6 = sis has zero places where the same lowercase English letter occurs twice in a row.
  • For the fourth query, S_7 = s has zero places where the same lowercase English letter occurs twice in a row.

Sample Input 2

5 1
aaaaa
1 5

Sample Output 2

4

S_1S_2\ldots S_5 = aaaaa has four places where the same lowercase English letter occurs twice in a row: S_1S_2 = aa, S_2S_3 = aa, S_3S_4 = aa, and S_4S_5 = aa.