func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> int main() { int n, i, j, r; char lvl[110]; scanf( %d , &n); scanf( %s , lvl); for (r = 1; r < n; r++) { for (i = 0; i < n; i++) { for (j = 0; j <= 4; j++) { if (i + j * r >= n || lvl[i + j * r] != * ) break; } if (j >= 5) { ...
#include <bits/stdc++.h> using namespace std; int main() { int x, y; cin >> x >> y; int m = 0; while (x * 100 + y * 10 >= 220) { int kx, ky; if (m % 2 == 0) { kx = min(2, x); x -= kx; ky = (220 - 100 * kx) / 10; y -= ky; if (y < 0) break; } e...
#include <bits/stdc++.h> using namespace std; const int maxn = 2000 + 10; const int maxm = 4e5 + 10; const long long mod = 1e9 + 7; const int inf = 0x3f3f3f3f; const double eps = 1e-5; const double pi = acos(-1.0); int t; int n, a[maxn]; int cnt[maxn]; int main() { ios::sync_with_stdio(false);...
#include <bits/stdc++.h> using namespace std; const int N = 1 << 17; int st[N], op[N], sz[N], dp[N], pid[N], c[N], hd[N], p[N], f[N], g[N], add[N]; double ans[N]; vector<int> adj[N], V[N]; long long sum[N]; int T, pn; void dfs(int u) { sz[u] = 1; dp[u] = dp[p[u]] + 1; for (auto v : adj[u]) {...
#include <bits/stdc++.h> using namespace std; int main() { std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int n, even = 0, odd = 0; cin >> n; long long int a[n]; for (long long int i = 0; i < n; i++) cin >> a[i]; if (n == 1) cout << a[0] << n ; ...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) using namespace std; void _print(long long int t) { cerr << t; } void _print(int t) { cerr << t; } void _print(string t) { cerr << t; } void _print(char t) { cerr << t; } void _print(long double t) { cerr << t; } void _print(double t) { cerr << t; }...
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); template <class T> T SQR(const T &a) { return a * a; } void run() { int A[4][4]; int n; cin >> n; int B[16]; for (int i = (0), ei = (n * n); i < ei; i++) scanf( %d , B + i); int nsq = n * n; sort(B, B...
#include <bits/stdc++.h> using namespace std; const int maxn = 5e5 + 10; long long n; vector<long long> v; void init() { for (int i = 0; i <= 38; i++) v.push_back(pow(3, i)); } int main() { init(); int t; cin >> t; while (t--) { cin >> n; long long res = 0, cur = 0; w...
#include <bits/stdc++.h> using namespace std; template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } const int maxn = 1000100; char s[maxn]; vector<int> a[maxn]; void solve() { cin >> s; int n = strlen(s); int c = 0; for (int i = 0; i < n; i++) { c += s[i] == 0 ...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; scanf( %d %d %d , &a, &b, &c); double rez = 1.0 * a * a * a * 1.41421356237309 / 12.0; rez += 1.0 * b * b * b * 1.41421356237309 / 6.0; rez += 1.0 * c * c * c * 7.23606797749978 / 24.0; printf( %.10lf n , rez); retur...
#include <bits/stdc++.h> using namespace std; int main() { int f[300][300]; f[2][1] = 2; f[2][2] = 1; f[4][1] = 32; f[4][2] = 30; f[4][3] = 80; f[4][4] = 109; f[8][1] = 6824; f[8][2] = 59808; f[8][3] = 147224; f[8][4] = 415870; f[8][5] = 1757896; f[8][6] = 1897056...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 11; const long long mod = 1e9 + 7; const int inf = 1e9; const int bl = 320; deque<int> arr[bl]; int cnt[bl][N]; void shift(int l, int r) { vector<int> a; int b = l / bl; while (!arr[b].empty()) { a.push_back(arr[b].front...
#include <bits/stdc++.h> using namespace std; const int MX = 5005; int n, m; int n1, n2, n3; vector<int> g[5005]; int pars[5005]; map<int, vector<int>> roots; vector<int> roots_v; vector<int> cs; int rootNum = 0; bool dp[5005][5005][2]; int find(int u) { if (pars[u] == u) return u; int p...
#include <bits/stdc++.h> using namespace std; long long begtime = clock(); template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cout << name << : << arg1 << n ; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* c...
#include <bits/stdc++.h> using namespace std; const int N = 203; const int mod = 1e9 + 7; vector<int> g[N]; int dp[N]; int ans, n; int len1, len2; void cal(int u, int fa, int &len) { dp[u] = 0; int &mx1 = dp[u], mx2 = 0; int v; for (__typeof((g[u]).begin()) v = (g[u]).begin(); v != (g[u]...
#include <bits/stdc++.h> using namespace std; int n, k; long long a[200010]; long long b[200010]; int s[200010]; long long ans; bool check(long long val) { memset(s, 0, sizeof(s)); int num = k; for (int i = 1; i <= n; i++) { if (!b[i]) { continue; } long long sum = a[...
#include <bits/stdc++.h> using namespace std; void require(bool cond, const string& message = Runtime error ) { if (!cond) { cerr << message << endl; assert(false); } } void readData() {} long long mina, maxa; void solve(long long x, long long n) { long long m = n / x; for (long...
#include <bits/stdc++.h> using namespace std; long long arr[1005]; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long t; cin >> t; while (t--) { long long n; cin >> n; for (long long i = 0; i < n; i++) { cin >> arr[i]; ...
#include <bits/stdc++.h> using namespace std; int n, k, a[105][105], m; vector<pair<int, int> > ans; void Solve2() { int cur = 0, cnt = 0; for (int i = n - 1; i <= n; ++i) { for (int j = m - 1; j <= m; ++j) { if (a[i][j] == 1 && cnt == 0) { ans.push_back({i, j}); ++cnt;...
#include <bits/stdc++.h> using namespace std; const int MXN = 100100; const int QQ = 500; const int INF = (int)1e9; const long long LINF = (long long)1e18; const int mod = 1000000007; set<pair<int, int> > eds; int x[MXN]; int main() { int n, m; scanf( %d%d , &n, &m); int a, b; for (int...
#include <bits/stdc++.h> using namespace std; long double a[1001][1001]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n, t, m, w, b; cout.precision(12); cin >> w >> b; for (int i = 0; i <= w; i++) { for (int j = 0; j <= b; j++) { if (!i && !j) conti...
#include <bits/stdc++.h> using namespace std; bool comp(long long a, long long b) { if (a > b) return true; else return false; } int isP(long long n) { if (n == 1) return 0; if (n == 2 || n == 3) return 1; for (long long i = 2; i <= sqrt(n); i++) { if (n % i == 0) return 0;...
#include <bits/stdc++.h> using namespace std; int how_many(string s, vector<string>& deleted) { int res = 0; for (auto i : deleted) for (int j = 0; j < s.size(); j++) { if (i[j] != s[j]) break; if (j == s.size() - 1) res++; } return res; } int main() { ios_base::sync_...
#include <bits/stdc++.h> using namespace std; long long ans = 0; int n, m, w[2010]; int main() { scanf( %d%d , &n, &m); for (int i = 1; i <= n; i++) { scanf( %d , &w[i]); } for (int i = 1, a, b; i <= m; i++) { scanf( %d%d , &a, &b); ans += min(w[a], w[b]); } printf( %d ...
#include <bits/stdc++.h> using namespace std; map<string, int> g; bool can; int n, i; char s[100][5]; void find(int x) { char temp[10]; string ss; int j; if (x == 1) { can = true; return; } if ((s[x][0] == s[x - 1][0]) || (s[x][1] == s[x - 1][1])) { strcpy(temp, s[x...
#include <bits/stdc++.h> using namespace std; int main() { long long m, n, p[30], ans; cin >> m >> n; for (__typeof(0) i = 0; i <= n - 1; i++) { cout << 1 n ; fflush(stdout); cin >> ans; if (ans == 0) return 0; if (ans == -1) p[i] = 0; else p[i] = 1; ...
#include <bits/stdc++.h> inline int Abs(int x) { return x < 0 ? -x : x; } inline int Sgn(int x) { return x < 0 ? -1 : 1; } const int MN = 100005, Sig = 26; const int ML = 100005; const int MQ = 100005; const int T = 400; const int B = 400; int N, Id[MN], Len[MN]; char str[ML]; int nxt[ML][Sig], faz[...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2 * 100 * 1000 + 100; int n, dp[MAXN], d[MAXN], mark[MAXN], ans[MAXN], D = 0, MIN = MAXN; pair<int, int> par[MAXN]; vector<pair<int, int> > g[MAXN]; vector<int> q, depth[MAXN], res; void bfs() { for (int i = 0; i < q.size(); i++) { i...
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, /STACK:102400000,102400000 ) const int INF = 0x3f3f3f3f3f, mod = 1e9 + 7; const double eps = 1e-6, PI = acos(-1); template <typename T> inline void read(T &x) { x = 0; T f = 1; char ch; do { ch = getchar(); if...
#include <bits/stdc++.h> using namespace std; int INF = 100000000; int n, m, x, y; char ch; long long int pre[2][(int)1e3 + 5], dp[2][(int)1e3 + 5]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m >> x >> y; memset(pre, 0, sizeof(pre)); memset(dp, 0, sizeof(dp...
#include <bits/stdc++.h> using namespace std; const int MAXN = 100007, INF = 1000000007; int main() { int n, m, k, cnt = 0; long long d[MAXN], d1[MAXN]; vector<pair<int, int> > G[MAXN]; pair<long long, int> used[MAXN]; set<pair<long long, int> > S; scanf( %d%d%d , &n, &m, &k); for (int...
#include <bits/stdc++.h> using namespace std; long long powerFunction(long long x, long long y) { long long res = 1; long long p = 1000000007; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } bool prime[10000001]; ...
#include <bits/stdc++.h> using namespace std; vector<vector<int>> edge; int n, m; int parent[100000]; int size[100000]; int visited[100000]; int finished[100000]; int has_loop[100000]; int find_root(int v) { if (parent[v] == -1) { return v; } return parent[v] = find_root(parent[v]); ...
#include <bits/stdc++.h> using namespace std; int T, a[4], ans; inline bool cmp(int x, int y) { return x > y; } int main() { scanf( %d , &T); while (T--) { ans = 0; scanf( %d%d%d , &a[1], &a[2], &a[3]); sort(a + 1, a + 3 + 1, cmp); for (int i = 1; i <= 3; ++i) { if (a[i])...
#include <bits/stdc++.h> using namespace std; int dp[1001001][2]; vector<int> G[1001001]; int ans[1001001] = {}; int ma[1001001] = {}; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; string s; cin >> s; for (int i = 0; i < (n); ++i) for (int j = ...
#include <bits/stdc++.h> using namespace std; template <class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; } template <class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; } long long f[2001], dp[2001][2001], m = 998244353; long long fun(long long i, long long...
#include <bits/stdc++.h> using namespace std; template <typename T, typename T1> T amax(T& a, T1 b) { if (b > a) a = b; return a; } template <typename T, typename T1> T amin(T& a, T1 b) { if (b < a) a = b; return a; } const long long N = 200005, INF = 2000000000000000000; const long lo...
#include <bits/stdc++.h> using namespace std; map<pair<long long, long long>, long long> ma; void put(long long u, long long v, long long w) { while (v != u) { long long par; if (v > u) { par = v / 2; ma[make_pair(par, v)] += w; ma[make_pair(v, par)] += w; v /= 2; ...
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<ll, ll>; using PP = pair<ll, P>; const ll n_ = 2222 + 100, inf = 1e18 + 1, mod = 1e9 + 7, sqrtN = 333; ll dy[4] = {-1, 0, 1, 0}, dx[4] = {0, 1, 0, -1}; ll n, m, k, tc = 1, a, b, c, sum, x, y, z, w, base, ans; ll gcd(ll x,...
#include <bits/stdc++.h> using namespace std; int main() { string str, s = QWERTYUIOPASDFGHJKLZXCVBNM ; cin >> str; set<char> m; long long result = 1; for (int i = 0; i < str.size(); i++) { if (str[i] == ? ) { if (i == 0) { result *= 9; } else result *...
#include <bits/stdc++.h> using namespace std; const int N = 100010; int T, n, cnt, now[N], ans[N]; char ch[N]; vector<int> A, B, C; map<pair<int, int>, bool> col; inline void ask() { int i, j; if (!A.size()) return; printf( Q %d , (int)A.size()); for (i = 0; i < A.size(); i++) printf( %d ...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) #pragma GCC optimize( unroll-loops ) #pragma GCC optimize( no-stack-protector ) #pragma GCC target( sse,sse2,ssse3,sse3,sse4,popcnt,avx,mmx,abm,tune=native ) using namespace std; signed main() { cin.tie(nullptr)->sync_with_stdio(false); long long n...
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; vector<long long> a(2 * n); for (long long i = 0; i < 2 * n; ++i) { cin >> a[i]; } sort(a.begin(), a.end()); if (n == 1) { cout << 0; return 0; } long long mn = 2e9; for (long ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 5; const int MOD = 998244353; long long fac[MAXN]; struct Edge { int to, next; } edge[MAXN * 2]; int head[MAXN], tot; void AddEdge(int s, int t) { edge[tot].to = t; edge[tot].next = head[s]; head[s] = tot++; edge[to...
#include <bits/stdc++.h> using namespace std; int block; unordered_map<int, int> x; vector<long long> a; struct query { int l, r, pos; bool operator<(const query &other) const { if (l / block == other.l / block) return r < other.r; return l / block < other.l / block; } }; int l = 0...
#include <bits/stdc++.h> using namespace std; int n; int a[110]; long long g[110], f[110][110][110]; char s[110]; int main() { int L, R; scanf( %d , &n); gets(s); if (s[0] != 0 ) gets(s); for (int i = 1; i <= n; i++) { scanf( %d , &g[i]); for (int j = 1; j < i; j++) g[i] = m...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int arr[n]; map<int, int> m; for (int i = 0; i < n; i++) { cin >> arr[i]; if (arr[i] != 0) { m[arr[i]]++; } } cout << m.size() << endl; return 0; }
#include <bits/stdc++.h> #pragma comment(linker, /STACK:536870912 ) #pragma warning(disable : 4996) using namespace std; const int N = 2e5 + 100, X[2] = {997, 449}; char s[N], t[N]; long long int h[2][N], p[2][N]; int w[N], g[N], lb[N], rb[N]; int n; pair<long long int, long long int> getH(int l, int...
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int N = 20 + 5; int go[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}; int n, m, k; char s[N][N]; struct Node { int x, y, v; } t[N]; int tot; int sx, sy; struct State { int x, y, S; }; int vis[N][N][1 << 10]; ...
#include <bits/stdc++.h> using namespace std; const int maxn = (1 << 23); bool vis[maxn], num[maxn]; int n, m; void dfs(int x) { if (vis[x]) return; vis[x] = 1; for (int i = 0; i < n; i++) { if (x & (1 << i)) dfs(x ^ (1 << i)); } if (num[x]) dfs((1 << n) - 1 - x); } int main() { ...
#include <bits/stdc++.h> using namespace std; long long c1, c2; int n, k; long long p(long long m) { long long mini = LLONG_MAX; for (int i = 1; i <= n; ++i) if ((n + i) / (i + 1) <= m and m <= n / i) mini = min(mini, 1LL * i * i * (m * (i + 1) - n) + 1LL * (i ...
#include <bits/stdc++.h> using namespace std; static const double EPS = 1e-5; int main() { int n, k; cin >> n >> k; vector<int> cur(n); vector<int> p(n); vector<int> goal(n); for (int i = 0; i < n; i++) { cin >> p[i]; } for (int i = 0; i < n; i++) cin >> goal[i]; bool ok ...
#include <bits/stdc++.h> using namespace std; template <class A, class B> ostream& operator<<(ostream& out, const pair<A, B>& a) { return out << ( << a.first << , << a.second << ) ; } template <class A> ostream& operator<<(ostream& out, const vector<A>& v) { out << [ ; for (int i = 0; i <...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:256000000 ) using namespace std; int main() { int n; scanf( %d , &n); if (n % 2 == 0) { printf( -1 n ); return 0; } for (int i = 0; i < n; ++i) { printf( %d , i); } printf( n ); for (int i = 0; i < n; ++i)...
#include <bits/stdc++.h> using namespace std; int main() { string a; int n, m; cin >> a >> n; m = a.size(); string ans = ; while (n--) { string b; cin >> b; if (b.substr(0, 0 + m) == a) { if (ans == ) ans = b; else if (b < ans) ans = ...
#include <bits/stdc++.h> using namespace std; int n, m, x, q[100100]; char t; vector<int> d; bool used[100100]; void calc(int x) { d.resize(0); for (int i = 2; i * i <= x; i++) if (x % i == 0) { while (x % i == 0) x /= i; d.push_back(i); } if (x != 1) d.push_back(x); ...
#include <bits/stdc++.h> using namespace std; int n, m, notFind; vector<pair<int, int>> edge[100001]; vector<int> ans[2], e[2]; int vis[100001]; void DFS(int u, int c, int vit) { vis[u] = c; e[c].push_back(u); for (auto k : edge[u]) { int v, col, nextCol; tie(v, col) = k; col =...
#include <bits/stdc++.h> using namespace std; vector<long long> v[100]; int n; long long tmp; int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) { int cnt = 0; scanf( %I64d , &tmp); while (tmp % 2 == 0) { tmp >>= 1; cnt++; } v[cnt].push_back(tmp); ...
#include <bits/stdc++.h> using namespace std; int N; int X[6060], Y[6060]; long long C[4][4]; int main() { ios::sync_with_stdio(0); cin.tie(0); cin.exceptions(ios::badbit | ios::failbit); cin >> N; for (int i = 1; i <= N; i++) cin >> X[i] >> Y[i]; long long res = 0; for (int i = 1;...
#include <bits/stdc++.h> using namespace std; const int maxn = 100000 * 2 + 5; const int maxd = 25; long long d[maxn], h[maxn], s[maxn], f[maxn], g[maxn]; int f_fst[maxd][maxn], f_snd[maxd][maxn], g_fst[maxd][maxn], g_snd[maxd][maxn]; void GetMax(long long a[], int &r0, int &r1, int x0, int x1, int y0, int ...
#include <bits/stdc++.h> using namespace std; int main() { cout << INTERCAL << n ; return 0; }
#include <bits/stdc++.h> using namespace std; int res = INT_MAX; int i, j; int n, d; int a[2018]; int main() { cin >> n >> d; for (int x = 0; x < n; x++) cin >> a[x]; sort(a, a + n); for (i = 0; i < n; i++) for (j = n - 1; j >= i; j--) { if (a[j] - a[i] <= d) { res = ...
#include <bits/stdc++.h> using namespace std; long long int mod = 1e9 + 7; long long int exp(long long int t, long long int x) { if (x == 0) return 1; if (x == 1) return t; if (x % 2 == 1) return (t * exp((t * t) % mod, x / 2)) % mod; if (x % 2 == 0) return exp((t * t) % mod, x / 2); } long lo...
#include <bits/stdc++.h> using namespace std; const long long N = 150009; long long a[N]; long long b[N], n, m, h; struct Tree { long long l, r; long long ly, mi; } t[N << 2]; void build_tree(long long p, long long l, long long r) { t[p].l = l, t[p].r = r; if (l == r) { t[p].mi = l -...
#include <bits/stdc++.h> using namespace std; int n; map<int, pair<int, int> > m; int main() { scanf( %i , &n); for (int i = 0; i < n; i++) { int a, b; scanf( %i%i , &a, &b); if (m.find(a) == m.end()) m[a] = make_pair(1, 0); else m[a].first += 1; if (b != a)...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int arr[30] = {}, n, i = 0; cin >> n; while (n > 0) arr[i] = n % 2, n /= 2, i++; for (i = 29; i >= 0; i--) if (arr[i]) cout << i + 1 << ; cout << n ; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int s = 0; int d = 0; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } int i = 0; int count = 1; int beg = 0; int last = n - 1; while (count <= n) { if (i == 0) { ...
#include <bits/stdc++.h> using namespace std; int main() { int i, count = 1, ans = 0; string input; cin >> input; for (i = 1; i < input.length(); i++) { if (input[i] != input[i - 1]) { ans += (count / 5) + (count % 5 > 0); count = 0; } count++; } ans += (cou...
#include <bits/stdc++.h> using namespace std; const int maxn = 300005; int needread[maxn]; int readed[maxn]; int cnt[maxn]; int main() { int n, q, type, num, pop_cnt = 0; queue<int> que; scanf( %d %d , &n, &q); int ans = 0; while (q--) { scanf( %d %d , &type, &num); if (type ...
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > vec[105]; int main() { int n, k; scanf( %d%d , &n, &k); for (int i = 1; i <= n; i++) vec[i].push_back(make_pair(i, i)); int ct = 101; int a, b; for (int i = 1; i <= k; i++) { scanf( %d%d , &a, &b); vec[a].pus...
#include <bits/stdc++.h> using namespace std; bool sortin(const pair<long long int, long long int> &e, const pair<long long int, long long int> &f) { return (e.first < f.first); } long long int i, j, k, l, m, n, c, p, q, ts, mn = 10e17, mod = 10e8 + 7; long long int a[250002], b[250002], x[2...
#include <bits/stdc++.h> using namespace std; const int N = 1111; int n; struct Edge { int u, v; long long weight; int adj(int x) { return x == u ? v : u; } }; struct Path { int u, v; long long weight; }; vector<Edge> E; vector<int> G[N]; vector<Path> res; int Trace[N]; int F...
#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; int arr[n]; int sum = 0; int ans = 0; for (int i = 0; i < n; i++) { cin >> arr[i]; sum += arr[i]; } sum = sum / 2...
#include <bits/stdc++.h> const int maxn = 2e5 + 5; const int mo = 998244353; using namespace std; int rd() { int x = 0, f = 1; char c = getchar(); while (!isdigit(c)) { if (c == - ) f = -1; c = getchar(); } while (isdigit(c)) x = (x << 3) + (x << 1) + c - 0 , c = getchar(); ...
#include <bits/stdc++.h> using namespace std; int n, m, k; pair<string, int> A[11]; int main() { scanf( %i , &n); for (int i = 0; i < 7; i++) A[i].second = 2e7; for (int i = 0; i < n; i++) { string s; int p; cin >> p >> s; sort(s.begin(), s.end()); if (s == ABC ) ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int n; cin >> n; vector<int> x(n); vector<int> p(n); for (int i = (0); i < ((n)); ++i) { cin >> x[i]; --x[i]; p[x[i]] = i; } int const MAX_SUM = 100001; vector<int> prim...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:66777216 ) using namespace std; int a, b, c, d, i, j, n, m, k; inline void die(long double first) { printf( %.15lf n , (double)first); exit(0); } long double check(long double y1, long double y2, long double yw, long double...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; const double pi = acos(-1.0); int dblcmp(double d) { if (fabs(d) < eps) return 0; return d > eps ? 1 : -1; } long long n, t; int a[66], l, p; long long dp[66][2][66]; long long getdp(int len, int less, int tot) { if (le...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; const int mod = 1e9 + 7; int n, a[N]; long long ans; map<long long, int> cnt; void go(long long pos) { cnt[pos]++; if (cnt[pos] == 2) { cnt[pos] = 0; go(pos + 1); } } int main() { ios_base::sync_with_stdio...
#include <bits/stdc++.h> using namespace std; const int MOD = 10; const double eps = 1e-5; const int maxN = 1100; const int inf = 1e9 + 100; int n, m, k; bool vis[maxN][maxN]; inline void init() { int a, b; cin >> n >> m >> k; for (int i = 0; i < k; i++) { cin >> a >> b; a--; ...
#include <stdio.h> #include<iomanip> #include<iostream> #include<iostream> #include <algorithm> #include<string.h> #include<string> #include<cmath> #include<queue> #include<map> #include<set> #include<bits/stdc++.h> using namespace std; #pragma warning(disable:4996) #define inf 0x3f3f3f3f ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1000000 + 5; char s[maxn]; int vis[maxn], a[maxn]; int main() { int n; scanf( %d , &n); scanf( %s , s + 1); for (int i = 1; i <= n; i++) scanf( %d , &a[i]); memset(vis, 0, sizeof(vis)); int x = 1; while (1) { if (...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:16777216 ) const long long inf = 2147383647; const double pi = 2 * acos(0.0); const double eps = 1e-9; const long long maxint = 2147483647; const long long minint = -2147483648; using namespace std; struct Bigint { string a; int sign; ...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int INF = INT_MAX; const int NINF = INT_MIN; int n, q, l, r, curr; vector<int> vec, tv, Count; void Solve() { cin >> n >> q; vec = tv = vector<int>(n, 0); for (int i = 0; i <= n - 1; i++) cin >> vec[i]; for (int i...
#include <bits/stdc++.h> using namespace std; int getInt() { int x; scanf( %d , &x); return x; } long long getLongLong() { long long x; scanf( %I64d , &x); return x; } double getDouble() { double x; scanf( %lf , &x); return x; } char getChar() { char x; scanf(...
#include <bits/stdc++.h> using namespace std; struct Point { int x, y; bool operator<(const Point &a) const { return y == a.y ? x < a.x : y > a.y; } }; Point p[200005]; int x[200005], y[2000005]; struct Segtree { struct node { int l, r; int v; } tr[200005 * 4]; void build(int...
#include <bits/stdc++.h> using namespace std; int main() { double ans, p, q, p1, p2, p3; int n, i; scanf( %d , &n); ans = 0.0; q = p2 = p3 = 1; p1 = 0; for (i = 1; i <= n + 1; i++) { if (i <= n) scanf( %lf , &p); else p = 0.0; ans += (1 - p) * p1; ...
#include <bits/stdc++.h> using namespace std; long long n, i, j; vector<long long> v, Ans; long long adj[504][504], dist[504][504]; bool visit[1000000]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; for (i = 1; i <= n; i++) { for (j = 1; j <= n; j++) { ...
#include <bits/stdc++.h> using namespace std; int main() { int n, count = 0; cin >> n; int home[n], guest[n]; for (int i = 0; i < n; ++i) { cin >> home[i] >> guest[i]; } for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { if (home[i] == guest[j]) count++; } ...
#include <bits/stdc++.h> using namespace std; long long binpow(long long a, long long b, long long m) { a %= m; long long res = 1; while (b > 0) { if (b & 1) res = (res * a) % m; a = (a * a) % m; b >>= 1; } return res; } void solve() { long long int x, n, y, z, ans = 1;...
#include <bits/stdc++.h> using namespace std; int arr[200005]; int ans[200005]; int n, m; bool vis[200005]; int s = 0, e = -1; int main() { scanf( %d %d , &n, &m); vector<pair<int, int> > q(m); for (int i = 0; i < n; ++i) scanf( %d , arr + i); for (int i = 0; i < m; ++i) scanf( %d %d , &q[...
#include <bits/stdc++.h> using namespace std; int n; bool isValid(int x1, int y1, int x2, int y2) { return x1 <= x2 && y1 <= y2; } int ask(int x1, int y1, int x2, int y2) { int ret = 0; cout << ? << x1 << << y1 << << x2 << << y2 << n ; cout.flush(); cin >> ret; return ret; ...
#include <bits/stdc++.h> using namespace std; long long a[505]; long long mod = 998244353; long long dp[505][505]; long long get_ans(long long l, long long r) { if (dp[l][r]) return dp[l][r]; if (l >= r) return 1; long long pl = l, _min = 1e9; for (long long i = l; i <= r; i++) { if (a[i...
#include <bits/stdc++.h> using namespace std; int N, s1, s2; int data[100001]; bool isRange(int x, int y, int z) { if (z >= x && z <= y) return true; return false; } int check(int x) { int L = data[N] - x; int R = data[N] + x; for (int i = N - 1; i >= 1; i--) { if (isRange(L, R, da...
#include <bits/stdc++.h> long long pow(long long a, long long n, long long mod) { long long t; for (t = 1; n; n >>= 1, a *= a, a %= mod) n & 1 && (t *= a, t %= mod); return t; } int main() { long long N, A, B, K, i, l, t, ans, mod = 1000000009; char s[100100]; for (scanf( %lld%lld%lld%lld%...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int m, n; cin >> m >> n; char a[m], b[n]; for (int i = 0; i < m; i++) cin >> a[i]; for (int i = 0; i < n; i++) cin >> b[i]; if ((a[0] == < && b[0] == ^ ) || (a...
#include <bits/stdc++.h> using namespace std; int cnt1 = 0; const int maxn = 1e5; int fac[maxn + 5], vis[maxn + 5]; vector<int> prime; void init() { memset(vis, 0, sizeof(vis)); for (int i = 2; i <= maxn; i++) { if (!vis[i]) prime.push_back(i); for (int j = 0; j < prime.size() && i * pri...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; void io() {} long long fast_exp(long long base, int exp, int m) { long long res = 1; while (exp > 0) { if (exp % 2 == 1) { res = (res * base) % m; } base = (base * base) % m; exp /= 2; } retu...
#include <bits/stdc++.h> struct oficinas { int valor; int sig; }; int v[200002], vaux[200002]; int buscar(int buscado); int main() { int n, q, type, x, y, i, A, B, aux; scanf( %d %d , &n, &q); for (i = 1; i <= n; i++) { v[i] = i; vaux[i] = i + 1; } for (i = 0; i < q; i+...
#include <bits/stdc++.h> using namespace std; const int maxn = 100 + 10; int a[maxn], chk[maxn]; string str; int main() { int n, k = 0; cin >> n >> str; if (str.size() < n) { cout << NO ; return 0; } for (int i = 0; i < str.size(); i++) { if (a[str[i] - 0 ] == 0) k++; ...