Under construction

Still being built. Things may change

A + B

Time limit8sMemory limit512 MB

Summary
Given binary numbers A and B, answer the maximum popcount of x in [A, A+B) after bit flips to A or B.
Level

Hard8 of 10

Topics
Bit manipulation, Segment tree
Solved
No attempts yet

Problem

Given binary numbers AA and BB, process the following queries.

  • Output query: print max⁡{the number of 1 bits in x∣A≤x<A+B}\max\{\text{the number of 1 bits in } x \mid A \leq x < A+B\}, where xx is written in binary.
  • A change query: flip bit ii of AA, counting from the least significant bit as bit 0.
  • B change query: flip bit ii of BB, counting from the least significant bit as bit 0.

Bit indices are 0-origin. Bit 0 of AA is the least significant bit.

Input

The input is given in the following format.

NN AA BB Q1Q_1 ... QNQ_N

The first line contains the number of queries NN, and the binary numbers AA and BB. Lines 2 to N+1N+1 contain the queries. QQ is an output query. "A ii" and "B ii" are change queries that flip bit ii of AA and bit ii of BB, counting from the least significant bit.

Output

For each output query, print the answer on its own line.

Constraints

  • 1≤N<3000001 \leq N < 300000
  • 1≤∣A∣,∣B∣≤3000001 \leq |A|, |B| \leq 300000, where ∣A∣|A| is the length of AA
  • For a query "A ii", 0≤i<∣A∣0 \leq i < |A|
  • For a query "B ii", 0≤i<∣B∣0 \leq i < |B|
  • BB is never 0

Examples2

  1. Example 1

    Input
    4 10000 00101
    Q
    A 0
    B 1
    Q
    
    Expected output
    3
    4
    
  2. Example 2

    Input
    9 0110111101 0010100111
    Q
    B 4
    Q
    A 4
    Q
    B 9
    Q
    A 8
    Q
    
    Expected output
    9
    9
    9
    10
    9