A - Multiple of 2 and N

実行時間制限: 2 sec / メモリ制限: 1024 MB

配点 : 100

問題文

正整数 N が与えられます。 2N のどちらでも割り切れる最小の正整数を求めてください。

制約

  • 1 \leq N \leq 10^9
  • 入力はすべて整数である。

入力

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

N

出力

2N のどちらでも割り切れる最小の正整数を出力せよ。


入力例 1

3

出力例 1

6

623 のどちらでも割り切れる数です。 また、6 未満の正整数であって、23 のどちらでも割り切れるような数はありません。 よって、答えは 6 です。


入力例 2

10

出力例 2

10

入力例 3

999999999

出力例 3

1999999998

Score : 100 points

Problem Statement

You are given a positive integer N. Find the minimum positive integer divisible by both 2 and N.

Constraints

  • 1 \leq N \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N

Output

Print the minimum positive integer divisible by both 2 and N.


Sample Input 1

3

Sample Output 1

6

6 is divisible by both 2 and 3. Also, there is no positive integer less than 6 that is divisible by both 2 and 3. Thus, the answer is 6.


Sample Input 2

10

Sample Output 2

10

Sample Input 3

999999999

Sample Output 3

1999999998
B - Maximum Difference

実行時間制限: 2 sec / メモリ制限: 1024 MB

配点 : 200

問題文

長さ N の整数列 A が与えられます。 A の(添字の)異なる 2 要素の差の絶対値の最大値を求めてください。

制約

  • 2 \leq N \leq 100
  • 1 \leq A_i \leq 10^9
  • 入力はすべて整数である。

入力

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

N
A_1 A_2 ... A_N

出力

A の(添字の)異なる 2 要素の差の絶対値の最大値を出力せよ。


入力例 1

4
1 4 6 3

出力例 1

5

A_3-A_1=6-1=5 が、異なる 2 要素の差の最大値です。


入力例 2

2
1000000000 1

出力例 2

999999999

入力例 3

5
1 1 1 1 1

出力例 3

0

Score : 200 points

Problem Statement

You are given an integer sequence A of length N. Find the maximum absolute difference of two elements (with different indices) in A.

Constraints

  • 2 \leq N \leq 100
  • 1 \leq A_i \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the maximum absolute difference of two elements (with different indices) in A.


Sample Input 1

4
1 4 6 3

Sample Output 1

5

The maximum absolute difference of two elements is A_3-A_1=6-1=5.


Sample Input 2

2
1000000000 1

Sample Output 2

999999999

Sample Input 3

5
1 1 1 1 1

Sample Output 3

0
C - Linear Approximation

実行時間制限: 2 sec / メモリ制限: 1024 MB

配点 : 300

問題文

すぬけ君は、長さ N の整数列 A を持っています。

すぬけ君は、整数 b を自由に選びます。 この時、A_ib+i が離れているとすぬけ君は悲しいです。 より具体的には、すぬけ君の悲しさの値は、次の式で計算されます。 なおここで、abs(x)x の絶対値を返す関数です。

  • abs(A_1 - (b+1)) + abs(A_2 - (b+2)) + ... + abs(A_N - (b+N))

すぬけ君の悲しさの値の最小値を求めてください。

制約

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq A_i \leq 10^9
  • 入力はすべて整数である。

入力

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

N
A_1 A_2 ... A_N

出力

すぬけ君の悲しさの値の最小値を出力せよ。


入力例 1

5
2 2 3 5 5

出力例 1

2

b=0 とすれば、すぬけ君の悲しさの値は、abs(2-(0+1))+abs(2-(0+2))+abs(3-(0+3))+abs(5-(0+4))+abs(5-(0+5))=2 となります。 b をどのように選んでも、すぬけ君の悲しさの値を 2 未満にすることは出来ないので、答えは 2 になります。


入力例 2

9
1 2 3 4 5 6 7 8 9

出力例 2

0

入力例 3

6
6 5 4 3 2 1

出力例 3

18

入力例 4

7
1 1 1 1 2 3 4

出力例 4

6

Score : 300 points

Problem Statement

Snuke has an integer sequence A of length N.

He will freely choose an integer b. Here, he will get sad if A_i and b+i are far from each other. More specifically, the sadness of Snuke is calculated as follows:

  • abs(A_1 - (b+1)) + abs(A_2 - (b+2)) + ... + abs(A_N - (b+N))

Here, abs(x) is a function that returns the absolute value of x.

Find the minimum possible sadness of Snuke.

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq A_i \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the minimum possible sadness of Snuke.


Sample Input 1

5
2 2 3 5 5

Sample Output 1

2

If we choose b=0, the sadness of Snuke would be abs(2-(0+1))+abs(2-(0+2))+abs(3-(0+3))+abs(5-(0+4))+abs(5-(0+5))=2. Any choice of b does not make the sadness of Snuke less than 2, so the answer is 2.


Sample Input 2

9
1 2 3 4 5 6 7 8 9

Sample Output 2

0

Sample Input 3

6
6 5 4 3 2 1

Sample Output 3

18

Sample Input 4

7
1 1 1 1 2 3 4

Sample Output 4

6
D - Equal Cut

実行時間制限: 2 sec / メモリ制限: 1024 MB

配点 : 600

問題文

すぬけ君は、長さ N の整数列 A を持っています。

すぬけ君は A3 箇所で切って、4 つの(空でない)連続する部分列 B,C,D,E に分解します。 切る位置は自由に選ぶことができます。

ここで、整数列 B,C,D,E について、その要素の総和をそれぞれ P,Q,R,S とおきます。 すぬけ君は、P,Q,R,S の最大値と最小値の差の絶対値が小さいほど嬉しいです。 P,Q,R,S の最大値と最小値の差の絶対値としてあり得る最も小さい値を求めてください。

制約

  • 4 \leq N \leq 2 \times 10^5
  • 1 \leq A_i \leq 10^9
  • 入力はすべて整数である。

入力

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

N
A_1 A_2 ... A_N

出力

P,Q,R,S の最大値と最小値の差の絶対値としてあり得る最も小さい値を出力せよ。


入力例 1

5
3 2 4 1 2

出力例 1

2

B,C,D,E=(3),(2),(4),(1,2) と分割すれば、P=3,Q=2,R=4,S=1+2=3 となります。 このとき、P,Q,R,S の最大値は 4、最小値は 2 で、その差の絶対値は 2 です。 最大値と最小値の差の絶対値を 2 未満にすることは出来ないため、2 が答えになります。


入力例 2

10
10 71 84 33 6 47 23 25 52 64

出力例 2

36

入力例 3

7
1 2 3 1000000000 4 5 6

出力例 3

999999994

Score : 600 points

Problem Statement

Snuke has an integer sequence A of length N.

He will make three cuts in A and divide it into four (non-empty) contiguous subsequences B, C, D and E. The positions of the cuts can be freely chosen.

Let P,Q,R,S be the sums of the elements in B,C,D,E, respectively. Snuke is happier when the absolute difference of the maximum and the minimum among P,Q,R,S is smaller. Find the minimum possible absolute difference of the maximum and the minimum among P,Q,R,S.

Constraints

  • 4 \leq N \leq 2 \times 10^5
  • 1 \leq A_i \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Find the minimum possible absolute difference of the maximum and the minimum among P,Q,R,S.


Sample Input 1

5
3 2 4 1 2

Sample Output 1

2

If we divide A as B,C,D,E=(3),(2),(4),(1,2), then P=3,Q=2,R=4,S=1+2=3. Here, the maximum and the minimum among P,Q,R,S are 4 and 2, with the absolute difference of 2. We cannot make the absolute difference of the maximum and the minimum less than 2, so the answer is 2.


Sample Input 2

10
10 71 84 33 6 47 23 25 52 64

Sample Output 2

36

Sample Input 3

7
1 2 3 1000000000 4 5 6

Sample Output 3

999999994