A - Nickname

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 100

問題文

あなたは同じ授業を受けている男性に名前を尋ねました。彼は S と名乗りました。S は英小文字からなる長さ 3 以上 20 以下の文字列です。 あなたは S から適当に連続する 3 文字を選んで、彼のあだ名とすることにしました。彼のあだ名として適切な文字列を 1 つ出力してください。

制約

  • 3 ≦ |S| ≦ 20
  • S は英小文字からなる。

入力

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

S

出力

答えを出力せよ。


入力例 1

takahashi

出力例 1

tak

入力例 2

naohiro

出力例 2

nao

Score : 100 points

Problem Statement

When you asked some guy in your class his name, he called himself S, where S is a string of length between 3 and 20 (inclusive) consisting of lowercase English letters. You have decided to choose some three consecutive characters from S and make it his nickname. Print a string that is a valid nickname for him.

Constraints

  • 3 \leq |S| \leq 20
  • S consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S

Output

Print your answer.


Sample Input 1

takahashi

Sample Output 1

tak

Sample Input 2

naohiro

Sample Output 2

nao
B - Tag

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 200

問題文

2 人の子供が数直線上で鬼ごっこをしています。鬼役の子供は今座標 A にいて 1 秒あたり距離 V 移動することができます。 また鬼から逃げている子供は今座標 B にいて 1 秒あたり距離 W 移動することができます。

鬼役の子供は相手と同じ座標にいるとき、相手を捕まえることができます。 今から T 秒の間に(ちょうど T 秒後も含む)鬼役の子供がもう一方の子供を捕まえることができるかどうかを判定してください。 ただし、2 人の子供は最適に動くとします。

制約

  • -10^9 \leqq A,B \leqq 10^9
  • 1 \leqq V,W \leqq 10^9
  • 1 \leqq T \leqq 10^9
  • A \neq B
  • 入力で与えられる値はすべて整数である。

入力

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

A V
B W
T

出力

鬼が捕まえることができるなら YES と、そうでないならば NO と出力せよ。


入力例 1

1 2
3 1
3

出力例 1

YES

入力例 2

1 2
3 2
3

出力例 2

NO

入力例 3

1 2
3 3
3

出力例 3

NO

Score : 200 points

Problem Statement

Two children are playing tag on a number line. (In the game of tag, the child called "it" tries to catch the other child.) The child who is "it" is now at coordinate A, and he can travel the distance of V per second. The other child is now at coordinate B, and she can travel the distance of W per second.

He can catch her when his coordinate is the same as hers. Determine whether he can catch her within T seconds (including exactly T seconds later). We assume that both children move optimally.

Constraints

  • -10^9 \leq A,B \leq 10^9
  • 1 \leq V,W \leq 10^9
  • 1 \leq T \leq 10^9
  • A \neq B
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

A V
B W
T

Output

If "it" can catch the other child, print YES; otherwise, print NO.


Sample Input 1

1 2
3 1
3

Sample Output 1

YES

Sample Input 2

1 2
3 2
3

Sample Output 2

NO

Sample Input 3

1 2
3 3
3

Sample Output 3

NO
C - Lamps

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 500

問題文

数直線上に電球が N 個並んでおり、電球には左から順に 1 から N までの番号がついています。 電球 i は座標 i にあります。

電球には光の強さを表す非負整数値が定まっており、 座標 x に光の強さ d の電球があるとき、その電球は座標 x-d-0.5 から座標 x+d+0.5 までの区間を照らします。 初めは電球 i の光の強さは A_i です。 そこで、以下の操作を K 回繰り返し行います。

  • 1 以上 N 以下の各整数 i に対し、操作時に座標 i を照らしている電球の個数を B_i とする。そして、各電球 i の光の強さを B_i に変更する。

K 回の操作を行った後の各電球の光の強さを求めてください。

制約

  • 1 \leqq N \leqq 2 \times 10^5
  • 1 \leqq K \leqq 2 \times 10^5
  • 0 \leqq A_i \leqq N

入力

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

N K
A_1 A_2 \ldots A_N

出力

K 回の操作を行った後の電球 i の光の強さ A{'}_i を、以下の形式で標準出力に出力せよ。

A{'}_1 A{'}_2 \ldots A{'}_N

入力例 1

5 1
1 0 0 1 0

出力例 1

1 2 2 1 2 

始めに座標 1 を照らしている電球は電球 1 のみであるので、操作後の電球 1 の強さは 1 になります。 また、始めに座標 2 を照らしている電球は電球 1 と電球 2 であるので、操作後の電球 2 の強さは 2 になります。


入力例 2

5 2
1 0 0 1 0

出力例 2

3 3 4 4 3 

Score : 500 points

Problem Statement

We have N bulbs arranged on a number line, numbered 1 to N from left to right. Bulb i is at coordinate i.

Each bulb has a non-negative integer parameter called intensity. When there is a bulb of intensity d at coordinate x, the bulb illuminates the segment from coordinate x-d-0.5 to x+d+0.5. Initially, the intensity of Bulb i is A_i. We will now do the following operation K times in a row:

  • For each integer i between 1 and N (inclusive), let B_i be the number of bulbs illuminating coordinate i. Then, change the intensity of each bulb i to B_i.

Find the intensity of each bulb after the K operations.

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq K \leq 2 \times 10^5
  • 0 \leq A_i \leq N

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 \ldots A_N

Output

Print the intensity A{'}_i of each bulb i after the K operations to Standard Output in the following format:

A{'}_1 A{'}_2 \ldots A{'}_N

Sample Input 1

5 1
1 0 0 1 0

Sample Output 1

1 2 2 1 2 

Initially, only Bulb 1 illuminates coordinate 1, so the intensity of Bulb 1 becomes 1 after the operation. Similarly, the bulbs initially illuminating coordinate 2 are Bulb 1 and 2, so the intensity of Bulb 2 becomes 2.


Sample Input 2

5 2
1 0 0 1 0

Sample Output 2

3 3 4 4 3 
D - Knapsack Queries on a tree

Time Limit: 3 sec / Memory Limit: 1024 MB

配点 : 700

問題文

N 頂点からなる根付き二分木があり、各頂点には 1 から N までの番号がついています。 頂点 1 が根であり、頂点 i (i \geqq 2) の親は頂点 \left[ \frac{i}{2} \right] です。

各頂点には 1 つのアイテムがあります。頂点 i にあるアイテムの価値は V_i であり、重さは W_i です。 そこで、次のクエリに Q 回答えてください。

  • 二分木の頂点 v 及び正の整数 L が与えられる。 v 及び v の先祖にあるアイテムを、重さの合計が L 以下となるようにいくつか(0 個でもよい)選ぶ。 このとき、選んだアイテムの価値の総和の最大値を求めよ。

ただし、頂点 u が頂点 v の先祖であるとは、頂点 u が頂点 v の間接的な親である、つまり、 w_1=vw_k=u、さらに各 i について w_{i+1}w_i の親となるような頂点の列 w_1,w_2,\ldots,w_k (k\geqq 2) が存在することを指します。

制約

  • 1 \leqq N < 2^{18}
  • 1 \leqq Q \leqq 10^5
  • 1 \leqq V_i \leqq 10^5
  • 1 \leqq W_i \leqq 10^5
  • 各クエリで指定される v, L1 \leqq v \leqq N, 1 \leqq L \leqq 10^5 を満たす。
  • 入力で与えられる値はすべて整数である。

入力

i 回目のクエリで指定される v, L をそれぞれ v_i, L_i とする。 このとき、入力は以下の形式で標準入力から与えられる。

N
V_1 W_1
:
V_N W_N
Q
v_1 L_1
:
v_Q L_Q

出力

1 から Q までの各整数 i について、 i 回目のクエリに対する答えを i 行目に出力せよ。


入力例 1

3
1 2
2 3
3 4
3
1 1
2 5
3 5

出力例 1

0
3
3

最初のクエリでは、選ぶことのできるアイテムは (V,W)=(1,2) なるアイテムのみであるので、 L=1 より 1 つもアイテムを選ぶことができません。 したがって、答えは 0 になります。

一方で 2 番目のクエリでは、選ぶことのできるアイテムは (V,W)=(1,2) なるアイテムと (V,W)=(2,3) なるアイテムの 2 つであり、 L=5 より両方を選ぶことができます。 したがって、答えは 3 になります。


入力例 2

15
123 119
129 120
132 112
126 109
118 103
115 109
102 100
130 120
105 105
132 115
104 102
107 107
127 116
121 104
121 115
8
8 234
9 244
10 226
11 227
12 240
13 237
14 206
15 227

出力例 2

256
255
250
247
255
259
223
253

Score : 700 points

Problem Statement

We have a rooted binary tree with N vertices, where the vertices are numbered 1 to N. Vertex 1 is the root, and the parent of Vertex i (i \geq 2) is Vertex \left[ \frac{i}{2} \right].

Each vertex has one item in it. The item in Vertex i has a value of V_i and a weight of W_i. Now, process the following query Q times:

  • Given are a vertex v of the tree and a positive integer L. Let us choose some (possibly none) of the items in v and the ancestors of v so that their total weight is at most L. Find the maximum possible total value of the chosen items.

Here, Vertex u is said to be an ancestor of Vertex v when u is an indirect parent of v, that is, there exists a sequence of vertices w_1,w_2,\ldots,w_k (k\geq 2) where w_1=v, w_k=u, and w_{i+1} is the parent of w_i for each i.

Constraints

  • All values in input are integers.
  • 1 \leq N < 2^{18}
  • 1 \leq Q \leq 10^5
  • 1 \leq V_i \leq 10^5
  • 1 \leq W_i \leq 10^5
  • For the values v and L given in each query, 1 \leq v \leq N and 1 \leq L \leq 10^5.

Input

Let v_i and L_i be the values v and L given in the i-th query. Then, Input is given from Standard Input in the following format:

N
V_1 W_1
:
V_N W_N
Q
v_1 L_1
:
v_Q L_Q

Output

For each integer i from 1 through Q, the i-th line should contain the response to the i-th query.


Sample Input 1

3
1 2
2 3
3 4
3
1 1
2 5
3 5

Sample Output 1

0
3
3

In the first query, we are given only one choice: the item with (V, W)=(1,2). Since L = 1, we cannot actually choose it, so our response should be 0.

In the second query, we are given two choices: the items with (V, W)=(1,2) and (V, W)=(2,3). Since L = 5, we can choose both of them, so our response should be 3.


Sample Input 2

15
123 119
129 120
132 112
126 109
118 103
115 109
102 100
130 120
105 105
132 115
104 102
107 107
127 116
121 104
121 115
8
8 234
9 244
10 226
11 227
12 240
13 237
14 206
15 227

Sample Output 2

256
255
250
247
255
259
223
253
E - O(rand)

Time Limit: 3 sec / Memory Limit: 1024 MB

配点 : 800

問題文

N 個の相異なる非負整数 A_1,A_2,\ldots,A_N が与えられます。 与えられた数の中から 1 個以上 K 個以下の数を選ぶ方法であって、次の 2 つの条件を満たすような方法は何通りあるか求めてください。

  • 選ばれた数のビットごとの論理積は S である。
  • 選ばれた数のビットごとの論理和は T である。

制約

  • 1 \leqq N \leqq 50
  • 1 \leqq K \leqq N
  • 0 \leqq A_i < 2^{18}
  • 0 \leqq S < 2^{18}
  • 0 \leqq T < 2^{18}
  • A_i \neq A_j (1 \leqq i < j \leqq N)

入力

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

N K S T
A_1 A_2 ... A_N

出力

答えを出力せよ。


入力例 1

3 3 0 3
1 2 3

出力例 1

2

\{1,2\} もしくは \{1,2,3\} と数を選ぶと条件を満たします。


入力例 2

5 3 1 7
3 4 9 1 5

出力例 2

2

入力例 3

5 4 0 15
3 4 9 1 5

出力例 3

3

Score : 800 points

Problem Statement

Given are N pairwise distinct non-negative integers A_1,A_2,\ldots,A_N. Find the number of ways to choose a set of between 1 and K numbers (inclusive) from the given numbers so that the following two conditions are satisfied:

  • The bitwise AND of the chosen numbers is S.
  • The bitwise OR of the chosen numbers is T.

Constraints

  • 1 \leq N \leq 50
  • 1 \leq K \leq N
  • 0 \leq A_i < 2^{18}
  • 0 \leq S < 2^{18}
  • 0 \leq T < 2^{18}
  • A_i \neq A_j (1 \leq i < j \leq N)

Input

Input is given from Standard Input in the following format:

N K S T
A_1 A_2 ... A_N

Output

Print the answer.


Sample Input 1

3 3 0 3
1 2 3

Sample Output 1

2

The conditions are satisfied when we choose \{1,2\} or \{1,2,3\}.


Sample Input 2

5 3 1 7
3 4 9 1 5

Sample Output 2

2

Sample Input 3

5 4 0 15
3 4 9 1 5

Sample Output 3

3
F - Triangles

Time Limit: 4 sec / Memory Limit: 1024 MB

配点 : 1000

問題文

2 次元平面上に (0,0), (W,0), (0,H), (W,H) を頂点とするような長方形 R があります。 W, H は正の整数です。 このとき、次の条件をすべて満たすような 2 次元平面上の三角形 \Delta の個数を求めてください。

  • \Delta の各頂点は格子点である。つまり、座標がいずれも整数である。
  • \DeltaR は頂点を共有しない。
  • \Delta の各頂点は R の周上にあり、それぞれが属する辺は相異なる。
  • \Delta の内部(周上及び頂点を含まない)にある格子点は高々 K 個である。

制約

  • 1 \leqq W \leqq 10^5
  • 1 \leqq H \leqq 10^5
  • 0 \leqq K \leqq 10^5
  • 入力で与えられる値はすべて整数である。

入力

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

W H K

出力

答えを出力せよ。


入力例 1

2 3 1

出力例 1

12

例えば (1,0), (0,2), (2,2) を頂点とするような三角形は、 内部に格子点が 1 つしか存在しないので、条件を満たします。


入力例 2

5 4 5

出力例 2

132

入力例 3

100 100 1000

出力例 3

461316

Score : 1000 points

Problem Statement

In a two-dimensional plane, we have a rectangle R whose vertices are (0,0), (W,0), (0,H), and (W,H), where W and H are positive integers. Here, find the number of triangles \Delta in the plane that satisfy all of the following conditions:

  • Each vertex of \Delta is a grid point, that is, has integer x- and y-coordinates.
  • \Delta and R shares no vertex.
  • Each vertex of \Delta lies on the perimeter of R, and all the vertices belong to different sides of R.
  • \Delta contains at most K grid points strictly within itself (excluding its perimeter and vertices).

Constraints

  • 1 \leq W \leq 10^5
  • 1 \leq H \leq 10^5
  • 0 \leq K \leq 10^5

Input

Input is given from Standard Input in the following format:

W H K

Output

Print the answer.


Sample Input 1

2 3 1

Sample Output 1

12

For example, the triangle with the vertices (1,0), (0,2), and (2,2) contains just one grid point within itself and thus satisfies the condition.


Sample Input 2

5 4 5

Sample Output 2

132

Sample Input 3

100 100 1000

Sample Output 3

461316