func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int n, m, i, j, k, l, a[1000009], b[1000009], p[1000009], ans, cn, t, x, y, z, mx, mn, s; char c[1000009], d[1000009], ch; struct point { int num, pos; } pp[1000009]; bool cmp(point a1, point a2) { if (a1.num == a2.num) { return a1.pos < a2.p...
#include <bits/stdc++.h> using namespace std; const int maxn = 5009; bool f[maxn][maxn], vis[maxn]; int pre[maxn][maxn], a[maxn]; int n, k, v, sum, cnt; inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) f = -1; ch = getchar(); ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; const int INF = 1e8 + 5; const long long mod = 1e9 + 7; const double pi = 3.1415926536; int dx[] = {1, -1, 0, 0, 1, 1, -1, -1}; int dy[] = {0, 0, 1, -1, 1, -1, -1, 1}; int xa, ya, xb, yb, n; vector<pair<int, int> > v; vector<int> r...
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; int n; int q; long long a[201]; multiset<long long> s; int main() { cin >> q; while (q--) { int flag = 0; s.clear(); cin >> n; long long x; for (int i = 1; i <= n; i++) { cin >> x; ...
#include <bits/stdc++.h> using namespace std; int solve() { int n, x; cin >> n >> x; vector<int> inp(n, 0); for (int i = 0; i < n; i++) cin >> inp[i]; for (int i = 0; i < n; i++) { if (inp[i] != x) break; if (i == (n - 1)) return 0; } for (int i = 0; i < n; i++) { if (i...
#include <bits/stdc++.h> using namespace std; int main() { int tc; int n; string str; cin >> n >> tc; cin >> str; vector<char> vc(3); vector<vector<int>> dp(6, vector<int>(n + 1, 0)); vc[0] = a ; vc[1] = b ; vc[2] = c ; int j, a = 0; do { for (int i = 0; i <=...
#include <bits/stdc++.h> using namespace std; struct debugger { template <typename T> debugger& operator,(const T& v) { cerr << v << ; return *this; } } dbg; void debugarr(int* arr, int n) { cout << [ ; for (int i = 0; i < n; i++) cout << arr[i] << ; cout << ] << end...
#include <bits/stdc++.h> using namespace std; const int maxn = (int)1e5 + 1, maxs = 21; int n, m, q, stot, etot, que[maxn], rnk[maxn]; long long bit[maxn], ans[maxn]; struct Point { int x, y; void read() { scanf( %d%d , &x, &y); } bool operator<(Point const &t) const { return x < t.x || (x =...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; scanf( %d%d%d , &a, &b, &c); int n = a * c - b * c; if (n % b > 0) printf( %d n , n / b + 1); else printf( %d n , n / b); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, i; cin >> n; if (n == 1) cout << n; else { cout << n << ; for (i = 1; i < n - 1; i++) cout << i << ; cout << n - 1; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long int a, b = 0; cin >> a; if (a == 0) { cout << 0 ; return 0; } b = a + 1; if (b % 2 == 0) { cout << b / 2; } else cout << b; }
#include <bits/stdc++.h> using namespace std; int n; long long int K; int ans[100]; long long int fib[100]; int main() { scanf( %d%I64d , &n, &K); fib[0] = fib[1] = 1, fib[2] = 2; for (int i = 3; i <= n; i++) fib[i] = fib[i - 1] + fib[i - 2]; for (int i = 1; i <= n; i++) ans[i] = i; for ...
#include <bits/stdc++.h> using namespace std; template <class T> ostream &operator<<(ostream &os, const pair<T, T> &p) { return os << ( << p.first << , << p.second << ) ; } template <class T> ostream &operator<<(ostream &os, const pair<const T, T> &p) { return os << ( << p.first << , << p.s...
#include <bits/stdc++.h> using namespace std; double p[111], q[111]; int main() { int n; cin >> n; for (int i = 0, u; i < n; i++) { scanf( %d , &u); p[i] = u / 100.0; q[i] = 1; } double ans = 0; while (1) { int now = 0; double tmp = 1; for (int i = 0; i ...
#include <bits/stdc++.h> using namespace std; int n; map<int, int> a; void reset() { a.clear(); } void input() { cin >> n; int c; for (int(i) = (0); (i) < (n); ++i) { cin >> c; a[c]++; } } bool check(int s) { for (auto it = a.begin(); it != a.end(); ++it) { double b =...
#include <bits/stdc++.h> using namespace std; long long n, a[100005]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; string s; cin >> s; if (n == 1 && s[0] == 1 ) cout << Yes ; else if (n == 1) cout << No ; else if (n == 2 && s[0] != s[1]) cou...
#include <bits/stdc++.h> using namespace std; vector<int> lefts[2000000], rights[2000000]; vector<pair<pair<int, int>, bool>> lws; int maxleft[2000000]; int maxright[2000000]; int minright[2000000]; vector<int> ans; bool fail = false; int n; int dfs(int v, int needed) { int cur = v; if (maxl...
#include <bits/stdc++.h> using namespace std; int rw, rh, bw, bh; int main() { cin >> rw >> rh >> bw >> bh; int Cred = rh * 2 + rw + 2, Cblue = bh * 2 + bw + 2; int n = Cblue + Cred; if (bw > rw) n += bw - rw; else n += rw - bw; cout << n << endl; return 0; }
#include <bits/stdc++.h> using namespace std; string s[11]; int a[11]; int n, k; int ans = 0x7fffffff; string t[11]; int num[11]; int main() { cin >> n >> k; for (int i = 0; i < n; i++) { cin >> s[i]; } for (int i = 0; i < k; i++) { a[i] = i; } do { for (int i =...
#include <bits/stdc++.h> int main(void) { char s[1000001] = ; int n, n2, x, y, i; scanf( %d , &n); n2 = (n / 7) * 7; while (n2 >= 0) { if ((n - n2) % 4 == 0) break; else n2 = n2 - 7; } if (n2 < 0) printf( -1 n ); else { y = n2 / 7; x = (n...
#include <bits/stdc++.h> using namespace std; int t; int n, d; int a; int main() { cin >> t; while (t--) { cin >> n >> d; cin >> a; long long ans = a; for (int i = 1; i < n; i++) { cin >> a; if (d == 0) continue; if (d > i * a) { d -= i * a; ...
#include <bits/stdc++.h> using namespace std; int a[200000], b[200000]; set<pair<int, int>> se; set<pair<int, int>>::iterator t; int main() { int n, m, d; cin >> n >> m >> d; for (int i = 0; i < n; i++) { cin >> a[i]; se.insert(make_pair(a[i], i)); } int cnt = 0, pos; while...
#include <bits/stdc++.h> const long long INF = 0x3f3f3f3f3f3f3f3fLL; const int inf = 0x3f3f3f3f; const int mod = 998244353; const double eps = 1e-6; void err() { puts( ); } template <typename T, typename... Args> void err(const T &arg, const Args &...args) { std::cout << arg << ; err(args...);...
#include <bits/stdc++.h> using namespace std; const long long maxN = 1e6 + 5; const long long inf = 1e10; const long long mod = 1e9 + 7; long long n; long long ans = 1; long long res[maxN]; void normalSieve(long long n) { for (long long i = 1; i <= n; i++) res[i] = 1; for (long long i = 2; i * i...
#include <bits/stdc++.h> using namespace std; ifstream fin( input.txt ); ofstream fout( output.txt ); bool isPrime(long long int x) { if (x <= 4 || x % 2 == 0 || x % 3 == 0) return x == 2 || x == 3; for (int i = 5; i * i <= x; i += 6) if (x % i == 0 || x % (i + 2) == 0) return 0; return 1; }...
#include <bits/stdc++.h> using namespace std; int main() { int t, n, k, i, j, res[201], max = 0, diff; cin >> t; for (i = 0; i < t; i++) { cin >> n >> k; int x[k]; for (j = 0; j < k; j++) { cin >> x[j]; if (j == 0) { max = x[j]; } if ((j > 0) &...
#include <bits/stdc++.h> using namespace std; const int maxn = 5e5 + 5; int nxt[maxn]; int n, ans, m, l, r; int rmq[maxn][30]; int main() { ios::sync_with_stdio(false); cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> l >> r; nxt[l] = max(nxt[l], r); } for (int i = 0; i <...
#include <bits/stdc++.h> using namespace std; struct vertex { map<char, int> next, go; int p, link; char pch; vector<int> leaf; unordered_set<int> visited; vertex(int p = -1, char pch = -1) : p(p), pch(pch), link(-1) {} }; vector<vertex> t; void aho_init() { t.clear(); t.push_b...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); long long n, a, b, c = 0; cin >> n >> a; for (int i = 1; i <= n; i++) { if (i * n >= a && a % i == 0) c++; } cout << c; }
#include <bits/stdc++.h> using namespace std; bool chk[64] = {false}; int comb[64][8]; char s[128]; int dp[16][128]; char ans[8][32]; int main() { for (int p = 0; p <= 6; p++) for (int q = 0; p + q <= 6; q++) { int r = 6 - p - q; int v = q * 4 + r * 7; chk[v] = true; ...
#include <bits/stdc++.h> using namespace std; long long prime[500001]; bool vis[500001]; bool isPrime(long long x) { for (long long i = 2; i <= sqrt(x); i++) { if (x % i == 0) return false; } return true; } int main() { long long n; int cnt = 0; memset(vis, false, sizeof(vis));...
#include <bits/stdc++.h> using namespace std; inline int gc() { static const int BUF = 1e7; static char buf[BUF], *bg = buf + BUF, *ed = bg; if (bg == ed) fread(bg = buf, 1, BUF, stdin); return *bg++; } inline int ri() { int x = 0, f = 1, c = gc(); for (; c < 48 || c > 57; f = c == - ?...
#include <bits/stdc++.h> using namespace std; template <typename T> T in() { char ch; T n = 0; bool ng = false; while (1) { ch = getchar(); if (ch == - ) { ng = true; ch = getchar(); break; } if (ch >= 0 && ch <= 9 ) break; } while (1) { ...
#include <bits/stdc++.h> using namespace std; signed main() { int n, k, s; cin >> n >> k >> s; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } s = min(s, n * n); vector<vector<int> > dp1(k + 1, vector<int>(s + 1, 1e9)); dp1[0][0] = 0; int ans = 1e9; for (...
#include <bits/stdc++.h> using namespace std; using ll = long long; ll solve(ll n) { --n; ll index = n / 3; ll off = 1; for (; index - off >= 0; off <<= 2) { index -= off; } ll fi = index + off; ll se = off << 1; for (ll place = off >> 2; place >= 1; place >>= 2) { ll t...
#include <bits/stdc++.h> using namespace std; template <class T> void splitstr(const string &s, vector<T> &out) { istringstream in(s); out.clear(); copy(istream_iterator<T>(in), istream_iterator<T>(), back_inserter(out)); } template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; ...
#include <bits/stdc++.h> using namespace std; int a[1000 + 10]; int ret[21][21]; int pool[410], two[100]; int main() { ios::sync_with_stdio(false); memset(a, 0, sizeof(a)); memset(ret, 0, sizeof(ret)); memset(pool, 0, sizeof(pool)); memset(two, 0, sizeof(two)); int n; cin >> n; ...
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; if (a < b) swap(a, b); cout << b << << (a - b) / 2 << endl; }
#include <bits/stdc++.h> using namespace std; struct player { string name; long long point; player() {} player(string n, long long p) { name = n, point = p; } bool operator<(const player &p) const { if (point == p.point) { return name < p.name; } return point > p.point;...
#include <bits/stdc++.h> using namespace std; struct cub { int c, h; } nr[100100]; vector<int> axnorm; vector<pair<int, int> > cul[100100]; struct cmp { bool operator()(pair<int, int> a, pair<int, int> b) { return (a.first > b.first); } }; priority_queue<pair<long long, int> > H[100100...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, net, i, flag, d; string str; cin >> n; net = 0; flag = 0; for (i = 0; i < n; i++) { cin >> d; cin >> str; if ((net == 0) && (str != South )) flag = 1; if ((net == 20000) && (str != North )) ...
#include <bits/stdc++.h> int main() { puts( 1 ); return 0; }
#include <bits/stdc++.h> using namespace std; char s[1200005]; long long num[30][30]; int b[1200005], c[1200005], cnt, tot; long long dp[1200005]; int main() { memset(dp, 0x3f, sizeof dp); int n, m; scanf( %d%d , &n, &m); scanf( %s , s + 1); for (int i = 1; i <= n; i++) { if (i >= ...
#include <bits/stdc++.h> const int MAXN = 1e6 + 5; std::vector<int> G[MAXN]; int f[MAXN][26]; void dfs(int v) { for (register int i = 1; i <= 20; ++i) { f[v][i] = f[f[v][i - 1]][i - 1]; } for (auto x : G[v]) { if (x == f[v][0]) continue; f[x][0] = v; dfs(x); } } int n...
#include <bits/stdc++.h> using namespace std; int a[100005]; int main() { int n, x; cin >> n >> x; long int sum = 0, zz; for (int i = 0; i < n; i++) cin >> zz, sum += zz; if (sum + n - 1 == x) cout << YES n ; else cout << NO n ; return 0; }
#include <bits/stdc++.h> using namespace std; struct qeury { int a, b, c; }; const int N = 5000 + 5; int ans[N][N]; int r[N], cc[N]; int main() { ios_base ::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m, k; cin >> n >> m >> k; vector<qeury> q; int a, b, c; for (...
#include <bits/stdc++.h> using namespace std; const int NMAX = 1e6 + 5; const int MOD = 998244353; long long lgput(long long b, long long p) { long long r = 1; while (p) { if (p & 1) { r = 1LL * r * b % MOD; } p >>= 1; b = b * b % MOD; } return r; } long long ...
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; if (b < a * 2) { cout << NO ; return 0; } cout << YES << n ; for (int i = 0; i < a - 1; i++) cout << 2 << ; cout << b - 2 * (a - 1) << n ; cout << 1 << n ; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 4, Mod = 1e9 + 7; struct Mint { int res; Mint() { res = 0; } Mint(int a) : res(a) {} friend Mint operator+(Mint A, Mint B) { return Mint((A.res + B.res >= Mod) ? (A.res + B.res - Mod) :...
#include <bits/stdc++.h> using namespace std; int main(int argc, char **argv) { ios_base::sync_with_stdio(false); cin.tie(0); ; int n; cin >> n; vector<int> indeg(n); queue<int> deg1; vector<int> xorV(n); for (int i = 0; i < n; i++) { cin >> indeg[i] >> xorV[i]; if (i...
#include <bits/stdc++.h> using namespace std; int main() { long long s, n, in; cin >> n; if (n == 1) cout << 1 << endl << 1 ; else { for (int i = 1; i <= n; i++) { s = i * (i + 1); s = s / 2; if (n < s) { in = i - 2; break; } }...
#include <bits/stdc++.h> using namespace std; unsigned int ip[100005]; unsigned int const one = -1; int main() { int n, k; cin >> n >> k; for (int i = 0; i < n; i++) { unsigned int a, b, c, d; scanf( %u.%u.%u.%u , &a, &b, &c, &d); ip[i] = (a << 24) + (b << 16) + (c << 8) + d; }...
// Murabito-B 21/04/13 #include <bits/stdc++.h> using namespace std; using ll = long long; void solve() { int a, b, c; cin >> a >> b >> c; for (int i = 0; i <= a - c; ++i) cout << 1; for (int i = 1; i < c; ++i) cout << 0; cout << 1 ; for (int i = 1; i < b; ++i) cout << 0; ...
#include <bits/stdc++.h> using namespace std; const long double pi = acos(-1); const long long M = 1e9 + 7; const long long N = 5e5; const long long INF = 1e9 + 1; long long n, a[N], x[N], res, ans; int main() { cin >> n; for (int i = 1; i <= n; ++i) { cin >> a[i]; } for (int j = 1; ...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; long long gcd(long long x, long long y) { return y == 0 ? x : gcd(y, x % y); } long long logg(long long x, long long y) { if (x == 0) return -1; return logg(x / y, y) + 1; } long long poww(long long a, long long b, long long m) {...
#include<bits/stdc++.h> using namespace std; #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define int long long #define line cout<< [At <<__LINE__<< ] <<endl; #define size(x) ((int)x.size()) namespace Debug{ void __print(signed x){cout << x;} void __print(long x){cout << x;} ...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; long long n, s, e, x[5001], a[5001], b[5001], c[5001], d[5001]; long long dp[5001][5001], ans = INF; void init() { for (int i = 0; i < 5001; i++) for (int j = 0; j < 5001; j++) dp[i][j] = INF; cin >> n >> s >> e; for (...
#include <bits/stdc++.h> using namespace std; int n, m, c, a, b; int main() { scanf( %d , &n); while (n--) { scanf( %d%d , &a, &b); if (a != b) if (a > b) m++; else c++; } if (m != c) if (m > c) printf( Mishka ); else prin...
#include <bits/stdc++.h> using namespace std; int main() { stringstream ss; string s; cin >> s; for (int i = 0; i < s.length(); i++) { switch (s[i]) { case > : ss << 1000; break; case < : ss << 1001; break; case + : s...
#include <bits/stdc++.h> using namespace std; const double PI = 2.0 * acos(0.0); const double EPS = 1e-9; const int MOD = 1000000007; const int INF = 1000000000; const long long LINF = 1000000000000000000LL; int main() { int r, h, ret, m, x; scanf( %d %d , &r, &h); r *= 2, h *= 2, ret = h / r ...
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; struct ask { int l, r, cur; } tmp; long long pre[maxn], suf[maxn], s[maxn], d[maxn], h[maxn], ans[maxn]; vector<ask> V, W; int n, m, a, b; long long solve(int l, int r, vector<ask> &V) { if (l == r) return 0; int mid = (l...
#include <bits/stdc++.h> #define int long long #define ld long double #define vc vector #define s second #define f first //#include prettyprint.hpp using namespace std; typedef pair <int, int> pii; int n, m; int t(int a){ return a+n; } int mod=998244353; vc< vc <int> ...
#include <bits/stdc++.h> using namespace std; mt19937_64 mrand(chrono::steady_clock::now().time_since_epoch().count()); int a[105], vis[105]; vector<int> v[105]; int main() { int n; cin >> n; for (int i = 1; i <= 2 * n; ++i) cin >> a[i]; int ans = 0; for (int i = 1; i <= 2 * n; ++i) { ...
#include <bits/stdc++.h> using namespace std; const int o_9357fc8171180e5951f52ff0433bc1c2 = 2e5 + 5; int o_c6e13f5716dd4a7981ad58d262f52b74[o_9357fc8171180e5951f52ff0433bc1c2]; int o_9c41a6fd007fd994071a60164bbac5df[o_9357fc8171180e5951f52ff0433bc1c2]; int o_0f2474e49c5126ff73eea4a0af8b5e21[o_9357fc8171180e5...
#include <bits/stdc++.h> const double PI = acos(-1.0); const int maxn = 1e6; const int INF = 0x3f3f3f; const long long linf = 0x3f3f3f3f3f3f3f3f; const int mod = 1e9 + 7; using namespace std; struct node { int a, b, color; } edge[maxn]; int n, m, ans; int vis[maxn]; vector<int> v[maxn]; void...
#include <bits/stdc++.h> using namespace std; vector<int> A[100005]; int main() { int n, m, i, j; cin >> n >> m; if (n < 4 and m < 4) { bool adj[10][10] = {}, adj2[10][10]; int A[n][m], B[n][m]; for (i = 0; i < n; i++) for (j = 0; j < m; j++) A[i][j] = i * m + j + 1; fo...
#include <bits/stdc++.h> using namespace std; priority_queue<int, vector<int>, greater<int> > q1, q2; int x[200005]; int main() { int n, z, ans = 0; cin >> n >> z; for (int i = 0; i < n; i++) cin >> x[i]; sort(x, x + n); int l1 = n >> 1; for (int i = 0; i < l1; i++) q1.push(x[i]); fo...
#include <bits/stdc++.h> using namespace std; int n, k, m; int a[100000]; int base = int(1e9 + 7); int lucky[2000]; long long co[2000]; long long f[2000][2000]; long long unlucky; long long frac[100001]; long long c[100001]; int size = 1100; int r1, r2; int getBit(int, int); void create(); ...
#include <bits/stdc++.h> using namespace std; long long a[101]; long long vis[101]; long long judge(vector<long long> A) { if (A.empty()) return 0; for (long long i = 0; i < A.size(); i++) { if (A[i] != i) return i; } return A.size(); } signed main() { long long t; cin >> t; ...
#include <bits/stdc++.h> using namespace std; const int N = 1000 + 10; int n, m; int px[] = {0, 1, -1, 0}; int py[] = {1, 0, 0, -1}; bool dig[10]; char a[N][N]; bool inside(int x, int y) { return x >= 0 && y >= 0 && x < n && y < m; } bool alone(int x, int y) { int k, x2, y2; for (k = 0; k < 4;...
#include <bits/stdc++.h> using namespace std; long long a[1000009]; int pre[10000009]; vector<long long> alr; int main() { int n; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); reverse(a, a + n); long long ans = 0, ans1 = 0; int taken = 0; for (int i = 0; i ...
#include <bits/stdc++.h> using namespace std; template <class T> T inline sqr(T x) { return x * x; } template <class T> inline void relaxMin(T &a, T b) { a = min(a, b); } template <class T> inline void relaxMax(T &a, T b) { a = max(a, b); } string str(int i) { char s[100]; spri...
#include <bits/stdc++.h> using namespace std; bool ex[100]; int att[100]; int de[100]; int jo[100]; int n, m, n1, n2; int ae() { int ina = 0; int inb = 0; pair<int, bool> mi[200]; for (int i = 0; i < n1; i++) mi[i].first = att[i], mi[i].second = 0; for (int i = n1; i < n1 + m; i++) { ...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3fll; template <typename T, bool MULTI = false, typename SIZE_T = int> struct sms_mo { static_assert(std::is_integral<T>::value, Not an integral type ); static_assert(std::is_integral<SIZE...
#include <bits/stdc++.h> int a[100]; int main() { int n; scanf( %d%d%d , &a[0], &a[1], &n); for (int i = 2; i <= n; i++) { a[i] = a[i - 1] + a[i - 2]; } printf( %d n , a[n]); }
#include <bits/stdc++.h> using namespace std; template <class T> int chkmax(T &a, T b) { if (b > a) { a = b; return 1; } return 0; } template <class T> int chkmin(T &a, T b) { if (b < a) { a = b; return 1; } return 0; } template <class iterator> void out...
#include <bits/stdc++.h> using namespace std; const int maxn = 5e5 + 100; class Node { public: int l, r; bool operator<(const Node &a) const { return r < a.r; } }; Node n[maxn]; int main() { int N; scanf( %d , &N); for (int i = 0; i < N; i++) scanf( %d%d , &n[i].l, &n[i].r); sort(...
#include <bits/stdc++.h> using namespace std; int a[210][210], n, m, s[110]; bool dop(int x, int y) { return (x >= 0 && y >= 0 && x < 2 * n && y < 2 * m); } void dfs(int x, int y, int cur) { s[cur]++; a[x][y] = cur; if (dop(x + 2, y) && a[x + 1][y] != -1 && a[x + 2][y] != cur) { dfs(x + 2, y, ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 400005; int N; long long T; long long A[MAXN]; long long pre[MAXN]; map<long long, int> mp; int BIT[MAXN]; void add(int idx) { for (; idx < MAXN; idx += idx & -idx) BIT[idx]++; } int get(int idx) { int ret = 0; for (; idx >...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long t, n, r; cin >> t; while (t--) { cin >> n >> r; vector<long long> v(n); set<long long> s; for (int i = 0; i < n; i++) { cin >> v[i]; s.ins...
#include <bits/stdc++.h> using namespace std; int a[100000]; bool b[100000]; int c[3][100000 / 3]; int main() { int n; while (cin >> n) { memset(a, 0, sizeof(a)); memset(b, true, sizeof(b)); bool flag = true; int sum1 = 0; int sum2, sum3; sum2 = sum3 = 0; for ...
#include <bits/stdc++.h> using namespace std; const int mod1 = 1e9 + 7; const int mod2 = 998244353; const long long int inf = 1e18; const double pi = 3.1415926535897932384626; long long int mpow(long long int a, long long int b, long long int m) { long long int res = 1; while (b) { if (b % 2) ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1005; int b[maxn]; int c[maxn]; bool visit[maxn]; int n, k; int main() { int i, p; while (scanf( %d%d , &n, &k) != EOF) { for (i = 1; i <= n; i++) scanf( %d , &b[i]); memset(c, 0, sizeof(c)); memset(visit, false, size...
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll mod = 1e9 + 7; int main() { ios_base::sync_with_stdio(false); int n, m; cin >> n; char prev = a ; int dur = 0; vector<int> durs; for (int i = 0; i < n; ++i) { char c; cin >> c; if (c == W...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e10; const double pi = 3.14159265359; const long long mod = 1743; const long long MAXN = 2 * 1e5 + 6; const long long MAXM = 2 * 1e5 + 6; const long long zero = 0; double v1, v2, e1, e2, h, d, r, area; int main() { ios::sync_with...
#include <bits/stdc++.h> using namespace std; const int N = 3e3 + 10; vector<pair<int, int> > v[N]; int ps[N], mx[N], cnt, wr; void dfs(int u, int par) { for (auto y : v[u]) { if (y.first == par) continue; ps[y.first] = ps[u]; if (y.second == 1) ps[y.first]++; else { ...
#include <bits/stdc++.h> using namespace std; const int modl = 1e9 + 7; string pattern; int n; vector<vector<int>> nums; void init(); int main() { cin >> n; cin >> pattern; init(); vector<vector<int>> dp(n + 1, vector<int>(1 << 20, 0)); for (int i = 0; i <= n; i++) { dp[i][0] = 1...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int INF = 1e9; const long long LNF = 1e18; void setIO(string s) { ios_base::sync_with_stdio(0); cin.tie(0); } const int N = 1e5 + 7; vector<int> adj[N], ans; bool vis[N][2], cvis[N]; bool dfs(int u, int p) { if ...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:256000000 ) using namespace std; struct circle { double x, y, r; circle() {} circle(double x, double y, double r = 0) : x(x), y(y), r(r) {} circle operator+(circle b) { return circle(x + b.x, y + b.y); } circle operator-(circle b) { retu...
#include <bits/stdc++.h> using namespace std; char s[200010]; int T, N; int Solve() { N = strlen(s + 1); int Ans = 0, Len = 1; while ((1 << (Len)) <= N) ++Len; for (register int i = 1; i <= N; ++i) { if (s[i] == 0 ) continue; int p = i, num = 0; while (p > 1 && s[p - 1] == 0 ...
#include <bits/stdc++.h> using namespace std; const int N = 5555; int t[N], l[N], r[N], x[N], a[N], dif[N]; int main() { int n, m; scanf( %d %d , &n, &m); for (int i = 0; i < m; ++i) { scanf( %d %d %d %d , t + i, l + i, r + i, x + i); --l[i], --r[i]; } for (int i = 0; i < n; ++i)...
#include <bits/stdc++.h> using namespace std; inline long long rin() { long long s = 0; bool bj = false; char c = getchar(); for (; (c > 9 || c < 0 ) && c != - ; c = getchar()) ; if (c == - ) bj = true, c = getchar(); for (; c >= 0 && c <= 9 ; c = getchar()) s = (s << 1) ...
/* -------------------- | LOSER | | ~NOOBOSS~ | -------------------- */ #include <bits/stdc++.h> using namespace std; #define mxx 1e18 #define mnn -1e18 #define Y() cout<< YES <<endl #define N(...
#include <bits/stdc++.h> using namespace std; vector<vector<int> > v(14 + 1); int go[1001][14], fail[1001], weight[1001], nxt, maxLength; pair<int, long long> a[1001]; long long dp[1001][(1 << 14)]; const long long negativeInfinity = LLONG_MIN / 2; void AddStringToAhoCorasick(string s, int val) { int ...
#include <bits/stdc++.h> using namespace std; int dp[100010][3]; vector<int> v; int n; int solve(int i, int op, int last) { if (i == n) { return 0; } if (dp[i][op] != -1) { return dp[i][op]; } int ans = 0x3f3f3f3f; int aux = op; if (aux == 2) { aux = -1; } ...
#include <bits/stdc++.h> using namespace std; int main() { string s, p; cin >> s; int sz = s.size(); for (char ch = a ; ch <= z ; ch++) { for (int i = 0; i <= s.size(); i++) { p = s.substr(0, i) + ch + s.substr(i, sz); if (p == string(p.rbegin(), p.rend())) { cout <...
#include <bits/stdc++.h> using namespace std; const int NM_MAX = 82; const int U_MAX = 6404; int U; vector<int> edges[U_MAX]; short int C[U_MAX][U_MAX]; short int R[U_MAX][U_MAX]; short int F[U_MAX][U_MAX]; int dist[U_MAX]; int parent[U_MAX]; queue<int> q; bool BellmanFord() { for (int i = 1...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; vector<int> a(2 * n); for (auto &it : a) cin >> it; vector<int> kop(n); vector<int> ARR; for (int i = 0; i < 2 * n; ++i) { if (!kop[a[i] - 1]) { ...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; long long gcd(long long p, long long q) { return q == 0 ? p : gcd(q, p % q); } int to[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; long long n, ans; long long qp(long long a, long long b) { long long s = 1; while (b) { if (b ...
#include <bits/stdc++.h> using namespace std; const long long inf = (1LL << 60); long long dp[1 << 22]; struct node { int x, k, p; } f[110]; int cmp(node x, node y) { return x.k < y.k; } long long ans; int main() { int n, m, b; scanf( %d%d%d , &n, &m, &b); int l = 1 << m; for (int i ...