A - Count Takahashi

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100

問題文

文字列が N 個与えられます。

i 番目 (1\leq i\leq N) に与えられる文字列 S _ iTakahashiAoki のどちらかと等しいです。

S _ iTakahashi と等しい i がいくつあるか求めてください。

制約

  • 1\leq N\leq 100
  • N は整数
  • S _ iTakahashiAoki のいずれか (1\leq i\leq N)

入力

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

N
S _ 1
S _ 2
\vdots
S _ N

出力

S _ iTakahashi と等しい i の個数を整数として一行に出力せよ。


入力例 1

3
Aoki
Takahashi
Takahashi

出力例 1

2

S _ 2,S _ 32 つが Takahashi と等しく、S _ 1 はそうではありません。

よって、2 を出力してください。


入力例 2

2
Aoki
Aoki

出力例 2

0

Takahashi と等しい S _ i が存在しないこともあります。


入力例 3

20
Aoki
Takahashi
Takahashi
Aoki
Aoki
Aoki
Aoki
Takahashi
Aoki
Aoki
Aoki
Takahashi
Takahashi
Aoki
Takahashi
Aoki
Aoki
Aoki
Aoki
Takahashi

出力例 3

7

Score : 100 points

Problem Statement

You are given N strings.

The i-th string S_i (1 \leq i \leq N) is either Takahashi or Aoki.

How many i are there such that S_i is equal to Takahashi?

Constraints

  • 1 \leq N \leq 100
  • N is an integer.
  • Each S_i is Takahashi or Aoki. (1 \leq i \leq N)

Input

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

N
S_1
S_2
\vdots
S_N

Output

Print the count of i such that S_i is equal to Takahashi as an integer in a single line.


Sample Input 1

3
Aoki
Takahashi
Takahashi

Sample Output 1

2

S_2 and S_3 are equal to Takahashi, while S_1 is not.

Therefore, print 2.


Sample Input 2

2
Aoki
Aoki

Sample Output 2

0

It is possible that no S_i is equal to Takahashi.


Sample Input 3

20
Aoki
Takahashi
Takahashi
Aoki
Aoki
Aoki
Aoki
Takahashi
Aoki
Aoki
Aoki
Takahashi
Takahashi
Aoki
Takahashi
Aoki
Aoki
Aoki
Aoki
Takahashi

Sample Output 3

7
B - Full House 2

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100

問題文

4 枚のカードがあり、それぞれのカードには整数 A,B,C,D が書かれています。
ここに 1 枚カードを加え、フルハウスとできるか判定してください。

ただし、 5 枚組のカードは以下の条件を満たすとき、またそのときに限って、フルハウスであると呼ばれます。

  • 異なる整数 x,y について、 x が書かれたカード 3 枚と y が書かれたカード 2 枚からなる。

制約

  • 入力は全て整数
  • 1 \le A,B,C,D \le 13

入力

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

A B C D

出力

1 枚カードを加えてフルハウスとできる場合は Yes 、そうでないときは No と出力せよ。


入力例 1

7 7 7 1

出力例 1

Yes

7,7,7,11 を加えた時、フルハウスとなります。


入力例 2

13 12 11 10

出力例 2

No

13,12,11,10 に何を加えてもフルハウスにはなりません。


入力例 3

3 3 5 5

出力例 3

Yes

3,3,5,53 を加えた時、フルハウスとなります。
また、 5 を加えてもフルハウスとなります。


入力例 4

8 8 8 8

出力例 4

No

8,8,8,8 に何を加えてもフルハウスにはなりません。
同じ 5 枚のカードはフルハウスではないことに注意してください。


入力例 5

1 3 4 1

出力例 5

No

Score : 100 points

Problem Statement

There are four cards with integers A,B,C,D written on them.
Determine whether a Full House can be formed by adding one card.

A set of five cards is called a Full House if and only if the following condition is satisfied:

  • For two distinct integers x and y, there are three cards with x written on them and two cards with y written on them.

Constraints

  • All input values are integers.
  • 1 \le A,B,C,D \le 13

Input

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

A B C D

Output

If adding one card can form a Full House, print Yes; otherwise, print No.


Sample Input 1

7 7 7 1

Sample Output 1

Yes

Adding 1 to 7,7,7,1 forms a Full House.


Sample Input 2

13 12 11 10

Sample Output 2

No

Adding anything to 13,12,11,10 does not form a Full House.


Sample Input 3

3 3 5 5

Sample Output 3

Yes

Adding 3,3,5,5 to 3 forms a Full House.
Also, adding 5 forms a Full House.


Sample Input 4

8 8 8 8

Sample Output 4

No

Adding anything to 8,8,8,8 does not form a Full House.
Note that five identical cards do not form a Full House.


Sample Input 5

1 3 4 1

Sample Output 5

No
C - Substring

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

英小文字からなる文字列 S が与えられます。S の空でない部分文字列は何種類ありますか?

ただし、部分文字列とは連続する部分列のことを指します。例えば、xxxyxxxy の部分文字列ですが、xxyxx の部分文字列ではありません。

制約

  • S は英小文字からなる長さ 1 以上 100 以下の文字列

入力

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

S

出力

答えを出力せよ。


入力例 1

yay

出力例 1

5

S の空でない部分文字列は以下の 5 種類です。

  • a
  • y
  • ay
  • ya
  • yay

入力例 2

aababc

出力例 2

17

入力例 3

abracadabra

出力例 3

54

Score: 200 points

Problem Statement

You are given a string S consisting of lowercase English letters. How many different non-empty substrings does S have?

A substring is a contiguous subsequence. For example, xxx is a substring of yxxxy but not of xxyxx.

Constraints

  • S is a string of length between 1 and 100, inclusive, consisting of lowercase English letters.

Input

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

S

Output

Print the answer.


Sample Input 1

yay

Sample Output 1

5

S has the following five different non-empty substrings:

  • a
  • y
  • ay
  • ya
  • yay

Sample Input 2

aababc

Sample Output 2

17

Sample Input 3

abracadabra

Sample Output 3

54
D - Broken Rounding

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

非負整数 X に対し、 i=0,1,\dots,K-1 の順に次の操作を行ったとき、操作を全て終えた時点での X を求めてください。

  • X10^i の位以下を四捨五入する。
    • 厳密には、 X を「 |Y-X| が最小となる 10^{i+1} の倍数のうち最大のもの」である Y に置き換える。
    • 具体例を挙げる。
      • 27310^1 の位以下を四捨五入すれば 300 となる。
      • 99910^2 の位以下を四捨五入すれば 1000 となる。
      • 10010^9 の位以下を四捨五入すれば 0 となる。
      • 101510^0 の位以下を四捨五入すれば 1020 となる。

制約

  • X,K は整数
  • 0 \le X < 10^{15}
  • 1 \le K \le 15

入力

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

X K

出力

答えを整数として出力せよ。


入力例 1

2048 2

出力例 1

2100

操作の過程で、 X2048 \rightarrow 2050 \rightarrow 2100 と変化します。


入力例 2

1 15

出力例 2

0

入力例 3

999 3

出力例 3

1000

入力例 4

314159265358979 12

出力例 4

314000000000000

X32bit 整数型に収まらない可能性があります。

Score : 200 points

Problem Statement

Given a non-negative integer X, perform the following operation for i=1,2,\dots,K in this order and find the resulting X.

  • Round X off to the nearest 10^i.
    • Formally, replace X with Y that is "the largest multiple of 10^i that minimizes |Y-X|."
    • Here are some examples:
      • Rounding 273 off to the nearest 10^2 yields 300.
      • Rounding 999 off to the nearest 10^3 yields 1000.
      • Rounding 100 off to the nearest 10^{10} yields 0.
      • Rounding 1015 off to the nearest 10^1 yields 1020.

Constraints

  • X and K are integers.
  • 0 \le X < 10^{15}
  • 1 \le K \le 15

Input

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

X K

Output

Print the answer as an integer.


Sample Input 1

2048 2

Sample Output 1

2100

X changes as 2048 \rightarrow 2050 \rightarrow 2100 by the operations.


Sample Input 2

1 15

Sample Output 2

0

Sample Input 3

999 3

Sample Output 3

1000

Sample Input 4

314159265358979 12

Sample Output 4

314000000000000

X may not fit into a 32-bit integer type.

E - Standings

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

1 から N の番号が付いた N 人がコイントスを何回かしました。人 iA_i 回表を出し、B_i 回裏を出したこと分かっています。

i のコイントスの 成功率\displaystyle\frac{A_i}{A_i+B_i} で定義されます。人 1,\ldots,N の番号を、成功率の高い順に並び替えてください。成功率が同じ人が複数いる場合、その中では人の番号が小さい順になるように並び替えてください。

制約

  • 2\leq N \leq 2\times 10^5
  • 0\leq A_i, B_i\leq 10^9
  • A_i+B_i \geq 1
  • 入力される数値は全て整数

入力

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

N
A_1 B_1
\vdots
A_N B_N

出力

1,\ldots,N の番号を成功率の高い順に空白区切りで出力せよ。成功率が同じ人の番号は昇順に並び替えて出力せよ。


入力例 1

3
1 3
3 1
2 2

出力例 1

2 3 1

1 の成功率は 0.25、人 2 の成功率は 0.75、人 3 の成功率は 0.5 です。

成功率の高い順に並び替えると出力例の順番になります。


入力例 2

2
1 3
2 6

出力例 2

1 2

1,2 は成功率が同じなので、番号の昇順に出力することに注意してください。


入力例 3

4
999999999 1000000000
333333333 999999999
1000000000 999999997
999999998 1000000000

出力例 3

3 1 4 2

Score : 300 points

Problem Statement

N people numbered 1 through N tossed a coin several times. We know that person i's tosses resulted in A_i heads and B_i tails.

Person i's success rate of the tosses is defined by \displaystyle\frac{A_i}{A_i+B_i}. Sort people 1,\ldots,N in descending order of their success rates, with ties broken in ascending order of their assigned numbers.

Constraints

  • 2\leq N \leq 2\times 10^5
  • 0\leq A_i, B_i\leq 10^9
  • A_i+B_i \geq 1
  • All input values are integers.

Input

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

N
A_1 B_1
\vdots
A_N B_N

Output

Print the numbers of people 1,\ldots,N in descending order of their success rates, with ties broken in ascending order of their assigned numbers.


Sample Input 1

3
1 3
3 1
2 2

Sample Output 1

2 3 1

Person 1's success rate is 0.25, person 2's is 0.75, and person 3's is 0.5.

Sort them in descending order of their success rates to obtain the order in Sample Output.


Sample Input 2

2
1 3
2 6

Sample Output 2

1 2

Note that person 1 and 2 should be printed in ascending order of their numbers, as they have the same success rates.


Sample Input 3

4
999999999 1000000000
333333333 999999999
1000000000 999999997
999999998 1000000000

Sample Output 3

3 1 4 2