#P2539. [AHOI2005] 矿藏编码
[AHOI2005] 矿藏编码
Description
An exploration robot discovered an extensive mining area on planet Samuel. In this mining area, there are towering mountains and flat plains. To facilitate survey, the entire mining area is divided into grid cells.
For example, as shown below, when , the mining area is a grid:

Black denotes mountains, and white denotes plains.
The exploration space station has scanned and recorded detailed information about this mining area. Because the area is extremely large, the scientists use a special encoding method to record it.
- If the entire mining area is plains, the code is
0. - If the entire mining area is mountains, the code is
1. - Otherwise, divide the mining area evenly into 4 parts, as shown below:

Encode each part in order to obtain . The code of the mining area is .
For example, in the figure above, the code of the mining area is: 2021010210001.
Xiaolian hopes you can, based on the given code, count how many grid cells in this mining area are plains.
Input Format
The first line contains an integer , indicating the size parameter of the mining area ().
The second line contains a code string composed of 0, 1, 2, with length at most , representing the code of the mining area.
Output Format
Output a single integer, representing how many grid cells in the mining area are plains.
2
2021010210001
9
Hint
Translated by ChatGPT 5
京公网安备 11011102002149号