#P10040. [CCPC 2023 北京市赛] 替换

[CCPC 2023 北京市赛] 替换

Problem Description

Given a string s1s2sns_1 s_2 \cdots s_n of length nn over the alphabet 01?.

For any k[1,n]k \in [1,n], consider the string Tk=t1t2tnT_k = t_1 t_2 \cdots t_n, where for 1in1 \le i \le n:

  • If sis_i \ne ?, then ti=sit_i = s_i.
  • Otherwise, if iki \le k, then ti=t_i = 0.
  • Otherwise, ti=tikt_i = t_{i-k}. You can compute tit_i by recursively finding tikt_{i-k}.

It is easy to see that the alphabet of TkT_k is 01. You need to compute, for all k[1,n]k \in [1,n], the number of 1 in TkT_k.

Input Format

The first line contains an integer n (1n105)n \ (1 \le n \le 10^5), representing the length of the string.
The second line contains a string s1s2sns_1 s_2 \cdots s_n of length nn over the alphabet 01?.

Output Format

Output nn lines. On the ii-th line, output one integer representing the number of 1 in TiT_i.

5
10?1?
3
4
2
3
2

Hint

T1=T_1 = 10011, T2=T_2 = 10111, T3=T_3 = 10010, T4=T_4 = 10011, T5=T_5 = 10010.

Translated by ChatGPT 5