Skip to content

Instantly share code, notes, and snippets.

@sbsatter
Created June 7, 2019 06:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sbsatter/2fa09e9b14caacb4c78e7af3af3fd7fe to your computer and use it in GitHub Desktop.
Save sbsatter/2fa09e9b14caacb4c78e7af3af3fd7fe to your computer and use it in GitHub Desktop.
# Enter your code here. Read input from STDIN. Print output to STDOUT
n = int(input())
array = sorted(list(map(int, input().split())))
# print(array)
mean = sum(array) / n
if n % 2 == 0:
n1 = n//2
n0 = n1 - 1
median = (array[n0] + array[n1])/2
else:
median = array[n//2]
mode = dict()
key = 0
occurrence = -1
for i in array:
mode[i] = mode.get(i, 0) + 1
(key, occurrence) = (key, occurrence) if occurrence >= mode[i] else (i, mode[i])
# print(key, occurrence)
print(round(mean, 1), round(median, 1), key, sep='\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment