atcoder#ABC256B. [ABC256B] Batters
[ABC256B] Batters
Score : points
Problem Statement
Takahashi is trying to create a game inspired by baseball, but he is having difficulty writing the code. Write a program for Takahashi that solves the following problem.
There are squares called Square , Square , Square , and Square . Initially, all squares are empty. There is also an integer ; initially, . Given a sequence of positive integers , perform the following operations for in this order:
- Put a piece on Square .
- Advance every piece on the squares squares ahead. In other words, if Square has a piece, move the piece to Square .
If, however, the destination square does not exist (i.e. is greater than or equal to ) for a piece, remove it. Add to the number of pieces that have been removed.
Print the value of after all the operations have been performed.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the value of after all the operations have been performed.
4
1 1 3 2
3
The operations are described below. After all the operations have been performed, equals .
- The operations for : 1. Put a piece on Square . Now, Square has a piece. 2. Advance every piece on the squares square ahead. After these moves, Square has a piece.
- The operations for : 1. Put a piece on Square . Now, Squares and have a piece. 2. Advance every piece on the squares square ahead. After these moves, Squares and have a piece.
- The operations for : 1. Put a piece on Square . Now, Squares , , and have a piece. 2. Advance every piece on the squares squares ahead. Here, for the pieces on Squares and , the destination squares do not exist (since and ), so remove these pieces and add to . now equals . After these moves, Square has a piece.
- The operations for : 1. Put a piece on Square . Now, Squares and have a piece. 2. Advance every piece on the squares squares ahead. Here, for the piece on Square , the destination square does not exist (since ), so remove this piece and add to . now equals . After these moves, Square has a piece.
3
1 1 1
0
The value of may not be updated by the operations.
10
2 2 4 1 1 1 4 2 2 1
8