Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
下の画像で示す図において、a 番の点と b 番の点が線で直接結ばれているかを答えてください。

制約
- 1 \leq a \lt b \leq 15
- a,b は整数
入力
入力は以下の形式で標準入力から与えられる。
a b
出力
a 番の点と b 番の点が線で直接結ばれているなら Yes、結ばれていないなら No を出力せよ。
入力例 1
1 2
出力例 1
Yes
問題文で示した図において、1 番の点と 2 番の点は線で直接結ばれています。 よって、Yes を出力します。
入力例 2
2 8
出力例 2
No
問題文で示した図において、2 番の点と 8 番の点は線で直接結ばれていません。 よって、No を出力します。
入力例 3
14 15
出力例 3
No
Score : 100 points
Problem Statement
Determine if there is a segment that directly connects the points numbered a and b in the figure below.

Constraints
- 1 \leq a \lt b \leq 15
- a and b are integers.
Input
The input is given from Standard Input in the following format:
a b
Output
Print Yes if there is a segment that directly connects the points numbered a and b; print No otherwise.
Sample Input 1
1 2
Sample Output 1
Yes
In the figure in the Problem Statement, there is a segment that directly connects the points numbered 1 and 2, so Yes should be printed.
Sample Input 2
2 8
Sample Output 2
No
In the figure in the Problem Statement, there is no segment that directly connects the points numbered 2 and 8, so No should be printed.
Sample Input 3
14 15
Sample Output 3
No
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
4 個のボールがあり、i 個目のボールの色は A_i です。
同じ色のボールを 2 つ選び両方捨てるという操作を最大何回行えるか求めてください。
制約
- A_1,A_2,A_3,A_4 はそれぞれ 1 以上 4 以下の整数
入力
入力は以下の形式で標準入力から与えられる。
A_1 A_2 A_3 A_4
出力
操作回数の最大値を整数として出力せよ。
入力例 1
2 1 2 1
出力例 1
2
1 個目のボールと 3 個目のボールはどちらも色が 2 なので、1 個目のボールと 3 個目のボールを共に捨てる操作を行えます。
次に、2 個目のボールと 4 個目のボールはどちらも色が 1 なので、2 個目のボールと 4 個目のボールを共に捨てる操作を行えます。
合計で 2 回操作を行えます。
入力例 2
4 4 4 1
出力例 2
1
入力例 3
1 2 3 4
出力例 3
0
操作を一度も行えない場合もあります。
Score : 100 points
Problem Statement
There are four balls, and the color of the i-th ball is A_i.
Find the maximum number of times you can perform this operation: choose two balls of the same color and discard both.
Constraints
- Each of A_1, A_2, A_3, A_4 is an integer between 1 and 4, inclusive.
Input
The input is given from Standard Input in the following format:
A_1 A_2 A_3 A_4
Output
Print the maximum number of times the operation can be performed as an integer.
Sample Input 1
2 1 2 1
Sample Output 1
2
The first and third balls both have color 2, so you can perform the operation to discard the first and third balls together.
Next, the second and fourth balls both have color 1, so you can perform the operation to discard the second and fourth balls together.
Hence, you can perform a total of two operations.
Sample Input 2
4 4 4 1
Sample Output 2
1
Sample Input 3
1 2 3 4
Sample Output 3
0
There are cases where you cannot perform the operation even once.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
英小文字からなる N 個の文字列 S_1, S_2, \ldots, S_N が与えられます。ここで、文字列の長さはそれぞれ相異なります。
これらの文字列を長さの昇順に並べ替え、この順に結合して得られる文字列を求めてください。
制約
- 2 \leq N \leq 50
- N は整数
- S_i は長さ 1 以上 50 以下の英小文字からなる文字列
- i \neq j のとき S_i と S_j の長さは異なる
入力
入力は以下の形式で標準入力から与えられる。
N S_1 S_2 \vdots S_N
出力
答えを出力せよ。
入力例 1
3 tc oder a
出力例 1
atcoder
( tc, oder, a ) を文字列の長さの昇順に並べ替えると ( a, tc, oder ) となります。これらの文字列を順に結合すると文字列 atcoder が得られます。
入力例 2
4 cat enate on c
出力例 2
concatenate
Score : 200 points
Problem Statement
You are given N strings S_1, S_2, \ldots, S_N, each consisting of lowercase English letters. The lengths of these strings are all distinct.
Sort these strings in ascending order of length, and then concatenate them in that order to form a single string.
Constraints
- 2 \leq N \leq 50
- N is an integer.
- Each S_i is a string consisting of lowercase English letters with length between 1 and 50, inclusive.
- If i \neq j, the length of S_i is different from the length of S_j.
Input
The input is given from Standard Input in the following format:
N S_1 S_2 \vdots S_N
Output
Print the answer.
Sample Input 1
3 tc oder a
Sample Output 1
atcoder
When we sort (tc, oder, a) in ascending order of length, we get (a, tc, oder). Concatenating them in this order yields the string atcoder.
Sample Input 2
4 cat enate on c
Sample Output 2
concatenate
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
長さ N の整数列 A=(A_1,A_2,\ldots,A_N) が与えられます。ここで、 A の各要素は -1 または 1 以上 N 以下の整数です。
以下の条件を全て満たす長さ N の整数列 P=(P_1,P_2,\ldots,P_N) が存在するか判定し、存在するならば一つ求めてください。
- P は (1,2,\ldots,N) を並び替えてできる整数列である。
- i=1,2,\ldots,N に対し、 A_i \neq -1 ならば P_i=A_i が成り立つ。
制約
- 1\le N\le 10
- A_i=-1 または 1\le A_i \le N
- 入力される値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \ldots A_N
出力
条件を全て満たす P が存在しない場合は No と出力せよ。
そうでない場合、条件を全て満たす P を以下の形式で出力せよ。
Yes P_1 P_2 \ldots P_N
条件を全て満たす P が複数存在する場合、どれを出力しても正答となる。
入力例 1
4 -1 -1 2 -1
出力例 1
Yes 3 1 2 4
P=(3,1,2,4) とすると条件を全て満たします。
このほかにも、 P=(1,3,2,4) や P=(4,3,2,1) なども条件を全て満たします。
入力例 2
5 -1 -1 1 -1 1
出力例 2
No
条件を全て満たす P は存在しません。
入力例 3
7 3 -1 4 -1 5 -1 2
出力例 3
Yes 3 7 4 1 5 6 2
Score : 200 points
Problem Statement
You are given an integer sequence A=(A_1,A_2,\ldots,A_N) of length N. Here, each element of A is either -1 or an integer between 1 and N, inclusive.
Determine whether there exists an integer sequence P=(P_1,P_2,\ldots,P_N) of length N that satisfies all of the following conditions, and if it exists, find one.
- P is a permutation of (1,2,\ldots,N).
- For i=1,2,\ldots,N, if A_i \neq -1, then P_i=A_i holds.
Constraints
- 1\le N\le 10
- A_i=-1 or 1\le A_i \le N
- 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
If there is no P that satisfies all conditions, output No.
Otherwise, output P that satisfies all conditions in the following format:
Yes P_1 P_2 \ldots P_N
If there are multiple P that satisfy all conditions, any of them may be output.
Sample Input 1
4 -1 -1 2 -1
Sample Output 1
Yes 3 1 2 4
P=(3,1,2,4) satisfies all conditions.
Besides this, P=(1,3,2,4) or P=(4,3,2,1) also satisfies all conditions.
Sample Input 2
5 -1 -1 1 -1 1
Sample Output 2
No
There is no P that satisfies all conditions.
Sample Input 3
7 3 -1 4 -1 5 -1 2
Sample Output 3
Yes 3 7 4 1 5 6 2
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 250 点
問題文
長さ N の数列 A が与えられます。
A のうち丁度 K 要素を自由に選んで消し、残った要素を順序を保って連結した数列を B とします。
( B の最大値 ) - ( B の最小値 ) としてありうる最小値を求めてください。
制約
- 入力は全て整数
- 1 \le K < N \le 2 \times 10^5
- 1 \le A_i \le 10^9
入力
入力は以下の形式で標準入力から与えられる。
N K A_1 A_2 \dots A_N
出力
答えを整数として出力せよ。
入力例 1
5 2 3 1 5 4 9
出力例 1
2
A=(3,1,5,4,9) から丁度 2 要素を自由に選んで消すことを考えます。
- 例えば 2 要素目の 1 、 5 要素目の 9 を消すと、消した後の数列 B=(3,5,4) となります。
- このとき B の最大値は 5 、最小値は 3 なので ( B の最大値 ) - ( B の最小値 ) =2 となり、これは達成可能な最小値です。
入力例 2
6 5 1 1 1 1 1 1
出力例 2
0
入力例 3
8 3 31 43 26 6 18 36 22 13
出力例 3
18
Score : 250 points
Problem Statement
You are given a sequence A of length N.
Freely choose exactly K elements from A and remove them, then concatenate the remaining elements in their original order to form a new sequence B.
Find the minimum possible value of this: the maximum value of B minus the minimum value of B.
Constraints
- All inputs are integers.
- 1 \le K < N \le 2 \times 10^5
- 1 \le A_i \le 10^9
Input
The input is given from Standard Input in the following format:
N K A_1 A_2 \dots A_N
Output
Print the answer as an integer.
Sample Input 1
5 2 3 1 5 4 9
Sample Output 1
2
Consider removing exactly two elements from A=(3,1,5,4,9).
- For example, if you remove the 2nd element 1 and the 5th element 9, the resulting sequence is B=(3,5,4).
- In this case, the maximum value of B is 5 and the minimum value is 3, so (maximum value of B) - (minimum value of B) =2, which is the minimum possible value.
Sample Input 2
6 5 1 1 1 1 1 1
Sample Output 2
0
Sample Input 3
8 3 31 43 26 6 18 36 22 13
Sample Output 3
18
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
長さ N の数列 A=(a_1,\ldots,a_N) があります。また、整数 K が与えられます。
あなたは次の操作を 0 回以上何度でも行えます。
- 1 \leq i \leq N-K を満たす整数 i を選び、a_i と a_{i+K} の値を入れ替える。
A を昇順に並べ替えることが出来るかどうかを判定してください。
制約
- 2 \leq N \leq 2 \times 10^5
- 1 \leq K \leq N-1
- 1 \leq a_i \leq 10^9
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N K a_1 \ldots a_N
出力
A を昇順に並び替えることが出来るならば Yes と、出来ないならば No と出力せよ。
入力例 1
5 2 3 4 1 3 4
出力例 1
Yes
次のように操作をすることで A を昇順に並び替えることが出来ます。
- i=1 とし、a_1 と a_3 の値を入れ替える。数列は (1,4,3,3,4) となる。
- i=2 とし、a_2 と a_4 の値を入れ替える。数列は (1,3,3,4,4) となる。
入力例 2
5 3 3 4 1 3 4
出力例 2
No
入力例 3
7 5 1 2 3 4 5 5 10
出力例 3
Yes
操作を行う必要が無い場合もあります。
Score : 300 points
Problem Statement
We have a sequence of length N: A=(a_1,\ldots,a_N). Additionally, you are given an integer K.
You can perform the following operation zero or more times.
- Choose an integer i such that 1 \leq i \leq N-K, then swap the values of a_i and a_{i+K}.
Determine whether it is possible to sort A in ascending order.
Constraints
- 2 \leq N \leq 2 \times 10^5
- 1 \leq K \leq N-1
- 1 \leq a_i \leq 10^9
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N K a_1 \ldots a_N
Output
If it is possible to sort A in ascending order, print Yes; otherwise, print No.
Sample Input 1
5 2 3 4 1 3 4
Sample Output 1
Yes
The following sequence of operations sorts A in ascending order.
- Choose i=1 to swap the values of a_1 and a_3. A is now (1,4,3,3,4).
- Choose i=2 to swap the values of a_2 and a_4. A is now (1,3,3,4,4).
Sample Input 2
5 3 3 4 1 3 4
Sample Output 2
No
Sample Input 3
7 5 1 2 3 4 5 5 10
Sample Output 3
Yes
No operations may be needed.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
長さ n の数列 S = (s_1, s_2, \dots, s_n) がすべての i (1 \leq i \leq n - 1) に対して s_i \leq s_{i+1} を満たすとき、かつそのときに限り「数列 S は広義単調増加である」と呼びます。
広義単調増加な長さ N の整数列 A = (a_1, a_2, \dots, a_N), B = (b_1, b_2, \dots, b_N) が与えられます。
このとき、次の条件を満たす広義単調増加な長さ N の整数列 C = (c_1, c_2, \dots, c_N) を考えます。
- すべての i (1 \leq i \leq N) に対して a_i \leq c_i \leq b_i が成り立つ。
整数列 C としてあり得る数列の個数を 998244353 で割ったあまりを求めてください。
制約
- 1 \leq N \leq 3000
- 0 \leq a_i \leq b_i \leq 3000 (1 \leq i \leq N)
- 整数列 A,B は広義単調増加である。
- 入力はすべて整数である。
入力
入力は以下の形式で標準入力から与えられる。
N a_1 a_2 \dots a_N b_1 b_2 \dots b_N
出力
C としてあり得る数列の個数を 998244353 で割ったあまりを出力せよ。
入力例 1
2 1 1 2 3
出力例 1
5
C としてあり得る数列は次の 5 個です。
- (1, 1)
- (1, 2)
- (1, 3)
- (2, 2)
- (2, 3)
数列 (2, 1) は広義単調増加でないため条件を満たさないことに注意してください。
入力例 2
3 2 2 2 2 2 2
出力例 2
1
C としてあり得る数列は次の 1 個です。
- (2, 2, 2)
入力例 3
10 1 2 3 4 5 6 7 8 9 10 1 4 9 16 25 36 49 64 81 100
出力例 3
978222082
個数を 998244353 で割ったあまりを求めることに注意してください。
Score : 400 points
Problem Statement
A sequence of n numbers, S = (s_1, s_2, \dots, s_n), is said to be non-decreasing if and only if s_i \leq s_{i+1} holds for every i (1 \leq i \leq n - 1).
Given are non-decreasing sequences of N integers each: A = (a_1, a_2, \dots, a_N) and B = (b_1, b_2, \dots, b_N).
Consider a non-decreasing sequence of N integers, C = (c_1, c_2, \dots, c_N), that satisfies the following condition:
- a_i \leq c_i \leq b_i for every i (1 \leq i \leq N).
Find the number, modulo 998244353, of sequences that can be C.
Constraints
- 1 \leq N \leq 3000
- 0 \leq a_i \leq b_i \leq 3000 (1 \leq i \leq N)
- The sequences A and B are non-decreasing.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N a_1 a_2 \dots a_N b_1 b_2 \dots b_N
Output
Print the number, modulo 998244353, of sequences that can be C.
Sample Input 1
2 1 1 2 3
Sample Output 1
5
There are five sequences that can be C, as follows.
- (1, 1)
- (1, 2)
- (1, 3)
- (2, 2)
- (2, 3)
Note that (2, 1) does not satisfy the condition since it is not non-decreasing.
Sample Input 2
3 2 2 2 2 2 2
Sample Output 2
1
There is one sequence that can be C, as follows.
- (2, 2, 2)
Sample Input 3
10 1 2 3 4 5 6 7 8 9 10 1 4 9 16 25 36 49 64 81 100
Sample Output 3
978222082
Be sure to find the count modulo 998244353.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 475 点
問題文
縦 H 行, 横 W 列のグリッドがあります。グリッドの上から i 行目, 左から j 列目のマスを (i, j) と呼びます。
グリッドの各マスは穴の空いたマスとそうでないマスのどちらかです。穴が空いたマスは (a_1, b_1), (a_2, b_2), \dots, (a_N, b_N) のちょうど N マスです。
正整数の組 (i, j, n) が次の条件を満たすとき、(i, j) を左上隅, (i + n - 1, j + n - 1) を右下隅とする正方形領域を 穴のない正方形 と呼びます。
- i + n - 1 \leq H
- j + n - 1 \leq W
- 0 \leq k \leq n - 1, 0 \leq l \leq n - 1 を満たす全ての非負整数の組 (k, l) に対して、(i + k, j + l) は穴が空いていないマスである。
グリッド内に穴のない正方形は何個ありますか?
制約
- 1 \leq H, W \leq 3000
- 0 \leq N \leq \min(H \times W, 10^5)
- 1 \leq a_i \leq H
- 1 \leq b_i \leq W
- (a_i, b_i) は互いに異なる
- 入力される値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
H W N a_1 b_1 a_2 b_2 \vdots a_N b_N
出力
穴のない正方形の個数を出力せよ。
入力例 1
2 3 1 2 3
出力例 1
6
穴のない正方形は全部で 6 個あります。
それらを列挙すると次の通りです。このうちはじめの 5 個は n = 1 の場合であり、領域の左上隅のマスと右下隅のマスが一致します。
- (1, 1) を左上隅かつ右下隅とする正方形領域
- (1, 2) を左上隅かつ右下隅とする正方形領域
- (1, 3) を左上隅かつ右下隅とする正方形領域
- (2, 1) を左上隅かつ右下隅とする正方形領域
- (2, 2) を左上隅かつ右下隅とする正方形領域
- (1, 1) を左上隅, (2, 2) を右下隅とする正方形領域
入力例 2
3 2 6 1 1 1 2 2 1 2 2 3 1 3 2
出力例 2
0
穴のない正方形が存在しない場合もあります。
入力例 3
1 1 0
出力例 3
1
穴のない正方形がグリッド全体と一致する場合もあります。
入力例 4
3000 3000 0
出力例 4
9004500500
Score : 475 points
Problem Statement
There is a grid with H rows and W columns. Let (i, j) denote the square at the i-th row from the top and j-th column from the left of the grid.
Each square of the grid is holed or not. There are exactly N holed squares: (a_1, b_1), (a_2, b_2), \dots, (a_N, b_N).
When the triple of positive integers (i, j, n) satisfies the following condition, the square region whose top-left corner is (i, j) and whose bottom-right corner is (i + n - 1, j + n - 1) is called a holeless square.
- i + n - 1 \leq H.
- j + n - 1 \leq W.
- For every pair of non-negative integers (k, l) such that 0 \leq k \leq n - 1, 0 \leq l \leq n - 1, square (i + k, j + l) is not holed.
How many holeless squares are in the grid?
Constraints
- 1 \leq H, W \leq 3000
- 0 \leq N \leq \min(H \times W, 10^5)
- 1 \leq a_i \leq H
- 1 \leq b_i \leq W
- All (a_i, b_i) are pairwise different.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
H W N a_1 b_1 a_2 b_2 \vdots a_N b_N
Output
Print the number of holeless squares.
Sample Input 1
2 3 1 2 3
Sample Output 1
6
There are six holeless squares, listed below. For the first five, n = 1, and the top-left and bottom-right corners are the same square.
- The square region whose top-left and bottom-right corners are (1, 1).
- The square region whose top-left and bottom-right corners are (1, 2).
- The square region whose top-left and bottom-right corners are (1, 3).
- The square region whose top-left and bottom-right corners are (2, 1).
- The square region whose top-left and bottom-right corners are (2, 2).
- The square region whose top-left corner is (1, 1) and whose bottom-right corner is (2, 2).
Sample Input 2
3 2 6 1 1 1 2 2 1 2 2 3 1 3 2
Sample Output 2
0
There may be no holeless square.
Sample Input 3
1 1 0
Sample Output 3
1
The whole grid may be a holeless square.
Sample Input 4
3000 3000 0
Sample Output 4
9004500500
Time Limit: 3 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
長さ N の整数列 A=(A_1,A_2,\ldots,A_N), B=(B_1,B_2,\ldots,B_N),C=(C_1,C_2,\ldots,C_N) および整数 K が与えられます。
1\leq i,j,k\leq N を満たす整数 i,j,k の選び方 N^3 通りそれぞれに対して A_iB_j+B_jC_k+C_kA_i の値を計算したとき、その中で大きい方から K 番目の値を求めてください。
制約
- 1\leq N\leq 2\times 10^5
- 1\leq K\leq \min(N^3,5\times 10^5)
- 1\leq A_i,B_i,C_i\leq 10^9
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N K A_1 A_2 \ldots A_N B_1 B_2 \ldots B_N C_1 C_2 \ldots C_N
出力
答えを出力せよ。
入力例 1
2 5 1 2 3 4 5 6
出力例 1
31
N^3=8 個の整数の値は以下の通りです。
- (i,j,k)=(1,1,1) : A_1B_1+B_1C_1+C_1A_1=1\times 3+3\times 5+5\times 1=23
- (i,j,k)=(1,1,2) : A_1B_1+B_1C_2+C_2A_1=1\times 3+3\times 6+6\times 1=27
- (i,j,k)=(1,2,1) : A_1B_2+B_2C_1+C_1A_1=1\times 4+4\times 5+5\times 1=29
- (i,j,k)=(1,2,2) : A_1B_2+B_2C_2+C_2A_1=1\times 4+4\times 6+6\times 1=34
- (i,j,k)=(2,1,1) : A_2B_1+B_1C_1+C_1A_2=2\times 3+3\times 5+5\times 2=31
- (i,j,k)=(2,1,2) : A_2B_1+B_1C_2+C_2A_2=2\times 3+3\times 6+6\times 2=36
- (i,j,k)=(2,2,1) : A_2B_2+B_2C_1+C_1A_2=2\times 4+4\times 5+5\times 2=38
- (i,j,k)=(2,2,2) : A_2B_2+B_2C_2+C_2A_2=2\times 4+4\times 6+6\times 2=44
これらを値の降順に並べ替えると (44,38,36,34,31,29,27,23) となるため、 大きい方から 5 番目の値は 31 です。
入力例 2
3 10 100 100 100 100 100 100 100 100 100
出力例 2
30000
入力例 3
5 54 800516877 573289179 26509423 168629803 696409999 656737335 915059758 201458890 931198638 185928366 140174496 254538849 830992027 305186313 322164559
出力例 3
689589940713840351
Score : 500 points
Problem Statement
You are given three integer sequences of length N, namely A=(A_1,A_2,\ldots,A_N), B=(B_1,B_2,\ldots,B_N), and C=(C_1,C_2,\ldots,C_N), and an integer K.
For each of the N^3 choices of integers i,j,k (1\leq i,j,k\leq N), compute the value A_iB_j + B_jC_k + C_kA_i. Among all these values, find the K-th largest value.
Constraints
- 1\leq N \leq 2\times 10^5
- 1\leq K \leq \min(N^3,5\times 10^5)
- 1\leq A_i,B_i,C_i \leq 10^9
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N K A_1 A_2 \ldots A_N B_1 B_2 \ldots B_N C_1 C_2 \ldots C_N
Output
Print the answer.
Sample Input 1
2 5 1 2 3 4 5 6
Sample Output 1
31
The N^3=8 values are computed as follows:
- For (i,j,k)=(1,1,1): A_1B_1+B_1C_1+C_1A_1=1\times 3+3\times 5+5\times 1=23
- For (i,j,k)=(1,1,2): A_1B_1+B_1C_2+C_2A_1=1\times 3+3\times 6+6\times 1=27
- For (i,j,k)=(1,2,1): A_1B_2+B_2C_1+C_1A_1=1\times 4+4\times 5+5\times 1=29
- For (i,j,k)=(1,2,2): A_1B_2+B_2C_2+C_2A_1=1\times 4+4\times 6+6\times 1=34
- For (i,j,k)=(2,1,1): A_2B_1+B_1C_1+C_1A_2=2\times 3+3\times 5+5\times 2=31
- For (i,j,k)=(2,1,2): A_2B_1+B_1C_2+C_2A_2=2\times 3+3\times 6+6\times 2=36
- For (i,j,k)=(2,2,1): A_2B_2+B_2C_1+C_1A_2=2\times 4+4\times 5+5\times 2=38
- For (i,j,k)=(2,2,2): A_2B_2+B_2C_2+C_2A_2=2\times 4+4\times 6+6\times 2=44
Sorting these values in descending order, we have (44,38,36,34,31,29,27,23), so the 5th largest value is 31.
Sample Input 2
3 10 100 100 100 100 100 100 100 100 100
Sample Output 2
30000
Sample Input 3
5 54 800516877 573289179 26509423 168629803 696409999 656737335 915059758 201458890 931198638 185928366 140174496 254538849 830992027 305186313 322164559
Sample Output 3
689589940713840351