A - Meal Delivery

Time Limit: 2 sec / Memory Limit: 256 MB

配点 : 100

問題文

すぬけ君は,数直線上の位置 x に住んでいます. また,位置 a, b にはそれぞれ出前を行っている店 A, B が存在します.

すぬけ君は,店 A, B のうち,より近いほうから出前をとることにしました. どちらの店がすぬけ君の住んでいる位置により近いかを求めてください.

ただし,数直線上の 2s, t の間の距離は |s-t| で表されます.

制約

  • 1 \leq x \leq 1000
  • 1 \leq a \leq 1000
  • 1 \leq b \leq 1000
  • x, a, b は互いに異なる
  • すぬけ君の位置から店 A, B までの距離は異なる

入力

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

x a b

出力

A のほうが近いなら A を,店 B のほうが近いなら B を出力せよ.


入力例 1

5 2 7

出力例 1

B

すぬけ君の位置から店 A, B までの距離はそれぞれ 3, 2 です. 店 B のほうが近いため B を出力します.


入力例 2

1 999 1000

出力例 2

A

Score : 100 points

Problem Statement

Snuke lives at position x on a number line. On this line, there are two stores A and B, respectively at position a and b, that offer food for delivery.

Snuke decided to get food delivery from the closer of stores A and B. Find out which store is closer to Snuke's residence.

Here, the distance between two points s and t on a number line is represented by |s-t|.

Constraints

  • 1 \leq x \leq 1000
  • 1 \leq a \leq 1000
  • 1 \leq b \leq 1000
  • x, a and b are pairwise distinct.
  • The distances between Snuke's residence and stores A and B are different.

Input

Input is given from Standard Input in the following format:

x a b

Output

If store A is closer, print A; if store B is closer, print B.


Sample Input 1

5 2 7

Sample Output 1

B

The distances between Snuke's residence and stores A and B are 3 and 2, respectively. Since store B is closer, print B.


Sample Input 2

1 999 1000

Sample Output 2

A
B - Not Found

Time Limit: 2 sec / Memory Limit: 256 MB

配点 : 200

問題文

英小文字からなる文字列 S が与えられます. S に現れない英小文字であって,最も辞書順(アルファベット順)で小さいものを求めてください. ただし,S にすべての英小文字が現れる場合は,代わりに None を出力してください.

制約

  • 1 \leq |S| \leq 10^5 (|S| は文字列 S の長さ)
  • S は英小文字のみからなる.

入力

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

S

出力

S に現れない英小文字であって,最も辞書順で小さいものを出力せよ. ただし,S にすべての英小文字が現れる場合は,代わりに None を出力せよ.


入力例 1

atcoderregularcontest

出力例 1

b

atcoderregularcontest という文字列には a は現れますが b は現れません.


入力例 2

abcdefghijklmnopqrstuvwxyz

出力例 2

None

この文字列には,すべての英小文字が現れます.


入力例 3

fajsonlslfepbjtsaayxbymeskptcumtwrmkkinjxnnucagfrg

出力例 3

d

Score : 200 points

Problem Statement

You are given a string S consisting of lowercase English letters. Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print None instead.

Constraints

  • 1 \leq |S| \leq 10^5 (|S| is the length of string S.)
  • S consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S

Output

Print the lexicographically smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print None instead.


Sample Input 1

atcoderregularcontest

Sample Output 1

b

The string atcoderregularcontest contains a, but does not contain b.


Sample Input 2

abcdefghijklmnopqrstuvwxyz

Sample Output 2

None

This string contains every lowercase English letter.


Sample Input 3

fajsonlslfepbjtsaayxbymeskptcumtwrmkkinjxnnucagfrg

Sample Output 3

d
C - Make a Rectangle

Time Limit: 2 sec / Memory Limit: 256 MB

配点 : 300

問題文

太さが無視できる棒が N 本あります. i 番目の棒の長さは A_i です.

すぬけ君は,これらの棒から 4 本の異なる棒を選び,それらの棒を辺として長方形(正方形を含む)を作りたいです. 作ることができる最大の長方形の面積を求めてください.

制約

  • 4 \leq N \leq 10^5
  • 1 \leq A_i \leq 10^9
  • A_i は整数

入力

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

N
A_1 A_2 ... A_N

出力

すぬけ君が作ることのできる最大の長方形の面積を出力せよ. ただし,長方形を作れない場合は,0 を出力せよ.


入力例 1

6
3 1 2 4 2 1

出力例 1

2

1 \times 2 の長方形を作ることができます.


入力例 2

4
1 2 3 4

出力例 2

0

長方形を作ることはできません.


入力例 3

10
3 3 3 3 4 4 4 5 5 5

出力例 3

20

Score : 300 points

Problem Statement

We have N sticks with negligible thickness. The length of the i-th stick is A_i.

Snuke wants to select four different sticks from these sticks and form a rectangle (including a square), using the sticks as its sides. Find the maximum possible area of the rectangle.

Constraints

  • 4 \leq N \leq 10^5
  • 1 \leq A_i \leq 10^9
  • A_i is an integer.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the maximum possible area of the rectangle. If no rectangle can be formed, print 0.


Sample Input 1

6
3 1 2 4 2 1

Sample Output 1

2

1 \times 2 rectangle can be formed.


Sample Input 2

4
1 2 3 4

Sample Output 2

0

No rectangle can be formed.


Sample Input 3

10
3 3 3 3 4 4 4 5 5 5

Sample Output 3

20
D - Coloring Dominoes

Time Limit: 2 sec / Memory Limit: 256 MB

配点 : 400

問題文

2 \times N のマス目があります. すぬけ君は,このマス目に N 個のドミノを,重ならないように敷き詰めました. ここで,ドミノは,1 \times 2 または 2 \times 1 のマス目を覆うことができます.

すぬけ君は,赤色,水色,緑色の 3 色を使って,これらのドミノを塗ることにしました. このとき,辺で接しているドミノは異なる色で塗るようにします. ここで,必ずしも 3 色すべてを使う必要はありません.

このような塗り方が何通りあるかを mod 1000000007 で求めてください.

ただし,ドミノの敷き詰め方は,文字列 S_1, S_2 を用いて,次のようにして与えられます.

  • 各ドミノは,それぞれ異なる英小文字または英大文字で表される.
  • S_ij 文字目は,マス目の上から i 番目,左から j 番目のマスにどのドミノがあるかを表す.

制約

  • 1 \leq N \leq 52
  • |S_1| = |S_2| = N
  • S_1, S_2 は英小文字または英大文字からなる
  • S_1, S_2 は正しいドミノの敷き詰め方を表している

入力

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

N
S_1
S_2

出力

ドミノを塗る方法の数を mod 1000000007 で出力せよ.


入力例 1

3
aab
ccb

出力例 1

6

次の 6 通りあります.


入力例 2

1
Z
Z

出力例 2

3

必ずしもすべての色を使わなくてもよいことに注意してください.


入力例 3

52
RvvttdWIyyPPQFFZZssffEEkkaSSDKqcibbeYrhAljCCGGJppHHn
RLLwwdWIxxNNQUUXXVVMMooBBaggDKqcimmeYrhAljOOTTJuuzzn

出力例 3

958681902

Score : 400 points

Problem Statement

We have a board with a 2 \times N grid. Snuke covered the board with N dominoes without overlaps. Here, a domino can cover a 1 \times 2 or 2 \times 1 square.

Then, Snuke decided to paint these dominoes using three colors: red, cyan and green. Two dominoes that are adjacent by side should be painted by different colors. Here, it is not always necessary to use all three colors.

Find the number of such ways to paint the dominoes, modulo 1000000007.

The arrangement of the dominoes is given to you as two strings S_1 and S_2 in the following manner:

  • Each domino is represented by a different English letter (lowercase or uppercase).
  • The j-th character in S_i represents the domino that occupies the square at the i-th row from the top and j-th column from the left.

Constraints

  • 1 \leq N \leq 52
  • |S_1| = |S_2| = N
  • S_1 and S_2 consist of lowercase and uppercase English letters.
  • S_1 and S_2 represent a valid arrangement of dominoes.

Input

Input is given from Standard Input in the following format:

N
S_1
S_2

Output

Print the number of such ways to paint the dominoes, modulo 1000000007.


Sample Input 1

3
aab
ccb

Sample Output 1

6

There are six ways as shown below:


Sample Input 2

1
Z
Z

Sample Output 2

3

Note that it is not always necessary to use all the colors.


Sample Input 3

52
RvvttdWIyyPPQFFZZssffEEkkaSSDKqcibbeYrhAljCCGGJppHHn
RLLwwdWIxxNNQUUXXVVMMooBBaggDKqcimmeYrhAljOOTTJuuzzn

Sample Output 3

958681902