You are given a string s=s1s2... sn of length n, which only contains digits 1, 2, ...,…
- User
You are given a string s=s_1s_2... s_n of length n, which only contains digits 1, 2, ..., 9.
A substring s[l ... r] of s is a string s_l s_{l + 1} s_{l + 2} … s_r. A substring s[l ... r] of s is called even if the number represented by it is even.
Find the number of even substrings of s. Note, that even if some substrings are equal as strings, but have different l and r, they are counted as different substrings. Input
The first line contains an integer n (1 ≤ n ≤ 65000) — the length of the string s.
The second line contains a string s of length n. The string s consists only of digits 1, 2, ..., 9.
Output
Print the number of even substrings of s.
Examples
Input
4 1234
Output
6
Input
4 2244
Output
10
Note
In the first example, the [l, r] pairs corresponding to even substrings are:
- s[1 ... 2]
- s[2 ... 2]
- s[1 ... 4]
- s[2 ... 4]
- s[3 ... 4]
- s[4 ... 4]
In the second example, all 10 substrings of s are even substrings. Note, that while substrings s[1 ... 1] and s[2 ... 2] both define the substring "2", they are still counted as different substrings.
Assistant
We need to find the number of even substrings in a string of digits (1-9). A substring is even if the integer it represents is even. This is equivalent to the last digit of the substring being even (i.e., digit 2,4,6,8). So any substring that ends at a position with an even digit is even. Substrings that end at odd digit are odd.
Thus, total even substrings = sum over positions i from 1 to n: if s[i] is even, then number of substrings ending at i = i (since any l from 1 to i gives a substring s[l..i] ending at i). So answer = sum_{i: s[i] even} i.
We must be careful: n up to 65000, so simple O(n) works.
Let's check examples: s=1234 -> even digits at positions 2 (digit 2) and 4 (digit 4). Sum = 2 + 4 =6. Correct.
s=2244 -> even digits at 1 (2), 2(2),3(4),4(4). Sum =1+2+3+4=10. correct.
So answer is sum of indices (1-indexed) where digit is even.
Implementation: read n, s. Loop i from 0 to n-1 (0-index), if digit%2==0, add i+1 to total. Print total.
Edge cases: n=1, digit odd ->0, digit even->1.
Thus final. ```python def main(): import sys data = sys.stdin.read().strip().split() if not data: return n = int(data[0]) s = data[1] total = 0 for i, ch in enumerate(s): if int(ch) % 2 == 0: total += i + 1 print(total)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.