A - Permute to Maximize

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

配点 : 100

問題文

1 以上 9 以下の数字 A,B,C が与えられます。

A,B,C を好きな順番で並べて繋げることで作れる 3 桁の整数のうち、値が最大のものを求めてください。

制約

  • A,B,C1 以上 9 以下の数字

入力

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

A B C

出力

答えを出力せよ。


入力例 1

3 2 4

出力例 1

432

A,B,C を好きな順番で並べて繋げることで作れる 3 桁の整数は 324, 342, 234, 243, 432, 4236 通りであり、 このうち値が最大のものは 432 です。


入力例 2

7 7 7

出力例 2

777

777 のみを作ることができます。


入力例 3

9 1 9

出力例 3

991

Score : 100 points

Problem Statement

You are given three digits A,B,C between 1 and 9, inclusive.

Find the maximum value among all 3-digit integers that can be formed by arranging A,B,C in any order and concatenating them.

Constraints

  • A,B,C are digits between 1 and 9, inclusive.

Input

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

A B C

Output

Output the answer.


Sample Input 1

3 2 4

Sample Output 1

432

There are six 3-digit integers that can be formed by arranging A,B,C in any order and concatenating them: 324, 342, 234, 243, 432, 423; the maximum value among them is 432.


Sample Input 2

7 7 7

Sample Output 2

777

Only 777 can be formed.


Sample Input 3

9 1 9

Sample Output 3

991
B - I'm a teapot

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

配点 : 100

問題文

高橋君はティーポットです。
高橋君はティーポットなので、紅茶なら喜んで受け入れますが、それ以外の液体を入れようとすると拒否してしまいます。
高橋君に S という名前の液体を入れることが出来るか判定してください。

英小文字からなる長さ N の文字列 S が与えられます。
Stea で終わる文字列であるかどうかを判定してください。

制約

  • 1 \leq N \leq 20
  • N は整数
  • S は英小文字からなる長さ N の文字列

入力

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

N
S

出力

Stea で終わる文字列であれば Yes を、そうでなければ No を出力せよ。


入力例 1

8
greentea

出力例 1

Yes

greenteatea で終わる文字列です。


入力例 2

6
coffee

出力例 2

No

coffeetea で終わる文字列ではありません。


入力例 3

3
tea

出力例 3

Yes

入力例 4

1
t

出力例 4

No

Score : 100 points

Problem Statement

Takahashi is a teapot.
Since he is a teapot, he will gladly accept tea, but will refuse any other liquid.
Determine whether you can pour a liquid named S into him.

You are given a string S of length N consisting of lowercase English letters.
Determine whether S is a string that ends with tea.

Constraints

  • 1 \leq N \leq 20
  • N is an integer.
  • S is a string of length N consisting of lowercase English letters.

Input

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

N
S

Output

If S is a string that ends with tea, print Yes; otherwise, print No.


Sample Input 1

8
greentea

Sample Output 1

Yes

greentea is a string that ends with tea.


Sample Input 2

6
coffee

Sample Output 2

No

coffee is not a string that ends with tea.


Sample Input 3

3
tea

Sample Output 3

Yes

Sample Input 4

1
t

Sample Output 4

No
C - Round-Robin Tournament

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

配点 : 200

問題文

1 から N までの番号が付いた N 人のプレイヤーが総当たり戦をしました。この総当たり戦で行われた試合全てについて、二人の一方が勝ち、もう一方が負けました。

総当たり戦の結果は N 個の長さ N の文字列 S_1,S_2,\ldots,S_N によって以下の形式で与えられます。

  • i\neq j のとき、S_ij 文字目は o, x のいずれかであり、o のときプレイヤー i がプレイヤー j に勝ったことを、x のときプレイヤー i がプレイヤー j に負けたことを意味する。

  • i=j のとき、S_ij 文字目は - である。

総当たり戦で勝った試合数が多いほうが順位が上であり、勝った試合数が同じ場合は、プレイヤーの番号が小さいほうが順位が上となります。 N 人のプレイヤーの番号を順位が高い順に答えてください。

制約

  • 2\leq N\leq 100
  • N は整数
  • S_io, x, - からなる長さ N の文字列
  • S_1,\ldots,S_N は問題文中の形式を満たす

入力

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

N 
S_1
S_2
\vdots
S_N

出力

N 人のプレイヤーの番号を、順位が高い順に空白区切りで出力せよ。


入力例 1

3
-xx
o-x
oo-

出力例 1

3 2 1

プレイヤー 10 勝、プレイヤー 21 勝、プレイヤー 32 勝なので、プレイヤーの番号は順位が高い順に 3,2,1 です。


入力例 2

7
-oxoxox
x-xxxox
oo-xoox
xoo-ooo
ooxx-ox
xxxxx-x
oooxoo-

出力例 2

4 7 3 1 5 2 6

プレイヤー 4 とプレイヤー 7 はどちらも 5 勝ですが、プレイヤー番号が小さいプレイヤー 4 のほうが順位が上になります。

Score : 200 points

Problem Statement

There are N players numbered 1 to N, who have played a round-robin tournament. For every match in this tournament, one player won and the other lost.

The results of the matches are given as N strings S_1,S_2,\ldots,S_N of length N each, in the following format:

  • If i\neq j, the j-th character of S_i is o or x. o means that player i won against player j, and x means that player i lost to player j.

  • If i=j, the j-th character of S_i is -.

The player with more wins ranks higher. If two players have the same number of wins, the player with the smaller player number ranks higher. Report the player numbers of the N players in descending order of rank.

Constraints

  • 2\leq N\leq 100
  • N is an integer.
  • S_i is a string of length N consisting of o, x, and -.
  • S_1,\ldots,S_N conform to the format described in the problem statement.

Input

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

N 
S_1
S_2
\vdots
S_N

Output

Print the player numbers of the N players in descending order of rank.


Sample Input 1

3
-xx
o-x
oo-

Sample Output 1

3 2 1

Player 1 has 0 wins, player 2 has 1 win, and player 3 has 2 wins. Thus, the player numbers in descending order of rank are 3,2,1.


Sample Input 2

7
-oxoxox
x-xxxox
oo-xoox
xoo-ooo
ooxx-ox
xxxxx-x
oooxoo-

Sample Output 2

4 7 3 1 5 2 6

Both players 4 and 7 have 5 wins, but player 4 ranks higher because their player number is smaller.

D - Trifecta

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

配点 : 200

問題文

1 から N の番号がついた N 頭の馬が競争をしました。

全ての馬は同時にスタートし、 i 番の馬はスタートからゴールまで T_i 秒かかりました。

1,2,3 着の馬の番号を求めてください。なお、 T_i は相異なることが保証されます。

制約

  • 3\leq N \leq 32
  • 1\leq T_i \leq 200
  • T_i は相異なる
  • 入力は全て整数

入力

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

N
T_1 \dots T_N

出力

1,2,3 着の馬の番号をそれぞれ空白区切りでこの順に出力せよ。


入力例 1

4
100 110 105 95

出力例 1

4 1 3

4,1,3,2 番の順にゴールしました。1,2,3 着の番号である 4,1,3 をこの順に空白区切りで出力してください。


入力例 2

8
72 74 69 70 73 75 71 77

出力例 2

3 4 7

Score : 200 points

Problem Statement

N horses numbered 1 to N had a race.

All horses started simultaneously, and horse i took T_i seconds from the start to the goal.

Find the numbers of the horses that finished in 1st, 2nd, and 3rd places. It is guaranteed that all T_i are distinct.

Constraints

  • 3\leq N \leq 32
  • 1\leq T_i \leq 200
  • All T_i are distinct.
  • All input values are integers.

Input

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

N
T_1 \dots T_N

Output

Output the numbers of the horses that finished in 1st, 2nd, and 3rd places, in this order, separated by spaces.


Sample Input 1

4
100 110 105 95

Sample Output 1

4 1 3

The horses finished in the order 4, 1, 3, 2. Output the numbers for 1st, 2nd, and 3rd places, which are 4, 1, 3, in this order, separated by spaces.


Sample Input 2

8
72 74 69 70 73 75 71 77

Sample Output 2

3 4 7
E - Min Max Pair

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

配点 : 300

問題文

1 以上 N 以下の整数からなる長さ N の数列 a = (a_1, \dots, a_N) が与えられます。

以下の条件を全て満たす整数 i, j の組の総数を求めてください。

  • 1 \leq i \lt j \leq N
  • \min(a_i, a_j) = i
  • \max(a_i, a_j) = j

制約

  • 2 \leq N \leq 5 \times 10^5
  • 1 \leq a_i \leq N \, (1 \leq i \leq N)
  • 入力は全て整数

入力

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

N
a_1 \ldots a_N

出力

答えを出力せよ。


入力例 1

4
1 3 2 4

出力例 1

2

(i, j) = (1, 4), (2, 3) が条件を満たします。


入力例 2

10
5 8 2 2 1 6 7 2 9 10

出力例 2

8

Score : 300 points

Problem Statement

You are given a sequence a = (a_1, \dots, a_N) of length N consisting of integers between 1 and N.

Find the number of pairs of integers i, j that satisfy all of the following conditions:

  • 1 \leq i \lt j \leq N
  • \min(a_i, a_j) = i
  • \max(a_i, a_j) = j

Constraints

  • 2 \leq N \leq 5 \times 10^5
  • 1 \leq a_i \leq N \, (1 \leq i \leq N)
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
a_1 \ldots a_N

Output

Print the answer.


Sample Input 1

4
1 3 2 4

Sample Output 1

2

(i, j) = (1, 4), (2, 3) satisfy the conditions.


Sample Input 2

10
5 8 2 2 1 6 7 2 9 10

Sample Output 2

8
F - ~

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

配点 : 350

問題文

整数列 A = (A_1, A_2, \ldots, A_{|A|}) に対し、Aチルダ型 とは以下の 4 つの条件をすべて満たすことであると定義します。

  • A の長さ |A|4 以上である
  • A_1 < A_2 である
  • A_{i - 1} < A_i > A_{i + 1} を満たす 2 \leq i < |A| なる整数 i はちょうど 1 個である 
  • A_{i - 1} > A_i < A_{i + 1} を満たす 2 \leq i < |A| なる整数 i はちょうど 1 個である 

数列 (1, 2, \ldots, N) を並べ替えて得られる数列 P = (P_1, P_2, \ldots, P_N) が与えられます。P の連続部分列であってチルダ型である数列の個数を求めてください。

制約

  • 4 \leq N \leq 3 \times 10^5
  • P = (P_1, P_2, \ldots, P_N)(1, 2, \ldots, N) を並べ替えて得られる数列
  • 入力される値はすべて整数

入力

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

N
P_1 P_2 \ldots P_N

出力

答えを出力せよ。


入力例 1

6
1 3 6 4 2 5

出力例 1

2

数列 (1, 3, 6, 4, 2, 5) の連続部分列のうちチルダ型であるものは (3, 6, 4, 2, 5), (1, 3, 6, 4, 2, 5)2 つのみです。


入力例 2

6
1 2 3 4 5 6

出力例 2

0

入力例 3

12
11 3 8 9 5 2 10 4 1 6 12 7

出力例 3

4

Score : 350 points

Problem Statement

For an integer sequence A = (A_1, A_2, \ldots, A_{|A|}), we say that A is tilde-shaped if it satisfies all of the following four conditions:

  • The length |A| is at least 4.
  • A_1 < A_2.
  • There exists exactly one integer i with 2 \leq i < |A| such that A_{i-1} < A_i > A_{i+1}.
  • There exists exactly one integer i with 2 \leq i < |A| such that A_{i-1} > A_i < A_{i+1}.

You are given a permutation P = (P_1, P_2, \ldots, P_N) of (1, 2, \ldots, N). Find the number of (contiguous) subarrays of P that are tilde-shaped.

Constraints

  • 4 \leq N \leq 3 \times 10^5
  • P = (P_1, P_2, \ldots, P_N) is a permutation of (1, 2, \ldots, N).
  • All input values are integers.

Input

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

N
P_1 P_2 \ldots P_N

Output

Output the answer.


Sample Input 1

6
1 3 6 4 2 5

Sample Output 1

2

Among the subarrays of (1, 3, 6, 4, 2, 5), exactly two are tilde-shaped: (3, 6, 4, 2, 5) and (1, 3, 6, 4, 2, 5).


Sample Input 2

6
1 2 3 4 5 6

Sample Output 2

0

Sample Input 3

12
11 3 8 9 5 2 10 4 1 6 12 7

Sample Output 3

4
G - 2x2 Erasing 2

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

配点 : 425

問題文

HW 列のマス目があり、各マスは白または黒に塗られています。
マス目の上から i 番目 (1\leq i\leq H) かつ左から j 番目 (1\leq j\leq W) のマスをマス (i,j) と表すことにします。
マス目の状態は H 個の、.# のみからなる長さ W の文字列 S_1,S_2,\ldots,S_H によって与えられ、
S_ij 文字目が . のとき、マス (i,j) が白く塗られていることを、# のときマス (i,j) が黒く塗られていることを表します。

高橋君はいくつか(0 個でも良い)の黒く塗られたマスを白に塗り替えることで、 マス目が黒く塗られたマスのみからなる 2\times 2 の部分を持たないようにしたいです。 より厳密には、次の条件をみたすようにしたいです。

1\leq i\leq H-1, 1\leq j\leq W-1 をみたす任意の整数の組 (i,j) について、 マス (i,j), マス (i,j+1), マス (i+1,j), マス (i+1,j+1) のうち 少なくとも 1 つは白く塗られている

高橋君が目標を達成するために、白く塗り替える必要のあるマスの個数の最小値を求めてください。

T 個のテストケースが与えられるので、それぞれについて答えを求めてください。

制約

  • 1\leq T\leq 100
  • 2\leq H\leq 7
  • 2\leq W\leq 7
  • S_i.# のみからなる長さ W の文字列
  • T,H,W は整数

入力

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

T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_T

\mathrm{case}_ii 番目のテストケースを表す。 各テストケースは以下の形式で与えられる。

H W
S_1
S_2
\vdots
S_H

出力

T 行出力せよ。
i 行目 (1\leq i\leq T) には、i 個目のテストケースの答えを出力せよ。


入力例 1

2
5 5
####.
##.##
#####
.####
##.#.
2 2
..
..

出力例 1

3
0

1 つめのテストケースについて、マス目の最初の状態は、下図左のようになっています。
このマス目の黒いマスのうち、例えば下図右の番号が入っている 3 つのマスを白く塗り替えることで、条件をみたすようにできます。

最初の状態から 2 個以下のマスを白く塗ることで条件をみたすようにすることはできないため、31 行目に出力します。

2 つめのテストケースについて、マス目は最初から条件をみたしています。
よって、02 行目に出力します。

Score : 425 points

Problem Statement

There is a grid with H rows and W columns, and each cell is painted white or black.
Let us denote the cell at the i-th row from the top (1\leq i\leq H) and the j-th column from the left (1\leq j\leq W) by cell (i,j).
The state of the grid is given by H strings S_1,S_2,\ldots,S_H of length W consisting of . and #.
If the j-th character of S_i is ., then cell (i,j) is white; if it is #, then cell (i,j) is black.

By repainting some black cells (possibly zero) to white, Takahashi wants to make the grid have no 2\times 2 subgrid consisting only of black cells. More precisely, he wants to satisfy the following condition.

For any integer pair (i,j) with 1\leq i\leq H-1 and 1\leq j\leq W-1, among cells (i,j), (i,j+1), (i+1,j), and (i+1,j+1), at least one is white.

Find the minimum number of cells that need to be repainted white in order for Takahashi to achieve his goal.

You are given T test cases; answer each of them.

Constraints

  • 1\leq T\leq 100
  • 2\leq H\leq 7
  • 2\leq W\leq 7
  • Each S_i is a string of length W consisting of . and #.
  • T,H,W are integers.

Input

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

T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_T

\mathrm{case}_i represents the i-th test case. Each test case is given in the following format:

H W
S_1
S_2
\vdots
S_H

Output

Output T lines. On the i-th line (1\leq i\leq T), output the answer for the i-th test case.


Sample Input 1

2
5 5
####.
##.##
#####
.####
##.#.
2 2
..
..

Sample Output 1

3
0

For the first test case, the initial state of the grid is as shown in the left figure below. By repainting, for example, the three cells with numbers in the right figure below from black to white, the condition can be satisfied.

It is impossible to satisfy the condition by repainting two or fewer cells from the initial state, so output 3 on the 1-st line.

For the second test case, the grid already satisfies the condition from the beginning. Thus, output 0 on the 2-nd line.

H - Insert or Erase

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

配点 : 475

問題文

長さ N の数列 A=(A_1,\ldots,A_N) が与えられます。A の要素は相異なります。

Q 個のクエリが与えられるので順に処理してください。各クエリは次の 2 種類のどちらかです。

  • 1 x yA 内の要素 x の直後に y を挿入する。このクエリが与えられる時点で、A には x が存在することが保証される。
  • 2 xA 内の要素 x を削除する。このクエリが与えられる時点で、A には x が存在することが保証される。

各クエリの処理後、A は空でなく、要素は相異なることが保証されます。

全てのクエリを処理した後の A を出力してください。

制約

  • 1 \leq N \leq 2\times 10^5
  • 1 \leq Q \leq 2\times 10^5
  • 1 \leq A_i \leq 10^9
  • A_i \neq A_j
  • 1 種類目のクエリにおいて、1 \leq x,y \leq 10^9
  • 1 種類目のクエリが与えられる時点で、A には x が存在する
  • 2 種類目のクエリにおいて、1 \leq x \leq 10^9
  • 2 種類目のクエリが与えられる時点で、A には x が存在する
  • 各クエリの処理後、A は空でなく、要素は相異なる
  • 入力は全て整数である

入力

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

N
A_1 \ldots A_N
Q
\mathrm{Query}_1
\vdots
\mathrm{Query}_Q

ここで \mathrm{Query}_ii 番目のクエリを表し、次の形式で与えられる。

1 x y
2 x

出力

全てのクエリを処理したあとの数列 A(A_1,\ldots,A_K) とする。A_1,\ldots,A_K をこの順に空白区切りで出力せよ。


入力例 1

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

出力例 1

4 5 1 3

クエリは次のように処理されます。

  • 最初 A=(2,1,4,3) である。
  • 1 番目のクエリにより 1 を削除する。A=(2,4,3) となる。
  • 2 番目のクエリにより、4 の直後に 5 を挿入する。A=(2,4,5,3) となる。
  • 3 番目のクエリにより 2 を削除する。A=(4,5,3) となる。
  • 4 番目のクエリにより、5 の直後に 1 を挿入する。A=(4,5,1,3) となる。

入力例 2

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

出力例 2

5 1 7 2 3

Score: 475 points

Problem Statement

You are given a sequence A=(A_1,\ldots,A_N) of length N. The elements of A are distinct.

Process Q queries in the order they are given. Each query is of one of the following two types:

  • 1 x y : Insert y immediately after the element x in A. It is guaranteed that x exists in A when this query is given.
  • 2 x : Remove the element x from A. It is guaranteed that x exists in A when this query is given.

It is guaranteed that after processing each query, A will not be empty, and its elements will be distinct.

Print A after processing all the queries.

Constraints

  • 1 \leq N \leq 2\times 10^5
  • 1 \leq Q \leq 2\times 10^5
  • 1 \leq A_i \leq 10^9
  • A_i \neq A_j
  • For queries of the first type, 1 \leq x,y \leq 10^9.
  • When a query of the first type is given, x exists in A.
  • For queries of the second type, 1 \leq x \leq 10^9.
  • When a query of the second type is given, x exists in A.
  • After processing each query, A is not empty, and its elements are distinct.
  • All input values are integers.

Input

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

N 
A_1 \ldots A_N
Q
\mathrm{Query}_1
\vdots 
\mathrm{Query}_Q

Here, \mathrm{Query}_i represents the i-th query and is given in one of the following formats:

1 x y
2 x 

Output

Let A=(A_1,\ldots,A_K) be the sequence after processing all the queries. Print A_1,\ldots,A_K in this order, separated by spaces.


Sample Input 1

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

Sample Output 1

4 5 1 3

The queries are processed as follows:

  • Initially, A=(2,1,4,3).
  • The first query removes 1, making A=(2,4,3).
  • The second query inserts 5 immediately after 4, making A=(2,4,5,3).
  • The third query removes 2, making A=(4,5,3).
  • The fourth query inserts 1 immediately after 5, making A=(4,5,1,3).

Sample Input 2

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

Sample Output 2

5 1 7 2 3
I - Cake Division

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

配点 : 575

問題文

円形のケーキがあり、ケーキは切り目によって N 個のピースに分けられています。各切り目は円の中心と円弧上の点を結ぶ線分です。

ピースおよび切り目には時計回りに 1, 2, \ldots, N の番号が付けられており、ピース i の質量は A_i です。ピース 1 をピース N + 1 とも呼ぶこととします。

切り目 i は ピース i とピース i + 1 の間にあり、ピース 1, 切り目 1, ピース 2, 切り目 2, \ldots, ピース N, 切り目 N の順に時計回りに並んでいます。

このケーキを以下の条件を満たすように K 人に分けようとしています。ただし、i 番目の人が受け取るピースの質量の合計を w_i とします。

  • すべての人が 1 つ以上の連続するピースを受け取る
  • 誰も受け取らないピースは存在しない
  • 上の 2 つの条件を満たすという条件下で \min(w_1, w_2, \ldots, w_K) が最大になるようにする

条件を満たす分け方における \min(w_1, w_2, \ldots, w_K) の値および条件を満たすすべての分け方で切られることのない切り目の個数を求めてください。ただし、切り目 i が切られるとは、ピース i とピース i + 1 が異なる人に分けられることを指します。

制約

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

入力

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

N K
A_1 A_2 \ldots A_N

出力

条件を満たす分け方における \min(w_1, w_2, \ldots, w_K) の値を x、 切られることのない切り目の個数を y として、xy をこの順に空白区切りで出力せよ。


入力例 1

5 2
3 6 8 6 4

出力例 1

13 1

以下の分け方が条件を満たします。

  • 一方の人にピース 2, 3 を渡し、もう一方の人にピース 4, 5, 1 を渡す。ピース 2, 3 の質量の合計は 14、ピース 4, 5, 1 の質量の合計は 13 である。
  • 一方の人にピース 3, 4 を渡し、もう一方の人にピース 5, 1, 2 を渡す。ピース 3, 4 の質量の合計は 14、ピース 5, 1, 2 の質量の合計は 13 である。

条件を満たす分け方における \min(w_1, w_2) の値は 13 であり、どちらの分け方でも切られない切り目は切り目 51 つです。


入力例 2

6 3
4 7 11 3 9 2

出力例 2

11 1

入力例 3

10 3
2 9 8 1 7 9 1 3 5 8

出力例 3

17 4

Score : 575 points

Problem Statement

There is a circular cake divided into N pieces by cut lines. Each cut line is a line segment connecting the center of the circle to a point on the arc.

The pieces and cut lines are numbered 1, 2, \ldots, N in clockwise order, and piece i has a mass of A_i. Piece 1 is also called piece N + 1.

Cut line i is between pieces i and i + 1, and they are arranged clockwise in this order: piece 1, cut line 1, piece 2, cut line 2, \ldots, piece N, cut line N.

We want to divide this cake among K people under the following conditions. Let w_i be the sum of the masses of the pieces received by the i-th person.

  • Each person receives one or more consecutive pieces.
  • There are no pieces that no one receives.
  • Under the above two conditions, \min(w_1, w_2, \ldots, w_K) is maximized.

Find the value of \min(w_1, w_2, \ldots, w_K) in a division that satisfies the conditions, and the number of cut lines that are never cut in the divisions that satisfy the conditions. Here, cut line i is considered cut if pieces i and i + 1 are given to different people.

Constraints

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

Output

Let x be the value of \min(w_1, w_2, \ldots, w_K) in a division that satisfies the conditions, and y be the number of cut lines that are never cut. Print x and y in this order, separated by a space.


Sample Input 1

5 2
3 6 8 6 4

Sample Output 1

13 1

The following divisions satisfy the conditions:

  • Give pieces 2, 3 to one person and pieces 4, 5, 1 to the other. Pieces 2, 3 have a total mass of 14, and pieces 4, 5, 1 have a total mass of 13.
  • Give pieces 3, 4 to one person and pieces 5, 1, 2 to the other. Pieces 3, 4 have a total mass of 14, and pieces 5, 1, 2 have a total mass of 13.

The value of \min(w_1, w_2) in divisions satisfying the conditions is 13, and there is one cut line that is not cut in either division: cut line 5.


Sample Input 2

6 3
4 7 11 3 9 2

Sample Output 2

11 1

Sample Input 3

10 3
2 9 8 1 7 9 1 3 5 8

Sample Output 3

17 4