A - Batting Average

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100

問題文

高橋君は野球ゲームを作っています。
高橋君はバッターの打率を指定された桁数の分だけ表示するプログラムを作ることにしました。

整数 A, B があります。ここで A, B1 \leq A \leq 10, 0 \leq B \leq A を満たします。
このとき、文字列 S を次のように定義します。

  • \dfrac{B}{A} を小数点第 4 位で四捨五入した値を「整数部 1 桁」「 . 」「小数部 3 桁」の順に末尾ゼロを省略せずに表記した文字列。

例えば A=7, B = 4 の場合は、\dfrac{B}{A} = \dfrac{4}{7} = 0.571428\dots で、これを小数点第 4 位で四捨五入した値は 0.571 です。よって S0.571 になります。

A, B が入力として与えられるので S を出力してください。

制約

  • 1 \leq A \leq 10
  • 0 \leq B \leq A
  • A, B は整数

入力

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

A B

出力

S を問題文の指示に従った形式で出力せよ。問題文の指示と異なる形式で出力した場合は誤答となることに注意せよ。


入力例 1

7 4

出力例 1

0.571

問題文本文でも説明した通り、\dfrac{B}{A} = \dfrac{4}{7} = 0.571428\dots で、これを小数点第 4 位で四捨五入した値は 0.571 です。よって S0.571 になります。


入力例 2

7 3

出力例 2

0.429

\dfrac{B}{A} = \dfrac{3}{7} = 0.428571\dots で、これを小数点第 4 位で四捨五入した値は 0.429 です。(繰り上がりが発生するのに注意してください。)
よって S0.429 となります。


入力例 3

2 1

出力例 3

0.500

\dfrac{B}{A} = \dfrac{1}{2} = 0.5 で、これを小数点第 4 位で四捨五入した値も同様に 0.5 です。
よって S0.500 となります。小数部を 3 桁並べる必要があるのに注意してください。


入力例 4

10 10

出力例 4

1.000

入力例 5

1 0

出力例 5

0.000

Score : 100 points

Problem Statement

Takahashi is making a computer baseball game.
He will write a program that shows a batter's batting average with a specified number of digits.

There are integers A and B, which satisfy 1 \leq A \leq 10 and 0 \leq B \leq A.
Let S be the string obtained as follows.

  • Round off \dfrac{B}{A} to three decimal digits, then write the integer part (1 digit), . (the decimal point), and the decimal part (3 digits) in this order, with trailing zeros.

For example, if A=7 and B=4, then \dfrac{B}{A} = \dfrac{4}{7} = 0.571428\dots rounded off to three decimal digits is 0.571. Thus, S is 0.571.

You are given A and B as the input and asked to print S.

Constraints

  • 1 \leq A \leq 10
  • 0 \leq B \leq A
  • A and B are integers.

Input

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

A B

Output

Print S in the format specified in the Problem Statement. Note that answers in different formats will be considered wrong.


Sample Input 1

7 4

Sample Output 1

0.571

As explained in the Problem Statement, \dfrac{B}{A} = \dfrac{4}{7} = 0.571428\dots rounded off to three decimal digits is 0.571. Thus, S is 0.571.


Sample Input 2

7 3

Sample Output 2

0.429

\dfrac{B}{A} = \dfrac{3}{7} = 0.428571\dots rounded off to three decimal digits is 0.429. (Note that it got rounded up.)
Thus, S is 0.429.


Sample Input 3

2 1

Sample Output 3

0.500

\dfrac{B}{A} = \dfrac{1}{2} = 0.5 rounded off to three decimal digits is again 0.5.
Thus, S is 0.500. Note that it must have three decimal places.


Sample Input 4

10 10

Sample Output 4

1.000

Sample Input 5

1 0

Sample Output 5

0.000
B - Unsupported Type

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100

問題文

長さ N の整数列 A=(A_1,A_2,\dots,A_N) と整数 X が与えられます。
XA に含まれるか判定してください。

制約

  • 入力は全て整数
  • 1 \le N \le 100
  • 1 \le A_i \le 100
  • 1 \le X \le 100

入力

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

N
A_1 A_2 \dots A_N
X

出力

XA に含まれるなら Yes 、含まれないなら No と出力せよ。


入力例 1

5
3 1 4 1 5
4

出力例 1

Yes

A=(3,1,4,1,5), X=4 であり、 XA に含まれます。


入力例 2

4
100 100 100 100
100

出力例 2

Yes

X が複数回 A に含まれる場合もあります。


入力例 3

6
2 3 5 7 11 13
1

出力例 3

No

Score : 100 points

Problem Statement

You are given an integer sequence A=(A_1,A_2,\dots,A_N) of length N and an integer X.
Determine whether X is contained in A.

Constraints

  • All input values are integers.
  • 1 \le N \le 100
  • 1 \le A_i \le 100
  • 1 \le X \le 100

Input

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

N
A_1 A_2 \dots A_N
X

Output

If X is contained in A, print Yes; otherwise, print No.


Sample Input 1

5
3 1 4 1 5
4

Sample Output 1

Yes

We have A=(3,1,4,1,5) and X=4; X is contained in A.


Sample Input 2

4
100 100 100 100
100

Sample Output 2

Yes

X may be contained in A multiple times.


Sample Input 3

6
2 3 5 7 11 13
1

Sample Output 3

No
C - String Too Long

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

連長圧縮(ランレングス圧縮)を復元してください。ただし、長すぎる場合には Too Long と出力してください。

N 個の文字と整数の組 (c_1,l_1),(c_2,l_2),\ldots,(c_N,l_N) が与えられます。

l_1 個の文字 c_1l_2 個の文字 c_2\ldotsl_N 個の文字 c_N をこの順に連結させた文字列を S とします。

S を出力してください。ただし、S の長さが 100 を超える場合には代わりに Too Long と出力してください。

制約

  • 1\leq N\leq 100
  • 1\leq l_i\leq 10^{18}
  • N,l_i は整数
  • c_i は英小文字
  • c_i\neq c_{i+1}

入力

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

N
c_1 l_1
c_2 l_2
\vdots
c_N l_N

出力

S の長さが 100 以下なら S を、そうでないなら Too Long と出力せよ。


入力例 1

8
m 1
i 1
s 2
i 1
s 2
i 1
p 2
i 1

出力例 1

mississippi

Smississippi です。S の長さは 100 以下であるため S を出力します。


入力例 2

7
a 1000000000000000000
t 1000000000000000000
c 1000000000000000000
o 1000000000000000000
d 1000000000000000000
e 1000000000000000000
r 1000000000000000000

出力例 2

Too Long

S の長さは 7\times 10^{18} であるため、Too Long を出力します。


入力例 3

1
a 100

出力例 3

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

入力例 4

6
g 4
j 1
m 4
e 4
d 3
i 4

出力例 4

ggggjmmmmeeeedddiiii

Score : 200 points

Problem Statement

Restore run-length encoding. If the result is too long, output Too Long.

You are given N pairs of characters and integers (c_1,l_1),(c_2,l_2),\ldots,(c_N,l_N).

Let S be the string formed by concatenating l_1 characters c_1, l_2 characters c_2, \ldots, and l_N characters c_N in this order.

Output S. However, if the length of S exceeds 100, output Too Long instead.

Constraints

  • 1\leq N\leq 100
  • 1\leq l_i\leq 10^{18}
  • N and l_i are integers.
  • Each c_i is a lowercase English letter.
  • c_i\neq c_{i+1}

Input

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

N
c_1 l_1
c_2 l_2
\vdots
c_N l_N

Output

If the length of S is at most 100, output S; otherwise, output Too Long.


Sample Input 1

8
m 1
i 1
s 2
i 1
s 2
i 1
p 2
i 1

Sample Output 1

mississippi

S is mississippi. Since the length of S is not greater than 100, output S.


Sample Input 2

7
a 1000000000000000000
t 1000000000000000000
c 1000000000000000000
o 1000000000000000000
d 1000000000000000000
e 1000000000000000000
r 1000000000000000000

Sample Output 2

Too Long

The length of S is 7\times 10^{18}, so output Too Long.


Sample Input 3

1
a 100

Sample Output 3

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

Sample Input 4

6
g 4
j 1
m 4
e 4
d 3
i 4

Sample Output 4

ggggjmmmmeeeedddiiii
D - Triangle (Easier)

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

N 頂点 M 辺の単純無向グラフが与えられます。頂点には 1, \dots, N の番号が付けられており、i \, (1 \leq i \leq M) 番目の辺は頂点 U_i と頂点 V_i を結んでいます。

以下の条件を全て満たす整数 a, b, c の組の総数を求めてください。

  • 1 \leq a \lt b \lt c \leq N
  • 頂点 a と頂点 b を結ぶ辺が存在する。
  • 頂点 b と頂点 c を結ぶ辺が存在する。
  • 頂点 c と頂点 a を結ぶ辺が存在する。

制約

  • 3 \leq N \leq 100
  • 1 \leq M \leq \frac{N(N - 1)}{2}
  • 1 \leq U_i \lt V_i \leq N \, (1 \leq i \leq M)
  • (U_i, V_i) \neq (U_j, V_j) \, (i \neq j)
  • 入力は全て整数

入力

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

N M
U_1 V_1
\vdots
U_M V_M

出力

答えを出力せよ。


入力例 1

5 6
1 5
4 5
2 3
1 4
3 5
2 5

出力例 1

2

(a, b, c) = (1, 4, 5), (2, 3, 5) が条件を満たします。


入力例 2

3 1
1 2

出力例 2

0

入力例 3

7 10
1 7
5 7
2 5
3 6
4 7
1 5
2 4
1 3
1 6
2 7

出力例 3

4

Score : 200 points

Problem Statement

You are given a simple undirected graph with N vertices and M edges. The vertices are numbered 1, \dots, N, and the i-th (1 \leq i \leq M) edge connects Vertex U_i and Vertex V_i.

Find the number of tuples of integers a, b, c that satisfy all of the following conditions:

  • 1 \leq a \lt b \lt c \leq N
  • There is an edge connecting Vertex a and Vertex b.
  • There is an edge connecting Vertex b and Vertex c.
  • There is an edge connecting Vertex c and Vertex a.

Constraints

  • 3 \leq N \leq 100
  • 1 \leq M \leq \frac{N(N - 1)}{2}
  • 1 \leq U_i \lt V_i \leq N \, (1 \leq i \leq M)
  • (U_i, V_i) \neq (U_j, V_j) \, (i \neq j)
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
U_1 V_1
\vdots
U_M V_M

Output

Print the answer.


Sample Input 1

5 6
1 5
4 5
2 3
1 4
3 5
2 5

Sample Output 1

2

(a, b, c) = (1, 4, 5), (2, 3, 5) satisfy the conditions.


Sample Input 2

3 1
1 2

Sample Output 2

0

Sample Input 3

7 10
1 7
5 7
2 5
3 6
4 7
1 5
2 4
1 3
1 6
2 7

Sample Output 3

4
E - Max - Min Query

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

整数の多重集合 S があります。はじめ S は空です。

Q 個のクエリが与えられるので順に処理してください。 クエリは次の 3 種類のいずれかです。

  • 1 x : Sx1 個追加する。

  • 2 x c : S から x\mathrm{min}(c, (S に含まれる x の個数 )) 個削除する。

  • 3 : (S の最大値 )- (S の最小値 ) を出力する。このクエリを処理するとき、 S が空でないことが保証される。

制約

  • 1 \leq Q \leq 2\times 10^5
  • 0 \leq x \leq 10^9
  • 1 \leq c \leq Q
  • 3 のクエリを処理するとき、S は空でない。
  • 入力は全て整数

入力

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

Q
\mathrm{query}_1
\vdots
\mathrm{query}_Q

i 番目のクエリを表す \mathrm{query}_i は以下の 3 種類のいずれかである。

1 x
2 x c
3 

出力

3 のクエリに対する答えを順に改行区切りで出力せよ。


入力例 1

8
1 3
1 2
3
1 2
1 7
3
2 2 3
3

出力例 1

1
5
4

多重集合 S は以下のように変化します。

  • 1 番目のクエリ : S3 を追加する。S\lbrace3 \rbrace となる。
  • 2 番目のクエリ : S2 を追加する。S\lbrace2, 3\rbrace となる。
  • 3 番目のクエリ : S = \lbrace 2, 3\rbrace の最大値は 3 、最小値は 2 なので、 3-2=1 を出力する。
  • 4 番目のクエリ : S2 を追加する。S\lbrace2,2,3 \rbrace となる。
  • 5 番目のクエリ : S7 を追加する。S\lbrace2, 2,3, 7\rbrace となる。
  • 6 番目のクエリ : S = \lbrace2,2,3, 7\rbrace の最大値は 7 、最小値は 2 なので、 7-2=5 を出力する。
  • 7 番目のクエリ : S に含まれる 2 の個数は 2 個なので、 \mathrm{min(2,3)} = 2 個の 2S から削除する。S\lbrace3, 7\rbrace となる。
  • 8 番目のクエリ : S = \lbrace3, 7\rbrace の最大値は 7 、最小値は 3 なので、 7-3=4 を出力する。

入力例 2

4
1 10000
1 1000
2 100 3
1 10

出力例 2


クエリ 3 が含まれない場合、何も出力してはいけません。

Score : 300 points

Problem Statement

We have a multiset of integers S, which is initially empty.

Given Q queries, process them in order. Each query is of one of the following types.

  • 1 x: Insert an x into S.

  • 2 x c: Remove an x from S m times, where m = \mathrm{min}(c,( the number of x's contained in S)).

  • 3 : Print ( maximum value of S)-( minimum value of S). It is guaranteed that S is not empty when this query is given.

Constraints

  • 1 \leq Q \leq 2\times 10^5
  • 0 \leq x \leq 10^9
  • 1 \leq c \leq Q
  • When a query of type 3 is given, S is not empty.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

Q
\mathrm{query}_1
\vdots
\mathrm{query}_Q

\mathrm{query}_i, which denotes the i-th query, is in one of the following formats:

1 x
2 x c
3 

Output

Print the answers for the queries of type 3 in the given order, separated by newlines.


Sample Input 1

8
1 3
1 2
3
1 2
1 7
3
2 2 3
3

Sample Output 1

1
5
4

The multiset S transitions as follows.

  • 1-st query: insert 3 into S. S is now \lbrace 3 \rbrace.
  • 2-nd query: insert 2 into S. S is now \lbrace 2, 3 \rbrace.
  • 3-rd query: the maximum value of S = \lbrace 2, 3\rbrace is 3 and its minimum value is 2, so print 3-2=1.
  • 4-th query: insert 2 into S. S is now \lbrace 2,2,3 \rbrace.
  • 5-th query: insert 7 into S. S is now \lbrace 2, 2,3, 7\rbrace.
  • 6-th query: the maximum value of S = \lbrace 2,2,3, 7\rbrace is 7 and its minimum value is 2, so print 7-2=5.
  • 7-th query: since there are two 2's in S and \mathrm{min(2,3)} = 2, remove 2 from S twice. S is now \lbrace 3, 7\rbrace.
  • 8-th query: the maximum value of S = \lbrace 3, 7\rbrace is 7 and its minimum value is 3, so print 7-3=4.

Sample Input 2

4
1 10000
1 1000
2 100 3
1 10

Sample Output 2


If the given queries do not contain that of type 3, nothing should be printed.