awsmpshk

Sjatie

Oct 1st, 2021 (edited)
214
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. n = int(input())
  2. arr = [int(x) for x in input().split()]
  3.  
  4. result = []
  5. count = 1
  6. elem = arr[0]
  7.  
  8. if n == 1:
  9.     print(f'{count} {elem}')
  10. else:
  11.     for i in range(1, n):
  12.         if arr[i] == elem:
  13.             count += 1
  14.             if i == n - 1:
  15.                 result.append(count)
  16.                 result.append(elem)
  17.         else:
  18.             result.append(count)
  19.             result.append(elem)
  20.             elem = arr[i]
  21.             count = 1
  22.             if i == n - 1:
  23.                 result.append(count)
  24.                 result.append(elem)
  25.  
  26.     print(' '.join([str(x) for x in result]))
  27.  
RAW Paste Data Copied