// yukicoder: No.723 2つの数の和 // 2019.4.21 bal4u #include #include #if 1 #define gc() getchar_unlocked() #else #define gc() getchar() #endif int in() // 非負整数の入力 { int n = 0, c = gc(); do n = 10 * n + (c & 0xf), c = gc(); while (c >= '0'); return n; } int cmp(const void *a, const void *b) { return *(int *)a - *(int *)b; } int N, X; int a[100005]; int f[100005]; int uniq(int *a, int n) { int i, j, k; for (i = 0, j = 1; j <= n; j++) { k = j; while (j < n && a[i] == a[j]) j++; f[i] = j-k+1; if (j < n) if (++i != j) a[i] = a[j]; } return i+1; } #if 1 int main() { int i, j; long long ans; N = in(), X = in(); for (i = 0; i < N; i++) a[i] = in(); qsort(a, N, sizeof(int), cmp); N = uniq(a, N); i = 0, j = N-1, ans = 0; while (i <= j) { while (i < N && a[i] + a[j] < X) i++; while (j >= 0 && a[i] + a[j] > X) j--; if (i == j) { if ((a[i]<<1) == X) ans += (long long)f[i]*f[i]; break; } if (i <= j && a[i]+a[j] == X) ans += ((long long)f[i]*f[j])<<1, i++; } printf("%lld\n", ans); return 0; } #else int main() { int i, j, ans; N = in(), X = in(); for (i = 0; i < N; i++) a[i] = in(); ans = 0; for (i = 0; i < N; i++) { for (j = 0; j < N; j++) { if (a[i]+a[j] == X) ans++; } } printf("ans=%d\n", ans); return 0; } #endif