A - RGB Cards

Time Limit: 2 sec / Memory Limit: 256 MB

配点 : 100

問題文

AtCoDeer君は、赤、緑、青色のカードを持っています。
それぞれのカードには 1 以上 9 以下の整数が書かれており、赤色のカードには r、緑色のカードには g、青色のカードには b が書かれています。
3 つのカードを左から順に赤、緑、青色の順に並べ、左から整数を読んだときにこれが 4 の倍数であるか判定しなさい。

制約

  • 1 ≤ r, g, b ≤ 9

入力

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

r g b

出力

AtCoDeer君が作った 3 桁の整数が 4 の倍数ならば YES、そうでないならば NO を出力しなさい。


入力例 1

4 3 2

出力例 1

YES

AtCoDeer君は 432 を作り、これは 4 の倍数です。よって YES を出力します。


入力例 2

2 3 4

出力例 2

NO

AtCoDeer君は 234 を作りますが、これは 4 の倍数ではありません。よって NO を出力します。

Score : 100 points

Problem Statement

AtCoDeer has three cards, one red, one green and one blue.
An integer between 1 and 9 (inclusive) is written on each card: r on the red card, g on the green card and b on the blue card.
We will arrange the cards in the order red, green and blue from left to right, and read them as a three-digit integer.
Is this integer a multiple of 4?

Constraints

  • 1 ≤ r, g, b ≤ 9

Input

Input is given from Standard Input in the following format:

r g b

Output

If the three-digit integer is a multiple of 4, print YES (case-sensitive); otherwise, print NO.


Sample Input 1

4 3 2

Sample Output 1

YES

432 is a multiple of 4, and thus YES should be printed.


Sample Input 2

2 3 4

Sample Output 2

NO

234 is not a multiple of 4, and thus NO should be printed.

B - Traveling AtCoDeer Problem

Time Limit: 2 sec / Memory Limit: 256 MB

配点 : 200

問題文

クリスマスもあと半年となり、トナカイのAtCoDeer君はプレゼントを配る計画を立てることにしました。
TopCoDeer通りには N 個の家が並んでいます。i 個目の家は座標 a_i にあります。彼はこのすべての家にプレゼントを配ることにしました。
好きな場所から開始し好きな場所で終了することができる時、最小の移動距離を求めなさい。

制約

  • 1 ≤ N ≤ 100
  • 0 ≤ a_i ≤ 1000
  • a_i は整数である。

入力

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

N
a_1 a_2 ... a_N

出力

AtCoDeer君が動く距離の最小値を出力しなさい。


入力例 1

4
2 3 7 9

出力例 1

7

AtCoDeer君が座標 9 からスタートし、座標 2 までそのまま一直線にすすむと移動距離 7 が達成できます。
また、移動距離が 7 未満の方法は存在しないので、最小の移動距離は 7 です。


入力例 2

8
3 1 4 1 5 9 2 6

出力例 2

8

同じ場所に複数の家がある可能性もあります。

Score : 200 points

Problem Statement

It is only six months until Christmas, and AtCoDeer the reindeer is now planning his travel to deliver gifts.
There are N houses along TopCoDeer street. The i-th house is located at coordinate a_i. He has decided to deliver gifts to all these houses.
Find the minimum distance to be traveled when AtCoDeer can start and end his travel at any positions.

Constraints

  • 1 ≤ N ≤ 100
  • 0 ≤ a_i ≤ 1000
  • a_i is an integer.

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

Print the minimum distance to be traveled.


Sample Input 1

4
2 3 7 9

Sample Output 1

7

The travel distance of 7 can be achieved by starting at coordinate 9 and traveling straight to coordinate 2.
It is not possible to do with a travel distance of less than 7, and thus 7 is the minimum distance to be traveled.


Sample Input 2

8
3 1 4 1 5 9 2 6

Sample Output 2

8

There may be more than one house at a position.

C - Colorful Leaderboard

Time Limit: 2 sec / Memory Limit: 256 MB

配点 : 300

問題文

AtCoderでは、コンテストに参加すると「色」が付き、これはレートによって次のように変化します:

  • レート 1-399:灰色
  • レート 400-799:茶色
  • レート 800-1199:緑色
  • レート 1200-1599:水色
  • レート 1600-1999:青色
  • レート 2000-2399:黄色
  • レート 2400-2799:橙色
  • レート 2800-3199:赤色

また、レートが 3200 以上になると色を自由に変えることができます。
現在 N 人の人がAtCoderのコンテストに参加したことがあり、i 人目の人のレートは a_i です。
そのとき、色の種類数の最小値と最大値を求めなさい。

制約

  • 1 ≤ N ≤ 100
  • 1 ≤ a_i ≤ 4800
  • a_i は整数である。

入力

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

N
a_1 a_2 ... a_N

出力

色の種類数の最小値、最大値をこの順で空白区切りで出力しなさい。


入力例 1

4
2100 2500 2700 2700

出力例 1

2 2

レート 2100 の人は「黄色」であり、それ以外の人は「橙色」なので、色の種類数は 2 となる。


入力例 2

5
1100 1900 2800 3200 3200

出力例 2

3 5

レート 1100 の人は「緑色」、レート 1900 の人は「青色」、レート 2800 の人は「赤色」である。
4 人目が「赤色」を選び、5 人目が「青色」を選んだ時、色の種類数は 3 であり、これは最小値を取る一つの例である。
4 人目が「紫色」を選び、5 人目が「黒色」を選んだ時、色の種類数は 5 であり、これは最大値を取る一つの例である。


入力例 3

20
800 810 820 830 840 850 860 870 880 890 900 910 920 930 940 950 960 970 980 990

出力例 3

1 1

この場合全員が「緑色」である。よって色の種類数は 1 となる。

Score : 300 points

Problem Statement

In AtCoder, a person who has participated in a contest receives a color, which corresponds to the person's rating as follows:

  • Rating 1-399 : gray
  • Rating 400-799 : brown
  • Rating 800-1199 : green
  • Rating 1200-1599 : cyan
  • Rating 1600-1999 : blue
  • Rating 2000-2399 : yellow
  • Rating 2400-2799 : orange
  • Rating 2800-3199 : red

Other than the above, a person whose rating is 3200 or higher can freely pick his/her color, which can be one of the eight colors above or not.
Currently, there are N users who have participated in a contest in AtCoder, and the i-th user has a rating of a_i.
Find the minimum and maximum possible numbers of different colors of the users.

Constraints

  • 1 ≤ N ≤ 100
  • 1 ≤ a_i ≤ 4800
  • a_i is an integer.

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

Print the minimum possible number of different colors of the users, and the maximum possible number of different colors, with a space in between.


Sample Input 1

4
2100 2500 2700 2700

Sample Output 1

2 2

The user with rating 2100 is "yellow", and the others are "orange". There are two different colors.


Sample Input 2

5
1100 1900 2800 3200 3200

Sample Output 2

3 5

The user with rating 1100 is "green", the user with rating 1900 is blue and the user with rating 2800 is "red".
If the fourth user picks "red", and the fifth user picks "blue", there are three different colors. This is one possible scenario for the minimum number of colors.
If the fourth user picks "purple", and the fifth user picks "black", there are five different colors. This is one possible scenario for the maximum number of colors.


Sample Input 3

20
800 810 820 830 840 850 860 870 880 890 900 910 920 930 940 950 960 970 980 990

Sample Output 3

1 1

All the users are "green", and thus there is one color.

D - Insertion

Time Limit: 2 sec / Memory Limit: 256 MB

配点 : 400

問題文

() で構成される N 文字の文字列 S が与えられる。S にいくつかの ( または ) を挿入することで正しい括弧列を作りたい。
ただし、正しい括弧列は次のように定義されている:

  • () は正しい括弧列である。
  • X が正しい括弧列であるとき、(X) をこの順につなげたものは正しい括弧列である。
  • XY が正しい括弧列であるとき、XY をこの順につなげたものは正しい括弧列である。
  • それ以外の括弧列は正しくない。

そのとき、作れる最も文字数が少ない正しい括弧列を求めなさい。このようなものが複数ある場合は、辞書順最小のものを求めなさい。

制約

  • S の長さは N である。
  • 1 ≤ N ≤ 100
  • S() のみで構成されている。

入力

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

N
S

出力

S から () を挿入していったときに作れる最小の長さの正しい括弧列のなかで辞書順最小の文字列を出力しなさい。


入力例 1

3
())

出力例 1

(())

入力例 2

6
)))())

出力例 2

(((()))())

入力例 3

8
))))((((

出力例 3

(((())))(((())))

Score : 400 points

Problem Statement

You are given a string S of length N consisting of ( and ). Your task is to insert some number of ( and ) into S to obtain a correct bracket sequence.
Here, a correct bracket sequence is defined as follows:

  • () is a correct bracket sequence.
  • If X is a correct bracket sequence, the concatenation of (, X and ) in this order is also a correct bracket sequence.
  • If X and Y are correct bracket sequences, the concatenation of X and Y in this order is also a correct bracket sequence.
  • Every correct bracket sequence can be derived from the rules above.

Find the shortest correct bracket sequence that can be obtained. If there is more than one such sequence, find the lexicographically smallest one.

Constraints

  • The length of S is N.
  • 1 ≤ N ≤ 100
  • S consists of ( and ).

Input

Input is given from Standard Input in the following format:

N
S

Output

Print the lexicographically smallest string among the shortest correct bracket sequences that can be obtained by inserting some number of ( and ) into S.


Sample Input 1

3
())

Sample Output 1

(())

Sample Input 2

6
)))())

Sample Output 2

(((()))())

Sample Input 3

8
))))((((

Sample Output 3

(((())))(((())))