solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t;
cin >> t;
while (t--) {
long long int L, v, l, r;
cin >> L >> v >> l >> r;
long long int c = L / v;
if (l % v != 0)
c = c - (r / v - l / v);
else
c = c - (r / v - l / v + 1);
cout << c << endl;
}
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
string A;
string prefix;
int prefixFn[100000];
int matches[100000];
void computePrefixFunction() {
int k = 0;
for (size_t q = 1; q < prefix.size(); ++q) {
while (k > 0 && prefix[k] != prefix[q]) {
k = prefixFn[k - 1];
}
if (prefix[k] == prefix[q]) {
... | 12 |
#include <bits/stdc++.h>
using namespace std;
long long n, m;
long long x, y;
long long read() {
long long k = 0, f = 1;
char c = getchar();
while (c > '9' || c < '0') {
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
k = k * 10 + (c - '0');
c = getchar();
}
return k ... | 13 |
#include <bits/stdc++.h>
using namespace std;
double pi = 3.141592653589793238;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int T = 1;
while (T--) {
int n;
cin >> n;
int arr[n];
for (int i = 0; i < n; i++) cin >> arr[i];
if (n <= 2) {
cout << n;
return 0;
}
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
int t[300000];
int a[300000];
int o[300000];
cin >> n;
for (int i = 0; i < n; i++) {
cin >> t[i];
a[t[i] - 1] = i;
}
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < min(n, i + 4); j++) {
int b = (t[j] * 2 - t[i]) -... | 19 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
int n;
int arr[400100];
int main() {
int t;
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", &arr[i]);
if (n == 1) ... | 7 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
int main() {
long long sum = 0;
int n, a, m, k, b, c, d, p, r, i, Ans = 0, mask = 0;
cin >> n;
vector<int> A(n);
for (int i = 0; i < n; i++) scanf("%i", &A[i]);
for (int i = 1 << 29; i; i >>= 1) {
mask |= i;
long long q10 = ... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const int inf = 1 << 29;
char s[N];
int dis[8][N], D[8][8];
int q[N], sum[8][1 << 8], st[N], n;
int func[8][8][1 << 8][1 << 8];
vector<int> v[8];
long long ans[17];
void SSSP(int c) {
static int vis[10];
for (int i = (int)(0); i <= (int)(7); i++) v... | 25 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (!b) return a;
return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return b / gcd(a, b) * a; }
void merge(vector<int> &aa, vector<int> &bb) {
vector<int> ret;
int idx1 = 0, idx2 = 0;
while (ret.size() < 10... | 14 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T SQR(T x) {
return x * x;
}
template <typename T>
inline T MIN(T x, T y) {
return (x < y) ? x : y;
}
template <typename T>
inline T MAX(T x, T y) {
return (x > y) ? x : y;
}
template <typename T>
inline T ABS(T x) {
return (x > 0) ? x :... | 14 |
#include <bits/stdc++.h>
#pragma GCC optimize("-O3")
using namespace std;
const long long N = 1e6 + 5;
void pairsort(long long a[], long long b[], long long n) {
pair<long long, long long> pairt[n];
for (long long i = 0; i < n; i++) {
pairt[i].first = a[i];
pairt[i].second = b[i];
}
sort(pairt, pairt + ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int max_n = 100111, inf = 1000111222;
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
os << "(" << p.first << " " << p.second << ")";
return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> ... | 18 |
#include <bits/stdc++.h>
using namespace std;
int a[100005], bin[100005];
int main() {
int i, n, x;
scanf("%d", &n);
for (i = 0; i < n; ++i) {
scanf("%d", &a[i]);
bin[i] = a[i];
}
sort(bin, bin + n);
int cont = 0;
for (i = 0; i < n; ++i) {
if (bin[i] != a[i]) ++cont;
if (cont > 2) {
... | 5 |
#include <bits/stdc++.h>
char s[120][120];
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) {
scanf("%s", s[i] + 1);
}
int left_x = -1, left_y, bc;
for (int i = 1; i <= n && left_x == -1; i++) {
for (int j = 1; j <= m && left_x == -1; j++) {
if (s[i][j] == 'B') {
... | 0 |
#include <bits/stdc++.h>
const long long inf = 0x3f3f3f3f3f3f3f3LL;
const long long mod = 1e9 + 7;
using namespace std;
template <class T>
void smin(T& a, T val) {
if (a > val) a = val;
}
template <class T>
void smax(T& a, T val) {
if (a < val) a = val;
}
template <typename T>
inline std::ostream& operator<<(std::o... | 7 |
#include <bits/stdc++.h>
using namespace std;
int mat[5201][5201];
int n;
vector<int> factors;
bool eval(int x) {
for (int i = 0; i < (n / x); i++) {
for (int j = 0; j < (n / x); j++) {
int block_val;
for (int k = 0; k < x; k++) {
for (int l = 0; l < x; l++) {
if (k == 0 && l == 0)
... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long int mod = 998244353;
long long int a[2005];
long long int dp[2005][4015];
long long int moves[2005][3];
long long int power(long long int x, long long int y, long long int p) {
long long int res = 1;
x = x % p;
while (y > 0) {
if (y & 1) res = (res * x) ... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
int a[maxn], b[maxn], n;
int heap1[maxn], heap[maxn], ps[maxn], pos[maxn], d[maxn], hs1, hlen;
int cmp(const int &i, const int &j) { return d[i] > d[j]; }
void heapup(int r) {
int q = ps[r], p = q >> 1;
while (p && d[heap[p]] > d[r]) {
ps[he... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e2 + 10;
vector<int> ans[4];
void record(int xa, int ya, int xb, int yb) {
ans[0].push_back(xa);
ans[1].push_back(ya);
ans[2].push_back(xb);
ans[3].push_back(yb);
}
int n, m;
string s1[N][N], s2[N][N];
struct {
deque<int> qc[N][N];
void push(int i... | 16 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7, inv2 = (MOD + 1) / 2;
long double eps = 1e-8;
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, -1, 1};
long double pi = acos(-1.0L);
struct Seg {
long long k, b;
Seg() {}
Seg(long long K, long long B) { k = K, b = B; }
long long gety(int ... | 19 |
#include <bits/stdc++.h>
using namespace std;
int a, b, c, d, e, f, g, h;
int r1, r2, r3, r4;
int main() {
cin >> a >> b >> c >> d >> e >> f >> g >> h;
if (a > h && d > e)
r1 = 1;
else if (a < h && d < e)
r1 = 2;
else
r1 = 0;
if (a > f && d > g)
r2 = 1;
else if (a < f && d < g)
r2 = 2;
... | 9 |
#include <bits/stdc++.h>
using namespace std;
struct MinCostMaxFlow {
static const int MAXV = 20010;
static const int INFf = 1000000;
struct Edge {
int v, cap;
int w;
int rev;
Edge() {}
Edge(int t2, int t3, int t4, int t5) : v(t2), cap(t3), w(t4), rev(t5) {}
};
int V, s, t;
vector<Edge> ... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, x, b, y;
cin >> n >> a >> x >> b >> y;
int s = 0;
if (x > a) {
s = x - a;
} else {
s = n - (a - x);
}
if (b > y) {
s = min(s, b - y);
} else {
s = min(s, n - (y - b));
}
int i = a, j = b;
for (int t = 1; t <= s; t... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 55;
char ss[maxn][3];
int main() {
int n, k;
while (~scanf("%d%d", &n, &k)) {
for (int i = 1; i <= n; i++) {
ss[i][0] = 'A' + i / 10;
ss[i][1] = 'a' + i % 10;
ss[i][2] = '\0';
}
char mid[10];
for (int i = 1; i <= n - k ... | 7 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int p, q, val;
} a[1000050];
bool cmp(node a, node b) { return a.val > b.val; }
int vis[1050], b[1050];
int main() {
int n;
scanf("%d", &n);
int tot = 0;
for (int i = 2; i <= 2 * n; i++)
for (int j = 1; j < i; j++) {
scanf("%d", &a[tot].val... | 5 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const int N = 200010;
int v[N];
int main(void) {
int n, m;
scanf("%d %d", &n, &m);
int c = 0;
set<pair<int, int> > s;
int last = -1;
for (int i = 0; i < n; i++) {
scanf("%d", v + i);
if (v[i] < 0) c++;
if (v[i] < 0 and i... | 10 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e+9 + 7;
const long long MAXN = 2e+3 + 7;
const long long INF = 1e+18;
long long n, m, nx, ny;
string a[MAXN];
long long dx[4] = {1, 0, -1, 0};
long long dy[4] = {0, 1, 0, -1};
long long deg[MAXN][MAXN] = {};
queue<pair<long long, long long> > q;
char... | 12 |
#include <bits/stdc++.h>
using namespace std;
int i, i0, n, m, a[105];
int main() {
scanf("%d", &n);
bool f = 0;
scanf("%d", &a[1]);
for (i = 2; i <= n; i++) {
scanf("%d", &a[i]);
if (a[i - 1] == 1 && a[i] == 1) f = 1;
if (a[i - 1] == 1 && a[i] == 2) m += 3;
if (a[i - 1] == 1 && a[i] == 3) m += ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
multiset<int> s1, s2;
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
int x;
cin >> x;
s1.insert(x);
}
for (int i = 0; i < n - 1; ++i) {
int x;
cin >> x;
s2.insert(x);
s1.erase(s1.find(x));
}
cout << *s1.begin() << end... | 3 |
#include <bits/stdc++.h>
int main() {
int n, k, p1 = 0, p2 = 0, ans = 0;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &k);
if (k == 1) {
ans++;
if (p1 == 0 && p2 == 1) ans++;
}
p2 = p1;
p1 = k;
}
printf("%d", ans);
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int ar[1009], xr[1009], m, pr[1009], n, in;
int chk(int k) {
xr[0] = ar[1];
ar[0] = 0;
int ta, i;
for (i = 2; i <= n; i++) {
xr[i - 1] = ar[i] - ar[i - 1];
ta = xr[(i - 1) % k] + ar[i - 1];
if (ta != ar[i]) return 0;
}
return 1;
}
int main() {
int ... | 4 |
#include <bits/stdc++.h>
template <typename Elem>
Elem max(Elem a, Elem b) {
return a > b ? a : b;
}
template <typename Elem>
Elem min(Elem a, Elem b) {
return a < b ? a : b;
}
long long work(long long a, long long n, long long p) {
long long c = a * n / p;
if (c == 0) {
return max(a, p - a * n);
}
if (... | 22 |
#include <bits/stdc++.h>
const int N = (int)2e5 + 1;
int n, m;
int a[N], ti, ri;
int t[N], r[N], s;
int b[N], bl, br;
int main() {
scanf("%d%d", &n, &m), s = 0;
for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
for (int i = 0; i < m; ++i) {
scanf("%d%d", &ti, &ri);
while (s > 0 && ri >= r[s - 1]) --s;
t... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 9, mod = 1e9 + 7;
long long n, a, b, sum, mn = mod, x;
int main() {
cin >> n;
if (n == 1) {
cin >> x;
return cout << x, 0;
}
for (int i = 0; i < n; i++) {
cin >> x;
sum += abs(x);
if (x >= 0)
a = 1;
else
b = 1;... | 10 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k;
int a[2000];
int b[2000];
int main() {
int temp1, temp2;
long long int ans;
memset(b, 0, 2000 * sizeof(int));
scanf("%d %d %d", &n, &m, &k);
for (int i = 0; i < n; i++) a[i] = i;
for (int i = 0; i <= n - k; i++) {
for (int j = 0; j < k / 2; j++)... | 8 |
#include <bits/stdc++.h>
using namespace std;
function<void(void)> ____ = []() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
};
int_fast64_t Q, L, R;
int pm[100], mu[100];
vector<int> prime;
void mu_table() {
for (int i = 2; i < 100; i++) {
if (!pm[i]) {
mu[i] = -1;
prime.push_bac... | 13 |
#include <bits/stdc++.h>
using namespace std;
int n, a[222222];
int main() {
cin >> n;
if (n % 2 == 0) {
printf("NO\n");
return 0;
}
for (int i = 1; i <= n; i++) {
if (i % 2 == 1) {
a[i] = i * 2 - 1;
a[i + n] = i * 2;
} else {
a[i] = i * 2;
a[i + n] = i * 2 - 1;
}
}... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1000005;
const long long N = 2e5 + 5;
long long n, k, a, b, mx, mn;
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
long long Abs(long long x) { return x < 0 ? -x : x; }
void calc(long long a, long long b) {... | 9 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool chkmin(T &a, const T &b) {
return a > b ? a = b, 1 : 0;
}
template <typename T>
inline bool chkmax(T &a, const T &b) {
return a < b ? a = b, 1 : 0;
}
const int oo = 0x3f3f3f3f;
namespace network_flow {
const int max0 = 3000000, max1 = 1... | 26 |
#include <bits/stdc++.h>
using namespace std;
char polje[300][300];
int bio[300][300], koraci[300][300], n, m, k, limit;
int kX[4] = {0, 0, -1, 1}, kY[4] = {1, -1, 0, 0}, sol;
void bfs(int prvi, int drugi, int broj) {
queue<pair<pair<int, int>, int> > p;
bio[prvi][drugi] = 1;
p.push(make_pair(make_pair(prvi, drug... | 11 |
#include <bits/stdc++.h>
using namespace std;
char s[11111];
struct e {
int x, y;
} v[11111];
bool cmp(e a, e b) { return a.x < b.x; }
int main() {
int a, i, tot, num;
long long ans;
bool p;
scanf("%d", &a);
memset(s, 0, sizeof s);
scanf("%s", s);
p = false, i = 0;
if (*s == '-' || *s == '+' && *(s + ... | 12 |
#include <bits/stdc++.h>
const long long maxn = 1e6;
using namespace std;
vector<vector<int> > adj;
int ans = 0, black = 0, white = 0;
bool vis[200001];
void dfs(int cur, int col) {
if (!vis[cur]) {
vis[cur] = true;
}
if (col)
black++;
else
white++;
for (int i = 0; i < adj[cur].size(); i++) {
... | 20 |
#include <bits/stdc++.h>
using namespace std;
void solve(int test_number);
void pre() {
cout.setf(ios::fixed);
cout.precision(20);
cerr.setf(ios::fixed);
cerr.precision(3);
}
void post() {
fprintf(stderr, "\n");
fprintf(stderr, "Execution time: %Lf", (long double)clock());
}
const int MAXN = 100100;
inline ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long m;
cin >> m;
long long u, v;
vector<vector<bool>> matrix(5, vector<bool>(5, false));
for (long long i = 0; i < m; ++i) {
cin >> u >> v;
u--, v--;
matrix[u][v] = true... | 5 |
#include <bits/stdc++.h>
using namespace std;
const double PI = 3.14159265359;
const double EPS = 1e-6;
const long long INF = ((long long)1 << 60);
const long long P = 1e9 + 7;
int k;
string sol(int a, int b, char start) {
int v = (start == 'G') ? 0 : 1;
vector<vector<int> > cp;
int st_val = v;
while (true) {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3fffffff;
const long long mod = 1000000007;
const int maxn = 18;
int g[maxn][maxn], d[1 << maxn];
int deg[maxn];
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) g[i][j] = inf;
for (int i = 0... | 16 |
#include <bits/stdc++.h>
using namespace std;
#define long long ll
void find() {
int n, k;
cin>>n>>k;
if(n%2 == 0) {
cout<<(k-1)%n+1<<"\n";
return;
}
if(k<=n/2) {
cout<<(k-1)%n+1<<"\n";
return;
}
int val = (k-(n/2)-1)/(n/2)+1;
k += val;
cout<<(k-1)%n+1<<"\n";
}
in... | 4 |
#include <bits/stdc++.h>
const long long M = 1e9 + 7;
const long long MAXN = 3e5 + 5;
using namespace std;
long long dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
vector<bool> is_prime(MAXN, true);
void test_cases() {
long long n;
char c;
string s;
cin >> n >> c >> s;
if (count(s.begin(), s.end(), c) == n) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long n, m = 0, k = 0, j = 0;
bool test = false, test1 = false;
;
long long const N = 1e5 + 7;
long long const oo = 1e5 + 7;
vector<long long> v, v2;
map<pair<long long, long long>, long long> my;
vector<long long> v1[oo];
long long z[oo];
void dfs(long long s) {
if (... | 6 |
#include <bits/stdc++.h>
using namespace std;
char h1, h2, m1, m2;
int format;
int main() {
scanf("%d\n%c%c:%c%c", &format, &h1, &h2, &m1, &m2);
if (format == 24) {
if ((h1 >= '2') && (h2 >= '4')) h1 = '0';
if (h1 > '2') h1 = '0';
} else {
if ((h1 == '1') && (h2 >= '3')) h1 = '0';
if ((h1 == '0') ... | 5 |
#include <bits/stdc++.h>
using namespace std;
void read (int &x) {
char ch = getchar(); x = 0; while (!isdigit(ch)) ch = getchar();
while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();
} const int N = 1e5 + 5, M = N << 1;
int n, m, s, tp = 1, t[N], ok[N], e[N], f[N];
struct qwq { int x, y, o; } a[M];
bool ... | 23 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > incoming[500000 + 5];
int max_b[500000 + 5], max_a[500000 + 5];
int main() {
int i, j, k, n, p, q, r, a, b, c, to_p = 0, to_q = 0;
long long int cnt = 0, ttl = 0;
scanf("%d %d %d %d", &n, &p, &q, &r);
for (i = 1; i <= n; i++) {
scanf("%d ... | 20 |
#include <bits/stdc++.h>
using namespace std;
bool isprime(long long int n) {
for (long long int i = 2; i <= (long long int)sqrt(n); i++) {
if (n % i == 0) return 0;
}
return 1;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int t = 1;
while (t--) {
long long int m, n;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000100;
const int MAXT = 2000;
int mfac[MAXN];
long long tt[MAXN];
int t[MAXN];
long long lv[MAXT];
int nfac[MAXT];
int d[MAXT][MAXT];
map<long long, int> s;
vector<vector<int> > vv;
vector<int> tfac;
long long v(int x) {
int cx = x;
tfac.clear();
wh... | 20 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int a, b, n, p = 0;
cin >> a >> b >> n;
while (a <= n && b <= n) {
if (a > b)
b = b + a;
else
a = a + b;
p++;
}
cout << p << endl;
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
long long int MAXN = 5000001;
const long long int mod = 1000000007;
const long long int INF = INT_MAX;
inline long long int gcd(long long int a, long long int b) {
if (a == 0) return b;
return gcd(b % a, a);
}
inline long long int pow(long long int a, long long int n, l... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int neginf = 0xC0C0C0C0;
using namespace std;
const int N = 2007, M = 1e5;
int tree[2][M << 2];
int query(int l, int r, int f) {
l += 2 * M, r += 2 * M;
int re = 0;
for (; l <= r; l >>= 1, r >>= 1) {
if (l & 1) re += tree[f][l++];... | 14 |
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll; // [9,223,372,036,854,775,807 to -9.....808] 19 digits
typedef long double ld;
#define inc(i, a, b) for (long long int i = a; i <= b; i++)
#define dec(i, a, b) for (long long int i = a; i >= b; i--)
#define fast \
ios_base:... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
long double discriminante;
discriminante = b * b - 4 * a * c;
long double x1, x2;
if (discriminante == 0) {
x1 = (long double)-b / (2 * a);
x2 = (long double)-b / (2 * a);
} else {
x1 = (long double)(-b... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 300000 + 10;
int n, q;
vector<int> G[N];
int ans[N];
int son[N];
int fa[N];
void dfs(int u) {
ans[u] = u;
son[u] = 1;
for (int i = 0; i < G[u].size(); i++) {
int v = G[u][i];
dfs(v);
son[u] += son[v];
}
for (int i = 0; i < G[u].size(); i+... | 11 |
#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>;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
ll n, m;
cin >> n >> m;
... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100100;
int n, m;
long long bal[N];
stack<int> st;
map<pair<int, int>, long long> ans;
int main() {
scanf("%d%d", &n, &m);
while (m--) {
int u, v;
long long d;
scanf(" %d%d%lld", &u, &v, &d);
bal[u] -= d;
bal[v] += d;
}
for (int i =... | 12 |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void smin(T &a, U b) {
if (a > b) a = b;
}
template <typename T, typename U>
inline void smax(T &a, U b) {
if (a < b) a = b;
}
template <class T>
inline void gn(T &first) {
char c, sg = 0;
while (c = getchar(), (c > '9' || c ... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, k;
scanf("%lld %lld", &n, &k);
long long ans;
if (n == 1) {
printf("0\n");
return 0;
}
k = min(k, n / 2);
ans = k * (2 * n - 2 * k - 1);
printf("%lld\n", ans);
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
int f() {
string s;
cin >> s;
s.erase(0, 4);
if (s.size() == 1) {
if (s < "9")
cout << "199" + s << endl;
else
cout << "198" + s << endl;
}
if (s.size() == 2) {
if (s < "99")
cout << "20" + s << endl;
else
cout << "1999" <... | 12 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
template <class T>
T abs(T x) {
return x > 0 ? x : -x;
}
int n;
int m;
int getInt(char c) {
if (isdigit(c))
return c - 48;
else
return c - 55;
}
char getChar(int x) {
if (x < 10)
return (char)(x + 48);
else
... | 12 |
#include <bits/stdc++.h>
using namespace std;
int n, r[17], b[17], R, B;
char c[17];
int dp[(1 << 16) + 10][16 * 16];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> c[i] >> r[i] >> b[i];
R += r[i];
B += b[i];
}
for (int mask = 0; m... | 16 |
#include <bits/stdc++.h>
using namespace std;
map<pair<long long, long long>, pair<long long, long long> > f;
long long n;
pair<long long, long long> dfs(long long mx, long long n) {
if (f[pair<long long, long long>(mx, n)].first)
return f[pair<long long, long long>(mx, n)];
if (n < 10)
return pair<long lon... | 3 |
#include <bits/stdc++.h>
int cnt[5];
char s[300010];
int main() {
int n;
scanf("%d", &n);
scanf("%s", s + 1);
for (int i = 1; i <= n; i++) cnt[s[i] - '0']++;
int need = n / 3;
for (int i = 1; i <= n; i++) {
if (cnt[0] < need && cnt[s[i] - '0'] > need) {
cnt[s[i] - '0']--;
s[i] = '0';
c... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int N = 200005;
char str[N] = {0};
void solve() {
int i = 0, n = 0;
scanf("%s", str);
n = strlen(str);
if (str[0] != str[n - 1]) {
str[0] = str[n - 1];
}
printf("%s\n", str);
}
int main() {
int o = 1;
scanf("%d", &o);
... | 1 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
using namespace std;
void google(int t) { cout << "Case #" << t << ": "; }
bool per_square(long double a) {
if (a < 0) return false;
long long sr = s... | 2 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize(3)
void solve() {
long long n;
cin >> n;
vector<long long> a(n + 1), mi(n + 1);
mi[n] = n;
vector<long long> presum(n + 1, 0);
for (long long i = 1; i <= n; i++) {
cin >> a[i];
presum[i] = presum[i - 1] + a[i];
}
vector<long doub... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t, n, i, j;
cin >> t;
while (t--) {
cin >> n;
long long a[n], sum = 0, d;
for (i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
}
double av = sum / (n * 1.0);
d = (long long)av;
if (d == av)
cout << d ... | 0 |
#include <bits/stdc++.h>
const long long MXN = 1e5 + 1;
const long long MNN = 1e3 + 1;
const long long MOD = 998244353;
const long long INF = 1e18;
const long long OO = 1e9 + 500;
using namespace std;
long long n, m, k, b[MXN];
long long sum;
double ans;
int main() {
cin >> n >> k >> m;
for (int i = 1; i <= n; i++)... | 9 |
#include <bits/stdc++.h>
#pragma GCC optimize(2)
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const long long mod = 998244353;
const long long INF = 1e9 + 7;
const int base = 131;
const double r = 0.57721566490153286060651209;
const double eps = 0.0000001;
int n, m;
int L[1010], R[1010], f... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int FACT_MAX = 2000005;
long long fact[FACT_MAX], fact_inv[FACT_MAX];
long long modpow(long long a, long long n) {
if (n == 0) return 1;
if (n % 2) {
return ((a % 1000000007) * (modpow(a, n - 1) % 1000000007)) % 1000000007;
} else {
return modpow((a * a)... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int contax = 0, contay = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] == 'x') {
contax++;
}
if (s[i] == 'y') {
contay++;
}
}
string k = "";
for (int i = 0; i < abs(contax - contay); i++) {
if... | 4 |
#include <bits/stdc++.h>
using namespace std;
void fastscan(long long &number) {
bool negative = false;
register int c;
number = 0;
c = getchar();
if (c == '-') {
negative = true;
c = getchar();
}
for (; (c > 47 && c < 58); c = getchar()) number = number * 10 + c - 48;
if (negative) number *= -1... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long y, long long m) {
long long r = 1;
for (; y; y >>= 1) {
if (y & 1) r = r * x % m;
x = x * x % m;
}
return r;
}
const long long N = 1e3 + 5, M = 1e9 + 7;
int main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long int n;
cin >> n;
if (n == 0)
cout << "1";
else if (n % 4 == 0)
cout << "6";
else if (n % 4 == 3)
cout << "2";
else if (n % 4 == 2)
cout << "4";
else
cout << "8";
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 3e5 + 20;
const int INFINITE = INT_MAX;
const int MAXNUM = MAX;
template <typename T>
struct SegTree {
struct SegTreeNode {
int l, r;
T val;
T addMark;
};
vector<SegTreeNode> nodes;
T *arr;
int istart, iend, maxIndex;
SegTree() {}
S... | 21 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXN = 200000;
const int MAXM = 200000;
const int MAXX = MAXM;
const int MAXS = 2 * MAXX;
int nf, nm;
long long fx[MAXN], flen[MAXN];
int fcnt[MAXN];
long long mx[MAXM], msz[MAXM];
long... | 17 |
#include <bits/stdc++.h>
int ans[252000], a[510], tot;
void move(int u) {
int t1, t2, t3;
t1 = a[u], t2 = a[u + 1], t3 = a[u + 2];
a[u] = t3, a[u + 1] = t1, a[u + 2] = t2;
}
int main() {
int t, n, i, j, mn, mx, u;
scanf("%d", &t);
while (t--) {
tot = 0;
scanf("%d", &n);
for (i = 1; i <= n; i++) ... | 16 |
#include <bits/stdc++.h>
using namespace std;
long long int power(long long int x, unsigned long long int y) {
long long int res = 1;
while (y > 0) {
if (y & 1) {
res = res * x;
}
y = y >> 1;
x = x * x;
}
return res;
}
long long int powermod(long long int x, unsigned long long int y,
... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200000 + 10;
int ch[MAXN * 10][30];
int val[MAXN * 10];
int sz = 1;
void insert(char s[]) {
int n = strlen(s);
int u = 0;
for (int i = 0; i < n; i++) {
int c = s[i] - 'a';
if (!ch[u][c]) {
val[sz] = 0;
memset(ch[sz], 0, sizeof ch[s... | 9 |
#define _CRT_SECURE_NO_WARNINGS
#pragma GCC Optimize("Ofast")
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <time.h>
#include <unordered_set>
#include <map>
#include <queue>
#include <algorithm>
#include <fstream>
#include <cstddef>
#include <cstdio>
#include <iostream>
#include <memor... | 13 |
#include <bits/stdc++.h>
using namespace std;
char str[3000010];
struct Splay {
int val[3000010], fa[3000010], sz[3000010];
int ch[3000010][2], rt, node_cnt;
inline int init() {
node_cnt = 2;
fa[2] = 1, ch[rt = 1][1] = 2;
return sz[1] = 2, sz[2] = 1;
}
inline int push_up(int x) { return sz[x] = sz... | 20 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int length, req_length;
char input[1000001];
scanf("%d %d", &length, &req_length);
scanf("%s", input);
if (req_length <= (length * 25)) {
char outputString[1000001];
int i = 0;
int j = 0;
while (j < length) {
if (req_length == 0)... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000005;
const int mod = 1e9 + 7;
int dp[maxn][21], r, n, q;
int fr[maxn], is[maxn], tot, prm[maxn];
int main() {
const int N = 1e6;
for (int i = 2; i <= N; i++) {
if (!is[i]) {
prm[++tot] = i;
fr[i] = i;
}
for (int j = 1; j <= t... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
string s;
cin >> n >> k;
cin >> s;
queue<int> Q[26];
vector<bool> ans(n, 1);
for (int i = 0; s[i]; i++) Q[s[i] - 'a'].push(i);
int i = 0;
while (k--) {
while (Q[i].empty()) ++i;
ans[Q[i].front()] = 0;
Q[i].pop();
}
fo... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
while (n--) {
long long c, s;
cin >> c >> s;
long long k = abs(c - s);
long long q = min(c, s);
if (q >= k && (q - k) % 3 == 0)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
long long num = 0, neg = 1;
char c = getchar();
while (!isdigit(c)) {
if (c == '-') neg = -1;
c = getchar();
}
while (isdigit(c)) {
num = (num << 3) + (num << 1) + c - '0';
c = getchar();
}
return num * neg;
}
int n, m... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s, t;
cin >> s >> t;
map<char, int> cnt;
for (int i = 0; i < s.size(); i++) {
cnt[s[i]]++;
}
vector<bool> found(t.size(), false);
int c = 0;
for (int i = 0; i < t.size(); i++) {
if (cnt[t[i]] > 0) {
cnt[t[i]]--;
c++;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, x, y;
cin >> n >> m >> x >> y;
for (int i = x; i > 1; i--) {
cout << i << " " << y << endl;
}
cout << 2 << " " << y - 1 << endl;
cout << 1 << " " << y - 1 << endl;
for (int i = 3; i <= n; i++) {
cout << i << " " << y - 1 << endl;... | 3 |
#include <bits/stdc++.h>
long long int stick[2];
long long int n, resposta;
long long int dividePartes() {
int i;
long long int cont = 0;
if (n % 2 != 0 || n <= 4) {
return cont;
}
stick[0] = 1;
long long int resto = (n - 2) / 2;
stick[1] = resto;
if (resto % 2 == 0) {
cont = 1;
}
cont += (s... | 2 |
#include <bits/stdc++.h>
#define i64 long long
#define sz(a) int((a).size())
#define all(a) a.begin(), a.end()
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define per(i, a, b) for (int i = (b) - 1; i >= (a); --i)
using namespace std;
const int M = 998244353;
struct mint {
int x; mint(int x) : x(x) {}
friend... | 23 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, temp;
int x, y, z;
scanf("%d", &a);
scanf("%d", &b);
scanf("%d", &c);
scanf("%d", &x);
scanf("%d", &y);
scanf("%d", &z);
int left = 0;
if (a > x) {
temp = a - x;
left += (temp >> 1);
}
if (b > y) {
temp = b - y;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
const int mod = 1000000007;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, l, r, x;
cin >> n >> l >> r >> x;
vector<ll> v(n);
for (int i = 0; i < n; i++) cin >> v[i];
int s = (1 << n);
ll ways = 0;
for (int i... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
if (n % 2 == 0 && n >= 1) {
cout << "Mahmoud";
} else
cout << "Ehab";
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1;
int n, ans, f[N], ff[N][26];
string s;
vector<pair<int, string>> g[N];
int match(string t, int len) {
for (int i = 0; i < t.size(); ++i) {
if (t[i] != s[len]) len = ff[len][t[i] - 'a'];
if (s[len] == t[i]) len++;
if (len == s.size()) ans... | 12 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.