func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; const int N = 100005; int n, cnt, sum, len, tlen, tcnt; int a[26], ans[N], tans[N], id[26], pos[N], tpos[N]; void work1() { printf( 0 n ); for (int i = 0; i < n; i++) for (int j = 1; j <= a[i]; j++) printf( %c , a + i); } bool cmp(int x, int y)...
#include <bits/stdc++.h> using namespace std; const int OO = 1e9; const long long INF = 1e18; const int irand(int lo, int hi) { return ((double)rand() / (RAND_MAX + 1.0)) * (hi - lo + 1) + lo; } const long long lrand(long long lo, long long hi) { return ((double)rand() / (RAND_MAX + 1.0)) * (hi - lo...
#include <bits/stdc++.h> using namespace std; long long a[100004]; long long d[100004]; int main() { int n; scanf( %d , &n); a[0] = 0; long long b = 0, c = 0; for (int i = 1; i <= n; ++i) { scanf( %lld , &a[i]); d[i] = a[i] - a[i - 1]; if (d[i] > 0) b += d[i]; } if ...
#include <bits/stdc++.h> using namespace std; int a[105]; bool b[105][105]; int main() { int n, m; cin >> n >> m; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < m; i++) { int u, v; cin >> u >> v; u--; v--; b[u][v] = b[v][u] = true; } int ans = ...
#include <bits/stdc++.h> using namespace std; int solve() { int n, x; cin >> n >> x; vector<int> a(n); vector<int> index; for (int(i) = 0; (i) < n; (i)++) { cin >> a[i]; if (a[i] % x != 0) index.push_back(i); } if (index.size() == 0) { cout << -1 n ; return 0; ...
#include <bits/stdc++.h> const int N = 1e5 + 10; const int MOD = 1e9 + 7; const int INF = 2e9; const long long INFLL = 1e18; const double PI = acos((double)-1); inline int mult(int a, int b, int p = MOD) { return (1ll * a * b) % p; } inline int add(int a, int b, int p = MOD) { return (1ll * a + b) % p; } ...
#include <bits/stdc++.h> template <typename T> bool Chkmin(T &x, T y) { return y < x ? x = y, true : false; } template <typename T> bool Chkmax(T &x, T y) { return y > x ? x = y, true : false; } const int MAXN = 1e6 + 1e3, MAXM = MAXN, oo = 0x3f3f3f3f; int n, m, tote, S, T; int head[MAXN], nex...
#include <bits/stdc++.h> using namespace std; const int N = 100001; int L, n, p, t; int dp[N], f[N]; int main() { scanf( %d%d%d%d , &L, &n, &p, &t); f[0] = -t; for (int i = 1, j = 0; i <= n; i++, j--) { int l, r; scanf( %d%d , &l, &r); f[i] = f[i - 1]; dp[i] = dp[i - 1]; ...
#include <bits/stdc++.h> using namespace std; long long arr[1002][2][102]; long long p10[1002]; long long n, m, k; long long ans = 0; void pree() { p10[0] = 1; for (long long i = 1; i <= n; ++i) { p10[i] = p10[i - 1] * 10LL; p10[i] %= k; } } void solve() { pree(); arr[0][...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int m; cin >> m; set<int> q; for (int i = 0; i < n; ++i) { int k; cin >> k; for (int j = 0; j < k; ++j) { int x; cin >> x; q.insert(x); } } cout << ((q.size() =...
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; cin >> n >> k; pair<int, int> ar[k]; for (long long i = 0; i < k; i++) { cin >> ar[i].first >> ar[i].second; } set<long long> X, Y; long long atk, safe; for (int i = 0; i < k; i++) { X.insert(ar[i]...
#include <bits/stdc++.h> void answer(const std::vector<std::vector<std::string>>& v) { for (const auto& r : v) { const char* separator = ; for (const std::string& x : r) { std::cout << separator << x; separator = ; } std::cout << n ; } } void solve(unsigned k...
#include <bits/stdc++.h> int main() { int n, m, h, sum = 0, i; int s[1000]; double d = 1; scanf( %d %d %d , &n, &m, &h); for (i = 0; i < m; i++) { scanf( %d , &s[i]); sum += s[i]; } if (sum < n) { puts( -1.0 n ); return 0; } if (sum - s[h - 1] < n - 1) { ...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; const int maxn = 1e6 + 10; const int md = 1e9 + 7; long long FAC[maxn], iFAC[maxn]; long long dp[maxn]; vector<tuple<int, int>> a; long long mpow(long long a, long long b) { if (b == 0) return 1; long long res = mpow(a, b /...
#include <bits/stdc++.h> using namespace std; int main() { int d1, d2, d3; cin >> d1 >> d2 >> d3; int s1 = d1 + d3 + d2; int s2 = 2 * d1 + 2 * d3; int s3 = 2 * d2 + 2 * d1; int s4 = 2 * d2 + 2 * d3; cout << min(s1, min(s2, min(s3, s4))); }
#include <bits/stdc++.h> using namespace std; int main() { int i = 0, a = 0, b = 0, c = 0; string s; cin >> s; for (; i < s.length(); i++) { if (s[i] == a ) a++; else break; } for (; i < s.length(); i++) { if (s[i] == b ) b++; else br...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; long long f[5020][5020], a[5020], powk[5020], ans, ans2, invn; int n, k; inline long long power(long long x, long long y) { long long res = 1; while (y) { if (y & 1) res = res * x % mod; x = x * x % mod; y >...
#include <bits/stdc++.h> using namespace std; const int dr[] = {+1, -1, +0, +0, +1, -1, +1, -1}; const int dc[] = {+0, +0, +1, -1, +1, -1, -1, +1}; const int ms[] = {+31, +29, +31, 30, +31, +30, +31, +31, +30, +31, +30, +31}; const int N = 200 + 5; const int MOD = 1e9 + 7; void add(int &a, int b) { a ...
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; int m; cin >> n >> m >> k; set<long long> removal; for (int i = 0; i < m; i++) { long long x; cin >> x; removal.insert(x); } long long total = 0; long long offset = 0; set<long long>::ite...
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 4; const int maxlog = 22; const int mod = 1e9 + 7; const int sq = 350; int deg[maxn], cnt[maxn]; map<pair<int, int>, int> m; long long ans = 0; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout....
#include <bits/stdc++.h> using namespace std; int main() { long long m, n, q = 998244853, sum = 1, a = 1, b = 1, r = 0, x = 208513042, y, z; cin >> n >> m; if (n == 0) { cout << 0; return 0; } if (m == 0) { cout << n; return 0; } for (long long...
#include <bits/stdc++.h> using namespace std; int len[55]; int n; struct node { int x, y, s; } arr[55 * 55]; int ans[55 * 55][2]; int main() { int i, j, tmp, k; while (scanf( %d , &n) != EOF) { for (i = 1; i <= n; i++) scanf( %d , &len[i]); k = 0; for (i = 1; i <= n; i++) ...
#include <bits/stdc++.h> using namespace std; int main() { int t; scanf( %d , &t); while (t--) { int n, ans = 0, num[101], temp, minn = 1e9 + 7, maxx = 0, ann; for (int i = 1; i <= 100; i++) num[i] = 0; scanf( %d , &n); for (int i = 1; i <= n; i++) { scanf( %d , &temp); ...
#include <bits/stdc++.h> using namespace std; const long long int mod = 998244353; vector<long long int> roots; long long int powermod(long long int a, long long int n, long long int p) { long long int ans = 1; while (n > 0) { if (n & 1) ans = (ans * a) % p; n >>= 1; a = a * a % p; ...
#include <bits/stdc++.h> const int N = 2005; using namespace std; bitset<N> f[N]; int n; int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { int t; scanf( %d , &t); if (t > 0) f[i][j] = 1; } } for (int i = 1; i <= n; i...
#include <bits/stdc++.h> int main() { int a, b, c; scanf( %d%d%d , &a, &b, &c); if ((a + b) == c || (c + b) == a || (a + c) == b) { printf( 1 ); } else { if ((a + b) < c) { printf( %d , (c - b - a + 1)); } else if (b + c < a) { printf( %d , (a - b - c + 1)); } e...
#include <bits/stdc++.h> using namespace std; int n; int cnt[3], seen[3]; string s; int main() { ios::sync_with_stdio(0); cin >> n >> s; int m = n / 3; for (int i = 0; i < n; i++) { cnt[s[i] - 0 ]++; } for (int i = 0; i < n; i++) { if (cnt[s[i] - 0 ] > m) { for (l...
#include <bits/stdc++.h> using namespace std; void solve() { int n, k, z; cin >> n >> k >> z; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } int ans = 0; for (int i = 0; i <= z; i++) { int kol = k - 2 * i; if (kol < 0) { continue; } int tren ...
#include <bits/stdc++.h> using namespace std; template <class T> inline void remax(T& A, T B) { if (A < B) A = B; } template <class T> inline void remin(T& A, T B) { if (A > B) A = B; } string ToString(long long num) { string ret; do { ret += ((num % 10) + 0 ); num /= 10; ...
#include <bits/stdc++.h> using namespace std; int i, j, n; void write(int X) { if (X < 0) putchar( - ), X = -X; if (X > 9) write(X / 10); putchar(X % 10 | 48); } void print(int k) { int h; for (h = 1; h <= (4); h++) { write(((i - 1) << 2) + h); putchar( ); write(((j - 1...
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long t; cin >> t; while (t--) { long long n; cin >> n; long long arr[n]; for (long long i = 0; i < n; i++) { cin >> arr[i]; ...
#include <bits/stdc++.h> using namespace std; const int dr[]{-1, -1, 0, 1, 1, 1, 0, -1}; const int dc[]{0, 1, 1, 1, 0, -1, -1, -1}; void run() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } void solve() { int n, m; cin >> n >> m; vector<pair<int, int>> v(m); vect...
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio; cin.tie(NULL); long long i, j, n, t, k, m; cin >> t; while (t--) { cin >> n >> k; vector<long long> s(n); for (long long i = 0; i < n; i++) { cin >> s[i]; } map<long lon...
#include <bits/stdc++.h> using namespace std; int main() { int t; scanf( %d , &t); while (t--) { int n; scanf( %d , &n); char s[n + 1]; scanf( %s , s + 1); int a[100] = {0}, b[100] = {0}; int aa = 0, bb = 0; for (int i = 1; i <= n; i++) { if (s[i] == a ...
#include <bits/stdc++.h> using namespace std; int n, u, r, i; bool flag = false; long long max_score = 0; vector<long long> a, b, k, p; inline long long score(vector<long long> a) { long long s = 0; for (i = (0); i < (n); ++i) { s += a[i] * k[i]; } return s; } vector<long long> per...
#include <bits/stdc++.h> using namespace std; long long n, s, d; bool f(char x) { if (x == a || x == e || x == i || x == o || x == u ) return true; if (x >= 0 && x <= 9 ) { int p = x - 0 ; if (p % 2 == 1) return true; } return false; } int main() { string s; ci...
#include <bits/stdc++.h> using namespace std; long long in() { int32_t x; scanf( %d , &x); return x; } const long long maxn = 1e5 + 10; const long long mod = 1e9 + 7; const long long inf = 1e9 + 10; vector<long long> g[maxn]; long long deg[maxn]; long long a[maxn]; bool mark[maxn]; lon...
#include <bits/stdc++.h> using namespace std; void er() { cout << NO << endl; exit(0); } int main() { int n; cin >> n; int a[n + 1]; int o = 0; int um = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; if (a[i] != 0) o++; um = um + a[i]; } if (o < 1) er(...
#include <bits/stdc++.h> using namespace std; const long double e = 1e-2; int k; long double R, r, l; long double x, y, xl, yl, xr, yr; long double a, b, c, S; long double COS[12], SIN[12]; bool check(long double x, long double y) { long double s = 0; for (int i = 0; i < 12; i += 2) s = ma...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n; cin >> n; string s[n]; long long flg = 1; long long ar[n]; for (long long i = 0; i < n; i++) { cin >> s[i]; long long flag = 0; long long pos = -...
#include <bits/stdc++.h> using namespace std; int main() { string s; getline(cin, s); long long int a[s.size()]; vector<long long int> v; for (long long int i = 0; i < s.size(); i++) { if (i == 0) { vector<long long int> tp(8, 0); long long int j = 0; long long int ...
#include <bits/stdc++.h> using namespace std; const int MX = 400005; template <typename T> void cmin(T &x, const T &y) { if (y < x) x = y; } template <typename T> void cmax(T &x, const T &y) { if (y > x) x = y; } template <typename T> void read(T &x) { x = 0; char c = getchar(); ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); int n; cin >> n; long long m_min = 1ll << 62; long long ans = 0; for (int i = 0; i < n; i++) { long long x; cin >> x; ans += x; if (x % 2 == 1) m_min = min(m_min, x); } if...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int maxn = 1e6 + 5; long long int power(long long int base, long long int exp) { long long int res = 1; while (exp) { if (exp % 2) res *= base; base *= base; res %= mod; base %= mod; exp /= 2; ...
#include <bits/stdc++.h> using namespace std; int main() { int n, A; cin >> n; for (int i = 1; i <= n; i++) { cin >> A; if (i == n) { while (A--) cout << PLR ; return 0; } while (A--) { cout << PRL ; } cout << R ; } }
#include <bits/stdc++.h> const int inf = int(1e9); const int mod = inf + 7; const double PI = acos(-1.0); using namespace std; const int N = 1e5 + 155; void solve() { int n, k, s = 0; cin >> n >> k; for (int i = 0; i < n; ++i) { int x; cin >> x; s += x; } for (int ans =...
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; int ans = 0; while ((a >= 1 && b > 1) || (a > 1 && b >= 1)) { if (a < b) { ans++; a--; b -= 2; } else { ans++; a -= 2; b--; } } cout << ans <<...
#include <bits/stdc++.h> using namespace std; int L[7], R[7]; int main() { int n; cin >> n; for (int i = 1; i <= n; ++i) { cin >> L[i] >> R[i]; } long double cases = 0; long double sum = 0; for (int p = 1; p <= 10000; ++p) { for (int mask = 3; mask < 1 << n; ++mask) { ...
#include <bits/stdc++.h> using namespace std; int main() { int n, sub; int grp; cin >> n >> sub; if (n == sub) grp = 0; else if (sub == 0 || sub == 1) grp = 1; else if (sub >= n - n / 2) grp = n - sub; else grp = sub; cout << grp << endl; }
#include <bits/stdc++.h> using namespace std; template <typename Bp, typename Ep, typename Mp> inline Mp __powMod(Bp a, Ep b, const Mp &m) { a %= m; Mp res = 1; while (b > 0) { if (b & 1) { res = ((long long)res * a) % m; } a = ((long long)a * a) % m; b >>= 1; } ...
#include <bits/stdc++.h> using namespace std; double pd[40][40][300]; int n, K; int r[40]; int go(int a, int i, int j) { if (a < i || a > j) return a; return j - (a - i); } double solve(int a, int b, int k) { if (k == 0) return b < a; double& ret = pd[a][b][k]; if (ret > -0.5) return r...
#include <bits/stdc++.h> using namespace std; long long MOD = 998244353; signed main() { ios_base::sync_with_stdio(0); cin.tie(); cout.tie(); long long n, k; cin >> n >> k; long long m = 0; vector<long long> v(n); for (long long i = 0; i < n; i++) cin >> v[i]; for (long long i ...
#include <bits/stdc++.h> using namespace std; int n, m, q; int nxt[100001]; char s[100001], t[100001]; int temp[100001]; int l, r; bool check(int u) { for (int i = 0; i < m; ++i) { if (s[u + i] != t[i]) return 0; } return 1; } void pre_do() { for (int i = 1; i <= n - m + 1; i++) ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 5e4 + 5; const int SQRN = 210; const int BSZ = 256; vector<int> g[MAXN]; int v[MAXN], lvl[MAXN], pai[MAXN]; int jump[MAXN], best[MAXN][SQRN]; int trie[BSZ * 20 + 5][2]; int n, q, cnt_trie = 1; void predfs(int cur, int p) { for (auto ...
#include <bits/stdc++.h> using namespace std; int main() { int n, t = 0, c = 0; char ch[105][105]; cin >> n; for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) cin >> ch[i][j]; for (int i = 1; i <= n; i++) { c = 0; for (int j = 1; j <= n; j++) { if (ch[i][j] == ...
#include <bits/stdc++.h> using namespace std; namespace std { bool operator<(const complex<double> &lhs, const complex<double> &rhs) { if (real(lhs) == real(rhs)) { return imag(lhs) < imag(rhs); } else { return real(lhs) < real(rhs); } } } // namespace std ostream &operator<<(ostrea...
#include <bits/stdc++.h> namespace IO { char gc() { return getchar(); } template <typename Tp> bool get1(Tp &x) { bool neg = 0; char c = gc(); while (c != EOF && (c < 0 || c > 9 ) && c != - ) c = gc(); if (c == - ) c = gc(), neg = 1; if (c == EOF) return false; x = 0; for (; c >...
#include <bits/stdc++.h> using namespace std; template <typename T> T gcd(T x, T y) { if (x < y) swap(x, y); while (y > 0) { T f = x % y; x = y; y = f; } return x; } const int maxn = 200005; int n; int a[maxn]; int dp[maxn]; vector<int> adj[maxn]; void dfs(int u, in...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 1; int v[N], md[N]; vector<int> freq[N]; int lm[N], rm[N]; int cs[N]; int val(int x, int l, int r) { if (l > r || l < 0) return 0; return upper_bound(freq[x].begin(), freq[x].end(), r) - lower_bound(freq[x].begin(), freq[...
#include <bits/stdc++.h> using namespace std; int u[1005]; int v[1005]; int main() { int n, k, i; cin >> n >> k; int a, b, c, d; int t; cin >> a >> b >> c >> d; if (n == 4) { cout << -1 << endl; } else if (k < n + 1) { cout << -1 << endl; } else { cout << a ...
#include <bits/stdc++.h> using namespace std; const int NR = 4e6 + 5; int n; long long P = 51123987; char s[NR]; int d[NR]; long long f[NR], g[NR]; int main() { scanf( %d , &n); scanf( %s , s + 1); for (int i = n; i >= 1; i--) { s[i * 2] = s[i]; s[i * 2 - 1] = # ; } s[n ...
#include <bits/stdc++.h> using namespace std; const long long N = 1e6 + 1; const long long M = 1e9 + 7; const long long H = 1e5 + 7; const long long B = 1e4 + 7; const long long A = 1e6 + 7; set<long long> o; map<long long, long long> mp, pm; map<char, long long> hs; vector<long long> v, vc, oreder1...
#include <bits/stdc++.h> using namespace std; int dp[225][1 << 16]; int dx[4] = {0, -1, 0, 1}; int dy[4] = {1, 0, -1, 0}; int tran[4] = {2, 3, 0, 1}; string s[15]; bool visit[15][15][1 << 16]; int n, m, length, backx, backy, startbody, status; struct snake { int x, y, body; } start; bool in(in...
#include <bits/stdc++.h> using namespace std; const int sz = 1e5 + 10, mod = 1e9 + 7, inf = 2e9; struct re { int to, va; bool co; }; re nel; int n, anch = 1, anzn = 1, cuq, si[sz], sq, cu, lg, rg, add; vector<re> sv[sz]; vector<pair<int, pair<int, int> > > pa[sz]; pair<int, int> dot[2][sz * 8]...
#include <bits/stdc++.h> using namespace std; const int N = 100005; int a[N], n, i, k, j, c, p, b[N], m, r, t, check, mr; struct tree { int data = 0; int rank = 1; } * ROOT[N], *f[N]; vector<int> leafs; void push(tree*& node, int number) { tree* child = new tree(); child->data = number; ...
#include <bits/stdc++.h> using namespace std; const long long OO = (long long)1e15; const double EPS = 1e-11; vector<vector<pair<long long, int> > > adj; vector<vector<long long> > ar; vector<vector<long long> > dep; long long nxt(int node, long long time) { int idx = lower_bound(ar[node].begi...
#include <bits/stdc++.h> using namespace std; long long M = 1e9 + 7; const long long N = 1e6 + 7; long long a[N]; long long n; long long res = 0; long long par[N]; long long sz[N]; long long findpar(long long v) { if (par[v] == v) return v; return par[v] = findpar(par[v]); } int32_t main()...
#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); template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p); string to_str...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int i, j, k, l, n; cout.precision(10); { cin >> n >> k; if (n <= k / 2) cout << YES << n ; else { cout << NO << ...
#include <bits/stdc++.h> using namespace std; int C[200005], A[200005], n, k, i, j, mx; int main() { scanf( %d%d%d , &n, &i, &k); for (i = 1; i <= n; i++) scanf( %d , &A[i]); for (i = j = 1; i <= n; i++) { while (j - i + 1 - C[A[i]] - (A[j] == A[i]) <= k && j <= n) { C[A[j]]++; j...
#include <bits/stdc++.h> using namespace std; unsigned long long n, a = 1, b = 1, mod = 1000000007, pp = 1000000005; unsigned long long fp(unsigned long long n, unsigned long long p) { if (p == 0) return 1; if (p == 1) return n; unsigned long long res; res = fp(n, p / 2) % mod; res = (res * re...
#include <bits/stdc++.h> using namespace std; bool isrange(int second, int first, int n, int m) { if (0 <= second && second < n && 0 <= first && first < m) return true; return false; } int dy[4] = {1, 0, -1, 0}, dx[4] = {0, 1, 0, -1}, ddy[8] = {1, 0, -1, 0, 1, 1, -1, -1}, ddx[8] = {0, 1, 0, -1, 1,...
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf( %d , &n); int len = 0, x, pre; long long ans = 0LL; for (int i = 0; i < n; i++) { scanf( %d , &x); if (i != 0) { if (pre == x) { len++; } else { ans += 1LL * (len + 1) * len /...
#include <bits/stdc++.h> using namespace std; void dfs(int u, int p[], bool mark[]) { mark[u] = true; if (mark[p[u]]) return; dfs(p[u], p, mark); } int main() { int result = 0, cycle = 0; int n; cin >> n; int p[n + 1], b[n + 1], f = 0; bool mark[n + 1]; for (int i = 1; i <= n...
#include <bits/stdc++.h> using namespace std; template <typename T> inline bool upmin(T &x, T y) { return y < x ? x = y, 1 : 0; } template <typename T> inline bool upmax(T &x, T y) { return x < y ? x = y, 1 : 0; } const long double eps = 1e-15; const long double pi = acos(-1); const long lon...
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > v; bool cmp(pair<int, int> a, pair<int, int> b) { if (a.first == b.first) { return a.second < b.second; } return a.first > b.first; } int main() { string s; int n, m; cin >> n >> m; cin >> s; char ara[m...
#include <bits/stdc++.h> using namespace std; int n, k; int x[100000], y[100000], xx[100000], yy[100000]; int ord[100000]; vector<int> inds; inline bool cmpx(const int &lhs, const int &rhs) { return x[lhs] < x[rhs]; } inline bool cmpy(const int &lhs, const int &rhs) { return y[lhs] < y[rhs]; } vector<in...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; int main() { int n, k; cin >> n >> k; cout << k * (6 * (n - 1) + 5) << endl; for (int i = 1; i <= n; i++) { printf( %d %d %d %d n , k * (6 * (i - 1) + 1), k * (6 * (i - 1) + 2), k * (6 * (i - 1) + 3), k...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9; const long long MOD = 1e9 + 7; const int MAXN = 705; const int bignumlen = 17; const int Blen = 8; const long long base = 100000000; struct bignum { int len; long long data[bignumlen]; long long &operator[](int x) { ret...
#include <bits/stdc++.h> using namespace std; class fenwickTree { public: int* tree; int size; int prefixSum(int index) { index++; int ret = 0; while (index > 0) { ret += tree[index]; index -= (index & -index); } return ret; } void update(int inde...
#include <bits/stdc++.h> template <class p, class q> void umin(p& a, const q& b) { if (a > b) a = b; } template <class p, class q> void umax(p& a, const q& b) { if (a < b) a = b; } using ll = long long; using VI = std::vector<int>; using VLL = std::vector<ll>; using namespace std; using na...
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T &x) { x = 0; char ch = getchar(); long long fh = 1; while (ch < 0 || ch > 9 ) { if (ch == - ) fh = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) x = x * 10 + ch - 0 , ch = getchar(); ...
#include <bits/stdc++.h> int main() { int input, max = 0, temp1, temp2; scanf( %d , &input); for (int i = 1; i <= input; i++) { if (input % i == 0) { temp1 = input / i; temp2 = i; if (temp1 <= temp2) { break; } } } printf( %d %d n , temp1, temp...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const int maxSize = 1 << 16; map<string, int> t; int a[maxSize]; vector<string> s; vector<vector<int> > v; int main() { int n, k; scanf( %d%d , &n, &k); v.resize(n); s.resize(n); for (int i = 0; i < n; i++) ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 200500; int n; pair<int, int> a[MAXN]; int b[MAXN]; int s[MAXN]; int FindMax(int j) { int ret = 0; for (; j >= 0; (j &= (j + 1))--) { ret = max(ret, s[j]); } return ret; } void Update(int j, int x) { for (; j < n;...
#include <bits/stdc++.h> using namespace std; inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } int n; vector<pair<int, int> > v; long long DP[...
#include <bits/stdc++.h> using namespace std; int row[1010]; int main() { int n, m, k; scanf( %d %d %d , &n, &m, &k); memset(row, 0x3f3f3f3f, sizeof row); long long ans = 0; for (int i = (0); i < (n); ++i) { int r, c; scanf( %d %d , &r, &c); row[r] = min(c, row[r]); } ...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; const int N = 2e5 + 5; int dist[N]; vector<int> open[N], close[N]; int n, k; bool done[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> k; for (auto i = 0; i < (long long)(n); i++) { int ...
#include <bits/stdc++.h> using namespace std; int a[50][50], n, m; bool can(int k) { int total = 0; for (int i = 0; i < m; i++) if (a[k][i] != i + 1) total++; if (total <= 2) return 1; return 0; } bool ok() { for (int i = 1; i <= n; i++) if (!can(i)) return 0; return 1; }...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, x, y, i; cin >> n >> m >> x >> y; cout << x << << y << endl; int a = x; for (i = 1; i < m + 1; i++) { if (i != y) { cout << x << << i << endl; } } n++; int cnt = 0; while (n-- && n > ...
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> ostream& operator<<(std::ostream& os, const std::map<T1, T2>& v) { os << [ ; for (typename std::map<T1, T2>::const_iterator ii = v.begin(); ii != v.end(); ++ii) os << ii->first << : << ii->second << ; ...
#include <bits/stdc++.h> using namespace std; int main() { int com[] = {1, 4, 6, 8, 9}; long long int t; cin >> t; while (t--) { int64_t k; cin >> k; string n; cin >> n; map<int, int> m; for (int i = 0; i < n.size(); i++) { m[n[i] - 0 ]++; } i...
#include <bits/stdc++.h> using namespace std; double DP[2][2510][2510]; double X[2510], Y[2510]; double dis(int a, int b) { return sqrt((X[a] - X[b]) * (X[a] - X[b]) + (Y[a] - Y[b]) * (Y[a] - Y[b])); } int main() { ios::sync_with_stdio(false); memset(DP, 0, sizeof(DP)); int N; cin >> N; ...
#include <bits/stdc++.h> using namespace std; template <class X, class Y> void minimize(X &x, const Y &y) { if (x > y) x = y; } template <class X, class Y> void maximize(X &x, const Y &y) { if (x < y) x = y; } template <class T> T Abs(const T &x) { return (x < 0 ? -x : x); } const int ...
#include <bits/stdc++.h> using namespace std; const long long inf = 0x7f7f7f7f7f7f7f7f; struct sta { int s; long long k, val; } p[105]; int n, m; long long b, f[(1 << 20) + 5]; bool cmp(sta a, sta b) { return a.k < b.k; } void init() { memset(f, -1, sizeof f); scanf( %d%d , &n, &m); ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long a, b, c; cin >> a >> b >> c; cout << a + b + c - 2 << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; bool bo[1005][1005]; double ans[1005][1005]; double f(int n, int m) { if (m == 0) return 1; if (bo[n][m]) return ans[n][m]; if (n == 0) { return 1.0 / (m + 1); } double a = 1.0, b = 1 - f(m, n - 1); double c = 1.0 * m / (m + 1) * (1 - f...
#include <bits/stdc++.h> using namespace std; long long n, w, a[1123], d, mx, mn; int main() { cin >> n >> w; for (int i = 0; i < n; ++i) { cin >> a[i]; d += a[i]; mx = max(d, mx); mn = min(d, mn); } cout << max(w + 1 - mx + mn, 0ll); }
#include <bits/stdc++.h> char str[100005]; int main(void) { int n, m; int i; scanf( %d%d , &n, &m); scanf( %s , str); for (i = 0; i < n && m; i++) { if ((!(i & 1)) && str[i] == 4 ) { if ((str[i + 1] == 4 && str[i + 2] == 7 )) break; else if (str[i + 1] == 7 ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 * 2 + 10; int n, len, h; struct node { int flag, mx, l, r; } t[MAXN << 2]; int a[MAXN], b[MAXN]; int L[MAXN]; void push_down(int k) { if (t[k].flag) { t[k << 1].flag += t[k].flag; t[k << 1 | 1].flag += t[k].flag; ...