func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } constexpr long long MAX = 5100000; constexp...
#include <bits/stdc++.h> using namespace std; unordered_map<int, int> mp; int cnt[200005]; int a[200005]; int num[200005]; int l, r, t; int tot = 0; int lz[200005]; int ans[200005]; int A, B; int be[200005]; struct Query { int l, r, id, t; Query() {} Query(int _l, int _r, int _id, in...
#include <bits/stdc++.h> using namespace std; int N, M, K; int Ar[110][110]; int Temp[110][110]; int Dn[110]; int Res = -1; int f() { int rev = 0; for (int i = 1, a, b; i <= N; i++) { a = 0; b = 0; for (int j = 1; j <= M; j++) { a += (Ar[i][j] == Dn[j]); b += (Ar[...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 4; int n, c[maxn]; string s[maxn]; long long dp[maxn][2]; long long best(int ind, bool rev) { if (ind == n) { return 0; } if (dp[ind][rev] != -1) { return dp[ind][rev]; } string t = s[ind - 1]; if (rev) ...
#include <bits/stdc++.h> using namespace std; template <class T> inline T abs(T x) { return x < 0 ? -x : x; } const double EPS = 1e-9; int n, m, a[55], b[55], mx, ans, x; double cur; int main() { scanf( %d , &n); for (int i = 0; i < n; ++i) scanf( %d , a + i); scanf( %d , &m); for (i...
#include <bits/stdc++.h> using namespace std; vector<int> get(int n) { if (n == 1) { return {1}; } if (n == 2) { return {3, 4}; } vector<int> a; if (n % 2 == 0) { int k = n / 2; for (int i = 1; i <= 2 * k - 1; i++) { a.push_back(1); } a.push_back(k...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; string a; vector<string> v, b; bool u = false, l = false; for (int i = 0; i < 4 * n; i++) { cin >> a; int k = 0; u = false; for (int j = (int)a.length() - 1; j >= 0; j--) { if ...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) using namespace std; mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count()); template <typename T> bool uax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template <typename T> bool uin(...
#include <bits/stdc++.h> int query(long long q) { printf( ? %lld n , q); fflush(stdout); int gcd; scanf( %d , &gcd); return gcd; } void printAnswer(int answer) { printf( ! %d n , answer); fflush(stdout); } const int MAX_PRIMES = 617; const int MAX_X = 1000 * 1000 * 1000; const ...
#include <bits/stdc++.h> using namespace std; long long ar[500005]; int main() { int n; scanf( %d , &n); for (int i = 0; i < n; i++) { scanf( %lld , &ar[i]); } string s; cin >> s; long long gain = 0; long long loss = 0; long long bob = 0; for (int i = 0; i < s.length(...
#include <bits/stdc++.h> using namespace std; const int MX = 100 + 3; int n, m, k; bool mat[MX][MX], tmp[MX][MX]; void solve1() { int q = (1 << m); int cnt = 0; int ans = 20; for (int z = 0; z < q; z++) { cnt = 0; memset(tmp, false, sizeof(tmp)); for (int j = 0; j < m; j++) {...
#include <bits/stdc++.h> const int Maxn = 500000; int n; struct Answer { int l, r; } a[Maxn + 5]; int len; void work(int left, int right) { if (left == right) { return; } int mid = (left + right) >> 1; work(left, mid); work(mid + 1, right); for (int i = left; i <= mid; i++)...
#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 { template <class c...
#include <bits/stdc++.h> using namespace std; long long t[100005], T[100005], x[100005], c[100005]; long long n, m; int main() { while (scanf( %lld%lld , &n, &m) != EOF) { int i; int a, b; long long sum = 0; for (i = 1; i <= n; i++) scanf( %lld%lld%lld%lld , &t[i], &T[i], &x[...
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1); struct myHash { template <class T1, class T2> size_t operator()(const pair<T1, T2>& p) const { auto hash1 = hash<T1>{}(p.first); auto hash2 = hash<T2>{}(p.second); return hash1 ^ hash2; } }; class segTree {...
#include <bits/stdc++.h> using namespace std; char ss[100050]; char b[12][12]; int len[12]; int n, m; bool g[100050][11]; bool f[100050][11]; int dp[100050]; struct Node { int a, b; }; int main() { int ll, pos; bool tmp; scanf( %s , ss); n = strlen(ss); scanf( %d , &m); ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; cin >> t; while (t--) { string s1; cin >> s1; int p1 = 0, p2 = 0, c1, c2; set<pair<pair<int, int>, pair<int, int> > > s; int c = 0;...
#include <bits/stdc++.h> using namespace std; long long ans; long long cnt(long long i, long long n, long long count) { long long c = 0, j = i, k = n; while (k / i > 0) { c += k / i; k /= i; } c /= count; return c; } void factorize(long long n, long long p) { long long coun...
#include <bits/stdc++.h> using namespace std; long long N, K; long long s1, s2, p1, p2; long long Get(long long now, long long to) { if (now <= to << 1) return 0; long long re = 0; s1 = 1; s2 = 0; p1 = now; p2 = now - 1; while (p2 >= to << 1) { if (p2 == to << 1) return s1 + re...
#include <bits/stdc++.h> using namespace std; const int maxn = 2000001; int N, M, cur, F, a[maxn], del[maxn]; int c[maxn]; inline int lowbit(int x) { return x & -x; } inline void add(int x, int d) { for (; x < maxn; x += lowbit(x)) { c[x] += d; } } inline int seek(int k) { int ans = 0,...
#include <bits/stdc++.h> using namespace std; int dx[] = {-1, 1, 0, 0}; int dy[] = {0, 0, -1, 1}; long long int sizes[100001]; long long int arr[100001]; bool ok = true; long long int A[100001]; pair<long long int, long long int> B[100001]; long long int root(long long int i) { while (i != arr[i])...
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll mod = 1e9L + 7; const int N = 121, M = 1211; int x[N], y[N]; ll dp[N][M]; ll c[M][M]; int main() { for (int i = 0; i < M; i++) { c[i][0] = 1; for (int j = 1; j <= i; j++) c[i][j] = (c[i - 1][j] + c[i - 1...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops ) #pragma GCC optimize( no-stack-protector,fast-math ) using namespace std; const int N = 5e5 + 100, OO = 724249387, T = 4500 + 100, M = 1e9 + 7, P = 6151, SQ = 280, lg = 30; map<int, int> mp; int dp[N], l[N], r...
#include <bits/stdc++.h> using namespace std; const int MAXL = 1e5; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; long long int k, p; long long int ans = 0; cin >> k >> p; for (int i = 1; i <= k; i++) { int x = i; string str1, str2; while (x...
#include <bits/stdc++.h> using namespace std; std::mt19937 rnd( (int)std::chrono::steady_clock::now().time_since_epoch().count()); long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } const int MAXH = 100000; const int MAXW = 100000; const int MAXDIM = MAXH >= MAXW ? MAXH : M...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; cout << n / 2 * 3 << endl; }
#include <bits/stdc++.h> using namespace std; const double eps = 1e-9; struct _hash { int operator()(const complex<double> &p) const { return p.real() * 20001 + p.imag(); } }; int n; complex<double> p[100]; unordered_set<complex<double>, _hash> pnts; double ans = -1; inline int compare(c...
#include <bits/stdc++.h> using namespace std; const int MAXN = 400; int x[MAXN], y[MAXN]; inline bool lt(int i, int xx, int yy) { return x[i] < xx || (x[i] == xx && y[i] < yy); } inline bool gt(int i, int xx, int yy) { return x[i] > xx || (x[i] == xx && y[i] > yy); } void mysort(int l, int r) { ...
#include <bits/stdc++.h> int main() { int n, i, cnt = 0; float y; scanf( %d , &n); int p[n]; for (i = 1; i <= n; i++) { scanf( %d , &p[i]); cnt += p[i]; } y = (float)cnt / (float)n; printf( %f , y); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; string res = ; if (s.find( . ) == string::npos) { s += . ; } int d = s.find( . ); int i = d - 1; int c = 0; while (i >= 0) { if (s[i] != - ) res = s[i] + res; c++; if (c == ...
#include <bits/stdc++.h> using namespace std; int dp[505][505], dp2[505]; void solve() { int n; cin >> n; vector<int> a(n); for (auto &i : a) cin >> i; memset(dp, 0, sizeof(dp)); for (int i = 0; i < n; i++) dp[i][i] = a[i]; for (int i = 1; i < n; i++) { for (int j = i - 1; j >= 0...
#include <bits/stdc++.h> using namespace std; const long long INF = (long long)1e18; const int mod = (int)1e9 + 7; const int MAXN = (int)1e5 + 5; long long n; const int bs = 350; int a[MAXN]; int mp[600][MAXN]; vector<int> ls[1000]; void swp(int l, int r) { int size = 0, i = 0; vector<int> t...
#include <bits/stdc++.h> using namespace std; int main() { string name; int counter = 0; cin >> name; for (int i = 0; i < name.length() / 2; i++) { if (name[i] != name[name.length() - 1 - i]) counter++; } if (name.length() % 2 == 0) { if (counter == 1) cout << YES n ; ...
#include <bits/stdc++.h> using namespace std; long long modpow(long long a, long long b, long long mod = (long long)(1e9 + 7)) { if (!b) return 1; a %= mod; return modpow(a * a % mod, b / 2, mod) * (b & 1 ? a : 1) % mod; } mt19937 rng(chrono::steady_clock::now().time_since_epoch()...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; if (n == 2 || n == 3 || n == 4 || n == 5 || n == 6 || n == 7) cout << 1 << endl; else if (n % 7 == 1) cout << ((n - 1) / 7) + 1 << endl; else ...
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 1e5 + 5; struct edge { int u, v; ll w; edge(int u, int v, ll w) : u(u), v(v), w(w) {} }; int n, m, k, closestP[N], par[N]; ll d[N], res; bool is1portal; vector<int> portal; vector<edge> adj[N], edges; int...
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n; cin >> n; vector<long long> a(n); long long sums = 0; for (long long i = 0; i < n; i++) { cin >> a[i]; sums += a[i]; } if (sums % 2 == 0) { ...
#include <bits/stdc++.h> using namespace std; int n; string t; map<string, int> mp; int solve(int l, int r) { int val = 0; for (int i = r - 1; i >= l; i--) { if (t[i] == ( ) val++; if (t[i] == ) ) val--; if (!val && (t[i] == + || t[i] == - )) { int L = solve(l, i); ...
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); const double eps = 0.00001; const int MOD = 1000000007; const int INF = 1000055555; const long long LLINF = 1223372000000000555; const int N = 1e5 + 1e4; const int M = 1234; cons...
#include <bits/stdc++.h> using namespace std; const int MAXN = 100010; template <class T, class Comp = less<T> > struct monoqueue { deque<pair<T, int> > dq; Comp comp; int left, right; bool one_index; monoqueue(bool ind1) : dq(), comp(), left(ind1), right(ind1), one_index(ind1) {} ...
#include <bits/stdc++.h> using namespace std; const int N = 200010; bool good[N], need[N]; int n; void ask(vector<int> &v) { printf( %d , (int)v.size()); for (int i = 0; i < (int)v.size(); i++) { printf( %d , v[i]); good[v[i]] = true; } puts( ); fflush(stdout); int idx; ...
#include <bits/stdc++.h> using namespace std; long long a1, a2, b1, b2, c1, c2; struct Point { long long x, y; Point(long long x = 0, long long y = 0) : x(x), y(y) {} }; int exgcd(int a, int b, int& x, int& y) { if (b == 0) { x = 1; y = 0; return a; } int d = exgcd(b, a %...
#include <bits/stdc++.h> using namespace std; string s; int n, ans, x = 201, y = 201, u[405][405]; int main() { scanf( %d , &n); cin >> s; for (int i = 0; i < n; ++i) { ans += u[x][y]; ++u[x][y]; if (s[i] == U ) ++x; if (s[i] == D ) --x; if (s[i] == R ) ++y; if...
#include <bits/stdc++.h> using namespace std; template <class T> bool umin(T& a, const T& b) { return a > b ? a = b, true : false; } template <class T> bool umax(T& a, const T& b) { return a < b ? a = b, true : false; } template <long long sz> using tut = array<long long, sz>; void usaco(str...
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n, m, val, sum = 0; cin >> n; vector<long long> v, q; for (long long i = 0; i < n; i++) { cin >> val; v.push_back(val); sum += val; } ...
#include <bits/stdc++.h> using namespace std; struct vt { int p; int a; int b; }; int main() { int n, index; cin >> n; int a[n + 5], b[200005]; for (int i = 1; i < 200005; i++) { b[i] = 0; } int maxd = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; b[a[i...
#include <bits/stdc++.h> using namespace std; bitset<300000010> su; int main() { su[1] = 1; int l, r, ans = 0; cin >> l >> r; if (l < 3 && r > 1) ans++; for (int i = 3; i * i <= r; i += 2) if (!su[i]) for (long long j = 1LL * i * i; j <= r; j += i << 1) su[j] = 1; while (l % ...
#include <bits/stdc++.h> using namespace std; int power(long long x, unsigned int y, int p) { long long res = 1; x = x % p; if (x == 0) return 0; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } int main() { long long n, p...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10; string s1, s2; int n, m; long long dp[maxn][3][3]; int p1[maxn], p2[maxn]; int f(char a) { return a == G ? 0 : (a == R ? 1 : 2); } void init(const string s, int n, const string t, int m, int p[]) { p[0] = 0; while (p[0]...
#include <bits/stdc++.h> using namespace std; int house[300010]; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; int a, b, c, d; for (int i = 0; i < n; ++i) cin >> house[i]; a = house[0]; d = house[n - 1]; if (a != d) { cout << n - 1 << endl; retu...
#include <bits/stdc++.h> using namespace std; const int dl = 10069; void bib() { for (int i = 0; i < (int)10; i++) { cout << a ; } } const int M = 4 * 3 * 100 * 1000 + 10; int seg[M]; int ans[M / 2]; int n, m; void battle(int s, int e, int winner, int l = 0, int r = n, int id = 1) { ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; int a[510]; int dp[510][510]; int dfs(int l, int r) { if (dp[l][r] != -1) { return dp[l][r]; } if (l > r) { return 0; } if (l == r) { return 1; } int mi = 1 + dfs(l + 1, r); if (a[l] == a...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; cin >> t; while (t--) { long long n, a, b, c, d; cin >> n >> a >> b >> c >> d; int x = 0; if (((c + d) < n * (a - b)) || ((c - d) > n * (...
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, /STACK:36777216 ) template <class T> inline void RD(T &); template <class T> inline void OT(const T &); template <class T> inline T &_RD(T &x) { RD(x); return x; } inline int RD() { int x; return _RD(x); } inl...
#include <bits/stdc++.h> using namespace std; int n, a[1005]; bool t[1005]; int main() { scanf( %d , &n); for (int i = 0; i < n; i++) scanf( %d , &a[i]); memset(t, 0, sizeof(t)); int count = 0; int taken = 0; bool right = true; while (1) { if (right) { for (int i = 0; i...
#include <bits/stdc++.h> using namespace std; int N, speed, limit, t6, ans; stack<int> st; int main() { cin >> N; for (int t, i = 1; i <= N; i++) { scanf( %d , &t); if (t == 6) { t6++; } else if (t == 4) { t6 = 0; } else if (t == 2) { ans += t6; t6...
#include <bits/stdc++.h> using namespace std; int n, t, dp[20][4][4][11][11]; int main() { scanf( %d%d , &n, &t); memset(dp, 0, sizeof(dp)); for (int i = 0; i != 4; ++i) for (int j = 0; j != 4; ++j) dp[1][i][j][0][0] = i != j; for (int i = 2; i != n; ++i) for (int j = 0; j != 4; ++j) ...
#include <bits/stdc++.h> using namespace std; const long long INF = 0x3f3f3f3f; const int N = 2e5 + 10; const int M = 1e6 + 10; const long long mod = 1e9 + 7; const double PI = acos(-1); int sq = 3000; int cntq, cntc; map<int, int> mp; int vis[N]; int cnt[N]; int num[N]; int ans[N]; struct q...
#include <bits/stdc++.h> using namespace std; vector<vector<int> > solve(int N) { vector<vector<int> > res(2, vector<int>(1, 1)); for (int n = 2, r = 0; n <= N; ++n) { res[r].push_back(n); ++r; if (r >= int((res).size())) { vector<int> new_row; for (const vector<int>& r : r...
#include <bits/stdc++.h> using namespace std; const int MAXN = 505; int n, m; int v[MAXN]; int head[MAXN]; double e[MAXN * MAXN]; int a, b, c; int main() { while (scanf( %d%d , &n, &m) != EOF) { for (int i = 1; i <= n; i++) scanf( %d , &v[i]); for (int i = 1; i <= m; i++) { scanf...
#include <bits/stdc++.h> using namespace std; struct debugger { template <typename T> debugger& operator,(const T& v) { cerr << v << ; return *this; } } debug1; template <typename T1, typename T2> inline ostream& operator<<(ostream& os, const pair<T1, T2>& p) { return os << ( ...
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, m, a, b; cin >> n >> m >> a >> b; int ans = 3; if (a % m == 1 && b % m == 0) { ans = min(ans, 1); } if (a % m == 1 || b % m == 0) { ans = min(ans, 2); } ...
#include <bits/stdc++.h> using namespace std; const int N = 2e5; vector<int> g[N]; int deg[N]; int cnt[N]; void dfs(int v, int &l) { for (int i = 0; i < g[v].size(); i++) { cnt[g[v][i]] = l + 1; l++; dfs(g[v][i], l); l--; } } int main() { ios_base::sync_with_stdio(), ...
#include <bits/stdc++.h> using namespace std; template <class T> inline bool getmin(T *a, const T &b) { if (b < *a) { *a = b; return true; } return false; } template <class T> inline bool getmax(T *a, const T &b) { if (b > *a) { *a = b; return true; } return f...
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; int n, m, dis[55][55], fast[55], slow[55], g1, g2, s1, s2; long long f[55][55][55]; bool cang[55], cans[55], canb[55]; long long work(int g, int b, int su, int sd) { memset(f, 0, sizeof(f)); memset(cang, false, sizeof(cang)); mem...
#include <bits/stdc++.h> using namespace std; stack<int> S; int n, m, q, x, y; struct rs_tree { int hed[200005], ver[600005], nxt[600005], tot, cnt; int dep[200005], fa[200005], top[200005], siz[200005], son[200005]; void push(int x, int y) { ver[++tot] = y; nxt[tot] = hed[x]; hed[...
#include <bits/stdc++.h> using namespace std; long long i, j, m, n, p, q, r, ans, l, ch = 1; string s; int f; vector<long long> v; int main() { cin >> s; l = s.size(); f = s.find( bear , 0); while (f >= 0) { p = f + 1; ch = abs(p - ch) + 1; q = p + 3; r = (l - q) + 1;...
#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(); } re...
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-8; const int maxn = 105; int n, m, a, b, c; char mat[maxn][maxn]; void draw(int x, int y, char c) { mat[x][y] = mat[x + 1][y] = mat[x][y + 1] = mat[x + 1][y + 1] = c; } void gao() { if (n * m % 2 == 1) { puts( IMPOSSIBLE )...
#include <bits/stdc++.h> const int pi = acos(-1); const long long MOD = 1000000007; const int M = 100005; const int N = 1000006; using namespace std; int n, m, x, y, ans; string s; char a[55][55]; bool vis[55][55]; vector<string> v; void calc(int i, string s) { if (i == 4) { v.push_back(...
#include <bits/stdc++.h> using namespace std; using namespace std; bool solve(int); int main() { int test = 0; while (solve(test++)) ; return 0; } const int N = 100 * 1000 + 5; const int INF = int(1e9); int n, b, m; pair<int, int> a[N]; struct edge { int to, f, c, rev; }; c...
#include <bits/stdc++.h> using namespace std; int n, m; int a[100]; long long ans; long long getval() { long long val = 0; for (int i = 0; i < n; ++i) { int mn = 100500; for (int j = i; j < n; ++j) { mn = min(mn, a[j]); val += mn; } } return val; } int mai...
#include <bits/stdc++.h> using namespace std; int main() { long long n, t, x, y; long long pos_ji, pos_ou; while (~scanf( %lld%lld , &n, &t)) { while (t--) { scanf( %lld%lld , &x, &y); long long ji = n / 2 * n + (n + 1) / 2 + 1; long long ou = n / 2 * n + 1; pos_ji ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); ; int precision = numeric_limits<double>::digits10; ; int n, a, b; cin >> n >> a >> b; cout << (a + b - 1 + 100 * n) % n + 1; }
#include <bits/stdc++.h> using namespace std; int q, tipe, temp, x, k, s; vector<int> v; set<int> cek; int val[100000 + 5]; map<pair<int, pair<int, int> >, int> temp2; int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } int main() { scanf( %d , &q); while (q--) { ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 200010; pair<double, double> A[MAXN]; int n, r, ord[MAXN], st[MAXN]; bool comp(int a, int b) { if (A[a].first != A[b].first) return A[a].first < A[b].first; return A[a].second < A[b].second; } int ccw(pair<double, double> a, pair<doubl...
#include <bits/stdc++.h> using namespace std; char s[200001], s1[200001]; int n, m, sum, gang, ans[200001], cnt; int main() { scanf( %s , s1 + 1); m = strlen(s1 + 1); for (int i = 1; i <= m; i++) { if (s1[i] == ( || s1[i] == ) ) s[++n] = s1[i]; if (s1[i] == # ) { s[++n] = ) ...
#include <bits/stdc++.h> using namespace std; long long n; long long Tree[1000001]; long long arr[200001]; void add(long long x, long long val) { for (; x <= n; x += x & (-x)) Tree[x] += val; return; } long long get(long long x) { long long sum = 0; for (; x > 0; x -= x & (-x)) sum += Tree...
#include<bits/stdc++.h> #include<unordered_map> using namespace std; typedef long long ll; typedef vector<ll> vll; const ll M = 1000000007; bool compare(vll x, vll y) { if (x[0] < y[0]) { return true; } return false; } void solve() { vector<vll> v(3); ll n1, n2...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; int main() { cin.tie(0), cout.tie(0); ios::sync_with_stdio(false); int t; cin >> t; while (t--) { int u = 0, l = 0, d = 0; string s; cin >> s; for (int i = 0; i < s.size(); i++) { if (s[i] >=...
#include <bits/stdc++.h> using namespace std; int main() { string s, s2; cin >> s; cin >> s2; vector<char> v, t; for (int i = 0; i < s.length(); i++) { v.push_back(s[i]); } vector<char>::iterator it; int i = 0; for (it = v.end() - 1; it >= v.begin(); it--) { t.push_ba...
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; long long n, sum; cin >> n >> sum; long long temp = 0; long long cnt = 0; while (temp < sum) { if (temp + n <= sum) { temp += n; ...
#include <bits/stdc++.h> namespace competitive_programming { inline namespace utility {} namespace debugging {} namespace io {} } // namespace competitive_programming namespace competitive_programming::utility { class timer { private: std::chrono::time_point<std::chrono::steady_clock> begin, end; ...
#include <bits/stdc++.h> using namespace std; int n, m; string s[2000]; string t[2000]; int main() { cin >> n >> m; for (int i = 0; i < n; i++) cin >> s[i]; for (int j = 0; j < m; j++) { bool flag = true; for (int i = 0; i < n - 1; i++) { if (s[i][j] > s[i + 1][j]) { ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long n, m; cin >> n >> m; long long a[n][m], f1 = 0; for (long long i = 0; i < n; i++) { for (long long j = 0; j < m; j++) { cin >> a[i][j]; if (a[i][j] > 4)...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int n, k, i; cin >> n >> k; vector<long long int> num(k + 1); long long int maxi = 1e18; long long int ind = -1; for (i = 1; i <= k; i++) { ...
#include <bits/stdc++.h> using namespace std; const int sz = 2e5 + 10; int pr[sz], si[sz], ar[sz][3]; bool us[sz]; bool comp(int a, int b) { return ar[a][2] > ar[b][2]; } int find_se(int v) { if (pr[v] == v) return v; else { pr[v] = find_se(pr[v]); return pr[v]; } } void un...
#include <bits/stdc++.h> using namespace std; int n, x, y; int a[1000]; bool inrange(int v) { return (v >= x && v <= y); } int main() { ios ::sync_with_stdio(false); cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; a[i] = a[i - 1] + a[i]; } cin >> x >> y; for (int i = ...
#include <bits/stdc++.h> using namespace std; int n, kangaroo[500000]; int main() { cin >> n; for (int _n = n, i = 0; i < _n; ++i) cin >> kangaroo[i]; sort(kangaroo, kangaroo + n); int middle = (n / 2) - !(n % 2); int i = middle, j = n - 1; while (i >= 0 && j > middle) { if (kangaroo...
#include <bits/stdc++.h> using namespace std; const long long int mod = 1e9 + 7; const long double PI = 3.141592653589793; int main() { ios_base::sync_with_stdio(false); long long int t; cin >> t; long long int l = 0, r = 0; set<long long int> le, ri; vector<long long int> v(2e5 + 10); ...
#include <bits/stdc++.h> using namespace std; long long int c[104][104]; long long int dp[104][104 * 104]; long long int mul[104][104]; long long int pw(long long int x, long long int y) { long long int ans(1); while (y) { if (y & 1) ans = (ans * x) % 1000000007; x = (x * x) % 1000000007; ...
#include <bits/stdc++.h> using namespace std; int n, len1, len2, ans; string s; int main() { cin >> n; getline(cin, s), getline(cin, s); while (len1 < s.size()) { len2 = len1 + n - 1; while (len2 > len1) if (s[len2] == . || s[len2] == ? || s[len2] == ! ) { len1 = l...
#include <bits/stdc++.h> using namespace std; const int MAXN = 300005; int n, ip[MAXN], p[MAXN], q[MAXN]; int tree[4 * MAXN], flag[4 * MAXN]; void push(int i, int L, int R) { if (L < R) { flag[2 * i] += flag[i]; flag[2 * i + 1] += flag[i]; } tree[i] += flag[i]; flag[i] = 0; } v...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 5; struct Node { int p; vector<int> v; Node() { p = 0, v = {1}; } inline int size() { return v.size(); } }; vector<int> G[maxn]; int ans[maxn]; void merge(Node& a, Node b) { b.v.push_back(0); if (a.size() < b.size...
#include <bits/stdc++.h> using namespace std; int sad = 0; int* visited; vector<int>* adj; void dfs(int curr, int prev) { visited[curr] = 1; for (auto& e : adj[curr]) { if (e == prev) continue; if (visited[e]) sad++; else dfs(e, curr); } } int main() { int...
#include <bits/stdc++.h> using namespace std; int vis[10100]; int dist[10100]; int pre[10100], cntt[30]; char str[10100]; struct Edge { int u, v, c, cost, next; } edge[1000100]; int anss, head[10100], cnt; void init() { cnt = 0; memset(head, -1, sizeof(head)); } void addedge(int u, int...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 100; char s[N]; int n, m, t[N]; int a[N * 4], b[N * 4], ab[N * 4], ba[N * 4], aba[N * 4], tag[N * 4]; void pushup(int now) { a[now] = max(a[(now << 1)], a[(now << 1 | 1)]); b[now] = min(b[(now << 1)], b[(now << 1 | 1)]); ab[now] =...
#include <bits/stdc++.h> using namespace std; const double eps(1e-8), Inf(1e10); const double pi(3.14159265358979); const int N = 6060; struct point { double x, y; } p[N + N] = {}; int n, q, k = 0, a, b, x[N] = {}; double ans[N] = {}; void init() { cin >> n >> q >> a >> b; for (int i = 1; ...
#include <bits/stdc++.h> int n, m, num; char tab[100][100]; int xx[10000][4]; int yy[10000][4]; int ch[100][100]; int id[100][100]; int getdir(int cd, int dd) { if (cd == 1) return (dd + 1) % 4; else return dd; } int main() { scanf( %d %d , &n, &num); for (int i = 0; i < n;...
#include bits/stdc++.h using namespace std; using ll = long long; using pii = pair<int,int>; using pll = pair<ll,ll>; template<typename T> int sz(const T &a){return int(a.size());} const int MN=601; int dist[MN]; bool used[MN]; int arr[MN][MN]; int main(){ cin.tie(NULL); ios_base::sy...