Advertisement
arvind_iyer_2001

Untitled

Jun 28th, 2021
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.37 KB | None | 0 0
  1. import math
  2. def main():
  3.     s_e()
  4.  
  5. def s_a():
  6.     a, b, c = tuple([int(x) for x in input().split()])
  7.     result = math.ceil(c*(a-b)/b)
  8.     print(result)
  9.  
  10. def s_b():
  11.     n, m = tuple([int(x) for x in input().split()])
  12.     cumsum = [0]
  13.     for i in range(n):
  14.         c, t = tuple([int(x) for x in input().split()])
  15.         cumsum.append(cumsum[i] + c * t)
  16.     v = [int(x) for x in input().split()]
  17.     l = 0
  18.     j = 0
  19.     for i in range(1,n+1):
  20.         while j<m and v[j] <= cumsum[i] :
  21.             print(i)
  22.             j += 1
  23.  
  24. def s_c():
  25.     n, m, k, t = tuple([int(x) for x in input().split()])
  26.     waste = []
  27.     qr = []
  28.     for i in range(k):
  29.         x, y = tuple([int(x) for x in input().split()])
  30.         pos = (x-1)*m + y-1
  31.         waste.append(pos)
  32.     waste.sort()
  33.     for i in range(t):
  34.         x, y = tuple([int(x) for x in input().split()])
  35.         pos = (x-1)*m + y-1
  36.         if(pos in waste):
  37.             qr.append('Waste')
  38.             continue
  39.         wastes = searchInsert(waste,pos)
  40.         res = (pos - wastes)%3
  41.         if(res == 0):
  42.             qr.append('Carrots')
  43.         elif (res == 1):
  44.             qr.append('Kiwis')
  45.         elif (res == 2):
  46.             qr.append('Grapes')
  47.     for i in qr:
  48.         print(i)
  49. def searchInsert(arr, x):
  50.     l = 0
  51.     r = len(arr) - 1
  52.     mid = 0
  53.     while l <= r:
  54.         mid = (l + r) // 2;
  55.         if arr[mid] == x:
  56.             return mid
  57.         elif arr[mid] < x:
  58.             l = mid + 1
  59.             if (r == mid):
  60.                 mid = r + 1
  61.                 break
  62.         else:
  63.             r = mid - 1
  64.             if (l == mid):
  65.                 break
  66.     return mid
  67.  
  68. def s_d():
  69.     n = int(input())
  70.     arr = []
  71.     s = 0
  72.     for i in range(n):
  73.         arr.append(int(input()))
  74.     arr.sort()
  75.     for i in range(n):
  76.         s +=  arr[i] * arr[n-i-1]
  77.  
  78.     print(s%10007)
  79.  
  80. def s_e():
  81.     n = int(input())
  82.     a = [int(x) for x in input().split()]
  83.     m = 1
  84.     ma = []
  85.     l = 1
  86.     prev = 0
  87.     while l< n:
  88.         if(a[l] == a[l-1]):
  89.             m+= 1
  90.         elif(abs(a[l-1] - a[l]) <= 1):
  91.             if(a[prev] == a[l]):
  92.  
  93.                 m+=1
  94.             else:
  95.                 ma.append(m)
  96.                 prev = l-1
  97.                 m = 1
  98.         else:
  99.             ma.append(m)
  100.             prev = l - 1
  101.             m = 1
  102.         l+=1
  103.     print(ma)
  104.  
  105.  
  106.  
  107.  
  108. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement