A - Round decimals

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 100

問題文

小数第三位までで表すことのできる実数 X が、小数第三位まで入力されます。
X を小数第一位で四捨五入した結果として得られる整数を出力してください。

制約

  • 0 \leq X < 100
  • X は小数第三位までで表現可能である。
  • X は小数第三位まで与えられる。

入力

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

X

出力

X を小数第一位で四捨五入して得られる整数を出力せよ。


入力例 1

3.456

出力例 1

3

3.456 の小数第一位は 4 であるので、3.456 を小数第一位で四捨五入した値は 3 となります。


入力例 2

99.500

出力例 2

100

入力例 3

0.000

出力例 3

0

Score : 100 points

Problem Statement

You are given a real number X, which is representable using at most three decimal digits, with three decimal digits.
Round X to the nearest integer and print the result.

Constraints

  • 0 \leq X < 100
  • X is representable using at most three decimal digits.
  • X has three decimal digits in input.

Input

Input is given from Standard Input in the following format:

X

Output

Print the integer resulting from rounding X to the nearest integer.


Sample Input 1

3.456

Sample Output 1

3

The digit in the first decimal place of 3.456 is 4, so we should round it down to 3.


Sample Input 2

99.500

Sample Output 2

100

Sample Input 3

0.000

Sample Output 3

0
B - Counting Arrays

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 200

問題文

1 から N までの番号がついた N 個の数列が与えられます。
数列 i は、長さが L_ij (1 \leq j \leq L_i) 番目の要素が a_{i,j} であるような数列です。

数列 i と 数列 j は、 L_i = L_j かつすべての k (1 \leq k \leq L_i) に対して a_{i,k} = a_{j,k} が成り立つ時に同じであるとみなします。
同じ数列は 1 種類として数えるとき、数列 1 から 数列 N の中に全部で何種類の数列がありますか?

制約

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq L_i \leq 2 \times 10^5 (1 \leq i \leq N)
  • 0 \leq a_{i,j} \leq 10^{9} (1 \leq i \leq N, 1 \leq j \leq L_i)
  • すべての数列の要素の個数の和、すなわち \sum_{i=1}^N L_i2 \times 10^5 を超えない。
  • 入力はすべて整数である。

入力

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

N
L_1 a_{1,1} a_{1,2} \dots a_{1,L_1}
L_2 a_{2,1} a_{2,2} \dots a_{2,L_2}
\vdots
L_N a_{N,1} a_{N,2} \dots a_{N,L_N}

出力

数列の種類数を出力せよ。


入力例 1

4
2 1 2
2 1 1
2 2 1
2 1 2

出力例 1

3

入力例 1 で与えられている数列は以下の 4 個です。

  • 数列 1 : (1, 2)
  • 数列 2 : (1, 1)
  • 数列 3 : (2, 1)
  • 数列 4 : (1, 2)

このうち数列 1 と数列 4 は同じ数列で、それ以外は互いに異なる数列なので全部で 3 種類の数列があります。


入力例 2

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

出力例 2

4

入力例 2 で与えられている数列は以下の 5 個です。

  • 数列 1 : (1)
  • 数列 2 : (1)
  • 数列 3 : (2)
  • 数列 4 : (1, 1)
  • 数列 5 : (1, 1, 1)

入力例 3

1
1 1

出力例 3

1

Score : 200 points

Problem Statement

You are given N sequences numbered 1 to N.
Sequence i has a length of L_i and its j-th element (1 \leq j \leq L_i) is a_{i,j}.

Sequence i and Sequence j are considered the same when L_i = L_j and a_{i,k} = a_{j,k} for every k (1 \leq k \leq L_i).
How many different sequences are there among Sequence 1 through Sequence N?

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq L_i \leq 2 \times 10^5 (1 \leq i \leq N)
  • 0 \leq a_{i,j} \leq 10^{9} (1 \leq i \leq N, 1 \leq j \leq L_i)
  • The total number of elements in the sequences, \sum_{i=1}^N L_i, does not exceed 2 \times 10^5.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
L_1 a_{1,1} a_{1,2} \dots a_{1,L_1}
L_2 a_{2,1} a_{2,2} \dots a_{2,L_2}
\vdots
L_N a_{N,1} a_{N,2} \dots a_{N,L_N}

Output

Print the number of different sequences.


Sample Input 1

4
2 1 2
2 1 1
2 2 1
2 1 2

Sample Output 1

3

Sample Input 1 contains four sequences:

  • Sequence 1 : (1, 2)
  • Sequence 2 : (1, 1)
  • Sequence 3 : (2, 1)
  • Sequence 4 : (1, 2)

Except that Sequence 1 and Sequence 4 are the same, these sequences are pairwise different, so we have three different sequences.


Sample Input 2

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

Sample Output 2

4

Sample Input 2 contains five sequences:

  • Sequence 1 : (1)
  • Sequence 2 : (1)
  • Sequence 3 : (2)
  • Sequence 4 : (1, 1)
  • Sequence 5 : (1, 1, 1)

Sample Input 3

1
1 1

Sample Output 3

1
C - Martial artist

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 300

問題文

高橋君は武術家です。 武術家の覚えられる技は N 個あり、技 1, 2, \ldots, N と名前がついています。 1 \leq i \leq N について、技 i を習得するには時間 T_i の修練が必要で、 さらに、修練の開始時点で技 A_{i,1}, A_{i,2}, \ldots, A_{i,K_i} をすでに習得している必要があります。 ここで、1 \leq j \leq K_i について、A_{i,j} < i であることが保証されます。

高橋君は時刻 0 の時点で技を 1 つも覚えていません。 高橋君は同時に 1 つの技に対する修練しかできず、また、一度始めた修練を途中でやめることもできません。 高橋君が技 N を習得するのに必要な時間の最小値を求めてください。

制約

  • 1 \leq N \leq 2\times 10^5
  • 1 \leq T_i \leq 10^9
  • 0 \leq K_i < i
  • 1 \leq A_{i,j} < i
  • \sum_{i=1}^N K_i \leq 2\times 10^5
  • A_{i,1}, A_{i,2}, \ldots, A_{i,K_i} はすべて異なる。
  • 入力は全て整数である。

入力

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

N
T_1 K_1 A_{1,1} A_{1,2} \ldots A_{1,K_1}
T_2 K_2 A_{2,1} A_{2,2} \ldots A_{2,K_2}
\vdots
T_N K_N A_{N,1} A_{N,2} \ldots A_{N,K_N}

出力

N を習得するのに必要な時間の最小値を出力せよ。


入力例 1

3
3 0
5 1 1
7 1 1

出力例 1

10

例えば高橋君は次のように行動することができます。

  • 高橋君は時刻 0 に技 1 の修練を開始し、時刻 3 に技 1 を習得します。
  • その後、時刻 3 に技 3 の修練を開始し、時刻 10 に技 3 を習得します。

このときが最短で、高橋君が技 3 を習得するのに必要な時間は 3+7=10 となります。 技 3 の習得のためには、技 2 を習得する必要はありません。


入力例 2

5
1000000000 0
1000000000 0
1000000000 0
1000000000 0
1000000000 4 1 2 3 4

出力例 2

5000000000

答えが 32 bit 整数に収まらないことがある事に注意してください。

Score : 300 points

Problem Statement

Takahashi is a martial artist. There are N moves that a martial artist can learn, called Move 1, 2, \ldots, N. For each 1 \leq i \leq N, it takes T_i minutes of practice to learn Move i. Additionally, at the beginning of that practice, all of the Moves A_{i,1}, A_{i,2}, \ldots, A_{i,K_i} must be already learned. Here, it is guaranteed that A_{i,j} < i for each 1 \leq j \leq K_i.

Takahashi has not learned any move at time 0. He cannot practice for more than one move simultaneously, nor can he stop a practice he has already started. Find the minimum number of minutes needed for Takahashi to learn Move N.

Constraints

  • 1 \leq N \leq 2\times 10^5
  • 1 \leq T_i \leq 10^9
  • 0 \leq K_i < i
  • 1 \leq A_{i,j} < i
  • \sum_{i=1}^N K_i \leq 2\times 10^5
  • A_{i,1}, A_{i,2}, \ldots, A_{i,K_i} are all distinct.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
T_1 K_1 A_{1,1} A_{1,2} \ldots A_{1,K_1}
T_2 K_2 A_{2,1} A_{2,2} \ldots A_{2,K_2}
\vdots
T_N K_N A_{N,1} A_{N,2} \ldots A_{N,K_N}

Output

Print the minimum number of minutes needed for Takahashi to learn Move N.


Sample Input 1

3
3 0
5 1 1
7 1 1

Sample Output 1

10

Here is one possible plan for Takahashi.

  • At time 0, start practicing for Move 1 to learn Move 1 at time 3.
  • Then, at time 3, start practicing for Move 3 to learn Move 3 at time 10.

Here, Takahashi spends 3+7=10 minutes to learn Move 3, which is the fastest possible. Note that he does not need to learn Move 2 to learn Move 3.


Sample Input 2

5
1000000000 0
1000000000 0
1000000000 0
1000000000 0
1000000000 4 1 2 3 4

Sample Output 2

5000000000

Note that the answer may not fit into a 32-bit integer.

D - Teleportation

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 400

問題文

AtCoder 国は無限に広がる直交座標の上にあります。
AtCoder 国には N 個の街があり、 1,2,\dots,N と番号が付けられています。街 i は地点 (x_i, y_i) にあり、2 つの異なる番号の街が同じ座標にあることはありません。

AtCoder 国には転移魔法(以下、魔法と表記)があります。魔法は整数の組 (a,b) によって識別されていて、地点 (x,y) にいるときに魔法 (a,b) を使うと (x+a,y+b) にワープすることができます。

すぬけ君は、任意の整数の組 (a,b) を選んで魔法 (a,b) を覚えることができる大魔術師です。また、すぬけ君は何種類でも魔法を覚えることができます。
魔法を使って街と街の間を移動したくなったすぬけ君は、全ての相異なる街の組 (i,j) について次の行動を取れるようにいくつかの魔法を覚えることにしました。

  • 覚えた魔法のうち 1 種類の魔法のみ を選ぶ。その後、選んだ魔法 のみ を繰り返し使って街 i から 街 j に移動する。

すぬけ君が上の条件を満たすように魔法を覚えるとき、少なくとも何種類の魔法を覚えればよいですか?

制約

  • 2 \leq N \leq 500
  • 0 \leq x_i \leq 10^9 (1 \leq i \leq N)
  • 0 \leq y_i \leq 10^9 (1 \leq i \leq N)
  • i \neq j ならば (x_i, y_i) \neq (x_j, y_j) である。

入力

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

N
x_1 y_1
x_2 y_2
\vdots
x_N y_N

出力

すぬけ君が覚える必要がある魔法の個数の最小値を出力せよ。


入力例 1

3
1 2
3 6
7 4

出力例 1

6

AtCoder 国の街の位置を図示したのが下の図です。(わかりやすさのために四隅の座標を表示しています。)

image

すぬけ君は次の 6 種類の魔法を覚えれば、すべての (i,j) (i \neq j) の組に対して街 i から 1 種類の魔法を 1 回使うことで街 j に着くことができるので条件を満たします。

  • (2, 4)
  • (-2, -4)
  • (4, -2)
  • (-4, 2)
  • (-6, -2)
  • (6, 2)

次の 6 種類の魔法も条件を満たします。このときすぬけ君は、すべての (i,j) (i \neq j) の組に対して街 i から 1 種類の魔法を 2 回使うことで街 j に着くことができます。

  • (1, 2)
  • (-1, -2)
  • (2, -1)
  • (-2, 1)
  • (-3, -1)
  • (3, 1)

条件を満たす魔法の組み合わせのうち 6 種類より少ないものは存在しないので、 6 を出力します。


入力例 2

3
1 2
2 2
4 2

出力例 2

2

次の 2 種類の魔法を覚えるのが最適です。

  • (1, 0)
  • (-1, 0)

入力例 3

4
0 0
0 1000000000
1000000000 0
1000000000 1000000000

出力例 3

8

Score : 400 points

Problem Statement

The Republic of AtCoder lies on a Cartesian coordinate plane.
It has N towns, numbered 1,2,\dots,N. Town i is at (x_i, y_i), and no two different towns are at the same coordinates.

There are teleportation spells in the nation. A spell is identified by a pair of integers (a,b), and casting a spell (a, b) at coordinates (x, y) teleports you to (x+a, y+b).

Snuke is a great magician who can learn the spell (a, b) for any pair of integers (a, b) of his choice. The number of spells he can learn is also unlimited.
To be able to travel between the towns using spells, he has decided to learn some number of spells so that it is possible to do the following for every pair of different towns (i, j).

  • Choose just one spell among the spells learned. Then, repeatedly use just the chosen spell to get from Town i to Town j.

At least how many spells does Snuke need to learn to achieve the objective above?

Constraints

  • 2 \leq N \leq 500
  • 0 \leq x_i \leq 10^9 (1 \leq i \leq N)
  • 0 \leq y_i \leq 10^9 (1 \leq i \leq N)
  • (x_i, y_i) \neq (x_j, y_j) if i \neq j.

Input

Input is given from Standard Input in the following format:

N
x_1 y_1
x_2 y_2
\vdots
x_N y_N

Output

Print the minimum number of spells Snuke needs to learn.


Sample Input 1

3
1 2
3 6
7 4

Sample Output 1

6

The figure below illustrates the positions of the towns (along with the coordinates of the four corners).

image

If Snuke learns the six spells below, he can get from Town i to Town j by using one of the spells once for every pair (i,j) (i \neq j), achieving his objective.

  • (2, 4)
  • (-2, -4)
  • (4, -2)
  • (-4, 2)
  • (-6, -2)
  • (6, 2)

Another option is to learn the six spells below. In this case, he can get from Town i to Town j by using one of the spells twice for every pair (i,j) (i \neq j), achieving his objective.

  • (1, 2)
  • (-1, -2)
  • (2, -1)
  • (-2, 1)
  • (-3, -1)
  • (3, 1)

There is no combination of spells that consists of less than six spells and achieve the objective, so we should print 6.


Sample Input 2

3
1 2
2 2
4 2

Sample Output 2

2

The optimal choice is to learn the two spells below:

  • (1, 0)
  • (-1, 0)

Sample Input 3

4
0 0
0 1000000000
1000000000 0
1000000000 1000000000

Sample Output 3

8
E - Just one

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 500

問題文

N 頂点 M 辺の無向グラフが与えられます。 頂点は頂点 1 ,頂点 2 , \ldots ,頂点 N、辺は辺 1 ,辺 2 , \ldots ,辺 M と番号付けられており、特に辺 i (1 \leq i \leq M) は頂点 U_i と頂点 V_i を結んでいます。 また、このグラフは単純であることが保証されます。すなわち、自己ループや多重辺は存在しません。

このグラフの M 本の辺すべてに向き付けをする方法は 2^M 通り考えられますが、 そのうち、どの頂点についても、その頂点から他の頂点に向かう辺がちょうど 1 本ずつ存在するような向き付けの方法は何通りありますか。 答えは非常に大きくなる可能性があるので、998244353 で割った余りを出力してください。

制約

  • 2 \leq N \leq 2\times 10^5
  • 1 \leq M \leq 2\times 10^5
  • 1 \leq U_i,V_i \leq N
  • U_i \neq V_i
  • 入力は全て整数である。
  • 与えられるグラフは単純である。

入力

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

N M
U_1 V_1
U_2 V_2
\vdots
U_M V_M

出力

答えを出力せよ。


入力例 1

3 3
1 2
1 3
2 3

出力例 1

2

条件をみたす辺の向き付けの方法は、

  • 1\rightarrow 2 , 2\rightarrow 3 , 1\leftarrow 3
  • 1\leftarrow 2 , 2\leftarrow 3 , 1\rightarrow 3

2 通りです。


入力例 2

2 1
1 2

出力例 2

0

すべての頂点から 1 本ずつ辺が出ているようにすることは明らかに不可能です。


入力例 3

7 7
1 2
2 3
3 4
4 2
5 6
6 7
7 5

出力例 3

4

Score : 500 points

Problem Statement

Given is an undirected graph with N vertices and M edges. The vertices are called Vertex 1, Vertex 2, \ldots, Vertex N, and the edges are called Edge 1, Edge 2, \ldots, Edge M. Edge i (1 \leq i \leq M) connects Vertex U_i and Vertex V_i. It is guaranteed that the graph is simple: it has no self-loops and no multi-edges.

There are 2^M ways to direct every edge in this graph. We want each vertex to have exactly one edge going from that vertex to another vertex. How many ways are there to direct the edges in that way? Since the answer may be enormous, print it modulo 998244353.

Constraints

  • 2 \leq N \leq 2\times 10^5
  • 1 \leq M \leq 2\times 10^5
  • 1 \leq U_i,V_i \leq N
  • U_i \neq V_i
  • All values in input are integers.
  • The given graph is simple.

Input

Input is given from Standard Input in the following format:

N M
U_1 V_1
U_2 V_2
\vdots
U_M V_M

Output

Print the answer.


Sample Input 1

3 3
1 2
1 3
2 3

Sample Output 1

2

There are two ways to direct the edges to achieve the objective:

  • 1\rightarrow 2 , 2\rightarrow 3 , 1\leftarrow 3
  • 1\leftarrow 2 , 2\leftarrow 3 , 1\rightarrow 3

Sample Input 2

2 1
1 2

Sample Output 2

0

It is obviously impossible to make every vertex have one edge going from that vertex.


Sample Input 3

7 7
1 2
2 3
3 4
4 2
5 6
6 7
7 5

Sample Output 3

4
F - Score of Permutations

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 500

問題文

(1,2, \dots, N) を並び替えた長さ N の順列 P = (p_1, p_2, \dots, p_N) に対して、 P のスコア S(P) を次のように定めます。

  • N 人の人とすぬけ君がいて、N 人の人には 1,2,\dots,N の番号がついています。はじめ、人 i (1 \leq i \leq N) はボール i を持っています。
    すぬけ君が叫ぶたびに、i \neq p_i であるようなすべての人 i は人 p_i に持っているボールを同時に渡します。
    すぬけ君は、1 回以上叫んだ後にすべての人 i がボール i を持っている状態になると叫ぶのをやめます。
    すぬけ君が叫ぶのをやめるまでに叫んだ回数が順列のスコアとなります。ここでスコアは有限の値を取ることが保証されます。

P としてあり得るものは N! 通りありますが、それらのスコアを K 乗した値の総和を 998244353 で割ったあまりを計算してください。

  • 厳密に言い換えると、(1,2, \dots, N) を並び替えた長さ N の順列全体の集合を S_N として

    \displaystyle \left(\sum_{P \in S_N} S(P)^K \right) \bmod {998244353}

    を計算してください。

制約

  • 2 \leq N \leq 50
  • 1 \leq K \leq 10^4
  • 入力はすべて整数である。

入力

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

N K

出力

\displaystyle \left(\sum_{P \in S_N} S(P)^K \right) \bmod {998244353} を出力せよ。


入力例 1

2 2

出力例 1

5

N = 2 のとき P としてあり得る順列は (1,2),(2,1)2 つです。

順列 (1,2) のスコアは次のように決まります。

  • はじめ人 1 はボール 1 を、人 2 はボール 2 を持っています。
    すぬけ君が 1 回目に叫んだ後に、人 1 はボール 1 を、人 2 はボール 2 を持っています。
    このとき、すべての人が自身の番号と同じ番号が書かれたボールを持っているので、すぬけ君は叫ぶのをやめます。
    よってスコアは 1 となります。

順列 (2,1) のスコアは次のように決まります。

  • はじめ人 1 はボール 1 を、人 2 はボール 2 を持っています。
    すぬけ君が 1 回目に叫んだ後に、人 1 はボール 2 を、人 2 はボール 1 を持っています。
    すぬけ君が 2 回目に叫んだ後に、人 1 はボール 1 を、人 2 はボール 2 を持っています。
    このとき、すべての人が自身の番号と同じ番号が書かれたボールを持っているので、すぬけ君は叫ぶのをやめます。
    よってスコアは 2 となります。

よって 1^2 + 2^2 = 5 がこの問題の答えになります。


入力例 2

3 3

出力例 2

79

すべての順列とスコアの組を列挙すると以下のようになります。

  • 順列 : (1,2,3), スコア : 1
  • 順列 : (1,3,2), スコア : 2
  • 順列 : (2,1,3), スコア : 2
  • 順列 : (2,3,1), スコア : 3
  • 順列 : (3,1,2), スコア : 3
  • 順列 : (3,2,1), スコア : 2

よって 1^3 + 2^3 + 2^3 + 3^3 + 3^3 + 2^3 = 79 を出力します。


入力例 3

50 10000

出力例 3

77436607

Score : 500 points

Problem Statement

For a permutation P = (p_1, p_2, \dots, p_N) of (1,2, \dots, N), let us define the score S(P) of P as follows.

  • There are N people, numbered 1,2,\dots,N. Additionally, Snuke is there. Initially, Person i (1 \leq i \leq N) has Ball i.
    Each time Snuke screams, every Person i such that i \neq p_i gives their ball to Person p_i simultaneously.
    If, after screaming at least once, every Person i has Ball i, Snuke stops screaming.
    The score is the number of times Snuke screams until he stops. Here, it is guaranteed that the score will be a finite value.

There are N! permutations P of (1,2, \dots, N). Find the sum, modulo 998244353, of the scores of those permutations, each raised to the K-th power.

  • Formally, let S_N be the set of the permutations of (1,2, \dots, N). Compute the following: \displaystyle \left(\sum_{P \in S_N} S(P)^K \right) \bmod {998244353}.

Constraints

  • 2 \leq N \leq 50
  • 1 \leq K \leq 10^4
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K

Output

Print \displaystyle \left(\sum_{P \in S_N} S(P)^K \right) \bmod {998244353}.


Sample Input 1

2 2

Sample Output 1

5

When N = 2, there are two possible permutations P: (1,2),(2,1).

The score of the permutation (1,2) is found as follows.

  • Initially, Person 1 has Ball 1, and Person 2 has Ball 2.
    After Snuke's first scream, Person 1 has Ball 1, and Person 2 has Ball 2.
    Here, every Person i has Ball i, so he stops screaming.
    Thus, the score is 1.

The score of the permutation (2,1) is found as follows.

  • Initially, Person 1 has Ball 1, and Person 2 has Ball 2.
    After Snuke's first scream, Person 1 has Ball 2, and Person 2 has Ball 1.
    After Snuke's second scream, Person 1 has Ball 1, and Person 2 has Ball 2.
    Here, every Person i has Ball i, so he stops screaming.
    Thus, the score is 2.

Therefore, the answer in this case is 1^2 + 2^2 = 5.


Sample Input 2

3 3

Sample Output 2

79

All permutations and their scores are listed below.

  • (1,2,3): The score is 1.
  • (1,3,2): The score is 2.
  • (2,1,3): The score is 2.
  • (2,3,1): The score is 3.
  • (3,1,2): The score is 3.
  • (3,2,1): The score is 2.

Thus, we should print 1^3 + 2^3 + 2^3 + 3^3 + 3^3 + 2^3 = 79.


Sample Input 3

50 10000

Sample Output 3

77436607
G - The baggage

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 600

問題文

重さが 1 , 2 , 3 , 4 , 55 種類の重さの荷物があり、重さが i (1 \leq i \leq 5) の荷物はそれぞれ A_i 個あります。
また、体力が 1 , 2 , 3 , 4 , 55 種類の体力の人がおり、体力が i (1 \leq i \leq 5) の人はそれぞれ B_i 人います。
それぞれの人は 0 個以上の任意の個数の荷物を持つことができますが、重さの合計が体力を超えるような組合せで荷物を持つことはできません。

T 個のテストケースが与えられます。 それぞれのケースに対して、うまく分担してすべての荷物を持つことは可能か判定してください。すなわち、各人に割り当てられた荷物の重さの総和がその人の体力を超えないように、すべての荷物を誰かに割り当てることが可能か判定して下さい。荷物を 1 つも持たない人がいても構いません。

制約

  • 1 \leq T \leq 5\times 10^4
  • 0 \leq A_i,B_i \leq 10^{16}
  • 1 \leq A_1+A_2+A_3+A_4+A_5
  • 1 \leq B_1+B_2+B_3+B_4+B_5
  • 入力は全て整数である。

入力

入力は標準入力から与えられる。入力の 1 行目にはテストケース数 T が与えられる。

T

その後、 T 個のテストケースが続く。各テストケースは以下の形式で与えられる。

A_1 A_2 A_3 A_4 A_5
B_1 B_2 B_3 B_4 B_5

出力

T 行出力せよ。 i (1\leq i\leq T) 行目には、i 番目のテストケースについてすべての荷物を持つことが可能なら Yes を、そうでないならば No を出力せよ。


入力例 1

3
5 1 0 0 1
0 0 0 2 1
0 3 0 0 0
0 0 2 0 0
10000000000000000 0 0 0 0
0 0 0 0 2000000000000000

出力例 1

Yes
No
Yes

1 つめのテストケースでは、例えば以下のようにすればすべての荷物を持つことができます。

  • 体力 4 の人のうちの 1 人目が、重さ 1 の荷物を 4 つ持つ。
  • 体力 4 の人のうちの 2 人目が、重さ 1 の荷物と重さ 2 の荷物を 1 つずつ持つ。
  • 体力 5 の人が、重さ 5 の荷物を 1 つ持つ。

2 つめのテストケースでは、体力が 3 の人のどちらかが重さ 2 の荷物を 2 つ以上持つ必要があり、不可能です。

Score : 600 points

Problem Statement

We have parcels with five different weights: 1, 2, 3, 4, 5. For each i (1 \leq i \leq 5), there are A_i parcels of weight i.
Additionally, we have people with five different strengths: 1, 2, 3, 4, 5. For each i (1 \leq i \leq 5), there are B_i people with strength i.
Each person can carry any number of parcels (possibly zero), but the total weight of the parcels must not exceed their strength.

You are given T test cases. For each case, determine whether it is possible for the people to carry all parcels with the appropriate allocation of parcels. That is, determine whether it is possible to allocate each parcel to someone so that each person is allocated parcels whose total weight does not exceed their strength. It is fine to have someone who carries no parcels.

Constraints

  • 1 \leq T \leq 5\times 10^4
  • 0 \leq A_i,B_i \leq 10^{16}
  • 1 \leq A_1+A_2+A_3+A_4+A_5
  • 1 \leq B_1+B_2+B_3+B_4+B_5
  • All values in input are integers.

Input

Input is given from Standard Input. The first line contains the number of test cases T:

T

Then, T test cases follow, each in the following format:

A_1 A_2 A_3 A_4 A_5
B_1 B_2 B_3 B_4 B_5

Output

Print T lines. The i-th line (1\leq i\leq T) should contain Yes if all parcels can be carried in the i-th test case, and No otherwise.


Sample Input 1

3
5 1 0 0 1
0 0 0 2 1
0 3 0 0 0
0 0 2 0 0
10000000000000000 0 0 0 0
0 0 0 0 2000000000000000

Sample Output 1

Yes
No
Yes

In the first test case, all parcels can be carried. Here is one way to do so:

  • The first person with strength 4 carries four parcels of weight 1.
  • The second person with strength 4 carries one parcel of weight 1 and another of weight 2.
  • The person with strength 5 carries one parcel of weight 5.

In the second test case, one of the two people with strength 3 has to carry two or more parcels of weight 2, which is impossible.

H - Random Kth Max

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 600

問題文

N 個の連続確率変数 X_1,X_2,\dots,X_N があり、 X_i\lbrack L_i, R_i \rbrack の範囲を取る連続一様分布に従います。
N 個の確率変数のうち大きい方から K 番目の値の期待値を E とします。注記に述べるように E \bmod {998244353} を出力してください。

注記

この問題で E は必ず有理数になることが証明できます。また、この問題の制約下では、E を既約分数 \frac{y}{x} で表したときに x998244353 で割り切れないことが保証されます。
このとき xz \equiv y \pmod{998244353} を満たすような 0 以上 998244352 以下の整数 z が一意に定まります。この zE \bmod {998244353} として出力してください。

制約

  • 1 \leq N \leq 50
  • 1 \leq K \leq N
  • 0 \leq L_i \lt R_i \leq 100
  • 入力はすべて整数である。

入力

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

N K
L_1 R_1
L_2 R_2
\vdots
L_N R_N

出力

E \bmod {998244353} を出力せよ。


入力例 1

1 1
0 2

出力例 1

1

\lbrack 0, 2 \rbrack 上の連続一様分布に従う確率変数の値の期待値が求める答えです。よって 1 を出力します。


入力例 2

2 2
0 2
1 3

出力例 2

707089751

答えを有理数で表すと \frac{23}{24} になります。707089751 \times 24 \equiv 23 \pmod{998244353} なので 707089751 を出力します。


入力例 3

10 5
35 48
44 64
47 59
39 97
36 37
4 91
38 82
20 84
38 50
39 69

出力例 3

810056397

Score : 600 points

Problem Statement

We have N continuous random variables X_1,X_2,\dots,X_N. X_i has a continuous uniform distribution over the interval \lbrack L_i, R_i \rbrack.
Let E be the expected value of the K-th greatest value among the N random variables. Print E \bmod {998244353} as specified in Notes.

Notes

In this problem, we can prove that E is always a rational number. Additionally, the Constraints of this problem guarantee that, when E is represented as an irreducible fraction \frac{y}{x}, x is indivisible by 998244353.
Here, there uniquely exists an integer z between 0 and 998244352 such that xz \equiv y \pmod{998244353}. Print this z as the value E \bmod {998244353}.

Constraints

  • 1 \leq N \leq 50
  • 1 \leq K \leq N
  • 0 \leq L_i \lt R_i \leq 100
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
L_1 R_1
L_2 R_2
\vdots
L_N R_N

Output

Print E \bmod {998244353}.


Sample Input 1

1 1
0 2

Sample Output 1

1

The answer is the expected value of the random variable with a continuous uniform distribution over the interval \lbrack 0, 2 \rbrack. Thus, we should print 1.


Sample Input 2

2 2
0 2
1 3

Sample Output 2

707089751

The answer represented as a rational number is \frac{23}{24}. We have 707089751 \times 24 \equiv 23 \pmod{998244353}, so we should print 707089751.


Sample Input 3

10 5
35 48
44 64
47 59
39 97
36 37
4 91
38 82
20 84
38 50
39 69

Sample Output 3

810056397