実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
1 以上 9 以下の数字 A,B,C が与えられます。
A,B,C を好きな順番で並べて繋げることで作れる 3 桁の整数のうち、値が最大のものを求めてください。
制約
- A,B,C は 1 以上 9 以下の数字
入力
入力は以下の形式で標準入力から与えられる。
A B C
出力
答えを出力せよ。
入力例 1
3 2 4
出力例 1
432
A,B,C を好きな順番で並べて繋げることで作れる 3 桁の整数は 324, 342, 234, 243, 432, 423 の 6 通りであり、 このうち値が最大のものは 432 です。
入力例 2
7 7 7
出力例 2
777
777 のみを作ることができます。
入力例 3
9 1 9
出力例 3
991
Score : 100 points
Problem Statement
You are given three digits A,B,C between 1 and 9, inclusive.
Find the maximum value among all 3-digit integers that can be formed by arranging A,B,C in any order and concatenating them.
Constraints
- A,B,C are digits between 1 and 9, inclusive.
Input
The input is given from Standard Input in the following format:
A B C
Output
Output the answer.
Sample Input 1
3 2 4
Sample Output 1
432
There are six 3-digit integers that can be formed by arranging A,B,C in any order and concatenating them: 324, 342, 234, 243, 432, 423; the maximum value among them is 432.
Sample Input 2
7 7 7
Sample Output 2
777
Only 777 can be formed.
Sample Input 3
9 1 9
Sample Output 3
991
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
整数 A, B, C が与えられます。A \neq B かつ B = C であるならば Yes を、そうでないならば No を出力してください。
制約
- 1 \leq A, B, C \leq 9
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
A B C
出力
問題文中の指示に従って Yes, No のいずれかを出力せよ。
入力例 1
4 5 5
出力例 1
Yes
4 \neq 5 かつ 5 = 5 なので Yes を出力します。
入力例 2
1 3 7
出力例 2
No
1 \neq 3 ですが 3 = 7 ではないので No を出力します。
入力例 3
6 6 6
出力例 3
No
Score : 100 points
Problem Statement
You are given integers A, B, C. If A \neq B and B = C, output Yes; otherwise, output No.
Constraints
- 1 \leq A, B, C \leq 9
- All input values are integers.
Input
The input is given from Standard Input in the following format:
A B C
Output
Output Yes or No according to the instructions in the problem statement.
Sample Input 1
4 5 5
Sample Output 1
Yes
Since 4 \neq 5 and 5 = 5, output Yes.
Sample Input 2
1 3 7
Sample Output 2
No
Although 1 \neq 3, we don't have 3 = 7, so output No.
Sample Input 3
6 6 6
Sample Output 3
No
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
N 人の人がいます。N 人の人には人 1, 人 2,\dots, 人 N と番号がついています。
人 i(2 \le i \le N) の親は人 P_i です。ここで、P_i < i が保証されます。
人 1 が人 N の何代前か求めてください。
制約
- 2 \le N \le 50
- 1 \le P_i < i(2 \le i \le N)
- 入力は全て整数。
入力
入力は以下の形式で標準入力から与えられる。
N P_2 P_3 \dots P_N
出力
答えを整数として出力せよ。
入力例 1
3 1 2
出力例 1
2
人 2 は人 3 の親であるため、人 3 の 1 代前です。
人 1 は人 2 の親であるため、人 3 の 2 代前です。
よって解は 2 です。
入力例 2
10 1 2 3 4 5 6 7 8 9
出力例 2
9
Score : 200 points
Problem Statement
There are N people, called Person 1, Person 2, \ldots, Person N.
The parent of Person i (2 \le i \le N) is Person P_i. Here, it is guaranteed that P_i < i.
How many generations away from Person N is Person 1?
Constraints
- 2 \le N \le 50
- 1 \le P_i < i(2 \le i \le N)
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N P_2 P_3 \dots P_N
Output
Print the answer as a positive integer.
Sample Input 1
3 1 2
Sample Output 1
2
Person 2 is a parent of Person 3, and thus is one generation away from Person 3.
Person 1 is a parent of Person 2, and thus is two generations away from Person 3.
Therefore, the answer is 2.
Sample Input 2
10 1 2 3 4 5 6 7 8 9
Sample Output 2
9
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
駐車場があります。この駐車場に駐車するときの料金は以下の通りです。
- L 時ちょうどから R 時ちょうどまでのあいだは、1 時間停めるごとに X の料金がかかる
- 上に該当しない時間のあいだは、1 時間停めるごとに Y の料金がかかる
この駐車場に、日をまたぐことなく車を A 時ちょうどから B 時ちょうどまで停めたとき、料金はいくらになりますか?
制約
- 1 \leq X, Y \leq 1000
- 1 \leq L < R \leq 23
- 1 \leq A < B \leq 23
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
X Y L R A B
出力
答えを出力せよ。
入力例 1
700 300 9 17 7 21
出力例 1
7400
車を 7 時から 21 時のあいだ停めたとき、かかる料金は以下のようになります。
- 7 時から 9 時までの 2 時間は 300 \times 2 = 600 の料金がかかる
- 9 時から 17 時までの 8 時間は 700 \times 8 = 5600 の料金がかかる
- 17 時から 21 時までの 4 時間は 300 \times 4 = 1200 の料金がかかる
600 + 5600 + 1200 = 7400 が求める答えです。
入力例 2
600 500 9 17 17 20
出力例 2
1500
車を 17 時から 20 時のあいだ停めたとき、かかる料金は以下のようになります。
- 17 時から 20 時までの 3 時間は 500 \times 3 = 1500 の料金がかかる
1500 が求める答えです。
入力例 3
900 200 12 14 11 13
出力例 3
1100
Score : 200 points
Problem Statement
There is a parking lot. The fee for parking in this lot is as follows:
- During the period from exactly L o'clock to exactly R o'clock, a fee of X is charged for each hour parked.
- During the period not covered above, a fee of Y is charged for each hour parked.
If a car is parked in this lot from exactly A o'clock to exactly B o'clock without crossing midnight, how much is the fee?
Constraints
- 1 \leq X, Y \leq 1000
- 1 \leq L < R \leq 23
- 1 \leq A < B \leq 23
- All input values are integers.
Input
The input is given from Standard Input in the following format:
X Y L R A B
Output
Output the answer.
Sample Input 1
700 300 9 17 7 21
Sample Output 1
7400
If a car is parked from 7 o'clock to 21 o'clock, the fee is as follows.
- For the 2 hours from 7 o'clock to 9 o'clock, a fee of 300 \times 2 = 600 is charged.
- For the 8 hours from 9 o'clock to 17 o'clock, a fee of 700 \times 8 = 5600 is charged.
- For the 4 hours from 17 o'clock to 21 o'clock, a fee of 300 \times 4 = 1200 is charged.
The answer is 600 + 5600 + 1200 = 7400.
Sample Input 2
600 500 9 17 17 20
Sample Output 2
1500
If a car is parked from 17 o'clock to 20 o'clock, the fee is as follows.
- For the 3 hours from 17 o'clock to 20 o'clock, a fee of 500 \times 3 = 1500 is charged.
The answer is 1500.
Sample Input 3
900 200 12 14 11 13
Sample Output 3
1100
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 350 点
問題文
長さ N の整数列 A=(A_1,A_2,\ldots,A_N) が与えられます。
Q 個のクエリが与えられるので順に処理してください。クエリは 2 種類あり、以下のいずれかの形式で与えられます。
1 c: A の先頭の要素を末尾に移動させる操作を c 回行う。2 l r: \displaystyle \sum_{i=l}^r A_i の値を出力する。
制約
- 1\le N\le 2\times 10^5
- 1\le Q\le 2\times 10^5
- 1\le A_i \le 10^9
- 1\le c\le N
- 1\le l\le r \le N
- 2 つ目の形式のクエリが 1 つ以上存在する
- 入力される値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N Q
A_1 A_2 \ldots A_N
\text{query}_1
\text{query}_2
\vdots
\text{query}_Q
各クエリ \text{query}_i は以下の 2 種類のいずれかの形式で与えられる。
1 c
2 l r
出力
問題文の指示に従って 2 つ目の形式のクエリへの答えを改行区切りで出力せよ。
入力例 1
4 3 3 1 4 5 2 1 3 1 1 2 2 3
出力例 1
8 9
各クエリは以下のように処理されます。
- 1 つ目のクエリ: A_1+A_2+A_3=3+1+4=8 なので 8 を出力します。
- 2 つ目のクエリ: A=(3,1,4,5) が A=(1,4,5,3) に変化します。
- 3 つ目のクエリ: A_2+A_3=4+5=9 なので 9 を出力します。
入力例 2
5 7 1 2 4 8 16 2 1 5 1 4 1 5 2 1 5 2 2 4 1 1 2 3 3
出力例 2
31 31 7 4
Score : 350 points
Problem Statement
You are given an integer sequence A=(A_1,A_2,\ldots,A_N) of length N.
Process Q queries in order. There are two types of queries, given in the following formats:
1 c: Perform the operation of moving the first element of A to the end c times.2 l r: Output the value of \displaystyle \sum_{i=l}^r A_i.
Constraints
- 1\le N\le 2\times 10^5
- 1\le Q\le 2\times 10^5
- 1\le A_i \le 10^9
- 1\le c\le N
- 1\le l\le r \le N
- At least one query of the second type exists.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N Q
A_1 A_2 \ldots A_N
\text{query}_1
\text{query}_2
\vdots
\text{query}_Q
Each query \text{query}_i is given in one of the following two formats:
1 c
2 l r
Output
Following the instructions in the problem statement, output the answers to the second type queries, separated by newlines.
Sample Input 1
4 3 3 1 4 5 2 1 3 1 1 2 2 3
Sample Output 1
8 9
Each query is processed as follows:
- First query: A_1+A_2+A_3=3+1+4=8, so output 8.
- Second query: A=(3,1,4,5) changes to A=(1,4,5,3).
- Third query: A_2+A_3=4+5=9, so output 9.
Sample Input 2
5 7 1 2 4 8 16 2 1 5 1 4 1 5 2 1 5 2 2 4 1 1 2 3 3
Sample Output 2
31 31 7 4
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
AtCoder レストランは開店してから N 日間営業しました。
開店してから i 日目 (1\leq i\leq N) には次の行動が行われました。
- i 日目の朝に、A_i 個の卵を仕入れる。
- i 日目の昼に、B_i 個の卵を使用する。このとき、卵は 在庫にある卵の中で仕入れた順に使用される 。
- i 日目の夜に、仕入れてから D 日間以上経過した卵をすべて処分する。
なお、1 日目の朝の前の時点で卵の在庫は無く、それぞれの日の昼に卵が足りなくなることはありませんでした。
N 日目の夜の行動の後で、レストランに何個の卵が残っているか求めてください。
T 個のテストケースが与えられるので、それぞれについて答えを求めてください。
制約
- 1 \leq T\leq 2\times 10^5
- 1 \leq D \leq N \leq 2\times 10^5
- 1 \leq A_i,B_i \leq 10
- N 日間のそれぞれの昼において、卵が足りなくなることはない。
- それぞれの入力において、各テストケースにおける N の総和は 2\times 10^5 以下である。
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_T
\mathrm{case}_i は i 個目のテストケースを表す。
各テストケースは以下の形式で与えられる。
N D A_1 A_2 \ldots A_N B_1 B_2 \ldots B_N
出力
T 行出力せよ。
i 行目 (1\leq i\leq T) には、i 個目のテストケースに対する答えを出力せよ。
入力例 1
3 3 1 7 2 3 1 3 2 3 2 7 2 3 1 3 2 2 1 2 1 1 2
出力例 1
3 5 0
1 個目のテストケースにおいて次の行動が行われます。
- 最初、AtCoder レストランには卵がありません。
- 1 日目の朝に卵を 7 個仕入れます。レストランには 1 日目に仕入れた卵が 7 個あります。
- 1 日目の昼に卵を 1 個使用します。レストランには 1 日目に仕入れた卵が 6 個残っています。
- 1 日目の夜に処分する卵はありません。レストランには 1 日目に仕入れた卵が 6 個残っています。
- 2 日目の朝に卵を 2 個仕入れます。レストランには 1 日目に仕入れた卵が 6 個、2 日目に仕入れた卵が 2 個あります。
- 2 日目の昼に卵を 3 個使用します。レストランには 1 日目に仕入れた卵が 3 個、2 日目に仕入れた卵が 2 個残っています。
- 2 日目の夜に、1 日目に仕入れた卵を処分します。レストランには 2 日目に仕入れた卵が 2 個残っています。
- 3 日目の朝に卵を 3 個仕入れます。レストランには 2 日目に仕入れた卵が 2 個、3 日目に仕入れた卵が 3 個あります。
- 3 日目の昼に卵を 2 個使用します。レストランには 3 日目に仕入れた卵が 3 個残っています。
- 3 日目の夜に処分する卵はありません。(2 日目に仕入れた卵は全て使用されているためです。)レストランには 3 日目に仕入れた卵が 3 個残っています。
よって、3 日目の夜の行動の後で、卵は 3 個残っているため、1 行目には 3 を出力します。
2 個目のテストケースにおいては、3 日目の夜に 1 日目に仕入れた卵を処分した後の個数を出力することに注意してください。
Score : 300 points
Problem Statement
AtCoder Restaurant was open for N days after opening.
On day i (1\leq i\leq N) after opening, the following actions were performed.
- In the morning of day i, A_i eggs are purchased.
- At noon on day i, B_i eggs are used. Here, eggs in stock are used in the order they were purchased.
- In the evening of day i, all eggs that have been stocked for D or more days are discarded.
There were no eggs in stock before the morning of day 1, and eggs never ran out at noon on any day.
Find how many eggs remain in the restaurant after the evening action on day N.
T test cases are given; solve each.
Constraints
- 1 \leq T\leq 2\times 10^5
- 1 \leq D \leq N \leq 2\times 10^5
- 1 \leq A_i,B_i \leq 10
- Eggs never run out at noon on any of the N days.
- For each input, the sum of N over all test cases is at most 2\times 10^5.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_T
\mathrm{case}_i represents the i-th test case.
Each test case is given in the following format:
N D A_1 A_2 \ldots A_N B_1 B_2 \ldots B_N
Output
Output T lines.
The i-th line (1\leq i\leq T) should contain the answer for the i-th test case.
Sample Input 1
3 3 1 7 2 3 1 3 2 3 2 7 2 3 1 3 2 2 1 2 1 1 2
Sample Output 1
3 5 0
In the first test case, the following actions are performed.
- Initially, AtCoder Restaurant has no eggs.
- In the morning of day 1, 7 eggs are purchased. The restaurant has 7 eggs stocked on day 1.
- At noon on day 1, 1 egg is used. The restaurant has 6 eggs stocked on day 1 remaining.
- In the evening of day 1, no eggs are discarded. The restaurant has 6 eggs stocked on day 1 remaining.
- In the morning of day 2, 2 eggs are purchased. The restaurant has 6 eggs stocked on day 1 and 2 eggs stocked on day 2.
- At noon on day 2, 3 eggs are used. The restaurant has 3 eggs stocked on day 1 and 2 eggs stocked on day 2 remaining.
- In the evening of day 2, the eggs stocked on day 1 are discarded. The restaurant has 2 eggs stocked on day 2 remaining.
- In the morning of day 3, 3 eggs are purchased. The restaurant has 2 eggs stocked on day 2 and 3 eggs stocked on day 3.
- At noon on day 3, 2 eggs are used. The restaurant has 3 eggs stocked on day 3 remaining.
- In the evening of day 3, no eggs are discarded. (This is because all eggs stocked on day 2 have already been used.) The restaurant has 3 eggs stocked on day 3 remaining.
Thus, 3 eggs remain after the evening action on day 3, so output 3 on the first line.
For the second test case, remember to output the number of eggs after discarding the eggs stocked on day 1 in the evening of day 3.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 400 点
問題文
N 種類の弁当が、それぞれ 1 個ずつ売られています。
i = 1, 2, \ldots, N について、i 種類目の弁当には A_i 個のたこ焼きと B_i 個のたい焼きが入っています。
高橋君は、 X 個以上のたこ焼きと Y 個以上のたい焼きを食べたいです。
高橋君がいくつかの弁当を選んで買うことで、 X 個以上のたこ焼きと Y 個以上のたい焼きを手に入れることが可能かどうか判定して下さい。また、可能な場合はそのために高橋君が購入しなければならない弁当の個数の最小値を求めて下さい。
各種類の弁当は 1 個しか売られていないため、同じ種類の弁当を 2 個以上購入することは出来ないことに注意して下さい。
制約
- 1 \leq N \leq 300
- 1 \leq X, Y \leq 300
- 1 \leq A_i, B_i \leq 300
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N X Y A_1 B_1 A_2 B_2 \vdots A_N B_N
出力
高橋君が X 個以上のたこ焼きと Y 個以上のたい焼きを手に入れることが不可能な場合は -1 を出力し、 可能な場合はそのために高橋君が購入しなければならない弁当の個数の最小値を出力せよ。
入力例 1
3 5 6 2 1 3 4 2 3
出力例 1
2
高橋君は、5 個以上のたこ焼きと 6 個以上のたい焼きを食べたいです。
高橋君は 2 種類目の弁当と 3 種類目の弁当を買うことで、
たこ焼きを 3 + 2 = 5 個、たい焼きを 4 + 3 = 7 個手に入れることができます。
入力例 2
3 8 8 3 4 2 3 2 1
出力例 2
-1
高橋君がたとえすべての弁当を買ったとしても、高橋君は 8 個以上のたこ焼きと 8 個以上のたい焼きを手に入れることが出来ません。
よって、-1 を出力します。
Score : 400 points
Problem Statement
A shop sells N kinds of lunchboxes, one for each kind.
For each i = 1, 2, \ldots, N, the i-th kind of lunchbox contains A_i takoyaki (octopus balls) and B_i taiyaki (fish-shaped cakes).
Takahashi wants to eat X or more takoyaki and Y or more taiyaki.
Determine whether it is possible to buy some number of lunchboxes to get at least X takoyaki and at least Y taiyaki. If it is possible, find the minimum number of lunchboxes that Takahashi must buy to get them.
Note that just one lunchbox is in stock for each kind; you cannot buy two or more lunchboxes of the same kind.
Constraints
- 1 \leq N \leq 300
- 1 \leq X, Y \leq 300
- 1 \leq A_i, B_i \leq 300
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X Y A_1 B_1 A_2 B_2 \vdots A_N B_N
Output
If Takahashi cannot get at least X takoyaki and at least Y taiyaki, print -1; otherwise, print the minimum number of lunchboxes that he must buy to get them.
Sample Input 1
3 5 6 2 1 3 4 2 3
Sample Output 1
2
He wants to eat 5 or more takoyaki and 6 or more taiyaki.
Buying the second and third lunchboxes will get him 3 + 2 = 5 taiyaki and 4 + 3 = 7 taiyaki.
Sample Input 2
3 8 8 3 4 2 3 2 1
Sample Output 2
-1
Even if he is to buy every lunchbox, it is impossible to get at least 8 takoyaki and at least 8 taiyaki.
Thus, print -1.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 500 点
問題文
正整数 n の桁和を、n を 10 進法で表したときの各桁の和と定義します。例えば 2025 の桁和は 2 + 0 + 2 + 5 = 9 です。
正整数 n が n の桁和で割り切れる時、n を 良い整数 と呼びます。例えば 2025 はその桁和である 9 で割り切れるので良い整数です。
正整数の組 (a, a+1) であって a と a+1 が共に良い整数であるものを 双子の良い整数 と呼びます。例えば (2024, 2025) は双子の良い整数です。
正整数 N が与えられます。N \leq a かつ a + 1 \leq 2N であるような双子の良い整数 (a, a + 1) を発見してください。そのような (a, a + 1) が存在しない場合はそのことを報告してください。
制約
- N は 1 以上 10^{100000} 未満の整数
入力
入力は以下の形式で標準入力から与えられる。
N
出力
問題文の条件を満たす (a, a+1) が存在する場合は a を、存在しない場合は -1 を出力せよ。a は leading-zeros を省略した表現で出力する必要がある点に注意せよ。
条件を満たす (a, a+1) が複数存在する場合はどれを出力してもよい。
入力例 1
5
出力例 1
8
(8, 9) は問題文の条件を満たす双子の良い整数です。他にも (5, 6), (6, 7), (7, 8), (9, 10) が条件を満たします。
入力例 2
21
出力例 2
-1
問題文の条件を満たす双子の良い整数は存在しません。
入力例 3
1234
出力例 3
2024
(2024, 2025) は問題文の条件を満たす双子の良い整数です。
入力例 4
1234567890123456789012345678901234567890
出力例 4
1548651852734633803438094164372911259190
Score : 500 points
Problem Statement
The digit sum of a positive integer n is defined as the sum of its digits when n is written in decimal. For example, the digit sum of 2025 is 2 + 0 + 2 + 5 = 9.
A positive integer n is called a good integer if it is divisible by its digit sum. For example, 2025 is a good integer because it is divisible by its digit sum of 9.
A pair of positive integers (a, a+1) is called twin good integers if both a and a+1 are good integers. For example, (2024, 2025) is twin good integers.
You are given a positive integer N. Find a pair of twin good integers (a, a + 1) such that N \leq a and a + 1 \leq 2N. If no such pair exists, report that fact.
Constraints
- N is an integer at least 1 and less than 10^{100000}.
Input
The input is given from Standard Input in the following format:
N
Output
If there exists such a pair (a, a+1), output a. Otherwise, output -1. Do not print leading zeros.
If there are multiple such pairs, you may print any.
Sample Input 1
5
Sample Output 1
8
(8, 9) is a valid pair of twin good integers satisfying the conditions. Other examples include (5, 6), (6, 7), (7, 8), (9, 10).
Sample Input 2
21
Sample Output 2
-1
No pair of twin good integers satisfies the conditions.
Sample Input 3
1234
Sample Output 3
2024
(2024, 2025) is a valid pair of twin good integers.
Sample Input 4
1234567890123456789012345678901234567890
Sample Output 4
1548651852734633803438094164372911259190
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 500 点
問題文
ABC250 は、 ABC1000 の開催を目指す高橋くんにとってちょうど 1/4 となる記念すべき回です。
そこで、高橋くんはピザを 1 枚買ってきて、そのピザのうちなるべく 1/4 に近い分量を食べて祝うことにしました。
高橋くんが買ってきたピザは凸 N 角形 (N \ge 4) の平らな形をしており、このピザを xy 平面上に置いた際、 i 番目の頂点の座標は (X_i,Y_i) でした。
高橋くんは、このピザを以下のように切って食べることにしました。
- まず、高橋くんはピザの頂点のうち隣接しない 2 頂点を選び、それらを通る直線に沿ってナイフを入れ、ピザを 2 つに切り分ける。
- その後、 2 つのピースのうち好きなものをどちらか 1 つ選んで食べる。
高橋くんが買ってきたピザの面積の 1/4 を a 、高橋くんが食べるピースの面積を b とした時、 8 \times |a-b| としてありえる最小値を求めてください。なお、この値は常に整数となることが示せます。
制約
- 入力は全て整数
- 4 \le N \le 10^5
- |X_i|, |Y_i| \le 4 \times 10^8
- 入力される頂点は反時計回りに凸 N 角形をなす。
入力
入力は以下の形式で標準入力から与えられる。
N X_1 Y_1 X_2 Y_2 \dots X_N Y_N
出力
答えを整数として出力せよ。
入力例 1
5 3 0 2 3 -1 3 -3 1 -1 -1
出力例 1
1
3 番目の頂点と 5 番目の頂点を通る直線に沿ってピザを切り分け、 4 番目の頂点を含む側のピースを食べたとします。
このとき、a=\frac{33}{2} \times \frac{1}{4} = \frac{33}{8} 、 b=4 、 8 \times |a-b|=1 であり、これがありえる最小値です。
入力例 2
4 400000000 400000000 -400000000 400000000 -400000000 -400000000 400000000 -400000000
出力例 2
1280000000000000000
入力例 3
6 -816 222 -801 -757 -165 -411 733 131 835 711 -374 979
出力例 3
157889
Score : 500 points
Problem Statement
ABC 250 is a commemorable quarter milestone for Takahashi, who aims to hold ABC 1000, so he is going to celebrate this contest by eating as close to 1/4 of a pizza he bought as possible.
The pizza that Takahashi bought has a planar shape of convex N-gon. When the pizza is placed on an xy-plane, the i-th vertex has coordinates (X_i, Y_i).
Takahashi has decided to cut and eat the pizza as follows.
- First, Takahashi chooses two non-adjacent vertices from the vertices of the pizza and makes a cut with a knife along the line passing through those two points, dividing the pizza into two pieces.
- Then, he chooses one of the pieces at his choice and eats it.
Let a be the quarter (=1/4) of the area of the pizza that Takahashi bought, and b be the area of the piece of pizza that Takahashi eats. Find the minimum possible value of 8 \times |a-b|. We can prove that this value is always an integer.
Constraints
- All values in input are integers.
- 4 \le N \le 10^5
- |X_i|, |Y_i| \le 4 \times 10^8
- The given points are the vertices of a convex N-gon in the counterclockwise order.
Input
Input is given from Standard Input in the following format:
N X_1 Y_1 X_2 Y_2 \dots X_N Y_N
Output
Print the answer as an integer.
Sample Input 1
5 3 0 2 3 -1 3 -3 1 -1 -1
Sample Output 1
1
Suppose that he makes a cut along the line passing through the 3-rd and the 5-th vertex and eats the piece containing the 4-th vertex.
Then, a=\frac{33}{2} \times \frac{1}{4} = \frac{33}{8}, b=4, and 8 \times |a-b|=1, which is minimum possible.
Sample Input 2
4 400000000 400000000 -400000000 400000000 -400000000 -400000000 400000000 -400000000
Sample Output 2
1280000000000000000
Sample Input 3
6 -816 222 -801 -757 -165 -411 733 131 835 711 -374 979
Sample Output 3
157889