#include <vector>
#include <iostream>
using namespace std;
int main()
{
int k = 0, K, l, m, N;
cout << "K N: ";
cin >> K >> N;
vector<int> A(N);
for (l = 0; l < N; ++l) cin >> A[l];
for (l = 0; l < N; ++l)
for (m = l + 1; m < N; ++m)
if (A[l] + A[m] == K) ++k;
cout << k << endl;
return 0;
}
#include <iostream>
#include <vector>
using namespace std;
struct Pair {
using num_t = long;
using sum_t = long long;
num_t a;
num_t b;
bool matches(const sum_t k) const {
return (sum_t)a + (sum_t)b == k;
}
};
class Task {
public:
Task(const vector<Pair::num_t>& present) {
const size_t n = present.size();
const auto m = n - 1;
for (size_t i = 0; i < m; ++i) {
for (size_t j = i + 1; j < n; ++j) {
pairs.emplace_back(Pair{ present[i], present[j] });
}
}
}
size_t count(const Pair::sum_t k) const {
size_t quantity = 0;
for (const auto& item : pairs) {
if (item.matches(k)) {
++quantity;
}
}
return quantity;
}
private:
vector<Pair> pairs;
};
int main() {
size_t n;
cin >> n;
vector<Pair::num_t> present(n);
for (auto& number : present) cin >> number;
Task task(present);
Pair::sum_t k;
cin >> k;
const auto matches = task.count(k);
cout << matches << '\n';
}