PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#SRD0000132. Những xâu con tuyệt vời (Awesome Substrings)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Những xâu con tuyệt vời (Awesome Substrings)

Awesome Substrings

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Given a binary string ss, call a nonempty contiguous substring awesome if it contains at least one 1 and its length is divisible by the number of 1 characters in it. Count all awesome substrings. Equal substrings at different positions are counted separately.

Input

One line containing a binary string ss.

Output

Print the number of awesome substrings.

Subtasks

  • Subtask 1 (10 points): 1≤∣s∣≤501\le |s|\le50.
  • Subtask 2 (20 points): 1≤∣s∣≤30001\le |s|\le3000.
  • Subtask 3 (30 points): 1≤∣s∣≤500001\le |s|\le50000.
  • Subtask 4 (40 points): 1≤∣s∣≤2000001\le |s|\le200000 (full original limits).

Examples

Example 1

Input

111

Output

6

Explanation: Every substring consists entirely of 1s. There are 3⋅4/2=63\cdot4/2=6 substrings.

Example 2

Input

01010

Output

10

Explanation: There are two occurrences each of 1, 01, 10, and 010, plus 1010 and 0101.

Example 3

Input

0000

Output

0

Explanation: No substring contains any 1.

Example 4

Input

1111100000

Output

25

Explanation: Counting substrings whose length is a positive multiple of their number of 1s gives 25.