func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; long long dp[500005] = {0}; dp[3] = 8; long long fac = 2; for (long long i = 5; i <= 500000; i += 2) { dp[i] = dp[i - 2] + fac * (i + i + i - 2 + i - 2);...
#include <bits/stdc++.h> using namespace std; string str; long long int n, k; int main() { string temp; ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long int a, b, i, j, cnt = 0; cin >> str; n = str.size(); cin >> k; for (i = 0; i < k; i++) { cin >> temp;...
#include <bits/stdc++.h> using namespace std; const long long int mod = 1000 * 1000 * 1000 + 7; const double PI = 3.14159265358979323846264; const pair<long long int, long long int> steps[] = { {1, 0}, {0, 1}, {-1, 0}, {0, -1}, {1, -1}, {1, 1}, {-1, -1}, {-1, 1}}; template <typename... T> void read(T&...
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const double EPS = 1e-9; const int oo = 210000000; int n; vector<int> p[4]; vector<int> g[201]; int solve(int x) { bool used[201]; for (int i = 1; i <= n; i++) used[i] = 0; int ans = 0, m = 0; while (m < n) { ...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; cin >> a >> b >> c; if (a == b) cout << YES ; else if (b - a > 0 && c > 0) { if ((b - a) % c == 0) cout << YES ; else cout << NO ; } else if (b - a > 0 && c < 0) { cout << NO ; ...
#include <bits/stdc++.h> using namespace std; using ll = long long; using db = double; using vi = vector<int>; const int l = 20; const int maxn = 300006; int e[maxn][l]; int tote; map<int, int> S; int a[maxn]; int yy[maxn]; int rr[maxn]; int h[maxn][1000 / l]; int n, q; int app[maxn]; in...
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; const ll INF = 1e16 + 2; signed main() { ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); vector<pair<ll, ll>> pts; pts.emplace_back(); ll ax, ay, bx, by; cin >> pts[0].first >> pts[0]....
#include <bits/stdc++.h> using namespace std; const int maxn = 200005; int n, a[maxn], tot, b[maxn], ans; inline int read() { int ret = 0, f = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) f = -f; ch = getchar(); } while (ch >= 0 && ch <= 9 ) { re...
#include <bits/stdc++.h> using namespace std; const int INF = (int)1E9; int N, M, MB, LASTB; unsigned long long LASTM; vector<int> adj[100005]; int LB, lb[100005], revlb[100005], tr[100005], a[100005], primes[1000], P; class mask { public: unsigned long long v[16]; mask() { memset(v, 0, sizeof(...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { string s; int n, l = 0, r = 0, u = 0, d = 0; cin >> s; for (int i = 0; i < s.size(); i++) { if (s[i] == L ) ...
#include <bits/stdc++.h> using namespace std; int main() { string bin; cin >> bin; int i = 0; for (; i + 1 < bin.length(); i++) if (bin[i] == 0 ) break; cout << bin.substr(0, i) + bin.substr(i + 1) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const long long N = 2e5 + 7; const string alpha = abcdefghijklmnopqrstuvwxyz ; long long power(long long x, long long y) { long long res = 1; x = x; while (y > 0) { if (y & 1) res = (res * x); y = y >> 1; x = (x * x); } return ...
#include <bits/stdc++.h> using namespace std; int N, M; int main() { cin >> M >> N; if (M == N) { cout << N << 1 << << N << 2 ; return 0; } if (N - M == 1) { cout << M << 9 << << N << 0 ; return 0; } if (M == 9 && N == 1) { cout << 9 10 ; ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, ctr{}; cin >> n; string vec; cin >> vec; int likh = count(vec.begin(), vec.end(), 8 ); if (likh > 0) { int m = min(likh, n % 11); int len = n - m; len...
#include <bits/stdc++.h> using namespace std; const int MAX_N = 1e5 + 5; char s[MAX_N]; vector<int> v; int main() { scanf( %s , s + 1); int n = strlen(s + 1); int tot = 0; for (int i = 1; i <= n; i++) { if (s[i] == ( ) tot++; else if (s[i] == ) ) tot--; } ...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int dis[40]; long long adj[40]; vector<long long> v1; vector<long long> v2; void bt(int l, int r, long long mask) { if (l == r) { v1.emplace_back(mask); return; } bt(l + 1, r, mask); if (adj[l] & mask) return;...
#include <bits/stdc++.h> using namespace std; int32_t main() { long long n, m; cin >> n >> m; vector<long long> a(n), b(m); for (long long i = 0; i < n; ++i) cin >> a[i]; for (long long i = 0; i < m; ++i) cin >> b[i]; long long tot = 0; for (long long i = 0; i < n; ++i) tot ^= a[i]; ...
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; int sum(int a, int b) { int s = a + b; if (s >= mod) s -= mod; return s; } int sub(int a, int b) { int s = a - b; if (s < 0) s += mod; return s; } int mult(int a, int b) { return (1LL * a * b) % mod; } int n...
#include <bits/stdc++.h> using namespace std; int main(int argc, char **argv) { string i, o; cin >> i >> o; sort(i.begin(), i.end()); if (i == 0 && i == o) { cout << OK << endl; return 0; } unsigned int z; for (z = 0; z < i.length() && i[z] == 0 ; ++z) ; while ...
#include <bits/stdc++.h> using namespace std; const long long k = 2; struct node { vector<node*> to; node() { to.resize(k, 0); } long long cnt = 0; }; node* root = new node(); inline bool getbit(long long a, long long pos) { return a & (1 << pos); } void addstring(long long b) { vector<lon...
#include <bits/stdc++.h> using namespace std; int main() { long long k4, k7, i, l; char s[100]; long long n; gets(s); l = strlen(s); k4 = 0; k7 = 0; for (i = 0; i < l; i++) { if (s[i] == 4 ) k4++; if (s[i] == 7 ) k7++; } if (k4 == 0 && k7 == 0) cout << -1;...
#include <bits/stdc++.h> using namespace std; long long int a[1000005]; int main() { long long int i, j, k, l, n, m; cin >> n >> m; if (n / m < 3) { cout << -1; return 0; } j = 1; long long int f = 0; long long int x, y; x = 1, y = n - 1; while (y - x >= 4 && j < m)...
#include <bits/stdc++.h> using namespace std; template <typename T> void vout(T x) { cout << x << endl; exit(0); } int gcd(int a, int b) { while (a && b) { if (a > b) a %= b; else b %= a; } return a + b; } const long long inf = -1e18; const long long mod =...
#include <bits/stdc++.h> const long long INF = 0x3f3f3f3f; using namespace std; void sol() { long long n, m; while (cin >> n >> m) { string s; cin.ignore(); cin >> s; long long x[6][n]; string a[6] = { abc , acb , bca , bac , cab , cba }; memset(x, 0, sizeof(x)); ...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; const int dx[] = {1, 0, -1, 0, -1, -1, 1, 1}; const int dy[] = {0, 1, 0, -1, -1, 1, -1, 1}; const int OO = INT_MAX; long long tolong(string s) { stringstream ss; ss << s; long long n; ss >> n; return n; } string t...
#include <bits/stdc++.h> using namespace std; long long int pow1(long long int a, long long int b) { long long int ans = 1; while (b) { if (b & 1) ans = (ans * a) % 1000000007; a = (a * a) % 1000000007; b = b >> 1; } return ans; } int n, m; pair<int, int> a[100005]; vector<...
#include <bits/stdc++.h> using namespace std; int n, r, f[60005]; int dp[105][60005]; struct node { int a, b, sign; } pro[105]; bool cmp(node a, node b) { if (a.sign == b.sign) { if (a.sign == 1) return a.a < b.a; else return a.a + a.b > b.a + b.b; } return a.sign...
#include <bits/stdc++.h> using namespace std; const int inf = 1000000000; struct sTree { int pl, pr; int val, cnt, debt; } tree[4000009]; int treeSize; int NewNode(int LL, int RR) { int cur = ++treeSize; tree[cur].cnt = RR - LL + 1; return cur; } void CalcDebt(int LL, int RR, int cur...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n, m; cin >> n >> m; map<int, int> a; long long x; for (long long i = 0; i < m; i++) { cin >> x; a[x]++; } long long mini = INT_MAX; for (long lon...
#include <bits/stdc++.h> using namespace std; int main() { int x; string s1, s2; int cnt = 0; cin >> x >> ws; for (int i = x; i; i--) { cin >> s1; cin >> s2; if (s2.compare( soft ) == 0) cnt++; } if (x - cnt > cnt) cnt = x - cnt; for (int i = 0; i < 100; ++i) { ...
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1, c = getchar(); for (; !isdigit(c); c = getchar()) if (c == - ) f ^= 1; for (; isdigit(c); c = getchar()) x = x * 10 + c - 0 ; return f ? x : -x; } const int N = 200005; int n, m; char s[N]; struct H...
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf( %d , &n); int cir = 0; bool ans = true; int now; for (int i = 0; i < n; i++) { if (!i) { scanf( %d , &now); continue; } int temp; scanf( %d , &temp); if (temp > now) { ...
#include <bits/stdc++.h> using namespace std; int c[3]; void solve() { int m, n; cin >> m >> n; vector<vector<int>> matrix(m, vector<int>(n)); for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { cin >> matrix[i][j]; } } for (int i = m - 1; i >= 0; --i) { f...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t, x, y, f1, f2, f3, f4, LIMH = 100000, LIML = -100000; cin >> t; while (t--) { int q; cin >> q; int hiX, loX, hiY, loY; hiX = LIMH; hiY = LIMH; loX = LIML...
#include <iostream> using namespace std; int c1=0,c2=0,cur1=1,cur2=1,ok1=0,ok2=0; pair<int,int> f1[105*105],f2[150*105]; void fa1(int val){ cout<<val<< ; cout<<f1[cur1].first<< <<f1[cur1].second<< n ; cur1++; if(cur1==c1+1) ok1=1; } void fa2(int val){ cout<<va...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; string str; for (int o = 0; o < t; o++) { cin >> str; int n = str.length(); int pre = 0, suf = 0, total = 0; if (str[0] == 1 ) { pre = 0; } else { pre = 1; for (int i = ...
#include <bits/stdc++.h> using namespace std; const int maxn = 100000 + 1; int n, m, s; int b[maxn]; int p[maxn]; int ansn, anst; bool ok(int k) { int i = n - 1; int j = k - 1; int tansn = 0, tanst = 0; int ss = s; while (j >= 0) { if (i >= 0 && b[i] >= p[j]) { tanst += p...
#include <bits/stdc++.h> using namespace std; int main() { string s; char ch[6] = aaaaa ; int ara[4] = {0}; cin >> s; map<char, int> ms, ms2; for (int i = 0; i < s.size(); i += 4) { for (int j = 0; j < 4 && (i + j) < s.size(); j++) { if (s[i + j] == ! ) { ara[j]++; ...
#include <bits/stdc++.h> using namespace std; const int DBG = 0, INF = int(1e9); string toString(long long k) { stringstream ss; ss << k; string res; ss >> res; return res; } int toInt(string s) { stringstream ss; ss << s; int res; ss >> res; return res; } int main(...
#include <bits/stdc++.h> const long long mod = 998244353; const long long inf = 1e18 + 10; using namespace std; long long modpow(long long a, long long b) { long long res = 1; while (b) { if (b % 2) { res *= a; } a *= a; res %= mod; a %= mod; b /= 2; } ...
#include <bits/stdc++.h> using namespace std; const unsigned int N = 150; unsigned int n, p, q, now[N], c[N], ans; inline unsigned int read() { unsigned int x = 0, f = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) f = -1; ch = getchar(); } while (ch >= 0 ...
#include <bits/stdc++.h> using namespace std; int main() { int n, x; cin >> n >> x; int eq = 0; int minPos = 1, maxPos; for (int i(0); i < n; i++) { int a; cin >> a; if (a < x) minPos++; else if (a == x) eq++; } int c = 0; if (eq == 0) { ...
#include <bits/stdc++.h> using namespace std; const int MAX = 100100; const long long oo = 1e18; int N; long long P[MAX], D[MAX]; int L[MAX], R[MAX]; void init_L() { stack<int> S; for (int i = 0; i <= N + 1; ++i) { while (S.size() >= 2) { int x = S.top(); S.pop(); if ...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; const double C = 0.57721566490153286060651209; const double pi = acos(-1.0); const int mod = 1e9 + 7; const int maxn = 1e5 + 10; int a[maxn]; int b[maxn]; int used[maxn]; int main() { int n; scanf( %d , &n); int k = 0...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> v(n); int ans = 0, cnt = 0; for (int i = 0; i < n; i++) { cin >> v[i]; } for (int i = 0; i < n; i++) { if (v[i] == i) ans++; else if (v[v[i]] == i) { cnt = 1; }...
#include <bits/stdc++.h> using namespace std; int n, k; long long arr[200001]; vector<long long> v; string s; int find(int i) { int curr = v[i]; int num = i; for (int j = i + 1; j < n; j++) if (v[j] == curr) num = j; else break; return num; } int main() { ...
#include <bits/stdc++.h> using namespace std; vector<int> adj[500010], ar; bool vis[500010]; int u, v, n, m, s, res = 0; void dfs(int cur) { vis[cur] = true; for (auto i : adj[cur]) if (!vis[i]) dfs(i); ar.push_back(cur); } int main() { scanf( %d%d%d , &n, &m, &s); for (int i = 0...
#include <bits/stdc++.h> long long a[100005]; long long count[100005]; int vis[100005]; struct Element { long long l, r; Element(long long l, long long r) : l(l), r(r) {} }; Element getCount(long long k, int n) { long long lower = 0, upper = 0; int met = 0; for (int i = 1; i <= n; i++) {...
#include <bits/stdc++.h> using namespace std; int n, m, s, k, a[2010], b[2010], nxt[2010], sum[2010], dp[2010][2010]; inline int read() { int s = 0, w = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == - ) w = -1; for (; isdigit(c); c = getchar()) s = (s << 1) + (s << 3) +...
#include <bits/stdc++.h> using namespace std; int n, k; string a; int b[10000]; int memo[2000][2000]; int dp(int i, int d) { if (abs(d) == k && i == a.length()) return 0; if (i == a.length() || abs(d) == k) return 1; if (memo[i][d] != -1) return memo[i][d]; int x; if (a[i] == L ) ...
#include <bits/stdc++.h> using namespace std; const int MAX_N = 1e3 + 5; const double eps = 1e-10; struct TARGET { int x, y, t; double p; } mp[MAX_N]; int n; double dis[MAX_N][MAX_N]; double dp[MAX_N]; bool MAP_CMP(TARGET a, TARGET b) { return a.t < b.t; } void input() { scanf( %d , &n);...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, c = 0; cin >> n >> m; int a[n], i; for (i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); for (i = 0; i < m; i++) if (a[i] <= 0) c = c + a[i]; cout << abs(c); }
#include <bits/stdc++.h> const int M = 1e9 + 7, N = 2 * 1e5 + 3; using namespace std; int main() { long long a, b, f, k, b0; cin >> a >> b >> f >> k; b0 = b; int ans = 0; if (b < f || b < a - f) { cout << -1; return 0; } b0 = b - f; if (b0 < 0) { cout << -1; ...
#include <bits/stdc++.h> using namespace std; const long long maxn = 1e5 + 7; const long long inf = 0x3f3f3f3f3f3f3f; const long long mod = 20000311; int n; vector<int> a(100), b(100); vector<int> step[100], ves[100]; void solve(int n) { int st = 0; for (int i = 0; i < step[n].size(); i++) { ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 3; struct tree { int l, r, minn, lazy; long long sum; } tre[MAXN << 2]; int n, m; long long a[MAXN]; void build(int i, int l, int r) { tre[i].l = l, tre[i].r = r; tre[i].lazy = 0; if (l == r) { tre[i].minn = a[l...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); map<pair<int, int>, int> f; int t, it, n, res, tmp, x, y, resr, resl, i; string s; cin >> t; for (it = 1; it <= t; it++) { cin >> n; cin >> s; s = ...
#include <bits/stdc++.h> using namespace std; int vis[5][5]; int ac[5][5], bc[5][5]; pair<int, int> sum[100]; pair<int, int> cal(int a, int b) { if (a == 1) { if (b == 1) return pair<int, int>(0, 0); else if (b == 2) return pair<int, int>(0, 1); return pair<int, int>(1, 0...
#include <bits/stdc++.h> using namespace std; int n, m, q, a[501][501], x, y, s, ans; vector<int> v; int main() { ios::sync_with_stdio(false); cin >> n >> m >> q; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) cin >> a[i][j]; for (int p = 1; p <= q; p++) { cin >> x >> y; ...
#include <bits/stdc++.h> class MapValue { public: std::string configuration; int s1; MapValue() {} MapValue(std::string configuration, int s1) : configuration(configuration), s1(s1) {} }; class PairHash { public: std::size_t operator()(const std::pair<int, int> &p) const { ...
#include <bits/stdc++.h> using namespace std; const int maxn = 2.7e5 + 5; int m, n, k; int mod; int f[19][maxn]; vector<long long> g; int cnt[maxn]; int upd(const int &x) { if (x < 0) return x + mod; if (x >= mod) return x - mod; return x; } void add(int &x, const int &y) { x = upd(x + y...
#include <bits/stdc++.h> using namespace std; bool issquare(int n) { int sq = sqrt(n); if (sq * sq == n) { return true; } else { return false; } } int main() { long long int n; cin >> n; long long int ans = n; int f = 1; while (n != 1 and f == 1) { int sqr =...
#include <bits/stdc++.h> using namespace std; const int maxn = ((int)5e5) + 5; long long int sum[maxn]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; string s; cin >> s; for (int i = 0; i < s.length(); i++) { long long int total = 0; for (int...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; scanf( %d%d , &n, &m); long long x = 1; long long a = 1; for (int i = 1; i <= m; i++) a = (a << 1) % 1000000009; for (int i = 1; i <= n; i++) { a--; x = x % 1000000009 * (a + 1000000009) % 1000000009; } ...
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-9; const long long MOD = 1e9 + 7; pair<int, int> es[200000]; vector<pair<int, int> > g[200000]; int degree[200000]; set<pair<int, int> > st; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m, k...
#include <bits/stdc++.h> using namespace std; template <class T> void Read(T &x) { char c; bool f(0); while (c = getchar(), c != EOF) { if (c == - ) f = 1; else if (c >= 0 && c <= 9 ) { x = c - 0 ; while (c = getchar(), c >= 0 && c <= 9 ) x = x * 10 + c - 0...
#include <bits/stdc++.h> using namespace std; int main(int argc, char *argv[]) { string s; int min1 = 200, min2 = 200, min3 = 200, min4 = 200, min5 = 200; cin >> s; for (int i = 0; i < s.size(); i++) { if (s[i] == h && i < min1) min1 = i; if (s[i] == e && i < min2 && min1 < i) min2 =...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); long long a, b; cin >> a >> b; cout << YES << endl; for (long long i = a; i <= b; i += 2) cout << i << << i + 1 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int const N = 100000; long long a[N + 5], res; int n, p; int main() { cin >> n >> p; for (int i = 1; i <= n; ++i) { cin >> a[i]; a[i] += a[i - 1]; } for (int i = 1; i < n; ++i) res = max(res, a[i] % p + (a[n] - a[i]) % p); cout << r...
#include <bits/stdc++.h> using namespace std; int n, m, k, t; int index(int i, int j) { return (i - 1) * m + j; } int main() { cin >> n >> m >> k >> t; int arr[k]; for (int i = 0; i < k; i++) { int a, b; cin >> a >> b; arr[i] = index(a, b); } sort(arr, arr + k); while (...
#include<bits/stdc++.h> using namespace std; const int maxn=4e3+100; typedef long long ll; ll l[maxn],r[maxn],d[maxn]; int main() { int n,m,k;cin>>n>>m>>k; for(int i=1;i<=m;i++)cin>>l[i]>>r[i]; ll ans=0; for(int i=1,j=k;j<=n;i++,j++)//枚举第一个区间 { ll sum=0,w; ...
#include <bits/stdc++.h> using namespace std; const int MAX_BUF_SIZE = 16384; char BUFOR[MAX_BUF_SIZE]; int BUF_SIZE, BUF_POS; char ZZZ; const int MXN = 1000010; const int C = 262144; const int INF = 1000000001; int n, m, h; int s[MXN]; int sum; int sh; void test() { scanf( %d %d %d , &n, ...
#include <bits/stdc++.h> using namespace std; int N, D; signed long long A[202020]; int M; void solve() { int i, j, k, l, r, x, y; string s; cin >> N >> D; for (i = 0; i < (N); i++) cin >> A[i]; cin >> M; for (i = 0; i < (M); i++) { cin >> x; if (x == A[0] || x == A[N - 1] ...
#include <bits/stdc++.h> using namespace std; int N, D, a[105], ans; int main() { int T; cin >> T; while (T--) { cin >> N >> D; for (int i = 1; i <= N; i++) cin >> a[i]; for (int i = 2; i <= N; i++) { int move = min(a[i], D / (i - 1)); a[1] += move; D -= move ...
#include <bits/stdc++.h> using namespace std; int main() { int n, t, c; cin >> n >> t >> c; int ls = 0; int ans = 0; for (int i = 1; i <= n; i++) { int a; cin >> a; if (a > t) ls = i; else if (i - ls >= c) ans++; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d, e = 0, all = 0, i = 0; cin >> a >> b; c = a; d = b; while (c) { if ((c % 10) > e) { e = c % 10; } c = c / 10; } while (d) { if ((d % 10) > e) { e = d % 10; } d =...
#include <bits/stdc++.h> using namespace std; inline int read() { static int r; static char c; r = 0, c = getchar(); while (c < 0 || c > 9 ) c = getchar(); while (c >= 0 && c <= 9 ) r = r * 10 + (c - 0 ), c = getchar(); return r; } template <typename T> inline void print(T* a, i...
#include <bits/stdc++.h> using namespace std; int r1, c1, r2, c2; int CB[10][10]; int dr[8] = {1, -1, 1, -1, -2, -2, 2, 2}; int dc[8] = {2, 2, -2, -2, -1, 1, -1, 1}; int main() { char s[10]; scanf( %s , s); r1 = s[0] - a + 1; c1 = s[1] - 0 ; scanf( %s , s); r2 = s[0] - a + 1; ...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d, e; cin >> a >> b >> c >> d >> e; if (a == 0 && b == 0 && c == 0 && d == 0 && e == 0) cout << -1; else if ((a + b + c + d + e) % 5 != 0) cout << -1; else cout << (a + b + c + d + e) / 5; return 0; }...
#include <bits/stdc++.h> using namespace std; int main() { int t, x; cin >> t; while (t--) { cin >> x; while (x > 0) { if (x % 3 == 0) x = x % 3; else if (x % 7 == 0) x = x % 7; else { x -= 7; x -= 3; } } if ...
#include <bits/stdc++.h> using namespace std; const double pi = 3.1415926535; const double eps = 1e-6; struct TP { int x, h, id; } P[110000]; bool cmp(TP a, TP b) { return a.x < b.x; } int n, tot, Z[110000], F[110000], num[110000], ans[110000]; int main() { scanf( %d , &n); for (int i = 0; i...
#include <bits/stdc++.h> using namespace std; struct order { int num; int pos; }; bool fun(order a, order b) { return (a.num < b.num); } int main() { int n, k, i, j; cin >> n >> k; vector<order> a(n); for (i = 0; i < n; i++) { cin >> a[i].num; a[i].pos = i + 1; } se...
#include <bits/stdc++.h> using namespace std; long long max(long long a, long long b) { return a > b ? a : b; } long long min(long long a, long long b) { return a < b ? a : b; } long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } const long long INF = (long long)(1e17); const double PI...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 1; map<long long, long long> p; vector<long long> v; int n, size; long long t, k; int main() { scanf( %d %lld , &n, &k); for (int i = 1; i <= n; ++i) { scanf( %lld , &t); p[t]++; v.push_back(t); } sort(v...
#include <bits/stdc++.h> using namespace std; long long n = 0, k[10000001], a, b, c; void nhap() { cin >> a >> b >> c; } void solve() { k[n] = a + b + c; n++; k[n] = a * b * c; n++; k[n] = (a + b) * c; n++; k[n] = a * (b + c); n++; k[n] = a + b * c; n++; k[n] = a * b ...
#include <bits/stdc++.h> using namespace std; long long n, m; int gcd(int x, int y) { if (y == 0) return x; return gcd(y, x % y); } int main() { cin >> n >> m; string x, y; cin.ignore(); getline(cin, x); getline(cin, y); int lenx = (int)x.length(), leny = (int)y.length(); i...
#include <bits/stdc++.h> using namespace std; const int N = 8e5 + 10; struct Node { int sum; int free; int carry; Node() { sum = 0; free = 1; carry = 0; } Node(int x) { sum = x; if (x == 0) { free = 1; carry = 0; } else { free = 0...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); int n, p; cin >> n >> p; vector<int> a(n); for (auto &x : a) { cin >> x; } sort(a.begin(), a.end()); vector<int> ans; for (int x = 1; x <= 2000; x++) { int...
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; int dp[1010][1010]; char s1[1010], s2[1010]; int main() { scanf( %s%s , s1 + 1, s2 + 1); int n = strlen(s1 + 1); int m = strlen(s2 + 1); for (int i = 1; i <= n; i++) dp[i][0] = i; for (int i = 1; i <= m; i++) dp[0][i...
#include <bits/stdc++.h> using namespace std; inline long long rd() { long long x = 0, w = 1; char c = getchar(); while (!isdigit(c) && c != - ) c = getchar(); if (c == - ) c = getchar(), w = -1; while (isdigit(c)) x = x * 10 + c - 48, c = getchar(); return x * w; } const int N = 30000...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n, x; cin >> n >> x; long long cnt = 0; for (int i = 1; i <= (int)(n); ++i) { if (x % i == 0) { if ((x / i) <= n) { cnt++; } } } ...
#include <bits/stdc++.h> using namespace std; void Freopen() { freopen( title .in , r , stdin); freopen( title .out , w , stdout); } int read() { int g = 0, f = 1; char ch = getchar(); while (ch < 0 || 9 < ch) { if (ch == - )...
#include <bits/stdc++.h> using namespace std; int main() { int x, mx = -1, n, res = -1; scanf( %d , &n); for (int i = 0; i < n; i++) { scanf( %d , &x); if (x - mx > 1 && res == -1) res = i + 1; mx = max(mx, x); } printf( %d n , res); return 0; }
#include <bits/stdc++.h> using namespace std; const int MAX = 2000 + 10; const long double One = 1e6; long double EPS = 1e-9; struct pro { int sp, bp, st, bt; long double failp; } d[MAX]; struct Case { long double point, penalty; Case() { point = -1e10; penalty = 1e10; } ...
#include <bits/stdc++.h> const long long mod = 1000000007; using namespace std; vector<long long> child0, child1, claw; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n; cin >> n; vector<long long> a(n); long long max = 0; for (int i = 0; ...
#include <bits/stdc++.h> using namespace std; long long power(long long a, long long b) { if (b == 0) return 1; else if (b % 2 == 0) return (power(a, b / 2) * power(a, b / 2)) % 998244353; else return (a * power(a, b / 2) * power(a, b / 2)) % 998244353; } int main() { long long...
#include <bits/stdc++.h> using namespace std; int n, k, ans, a[2000]; int main() { cin >> n >> k; ans = k; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++) ans = max(ans, k / a[i] * a[j] + k % a[i]); cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; priority_queue<pair<int, int>, vector<pair<int, int> >, less<pair<int, int> > > p; int n, m, ans, ask; int now, head[100086], a[100086], x, y, vis[100086]; struct node { int next, to; } edge[100086]; void add(int x, int y) { now++; edge[now]....
#include <bits/stdc++.h> using namespace std; long long MOD = 1e9 + 7; long long MAX = 1e17; bool help[26]; int main() { ios_base::sync_with_stdio(0); ; int a, b, l, r; cin >> a >> b >> l >> r; if (a == 3 and b == 1 and l == 4 and r == 10) { cout << 4 << endl; return 0; } ...
#include <bits/stdc++.h> using namespace std; const long long N = 102, M = 200001; long long a[N], mem[M][N]; long long dp(long long n, long long k) { if (n < M && mem[n][k] != -1) return mem[n][k]; if (k == 0) return n; if (n == 0) return 0; if (n < M) return mem[n][k] = dp(n, k - 1) - dp...
#include <bits/stdc++.h> using namespace std; int main() { string f, m, s; cin >> f >> m >> s; string answer = ? ; if (f == m && s != m) { if (s == paper && f == rock ) { answer = S ; } else if (s == scissors && f == paper ) { answer = S ; } else if (s == ...