Binary String

시간 제한4초메모리 제한2048 MB

요약
각 k마다 '?' 위치 i를 i-k의 값(또는 i<=k이면 0)으로 채우고, 완성된 문자열에서 1의 개수를 출력한다.
난이도

보통10점 중 7점

유형
문자열, 구현, 정수론, 수학
정답자
아직 제출이 없습니다

문제

You are given a string s_1s_2…s_ns\_1 s\_2 \ldots s\_n of length nn with elements from the character set "01?".

For every k∈\[1,n]k \in \[1, n], consider the string T_k=t_1t_2…t_nT\_k = t\_1 t\_2 \ldots t\_n where, for 1≤i≤n1 \le i \le n:

  • If s_i≠s\_i \ne ?, then t_i=s_it\_i = s\_i.
  • Otherwise, if i≤ki \le k, then t_i=t\_i =0.
  • Otherwise, t_i=t_i−kt\_i = t\_{i-k}, and you can recursively compute t_i−kt\_{i-k} to obtain t_it\_i.

It is easy to see that the character set of T_kT\_k is "01". You need to calculate the number of 1 in T_kT\_k for all k∈\[1,n]k \in \[1, n].

입력

The first line of input contains an integer nn (1≤n≤1051 \le n \le 10^5) representing the length of the string.

The second line contains the string s_1s_2…s_ns\_1 s\_2 \ldots s\_n of length nn with elements from the character set "01?".

출력

Output nn lines, where the kk-th line contains an integer representing the number of 1 in T_kT\_k.

예제1

  1. 예제 1

    입력
    5
    10?1?
    
    예상 출력
    3
    4
    2
    3
    2