This page is still under construction.

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

Jumping Frog

Time limit1sMemory limit1024 MB

Summary
Given a circular string of rocks and ponds, count the step sizes K (1 to N-1) for which some rock's K-step cycle stays entirely on rocks.
Level

Hard8 of 10

Topics
Number theory, Math, String, Implementation
Solved
No attempts yet

Problem

Pog the Frog wants to compete in the World Frog Jump competition held in Nlogonia. Each frog performs a sequence of acrobatic jumps in a specially built arena. The arena has NN positions spaced evenly around a circle, so the arc between two adjacent positions always has the same length, and each position is either a rock or a pond. The positions are numbered from 00 to N−1N-1 clockwise, which lets the judges record where every jump happened. Position 00 is adjacent to position 11 and to position N−1N-1.

The rules say that a frog's sequence of jumps starts on a rock, always goes from a rock to another rock, and ends on the position where it started. A frog does not have to use every rock in the arena.

Pog is practicing for the competition. At the start of a practice session he picks a starting rock and an integer jump length KK with 1≤K≤N−11 \le K \le N-1. Whenever he stands on the rock numbered ii, he aims his next jump at the position numbered (i+K) mod N(i+K) \bmod N. He stops once he lands back on the starting rock. Landing on a pond or outside the marked positions means disqualification, so every position he lands on must be a rock. For example, if the arena has 3 positions and all of them are rocks, and Pog starts at position 00 with K=2K = 2, he jumps from 00 to 22, then to 11, then back to 00, and the session ends.

Given the state of the NN positions, count the distinct values of KK that Pog can choose for his practice sessions, where any rock may be the starting position.

Input

The first line contains a string SS of NN characters (3≤N≤1053 \le N \le 10^5). The ii-th character of SS (i=0,1,…,N−1i = 0, 1, \dots, N-1) describes position ii: R means a rock and P means a pond.

Output

Print one line with the number of distinct jump lengths Pog can choose.

Examples3

  1. Example 1

    Input
    RRR
    
    Expected output
    2
    
  2. Example 2

    Input
    RRPR
    
    Expected output
    1
    
  3. Example 3

    Input
    PRP
    
    Expected output
    0