using System; using System.Collections.Generic; using System.Text; using System.Linq; class Program { public void Proc() { Reader.IsDebug = false; int queryCount = int.Parse(Reader.ReadLine()); for(int i=0; ia=='R'); int gCount = inpt.Count(a=>a=='G'); int wCount = inpt.Count(a=>a=='W'); if(rCount != gCount) { return false; } if(wCount < rCount) { return false; } int fIdx = Math.Max(0, inpt.IndexOf('G') - gCount); Dictionary rosen = new Dictionary(); char[] rev = inpt.Substring(fIdx).Reverse().ToArray(); for(int i=0; ia.Value == 'R') == 0) { return false; } int idx = rosen.First(a=>a.Value == 'R').Key; rosen[idx] = 'G'; } else { if(rosen.Count(a=>a.Value == 'G') == 0) { if(rosen.Count(a=>a.Value == 'W') == 0) { return false; } } else { int idx = rosen.First(a=>a.Value == 'G').Key; rosen[idx] = 'W'; } } } return !(rosen.Count(a=>a.Value != 'W') > 0); } public class Reader { public static bool IsDebug = true; private static String PlainInput = @" 5 WWWWWWWWWGR WWWWGWGRR WWWWWWWWWWWWWWGRRG WGRWGR WWWWWWWWWWWWWWWWWGGWGWGGWGWGGGWGG "; private static System.IO.StringReader Sr = null; public static string ReadLine() { if (IsDebug) { if (Sr == null) { Sr = new System.IO.StringReader(PlainInput.Trim()); } return Sr.ReadLine(); } else { return Console.ReadLine(); } } } static void Main() { Program prg = new Program(); prg.Proc(); } }