using System; using System.Collections.Generic; using System.IO; using System.Linq; class Solution { static void Main(String[] args) { int n = Convert.ToInt32(Console.ReadLine()); string[] a_temp = Console.ReadLine().Split(' '); int[] a = Array.ConvertAll(a_temp,Int32.Parse); var sorted = a.OrderBy(i => i).ToArray(); var result = 1; var currentCounter = 1; var lowVal = sorted[0]; //first value of streak var lastValIdx = 0; //start at first item for(int i=1; i < n; i++) { var cur = sorted[i]; //last streak is over, need to start a new one if (cur - lowVal > 1) { if (cur - sorted[lastValIdx] > 1) { lastValIdx = i; currentCounter = 1; lowVal = cur; continue; //don't let counter below increment } else { //new streak is in-progress set counter to difference of last change and reset lowval currentCounter = i - lastValIdx; lowVal = sorted[lastValIdx]; lastValIdx = i; } } else if (cur > sorted[lastValIdx]) { //need to increment last val idx but we're still within 2 to streak continues lastValIdx = i; } currentCounter++; if (result < currentCounter) { result = currentCounter; } } Console.WriteLine(result); } }