solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int a = 1000, b = 2011;
bool ok(int p, int q) {
int cn = 0;
while (p) {
if (p % 10 != q % 10) cn++;
p /= 10;
q /= 10;
}
if (cn <= 1)
return true;
else
return false;
}
int main() {
int i, j, k, l, m, n, c;
cin >> n;
vector<int> ans;
for ... | 9 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const int mx = 3e5;
int n, k;
long long a[mx], p[mx], pref[mx];
int main() {
cin >> n >> k;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
for (int i = 0; i < n; ++i) {
cin >> p[i];
}
for (int i = 1; i <= n; ++i) {
pref[i... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int M = 1e6 + 3;
int ara[N];
int main() {
int n;
cin >> n;
ara[0] = 1;
ara[1] = 1;
for (int i = 2; i <= n; i++) {
ara[i] = (3 * ara[i - 1]) % M;
}
cout << ara[n] << "\n";
return 0;
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
long long arr[n];
int i;
for (i = 0; i < n; i++) cin >> arr[i];
vector<bool> rmfld(n, false);
vector<bool>::iterator itr;
for (i = 0; i < n; i++) {
int val = (i + arr[i]) % n;
if (val < 0) val = n + val;
rmfld[val]... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n;
int ans[N];
int t[2 * N], id[2 * N];
int main() {
scanf("%d", &n);
stack<int> st;
for (int i = 0, j = 0; i < 2 * n; i++) {
char c;
scanf(" %c", &c);
if (c == '-') {
t[i] = -1;
scanf("%d", id + i);
if (st.empty... | 9 |
#include <bits/stdc++.h>
using namespace std;
struct ban {
int a, b, c;
};
struct ban1 {
int x, d;
};
bool operator<(const ban1& a, const ban1& b) { return a.d > b.d; }
int n, m, k;
string s;
ban a[12][102];
ban1 b[102];
int ans;
int main() {
int i, j, ii, jj;
cin >> n >> m >> k;
int ck = k;
for (i = 0; i <... | 4 |
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:64000000")
const int MAXN = 200005;
int n;
pair<long long, int> f[MAXN][2];
int a[MAXN];
pair<long long, int> rec(int x, int y) {
if (x >= n) return pair<long long, int>(0LL, 0);
if (x < 0) return pair<long long, int>(0LL, 0);
if (!x) {... | 9 |
#include <bits/stdc++.h>
using namespace std;
inline void IO() {
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
}
int main(int argc, char const *argv[]) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int n;
cin >> n;
long long int lb = 1, inc = 0, ub = 1;
while (true... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int MaxN = 300;
int n;
int a[MaxN], b[MaxN];
int main() {
cin.sync_with_stdio(0);
cin >> n;
for (int i = 0; i < n; i++) {
char c;
cin >> c;
a[i] = c - '0';
}
for (int i = 0; i < n; i++) {
char c;
cin >> c;
b[i] = c - '0';
}
sort(a... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 70;
int n, k, a[maxn][2];
bool check() {
int x[2] = {0, 0}, s = 0, l = 1;
for (int *p = a[0]; p < a[n]; p += 2) {
if (p[s] > p[l]) swap(s, l);
long long d = p[l] - (long long)p[s] * k + x[l];
if (d > k)
return false;
else if ... | 17 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
int const N = 1e5 + 5, M = 1005;
using namespace std;
long long n, m, out[M], in[M], low, lst, si[M];
vector<vector<long long>> v;
bool vis[M];
vector<pair<pair<long long, long long>, long long>> ans;
void dfs(long long node) {
lst = node;
vis[node] = true;
for ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.sync_with_stdio(false);
cout.sync_with_stdio(false);
double a, b, c, s, x, y, z, sum;
cin >> s >> a >> b >> c;
sum = a + b + c;
if (sum == 0) {
x = y = 0;
z = s;
} else {
x = a / sum * s;
y = b / sum * s;
z = c / sum * s;
... | 10 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
int a[5][55];
struct tp {
int x, y, z;
};
vector<tp> sol;
void db() {
for (int i = 1; i <= n; i++) cerr << a[2][i] << ' ';
cerr << '\n';
for (int i = 1; i <= n; i++) cerr << a[3][i] << ' ';
cerr << '\n';
cerr << '\n';
}
bool ostalo() {
for (int i = 1... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int x[n];
int sum = 0;
for (int i = 0; i < n; i++) {
cin >> x[i];
sum += x[i];
}
if (sum != 0) {
cout << "YES" << endl;
cout << 1 << endl;
cout << 1 << " " << n << endl;
return 0;
}
int it = -22;
for ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x = 0, c = 0;
string s;
cin >> s;
for (int i = 0; i < s.size(); i++) {
if (s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' || s[i] == 'u')
c++;
else if (s[i] >= '0' && s[i] <= '9') {
x = s[i] - '0';
if (x % 2 != 0)... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000010;
const int mod = 1000000007;
set<int> s[N];
long long a[N];
long long qpow(long long B, long long E) {
long long A = 1;
for (; E; E >>= 1, B = B * B % mod) E& 1 ? A = A * B % mod : 0;
return A;
}
int main() {
int n;
cin >> n;
for (int i = 1... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, m, q;
int tt;
int ss = n + m;
int fa[400005];
bool vis[500005];
int ans;
int find(int x) {
if (fa[x] == x) return x;
return fa[x] = find(fa[x]);
}
int main() {
scanf("%d%d%d", &n, &m, &q);
for (int i = 1; i <= n + m; i++) {
fa[i] = i;
}
for (int i = 1... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
map<int, int> m;
int n, temp, currentMax = 0, sum = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> temp;
m[temp]++;
}
for (std::map<int, int>::iterator it = m.begin(); it != m.end(); ++it) {
if (it->second > currentMax) {
curren... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
double arr[2][100009];
vector<pair<double, int> > x, y;
set<pair<double, int> > x1, y1;
cin >> n >> k;
for (int f = 0; f < n; f++) {
int a, b, c, d;
scanf("%d %d %d %d", &a, &b, &c, &d);
arr[0][f] = (a + c) / 2.0;
arr[1][f]... | 15 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x3f3f3f3f3f3f3f3f;
struct Package {
long long x, k;
int s;
} a[110];
inline bool operator<(const Package &a, const Package &b) { return a.k < b.k; }
int n, m;
long long b, f[1 << 20], ans = INF;
int main() {
cin >> n >> m >> b;
for (int i = 1,... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(nullptr);
long long n;
cin >> n;
vector<long long> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
vector<long long> b(n);
b[0] = a[0];
for (int i = 1; i < n; i++) b[i] = b[i - 1] ^ a[i];
if (b[n - 1] == ... | 15 |
#include <bits/stdc++.h>
using namespace std;
inline int rei() {
int x;
cin >> x;
return x;
}
inline long long rel() {
long long x;
cin >> x;
return x;
}
inline string res() {
string x;
cin >> x;
return x;
}
set<tuple<int, int, int, int>> st;
void Calc() {
int N = rei();
int Q = rei();
st.insert... | 14 |
#include <bits/stdc++.h>
using namespace std;
int res(int x) {
if (x > 0) return 1;
if (x == 0) return 0;
if (x < 0) return -1;
}
bool check(int a, int b) {
if (a == 0) return true;
if (res(a) != res(b)) return false;
return !(a % b);
}
bool che(int a, int b, int c, int d, int m, int n) {
return check(a -... | 9 |
#include <bits/stdc++.h>
using namespace std;
int nilai[1005], degin[1005], degout[1005], n, p, nxt[1005];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> p;
for (int i = 0; i < p; ++i) {
int a, b, c;
cin >> a >> b >> c;
degout[a]++;
degin[b]++;
nilai[a]... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1200000;
bool is_prime(int x) {
for (long long i = 2; i * i <= x; ++i)
if (x % i == 0) return 0;
return (x != 1);
}
bool is_pal(int x) {
string s = to_string(x);
string t = s;
reverse(t.begin(), t.end());
return s == t;
}
int main() {
ios::sy... | 8 |
#include <bits/stdc++.h>
int main() {
int i, j, n;
char str[100][102];
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%s", str[i]);
}
for (i = 0; i < n; i++) {
int flag = 0;
for (j = 0; j < i; j++) {
if (strcmp(str[i], str[j]) == 0) {
flag = 1;
break;
}
}
i... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100100;
int n, m, k, s, a[maxn], d[110][maxn];
vector<int> g[maxn];
vector<int> q;
void init() {
for (int type = 1; type <= k; type++) {
q.clear();
for (int i = 1; i <= n; i++) d[type][i] = -1;
for (int i = 1; i <= n; i++)
if (a[i] == ty... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 7001, INF = 1e9;
int n;
int used[MAXN], sz[MAXN];
long long c[MAXN];
vector<int> g[MAXN];
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
vector<long long> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
bool is_vowel(char c) {
c = tolower(c);
return c == 'a' || c == 'e' || c == 'o' || c == 'i' || c == 'u' || c == 'y';
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long a[300001], p[300001], dp[300001][3];
const long long INF = 1e18;
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
long long q;
cin >> q;
while (q--) {
long long n;
cin >> n;
for (long long i = 0; i < n; i++) {
cin >> a[i] >> p[i];
... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7;
long long powmod(long long a, long long b) {
long long res = 1;
a %= M;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1) res = res * a % M;
a = a * a % M;
}
return res % M;
}
const int N = 3e5 + 10;
vector<int> g[N], vert[N];
int co... | 14 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n, m;
vector<int> nums, pre1, pre2, revpre(1, 0);
vector<pair<int, int>> segs;
void Load() {
scanf("%d%d", &n, &m);
for (int i = 0; i < ((int)(n)); ++i) {
int l, r;
scanf("%d%d", &l, &r);
segs.push_back({l, r});
}
pre1.resize(m ... | 11 |
#include <bits/stdc++.h>
using namespace std;
void solve();
int main() {
int t = 1;
while (t--) solve();
}
void solve() {
long long n, m, x, y;
cin >> n >> x >> m >> y;
if (x > y) {
swap(n, m);
swap(x, y);
}
y -= x;
x = 0;
long long ans = 1 + m;
for (long long i = 1; i <= n; i++) {
if (i... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
double radius, corners;
cin >> corners >> radius;
double x = M_PI / corners;
double y = M_PI / (2.0 * corners);
double z = M_PI - x - y;
double length = (radius * sin(y)) / sin(z);
double area = 0.5 * length * radius... | 13 |
#include <bits/stdc++.h>
using namespace std;
long long int max(long long int a, long long int b) {
if (a >= b) {
return a;
} else {
return b;
}
}
int main() {
int t;
scanf("%d", &t);
while (t--) {
long long int w, h;
scanf("%lld %lld", &w, &h);
long long int h1, h2, v1, v2;
scanf("%... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
T gcd(T a, T b) {
T r;
while (b != 0) {
r = a % b;
a = b;
b = r;
}
return a;
}
template <class T>
T lcm(T a, T b) {
return a / gcd(a, b) * b;
}
template <class T>
int getbit(T s, int i) {
return (s >> i) & 1;
}
template <class T>
T... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, x, a, b, w, z, p, q, t, m;
cin >> m;
while (m--) {
cin >> n >> x >> a >> b;
p = max(a, b);
q = min(a, b);
w = n - p;
z = q - 1;
t = (x - (w + z));
if (t <= 0) {
p = p + x;
} else {
p = p + w + z... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int OO = 0x3f3f3f3f, N = 1e5 + 5, mod = 1e9 + 7;
int n, ck, l, c;
long long pos;
map<long long, int> ans;
vector<pair<long long, pair<int, int>>> v;
int solve(long long idx) {
if (ans[idx]) return ans[idx];
int st = 0, en = v.size() - 1;
while (st < en) {
in... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
int l = s.length();
if (l == 1) {
if (s[0] == '?')
cout << 'a' << endl;
else
cout << s << endl;
} else {
if (s[0] == '?') {
if... | 2 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
long long int n1, n2, k1, k2;
cin >> n1 >> n2 >> k1 >> k2;
if (n1 > n2)
cout << "First";
else
cout << "Second";
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 100 + 321;
long long a[maxN];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int d;
cin >> d;
a[d]++;
}
int ans = 0;
for (int i = 1; i <= 100; i++) ans += a[i] / 2;
cout << ans / 2 << endl;
return 0;
}
| 2 |
#include <bits/stdc++.h>
const int MaxN = 1e6 + 10;
namespace IO {
char buf[1 << 15], *fs, *ft;
inline char getc() {
return (ft == fs &&
(ft = (fs = buf) + fread(buf, 1, 1 << 15, stdin), ft == fs))
? 0
: *fs++;
}
template <typename T>
inline void read(T &x) {
x = 0;
T f = 1, ch... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int tc;
cin >> tc;
while (tc--) {
long long x, n;
cin >> x >> n;
long long cur = (n / 4) * 4;
while (cur != n) {
cur++;
if (x % 2 == 0)
x -= cur;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 2e14;
const long long MOD = 1e9 + 7;
const int N = 1e6 + 10;
vector<int> v[30];
vector<int> u[30];
int a[N];
int b[N];
long long inv(int l, int r) {
if (l == r) {
return 0;
}
int m = (l + r) / 2;
long long ans = inv(l, m) + inv(m + 1, r);
... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<unsigned long long> pref;
pref.push_back(0);
unsigned long long n, q, curr;
unsigned long long last = 0;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> curr;
last += curr;
pref.push_back(last);
}
cin >> q;
while (q--) {
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int fa[18][100005], dep[100005], n, q, t, ia[100005], ib[100005];
vector<int> ve[100005], vec[100005], aq;
void update() {
for (int i = 0; i <= 17; i++) {
for (int j = 1; j <= n; j++) {
if (fa[i][j] != -1) fa[i + 1][j] = fa[i][fa[i][j]];
}
}
}
void dfs(int... | 16 |
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 128000;
long long a[maxn];
long long n;
set<long long> q;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
long long sum = 0;
for (long long i = 0; i < n; ++i) {
cin >> a[i];
sum += a[i];
}
long long s1 = 0;
str... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e6 + 6;
char buf[MAX];
int app[26];
int n;
int main() {
scanf("%d", &n);
map<int, int> cnt;
long long ans = 0;
for (int i = int(0); i < int(n); i++) {
scanf("%s", buf);
int len = strlen(buf);
memset(app, 0, sizeof app);
for (int j = ... | 8 |
#include <bits/stdc++.h>
using namespace std;
const long long MX = 2e5;
int n;
long long a[200001] = {}, b[200001] = {}, sumA = 0, sumB = 0, op, op2 = 0;
string s = "";
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
sumA += a[i];
}
for (int i = 0; i < n; i++) {
cin >> b[i];
su... | 19 |
#include <bits/stdc++.h>
using namespace std;
int n, k, m;
vector<int> v[300100];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> k >> m;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
v[x % m].push_back(x);
}
for (int i = 0; i < m; i++) {
if (int(v[i].size()) >=... | 5 |
#include <bits/stdc++.h>
using namespace std;
using cd = complex<double>;
mt19937 rnd(chrono::system_clock::now().time_since_epoch().count());
long long num[2][2];
long long cal(long long sx, long long sy, long long nx, long long ny) {
if (sx == nx && sy == ny)
return 0;
else
return 2;
}
long long get(long ... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2E5 + 10;
const int INF = 1 << 29;
int n, x, y;
vector<int> E[MAXN];
int deg[MAXN];
int f[MAXN], g[MAXN];
void DFS(int u, int pre) {
int cnt = 0, w = -1;
for (int v, i = 0; i < E[u].size(); ++i)
if ((v = E[u][i]) != pre) {
DFS(v, u);
cnt... | 14 |
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
int a[101010];
int solve() {
int n, m;
cin >> n >> m;
for (int i = 0; i < n; ++i) cin >> a[i];
... | 23 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int sum = 0;
for (int i = 0; i < s.length(); i++) {
sum = (sum * 16) % 1000003;
if (s[i] == '>')
sum = (sum + 8) % 1000003;
else if (s[i] == '<')
sum = (sum + 9) % 1000003;
else if (s[i] == '+')
sum ... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n, e;
cin >> n >> e;
vector<pair<long long, long long>> v[n + 1];
for (long long i = 0; i < e; i++) {
long long x, y, z;
cin >> x >> y >> z;
v[x].push... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long l, r, k = 1;
cin >> l >> r;
while (k <= r) {
k *= 10;
}
long long th = k / 2, ch;
if (l >= th)
ch = l;
else if (r < th)
ch = r;
else
ch = th;
cout << ch * (k - 1 - ch) << endl;
return 0;
}
| 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, d;
cin >> n >> d;
int t;
cin >> t;
while (t--) {
int a, b;
cin >> a >> b;
int k1 = a + b;
int k2 = abs(a - b);
if (k1 <= (2 * n - d) && k1 >= d && k2 <= d)
cout << "YES" << endl;
else
cout << "NO" << endl;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
if (n <= 3)
printf("%d\n", n <= 2 ? -1 : 210);
else {
char a[7][3] = {"05", "08", "17", "02", "20", "11"};
int temp = (n - 4) % 6;
printf("1");
for (int i = 0; i < n - 4; i++) {
printf("0");
}
pr... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int A = 26;
const int N = 2010;
const int INF = 696969696;
char a[N], b[N];
int t, n, f[N][N];
vector<int> cntA[N], cntB[N];
int main() {
for (int i = 0; i < N; ++i) {
cntA[i].resize(A, 0), cntB[i].resize(A, 0);
}
cin >> t;
while (t--) {
scanf("%d %s %... | 18 |
#include <bits/stdc++.h>
using namespace std;
template <class X, class Y>
bool minimize(X &x, const Y &y) {
X eps = 1e-9;
if (x > y + eps) {
x = y;
return true;
} else
return false;
}
template <class X, class Y>
bool maximize(X &x, const Y &y) {
X eps = 1e-9;
if (x + eps < y) {
x = y;
retu... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a, b, c;
while (cin >> a >> b >> c) {
long long mn = min(a, min(b, c));
long long mx = max(a, max(b, c));
cout << mx - mn << endl;
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
struct Node {
long long val;
Node *next;
};
Node *Root = NULL;
void _addNodeEnd(long long n) {
if (Root == NULL) {
Root = new Node();
Root->next = NULL;
Root->val = n;
} else {
Node *curNode = Root;
while (curNode != NULL) curNode = curNode->next... | 10 |
#include <bits/stdc++.h>
using namespace std;
int arr[100009];
int sumLeft[100009], sumRight[100009];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
int n, l, r, Qr, Ql, total = 0, res = INT_MAX, currSum = 0;
cin >> n >> l >> r >> Ql >> Qr;
for (int i = 0; i < n; ++i) {
cin >> a... | 7 |
#include <bits/stdc++.h>
const int MOD = 1000000007;
const int MAX = 10000005;
using namespace std;
template <class T>
T max(T a, T b, T c) {
return max(a, max(b, c));
}
bool prime[1000001];
void SieveOfEratosthenes(int n) {
memset(prime, true, sizeof(prime));
for (int p = 2; p * p <= n; p++) {
if (prime[p] =... | 7 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC target("avx,avx2")
#pragma GCC optimize("unroll-loops")
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 2e5 + 100;
const int INF = 1e9;
vector<int> g[N], rg[N], g2[N];
pair<int, int> val[N], ans[N];
v... | 16 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
long long power(long long a, long long b) {
long long ret = 1;
while (b) {
if (b & 1) ret *= a;
a *= a;
if (ret >= MOD) ret %= MOD;
if (a >= MOD) a %= MOD;
b >>= 1;
}
return ret;
}
long long invmod(long long x) { re... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, i;
bool lk = true;
;
char a[100], b[100];
int main() {
scanf("%d", &n);
getchar();
for (i = 0; i < n; i++) a[i] = getchar();
for (i = 0; i < n; i++) b[i] = getchar();
sort(a, a + n);
sort(b, b + n);
for (i = 0; i < n; i++)
if (a[i] >= b[i]) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
#define ar array
#define int long long
#define all(x) (x).begin(), (x).end()
const int MAX_N = 1e5 + 1;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int LINF = 1e18;
void solve() {
int tc = 1;
cin >> tc;
for (int t = 1; t <= tc; t++) {
int l,n,m;
cin>>l>>n>>m;... | 3 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using minpq = priority_queue<T, vector<T>, greater<T>>;
const int N = 5e5 + 5;
struct node {
int LR, RL, preL, preR, preLR, preRL, sufL, sufR, sufLR, sufRL, len;
node() {
LR = RL = preL = preR = preLR = preRL = sufL = sufR = sufLR = sufRL = len... | 20 |
#include <bits/stdc++.h>
using namespace std;
int main() {
srand(time(NULL));
char s[] =
"100100000111111101010010010001010101110110110111010011111100100000000010"
"100011011000000100101100011111000101011000111100010111010001000101111111"
"10100";
for (int i = 0; i < 216; i++) {
if (i < 100)... | 10 |
#include <bits/stdc++.h>
using namespace std;
const long long int M = (1ll << 32) - 1;
const long long int N = 1e5 + 1;
long long int power(long long int x, long long int y, long long int M = ::M) {
long long int ans = 1;
while (y) {
if (y & 1) ans = (ans * x);
y >>= 1LL;
x = (x * x);
}
return ans;
... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int inv = 1000000000;
const int minv = -inv;
const int max_n = 100010;
const int max_m = 100010;
const int max_k = 110;
const int modref = 1000000007;
int n, m;
int a[max_n];
int b[max_n][max_k + 1] = {0};
int c[max_k + 1] = {0};
int bin[max_n + max_k + 1][max_k + 1];... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
vector<int> sizes;
int x;
while (cin >> x) {
sizes.push_back(x);
}
int min = sizes.back();
for (int i = 0; i < (n - k) * 2; i++) {
int size = sizes[i] + sizes[(n - k) * 2 - i - 1];
if (size > min) {
min... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int s[maxn], g[maxn], a[maxn], n;
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d%d", &s[i], &g[i]);
a[i] = s[i] + g[i];
}
for (int i = 1; i < n; i++) a[i + 1] = min(a[i + 1], a[i] + 1);
for (int i... | 10 |
#include <bits/stdc++.h>
using namespace std;
unsigned long long n, m, k, i, rem, row, col;
int main(void) {
cin >> n >> m >> k;
if (k == 0) return cout << 1 << " " << 1, 0;
if (k < n) return cout << k + 1 << " 1", 0;
if (k <= n + m - 2) return cout << n << " " << (k - n + 2), 0;
k -= (n);
row = k / (m - 1)... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x, y, z;
cin >> x >> y >> z;
int a = sqrt((x * y) / z);
int b = sqrt((x * z) / y);
int c = sqrt((y * z) / x);
cout << (a + b + c) * 4 << endl;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
template <class T1>
void deb(T1 e1) {
cout << e1 << endl;
}
template <class T1, class T2>
void deb(T1 e1, T2 e2) {
cout << e1 << " " << e2 << endl;
}
template <class T1, class T2, class T3>
void deb(T1 e1, T2 e2, T3 e3) {
cout << e1 << " " << e2 << " " << e3 << endl;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 5;
int noOfHashes = 3;
long long base = 10;
long long MOD[3] = {(long long)1e9 + 7, (long long)1e9 + 9, INT_MAX};
long long powers[3][MAXN];
long long Hashed[3][MAXN];
string s;
void init() {
for (int j = 0; j < noOfHashes; ++j) {
for (int i = 0... | 15 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
int main() {
stack<pair<int, int> > st;
char buf[1000000 + 10];
scanf("%s", buf);
string s = string(buf);
int m = 0;
int n = 1;
int sum = 0;
vector<int> start(2 * 1000000 + 10, -1);
vector<int> num(1000000 + 10, 0... | 11 |
#include <bits/stdc++.h>
using namespace std;
using namespace chrono;
void _print(long long t) { cerr << t; }
void _print(int t) { cerr << t; }
void _print(string t) { cerr << t; }
void _print(char t) { cerr << t; }
void _print(long double t) { cerr << t; }
void _print(double t) { cerr << t; }
void _print(unsigned long... | 10 |
#include <bits/stdc++.h>
using namespace std;
int a[1000007];
int b[1000007];
int main() {
int m, p;
scanf("%d %d", &m, &p);
int i, j;
long long int ans = 0;
for (i = 1; i <= m; i++) scanf("%d", a + i);
for (i = 1; i <= p; i++) {
j = i;
while (j <= m) {
b[a[j]]++;
j = j + p;
}
if... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T &x) {
int f = 1;
char k = getchar();
x = 0;
for (; k > '9' || k < '0'; k = getchar())
if (k == '-') f = -1;
for (; k >= '0' && k <= '9'; k = getchar()) x = x * 10 + k - '0';
x *= f;
}
template <class T>
inline void _prin... | 17 |
#include <bits/stdc++.h>
unsigned long long a, b;
int main() {
std::cin >> a >> b;
while (1) {
if (a == 0 || b == 0) break;
if (a >= 2 * b) {
a = a % (2 * b);
continue;
} else if (b >= 2 * a) {
b = b % (2 * a);
continue;
} else
break;
}
std::cout << a << ' ' << b <<... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 105;
int a[maxn], ted;
long long sum;
bool mark[maxn];
vector<int> v;
int main() {
ios_base::sync_with_stdio(false);
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= m; i++) {
int x;
cin >> x;
mar... | 6 |
#include <bits/stdc++.h>
using namespace std;
int mm[55][55], n, m;
char s[55][55];
const int d[4][2] = {1, 0, -1, 0, 0, 1, 0, -1};
bool inMap(int x, int y) { return x >= 0 && x < n && y >= 0 && y < m; }
void dfs(int x, int y, int dir, int chg, int state) {
mm[x][y] = state;
for (int i = 0; i < 4; ++i) {
int xx... | 9 |
#include <bits/stdc++.h>
using namespace std;
struct Edge {
int a, b, L, R;
} E[3010];
struct edge {
int v, L, R;
edge() {}
edge(int v, int L, int R) : v(v), L(L), R(R) {}
};
vector<edge> adj[1010];
int n, m, ans;
void read() {
scanf("%d %d", &n, &m);
for (int i = 1; i <= m; ++i) {
scanf("%d %d %d %d", ... | 12 |
#include <bits/stdc++.h>
using namespace std;
double PI = acos(-1);
int const N = 5e5 + 10, M = 1e7 + 1, oo = 1e9;
const int mod = oo + 7;
const long long OO = 3e18;
int n, aa[N];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i = 0; i < n; i++) cin >> aa[i];
sort(aa, aa + n);
int l = ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int a[555][555], b[555][555], n, m;
void change(int i, int j) {
if (!a[i][j])
a[i][j] = 1;
else
a[i][j] = 0;
}
int main() {
ios_base ::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) cin >> a[i... | 7 |
#include <bits/stdc++.h>
const int MAXN = 50 + 10;
int p, q;
int x[MAXN][2], z[MAXN][2];
int main() {
int l, r;
int ans = 0;
scanf("%d%d", &p, &q);
scanf("%d%d", &l, &r);
for (int i = 0; i < p; ++i) scanf("%d%d", &z[i][0], &z[i][1]);
for (int i = 0; i < q; ++i) scanf("%d%d", &x[i][0], &x[i][1]);
x[q][0] =... | 5 |
#include <bits/stdc++.h>
#pragma GCC optimize(3, "Ofast", "inline")
using namespace std;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
const long long maxn = (long long)3e5 + 5;
const long long mod = 998244353;
const long long inf = 0x3f3f3f3f;
long long T = 1;
long long a[maxn];
vector<... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int a, b, c;
cin >> a >> b >> c;
int e1 = sqrt(a * c / b);
int e2 = sqrt(a * b / c);
int e3 = sqrt(b * c / a);
cout << 4 * (e1 + e2 + e3) << endl;
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000010;
int Next[maxn], Len, x, y;
char a[maxn];
void KMP() {
Next[1] = 0;
for (int i = 2, k = 0; i <= Len; i++) {
while (k && a[i] != a[k + 1]) k = Next[k];
if (a[i] == a[k + 1]) k++;
Next[i] = k;
}
for (int i = 2, k = 0; i <= Len; i++... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
long long n, k;
cin >> n >> k;
long long a[n], flag = 0;
string str;
cin >> str;
for (long long i = 0; i < str.length(); i++) a[i] = str[i] - '0';
string s = {};
for (long long i = 0; i... | 9 |
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
const signed INF_ = 1001001001;
const long long INF = 1001001001001001001LL;
const int DX[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0},
DY[9] = {-1, 0, 1, 0, -1, 1, 1, -1, 0};
template <class T>
os... | 18 |
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:33554432")
int N, M, R[5004], B[5004], cnt[5004], ans;
bool A[5004][5004];
char buf[5004];
int main() {
int i, j;
scanf("%d%d", &N, &M);
for (i = 1; i <= N; i++) {
scanf("%s", buf + 1);
for (j = 1; j <= M; j++) A[i][j] = buf[j] ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string s;
cin >> n >> s;
int a[26] = {0};
for (int i = 0; i < n; i++) {
a[s[i] - 'a']++;
}
sort(a, a + 26, greater<int>());
if (n == 1 || a[0] >= 2)
cout << "YES"
<< "\n";
else
cout << "NO"
<< "\n";
retur... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char s[5] = {'a', 'b', 'c', 'd'};
int n, i = 0;
cin >> n;
while (n > 0) {
cout << s[i];
n--;
i++;
if (i == 4) {
i = 0;
}
}
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (a == 0) return b;
return gcd(b % a, a);
}
long long powm(long long base, long long exp, long long mod = 998244353) {
base %= mod;
long long ans = 1;
while (exp) {
if (exp & 1LL) ans = (ans * base) % mod;
exp >>... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
const int maxint = 0x3f3f3f3f;
const int mod = 1e9 + 7;
int n, m, a[110], mi, ans;
int jisuan(int x, int y) {
int i, ret = 0;
for (i = 1; i <= n; i++) {
if (a[i] < x || a[i] > y) ret++;
}
return ret;
}
int main() {
int i;
cin >> n ... | 4 |
#include <bits/stdc++.h>
const int MAX = 1e6 + 10;
const int MOD = 1e9 + 7;
using namespace std;
vector<long long> v, vv;
int vis[MAX];
int main() {
ios::sync_with_stdio(false), cout.tie(NULL);
v.push_back(1);
vv.push_back(1);
for (int i = 2; i <= 1000000; i++) {
if (vis[i]) continue;
vv.push_back(i);
... | 13 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.