func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int main() { int n, x = 4, y = 5; scanf( %d , &n); if (n == 1 || n == 2) { cout << 1; return 0; } while (y < n) { if (x & 1) x = 2 * y, y = x + 1; else x = 2 * y - 1, y = x + 1; } printf( %d , (x == n |...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long INFF = 0x3f3f3f3f3f3f3f3fll; const long long M = 1e9 + 7; const long long maxn = 1e6 + 7; const double pi = acos(-1.0); const double eps = 0.0000000001; long long gcd(long long a, long long b) { return b ? gcd(b, a...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> arr(n); for (int i = 0; i < n; i++) { cin >> arr[i]; } int m; cin >> m; while (m--) { int k, pos; cin >> k >> pos; pos--; vector<vector<int>> ans(k); vector<lon...
#include <bits/stdc++.h> using namespace std; void Fast() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } void File() {} using ll = long long; using ull = unsigned long long; ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); } const int N = 100001; bool prime[N]; int n,...
#include <bits/stdc++.h> using namespace std; int n, k, cnt; pair<int, int> Ans[100010]; int main() { scanf( %d%d , &n, &k); if (k == 1 || k > 3 || n <= 3 || (k == 2 && n == 4)) { puts( -1 ); return 0; } if (k == 2) { printf( %d n , n - 1); for (int i = 1; i < n; i++) pri...
#include <bits/stdc++.h> #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) #pragma GCC optimize( unroll-loops ) #pragma GCC optimize( Ofast ) #pragma GCC optimize( O3 ) #pragma GCC target( avx ) using namespace std; long long fpow(long long x, long long y, long long m) { lo...
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; const double eps = 1e-6; const int inf = 0x3f3f3f3f; const long long INF = 100000000000000000ll; const int MAXN = 4004; const int MAXM = 300030; int dp[MAXN][MAXN]; int main() { int n; cin >> n; dp[0][0] = 1; for...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; string second; cin >> n >> second; int i; int p = 0; for (i = 0; i < n; i++) { if (second[i] == 8 ) p++; } int m = (n - p) / 10; if (p > m) { co...
#include <bits/stdc++.h> using namespace std; int n, u, v, c, a[100005], b[100005]; vector<int> adj[100005]; int mod_pow(int a, int b) { int rtn = 1; while (b) { if (b & 1) rtn = (1ll * rtn * a) % 1000000007; a = 1ll * a * a % 1000000007; b /= 2; } return rtn; } void dfs(in...
#include <bits/stdc++.h> template <typename T> class IntegerIterator { public: using value_type = T; using difference_type = std::ptrdiff_t; using pointer = T *; using reference = T; using iterator_category = std::input_iterator_tag; explicit IntegerIterator(T value) : value(value) {} ...
#include <bits/stdc++.h> using namespace std; void solve() { int a = 1, l = -1, r = -1; string s; for (int i = 1; i <= 30; i++) { cout << ? << (1 << i) << << (1 << (i - 1)) << endl; cin >> s; if (s == x ) { continue; } else { l = (1 << (i - 1)) + 1; ...
#include <bits/stdc++.h> int main() { int x, y = 0, i = 1, j = 1, n = 0, q, a[102]; scanf( %d , &x); for (i = 1; i <= x; i++) { scanf( %d , &a[i]); if (a[i] > y) y = a[i]; } for (i = 1; i <= x; i++) { q = y - a[i]; n = n + q; } printf( %d n , n); return 0; } ...
#include <bits/stdc++.h> int a[128][128], v[128], cor[128], bucket[128]; int m, n; int main() { scanf( %d%d , &n, &m); for (int i = 1; i <= m; ++i) { scanf( %d , &v[i]); cor[i] = 1; for (int j = 2; j <= n; ++j) { int x; scanf( %d , &x); if (x > v[i]) { v...
#include <bits/stdc++.h> using namespace std; const int Mo = 998244353; const int N = 2e5 + 50; const int md = 998244353; inline void add(int &x, int y) { x += y; if (x >= md) { x -= md; } } inline void sub(int &x, int y) { x -= y; if (x < 0) { x += md; } } inline i...
#include <bits/stdc++.h> using namespace std; struct v3 { int x, y, z, i; v3 cross(const v3& rhs) { return {y * rhs.z - z * rhs.y, -(x * rhs.z - z * rhs.x), x * rhs.y - y * rhs.x}; } long long dot(const v3& rhs) { return x * rhs.x + y * rhs.y + z * rhs.z; } }; vector<pair<int...
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const int mod = 998244353; void reduce(int &a) { a += a >> 31 & mod; } int Mod(int x) { return x >= mod ? x - mod : x; } long long read() { long long x = 0; int f = 1; char ch = getchar(); for (; !isdigit(ch); ch = g...
#include <bits/stdc++.h> using namespace std; inline void pisz(int n) { printf( %d n , n); } template <typename T, typename TT> ostream &operator<<(ostream &s, pair<T, TT> t) { return s << ( << t.first << , << t.second << ) ; } template <typename T> ostream &operator<<(ostream &s, vector<T> t) { ...
#include <bits/stdc++.h> using namespace std; map<pair<int, int>, int> mp; vector<int> res, low, b; int ask(int l, int r) { if (l == r) return -1; if (l > r) swap(l, r); if ((res[l] | res[r]) == (low[l] | low[r])) return res[l] | res[r]; auto it = mp.find(make_pair(l, r)); if (it != mp.end()...
#include <bits/stdc++.h> using namespace std; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); long long n, k; cin >> n >> k; if (k < (n * n + n) / 2) return cout << -1, 0; long long t = k; k -= (n * n + n) / 2; long long a[n + 1]; for (long long i = 1; i <= n; i++) a[i] = i...
#include <bits/stdc++.h> using namespace std; long long mod = 1000000007; string s; long long dp[1000001][7]; long long f(int idx, int la = 6) { if (idx == s.size()) { if (la == 2) return 0; if (la == 1) return 0; return 1; } if (dp[idx][la] != -1) return dp[idx][la]; long lo...
#include <bits/stdc++.h> using namespace std; int n, s, T, ans; int ar[101]; bool ok[301]; int dp[301][301]; int res[301][301]; int tmp[301][301]; int ways[24][301][301]; vector<int> v; int main() { scanf( %d%d , &n, &T); for (int i = 1; i <= n; i++) { scanf( %d , &ar[i]); ok[ar[...
#include <bits/stdc++.h> int main(void) { char s[1001]; scanf( %s , s); if (s[0] > 64 && s[0] < 91) printf( %s , s); else { s[0] -= 32; for (int i = 0; i < strlen(s); i++) printf( %c , s[i]); } }
#include <bits/stdc++.h> using namespace std; long long n, h; bool ok(long long x) { long long ans = 0; if (x >= 2e9) return 1; if (x <= h) ans = x * (x + 1) / 2; else { ans = h * (h + 1) / 2 + (x - h) * h; long long high = x - h - 1; long long t1 = high / 2, t2 = high - t1...
#include <bits/stdc++.h> using namespace std; long double mm = 0; int xs[4]; int ys[4]; int mxs[4]; int mys[4]; int used[1001][1001]; long double di(int x1, int y1, int x2, int y2) { return sqrt(abs((long double)x1 - (long double)x2) * abs((long double)x1 - (long double)x2) + ...
#include<bits/stdc++.h> #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) #define ll long long #define lb(x) ((x)&-(x)) #define pii pair<int,int> #define vi vector<int> #define pb push_back #define fi first #define se second #define de(x) cout<<#x<< x <<endl...
#include <bits/stdc++.h> using namespace std; vector<vector<int> > al, dist; int n, m; bool done[5000]; vector<int> bfs(const vector<vector<int> >& al, int s) { queue<int> q; vector<int> dist(al.size(), INT_MAX); dist[s] = 0; q.push(s); while (!q.empty()) { int i = q.front(); q...
#include <bits/stdc++.h> using namespace std; const int maxn = 3006; struct arr { int x, y, i; } a[maxn]; int r, c, n, K; int pos[maxn], L[maxn], R[maxn]; long long ans; bool cmpx(arr x, arr y) { if (x.x == y.x) return x.y < y.y; return x.x < y.x; } bool cmpy(arr x, arr y) { if (x.y ...
/*Allah Vorosha*/ #include<bits/stdc++.h> #define ll long long #define ld long double #define pb push_back #define in insert #define rev reverse #define all(x) (x).begin(),(x).end() #define all2(x) (x).rbegin(),(x).rend() #define sz(v) (int)v.size() #define yes cout << YES n #define no cout << ...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 1; long long a[N]; int main() { ios_base::sync_with_stdio(0); int n; cin >> n; priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> q; for (int i = 1; i <...
#include <bits/stdc++.h> int main() { long long int n, m, i, ans = 0, cish, h, sd = 0, c; int q, j; scanf( %d , &q); int a[10][10] = {{0}, {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}, {2, 4, 6, 8, 0}, {3, 6, 9, 2, 5, 8, 1, 4, 7, 0}, ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1001000; const int INF = 1e9; int n, L, U; int head[maxn], nxt[maxn << 1], rdc[maxn << 1], w[maxn << 1], tnt; int prt, rt, asiz; int siz[maxn], mdep[maxn]; int fdep, gdep; int f[maxn], g[maxn], fp[maxn], gp[maxn], dta; int q[maxn], qt, q...
#include <bits/stdc++.h> const double pi = acos(-1.0); const double eps = 1e-9; using namespace std; int k, n1, n2, n3, t1, t2, t3; void solve() { cin >> k >> n1 >> n2 >> n3 >> t1 >> t2 >> t3; set<pair<long long, int>> st[3]; for (int i = 1; i <= 1000; i++) { if (i <= n1) { st[0].ins...
#include <bits/stdc++.h> using namespace std; long long read() { long long ans = 0, f = 1; char c = getchar(); while (c > 9 || c < 0 ) { if (c == - ) f = -1; c = getchar(); } while (c >= 0 && c <= 9 ) { ans = ans * 10 + c - 0 ; c = getchar(); } return ans ...
#include <bits/stdc++.h> using namespace std; const int dx[4] = {0, 0, -1, 1}; const int dy[4] = {-1, 1, 0, 0}; int i, j, x, y, n, m, e[26], b[510][510], l, ans, flag, xx, yy; char c, s[100010]; int main() { scanf( %d%d%d%d , &n, &m, &x, &y); scanf( %s , s); l = strlen(s); ans = 1; prin...
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<vector> using namespace std; int n,m; char s[200009],t[200009]; int f[200009],g[200009]; vector<int> p[30]; int main() { scanf( %d%d ,&n,&m); scanf( %s%s ,s+1,t+1); for(int i=1;i<=n;i++) s[i]-= a -1; ...
#include <bits/stdc++.h> using namespace std; int main() { long long in, temp = 0, t = 0; int casos; cin >> casos; for (int i = 0; i < casos; i++) { cin >> in; temp = in * (in + 1) / 2; for (long long i = 0;; i++) { if ((1 << i) > in) { break; } else { ...
#include <bits/stdc++.h> using namespace std; const long long inf = 1000000007; const int N = 105; int n, m, k, nl, d[N][N], ok; struct point { int x, y; point(){}; point(int x, int y) : x(x), y(y) {} }; string a[N]; vector<point> l[N * N]; int s[N * N], p[N * N]; void input() { cin ...
#include <bits/stdc++.h> using namespace std; long long fpm(long long b, long long e, long long m) { long long t = 1; for (; e; e >>= 1, b = b * b % m) e & 1 ? t = t * b % m : 0; return t; } template <class T> inline bool chkmin(T &a, T b) { return a > b ? a = b, true : false; } template <...
#include <bits/stdc++.h> using namespace std; void ioe() { freopen( in_3.txt , r , stdin); freopen( out_3.txt , w , stdout); freopen( er_3.txt , w , stderr); } struct lex_compare { public: bool operator()(const pair<long long, long long>& lhs, const pair<long long, long...
#include <bits/stdc++.h> using namespace std; void optimise() { ios_base::sync_with_stdio(false); cin.tie(NULL); } long long int mod = 998244353; void normalize(long long int &a) { a = (a + mod) % mod; } long long int modmul(long long int a, long long int b) { a = a % mod; b = b % mod; n...
#include <bits/stdc++.h> using namespace std; const double PI = 3.14159265359; double ans, x, y; int n, zeros, ones; int main() { scanf( %d , &n); for (int i = 0; i < 2 * n; ++i) { scanf( %lf , &y); x -= y - int(y); if (y == int(y)) ++zeros; else ++ones; } ...
#include <bits/stdc++.h> using namespace std; int a[1000005]; long long dp[1000005]; multiset<int> se; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int i, c, j, k, l, m, n, t, r, cnt; int flag = 0; long long ans = 0, an = 0; t = 1; while (t--) { ...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:102400000,102400000 ) using namespace std; template <class _T> inline _T loww(_T n) { return n & (-n); } template <class _T> inline void swapp(_T &x, _T &y) { _T t; t = x, x = y, y = t; } template <class _T> inline _T minn(_T i, _T...
#include <bits/stdc++.h> using namespace std; int a[200010]; int main() { int n; scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %d , &a[i]); for (int i = 1; i <= (n + 1) / 2; i++) { if (i % 2 == 1) { int temp; temp = a[i]; a[i] = a[n + 1 - i]; a[n + 1 - ...
#include <bits/stdc++.h> using namespace std; int a[40][40]; int f[40][40]; int main() { int i, j, k, l, o, n, nn, best, ans, tot, sum, better, tmp; scanf( %d , &n); for (i = 0; i < n; i++) for (j = 0; j < n; j++) scanf( %d , &a[i][j]); nn = (n + 1) / 2; ans = -2000000000; for (i =...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int inch = n / 3; if (n % 3 == 2) inch++; cout << inch / 12 << << inch % 12; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 303; int n; bool eq[N][N]; int dp[N][N]; string s[N]; int main() { cin >> n; int allsum = n - 1; for (int i = 0; i < n; ++i) { cin >> s[i]; allsum += s[i].size(); } for (int i = 0; i < n; ++i) { eq[i][i] = tr...
#include <bits/stdc++.h> using namespace std; int par[21], siz[21]; int root(int a) { while (a != par[a]) { a = par[a]; } return a; } void unionn(int a, int b) { int root_a = root(a); int root_b = root(b); if (root_a == root_b) { return; } if (siz[root_a] < siz[root...
#include <bits/stdc++.h> using namespace std; int w[100005]; long long p[100005]; int e[2005]; int edge(int n) { int ans = n * (n - 1) / 2; if (!(n & 1)) ans += n / 2 - 1; return ans; } int main() { int n, m, q; cin >> n >> m; for (int i = 0; i < m; i++) cin >> q >> w[i]; sort(...
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; inline int add(int a, int b) { if ((a += b) >= mod) a -= mod; return a; } inline int mult(int a, int b) { long long t = 1ll * a * b; if (t >= mod) t %= mod; return t; } inline int dec(int a, int b) { if ((a -...
#include <bits/stdc++.h> using namespace std; int solve(void) { int n, s; cin >> n >> s; set<int> avail; char c; for (int i = 0; i < n; i++) { cin >> c; avail.insert((int)c - a + 1); } int cnt = 1; int ans = *avail.begin(); int prev = ans; avail.erase(avail.begi...
#include <bits/stdc++.h> using namespace std; inline long long mod(long long n, long long m) { long long ret = n % m; if (ret < 0LL) ret += m; return ret; } long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); } long long exp(long long a, long long b, long long m) { i...
#include <bits/stdc++.h> using namespace std; int n, m; int s[100100]; int main() { scanf( %d , &n); if (n % 4 == 2 || n % 4 == 3) puts( -1 ); else { for (int i = 0; i < n / 2; i += 2) s[i] = i + 2, s[i + 1] = n - i, s[n - i - 1] = n - i - 1, s[n - i - 2] = i + 1; i...
#include <bits/stdc++.h> using namespace std; int a[200000]; int main() { int n; cin >> n; for (int i = 0; i < n; ++i) { cin >> a[i]; } sort(a, a + n); int q; cin >> q; for (int i = 0; i < q; ++i) { int m; cin >> m; int l = 0, r = n - 1; while (l <= r)...
#include <bits/stdc++.h> using namespace std; const int N = 1010; int n, m; int g[N][N]; int ans = 0; inline void Solve(int l, int r, int K, int dep) { if (l >= r) return; ans = ((ans) < (dep) ? (dep) : (ans)); int siz = (r - l + 1) / K; if (!siz) ++siz; int last = l, cnt = 0; vector...
#include <bits/stdc++.h> using namespace std; int main() { int n, l, sum = 0; cin >> n; string st; for (l = 0; l < n; l++) { cin >> st; if (st[0] == T ) sum = sum + 4; else if (st[0] == C ) sum = sum + 6; else if (st[0] == O ) sum = sum + 8; e...
#include <bits/stdc++.h> const long long inf = 1000000000; const long long inf64 = inf * inf; const double pi = acos(-1.0); long long Abs(long long x) { return (x >= 0 ? x : -x); } using namespace std; bool solve() { int n; cin >> n; vector<vector<long long> > mat(n, vector<long long>(n)); v...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (b > a) { return gcd(b, a); } if (b == 0) { return a; } return gcd(b, a % b); } long long expo(long long a, long long b, long long mod) { long long res = 1; while (b > 0) { if...
#include <bits/stdc++.h> using namespace std; int main() { int N; string team1 = ; string team2 = ; int team1points = 0; int team2points = 0; cin >> N; while (N--) { string goalTeam; cin >> goalTeam; if (team1 == goalTeam) { team1points++; } else if (t...
#include <bits/stdc++.h> using namespace std; bool possible = 1; void change(char str[], char mask[]) { char best[6]; best[0] = 0 ; for (int i = 0; i < (4); ++i) { for (int d = 0; d < (10); ++d) if (!(i == 0 && d == 0)) { char temp = str[i]; str[i] = (d + 0 ); ...
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); cin.sync_with_stdio(0); int n; cin >> n; vector<vector<int> > p(n); for (int i = 1; i < n; i++) { int tmp; cin >> tmp; p[tmp - 1].push_back(i); } int ans = 0; queue<pair<int, int> > q; q....
#include<bits/stdc++.h> using namespace std; int a, b; bool check(int cnt) { int cnt6 = cnt/6; int cnt2 = cnt/2 - cnt6; int cnt3 = cnt/3 - cnt6; if(cnt2 <= a) { cnt6 -= a-cnt2; } if(cnt3 <= b) { cnt6 -= b-cnt3; } return cnt6 >= 0; } int main() { #ifdef DEBUG a = 0, b = ...
#include <bits/stdc++.h> using namespace std; const long long N = 1e6 + 5; const long long MOD = 1e9 + 7; long long n, ct; long long a[N], vis[N]; vector<long long> g[N]; void dfs(long long k) { if (vis[k]) return; vis[k] = 1; ct++; for (auto it : g[k]) dfs(it); } int32_t main() { ...
#include <bits/stdc++.h> using namespace std; int mx, cnt, k; char s[105]; int main() { while (~scanf( %s , &s)) { k = strlen(s); mx = 0; for (int i = 0; i < k; i++) { for (int j = i + 1; j < k; j++) { cnt = 0; if (s[i] == s[j]) { for (int o = 0; o ...
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; cout << min(a, b) << << (max(a, b) - min(a, b)) / 2; return 0; }
#include <bits/stdc++.h> using namespace std; int vis[2005]; int main() { int n, m, k; char c; scanf( %d%d%d , &n, &m, &k); int ans = 0; for (int i = 0; i < n; i++) { getchar(); int temp = 0; for (int j = 0; j < m; j++) { scanf( %c , &c); if (c == . ) { ...
#include <bits/stdc++.h> using namespace std; const int maxN = 300, maxTreeSize = 1 << 10; struct Tree { private: bool active[maxTreeSize]; int Min[maxTreeSize], Max[maxTreeSize], offset; public: void resize(int n) { offset = 1; while (offset < n) offset *= 2; } void add(i...
#include <bits/stdc++.h> using namespace std; bool Caps(string a) { for (int i = 0; i < a.size(); i++) if (a.at(i) < 65 && a.at(i) > 90) return false; return true; } int main() { long long n, cnt = 0; cin >> n; while (n > 0) { int rem = n % 10; if (rem == 4 || rem == 7) { ...
#include <bits/stdc++.h> using namespace std; const int inf = (int)1e9; const int mod = inf + 7; const double eps = 1e-9; const double pi = acos(-1.0); int n, cnt, m; string second, t; vector<string> g[100]; map<string, int> id; map<int, string> st; bool check(string second, string t) { string...
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b; cin >> n >> a >> b; int ans = a; if (b < 0) { int t = abs(b); while (t--) { --a; if (a == 0) a = n; } } else { while (b--) { ++a; if (a == n + 1) a = 1; } } ...
#include <bits/stdc++.h> using namespace std; map<char, int> U1; map<char, int> U2; map<char, int> U3; int n, len; int panduan(int a) { if (a != len) a = min(a + n, len); else if (a == len && n == 1) a = a - 1; return a; } int main() { cin >> n; string a, b, c; cin >>...
#include <bits/stdc++.h> using namespace std; struct trip { int a, b, c; }; const int MAXINT = 100; int n, temp; vector<int> pos, neg; bool zeros = false; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> temp; if (temp > 0) pos.push_back(temp); else if (t...
#include <bits/stdc++.h> using namespace std; vector<pair<long long int, long long int> > v; long long int indegree[300005]; long long int vis[300005]; long long int parent[300005]; long long int getpar(long long int child) { if (parent[child] == child) return child; else return parent[c...
#include <bits/stdc++.h> using namespace std; int main() { long long int k; cin >> k; string str, s; cin >> str; s = str; for (long long int i = 1; i < k; i++) str = str + s; map<char, vector<long long int>> pos; long long int i = 0; for (auto c : str) { pos[c].push_back(i)...
#include <bits/stdc++.h> using namespace std; const long long M = 100100 * 5; const long long N = 50005; long long m, b, k; map<long long, long long> fre; int v1[M], mmax; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> m; for (int i = 0; i < m; i++) { ...
#include <bits/stdc++.h> using namespace std; vector<int> arr, hgt, res; int n; int func(int i, int j) {} int main() { int a, b, c, d, e, f, g; cin >> a; while (a--) { cin >> b; vector<int> num; for (int i = 0; i < b; i++) { cin >> c; num.push_back(c); } ...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:36777216 ) using namespace std; const int inf = 1 << 30; const long long Inf = 1LL << 62; const int dx[] = {-1, 0, 1, 0, -1, -1, 1, 1, 0}; const int dy[] = {0, 1, 0, -1, -1, 1, 1, -1, 0}; const double eps = 1e-9; const double pi = 3.14159265358979...
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 10, LOG = 23, MAX = 1e6 + 10, M = 1e9 + 7; long long n; long long mark[N], level[N], par[N][LOG + 10], arr[MAX], cnt[N], tavan[MAX]; vector<long long> g[N]; map<pair<long long, long long>, long long> mp; void DFS(long long v) { ma...
#include <bits/stdc++.h> using namespace std; template <class T> inline T MIN_3(T a, T b, T c) { return min(min(a, b), c); } template <class T> inline T MAX_3(T a, T b, T c) { return max(max(a, b), c); } template <class T> inline T BIGMOD(T n, T m, T mod) { long long int ans = 1; long ...
#include <bits/stdc++.h> using namespace std; const int MAX = 1e5 + 5; int n; char a[MAX]; pair<char, int> b[MAX]; int main() { cin >> (a + 1); n = strlen(a + 1); for (int i = 1; i <= n; ++i) { b[i].first = a[i]; b[i].second = i; } sort(b + 1, b + n + 1, [&](const pa...
#include <bits/stdc++.h> using namespace std; using ll = long long; struct Rect { int right, left, top, bottom; int height() { return top - bottom; } int width() { return right - left; } int area() { return (top - bottom) * (right - left); } }; void solve() { int w, h; cin >> w >> h; ...
#include <bits/stdc++.h> using namespace std; const int M = 1e9 + 7; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; vector<long long> L(n), R(n), A(n); for (int i = 0; i < n; ++i) { cin >> L[i]; } for (int i = 0; i < n; ++i) { cin >> R[i]...
#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 <typename T> inline void gn(T &first) { char c, sg = 0; while (...
#include <bits/stdc++.h> using namespace std; const int N = 505; int n, m, qc; bool fd[N][N]; bitset<N> bs1[N][N]; bitset<N> bs2[N][N]; struct query { int x1, y1, x2, y2; int id; }; vector<query> qs; vector<bool> ans; void solve(vector<int>& ids, int tl, int tr) { if (ids.size() == 0) ...
#include <bits/stdc++.h> using namespace std; const int maxn = 2015; const int inf = 1 << 29; int n, h, a[maxn], l[maxn], r[maxn]; double p, dp[maxn][maxn][2][2]; int main() { cin >> n >> h >> p; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); for (int i = 0; i < n; i+...
#include <bits/stdc++.h> using namespace std; int getcom(pair<int, int> a, pair<int, int> b) { vector<int> all; all.push_back(a.first); all.push_back(a.second); all.push_back(b.first); all.push_back(b.second); sort(all.begin(), all.end()); int com = -1; for (int k = 1; k < 4; k++) { ...
#include <bits/stdc++.h> using namespace std; bool solve(string temp, string p) { int i = 0, j = 0; while (i != temp.size()) { if (temp[i] == p[j]) { i++; j++; } else i++; if (j == p.size()) break; } if (i <= temp.size() && j >= p.size()) return true; ...
#include <bits/stdc++.h> using namespace std; const int N = 2e2 + 10, oo = 1e9 + 10, MOD = 1e9 + 7; int n, m; char a[N][N]; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> m; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) cin >> a[i][j]; } if (n % 3 && ...
#include <bits/stdc++.h> using namespace std; int total_operation = 0; bool is_prime(long long n) { if (n == 2) return true; if (n % 2 == 0 || n < 2) return false; for (int i = 3; i * i <= n; i += 2) { if (n % i == 0) return false; } return true; } int countprime_in_range(int n) { ...
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; while (t--) { long long n, a, b; cin >> n >> a >> b; string s = ; char x = a ; for (int i = 0; i < n; i++) { if (i % b == 0) x = a ; s += x; x++; } cout...
#include <bits/stdc++.h> using namespace std; const int MAX = 2e5 + 3; string s, p; int F[MAX][2]; void solve() { cin >> s >> p; F[0][0] = F[0][1] = 0; for (int i = 1; i <= p.size(); ++i) { for (int j = 0; j < 2; ++j) { F[i][j] = F[i - 1][j]; } ++F[i][p[i - 1] - 0 ]; ...
#include <bits/stdc++.h> std::string x; long long getlen(long long r) { long long now = 1, lst = 0, res = 0; int dig = 0; while (now <= r) { res += (now - 1 - lst) * dig; lst = now - 1; now *= 10; ++dig; } res += (r - lst) * dig; return res; } int main() { lon...
#include <bits/stdc++.h> using namespace std; using ll = long long; vector<pair<int, int>> ans; int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; reverse(a.begin(), a.end()); vector<pair<int, int>> an...
#include <bits/stdc++.h> using namespace std; int n, m; int a[1000005], dp1[1000005], dp2[1000005], dp3[1000005]; long long ans; int main(int argc, const char* argv[]) { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m; for (int i = 1; i <= n; ++i) cin >> a[i]; ...
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int mod=1e9+7; inline int addmod(int x) { return x>=mod?x-mod:x; } inline int submod(int x) { return x<0?x+mod:x; } int n,m,q,b[105],c[105],sum[105],f[105][10005],qans[1005],pn; int solve(int x) { memse...
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); int i, n, e; double x1, y1, x2, y2, vmax, t, vx, vy, wx, wy; cin >> x1 >> y1 >> x2 >> y2; cin >> vmax >> t; cin >> vx >> vy; cin >> wx >> wy; double sid; double l = 0.0, r = (double)1e9; double eps = 1e-7;...
#include <bits/stdc++.h> using namespace std; void reshenie() { int n, m; cin >> n >> m; int a[n][n]; for (int i = 0; i < n; ++i) { for (int j = i; j < n; ++j) { a[i][j] = a[j][i] = 0; } } while (m--) { int u, v; cin >> u >> v; --u, --v; a[u][v] = ...
#include <bits/stdc++.h> #pragma GCC optimize( O2 ) using namespace std; const int N = 2e5 + 10; const long long mod = 1e9 + 7; const long long mod2 = 998244353; const long long inf = 8e18; const int LOG = 22; long long pw(long long a, long long b, long long M) { return (!b ? 1 : (b &...
#include <bits/stdc++.h> using namespace std; int mark[200002]; vector<int> pos[11]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int i, l, t, j, cnt, mx, last; bool flag; string s; cin >> t; while (t--) { cin >> l >> s; for (i = 0; i ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int testCases = 1; cin >> testCases; while (testCases--) { long long int n, m; cin >> n >> m; vector<string> array(n); vector<pair<long long int, long long int>> so...