func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; const int N = 1010; const int MAXK = 1000010; int n, m, k, p, a[N][N], row[N], col[N]; long long ans1[MAXK], ans2[MAXK]; multiset<long long> Unis; void solve(long long *ans, int n, int *a, int dta) { Unis.clear(); for (int i = 1; i <= n; ++i) { U...
#include <bits/stdc++.h> using namespace std; int c, hi, hb, wi, wb; inline long long f(int x) { long long k1 = x; long long k2 = 1ll * (0ll + c - 1ll * x * wi) / wb; return k1 * hi + k2 * hb; } int main() { cin >> c >> hi >> hb >> wi >> wb; int kek1 = c / wi; int l = 0; int r = ke...
#include <bits/stdc++.h> using namespace std; int n, m, a[101000], tmp; struct C { int b, p; } c[101000]; long long ans = 0, tot; bool cmp(C c1, C c2) { return c1.b < c2.b; } priority_queue<int, vector<int>, greater<int> > q; int main() { scanf( %d%d , &n, &m); for (int i = 1; i <= n; i++) s...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; int t, n, a[N]; int main() { ios::sync_with_stdio(false); for (cin >> t; t; t--) { cin >> n; long long l = 0, r = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; l += a[i]; r ^= a[i]; } ...
#include bits/stdc++.h using namespace std; #define ll long long int #define pb push_back #define ppb pop_back #define pf push_front #define ppf pop_front #define all(x) (x).begin(),(x).end() #define uniq(v) (...
#include <bits/stdc++.h> using namespace std; long long gcd(long long x, long long y) { if (y == 0) return x; return gcd(y, x % y); } long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } void XsliferX() { ios::sync_with_stdio(0); ios_base::sync_with_stdio(0); cin.tie(0), c...
#include <bits/stdc++.h> template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } constexpr long long MAX = 5100000; constexp...
#include <bits/stdc++.h> using namespace std; const long long inf = 1000ll * 1000ll * 1000ll; const long long inf64 = inf * inf; const double pi = acos(-1.0); long long Abs(long long a) { return (a >= 0 ? a : -a); } template <typename T> inline T Sqr(T a) { return a * a; } vector<int> par, sz; b...
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 10; const int inf = 1e9; int arr[N], pos[N], rMax[N]; int main() { int n, m; scanf( %d %d , &n, &m); for (int i = 0; i < n; i++) { scanf( %d , arr + i); pos[arr[i]] = i; } fill(rMax, rMax + N, n - 1); while (...
#include <bits/stdc++.h> using namespace std; void change_stream(char* in, char* out) { ifstream fin; fin.open(in); ofstream fout; fout.open(out); if (fin && fout) { freopen(in, r , stdin); freopen(out, w , stdout); } } long long a[500], renum[500]; void shift(long long i...
#include <bits/stdc++.h> using namespace std; long long dist(const pair<long long, long long> &a, const pair<long long, long long> &b) { return (a.first - b.first) * (a.first - b.first) + (a.second - b.second) * (a.second - b.second); } int main() { ios_base::sync_with_stdio(...
#include <bits/stdc++.h> using namespace std; int a[200010]; int base; int n, tmp; int main() { cin >> n; cin >> base; a[100000]++; for (int i = 1; i <= n - 1; i++) { cin >> tmp; int offset = tmp - base; if (abs(offset) > 100000) { cout << NO << endl; return...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; inline int read() { 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 = getcha...
#include <bits/stdc++.h> using namespace std; template <class T, class T2> inline int chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; } template <class T, class T2> inline int chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; } const int MAXN = (1 << 20); int n, sum = 0; vect...
#include <bits/stdc++.h> using namespace std; int main() { long long i, n, ans, ghor, j, k, flag = 0; cin >> n; for (i = 0;; i++) { ans = (n - 1) / (5 * pow(2, i)); if (ans == 0) break; n = n - (5 * pow(2, i)); } ghor = i + 1; long long p = pow(2, i); long long cnt = 1;...
#include <bits/stdc++.h> using namespace std; void solve() { int i, j, n, m; cin >> n; vector<int> vec(n); vector<int> ans; int count = 1; for (int i = 0; i < n; i++) { cin >> vec[i]; } for (int i = 0; i < n; i++) { count = 1; for (int j = 0; j < n; j++) { i...
#include <bits/stdc++.h> using namespace std; const int block_size = 320; const long long mod = 1e9 + 7; const long long inf = 1e9 + 7; const long double eps = 1e-9; const double PI = atan(1) * 4; template <typename T> inline int sign(const T &a) { if (a < 0) return -1; if (a > 0) return 1; ...
#include <bits/stdc++.h> using namespace std; char matrix[2020][2020]; int dp[2020][2020]; pair<int, int> p[2020 * 2020]; int n, m; int fill(int i, int j) { if (i < 0 || j < 0 || i >= n || j >= m) { return 0; } if (dp[i][j] == -1) { int start_x = i; int start_y = j; int c...
#include <bits/stdc++.h> int n, m; int f[2000010], mx, mn = (int)1e7; short check(int x) { int i; for (i = x; i <= mx; i += x) if (f[i + x - 1] >= i && f[i + x - 1] - i > m) return 0; return 1; } int main() { int i, x; scanf( %d%d , &n, &m); for (i = 1; i <= n; i++) { scanf...
#include <bits/stdc++.h> using namespace std; string raspuns; long long n, x, y; int read() { char c; int nr = 0; c = getchar(); while (c < 0 || c > 9 ) c = getchar(); while (c >= 0 && c <= 9 ) { nr = nr * 10 + (c - 0 ); c = getchar(); } return nr; } int main()...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { for (; b; a %= b, swap(a, b)) ; return a; } int main() { ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); int t; cin >> t; while (t--) { int n, x; cin >> n >> x; int cnt =...
#include <bits/stdc++.h> using namespace std; const int maxn = 1005; int in[maxn]; int t1, t2; struct edge { int v, w; }; vector<edge> g[maxn]; void dfs(int u, int fa) { if (in[u] == 1) { if (!t1) t1 = u; t2 = u; } for (edge e : g[u]) { if (e.v == fa) continue; df...
#include<bits/stdc++.h> #define lowbit(x) ((x)&(-(x))) #define DEBUG fprintf(stderr, Running on Line %d in Function %s n ,__LINE__,__FUNCTION__) #define SZ(x) ((int)x.size()) #define mkpr std::make_pair #define pb push_back typedef long long ll; typedef unsigned int uint; typedef unsigned long l...
#include <bits/stdc++.h> using namespace std; namespace whatever { int readu() { char ch = getchar(); while (!isdigit(ch)) ch = getchar(); int value = ch - 0 ; ch = getchar(); while (isdigit(ch)) { value = value * 10 + ch - 0 ; ch = getchar(); } return value; } void w...
#include <bits/stdc++.h> using namespace std; const int mxN = 20; int n, m, a[mxN][mxN], c[4][2] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}}; vector<vector<int>> ops, cs{{0, 2, 3, 1}, {2, 4, 5, 3}, {0, 2, 4, 5, 3, 1}}; array<int, 2> p[mxN * mxN + 1]; set<vector<int>> vis; void oc(int i1, int j1, bool b) { ops....
#include <bits/stdc++.h> using namespace std; void solve(vector<int> &v, int n, int k) { set<int> s; for (int i = 0; i < n; i++) s.insert(v[i]); if (s.size() >= k) { vector<int> res; cout << YES << endl; for (auto x : s) { for (int i = 0; i < n; i++) { if (x == v[i]...
#include <bits/stdc++.h> using namespace std; const int N = 200010; int n, a[7], cnt[7], t[N]; void GetData() { int i; scanf( %d , &n); for (i = 0; i < 3; ++i) scanf( %d , &a[i]); for (i = 0; i < n; ++i) scanf( %d , &t[i]); } void Solve() { int i, j, ans, mn; bool flag = false; s...
#include <bits/stdc++.h> using namespace std; signed main() { cin.tie(0); cout.tie(0); cin.sync_with_stdio(0); cout.sync_with_stdio(0); long long n; cin >> n; vector<long long> v(n); vector<long long> msuf(n + 1); for (long long i = 0; i < n; ++i) cin >> v[i]; for (long long ...
#include <bits/stdc++.h> #pragma warning(disable : 4996) using namespace std; const long long MOD = 1e9 + 7; const long long MODD = 1e9 + 1; const long long MODL = 998244353; const long long N = 200005; const long long INF = 1e18; const long long mx = 1e5 + 1; long long Power(long long x, long long y)...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int e = 0; int d; int a[15], b[15], l[10]; for (int f = 0; f < n; f++) cin >> a[f]; for (int j = 0; j < m; j++) cin >> b[j]; int rr = 0, tt = 0; for (int g = 0; g < n; g++) { if (a[g] < 0 ||...
#include <bits/stdc++.h> using namespace std; int main() { int n, k, a; cin >> n >> k; list<int> lst; map<int, bool> vis; for (int i = 0; i < n; i++) { cin >> a; if (lst.size() < k) { if (vis.find(a) == vis.end()) { lst.push_front(a); vis[a] = true; ...
#include <bits/stdc++.h> using namespace std; struct node { int x, y; } A[10005], B[10005], CA[10005], CB[10005]; int tim, qim; node operator+(node a, node b) { return node{a.x + b.x, a.y + b.y}; } node operator-(node a, node b) { return node{a.x - b.x, a.y - b.y}; } int operator*(node a, node b) { re...
#include <bits/stdc++.h> using namespace std; int ky[8] = {-1, 1, -2, 2, -2, 2, -1, 1}; int kx[8] = {-2, -2, -1, -1, 1, 1, 2, 2}; int dy[4] = {-1, 0, 1, 0}; int dx[4] = {0, 1, 0, -1}; int ddy[8] = {-1, 0, 1, -1, 1, -1, 0, 1}; int ddx[8] = {-1, -1, -1, 0, 0, 1, 1, 1}; const double PI = acos(-1.0); int ...
#include <bits/stdc++.h> using namespace std; int di[] = {0, 0, 1, -1, 1, 1, -1, -1}; int dj[] = {1, -1, 0, 0, 1, -1, 1, -1}; inline int calcMedian(vector<int> &vec) { if (((int)vec.size()) % 2 == 1) { return vec[((int)vec.size()) / 2]; } return (vec[((int)vec.size()) / 2 - 1] + vec[((int)vec....
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); ; string s; int flag = 0; cin >> s; string at = at , dot = dot ; for (int i = 1; i < s.size() - 3; i++) { if (s.substr(i, 2) == at && flag == 0) { s.replace(i, 2, @ ); fl...
#include <bits/stdc++.h> using namespace std; signed main() { long long int n, max = 0; cin >> n; map<string, long long int> m; string s; while (n--) { cin >> s; m[s]++; } for (auto it = m.begin(); it != m.end(); it++) { if (it->second > max) { max = it->second;...
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; const int maxn = 2 * 1e5; char s[maxn]; int n; int l, r; int is_pal(int l, int r) { for (int i = l; i <= (r + l) / 2; i++) { if (s[i] != s[r - (i - l)]) return 0; } return 1; } int main() { cin >> (s + 1); r =...
#include <bits/stdc++.h> using namespace std; const int maxn = 300010; int n; long long w[maxn], ma[maxn][2], ans; vector<int> a[maxn]; vector<long long> c[maxn]; bool visited[maxn]; void dfs(int u) { visited[u] = true; for (int i = 0; i < (int)a[u].size(); ++i) { int v = a[u][i]; if...
#include <bits/stdc++.h> using namespace std; int main() { long long int l, r; cin >> l >> r; (l == r) ? cout << l : cout << 2; }
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 9; int a[N], b[N]; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) { int n; 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; void read_file(bool outToFile = true) {} int A[500 + 9]; int n, m, b, mod; int dp[2][500 + 9 + 2][500 + 9 + 1]; int build() { int p = 0; for (int c = 0; c <= b; c++) dp[p][0][c] = dp[!p][0][c] = 1; for (int c = 0; c <= b; c++) for (int r = 1; r...
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { return a % b == 0 ? b : gcd(b, a % b); } const int MAXN = 100010; int fst[MAXN], sec[MAXN]; int ans[MAXN]; int N, K; int cmp(const int &a, const int &b) { return a > b; } int main() { while (scanf( %d%d , &N, &K) != EOF) { f...
#include <bits/stdc++.h> using namespace std; int main() { int n; double a, b, jav = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> a >> b; jav += b; } jav /= n; cout << jav + 5; }
#include <bits/stdc++.h> #pragma comment(linker, /STACK:10000000 ) using namespace std; template <class T> T inline sqr(T x) { return x * x; } const double pi = 3.1415926535897932384626433832795; const double eps = 1e-8; long long ans = 0; bool f(long long x, long long y, long long n) { long ...
#include <bits/stdc++.h> using namespace std; class p1328D { public: void solve() { int q; cin >> q; while (q--) { int n; cin >> n; vector<int> t(n); for (int i = 0; i < n; i++) cin >> t[i]; int sum = 1; for (int i = 1; i < n; i++) { ...
#include <bits/stdc++.h> using namespace std; const int N = 100005; int n, m, s, vis[100005], cy; long long t; int nex(int x, int y) { if (x < m) return (x + y) % n; else return (x - y + n) % n; } int main() { scanf( %d %d , &n, &m); scanf( %d %lld , &s, &t); --s; while...
#include <bits/stdc++.h> using namespace std; template <typename T> static ostream& operator<<(ostream& stream, const vector<T>& t); template <typename T> static istream& read(T, T, istream& = cin); template <typename T> static istream& operator>>(istream& stream, vector<T>& t) { return read((t).begin...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; int main() { ios_base::sync_with_stdio(0); cin.tie(0); ; int n; cin >> n; vector<int> dem(1000); int maxx = INT_MIN; for (int i = 0; i < n; ++i) { int u; cin >> u; dem[--...
#include <bits/stdc++.h> using namespace std; int a[10]; int main() { int n; while (~scanf( %d , &n)) { memset(a, 0, sizeof(a)); for (int i = 1; i <= n; i++) scanf( %d , &a[i]); sort(a + 1, a + n + 1); printf( %d n , a[(1 + n) / 2]); } }
#include <bits/stdc++.h> using namespace std; const int MAX = 5005; int n; string strs[MAX]; string strp[MAX]; int anspos = 0; int strlens[MAX]; int vis[MAX]; int change[MAX][2]; string ansa, ansb; bool cal(int pos) { int len = strs[pos].size(); strlens[pos] = len; int l = -1, r = len;...
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > E[1010]; int deg[1010], vis[1010]; vector<pair<int, pair<int, int> > > ans; int N, P; int main() { int u, v, d; while (~scanf( %d%d , &N, &P)) { for (int i = 0; i < N; i++) deg[i] = 0, E[i].clear(); for (int i = 0; i <...
#include <bits/stdc++.h> using namespace std; int a[55], b[55]; int main() { int n, m; scanf( %d%d , &n, &m); for (int i = 1; i <= n; i++) scanf( %d , a + i); for (int i = 1; i <= m; i++) scanf( %d , b + i); long long ans = 1ll << 62; for (int x = 1; x <= n; x++) { long long maxv = -...
#include <bits/stdc++.h> using namespace std; const long long base = 1E9 + 7; const int N = 200100; const double ep = 0.0000001; int n; long long x[N], y[N]; long long cx = 0, cy = 0; void fail() { cout << NO ; exit(0); } bool symmetric(int i, int j) { long long x1 = cx - x[i] * n; ...
#include <bits/stdc++.h> int compare(char *s, char *t, int l) { int i; for (i = 0; i < l; i++) { char a = toupper(s[i]), b = toupper(t[i]); if (a != b) return a - b; } return 0; } int main() { static char ss[100][100 + 1], cc[100 + 1], lucky[100]; static int ll[100]; int n,...
#include <bits/stdc++.h> using namespace std; char s[1100]; int main() { scanf( %s , s); for (int i = 0; s[i]; i++) printf( %c , s[i]); for (int i = strlen(s) - 1; i >= 0; i--) printf( %c , s[i]); return 0; }
#include <bits/stdc++.h> using namespace std; string p[105] = { }; int cts[105] = {0}; string pass; int main(int argc, char const *argv[]) { int n, k; cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> p[i]; int xx = p[i].length(); cts[xx]++; } for (int i = 1; i <= 100...
#include <bits/stdc++.h> using namespace std; const double PI = 3.141592653589793238462643383279502884197169399375105820974944592307816406286; double d, h, v, e; int main() { scanf( %lf%lf%lf%lf , &d, &h, &v, &e); if (4 * v - d * d * PI * e <= 0) printf( NO n ); else printf( YES n%...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { int n, m; cin >> n >> m; int sum = 0; for (int i = 0; i < n; i++) { int a; cin >> a; sum += a; } ...
#include <bits/stdc++.h> using namespace std; const int N_ = 100500; int N, M; vector<int> gph[N_], rev[N_], bth[N_]; int outdg[N_], indg[N_]; bool visited[N_]; vector<int> ord; void dfs(int u) { visited[u] = true; for (int i = 0; i < gph[u].size(); i++) { int v = gph[u][i]; if (!vis...
#include <bits/stdc++.h> using namespace std; int main() { long n, t; cin >> n >> t; string s1, s2; getline(cin, s1); getline(cin, s1, . ); getline(cin, s2); long a = -1, count = 0; for (int i = 0; i < s2.length(); i++) if (s2[i] >= 5 ) { a = i; break; }...
#include <bits/stdc++.h> using namespace std; const int INF = 400000; const double EPS = 1e-9; int mods(int a, int b) { return (b + (a % b)) % b; } int n, m, k, x, ans, p[105], s[105], strongest[105]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m >> k;...
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> istream& operator>>(istream& in, pair<T1, T2>& a) { in >> a.first >> a.second; return in; } template <typename T1, typename T2> ostream& operator<<(ostream& out, pair<T1, T2> a) { out << a.first << << a.second;...
#include <bits/stdc++.h> using namespace std; using bigint = long long int; using vi = vector<int>; using vll = vector<long long int>; int cnt[200001]; int main() { int N, A; cin >> N >> A; for (int i = 0; i < N; i++) { int x; cin >> x; cnt[x]++; } int ans = 0; if (...
#include <bits/stdc++.h> using namespace std; int main() { int H, W, K; cin >> H >> W >> K; vector<string> photo(H); for (int h = 0; h < int(H); ++h) cin >> photo[h]; vector<vector<char> > star(H, vector<char>(W, 0)); for (int r = 1; r < int(H - 1); ++r) for (int c = 1; c < int(W - 1);...
#include <bits/stdc++.h> using namespace std; int n, m, a, b, ans[400]; string s[400]; long long calc(int pos, int res) { for (int i = res + 1; i <= 10; i++) { for (int j = 0; j < 1 << i; j++) { string t = ; for (int k = 0; k < i; k++) t = t + (char)(((j >> k) & 1) + 0 ); if...
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; long long dp[5010][5010]; char s[5010], z[5010]; long long solve() { int M = strlen(s), N = strlen(z); for (int i = 0; i <= M; i++) dp[i][0] = 0; for (int i = 0; i <= N; i++) dp[0][i] = 0; for (int i = 1; i <= M; i++) ...
#include <bits/stdc++.h> using namespace std; int a[] = {0, 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51, 1, 2, 1, 14, 1, 2, 2, 14, 1, 6, 1, 4, 2, 2, 1, 52, 2, 5, 1, 5, 1, 15, 2, 13, 2, 2, 1, 13, 1, 2, 4,...
#include <bits/stdc++.h> using namespace std; const int Max_n = 2e5 + 10; const int Max_m = 4e5 + 10; int f[Max_n]; struct A { long long val; int pos; bool operator<(const A &a) const { return val < a.val; } } a[Max_n]; struct Edge { int u, v; long long cost; bool operator<(const E...
#include <bits/stdc++.h> using namespace std; int defence[4]; int atack[4]; int main() { for (int i = 0; i < 4; i++) cin >> defence[i] >> atack[i]; int maximum = max(defence[0], defence[1]); maximum = max(maximum, atack[0]); maximum = max(maximum, atack[1]); if (defence[0] > atack[2] && defe...
#include <bits/stdc++.h> using namespace std; int n, m, k, q; int x[411111], y[411111], a[411111], b[411111], aa[411111], bb[411111]; int ans[411111]; int mi[2000222]; void init(int pos, int l, int r) { mi[pos] = -1; if (l == r) return; init(pos + pos, l, (l + r) / 2); init(pos + pos + 1, (l...
#include <bits/stdc++.h> using namespace std; int n; int ans[400] = { 1, 9, 245, 126565, 54326037, 321837880, 323252721, 754868154, 328083248, 838314395, 220816781, 893672292, 166441208, 251255697, 114256285, 118775501, 482714697, 11784725, 460862131, 550384565, 106742...
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0; bool t = false; char ch = getchar(); while ((ch < 0 || ch > 9 ) && ch != - ) ch = getchar(); if (ch == - ) t = true, ch = getchar(); while (ch <= 9 && ch >= 0 ) x = x * 10 + ch - 48, ch = getchar(); retu...
#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; priority_queue<long long int> mxheap; long long int gcd(long long int x, long long int y) { if...
#include <bits/stdc++.h> int main() { char s[150]; int o = 1, z = 0, a[150]; scanf( %s , &s); for (int i = 0; i < strlen(s); i++) { a[i] = s[i] - 0 ; } for (int i = 0; i < strlen(s) - 1; i++) { if (a[i] == a[i + 1]) { o++; if (o == 7) { printf( YES n ); ...
#include <bits/stdc++.h> using namespace std; const int mxn = 1e5 + 5; int n, a[mxn], c[mxn]; bool vis[mxn]; int main() { scanf( %d , &n); for (int(i) = (int)(1); (i) <= (int)(n); ++(i)) scanf( %d , a + i); int cnt = 0; for (int(i) = (int)(n); (i) >= (int)(1); --(i)) { c[i] = c[i + 1] + ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 7; int a[N], n, q; long long sum[N << 2][11], mul[11] = {1}; long long SUM[11], LA[11]; int lazy[N << 2][11]; void pushup(int rt) { for (int i = 0; i < 10; ++i) { sum[rt][i] = sum[rt << 1][i] + sum[rt << 1 | 1][i]; } } voi...
#include <bits/stdc++.h> using namespace std; const long long INF = 1ll << 32; const int mod = 1e9 + 7; inline int add(int x, int y) { x += y; if (x >= mod) return x - mod; return x; } inline int sub(int x, int y) { x -= y; if (x < 0) return x + mod; return x; } inline int mul(in...
#include <bits/stdc++.h> using namespace std; long long n; bool isvalid(long long x) { if (x >= 0 && x <= n - 1) return true; else return false; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; vector<long long> a(n); for (long long i = 0; i...
#include <bits/stdc++.h> using namespace std; int ans; int main() { int d, n, u, i, prev; cin >> d >> n; for (i = 0; i < n; i++) { cin >> u; if (i and prev != 1) ans += d - prev + 1; prev = u + 1; if (prev > d) prev -= d; } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { int n; cin >> n; int ans = 1e9; for (int i = 1; i * i <= n; i++) { ans = min(ans, i - 1 + (n - i + i - 1) / i); } ...
#include <bits/stdc++.h> const int n = 7; const int msiz = 1 << n; const int mod = 1000000007; int a[n]; int ans[msiz]; long long int tans[msiz]; struct matrix { long long int cont[msiz][msiz]; matrix operator*(const matrix& r) const { matrix p; int i, j, k; for (i = 0; i < msiz;...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int max_n = 1e5 + 5; string q[max_n]; int dig[10][2]; int main() { string s; cin >> s; int n; scanf( %d , &n); for (int i = 1; i <= n; i++) cin >> q[i]; for (int i = 0; i <= 9; i++) { dig[i][0] = i; ...
#include <bits/stdc++.h> using namespace std; const int inf = 2000000000; int H, T, R, m, hi[205], ti[205], n, hj[205], tj[205], h[205][205], t[3000000][3], w, d[205][205]; void adde(int x, int y, int X, int Y) { t[w][0] = X; t[w][1] = Y; t[w][2] = h[x][y]; h[x][y] = w++; } struct node...
#include <bits/stdc++.h> using namespace std; const int N = 101000; int n, z[N], a[N], b[N]; set<pair<int, int> > Set; int main() { scanf( %d , &n); for (int i = 0; i < n; i++) { scanf( %d , &a[i]); } for (int i = 0; i < n; i++) { scanf( %d , &b[i]); } vector<int> ans; ...
#include <bits/stdc++.h> using namespace std; int n, a, r, m; vector<int> h; vector<long long> pref; long long cost(long long goal) { long long indexl = distance(h.begin(), lower_bound(h.begin(), h.end(), goal)); long long cost_a = 0; if (indexl > 0) { cost_a = goal * (indexl)-pref[indexl - ...
#include <bits/stdc++.h> typedef struct { double x, y; } point_t; typedef struct { double x, y, r; } circle_t; typedef struct { double A, B, C; } Line; Line zhong_chui_xian(circle_t circle1, circle_t circle2) { Line L1; point_t p; double k; p.x = (circle1.x + circle2.x) / 2; ...
#include <bits/stdc++.h> using namespace std; template <typename A, typename B> string to_string(pair<A, B> p); template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p); template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p); string to_str...
#include <bits/stdc++.h> using namespace std; const long double eps = 1e-9; const int inf = (1 << 30) - 1; const long long inf64 = ((long long)1 << 62) - 1; const long double pi = 3.1415926535897932384626433832795; const string task = ; template <class T> T sqr(T x) { return x * x; } const int...
#include <bits/stdc++.h> using namespace std; const long long inf = (1ll << 60); const int maxn = 10010; long long dp[2][maxn], c; int p[maxn], s[maxn]; int n, id; int main() { scanf( %d%I64d , &n, &c); for (int i = 0; i < n; i++) scanf( %d , p + i); for (int i = 0; i < n; i++) scanf( %d , s +...
#include <bits/stdc++.h> using namespace std; void in(long long int &number) { bool negative = false; register int c; number = 0; c = getchar(); if (c == - ) { negative = true; c = getchar(); } for (; (c > 47 && c < 58); c = getchar()) number = number * 10 + c - 48; if (...
#include<bits/stdc++.h> #define mx 100005 #define lli long long int #define ulli unsigned long long int #define mset(a,b) memset(a, b, sizeof(a)) #define infile freopen( in.txt , r , stdin); #defi...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma ) #pragma GCC optimize( unroll-loops ) using namespace std; long long int MOD = 998244353; double eps = 1e-12; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL...
#include <bits/stdc++.h> using namespace std; const int N = 32005; int n, m, i, j, f; int a[N]; long long ans; int main() { scanf( %d%d , &n, &m); for (i = m + 1; i <= (n + 1) / 2; i++) { for (j = m + 1; j < 2 * i; j++) { f = (i * (2 * i - j) + (n + 1) * (2 * j - i)) / (i + j); ...
#include <bits/stdc++.h> using namespace std; const int Mod = 1e9 + 7; const double pi = 2 * acos(0.0); const int N = 3e5 + 5; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, t; cin >> t; while (t--) { cin >> n; int x, z = 0, tot = 0; f...
#include <bits/stdc++.h> using namespace std; int n, x; int a[105]; long double dp[2][105][10005]; const long double threshold = 1e-12; int main() { scanf( %d%d , &n, &x); long double s = 0.0; for (int i = 1; i <= n; i++) { scanf( %d , &a[i]); s += a[i]; } dp[0][0][0] = 1.0; ...
#include <bits/stdc++.h> using namespace std; const long long int MOD = 1000000007; const long double PI = 3.14159265; long long int powerWithMod(long long int base, long long int exponent, long long int MODulus = LLONG_MAX) { long long int ansult = 1; base %= MODulus; w...
#include <bits/stdc++.h> using namespace std; const long long int N = 100005; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); { long long int i, j, k, n, m, ans = 0, cnt = 0, sum = 0; cin >> n; vector<long long int> v; long long int a[n]; ...
#include <bits/stdc++.h> using namespace std; const int INF = 1e7; const long long MOD = 998244353; vector<vector<int> > occur; vector<vector<long long> > minC, dp; long long gV(int l, int r) { if (l == r + 1) { return 1; } return dp[l][r]; } void calc(int l, int r) { int cMinC = m...
#include <bits/stdc++.h> #pragma comment(linker, /STACK: 2000000 ) using namespace std; int main(void) { srand(time(0)); cout << fixed << setprecision(7); cerr << fixed << setprecision(7); int n; ios_base ::sync_with_stdio(0); cin.tie(0); cin >> n; function<int(int)> ok = [&](int ...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; vector<long long> v[100009], vv[100009]; long long vis[100009], dis[101][100001], ar[100001]; void bfs(long long k) { queue<long long> q; memset(vis, 0, sizeof(vis)); for (long long x : vv[k]) { q.push(x); vis...