atcoder#ABC256B. [ABC256B] Batters

[ABC256B] Batters

Score : 200200 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 44 squares called Square 00, Square 11, Square 22, and Square 33. Initially, all squares are empty. There is also an integer PP; initially, P=0P = 0. Given a sequence of positive integers A=(A1,A2,,AN)A = (A_1, A_2, \dots, A_N), perform the following operations for i=1,2,,Ni = 1, 2, \dots, N in this order:

  1. Put a piece on Square 00.
  2. Advance every piece on the squares AiA_i squares ahead. In other words, if Square xx has a piece, move the piece to Square (x+Ai)(x + A_i).
    If, however, the destination square does not exist (i.e. x+Aix + A_i is greater than or equal to 44) for a piece, remove it. Add to PP the number of pieces that have been removed.

Print the value of PP after all the operations have been performed.

Constraints

  • 1N1001 \leq N \leq 100
  • 1Ai41 \leq A_i \leq 4
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

A1A_1 A2A_2 \dots ANA_N

Output

Print the value of PP 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, PP equals 33.

  • The operations for i=1i=1: 1. Put a piece on Square 00. Now, Square 00 has a piece. 2. Advance every piece on the squares 11 square ahead. After these moves, Square 11 has a piece.
  • The operations for i=2i=2: 1. Put a piece on Square 00. Now, Squares 00 and 11 have a piece. 2. Advance every piece on the squares 11 square ahead. After these moves, Squares 11 and 22 have a piece.
  • The operations for i=3i=3: 1. Put a piece on Square 00. Now, Squares 00, 11, and 22 have a piece. 2. Advance every piece on the squares 33 squares ahead. Here, for the pieces on Squares 11 and 22, the destination squares do not exist (since 1+3=41+3=4 and 2+3=52+3=5), so remove these pieces and add 22 to PP. PP now equals 22. After these moves, Square 33 has a piece.
  • The operations for i=4i=4: 1. Put a piece on Square 00. Now, Squares 00 and 33 have a piece. 2. Advance every piece on the squares 22 squares ahead. Here, for the piece on Square 33, the destination square does not exist (since 3+2=53+2=5), so remove this piece and add 11 to PP. PP now equals 33. After these moves, Square 22 has a piece.
3
1 1 1
0

The value of PP may not be updated by the operations.

10
2 2 4 1 1 1 4 2 2 1
8