A - Five Integers

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100

問題文

与えられる 5 つの整数 A, B, C, D, E の中に何種類の整数があるかを出力してください。

制約

  • 0 \leq A, B, C, D, E \leq 100
  • 入力はすべて整数

入力

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

A B C D E

出力

答えを出力せよ。


入力例 1

31 9 24 31 24

出力例 1

3

与えられる 5 つの整数 31, 9, 24, 31, 24 の中には、9, 24, 31 という 3 種類の整数があります。 よって、3 を出力します。


入力例 2

0 0 0 0 0

出力例 2

1

Score : 100 points

Problem Statement

Print how many distinct integers there are in given five integers A, B, C, D, and E.

Constraints

  • 0 \leq A, B, C, D, E \leq 100
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B C D E

Output

Print the answer.


Sample Input 1

31 9 24 31 24

Sample Output 1

3

In the given five integers 31, 9, 24, 31, and 24, there are three distinct integers 9, 24, and 31. Thus, 3 should be printed.


Sample Input 2

0 0 0 0 0

Sample Output 2

1
B - Rightmost

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100

問題文

英小文字からなる文字列 S が与えられます。
Sa が現れるならば最後に現れるのが何文字目かを出力し、現れないならば -1 を出力してください。

制約

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

入力

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

S

出力

答えを出力せよ。


入力例 1

abcdaxayz

出力例 1

7

Sa3 回現れますが、最後に現れるのは 7 文字目なので、7 を出力します。


入力例 2

bcbbbz

出力例 2

-1

Sa は現れないので、-1 を出力します。


入力例 3

aaaaa

出力例 3

5

Score : 100 points

Problem Statement

You are given a string S consisting of lowercase English letters.
If a appears in S, print the last index at which it appears; otherwise, print -1. (The index starts at 1.)

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

abcdaxayz

Sample Output 1

7

a appears three times in S. The last occurrence is at index 7, so you should print 7.


Sample Input 2

bcbbbz

Sample Output 2

-1

a does not appear in S, so you should print -1.


Sample Input 3

aaaaa

Sample Output 3

5
C - Avoid Rook Attack

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

8 マス、横 8 マスの 64 マスからなるマス目があります。 上から i 行目 (1\leq i\leq8) 、左から j 列目 (1\leq j\leq8) のマスをマス (i,j) と呼ぶことにします。

それぞれのマスは、空マスであるかコマが置かれているかのどちらかです。 マスの状態は長さ 8 の文字列からなる長さ 8 の列 (S _ 1,S _ 2,S _ 3,\ldots,S _ 8) で表されます。 マス (i,j) (1\leq i\leq8,1\leq j\leq8) は、S _ ij 文字目が . のとき空マスで、# のときコマが置かれています。

あなたは、すでに置かれているどのコマにも取られないように、いずれかの空マスに自分のコマを置きたいです。

マス (i,j) に置かれているコマは、次のどちらかの条件を満たすコマを取ることができます。

  • i 行目のマスに置かれている
  • j 列目のマスに置かれている

たとえば、マス (4,4) に置かれているコマは、以下の図で青く示されたマスに置かれているコマを取ることができます。

あなたがコマを置くことができるマスがいくつあるか求めてください。

制約

  • S _ i., # からなる長さ 8 の文字列 (1\leq i\leq 8)

入力

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

S _ 1
S _ 2
S _ 3
S _ 4
S _ 5
S _ 6
S _ 7
S _ 8

出力

すでに置かれているコマに取られずに自分のコマを置くことができる空マスの個数を出力せよ。


入力例 1

...#....
#.......
.......#
....#...
.#......
........
........
..#.....

出力例 1

4

すでに置かれているコマは、以下の図で青く示されたマスに置かれたコマを取ることができます。

よって、あなたがすでに置かれているコマに取られないように自分のコマを置くことができるマスはマス (6,6), マス (6,7), マス (7,6), マス (7,7)4 マスです。


入力例 2

........
........
........
........
........
........
........
........

出力例 2

64

コマがひとつも置かれていないこともあります。


入力例 3

.#......
..#..#..
....#...
........
..#....#
........
...#....
....#...

出力例 3

4

Score : 200 points

Problem Statement

There is a grid of 64 squares with 8 rows and 8 columns. Let (i,j) denote the square at the i-th row from the top (1\leq i\leq8) and j-th column from the left (1\leq j\leq8).

Each square is either empty or has a piece placed on it. The state of the squares is represented by a sequence (S_1,S_2,S_3,\ldots,S_8) of 8 strings of length 8. Square (i,j) (1\leq i\leq8,1\leq j\leq8) is empty if the j-th character of S_i is ., and has a piece if it is #.

You want to place your piece on an empty square in such a way that it cannot be captured by any of the existing pieces.

A piece placed on square (i,j) can capture pieces that satisfy either of the following conditions:

  • Placed on a square in row i
  • Placed on a square in column j

For example, a piece placed on square (4,4) can capture pieces placed on the squares shown in blue in the following figure:

How many squares can you place your piece on?

Constraints

  • Each S_i is a string of length 8 consisting of . and # (1\leq i\leq 8).

Input

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

S_1
S_2
S_3
S_4
S_5
S_6
S_7
S_8

Output

Print the number of empty squares where you can place your piece without it being captured by any existing pieces.


Sample Input 1

...#....
#.......
.......#
....#...
.#......
........
........
..#.....

Sample Output 1

4

The existing pieces can capture pieces placed on the squares shown in blue in the following figure:

Therefore, you can place your piece without it being captured on 4 squares: square (6,6), square (6,7), square (7,6), and square (7,7).


Sample Input 2

........
........
........
........
........
........
........
........

Sample Output 2

64

There may be no pieces on the grid.


Sample Input 3

.#......
..#..#..
....#...
........
..#....#
........
...#....
....#...

Sample Output 3

4
D - Get Min

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

中に何も入っていない袋があります。

Q 個のクエリが与えられるので、これらのクエリを順に処理したときのタイプ 2 の各クエリの答えを出力してください。

各クエリは、以下のいずれかの形式です。

  • タイプ 1 : 1 x の形式で入力として与えられる。整数 x が書かれたボールを 1 つ袋の中に入れる。

  • タイプ 2 : 2 の形式で入力として与えられる。袋に入っているボールのうち書かれている整数が最小のものを 1 つ取り出し、その整数を答えとする。ただし、袋の中にボールが入っていないときにはこのクエリは与えられない。

制約

  • 2 \leq Q \leq 100
  • タイプ 1 のクエリにおいて、1 \leq x \leq 100
  • タイプ 2 のクエリが与えられたとき、袋は空ではない
  • タイプ 2 のクエリが 1 つ以上与えられる
  • 入力される値はすべて整数

入力

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

Q 
\text{query}_1
\text{query}_2
\ldots
\text{query}_Q

ただし、\text{query}_ii 番目のクエリであり、以下のいずれかの形式で与えられる。

1 x
2

出力

タイプ 2 のクエリの個数を q として、q 行出力せよ。

i 行目には、i 番目のタイプ 2 のクエリの答えを出力せよ。


入力例 1

5
1 6
1 7
2
1 1
2

出力例 1

6
1

はじめ、袋の中にボールは入っていません。

1 番目のクエリでは、袋の中に 6 が書かれたボールを入れます。

2 番目のクエリでは、袋の中に 7 が書かれたボールを入れます。

3 番目のクエリでは、袋の中には 6 が書かれたボールと 7 が書かれたボールが入っているため、6 が書かれたボールを取り出します。このクエリの答えは 6 となります。

4 番目のクエリでは、袋の中に 1 が書かれたボールを入れます。

5 番目のクエリでは、袋の中には 1 が書かれたボールと 7 が書かれたボールが入っているため、1 が書かれたボールを取り出します。このクエリの答えは 1 となります。


入力例 2

8
1 5
1 1
1 1
1 9
2
2
1 2
2

出力例 2

1
1
2

同じ整数が書かれたボールを複数個袋の中に入れることもあります。

Score : 200 points

Problem Statement

There is an empty bag.

You are given Q queries. Process these queries in order and output the answer to each type-2 query.

Each query is of one of the following types.

  • Type 1: Given as input in the format 1 x. Put a ball with the integer x written on it into the bag.

  • Type 2: Given as input in the format 2. Pick out one ball with the minimum integer written on it from the balls in the bag, and report that integer as the answer. This query is not given when the bag contains no balls.

Constraints

  • 2 \leq Q \leq 100
  • In a type-1 query, 1 \leq x \leq 100.
  • When a type-2 query is given, the bag is not empty.
  • At least one type-2 query is given.
  • All input values are integers.

Input

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

Q 
\text{query}_1
\text{query}_2
\ldots
\text{query}_Q

Here, \text{query}_i is the i-th query and is given in one of the following formats:

1 x
2

Output

Let q be the number of type-2 queries, and output q lines.

The i-th line should contain the answer to the i-th type-2 query.


Sample Input 1

5
1 6
1 7
2
1 1
2

Sample Output 1

6
1

Initially, the bag contains no balls.

The 1st query puts a ball with 6 written on it into the bag.

The 2nd query puts a ball with 7 written on it into the bag.

In the 3rd query, the bag contains a ball with 6 written on it and a ball with 7 written on it, so you pick out the ball with 6 written on it. The answer to this query is 6.

The 4th query puts a ball with 1 written on it into the bag.

In the 5th query, the bag contains a ball with 1 written on it and a ball with 7 written on it, so you pick out the ball with 1 written on it. The answer to this query is 1.


Sample Input 2

8
1 5
1 1
1 1
1 9
2
2
1 2
2

Sample Output 2

1
1
2

The bag may contain multiple balls with the same integer.

E - Perfect Bus

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 250

問題文

一台のバスが走っています。バスの乗客の数は常に非負整数です。

このバスにはある時点で 0 人以上の乗客が乗っており、その時点から現在までに N 回停車しました。このうち i 回目の停車では乗客が差し引き A_i 人増えました。A_i は負の値であることもあり、その場合は乗客が差し引き -A_i 人減ったことを意味しています。また、停車時以外には乗客の乗り降りはありませんでした。

与えられた情報に矛盾しない現在のバスの乗客の数として考えられる最小値を求めてください。

制約

  • 1 \leq N \leq 2 \times 10^5
  • -10^9 \leq A_i \leq 10^9
  • 入力される数値はすべて整数

入力

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

N
A_1 A_2 \ldots A_N

出力

答えを出力せよ。


入力例 1

4
3 -5 7 -4

出力例 1

3

はじめに乗っている乗客の人数が 2 人であるとき、現在の乗客の人数は 2 + 3 + (-5) + 7 + (-4) = 3 人であり、さらにバスの乗客の人数は常に非負整数となります。


入力例 2

5
0 0 0 0 0

出力例 2

0

入力例 3

4
-1 1000000000 1000000000 1000000000

出力例 3

3000000000

Score: 250 points

Problem Statement

A bus is in operation. The number of passengers on the bus is always a non-negative integer.

At some point in time, the bus had zero or more passengers, and it has stopped N times since then. At the i-th stop, the number of passengers increased by A_i. Here, A_i can be negative, meaning the number of passengers decreased by -A_i. Also, no passengers got on or off the bus other than at the stops.

Find the minimum possible current number of passengers on the bus that is consistent with the given information.

Constraints

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

Input

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

N
A_1 A_2 \ldots A_N

Output

Print the answer.


Sample Input 1

4
3 -5 7 -4

Sample Output 1

3

If the initial number of passengers was 2, the current number of passengers would be 2 + 3 + (-5) + 7 + (-4) = 3, and the number of passengers on the bus would have always been a non-negative integer.


Sample Input 2

5
0 0 0 0 0

Sample Output 2

0

Sample Input 3

4
-1 1000000000 1000000000 1000000000

Sample Output 3

3000000000