inlineintrd(){ int x = 0; bool f = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) f |= (c == '-'); for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); return f ? -x : x; }
#define N 200007
ll f[N], ans;
intmain(){ int l = rd(), k = rd(); f[1] = f[k] = 1; ++k; for (int i = 3; i <= l; ++i) { f[i] += f[i - 2]; if (i > k) f[i] += f[i - k]; } for (int i = 1; i <= l; ++i) ans += f[i]; printf("%lld\n", ans); return0; }
inlineintrd(){ int x = 0; bool f = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) f |= (c == '-'); for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); return f ? -x : x; }
#define N 17 #define M 1007 #define fr first #define sc second
map<pii, int> f;
intgcd(int a, int b){return b ? gcd(b, a % b) : a;}
inlineintrd(){ int x = 0; bool f = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) f |= (c == '-'); for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); return f ? -x : x; }
intmain(){ int n = rd(), t = rd(), mx = 0; for (int i = 1; i <= n; ++i) { int nw = rd(); mx = max(mx, nw); if (t >= 0) t -= nw; // t is the starting time of the second check printf("%d\n", t < 0 ? 1 : t / mx + 2); } return0; }
inlineintrd(){ int x = 0; bool f = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) f |= (c == '-'); for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); return f ? -x : x; }
#define N 500007
char s[N], t[N];
int sum[N], f[N];
deque<int> pos;
intmain(){ pos.push_back(0); int n = rd(), m = rd(); scanf("%s", s + 1); scanf("%s", t + 1); for (int i = 1; i <= n; ++i) sum[i] = sum[i - 1] + (t[i] != t[i - 1]);
// the number of segments in [l, r] : sum[r] - sum[l + 1] + 1 auto val = [&](int p) {return2 * f[p] - sum[p + 1];}; for (int i = 1; i <= n; ++i) { if (s[i] == t[i]) f[i] = f[i - 1]; else { while (i - pos.front() > m) pos.pop_front(); f[i] = f[pos.front()] + (sum[i] - sum[pos.front() + 1] + 1) / 2 + 1; } while (!pos.empty() && val(pos.back()) >= val(i)) pos.pop_back(); pos.push_back(i); } printf("%d\n", f[n]); return0; }
inlineintrd(){ int x = 0; bool f = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) f |= (c == '-'); for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); return f ? -x : x; }
template<typename T> inlineboolgetmin(T &a, T b){return a > b ? (a = b, true) : false;}
#define mp make_pair
#define N 100007
int n, m, tot, hd[N], hdr[N];
structedge{int to, nxt, w;} e[N << 1];
voidadd(int u, int v, int w){ e[++tot] = {v, hd[u], w}; hd[u] = tot; e[++tot] = {u, hdr[v], w}; hdr[v] = tot; }
#define mod 1000000007
inlinevoidadd(int &a, int b){a = (a + b >= mod ? a + b - mod : a + b);}
bool use[N];
int cnt[2][N];
ll dis[2][N];
typedefpair<ll, int> cur;
priority_queue<cur, vector<cur>, greater<cur>> q;
inlinevoiddij(int u, int *h, int id){ memset(use, 0, sizeof(use)); dis[id][u] = 0; cnt[id][u] = 1; q.push(mp(0, u)); while (!q.empty()) { int u = q.top().second; q.pop(); if (use[u]) continue; use[u] = true; for (int i = h[u], v; i; i = e[i].nxt) if (getmin(dis[id][v = e[i].to], dis[id][u] + e[i].w)) { cnt[id][v] = cnt[id][u]; q.push(mp(dis[id][v], v)); } elseif (dis[id][v] == dis[id][u] + e[i].w) add(cnt[id][v], cnt[id][u]); } }
intmain(){ int n = rd(), m = rd(); for (int i = 1; i <= m; ++i) { int u = rd(), v = rd(), w = rd(); add(u, v, w); } memset(dis, 0x3f, sizeof(dis)); dij(1, hd, 0); dij(2, hdr, 1); ll mnd = dis[0][2]; for (int i = 1; i <= m; ++i) { int u = e[i * 2].to, v = e[i * 2 - 1].to, w = e[i * 2].w; if (dis[0][v] + dis[1][u] + w < mnd) puts("HAPPY"); elseif (dis[0][u] + dis[1][v] + w == mnd && 1ll * cnt[0][u] * cnt[1][v] % mod == cnt[0][2]) puts("SAD"); elseputs("SOSO"); } return0; }
inlineintrd(){ int x = 0; bool f = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) f |= (c == '-'); for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); return f ? -x : x; }
template<typename T> inlineboolgetmin(T &a, T b){return a > b ? (a = b, true) : false;}
#define mp make_pair
#define N 100007
int n, m, tot, hd[N], hdr[N];
structedge{int to, nxt, w;} e[N << 1];
voidadd(int u, int v, int w){ e[++tot] = {v, hd[u], w}; hd[u] = tot; e[++tot] = {u, hdr[v], w}; hdr[v] = tot; }
bool use[N];
int pos[N], sum[N];
ll dis[2][N];
typedefpair<ll, int> cur;
priority_queue<cur, vector<cur>, greater<cur>> q;
inlinevoiddij(int u, int *h, int id){ memset(use, 0, sizeof(use)); dis[id][u] = 0; q.push(mp(0, u)); while (!q.empty()) { int u = q.top().second; q.pop(); if (use[u]) continue; use[u] = true; if (!id) pos[u] = ++pos[0]; for (int i = h[u], v; i; i = e[i].nxt) if (getmin(dis[id][v = e[i].to], dis[id][u] + e[i].w)) q.push(mp(dis[id][v], v)); } }
intmain(){ int n = rd(), m = rd(); for (int i = 1; i <= m; ++i) { int u = rd(), v = rd(), w = rd(); add(u, v, w); } memset(dis, 0x3f, sizeof(dis)); dij(1, hd, 0); dij(2, hdr, 1); ll mnd = dis[0][2]; for (int u = 1; u <= n; ++u) for (int i = hd[u], v; i; i = e[i].nxt) if (dis[0][u] + e[i].w + dis[1][v = e[i].to] == mnd) {++sum[pos[u]]; --sum[pos[v]];} for (int i = 1; i <= n; ++i) sum[i] += sum[i - 1]; for (int i = 1; i <= m; ++i) { int u = e[i * 2].to, v = e[i * 2 - 1].to, w = e[i * 2].w; if (dis[0][v] + dis[1][u] + w < mnd) puts("HAPPY"); elseif (dis[0][u] + dis[1][v] + w == mnd && sum[pos[u]] == 1) puts("SAD"); elseputs("SOSO"); } return0; }
inlineintrd(){ int x = 0; bool f = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) f |= (c == '-'); for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); return f ? -x : x; }
constdouble pi = 3.141592653589793; constdouble sin60 = sqrt(3) / 2.0;
// A = 0 | B = 1 | C = 2 | D = 3 || sum = 6
vector<int> simulate(int x, int y, int tar, double pos, double ang, double rem){ //printf("%d %d %d %.3lf %.3lf %.3lf\n", x, y, tar, pos, ang, rem); double angtar = acos((2 * pos - 1) / 2.0 / sqrt(pos * pos + 1 - pos)); if (ang < angtar) { double len = pos * sin60 / sin(pi * 2 / 3 - ang); if (rem <= len) returnvector<int>{x, y, tar}; return simulate(x, tar, 6 - x - y - tar, sin(ang) / sin(pi * 2 / 3 - ang) * pos, pi / 3 + ang, rem - len); } else { double len = (1 - pos) * sin60 / sin(ang - pi / 3); if (rem <= len) returnvector<int>{x, y, tar}; return simulate(tar, y, 6 - x - y - tar, 1 - sin(ang) / sin(ang - pi / 3) * (1 - pos), ang - pi / 3, rem - len); } }
intmain(){
auto rdv = [&]() { char c = getchar(); while (!isalpha(c)) c = getchar(); return c - 'A'; };
auto getpos = [&]() { int x = rdv(), y = rdv(); double ang = rd() * pi / 180, l = rd(); double step1 = sin60 / sin(pi * 2 / 3 - ang); // The Law of Sines if (step1 >= l) returnvector<int>{0, x, y}; elsereturn simulate(x, y, 6 - x - y, sin(ang) / sin(pi * 2 / 3 - ang), pi / 3 + ang, l - step1); }; vector<int> pos1 = getpos(); sort(pos1.begin(), pos1.end()); vector<int> pos2 = getpos(); sort(pos2.begin(), pos2.end()); puts(pos1 == pos2 ? "YES" : "NO"); return0; }
inlineintrd(){ int x = 0; bool f = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) f |= (c == '-'); for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); return f ? -x : x; }
inlineboolgetmin(int &a, int b){return (a > b ? (a = b, true) : false);} inlineboolgetmax(int &a, int b){return (a < b ? (a = b, true) : false);}
// F is the type of flow template<constint V, constint E, classF, constFflowInf> structFlow {
int tot = 1, S, T, hd[V], cur[V], dis[V]; structedge{int to, nxt; F cap;} e[E << 1];
voidclear(){tot = 1; memset(hd, 0, sizeof(hd));} voidadd(int u, int v, F w){ e[++tot].nxt = hd[u], hd[u] = tot, e[tot].to = v, e[tot].cap = w; e[++tot].nxt = hd[v], hd[v] = tot, e[tot].to = u, e[tot].cap = 0; } inlineboolbfs(){ staticint q[V], qhd, qtl; memcpy(cur, hd, sizeof(hd)); memset(dis, -1, sizeof(dis)); q[qhd = qtl = 1] = S; dis[S] = 0; while (qhd <= qtl) { int u = q[qhd++]; for (int i = hd[u], v; i; i = e[i].nxt) if (dis[v = e[i].to] == -1 && e[i].cap != 0) { dis[v] = dis[u] + 1; q[++qtl] = v; } } return dis[T] != -1; } F dfs(int u, F rem){ if (u == T) return rem; F flow = 0; for (int i = cur[u], v; i && rem; i = e[i].nxt) { cur[u] = i; v = e[i].to; F nw = min(rem, e[i].cap); if (nw != 0 && dis[v] == dis[u] + 1) { int ret = dfs(v, nw); flow += ret; rem -= ret; e[i].cap -= ret; e[i ^ 1].cap += ret; } } if (flow == 0) dis[u] = -1; return flow; } F dinic(int source, int sink){ S = source; T = sink; F flow = 0; while (bfs()) flow += dfs(S, flowInf); return flow; } };
#define N 1207 #define M 1000007
Flow<N, M, int, 1000000000> f;
int l[N], r[N];
intmain(){ int n = rd(), m = rd(); int S = N - 1, T = N - 2; for (int i = 1; i <= 400; ++i) f.add(S, i, 1); for (int i = 1; i <= n; ++i) { l[i] = rd(); r[i] = rd(); f.add(400 + i, T, 1); for (int j = l[i]; j <= r[i]; ++j) f.add(j, 400 + i, 1); } printf("%d\n", f.dinic(S, T)); f.clear(); for (int i = 1; i <= 400; ++i) f.add(i, 400 + i, 1); for (int i = 1; i <= m; ++i) { f.add(S, 800 + i, 1); for (int j = l[i]; j <= r[i]; ++j) f.add(800 + i, j, 1); } for (int i = m + 1; i <= n; ++i) { f.add(800 + i, T, 1); for (int j = l[i]; j <= r[i]; ++j) f.add(400 + j, 800 + i, 1); } printf("%d\n", f.dinic(S, T)); return0; }
inlineintrd(){ int x = 0; bool f = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) f |= (c == '-'); for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); return f ? -x : x; }
template<typename T> inlineboolgetmin(T &a, T b){return a > b ? (a = b, true) : false;}
#define N 200007
int sum[N];
pii s[N];
priority_queue<int, vector<int>, greater<int>> q;
intmain(){ int n = rd(); for (int i = 1; i <= n; ++i) { int l = rd(), r = rd() - 1; s[i] = make_pair(l, r); ++sum[l]; --sum[r + 1]; } sort(s + 1, s + 1 + n); int ans = 0; for (int i = 1; i <= n; ++i) { int l = i, r = n; while (!q.empty() && q.top() < s[i].first) q.pop(); while (l < r) { int mid = (l + r + 1) / 2; s[mid].first <= s[i].second ? l = mid : r = mid - 1; } q.push(s[i].second); ans = max(ans, r - i + (int)q.size()); } printf("%d ", ans); ans = 0; for (int i = 1; i < N; ++i) {sum[i] += sum[i - 1]; ans = max(ans, sum[i]);} printf("%d\n", ans); return0; }
inlineintrd(){ int x = 0; bool f = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) f |= (c == '-'); for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); return f ? -x : x; }
#define N 1007
pair<int, char> hint[N];
int y[N], h[N], tot;
structsegpair{int l, r, h;} s[N];
map<int, char> f;
intmain(){ int n = rd(), a = rd(), b = rd(), q = rd(); for (int i = 1; i <= a; ++i) { int p = rd(); char c = getchar(); while (!isalpha(c)) c = getchar(); hint[i] = {p, c}; } for (int i = 1; i <= b; ++i) {y[i] = rd(); h[i] = rd();} y[b + 1] = n + 1; for (int i = 1; i <= b; ++i) if (h[i]) s[++tot] = {y[i], y[i + 1] - 1, h[i]};
auto find = [&](int p) { if (!tot) return p; for (int i = tot; i; --i) { if (p > s[i].r) return p; if (p < s[i].l) continue; p = s[i].h + (p - s[i].h) % (s[i].l - s[i].h); } return p; };
for (int i = 1; i <= a; ++i) f[find(hint[i].first)] = hint[i].second; for (int i = 1; i <= q; ++i) { int pos = find(rd()); putchar(f.find(pos) == f.end() ? '?' : f[pos]); } return0; }