func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> bool x[1000000] = {0}; int a, b, c; int y[10001]; int main() { for (a = 2; a < 1001; a++) { if (x[a] == 0) { for (b = a * a; b < 1000000; b = b + a) x[b] = 1; } } int qqq[11200]; int p, q, k, z, r, s = 1, t = 13; while (s != 11185) { k = t; ...
#include <bits/stdc++.h> using namespace std; template <typename T> T BigMod(T b, T p, T m) { if (p == 0) return 1; if (p % 2 == 0) { T s = BigMod(b, p / 2, m); return ((s % m) * (s % m)) % m; } return ((b % m) * (BigMod(b, p - 1, m) % m)) % m; } template <typename T> T ModInv(T ...
#include <bits/stdc++.h> using namespace std; int n, a[200015]; char s[200015]; vector<pair<int, int> > ans; int main() { scanf( %d , &n); for (int i = (1); i <= (n); i++) scanf( %d , &a[i]); scanf( %s , s + 1); sort(a + 1, a + n + 1); int lp = 1, rp = n; for (int i = (1); i <= (n); i+...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e6 + 7; int h[MAXN], fen[MAXN], pre[MAXN], suf[MAXN], cnt[MAXN]; struct query { int id, a, b, pre, suf; } q[MAXN]; bool operator<(query x, query y) { return x.a < y.a; } bool compare(query x, query y) { return x.id < y.id; } void upd(in...
#include <bits/stdc++.h> using namespace std; int main() { vector<string> str_list; string str; int max_length = 0, left_more = 0; while (getline(cin, str)) { max_length = max((int)str.size(), max_length); str_list.push_back(str); } cout << string(max_length + 2, * ) << endl; ...
#include <bits/stdc++.h> using namespace std; int32_t main() { ios::sync_with_stdio(false); cin.tie(0); long long int n; cin >> n; map<int, int> mp; for (int i = 0; i < n; i++) { int a; cin >> a; mp[a] = i + 1; } for (int i = 1; i <= n; i++) { cout << mp[i] <<...
#include <bits/stdc++.h> using namespace std; template <class T> bool umin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template <class T> bool umax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } vector<int> b[200009], r[200009]; ve...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); string arr; cin >> arr; long long a = 1; long long counter = 1; for (int i = 0; i < arr.size() - 1; i++) { if ((arr[i] - 0 ) + arr[i + 1] - 0 == 9) a++; else...
#include <bits/stdc++.h> using namespace std; long long dp[1001][1001 + 2][2][2]; int n, k, hv = 1002; char s[1001 + 5], l[1001 + 5], r[1001 + 5]; long long go(int pos, int pv, int ch, int f) { if (pos == -1) return (long long)f; long long &ret = dp[pos][pv][ch][f]; if (ch && ret != -1) return ret...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int n, j; cin >> n; int a[1000020]; for (int i = 0; i < 1000020; i++) { a[i] = 0; } for (int i = 0; i < n; i++) { cin >> j; a[j]++; } j = 0; for (int i = 0; i < 1000020; ...
#include <bits/stdc++.h> using namespace std; bool comp(pair<long long, long long> &p1, pair<long long, long long> &p2) { if (p1.first == p2.first) { return p1.second < p2.second; } else { return p1.first < p2.first; } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL...
#include <bits/stdc++.h> using namespace std; long long n, a[111111], i, k, l, r, s[111111], ans; int main() { cin >> n; if (n % 2 == 0) { cout << -1; return 0; } for (i = 0; i < n; i++) { cout << i << ; } cout << endl; for (i = 0; i < n; i++) cout << i << ; ...
#include <bits/stdc++.h> using namespace std; template <typename T> inline bool ckmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; } template <typename T> inline bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } const int N = 3e5 + 10, P = 998244353; int n, c[N]; int add(int ...
#include <bits/stdc++.h> using namespace std; long long n, a[100001], b[100001]; map<long long, long long> cntup; map<long long, long long> cntdown; long long ans; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; long long x = (n + 1) / 2; for (long long i = 1; i <= n; ++...
#include <bits/stdc++.h> using namespace std; template <class T1> void deb(T1 e) { cout << e << endl; } template <class T1, class T2> void deb(T1 e1, T2 e2) { cout << e1 << << e2 << endl; } template <class T1, class T2, class T3> void deb(T1 e1, T2 e2, T3 e3) { cout << e1 << << e2 ...
#include <bits/stdc++.h> using namespace std; int i, j, k, sm, mx, mn, res, n; int a, b; void read() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; cin >> a >> b; } void solve() { i = a; j = b; while (i) { mx = max(mx, i % 10); i /= 10; } while...
#include <bits/stdc++.h> using namespace std; int main(void) { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n; cin >> n; long long all = 0; long long ans = 0; for (long long i = 0; i < n; i++) { long long x; cin >> x; ans = max(ans, x); all ...
#include <bits/stdc++.h> using namespace std; int b[200005]; int arr[200005]; int cnt[200005]; vector<int> v[200005]; int main() { ios_base::sync_with_stdio(); cin.tie(0); int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) v[i].clear(); memset(cnt, 0, sizeof(cnt)); for (int i ...
#include <bits/stdc++.h> using namespace std; int mp[510][510], uss[510][510] = {0}, n, m, siz[510] = {0}, gnu[510][510], p, f[510] = {0}; int main() { int ans = 0; cin >> n >> m >> p; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { scanf( %1d , &mp[i][j])...
#include <bits/stdc++.h> using namespace std; inline long long mod(long long n, long long m) { long long ret = n % m; if (ret < 0) ret += m; return ret; } long long gcd(long long a, long long b) { return (b == 0LL ? a : gcd(b, a % b)); } long long exp(long long a, long long b, long long m) {...
#include <bits/stdc++.h> using namespace std; long long dx[] = {-1, 0, 1, 0}; long long dy[] = {0, 1, 0, -1}; long long spf[10]; long long dist[1001]; void sieve() { long long i, j; for (i = 0; i < 10; i++) spf[i] = i; for (i = 4; i < 10; i += 2) spf[i] = 2; for (i = 3; i * i < 10; i++) { ...
#include <bits/stdc++.h> using namespace std; int main(int argc, char *argv[]) { double m, R, res[100005], tmp = 0; cin >> m >> R; res[0] = 2; res[1] = 2 + sqrt(2); for (int i = 2; i <= 100000; i++) res[i] = 2 * (i - 1) + 2 * sqrt(2); tmp += m * res[0]; if (m == 1) printf( %.9lf , ...
#include <bits/stdc++.h> using namespace std; int n, T; int t[5005]; double p[5005]; double f[5005][5005]; double res; double fastpow(double a, int b) { if (!b) return 1; double res = fastpow(a, b / 2); if (b % 2) return res * res * a; return res * res; } int main() { ios_base::syn...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1005; int n, a[MAXN]; vector<int> ans; int main() { scanf( %d , &n); ans.reserve(n); for (int i = 1; i <= n; ++i) scanf( %d , &a[i]); a[n + 1] = 1; for (int i = 1; i <= n; ++i) if (a[i + 1] == 1) ans.push_back(a[i]); ...
#include <bits/stdc++.h> using namespace std; long long powm(long long base, long long exp, long long mod = 1000000007) { long long ans = 1; while (exp) { if (exp & 1) ans = (ans * base) % mod; exp >>= 1, base = (base * base) % mod; } return ans; } void fastscan(int &x) { registe...
#include <bits/stdc++.h> using namespace std; using ld = long double; using ll = long long; void solve() { int n; cin >> n; vector<int> v(n); vector<pair<int, int>> a(n); for (int i = 0; i < n; i++) { cin >> v[i]; a[i] = {v[i], i}; } sort(a.begin(), a.end()); vector<i...
#include <bits/stdc++.h> using namespace std; using ll = long long; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fLL; const double EPS = 1e-8; const int MOD = 1000000007; const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1}; const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[...
#include <bits/stdc++.h> using namespace std; const int maxn = 6e4, maxm = 2e6; int g[maxm]; int a[maxn], L[maxn], R[maxn], dp[maxn], ans[maxn]; int n, m, i, j, k; int main() { scanf( %d%d , &n, &m); for (i = 1; i <= 1e6; i++) g[i] = g[i - 1] ^ i; for (i = 1; i <= n; i++) scanf( %d , &a[i]); ...
#include <bits/stdc++.h> using namespace std; const int mxn = 200001, mxk = 8; int n, m, k; pair<int, int> a[mxn]; int first[mxk]; int dp[1 << mxk], p[1 << mxk]; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> m >> k; for (int i = 1; i <= n; i++) { cin >> a[i].first >> ...
#include <bits/stdc++.h> using namespace std; using ll = long long; void solve() { int n, m; cin >> n >> m; vector<string> f(n); for (int i = 0; i < n; ++i) { cin >> f[i]; } vector<int> v(m); for (int j = 1; j < m; ++j) { for (int i = 1; i < n; ++i) { if (f[i - 1][j...
#include <bits/stdc++.h> using namespace std; int a[13], t, ans; const int P = 1e9 + 7; int qp(int a, int b) { int r = 1; for (; b; b >>= 1, a = a * 1ll * a % P) if (b & 1) r = r * 1ll * a % P; return r; } void dfs(int x, int y, bool b) { if (x == t) { if (b) ans = (ans +...
#include <bits/stdc++.h> using namespace std; const int NMAX = 100000 + 5; const int MMAX = 2000 + 5; const int INF = 1000000000; const int BS = 1000000000 + 7; const long long INFLL = 1000000000ll * 1000000000ll; const long double eps = 1e-6; int main(int argc, char** argv) { if (argc > 1 && strcmp...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; long long int n; long long int v[N]; vector<long long int> a, b; long long int solve(const vector<long long int> &vet) { long long int max_so_far = INT_MIN, max_ending_here = 0; for (int i = 0; i < vet.size(); i++) { max_end...
#include <bits/stdc++.h> using namespace std; const long long md = 1e9 + 7; int main() { cout.precision(12); iostream::sync_with_stdio(0); cin.tie(0), cout.tie(0); const int MX = 1e6 + 1; vector<int> pr(MX, 1); vector<int> o; for (int i = 2; i < MX; i++) { if (!pr[i]) continue; ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, a, b; cin >> n >> m >> a >> b; int q = m * a; if (q < b) { cout << n * a; } else { int v = n / m; n -= v * m; cout << v * b + min(b, n * a); } }
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int n = s.length(); int l = n, r = n; bool found = false; for (int i = 0; i < n; i++) { if (found == false && s[i] > a ) { found = true; l = i; } if (found == true && s[i] == a ...
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; if (n & 1) cout << -1 * (n / 2 + 1) << endl; else cout << n / 2 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long int n, m, i, pos = -1, flag; string s1, s2; cin >> n >> m; cin >> s1; cin >> s2; for (i = 0; i < n; i++) { if (s1[i] == * ) { pos = i; break; } } if (pos == -1) { if (s1 == s2) ...
#include <bits/stdc++.h> using namespace std; int n, k; int a[100005]; int maxans, maxnum; int main() { scanf( %d%d , &n, &k); for (int i = 0; i < n; i++) scanf( %d , &a[i]); sort(a, a + n); int l = 0, r = 0; int curk = k, curans = 0, curnum = 0; while (r < n) { while (r < n && c...
#include <bits/stdc++.h> using namespace std; int main() { long long n, m; long long a[100001]; long long b[100001]; cin >> n >> m; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); long long x = 0, i = 1, count = 0; while (m > 0) { if (a[x] != i) { if (m - i >= ...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; long long n, m, l, r, a[N], b[N], dp[N]; void prework() { int k = 1; for (int i = 2; i <= n; ++i) if (a[i + 1] - a[i] > a[k + 1] - a[k]) k = i; r = a[k + 1] - a[k] - 1; for (int i = 1; i <= n; ++i) b[i] = a[i + k]; in...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int l = 8 * n + 1; double m = sqrt(l); int k = sqrt(l); if (m == k) cout << YES << endl; else cout << NO << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; long long by = (n / 2) + (n / 3) + (n / 5) + (n / 7) - (n / 6) - (n / 10) - (n / 14) - (n / 15) - (n / 35) - (n / 21); by += (n / 30) + (n / 42) + (n / 70) + (n / 105); by -= (n / 210); cout ...
#include <bits/stdc++.h> using namespace std; bool mark[100]; int main() { int n, A[100][100]; cin >> n; int k = n; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) cin >> A[i][j]; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) { if (A[i][j] == 1 or A[i][j] ...
#include <bits/stdc++.h> using namespace std; const int MAX = 1e5 + 10; string s[105]; int n, last_hh, last_mm, last_tme, cur_tme, cur_mm, cur_hh, ans = 1, cnt = 0; int calch(int i) { return (s[i][1] - 0 ) * 10 + s[i][2] - 0 ; } int calcm(int i) { return (s[i][4] - 0 ) * 10 + s[i][5] - 0 ; } int main(...
#include <bits/stdc++.h> using namespace std; const int N = 1e6; long long int ans, n, a[N]; string s; int main() { cin >> n >> s; if (n == 1) { cout << Yes ; return 0; } for (int i = 0; i < n; i++) { a[s[i] - a ]++; } for (int i = 0; i < 26; i++) { if (a[i] =...
#include <bits/stdc++.h> using namespace std; string a, str, ans; int n, m; int G[205 * 2][205 * 2]; bool check(int x, int y) { bool f1 = (a[ans[x] - a ] == C ), f2 = (a[ans[y] - a ] == C ); int ta = 2 * x + 2, tb = 2 * y + 2; return !G[ta - f1][tb - (!f2)] && !G[tb - f2][ta - (!f1)]; } bo...
#include <bits/stdc++.h> using namespace std; template <typename _T> inline void _DBG(const char *s, _T x) { cerr << s << = << x << n ; } template <typename _T, typename... args> void _DBG(const char *s, _T x, args... a) { while (*s != , ) cerr << *s++; cerr << = << x << , ; _DBG...
#include <bits/stdc++.h> using namespace std; int TRIE[200005 * 32 * 2][2]; int isword[200005 * 32 * 2]; int nxt; void ins(string &s) { int v = 0; for (int i = 0; i < s.size(); i++) { if (TRIE[v][s[i] - 0 ] == -1) TRIE[v][s[i] - 0 ] = nxt++; isword[v]++; v = TRIE[v][s[i] - 0 ]; ...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) #pragma GCC optimize( Ofast ) using namespace std; int seg[800006][16], x[800006], n, m, t, p, T, ans, pc, L, R, k; vector<int> v; inline int gt(int a, int b) { int k1 = (pow(10, b)); int k2 = (pow(10, b - 1)); if ((k1 % 10) == 9) k1++; if ...
#include <bits/stdc++.h> using namespace std; int main() { long long int a, b, x, i, j, k, n; cin >> a >> b >> x; string s; n = a + b; if (a >= b) { s = 0 ; a -= 1; } else { s = 1 ; b -= 1; } for (i = 1; i < n; i++) { if (s[i - 1] == 0 && x > 1) { ...
#include <bits/stdc++.h> #pragma optimization_level 3 #pragma comment(linker, /stack:200000000 ) #pragma GCC optimize( Ofast ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) using namespace std; long double TL = 1.0; bool is_tl = 0; long long CALLS = 0; inline bool IS()...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int t; cin >> t; while (t--) { long long int n, i, j, k, l, sum = 0, g = 0, sum1 = 0, q, one, zero, k1; cin >> n >> k1; string s; cin >> s; for (i = 0; i < k1; i++) { k ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int x, y, z; long long int x1, y1, z1; cin >> x >> y >> z >> x1 >> y1 >> z1; long long int a[6]; for (long long int i = 0; i < 6; i++) cin >> a[i]; ...
#include <bits/stdc++.h> using namespace std; char str[100010]; int main() { int ans[] = {4, 0, 0, 0}; while (~scanf( %s , str)) { int tmp = 0; int len = strlen(str); for (int i = 0; i < len; ++i) { tmp = tmp * 10 + str[i] - 0 ; tmp %= 4; } printf( %d n , ans...
#include <bits/stdc++.h> using namespace std; int a[100000]; int main() { int n, h; cin >> n >> h; for (int i = 0; i < (int)(n); i++) cin >> a[i]; int head = min_element(a, a + n) - a; sort(a, a + n); int ret1 = max(a[0] + a[n - 1] + h, a[n - 1] + a[n - 2]) - min(a[1] + a[2]...
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const double eps = 1e-9; const long long INF = 100000000000000000; const int MAXN = 3 * 100000; struct T { int left, right, diff; bool operator>(const T& other) { if (diff != other.diff) return diff < other.diff; ...
#include <bits/stdc++.h> using namespace std; void RD(int &x) { scanf( %d , &x); } void RD(long long &x) { scanf( %I64d , &x); } void RD(unsigned int &x) { scanf( %u , &x); } void RD(double &x) { scanf( %lf , &x); } void RD(int &x, int &y) { scanf( %d%d , &x, &y); } void RD(long long &x, long long &y) { s...
#include <bits/stdc++.h> using namespace std; char s[1001]; int main(void) { int k, l, r, i, j; cin >> s >> k; l = strlen(s); r = l / k; if (l % k != 0) { cout << NO << endl; return 0; } for (i = 0; i < l; i += r) for (j = 0; j < r / 2; j++) { if (s[i + j] !...
#include <bits/stdc++.h> using namespace std; long long a[51], us[51]; int main() { long long t, n; cin >> t; while (t--) { cin >> n; for (long long i = 1; i <= n; ++i) cout << i << ; cout << n ; } return 0; }
#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; long long int invmod(long long int x, long long int n, long long int mod) { if (n == 0) return 1 % mod; long long int half = invmod(x, n / 2, mod); half = (half * half) % mod; if (n % 2 == 1) half = (half * (x % mod)) % mod; return half; } long l...
#include <bits/stdc++.h> using namespace std; void debug_out() { cerr << endl; } void clock_out() { cerr << nTime Elapsed : << 1.0 * clock() / CLOCKS_PER_SEC << s n ; } void fileio() { freopen( /home/dwai/Desktop/cp/input.txt , r , stdin); freopen( /home/dwai/Desktop/cp/output.txt , w , st...
#include <bits/stdc++.h> using namespace std; int main() { int n, fp = 0; cin >> n; vector<int> p(n); bool nice = false; bool entrou = false; for (int i = 0; i < n; i++) { cin >> p[i]; if (i == p[i]) fp = fp + 1; } for (int i = 0; i < n; i++) { if (p[i] != i) { ...
#include <bits/stdc++.h> using namespace std; struct disjoint_set { vector<int> p; disjoint_set(int n) : p(n, -1) {} bool share(int a, int b) { return root(a) == root(b); } int sz(int u) { return -p[root(u)]; } int root(int u) { return p[u] < 0 ? u : p[u] = root(p[u]); } bool merge(int u, in...
#include <bits/stdc++.h> using namespace std; const int N = 101000; int n, m, k[N], g[50][50], cnt[50], tmp[50]; vector<pair<int, int> > v[N]; inline int gcd(int first, int second) { return (!second) ? first : gcd(second, first % second); } inline void init() { int i, j; for (i = 1; i <= 40; +...
#include <bits/stdc++.h> using namespace std; void moveLeft() { cout << LEFT << endl; } void moveRight() { cout << RIGHT << endl; } void print(char ch) { cout << PRINT << ch << endl; } int main() { int numberOfCells, currentCell; cin >> numberOfCells >> currentCell; string slogan; cin >...
#include <bits/stdc++.h> using namespace std; const int MaxN = int(2e5); const long double pi = 3.1415926535897932384626433832795; char s[MaxN]; int main() { while (gets(s)) { int len = strlen(s); int l = 0; while (s[l] == 32) ++l; int r = len - 1; while (s[r] == 32) --r; ...
#include <bits/stdc++.h> using namespace std; const long long int mxn = 1e5 + 5; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int t = 1; while (t--) { long long int i, j, k, n, m; cin >> n; map<long long int, long long int> mp, diff; for (i = 0; i...
#include <bits/stdc++.h> using namespace std; const int SIZE = 401; const int MOD = 1000000007; struct matr { long long a[8][8]; }; matr d, f, e; int n; void make() { for (int i = 0; i < 8; i++) for (int j = 0; j < 8; j++) f.a[i][j] = d.a[i][j] = e.a[i][j] = 0; d.a[0][1] = 1; d.a[0...
#include <bits/stdc++.h> using namespace std; vector<pair<int, pair<int, int> > > v; int x; int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } int arr[500001]; int tree[500001 * 5]; void init(int node, int b, int e) { if (b == e) { tree[node] = arr[b]; return; ...
#include <bits/stdc++.h> template <class T> inline void read(T &x) { x = 0; register char c = getchar(); register bool f = 0; while (!isdigit(c)) f ^= c == - , c = getchar(); while (isdigit(c)) x = x * 10 + c - 0 , c = getchar(); if (f) x = -x; } template <class T> inline void print(...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); string s; cin >> s; int br = 0; for (int i = 0; i < s.size() / 2; i++) { if (s[i] == s[s.size() - i - 1]) continue; br++; } if (br >= 2 || br == 0) { if (s.size() % 2 == 1 && br == 0...
#include <bits/stdc++.h> using namespace std; int A[10010]; int B[10010]; bool check(int st, int ed) { int mx = st; for (int i = st; i <= ed; i++) { if (A[i] > A[mx]) { mx = i; } if (A[i] == A[mx]) { if (st <= i - 1 && A[i - 1] < A[i]) mx = i; if (i + 1 <= ed &&...
#include <bits/stdc++.h> using namespace std; string s[505]; int n, par[505][505], a[505 * 505] = {0}, v[505 * 505] = {0}, p[505 * 505]; bool b[505 * 505] = {0}; int dfs(int x, int y, int k) { par[x][y] = k; int ret = 1; if (x > 0 && par[x - 1][y] == -1 && s[x - 1][y] == . ) ret += dfs(x - ...
#include <bits/stdc++.h> using namespace std; long long a[16], d[40000], vis[40000]; int main() { ios::sync_with_stdio(0); int n, x, i, j, k, l0, m, m0, m1, c; long long l, r, v, ans = 0; cin >> n >> l >> r >> x; for (i = 1; i <= n; i++) cin >> a[i]; sort(a + 1, a + n + 1); for (i = 1,...
#include <bits/stdc++.h> using namespace std; template <typename T> inline int read(T &a) { a = 0; char c = getchar(), f = 1; while (c > 9 || c < 0 ) { if (c == - ) f = (~f) + 1; if (c == -1) return -1; c = getchar(); } while (c <= 9 && c >= 0 ) a = (a << 1) + (a...
#include <bits/stdc++.h> using namespace std; int main() { string s; int i, j, n, k, imp, c, h; int f[200]; { imp = 0; memset(f, 0, sizeof(f)); cin >> k; cin >> s; n = ((int)s.size()); h = n % 2 + n / 2; for (i = 0; i < n; i++) if (isalpha(s[i])) f[s...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int N = 1e6 + 5; int n, cnt[3], dp[N], sum = 1; int add(int x, int y) { return (1ll * x + 1ll * y) % mod; } int mul(int x, int y) { return (1ll * x * 1ll * y) % mod; } int del(int x, int y) { return ((1ll * x - 1ll * y) % mod + m...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 7; pair<long long, long long> a[N]; long long top, k, n, avr, mx; int main() { scanf( %d %d %d , &n, &mx, &avr); for (int i = 1; i <= n; i++) { int b, r; scanf( %d %d , &b, &r); a[i] = make_pair(r, b); top += b; ...
#include <bits/stdc++.h> using namespace std; char ch[55][55]; int main() { int n, m; cin >> n >> m; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) cin >> ch[i][j]; int ret = 0; for (int i = 0; i < n - 1; i++) for (int j = 0; j < m - 1; j++) { bool f = 0, a = 0, c ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { string s; cin >> s; if (s.size() == 1) { if (s[0] == ? ) printf( a n ); else cout << s << n ; } else { int f = 0; for (int i = 0; i < s...
#include <bits/stdc++.h> using namespace std; unsigned long long tcc, n, m; int main() { scanf( %lld , &tcc); while (tcc--) { scanf( %lld %lld , &n, &m); unsigned long long sum = 0, m2 = m, t = 10; while (t-- && m2 <= n) { sum += m2 % 10; m2 += m; } m2 = m * 1...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const long long SIZE = 100000; const int INF = 0x3f3f3f3f; const long long ll_INF = 0x3f3f3f3f3f3f3f3f; const long double PI = acos(-1); const long long MAXN = numeric_limits<long long>::max(); const long long MAX = 2000000; ...
#include <bits/stdc++.h> using namespace std; long long x[100002]; vector<int> P[2 * 100002]; void NoSol() { printf( No n ); exit(0); } long long sqr(int x) { return 1LL * x * x; } int bs(int x, long long val) { int i = -1, sz = P[x].size(), p = 1; while (p < sz) p <<= 1; while (p) { ...
#include <bits/stdc++.h> using namespace std; int main() { long long n, k, m, a[100100], sum = 0; priority_queue<pair<long long, long long>, vector<pair<long long, long long> >, greater<pair<long long, long long> > > pq; cin >> n >> k; for (int i = 1; i ...
#include <bits/stdc++.h> using namespace std; int n, p, q; unsigned int C[132]; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int a[132]; void Init() { C[0] = 1; for (int i = 1; i <= min(p, n - 1); ++i) { a[0] = 0; for (int j = 0; j < i; ++j) a[++a[0]] = n - j; for (int k...
#include <bits/stdc++.h> using namespace std; template <typename T> T sgn(T x) { return x < 0 ? -1 : x != 0; } template <typename T> T gcd(T a, T b) { return a ? gcd(b % a, a) : b; } void reads(string& x) { char kk[((long long)5e2 + 123)]; scanf( %s , kk); x = kk; } long long n, ...
#include <bits/stdc++.h> using namespace std; vector<int> v[100005]; bool d[100005]; int s[100005]; void del(int i, int par) { if (v[i].size() <= 2) { d[i] = true; for (int j : v[i]) if (j != par) del(j, i); } } int main() { int n; cin >> n; int a, b; for (int i...
#include <bits/stdc++.h> using namespace std; const long long int INF = 1e18; const int inf = 1e9; const int MOD = 1e9 + 7; const int nax = 1000000 + 10; int main() { ios::sync_with_stdio(0); double a, b, m, t, dx, dz, mz, mx, vx, vy, vz, ansx, ansz; int pz, px; cin >> a >> b >> m; cin >...
#include <bits/stdc++.h> using namespace std; long long mod = 1000000007LL; long long large = 2000000000000000000LL; vector<int> p; int f(int x) { return p[x] == x ? x : p[x] = f(p[x]); } vector<vector<pair<int, int> > > adj; int main() { int n, m, a, b; cin >> n >> m >> a >> b; p.assign(n, 0)...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false), cin.tie(0); int n; string s; cin >> n >> s; if (count(s.begin(), s.end(), s[0]) == s.size() || s.size() == 1) { cout << NO << endl; } else { cout << YES << endl; for (int i = 0; i < ...
#include <bits/stdc++.h> using namespace std; int need, e; int mat[128][128]; bool found; int add; int v; int main() { memset(mat, 0, sizeof mat); cin >> need; e = 0; while (e < need) { found = false; for (int i = 1; i <= v && found == false; i++) for (int j = i + 1; j ...
#include <bits/stdc++.h> using namespace std; template <typename T> inline void read(T &x) { x = 0; int fu = 1; char c = getchar(); while (c > 57 || c < 48) { if (c == 45) fu = -1; c = getchar(); } while (c <= 57 && c >= 48) { x = (x << 3) + (x << 1) + c - 48; c = g...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; long long n; cin >> n; string s = ROYGBIV ; long long x = n - 7; string st = GBIV ; long long i = 0; while (i < x) { s += st[(i % 4)]; ...
#include <bits/stdc++.h> using namespace std; int n, m, k, s, a[500009], b[500009]; int chk[500009]; bool ok(int p) { vector<int> c(500009); for (int i = 0; i <= p; i++) c[a[i]]++; for (int i = 0; i < 500009; i++) if (c[i] < chk[i]) return false; return true; } int main() { ios_bas...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1005; char s[MAXN][MAXN]; int n, m, pre[MAXN], nex[MAXN]; bool check[MAXN]; int main() { scanf( %d%d n , &n, &m); for (int i = 1; i <= n; ++i) gets(s[i] + 1); for (int j = 0; j <= m + 1; ++j) pre[j] = j - 1, nex[j] = j + 1; int r...
#include <bits/stdc++.h> using namespace std; const int SIZE = 1000009; char s[SIZE]; long long int dsum[SIZE]; int dtotal; long long int usum[SIZE]; int utotal; int main() { int N; scanf( %d%s , &N, s + 1); for (int i = 1; i <= N; i++) { if (s[i] == U ) { ++utotal; us...
#include <bits/stdc++.h> using namespace std; int n, hitung, arr[212]; void swap(int x, int y) { for (int i = y; i > x; i--) { int tmp = arr[i - 1]; arr[i - 1] = arr[i]; arr[i] = tmp; hitung += 1; } } int main() { cin >> n; for (int i = 1; i <= 2 * n; i++) { cin >...
#include <bits/stdc++.h> using namespace std; int n, m; int A[110][110]; char buf[3]; bool mark[110][110][30][2]; bool memo[110][110][30][2]; bool win(int u, int v, int prev, int turn) { bool& ans = memo[u][v][prev][turn]; if (mark[u][v][prev][turn]) return ans; mark[u][v][prev][turn] = true; ...