A - Transfer

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 100

問題文

水を入れる容器が 2 つあります。

容器 1 には水を A ミリリットルまで入れることができ、水が B ミリリットル入っています。

容器 2 には水が C ミリリットル入っています。

容器 2 から容器 1 に入るだけ水を移します。

容器 2 の中には何ミリリットルの水が残るでしょうか。

制約

  • 入力は全て整数である。
  • 1 \leq B \leq A \leq 20
  • 1 \leq C \leq 20

入力

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

A B C

出力

ミリリットル単位で容器 2 の中に残る水の量を整数で出力せよ。


入力例 1

6 4 3

出力例 1

1

容器 2 から容器 12 ミリリットルの水を移すことになるので、容器 2 には 1 ミリリットルの水が残ります。


入力例 2

8 3 9

出力例 2

4

入力例 3

12 3 7

出力例 3

0

Score : 100 points

Problem Statement

We have two bottles for holding water.

Bottle 1 can hold up to A milliliters of water, and now it contains B milliliters of water.

Bottle 2 contains C milliliters of water.

We will transfer water from Bottle 2 to Bottle 1 as much as possible.

How much amount of water will remain in Bottle 2?

Constraints

  • All values in input are integers.
  • 1 \leq B \leq A \leq 20
  • 1 \leq C \leq 20

Input

Input is given from Standard Input in the following format:

A B C

Output

Print the integer representing the amount of water, in milliliters, that will remain in Bottle 2.


Sample Input 1

6 4 3

Sample Output 1

1

We will transfer two milliliters of water from Bottle 2 to Bottle 1, and one milliliter of water will remain in Bottle 2.


Sample Input 2

8 3 9

Sample Output 2

4

Sample Input 3

12 3 7

Sample Output 3

0
B - Uneven Numbers

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 200

問題文

整数 N が与えられます。N 以下の正の整数のうち、(先頭に 0 をつけずに十進法で表記したときの) 桁数が奇数であるようなものの個数を求めてください。

制約

  • 1 \leq N \leq 10^5

入力

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

N

出力

N 以下の正の整数のうち、桁数が奇数であるようなものの個数を出力せよ。


入力例 1

11

出力例 1

9

11 以下の正の整数のうち、桁数が奇数であるようなものは 1, 2, \ldots, 99 個です。


入力例 2

136

出力例 2

46

1, 2, \ldots, 9 に加えて、100, 101, \ldots, 13637 個の数も桁数が奇数です。


入力例 3

100000

出力例 3

90909

Score : 200 points

Problem Statement

Given is an integer N. Find the number of positive integers less than or equal to N that have an odd number of digits (in base ten without leading zeros).

Constraints

  • 1 \leq N \leq 10^5

Input

Input is given from Standard Input in the following format:

N

Output

Print the number of positive integers less than or equal to N that have an odd number of digits.


Sample Input 1

11

Sample Output 1

9

Among the positive integers less than or equal to 11, nine integers have an odd number of digits: 1, 2, \ldots, 9.


Sample Input 2

136

Sample Output 2

46

In addition to 1, 2, \ldots, 9, another 37 integers also have an odd number of digits: 100, 101, \ldots, 136.


Sample Input 3

100000

Sample Output 3

90909
C - Build Stairs

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 300

問題文

左右一列に N 個のマスが並んでおり、左から i 番目のマスの高さは H_i です。

あなたは各マスについて 1 度ずつ次のいずれかの操作を行います。

  • マスの高さを 1 低くする。
  • 何もしない。

操作をうまく行うことでマスの高さを左から右に向かって単調非減少にできるか求めてください。

制約

  • 入力は全て整数である。
  • 1 \leq N \leq 10^5
  • 1 \leq H_i \leq 10^9

入力

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

N
H_1 H_2 ... H_N

出力

マスの高さを左から右に向かって単調非減少にできるなら Yes、そうでないなら No を出力せよ。


入力例 1

5
1 2 1 1 3

出力例 1

Yes

左から 2 番目のマスのみ高さを 1 低くすることで目的を達成できます。


入力例 2

4
1 3 2 1

出力例 2

No

入力例 3

5
1 2 3 4 5

出力例 3

Yes

入力例 4

1
1000000000

出力例 4

Yes

Score : 300 points

Problem Statement

There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.

For each square, you will perform either of the following operations once:

  • Decrease the height of the square by 1.
  • Do nothing.

Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.

Constraints

  • All values in input are integers.
  • 1 \leq N \leq 10^5
  • 1 \leq H_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N
H_1 H_2 ... H_N

Output

If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print Yes; otherwise, print No.


Sample Input 1

5
1 2 1 1 3

Sample Output 1

Yes

You can achieve the objective by decreasing the height of only the second square from the left by 1.


Sample Input 2

4
1 3 2 1

Sample Output 2

No

Sample Input 3

5
1 2 3 4 5

Sample Output 3

Yes

Sample Input 4

1
1000000000

Sample Output 4

Yes
D - Gathering Children

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 400

問題文

マスの情報を表す、LR で構成された文字列 S が与えられます。

文字列 S の長さを N としたとき、N 個のマスが左右一列に並んでおり、左から i 番目のマスには S の左から i 番目の文字が書かれています。

ただし、左端のマスには必ず R、右端のマスには必ず L が書かれています。

はじめ、各マスには 1 人の子どもが居ます。

子どもたちはそれぞれ次の規則に従った移動を 10^{100} 回行います。

  • 今居るマスに書かれた文字に従って 1 マス移動する。すなわち、今居るマスに書かれた文字が L のとき左隣のマスに、R のとき右隣のマスに移動する。

10^{100} 回の移動の後に各マスに居る子どもの人数を求めてください。

制約

  • S は長さ 2 以上 10^5 以下の文字列であり、S の各文字は L または R である。
  • S1 文字目は RN 文字目は L である。

入力

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

S

出力

10^{100} 回の移動の後に各マスに居る子どもの人数を左のマスから順に出力せよ。


入力例 1

RRLRL

出力例 1

0 1 2 1 1
  • 1 回の移動の後に各マスに居る子どもの人数は左のマスから順に 0, 2, 1, 1, 1 人です。
  • 2 回の移動の後に各マスに居る子どもの人数は左のマスから順に 0, 1, 2, 1, 1 人です。
  • この移動を 10^{100} 回行った後に各マスに居る子どもの人数は左のマスから順に 0, 1, 2, 1, 1 人です。

入力例 2

RRLLLLRLRRLL

出力例 2

0 3 3 0 0 0 1 1 0 2 2 0

入力例 3

RRRLLRLLRRRLLLLL

出力例 3

0 0 3 2 0 2 1 0 0 0 4 4 0 0 0 0

Score : 400 points

Problem Statement

Given is a string S consisting of L and R.

Let N be the length of S. There are N squares arranged from left to right, and the i-th character of S from the left is written on the i-th square from the left.

The character written on the leftmost square is always R, and the character written on the rightmost square is always L.

Initially, one child is standing on each square.

Each child will perform the move below 10^{100} times:

  • Move one square in the direction specified by the character written in the square on which the child is standing. L denotes left, and R denotes right.

Find the number of children standing on each square after the children performed the moves.

Constraints

  • S is a string of length between 2 and 10^5 (inclusive).
  • Each character of S is L or R.
  • The first and last characters of S are R and L, respectively.

Input

Input is given from Standard Input in the following format:

S

Output

Print the number of children standing on each square after the children performed the moves, in order from left to right.


Sample Input 1

RRLRL

Sample Output 1

0 1 2 1 1
  • After each child performed one move, the number of children standing on each square is 0, 2, 1, 1, 1 from left to right.
  • After each child performed two moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.
  • After each child performed 10^{100} moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.

Sample Input 2

RRLLLLRLRRLL

Sample Output 2

0 3 3 0 0 0 1 1 0 2 2 0

Sample Input 3

RRRLLRLLRRRLLLLL

Sample Output 3

0 0 3 2 0 2 1 0 0 0 4 4 0 0 0 0
E - Max GCD

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 500

問題文

長さ N の整数列 A_1, A_2, \cdots, A_N があります。

次の操作を 0 回以上 K 回以下行うことができます。

  • i \neq j なる 1 以上 N 以下の 2 つの整数 i, j を選び、A_i1 を足し、A_j-1 を足す。この操作の後いずれかの要素が負になってもよい。

操作後の A の全ての要素を割り切る正の整数として考えられる値の最大値を計算してください。ただし、正の整数 x が整数 y を割り切るとは、ある整数 z を用いて y = xz と表せる場合を表します。

制約

  • 2 \leq N \leq 500
  • 1 \leq A_i \leq 10^6
  • 0 \leq K \leq 10^9
  • 入力は全て整数である

入力

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

N K
A_1 A_2 \cdots A_{N-1} A_{N}

出力

操作後の A の全ての要素を割り切る正の整数として考えられる値の最大値を出力せよ。


入力例 1

2 3
8 20

出力例 1

7

例えば以下の操作で、7A の全ての要素を割り切るようにできます。

  • i = 2, j = 1 とする。A(7, 21) となる。

また、8 以上の整数が A の全ての要素を割り切るようにはできません。


入力例 2

2 10
3 5

出力例 2

8

例えば、以下のように操作を 5 回行います。

  • i = 2, j = 1 とする。A(2, 6) となる。

  • i = 2, j = 1 とする。A(1, 7) となる。

  • i = 2, j = 1 とする。A(0, 8) となる。

  • i = 2, j = 1 とする。A(-1, 9) となる。

  • i = 1, j = 2 とする。A(0, 8) となる。

このとき、0 = 8 \times 0, 8 = 8 \times 1 と表せるので、8A の全ての要素を割り切ります。また、9 以上の整数が A の全ての要素を割り切るようにはできません。


入力例 3

4 5
10 1 2 22

出力例 3

7

入力例 4

8 7
1 7 5 6 8 2 6 5

出力例 4

5

Score : 500 points

Problem Statement

We have a sequence of N integers: A_1, A_2, \cdots, A_N.

You can perform the following operation between 0 and K times (inclusive):

  • Choose two integers i and j such that i \neq j, each between 1 and N (inclusive). Add 1 to A_i and -1 to A_j, possibly producing a negative element.

Compute the maximum possible positive integer that divides every element of A after the operations. Here a positive integer x divides an integer y if and only if there exists an integer z such that y = xz.

Constraints

  • 2 \leq N \leq 500
  • 1 \leq A_i \leq 10^6
  • 0 \leq K \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 \cdots A_{N-1} A_{N}

Output

Print the maximum possible positive integer that divides every element of A after the operations.


Sample Input 1

2 3
8 20

Sample Output 1

7

7 will divide every element of A if, for example, we perform the following operation:

  • Choose i = 2, j = 1. A becomes (7, 21).

We cannot reach the situation where 8 or greater integer divides every element of A.


Sample Input 2

2 10
3 5

Sample Output 2

8

Consider performing the following five operations:

  • Choose i = 2, j = 1. A becomes (2, 6).
  • Choose i = 2, j = 1. A becomes (1, 7).
  • Choose i = 2, j = 1. A becomes (0, 8).
  • Choose i = 2, j = 1. A becomes (-1, 9).
  • Choose i = 1, j = 2. A becomes (0, 8).

Then, 0 = 8 \times 0 and 8 = 8 \times 1, so 8 divides every element of A. We cannot reach the situation where 9 or greater integer divides every element of A.


Sample Input 3

4 5
10 1 2 22

Sample Output 3

7

Sample Input 4

8 7
1 7 5 6 8 2 6 5

Sample Output 4

5
F - Enclosed Points

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 600

問題文

2 次元平面上の N 個の点からなる集合 S があり、i 番目の点の座標は (x_i, y_i) です。N 個の点の x 座標、y 座標はそれぞれ相異なります。

S の空でない部分集合 T に対して f(T) を、各辺が座標軸と平行であって T の点を全て含むような最小の長方形に含まれる点の個数として定義します。より正確には、

  • f(T) := T に含まれる点について x 座標の最小値と最大値を それぞれ a, b, そして y 座標の最小値と最大値をそれぞれ c, d としたとき、a \leq x_i \leq b かつ c \leq y_i \leq d を満たす 1 \leq i \leq N の個数

S の空でない全ての部分集合 T についての f(T) の和を計算してください。答えは非常に大きくなることがあるので、998244353 で割った余りを出力してください。

制約

  • 1 \leq N \leq 2 \times 10^5
  • -10^9 \leq x_i, y_i \leq 10^9
  • x_i \neq x_j (i \neq j)
  • y_i \neq y_j (i \neq j)
  • 入力は全て整数である

入力

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

N
x_1 y_1
:
x_N y_N

出力

S の空でない全ての部分集合 T についての f(T) の和を 998244353 で割った余りを出力せよ。


入力例 1

3
-1 3
2 1
3 -2

出力例 1

13

1, 2, 3 番目の点をそれぞれ P_1, P_2, P_3 とします。S = \{P_1, P_2, P_3\} の空でない部分集合は 7 個あり、それぞれに対する f の値は次の通りです。

  • f(\{P_1\}) = 1
  • f(\{P_2\}) = 1
  • f(\{P_3\}) = 1
  • f(\{P_1, P_2\}) = 2
  • f(\{P_2, P_3\}) = 2
  • f(\{P_3, P_1\}) = 3
  • f(\{P_1, P_2, P_3\}) = 3

これらの和は 13 です。


入力例 2

4
1 4
2 1
3 3
4 2

出力例 2

34

入力例 3

10
19 -11
-3 -12
5 3
3 -15
8 -14
-9 -20
10 -9
0 2
-7 17
6 -6

出力例 3

7222

和を 998244353 で割った余りを出力することに注意してください。

Score : 600 points

Problem Statement

We have a set S of N points in a two-dimensional plane. The coordinates of the i-th point are (x_i, y_i). The N points have distinct x-coordinates and distinct y-coordinates.

For a non-empty subset T of S, let f(T) be the number of points contained in the smallest rectangle, whose sides are parallel to the coordinate axes, that contains all the points in T. More formally, we define f(T) as follows:

  • f(T) := (the number of integers i (1 \leq i \leq N) such that a \leq x_i \leq b and c \leq y_i \leq d, where a, b, c, and d are the minimum x-coordinate, the maximum x-coordinate, the minimum y-coordinate, and the maximum y-coordinate of the points in T)

Find the sum of f(T) over all non-empty subset T of S. Since it can be enormous, print the sum modulo 998244353.

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • -10^9 \leq x_i, y_i \leq 10^9
  • x_i \neq x_j (i \neq j)
  • y_i \neq y_j (i \neq j)
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
x_1 y_1
:
x_N y_N

Output

Print the sum of f(T) over all non-empty subset T of S, modulo 998244353.


Sample Input 1

3
-1 3
2 1
3 -2

Sample Output 1

13

Let the first, second, and third points be P_1, P_2, and P_3, respectively. S = \{P_1, P_2, P_3\} has seven non-empty subsets, and f has the following values for each of them:

  • f(\{P_1\}) = 1
  • f(\{P_2\}) = 1
  • f(\{P_3\}) = 1
  • f(\{P_1, P_2\}) = 2
  • f(\{P_2, P_3\}) = 2
  • f(\{P_3, P_1\}) = 3
  • f(\{P_1, P_2, P_3\}) = 3

The sum of these is 13.


Sample Input 2

4
1 4
2 1
3 3
4 2

Sample Output 2

34

Sample Input 3

10
19 -11
-3 -12
5 3
3 -15
8 -14
-9 -20
10 -9
0 2
-7 17
6 -6

Sample Output 3

7222

Be sure to print the sum modulo 998244353.