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 total = 0; for (var i = 0; i < continuous.Count; i++) { if (i % 2 == 0) total += continuous[i]; else { if (i == continuous.Count - 1) total += Math.Max(continuous[i] - 1, 0); else total += Math.Max(continuous[i] - 2, 0); } } var total2 = 0; ; for (var i = 0; i < continuous.Count; i++) { if (i % 2 == 1) total2 += continuous[i]; else { if (i == 0) total2 += Math.Max(continuous[i] - 1, 0); else total2 += Math.Max(continuous[i] - 2, 0); } } Console.WriteLine(Math.Max(total, total2)); } } }