Strings Hate Zeroes
Practice
0 (0 votes)
Medium Hard
Problem
1% Success 261 Attempts 50 Points 1s Time Limit 512MB Memory 1024 KB Max Code

Consider a string s of length n consisting of characters 0 to 9. Let \(r(s)\) be the number of distinct characters this string has, and \(N(c)\) be the number of times character c appears in the string. We call the string s happy if \(N(0) \lt \frac{n}{r(s)} \)

For example strings \(010\) and \(012\) are NOT happy, but strings \(0112\) and \(123456789\) are happy.

Given a string S, find the number of happy substrings(out of a total \(\frac{|S|(|S|+1)}{2} \) ) of S.

Input
The only line of the input contains the string S

Output
Print one line containing the number of happy substrings of S

Constraints

  • \(|S| \le 10^5 \)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:50
1 votes
Tags:
Segment TreesMedium-Hard
Editorial

No editorial available for this problem.