Under construction

Still being built. Things may change

Black Debt

Time limit1sMemory limit512 MB

Summary
Contestants get point increases over time; after each update, report the total count of (yellow, black) pairs where the black contestant has strictly more points.
Level

Hard8 of 10

Topics
Segment tree, Binary search, Sorting, Prefix sum
Solved
No attempts yet

Problem

nn contestants take part in a programming competition. Before the competition, Mr. Malnar gave each contestant a shirt. Some contestants got yellow shirts and some got black shirts, which created a rivalry between the black team and the yellow team.

At the start of the competition every contestant has 0 points, and the color of each contestant's shirt is known. During the competition there are qq changes in the scores. In the ii-th change, contestant xix_i has just received did_i more points.

Each contestant in a yellow shirt computes their penalty (the so-called black debt) as the number of contestants in black shirts who at that moment have strictly more points than they do. After each change in the scores, compute and print the sum of the penalties of the contestants in yellow shirts.

Input

The first line contains the positive integers nn (1≤n≤1051 \le n \le 10^5) and qq (1≤q≤3⋅1051 \le q \le 3 \cdot 10^5) from the problem statement.

The next line contains a string of nn characters describing the shirt color of each contestant. Each character in that string is one of the uppercase letters C or Z, denoting the shirt color of the ii-th contestant (black or yellow). There will be at least one contestant with a black shirt and at least one contestant with a yellow shirt.

The following qq lines each contain two positive integers xix_i (1≤xi≤n1 \le x_i \le n) and did_i (1≤di≤3⋅1051 \le d_i \le 3 \cdot 10^5).

The maximum number of points a contestant can score in the competition is 3⋅1053 \cdot 10^5.

Output

In the ii-th of the qq lines of output, print the total black debt after the ii-th change.

Examples2

  1. Example 1

    Input
    3 3
    CZZ
    1 10
    2 20
    3 5
    
    Expected output
    2
    1
    1
    
  2. Example 2

    Input
    4 6
    CZCZ
    3 70
    3 30
    2 100
    1 10
    4 80
    1 100
    
    Expected output
    2
    2
    1
    2
    1
    3