func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int countbit(int n) { return (n == 0) ? 0 : (1 + countbit(n & (n - 1))); } int lowbit(int n) { return (n ^ (n - 1)) & n; } const double pi = acos(-1.0); const double eps = 1e-11; template <class T> T sqr(T x) { return x * x; } int n, m, k; int c[101]...
#include <bits/stdc++.h> using namespace std; template <class C> inline void mini(C& a4, C b4) { a4 = min(a4, b4); } template <class C> inline void maxi(C& a4, C b4) { a4 = max(a4, b4); } const int INF = 1e9 + 7; const int base = 1e9; const int SIGMA = 26; const int N = 1e5 + 7; int n; ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; bool cmax(int &a, int b) { return (a < b) ? a = b, 1 : 0; } bool cmin(int &a, int b) { return (a > b) ? a = b, 1 : 0; } template <typename T> T read() { T ans = 0, f = 1; char ch = getchar(); while (!isdigit(ch) && ch != - ) c...
#include <bits/stdc++.h> using namespace std; long long a[100010]; long long dif[100010]; int main() { int n; scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %lld , &a[i]); for (int i = 1; i <= n - 1; i++) { dif[i] = a[i + 1] - a[i]; } long long d = 0; for (int i = 1; i <=...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using pii = pair<int, int>; constexpr int N = 2e5 + 5; int t, a, b, p; string s; void Solve() { cin >> t; while (t--) { cin >> a >> b >> p >> s; s.pop_back(); vector<ll> suf; suf.r...
#include <bits/stdc++.h> const int N = 1e5 + 1e4; struct edg { int now, to, val; } ed[N]; struct edge { int to, next; } e[N]; int ehead[N], ecnt; inline void add_edge(int now, int to) { ecnt++; e[ecnt].to = to; e[ecnt].next = ehead[now]; ehead[now] = ecnt; } int n, m, left, rig...
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 2e5 + 10; int beg[N]; int nxt[N]; int to[N]; int tot; int a[N]; void add(int x, int y) { ++tot; nxt[tot] = beg[x]; to[tot] = y; beg[x] = tot; } int main() { ios::sync_with_stdio(false); cin.ti...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, k, p, x; cin >> n >> k >> p; std::vector<int> even, odd; for (int i = 0; i < n; ++i) { cin >> x; if (x % 2) odd.emplace_back(x); else ...
#include <bits/stdc++.h> template <class T> int gmax(T &a, T b) { if (b > a) { a = b; return 1; } return 0; } template <class T> int gmin(T &a, T b) { if (b < a) { a = b; return 1; } return 0; } using namespace std; string to_string(string s) { return ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 10; const int MOD = 998244353; int n, q; long long seg[4 * MAXN], mul[4 * MAXN], plu[4 * MAXN]; set<pair<int, int>> number[MAXN]; void shift(int l, int r, int id) { int mid = l + r >> 1; seg[id << 1] = (seg[id << 1] * mul[id]) % ...
#include <bits/stdc++.h> int main(void) { int a[100][5], n, i, j, k = 0, min = 10000; scanf( %d , &n); for (i = 0; i < n; i++) { scanf( %d%d%d%d , &a[i][0], &a[i][1], &a[i][2], &a[i][3]); a[i][4] = i + 1; } for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { if (a[j][0] >...
#include <bits/stdc++.h> using namespace std; long long a[2210], b[2210]; long long inf = 1e13; int main() { memset(a, 0, sizeof(a)); memset(b, 0, sizeof(b)); int n = 0, k = 0; scanf( %d%d , &n, &k); for (int i = 1; i <= n; ++i) { scanf( %I64d , &a[i]); } for (int i = 1; i <= n...
#include <bits/stdc++.h> using namespace std; int a[17] = {1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0, 1, 0, 1, 0}, b; int main() { cin >> b; cout << a[b]; return 0; }
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; const int iinf = INT_MAX; const long long linf = 2e18; const double dinf = 1e30; const int MOD = 1000000007; inline int read() { int X = 0, w = 0; char ch = 0; while (!isdigit(ch)) { w |= ch == - ; ch = getchar...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, p; cin >> n >> p; int cnt = 0; for (int i = 1; i < n; ++i) { for (int j = i + 1; j <= n; ++j) { if (cnt == 2 * n + p) break; cout << i << << j << n ;...
#include <bits/stdc++.h> using namespace std; double getangle(pair<int, int> a, pair<int, int> b) {} int main() { int n; cin >> n; double arr[n + 1]; for (int i = 0; i < n; ++i) { int x, y; cin >> x >> y; arr[i] = atan2(x, y); if (arr[i] < 0) arr[i] += 2.0 * M_PI; arr...
#include <bits/stdc++.h> using namespace std; int main() { string aux; cin >> aux; int flag_Invalid_Input = 0; int memo[10] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512}; int counter = 0; int len = aux.size(); int i, j; for (i = 0; i < len; i++) { if (aux[i] > 1 ) { for (j...
#include <bits/stdc++.h> using namespace std; const int maxn = 210010; const int mod = 1e9 + 7; int dp[110][maxn], sum[maxn]; int a, b, k, t; int main() { scanf( %d%d%d%d , &a, &b, &k, &t); dp[0][0] = 1; for (int i = 1; i <= t; i++) { for (int j = 0; j < maxn; j++) sum[j] = ((j > 0...
#include <bits/stdc++.h> using namespace std; void dfs(long long n, long long i, unordered_map<long long, vector<long long>> &adj, vector<bool> &vis, vector<long long> &a1, vector<long long> &a2) { if (vis[n]) return; vis[n] = true; if (i == 0) a1.push_back(n); else ...
#include <bits/stdc++.h> using namespace std; const long double PI = acos(-1); struct Point { long long x, y, r; Point() {} Point(long long a, long long b, long long c) { x = a; y = b; r = c; } }; long double rad; long double cor(long double angle) { if (angle < 0) { ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int maxn = n * n - 1; int c = 0; for (int i = 0; i <= maxn; i++) { if (i % 2 == 0) { cout << i << ; c++; } if (c == n) { cout << endl; c = 0; } } for (in...
#include <bits/stdc++.h> using namespace std; long long n, m, k, x, i, sum, j, r = 1, B[20][20]; char A[20][20]; int main() { cin >> n >> m; for (i = 0; i < n; i++) { cin >> x; sum += x; } if (sum == 0) cout << 0; else { if (abs(sum) <= m) cout << 1 ; e...
#include <bits/stdc++.h> template <class T> int gmax(T &a, T b) { if (b > a) { a = b; return 1; } return 0; } template <class T> int gmin(T &a, T b) { if (b < a) { a = b; return 1; } return 0; } using namespace std; string to_string(string s) { return ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2005; struct Point { long long x, y; Point() {} Point(long long x, long long y) : x(x), y(y) {} bool operator<(const Point& rhs) const { if (y != rhs.y) return y < rhs.y; else return x < rhs.x; } }; ...
#include <bits/stdc++.h> using namespace std; using VI = vector<int>; const int NN = 200011; int a[NN], b[NN], arr[NN]; VI vec[NN], cyc[NN]; int nc; int dp[NN], vst[NN]; int n, s; void dfs(int u) { while (not vec[u].empty()) { int v = vec[u].back(); vec[u].pop_back(); dfs(a[v]); ...
#include <bits/stdc++.h> using namespace std; long long int n, i, j, t, ans, arr[3009], crr[3009][3009]; int main() { scanf( %lld , &t); while (t--) { scanf( %lld , &n); ans = 0; for (i = 1; i <= n; i++) scanf( %lld , &arr[i]); for (i = n; i >= 1; i--) { for (j = i - 1; j >...
#include <bits/stdc++.h> using namespace std; int main() { int n, b, one, two; string a; one = 0; two = 0; cin >> n >> a; for (b = 0; b < n; b++) { if (a[b] == 1 ) { one++; } else { two++; } } if (one > two) { cout << one - two; } else { ...
#include <bits/stdc++.h> using namespace std; int n, k; int a[2000000]; int dem; int maxa; int dp[10000001]; void mmax(int &a, int b) { a = max(a, b); } bool ok(int len) { for (int i = 0; i <= maxa; i++) dp[i] = 0; dp[len] = 1; for (int i = len + 1; i <= maxa; i++) { mmax(dp[i], dp[i -...
#include <bits/stdc++.h> using namespace std; map<long long, long long> mp1, mp2; long long n, x, yy, c; vector<pair<int, int>> v; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> x >> yy; v.push_back({x, yy}); mp1[x + yy]++; mp2[x - yy]++; } for (int i = 0; ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 200010; int nowarn; int n, m; namespace Tree { int head[MAXN], nxt[MAXN], to[MAXN], eidx; void init() { eidx = 0; memset(head, -1, sizeof(head)); } void adde(int u, int v) { to[eidx] = v, nxt[eidx] = head[u], head[u] = eidx++; } ...
#include <bits/stdc++.h> using namespace std; int main() { int n, s = 1, i; cin >> n; int a[n]; for (i = 0; i < n; i++) { cin >> a[i]; if (a[i] == s) { s++; } } cout << s - 1 << endl; s = 1; for (i = 0; i < n; i++) { if (a[i] == s) { cout << i ...
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf( %d , &n); long long broj = 3; int i; for (i = 0; i < 3 * n - 1; i++) { broj *= 3; broj %= 1000000007; } long long broj1 = 7; for (i = 0; i < n - 1; i++) { broj1 *= 7; broj1 %= 1000000007;...
#include <bits/stdc++.h> using namespace std; const int N = 100005; int a[N], cnt[N]; int f[N], bj[N]; vector<int> d[N]; int n, mx; long long ans; void init(int n) { for (int i = 1; i <= n; i++) f[i] = 1; for (int i = 2; i <= n; i++) { if (bj[i]) continue; f[i] = -1; for (int j...
#include <bits/stdc++.h> using namespace std; const int N = 1005, mod = 1e9 + 7; int yh[N][N], a[N]; long long kpow(long long a, long long b) { long long ans = 1; while (b) { if (b & 1) ans = ans * a % mod; a = a * a % mod; b >>= 1; } return ans; } int main() { for (int...
#include <bits/stdc++.h> using namespace std; int dp[81][81][81], n, m, i, j, k, ans, inf = 1000007, x, y, l, len; pair<int, int> p; vector<pair<int, int> > g[82]; int main() { cin >> n >> m; if (m > n) { cout << -1 << endl; return 0; } cin >> k; for (i = 0; i < k; i++) { ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 100005; int n; long long arr[MAXN][3]; map<pair<long long, long long>, pair<long long, int> > height; void update(long long x, long long y, long long z, int id) { if (height.find(make_pair((x), (y))) == height.end()) height[make_pair((...
#include <bits/stdc++.h> using namespace std; string s; int len; int main() { cin >> len; cin >> s; int sum = 0; cout << s[0]; for (int i = 1;; i++) { sum += i; if (sum >= len) break; cout << s[sum]; } }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; int t; cin >> t; while (t--) { int n; cin >> n; for (long long int i = (long long int)0; i < (long long int)n; i++) cout << i + 1 << ...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:1000000000 ) #pragma GCC optimize( Ofast,no-stack-protector ) using namespace std; const int maxn = (int)2e5 + 10; vector<int> ed[maxn]; int t[maxn], h[maxn]; long long dp[maxn][2]; void go(int v, int p) { vector<pair<long long, int> > g; ...
#include <bits/stdc++.h> using namespace std; pair<long double, pair<long long, long long> > c[250001]; long double p, q, abcd, ABCD; long long a, b, n, i, x, y; bool comp(pair<long double, pair<long long, long long> > a, pair<long double, pair<long long, long long> > b) { if (a.first < b.firs...
#include <bits/stdc++.h> using namespace std; long long n, m, k, t, x, y, z, w, ct, ans, f; string s, l; long long a[200005]; set<long long> si; queue<long long> qi; map<long long, long long> mi; vector<long long> vi; priority_queue<long long> pqdi; priority_queue<long long, vector<long long>, great...
#include <bits/stdc++.h> using namespace std; const int MAX = 1e5 + 10; const int MAXN = 1e4 + 10; const int MOD = 1e9 + 7; const int inf = 1e9; const double pi = acos(-1.0); const double eps = 1e-6; int dx[] = {0, -1, 0, 1}; int dy[] = {1, 0, -1, 0}; map<int, int> mymap, mymap1; int n, m; vecto...
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; template <typename T> struct modular { constexpr modular() : val(0) {} constexpr modular(const modular<T>& _m) : val(_m.val) {} template <typename U> constexpr modular(const U& _r = U()) { val = -MOD <= _r && _r < MO...
/** * Author: Daniel * Created Time: 2021-05-20 00:17:05 **/ // time-limit: 2000 // problem-url: https://codeforces.com/contest/1525/problem/E #include <bits/stdc++.h> using namespace std; #define F first #define S second #define ER erase #define IS insert #define PI acos(-1) #defi...
#include <bits/stdc++.h> using namespace std; long long n, s, a, ans, a11, r; vector<long long> aa, ab, c; int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> s >> a; if (s == 11) { a11++; ans += a; } if (s == 0) c.push_back(a); if (s == 10) aa.push...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int n; cin >> n; vector<int> v(n); for (int i = (int)(0); i < (int)(n); ++i) cin >> v[i]; sort(v.begin(), v.end()); cout << v[(n - 1) / 2] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } const double EPS = 1e-10; const double PI = acos(...
#include <bits/stdc++.h> long long mpow(long long a, long long n, long long mod) { long long ret = 1; long long b = a; while (n) { if (n & 1) ret = (ret * b) % mod; b = (b * b) % mod; n >>= 1; } return (long long)ret; } using namespace std; vector<int> v, v1; pair<int, in...
#include <bits/stdc++.h> using namespace std; int n, k, ans = -1; int a1[1000001], b1[1000001], a[1000001], b[1000001], t[1000001], d[1000001], in[1000001], Max[2000001]; int s = 1; int getmax(int v, int vl, int vr, int l, int r) { if (l > vr || r < vl) { return 0; } if (vl >= l && vr ...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3fffffff; const int SINF = 0x7fffffff; const long long LINF = 0x3fffffffffffffff; const long long SLINF = 0x7fffffffffffffff; const long double DINF = pow(2, 100); const int MAXN = 1007; const int MOD = static_cast<int>(1e9 + 7); const lo...
#include <bits/stdc++.h> using namespace std; char s[1010]; int main() { int f1 = 0, f2 = 0; scanf( %s , s); int len = strlen(s); for (int i = 0; i < len; i++) { if (s[i] == 0 ) { if (f1 == 0) { printf( 1 1 n ); f1 = 1; } else { printf( 3 1 n );...
#include <bits/stdc++.h> using namespace std; int oo = 1000000000; long long n; long long a[100005]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr); cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; if (n == 1) { cout << 1 << << 1 << endl; ...
#include <bits/stdc++.h> using namespace std; vector<int> me; long long sum(long long x) { return (x * (x + 1)) / 2; } int main() { int k; string s; cin >> k >> s; for (int i = 0; i < s.size(); i++) { if (s[i] == 1 ) { me.push_back(i); } } long long ans = 0, cnt = 0,...
#include <bits/stdc++.h> using namespace std; int n, m; int f[50][50], mn[50], mx[50]; const int INF = 1e9; int gm, gg, sm, ss; long long d[51][51] = {}, nd[51][51]; bool cang[50], cans[50], canb[50]; int main() { scanf( %d%d , &n, &m); for (int i = 0; i < (int)(n); ++i) for (int j = 0; j ...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; struct P { long long x, y; P() {} P(long long _x, long long _y) : x(_x), y(_y) {} P operator+(const P &o) { return P(x + o.x, y + o.y); } P operator-(const P &o) { return P(x - o.x, y - o.y); } long long operator*(const ...
#include <bits/stdc++.h> using namespace std; bool Check(long long A, long long B, long long T1, long long T2) { if (!A && !B) return !T1 && !T2; return !((T1 * A + T2 * B) % (A * A + B * B)) && !((T2 * A - T1 * B) % (A * A + B * B)); } int main() { long long X0, Y0, X1, Y1, X2, Y2; c...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); ; cin.tie(NULL); ; int n, b; double total = 0, maxx = 0; cin >> n >> b; double ar[n]; for (int i = 0; i < n; i++) { cin >> ar[i]; total += ar[i]; maxx = max(maxx, ar[i])...
#include <bits/stdc++.h> using namespace std; int main() { long long int l, r; cin >> l >> r; cout << YES << endl; for (long long int i = l; i <= r; i += 2) { cout << i << << i + 1 << endl; } }
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; long long n, m; char s[111111], t[111111]; bool ar[111111]; long long fail[111111], f[111111], ff[111111], dp[111111]; void kmp() { int i = 0, j = -1; fail[0] = -1; while (i < m) { while (j > -1 && t[i] != t[j])...
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const int dx4[] = {-1, 0, 1, 0}; const int dy4[] = {0, 1, 0, -1}; const int dx8[] = {-1, -1, -1, 0, 0, 1, 1, 1}; const int dy8[] = {-1, 0, 1, -1, 1, -1, 0, 1}; const int dxk[] = {-2, -2, -1, -1, 1, 1, 2, 2}; const int dyk[] = {-...
#include <bits/stdc++.h> using namespace std; const long long inf = 1e9; const long long inf64 = 1e18; const long long MOD = inf + 7; long long a[100005], p[100005]; long long n, m; bool check(long long mid) { long long last = 0; for (long long i = 0; i < (long long)n; i++) { if (last == m) ...
#include <bits/stdc++.h> using namespace std; const int N = 1007, K = 1007, INF = LONG_MAX; int i, j, n, x, y; int gcd(int x, int y) { while (x && y) { if (x > y) x %= y; else y %= x; } return x | y; } multiset<int> m; vector<int> ans; int main() { cin >> n; ...
#include <bits/stdc++.h> using namespace std; const int N = 1e7 + 5; const int M = 25; int A[M], B[M], n, m, x, y, cnt; int dp[M * 4][M * 4]; void Min(int &x, int y) { x = min(x, y); } int main() { cin >> n >> m; for (int i = 0; i < n; ++i) cin >> A[i]; for (int i = 0; i < n; ++i) cin >> B[i];...
#include <bits/stdc++.h> using namespace std; const double pi = 2 * acos(0.0); const int INF = 0x3f3f3f3f; const double inf = 1.0 / 0.0; void solve(); void Adi() { ios::sync_with_stdio(false); cin.tie(0); } int main() { Adi(); solve(); cerr << time taken : << (float)clock() / CLOC...
#include <bits/stdc++.h> using namespace std; int main() { int x, y, z, t1, t2, t3; cin >> x >> y >> z >> t1 >> t2 >> t3; unsigned long long xy, xz; if (x > y) { xy = x - y; } else { xy = y - x; } if (x > z) { xz = x - z; } else { xz = z - x; } unsigne...
#include <bits/stdc++.h> int mat[1010][1010]; int counts = 0; int main() { int n; scanf( %d , &n); for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) scanf( %d , &mat[i][j]); } counts = 0; for (int i = 1; i <= n; i++) counts += mat[i][i]; counts %= 2; int m; scan...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 20; int x[maxn], y[maxn]; int main() { int n, m; while (cin >> n >> m) { for (int i = 1; i <= n; i++) scanf( %d , &x[i]); for (int j = 1; j <= m; j++) scanf( %d , &y[j]); int ans = 0; int p1 = 1, p2 = 1; l...
#include <bits/stdc++.h> using namespace std; int main() { int w, h, k; cin >> w >> h >> k; int s = 0; w -= 2; for (int i = 0; i < k; i++) { s += (w + h) * 2; w -= 4; h -= 4; } cout << s; }
#include <bits/stdc++.h> using namespace std; long long w[100005], mon[305], droz[305], wlazi[305], t; long long dfs(long long co) { long long x; if (!droz[co]) return mon[co]; x = dfs(droz[co]); t -= x; mon[co] += x; return mon[co]; } int main() { long long n, q, a, b, c, mod = 10...
#include <bits/stdc++.h> const bool DEBUG = false; using namespace std; const long long maxn = 2e5 + 5; const long long INF = 1e18 + 1; const long long M = 1e9 + 7; const int lg = 21; int n, m, x[maxn], b[maxn], a[maxn], y[maxn]; vector<pair<int, int> > v; set<int> s; int main() { ios::sync_with...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int list[100000]; for (int i = 0; i < n; i++) { cin >> list[i]; } int max = 1; int temp = 1; for (int i = 0; i < n - 1; i++) { if (list[i] < list[i + 1]) { temp++; } else { i...
#include <bits/stdc++.h> using namespace std; long long T, A, B, res; vector<long long> P; int main() { cin >> T >> A >> B; if (T == 1) { if (A == 1) { if (B == 1) { res = -1; } } else { if (B % A == 0) { ++res; } while (B > 0) { ...
#include <bits/stdc++.h> using namespace std; const int inf = 1000 * 1000 * 1000 + 7; const int N = 1000 * 1000 + 7; long long a[N]; multiset<long long> st; int main() { int n; cin >> n; for (int i = 0; i < n; ++i) scanf( %I64d , a + i); long long ans = 0; for (int i = 0; i < n; ++i) { ...
#include <bits/stdc++.h> using namespace std; long long n, a[200010], cnt, id, k[200010]; double ans = -1, pre[200010]; double f(long long x, long long mid) { return ((pre[n] - pre[n - x]) + (pre[mid] - pre[mid - x - 1])) / (x * 2 + 1); } signed main() { scanf( %lld , &n); for (long long i = 1; ...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } const int MAX = 1e5; const long long MOD = 1e9 + 7; const long long inf = 1e18; int a[MAX + 5]; int main() { ios_base::sync_with_stdio(false); int n, m, r, i, j; long long an...
#include <bits/stdc++.h> using namespace std; const long long MAXN = 1e5 + 10; class Edge { public: long long dest, weight, cost; Edge() { dest = 0; weight = 0; cost = 0; } }; class Compare { public: bool operator()(pair<long long, long long>& a, pai...
#include <bits/stdc++.h> using namespace std; long long n, mx, now, ans; int main() { scanf( %lld , &n); mx = 2 * n - 1; while (now * 10 + 9 <= mx) now = now * 10 + 9; for (long long k = now; k <= mx; k += now + 1) { long long d = max(k - n, 1ll), u = max(k - d, d); ans += (u - d + 1) ...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; const long long mo = 1e9 + 7; int n, m, k, nn; template <typename T> inline void read(T &X) { X = 0; int w = 0; char ch = 0; while (!isdigit(ch)) { w |= ch == - ; ch = getchar(); } while (isdigit(ch)...
#include <bits/stdc++.h> using namespace std; template <class T1, class T2> ostream &operator<<(ostream &os, pair<T1, T2> &p); template <class T> ostream &operator<<(ostream &os, vector<T> &v); template <class T> ostream &operator<<(ostream &os, set<T> &v); template <class T1, class T2> ostream &opera...
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; int num[maxn]; long long ret; int n; void init() { scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %d , &num[i]); } void print() { for (int i = 1; i < n; i++) { int j = 0; for (; j < 30; j++) if (...
#include <bits/stdc++.h> using namespace std; int main() { int t, cont = 0, z = 0, x, n; int a[] = {1, 3, 6}; cin >> t; for (int i = 0; i < t; i++) { cin >> n; x = n; while (x > 0) { x = x / 10; z++; } if (z == 4) { for (int k = 1; k <= 9; k++) {...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int T = 1; cin >> T; while (T--) { int64_t w, h; cin >> w >> h; vector<int64_t> hor1, hor2, ver1, ver2; int64_t k; int64_t q; cin >> k; for (int i = 0; i...
#include <bits/stdc++.h> using namespace std; int main() { long long n, m; long long i; cin >> n >> m; long long cnt = 0; for (i = 1; i <= n; i++) { cnt += (m + i) / 5 - i / 5; } cout << cnt; return 0; }
#include <bits/stdc++.h> using namespace std; template <typename T, size_t N> long long SIZE(const T (&t)[N]) { return N; } template <typename T> long long SIZE(const T &t) { return t.size(); } string to_string(const string s, long long x1 = 0, long long x2 = 1e9) { return + ((x1 < s.siz...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; int k[1000010]; long long qpow(long long x, int n) { long long ans = 1; for (; n; n >>= 1, x = x * x % mod) if (n & 1) ans = ans * x % mod; return ans; } long long lpow(long long x, int n) { long long ans = 1;...
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; const int UNDEF = -1; const long long INF = 1e18; template <typename T> inline bool chkmax(T &aa, T bb) { return aa < bb ? aa = bb, true : false; } template <typename T> inline bool chkmin(T &aa, T bb) { return aa > bb ?...
#include <bits/stdc++.h> using namespace std; bool ps[1111111]; const int mod = 1e9 + 7; int main() { int p, k, c = 0; long long ans = 1; scanf( %d%d , &p, &k); for (int i = 0; i < p; ++i) { if (ps[i]) continue; c++; long long b = i; while (!ps[b]) ps[b] = 1, b = (b * k) ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; scanf( %d%d , &n, &m); if (m == 3 && (n == 5 || n == 6)) { printf( -1 n ); return 0; } for (int i = 0; i < m; ++i) printf( %d %d n , i, i * i + 10000000); for (int i = 0; i < n - m; ++i) printf( %d %d n , i, -i ...
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > vec[2102100]; pair<int, int> tr[2102100]; int lz[2102100]; int id[2102100]; int l[2102100]; int r[2102200]; int b[2102100]; int path[2102100]; int st[2102100]; void build(int p, int l, int r) { tr[p] = {0, -1}; lz[p] = 0...
#include <bits/stdc++.h> using namespace std; long long int MOD = 1000000007; long long int MOD1 = 998244353; mt19937 tw(chrono::high_resolution_clock::now().time_since_epoch().count()); unsigned long long power(unsigned long long x, int y, int p) { unsigned long long res = 1; x = x % p; while (y ...
#include <bits/stdc++.h> using namespace std; long long qu(long long a, long long b) { cout << ? << a << << b << endl; fflush(stdout); string s; cin >> s; if (s[0] == x ) return 1; return 2; } int main() { string s; while (1) { cin >> s; if (s != start ) retu...
#include <bits/stdc++.h> using namespace std; const int MD = 1000000007; inline void add(int &a, const int b) { a += b; if (a >= MD) a %= MD; } inline int mul(const int &a, const int &b) { long long r = 1ll * a * b; if (r >= MD) r %= MD; return r; } int a[9], n, k; bool vis[9]; boo...
#include <bits/stdc++.h> using namespace std; const int M = 1e5 + 10; const int INF = 0x3f3f3f3f; const int mod = 998244353; vector<long long> v; long long dfs(vector<long long> &v, int bit) { vector<long long> v0, v1; if (bit < 0 || v.size() == 0) return 0; for (long long &j : v) { if ((j...
#include <bits/stdc++.h> using namespace std; void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << = << a << endl; err(++it, args...); } inline int add(int a, int b) { a += b; return a >...
#include <bits/stdc++.h> using namespace std; const long double EPS = 1e-9; struct Point { long long x, y; Point() {} Point(long long x, long long y) : x(x), y(y) {} Point operator-(const Point& a) { return Point(x - a.x, y - a.y); } long long operator*(Point a) { return x * a.x + y * a.y; } ...
#include <bits/stdc++.h> using namespace std; const int maxn = 100000007; const double eps = 1e-6; const long long Inf = 1LL << 62; const long long mod = 1000000007; const long long pnum = 5761460; void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterat...
#include <bits/stdc++.h> using namespace std; long long M = 1e9 + 7; double pi = acos(-1.0); long long powerm(long long x, long long y) { long long res = 1; while (y) { if (y & 1) res = (res * x) % M; y = y >> 1; x = (x * x) % M; } return res % M; } long long power(long lon...
#include <bits/stdc++.h> using namespace std; const int maxn = 7e5 + 10; const int inf = 0x3f3f3f3f; int n, m, p, q, nx, ny; long long sum[300][300]; int dis[300][300]; int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0}; char maze[300][300]; void bfs(int sx, int sy, long long k) { dis[sx][sy] = 0, s...
#include <bits/stdc++.h> using namespace std; template <class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; } template <class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.precision(1...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000 * 100 + 50; vector<long long> nb[MAXN]; long long n, m, k, cmp, sz[MAXN]; bool mrk[MAXN]; long long pw(long long x, long long y) { if (!y) return 1; if (y == 1) return x % k; long long tmp = pw(x, y / 2); if (y % 2) re...