solution
stringlengths
52
181k
difficulty
int64
0
6
#include<iostream> using namespace std; int main() { int n, m, d, v, a[101]; while( cin >> n >> m ) { if( n + m == 0 ) break; for( int i = 0; i < 101; i++ ) a[i] = 0; for( int i = 0; i < n; i++ ) { cin >> d >> v; if( a[d] < ...
0
#include <bits/stdc++.h> using namespace std; const int MAXN = 5123; string t; int n, a, b; int memo[MAXN]; int step[MAXN]; int z[MAXN + MAXN]; void zfunction(const string& s) { memset(z, 0, sizeof z); int n = s.size(); int L = 0, R = 0; for (int i = 1; i < n; i++) { if (i > R) { L = R = i; whil...
6
#include <bits/stdc++.h> using namespace std; inline void up(int& x, int y) { x = x + y < 1000000007 ? x + y : x + y - 1000000007; } inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { ...
1
#include <bits/stdc++.h> using namespace std; int main() { int a, T; cin >> T; while (T--) { scanf("%d", &a); printf("1 %d\n", a - 1); } }
1
#include<bits/stdc++.h> using namespace std; int main() { int t; string s; cin>>t; while(t--) { cin>>s; for(int i=0;i<s.length();i++) { if(i%2==0) { if(s[i]=='a') cout<<'b'; else cout<<'a'; } el...
1
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 69; const int MOD = 1e9 + 7; int n, ans, par[MAXN], depth[MAXN]; void add(int v) { par[v] = v; } void find(int v) { if (par[v] != v) { find(par[v]); depth[v] = (depth[v] + depth[par[v]]) % MOD; par[v] = par[par[v]]; } } void upd(int v,...
5
#include<bits/stdc++.h> #define ll long long #define fi first #define se second #define mp make_pair #define pb push_back #define pii pair<int,int> #define pll pair<long long,long long> #define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define endl "\n" using namespace std; int n; vect...
2
#include <bits/stdc++.h> using namespace std; const long long llINF = 9223372036854775807; const int INF = 2147483647; const int maxn = 2e5 + 7; const int maxm = 1e6 + 7; const long long mod = 998244353; const double pi = acos(-1.0); const double eps = 1e-9; long long n, m; long long p[maxn]; long long fac[maxn]; long ...
6
#include <bits/stdc++.h> using namespace std; int main() { int N; string A ,S = "Three"; cin >> N; for(int i = 0; i < N; i++){ cin >> A; if(A == "Y"){ S = "Four"; break; } } cout << S; }
0
#include<bitset> #include<cstdio> #include<algorithm> #define rep(i,l,r) for (int i=(l); i<=(r); i++) using namespace std; const int N=510,mod=998244353; int n,m,y,rk,ans,a[N][N],pw[N]; bitset<N> b[N]; int main(){ scanf("%d%d",&n,&m); pw[0]=1; rep(i,1,n){ bitset<N>x(0); rep(j,1,m) scanf("%d",&y),x[j-1]=y; for...
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; while (n--) { long int q; cin >> q; long int inp[200000]; long int count[200000] = {0}; long int _max = -1, _min = 2000001; for (long int i = 0; i < q; i++) { cin >> inp[i]; count[inp[i]]++; if (i...
3
#include <bits/stdc++.h> using namespace std; long long a[100008], b[100009]; map<long long, long long> mp; map<long long, long long> mp1; int main() { cin.sync_with_stdio(false); long long i, j, k, l, c, v, bbbb[1000], aa[1009], bb[1000], n, m, r, t; long long x1, x2, y1, y2, x3, x4, x5, x6; string s, s1, s2, ...
1
#include <bits/stdc++.h> using namespace std; typedef struct { long long int b, c; } No; vector<int> grafo[100100]; No arv[4 * 100100]; int pos[100100]; pair<int, int> axpos[100100]; long long int custo[100100]; long long int subida[100100]; long long int biscoito[100100]; long long int n, t; void atualiza(int no, in...
6
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; int a[N], dis[N], ans, num; bool vis[N]; vector<int> pic[N], prime; queue<int> que; void read(int &x) { x = 0; int f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch)) { ...
5
#include <bits/stdc++.h> using namespace std; template <typename T> inline bool upmin(T &x, T y) { return y <= x ? x = y, 1 : 0; } template <typename T> inline bool upmax(T &x, T y) { return x <= y ? x = y, 1 : 0; } const long double eps = 1e-9; const long double pi = acos(-1); const int oo = 1 << 30; const long lo...
6
#include <bits/stdc++.h> using namespace std; int res; int DN[2005][2005]; char S1[2005], S2[2005]; int main() { scanf("%s%s", S1 + 1, S2 + 1); int uz1 = strlen(S1 + 1); int uz2 = strlen(S2 + 1); for (int i = 1; i <= uz1; i++) for (int j = 1; j <= uz2; j++) { DN[i][j] = DN[i - 1][j - 1] + (S1[i] == S2...
1
#include<bits/stdc++.h> using namespace std; #define T top() #define E end() #define PS push #define Q queue #define PP pop() #define L0 (LL)0 #define V vector #define ST stack #define FI first #define MAX 4e18 #define MIN -MAX #define DQ deque #define SZ size() #define C clear() #define B begin() #define F front() #de...
3
#include <bits/stdc++.h> using namespace std; int tmp[111]; void permuteArr(int *arr1, int *per, int sz) { for (int i = 0; i < sz; i++) tmp[per[i] - 1] = arr1[i]; for (int i = 0; i < sz; i++) arr1[i] = tmp[i]; } bool isSame(int *arr1, int *arr2, int sz) { for (int i = 0; i < sz; i++) if (arr1[i] != arr2[i]) r...
4
#include <iostream> #define N 15 using namespace std; int jump(int,int); int X,Y,data[N][N],dp[N][N]; int main(){ bool q[N][N]; while(1){ cin >> X >> Y; if(X==0&&Y==0) break; for(int i=0;i<Y;i++) for(int j=0;j<X;j++) cin >> data[i][j],q[i][j]=false,dp[i][j]=0; for(int i=0;i<X;i++) if(dat...
0
#include <iostream> using namespace std; int main() { double x[4], y[4]; int n; cin >> n; while (n--) { for (int i = 0; i < 4; ++i) cin >> x[i] >> y[i]; double A1 = y[1] - y[0]; double B1 = x[0] - x[1]; double C1 = A1 * x[0] + B1 * y[0]; double A2 = y[3] - y[2]; double B2 = x[2] - x[3]; double C2 = A1...
0
#include <bits/stdc++.h> using namespace std; int main() { unsigned int n, a, b, c, cnt, i, j; while (cin >> n >> a >> b >> c) { cnt = 0; for (i = 0; i <= b; i++) { for (j = 0; j <= c; j++) { if ((2 * (n - i - 2 * j)) <= a) { cnt++; } } } cout << cnt << endl; ...
2
#include <bits/stdc++.h> using namespace std; const double PI = acos(0) * 2; const double EPS = 1e-8; const long long MOD = 1e9 + 7; const int MAXN = 1e5 + 5; const int oo = 1e9; const double foo = 1e30; template <class T> int getbit(T s, int i) { return (s >> i) & 1; } template <class T> T onbit(T s, int i) { retu...
4
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:256000000") using namespace std; const long long MOD = (int)1e9 + 7; const long long MOR = (int)1e9 + 31; const long long INF = (long long)1e15 + 100; const int dx[] = {0, 1, 0, -1}; const int dy[] = {1, 0, -1, 0}; const int MAXN = (int)3e5 + 5; const double pi =...
1
#include<bits/stdc++.h> using namespace std; int n,m; int x,y,z; int fa[100010]; int g[100010],cnt=0; int find(int x){ if(fa[x]==x) return x; return fa[x]=find(fa[x]); } int main() { scanf("%d %d",&n,&m); for(int i=1;i<=n;i++) fa[i]=i; for(int i=1;i<=m;i++){ scanf("%d %d %d",&x,&y,&z); int u=f...
0
#include <bits/stdc++.h> using namespace std; int tmp, res, n, a[20000 + 5]; void Init(); void Process(); int main() { Init(); Process(); return 0; } void Init() { scanf("%d", &n); for (int i = 1; i <= n; ++i) { scanf("%d", &a[i]); res += a[i]; } } void Process() { int k; for (int i = 1; i <= n;...
4
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int sum = 0, a; for (int i = 0; i < n; i++) { cin >> a; sum += a; } int m; cin >> m; vector<char> good(1e5 + 1, false); int l, r; for (int i = 0; i < m; i++) { cin >> l >> r; for (int j = l; j <= r; j++) { ...
1
#include <bits/stdc++.h> #define eps 1e-9 #define nmax 200 #define f(c,a,b) for(int c=a; c<=b; c++) #define pi acos(-1) using namespace std; typedef double db; struct P{ db x, y; P operator - (P a){ return (P){x-a.x, y-a.y}; } db dot(P a){ return a.x*x + a.y*y; } P operator * (db a) { return (P){a*x, a...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<string> a(m), b(m); vector<string> line(n); vector<string> ans(n); char s[15]; for (int i = 0; i < m; i++) { scanf("%s", s); string x = ""; for (int j = 0; j < strlen(s); j++) x += s[j]; a[i] = x; ...
2
#include <bits/stdc++.h> using namespace std; int cnt = 0; int a[3][3]; char ans[3][3]; int main() { for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) { cin >> a[i][j]; ans[i][j] = '1'; } if (a[0][0] + a[0][1] + a[1][0] & 1) cout << '0'; else cout << '1'; if (a[0][1] + a[0][0] ...
1
#include <bits/stdc++.h> using namespace std; int n, N, M, K, b[100005], q[100005 * 400]; bool e[100005]; long long H, a[100005], d[100005], c[25]; priority_queue<pair<int, int> > Q; void init() { scanf("%I64d%d%d%d", &H, &N, &M, &K); for (int i = 1; i <= N; i++) scanf("%I64d%d", &a[i], &b[i]); } void doit() { me...
3
#include <bits/stdc++.h> using namespace std; int n, x; vector<vector<int> > graph; vector<bool> visited; void dfs(int node) { visited[node] = true; for (__typeof((graph[node]).begin()) child = (graph[node]).begin(); child != (graph[node]).end(); ++child) if (!visited[*child]) dfs(*child); } int main() {...
3
#include <bits/stdc++.h> #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 long n, k; vector<vector<pair<long long, long long>>> graph; pair<long long, long long> DFS(long long node, long long...
3
#include<iostream> using namespace std; int main(){ int n; int num[2001] = {0}; for(int i=0;i<=1000;i++) for(int j=0;j<=1000;j++)num[i+j]++; while(cin >> n){ int res = 0; for(int i=0;i<=1000;i++){ for(int j=0;j<=1000;j++){ if(n-i-j<0 || n-i-j>2000)continue; res += num[n-i-j]; } ...
0
#include<bits/stdc++.h> using namespace std; long x,k,d; int main(){ cin>>x>>k>>d; x=abs(x); if(x/d>=k) cout<<x-d*k<<endl; else cout<<abs(x%d-((x/d)%2==k%2?0:d))<<endl; }
0
#include <bits/stdc++.h> using namespace std; void jabru() { int n; cin >> n; vector<pair<int, int> > v(n); for (long long i = 0; i < n; i++) { int x; cin >> x; v[i] = make_pair(x, i); } sort(v.begin(), v.end()); vector<int> ans(n); int ind = v[0].first; for (long long i = 0; i < n; i++) {...
3
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned int ui; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> pii; typedef pair<long long, long long> pll; const int inf = 1e9; const ll inf64 = 1e18; bool check(vector<string> a) { int n = (int) a.size...
3
#include <bits/stdc++.h> using namespace std; int arr[305][305]; int main() { int i, j, k, a, b, c = 1, n, m, t, x, y; scanf("%d", &n); for (i = 1; i <= n; i++) { for (j = 1; j <= n; j++) { if (i % 2 == 1) arr[j][i] = c++; else arr[n - j + 1][i] = c++; } } for (i = 1; i <= ...
3
#include<bits/stdc++.h> using namespace std; int main(){ string s; cin >> s; int g = 0, p = 0; for(int i=0;i<s.size();++i){ if(s[i] == 'g')g++; else p++; } cout << (g - p) / 2 << endl; return 0; }
0
#include <bits/stdc++.h> struct Point{ double x,y; Point(double x = 0,double y = 0) : x(x), y(y) {} Point operator + (const Point &p)const{ return Point(x + p.x , y + p.y); } Point operator - (const Point &p)const{ return Point(x - p.x , y - p.y); } Point operator * (const double &k)const{ ...
0
#include <bits/stdc++.h> using namespace std; string outputAns(string odds, string evens, vector<int> &freq) { string out = ""; for (int i = 0; i < odds.length(); i++) for (int j = 1; j <= freq[odds[i] - 'a']; j++) out += string(1, odds[i]); for (int i = 0; i < evens.length(); i++) for (int j = 1; j <= fr...
2
#include <bits/stdc++.h> using namespace std; const int oo = 10000000; int f(int a, int k) { int aa = a; int u = 0; while (a > k) { a /= 2; u++; } if (a == k) return u; while (k > a) { a *= 2; u++; } if (a == k) return u; return 1 + f(aa / 2, k); } int b[100005]; set<int> s; set<int>::...
3
#include <bits/stdc++.h> using namespace std; int main() { int N,D; cin >> N >> D; cout << (2*D+N)/(2*D+1) << endl; }
0
#include <bits/stdc++.h> using namespace std; vector<int> G[1000013]; void add(int u, int v) { G[u].push_back(v); } int dfn[1000013], low[1000013], num; stack<int> st; int scc[1000013], sc; int sz[1000013]; void tarjan(int u) { low[u] = dfn[u] = ++num; st.push(u); for (auto v : G[u]) { if (!dfn[v]) { ta...
6
#include <bits/stdc++.h> using namespace std; int n, k; set<int> query; multiset<pair<int, int> > mySet; void ssotQuery() { cout << "? "; for (auto it : query) cout << it << ' '; cout << endl; int pos, x; cin >> pos >> x; mySet.insert({pos, x}); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); ...
4
#include <bits/stdc++.h> using namespace std; const int N = 1003; int a[N], b[N]; int main() { int n, k; scanf("%d %d", &n, &k); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } for (int i = 0; i < n; i++) { scanf("%d", &b[i]); } int l = 0, r = 2000; while (l <= r) { int mid = (l + r) >> ...
4
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; string s, t; cin >> s; int open = 0, close = 0, act = 0, i; for (i = 0; i < s.size(); i++) { if (s[i] == '(') { open++; if (open * 2 <= m) t += s[i...
3
#include<bits/stdc++.h> using namespace std; int ask(int i){ int r; cout<<"? "<<i<<"\n"; fflush(stdout); cin >> r; return r; } int main(){ int n; cin >> n; if(n<=100){ int a[n]; for(int i=0;i<n;i++){ a[i]=ask(i+1); } if(a[0]<a[1]){ cout<<"! 1\n"; fflush(stdout); ...
1
#include <bits/stdc++.h> using namespace std; int main() { set<long long> s[4]; long long x, y, z, ans = 0, mx = 0; int tt, qq; cin >> tt; for (qq = 1; qq <= tt; qq++) { cin >> x >> y; ans += y; if (x == 0) { if (y > 0) { s[0].insert(y); if (s[3].size()) { z = *s[3]...
5
#include <bits/stdc++.h> using namespace std; pair<long double, long double> a, b, r, p[100005]; int n, e = 0, pos; long double fr[100005], fa[100005], fb[100000], sm = 0, res, ra, rb, y, w; long double far(pair<long double, long double> f, pair<long double, long double> s) { return sqrt((f.first - s....
3
#include <iostream> using namespace std; int main(){ int a,b,c; char x; int r=0,m=0; while(cin>>a>>x>>b>>x>>c){ if(a*a+b*b==c*c)r++; if(a==b)m++; } cout<<r<<endl <<m<<endl; }
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int n; long long m; cin >> n >> m; vector<long long> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } long long sum = std::accumulate(a.begin(), a.end(), 0); if (sum < m) { cout << -1 << endl; re...
4
#include<iostream> int main(){int n;std::cin>>n;std::cout<<(n>=30?"Yes":"No");}
0
#include <bits/stdc++.h> const int maxn = 1e6 + 10; const int inf = 0x3f3f3f3f; const long long INF = 0x3f3f3f3f3f3f3f3f; using namespace std; long long ts, tf, t, n, arr[maxn], now, idx, ans, anss; queue<long long> q; int main() { scanf("%lld%lld%lld", &ts, &tf, &t); scanf("%lld", &n); for (int i = 0; i < n; i++...
2
#include <bits/stdc++.h> using namespace std; template <typename TH> void _dbg(const char* sdbg, TH h) { cerr << sdbg << "=" << h << "\n"; } template <typename TH, typename... TA> void _dbg(const char* sdbg, TH h, TA... t) { while (*sdbg != ',') cerr << *sdbg++; cerr << "=" << h << ","; _dbg(sdbg + 1, t...); } ...
5
#include <bits/stdc++.h> using namespace std; long long h, n; long long level; int main() { while (cin >> h >> n) { long long ans = 0LL; level = 0LL; long long tot = 1LL << h; while (true) { if (level == h) { break; } if (ans % 2) { if (n <= tot / 2LL) { ans...
3
#include <bits/stdc++.h> using namespace std; const int MAXN = 210000; namespace SegTree { struct Node { int val, cnt, addn; bool operator<(const Node x) const { return val < x.val; } } tree[MAXN << 2]; Node merge(Node l, Node r) { l.addn = r.addn = 0; if (l.val == r.val) return (Node){l.val, l.cnt + r.cnt,...
5
#include <bits/stdc++.h> using namespace std; long long n, ans, ar[200004]; long long freq[200004]; long long pre[200004]; long long get_sum(long long i, long long j) { if (i == 0) return pre[j]; return pre[j] - pre[i - 1]; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = ...
6
#include<stdio.h> #include<iostream> #include<algorithm> using namespace std; int main(){ int m,n,i,j,t,y; int e[15]={10000}; for(i=0;i<12;i++){ scanf("%d",&e[i]); } sort(e,e+12); if(e[0]==e[1] && e[2]==e[3] && e[4]==e[5] && e[6]==e[7] && e[8]==e[9] && e[10] == e[11]){ printf("yes\n"); } else{ printf("n...
0
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; const int maxN = 1100; int D[maxN][maxN]; int sum[maxN][maxN], sum2[maxN][maxN]; int N, M, K; int main() { int i, j, k; scanf("%d%d%d", &N, &M, &K); for (i = 1000; i >= 1; i--) { D[K][i] = 1; sum[K][i] = 1000 - i + 1 + sum[K][i + 1]...
5
#include<cstdio> #include<cstring> #include<algorithm> #include<cstdlib> #include<ctime> #include<utility> #include<map> #include<queue> #include<set> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii; int n; map<ll,int> a; queue<pii> q; set<int> l[100010]; int f[10001...
0
#include <bits/stdc++.h> typedef long long int ll; using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll tc; cin >> tc; while (tc--) { ll n, ans = LLONG_MAX, pre = 0; cin >> n; vector<ll> c(n); priority_queue<ll, vector<ll>, greate...
3
#include <bits/stdc++.h> using namespace std; int n; int a[6000]; int Fen[6000]; void upd(int x) { for (; x <= n; x |= (x + 1)) Fen[x]++; } int how(int x) { int a = 0; for (; x >= 0; x = (x & (x + 1)) - 1) a += Fen[x]; return a; } int main() { cin >> n; for (int(i) = (0); i < (n); ++(i)) cin >> a[i]; int ...
3
#include <bits/stdc++.h> using namespace std; const long long maxn = 3e5 + 10; long long a[maxn], nxt[maxn], dp[maxn], n, q; unordered_map<long long, long long> NXT[maxn]; signed main() { ios::sync_with_stdio(false); cin >> q; while (q--) { cin >> n; for (long long i = 0; i < n; i++) cin >> a[i]; nxt[...
4
#include <bits/stdc++.h> using namespace std; ifstream fin("AAtest.in.txt"); long long t, n, k, jad[200005]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cerr.tie(0); cin >> t; while (t--) { cin >> n >> k; long long ma = -10000000000; for (int(i) = (0); ((i)) < ((n)); ((i))++) ...
2
#include <bits/stdc++.h> using namespace std; const long double pi = 3.14159265358979323846; void debn(vector<int> a) { for (auto v : a) cout << v << ' '; cout << endl; } void debnn(vector<vector<int>> a) { for (auto v : a) { for (auto w : v) cout << w << ' '; cout << endl; } } long long powmod(long lon...
2
#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; if (n > m) { swap(n, m); } if (n == 1) { long long mod = m % 6; if (mod <= 3) { cout << (m / 6) * 6 << endl; } else { cout << (m / 6) * 6 +...
2
#include <bits/stdc++.h> using namespace std; const int N = 10000; const long double pi = acos(-1.0); int n, a[200200]; long long sum[200200]; int read() { int x = 0, f = 1; char ch = getchar(); while ((ch < '0') || (ch > '9')) { if (ch == '-') f = -1; ch = getchar(); } while ((ch >= '0') && (ch <= '9...
5
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") using namespace std; long long n, k, l, mod; struct matrix { long long m[2][2]; matrix() { memset(m, 0, sizeof(m)); } matrix operator*(matrix const& other) { matrix res; for (long long i = 0; i <= 1; i++) { f...
4
#include <bits/stdc++.h> int main() { int n, m; bool flag[26]; char color; std::cin >> n >> m >> color; int i, j, count = 0; for (i = 0; i < 26; i++) flag[i] = false; char plan[n][m]; for (i = 0; i < n; i++) { for (j = 0; j < m; j++) std::cin >> plan[i][j]; } for (i = 0; i < n; i++) { for (j...
2
#include<iostream> #include<algorithm> #include<vector> #include<queue> #define lol(i,n) for(int i=0;i<n;i++) #define mod 1000000007 typedef long long ll; using namespace std; pair<ll,ll> a[100010]; ll cls[100010]; int main(){ int n;ll t; cin>>t>>n; ll sum=0;cls[0]=0; a[0]=make_pair(-1,-1); for(int i=1;i<=n;i++){...
0
#include <bits/stdc++.h> using namespace std; int main(){ int n,m; cin>>n>>m; if(n%2){ for(int i=1,j=2*m;m>0&&i<j;i++,j--){ cout<<i<<" "<<j<<endl; m--; } }else{ for(int i=1,j=n/2;m>0&&i<j;i++,j--){ cout<<i<<" "<<j<<endl; m--; } for(int i=n/2+1,j=n-1;m>0&&i<j;i++,j--){...
0
#include <bits/stdc++.h> using namespace std; vector<int> cost; int n; pair<int, int> a[200001]; int main() { int i = 0; for (;;) { int tmp = i * i; cost.push_back(tmp); if (tmp > 1000000000) break; ++i; } scanf("%d", &n); for (int i = 0; i < n; ++i) { int x; scanf("%d", &x); int t...
5
#include <bits/stdc++.h> using namespace std; long long n, m, t1, t2, a[100005], b[100005]; set<long long> g[100005]; int main() { ios_base::sync_with_stdio(0), cin.tie(0); cin >> n >> m; for (long long i = 1; i <= m; ++i) { cin >> t1 >> t2; g[t1].insert(t2); g[t2].insert(t1); } for (long long i =...
4
#include <bits/stdc++.h> #pragma GCC optimize(3) using namespace std; const long long llINF = 9223372036854775807; const int INF = 2147483647; const int maxn = 3e5 + 7; long long a, b; long long ans = llINF; set<long long> s; int main(int argc, char const *argv[]) { cin >> a >> b; long long c = a + b; long long l...
6
#include <bits/stdc++.h> using namespace std; long n, k, m; long a[1010], b[1010]; int main() { scanf("%ld %ld", &n, &k); for (long i = 1; i <= n; i++) scanf("%ld", &b[i]); for (long i = n; i >= 1; i--) { m++; long dem = 0; for (long j = 1; j <= m; j++) { if (dem == b[i]) { for (long t =...
2
#include <bits/stdc++.h> using namespace std; long long int mod = 1e9 + 7; long long int mxm = 1e18; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int t; cin >> t; while (t--) { long long int n; cin >> n; long long int a[n], i; set<long long int> x; for (i = 0; i ...
3
#include <bits/stdc++.h> using namespace std; const int N = 100005; int n, Q; vector<int> g[N]; int in[N], out[N]; int T; int D[N]; int P[N][22]; void DFS(int k, int p) { in[k] = ++T; P[k][0] = p; D[k] = D[p] + 1; for (int i = 0; i < g[k].size(); i++) if (g[k][i] != p) DFS(g[k][i], k); out[k] = ++T; } int...
4
#include <bits/stdc++.h> using namespace std; long long n, m, i, j, u, v, l, k, used[100001], a[100001], w, ans = -1; vector<pair<long long, long long> > g[100001]; int main() { cin >> n >> m >> k; for (i = 0; i < m; i++) { scanf("%d%d%d", &u, &v, &l); g[u].push_back(make_pair(v, l)); g[v].push_back(mak...
2
#include <bits/stdc++.h> using namespace std; int n, m, i, j, k, ans; long long a[200005], d; int main() { scanf("%d", &n); for (i = 1; i <= n; ++i) scanf("%I64d", &a[i]); for (k = 1; k <= n;) { ++ans; for (i = k; a[i] == -1; ++i) ; for (j = i + 1; a[j] == -1; ++j) ; if (j > n) break; ...
4
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > g(200200); int n, d, h; int main() { cin >> n; cin >> d; cin >> h; if (n == 2) { if (h == d && d == 1) { cout << "1 2" << endl; return 0; } else { cout << -1 << endl; return 0; } } if (d > 2 * h || d ==...
2
#include <bits/stdc++.h> using namespace std; int i, j, k, n, m, mi, ro, t; int si[100010], L[100010], R[100010], id[100010], tr[100010 * 4], wei[100010]; pair<int, int> c[100010 * 4]; vector<int> root; vector<pair<int, int> > a[100010], b[100010]; long long an; void dfs(int x, int y) { int i, ma = 0; si[x] = 1; ...
4
#include <bits/stdc++.h> using namespace std; const int MAXN = 5e5 + 10; int n, m; int bs; int a[MAXN]; int cnt[MAXN]; struct Query { int l, r, id; bool operator<(const Query& b) const { int b1 = l / bs, b2 = b.l / bs; if (b1 != b2) return b1 < b2; else return (b1 & 1) ? r > b.r : r < b.r; ...
6
#include <bits/stdc++.h> using namespace std; const int M = 1e9 + 7; long long qpow(long long x, long long k) { return k == 0 ? 1 : 1ll * qpow(1ll * x * x % M, k >> 1) * (k & 1 ? x : 1) % M; } const int maxn = 1e3 + 5; int val, n; int findcol(int row) { int l = 1, h = n, col; while (l <= h) { int mid = (l + h...
5
#include <bits/stdc++.h> using namespace std; int32_t main() { long long int t; cin >> t; while (t--) { long long int n; cin >> n; vector<long long int> v(n); long long int ans = 0, c = 0; for (long long int i = 0; i < n; i++) cin >> v[i]; for (long long int i = 0; i < n; i++) { c++;...
1
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 2; long long inf = 1ll << 60; void solve() { long long n; cin >> n; long long x[n]; for (long long i = 0; i < n; i++) { cin >> x[i]; } long long ma = 0, ans = 0; for (long long i = 0; i < n; i++) { if (x[i] >= ma) { if (i and ...
3
#include <bits/stdc++.h> using namespace std; using pii = pair<long long, long long>; const long long MOD = 1e9 + 7; const long long INF = 1 << 29; const long long N = 1e6 + 10; const long long MOD1 = 1073741824; struct IOsetup { IOsetup() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nul...
1
#include <bits/stdc++.h> using namespace std; int n, m; pair<int, int> a[12], b[12]; set<int> the; set<int> ca[12], cb[12]; int main(void) { ios_base::sync_with_stdio(false); cin >> n >> m; for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; a[i] = make_pair(x, y); } for (int i = 0; i < m; i++)...
4
# include <iostream> # include <algorithm> # include <vector> # include <string> # include <set> # include <map> # include <cmath> # include <iomanip> # include <functional> # include <utility> # include <stack> # include <queue> # include <list> # include <tuple> # include <unordered_map> # include <numeric> # include...
0
#include <bits/stdc++.h> using namespace std; int main() { char b; cin >> b; cout << (b == 'A' ? 'T' : b == 'C' ? 'G' : b == 'G' ? 'C' : b == 'T' ? 'A' : ' '); }
0
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; using ll = long long; using ld = long double; using pi = pair<int, int>; using pl = pair<ll, ll>; using vi = vector<int>; using vl = vector<ll>; using vpi = vector<pi>; using si = set<int>; using sl = set<ll>; using qi = queue<int>; using ql = que...
2
#include<cstdio> #include<vector> using namespace std; int n; const int MAXN=1e5+5; vector<int>neigh[MAXN]; int cnt[MAXN],L[MAXN],P[MAXN]; void Traverse(int v){ cnt[v]=1; for(int i=0;i<neigh[v].size();i++){ int u=neigh[v][i]; if(P[v]==u)continue; L[u]=L[v]+1;P[u]=v; Traverse(u); cnt[v]+=cnt[u]; } } int mai...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 222222; char ss[maxn]; int cnt[33], tot, Q[33]; int main() { scanf("%s", ss + 1); int N = strlen(ss + 1); for (int i = 1; i <= N; ++i) ++cnt[ss[i] - 'a']; for (int i = 0; i < 26; ++i) if (cnt[i] & 1) Q[++tot] = i; int uuu = tot >> 1; for (in...
3
#include <bits/stdc++.h> using namespace std; template <typename T> T abs(T x) { return x > 0 ? x : -x; } template <typename T> T sqr(T x) { return x * x; } template <typename T> ostream &operator<<(ostream &s, const vector<T> &x) { s << "["; for (auto it : x) { s << it << ", "; } s << "]"; return s; ...
2
#include<iostream> #include<vector> #include<algorithm> #include<string> using namespace std; int main(){ long long x,k,d,s; cin>>x>>k>>d; x=abs(x); s=min(k,x/d); if((k-s)%2==0){ cout<<x-s*d<<endl; }else{ cout<<(1+s)*d-x<<endl; } }
0
#include <bits/stdc++.h> using namespace std; const int MAXN = 500000; const int MOD = int(1E9) + 7; struct mint { int x; mint(int _x = 0) : x(_x) {} friend mint operator+(mint a, mint b) { return a.x + b.x >= MOD ? a.x + b.x - MOD : a.x + b.x; } friend mint operator-(mint a, mint b) { return a.x - b....
6
#include <bits/stdc++.h> using namespace std; int main() { int tc; cin >> tc; while (tc--) { long long n, m; cin >> n >> m; long long cnt = n / m, tmp = 0, sum = 0; set<long long> st; vector<int> v; for (int i = 0; i < n; i++) { tmp += m; tmp %= 10; if (st.find(tmp) != st...
3
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> using namespace std; int a[1100]; bool b[1100000]; int main() { int n; cin>>n; memset(b,0,sizeof(b)); long long maxx=999999; for(int i=1;i<=n;i++) { cin>>a[i]; b[a[i]]=1; } int l=0; for(int i=1;i<=n;i++) { int x=a[...
0
#include <bits/stdc++.h> using namespace std; template <class C> void mini(C& a, C b) { a = min(a, b); } template <class C> void maxi(C& a, C b) { a = max(a, b); } const long long mod = 1e9 + 7; struct nodo { void upd(int val, int x, int y) { v = val; } nodo comb(nodo& izq, nodo& der) { v = max(izq.v, der.v...
6
#include <iostream> using namespace std; int main(void){ long q, h, s, d, n; cin >> q >> h >> s >> d >>n; if(2*q < h) h = 2*q; if(2*h < s) s = 2*h; if(2*s < d) d = 2*s; cout << (n/2)*d + (n%2)*s << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; #define all(x) (x).begin(),(x).end() #define YES() printf("YES\n") #define NO() printf("NO\n") #define isYES(x) printf("%s\n",(x) ? "YES" : "NO") #define Yes() printf("Yes\n") #define No() printf("No\n") #define isYes(x) printf("%s\n",(x) ? "Yes" : "No") #define isIn(x,y,h,...
0