using System; using System.Collections.Generic; using System.Text; using System.Linq; class Program { public void Proc() { Reader.IsDebug = false; int panelCount = int.Parse(Reader.ReadLine()); string inpt = Reader.ReadLine(); char[] big = inpt.Where(a=>a>'y').ToArray(); char[] nokori = inpt.Where(a=>a<='y').ToArray(); int ans = this.getAns(nokori.Where(a=>a!='y').ToArray(), nokori.Where(a=>a=='y').ToArray()) + big.Length; Console.WriteLine(ans); } private int getAns(char[] nokori , char[] yList) { int ans = 0; List target = new List(); yList.ToList().ForEach(a=>target.Add(a.ToString())); char[] other = nokori; if(target.Count == 0) { return ans; } if(other.Count(a=>a > 'u') > 0) { char[] uOver = other.Where(a=>a>'u').OrderBy(a=>a).ToArray(); other = other.Where(a=>a<='u').ToArray(); if(uOver.Length >= target.Count) { return target.Count; } else { ans = uOver.Length; target = target.Skip(uOver.Length).ToList(); } } if(target.Count == 0) { return ans; } if(other.Count(a=>a=='u') > 0) { char[] u = other.Where(a=>a=='u').ToArray(); other = other.Where(a=>a!='u').ToArray(); if(u.Length > target.Count) { target = target.Select(a=>a + "u").ToList(); u = u.Skip(target.Count).ToArray(); other = other.Concat(u).ToArray(); } else if(u.Length < target.Count) { other = other.Concat(target.Skip(u.Length).Select(a=>a[0])).ToArray(); target = target.Take(u.Length).Select(a=>a + "u").ToList(); } } else { if(target.Count >= 2) { target.ToList().ForEach(a=>other = other.Concat(a.ToArray()).ToArray()); char[] newY = other.Where(a=>a == 'y').Take(target.Count - 1).ToArray(); other = other.Where(a=>a!='y').Concat(new char[]{'y'}).ToArray(); return ans + this.getAns(other, newY); } else { return ans; } } if(other.Count(a=>a>'k') > 0) { char[] kOver = other.Where(a=>a>'k').OrderBy(a=>a).ToArray(); other = other.Where(a=>a <= 'k').ToArray(); if(kOver.Length >= target.Count) { ans += target.Count; return ans; } else { ans += kOver.Length; target = target.Skip(kOver.Length).ToList(); } } if(other.Count(a=>a=='k') > 0) { char[] k = other.Where(a=>a=='k').ToArray(); other = other.Where(a=>a!='k').ToArray(); if(k.Length > target.Count) { k = k.Skip(target.Count).ToArray(); other = other.Concat(k).ToArray(); target = target.Select(a=>a + "k").ToList(); } else if(k.Length < target.Count) { target.Skip(k.Length).ToList().ForEach(a=>other = other.Concat(a.ToArray()).ToArray()); target = target.Take(k.Length).Select(a=>a + "k").ToList(); } } else { if(target.Count >= 2) { target.ToList().ForEach(a=>other = other.Concat(a.ToArray()).ToArray()); char[] newY = other.Where(a=>a == 'y').Take(target.Count - 1).ToArray(); other = other.Where(a=>a!='y').Concat(new char[]{'y'}).ToArray(); return ans + this.getAns(other, newY); } else { return ans; } } if(target.Count == 0) { return ans; } if(other.Count(a=>a>'i') > 0) { char[] iOver = other.Where(a=>a>'i').OrderBy(a=>a).ToArray(); other = other.Where(a=>a<='i').ToArray(); if(iOver.Length < target.Count) { ans+=iOver.Length; target = target.Skip(iOver.Length).ToList(); } else { ans+=target.Count; return ans; } } if(other.Count(a=>a=='i') > 0) { char[] i = other.Where(a=>a=='i').ToArray(); other = other.Where(a=>a != 'i').ToArray(); if(i.Length > target.Count) { i = i.Skip(target.Count).ToArray(); other = other.Concat(i).ToArray(); target = target.Select(a=>a + "i").ToList(); } else if(i.Length < target.Count) { target.Skip(i.Length).ToList().ForEach(a=>other = other.Concat(a.ToArray()).ToArray()); target = target.Take(i.Length).Select(a=>a + "i").ToList(); } } else { if(target.Count >= 2) { target.ToList().ForEach(a=>other = other.Concat(a.ToArray()).ToArray()); char[] newY = other.Where(a=>a == 'y').Take(target.Count - 1).ToArray(); other = other.Where(a=>a!='y').Concat(new char[]{'y'}).ToArray(); return ans + this.getAns(other, newY); } else { return ans; } } if(target.Count > 0) { if(other.Length > target.Count) { ans += target.Count; other = other.OrderBy(a=>a).Skip(target.Count).ToArray(); target.Clear(); } else if(other.Length > 0) { ans += other.Length; target = target.Skip(other.Length).ToList(); other = new char[0]; } } if(target.Count > 0) { target.ForEach(a=>other = other.Concat(a.ToArray()).ToArray()); } if(other.Count(a=>a=='y') >= 2) { char[] newY = other.Where(a=>a=='y').Skip(1).ToArray(); other = other.Where(a=>a!='y').Concat(new char[]{'y'}).ToArray(); return ans + this.getAns(other, newY); } return ans; } public class Reader { public static bool IsDebug = true; private static String PlainInput = @" 8 yywxvyyy "; 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(); } }