cswork / OAOpen practice workspace

WayfairOA #2

Number of Divisible Substrings (For MLE)

Estimated MediumJudge-ready

Topics (AI-labelled)Prefix & RangesHashing

Map lowercase letters using this fixed table: ab→1, cde→2, fgh→3, ijk→4, lmn→5, opq→6, rst→7, uvw→8, xyz→9. Count the contiguous non-empty substrings whose sum of mapped values is divisible by the substring length. Count by position: identical content at different positions is counted separately. The mapping image in the fixed original text was a broken local path; this site restored it from the public Problem Source original image on the original FastPrep page, and the original starter also explicitly references LC2950; the evidence and image hash are in the editorial.

Input

A lowercase English string word, without quotes. Full original range 1≤word.length≤2000; the empty string is not accepted.

Output

Output the number of qualifying contiguous non-empty substrings, as an exact integer with no modulo.

Example 1

Input:

asdf

Output:

6

Example 2

Input:

bdh

Output:

4

Example 3

Input:

abcd

Output:

6

Example notes

Original examples kept: asdf→6, corresponding to a, s, d, f, as, sdf; bdh→4, corresponding to b, d, h, bdh; abcd→6, corresponding to a, b, c, d, ab, cd. The first group ab has only two letters, so you cannot map by three letters per group or by a phone keypad.

Editorial

Loading solution…