solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; int main() { int n, m, d, arr[10001]; cin >> n >> m >> d; for (int i = 1; i <= (n * m); i++) cin >> arr[i]; int curr = arr[1] % d; for (int i = 2; i <= (n * m); i++) { if (curr != (arr[i] % d)) { cout << -1; return 0; } } sort(arr + 1, arr ...
2
#include <bits/stdc++.h> #pragma GCC optimize(2) #pragma GCC optimize(3) using namespace std; const int mod = 1e9 + 7; const int maxx = 2e5 + 10; const double eps = 1e-6; using namespace std; const long double PI = 3.14159265358979323846; char ss[maxx], pp[maxx]; long long len, n; long long mp[maxx]; long long dou[maxx...
5
#include "bits/stdc++.h" using namespace std; #ifdef _DEBUG #include "dump.hpp" #else #define dump(...) #endif //#define int long long #define rep(i,a,b) for(int i=(a);i<(b);i++) #define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--) #define all(c) begin(c),end(c) const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f...
0
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int64_t n, i, j, k, l, sum = 0, flag = 0, t, a[200005], ans = 0; int64_t f(int64_t l, int64_t r) { vector<int64_t> v; for (int64_t i = l; i <= r; i++) { v.push_back(a[i]); } if (is_sorted((v).b...
1
#include <bits/stdc++.h> using namespace std; inline long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } int main() { long long t1, t2, x1, x2, t0; cin >> t1 >> t2 >> x1 >> x2 >> t0; if (t1 == t2) { cout << x1 << " " << x2 << endl; return 0; } if (t1 == t0) { ...
3
#include <iostream> #include <string> #include <vector> using namespace std; int s_to_i(string s){ int n=0; for(int i=0 ; i<(int)s.size() ; i++ ){ n *= 10; n += s[i] - '0'; } return n; } vector<int> vs_to_vi(vector<string> vs){ vector<int> vi; for(int i=0 ; i<(int)vs.size() ; i++ ){ vi.push_back( s_to_i(v...
0
#include <bits/stdc++.h> using namespace std; int n; int indegree[8010]; int type[8010]; int d[8010]; long long ans = 0; bool adjacencyMat[8010][8010]; char s[8010]; queue<int> q; map<char, string> hexToBinDict; int main() { hexToBinDict['0'] = "0000"; hexToBinDict['1'] = "0001"; hexToBinDict['2'] = "0010"; hex...
5
#include <bits/stdc++.h> using namespace std; int main() { int d1, d2, d3, sum = 0, p; cin >> d1 >> d2 >> d3; sum += min(min(d1, d2 + d3), min(d2, d1 + d3)); if (sum == d1) p = d1; else p = d2; sum += min(d3, (d2 + d1)); if (p == d1) sum += min(d2, (d1 + d3)); else sum += min(d1, (d2 + d...
1
#include <bits/stdc++.h> #pragma comment(linker, "/STATK:134217728") using namespace std; int n, q; char s[1 << 17]; struct P { int L, R; char c; P() {} P(int L, int R, char c) : L(L), R(R), c(c) {} }; bool operator<(const P& a, const P& b) { return a.L < b.L; } int cnt[26]; int main() { set<P> S; scanf("%d...
5
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int M, N; cin >> M >> N; cout << (M * N) / 2; return 0; }
1
#include<bits/stdc++.h> using namespace std; int main(){ int a, b, x; cin >> a >> b >> x; if(0.5*a*a*b>x){ double r=2.0*x/(a*b); printf("%.10f\n",90-atan(r/b)*180/M_PI); return 0; } double r=(2*((double)a*a*b-x))/(a*a*a); printf("%.10f\n",atan(r)*180/M_PI); return 0; }
0
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 7; const int MXN = 1e6 + 7; const int N = 1e3 + 7; long long n; long long a[MXN], t[4 * MXN], to[4 * MXN]; string s; inline void push(long long v, long long L, long long R) { if (to[v]) { t[v] += to[v]; to[v + v] += to[v]; to[v + v + 1] +...
3
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int a1, b1, c1, a2, b2, c2; cin >> a1 >> b1 >> c1 >> a2 >> b2 >> c2; if ((a1 == 0 and b1 == 0 and c1 != 0) or (a2 == 0 and b2 == 0 and c2 != 0)) { cout << "0"; return 0; ...
2
#include <bits/stdc++.h> using namespace std; int main() { long long t, x; cin >> t; while (t--) { cin >> x; long long a = 1, b = 1, c = 1; while (a <= x) { b += pow(2, c); a += (b * b) - ((b * (b - 1)) / 2); c++; } cout << c - 1 << endl; } }
2
#include <bits/stdc++.h> using namespace std; void answer() { int n, s, c = 0, d = 0; cin >> n >> s; if (n >= s) { cout << 1; return; } c = s / n; d = s % n; if (d == 0) { cout << c; return; } (d <= n) ? cout << c + 1 : cout << c + d; } int32_t main() { int t; t = 1; while (t--) ...
1
#include <bits/stdc++.h> using namespace std; const int MAX = 1e5 + 5; set<int> adj[MAX]; int n, m; int dfs(int source) { vector<int> unpaired; while (!adj[source].empty()) { int each = *adj[source].begin(); adj[source].erase(each); adj[each].erase(source); int u = dfs(each); if (u == 0) { ...
5
#include <bits/stdc++.h> using namespace std; void solve(); int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed; cout.precision(12); solve(); return 0; } template <typename T> void sc(T& x) { cin >> x; } template <typename Head, typename... Tail> void sc(Head& head, Tail&... tail) { cin ...
4
#include <bits/stdc++.h> using namespace std; struct T { int t, k, d, fin; vector<int> ids; T(int t, int k, int d) : t(t), k(k), d(d) { fin = t + d - 1; } T() : T(0, 0, 0) {} bool operator<(const T &other) const { return fin < other.fin; } bool operator>(const T &other) const { return fin > other.fin; } }; ...
3
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef complex<long double> cd; const int maxn = 2e5 + 5; int p[maxn], q[maxn], rp[maxn], rq[maxn]; int n; int rA[maxn], A[maxn], B[maxn]; void power(int b){ if (b == 0) return; power(b / 2); for (int i = 1; i <= n; i++) B[i] = A[A[i]]; for ...
0
#include <bits/stdc++.h> using namespace std; int xcum[1000010]; int n, q; int v[100000]; int cnt; int qual; int used[21 * 50000][2]; int trie[21 * 50000][2]; void add(int x) { int at = 0; for (int i = 20; i >= 0; i--) { int b = ((x & (1 << i)) != 0); if (used[at][b] != qual) { used[at][b] = qual; ...
6
#include <bits/stdc++.h> using namespace std; const int maxn = (int)2e5 + 100; int e[maxn][2]; double ed[maxn]; bool restr[maxn]; vector<int> g[maxn]; double w[maxn]; int getOth(int id, int v) { return e[id][0] + e[id][1] - v; } double getDer(int v, double len = 0., int par = -1) { double ans = pow(len, 0.5) * w[v]; ...
3
#include <iostream> #include <algorithm> using namespace std; int dp[5009][5], n, p[100009]; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> p[i]; for (int i = 0; i <= n; i++) { for (int j = 0; j <= 4; j++) dp[i][j] = (1 << 30); } dp[0][0] = 0; dp[0][1] = 0; dp[0][2] = 0; dp[0][3] = 0; dp[0][4] = 0; f...
0
#include <bits/stdc++.h> int main() { int n; int a[20]; int maxl = 1; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } int flag = 1; for (int i = n; i > 0; i /= 2) { for (int j = 0; j < n; j += i) { flag = 1; for (int k = 1; k < i; k++) { if (a[j + k] < a[...
1
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10, M = 5e9 + 10, mod = 1e9 + 7, inf = 1e18; long long n, a[N], i; vector<int> v; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for (i = 0; i < n; i++) cin >> a[i]; for (i = 0; i < n; i++) { long long x...
5
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1e5+7; void dfs(int now,int n,string ans,int k){ if(now == n){ cout << ans << "\n"; return ; } for(int i = 0;i <= k;++i) dfs(now+1,n,ans+(char)('a'+i),max(k,i+1)); return ; } int main() { int n; cin >> n; dfs(0,n,"",0); ...
0
#include<bits/stdc++.h> using namespace std; int main() { int n,maxn,ans = 0; cin >> n >> maxn; while(n--){ int t; cin >> t; if(t >= maxn) ans++; } cout << ans << endl; }
0
#include"bits/stdc++.h" using namespace std; #define rep(i,n) for(int i=0;i<n;i++) #define int long long constexpr long long mod = 1000000007; typedef pair<int, int> P; int res; int fib[90]; int fi2[90][90]; int gcd(int a, int b) { if (a < b)swap(a, b); if (!b)return 0; if (a / b > 1&&b>1)res++; if (b == 1 && a > 2...
0
#include <bits/stdc++.h> int main() { int n, k, s = 0; scanf("%d %d", &n, &k); s = n % k; printf("%d", n + k - s); return 0; }
1
#include<bits/stdc++.h> using namespace std; const int mn=105; int p,pos[205],x,n; int main() { scanf("%d%d",&x,&n); for(int i=1;i<=n;++i) {scanf("%d",&p);pos[p+100]=1;} int tmp=200,ans=0; for(int i=-10;i<=101;++i) { if(pos[i+100]) continue; if(tmp>abs(x-i)) tmp=abs(x-i),ans=i; } cout<<ans; }
0
#include <bits/stdc++.h> int main() { int ch, min, a; scanf("%d:%d%d", &ch, &min, &a); a += ch * 60 + min; printf("%.2d:%.2d\n", a / 60 % 24, a % 60); }
2
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; vector<int> v, v1; void solve() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) { int x; scanf("%d", &x); if (x) { v.push_back(x); } else { v1 = v; sort((v).begin(), (v).end()); reverse((v).begin...
3
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int N = 5000; vector<int> g[N]; int deg[N]; const int inf = 1e9 + 5; bool graph[N][N]; int solve(int x) { int i, j; int l = g[x].size(); int res = inf; for (i = 0; i < l; i++) { int w = g[x][i]; int l2 = g[w].size(); for (j...
2
#include <bits/stdc++.h> using namespace std; int main(){ int sum, N; cin >> sum >> N; vector<int> A(N); for(int i = 0; i < N; i++)cin >> A[i]; sort(A.begin(), A.end(), greater<int>()); int ans = max((A[0] - 1) - (sum - A[0]), 0); cout << ans << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; const int maxN = (1 << 22); int dP[maxN], a[maxN], n; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i]; for (int i = 0; i < (1 << 22); ++i) dP[i] = -1; for (int i = 1; i <= n; ++i) dP[a[i]] = a[i...
5
#include <bits/stdc++.h> using namespace std; const int N = 1e6; int main() { int h1, a1, c1, h2, a2; cin >> h1 >> a1 >> c1 >> h2 >> a2; vector<int> v; while (1) { if (h2 <= 0) break; if (h1 <= a2 && a1 < h2) { v.push_back(0); h1 += c1; h1 -= a2; continue; } else { v.pu...
2
#include <iostream> #include <complex> #include <sstream> #include <string> #include <algorithm> #include <deque> #include <list> #include <map> #include <numeric> #include <queue> #include <vector> #include <set> #include <limits> #include <cstdio> #include <cctype> #include <cmath> #include <cstring> #include <cstdli...
0
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5, M = 2e5 + 5, mx = 1e9, LN = 20, mod = 1e9 + 7; int ans; int n, m; vector<string> v; bool checkRow(int idx) { for (int i = 0; i < m; i++) if (v[idx][i] == 'P') return false; return true; } bool checkCol(int idx) { for (int i = 0; i < n; i++) ...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 1010; int f1[maxn], f2[maxn]; int find1(int a) { if (a != f1[a]) { a = f1[a] = find1(f1[a]); } return a; } int find2(int a) { if (a != f2[a]) { a = f2[a] = find2(f2[a]); } return a; } int main() { int n, m1, m2; cin >> n >> m1 >> m2;...
4
#include <bits/stdc++.h> using namespace std; template <typename T> inline long long squ(T x) { return (long long)x * x; } template <typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } template <typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; } templat...
5
#include <bits/stdc++.h> using namespace std; long long n, m, a[300000 + 100][10]; pair<long long, long long> dp[300]; signed main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false); cin >> n >> m; for (long long i = 1; i < n + 1; i++) { for (long long j = 0; j < m; j++) cin >> a[i][j]; for...
4
#include<bits/stdc++.h> typedef long long lnt; using namespace std; lnt n,a,b,c,d,l,r; inline bool range(lnt v,lnt x,lnt y){ return v>=x&&v<=y; } signed main(){ cin>>n>>a>>b>>c>>d;--n; for(int i=0;i<=n;++i){ l=-i*d+(n-i)*c; r=-i*c+(n-i)*d; if(range(b-a,l,r)) return puts("YES"),0; } return puts("NO"),0; }
0
#include<bits/stdc++.h> using namespace std; #define ll long long #define rep(i, n) for(int i = 0; i < (int)(n); i++) int main(){ string s; cin>>s; reverse(s.begin(),s.end()); while (s.size()!=0){ if (s.substr(0,5)=="maerd" or s.substr(0,5)=="esare") s.erase(0,5); else if (s.substr(0,6)=="resare") s.erase(0,...
0
#include <bits/stdc++.h> using namespace std; const long long N = 2e5 + 5; long long n, k, x = 0; string s; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; cin >> n >> k >> s; for (char ch = 'a'; ch <= 'z'; ch++) { long long curx = 0; for (long long i = 0; i < n; i++) { if...
2
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int data[26][4 * N], flag[26][4 * N], n, q; string s; void shift(int ch, int node, int st, int en) { if (flag[ch][node] == -1) return; int mid = (st + en) / 2; flag[ch][node * 2 + 0] = flag[ch][node]; flag[ch][node * 2 + 1] = flag[ch][node]; ...
5
#include <bits/stdc++.h> using namespace std; int n, m, r, c, tr, tc; double dp[2010][2010]; bool row[2010], col[2010]; int main() { while (cin >> n >> m) { memset(row, false, sizeof(row)); memset(col, false, sizeof(col)); tr = tc = 0; for (int i = 1; i <= m; (i)++) { cin >> r >> c; if (!r...
4
#include <bits/stdc++.h> using namespace std; const int MAXN = 110; int n, m; string mp[MAXN]; char getCurChar(int x, int y) { bool can[4]; memset(can, true, sizeof(can)); if (x > 0) can[mp[x - 1][y] - 'A'] = false; if (y > 0) can[mp[x][y - 1] - 'A'] = false; if (y < m && mp[x][y + 1] != '*') can[mp[x][y + 1]...
5
#include <bits/stdc++.h> int main() { unsigned long long a, b, x; std::cin >> a >> b; a < b | a - b & 1 ? std::cout << -1 : (x = (a - b) / 2, a -= x, x ^ a ^ b ? std::cout << -1 : std::cout << x << ' ' << a); }
4
#include <bits/stdc++.h> using namespace std; const int N = 610; const int M = 5e5 + 10; const int INF = 0x3f3f3f3f; int mx[N][N << 2], f[M][105], pr[M], c[N], n, k, p; int lowbit(int x) { return x & -x; } void update(int x, int val) { for (; x <= p; x += lowbit(x)) c[x] = max(c[x], val); } int get_max(int x) { int...
3
#include <bits/stdc++.h> using namespace std; const int N = 1e5; long long tree[1 << 19], lazy[1 << 19]; vector<int> a; void build(int i, int l, int r) { lazy[i] = -1; if (l == r) { tree[i] = a[l]; return; } int mid = (l + r) / 2; build(i * 2, l, mid); build(i * 2 + 1, mid + 1, r); tree[i] = tree[...
2
#include <bits/stdc++.h> using namespace std; const int b = 233; const int N = 1e5 + 50; const int mod = 1e9 + 9; char s[N]; int n, m, opt, k, l, r; long long Pow[N], Pow2[N]; struct Kano { int l, r, lazy; long long h; } kano[N * 4]; void pushup(int x) { kano[x].h = ((kano[x << 1].h * Pow[kano[x << 1 | 1].r...
5
#include <iostream> #include <vector> #include <set> #include <algorithm> using namespace std; int ans; vector<int> ansv; vector<vector<int> > v; void dfs(int prev, int next, int a, vector<int> vi, set<pair<int,int> > s){ if(v[prev][next] == -1 || s.find(pair<int,int>(prev,next)) != s.end()) return; vi.push_back(...
0
#include <bits/stdc++.h> using namespace std; int main() { long long a, b = 1, x = 0; cin >> a; a--; for (int k = 1; k <= a; k++) { x += 2; b += 6 * x; } cout << b; return 0; }
2
#include <bits/stdc++.h> template <class T> std::istream &operator>>(std::istream &is, std::vector<T> &xs) { for (auto &x : xs) is >> x; return is; } template <class T> std::ostream &operator<<(std::ostream &os, const std::vector<T> &xs) { for (auto it = xs.begin(); it != xs.end(); ++it) { os << "[ "[it != xs...
2
#include <iostream> using namespace std; int main() { int t,n,x; cin>>t; while(t--) { cin>>n; x=2*n; int odd=0; int a; for(int i=0;i<x;i++){ cin>>a; if(a%2==1) odd++; } if(odd==n) { cout<<"YES"...
1
#include <bits/stdc++.h> using namespace std; vector<vector<long long int> > cn(long long int n, long long int m) { return vector<vector<long long int> >(n, vector<long long int>(m)); } bool compare(char &s1, char &s2) { return s1 > s2; } bool sortmahstyle(const pair<long long int, long long int> &a, ...
3
#include <bits/stdc++.h> using namespace std; int n, m; bool g[7][7]; int N; int A[100]; int B[100]; int uc[7]; set<pair<int, int> > forb; int used[100007]; int was[100007]; int AA[100007]; int BB[100007]; int p[100007]; set<pair<int, int> > forb0; void solveSmall() { for (int i = 0; i < m; i++) { int a, b; s...
3
#include <bits/stdc++.h> using namespace std; const int p = 998244353; inline int fpow(int x, int y) { int ans = 1; while (y) { if (y & 1) ans = 1ll * ans * x % p; x = 1ll * x * x % p, y >>= 1; } return ans; } int n; int cnt[100086]; int sum[100086], a[100086], b[100086]; long long siz[100086]; int f[10...
6
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int M = 1e9 + 6; const int ini = 333333336; long long pow_mod(long long a, long long n) { long long x = 1; while (n) { if (n & 1) x = x * a % mod; a = a * a % mod; n >>= 1; } return x; } void solve(long long fo, long long t...
5
#include <bits/stdc++.h> using namespace std; long long read() { long long x = 0, f = 0; char ch = getchar(); while (!isdigit(ch)) f = ch == '-', ch = getchar(); while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar(); return f ? -x : x; } const int N = 100005; int n, m; vector<pair<int, int> ...
5
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; int flag = 0, p, q, prev = INT_MAX; for (int i = 0; i < n; ++i) { cin >> p >> q; if (p != q) { cout << "rated"; return 0; } else if (q > prev) { flag = 1...
1
#include <bits/stdc++.h> using namespace std; long long int gcd(long long int a, long long int b) { if (b < a) { long long int temp = a; a = b; b = temp; } if (a == 0) { return b; } return gcd(b % a, a); } long long int lcm(long long int a, long long int b) { return (a * b / gcd(a, b)); } lo...
2
#include <bits/stdc++.h> using namespace std; const long long mx = 1e5 + 10; long long n, m, a[mx], cnt[mx], r[mx], l[mx], p[mx], ans[mx]; int main() { cin >> n >> m; for (long long i = 1; i <= n; i++) { cin >> a[i]; if (a[i] < mx) cnt[a[i]]++; } for (long long i = 0; i < m; i++) cin >> l[i] >> r[i]; ...
2
#include <bits/stdc++.h> using namespace std; template <int BASE, long long MODULO> class StringHash { template <int B, long long M> friend class StringHasher; vector<long long> hash; public: size_t getSize() const { return hash.size(); } }; template <int BASE, long long MODULO> class StringHasher { static ...
6
#include <bits/stdc++.h> using namespace std; int main() { int n,a[100005]; cin>>n; for(int i=1;i<=n;i++){ int b; cin>>b; a[b]=i; } for(int i=1;i<=n;i++) cout<<a[i]<<" "; cout<<endl; }
0
#include <bits/stdc++.h> using namespace std; int main() { int num, Mishka = 0, Chris = 0; cin >> num; for (int i = 0; i < num; i++) { int num1, num2; cin >> num1 >> num2; if (num1 > num2) { Mishka++; } else if (num2 > num1) { Chris++; } } if (Mishka > Chris) { cout << "Mis...
1
#include <bits/stdc++.h> using namespace std; int main(){ int k; cin>>k; if (k%2==0||k%10==5){ cout<<-1; return 0; } int ans=1, r=7%k; while (r!=0){ ans++; r=(r*10+7)%k; } cout<<ans<<endl; }
0
#include <bits/stdc++.h> using namespace std; const int MAXN = 3005; char c[MAXN][MAXN]; int l[MAXN][MAXN], r[MAXN][MAXN], d[MAXN][MAXN], fen[2 * MAXN][MAXN]; vector<pair<int, int> > ev[MAXN]; void add(int t, int x, int val) { for (; x < MAXN; x |= x + 1) fen[t][x] += val; } int getPref(int t, int x) { int res = 0;...
5
#include <bits/stdc++.h> using namespace std; void solve() { long long int offset = 100 * 100 * 10; long long int mxbal = offset + offset; long long int n, k; cin >> n >> k; vector<long long int> a(n + 1), b(n + 1); for (long long int i = 0; i < n; ++i) cin >> a[i]; for (long long int i = 0; i < n; ++i) c...
3
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; const long long mod = 1e9 + 7; long long giv[maxn]; int n, nm; long long w[2]; long long res; struct node { int to, next; } edg[maxn * 2]; int beg[maxn]; bool col[maxn]; long long num[maxn][2]; void ran(int x, bool y, int fa) { col[x] = y; w[...
5
#include <bits/stdc++.h> using namespace std; const long long N = (2e5 + 5); const long long MOD = 1e9 + 7; const long long INF = 1e16; const long long LOG = 29; long long binpow(long long a, long long b) { a %= MOD; long long res = 1; while (b > 0) { if (b & 1) res = (res * a) % MOD; a = (a * a) % MOD; ...
1
#include <bits/stdc++.h> using namespace std; pair<pair<int, int>, int> req[1000]; pair<int, int> t[1000]; int n, k; bool cmp1(pair<pair<int, int>, int> a, pair<pair<int, int>, int> b) { if (a.first.first != b.first.first) return a.first.first > b.first.first; else if (a.first.second != b.first.second) retu...
3
#include <bits/stdc++.h> using namespace std; int n; string a, b; int d[30][30]; string resp; int main() { cin.sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> a >> b >> n; for (int i = 0; i < 26; i++) for (int j = 0; j < 26; j++) if (i != j) d[i][j] = 1e8; for (int i = 1; i <= n; i++) { ch...
2
#include <bits/stdc++.h> #pragma GCC optimize("Ofast,no-stack-protector") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #pragma GCC optimize("unroll-loops") #pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; long long x, y, z, a[105]; string s[105]; int main() {...
1
#include <bits/stdc++.h> const int INF = 1e9 + 10; unsigned long long MOD = 998244353; using namespace std; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); unsigned long long n; cin >> n; if ((n - 2) % 3 != 0) { cout << 1 << " " << 1 << " " << n - 2; } else { cout << 2 << " ...
1
#include <bits/stdc++.h> using namespace std; int main() { long long t, n, k; cin >> t; while (t--) { cin >> n; long long ans = 0; while (n > 0) { if (n % 2 == 1) { ans += 1; n--; if ((n % 4 == 0) && (n >= 8)) { n--; } else { if (n % 4 == 0) { ...
1
#include <bits/stdc++.h> using namespace std; #define rep(i,a,b) for (int i = (a); i < (b); i++) #define REP(i,n) rep(i,0,n) void solve() { int n,p;string s;cin>>n>>p>>s; int64_t ans=0; if(p==2||p==5){ REP(i,n)if(!((s[i]-'0')%p))ans+=i+1; }else{ map<int,int>cnt; cnt[0]=1; ...
0
#include <bits/stdc++.h> using namespace std; const int nax = 100005, mod = 1e9 + 7, inf = 1e9; int dp[nax][2], n, col[nax]; vector<int> v[nax]; int pot(int a, int b) { int res = 1; while (b) { if (b & 1) res = (long long)res * a % mod; a = (long long)a * a % mod; b /= 2; } return res; } void dfs(in...
4
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[1002][1002] = {0}; map<int, int> mx; map<int, int> my; int x = 0; int y = 0; for (int i = 1; i < 1001; i++) { mx.insert({i, x}); my.insert({i, y}); if (i % 2 == 1) x += 1; else y += 1; if (i...
2
#include <bits/stdc++.h> using namespace std; const int nmax = 1e6 + 42; int n, wanted, inp[nmax]; long long eval(int i, int cur) { long long s = ((-inp[i]) % cur + cur) % cur; long long t = cur - s; long long d = (inp[i] + s) / cur; return 1LL * s * (d - 1) * (d - 1) + 1LL * t * d * d; } priority_queue<pair<lo...
5
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d; while (scanf("%d%d%d%d", &a, &b, &c, &d) != EOF) { int x, y = 2, z = max(abs(a - c), abs(b - d)); if (a != c && b != d) x = 2; else x = 1; if (abs(a - c) == abs(d - b)) y = 1; else if ((c + d + (b - a)) ...
1
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b, s = 0; cin >> n; int d[n - 2]; for (int i = 0; i <= n - 2; i++) { cin >> d[i]; } cin >> a >> b; for (int j = (a - 1); j < (b - 1); j++) { s += d[j]; } cout << s << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; int main(){ int n,k; cin>>n>>k; int x[n]; for(int i=0;i<n;i++)cin>>x[i]; int l,r,d,mm; int m=2000000001; for(int i=0;i<n-k+1;i++){ l=max(x[i],-x[i]); r=max(x[i+k-1],-x[i+k-1]); d=max(x[i]-x[i+k-1],x[i+k-1]-x[i]); mm=min(l+d,r+d); m=m...
0
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; long double tot_ans = 0; vector<pair<int, int> > adj[N]; int u, v, c, n; int lvl[N]; int sv[N]; int init[N]; long double compute(int wt, int t7t, int fo2) { long double ret = 0; if (t7t && fo2 >= 2) { long double prop1 = 1.0 * t7t / n ...
4
#include <iostream> #include <algorithm> #include <vector> #include <cstring> using namespace std; int main() { int n; while(cin>>n, n) { vector<int> vi; for(int i=1; i<n; ++i) vi.push_back(i*i%n); sort(vi.begin(), vi.end()); vector<int>::iterator uni = unique(vi.be...
0
#include <bits/stdc++.h> using namespace std; int main() { int a,b,c,d,e,f,g,h,i; cin >>a >>b >>c >>d >>e >>f >>g >>h >>i; if(a+e==b+d&&b+f==c+e&&d+h==e+g&&e+i==f+h){ cout << "Yes" << endl;} else{ cout << "No" << endl;} }
0
#include <bits/stdc++.h> using namespace std; const int NMAX = 200000 + 5; int v[NMAX]; int main() { ios_base ::sync_with_stdio(false); int n; cin >> n; for (int i = 1; i <= n; ++i) cin >> v[i]; for (int i = 1; i <= n; ++i) { v[i] %= 2; if (v[i] == 1) { if (v[i + 1] == 0) { cout << "NO\n...
2
#include<iostream> using namespace std; int main(){ int a,b,ans=0; cin>>a>>b; ans+=a; if(a>b)ans-=1; cout<<ans<<endl; }
0
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n, k; cin >> n >> k; string s; cin >> s; long long previous = 0; vector<long long> preb; vector<long long> prea; for (long long i = 0; i < n; i++) { if (s[i]...
3
#include <bits/stdc++.h> using namespace std; int solve(vector<int> v) { int max = 0, aux = 0; map<int, int> m; for (int i = 0; i < v.size(); i++) { if (v[i] < 0) { if (m.find(-(v[i])) == m.end()) { max++; } else { aux--; } } else { m[v[i]]++; aux++; if ...
2
#include <bits/stdc++.h> using namespace std; int main() { long int n, k, i; long int a; long long ans = 0; cin >> n >> k; long int x[n]; long int c[n]; for (i = 0; i < n; i++) cin >> x[i]; cin >> a; for (i = 0; i < n; i++) cin >> c[i]; deque<long int> d; for (i = 0; i < n; i++) { if (k < x[i]...
6
#include <vector> #include <map> #include <set> #include <stack> #include <queue> #include <algorithm> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <string> #include <cstring> #include <complex> #include <ctime> #include <cst...
0
#include <bits/stdc++.h> using namespace std; void task(); int main() { task(); return 0; } const int INF = 0x3f3f3f3f; const int N = 203; struct Rib { int to; int cap; int flow; int back; }; int n, m; int a[101]; int b[101]; vector<Rib> g[N]; int S = 201, T = 202; int ans[101][101]; int dist[N]; int pt[N];...
5
#include <bits/stdc++.h> using namespace std; bool check(int arr[], int size, int k) { for (int i = 0; i < size; i++) { if (arr[i] != k) return false; } return true; } int main() { int n, k; cin >> n >> k; int ranks[n]; for (int i = 0; i < n; i++) cin >> ranks[i]; int counter = 0; while (!check(ra...
2
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; vector<long long> primes; if (n == 1) { cout << 1 << endl << 0; return 0; } while (n % 2 == 0) { primes.push_back(2); n = n / 2; } for (int i = 3; i <= sqrt(n); i += 2) { while (n % i == 0) { prim...
3
#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; string s; cin >> s; vector<set<int>> num(2); for (int i = 0; i < n; i++) { num[s[i] - '0'].insert(i); } vector<int> ...
4
#include <iostream> using namespace std; int main() { int n, count; bool *data; while (cin >> n) { data = new bool[n + 1]; count = 0; for (int i = 0;i <= n;i++) data[i] = true; for (int i = 2;i <= n;i++) { if (data[i]) { count++; for (int j = i + i;j <= n;j += i) { data[j] = false; } ...
0
#include <bits/stdc++.h> using namespace std; template <class TH> void _dbg(const char *sdbg, TH h) { cerr << sdbg << '=' << h << endl; } template <class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) { while (*sdbg != ',') cerr << *sdbg++; cerr << '=' << h << ','; _dbg(sdbg + 1, a...); } template ...
5
#include <bits/stdc++.h> using namespace std; int n, cnt[100015], x[100015], y[100015], z[100015]; vector<int> a[100015]; int getpos(int i, int u) { if (x[i] == u) return 0; if (y[i] == u) return 1; if (z[i] == u) return 2; } void dfs(int u, int v) { cout << u << ' '; if (cnt[v] == 0) { cout << v; ret...
3
#include <bits/stdc++.h> int main(int argc, char *argv[]) { int i, n; long long res = 1; scanf("%d", &n); for (i = n; i < 2 * n - 1; i++) res *= i; for (i = 2; i < n; i++) res /= i; printf("%d", res); return 0; }
1
#include <bits/stdc++.h> using namespace std; int N, M, C, a[100009]; int res(int p1, int p2, int p3) { int s = 0; if (p1 > p2) s += (p2 - p1); if (p2 > p3) s += (p3 - p2); return s; } void solve(int s) { int G; cin >> G; if (G <= C / 2) { for (int i = 1; i <= N; i++) { if (a[i] == 0 || a[i] > G...
4