code_file1
stringlengths
87
4k
code_file2
stringlengths
85
4k
#include <stdio.h> #include <algorithm> #include <set> #include <tuple> #include <queue> #include <vector> using namespace std; using ll = unsigned long long; using pii = pair<int, int>; int n, m, a[10000], b[10000], c[200], d[10000], v[200]; vector<pii> e[200]; void dfs(int x, int p) { if (v[x]) return; v[x] = 1;...
#include <bits/stdc++.h> #define SZ(X) ((int)(X).size()) #define ALL(X) (X).begin(), (X).end() #define REP(I, N) for (int I = 0; I < (N); ++I) #define REPP(I, A, B) for (int I = (A); I < (B); ++I) #define RI(X) scanf("%d", &(X)) #define RII(X, Y) scanf("%d%d", &(X), &(Y)) #define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y...
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define pb push_back #define mii map <int, int> #define mll map <ll, ll> #define pii pair <int, int> #define pll pair <ll, ll> #define vi vector <int> #define vd vector <double> #define vll vector <ll> #define fi first #define se second #define si set ...
#include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> #include <cmath> #include <vector> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <queue> #include <ctime> #include <cassert> #include <complex> #include <string> #include <cstring> #include <chrono> ...
#include<bits/stdc++.h> using namespace std; #define int long long mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int rnd(int l,int r){return l+rng()%(r-l+1);} #define forinc(a,b,c) for(int a=b, _c=c; a<=_c; ++a) #define fordec(a,b,c) for(int a=b, _c=c; a>=_c; --a) #define forv(a,b) for(auto &a:b)...
#include <bits/stdc++.h> using namespace std; int main() { int N; string s; cin >> N >> s; int cnt = 0, ans = 0; for(int i = 0; i<N; i++){ int a = 0, b = 0; for(int j = i; j<N; j++){ if(s[j] == 'A'){ a++; } else if(s[j] == 'T'){ a--; } else if(s[j] == 'C'){ b++; } else{ ...
#include <bits/stdc++.h> #define ff first #define ss second #define pb push_back #define eb emplace_back #define mp make_pair #define mt make_tuple #define pii pair<int, int> #define pll pair<long long,long long> #define vl vector<long long> #define vll vector<pll> #define vi vector<int> #define vii vector<pii> #define...
#include <bits/stdc++.h> using namespace std; #define pb push_back #define eb emplace_back #define x first #define y second #define FOR(i, m, n) for (ll i(m); i < n; i++) #define DWN(i, m, n) for (ll i(m); i >= n; i--) #define REP(i, n) FOR(i, 0, n) #define DW(i, n) DWN(i, n, 0) #define F(n) REP(i, n) #define FF(n) REP...
#include<bits/stdc++.h> #define lli unsigned long long int #define endl "\n" #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL); using namespace std; lli min(lli a,lli b) { if (a<b) { return a; } else { return b; } } lli max(lli a,lli b) { if ...
#include<iostream> #include<vector> #include<algorithm> #include<set> #include<map> #include<queue> #include<cmath> #include<iomanip> #include<cstring> #include<complex> #include<cstdio> #define initdp(a,b) for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=-1; #define fi first #define se second #define pb push_back #d...
#include <bits/stdc++.h> using namespace std; const int N = 2e3 + 5; typedef long long LL; LL const mod = 1e9 + 7; LL n, dp[N][2]; LL qmi(LL a, LL k, LL p) { LL res = 1 % p; // res记录答案, 模上p是为了防止k为0,p为1的特殊情况 while (k) { // 只要还有剩下位数 if (k & 1) res = (LL)res * a % p; // 判断...
/* Generated by powerful Codeforces Tool * You can download the binary file in here https://github.com/xalanq/cf-tool (Windows, macOS, Linux) * Author: alireza_kaviani * Time: 2020-12-05 16:43:07 **/ #include <bits/stdc++.h> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/assoc_container.hpp> using namespa...
#include <bits/stdc++.h> using namespace std; using ull = unsigned long long; using ll = long long; using ld = long double; const int mod = 1e9 + 7; const double pi = acos(-1.0); const int inf = INT_MAX; const int N = 50 + 5; int n; ll x, a[N], lim[N], dp[N][2], num_x[N]; ll recurse(int i, int c) { if (dp[i][c] !=...
#include <bits/stdc++.h> using namespace std; typedef long long int ll; int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int n; cin >> n; ll X; cin >> X; vector<ll> a(n); for(int i=0;i<n;i++){ cin >> a[i]; } vector<ll> x(n); for(int i=n-1;i>=0;i--){ x[i]=X/a[i]; X%=a[i]; } vector<ll> t(n); ...
// g++ -std=c++11 a.cpp #include<iostream> #include<vector> #include<string> #include<algorithm> #include<map> #include<set> #include<unordered_map> #include<utility> #include<cmath> #include<random> #include<cstring> #include<queue> #include<stack> #include<bitset> #include<cstdio> #include<sstream> #include<random> #...
#pragma region Macros #include <bits/stdc++.h> #define rep(i, n) for(int(i) = 0; (i) < (n); (i)++) #define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++) #define ALL(v) (v).begin(), (v).end() #define LLA(v) (v).rbegin(), (v).rend() #define SZ(v) (int)(v).size() #define INT(...) ...
#include <iostream> #include <algorithm> template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;} using namespace std; int main() { int a, b, x, y; cin >> a >> b >> x >> y; --a, --b; int res = x+y*abs(b-a); if(a>0) chmin(res, x+y*abs(b-(a-1))); if(a>b) chmin(res, x*((a-b)*2-1)); else c...
#include <iostream> #include <algorithm> #include <numeric> #include <vector> #include <string> #include <map> #include <set> #include <queue> #include <deque> #include <stack> #include <iomanip> #include <functional> #include <bitset> #include <limits> #include <cstdio> #include <cmath> #include <cassert> #include <ra...
// Author: wlzhouzhuan #include <bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define pii pair<int, int> #define pb push_back #define fir first #define sec second #define rep(i, l, r) for (int i = l; i <= r; i++) #define per(i, l, r) for (int i = l; i >= r; i--) #define mset(s...
#include <bits/stdc++.h> //#include <atcoder/all> using namespace std; //using namespace atcoder; using ll=long long; using ld=long double; using pll=pair<ll, ll>; //using mint = modint1000000007; #define rep(i,n) for (ll i=0; i<n; ++i) #define all(c) begin(c),end(c) #define PI acos(-1) #define oo 2e18 template<typenam...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int h, w; cin >> h >> w; vector<int> a(h * w); int mi = INT_MAX; for (int i = 0; i < h * w; i++) { cin >> a[i]; mi = min(mi, a[i]); } int ans = 0; for (int i ...
//デバッグ用オプション:-fsanitize=undefined,address //コンパイラ最適化 #pragma GCC optimize("Ofast") //インクルードなど #include <bits/stdc++.h> // #include <atcoder/all> using namespace std; // using namespace atcoder; typedef long long ll; using vint = vector<int>; using vll = vector<ll>; using vs = vector<string>; using vbool = vector<bo...
#include <bits/stdc++.h> using namespace std; int N, vis[10005]; int main () { #ifndef ONLINE_JUDGE freopen("cpp.in", "r", stdin); #endif cin >> N; if (N == 3) return puts("6 10 15") & 0; for (int i = 6; i <= 10000; i += 6) vis[i] = 1; for (int i = 10; i <= 10000; i += 10) vis[i] = 1; for (int i = 15; i <= 100...
#include <bits/stdc++.h> using namespace std; #define rep0(i,n) for(int (i) = 0; (i) < (n); ++(i)) #define pf(x) cout << (x) << endl #define all(x) (x).begin(),(x).end() template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b...
#include<bits/stdc++.h> using namespace std; #define int long long #define rep(i, n) for(int i = 0;i<(int)(n);i++) #define all(v) (v).begin(),(v).end() using ll = long long; using P = pair<int,int>; struct UnionFind { vector<int> par, size; UnionFind(int x) { par.resize(x); size.resize(x, 1); ...
// Problem : B - Values // Contest : AtCoder - AtCoder Regular Contest 106 // URL : https://atcoder.jp/contests/arc106/tasks/arc106_b // Memory Limit : 1024 MB // Time Limit : 2000 ms // Powered by CP Editor (https://github.com/cpeditor/cpeditor) #include <bits/stdc++.h> using namespace std; int N, M; int dsu[20000...
#include <bits/stdc++.h> #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define rep(i,n) for(int i=0;i<(int)(n);i++) #define drep(i,j,n) for(int i=0;i<(int)(n-1);i++)for(int j=i+1;j<(int)(n);j++) #define trep(i,j,k,n) for(int i=0;i<(int)(n-2);i++)for(int j=i+1;j<(int)(n-1);j++)for(int k=j+1;k<(i...
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace std; typedef long long ll; int a[105][105]; int s1[18]; int s2[18]; int v[105]; int main(){ int n,m; cin >> n >> m; int x,y; for(int i = 0; i < m; i++){ cin >> x >> y; a[x][y]+=1; } int t; cin >> t; for...
#pragma GCC optimize("Ofast") //#pragma GCC target ("sse4") #include<iostream> #include<string> #include<cstdio> #include<vector> #include<cmath> #include<algorithm> #include<functional> #include<iomanip> #include<queue> #include<ciso646> #include<random> #include<map> #include<set> #include<bitset> #include<stack> #i...
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define next Cry_For_theMoon using namespace std; const int MAXN=25,LIM=1<<19; int n,m,g[MAXN][MAXN]; int f[LIM],d[LIM],ans,vis[MAXN]; inline int Min(int a,int b){ return (a<b)?a:b; } int main(){ scanf("%d%d",&n,&m); ans=n; for(int i=1;i<=n...
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(int)(n);i++) #define chmin(x,y) x = min((x),(y)) #define chmax(x,y) x = max((x),(y)) #define popcount(x) __builtin_popcount(x) using namespace std; using ll = long long ; using P = pair<int,int> ; using pll = pair<long long,long long>; const int INF = 1e9; const ...
#include<bits/stdc++.h> using namespace std; const int MAX = 200010; const int64_t INF = 1e18; vector<vector<int>> G(MAX,vector<int>(0)); int64_t dp[MAX][2]; int main(){ int N; cin >> N; for(int i=0; i<N; i++){ int x, c; cin >> x >> c; G[c].push_back(x); } G[N+1].push_back(0); for(int i=0; i<MA...
#include<iostream> using namespace std; int main(){ int n,x=0; cin>>n>>x; char a[n+1]; cin>>a; for(int i=0;i<n;i++){ if(a[i]=='o'){ x++; }else if(a[i]=='x' && x!=0){ x--; } } cout<<x; return 0; }
#include <iostream> #include <math.h> #include <string> #include <vector> #include <algorithm> //#include <bits/stdc++.h> using namespace std; int main() { long long a, b, c; cin >> a >> b >> c; cout << 21 - (a + b + c); return 0; }
//HAR HAR MAHADEV //WHEN IT GETS HARDER REMEMBER WHY YOU STARTED💪 /*ヽ`、ヽ``、ヽ`ヽ`、、ヽ `ヽ 、ヽ`🌙`ヽヽ`ヽ、ヽ` ヽ`、ヽ``、ヽ 、``、 `、ヽ` 、` ヽ`ヽ、ヽ `、ヽ``、 ヽ、``、`、ヽ``、 、ヽヽ`、`、、ヽヽ、``、 、 ヽ`、 ヽ``、 ヽ`ヽ`、、ヽ `ヽ 、 🚶ヽ````ヽヽヽ`、、ヽ`、、ヽ*/ #include <bits/stdc++.h> #pragma GCC optimize ("O3") #pragma GCC target ("sse4") #include <bits/stdc++.h> #incl...
#include <iostream> #include <iomanip> #include <utility> #include <cmath> #include <random> #include <vector> #include <map> #include <set> #include <deque> #include <queue> #include <stack> #include <string> #include <algorithm> using namespace std; #define rep(i,n) for(int i = 0; i<n; ++i) #define REP(i,n) for(int ...
#include <cstdlib> #include <bits/stdc++.h> using namespace std; #define ll long long #define ii pair<int,int> #define vi vector<int> #define vii vector<ii> #define vc vector<char> #define vs vector<string> #define vd vector<double> #define vll vector<ll> #define vvi vector<vi> #define vvii vector<vii> #define vvc vect...
#include <bits/stdc++.h> #define f first #define s second #define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i) #define pb push_back #define all(s) begin(s), end(s) #define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define sz(s) int(s.size()) #define ENDL '\n' #define vv(type, name, h, ...) vec...
#include<bits/stdc++.h> #define ll long long int #define pii pair<int,int> #define pll pair<ll,ll> #define vpii vector< pii > #define vpll vector< pll > #define mpii map<int,int> #define mpll map<ll,ll> #define MOD 1000000007 #define all(v) v.begin(),v.end() #define s(v) v.size() #define test ll t;cin>>t;while(t--) #de...
#include <bits/stdc++.h> #define fi first #define se second #define mp make_pair #define pb push_back using namespace std; typedef long long ll; typedef pair<int,int> pi; const int mod=1000000007; inline int add(int x,int y) { return ((ll)x+y)%mod; } bool g[2005][2005]; int dp[2005][2005],lr[2005][2005],tb[2005][2005]...
#define _CRT_SECURE_NO_WARNINGS #define _SCL_SECURE_NO_WARNINGS #include <cstdio> #include <cstdlib> #include <cstring> #include <cassert> #include <iostream> #include <string> #include <vector> #include <list> #include <utility> #include <algorithm> #include <functional> #include <cmath> #include <stack> #include <que...
#include<bits/stdc++.h> #define int long long #define forr(i,l,r) for(int i=l;i<=r;i++) #define ffor(i,r,l) for(int i=r;i>=l;i--) using namespace std; signed main() { int a,b,c; cin>>a>>b>>c; cout<<a+b+c-min(a,min(b,c))<<endl; return 0; }
/** * Dont raise your voice, improve your argument. * --Desmond Tutu */ #include <bits/stdc++.h> using namespace std; const bool ready = [](){ ios_base::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(12); return true; }(); using ld=long double; const ld PI = acos((ld)-1); using ll= l...
#include <bits/stdc++.h> #include <random> #include <unordered_map> #include <unordered_set> using namespace std; #pragma GCC target("avx2") #pragma GCC optimize("O3,unroll-loops") using ll = long long; using ull = unsigned long long; #define pb push_back #define mp make_pair #define all(x) (x).begin(), (x).end() #def...
#include<bits/stdc++.h> // no of bits to store no 2e5 is 19 // 2e5 ka 5 times square root lene se 2 or 3 ke pass pahunch jate hai using namespace std; #define int long long #define mod 1000000007 #define MAX 1000000000 #define ff first #define ss ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n],b[n],c[n]; for(int i=0; i<n; i++) { cin >> a[i]; a[i]--; } for(int i=0; i<n; i++) { cin >> b[i]; b[i]--; } for(int i=0; i<n; i++) { cin >> c[i]; c[i]--; ...
#include <bits/stdc++.h> #define ll long long #define vi vector<int> #define vl vector<long long> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep_lr(i, f, n) for (int i = f; i < (int)(n); i++) #define maxe(v) *max_element(v.begin(),v.end()) #define mine(v) *min_element(v.begin(),v.end()) #define sorts(...
#include <iostream> #include <sstream> #include <iomanip> #include <algorithm> #include <functional> #include <iterator> #include <numeric> #include <cstdint> #include <cmath> #include <bitset> #include <string> #include <list> #include <vector> #include <stack> #include <queue> #include <set> #include <map> #include <...
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <functional> using namespace std; #define int long long #define double long double #define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define mod 1000000007 #define M2 1000000009 #define ...
#include <bits/stdc++.h> using namespace std; int main() { int64_t N; cin >> N; int64_t a, b, c; int64_t kai; int64_t ans = -1; if(N == 1) cout << 1 << endl; else { b = 0; kai = 1; while(true) { b++; kai *= 2; if(N < kai) break; a = N / kai; c = N - a...
#include<bits/stdc++.h> //#include <atcoder/all> #define rep(i,n)for(int i=0;(i)<(int)(n);i++) #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++) #define ALL(a) (a).begin(),(a).end() #define pb push_back #define fi first #define se second #define sz(x) ((int)x.size()) using namespace std; //using namespace atc...
#include<bits/stdc++.h> #define all(v) v.begin(), v.end() #define sz(x) (int)x.size() #define debug(x) cout << #x << ':' << x << endl; #define rep(i,n) for(long long i = 0; i < n ; i++) #define reps(i,n) for(long long i = 1; i <= n ; i++) #define make_unique(v...
#include<stdio.h> #include<iostream> #include<algorithm> #include<vector> using namespace std; int main() { int x, y, z; cin >> x >> y >> z; cout << (y * z - 1) / x << endl; }
//#include<bits/stdc++.h> #include<iostream> #include<string> #include<cmath> #include<cstdio> #include<cstring> #include<algorithm> #include<cctype> #include<vector> #include<map> #include<deque> #include<queue> using namespace std; #define re register #define inf 0x3f3f3f3f //#define inf 0x3f3f3f3f3f3f3f3f #define l...
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <utility> #include <tuple> #include <cstdint> #include <cstdio> #include <map> #include <queue> #include <set> #include <stack> #include <deque> #include <unordered_map> #include <unordered_set> #include <bitset> #include <c...
#include <bits/stdc++.h> using namespace std; int main(){ int a,b,Xcor,Xstep; cin >> a >> b >> Xcor >> Xstep; int Xupdown= min(2*Xcor, Xstep); int ans= (a <= b) ? Xupdown*(b-a) + Xcor : Xupdown*(a-b-1)+ Xcor; cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; int n,f[100001][10]; string s,x; int main(){ cin>>n; cin>>s>>x; f[n][0]=1; for(int i=n;i>=1;i--){ for(int j=0;j<7;j++){ bool a=f[i][(j*10)%7]; bool b=f[i][(j*10+(s[i-1]-'0'))%7]; if(x[i-1]=='T'){ f[i-1][j]=a|b; } else{ f[i-1][j]=a&b; } } } ...
#include <bits/stdc++.h> using namespace std; int main(){ char S,T; cin >> S; cin >> T; if(S=='Y'){ if(T=='a') cout << "A" << endl; if(T=='b') cout << "B" << endl; if(T=='c') cout << "C" << endl; }else{ cout << T << endl; } }
#include<cstdio> #include<cstring> #include<cmath> #include<cassert> #include<iostream> #include<iomanip> #include<map> #include<unordered_map> #include<set> #include<unordered_set> #include<vector> #include<algorithm> #include<string> #include<queue> using namespace std; #define DEBUG(x) cout<<#x<<"="<<x<<endl #define...
#include <bits/stdc++.h> using namespace std; //#include <atcoder/all> //using namespace atcoder; //using mint = modint1000000007; //using mint = modint998244353; template <typename T> bool chmax(T &u, const T z) { if (u < z) {u = z; return true;} else return false; } template <typename T> bool chmin(T &u, const T z) {...
#include <bits/stdc++.h> using Int = long long; // clang-format off using pii = std::pair<Int, Int>; #define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++) #define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__) #define RREP_(i, a_, b_, a, b, ...) for (Int i = Int(b) - 1, low...
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<vector> #include<cmath> #include<queue> #include<set> #include<map> #include<stack> #include<bitset> #include<climits> #include<complex> using namespace std; template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A,...
//dragon->emperor #include <bits/stdc++.h> using namespace std; /**********************************************************************************/ #define mod 1000000007 #define mod2 998244353 const double pi = acos(-1); #define inf 1e18+5 #define iinf 1e9+5 #define ll long long #define ld long double #define fl...
#include <bits/stdc++.h> using namespace std; #define PB push_back #define ll long long #define endl "\n" #define uwu \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define F0R(i, a, b) for (int i=a; i<(b); i++) #define FOR(i, a) for (int...
//Coded by Chirath Nirodha #include<bits/stdc++.h> #define F first #define S second #define PB push_back #define MP make_pair typedef long long ll; typedef long double ld; typedef unsigned long long ull; using namespace std; const ll mod=1e9+7; inline void io(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout....
#pragma GCC optimize("O3", "unroll-loops") #define fs first #define sc second #include <bits/stdc++.h> using namespace std; typedef pair<int, int> pii; const int maxn = 2e5 + 10; long long n, m, h[maxn], wi, pre1[maxn], pre2[maxn], pos, ans = 1e18; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cin >>...
#include <bits/stdc++.h> using namespace std; #define LL long long #define forn(i, n) for (int i = 0; i < n; i++) #define fori(i, a, b) for (int i = a; i <= b; i++) #define ff first #define ss second int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); LL n, m; cin >> n >> m; ...
#include <bits/stdc++.h> using namespace std; #define int long long signed main(){ cin.tie(nullptr)->sync_with_stdio(false); int n,k; cin >> n >> k; for(int i = 0; i<k; i++){ string s = to_string(n); sort(s.begin(),s.end()); int low = stoll(s); reverse(s.begin(),s.end()); int high = stoll(s); n = high-l...
#include<bits/stdc++.h> using namespace std; #define ll long long int #define ull unsigned long long int /**********************************************/ void solve(ll n, ll k) { ll x = n; while (k--) { string s = to_string(x); sort(s.begin(), s.end(), greater<char>()); ll g1 = stoll(s); reverse(s.begi...
#include <bits/stdc++.h> #define int long long int #define vi vector<int> #define vvi vector<vector<int>> #define u_m unordered_map<int,int> #define u_s unordered_set<int> #define pii pair<int,int> #define pb(a) push_back(a) #define for...
#include<bits/stdc++.h> using namespace std; int main(){ int a,b,c; cin>>a>>b>>c; if(a!=b && b!=c && c!=a){ cout<<"0"<<endl; } else{ // int sum=a+b+c; if(a==b) cout<<c<<endl; else if(b==c) cout<<a<<endl; else cout<<b<<endl; } return 0; }
#include <bits/stdc++.h> using namespace std; // #include <atcoder/all> // using namespace atcoder; #define debug(args...) (Debugger()), args class Debugger { public: Debugger(const std::string &_separator = " => ") : first(true), separator(_separator) {} template <typename ObjectType> Debugger &operat...
#include <bits/stdc++.h> using namespace std; #ifdef tabr #include "library/debug.cpp" #else #define debug(...) #endif int main() { ios::sync_with_stdio(false); cin.tie(0); int tt; cin >> tt; while (tt--) { int n; cin >> n; vector<string> s(3); vector<int> a(4); ...
#include "bits/stdc++.h" using namespace std; #define ll long long int main() { int t; cin >> t; while (t--) { int n; cin >> n; string s; cin >> s >> s >> s; for (int i = 0; i < n; i++) cout << "1"; for (int i = 0; i < n; i++) cout...
#include <bits/stdc++.h> //#include <atcoder/all> using namespace std; #define rep(i,x,y) for(ll i=(x);i<(y);i++) #define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--) #define all(x) (x).begin(),(x).end() #define itrout(x) for(int i=0;i<x.size();i++) {cout << x[i] << (i==x.size()-1 ? "\n" : " ");} #ifdef LOCAL #define de...
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define ndl cout << '\n'; #define yes cout<<"YES"<<'\n'; #define no cout << "NO" << '\n'; #define TC int ___T,case_n = 1;scanf("%d ",&___T);while(___T-->0) int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll x; cin>>x; i...
#include <iostream> #include <cstdio> #include <vector> #include <algorithm> using namespace std; const int maxN = 1e2 + 10; int n, a[maxN], k = 1e4; int read(); string s; int main(){ n = read(); n++; cin >> s; a[0] = read(); int t = 0; for(int i = 1; i < n; i++){ a[i] = read(); k = min(k, abs(a[i] - a[i - 1]))...
#include <iostream> #include <string> #include <complex> #include <cstdio> #include<functional> #include<cmath> #include<string> #include<ctime> #include<cstring> #include<algorithm> using namespace std; typedef complex<double> cp; #define ll long long #define sci(x) scanf("%d",&x) #define scl(x) scanf("%lld",&x) #def...
#include <bits/stdc++.h> using namespace std; typedef long long ll; //int:2*10**9 typedef long double ld; typedef pair<ll,ll> P; #define REP(i,n) for(ll i = 0; i<(ll)(n); i++) #define FOR(i,a,b) for(ll i=(a);i<=(b);i++) #define FORD(i,a,b) for(ll i=(a);i>=(b);i--) #define vec2(name,i,j,k) vector<vector<ll>> name(i,vect...
#include<bits/stdc++.h> using namespace std; #define debug(n) cerr << #n << ':' << n << endl; #define dline cerr << __LINE__ << endl; using ll = long long; template<class T, class U> using P = pair<T,U>; template<class T> using Heap = priority_queue<T>; template<class T> using heaP = priority_queue<T,vector<T>,gr...
#include<bits/stdc++.h> using namespace std; bool vis[17][17]; int h,w,a,b; int ans; void dfs(int x,int y,int a,int b) { if(x==h&&y==w+1) { ans++; return ; } if(y==w+1) { dfs(x+1,1,a,b); return ; } if(vis[x][y]) { dfs(x,y+1,a,b); return ; } if(a) { if(y!=w&&vis[x][y+1]==0) { vis[x][y]=1; ...
#include <bits/stdc++.h> using namespace std; #define repd(i,a,b) for (int i=(a);i<(b);i++) #define rep(i,n) repd(i,0,n) #define all(x) (x).begin(),(x).end() #define SIZE(x) ll(x.size()) template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> inline bool chm...
#include <bits/stdc++.h> using namespace std; #define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0) #define MAXX 300005 #define pb push_back #define fixx(n) fixed << setprecision(n) #define F first #define S second #define PI 3.14159265358979323846 #define ll long long int #define int ll #define do...
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> P; #define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0) #define p_map(map,it) do {cout << "{";for (auto (it) = map.begin(...
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define pb push_back #define mii map <int, int> #define mll map <ll, ll> #define pii pair <int, int> #define pll pair <ll, ll> #define vi vector <int> #define vd vector <double> #define vll vector <ll> #define fi first #define se second #define si set ...
#include<bits/stdc++.h> using namespace std; #define pb emplace_back #define st first #define nd second typedef long long ll; typedef vector<int> vi; typedef pair<int,int> ii; typedef vector<ii> vii; typedef vector<vi> vvi; #define sz(a) int((a).size()) #define all(c) (c).begin(),(c).end() #define tr(c,i) for(type...
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define sz(v) int((v).size()) #define all(x) (x).begin(), (x).end() #define forn(i, n) for (int i = 1; i <= int(n); ++i) //출처: https://codeforces.com/blog/entry/68809 void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} void __print(long ...
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; int main(){ ll n, k; cin >> n >> k; vvl t(n, vl(n)); rep(i,n)rep(j,n) cin >> t[i][j]; ...
#ifdef LC #include "pch.h" #else #include <bits/stdc++.h> #endif using namespace std; using ll = long long; #define int ll #define all(x) x.begin(), x.end() #define x first #define y second #define mp make_pair #define mt make_tuple signed main() { #ifdef LC assert(freopen("input.txt", "r", stdin)); #endif ios...
#pragma GCC target("avx2") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> //#include <atcoder/all> using namespace std; //using namespace atcoder; #define DEBUG #ifdef DEBUG template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << '(' << ...
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define mp make_pair #define mt make_tuple #define eb emplace_back #define f first #define s second #define all(c) begin(c),end(c) using namespace std; using namespace __gnu_pbds; typedef long long int ll; typedef lo...
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> VI; typedef vector<long long> Vll; ll mm=1000000000;ll MM=mm+7; #define rep(i, n) for(int i=0;i<n;i++) #define PI 3.141592653589793 int main(){ ll a,b,c; cin >> a >> b >> c; ll x=a%10; if(x==0 || x==1|| x==5 ||...
// E - White Pawn #include <bits/stdc++.h> using namespace std; int main(){ int N, M; cin>>N>>M; int C = min(N, M), L = C*2 + 1; auto ixOk = [&](int y){ return 0 <= y && y < L; }; vector<pair<int,int>> D; while(M--){ int x, y; cin>>x>>y; y -= N - C; if(ixOk(y)) D.emplace_back(x, y); } sort(D.begin(), D....
#include<bits/stdc++.h> using namespace std; using ll = long long; #define F first #define S second int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll n, m; cin >> n >> m; map<ll, vector<ll>> mp; for(int i = 0; i < m; i++){ ll x, y; cin >> x >> y; mp[x].push_back(y); } ...
#include <bits/stdc++.h> using namespace std; int main(){ int H,W; cin >> H >> W; int block_min=101; int block_grid=0; int block_mins=0; vector<int> A(W); for(int i=0;i<H;i++){ for(int j=0;j<W;j++){ cin >> A[j]; int a=A[j]; if(a<block_min){ ...
#include <bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ...
#include <algorithm> #include <bitset> #include <cmath> #include <complex> #include <cstdio> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <sys/types.h> #include <unistd.h> #include <vector> #pragma region macros #define _overload(_1, ...
#include <bits/stdc++.h> // #include <atcoder/all> // #include "icld.cpp" using namespace std; using ll = long long int; using vi = vector<int>; using si = set<int>; using vll = vector<ll>; using vvi = vector<vector<int>>; using ss = string; using db = double; template<typename T> using minpq = priority_queue <T,vector...
#include <bits/stdc++.h> using namespace std; #define FREP(i,a,b) for(long long i=a;i<b;i++) #define REP(i,n) FREP(i,0,n) #define PB push_back #define ll long long #define MP make_pair #define mod 1000000007 #define endl "\n" #define vi vector<ll> #define si set<ll> #define mi map<ll,ll> #define bs binary_search #defi...
#include<bits/stdc++.h> using namespace std; using ll=long long; ll mod=1000000007; set<ll> enum_divisors(ll N){ set<ll> res; for(ll i=1;i*i<=N;i++){ if(N%i==0){ res.insert(i); res.insert(N/i); } } return res; } int main(){ ll N,count=0; cin >> N; const auto &P=e...
#include <bits/stdc++.h> using namespace std; using ll = long long int; const int MAX = (int)(1e5 + 5); const ll INF = (ll)(1e10 + 5); const int MAX_N = (int)(2e2 + 5); int n; int a[MAX_N]; int dp[MAX_N][200]; vector<vector<int>> candidates; int get_valid_modulo() { if (dp[n][0] >= 3) return 0; for (int i =...
#include <iostream> #include <iomanip> #include <sstream> #include <vector> #include <string> #include <set> #include <unordered_set> #include <map> #include <unordered_map> #include <stack> #include <queue> #include <deque> #include <algorithm> #include <functional> #include <iterator> #include <limits> #include <nume...
#include <bits/stdc++.h> #include <fstream> #define vi vector<int> #define tests int t; cin>>t; while(t--) #define ll long long #define vll vector<long long> #define srt(v) sort(v.begin(), v.end()) #define srtg(v) sort(v.begin(), v.end(), greater<int> ()) #define FOR(k, n) for(int k=0; k<n; k++) #define pb push_back #...
#include <iostream> #include <math.h> using namespace std; int main() { ios_base::sync_with_stdio(false);cin.tie(0); long long N,i,j,arr1[38]={0},arr2[38]={0},M=0; cin >> N; arr1[0] = 1; arr2[0] = 1; arr1[1] = 3; arr2[1] = 5; for(i=2;i<38;i++){ arr1[i] = arr1[i-1]*3; ar...
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; using ll = long long; // int64_t using ull = unsigned long long; using pii = pair<int,int>; #define rep(i,n) for(int i = 0; i < (n); ++i) #define rrep(i,n) for(int i = 1; i <= (n); ++i) #define drep(i,n) for(int i = (n)-1; i >= 0; --i) const ll INF ...
#include "cstdio" #include "cstring" #include "cctype" #include "queue" #define R register #define getchar() (_==__&&(__=(_=___)+fread(___,1,1<<16,stdin),_==__)?EOF:*_++) char ___[1<<16],*_=___,*__=___; const int big=100010; int n; long long ans,a[big]; std::priority_queue<int>q[2]; inline int read() { char c(getch...
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i = 0; i < n; i++) #define all(v) v.begin(), v.end() using ll = long long; const int inf = (int)1e9; const ll inf_ll = (ll)1e19; const int mod = 1000000007; const int mod2 = 998244353; int main(){ char s, t; cin >> s >> t; if(s == 'Y') cou...
/*@author Vipen Loka*/ #include <bits/stdc++.h> #define endl '\n' #define ff first #define ss second #define ll long long #define vi vector<int> #define vll vector<ll> #define vvi vector < vi > #define pii pair<int,int> #define pll pair<long long, long long> #define mod 1000000007 #define inf 1000000000000000001; #defi...
#include <iostream> #include <algorithm> #include <vector> #include <string> #include <utility> #include <set> #include <map> #include <cmath> #include <queue> #include <cstdio> #include <limits> #define rep(i,n) for(int i = 0; i < n; ++i) #define rep1(i,n) for(int i = 1; i <= n; ++i) using namespace std; template<clas...
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; typedef long long ll; int main() { ll N, M, K, A; cin >> N >> M >> K; vector<bool> start(N + 1, false); rep(i, K) { cin >> A; start[A] = true; } double L = 0, R = 1e20; vector...
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define MAXX 3000002 ll pre[3][MAXX]; ll dp[3][MAXX]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll N,K; cin>>N>>K; ll MAX_SUM = 3LL*N; for(ll j=1;j<=MAX_SUM;++j) { if(j <= N) dp[0][...
#include<bits/stdc++.h> typedef unsigned long long ull; typedef long long ll; #define rep(i,l,r) for(int i=l;i<=r;i++) #define nep(i,r,l) for(int i=r;i>=l;i--) void sc(int &x){scanf("%d",&x);} void sc(int &x,int &y){scanf("%d%d",&x,&y);} void sc(int &x,int &y,int &z){scanf("%d%d%d",&x,&y,&z);} void sc(ll &x){scanf("%ll...
#include <bits/stdc++.h> #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; using lint = long long; int main(void) { string S; cin >> S; string T1 = ""; string T2 = ""; int t = 1; for(int i = 0; i < S.size(); i++){ if(S[i] != 'R'){ if(t == 1){ ...
#include <bits/stdc++.h> using namespace std; int main() { string s, t = ""; cin >> s; int n = s.length(); bool flip = true; deque<char> deq; for (int i = 0; i < n; i++) { if (s[i] == 'R') { flip = !flip; } else { if (flip) { deq.emplace_f...
#include <bits/stdc++.h> // #include "icld.cpp" using namespace std; using ll = long long int; using pii = pair<int,int>; using vi = vector<int>; using vll = vector<ll>; using vvi = vector<vector<int>>; using ss = string; const int dx[4] = {1,0,-1,0}; const int dy[4] = {0,1,0,-1}; //#define pi 3.14159265358979 #define ...
#include<bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; #define rep(i,a,b) for(ll i=a;i<b;i++) #define nl cout<<endl #define pii pair<ll,ll> #define vi vector<ll> #define vii vector<pii> #define mi map<ll,ll> #define all(a) (a).begin(),(a).end() #define pb push_back #define ...
#pragma GCC optimize("O3") //#pragma GCC target("avx") #include <bits/stdc++.h> using namespace std; #define re return #define pb push_back #define all(x) (x).begin(), (x).end() #define make_unique(x) sort(all(x)),x.resize(unique(all(x))-x.begin()) #define fi first #define se second #define ss second.second #define sf ...
///Bismillahir Rahmanir Rahim #include<bits/stdc++.h> using namespace std; #define FAST ios::sync_with_stdio(0); cin.tie(0) #define int long long #define pb push_back #define pp pop_back #define mp make_pair #define pi 2*acos(0.0) #d...
#include<bits/stdc++.h> using namespace std; string s = "atcoder"; int main() { ios_base::sync_with_stdio(false); cin.tie(0); string a; int t,n,i,j; cin >> t; while(t--) { cin >> a; n = a.length(); if(a > s) cout << 0 << endl; else { for...
#include <iostream> #include <vector> using namespace std; vector <long long> x; long long gcd(long long a, long long b) { if (a == 0) return b; else return gcd(b % a, a); } int main() { long long primes[15] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47 }; int n; cin >> n; long long temp; long ...
/** * code generated by JHelper * More info: https://github.com/AlexeyDmitriev/JHelper * @author */ #include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) using ll = long long; using s = string; using P = pair<int, int>; template<class T>bool chmax(T &a, const T &b) { if (a <...
#include <iostream> using namespace std; int main() { int a,sum=0,dex=3; while(dex--) { cin >> a; if(a==1) { a=6; } else if(a==2) { a=5; } else if(a==3) { a=4; } else if(a==4) { a=3; } else if(a==5) { a=2; ...
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <stack> #include <queue> #include <cmath> #include <tuple> #include <cstdio> #include <bitset> #include <sstream> #include <iterator> #include <numeric> #include <map> #include <cstring> #include <set> #include <functional> #include <...
// E - Count Descendants #include <bits/stdc++.h> using namespace std; #define vec vector using vi = vec<int>; vec<vi> adj, T; vi L, R; int dfs(int d, int p, int t){ T[d].push_back(t); L[p] = t; for(int&c:adj[p]) t = dfs(d+1, c, t+1); R[p] = t+1; return t+1; } int f(int d, int t){ return lower_bound(T[d].begin...
/* #region header */ #pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; // types using ll = long long; using ull = unsigned long long; using ld = long double; typedef pair<ll, ll> Pl; typedef pair<int, int> Pi; typedef vector<ll> vl; typedef vector<int> vi; typedef vector<char> vc; template <t...
#include <iostream> #include <cstdint> using namespace std; int main() { int N, K, M; cin >> N >> K >> M; int64_t sum = 0; for (size_t i = 1; i < N; ++i) { int n; cin >> n; sum += n; } int64_t diff = (M * N) - sum; if (diff > K) { cout << -1 << endl; } else { cout << max(diff, stat...
#include<bits/stdc++.h> using namespace std; #define ll long long ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); } ll lcm(ll a,ll b) { return a/gcd(a,b)*b; } int main() { ll n; cin>>n; ll ans=1; for(int i=2;i<=n;i++) ans=lcm(ans,i); cout<<ans+1<<endl; }
#include <bits/stdc++.h> using namespace std; #define forn(i,n) for(int i=0;i<(int)(n);i++) #define si(c) ((int)(c).size()) #define forsn(i,s,n) for(int i = (int)(s); i<((int)n); i++) #define dforsn(i,s,n) for(int i = (int)(n)-1; i>=((int)s); i--) #define all(c) (c).begin(), (c).end() #define D(a) cerr << #a << "=" <...
#include<bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll,ll>pll; const int mod = 1e9 + 7; pair<int,int> find(vector<vector<int>>& grid){ for(int i = 0; i < grid.size(); i++){ for(int j ...
#include <sstream> #include <iostream> #include <string> #include <vector> #include <deque> #include <numeric> #include <algorithm> #include <iomanip> #include <map> #include <set> #include <list> #include <cassert> #include <cmath> #include <climits> #include <map> #include <queue> #include <functional> #include <cass...
#include <bits/stdc++.h> using namespace std; int main() { string S; cin >> S; bool reversed = false; deque<char> T; for (auto c : S) { if (c == 'R') { reversed = !reversed; continue; } if (reversed) { if (!T.empty() && T.front() == c) { T.pop_front(); ...
// Problem: D - Message from Aliens // Contest: AtCoder - ZONe Energy Programming Contest // URL: https://atcoder.jp/contests/zone2021/tasks/zone2021_d // Memory Limit: 1024 MB // Time Limit: 2000 ms #include <bits/stdc++.h> using namespace std; #define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #p...
#include<bits/stdc++.h> #define ll long long using namespace std; int read() { char c; int w=1; while((c=getchar())>'9'||c<'0')if(c=='-')w=-1; int ans=c-'0'; while((c=getchar())>='0'&&c<='9')ans=(ans<<1)+(ans<<3)+c-'0'; return ans*w; } int n,m; struct nod { int next,to; }e[1000005]; int cnt; int h[1000005]; void...
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for(int i = 0; i < (int)(n); ++i) #define FOR(i, a, b) for(int i = (int)(a); i <= (int)(b); ++i) #define FORR(i, a, b) for(int i = (int)(a); i >= (int)(b); --i) #define ALL(c) (c).begin(), (c).end() using ll = long long; using VI = vector<int>; using VL ...
#include <bits/stdc++.h> using namespace std; #define pb push_back #define ppb pop_back #define pf push_front #define ppf pop_front #define p push #define pp pop #define B begin() #define E end() #define rB rbegin() #define rE rend() #define Si size() #define C count() #define yes cout<<"Yes\n" #define no cout<<"No\...
/* Auth: Loxilante Date: 2021-02-13 20:18:37 Prog: B.cpp */ #define F_C #include <bits/extc++.h> #define rep(i, l, r) for(int i = l; i < r; i++) #define hrp(i, l, r) for(int i = l; i <= r; i++) #define rev(i, r, l) for(int i = r; i >= l; i--) #define ms(n, t) memset(n, t, sizeof(n)) #define pb push_back #define int...
#include<bits/stdc++.h> #define il inline #define db double const int N=105; int n,tot; char g[N][N]; bool ok[N]; db ans; il void dfs(int u) { ok[u]=1,tot++; int v; for (v=1; v<=n; v++) if (!ok[v]&&g[v][u]>48) dfs(v); } int main() { scanf("%d",&n); int i; for (i=1; i<=n; i++) scanf("%s",g[i]+1); for (i=1; i<...
#include<bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0); int n; cin >> n; int a[n]; map<int,int> m; for(int i=0;i<n;i++) { cin >> a[i]; m[a[i]]++; } long long ans=0; for(int i=0;i<n;i++) { ans+=(n-i-1)-(m[a[i]]-1); m[a[i]]--; } cout << a...
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define all(x) (x).begin(),(x).end() template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;} template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;} int dx[4]={0,1,0,-1}, dy[4]={1,0,...
#define LOCAL #ifdef LOCAL #define _GLIBCXX_DEBUG #endif #include <bits/stdc++.h> using namespace std; #define int long long #define rep(i,s,n) for (int i = (ll)s; i < (ll)n; i++) #define rrep(i,n,e) for (int i = (ll)n; i > (ll)e; i--) #define ll long long #define ld long double #define pb push_back #define eb emplace...
#include <bits/stdc++.h> using namespace std; int main() { #ifndef ONLINE_JUDGE freopen("tpl.txt","r",stdin); #endif int n; cin >> n; vector<int> vc; for(int i = 0; i < 1 << n; i++) { int tmp; cin >> tmp; vc.push_back(tmp); } int max_pos = max_element(vc.begin(),vc.end()) - vc.begin(...
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef double db; typedef pair <int, int> pin; const int N = 2e5 + 5; int n, ans, top = 0, stk[N]; char s[N]; template <typename T> inline void read(T &X) { char ch = 0; T op = 1; for (X = 0; ch > '9' || ch < '0'; ch = getchar()) i...
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll INF = 1001001001001001001; const int MOD = 1000000007; int main(){ int n;cin>>n; vector<ll> r; vector<ll> g; vector<ll> b; for(int i=0;i<2*n;i++) { ll a;char c;cin>>a>>c; if(c=='R') r.push_back(a); else if(c=='G') g.push...
#include <bits/stdc++.h> using namespace std; #define MOD 1000000007 #define int long long int #define popcount(x) __builtin_popcountll(x) #define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define sc second #define pb push_back #define fr first #define all(a) (a).begin(),(a).end() #define mem0(a) memse...
/*...................................................................* *............___..................___.....____...______......___....* *.../|....../...\........./|...../...\...|.............|..../...\...* *../.|...../.....\......./.|....|.....|..|.............|.../........* *....|....|.......|...../..|....|.....
#include<iostream> #include<cstdio> using namespace std; #define fo(i,a,b) for(int i=a;i<=b;++i) #define fod(i,a,b) for(int i=a;i>=b;--i) #define LL long long int n,m; LL ans=0; int main(){ scanf("%d%d",&n,&m); char s[30]; int sum=0; fo(i,1,n){ scanf("%s",s); int u=0; fo(j,1,m){ if(s[j-1]=='1')++u; } i...
//#define _GLIBCXX_DEBUG #include <bits/stdc++.h> #include <algorithm> #define rep(i,n) for(int i=0;i<(n);++i) #define all(a) (a).begin(),(a).end() using namespace std; //using Graph = vector<vector<int>>; typedef long long ll; using Graph = vector<vector<pair<ll,ll>>>; const int mod =1e+9+7; const int dy[4]={0,1,0,-1...
#include <iostream> #include <cstring> #include <cstdio> #define LL long long #define maxn 210005 using namespace std; int n,a[maxn]; bool vis[maxn]; int main() { memset(vis,0,sizeof(vis)); scanf("%d",&n); for (int i=0;i<n;i++) scanf("%d",&a[i]); int now=0; for (int i=0;i<n;i++) { vis...
#include<bits/stdc++.h> using namespace std; int main() { int A, B, C; cin >> A >> B >> C; cout << ( A + B + C - min( { A, B, C } ) ) << endl; return 0; }
// Created by Pratik // NIT PATNA #include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; using namespace std; #define M 1000000007 #define pi 3.14159265358979323846 #define ll ...
// a(i) a(i+1) // a(i+1)+1 a(i)-1 // // a(i) + i // // A = 8 5 4 7 4 5 // A(i) + i = 8 6 6 10 8 10 // B(i) + i = 10 6 8 10 8 6 // // B = 10 5 6 7 4 1 #include "bits/stdc++.h" #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; ...
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn=2e5+5; int n,a[maxn],b[maxn]; ll sum1,sum2; int tot,head[maxn],pos[maxn]; unordered_map<int,int>mapp; vector<int>qwq[maxn],Tmp; int main() { scanf("%d",&n); for(int i=1;i<=n;++i) scanf("%d",&a[i]),sum1+=a[i]; for(int i=1;i<=n;++i) sca...
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main(){ int N; cin>>N; vector<ll>A(N+1,0); for (int i=1;i<A.size();i++) cin>>A.at(i); vector<ll>p(N+1,0); vector<ll>q(N+1,0); for (int i=0;i<A.size()-1;i++){ p.at(i+1)=p.at(i)+A.at(i+1); q.at(i+1)=q.at(i)>p.at(i+1)?q.at...
/* *author:DJ *CODE GIVEN ABOVE ;) */ #pragma GCC optimize "trapv" #pragma GCC optimize("O3") #include <bits/stdc++.h> #define sq(a) a*a const double pi = 2 * acos(0.0) ; using namespace std ; using ll = long long ; template<typename... T> void read(T&... args){ ((cin >> args),...) ; } int main(){ #ifdef LOCA...
#include<bits/stdc++.h> using namespace std; #define ll long long #define pii pair<int,int> string s; bool ch1,ch2; int main(){ cin>>s; ch1=true; ch2=true; for(int i = 0;i < s.size();i+=2){ if(s[i] >='a' && s[i] <= 'z') continue; else{ ch1=false; break; } } for(int i = 1;i < s.size();i+=2){ if(...
#include<bits/stdc++.h> #define endl '\n' using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin>>n; cout<<n-1<<endl; }
// Problem: B - Gentle Pairs // Contest: AtCoder - AtCoder Beginner Contest 187 // URL: https://atcoder.jp/contests/abc187/tasks/abc187_b // Memory Limit: 1024 MB // Time Limit: 2000 ms // Powered by CP Editor (https://github.com/cpeditor/cpeditor) #include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> usin...
//git pull --rebase origin master #include<bits/stdc++.h> using namespace std; #define gc getchar_unlocked #define fo(i,n) for(int i=0;i<n;i++) #define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1) #define ll long long #define si(x) scanf("%d",&x) #define sl(x) scanf("%lld",&x) #define ss(s) scanf("%s",s) #define pi(x) ...
#include <stdio.h> #include <iostream> #include <vector> // #include <bits/stdc++.h> #include <queue> #include <algorithm> #include <string> #include <iomanip> #include <cmath> using namespace std; typedef long long ll; #define rep(i,k,n) for(ll i=k; i<(ll)(n); i++) #define Q 1000000007 ll max(vector<ll> a) { re...
/*It is better to taste failure than to regret*/ #include <algorithm> #include <bitset> #include <cassert> #include <chrono> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <c...
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) typedef long long ll; typedef pair<ll, ll> P; typedef vector<int> vi; typedef vector<ll> vl; // input int N; vi A; void input() { cin >> N; A = vi(N); rep(i, N) cin >> A[i]; } int main() { input(); ...
//{{{ #include<algorithm> #include<cmath> #include<deque> #include<fstream> #include<iomanip> #include<iostream> #include<map> #include<numeric> #include<queue> #include<random> #include<set> #include<sstream> #include<sys/time.h> #include<unordered_map> #include<unordered_set> #include<vector> using ll = long long; en...
#include<bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<b;i++) #define rrep(i,a,b) for(int i=a;i>=b;i--) #define fore(i,a) for(auto &i:a) #define all(x) (x).begin(),(x).end() //#pragma GCC optimize ("-O3") using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } typedef long ...
#include<bits/stdc++.h> using namespace std; #define int long long #define double long double #define endl '\n' #define pb push_back #define pob pop_back #define pii pair<int,int> #define mod 1000000007 // #define mod 1000000009 // #define mod 163577857 // #define mod 998244353 #define rep(i,n) for (int i = 0; i < n; i...
#include <bits/stdc++.h> #define F first #define S second #define MP make_pair #define pb push_back #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define LCM(a, b) (a) / __gcd((a), (b)) * (b) #define log_2(a) (log((a)) / log(2)) #define ln '\n' using namespace std; using LL = long long; using...
#include<cstdio> #define F(i,l,r) for(int i=l,i##_end=r;i<i##_end;++i) using namespace std; const int N=1005,INF=0x3fffffff; template<typename T>void read(T &x) { bool neg=false; unsigned char c=getchar(); for(;(c^48)>9;c=getchar())if(c=='-')neg=true; for(x=0;(c^48)<10;c=getchar())x=(x<<3)+(x<<1)+(c^48); if(neg)x=...
#include <bits/stdc++.h> using namespace std; int main(){ char a, b, c; cin >> a >> b >> c; if(a == b && b == c)cout << "Won"; else cout << "Lost"; }
#include<iostream> #include<string> #include<vector> #include<set> #include<iomanip> #include<algorithm> #include<cmath> #include<bitset> #include<queue> #include<stack> #include<utility> #include<map> using namespace std; typedef long long ll; typedef long double lb; typedef vector<int> vi; typedef vector<ll> vl; ty...
#include <bits/stdc++.h> using namespace std; //using int = long long int; using ll = long long int; using pii = pair < int, int >; #define ff first #define ss second #define endl '\n' #define pb push_back #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define rep(i, j, n) for(int i = j; i...
#include <bits/stdc++.h> using namespace std; int main() { int A, B, C; cin >> A >> B >> C; if( A*A + B*B < C*C ) cout << "Yes"; else cout << "No"; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define PI 3.14159265 template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } //mod Inverse long long modInverse(long long a, long long m) //m and a...
#define _USE_MATH_DEFINES #include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <ctime> #include <complex> #include <deque> #include <iostream> #include <list> #include <map> #include <set> #include <stack> #include <string> #include <tuple> #include <vector> #include <queue> #define INF...
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int, int>; int main() { char S, T; cin >> S >> T; if(S=='Y'){ char s = toupper(T); cout <<s<< endl; }else{ cout << T << endl; } }
#include <bits/stdc++.h> #if __has_include(<atcoder/all>) #include <atcoder/all> using namespace atcoder; #endif using namespace std; using ll = long long; struct Edge { ll to; ll cost; }; using Graph = vector<vector<Edge>>; using P = pair<ll, ll>; #define mp make_pair #define REP(i, n) for (int i = 0; i < (n);...
#include <bits/stdc++.h> using namespace std; using ll = long long; using PII = pair<ll, ll>; #define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(x) x.begin(), x.end() #define POPCOUNT(x) __builtin_popcount(x) template <typename T> void chmin(T &a, const T &b) { a = min(...
#include<bits/stdc++.h> #define llinf 4154118101919364364 using namespace std; long long n,m; long long w[32],l[131072],v[131072]; long long res=llinf; long long sigw[1024]={0}; map<long long,long long> mp; long long find(long long wei){ if(mp[wei]!=-1){return mp[wei];} long long d=0; for(int i=0;i<m;i++){ ...
#include <bits/stdc++.h> #define mod 1000000007 #define fast_io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define vi vector<int> #define vl vector<ll> #define REP(s, e) for (auto i = s; i <= e; i++) #define show(s) cout<<s<<" " #define MAXI 2147483647 #define MAXL 9223372036854775807 #define FOR(a,b) for (ll i = a...
#include <bits/stdc++.h> using namespace std; #define int long long #define deb(x) cout <<"\n"<< (#x) << " = " << (x) << "\n" using pi = pair<int,int>; using vi = vector<int>; using vb = vector<bool>; using vpi = vector<pi>; using vvi = vector<vi> ; #define mp make_pair #define f first #define s second #define sz(x) (i...
#include <iostream> // cout, endl, cin #include <string> // string, to_string, stoi #include <vector> // vector #include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound #include <utility> // pair, make_pair #include <tuple> // tuple, make_tuple #include <cstdint> // int64_t, int*_t #include <cstd...
#include <bits/stdc++.h> using namespace std; typedef long long i64; typedef unsigned long long ui64; typedef vector<i64> vi; typedef vector<vi> vvi; typedef pair<i64, i64> pi; #define pb push_back #define sz(a) i64((a).size()) #define all(c) (c).begin(), (c).end() #define REP(s, e, i) for(i=(s); i < (e); ++i) inlin...
#include <iostream> #include <string> #include <math.h> using namespace std; typedef long long llong; int main() { string s; llong sum = 0; llong i = 0; cin >> s; int n = s.length() - 1; for (i = 0; i <= n - 1; i++) { sum += (llong)((pow(10, i + 1) - pow(10, i)) * (i / 3)); } ...
#include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <iostream> #include <algorithm> #include <vector> #include <set> #include <map> #include <stack> #include <queue> #define rep(i,l,r) for(int i=(l);i<=(r);++i) #define per(i,r,l) for(int i=(r);i>=(l);--i) using namespace std; typedef long ...
#include<bits/stdc++.h> #define ll long long using namespace std; int main() { ll H,W; cin>>H>>W; char mat[H+1][W+1]; for(ll i=0;i<H;i++) { for(ll j=0;j<W;j++) { cin>>mat[i][j]; } } ll count=0; for(ll i=1;i<H-1;i++) { for(ll j=1;j<W-1;j++) { if(mat[i][j]=='#') { if(mat[i][j-1]=='#') { if(m...
#include <bits/stdc++.h> using namespace std; #define endl ("\n") #define int long long #define pb push_back #define mp make_pair #define ff first #define ss second #define all(c) c.begin(), c.end() #define rep(i,n) for(int i=0;i<n;i++) #define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);...
#include<bits/stdc++.h> #define rg register #define fp( i , x , y ) for( rg int i=(x); i<=(y); ++i ) #define fq( i , x , y ) for( rg int i=(y); i>=(x); --i ) #define i60 long long using namespace std ; const int N = 2e5+10 , skc = 998244353 ; int pre[N] , deg[N] , n , pi[N] ; queue <int> q ; bool is[N] ; int...
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> P; #define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++) #define frep(i,m,n) for(ll (i)=(m); (i)<=(ll)(n); (i)++) #define rrep(i,n) for(ll (i)=(n)-1; (i)>-1; (i)--) #define frrep(i,m,n) for(ll (i)=(n); (i)>(ll)(m); (i)--) #define A...
#include <bits/stdc++.h> #define MOD 1000000007 #define PI (2*acos(0.0)) #define eps 1e-9 #define ff first #define ss second #define pb push_back #define endl '\n' #define fu cout << "lol" << endl; #define precision(n) cout << fixed << setprecision(n); #define debug(x) cout << (#x) << " is " << (x) << endl; #define p...
#include<bits/stdc++.h> using namespace std; #define ll long long #define fo(i,a,b) for(int i=a; i<b; i++) #define vi vector<int> #define vii vector<int,int> #define pi pair<int,int> #define F first #define S second #define PB push_back #define MP make_pair #define FASTIO ios::sync_with_stdio(0),cin.tie(0),cout.tie(0...
#include<bits/stdc++.h> // #include<atcoder/all> using namespace std; // using namespace atcoder; using lint = long long; using ulint = unsigned long long; template<class T>using graph = vector<vector<T>>; #define endl '\n' int const INF = 1<<30; lint const INF64 = 1LL<<61; lint const mod = 1e9+7; //long const mod = 99...
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pint; typedef pair<ll,ll> pll; typedef vector<int> vint; typedef vector<ll> vll; typedef vector<string> vstr; typedef vector<pint> vpint; typedef vector<pll> vpll; #define vint2(v,n,m,init) vector<vector<int>> v(...
/*Be patient && calm! All our dreams can come true, if we have the courage to pursue them. I fear not the man who has practiced 10,000 kicks once, but I fear the man who has practiced one kick 10,000 times. Do not pray for an easy life, pray for the strength to endure a difficult one. When something is important enough...
#include <iostream> #include <bits/stdc++.h> #define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL) #define mod 1000000007 #define ll long long #define pb push_back #define mp make_pair #define gcd __gcd #define F first #define S second #define PI 3.14159265358979323 using namespace std; vecto...
#include <bits/stdc++.h> using namespace std; #define int long long int const double pi = 3.14159265358979; const int inf = 1e13; #define pii pair<int,int> #define endl "\n" #define dtor(deg) (((deg)/360)*2*pi) #define all(a) a.begin(),a.end() #define overload(_1,_2,_3,_4,name,...) name #define _rep1(n) for(int i = 0; ...
#include<iostream> #include<math.h> #include<vector> #include<algorithm> #include<string> #include<map> #define rep(i,n) for(int i=0;i<(n);i++) bool is_prime(int x){ if(x<=1) return false; for(int i=2;i*i<x;i++){ if(x%i==0) return false;} return true;} template<class T>void chmin(T& a,T b){ if(a>b){ ...
#include <bits/stdc++.h> #define pb push_back typedef long long ll; using namespace std; int solve(int n){ if (n == 0) return 0; vector <int> digits; while (n){ digits.pb(n % 10); n /= 10; } sort(digits.begin(), digits.end()); int small = 0; int i = 0; n = digits.size(); while (!digits[i] and i < n) ++...
//xtwakioi! xtwddYnoi(双重含义)! #include <bits/stdc++.h> #define ri register #define int long long #define E (n+1) #define mk make_pair using namespace std; inline int read() { int s=0, w=1; ri char ch=getchar(); while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); } while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+...
#include<bits/stdc++.h> using namespace std; template <typename T> inline void read(T &x){ x=0;char ch=getchar();bool f=false; while(!isdigit(ch)){if(ch=='-'){f=true;}ch=getchar();} while(isdigit(ch)){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();} x=f?-x:x; return ; } template <typename T> inline void write(T x){ if(x<0)...
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> #ifdef local #define safe cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n" #define pary(a...) danb(#a, a) #define debug(a...) qqbx(#a, a) template <typename ...T> void qqbx(const char *s, T ...a) { int cnt = sizeof...(T); ((std::cerr << "\033[1;32m(...
#include<bits/stdc++.h> using namespace std; const int N=2e5+11; typedef pair<int,int> PII; struct q{ int x,y,num; }a[N],c[8]; struct w{ int x,y,num; }b[N]; int st[8],number[200]; unordered_map<int,int>m; bool cmp1( q a, q b) { return a.x<b.x; } bool cmp2( w a, w b) { return a.y<b.y; } int main() { ...
//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector") #include <bits/stdc++.h> #include<set> #include <array> using namespace std; #define ll long long #define endl '\n' #define mod 1000000007 #define pb push_back #define ff first #define ss second #define con continue #define ub upper_bound #define lb lower_...