func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int main() { int n, a; scanf( %d %d %*d , &n, &a); map<long long, int> cnt1; map<pair<int, int>, int> cnt2; long long ans = 0; for (int i = 0; i < n; ++i) { int vx, vy; scanf( %*d %d %d , &vx, &vy); long long v = 1LL * a * vx - ...
#include <bits/stdc++.h> using namespace std; long long L[200005], R[200005], U[200005], D[200005]; long long n; string S; long long x, y, sx = 0, sy = 0; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> S >> x >> y; S = _ + S; L[0] = R[0] = U[...
#include <bits/stdc++.h> using namespace std; const int N = 500023; bool vis[N]; vector<int> adj[N]; void solve() { long long int n; cin >> n; vector<long long int> v; for (long long int i = 0; i < n; i++) { long long int c; cin >> c; v.push_back(c); } sort((v).begin(...
#include <bits/stdc++.h> using namespace std; long long fact(int x) { long long ans = 0; while (x > 0) { ans += x; x--; } return ans; } int main() { int n; cin >> n; vector<vector<char> > a(n, vector<char>(n)); for (int i = 0; i < n; i++) for (int j = 0; j < n; ...
#include <bits/stdc++.h> using namespace std; int n, m, ans, a[300010]; bool check(int mid) { int pre = mid + a[1] >= m ? 0 : a[1]; for (int i = 2; i <= n; i++) { if (a[i] + mid < pre) return false; if (a[i] <= pre) continue; else if (a[i] + mid >= m && (a[i] + mid) % m >= pre) ...
#include <bits/stdc++.h> using namespace std; #define int unsigned long long const int N = 100010; int n, a[N]; signed main(void) { ios::sync_with_stdio(false); map <int, int> mp; int T; cin >> T; while(T--) { mp.clear(); int res = 0; i...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast,fast-math,unroll-loops ) using namespace std; const int maxn = 2e5 + 50; inline char nc() { static char buf[100000], *p1 = buf, *p2 = buf; return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF ...
#include <bits/stdc++.h> using namespace std; int m; long long n; long long deg[1001001], result; vector<vector<int> > e; int main() { scanf( %d%d , &n, &m); for (int i = 0; i < m; i++) { int a, b; scanf( %d%d , &a, &b); deg[a]++; deg[b]++; } result = 0; for (int ...
#include <bits/stdc++.h> const int MAXN = 1e5 + 19; int qpow(int a, int b, int p) { int res = 1; while (b) { if (b & 1) res = (long long)res * a % p; a = (long long)a * a % p, b >>= 1; } return res; } int n, m, k, p; int fa[MAXN], size[MAXN]; int getf(int node) { return fa[no...
#include <bits/stdc++.h> using namespace std; int main() { vector<long long int> vec1, vec2; vector<long long int>::iterator it; long long int n, a, sz, s1 = 0, s2 = 0, s3 = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> a; s1 += a; } n--; for (int i = 0; i < n; i++) {...
#include <bits/stdc++.h> using namespace std; const int inf = 2000000000; const int maxn = 1000005; int n; int a[maxn]; bool vis[maxn]; int main() { long long ans = 0LL; scanf( %d , &n); for (int i = n; i >= 0; i--) { if (vis[i]) continue; int t = 0, s = 0; for (int j = 0; j ...
#include <bits/stdc++.h> using namespace std; int fail[1000006]; int main() { int n, k; cin >> n >> k; string s; cin >> s; fail[-1] = fail[0] = -1; for (int i = 1; i < n; ++i) { int ptr = i - 1; while (s[i] != s[fail[ptr] + 1] && ptr > 0) ptr = fail[ptr]; fail[i] = fail[p...
#include <bits/stdc++.h> using namespace std; long long min(long long x, long long y) { return (x < y) ? x : y; } long long max(long long x, long long y) { return (x > y) ? x : y; } const int N = 100009; int x, y, n, m, i, u, w, z, sum, best, j, k, t, mx; int a[N]; string s, ans; int main() { ios_ba...
#include <bits/stdc++.h> using namespace std; vector<int> V[1005]; int dis[1005], rdis[1005], G[1005][1005]; void spfa(int s, int e) { queue<int> Q; memset(dis, 0x3f, sizeof(dis)); memset(rdis, 0x3f, sizeof(rdis)); Q.push(s); dis[s] = 0; while (!Q.empty()) { int f = Q.front(); ...
#include <bits/stdc++.h> typedef long long ll; using namespace std; int k; int addk(int a,int b) { int base,aw,bw,ret=0; for(base=1;base<=max(a,b);base*=k) { aw=a/base%k; bw=b/base%k; ret+=(aw+bw)%k*base; } return ret; } int subk(int a,int b) { int base,aw,bw,ret=...
#include <bits/stdc++.h> using namespace std; int n, k; const int maxn = 1e5 + 10; stack<int> max_seen; int ans[maxn]; vector<int> to[maxn]; void calc(int a) { int s = max(a - k, 0), t = min(n, a + k + 1); if (max_seen.empty()) ans[a] += t - s; else ans[a] += t - max(max_seen.top()...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; long ans = 0; for (int i = 0; i < n; i++) { if ((s[i] - 0 ) % 2 == 0) ans += (i + 1); } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 35; int n, m; int a[MAXN][MAXN]; int part[MAXN][MAXN], partn = 0; long long ans = 0; int x[MAXN][2]; int res[MAXN][MAXN]; int c[MAXN]; int u[MAXN]; void read() { scanf( %d%d , &n, &m); for (int i = 1; i <= n; i++) { char ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; long long c = n, maxi = INT_MIN, mini = INT_MIN, t = 0; for (int i = 0; i < n; i++) { cin >> a[i]; if (maxi != a[i]) { maxi = a[i]; mini = a[i]; t = 1; } else { ...
#include <bits/stdc++.h> using namespace std; int ar[305][305]; vector<pair<int, int> > poss[90005]; int dp[305][305]; vector<int> col[305]; int vis[305]; int n, m, p; void pr() {} void solve() { memset(dp, 127, sizeof(dp)); ; scanf( %d %d %d , &n, &m, &p); for (int i = 0; i < (int)(n)...
#include <bits/stdc++.h> using namespace std; const int INF = (int)2E9; const long long LINF = (long long)9E18; const long double PI = acos(-1.0); const long double EPS = 1E-11; template <typename T> inline T sqr(const T x) { return x * x; } template <typename T> T gcd(T a, T b) { return (b ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int cnt[1001] = {0}, a[n]; for (int i = 0; i < n; ++i) { cin >> a[i]; cnt[a[i]] = i; } int vis[1001] = {0}; vector<int> res; for (int i = 0; i < n; i++) { if (cnt[a[i]] == i) res.push_back(a...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC target( avx,avx2,fma ) #pragma GCC optimization( unroll-loops ) using namespace std; using namespace chrono; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cout << name << : << arg1 << n ; } template <type...
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf( %d , &n); char ar[n + 2]; char br[n + 2]; scanf( %s%s , ar + 1, br + 1); vector<int> v[2]; for (int i = 1; i <= n; i++) { if (ar[i] != br[i]) { if (ar[i] == a ) v[0].push_back(i); el...
#include <bits/stdc++.h> using namespace std; int k; int n; int planks[1005]; int g = 0; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> k; for (int t = 0; t < k; t++) { cin >> n; for (int i = 0; i < n; i++) cin >> planks[i]; sort(planks, ...
#include <bits/stdc++.h> using namespace std; long long A[200005]; long long fast_pow(long long a, long long b) { long long res = 1; while (b > 0) { if (b & 1) res = (res * a) % 1000000007; a = (a * a) % 1000000007; b >>= 1; } return res; } int main() { long long div = 1,...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; if ((n == 1 && k > 0) || (k == 0 && n > 1) || k < n / 2) cout << -1; else if (k == 0) cout << 1; else { int x = k - (n - 2) / 2; cout << x << << x * 2 << ; for (int i = 1; i <...
#include <bits/stdc++.h> using namespace std; const int N = 2001000, mod = 998244353; int n, a[N], b[N], f[N], ans, sum, inv[N]; void Init() { f[0] = inv[1] = 1; f[1] = n; for (int i = 2; i < N; ++i) { inv[i] = mod - mod / i * (long long)inv[mod % i] % mod; f[i] = (long long)f[i - 1] * (...
#include <bits/stdc++.h> using namespace std; struct mat { long double x[51][51]; } mi, ma; int n, p; long double pa, push_back, aa[51][51], bb[51][51], dp[51][51], ta, tb, ans; mat tim(mat a, mat b) { mat re; for (int c = 0; c < 51; c++) for (int d = 0; d < 51; d++) { re.x[c][d] =...
#include <bits/stdc++.h> using namespace std; int sum[51], ind[51]; int main() { for (int i = 1; i <= 50; ++i) sum[i] = i * (i + 1) / 2; for (int i = 1; i <= 50; ++i) ind[i] = i; int n, temp, reqind; cin >> n; for (int i = 1; i <= 50; ++i) { if (n <= sum[i]) { temp = sum[i]; ...
#include <bits/stdc++.h> using namespace std; int main() { long long n, m; cin >> n >> m; for (long long i = 1; i <= n; i++) { long long s, f, t; cin >> s >> f >> t; if (s == f) { cout << t << endl; } else if (s < f) { long long t1 = s - 1; while (t1 < t) ...
#include <bits/stdc++.h> using namespace std; const int maxn = 405; const int inf = 0x3f3f3f3f; int n, m; int a[maxn]; int f[maxn][maxn][maxn]; template <typename T> inline void minimize(T &target, const T &value) { if (target > value) { target = value; } } void divide(int a[], int f[]...
#include <bits/stdc++.h> using namespace std; pair<int, int> pairs[2 * 100000 + 10]; vector<int> adj[100000 + 10]; bool done[100000 + 10]; int result[100000 + 10]; void check(int N) { bool adj[N + 2][N + 2]; memset(adj, false, sizeof(adj)); for (int i = 1; i <= 2 * N; i++) { scanf( %d %d ,...
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1); struct Comp { double re, im; Comp(double x = 0.0, double y = 0.0) : re(x), im(y) {} Comp operator+(const Comp& rhs) const { return Comp(re + rhs.re, im + rhs.im); } Comp operator-(const Comp& rhs) const { ret...
#include <bits/stdc++.h> using namespace std; int a[110], b[110]; int main() { int n, m, i, j; cin >> n >> m; for (i = 1; i <= m; i++) cin >> a[i]; for (i = 1; i <= m; i++) for (j = a[i]; b[j] == 0; j++) b[j] = a[i]; for (i = 1; i <= n; i++) cout << b[i] << ; return 0; }
#include <bits/stdc++.h> using namespace std; long long a[100100], b[100100]; int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); long long n, m, cl, ce, v, x1, y1, x2, y2, q, mi; cin >> n >> m >> cl >> ce >> v; for (long long i = 0; i < cl; i++) cin >> a[i]; for (long long i = 0; i...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(NULL); cin.tie(NULL); string com; cin >> com; string s[5]; for (int i = 0; i < 5; i++) { cin >> s[i]; if (s[i][0] == com[0] || s[i][1] == com[1]) { cout << YES ; return 0; ...
#include <bits/stdc++.h> using namespace std; vector<int> adj[200001]; bool vis[200001]; int en = -1; int a[200005], b[200005]; void dfs(int x) { vis[x] = 1; for (auto it = adj[x].begin(); it != adj[x].end(); ++it) { if (!vis[*it]) { dfs(*it); } } if (en == -1) en = x; ...
#include <bits/stdc++.h> using namespace std; int n, p; long long fac[250005], ans; int main() { scanf( %d%d , &n, &p); fac[0] = 1; for (int i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % p; for (int i = 1; i <= n; i++) ans = (ans + fac[n - i + 1] * (n - i + 1) % p * fac[i] % p) % p; pr...
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; long long s[n]; for (long long c = 0; c < n; c++) cin >> s[c]; long long sum = 0; long long nextAllowedNum = 10000000000000 + 33; for (long long c = n - 1; c >= 0; c--) { if (nextAllowedNum <= 0) brea...
#include <bits/stdc++.h> using namespace std; void vin(vector<long long int> &v, long long int t) { for (long long int i = 0; i < t; i++) cin >> v[i]; } void vout(vector<long long int> &v, long long int t) { for (long long int i = 0; i < t; i++) cout << v[i] << ; cout << endl; } void ingraph(...
#include <bits/stdc++.h> using namespace std; inline int gi() { char c = getchar(); int x = 0, f = 1; for (; c < 0 || c > 9 ; c = getchar()) if (c == - ) f = -1; for (; c >= 0 && c <= 9 ; c = getchar()) x = (x << 1) + (x << 3) + c - 0 ; return x * f; } const int N = 5e5 + 5, Mo...
#include <bits/stdc++.h> using namespace std; const long long N = 2e5 + 7, inf = 1e9; long long n, m, cnt, ans; long long a[N], b[N], c[N], tr[N]; long long lowbit(long long x) { return x & -x; } long long query(long long x) { long long sum = 0; for (; x; x -= lowbit(x)) sum += tr[x]; return sum...
#include <bits/stdc++.h> using namespace std; const long long maxn = 1e6 + 10; long long n, k, A[maxn]; int32_t main() { ios_base::sync_with_stdio(false); cin >> n; for (long long i = 0; i < n; i++) { long long a, b, c, d; cin >> a >> b >> c >> d; if (a > b * c) { cout << -...
#include <bits/stdc++.h> using namespace std; struct Boot { int _pos; char _char; }; struct PairBoots { Boot _left; Boot _right; }; int main() { int n; string leftBoots; string rightBoots; vector<vector<Boot>> leftBootsBucket(27); vector<vector<Boot>> rightBootsBucket(27)...
#include <bits/stdc++.h> bool choice_first(std::vector<size_t> a, std::vector<size_t> b) { uint64_t sum_a, sum_b; sum_a = sum_b = 0; for (auto elem : a) { sum_a += elem; } for (auto elem : b) { sum_b += elem; } return sum_a > sum_b || (sum_a == sum_b && a < b); } int main()...
#include <bits/stdc++.h> using namespace std; template <typename T> inline T abs(T zz) { return zz < 0 ? -zz : zz; } template <typename T> inline T sqr(T zz) { return zz * zz; } const int MAGIC = 1000500; vector<int> used; vector<int> primes; bool is_prime(int n) { for (int p : primes)...
#include <bits/stdc++.h> using namespace std; int main() { int ans = 0, n; string s; cin >> n; for (int i = 1; i <= n; i++) { cin >> s; int flag = 0; for (int i = 0; i < s.length(); i++) if (s[i] == + ) flag = 1; if (flag) ans += 1; else ans -= ...
#include <bits/stdc++.h> using namespace std; double R, r; struct Punct { double x, y; }; Punct A, B; inline double Dist(Punct A, Punct B) { return sqrt((A.x - B.x) * (A.x - B.x) + (A.y - B.y) * (A.y - B.y)); } int main() { double d; cin >> A.x >> A.y >> R; cin >> B.x >> B.y >> r; ...
#include <bits/stdc++.h> using namespace std; void smain(); int main() { ios_base::sync_with_stdio(0); cout.precision(12); cout << fixed; smain(); return 0; } int n; int ans[1000001]; int f[1000001]; inline int sum(int r) { int result = 0; for (; r >= 0; r = (r & (r + 1)) - 1...
#include <bits/stdc++.h> using namespace std; int dx[] = {0, 0, -1, 1}; int dy[] = {-1, 1, 0, 0}; const int N = 1e6 + 5; long long ans, sum, d[N]; int n, m; int main() { int a, b; while (~scanf( %d%d , &n, &m)) { memset(d, 0, sizeof(d)); for (int i = 0; i < (m); ++i) { scanf( %...
#include <bits/stdc++.h> using namespace std; long long n, a[200009], ans = 1, b[200009], sum = 1; bool vis[200009]; void dfs(long long x) { if (vis[x]) return; vis[x] = 1; dfs(a[x]); } int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) cin ...
#include <bits/stdc++.h> using namespace std; int dp[2][105]; int main() { int c, w, h, c2; cin >> c >> w >> h; c2 = (c + 1) >> 1; int *src = dp[0], *dst = dp[1]; src[0] = 1; for (int i = 1; i <= w; i++) src[i] = 0; while (c2--) { dst[0] = src[0]; for (int i = 1; i <= w; i+...
#include <bits/stdc++.h> const int N = 1e6 + 10; const int mod = 1e9 + 7; const int INF = 0x3f3f3f3f; using namespace std; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } int n, m; long long f[N]; int main(...
#include <bits/stdc++.h> using namespace std; const int N = 200010; const int px[] = {0, 0, 1, -1}, py[] = {1, -1, 0, 0}; int n, m, a[1010][1010], tx[N], ty[N], f[N], ch[N][2], rev[N], tr[N * 4], cnt[N * 4], tag[N * 4]; long long ans; bool isroot(int x) { return !x || !f[x] || (ch[f[x]][0] != x &&...
#include <bits/stdc++.h> using namespace std; struct lhy { int x, y, l, r, id; } b[400040]; int n, m, mN, ans; int cnt[400040], a[400040], Ans[400040], c[2 * 400040], C[2 * 400040], L[400040], R[400040], x[2 * 400040]; inline void add(int x, int o) { for (; x <= mN; x += x & -x) c[x] = max(c[x...
#include <bits/stdc++.h> using namespace std; long long n, a[100069], dv; int main() { long long i, j, z = 1; scanf( %lld%lld , &n, &dv); if (n > dv) { printf( 0 n ); return 0; } for (i = 1; i <= n; i++) { scanf( %lld , a + i); for (j = 1; j < i; j++) { z = z * ...
#include <bits/stdc++.h> using namespace std; int f(string s, int i) { if (s[i] == ( ) return 0; if (s[i] == [ ) return 1; if (s[i] == 8 ) return 2; } int main() { int a, b; string s1, s2; cin >> s1 >> s2; a = b = 0; for (int i = 0; i < s1.size(); i += 2) { if ((f(s1, i)...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int max_n = 200005; vector<pair<int, int>> g[max_n]; int sz[max_n]; long long dis[max_n]; void dfs(int x) { sz[x] = 1; for (auto p : g[x]) { int u = p.first; if (sz[u]) continue; dis[u] = p.second; ...
#include <bits/stdc++.h> using namespace std; int main() { long long n, i, tmp_ara1, tmp_ara2; vector<long long> ara1(2000007, -1), ara2(2000007, -1), ans(200007, -1), in_front; cin >> n; for (i = 1; i <= n; i++) { cin >> tmp_ara1 >> tmp_ara2; ara1[tmp_ara1] = tmp_ara2; ara...
#include <bits/stdc++.h> using namespace std; int n, m; char gird[64][64]; set<long long int> set_of_cols; int main(void) { int i, j; scanf( %d%d , &n, &m); for (i = 0; i < n; ++i) scanf( %s , gird[i]); for (i = 0; i < n; ++i) { long long int id = 0; for (j = 0; j < m; ++j) { ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); string str; cin >> str; int t; cin >> t; int type, pos, l, r; char c; set<int> s[26]; for (int i = 0; i < str.length(); i++) s[str[i] - a ].insert(i + 1); while (t...
#include <bits/stdc++.h> using namespace std; bool check(char a) { if (a == a || a == e || a == i || a == o || a == u ) return true; if (a == 1 || a == 3 || a == 5 || a == 7 || a == 9 ) return true; return false; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); ...
#include <bits/stdc++.h> using namespace std; int main() { int t; string s; getline(cin, s); long long n = s.size(), i; for (i = n - 1; i >= 0; i--) { if (isupper(s[i])) { s[i] = tolower(s[i]); } if (s[i] == ? || s[i] == ) { continue; } else if (s[i] ...
#include <bits/stdc++.h> long long inp() { char c = getchar(); int neg = 1; while (c < 0 || c > 9 ) { if (c == - ) neg = -1; c = getchar(); } long long sum = 0; while (c >= 0 && c <= 9 ) { sum = sum * 10 + c - 0 ; c = getchar(); } return sum * neg; } ...
#include <bits/stdc++.h> using namespace std; pair<int, int> s[100010]; int a[100010], b[100010]; int main() { int N, P, i, x; scanf( %d n , &N); for (i = 0; i < N; i++) { scanf( %d , &x); s[i] = make_pair(x, i); } sort(s, s + N); P = N / 3; for (i = 0; i < P; i++) { ...
#include <bits/stdc++.h> using namespace std; int n, m, t[100010], nowt, pos, ans[100010]; pair<int, int> a[100010]; int main() { scanf( %d%d , &n, &m); for (int i = 1; i <= n; ++i) { scanf( %d%d , &t[i], &a[i].first); a[i].second = i; } for (int i = 1, j; i <= n; i = j + 1) { ...
#include <bits/stdc++.h> using namespace std; long long fastPow(long long a, long long b) { long long ret = 1; while (b) { if (b & 1) ret *= a; a *= a; b >>= 1; } return ret; } int main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); long long n, e, o, ce, co,...
#include <bits/stdc++.h> template <typename T> void MACRO_VAR_Scan(T& t) { std::cin >> t; } template <typename First, typename... Rest> void MACRO_VAR_Scan(First& first, Rest&... rest) { std::cin >> first; MACRO_VAR_Scan(rest...); } template <typename T> void MACRO_VEC_ROW_Init(int n, T& t) ...
#include <bits/stdc++.h> int cut; int q[100005] = {0}; int totalnode, totaledge, i, j, k, l, a, b, t1, t2; int c(int q) { if (q == 2) { return cut; } else if (q == cut) { return 2; } else return q; } int main() { for (i = 0; i < 100005; i++) q[i] = i; scanf( %d %d %d , ...
#include <bits/stdc++.h> using namespace std; struct Date { int y, m, d; }; const int monthDays[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int countLeapYears(Date d) { int years = d.y; if (d.m <= 2) years--; return years / 4 - years / 100 + years / 400; } int getDifference(Dat...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e16; long long n, a[200005], p[200005], MA = 0, z = 0; int main() { scanf( %lld , &n); memset(p, 0, sizeof(p)); for (int i = 0; i < n; i++) { scanf( %lld , &a[i]); p[a[i]]++; if (p[a[i]] > MA) { MA = p[a[i...
#include <bits/stdc++.h> using namespace std; set<pair<pair<long long int, long long int>, long long int> > ev; vector<long long int> cnt, len; multiset<pair<long long int, long long int> > flug; void expand( set<pair<pair<long long int, long long int>, long long int> >::iterator it, long long int...
#include <bits/stdc++.h> using namespace std; const long double eps = 1e-9; const long long MOD = 1e9 + 7; const int N = 2e6 + 10; const long double pi = 3.1415926535897932384650288; int n, m; string s, t; bool ok(int i, int j, int d) { if (j == m) return 1; if (i == n) return 0; if (i < 0) ...
#include <bits/stdc++.h> using namespace std; int readint() { int x = 0, f = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) f = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) { x = x * 10 + ch - 0 ; ch = getchar(); } return x * f; }...
#include <bits/stdc++.h> using namespace std; template <typename T> inline T read() { T x = 0, f = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) f = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) { x = (x << 1) + (x << 3) + (ch ^ 48); ch = ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int arr[102]; int n; cin >> n; for (int i = 1; i <= n; i++) cin >> arr[i]; int myseq[102]; for (int i = 1; i <= n; i++) { if (i & 1) myseq[i] = arr[i + 1]; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 2005; const long long mod = 998244353; string s, t; long long p[maxn], n; long long dp[maxn][maxn]; long long ksm(long long a, long long b) { long long r = 1; while (b) { if (b & 1) r = (r * a) % mod; a = a * a % mod; ...
#include <bits/stdc++.h> const char en = n ; using namespace std; int main() { ios::sync_with_stdio(false); int n; cin >> n; vector<long long> V(n + 47, 0); long long ma2 = 0; long long ma3 = 0; vector<long long> X; for (int i = 0; i < n; i++) { cin >> V[i]; long long...
#include <bits/stdc++.h> using namespace std; const int oo = 1000000000; const double H = sqrt(3.0) * 0.5; const double eps = 1e-6; int main() { double r; scanf( %lf , &r); int i; long long ans = 0; for (i = 0; i <= r; i++) { double x = 1.5 * i + 1.0; if (x > r) break; do...
#include <bits/stdc++.h> using namespace std; void solve() { string s; cin >> s; unordered_map<char, vector<long long int> > um; long long int i; for (i = 0; i < s.length(); i++) { um[s[i]].push_back(i); } long long int last = -1; bool flag; string ans = ; for (i = 25...
#include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; using ll = long long; const int N = 3e3 + 3; int a[N][N]; pii sum[N]; int main() { ios_base::sync_with_stdio(false); int n, m; cin >> n >> m; for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) cin >> a[i...
#include <bits/stdc++.h> using namespace std; const int N = 1000005; long long A[N], B[N], n, xx, mx; bool check(int n, int m) { int x = n - xx, y = mx - x; if (x < 0 || x >= n || y < 0 || y >= m) return 0; memset(B, 0, sizeof(B)); for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) ++...
#include <bits/stdc++.h> using namespace std; char A[1005][1005]; int P[1000005], MinX[1000005], MinY[1000005], MaxX[1000005], MaxY[1000005], M[1005][1005]; int xr[] = {-1, 1, 0, 0}; int xc[] = {0, 0, -1, 1}; int n, m; void dfs(int x, int y, int i) { if ((x < 0) || (x >= n) || (y < 0) || (y >= m...
#include <bits/stdc++.h> using namespace std; const int _5 = 100005, _6 = 1000006; int n, a[1001], b[1001]; vector<int> v; int main() { scanf( %d , &n); for (int i = 0, b; i < n; ++i) cin >> a[i]; for (int i = n - 1; i >= 0; --i) { if (!b[a[i]]) { b[a[i]] = 1; v.push_back(a[i...
#include <bits/stdc++.h> using namespace std; const int oo = numeric_limits<int>::max(); const int n_oo = numeric_limits<int>::min(); const int ALF = 26; struct SuffixAutomaton { int toInt(char c) { return c - a ; } char toChar(int j) { return char(j + a ); } struct Nodo { vector<int> hijo...
#include <bits/stdc++.h> using namespace std; int n; vector<int> x; int ax[3]; int main() { ax[0] = ax[1] = ax[2] = 0; cin >> n; for (int i = 0; i < n; ++i) { string s; cin >> s; int cc = 0; for (int i = 0; i < s.size(); ++i) cc += s[i] - 0 ; x.push_back(cc % 3); ...
#include <bits/stdc++.h> using namespace std; const long long MOD = 998244353; const long long N = 1e5 + 5; vector<long long> vp; long long n; long long a[N]; long long binsearch(long long lo, long long hi, long long check) { long long ans = -1; while (hi >= lo) { long long mid = (lo + hi) /...
#include <bits/stdc++.h> using namespace std; const long long int N = 100005; bool powertwo(long long int n) { return (n and !(n & (n - 1))); } int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long int t; cin >> t; while (t--) { long long int n; cin >> ...
#include <bits/stdc++.h> using namespace std; struct Point { double x, y; int num; Point() {} Point(double _x, double _y, int _num) : x(_x), y(_y), num(_num) {} void read() { scanf( %lf%lf , &x, &y); } double operator*(const Point &a) const { return x * a.y - a.x * y; } Point operator-(c...
#include <bits/stdc++.h> using namespace std; int main() { double a, b, c, d, e, f; cin >> a >> b; for (int i = 0; i < a; i++) { cin >> c >> d; e = c / d; if (i > 0) f = min(e, f); else if (i == 0) f = e; } printf( %.08f n , f * b); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, p[105][105], ans = 0; cin >> n; for (int i = 0; i < n; i++) { for (int j = 0; j < 2; j++) { cin >> p[i][j]; } } for (int i = 0; i < n; i++) { for (int j = 0; j < 2; j++) { if (p[i][j + 1] - p[i][j...
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const int INF = 1000 * 1000 * 1000 + 7; const long long LINF = INF * (long long)INF; const int L = 22; int G[L]; int dp[1 << L]; int P[1 << L]; int M[1 << L]; int n; void print(int mask) { for (int i = (0); i < (n); i+...
#include <bits/stdc++.h> using namespace std; inline long long rd() { long long x = 0; int ch = getchar(), f = 1; while (!isdigit(ch) && (ch != - ) && (ch != EOF)) ch = getchar(); if (ch == - ) { f = -1; ch = getchar(); } while (isdigit(ch)) { x = (x << 1) + (x << 3) + ch...
#include <bits/stdc++.h> using namespace std; char s[300005]; int ans[300005]; int main() { int n, m; while (cin >> n >> m) { int cnt = 0; for (int i = 1; i <= n; i++) cin >> s[i]; for (int i = 1; i < n; i++) if (s[i] == s[i + 1] && s[i] == . ) cnt++; for (int i = 0; i <...
#include <bits/stdc++.h> using namespace std; int a[1005], b[1005]; int main() { int n; string s, ss; cin >> n >> s >> ss; for (int i = 0; i < n; i++) { a[i] = s[i] - 0 ; b[i] = ss[i] - 0 ; } sort(a, a + n); sort(b, b + n); int sum1 = 0, sum2 = 0; for (int i = 0, ...
#include<bits/stdc++.h> #define endl n #define bug puts( aaa ); #define Case int t;scanf( %d ,&t);while(t--) #define ios ios::sync_with_stdio(0),cin.tie(0); using namespace std; typedef long long ll; typedef unsigned long long ull; const double eps = 1e-5; const int inf = 0x3f3f3f3f; const int mo...
#include <bits/stdc++.h> using namespace std; const int64_t N = 1e5 + 1; int64_t crt_node = 0, maxi = 0; vector<int64_t> previous; vector<vector<int64_t>> adj; void dfs(int64_t node, int64_t pere, int64_t len) { previous[node] = pere; if (len > maxi) { crt_node = node; maxi = len; } ...
#include <bits/stdc++.h> using namespace std; const int MN = 111; int a[MN], n, g[MN][MN], c[MN]; struct Block { int f[MN][MN]; void cal1() { memset(f, 0, sizeof f); for (int from = (1), _b = (100); from <= _b; from++) { for (int to = (from), _b = (100); to <= _b; to++) f[from][to] =...
#include <bits/stdc++.h> using namespace std; const int maxn = 300 + 10; const int maxm = maxn * maxn; const int INF = 0x3f3f3f3f; int connect[maxn][maxn], edgecnt[maxn]; int price[maxn], vis[maxn * 2], match[maxn * 2]; int n; bool extend(int u) { vis[u] = true; for (int i = 1; i <= edgecnt[u]; ...