Advertisement
Guest User

Untitled

a guest
May 25th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.29 KB | None | 0 0
  1. N = int(input())
  2.  
  3. nechet = [0] * 7
  4. chet = [0] * 7
  5. res = 0
  6.  
  7. def cnt(i, j, k):
  8.     global res
  9.     if i == j == k:
  10.         res += nechet[i]*(nechet[i] - 1)*(nechet[i] - 2) // 6 \
  11.                + nechet[i] * chet[i] * (chet[i] - 1) // 2
  12.     elif i == j:
  13.         res += nechet[i] * (nechet[i] - 1) * nechet[k] // 2 \
  14.                + chet[i] * (chet[i] - 1) * nechet[k] // 2 \
  15.                + chet[i] * nechet[i] * chet[k]
  16.     elif j == k:
  17.         res += nechet[j] * (nechet[j] - 1) * nechet[i] // 2\
  18.                + chet[j] * (chet[j] - 1) * nechet[i] // 2 \
  19.                + chet[j] * nechet[j] * chet[i]
  20.     elif i == k:
  21.         res += nechet[i] * (nechet[i] - 1) * nechet[j] // 2\
  22.                + chet[i] * (chet[i] - 1) * nechet[j] // 2\
  23.                + chet[i] * nechet[i] * chet[j]
  24.     else:
  25.         res += nechet[i] * nechet[j] * nechet[k]\
  26.                + chet[i] * chet[j] * nechet[k]\
  27.                + chet[i] * nechet[j] * chet[k]\
  28.                + nechet[i] * chet[j] * chet[k]
  29.  
  30. for i in range(N):
  31.     num = int(input())
  32.     if num % 2 == 0:
  33.         chet[num % 7] += 1
  34.     else:
  35.         nechet[num % 7] += 1
  36.  
  37. for i in range(0, 7):
  38.     for j in range(i, 7):
  39.         for k in range(j, 7):
  40.             if (i + j + k) % 7 == 0:
  41.                 cnt(i, j, k)
  42. print(res)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement