A - Takahashi san 2

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100

問題文

キーエンスでは、役割や年齢、立場の違いに関係なく「さん」付けして呼ぶという文化があります。

英小文字のみからなる文字列 S が与えられます。
Ssan で終わっているならば Yes を、終わっていないならば No を出力してください。

制約

  • S は英小文字のみからなる長さ 4 以上 30 以下の文字列

入力

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

S

出力

Ssan で終わっているならば Yes を、終わっていないならば No を出力せよ。


入力例 1

takahashisan

出力例 1

Yes

文字列 S=takahashisansan で終わっているため、 Yes を出力します。


入力例 2

aokikun

出力例 2

No

文字列 S=aokikunsan で終わっていないため、 No を出力します。

Score : 100 points

Problem Statement

KEYENCE has a culture of addressing everyone with the suffix "-san," regardless of roles, age, or positions.

You are given a string S consisting of lowercase English letters.
If S ends with san, print Yes; otherwise, print No.

Constraints

  • S is a string of length between 4 and 30, inclusive, consisting of lowercase English letters.

Input

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

S

Output

If S ends with san, print Yes; otherwise, print No.


Sample Input 1

takahashisan

Sample Output 1

Yes

The string S= takahashisan ends with san, so print Yes.


Sample Input 2

aokikun

Sample Output 2

No

The string S= aokikun does not end with san, so print No.

B - Unvarnished Report

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

キーエンスでは良いことも悪いこともありのままに報告するという文化があります。
そこで、報告内容が元の文章のありのままであるかを確認したいです。

英小文字のみからなる文字列 S, T が与えられます。
ST が等しいならば 0 を、そうでないならば異なっている文字のうち先頭のものが何文字目かを出力してください。
ただし、S,T の一方にのみ i 文字目が存在するときも、i 文字目は異なっているとみなすものとします。

より厳密には、ST が等しくないならば次の条件のうちいずれかをみたす最小の整数 i を出力してください。

  • 1\leq i\leq |S| かつ 1\leq i\leq |T| かつ S_i\neq T_i
  • |S|< i\leq |T|
  • |T|< i\leq |S|

ただし、|S|,|T| でそれぞれ S,T の長さを、S_i,T_i でそれぞれ S,Ti 文字目を表します。

制約

  • S,T は英小文字のみからなる長さ 1 以上 100 以下の文字列

入力

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

S
T

出力

ST が等しいならば 0 を、そうでないならば異なっている文字のうち先頭のものが何文字目かを出力せよ。


入力例 1

abcde
abedc

出力例 1

3

S=abcde, T=abedc です。
ST1,2 文字目は等しく、3 文字目が異なるため、 3 を出力します。


入力例 2

abcde
abcdefg

出力例 2

6

S=abcde, T=abcdefg です。
ST5 文字目まで等しく、T にのみ 6 文字目が存在するため、6 を出力します。


入力例 3

keyence
keyence

出力例 3

0

ST は等しいため、 0 を出力します。

Score : 200 points

Problem Statement

KEYENCE has a culture of reporting things as they are, whether good or bad.
So we want to check whether the reported content is exactly the same as the original text.

You are given two strings S and T, consisting of lowercase English letters.
If S and T are equal, print 0; otherwise, print the position of the first character where they differ.
Here, if the i-th character exists in only one of S and T, consider that the i-th characters are different.

More precisely, if S and T are not equal, print the smallest integer i satisfying one of the following conditions:

  • 1\leq i\leq |S|, 1\leq i\leq |T|, and S_i\neq T_i.
  • |S| < i \leq |T|.
  • |T| < i \leq |S|.

Here, |S| and |T| denote the lengths of S and T, respectively, and S_i and T_i denote the i-th characters of S and T, respectively.

Constraints

  • S and T are strings of length between 1 and 100, inclusive, consisting of lowercase English letters.

Input

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

S
T

Output

If S and T are equal, print 0; otherwise, print the position of the first character where they differ.


Sample Input 1

abcde
abedc

Sample Output 1

3

We have S= abcde and T= abedc.
S and T have the same first and second characters, but differ at the third character, so print 3.


Sample Input 2

abcde
abcdefg

Sample Output 2

6

We have S= abcde and T= abcdefg.
S and T are equal up to the fifth character, but only T has a sixth character, so print 6.


Sample Input 3

keyence
keyence

Sample Output 3

0

S and T are equal, so print 0.

C - Separated Lunch

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

キーエンス本社に勤務する人数が増えてきたので、本社に存在する部署を 2 つのグループに分け、昼休みの時間帯を分けることにしました。

キーエンス本社には N 個の部署が存在し、i 番目 (1\leq i\leq N) の部署に所属する人数は K_i 人です。

それぞれの部署をグループ A, B のいずれか一方に割り当て、グループごとに同時に昼休みをとり、 かつグループ A, B の昼休みの時間が重ならないようにしたとき、同時に昼休みをとる最大人数としてあり得る最小の値を求めてください。
すなわち、グループ A に割り当てられた部署に所属する人数の合計とグループ B に割り当てられた部署に所属する人数の合計 のうち大きい方の値としてあり得る最小の値を求めてください。

制約

  • 2\leq N \leq 20
  • 1\leq K_i \leq 10^8
  • 入力はすべて整数

入力

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

N
K_1 K_2 \ldots K_N

出力

同時に昼休みを取る最大人数としてあり得る最小の値を出力せよ。


入力例 1

5
2 3 5 10 12

出力例 1

17

1,2,5 番目の部署をグループ A に、3,4 番目の部署をグループ B に割り当てたとき、 グループ A に割り当てられた部署に所属する人数の合計は 2+3+12=17 、 グループ B に割り当てられた部署に所属する人数の合計は 5+10=15 となり、 このとき同時に昼休みを取る最大人数は 17 となります。

一方で、グループ A,B それぞれに割り当てられた部署に所属する人数の合計がいずれも 16 以下になるように 部署を割り当てることはできないため、17 を出力します。


入力例 2

2
1 1

出力例 2

1

同一人数の部署が複数存在する可能性もあります。


入力例 3

6
22 25 26 45 22 31

出力例 3

89

例えば、1,4,5 番目の部署をグループ A に、2,3,6 番目の部署をグループ B に割り当てたとき同時に昼休みを取る最大人数は 89 となります。

Score : 300 points

Problem Statement

As KEYENCE headquarters have more and more workers, they decided to divide the departments in the headquarters into two groups and stagger their lunch breaks.

KEYENCE headquarters have N departments, and the number of people in the i-th department (1\leq i\leq N) is K_i.

When assigning each department to Group A or Group B, having each group take lunch breaks at the same time, and ensuring that the lunch break times of Group A and Group B do not overlap, find the minimum possible value of the maximum number of people taking a lunch break at the same time.
In other words, find the minimum possible value of the larger of the following: the total number of people in departments assigned to Group A, and the total number of people in departments assigned to Group B.

Constraints

  • 2 \leq N \leq 20
  • 1 \leq K_i \leq 10^8
  • All input values are integers.

Input

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

N
K_1 K_2 \ldots K_N

Output

Print the minimum possible value of the maximum number of people taking a lunch break at the same time.


Sample Input 1

5
2 3 5 10 12

Sample Output 1

17

When assigning departments 1, 2, and 5 to Group A, and departments 3 and 4 to Group B, Group A has a total of 2+3+12=17 people, and Group B has a total of 5+10=15 people. Thus, the maximum number of people taking a lunch break at the same time is 17.

It is impossible to assign the departments so that both groups have 16 or fewer people, so print 17.


Sample Input 2

2
1 1

Sample Output 2

1

Multiple departments may have the same number of people.


Sample Input 3

6
22 25 26 45 22 31

Sample Output 3

89

For example, when assigning departments 1, 4, and 5 to Group A, and departments 2, 3, and 6 to Group B, the maximum number of people taking a lunch break at the same time is 89.

D - Laser Marking

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 350

問題文

xy 平面に対し、レーザを照射しながら線分を印字する印字機があります。

  • 印字開始時、レーザ照射位置は座標 (0, 0) にある。
  • 線分を印字する際は、以下の流れに従う。

    • まず、レーザ照射位置を線分の端点のうちどちらか 1 つに移動させる。
      • どちらの端点から描画を始めてもよい。
    • その後、レーザ照射位置のある端点からもう一方の端点まで、レーザを照射しながらレーザ照射位置を一直線に移動させる。
      • 線分の途中で印字を中止することは許されない。
  • レーザを照射していない時、レーザ照射位置は 1 秒あたり速度 S で任意の方向に移動できる。

  • レーザを照射している時、レーザ照射位置は 1 秒あたり速度 T で印字中の線分に沿って移動できる。
  • レーザ照射位置の移動にかかる時間以外の所要時間は無視できる。

高橋君はこの印字機で N 本の線分を印字したいです。
そのうち i 本目の線分は、座標 (A_i, B_i) と座標 (C_i, D_i) を結びます。
なお、複数の線分が重なっていることがありますが、全ての線分についてその都度重なっている部分を印字する必要があります。

うまく印字機を操作したとき、全ての線分を印字完了するまでにかかる最小の時間は何秒ですか?

制約

  • 入力は全て整数
  • 1 \le N \le 6
  • 1 \le T \le S \le 1000
  • -1000 \le A_i,B_i,C_i,D_i \le 1000
  • (A_i,B_i) \neq (C_i,D_i) ( 1 \le i \le N )

入力

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

N S T
A_1 B_1 C_1 D_1
\vdots
A_N B_N C_N D_N

出力

答えを出力せよ。
なお、真の値との絶対誤差または相対誤差が 10^{-6} 以下であれば正解として扱われる。


入力例 1

3 2 1
1 3 2 1
0 2 0 0
3 0 2 0

出力例 1

6.44317475868633722080
  • レーザを照射しながらレーザ照射位置を (0,0) から (0,2) まで移動させ、 2 本目の線分を描画する。
    • この描画に要する時間は 2 秒である。
  • レーザを照射せずレーザ照射位置を (0,2) から (1,3) まで移動させる。
    • この移動に要する時間は \sqrt{2}/2 秒である。
  • レーザを照射しながらレーザ照射位置を (1,3) から (2,1) まで移動させ、 1 本目の線分を描画する。
    • この描画に要する時間は \sqrt{5} 秒である。
  • レーザを照射せずレーザ照射位置を (2,1) から (2,0) まで移動させる。
    • この移動に要する時間は 1/2 秒である。
  • レーザを照射しながらレーザ照射位置を (2,0) から (3,0) まで移動させ、 3 本目の線分を描画する。

    • この描画に要する時間は 1 秒である。
  • 全体の所要時間は 2 + (\sqrt{2}/2) + \sqrt{5} + (1/2) + 1\approx 6.443175 秒です。


入力例 2

2 1 1
0 0 10 10
0 2 2 0

出力例 2

20.97056274847714058517

入力例 3

6 3 2
-1000 -1000 1000 1000
1000 -1000 -1000 1000
-1000 -1000 1000 1000
1000 -1000 -1000 1000
1000 1000 -1000 -1000
-1000 1000 1000 -1000

出力例 3

9623.35256169626864153344

複数の線分が重なっていますが、全ての線分についてその都度重なっている部分を印字する必要があります。


入力例 4

6 10 8
1000 1000 -1000 -1000
1000 -1000 -1000 -1000
-1000 1000 1000 1000
-1000 1000 -1000 -1000
1000 1000 1000 -1000
1000 -1000 -1000 1000

出力例 4

2048.52813742385702910909

Score : 350 points

Problem Statement

There is a printing machine that prints line segments on the xy-plane by emitting a laser.

  • At the start of printing, the laser position is at coordinate (0, 0).
  • When printing a line segment, the procedure below is followed.

    • First, move the laser position to one of the endpoints of the line segment.
      • One may start drawing from either endpoint.
    • Then, move the laser position in a straight line from the current endpoint to the other endpoint while emitting the laser.
      • It is not allowed to stop printing in the middle of a line segment.
  • When not emitting the laser, the laser position can move in any direction at a speed of S units per second.

  • When emitting the laser, the laser position can move along the line segment being printed at a speed of T units per second.
  • The time required for operations other than moving the laser position can be ignored.

Takahashi wants to print N line segments using this printing machine.
The i-th line segment connects coordinates (A_i, B_i) and (C_i, D_i).
Some line segments may overlap, in which case he needs to print the overlapping parts for each line segment separately.

What is the minimum number of seconds required to complete printing all the line segments when he operates the printing machine optimally?

Constraints

  • All input values are integers.
  • 1 \le N \le 6
  • 1 \le T \le S \le 1000
  • -1000 \le A_i,B_i,C_i,D_i \le 1000
  • (A_i,B_i) \neq (C_i,D_i) ( 1 \le i \le N )

Input

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

N S T
A_1 B_1 C_1 D_1
\vdots
A_N B_N C_N D_N

Output

Print the answer.

Your output will be considered correct if the absolute or relative error from the true value does not exceed 10^{-6}.


Sample Input 1

3 2 1
1 3 2 1
0 2 0 0
3 0 2 0

Sample Output 1

6.44317475868633722080
  • Emit the laser while moving the laser position from (0,0) to (0,2), printing the second line segment.
    • This takes 2 seconds.
  • Move the laser position from (0,2) to (1,3) without emitting the laser.
    • This takes \sqrt{2}/2 seconds.
  • Emit the laser while moving the laser position from (1,3) to (2,1), printing the first line segment.
    • This takes \sqrt{5} seconds.
  • Move the laser position from (2,1) to (2,0) without emitting the laser.
    • This takes 1/2 second.
  • Emit the laser while moving the laser position from (2,0) to (3,0), printing the third line segment.
    • This takes 1 second.
  • The total time taken is 2 + (\sqrt{2}/2) + \sqrt{5} + (1/2) + 1 \approx 6.443175 seconds.

Sample Input 2

2 1 1
0 0 10 10
0 2 2 0

Sample Output 2

20.97056274847714058517

Sample Input 3

6 3 2
-1000 -1000 1000 1000
1000 -1000 -1000 1000
-1000 -1000 1000 1000
1000 -1000 -1000 1000
1000 1000 -1000 -1000
-1000 1000 1000 -1000

Sample Output 3

9623.35256169626864153344

Multiple line segments overlap here, and you need to print the overlapping parts for each line segment separately.


Sample Input 4

6 10 8
1000 1000 -1000 -1000
1000 -1000 -1000 -1000
-1000 1000 1000 1000
-1000 1000 -1000 -1000
1000 1000 1000 -1000
1000 -1000 -1000 1000

Sample Output 4

2048.52813742385702910909
E - Sensor Optimization Dilemma 2

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 475

問題文

ある製品の製造には 1,2,\dots,N の番号が付いた N 個の工程が必要です。

各工程 i について、それを処理する 2 種類の機械 S_i,T_i が売られています。

  • 機械 S_i : 1 台につき 1 日あたり製品 A_i 個分の処理ができ、 1P_i 円で導入できる
  • 機械 T_i : 1 台につき 1 日あたり製品 B_i 個分の処理ができ、 1Q_i 円で導入できる

それぞれの機械は 0 台以上何台でも導入できます。

機械の導入の結果、工程 i1 日あたり製品 W_i 個分処理できるようになったとします。
このとき、製造能力を W の最小値、すなわち \displaystyle \min^{N}_{i=1} W_i と定義します。

全体の予算が X 円のとき、達成可能な製造能力の最大値を求めてください。

制約

  • 入力は全て整数
  • 1 \le N \le 100
  • 1 \le A_i,B_i \le 100
  • 1 \le P_i,Q_i,X \le 10^7

入力

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

N X
A_1 P_1 B_1 Q_1
A_2 P_2 B_2 Q_2
\vdots
A_N P_N B_N Q_N

出力

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


入力例 1

3 22
2 5 3 6
1 1 3 3
1 3 2 4

出力例 1

4

例えば、次の通り機械を導入することで製造能力を 4 にすることができ、これが達成可能な最大値です。

  • 工程 1 に対し機械 S_12 台導入する。
    • 1 日あたり製品 4 個分の処理に相当し、導入に合計 10 円かかる。
  • 工程 2 に対し機械 S_21 台導入する。
    • 1 日あたり製品 1 個分の処理に相当し、導入に合計 1 円かかる。
  • 工程 2 に対し機械 T_21 台導入する。
    • 1 日あたり製品 3 個分の処理に相当し、導入に合計 3 円かかる。
  • 工程 3 に対し機械 T_32 台導入する。
    • 1 日あたり製品 4 個分の処理に相当し、導入に合計 8 円かかる。

入力例 2

1 10000000
100 1 100 1

出力例 2

1000000000

入力例 3

1 1
1 10000000 1 10000000

出力例 3

0

正の製造能力が得られない場合もあります。


入力例 4

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

出力例 4

894742

Score : 475 points

Problem Statement

The manufacturing of a certain product requires N processes numbered 1,2,\dots,N.

For each process i, there are two types of machines S_i and T_i available for purchase to handle it.

  • Machine S_i: Can process A_i products per day per unit, and costs P_i yen per unit.
  • Machine T_i: Can process B_i products per day per unit, and costs Q_i yen per unit.

You can purchase any number of each machine, possibly zero.

Suppose that process i can handle W_i products per day as a result of introducing machines.
Here, we define the production capacity as the minimum of W, that is, \displaystyle \min^{N}_{i=1} W_i.

Given a total budget of X yen, find the maximum achievable production capacity.

Constraints

  • All input values are integers.
  • 1 \le N \le 100
  • 1 \le A_i,B_i \le 100
  • 1 \le P_i,Q_i,X \le 10^7

Input

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

N X
A_1 P_1 B_1 Q_1
A_2 P_2 B_2 Q_2
\vdots
A_N P_N B_N Q_N

Output

Print the answer as an integer.


Sample Input 1

3 22
2 5 3 6
1 1 3 3
1 3 2 4

Sample Output 1

4

For example, by introducing machines as follows, we can achieve a production capacity of 4, which is the maximum possible.

  • For process 1, introduce 2 units of machine S_1.
    • This allows processing 4 products per day and costs a total of 10 yen.
  • For process 2, introduce 1 unit of machine S_2.
    • This allows processing 1 product per day and costs a total of 1 yen.
  • For process 2, introduce 1 unit of machine T_2.
    • This allows processing 3 products per day and costs a total of 3 yen.
  • For process 3, introduce 2 units of machine T_3.
    • This allows processing 4 products per day and costs a total of 8 yen.

Sample Input 2

1 10000000
100 1 100 1

Sample Output 2

1000000000

Sample Input 3

1 1
1 10000000 1 10000000

Sample Output 3

0

There may be cases where a positive production capacity cannot be achieved.


Sample Input 4

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

Sample Output 4

894742
F - Shipping

Time Limit: 5 sec / Memory Limit: 1024 MiB

配点 : 550

問題文

キーエンスは即納で有名です。

この問題において、暦は 1 日、 2 日、 3 日、 \dots と続いています。

注文 1,2,\dots,N があり、注文 iT_i 日に発生することが分かっています。
これらの注文に対し、以下のルールに従って出荷を行います。

  • 出荷は注文 K 個分までまとめて行うことができる。
  • 注文 i は、 T_i 日以降にしか出荷できない。
  • 一度出荷すると、その出荷の X 日後になるまで次の出荷が行えない。
    • すなわち、 a 日に出荷を行った時、次の出荷ができるのは a+X 日である。

注文から出荷までにかかった日数 1 日につき、不満度が 1 蓄積します。
すなわち、注文 iS_i 日に出荷されたとき、その注文によって蓄積する不満度は (S_i - T_i) です。

出荷するタイミングを上手く定めた時、全ての注文において蓄積した不満度の総和として達成可能な最小値を求めてください。

制約

  • 入力は全て整数
  • 1 \le K \le N \le 100
  • 1 \le X \le 10^9
  • 1 \le T_1 \le T_2 \le \dots \le T_N \le 10^{12}

入力

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

N K X
T_1 T_2 \dots T_N

出力

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


入力例 1

5 2 3
1 5 6 10 12

出力例 1

2

例えば、次の通り出荷することで不満度の総和を 2 にすることができ、これが達成可能な最小です。

  • 注文 11 日に出荷する。
    • これにより不満度は (1-1) = 0 蓄積し、次の出荷ができるのは 4 日である。
  • 注文 2,36 日に出荷する。
    • これにより不満度は (6-5) + (6-6) = 1 蓄積し、次の出荷ができるのは 9 日である。
  • 注文 410 日に出荷する。
    • これにより不満度は (10-10)=0 蓄積し、次の出荷ができるのは 13 日である。
  • 注文 513 日に出荷する。
    • これにより不満度は (13-12)=1 蓄積し、次の出荷ができるのは 16 日である。

入力例 2

1 1 1000000000
1000000000000

出力例 2

0

入力例 3

15 4 5
1 3 3 6 6 6 10 10 10 10 15 15 15 15 15

出力例 3

35

Score : 550 points

Problem Statement

KEYENCE is famous for quick delivery.

In this problem, the calendar proceeds as Day 1, Day 2, Day 3, \dots.

There are orders 1,2,\dots,N, and it is known that order i will be placed on Day T_i.
For these orders, shipping is carried out according to the following rules.

  • At most K orders can be shipped together.
  • Order i can only be shipped on Day T_i or later.
  • Once a shipment is made, the next shipment cannot be made until X days later.
    • That is, if a shipment is made on Day a, the next shipment can be made on Day a+X.

For each day that passes from order placement to shipping, dissatisfaction accumulates by 1 per day.
That is, if order i is shipped on Day S_i, the dissatisfaction accumulated for that order is (S_i - T_i).

Find the minimum possible total dissatisfaction accumulated over all orders when you optimally schedule the shipping dates.

Constraints

  • All input values are integers.
  • 1 \le K \le N \le 100
  • 1 \le X \le 10^9
  • 1 \le T_1 \le T_2 \le \dots \le T_N \le 10^{12}

Input

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

N K X
T_1 T_2 \dots T_N

Output

Print the answer as an integer.


Sample Input 1

5 2 3
1 5 6 10 12

Sample Output 1

2

For example, by scheduling shipments as follows, we can achieve a total dissatisfaction of 2, which is the minimum possible.

  • Ship order 1 on Day 1.
    • This results in dissatisfaction of (1-1) = 0, and the next shipment can be made on Day 4.
  • Ship orders 2 and 3 on Day 6.
    • This results in dissatisfaction of (6-5) + (6-6) = 1, and the next shipment can be made on Day 9.
  • Ship order 4 on Day 10.
    • This results in dissatisfaction of (10-10) = 0, and the next shipment can be made on Day 13.
  • Ship order 5 on Day 13.
    • This results in dissatisfaction of (13-12) = 1, and the next shipment can be made on Day 16.

Sample Input 2

1 1 1000000000
1000000000000

Sample Output 2

0

Sample Input 3

15 4 5
1 3 3 6 6 6 10 10 10 10 15 15 15 15 15

Sample Output 3

35
G - Only One Product Name

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 600

問題文

キーエンスの商品名はすべて 英大文字 2 文字 からなります。
すでに N 個の商品名を使用しており、i 個目 (1\leq i\leq N) の商品名は S_i です。
一度使用した商品名は再び使うことができないので、過去に使用した商品名の一覧がすぐわかるように NG リストを作ることにしました。

NGリストは次の条件をみたす必要があります。

  • 1 つ以上の文字列からなり、各文字列は英大文字のみからなる。
  • すでに使用されている商品名それぞれについて、その商品名を(連続する)部分文字列として含む文字列が 1 つ以上存在する。
  • リスト内のすべての文字列は、すでに使用されている商品名でない長さ 2 の文字列を(連続する)部分文字列として含まない。

NG リストの文字列の数としてあり得る最小の値を求めてください。

制約

  • 1\leq N\leq 26^2
  • N は整数
  • S_i は英大文字のみからなる長さ 2 の文字列
  • S_1,S_2,\ldots,S_N はすべて異なる。

入力

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

N
S_1
S_2
\vdots
S_N

出力

NG リストの文字列の数としてあり得る最小の値を出力せよ。


入力例 1

7
AB
BC
CA
CD
DE
DF
XX

出力例 1

3

条件をみたす NG リストとしては例えば次の 3 つの文字列からなるようなものが考えられます。

  • CABCDE
  • DF
  • XX

これは 3 つの文字列からなり、2 つ以下の文字列からなり条件をみたす NG リストは存在しないため、 3 を出力します。


入力例 2

5
AC
BC
CD
DE
DF

出力例 2

2

条件をみたす NG リストとしては例えば次の 2 つの文字列からなるようなものが考えられます。

  • ACDE
  • BCDF

すでに使用されている商品名は NG リスト内の複数の文字列に登場したり、同一文字列に複数回含まれたりしていても良いことに注意してください。


入力例 3

6
AB
AC
CB
AD
DB
BA

出力例 3

1

例えば、ABACBADB のみからなる NG リストが条件をみたしています。

Score : 600 points

Problem Statement

All KEYENCE product names consist of two uppercase English letters.
They have already used N product names, the i-th of which (1\leq i\leq N) is S_i.
Once a product name is used, it cannot be reused, so they decided to create an NG (Not Good) list to quickly identify previously used product names.

The NG list must satisfy the following conditions.

  • It consists of one or more strings, each consisting of uppercase English letters.
  • For each already used product name, there exists at least one string in the list that contains the name as a (contiguous) substring.
  • None of the strings in the list contain any length-2 (contiguous) substring that is not an already used product name.

Find the minimum possible number of strings in the NG list.

Constraints

  • 1\leq N\leq 26^2
  • N is an integer.
  • Each S_i is a string of length 2 consisting of uppercase English letters.
  • All S_1,S_2,\ldots,S_N are distinct.

Input

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

N
S_1
S_2
\vdots
S_N

Output

Print the minimum possible number of strings in the NG list.


Sample Input 1

7
AB
BC
CA
CD
DE
DF
XX

Sample Output 1

3

One NG list satisfying the conditions is the one consisting of the following three strings:

  • CABCDE
  • DF
  • XX

This has three strings, and there is no NG list satisfying the conditions with 2 or fewer strings, so print 3.


Sample Input 2

5
AC
BC
CD
DE
DF

Sample Output 2

2

One NG list satisfying the conditions is the one consisting of the following two strings:

  • ACDE
  • BCDF

Note that each used product name may appear in multiple strings in the NG list or multiple times within the same string.


Sample Input 3

6
AB
AC
CB
AD
DB
BA

Sample Output 3

1

For example, an NG list consisting only of ABACBADB satisfies the conditions.