text stringlengths 49 983k |
|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
long long int i, n, temp = 0, j, neg = 0, zer = 0, pos = 0, sum = 0, e = 0,
flag = 0, flag2 = 0, time = 0, disap = 0, m,
mi = 99999999, ma = -99999999, z = 0, k;
long long int a = 0, b = 0;
long long int c, d, s = 0, t = 0;
long long int ct = 0;
char inc;
vector<long long int> v, v2, v3;
long long int ar2[200001] = {0}, ar[100][100] = {0};
string st, st2, st3, st4;
vector<pair<int, int> > vp;
cin >> n;
for (i = 0; i < n; i++) {
cin >> a >> b;
vp.push_back(make_pair(a, b));
}
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
if (i == j) {
continue;
} else if (vp[i].second == vp[j].first) {
sum += 1;
}
}
}
cout << sum;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, br = 0;
cin >> n;
int home[n], guest[n];
for (int i = 0; i < n; i++) {
cin >> home[i] >> guest[i];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (home[i] == guest[j]) {
br++;
}
}
}
cout << br;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, flag = 0;
cin >> n;
int arr[n][2];
for (int i = 0; i < n; ++i) {
for (int j = 0; j < 2; ++j) {
cin >> arr[i][j];
}
}
for (int k = 0; k < n; ++k) {
for (int l = 0; l < n; ++l) {
if (arr[k][0] == arr[l][1]) {
flag++;
}
}
}
cout << flag;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[30][2];
for (int i = 0; i < n; ++i) {
for (int j = 0; j < 2; ++j) {
cin >> a[i][j];
}
}
int counter = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (a[i][0] == a[j][1]) counter++;
}
}
cout << counter << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, co = 0;
cin >> n;
vector<int> a;
vector<int> b;
for (int i = 0; i < n; i++) {
int t, u;
cin >> t >> u;
a.push_back(t);
b.push_back(u);
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (a[i] == b[j] && i != j) {
co++;
}
}
}
cout << co << flush;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n], b[n];
for (int i = 1; i <= n; i++) {
cin >> a[i];
cin >> b[i];
}
int count = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (a[i] == b[j] && i != j) {
count++;
}
}
}
cout << count;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int a[122], b[122];
int main() {
int n, k, t, ans = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> k >> t;
a[k]++;
b[t]++;
}
for (int i = 1; i <= 100; i++)
if (a[i] > 0) ans += a[i] * b[i];
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t, k = 0;
cin >> t;
vector<int> myv;
map<int, int> mip;
while (t--) {
int a, b;
cin >> a >> b;
myv.push_back(a);
mip[b]++;
}
for (int i = 0; i < myv.size(); i++) {
k += mip[myv[i]];
}
cout << k;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int* h = new int[n];
int* a = new int[n];
for (int i(0); i < n; ++i) cin >> h[i] >> a[i];
int t = 0;
for (int i(0); i < n; ++i) t += count(a, a + n, h[i]);
cout << t;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, c = 0;
cin >> n;
int a[n], h[n];
for (int i = 0; i < n; i++) {
cin >> a[i] >> h[i];
for (int j = 0; j <= i; j++) {
if (a[j] == h[i]) {
c++;
}
if (h[j] == a[i]) c++;
}
}
cout << c;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, number = 0;
cin >> n;
vector<int> a(n), b(n);
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
for (int j = 0; j < n; j++) {
if (a[i] == b[j]) {
number++;
}
if (a[j] == b[i]) {
number++;
}
}
}
cout << number << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
int home, away;
int teamColors[2][n];
int away_uniform = 0;
for (int i = 0; i < n; i++) {
scanf("%d%d", &teamColors[0][i], &teamColors[1][i]);
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (teamColors[1][j] == teamColors[0][i]) {
away_uniform++;
}
}
}
printf("%d", away_uniform);
}
|
#include <bits/stdc++.h>
using namespace std;
int n, a, b, d[500], s;
int main() {
scanf("%d", &n);
for (int i = 1; i <= 2 * n; i++) scanf("%d", &d[i]);
for (int i = 1; i <= 2 * n; i++)
for (int j = 1; j <= 2 * n; j++)
if (d[i] == d[i + (2 * j - 1)]) s++;
printf("%d", s);
scanf(" ");
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int teams = 0;
cin >> teams;
int uni[teams][2];
int ch = 0;
for (int i = 0; i < teams; i++) {
cin >> uni[i][0];
cin >> uni[i][1];
}
for (int i = 0; i < teams - 1; i++) {
for (int j = i + 1; j < teams; j++) {
if (uni[i][0] == uni[j][1]) ch++;
if (uni[i][1] == uni[j][0]) ch++;
}
}
cout << ch;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void i_f_o() {
ios_base::sync_with_stdio(NULL);
cin.tie(NULL);
cout.tie(NULL);
}
int32_t main() {
int n;
cin >> n;
int a[n], b[n];
int ans = 0;
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
}
for (int i = 0; i < n; i++) {
int temp = a[i];
for (int j = 0; j < n; j++) {
if (temp == b[j]) ans++;
}
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n = 0;
cin >> n;
map<int, int> home_color_count;
map<int, int> away_color_count;
map<int, vector<int>> team_to_color;
for (int i = 0; i < n; i++) {
int x = 0, y = 0;
cin >> x >> y;
team_to_color[i].push_back(x);
team_to_color[i].push_back(y);
home_color_count[x] += 1;
away_color_count[y] += 1;
}
int ans = 0;
for (auto item : team_to_color) {
int home_color = item.second[0];
int away_color = item.second[1];
ans += home_color_count[away_color];
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (b > a) return gcd(b, a);
if (a % b == 0) return b;
return gcd(b, a % b);
}
void sieve() {
int primes[10];
memset(primes, true, sizeof(primes));
primes[0] = false;
primes[1] = false;
for (int i = 2; i <= 10000; i++) {
if (primes[i] == 1) {
for (int j = i * i; j <= 10000; j += i) primes[j] = false;
}
}
}
long long power(long long x, long long y, long long p) {
long long res = 1;
x = x % p;
while (y > 0) {
if (y & 1) res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
long long modInverse(long long n, long long p) { return power(n, p - 2, p); }
long long nCrModP(long long n, long long r, long long p) {
if (n < r) return 0;
if (r == 0) return 1;
long long fac[n + 1];
fac[0] = 1;
for (int i = 1; i <= n; i++) fac[i] = (fac[i - 1] * i) % p;
return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) %
p;
}
void solve(vector<pair<int, int> >::iterator start,
vector<pair<int, int> >::iterator end, int &count);
long long modFact(long long n, long long p) {
if (n >= p) return 0;
long long result = 1;
for (long long i = 1; i <= n; i++) result = (result * i) % p;
return result;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long t;
t = 1;
for (int loop = 0; loop < (int)(t); ++loop) {
long long n;
cin >> n;
vector<pair<int, int> > arr(n);
for (int i = 0; i < (int)(n); ++i) {
cin >> arr[i].first >> arr[i].second;
}
int count = 0;
for (int i = 0; i < (int)(n); ++i) {
for (int j = 0; j < n; j++) {
if (i != j)
if (arr[i].first == arr[j].second) count++;
}
}
cout << count;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, c = 0, freq[101] = {0};
cin >> n;
int x[n], y[n];
for (int i = 0; i < n; i++) {
cin >> x[i] >> y[i];
freq[x[i]]++;
}
for (int i = 0; i < n; i++) {
c += freq[y[i]];
}
cout << c;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int home[n];
int guest[n];
int count = 0;
for (int i = 0; i < n; i++) {
cin >> home[i] >> guest[i];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (home[i] == guest[j]) {
count++;
}
}
}
cout << count;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[30], b[30];
for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
int c = 0;
for (int j = 0; j < n; j++) {
for (int i = 0; i < n; i++) {
if (a[j] == b[i]) c++;
}
}
cout << c << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void initialMethod();
int main() {
int teams = 0;
int answer = 0;
cin >> teams;
int colorArr[teams][2];
for (int i = 0; i < teams; i++) {
for (int j = 0; j < 2; j++) {
cin >> colorArr[i][j];
}
}
for (int i = 0; i < teams; i++) {
for (int k = 0; k < teams; k++) {
if (k == i) break;
if (colorArr[i][0] == colorArr[k][1] && colorArr[i][1] == colorArr[k][0])
answer += 2;
else if (colorArr[i][0] == colorArr[k][1] ||
colorArr[i][1] == colorArr[k][0])
answer++;
}
}
cout << answer << endl;
return 0;
}
void initialMethod() {
int teams;
int currentArrayIndex = 0;
cin >> teams;
int teamsColor[teams * 2];
int totalCount = 0;
int arrSize;
for (int i = 0; i < teams; i++) {
for (int j = 0; j < 2; j++) {
cin >> teamsColor[currentArrayIndex];
currentArrayIndex++;
}
}
arrSize = sizeof(teamsColor) / sizeof(teamsColor[0]);
for (int i = 0; i < arrSize; i++) {
if (i % 2 == 0) {
for (int k = 0; k < arrSize; k++) {
if (k % 2 != 0) {
if (teamsColor[k] == teamsColor[i]) totalCount++;
}
}
}
}
cout << totalCount;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, counter = 0;
cin >> n;
int arr[n][2];
for (int i = 0; i < n; i++)
for (int j = 0; j < 2; j++) cin >> arr[i][j];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (arr[i][0] == arr[j][1]) {
counter++;
}
}
}
cout << counter << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, hom[31], guest[31], count = 0;
cin >> a;
for (int i = 0; i < a; i++) {
cin >> hom[i] >> guest[i];
}
for (int i = 0; i < a; i++) {
for (int j = 0; j < a; j++) {
if (hom[i] == guest[j]) {
count++;
}
}
}
cout << count;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a[200], b[200], c = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (a[i] == b[j]) c++;
}
}
cout << c;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int home, away;
int teamColors[2][n];
int away_uniform = 0;
for (int i = 0; i < n; i++) {
cin >> teamColors[0][i] >> teamColors[1][i];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (teamColors[1][j] == teamColors[0][i]) {
away_uniform++;
}
}
}
cout << away_uniform;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, k, dai, dem, vt, ck, max1, min1, kq, tong;
int h[111];
int g[111];
void sol() {
int i, j;
dem = 0;
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
if (h[i] == g[j]) dem++;
}
}
cout << dem << endl;
}
int main() {
int i, j;
while (scanf("%d", &n) > 0) {
for (i = 0; i < n; i++) {
scanf("%d %d", &h[i], &g[i]);
}
sol();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k = 0;
cin >> n;
int h[n], g[n];
for (int i = 0; i < n; i++) {
cin >> h[i] >> g[i];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (h[i] == g[j]) k++;
}
}
cout << k;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, count = 0;
cin >> n;
n *= 2;
int *a = new int[n];
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (a[i] == a[j])
if (((i % 2 != 0) && (j % 2 == 0)) || ((i % 2 == 0) && (j % 2 != 0)))
count += 1;
}
}
cout << count;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int number(0);
vector<int> h(n), a(n);
for (int i = 0; i < n; ++i) {
cin >> h[i] >> a[i];
for (int j = 0; j < i; ++j) {
if (h[i] == a[j]) {
number += 1;
}
if (a[i] == h[j]) {
number += 1;
}
}
}
cout << number << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, ans = 0;
vector<pair<int, int> > uniforms;
cin >> n;
for (int i = 0; i < n; i++) {
int a, b;
cin >> a >> b;
uniforms.push_back(make_pair(a, b));
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (uniforms[i].first == uniforms[j].second) ++ans;
}
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, arr1[30], arr2[30], i = 0, j = 0;
int count = 0;
cin >> n;
for (i; i < n; i++) cin >> arr1[i] >> arr2[i];
for (i = 0; i < n; i++)
for (j = 0; j < n; j++) {
if (arr1[i] == arr2[j]) count++;
}
cout << count << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, rez = 0, i, j, t;
cin >> n;
int a[n], b[n];
for (i = 0; i < n; i++) {
cin >> a[i] >> b[i];
}
for (i = 0; i < n; ++i) {
t = a[i];
for (j = 0; j < n; ++j) {
if (t == b[j]) ++rez;
}
}
cout << rez << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, h[30], a[30], count(0);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> h[i] >> a[i];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (h[i] == a[j]) {
count++;
}
}
}
cout << count;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int numOfComparisons, HomeUniform, GuestUniform, count = 0;
cin >> numOfComparisons;
int *Home = new int[numOfComparisons];
int *Guest = new int[numOfComparisons];
for (int i = 0; i < numOfComparisons; i++) {
cin >> Home[i] >> Guest[i];
}
for (int i = 0; i < numOfComparisons; i++) {
for (int j = 0; j < numOfComparisons; j++) {
if (Home[i] == Guest[j]) count++;
}
}
cout << count;
return 0;
}
|
#include <bits/stdc++.h>
int solve(int n, int i, int home, int arr1[], int count) {
for (int j = 0; j < n; j++) {
if (j == i) {
continue;
}
if (home == arr1[j]) {
count++;
}
}
return count;
}
int main() {
int n, count = 0, home;
scanf("%d", &n);
int arr[n], arr1[n];
for (int i = 0; i < n; i++) {
scanf("%d %d\n", &arr[i], &arr1[i]);
}
for (int i = 0; i < n; i++) {
home = arr[i];
count = solve(n, i, home, arr1, count);
}
printf("%d", count);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int a[101], b[101];
int main() {
int n, l = 0;
cin >> n;
int a1, b1;
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
}
for (int i = 0; i < 101; i++) {
for (int y = 0; y < 101; y++) {
if (a[i] == b[y] && a[i] != 0) l++;
}
}
cout << l;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, s = 0;
cin >> n;
int a[n + 1], b[n + 1];
for (int i = 1; i <= n; i++) {
cin >> a[i] >> b[i];
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (a[i] == b[j]) {
s++;
}
}
}
cout << s;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int x[101], y[101];
int n, a = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> x[i] >> y[i];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < i; j++) {
if (x[i] == y[j]) a++;
if (x[j] == y[i]) a++;
}
}
cout << a << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
while (cin >> n) {
int h[n], g[n];
for (int i = 0; i < n; i++) {
cin >> h[i] >> g[i];
}
int count = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (j != i) {
if (h[i] == g[j]) count++;
}
}
}
cout << count << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
long long int n;
cin >> n;
long long int a[n], b[n];
long long int j, k, i = 0, m = 0, h = n;
while (h--) {
cin >> j >> k;
a[i++] = j;
b[m++] = k;
}
long long int r = 0, t, s;
for (t = 0; t < n; t++) {
for (s = 0; s < n; s++) {
if (a[t] == b[s]) r++;
}
}
cout << r;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
unsigned int num{}, games{};
cin >> num;
vector<pair<int, int>> team(num);
for (unsigned int i = 0; i < num; ++i) {
cin >> team[i].first >> team[i].second;
}
for (unsigned int i = 0; i < num; ++i) {
for (unsigned int j = 0; j < num; ++j) {
if (team[i].first == team[j].second) games++;
}
}
cout << games;
cout << endl;
return 0;
}
|
#include <bits/stdc++.h>
int main() {
int i, n, res = 0, j;
scanf("%d", &n);
int h[n], g[n];
for (i = 0; i < n; i++) scanf("%d %d", &h[i], &g[i]);
for (i = 0; i < n; i++)
for (j = 0; j < n; j++)
if (h[i] == g[j]) res++;
printf("%d", res);
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int N, A[33][2], i, j, Res;
Res = 0;
cin >> N;
for (i = 0; i < N; i++) {
cin >> j;
A[i][0] = j;
cin >> j;
A[i][1] = j;
}
for (i = 0; i < N; i++) {
for (j = 0; j < N; j++) {
if (i != j) {
if (A[i][0] == A[j][1]) {
Res++;
}
}
}
}
cout << Res;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, ans = 0;
scanf("%d", &a);
vector<int> home(a), guest(a);
for (int i = 0; i < a; ++i) {
cin >> home[i] >> guest[i];
}
for (int i = 0; i < a; ++i) {
for (int j = 0; j < a; ++j) {
if (i != j)
if (home[i] == guest[j]) ++ans;
}
}
cout << ans << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, home[30], guest[30], k = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> home[i] >> guest[i];
}
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) {
if (home[i] == guest[j]) k++;
}
cout << k;
}
|
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int MAXN = 2e2 + 5;
const long long INFLL = 1e18;
int n;
int h[100], a[100];
int main() {
scanf("%d", &n);
int ans = 0;
for (int i = 0; i < n; i++) scanf("%d %d", &h[i], &a[i]);
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) {
if (h[i] == a[j]) ans++;
}
printf("%d\n", ans);
return 0;
}
|
#include <bits/stdc++.h>
int main() {
int n, count = 0, i, j;
scanf("%d", &n);
int h[n], a[n];
for (i = 0; i < n; i++) scanf("%d %d", &h[i], &a[i]);
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
if (h[i] == a[j]) count++;
}
}
printf("%d\n", count);
return 0;
}
|
#include <bits/stdc++.h>
int main() {
int p[30][2];
int n, i, j, t = 0;
scanf("%d", &n);
for (i = 0; i < n; i++)
for (j = 0; j < 2; j++) scanf("%d", &p[i][j]);
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
if (i != j) {
if (p[i][0] == p[j][1]) t++;
}
}
}
printf("%d\n", t);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
map<int, int> h;
map<int, int> a;
vector<int> uni;
int teams;
cin >> teams;
int temph, tempa;
for (int i = 0; i < teams; i++) {
cin >> temph >> tempa;
if (h.count(temph) > 0)
h[temph]++;
else {
h[temph] = 1;
uni.push_back(temph);
}
if (a.count(tempa) > 0)
a[tempa]++;
else
a[tempa] = 1;
}
int resul = 0;
for (int i = 0; i < uni.size(); i++) {
resul += h[uni[i]] * a[uni[i]];
}
cout << resul;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, b, sum = 0;
vector<int> u, v;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a >> b;
u.push_back(a);
v.push_back(b);
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (v[i] == u[j]) {
sum++;
}
}
}
cout << sum << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, n;
cin >> n;
vector<int> v1, v2;
for (int i = (0); i < (int)(n); i++) {
cin >> a >> b;
v1.push_back(a);
v2.push_back(b);
}
int sum = 0;
for (int i = 0; i < v2.size(); i++) {
for (int j = 0; j < v1.size(); j++)
if (v2[i] == v1[j]) sum++;
}
cout << sum;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, sum = 0, maxx = 0;
int h[110], a[110];
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> h[i] >> a[i];
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (j == i) continue;
if (h[i] == a[j]) sum++;
}
}
cout << sum << endl;
return 0;
}
|
#include <bits/stdc++.h>
struct Matchs {
int Home;
int Guest;
} MyMatch[31];
int main(void) {
unsigned short int n, i, j, ans = 0;
scanf("%hu", &n);
for (i = 0; i < n; ++i) {
scanf("%d %d", &MyMatch[i].Home, &MyMatch[i].Guest);
}
for (i = 0; i < n; ++i) {
for (j = 0; j < n; ++j) {
if ((MyMatch[i].Guest == MyMatch[j].Home) && (i != j)) {
++ans;
}
}
}
printf("%i", ans);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
int main() {
int n;
cin >> n;
vector<int> home(n);
vector<int> out(n);
int count = 0;
for (int i = 0; i < n; i++) {
cin >> home[i];
cin >> out[i];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i == j) continue;
int n1 = home[i];
int n2 = out[j];
if (n1 == n2) count++;
}
}
cout << count;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int x, arr[60], arr_2[60], count = 0;
cin >> x;
x *= 2;
for (int i = 0; i < x; i++) cin >> arr[i];
for (int i = 0; i < x; i += 2) {
for (int j = 1; j < x; j += 2) {
if (arr[i] == arr[j]) count++;
}
}
cout << count << endl;
return 0;
}
|
#include <bits/stdc++.h>
template <class T, class U>
T getMin(T a, U b) {
return (a < b ? a : b);
}
template <class T, class U>
T getMax(T a, U b) {
return (a > b ? a : b);
}
template <class T>
T charIndexS(T c) {
return c - 96;
}
template <class T>
T charIndexL(T c) {
return c - 64;
}
template <class T, class U, class O, class P>
T arrayOutofBoundary(T r, U c, O m, P n) {
return r < 0 || c < 0 || r == m || c == n;
}
template <class T, class U>
T power(T base, U exponent) {
return (exponent == 0) ? 1 : (base * pow(base, exponent - 1));
}
int dx[] = {+0, +0, +1, -1, -1, +1, -1, +1};
int dy[] = {-1, +1, +0, +0, +1, +1, -1, -1};
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
vector<int> h(105, 0);
vector<int> g(105, 0);
int result = 0;
while (n--) {
int a, b;
cin >> a >> b;
h[a]++;
g[b]++;
if (g[a]) result += g[a];
if (h[b]) result += h[b];
}
cout << result << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, ans(0);
cin >> n;
int h[n], a[n];
for (int i = 0; i < n; i++) {
cin >> h[i] >> a[i];
}
for (int b = 0; b < n; b++) {
for (int c = 0; c < n; c++) {
if (c != b) {
if (h[b] == a[c]) ans++;
}
}
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int fr[101][2];
int main() {
int n, c = 0;
cin >> n;
int ind = 1;
map<int, int> mp;
for (int i = 0; i < n; i++) {
int a, b;
cin >> a >> b;
if (mp[a] == 0) mp[a] = ind++;
if (mp[b] == 0) mp[b] = ind++;
fr[mp[a]][0]++;
fr[mp[b]][1]++;
}
for (int i = 1; i < ind; i++) c += fr[i][0] * fr[i][1];
cout << c << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t, a, b, ans = 0;
vector<int> home;
vector<int> away;
cin >> t;
while (t--) {
cin >> a >> b;
home.push_back(a);
away.push_back(b);
}
for (int i = 0; i < home.size(); i++) {
for (int j = 0; j < away.size(); j++) {
if (home[i] == away[j]) ans++;
}
}
cout << ans << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int home[n], away[n];
for (int i = 0; i < n; i++) cin >> home[i] >> away[i];
int count = 0;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (home[i] == away[j]) count++;
cout << count << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i = 0, res = 0;
cin >> n;
int h[n], a[n];
while (i < n) {
cin >> h[i] >> a[i];
i++;
}
for (i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (h[i] == a[j]) res++;
cout << res;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
struct team {
int h, a;
};
int main() {
int n;
cin >> n;
team t[n];
for (int i = 0; i < n; i++) cin >> t[i].h >> t[i].a;
int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i == j) continue;
if (t[i].h == t[j].a) ans++;
}
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, a[30], b[30], ans;
int main() {
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) ans += a[i] == b[j];
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
int main() {
int i, j, n, a[100][100], m = 0;
scanf("%d", &n);
for (i = 0; i < n; i++) {
for (j = 0; j < 2; j++) {
scanf("%d", &a[i][j]);
}
}
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
if (a[i][0] != a[j][1] && i != j) m++;
}
}
printf("%d", n * (n - 1) - m);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, h[101] = {0}, w[101], hh, game = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> hh >> w[i];
h[hh]++;
}
for (int i = 0; i < n; i++) game += h[w[i]];
cout << game << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void fast() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
long long int a[101];
long long int b[101];
int main() {
long long int n, c = 0;
;
cin >> n;
for (long long int i = 0; i < n; i++) {
long long int x, y;
cin >> x >> y;
a[x]++;
b[y]++;
}
for (long long int i = 1; i < 101; i++) {
if (a[i] > 0 && b[i] > 0) c += a[i] * b[i];
}
cout << c << '\n';
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, ct = 0;
cin >> n;
int h[n], a[n];
for (int i = 0; i < n; i++) cin >> h[i] >> a[i];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (h[i] == a[j]) ct++;
}
}
cout << ct;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n + 1], b[n + 2];
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
}
int cnt = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (a[i] == b[j]) cnt++;
}
}
cout << cnt;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long a, b[1000000], c[1000000], d, e;
int main() {
cin >> a;
for (int i = 0; i < a; i++) {
cin >> b[i] >> c[i];
}
for (int i = 0; i < a; i++) {
for (int j = 0; j < a; j++) {
if (i != j && b[i] == c[j]) {
d++;
}
}
}
cout << d;
}
|
#include <bits/stdc++.h>
const long long INF = 1e18 + 123;
const long double EPS = 1e-9;
const int inf = 1e9 + 123;
const int MOD = 1e9 + 7;
const int N = 1e5 + 123;
const int M = 1e6 + 123;
const double pi = 3.14159265359;
using namespace std;
long long x, y, t, l, r;
long long p, py, q, k;
long long n, m, cal, ans, res;
string s;
bool visited(N);
vector<int> c;
vector<int> w;
vector<vector<int>> g;
void solve() {
cin >> n;
vector<int> h(n), a(n);
for (long long i = 0; i < n; i++) {
cin >> h[i] >> a[i];
for (long long j = 0; j < i; j++) {
if (h[i] == a[j]) {
ans++;
}
if (a[i] == h[j]) {
ans++;
}
}
}
cout << ans;
}
int main() {
solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, ans = 0;
cin >> n;
vector<pair<int, int>> a(n);
for (int i = 0; i < n; i++) {
int a1, b;
cin >> a1 >> b;
a[i].first = a1;
a[i].second = b;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (a[i].first == a[j].second && i != j) {
ans++;
}
}
}
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, arr[30][2], game = 0;
cin >> n;
for (int i = 0; i < n; i++) cin >> arr[i][0] >> arr[i][1];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (arr[i][0] == arr[j][1]) game++;
}
}
cout << game;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int h[105], a[105];
int main() {
int n;
int x, y;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> x >> y;
h[x]++;
a[y]++;
}
int count = 0;
for (int i = 0; i < 105; i++) {
count += h[i] * a[i];
}
cout << count;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, g(0);
cin >> n;
int uni[n][2];
for (int i = 0; i < n; i++) {
cin >> uni[i][0] >> uni[i][1];
}
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (uni[i][0] == uni[j][1]) g++;
if (uni[i][1] == uni[j][0]) g++;
}
}
cout << g;
return 0;
}
|
#include <bits/stdc++.h>
int main() {
int n, a[30], h[30], c = 0;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &h[i]);
scanf("%d", &a[i]);
}
for (int j = 0; j < n; j++) {
for (int i = 0; i < n; i++) {
if (h[j] == a[i]) c++;
}
}
printf("%d", c);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, sum = 0;
cin >> n;
int a[n + 5], h[n + 5];
for (int i = 0; i < n; i++) cin >> h[i] >> a[i];
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (a[i] == h[j]) sum++;
if (h[i] == a[j]) sum++;
}
}
cout << sum << endl;
return 0;
}
|
#include <bits/stdc++.h>
int main() {
int teamsNum, i, j, x = 0;
scanf("%i", &teamsNum);
int colors[teamsNum][2];
for (i = 0; i < teamsNum; i++)
for (j = 0; j < 2; j++) scanf("%i", &colors[i][j]);
for (i = 0; i < teamsNum; i++) {
for (j = 0; j < teamsNum; j++)
if (colors[i][0] == colors[j][1]) x++;
}
printf("%i", x);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, j, h[40], a[40], s = 0;
cin >> n;
for (i = 0; i < n; i++) {
cin >> h[i] >> a[i];
}
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
if (i != j) {
if (h[i] == a[j]) {
s++;
}
}
}
}
cout << s << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, j, count, sum, flag, temp;
struct team {
int h;
int g;
} t[35] = {0};
while (cin >> n) {
count = 0;
for (i = 0; i < n; i++) {
cin >> t[i].h >> t[i].g;
}
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
if (j == i) {
continue;
}
if (t[i].h == t[j].g) {
count++;
}
}
}
cout << count << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, arr[30][2], count = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> arr[i][0] >> arr[i][1];
}
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (i != j and arr[i][0] == arr[j][1]) count++;
cout << count << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, c = 0;
cin >> n;
int ar[n], arr[n];
for (int i = 0; i < n; i++) {
cin >> ar[i] >> arr[i];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (ar[i] == arr[j]) c++;
}
}
cout << c << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
map<int, int> mark1;
map<int, int> mark2;
int a[10000], b[10000], t;
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i] >> b[i];
mark1[a[i]]++;
mark2[b[i]]++;
}
for (int i = 1; i <= n; i++) {
t += mark1[b[i]];
}
cout << t;
}
|
#include <bits/stdc++.h>
int main() {
int n, i, count = 0, j;
scanf("%d", &n);
int arr[n][2];
for (i = 0; i < n; i++) {
scanf("%d %d", &arr[i][0], &arr[i][1]);
}
for (i = 0; i < n; i++) {
for (j = i + 1; j < n; j++) {
if (arr[i][0] == arr[j][1]) count++;
if (arr[i][1] == arr[j][0]) count++;
}
}
printf("%d", count);
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int games;
cin >> games;
vector<pair<int, int>> vec;
for (int i = 0; i < games; i++) {
int h, a;
cin >> h >> a;
vec.push_back((make_pair(h, a)));
}
int l = vec.size();
int count = 0;
for (int i = 0; i < l - 1; i++) {
for (int j = i + 1; j < l; j++) {
if (vec[i].first == vec[j].second) count++;
if (vec[i].second == vec[j].first) count++;
}
}
cout << count << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n;
int h[2][30];
int check() {
int cnt = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (h[0][i] == h[1][j] && j != i) {
cnt++;
}
}
}
return cnt;
}
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> h[0][i] >> h[1][i];
}
cout << check();
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, j, count{0};
cin >> n;
int h[n], g[n];
for (i = 0; i < n; i++) {
cin >> h[i] >> g[i];
}
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
if (h[i] == g[j]) count++;
}
}
cout << count << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
int a[n][2];
int count = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < 2; j++) {
cin >> a[i][j];
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i != j) {
if (a[i][0] == a[j][1]) {
count++;
}
}
}
}
cout << count << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<int> a(n);
vector<int> b(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
cin >> b[i];
}
int resp = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i == j) continue;
if (a[i] == b[j]) resp++;
}
}
cout << resp << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int arr[2 * n];
for (int i = 0; i < 2 * n; i++) {
cin >> arr[i];
}
int count = 0;
for (int i = 0; i < 2 * n; i += 2) {
for (int j = 1; j < 2 * n; j += 2) {
if (arr[i] == arr[j] && j - i != 1) {
count++;
}
}
}
cout << count;
}
|
#include <bits/stdc++.h>
int main() {
int N;
scanf("%d", &N);
int gu[N], hu[N], i, j, ct = 0;
for (i = 0; i < N; i++) {
scanf("%d %d\n", &hu[i], &gu[i]);
}
for (i = 0; i < N; i++) {
for (j = 0; j < N; j++) {
if (hu[i] == gu[j] && i != j) ct++;
}
}
printf("%d\n", ct);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, c = 0, temp;
int h[101], g[101];
cin >> n;
for (int i = 0; i < n; i++) {
cin >> h[i] >> g[i];
}
for (int j = 0; j < n; j++) {
temp = n - 1;
while (temp > j) {
if (h[j] == g[temp]) c++;
if (h[temp] == g[j]) c++;
temp--;
}
}
cout << c;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, cnt1 = 0, cnt2 = 0;
cin >> n;
int arr[n][2];
for (int i = 0; i < n; i++) {
for (int j = 0; j < 2; j++) {
cin >> arr[i][j];
}
}
for (int i = 0; i < n; i++) {
for (int k = 0; k < n; k++) {
if (arr[i][0] == arr[k][1]) {
cnt1 += 1;
}
}
}
cout << cnt1 << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int arr1[n];
int arr2[n];
int c = 0;
for (int i = 0; i < n; i++) {
cin >> arr1[i];
cin >> arr2[i];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (arr1[i] == arr2[j]) c += 1;
}
}
cout << c;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, ans = 0;
scanf("%d", &a);
vector<int> home(a), guest(a);
for (int i = 0; i < a; ++i) {
cin >> home[i] >> guest[i];
for (int j = 0; j < i; j++) {
if ((home[i] == guest[j])) ++ans;
if (home[j] == guest[i]) ++ans;
}
}
cout << ans << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, home[32], guest[32], count;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> home[i] >> guest[i];
}
count = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (home[i] == guest[j]) {
count++;
}
}
}
cout << count << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int arr[30];
int arr2[30];
int counter = 0;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> arr[i] >> arr2[i];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (arr[i] == arr2[j]) {
counter++;
}
}
}
cout << counter << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int a[110], b[110];
int main() {
int n;
while (scanf("%d", &n) == 1) {
int ans = 0;
for (int i = 0; i < n; i++) scanf("%d%d", &a[i], &b[i]);
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (a[i] == b[j]) ans++;
printf("%d\n", ans);
}
}
|
#include <bits/stdc++.h>
int main() {
int i = 0, j = 0, n, count = 0;
scanf("%d", &n);
int h[n], g[n];
for (i = 0; i < n; i++) {
scanf("%d%d", &h[i], &g[i]);
}
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
if (h[i] == g[j]) {
count++;
}
}
}
printf("%d\n", count);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, count = 0;
cin >> n;
int a[n], b[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
cin >> b[i];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (a[i] == b[j]) count++;
}
}
cout << count << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, count = 0;
cin >> n;
int home[n], guest[n];
for (int i = 0; i < n; ++i) {
cin >> home[i] >> guest[i];
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (home[i] == guest[j]) count++;
}
}
cout << count;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.