Guest User

Untitled

a guest
Aug 19th, 2019
86
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. n = int(input())
  2. r = list(map(int, input().split()))
  3. rad = []
  4. coun = dict()
  5. j = r[0]
  6. c = 0
  7. for i in r:
  8. if i == j:
  9. c += 1
  10. else:
  11. coun[j] = c
  12. rad.append(j)
  13. j = i
  14. c = 1
  15. coun[j] = c
  16. rad.append(j)
  17. sorted(rad)
  18. ans = []
  19.  
  20. while len(rad) >= 3:
  21. a, b, c = rad[-1], rad[-2], rad[-3]
  22.  
  23. while coun[a] * coun[b] * coun[c] != 0:
  24. ans.append(a)
  25. ans.append(b)
  26. ans.append(c)
  27. coun[a] -= 1
  28. coun[b] -= 1
  29. coun[c] -= 1
  30.  
  31. if coun[a] == 0:
  32. rad.remove(a)
  33. if coun[b] == 0:
  34. rad.remove(b)
  35. if coun[c] == 0:
  36. rad.remove(c)
  37.  
  38. print(len(ans) // 3)
  39. for i in range(0, len(ans) - 2, 3):
  40. print(ans[i], ans[i + 1], ans[i + 2])
RAW Paste Data