text stringlengths 49 983k |
|---|
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
long long n, m, k, x, y, z;
bool sortbysec(const pair<long long, long long> &a,
const pair<long long, long long> &b) {
return (a.second < b.second);
}
bool sortbyfi(const pair<long long, pair<long long, long long>> &a,
const pair<long long, pair<long long, long long>> &b) {
return (a.first > b.first);
}
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>>
pq;
void Birdperson() {
cin >> n >> m;
int a[11];
memset(a, 0, sizeof(a));
for (long long i = 0; i < n; i++) {
cin >> x;
a[x]++;
}
long long ans = 0;
for (int i = 1; i <= 10; i++) {
for (int j = i + 1; j <= 10; j++) {
ans += (a[i] * a[j]);
}
}
cout << ans << "\n";
}
int main() {
std::ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long t = 1;
while (t--) {
Birdperson();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
const int N = 400005;
const int MOD = 1000000007;
const int M = 1000005;
long long a[10005];
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < n; ++i) {
int x;
cin >> x;
x--;
a[x]++;
}
long long ans = 0;
for (int i = 0; i < m; ++i)
for (int j = i + 1; j < m; ++j) {
ans += a[i] * a[j];
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int N, M, arr[maxn], vis[maxn];
int main() {
scanf("%d%d", &N, &M);
for (int i = 1; i <= N; i++) scanf("%d", arr + i), vis[arr[i]]++;
long long ans = 0;
for (int i = 1; i <= M; i++) {
ans += vis[i - 1] * vis[i];
vis[i] += vis[i - 1];
}
printf("%lld\n", ans);
}
|
#include <bits/stdc++.h>
using namespace std;
long long int a[12], n, m, res = 0, k;
int main() {
memset(a, 0, sizeof a);
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> k;
a[k]++;
}
for (int i = 1; i <= 10; i++)
for (int j = i + 1; j <= 10; j++) res += (a[i] * a[j]);
cout << res << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long ar[10];
int main() {
int n, m, i, j, k;
long long s = 0;
cin >> n >> m;
for (i = 0; i < n; i++) {
int p;
scanf("%d", &p);
ar[p - 1]++;
}
for (i = 0; i < m - 1; i++) {
for (j = i + 1; j < m; j++) {
s += ar[i] * ar[j];
}
}
cout << s;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 1000000007;
constexpr int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
constexpr int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1},
dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U>
inline bool chmax(T &a, U b) {
return a < b ? (a = b, true) : false;
}
template <typename T, typename U>
inline bool chmin(T &a, U b) {
return a > b ? (a = b, true) : false;
}
struct IOSetup {
IOSetup() {
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
std::cout << fixed << setprecision(20);
}
} iosetup;
int main() {
int n, m;
cin >> n >> m;
vector<int> book(m, 0);
while (n--) {
int a;
cin >> a;
--a;
++book[a];
}
int ans = 0;
for (int i = (0); i < (m); ++i)
for (int j = (i + 1); j < (m); ++j) ans += book[i] * book[j];
cout << ans << '\n';
return 0;
}
|
#include <bits/stdc++.h>
const unsigned long long inf = 1LL << 61;
const double eps = 1e-5;
using namespace std;
bool cmp(int a, int b) { return a > b; }
long long a[200000 + 10];
int main() {
long long n, m;
while (cin >> n >> m) {
map<int, int> mp;
int b[20];
memset(b, 0, sizeof(b));
int num = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
if (!mp[a[i]]) {
mp[a[i]] = 1;
} else {
b[a[i]]++;
}
}
long long sum = 0;
for (int i = 1; i <= m; i++) {
int x = b[i];
sum += 1ll * x * (x + 1) / 2;
}
long long x = n * (n - 1);
printf("%I64d\n", (x / 2 - sum));
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<int> books(m);
for (int i = 0; i < n; i++) {
int c;
cin >> c;
books[c - 1]++;
}
int choice = 0;
for (int i = 0; i < m; i++) {
for (int j = i + 1; j < m; j++) {
choice += books[i] * books[j];
}
}
cout << choice << endl;
return 0;
}
|
#include <bits/stdc++.h>
int cnt[20];
int main() {
int n, crt;
scanf("%d%*d", &n);
while (n--) {
scanf("%d", &crt);
cnt[crt]++;
}
long long ans = 0;
for (int i = 1; i < 10; i++)
for (int j = i + 1; j <= 10; j++) ans += 1LL * cnt[i] * cnt[j];
printf("%I64d\n", ans);
}
|
#include <bits/stdc++.h>
using namespace std;
int a[262144];
int main() {
int n, m, i, tbr = 0, ans = 0;
cin >> n >> m;
for (i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
tbr = 1;
for (i = 1; i < n; i++) {
if (a[i] == a[i - 1])
tbr++;
else {
ans += (n - i) * tbr;
tbr = 1;
}
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m, i, j, k, l, t, s = 0, a, temp[11] = {0}, cnt = 0;
long long r1 = 1, r2 = 1, r, r3;
cin >> n >> m;
for (i = 0; i < n; i++) {
cin >> a;
temp[a]++;
}
for (i = 1; i <= m; i++) {
for (j = i + 1; j <= m; j++) {
s = s + (temp[i] * temp[j]);
}
}
cout << s << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int mx = 1e5;
int main() {
int n, m;
cin >> n >> m;
vector<int> a(n), cnt(11);
for (int i = 0; i < n; i++) {
cin >> a[i];
cnt[a[i]]++;
}
unsigned long long ans = 0;
for (int i = 0; i <= 10; i++) {
int sm = n;
sm -= cnt[i];
ans += 1LL * cnt[i] * sm;
}
cout << ans / 2;
}
|
#include <bits/stdc++.h>
const int maxm = 15;
long long Ans;
int n, m, a[maxm];
int main() {
scanf("%d%d", &n, &m);
memset(a, 0, sizeof(a));
for (int i = 1; i <= n; i++) {
int x;
scanf("%d", &x);
a[x]++;
}
Ans = 1LL * n * (n - 1);
for (int i = 1; i <= m; i++) {
Ans = Ans - 1LL * a[i] * (a[i] - 1);
}
printf("%I64d\n", Ans / 2);
}
|
#include <bits/stdc++.h>
using namespace std;
struct _ {
ios_base::Init i;
_() {
cin.sync_with_stdio(0);
cin.tie(0);
}
} _;
long long power(long long a, long long n) {
long long ans = 1;
while (n) {
if (n % 2 == 1) ans *= a;
a *= a;
n /= 2;
}
return ans;
}
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int main() {
int n, m;
cin >> n >> m;
int arr[m + 2];
memset(arr, 0, sizeof arr);
int i, x;
for (i = 0; i < n; i++) {
cin >> x;
arr[x]++;
}
long long sum[m + 2];
sum[1] = arr[1];
for (i = 2; i < m + 1; i++) sum[i] = sum[i - 1] + arr[i];
long long ans = 0;
for (i = 1; i < m + 1; i++) ans += arr[i] * (sum[m] - sum[i]);
cout << ans << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18 + 5;
const long long MAX_N = 2e5 + 5;
const long long MODD = 1e9 + 7;
const long long BITS = 10;
long long max(long long a, long long b) { return a > b ? a : b; }
long long min(long long a, long long b) { return a < b ? a : b; }
double max(double a, double b) { return a > b ? a : b; }
double min(double a, double b) { return a < b ? a : b; }
long long modd(long long a) {
if (a < 0LL) return a * -1LL;
return a;
}
double modd(double a) {
if (a < 0.0) return a * -1.0;
return a;
}
long long modulo(long long a) { return (a + MODD) % MODD; }
void swap(long long &a, long long &b) {
long long t = a;
a = b;
b = t;
}
long long power(long long k, long long p) {
if (p == 0) return 1LL;
long long P = power(k, p / 2LL);
P = (P * P) % MODD;
if (p % 2 == 1) P = (P * k) % MODD;
return P;
}
int iii = 0;
void _debug() { cout << "here " << (iii++) << endl; }
void solve() {
long long n, m;
cin >> n >> m;
long long a[n];
for (long long i = 0; i < n; i++) {
cin >> a[i];
}
long long cnt[m + 5];
memset(cnt, 0, sizeof(cnt));
for (long long i = 0; i < n; i++) {
cnt[a[i]]++;
}
long long ans = 0;
for (long long i = 0; i < n; i++) {
cnt[a[i]]--;
long long val = n - i - 1;
val -= cnt[a[i]];
val = max(0, val);
ans += val;
}
cout << ans << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long t = 1;
for (long long i = 0; i < t; i++) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, m, x = 1, y = 1, a[1000100], cr, tr, u[1000100];
int main() {
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
u[a[i]]++;
}
x = 0;
for (int i = 1; i <= m; ++i) {
n -= u[i];
x += u[i] * n;
}
cout << x;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int num[200005], n, m, i, ans;
int main() {
scanf("%d%d", &n, &m);
memset(num, 0, sizeof(num));
for (i = 0; i < n; ++i) {
scanf("%d", num);
++num[num[0]];
}
ans = 0;
for (i = 1; i < m; ++i) {
n -= num[i];
ans += num[i] * n;
}
printf("%d\n", ans);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long ar[1000001];
long long nCr(long long n, long long r) {
long long i, c = 1;
for (i = 1; i <= r; i++) {
c *= (n - r + i);
c /= i;
}
return c;
}
int main() {
long long i, j, k, n, m, sum, k1;
cin >> n >> m;
for (i = 0; i < n; i++) {
cin >> sum;
ar[sum]++;
}
k = nCr(n, 2);
for (j = 0; j <= m; j++) {
k -= nCr(ar[j], 2);
}
cout << k;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m;
cin >> n >> m;
long long a[n];
for (long long i = 0; i < n; i++) cin >> a[i];
long long h[11] = {0};
for (long long i = 0; i < n; i++) h[a[i]]++;
long long sum = 0;
for (long long i = 1; i <= 10; i++) {
for (long long j = i + 1; j <= 10; j++) sum += (h[i] * h[j]);
}
cout << sum << "\n";
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, g;
cin >> n >> g;
vector<long long> v, ans;
map<long long, long long> m;
map<long long, long long>::iterator it;
for (int i = 0; i < n; i++) {
long long a;
cin >> a;
m[a]++;
}
for (it = m.begin(); it != m.end(); ++it) {
v.push_back(it->second);
}
long long s1 = 0;
for (int i = 0; i < v.size() - 1; i++) {
long long s = 0;
for (int j = i + 1; j < v.size(); j++) {
s += v[j];
}
s1 += s * v[i];
}
cout << s1 << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, m, genre[15], x, ans;
int main() {
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> x;
genre[x]++;
}
for (int i = 1; i < m; i++) {
for (int j = i + 1; j <= m; j++) {
ans += genre[i] * genre[j];
}
}
cout << ans << '\n';
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, i, j = 1;
cin >> n >> m;
long long total = 0;
int book[n];
for (i = 0; i < n; i++) cin >> book[i];
sort(book, book + n);
for (i = n - 1; i > 0; i--) {
if (book[i] == book[i - 1]) {
j++;
} else {
total += j * i;
j = 1;
}
}
cout << total;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, m, s, a, b[15];
int main() {
int i, j;
cin >> n >> m;
for (i = 0; i < n; i++) {
scanf("%d", &a);
b[a]++;
}
for (i = 1; i <= m; i++) {
for (j = i + 1; j <= m; j++) {
s += b[j] * b[i];
}
}
cout << s << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long M = 1000000007;
void fast() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
long long power(long long base, long long n) {
if (n == 0) return 1;
if (n == 1) return base;
long long halfn = power(base, n / 2);
if (n % 2 == 0)
return (halfn * halfn) % M;
else
return (((halfn * halfn) % M) * base) % M;
}
void solve() {
long long n, m;
cin >> n >> m;
vector<long long> a(n);
for (auto& i : a) cin >> i;
map<long long, long long> mp;
for (auto i : a) mp[i]++;
long long c = 0;
for (long long i = 1; i <= m; i++) {
for (long long j = i + 1; j <= m; j++) {
c += mp[i] * mp[j];
}
}
long long x = (n * (n - 1)) / 2;
long long c1 = 0;
for (long long i = 1; i <= m; i++) {
c1 += (mp[i] * (mp[i] - 1)) / 2;
}
cout << x - c1;
}
int main() {
fast();
solve();
return 0;
}
|
#include <bits/stdc++.h>
int main() {
int n, i, j, m, s = 0;
scanf("%d %d", &n, &m);
int arr1[m + 1];
for (i = 0; i <= m; i++) {
arr1[i] = 0;
}
for (i = 0; i < n; i++) {
scanf("%d", &j);
arr1[j]++;
}
for (i = 1; i < m; i++) {
for (j = i + 1; j <= m; j++) {
s += arr1[i] * arr1[j];
}
}
printf("%d\n", s);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int sgn(int a) {
if (a < 1) return -1;
if (a == 0) return 0;
return 1;
}
int main() {
int n, m, b;
cin >> n >> m;
int a[m];
fill(a, a + m, 0);
for (int i = 0; i < n; ++i) {
cin >> b;
++a[b - 1];
}
int ans = 0, foo = 0;
for (int i = 0; i < m - 1; ++i) {
for (int j = i + 1; j < m; ++j) {
foo += a[j];
}
foo *= a[i];
ans += foo;
foo = 0;
}
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int g[100] = {0}, m, n, i, j, a, ans = 0;
cin >> n >> m;
for (i = 1; i <= n; i++) {
cin >> a;
g[a]++;
}
for (i = 1; i <= m; i++)
for (j = i + 1; j <= m; j++) ans += g[i] * g[j];
cout << ans;
}
|
#include <bits/stdc++.h>
using namespace std;
int num[11];
int n, m;
int main() {
int i, j;
memset(num, 0, sizeof(num));
scanf("%d%d", &n, &m);
for (i = 0; i < n; i++) {
scanf("%d", &j);
num[j]++;
}
long long ans = 0;
for (i = 1; i <= 10; i++) {
if (num[i] == 0) continue;
for (j = i + 1; j <= 10; j++) {
if (num[j] == 0) continue;
ans += num[i] * num[j];
}
}
printf("%I64d\n", ans);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void debug_out() { cerr << "\n"; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << ' ' << H;
debug_out(T...);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(12);
int n;
cin >> n;
int k;
cin >> k;
vector<long long int> v(k + 1);
for (int i = 0, x; i < n; ++i) {
cin >> x;
v[x]++;
}
long long int cnt = 0;
long long int sum = accumulate(v.begin(), v.end(), 0ll);
for (int i = 1; i <= k; ++i) {
sum -= v[i];
cnt += ((v[i]) * sum);
}
cout << cnt << "\n";
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
int genre[12];
cin >> n >> m;
for (int i = 1; i <= m; ++i) genre[i] = 0;
int a;
for (int i = 0; i < n; ++i) {
cin >> a;
genre[a]++;
}
long long int ans = 0;
for (int i = 1; i < m; ++i) {
for (int j = i + 1; j <= m; ++j) ans += (long long int)genre[i] * genre[j];
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
int m;
cin >> n >> m;
vector<int> a(m, 0);
for (int i = 0; i < n; ++i) {
int buf;
cin >> buf;
++a[buf - 1];
}
long long ans = 0;
for (int i = 0; i < m; ++i) {
for (int j = i + 1; j < m; ++j) {
ans += a[i] * a[j];
}
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, n, m, data;
long long int ans = 0;
scanf("%d%d", &n, &m);
int arr[m + 1];
memset(arr, 0, sizeof(arr));
for (i = 0; i < n; i++) {
cin >> data;
arr[data] += 1;
}
for (i = 1; i <= m; i++) {
if (arr[i]) {
ans += (n - arr[i]) * arr[i];
}
}
printf("%lld", ans / 2);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int a, i, cnt[11] = {0};
for (i = 0; i < n; i++) {
cin >> a;
cnt[a]++;
}
long long ans = ((long long)n * (n + 1)) / 2;
for (i = 0; i <= m; i++) {
ans = ans - ((long long)cnt[i] * (1 + cnt[i])) / 2;
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long int a[15];
int main() {
long long int n, i, m, x;
long long int sum, t;
while (cin >> n >> m) {
memset(a, 0, sizeof(a));
for (i = 0; i < n; i++) {
cin >> x;
a[x]++;
}
t = 0;
sum = 0;
for (i = 1; i <= m; i++) {
if (a[i] > 1) {
t += a[i] * (a[i] - 1) / 2;
}
}
sum = n * (n - 1) / 2 - t;
cout << sum << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int a[200005];
for (int i = 1; n >= i; ++i) {
int b;
cin >> b;
a[b]++;
}
long long ans = 0;
for (int i = 1; m >= i; ++i) {
ans += (long long)a[i] * (n - a[i]);
}
cout << ans / 2;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int many, genre;
cin >> many >> genre;
map<int, int> mapping;
for (int i = 0; i < many; i++) {
int temp;
cin >> temp;
mapping[temp]++;
}
int answer = 0;
for (int i = 1; i <= genre; i++)
for (int j = i + 1; j <= genre; j++) answer += mapping[i] * mapping[j];
cout << answer << endl;
cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << " ms\n";
return 0;
}
|
#include <bits/stdc++.h>
int main() {
long long int i, j, n, m, ans;
scanf("%lld%lld", &n, &m);
long long int a[m + 1];
for (i = 0; i <= m; i++) a[i] = 0;
for (i = 0; i < n; i++) {
scanf("%lld", &j);
a[j]++;
}
ans = n * (n - 1) / 2;
for (i = 1; i <= m; i++) ans -= a[i] * (a[i] - 1) / 2;
printf("%lld", ans);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long n, m, a, tl, Ans;
map<long long, long long> mp;
int main() {
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> a;
mp[a]++;
}
tl = n;
for (int i = 1; i <= m; i++) {
Ans += ((tl - mp[i]) * mp[i]);
tl -= mp[i];
}
cout << Ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, a[200000], b[11] = {1};
long long sum = 0;
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> a[i];
b[a[i]]++;
}
for (int i = 0; i < n; i++) sum += n - 1 - i - (b[a[i]]-- - 1);
cout << sum;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
long long n, s, d1, d = 0;
long long m, num;
cin >> n >> m;
long long a[m];
for (long long i = 0; i < m; i++) a[i] = 0;
for (long long i = 0; i < n; i++) {
cin >> num;
a[num - 1]++;
}
s = n * (n - 1) / 2;
for (long long i = 0; i < m; i++) {
if (a[i] > 1) {
d1 = a[i] * (a[i] - 1) / 2;
d += d1;
}
}
s -= d;
cout << s << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int a[11];
int main() {
int n, m;
cin >> n >> m;
int ans = 0;
for (int i = 1; i <= n; i++) {
int p;
cin >> p;
a[p]++;
}
for (int i = 1; i <= 9; i++)
for (int j = i + 1; j <= 10; j++) ans += a[i] * a[j];
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, g;
cin >> n >> m;
int count[m];
fill(count, count + m, 0);
for (int i = 0; i < n; i++) {
cin >> g;
count[g - 1]++;
}
long long ans = 0;
for (int i = 0; i < m; i++) ans += count[i] * (n - count[i]);
cout << ans / 2 << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
inline int in() {
int32_t x;
scanf("%d", &x);
return x;
}
int a[111];
int32_t main() {
int n = in(), m = in();
for (int i = 0; i < n; i++) a[in()]++;
long long ans = (n * 1ll * (n - 1)) / 2;
for (int i = 0; i <= m; i++) ans -= (a[i] * 1ll * (a[i] - 1)) / 2;
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int a[n];
long long num[m], ans = 0;
int k = 0;
for (int x = 0; x < m; x++) {
num[x] = 0;
}
for (int x = 0; x < n; x++) {
scanf("%d", &a[x]);
num[a[x] - 1] += 1;
}
for (int x = 0; x < m; x++) {
if (num[x] > 0) k += 1;
}
ans += k * (k - 1) / 2;
int p = k;
for (int x = 0; x < m; x++) {
if (num[x] > 1) {
ans += (p - 1) * (num[x] - 1);
p += num[x] - 1;
}
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int num[n];
int cont = 0;
int can[m];
for (int i = 1; i <= m; i++) {
can[i] = 0;
}
for (int i = 0; i < n; i++) {
cin >> num[i];
can[num[i]]++;
}
for (int i = 1; i <= m - 1; i++) {
for (int j = i + 1; j <= m; j++) {
cont = cont + can[i] * can[j];
}
}
cout << cont << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
int m;
cin >> n >> m;
int a[n];
map<int, int> q;
for (int i = 0; i < n; i++) {
cin >> a[i];
q[a[i]]++;
}
sort(a, a + n);
long long ans1 = 0;
for (int i = 0; i < n - 1; i++) {
if (a[i] != a[i + 1]) {
ans1 += (n - i - 1) * q[a[i]];
}
}
cout << ans1;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
int m;
long long counts[10];
memset(counts, 0, sizeof(counts));
cin >> n >> m;
for (int i = 0; i < n; i++) {
int num;
cin >> num;
counts[num - 1]++;
}
long long result = n * (n - 1) / 2;
for (int i = 0; i < m; i++) {
result -= counts[i] * (counts[i] - 1) / 2;
}
cout << result << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
cin >> n;
int m;
cin >> m;
vector<int> a;
int k;
long long int n1 = 0, n2 = 0, n3 = 0, n4 = 0, n5 = 0, n6 = 0, n7 = 0, n8 = 0,
n9 = 0, n10 = 0;
for (long long int i = 0; i < n; i++) {
cin >> k;
a.push_back(k);
if (a[i] == 1) {
n1++;
} else if (a[i] == 2) {
n2++;
} else if (a[i] == 3) {
n3++;
} else if (a[i] == 4) {
n4++;
} else if (a[i] == 5) {
n5++;
} else if (a[i] == 6) {
n6++;
} else if (a[i] == 7) {
n7++;
} else if (a[i] == 8) {
n8++;
} else if (a[i] == 9) {
n9++;
} else if (a[i] == 10) {
n10++;
}
}
long long int nb = 0;
nb = n1 * (n2 + n3 + n4 + n5 + n6 + n7 + n8 + n9 + n10) +
n2 * (n3 + n4 + n5 + n6 + n7 + n8 + n9 + n10) +
n3 * (n4 + n5 + n6 + n7 + n8 + n9 + n10) +
n4 * (n5 + n6 + n7 + n8 + n9 + n10) + n5 * (n6 + n7 + n8 + n9 + n10) +
n6 * (n7 + n8 + n9 + n10) + n7 * (n8 + n9 + n10) + n8 * (n9 + n10) +
n9 * n10;
cout << nb;
return 0;
}
|
#include <bits/stdc++.h>
int main() {
long n, m;
scanf("%ld %ld\n", &n, &m);
std::vector<long> count(m, 0);
for (long p = 0; p < n; p++) {
long genre;
scanf("%ld", &genre);
++count[--genre];
}
long long total(0);
for (long p = 0; p < m; p++) {
for (long q = p + 1; q < m; q++) {
total += count[p] * count[q];
}
}
printf("%lld\n", total);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
map<int, int> mm;
vector<int> vv(555555, 0);
vector<int> v(n);
for (int i = 0; i < n; i++) cin >> v[i], mm[v[i]]++;
sort(v.begin(), v.end());
set<int> s;
long long sum = 0;
for (int i = 0; i < n; i++) {
if (!s.count(v[i])) {
int x = n - (i + 1) - (mm[v[i]] - 1);
sum += x;
s.insert(v[i]);
vv[v[i]] = x;
} else {
sum += vv[v[i]];
}
}
cout << sum;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
long n, k, a[12];
long i, j, t, x, y, z, ans;
ans = 0;
memset(a, 0, sizeof(a));
cin >> n >> k;
for (i = 0; i < n; i++) {
cin >> x;
a[x]++;
}
for (i = 1; i < k; i++)
for (j = i + 1; j <= k; j++) ans += a[i] * a[j];
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
inline bool isEq(double a, double b) { return (abs(a - b) < 1e-9); }
inline double NegZero(double x) {
if (isEq(x, -0.0))
return +0.0;
else
return x;
}
long long nCr(long long n, long long r) {
long long c = 1;
for (int i = 1; i <= r; i++) {
c *= n;
c /= i;
n--;
}
return c;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n, m, ara[15], rep = 0, g;
cin >> n >> m;
memset(ara, 0, sizeof(ara));
for (int i = 0; i < n; i++) {
cin >> g;
ara[g]++;
}
long long C = nCr(n, 2);
for (int i = 1; i <= m; i++) {
if (ara[i] > 1) C -= nCr(ara[i], 2);
}
cout << C;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int getint() {
char c;
for (c = getchar(); c < '0' || c > '9'; c = getchar())
;
int t = c - 48;
for (c = getchar(); c >= '0' && c <= '9'; c = getchar()) t = t * 10 + c - 48;
return t;
}
void putint(int n) {
char a[9];
int size = 0;
if (n == 0) putchar('0');
while (n) {
a[size++] = n % 10 + 48;
n /= 10;
}
for (int i = size - 1; i >= 0; i--) putchar(a[i]);
putchar('\n');
}
int n, m, a[20], x, ans;
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) {
scanf("%d", &x);
a[x]++;
}
ans = 0;
for (int i = 1; i < m; i++)
for (int j = i + 1; j <= m; j++) ans += a[i] * a[j];
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
long N, M;
long arr[200005];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> N >> M;
for (int i = 1; i <= N; i++) {
int x;
cin >> x;
arr[x] = arr[x] + 1;
}
int ans = 0;
for (long i = 1; i <= M; i++) {
for (long j = i + 1; j <= M; j++) {
ans = ans + (arr[i] * arr[j]);
}
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> cnt;
void init() {
cin >> n >> m;
cnt.resize(m);
int x;
for (int i = 0; i < n; ++i) {
cin >> x;
cnt[x - 1]++;
}
}
void solve() {
long long ans = 0, sum = 0;
for (int i = 0; i < m; ++i) sum += cnt[i];
for (int i = 0; i < m; ++i) ans = ans + (sum - cnt[i]) * cnt[i];
cout << ans / 2;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
init();
solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long pow(long long int y) {
unsigned long long int res = 1;
unsigned long long int x = 10;
while (y > 0) {
if (y & 1) res = (res * x) % 1000000007;
y = y >> 1;
x = (x * x) % 1000000007;
}
return res;
}
void printPowerSet(int set[], int set_size) {
unsigned int pow_set_size = pow(2, set_size);
int counter, j;
for (counter = 0; counter < pow_set_size; counter++) {
for (j = 0; j < set_size; j++) {
if (counter & (1 << j)) cout << set[j] << " ";
}
cout << endl;
}
}
long long int gc(int a, int b) {
for (;;) {
if (a == 0) return b;
b %= a;
if (b == 0) return a;
a %= b;
}
}
long long int lcm(int a, int b) {
int temp = gc(a, b);
return temp ? (a / temp * b) : 0;
}
int main() {
int n, m, k, count;
cin >> n >> m;
int arr[11];
for (int i = 0; i < 11; i++) arr[i] = 0;
for (int i = 0; i < n; i++) {
cin >> k;
arr[k] += 1;
}
count = 0;
for (int i = 1; i <= m - 1; i++) {
for (int j = i + 1; j <= m; j++) count += arr[i] * arr[j];
}
cout << count << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
vector<int> f(11, 0);
for (int i = 0, x; i < n; ++i) cin >> x, f[x]++;
long long res = 0;
for (int i = 0; i < 11; ++i) {
if (f[i] == 0) continue;
long long cnt = 0;
for (int j = i + 1; j < 11; ++j) {
if (f[j] == 0) continue;
cnt += f[j];
}
res += (cnt * f[i]);
}
cout << res << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, temp, a[12] = {0}, sum = 0;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> temp;
a[temp]++;
}
for (int i = 1; i <= m; i++) {
for (int j = i + 1; j <= m; j++) {
sum += a[i] * a[j];
}
}
cout << sum;
}
|
#include <bits/stdc++.h>
using namespace std;
int arr[2000];
int main() {
int test, m, c = 0, sum1 = 0, i, j, a;
cin >> test >> m;
for (int i = 1; i <= test; i++) {
cin >> a;
arr[a]++;
}
long long sum = 0;
for (i = 1; i <= m; i++)
for (j = i + 1; j <= m; j++) sum += 1LL * arr[i] * arr[j];
cout << sum << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x, sum = 0, ans = 0, k;
cin >> n >> k;
map<int, int> mp;
vector<int> v;
for (int i = 0; i < n; i++) {
cin >> x;
mp[x]++;
}
for (auto it : mp) {
int d = it.second;
v.push_back(d);
}
for (int i = 0; i < v.size(); i++) {
sum = sum + v[i];
}
for (int i = 0; i < v.size() - 1; i++) {
sum = sum - v[i];
ans = ans + (v[i] * sum);
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
long int res = 0;
int input[maxn];
int type[15];
int n;
int m;
int main() {
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> input[i];
type[input[i]]++;
}
for (int i = 1; i <= m - 1; i++) {
for (int j = i + 1; j <= m; j++) {
res += type[i] * type[j];
}
}
cout << res << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int v[n], s[n];
for (int i = 0; i < n; i++) {
cin >> v[i];
}
sort(v, v + n);
for (int i = 0; i < n; i++) {
s[i] = 1;
}
int j = 0;
for (int i = 0; i < n - 1; i++) {
if (v[i] == v[i + 1]) {
s[j] = s[j] + 1;
} else
j = j + 1;
}
int cont = 0;
int num = n;
for (int i = 0; i < n; i++) {
cont = cont + s[i] * (num - s[i]);
num = num - s[i];
if (num == 0) {
break;
}
}
cout << cont << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long v[11];
signed main() {
long long n, m;
cin >> n >> m;
for (long long i = (0); i < (n); i++) {
long long a;
cin >> a;
v[a - 1]++;
}
long long ans = 0;
for (long long i = (0); i < (m); i++) {
for (long long j = (i + 1); j < (m); j++) {
ans += v[i] * v[j];
}
}
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
int m;
cin >> n >> m;
int a[n];
int b[m];
for (int i = 1; i <= m; i++) b[i] = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
b[a[i]]++;
}
long long int c = 0;
for (int i = 1; i <= m; i++) {
int s = 0;
for (int j = i + 1; j <= m; j++) {
s = s + b[j];
}
c = c + b[i] * s;
}
cout << c << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
map<long long, long long> ma;
long long i, t, s = 0, n, x;
cin >> n >> t;
for (i = 0; i < n; i++) {
cin >> x;
ma[x]++;
}
x = n;
x *= (x - 1);
x /= 2;
for (auto c : ma)
if (c.second != 1) s += c.second * (c.second - 1) / 2;
cout << x - s;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int arr[15];
int main() {
std::ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
int i;
for (i = 0; i < n; i++) {
int t;
cin >> t;
arr[t]++;
}
int j;
int ans = 0;
for (i = 1; i <= m; i++) {
for (j = i + 1; j <= m; j++) {
ans += arr[i] * arr[j];
}
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, m, a, i, j, ans, f[11];
int main() {
cin >> n >> m;
for (i = 1; i <= n; i++) {
cin >> a;
f[a]++;
}
for (i = 1; i < m; i++)
for (j = i + 1; j <= m; j++) ans += f[i] * f[j];
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long int fact(int x) {
long long int p = 1;
if (x != 1) {
for (int i = x; i > x - 2; i--) {
p = p * i;
}
} else {
return 1;
}
p = p / 2;
return p;
}
int main() {
long long int n, m;
cin >> n >> m;
unordered_map<int, int> mp;
long long int factn, factm;
for (long long int i = 1; i <= n; i++) {
int x;
cin >> x;
mp[x]++;
}
long long int sum = fact(n);
for (long long int i = 1; i <= m; i++) {
if (mp[i] >= 2) {
sum = sum - fact(mp[i]);
}
}
cout << sum;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, i, j, m, mas[11], ans;
int main() {
cin >> n >> m;
for (i = 0; i < n; i++) {
int k;
cin >> k;
mas[k]++;
}
for (i = 1; i <= m; i++)
for (j = i + 1; j <= m; j++) ans += mas[i] * mas[j];
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long int n, a[200000], b[200000];
long int m, i, j, k = 0, count, c, d, e, f;
while (cin >> n >> m) {
for (int i = 0; i < 200000; i++) {
b[i] = 0;
}
count = 0, f = 0;
for (i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
for (i = 0; i < n; i++) {
k = a[i];
b[k]++;
}
for (i = 1; i <= m; i++) {
if (b[i] > 1) {
j = b[i];
f = f + j;
c = n - f;
d = c * j;
count = count + d;
} else {
f = f + 1;
c = n - f;
count = count + c;
}
}
cout << count << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, t, i, x, sum;
cin >> n >> m;
int arr[m], arr1[m];
for (i = 0; i < m; i++) arr[i] = arr1[i] = 0;
t = n;
while (t--) {
cin >> x;
arr[x - 1]++;
}
sum = 0;
for (i = 0; i < m; i++) {
sum += arr[i];
arr1[i] += sum;
}
sum = 0;
for (i = 1; i < m; i++) {
sum += (arr[i] * arr1[i - 1]);
}
cout << sum;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void smain();
int main() {
ios_base::sync_with_stdio(0);
cout.precision(12);
cout << fixed;
smain();
return 0;
}
long long n, m, a[200002];
long long cnt[10];
void smain() {
for (; cin >> n >> m;) {
for (long long i = 0; i < n; i++) cin >> a[i];
for (long long i = 0; i < m; i++) cnt[i] = 0;
for (long long i = 0; i < n; i++) cnt[a[i] - 1] += 1;
long long res = 0;
for (long long i = 0; i < m; i++) res += cnt[i] * (n - cnt[i]);
cout << res / 2 << '\n';
}
}
|
#include <bits/stdc++.h>
using namespace std;
int n, m, x, i = 1, j = 1, a[11];
long long sum;
map<int, int> mp;
map<int, int>::iterator it;
int main() {
cin >> n >> m;
while (n--) {
cin >> x;
mp[x]++;
}
it = mp.begin();
while (it != mp.end()) {
a[i] = it->second;
i++, it++, j++;
}
for (i = 2; i < j; i++) a[i] += a[i - 1];
it = mp.begin(), i = 1;
while (it != mp.end()) {
sum += (a[j - 1] - a[i]) * it->second;
i++, it++;
}
cout << sum << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long freq[500005] = {0};
long long n, m, ans = 0;
scanf("%lld %lld", &n, &m);
long long a[n + 1];
for (long long i = 0; i < n; i++) {
scanf("%lld", &a[i]);
freq[a[i]]++;
}
ans = n * (n - 1) / 2;
for (long long i = 0; i < 500005; i++) {
if (freq[i] > 1) ans -= freq[i] * (freq[i] - 1) / 2;
}
cout << ans;
}
|
#include <bits/stdc++.h>
using namespace std;
const int tSize = 100001;
typedef int table[tSize][tSize];
int arr[401];
vector<int> ray[401];
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int compare2(const void* a, const void* b) {
return ((*(pair<int, int>*)a).first - (*(pair<int, int>*)b).first);
}
int compareIntReverse(const void* a, const void* b) {
return ((*(int*)b) - (*(int*)a));
}
int compare(const void* a, const void* b) {
if ((*(pair<int, int>*)a).first - (*(pair<int, int>*)b).first == 0) {
return ((*(pair<int, int>*)a).second - (*(pair<int, int>*)b).second);
}
return ((*(pair<int, int>*)a).first - (*(pair<int, int>*)b).first);
}
long long min(long long a, long long b) {
if (a > b)
return b;
else
return a;
}
bool check(string s) {
int k = 0;
if (s.size() < 1) return false;
if (s[0] == '0')
if (s.size() > 1) return false;
for (int i = 0; i < s.size(); i++) {
if (s[i] < '0' || s[i] > '9') return false;
}
return true;
}
int main() {
double epsilon = 1e-7;
int n, m;
cin >> n;
cin >> m;
int arr[11];
for (int i = 0; i < m; i++) arr[i] = 0;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
arr[a - 1]++;
}
long long ex = 0, cur = 0;
for (int i = 0; i < m; i++) {
for (int j = i + 1; j < m; j++) {
cur += arr[j];
}
ex += arr[i] * cur;
cur = 0;
}
cout << ex;
cin >> n;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int arr[200010];
int main() {
long long int test, m, c = 0, sum = 0, sum1 = 0, i, j;
cin >> test >> m;
for (int i = 1; i <= test; i++) {
int a;
cin >> a;
arr[a] = arr[a] + 1;
}
for (i = 1; i <= m; i++) {
for (j = i + 1; j <= m; j++) {
sum = sum + arr[i] * arr[j];
}
}
cout << sum << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
struct genre {
int genreQuantity = 0;
};
int main() {
int n, m, temp;
vector<int> sequenceGenre;
vector<genre> listGenre;
cin >> n >> m;
genre t1;
for (int i = 0; i < n; i++) {
listGenre.push_back(t1);
}
for (int i = 0; i < n; i++) {
cin >> temp;
sequenceGenre.push_back(temp);
listGenre[temp - 1].genreQuantity++;
}
int count = 0, sum = n, del = 0;
for (int i = 0; i < m; i++) {
del += listGenre[i].genreQuantity;
count += (sum - del) * listGenre[i].genreQuantity;
}
cout << count;
return 0;
}
|
#include <bits/stdc++.h>
enum { WHITE, GREY, BLACK };
using namespace std;
const int inf = 0x7FFFFFFF;
struct point_int {
int x, y;
point_int() {}
point_int(int a, int b) { x = a, y = b; }
bool operator==(const point_int &a) const { return x == a.x and y == a.y; }
};
struct point_double {
double x, y;
point_double() {}
point_double(double a, double b) { x = a, y = b; }
};
struct Node {
int v, w;
Node() {}
bool operator<(const Node &a) const { return w > a.w; }
Node(int _v, int _w) { v = _v, w = _w; }
};
namespace my {
template <class T>
T gcd(T a, T b) {
return b == 0 ? a : gcd(b, a % b);
}
template <typename T>
T lcm(T a, T b) {
return a / gcd(a, b) * b;
}
template <class T>
T big_mod(T n, T p, T m) {
if (p == 0) return (T)1;
T x = big_mod(n, p / 2, m);
x = (x * x) % m;
if (p & 1) x = (x * n) % m;
return x;
}
template <class T>
T multiplication(T n, T p, T m) {
if (p == 0) return (T)0;
T x = multiplication(n, p / 2, m);
x = (x + x) % m;
if (p & 1) x = (x + n) % m;
return x;
}
template <class T>
T my_pow(T n, T p) {
if (p == 0) return 1;
T x = my_pow(n, p / 2);
x = (x * x);
if (p & 1) x = (x * n);
return x;
}
template <class T>
double getdist(T a, T b) {
return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
template <class T>
T extract(string s, T ret) {
stringstream ss(s);
ss >> ret;
return ret;
}
template <class T>
string tostring(T n) {
stringstream ss;
ss << n;
return ss.str();
}
template <class T>
inline T Mod(T n, T m) {
return (n % m + m) % m;
}
template <class T>
T MIN3(T a, T b, T c) {
return min(a, min(b, c));
}
template <class T>
T MAX3(T a, T b, T c) {
return max(a, max(b, c));
}
template <class T>
void print_vector(T &v) {
int sz = v.size();
if (sz) cout << v[0];
for (int i = 1; i < sz; i++) cout << ' ' << v[i];
cout << "\n";
}
bool isVowel(char ch) {
ch = toupper(ch);
if (ch == 'A' || ch == 'U' || ch == 'I' || ch == 'O' || ch == 'E')
return true;
return false;
}
bool isConsonant(char ch) {
if (isalpha(ch) && !isVowel(ch)) return true;
return false;
}
} // namespace my
namespace debug {
int sum() { return 0; }
template <typename T, typename... Args>
T sum(T a, Args... args) {
return a + sum(args...);
}
void print() {
cout << "\n";
return;
}
template <typename T, typename... Args>
void print(T a, Args... args) {
cout << a << " ";
print(args...);
}
} // namespace debug
int read_int() {
int n;
scanf("%d", &n);
return n;
}
int read_LLD() {
long long int n;
scanf("%lld", &n);
return n;
}
inline int buffer_input() {
char inp[1000];
scanf("%s", inp);
return atoi(inp);
}
long long int Freq[1000];
int main() {
int N, M;
cin >> N >> M;
for (int i = 0; i < N; i++) {
int x;
cin >> x;
Freq[x]++;
}
long long int ans = 0;
for (int i = 1; i <= M; i++) {
for (int j = i + 1; j <= M; j++) {
ans += (Freq[i] * Freq[j]);
}
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, wyn = 0, lasti = 0;
scanf("%d %d", &n, &m);
int liczby[n];
for (int i = 0; i < n; i++) {
scanf("%d", &liczby[i]);
}
sort(liczby, liczby + n, std::greater<int>());
for (int i = 1; i < n; i++) {
if (liczby[i] < liczby[i - 1]) {
lasti = i;
}
wyn = wyn + lasti;
}
printf("%d", wyn);
}
|
#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[200500];
int t[1000];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
for (int i = 0; i < n; ++i) {
t[a[i]]++;
}
int ans = 0;
for (int i = 1; i <= m; ++i) {
for (int j = i + 1; j <= m; ++j) {
ans += t[i] * t[j];
}
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<int> v(n);
vector<int> x(n), a(12, 0);
for (int i = 0; i < n; i++) {
cin >> v[i];
}
for (int i = n - 1; i >= 0; i--) {
x[i] = a[v[i]];
a[v[i]]++;
}
long long res = 0;
for (int i = 0; i < n; i++) {
res += n - x[i] - 1 - i;
}
cout << res << '\n';
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int x1[4] = {0, 1, 0, -1};
int yy1[4] = {-1, 0, 1, 0};
string alph = "abcdefghijklmnopqrstuvwxyz";
vector<string> v(1005);
int arr[1005][1005];
const int mx = 1e5 + 5;
int clr[mx];
int sum[mx];
int res[mx];
vector<vector<int> > g;
int n;
vector<char> used;
void dfs(int v) {
used[v] = true;
for (auto to : g[v]) {
if (!used[to]) dfs(to);
res[v] += clr[to];
}
}
void CAD() {
int n, m;
cin >> n >> m;
map<int, int> mp;
int k;
for (int i = 0; i < n; i++) {
cin >> k;
mp[k]++;
}
int res = 0, t = 0;
for (int i = 1; i <= m; i++) {
if (mp[i] == 0) continue;
res += (n - mp[i] - t) * mp[i];
t += mp[i];
}
cout << res;
}
int main() {
int tt = 1;
while (tt--) CAD();
}
|
#include <bits/stdc++.h>
using namespace std;
int a[11];
int main() {
int n, m, temp, result = 0;
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++) {
scanf("%d", &temp);
a[temp]++;
}
for (int i = 1; i < 10; i++)
for (int j = i + 1; j <= 10; j++) result += a[i] * a[j];
printf("%d", result);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n, m;
int cnt[11];
int main() {
std ::ios_base ::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
int val;
cin >> val;
cnt[val]++;
}
long long res = 0;
for (int i = 1; i <= m; i++) res += 1ll * cnt[i] * (n - cnt[i]);
res /= 2;
cout << res << "\n";
}
|
#include <bits/stdc++.h>
using namespace std;
int n, m;
int cun[101];
int ans;
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) {
int ls;
scanf("%d", &ls);
cun[ls]++;
}
for (int i = 1; i <= m; i++) {
for (int j = i + 1; j <= m; j++) {
ans += cun[i] * cun[j];
}
}
printf("%d\n", ans);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long inf = LONG_MAX;
const long long arr = 1000000;
bool comp(pair<long long, long long> a, pair<long long, long long> b) {
if (a.first == b.first)
return a.second < b.second;
else
return a.first < b.first;
}
int main(void) {
long long n, m;
cin >> n >> m;
vector<long long> a(m + 1, 0);
for (int i = 0; i < n; i++) {
long long x;
cin >> x;
a[x]++;
}
long long ans = 0;
for (long long i = 1; i < m; i++) {
for (long long j = i + 1; j <= m; j++) {
ans += a[i] * a[j];
}
}
cout << ans << '\n';
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
long long n, m;
cin >> n >> m;
vector<long long> a(m);
long long sum1 = 0;
long long sum2 = 0;
for (int i = 0; i < n; ++i) {
int x;
cin >> x;
++a[x - 1];
}
for (int i = 0; i < m; ++i) {
sum1 += a[i];
sum2 += a[i] * a[i];
}
sum1 *= sum1;
cout << (sum1 - sum2) / 2;
return 0;
}
|
#include <bits/stdc++.h>
int main() {
int n, m;
scanf("%d%d", &n, &m);
int genre[11];
int i;
for (i = 1; i <= m; i++) {
genre[i] = 0;
}
for (i = 0; i < n; i++) {
int a;
scanf("%d", &a);
genre[a]++;
}
long long options = 0;
for (i = 1; i < m; i++) {
if (genre[i] > 0) {
options += genre[i] * (n - genre[i]);
n = n - genre[i];
}
}
printf("%lld\n", options);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
long long n, m, genres[11];
long long combo(long long a) { return a * (a - 1) / 2; }
int main() {
cin >> n >> m;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
genres[a]++;
}
long long ans = combo(n);
for (int i = 0; i < 11; i++) ans -= combo(genres[i]);
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, m;
cin >> n >> m;
long long int books[m];
for (long long int i = 0; i < m; i++) {
books[i] = 0;
}
long long int temp;
for (long long int i = 0; i < n; i++) {
cin >> temp;
books[temp - 1]++;
}
long long int sum = 0;
long long int sumsq = 0;
for (int i = 0; i < m; i++) {
sum += books[i];
sumsq += books[i] * books[i];
}
long long int total = sum * sum - sumsq;
cout << total / 2;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m, f[10] = {0}, x, i;
long long ans, z;
scanf("%lld", &n);
scanf("%lld", &m);
for (i = 0; i < n; i++) {
scanf("%lld", &x);
f[x - 1]++;
}
ans = (n * (n - 1)) / 2;
for (i = 0; i < m; i++) {
z = (f[i] * (f[i] - 1)) / 2;
ans -= z;
}
cout << ans;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
unsigned long long num, genres;
cin >> num >> genres;
vector<long long> numingenre(genres, 0);
for (int i = 0; i < num; i++) {
int temp;
cin >> temp;
numingenre[temp - 1] += 1;
}
unsigned long long poss = 0, prev = 0;
for (auto i : numingenre) {
prev += i;
poss += (num - prev) * i;
}
cout << poss;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, m, sm, x, i, j, k, gen[11] = {0};
cin >> n >> m;
for (i = 0; i < n; i++) {
cin >> k;
gen[k]++;
}
sm = 0;
x = 1;
for (i = 1; i <= m; i++) {
for (j = i + 1; j <= m; j++) {
x = gen[i] * gen[j];
sm = sm + x;
}
}
cout << sm << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int N, M;
int gen[11];
int main() {
int i, x;
cin >> N >> M;
for (i = 1; i <= N; ++i) {
cin >> x;
gen[x]++;
}
int nr_posibilitati = 0, j;
for (i = 1; i < 10; ++i)
for (j = i + 1; j <= 10; ++j) {
nr_posibilitati += gen[i] * gen[j];
}
cout << nr_posibilitati << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long number[11];
int main() {
long long n, m, taker;
memset(number, 0, sizeof(number));
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> taker;
number[taker]++;
}
long long sum = 0;
for (int i = 1; i <= m; i++) {
for (int j = 1; j != i; j++) {
sum += number[i] * number[j];
}
}
cout << sum << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int a[maxn], n, m;
int cnt[maxn];
void solve() {
long long tot = 1LL * n * (n - 1) / 2;
long long jianqu = 0;
for (int i = 1; i <= m; i++) {
if (cnt[i] < 2) continue;
jianqu += 1LL * cnt[i] * (cnt[i] - 1) / 2;
}
printf("%I64d\n", tot - jianqu);
}
int main() {
while (scanf("%d %d", &n, &m) != EOF) {
memset(cnt, 0, sizeof(cnt));
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
cnt[a[i]]++;
}
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 100;
int zl[20];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
long long ans = 0;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
ans += i - zl[x];
zl[x]++;
}
cout << ans << "\n";
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
int n, m, ans = 0;
cin >> n >> m;
vector<int> v(m);
for (int((i)) = (0); ((i)) < ((n)); ((i))++) {
int a;
cin >> a;
v[a - 1]++;
}
for (int((i)) = (0); ((i)) < ((m)); ((i))++)
for (int(j) = (i + 1); (j) < (m); (j)++) ans += v[i] * v[j];
cout << ans;
}
|
#include <bits/stdc++.h>
using namespace std;
vector<int> happy_numbers;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int main() {
int n, m;
cin >> n >> m;
vector<int> books;
books.resize(m, 0);
for (int i = 0; i < n; ++i) {
int tmp;
cin >> tmp;
books[tmp - 1]++;
}
int ans = 0;
set<pair<int, int>> been;
for (int i = 0; i < m; ++i)
for (int j = 0; j < m; ++j) {
if (i == j) continue;
pair<int, int> be(i, j), bee(j, i);
if (been.count(be) || been.count(bee)) continue;
been.insert(be);
ans += books[i] * books[j];
}
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
clock_t clk = clock();
long long int i, j;
void solve(void);
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
;
int t = 1;
while (t--) solve();
return 0;
}
void solve() {
long long int n, m;
cin >> n >> m;
long long int x;
long long int ans = 0;
long long int cnt[11] = {0};
for (i = 0; i <= n - 1; ++i) {
cin >> x;
++cnt[x];
}
for (i = 1; i <= m; ++i)
for (j = i + 1; j <= m; ++j) ans += cnt[i] * cnt[j];
cout << ans << '\n';
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.