A - Maximize the Formula

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 100

問題文

あなたは子供にゲームをプレイさせ、その結果に応じてお小遣いをあげることにしました。

そのゲームの内容は以下の通りです。

  • 1 以上 9 以下の整数 1 つが書かれた整数パネル 3 枚と + が書かれた演算子パネル 1 枚がある
  • これら 4 枚のパネルを横一列に並べて X + Y の形の数式を作る (すなわち、演算子パネルを端に置くことはできない)
  • 数式を計算した結果と同じ値のお小遣いをあげる

ゲームで使用する各整数パネルの値 A, B, C が与えられるので、あげることになり得るお小遣いの最大値を求めてください。

制約

  • 入力はすべて整数である
  • 1 \leq A, B, C \leq 9

入力

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

A B C

出力

あげることになり得るお小遣いの最大値を出力せよ。


入力例 1

1 5 2

出力例 1

53

52+1 と並べたときにあげることになるお小遣いは 53 となりこれが最大です。


入力例 2

9 9 9

出力例 2

108

入力例 3

6 6 7

出力例 3

82

Score : 100 points

Problem Statement

You have decided to give an allowance to your child depending on the outcome of the game that he will play now.

The game is played as follows:

  • There are three "integer panels", each with a digit between 1 and 9 (inclusive) printed on it, and one "operator panel" with a + printed on it.
  • The player should construct a formula of the form X + Y, by arranging the four panels from left to right. (The operator panel should not be placed at either end of the formula.)
  • Then, the amount of the allowance will be equal to the resulting value of the formula.

Given the values A, B and C printed on the integer panels used in the game, find the maximum possible amount of the allowance.

Constraints

  • All values in input are integers.
  • 1 \leq A, B, C \leq 9

Input

Input is given from Standard Input in the following format:

A B C

Output

Print the maximum possible amount of the allowance.


Sample Input 1

1 5 2

Sample Output 1

53

The amount of the allowance will be 53 when the panels are arranged as 52+1, and this is the maximum possible amount.


Sample Input 2

9 9 9

Sample Output 2

108

Sample Input 3

6 6 7

Sample Output 3

82
B - 1 Dimensional World's Tale

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 200

問題文

この世界は 1 次元世界であり、世界を治める 2 つの帝国はそれぞれ A 帝国、B 帝国と呼ばれています。

A 帝国の首都は座標 X、B 帝国の首都は座標 Y に位置しています。

ある日、A 帝国は座標 x_1, x_2, ..., x_N、B 帝国は座標 y_1, y_2, ..., y_M の都市を支配下に置きたくなりました。

このとき、以下の 3 つの条件をすべて満たす整数 Z が存在すれば、合意が成立して戦争は起きませんが、存在しない場合には戦争が起こります。

  • X < Z \leq Y
  • x_1, x_2, ..., x_N < Z
  • y_1, y_2, ..., y_M \geq Z

戦争が起こるかどうか判定してください。

制約

  • 入力はすべて整数である
  • 1 \leq N, M \leq 100
  • -100 \leq X < Y \leq 100
  • -100 \leq x_i, y_i \leq 100
  • x_1, x_2, ..., x_N \neq X
  • x_i はすべて異なる
  • y_1, y_2, ..., y_M \neq Y
  • y_i はすべて異なる

入力

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

N M X Y
x_1 x_2 ... x_N
y_1 y_2 ... y_M

出力

戦争が起こるなら War、そうでないなら No War を出力せよ。


入力例 1

3 2 10 20
8 15 13
16 22

出力例 1

No War

Z = 16 とすれば、次のように 3 つの条件をすべて満たすので合意が成立し、戦争は起きません。

  • X = 10 < 16 \leq 20 = Y
  • 8, 15, 13 < 16
  • 16, 22 \geq 16

入力例 2

4 2 -48 -1
-20 -35 -91 -23
-22 66

出力例 2

War

入力例 3

5 3 6 8
-10 3 1 5 -100
100 6 14

出力例 3

War

Score : 200 points

Problem Statement

Our world is one-dimensional, and ruled by two empires called Empire A and Empire B.

The capital of Empire A is located at coordinate X, and that of Empire B is located at coordinate Y.

One day, Empire A becomes inclined to put the cities at coordinates x_1, x_2, ..., x_N under its control, and Empire B becomes inclined to put the cities at coordinates y_1, y_2, ..., y_M under its control.

If there exists an integer Z that satisfies all of the following three conditions, they will come to an agreement, but otherwise war will break out.

  • X < Z \leq Y
  • x_1, x_2, ..., x_N < Z
  • y_1, y_2, ..., y_M \geq Z

Determine if war will break out.

Constraints

  • All values in input are integers.
  • 1 \leq N, M \leq 100
  • -100 \leq X < Y \leq 100
  • -100 \leq x_i, y_i \leq 100
  • x_1, x_2, ..., x_N \neq X
  • x_i are all different.
  • y_1, y_2, ..., y_M \neq Y
  • y_i are all different.

Input

Input is given from Standard Input in the following format:

N M X Y
x_1 x_2 ... x_N
y_1 y_2 ... y_M

Output

If war will break out, print War; otherwise, print No War.


Sample Input 1

3 2 10 20
8 15 13
16 22

Sample Output 1

No War

The choice Z = 16 satisfies all of the three conditions as follows, thus they will come to an agreement.

  • X = 10 < 16 \leq 20 = Y
  • 8, 15, 13 < 16
  • 16, 22 \geq 16

Sample Input 2

4 2 -48 -1
-20 -35 -91 -23
-22 66

Sample Output 2

War

Sample Input 3

5 3 6 8
-10 3 1 5 -100
100 6 14

Sample Output 3

War
C - String Transformation

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 300

問題文

英小文字のみからなる文字列 S, T が与えられます。

文字列 S に対して、次の操作を何度でも行うことができます。

操作: 2つの異なる英小文字 c_1, c_2 を選び、S に含まれる全ての c_1c_2 に、c_2c_1 に置き換える

0 回以上操作を行って、ST に一致させられるか判定してください。

制約

  • 1 \leq |S| \leq 2 \times 10^5
  • |S| = |T|
  • S, T は英小文字のみからなる

入力

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

S
T

出力

ST に一致させられる場合は Yes、そうでない場合は No を出力せよ。


入力例 1

azzel
apple

出力例 1

Yes

次のように操作を行えば、azzelapple にできます。

  • c_1 として e を、c_2 として l を選ぶと、azzelazzle になる
  • c_1 として z を、c_2 として p を選ぶと、azzleapple になる

入力例 2

chokudai
redcoder

出力例 2

No

どのように操作を行っても chokudairedcoder にできません。


入力例 3

abcdefghijklmnopqrstuvwxyz
ibyhqfrekavclxjstdwgpzmonu

出力例 3

Yes

Score : 300 points

Problem Statement

You are given strings S and T consisting of lowercase English letters.

You can perform the following operation on S any number of times:

Operation: Choose two distinct lowercase English letters c_1 and c_2, then replace every occurrence of c_1 with c_2, and every occurrence of c_2 with c_1.

Determine if S and T can be made equal by performing the operation zero or more times.

Constraints

  • 1 \leq |S| \leq 2 \times 10^5
  • |S| = |T|
  • S and T consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S
T

Output

If S and T can be made equal, print Yes; otherwise, print No.


Sample Input 1

azzel
apple

Sample Output 1

Yes

azzel can be changed to apple, as follows:

  • Choose e as c_1 and l as c_2. azzel becomes azzle.
  • Choose z as c_1 and p as c_2. azzle becomes apple.

Sample Input 2

chokudai
redcoder

Sample Output 2

No

No sequences of operation can change chokudai to redcoder.


Sample Input 3

abcdefghijklmnopqrstuvwxyz
ibyhqfrekavclxjstdwgpzmonu

Sample Output 3

Yes
D - Factorization

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 400

問題文

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

a_1 \times a_2 \times ... \times a_N = M となる正整数からなる長さ N の数列 a が何通りあるかを 10^9+7 で割った余りを求めてください。

ただし、数列 a'a'' が異なるとは、ある i が存在して a_i' \neq a_i'' であることをいいます。

制約

  • 入力はすべて整数である
  • 1 \leq N \leq 10^5
  • 1 \leq M \leq 10^9

入力

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

N M

出力

条件を満たす正整数からなる数列が何通りあるかを 10^9 + 7 で割った余りを出力せよ。


入力例 1

2 6

出力例 1

4

\{a_1, a_2\} = \{1, 6\}, \{2, 3\}, \{3, 2\}, \{6, 1\}4 通りの数列が条件を満たします。


入力例 2

3 12

出力例 2

18

入力例 3

100000 1000000000

出力例 3

957870001

Score : 400 points

Problem Statement

You are given positive integers N and M.

How many sequences a of length N consisting of positive integers satisfy a_1 \times a_2 \times ... \times a_N = M? Find the count modulo 10^9+7.

Here, two sequences a' and a'' are considered different when there exists some i such that a_i' \neq a_i''.

Constraints

  • All values in input are integers.
  • 1 \leq N \leq 10^5
  • 1 \leq M \leq 10^9

Input

Input is given from Standard Input in the following format:

N M

Output

Print the number of the sequences consisting of positive integers that satisfy the condition, modulo 10^9 + 7.


Sample Input 1

2 6

Sample Output 1

4

Four sequences satisfy the condition: \{a_1, a_2\} = \{1, 6\}, \{2, 3\}, \{3, 2\} and \{6, 1\}.


Sample Input 2

3 12

Sample Output 2

18

Sample Input 3

100000 1000000000

Sample Output 3

957870001