code_file1
stringlengths
87
4k
code_file2
stringlengths
82
4k
#include<iostream> #include<cstring> #include<set> using namespace std; int n; string ss; set<string> s; int main() { cin>>n; for(int i=0;i<n;i++){ cin>>ss; if(ss[0]=='!'){ string t=ss; t.erase(t.begin()); if(s.count(t)){ cout<<t; return 0; ...
#include <bits/stdc++.h> using namespace std; #define int long long #define REP(i, n) FOR(i, 0, n) #define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i) #define ALL(obj) (obj).begin(), (obj).end() #define ALLR(obj) (obj).rbegin(), (obj).rend() #define CEIL(a, b) ((a - 1) / b + 1) void solve() { i...
#include <bits/stdc++.h> using namespace std; using ll = long long; int main () { ll p, q, r; ll inf = 1e8 + 7; inf = inf * inf; p = -inf; q = inf; r = 0; int N; cin >> N; for (int i = 0; i < N; i ++) { ll a, t; cin >> a >> t; ll al, bt, gm; if (t == 1) { gm = a; al = -inf;...
#include <bits/stdc++.h> typedef long long ll; typedef long double ld; #define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define PRECISION cout << fixed << setprecision(20); using namespace std; const int mod = 998244353; struct Mint { ll v; explicit operator ll() const { return ...
#include <algorithm> #include <cctype> #include <cmath> #include <cstring> #include <iostream> #include <sstream> #include <numeric> #include <map> #include <set> #include <queue> #include <vector> using namespace std; typedef long long LL; typedef long double LD; typedef pair<LL, LL> II; typedef pair<LL, II> III; ty...
#include <bits/stdc++.h> #include <iostream> using namespace std; #define ll long long #define ld long double #define mp make_pair #define pb push_back #define fo(i,n) for(ll i=0;i<n;i++) #define fo1(i,n) for(ll i=1;i<=n;i++) #define loop(i,a,b)for(ll i=a;i<=b;i++) #define loopr(i,a,b)for(ll i=b;i>=a;i--) #define vll v...
#include <bits/stdc++.h> using namespace std; using ll = long long; using vl = vector<ll>; using vvl = vector<vl>; const ll MAX = 1000000000000000000LL; const ll md = 998244353; #define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL) ll pw(ll a, ll n) { ll result = 1; while (n) { if (n&1) result = (result...
// Problem: D - Powers // Contest: AtCoder - AtCoder Regular Contest 106 // URL: https://atcoder.jp/contests/arc106/tasks/arc106_d // Memory Limit: 1024 MB // Time Limit: 3000 ms // Powered by CP Editor (https://github.com/cpeditor/cpeditor) #define _CRT_SECURE_NO_WARNINGS #include <bits/stdc++.h> using namespace std;...
#pragma comment(linker, "/STACK:128777216") #pragma GCC optimize("fast-maths") #pragma GCC optimize("unroll-loops") #pragma GCC optimize("no-stack-protector") #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma,tune=native") #define _USE_MATH_DEFINES #define _CRT_SECUR...
#pragma GCC optimize("Ofast") #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> // ...
#include<bits/stdc++.h> using namespace std; #define mp make_pair #define fi first #define se second #define pb push_back #define pf push_front #define ppb pop_back #define ppf pop_front #define sz(v) (v).size() #define all(v) (v).begin(),(v).end() #define REP(i,a,b) for(int (i)=(a);(i)<(b);(i)++) #define rep(i,a,b) fo...
#include <bits/stdc++.h> using namespace std; int main() { int N, ret = 0; cin >> N; vector<int> A(N); for (int i = 0; i < N; i++) cin >> A[i]; int m = 0; for (int i = 0; i < N; i++) { m = A[i]; for (int j = i; j < N; j++) { m = min(m, A[j]); ret = max(ret, m * (j - i + 1)); } } ...
#include <bits/stdc++.h> //#include <atcoder/all> #define rep(i, a) for (int i = (int)0; i < (int)a; ++i) #define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i) #define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i) #define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i) #define pb push_back #define eb emplac...
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, j, k) for(int i = j; i < k; i++) #define print(x) cout << x #define newline cout << endl #define space cout << ' ' #define INF 1000000000007 using namespace std; using ll = long long; using vi = vector<int>; using vl = vector<...
#include<bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; pair<int,int> points[n]; for(int i=0;i<n;i++){ cin>>points[i].first>>points[i].second; } int freq=0; for(int i=0;i<n;i++){ int j=n-1; while(j>i){ float a=(points[j].second)-(poi...
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (int)(n); ++i) int main() { int n; cin >> n; ll ans = 0; rep(i, n) { int a, b; cin >> a >> b; ans += (ll)(a + b) * (b - a + 1) / 2; } cout << ans << endl; return 0; }
#ifdef LOCAL //#define _GLIBCXX_DEBUG #endif //#pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> P; typedef pair<int, int> Pi; typedef vector<ll> Vec...
#include<iostream> #include<algorithm> #include<string> #include<map> #include<iomanip> #include<vector> #include<queue> //#include<atcoder/segtree> #define rep(i, n) for(int i=0; i<n; i++) using namespace std; typedef long long ll; using P = pair<int,int>; using T = tuple<int,int,int>; const int INF = 1e9; //using nam...
#include<bits/stdc++.h> #define ll long long #define fi first #define se second using namespace std; const int N = 2e5 + 5; int mod = 998244353; int main(){ ios::sync_with_stdio(0), cin.tie(0); int n; cin >> n; n *= 2; int a[n], tag[n]; vector<pair<int, int>> v; for (int i = 0; i < n; i++) c...
#include<iostream> #include<algorithm> #include<vector> #include<queue> #include<stack> #include<string> #include<map> #include<set> #include<tuple> #include<cmath> #include<iomanip> using namespace std; typedef long long ll; typedef vector<ll> v; typedef vector<vector<ll>> vv; #define MOD 1000000007 #define INF 10...
#include<bits/stdc++.h> #define ll long long int #define mk make_pair #define pb push_back #define INF (ll)1e18 #define pii pair<ll,ll> #define mod 998244353 #define f(i,a,b) for(ll i=a;i<b;i++) #define fb(i,a,b) for(ll i=a;i>b;i--) #define ff first #define ss second #define srt(v) if(!v.empty())sort(v.begin(),v.end()...
// Umang_US #include<bits/stdc++.h> #define ll long long int #define ld long double #define pb push_back #define pob pop_back #define vi vector<ll> #define mp make_pair #define sz size() #define rep1(i,n) for(ll i=1;i<=n;i++) #define rep(i,n) for(ll i=0;i<n;i++) #define fast ios::sync_with_stdio(0);cin.tie(0);...
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; #define MOD ll(998244353) #define all(x) (x).begin(),(x).end() #define dbg(x) cerr<<#x<<": "<<x<<endl int main(){ ll h, w; cin >> h >> w; vector<vector<ll>> board(h, vector<ll>(w)); ...
#include<iostream> #include<algorithm> using namespace std; int H,W; string A[2000]; int dp[2000][2000]; main() { cin>>H>>W; for(int i=0;i<H;i++)cin>>A[i]; int ans; for(int i=H;i--;)for(int j=W;j--;) { int L=-1e9,R=-1e9; if(i<H-1) { L=-dp[i+1][j]; } if(j<W-1) { R=-dp[i][j+1]; } ans=dp[i][j]=m...
#include<bits/stdc++.h> using namespace std; int a1,a2,a3; int main(){ cin>>a1>>a2>>a3; if(a1>a2)swap(a1,a2); if(a1>a3)swap(a1,a3); if(a2>a3)swap(a2,a3); cout<<(a3-a2==a2-a1?"Yes":"No"); }
#include <math.h> #include <algorithm> #include <fstream> #include <iomanip> #include <iostream> #include <string> #include <vector> using namespace std; int main() { int a, b, x, y; cin >> a >> b >> x >> y; if (a == b) cout << x << endl; else if(a>b){ if (2 * x < y) cout << x * (2 * (a - b) - 1) ...
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll n,L=10000000000; string s,t; int main(void){ cin>>n>>s; for(int i=0;i<n;i++)t+="110"; if(s=="1")cout<<L*2<<endl; else if(n%3==1 && t.substr(0,n)==s)cout<<L-((n-1)/3)<<endl; else if(n%3==2 && t.substr(0,n)==s)cout<<L-((n-2)/3)<<en...
#include <iostream> #include <string> #include <algorithm> #include <vector> #include <queue> #include <utility> #include <tuple> #include <cmath> #include <numeric> #include <set> #include <map> #include <array> #include <complex> #include <iomanip> #include <cassert> #include <random> using ll = long long; using std:...
#include <bits/stdc++.h> using namespace std; using ll = long long; int main(){ int n; cin >> n; int ans = n*108; ans = ans/100; if(ans<206) cout << "Yay!" << endl; if(ans==206) cout << "so-so"<<endl; if(ans>206) cout << ":(" << endl; return 0; }
#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> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define ll long long #define pb push_back #define INF 9223372036854775807ll #define endl '\n' #define pii pair<ll int,ll int> #define vi vector<ll int> #define all...
#include <bits/stdc++.h> using namespace std; #define ll long long #define fr(i,j,k) for(int i=j;i<k;i++) #define f(n) fr(i,0,n) #define f1(n) fr(i,1,n+1) #define pb push_back #define F first #define S second #define all(x) x.begin(), x.end() const int mod = 1e9 + 7; const int maxn = 1e5+5; int l[maxn], r[maxn]; int p[...
#include <bits/stdc++.h> using namespace std; // #include <atcoder/all> // using namespace atcoder; typedef long long ll; typedef unsigned long long ull; typedef pair<ll,ll> pll; typedef pair<pll,ll> ppll; typedef pair<pll,pll> ppp; typedef vector<ll> vll; typedef vector<pll> vp; typedef priority_queue<pll,vp,greater<...
#include <bits/stdc++.h> using namespace std; int main() { long long N, Q; cin >> N >> Q; vector<long long> A(N); for (int i = 0; i < N; i++) cin >> A[i]; vector<pair<long long, long long>> vec; for (int i = 0; i < N; i++) { vec.emplace_back(A[i], i); } sort(vec.begin(), vec.end()); for (int i = 0; i < Q; ...
#include<bits/stdc++.h> using namespace std; int main() { int n; cin>>n; cout<<(1<<n)-1<<endl; for(int i=1;i<(1<<n);i++) { for(int j=0;j<(1<<n);j++) putchar('A'+(__builtin_popcount(i&j)&1)); puts(""); } return 0; }
//#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) 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; return 1; } return 0; } ...
#include<bits/stdc++.h> using namespace std; long long dp1[200010],dp2[200010],tr[200010],n,m,t,ans=0,vis[200010]; vector<long long>f[200010]; void change(long long x){ for(long long i=x;i<=m;i+=i&-i) tr[i]++; } long long ask(long long x){ long long s=0; for(long long i=x;i;i-=i&-i) s=s+tr[i]; r...
#include<iostream> #include<string> #include<vector> #include<set> #include<iomanip> #include<algorithm> #include<cmath> #include<bitset> #include<queue> #include<stack> #include<utility> #include<cstdlib> #include<cstdio> #include<map> #include<unordered_set> #include<unordered_map> #include<list> #include<tuple> usin...
#ifdef _LOCAL #include "local_include.hpp" #else #include <bits/stdc++.h> using namespace std; #endif #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; #define fto(i, s, e) for (int i = (s); i <= (e); ++i) #define fto1(i, s, e) for (int i = (s); i < (e); ++i) #define fdto(i, s, e) for (...
//sudo apt install bcmwl-kernel-source #include "bits/stdc++.h" using namespace std; typedef long long int ll; typedef long double ld; ll P=1e9+7; ll mmod=998244353; vector<ll> tenx(11); /*----------------------------------------------------------------------------------------------------------------------------*/...
#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 <iostream> #include <cmath> using namespace std; long long N, M; long long calc_expand_mod(long long n, long long b, long long m){ long long ans = 1; while (n > 0) { if ((n & 1) == 1) ans = (ans * b) % m; n >>= 1; b = (b * b) % m; } return ans; } int main(){ cin >>...
#include <bits/stdc++.h> #include <math.h> using namespace std; template<typename T> long long modpow(const T n,const T p,const T mod); template<typename T> long long modinv(const T n,const T mod); template<typename T> bool chmax(T &a,const T &b); template<typename T> bool chmin(T &a,const T &b); long long inf=10000...
#pragma GCC optimize ("O3") #pragma GCC target ("sse4") #include<stdio.h> #include<iostream> #include<vector> #include<algorithm> #include<string> #include<string.h> #include<queue> #ifdef LOCAL #define eprintf(...) fprintf(stderr, __VA_ARGS__) #else #define NDEBUG #define eprintf(...) do {} while (0) #endif #include<...
#include <bits/stdc++.h> using namespace std; int main(void) { int n, k; cin >> n >> k; int ans = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= k; j++) { ans += i * 100 + j; } } cout << ans << endl; return 0; }
#include<bits/stdc++.h> #define ll long long int using namespace std; #define mod 1000000007 int main(){ ll n,k; cin>>n>>k; cout<<100*k*(n*(n+1)/2)+n*k*(k+1)/2<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; // union by size + path having class UnionFind { public: vector <ll> par; // 各元の親を表す配列 vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化) // Constructor UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) { for (ll i = 0; i < sz_; ++i) par[i] = ...
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (lli i = a; i < b; i++) #define lli long long int #define ld long double #define all(v) v.begin(), v.end() #define hell 1000000000000000 #define pb push_back #define vi vector<lli> #define vip vector<pair<lli, lli>> #define F first #define S second ...
#include <iostream> #include <vector> #include <algorithm> using namespace std; typedef long long ll; typedef vector <ll> vl; typedef vector <vl> vvl; typedef vector <char> vc; typedef vector <vc> vvc; typedef vector <int> vi; typedef vector <vi> vvi; const ll MOD = 998244353; int mat[5001][5001]; ll dp[5001][5001]...
#include <bits/stdc++.h> using namespace std; #define ll long long #define rep(i, n) for (ll i = 0; i < n; ++i) #define rep_up(i, a, b) for (ll i = a; i < b; ++i) #define rep_down(i, a, b) for (ll i = a; i > b; --i) #define P pair<ll, ll> #define Graph vector<vector<ll>> #define fi first #define se second #define vvvl...
#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...
/** * author: otera **/ #include<bits/stdc++.h> using namespace std; #define int long long typedef long long ll; typedef long double ld; const int inf=1e9+7; const ll INF=1LL<<60; #define rep(i, n) for(int i = 0; i < n; ++ i) #define per(i,n) for(int i=n-1;i>=0;i--) #define Rep(i,sta,n) for(int i=sta;i<n;i++)...
/* Bismillahirrahmanirrahim */ /* Author : Jehian Norman Saviero (@Reiva5) */ #include <bits/stdc++.h> // MACROS SAMPAH #define Jehian using #define Norman namespace #define Saviero std Jehian Norman Saviero; // MACROS TYPE typedef long l; typedef long long ll; typedef unsigned long ul; typedef unsigned long long...
#include <bits/stdc++.h> using namespace std; int main() { int n, k, m; cin >> n >> k >> m; int s = 0; int A; for(int i = 0; i < n - 1; i++){ cin >> A; s += A; } int B = n*m - s; if(B > k){ cout << -1; } else if(B < 0){ cout << 0; } else{ cout << B; } }
#include<bits/stdc++.h> #define ll long long #define re register #define INF 2147483647 using namespace std; inline ll read() { ll f=1,x=0;char s=getchar(); while(s<'0'||s>'9') { if(s=='-') f=-1; s=getchar(); } while(s>='0'&&s<='9') { x=x*10+s-48; s=getchar(); } return f*x; } ll C[100][100]; int mai...
/* dont stick to an approach */ #include <iostream> #include <iomanip> #include <cmath> #include <string> #include <algorithm> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <unordered_map> #include <vector> #include <numeric> #include <cstdlib> #include <bitset> using namesp...
#include <bits/stdc++.h> using namespace std; #include <math.h> #include <iomanip> #include <cstdint> #include <string> #include <sstream> template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if ...
#pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2") #include <bits/stdc++.h> using namespace std; // #include <ext/pb_ds/assoc_container.hpp> // using namespace __gnu_pbds; // template <class c, class cmp = less<c> > using ordered_set = tree<c, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>; #...
#include <bits/stdc++.h> using namespace std; void printmat(const vector<vector<long long>>& mat) { for (auto row : mat) { for (int elem : row) cout << elem << ", "; cout << endl; } } void printv(const vector<int>& v) { for (int elem : v) cout << elem << " "; cout <<...
#include <bits/stdc++.h> #define rep(i,n) for(int i = 0; i < (n); ++i) #define srep(i,s,t) for(int i = s; i < t; ++i) #define drep(i,n) for(int i = (n)-1; i >= 0; --i) using namespace std; typedef long long int ll; typedef pair<int,int> P; #define yn {puts("Yes");}else{puts("No");} #define MAX_N 200005 int n; vector<i...
#include <iostream> #include <string> #include <cmath> #include <algorithm> using namespace std; int main() { int A, B; cin >> A >> B; int* E; E = (int*)malloc((A + B) * sizeof(int)); int sum = 0; int j = 1; if (A > B) { for (int i = 0; i < A; i++) { E[i] = i + 1; sum += E[i]; } for (int i = ...
#include <bits/stdc++.h> #include <cstdint> using namespace std; #define endl "\n" #define pb push_back #define fo(i, start, end) for (ll i = start; i < end; i++) #define rep(i, start, end, step) for (ll i = start; i < end; i += step) #define print(x) cout << #x << " is " << x << endl #define all(arg) arg.begin(), ar...
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<(ll)(n);i++) #define rep2(i,s,n) for(int i=(s);i<(int)(n);i++) typedef long long ll; typedef pair<ll,ll> P; typedef tuple<ll,ll,ll> T; int main() { int n; cin>>n; ll C; cin>>C; vector<P> e; rep(i,n) { ll a,b,c; cin>>a>>b>>c; e...
#include <bits/stdc++.h> using namespace std; #define mp(a, b) make_pair(a, b) typedef pair<int, int> pii; typedef long long ll; const int maxn = 2e5 + 10; int a[maxn], b[maxn], c[maxn], d[maxn]; ll ans; int n, l; int main() { scanf("%d%d", &n, &l); for(int i = 1; i <= n; ++i) scanf("%d", &a[i]); for(int i = 1; i <=...
#include <cstdio> using namespace std; int main() { int i, j; long long n, x = 3, y; scanf("%lld", &n); for (i = 1; x <= n; i++, x *= 3) { y = 5; for (j = 1; x + y <= n; j++, y *= 5) { if (x + y == n) { printf("%d %d\n", i, j); ...
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define all(a) a.begin(), a.end() #define pb push_back #define mp make_pair typedef long long ll; typedef pair<ll,ll> P; typedef pair<ll,int> pli; typedef pair<int,int> pii; #define rep(i,a,b) for(ll i=a ; i<b ; i++) #define qrep(que, ite)...
#include <bits/stdc++.h> using namespace std; typedef long long ll; void fun() { ll a[3]; cin>>a[0]>>a[1]>>a[2]; sort(a,a+3); cout<<a[2]+a[1]; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll t=1; // cin>>t; while(t--) fun(); return 0; }
#include<bits/stdc++.h> using namespace std; long long x,y,a,b,ans; int main(){ cin>>x>>y>>a>>b; bool flag=0; while(x<y/a&&x<(x+b)/a){ x*=a; ans++; } ans+=(y-x-1)/b; printf("%lld\n",ans); }
#include<bits/stdc++.h> using namespace std; int main(){ int64_t n,m,x,y; cin>>n>>m>>x>>y; x--,y--; vector<vector<vector<int64_t>>>trn(n); for(int64_t i=0,a,b,c,d;i<m;i++){ cin>>a>>b>>c>>d; a--,b--; trn[a].push_back(vector<int64_t>{b,c,d}); trn[b].push_back(vector<int64_t>{a,c,d}); } pri...
#include <bits/stdc++.h> #define REP(i,n) for (int i = 0; i <(n); ++i) #define REP2(i,x,n) for (int i = x; i <(n); ++i) #define ALL(v) v.begin(), v.end() #define RALL(v) v.rbegin(), v.rend() using namespace std; using ll = long long; using P = pair<int,int>; static const double PI = acos(-1); static const int INF = 1e9...
#include<bits/stdc++.h> using namespace std; typedef long long ll; const ll MOD = 1e9 + 7; int mpow(int base, int exp); #define pb push_back #define mp make_pair #define ff first #define ss second #define fo(i,n) for(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...
#include <bits/stdc++.h> #define pb(x) push_back(x) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define F(w,x,y) for(ll w=x; w<y; w++) #define endl "\n" #define mod 1000000007 #define INF 1000000000 typedef long long ll; typedef long double ld; using namespace std; void play() { ...
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL string to_string(string s) { return '"' + s + '"'; } string to_string(const char* s) { return to_string(string(s)); } string to_string(bool b) { return to_string(int(b)); } string to_string(vector<bool>::reference b) { return to_string(int(b)); } string to_stri...
#include<bits/stdc++.h> using namespace std; const int mod=1e9+7; int n,f[1005]={0,1,1},g; //A 0 B 1 void upd(int &x,int y){ x=(x+y)%mod; } int main() { cin>>n; char c; for(int i=0;i<4;i++)cin>>c,g+=(1<<(3-i))*(c-'A'); if(g==0)cout<<1; if(g==1)cout<<1; if(g==2)cout<<1; if(g==3)cout<<1; if(g==4){ int a=1; f...
#include<bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ll long long int main(){ ll n; cin >> n; ll bit=1; rep(i,n){ bit*=2; } vector<ll> a(bit),c(bit); rep(i,bit){ cin >> a.at(i); } c=a; ll ans=0; for(int i=0;i<n;i++){ vector<ll> b; ...
#ifdef _DEBUG #include "../../../library/src/debug_template.cpp" #define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__) #else #define DMP(...) ((void)0) #endif #include <cassert> #include <cstdio> #include <cmath> #include <iostream> #include <iomanip> #include <string> #include <vector> #include <set> #include <map> #incl...
#include <numeric> #include <bits/stdc++.h> #include <utility> #include <iostream> #include <algorithm> #include <vector> #include <cmath> #include <math.h> #include <string> #define ll long long #define ull unsigned long long #define make(type,x) type x; cin>>x #define make2(type,x,y) type x,y; cin>>x>>y #define fr(x,...
#include <bits/stdc++.h> #define int long long #define double long double #define x first #define y second #define pb push_back #define rt return using namespace std; double dp[110][110][110]; double solve(int a,int b,int c){ if (a==100||b==100||c==100) return dp[a][b][c]=0.0; if (dp[a][b][c]!=-1.0) return dp[a][b][c...
/* AUTHOR: nit1n CREATED: 21.03.2021 21:41:12 */ #include<bits/stdc++.h> #define int long long using namespace std ; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL) ; int n ; cin >> n ; int l = 0 , h = 1e6 +10 ; while(l<h){ int mid = (l+h)/2 ; string s = to_string(mid) + to_stri...
#include<bits/stdc++.h> #define int long long #define rint regester int const int maxn = 1e6 + 10; const int INF = 1e9; using std::ios; using std::cin; using std::cout; using std::max; using std::min; using std::sort; using std::unique; using std::lower_bound; using std::swap; using std::abs; using std::acos; using std...
#include<bits/stdc++.h> #define FAST ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0); using namespace std; #define int long long //typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int,int> pii; signed main() { FAST int n,q; cin>>n>>q; vi v(n+1); for (int i = 1;...
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for(int i = 0; i < (n); i++) #define REPS(i, n) for(int i = 1; i <= (n); i++) #define RREP(i, n) for(int i = (n)-1; i >= 0; i--) #define RREPS(i, n) for(int i = (n); i > 0; i--) #define ALL(v) v.begin(), v.end() #define RALL(v) v.rbegin(), v.rend() #...
#include<bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<int> H(n), L((n+1)/2), R((n+1)/2); for (int i = 0; i < n; ++i) cin >> H[i]; sort(H.begin(), H.end()); for (int i = 0; i+1 < n; i+=2) L[i/2+1] = L[i/2] + H[i+1] - H[i]; for (int i = n-2; i >= 0; i-=2) R[i/2] = R[i/2+1...
//#include <tourist> #include <bits/stdc++.h> //#include <atcoder/all> using namespace std; //using namespace atcoder; typedef long long ll; typedef unsigned int uint; typedef unsigned long long ull; typedef pair<ll, ll> p; const int INF = 1e9; const ll LINF = ll(1e18); const int MOD = 1000000007; const int dx[4] = {0,...
#include<bits/stdc++.h> using namespace std; #define pb push_back #define ll long long #define x1 first #define y1 second #define frb(i,a,b) for(ll (i)=(a);(i) <= (b); (i)+=(i)&-(i)) #define rfrb(i,a) for(ll (i)=(a);(i) > 0;(i)-=(i)&-(i)) #define fr(i,a,b) for(ll (i) = (a); (i) <= (b); (i)++) #define rep(i,c) for(auto ...
/* Washief Hossain Mugdho 12 April 2021 AtCoder ARC_116 arc116_c */ #ifndef DEBUG #pragma GCC optimize("O2") #endif #include <bits/stdc++.h> #define pb push_back #define mp make_pair #define fr first #define sc second #define fastio ios_base::sync_with_stdio(0) #define untie cin.tie(0) #define rep(i, n) f...
#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 ...
#include<bits/stdc++.h> using namespace std; #define ll long long int main(){ int n,k; cin>>n>>k; for(int i=0;i<k;i++){ string s = to_string(n); sort(s.begin(),s.end()); string s1 = s; sort(s.rbegin(),s.rend()); string s2 = s; n = stoi(s2) - stoi(s1); } cout<<n; }
#include <bits/stdc++.h> #define f(a, n) for (int a = 0; a < n; a++) #define F(a, n) for (int a = 1; a <= n; a++) using namespace std; /* We declare an array of size 2^20. We will pretend N = 2^19. (sort of) The i-th element is stored in A[N+i]. (0 indexed) for i in [1, N-1], A[i] = A[2i] + A[2i+1]. When we update e...
#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; #define ordered_set tree<ll, null_type , less<ll> , rb_tree_tag , tree_order_statistics_Node_update> #define ll long long #define ull unsigned long long #define pb...
#include <bits/stdc++.h> typedef long long ll; using namespace std; #define repr(i,a,b) for(int i=a;i<b;i++) #define rep(i,n) for(int i=0;i<n;i++) #define invrepr(i,a,b) for(int i=b-1;i>=a;i--) #define invrep(i,n) invrepr(i,0,n) #define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr) #define P pair<int,int> co...
#include<bits/stdc++.h> using namespace std; const long long mod=1e9+7,INF=1e18; #define ll long long #define line cout<<"\n"; #define flush cout<<endl; #define pll pair<ll,ll> #define x first #define y second #define p_all(arr) for(auto i:arr){cout<<i<<" ";}cout<<"\n"; vector<ll> par,sze,val; vector<vector<pll> > tree...
// < Rahil Malhotra / ViciousCoder > #include "bits/stdc++.h" using namespace std; template <typename T> void print(T t) { cout<<t<<endl; } template<typename T, typename... Args> void print(T t, Args... args) { cout<<t<<" "; print(args...); } #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define end...
//always use #include <bits/stdc++.h> using namespace std; #define forn(i, n) for(int i=0; i<n; i++) #define mp make_pair #define pb push_back #define f first #define s second typedef long long ll; #define MOD 1000000007 #define HASHMOD 1275341791 //2 147 483 647 (2^31-1) int max //9 223 372 036 854 775 807 (2^63-1) ll...
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; int x = (a + b) / 2; int y = a - x; cout << x << " " << y << endl; }
#include<iostream> #include<stdio.h> #include<vector> #include<algorithm> #include<set> #include<string> #include<map> #include<string.h> #include<complex> #include<math.h> #include<queue> #include <functional> #include<time.h> #include <stack> #include<iomanip> #include<functional> using namespace std; #define rep(i,a...
#include <bits/stdc++.h> using namespace std; // type alias typedef long long LL; typedef pair<int,int> II; typedef tuple<int,int,int> III; typedef vector<int> VI; typedef vector<string> VS; typedef unordered_map<int,int> MAPII; typedef unordered_set<int> SETI; template<class T> using VV=vector<vector<T>>; // minmax te...
// Problem : B - Various distances // Contest : AtCoder - AtCoder Beginner Contest 180 // URL : https://atcoder.jp/contests/abc180/tasks/abc180_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_containe...
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; #define FOR(i, a, b) for (int i=a; i<(b); i++) #define range(a) a.begin(), a.end() #define endl "\n" #define Yes() cout << "Yes" << endl #define No() cout << "No" << endl #define MP make_pair con...
#pragma GCC optimize("Ofast,unroll-loops") #pragma GCC target("avx,avx2,sse4,fma") #include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; template <typename T> using minpq = priority_queue<T, vector<T>, greater<T>>; const int IN_SZ = 20<<20, OUT_SZ = 20<<20; int _i0, _o0; char _, _i[IN_SZ], _o[O...
#include <iostream> #include <cstdio> #include <string> #include <algorithm> #include <utility> #include <cmath> #include <vector> #include <stack> #include <queue> #include <deque> #include <set> #include <map> #include <tuple> #include <numeric> #include <functional> using namespace std; typedef long long ll; typedef...
#include <bits/stdc++.h> using namespace std; #define flush cout.flush using ll = int; using ull = unsigned long long; using ld = long double; using pl = pair<ll, ll>; const ll INF = 1e9 + 7; const ll mod = 1e9 + 7; const ll mod2 = 998244353; const ld eps = 1e-9; const ld PI = acos(-1); ll n, m; vector<vector<char>>...
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define pb push_back #define f(i,n) for(int i=0; i<n; ++i) #define fi(i,st,n) for(int i=st; i<=n; ++i) #define veci vector<int> #define vecp vector<pair<int,int> > #define vecl vector<ll> int prime[100000+10]; ll lcm(ll ...
#include <iostream> #include <vector> #include <algorithm> int main(){ long long n, ans = 0; std::cin >> n; std::vector <int> a(n); std::vector <std::vector<int> > list(200, std::vector<int>(0)); for (int i = 0; i < n; ++i){ std::cin >> a[i]; } for (int i = 0; i < n; ++i){ ...
#include <bits/stdc++.h> using namespace std; using ll = long long int; const int MAX = (int)(1e5 + 5); const ll INF = (ll)(1e17 + 5); const int MAX_N = (int)(2e5 + 5); int n; ll x[MAX_N]; int c[MAX_N]; ll dp[MAX_N][2]; // dp[i][0]: end color i at left, dp[i][1]: end color i at right int main(void) { // Here ...
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define REP(i,n) for(ll i=0; i<ll(n); i++) #define FOR(i,m,n) for(ll i=ll(m); i<ll(n); i++) #define ALL(obj) (obj).begin(),(obj).end() #define VI vector<int> #define VP vector<pair<ll,ll>> #define VPP vector<pair<int,pair<int,int>>> #define VLL vecto...
#pragma GCC optimize("Ofast") #include<bits/stdc++.h> #define int long long using namespace std; inline int read() { int x=0; bool flag=1; char c=getchar(); while(c<'0'||c>'9') { if(c=='-') flag=0; c=getchar(); } while(c>='0'&&c<='9') { x=(x<<1)+(x<<3)+c-'0'; c=getchar(); } return (flag?x:~(x-1)); ...
#include <bits/stdc++.h> using namespace std; #define ar array #define ll long long const int MAX_N = 1e5 + 1; const ll MOD = 1e9 + 7; const ll INF = 1e9; int findMaxGCD(int arr[], int n) { // Calculating MAX in array int high = 0; for (int i = 0; i < n; i++) high = max(high, arr[i]); // M...
#include<bits/stdc++.h> using namespace std; #define int long long const int MOD = 1e9 + 7; int32_t main(){ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); int n; cin>>n; set<int> s; for(int i=0;i<n;i++){ int x; cin>>x; s.insert(x); } int prev = 0; int ans = 1; for(int i : s){ int extra = i - pr...
#pragma GCC target("avx2") #pragma GCC optimization("O3") #pragma GCC optimization("unroll-loops") // warning: pragmas don't work on USACO and just set to O0 #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> //gp_hash_table<T, U, chash>; #include <ext/pb_ds/tree_policy.hpp> //tree<T, U, cmp, rb_tre...
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx") #pragma GCC optimize("O3") #include <bits/stdc++.h> #include <sys/time.h> using namespace std; struct state { int x; int y; int score; string path; vector<bool> used; }; int main() { struct timeval tmp_time; gettimeofday(&tmp_time, NULL);...
// ██████  ██  ██ ██████  ██ ██  ██  ██████  // ██       ██  ██ ██   ██ ██ ██  ██  ██    ██  // ██  ███ ██  ██ ██████  ██ █████   ██  ██  // ██  ██ ██  ██ ██   ██ ██ ██  ██  ██  ██  //  ██████   ██████  ██  ██ ██ ██  ██  ██████   #include <bits/stdc++.h> typedef long long ll; using namespace std; #...
#include<iostream> using namespace std; typedef long long ll; long long int gcd(long long a,long long b){ if(b==0){ return a; } else{ return gcd(b,a%b); } } long long int lcm(long long a,long long b){ return a/gcd(a,b)*b; } int main(){ int a,b; cin >> a >> b; int as,bs; as=a%100%10+a/10%10+a/100...
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; #define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define int long long #define double long double #define setbits(x) __builtin_popcountll(x) #define zrobits(x) ...
#include <bits/stdc++.h> using namespace std; #define sim template <class c #define ris return *this #define dor > debug &operator<< #define eni(x) \ sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<(c i) \ {...
#include <bits/stdc++.h> // #pragma GCC optimize("O3") #define Fast cin.tie(0), ios::sync_with_stdio(0) #define All(x) x.begin(), x.end() #define louisfghbvc int t; cin >> t; for(int tt = 0; tt < t; ++tt) #define sz(x) (int)(x).size() #define sort_unique(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end())...
#include <bits/stdc++.h> using namespace std; int main() { string s = "atcoder"; int T; cin >> T; while (T--) { string t; cin >> t; int len = t.size(); int ans = INT_MAX, sum = 0; for (auto cs : s) { int cnt = 0; for (auto it = t.begin(); it != t....
#include <bits/stdc++.h> #define rep(i,n) for(int i=0; i<(n); i++) #define reps(i,s,n) for(int i=(s); i<(n); i++) #define all(v) v.begin(),v.end() #define outve(v) for(auto i : v) cout << i << " ";cout << endl #define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;} #define in(n,v) for(int i=0;...
#include <iostream> #include <cmath> using namespace std; int main(){ int a,b,wk; cin >> a >> b >> wk; int w = wk * 1000; int dif = b - a; int min = 0; if(w%b==0){ min = w/b; }else{ min = w/b + 1; } int mmin = b * min - w; if(mmin > min * dif){ min += 1;...
#include <bits/stdc++.h> #include <math.h> using namespace std; typedef long long ll; #define rep(i, n) for(int i = 0; i < (int)(n); i ++) vector <int> dy = {0, 1, 0, -1}; vector <int> dx = {1, 0, -1, 0}; const int INF = 1000000000; const ll INFLL = 100000000000000000; long long pow(long long x, long long n) { l...
#include <bits/stdc++.h> #define F first #define S second #define MAX 10000003 using namespace std; #define ll long long int #include<fstream> #define MOD 1000000007 #define fast ios_base::sync_with_stdio(false); #define io cin.tie(NULL); #define inp(arr,n) for(ll i=0;i<n;i++){cin>>arr[i];} #define print(arr,n) ...
//DUEL #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #define x first #define y second #define pii pair<int,int> #define pb push_back #define eb emplace_back #pragma GCC optimize("unroll-loops") #define shandom_ruffle(a, b) shuffle(a, b, rng) #define vi vector<int> #define vl vector<ll> #define popcn...
#include <bits/stdc++.h> #define lc (o<<1) #define rc ((o<<1)|1) #define PB push_back #define MK make_pair using namespace std; #define DebugP(x) cout << "Line" << __LINE__ << " " << #x << "=" << x << endl const int maxn = 2e5 + 5; const int modu = 1e9 + 7; // 1e9 + 7 const int inf = 0x3f3f3f3f; const double eps = 1e-...
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for(int i=0; i<(n); ++i) #define RREP(i, n) for(int i=(n);i>=0;--i) #define FOR(i, a, n) for (int i=(a); i<(n); ++i) #define RFOR(i, a, b) for(int i=(a);i>=(b);--i) #define SZ(x) ((int)(x).size()) #define ALL(x) (x).begin(),(x).end() #define DUMP(x) c...
//#pragma GCC optimize ("O2") //#pragma GCC target ("avx2") //#include<bits/stdc++.h> //#include<atcoder/all> //using namespace atcoder; #include<cstdio> #include<cstring> #include<algorithm> using namespace std; typedef long long ll; #define rep(i, n) for(int i = 0; i < (n); i++) #define rep1(i, n) for(int i = 1; i ...
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i,n) for (long long i = 0; i < (n); ++i) #define INF LONG_MAX/3 //#define DIV 1000000007 //#define DIV 998244353 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, con...
#include <bits/stdc++.h> using namespace std; int main(){ long a, b, c, d, e; cin >> a >> b; c = b - a; for(int i = c; i > 0; i--){ d = (a + (i - 1)) / i; e = b / i; if(e - d >= 1){ cout << i << endl; break; } } }
#include<iostream> #include<vector> #include<cstring> #include<cmath> #include<algorithm> #include<math.h> using namespace std; const int INF = 1e9+5; #define ll long long int #define vi vector<int> #define vb vector<bool> int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt"...
#include <bits/stdc++.h> #define REP(i,n) for (int i = 0; i < (n); ++i) template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;} template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;} using namespace std; using ll = long long; using P = pair<in...
#include<iostream> #include<cstdio> #include<cstdlib> #include<cmath> #include<cstring> #include<algorithm> #include<climits> #include<utility> #include<vector> #include<queue> #define int long long using namespace std; const int MaxN = 500005; int n, ans; char s[MaxN], t[MaxN]; queue<int> pos; inline int Read(){ int...
#include <bits/stdc++.h> using namespace std; #define pb push_back #define mk make_pair #define mod 998244353 #define ll long long #define lb lower_bound #define ub upper_bound #define endl "\n" #define ff first #define ss second #define prec(y,x) fixed<<setprecision(y)<<x #define inf 1e18 #define pi 3.1415926535 int32...
#include<bits/stdc++.h> using namespace std; #define pys cout<<"YES"<<endl #define pyn cout<<"NO"<<endl #define loop(i,n) for(int i=0;i<n;i++) #define MOD 1000000007 #define pb push_back #define mp make_pair #define f first #define nl cout<<endl #define s second typedef vector<int> vi; typedef long long ll; void sol...
#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; typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; int main(){...
#include <bits/stdc++.h> using namespace std; long long int mod = 998244353; typedef long long int lli; typedef pair<lli,lli> pii; typedef vector<int> vi; typedef vector<lli> vlli; typedef vector<bool> vb; typedef unsigned long long int ulli; long long int max(long long int a,long long int b){ if(a>b) return a; ...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using Vec = vector<int>; using Graph = vector<vector<int>>; int MOD=1000000007; ll ll_max=9223372036854775807; bool IsPrime(int num) { if (num < 2) return false; else if (num == 2) return true; else if (nu...
/*ver 7*/ #include <bits/stdc++.h> using namespace std; void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);} using ll = long long; using ld = long double; using vl = vector<ll>; using vd = vector<ld>; using vs = vector<string>; using vb = vector<bool>; using vvl = vector<vector<ll>>; ...
#include<iostream> #include<array> #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<complex> #include<bitset> #include<stack> #include<unordered_map> #incl...
/* Author: Nguyen Tan Bao Status: Idea: */ #include <bits/stdc++.h> #define FI first #define SE second #define ALL(a) a.begin(), a.end() #define SZ(a) int((a).size()) #define MS(s, n) memset(s, n, sizeof(s)) #define FOR(i,a,b) for (int i = (a); i <= (b); i++) #define FORE(i,a,b) for (int i = (a); i >= (b);...
#include <bits/stdc++.h> using namespace std; const int A = 1000000000; void read(long long &x) { double s; cin >> s; x = round(s * 10000); } long long sqrtll(long long x) { long long l = 0, r = A; while (l < r) { long long m = (l + r + 1) / 2; if (m * m <= x) { l = m; } else { r = ...
#include <bits/stdc++.h> #define lli long long int #define pb push_back #define mod 1000000007 #define inf 1000000000000000000 #define mp make_pair using namespace std; int main() { cout.precision(16); ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long double x,y,r; cin>>x>>y>...
#include"bits/stdc++.h" using namespace std; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef vector<PII> VPII; typedef long long LL; typedef vector<LL> VL; typedef vector<VL> VVL; typedef pair<LL, LL> PLL; typedef vector<PLL> VPLL; typedef priority_queue...
#include <bits/stdc++.h> using namespace std; using ll = int64_t; ll MOD = 1000000007; int main(){ int H,W; cin>>H>>W; vector<vector<char>> s(H,(vector<char>(W))); for(int i=0;i<H;i++) for(int j=0;j<W;j++) cin>>s[i][j]; vector<vector<ll>> dp(H,(vector<ll>(W))); vector<vector<ll>> dpx(H,(vector<ll>(W))); ...
#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> #define rep(i, n) for (int i = 0; i < (n); ++i) #define sz(x) int(x.size()) #define show(x) {for(auto i: x){cout << i << " ";} cout << endl;} using namespace std; using ll = long long; using P = pair<int, int>; int MOD = 1000000007; struct mint { ll x; // typedef long long ll; mint(ll ...
#include<bits/stdc++.h> using namespace std; #define ll long long int main() { ios_base::sync_with_stdio(0); #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif ll x,y; cin >> x >> y; ll a = min(x,y); ll b = max(x,y); if((a+3)>b) { cout << "Yes" << en...
// Author :- Sarvesh Chaudhary #include<bits/stdc++.h> using namespace std; #define w(x) int x; cin>>x; while(x--) #define ll long long int #define sidha(i,a,b) for(int i=a;i<b;i++) #define set_built(x) __builtin_popcountll(x) #define zero_built(x) __bultin_ctzll(x) #define pairi pair<int,int> #define vi vector<int> #d...
#include <bits/stdc++.h> using namespace std; using ll = long long; ll m = 1e9 + 7; ll mpow(ll a, ll n) { ll ret = 1; while (n) { if (n % 2) { ret *= a; ret %= m; } a = (a * a) % m; n /= 2; } return ret; } int main () { int N, M, K; cin >> N >> M >> K; if (N - M > K) { cout...
#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) #pragma GCC optimize ("-O3") using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } //--------------------------------------------------...
#include<iostream> #include<vector> #include<algorithm> #include<math.h> #define rep(i,n) for(ll i = 0; i < (n); i++) using ll = long long; using namespace std; int main(){ ll n, j = 0; cin >> n; vector<ll>a; ll b = (ll)sqrt(n); if(n == 1){ cout << 1 << endl; return 0; }else if(...
#include <iostream> #include <vector> #include <climits> #include <algorithm> #include <cmath> #include <map> #include <set> #include <string> #include <bitset> #include <utility> #include <numeric> #include <queue> #include <stack> #include <functional> #include <iomanip> using ll = long long; using namespace std; c...
#include <iostream> #include <vector> #include <iostream> #include <algorithm> #include <math.h> using namespace std; const int MOD = 1000000007; int main() { int N, P; cin >> N >> P; int dgt = (int)log2(N); long long ans = 1; vector<long long> modulo(40); modulo.at(0) = 1; modulo.at(1) = P - 2; for (in...
#include<iostream> #define mod 1000000007 long long pow(long long x, long long n); using namespace std; int main(){ long long N,P,res; cin >> N>>P; res=pow(P-2,N-1); res*=P-1; res%=mod; cout << res << endl; } long long pow(long long x, long long n) { long long ret = 1; while (n > 0) {...
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_multiset tree<long long , null_type,less_equal<long long >, rb_tree_tag,tree_order_statistics_node_update> #define ordered_set tree<long long , null_type,less<long long >, rb...
#include<bits/stdc++.h> #define ll long long int #define mk make_pair #define pb push_back #define INF (ll)1e18 #define pii pair<ll,ll> #define mod 998244353 #define f(i,a,b) for(ll i=a;i<b;i++) #define fb(i,a,b) for(ll i=a;i>b;i--) #define ff first #define ss second #define srt(v) if(!v.empty())sort(v.begin(),v.end()...
#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() #define allr(v) v.rbegin(), v.rend() #define V vector #define pb push_back #define eb emplace_back #define lb lower_bound #define ub upper_bound #define mp make_pair #define sz(x) int(x.size()...
//#pragma GCC optimize("Ofast", "unroll-loops") //#pragma GCC target("sse", "sse2", "sse3", "ssse3", "sse4", "avx") #ifdef __APPLE__ # include <iostream> # include <cmath> # include <algorithm> # include <stdio.h> # include <cstdint> # include <cstring> # include <string> # include <cstdlib> # include <vector> # inclu...
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll gcd(ll m, ll n) { if (n == 0) return m; else return gcd(n, m % n); } ll extgcd(ll a, ll b, ll &x, ll &y) { if (b == 0) { x = 1; y = 0; return a; } ll d = extgcd(b, a % b, y, x); y -= a / b * x; retu...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; #define mp make_pair #define pb push_back #define fi first #define se second #define sz(x) int(x.size()) //const int mod = 1e9 + 7; const int inf = 2e9 + 5; const ll linf = 9e18 + 5; const ll ll0 = 0 * 1ll; ll n, s, k; ll mod...
#include <bits/stdc++.h> using namespace std; int a[15],tot; int main(){ int n; scanf("%d",&n); if(n==0){ printf("Yes"); return 0; } while(n%10==0)n/=10; while(n){ a[++tot]=n%10; n/=10; } int flag=1; for(int i=1;i<=tot;i++)if(a[i]!=a[tot+1-i])flag=0; printf(flag?"Yes":"No"); }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(int)(n);i++) #define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++) #define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--) #define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++) #define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend...
#include <bits/stdc++.h> using namespace std; #define fst ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define endk cout<<"\n"; typedef long long int ll; typedef long int l; #define l(i,a,b) for(i=a;i<b;i++) #define lo(i,a,b) for(i=a;i>=b;i--) #define s(v) sort(v.begin(),v.end()); #define pb push_back; #de...
#include <bits/stdc++.h> #define M 1000000007 #define pii 3.14159265359 #define pb push_back #define pob pop_back #define forr(i,n) for(i=0;i<n;i++) #define fors(i,j,n) for(i=j;i<n;i++) #define pi pair<int,int> #define ff first #define ss second #define tcase 0 #define all(v) v.begin(),v.end() typedef long long int l...
#include<bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll n; cin >> n; ll ans = 2; for (ll i = 3; i <= n; i++) ans = (((i * ans)) / (__gcd(i, ans))); cout << ans + 1; }
#include <iostream> #include <string> #include <vector> using namespace std; int main(){ string S; cin >> S; long long m, b, q; m = 0; b = 0; q = 10; for(int i=0; i<=9; i++){ if(S.at(i) == 'o') m++; if(S.at(i) == 'x') b++; } q -= m; q -= b; long long ans = 0...
#include<bits/stdc++.h> using namespace std; #define ff first #define ss second #define fo(i,n) for(int i=0;i<n;i++) #define fod(i,n) for(int i=n-1;i>=0;i--) #define For(i,a,b) for(int i=a;i<=b;i++) #define all(x) x.begin(),x.end() #define SET(x) memset(x,...
#include<bits/stdc++.h> using namespace std; #define rep(i, a, n) for(int i=(a); i<(n); ++i) #define per(i, a, n) for(int i=(a); i>(n); --i) #define pb emplace_back #define mp make_pair #define clr(a, b) memset(a, b, sizeof(a)) #define all(x) (x).begin(),(x).end() #define lowbit(x) (x & -x) #define fi first #define se...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int h, w; cin >> h >> w; int n, m; cin >> n >> m; vector<int> a(n), b(n); for (int i = 0; i < n; i++) cin >> a[i] >> b[i]; vector<int> c(m), d(m); for (int i = 0; i < m; i++) cin >> c[i] >> d...
#include <iostream> #include <vector> using namespace std; vector<vector<int>> graph; vector<bool> visit(2000); void dfs(int now_town){ if(visit[now_town]){ return; } visit[now_town] = true; for(auto next_town : graph[now_town]){ dfs(next_town); } } int main(void)...
#include <bits/stdc++.h> using namespace std; using Tuple = tuple<int, int, int, int>; using V1 = vector<int>; using V2 = vector<V1>; using V3 = vector<V2>; using PQueue = priority_queue<Tuple, vector<Tuple>, greater<Tuple>>; constexpr int INF = 1e+9; template<typename T> bool chmin(T &a, T b) { if (a > b) { ...
#include <bits/stdc++.h> using namespace std; using vi = vector<int>; using vb = vector<bool>; using vl = vector<long>; using vs = vector<string>; using vvi = vector<vector<int>>; using vvb = vector<vector<bool>>; using vvc = vector<vector<char>>; using vvl = vector<vector<long>>; using pii = pair<int, int>; using pil ...
#include<cstdio> typedef long long ll; struct SegmentTree { int num,rt; ll size[2000005],sum[2000005]; int lson[2000005],rson[2000005]; SegmentTree() {num=0; rt=0;} inline void _change(int &p,int l,int r,int x,int d) { if(!p) p=++num; size[p]+=d; sum[p]+=x*1ll*d; if(l==r) ret...
#include <bits/stdc++.h> using namespace std; long N, C, x, y, c, cur, pr1, pr2, total; vector<pair<long, long>> a; bool sortbc(const pair<int,int> &a, const pair<int,int> &b) { if (a.first == b.first) return (a.second > b.second); return a.first < b.first; } int main() { cin>>N>>C; fo...
#include <bits/stdc++.h> using namespace std; typedef int_fast32_t int32; typedef int_fast64_t int64; const int32 inf = 1e9+7; const int32 MOD = 1000000007; const int64 llinf = 1e18; #define YES(n) cout << ((n) ? "YES\n" : "NO\n" ) #define Yes(n) cout << ((n) ? "Yes\n" : "No\n" ) #define POSSIBLE(n) cout << ((n) ?...
#include <iostream> #include<stdio.h> #include<iostream> #include <cmath> using namespace std; int main(){ int n,plus,minus; cin>>n>>minus>>plus; int sum=(n-minus)+plus; cout<<sum; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define pii pair<int,int> #define fi first #define se second #define mp make_pair #define poly vector<ll> #define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++) #define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--) #defi...
#include <bits/stdc++.h> using namespace std; //UnionFindテンプレ class UnionFind { // まとめる 判定 サイズを知る public: // Aから見た親の番号を格納する。rootだったら-1*その集合のサイズ。 vector<int> Parent; // 初期化 UnionFind(int N) { Parent = vector<int>(N, -1); } // Aのrootを調べる int root(int A) { if (Parent[...
#include <bits/stdc++.h> using namespace std; int main(){ string S; cin >> S; int o=0,x=0,q=0; for(int i=0;i<10;i++){ if(S[i]=='o') o++; if(S[i]=='x') x++; if(S[i]=='?') q++; } int ans = 0; for(int i=0;i<10000;i++){ vector<int> V(10,0); int now = i; for(int j=0;j<4;j++){ ...
#include <iostream> #include <algorithm> #include <string> #include <cstring> #include <cstdio> using namespace std; int main() { string s; cin >> s; int ans_o = 0, ans_p = 0; for(int i = 0; i < s.length(); ++i){ if(s[i] == 'o') ans_o++; if(s[i] == '?') ans_p++; } if(ans_o > 4) ...
#include<bits/stdc++.h> using namespace std; typedef long long ll; char dp[105][105]; string s; ll Mod; ll mypow(ll a,ll b){ ll ans=1; while(b){ if(b&1)ans=ans*a%Mod; a=a*a%Mod; b>>=1; } return ans; } char chos(char s1,char s2){ if(s1==s2)return s1; if(s1=='P'&&s2=='R'...
#include <bits/stdc++.h> #define ll unsigned long long //#define fin cin using namespace std; int n, k; string s; char winner(char a, char b) { if(a == 'R' && b == 'S') return a; if(a == 'P' && b == 'R') return a; if(a == 'S' && b == 'P') return a; return b; } int main() { ...
#include<bits/stdc++.h> using namespace std; #define int long long #define pb push_back #define ppb pop_back #define pf push_front #define ppf pop_front #define all(x) (x).begin(),(x).end() #define uniq(v) (v).erase(unique(all(...
#include <iostream> #include <algorithm> #include <bits/stdc++.h> #define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define ll long long #define mm(arr) memset(arr, 0, sizeof(arr)) #define scanArray(a,n) for(int i = 0; i < n; i++){cin >> a[i];} #define pb push_back #define PI 3.141592653589793 #de...
#include<bits/stdc++.h> using namespace std; int main(){ int V,T,S,D; cin>>V>>T>>S>>D; if (D<V*T || D>V*S){ cout<<"Yes"<<endl; } else{ cout<<"No"<<endl; } }
#define _CRT_SECURE_NO_WARNINGS #include<bits/stdc++.h> #include<unordered_map> using namespace std; clock_t T; #define ctime cerr << "Time : " << double(clock() - T) / CLOCKS_PER_SEC << endl #define all(v) ((v).begin()), ((v).end()) #define sz(v) v.size() #define endl "\n" typedef long long ll; typedef vector<int> vi;...
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll, ll> pll; typedef vector<ll> vll; typedef vector<vector<ll>> vvll; typedef vector<pll> vpll; typedef vector<bool> vbl; typedef vector<vector<bool>> vvbl; void INX(){} template<typename Head, typename... Tail> vo...
#include <iostream> #include <vector> #include <string> using namespace std; #define rep(i,n) for(int i=0; i<n; i++) int main() { string str; cin >> str; int ans = 0; rep(i,12){ if(str.compare(i,4,"ZONe")==0){ ans++; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; // using mint = long double; // using mint = modint998244353; // using mint = modint1000000007; typedef long long ll; typedef pair<ll, ll> P; typedef pair<ll, P> T; typedef pair<ll, vector<ll>> Pd; const ll INF = 1e18; const ll fact_table = 320000; priority_queue<ll> p...
#include <bits/stdc++.h> using namespace std; #define rep(i,a,b) for(int i=(a);i<=(b);++i) #define FI freopen("/home/empathy/in.txt", "r", stdin) #define FO freopen("/home/empathy/out.txt", "w", stdout) template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { retu...
// AUTHOR:- Saumya Rangani #include <bits/stdc++.h> using namespace std; #define int long long #define pi (3.141592653589) #define mod 1000000007 #define float double #define pb push_back #define mp make_pair #define vi vector<int> #define vii vector<pair<int,int>> #define fr first #define sc second #define all(c) c.b...
#pragma GCC optimize("O3") #pragma GCC target("avx2") #include <algorithm> #include <iostream> #include <array> using namespace std; #define f(x,y,z) for(int x=y;x<=z;++x) int n, m, q, l, r, h, mn, imn; array<int, 51> bx, kt; pair<int, int> bg[51]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie...
/************************************************************************* > File Name: 1.cpp > Author: Knowledge_llz > Mail: 925538513@qq.com > Blog: https://blog.csdn.net/Pig_cfbsl > Created Time: 2020/10/11 22:45:26 ************************************************************************/ #include<bits/stdc+...
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<ll,ll>; using Graph= vector<vector<int>>; #define rep(i,n) for (ll i=0; i < (n); ++i) #define rep2(i,n,m) for(ll i=n;i<=m;i++) #define rep3(i,n,m) for(ll i=n;i>=m;i--) #define pb push_back #define eb emplac...
#include<iostream> #include<algorithm> #include<ctime> #include<vector> #include<string> #include<cmath> #include<map> #include<iomanip> #include<numeric> #include<queue> #include<deque> #include<cfloat> #include<functional> #include<tuple> #include<math.h> #include<bitset> #include<stack> #include<set> #include<random...
#pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma") #pragma GCC optimize("unroll-loops") //#pragma GCC target("avx,avx2,fma") #include <bits/stdc++.h> using namespace std; #define null NULL typedef long double ld; #define int long long #define pb...
#include <bits/stdc++.h> using namespace std; typedef long long int ll; #define endl "\n" #define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); int main() { fast; #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif ll n,x; cin>>n>>x; vector<ll> v(n,0),p(n,0)...
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> P; typedef pair<ll, ll> Pll; using Graph = vector<vector<int>>; using Graphl = vector<vector<ll>>; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define Rep(i, k, n) for (int i = k; i < (int)(n); i+...
#include <bits/stdc++.h> #define rep(i, n) for(int i = 0; i < (n); i++) #define rep2(i, x, n) for(int i = x; i < (n); i++) using namespace std; using ll = long long; //const double PI = 3.14159265358979323846; int main() { ll a, b, c; cin >> a >> b >> c; if(c % 2 == 0) { a = a * a; b = b *...
#include <iostream> using namespace std; typedef long long ll; ll abso(ll a){ if(a < 0){ return -a; }else{ return a; } } int main(){ ll A, B, C; cin >> A >> B >> C; if(A == B){ cout << "="; }else if(C%2 == 0){ if(abso(A) == abso(B)){ cout << ...
#include<bits/stdc++.h> using namespace std; #define N 200005 char s[N];int l,i,st[N],hd; int main(){ scanf("%d%s",&l,s+1); for(i=1;i<=l;++i){ st[++hd]=s[i]; while(hd>2&&st[hd-2]=='f'&&st[hd-1]=='o'&&st[hd]=='x')hd-=3; } cout<<hd; }
#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...