ZXC - Editorial

PROBLEM LINK:

Practice
Contest: Division 1
Contest: Division 2
Contest: Division 3
Contest: Division 4

Author: pols_agyi_pols
Tester: kingmessi
Editorialist: iceknight1093

DIFFICULTY:

TBD

PREREQUISITES:

None

PROBLEM:

For a binary string S, define f(S) as follows:

  • |S|-1 times, delete one character from S.
    Then, add to the score the number of pairs of adjacent characters that differ.

You’re given S, compute f(S).

EXPLANATION:

Let k denote the number of adjacent different characters in S.
For example, if S = \texttt{110100} then k = 3.

Let’s analyze how k changes when one character is deleted from S.
This requires a bit of casework.

Casework
  • If we delete S_1,
    • If S_1 = S_2, k doesn’t change at all.
    • Otherwise, k decreases by 1.
  • Similarly, deleting S_N reduces k by either 0 or 1, depending on whether S_N = S_{N-1} or not.
  • Next, say we delete S_i for some index 1 \lt i \lt |S| (that is, some character in the middle of S).
    • If S_{i-1} \neq S_{i+1}, k doesn’t change.
    • If S_{i-1} = S_{i+1}, we again have two further cases:
      • If S_i = S_{i-1}, k doesn’t change (this is, for example, deleting the middle element from \texttt{000}).
      • If S_i \neq S_{i-1}, k reduces by 2 (this corresponds to deleting the middle element from \texttt{010}).

The important thing to note here is that no matter what, k cannot increase: it either remains the same, decreases by 1, or by 2.

To compute f(S), we repeatedly delete a character from it, update k, and add k to the score.
Our objective is to maximize this sum: and so ideally, we perform deletions that don’t change k as much as possible.

This is, in fact, always possible!
That is, we can always perform moves that don’t affect k, till we’re forced to do so - at which point every following move can reduce k by 1, till we eventually reach k = 0 exactly when the string has length 1.

Proof

First, consider the case when S is an “alternating” string, i.e, S = \texttt{010101\ldots} or S = \texttt{101010\ldots}

For such a string, we’ll have k = |S|-1.
Deleting the first (or last) character of S will reduce both |S| and k by 1, which is the best we can do.

If S is not an alternating string, S must satisfy at least one of the following:

  1. Every character of S is the same.
    In this case, k = 0 already, and it doesn’t matter which character we delete.
  2. S contains \texttt{001} as a substring.
    Here, we can delete the middle 0, and k doesn’t change.
  3. S contains \texttt{110} as a substring.
    Here, we can delete the middle 1, and k doesn’t change.

So, if every character of S is initially the same, the moves we make don’t matter (and k is always 0).
Otherwise, we can always perform moves that don’t reduce k, till S becomes an alternating string.
For an alternating string, k is one less than the length; so any move we make is forced to reduce k as well (since k can’t be \geq |S|).
We have a way to always reduce k by exactly 1, and so that’s optimal.

This gives us a rather simple way to calculate the cost.
Let k initially be the number of adjacent different characters in S.
Then,

  • The last few moves will add k-1, k-2, k-3, \ldots, 0 to our score.
    This adds 0 + 1 + 2 + \ldots + (k-1) = \frac{k\cdot (k-1)}{2} to the overall total.
  • Every other move will add k to the score.
    That’s (N-1-k) moves, for a total of (N-1-k)\cdot k.

The final answer is thus simply

(N-1-k)\cdot k + \frac{k\cdot (k-1)}{2}

TIME COMPLEXITY:

\mathcal{O}(N) per testcase.

CODE:

Editorialist's code (Python)
for _ in range(int(input())):
    n = int(input())
    s = input()
    k = 0
    for i in range(n-1):
        k += s[i] != s[i+1]
    
    print((n-1-k)*k + k*(k-1)//2)
1 Like

Can someone explain why is the code below (which is identical with the editorial) not working for the last test case?

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t; cin >> t;
    
    while (t--) {
        int n; cin >> n;
        string s; cin >> s;

        if (n == 1) {
            cout << 0 << '\n';
            continue;
        }

        int k = 0;
        for (int j = 0; j < n - 1; ++j)
            if(s[j] != s[j + 1])
                k++;

        cout << (n - 1 - k) * k + (k * (k - 1)) / 2 << '\n';
    }

    return 0;
}

it returns 1598638578 whereas the expected output is 3746122226

the input:
1
100000
0110011001100110010111101100101001100110010111101100011000010001010010101110001001001011100100001001001110001100001111110010011000000011000000110100010000000010100011101010101000100011111100001000000111111111011010101000101011101111000111100011010111001000110001100111111101001011011001111110000111101111001100000101001011011101010011101011110010111110101100111100110000100101001010001100010100100000100011111100010100010010001011110010101011010000011000100011100111110100011000000010100011001110000101111101100000000100111011110001001001001001011100101000011101011001010111100001001100100000110100101001101101011011100010101101001011101100001011101001100111100000000100001011000111111111000101011010010000110100110111001011110010100101100000100001111001101000010110100110111011111101101100010011111001001101010100101100111000000011000110011011110001010010000000100111011010000110010110010000100110100011100101110000101010111111001011101100100100101101001101110010111110000010000010101011001000101111001011101101101000101001001111000110010110001101001100101100001111000000001011110000111010100010110010110100110001001001100111001111101101001011001110101110010011100110000010100111111100111101010011100001100101001001011001111101010000111110110000111110111110001001010011001000010001110111101101101011111010000001111110001111111001110110011000001100000010010110110101001000011101010001101001100101100100100101000101010110111011001001010110010101110110101100111101011100101111010000111001011001110000110001000100101110011011000111111000000101100010000010000101111001110111001101111011011001101111111001011111011101111010001100111011001111011011010011000000010001101001001101101001010000010010101101001111001000011101100110010110001100110110000111011101000110100101011100010011101010110000001011101100100110011111001110100000111000001111101011101111111000101010001001101100101101011010101001100111001110001110111011110001010011110110011111001100111000000111001010011100101000000110011010010111100001010011011101001111011101101111010001101110011110000100000101101010101111111110101010110111001111011001100001011101101000100011110010011000011110001100000001001001001111111000101011000111010010110011000111111101110010011010111001011010011001101110110101000010101011011111010111101011000011100111100010010111001001000010111111010111010111101100011001001100001110000111111010111101100010110101000011000000000101000111000010011101101000110111001111011101010101000011110011001101110010011110111111001001001101110100011010101101101101001100100111111111010100001100011010110001010111011000010111100001110000010110100000100011100011110101010000111101100000110010101110101111111001110101001000001010100111101101110001011111101100000001010001101100111001011111101010101111100111001010000010011111001111101011010100000011101111101000110101010000001100100111110100001000110011000010110010100111110100110010110001011011010001010010101101100000100001101110010000100111010111100111100110101100101011011000111010011001110010110001101001110100011001011111000101001110110100101011010001010111001100111110100110110110001110101101011101011011000110011000100100011010101001000101011100000111111100100111011111110001001111101101111100110100101010000111101111000011001000111111101000110100000011111100010010101100010111111010001010001101000000111011000001000111101111010111111110010001100001010101101101001011100101100000000111011010111100110111110011000001001011000100001001001111001101001111100111111011000111100001010001000001101101011101000001000000110110001010000001101100111001000101111000110010001101010000111111010000110011100110001101110111110000101000000111101111001011010110111110111001010110001110110101111110011000001001101110000000000100010001111110001010001001001010111011011111110111101010101101101011001000000111110001011101011001010111111011001011111110101001010001011001111001100100111100111011110100000011100111010110101110101101000100001101110001000011011001001000100111100100100000111101100010011001000100111111000110110010010100100101010111010001001011111011001001010110001110111001001101010011010011110111000001000110011011011000101000101101010111010100000011111010110110111101001011010011010000111101011111011001011100001110100110001101110011111001101101010010101001100110100101001010010100101010111001110111111011101101011011010111110000000011000101001011011111000011110111011001001110100001111110001100111010010000100001110001010010110100011110001110101000011101001010110010010110101111101101000011101111011110010010001101100101011100111100001011011011110000001001111011001110100111101100011010100100111011010001011000110011100101000001110010010110111011010110101000001111100110011110100001001001011101100111011011100000001000011001010101111111000100001011111111010010001000111010010101001010111001111100111010000101010001111000101111110010000000110001010000110100011100101101111000100001010011100100010000100000001010000001010011111101000001110100110111111010011110000111110011010000100011011000100000100001011010010001100110010111000100101010011100110001001101001100111011010001011100101101101101111101110110100110111101010100001000100011100101011101100111110101101000100000100111101101001001000011001110001011111000011010011000000101111110010001110010011101111101011010000100111111000110011100100001100001011111001011000101110111010000101000010111101100001100100000100101100010101111011010111101011110001111010010001010111010011111111110110111001111101100000010110011101110101111010110111010001111101100111011100100110000101110110001001101110100000001000000010111011100111000001000010011010110001100010111000001001001111110111000000100110011110100001100100000110101111011001101100011100110111100100011101111100111000110010100011001101001111101000001000100101111001101101001100110111111000010010000111101111101100100100111010011100011101011011101111101101110000111000111100100010110101111000000000010011001010100000110001100000110010100101111100000011000010111111001011110110111101011111110100011001010110000100010011010110010101101110110011110010010111110000010111101100100100001101111101100110100001011000111000110010110001110010110001110111011101110000101010101011100101001011010010000000100010001000111010101000010110010011001110111111001110001111000101110101011010000101111000101111110010100110010001100001010001111101100000000101000011000100100011000101100010100101001011000100101000101111110011001101000100110001101011001110111100101110101101110000010101111011010111001001011101100110001111101111000001001011000000110110010110000110010010010110000010001100010001010110011011100011110000000000010001101000011110011000001001010110001011010001001100101001010010111110011011100000101111000111101101001101011111000111110101010010100101110110110110010111011000101001111000111111100111110011101100010111100001000010101100101011011010101111110011010101100101100101111101000001000010100111111101110001011110101001111111101100100001110001011110110001011111100101000100001111011111101000101100011110101101001100010001100001100000000111000011110111101001110000111101100101110011011111110101011111110001001101000000001010001010110011010110001000111111101000000101010010100001100001111000101111000110100000000110101111111000110110001001001000001111010011111000001011100111011010100101011111000111101110101000111100111011010101101110111000101001000100110110111101010100011010111010101101111011010000101000111111110000000011100000111101000010011000001101100000110100100101001010110010111111000100111010101010100001000011011011001110111111000111000000100110111101101010011111011111101000001111110101101001011011110100000001011010000000010111010001100000111101110011001111011011001001100111100111101010000010001101011101010111110111011011000111101010010100100010111000000101010001001010110010001000100011001111111010000001000110110001111101010101001001101011110101001001011111000101101110001001001110110000110111101100001100010101100101101110010010110001111000101010110001110000110110010010001010011101111110110100000011011110110110000111001011010100101011000010010100000100010111101110000010011111011100110111110010110101001010011001000111111010101101001101011010101111000011110000010100010001011111001000101001101000010010010101110101100111011100111001011100001000000011000111000101111001111000000011101011010011000001100001101000110011110001101010010010111000101011101001100011110100111000001110010110110100111000011000001011100011110001101111110110010101111000000001100010011100111000011010011000100111110000000100000101001001010010000101110001010010100001111111111010100101010100111011011100001000101101110011100110010101110011110010111110111101000100000101000011000000101000001110111111110011101001010100100000101101100111101000011000110111111100101001011001011100101001000101101111111110111010000100001101101110111000010011100110010010010010100000111111101000100010011111100000111100010101101001111110110111011101001110100100101100010001100101111000100100111000110101011101111101010101011000100011111100101010001110110001101100101110101110111001100000001001101010000111000001011100000110001101100000000010001100010100101010011000101001001010110100100100001100101101000100011010011001101001010111110100100101000110010110111011101111110111110100000100111100111100010010110001000010011010010100010101101110001101100100000000001101101011110101001011000110111011011101101000101110110011101110101110001001110101000011011010100011110101000101111101100011010010100110000110000000000110010111110001111100111000101010110010001100000000001100110101000101100011010110101111000001101001011011011001101011100011001100011110110010111010000111000001000110010101011101010101110001000011000010101011001010110001100111000100100100010100111100111111110011110011011010111000110011110111000001010100101010011000111011000010101100001101000010111001001000101000010010110101001000111001101001111110000110011111000000011011010100001011001100111001001010011000101110100000101101100111010100000000101111001100101011101000010111011100110011000001011101110011101011010100110100110100111011011111110010000000010010100010011000100011010000111100011011011100001110001010110001111110010100101011000010011000010101111000000100011111010000011010000011000100001001100100000100000000101010101000100000001101010110100000101111101100000000010101110101010001000011010110100110101010101101011000100101001111011111111101000000101100011010100110110111100110000101100001110011001010110011010110100001001101010111111100110101000000111101100110101111111001011011101111011111000010000101001101111011000100100100010111011001010011111010001011001011000010010000110000010100111010110010010000110011101000110101010101010011011101101111001110101110100111011101111110010100010110010101001001001110111011101001000111010101000001000001110100100011000110110110011010001000010101010000001110011001100010011001001011100101001000011000100101110000011111000001111001101011001000110000011011010001110010110000010001100100011100000000011000111101100000011100010101101001001000010101110111000000111111000101001100000110001000001111111001110010001011000100111110110000010000011010011001111010101001011111101111110100110101001011000110011011011100110101101111000100001011101100110111001011011111100101110000101000011100000111100011101000100011100001000011001001001011011110011001110110100000110101110100000000010000111010010100100011111010000011111000110111000010100111011101111001100010010100001110011001111110011101000110001111111011010010001010100010001000100111001101111010110000011001101101111101011001111011101000010111001010111011110111010100011111101010011110011010101011010100001101101011111010110011011010101010101010010110000011000111011001101111101111010001101000111111111111100101010000110101111101010001111111000011101011110001111011110100110010000101111111000000001101101111100110001001000100111100000001011010011101101010011101100010001010010001001100010100111100000111010100110011000000010101001100011001000000000100000101110100110011110000111000111111000010110011011101101100100111000001000101101110001101101111110100110101000110100110101110100101101000000010111011001001110011111000110011000111011011001101001110010101011111001100000010110011001001111110101111111110100010011010010001000100101000001000110000100110010000111010101101111100100111101011000110111001011110001110001101010101100111010101100111011011010011010001010101010111111101001100001011001101101101101110000011110110101111100000000101000000001011100100010011110001101001000100101101111110001000010111110010101101110111001001011011011011010010101001101111101010011010010101010010010110011111101000111100100010010001000000001110101010101101001111000111101011001111100000101101011110010100000000001001000111010111000011101000110100100011100101000100110111101010010110001111001001011010010100001111110100100011110000010100110001100111110100011100101010011010001000111100010000110111001010010111000110111100011110110000101010001011111010110010110100000111110111010111101110100001010011111101101010100000010111111100111001000001011111000100011111101001100011110010100011111010011111000101100111010000110100110011100110100111110101100100111111110011110001110111011000011110111111001011011101100010000111011000101100110010101011000010001000100001001100010100011011110101110011010101111001000000101010110111101000111101110110101111111111101010000101010100100001010001111001001110010100010000011000101001001111101110001101011001111100001000100000100110111000111101010111100101101001101001000100000101111011100110010000011010010110000111001001110001010101011000111111011100010101100011010101001101000100000010000111000000010100011011111101001111000000001110110001010101010001000000110101000100000010100011010011000001111000010101001011101110000010101101101001100001111011000011000001010001010100000101000011100000001110111010110010001010001110111101011101110001101110110100111010101001010011010011111011110000001000101011010001110010100111000010000111000001101100111001011111110111010111010010010110010110100100000101111100110010011110111011110001100000100111010010111000101100101001001001101011000000111010011000111110100100100001000011101011011100000010001011000001100101000000110111011100000001000011110000100111011000011100111011001110101111101100010111011001001000111110101010101010010101101100000110110011011001101111101101110101110000111000011000010100111010000011101100111000100110100010110111110100100000110110001111100111011011100101001001110111011101000111100101101111110101001010010000111011010100110100010010000100111110011001011101100011100010111000001000100000011100011100110010100000100101101000001011111011110000001101000001011110111010000111010001011011001001011000010110111111011111001110110000111010011011100111010001010110000101000101101101011101000100010101010010110111101010000000111000101010111111100011101101010010110001010000011010000101110010111000000111111101100101000100110100100110101111010100011100001101101010110100001001101111101110001000001111000110110100011010111010011001110000100101111110100110110101011100001000101110100100001010111011011111110111000100010000001011010010010100101111001111101110001100000010010100001110001010111001010001001010100100001011001011001010101101110100011011000100101100010101111101111011011110100100000001101111001010101101110010111101110110011000001000001110001001001110010011010111010101111100011110001001010001000011100000011010000001001110010000111100011000001111110111000100001101011110011000010100011101111101100111000011111111111001011000000011100010111111101000000100000101111000010010010011011101101011100001100010001101111110001011101111001100010100000000111111110100100110011110011111001001111110001011011011010100110110000110011001010111111000111100000111111101111100000101001110010100011111000000000100001111101001010001011100001010110001110101111111001010010100111011100010001001100110001011111110011110001111100101100001110001000100001100000011011011010110001110010111101000000000011001011110101110011010001011000101010111001001001001111000100000110111111011110001110011111011000101000000101011100000011001010110111111100110110110001011111110110001001000010101110011011011110111101100010111011101001011001001010101101011001000110000001100001100100111001001110110110011100110000101111101111010000011011011110101101111010101001010001001010110001001001011011011001101110000011000110011110010100111110111011110110111101110110100100110000001111011011000000110101110110010000001000000010101110110001110001110011000001000011000110100101110100101101000111010010101000101101000101000101011111101110111011010111010011001011100001100010001011000110110100110001000101100100001000100001010110011001000010000111101010110101110010110010111110001101011001100000011011100110100000111000010101100000010011100111000001111110001101110111100110110011000100101100100010100100101000111000100000100011000011011011001111110110001011001011100100000010011110111111011011111111110001110000111001111001100100101011100010111000110111101011001111011001100101110100100010001001000001001010010111100011101001111111111111111110100101011110101110010100000000001010110101100010000100101000100011100010111000000011111001000111001111010000000011000111000101100000100110111000110110010000001000111010010010110111000101100110000111010100101010100010010001010010011000001000101000011000011111001101101001110100011110000001000001100111111111100110011111100100100011111111100000010101010111100100111010000000010001111011101001111011111101101010001100110010001111100000000000000000111111111101100110010011001010010011110001000111110110101110100010110010001110010001001011100011011010100000010000001100000111111000001001101101010100111100011010011001001011010101110010100001010100001110110010001010110110101111101010010001000110100000110010101101010010101011000011001101111110010111101111101010100001001001100110111100010110111100111011100000111010011111001111011010011010111100111101011011001000011100000001010110101110011001110011010110001111010100000111010000100101000000001001011110111101100001000101010011110110101010110000011111001000111010000011101001100101010011011100111000110010101100100011111100000011111110110010011110110010110111111000110100100100100011011101111011110100000100011110111101111011111000101011000101001101011001100100001111010001100001101100111010010110100000101000110110011100011111000110110111010101000011011100001010011000001110100000011111000000000101000100101110100011010000100000001000010101110101010010101000001011110011100000100000110001011010111011011000010110000100111100000111001100000100111111100101101010010100000110001101010101110000001000011010001101101001101001110010111111111100011000100111100001000111100110110000111101011011001111110110111011110100010000001001101001001010000100001111000100101000101010110011011010100111001010100001010011100101110001101100110010010110001100101110011100000101111000010000011110001100001011100011110110011110001000110011101000000011100010010000111111100000011110010111110000111110001001000100101111010011001001111011101101010101101100111111001010110010101100100111101010010101110010010111100001100000110001100111101111111000011011000101001011100001000001010010000000000011001111101100110111001010000000001101101000111011011010110000101110110000101101111101001001101011100111100110101110010111010101110010011010011000100101110000011100101110111101111001011100011000110110110100111111101000000111100001110110001111100100011011000000101111010111111001010010100010101110001111010001110100101000101010100000111000011000110000011011000101110001000010011101001011111111010001010110110001100111100001100101111100001000011011010100000010110101100000101111000011010000110010010000011000001010110111001010000011110000010010111101010110010001011111111110110110011001011001110110001010010110011001100100011111010001001110000000101001110011101001000101010001111111111010100011000010010101010001001000000111000010111001010010010100001001110101001100101111000011111101100000001110001110100000001000110010011011111101110100010011110100110100101011000111001110001100000100010010111100010101010000010100111011101010001100100000111100110000111111101001101001000110100100011010010111110001100101101110011101000100101000010011101101011111101100011111010000000100100000111010001000011101111010110101011100101101110000100011100101111111010100001001110010010000110101001110100111111100110010100110100101011100110001011000101010010000100111100001111010001010001011011100100111100100001110010101101101101111111101101100011101110100110010001100111110000011011001110111100001101011011111011100100001001110111010111011010100110000001101011100100111011010011100111110011010110011011010100101111000001011000010111101000101011001001010001011110111110110110100001000110001110110000110011110000001110101100111111100010010110001001100000010110011111111110110111010100101010011010100111101000000110010110010100111001010111101011101011011010101001110110110011110010110011101100111010100100101000100101111000101000001101001111000111000100111111110000111101011101000101000101001000000111000001010011110001001100100100101111101100101000101111011011111011010111000100100011100111101010001010111000111000011001110011011111000001011101000110110100000010111110111001111010001101111011011110010111011110110001111111110010010111010110010101100111011000011011000101001101100110110100001110101101011101111110111111011101000010100101011000000010010101111110011110110111111001111111110101110000110111010001101011111010010111100000010000111111111000110010111110110110110101000001110001111001111100100101000110101101101111101001000111000111011010101001010101110011101101110011101010001101100000110111101111101111010011011111000111111001100110010110000110010110011111010100100111101111111001000011100100101001000010000011010111000111111001100100000101000101111101101001110011010101111111011001100011001110111100110100110100001011010101010101110100011101011001011011101011010111010011100000111010111101010100001111001000101010101110111000011011010111111111010111110001001101101011110110010100010000010110101100111011110111001101011011111010000011010101110001001100001010101000011111001000100101100101111011010110011111001011011100111111111100000111111100011100100000100001111101111001010000100111100110110111000111010000000000110001011010010100011000011101101101010110110011000001010001001000101100111001110000010011111010101100101111000011111011101111110110101111001110000001010000000011011010101100011000011011110111000111001011101110101010011101010111111000001001010100011000011011010010101100011010010101111001100111010001001100101010110011110110011101001111000110110111111101100111100001111111010101000110100011011111110000001011000101111110010101011000010000011111111010001100111110001011111010011000011110011111000111011000001100110011001010000010100101010011111101001110110011000000111000110100011010110011010111010100001011011111010011001101010100001000100010100101001000100111001000100010011111011001101100110111011000011010111101010100001101000010110110011110011011110100000101101111001101101001101010111001100011110001011000110111101111110011101111100001010101111001010000100100011110110001101010000101101101111010010000011010111100100000011110111000001111011110100011111100011011110011001001101001111101111000010110111110011000011001010101010100101101000110111110010101100111010011101000111111101110110100110101101110110111100001100100111100111101000101011000010110110000100001101001000010011101011011010100111111000011001111101000000001011101100011000101010011101001110010001011011110011111111110110111001011111110100011101000011001001001011010111001101010111011010011111011101110010001011001111000010101110011101110011011011000000100111001101011111111010000010010011011010110010101010100001010101010001101110000001101010101000110011111101101110111000111010001010101111011011011111010101100011110101000111000011111101101000000100011001110100011101111110000010101110110101101001100110100101010101010011001000110000010001001100101101011101101011110001000010100010010111010001110110011001110000110011101011100110100111001011111111001110111100110111101101110100111101000011000111101111000000100010100101010110101010110100010001010110110011011010100001110001010011101101011101011010101111001100110100101110001111111111111110100100000000010011000000011101101111011110111101111000001100110100010101010010110110111011111100000111110110111110100111101010101010100010110011011001001111000001100110011111101010111101110110100001000000010111010111100110100011100100100101100010011101100001001010111111001011100011000101000110001010011100001000010011101100010010010101111100010110111111000100001000101010101000000110010000010100000001100000000010111011100001100011010111011100001001101100100010011010111000110110000001010101110101100010101110110010100100101000110000111010001111100000100001011001101001001111110101011010110111001001101110101010001011101011110110010110000010100010001010100101100010110011101010001000110000100011111111000010101000010011100100110001011011001100101101010000111001111110100110101000100010101011000111110111101000111101000100100100011111010010111111011000101101110001011101010110101101000111011011111111101101110001110100001110101100011000101100100110111100111111011100000000111010111000010011111011011111010010100011011000101001101001100011101100011000010001111110100011010010000000100010000000010010000000110111011111001000111101010001110110101101111001111100001100001111000010011101001101001001100011010111101100000010111010101010111111001010010000001001000101101110001010110000111101010001011100110101100001000010100101010000111100111111000010111010000010011101111000101100011011101101001111110000011011001000111011111011000100011101010110100111101100011111011001111010110101011010100110010011111100110010100011100101000010011001101010111111110111101101001010101100100101000101100100101101101011110001101110000010011110000101011000110101010000010111011010000101011011100001000010001011000111101011111101001000011001111110011010000000101111011110100011001111010011010100100110000001100111011001000011101101001110101100100110110101110110010110001001101010101011001111000010001001000000101001001111010110001001100000011100001100101110000000010010010111100000100011111100001110101010011001110111010111000101100001110010011001001001110000101000101100110110100000001110000000001100001100011011101010001100101111010110110101001000100110101011111001100110100010100110110100110111100011001101000110001011101110110101101011000101100100100110111110001100011100010101110100010011101101110111111000001001111001111101100100011111000001011111101110110110001000100100011100010110111110111000010010101100011011101100110110011001110010001100101001011111011111111010110000110100010101000001110010101101100000011110010011010000100101110010001000001101110100011111111000011000011010101110110010000001111011001000001001111011001000001110111001000000011001000100100100110001111100100111101110000101111011101101100001101101101100011010111101001010101100011100010001000111100111100010100011010010010001110001101110110000100100000100101010111110000010101011000011000000110110100000001101100000101011101110110110011110001000000011111001001111101011101000110111100111001100000111001100011110111010010001011001100100110101000100100001011001111001010010111001111101111000111101001100101101110000001111000001100011110011000100010101111010101110110010011110100111001011010100000011000111000010011110011011010011001001001100000011111000011111101000100001111001000010011001111100000001101001111110001001000101110000100001110111101100010000010111010010110010101001000011100100111101111100101001000010111000100110101001000110010010110100011010000110000001100010000111110011101010011110010100000000000101110100110000110110010110111100010011010111000100011011011011000101011101100001110100000110111110111100000101111011010101111011011111010010000000011110000110011010010010111001100010111000101010000001100111110011010001101011001100110110010010000101011000101001101110001110111011010001000110000101000111100111110100001010000111000101000101000010100110000010110101110100000000001110000100001011001010000101011101000101111010111011101110010000110011100010100011010110110111110000101111011111011001011000100100010111100010100000100101101101110001010101011110111010011010000000001100011000101001110110010000010111111000111010110110100000011001000000010101110110100110111011110110010101101011101101100001101111100111100011000001011111001001100110110100000000111110000110001001010000010100011111101001110000001111101001100101000111011111100100101011111110101000001100000100010001110001111100110111110111111100001001110010010110011111001111001011001110010010011100111100111000001000000011101100101101100101010101101100001000001011110011101001011010010001011010110111101000011010100001101110001111011001000101101001101001101001010011101011111110001001111100101010101110001011000101010101011100101011000000001110100010011000100010100001100111010001010010010011100000000000010111011011001110101111110011010101101110010101011010011111101011110011100010000001110101101001100000000011001111011100100101010011100100100100000010010001001111010101000010100100110010011111110111101011100000011000110110011110001000011010000001001101101111111101010110111000110001001110110001011001100100011000110110101100110010011011010000001101100110011100111010111011011100100011100010111101010100011000011001010010001110101000110001001001100000101111100110000100100101001010100100111100101001010110000011111011011011111101001010101001011100100110111011101101111000110100111010010110101110001111011100100101111110100110001111111000101010110101110011110110110010010010100001111101000001001101100000111111011000011000011001001011010111001101000000001010110010010110011101100000001110100010001010011000000101111001000101110000110110000111010011001010011000110000110111110100101101000010001011101010001100000110010111110100001111101010110111001111101010010001101111100111110001011000100111011111011011010111010011110100101001110010001001100101011111111111111000110101101111110110011000100010110000011101110101101011010011111011111101101101111111010010110011000001011110101101001110111101010011000111010001010101010111101001000111110001010001000001101010101001010100001100100000011100000011010010111110011000101001101011010101110010010100110101101011110101010000000001100111000110011111100000101011111000110000010010000100100110000101000001110010011001000100010000101010010101010100110001111011001110100011100110110001001110011111001000100011011010111011110001011011001011100111100101000101011111010001110111001011111010110100001100111000001101011101110011010110101110100011110001110001000001010100110101001011110010110101100100101100111000100011011001111001010100111110110010001111101000101011000010011101111110001100000010000111110010100011001000011010111011010010001000111101000100110111010111010000011000001011110011111110010101111111010011011101100011101011111110100111011110011001110010111110000111001111111010010100010110001110010011001100001001100010000101100011010110111111011011100011001010111110011111001110000011111001010011000111010001111100010000110110101101011011101100010111000111001110100101011110010111110100111101011101110101011011010110001100010001000100111011100000110011011001100111011110100001110000010010110100000100000110110001010111000100000110111011100000001110001101000111111000101100011110111110111010100001110011100101011010111000010101001110001111110011011100001010001110100110000101011010011101110110010101100111110000000011100111010011101100111000111001001011100011111011101101000100010010010110110101001011101011010110100100011110101111100111101011100010111110110101100011101011101010000001110001010001110101101011111100101011111000011100000011000101101010111011101100111011011110110101011010101010010010000110010100100111100001101101011100101110001010100101111110101100001101111000101000110000000001111000001100010101000000111100110100111101110100010010111000000000101111100111101001110001100111110010101110100110001101010111010111100100111111111010110100000101010100010100000011100001001000111111001101100101111110111000110001010110100101010100111100100011110011000100100110011010100000110110100111100011001001110010100010001101111001110111011101011010111101011110001010000110111001100111011111000110110000111001111011100111000110110010111110010111011101100000101110111000111000000100001000010000010010011001000110000010101111111100100101001010101010011000100110010101011001111000001101101001110001000110111110001011011111101101010000011110010001100010110110010111000100000101010101000100100000010010111101011110100110101010011101101011110110101001100110101100010010010101111100110000010110101001011110101111111110011001111100000011000000011111100111001001110010011100010101000110111001110101000110011100110010010011101101001100011100000100011100011000111111110110000111011101000001010100011010000000100001101000000100010111001000010101111000010110110011101011010101101000010011110111010011111100011111000100110011111001101001101110010110011001101111100100010110110110001111001111111111011111101010001011010100101010011111111010000110001101101000010110101000111001101100001001001001101011111111001001000000101100111110111111101001011011010011011100101001000111010011111101100000010011000010100100110001010001001110101110010001011000011111001010110011001000010010001100001111011000010010111000010100001110011101100111110000000010100100101010010001001000110001110100010010101111011100010001110001111100010000100011001001110111101100010110110111010111111011011111100101001001110111110110010001111110001011100100100101011100011001001001101000110010101011100000010100001001001011010100110100011011011000101001100101011010001001111010001111111011010100111011000000001001001000011001110010111110010001000111111101000001100111110000011010011010000001001101101010010111010000101011100011110110001000011110001011001000100101110111011101100001100010100100010111110011110100000111101011110111111010011000100001001001110111010111101101100001000101101000001111000100000110110110100111000001100001000111001011000111001110011110011111111001001101111011011010011101101101100000000000110110101010100010011101001111101100001101110011111101111000101001000111100001100110100011011000111110010011100000001010010100010010111101001110101001000111110000001000100101001011111000011101111101010111100111000110100111110101001001000100101000101111100000100001110110101001000001011001000111010111101100001110101011001011101100111010010100011110011111101000010001100001111100101110101001101110011101101000101101010001101000000011100001110001100001110110101000110001111111111000000001010000011101110101000100100111110101011110110000101111100111001001001000101100010011110001000000010100000000011101011000010000111010111111110100011011100101111000001000001000001010111111111011001110010001111110100111011010110100110010010001100101111000011101010001100111100010100110111011010010001100110101100011011001111111001011011110011001011000100010001100001101001001100100100110010010111101101010010110111000101010111010101111010100110001010101110010111101001000110111001101001011100111001111011100000011010010011001010110111101001000010100111110010100110010101111100000110011110000011100000001111111010110111100101110110110111001000110001100110110000010100100101101001110001111111011111010101110010110011001010111110110111010001101000000110101100111110111011001011111011111001001101011100101100000100011000011010011110101001101111110111011011111001110000001010000011000000000010101101011101110010010001010110000110001110010101011100100001001010010001110101101001110000001100100000001010001111101010010110101100110000100100111101100000110010101101001010111111100001001100111010110011110000010000100011100000011010110011010100100100011001101100100000100011110001101011100000111010110101110001010101111010011111100000100000010110100011111110001010010001011101101011011101001111101110100011011000010011000010010100000010101010110111001000010000000101110011110100010010101011011010111010110011110100011011010001100010110001101011011111011111111101001001110101100100000101111000100100100000111101110100000011111110101100011000111111010000000111010100010011000101000001000101110010000100101100001110101110100000001110101000111111000010111100110110111001001000101111010110000010101110001101010001110000001001101001000011100000110000110001100101000001111000010100100000110001111011010100001010010011111110101111101011001011011110010111000000110001101000000010111011010111111010101101000011000111000100010000011111001001111010111010101101101011001001011111111100011010001001111011101010111100110100111111110111001001100110110001001110110111101000001110010000101110000000010110101110101100111010010001101011000011010110101010000110010110001001010100110100110101010100100010000010011010101110000101010100001100011001101101011100100111011110111010100011001111100010110000011010100100100011010011100111111010001100011011100010010111100101010000011110110111011110000100001010010100101110000110110111111011010111110011001000111101011111010011111010111111110010010110111100010010100111001011100001110001001101011001101111011111000100100011010001001001010111110110001101110001101011010010111110100100001101111100111011100000111100010101000000110010001011100000100010010101100001001111000000110111100100101110000011010011100101000111000000110011100100110001101111110111101100001011011001011001010110001100111101101001101001111100000000011000010001010010101001011001001000101110111011011000000100101101010100111010011010110110001111110111111010001001001100110100100100010011101011000110001101100010110110100101100001011111010100110101110001110000110100110101100001100001100101010001110100001101111011110001000110100010111111101000110101111111110011001011010100001010111011100100011101100101010011010111101000111010110100101011110110010011101100010000010111011101000011100011000100111111010110011111001010101110010010101110111010100011110110110010100111000001010010001101001001011110110100100110110101011000011111000010100100101101110000111001100010100011011011101001001011000001111011100100101000101111001101111110110101000011011011001001010111010001010001111010001110001010011011000111110110000110101111000111011011011010111101011010001111010001111101110010111001100100101110101110101110100010111110010000011011010000100011000010011110001000101101101010110100001000101010010010000011111010111011000011010110100000110110111011001111101101001011110101001110000000011010110010010101010100110111011110011001000110101111000111110001100010100011010000111101001100011001101011011011000110101001100011000010010001011101100010110010110100011010001001001101111110001111110011101000010110110101000000101001010001100101111001000000111001110011011100101111111000100001101110011010001101011011001111010110100100101001000100111110100010111001001000001010111000110011110100101101110010000011101100110110001111010000011111011010000001101100001101011100000000100111011110110101000011010111000000110110011010001001000011000001100110001010110101011001011001101110101011011111110000110011111111100011010110011111011101111110010011011111101000011010000000011111111100010110100111101010010011000110101110110111011101010010000111101100011000101111101001101010100011011111110101001000010101001110001011110100101100111101101001110011010011010111010001101100110111011101101010010111100000111001010011101110011010010010011010011010100100100011011110011011000000100001110101111111000100010110001010011111010001111111001000010010000111001000011000101010100001111110111010100110111110001101011010001101110010011010110001001100100111100111111010100010111111111001000010111001110110100101100010010010101010110000001100000111011111001101101100100100001011001100000001000000010011010101101110000100100011110100000101101111111100001001001011011101110000111111101010101001111110000111100010000010101010010111010001000011000010111010110101001100110001111011001011111010010100001010001001000100000111001010010110100010100111110100011101001111101101001111110111011110001101111110011000100101110001101001011100000000000000010011000011101101001010110100001100000001110011101100100100011011100001011001101110110110011111001011100010011111010000011101011110010011001111000000010001110011110001111111111011110001110101000101110001000111010010010110101000101101111111101101100001110000011000011000000110100100011001000111111101011100111000000110000000111100001111100101001110010111101000100010100110000010000110101111000001001010001100000010011000111010111110010100000000100010001010110011110111111111000001000011111010100001111011010001110000111010100000000110000001111110110000100011010111011101011111000110000010000100011111111000001111101011000000000000000110110110100001010111011001011000100000000100110111110101001100100000111111101111001110111000000101010111011001101110111000011110011101001001011100011001100111110110111010011110011010000111001110000111101111001011011011000000011010000111010110100110111100000011111010010010011100010111100000100001110100110010011110101110111010111111010011000001001100111111101101010111110111111110101100110111110000010001011011010010111101010000110101001110010001010101011100100100010011010010100110001100111010010000110000000011101101011111101100000011001010101100100101101001100110100101101001100000001100110001011110100111000100011001000100011111010000100101011101110101011101010010101111101000101110111001011000001010100100001101110111011100000000011001110101100001110110000000000100111000011101000010000001001001101011111011101110000101010000001100010011100011110100111011011100000010000000001110100010101110110000001101111100101001101010000110101101011100010100001101110001001100011111010111010100000101000101101011011011111100001010110100111001101001110011101011010111110110000110010111001001001010110011110010111011001010001100101010011001001001110110010001100011110101000111010110111100100001111010111001110110010100111100011001110011001100101111010000001010110011010110000100011111001001100110100101010110011110100001101111010111101101101100011111101100010011110110000010101000011111100001011011010011110110100011100001010000010010101000111010111011100110101011110001111011101001110000011011111111111111101010110010010101111000111000110111011001011110010111111111110110000010001000010011000001011101011011111111100111011000011011111011100110010110011110011001000100010110010001001111010001000000001000001101000011110000101000001001111100100000110000010111111100010100111011001100001111001001001010010001010111101100100010011110010110101111101011011000101100001000000011001011110100000110110010001001111010101010000100000111001111011111001101011101010110101110101100100100010110001011100010010011101101000100111101011000111000110100100111100000011100001101001100100111001100111101110100111010010101011010000010111100100100000110110001100010110110101110001010100011000110110000100110100100111101101001100001110100010000111000100000000100001000001000111110101010001111010111110000010101110100001100000011000001100100100000001110110111000011000000101011101010001000011000011100000101101000110001010001110001010001100100101000111010110111000011000110111101000001101010011010100100110100101001110100000001101100010111110001100011101011001110101001111010101001011011111100110111011000011100110111011001011101011110111001101011110110010101101111010111111000100101101100001011000101010010010000101001000110011100111000110000111111011101111100010100110101001011111110010110110001101001101101001001100000100111100111100111000101011000001110111010011101010010000100100001001100100000000111010000111011101101100110001100110010110110000010111100101101000100110100111001100111001100011111010101011111101000001111110001111000101010001110001010100001100101110001011100101011111101011001001110001111111101100100000000100011110001000001000000101101100001100100001100101111110101011000001001110110011111110011110110101010011000010111101000110010001001011010011111111001100000110101000111011000001111011100110011000100001001001101111101001011010111000000010111100010110010001010100111110110111110110111010101001101100100100110000100011101001001111110101110001110111100001101101010010100010100000011001100001110111100000111001110000001111011110000001011111111000100101111100111110101001100101110011111110000100011000000001110101110101101001010101000100011001110011101001001001110001010001111010101110001100011011110110100100011011101000010110000001101100110000000100111110010110110000101011111010100001110010101010100110010001100101111010110111101111010010010110101111101011111100000000111101110110101011000101010000000001011111011001000100011010101101010101110101101001000001000000000111110101000010100101100100010111000010110011110011110010100000011000100111000100001101011111011100011001111000011001000100001111100111001110011101000101000011110101010001100010100101100110001010000101101110010101011111010111110000000101111110100011001011100010010111000000000100110100000110001001000101000100110010000101000011110010011111111000001110100000001111000111110101010010110011011001101001101000110010101001001100010100110100100111101110100100100101111110000000001100100010110110110111111010011010111000100001111000000101000000110110101011111111110111001011011010101010011001001110100110001111111111100101100111101100110010111111100111101000110101111010001011111001000101010001100000011111110001001001100001010100110011001110101100000010010101101001000011110101010101101100110110111011000101000100001110000101110011010100110100001110011001011000011010110111000111111000010111100101111111010100101000000001111101111101001001101100110000111011101000001101101110111000001110111011011111000111101110001100100111011111101111011011001101101110011010101001101111010011001001011010111100110110011111101001001011111110001111110100010101111011100101010000011011000101001001101101000100001011010111110001001011110100001110011101001011000100011000101110100011100111001101100101100011000100011000101010111001111111001011101010000110000111011101101001000100100010001000110011011010010111010000100100001000101010110100111000011110100010000100000101111001111111100100010111100001011000111001011000000100011001111101000000110111011111100001010010000001101100010101100100000011011100001011000110010001010110011000110100111111000010100001101010001100001011111111011001110101100010111000000101011000010010101100010110101110100011111000010011011001100011010010110111110100101110001101011111001001010100101001000100000001011011101111111001011101000111001110000000010101110000001001101100110111100001001100001100000101110001000111110010010010110001101100100101111010110110111001000100110110010101010111100000010001110001100111110100101101001100001110011100100001001010001010011100100010011010010110111011000100110011001011101110111000001101100010111110000001100011001000001001110101001101101111011011010110100001110000111000010010111011110111000001010100000100101010110100100010100010101101011110100111011101011110110001001111110011110110110101010000100001111100000101010000001011100011000100011100010001111100001001001110011110110010100111101100000000010001111100110100011101011001000100110000110001100111000010001101101011000010101101011111111000011011010101010010100111011011001001101111010111011100111101110111000010000111010110101111011000101100011001101110100100000011000111001100001101000011011111111111001100010001010010101010011001001010111001100000100011111100000111111110110010110011011010100101010110110001110100001110000111000110110110101010001010000010100000100111110001000011111111001101111110010101100001110001110000011100010100001100010111101000101010011100110000100110000010110111101110101001101010100010100111011101111111101001011011101111100010111001111000101100011011001011101010001011100000111111101101110001111100000111001010101001110101011110000010110100001000001101111010000101010000100101011010000011111111111111111011000010110111010000001001000010011010010111001010101011000001111100111100011100101010000101001000110111110110010100010110101001100011100110110100000110100010011011001000111010111110000111100010001001110111011111111010000110110110011100110111011000100100010001101100001001000000001001010001000010100111010001010010000011110100000011111011101010001101011001000000011111110000001100000000010001000011111101111100001101011110110110010110110000010110001010110110110100110100010010011011000010110111001011010100000010101000100010000100011100110011011100100100001101011000011001111010000100011011100101011100111110111111011111101111001010000010001010100110000110000110110101101100000000011100011101001001101100111000010100101010000010101100001000111010111001011000001101001010011000111111001010011001010110011111110010010110010101110110111000101001110101010011010011010100011111000110000101101100011010101011011111111001000011010111000110001000110101010010010101110001000111111011101100110101000111001110111111001101100001110011001010011100011101110011101000101000101110111111100010101001110000010111001011001010100110100001001010010100000100000010101011001100010011111011101111111110111101011100011111111001101111100001010111001110101010100100010101110011110111111001100011011100111100011000110001000101011010110100000110111101001000010100111110001100111011100101101111010011100110000011110001111101100100010011111010110111110011010101011101101000011111110110010101100110101001100011111011011101111110100001011110011100101010001111011000000010100100100111111100100011000111000110011101100001111111101110000010001101110011011100111111001101010011011011000000111000101100100100101101110101100011001000100011101110110110000010001000111100011110010110010000101010011110100100010110011010001100001001010111111000101010110010001110011011010100010010101001011010011101101101111010001111010100100111000100010100010111001100100110111111111000010111010000011000101101011111110110111001100010011111110001110110111101101110110111110111011000011000101000110010010111000101011110111001011010011100000110110100000001101101101001000100100100101100011110001100101110011001010010111001100110011011110001010110111010100100000110110001000001111100000110001000100101011100111000011110110101001101111001010001111101010010010101000111000011001001101001001000101100011011111010110010110110000011101011110011010100010001111100011010001110010010100000100011100101110010010111101101000000100011100111101011011000010010001111000101001011111111100011001100101100011001111111100011000011001111101100100110001101111001111100001010011110111101111011110110010000101110000001110010110100010100001011000010110010110011110001011110010011001100001001011111011010001101000001011010001100000110100001001110111001010100101101110011101000111011110111010111010100010010001000001011110101000111101110110001100100110000010001101110101111000111111101111111110110111110011101011001000111001100001100011110101111110001100011011011100100100101101001100011110110000100011101000011111101100111100111101110110101111010111010100010110001101011100110100100110010110011100111101001011110110100011110111101110110000110111110111101110010001110000110000000011001010010101001011101011000011000001011110010000010110010001101101010010101010010100110111111100011011101010111000010101010000011101100001111010101110010110100010101101010000010101111100010010100101111000110111110110101111001000001100001011100000111101011001100011011001000100111001010110101001010000100001001100010010111111110011011011000000000010001000111000110010011101110010010100000000111011111010010100000000111001100100100001001110011001101010101111101101100000010111001100010001000101011101110010111101110101111010111000100100011001100100000000000001101010111101000110101110101010011110001000010010100001110001000011101000001000000010001001001111111001001100110000001110001011001111100110001100001100101011011001010001001110000011101010000001001101000000001011010100001110000010001101011101010101000011010100100100101001110010010101000101110001010001101111011001011011001011001010111000001110000101010110101111010110110101010110001111100101011101011111101100100011100000010100011100011111000111100111101101001001101001110100100000001110001010001111001011010011000011001100110010100110111111110011100000001111110110010001011001110011011001000010011100110101110111010100010000101110110010100001111011110000010000101100011011111101110100101100110011001011010010000111010000100110101111101000101000011101110101101100010000010111011011010101001101000001000001001111000000011100011100011001011001011000010100001011110010101101000011110000100110010110110011100001000010001010110110111110110101010010010101111000010000000000010010101010011001100010000000010111000110000111111011111010101011001110111101000100000101111000111000011101000101011000100100000011010111011010000010001010000110011000111010001001000011100101101101011100011000001001010010101110011100010011111000011001100111110110101010101111011010010001110100101101011010110011100101001111001011100010111010010110110000101101000101100001011010101101000110001110001011110010101100101011111101111101101100110110110010011010001111001111000101010011100110111010011010011010101101111010110111110000010110001110111000010010001000001001111110000111011000001111001000110100101010111101001010011001010010001111001011110000110010110010001110111001001101001101000101010000100110010000000100101101100000001000110011111111100100011111011111011000000010111001101001000110010101111001010100011110000010111011011010011011110010101011111110001011000101111001110111000111001100101011110010100001000111110100110000100000000011001010011010110011101111111010110101100101000001010000110011101110101110000000101001001011010010010110110001010101100100000011000111001110001000010101011111101001000110101001000101011100011111100100010101111111110111110100010101011011111111111100111000010001000101010010101011011000111101010011110011000000111100001111010111111001001000000010100001010101101010111010111111001111101110101001111101010111100111100011001100101010011000100101100001101001001110101100101100011000110101000000101100111010100111010110111100001010010100110110010111010011000001111001000101101011111010010000100010101001101000110011101010111110110111010101101000100000000111011010011100101001011000010101011101100010001011001110111010110001100110000001001100110011101110100101000100011111111010110000110001010001111110111011110111110010000011011110011000000001100100011010110100101110011110011010111101010100010000110101000001110011011101010111101111011011111001111111101100111010111111111100111001100000110111101110100001010111101100111011100000000001110101110110110011111110101001100000110000011011000000111011100010001100001000011111000011110100001101111110000111000110101110011111100011010111001011111010000100100000011011100010011011101101000011111111000101101011101111111110110110001111000001001110101001000000011110101101000111110110011000010111010110010010110100111111101110100001100000000000011000111110001001100110101110011100011110010001001100110100011000010001100101010000011001110100010001101101100011101001001001101001000011100111011100000000101011011011110101110111010010001011010010110101001001000011000001100000101000111111110001001110110010101000010100110000101111011010100100101100011011000010100100000100101101000011011000010101111111000111000110001110000100000110110011011010110011101101011000111111000110100110011010111011100100100100100001010011010010011111000101111101101111101010000011111000100101001100101110100001000110011111000110001011000111010010101001011111010110010000100010000010101000001000110000110101100100100010010100111111011000000011101101100010000001010111111101001010101110100011101000010100110111101101101110110011010111111011010110001001110001011000011101010001101000101110111011000111011111001101100111000100100110100110010000101100011110010010001111110100001110101010011000101110011001010000000001110010110010001011010001110100001101110011110011110001011101010100011110101101010111100000011111101011011100101011011101011001101000100001010100011100000101001101101110100001100101110010000010101101011000011111101001111100111110100010010111000011111011101100110110000010000011111101101000111010001001000101110011110001111111101001101000110110001010011110100011101111010111001101101000111011111100001001111010000101000101001111111001010100100010011111010011001100100011010101010110111100110001000001100111001101001101100010000101001100001000110010011000110000100011111000100000100101010011101010100000001111000001111111100001010001000111111100110011110011011010010100111100101100110101001101001010010010111100100100001001010101000000010001101000111111100001010111010101100111000000110001011010001000000110110011101010001011001010011010100011000000101000111010101100110010101010001111010101010100110010001011010000110110010101010000001000100111010111001000000010100101111001100000010100010010101110000010000100001000100010100100000110001001001101110110101101000110000101111000110010001000110010101111100001100101000011000100010011100001110101011111001010101010001111100100000010010111110011010000000101001000001111000100110011000001000110111010000100101000011001101000100000110110000000100101011100110111001001000011110111111101001001101101110011001110010010111010100101111001011010111100111000100100111100111101011010000010000000010111010010000100101001111101101101001000111001100100010011110011011100011010110001001110110001111000001000000001110001000000010100011010010111100101001001010001000110101101000110101011111101101011111010110011111100001000011011000000000010111100001001111001101010000101101111101001000010011010110010010100010011101010011001101000000011111011010010100001001111101100111000111101110000101001011110000100010001100110100001100100101101001100010111011101001110100001011111110000011011001000111111001000100100101000101001111110111010011000000010001100110011101100010111000000000101001010011011110000011001011000111110011000101000101000000000111011011110001110110101110111110100100010110010101000000010111101100000011111010010010100110010110000010011011111101110011101110001111011010011101001000010110011110001010011010101000001111100101100110101110010110101101001011011001010101011111001100110000000111101001101100011111100010000000011101011101111111010101010011111100010101011100100011011110001111101101100011000001001000010101010111000011101101100001001100111011010011011011100011100001101011101011001100000011001111010001101001100010001111000100011000110010101011001010011110001101101011111000001011000001010111011001001011010110111111010100110100100000001010101000110110111101110011001110001101011100001100000101011110000100110001101100100110011111111100011011111010000110100111110011110111001111001100010001000101101001101001001010000110000001010011101111111011000000011000011010011110010010010100111010111110011010101000110011010010110111110010011010000100011101000111111111111100011100111001001010111111000011011100111001110010001010110010011110001111111001101011110100010100011001100111110000011000010111101001110100110000000110011110111010000110001110101001110110010011011010111011001011010110000011001111000100110111010101001111010101110111101010111001111110010101000101110000010100000011011010100101001001111101110111101001011100011101001001010011100110000111000111001000011100000111001001111011100111000001110010000111100000100101010010001010100111111101011100100100011010001101000010011100000000100100010111110010100001110101000100001000110000001010110100000011001001011100111001111001101000010111100011011011011101001011100010001100101000110110110100101110101001110011110001110011010010111101010110011000100101110110010001101010001100111100010111010111110010000011101011111101010010010111011111000011101011101111110010100010111010011011110001010011000000010110011010101010100111011010001101110111110000111001011100110110111011110010000011000011111011100011100011101011011001001111101100010110001111011000111100011011000100110101001111010100110101001010110001000011111101100000101100111101111100111110010111100100010111100001101100111101010010010110100001010000101011101110100011101010010010100001011100010001100011010111011001001000010011111100010010000101111001111001111111000001111101001111101000001011101001111101000011010010100100111000010011000110101001010100011001001010101100000011001111001100111111110001000110111111111011001100011101111111101101011011110100010101110010100011110000000001000101111010011100011100010010111110111010011100011011000010110110000110101100000110111011001011110111110011010010011000010100000100101101000110001001010011011100111000110111101100101001111101110000101111000111100001111011100110000100000011110011011110111111101000010111100101010100001011110010010101011010010111100001010110011011101101101111000010010100101010101001000110011011000100100111010110010111000011100001110001100010001111011111010010001110101000000001101110101000011000101001100101111110011101001000010110010010001111010011100101111000011110000011100000000101011110001110111001011100011111000001100101101110100110100010010100001101000011110010111101010010100010000011000101100001000101110000101011001110000101000110001000001011011100000111010111101110000010101100111000001000110111010001110100110101000010110011010010110010000001110110011111110000110101011001100110101111110101010111101010111000110111110001001011110001000001011000101101110000111010011010001011100010111001110011100101001000110110110001111100111101010110101000011001111110011110010100011111110000010101010110111100001101001101011011101111010100100000001111101111001010110111001111000101011110000000010001011010001100000110101111001110111010011100011001111001000110111001101100101000010010001011000101010110101111011011111000100001000110101000011000111010001100100101100101011100111001110111100001001001010111110001001111111001111101011011111001011101100101101100011110110000011011001011101010101001011001010100010000101111110110101011110110001000010001000100100110000100101010101110111011101111011101011100100101111111010010001111011011010001011011001100111111001000011111011100101011011010101010111100000111001110011010101000011111011110101001101001101101010110001111110100010101101100111001010010101100101101100101100110110100011000010110001100010110001011100101011010001110000001000001111001000110001111100111001001000010100010010101110011001100101001101110000111010101101011010000000010001000101001001011100000100001111101000100010011000100101110000001111010010001000000110101111011101101111010001010001010010001011011110010101100001010100101011101100110001101110000111011111100011101111100101111010101010100001111111010001001001101101010111011011011110000001111110010000100011001101110000100011100110011100010101100101000101011010110000001101111010100011111111101000010000010110011100101001000110111010100110111111101101001010010001000000100001110100001011101011011001010110111011100010111011001001100001111110000000110100000110011011110110000111110011010110010110111100001101011011100101001001011001010001100001000111010110111110101011110111110100101010100101011001111100010111001000001101101111111100110110011011101110111011011000101100010111011001111010000001001000000000110110010001101111110010110110100100111011011110100101111011011011100111001000011010100110100111001100111010001111110100110011011001111000001100001100010001010100011010010001010101001100011011110011110101011101000001110100111001111010011110100111101101000101111100000011101000000100111010111101111000110100101110000010110010100100100011111101010010001000011110001010111000000101101000100110000010001011011101011110100011010011110011010010011000111110101100001010100111010101111001010100111010101000010101111110011010101001101110000011100111101101011101000011110110101100100011011111111101100111110010100001011000010100001001000100010010111111101100011100100100111011000110011010111110000100001001100101011100001100000010010100010000001000100110110110100010001001001001101111111000110110010101100001111101111001000111101010010001011110101110110101100011001110100011100010000101010100111010001000100001111001001110110010000011110000011000101011101001101101010001101111110011111101101010111010101111011010111110011011000001011001101110000101111111000010100001101110011110000010000101101001101101100000100011010101001000110100011111111111101110110010001100111100000111100010110001011111101100001110010100001110000010000001101001110100100011100011001011001011111011010111100011110011111010000000111011000101000100001011001100110010000100010010111011100010111000111111001010001011000110010111101100110101000000101101011001101010000001100001101010000110100001001110110010000101011110011000101011000001010000110101110111011111000011110101100111001001010100100010011001001010111011110110001101010010000111011110011111000001001111100111110100100010011001101011111010000011011000011001100101010101010010100111001000110011010001111111101111000010010110001100111100010011001100010101100111010011011111110000111011010010010110101000100101111011000110010000101001101101001111100101100011010010010101100110011111110111000001001100011111110101110010111010011110110000010001011011000110001001011101011100100111010111001100110101011101111101111111100000011011100110110001001000111100001011011010100000111111110001000010101111010100000001011100001011110110111110110001101010100110001100101011001110010101000101010101000110010000001110001100010001111111100101010100100111100010001111101011111111110001011000101010100100001010100001000110000001000110011101011100010111111100101011100010111010001111100000000000101100111011000111011011001111010101111110001101110001100001001000010001000000101101111100001110011000000110011101110000101000100000100010000011101010010101101000101111101011110011110011110111111000010010000111111010101100001100001111110111100011101100111010000100110001011000011010011110011000110101111101111100101100011100011101111011110100010110011100010101011111000011100101111110011111101001010000001001101000100001111000001010111001111100100011010110011000010001100110111001110101001100001011011010001010000011000010011111010111110010101010110011011100000000001101010011100000001110010001111110011101110100100100111111110110011110010100001111011011001000011010100011010111000101010110100100000101011111110101010001101110011010111101111000100000011000011001011001011000111000110001000011110111000101001011110010011100111111000100101110111010011101101100110011101001011111000111000110111011000111011011100011010110011001000101101111001000010111010001010101001000100010100010100001000100011101101110110001010010101110010111011001011101110101011101111000010110000001101001000111001011110111100001110010111000111010011001010101010101010010011000011000001100101100000100101010010001001001110001000011110000100110011100010100101100001001010001101100111011001101000100100100101111101000000101111101011110001000100000010110100101000110100101100110100101010100100011101110110111000101111001110101000101000011110111010000111010011001101010110100100100100011011010110100100110111011011000110100001000100111010010001111001101110000001100111101011111100100100010001011001110000010011011111101010100110110110101101001001111111011111101000010000101111001100110011011111100011001010011011111101011100100110000110001100110110010000000001101000100110100000010100011010001110010011110111010111111110100001100110111000100001000011111001001110010111011001011011101110011010011111001011011001101110100100100000011110000001101011010001001010000001001111011011101001011100010010100011110011011110010111010011100001010100001001000110100111000000001000000011100000110101100111001011011011001111010110101010000010111001010111000001111110111110101010100101001101000010111111101111110100100000011000100111110110111011010000011111110001111110001010111110100111001010100000111001110001101111010101100110010101001000101011001011011100000100100001111011101111100111000010011001000001001111010001000010111010111010001110001101111110101001001010010110101011000000110001111100011100011000010110000000001101001100101011000001011100100100011001111111010101111110100111011100110111011100010001011000110001110100110100010010100001001000000101011110111001111001011001111000101001010110101110001010100101010100000000111010100100001101001001100001111010011110011111011010011000100001001011001000001011010010011010001011010100001010011010110100001001000010100000000100011111110010001110001010110000100110011101111011110011011110100110100111111000101110111010001111000111001111011001101100110110111011100010011000000000001100011010110111101000101100111111111010100110001000000000111000111100001011100001000010001111101101011010100101100001011011111111101000101110110111100100001110110001100010110010111001011010010000110001101110100001011011111100001000001101011101001110000000010000111101110101101100100110110101010101000000101100010001010100001001101001110000111001100110010000010110010000010010010011100101111111100100100011101011110001111111011111101111111000111011000010001011111110001011000001111010100001011100110001111101010101011111111110100110011100010101100101100111101011100100101011111110100001111100011001110001000001110010111101101101110101011100100110011110111110000010011010110111111111111010000011011101000101011100110110001000010101010011010110111111000001111000100011000111011001101100111101000100101100110100110111010111110111111111001010111011111000000111001111011101101111111111000000010101100001011100001101100010000000001010001000111001101101010001010010010011111010101001110010100001101001101101001111101010010001101011110011111100001010000101101111001101101111111110000001001101111100111111100100010100001100001100101111011111010101001011110010110010000000001111011000101010111111011001000011110011101010100001101001111011100110000111100111101001000010011100010101011001010100000100100110001111000000110011011110101100010011001111001011110000011011111001100101100001011110010110011011111101110011100110101100100000101010000111100110011001101000110001010110010000111000000000100001000011110100010010011100101010011000101011001110010111110110111101110011110101101010001111100000011010111111110001011100110000010101010110000001001110110000010010101010010000110100110110000000001010010010001010101101101101101100111010110000010100001100111111101100101110110100100010111000101100111010011111001000100010010011000110010110110000100110100100010101010111000101011101000100010111001110011010110010110001011000001110011011101110111101010001011110000101001000110001110101011100110000110010001010010100110110110100011010101010000011111001111000111000011000011001001101100001010000101001011100001111011110101100010000111111011111100100001010011100110111111111110100111101101100111101001000000011001011011001010010001110011100000111000100001001010000010010111100001001010101001000010000101000100000101110000000100010110011011110110011000001110011011010011001111001000101011110010111110011010111000011100110101000000010000000101010001111101010010011011100010010110110001101101011010111001110110111100110101011111110001100101111000001101101101111001010010100000101101011111111001111100011000000110000011100100110110110111010011001100111011111100111100110001101100011001100001000010100101101110111101110011011110011100001110001111011000011001010111111100011011100111110000100101110010111110011011111011001101011111011110110110001011101001110101001001111000101101001111010110001001000110010110001011111111000111100101101000000010000001101111100000001100010011000011010010100111110011001011101010111101100010111010100101110011001111100111110110011101000010100011111010011001011010011010101111101101100110011100010000010111101011110110010010100001111001000011111010000010110100101001111000101110010101110000011111101001010001111000000000110011110101111001100101011110010010011001111100000101100100001011110100000011010101100001011011111111110110011000000011110001110011100000000010100111000010000111111011011010001011000000111110010101100110000010111111100011011010100010001010110100010000111001011000110011101000101010101011110111100001100000100001101011110110001000000011001011011110011100110000100111110110100010100101110010101101010000110001100101101111001100011010101111110001011001001010110000101000001000000101111000101110110001000100001111110100111101101001011010010011001110011101011110101011100110100110000101001110011010100010100000001100000000011101110001001101001011010001000011000011000000111101101111010100111001011010101010010011110011111111001101100000010011111101011101000000001110011110110001110111011000110111010100101010011011010001011110011100011011010001001011110110011001011101011011101110111010101101000000101101011011011100001100011011000100001001000001100111000011010101110000010111110111100001111110001101111110010011010010000101010101011100100110000000011010011011000100010011110011010101110010110101000111111011111110000010101110000011000100110110001111011010101111001010001111010110011001011001110100100011001111001011010100011000011111011111001101101011110011110101100011010100101010011110101010011110011000000001110100000110010101110001101101111010011110011111110111101110011000110110110001000011111000110100011111100101000010101010101101001000011101111000011111011011001101110000001100111011011000101010101001001111000111101010000101010110101101110000010001111011001110010001001000101001011100010011101110011101001011100011001011000111100101011011001110101010010010000011001001111101110100001100001011101110011110001111111100111010001001111000011100110111110001111010010101101011111110111011001110010110010100100110001001001001111001101001111100111001000111010111010011001100100011110000101110110110101110110111000101110111010010100100001110100010110110100011011101010001011011111010100100111010100010011100111110101010000011010000010101101000010001000011100000011001011001100111010011100101110111111010111001110110101100000110111110100001101101001110100111110000111110000111010000010101110101011111011100101011001100011110111110000101010100000101010011101100001101100000101101101101001011100011101011001000110101001000010010010100001101111000010001100000010001010101111101011000110101111101100011000000110100000110000011010110101001000101010110000111111001111111110000001101010011000011000110001110010110110110100001110100101010001100101100101100000110000010000100100010110000100101001110110010101111010110000001110111011010111000000001000011111011000011101001000111011000110010111110110011100100010010110100110011110101110110111101011101101110000000101000100001010011011001011000111000000011111101101010100101100110100110111001000001000001110011111010011011011111111101111111000000100110001101000101010010101110110001011011001011010110100101011100010110001011100101110011011110101100100000000010000011000000000010000000011000011111110000100101001001110110000000101001101000010111100010111001100001110111001010110101101000011101001000110010000100000001000110000111001100111110010001100010110101011010110010111001001100100011100110010000101011011011111101011111011001001010111011001001011010010011000100010101000000111010100010001111001101001011100101001111011101110111110110000000110000010001101000010001110101001110101101100000010010001110101001100011011101101101111100100101101000100100001110101000001101011000111110100001010100011110001100000010111110000111101111010111100010011100010100100111111100110101000111100010100111000101111110100111011001010011100111001010101100100101010110110100110101101000011101111000110001010001100010111001000011010010000001000110101111100011101100101011101001110010101100111100000100110111111100110011100100001010101010000001100110010101111011001010010110111110111011000000010100110001011110011010010100010110000111011101110101000011011001011100111100010011111101111011110001110000111011111001000011011100111111001111101010101100011010000100101000011000011101000011011110010011100011111111000000001110011101111101010000001111100100101100011111011101101110110010101000111101111111100001000111110111111111000011100100100011011010001011000001000111010110000101100111101111001100011000000111011100110000011101100001110000011101100101011001010100110110000011100101010101010100111010110101100010110100110010000101100100000010101001110011110001011011101011100001100010011010110011111110011101010010010111101010010111111111111111010111110000100111000010011101101100001001011111001001111111001100100010010011110011101001011010011010001111101110010100000111111010001110011011110010000000101000101001111101010101001100001100110101111001101000000100101011111011011001110111011101011111101111011001001111100100111101110000111101011101111101010100010111010100011000001111010100010101111011111000111001001111001111011011010100100001110010100101101010100001100100110010011111010100011010110111010110110101001000011100010111010100101011100001011001011110111110010011111010101001001111110101110000101100011000101100011110001000011011011100001000000001101011001010000001100111011001100010011101101011101100110011110010100010010100101011111000001000110101111110001000110110011101011101100101000111001110111100100111000100001101100001100000000001100101100100111100010011111011010001111001001111010010011001111110000110000000001001100101110101001110011011000101100000011000100101111101010000001001101100111110111100110100011010011010100111111110100111101010101101111100011000001010101011011111110100110111100001101111100011000010100000111111000010011001011100000000011110011011010001111110101000100001110101010100001000111000011101101011011011001101111100110001111001000011101011110010000000110110100111000001101111111000100000000110001010110011001000001001000110000010100011100000101111000000010110010101110010000101111010010110000001100011110011110100100010111010001001001000001110010110110111000000001001001100101100111100010010100101010110001001001000010011101101111001010100000100110011000110111111001110010001001000000001011001000101000000010111110011000000110100010010101000011101100101111001110101001001011000001101001010110101101101010010010000000011100111110001010011010101111000010000000010001111100010110100000011111111110000110010010100000010101010011011110011111100110100111001110111110101101001111011001100101100100110000100000100100110100100010101110011010101001001111011000110000010011101011010110101010101011000011100011001110101001001000010000010100010100101001011001010100110000101010101101010010110110111101001101100000011101100110010101011111110010101101011111000110000101100000011100011001100010110101111011011010000001010100011011101110001100010101100011110110111010100111101100001101001111100000110110011000111100011000001110101111101011001010111111001011111001000011111111110010111110010111110010001111001100101000101011010101010010011000111111110011011001110100101111110010011100101110111100100011110100011010011101101100011101010101110000011110100000011100100010001010110101111001100111010000011001100011101100111101011011000101111010010010101001111011110010000111010000011111111010011111111110001110011001011000000100100101101001011010101010001001000011100010000010000011001110000101110111101110100011101101111101011010010100110101111000010100010011011101100111010000110001110100001101111011010011111011101101110000101010100001100110100111110001111101110101011001101000001101110000010110010101111101100111000110011101011000111011010101100100110000011110111101100101011100110111011110010101010100000011111101001100001100100001011000000101110110100010010100110000100110110000101011110111101110111000101101101100001101001000011111101001000101111011010010100111110100001000110000110011010001001110001100100011010000011110101001111011000011011100001000111111001110011000011101111001111010111001010010100101101101110110011101000101110011111111111010001100101101000111100100101010001011110111111110100110111110001001010110000111011100110110111111101000001000100110001010011101111101111100101010111011110010011110011000000011100110000111000000101011111110000011011011110100110101010100111011100010011101010000011100011111101101011100110101111001101111101001100100010110001001101011011011011100100111111001110011101010011101011001011001111011001010000100110011000001011100110000101001111110001100000001000111100000101011111111111110000000001011010010100011101011000111010100101101010111010000111110000101001000110110000011100100100110111101011100000111001010001100000001001010101011000100001011110011110111111100000011010110100101100000100000100100001010010011100000101100010100111010100011100111110110111110010100111101010110101101010000100001100110000000101010100010111001010100100100111001011111111111000000111001001001000110100111000110010111001110011010110101000111000010001100101100111010001111101001100011100110011110010010111111010001111011110100100110110011011110101001100111000111001110000011000010111110010011011100010000000010111100010110001000010101011110111001010111101111111001101101000001000100010111010011110000100110000000001000110010110111100110101001001000010101110111001011100010001011011010110111011011010001001010101110001111000100100000110000101111000000010111011001010001001011011111100110100110011110101110011001001010001101101111001011100001100100010100000010110101000010111110001010101011100000000011010011111001000100101111010001011101000111101100101011010000110001010000110110100010111100010011110100111010000100010100011100011010100000000111100010110110100101101111001101010101101010011111100111111001110001001010101100011011100100000100000010000100010110010010110011111111000001111011000100011111110101101011001101101010110100101111100000110111100110101011110100011100100101111010110110010011011000010001000000110000110001011010000001001101011010000011000000100101111100101011111111001100101101110010001001000010010011100111101010010110011001010010001100100000001001000000011000000000111001011001011100001000000111111110000010011001111100100011100000011001110101010100100100010011000000001110011101111001101110110101011011111011101101110111001111010001010010000101101101010111011000010110111100010111001011101001110100100101000100100100101010001100101010100011011100100110001111000011111010100000010111011011011001011100111001111111111010011110010010011100101111001011100110000111100110101101000011101011101010101100101110101111011010110100110000011111101111100111100001111001001101100001101011010000000001111000110101011001111111110010111001110000111010111111111100011100101011101001011001000010000101101000110111110010000100000000110011101101011011110110010111101100011000000101100000101001011010110000010010111010010101000111100011000000111110100100010101000110110101011010111010110001101101100111000101100011001000010001111110011110101010100000100100110100011111100000000111001000100001100000110101100011001100000110111001010110000111101011000101100000100110100110001100010101011001010001011010101001111101111011001100011010011001010101001101011110010101001110001000000011001010000010101100101100110000100010001000101100100010110010100011100001111100110000111000001010011101010110000010010110101111111000000110100011000110100000011000111011010001010100000110100111111100100110110101011110110001010000010110100100101100101010110000110000000010011111000001111100111001111100010011010111011010001100010010001011100000000010100100000101101110100010100001101101110101010100001001111101110101000111011001111001001011111100101111100100000011111010110010100100010001111000111000110100111001110110101010000011110101111010001010010111100000010111111111000100010000010100100111010111010011111010011001010110000100001101111011000101100001110001000000100000010011000010011111100001101110011001110111101110101100000111111011100001010000000010011011100001011001101101100010110001010110011010100010001001110011000000110100011101010111001011101000010101110000110111000011100111000010100100010000101110110010100010001111111000111110000100101101110000011000101100110100110011100111011110010110010101100011000010000011111101110100111111011001110101010111100011101010011110100101101010111100010110011010010011001110100001000001010111100100011010011111111111110011010001011010010101001110101110000010011010010101100100001011100111010110001011110110011001101001010111101010100101010000001110010011100010011100101001101110001010011110110011101111101001011100011000001000100001111101011011001111101100101101110110000000110011001000101000101011100000011000111100110010101100011111010111011111010011111111010010010001111000011011011101010111000000010100111110110000010001100011111110010011110100011011001000011101110101101101101101001110010000000011011100000111111110001000101011000011110011000011100100000110110110110000111001001000011111000101001101100100110011001111111011111010101011111101011100110010111000101001101011100111110001010101010111011100000011001000000001011101000110110001100001101001110101100100010100101111011000101111110111101110011000111100000011100001100010000100111001010011011110011011100101110110011100010101000000010001001011100100000011001100010010001100100000010000001011110101001101011011011111001001001011101101011001100010101100101011001000101001110000010010010100000110111010100001111101110111001110010001001111111001001111000110001101011110100001001101100001000010111111000010011011110001011101110111010011110100111101100100101110001001111111101111000000100111100111001000001010111100110001010100111010100010110100001000110011110101101000011101010011101011110100111111100101000111011110001010011111011011101111100011101000110000110001100010000011101010000111111100110011001100100111110010011001010101011011000000000100111110010110110001111101001111101000011010000110100010001001111110011111010111001100010000100000111101000111011000101111111100001110110011110100100111101100011011110011100100010100000111100111011010000000001110000010100010001110010100101110101100100110011110000001110101101000010101010100111000010010011000011010000011001110100111101110011111101010100000101101011111110011110101101110111100001110111100111101010010010111001100011111111011000101111011100001101001000111111100111000011011001000101110111001001000111110000111111100011000011010010000100011001110100000101011011000101011100010100010000110001000010100000011111001010001110011010001111111011000010101101111000101010000011001000011101111100110110011100010100100001001001000110000001101000011101001100001101011100111001001011110001000110111011110001001000111000101101110110000010100001100011111010100000100001010001110000001001010100001110001111111001110100011001001010100111000110011001010001011001101010100111000111101001011110111010100001110011010111000100100100110100011100110100001101001011100000111100010001111001011000010001100111000011000001100111100111101000001010110110000111010111100001001001000111011000001000110010001000101001000000111110100000110111101111110011001010011110110101010100100011011000110000100101111100001000000000101101000011000111100010101111101111010111111100110111111100011110111101001011100110010110100110101110111011110011111010101011111110011110110010101011111100111000111101111000001000010111000001101110110111001111000011111011111011111100101000001110100011111011100011100111001000100111110011001001101100110010101000011100000011111001011001110000010011000110101100101111011101100100001101000101100010111001111000000010010110001011111011101101100110011110011000000100101111000011100100101100101001000110000111010111110010111110110010010111011101101011010110011100101001110010000011001011000100000001101110000111100101110011111010100001110101011111011011010001100111001011010101001110110000010001001001011011101111010011011000110110100100010101010110111000111100101010111110110110100100011111101000011111010110000111010000101011100111100000110001001101101011101001001011000010100000100011011100001111110000000111000110111001000110101100101101011011011100001110111110001100010100111100110100010110101011111011001001000010011001100101000001111110000001111010101101111010010000110110111110111101011000110110001010100111001101000010110100010100101111011111111111001111111000100011101111100000110101000101010110101000001010010011000100000000110101110011001101010001101110110101110010011001011101000100000010001111010110000111110000110000110011101011010011010010101111000100010000111001000010100001111101010011000000110101101001100111001101110000111101110011011001011110111101100000000101110110000010001001000001101111100100100110000101111011101010111110000111000111101110000000101010110000111101110011100001110100001110010011011100100110110111100111101111101101110000101111011101010011011100101011110010001001000011000011001110010101111001010000101110111110100101001011101110110111110110101110100111100001110001011010110010100111011100011001101111010000101101110001000111100110100000011100111010111001110000110010101101101000011010001100100100001110011011111101001111000010111101110011010101000110100000011101111011011100101001100111110101101001100101111101111010001010000101000101111100111100001000011110100100010010001010101000100101011110110100011000000011111010010110001111011011000101010111110011011110011011010111110000001010011111111001111110100111100100011000110111100010111111001100000010010110010101101000110011101011101100100111000000101011011000010100011010010110110011101110001000001001010111001001110011011000111011110110110100001000101101101110110011010111010011011110011001001111011000011010111111010101010001011011010111111011010100111110010001110111001110111001101101101001111011111110001100101000011000001111100110011111010001001100101010010101010000000110000100011010110101110011011000001000011111001000001000110100110011101111010011010011110111110111001111110110010110101101000010001101111101000000101000111011010011110110000001000111110010111101001001011110110001110011111011100110110001100110001011111010101110110011110101001100111111101101001001110100110001100100100011111110110000111101010011010011000000001011010100000011111011011001101010001000110000000111011001011100111001110110101010001000000100011111010000100100001000010101001001000011000100000110111010001111111001111010011011011111110011010110111101111010101001111111011100100101100110111010110100010110011110010011001101101100001010001110111111010001011110110110010000110110000001100110110110101000101110011110001001010100010110001010110001100111001100101010101111101100111000111110000000100001010111001100001000101111011000111110011000011100000101010100001111011101001001100000001000110100101111110000110001001100011101011010001100010101010111101111101110001000110111001000010011110101100111011010101001111100010010110011100100101011111000001111000000001000011010001010010100111111011011011001110110000101101111110100101010011001100000001110000011100110010100111111110101010100001000100010000111111010111000111100001011000001000000100110010101010000000101001111011011011010010100111010001100000111101101100101001110010001100011100011100100000001001100011110110101000000110011011111101010001010111101100010101100100010110100100110010111110110011101010010111111001100111100010110010111101101100110101110011011000010000100011010101010010110101101001001001111110011111010001011111000111010111110111111011011111100101111000111010001100011111010101100111001000101000011110110011100001101110010101110111100110011001111110011011000001011011000111001101001101011010011011010110011110001101010100110100001010011110101000100001011011111111010111110011011001001111101011101110000110100100100011000111000101110000110111011101111011011110111111110111111001001110110111101001111110000111111110101110001010100001100110101100000001110010110101110100010000001110001001010101001000101010110110001000111010110100001000100100111101111011101111110100011100111001010001010101111000000101010001101000011101010101101111101110010000001000100011011111010110010101101101110100110100001111111111000001001000000000001100001001010011110100111001010001011001101101001001100010111110011110001001011110111110101101100101000100101011010011111010111011011110011011010111000011011111010111000100110010001101000101000111010000001110000101111100111010111000011101100000111110001000100111011111001100010001111000110100111101001101000111000111110101100001100101100100000100110110100100110001101110001100001000110111001010000100110110100111011010110011001110101111001001110101100010100010111101001100000101001101100101000001000100100100010001100010010110101001011001011001011010100101000010111100011000111100010101000100011101111011000010000001011001110001100100111010011011111010110000011001110001100010101010011110101101011111101000100101101100100011001111100110111000100011110000001101001011111111000111010001001010110110101110011001110001111100100100001011100011011110000110000100011011001001101100111110100101001101010010000001000100101100000100111000000000111001000011101110010101110101001010101011011110111101011101000111010101101100111001110011001000100111011111010000011011111001111001100111011011101011000001011011010011011010001100110110101010111011011101100100111000111110011111001110111010100101111011111011100010011000010001000101010100100000010111111100100000000111110110101010010010101111001000110111100010101100000010000010010011110101010001100000000110101001000101001000101111101001110110010011101100111011001010010000011100000111001001010001101110100101101001010010111011000000000010101110011010000000011100011010011011111010101010100110011001110100100010011011101111010110001010100011101100100110111011001100111111100001000001111100110110000011110011001010010111100110111010111111010110001000100000111000101011011011110001011010010000111010101011110001000010100110111000100010010101111011111000010011101001001000101111110011011101011000110111011100000101111000110001101000010110011101010011010111001010101110101101101001001000110001111111101100101110001101101000110001111011011110011100000110110001000010100110001111011100001111010101011100001001001010011111110011110101111110011110110100100100011011001110110100010101010010000110001111111101011110011111101001110011100111110011100111111001101110101010001011111001010001110101100110011000110000110111100111110011000101110001110111110100101011111110011100010011001101101100000010101111100100011010111000100000010111010000000001011111010110010110111011101101000011111001111111010010001001000000111101010001100010111010111010111011111000000110010010011111010101000111001110111001011000001010001000001011101011001010011101011001100110110101101110101011101101000101001110111110011000000010000101100010000011010101000001001111001111000000110110101100101010110100100110010010101011111001111101011000010110111100000001111101011101111001101110011001010101101001100010000011111000110010100100010111010100001110110100111001010100111010110101000001110000110100100111100010010110011110011100110101011100001011110011100110011001010011101011110110001101101001110001111000000110101011010101010101110001001101000011100110111111101010010110000000100101000010010100101110011101000011110010000101011101000110011000111110001111010110110110001111101001100001111011111111111011001100110011101001100101010100000010111010010001010110010001011001101000010101100011111111100011110111111100101101111011011110001001010111100101010110000011100111111010111101011101110001010011110100011000001010010010011000101001111010111010110111010110001000000000000000011001011101111110111010110111000100001110001000011100000110011010001011100110101000100001010100110111000110011100001101011100010110101111100100001001011010111010101011000001000000011000011101101110001110011101000100110001011110001100100111100111110110001101110110001001111101110001001111101001000100110111000011001000111010010000100010011101111000000000111010011000110001110101011110111010001001000101111011111110101001100100011000111110111001111110011100011011011101101100001100101111101001110101111111000000001011100111101111011100000101010101100110011011011000011001011010100111010010000010000101111000011011001001101110010100110110111100111010011100110110011110001101001011110101000010010111100100101111000011111001111000101101001000111001110011001101000111001001011011101101011010001011010010110101111110101111011100100101000000100011111010101001101010010111111010100100011010100110111100001010011100111111100011000001111011000000010110001000100110001011101001011101010010100110111110011010101000001001111001010011101011101110000111000011011101011110100111011000100011111101011001101011001101011100100101000111111110000001001110011011000101010000011000000101011110011001100000100000100000101100111010000010101111000100111001010010000111110001100111111010010101111111010110010001111011101011001011010011010111111001000101101000000011001101011111010000010111110100110110011010100000110001110000011001001000110010111100011000101010101000011111011110100110011010000011111101001010010001000111111011101001001000011000000011100101111001110000100100111100000001000000111000100101001000000010011001100010111111010111111001011101110101100010000001111101000101101110011110100010010010100110010010000110110000011110010001101110001011011001000100100101010010001111000000001000110011101100001000000101100111111000000010000111000110101001001010101000111111111101111001011010011100011111110101001001011110000010100111011010001001110000101000110101100100100001001110000011010101110000101001111100111011010100111000000100000100100000111010111011000011111001000011001011000001111111001010000101110011101100111001000010101010101010110011010111111111000000111011000111011001001001011010010000001011000101101100110011010110100001100000010001111100000100010101111001010000010100000000010111110001100100101001010001010111100011010111101100100010011101010011101111100001101111100011100101111001101101101011101101011111000101110010111010000111101000101101000100010011010000111011110100000011111110101110101111011001101010001001011110110000100000010001101000100111100001100000110101011001010101111111100100011001100001001000110111011110101111110001010111100010110111111111100111000100000111101011100110101100100011000111101001011010011011111000000100001010110000010000010111011100011100011100011000010101101001001100000100010101001100010000000011110110001001100101100011101100100011111011110111000000010101111110100011010011010011001011010101010011000001110001100011001011001011101010000101010101000110111100100011100001110110000000011111100000100111101111110001111111000100010110100100100110110111100111110100011111101011100101011111010111011101001001011010100101110011111011111001101001001001010100100001100100010011111011100011100010110011000001010011100011000001100001010111001111110110010110000111000011000100011110000111001101011100111010101110011100100111111101100110001000001110110101010101110100011100101100010100101111110000110010100100000001101001100110111011110000011010011100010000010111101110001000001100110011100100001011110111001011010100110100110000101110010001101100010100000100001011111100000111000111011110011110101011001111001110111110111011001010100011111000010001110101111111110000101111110010001111010111110000111010101011011011111000111111000100001011010010100011001110100010000000010001110110001000001001000011011010111111001100001000001101110100101100101011101010110111000110011101000011010001010000111110101111011111000010110000000000101111001011100110011110110101101100100110000101110101010010001011110001111011010000010000111001000000010100111100010001001100000011000111100011010010000100111000101111011101110110111010101111101001000011111011010100001011110000101101010100111111000101010100000010110111101100010010111101101110001011001110101010001000001101101000110011110110001010110111111111111110101101101011101100010101010111010101111101111111010011100001001010001101000100000111011000101101000100101011100001100011101100011001110100011110111111010100001001000100111111010000111100000101100110011010100001010100111001000001100101100011111110100001101001010011011010111011011001011100100101011001110001001110

#include<bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);

int t; cin >> t;

while (t--) {
    long long n; cin >> n;
    string s; cin >> s;

    if (n == 1) {
        cout << 0 << '\n';
        continue;
    }

    long long k = 0;
    for (int j = 0; j < n - 1; ++j)
        if(s[j] != s[j + 1])
            k++;

    cout<<(n - 1 - k) * k + (k * (k - 1)) / 2<<"\n";
   
}

return 0;

}

your logic was correct just avoid using int in contests this causes overflow many times. start using long long int or just long long. that was the only error with your code, my code above is an accepted solution that is just your code but using long long datatype for n and k.

1 Like

So, you just pasted a string containing 10^5 chars. Wow!

1 Like

lol!! maybe he is new and thought this will somehow help us :joy:

1 Like

lmao i wish i could upload the txt file :frowning:

thanks a lot!

Since n < 10^5 and k is at most 10^5, I thought it would work.

Obvsly, making n and k long long is the only true approach but I realize the following is needed if one insists using them as int.

long long result = (long long)(n - 1 - k) * k + (long long)k * (k - 1) / 2;

1 Like

For reference, the limit of a (signed) 32-bit integer is 2^{31}-1, which is approximately 2.1\cdot 10^9
Multiplying two values close to 10^5 is definitely going to exceed that.

An alternate method, for a bit less typing, is to use 1ll * (n - 1 - k) * k + 1ll * k * (k - 1) / 2
Multiplying by 1ll first implicitly casts the data type to long long.

3 Likes