using System; using System.Linq; using System.Collections.Generic; using System.Collections; namespace Algorithm { class Program { static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); var a = Console.ReadLine().Split().Select(int.Parse).ToArray(); var continuous = new List(); var cur = a[0]; var count = 1; for (var i = 1; i < n; i++) { if (cur == a[i]) count++; else { continuous.Add(count); count = 1; } cur = a[i]; } continuous.Add(count); var dp = new int[continuous.Count]; dp[0] = continuous[0]; for (var i = 1; i < continuous.Count; i++) { dp[i] = Math.Max(dp[i], dp[i - 1] + continuous[i] - 1); if (i > 1) dp[i] = Math.Max(dp[i], dp[i - 2] + continuous[i]); } Console.WriteLine(dp[continuous.Count - 1]); } } }