ANCO

Stephan Says Six Seven

Time limit: 2sMemory limit: 256 MBPoints: 333

Problem Statement

Unfortunately, after doomscrolling Instagram for 6 to 7 hours each day, Stephan has become obsessed with the corny '6 7' meme, and likes to say '6 7' really loudly for no reason.

One day, Stephan says a sequence ss with NN numbers (2≤N≤1052 \leq N \leq 10^5), each of which is either 6 or 7. It is guaranteed that ss has at least one 6 and one 7. (After all, to get the full effect of a '6 7', you have to say both numbers!)

Define a six-seven to be a pair of two indices (i, j)(i,\, j) such that if one were to remove every single other index from the list other than those two, the number at the first index ii would be 6, and the number at the second index jj would be 7.

Solve for the number of six-sevens in the sequence that Stephan says. (Whew, that's a tongue twister!)

Input Format

The first line contains NN.

The second line contains the sequence, ss.

Output Format

One line with the answer.

Note that the answer for this problem could be really large; thus, for C++ and Java users, it is best if your answer is in the form of a 64-bit integer (e.g. a "long long") instead of the normal 32-bit integer.

Constraints

  • • 2≤N≤1052 \leq N \leq 10^5
  • • ss contains only the digits 6 and 7
  • • ss has at least one 6 and one 7

Sample Test Cases

Sample Input 1

7
6666667

Sample Output 1

6

Explanation: The possible six-sevens are at indices (i, j) = (0, 6), (1, 6), (2, 6), (3, 6), (4, 6), and (5, 6).

Sample Input 2

6
667767

Sample Output 2

7

Sample Input 3

4
7766

Sample Output 3

0

Test Case Information

  • • For test cases 4–6, N≤10N \leq 10.
  • • For test cases 7–10, N≤103N \leq 10^3.
  • • For test cases 11–20, N≤105N \leq 10^5.
  • • For test cases 4, 7, and 11, it is guaranteed that there is exactly one 7 in ss.

Submit Solution (Practice)

You must be logged in to submit.

If you are using C++17, please declare your main method as exactly "int main()", and make sure that your main method returns 0. (Note: You can add other methods, though, just make sure that your main method (the method where your code begins to run) is called "int main()".)

If you are using Java, please name your class exactly "Main".

Submission History

IDLanguageVerdictScoreSubmitted (PST)
No submissions yet.