E - abc285_brutmhyhiizp

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

別世界の AtCoder で開催されている AtCoder Big Contest では、 10^{16} 問の問題が一度に出題されます。
問題の ID は 1 問目から順に A, B, ..., Z, AA, AB, ..., ZZ, AAA, ... と付けられています。

つまり、 ID は以下の順番で付けられています。

  • 長さ 1 の英大文字からなる文字列を辞書順に並べたもの
  • 長さ 2 の英大文字からなる文字列を辞書順に並べたもの
  • 長さ 3 の英大文字からなる文字列を辞書順に並べたもの
  • ...

このコンテストに含まれる問題の ID である文字列 S が与えられるので、それが何問目か答えてください。

制約

  • S は AtCoder Big Contest に含まれる問題の ID として正しい

入力

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

S

出力

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


入力例 1

AB

出力例 1

28

ID が AB である問題は、 AtCoder Big Contest の 28 問目です。


入力例 2

C

出力例 2

3

ID が C である問題は、 AtCoder Big Contest の 3 問目です。


入力例 3

BRUTMHYHIIZP

出力例 3

10000000000000000

ID が BRUTMHYHIIZP である問題は、 AtCoder Big Contest の 10^{16} 問目、すなわち最終問題です。

Score : 300 points

Problem Statement

In a parallel universe, AtCoder holds AtCoder Big Contest, where 10^{16} problems are given at once.
The IDs of the problems are as follows, from the 1-st problem in order: A, B, ..., Z, AA, AB, ..., ZZ, AAA, ...

In other words, the IDs are given in the following order:

  • the strings of length 1 consisting of uppercase English letters, in lexicographical order;
  • the strings of length 2 consisting of uppercase English letters, in lexicographical order;
  • the strings of length 3 consisting of uppercase English letters, in lexicographical order;
  • ...

Given a string S that is an ID of a problem given in this contest, find the index of the problem. (See also Samples.)

Constraints

  • S is a valid ID of a problem given in AtCoder Big Contest.

Input

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

S

Output

Print the answer as an integer.


Sample Input 1

AB

Sample Output 1

28

The problem whose ID is AB is the 28-th problem of AtCoder Big Contest, so 28 should be printed.


Sample Input 2

C

Sample Output 2

3

The problem whose ID is C is the 3-rd problem of AtCoder Big Contest, so 3 should be printed.


Sample Input 3

BRUTMHYHIIZP

Sample Output 3

10000000000000000

The problem whose ID is BRUTMHYHIIZP is the 10^{16}-th (last) problem of AtCoder Big Contest, so 10^{16} should be printed as an integer.

F - Don’t be cycle

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

N 頂点 M 辺の単純無向グラフが与えられます。頂点には 1 から N の番号がついており、i 番目の辺は頂点 A_i と頂点 B_i を結んでいます。 このグラフから 0 本以上のいくつかの辺を削除してグラフが閉路を持たないようにするとき、削除する辺の本数の最小値を求めてください。

単純無向グラフとは 単純無向グラフとは、自己ループや多重辺を含まず、辺に向きの無いグラフのことをいいます。

閉路とは 単純無向グラフが閉路を持つとは、i \neq j ならば v_i \neq v_j を満たす長さ 3 以上の頂点列 (v_0, v_1, \ldots, v_{n-1}) であって、各 0 \leq i < n に対し v_iv_{i+1 \bmod n} の間に辺が存在するものがあることをいいます。

制約

  • 1 \leq N \leq 2 \times 10^5
  • 0 \leq M \leq 2 \times 10^5
  • 1 \leq A_i, B_i \leq N
  • 与えられるグラフは単純
  • 入力はすべて整数

入力

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

N M
A_1 B_1
A_2 B_2
\vdots
A_M B_M

出力

答えを出力せよ。


入力例 1

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

出力例 1

2

頂点 1 と頂点 2 を結ぶ辺・頂点 4 と頂点 5 を結ぶ辺の 2 本を削除するなどの方法でグラフが閉路を持たないようにすることができます。
1 本以下の辺の削除でグラフが閉路を持たないようにすることはできないので、2 を出力します。


入力例 2

4 2
1 2
3 4

出力例 2

0

入力例 3

5 3
1 2
1 3
2 3

出力例 3

1

Score : 300 points

Problem Statement

You are given a simple undirected graph with N vertices and M edges. The vertices are numbered 1 to N, and the i-th edge connects vertex A_i and vertex B_i. Let us delete zero or more edges to remove cycles from the graph. Find the minimum number of edges that must be deleted for this purpose.

What is a simple undirected graph? A simple undirected graph is a graph without self-loops or multi-edges whose edges have no direction.

What is a cycle? A cycle in a simple undirected graph is a sequence of vertices (v_0, v_1, \ldots, v_{n-1}) of length at least 3 satisfying v_i \neq v_j if i \neq j such that for each 0 \leq i < n, there is an edge between v_i and v_{i+1 \bmod n}.

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • 0 \leq M \leq 2 \times 10^5
  • 1 \leq A_i, B_i \leq N
  • The given graph is simple.
  • All values in the input are integers.

Input

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

N M
A_1 B_1
A_2 B_2
\vdots
A_M B_M

Output

Print the answer.


Sample Input 1

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

Sample Output 1

2

One way to remove cycles from the graph is to delete the two edges between vertex 1 and vertex 2 and between vertex 4 and vertex 5.
There is no way to remove cycles from the graph by deleting one or fewer edges, so you should print 2.


Sample Input 2

4 2
1 2
3 4

Sample Output 2

0

Sample Input 3

5 3
1 2
1 3
2 3

Sample Output 3

1
G - Project Planning

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 400

問題文

キーエンスには N 個の部署があり、i\,(1 \leq i \leq N) 番目の部署には A_i 人の社員が所属しています。異なる部署に同じ社員が所属していることはありません。

キーエンスは、部署をまたいだ全社横断プロジェクトを計画しています。1 つのプロジェクトは K 個の相異なる部署から 1 人ずつ選出して作り、ちょうど K 人から構成されるようにします。

プロジェクトは最大でいくつ作れますか?ただし、1 人が複数のプロジェクトに参加することはできません。

制約

  • 1 \leq K \leq N \leq 2 \times 10^5
  • 1 \leq A_i \leq 10^{12}
  • 入力は全て整数

入力

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

N K
A_1 A_2 \ldots A_N

出力

プロジェクトの個数の最大値を出力せよ。


入力例 1

3 3
2 3 4

出力例 1

2

3 個の部署それぞれから 1 人ずつ選出したプロジェクトを 2 つ作ることができます。


入力例 2

4 2
1 1 3 4

出力例 2

4

入力例 3

4 3
1 1 3 4

出力例 3

2

Score : 400 points

Problem Statement

KEYENCE has N departments, where A_i employees belong to the i-th department (1 \leq i \leq N). No employee belongs to multiple departments.

The company is planning cross-departmental projects. Each project will be composed of exactly K employees chosen from K distinct departments.

At most how many projects can be made? No employee can participate in multiple projects.

Constraints

  • 1 \leq K \leq N \leq 2 \times 10^5
  • 1 \leq A_i \leq 10^{12}
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 \ldots A_N

Output

Print the maximum possible number of projects.


Sample Input 1

3 3
2 3 4

Sample Output 1

2

There can be two projects, each composed of three employees from distinct departments.


Sample Input 2

4 2
1 1 3 4

Sample Output 2

4

Sample Input 3

4 3
1 1 3 4

Sample Output 3

2
H - Amusement Park

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 500

問題文

髙橋君は遊園地に遊びに行きました。
この遊園地には N 個のアトラクションがあり、i 個目のアトラクションの「楽しさ」の初期値は A_i です。

髙橋君が i 個目のアトラクションに乗ると、以下の現象が順番に起きます。

  • 髙橋君の「満足度」に、i 個目のアトラクションの現在の「楽しさ」が加算される。
  • i 個目のアトラクションの「楽しさ」が、1 減少する。

髙橋君の「満足度」の初期値は 0 です。髙橋君はアトラクションに合計 K 回まで乗ることができます。
最終的な髙橋君の「満足度」の最大値はいくつですか?

なお、髙橋君の「満足度」はアトラクションに乗ること以外で変化しません。

制約

  • 1 \leq N \leq 10^5
  • 1 \leq K \leq 2 \times 10^9
  • 1 \leq A_i \leq 2 \times 10^9
  • 入力は全て整数

入力

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

N K
A_1 A_2 \dots A_N

出力

最終的な髙橋君の「満足度」の最大値を出力せよ。


入力例 1

3 5
100 50 102

出力例 1

502

1 個目のアトラクションに 2 回、3 個目のアトラクションに 3 回乗ります。
最終的な「満足度」は、(100+99)+(102+101+100)=502 です。
「満足度」を 503 以上にする方法はないので、502 が答えになります。


入力例 2

2 2021
2 3

出力例 2

9

アトラクションに乗る合計回数は、K 回より少なくても構いません。

Score : 500 points

Problem Statement

Takahashi has come to an amusement park.
The park has N attractions. The fun of the i-th attraction is initially a_i.

When Takahashi rides the i-th attraction, the following sequence of events happens.

  • Takahashi's satisfaction increases by the current fun of the i-th attraction.
  • Then, the fun of the i-th attraction decreases by 1.

Takahashi's satisfaction is initially 0. He can ride the attractions at most K times in total in any order.
What is the maximum possible value of satisfaction Takahashi can end up with?

Other than riding the attractions, nothing affects Takahashi's satisfaction.

Constraints

  • 1 \leq N \leq 10^5
  • 1 \leq K \leq 2 \times 10^9
  • 1 \leq A_i \leq 2 \times 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 \dots A_N

Output

Print the maximum possible value of satisfaction that Takahashi can end up with.


Sample Input 1

3 5
100 50 102

Sample Output 1

502

Takahashi should ride the first attraction twice and the third attraction three times.
He will end up with the satisfaction of (100+99)+(102+101+100)=502.
There is no way to get the satisfaction of 503 or more, so the answer is 502.


Sample Input 2

2 2021
2 3

Sample Output 2

9

Takahashi may choose to ride the attractions fewer than K times in total.

I - Merge Sets

Time Limit: 4 sec / Memory Limit: 1024 MiB

配点 : 525

問題文

A \cap B = \emptyset を満たす 2 つの整数の集合 A, B に対して、f(A,B) を以下のように定義します。

  • A \cup B に含まれる要素を昇順に並べた数列を C=(C_1,C_2,\dots,C_{|A|+|B|}) とする。
  • A=\lbrace C_{k_1},C_{k_2},\dots,C_{k_{|A|}}\rbrace となるような k_1,k_2,\dots,k_{|A|} をとる。 このとき、\displaystyle f(A,B)=\sum_{i=1}^{|A|} k_i とする。

例えば、A=\lbrace 1,3\rbrace,B=\lbrace 2,8\rbrace のとき、C=(1,2,3,8) より A=\lbrace C_1,C_3\rbrace なので、f(A,B)=1+3=4 です。

それぞれが M 個の要素からなる N 個の整数の集合 S_1,S_2\dots,S_N があり、各 i\ (1 \leq i \leq N) について S_i = \lbrace A_{i,1},A_{i,2},\dots,A_{i,M}\rbrace です。 ただし、S_i \cap S_j = \emptyset\ (i \neq j) が保証されます。

\displaystyle \sum_{1\leq i<j \leq N} f(S_i, S_j) を求めてください。

制約

  • 1\leq N \leq 10^4
  • 1\leq M \leq 10^2
  • 1\leq A_{i,j} \leq 10^9
  • i_1 \neq i_2 または j_1 \neq j_2 ならば A_{i_1,j_1} \neq A_{i_2,j_2}
  • 入力は全て整数

入力

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

N M
A_{1,1} A_{1,2} \dots A_{1,M}
\vdots
A_{N,1} A_{N,2} \dots A_{N,M}

出力

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


入力例 1

3 2
1 3
2 8
4 6

出力例 1

12

S_1,S_2 はそれぞれ問題文中で例示した A,B と一致し、f(S_1,S_2)=1+3=4 です。 f(S_1,S_3)=1+2=3,f(S_2,S_3)=1+4=5 であるため、4+3+5=12 が答えです。


入力例 2

1 1
306

出力例 2

0

入力例 3

4 4
155374934 164163676 576823355 954291757
797829355 404011431 353195922 138996221
191890310 782177068 818008580 384836991
160449218 545531545 840594328 501899080

出力例 3

102

Score : 525 points

Problem Statement

For two sets of integers, A and B, such that A \cap B = \emptyset, we define f(A,B) as follows.

  • Let C=(C_1,C_2,\dots,C_{|A|+|B|}) be a sequence consisting of the elements of A \cup B, sorted in ascending order.
  • Take k_1,k_2,\dots,k_{|A|} such that A=\lbrace C_{k_1},C_{k_2},\dots,C_{k_{|A|}}\rbrace. Then, let \displaystyle f(A,B)=\sum_{i=1}^{|A|} k_i.

For example, if A=\lbrace 1,3\rbrace and B=\lbrace 2,8\rbrace, then C=(1,2,3,8), so A=\lbrace C_1,C_3\rbrace; thus, f(A,B)=1+3=4.

We have N sets of integers, S_1,S_2\dots,S_N, each of which has M elements. For each i\ (1 \leq i \leq N), S_i = \lbrace A_{i,1},A_{i,2},\dots,A_{i,M}\rbrace. Here, it is guaranteed that S_i \cap S_j = \emptyset\ (i \neq j).

Find \displaystyle \sum_{1\leq i<j \leq N} f(S_i, S_j).

Constraints

  • 1\leq N \leq 10^4
  • 1\leq M \leq 10^2
  • 1\leq A_{i,j} \leq 10^9
  • If i_1 \neq i_2 or j_1 \neq j_2, then A_{i_1,j_1} \neq A_{i_2,j_2}.
  • All input values are integers.

Input

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

N M
A_{1,1} A_{1,2} \dots A_{1,M}
\vdots
A_{N,1} A_{N,2} \dots A_{N,M}

Output

Print the answer as an integer.


Sample Input 1

3 2
1 3
2 8
4 6

Sample Output 1

12

S_1 and S_2 respectively coincide with A and B exemplified in the problem statement, and f(S_1,S_2)=1+3=4. Since f(S_1,S_3)=1+2=3 and f(S_2,S_3)=1+4=5, the answer is 4+3+5=12.


Sample Input 2

1 1
306

Sample Output 2

0

Sample Input 3

4 4
155374934 164163676 576823355 954291757
797829355 404011431 353195922 138996221
191890310 782177068 818008580 384836991
160449218 545531545 840594328 501899080

Sample Output 3

102