func_code_string
stringlengths
59
71.4k
#include<bits/stdc++.h> using namespace std; void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;} void __print(float x) {c...
#include <bits/stdc++.h> struct Mat { double a[253][253]; } A[53]; int Sta[25][25], d[25], n, m, a, b, tot; double p[25], tp[253][253]; std::vector<int> v[25]; void sq(int x, int y) { register int i, ii, iii; for (i = 0; i < tot; i++) for (ii = 0; ii < tot; ii++) for (iii = 0; iii ...
#include <bits/stdc++.h> using namespace std; int main() { int m, n, k, i, j, t, x; int c[200]; cin >> n; int a[n]; for (i = 0; i < n; i++) { cin >> a[i]; c[i] = a[i]; } cin >> m; int b[m]; for (j = 0; j < m; j++) { cin >> b[j]; c[i + j] = b[j]; } ...
#include <bits/stdc++.h> using namespace std; struct point { double x, y; point(double x, double y) : x(x), y(y) {} point() {} inline void read() { scanf( %lf%lf , &x, &y); } inline double len() const { return sqrt(x * x + y * y); } inline double len2() const { return x * x + y * y; } in...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; int n, m, h, t, u, v, src[MAXN], dst[MAXN], num[MAXN], used[MAXN]; vector<int> g[MAXN]; void out(vector<int> &v) { for (int i = 0; i < v.size(); ++i) { cout << v[i] << n [i == v.size() - 1]; } } bool check(int u, int ...
#include <bits/stdc++.h> using namespace std; const long double eps = 1e-13; const long double PI = acos(-1); const int INF = (int)1e9; const long long INFF = (long long)1e18; const int mod = (int)1e9 + 7; const int MXN = (int)2e5 + 7; char s[MXN]; int cnt[MXN]; int num[MXN], num2[MXN], a[MXN]; bo...
#include <bits/stdc++.h> using namespace std; int main() { int n, t = 1, i; cin >> n; int a[n]; for (i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); for (i = 0; i < n - 1; i++) { if (a[i + 1] == a[i]) { t++; } else if (t > (n + 1) / 2) { cout << NO ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } int res[101] = {0}; for (int i = 0; i < n; i++) { res[arr[i]]++; } i...
#include <bits/stdc++.h> using namespace std; int K, P, cd; int cal(int ct, vector<pair<int, int> > vt) { int t = vt.size(), res = 0; for (int st = 1; st < (1 << t); st++) { int val = 1, sl = 0; for (int j = 0; j < t; j++) { if ((st >> j) % 2 == 1) val *= vt[j].first, sl++; } ...
#include <bits/stdc++.h> using namespace std; const int maxn = (int)1e5 * 2 + 7; int a[maxn], b[maxn], t[4 * maxn], n, W, H; void build(int v, int l, int r) { if (r - l == 1) { t[v] = a[l]; return; } build(2 * v + 1, l, (l + r) / 2); build(2 * v + 2, (l + r) / 2, r); t[v] = max(t...
#include <bits/stdc++.h> using namespace std; int main() { long long left; long long right; scanf( %lld%lld , &left, &right); long long ans = 0LL; for (int i = (62); i >= (0); --i) { long long bitLeft = left & (1LL << i); long long bitRight = right & (1LL << i); if (bitRight &&...
#include <bits/stdc++.h> long long k, pa, pb, dp[1107][1107]; int main() { scanf( %lld%lld%lld , &k, &pa, &pb); long long invb = 1, base = pb; for (int t = 1000000007 - 2; t; t >>= 1, (base *= base) %= 1000000007) if (t & 1) (invb *= base) %= 1000000007; long long inva_b = 1; base = pa + p...
#include <bits/stdc++.h> using namespace std; template <class Ta, class Tb> inline Tb cast(Ta a) { stringstream ss; ss << a; Tb b; ss >> b; return b; }; const double EPS = 1e-9; const int INF = 1000000000; const int MOD = 1000000007; const int diri[8] = {-1, 0, 1, 0, -1, 1, 1, -1}; ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, h; string s; cin >> n >> s; m = (s[3] - 0 ) * 10 + s[4] - 0 ; if (m > 59) { s[3] = 0 ; } if (n == 24) { h = (s[0] - 0 ) * 10 + s[1] - 0 ; if (h > 23) { if (s[0] - 0 > 2) s[0] =...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); priority_queue<int, vector<int>, greater<int>> pq; int n, k; cin >> n >> k; for (int i = 0; i < n; i++) { int x; cin >> x; pq.push(x); } int ans = 0; for (int i ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; map<int, int> v[N]; int rec(int node, int w) { auto it = v[node].lower_bound(w); if (it == v[node].begin()) { return 1; } it--; return (*it).second + 1; } int32_t main() { ios::sync_with_stdio(0); cin.tie(...
#include <bits/stdc++.h> using namespace std; int main() { long long int a, b; scanf( %lld%lld , &a, &b); long long int c = a, d = b; long long int cnt = 0, rem; while (c >= 1 && d >= 1) { if (d == 1) { printf( %lld , cnt + c); return 0; } if (c >= d) { ...
#include <bits/stdc++.h> using namespace std; const int N = (int)5e5 + 9; vector<int> T[N]; bool use[2 * N]; int p; int l[N], r[N]; void dfs(int u, int par) { if (par == -1) { l[u] = 1; r[u] = T[u].size() + 2; use[1] = true; use[T[u].size() + 2] = true; p = T[u].size() + ...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) #pragma GCC target( avx2 ) using namespace std; const long double two = 2; const long double INF = 2e18 + 100; const long long MOD = 998244353; const long long N = 1e5 + 10; const long long nul = 0; const long long SIZE = 1e6 * 3; struct exam { ...
#include <bits/stdc++.h> using namespace std; bool sol(long long n, long long m, long long a, long long l, long long r, long long& b, long long& c) { if (abs(n * a - m) <= r - l) { long long diff = m - n * a; b = diff > 0 ? r : l; c = b - diff; return true; } return fa...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false), cin.tie(nullptr); string a, b, c = ; cin >> a >> b; for (int i = 0; i < a.length(); i++) { if (a[i] + 1 < b[i]) { c += a[i] + 1; for (int j = i + 1; j < a.length(); j++) c += z ; ...
#include <bits/stdc++.h> using namespace std; int arr[5] = {10, 15, 60, 4, 19}; int result = 0; int getMin(int r, int g, int b) { if (r < g) { if (r < b) { return r; } else { return b; } } else { if (g < b) { return g; } else { return b; ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); string s; cin >> s; long long a = -1, b = -1; int flag = 0; for (int i = 0; i < s.length(); i++) { if (s[i] == [ ) { a = i; flag = 1; break; } ...
#include <bits/stdc++.h> using namespace std; long long int a[500005]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long int t, n, m, q, i, j, k, x, y = 2, z; cin >> n >> k; set<long long int> s; for (i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); f...
#include <bits/stdc++.h> using namespace std; int main() { int n, x, y; cin >> n >> x >> y; int z = n / 2; if (x >= z && x <= z + 1 && y >= z && y <= z + 1) cout << NO ; else cout << YES ; return 0; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 405; char G[405][405], P[405][405]; bitset<MAXN> nolet[405][27]; int main() { int N, M; scanf( %d%d , &N, &M); for (int i = 0; i < N; ++i) { scanf( %s , G[i]); for (int c = 0; c < 26; ++c) for (int j = 0; j < M; ++j...
#include <bits/stdc++.h> int a[100000]; int main() { int y, k, n, i; while (scanf( %d %d %d , &y, &k, &n) != EOF) { int flag = 0; int l = n / k; for (i = 1; i <= l; i++) { a[i] = i * k; if (a[i] > y) { printf( %d , a[i] - y); flag = 1; } }...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; char a[n][5]; for (int i = 1; i <= n; i++) { for (int j = 1; j <= 5; j++) { cin >> a[i][j]; } } int flag = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= 4; j++) { if ((a...
#include <bits/stdc++.h> const int inf = (1ll << 30) - 1; const int maxn = (int)1e5 + 10; using namespace std; pair<long long, long long> e[100100]; int en; vector<int> g[100100]; long long dp[100100], d[100100]; int pr[100100]; int used[100100]; long long mi[100100]; int n, m, L, second, t; voi...
#include <bits/stdc++.h> using namespace std; int n, m; int sz = 1; string data[109]; struct node { int x, y; int pos; }; bool operator<(const node& a, const node& b) { if (a.x == b.x) { if (a.y == b.y) { return a.pos < b.pos; } return a.y < b.y; } return a.x ...
#include <bits/stdc++.h> using namespace std; int n; int p; int a[300010]; int ans; int main() { int i, j, k; scanf( %d , &n); ans = 1; a[n + 1] = -1; printf( 1 ); for (k = 1; k <= n; ++k) { scanf( %d , &p); if (a[p + 1] == -1) { i = p - 1; a[p] = -1; ...
#include <bits/stdc++.h> using namespace std; int main() { long long sum = 0; int d[1000000 + 1] = {0}; for (int i = 1; i <= 1000000; i++) { for (int j = i; j <= 1000000; j += i) { d[j]++; } } int a, b, c; cin >> a >> b >> c; for (auto(i) = (1); (i) < (a + 1); ++(i)) ...
#include <bits/stdc++.h> struct Seg { int l; int r; int y; }; struct Event { int x; enum { BEG, END } type; Seg seg; static Event beginOf(Seg seg) { return Event{seg.l, BEG, seg}; } static Event endOf(Seg seg) { return Event{seg.r, END, seg}; } friend bool operator<(const Event...
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char c = getchar(); while (c < 0 || c > 9 ) { if (c == - ) f = -1; c = getchar(); } while (c >= 0 && c <= 9 ) { x = (x << 3) + (x << 1) + (c ^ 48); c = getchar(); } return f...
#include <bits/stdc++.h> using namespace std; int main() { vector<string> v; int i, j, k, l, l1, l2; string a, b, s1, s2, s; cin >> a >> b; l1 = a.size(); l2 = b.size(); for (i = 1; i <= l1; i++) { for (j = 1; j <= l2; j++) { for (k = 0, s1 = ; k < i; k++) { s1 ...
#include <bits/stdc++.h> using namespace std; int n; int m; struct st { int dp; int maxt; int cnt; bool use; st() { dp = maxt = cnt = 0; use = false; } }; vector<st> dp[123457]; vector<int> v[123457]; vector<int> nex[123457]; bool oc[123457]; bool visited[123457];...
#include <bits/stdc++.h> using namespace std; void ok(int x) { cout << x << n ; exit(0); } int main() { int n, p; cin >> n >> p; for (int k = 0; k < int(1e8); k++) { long long n1 = n - 1LL * p * k; if (n1 < 0) continue; if (n1 >= k && k >= __builtin_popcountll(n1)) ok(k);...
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > ans; vector<int> e[100010]; void dfs(int x, int p, int entry) { ans.emplace_back(x, entry); if (x == 1) { for (int it : e[x]) if (it != p) dfs(it, x, ++entry), ans.emplace_back(1, entry); } else { int cur = ent...
#include <bits/stdc++.h> using namespace std; int main() { string s; int n, sumA = 0, sumG = 0; cin >> n; vector<pair<int, int>> vec(n); for (int i = 0; i < n; i++) cin >> vec[i].first >> vec[i].second; if (vec[0].first > vec[0].second) { sumG = vec[0].second; s.push_back( G ); ...
#include <bits/stdc++.h> using namespace std; vector<int> spl; int p[2000006]; void prime() { p[0] = p[1] = 0; for (int i = 2; i < 1420; i++) { if (!p[i]) { spl.push_back(i); for (int j = i * i; j < 2000006; j += i) p[j] = i; } } } int n, q; int a[100005]; vector<...
#include <bits/stdc++.h> using namespace std; template <typename T> T gcd(T a, T b) { if (a == 0) return b; return gcd(b % a, a); } template <typename T> T pow(T a, T b, long long m) { T ans = 1; while (b > 0) { if (b % 2 == 1) ans = ((ans % m) * (a % m)) % m; b /= 2; a = (...
#include <bits/stdc++.h> using namespace std; const int MAXH = 200000 + 10, MAXN = 2000 + 10; const long long MOD = 1000000007; struct Point { int x, y; bool operator<(const Point &p1) const { return x + y < p1.x + p1.y; } } p[MAXN]; long long fac[MAXH], inv[MAXH]; long long f[MAXN]; inline long...
#include <bits/stdc++.h> using namespace std; int main() { int n, x = 0, y = 0; cin >> n; int *C = new int[n]; for (int i = 0; i < n; i++) { cin >> C[i]; } for (int j = 0; j < n; j++) { if (j == 0) { y = abs(C[j] - C[j + 1]); x = abs(C[j] - C[n - 1]); } else...
#include <bits/stdc++.h> using namespace std; int modul(int a, int b) { if (a - b < 0) return b - a; return a - b; } int main() { int n, k, st, et, s, e, d, v[103], j, m, stm, etm; cin >> n >> k; st = et = 0; d = 0; for (int i = 1; i <= n; i++) { cin >> v[i]; if (v[i] == ...
#include <bits/stdc++.h> using namespace std; const int N = 1010, L = 33, B = 7340033, root = 3; int dp[L][N << 2]; int mypw(int x, int k) { int ret = 1; while (k) { if (k & 1) ret = 1ll * ret * x % B; k >>= 1; x = 1ll * x * x % B; } return ret; } void change(int y[], int l...
#include <bits/stdc++.h> const int BUFFSIZE = 10240; char BUFF[BUFFSIZE + 1], *p = BUFF; int CHAR, SIGN, BYTES = 0; using namespace std; vector<long long> V; void dfs(long long N) { if (N > 5000000000LL) return; V.push_back(N); dfs(N * 10 + 4); dfs(N * 10 + 7); } int main() { dfs(0);...
#include <bits/stdc++.h> using namespace std; using ll = long long; bitset<10000> B; int BIT[100010]; int n; void update(int pos, int x) { for (; pos < n; pos |= pos + 1) BIT[pos] += x; } int qu(int pos) { int ret = 0; for (; pos; pos &= pos - 1) ret += BIT[pos - 1]; return ret; } in...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const int maxn = 1e5 + 5; long long dp[205][15005]; long long p2[205], p5[205]; long long a[205]; int n, k; int main() { cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; while (a[i] % 2 == 0) a[i] ...
#include <bits/stdc++.h> using namespace std; map<string, int> types; int count(const string &data) { int amps = 0, stars = 0, i, j; for (i = 0; i < (int)data.size() && data[i] == & ; i++, amps++) ; for (j = data.size() - 1; j >= 0 && data[j] == * ; j--, stars++) ; string t = data.su...
#include <bits/stdc++.h> using namespace std; int Case, n, sz, ans, A[300000 + 5], Min[300000 + 5], Max[300000 + 5], Id[300000 + 5]; int main() { for (scanf( %d , &Case); Case; Case--) { scanf( %d , &n); for (int i = 1; i <= n; i++) Id[i] = 0, Min[i] = n + 1, Max[i] = 0; for (int i = 1...
#include <bits/stdc++.h> using namespace std; int k; long long int m, lim = 2e18; long long int dp[70][70][2]; long long int solve(string s, int pos, int k, bool f) { if (k < 0) return 0; if (pos == (int)s.size()) { return (k == 0); } if (dp[pos][k][f] != -1) return dp[pos][k][f]; lo...
#include <bits/stdc++.h> int arr[1005]; int n; using namespace std; int main() { int n; scanf( %d , &n); int sum = 0; for (int i = 0; i < 505; i++) { sum += i; arr[i + 1] = sum; } if (n == 0) { printf( a n ); return 0; } for (int i = 0; i < 26; i++) { ...
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; vector<long long> p(n); for (auto& i : p) cin >> i; vector<long long> dp(n, 1); vector<int> exist(n, false); for (long long i = 0; i < (n); ++i) { exist[p[i] - 1] = true; if (p[i] != 1) ...
#include <bits/stdc++.h> using namespace std; const long long N = 5 * 1e5 + 1; int main() { long long q; cin >> q; vector<long long> v(N); for (int i = 0; i <= N; i++) { v[i] = i; } deque<long long> dq; vector<pair<long long, long long>> pq(q); long long idx = 0; while (q...
#include <bits/stdc++.h> using namespace std; const int cap = 1e3; int n, m; char grid[cap][cap]; int vis[4][cap][cap] = {}; vector<pair<int, int>> dirs = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}}; bool dfs(int i, int j, int d, int t) { if (i < 0 || i == n || j < 0 || j == m || grid[i][j] == * || (...
#include <bits/stdc++.h> using namespace std; long long n, pos, ans = 10000000000000000; long long a[3000 + 5], b[3000 + 5], f[3000 + 5][3000 + 5], Min[3000 + 5]; long long read() { char c; long long x = 0, f = 1; c = getchar(); while (c > 9 || c < 0 ) { if (c == - ) f = -1; c = ...
#include <bits/stdc++.h> #define int long long int #define us unsigned int #define null 0 #define m_p make_pair #define f_i first #define s_e second #define p_b push_back using namespace std; void IOS() { ios_base::sync_with_stdio(false); cin.tie(NULL); } int3...
#include <bits/stdc++.h> using namespace std; const int Y = 10; int n; string fcol = ; bool place(int y, int x) { cout << x << << y << endl; string ret; cin >> ret; return (ret == fcol); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; cout << 0...
#include <bits/stdc++.h> using namespace std; struct FlowEdge { int to, cap, rev; FlowEdge(int to_, int cap_, int rev_) : to(to_), cap(cap_), rev(rev_) {} }; class FordFulkerson { public: FordFulkerson() {} FordFulkerson(int n) : G(n), used(n) {} void add(int from, int to, int cap) { ...
#include <bits/stdc++.h> using namespace std; int main() { int t, x = 0, k = 0; cin >> t; while (t--) { int m, n, x, y = 0; cin >> m; cin >> n; x = m * n; int a[x]; for (int i = 0; i < x; i++) { cin >> a[i]; if (a[i] < 0) { a[i] = 0 - a[i]; ...
#include <bits/stdc++.h> using namespace std; long long MOD = 1000000007; void runCase(int caseNum) { string s; cin >> s; int res = true; if (s.size()) { stack<char> st; st.push(s[0]); for (int i = 1; i < s.size(); ++i) { if (!st.empty() && st.top() == s[i]) st....
#include <bits/stdc++.h> using namespace std; inline int read(int f = 1, int x = 0, char ch = ) { while (!isdigit(ch = getchar())) if (ch == - ) f = -1; while (isdigit(ch)) x = x * 10 + ch - 0 , ch = getchar(); return f * x; } const int N = 1e2 + 5; int n, c[2], p[N], q[N], f[2][N][N][N...
#include <bits/stdc++.h> using namespace std; const long long MAGIC = 400; const long long N = 1e5 + 2; const long long inf = 1e14 + 2; long long lzval[MAGIC], lzmul[MAGIC], ar[N], add[N]; bool used[N]; vector<long long> idx[MAGIC]; struct hull { long long ptr; struct line { long long a, b...
#include <bits/stdc++.h> using namespace std; long long m[1000001], cd, kq[100000]; map<long long, long long> ruler; int main() { cin >> cd; for (long long i = 1; i <= cd; i++) { cin >> m[i]; ruler[m[i]] = 1; } for (long long i = 1; i <= cd; i++) { long long e = 1; kq[e] ...
#include <bits/stdc++.h> using namespace std; map<string, int> A; string s; int main() { A[ void ] = 100; A[ errtype ] = 0; int n; cin >> n; for (int i = 0; i < n; ++i) { cin >> s; if (s[4] == d ) { string a, b; cin >> a >> b; int l = a.length(); ...
#include <bits/stdc++.h> using std::map; const int MAXN = 1000 + 3; int table[MAXN][MAXN]; int n, m, k; map<int, int> r, c; int main(int argc, char *argv[]) { scanf( %d%d%d , &n, &m, &k); for (int i = 1; i <= n; ++i) { r[i] = i; for (int j = 1; j <= m; ++j) { if (i == 1) c[j] = j...
#include <bits/stdc++.h> using namespace std; int main() { long long i, j, d = 0, e = 0, f = 0, sum = 0, c = 0, n; cin >> n; char a[4][4]; map<int, int> m; for (i = 0; i < 4; i++) { for (j = 0; j < 4; j++) { cin >> a[i][j]; } } for (i = 0; i < 4; i++) { for (j =...
#include <bits/stdc++.h> using namespace std; using ll = long long; const int MOD = (int)998244353; const int MAXN = (int)1e6 + 5; template <typename T> class BIT { public: BIT(T* _a, int _n) { a = _a; n = _n; bit = new T[n + 1]; for (int i = 1; i <= n; ++i) bit[i] = 0; ...
#include <bits/stdc++.h> struct node { int mx, se, cmx; int cnt; long long sum; node() : mx(0), se(-1), cmx(0), cnt(0), sum(0) {} node(int v) : mx(v), se(-1), cmx(1), cnt(1), sum(v) {} }; node operator+(const node &a, const node &b) { node res; if (a.mx == b.mx) { res.mx = a.mx; ...
#include <bits/stdc++.h> const int INF = 1e9 + 7; struct Node { int min, max; int low, high; int lcnt, rcnt, cnt; } st[2000000]; int as[500005]; int query(int w, int L, int R, int& low, int& high) { if (R - L == 1) { return as[L] >= low && as[L] <= high; } int M = (L + R) / 2; ...
#include <bits/stdc++.h> using namespace std; const string nameFiles = ; void error(vector<string>::iterator) {} template <typename T, typename... Args> void error(vector<string>::iterator cur_var, T a, Args... args) { cerr << cur_var->substr((*cur_var)[0] == ) << = << a << endl; error(++cur_...
#include <bits/stdc++.h> using namespace std; const int INF = 0x7f7f7f7f; const int MOD = 1e9 + 7; const double eps = 1e-6; int main() { int n, r, v; scanf( %d%d%d , &n, &r, &v); double s = acos(-1.0) * r * 2; while (n--) { int a, b; scanf( %d%d , &a, &b); double d = b - a; ...
#include <bits/stdc++.h> using namespace std; template <typename T> T gcd(T a, T b) { return !b ? a : gcd(b, a % b); } template <typename T> T lcm(T a, T b) { return a * (b / gcd(a, b)); } template <typename T> T sqr(T a) { return a * a; } template <typename T> T cube(T a) { retu...
#include <bits/stdc++.h> using namespace std; template <typename T> void write(ostream& out, T t) { out << t << n ; } template <typename T, typename... Args> void write(ostream& out, T t, Args... args) { out << t << ; write(out, args...); } template <typename... Args> void debug(Args....
#include <bits/stdc++.h> using namespace std; int main() { int t; scanf( %d , &t); for (int tt = 0; tt < t; tt++) { vector<vector<int> > A(9, vector<int>(9)); for (int i = 0; i < 9; i++) { int q; scanf( %d , &q); for (int j = 0; j < 9; j++) { A[i][8 - j] = q...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long t, n, k, p; long long a[50]; cin >> t; while (t--) { cin >> n >> k; for (int i = 0; i < n; i++) cin >> a[i]; long long limit = 10e16; p = 1; whi...
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b, ans = 0; cin >> n >> a >> b; vector<int> vec(n); for (int i = 0; i < n; i++) cin >> vec[i]; for (int i = 0; i < n / 2 + (n % 2); i++) { if (vec[i] != vec[n - i - 1] && vec[i] != 2 && vec[n - i - 1] != 2) { cout...
#include <bits/stdc++.h> using namespace std; const int MAX_N = 100005, MAX_K = 105; int N, M, K, S; int good_type[MAX_N]; int distances[MAX_N][MAX_K]; vector<int> adj[MAX_N]; int dist[MAX_N]; void RunBFS(int type) { queue<int> q; for (int i = 0; i < N; ++i) { if (good_type[i] == type) { ...
#include <bits/stdc++.h> using namespace std; const long long N = 1e6 + 7; const long long mod = 1e9 + 7; long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } map<long long, long long> mp; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie...
#include <bits/stdc++.h> using namespace std; const long long linf = 1LL << 62; const int iinf = 1000000009; const double dinf = 1e17; const int Mod = 1e9 + 9; const int maxn = 1000005; int n; long long a, b[maxn]; long long dp[3][maxn]; void solve() { ios::sync_with_stdio(false); cin >> n; ...
#include <bits/stdc++.h> using namespace std; int n, m, q; int x[1000][1000]; int r[1000][1000][4]; void upd1(int j) { int i = 0; for (int k = 0; k < n; ++k) { if (x[k][j] == 0) { i = k + 1; r[k][j][0] = -1; } else r[k][j][0] = i; } i = n - 1; for (int k...
#include <bits/stdc++.h> using namespace std; const int max_n = 511, inf = 1e9 + 100; bool m[max_n][max_n]; bool vis[max_n][max_n]; int mini[max_n], maxi[max_n]; int minj[max_n], maxj[max_n]; int si, sj; int n; int di[] = {0, 0, 1, -1}; int dj[] = {-1, 1, 0, 0}; char dir[] = LRDU ; string resul...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) #pragma GCC optimize( unroll-loops ) #pragma comment(linker, /STACK:2000000 ) using namespace std; template <int D, typename T> struct Vec : public vector<Vec<D - 1, T>> { static_assert(D >= 1, Vector dimension must be greater than zero! ); templ...
#include <bits/stdc++.h> using namespace std; int main() { long b, c, m, n, k, l; cin >> m >> k; l = k; for (int i = 0; i < k; i++) { if (m % 10 == 0) m /= 10; else m--; } cout << m; }
#include <bits/stdc++.h> int main() { int t; scanf( %d , &t); while (t--) { int n; scanf( %d , &n); int a[n]; for (int i = 0; i < n; i++) { scanf( %d , &a[i]); } for (int i = 0; i < n; i++) { for (int j = 0; j < n - i - 1; j++) { if (a[j + 1] <...
#include <bits/stdc++.h> using namespace std; const int MAXD = 500; const int MAXS = 5000; bool vis[MAXD][MAXS + 1]; int dig[MAXD][MAXS + 1], from[MAXD][MAXS + 1]; struct Data { int last, c, prev_r; int r, sum; bool operator<(const Data &other) const { return last < other.last; } }; queue<Da...
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n; cin >> n; if (n == 2) { cout << 2; } else { cout << 1; } return 0; }
#include <bits/stdc++.h> using namespace std; int mod = 998244353; const int M = 2e5 + 10; const int N = 5e2 + 10; inline long long read() { long long b = 1, sum = 0; char c = getchar(); while (!isdigit(c)) { if (c == - ) b = -1; c = getchar(); } while (isdigit(c)) { sum...
#include <bits/stdc++.h> using namespace std; int n; int v[1100]; int pd[1100][1 << 8]; int qtd1, qtd2; int vis[1100][1 << 8]; int inv[1100]; vector<int> pos[10]; bool check(int mask) { for (int i = 0; i < 8; ++i) { if (mask & (1 << i)) continue; if (qtd1) return false; } retur...
#include <bits/stdc++.h> bool a[100000 << 1]; int b[100000 << 1], c[100000 << 1], h[100000], n, m, i, x, y; int go(int k) { int i, t, x = -1; for (i = h[k]; ~i; i = b[i]) if (!a[i]) { a[i] = 1, a[i >= m ? i - m : i + m] = 1; t = go(c[i]); if (~t) printf( %d %d %d n ...
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const double eps = 1e-11; const int inf = 0x7FFFFFFF; template <class T> inline void checkmin(T &a, T b) { if (b < a) a = b; } template <class T> inline void checkmax(T &a, T b) { if (b > a) a = b; } template <clas...
#include <bits/stdc++.h> using namespace std; const int inf = 1e9 + 7; template <class T> void dbs(string str, T t) { cerr << str << : << t << n ; } template <class T, class... second> void dbs(string str, T t, second... s) { int idx = str.find( , ); cerr << str.substr(0, idx) << : <...
#include <bits/stdc++.h> using namespace std; int n, m, g[505][505], f[505][505], tot[505], ans[505][505]; int main() { scanf( %d%d , &n, &m); memset(g, 0x3f, sizeof(g)); memset(f, 0x3f, sizeof(f)); for (int i = 1; i <= n; i++) f[i][i] = 0; for (int i = 1; i <= m; i++) { int u, v, w; ...
#include <bits/stdc++.h> using namespace std; inline void read(int &a) { a = 0; int c = getchar(), b = 1; while (c > 9 || c < 0 ) { if (c == - ) b = -1; c = getchar(); } while (c >= 0 && c <= 9 ) a = (a << 3) + (a << 1) + c - 48, c = getchar(); a *= b; } inline int Rem...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-10, pi = 3.1415926535898; const int mod = 998244353, maxn = 2e5 + 10; int T, n, m, k, x, y, a[maxn], p, b; long long fac[maxn] = {1, 1}, inv[maxn] = {1, 1}, inv_fac[maxn] = {1, 1}; char st[maxn]; void init() { for (int i = 2; i < maxn...
#include <bits/stdc++.h> using namespace std; int main() { string a, b, str; int n, cont = 0, ca = 0, cb = 0; cin >> a >> b; n = a.size(); for (int i = 0; i < n; i++) { if (a[i] != b[i]) cont++; } if (cont % 2 == 0) { for (int i = 0; i < n; i++) { if (a[i] != b[i]) { ...
#include <bits/stdc++.h> using namespace std; inline void input(long long &x) { long long y = 1; char c = getchar(); while (c < 0 || c > 9 ) { if (c == - ) y = -1; c = getchar(); } x = 0; while (c >= 0 && c <= 9 ) { x = x * 10 + (c - 0 ); c = getchar(); } ...
#include <bits/stdc++.h> using namespace std; const int MAXN = (int)1e5 + 10; int n, cnt = 0; string a, b; void check(string a, string b) { int p = 0; for (; p < ((int)(a).size()) && a[p] == b[p]; ++p) ; if (a.substr(0, p) == b.substr(0, p) && a.substr(p) == b.substr(p + 1)) ++cnt; } int...
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll a[200009],n,p; bool vis[200009][2]; pair <ll,ll> g[200009]; int main() { ios::sync_with_stdio(0); int t; cin>>t; while(t--) { cin>>n>>p; ll ans=0; for(int i=1;i<=n;i++) ...
#include <bits/stdc++.h> using namespace std; template <class T1, class T2> inline istream& operator>>(istream& fin, pair<T1, T2>& pr) { fin >> pr.first >> pr.second; return fin; } template <class T0, class T1, class T2> inline istream& operator>>(istream& fin, tuple<T0, T1, T2>& t) { fin >> get...