Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
下の画像で示す図において、a 番の点と b 番の点が線で直接結ばれているかを答えてください。
制約
- 1 \leq a \lt b \leq 10
- a, b は整数
入力
入力は以下の形式で標準入力から与えられる。
a b
出力
a 番の点と b 番の点が線で直接結ばれている場合は Yes
を出力し、結ばれていない場合は No
を出力せよ。
ジャッジは英大文字と英小文字を厳密に区別することに注意せよ。
入力例 1
4 5
出力例 1
Yes
問題文で示した図において、4 番の点と 5 番の点は線で直接結ばれています。
よって、Yes
を出力します。
入力例 2
3 5
出力例 2
No
問題文で示した図において、3 番の点と 5 番の点は線で直接結ばれていません。
よって、No
を出力します。
入力例 3
1 10
出力例 3
Yes
Score : 100 points
Problem Statement
In the figure shown in the image below, are the points numbered a and b directly connected by a line segment?
Constraints
- 1 \leq a \lt b \leq 10
- a and b are integers.
Input
Input is given from Standard Input in the following format:
a b
Output
If the points numbered a and b are directly connected by a line segment, print Yes
; otherwise, print No
.
The judge is case-sensitive: be sure to print uppercase and lowercase letters correctly.
Sample Input 1
4 5
Sample Output 1
Yes
In the figure shown in the Problem Statement, the points numbered 4 and 5 are directly connected by a line segment.
Thus, Yes
should be printed.
Sample Input 2
3 5
Sample Output 2
No
In the figure shown in the Problem Statement, the points numbered 3 and 5 are not directly connected by a line segment.
Thus, No
should be printed.
Sample Input 3
1 10
Sample Output 3
Yes
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
英小文字からなる長さ N の文字列 S が与えられます。S の末尾の文字を出力してください。
制約
- N は整数
- 1 ≤ N ≤ 1000
- S は英小文字からなる長さ N の文字列
入力
入力は以下の形式で標準入力から与えられる。
N S
出力
S の末尾の文字を出力せよ。
入力例 1
5 abcde
出力例 1
e
S = {}abcde
です。S の末尾の文字は e
なので、e
を出力します。
入力例 2
1 a
出力例 2
a
Score : 100 points
Problem Statement
Given a string S of length N consisting of lowercase English alphabets, print the last character of S.
Constraints
- N is an integer.
- 1 ≤ N ≤ 1000
- S is a string of length N consisting of lowercase English alphabets.
Input
Input is given from Standard Input in the following format:
N S
Output
Print the last character of S.
Sample Input 1
5 abcde
Sample Output 1
e
The last character of S = {}abcde
is e
, so e
should be printed.
Sample Input 2
1 a
Sample Output 2
a
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
長さ N の整数からなる数列 A=(A_1,\ldots,A_N) が与えられます。
A_1,\ldots,A_N に含まれない最小の非負整数を求めてください。
制約
- 1 \leq N \leq 2000
- 0 \leq A_i \leq 2000
- 入力は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
N A_1 \ldots A_N
出力
答えを出力せよ。
入力例 1
8 0 3 2 6 2 1 0 0
出力例 1
4
非負整数は 0,1,2,3,4,\ldots と続きます。
0,1,2,3 は A に含まれ、4 は A に含まれないので、答えは 4 です。
入力例 2
3 2000 2000 2000
出力例 2
0
Score : 200 points
Problem Statement
You are given a sequence of length N consisting of integers: A=(A_1,\ldots,A_N).
Find the smallest non-negative integer not in (A_1,\ldots,A_N).
Constraints
- 1 \leq N \leq 2000
- 0 \leq A_i \leq 2000
- 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
8 0 3 2 6 2 1 0 0
Sample Output 1
4
The non-negative integers are 0,1,2,3,4,\ldots.
We have 0,1,2,3 in A, but not 4, so the answer is 4.
Sample Input 2
3 2000 2000 2000
Sample Output 2
0
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
正の整数 X に対して、X を 2 進表記したときに 末尾 に連続する 0 の個数(の最大値)を \text{ctz}(X) で表します。
ただし、X を 2 進表記したとき末尾が 1 ならば \text{ctz}(X)=0 です。
正の整数 N が与えられるので、\text{ctz}(N) を出力してください。
制約
- 1\leq N\leq 10^9
- N は整数
入力
入力は以下の形式で標準入力から与えられる。
N
出力
\text{ctz}(N) を出力せよ。
入力例 1
2024
出力例 1
3
2024 を 2 進表記すると 11111101000
であり、末尾から 0
が 3 個連続しているため、\text{ctz}(2024)=3 です。
よって、3 を出力します。
入力例 2
18
出力例 2
1
18 を 2 進表記すると 10010
であるため、\text{ctz}(18)=1 です。
0
は末尾から連続する必要があることに注意してください。
入力例 3
5
出力例 3
0
Score: 200 points
Problem Statement
For a positive integer X, let \text{ctz}(X) be the (maximal) number of consecutive zeros at the end of the binary notation of X.
If the binary notation of X ends with a 1, then \text{ctz}(X)=0.
You are given a positive integer N. Print \text{ctz}(N).
Constraints
- 1\leq N\leq 10^9
- N is an integer.
Input
The input is given from Standard Input in the following format:
N
Output
Print \text{ctz}(N).
Sample Input 1
2024
Sample Output 1
3
2024 is 11111101000
in binary, with three consecutive 0
s from the end, so \text{ctz}(2024)=3.
Thus, print 3.
Sample Input 2
18
Sample Output 2
1
18 is 10010
in binary, so \text{ctz}(18)=1.
Note that we count the trailing zeros.
Sample Input 3
5
Sample Output 3
0
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
回転テーブルの周りに人 0、人 1、\ldots、人 N-1 がこの順番で反時計回りに等間隔で並んでいます。また、人 i の目の前には料理 p_i が置かれています。
あなたは次の操作を 0 回以上何度でも行うことが出来ます。
- 回転テーブルを反時計回りに 1 周の \frac{1}{N} だけ回す。これによって、(この操作の直前に)人 i の目の前にあった料理は人 (i+1) \bmod N の目の前に移動する。
操作を完了させた後において、人 i は料理 i が人 (i-1) \bmod N、人 i、人 (i+1) \bmod N のいずれかの目の前に置かれていると喜びます。
喜ぶ人数の最大値を求めてください。
a \bmod m とは
整数 a と正整数 m に対し、a \bmod m は a-x が m の倍数となるような 0 以上 m 未満の整数 x を表します。(このような x は一意に定まることが証明できます)制約
- 3 \leq N \leq 2 \times 10^5
- 0 \leq p_i \leq N-1
- i \neq j ならば p_i \neq p_j
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N p_0 \ldots p_{N-1}
出力
答えを出力せよ。
入力例 1
4 1 2 0 3
出力例 1
4
操作を 1 回行うと下の画像のようになります。
この時、4 人が喜ぶことを以下のように確かめられます。
- 人 0 は料理 0 が人 3\ (=(0-1) \bmod 4) の目の前に置かれているので喜びます。
- 人 1 は料理 1 が人 1\ (=1) の目の前に置かれているので喜びます。
- 人 2 は料理 2 が人 2\ (=2) の目の前に置かれているので喜びます。
- 人 3 は料理 3 が人 0\ (=(3+1) \bmod 4) の目の前に置かれているので喜びます。
5 人以上が喜ぶことは無いため、答えは 4 です。
入力例 2
3 0 1 2
出力例 2
3
入力例 3
10 3 9 6 1 7 2 8 0 5 4
出力例 3
5
Score : 300 points
Problem Statement
Person 0, Person 1, \ldots, and Person (N-1) are sitting around a turntable in their counterclockwise order, evenly spaced. Dish p_i is in front of Person i on the table.
You may perform the following operation 0 or more times:
- Rotate the turntable by one N-th of a counterclockwise turn. As a result, the dish that was in front of Person i right before the rotation is now in front of Person (i+1) \bmod N.
When you are finished, Person i is happy if Dish i is in front of Person (i-1) \bmod N, Person i, or Person (i+1) \bmod N.
Find the maximum possible number of happy people.
What is a \bmod m?
For an integer a and a positive integer m, a \bmod m denotes the integer x between 0 and (m-1) (inclusive) such that (a-x) is a multiple of m. (It can be proved that such x is unique.)Constraints
- 3 \leq N \leq 2 \times 10^5
- 0 \leq p_i \leq N-1
- p_i \neq p_j if i \neq j.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N p_0 \ldots p_{N-1}
Output
Print the answer.
Sample Input 1
4 1 2 0 3
Sample Output 1
4
The figure below shows the table after one operation.
Here, there are four happy people:
- Person 0 is happy because Dish 0 is in front of Person 3\ (=(0-1) \bmod 4);
- Person 1 is happy because Dish 1 is in front of Person 1\ (=1);
- Person 2 is happy because Dish 2 is in front of Person 2\ (=2);
- Person 3 is happy because Dish 3 is in front of Person 0\ (=(3+1) \bmod 4).
There cannot be five or more happy people, so the answer is 4.
Sample Input 2
3 0 1 2
Sample Output 2
3
Sample Input 3
10 3 9 6 1 7 2 8 0 5 4
Sample Output 3
5
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
冷蔵庫に N 種類の材料があります。これらを材料 1、\dots、材料 N と呼びます。材料 i は Q_i グラムあります。
あなたは 2 種類の料理を作れます。料理 A は、1 人分を作るのに各材料 i (1 \leq i \leq N) が A_i グラム必要です。料理 B は、1 人分を作るのに各材料 i が B_i グラム必要です。どちらも整数人分しか作れません。
冷蔵庫にある材料のみを使って、最大で合計何人分の料理を作れますか。
制約
- 1 \leq N \leq 10
- 1 \leq Q_i \leq 10^6
- 0 \leq A_i \leq 10^6
- A_i \geq 1 であるような i が存在する。
- 0 \leq B_i \leq 10^6
- B_i \geq 1 であるような i が存在する。
- 入力値はすべて整数である。
入力
入力は以下の形式で標準入力から与えられる。
N Q_1 Q_2 \dots Q_N A_1 A_2 \dots A_N B_1 B_2 \dots B_N
出力
最大で合計 S 人分の料理を作れるとして、整数 S を出力せよ。
入力例 1
2 800 300 100 100 200 10
出力例 1
5
この冷蔵庫には、800 グラムの材料 1 と 300 グラムの材料 2 があります。
100 グラムの材料 1 と 100 グラムの材料 2 で料理 A を 1 人分作れ、200 グラムの材料 1 と 10 グラムの材料 2 で料理 B を 1 人分作れます。
料理 A を 2 人分、料理 B を 3 人分作るのに必要な材料 1 の量は 100 \times 2 + 200 \times 3 = 800 グラム、材料 2 の量は 100 \times 2 + 10 \times 3 = 230 グラムで、いずれも冷蔵庫にある量を超えません。このようにして合計 5 人分の料理を作ることができますが、6 人分を作る方法はなく、答えは 5 です。
入力例 2
2 800 300 100 0 0 10
出力例 2
38
800 グラムの材料 1 で料理 A を 8 人分、300 グラムの材料 2 で料理 B を 30 人分、合計 38 人分作れます。
入力例 3
2 800 300 801 300 800 301
出力例 3
0
何も作れません。
入力例 4
10 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 0 1 2 3 4 5 6 7 8 9 9 8 7 6 5 4 3 2 1 0
出力例 4
222222
Score: 300 points
Problem Statement
Your refrigerator has N kinds of ingredients. Let us call them ingredient 1, \dots, ingredient N. You have Q_i grams of ingredient i.
You can make two types of dishes. To make one serving of dish A, you need A_i grams of each ingredient i (1 \leq i \leq N). To make one serving of dish B, you need B_i grams of each ingredient i. You can only make an integer number of servings of each type of dish.
Using only the ingredients in the refrigerator, what is the maximum total number of servings of dishes you can make?
Constraints
- 1 \leq N \leq 10
- 1 \leq Q_i \leq 10^6
- 0 \leq A_i \leq 10^6
- There is an i such that A_i \geq 1.
- 0 \leq B_i \leq 10^6
- There is an i such that B_i \geq 1.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N Q_1 Q_2 \dots Q_N A_1 A_2 \dots A_N B_1 B_2 \dots B_N
Output
Assuming that you can make a maximum total of S servings of dishes, print the integer S.
Sample Input 1
2 800 300 100 100 200 10
Sample Output 1
5
This refrigerator has 800 grams of ingredient 1 and 300 grams of ingredient 2.
You can make one serving of dish A with 100 grams of ingredient 1 and 100 grams of ingredient 2, and one serving of dish B with 200 grams of ingredient 1 and 10 grams of ingredient 2.
To make two servings of dish A and three servings of dish B, you need 100 \times 2 + 200 \times 3 = 800 grams of ingredient 1, and 100 \times 2 + 10 \times 3 = 230 grams of ingredient 2, neither of which exceeds the amount available in the refrigerator. In this way, you can make a total of five servings of dishes, but there is no way to make six, so the answer is 5.
Sample Input 2
2 800 300 100 0 0 10
Sample Output 2
38
You can make 8 servings of dish A with 800 grams of ingredient 1, and 30 servings of dish B with 300 grams of ingredient 2, for a total of 38 servings.
Sample Input 3
2 800 300 801 300 800 301
Sample Output 3
0
You cannot make any dishes.
Sample Input 4
10 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 0 1 2 3 4 5 6 7 8 9 9 8 7 6 5 4 3 2 1 0
Sample Output 4
222222
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
この問題は インタラクティブな問題(あなたが作成したプログラムとジャッジプログラムが標準入出力を介して対話を行う形式の問題)です。
ジャッジが 0 と 1 のみからなる長さ N の文字列 S = S_1S_2\ldots S_N を持っています。 文字列 S は、S_1 = 0 および S_N = 1 を満たします。
あなたには S の長さ N が与えられますが、S 自体は与えられません。 その代わり、あなたはジャッジに対して以下の質問を 20 回まで行うことができます。
- 1 \leq i \leq N を満たす整数 i を選び、S_i の値を尋ねる。
1 \leq p \leq N-1 かつ S_p \neq S_{p+1} を満たす整数 p を 1 個出力してください。
なお、本問題の条件下でそのような整数 p が必ず存在することが示せます。
制約
- 2 \leq N \leq 2 \times 10^5
入出力
最初に、文字列 S の長さ N を標準入力から受け取ってください。
N
次に、あなたはジャッジに対して問題文中の質問を 20 回まで繰り返すことができます。
質問は、以下の形式で標準出力に出力してください。 ここで、i は 1 \leq i \leq N を満たす整数でなければなりません。
? i
これに対する応答として、S_i の値が次の形式で標準入力から与えられます。
S_i
ここで、S_i は 0 または 1 です。
問題文中の条件を満たす整数 p を見つけたら、解答を以下の形式で出力してください。 その後、ただちにプログラムを終了してください。
! p
答えが複数ある場合、どれを出力しても正解とみなされます。
注意点
- 出力を行うたびに、末尾に改行を入れて標準出力を flush してください。そうしなかった場合、ジャッジ結果が TLE となる可能性があります。
- 対話の途中で不正な出力を行った、あるいはプログラムが途中で終了した場合のジャッジ結果は不定です。
- 解答を出力したらただちにプログラムを終了してください。そうしない場合、ジャッジ結果は不定です。
- 文字列 S はあなたとジャッジの対話の開始時に固定され、あなたが行った質問などに応じて変更されることはありません。
入出力例
以下は、N = 7, S = 0010011 の場合の入出力例です。
入力 | 出力 | 説明 |
---|---|---|
7 |
N が与えられます。 | |
? 1 |
S_1 が何かをジャッジに質問します。 | |
0 |
質問に対する答えとして S_1 = 0 がジャッジから返されます。 | |
? 6 |
S_6 が何かをジャッジに質問します。 | |
1 |
質問に対する答えとして S_6 = 1 がジャッジから返されます。 | |
? 5 |
S_5 が何かをジャッジに質問します。 | |
0 |
質問に対する答えとして S_5 = 0 がジャッジから返されます。 | |
! 5 |
問題文中の条件を満たす整数 p として、p = 5 を解答します。 | |
解答した p = 5 について、1 \leq p \leq N-1 かつ S_p \neq S_{p+1} が成り立ちます。 よって、この後ただちにプログラムを終了することで、正解と判定されます。
Score : 400 points
Problem Statement
This is an interactive task, where your program and the judge interact via Standard Input and Output.
The judge has a string of length N consisting of 0 and 1: S = S_1S_2\ldots S_N. Here, S_1 = 0 and S_N = 1.
You are given the length N of S, but not the contents of S. Instead, you can ask the judge at most 20 questions as follows.
- Choose an integer i such that 1 \leq i \leq N and ask the value of S_i.
Print an integer p such that 1 \leq p \leq N-1 and S_p \neq S_{p+1}.
It can be shown that such p always exists under the settings of this problem.
Constraints
- 2 \leq N \leq 2 \times 10^5
Input and Output
First, receive the length N of the string S from Standard Input:
N
Then, you get to ask the judge at most 20 questions as described in the problem statement.
Print each question to Standard Output in the following format, where i is an integer satisfying 1 \leq i \leq N:
? i
In response to this, the value of S_i will be given from Standard Input in the following format:
S_i
Here, S_i is 0 or 1.
When you find an integer p satisfying the condition in the problem statement, print it in the following format, and immediately quit the program:
! p
If multiple solutions exist, you may print any of them.
Notes
- Print a newline and flush Standard Output at the end of each message. Otherwise, you may get a TLE verdict.
- If there is malformed output during the interaction or your program quits prematurely, the verdict will be indeterminate.
- After printing the answer, immediately quit the program. Otherwise, the verdict will be indeterminate.
- The string S will be fixed at the start of the interaction and will not be changed according to your questions or other factors.
Sample Input and Output
In the following interaction, N = 7 and S = 0010011.
Input | Output | Description |
---|---|---|
7 |
N is given. | |
? 1 |
Ask the value of S_1. | |
0 |
The judge responds with S_1 = 0. | |
? 6 |
Ask the value of S_6. | |
1 |
The judge responds with S_6 = 1. | |
? 5 |
Ask the value of S_5. | |
0 |
The judge responds with S_5 = 0. | |
! 5 |
Present p = 5 as an integer satisfying the condition. | |
For the presented p = 5, we have 1 \leq p \leq N-1 and S_p \neq S_{p+1}. Thus, if the program immediately quits here, this case will be judged as correctly solved.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
N 頂点の木と、長さ M の数列 A=(A_1,\ldots,A_M)、整数 K が与えられます。
木の頂点には 1 から N の番号がつけられており、i 番目の辺は頂点 U_i と V_i を結んでいます。
この木の N-1 個の辺をそれぞれ赤か青のどちらかに塗ります。そのような方法は 2^{N-1} 通りありますが、そのうち次の条件を満たすような塗り方の個数を 998244353 で割った余りを求めてください。
条件:
最初、駒を頂点 A_1 におく。i=1,\ldots,M-1 の順に、駒を頂点 A_i から頂点 A_{i+1} まで、辺をたどって最短経路で動かす。
これらの操作を最後まで行ったとき、赤く塗られた辺を通過した回数を R、青く塗られた辺を通過した回数を B とすると、R-B=K である。
制約
- 2 \leq N \leq 1000
- 2 \leq M \leq 100
- |K| \leq 10^5
- 1 \leq A_i \leq N
- 1\leq U_i,V_i\leq N
- 与えられるグラフは木である
- 入力に含まれる値は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
N M K A_1 A_2 \ldots A_M U_1 V_1 \vdots U_{N-1} V_{N-1}
出力
答えを出力せよ。
入力例 1
4 5 0 2 3 2 1 4 1 2 2 3 3 4
出力例 1
2
1,3 番目の辺を赤く、2 番目の辺を青く塗ったとき、
- 頂点 2 から頂点 3 への移動で赤い辺を 0 回、青い辺を 1 回
- 頂点 3 から頂点 2 への移動で赤い辺を 0 回、青い辺を 1 回
- 頂点 2 から頂点 1 への移動で赤い辺を 1 回、青い辺を 0 回
- 頂点 1 から頂点 4 への移動で赤い辺を 2 回、青い辺を 1 回
それぞれ通過し、全体では赤い辺を 3 回、青い辺を 3 回通るため、条件を満たします。
この他、1,3 番目の辺を青く、2 番目の辺を赤く塗るときも条件を満たし、これら以外の塗り方は条件を満たさないため、答えは 2 通りです。
入力例 2
3 10 10000 1 2 1 2 1 2 2 1 1 2 1 2 1 3
出力例 2
0
条件を満たす塗り方が存在しないこともあります。
入力例 3
10 2 -1 1 10 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10
出力例 3
126
入力例 4
5 8 -1 1 4 1 4 2 1 3 5 1 2 4 1 3 1 1 5
出力例 4
2
Score : 500 points
Problem Statement
Given are a tree with N vertices, a sequence of M numbers A=(A_1,\ldots,A_M), and an integer K.
The vertices are numbered 1 through N, and the i-th edge connects Vertices U_i and V_i.
We will paint each of the N-1 edges of this tree red or blue. Among the 2^{N-1} such ways, find the number of ones that satisfies the following condition, modulo 998244353.
Condition:
Let us put a piece on Vertex A_1, and for each i=1,\ldots,M-1 in this order, move it from Vertex A_i to Vertex A_{i+1} along the edges in the shortest path. After all of these movements, R-B=K holds, where R and B are the numbers of times the piece traverses a red edge and a blue edge, respectively.
Constraints
- 2 \leq N \leq 1000
- 2 \leq M \leq 100
- |K| \leq 10^5
- 1 \leq A_i \leq N
- 1\leq U_i,V_i\leq N
- The given graph is a tree.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M K A_1 A_2 \ldots A_M U_1 V_1 \vdots U_{N-1} V_{N-1}
Output
Print the answer.
Sample Input 1
4 5 0 2 3 2 1 4 1 2 2 3 3 4
Sample Output 1
2
If we paint the 1-st and 3-rd edges red and the 2-nd edge blue, the piece will traverse the following numbers of red and blue edges:
- 0 red edges and 1 blue edge when moving from Vertex 2 to 3,
- 0 red edges and 1 blue edge when moving from Vertex 3 to 2,
- 1 red edge and 0 blue edges when moving from Vertex 2 to 1,
- 2 red edges and 1 blue edge when moving from Vertex 1 to 4,
for a total of 3 red edges and 3 blue edges, satisfying the condition.
Another way to satisfy the condition is to paint the 1-st and 3-rd edges blue and the 2-nd edge red. There is no other way to satisfy it, so the answer is 2.
Sample Input 2
3 10 10000 1 2 1 2 1 2 2 1 1 2 1 2 1 3
Sample Output 2
0
There may be no way to paint the tree to satisfy the condition.
Sample Input 3
10 2 -1 1 10 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10
Sample Output 3
126
Sample Input 4
5 8 -1 1 4 1 4 2 1 3 5 1 2 4 1 3 1 1 5
Sample Output 4
2
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
N 個の文字列 S _ 1,S _ 2,\ldots,S _ N が与えられます。 S _ i\ (1\leq i\leq N) は英小文字からなる長さ 10 以下の空でない文字列で、互いに異なります。
先手太郎君と後手次郎君がしりとりをします。 このしりとりでは、先手太郎君と後手次郎君の手番が交互に訪れます。 はじめの手番は先手太郎君の手番です。 それぞれのプレイヤーは自分の手番において整数 i\ (1\leq i\leq N) を 1 つ選びます。 このとき、i は次の 2 つの条件を満たしていなければなりません。
- i は、しりとりが開始してからこれまでの 2 人の手番で選ばれたどの整数とも異なる
- この手番がしりとりの最初の手番であるか、直前に選ばれた整数を j として、S _ j の最後の文字と S _ i の最初の文字が等しい
条件を満たす i を選べなくなったプレイヤーの負けで、負けなかったプレイヤーの勝ちです。
2 人が最適に行動したときに勝つのはどちらかを判定してください。
制約
- 1 \leq N \leq 16
- N は整数
- S _ i\ (1\leq i\leq N) は英小文字からなる長さ 10 以下の空でない文字列
- S _ i\neq S _ j\ (1\leq i\lt j\leq N)
入力
入力は以下の形式で標準入力から与えられる。
N S_1 S_2 \vdots S_N
出力
2 人が最適に行動したとき、先手太郎君が勝つなら First
、後手次郎君が勝つなら Second
と出力せよ。
入力例 1
6 enum float if modint takahashi template
出力例 1
First
例えば、ゲームは以下のように進行します。 この進行例では 2 人の行動が必ずしも最適とは限らないことに注意してください。
- 先手太郎君が i=3 を選ぶ。S _ i=
if
である。 - 後手次郎君が i=2 を選ぶ。S _ i=
float
であり、if
の最後の文字とfloat
の最初の文字は等しい。 - 先手太郎君が i=5 を選ぶ。S _ i=
takahashi
であり、float
の最後の文字とtakahashi
の最初の文字は等しい。 - 後手次郎君は i\neq2,3,5 であって S _ i の最初の文字が
i
と等しいものを選べないため、負ける。
このとき、先手太郎君が勝ちます。
入力例 2
10 catch chokudai class continue copy exec havoc intrinsic static yucatec
出力例 2
Second
入力例 3
16 mnofcmzsdx lgeowlxuqm ouimgdjxlo jhwttcycwl jbcuioqbsj mdjfikdwix jhvdpuxfil peekycgxco sbvxszools xuuqebcrzp jsciwvdqzl obblxzjhco ptobhnpfpo muizaqtpgx jtgjnbtzcl sivwidaszs
出力例 3
First
Score : 500 points
Problem Statement
You are given N strings S _ 1,S _ 2,\ldots,S _ N. S _ i\ (1\leq i\leq N) is a non-empty string of length at most 10 consisting of lowercase English letters, and the strings are pairwise distinct.
Taro the First and Jiro the Second play a word-chain game. In this game, the two players take alternating turns, with Taro the First going first. In each player's turn, the player chooses an integer i\ (1\leq i\leq N), which should satisfy the following two conditions:
- i is different from any integer chosen by the two players so far since the game started;
- the current turn is the first turn of the game, or the last character of S_j equals the first character of S_i, where j is the last integer chosen.
The player who is unable to choose a conforming i loses; the other player wins.
Determine which player will win if the two players play optimally.
Constraints
- 1 \leq N \leq 16
- N is an integer.
- S _ i\ (1\leq i\leq N) is a non-empty string of length at most 10 consisting of lowercase English letters.
- S _ i\neq S _ j\ (1\leq i\lt j\leq N)
Input
The input is given from Standard Input in the following format:
N S_1 S_2 \vdots S_N
Output
Print First
if Taro the First wins when the two players play optimally; print Second
if Jiro the Second wins.
Sample Input 1
6 enum float if modint takahashi template
Sample Output 1
First
For example, the game progresses as follows. Note that the two players may not be playing optimally in this example.
- Taro the First chooses i=3. S _ i=
if
. - Jiro the Second chooses i=2. S _ i=
float
, and the last character ofif
equals the first character offloat
. - Taro the First chooses i=5. S _ i=
takahashi
, and the last character offloat
equals the first character oftakahashi
. - Jiro the Second is unable to choose i\neq2,3,5 such that S _ i starts with
i
, so he loses.
In this case, Taro the First wins.
Sample Input 2
10 catch chokudai class continue copy exec havoc intrinsic static yucatec
Sample Output 2
Second
Sample Input 3
16 mnofcmzsdx lgeowlxuqm ouimgdjxlo jhwttcycwl jbcuioqbsj mdjfikdwix jhvdpuxfil peekycgxco sbvxszools xuuqebcrzp jsciwvdqzl obblxzjhco ptobhnpfpo muizaqtpgx jtgjnbtzcl sivwidaszs
Sample Output 3
First