E - Minimum Glutton

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

配点 : 250

問題文

N 個の料理があり、i 個目の料理の甘さA_iしょっぱさB_i です。

高橋君はこれらの N 個の料理を好きな順番で並べ、その順に食べようとします。

高橋君は並べた順番の通りに料理を食べていきますが、食べた料理の甘さの合計が X より大きくなるかしょっぱさの合計が Y より大きくなるとその時点で食べるのをやめます。

高橋君が食べることになる料理の個数としてあり得る最小値を求めてください。

制約

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq X, Y \leq 2 \times 10^{14}
  • 1 \leq A_i, B_i \leq 10^9
  • 入力される値はすべて整数

入力

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

N X Y
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_N

出力

答えを出力せよ。


入力例 1

4 7 18
2 3 5 1
8 8 1 4

出力例 1

2

i 個目の料理のことを料理 i と書きます。

高橋君が 4 個の料理を料理 2, 3, 1, 4 の順に並べ替えたとき、料理 2, 3 を食べた時点での食べた料理の甘さの合計が 8 となり 7 より大きくなります。したがってこの場合は高橋君が食べることになる料理の個数は 2 個です。

高橋君が食べる料理の個数が 1 個以下になることはないため、2 を出力します。


入力例 2

5 200000000000000 200000000000000
1 1 1 1 1
2 2 2 2 2

出力例 2

5

入力例 3

8 30 30
1 2 3 4 5 6 7 8
8 7 6 5 4 3 2 1

出力例 3

6

Score : 250 points

Problem Statement

There are N dishes, and the i-th dish has a sweetness of A_i and a saltiness of B_i.

Takahashi plans to arrange these N dishes in any order he likes and eat them in that order.

He will eat the dishes in the arranged order, but he will stop eating as soon as the total sweetness of the dishes he has eaten exceeds X or the total saltiness exceeds Y.

Find the minimum possible number of dishes that he will end up eating.

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq X, Y \leq 2 \times 10^{14}
  • 1 \leq A_i, B_i \leq 10^9
  • All input values are integers.

Input

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

N X Y
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_N

Output

Print the answer.


Sample Input 1

4 7 18
2 3 5 1
8 8 1 4

Sample Output 1

2

The i-th dish will be denoted as dish i.

If he arranges the four dishes in the order 2, 3, 1, 4, as soon as he eats dishes 2 and 3, their total sweetness is 8, which is greater than 7. Therefore, in this case, he will end up eating two dishes.

The number of dishes he will eat cannot be 1 or less, so print 2.


Sample Input 2

5 200000000000000 200000000000000
1 1 1 1 1
2 2 2 2 2

Sample Output 2

5

Sample Input 3

8 30 30
1 2 3 4 5 6 7 8
8 7 6 5 4 3 2 1

Sample Output 3

6
F - digitnum

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

配点 : 300

問題文

整数 N が与えられるので、以下の問題を解いてください。

f(x)= ( x 以下の正整数で、 x と桁数が同じものの数) とします。
f(1)+f(2)+\dots+f(N)998244353 で割った余りを求めてください。

制約

  • N は整数
  • 1 \le N < 10^{18}

入力

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

N

出力

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


入力例 1

16

出力例 1

73
  • 1 以上 9 以下の正整数 x について、 x 以下の整数で、 x と桁数が同じものは 1,2,\dots,x です。
    • これより、 f(1)=1,f(2)=2,...,f(9)=9 となります。
  • 10 以上 16 以下の正整数 x について、 x 以下の整数で、 x と桁数が同じものは 10,11,\dots,x です。
    • これより、 f(10)=1,f(11)=2,...,f(16)=7 となります。

結局、求める答えは 73 です。


入力例 2

238

出力例 2

13870

入力例 3

999999999999999999

出力例 3

762062362

998244353 で割った余りを求めることに注意してください。

Score : 300 points

Problem Statement

Given an integer N, solve the following problem.

Let f(x)= (The number of positive integers at most x with the same number of digits as x).
Find f(1)+f(2)+\dots+f(N) modulo 998244353.

Constraints

  • N is an integer.
  • 1 \le N < 10^{18}

Input

Input is given from Standard Input in the following format:

N

Output

Print the answer as an integer.


Sample Input 1

16

Sample Output 1

73
  • For a positive integer x between 1 and 9, the positive integers at most x with the same number of digits as x are 1,2,\dots,x.
    • Thus, we have f(1)=1,f(2)=2,...,f(9)=9.
  • For a positive integer x between 10 and 16, the positive integers at most x with the same number of digits as x are 10,11,\dots,x.
    • Thus, we have f(10)=1,f(11)=2,...,f(16)=7.

The final answer is 73.


Sample Input 2

238

Sample Output 2

13870

Sample Input 3

999999999999999999

Sample Output 3

762062362

Be sure to find the sum modulo 998244353.

G - Strange Mirroring

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

配点 : 350

問題文

英大小文字からなる文字列 S が与えられます。

S に以下の操作を 10^{100} 回繰り返します。

  • まず、 S の大文字を小文字に、小文字を大文字に書き換えた文字列を T とする。
  • その後、 ST とをこの順に連結した文字列を新たな S とする。

Q 個の質問に答えて下さい。 そのうち i 個目は次の通りです。

  • 全ての操作を終えた後の S の先頭から K_i 文字目を求めよ。

制約

  • S は英大小文字からなる長さ 1 以上 2 \times 10^5 以下の文字列
  • Q,K_i は整数
  • 1 \le Q \le 2 \times 10^5
  • 1 \le K_i \le 10^{18}

入力

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

S
Q
K_1 K_2 \dots K_Q

出力

i 個目の質問の答えを C_i とする時、以下の形式で 1 行に空白区切りで出力せよ。

C_1 C_2 \dots C_Q

入力例 1

aB
16
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

出力例 1

a B A b A b a B A b a B a B A b

操作前の S = aB です。

  • aB1 回操作を行うと aBAb となります。
  • aB2 回操作を行うと aBAbAbaB となります。
  • \dots

10^{100} 回の操作を終えた後の S = aBAbAbaBAbaBaBAb... です。


入力例 2

qWeRtYuIoP
8
1 1 2 3 5 8 13 21

出力例 2

q q W e t I E Q

入力例 3

AnUoHrjhgfLMcDIpzxXmEWPwBZvbKqQuiJTtFSlkNGVReOYCdsay
5
1000000000000000000 123456789 1 987654321 999999999999999999

出力例 3

K a A Z L

Score : 350 points

Problem Statement

You are given a string S consisting of uppercase and lowercase English letters.

We perform the following operation on S 10^{100} times:

  • First, create a string T by changing uppercase letters in S to lowercase, and lowercase letters to uppercase.
  • Then, concatenate S and T in this order to form a new S.

Answer Q queries. The i-th query is as follows:

  • Find the K_i-th character from the beginning of S after all operations are completed.

Constraints

  • S is a string consisting of uppercase and lowercase English letters, with length between 1 and 2 \times 10^5, inclusive.
  • Q and K_i are integers.
  • 1 \le Q \le 2 \times 10^5
  • 1 \le K_i \le 10^{18}

Input

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

S
Q
K_1 K_2 \dots K_Q

Output

Let C_i be the answer to the i-th query. Print them in a single line, separated by spaces, in the following format:

C_1 C_2 \dots C_Q

Sample Input 1

aB
16
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

Sample Output 1

a B A b A b a B A b a B a B A b

Before the operations, S = aB.

  • After performing the operation once on aB, it becomes aBAb.
  • After performing the operation twice on aB, it becomes aBAbAbaB.
  • \dots

After performing the operation 10^{100} times, S = aBAbAbaBAbaBaBAb...


Sample Input 2

qWeRtYuIoP
8
1 1 2 3 5 8 13 21

Sample Output 2

q q W e t I E Q

Sample Input 3

AnUoHrjhgfLMcDIpzxXmEWPwBZvbKqQuiJTtFSlkNGVReOYCdsay
5
1000000000000000000 123456789 1 987654321 999999999999999999

Sample Output 3

K a A Z L
H - Destruction

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

配点 : 500

問題文

N 頂点 M 辺の連結無向グラフがあります。
頂点には 1 から N の番号が、辺には 1 から M の番号がついており、辺 i は頂点 A_iB_i を結んでいます。

高橋君は、このグラフから 0 個以上の辺を取り除こうとしています。

i を取り除くと、C_i \geq 0 のとき C_i の報酬を得、C_i<0 のとき |C_i| の罰金を払います。

辺を取り除いたあともグラフが連結でなければならないとき、高橋君が得られる報酬の最大値を求めてください。

制約

  • 2 \leq N \leq 2\times 10^5
  • N-1 \leq M \leq 2\times 10^5
  • 1 \leq A_i,B_i \leq N
  • -10^9 \leq C_i \leq 10^9
  • 与えられるグラフは連結である
  • 入力に含まれる値は全て整数である

入力

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

N M
A_1 B_1 C_1
A_2 B_2 C_2
\vdots
A_M B_M C_M

出力

答えを出力せよ。


入力例 1

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

出力例 1

4

4,5 を取り除くことで合計 4 の報酬を得られます。これより多くの報酬を得ることはできないため、答えは 4 となります。


入力例 2

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

出力例 2

1

報酬が負であるような辺が存在することもあります。


入力例 3

2 3
1 2 -1
1 2 2
1 1 3

出力例 3

5

多重辺や自己ループが存在することもあります。

Score : 500 points

Problem Statement

We have a connected undirected graph with N vertices and M edges.
The vertices are numbered 1 through N, and the edges are numbered 1 through M. Edge i connects Vertices A_i and B_i.

Takahashi is going to remove zero or more edges from this graph.

When removing Edge i, a reward of C_i is given if C_i \geq 0, and a fine of |C_i| is incurred if C_i<0.

Find the maximum total reward that Takahashi can get when the graph must be connected after removing edges.

Constraints

  • 2 \leq N \leq 2\times 10^5
  • N-1 \leq M \leq 2\times 10^5
  • 1 \leq A_i,B_i \leq N
  • -10^9 \leq C_i \leq 10^9
  • The given graph is connected.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
A_1 B_1 C_1
A_2 B_2 C_2
\vdots
A_M B_M C_M

Output

Print the answer.


Sample Input 1

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

Sample Output 1

4

Removing Edges 4 and 5 yields a total reward of 4. You cannot get any more, so the answer is 4.


Sample Input 2

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

Sample Output 2

1

There may be edges that give a negative reward when removed.


Sample Input 3

2 3
1 2 -1
1 2 2
1 1 3

Sample Output 3

5

There may be multi-edges and self-loops.

I - Bomb Game 2

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

配点 : 550

問題文

N 人の人が一列に並んでおり、人 i は先頭から i 番目に並んでいます。

以下の操作を、列に並んでいる人が 1 人になるまで繰り返します。

  • 先頭に並んでいる人を \frac{1}{2} の確率で列から取り除き、そうでない場合は列の末尾に移す。

i=1,2,\ldots,N それぞれについて、人 i が最後まで列に並んでいる 1 人になる確率を \text{mod }998244353 で求めて下さい。(取り除くかどうかの選択はすべてランダムかつ独立です。)

確率 \text{mod } 998244353 の定義

この問題で求める確率は必ず有理数になることが証明できます。 また、この問題の制約下では、求める確率を既約分数 \frac{y}{x} で表したときに x998244353 で割り切れないことが保証されます。

このとき xz \equiv y \pmod{998244353} を満たすような 0 以上 998244352 以下の整数 z が一意に定まります。この z を答えてください。

制約

  • 2\leq N\leq 3000
  • 入力は全て整数

入力

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

N 

出力

i=1,2,\ldots,N に対する答えを空白区切りで出力せよ。


入力例 1

2

出力例 1

332748118 665496236

1 が最後まで列に並んでいる 1 人になる確率は \frac{1}{3} です。

2 が最後まで列に並んでいる 1 人になる確率は \frac{2}{3} です。


入力例 2

5

出力例 2

235530465 792768557 258531487 238597268 471060930

Score : 550 points

Problem Statement

There are N people standing in a line, with person i standing at the i-th position from the front.

Repeat the following operation until there is only one person left in the line:

  • Remove the person at the front of the line with a probability of \frac{1}{2}, otherwise move them to the end of the line.

For each person i=1,2,\ldots,N, find the probability that person i is the last person remaining in the line, modulo 998244353. (All choices to remove or not are random and independent.)

How to find probabilities modulo 998244353

The probabilities sought in this problem can be proven to always be a rational number. Furthermore, the constraints of this problem guarantee that if the sought probability is expressed as an irreducible fraction \frac{y}{x}, then x is not divisible by 998244353.

Now, there is a unique integer z between 0 and 998244352, inclusive, such that xz \equiv y \pmod{998244353}. Report this z.

Constraints

  • 2\leq N\leq 3000
  • All input values are integers.

Input

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

N 

Output

Print the answer for people i=1,2,\ldots,N, separated by spaces.


Sample Input 1

2

Sample Output 1

332748118 665496236

Person 1 will be the last person remaining in the line with probability \frac{1}{3}.

Person 2 will be the last person remaining in the line with probability \frac{2}{3}.


Sample Input 2

5

Sample Output 2

235530465 792768557 258531487 238597268 471060930