F. We Were Both Children
Input
7
5
1 2 3 4 5
3
2 2 2
6
3 1 3 4 9 10
9
1 3 2 4 2 3 7 8 5
1
10
8
7 11 6 8 12 4 4 810
9 11 9 12 1 7 2 5 8 10
Output
3
3
3
5
0
4
4
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define xx first
#define yy second
typedef pair<int, int> PII;
const int inf = 0x3f3f3f3f;
const int N = 1e6 + 10;
int v[N], n, m, k, x, t, T;
map<int, int> mp;
void ClearFloat()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
signed main()
{
ClearFloat();
cin >> T;
while (T--)
{
memset(v, 0, sizeof v);
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> x;
mp[x]++;
}
for (auto [a, b] : mp)
{
for (int i = a; i <= n; i += a)
v[i] += b;
}
int ans = 0;
for (auto i : v)
{
if (i > ans)
ans = i;
}
cout << ans << endl;
mp.clear();
}
return 0;
}
G. The Morning Star
Input
5
3
0 0
-1 -1
1 1
4
4 5
5 7
6 9
10 13
3
-1000000000 1000000000
0 0
1000000000 -1000000000
5
0 0
2 2
-1 5
-1 10
2 11
3
0 0
-1 2
1 -2
Output
6
2
6
8
0
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define xx first
#define yy second
typedef pair<int, int> PII;
const int inf = 0x3f3f3f3f;
const int N = 1e6 + 10;
int v[N], n, m, k, x, t, T, y;
void ClearFloat()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
signed main()
{
ClearFloat();
cin >> T;
while (T--)
{
cin >> n;
map<int, int> up, side, dig, udig;
for (int i = 1; i <= n; i++)
{
cin >> x >> y;
up[x]++;
side[y]++;
dig[x + y]++;
udig[x - y]++;
}
int ans = 0;
for (auto i : up)
ans += i.second * (i.second - 1);
for (auto i : side)
ans += i.second * (i.second - 1);
for (auto i : dig)
ans += i.second * (i.second - 1);
for (auto i : udig)
ans += i.second * (i.second - 1);
cout << ans << endl;
}
return 0;
}