#include #define rep(i, n) for (int i = 0; i < n; ++i) typedef long long ll; using namespace std; int main() { cin.tie(0)->sync_with_stdio(0); int N, M; cin >> N >> M; vector A(N); rep(i, N) cin >> A[i], A[i] *= 2; ll ans = 0, cnt = 0; set st; rep(i, N) { st.insert(A[i]); int rev = (A[i] + M) % (2 * M); if (st.find(rev) != st.end()) { ans += i - 1 + cnt; cnt++; } else { ans += cnt; } } cout << ans << "\n"; return 0; }