A - ?UPC

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100

問題文

文字列 S が与えられます。ここで、S1 文字目は英大文字、2 文字目以降は英小文字です。

S1 文字目と UPC をこの順に結合した文字列を出力してください。

制約

  • S は長さ 1 以上 100 以下の文字列
  • S1 文字目は英大文字
  • S2 文字目以降は英小文字

入力

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

S

出力

S1 文字目と UPC をこの順に結合した文字列を出力せよ。


入力例 1

Kyoto

出力例 1

KUPC

Kyoto1 文字目は K であるため、KUPC を結合した KUPC を出力します。


入力例 2

Tohoku

出力例 2

TUPC

Score : 100 points

Problem Statement

You are given a string S. Here, the first character of S is an uppercase English letter, and the second and subsequent characters are lowercase English letters.

Print the string formed by concatenating the first character of S and UPC in this order.

Constraints

  • S is a string of length between 1 and 100, inclusive.
  • The first character of S is an uppercase English letter.
  • The second and subsequent characters of S are lowercase English letters.

Input

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

S

Output

Print the string formed by concatenating the first character of S and UPC in this order.


Sample Input 1

Kyoto

Sample Output 1

KUPC

The first character of Kyoto is K, so concatenate K and UPC, and print KUPC.


Sample Input 2

Tohoku

Sample Output 2

TUPC
B - Heavy Snake

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

N 匹のヘビがいます。

はじめ、i 匹目のヘビの太さは T_i、長さは L_i です。

ヘビの重さは太さと長さの積となります。

1 \leq k \leq D を満たす各整数 k について、すべてのヘビの長さが k 伸びたときの最も重いヘビの重さを求めてください。

制約

  • 1 \leq N, D \leq 100
  • 1 \leq T_i, L_i \leq 100
  • 入力される値はすべて整数

入力

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

N D
T_1 L_1
T_2 L_2
\vdots
T_N L_N

出力

D 行出力せよ。k 行目には、すべてのヘビの長さが k 伸びたときの最も重いヘビの重さを出力せよ。


入力例 1

4 3
3 3
5 1
2 4
1 10

出力例 1

12
15
20

すべてのヘビの長さが 1 伸びたとき、ヘビの重さはそれぞれ 12, 10, 10, 11 となるので 1 行目には 12 を出力します。

すべてのヘビの長さが 2 伸びたとき、ヘビの重さはそれぞれ 15, 15, 12, 12 となるので 2 行目には 15 を出力します。

すべてのヘビの長さが 3 伸びたとき、ヘビの重さはそれぞれ 18, 20, 14, 13 となるので 3 行目には 20 を出力します。


入力例 2

1 4
100 100

出力例 2

10100
10200
10300
10400

Score : 200 points

Problem Statement

There are N snakes.

Initially, the thickness of the i-th snake is T_i, and its length is L_i.

The weight of a snake is defined as the product of its thickness and length.

For each integer k satisfying 1 \leq k \leq D, find the weight of the heaviest snake when every snake's length has increased by k.

Constraints

  • 1 \leq N, D \leq 100
  • 1 \leq T_i, L_i \leq 100
  • All input values are integers.

Input

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

N D
T_1 L_1
T_2 L_2
\vdots
T_N L_N

Output

Print D lines. The k-th line should contain the weight of the heaviest snake when every snake's length has increased by k.


Sample Input 1

4 3
3 3
5 1
2 4
1 10

Sample Output 1

12
15
20

When every snake’s length has increased by 1, the snakes' weights become 12, 10, 10, 11, so print 12 on the first line.

When every snake’s length has increased by 2, the snakes' weights become 15, 15, 12, 12, so print 15 on the second line.

When every snake’s length has increased by 3, the snakes' weights become 18, 20, 14, 13, so print 20 on the third line.


Sample Input 2

1 4
100 100

Sample Output 2

10100
10200
10300
10400
C - Various Kagamimochi

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

N 個の餅が小さいほうから順に並んでいます。 i 番目 (1\leq i\leq N) の餅の大きさは A _ i です。

2 つの餅 A,B の大きさをそれぞれ a,b としたとき、ab の半分以下であるとき、かつそのときに限り、餅 A を餅 B の上に乗せて鏡餅を 1 つ作ることができます。

N 個の餅から 2 つの餅を選び、一方をもう一方の上に乗せることで鏡餅を 1 つ作ります。

何種類の鏡餅を作ることができるか求めてください。

ただし、鏡餅を構成する餅の大きさが同じでも、少なくとも一方が異なる餅であれば別の種類の鏡餅として数えます。

制約

  • 2\leq N\leq 5\times 10 ^ 5
  • 1\leq A _ i\leq 10 ^ 9\ (1\leq i\leq N)
  • A _ i\leq A _ {i+1}\ (1\leq i\lt N)
  • 入力はすべて整数

入力

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

N
A _ 1 A _ 2 \cdots A _ N

出力

作ることができる鏡餅の種類数を出力せよ。


入力例 1

6
2 3 4 4 7 10

出力例 1

8

与えられた餅の大きさは以下のようになっています。

このとき、以下の 8 種類の鏡餅を作ることができます。

大きさ 4 の餅の上に大きさ 2 の餅を乗せた鏡餅や、大きさ 10 の餅の上に大きさ 4 の餅を乗せた鏡餅は 2 種類あることに注意してください。


入力例 2

3
387 388 389

出力例 2

0

鏡餅を 1 種類も作ることができない場合もあります。


入力例 3

32
1 2 4 5 8 10 12 16 19 25 33 40 50 64 87 101 149 175 202 211 278 314 355 405 412 420 442 481 512 582 600 641

出力例 3

388

Score : 300 points

Problem Statement

There are N mochi (rice cakes) arranged in ascending order of size. The size of the i-th mochi (1 \leq i \leq N) is A_i.

Given two mochi A and B, with sizes a and b respectively, you can make one kagamimochi (a stacked rice cake) by placing mochi A on top of mochi B if and only if a is at most half of b.

You choose two mochi out of the N mochi, and place one on top of the other to form one kagamimochi.

Find how many different kinds of kagamimochi can be made.

Two kagamimochi are distinguished if at least one of the mochi is different, even if the sizes of the mochi are the same.

Constraints

  • 2 \leq N \leq 5 \times 10^5
  • 1 \leq A_i \leq 10^9 \ (1 \leq i \leq N)
  • A_i \leq A_{i+1} \ (1 \leq i < N)
  • All input values are integers.

Input

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

N
A_1 A_2 \cdots A_N

Output

Print the number of different kinds of kagamimochi that can be made.


Sample Input 1

6
2 3 4 4 7 10

Sample Output 1

8

The sizes of the given mochi are as follows:

In this case, you can make the following eight kinds of kagamimochi:

Note that there are two kinds of kagamimochi where a mochi of size 4 is topped by a mochi of size 2, and two kinds where a mochi of size 10 is topped by a mochi of size 4.


Sample Input 2

3
387 388 389

Sample Output 2

0

It is possible that you cannot make any kagamimochi.


Sample Input 3

32
1 2 4 5 8 10 12 16 19 25 33 40 50 64 87 101 149 175 202 211 278 314 355 405 412 420 442 481 512 582 600 641

Sample Output 3

388
D - Coming of Age Celebration

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 400

問題文

ある星には N 人の宇宙人がおり、全員未成年です。

i 人目の宇宙人は現在 A_i 個の石を所持しており、ちょうど i 年後に成人します。

この星では誰かが成人するとき、石を 1 個以上所持している成人全員が、成人する宇宙人に成人祝いとして石を 1 個渡します。

N 年後に各宇宙人が所持している石の個数を求めてください。

ただし、今後新たな宇宙人は産まれないものとします。

制約

  • 1 \leq N \leq 5 \times 10^5
  • 0 \leq A_i \leq 5 \times 10^5
  • 入力される値はすべて整数

入力

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

N
A_1 A_2 \ldots A_N

出力

N 年後に i 人目の宇宙人が所持している石の個数を B_i として B_1, B_2, \ldots, B_N をこの順に空白区切りで出力せよ。


入力例 1

4
5 0 9 3

出力例 1

2 0 10 5

i 人目の宇宙人が持っている石の個数を C_i で表します。

はじめ (C_1, C_2, C_3, C_4) = (5, 0, 9, 3) です。

1 年後には (C_1, C_2, C_3, C_4) = (5, 0, 9, 3) となります。

2 年後には (C_1, C_2, C_3, C_4) = (4, 1, 9, 3) となります。

3 年後には (C_1, C_2, C_3, C_4) = (3, 0, 11, 3) となります。

4 年後には (C_1, C_2, C_3, C_4) = (2, 0, 10, 5) となります。


入力例 2

5
4 6 7 2 5

出力例 2

0 4 7 4 9

入力例 3

10
2 9 1 2 0 4 6 7 1 5

出力例 3

0 2 0 0 0 4 7 10 4 10

Score : 400 points

Problem Statement

On a certain planet, there are N aliens, all of whom are minors.

The i-th alien currently has A_i stones, and will become an adult exactly i years later.

When someone becomes an adult on this planet, every adult who has at least one stone gives exactly one stone as a congratulatory gift to the alien who has just become an adult.

Find how many stones each alien will have after N years.

Assume that no new aliens will be born in the future.

Constraints

  • 1 \leq N \leq 5 \times 10^5
  • 0 \leq A_i \leq 5 \times 10^5
  • 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

Let B_i be the number of stones owned by the i-th alien after N years. Print B_1, B_2, \ldots, B_N in this order, separated by spaces.


Sample Input 1

4
5 0 9 3

Sample Output 1

2 0 10 5

Let C_i be the number of stones that the i-th alien has at a given time.

Initially, (C_1, C_2, C_3, C_4) = (5, 0, 9, 3).

After 1 year, (C_1, C_2, C_3, C_4) = (5, 0, 9, 3).

After 2 years, (C_1, C_2, C_3, C_4) = (4, 1, 9, 3).

After 3 years, (C_1, C_2, C_3, C_4) = (3, 0, 11, 3).

After 4 years, (C_1, C_2, C_3, C_4) = (2, 0, 10, 5).


Sample Input 2

5
4 6 7 2 5

Sample Output 2

0 4 7 4 9

Sample Input 3

10
2 9 1 2 0 4 6 7 1 5

Sample Output 3

0 2 0 0 0 4 7 10 4 10
E - Simultaneous Kagamimochi

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 450

問題文

N 個の餅が小さいほうから順に並んでいます。 i 番目 (1\leq i\leq N) の餅の大きさは A _ i です。

2 つの餅 A,B の大きさをそれぞれ a,b としたとき、ab の半分以下であるとき、かつそのときに限り、餅 A を餅 B の上に乗せて鏡餅を 1 つ作ることができます。

同時にいくつの鏡餅を作ることができるか求めてください。

より厳密には、以下ができるような最大の非負整数 K を求めてください。

  • N 個の餅から 2K 個の餅を選んで K 個の 2 つ組に分け、それぞれの組について一方をもう一方の上に乗せることで鏡餅を K 個作る。

制約

  • 2\leq N\leq 5\times 10 ^ 5
  • 1\leq A _ i\leq 10 ^ 9\ (1\leq i\leq N)
  • A _ i\leq A _ {i+1}\ (1\leq i\lt N)
  • 入力はすべて整数

入力

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

N
A _ 1 A _ 2 \dotsc A _ N

出力

同時に K 個鏡餅を作れるような最大の K を出力せよ。


入力例 1

6
2 3 4 4 7 10

出力例 1

3

与えられた餅の大きさは以下のようになっています。

このとき、以下の 3 つの鏡餅を同時に作ることができます。

6 つの餅から 4 つ以上の鏡餅を作ることはできないので、3 を出力してください。


入力例 2

3
387 388 389

出力例 2

0

鏡餅を 1 つも作ることができない場合もあります。


入力例 3

24
307 321 330 339 349 392 422 430 477 481 488 537 541 571 575 602 614 660 669 678 712 723 785 792

出力例 3

6

Score : 450 points

Problem Statement

There are N mochi (rice cakes), arranged in ascending order of size. The size of the i-th mochi (1\leq i\leq N) is A_i.

Given two mochi A and B, with sizes a and b respectively, you can make one kagamimochi (a stacked rice cake) by placing mochi A on top of mochi B if and only if a is at most half of b.

Find how many kagamimochi can be made simultaneously.

More precisely, find the maximum non-negative integer K for which the following is possible:

  • From the N mochi, choose 2K of them to form K pairs. For each pair, place one mochi on top of the other, to make K kagamimochi.

Constraints

  • 2 \leq N \leq 5 \times 10^5
  • 1 \leq A_i \leq 10^9 \ (1 \leq i \leq N)
  • A_i \leq A_{i+1} \ (1 \leq i < N)
  • All input values are integers.

Input

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

N
A_1 A_2 \dotsc A_N

Output

Print the maximum K such that K kagamimochi can be made simultaneously.


Sample Input 1

6
2 3 4 4 7 10

Sample Output 1

3

The sizes of the given mochi are as follows:

In this case, you can make the following three kagamimochi simultaneously:

It is not possible to make four or more kagamimochi from six mochi, so print 3.


Sample Input 2

3
387 388 389

Sample Output 2

0

It is possible that you cannot make any kagamimochi.


Sample Input 3

24
307 321 330 339 349 392 422 430 477 481 488 537 541 571 575 602 614 660 669 678 712 723 785 792

Sample Output 3

6
F - Dangerous Sugoroku

Time Limit: 4 sec / Memory Limit: 1024 MiB

配点 : 550

問題文

N 個のマスが 1 列に並んでおり、順に 1, 2, \ldots, N の番号が付けられています。

M 個の整数組 (L_1, R_1), \ldots, (L_M, R_M) が与えられます。

マス j はある i に対して L_i \leq j \leq R_i を満たすとき、またそのときに限り 悪いマス であると定めます。

マス 1 から以下の行動を繰り返すことでマス N に移動できるか判定してください。

  • 現在位置しているマスをマス x とする。以下の条件をすべて満たすような整数 i を選び、マス x + i に移動する。
    • A \leq i \leq B
    • x + i \leq N
    • マス x + i は悪いマスでない

制約

  • 2 \leq N \leq 10^{12}
  • 0 \leq M \leq 2 \times 10^4
  • 1 \leq A \leq B \leq 20
  • 1 < L_i \leq R_i < N (1 \leq i \leq M)
  • R_i < L_{i + 1} (1 \leq i \leq M - 1)
  • 入力される値はすべて整数

入力

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

N M A B
L_1 R_1
L_2 R_2
\vdots
L_M R_M

出力

問題文中の行動を繰り返すことでマス N に移動できる場合は Yes を、そうでない場合は No を出力せよ。


入力例 1

24 2 3 5
7 8
17 20

出力例 1

Yes

マス 1 \to 6 \to 9 \to 12 \to 16 \to 21 \to 24 のように移動することでマス N に移動することができます。


入力例 2

30 1 5 8
4 24

出力例 2

No

入力例 3

100 4 10 11
16 18
39 42
50 55
93 99

出力例 3

Yes

Score : 550 points

Problem Statement

There are N squares arranged in a row, labeled 1, 2, \ldots, N from left to right.

You are given M pairs of integers (L_1, R_1), \ldots, (L_M, R_M).

A square j is defined to be bad if and only if there exists some i such that L_i \leq j \leq R_i.

Determine whether you can move from square 1 to square N by repeatedly performing the following action:

  • Let your current square be x. Choose an integer i that satisfies all of the following conditions, and move to square x + i.
    • A \leq i \leq B
    • x + i \leq N
    • Square x + i is not bad.

Constraints

  • 2 \leq N \leq 10^{12}
  • 0 \leq M \leq 2 \times 10^4
  • 1 \leq A \leq B \leq 20
  • 1 < L_i \leq R_i < N \ (1 \leq i \leq M)
  • R_i < L_{i+1} \ (1 \leq i \leq M - 1)
  • All input values are integers.

Input

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

N M A B
L_1 R_1
L_2 R_2
\vdots
L_M R_M

Output

If it is possible to reach square N by repeating the action described in the problem statement, print Yes. Otherwise, print No.


Sample Input 1

24 2 3 5
7 8
17 20

Sample Output 1

Yes

You can move to square N in this way: 1 \to 6 \to 9 \to 12 \to 16 \to 21 \to 24.


Sample Input 2

30 1 5 8
4 24

Sample Output 2

No

Sample Input 3

100 4 10 11
16 18
39 42
50 55
93 99

Sample Output 3

Yes
G - Simultaneous Kagamimochi 2

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 575

問題文

N 個の餅が小さいほうから順に並んでいます。 i 番目 (1\leq i\leq N) の餅の大きさは A _ i です。

2 つの餅 A,B の大きさをそれぞれ a,b としたとき、ab の半分以下であるとき、かつそのときに限り、餅 A を餅 B の上に乗せて鏡餅を 1 つ作ることができます。

整数の 2 つ組が Q 個与えられます。 i 番目 (1\leq i\leq Q)2 つ組を (L _ i,R _ i) として、次の問題をすべての i について解いてください。

L _ i 番目から R _ i 番目までの R _ i-L _ i+1 個の餅だけを使って、同時にいくつの鏡餅を作ることができるか求めてください。

より厳密には、以下ができるような最大の非負整数 K を求めてください。

  • L _ i 番目から R _ i 番目までの R _ i-L _ i+1 個の餅から 2K 個の餅を選んで K 個の 2 つ組に分け、それぞれの組について一方をもう一方の上に乗せることで鏡餅を K 個作る。

制約

  • 2\leq N\leq 2\times 10 ^ 5
  • 1\leq A _ i\leq 10 ^ 9\ (1\leq i\leq N)
  • A _ i\leq A _ {i+1}\ (1\leq i\lt N)
  • 1\leq Q\leq 2\times 10 ^ 5
  • 1\leq L _ i\lt R _ i\leq N\ (1\leq i\leq Q)
  • 入力はすべて整数

入力

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

N
A _ 1 A _ 2 \dotsc A _ N
Q
L _ 1 R _ 1
L _ 2 R _ 2
\vdots
L _ Q R _ Q

出力

Q 行出力せよ。 i 行目 (1\leq i\leq Q) には、i 番目の 2 つ組に対応する問題の答えを出力せよ。


入力例 1

11
1 1 2 3 4 4 7 10 11 12 20
5
2 5
3 8
7 11
1 2
1 11

出力例 1

2
3
1
0
5

それぞれの問題に対する答えは以下のようになります。 鏡餅の作り方は一例です。

  • それぞれの餅の大きさは (1,2,3,4) です。(1,3),(2,4)2 つの鏡餅を作ることができます。
  • それぞれの餅の大きさは (2,3,4,4,7,10) です。(2,4),(3,7),(4,10)3 つの鏡餅を作ることができます。
  • それぞれの餅の大きさは (7,10,11,12,20) です。(10,20)1 つの鏡餅を作ることができます。
  • それぞれの餅の大きさは (1,1) です。1 つも鏡餅を作ることができません。
  • それぞれの餅の大きさは (1,1,2,3,4,4,7,10,11,12,20) です。(1,2),(1,3),(4,10),(4,11),(7,20)5 つの鏡餅を作ることができます。

以上より、2 3 1 0 5 をこの順に出力してください。


入力例 2

24
127 148 170 174 258 311 331 414 416 436 517 523 532 587 591 638 660 748 760 776 837 857 972 984
15
7 11
8 9
8 13
12 15
9 23
1 17
8 12
1 5
6 17
3 7
12 19
13 18
7 22
1 12
14 15

出力例 2

0
0
0
0
2
6
0
1
1
0
0
0
3
5
0

Score : 575 points

Problem Statement

There are N mochi (rice cakes), arranged in ascending order of size. The size of the i-th mochi (1\leq i\leq N) is A_i.

Given two mochi A and B, with sizes a and b respectively, you can make one kagamimochi (a stacked rice cake) by placing mochi A on top of mochi B if and only if a is at most half of b.

You are given Q integer pairs. Let (L_i, R_i) be the i-th pair (1\leq i\leq Q), and solve the following problem for each i:

Using only the R_i - L_i + 1 mochi from the L_i-th to the R_i-th, how many kagamimochi can you make simultaneously?

More precisely, find the maximum non-negative integer K such that:

  • Out of the R_i - L_i + 1 mochi from the L_i-th to the R_i-th, choose 2K mochi and form K pairs. For each pair, place one mochi on top of the other, to make K kagamimochi.

Constraints

  • 2 \leq N \leq 2 \times 10^5
  • 1 \leq A_i \leq 10^9 \ (1 \leq i \leq N)
  • A_i \leq A_{i+1} \ (1 \leq i < N)
  • 1 \leq Q \leq 2 \times 10^5
  • 1 \leq L_i < R_i \leq N \ (1 \leq i \leq Q)
  • All input values are integers.

Input

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

N
A_1 A_2 \dotsc A_N
Q
L_1 R_1
L_2 R_2
\vdots
L_Q R_Q

Output

Print Q lines. The i-th line (1\leq i\leq Q) should contain the answer to the i-th query.


Sample Input 1

11
1 1 2 3 4 4 7 10 11 12 20
5
2 5
3 8
7 11
1 2
1 11

Sample Output 1

2
3
1
0
5

The answers to each query are as follows. One possible way to make the kagamimochi is given for each query.

  • The mochi sizes are (1, 2, 3, 4). You can make the two kagamimochi (1,3) and (2,4).
  • The mochi sizes are (2, 3, 4, 4, 7, 10). You can make the three kagamimochi (2,4), (3,7), and (4,10).
  • The mochi sizes are (7, 10, 11, 12, 20). You can make one kagamimochi (10,20).
  • The mochi sizes are (1, 1). You cannot make any kagamimochi.
  • The mochi sizes are (1, 1, 2, 3, 4, 4, 7, 10, 11, 12, 20). You can make five kagamimochi (1,2), (1,3), (4,10), (4,11), and (7,20).

Hence, print 2, 3, 1, 0, 5 in this order.


Sample Input 2

24
127 148 170 174 258 311 331 414 416 436 517 523 532 587 591 638 660 748 760 776 837 857 972 984
15
7 11
8 9
8 13
12 15
9 23
1 17
8 12
1 5
6 17
3 7
12 19
13 18
7 22
1 12
14 15

Sample Output 2

0
0
0
0
2
6
0
1
1
0
0
0
3
5
0