import sys input = lambda :sys.stdin.readline()[:-1] ni = lambda :int(input()) na = lambda :list(map(int,input().split())) yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES") no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO") ####################################################################### n, m = na() if m % 2: print(0) exit() a = na() a = a + [m + x for x in a] j = 0 ans = 0 #print(a) for i in range(n * 2): while j < i and a[i] - a[j] > m//2: j += 1 if i >= n and a[i] - a[j] == m//2: ans += i - j - 1 #print(i, j) print(ans)