import java.util.*;
import java.util.regex.*;
import java.text.*;
import java.math.*;


public class LightSwitchingPuzzle
{
	public int minFlips(String state)
	{
		int n = state.length();
        int ret = 0;
        BitSet s = new BitSet(n);
        for (int i = 0; i < n; i++) {
            s.set(i, state.charAt(i) == 'Y');
        }
        for (int i = 0; i < n; i++) {
            if (s.get(i)) {
                ret++;
                for (int j = i; j < n; j+= (i + 1)) {
                    s.flip(j);
                }
            }
        }
        for (int i = 0; i < n; i++) {
            if (s.get(i)) {
                return -1;
            }
        }
        return ret;
    }
	
	// BEGIN KAWIGIEDIT TESTING
	// Generated by KawigiEdit 2.1.8 (beta) modified by pivanof
	private static boolean KawigiEdit_RunTest(int testNum, String p0, boolean hasAnswer, int p1) {
		System.out.print("Test " + testNum + ": [" + "\"" + p0 + "\"");
		System.out.println("]");
		LightSwitchingPuzzle obj;
		int answer;
		obj = new LightSwitchingPuzzle();
		long startTime = System.currentTimeMillis();
		answer = obj.minFlips(p0);
		long endTime = System.currentTimeMillis();
		boolean res;
		res = true;
		System.out.println("Time: " + (endTime - startTime) / 1000.0 + " seconds");
		if (hasAnswer) {
			System.out.println("Desired answer:");
			System.out.println("\t" + p1);
		}
		System.out.println("Your answer:");
		System.out.println("\t" + answer);
		if (hasAnswer) {
			res = answer == p1;
		}
		if (!res) {
			System.out.println("DOESN'T MATCH!!!!");
		} else if ((endTime - startTime) / 1000.0 >= 2) {
			System.out.println("FAIL the timeout");
			res = false;
		} else if (hasAnswer) {
			System.out.println("Match :-)");
		} else {
			System.out.println("OK, but is it right?");
		}
		System.out.println("");
		return res;
	}
	public static void main(String[] args) {
		boolean all_right;
		all_right = true;
		
		String p0;
		int p1;
		
		// ----- test 0 -----
		p0 = "YYYYYY";
		p1 = 1;
		all_right = KawigiEdit_RunTest(0, p0, true, p1) && all_right;
		// ------------------
		
		// ----- test 1 -----
		p0 = "YNYNYNYNY";
		p1 = 2;
		all_right = KawigiEdit_RunTest(1, p0, true, p1) && all_right;
		// ------------------
		
		// ----- test 2 -----
		p0 = "NNNNNNNNNN";
		p1 = 0;
		all_right = KawigiEdit_RunTest(2, p0, true, p1) && all_right;
		// ------------------
		
		// ----- test 3 -----
		p0 = "YYYNYYYNYYYNYYNYYYYN";
		p1 = 4;
		all_right = KawigiEdit_RunTest(3, p0, true, p1) && all_right;
		// ------------------
		
		// ----- test 4 -----
		p0 = "NYNNYNNNYNNNNYNNNNNYNNNNNNYNNNNNNNY";
		p1 = 12;
		all_right = KawigiEdit_RunTest(4, p0, true, p1) && all_right;
		// ------------------
		
		if (all_right) {
			System.out.println("You're a stud (at least on the example cases)!");
		} else {
			System.out.println("Some of the test cases had errors.");
		}
	}
	// PROBLEM STATEMENT
	// 
	// Leo has N lights in a row.
	// The lights are numbered 1 through N.
	// Each light is either on or off.
	// 
	// 
	// 
	// Leo wants to turn all the lights off.
	// He has N switches he may use.
	// The switches are also numbered 1 through N.
	// For each i, switch number i toggles the state of all lights whose numbers are multiples of i.
	// (For example, switch 3 will toggle the state of light 3, light 6, light 9, and so on.)
	// 
	// 
	// 
	// You are given the current state of all lights as a String state with N characters.
	// For each valid i, state[i] is either 'Y' (meaning that light i+1 is currently on) or 'N' (meaning that the light is off).
	// Determine the smallest number of switches Leo needs to press in order to turn off all the lights.
	// If there is no way to turn off all the lights, return -1 instead.
	// 
	// 
	// DEFINITION
	// Class:LightSwitchingPuzzle
	// Method:minFlips
	// Parameters:String
	// Returns:int
	// Method signature:int minFlips(String state)
	// 
	// 
	// CONSTRAINTS
	// -state will contain between 1 and 1000 characters, inclusive.
	// -Each character of state will be either 'Y' or 'N'.
	// 
	// 
	// EXAMPLES
	// 
	// 0)
	// "YYYYYY"
	// 
	// Returns: 1
	// 
	// We can turn off all the lights by pressing switch 1.
	// 
	// 1)
	// "YNYNYNYNY"
	// 
	// Returns: 2
	// 
	// 
	// We cannot turn these lights off in a single step.
	// It can be done in two steps.
	// One possible solution looks as follows:
	// First, press the second switch.
	// This will toggle lights with numbers 2, 4, 6, and 8.
	// The state of the lights after this change will be "YYYYYYYYY".
	// Next, press the first switch to toggle all lightbulbs.
	// 
	// 
	// 2)
	// "NNNNNNNNNN"
	// 
	// Returns: 0
	// 
	// All the lights are already off. 
	// 
	// 3)
	// "YYYNYYYNYYYNYYNYYYYN"
	// 
	// Returns: 4
	// 
	// 
	// 
	// 4)
	// "NYNNYNNNYNNNNYNNNNNYNNNNNNYNNNNNNNY"
	// 
	// Returns: 12
	// 
	// 
	// 
	// END KAWIGIEDIT TESTING
}
//Powered by KawigiEdit 2.1.8 (beta) modified by pivanof!
