Problem:
 Score : 300 points    Problem Statement You are given an integer sequence of length N , a_1,a_2,...,a_N .  For each 1≤i≤N , you have three choices: add 1 to a_i , subtract 1 from a_i or do nothing.  After these operations, you select an integer X and count the number of i such that a_i=X .  Maximize this count by making optimal choices.      Constraints  1≤N≤10^5  0≤a_i<10^5 (1≤i≤N)  a_i is an integer.         Input The input is given from Standard Input in the following format:  N  a_1  a_2 .. a_N       Output Print the maximum possible number of i such that a_i=X .        Sample Input 1 7
3 1 4 1 5 9 2      Sample Output 1 4  For example, turn the sequence into 2,2,3,2,6,9,2 and select X=2 to obtain 4 , the maximum possible count.       Sample Input 2 10
0 1 2 3 4 5 6 7 8 9      Sample Output 2 3       Sample Input 3 1
99999      Sample Output 3 1

Solution (Python):
from collections import defaultdict

def main():
    _ = int(input())

    d = defaultdict(lambda: 0)
    for a in [int(i) for i in input().split()]:
        d[a-1] += 1
        d[a] += 1
        d[a+1] += 1
    print(sorted(d.items(), key=lambda x: x[1], reverse=True)[0][1])
        

if __name__ == "__main__":
    main()

Solution (Python):
from collections import Counter

N = int(input())
As = list(map(int, input().split()))
box = []

for a in As:
    box.append(a)
    box.append(a+1)
    box.append(a-1)
    
cnt = Counter(box).most_common(1)
print(cnt[0][1])

Solution (Python):
from collections import Counter

N = map(int, input())

cnt = Counter()

a = input().split()
for v in a:
    cnt[str(int(v) - 1)] += 1
    cnt[v] += 1
    cnt[str(int(v) + 1)] += 1

print(cnt.most_common(1)[0][1])

Solution (Python):
N = int(input())
d = dict()
for a in map(int,input().split()):
  if a-1 in d:
    d[a-1] += 1
  else:
    d[a-1] = 1
  if a in d:
    d[a] += 1
  else:
    d[a] = 1
  if a+1 in d:
    d[a+1] += 1
  else:
    d[a+1] = 1
print(max(d.values()))

Solution (Python):
N = int(input())
src = list(map(int, input().split()))
MAX = 10**5

counts = [0 for i in range(MAX+1)]
for a in src:
    if a > 0: counts[a-1] += 1
    counts[a] += 1
    counts[a+1] += 1

print(max(counts))

Solution (Python):
temp = input().split(" ")
n = int(temp[0])
inp = input().split(" ")
nums = [0 for a in range(100003)]
for a in range(n):
    nums[int(inp[a])+1]+=1
    nums[int(inp[a])+2]+=1
    nums[int(inp[a])]+=1
print(max(nums))

Solution (Python):
from sys import stdin
di = {}
n = int(stdin.readline())
a = map(int,stdin.readline().split())
for i in a:
 di[i] = di.get(i,0) + 1
 di[i-1] = di.get(i-1,0) + 1
 di[i+1] = di.get(i+1,0) + 1
ans = -5
for i in di:
 if di[i] > di.get(ans,0):
  ans = i
print di[ans]

Solution (Python):

def get_ln_inputs():
    return input().split()


def get_ln_int_inputs():
    return list(map(int, get_ln_inputs()))


def main():
    A_MAX = 10 ** 5

    N = get_ln_int_inputs()[0]
    a = get_ln_int_inputs()
    counts = [0 for _ in range(A_MAX)]

    for num in a:
        counts[num] += 1
    
    max_count = 0
    for target in range(1, A_MAX - 1):
        count = counts[target - 1] + counts[target] + counts[target + 1]
        max_count = max(count, max_count)

    print(max_count)

main()

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
f = [0 for x in range(10**5 + 10)]
for i in a:
    f[i] += 1
    f[i + 1] += 1
    f[i - 1] += 1


print(max(enumerate(f), key=lambda x: x[1])[1])

Solution (Python):
from collections import  Counter
N =int(input())

a= list(map(int,input().split()))

c = Counter(a)
new_c = Counter(a)
for key,val in c.items():
    new_c[key-1] +=val
    new_c[key+1] += val

print(new_c.most_common()[0][1])