A - 2^n - 2*n

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

配点 : 100 点

問題文

整数 N が与えられるので、 2^N-2N の値を計算して出力してください。

制約

  • N は 1 以上 11 以下の整数

入力

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

N

出力

答えを出力せよ。


入力例 1

1

出力例 1

0

この入力で与えられる N の値は 1 なので、 2^1 - 2 \times 1 の値である 0 を出力してください。


入力例 2

2

出力例 2

0

この入力で与えられる N の値は 2 なので、 2^2 - 2 \times 2 の値である 0 を出力してください。


入力例 3

11

出力例 3

2026

この入力で与えられる N の値は 11 なので、 2^{11} - 2 \times 11 の値である 2026 を出力してください。

Score : 100 points

Problem Statement

You are given an integer N. Compute and output the value of 2^N-2N.

Constraints

  • N is an integer between 1 and 11, inclusive.

Input

The input is given from Standard Input in the following format:

N

Output

Output the answer.


Sample Input 1

1

Sample Output 1

0

The value of N given in this input is 1, so output the value of 2^1 - 2 \times 1, which is 0.


Sample Input 2

2

Sample Output 2

0

The value of N given in this input is 2, so output the value of 2^2 - 2 \times 2, which is 0.


Sample Input 3

11

Sample Output 3

2026

The value of N given in this input is 11, so output the value of 2^{11} - 2 \times 11, which is 2026.

B - Move Right

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

配点 : 100 点

問題文

横一列に 4 つのマスが並んでいます。

各文字が 0 または 1 である長さ 4 の文字列 S が与えられます。
S の i 文字目が 1 であるとき、左から i 番目のマスには 1 人の人がおり、
S の i 文字目が 0 であるとき、左から i 番目のマスには人がいません。

全ての人が一斉に、1 つ右隣のマスへ移動します。この移動により、もともと右端のマスにいた人は消えます。

移動後の各マスに人がいるかどうかを、S と同様のルールで文字列として出力してください。

制約

  • S は 0, 1 のみからなる長さ 4 の文字列

入力

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

S

出力

長さ 4 の文字列であって、移動後、左から i 番目のマスに人がいるならば i 文字目が 1、いないならば 0 であるようなものを出力せよ。


入力例 1

1011

出力例 1

0101

移動により、左から 1 番目のマスにいた人は左から 2 番目のマスに、
左から 3 番目のマスにいた人は左から 4 番目のマスに移動し、
左から 4 番目のマス(右端のマス)にいた人は消えます。


入力例 2

0000

出力例 2

0000

入力例 3

1111

出力例 3

0111

Score : 100 points

Problem Statement

There are 4 squares lined up horizontally.

You are given a string S of length 4 consisting of 0 and 1.
If the i-th character of S is 1, there is a person in the i-th square from the left;
if the i-th character of S is 0, there is no person in the i-th square from the left.

Now, everyone will move to the next square to the right simultaneously. By this move, the person who was originally in the rightmost square will disappear.

Determine if there will be a person in each square after the move. Print the result as a string in the same format as S. (See also Sample Input / Output for clarity.)

Constraints

  • S is a string of length 4 consisting of 0 and 1.

Input

Input is given from Standard Input in the following format:

S

Output

Print a string of length 4 such that the i-th character is 1 if there will be a person in the i-th square from the left after the move, and 0 otherwise.


Sample Input 1

1011

Sample Output 1

0101

After the move, the person who was originally in the 1-st square will move to the 2-nd square,
the person in the 3-rd square to the 4-th square,
and the person in the 4-th square will disappear.


Sample Input 2

0000

Sample Output 2

0000

Sample Input 3

1111

Sample Output 3

0111
C - Pentagon

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

配点 : 200 点

問題文

以下の図で表される正五角形 P があります。

P の点 S_1 と点 S_2 を結ぶ線分と、点 T_1 と点 T_2 を結ぶ線分の長さが等しいか判定してください。

制約

  • S_1,S_2,T_1,T_2 は A, B, C, D, E のいずれかの文字
  • S_1 \neq S_2
  • T_1 \neq T_2

入力

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

S_1S_2
T_1T_2

出力

P の点 S_1 と点 S_2 を結ぶ線分と、点 T_1 と点 T_2 を結ぶ線分の長さが等しい場合 Yes を、等しくない場合 No を出力せよ。


入力例 1

AC
EC

出力例 1

Yes

P の点 A と点 C を結ぶ線分と、P の点 E と点 C を結ぶ線分の長さは等しいです。


入力例 2

DA
EA

出力例 2

No

P の点 D と点 A を結ぶ線分と、P の点 E と点 A を結ぶ線分の長さは等しくありません。


入力例 3

BD
BD

出力例 3

Yes

Score : 200 points

Problem Statement

A regular pentagon P is shown in the figure below.

Determine whether the length of the line segment connecting points S_1 and S_2 of P equals the length of the line segment connecting points T_1 and T_2.

Constraints

  • Each of S_1, S_2, T_1, and T_2 is one of the characters A, B, C, D, and E.
  • S_1 \neq S_2
  • T_1 \neq T_2

Input

The input is given from Standard Input in the following format:

S_1S_2
T_1T_2

Output

If the length of the line segment connecting points S_1 and S_2 of P equals the length of the line segment connecting points T_1 and T_2, print Yes; otherwise, print No.


Sample Input 1

AC
EC

Sample Output 1

Yes

The length of the line segment connecting point A and point C of P equals the length of the line segment connecting point E and point C.


Sample Input 2

DA
EA

Sample Output 2

No

The length of the line segment connecting point D and point A of P does not equal the length of the line segment connecting point E and point A.


Sample Input 3

BD
BD

Sample Output 3

Yes
D - ARC Division

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



配点 : 200 点

問題文

AtCoder では、ARC が 2 つの division に分けられています。

  • ARC Div. 1 では、コンテスト開始時のレーティングが 1600 以上 2799 以下の参加者がレーティング更新の対象です。
  • ARC Div. 2 では、コンテスト開始時のレーティングが 1200 以上 2399 以下の参加者がレーティング更新の対象です。

高橋くんは、これから N 回の ARC に参加することにしました。

はじめ、高橋くんのレーティングは R です。

i 回目 (1\leq i\leq N) の ARC は Div. D _ i で、高橋くんが取った成績は整数 A _ i で表されます。

i 回目の ARC において高橋くんがレーティング更新の対象ならば、コンテスト開始時の高橋くんのレーティングを T として、更新後の高橋くんのレーティングは T+A _ i になります。 高橋くんがレーティング更新の対象でなければ、高橋くんのレーティングは変化しません。

ARC でのレーティングの更新はコンテストが終了したあと直ちに行われ、次のコンテストのレーティング更新の対象であるかは更新後のレーティングをもとに判定されます。

N 回の ARC を終えたとき、高橋くんのレーティングがいくつになっているか求めてください。

ただし、高橋くんはこの N 回の ARC 以外のコンテストには参加せず、ARC 以外でレーティングが変動することはありません。

制約

  • 1\leq N\leq 100
  • 0\leq R\leq 4229
  • 1\leq D _ i\leq 2\ (1\leq i\leq N)
  • -1000\leq A _ i\leq 1000\ (1\leq i\leq N)
  • 入力はすべて整数

入力

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

N R
D _ 1 A _ 1
D _ 2 A _ 2
\vdots
D _ N A _ N

出力

N 回の ARC を終えた後の、高橋くんのレーティングを出力せよ。


入力例 1

4 1255
2 900
1 521
2 600
1 52

出力例 1

2728

はじめ、高橋くんのレーティングは 1255 です。

それぞれのコンテストで、高橋くんのレーティングは次のように変化します。

  • 1 回目の ARC は Div. 2 です。高橋くんはレーティング更新の対象なので、高橋くんのレーティングは 1255+900=2155 になります。
  • 2 回目の ARC は Div. 1 です。高橋くんはレーティング更新の対象なので、高橋くんのレーティングは 2155+521=2676 になります。
  • 3 回目の ARC は Div. 2 です。高橋くんはレーティング更新の対象ではないので、高橋くんのレーティングは変化しません。
  • 4 回目の ARC は Div. 1 です。高橋くんはレーティング更新の対象なので、高橋くんのレーティングは 2676+52=2728 になります。

4 回の ARC を終えた後、高橋くんのレーティングは 2728 となっているので、2728 を出力してください。


入力例 2

2 3031
1 1000
2 -1000

出力例 2

3031

高橋くんはレッドコーダーなので、ARC でどのような成績を取ってもレーティングは変動しません。


入力例 3

15 2352
2 -889
2 420
2 -275
1 957
1 -411
1 -363
1 151
2 -193
2 289
2 -770
2 109
1 345
2 551
1 -702
1 355

出力例 3

1226

Score : 200 points

Problem Statement

AtCoder Regular Contest (ARC) is divided into two divisions.

  • In ARC Div. 1, participants whose rating at the start of the contest is between 1600 and 2799, inclusive, are subject to rating updates.
  • In ARC Div. 2, participants whose rating at the start of the contest is between 1200 and 2399, inclusive, are subject to rating updates.

Takahashi decided to participate in N ARCs.

Initially, his rating is R.

The i-th (1\leq i\leq N) ARC is Div. D _ i, and his performance in that contest is represented by an integer A _ i.

If he is subject to a rating update in the i-th ARC, let T be his rating at the start of that contest. Then, after the contest, his rating becomes T+A _ i.

If his is not subject to a rating update, his rating does not change.

Rating updates for ARCs are performed immediately after the contest ends, and whether he is subject to rating updates in the next contest is determined based on his rating after the update.

Find his rating after finishing the N ARCs.

He does not participate in any contests other than these N ARCs, and his rating does not change in other ways.

Constraints

  • 1\leq N\leq 100
  • 0\leq R\leq 4229
  • 1\leq D _ i\leq 2\ (1\leq i\leq N)
  • -1000\leq A _ i\leq 1000\ (1\leq i\leq N)
  • All input values are integers.

Input

The input is given in the following format from Standard Input:

N R
D _ 1 A _ 1
D _ 2 A _ 2
\vdots
D _ N A _ N

Output

Print Takahashi's rating after finishing the N ARCs.


Sample Input 1

4 1255
2 900
1 521
2 600
1 52

Sample Output 1

2728

Initially, Takahashi's rating is 1255.

For each contest, Takahashi's rating changes as follows:

  • The 1st ARC is Div. 2. He is subject to rating updates, so his rating becomes 1255+900=2155.
  • The 2nd ARC is Div. 1. He is subject to rating updates, so his rating becomes 2155+521=2676.
  • The 3rd ARC is Div. 2. He is not subject to rating updates, so his rating does not change.
  • The 4th ARC is Div. 1. He is subject to rating updates, so his rating becomes 2676+52=2728.

After the four ARCs, his rating is 2728, so print 2728.


Sample Input 2

2 3031
1 1000
2 -1000

Sample Output 2

3031

He is a Red coder, so his rating does not change upon his performance in ARC.


Sample Input 3

15 2352
2 -889
2 420
2 -275
1 957
1 -411
1 -363
1 151
2 -193
2 289
2 -770
2 109
1 345
2 551
1 -702
1 355

Sample Output 3

1226
E - Σ

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

配点 : 250 点

問題文

長さ N の正整数列 A=(A_1,A_2,\dots,A_N) および正整数 K が与えられます。

1 以上 K 以下の整数のうち、A の中に一度も現れないものの総和を求めてください。

制約

  • 1\leq N \leq 2\times 10^5
  • 1\leq K \leq 2\times 10^9
  • 1\leq A_i \leq 2\times 10^9
  • 入力は全て整数

入力

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

N K
A_1 A_2 \dots A_N

出力

答えを出力せよ。


入力例 1

4 5
1 6 3 1

出力例 1

11

1 以上 5 以下の整数のうち、A の中に一度も現れないものは 2,4,5 の 3 つです。

よって、それらの総和である 2+4+5=11 を出力します。


入力例 2

1 3
346

出力例 2

6

入力例 3

10 158260522
877914575 24979445 623690081 262703497 24979445 1822804784 1430302156 1161735902 923078537 1189330739

出力例 3

12523196466007058

Score: 250 points

Problem Statement

You are given a sequence of positive integers A=(A_1,A_2,\dots,A_N) of length N and a positive integer K.

Find the sum of the integers between 1 and K, inclusive, that do not appear in the sequence A.

Constraints

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

Input

The input is given from Standard Input in the following format:

N K
A_1 A_2 \dots A_N

Output

Print the answer.


Sample Input 1

4 5
1 6 3 1

Sample Output 1

11

Among the integers between 1 and 5, three numbers, 2, 4, and 5, do not appear in A.

Thus, print their sum: 2+4+5=11.


Sample Input 2

1 3
346

Sample Output 2

6

Sample Input 3

10 158260522
877914575 24979445 623690081 262703497 24979445 1822804784 1430302156 1161735902 923078537 1189330739

Sample Output 3

12523196466007058