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()); StringBuilder ans = new StringBuilder(); for(int i=0; i{ if(a=='R') { rCount++; } else if(a=='G') { gCount++; } else { wCount++; } }); if(rCount == 0) { return false; } 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 = @" "; 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(); } }