func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int tata[2010], g[2010]; vector<pair<int, int>> edges; bitset<2001> secret[2001]; int find(int x) { return (tata[tata[x]] == tata[x] ? tata[x] : tata[x] = find(tata[x])); } void unite(int a, int b) { a = find(a); b = find(b); assert(a != b); ...
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f, N = 10; int ans = inf, n, k, idx[N]; char arr[N][N]; int convert(int num) { int ret = 0; for (int i = 0; i < k; ++i) { ret = (ret * 10) + (arr[num][idx[i]] - 0 ); } return ret; } int main() { cin >> n >> k...
#include <bits/stdc++.h> using namespace std; template <class A, class B> inline bool mina(A &x, B y) { return (x > y) ? (x = y, 1) : 0; } template <class A, class B> inline bool maxa(A &x, B y) { return (x < y) ? (x = y, 1) : 0; } template <class Value_t> class SegmentTree { public: ty...
#include <bits/stdc++.h> using namespace std; int main(int argc, char* argv[]) { int v1, v2, t, d, sum, a, t1, t2; while (cin >> v1 >> v2 >> t >> d) { sum = v1 + v2; for (int i = 2; i < t; i++) { if (v1 <= v2) { v1 += d; sum += v1; } else { v2 += d; ...
#include <bits/stdc++.h> const int INF = 1e9 + 100; const long long lINF = 4e18; const double EPS = 1e-12; using namespace std; const int N = 5e5 + 100; int n, k, h[N], s[N], mn = INF, mxh[N], should = INF; vector<int> graph[N]; vector<int> can, need; void dfs1(int v, int par = -1, int mx = INF) { ...
#include <bits/stdc++.h> using namespace std; const int maxn = 100000; bool isprime[maxn]; int p[5], s[5], n; const int tenpow[6] = {1, 10, 100, 1000, 10000, 100000}; int tenpowmul[6][10]; int getd[maxn][5]; int ans; bool good[2 * maxn][6]; int tans[maxn]; void solve(int i) { if (i == 0) { ...
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == - ) f = -1; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + ch - 48; ch = getchar(); } return x * f; } namespace sta...
#include <bits/stdc++.h> using ll = long long; using namespace std; int main() { cin.tie(0); ios_base::sync_with_stdio(false); int n, m; char c; cin >> n >> m >> c; vector<string> vec(n); for (int i = 0; i < n; ++i) { cin >> vec[i]; } unordered_set<char> s; for (int i...
#include<bits/stdc++.h> using namespace std; #define show(x) cout<< #x << = << x << n ; #define mod 998244353 #define INF 1000000000000000000 #define pie 3.14159265358979323846 #define ll long long int #define pb push_back #define popcnt __builtin_popcount #define mp make_pair #define pii ...
#include <bits/stdc++.h> using namespace std; bool prime(long long x) { if (x == 2) { return true; } if (x <= 1) { return false; } for (int i = 2; i < sqrt(x); i++) { if (x % i == 0) { return false; } } return true; } void printv(vector<long long> v) {...
#include <bits/stdc++.h> using namespace std; int k[3]; int t[3]; long long a[100010]; struct mydata { int idx; long long x; bool operator<(const mydata &r) const { if (x == r.x) return idx < r.idx; else return x < r.x; } } b[100010]; std::priority_queue<long lo...
#include <bits/stdc++.h> using namespace std; const int MAXN = 100005, MAXM = 1005; bitset<MAXM> All, P[MAXM]; int n, m, Q; int start[MAXN], cnt = 0; int Ans[MAXN]; struct Node { int op, x, y, id; } T[MAXN]; struct Edge { int next, to; } edge[MAXN]; void add(int from, int to) { cnt++; ...
#include <bits/stdc++.h> using namespace std; template <class T, class L> bool smax(T& x, L y) { return x < y ? (x = y, 1) : 0; } template <class T, class L> bool smin(T& x, L y) { return x > y ? (x = y, 1) : 0; } const int maxn = 2e5 + 17; int n, m, gp[maxn], rate[maxn], cnt, sz[maxn]; unor...
#include <bits/stdc++.h> using namespace std; map<int, int> mp; long long v[100000]; vector<long long> V[200005]; long long sum[200005] = {0}, l[5005], r[5005], ans[5005]; int main() { long long int n, k, q, i, j, a, b, d, l1, t, sm = 0; cin >> t; for (i = 1; i <= t; i++) { cin >> l[i]; ...
#include <bits/stdc++.h> #pragma GCC optimize( O2 ) using namespace std; const int MAX = 1e5 + 5; const long long MAX2 = 11; const int MOD = 1000000000 + 7; const long long INF = 20000; const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1}; const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1}; const double pi = acos(-...
#include <bits/stdc++.h> using namespace std; char str[1000001]; int main() { int n; scanf( %d , &n); scanf( %s , str); int sum = 0; int ln = -1; int i, j, k, ans = 0; for (i = 0; i < n; i++) { if (str[i] == ( ) { sum++; if (sum == 0) { ans += i - ln + ...
#include <bits/stdc++.h> using namespace std; const long long MOD = (long long)1e9 + 7; const long long N = (long long)2e6 + 222; const long long INF = (long long)1e18; const double eps = (double)1e-6; long long n, m, l, r, used[N]; vector<long long> g[N]; set<long long> s; long long cnt = 0; void d...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; if (n <= 3 || n == 5 || n == 7 || n == 11) { cout << -1 << n ; } else { if (n % 2 == 0) { cout << n / 4 << n ; } else { ...
#include <bits/stdc++.h> using namespace std; int n, m, k, a[300000][2], fa[300000], sz[300000], top[300000], d[300000], prf[300000], f1[300000], q1[300000], q2[300000]; vector<int> g[300000], b[300000]; map<int, map<int, int> > f2[300000]; long long ans; void dfs1(int u) { d[u] = d[fa[u]] + 1; ...
#include <bits/stdc++.h> using namespace std; int arr[300005]; map<int, int> mp; vector<int> opt; int main() { int n, lst = 0; cin >> n; for (int i = 1; i <= n; i++) { scanf( %d , &arr[i]); if (mp[arr[i]] && mp[arr[i]] > lst) { mp[arr[i]] = 0; opt.push_back(++lst); ...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const double EPS = 1e-9; const long long INF = 1e18 + 2007; const double PI = 3.1415926535897932384626433832795; const long long N = 200005; long long gcd(long long a, long long b) { return a ? gcd(b % a, a) : b; } signed main(...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, i, j, z, x = 10, k = 0, year = 0, l = 0, f = 0; string s; cin >> n; while (n--) { cin >> s; x = 10; f = 0; year = 0; k = s.length() - 4; for (i = 1; i < k; i++) { f += x; x...
#include <bits/stdc++.h> using namespace std; long long read() { long long f = 1, x = 0; char ss = getchar(); while (ss < 0 || ss > 9 ) { if (ss == - ) f = -1; ss = getchar(); } while (ss >= 0 && ss <= 9 ) { x = x * 10 + ss - 0 ; ss = getchar(); } return f...
#include <bits/stdc++.h> using namespace std; int fw[100005], s[100005], t[100005]; bool r[100005], v[100005]; int res = 0; void dfs(int i) { v[i] = true; if (v[fw[i]]) { t[res] = i; } else { dfs(fw[i]); } } int main() { int n = 0; ios::sync_with_stdio(false); memse...
#include <bits/stdc++.h> using namespace std; template <class F, class T> T convert(F input, int width = 0, int prec = -1) { stringstream A; T res; if (prec > -1) A << fixed << setprecision(prec); A << setw(width) << setfill( 0 ) << input; A >> res; return res; } int main() { strin...
#include <bits/stdc++.h> using namespace std; string board[8]; int main() { for (int i = 0; i < 8; ++i) cin >> board[i]; const char* s = WB ; for (int i = 0; i < 8; ++i) { int c = board[i][0] == B ; for (int j = 1; j < 8; ++j) { if (board[i][j] != s[(c + j) % 2]) { cout...
#include <bits/stdc++.h> std::mt19937 rng( (int)std::chrono::steady_clock::now().time_since_epoch().count()); const int ms = 101; long long memo[ms][ms], memo2[ms][ms][ms]; long long a[ms]; std::string str; long long dp(int l, int r); long long dp2(int l, int r, int x) { if (r - l <= 0) return 0...
#include <bits/stdc++.h> using namespace std; int n, i, x, b[110000]; void modify(int x, int y) { for (; x <= n; x += x & -x) b[x] = ((b[x]) > (y) ? (b[x]) : (y)); } int get(int x) { int ans = 0; for (; x; x -= x & -x) ans = ((ans) > (b[x]) ? (ans) : (b[x])); return ans; } int main() { ...
#include <bits/stdc++.h> using namespace std; int a, b, c, d, arr[200001], arr2[200001], e, f, g, mn = 1e9, ans, sum, ct, t, ct2, mx, sum2; bool kk; int main() { cin >> a; for (int i = 0; i < a; i++) { cin >> arr[i]; sum += arr[i]; } ...
#include <bits/stdc++.h> using namespace std; int x[5], y[5]; int matr[5005][5005]; inline void err() { for (int i = 0; i <= 5000; ++i) for (int j = 0; j <= 5000; ++j) matr[i][j] = -1; } inline void fil(int i, int j, int ii, int jj, int val) { for (int a = i; a <= ii; ++a) for (int b = j...
#include <bits/stdc++.h> using namespace std; int n[101]; vector<int> cost; int main() { int N, B; cin >> N >> B; int o, e; o = e = 0; for (int i = 0; i < N; i++) { cin >> n[i]; } for (int i = 0; i < N; i++) { if (n[i] % 2) o++; else e++; if (o...
#include <bits/stdc++.h> using namespace std; int root, n; vector<int> mp[200605]; int Dfs(int u, int from) { set<int> s; for (int i = 0; i < mp[u].size(); i++) { int v = mp[u][i]; if (v == from) continue; int tmp = Dfs(v, u); if (tmp == -1) return -1; s.insert(tmp + 1); ...
#include <bits/stdc++.h> using namespace std; long long dx[] = {1, 0, -1, 0}; long long dy[] = {0, 1, 0, -1}; long long gcd(long long x, long long y) { if (y == 0) return x; else return gcd(y, x % y); } long long expo(long long n, long long m, long long p) { long long r = 1; n = ...
#include <bits/stdc++.h> using namespace std; const int MaxN = 14050; template <class t> inline void read(t &s) { s = 0; register int f = 1; register char c = getchar(); while (!isdigit(c)) { if (c == - ) f = -1; c = getchar(); } while (isdigit(c)) s = (s << 3) + (s << 1) + ...
/* Solution by:- --------------Sannidhay Vashal ----------------NIT SRINAGAR */ #include<iostream> #include<vector> #include<algorithm> #include<stack> #include<queue> #include<map> #include<math.h> #include<climits> #include<set> #include<cstring> #include<unordered_map> #includ...
#include <bits/stdc++.h> using namespace std; long long ans, n, m, a, r, c, sum, sums[1000002], sumsR[1000002], sumsC[1000002], sumsR2[1000002], sumsC2[1000002]; const long long p = 998244353; struct el { long long x, r, c; }; bool operator<(el x, el y) { return x.x < y.x; } el arr[1000002]; l...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long cnt, n, pre, i, j, k, l, x, y, z, a[310][310]; cin >> n; pre = 0; for (i = 1; i <= n; i++) { for (j = 1; j <= n; j++) { cin >> a[i][j]; pr...
#include <bits/stdc++.h> using namespace std; const int NM = 1000005; const int Mod = 1000000007; int N, m, n, p26 = 0, pi[NM], i, x, y, b[NM]; char a[NM]; bool kmp[NM]; long long put(long long a, int b) { if (!b) return 1; if (b & 1) return a * put(a * a % Mod, b >> 1) % Mod; return put(a * a...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 100; char s[N]; int cost(char a, char b) { return min(abs(b - a), 26 - abs(b - a)); } int main() { int ans = 1e9; int n; cin >> n; scanf( %s , s + 1); for (int i = 1; i <= n; i++) { int j = i + 1, k = j + 1, t = k + 1;...
#include <bits/stdc++.h> using namespace std; using namespace std; int m, h, t, n, i, j, k; int a[200000], q[200000]; long long sum[200000], ans; long long pas[200000]; long long get(int i, int j) { return sum[j] - sum[i] + a[i]; } int main() { cin >> n; for (i = 0; i < n; i++) cin >> a[i]; ...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) #pragma GCC target( sse,sse2,sse3,sse4,fma4,ssse3,popcnt,abm,aes,pclmul,cld,inline-all-stringops ) #pragma comment(linker, /STACK:66777216 ) using namespace std; static unsigned rnd() { static int second = 124612741; second ^= second << 13; ...
#include <bits/stdc++.h> using namespace std; long long read() { long long cc = getc(stdin); for (; cc < 0 || cc > 9 ;) cc = getc(stdin); long long ret = 0; for (; cc >= 0 && cc <= 9 ;) { ret = ret * 10 + cc - 0 ; cc = getc(stdin); } return ret; } long long power(long ...
#include <bits/stdc++.h> using namespace std; string st; long n, k, ans, calc; int main() { ios_base::sync_with_stdio(0); cin >> n >> k; cin >> st; for (int i = 0; i < st.size(); i++) { if (st[i] == # ) ++calc; else { ans = max(ans, calc); calc = 0; } ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 5005; struct Point { double x, y, z; }; double dist(Point a, Point b) { return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) + (a.z - b.z) * (a.z - b.z)); } Point p[MAXN]; double dis[MAXN]; int main() {...
#include <bits/stdc++.h> using namespace std; const int N = 510; bool dp[N][N]; int n, k; int a[N], b[N]; int main() { cin >> n >> k; long long sum1 = 0, sum2 = 0; long long ans = 0; for (int i = 1; i <= n; i++) { scanf( %d%d , &a[i], &b[i]); sum1 += a[i]; sum2 += b[i]; ...
#include <bits/stdc++.h> using namespace std; int main() { string s, t; getline(cin, s); getline(cin, t); int x = -1, y = -1; for (int i = 0, j = 0; j < t.length(); j++) { i += s[i] == t[j]; if (i == s.length()) { x = j; break; } } for (int i = s.length(...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const double eps = 1e-9; char mapp[110][110]; int main() { cin.sync_with_stdio(false); int n, m; int ans, cnt; int x1, x2, y1, y2; while (cin >> n >> m) { ans = 0; x1 = 0x3f3f3f3f, x2 = -1, y1 = 0x3f3f...
#include <bits/stdc++.h> using namespace std; int maxN = -1; vector<string> str; bool ok = false; int main() { string s; while (getline(cin, s)) { maxN = max(maxN, (int)s.size()); str.push_back(s); } for (int i = 0; i < maxN + 2; i++) cout << * ; cout << endl; int n = str....
#include <bits/stdc++.h> using namespace std; inline long long read() { char c = getchar(); long long x = 0; bool f = 0; for (; !isdigit(c); c = getchar()) f ^= !(c ^ 45); for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48); if (f) x = -x; return x; } long long n, a[...
#include <bits/stdc++.h> using namespace std; template <class T> T sqr(T x) { return x * x; } long double pi = 3.1415926535897932384626433832795; long long mod = 1e9 + 7; const int N = 1e6 + 10; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } vector<vector<long long> > e(...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<int> scores; for (int i = 0; i < n; i++) { int temp; cin >> temp; scores.push_back(temp); } int max = scores[0]; int min = scor...
#include <bits/stdc++.h> using namespace std; const long long int inf = 1e9 + 7; const long long int inf2 = inf * inf; priority_queue<long long int, vector<long long int>, greater<long long int>> mnheap; long long int gcd(long long int x, long long int y) { if (x == 0) return y; return gcd(y % x...
#include <bits/stdc++.h> using namespace std; const int MAX = 100000 + 10; int pos[MAX], s[MAX]; int main() { int n, a; while (cin >> n) { memset(pos, 0, sizeof pos); memset(s, -1, sizeof s); for (int i = 1; i <= n; ++i) { cin >> a; if (s[a] == -1) s[a] = 0; ...
#include <bits/stdc++.h> using namespace std; const int MAXN = -1; int n; int main() { int t; scanf( %d , &t); for (int cs = (0); cs < (int)(t); cs++) { scanf( %d , &n); printf( %d %d n , n - 1, 1); } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; const int INF = 1e9; struct Node { int cnt; int xy, yx; int minx, miny; int maxx, maxy; Node() : cnt(0), xy(-INF), yx(-INF), minx(INF), miny(INF), maxx(0), maxy(0) {} Node(int x, int y) : cnt(1), xy(x - y), yx(y ...
#include <bits/stdc++.h> using namespace std; struct DirectedEulerPath { int n; vector<vector<int> > g; vector<int> path; void init(int _n) { n = _n; g = vector<vector<int> >(n + 1, vector<int>()); path.clear(); } void add_edge(int u, int v) { g[u].push_back(v); } void ...
#include <bits/stdc++.h> using namespace std; const long long maxn = 1e5 + 7; long long n, k, a; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> k; a = n / (2 * (k + 1)); cout << a << << a * k << << n - a * (k + 1); }
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC target( avx,avx2,fma ) #pragma GCC optimization( unroll-loops ) using namespace std; int n; pair<int, int> e[200005]; int deg[200005]; vector<int> Adj[200005]; void solve(); int main() { solve(); } void solve() { cin >> n; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; int n, m; int long long dp[maxn]; vector<pair<int long long, int long long>> veci[maxn]; set<pair<int long long, int long long>> st; bool mark[maxn]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0...
#include <bits/stdc++.h> using namespace std; inline int in() { int x; scanf( %d , &x); return x; } const int N = 2 * 1e5 + 10; const long long MOD = 1e9; const long double eps = 1e-12; int n, m; long long fib[N], fib_sum[N], g0[4 * N], g1[4 * N], lazy[4 * N]; void precalc() { fib[0] =...
#include <bits/stdc++.h> using namespace std; const string s[] = { Washington , Adams , Jefferson , Madison , Monroe , Adams , Jackson , Van Buren , Harrison , Tyler , Polk , Taylor , Fillmore , Pierce , Buchanan , Lincoln , Johnson , Gran...
#include <bits/stdc++.h> using namespace std; int main() { string str; cin >> str; vector<char> a(str.begin(), str.end()); cin >> str; vector<char> b(str.begin(), str.end()); int res = 0; for (int i = 0; i < a.size(); i++) { if (a[i] >= a ) a[i] += - a + A ; if (b[i] >= a...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; int i, j, temp, d = 0; for (i = 0; i < n; i++) { cin >> a[i]; } for (i = 0; i < n; i++) { for (j = i + 1; j < n; j++) { if (a[i] > a[j]) { temp = a[j]; a[j] = a[i...
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; const int NN = 1 << 20; int qpow(int a, int b) { int ret = 1; while (b) { if (b & 1) ret = (long long)ret * a % mod; a = (long long)a * a % mod; b >>= 1; } return ret; } namespace NTT { const int g =...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; map<int, int> m; vector<int> v; for (int i = 0; i < 4 * n; i++) { int x; cin >> x; m[x]++; if (m[x] % 2) v.push_back(x); } ...
#include <bits/stdc++.h> int main() { const double eps = 1e-6; double x[3], y[3]; for (int i = 0; i < 3; ++i) scanf( %lf%lf , &x[i], &y[i]); x[1] -= x[0]; x[2] -= x[0]; y[1] -= y[0]; y[2] -= y[0]; x[0] = y[0] = 0; double cx = (y[2] * (x[1] * x[1] + y[1] * y[1]) - y...
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 7; const int MXN = 1e6 + 7; const double EPS = 1e-9; const double PI = acos(-1); long long a[MXN], cnt[MXN], n; long long dp1[MXN], dp2[MXN], pref[MXN]; int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; ...
#include <bits/stdc++.h> using namespace std; const int a1[2][6] = {{1, 3, 4, 5, 2, 6}, {3, 2, 6, 4, 1, 5}}; int i, j, k, n, m; int a[10], f[10]; char p[10]; string s; set<string> yao, laji; void sou(string a, int ty) { if (laji.count(a)) return; int i, j; if (ty) laji.insert(a); for (i ...
#include <bits/stdc++.h> using namespace std; long long n, m, k, l; int main() { cin >> n >> m >> k >> l; long long x = m * ((k + l) / m + ((k + l) % m == 0 ? 0 : 1)); if (x <= n) cout << x / m << endl; else cout << -1 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 1e3 + 5; const int inf = 0x3f3f3f3f; struct node { int val, r, d; } cells[maxn * maxn]; int n, m, q; inline int getIndex(int x, int y) { return x * (m + 1) + y; } void solve() { scanf( %d%d%d , &n, &m, &q); for (int i = 0; i <= n...
#include <bits/stdc++.h> using namespace std; int n, a[200100], b[200100]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) { int x; cin >> x; b[x] = i; } int mx = ...
#include <bits/stdc++.h> int main() { double n, r; std::cin >> n >> r; double ang = 180 / n; ang = 3.1415926536 * ang / 180.0; double R = sin(ang) / (1 - sin(ang)) * r; printf( %0.7lf n , R); return 0; }
#include <bits/stdc++.h> using namespace std; const long double pi = acos(-1); const long long inf = 1LL << 30; const double eps = 1e-9; const long long mod = 1e9 + 7; const int Alpha = 28; const int MAXLEN = 1e5 + 5; class SuffixAutomata { public: struct state { int len, link; int ne...
#include <bits/stdc++.h> using namespace std; int main() { long int n, i; cin >> n; long int a[n]; for (i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); long long int sum = 0, j = 0; for (i = 0, j = n - 1; i < j; i++, j--) { sum = sum + ((a[i] + a[j]) * (a[i] + a[j]));...
#include <bits/stdc++.h> using namespace std; int main() { string s[] = { Washington , Adams , Jefferson , Madison , Monroe , Adams , Jackson , Van Buren , Harrison , Tyler , Polk , Taylor , Fillmore , Pierce , Buchanan , Lincoln , ...
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const long long inf = (1LL << 60); const double pi = acos(-1); long long powmod(long long a, long long b) { long long res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1) res = res * a % mod; ...
#include <bits/stdc++.h> using namespace std; int main() { int n, i, j, k, l; cin >> n >> i >> j >> k >> l; int man = (abs(k - i) + abs(l - j)); if (i == n && k == 0 || k == n && i == 0) cout << min(man + 2 * min(n - j, n - l), man + 2 * min(j, l)); else if (j == n && l == 0 || l == n && j...
#include <bits/stdc++.h> using namespace std; char a[100010]; int n, k; int main() { cin >> n >> k >> a; for (int i = 0; i < n && k > 0; i++) { if (a[i] == 4 && a[i + 1] == 7 ) { if (i % 2 == 0) a[i] = a[i + 1] = 4 ; else if (i > 0 && a[i - 1] == 4 ) { if (...
#include <bits/stdc++.h> using namespace std; long long n, k, l; const long long mod = 998244353; long long qpow(long long a, long long n) { long long ret = 1; while (n > 0) { if (n & 1) ret = ret * a % mod; a = a * a % mod; n >>= 1; } return ret; } const int maxn = 4005; ...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; class matrix { public: int row, col; std::vector<std::vector<int>> num; matrix(int row, int col, int defaultValue = 0) { this->num = std::vector<std::vector<int>>(row, std::vector<int>(col, defaultValue)); ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n % 10 <= 5) { cout << (n / 10) * 10; } else { cout << ((n / 10) + 1) * 10; } }
#include <bits/stdc++.h> typedef struct S { unsigned val, ki, ka, min, max; long long unsigned sum; struct S *lc, *rc; } v; v *alloc(unsigned ki, unsigned ka, unsigned val) { v *x; x = (v *)malloc(sizeof(v)); x->val = val; x->min = val; x->max = val; x->ki = ki; x->ka = ka;...
#include <bits/stdc++.h> using namespace std; int main() { int n, col, row; cin >> n; col = sqrt(n); while (1) { if (n % col == 0) { int a, b; a = n / col; b = col; if (a >= b) cout << b << << a << endl; else cout << a << << b...
#include <bits/stdc++.h> using namespace std; const int inf = 1e9 + 5; const long long linf = 1e18 + 5; const int mod = 1e9 + 7; const int N = 100 + 5; const int M = 10; int n, a[M], C[N][N], dp[M][N]; int f(int cur, int n) { if (cur == M) return !n; int &r = dp[cur][n]; if (r != -1) return ...
#include <bits/stdc++.h> using namespace std; const long long INF = 9999999999999999; const double PI = acos(-1); long long A[100]; int main() { ios::sync_with_stdio(false); long long a, b, c; cin >> a >> b >> c; A[0] = a; A[1] = b; for (long long i = 2; i < 50; i++) { A[i] = A[i...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int a, b; cin >> a >> b; int s[6] = {a, b, b - a, -a, -b, a - b}; int n; cin >> n; cout << (s[(n - 1) % 6] % (long long)1000000007 + (long long)1000000007) % ...
#include <bits/stdc++.h> using namespace std; long long a[100005]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, i; cin >> n; long long mx = -1, mn = 1e18; for (i = 0; i < n; i++) { cin >> a[i]; mn = min(mn, a[i]); mx = max(mx, a[i])...
#include <bits/stdc++.h> using namespace std; unsigned long long int Gcd(unsigned long long int a, unsigned long long int b) { if (b == 0) return a; else return Gcd(b, a % b); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); unsigned long long int l, r, gcd, lcm; ...
#include <bits/stdc++.h> using namespace std; using ll = long long; void solve() { int n; int q; cin >> n >> q; string s; cin >> s; vector<array<int, 26>> pref(n + 1); pref[0].fill(0); for (int i = 0; i < n; i++) { for (int c = 0; c ...
#include <bits/stdc++.h> using namespace std; template <class c> struct rge { c b, e; }; template <class c> rge<c> range(c i, c j) { return rge<c>{i, j}; } template <class c> auto dud(c* x) -> decltype(cerr << *x, 0); template <class c> char dud(...); struct debug { template <class c...
#include <bits/stdc++.h> using namespace std; typedef vector<int> vt; int a[110000]; int n; void solve() { vt v; vt::iterator it; for (int i = 0; i < n; i++) { it = upper_bound(v.begin(), v.end(), a[i]); if (it == v.end()) v.push_back(a[i]); else *it = a[i]; }...
#include <bits/stdc++.h> using namespace std; int main() { string s1, s2; cin >> s1; s2 = hello ; int i = 0, j = 0, count = 0; int l = s1.length(); while (l) { if (s1[i] != s2[j]) i++; if (s1[i] == s2[j]) { i++; j++; count++; } l--; } ...
#include <bits/stdc++.h> using namespace std; int main() { ifstream in( input.txt ); string s; bool e = false; int i, c = 0; getline(cin, s); for (i = 0; i < s.size(); i++) { if (s[i] == 1 ) e = true; if (e == true) if (s[i] == 0 ) c++; } if ((c >= 6) && (e == t...
#include <bits/stdc++.h> using namespace std; int a[122], b[122]; int main() { int n, k, t, ans = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> k >> t; a[k]++; b[t]++; } for (int i = 1; i <= 100; i++) if (a[i] > 0) ans += a[i] * b[i]; cout << ans << endl; }
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; using LL = long long; using PII = pair<int, int>; using PLL = pair<LL, LL>; using VI = vector<int>; using VVI = vector<VI>; const int INF = 1e9; const int MXN = 55; const int MXM = 2e4 + 5; int n, m, k; VVI init(MXN, VI(MXM, 0...
#include <bits/stdc++.h> using namespace std; template <class T> inline T gcd(T a, T b) { if (a < 0) return gcd(-a, b); if (b < 0) return gcd(a, -b); return (b == 0) ? a : gcd(b, a % b); } template <class T> inline T lcm(T a, T b) { if (a < 0) return lcm(-a, b); if (b < 0) return lcm(a, ...
#include <bits/stdc++.h> using namespace std; template <typename T> inline T second(T a) { return a * a; } template <class T> inline string tostring(T a) { ostringstream os( ); os << a; return os.str(); } template <typename T> inline long long tolong(T a) { long long res; istr...
#include <bits/stdc++.h> using namespace std; int main() { do { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); } while (false); string L, R; cin >> L >> R; reverse(L.begin(), L.end()); L.resize(R.size(), 0 ); reverse(L.begin(), L.end()); int n, m...
#include <bits/stdc++.h> using namespace std; const int N = 2010; struct edge { int to, next, w; } e[200010]; int head[N], ecnt, n, vis[N], val[N], mark[N][N]; long long dp[2][N][N], cover[N][N], sum; inline void adde(int from, int to, int w) { e[++ecnt] = (edge){to, head[from], w}, head[from] = e...
#include <bits/stdc++.h> const double eps = 1e-9; double a, b, c, nx, mx, ny, my, ans; long long ax, ay, bx, by; int main() { std::cin >> a >> b >> c >> ax >> ay >> bx >> by; ans = std::abs(ax - bx) + std::abs(ay - by); if ((a < eps && a > -eps) || (b < eps && b > -eps)) { printf( %.7lf n , an...