A - Last Card

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 100

問題文

1,2,\ldots,N の番号のついた N 人の人に合計 K 枚のカードを配ります。

A から始めて 人 A,A+1,A+2,\ldots,N,1,2,\ldots の順に 1 枚ずつカードを配るとき、最後のカードは誰に配られるでしょうか?

厳密には、人 x(1 \leq x < N) の次には人 x+1 にカードを配り、人 N の次には人 1 にカードを配ります。

制約

  • 1 \leq N,K \leq 1000
  • 1 \leq A \leq N
  • 入力は全て整数

入力

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

N K A

出力

最後のカードが配られた人の番号を出力せよ。


入力例 1

3 3 2

出力例 1

1

2、人 3、人 1 の順にカードを配ります。


入力例 2

1 100 1

出力例 2

1

入力例 3

3 14 2

出力例 3

3

Score : 100 points

Problem Statement

We will hand out a total of K cards to N people numbered 1, 2, \ldots, N.

Beginning with Person A, we will give the cards one by one to the people in this order: A, A+1, A+2, \ldots, N, 1, 2, \ldots. Who will get the last card?

Formally, after Person x(1 \leq x < N) gets a card, Person x+1 will get a card. After Person N gets a card, Person 1 gets a card.

Constraints

  • 1 \leq N,K \leq 1000
  • 1 \leq A \leq N
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K A

Output

Print a number representing the person who will get the last card.


Sample Input 1

3 3 2

Sample Output 1

1

The cards are given to Person 2, 3, 1 in this order.


Sample Input 2

1 100 1

Sample Output 2

1

Sample Input 3

3 14 2

Sample Output 3

3
B - KEYENCE building

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 200

問題文

1 から N の番号がついた N 人の人がいます。

i はキーエンス本社ビルの建築面積を S_i 平方メートルであると予想しました。

キーエンス本社ビルは下図のような形をしています。ただし、a,b はある 正の整数 です。
つまり、キーエンス本社ビルの建築面積は 4ab+3a+3b 平方メートルと表されます。

N 人のうち、この情報のみによって、予想した面積が確実に誤りであるとわかる人数を求めてください。

キーエンス本社ビル見取り図

制約

  • 1 \leq N \leq 20
  • 1 \leq S_i \leq 1000
  • 入力に含まれる値は全て整数である

入力

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

N
S_1 \ldots S_N

出力

答えを出力せよ。


入力例 1

3
10 20 39

出力例 1

1

a=1,b=1 のとき面積は 10 平方メートル、a=2,b=3 のとき面積は 39 平方メートルとなります。

しかし a,b がどのような正の整数であったとしても面積が 20 平方メートルになることはありません。

よって、人 2 の予想だけは確実に誤りであることがわかります。


入力例 2

5
666 777 888 777 666

出力例 2

3

Score : 200 points

Problem Statement

There are N people numbered 1 to N.

Person i guessed the building area of KEYENCE headquarters building to be S_i square meters.

The shape of KEYENCE headquarters building is shown below, where a and b are some positive integers.
That is, the building area of the building can be represented as 4ab+3a+3b.

Based on just this information, how many of the N people are guaranteed to be wrong in their guesses?

Sketch of KEYENCE headquarters building

Constraints

  • 1 \leq N \leq 20
  • 1 \leq S_i \leq 1000
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
S_1 \ldots S_N

Output

Print the answer.


Sample Input 1

3
10 20 39

Sample Output 1

1

The area would be 10 square meters if a=1,b=1, and 39 square meters if a=2,b=3.

However, no pair of positive integers a and b would make the area 20 square meters.

Thus, we can only be sure that Person 2 guessed wrong.


Sample Input 2

5
666 777 888 777 666

Sample Output 2

3
C - ABC conjecture

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 300

問題文

正の整数 N が与えられます。

A\leq B\leq C かつ ABC\leq N であるような正の整数の組 (A,B,C) の個数を求めてください。

なお、制約の条件下で答えは 2^{63} 未満であることが保証されます。

制約

  • 1 \leq N \leq 10^{11}
  • N は整数である

入力

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

N

出力

答えを出力せよ。


入力例 1

4

出力例 1

5

条件を満たす組は (1,1,1),(1,1,2),(1,1,3),(1,1,4),(1,2,2)5 つです。


入力例 2

100

出力例 2

323

入力例 3

100000000000

出力例 3

5745290566750

Score : 300 points

Problem Statement

You are given a positive integer N.

Find the number of triples of positive integers (A, B, C) such that A\leq B\leq C and ABC\leq N.

The Constraints guarantee that the answer is less than 2^{63}.

Constraints

  • 1 \leq N \leq 10^{11}
  • N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

Print the answer.


Sample Input 1

4

Sample Output 1

5

There are five such triples: (1,1,1),(1,1,2),(1,1,3),(1,1,4),(1,2,2).


Sample Input 2

100

Sample Output 2

323

Sample Input 3

100000000000

Sample Output 3

5745290566750
D - Project Planning

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 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
E - Swap

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 500

問題文

K, E, Y のみからなる文字列 S が与えられます。

S の隣接する 2 文字を入れ替える操作を K 回まで行えるとき、作ることができる文字列は何種類ありますか?

制約

  • 2 \leq |S| \leq 30
  • 0 \leq K \leq 10^9
  • SK, E, Y のみからなる

入力

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

S
K

出力

答えを出力せよ。


入力例 1

KEY
1

出力例 1

3

KEY に対して 1 回以下の操作を行うことで得られる文字列は KEY, EKY, KYE3 種類です。


入力例 2

KKEE
2

出力例 2

4

KKEE に対して 2 回以下の操作を行うことで得られる文字列は KKEE, KEKE, EKKE, KEEK4 種類です。


入力例 3

KKEEYY
1000000000

出力例 3

90

Score : 500 points

Problem Statement

Given is a string S consisting of K, E, Y.

How many strings are there that can be obtained with at most K swaps of two adjacent characters in S?

Constraints

  • 2 \leq |S| \leq 30
  • 0 \leq K \leq 10^9
  • S consists of K, E, Y.

Input

Input is given from Standard Input in the following format:

S
K

Output

Print the answer.


Sample Input 1

KEY
1

Sample Output 1

3

With at most one swap, there are three strings that can be obtained: KEY, EKY, KYE.


Sample Input 2

KKEE
2

Sample Output 2

4

With at most two swaps, there are four strings that can be obtained: KKEE, KEKE, EKKE, KEEK.


Sample Input 3

KKEEYY
1000000000

Sample Output 3

90
F - Treasure Hunting

Time Limit: 3 sec / Memory Limit: 1024 MB

配点 : 500

問題文

H 行、横 W 列のマス目があります。上から i 行目、左から j 列目のマスを (i,j) と書くことにします。(i,j) には整数 A_{i,j} が書かれています。

高橋君は (1,1) を出発し、(H,W) にたどり着くまで、1 つ右あるいは 1 つ下のマスへ移動することを繰り返します。ただし、マス目の外に出ることはできません。

この時、移動のコストを以下のように定義します。

通った H+W-1 個のマスに書かれた整数のうち大きい方 K 個の和

コストとしてありうる最小値を求めてください。

制約

  • 1 \leq H,W \leq 30
  • 1 \leq K < H+W
  • 1 \leq A_{i,j} \leq 10^9
  • 入力は全て整数

入力

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

H W K
A_{1,1} A_{1,2} \ldots A_{1,W}
A_{2,1} A_{2,2} \ldots A_{2,W}
\vdots
A_{H,1} A_{H,2} \ldots A_{H,W}

出力

答えを出力せよ。


入力例 1

1 3 2
3 4 5

出力例 1

9

移動の方法は一通りのみであり、通ったマスに書かれた整数は大きい方から順に 543 となるので、9(=5+4) を出力します。


入力例 2

2 2 1
3 2
4 3

出力例 2

3

(1,1)(1,2)(2,2) の順に通った時コストが最小となります。


入力例 3

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

出力例 3

21

Score : 500 points

Problem Statement

We have a grid with H horizontal rows and W vertical columns. Let (i, j) denote the square at the i-th row from the top and j-th column from the left. (i, j) contains an integer A_{i,j}.

Takahashi will depart (1, 1) and repeatedly move one square right or down until reaching (H, W). It is not allowed to exit the grid.

The cost of this travel is defined as:

the sum of the K greatest integers among the integers written on the H+W-1 squares traversed.

Find the minimum possible cost.

Constraints

  • 1 \leq H,W \leq 30
  • 1 \leq K < H+W
  • 1 \leq A_{i,j} \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

H W K
A_{1,1} A_{1,2} \ldots A_{1,W}
A_{2,1} A_{2,2} \ldots A_{2,W}
\vdots
A_{H,1} A_{H,2} \ldots A_{H,W}

Output

Print the answer.


Sample Input 1

1 3 2
3 4 5

Sample Output 1

9

There is only one way to travel, where the traversed squares contain the integers 5, 4, 3 from largest to smallest, so we print 9(=5+4).


Sample Input 2

2 2 1
3 2
4 3

Sample Output 2

3

The minimum cost is achieved by traversing (1,1), (1,2), (2,2) in this order.


Sample Input 3

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

Sample Output 3

21
G - Divisors of Binomial Coefficient

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 600

問題文

二項係数 \displaystyle \binom{N}{K} の正の約数の個数を 998244353 で割った余りを求めてください。

制約

  • 1 \leq N \leq 10^{12}
  • 0 \leq K \leq \min(10^6,N)
  • 入力に含まれる値は全て整数である

入力

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

N K

出力

答えを出力せよ。


入力例 1

5 2

出力例 1

4

\displaystyle \binom{5}{2}=10 です。10 の正の約数は 1,2,5,104 個です。


入力例 2

103 3

出力例 2

8

\displaystyle \binom{103}{3}=176851 です。176851 の正の約数は 8 個あります。


入力例 3

1000000000000 1000000

出力例 3

110520107

Score : 600 points

Problem Statement

Find the number, modulo 998244353, of positive divisors of a binomial coefficient \displaystyle \binom{N}{K}.

Constraints

  • 1 \leq N \leq 10^{12}
  • 0 \leq K \leq \min(10^6,N)
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K

Output

Print the answer.


Sample Input 1

5 2

Sample Output 1

4

We have \displaystyle \binom{5}{2}=10, which has four positive divisors: 1,2,5,10.


Sample Input 2

103 3

Sample Output 2

8

We have \displaystyle \binom{103}{3}=176851, which has eight positive divisors.


Sample Input 3

1000000000000 1000000

Sample Output 3

110520107
H - Eat Them All

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 600

問題文

3 行、横 3 列のマス目があります。上から i 行目、左から j 列目のマスを (i,j) と書くことにします。(i,j) には A_{i,j} 個の猫缶が置かれています。

すぬけ君は現在 (1,1) にいます。すぬけ君は以下の行動を繰り返します。

  • すぬけ君が現在いるマスに置かれている猫缶を 1 つ食べた後、隣接するマスに移動する

すぬけ君は、現在いるマスに猫缶が残っていないとき行動を終了します。

行動を終了した時に以下の条件が全て満たされることは可能ですか?可能ならばすぬけ君の行動の一例を示してください。

  • すぬけ君は (1,1) にいる。
  • どのマスにも猫缶が残っていない。

制約

  • 1 \leq A_{i,j} \leq 100
  • 入力は全て整数

入力

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

A_{1,1} A_{1,2} A_{1,3}
A_{2,1} A_{2,2} A_{2,3}
A_{3,1} A_{3,2} A_{3,3}

出力

条件が全て満たされることが不可能な時は NO と出力せよ。

そうでなく、可能な時は L,R,U,D からなる文字列 S を出力せよ。Si 文字目はすぬけ君の i 回目の行動の内容を表し、L1 つ左のマス、R1 つ右のマス、U1 つ上のマス、D1 つ下のマスに移動することをそれぞれ意味する。


入力例 1

1 1 1
1 1 1
1 2 1

出力例 1

DDRUDRUULL

すぬけ君は終了時点で (1,1) に戻っていなければいけないことに注意してください。

なお、RRDDLUDLUU などの出力も正しいです。


入力例 2

2 4 2
2 1 1
1 1 2

出力例 2

NO

目標を達成することは不可能なので、NO と出力してください。


入力例 3

2 2 3
2 1 2
1 3 2

出力例 3

DUDDRUDRLRUULRDULL

Score : 600 points

Problem Statement

We have a grid with 3 horizontal rows and 3 vertical columns. Let (i, j) denote the square at the i-th row from the top and j-th column from the left. (i, j) contains A_{i,j} cans of cat food.

Snuke is now on (1,1). He will repeat the following action.

  • Consume one can on the square he is on, and move up, down, left, or right to an adjacent square.

When there is no more can on the square he is on, he will end this process.

Is it possible that all of the conditions below are satisfied at the end of the process? If it is possible, show one sequence of actions that make it happen.

  • Snuke is at (1,1).
  • There is no more can on every square.

Constraints

  • 1 \leq A_{i,j} \leq 100
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

A_{1,1} A_{1,2} A_{1,3}
A_{2,1} A_{2,2} A_{2,3}
A_{3,1} A_{3,2} A_{3,3}

Output

If it is impossible that the conditions are satisfied, print NO.

If it is possible, print a string S consisting of L, R, U, D. The i-th character of S should represent the i-th action of Snuke, where L, R, U, D means moving one square left, right, up, down, respectively.


Sample Input 1

1 1 1
1 1 1
1 2 1

Sample Output 1

DDRUDRUULL

Note that Snuke must be back on (1, 1) in the end.

There are also other correct outputs, such as RRDDLUDLUU.


Sample Input 2

2 4 2
2 1 1
1 1 2

Sample Output 2

NO

It is impossible to achieve the objective, so print NO.


Sample Input 3

2 2 3
2 1 2
1 3 2

Sample Output 3

DUDDRUDRLRUULRDULL