solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n, q;
cin >> n >> q;
deque<long long> dq;
for (long long i = 0; i < n; i++) {
long long x;
cin >> x;
dq.push_back(x);
}
map<long long, pair<long long, long long>> sol;
f... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long n;
vector<long long> holder;
void Lucky(long long num, int i) {
if (i == 10) {
if (num) {
holder.push_back(num);
}
return;
}
Lucky(num * 10 + 4, i + 1);
Lucky(num * 10 + 7, i + 1);
Lucky(num, i + 1);
}
int main() {
ios_base::sync_with... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char s[1000005];
gets(s);
int l = strlen(s);
int *arr = (int *)malloc(sizeof(int) * l);
int p = 0, q = 0;
for (int i = 0; s[i]; i++) {
if (s[i] == 'l') {
arr[l - 1 - p] = i + 1;
p++;
} else {
arr[q] = i + 1;
q++;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long tc, n;
cin >> tc;
while (tc--) {
string s1, s2;
cin >> n >> s1 >> s2;
if (s1 == s2) {
cout << "Yes" << endl;
continue;
}
int cnt = 0, pos1 = 0, pos2 = 0;
for (int i = 0; i < n; i++) {
if (s1[i] != s2[i])... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100 + 5;
const int K = 30;
int n, m;
string s[N * 2], st[N * 2], nd[N * 2];
int sz[N * 2];
int res[N * 2];
bitset<66000> a[N * 2][15];
void compute(int i) {
for (int k = 1; k < 15; k++) {
for (int j = 0; j + k - 1 < s[i].size(); j++) {
int cur = 0;... | 14 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int s = 0, t = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') t = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();
return s * t;
}
const int N = 1e5 +... | 24 |
#include <bits/stdc++.h>
using namespace std;
char a[100];
int main(void) {
int n;
scanf("%d", &n);
sprintf(a, "%o", n);
int ans = 0;
for (int i = 0; a[i]; i++)
if (a[i] == '1') ans++;
printf("%d", ans);
return 0;
}
| 13 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100001;
int n, m, a[N], b[N];
int main() {
std::ios::sync_with_stdio(false);
scanf("%d%d", &n, &m);
long long l = 0, r = 0, mid, ans = -1;
for (int i = 0; i < n; i++) {
scanf("%d", a + i);
r += (long long)a[i];
}
long long tot = r;
r += 2... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int MN = 300005, inf = 1000000005, mod = 1000000007;
const long long INF = 1000000000000000005LL;
struct odp {
int a, b, c;
};
pair<int, int> S[MN];
int T[MN];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d", &S[i].first);
... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(0);
cin.sync_with_stdio(0);
;
long long n, c = 0;
cin >> n;
string s;
cin >> s;
for (int i = 0; i < n; i++) {
if (s[i] == s[i + 1] && s[i] != '?') {
cout << "NO" << endl;
return 0;
}
}
for (int i = 0; i < n; i++) ... | 5 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<long long int> > dp(5009, vector<long long int>(5009, 0));
long long int modexpo(long long int base, long long int expo,
long long int mod) {
long long int result = 1;
while (expo > 0) {
if (expo & 1) result = (result * base) % mo... | 16 |
#include <bits/stdc++.h>
FILE *in = stdin;
FILE *out = stdout;
int color[204][204];
int x[4], y[4];
int xx[4], yy[4];
int main() {
int i, j, k;
for (i = 0; i < 4; i++) {
fscanf(in, "%d %d", &xx[i], &yy[i]);
xx[i] += 100;
yy[i] += 100;
}
std::sort(xx, xx + 4);
std::sort(yy, yy + 4);
for (i = xx[0... | 8 |
#include <bits/stdc++.h>
using namespace std;
int a[3333];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
int kol = 0;
for (int g = 1; g <= n; g++) {
int num = -1;
for (int i = 1; i <= n; i++)
if (a[i] == g) num = i;
for (int i = num; i > g; i--) {
a[i] = a[i -... | 11 |
#include <bits/stdc++.h>
int C;
int t;
int board[8][8];
bool vis[64];
int p1, p2;
bool YES;
int dirx[4] = {2, 2, -2, -2};
int diry[4] = {2, -2, 2, -2};
std::vector<int> ady[64];
bool llegar[64][11];
bool no[64];
int main() {
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
int u = i * 8 + j;
... | 7 |
#include <bits/stdc++.h>
const long long maxn = 100000000 + 10;
using namespace std;
int main() {
char a[100000 + 10];
cin >> a;
long long int size = 0;
long long sum = 0;
while (a[size] != 0) size++;
map<char, int> m;
for (int i = 0; i < size; i++) {
map<char, int>::iterator itr = m.find(a[i]);
i... | 7 |
#include <bits/stdc++.h>
using namespace std;
inline long long rd() {
long long x = 0;
int ch = getchar(), f = 1;
while (!isdigit(ch) && (ch != '-') && (ch != EOF)) ch = getchar();
if (ch == '-') {
f = -1;
ch = getchar();
}
while (isdigit(ch)) {
x = (x << 1) + (x << 3) + ch - '0';
ch = getch... | 15 |
#include <bits/stdc++.h>
int main() {
int N;
std::cin >> N;
std::vector<int> p(N, 0);
std::vector<int> s(N, 0);
std::vector<int> pr(N, 0);
std::vector<int> sr(N, 0);
for (int i = 0; i < N; ++i) {
int t;
std::cin >> t;
--t;
p[i] = t;
pr[t] = i;
}
for (int i = 0; i < N; ++i) {
in... | 15 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long T = 1;
while (T--) {
long long n, m;
cin >> n >> m;
vector<pair<long long, long long> > r(n), s(m);
for (long long i = 0; i < n; i++) cin >> r[i].first >> r[i].second;
... | 12 |
#include <bits/stdc++.h>
const int INF = 2000000005;
const long long BIG_INF = 2000000000000000005;
const int mod = 1000000007;
const int P = 31;
const long double PI = 3.141592653589793238462643;
const double eps = 1e-9;
using namespace std;
vector<pair<int, int> > dir = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
bool valid(... | 18 |
#include <bits/stdc++.h>
using namespace std;
struct Point {
long long x, y, t;
Point() : x(), y(), t() {}
Point(long long _x, long long _y) : x(_x), y(_y), t() {}
void scan() { scanf("%lld%lld", &x, &y); }
Point operator-(Point p) { return Point(x - p.x, y - p.y); }
bool operator<(const Point &p) const {
... | 17 |
#include <bits/stdc++.h>
using namespace std;
class tancor {
public:
int startTime;
int nomer;
int oldNomer;
int startX;
int startY;
int defX;
int defY;
int value;
};
class bump {
public:
int time;
int index1;
int index2;
};
bool UDgreater(bump a, bump b) { return a.time < b.time; }
bool UDgreat... | 11 |
#include <bits/stdc++.h>
int dx[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int dy[8] = {1, 0, -1, 0, -1, 1, 1, -1};
using namespace std;
class pa3 {
public:
int x;
int y, z;
pa3(int x = 0, int y = 0, int z = 0) : x(x), y(y), z(z) {}
bool operator<(const pa3 &p) const {
if (x != p.x) return x < p.x;
if (y != p.y... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s, s1, new_string;
cin >> s;
cin >> s1;
int length = s.size();
int length1 = s1.size();
sort(s1.begin(), s1.end());
for (int i = 0; i < length; i++) {
for (int j = length1 - 1; j >= 0; j--) {
if (s[i] >= s1[j]) {
break;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2005, M = 200005;
int a, b, m, ans, u[M], v[M], d[N], col[N][N];
int main() {
scanf("%d%d%d", &a, &b, &m);
for (int i = 1; i <= m; i++) {
scanf("%d%d", &u[i], &v[i]);
v[i] += a;
d[u[i]]++;
d[v[i]]++;
}
for (int i = 1; i <= a + b; i++) a... | 20 |
#include <bits/stdc++.h>
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << '\n';
err(++it, args...);
}
template <class T1, class T2>
ostream &operator<<(ostream &os, const pair... | 15 |
#include <bits/stdc++.h>
using namespace std;
int sol(long long a, long long b) {
if (a > b) swap(a, b);
if (a == 0 || b == 0) return 0;
if (b % a == 0) return 1;
int ret = !sol(a, b % a);
if (ret) return 1;
b = b / a;
if (a & 1) return b % 2 == 0;
b--;
return b % (a + 1) == a || b % (a + 1) % 2 != 0;... | 15 |
#include <bits/stdc++.h>
using namespace std;
template <typename _typer>
inline _typer read() {
_typer init = 0;
char ch = getchar(), k = 0;
for (; !isdigit(ch); ch = getchar()) k = (ch == '-');
for (; isdigit(ch); ch = getchar())
init = (init << 3) + (init << 1) + (ch ^ 48);
return k ? -init : init;
}
co... | 14 |
#include <bits/stdc++.h>
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(long double x) { cerr << x; }
void... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t;
cin >> t;
while (t--) {
long long n, x, m, l = 0, r = 0;
cin >> n >> x >> m;
int check = 0;
for (long int i = 0; i < m; i++) {
long int n1, n2;
cin >> n1 >> n2;
if (check == 0) {
if ((x >= n1) && (x <... | 5 |
#include <bits/stdc++.h>
using namespace std;
int a[200010];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> pos[206];
for (int i = 0; i < n; i++) {
cin >> a[i];
pos[a[i]].push_back(i);
}
int ans = 1;
ve... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 500000 + 10;
pair<int, int> p[maxn];
vector<pair<int, int> > v;
void solve(int l, int r) {
if (r - l == 1) return;
int mid = (l + r) / 2;
solve(l, mid);
solve(mid, r);
for (int i = l; i < r; i++) v.push_back(make_pair(p[mid].first, p[i].second));
... | 15 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
long long wyn[1007][1007];
int main() {
scanf("%d%d", &n, &k);
wyn[2][2] = 1;
wyn[2][1] = 2;
wyn[4][4] = 109;
wyn[4][3] = 80;
wyn[4][2] = 30;
wyn[4][1] = 32;
wyn[8][8] = 7593125;
wyn[8][7] = 4898872;
wyn[8][6] = 1897056;
wyn[8][5] = 1757896;
... | 19 |
#include <bits/stdc++.h>
static int goin[3100][3100];
static int goout[3100][3100];
static int result[3100][3100];
int main() {
int m, n;
scanf("%d%d", &n, &m);
int ret = 0;
while (m--) {
int a, b;
scanf("%d%d", &a, &b);
((goout)[(a)][(++((goout)[(a)][(0)]))]) = b;
}
int i;
for (i = 1; i <= n;... | 9 |
#include <bits/stdc++.h>
using namespace std;
int f[800005], m, a, b, c, A[100005], lz[800005];
void lazy(int x, int l, int r) {
if (l != r) {
lz[x * 2] += lz[x];
lz[x * 2 + 1] += lz[x];
}
f[x] += lz[x];
lz[x] = 0;
}
int upd(int x, int l, int r, int ll, int rr, int val) {
lazy(x, l, r);
if (l > rr |... | 14 |
#include <bits/stdc++.h>
using namespace std;
class pipe {
public:
int pipeNum;
int end;
int amount;
int direction;
pipe(int num, int end, int amount, int direction)
: pipeNum(num), end(end), amount(amount), direction(direction) {}
};
int main() {
int n, m;
cin >> n >> m;
vector<int> flows(n + 1)... | 13 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
const ld pi = acos(0) * 2;
template <typename T>
inline void read(T &x) {
char c;
bool nega = 0;
while ((!isdigit(c = getchar())) && (c != '-... | 8 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//typedef __int128 ll;
typedef unsigned int uint;
typedef unsigned long long ull;
//typedef double db;
typedef long double ld;
typedef pair<int,int> PII;
typedef pair<ll,int> Pli;
typedef pair<ll,ll> Pll;
typedef vector<int> VI;
typedef vector<PII> VII;... | 1 |
#include <bits/stdc++.h>
using namespace std;
void run_case(int test) {
int n;
cin >> n;
auto query = [&](vector<int> a) {
cout << "? ";
for (int e : a) cout << e << ' ';
cout << endl;
int res;
cin >> res;
return res - 1;
};
vector<int> res(n);
for (int i = n; i >= 1; i--) {
vect... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1;
int in[N] = {0}, out[N] = {0}, mrk[N] = {0}, lvl[N] = {0}, inDeg[N] = {0};
vector<pair<int, int> > v;
int n;
vector<int> g[N];
void dfs(int s, int p) {
in[s] = 0;
mrk[s] = 1;
lvl[s] = lvl[p] + 1;
for (auto i : g[s]) {
if (!mrk[i]) dfs(i, s... | 10 |
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define TIMES(n) while (n--)
#define SCD(t) scanf("%d",&t)
#define SCLD(t) scanf("%ld",&t)
#define SCLLD(t) scanf("%lld",&t)
#define SCC(t) ... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long a[100001], s[100001], n, d, b, ans;
int main() {
long long i, j, l, r, mid, s1, s2, t1, t2;
scanf("%I64d %I64d %I64d", &n, &d, &b);
for (i = 1; i <= n; i++) scanf("%I64d", &a[i]), s[i] = s[i - 1] + a[i];
l = 1;
r = n;
ans = n + 1;
while (l <= r) {
... | 15 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &n) {
n = 0;
T f = 1;
char c = getchar();
while (!isdigit(c) && c != '-') c = getchar();
if (c == '-') f = -1, c = getchar();
while (isdigit(c)) n = n * 10 + c - '0', c = getchar();
n *= f;
}
template <typename T>
void write(T... | 18 |
#include <bits/stdc++.h>
using namespace std;
map<string, vector<string> > raw, res;
int n, m;
string tmp1, tmp2;
bool flag;
bool suffix(string, string);
int main() {
cin >> n;
while (n--) {
cin >> tmp1 >> m;
while (m--) {
cin >> tmp2;
raw[tmp1].push_back(tmp2);
}
}
for (map<string, vect... | 6 |
#include <bits/stdc++.h>
using namespace std;
uint64_t in() {
char c;
int s = 1;
long long n = 0;
c = getchar();
while (c != '-' && !(c >= '0' && c <= '9')) c = getchar();
while (c >= '0' && c <= '9') {
n = 10 * n + c - '0';
c = getchar();
}
return n;
}
int main() {
ios_base::sync_with_stdio(f... | 7 |
#include <bits/stdc++.h>
using namespace std;
int read() {
char ch = getchar();
int h = 0, t = 1;
while (ch != '-' && (ch > '9' || ch < '0')) ch = getchar();
if (ch == '-') t = -1, ch = getchar();
while (ch >= '0' && ch <= '9') h = h * 10 + ch - '0', ch = getchar();
return h * t;
}
const int N = 210000;
int... | 16 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:32000000")
const int nil = -1;
using namespace std;
inline bool read(int& val) { return scanf("%d", &val) != -1; }
inline bool read(long long& val) { return scanf("%I64d", &val) != -1; }
inline bool read(double& val) { return scanf("%lf", &val) != -1; }
inline bo... | 18 |
#include <bits/stdc++.h>
using namespace std;
using namespace std;
bool cmp(int a, int b) { return a > b; }
int main() {
int t;
cin >> t;
int ans, answer;
vector<int> v;
int n, arr[11] = {};
for (int i = 0; i < t; i++) {
cin >> n;
int j = 1, ch = 0;
arr[n]++;
v.clear();
for (int j = 0; j... | 7 |
#include <bits/stdc++.h>
using namespace std;
int h, n, pr1[200005], pr2[200005], a[200005], p, x[200005], l;
vector<int> v[200005];
int main() {
cin.sync_with_stdio(false);
cin >> h;
for (int i = 0; i <= h; i++) cin >> a[i];
n = 1;
p = 1;
for (int i = 1; i <= h; i++) {
if (a[i - 1] > 1 && a[i] > 1) {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long counter;
class classComp {
public:
bool operator()(const pair<long long, long long> &p1,
const pair<long long, long long> &p2) {
if (p1.first == p2.first) return p2.second < p1.second;
return p2.first < p1.first;
}
};
long long a[300... | 18 |
#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
inline istream& operator>>(istream& fin, pair<T1, T2>& pr) {
fin >> pr.first >> pr.second;
return fin;
}
template <class T0, class T1, class T2>
inline istream& operator>>(istream& fin, tuple<T0, T1, T2>& t) {
fin >> get<0>(t) >> get<1>(t... | 12 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T& x) {
bool fu = 0;
char c;
for (c = getchar(); c <= 32; c = getchar())
;
if (c == '-') fu = 1, c = getchar();
for (x = 0; c > 32; c = getchar()) x = x * 10 + c - '0';
if (fu) x = -x;
};
template <class T>
inline void rea... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int NMAX = 5010, KMAX = 5010;
int N, K, V;
long long sum;
int a[NMAX];
bool f[NMAX][KMAX][2];
int main() {
scanf("%d %d %d", &N, &K, &V);
for (int i = 1; i <= N; i++) {
scanf("%d", &a[i]);
sum += a[i];
}
if (sum < V) {
printf("NO\n");
return 0;... | 16 |
#include <bits/stdc++.h>
int main() {
int i, j, k, l, m, n;
scanf("%d", &n);
if (n < 0) n = -n;
for (i = 0;; i++) {
n -= i;
if (n <= 0 && n % 2 == 0) break;
}
printf("%d\n", i);
return 0;
}
| 8 |
#include <bits/stdc++.h>
using namespace std;
long long n, A, S;
long long a[500010];
vector<long long> p;
int main() {
scanf("%lld", &n);
for (long long i = 0; i < n; i++) {
scanf("%lld", &a[i]);
S = S + a[i];
}
if (S % 3) {
printf("0\n");
return 0;
}
S = S / 3;
for (long long i = 0, T = ... | 9 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using i3 = pair<int, ii>;
using li = pair<ll, int>;
using lii = pair<ll, ii>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<ii>;
using vli = vector<li>;
using vpll = vector<pll>;
... | 13 |
#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; }
long long int power(long long int x, long long int y,
long long int m = 1000000007) {
long long int ans... | 10 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n;
cin >> n;
string s;
cin >> s;
long long ob = 0, cb = 0, ans = 0;
if (count(s.begin(), s.end(), '(') != count(s.begin(), s.end(), ')')) {
cout << -1 << endl;
return;
}
long long i = 0;
while (i < n) {
ob += (s[i] == '... | 5 |
#include <iostream>
#include <vector>
using namespace std;
using LL = long long;
const int DIV = 1e5;
inline LL ceil(LL x, LL y) {
return (x + y - 1) / y;
}
int main() {
int T, M; cin >> T >> M;
vector<bool> is_seen(M + 1, false);
is_seen[0] = true;
vector<int> answer(M + 1, -1);
answer[0] =... | 14 |
#include <bits/stdc++.h>
using namespace std;
const double pai = acos(-1);
const double eps = 1e-10;
const long long mod = 1e9 + 7;
const int MXN = 1e6 + 5;
vector<pair<int, int> > g[MXN];
vector<int> bcc_arc[MXN];
vector<int> bcc[MXN];
int dfn[MXN];
int iscut[MXN];
int dfs_clock;
int bcc_clock;
int bccno[MXN];
struct ... | 16 |
#include <bits/stdc++.h>
using namespace std;
template <class c>
struct rge {
c b, e;
};
template <class c>
rge<c> range(c i, c j) {
return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
~debug() { cerr << endl; }
template <class c>... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long pascal[4005][4005], arr[4005][4005];
long long eq[4005];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= n; j++) {
if (j == 0) {
pascal[i][j] = 1;
} else {
pascal[i][j] = 0;
}
... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9;
const double eps = 1e-9;
const double pi = acos(-1.0);
const int mod = (int)1e9 + 7;
int k, n;
int a[100100];
vector<int> v;
int M[100100];
int id;
int fact[100100], invfact[100100];
int d[1111][1111];
bool isHappy(int x) {
while (x > 0) {
if... | 13 |
#include <bits/stdc++.h>
using namespace std;
vector<int> v[100005];
int height[100005], parent[100005][20];
void dfs(int node, int par) {
parent[node][0] = par;
for (int i = 1; i < 20; i++)
parent[node][i] = parent[parent[node][i - 1]][i - 1];
height[node] = height[par] + 1;
for (int i = 0; i < v[node].siz... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int N;
map<char, long long int> azul;
for (int i = 0; i < 26; i++) {
azul[65 + i] = 0;
azul[97 + i] = 0;
}
for (int i = 0; i < 10; i++) {
azul[i] = 0;
}
string line;
getline(cin, line);
N = 0;
for (int i = 0; i < line.l... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
return b ? gcd(b, a % b) : a;
}
bool cmp(int i, int j) { return i > j; }
int main() {
int k, r;
cin >> k >> r;
int ans = 1;
int i = 1;
while (1) {
if ((k * i) % 10 == 0 || (k * i) % 10 == r) break;
i+... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
unsigned long a, b, c;
cin >> a >> b;
c = min(a, b);
a = 1;
for (b = 1; b <= c; b++) {
a = a * b;
}
cout << a << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
long long tc, cn = 0, k, n;
long long a[25];
long long m(long long a) {
if (abs(a) > 1000000007) a %= 1000000007;
return a;
}
long long inv[30];
long long ep(long long a, long long p) {
int x = a;
if (inv[a] != -1) return inv[a];
long long res = 1;
while (p) {
... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
string s1, s2, s3, test;
cin >> s1 >> s2 >> s3;
int t;
bool flag1, flag2, flag3;
cin >> t;
s1.erase(remove(begin(s1), end(s1), ';'), s1.end());
s1.erase(remove(begin(s1), end(s1), ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long n;
cin >> n;
long long a[n][2], miin = INF, maax = -INF;
for (long long i = 0; i < n; i++) {
cin >> a[i][0] >> a[i][1];
miin = min(miin, a[... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 7;
const long long mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n;
int a[N];
int foo(int l, int r) {
if (l > r) return 0;
int cur = r - l + 1;
int mn = 1e9;
for (int i = l; i <= r; i++) {
mn = min(mn... | 14 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int maxn = 5e5 + 10;
struct Node {
int x, id;
} a[maxn];
int n, c1[maxn], c2[maxn];
int lowbit(int x) { return x & (-x); }
int sum(int c[], int x) {
int ret = 0;
for (int i = x; i; i -= lowbit(i)) ret = (ret + c[i]) % mod;
return... | 15 |
#include <bits/stdc++.h>
using namespace std;
int dp[1002][1002];
int x, y, n, d2;
bool used = false;
int v[21][2];
int conv(int x) { return x + 500; }
int solve(int x, int y) {
if (x * x + y * y > d2) {
return 0;
}
if (dp[conv(x)][conv(y)] != -1) return dp[conv(x)][conv(y)];
for (int i = 0; i < n; i++) {
... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 100;
const int maxm = 5e5 + 10;
const long long INF = 1e18;
long long powmod(long long x, long long y) {
long long t;
for (t = 1; y; y >>= 1, x = x * x % mod)
if (y & 1) t = t * x % mod;
return t;
}
long long gcd(lon... | 15 |
#include <bits/stdc++.h>
using namespace std;
int a[101][101];
int main() {
int K;
scanf("%d", &K);
int tot = 0;
int v = 2;
while (tot < K) {
for (int i = 1; i < v && (tot + (i - 1)) <= K; i++) {
a[i][v] = a[v][i] = 1;
tot += (i - 1);
}
v++;
}
v--;
printf("%d\n", v);
for (int i... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 10005, M = 30000, inf = 1e9;
int n, m, s, e, pnt[M * 2], nxt[M * 2], col[M * 2], head[N], E = -1;
void add(int u, int v, int w) {
pnt[++E] = v;
nxt[E] = head[u];
head[u] = E;
col[E] = w;
}
struct edge {
int to, cap, rev;
};
vector<edge> g[N + M];
voi... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
struct node {
long long x, y;
} s[maxn];
bool cmp(node a, node b) {
if (a.x < b.x)
return true;
else if (a.x == b.x) {
if (a.y < b.y) return true;
}
return false;
}
int main() {
long long n;
while (cin >> n) {
long long an... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
long long tot;
long long a[310], at[310];
int nxt[310], pre[310];
bool vis[310];
int tac = 0;
long long md = 1e9 + 7;
long long d[310][100010];
int main() {
scanf("%d%d%I64d", &n, &m, &tot);
for (int i = 0; i < n; i++) {
scanf("%I64d", &at[i]);
nxt[i] ... | 13 |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("AAtest.in.txt");
long long n, k, l, o;
int main() {
ios::sync_with_stdio(0);
cin.tie();
cout.tie();
cerr.tie();
cin >> n >> k;
o = 1;
l = (n - k) / 2 + 1;
o %= l;
for (int i = 0; i < n; i++) {
if (o)
cout << 0;
else
cout <... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string letter;
cin >> letter;
for (int i = 0; i < letter.length(); i++) {
if (letter[i] == 'A' || letter[i] == 'I' || letter[i] == 'O' ||
letter[i] == 'U' || letter[i] == 'Y' || letter[i] == 'E' ||
letter[i] == 'a' || letter[i] == 'i' ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string s;
cin >> n >> s;
int flag = 0;
for (int i = 0; i < n; i++) {
if ((s[i] == 'a' || s[i] == 'e' || s[i] == 'o' || s[i] == 'i' ||
s[i] == 'u' || s[i] == 'y')) {
if (flag == 0) {
cout << s[i];
flag = 1;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int read() {
int f = 1, x = 0;
char s = getchar();
while (s < '0' || s > '9') {
if (s == '-') f = -1;
s = getchar();
}
while (s >= '0' && s <= '9') {
x = x * 10 + s - '0';
s = getchar();
}
return x * f;
}
int n, m, i, j, k, s, o;
int a[1005][7]... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 3;
vector<int> res[N];
int main() {
int n;
cin >> n;
int ans = 0;
int l = 0, r = N;
while (l <= r) {
int mid = (l + r) / 2;
if ((mid * (mid - 1)) / 2 <= n)
ans = mid, l = mid + 1;
else
r = mid - 1;
}
int cur = 1;
c... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, b, i, c = 0, d = 0;
cin >> n;
for (i = 0; i < n; i++) {
cin >> a >> b;
if (a > b) c++;
if (b > a) d++;
}
if (c > d)
cout << "Mishka";
else if (d > c)
cout << "Chris";
else
cout << "Friendship is magic!^^";
retur... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
for (int i = 1; i <= t; i++) {
int r, b, g;
cin >> r >> b >> g;
if (r + b + 1 >= g && g + b + 1 >= r && r + g + 1 >= b)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int n;
int a[100005];
int pre[100005];
int main() {
int t1, t2;
int temp;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
t1 = upper_bound(a, a + i, a[i] - 90) - a;
t2 = upper_bound(a, a + i, a[i] - 1440) - a;
if (pre[i] - pre[t1]... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
string str[2];
int dist[2][100005];
int main() {
cin >> n >> k >> str[0] >> str[1];
queue<pair<int, int> > q;
q.push(make_pair(0, 0));
memset(dist, -1, sizeof(dist));
dist[0][0] = 0;
while (!q.empty()) {
int s = q.front().first, h = q.front().secon... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 155, M = 2055;
const int P = 51123987;
int n;
char s[N];
int last[5];
int f[N][55][55], g[N][55][55], Nxt[N][4];
inline void Add(int &x, int k) {
k %= P;
x = (x + k) % P;
}
int main() {
scanf("%d", &n);
scanf("%s", s + 1);
last[0] = last[1] = last[2]... | 17 |
#include <bits/stdc++.h>
using namespace std;
int T, n, i, j, k, a[30005], l, r, mi[30005];
int main() {
scanf("%d", &T);
while (T--) {
scanf("%d", &n);
for (i = 1; i <= n; i++) scanf("%d", &a[i]);
l = 1;
while (l < n && a[l + 1] <= a[l]) l++;
r = n;
while (r > 1 && a[r - 1] <= a[r]) r--;
... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long n, k;
long long a[1000000];
vector<long long> indexx[1000000];
long long c[1000000];
long long e;
long long v[1000000];
struct wavelet {
long long L, R;
vector<long long> b;
};
wavelet tree[1000000];
void init(long long node, long long *pl, long long *pr, long... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int NN = 1e5 + 3;
vector<vector<int>> g(NN), gr(NN);
int used[NN];
vector<int> cnt;
void dfs(int v) {
used[v] = 1;
for (const auto& to : g[v])
if (!used[to]) dfs(to);
cnt.push_back(v);
}
int pr[NN];
int sz[NN];
int used1[NN];
vector<vector<int>> gg(NN);
int ... | 11 |
#include <bits/stdc++.h>
using namespace std;
int w[300001], k;
long long dp[300001], mx = -1e9;
vector<int> adj[300001];
bool vis[300001];
void dfs(int x) {
vis[x] = 1;
dp[x] = w[x];
for (int i = 0; i < adj[x].size(); i++) {
if (vis[adj[x][i]]) continue;
dfs(adj[x][i]);
if (dp[adj[x][i]] > 0) dp[x] +... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 100000;
vector<int> divi[MAX + 5];
int tdivs[3 * MAX + 5], divs[3 * MAX + 5];
int dp[8][405], ndp[8][405];
int poss[405];
int memo[8][8];
int main() {
for (int i = 0; i < 8; ++i)
for (int j = 0; j < 8; ++j) {
int pos2 = 0;
if ((i & 1) && (j... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n;
cin >> n;
int a = 1;
int b = 1;
string name = "";
for (int i = 1; i <= n; i++) {
while (i <= n && i < a) {
name += 'o';
i++;
}
if (i <= n) {
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int a, b, c, d, i, j, k, l, m, n, p, q, r, u, w, e, f, g, h, t,
ct = 0, ct1 = 0, ct2 = 0, ck = 0, ck1 = 0, ck2 = 0, ln, ln1, start, end,
mid;
long long int ans, a1 = 0, a2 = 0, a3 = 0, a4 = 0, b1 = 0, b2 = 0, b3 = 0,
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a[2], b[2];
int num1, num2;
while (cin >> a[0] >> b[0] >> a[1] >> b[1]) {
if (a[0] <= a[1] && b[0] <= b[1]) {
puts("Polycarp");
continue;
}
num1 = a[0] + b[0];
num2 = max(a[1], b[1]);
puts(num1 <= num2 ? "Polycarp" : "V... | 9 |
#include <bits/stdc++.h>
using namespace std;
int qtde[310][310], n, vis[310], ok;
vector<int> adj[310], path[310][310], vet;
void dfs(int u, int p) {
vis[u] = 1;
vet.push_back(u);
path[p][u] = vet;
for (int i = 0; i < adj[u].size(); i++) {
int v = adj[u][i];
if (!vis[v]) dfs(v, p);
}
vet.pop_back()... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3030;
int n, R, C, K, p, sum, pr[N], nx[N], lx[N];
long long ans;
struct vec {
int x, y;
} a[N];
vector<int> ve[N], in;
bool cmp(int u, int v) {
return a[u].y != a[v].y ? a[u].y < a[v].y : a[u].x < a[v].x;
}
void work(int s) {
in.clear();
for (int i = ... | 22 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e7 + 10, M = 1e6 + 100;
;
long long n, v[N], p[M], w, mu[N], sum[M];
long long cnt[M], pos, tr[N], to[M];
inline long long get1(long long n) {
long long ans = 0;
for (long long l = 1, r; l <= n; l = r + 1) {
r = n / (n / l);
ans += 1ll * (mu... | 19 |
#include <bits/stdc++.h>
int main() {
std::ios::sync_with_stdio(0);
std::cin.tie(0);
std::string s;
std::cin >> s;
std::array<std::vector<int>, 26> sfxsum;
for (int ch = 0; ch < 26; ++ch) {
sfxsum[ch].resize(s.size() + 1);
for (auto idx = s.size(); idx--;)
sfxsum[ch][idx] = sfxsum[ch][idx + 1]... | 10 |
#include <bits/stdc++.h>
using namespace std;
int n;
string q;
int getF1(int l, int r, int cq) {
if (l + 1 == r) {
return l + 1;
}
char f = q[l];
for (int i = l; i < (l + r) / 2; i++) {
if (q[i] == '0') {
q[i] = '1';
} else {
q[i] = '0';
}
}
int nq;
cout << "? " << q << "\n";
... | 12 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.