A - Trapezoids

Time Limit: 2 sec / Memory Limit: 256 MB

配点 : 100

問題文

上底の長さが a、下底の長さが b、高さが h の台形があります。

台形の例

この台形の面積を求めてください。

制約

  • 1 \leq a \leq 100
  • 1 \leq b \leq 100
  • 1 \leq h \leq 100
  • 入力で与えられる値はすべて整数
  • h は偶数

入力

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

a
b
h

出力

台形の面積を整数で出力せよ。面積が整数になることは保障されている。


入力例 1

3
4
2

出力例 1

7

上底の長さ 3、下底の長さ 4、高さ 2 の台形の面積は、 (3+4)×2/2 = 7 です。


入力例 2

4
4
4

出力例 2

16

この例で与えられるのは平行四辺形ですが、平行四辺形も台形です。

Score : 100 points

Problem Statement

You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively.

An example of a trapezoid

Find the area of this trapezoid.

Constraints

  • 1≦a≦100
  • 1≦b≦100
  • 1≦h≦100
  • All input values are integers.
  • h is even.

Input

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

a
b
h

Output

Print the area of the given trapezoid. It is guaranteed that the area is an integer.


Sample Input 1

3
4
2

Sample Output 1

7

When the lengths of the upper base, lower base, and height are 3, 4, and 2, respectively, the area of the trapezoid is (3+4)×2/2 = 7.


Sample Input 2

4
4
4

Sample Output 2

16

In this case, a parallelogram is given, which is also a trapezoid.

B - Card Game for Three (ABC Edit)

Time Limit: 2 sec / Memory Limit: 256 MB

配点 : 200

問題文

A さん、B さん、C さんの 3 人が以下のようなカードゲームをプレイしています。

  • 最初、3 人はそれぞれ abc いずれかの文字が書かれたカードを、何枚か持っている。これらは入力で与えられた順番に持っており、途中で並べ替えたりしない。
  • A さんのターンから始まる。
  • 現在自分のターンである人がカードを 1 枚以上持っているならば、そのうち先頭のカードを捨てる。その後、捨てられたカードに書かれているアルファベットと同じ名前の人 (例えば、カードに a と書かれていたならば A さん) のターンとなる。
  • 現在自分のターンである人がカードを 1 枚も持っていないならば、その人がゲームの勝者となり、ゲームは終了する。

3 人が最初に持っているカードがそれぞれ先頭から順に与えられます。 具体的には、文字列 S_AS_BS_C が与えられます。文字列 S_Ai 文字目 ( 1 \leq i \leq |S_A| ) に書かれている文字が、A さんの持っている中で先頭から i 番目のカードに 書かれている文字です。文字列 S_BS_C についても同様です。

最終的に誰がこのゲームの勝者となるかを求めてください。

制約

  • 1 \leq |S_A| \leq 100
  • 1 \leq |S_B| \leq 100
  • 1 \leq |S_C| \leq 100
  • S_AS_BS_C に含まれる文字はそれぞれ abc のいずれか

入力

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

S_A
S_B
S_C

出力

A さんが勝つなら A、B さんが勝つなら B、C さんが勝つなら C と出力せよ。


入力例 1

aca
accc
ca

出力例 1

A

ゲームは以下のように進行します。

  • A さんが、持っている中で最初のカード a を捨てる。次は A さんの番となる。
  • A さんが、持っている中で最初のカード c を捨てる。次は C さんの番となる。
  • C さんが、持っている中で最初のカード c を捨てる。次は C さんの番となる。
  • C さんが、持っている中で最初のカード a を捨てる。次は A さんの番となる。
  • A さんが、持っている中で最初のカード a を捨てる。次は A さんの番となる。
  • A さんはもう持っているカードがない。よって A さんの勝利となり、ゲームは終了する。

入力例 2

abcb
aacb
bccc

出力例 2

C

Score : 200 points

Problem Statement

Alice, Bob and Charlie are playing Card Game for Three, as below:

  • At first, each of the three players has a deck consisting of some number of cards. Each card has a letter a, b or c written on it. The orders of the cards in the decks cannot be rearranged.
  • The players take turns. Alice goes first.
  • If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says a, Alice takes the next turn.)
  • If the current player's deck is empty, the game ends and the current player wins the game.

You are given the initial decks of the players. More specifically, you are given three strings S_A, S_B and S_C. The i-th (1≦i≦|S_A|) letter in S_A is the letter on the i-th card in Alice's initial deck. S_B and S_C describes Bob's and Charlie's initial decks in the same way.

Determine the winner of the game.

Constraints

  • 1≦|S_A|≦100
  • 1≦|S_B|≦100
  • 1≦|S_C|≦100
  • Each letter in S_A, S_B, S_C is a, b or c.

Input

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

S_A
S_B
S_C

Output

If Alice will win, print A. If Bob will win, print B. If Charlie will win, print C.


Sample Input 1

aca
accc
ca

Sample Output 1

A

The game will progress as below:

  • Alice discards the top card in her deck, a. Alice takes the next turn.
  • Alice discards the top card in her deck, c. Charlie takes the next turn.
  • Charlie discards the top card in his deck, c. Charlie takes the next turn.
  • Charlie discards the top card in his deck, a. Alice takes the next turn.
  • Alice discards the top card in her deck, a. Alice takes the next turn.
  • Alice's deck is empty. The game ends and Alice wins the game.

Sample Input 2

abcb
aacb
bccc

Sample Output 2

C
C - Many Formulas

Time Limit: 2 sec / Memory Limit: 256 MB

配点 : 300

問題文

1 以上 9 以下の数字のみからなる文字列 S が与えられます。 この文字列の中で、あなたはこれら文字と文字の間のうち、いくつかの場所に + を入れることができます。 一つも入れなくてもかまいません。 ただし、+ が連続してはいけません。

このようにして出来る全ての文字列を数式とみなし、和を計算することができます。

ありうる全ての数式の値を計算し、その合計を出力してください。

制約

  • 1 \leq |S| \leq 10
  • S に含まれる文字は全て 19 の数字

入力

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

S

出力

ありうる全ての数式の値の総和を 1 行に出力せよ。


入力例 1

125

出力例 1

176

考えられる数式としては、 1251+2512+51+2+54 通りがあります。それぞれの数式を計算すると、

  • 125
  • 1+25=26
  • 12+5=17
  • 1+2+5=8

となり、これらの総和は 125+26+17+8=176 となります。


入力例 2

9999999999

出力例 2

12656242944

Score : 300 points

Problem Statement

You are given a string S consisting of digits between 1 and 9, inclusive. You can insert the letter + into some of the positions (possibly none) between two letters in this string. Here, + must not occur consecutively after insertion.

All strings that can be obtained in this way can be evaluated as formulas.

Evaluate all possible formulas, and print the sum of the results.

Constraints

  • 1 \leq |S| \leq 10
  • All letters in S are digits between 1 and 9, inclusive.

Input

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

S

Output

Print the sum of the evaluated value over all possible formulas.


Sample Input 1

125

Sample Output 1

176

There are 4 formulas that can be obtained: 125, 1+25, 12+5 and 1+2+5. When each formula is evaluated,

  • 125
  • 1+25=26
  • 12+5=17
  • 1+2+5=8

Thus, the sum is 125+26+17+8=176.


Sample Input 2

9999999999

Sample Output 2

12656242944
D - Snuke's Coloring

Time Limit: 3 sec / Memory Limit: 256 MB

配点 : 400

問題文

H 行、横 W 列のマス目からなる盤があります。最初、どのマス目も白く塗られています。

すぬけ君が、このうち N マスを黒く塗りつぶしました。i 回目 ( 1 \leq i \leq N ) に塗りつぶしたのは、 上から a_i 行目で左から b_i 列目のマスでした。

すぬけ君がマス目を塗りつぶした後の盤の状態について、以下のものの個数を計算してください。

  • 各整数 j ( 0 \leq j \leq 9 ) について、盤の中に完全に含まれるすべての 33 列の連続するマス目のうち、黒いマスがちょうど j 個あるもの。

制約

  • 3 \leq H \leq 10^9
  • 3 \leq W \leq 10^9
  • 0 \leq N \leq min(10^5,H×W)
  • 1 \leq a_i \leq H (1 \leq i \leq N)
  • 1 \leq b_i \leq W (1 \leq i \leq N)
  • (a_i, b_i) \neq (a_j, b_j) (i \neq j)

入力

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

H W N
a_1 b_1
:
a_N b_N

出力

出力は 10 行からなる。 j+1 行目 ( 0 \leq j \leq 9 ) には、盤の中に完全に含まれるすべての 33 列の連続するマス目のうち、黒いマスがちょうど j 個あるものの 総数を出力せよ。


入力例 1

4 5 8
1 1
1 4
1 5
2 3
3 1
3 2
3 4
4 4

出力例 1

0
0
0
2
4
0
0
0
0
0

この盤に含まれる 3×3 の正方形は全部で 6 個ありますが、これらのうち 2 個の内部には黒いマスが 3 個、残りの 4 個の内部には黒いマスが 4 個含まれています。


入力例 2

10 10 20
1 1
1 4
1 9
2 5
3 10
4 2
4 7
5 9
6 4
6 6
6 7
7 1
7 3
7 7
8 1
8 5
8 10
9 2
10 4
10 9

出力例 2

4
26
22
10
2
0
0
0
0
0

入力例 3

1000000000 1000000000 0

出力例 3

999999996000000004
0
0
0
0
0
0
0
0
0

Score : 400 points

Problem Statement

We have a grid with H rows and W columns. At first, all cells were painted white.

Snuke painted N of these cells. The i-th ( 1 \leq i \leq N ) cell he painted is the cell at the a_i-th row and b_i-th column.

Compute the following:

  • For each integer j ( 0 \leq j \leq 9 ), how many subrectangles of size 3×3 of the grid contains exactly j black cells, after Snuke painted N cells?

Constraints

  • 3 \leq H \leq 10^9
  • 3 \leq W \leq 10^9
  • 0 \leq N \leq min(10^5,H×W)
  • 1 \leq a_i \leq H (1 \leq i \leq N)
  • 1 \leq b_i \leq W (1 \leq i \leq N)
  • (a_i, b_i) \neq (a_j, b_j) (i \neq j)

Input

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

H W N
a_1 b_1
:
a_N b_N

Output

Print 10 lines. The (j+1)-th ( 0 \leq j \leq 9 ) line should contain the number of the subrectangles of size 3×3 of the grid that contains exactly j black cells.


Sample Input 1

4 5 8
1 1
1 4
1 5
2 3
3 1
3 2
3 4
4 4

Sample Output 1

0
0
0
2
4
0
0
0
0
0

There are six subrectangles of size 3×3. Two of them contain three black cells each, and the remaining four contain four black cells each.


Sample Input 2

10 10 20
1 1
1 4
1 9
2 5
3 10
4 2
4 7
5 9
6 4
6 6
6 7
7 1
7 3
7 7
8 1
8 5
8 10
9 2
10 4
10 9

Sample Output 2

4
26
22
10
2
0
0
0
0
0

Sample Input 3

1000000000 1000000000 0

Sample Output 3

999999996000000004
0
0
0
0
0
0
0
0
0