This page is still under construction.

Parts of this page are still being built. What you see may change.

Organizing Beads

Time limit2sMemory limit1024 MB

Summary
After each toggle of a cell, report the minimum pushes to gather all beads into a contiguous block at the left or right end of the barrel.
Level

Hard8 of 10

Topics
Prefix sum, Sorting, Implementation, Math
Solved
No attempts yet

Problem

Hyunuk has a long barrel with nn cells (2≤n≤2⋅1052 \le n \le 2 \cdot 10^5). Each cell is either empty or holds one bead. Beads stored here and there do not look good, so Hyunuk wants to gather all the beads at one end. Specifically, if the barrel holds kk beads, the beads must occupy cells 11 through kk or cells n−k+1n-k+1 through nn.

Hyunuk can push the bead in cell ii of the barrel lightly to move it to cell i−1i-1 or cell i+1i+1. If the cell in the direction of the push holds a bead, that bead is pushed in the same direction as well. For example, suppose cells 2, 3, and 5 hold beads. If Hyunuk pushes the bead in cell 2 toward cell 3, the bead in cell 3 is pushed to cell 4 as well. The bead in cell 5 stays where it is.

Hyunuk wonders how the minimum number of moves needed to organize all the beads changes as he adds or removes beads from the barrel. Write a program that computes the minimum number of moves needed to organize the bead barrel after each insertion or removal.

Input

The first line contains a single integer n (2≤n≤2⋅105)n\ (2 \le n \le 2 \cdot 10^5), the length of the bead barrel.

The second line contains a string of length nn consisting of only O and X that represents the state of the bead barrel. If the ii-th character is O, the cell holds a bead. Otherwise the ii-th character is X and the cell is empty.

The third line contains a single integer q (1≤q≤2⋅105)q\ (1 \le q \le 2 \cdot 10^5), the number of actions Hyunuk performs.

Each of the next qq lines contains a single integer k (1≤k≤n)k\ (1 \le k \le n) that represents one of Hyunuk's actions. This means that if cell kk of the barrel holds a bead, the bead is removed, and if it does not, a bead is inserted there.

The input is given so that the barrel never ends up with zero beads.

Output

Output qq lines. The ii-th line contains a single integer, the minimum number of moves needed to organize all the beads after Hyunuk's first ii actions.

Examples1

  1. Example 1

    Input
    6
    OXXOXO
    4
    3
    1
    6
    3
    
    Expected output
    2
    1
    2
    2