solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const long double pi = acos(-1);
const long long inf = (long long)1e9;
const int mod = 1000000007;
int n, m, k;
const int N = 3e5 + 10;
template <typename M>
istream& operator>>(istream& is, vector<M>& v) {
for (auto& it : v) is >> it;
return is;
}
template <typename M>... | 11 |
#include <bits/stdc++.h>
using namespace std;
const double dinf = 1e200;
void mytimer(string task) {}
void ext(int c) {}
long long lim = 1000000000000000000LL + 1000000000;
vector<int> gr[20];
int placeof[20];
int vertof[20];
long long dp[1 << 17];
int n;
inline bool can(int v, int m) {
for (int i = 0; i < (int)gr[v]... | 16 |
#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1000000007;
long long int nC5(long long int n) {
long long int r = n * (n - 1LL) * (n - 2LL) * (n - 3LL) * (n - 4LL);
return r / 120LL;
}
int main() {
long long int n;
cin >> n;
long long int ans = nC5(n) * nC5(n) * 120LL;
cout << ans <... | 6 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x;
char c;
int f = 1;
while ((c = getchar()) != '-' && (c > '9' || c < '0'))
;
if (c == '-') c = getchar(), f = -1;
x = c ^ '0';
while ((c = getchar()) >= '0' && c <= '9')
x = (x << 1) + (x << 3) + (c ^ '0');
return x * f;
}
i... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, i, a, b;
int main() {
cin >> n;
int y[n];
for (i = 0; i < n; i++) {
cin >> y[i];
if (y[i] == 25)
a++;
else if (y[i] == 50 && a > 0)
a--, b++;
else if (a > 0 && b > 0)
a--, b--;
else if (a >= 3)
a -= 3;
else {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000005;
const int INF = 1 << 30;
struct Node {
unsigned long long sum[2];
int w[2], cv[2], sz, h;
Node *lc, *rc;
Node() {}
Node(int a, int b, int c) : sz(1), h(c), lc(0), rc(0) {
cv[0] = cv[1] = 0;
w[0] = sum[0] = a;
w[1] = sum[1] = b... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
string s;
cin >> s;
string ans;
int n = s.length();
bool possible = true;
for (int i = 0; i < s.length(); i++) {
if (s[i] != s[0]) {
possible = false;
break;
}
}
if... | 3 |
#include <bits/stdc++.h>
using namespace std;
void input(vector<int>& a) {
for (int i = 0; i < a.size(); i++) cin >> a[i];
}
void inputp(vector<pair<int, int> >& a) {
for (int i = 0; i < a.size(); i++) cin >> a[i].first >> a[i].second;
}
void output(vector<int>& a) {
for (int i = 0; i < a.size(); i++) cout << a[i... | 5 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using D = double;
using uint = unsigned int;
const int maxn = 100005;
char s[maxn];
int ans[30];
int n, m;
void ttry(int b) {
int last = -1;
int lastc = -1;
for (int i = 0; i < 26; i++) ans[i] = 0;
for (int i = 0; i < n;... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
int t;
cin >> t;
while (t--) {
int n, k;
cin >> n >> k;
int a[n], b[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
cin >> b[i];
}
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> table(n);
for (int i = 0; i < n; ++i) cin >> table[i];
vector<pair<int, int> > numbers(3000, make_pair(-1, -1));
for (int i = 0; i < n; ++i)
for (int j = 0; j < table[i]; ++j) {
int temp;
cin >> temp;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int l, r;
cin >> l >> r;
if (2 * l > r)
cout << "YES\n";
else
cout << "NO\n";
}
int main() {
int t;
cin >> t;
while (t--) solve();
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;
const int MAXN = 1e6 + 10;
vector<int> v1[MAXN];
int a[MAXN];
int cm[MAXN];
long long s[MAXN];
long long ans = 0;
set<int> s1;
set<int>::iterator iter;
void init() {
memset(a, 0, sizeof(a))... | 5 |
#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;
long long int ar[n], sumt = 0, suma = 0, sumb = 0;
for (long long int i = 0; i < n; i++) {
cin >> ar[i];
sumt += ar[i];
}
long long int i = 0, j = n - 1,... | 4 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:60000000")
using namespace std;
int c1, c2, c3, c4, n, m;
vector<int> a, b;
void read() {
int i;
cin >> c1 >> c2 >> c3 >> c4;
cin >> n >> m;
a.resize(n + 2);
for (i = 1; i <= n; i += 1) cin >> a[i];
b.resize(m + 2);
for (i = 1; i <= m; i += 1) cin >... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000 + 33;
int n, m, k;
bool ary[N][N];
bool valid(int a, int b) { return (a < n && a >= 0 && b < m && b >= 0); }
bool ok(int a, int b) {
if (!valid(a, b) || !valid(a + 1, b) || !valid(a, b + 1) ||
!valid(a + 1, b + 1))
return 0;
if (ary[a][b] ==... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long double eps = 1e-9;
const int N = 55, M = 5005;
int n, R;
long double dp[N][M];
int a[N], b[N], p[N];
bool check(long double x) {
for (int i = n; i > 0; i--) {
for (int j = R + 1; j < M; j++) dp[i + 1][j] = x;
for (int j = 0; j <= R; j++)
dp[i][j] ... | 16 |
#include <bits/stdc++.h>
template <class T>
inline T gcd(T a, T b) {
return a % b ? gcd(b, a % b) : b;
}
using namespace std;
class ppp {
public:
long long val;
long long tree[4 * 200010];
void update(int node, int low, int hi, int i, long long value) {
if (low == hi) {
tree[node] = min(val, tree[nod... | 9 |
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
int main() {
auto start = high_resolution_clock::now();
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, h;
cin >> n >> h;
vector<pair<int, int>> air(n);
for (int i = 0; i < n; ++i) {
cin >> air[i].first >> air[i].sec... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200050;
int p[N], nxt[N];
vector<int> G[N];
int find(int u) {
if (u == p[u]) return u;
return p[u] = find(p[u]);
}
int findnxt(int u) {
if (u == nxt[u]) return u;
return nxt[u] = findnxt(nxt[u]);
}
int main() {
int n, q;
scanf("%d%d", &n, &q);
fo... | 11 |
#include <bits/stdc++.h>
using namespace std;
clock_t time_p = clock();
void time_taken() {
time_p = clock() - time_p;
cerr << "Time Taken : " << (float)(time_p) / CLOCKS_PER_SEC << "\n";
}
const long long mod = 1e9 + 7;
const long long INF = 1e18;
template <typename Arg1, typename Arg2>
ostream& operator<<(ostream... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const long double PI = acos(-1);
const int M = 998244353;
int n, m, k, t, T;
long long ans;
long long a, b;
map<long long, long long> mpx, mpy, mx, my;
map<pair<int, int>, long long> X, Y;
vector<long long> first, second;
int main() {
ios_base::sync... | 11 |
#include <bits/stdc++.h>
using namespace std;
const long long int N = 1e5 + 5, inf = 1e18;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int n, m;
cin >> n >> m;
long long int ary[m];
long long int sum = 0;
vector<pair<long long int, long long int> > v;
for (l... | 10 |
#include <bits/stdc++.h>
using namespace std;
int n, a, mx, s, i;
int main() {
cin >> n;
for (i = 0; i < n; i++) {
cin >> a;
s += a;
mx = max(mx, a);
}
cout << mx - (s - mx) + 1;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
const int oo = (int)1e9;
const double eps = 1e-9;
int dx1, ax1, dx2, ax2, dy1, ay1, dy2, ay2, d1, a1;
void pre() {
int n1 = dx1 + ax2;
int n2 = dx2 + ax1;
if (n1 > n2) {
d1 = dx1;
a1 = ax2;
} else if (n1 < n2) {
d1 = dx2;
a1 = ax1;
} else {
a1 ... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long int b[100001];
signed main() {
long long int n, x, y, c = 0, k = 0;
cin >> n >> y;
vector<long long int> a;
for (long long int i = 0; i < n; i++) {
cin >> x;
a.push_back(x);
}
for (long long int i = 0; i < n - 1; i++) {
if (a[i + 1] == a[i]... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int INF = (int)1e9;
const long long LINF = (long long)1e18;
const long double PI = acos((long double)-1);
const long double EPS = 1e-9;
inline long long gcd(long long a, long long b) {
long long r;
while (b) {
r = a % b;
a = b... | 11 |
#include <bits/stdc++.h>
using namespace std;
template <typename A1>
void prn(A1&& arg) {
cout << arg << '\n';
}
template <typename A1, typename... A>
void prn(A1&& arg, A&&... args) {
cout << arg << ' ';
prn(args...);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long lo... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;
int n, odd[maxn], sum[maxn];
long long a, ans, cnt[2][maxn];
inline long long rd() {
long long res = 0;
int f = 1;
char ch = getchar();
for (; !isdigit(ch); ch = getchar())
if (ch == '-') f = -1;
for (; isdigit(ch); ch = getchar()) r... | 12 |
#include <bits/stdc++.h>
using namespace std;
int f(long long x, long long y, long long x1, long long y1) {
long long t = (x * x1 + y * y1) % (x1 * x1 + y1 * y1);
if (t) return 0;
long long tx = -y1;
long long ty = x1;
x1 = tx;
y1 = ty;
t = (x * x1 + y * y1) % (x1 * x1 + y1 * y1);
if (t) return 0;
ret... | 12 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
long long n, m, i, j, frq[30][30];
string s;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
if (0)
;
cin >> n >> s;
for (i = 0; i < n - 1; i++) {
frq[s[i] - 'A'][s[i + 1] - 'A']++;
}
string ans = "";
long l... | 1 |
#include <bits/stdc++.h>
using namespace std;
int i, j, k, t, n, m, f[300500], q, l, r;
char c;
set<int> st[2005000];
int main() {
ios::sync_with_stdio(0);
scanf("%d", &t);
while (t--) {
scanf("%d%d", &n, &q);
for (i = 1; i <= n; i++) {
c = getchar();
if (c == '+' || c == '-') {
f[i] =... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int total = 0;
for (int i = 0; i < 5; i++) {
int aux;
cin >> aux;
total += aux;
}
if (total == 0) {
cout << "-1" << endl;
return 0;
}
if (total % 5 == 0)
cout << total / 5 << endl;
else
cout << "-1" << endl;
}
| 3 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimization("unroll-loops")
std::pair<int, int> DR[] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1},
{-1, 1}, {-1, -1}, {1, 1}, {1, -1}};
using namespace std;
int cone(int n) {
int cnt = 0;
while (n) {
n = (n - 1) & n;
cn... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100050;
long long h[maxn], p[maxn], vis[maxn];
int n, m;
bool check(long long mid) {
long long dest;
int pt, j;
memset(vis, 0, sizeof(vis));
for (int i = pt = 0; i < n; i++) {
if (h[i] <= p[pt])
dest = h[i] + mid;
else {
if (mid ... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n;
int m;
int c[3333];
int main() {
scanf("%d%d", &n, &m);
memset(c, 0, sizeof(c));
for (int i = 1; i <= n; i++) {
int a, b;
scanf("%d%d", &a, &b);
c[a] += b;
}
int ans = 0;
for (int i = 1; i <= 3001; i++) {
ans += min(m, c[i - 1] + c[i]);
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, a[110];
bool hit[2 * 1000000 + 1];
int b[110], num;
int main() {
int T;
cin >> T;
while (T--) {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
memset(hit, 0, sizeof(hit));
num = 0;
for (int i = 1; i <= 1000000 && num < n; i... | 8 |
#include <bits/stdc++.h>
using namespace std;
char s1[1000 * 200 + 100], s2[1000 * 200 + 100];
bool equ(int l1, int r1, int l2, int r2) {
if ((r1 - l1) % 2 == 1) {
for (int i = l1; i < r1; i++) {
if (s1[i] != s2[i - l1 + l2]) return false;
}
return true;
} else {
bool t = false;
for (int i... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n;
string s, type;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
int l = 0, r = 1e9;
cout << "0 1\n";
cout << flush;
cin >> type;
for (int i = 1; i < n; ++i) {
int mid = (((int64_t)l + r) >> 1LL);
cout << mid << " 1\n... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n, t, a, b, c, k, m, res;
vector<int> Like[2005], Dis[2005], Connect[2005];
bool Free[2005];
void bfs(int cur) {
Connect[c].push_back(cur);
for (int i = 0, _n = (Like[cur].size()); i < _n; i++) {
int tmp = Like[cur][i];
if (Free[tmp]) {
Free[tmp] = fal... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int i, j, k, cnt = 0, n, a, b, c;
cin >> n;
if (n % 2 == 0) {
a = n / 2;
if (a % 2 == 0)
cout << n / 2 << " " << n / 2;
else
cout << n - 10 << " " << 10;
} else {
cout << n - 9 << " " << 9;
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int nmax = 1e5 + 42;
string inp;
int n;
int seen[26];
int main() {
cin >> n;
cin >> inp;
for (auto k : inp) seen[k - 'a']++;
for (int i = 0; i < 26; i++)
for (int j = 0; j < seen[i]; j++) cout << char(i + 'a');
cout << endl;
return 0;
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
int a[11], b[11];
int main(void) {
int n, i, j, lft, x, minMoriartyCanGet = 0, maxSherlockCanGet = 0;
string sh, mor;
cin >> n >> sh >> mor;
for (i = 0; i < n; i++) a[sh[i] - '0']++;
for (i = 0; i < n; i++) b[mor[i] - '0']++;
lft = 0;
for (i = 8; i >= 0; i--) ... | 5 |
#include <bits/stdc++.h>
int n;
int a[3000];
int ans;
int main() {
int i, j;
scanf("%d", &n);
for (i = 2; i < (1 << (n + 1)); i++) {
scanf("%d", &a[i]);
}
for (i = n; i > 0; i--) {
for (j = 0; j < (1 << (i - 1)); j++) {
if (a[2 * j + (1 << i)] > a[2 * j + 1 + (1 << i)]) {
ans += a[2 * j ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200010;
bool a[maxn], b[maxn];
int h1[maxn], h2[maxn], w1[maxn], w2[maxn];
long long ans[maxn];
struct input {
int t, x;
} in[maxn];
int main() {
ios::sync_with_stdio(false);
int w, h, n;
cin >> w >> h >> n;
a[0] = a[w] = true;
b[0] = b[h] = tru... | 7 |
#include <bits/stdc++.h>
using namespace std;
const long long maxh = 50 + 5;
const long long INF = 1LL << 60;
long long twop[maxh];
struct Node {
Node *lc, *rc;
long long Sum, tag;
Node() {
lc = rc = NULL;
Sum = tag = 0;
}
void pull() {
if (!tag) Sum = (lc ? lc->Sum : 0) + (rc ? rc->Sum : 0);
}
... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int s, t;
scanf("%d%d", &s, &t);
double ans = 100005;
int N;
scanf("%d", &N);
for (int i = 1; i <= N; i++) {
int x, y, v;
scanf("%d%d%d", &x, &y, &v);
double now = sqrt((x - s) * 1.0 * (x - s) + (y - t) * (y - t)) / v;
if (now < ans)... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x, y, w, z, a = 0;
cin >> x >> y;
for (int i = 0; i < x; i++) {
z = 0;
cin >> w;
while (w) {
if (w % 10 == 7 || w % 10 == 4) z++;
w /= 10;
}
if (z <= y) a++;
}
cout << a << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
if (n / 2 > k || n == 1 && k > 0) {
cout << -1;
} else {
if (n == 1) {
cout << 1;
} else {
cout << (k - n / 2 + 1) << " " << 2 * (k - n / 2 + 1) << " ";
for (int i = 0; i < n - 2; i++) {
cou... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
long long a, b, c;
long long sum = 0, nu1, nu2;
for (int i = 0; i < n; i++) {
cin >> a;
sum += a;
}
long long su1 = 0;
for (int i = 0; i < n - 1; i++) {
cin >> b;
su1 += b;
}
long long x = sum - su1;
cout <... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1);
long long power(long long b, long long e, long long m) {
if (e == 0) return 1;
if (e & 1) return b * power(b * b % m, e / 2, m) % m;
return power(b * b % m, e / 2, m);
}
long long power(long long b, long long e) {
if (e == 0) return ... | 17 |
#include <bits/stdc++.h>
using namespace std;
long long p[10000005];
int idxp;
int main() {
long long n;
int i, j;
long long countt = 0;
scanf("%I64d", &n);
if (n % 3 != 0)
printf("0\n");
else {
n = n / 3;
long long r = (long long)sqrt(n);
for (i = 1; i <= r; i++) {
if (n % i == 0) p[i... | 16 |
#include <bits/stdc++.h>
using namespace std;
typedef struct point {
int x;
int y;
} POINT;
string solve() {
int n, m, i, j, k;
cin >> n >> m;
char puzzle[n][m];
for (i = 0; i < n; i++)
for (j = 0; j < m; j++) cin >> puzzle[i][j];
POINT topLeft, topRight, bottomLeft, bottomRight;
if (n == 1) {
i... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long maxa = 0, mina = 0x3f3f3f3f, maxb = 0, minb = 0x3f3f3f3f,
mxd = -0x3f3f3f3f, mnd = 0x3f3f3f3f;
long long ansb = 0, ansn = 0;
char s[500005];
bool check(long long mid) {
long long minx = max(0ll, maxa - mid), maxx = mina + mid,
miny = max(0l... | 18 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
long long int k, p, ans = 0, n;
string s, rev;
cin >> k >> p;
for (long long int i = 1; i <= k; i++) {
s = to_string(i);
rev = s;
reverse(rev.begin(), rev.end());
s += rev;
n = stoll(s);
n %= p;
ans += n;
ans %= p;
... | 5 |
#include <bits/stdc++.h>
const int size = 1 << 16, mod = 1000000007, mask = (1 << 15) - 1;
std::complex<double> root[size], invR[size];
int tot;
void init(int n) {
tot = n;
double fac = 2.0 * acos(-1.0) / n;
for (int i = 0; i < n; ++i) {
root[i] = std::complex<double>(cos(i * fac), sin(i * fac));
invR[i] ... | 25 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 205, MAXM = 20005, INF = 0x3f3f3f3f, STEP = 40000;
struct Graph {
int u, v, w;
} gra[MAXM];
struct Edge {
int to, cap, next;
} edge[MAXM];
int head[MAXN], id[MAXN], que[MAXN], dis[MAXN], p[MAXN], q[MAXN],
pc[MAXN][MAXN], n, m, tot, ans;
void addedge... | 21 |
#include <bits/stdc++.h>
using namespace std;
long long arr[5];
int main() {
long long test;
while (cin >> test) {
string s;
for (long long t = 1; t <= test; t++) {
cin >> s;
long long ans = 999999999;
long long ck = 0;
memset(arr, 0, sizeof(arr));
for (long long i = 0; i < s.s... | 4 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:268435456")
using namespace std;
template <typename T>
T sqr(const T &x) {
return x * x;
}
template <typename T>
T my_abs(const T &x) {
return x < 0 ? -x : x;
}
const int INF = (int)1e9;
const long long LINF = (long long)6e18;
const long long INF64 = LINF;
co... | 14 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U>
using Pa = pair<T, U>;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;
class SuffixArray {
public:
vec<int> SA;
const string S;
int N;
SuffixArray(const string& S) : S(S) {
... | 16 |
#include <bits/stdc++.h>
const int M = 7851, mod = 1e9 + 7;
int n, r, a, b, c, d, tot, len, X[M], G[M][M];
struct Pair {
int x, y;
inline bool operator<(const Pair& it) const {
return x == it.x ? y < it.y : x < it.x;
}
} p[20005];
inline void swap(int& a, int& b) {
int c = a;
a = b;
b = c;
}
inline int ... | 23 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, q, ans = 0, x = 0, y = 0;
string s;
char c;
cin >> n >> q >> s;
for (int i = 0; i < n; i++) {
if (s[i] == '.') y++;
if (s[i] != '.' || i == n - 1) {
ans += max((y - 1), 0);
y = 0;
}
}
s = "a" + s + "a";
for (int i ... | 8 |
#include <bits/stdc++.h>
int n, a, d;
unsigned long long m = 368131125, mod = 1e9, x = 1.2e10;
int main() {
scanf("%d%d%d", &n, &a, &d);
printf("%llu %llu\n", m * a % mod * x + 1, m * d % mod * x);
return 0;
}
| 27 |
#include <bits/stdc++.h>
using namespace std;
int a, b, i, x = 0, y = 999999998;
int main() {
cin >> a >> b;
if (a % 2) {
x = y + 1;
a--;
}
if (b < a / 2 || !a && b)
cout << -1;
else {
for (i = 1; i < a / 2; i++, y -= 2) cout << y << ' ' << y - 1 << " ";
b -= (a / 2) - 1;
if (a) cout <... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int maxx = 1e5 + 20;
int a[maxx];
int main() {
long long sum = 0;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
}
int t = 0;
for (int i = 0; i < n; i++) {
if ((sum - a[i]) % 2 == 0) t++;
}
cout << t << endl;
r... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, m, P, a[10010], b[100010], Phi, D[1010], q[10010], r[10010], f[1010];
void read(int &x) {
char ch = getchar();
int mark = 1;
for (; ch != '-' && (ch < '0' || ch > '9'); ch = getchar())
;
if (ch == '-') mark = -1, ch = getchar();
for (x = 0; ch >= '0' &&... | 18 |
#include <bits/stdc++.h>
using namespace std;
const long long LM = 1LL << 60;
template <typename T>
void _smawk(const vector<int> &rows, const vector<int> &cols,
const function<T(int, int)> &lookup, vector<int> *result) {
if (rows.size() == 0) return;
vector<int> _cols;
for (int col : cols) {
whil... | 20 |
#include <bits/stdc++.h>
using namespace std;
long long max(long long a, long long b) {
if (a > b)
return a;
else
return b;
}
long long min(long long a, long long b) {
if (a < b)
return a;
else
return b;
}
long long lowbit(long long x) { return x & (-x); }
long long prime(long long x) {
if (x ... | 13 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
string s;
cin >> s;
int mat = (n * (n - 1)) / 2;
int c2 = 0;
int in;
for (int i = 0; i < n; i++)
if (s[i] == '2') {
c2++;
in = i;
}
int d = (n * n) - n + c2 - (c2 * c2);
if (c2 == 1 || c2 == 2)
cout... | 2 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
const long double PI = 3.141592653589793;
const long long INF = 9223372036854775807ll;
const long long mod = 1e9 + 7;
void solve() {
int n;
cin >> n;
int grundy[n + 1];
int xor_sum[n + 1]... | 12 |
#include <bits/stdc++.h>
using namespace std;
template <class T, class L>
bool smax(T &x, L y) {
return x < y ? (x = y, 1) : 0;
}
template <class T, class L>
bool smin(T &x, L y) {
return y < x ? (x = y, 1) : 0;
}
const int maxn = 1e5 + 17;
long long n, a[maxn], lef[maxn], ri[maxn], l[maxn], r[maxn], ans;
int main(... | 12 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 100, M = 1e6, inf = 1e9 + 123, mod = 1e9 + 7, key = 31;
const double EPS = 0.000000001;
template <typename T>
inline T sqr(T t) {
return t * t;
}
inline void file() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
char c;
bool x[N],... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 110000, M = 260, infty = 1000000000;
int n, q, len[3];
char s[N], ss[3][M];
int memo[M][M][M], nextt[N][26];
bool ismemo[M][M][M];
int calc(int a0, int a1, int a2) {
int a[3] = {a0, a1, a2};
if (ismemo[a0][a1][a2]) return memo[a0][a1][a2];
int best = inf... | 14 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args.... | 13 |
#include <bits/stdc++.h>
using namespace std;
string str;
int cur_index;
bool alp_find(char ch, int index) {
for (int i = index; i < str.size(); i++) {
if (str.at(i) == ch) {
cur_index = i + 1;
return true;
}
}
return false;
}
int main() {
cin >> str;
int count = 0;
if (alp_find('h', 0))... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
long long H, N;
cin >> H >> N;
long long ans = 0;
for (long long lo = 1, hi = (1LL << H), i = 0; lo < hi; i++) {
long long mid = (lo + hi) / 2;
long long dis = hi - mid;
if (i % 2 == 0) {
if (N <= mi... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int tt;
cin >> tt;
while (tt--) {
int n;
cin >> n;
cout << n << '\n';
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int tests;
cin >> tests;
for (int test = 0; test < tests; ++test) {
int n;
cin >> n;
vector<int64_t> a(n);
copy_n(istream_iterator<int64_t>(cin), n, a.begin());
int res = 0;
for (int i = 1; i < n; ++i) {
int sec = 0;
in... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, k;
cin >> n >> k;
long long arr[200005];
memset(arr, 0, sizeof arr);
for (long long i = 0; i < n; i++) cin >> arr[i];
long long ans = 0, temp = 0, carry = 0;
for (long long i = 0; i < n; i++) {
if (i == n - 1) {
arr[i] += ca... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long INF64 = 1e18;
const long long mod = 1e9 + 7;
const int maxn = 4e3 + 7;
vector<int> g[maxn];
int used[maxn];
vector<int> loops;
map<int, int> loopLensCnts;
long long dp[maxn][maxn];
vector<long long> loopsCur;
int lastLoopLen;
long long calcDpWithAll(long lon... | 18 |
#include <bits/stdc++.h>
using namespace std;
int p, d, t, f, c;
int solve() {
double dp = p * t;
int res = 0;
if (dp > c || p > d) return 0;
while (dp < c) {
double temp = dp / (d - p);
dp += temp * p;
if (dp >= c) return res;
++res;
temp = f + dp / d;
dp += temp * p;
}
return res;
... | 7 |
#include <bits/stdc++.h>
const int N = 200005;
using namespace std;
char a[N], b[N];
int lena, lenb;
int da[N];
bool vis[N];
bool check(int mid) {
memset(vis, 0, sizeof vis);
for (int i = 1; i <= mid; i++) vis[da[i]] = 1;
int j = 1, sum = 0;
for (int i = 1; i <= lena; i++) {
if (vis[i]) continue;
if (a[... | 9 |
#include <bits/stdc++.h>
using namespace std;
vector<int> v[200010], c[200010], rt;
int n, siz[200010], fa[200010], dep[200010];
vector<pair<int, pair<int, int> > > ans;
void dfs1(int np, int fath) {
bool isrt = 1;
siz[np] = 1;
for (int x : v[np]) {
if (x == fath) continue;
dfs1(x, np);
siz[np] += siz... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, l;
cin >> n >> l;
vector<int> v(n), u(n);
for (int i = 0; i < v.size(); ++i) {
cin >> v[i];
}
for (int j = 0; j < u.size(); ++j) {
cin >> u[j];
}
bool valid = false;
fo... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long a[300010], b[300010];
int main() {
long long n, x = 0, score = 0, y = 0;
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i], score += a[i];
sort(a, a + n);
b[0] = score;
if (n == 1) {
cout << a[0] << endl;
return 0;
}
for (int i = 1; i < n; ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
int n;
cin >> n;
vector<int> cnt(100001, 0);
for (int i = 0; i < n; ++i) {
int a;
cin >> a;
++cnt[a];
}
bool hasOdd = false;
for (int i = 1; i <= 100000; ++i) {
if (cnt[i] % 2 != 0) {
hasOdd = true... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int k;
scanf("%d", &k);
if (k == 0) {
cout << "ab";
return 0;
}
int c = 0;
vector<int> v;
while (k) {
bool flag = 0;
for (int i = 1;; i++) {
if (i > k) break;
k -= i;
if (!flag) {
v.push_back(c);
v... | 8 |
#include <bits/stdc++.h>
long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Arg... | 5 |
#include <bits/stdc++.h>
using namespace std;
int m0[2000009];
set<int> se[3];
void modosit0(int cs, int k, int v, int h, int val) {
if (h < k || v < h) return;
if (k == v && k == h) {
m0[cs] += val;
return;
}
m0[cs] += val;
modosit0(2 * cs, k, (k + v) / 2, h, val);
modosit0(2 * cs + 1, (k + v) / 2 ... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int arr[] = {4, 7, 44, 47, 74, 77, 444, 447, 477, 777, 744, 747, 474, 774};
bool a = false;
for (int i = 0; i < 14; i++) {
if (n % arr[i] == 0) {
a = true;
}
}
if (a) {
cout << "YES";
} else {
cout << "NO";... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int A, B, n;
scanf("%d %d %d", &A, &B, &n);
if (A == 0 && A + B == 0) {
printf("%d", (n + 1) / 2);
return 0;
}
if (A == 0) {
printf("No solution");
return 0;
}
if (A != 0 && B == 0) {
printf("0");
return 0;
}
int C = B ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const double pi = acos(-1.0);
int sgn(double d) { return d > eps ? 1 : (d < -eps ? -1 : 0); }
double trim(double d, double l = 1.0) { return d > l ? l : (d < -l ? -l : d); }
vector<int> average(const vector<vector<int> >& x, int start, int len) {
... | 18 |
#include <bits/stdc++.h>
using namespace std;
long double a[650], b[650];
int main() {
int n, k;
cin >> n >> k;
long double ans = 0;
a[0] = 1;
for (int x = 1; x <= n; x++) {
for (int y = 0; y < 650; y++) {
b[y] = a[y];
b[y] -= a[y] * (1.0 / (y + 2)) * 1.0 / k;
if (y) b[y] += a[y - 1] * (... | 19 |
#include <bits/stdc++.h>
int main() {
long int a, b;
scanf("%ld%ld", &a, &b);
long int r, x, y;
x = a;
y = b;
while (y != 0) {
r = x % y;
x = y;
y = r;
}
a = a / x;
b = b / x;
if (b - a == 1 || a - b == 1)
printf("Equal\n");
else if (a > b)
printf("Masha\n");
else if (a < b)
... | 7 |
#include <bits/stdc++.h>
using namespace std;
inline char gc() {
static char buf[100000], *p1 = buf, *p2 = buf;
return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
? EOF
: *p1++;
}
inline long long read() {
long long x = 0;
char ch = getchar();
bool positive... | 24 |
#include <bits/stdc++.h>
using namespace std;
void func(void) {
freopen("input.c", "r", stdin);
freopen("output.c", "w", stdout);
}
void print(vector<long long> &v) {
cout << v.size() << endl;
for (int i = 0; i < v.size(); i++) {
printf("%lld ", v[i]);
}
printf("\n");
}
void print(vector<pair<long long,... | 13 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
int fx[] = {0, 0, -1, 1, +1, -1, -1, +1};
int fy[] = {1, -1, 0, 0, +1, +1, -1, -1};
bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) {
return a.first > b.first;
}
template <typename T>
inline T Bigmod(T base, T power, T MO... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const int MOD = 1e9 + 7;
const int MAXN = 5e5 + 5;
const double PI = 4 * atan((double)1);
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int m, k, n, s;
cin ... | 11 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
for (int i = 0; i < t; i++) {
string s, c;
cin >> s >> c;
int t = s.compare(c);
int minn = s.size() - 1;
string sorted = s;
sort(sorted.begin(), sorted.end());
for (... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 6e5 + 100;
struct AcAm {
int fail[N], ch[N][26], si[N], size;
int insert(char *s) {
int len = strlen(s + 1), u = 0;
for (int i = 1; i <= len; i++) {
int c = s[i] - 'a';
if (!ch[u][c]) ch[u][c] = ++size;
u = ch[u][c];
}
si[... | 16 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.