A sorted string
Practice
3 (25 votes)
Advanced data structures
Data structures
Fenwick tree
Problem
77% Success 2048 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

You are given a string \(S\) of length \(N\). The string contains only '\(a\)', '\(b\)', and '\(c\)'.

Your task is to find the count of substrings in string \(S\) that have \(F('a') \gt F('c')\). Print \(ans \% (10^{9}+7)\).

Here, \(F(x)\) denotes the frequency of occurrence of character \(x\) in the string.

Input format

  • The first line contains an integer \(N\) that denotes the length of the string.
  • The next line contains string \(S\).

Output format

Print the count of substrings in string \(S\) that have \(F('a') \gt F('c')\) modulus \(10^9 + 7\)

Constraints
\(1 \le N \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:30
22 votes
Tags:
ApprovedBit ManipulationFenwick treeMathMediumOpenProbabilityStatisticsTrees
Points:30
8 votes
Tags:
Advanced Data StructuresAlgorithmsData StructuresFenwick TreeMediumOpen
Points:30
4 votes
Tags:
Data StructuresFenwick treeMedium