Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
100 以上の整数 N が与えられます。N の下 2 桁を出力してください。
ただし、N の下 2 桁とは十の位と一の位をこの順に並べたものを言います。
制約
- 100 \le N \le 999
- N は整数である。
入力
入力は以下の形式で標準入力から与えられる。
N
出力
答えを出力せよ。
入力例 1
254
出力例 1
54
254 の下 2 桁は 54 であるため、54 を出力します。
入力例 2
101
出力例 2
01
101 の下 2 桁は 01 であるため、01 を出力します。
Score : 100 points
Problem Statement
You are given an integer N at least 100. Print the last two digits of N.
Strictly speaking, print the tens and ones digits of N in this order.
Constraints
- 100 \le N \le 999
- N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Sample Input 1
254
Sample Output 1
54
The last two digits of 254 are 54, which should be printed.
Sample Input 2
101
Sample Output 2
01
The last two digits of 101 are 01, which should be printed.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
正の整数 X について、レベル X の 龍文字列 とは、1 個の L, X 個の o, 1 個の n, 1 個の g をこの順に並べた長さ (X+3) の文字列です。
正の整数 N が与えられるので、レベル N の龍文字列を出力してください。
大文字と小文字は区別されることに注意してください。
制約
- 1\leq N\leq 2024
- N は整数
入力
入力は以下の形式で標準入力から与えられる。
N
出力
レベル N の龍文字列を出力せよ。
入力例 1
3
出力例 1
Looong
1 個の L, 3 個の o, 1 個の n, 1 個の g をこの順に並べた文字列は Looong です。
入力例 2
1
出力例 2
Long
Score: 100 points
Problem Statement
For a positive integer X, the Dragon String of level X is a string of length (X+3) formed by one L, X occurrences of o, one n, and one g arranged in this order.
You are given a positive integer N. Print the Dragon String of level N.
Note that uppercase and lowercase letters are distinguished.
Constraints
- 1 \leq N \leq 2024
- N is an integer.
Input
The input is given from Standard Input in the following format:
N
Output
Print the Dragon String of level N.
Sample Input 1
3
Sample Output 1
Looong
Arranging one L, three os, one n, and one g in this order yields Looong.
Sample Input 2
1
Sample Output 2
Long
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
高橋君は置き時計を買いました。
この時計は、現在の時刻が 24 時制で \mathrm{AB} 時 \mathrm{CD} 分であるときに図 1 のように時刻を表します。
例えば図 2 では、時計は 7 時 58 分を示しています。
時刻の表示方法をより形式的に説明すると次のようになります。
現在の時刻が 24 時制で h 時 m 分であるとします。ここで 24 時制とは、時間を 0 以上 23 以下の整数で、分を 0 以上 59 以下の整数で表す時刻の表現方法を言います。
h の 10 の位を A, 1 の位を B, m の 10 の位を C, 1 の位を D とします。(ただし h, m が 1 桁である場合は先行ゼロを追加して考えます。)
このとき時計は左上に A を、左下に B を、右上に C を、右下に D を表示します。

高橋君は、次の条件を満たす時刻を 見間違えやすい時刻 と呼ぶことにしました。
- 時計の表示の右上と左下を入れ替えても、それに対応する 24 時制の時刻が存在する。
例えば 図 3 は 20 時 13 分を示していますが、時計の表示の右上と左下を入れ替えると 21 時 3 分を意味する表示になります。よって 20 時 13 分は見間違えやすい時刻です。
今、時計は H 時 M 分を示しています。
(現時点も含めて)以降はじめて訪れる見間違えやすい時刻を 24 時制で答えてください。
制約
- 0 \leq H \leq 23
- 0 \leq M \leq 59
- H, M は整数
入力
入力は以下の形式で標準入力から与えられる。
H M
出力
答えを h 時 m 分とする。ここで h, m は 0 \leq h \leq 23, 0 \leq m \leq 59 である必要がある。
このとき h, m を以下の形式で出力せよ。
h m
なお、h, m を 2 桁に揃えるために先行ゼロをつけた形式で出力しても正答と見なされる。
入力例 1
1 23
出力例 1
1 23
1 時 23 分は見間違えやすい時刻です。なぜならば、時計の表示の右上と左下を入れ替えると 2 時 13 分を意味する表示になるからです。
よって答えは 1 時 23 分です。
なお、01 23 のように先行ゼロをつけた形式で出力しても正答として扱われます。
入力例 2
19 57
出力例 2
20 0
19 時 57 分以降ではじめて訪れる見間違えやすい時刻は 20 時 0 分です。
入力例 3
20 40
出力例 3
21 0
24 時制では 24 時 0 分という表記は合法でないのに注意してください。
Score : 200 points
Problem Statement
Takahashi bought a table clock.
The clock shows the time as shown in Figure 1 at \mathrm{AB}:\mathrm{CD} in the 24-hour system.
For example, the clock in Figure 2 shows 7:58.
The format of the time is formally described as follows.
Suppose that the current time is m minutes past h in the 24-hour system. Here, the 24-hour system represents the hour by an integer between 0 and 23 (inclusive), and the minute by an integer between 0 and 59 (inclusive).
Let A be the tens digit of h, B be the ones digit of h, C be the tens digit of m, and D be the ones digit of m. (Here, if h has only one digit, we consider that it has a leading zero; the same applies to m.)
Then, the clock shows A in its top-left, B in its bottom-left, C in its top-right, and D in its bottom-right.

Takahashi has decided to call a time a confusing time if it satisfies the following condition:
- after swapping the top-right and bottom-left digits on the clock, it still reads a valid time in the 24-hour system.
For example, the clock in Figure 3 shows 20:13. After swapping its top-right and bottom-left digits, it reads 21:03. Thus, 20:13 is a confusing time.
The clock now shows H:M.
Find the next confusing time (including now) in the 24-hour system.
Constraints
- 0 \leq H \leq 23
- 0 \leq M \leq 59
- H and M are integers.
Input
The input is given from Standard Input in the following format:
H M
Output
Let h:m be the answer, where h and m must satisfy 0 \leq h \leq 23 and 0 \leq m \leq 59.
Print h and m in the following format:
h m
Your answer is considered correct even if h contains a leading zero to represent it as a 2-digit integer; the same applies to m.
Sample Input 1
1 23
Sample Output 1
1 23
1:23 is a confusing time because, after swapping its top-right and bottom-left digits on the clock, it reads 2:13.
Thus, the answer is 1:23.
Your answer is considered correct even if you print 01 23 with a leading zero.
Sample Input 2
19 57
Sample Output 2
20 0
The next confusing time after 19:57 is 20:00.
Sample Input 3
20 40
Sample Output 3
21 0
Note that 24:00 is an invalid notation in the 24-hour system.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
英大文字および数字からなる 2 文字の文字列が N 個与えられます。i 個目の文字列は S_i です。
以下の 3 つの条件をすべて満たすか判定してください。
・すべての文字列に対して、1 文字目は H , D , C , S のどれかである。
・すべての文字列に対して、2 文字目は A , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , T , J , Q , K のどれかである。
・すべての文字列は相異なる。つまり、i \neq j ならば S_i \neq S_j である。
制約
- 1 \leq N \leq 52
- S_i は英大文字および数字からなる 2 文字の文字列
入力
入力は以下の形式で標準入力から与えられる。
N S_1 S_2 \vdots S_N
出力
3 つの条件をすべて満たす場合は Yes、そうでない場合は No を出力せよ。
入力例 1
4 H3 DA D3 SK
出力例 1
Yes
このとき 3 つの条件をすべて満たすことが確認できます。
入力例 2
5 H3 DA CK H3 S7
出力例 2
No
S_1 と S_4 がともに H3 となってしまっているため、3 番目の条件に反します。
入力例 3
4 3H AD 3D KS
出力例 3
No
入力例 4
5 00 AA XX YY ZZ
出力例 4
No
Score : 200 points
Problem Statement
You are given N strings, each of length 2, consisting of uppercase English letters and digits. The i-th string is S_i.
Determine whether the following three conditions are all satisfied.
・For every string, the first character is one of H, D, C, and S.
・For every string, the second character is one of A, 2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, K.
・All strings are pairwise different. That is, if i \neq j, then S_i \neq S_j.
Constraints
- 1 \leq N \leq 52
- S_i is a string of length 2 consisting of uppercase English letters and digits.
Input
The input is given from Standard Input in the following format:
N S_1 S_2 \vdots S_N
Output
If the three conditions are all satisfied, print Yes; otherwise, print No.
Sample Input 1
4 H3 DA D3 SK
Sample Output 1
Yes
One can verify that the three conditions are all satisfied.
Sample Input 2
5 H3 DA CK H3 S7
Sample Output 2
No
Both S_1 and S_4 are H3, violating the third condition.
Sample Input 3
4 3H AD 3D KS
Sample Output 3
No
Sample Input 4
5 00 AA XX YY ZZ
Sample Output 4
No
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
アーティストの高砂君は、魚の骨をかたどったオブジェを作りました。
オブジェは N 本の肋骨と 1 本の脊椎からなります。 肋骨には 1 から N までの番号が付けられています。
高砂君は、以下の条件をすべて満たすように N+1 本の骨に 1 つずつ文字列を書こうと考えています。
- 脊椎に書く文字列の長さは N である。
- 肋骨 i = 1, \dots, N に対して、以下が成り立つ。
- 肋骨 i に書く文字列の長さは A_i である。
- 肋骨 i に書く文字列の B_i 文字目は、脊椎に書く文字列の i 文字目に一致する。
- N+1 本の骨に書く文字列はいずれも、S_1, \cdots, S_M のいずれかである(重複してもよい)。
S_1, \cdots, S_M は英小文字からなる文字列であり、互いに異なります。
j = 1, \cdots, M に対して、以下の質問に答えてください。
- 条件を満たす書き方のうち、脊椎に書く文字列が S_j であるものは存在しますか?
制約
- N は整数
- 1 \leq N \leq 10
- A_i, B_i は整数 (1 \leq i \leq N)
- 1 \leq B_i \leq A_i \leq 10 (1 \leq i \leq N)
- M は整数
- 1 \leq M \leq 200\,000
- S_j は英小文字からなる文字列 (1 \leq j \leq M)
- 1 \leq |S_j| \leq 10 (1 \leq j \leq M)
- S_1, \cdots, S_M は相異なる
入力
入力は以下の形式で標準入力から与えられる。
N A_1 B_1 \vdots A_N B_N M S_1 \vdots S_M
出力
M 行出力せよ。
j 行目 (1 \leq j \leq M) には、条件を満たす書き方のうち脊椎に書く文字列が S_j のものが存在するならば Yes を、存在しないならば No を出力せよ。
入力例 1
5 5 3 5 2 4 1 5 1 3 2 8 retro chris itchy tuna crab rock cod ash
出力例 1
Yes Yes No No No No No No
肋骨 1,2,3,4,5 にそれぞれ chris, retro, tuna, retro, cod と書くことで、脊椎に retro を書いたときに条件を満たします。

retroの長さは 5 文字。- 各肋骨について、以下が成り立つ。
- 肋骨 1 に書かれる文字列
chrisの長さは 5 文字である。その 3 文字目はrであり、retroの 1 文字目に一致する。 - 肋骨 2 に書かれる文字列
retroの長さは 5 文字である。その 2 文字目はeであり、retroの 2 文字目に一致する。 - 肋骨 3 に書かれる文字列
tunaの長さは 4 文字である。その 1 文字目はtであり、retroの 3 文字目に一致する。 - 肋骨 4 に書かれる文字列
retroの長さは 5 文字である。その 1 文字目はrであり、retroの 4 文字目に一致する。 - 肋骨 5 に書かれる文字列
codの長さは 3 文字である。その 2 文字目はoであり、retroの 5 文字目に一致する。
- 肋骨 1 に書かれる文字列
肋骨 1,2,3,4,5 にそれぞれ itchy, chris, rock, itchy, ash と書くことで、脊椎に chris を書いたときに条件を満たします。

入力例 2
5 5 1 5 2 5 3 5 4 5 5 8 retro chris itchy tuna crab rock cod ash
出力例 2
Yes Yes Yes No No No No No
Score : 300 points
Problem Statement
Artist Takasago has created an object in the shape of a fish skeleton.
The object consists of N ribs and one spine. The ribs are numbered 1 through N.
He wants to write one string on each of the N+1 bones, satisfying all of the following conditions.
- The length of the string written on the spine is N.
- For each rib i = 1, \dots, N, the following hold.
- The length of the string written on rib i is A_i.
- The B_i-th character of the string written on rib i equals the i-th character of the string written on the spine.
- Each of the strings written on the N+1 bones is one of S_1, \cdots, S_M (duplicates allowed).
S_1, \cdots, S_M are strings consisting of lowercase English letters, and they are all distinct.
For each j = 1, \cdots, M, answer the following question.
- Among the ways to write strings satisfying the conditions, is there one where the string written on the spine is S_j?
Constraints
- N is an integer.
- 1 \leq N \leq 10
- A_i and B_i are integers. (1 \leq i \leq N)
- 1 \leq B_i \leq A_i \leq 10 (1 \leq i \leq N)
- M is an integer.
- 1 \leq M \leq 200\,000
- S_j is a string consisting of lowercase English letters. (1 \leq j \leq M)
- 1 \leq |S_j| \leq 10 (1 \leq j \leq M)
- S_1, \cdots, S_M are pairwise distinct.
Input
The input is given from Standard Input in the following format:
N A_1 B_1 \vdots A_N B_N M S_1 \vdots S_M
Output
Output M lines.
The j-th line (1 \leq j \leq M) should contain Yes if there exists a way to write strings satisfying the conditions with S_j written on the spine, and No otherwise.
Sample Input 1
5 5 3 5 2 4 1 5 1 3 2 8 retro chris itchy tuna crab rock cod ash
Sample Output 1
Yes Yes No No No No No No
By writing chris, retro, tuna, retro, cod on ribs 1,2,3,4,5 respectively, the conditions are satisfied with retro written on the spine.

- The length of
retrois 5. - For each rib, the following hold.
- The string written on rib 1 is
chris, which has length 5. Its third character isr, which equals the first character ofretro. - The string written on rib 2 is
retro, which has length 5. Its second character ise, which equals the second character ofretro. - The string written on rib 3 is
tuna, which has length 4. Its first character ist, which equals the third character ofretro. - The string written on rib 4 is
retro, which has length 5. Its first character isr, which equals the fourth character ofretro. - The string written on rib 5 is
cod, which has length 3. Its second character iso, which equals the fifth character ofretro.
- The string written on rib 1 is
By writing itchy, chris, rock, itchy, ash on ribs 1,2,3,4,5 respectively, the conditions are satisfied with chris written on the spine.

Sample Input 2
5 5 1 5 2 5 3 5 4 5 5 8 retro chris itchy tuna crab rock cod ash
Sample Output 2
Yes Yes Yes No No No No No
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 250 点
問題文
長さ N の整数列 A,B が与えられます。1 以上 N 以下の整数 i,j を選んで、 A_i + B_j の値を最大化してください。
制約
- 1 \leq N \leq 5 \times 10^5
- |A_i| \leq 10^9\,(i=1,2,\dots,N)
- |B_j| \leq 10^9\,(j=1,2,\dots,N)
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \dots A_N B_1 B_2 \dots B_N
出力
A_i + B_j の最大値を出力せよ。
入力例 1
2 -1 5 3 -7
出力例 1
8
(i,j)=(1,1),(1,2),(2,1),(2,2) に対する A_i+B_j の値はそれぞれ 2,-8,8,-2 であり、(i,j)=(2,1) が最大値 8 を達成します。
入力例 2
6 15 12 3 -13 -1 -19 7 17 -13 -10 18 4
出力例 2
33
Score : 250 points
Problem Statement
You are given two integer sequences A and B, each of length N. Choose integers i, j (1 \leq i, j \leq N) to maximize the value of A_i + B_j.
Constraints
- 1 \leq N \leq 5 \times 10^5
- |A_i| \leq 10^9 (i=1,2,\dots,N)
- |B_j| \leq 10^9 (j=1,2,\dots,N)
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N A_1 A_2 \dots A_N B_1 B_2 \dots B_N
Output
Print the maximum possible value of A_i + B_j.
Sample Input 1
2 -1 5 3 -7
Sample Output 1
8
For (i,j) = (1,1), (1,2), (2,1), (2,2), the values of A_i + B_j are 2, -8, 8, -2 respectively, and (i,j) = (2,1) achieves the maximum value 8.
Sample Input 2
6 15 12 3 -13 -1 -19 7 17 -13 -10 18 4
Sample Output 2
33
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
i=1,2,\dots,N に対して、1 を A_i 個つなげた整数を B_i と表します。
より厳密には、B_i=\sum_{j=0}^{A_i-1}{10^j} と表します。
\sum_{i=1}^{N}{B_i} を求めてください。
制約
- 1 \leq N \leq 2 \times 10^5
- 1 \leq A_i \leq 2 \times 10^5
- 入力される値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \ldots A_N
出力
答えを 1 行で出力せよ。
入力例 1
4 3 3 3 3
出力例 1
444
B_1=B_2=B_3=B_4=111 なので、B_1+B_2+B_3+B_4=444 です。
入力例 2
3 30 10 20
出力例 2
111111111122222222223333333333
答えは非常に大きくなる可能性があります。
入力例 3
10 1 2 3 4 5 6 7 8 9 10
出力例 3
1234567900
Score : 400 points
Problem Statement
For i=1,2,\dots,N, let B_i denote the integer formed by concatenating A_i ones.
More formally, B_i=\sum_{j=0}^{A_i-1}{10^j}.
Find \sum_{i=1}^{N}{B_i}.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 1 \leq A_i \leq 2 \times 10^5
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N A_1 A_2 \ldots A_N
Output
Output the answer in one line.
Sample Input 1
4 3 3 3 3
Sample Output 1
444
B_1=B_2=B_3=B_4=111, so B_1+B_2+B_3+B_4=444.
Sample Input 2
3 30 10 20
Sample Output 2
111111111122222222223333333333
The answer may be very large.
Sample Input 3
10 1 2 3 4 5 6 7 8 9 10
Sample Output 3
1234567900
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 450 点
問題文
整数 A,B,X,Y が与えられます。
二次元平面上にコマが置かれています。はじめコマは座標 (0,0) にあります。
あなたは以下の操作を 0 回以上何回でも行うことができます:
- 今コマがある座標を (x,y) として、座標 (x-1,y),(x+1,y),(x,y-1),(x,y+1) のいずれかにコマを移動させる。
k 回目 (k \geq 1) に行う操作にかかるコストは k の偶奇によって異なり、それぞれ以下の通りです:
- k が奇数のとき:今コマがある座標を (x,y) として、座標 (x-1,y),(x+1,y) に移動させる場合のコストは A、座標 (x,y-1),(x,y+1) に移動させる場合のコストは B である。
- k が偶数のとき:今コマがある座標を (x,y) として、座標 (x-1,y),(x+1,y) に移動させる場合のコストは B、座標 (x,y-1),(x,y+1) に移動させる場合のコストは A である。
コマを座標 (X,Y) に移動させるために必要なコストの総和の最小値を求めてください。
T 個のテストケースが与えられるので、それぞれについて答えを求めてください。
制約
- 1\le T\le 2\times 10^5
- 1\le A,B\le 10^9
- -10^9\le X,Y\le 10^9
- 入力される値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
T
\text{case}_1
\text{case}_2
\vdots
\text{case}_T
i 番目 (1\le i\le T) のテストケース \text{case}_i は以下の形式で与えられる。
A B X Y
出力
各テストケースに対する答えを順に改行区切りで出力せよ。
入力例 1
5 1 2 -1 2 8 5 0 0 7 13 9 4 1 1 0 100 31 9 -74 -60
出力例 1
4 0 103 100 1332
1 番目のテストケースについて考えます。
以下のように移動することでコストの総和が 4 になります:
- コマを座標 (0,0) から座標 (-1,0) に移動させる。コストが 1 かかる。
- コマを座標 (-1,0) から座標 (-1,1) に移動させる。コストが 1 かかる。
- コマを座標 (-1,1) から座標 (-1,2) に移動させる。コストが 2 かかる。
コストの総和が 4 未満でコマを座標 (-1,2) に移動させることはできないので、1 行目には 4 を出力してください。
Score : 450 points
Problem Statement
You are given integers A,B,X,Y.
A piece is placed on a two-dimensional plane. Initially, the piece is at coordinate (0,0).
You can perform the following operation zero or more times:
- Let the current coordinate of the piece be (x,y). Move the piece to one of the coordinates (x-1,y),(x+1,y),(x,y-1),(x,y+1).
The cost of the k-th operation (k \geq 1) depends on the parity of k, as follows:
- If k is odd: Let the current coordinate of the piece be (x,y). The cost of moving to (x-1,y) or (x+1,y) is A, and the cost of moving to (x,y-1) or (x,y+1) is B.
- If k is even: Let the current coordinate of the piece be (x,y). The cost of moving to (x-1,y) or (x+1,y) is B, and the cost of moving to (x,y-1) or (x,y+1) is A.
Find the minimum total cost required to move the piece to coordinate (X,Y).
T test cases are given; solve each one.
Constraints
- 1\le T\le 2\times 10^5
- 1\le A,B\le 10^9
- -10^9\le X,Y\le 10^9
- All input values are integers.
Input
The input is given from Standard Input in the following format:
T
\text{case}_1
\text{case}_2
\vdots
\text{case}_T
The i-th (1\le i\le T) test case \text{case}_i is given in the following format:
A B X Y
Output
Output the answers for the test cases in order, each on a separate line.
Sample Input 1
5 1 2 -1 2 8 5 0 0 7 13 9 4 1 1 0 100 31 9 -74 -60
Sample Output 1
4 0 103 100 1332
Consider the first test case.
The following moves cost 4 in total:
- Move the piece from (0,0) to (-1,0). This costs 1.
- Move the piece from (-1,0) to (-1,1). This costs 1.
- Move the piece from (-1,1) to (-1,2). This costs 2.
It is impossible to move the piece to (-1,2) with a total cost less than 4, so output 4 on the first line.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
長さ N の整数列 A=(A_1,A_2,\dots,A_N) が与えられます。
A に対して、以下の操作を好きな回数行うことができます。
- 1 以上 N 以下の整数 i を一つ選び、i の正の約数であるようなすべての整数 j について A_j に 1 を足す。
A の要素をすべて等しくすることが可能かを判定し、可能ならばそのために必要な操作回数の最小値を求めてください。
制約
- 1 \leq N \leq 2 \times 10^5
- 1 \leq A_i \leq 10^9
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \ldots A_N
出力
A の要素をすべて等しくすることが可能ならばそのために必要な操作回数の最小値を、そうでないならば -1 を 1 行で出力せよ。
入力例 1
3 4 7 4
出力例 1
3
1 回目の操作で i=3 を選べば、A=(5,7,5) となります。
2 回目の操作で i=3 を選べば、A=(6,7,6) となります。
3 回目の操作で i=3 を選べば、A=(7,7,7) となります。
3 回未満の操作で A の要素をすべて等しくすることはできないため、答えは 3 です。
入力例 2
5 1 3 4 5 6
出力例 2
5
入力例 3
2 5 2
出力例 3
-1
Score : 500 points
Problem Statement
You are given a length-N integer sequence A=(A_1,A_2,\dots,A_N).
You can perform the following operation on A any number of times.
- Choose an integer i with 1 \leq i \leq N. For every integer j that is a positive divisor of i, add 1 to A_j.
Determine whether it is possible to make all elements of A equal, and if it is possible, find the minimum number of operations required to do so.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 1 \leq A_i \leq 10^9
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N A_1 A_2 \ldots A_N
Output
If it is possible to make all elements of A equal, output, in one line, the minimum number of operations required to do so; otherwise, output -1.
Sample Input 1
3 4 7 4
Sample Output 1
3
If you choose i=3 for the first operation, you get A=(5,7,5).
If you choose i=3 for the second operation, you get A=(6,7,6).
If you choose i=3 for the third operation, you get A=(7,7,7).
It is impossible to make all elements of A equal with fewer than three operations, so the answer is 3.
Sample Input 2
5 1 3 4 5 6
Sample Output 2
5
Sample Input 3
2 5 2
Sample Output 3
-1