A - Measure

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 100

問題文

英小文字からなる長さ 2 または 3 の文字列 S が与えられます。長さが 2 の場合はそのまま、長さが 3 の場合は逆順にして出力してください。

制約

  • S の長さは 2 または 3 である
  • S は英小文字からなる

入力

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

S

出力

S の長さが 2 の場合はそのまま、長さが 3 の場合は逆順にして出力せよ。


入力例 1

abc

出力例 1

cba

S の長さは 3 なので、逆順にして出力します。


入力例 2

ac

出力例 2

ac

S の長さは 2 なので、そのまま出力します。

Score : 100 points

Problem Statement

You are given a string S of length 2 or 3 consisting of lowercase English letters. If the length of the string is 2, print it as is; if the length is 3, print the string after reversing it.

Constraints

  • The length of S is 2 or 3.
  • S consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S

Output

If the length of S is 2, print S as is; if the length is 3, print S after reversing it.


Sample Input 1

abc

Sample Output 1

cba

As the length of S is 3, we print it after reversing it.


Sample Input 2

ac

Sample Output 2

ac

As the length of S is 2, we print it as is.

B - Exchange

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 200

問題文

高橋君は最初 A 枚、青木君は最初 B 枚のクッキーを持っています。 二人は、高橋君からはじめて交互に、以下の操作を繰り返します。

  • 自分が持っているクッキーの枚数が奇数なら、自分が持っているクッキーを 1 枚食べ、偶数なら何もしない。その後、自分が持っているクッキーの半分を相手に渡す。

合計 K 回の操作を行った後の、高橋君と青木君が持っているクッキーの枚数をそれぞれ求めてください。

制約

  • 1 \leq A,B \leq 10^9
  • 1 \leq K \leq 100
  • A,B,K は整数である

入力

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

A B K

出力

合計 K 回の操作を行った後の、高橋君と青木君が持っているクッキーの枚数を順に出力せよ。


入力例 1

5 4 2

出力例 1

5 3

以下のように操作は進みます。

  • 最初、高橋君と青木君はそれぞれ 5,4 枚のクッキーを持っている。
  • 高橋君はクッキーを 1 枚食べ、青木君に 2 枚のクッキーを渡す。操作後、二人はそれぞれ 2,6 枚のクッキーを持っている。
  • 青木君は高橋君に 3 枚のクッキーを渡す。二人はそれぞれ 5,3 枚のクッキーを持っている。

入力例 2

3 3 3

出力例 2

1 3

入力例 3

314159265 358979323 84

出力例 3

448759046 224379523

Score : 200 points

Problem Statement

In the beginning, Takahashi has A cookies, and Aoki has B cookies. They will perform the following operation alternately, starting from Takahashi:

  • If the number of cookies in his hand is odd, eat one of those cookies; if the number is even, do nothing. Then, give one-half of the cookies in his hand to the other person.

Find the numbers of cookies Takahashi and Aoki respectively have after performing K operations in total.

Constraints

  • 1 \leq A,B \leq 10^9
  • 1 \leq K \leq 100
  • A,B and K are integers.

Input

Input is given from Standard Input in the following format:

A B K

Output

Print the number of cookies Takahashi has, and the number of cookies Aoki has, in this order, after performing K operations in total.


Sample Input 1

5 4 2

Sample Output 1

5 3

The process will go as follows:

  • In the beginning, Takahashi and Aoki have 5 and 4 cookies, respectively.
  • Takahashi eats one cookie and gives two cookies to Aoki. They now have 2 and 6 cookies, respectively.
  • Aoki gives three cookies to Takahashi. They now have 5 and 3 cookies, respectively.

Sample Input 2

3 3 3

Sample Output 2

1 3

Sample Input 3

314159265 358979323 84

Sample Output 3

448759046 224379523
C - Align

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 400

問題文

整数が N 個与えられます。i 個目の整数は A_i です。 これらを好きな順に一列に並べるとき、隣り合う要素の差の合計の最大値を求めてください。

制約

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

入力

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

N
A_1
:
A_N

出力

与えられた整数たちを好きな順に一列に並べるとき、隣り合う要素の差の合計の最大値を出力せよ。


入力例 1

5
6
8
1
2
3

出力例 1

21

3,8,1,6,2 の順に並べたとき、隣り合う要素の差の合計は 21 になり、 これが達成できる最大の値です。


入力例 2

6
3
1
4
1
5
9

出力例 2

25

入力例 3

3
5
5
1

出力例 3

8

Score : 400 points

Problem Statement

You are given N integers; the i-th of them is A_i. Find the maximum possible sum of the absolute differences between the adjacent elements after arranging these integers in a row in any order you like.

Constraints

  • 2 \leq N \leq 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_N

Output

Print the maximum possible sum of the absolute differences between the adjacent elements after arranging the given integers in a row in any order you like.


Sample Input 1

5
6
8
1
2
3

Sample Output 1

21

When the integers are arranged as 3,8,1,6,2, the sum of the absolute differences between the adjacent elements is |3 - 8| + |8 - 1| + |1 - 6| + |6 - 2| = 21. This is the maximum possible sum.


Sample Input 2

6
3
1
4
1
5
9

Sample Output 2

25

Sample Input 3

3
5
5
1

Sample Output 3

8
D - Crossing

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 500

問題文

整数 N が与えられます。\{1,2,...N\} の部分集合の組 (S_1,S_2,...,S_k) であって、以下の条件を満たすものが存在するか判定し、 存在する場合はひとつ構成してください。

  • 1,2,...,N のうちどの整数も、S_1,S_2,...,S_k のうちちょうど 2 つに含まれる
  • S_1,S_2,...,S_k のうちどの 2 つの集合をとっても、それらに共通して含まれる要素はちょうど 1 つである

制約

  • 1 \leq N \leq 10^5
  • N は整数である

入力

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

N

出力

条件を満たす部分集合の組が存在しない場合、No を出力せよ。 存在する場合、まず Yes を出力し、次いで以下の形式で部分集合の情報を出力せよ。 ただし、S_i=\{S_{i,1},S_{i,2},...,S_{i,|S_i|}\} とする。

条件を満たすものが複数ある場合、どれを出力しても構わない。

k
|S_1| S_{1,1} S_{1,2} ... S_{1,|S_1|}
:
|S_k| S_{k,1} S_{k,2} ... S_{k,|S_k|}

入力例 1

3

出力例 1

Yes
3
2 1 2
2 3 1
2 2 3

(S_1,S_2,S_3)=(\{1,2\},\{3,1\},\{2,3\}) とすれば、条件を満たすことが確認できます。


入力例 2

4

出力例 2

No

Score : 500 points

Problem Statement

You are given an integer N. Determine if there exists a tuple of subsets of \{1,2,...N\}, (S_1,S_2,...,S_k), that satisfies the following conditions:

  • Each of the integers 1,2,...,N is contained in exactly two of the sets S_1,S_2,...,S_k.
  • Any two of the sets S_1,S_2,...,S_k have exactly one element in common.

If such a tuple exists, construct one such tuple.

Constraints

  • 1 \leq N \leq 10^5
  • N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

If a tuple of subsets of \{1,2,...N\} that satisfies the conditions does not exist, print No. If such a tuple exists, print Yes first, then print such subsets in the following format:

k
|S_1| S_{1,1} S_{1,2} ... S_{1,|S_1|}
:
|S_k| S_{k,1} S_{k,2} ... S_{k,|S_k|}

where S_i={S_{i,1},S_{i,2},...,S_{i,|S_i|}}.

If there are multiple such tuples, any of them will be accepted.


Sample Input 1

3

Sample Output 1

Yes
3
2 1 2
2 3 1
2 2 3

It can be seen that (S_1,S_2,S_3)=(\{1,2\},\{3,1\},\{2,3\}) satisfies the conditions.


Sample Input 2

4

Sample Output 2

No