Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    a_list = list(map(int, input().split()))

    vals = []
    for i in set(a_list):
        for X in [i]:
            vals.append(len([a for a in a_list if abs(X - a) <= 1]))
    print(max(vals))

if __name__ == '__main__':
    main()


Fixed submission:
import sys
import collections
input = sys.stdin.readline

def main():
    N = int(input())
    a_list = list(map(int, input().split()))
    num_freq = collections.Counter(a_list)

    vals = []
    for X in set(a_list):
        v = 0
        if X in num_freq:
            v += num_freq[X]
        if X - 1 in num_freq:
            v += num_freq[X-1]
        if X + 1 in num_freq:
            v += num_freq[X+1]
        vals.append(v)
    print(max(vals))

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    a_list = list(map(int, input().split()))

    vals = []
    for i in set(a_list):
        for X in [i-1, i, i+1]:
            vals.append(len([a for a in a_list if abs(X - a) <= 1]))
    print(max(vals))

if __name__ == '__main__':
    main()


Fixed submission:
import sys
import collections
input = sys.stdin.readline

def main():
    N = int(input())
    a_list = list(map(int, input().split()))
    num_freq = collections.Counter(a_list)

    vals = []
    for X in set(a_list):
        v = 0
        if X in num_freq:
            v += num_freq[X]
        if X - 1 in num_freq:
            v += num_freq[X-1]
        if X + 1 in num_freq:
            v += num_freq[X+1]
        vals.append(v)
    print(max(vals))

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    a_list = list(map(int, input().split()))

    vals = []
    for i in a_list:
        for X in [i-1, i, i+1]:
            vals.append(len([a for a in a_list if abs(X - a) <= 1]))
    print(max(vals))

if __name__ == '__main__':
    main()


Fixed submission:
import sys
import collections
input = sys.stdin.readline

def main():
    N = int(input())
    a_list = list(map(int, input().split()))
    num_freq = collections.Counter(a_list)

    vals = []
    for X in set(a_list):
        v = 0
        if X in num_freq:
            v += num_freq[X]
        if X - 1 in num_freq:
            v += num_freq[X-1]
        if X + 1 in num_freq:
            v += num_freq[X+1]
        vals.append(v)
    print(max(vals))

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    a_list = list(map(int, input().split()))

    vals = []
    for i in a_list:
        for X in [i-1, i, i+1]:
            vals.append(len([a for a in a_list if abs(X - a) <= 1]))
    print(max(vals))

if __name__ == '__main__':
    main()


Fixed submission:
import sys
import collections
input = sys.stdin.readline

def main():
    N = int(input())
    a_list = list(map(int, input().split()))
    num_freq = collections.Counter(a_list)

    vals = []
    for X in set(a_list):
        v = 0
        if X in num_freq:
            v += num_freq[X]
        if X - 1 in num_freq:
            v += num_freq[X-1]
        if X + 1 in num_freq:
            v += num_freq[X+1]
        vals.append(v)
    print(max(vals))

if __name__ == '__main__':
    main()