func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; long long int dp[101000]; int main(int argc, char const *argv[]) { int t, a, b, k; scanf( %d%d , &t, &k); dp[0] = 1; for (int i = 1; i <= 100000; i++) { dp[i] = (dp[i] + dp[i - 1]) % 1000000007; if (i >= k) dp[i] = (dp[i] + dp[i - k]) % 100...
#include <bits/stdc++.h> using namespace std; int n; struct SegTree { int L, R, P, DELTA; struct node { int d; bool zero; } v[212345 * 4]; inline void set_zero(int x) { v[x].zero = 1; v[x].d = 0; } inline void fix(int x, int d) { v[x].zero = 0; v[x].d +=...
#include <bits/stdc++.h> using namespace std; const int N = 510; struct node { int x, y; } d[2]; int n, m, T, g[N][N]; int f, len, root, fa[N], size[N], son[N][2], t[4]; int a[N][N][2], b[N][N][2], dt[N], tmp, tmp2, ans; int Abs(int x) { return x > 0 ? x : -x; } void init() { int i, j; for...
#include <bits/stdc++.h> using namespace std; struct car { int c, v; }; bool operator<(car a, car b) { return a.v < b.v; } int main() { ios::sync_with_stdio(false); int n, k, s, t; cin >> n >> k >> s >> t; vector<car> arr(n); for (int i = 0; i < n; i++) cin >> arr[i].c >> arr[i].v; ...
#include <bits/stdc++.h> using namespace std; char t[200003], p[200003]; int a, pos[200003], nt, np; bool check(int mid) { int it = 0; for (int ip = 0; ip < np; ip++) { while (it < nt && (t[it] != p[ip] || pos[it + 1] <= mid)) it++; if (it == nt) return false; it++; } return tr...
#include <bits/stdc++.h> using namespace std; const int N = 1000 + 10; char ch[N]; int a[N][N]; int h[N], l[N]; int n, m; int main() { cin >> n >> m; int tot = 0; for (int i = 1; i <= n; i++) { scanf( %s , ch + 1); for (int j = 1; j <= m; j++) { a[i][j] = ch[j] == * ? 1 :...
#include <bits/stdc++.h> using namespace std; template <typename A, typename B> string to_string(pair<A, B> p); template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p); string to_string(const string& s) { return + s + ; } string to_string(const char* s) { return to_string((...
#include <bits/stdc++.h> using namespace std; int a[200015], n, k, b[100015]; int cmp(int x, int y) { return x < y; } int main() { while (scanf( %d%d , &n, &k) != EOF) { memset(a, 0, sizeof(a)); int ans = 0, flag = 1, t = 0; int m = k; for (int i = 0; i < n; i++) { scanf( %d ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n % 2 == 1) { cout << (n - 1) / 2 << endl; } else { long long x = 1; while (2 * x <= n) { x *= 2; } cout << (n - x) / 2 << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int mark[(10000000 >> 5) + 1]; void sieve() { register int i, j, k; (mark[1 >> 5] |= 1 << (1 & 31)); int n = 10000000; for (i = 2; i <= n; i++) { if (!(mark[i >> 5] >> (i & 31) & 1)) { for (k = n / i, j = i * k; k >= i; k--, j -= i) ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n, 0); vector<int> p(n, 0); for (int i = 0; i < n; i++) { cin >> a[i]; a[i]--; } int x; for (int i = 0; i < n; i++) { cin >> x; p[x - 1] = i; } int ii = 1; wh...
#include <bits/stdc++.h> using namespace std; int s, t, n; string str; bool flag = true, flag1 = true; int main() { scanf( %d , &n); cin >> str; for (int i = 0; i < n; i++) { if (str[i] == R && flag) { s = i; flag = false; } if (str[i] == L && flag1) { ...
#include <bits/stdc++.h> using namespace std; long long INF = -10000000; int main() { long long da, db; cin >> da >> db; if (da == db) { cout << da * 10 << << db * 10 + 1; } else if (da == 9 && db == 1) { cout << da * 10 + 9 << << db * 100; } else if (da == 0 && db == 1) { ...
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> std::istream& operator>>(std::istream& i, pair<T, U>& p) { i >> p.first >> p.second; return i; } template <typename T> std::istream& operator>>(std::istream& i, vector<T>& t) { for (auto& v : t) { i >> v; }...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int c1, c2, c3, c4; cin >> c1 >> c2 >> c3 >> c4; int n, m; cin >> n >> m; int a[n], b[m]; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < m; i++) cin >> b[i]; int sb =...
#include <bits/stdc++.h> using namespace std; char ans[1000000]; int main() { int n, c, k = 1, u = 0, w = 1, h = 0; cin >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; int m = 0; while (w) { u = 0; for (int i = 0; i < n; i++) { if (a[i] == 0) u++; } ...
#include <bits/stdc++.h> using namespace std; int fact(int a) { int res = 1; while (a > 0) { res *= a--; } return res; } int main() { int a, b; cin >> a >> b; cout << fact(min(a, b)); return 0; }
#include <bits/stdc++.h> using namespace std; namespace mine { long long qread() { long long ans = 0, f = 1; char c = getchar(); while (c < 0 or c > 9 ) { if (c == - ) f = -1; c = getchar(); } while ( 0 <= c and c <= 9 ) ans = ans * 10 + c - 0 , c = getchar(); return ans...
#include <bits/stdc++.h> using namespace std; const int MAX = 105; vector<int> adj[MAX]; string s[MAX]; int mark[MAX]; bool cycle; string ans = ; void dfs(int v) { mark[v] = 1; for (int i = 0; i < adj[v].size(); i++) { int u = adj[v][i]; if (mark[u] == 1) cycle = true; if (!m...
#include <bits/stdc++.h> using namespace std; template <class T> ostream& operator<<(ostream& out, const tuple<T>& a) { out << [ << get<0>(a) << ] ; return out; } template <class T, class U> ostream& operator<<(ostream& out, const tuple<T, U>& a) { out << [ << get<0>(a) << << get<1>(a) ...
#include <bits/stdc++.h> using namespace std; int main() { ios ::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (fopen( main.in , r )) freopen( main.in , r , stdin); else if (fopen( something .inp , r )) freopen( something ...
#include <bits/stdc++.h> using namespace std; int d[1234678], a[1234678], ans; int main() { int n, cnt = 0; char c; scanf( %d n , &n); for (int i = 1; i <= n; i++) { scanf( %c , &c); d[i] = (c == R ); } for (int i = 1; i <= n; i++) scanf( %d , &a[i]); ans = 1047483647; ...
#include <bits/stdc++.h> using namespace std; int main() { char a; int b; scanf( %c%d , &a, &b); if ((a == a || a == h ) && (b == 1 || b == 8)) printf( 3 n ); else if (a == a || a == h || b == 1 || b == 8) printf( 5 n ); else printf( 8 n ); }
#include <bits/stdc++.h> using namespace std; const long long NMAX = 1000001; vector<int> v[NMAX]; int tobehappy[NMAX]; void DFS(int node) { if (v[node].size() == 0) tobehappy[node] = 1; for (auto x : v[node]) { DFS(x); tobehappy[node] += tobehappy[x]; } } int main() { int n, i...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 7; int n, u, v, cnt, head[maxn], to[maxn << 1], nex[maxn << 1], deep[maxn], len[maxn], son[maxn], *f[maxn], tmp[maxn], *id = tmp, ans[maxn]; inline int read() { int x = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) { ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; int ans = 0; for (int i = 0; i < n - 1; i++) { int t = 0; while (i + int(pow(2, t)) < n) t++; t = t - 1; a[i + int(pow(2, t))] += a[i]; ...
#include <bits/stdc++.h> #pragma GCC optimize( ...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; string mat[n + 5]; int dp[n + 5][n + 5]; for (int i = 0; i < (n); i++) cin >> mat[i]; memset(dp, 0, sizeof(dp)); if (mat[0][0] == a ) dp[0][0] = 1; for (int i = 1; i < (n); i++) { dp[i][0] = dp...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; map<int, vector<int> > ps; set<int> xs; for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; ps[y].push_back(x); xs.insert(x); } map<int, int> rk; const int INF = 1 << 30; for (i...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; string s; bool x = false, y = false; cin >> s; if (n == 1) { s[0] % 2 ? cout << 1 n : cout << 2 n ; continue; } for (int i = 0; i ...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const long long INF = 4e18; const int inf = 2e9; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int lcm(int a, int b) { return a * b / gcd(a, b); } int a[3005], pos[3005]; int main(void) { int n, i, j, naik = 0; ...
#include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { int n; char s[105][105]; while (~scanf( %d , &n)) { for (int i = 1; i <= n; ++i) scanf( %s , s[i] + 1); vector<pair<int, int> > r; bool rc = true; for (int i = 1; i <= n; ++i) { int j; ...
#include <bits/stdc++.h> using namespace std; const int MaxN = 1e5 + 10; vector<string> tot[MaxN]; int cnt; char s[MaxN]; bool check[MaxN], flag; set<string> ans; int main() { scanf( %s , s); int len = strlen(s); check[len] = 1; for (int i = len - 2; i >= 5; i--) { if (check[i + 2]...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int r, g, b, w; cin >> r >> g >> b >> w; int evens = (r % 2 == 0) + (g % 2 == 0) + (b % 2 == 0) + (w % 2 == 0); int odds = (r % 2 == 1) + (g % 2 == 1) + (b % 2 == 1) + (w % 2 == 1); if...
#include <bits/stdc++.h> using namespace std; int main() { string name; cin >> name; string right = , left = ; int i = 0; for (; true; i++) { if (name[i] == | ) { break; } left += name[i]; } i++; for (; i < name.length(); i++) { right += name[i]; ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 7; pair<double, double> a[MAXN]; double F[MAXN], S[MAXN]; int n, p; bool cmp(pair<double, double> x, pair<double, double> y) { return x.first * y.second > x.second * y.first; } int vt = -1; int main() { ios_base::sync_with_st...
#include <bits/stdc++.h> #include <string> #include <cstdint> #include <iterator> #include <algorithm> #include <fstream> #include <vector> #include <set> using namespace std; using ll = long long; using ld = long double; #define FAST_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.ti...
#include <bits/stdc++.h> const long long P = 1000000000039LL; inline long long mul(long long a, long long b) { long long ans = 0; for (; b; b >>= 1) { if (b & 1) { ans = (ans + a) % P; } a = (a << 1) % P; } return ans; } int k = 0, t = 0; long long fac[10], ifac[10]; ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int n; double r; cin >> n >> r; double X[n]; for (int i = 0; i < n; i++) { cin >> X[i]; } double Y[n]; Y[0] = r; for (int i = 1; i < n; i++) { Y[i] = r; for (int j =...
#include <bits/stdc++.h> using namespace std; int main() { vector<int> grundies; grundies.push_back(0); for (int i = 1; i <= 60; i++) { long long accum = 0; long long add = 0; while (accum < i) { accum += add; add++; } if (accum > i) { add--; ...
#include <bits/stdc++.h> #pragma comment(linker, /stack:225450978 ) #pragma GCC optimize( Ofast ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) using namespace std; const long long Mod = 1000000007LL, INF = 1e9, LINF = 1e18; const long double Pi = 3.141592653589793116, EPS =...
#include <bits/stdc++.h> using namespace std; string to_string(string s) { return + s + ; } string to_string(const char *s) { return to_string((string)s); } string to_string(bool b) { return (b ? true : false ); } template <typename A, typename B> string to_string(pair<A, B> p) { return ( + ...
#include <bits/stdc++.h> using namespace std; template <typename T, typename S> ostream &operator<<(ostream &os, const pair<T, S> &p) { return os << ( << p.first << , << p.second << ) ; } template <typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_sam...
#include <bits/stdc++.h> using namespace std; using lli = long long; using lld = long double; using ulli = unsigned long long int; using pll = pair<lli, lli>; using ttt = pair<lli, pll>; using vttt = vector<ttt>; using vll = vector<pll>; using vl = vector<lli>; using vi = vector<int>; using vvi = ...
#include <bits/stdc++.h> using namespace std; vector<int> x[100000], G[100000]; int n, a[100000], col[100000], cnt, p[2001][1000]; long long ret = 1, ret2 = 0; long long gcd(long long r, long long s) { if (s == 0) return r; return gcd(s, r % s); } void dfs(int pos) { if (col[pos] >= 1) return;...
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; const int MAXN = 50 + 10; template <typename T> inline void add(T& a, T b) { a += b; if (a >= MOD) a -= MOD; } int main() { static long long g[MAXN][MAXN]; static long long f[MAXN][MAXN]; static long long F[MAXN]...
#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; cin >> n; string s1, s2; cin >> s1 >> s2; long long a = 0, b = 0, c = 0, d = 0; vector<long long> a1, b1, c1, d1; for (long long ...
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; int n, m; map<int, bool> ma, mb; int a[maxn], b[maxn]; int main() { scanf( %d%d , &n, &m); for (int i = 1; i <= n; i++) { scanf( %d , &a[i]); if (ma[a[i]] == true) { printf( 0 n ); return 0; } ...
#include <bits/stdc++.h> using namespace std; const int MAX = 1600 + 5; const int dr[] = {0, 0, 1, -1, 1, -1, 1, -1}; const int dc[] = {1, -1, 0, 0, 1, 1, -1, -1}; int n, m, nr, nc, cnt, ct; bool grid[MAX][MAX], x[MAX][MAX], y[MAX][MAX], z[MAX][MAX], val; vector<int> ans; pair<int, int> cur; bool insi...
#include <bits/stdc++.h> using namespace std; long long a[200200], b[200200]; set<pair<long long, long long> > s; set<pair<long long, long long> >::iterator it, it2; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long n, i; cin >> n; for (i = 0; i < n; i++) c...
#include <bits/stdc++.h> using namespace std; const int maxn = 101010 * 2; int a[maxn], n, m; int b[maxn]; int p[maxn]; int query(int poin, long long l, bool dir) { int tv; int cir; int las; if (dir) { tv = upper_bound(b + 1, b + 1 + n, b[poin] + l) - b - 1; if (tv == poin) retur...
#include <bits/stdc++.h> using namespace std; int64_t nearest_power_of_2(int64_t a) { int cnt = 0; while (a / 2 != 0) { a = a / 2; cnt++; } return cnt; } int main() { int64_t t; cin >> t; for (int i = 0; i < t; i++) { int64_t n; cin >> n; vector<int64_t>...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int maxn = 2000; const int maxm = 1000 * 10; struct edge { int v, w, next; } e[maxm * 2]; struct node { int d, u; bool operator<(const node &b) const { return d > b.d; } }; int head[maxn], d[maxn], d2[maxn]; ...
#include <bits/stdc++.h> using namespace std; long long n, h, f[100], g[100][100]; long long fun(long long x) { int i; if (f[x] > -1) return 0; f[x] = 0; for (i = 0; i < x; ++i) { fun(i); fun(x - i - 1); f[x] += f[i] * f[x - i - 1]; } return 0; } long long rec(long lo...
#include <bits/stdc++.h> using namespace std; int main() { long long r; cin >> r; if (r % 2 == 0 || r == 1 || r == 3) cout << NO ; else { long long x, y; long long up = (r - 1); for (int i = 1; i < 100000; i++) { if ((up / i - i - 1) % 2 == 0) { x = i; ...
#include <bits/stdc++.h> using namespace std; long long mod = 1e9 + 7; const long long N = 100011; void solve() { long long n, ans = 0; cin >> n; pair<long long, long long> a[n + 17]; multiset<long long> s; for (long long i = 1; i <= n; i++) cin >> a[i].first; for (long long i = 1; i <= ...
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b, c = 0; string s; cin >> n >> a >> b >> s; bool turnA; if (a > b) turnA = true; else turnA = false; for (int i = 0; i < s.size(); ++i) { if (s[i] == . ) { if ((i == 0 || s[i - 1] == * ) && ...
#include<bits/stdc++.h> using namespace std; int main(){ long long int t,a1,b1,f1,a2,b2,f2,x; cin>>t; while(t--){ x=0; cin>>a1>>a2>>b1>>b2>>f1>>f2; if((a1==f1 && a2==f2) || (b1==f1 && b2==f2)){ // cout<< a ; cout<<0; continue; } if(a1<b1)swap(a1,b1); if(a2<b2)swap(a...
#include <bits/stdc++.h> const int maxn = 5e5 + 5; int fa[maxn], t[maxn], n, m, k, v, u, ev, eu; int find(int n) { return n == fa[n] ? n : (fa[n] = find(fa[n])); } void merge(int u, int v) { ev = find(v); eu = find(u); if (ev != eu) { fa[ev] = eu; t[eu] += t[ev]; } } int main() {...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-10; const int inf = 0x3f3f3f3f, N = 2e5 + 10; const double pi = acos(-1); using namespace std; char s[N]; int num[N]; int main() { int n, k; while (cin >> n >> k) { scanf( %s , s + 1); memset(num, 0, sizeof(num)); ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 10; long long a[MAXN]; long long b[MAXN]; int n, m; long long c2(long long x) { return (x * (x - 1)) / 2; } long long f(int l) { if (m < l * n) { return -1; } for (int i = 1; i <= n; i++) { if (a[i] < i * l + n * ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long n, r; cin >> n >> r; long long int sum = 0; if (n == 1) { sum = 1; } else if (n <= r) { sum = ((n - 1) * (n)) / 2 + 1; } else { sum = (r * (r + ...
#include <bits/stdc++.h> using namespace std; long long n, q, x, y, ans; int main() { cin >> n >> q; while (q--) { cin >> x >> y; ans = 0; if ((x & 1) == (y & 1)) { ans += (x - 1) / 2 * n; x = x % 2; if (x) ans += (y + 1) / 2; else ans ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, p, q, r; cin >> n >> p >> q >> r; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } long long dp[n][3]; dp[0][0] = 1ll * p * a[0]; for (int ...
#include <bits/stdc++.h> using namespace std; template <typename T> bool chkmax(T &x, T y) { return x < y ? x = y, true : false; } template <typename T> bool chkmin(T &x, T y) { return x > y ? x = y, true : false; } int readint() { int x = 0, f = 1; char ch = getchar(); while (ch < ...
#include <bits/stdc++.h> using namespace std; const int N = 2005; bool vis[N]; pair<int, int> pt[N]; int dp[N]; int main() { memset(dp, 0x3f, sizeof(dp)); int a, m, n; cin >> a >> n >> m; for (int i = 1; i <= n; i++) { int l, r; scanf( %d %d , &l, &r); for (int j = l + 1; j...
#include <bits/stdc++.h> #pragma GCC target( avx2 ) #pragma GCC optimize( Ofast ) #pragma GCC optimize( unroll-loops ) using namespace std; template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << ( << p.first << , << p.second << ) ; return os; } template <c...
#include<bits/stdc++.h> #define ll long long #define R return #define pb push_back #define SI size() using namespace std; long long t,n,a[100030],ans,w[5030]; int main(){ cin >> t; while(t--){ ans = 0; memset(w,0,sizeof w); cin >> n; for(int i=0...
#include <bits/stdc++.h> using namespace std; template <class T> void _R(T &x) { cin >> x; } void _R(int &x) { scanf( %d , &x); } void _R(int64_t &x) { scanf( %lld , &x); } void _R(double &x) { scanf( %lf , &x); } void _R(char &x) { scanf( %c , &x); } void _R(char *x) { scanf( %s , x); } void R...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:60000000 ) using namespace std; const long double eps = 1e-9; const int inf = (1 << 30) - 1; const long long inf64 = ((long long)1 << 62) - 1; const long double pi = 3.1415926535897932384626433832795; const string task = ; template <class T> T...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5, oo = 0x3f3f3f3f; pair<int, int> stop[maxn]; int nxt[maxn]; int main(void) { int d, n, m; scanf( %d%d%d , &d, &n, &m); int x, y; for (int i = 1; i <= m; i++) { scanf( %d%d , &x, &y); stop[i] = pair<int, int>(x, ...
#include <bits/stdc++.h> using namespace std; bool cmp(int a, int b) { return a > b; } int h[2005]; int main() { int i, n, a, b, ans = 0; scanf( %d %d %d , &n, &a, &b); for (i = 0; i < n; ++i) scanf( %d , &h[i]); sort(h, h + n, cmp); if (h[a - 1] > h[a]) ans = h[a - 1] - h[a]; printf( %d...
#include <bits/stdc++.h> using namespace std; const int N = 200100; int t, n; int MOD; vector<pair<long long int, long long int> > v[N]; long long int kol[N]; long long int gotov[N], sad, a, b; long long int c; long long int sol; vector<long long int> p; long long int FI; long long int inv[N], i...
#include <bits/stdc++.h> using namespace std; bool debug = 0; long long a[26], dp[26][26]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int tc = 1; while (tc--) { string s; cin >> s; int n = s.length(); long long mx = 0; for (int i = 0...
#include <bits/stdc++.h> using namespace std; bool pal(string& s) { int j = s.size() - 1; int i = 0; while (i < j) { if (s[i++] != s[j--]) return false; } return true; } int main() { string s; cin >> s; int n = s.size(); for (int len = n; len >= 0; len--) { for (i...
#include <bits/stdc++.h> using namespace std; const long long int MOD = 1e9 + 7; bool isPoTwo(long long int x) { return x && (!(x & (x - 1))); } long long int power(long long int x, unsigned long long int y, long long int p) { long long int res = 1; x = x % p; if (x == 0) retur...
#include <bits/stdc++.h> using namespace std; int main() { int n, a, mn = INT_MAX, ans = INT_MAX; cin >> n; map<int, int> mp; map<int, int> mp_ans; for (int i = 1; i <= n; i++) { cin >> a; if (mp[a] == 0) mp[a] = i; else { if (a <= mn) { mn = a; ...
#include <bits/stdc++.h> using namespace std; long long pow(int a, int b, long long MOD) { long long x = 1, y = a; while (b > 0) { if (b % 2 == 1) { x = (x * y); if (x > MOD) x %= MOD; } y = (y * y); if (y > MOD) y %= MOD; b /= 2; } return x; } long ...
#include <bits/stdc++.h> const int INF = 0x3f3f3f3f; int n, m; int f[55][405][405], s[405]; void DP() { int i, j, k, mx, my, ans = 0; memset(f, 0, sizeof(f)); for (i = 1, s[0] = 0; i <= n; i++) { scanf( %d , &s[i]); s[i] += s[i - 1]; } for (k = 2; k <= m; k++) { mx = my = -...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; int fact(int n) { long long ans = n; for (int i = n - 1; i > 0; --i) { ans = (ans * i) % MOD; } return ans; } int pow2(int n) { long long ans = 1, b = 2; while (n > 0) { if (n % 2) { ans = (ans *...
#include <bits/stdc++.h> using namespace std; const int maxn = 1000 + 10; vector<int> v[maxn]; int dp[maxn]; int a[10][maxn]; int main() { int n, K; cin >> n >> K; for (int i = 0; i < K; i++) { for (int j = 0; j < n; j++) scanf( %d , &a[i][j]), v[a[i][j]].push_back(j); } memset(dp,...
#include <iostream> #include <cmath> #include <vector> #include <algorithm> #include <set> #include <cstdio> #include <map> #include <queue> #include <ctime> #include <iomanip> #include <stack> #include <assert.h> #include <unordered_map> using namespace std; #define F first ...
#include <bits/stdc++.h> using namespace std; long long a[1005], b[1005]; int main() { int n, l, r; cin >> n; long long bans = 1, aans = 1, mx = 0; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) cin >> b[i]; for (int l = 0; l < n; l++) { for (int r = l; r < n; r...
#include <bits/stdc++.h> using namespace std; int n, m, x, y, col[111111], used[111111], size; vector<int> g[111111], L, R, mat[111111]; void paint(int id, int c) { col[id] = c; c == 1 ? L.push_back(id) : R.push_back(id); for (vector<int>::iterator ii = g[id].begin(); ii != g[id].end(); ii++) ...
#include <bits/stdc++.h> using namespace std; int main() { long long m, sum, p; cin >> m; for (int i = 5; i < 400006; i++) { p = 5, sum = 0; while (i / p) sum += i / p, p *= 5; if (sum == m) { cout << 5 n << i << << i + 1 << << i + 2 << << i + 3 << ...
#include <bits/stdc++.h> using namespace std; using lint = long long; using ulint = unsigned long long; const int N = 1500 + 1; int a[N]; int bit[N]; int back[N]; int lsb(int x) { return x & -x; } int query(int r) { int res = 0; for (; r > 0; r -= lsb(r)) { res = max(res, bit[r]); } ...
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; int ma[10][10]; bool vis[20]; int isok[20][20], tmp[20][20]; int n, m, ok = 0; int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; void solve() { puts( YES ); if (n > 4) { for (int i = 1; i <= m; i++) { if ...
#include <bits/stdc++.h> using namespace std; int main() { string s; for (int i = 0; i < 10; i++) { cout << i << endl; getline(cin, s); if (s == great || s == cool || s == not bad || s == don t touch me || s == don t think so ) { cout << normal n ; retur...
#include <bits/stdc++.h> using namespace std; map<long long, pair<long long, long long> > mp; pair<long long, long long> dfs(long long x) { if (x == 0) return make_pair(0, 0); if (mp.count(x)) return mp[x]; long long t = pow(x + 0.5, 1.0 / 3); pair<long long, long long> res = dfs(t * t * t - 1); ...
#include <bits/stdc++.h> using namespace std; int a, b, m, t; long long sum(int l, int r) { long long sl = a + (l - 1) * b; long long sr = a + (r - 1) * b; return (sl + sr) * (r - l + 1) / 2; } bool chk(int l, int x) { return a + 1LL * (x - 1) * b <= 1LL * t && sum(l, x) <= 1LL * m * t; } ...
#include <bits/stdc++.h> #pragma GCC optimize( -O3 ) using namespace std; template <typename T1, typename T2> ostream& operator<<(ostream& os, pair<T1, T2> p) { cout << ( << p.first << , << p.second << ) ; return os; } template <typename T> ostream& operator<<(ostream& os, vector<T>& vec) { ...
#include <bits/stdc++.h> using namespace std; inline void PAUSE() { char tmp; cin >> tmp; } int M[100001]; int f[100001]; int main() { int n; scanf( %d , &n); for (int i = 0; i <= 100000; i++) { M[i] = -1; } int x, k; for (int i = 0; i < n; i++) { scanf( %d %d , &...
#include <bits/stdc++.h> using namespace std; void solve() { long long ans = 0; long long a, b, c, s; cin >> s >> a >> b >> c; ans = s / c + (s / c / a) * b; cout << ans << endl; } int main() { int T; cin >> T; while (T--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int a[256], n, k, p; cin >> n >> k; memset(a, -1, sizeof(a)); for (int i = 0; i < n; i++) { cin >> p; if (a[p] == -1) { for (int j = max(0, p - k + 1); j <= p; j++) if (a[j] == -1 || a[j] == j) { for...
#include <bits/stdc++.h> using namespace std; const int inf = (int)1e9; const int mod = inf + 7; const double eps = 1e-9; int a[100][100]; int n, x, y; bool u[400], u1[400]; vector<int> v; int main() { ios_base ::sync_with_stdio(false); cin.tie(NULL); cin >> n; for (int i = 1; i <= n *...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int n, k; cin >> n >> k; long long int a[n + 2]; a[0] = 0; pair<long long int, long long int> min; min.first = INT_MAX; for (long long int i = 1; i <= n;...
#include <bits/stdc++.h> using namespace std; const int inf = 1.01e9; const double eps = 1e-9; const int N = 22; double RES = 0; double rf, re, rs; double df, de; int cnt = 0; int a[N]; int ac = 0; int b[N]; int bc = 0; int nf, ne, ns; double e[N]; double FI[200]; double EN[200]; doubl...
#include <bits/stdc++.h> using namespace std; long long i, j, k, l, n, m, last, res; long long a[100009]; queue<long long> q; int main() { cin >> n; for (i = 1; i <= n; i++) cin >> a[i]; sort(a + 1, a + 1 + n); q.push(1); for (i = 2; i <= n; i++) { if (!q.empty() && a[q.front()] < a[...
#include <bits/stdc++.h> using namespace std; set<pair<int, int> > s; std::vector<int> vv; std::vector<std::vector<int> > gr; std::vector<int> vis; int k; pair<int, int> dfs(int u, int l) { vis[u] = l; vv.emplace_back(u); for (int v : gr[u]) { if ((vis[v]) && (vis[u] - vis[v]) >= k) { ...
#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) { ...