Under construction

Still being built. Things may change

Rank Promotion

Time limit3sMemory limit1024 MB

Summary
Given n quiz results as Y or N, compute the final rank when a rank rises after any window of at least c quizzes with correct ratio at least p/q, starting from the current rank.
Level

Hard8 of 10

Topics
Prefix sum, Dynamic programming, Implementation
Solved
No attempts yet

Problem

Quiz Solver is a popular online computer game. Each time a player opens the mobile app, a new quiz appears. The player submits an answer, which is judged correct or incorrect and recorded in the database. When a player shows high accuracy over many quizzes, the player's rank is promoted.

Player ranks are non-negative integers, and every player starts at rank 00. Promotion is defined by an integer cc and a rational number p/qp/q. After the ee-th quiz, the player's rank increases by one if there is an integer ss such that:

  • 1≤s≤e−c+11 \le s \le e - c + 1.
  • The player was already at the current rank before the ss-th quiz started.
  • The ratio of correct answers from the ss-th through the ee-th quiz is at least p/qp/q.

Otherwise, the rank stays the same.

One day, the administrator of Quiz Solver found that the rank data of the players was lost in a database failure. The log of quiz solving records was completely intact. Recompute each player's rank from that player's solving records.

Input

The input is a single test case in this format.

nn cc pp qq

S1S_1 ⋯\cdots SnS_n

The first line has four integers with 1≤n≤5×1051 \le n \le 5 \times 10^5, 1≤c≤2001 \le c \le 200, and 1≤p≤q≤5×1051 \le p \le q \le 5 \times 10^5. nn is the number of quizzes answered by one player, and cc, pp, qq have the meanings given in the problem statement. Each SiS_i is Y if the answer to the ii-th quiz was correct, or N if it was incorrect.

Output

Output the player's final rank after the nn-th quiz on one line.

Hint

In Sample Input 1, the player is promoted to rank 1 after the fourth quiz, because the correct ratio 3/4 is higher than p/q=4/7p/q = 4/7. No promotion happens at the third quiz, since only three quizzes have been answered, fewer than c=4c = 4. After the eleventh quiz, the player is promoted to rank 2.

Figure B.1. Rank promotion timings for Sample Input 1

Examples4

  1. Example 1

    Input
    12 4 4 7
    YYYNYYNNNYYN
    
    Expected output
    2
    
  2. Example 2

    Input
    10 1 1 1
    YNYNYNYNYN
    
    Expected output
    5
    
  3. Example 3

    Input
    17 5 250000 500000
    YYYYYYYYYYYYYYYYY
    
    Expected output
    3
    
  4. Example 4

    Input
    8 3 2 3
    YNNYYYYN
    
    Expected output
    2