func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; inline void read(int &first) { first = 0; while (1) { char ch = getchar(); if (ch == || ch == n ) break; first = first * 10 + ch - 0 ; } } inline void write(int first) { char wr[12]; int k = 0; if (!first) ++k, wr[k] ...
#include <bits/stdc++.h> int n, m, k, s; int u[9][4]; int main() { scanf( %d%d%d%d , &n, &m, &k, &s); for (int i = 0; i < 9; i++) { u[i][0] = -0x3f3f3f3f; u[i][1] = 0x3f3f3f3f; u[i][2] = -0x3f3f3f3f; u[i][3] = 0x3f3f3f3f; } for (int i = 0; i < n; i++) { for (int j = 0...
#include <bits/stdc++.h> using namespace std; int prime[100010]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; int cnt = 0; for (int i = 2; i <= n; i++) { if (!prime[i]) { cnt++; for (int j = i; j <= n; j += i) prime[j] = cnt; } } ...
#include <bits/stdc++.h> using namespace std; const int _ = 1e2; const int maxn = 2e6 + _; const int mod = 998244353; inline int ad(int x, int y) { return x >= mod - y ? x - mod + y : x + y; } inline int re(int x, int y) { return x < y ? x - y + mod : x - y; } inline int mu(int x, int y) { return (long lo...
#include <bits/stdc++.h> using namespace std; inline void _redirect_streams(const string input = , const string output = ) { if (not input.empty()) assert(freopen(input.c_str(), r , stdin) != nullptr); if (not output.empty()) assert(freopen(output.c_str(), w , std...
#include <bits/stdc++.h> using namespace std; int n, m, x, y, z, k, w; char S[10005]; int dp[10005]; int ok[20005]; bool check(int x, int y, int pos) { for (int i = (0); i < (pos); i++) if (S[i + x] != S[i + y]) return 1; return 0; } struct node { char S[4]; } ANS[20005]; bool cmp(...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; vector<long long> fac, ifac; long long fast_pow(long long a, long long b, long long mod) { if (!b) return 1; long long l = fast_pow(a, b >> 1, mod); l = l * l % mod; if (b & 1) l = l * a % mod; return l; } long ...
#include <bits/stdc++.h> using namespace std; int n, m; long long int dp[503][5030]; long long int cnt[100100]; long long int fav[100100]; int t[550]; int used[100100]; long long int h[15]; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cin >> n >> m; for (int i = 0; i < n...
#include <bits/stdc++.h> using namespace std; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); clock_t startTime; double getCurrentTime() { return (double)(clock() - startTime) / CLOCKS_PER_SEC; } void solve() { int n; cin >> n; vector<int> a(n); int totalXor = 0; ...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k, t, s, x, i, count; vector<long long int> a; vector<pair<long long int, pair<long long int, long long int> > > r; cin >> n >> k; for (int i = 0; i < n; i++) { cin >> x; a.push_back(x); } long long i...
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; const int maxn = 100001, inf = 2147483647; const long long mod = 1 ? 998244353 : 1000000007, linf = 9223372036854775807; const double pi = acos(-1); inline long long mi(long long a, long long b, long long mm = mod) { a %= mm; long...
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 10; vector<int> g[N]; bool visited[N]; vector<int> z; void dfs(int v, int depth) { visited[v] = true; bool isLeaf = true; for (auto& i : g[v]) { if (!visited[i]) { dfs(i, depth + 1); isLeaf = false; } ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; long long a[maxn], n, b[maxn], f[maxn]; int main() { scanf( %lld , &n); for (int i = 1; i <= n; i++) scanf( %lld , &a[i]), b[i] = a[i]; sort(b + 1, b + n + 1); for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++)...
#include <bits/stdc++.h> using namespace std; const int N = 100010; pair<int, int> a[N]; int s[N], ss[N]; int main() { int n, m; scanf( %d , &n); for (int i = 0; i < n; i++) { scanf( %d%d , &ss[i], &a[i].first); a[i].second = i; } s[n - 1] = ss[n - 1]; for (int i = n - 2; i...
#include <bits/stdc++.h> using namespace std; int k, n, x[10000], y[10000], z[10000], ans, xx[10000], yy[10000], r, la[10][10000], d[10000]; bool flag[10000], ff[10000]; struct lsg { int x, y; } a[10000], b[10000]; int gcd(int x, int y) { return y == 0 ? x : gcd(y, x % y); } bool dfs(int l) { ...
#include <bits/stdc++.h> using namespace std; int main() { int n, sum; cin >> n >> sum; if (n == 0 || (sum == 0 && n > 1)) cout << -1 << << -1 << endl; else { int ma; string t = ; int x = sum; while (x > 0 && t.length() != n) { if...
#include <bits/stdc++.h> bool match(const char* text, const char* pattern, int n, int m) { int post = 0, posp = 0; while (post < n && posp < m) { if (text[post] == pattern[posp]) { ++post; ++posp; } else ++post; } return (posp == m); } char data[200002], filt[20...
#include <bits/stdc++.h> using namespace std; int T, n; int a[200010]; int sum; int ans[200010]; map<int, vector<pair<int, int> > > o; int exgcd(int a, int b, int &x, int &y) { if (!b) { x = 1, y = 0; return a; } int t = exgcd(b, a % b, y, x); y -= a / b * x; return t; } ...
#include <bits/stdc++.h> int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); int n; std::cin >> n; std::vector<std::vector<int>> a(n, std::vector<int>(n)); for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { a[i][j] = 4 * (i % (n / 2) * (n / 2) + j ...
#include <bits/stdc++.h> using namespace std; int main() { int64_t n, k, m; cin >> n >> k >> m; int64_t ans = 0; vector<vector<int64_t>> dp(n + 1, vector<int64_t>(k + 1)); vector<int64_t> u(n + 1); vector<int64_t> g(n + 1); dp[0][0] = 1; u[1] = 1; for (int64_t i = 2; i <= n; i++)...
#include <bits/stdc++.h> using namespace std; inline long long qr() { long long x = 0, f = 1; char ch; while (!isdigit(ch = getchar())) if (ch == - ) f = -1; for (; isdigit(ch); x = x * 10 + ch - 48, ch = getchar()) ; return x * f; } const int N = 100010; int n, k, a[N], res; ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, x; cin >> n >> x; vector<int> v[n + 1]; for (int i = 0; i < n - 1; i++) { int a, b; cin >> a >> b; v[a].push_back(b); v[b].push_back(...
#include <bits/stdc++.h> using namespace std; int n, m, s; pair<int, int> A[200000]; pair<pair<int, int>, int> B[200000]; set<pair<pair<int, int>, int> > candidates; pair<int, int> q[200000]; int sp, st; int answer[200000]; bool check(int days) { int j = n - 1; sp = st = 0; int used = 0; ...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,tune=native ) using namespace std; template <typename T> inline bool chkmax(T& aa, T bb) { return aa < bb ? aa = bb, true : false; } template <typename T> inli...
#include <bits/stdc++.h> using namespace std; namespace debug { void __(short x) { cout << x; } void __(int x) { cout << x; } void __(long long x) { cout << x; } void __(unsigned long long x) { cout << x; } void __(double x) { cout << x; } void __(long double x) { cout << x; } void __(char x) { cout <...
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf( %d , &n); vector<int> a(n); long long sum = 0; for (int& x : a) { scanf( %d , &x); sum += x; } if (sum != 0) { puts( YES ); puts( 1 ); printf( %d %d n , 1, n); exit(0); } ...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, s, ans = 0, mid = 0; scanf( %lld %lld , &n, &s); long long int a[n]; for (int i = 0; i < n; i++) scanf( %lld , &a[i]); sort(a, a + n); mid = n / 2; if (s >= a[mid]) { for (int i = n / 2; i < n; i++) { ...
#include <bits/stdc++.h> using namespace std; int n, m, tot, ans, Head[100000 + 5], q[100000 + 5], T[100000 + 5], Deg[100000 + 5]; bool Flag[100000 + 5]; struct Edge { int next, node; } h[100000 + 5 << 1]; inline void addedge(int u, int v) { h[++tot].next = Head[u], Head[u] = tot; h[tot].n...
#include <bits/stdc++.h> using namespace std; int main() { int mas[105] = {0}; int n; scanf( %d , &n); int res = -1; int resl = -1; for (int i = 0; i < n; i++) scanf( %d , &mas[i]); for (int i = 0; i < n; i++) { int len = 0; int mest = 0; for (int j = i; j < n; j++) {...
#include <bits/stdc++.h> using namespace std; int A[1001][1001]; int n, m, k, i, j, l, r, a, b, x, y, p, q; int main() { cin >> n >> a >> b; x = n / 2; y = n - x; p = 1; q = 2; for (i = 1; i <= a; i++) for (j = 1; j <= b; j++) { l = A[i - 1][j] % 2; r = A[i][j - 1] ...
#include <bits/stdc++.h> using namespace std; const int maxN = (int)2e5 + 10; const int maxM = (int)4e5 + 10; int n, m, k, type[maxN], a[maxN], pa[maxN]; long long d[maxN]; vector<int> c[maxN], w[maxN]; set<pair<long long, int> > s; int en, ea[maxM], eb[maxM], ep[maxM]; long long ew[maxM]; inline bo...
#include <bits/stdc++.h> using namespace std; int arr[300005]; int main() { int n; cin >> n; cout << 1 << ; int right = n; for (int i = 1; i <= n; i++) { int temp; scanf( %d , &temp); arr[temp] = 1; while (arr[right]) right--; printf( %d , i - (n - right) + 1)...
#include <bits/stdc++.h> using namespace std; bool good(int64_t a, int64_t b) { if (a == 0) return false; if (!good(b % a, a)) return true; int64_t c = b / a; return (c % (a + 1)) % 2 == 0; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10...
#include <bits/stdc++.h> using namespace std; const int D = 1e6 + 3; const int MAXN = 110; int F[MAXN]; struct Mt { int v[MAXN][MAXN]; int N, M; Mt() { for (int i = 0; i < MAXN; i++) { for (int j = 0; j < MAXN; j++) { v[i][j] = 0; } } } void I() { ...
#include <bits/stdc++.h> using namespace std; char c[1000]; int i, n, d, t, q; int main() { cin >> c; n = strlen(c); i = 0; while (i < n && c[i] != @ ) { if (!isalnum(c[i]) && c[i] != _ ) { cout << NO ; return 0; } i++; } i++; t = i; if (i == ...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; const int dir[8][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}, {1, 1}, {1, -1}, {-1, -1}, {-1, 1}}; const int mod = 1e9 + 7, gakki = 5 + 2 + 1 + 19880611 + 1e9; const int MAXN = 1e6 + 5, MAXM = 1e6 + 5; const int MAX...
#include <bits/stdc++.h> const int MAXN = 100005; int n, q, A[MAXN], B[MAXN]; double ans, f[MAXN][105]; int main() { scanf( %d , &n); for (register int i = 1; i <= n; ++i) scanf( %d , A + i), f[i][B[i] = A[i]] = 1, ans += f[i][0]; scanf( %d , &q); register int u, v, k; while (q--) { ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; int l = 2, h = 1e5; int ans = 2; while (l <= h) { int m = l + (h - l) / 2; if ((long long)m * (m - 1)...
#include <bits/stdc++.h> using namespace std; int main() { int n, t; cin >> n >> t; for (int i = 1; i <= n; i++) { int a; cin >> a; t -= 86400 - a; if (t <= 0) { cout << i << endl; return 0; } } }
#include <bits/stdc++.h> using namespace std; const double eps = 1e-10; const double PI = 3.1415926535897932; const int dir[4][2] = {-1, 0, 0, -1, 1, 0, 0, 1}; const int maxn = 2e5 + 5; const int MOD = 998244353; int n, m; int d[maxn]; long long sum[maxn]; long long qpow(long long a, long long p) { ...
#include <bits/stdc++.h> using namespace std; const int MX = 1000; int dp[MX][MX], a[MX], x[MX], y[MX], n, d; int dis(int i, int j) { return abs(x[i] - x[j]) + abs(y[i] - y[j]); } int main() { cin >> n >> d; for (int i = 2; i < n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) cin >> x[i] >> y[i];...
#include <bits/stdc++.h> using namespace std; vector<int> g[100005]; int n, m; vector<int> c[100005]; int nc; bool b[100005]; int v[100005]; vector<pair<int, int> > e; int s0[100005], s1[100005]; int w[100005]; void add(int x, int y) { e.push_back(make_pair(x, y)); if (((int)e.size()) == m...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-9; int main() { cout << fixed << setprecision(12); int n, k; cin >> n >> k; vector<vector<int>> y(n, vector<int>(k + 1)); for (auto &yi : y) for (auto &yij : yi) cin >> yij; vector<double> sum(n); for (int j = 0;...
#include <bits/stdc++.h> using namespace std; const int maxn = 200010; int a[maxn]; int f[maxn]; int miss[maxn]; int sum[maxn]; int main() { int n, s; cin >> n >> s; for (int i = 1; i <= n; i++) { scanf( %d , &a[i]); } int ans1 = 0; if (a[s] != 0) { ans1++; a[s] =...
#include <bits/stdc++.h> using namespace std; long double PI = acos(-1); long double DEL = 1e-10; int M = 1e9 + 7; const int N = 3e5 + 10; #define ftt cin>>tc;for(int cas=1;cas<=tc;++cas) #define all(a) a.begin(),a.end() #define vpii vector<pair<int,int> > #define vvi vector<vector<int> > #defin...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const string nl = n ; vector<int> readVector(int n) { vector<int> ret(n); for (int i = 0; i < n; i++) cin >> ret[i]; return ret; } void setIO(string name) { freopen((name + .in ).c_str(), r , stdin); freopen...
#include <bits/stdc++.h> int n, m; char map[1010][1010], ans[1010][1010]; int main() { scanf( %d%d , &n, &m); for (int i = 1; i <= n; i++) scanf( %s , map[i] + 1); for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) ans[i][j] = . ; for (int i = 1; i <= n; i++) for (int j = 1; j ...
#include <bits/stdc++.h> using namespace std; long long n; struct mat { long long** val; mat() { val = new long long*[6]; for (int i = 0; i < 6; i++) { val[i] = new long long[6]; for (int j = 0; j < 6; j++) val[i][j] = 0; val[i][i] = 1; } } mat(long long v...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 100; const int mod = 1e9 + 7; int main() { ios::sync_with_stdio(0); int t; cin >> t; while (t--) { int n, x, y; cin >> n >> x >> y; cout << max(min(n, x + y - n + 1), 1) << << min(x + y - 1, n) << endl; ...
#include <bits/stdc++.h> using namespace std; using ll = long long; namespace SCCKosaraju { vector<vector<int>> adj, radj; vector<int> todo, comp, curr; vector<bool> vis; void dfs1(int x) { vis[x] = 1; for (int y : adj[x]) if (!vis[y]) dfs1(y); todo.push_back(x); } void dfs2(int x, i...
#include <bits/stdc++.h> using namespace std; const int Maxn = 10000005, p = 1e9 + 7; int n, k, cnt, phi[Maxn], prim[Maxn], sum[Maxn], ct[Maxn]; long long ans; bool vis[Maxn]; void init(void) { phi[1] = 1; for (int i = 2; i <= n; i++) { if (!vis[i]) prim[++cnt] = i, phi[i] = i - 1; for (...
#include <bits/stdc++.h> using namespace std; int a[100010], diff[100010]; int main() { int i, j, k, n, neg1, neg2, pos, ans, mx = -1, df, d; cin >> n; for (i = 0; i < n; i++) cin >> a[i]; for (i = 0; i < n - 1; i++) { diff[i] = a[i] - a[i + 1]; } i = 0; while (i < n - 1) { ...
#include <bits/stdc++.h> using namespace std; int n; char s[100000 + 10]; int num[30]; int main() { scanf( %d , &n); scanf( %s , s); sort(s, s + n); printf( %s n , s); }
#include <bits/stdc++.h> using namespace std; void fileioe() { freopen( input.txt , r , stdin); freopen( xyz.txt , w , stdout); freopen( error.txt , w , stderr); } const long long mod = 1000000007; const long long INF = 1e18; const long long MAX = 100001; void solve() { long long n; ...
#include <bits/stdc++.h> using namespace std; long long lkd(long long a, long long b) { while (b > 0) { long long c = b; b = a % b; a = c; } return a; } int main() { long long a, s, b = 1; cin >> a >> s; for (long long i = 0; i < s; i++) b = b * 10; cout << (a * b) ...
#include <bits/stdc++.h> using namespace std; const int M = 110000; long long a[M], b[M], c[M], be[M]; long long n, d, x; long long getNextX() { x = (x * 37 + 10007) % 1000000007; return x; } void initAB() { long long i; for (i = 0; i < n; i = i + 1) { a[i] = i + 1; } for (i ...
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 5; int ans[N << 1]; int main() { int n; cin >> n; int b1 = n + 1; int b2 = 2 * n - 1; int a1 = 1; int a2 = n; int cnt = 1; for (int i = 1; i <= n - 1; ++i) { if (cnt & 1) ans[a1++] = i, ans[a2--] = i;...
#include <bits/stdc++.h> typedef struct { long long s, l, r, m; } value; long long maxll(long long a, long long b) { return a > b ? a : b; } void sum(value *v, value *l, value *r) { v->s = l->s + r->s; v->l = maxll(l->l, l->s + r->l); v->r = maxll(r->r, r->s + l->r); v->m = maxll(l->r + r->l...
#include <bits/stdc++.h> using namespace std; template <class T> inline void read(T &x) { x = 0; char c = getchar(); bool f = 0; for (; !isdigit(c); c = getchar()) f ^= c == - ; for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^ 48); x = f ? -x : x; } int n, x, len, res,...
#include <bits/stdc++.h> #pragma optimization_level 3 #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops,fast-math,O3 ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx ) using namespace std; const long double PI = 3.14159265358979323846; const long long mod = 1e+9 + 7; const int I...
#include <bits/stdc++.h> using namespace std; const int maxn = 3005; int prv[maxn], nxt[maxn], cnt[maxn]; int le[maxn]; int r, c, n, k; vector<int> pos[maxn]; signed main(void) { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> r >> c >> n >> k; for (int i = 1; i <= n; ++i...
#include <bits/stdc++.h> using namespace std; string s[555]; int dp[555], v[555], ones[555]; vector<pair<int, int> > vc[555]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m, k; cin >> n >> m >> k; for (int i = 1; i <= n; i++) { cin >> s[i]; int ...
#include <bits/stdc++.h> using namespace std; const int MaxN = int(2e5) + 256; const int INF = int(1e9); const int mod = (int)(1e9) + 7; const double pi = 3.1415926535897932384626433832795; long long n, m, ans, A[MaxN], k, a, b, q; long long t[MaxN * 8], t1[MaxN * 8]; void upd(int v, int l, int r, int p...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, i, j; cin >> n; long long int a[n], b[n], t[n]; for (i = 1; i < n; i++) cin >> a[i]; for (i = 1; i < n; i++) cin >> b[i]; for (i = 0; i < 4; i++) { t[0] = i; for (j = 1; j < n; j++) { if (a[j] == ...
#include <bits/stdc++.h> using namespace std; int n, depth = 0; string loc[500]; string comm; int main() { cin >> n; for (int i = 0; i < n; ++i) { cin >> comm; if (comm == cd ) { cin >> comm; int pos = 0; if (comm[0] == / ) { depth = 0; pos = 1...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) #pragma comment(linker, /stack:200000000 ) #pragma GCC optimize( Ofast ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ...
#include <bits/stdc++.h> using namespace std; const long long oo = 1000000000000000000; const int N = 100005; int main() { int n, x; scanf( %d , &n); multiset<int> a, b; for (int i = 0; i < int(n); i++) { scanf( %d , &x); a.insert(x); } for (int i = 0; i < int(n - 1); i++) { ...
#include <bits/stdc++.h> using namespace std; const long double Eps = 1e-8; char what[27] = A??????HI???M?O????TUVWXY? ; char str[100005]; void input() { scanf( %s , str); } bool good() { int N = strlen(str); for (int i = 0; i < N; i++) { if (str[i] != what[str[N - i - 1] - A ]) return false...
#include <bits/stdc++.h> using namespace std; int main() { int h, w, x, y, star = 0, sum, flag; char arr[505][505]; cin >> h >> w; for (int i = 1; i <= h; i++) { for (int j = 1; j <= w; j++) { cin >> arr[i][j]; if (arr[i][j] == * ) { star++; if (arr[i][j - ...
#include <bits/stdc++.h> using namespace std; int n; long long s, x; int main() { srand(time(NULL)); cin >> n; n--; s = 1; x = 12; while (n) { s += x; x += 12; n--; } cout << s << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int M = 1e5 + 10; int a[M], col[M], flag; bool vis[M]; vector<int> vc[M]; vector<pair<int, int> > node[M]; void bfs(int sta) { col[sta] = 0; vis[sta] = true; queue<int> q; q.push(sta); while (!q.empty()) { int u = q.front(); ...
#include <bits/stdc++.h> using namespace std; int i, j, k, l; int n, m, d, a[100010][4]; int ms[11111]; double cx, cy, ccx, ccy; int x1, stupid_cmath, x2, y2; int main() { cin >> n; for (i = 0; i < n; ++i) { cin >> x1 >> stupid_cmath >> x2 >> y2; a[i][0] = ((x1) < (x2) ? (x1) : (x2)); ...
#include <bits/stdc++.h> using namespace std; int a, b, c, n; int main() { ios_base::sync_with_stdio(false); ; cin >> a >> b >> c >> n; if (a - c < 0 || b - c < 0) return cout << -1, 0; if (a + b - c >= n) return cout << -1, 0; cout << n - (a + b - c); return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 5; int n; string s; int main() { cin >> n; cin >> s; bool tmp = false; for (int i = 0; i <= s.size() - 1; i++) { if (s[i] > s[i + 1]) { tmp = true; s.erase(i, 1); break; } } if (!tmp) ...
#include <bits/stdc++.h> using namespace std; const int mx = 1e5 + 10; long long len, ans, val[26], s[mx]; char str[mx]; map<pair<long long, char>, long long> dp; int main() { for (int i = 0; i < 26; i++) scanf( %I64d , &val[i]); scanf( %s , str); len = strlen(str); s[0] = val[str[0] - a ];...
#include <bits/stdc++.h> using namespace std; int main() { int n, t, sum = 0, x; cin >> n >> x; while (n--) { cin >> t; sum += t; } if (sum < 0) sum *= -1; int ans = sum / x + bool(sum % x); cout << ans << endl; return 0; }
#include <bits/stdc++.h> int main() { int n; scanf( %d , &n); int p = 0; int a[100100]; for (int i = 0; i < n; i++) scanf( %d , &a[i]); int s = n + n - 1; for (int i = 0; i < n; i++) { s += fabs(a[i] - p); p = a[i]; } printf( %d n , s); }
#include <bits/stdc++.h> #pragma comment(linker, /STACK:100000000000000 ) using namespace std; const long long int INF = 2e9 + 1; char s[50000], s2[50000]; struct automato { struct leaf { int link, len; map<char, int> nex; bool cl; leaf() : cl(false) {} }; vector<leaf> tre...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); double n, k; cin >> n >> k; double a, b; cin >> a >> b; n--; double len = 0; while (n--) { double x, y; cin >> x >> y; len += ((double)sqrt(pow(x - a, 2) + pow(y ...
#include <bits/stdc++.h> using namespace std; const int N = 2e4; const int T = 24 * 60 * 60; int was, n, M, add, cnt, ans[N]; vector<int> ind[T]; int main() { scanf( %d%d%d , &n, &M, &add); for (int i = 0; i < (int)(n); i++) { int h, m, s; scanf( %d:%d:%d , &h, &m, &s); ind[s + 60 ...
#include <bits/stdc++.h> using namespace std; const int MOD = 998244353; int sum(int a, int b) { return (a + b) % MOD; } int prod(int a, int b) { return a * 1ll * b % MOD; } int mpow(int b, int e) { if (e == 0) return 1; if (e & 1) return prod(b, mpow(b, e - 1)); return mpow(prod(b, b), e / 2); ...
#include <bits/stdc++.h> using namespace std; int main() { long long n; bool a = false; cin >> n; for (long long i = 1; i < n; i++) { for (long long j = 1; j < n; j++) { if (((n - i - j) % 3) != 0 && (i % 3) != 0 && (j % 3) != 0) { cout << i << << j << << (n - i - j) ...
#include <bits/stdc++.h> using namespace std; int gi() { int x = 0, w = 1; char ch = getchar(); while ((ch < 0 || ch > 9 ) && ch != - ) ch = getchar(); if (ch == - ) w = 0, ch = getchar(); while (ch >= 0 && ch <= 9 ) x = (x << 3) + (x << 1) + ch - 0 , ch = getchar(); return w ...
#include <bits/stdc++.h> using namespace std; int n, s, k; vector<int> a; void Input() { cin >> n >> s >> k; a.clear(); a.resize(k); for (auto &z : a) cin >> z; } void Solve() { for (int i = 0; i <= k; i++) { if (s - i >= 1 && find(a.begin(), a.end(), s - i) == a.end()) { c...
#include <bits/stdc++.h> using namespace std; int main() { int n, i, j, a[102][102]; scanf( %d , &n); ; for (i = 0; i < n; i++) { for (j = 0; j < n; j++) scanf( %d , &a[i][j]); ; } if (i == 1) { printf( 0 n ); return 0; } for (i = 0; i < n; i++) { int f[...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; int a[t]; for (int i = 0; i < t; i++) { cin >> a[i]; if (360 % (180 - a[i]) == 0) cout << YES << endl; else cout << NO << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; template <class T> void chmax(T &a, T b) { if (a < b) a = b; } template <class T> void chmin(T &a, T b) { if (a > b) a = b; } constexpr long long INF = 1000000000000000000; constexpr long long mod = 1000000007; constexpr long double eps = 1e-8; ...
#include <bits/stdc++.h> using namespace std; void data() {} const int N = 1e6 + 100; const long long mod = 998244353; const long long mod2 = 1e9 + 7; map<int, int> was, was2; int main() { data(); int t; cin >> t; while (t--) { int n; cin >> n; int a[n + 1]; for (in...
#include <bits/stdc++.h> using namespace std; struct edge { int u, v; long long w; }; long long MOD = 1000000007; long long _MOD = 1000000009; double EPS = 1e-10; long long c[100][100]; long long C(long long n, long long k) { if (n < 100) return c[n][k]; long long ans = 1; for (int i...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:256000000 ) using namespace std; mt19937 ggen; int n, s; int a[200010]; int ctr[200010]; vector<int> v; void solve() { cin >> n >> s; s--; for (int i = 0; i < n; i++) cin >> a[i]; int ans = 0; if (a[s] != 0) ans++; for (int...
#include <bits/stdc++.h> using namespace std; template <typename T, bool maximum_mode = false> struct RMQ { int n = 0, levels = 0; vector<vector<T>> range_min; RMQ(const vector<T> &values = {}) { if (!values.empty()) build(values); } static int largest_bit(int x) { return 31 - __builtin_...
#include <bits/stdc++.h> using namespace std; const int mod = 1e4 + 7; const long long INF = 1e18; const int maxn = 6e5 + 5; int n, m, k; struct edge { int to, cost; edge() {} edge(int to, int cost) : to(to), cost(cost) {} }; vector<edge> G[maxn]; int d[maxn]; pair<int, int> p[maxn]; m...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a, b, c; int f1, f2, s1, s2, t1, t2; cin >> f1 >> f2 >> s1 >> s2 >> t1 >> t2; int sum1 = f1 + s1 + t1; a = f1; b = s1; c = t1; n -= sum1; if (n > 0) { f2 = f2 - f1; if (f2 < n) { ...
#include <bits/stdc++.h> using namespace std; int a[105]; int main() { int n, c, max = 0, t; scanf( %d%d , &n, &c); for (int i = 0; i < n; i++) scanf( %d , &a[i]); for (int i = 0; i < n - 1; i++) { t = a[i] - c; if (t < 0) continue; else { t -= a[i + 1]; i...
#include <bits/stdc++.h> using namespace std; const int MAX = 1e5 + 10; int main() { int a, b, c; while (cin >> a >> b >> c) { int s[MAX] = {0}; s[a]++; s[b]++; s[c]++; if (s[1] >= 1 || s[2] >= 2 || s[3] >= 3 || (s[2] == 1 && s[4] == 2)) printf( YES n ); else ...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000000; const int MAX = 100005; const int RIGHT = 131072; const int SIZE = 263000; double L[MAX], R[MAX], T[SIZE]; int X[MAX], H[MAX], N, M; pair<int, int> Mush[MAX]; void update(int l, int r, double p, int n, int a, int b) { ...
#include <bits/stdc++.h> using namespace std; const int N = (int)1e5 + 5, mod = (int)0; int best[N], q[N]; int main() { string s; cin >> s; int n = (int)s.size(); best[n] = 1e9; for (int j = n - 1; j >= 0; --j) { s[j] -= a ; best[j] = min(best[j + 1], (int)s[j]); } strin...
#include <bits/stdc++.h> using namespace std; string nb; int main() { int N; cin >> N; cin >> nb; string m; m.append(N, 9 ); string act = nb; for (int shift = 0; shift < N; shift++) { for (int p = 0; p <= 9; p++) { m = min(m, act); for (int i = 0; i < N; i++) act...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, m, l, a[100001], i, t = 0, p, d, k, w; cin >> n >> m >> l; for (i = 0; i < n; i++) cin >> a[i]; if (a[0] > l) t++; for (i = 1; i < n; i++) { if (a[i] >...
#include <bits/stdc++.h> using namespace std; int main() { string b, b1, b2, e1, e2, e; cin >> b1 >> b2 >> e1 >> e2; swap(b2[0], b2[1]); swap(e2[0], e2[1]); b = b1 + b2; e = e1 + e2; b.erase(b.find( X ), 1); e.erase(e.find( X ), 1); if ((b + b).find(e) != string::npos) { co...