text stringlengths 49 983k |
|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, s = 0;
cin >> n;
long long g[n], h[n];
for (int i = 0; i < n; i++) {
cin >> h[i];
cin >> g[i];
}
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (h[i] == g[j]) s++;
cout << s;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a[200], x = 0;
cin >> n;
for (int i = 0; i < 2 * n; i++) {
cin >> a[i];
}
for (int i = 0; i < 2 * n; i += 2) {
for (int j = 1; j < 2 * n; j += 2)
if (a[i] == a[j]) x++;
}
cout << x;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, j, c = 0, x, y;
scanf("%d", &n);
int a[n], b[n];
for (i = 0; i < n; i++) {
scanf("%d %d", &x, &y);
a[i] = x;
b[i] = y;
}
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
if (a[i] == b[j]) {
c++;
}
}
}
cout << c << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int x[30], y[30], n;
int counter = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> x[i] >> y[i];
}
for (int i = 0; i < n; i++) {
for (int k = 0; k < n; k++) {
if (x[i] == y[k]) {
counter++;
}
}
}
cout << counter;
return 0;
}
|
#include <bits/stdc++.h>
int main() {
int n, i, j, x, y, cnt = 0;
scanf("%d", &n);
int a[n], b[n];
for (i = 0; i < n; i++) {
scanf("%d%d", &x, &y);
a[i] = x;
b[i] = y;
}
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
if (a[i] == b[j]) {
cnt++;
}
}
}
printf("%d\n", cnt);
return 0;
}
|
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
vector<int> home(101, 0);
vector<int> away(n);
int x;
for (int i = 0; i < n; i++) {
cin >> x;
home[x]++;
cin >> away[i];
}
long long sol = 0;
for (int i = 0; i < n; i++) {
sol += home[away[i]];
}
cout << sol;
return 0;
}
|
#include <bits/stdc++.h>
int main() {
int n, i, j, g = 0;
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 (i == j) {
continue;
} else if (h[i] == a[j]) {
g++;
}
}
}
printf("%d", g);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a;
vector<int> v;
vector<int> v1;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a;
v.push_back(a);
cin >> a;
v1.push_back(a);
}
int cont = 0;
sort(v.begin(), v.end());
sort(v1.begin(), v1.end());
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (v[i] == v1[j]) cont++;
if (v[i] < v1[j]) break;
}
}
cout << cont << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int i, j, cl = 0;
int h[n], a[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 (h[i] == a[j]) cl++;
}
}
cout << cl;
}
|
#include <bits/stdc++.h>
using namespace std;
void qs(int arr[], int x, int y) {
int i, j, p;
i = x;
j = y;
while (i < j) {
if (arr[i] < arr[j]) {
i++;
} else {
p = arr[j];
arr[j] = arr[i];
j--;
arr[i] = arr[j];
arr[j] = p;
}
}
if (x < j - 1) {
qs(arr, x, j - 1);
}
if (j + 1 < y) {
qs(arr, j + 1, y);
}
}
int main() {
int n, i, j, p, q, x, c;
cin >> n;
x = 0;
int a[n], b[n];
for (i = 0; i < n; i++) {
cin >> a[i] >> b[i];
}
qs(a, 0, n - 1);
qs(b, 0, n - 1);
i = 0;
j = 0;
p = 0;
q = 0;
while (i < n and j < n) {
if (a[i] < b[j]) {
i++;
} else if (a[i] > b[j]) {
j++;
} else {
for (c = i; c < n; c++) {
if (a[i] == a[c]) {
p++;
} else {
break;
}
}
i = c;
for (c = j; c < n; c++) {
if (b[j] == b[c]) {
q++;
} else {
break;
}
}
j = c;
x += p * q;
p = 0;
q = 0;
}
}
cout << x;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int x[n], y[n], cnt = 0;
for (int i = 0; i < n; i++) {
cin >> x[i] >> y[i];
}
sort(x, x + n);
sort(y, y + n);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (x[i] == y[j]) cnt++;
}
}
cout << cnt << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, c, j, i, l;
cin >> n;
int x[n][2];
for (i = 0; i < n; i++) {
for (j = 0; j < 2; j++) {
cin >> x[i][j];
}
}
c = 0;
for (l = 0; l < n; l++) {
for (i = 0; i < n; i++) {
if (x[l][0] == x[i][1]) c += 1;
}
}
cout << c;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int nom, counter = 0;
cin >> nom;
int uniform[nom][2];
for (int i = 0; i < nom; i++) {
for (int j = 0; j < 2; j++) {
cin >> uniform[i][j];
}
}
for (int i = 0; i < nom; i++) {
for (int j = i + 1; j < nom; j++) {
if (uniform[i][0] == uniform[j][1]) counter++;
if (uniform[i][1] == uniform[j][0]) counter++;
}
}
cout << counter;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char **argv) {
int n, r = 0;
cin >> n;
int h[n], v[n];
for (int k = 0; k < n; k++) {
cin >> h[k] >> v[k];
}
for (int k = 0; k < n; k++) {
for (int j = 0; j < n; j++) {
if (h[k] == v[j] && k != j) r++;
}
}
cout << r << endl;
return 0;
}
|
#include <bits/stdc++.h>
int a[33], b[33];
int main() {
int i, j, n, r = 0;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d%d", &a[i], &b[i]);
for (j = 0; j < i; j++) r += (a[i] == b[j]) + (a[j] == b[i]);
}
printf("%d", r);
}
|
#include <bits/stdc++.h>
using namespace std;
bool ab[100000000];
int ab1[1000000];
int ab2[1000000];
int v1[1000000];
int v2[1000000];
map<unsigned long long int, unsigned long long int> m;
map<unsigned long long int, unsigned long long int> m1;
map<unsigned long long int, unsigned long long int> m2;
vector<unsigned long long int>::iterator itr;
int main() {
string s12;
int a, b, d = 10000000, j = 0, i = 0, t, s = 0, s2, as, as1, n = 50, c = 0,
c2 = 0, l;
cin >> t;
s = t;
for (i = 0; i < s; i++) {
cin >> a >> b;
v1[i] = a;
v2[i] = b;
}
for (i = 0; i < s; i++) {
for (j = 0; j < s; j++)
if (v2[i] == v1[j]) c++;
if (v1[i] == v2[j]) c++;
}
cout << c << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int a[100001], s[100001], i, j, k, n;
int main() {
cin >> n;
for (i = 0; i < n; i++) {
cin >> a[i] >> s[i];
}
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
if (a[i] == s[j]) k++;
}
}
cout << k;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a[100], b[100], c = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
}
for (int j = 0; j < n; j++) {
for (int k = 0; k < n; k++) {
if (a[j] == b[k] && k != j) c++;
}
}
cout << c;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int* home = new int[n];
int* away = new int[n];
for (int i = 0; i < n; i++) {
cin >> home[i];
cin >> away[i];
}
int count = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (away[j] == home[i]) {
count++;
}
}
}
cout << count << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, s, count1 = 0;
cin >> n;
int g[2 * n];
int host[n];
int guest[n];
for (int i = 0; i < 2 * n; i++) {
cin >> s;
g[i] = s;
}
for (int i = 0; i < 2 * n; i++) {
for (int j = 1; j < 2 * n; j++) {
if (j % 2 == 1 && i % 2 == 0) {
if (g[i] == g[j]) count1 += 1;
}
}
}
cout << count1;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a[110][2], i, j, n, c = 0;
cin >> n;
for (i = 0; i < n; i++) {
cin >> a[i][0] >> a[i][1];
}
for (i = 0; i < n; i++) {
for (j = i + 1; j < n; j++) {
if (a[i][0] == a[j][1]) c++;
if (a[i][1] == a[j][0]) c++;
}
}
cout << c;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int ans = 0;
vector<pair<int, int> > v(n);
for (int i = 0; i < n; i++) cin >> v[i].first >> v[i].second;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (v[i].first == v[j].second) ans++;
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int main() {
int n;
int a[120];
int b[120];
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> a[i] >> b[i];
}
int ans = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (a[i] == b[j]) ans++;
}
}
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long t, n, m, g, o;
bool q = 1;
long long k, j, i, l, p;
vector<vector<int>> v(1e5);
vector<bool> visited(1e5, 0);
vector<int> vv, w;
queue<int> qq;
string s, h, c, u;
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> g >> t;
w.push_back(t);
vv.push_back(g);
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (j == i) continue;
if (w[j] == vv[i]) k++;
}
}
cout << k << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
int a[100];
int b[100];
int count = 0;
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 (b[i] == a[j]) {
count++;
}
}
}
cout << count;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, res = 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]) {
res++;
}
}
}
cout << res << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, counter = 0;
cin >> n;
int h[50] = {}, g[50] = {};
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]) {
counter++;
}
if (g[i] == h[j]) {
counter++;
}
}
}
cout << counter / 2 << endl;
return 0;
}
double power(double x, double y) {
double h = 1;
for (int i = 0; i < y; i++) {
h = h * x;
}
return h;
}
long long factorial(long long x) {
long long res = 1;
for (int i = 1; i <= x; i++) {
res = res * i;
}
return res;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int arr[30][2];
int n, k = 0;
cin >> n;
while (!(n >= 2 && n <= 30)) {
cout << "Please enter a number from 2 to 30" << endl;
cin >> n;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < 2; j++) {
cin >> arr[i][j];
while (!(arr[i][j] >= 1 && arr[i][j] <= 100)) {
cout << "Please enter a number from 1 to 100" << endl;
cin >> arr[i][j];
}
while ((j == 1) && (arr[i][j] == arr[i][j - 1])) {
cout << "please enter a number different to the home uniform" << endl;
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]) k++;
}
}
cout << k << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, n, j, a[30], h[30], c = 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 && h[i] == a[j]) {
c++;
}
}
}
cout << c << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a[30][2], t = 0;
cin >> n;
for (int i = 0; i < n; i++) {
for (int j = 0; j < 2; j++) {
cin >> a[i][j];
}
}
for (int r = 0; r < n; r++) {
for (int k = 0; k < n; k++) {
if (a[r][0] == a[k][1]) t++;
}
}
cout << t;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n], b[n];
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 << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, n, total = 0;
cin >> n;
int h[n], a[n];
for (i = 0; i < n; i++) cin >> h[i] >> a[i];
for (i = 0; i < n; i++) {
for (j = i + 1; j < n; j++) {
if (a[i] == h[j]) total++;
if (a[j] == h[i]) total++;
}
}
cout << total;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
const int MOD = (int)1e9 + 7;
const int N = (int)1e6 + 7;
char s[N], s1[N], s2[N];
int n, k;
pair<int, int> a[N];
void Init() {}
int Solve() {
for (int i = (0); i < (n); ++i) scanf("%d%d", &a[i].first, &a[i].second);
int cnt = 0;
for (int i = (0); i < (n); ++i)
for (int j = (0); j < (n); ++j)
if (i != j) {
if (a[i].first == a[j].second) cnt++;
}
return printf("%d\n", cnt);
}
int main() {
while (~scanf("%d", &n)) {
Init();
Solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int l, j, i, count = 0;
cin >> l;
int a[l], b[l];
for (i = 0; i < l; i++) {
cin >> a[i] >> b[i];
}
for (i = 0; i < l; i++) {
for (j = 0; j < l; j++) {
if (a[i] == b[j]) {
count++;
}
}
}
cout << count;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n][2], k = 0;
for (int i = 0; i < n; i++) {
cin >> a[i][0] >> a[i][1];
}
for (int i = 0; i < n; i++) {
for (int l = 0; l < n; l++) {
if (i != l)
if (a[i][0] == a[l][1]) k++;
}
}
cout << k;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int x;
cin >> x;
map<int, int> m;
map<int, int> mm;
int s = 0;
while (x--) {
int y, t;
cin >> y >> t;
m[y]++;
mm[t]++;
if (m[t] > 0) s += m[t];
if (mm[y] > 0) s += mm[y];
}
cout << s << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, cnt(0);
cin >> n;
int x[n], y[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 < n; j++) {
if (x[i] == y[j]) cnt++;
}
}
cout << cnt << endl;
return 0;
}
|
#include <bits/stdc++.h>
int main() {
int n, i, count = 0;
scanf("%d", &n);
int a[n], c[105] = {0};
for (i = 0; i < n; i++) {
int b = 0;
scanf("%d%d", &a[i], &b);
c[b]++;
}
for (i = 0; i < n; i++) count = count + c[a[i]];
printf("%d", count);
}
|
#include <bits/stdc++.h>
using namespace std;
int c[100][2];
int main() {
int n, sum = 0;
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d %d", &c[i][0], &c[i][1]);
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) {
if (j == i) continue;
if (c[i][0] == c[j][1]) sum++;
}
printf("%d\n", sum);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<pair<int, int> > v(n);
for (int i = 0; i < n; i++) cin >> v[i].first >> v[i].second;
int ans = 0;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (i != j and v[i].first == v[j].second) ans++;
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int count(int x, int* a, int s) {
int r = 0;
for (int i = 0; i < s; ++i) {
if (a[i] == x) ++r;
}
return r;
}
int main() {
int n, r = 0;
cin >> n;
int *h = new int[n], *g = new int[n];
for (int i = 0; i < n; ++i) {
int a, b;
cin >> a >> b;
r += count(a, g, i);
r += count(b, h, i);
h[i] = a;
g[i] = b;
}
cout << r;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
int color[n][2];
for (int i = 0; i < n; i++) {
scanf("%d %d", &color[i][0], &color[i][1]);
}
int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i != j) {
if (color[i][0] == color[j][1]) ans++;
}
}
}
printf("%d\n", ans);
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
const int INF = 105000;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, ans = 0;
cin >> n;
vector<pair<int, int> > a(n);
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
a[i].first = x, a[i].second = y;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (a[j].first == a[i].second && j != i) {
ans++;
}
}
}
cout << ans;
}
|
#include <bits/stdc++.h>
using namespace std;
int a[101], b[101];
int n, i, j, nr;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for (i = 1; i <= n; i++) cin >> a[i] >> b[i];
for (i = 1; i <= n; i++)
for (j = 1; j <= n; j++)
if (a[i] == b[j]) nr++;
cout << nr;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x[31], y[31], sum = 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 < n; j++) {
if (x[i] == y[j]) sum++;
}
}
cout << sum << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, j, x, y, cnt = 0;
scanf("%d", &n);
int a[n], b[n];
for (i = 0; i < n; i++) {
scanf("%d%d", &x, &y);
a[i] = x;
b[i] = y;
}
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
if (a[i] == b[j]) {
cnt++;
}
}
}
printf("%d\n", cnt);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
struct kk {
int a;
int b;
} c[50];
int main() {
int n, i, k = 0, j;
cin >> n;
for (i = 0; i < n; i++) cin >> c[i].a >> c[i].b;
for (i = 0; i < n; i++)
for (j = 0; j < n; j++) {
if (c[i].a == c[j].b) k++;
}
cout << k << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
map<int, pair<int, int>> d;
int i = 0;
while (n--) {
int h, a;
cin >> h >> a;
pair<int, int> p = make_pair(h, a);
d.insert({i++, p});
}
int changes = 0;
for (auto i = d.begin(); i != d.end(); i++) {
for (auto j = d.begin(); j != d.end(); j++) {
if (i != j) {
if (i->second.first == j->second.second) {
changes++;
}
}
}
}
cout << changes << '\n';
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1000000007ll;
const long long int MOD = 1000000009ll;
int local_debug = 0;
long long int bit_count(long long int _x) {
long long int _ret = 0;
while (_x) {
if (_x % 2 == 1) _ret++;
_x /= 2;
}
return _ret;
}
long long int bit(long long int _mask, long long int _i) {
long long int x = 1;
return (_mask & (x << _i)) == 0 ? 0 : 1;
}
long long int powermod(long long int _a, long long int _b,
long long int _m = mod) {
long long int _r = 1;
while (_b) {
if (_b % 2 == 1) _r = (_r * _a) % _m;
_b /= 2;
_a = (_a * _a) % _m;
}
return _r;
}
long long int power(long long int _a, long long int _b) {
long long int _r = 1;
while (_b) {
if (_b % 2 == 1) _r = (_r * _a);
_b /= 2;
_a = (_a * _a);
}
return _r;
}
long long int add(long long int a, long long int b, long long int m = mod) {
a %= m;
b %= m;
long long int x = a + b;
while (x >= m) x -= m;
return x;
}
long long int sub(long long int a, long long int b, long long int m = mod) {
long long int x = a - b;
while (x < 0) x += m;
return x;
}
long long int mul(long long int a, long long int b, long long int m = mod) {
a %= m;
b %= m;
long long int x = a * b;
x %= m;
return x;
}
long long int gcd(long long int a, long long int b) {
if (a < b) {
a = a ^ b;
b = a ^ b;
a = a ^ b;
}
if (b == 0) return a;
long long int t;
while (b) {
t = b;
b = a % b;
a = t;
}
return a;
}
long long int lcm(long long int a, long long int b) {
return (a * b) / gcd(a, b);
}
long long int maxSubArraySum(vector<long long int> a, long long int size) {
long long int max_so_far = a[0];
long long int curr_max = a[0];
for (long long int i = 1; i < size; i++) {
curr_max = max(a[i], curr_max + a[i]);
max_so_far = max(max_so_far, curr_max);
}
return max_so_far;
}
int main() {
long long int n;
scanf("%lld", &n);
;
vector<long long> hrr(n);
vector<long long> grr(n);
for (int i = 0; i < n; i++) {
scanf("%lld", &hrr[i]);
;
scanf("%lld", &grr[i]);
;
}
int count = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j <= n; j++) {
if (hrr[i] == grr[j]) {
count++;
}
}
}
cout << count << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<vector<int>> v;
vector<int> temp(2);
while (n--) {
cin >> temp[0] >> temp[1];
v.push_back(temp);
}
int sum = 0;
for (int i = 0; i < v.size(); i++) {
for (int j = 0; j < v.size(); j++) {
if (i == j) {
continue;
}
if (v[i][1] == v[j][0]) {
sum++;
}
}
}
cout << sum;
}
|
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline istream& read(vector<T>& v) {
for (auto& p : v) cin >> p;
return cin;
}
template <class T>
inline istream& read(vector<vector<T>>& v) {
for (auto& p : v) read(p);
return cin;
}
inline void printf(const int d) { printf("%d", d); }
inline void printf(const long long d) { printf("%lld", d); }
inline void printf(const char c) { printf("%c", c); }
inline void printf(const string& s) { printf("%s", s.c_str()); }
inline void print() { printf("\n"); }
template <class T>
inline void print(const T& t) {
printf(t);
printf("\n");
}
template <class... A>
inline void print(const char f[], const A&... a) {
printf(f, a...);
printf("\n");
}
template <class T, class... A>
inline void print(const T& t, const A&... a) {
printf(t);
printf(" ");
print(a...);
}
template <class T>
inline void print(const vector<T>& v, bool newline = false) {
for (size_t i = 0; i < v.size(); i++) {
printf(i == 0 ? "" : newline ? "\n" : " ");
printf(v[i]);
}
print();
}
int inf = 0x3f3f3f3f;
double eps = 1e-8;
long long mod = 1000000007ll;
long long binf = 0x3f3f3f3f3f3f3f3f;
struct FastIO {
FastIO() {
cin.sync_with_stdio(0);
cin.tie(0);
}
};
FastIO fio;
template <class T>
map<T, int> tally(const vector<T>& arr) {
map<T, int> result;
for (auto& v : arr) result[v]++;
return result;
}
template <class T>
vector<T> factor(T n) {
vector<T> result;
if (n < 0) {
result.push_back(-1);
n = -n;
}
while (n % 2 == 0) {
result.push_back(2);
n /= 2;
}
while (n % 3 == 0) {
result.push_back(3);
n /= 3;
}
for (T p = 5; p * p <= n; p += 6) {
while (n % p == 0) {
result.push_back(p);
n /= p;
}
while (n % (p + 2) == 0) {
result.push_back(p + 2);
n /= p + 2;
}
}
if (n > 1) result.push_back(n);
return result;
}
template <class T>
vector<int> kmp_pre(const T& p) {
int n = p.size(), start = 0;
vector<int> match(n);
for (int i = 1; i < n; i++) {
while (start > 0 && p[i] != p[start]) start = match[start - 1];
if (p[i] == p[start]) start++;
match[i] = start;
}
return match;
}
template <class T>
vector<int> kmp_match(const T& s, const T& p, const vector<int>& match,
bool fs = false) {
int n = p.size(), m = s.size(), start = 0;
vector<int> result;
for (int i = 0; i < m; i++) {
while (start > 0 && s[i] != p[start]) start = match[start - 1];
if (s[i] == p[start]) start++;
if (start == n) {
result.push_back(i - n + 1);
if (fs) return result;
start = match[start - 1];
}
}
return result;
}
template <class T>
vector<int> kmp(const T& s, const T& p, bool fs = false) {
return kmp_match(s, p, kmp_pre(p), fs);
}
int main() {
int n, ans = 0;
cin >> n;
vector<int> home(n), guest(n);
for (int i = (0); i < int(n); i++) cin >> home[i] >> guest[i];
for (int i = 0; i < (n); i++)
for (int j = 0; j < (n); j++) {
if (i == j) continue;
if (home[i] == guest[j]) ans++;
}
print(ans);
}
|
#include <bits/stdc++.h>
using namespace std;
const int INF = ~0U >> 1;
const double eps = 1e-6;
const int MAXN = 100;
int n, A[MAXN], B[MAXN];
int main() {
cin >> n;
for (int i = 0; i < n; i++) scanf("%d %d", &A[i], &B[i]);
int res = 0;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (j != i)
if (A[i] == B[j]) res++;
cout << res << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int h[n];
int a[n];
int k = 0;
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 (h[i] == a[j]) {
k = k + 1;
}
if (h[j] == a[i]) {
k = k + 1;
}
}
}
cout << endl << k;
}
|
#include <bits/stdc++.h>
using namespace std;
struct team {
int h;
int a;
};
int main() {
int n;
int c = 0;
cin >> n;
team t[100];
for (int i = 0; i < n; i++) {
cin >> t[i].h;
cin >> t[i].a;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (t[i].a == t[j].h) {
c++;
}
}
}
cout << c;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a_g[n];
int arr[101] = {0};
int a_h[n];
for (int i = 0; i < n; i++) {
cin >> a_h[i];
cin >> a_g[i];
arr[a_g[i]]++;
}
int ctr = 0;
for (int i = 0; i < n; i++) {
ctr += arr[a_h[i]];
}
cout << ctr;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using namespace std;
using namespace std;
signed main() {
long long n;
cin >> n;
vector<long long> v1(n);
vector<long long> v2(n);
for (long long i = 0; i < (long long)(n); ++i) {
cin >> v1[i] >> v2[i];
}
long long c = 0;
for (long long i = 0; i < (long long)(n); ++i) {
for (long long j = 0; j < (long long)(n); ++j) {
if (v1[i] == v2[j]) c++;
}
}
cout << c << "\n";
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, c = 0;
cin >> n;
int a[n * 2];
for (int i = 0; i < n * 2; i++) cin >> a[i];
if (n == 2) {
if (a[1] == a[2]) c++;
if (a[0] == a[3]) c++;
} else {
for (int i = 1; i < n * 2; i += 2) {
for (int j = 0; j < n * 2; j += 2) {
if (a[i] == a[j]) c++;
}
if (a[i] == a[i - 1]) c--;
}
}
cout << c;
return 0;
}
|
#include <bits/stdc++.h>
int teams[30][2];
using namespace std;
int main() {
int h, a, count = 0, n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> h >> a;
teams[i][0] = h;
teams[i][1] = a;
}
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) {
if (j == i) continue;
if (teams[i][0] == teams[j][1]) count++;
}
cout << count;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
struct bl {
int x, y;
};
int main() {
int n, cnt = 0;
bl a[31];
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i].x >> a[i].y;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (a[i].x == a[j].y) cnt++;
cout << cnt;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, s = 0, i, j;
cin >> n;
int a[n], b[n];
for (i = 0; i <= n - 1; i++) cin >> a[i] >> b[i];
for (j = 0; j <= n - 1; j++)
for (i = 0; i <= n - 1; i++) {
if (i == j) {
i++;
}
if (i <= n - 1) {
if (a[j] == b[i]) s++;
}
}
cout << s;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int c1, c2;
int count = 0;
int* primary_color = new int[n];
int* secondary_color = new int[n];
for (int i = 0; i < n; i++) {
cin >> primary_color[i] >> secondary_color[i];
}
int j = 0;
while (j < n) {
for (int i = 0; i < n; i++) {
if (primary_color[j] == secondary_color[i]) {
count++;
}
}
j++;
}
cout << count << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
void solve() {
int i, j, n, ct = 0;
cin >> n;
int h[n], g[n];
for (i = 0; i < n; i++) cin >> h[i] >> g[i];
sort(h, h + n);
sort(g, g + n);
i = 0;
j = 0;
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
if (h[i] == g[j]) ct++;
}
}
cout << ct;
}
int main() {
auto start = chrono::high_resolution_clock::now();
ios_base::sync_with_stdio(false);
int t = 1;
while (t--) solve();
auto stop = chrono::high_resolution_clock::now();
auto durn = chrono::duration_cast<chrono::microseconds>(stop - start);
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int i, n, j, c = 0;
cin >> n;
int s[n];
int a[n];
for (i = 0; i < n; i++) cin >> s[i] >> a[i];
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++)
if (i != j && s[i] == a[j]) c++;
}
cout << c;
return (0);
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int i, j, ctn = 0;
int h[n], a[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 (h[i] == a[j]) ctn++;
}
}
cout << ctn;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, count = 0;
cin >> a;
int x[a], y[a];
for (int i = 0; i < a; i++) {
cin >> x[i];
cin >> y[i];
}
for (int i = 0; i < a; i++) {
for (int j = 0; j < a; j++) {
if (x[i] == y[j]) {
count++;
}
}
}
cout << count;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<pair<int, int> > vect;
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
vect.push_back(make_pair(x, y));
}
int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (vect[i] != vect[j]) {
if (vect[i].first == vect[j].second) ans++;
}
}
}
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
std::ios::sync_with_stdio(false);
int n, cnt = 0;
cin >> n;
vector<int> v1(n);
vector<int> v2(n);
for (int i = 0; i < n; i++) cin >> v1[i] >> v2[i];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (v1[i] == v2[j]) {
cnt++;
}
}
}
cout << cnt;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n], b[n];
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
}
int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (a[i] == b[j]) ans++;
}
}
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, count = 0;
cin >> n;
int a[n], b[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]) {
count++;
}
}
}
cout << count;
}
|
#include <bits/stdc++.h>
int main() {
int n, a[30], b[30], i, j, count;
while (~scanf("%d", &n)) {
count = 0;
for (i = 0; i < n; i++) scanf("%d%d", &a[i], &b[i]);
for (i = 0; i < n; i++)
for (j = 0; j < n; j++)
if (a[i] == b[j]) count++;
printf("%d\n", count);
}
return 0;
}
|
#include <bits/stdc++.h>
const long long int MOD = 1e9 + 7;
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1, -1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
using namespace std;
void vok() {
ios_base::sync_with_stdio(false);
cout.tie(NULL);
cin.tie(NULL);
}
long long int gcd(long long int a, long long int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
long long int lcm(long long int a, long long int b) {
return ((a * b) / gcd(a, b));
}
vector<long long int> pp;
void gen() {
vector<bool> prime(33000, true);
prime[0] = prime[1] = false;
for (int p = 0; p * p <= 33000; p++) {
if (prime[p]) {
for (int i = p * p; i <= 33000; i += p) prime[i] = false;
}
}
for (int i = 0; i < 33000; i++)
if (prime[i]) pp.push_back(i);
}
long long int find(vector<int>& A, int n) {}
void solve() {
long long int n, m, x, y, a, b, k;
a = b = x = y = k = 0;
long long int ans = 0, res = 0;
cin >> n;
string str;
vector<int> A, B;
for (int i = 0; i < n; i++) {
cin >> a;
cin >> b;
A.push_back(a);
B.push_back(b);
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (A[i] == B[j]) x++;
}
}
cout << x << endl;
}
int main() {
vok();
int t = 1;
while (t--) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, h = 0;
cin >> n;
int **ary = new int *[n];
for (int i = 0; i < n; ++i) {
ary[i] = new int[2];
}
for (int i = 0; i < n; i++) {
for (int q = 0; q < 2; q++) cin >> ary[i][q];
}
for (int q = 0; q < n; q++) {
for (int i = 0; i < n; i++) {
if (ary[i][0] == ary[q][1]) {
h++;
}
}
}
cout << h << endl;
for (int i = 0; i < n; ++i) {
delete[] ary[i];
}
delete[] ary;
return 0;
}
|
#include <bits/stdc++.h>
int main() {
int n, i, a = 0;
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 (int j = i + 1; j < n; j++) {
if (arr[i][0] == arr[j][1]) {
a++;
}
if (arr[i][1] == arr[j][0]) {
a++;
}
}
}
printf("%d", a);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int h[35], g[35];
int n;
int ret;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> h[i] >> g[i];
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
if (i != j && h[i] == g[j]) ret++;
cout << ret;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, j, ans = 0;
cin >> n;
int h[n], a[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]) ans++;
}
}
}
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<pair<int, int>> color(n);
vector<int> h(101, 0), g(101, 0);
for (int i = 0; i < n; ++i) {
cin >> color[i].first >> color[i].second;
++h[color[i].first];
++g[color[i].second];
}
int ans = 0;
for (int i = 1; i < 101; ++i) {
ans += (h[i] * g[i]);
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, c = 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]) c++;
}
}
cout << c << "\n";
return 0;
}
|
#include <bits/stdc++.h>
int main() {
int n, i, j, r, c, count = 0;
scanf("%d", &n);
int A[n + 100][2];
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]) count++;
}
}
printf("%d\n", count);
return 0;
}
|
#include <bits/stdc++.h>
int main() {
int i, j, k, n, count = 0;
scanf("%d", &n);
int a[n][2];
for (i = 0; i < n; i++) {
for (j = 0; j < 2; j++) scanf("%d", &a[i][j]);
}
for (i = 0; i < n; i++) {
for (k = 0; k < n; k++) {
if (i != k) {
if (a[i][0] == a[k][1]) count++;
}
}
}
for (i = 0; i < n; i++) {
for (k = 0; k < n; k++) {
if (i != k) {
if (a[i][1] == a[k][0]) count++;
}
}
}
printf("%d", count / 2);
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n][2], i, j;
for (i = 0; i < n; i++) {
for (j = 0; j < 2; j++) cin >> a[i][j];
}
int c = 0;
for (i = 0; i < n; i++) {
for (j = i + 1; j < n; j++) {
if (a[i][0] == a[j][1]) c++;
if (a[i][1] == a[j][0]) c++;
}
}
cout << c << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, j, h, a, hs[101], as[101], c = 0;
cin >> n;
for (i = 1; i <= 100; i++) {
hs[i] = 0;
as[i] = 0;
}
for (i = 1; i <= n; i++) {
cin >> h >> a;
hs[h]++;
as[a]++;
}
for (i = 1; i <= 100; i++) {
c = c + hs[i] * as[i];
}
cout << c;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, j, cou = 0, a[30][2];
cin >> n;
for (i = 0; i < n; i++) cin >> a[i][0] >> a[i][1];
for (i = 0; i < n - 1; i++) {
for (j = i + 1; j < n; j++) {
if (a[i][0] == a[j][1]) cou++;
if (a[j][0] == a[i][1]) cou++;
}
}
cout << cou << endl;
return 0;
}
|
#include <bits/stdc++.h>
int main() {
int n, i, j, counter = 0;
scanf("%d", &n);
int a[n][2];
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]) counter++;
}
}
printf("%d", counter);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int l[101], r[101], n, a, b;
cin >> n;
for (int i = 0; i < 101; i++) {
l[i] = 0;
r[i] = 0;
}
for (int i = 1; i <= n; i++) {
cin >> a >> b;
l[a]++;
r[b]++;
}
int count = 0;
for (int i = 0; i < 101; i++) count = count + (l[i] * r[i]);
cout << count << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, h[110], a[110];
int total;
int main() {
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%d %d", &h[i], &a[i]);
}
for (int i = 0; i < n - 1; ++i) {
for (int j = i + 1; j < n; ++j) {
if (h[i] == a[j]) total++;
if (h[j] == a[i]) total++;
}
}
printf("%d\n", total);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, cnt = 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 (i != j) {
if (h[i] == g[j]) cnt++;
}
}
}
cout << cnt;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
cout << setprecision(10);
long long int n, i, l, k, j, a = 0, f = 0, c = 0, b = 0, x = 1000000007, d, y;
string s, w;
vector<long long int> vc, vct;
vector<string> ch;
double num, nr, radi;
cin >> x;
for (i = 0; i < x; i++) {
cin >> a >> b;
vc.push_back(a);
vct.push_back(b);
}
for (i = 0; i < x; i++) {
for (j = 0; j < x; j++) {
if (vc[i] == vct[j]) c++;
}
}
cout << c << endl;
}
|
#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, h, g;
vector<int> v1, v2;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> h >> g;
v1.push_back(h);
v2.push_back(g);
}
int ans = 0;
for (auto it = v1.begin(); it != v1.end(); it++) {
for (auto it2 = v2.begin(); it2 != v2.end(); it2++) {
if (*it == *it2) ans++;
}
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
int main() {
int i, j, n, data[35][2], cnt = 0;
scanf("%d", &n);
for (i = 1; i <= n; i++) {
scanf("%d %d", &data[i][0], &data[i][1]);
}
for (i = 1; i <= n; i++) {
for (j = 1; j <= n; j++) {
if (i != j && data[i][0] == data[j][1]) cnt++;
}
}
printf("%d", cnt);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, c = 0;
cin >> n;
int h[n], a[n];
for (int i = 0; i < n; i++) {
cin >> h[i];
cin >> a[i];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (h[i] == a[j]) {
c++;
}
}
}
cout << c << endl;
return 0;
}
|
#include <bits/stdc++.h>
int main() {
int n, a[30], b[30], i, j, k = 0;
scanf("%d", &n);
for (i = 0; i < n; i++) scanf("%d%d", &a[i], &b[i]);
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
if (a[i] == b[j]) k++;
}
}
printf("%d", k);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
set<char> myset;
long long n, amount, a[1111111], ans, b[111];
string s;
void fun1();
void fun2();
void fun3();
void fun4();
void fun5();
void fun6();
void fun7();
int main() {
fun2();
return 0;
}
void fun1() {
char ch = ' ';
while (ch != '}') {
cin >> ch;
if (ch != '{' && ch != ' ' && ch != ',') myset.insert(ch);
}
cout << myset.size() - 1;
}
void fun2() {
int y, ans = 0, x;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> x >> y;
a[x]++;
b[y]++;
}
for (long long i = 0; i <= 100; i++) {
if (a[i]) ans += a[i] * b[i];
}
cout << ans;
}
void fun3() {
int x;
cin >> n;
int mx = -1, mn = 9999999999, numbermx, numbermn;
for (long long i = 0; i < n; i++) {
cin >> x;
if (mx < x) {
numbermx = i;
mx = x;
}
if (mn >= x) {
numbermn = i;
mn = x;
}
}
if (numbermn < numbermx) {
cout << numbermx + n - 2 - numbermn;
} else {
cout << numbermx + n - 1 - numbermn;
}
}
void fun4() {
char ch;
long long ans1 = 0, ans2 = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> ch;
if (ch == 'D')
ans1++;
else
ans2++;
}
if (ans1 == ans2)
cout << "Friendship";
else {
if (ans1 > ans2)
cout << "Danik";
else
cout << "Anton";
}
}
void fun5() {
long long x = 0, sumans = 0;
cin >> n;
for (long long i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
for (long long i = 0; i < n; i++) {
cout << a[i] << " ";
}
}
void fun6() {
char ch;
cin >> s;
int n1 = s.length(), low = 0, up = 0, x = 0;
for (int i = 0; i < n1; i++) {
cin >> ch;
if (s[i] == '0')
low = 0;
else
low = 1;
if (ch == '0')
up = 0;
else
up = 1;
if (low != up && low + up == 1)
cout << 1;
else
cout << 0;
}
}
void fun7() {
char a, b, c, d;
cin >> a >> b >> c >> d;
if (d == '9') {
d = '0';
if (c == '9') {
c = '0';
if (b == '9') {
b = '0';
a++;
} else
b++;
} else
c++;
} else
d++;
for (; a <= '9'; a++) {
for (; b <= '9'; b++) {
for (; c <= '9'; c++) {
for (; d <= '9'; d++) {
if (a != b && a != c && a != d && b != c && b != d && c != d) {
cout << a << b << c << d;
return;
}
}
d = '0';
}
c = '0';
}
b = '0';
}
}
|
#include <bits/stdc++.h>
int main() {
int n, sum = 0;
scanf("%d", &n);
int a[n], h[n];
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]) {
sum = sum + 1;
}
}
}
printf("%d", sum);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void solve();
void precalc();
int main() {
string s = "change me please";
int t = 1;
while (t--) solve();
return 0;
}
void solve() {
int n;
cin >> n;
vector<int> a(n), h(n);
for (int i = 0; i < n; ++i) cin >> a[i] >> h[i];
int ans = 0;
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
if (a[i] == h[j]) ++ans;
cout << ans;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> home;
vector<int> away;
int h, a;
for (int i = 0; i < n; i++) {
cin >> h >> a;
home.push_back(h);
away.push_back(a);
}
int sum = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++)
if (home[i] == away[j]) sum++;
}
cout << sum << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, h[50], a[50], i, j, ans = 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 (h[i] == a[j]) ans++;
}
}
cout << ans;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
int n;
cin >> n;
int h[n], a[n];
for (int i = 0; i < n; i++) {
cin >> h[i] >> a[i];
}
int cnt = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (h[i] == a[j]) cnt++;
}
}
cout << cnt;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
bool anagram(char *s1, char *s2) {
long long int count[256];
memset(count, 0, sizeof(count));
long long int i;
for (i = 0; s1[i] && s2[i]; i++) {
count[s1[i]]++;
count[s2[i]]--;
}
if (s1[i] || s2[i]) {
return false;
}
for (long long int i = 0; i < 256; i++) {
if (count[i]) {
return false;
}
}
return true;
}
long long int moduloMultiplication(long long int a, long long int b,
long long int zz) {
long long int res = 0;
a %= 1000000007;
while (b) {
if (b & 1) res = (res + a) % zz;
a = (2 * a) % zz;
b >>= 1;
}
return res;
}
long long int convert(string s) {
bool o = true;
long long int ans = 0;
for (long long int i = 0; i < s.length(); i++) {
ans = ans * 10 + (s[i] - 48);
}
return ans;
}
long long int powmod(long long int a, long long int b, long long int modulo) {
if (b == 0 || a == 1) return 1;
long long int half = powmod(a, (b / 2), modulo) % modulo;
long long int full = (half * half) % modulo;
if (b % 2) return (full * a) % modulo;
return full % modulo;
}
long long int invmod(long long int a, long long int modulo) {
long long int check = powmod(a, modulo - 2, modulo) % modulo;
return check;
}
long long int max(long long int a, long long int b) {
if (a > b) {
return a;
}
return b;
}
long long int min(long long int a, long long int b) {
if (a < b) {
return a;
}
return b;
}
long long int min(long long int a, long long int b, long long int c) {
if (a < b) {
return min(a, c);
} else {
return min(b, c);
}
}
long long int max(long long int a, long long int b, long long int c) {
if (a < b) {
return max(b, c);
} else {
return min(a, c);
}
}
long long int min(long long int a, int b) {
if (a < b) return a;
return b;
}
long long int min(int a, long long int b) {
if (a < b) return a;
return b;
}
long long int max(long long int a, int b) {
if (a > b) return a;
return b;
}
long long int max(int a, long long int b) {
if (a > b) return a;
return b;
}
long long int gcd(long long int a, long long int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
long long int lcm(long long int a, long long int b) {
return a / gcd(a, b) * b;
}
void yes() {
cout << "YES"
<< "\n";
}
void no() {
cout << "NO"
<< "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long int n, k, m, ans = 0, flag = 0, temp = 0, f1 = 0, count = 0, f2 = 0,
sum = 0, xx = 0, minn1 = 1e18, minn2 = 1e18,
maxx1 = -1e18, maxx2 = -1e18;
cin >> n;
long long int a[n][2];
for (long long int i = 0; i < n; i++) {
cin >> a[i][0] >> a[i][1];
}
for (long long int i = 0; i < n; i++) {
for (long long int j = 0; j < n; j++) {
if (a[i][0] == a[j][1]) {
count++;
}
}
}
cout << count << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a;
cin >> a;
int vmarr[1001][1001];
for (int i = 0; i < a; i++) {
int a1, b1;
cin >> a1 >> b1;
vmarr[i][0] = a1;
vmarr[i][1] = b1;
}
int vmans = 0;
for (int i = 0; i < a; i++) {
int temp = vmarr[i][0];
int temp2 = vmarr[i][1];
for (int j = i + 1; j < a; j++) {
if (vmarr[j][1] == temp) {
vmans++;
}
}
for (int j = i + 1; j < a; j++) {
if (vmarr[j][0] == temp2) {
vmans++;
}
}
}
cout << vmans;
return 0;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.