solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
const bool DEBUG = false;
using namespace std;
const long long maxn = 2e5 + 5;
const long long INF = 1e18 + 1;
const long long M = 1e9 + 7;
const int lg = 21;
long long n, b[maxn];
vector<long long> g[60];
vector<long long> v;
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
c... | 14 |
#include <bits/stdc++.h>
using namespace std;
int a[400007];
int main() {
int n;
scanf("%d", &n);
int sum = 0;
for (auto i = (1); i <= (n); ++i) {
scanf("%d", &a[i]);
sum += a[i];
}
int cnt = 0;
for (auto i = (1); i <= (n); ++i)
if (a[i] == sum / n && sum % n == 0) ++cnt;
printf("%d\n", cnt)... | 4 |
#include <bits/stdc++.h>
using namespace std;
using namespace std;
long long gcdx(long long a, long long b) { return b ? gcdx(b, a % b) : a; }
long long gcd(long long a, long long b) { return gcdx(abs(a), abs(b)); }
void setbit(int &m, int ind, int val) {
if (val)
m = (m | (1 << ind));
else
m = (m & ~(1 << ... | 9 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int d;
int max_a, min_b, max_ab, max_bc, max_abc;
void init_leaf(int v) {
d = v;
max_a = v;
min_b = v;
max_ab = max_abc = max_bc = -1123456;
}
void update(const node& l, const node& r) {
d = l.d + r.d;
max_a = max(l.max_a, l.d... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
string a[4];
for (int i = 0; i < 4; i++) {
cin >> a[i];
}
int res[2];
int mn = 9999;
int mx = 0;
for (int i = 0; i < 4; i++) {
if (mn > a[i].size() - 2) {
res[0] = i;
mn = min(mn, int(a[i].size()... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, x, y, mn = 1e16, mx = 0, ans = 0, t;
int main() {
cin >> n;
long long lo = 1, hi = 1000;
while (lo <= hi) {
long long md = (lo + hi) >> 1;
if (md * (md + 1) / 2. <= n) {
ans = max(ans, md);
lo = md + 1;
} else
hi = md - 1;... | 8 |
#include <bits/stdc++.h>
long long h, w;
long long ansh, answ;
void judge(long long x, long long y) {
if (x * y < ansh * answ) {
return;
}
if (x * y > ansh * answ) {
ansh = x;
answ = y;
return;
}
if (x * y == ansh * answ && x > ansh) {
ansh = x;
answ = y;
}
}
int main() {
while (sc... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1010;
const long long INF = 1000LL * 1000 * 1000 * 1000 * 1000 + 10;
int n, m, k, p;
int a[MAXN][MAXN];
long long r[MAXN], c[MAXN], sr[MAXN * MAXN], sc[MAXN * MAXN];
int main() {
ios_base::sync_with_stdio(false);
cin >> m >> n >> k >> p;
for (int i = ... | 12 |
#include <bits/stdc++.h>
using namespace std;
template <typename X>
ostream& operator<<(ostream& x, const vector<X>& v) {
for (long long i = 0; i < v.size(); ++i) x << v[i] << " ";
return x;
}
template <typename X>
ostream& operator<<(ostream& x, const set<X>& v) {
for (auto it : v) x << it << " ";
return x;
}
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, b;
scanf("%d", &n);
scanf("%d", &a);
scanf("%d", &b);
if (b == 0) {
printf("%d\n", a);
return 0;
} else if (b < 0) {
for (int i = 1; i <= abs(b); i++) {
a--;
if (a == 0) a = n;
}
} else if (b > 0) {
for (i... | 2 |
#include <bits/stdc++.h>
using namespace std;
int Solve() {
int n;
cin >> n;
for (int i = -1; ++i < n;) {
int x, y;
cin >> x >> y;
if (x > y) {
swap(x, y);
}
long long l = 0, r = (long long)1e9;
for (int j = -1; ++j < 200;) {
long long mid = (l + r) / 2;
if ((mid * (mid +... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t;
cin >> t;
while (t--) {
long long int n;
cin >> n;
long long int a, b;
long long int c = 0, d = 0;
long long int f = 0;
for (long long int i = 0; i < n; i++) {
cin >> a >> b;
if (a < c || b < d || a - c... | 4 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
using namespace std;
const int N = 3e5 + 5, M = 2 * N + 5;
int head[N], nxt[M], to[M], ne, n;
void init() {
ne = 0;
memset(head, -1, n * sizeof head[0]);
}
void addEdge(int f, ... | 10 |
#include <bits/stdc++.h>
using namespace std;
bool sortcol(const vector<long long int>& v1, const vector<long long int>& v2) {
return (v1[0] < v2[0]);
}
int main() {
long long int n;
cin >> n;
vector<vector<long long int>> v(n);
for (long long int i = 0; i < n; i++) {
long long int x, y;
cin >> x >> y... | 7 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
const long long mod = 1e9 + 7;
const long long MOD = 998244353;
const double EPS = 1e-8;
const double PI = acos(-1.0);
void _print(long long t) { cerr << t; }
void _print(int t) { cerr << t; }
void _print(string t) { cerr << t; }
void _print(char... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6;
struct tree {
int mx, turnLeft, turnRight;
};
string a;
int n, m;
tree t[4 * N], e;
tree combine(tree t1, tree t2) {
tree res;
int add = min(t1.turnRight, t2.turnLeft);
res.mx = t1.mx + t2.mx + add;
res.turnRight = t1.turnRight + t2.turnRight - ... | 12 |
#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1000000007;
const long long BIG = 1446803456761533460;
const int Big = 336860180;
stringstream sss;
const long long int B = 16;
long long int K, t;
long long int have[B];
long long int dp[B];
long long int ent[B][B];
string hexchr = "0123456789abcd... | 17 |
#include <bits/stdc++.h>
using namespace std;
vector<long long> v;
long long n, a, tmp;
long long m[3][109], d[109][109];
long long dx[] = {0, 1}, dy[] = {1, 0};
void solve(long long x, long long y, long long tmp1) {
for (long long i = (0); i < (2); i++) {
long long tmpx = x + dx[i], tmpy = y + dy[i];
if (tmp... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
double s;
cin >> s;
double a, b, c;
cin >> a >> b >> c;
if (a == 0 && b == 0 && c == 0) {
printf("0 0 %.08lf", s);
} else {
printf("%.15lf %.15lf %.15lf", s / (a + b + c) * a, s / (a + b + c) * b,
s / (a + b + c) * c);
}
retur... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m;
cin >> n >> m;
string s1;
cin >> s1;
string s2;
cin >> s2;
string res = "";
res += s1[0];
res += s2[0];
res += s1[n - 1];
res += s2[m - 1];
if (res == "<v>^" || res == ">^<v"... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
const long long mod = 1e9 + 7;
int n, k, m;
map<int, int> id;
int num[maxn];
int unlucky;
long long quick_pow(long long a, long long p, long long n) {
long long ret = 1;
while (p) {
if (p % 2 == 1) ret = ret * a % n;
a = a * a % n;
... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100100;
int n, k;
struct line {
int a, b, c;
};
long long gcd(long long a, long long b) {
while (b) {
a %= b;
swap(a, b);
}
return a;
}
struct fraq {
long long a, b;
bool operator<(const fraq oth) const {
if (a * oth.b < b * oth.a) r... | 21 |
#include <bits/stdc++.h>
using namespace std;
pair<int, int> transform(const pair<int, int>& org, int dir) {
switch (dir) {
case (0):
return org;
case (1):
return make_pair(org.second, -org.first);
case (2):
return make_pair(-org.first, -org.second);
case (3):
return make_pair(... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
string a;
int p = -1, s = -1, num = 0, l, i;
cin >> a;
l = a.size();
for (i = 0; i < l; i++) {
if (a[i] == '1') {
p = i;
break;
}
}
for (i = l - 1; i >= 0; i--) {
... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
int main() {
long long n, k;
long long a, b;
while (cin >> n >> k >> a >> b) {
long long maxx = 0, minn = 1e12;
... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 100 + 10;
bool a[MAX][MAX];
bool mark[MAX];
int n, m;
void dfs(int u) {
mark[u] = 1;
for (int i = 0; i < n; i++)
if (!mark[i] && a[u][i]) {
mark[i] = 1;
dfs(i);
}
}
int main() {
cin >> n >> m;
for (int i = 0; i < m; i++) {
int... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
vector<int> v(n + 1);
for (long long int i = 1; i <= n; ++i) cin >> v[i];
int l = 2, r = n - 1;
int ans = 0;
while (l < r) {
if (v[l + 1] == 1 && v[l] == 0 && v[l - 1] == 1)... | 2 |
#include <bits/stdc++.h>
long long read() {
char last = '+', ch = getchar();
while (ch < '0' || ch > '9') last = ch, ch = getchar();
long long tmp = 0;
while (ch >= '0' && ch <= '9') tmp = tmp * 10 + ch - 48, ch = getchar();
if (last == '-') tmp = -tmp;
return tmp;
}
int n, m;
long long t, M;
long long x[20... | 22 |
#include <bits/stdc++.h>
const int MAXN = 100010;
int numbers[MAXN];
int main() {
int t;
int n, m, k, x;
scanf(" %d", &t);
while (t--) {
scanf(" %d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &numbers[i]);
}
int low = 1;
int high = n;
while (numbers[low + 1] <= numbers[low] &... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long toNumber(string str) {
long long num;
stringstream ss(str);
ss >> num;
return num;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL), cout.tie(NULL);
int ans[][6] = {{4, 5, 6, 3, 2, 1},
{11, 12, 13, 10, 9, 8},
... | 4 |
#include <bits/stdc++.h>
using namespace std;
class DebugStream {
} LOG;
template <typename T>
DebugStream &operator<<(DebugStream &s, const T &) {
return s;
}
const int maxN = 1e5 + 9, maxV = 300, MOD = 998244353, SQ = 335, lg = 20;
int getsz() {
string st;
getline(cin, st);
return st[0] - '0';
}
int main() {
... | 16 |
#include <bits/stdc++.h>
using namespace std;
int g[100005];
int main() {
int n, a, b;
double x;
cin >> n >> x;
double cnt = 0;
for (int i = 1; i < n; i++) {
scanf("%d%d", &a, &b);
g[a]++;
g[b]++;
}
for (int i = 1; i <= n; i++) {
if (g[i] == 1) cnt++;
}
double ans = (x / cnt) * 2.0;
... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string temp;
cin >> temp;
vector<int> num(n);
map<int, int> prefix;
for (int i = 0; i < n; ++i) {
if (temp[i] == '0') {
num[i] = -1;
} else {
num[i] = 1;
}
}
prefix[0] = 1;
int ans = 0, curr = 0;
fo... | 7 |
#include <bits/stdc++.h>
using namespace std;
struct trans {
int first, second, d, t, e;
};
int n, m, k;
long long dp[505][505];
trans w[500007];
vector<int> kek[505][505];
bool in(int first, int second, int x1, int y1, int x2, int y2) {
return first >= x1 && first <= x2 && second >= y1 && second <= y2;
}
vector<pa... | 18 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
bool tg[300005];
struct num {
int val, l, r;
} h[25];
struct node {
num x, y, z, s;
} p[300005][2];
int read() {
int x = 0;
char cr = getchar();
bool flag = 0;
while (cr < '0' || cr > '9') {
if (cr == '-') flag = 1;
cr = getchar();
}
while ... | 20 |
#include <bits/stdc++.h>
char s1[1111111];
char s2[1111111];
void reverse(char* str, int l, int r) {
while (l < r) {
char t = str[l];
str[l] = str[r], str[r] = t, l++, r--;
}
}
long long ans = 0;
const long long mod = 998244353;
void exec() {
int n, m;
scanf("%d%d", &n, &m);
scanf("%s%s", s1 + 1, s2 +... | 9 |
#include <bits/stdc++.h>
using namespace std;
int a[2000] = {0}, b[2000] = {0}, j;
void check(int maxn) {
bool done = false;
for (j = 1; j <= 1024; j++) {
memset(b, 0, sizeof(b));
for (int i = 0; i <= maxn; i++) {
if (a[i] > 0) b[i ^ j]++;
}
done = true;
for (int i = 0; i <= maxn; i++) {
... | 4 |
#include <bits/stdc++.h>
int d[30][30];
int main() {
int n, i, j, ans, s, t, r;
char x[20];
scanf("%d", &n);
memset(d, 0, sizeof(d));
ans = 0;
for (i = 0; i < n; i++) {
scanf("%s", x);
r = strlen(x);
s = x[0] - 'a';
t = x[r - 1] - 'a';
for (j = 0; j < 26; j++) {
if (j == s) {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
char s[200005];
int n, k;
int calc(char c) {
int num = 0, ans = 0;
for (int i = 1; i <= n + 1; i++) {
if (s[i] == c)
num++;
else {
ans += num / k;
num = 0;
}
}
return ans;
}
int main() {
scanf("%d%d", &n, &k);
scanf("%s", s + 1);
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
char a[55][3];
int deg[55];
vector<int> g[55];
int cl[55], slt;
void dfs(int u) {
cl[u] = slt;
for (int i = 0; i < deg[u]; ++i) {
int v = g[u][i];
if (cl[v] == 0) dfs(v);
}
}
void tao() {
a[1][1] = 0;
a[1][2] = 0;
for (int i = 2; i <= 50; ++i) ... | 7 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
int mod = 1e9 + 7;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long powmod(long long a, long long b) {
long long res = 1;
if (a >= mod) a %= mod;
for (; b; b >>= 1) {
if (b & 1) res = res * a;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_INT = (1ll << 31) - 1;
const int INF = 2e9 + 10;
const long long inf = 9e18 + 10;
const int MO = 1e9 + 7;
const double eps = 1e-8;
int main() {
int t;
cin >> t;
while (t--) {
long long n, k;
scanf("%lld%lld", &n, &k);
long long l1, r1, l2, r2... | 13 |
#include <bits/stdc++.h>
using namespace std;
double h, r;
double pi = 3.141592653589793;
bool isGreaterThan(double a, double b) { return a - b > 0.000001; }
bool isZero(double d) { return d < 0.000001 && d > -0.000001; }
pair<double, double> findCoordinatesOnPlane(double x, double y, double z) {
double angleOnCircle... | 22 |
#include <bits/stdc++.h>
using namespace std;
long long n, k, ans = 0;
char a[100005];
signed main() {
scanf("%lld%lld%s", &n, &k, a + 1);
ans = n * (k - 1);
for (long long i = 1; i < n; i++)
if (a[i] != a[i + 1]) ans += n * (k - 1);
long long len = 1;
for (long long i = 2; i <= n; i++)
if (len < 2)
... | 19 |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
long long sum = 0, ff = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') ff = -1;
ch = getchar();
}
while (isdigit(ch)) sum = sum * 10 + (ch ^ 48), ch = getchar();
return sum * ff;
}
const long long N = 2005;
const ... | 24 |
#include "bits/stdc++.h"
using namespace std;
const int nax = 4e5 + 5;
queue<int> cue;
vector<int> edge[nax];
vector<int> is(nax), vis(nax), in(nax);
void find_cycle (int cur) {
vis[cur] = 1;
if (is[cur] == 2) return ;
if (is[cur] == 1) {
cue.push(cur);
in[cur] = 1;
return ;
}
is[cur] = 1;
for (... | 13 |
#include <bits/stdc++.h>
using namespace std;
bool shit(vector<pair<int, int> > vec) {
double s1, s2, s3;
s1 = (vec[0].first != vec[1].first) ? (vec[0].second - vec[1].second * 1.0) /
(vec[0].first - vec[1].first)
: 3000;
s2 = (vec[... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int kMaxN = 200001;
struct V {
bool b;
vector<int> e;
} v[kMaxN];
int n, m, x, y, s, b, ans;
void S(int f, int x) {
if (v[x].b) {
b &= x == s || f == s;
return;
}
v[x].b = 1;
b &= v[x].e.size() == 2;
for (int i = 0; i < v[x].e.size(); i++) {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n, k, m = 0;
int a[25];
int main() {
scanf("%d%d", &n, &k);
for (int i = 2; i <= n; i++) {
while (n % i == 0) {
n /= i;
m++;
a[m] = i;
}
}
if (m < k)
cout << "-1";
else {
for (int i = 1; i < k; i++) cout << a[i] << " ";
in... | 3 |
#include <bits/stdc++.h>
using namespace std;
char s[1010];
int cnt[130] = {0}, cnt2[130] = {0}, ans[130] = {0};
double xxx[130];
int main() {
int n;
scanf("%s%d", s, &n);
int len = strlen(s);
for (int i = 0; i < len; ++i) ++cnt[s[i]];
int m = 0, n0 = n;
for (int i = 'a'; i <= 'z'; ++i)
if (cnt[i]) cnt2... | 6 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
void mytimer(string task) {}
void ext(int c) {}
char src[2100][2100];
char ar1[2100][2100];
char ar2[2100][2100];
int n;
const int A = 5;
vector<pair<int, int> > fig;
void dfs(int a, int b) {
fig.push_back(make_pair(a, b));
ar... | 12 |
#include <bits/stdc++.h>
using namespace std;
int n, cnt, total;
int a[4010];
void solve() {
int i, ans;
ans = 1e9;
for (i = 0; i <= cnt; i++)
if (i <= n && cnt - i <= n) ans = min(ans, abs(total - i * 1000));
printf("%.3lf\n", double(ans) / 1000.0);
}
void input() {
int i;
double x;
scanf("%d", &n);
... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, l, r, k = 1000000, p = 0;
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> l >> r;
k = min(k, r - l + 1);
}
cout << k << endl;
for (int i = 0; i < n; i++) {
cout << p << ' ';
p++;
p %= k;
}
return 0;
}
| 9 |
#include <bits/stdc++.h>
int main() {
long long int i, k, n, w;
scanf("%lld %lld %lld", &k, &n, &w);
if (((k * w * (w + 1)) / 2) < n) {
printf("0");
} else {
i = (k * w * (w + 1)) / 2 - n;
printf("%lld", i);
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, x, n, s = 0;
cin >> a >> b >> c;
cin >> x;
while (x--) {
cin >> n;
if (n > b && n < c) s++;
}
cout << s << endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e9 + 7;
long long power(long long x, long long y) {
long long res = 1;
while (y > 0) {
if (y & 1) res = ((res) * (x));
res %= N;
y = y >> 1;
x = ((x) * (x));
}
return res;
}
long long powmod(long long a, long long b, long long n)... | 1 |
#include <bits/stdc++.h>
using namespace std;
int a[1100], b[1100];
int main() {
int i, j, n, k, cnt;
scanf("%d %d", &n, &k);
for (i = 1; i <= n; i++) scanf("%d", &b[i]);
for (i = 1; i <= n; i++) {
cnt = 1;
while (b[cnt]) cnt++;
a[i] = cnt;
b[cnt]--;
for (j = 1; j <= cnt - k; j++) b[j]--;
... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d;
cin >> a >> b >> c >> d;
double mm = max(0.3 * a, a - a * c * (0.004));
double vv = max(0.3 * b, b - b * d * (0.004));
int m = mm;
int v = vv;
if (m > v)
cout << "Misha" << endl;
else if (m < v)
cout << "Vasya" << endl;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long a, b, i, j, k, l;
void op() {
if (a == 0 || b == 0) return;
if (a >= 2 * b) {
a = a % (2 * b);
op();
} else if (b >= 2 * a) {
b = b % (2 * a);
op();
}
return;
}
int main() {
cin >> a >> b;
op();
cout << a << " " << b << "\n";
retu... | 3 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
using pld = pair<ld, ld>;
int gcd(int a, int b) {
while (b) {
const int aux = b;
b = a % b;
a ... | 8 |
#include <bits/stdc++.h>
template <class p, class q>
void umin(p& a, const q& b) {
if (a > b) a = b;
}
template <class p, class q>
void umax(p& a, const q& b) {
if (a < b) a = b;
}
using ll = long long;
using VI = std::vector<int>;
using VLL = std::vector<ll>;
using namespace std;
using namespace std::chrono;
int n... | 21 |
#include <bits/stdc++.h>
using namespace std;
pair<int, int> s[200100];
int p[200100];
int a[200100];
int b[200100];
map<int, int> cant;
map<int, vector<int> > who;
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < (n); i++) scanf("%d", &p[i]);
for (int i = 0; i < (m); i++) {
scanf("%d", &s[i].first... | 13 |
#include <bits/stdc++.h>
using namespace std;
long long dis[2020];
int a[2020][2020];
int vis[2020];
int main() {
int n, i, pl, j, mnn = 1000000000;
long long mn;
scanf("%d", &n);
for (i = 1; i < n; i++)
for (j = i + 1; j <= n; j++) {
scanf("%d", &a[i][j]);
a[j][i] = a[i][j];
mnn = min(a[i... | 19 |
#include <bits/stdc++.h>
using namespace std;
const long long LINF = 1e18 + 7;
const int N = 2e3 + 7;
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = 1e-9;
int n, m, x, ind, a[4];
string lesha[4], desc[20];
bool check(int k) {
int p = 0;
for (int i = (0); i < (n); ... | 9 |
#include <bits/stdc++.h>
using namespace std;
string to_string(char s) { return string(1, s); }
string to_string(string s) { return "\"" + s + "\""; }
template <typename T>
string to_string(vector<T>);
template <typename U, typename V>
string to_string(pair<U, V> p) {
return "(" + to_string(p.first) + ", " + to_strin... | 0 |
#include <bits/stdc++.h>
using namespace std;
mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());
int rng(int l, int r) { return uniform_int_distribution<int>(l, r)(gen); }
struct Treap;
using twoTreaps = array<Treap *, 2>;
struct Treap {
int id;
int val;
int res;
int lazyres;
int lazyval;
... | 20 |
#include <bits/stdc++.h>
int a[2000005], len;
char s[2000005], ans[2000005];
char f(int id) {
if (id == 1) return 'a';
if (id == 2) return 'b';
if (id == 4) return 'c';
return '\0';
}
int solve() {
int i, j, k = 0;
if (len <= 3) {
ans[k++] = f(a[0]);
ans[k] = '\0';
return 1;
}
for (i = 0, j ... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5, INF = 0x3f3f3f3f;
struct Node {
int mi, ma;
int max;
} tr[N * 4];
int a[N], b[N];
bool st[N];
int op[N], q[N];
void pushup(int u) {
tr[u].ma = max(tr[u << 1].ma, tr[u << 1 | 1].ma);
if (tr[u << 1].mi == 0 || tr[u << 1 | 1].mi == 0)
tr[u].m... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
const long long INF = 1e18;
template <typename T>
void chkmax(T &x, T y) {
x = max(x, y);
}
template <typename T>
void chkmin(T &x, T y) {
x = min(x, y);
}
template <typename T>
void read(T &x) {
x = 0;
int f = 1;
char c = getchar();
fo... | 24 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int i, j, n, t, x, k, m, y, z;
vector<long long int> v;
cin >> n >> k;
long long int a[n], b[n];
for (i = 0; i < n; i++) {
cin >> a[i];
}
cin >> x;
for (i = 0; i < n; i++) {
cin >> b[i];
}
long long int min = 1e10;
multis... | 7 |
#include <bits/stdc++.h>
int main() {
int a, b, c, d;
scanf("%d%d%d%d", &a, &b, &c, &d);
for (int i = a; i <= 2 * a; ++i)
for (int j = b; j <= 2 * b && j < i; ++j)
for (int k = c; k <= 2 * c && k < j; ++k)
if (d <= i && d <= j && d <= k && d * 2 >= k && d * 2 < j &&
d * 2 < i) {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int q, n;
cin >> q;
for (int i = 0; i < q; i++) {
cin >> n;
int arr[n], arr2[n];
for (int j = 0; j < n; j++) {
cin >> arr[j];
}
for (int j = 0; j < n; j++) {
int k = j, cnt = 0;
while (cnt < n) {
if (j + 1 == ... | 2 |
#include <bits/stdc++.h>
using namespace std;
string s;
vector<string> t;
int dx[4] = {0, 1, 1, 1};
int dy[4] = {1, 0, 1, -1};
int main() {
ios_base::sync_with_stdio(false);
t.assign(50, string(50, 'O'));
for (int i = 0; i < 10; ++i) {
cin >> s;
for (int j = 0; j < 10; ++j) t[i + 20][j + 20] = s[j];
}
... | 8 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
string toString(T n) {
ostringstream ost;
ost << n;
ost.flush();
return ost.str();
}
int toInt(string s) {
int r = 0;
istringstream sin(s);
sin >> r;
return r;
}
long long toLInt(string s) {
long long r = 0;
istringstream sin(s);
sin... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d\n", &n);
char cc[] = {'A', 'C', 'G', 'T'};
vector<char> code(n);
vector<int> count(4);
for (int i = 0; i < n; ++i) {
scanf("%c", &code[i]);
if (code[i] == 'A')
++count[0];
else if (code[i] == 'C')
++count[1];... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long long sze = 5e5 + 50, INF = 1e18, mod = 1000000007;
const long double eps = 1e-9, PI = 2 * acos(0.0);
template <class T>
void show(const vector<T> &a) {
for (T x : a) cout << x << " ";
cout << '\n';
}
vector<long long> vertices[sze];
vector<char> visit(sze, fa... | 13 |
#include <bits/stdc++.h>
using namespace std;
inline void read(int &x) {
char ch = getchar();
x = 0;
bool flag = 0;
while (ch > '9' || ch < '0') {
if (ch == '-') flag = 1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = (x << 3) + (x << 1) + ch - 48;
ch = getchar();
}
if (flag) x ... | 22 |
#include <bits/stdc++.h>
using namespace std;
vector<long long int> A;
int main() {
long long int a, b, c, t, i, j, k;
cin >> t;
while (t--) {
cin >> a >> b;
long long int f = 0, f1 = 0;
if (a % b != 0)
cout << a << endl;
else {
for (i = 1; i <= sqrt(b); i++) {
if (b % i == 0) ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int L[200001 << 2][2];
int R[200001 << 2][2];
int Max[200001 << 2][2];
bool Pure[200001 << 2][2];
int M[2];
void PushUp(int rt, int k) {
Pure[rt][k] = Pure[rt << 1][k] && Pure[rt << 1 | 1][k];
Max[rt][k] = max(R[rt << 1][k] + L[rt << 1 | 1][k],
max(Ma... | 7 |
#include <bits/stdc++.h>
using namespace std;
int gi() {
int x = 0, w = 1;
char ch = getchar();
while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
if (ch == '-') w = 0, ch = getchar();
while (ch >= '0' && ch <= '9')
x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
return w ? x : -x;
}
const ... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 20;
int n, ar[maxn], cnt = 1, trie[maxn][27], nxt[maxn][27], ok[maxn], f[maxn],
sum[maxn];
long long ans, am[maxn], a[maxn];
vector<int> order, vec[maxn], comp;
int add(string &s) {
int i = 0;
for (char c : s) {
if (trie[i][c ... | 16 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:134217728")
using namespace std;
const long long MOD = 998244353;
const long long MAXN = 100000 + 100;
bool check(const vector<int>& v) {
set<int> q;
int n = v.size() / 2;
int s = 0;
for (int i = 0; i < n; ++i) {
s += v[i];
}
q.insert(s);
int cu... | 4 |
#include <bits/stdc++.h>
using namespace std;
struct point {
long long position, cost;
} points[5000];
long long dp[5000][5000];
bool compare(point n1, point n2) { return n1.position < n2.position; }
int main() {
int n, l;
while (cin >> n) {
memset(dp, 0, sizeof(dp));
for (int i = 0; i < n; i++) {
c... | 10 |
#include <bits/stdc++.h>
int main() {
int Q;
std::cin >> Q;
while (Q--) {
int n, x;
std::cin >> n >> x;
int a[5 + n];
for (int i = 1; i <= n; i++) std::cin >> a[i];
std::sort(a + 1, a + n + 1);
long long sum = 0;
int ans = 0;
for (int i = n; i > 0; i--) {
sum += a[i];
i... | 3 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > more;
int modexp(long long int a, long long int b) {
long long int ret = 1;
a %= 1000000007;
while (b) {
if ((b & 1)) {
ret *= a;
ret %= 1000000007;
}
a *= a;
a %= 1000000007;
b >>= 1;
}
return ret;
}
int mai... | 14 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-10;
const int inf = 1 << 30;
const int INF = 0x3f3f3f3f;
long long h, w;
long long ah, aw;
long long high, wide;
int main() {
cin >> high >> wide;
int flag = 1;
for (int i = 0; 1 << i <= wide; ++i) {
w = 1 << i;
h = 1.25 * w;
if (h <=... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, q, i, l, r, min = 200001, max = 0;
vector<int> rcp(200010);
cin >> n >> k >> q;
while (n--) {
cin >> l >> r;
rcp[l]++;
rcp[r + 1]--;
if (l < min) min = l;
if (r > max) max = r;
}
for (i = min; i <= rcp.size(); i++) {
... | 6 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
bool uax(T& a, const T& b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T>
bool uin(T& a, const T& b) {
if (a > b) {
a = b;
return true;
}
return false;
}
const int N = 2000;
bitset<N> ans[N];
bitset<N> ... | 19 |
#include <bits/stdc++.h>
using namespace std;
int a[50001], n;
pair<int, int> b[50001];
int main() {
cin >> n;
for (int i = 0; i < n; ++i) cin >> a[i];
a[n] = a[0];
for (int i = 0; i < n; ++i) b[i] = make_pair(a[i] + a[i + 1], i);
sort(b, b + n);
for (int i = 0; i < n; ++i) a[b[i].second] = i;
for (int i ... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int T;
int N;
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> T;
while (T--) {
cin >> N;
cout << 1 << ' ' << N - 1 << " 1";
for (int i = 2; i < N + 1; i++) cout << ' ' << i;
cout << '\n' << flush;
int mayor;
cin >> mayor;
... | 9 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > tree;
vector<int> a, dp1, dp2;
void dfs1(int node, int parent = -1) {
dp1[node] = a[node];
for (auto child : tree[node]) {
if (child != parent) {
dfs1(child, node);
dp1[node] += max(dp1[child], 0);
}
}
}
void dfs2(int node, int... | 10 |
#include <bits/stdc++.h>
using namespace std;
unsigned long long a[200002], maxs, j, p[200002], s[200002];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
unsigned long long n, k, x, m = 1;
cin >> n >> k >> x;
while (k--) {
m *= x;
}
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i =... | 9 |
#include <bits/stdc++.h>
using i64 = long long;
constexpr int P = 1000000007;
int norm(int x) {
if (x < 0) {
x += P;
}
if (x >= P) {
x -= P;
}
return x;
}
template <class T>
T power(T a, int b) {
T res = 1;
for (; b; b /= 2, a *= a) {
if (b % 2) {
res *= a;
}
}
return res;
}
stru... | 14 |
#include <bits/stdc++.h>
int main() {
int a[5], i, j, n, d[5], s;
while (~scanf("%d %d %d %d", &a[0], &a[1], &a[2], &a[3])) {
for (i = 0; i < 3; i++) d[i] = a[i + 1] - a[i];
if ((d[0] == d[1]) && (d[1] == d[2]))
printf("%d\n", (a[3] + d[0]));
else if (!((a[0] && a[1]) && (a[2] && a[3])))
pri... | 10 |
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fo(p,n) for(int i=p;i<n;i++)
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mp make_pair
#define pb push_back
#define M 1000000007
int mod(int x){
return ((x%M + M)%M);
}
int add(int a,int b){
return mod... | 4 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int s = 0;
bool f = 0;
char ch = ' ';
while (!isdigit(ch)) {
f |= (ch == '-');
ch = getchar();
}
while (isdigit(ch)) {
s = (s << 3) + (s << 1) + (ch ^ 48);
ch = getchar();
}
return (f) ? (-s) : (s);
}
inline void write(int... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char s[100];
int x;
scanf("%s%d", s, &x);
int n = strlen(s), tot = 0;
for (int i = 0; i < n; i++) {
int to = -1;
for (int j = 9; j >= 0; j--) {
for (int k = i; k < n; k++) {
if (s[k] == j + '0') {
to = k;
brea... | 6 |
//Bismillahir Rahmanir Rahim...Allah!
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
vector<int>ar[1005];
int valu[1005];
lli w[100007];
lli kdp[105][500*500];
lli knapsack(lli i,lli W)
{ if(kdp[i][W]!=0)return kdp[i][W];if(i==0||W==0)return 0; else if(w[... | 6 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
struct T {
int d[4];
bool operator<(const T& b) const {
for (int i = 0, _n = (4); i < _n; ++i)
if (d[i] != b.d[i]) return d[i] < b.d[i];
return false;
}
};
int n;
char s[10001];
set<T> cur, nxt;
const string f[]... | 14 |
#include <bits/stdc++.h>
using namespace std;
vector<int> locs;
void computeLPSArray(char *pat, int M, int *lps);
void KMPSearch(char *pat, char *txt) {
int M = strlen(pat);
int N = strlen(txt);
int *lps = (int *)malloc(sizeof(int) * M);
int j = 0;
computeLPSArray(pat, M, lps);
int i = 0;
while (i < N) {
... | 12 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.