code1
stringlengths
54
12k
code2
stringlengths
66
12k
similar
int64
0
1
__index_level_0__
int64
24
101M
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using P = pair<ll, ll>; using Pld = pair<ld, ld>; using Vec = vector<ll>; using VecP = vector<P>; using VecB = vector<bool>; using VecC = vector<char>; using VecD = vector<ld>; using VecS = vector<string>; template <class T> using Vec2 = vector<vector<T>>; #define REP(i, m, n) for(ll i = (m); i < (n); ++i) #define REPN(i, m, n) for(ll i = (m); i <= (n); ++i) #define REPR(i, m, n) for(ll i = (m)-1; i >= (n); --i) #define REPNR(i, m, n) for(ll i = (m); i >= (n); --i) #define rep(i, n) REP(i, 0, n) #define repn(i, n) REPN(i, 1, n) #define repr(i, n) REPR(i, n, 0) #define repnr(i, n) REPNR(i, n, 1) #define all(s) (s).begin(), (s).end() #define pb push_back #define fs first #define sc second template <class T1, class T2> bool chmax(T1 &a, const T2 b){if(a < b){a = b; return true;} return false;} template <class T1, class T2> bool chmin(T1 &a, const T2 b){if(a > b){a = b; return true;} return false;} ll pow2(const int n){return (1LL << n);} template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &i : v) os << i << ' '; return os; } void co() { cout << '\n'; } template <class Head, class... Tail> void co(Head&& head, Tail&&... tail) { cout << head << ' '; co(forward<Tail>(tail)...); } void ce() { cerr << '\n'; } template <class Head, class... Tail> void ce(Head&& head, Tail&&... tail) { cerr << head << ' '; ce(forward<Tail>(tail)...); } void sonic(){ios::sync_with_stdio(false); cin.tie(0);} void setp(const int n){cout << fixed << setprecision(n);} constexpr int INF = 1000000001; constexpr ll LINF = 1000000000000000001; constexpr ll MOD = 1000000007; constexpr ll MOD_N = 998244353; constexpr ld EPS = 1e-11; const double PI = acos(-1); struct Doubling { const int sz = 64; int n; vector<vector<ll>> data; vector<vector<ll>> sum; Doubling(int _n) : n(_n) { data.resize(sz); for (size_t i = 0; i < sz; ++i) { data[i].resize(n); } sum.resize(sz); for (size_t i = 0; i < sz; ++i) { sum[i].resize(n); } } void build(vector<ll> v) { for (size_t i = 0; i < n; ++i) { data[0][i] = v[i]; } for (size_t i = 0; i < sz - 1; ++i) { for (size_t j = 0; j < n; ++j) { data[i + 1][j] = data[i][data[i][j]]; } } for (size_t i = 0; i < n; ++i) { sum[0][i] = i; } for (size_t i = 0; i < sz - 1; ++i) { for (size_t j = 0; j < n; ++j) { sum[i + 1][j] = sum[i][j] + sum[i][data[i][j]]; } } } ll solve(ll f, ll k) { int cnt = 0; ll res = 0; while (k) { if (k & 1){ res += sum[cnt][f]; f = data[cnt][f]; } k >>= 1; ++cnt; } return res; } }; int main(void) { ll n, x, m; cin >> n >> x >> m; Vec a(m); rep(i, m) a[i] = i * i % m; Doubling db(m); db.build(a); co(db.solve(x, n)); return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define vvi vector<vector<int>> #define vec vector #define pq priority_queue #define all(v) (v).begin(), (v).end() #define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end()); #define rep(i, n) for (int (i) = (0); (i) < (n); ++(i)) #define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i)) #define dbg(x) cerr << #x << ": " << x << endl; #define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl; #define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl; #define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl; #define line() cerr << "---------------" << endl; const int dx[] = {1, -1, 0, 0}; const int dy[] = {0, 0, -1, 1}; const double PI = 3.14159265358979323846; 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; } template<typename T, typename U> void print1(T Array, U size) { for (int i = 0; i < size; i++) { cout << Array[i] << " "; } cout << endl; } template<typename T> void print(T Array, int height, int width) { for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { cout << " " << Array[i][j]; } cout << endl; } } const int INF = 1e15; int dp[55555]; int c[22]; int n, m; signed main() { cin >> n >> m; rep (i, m) { cin >> c[i]; } fill(dp, dp+n+5, INF); dp[0] = 0; for (int i = 0; i <= n; i++) { for (int j = 0; j < m; j++) { if (i - c[j] >= 0) { dp[i] = min(dp[i], dp[i-c[j]] + 1); } } } cout << dp[n] << endl; return 0; }
0
68,792,163
#include <iostream> #include <string> #include <array> #include <algorithm> #include <vector> #include <string> #include <set> #define int long long using namespace std; void printVector(const vector<int>& vec) { for (int value : vec) { cout << value << " "; } cout << endl; } signed main() { string s; int n; set<char> S; cin >> s; n = s.length(); for(int i = 0; i < n; i ++){ S.insert(s[i]); } if(n == S.size()) cout << "yes"; else cout << "no"; return 0; }
#include<iostream> using namespace std; int main(){ int n; cin>>n; int cnt=100000; for(int i=0;i<n;i++){ cnt=cnt*1.05; if((cnt%1000)>0){ cnt+=1000; cnt-=(cnt%1000); } } cout<<cnt<<endl; return 0; }
0
80,781,505
#include <iostream> #include <string> #include <stack> #include <queue> #include <cctype> #include <algorithm> #include <vector> #include <map> #include <cmath> #include <stdlib.h> #include <tuple> #include <iomanip> #include <iterator> #include <stdio.h> #include <fstream> #include <time.h> using namespace std; const double PI = 3.14159265358979323846; const long long int MOD = 1000000000 + 7; struct UnionFind { vector<int> parent; UnionFind(int N) : parent(N) { for (int i = 0; i < N; i++) { parent[i] = -1; } } int root(int i) { if (parent[i] < 0) { return i; } return (parent[i] = root(parent[i])); } bool unite(int x, int y) { int rx = root(x); int ry = root(y); if (rx != ry) { parent[ry] += parent[rx]; parent[rx] = ry; return true; } else { return false; } } bool same(int x, int y) { return root(x) == root(y); } int treeSize(int x) { return -parent[root(x)]; } }; long long int modpow(long long int base, long long int pow, long long int mod) { if (pow == 1) { return base; } else if (pow == 0) { return 1; } if (pow % 2 == 0) { auto temp = modpow(base, pow / 2, mod); return (temp * temp) % mod; } else { return base * modpow(base, pow - 1, mod) % mod; } } long long int moddiv(long long int X, long long int Y, long long int mod) { auto fermatDiv = modpow(Y, mod - 2, mod); return (X * fermatDiv) % mod; } long long modCombination(long long left, long long right, long long int mod) { long long answer = 1; for (long long i = 0; i < right; i++) { answer = (answer * (left - i)) % mod; answer = moddiv(answer, (i + 1), mod); } return answer; } bool IsPrime(long long N) { if (N == 1) { return false; } for (long long i = 2; i * i <= N; i++) { if (N % i == 0) { return false; } } return true; } vector<pair<long long, long long> > prime_factorize(long long N) { vector<pair<long long, long long> > res; for (long long a = 2; a * a <= N; ++a) { if (N % a != 0) continue; long long ex = 0; while (N % a == 0) { ++ex; N /= a; } res.push_back({ a, ex }); } if (N != 1) res.push_back({ N, 1 }); return res; } long long euclid(long long a, long long b) { if (a > b) { long long temp = b; b = a; a = temp; } if (b % a == 0) { return a; } else { return euclid(a, b - a); } } int main() { long long N, M; cin >> N >> M; priority_queue<long long> items; for (long long i = 0; i < N; i++) { long long temp; cin >> temp; items.push(temp); } for (long long i = 0; i < M; i++) { long long item = items.top(); items.pop(); item = item >> 1; items.push(item); } long long answer = 0; while (!items.empty()) { answer += items.top(); items.pop(); } cout << answer << endl; return 0; }
#include <iostream> #include <vector> #include <algorithm> #include <queue> #include <string> #include <functional> #include <set> #define DB cerr<<"D"<<endl #define pb push_back using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6; template<typename T, typename U, typename O> void caut(T a, U b, O c){cout<<"("<<a<<","<<b<<","<<c<<") ";} template<typename T, typename U> void caut(T a, U b){cout<<"("<<a<<","<<b<<") ";} template<typename T> void caut(T a){cout<<"("<<a<<") ";} using P=pair<double,int>; const ll M = 998244353; void add(ll& x, ll y) {x+=y; x%=M;} void chmax(ll& x, ll y) {if (x<y) x=y;} int main() { int n; cin>>n; ll a[n],b[n]; for(int i=0;i<n;i++) cin>>a[i]; for(int i=0;i<n;i++) cin>>b[i]; int an=0; ll fu=0; ll c[n]; for(int i=0;i<n;i++) { c[i]=a[i]-b[i]; if (c[i] < 0) an++,fu+=-c[i]; } sort(c,c+n,greater<ll>()); for(int i=0;i<=n && fu>0;i++) { if (i==n || c[i]<0) { cout<<-1<<endl; return 0; } fu -= c[i]; an++; } cout<<an<<endl; }
0
5,190,694
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rrep(i, n) for(int i = n-1; i >= 0; i--) #define all(x) (x).begin(),(x).end() #define rall(v) (v).rbegin(), (v).rend() #define FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0) typedef long long ll; using P = pair<int,int>; using VI = vector<int>; using VVI = vector<vector<int>>; using VL = vector<ll>; using VVL = vector<vector<ll>>; using VP = vector<P>; template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; } template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; } int main(){ ll N, T; cin >> N >> T; VL t(N); rep(i,N) cin >> t[i]; ll ans = T; rep(i,N-1){ ans += min(t[i+1]-t[i], T); } cout << ans << endl; return 0; }
#include<iostream> #include<unordered_map> #include<bitset> #include<math.h> #include<vector> #include<set> #include<algorithm> #include<ctype.h> #include<unordered_set> #include<string> #include<iomanip> #include<queue> #include<limits> #include<map> #include<stack> #include<iterator> #include<cstring> #include<deque> #define pi 3.141592653589793238 #include<chrono> #pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") #define MOD 1000000007 #define INF 999999999999999999 #define pb push_back #define ff first #define ss second #define mt make_tuple #define ll long long #define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); using namespace std; #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; int main() { fast; ll T = 1, i, j; while (T--) { ll a,b, m; cin >> a >> b >> m; vector<ll> v1(a), v2(b); ll minf = INF, minm = INF; for(i = 0; i < a; i++){ cin >> v1[i]; minf = min(minf, v1[i]); } for(i = 0; i < b; i++){ cin >> v2[i]; minm = min(minm, v2[i]); } ll ans; ans = minf + minm; for(i = 0; i < m; i++){ ll x , y, c; cin >> x >> y >> c; x--, y--; ll val = max(0LL, v1[x] + v2[y] - c); ans = min(ans, val); } cout << ans; } return 0; }
0
30,714,424
#include <bit> #include <bitset> #include <assert.h> #include <stdio.h> #include <string.h> #include <algorithm> #include <sstream> #include <iostream> #include <set> #include <map> #include <vector> #include <math.h> #include <stdlib.h> #include <queue> #include <stack> #include <iomanip> typedef long double ld; typedef long long ll; using namespace std; #define MAXN (1 << 20) vector<int> pos, neg; int a[MAXN]; int n; vector<pair<int, int> > ans; int main() { cout << fixed << setprecision(12); cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] >= 0) { pos.push_back(a[i]); } else if (a[i] < 0) { neg.push_back(a[i]); } } sort(pos.begin(), pos.end()); sort(neg.begin(), neg.end(), greater<int>()); if (pos.size() && neg.size()) { int nn = neg[0]; int pp = pos[0]; for (int i = 1; i < pos.size(); i++) { ans.push_back(make_pair(nn, pos[i])); nn -= pos[i]; } for (int i = 1; i < neg.size(); i++) { ans.push_back(make_pair(pp, neg[i])); pp -= neg[i]; } ans.push_back(make_pair(pp, nn)); } else if (pos.size()) { int nn = pos[0]; for (int i = 1; i < pos.size() - 1; i++) { ans.push_back(make_pair(nn, pos[i])); nn -= pos[i]; } ans.push_back(make_pair(pos[pos.size() - 1], nn)); } else if (neg.size()) { int nn = neg[0]; for (int i = 1; i < neg.size(); i++) { ans.push_back(make_pair(nn, neg[i])); nn -= neg[i]; } } pair<int, int> last = ans[ans.size() - 1]; cout << last.first - last.second << endl; for (int i = 0; i < ans.size(); i++) { cout << ans[i].first << " " << ans[i].second << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll x,n,c=0; cin>>n; int a[n+1]={}; for(int i=1;i<=n;i++) { cin>>a[i]; } for(int i=1;i<=n;i++) { if(a[a[i]]==i)c++; } cout<<c/2<<endl; return 0; }
0
34,820,593
#include <stdio.h> int main(){ int a[26]={0}; char temp; while(scanf("%c",&temp)!=EOF){ if(temp-'a'>=0&&temp-'a'<26)a[temp-'a']++; if(temp-'A'>=0&&temp-'A'<26)a[temp-'A']++; } for(int i=0;i<26;i++){ printf("%c : %d\n",i+'a',a[i]); } }
#include<bits/stdc++.h> using namespace std; int main(){ int H,W; cin>>H>>W; vector<string> A(H+1); string S=""; for(int i=0;i<=W;i++) S+='.'; A[0]=S; for(int i=1;i<=H;i++){ cin>>A[i]; A[i]='.'+A[i]; } vector<vector<int>> B(H+1,vector<int>(W+1)); for(int i=1;i<=H;i++){ for(int j=1;j<=W;j++){ int a=B[i-1][j],b=B[i][j-1]; if(A[i][j]=='#' && A[i-1][j]=='.') a++; if(A[i][j]=='#' && A[i][j-1]=='.') b++; if(i==1) B[i][j]=b; else if(j==1) B[i][j]=a; else B[i][j]=min(a,b); } } cout<<B[H][W]<<endl; }
0
13,561,384
#include <bits/stdc++.h> using namespace std; #define int long long #define pb push_back #define pf push_front #define pii pair <int, int> #define all(vv) (vv).begin(), (vv).end() #define rep(ii, jj, ll, ss) for(int ii = jj; ii < ll; ii += ss) #define time cerr << '\n' << (double)clock()/CLOCKS_PER_SEC << '\n'; return 0; int n; vector <int> v; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); bool yay = false; int ans = 0; cin >> n; rep(i, 0, n, 1) { int x; cin >> x; if (x == 1) yay = true; v.pb(x); } if (!yay) cout << -1; else { bool ok = false; int next = 2; rep(i, 0, n-1, 1) { if (v[i] == 1) ok = true; if (!ok) { ++ans; continue; } else { if (v[i+1] != next) ++ans; else ++next; } } cout << ans; } time }
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <iostream> #include <string> #include <vector> #include <map> #include <unordered_map> #include <queue> #include <algorithm> #include <bits/stdc++.h> #include <cmath> #include <limits> using namespace std; typedef long long LL; using Graph = vector<vector<int>>; typedef long long LL; static LL INF = (1LL<<62); LL S; int main(int argc, char* argv[]){ cin.tie(0); ios::sync_with_stdio(false); cin >> S; LL a, c; LL b, d; for(a=1; ; a++){ if( a >= 1000000000LL || a*a > S){ break; } } d = a; LL u = (a*d) - S; b = 1; c = u; if(c > 1000000000LL){ while(c >= 1000000000LL){ d--; u = abs((a*d) - S); c = u; } } printf("0 0 %lld %lld %lld %lld\n", a, c, b, d); return 0; }
0
69,279,606
#include <bits/stdc++.h> #define irep(i,n) for(int i = 0; i < (int)(n); i++) #define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++) #define irrep(i,n) for(int i = (int)(n-1); i > -1; i--) #define irrep2(i,n,a) for(int i = (int)(n); i >= (int)(a); i--) #define fi first #define se second using namespace std; using ll = long long; using v_int = vector<int>; using v2_int = vector<v_int>; using v_ll = vector<ll>; using v2_ll = vector<v_ll>; using v_string = vector<string>; using v_bool = vector<bool>; using v2_bool = vector<v_bool>; using pii = pair<int, int>; using mii = map<int, int>; const double PI = 3.1415926535897932; const int INF = (int)2e9; const ll LINF = (ll)2e18; const ll MOD = 1000000007; const int dc[8] = {1, -1, 0, 0, 1, -1, 1, -1}; const int dr[8] = {0, 0, 1, -1, 1, 1, -1, -1}; template<typename T, typename U> inline ostream& operator<<(ostream &o, pair<T,U> &p) { return o << "{" << p.first << "," << p.second << "}"; } template<typename T> inline istream& operator>>(istream &is, vector<T> &vec) { for(auto &v : vec) { is >> v; } return is; } template<typename T> inline ostream& operator<<(ostream &os, vector<T> &vec) { for(auto &v : vec) { os << v << ",";} return os; } template<typename T> inline ostream& operator<<(ostream &os, vector<vector<T> > &mat) { for(auto &row : mat) { os << row << endl; } return os; } template<typename T> inline void chmin(T &a, T b) { a = min(a, b); } template<typename T> inline void chmax(T &a, T b) { a = max(a, b); } int main(void) { int r, d, x; cin >> r >> d >> x; irep(i, 10) { x = r * x - d; cout << x << endl; } return 0; }
#include <iostream> #include <vector> #include <map> #include <algorithm> using namespace std; typedef unsigned long long ull; typedef long long ll; int main() { int n; cin >> n; int a, b, c, d; a = n / 1000; b = n / 100 - a * 10; c = n / 10 - a * 100 - b * 10; d = n - a * 1000 - b * 100 - c * 10; int op1[8] = {1, 1, 1, 1, -1, -1, -1, -1}; int op2[8] = {1, 1, -1, -1, 1, 1, -1, -1}; int op3[8] = {1, -1, 1, -1, 1, -1, 1, -1}; char ans1 = '+'; char ans2 = '+'; char ans3 = '+'; for (int i = 0; i < 8; ++i) { int cal = a + b * op1[i] + c * op2[i] + d * op3[i]; if (cal == 7) { if (op1[i] == -1) { ans1 = '-'; } if (op2[i] == -1) { ans2 = '-'; } if (op3[i] == -1) { ans3 = '-'; } break; } } cout << a << ans1 << b << ans2 << c << ans3 << d << "=7" << endl; }
0
90,240,066
#include <iostream> using namespace std; #define in(v) cin>>v; #define out(v) cout<<v<<"\n" int main() { int a, b; scanf("%d%d", &a, &b); if (a % b == 0) printf("-1\n"); else printf("%lld\n", (long long)a*(b+1)); return 0; }
#include <iostream> #include <string> using namespace std; enum STATUS { TOP, UP, DOWN, BOTTOM }; int main() { int n; string f; int count; STATUS status; while (1) { count = 0; status = BOTTOM; cin >> n; if (!n) break; while (n--) { cin >> f; if (f[1] == 'u') { if (status == UP) { status = TOP; count++; } else if (status == DOWN) { status = TOP; } else if (status == BOTTOM) { status = UP; } } else { if (status == DOWN) { status = BOTTOM; count++; } else if (status == UP) { status = BOTTOM; } else if (status == TOP) { status = DOWN; } } } cout << count << endl; } }
0
81,155,647
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main(){ std::vector<string> word; std::vector<int> count; string now; int num=0,most=0; bool aaa; while(cin >> now){ aaa = true; for(int i=0;i<num;i++) if(word[i] == now){ count[i]++; aaa = false; } if(aaa){ word.push_back(now); count.push_back(1); num = word.size(); } } now = " "; for(int i=0,mmm=0,nnn=0;i<num;i++){ if(mmm < count[i]){ mmm = count[i]; most = i; } if(now.size() < word[i].size()){ now = word[i]; } } cout << word[most] << ' ' << now << endl; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long int ll; const int mod = 1e9+7; const ll inf = 1e18; const double pi = 3.1415926535897932384626; ll mpow(ll a,ll b,ll m){ ll res=1; while(b){ if(b%2) res=res*a%m; a=a*a%m; b/=2; } return res; } ll inv(ll a,ll m){ return mpow(a,m-2,m); } ll gcd(ll a,ll b){ if(b==0) return a; return gcd(b,a%b); } void solve(){ int n; cin>>n; string s,t; cin>>s>>t; for(int i=0;i<n;i++) cout<<s[i]<<t[i]; } int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); solve(); return 0; }
0
58,556,772
#include <bits/stdc++.h> using namespace std; int main() { string a; cin >> a; cout << (('a' <= a[0] && a[0] <='z')? 'a' : 'A') << endl; }
#include <iostream> using namespace std; int main() { double x1, y1, x2, y2, x3, y3, xp, yp; double a, b, c; while(cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> xp >> yp) { a = (x3 - x2)*(yp - y2) - (y3 - y2)*(xp - x2); b = (x1 - x3)*(yp - y3) - (y1 - y3)*(xp - x3); c = (x2 - x1)*(yp - y1) - (y2 - y1)*(xp - x1); if((a >= 0 && b >= 0 && c >= 0) || (a <= 0 && b <= 0 && c <= 0)) { cout << "YES" << endl; } else { cout << "NO" << endl; } } }
0
92,660,422
#include<bits/stdc++.h> using namespace std; typedef vector <int> vi; typedef pair< int ,int > pii; #define endl "\n" #define f0(i,n) for(int i=0;i<n;i++) #define f1(i,n) for(int i=1;i<=n;i++) #define sd(val) scanf("%d",&val) #define ss(val) scanf("%s",&val) #define sl(val) scanf("%lld",&val) #define debug(val) printf("check%d\n",val) #define all(v) v.begin(),v.end() #define pb push_back #define MP make_pair #define FF first #define SS second #define int long long #define MOD 1000000007 #define clr(val) memset(val,0,sizeof(val)) #define what_is(x) cerr << #x << " is " << x << endl; #define OJ \ freopen("input.txt", "r", stdin); \ freopen("output.txt", "w", stdout); #define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); int frogA(int ind,vector<int>&dp,int n,int arr[]){ if(ind==n-1) return 0; if(dp[ind]!=-1) return dp[ind]; int c1=INT_MAX; c1=abs(arr[ind]-arr[ind+1])+frogA(ind+1,dp,n,arr); int c2=INT_MAX; if(ind+2<=n-1){ c2=abs(arr[ind]-arr[ind+2])+frogA(ind+2,dp,n,arr); } dp[ind]=min(c1,c2); return dp[ind]; } signed main() { FIO; int n; cin>>n; int arr[n]; for(int i=0;i<n;i++) cin>>arr[i]; vector<int>dp(n+1,-1); cout<<frogA(0,dp,n,arr)<<endl; }
#include <bits/stdc++.h> using namespace std; #define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; i++) #define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; i--) #define vi vector<int> #define vs vector<string> #define all(x) (x).begin(),(x).end() int main() { int n,m; cin >> n; vs s(n); repp(i,0,n){ cin >> s[i]; } cin>> m; vs t(m); repp(i,0,m){ cin >> t[i]; } vi cnt(n+1,0); repp(i,0,n){ repp(j,0,n){ if(s[i]==s[j]){ cnt[i]++; } } repp(j,0,m){ if(s[i]==t[j]){ cnt[i]--; } } } cout<< *max_element(all(cnt)) <<endl; }
0
69,017,601
#include<iostream> #include<cmath> #include<cstdio> #include<vector> #include<set> #include<map> #include<stack> #include<queue> #include<utility> #include<algorithm> #include<cstring> #include<sstream> #include <iomanip> using namespace std; typedef long long ll ; typedef double db; typedef vector<int> vi; typedef pair<int,int> pii; typedef vector< pair<int,int> > vii; const double pi = 2*acos(0) ; #define pf printf #define sf scanf #define pb(a) push_back(a) #define mp make_pair #define fi first #define se second #define for0(i,n) for(int i=0;i<n;i++) #define for1(i,n) for(int i=1;i<=n;i++) #define forab(i,a,b) for(int i=a;i<=b;i++) #define lcm(a, b) ((a)*((b)/gcd(a,b))) #define sq(a) (a)*(a) #define nw "\n" #define abs(x) fabs(x) #define pcase(z,x) cout<<"Case "<<z<<": "<<x<<"\n" int main() { string a,b,s; cin>>a; cin>>b; int x = a.size(); int y = b.size(); int n = min(x,y); for0(i,n){ s += a[i]; s += b[i]; } if(x>y) s+=a[x-1]; else if(y>x) s+=b[y-1]; cout<<s<<nw; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define rep(i,n) for(int (i)=0;(i)<(n);(i)++) #define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--) #define itn int #define miele(v) min_element(v.begin(), v.end()) #define maele(v) max_element(v.begin(), v.end()) #define SUM(v) accumulate(v.begin(), v.end(), 0LL) #define lb(a, key) lower_bound(a.begin(),a.end(),key) #define ub(a, key) upper_bound(a.begin(),a.end(),key) #define COUNT(a, key) count(a.begin(), a.end(), key) #define BITCOUNT(x) __builtin_popcount(x) #define pb push_back #define all(x) (x).begin(),(x).end() #define F first #define S second using P = pair <int,int>; using WeightedGraph = vector<vector <P>>; using UnWeightedGraph = vector<vector<int>>; const long long INF = 1LL << 60; const int MOD = 1000000007; void YN(bool flg) {cout<<(flg?"YES":"NO")<<'\n';} void Yn(bool flg) {cout<<(flg?"Yes":"No")<<'\n';} void yn(bool flg) {cout<<(flg?"yes":"no")<<'\n';} template <typename T> int getIndexOfLowerBound(vector <T> &v, T x){ return lower_bound(v.begin(),v.end(),x)-v.begin(); } template <typename T> int getIndexOfUpperBound(vector <T> &v, T x){ return upper_bound(v.begin(),v.end(),x)-v.begin(); } 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; } #define DUMPOUT cerr #define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++) template <typename T, typename U> istream &operator>>(istream &is, pair<T,U> &p_var) { is >> p_var.first >> p_var.second; return is; } template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; } template <typename T> istream &operator>>(istream &is, vector<vector<T>> &df) { for(int i=0;i<df.size();i++)for(int j=0;j<df[i].size();j++) is >> df[i][j]; return is; } template <typename T, typename U> ostream &operator<<(ostream &os, pair<T, U> &pair_var) { DUMPOUT<<'{'; os << pair_var.first; DUMPOUT<<','; os << " "<< pair_var.second; DUMPOUT<<'}'; return os; } template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) { DUMPOUT<<'['; for (int i = 0; i < vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : " "); DUMPOUT<<']'; return os; } template <typename T> ostream &operator<<(ostream &os, vector<vector<T>> &df) { for (auto& vec : df) os<<vec; return os; } template <typename T, typename U> ostream &operator<<(ostream &os, map<T, U> &map_var) { DUMPOUT << "{"; repi(itr, map_var) { os << *itr; itr++; if (itr != map_var.end()) DUMPOUT << ", "; itr--; } DUMPOUT << "}"; return os; } template <typename T> ostream &operator<<(ostream &os, set<T> &set_var) { DUMPOUT << "{"; repi(itr, set_var) { os << *itr; itr++; if (itr != set_var.end()) DUMPOUT << ", "; itr--; } DUMPOUT << "}"; return os; } void print() {cout << endl;} template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) { cout << head; if (sizeof...(tail) != 0) cout << " "; print(forward<Tail>(tail)...); } void dump_func() {DUMPOUT << '#'<<endl;} template <typename Head, typename... Tail> void dump_func(Head &&head, Tail &&... tail) { DUMPOUT << head; if (sizeof...(Tail) > 0) DUMPOUT << ", "; dump_func(std::move(tail)...); } #ifdef DEBUG_ #define DEB #define dump(...) \ DUMPOUT << " " << string(#__VA_ARGS__) << ": " \ << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" \ << endl \ << " ", \ dump_func(__VA_ARGS__) #else #define DEB if (false) #define dump(...) #endif signed main(void) { cin.tie(0); ios::sync_with_stdio(false); int n; cin>>n; vector <int> a(n); cin>>a; int sum = SUM(a); if(sum%(n*(n+1)/2)) {print("NO"); return 0;} int z = sum/(n*(n+1)/2); rep(i, n){ int sa; if(i == 0) sa = a[n-1] - a[i]; else sa = a[i-1] - a[i]; if((sa+z)%n) {print("NO"); return 0;} int x = (sa+z)/n; if(x<0) {print("NO"); return 0;} dump(i, a[i], a[i-1], x % n, x, sa); } print("YES"); }
0
82,496,445
#include <bits/stdc++.h> #include <algorithm> using namespace std; #define sqr(x) ((x) * (x)) #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() typedef long long ll; const int MOD = 1000000007; const int INF = 1000000007; const ll INFLL = 1000000000000000007LL; void solve() { int N; cin >> N; vector<pair<string, int>> pl; for (int i = 0; i < N; i++) { string s; int t; cin >> s >> t; pl.push_back(make_pair(s, t)); } string X; cin >> X; int ans = 0; bool flag = false; for (auto x : pl) { if (flag) ans += x.second; if (x.first == X) { flag = true; } } cout << ans << endl; } int main() { cin.tie(0); ios::sync_with_stdio(false); solve(); return 0; }
#include <algorithm> #include <cmath> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <queue> #include <set> #include <tuple> #include <vector> using namespace std; #define rep(i, n) for (int64_t i = 0; i < (n); i++) #define irep(i, n) for (int64_t i = 0; i <= (n); i++) #define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--) #define rirep(i, n) for (int64_t i = n; i >= 0; i--) int64_t MOD; int64_t dpow(int64_t x, int64_t y) { if (y == 0) { return 1; } if (y % 2 == 0) { return dpow(x * x % MOD, y / 2); } else { return x * dpow(x, y - 1) % MOD; } } int64_t inv(int64_t x) { return dpow(x, MOD - 2); } int main() { int N; cin >> N >> MOD; string s; cin >> s; int64_t result = 0; int d = 0; vector<int64_t> dp(MOD, 0); dp[0] = 1; rep(i, N) { d = 10 * d + (s[i] - '0'); d %= MOD; if (MOD == 2 || MOD == 5) { result += (d % MOD == 0 ? i + 1 : 0); } else { int shift = dpow(10, i + 1); int key = d * inv(shift) % MOD; result += dp[key]; dp[key]++; } } cout << result << endl; return 0; }
0
32,368,174
#include <iostream> #include <string> #include <algorithm> #include <vector> #include <iomanip> #include <cmath> #include <queue> #include <stack> #include <cstdlib> #include <map> #include <iomanip> #include <set> #include <stdio.h> #include <ctype.h> using namespace std; #define pie 3.141592653589793238462643383279 #define mod 1000000007 #define INF 1145141919364364 #define int long long #define all(vec) vec.begin(),vec.end() #define P pair<int,int> #define S second #define F first int gcd(int x, int y) { if (y == 0)return x; return gcd(y, x%y); } int lcm(int x, int y) { return x / gcd(x, y)*y; } bool prime(int x) { for (int i = 2; i <= sqrt(x); i++) { if (x%i == 0)return false; } return true; } int kai(int x, int y) { int res = 1; for (int i = x - y + 1; i <= x; i++) { res *= i; res %= mod; } return res; } int mod_pow(int x, int y, int m) { int res = 1; while (y > 0) { if (y & 1) { res = res * x % m; } x = x * x % m; y >>= 1; } return res; } int comb(int x, int y) { if (y > x)return 0; return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod; } int n, k, a[20]; bool bl[20]; int ans = INF; signed main() { cin >> n >> k; for (int i = 0; i < n; i++)cin >> a[i]; for (int i = 0; i <= (1 << n); i++) { int cnt = 0; for (int j = 0; j < n; j++) { if (i&(1 << j)) { cnt++; bl[j] = true; } else bl[j] = false; } if (cnt < k)continue; int ma = 0; int cnt2 = 0; for (int i = 0; i < n; i++) { if (bl[i] && a[i] <= ma) { cnt2 += ma - a[i] + 1; ma++; } else if (ma < a[i])ma = a[i]; } ans = min(ans, cnt2); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define d(x) cerr << #x ":" << x << endl; #define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl #define rep(i, n) for (int i = (int)(0); i < (int)(n); i++) #define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define all(v) v.begin(), v.end() #define dump(v) \ cerr << #v ":[ "; \ for (auto macro_vi : v) { \ cerr << macro_vi << " "; \ } \ cerr << "]" << endl; #define ddump(v) \ cerr << #v ":" << endl; \ for (auto macro_row : v) { \ cerr << "["; \ for (auto macro__vi : macro_row) { \ cerr << macro__vi << " "; \ } \ cerr << "]" << endl; \ } using lint = long long; const int INF = 1e9; const lint LINF = 1e18; const lint MOD = 1e9 + 7; const double EPS = 1e-10; int main() { string S; cin >> S; int N = S.size(); int head = 0, tale = N; int ans = 0; while (head < tale) { if (S[head] == S[tale - 1]) head++, tale--; else { if (S[head] == 'x') { ans++; head++; } else if (S[tale - 1] == 'x') { ans++; tale--; } else { cout << -1 << endl; return 0; } } } cout << ans << endl; return 0; }
0
86,624,917
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MM = 1000000000; const int MOD = MM + 7; const int MAX = 510000; #define rep(i, n) for(ll i=0; i<n; i++) #define Rep(i, j, n) for(ll i=j; i<n; i++) #define all(vec) vec.begin(), vec.end() 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;} const ll INF = 1LL << 60; int main() { int n, k; cin >> n >> k; set<int> s; rep(i, k) { int d; cin >> d; rep(j, d) { int a; cin >> a; s.insert(a); } } cout << n - s.size() << endl; }
#include <algorithm> #include <bitset> #include <tuple> #include <cstdint> #include <cstdio> #include <cctype> #include <assert.h> #include <stdlib.h> #include <stdio.h> #include <cassert> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <limits> #include <map> #include <memory> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #include <math.h> using namespace std; using ll = long long; using vl = vector<long long>; using vll = vector<vector<long long>>; using vs = vector<string>; using vc = vector<char>; using vcc = vector<vector<char>>; using vm = vector<short>; using vmm = vector<vector<short>>; signed main() { ll n; ll a; ll count = 0; ll ans = 1; ll kako = 0; cin >> n; for (int i = 0; i <= n; i++) { a = i; for (int j = 0; j < 10; j++) { if (a % 2 == 0) { a = a / 2; count++; } else { if (count >= kako) { kako = count; ans = i; } } } count = 0; } cout << ans << endl; }
0
92,139,259
#include <queue> #include <stack> #include <map> #include <algorithm> #include <iostream> #include <math.h> #include <stdio.h> #include <string.h> #include <vector> #include <complex> typedef long long int LL; typedef unsigned long long int ULL; using namespace std; int s[2005], t[2005]; const LL M = (LL)1e9 + 7; LL r_fix[2005][2005]; LL s_pre_t_fix[2005][2005]; LL s_fix_t_pre[2005][2005]; LL total[2005][2005]; int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) { scanf("%d", &s[i]); } for (int i = 1; i <= m; i++) { scanf("%d", &t[i]); } for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (s[i] == t[j]) { r_fix[i][j] = (total[i - 1][j - 1] + 1) % M; } else { r_fix[i][j] = 0; } s_fix_t_pre[i][j] = (s_fix_t_pre[i][j - 1] + r_fix[i][j]) % M; total[i][j] = (total[i - 1][j] + s_fix_t_pre[i][j]) % M; } } printf("%lld\n", total[n][m] + 1); }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0; i<(int)n; i++) #define rep2(i,a,n) for(int i=(a); i<(int)(n); i++) #define all(vec) vec.begin(),vec.end() using ll = long long; using vi = vector<int>; using vs = vector<string>; using vvi = vector<vi>; using vll = vector<ll>; using pii = pair<int, int>; using psi = pair<string, int>; const int dx[4] = {1, 0,-1, 0}; const int dy[4] = {0, 1, 0,-1}; const ll mod = 1e9+7; int gcd(int a, int b){if(a<b) swap(a,b); if (a%b == 0){return(b);}else{return(gcd(b, a%b));}} int lcm(int a, int b){return a * b / gcd(a, b);} long long N, M, K, H, W, L, R; int main(){ cin >> N >> H; int at1 = 0; vi at2(N); rep(i,N){ int a; cin >> a; at1 = max(at1, a); cin >> at2[i]; } sort(all(at2),greater<int>()); int chkat = 1e9; rep(i,N){ if(at2[i]<at1){chkat=i; break;} } int cnt = 0; rep(i,N){ if(i==chkat){ break; } H = H-at2[i]; cnt++; if(H<=0) break; } if(H>0) cnt += (H+at1-1)/at1; cout << cnt << endl; return 0; }
0
64,084,780
#include <iostream> #include <string> using namespace std; string O,E; int main(){ cin >> O >> E; int o = 0; int e = 0; string ans; for(int i = 0;i < O.length() + E.length();i++){ if(i % 2 == 0){ ans += O[o]; o++; }else{ ans += E[e]; e++; } } cout << ans << endl; }
#include <iostream> #include <vector> #include <algorithm> using namespace std; using ll = long long; const int MAX = 1e5+10; const int MOD = 1e9+7; int main(){ int N,M; cin >> N >> M; vector<ll> x(N), y(M); for(int i=0;i<N;i++) cin >> x[i]; for(int i=0;i<M;i++) cin >> y[i]; ll x_sum = 0ll; ll y_sum = 0ll; for(int i=1;i<N;i++){ ll x_tmp = x[i] - x[i-1]; x_sum += x_tmp * i * (N-i); x_sum %= MOD; } for(int j=1;j<M;j++){ ll y_tmp = y[j] - y[j-1]; y_sum += y_tmp * j * (M-j); y_sum %= MOD; } cout << (x_sum * y_sum) % MOD << endl; return 0; }
0
86,039,974
#include <iostream> #include <vector> using namespace std; int main(void) { int n, j, num = 0; cin >> n; vector<int> height(n, 0); for(int i = 0; i < n; i++) cin >> height.at(i); for(int i = 0; i < n;) { if(height.at(i) == 0) { i++; continue; } for(j = i; j < n; j++) { if(height.at(j) == 0) { break; } } for(int k = i; k < j; k++) { height.at(k)--; } num++; } cout << num << endl; }
#include<iostream> using namespace std; int main(){ char a,b; cin>>a>>b; bool reverse=true; if(a=='H'){ reverse=false; } if(reverse){ cout<<(b=='H'?'D':'H'); } else{ cout<<b; } }
0
9,652,363
#include <bits/stdc++.h> using namespace std; int main() { int a, b; int x, y; cin >> a >> b; x = (a + b) / 2; y = (a + b) % 2; cout << x + y << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i = 0; i < (n); i++) #define all(v) begin(v),end(v) using ll = long long; int main() { int h,w,k;cin>>h>>w>>k; vector<vector<char>> c(h,vector<char>(w)); rep(i,h)rep(j,w)cin>>c[i][j]; int ans=0; rep(bit1,1<<h)rep(bit2,1<<w){ vector<int> H(h),W(w); rep(i,h)rep(j,w){ if(bit1&(1<<i)){ if(c[i][j]=='#')H[i]=1; } if(bit2&(1<<j)){ if(c[i][j]=='#')W[j]=1; } } int cnt=0; rep(i,h){ if(H[i]==1)continue; rep(j,w){ if(W[j]==0){ if(c[i][j]=='#')cnt++; } } } if(cnt==k)ans++; } cout<<ans<<endl; }
0
57,385,383
#include <bits/stdc++.h> using namespace std; int main() { string A,B,C; cin >> A >> B >> C; bool a=false; if(A.at(A.size()-1)==B.at(0)){ if(B.at(B.size()-1)==C.at(0)) a=true; } if(a)cout << "YES" << endl; else cout << "NO" << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll, ll> Pair; typedef vector<ll> vll; typedef vector<vector<ll>> Graph; typedef vector<string> vs; typedef vector<pair<ll, ll>> Pll; typedef queue<ll> qll; #define REP(i,n) for(ll i=0;i<(ll)(n);i++) #define REPD(i,n) for(ll i=n-1;i>=0;i--) #define REPA(i,a) for(ll i=0;i<(ll)(a.size());i++); #define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++) #define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--) #define COUT(a) cout << (a) << endl; #define ENDL(a) cout << endl; #define COUTA(i,a) for(ll i=0;i<(ll)(a.size());i++) {cout << (a)[i] << " ";} cout << endl; #define pb push_back #define paired make_pair #define ALL(a) (a).begin(),(a).end() #define SORT(a) sort((a).begin(),(a).end()) #define RSORT(a) sort((a).rbegin(), (a).rend()) #define YES cout << "YES" << endl; #define NO cout << "NO" << endl; #define Yes cout << "Yes" << endl; #define No cout << "No" << endl; #ifdef _DEBUG #define debug(x) cout << "[debug] " << #x << ": " << x << endl #else #define debug(x) #endif template <typename T> void debugV(const vector<T> v) { #ifdef _DEBUG rep(i, v.size()) { cout << i << ":" << v[i] << " "; } cout << endl; #else (void)v; #endif } const unsigned int BIT_FLAG_0 = (1 << 0); const unsigned int BIT_FLAG_1 = (1 << 1); const unsigned int BIT_FLAG_2 = (1 << 2); const unsigned int BIT_FLAG_3 = (1 << 3); const unsigned int BIT_FLAG_4 = (1 << 4); const unsigned int BIT_FLAG_5 = (1 << 5); const unsigned int BIT_FLAG_6 = (1 << 6); const unsigned int BIT_FLAG_7 = (1 << 7); const unsigned int BIT_FLAG_8 = (1 << 8); const unsigned int BIT_FLAG_9 = (1 << 9); const unsigned int BIT_FLAG_10 = (1 << 10); const unsigned int BIT_FLAG_11 = (1 << 11); constexpr ll INF = 0x3f3f3f3f3f3f3f3f; constexpr double PI=3.14159265358979323846; constexpr int MOD = 1000000007; struct UnionFind { vll data; UnionFind(ll sz) { data.assign(sz, -1); } bool unite(ll x, ll y) { x = find(x); y = find(y); if (x == y) { return (false); } if (data[x] > data[y]) { swap(x, y); } data[x] += data[y]; data[y] = x; return (true); } ll find(ll k) { if(data[k] < 0) { return (k); } return (data[k] = find(data[k])); } ll size(ll k) { return (-data[find(k)]); } ll same(ll x, ll y) { return (find(x) == find(y)); } }; void Main() { string n; cin >> n; ll count = 0; REP(i, n.length()) { count += n[i] - '0'; } if (count % 9 == 0) { Yes; } else { No; } } int main() { cin.tie(0); ios_base::sync_with_stdio(false); cout << fixed << setprecision(15); Main(); }
0
48,266,870
#include <cstdio> int main(void){ int n, x, min = 1000000, max = -1000000; long long sum = 0; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &x); sum += x; if (x < min) min = x; if (x > max) max = x; } printf("%d %d %lld\n", min, max, sum); return 0; }
#include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <cctype> #include <climits> #include <iostream> #include <string> #include <bitset> #include <vector> #include <map> #include <list> #include <stack> #include <queue> #include <algorithm> using namespace std; #define ALL(g) (g).begin(), (g).end() #define REP(i, x, n) for(int i = x; i < n; i++) #define rep(i, n) REP(i, 0, n) #define INF 1 << 30 #define pb push_back #define mp make_pair typedef pair<int, int> pii; typedef pair<long, long> pll; typedef long long ll; static const int MAX = 100000; vector<int> G[MAX]; vector<int> out; int V[MAX]; int N; int indeg[MAX]; void bfs(int s) { queue<int> q; q.push(s); V[s] = 1; while (!q.empty()) { int u = q.front(); q.pop(); out.push_back(u); rep(i, G[u].size()) { int v = G[u][i]; indeg[v]--; if (indeg[v] == 0 && V[v] == 0) { V[v] = 1; q.push(v); } } } } void tsort(void) { rep(i, N) { V[i] = 0; indeg[i] = 0; } rep(i, N) { rep(j, G[i].size()) { indeg[G[i][j]]++; } } rep(i, N) { if (indeg[i] == 0 && V[i] == 0) bfs(i); } } int main(void) { int M, s, t; scanf("%d %d", &N, &M); rep(i, M) { scanf("%d %d", &s, &t); G[s].push_back(t); } tsort(); rep(i, out.size()) printf("%d\n", out[i]); return 0; }
0
13,749,529
#include <bits/stdc++.h> #define f(i,a,b) for( ll i = a; i < b ; i++ ) #define af(i,a,b) for( ll i = a; i >= b ; i--) #define rep(i,a,b,k) for(ll i = a; i < b ; i+= k ) #define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k) #define ones(x) (ll) __builtin_popcount(x) #define fs first #define sc second #define pb push_back #define po pop_back #define mp make_pair #define sz(a) (ll) a.size() #define all(a) a.begin(), a.end() #define sor(a) sort( a.begin(), a.end() ) #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL) #define ller ios::sync_with_stdio(false);cin.tsie(nullptr);cout.tie(nullptr) #define watch(x) cout << (#x) << " is " << (x) <<"#" <<endl #define PI 3.1415926535 using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll,ll> ii ; typedef vector<ll> vi ; typedef vector<ii> vii ; const ll mod = 998244353; const ll MAX = 3e3+23; const ll inf = 1e18+7; int main(){ fastio; string s; cin>>s; ll cont =0; f(i,0,sz(s)){ if(s[i]=='A') cont++; } if(cont==2 || cont==1) cout<<"Yes\n"; else cout<<"No\n"; return 0; }
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i = 0;i < (n);i++) using ll = long long; const ll MOD=1000000007; int main() { ll H,W; cin>>H>>W; vector<string> Grid(H); rep(i,H) { cin>>Grid.at(i); } vector<ll> tatejiku(0); string hoge=""; rep(i,W) { hoge+="."; } rep(i,H) { if(Grid.at(i)!=hoge) {tatejiku.push_back(i);} } vector<ll> yokojiku(0); rep(i,W) { rep(j,H) { if(Grid.at(j).at(i)=='#') {yokojiku.push_back(i); break;} } } for(auto p:tatejiku) { for(auto q:yokojiku) { cout<<Grid.at(p).at(q); } cout<<endl; } return 0; }
0
86,615,518
#include <bits/stdc++.h> using namespace std; int main() { long long n, a[100010]; long long sum = 1, ans = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); for (long long i = 0; i < n; i++) { if (a[i] == 0) { cout << 0 << endl; return 0; } if (sum > 1000000000000000000 / a[i]) { ans = -1; break; } sum *= a[i]; } if (ans != -1) { ans = sum; } printf("%lld\n", ans); return 0; }
#include <bits/stdc++.h> #define rep(i, n) for(long long int i = 0; i < n; i++) #define _rep(i, m, n) for(long long int i = m; i < n; i++) using namespace std; typedef long long ll; typedef pair<int, int> P; const ll mod = 1000000007; using Graph = vector<vector<int>>; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; ll gcd(ll A, ll B){ if(B == 0)return A; return gcd(B, A % B); } ll lcm(ll A, ll B){ return A * (B / gcd(A, B)); } int main(){ int n, p; cin >> n >> p; vector<ll> a(n); rep(i, n) cin >> a[i]; ll dp[60][2]; rep(i, n){ if(i == 0){ if(a[i] % 2 == 0){ dp[i][0] = 2; dp[i][1] = 0; }else{ dp[i][0] = 1; dp[i][1] = 1; } continue; } if(a[i] % 2 == 0){ dp[i][0] = dp[i - 1][0] * 2; dp[i][1] = dp[i - 1][1] * 2; }else{ dp[i][0] = dp[i - 1][0] + dp[i - 1][1]; dp[i][1] = dp[i - 1][0] + dp[i - 1][1]; } } if(p % 2 == 0)cout << dp[n - 1][0] << endl; else cout << dp[n - 1][1] << endl; }
0
23,832,371
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < n; ++i) #define ALL(c) (c).begin(), (c).end() #define SUM(x) std::accumulate(ALL(x), 0LL) #define MIN(v) *std::min_element(v.begin(), v.end()) #define MAX(v) *std::max_element(v.begin(), v.end()) #define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end()) using namespace std; using ll = long long; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> inline void dump(vector<T> v) { for (auto& x : v) cerr << x << " "; cerr << endl; } template<class T> inline void dump(vector<pair<T, T>> v) { for (auto& p : v) cerr << p.first << " " << p.second << endl; } template<class T> inline void dump(vector<vector<T>> vv) { for (auto& v : vv) {for (auto& x : v) cerr << x << " "; cerr << endl;} } constexpr int INF = 1e9+5; constexpr long long INFLL = 1LL<<62; constexpr double eps = (1e-9); int main() { cin.tie(0); ios::sync_with_stdio(false); int h, w, a, b; cin >> h >> w >> a >> b; rep(i, b) { rep(j, a) cout << 0; rep(j, w-a) cout << 1; cout << endl; } rep(i, h-b) { rep(j, a) cout << 1; rep(j, w-a) cout << 0; cout << endl; } return 0; }
#include <assert.h> #include <limits.h> #include <algorithm> #include <bitset> #include <cctype> #include <cmath> #include <complex> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <vector> using ll = long long; using P = std::pair<ll, ll>; #define rep(i, a, b) for (ll(i) = (a); i < (b); i++) #define all(i) i.begin(), i.end() #define debug(i) std::cerr << "debug " << i << std::endl template <typename T1, typename T2> std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) { return os << pa.first << " " << pa.second; } template <typename T> std::ostream& operator<<(std::ostream& os, std::vector<T> vec) { for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " "); return os; } template<typename T1,typename T2> inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);} template<typename T1,typename T2> inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);} const ll MOD = 1e9 + 7; ll pow_mod(ll a, ll b, ll mod=-1) { if ((a == 0)||(mod!=-1&&a%mod==0)) { return 0; } ll x = 1; while (b > 0) { if (b & 1) { x = (mod!=-1)?(x * a) % mod:x*a; } a = (mod!=-1)?(a * a) % mod:a*a; b >>= 1; } return x; } int main() { std::cin.tie(0); std::ios::sync_with_stdio(false); ll n; std::cin>>n; std::vector<ll> temp(n,-1); ll side; rep(i,0,n+1){ ll a; std::cin>>a; a--; if(temp[a]>=0){ side=temp[a]+(n-i); break; } temp[a]=i; } std::vector<ll> conv(n+2),conv_side(side+1); conv[0]=1;conv_side[0]=1; rep(i,1,n+2){ conv[i]=(((conv[i-1]*(n+2-i))%MOD)*pow_mod(i,MOD-2,MOD))%MOD; } rep(i,1,side+1){ conv_side[i]=(((conv_side[i-1]*(side+1-i))%MOD)*pow_mod(i,MOD-2,MOD))%MOD; } rep(i,1,n+2){ if(i-1<=side)std::cout<<(conv[i]-conv_side[i-1]+MOD)%MOD<<"\n"; else std::cout<<conv[i]<<"\n"; } return 0; }
0
96,905,055
#include<bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int,int>; #define rep(i,n) for(int i=0; i<n; i++) #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) #define INF 2147483647 #define LLINF 9223372036854775807LL int d[] = {1,0,-1,0,1}; int main(){ int h,w; cin>>h>>w; char C[1010][1010]; for(int i=1; i<=h; i++){ for (int j=1; j<=w; j++) cin >> C[i][j]; } int V[1010][1010] = {0}; queue<pii> Q; for(int i=1; i<=h; i++){ for (int j=1; j<=w; j++){ if (C[i][j] == '#'){ V[i][j] = 1; Q.push(make_pair(i,j)); } } } while(!Q.empty()){ int tmp_h = Q.front().first; int tmp_w = Q.front().second; Q.pop(); rep(i,4){ if (V[tmp_h+d[i]][tmp_w+d[i+1]] == 0 && tmp_h+d[i] >= 1 && tmp_h+d[i] && tmp_h+d[i] <= h && tmp_w+d[i+1] >= 1 && tmp_w+d[i+1] <= w){ V[tmp_h+d[i]][tmp_w+d[i+1]] = V[tmp_h][tmp_w] + 1; Q.push(make_pair(tmp_h+d[i], tmp_w+d[i+1])); } } } int ans = -1; for(int i=1; i<=h; i++){ for (int j=1; j<=w; j++){ ans = max(ans, V[i][j]); } } cout << ans - 1 << endl; }
#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>; #define chmax(x,y) x = max(x,y); #define chmin(x,y) x = min(x,y); const int di[] = {-1, 0, 1, 0}; const int dj[] = {0, -1, 0, 1}; const int INF = 1001001001; int main() { int n; cin >> n; map<int,int> a, b; rep(i,n) { int v; cin >> v; if (i%2) a[v]++; else b[v]++; } priority_queue<P> ap, bp; for (auto p : a) { ap.emplace(p.second, p.first); } for (auto p : b) { bp.emplace(p.second, p.first); } vector<P> x, y; int cnt = 2; while (!ap.empty() && cnt > 0) { auto p = ap.top(); ap.pop(); x.push_back(p); cnt--; } cnt = 2; while (!bp.empty() && cnt > 0) { auto p = bp.top(); bp.pop(); y.push_back(p); cnt--; } int ans = INF; rep(i,x.size())rep(j,y.size()) { int now = 0; if (x[i].second == y[j].second) { now = n/2 + n/2 - max(x[i].first, y[j].first); } else { now = n - x[i].first - y[j].first; } ans = min(ans, now); } cout << ans << endl; return 0; }
0
12,371,479
#include <cstdlib> #include <string> #include <iostream> std::string get_in_circle(int w, int h, int x, int y, int r) { std::string res; if (x >= 0 + r && y >= 0 + r && x <= w -r && y <= h - r) { res = std::string {"Yes"}; } else { res = std::string {"No"}; } return res; } int main() { int w, h, x, y, r; std::cin >> w >> h >> x >> y >> r; std::cout << get_in_circle(w, h, x, y, r) << std::endl; return EXIT_SUCCESS; }
#include <iostream> #include <iomanip> #include <cstdio> #include <queue> #include <cstring> #include <vector> #include <map> #include <algorithm> #include <cctype> #include <cmath> #include <bitset> #include <set> #include <stack> using namespace std; #define REP(i,n) for(int i=0;i<(int)(n);i++) #define RREP(i,n) for(int i=n-1;i>=0;i--) #define FOR(i,k,n) for(int i=(k);i<(int)(n);i++) #define all(i,n) (i),(i+n) int dx4[4]={1,0,-1,0}; int dy4[4]={0,-1,0,1}; int dx8[8]={1,0,-1,1,-1,1,0,-1}; int dy8[8]={1,1,1,0,0,-1,-1,-1}; int dx9[9]={0,1,0,-1,1,-1,1,0,-1}; int dy9[9]={0,1,1,1,0,0,-1,-1,-1}; typedef pair<int, int> P; typedef pair<string, int> SP; typedef long long ll; typedef pair<ll, ll> PLL; const int INF = 1e9; const ll LLINF = 1e18; const int MAX_V = 1e6+1; const ll mod = 1000000007; int n, q; vector<int> g[200005]; void dfs(int now, int from, vector<int> &ans, int sum) { sum += ans[now]; ans[now] = sum; for(int u : g[now]) { if(u == from) continue; dfs(u, now, ans, sum); } } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> n >> q; REP(i, n - 1) { int a, b; cin >> a >> b; a--; b--; g[a].push_back(b); g[b].push_back(a); } vector<int> ans(n, 0); REP(i, q) { int p, x; cin >> p >> x; p--; ans[p] += x; } dfs(0, -1, ans, 0); REP(i, n) cout << ans[i] << " "; cout << endl; }
0
6,071,067
#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() 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; } typedef long long ll; const long long INF = 1LL << 60; const long long MOD = 1e9 + 7; typedef pair<int, int> P; int main() { int N, M; cin >> N >> M; set<int> st; rep(i, M) { int A; cin >> A; st.insert(A); } vector<ll> dp(N + 2); dp[0] = 1; rep(i, N) { if (st.count(i + 1) == 0) { dp[i + 1] += dp[i]; dp[i + 1] %= MOD; } if (st.count(i + 2) == 0) { dp[i + 2] += dp[i]; dp[i + 2] %= MOD; } } cout << dp[N] % MOD << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i = 0; i < (int)(n); ++i) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) int main() { int N,M; cin >>N>>M; vector<int>a(M),b(M),c(M); rep(i,M){ cin>>a.at(i)>>b.at(i)>>c.at(i); a.at(i)--; b.at(i)--; } vector<vector<int>>d(N,vector<int>(N)); rep(i,N){ rep(j,N){ if(i==j){ d.at(i).at(j)=0; } else{ d.at(i).at(j)=1001001001; } } } rep(i,M){ d.at(a.at(i)).at(b.at(i))=c.at(i); d.at(b.at(i)).at(a.at(i))=c.at(i); } for(int k = 0; k < N; k++) { for(int i = 0; i < N; i++) { for(int j = 0; j < N; j++) { d[i][j] =min(d[i][j], d[i][k] + d[k][j]); } } } int ans=M; rep(i,M){ bool ex=false; rep(j,N){ if(d.at(j).at(a.at(i))+c.at(i)==d.at(j).at(b.at(i))){ ex=true; } } if(ex){ ans--; } } cout<<ans<<endl; }
0
6,160,463
#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 <cctype> using namespace std; int main() { string S; cin >> S; bool A = false; for (int i = 0; i < S.size(); i++) { for (int j = 0; j < S.size() && j<i; j++) { if (S.at(i) == S.at(j)) { A = true; } } } if (A == true) { cout << "no" << endl; } else { cout << "yes" << endl; } }
#include <iostream> #include <algorithm> #include <string> #include <vector> #include <set> #include <cmath> #include <stdio.h> #include <list> #include <numeric> #include <stack> #include <queue> #include <tuple> #include <bitset> #include <map> #include <math.h> using namespace std; #define rep(i,n) for(int i = 0; i < (n); i++) typedef long long ll; typedef pair<int,int> P; const int inf=1000000007; const ll mod=1000000007; const double PI=3.14159265358979323846; int dx[] = {1,-1,0,0}; int dy[] = {0,0,1,-1}; int main(){ int N; cin >> N; int P[N]; int Q[N]; int ord[N]; rep(i,N) { cin >> P[i]; ord[i] = i+1; } rep(i,N) { cin >> Q[i]; } int a,b; int cnt = 0; do { bool fa = true; bool fb = true; rep(i,N) { if(ord[i] != P[i]) fa = false; if(ord[i] != Q[i]) fb = false; } if(fa) a = cnt; if(fb) b = cnt; cnt++; }while(next_permutation(ord,ord+N)); cout << abs(a-b) << endl; return 0; }
0
86,790,442
#include <bits/stdc++.h> using namespace std; const long long int INF = 1e18; int main(){ int n, k; cin >> n >> k; vector<int> h(n+1); for(int i=1; i<=n; i++){ cin >> h[i]; } vector<vector<long long int>> dp(n-k+1, vector<long long int>(n+1, INF)); dp[0][0] = 0; for(int i=1; i<=n-k; i++){ for(int j=1; j<=n; j++){ for(int l=0; l<j; l++){ dp[i][j] = min(dp[i][j], dp[i-1][l] + max(0, h[j] - h[l])); } } } long long int ans = INF; for(int j=0; j<=n; j++){ ans = min(ans, dp[n-k][j]); } cout << ans << endl; return 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; #define rep(i,n) for(int (i) = 0; (i) < (int)(n); (i)++) #define debug(var) do{std::cout << #var << " : ";view(var);}while(0) template<typename T> void view(T e){std::cout << e << std::endl;} template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;} template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } } 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; } void Yes(){cout << "Yes" << endl;} void No(){cout << "No" << endl;} void YES(){cout << "YES" << endl;} void NO(){cout << "NO" << endl;} void err() {cout << -1 << endl;} #define all(x) (x.begin(), x.end()) const int MOD = 1000000007; const int INF = 1e9; #define PI acos(-1); int dx[4] = {1,-1,0,0}; int dy[4] = {0,0,1,-1}; int ddx[8] = {1,1,1,-1,-1,-1,0,0}; int ddy[8] = {0,1,-1,0,1,-1,1,-1}; int main(){ string s; cin >> s; map<char, int> mp; for(auto c : s) { mp[c]++; } bool ok = true; for(auto p : mp) { if(p.second != 2) ok = false; } if(ok) Yes(); else No(); }
0
26,875,039
#include<bits/stdc++.h> using namespace std; #define N 100010 #define ll long long int main() { ll a,b,c,d; cin>>a>>b>>c>>d; ll ans = max(max(max(a*c,a*d),b*c),b*d); cout<<ans; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define endl '\n' #define F first #define S second #define umap unordered_map #define uset unordered_set #define test ll cases; cin>>cases; for(ll testCase = 1; testCase <= cases; testCase++) #define fill(name, val) memset(name, val, sizeof(name)); #define mop(a, op, b) (a%mod op b%mod)%mod #define precise fixed<<setprecision(50) #define vll vector<ll> #define vvll vector<vll> #define pll pair<ll, ll> #define get(a, n) for(ll it = 0; it < n; it++) cin>>a[it]; #define boost ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define debug(x) cerr << #x << " : " << (x) << endl #define MX 100001 #define mod 1000000007LL #define inf 1000000000000000000LL void init(){ boost; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } int main(){ init(); ll n, k; cin>>n>>k; ll a[n]; get(a, n); ll dp[n+1][k+1]; dp[0][0] = 1; for(ll i = 1; i <= k; i++) dp[0][i] = 0; for(ll i = 1; i <= n; i++){ dp[i][0] = 1; for(ll j = 1; j <= k; j++){ dp[i][j] = mop(dp[i][j-1], +, dp[i-1][j]); if(j >= a[i-1] + 1) dp[i][j] = (dp[i][j] + mod - dp[i-1][j-a[i-1]-1])%mod; } } cout<<dp[n][k]; }
0
42,283,432
#include <functional> #include <iostream> #include <vector> #include <set> #include <algorithm> #include <queue> #include <string> #include <cstring> #include <math.h> using namespace std; int main() { int n,m,l; cin >> n >> m >> l; int a[n]; for(int i = 0;i<n;i++){ cin >> a[i]; } int ans = 0; for(int i = 0;i<n;i++){ int sum = 0; for(int k = 0;k<100000;k++){ if(1 + k*a[i]>=m+1){ break; } sum = sum + 1; } ans = ans + sum; } cout << ans + l << endl; return 0; }
#include<iostream> #include<algorithm> #include<vector> using namespace std; int main(){ int n,k; cin>>n>>k; vector<int>v(n); for(int i=0;i<n;i++) { cin>>v[i]; } sort(v.begin(),v.end()); int sum=0; for(int i=v.size()-1;i>=n-k;i--) { sum+=v[i]; } cout<<sum; }
0
22,549,104
#include <iostream> #include <vector> using namespace std; int main() { int N; cin >> N; if( N >= 2){ vector<unsigned> f; f.push_back(1); f.push_back(1); for(int i = 2; i <= N; i++){ int temp = f.at(i-1) + f.at(i-2); f.push_back(temp); } cout << f.at(N) << endl;; }else{ cout << 1 << endl; } return 0; }
#include <bits/stdc++.h> typedef long long ll; #define fr(i,a,b) for(ll i=a; i<b; i++) #define rf(i,a,b) for(ll i=a; i>=b; i--) typedef std::vector<long long > vi ; #define F first #define S second #define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define mod 1000000007 #define PB push_back #define MP make_pair #define PI 3.14159265358979323846 #define all(a) a.begin(),a.end() #define mx(a) *max_element(all(a)) #define mn(a) *min_element(all(a)) #define endl '\n' #define show(a) for(auto el:a)cout<<el<<" " const ll INF=LLONG_MAX/2; const ll N=2e5+1; #define yesno(f) yes(f);no(f); #define yes(f) if(f)cout<<"YES\n"; #define no(f) if(!f)cout<<"NO\n"; using namespace std; int main() { fast; ll t=1; while(t--) { ll n,i,j=0,a,b; std::cin >> n>>a; if(n<a) cout<<"0\n"; else cout<<"10\n"; } }
0
71,068,698
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/trie_policy.hpp> #include <ext/rope> using namespace std; #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define fi first #define se second #define mp make_pair #define pb push_back #define eb emplace_back #define gcd __gcd #define rep(i,s,end) for(int i = (s); i < (end); ++i) #define rep0(i, end) for(int i = 0; i <= (end); ++i) #define rep1(i, end) for(int i = 1; i <= (end); ++i) #define lb lower_bound #define ub upper_bound #define vt vector #define endl "\n" #define fileopen(filename, in_type, out_type) if (fopen(filename in_type, "r")) {freopen(filename in_type, "r", stdin);freopen(filename out_type, "w", stdout);} #define local_input(x) if (x && fopen("input.txt","r")) freopen("input.txt","r",stdin); #define fastio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL) #define fscan(x) scanf("%d", &x) #define fscandb(x) scanf("%lf", &x) #define fscanll(x) scanf("%lld",&x) #define int ll typedef double db; typedef long long ll; typedef pair<int,int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<bool> vb; typedef vector<pii> vpii; typedef vector<pll> vpll; #define pi 3.1415926535897932 #define mn 100002 int n,m, root = 1; int a[mn]; vi adjlist[mn]; void fuck_no(){cout << "NO"; exit(0);} void dfs(const int& u, const int& p) { if(adjlist[u].size() > 1){ int sum = 0; for(int& i : adjlist[u]) if(i != p){ dfs(i,u); sum += a[i]; if(a[i] > a[u]) fuck_no(); } int x = sum-a[u], y = a[u]-x; if(x < 0 || y < 0) fuck_no(); a[u] = y; } } signed main() { fastio; cin >> n; rep1(i,n){ cin >> a[i]; } if(n == 2){ cout << (a[1] == a[2] ? "YES\n" : "NO\n"); return 0; } rep(i,1,n){ int x,y; cin >> x >> y; adjlist[x].pb(y), adjlist[y].pb(x); if(root == 1){ if(adjlist[x].size() > 1) root = x; if(adjlist[y].size() > 1) root = y; } } dfs(root, 0); cout << (a[root] ? "NO\n" : "YES\n"); return 0; }
#include <bits/stdc++.h> #define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++) #define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--) #define sz(v) (int)(v).size() #define pb push_back #define sc second #define fr first #define sor(v) sort(v.begin(),v.end()) #define rev(s) reverse(s.begin(),s.end()) #define lb(vec,a) lower_bound(vec.begin(),vec.end(),a) #define ub(vec,a) upper_bound(vec.begin(),vec.end(),a) #define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end()) using namespace std; typedef long long int ll; typedef pair <int, int> P; const ll MOD=1000000007; int main() { ios::sync_with_stdio(false); cin.tie(0); int N; cin>>N; vector<int> a(N,0); rep(i,0,N) cin>>a[i]; sor(a); if(N==2){ if(a[0]==1&&a[1]==1) cout <<"Possible"<<"\n"; else cout <<"Impossible"<<"\n"; } else if(a[N-1]%2){ if(!(a[0]==(a[N-1]+1)/2&&a[1]==a[0]&&a[2]!=a[1])) cout <<"Impossible"<<"\n"; else{ rep(i,(a[N-1]+1)/2, a[N-1]+1){ if(ub(a,i)-lb(a,i)<2){ cout <<"Impossible"<<"\n"; return 0; } } cout <<"Possible"<<"\n"; } } else{ if(!(a[0]==a[N-1]/2&&a[1]!=a[0])) cout <<"Impossible"<<"\n"; else{ rep(i,a[N-1]/2+1, a[N-1]+1){ if(ub(a,i)-lb(a,i)<2){ cout <<"Impossible"<<"\n"; return 0; } } cout <<"Possible"<<"\n"; } } }
0
59,680,422
#include<iostream> using namespace std; typedef long long li; #define rep(i,n) for(int i=0;i<(n);i++) #define df 0 template<class T> void print(const T& t){ cout << t << "\n"; } template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); } string q[]={"Vacant","Male","Female"}; int main(){ int n; cin >>n; int a=0,b=n-1; print(a); flush(cout); string s; cin >>s; if(s==q[0]) return 0; int aj=(s==q[1]); print(b); flush(cout); cin >>s; if(s==q[0]) return 0; int bj=(s==q[1]); while(1){ int m=(a+b)/2; print(m); flush(cout); cin >>s; if(s==q[0]) return 0; int mj=(s==q[1]); if((m-a)%2==(mj+aj)%2){ a=m; aj=mj; }else{ b=m; bj=mj; } } }
#include<cstdio> int main(void){ int n, u, k, v; scanf("%d", &n); int a[n+1][n+1]; for (int row = 1; row <= n; ++row) { for (int column = 1; column <= n; ++column) a[row][column] = 0; } for (int vertexi = 0; vertexi < n; ++vertexi) { scanf("%d %d", &u, &k); for (int outi = 0; outi < k; ++outi) { scanf("%d", &v); a[u][v] = 1; } } for (int row = 1; row <= n; ++row) { for (int column = 1; column <= n; ++column) { if(column > 1) printf(" "); printf("%d", a[row][column]); } printf("\n"); } return 0; }
0
89,667,625
#include <bits/stdc++.h> using namespace std; int main(){ int r, g; cin >> r >> g; cout << r * r - g << endl; }
#include <bits/stdc++.h> #include <iomanip> #include <math.h> #include <unistd.h> #include <stdio.h> #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #define all(a) (a).begin(),(a).end() #define vecin(a) rep(i,a.size())cin >> a[i] #define vecout(a) rep(i,a.size()){cout << a[i];cout << (i == a.size() - 1 ? "\n":" ");} #define rep(i,x) for(ll i = 0;i<x;i++) #define REP(i,x) for(ll i = 1;i<=x;i++) #define mp make_pair using ll = long long; using ld = long double; using namespace std; using dou = double; const ll inf = 2147483647; const ll INF = 1LL << 60; const dou pi = 3.14159265358; const ll mod = 1000000007LL; typedef pair<ll,ll> P; using graph = vector<vector<ll>>; template<class T, class U> inline bool chmin(T& a, const U& b){ if(a > b){ a = b; return 1; } return 0; } template<class T, class U> inline bool chmax(T& a, const U& b){ if(a < b){ a = b; return 1; } return 0; } template<class T, class U> inline bool change(T& a,U& b){if(a > b){swap(a,b);return 1;}return 0;} template<class T> T gcd(T a,T b){ if(a < b)swap(a,b); if(a % b == 0)return b; else return gcd(b,a%b); } template<class T> T lcm(T a,T b){ return a / gcd(a,b) * b; } template<class T> inline bool isp(T n){ bool res = true; if(n == 1)return false; else{ for(ll i = 2;i * i <= n;i++){ if(n % i == 0){ res = false; break; } } return res; } } const ll cmax = 1000000; vector<ll> fac(cmax),finv(cmax),inv(cmax); void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (ll i = 2; i < cmax; i++){ fac[i] = fac[i - 1] * i % mod; inv[i] = mod - inv[mod%i] * (mod / i) % mod; finv[i] = finv[i - 1] * inv[i] % mod; } } ll nCk(ll n, ll k){ if(fac[0] == 0)COMinit(); if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % mod) % mod; } ll modpow(ll n,ll m,ll MOD){ if(m == 0)return 1; if(m < 0)return -1; ll res = 1; while(m){ if(m & 1)res = (res * n) % MOD; m >>= 1; n *= n; n %= MOD; } return res; } ll mypow(ll n,ll m){ if(m == 0)return 1; if(m < 0)return -1; ll res = 1; while(m){ if(m & 1)res = (res * n); m >>= 1; n *= n; } return res; } int main(){ ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); struct edge{ll from,to,cost;}; ll N,M; cin >> N >> M; vector<vector<ll>> dist(N,vector<ll>(N,INF)); vector<edge> es(M); rep(i,M){ cin >> es[i].from >> es[i].to >> es[i].cost; es[i].from--;es[i].to--; dist[es[i].from][es[i].to] = es[i].cost; dist[es[i].to][es[i].from] = es[i].cost; } rep(i,N){ dist[i][i] = 0; } rep(i,N){ rep(j,N){ rep(k,N){ chmin(dist[j][k],dist[j][i] + dist[i][k]); } } } ll ans = 0; rep(e,M){ bool ok = 1,go = 0; rep(i,N){ rep(j,N){ if(dist[i][j] == dist[i][es[e].from] + es[e].cost + dist[es[e].to][j]){ ok = 0; go = 1; break; } } if(go)break; } if(ok)ans++; } cout << ans << "\n"; }
0
79,508,424
#include <bits/stdc++.h> using namespace std; long long gcm(long long a, long long b){ if(a % b == 0) return b; a = a % b; return gcm(b, a); } long long lcm(long long a, long long b){ return a / gcm(a, b) * b; } int main() { int n; cin >> n; long long ans = 1; for(int i = 0; i < n; i++){ long long k; cin >> k; ans = lcm(ans, k); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define _GLIBCXX_DEBUG #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) using ll = long long; using ld = long double; #define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++) #define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++) #define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++) #define repr(i,n) for (ll i = (n-1); i>=0;i--) #define repr3(i,n) for(ll i = (n);i>0;i--) #define repr4(i,s,n) for(ll i = (n);i>=(s);i--) #define stlen(s) ll s.size()-1 #define all(v) v.begin(), v.end() #define cout(n) cout<<std::fixed<<std::setprecision(n) using Graph = vector<vector<int>>; using Graphw = vector<vector<pair<ll,ll>>>; #define INF1 INT_MAX; #define INF2 LLONG_MAX; #define PI 3.14159265358979323846; #define MOD 1000000007; int main(){ int N; cin >> N; vector<vector<pair<ll,ll>>> G(N+1); for (int i = 0; i < N-1; ++i) { int a, b; ll c; cin >> a >> b>>c; G[a].push_back(make_pair(b,c)); G[b].push_back(make_pair(a,c)); } vector<ll> dist(N+1, -1); queue<ll> que; int Q,K; cin>>Q>>K; dist[K] = 0; que.push(K); while (!que.empty()) { int v = que.front(); que.pop(); rep(j,G[v].size()) { if (dist[G[v][j].first] != -1) continue; dist[G[v][j].first] = dist[v] + G[v][j].second; que.push(G[v][j].first); } } ll ans[Q]; rep(i,Q){ int x,y; cin>>x>>y; ans[i]=dist[x]+dist[y]; } rep(i,Q){ cout<<ans[i]<<endl; } return 0; }
0
93,784,889
#include <bits/stdc++.h> #include <vector> #include <algorithm> #include <iostream> using namespace std; int main() { int N, K, ans; cin >> N >> K; ans=0; vector<int> l(N); for (int i=0; i<N; i++) { cin >> l[i]; } sort(l.begin(),l.end()); reverse(l.begin(),l.end()); for (int j=0; j<K; j++) { ans=ans+l[j]; } cout << ans << endl; }
#include <bits/stdc++.h> #include <boost/multiprecision/cpp_int.hpp> using namespace std; using ll = long long; using ld = long double; template <class T> using vt = vector<T>; template <class T> using vvt = vector<vector<T>>; template <class T> using vvvt = vector<vector<vector<T>>>; using ml = boost::multiprecision::cpp_int; #define all(c) (c).begin(), (c).end() #define rep(i, b, e) for (ll i = b; i < e; i++) #define repr(i, b, e) for (ll i = b; e < i; i--) #define val(itr) *(itr) #define llong_max 9223372036854775807 #define ldbl_max 1.79769e+308 #define mod 1000000007 #define pi 3.14159265358979323846 #define fori(i, ...) if(ll i = -1) for(__VA_ARGS__) if(i++, true) #define each(i, e, c) fori(i, auto e = c.begin(); e != c.end(); ++e) #define forir(i, v, ...) if(ll i = Size(v)) for(__VA_ARGS__) if(i--, true) #define eachr(i, e, c) forir(i, auto e = c.rbegin(); e != c.rend(); ++e) auto Count = [] (auto b, auto e, auto x) { return (ll)count(b, e, x); }; auto CtoN = [] (auto c) { return (ll)(c - '0'); }; auto DivC = [] (auto a, auto b) { return ceil((ld)a / (ld)b); }; auto Fix = [] (auto b, auto e, auto fix) { for (auto it = b; it != e; ++it)*it += fix; }; auto Pow = [] (auto a, auto b) { return (ll)pow(a, b); }; auto Pow2 = [] (auto n) { return (1LL << n); }; auto Pow10 = [] (auto n) { return (ll)pow(10, n); }; auto Size = [] (auto& c) { return (ll)(c).size(); }; auto Sum = [] (auto b, auto e) { return accumulate(b, e, 0LL); }; template <class T> vvt<T> VVT (ll ys, ll xs, T fill = T()) { vvt<T> v(ys); each(i, y, v) { val(y).resize(xs, fill); } return v; } template <class T> vvvt<T> VVVT (ll zs, ll ys, ll xs, T fill = T()) { vvvt<T> v(zs); each(i, z, v) { val(z) = VVT(ys, xs, fill); } return v; } template <class T> vt<T> InputVT (ll size, T fix = T()) { vt<T> v(size); each(i, e, v) { cin >> val(e); val(e) += fix; } return v; } template <class T> vvt<T> InputVVT (ll ys, ll xs, T fix = T()) { vvt<T> v(ys); each(i, y, v) val(y).resize(xs); each(i, y, v) each(j, x, val(y)) { cin >> val(x); val(x) += fix; } return v; } template <class T> vvvt<T> InputVVVT (ll zs, ll ys, ll xs, T fix = T()) { vvvt<T> v(zs); each(i, z, v) { val(z) = InputVVT<T>(ys, xs, fix); } return v; } struct Engine { ll x; ll y; ld angle; }; auto NyaSort = [](const Engine& l, const Engine& r) { return l.angle < r.angle; }; int main(void) { ll N; cin >> N; vt<Engine> v(N); each(i, e, v) { cin >> e->x >> e->y; e->angle = atan2(e->y, e->x); } sort(all(v), NyaSort); ld ans = 0; rep(i, 0, N) { ll xsum = 0; ll ysum = 0; rep(j, i, i+N) { xsum += v[j % N].x; ysum += v[j % N].y; ans = max(ans, (ld)sqrt(xsum * xsum + ysum * ysum)); } } cout << std::fixed << std::setprecision(12) << ans; return 0; }
0
84,257,395
#include <bits/stdc++.h> #define REP(i, n) for(ll i = 0; i < n; i++) #define ALL(x) (x).begin(),(x).end() #define MSG(x) cout << x << endl; #define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl; #define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl; #define yn(x) x ? cout << "yes" << endl : cout << "no" << endl; using namespace std; using ll = long long; const static ll MOD = 1e9 + 7; int main(int argc, char *argv[]) { string s; cin >> s; MSG(s.substr(0, 4) + " " + s.substr(4)) }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; using Graph = vector<vector<int>>; #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++) #define RRep(i, k, n) for (int i = k; i > (int)(n); i--) #define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl #define ALL(a) (a).begin(),(a).end() 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 (a > b) { a = b; return 1; } return 0; } const long long INF = 1LL << 60; const int MOD = 1000000007; const double PI = acos(-1); const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; int main() { set<char> s; string a; cin >> a; rep(i, a.size()) s.insert(a[i]); cout << (s.size() == 2 ? "Yes" : "No") << endl; }
0
60,067,761
#include<bits/stdc++.h> #define range(i,a,b) for(int i = (a); i < (b); i++) #define rep(i,b) range(i,0,b) #define debug(x) cout << "debug" << x << endl; using namespace std; int main(){ int x,y; while(cin >> x >> y){ if(x == y && x == 0) break; if(x <= y) cout << x << ' ' << y << endl; else if(x > y) cout << y << ' ' << x << endl; } }
#include<stdio.h> int main(){ int H[10000], W[10000]; int length; int i=0, j, k; do{ scanf("%d %d", &H[i], &W[i]); i += 1; }while(H[i-1]!=0 || W[i-1]!=0); length = i; for(i=0; i<length-1; i++){ for(j=0; j<H[i]; j++){ for(k=0; k<W[i]; k++){ printf("#"); } printf("\n"); } printf("\n"); } return 0; }
0
69,230,268
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> P; typedef vector<int> VI; 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 (a>b) { a=b; return 1; } return 0; } #define _overload3(_1,_2,_3,name,...) name #define _rep(i,n) repi(i,0,n) #define repi(i,a,b) for(int i=int(a);i<int(b);++i) #define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__) #define all(x) (x).begin(),(x).end() vector<ll> y(51, 0); vector<ll> z(51, 0); ll ans(int n, ll eat, ll pos) { if (n == 0) { return eat + 1; } else if (pos == y[n]) { return eat + z[n]; } else if (pos == 0) { return eat; } else if (pos < y[n] / 2) { return ans(n-1, eat, pos-1); } else if (pos == y[n] / 2) { return eat + z[n-1] + 1; } else { return ans(n-1, eat+z[n-1]+1, pos-y[n-1]-2); } } int main() { ll n, x; cin >> n >> x; y[0] = 1; z[0] = 1; rep (i, 50) { y[i+1] = y[i] * 2 + 3; z[i+1] = z[i] * 2 + 1; } cout << ans(n, 0, x-1); }
#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>; ll x = 1e9 + 7; const int INF = 1001001001; int main() { vector<vector<int>> a(3, vector<int>(3)); rep(i,3)rep(j,3) { cin >> a[i][j]; } int n; cin >> n; vector<bool> t(101, false); rep(i,n) { int b; cin >> b; t[b] = true; } rep(i,3) { if (t[a[i][0]] && t[a[i][1]] && t[a[i][2]]) { cout << "Yes" << endl; return 0; } } rep(i,3) { if (t[a[0][i]] && t[a[1][i]] && t[a[2][i]]) { cout << "Yes" << endl; return 0; } } if (t[a[0][0]] && t[a[1][1]] && t[a[2][2]]) { cout << "Yes" << endl; return 0; } if (t[a[0][2]] && t[a[1][1]] && t[a[2][0]]) { cout << "Yes" << endl; return 0; } cout << "No" << endl; return 0; }
0
89,551,425
#include<stdio.h> int main(){ int a,b; scanf("%d%d",&a,&b); printf("a %s b\n",a>b?">":a<b?"<":"=="); return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ int N; vector<int> T(3); cin >> N >> T[0] >> T[1] >> T[2]; vector<int> L(N); for(int i=0; i<N; i++) cin >> L[i]; vector<int> Ltemp(4); int result=1e9; for(int i=0; i<(1<<(2*N)); i++){ int mp=0; for(int l=0; l<4; l++){ Ltemp[l]=0; } for(int j=0; j<N; j++){ int a=((i&(1<<(2*j)))>0?1:0); int b=((i&(1<<(2*j+1)))>0?1:0); if(a*b==0&&Ltemp[a+2*b]>0) mp+=10; Ltemp[a+2*b]+=L[j]; } for(int k=0; k<3; k++){ if(Ltemp[k]==0) mp+=1e8; mp+=abs(T[k]-Ltemp[k]); } result=min(result,mp); } cout << result << endl; }
0
56,772,572
#include <bits/stdc++.h> using namespace std; int main() { vector<int> W(26, 0); string s = ""; string s0; while(cin >> s0){ s += s0; } for(int i = 0; i < s.size(); i++){ char c = s.at(i); if('A' <= c && c <= 'Z'){ c = c - 'A' + 'a'; } if('a' <= c && c <= 'z'){ W.at(c-'a') += 1; } } for(int i = 0; i < W.size(); i++){ cout << (char)('a' + i) << " : " << W.at(i) << endl; } }
#include <bits/stdc++.h> #define rep(a,n) for (ll a = 0; a < (n); ++a) using namespace std; typedef long long ll; typedef pair<ll,ll> P; typedef vector<vector<ll> > Graph; 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 (a > b) { a = b; return 1; } return 0; } const ll INF = 1e18; int main(){ ll n; cin >> n; ll a,b; cin >> a >> b; vector<ll>p(n); ll one=0; ll two=0; ll thr=0; rep(i,n){ cin >> p[i]; if(p[i]<=a)one++; else if(p[i]<=b)two++; else thr++; } ll ans = min(one,min(two,thr)); cout << ans << endl; return 0; }
0
16,395,225
#include<bits/stdc++.h> #define _GLIBCXX_DEBUG #define all(v) (v).begin(),(v).end() using namespace std; using ll=long long; using pii=pair<int, int>; using vi=vector<int>; using vii=vector<vector<int>>; const ll LINF=1LL<<60; const int INF=1<<29; const ll MOD=1e9+7; int main(){ double a, b, x; cin >> a >> b >> x; double l=0, r=M_PI/2; while(r-l > 1e-8){ double mid=l+(r-l)/2; double v; if(b-a*tan(mid) >= 0){ v=(a*b-a*a*tan(mid)/2)*a; } else{ v=b*b/tan(mid)/2*a; } if(v <= x) r=mid; else l=mid; } cout << fixed << setprecision(7); cout << r*180/M_PI << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define maxn 600020 #define rep(i,l,r) for(register int i = l ; i <= r ; i++) #define repd(i,r,l) for(register int i = r ; i >= l ; i--) #define rvc(i,S) for(register int i = 0 ; i < (int)S.size() ; i++) #define rvcd(i,S) for(register int i = ((int)S.size()) - 1 ; i >= 0 ; i--) #define fore(i,x)for (register int i = head[x] ; i ; i = e[i].next) #define pb push_back #define prev prev_ #define stack stack_ #define mp make_pair #define fi first #define se second #define inf 0x3f3f3f3f typedef long long ll; typedef pair<int,int> pr; int a[maxn],f[maxn],g[maxn]; int n,S; int main(){ scanf("%d",&n); S = (1 << n) - 1; rep(i,0,S) scanf("%d",&f[i]) , g[i] = -inf; rep(i,0,n - 1){ rep(j,0,S){ if ( j & (1 << i) ){ if ( f[j] < f[j ^ (1 << i)] ){ g[j] = f[j] , f[j] = f[j ^ (1 << i)]; if ( g[j] < g[j ^ (1 << i)] ) g[j] = g[j ^ (1 << i)]; } else if ( g[j] < f[j ^ (1 << i)] ) g[j] = f[j ^ (1 << i)]; } } } rep(i,1,S){ int pre = 0,ans = f[i] + g[i]; repd(j,n - 1,0){ if ( i & (1 << j) ){ ans = max(ans,f[pre | ((1 << j) - 1)] + g[pre | ((1 << j) - 1)]); pre |= 1 << j; } } printf("%d\n",ans); } }
0
21,887,201
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define MOD 1000000007 int main (){ int N,M; long long ans=0; cin>>N>>M; vector<pair<long long,long long>>energy(N); rep(i,N){ long long a,b; cin>>a>>b; energy[i]=make_pair(a,b); } sort(energy.begin(),energy.end()); for(int i=0;i<N;i++){ if(energy[i].second>=M){ ans+=energy[i].first*M; cout<<ans; return 0; } else{ M-=energy[i].second; ans+=energy[i].first*energy[i].second; } } }
#include <bits/stdc++.h> using namespace std; #include <iostream> #include <vector> #include <cstdlib> #include <cmath> #include <math.h> #include <sstream> #include <numeric> #include <cctype> #include <bitset> #include <cassert> #include<algorithm> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep1(i, n) for (int i = 1; i <= (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) #define SIZE 100005 #define INF 1000000000000000LL #define all(x) x.begin(),x.end() using pint = pair<int,int>; using vec = vector<int>; using ll=long long; using vll = vector<ll>; using vvll = vector<vector<ll>>; 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; } const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll n; cin>>n; set<ll> s; rep(i,n){ int a; cin>>a; s.insert(a); } if((ll)(s.size())==n){ cout<<"YES"<<endl; return 0; }else{ cout<<"NO"<<endl; return 0; } }
0
46,133,756
#include<cstdio> #include<iostream> #include<vector> #include<set> using namespace std; int main(void) { int N, M; scanf("%d%d", &N, &M); int H[100010]; for (int i = 0; i < N; i++) { scanf("%d", &H[i]); } int A[100010], B[100010]; set<int> badTowers; for (int i = 0; i < M; i++) { scanf("%d%d", &A[i], &B[i]); int H_A = H[A[i] - 1]; int H_B = H[B[i] - 1]; if (H_A == H_B) { badTowers.insert(A[i]); badTowers.insert(B[i]); } else if (H_A > H_B){ badTowers.insert(B[i]); } else { badTowers.insert(A[i]); } } printf("%zu", N - badTowers.size()); return 0; }
#include <iostream> const int MOD = 1000000007; int main(){ int N; std::cin >> N; std::string S; std::cin >> S; long long ans = 1; long long left = 0; for(int i=0; i<N*2; ++i){ if(left%2==1) S[i] = (S[i]=='B' ? 'W' : 'B'); if(S[i]=='B') ++left; else ans = ans * (left--) % MOD; } if(left==0) { for(int i=1; i<=N; ++i) ans = ans * i % MOD; std::cout << ans%MOD << std::endl; } else { std::cout << 0 << std::endl; } return 0; }
0
71,020,409
#include <bits/stdc++.h> #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define rep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++) #define rrep(i,n) for(int i = (int)(n-1); i > -1; i--) #define rrep2(i,n,a) for(int i = (int)(n); i >= (int)(a); i--) #define fi first #define se second using namespace std; using ll = long long; using v_int = vector<int>; using v2_int = vector<v_int>; using v_ll = vector<ll>; using v2_ll = vector<v_ll>; using v_string = vector<string>; using v_bool = vector<bool>; using v2_bool = vector<v_bool>; using pii = pair<int, int>; using mii = map<int, int>; const double PI = 3.1415926535897932; const int INF = (int)2e9; const ll LINF = (ll)2e18; const ll MOD = 1000000007; const int dc[8] = {1, -1, 0, 0, 1, -1, 1, -1}; const int dr[8] = {0, 0, 1, -1, 1, 1, -1, -1}; template<typename T, typename U> inline ostream& operator<<(ostream &o, pair<T,U> &p) { return o << "{" << p.first << "," << p.second << "}"; } template<typename T> inline istream& operator>>(istream &is, vector<T> &vec) { for(auto &v : vec) { is >> v; } return is; } template<typename T> inline ostream& operator<<(ostream &os, vector<T> &vec) { for(auto &v : vec) { os << v << ",";} return os; } template<typename T> inline ostream& operator<<(ostream &os, vector<vector<T> > &mat) { for(auto &row : mat) { os << row << endl; } return os; } template<typename T> inline void chmin(T &a, T b) { a = min(a, b); } template<typename T> inline void chmax(T &a, T b) { a = max(a, b); } ll solve1(ll n, int p) { if(n==0) { return 0; } return n/p + solve1(n/p, p); } ll solve2(ll n, int p) { if(n%2==1) { return solve1(n, p) - solve2(n-1, p); } ll res = solve1(n/2, p); if(p==2) { res += n/p; } return res; } int main(void) { ll n; cin >> n; ll ans = min(solve2(n, 2), solve2(n, 5)); cout << ans << endl; return 0; }
#include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <string> #include <cmath> #include <bitset> #include <vector> #include <map> #include <set> #include <queue> #include <deque> #include <algorithm> #include <complex> #include <unordered_map> #include <unordered_set> #include <random> #include <cassert> #include <fstream> #include <utility> #include <functional> #include <time.h> #include <stack> #include <array> #include <list> using namespace std; typedef long long ll; typedef long double ld; #define vi vector<int> #define vl vector<ll> #define vii vector< vector<int> > #define vll vector< vector<ll> > #define vs vector<string> #define pii pair<int,int> #define pis pair<int,string> #define psi pair<string,int> #define pll pair<ll,ll> #define rep(i,n) for(int i=0; i<(int)(n); i++) #define rep1(i,n) for(int i=1; i<=(int)(n); i++) #define all(c) c.begin(),c.end() #define psb push_back #define ppb pop_back const int I_INF = 1001001001; const ll LL_INF = 1001001001001001001; const ld EPS = 0.001; int main() { int N, K; cin >> N >> K; vi a(N); rep (i, N) cin >> a[i]; rep (i, K) { vi b(N+1); rep (j, N) { int l = max(0, j-a[j]); int r = min(j+a[j]+1, N); b[l]++; b[r]--; } rep (j, N) b[j+1] += b[j]; b.ppb(); if (a == b) break; a = b; } rep (i, N) cout << a[i] << endl; }
0
19,278,760
#include <bits/stdc++.h> using namespace std; int strongness(int n) { return (n + 11) % 13; } int main() { int a, b; cin >> a >> b; int sa = strongness(a); int sb = strongness(b); string ans; if (sa > sb) { ans = "Alice"; } else if (sa == sb) { ans = "Draw"; } else { ans = "Bob"; } cout << ans << endl; return 0; }
#include "bits/stdc++.h" #define DEBUG(x) cout<<#x<<": "<<x<<endl; #define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl using namespace std; #define vi vector<int> #define vl vector<ll> #define vii vector< vector<int> > #define vll vector< vector<ll> > #define vs vector<string> #define pii pair<int,int> #define pis pair<int,string> #define psi pair<string,int> #define pll pair<ll,ll> #define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) #define MOD 1000000007 #define mod 1000000009 #define pi 3.14159265358979323846 #define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl; #define pb push_back template<class T> void print(const T& x){cout << x << endl;} int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 }; int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 }; typedef long long ll; const int inf = 1000000001; const ll INF = 1e18 * 4; int main(){ int k, x; cin >> k >> x; if(500*k >= x) cout << "Yes"; else cout <<"No"; cout << endl; return 0; }
0
58,667,989
#include <bits/stdc++.h> using namespace std; const int INF = (int)1e9; const int MOD = (int)1e9 + 7; const double PI = acos(-1); #define EPS 1e-14 typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef pair<int, int> pii; typedef pair<double, double> pdd; inline int inputi(){ int x; scanf("%d", &x); return x; } inline double inputd(){ double x; scanf("%lf", &x); return x; } inline string inputs(){ string x; cin >> x; return x; } #define pb push_back #define mp make_pair #define fst first #define sec second #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define RFOR(i, a, b) for (int i = (b) - 1; i >= (a); i--) #define REP(i, n) for (int i = 0; i < (n); i++) #define RREP(i, n) for (int i = (n) - 1; i >= 0; i--) #define REPit(type, i, obj) for (type::iterator i = (obj).begin(); i != (obj).end(); i++) #define RREPit(type, i, obj) for (type::iterator i = (obj).rbegin(); i != (obj).rend(); i++) #define all(obj) (obj).begin(), (obj).end() #define rall(obj) (obj).rbegin(), (obj).rend() #define sz(obj) ((int)(obj).size()) #define sort(obj) sort(all(obj)) #define exist(obj, key) ((obj).find(key) != (obj).end()) #define clear(array) memset((array), 0, sizeof(array)) #define print(x) cout << (x) << endl template <class T> inline void printall(vector<T> v){ REP(i, sz(v)) cout << v[i] << "\n "[i < sz(v) - 1]; } #define dump(x) cerr << #x << ": " << (x) << endl #define debug(x) cerr << #x << ": " << (x) << " (" << __LINE__ << ")" << endl int main() { int a, b; int dp[16][16]; while (a = inputi(), b = inputi(), a || b){ REP(i, a) REP(j, b) dp[i][j] = -1; int n = inputi(); REP(i, n){ int x = inputi(), y = inputi(); dp[x - 1][y - 1] = 0; } bool flag = true; REP(i, a){ if (dp[i][0] == 0) flag = false; dp[i][0] = flag; } flag = true; REP(j, b){ if (dp[0][j] == 0) flag = false; dp[0][j] = flag; } FOR(i, 1, a){ FOR(j, 1, b){ if (dp[i][j] == -1){ dp[i][j] = dp[i - 1][j] + dp[i][j - 1]; } } } print(dp[a - 1][b - 1]); } return 0; }
#include <bits/stdc++.h> using namespace std; const double pi = 2 * acos(0.0); const double eps = 1e-8; #define REP(i,a,b) for(int i=(a); i<(b);++i) #define rep(i,n) REP(i,0,n) typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef int Cost; struct Edge { int src, dst; Cost cost; Edge(int s, int d, Cost c) : src(s), dst(d), cost(c) {} }; typedef vector<Edge> Edges; typedef vector<Edges> Graph; typedef vector<Cost> Array; typedef vector<Array> Matrix; int dx[8] = {0, 1, 0, -1, 1, -1, 1, -1}; int dy[8] = {1, 0, -1, 0, 1, -1, -1, 1}; struct UnionFind { vector<int> par; int cnt; UnionFind(int size_) : par(size_, -1), cnt(size_) { } void unite(int x, int y) { if ((x = find(x)) != (y = find(y))) { if (par[y] < par[x]) swap(x, y); par[x] += par[y]; par[y] = x; cnt--; } } bool same(int x, int y) { return find(x) == find(y); } int find(int x) { return par[x] < 0 ? x : par[x] = find(par[x]); } int size(int x) { return -par[find(x)]; } int size() { return cnt; } }; int main(void) { ios_base::sync_with_stdio(false); cin.tie(0); int n, q, com, x, y; cin >> n >> q; UnionFind uf = UnionFind(n); for (int i = 0; i < q; i++) { cin >> com >> x >> y; if (com == 0) uf.unite(x, y); else if (com == 1) cout << (uf.same(x, y) ? 1 : 0) << endl; } return 0; }
0
83,830,790
#include <bits/stdc++.h> const int N = 1e3+5; int n, m, a, b, s[N][N]; int main() { scanf("%d%d%d%d", &n, &m, &a, &b); for(int i = 1; i <= b; ++i) for(int j = 1; j <= a; ++j) s[i][j] = 1; for(int i = b+1; i <= n; ++i) for(int j = a+1; j <= m; ++j) s[i][j] = 1; for(int i = 1; i <= n; puts(""), ++i) for(int j = 1; j <= m; ++j) putchar(s[i][j]^48); return 0; }
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; #define ull unsigned long long #define ld long double #define vi vector<int> #define vll vector<ll> #define vc vector<char> #define vs vector<string> #define vpii vector<pii> #define vpll vector<pll> #define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++) #define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++) #define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--) #define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--) #define sz(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define SORT(v, n) sort(v, v + n); #define VSORT(v) sort(v.begin(), v.end()); #define RSORT(x) sort(rall(x)); #define pb push_back #define mp make_pair #define INF (1e9) #define PI (acos(-1)) #define EPS (1e-7) ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; } ull lcm(ull a, ull b) { return a / gcd(a, b) * b; } int main(){ int h, w; cin >> h >> w; vs s(h); rep(i, h) cin >> s[i]; queue<pii> q; vector<vi> dist(h, vi(w, INF)); q.emplace(0, 0); dist[0][0] = (s[0][0]=='.'?0:1); while (!q.empty()) { auto p = q.front(); q.pop(); int y = p.first, x = p.second, d = dist[y][x]; const vi dy = { 0, 1 }, dx = { 1, 0 }; rep(i, 2) { int ny = y + dy[i], nx = x + dx[i]; if (ny<0 || ny>=h || nx<0 || nx>=w) continue; int nd = d + (s[y][x]!=s[ny][nx]?1:0); if (dist[ny][nx] <= nd) continue; q.emplace(ny, nx); dist[ny][nx] = nd; } } int cnt = dist[h-1][w-1] + (s[h-1][w-1]=='.'?0:1); cout << (cnt / 2) << endl; return 0; }
0
78,113,050
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<string> vstr; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define fi first #define se second #define mp make_pair #define pb push_back #define ub upper_bound #define lb lower_bound #define asd cout << "ok" << endl; #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define trav(it, m) for(auto it = m.begin(); it it!= m.end(); it++) const char nl = '\n'; const int MOD = 1e9 +7; const ll INF = 1e19; const ld PI = acos((ld)-1); const int MX = 2e5 + 5; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n, m, x, y; cin >> n >> m >> x >> y; vi v1, v2; for(int i = 0; i < n; i++){ int x; cin >> x; v1.pb(x); } for(int i = 0; i < m; i++){ int x; cin >> x; v2.pb(x); } v1.pb(x); v2.pb(y); sort(all(v1)); sort(all(v2)); if(v1[v1.size()-1] < v2[0]) { cout << "No War" << nl; return 0; } cout << "War" << nl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; const ll mod = 1e9+7; int main(){ string s; cin >> s; ll k; cin >> k; ll n = s.size()-1; ll ans = 0; bool same = true; ll now = 1; vector<ll> can; bool all = true; for(ll i = 0; i < n; i++){ if(s[i] == s[i+1] && same){ now++; } else if(s[i] == s[i+1]){ now++; same = true; } else { all = false; can.push_back(now); now = 1; } } if(all){ cout << s.size()*k/2 << endl; return 0; } if(n > 0 && s[n-1] == s[n]) can.push_back(now); same = false; if(s[0] == s[n]) same = true; for(auto p:can){ ans += p/2; } ans *= k; if(can.empty()){ cout << k/2 << endl; return 0; } if(can[0]%2 != 0 && can.back()%2 != 0 && same) ans += k-1; cout << ans << endl; }
0
74,031,464
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using ll = long long; using namespace std; int main(){ int n; cin>>n; int ans=1; int m=n; while(1){ if(m%360==0){ cout<<ans<<endl; return 0; } ans++; m+=n; m%=360; } }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace std; #define pii pair<int, int> #define pll pair<long long, long long> #define fi first #define se second #define mp make_pair #define pb push_back #define DEBUG 1 #define cerr if (DEBUG) cerr #define test cerr << "hi\n"; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); #define rand(l, r) uniform_int_distribution<long long>(l, r)(rng) using namespace __gnu_pbds; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> OST; #define INF 0x3f3f3f3f3f3f3f3f #define MAXN 500005 #define MOD 1000000007LL int n, m; vector<int> p[MAXN]; void solve() { cin >> n >> m; for (int i = 0, a, b; i < n; i++) { cin >> a >> b; if (m-a >= 0) { p[m-a].pb(b); } } priority_queue<int> q; long long ans = 0; for (int i = m; i >= 0; i--) { for (int x : p[i]) q.push(x); if (q.size()) { ans += q.top(); q.pop(); } } cout << ans << '\n'; } int main() { #ifdef LOCAL freopen("input.txt", "r", stdin); auto start_time = clock(); #endif ios_base::sync_with_stdio(0); cin.tie(0); int t = 1; for (int no = 1; no <= t; no++) { solve(); } #ifdef LOCAL cerr << "TIME ELAPSED: " << double(clock() - start_time) / CLOCKS_PER_SEC << '\n'; #endif }
0
1,938,345
#include<bits/stdc++.h> using namespace std; int main(){ long long n,k;cin>>n>>k; vector<pair<long long, long long > >nos(n); long long a,b; for(int i=0;i<n;i++){ cin>>a>>b; nos[i]=make_pair(a,b); } sort(nos.begin(),nos.end()); int i=0; while(k!=0){ if(k<=nos[i].second){cout<<nos[i].first;break;} k-=nos[i].second; i++; } }
#include <bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<b;i++) #define rrep(i,b,a) for(int i=b;i>=a;i--) #define fori(a) for(auto i : a ) #define all(a) begin(a), end(a) #define set(a,b) memset(a,b,sizeof(a)) #define sz(a) a.size() #define pi 3.14159 #define ll long long #define ull unsigned long long #define pb push_back #define PF push_front #define mp make_pair #define pq priority_queue #define mod 1000000007 #define f first #define s second #define pii pair< int, int > #define vi vector<int> #define vpii vector<pii> #define debug(v) for(auto i:v) cout<<i<<" "; #define tc int t; cin >> t; while(t--) using namespace std; string repeat(string s, int n) { string s1 = ""; for (int i=0; i<n;i++) s1+=s; return s1; } string getString(char x) { string s(1, x); return s; } void optimizeIO(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } int gcd(int a, int b){ if (a == 0) return b; return gcd(b % a, a); } void solve(){ int n,x; cin>>n>>x; int a[n]; rep(i,0,n) cin>>a[i]; int gc=abs(a[0]-x); rep(i,1,n){ gc=__gcd(gc,abs(a[i]-x)); } cout<<gc<<endl; } int main(){ optimizeIO(); { solve(); } }
0
40,711,032
#include <bits/stdc++.h> using namespace std; using ll=long long; using vi = vector<int>; using vvi = vector<vector<int>>; using vl = vector<ll>; using vvl = vector<vector<ll>>; #define all(x) x.begin(),x.end() #define rep(i,j,n) for (long long i = j; i < (long long)(n); i++) #define _GLIBCXX_DEBUG #define MOD 1000000007 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 (a > b) { a = b; return 1; } return 0; } using pl = pair<ll,ll>; signed main(){ ll n,m; cin>>n>>m; vvl v(n,vl(0)); vector<pl> vp(m); rep(i,0,m){ ll a,b; cin>>a>>b; vp[i]=make_pair(a,b); --a; v[a].push_back(b); } rep(i,0,n)if(v[i].size()>0)sort(all(v[i])); rep(i,0,m){ ll a,b; tie(a,b)=vp[i]; ll j=1; rep(k,0,v[a-1].size()){ if(v[a-1][k]==b){ j=k+1; break; } } string s=to_string(a); rep(i,0,6-s.size())cout<<0; cout<<a; string t=to_string(j); rep(i,0,6-t.size())cout<<0; cout<<j<<endl; } return 0; }
#include<bits/stdc++.h> #ifdef LOCAL #include "lib/debug.hpp" #else #define debug(...) 1 #endif #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define rep(i, n) REP(i, 0, (n)) #define repc(i, n) REPC(i, 0, (n)) #define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++) #define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++) #define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--) using namespace std; using ll = long long; using ld = long double; using pr = pair<ll, ll>; using vll = vector<ll>; using vpr = vector<pr>; using P = pair<int, int>; template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; } template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; } void answer() { int n; cin >> n; vector<int> mp(n+1, 0); { vector<int> b(n); rep(i, n) { int a; cin >> a; a--; b[a]++; } rep(i, n) mp[b[i]]++; } vector<ll> sum1(n+2, 0), sum2(n+2, 0); repc(i, n) { sum1[i+1] = sum1[i] + i * mp[i]; sum2[i+1] = sum2[i] + mp[i]; } vector<ll> ans(n+1, 0); REPC(i, 1, n) { ll res = 0; res = sum1[i+1] + (sum2[n+1] - sum2[i+1]) * i; res /= ll(i); chmax(ans[res], ll(i)); } REPCM(i, n-1, 1) chmax(ans[i], ans[i+1]); REPC(i, 1, n) cout << ans[i] << '\n'; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(0); answer(); return 0; }
0
36,493,459
#include <bits/stdc++.h> #define FOR(i, l, r) for(ll i = l; i < r; i++) #define rep(i, N) FOR(i, 0, N) using namespace std; typedef long long ll; typedef pair<int,int> P; typedef vector<int> vi; typedef vector<ll> vl; const ll MOD = round(1e9+7); int main() { int N; cin >> N; vector<string> S(N); rep(i,N) cin >> S[i]; int BA = 0, A = 0, B = 0; int ans = 0; rep(i,N){ if(S[i][0] == 'B') B++; if(S[i][(int)S[i].size()-1] == 'A') A++; if(S[i][0] == 'B' && S[i][(int)S[i].size()-1] == 'A') BA++; rep(j,(int)S[i].size()-1){ if(S[i].substr(j,2) == "AB") ans++; } } if(BA > 0){ A -= BA; B -= BA; ans += BA-1; if(A > 0) {ans++; A--;} if(B > 0) {ans++; B--;} } ans += min(A,B); cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; 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(a > b) { a = b; return 1; } return 0; } #define DEBUG #ifdef DEBUG template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << '(' << p.first << ',' << p.second << ')'; return os; } template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { os << '{'; for(int i = 0; i < (int)v.size(); i++) { if(i) { os << ','; } os << v[i]; } os << '}'; return os; } void debugg() { cerr << endl; } template <class T, class... Args> void debugg(const T &x, const Args &... args) { cerr << " " << x; debugg(args...); } #define debug(...) \ cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debugg(__VA_ARGS__) #define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl #else #define debug(...) (void(0)) #define dump(x) (void(0)) #endif struct Setup { Setup() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } __Setup; using ll = long long; #define ALL(v) (v).begin(), (v).end() #define RALL(v) (v).rbegin(), (v).rend() const double EPS = 1e-7; const int INF = 1 << 30; const ll LLINF = 1LL << 60; constexpr int MOD = 1000000007; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; const int max_log = 60; int main() { ll N, X, M; cin >> N >> X >> M; vector dub(max_log, vector<ll>(M)); vector sum(max_log, vector<ll>(M)); for(ll i = 0; i < M; i++) { dub[0][i] = i * i % M; sum[0][i] = i; } for(int k = 0; k < max_log - 1; k++) { for(int i = 0; i < M; i++) { dub[k + 1][i] = dub[k][dub[k][i]]; } for(int i = 0; i < M; i++) { sum[k + 1][i] = sum[k][i] + sum[k][dub[k][i]]; } } ll ans = 0; for(int i = 0; i < max_log; i++) { if(N & (1LL << i)) { ans += sum[i][X]; X = dub[i][X]; } } cout << ans << endl; }
0
88,213,527
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define ll long long int #define MOD 1000000007 #define oo 1000000000000000000 #define forr(i,n) for(ll i=0;i<n;i++) #define fastio ios_base::sync_with_stdio(false); cin.tie(0) ; cout.tie(0); #define all(x) x.begin(),x.end() #define eb emplace_back #define pb push_back #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> using namespace __gnu_pbds; using namespace std; ll valueOfIndex(ordered_set&s , ll i){ return *(s.find_by_order(i)); } ll indexOfValue(ordered_set&s , ll x){ return s.order_of_key(x); } ll add(ll a, ll b,ll p=MOD) { a%=p; b%=p; return (a+b + p)%p;} ll mul(ll a, ll b,ll p=MOD) { a%=p; b%=p; return (a*b + p)%p;} ll power(ll x,ll n,ll p=MOD){ if(x==0) return 0; if(n==0 || x==1) return 1LL; ll r = (power(x,n/2,p))%p; if(n&1) return mul(mul(r,r,p) , x,p); else return mul(r,r,p); } ll inv(ll x){return power(x,MOD-2);} void __sol(){ ll mx = 1e18; ll n; cin >> n; vector<ll> v(n); forr(i,n) cin >> v[i]; sort(all(v)); ll ans = 1; forr(i,n){ ll x = v[i]; if(x==0){ cout << 0; return; } else if( x<=mx/ans ) ans*=x; else{ cout << -1; return; } } cout << ans; return; } int main(){ fastio ll tc=1; while(tc--) __sol(); return 0; }
#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; template <typename T> using Order_Set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define PI acos(-1.0) #define O_O \ ios_base::sync_with_stdio(false); \ cin.tie(NULL) #define precision(a) fixed << setprecision(a) #define endl '\n' #define Flush cout << flush #define LLMX 0x3fffffffffffffff long long N; int main() { O_O; long long N, K; long long gcd, k, mx = 0; cin >> N >> K; cin >> gcd; mx = gcd; for (int i = 1; i < N; i++) { cin >> k; mx = max(mx, k); gcd = __gcd(gcd, k); } if (K > mx) { cout << "IMPOSSIBLE" << endl; return 0; } if (K%gcd==0) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; return 0; }
0
22,423,113
#include<iostream> #include<cmath> int main(void){ int n, d, ans = 0; std::cin >> n >> d; int x[n][d]; for(int i = 0; i < n; i++){ for(int j = 0; j < d; j++){ std::cin >> x[i][j]; } } for(int i = 0; i < n; i++){ for(int j = i+1; j < n; j++){ int dist = 0; for(int k = 0; k < d; k++){ dist += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]); } int rdist = std::sqrt(dist); if(rdist * rdist == dist) ans++; } } std::cout << ans << std::endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int main(){ #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif string s; cin>>s; char c=s[0]; int ans=1; for(int i=1;i<4;++i){ if(s[i]==c) ++ans; else{ c=s[i]; ans=1; } if(ans==3){ cout<<"Yes"; return 0; } } cout<<"No"; return 0; }
0
54,385,122
#include<bits/stdc++.h> #define ll long long #define debug(x) cout<<x<<"DE"<<endl; using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n,m,s=0; cin>>n; ll l1[n+1]; for(int i=1;i<=n;i++){ cin>>l1[i]; if(i==1)m=l1[i]; else m=__gcd(m,l1[i]); } cout<<m; }
#include <bits/stdc++.h> #define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false)) #define rep(i, n) for (int i = 0; i < (n); ++i) #define precise(i) fixed << setprecision(i) using ll = unsigned long long int; using namespace std; int main() { fastIO; int n, a, b; cin >> n >> a >> b; int sum = 0; for (int i = 1; i <= n; i++) { int sub_sum = 0; int t = i; while (t > 0) { sub_sum += t % 10; t /= 10; } if (a <= sub_sum && sub_sum <= b) sum += i; } cout << sum << endl; }
0
89,788,493
#include<bits/stdc++.h> using namespace std; typedef long long ll; template<class Abel> struct UnionFind { vector<int> par; vector<int> rank; vector<Abel> diff_weight; UnionFind(int n = 1, Abel SUM_UNITY = 0) { init(n, SUM_UNITY); } void init(int n = 1, Abel SUM_UNITY = 0) { par.resize(n); rank.resize(n); diff_weight.resize(n); for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY; } int root(int x) { if (par[x] == x) { return x; } else { int r = root(par[x]); diff_weight[x] += diff_weight[par[x]]; return par[x] = r; } } Abel weight(int x) { root(x); return diff_weight[x]; } bool same(int x, int y) { return root(x) == root(y); } bool merge(int x, int y, Abel w) { w += weight(x); w -= weight(y); x = root(x); y = root(y); if (x == y) return false; if (rank[x] < rank[y]) swap(x, y), w = -w; if (rank[x] == rank[y]) ++rank[x]; par[y] = x; diff_weight[y] = w; return true; } Abel diff(int x, int y) { return weight(y) - weight(x); } }; int main(){ ios::sync_with_stdio(false); cin.tie(0); ll n,m; cin>>n>>m; UnionFind<ll> uni(n); int l[m],r[m],d[m]; for(int i=0;i<m;i++){ cin>>l[i]>>r[i]>>d[i]; l[i]--,r[i]--; uni.merge(l[i],r[i],d[i]); } bool pos=true; for(int i=0;i<m;i++){ if(uni.diff(l[i],r[i]) != d[i]) pos = false; } if(pos) cout<<"Yes"<<endl; else cout<<"No"<<endl; }
#include <bits/stdc++.h> #define fi first #define se second #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) #define srep(i,s,t) for (int i = s; i < t; ++i) #define rng(a) a.begin(),a.end() #define rrng(a) a.rbegin(),a.rend() #define maxs(x,y) (x = max(x,y)) #define mins(x,y) (x = min(x,y)) #define limit(x,l,r) max(l,min(x,r)) #define lims(x,l,r) (x = max(l,min(x,r))) #define isin(x,l,r) ((l) <= (x) && (x) < (r)) #define pb push_back #define eb emplace_back #define sz(x) (int)(x).size() #define pcnt __builtin_popcountll #define uni(x) x.erase(unique(rng(x)),x.end()) #define show(x) cout<<#x<<" = "<<x<<endl; #define print(x)cout<<x<<endl; #define PQ(T) priority_queue<T,v(T),greater<T> > #define bn(x) ((1<<x)-1) #define dup(x,y) (((x)+(y)-1)/(y)) #define newline puts("") #define v(T) vector<T> #define vv(T) v(v(T)) using namespace std; typedef long long int ll; typedef unsigned uint; typedef unsigned long long ull; typedef pair<int,int> P; typedef tuple<int,int,int> T; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; typedef vector<P> vp; typedef vector<T> vt; int main() { int n,k; cin>>n>>k; deque<ll> q; rep(i,n){ ll v; cin>>v; q.push_back(v); } ll ans = 0; rep(r,k+1){ rep(l,k+1){ rep(d,k+1){ deque<ll> qq = q; priority_queue<ll,vector<ll>,greater<ll>> pq; if((r+l)>(int)qq.size()) continue; if((r+l+d)>k) continue; rep(i,r){ pq.push(qq.front()); qq.pop_front(); } rep(i,l){ pq.push(qq.back()); qq.pop_back(); } rep(i,d){ if(pq.size()) if(pq.top()<0)pq.pop(); } ll tmp = 0; while(!pq.empty()){ tmp+=pq.top(); pq.pop(); } maxs(ans,tmp); } } } print(ans); return 0; }
0
27,977,910
#include <bits/stdc++.h> using namespace std; int main() { int n,m,ans=0; cin>>n>>m; int k[11],bulb[11][11],p[11]; for(int i=0;i<m;i++){ cin>>k[i]; for(int j=0;j<k[i];j++) cin>>bulb[i][j],bulb[i][j]--; } for(int i=0;i<m;i++) cin>>p[i]; for(int ptn=0;ptn<1<<n;ptn++){ int sum[11]={0}; bool light=true; for(int i=0;i<m;i++){ for(int j=0;j<k[i];j++){ if(ptn&1<<bulb[i][j]) sum[i]++; } } for(int i=0;i<m;i++) if(p[i]!=sum[i]%2) light=false; if(light) ans++; } cout<<ans; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++) #define VL vector<ll> #define VS vector<string> #define VB vector<bool> #define VP vector<pair<ll,ll>> #define VVL vector<vector<ll>> #define VVP vector<vector<pair<ll,ll>>> #define PL pair<ll,ll> #define ALL(v) (v).begin(), (v).end() int main(){ ll N; cin>>N; VL A(N); ll ans=0; rep(i,0,N)cin>>A[i]; rep(i,0,N){ rep(j,0,N){ if(i==j)continue; ans=max(abs(A[i]-A[j]),ans); } } cout<<ans<<endl; return 0; }
0
1,396,272
#include<bits/stdc++.h> using namespace std; using ll = long long; #define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0); int main() { fast_io; string s; int k; cin>>k>>s; if(s.size()<=k) { cout<<s<<endl; } else { cout<<s.substr(0,k)<<"..."<<endl; } }
#include <algorithm> #include <bits/stdc++.h> #include<iostream> #include<string> using namespace std; #define rep(i, n) for (int i = 0; i <(int)(n); i++) #define all(x) (x).begin(), (x).end() #define ll long long const ll MOD=1000000007; const ll INF=1<<27; int n,a,b,c; vector<int> l(10); int ans=INF; void dfs(int depth,vector<int> v){ if(depth==n){ if(find(all(v),0)==v.end()||find(all(v),1)==v.end()||find(all(v),2)==v.end())return; else { vector<int> sum(3,0); vector<int> cnt(3,0); for(int i=0;i<n;i++){ if(v[i]==0)sum[0]+=l[i],cnt[0]++; if(v[i]==1)sum[1]+=l[i],cnt[1]++; if(v[i]==2)sum[2]+=l[i],cnt[2]++; } int ret=0; int tmp=0; tmp=(cnt[0]-1)+(cnt[1]-1)+(cnt[2]-1); ret=abs(a-sum[0])+abs(b-sum[1])+abs(c-sum[2])+10*tmp; ans=min(ans,ret); return; } } for(int i=0;i<4;i++){ v[depth]=i; dfs(depth+1,v); } } int main(){ cin>>n>>a>>b>>c; l.resize(n); rep(i,n)cin>>l[i]; vector<int> v(n,0); dfs(0,v); cout << ans << endl; }
0
38,961,310
#include <iostream> using namespace std; int main() {int a,b,x; cin>>a>>b>>x; if(a>x){ cout<<"NO"; } else if((a+b)<x){ cout<<"NO"; } else if((a+b)>x &&a<=x){ cout<<"YES"; } return 0; }
#include <bits/stdc++.h> #include <iomanip> #include <iostream> #include <vector> #include <queue> using namespace std; using Graph = vector<vector<int>>; typedef long long ll; typedef long double lld; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define PI 3.14159265359 #define MOD 1000000007 int main() { int n,m; cin >> n >> m; Graph G(n); rep(i,m){ int a,b; cin >> a >> b; --a;--b; G[a].push_back(b); G[b].push_back(a); } vector<int>dist(n,-1); queue<int>q; vector<int>prev(n,-1); dist[0] = 0; q.push(0); while(!q.empty()){ int v = q.front(); q.pop(); for(int nv : G[v]){ if(dist[nv] != -1)continue; dist[nv] = dist[v] + 1; prev[nv] = v; q.push(nv); } } cout << "Yes"<<endl; rep(i,n){ if(i==0)continue; cout << prev[i] + 1 << endl; } }
0
50,879,501
#include<bits/stdc++.h> #define ll long long #define pb push_back #define mp make_pair using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t=1; while(t--) { string s; cin>>s; string ans; for(int i=0;i<s.size();++i) { if(s[i]=='0') ans.pb('0'); else if(s[i]=='1') ans.pb('1'); else if(ans.size()>0) ans.pop_back(); } cout<<ans; } }
#include <iostream> #include <vector> #include <algorithm> #include <string.h> #include <math.h> #include <map> #include <iomanip> #include <stdio.h> #include <bitset> typedef long long LL; constexpr long long INFLL = 1e18; using namespace std; LL solve(LL temp) { LL ans; LL count; LL x = 0; count = temp / 2 + 1; if (temp % 2) { if (count % 2) { ans = 1; } else { ans = 0; } } else { count--; ans = temp; if (count % 2) { ans++; } else { } } return ans; } int main() { LL A, B; cin >> A >> B; if (A > 0) { A = solve(A - 1); } bitset<64> bsA(A); bitset<64> bsB(solve(B)); cout << (bsA ^ bsB).to_ullong() << endl; return 0; }
0
57,890,944
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") #pragma comment(linker, "/stack:200000000") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef string str; typedef pair <int,int> pii; typedef pair <ll,ll> pll; typedef vector <int> vi; typedef vector <ll> vll; typedef vector <pii> vpii; typedef vector <pll> vpll; #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> #define ordered_multiset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> #define mp make_pair #define pb push_back #define pob pop_back #define pf push_front #define pof pop_front #define fi first #define se second #define fs first.second #define ss second.second #define ff first.first #define sf second.first #define newl '\n' #define fbo find_by_order #define ook order_of_key #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(),x.rend() #define watch(x) cout << (#x) << " is : " << (x) << newl mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); vi dirx = {0,0,1,-1}; vi diry = {1,-1,0,0}; char to_upper (char x){ if( 97 <= int(x) && int(x) <= 122) return char(x-32); if( 65 <= int(x) && int(x) <= 90) return x; return -1; } char to_lower (char x){ if( 97 <= int(x) && int(x) <= 122) return x; if( 65 <= int(x) && int(x) <= 90) return char(x+32); return -1; } int numerize (char x){ if(48 <= int(x) && int(x) <= 57) return int(x-'0'); if(97 <= int(x) && int(x) <= 122) return int(x-96); if(65 <= int(x) && int(x) <= 90) return int(x-64); return -1; } bool isect (int l1, int r1, int l2, int r2){ pii p1 = {l1,r1}; pii p2 = {l2,r2}; if(p1>p2)swap(p1,p2); return (p2.fi <= p1.se); } ll quickpow (ll num1, ll num2, ll MOD){ if(num2==0)return 1%MOD; else if(num2==1)return num1%MOD; else{ ll temp = quickpow (num1,num2>>1LL,MOD); ll res = ((temp%MOD) * (temp%MOD))%MOD; if(num2&1) res = ((res%MOD)*(num1%MOD))%MOD; return res; } } ll invmod (ll num, ll MOD){return quickpow (num,MOD-2,MOD);} ll gcd (ll num1, ll num2){ if(num1 < num2) swap(num1,num2); ll num3 = num1 % num2 ; while(num3 > 0){ num1 = num2; num2 = num3; num3 = num1 % num2;} return num2; } ll lcm (ll num1 , ll num2){return (ll) (num1/__gcd(num1,num2))*num2;} bool has[400]; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); pii p = {INT_MAX,INT_MAX}; int x,n; cin >> x >> n; for(int i = 1; i <= n; ++i){ int a; cin >> a; has[a] = true; } for(int i = 0; i <= 300; ++i){ if(has[i]) continue; int ab = abs(i-x); p = min(p,{ab,i}); } cout << p.se << newl; return 0; }
#include <iostream> #include <vector> using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(0); int N; cin >> N; vector<int> A(N); for(int i = 0; i < N; ++i){ cin >> A[i]; A[i]--; } int ret = 0; for(int i = 0; i < N; ++i){ if(A[A[i]] == i) ret++; } cout << ret/2 << endl; return 0; }
0
80,234,248
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; using ll = long long; ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else { return gcd(b, a % b); } } ll lcm(ll a, ll b) { return a * b / gcd(a, b); } int main() { ll a, b, c, d; cin >> a >> b >> c >> d; ll total = b - a + 1; ll cd = lcm(c, d); ll mula = b / c - a / c; if (a % c == 0) { mula += 1; } ll mulb = b / d - a / d; if (a % d == 0) { mulb += 1; } ll mulc = b / cd - a / cd; if (a % cd == 0) { mulc += 1; } ll k = mula + mulb - mulc; cout << total - k << endl; return 0; }
#include<iostream> #include<algorithm> #include<string> #include<vector> #include<cmath> #include<map> #include<iomanip> #include<queue> #include<stack> #include<time.h> #define rep(i,n)for(int i=0;i<n;i++) #define int long long #define ggr getchar();getchar();return 0; #define prique priority_queue constexpr auto mod = 1777777777; #define inf 1e15 #define key 1e9 using namespace std; typedef pair<int, int>P; void yes() { cout << "Yay!" << endl; } void no() { cout << ":(" << endl; } template<class T> inline void chmax(T& a, T b) { a = std::max(a, b); } template<class T> inline void chmin(T& a, T b) { a = std::min(a, b); } const int MAX = 330000; int fac[MAX], finv[MAX], inv[MAX]; void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % mod; inv[i] = mod - inv[mod % i] * (mod / i) % mod; finv[i] = finv[i - 1] * inv[i] % mod; } } int COMB(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % mod) % mod; } bool prime(int n) { int cnt = 0; for (int i = 1; i <= sqrt(n); i++) { if (n % i == 0)cnt++; } if (cnt != 1)return false; else return n != 1; } int gcd(int x, int y) { if (y == 0)return x; return gcd(y, x % y); } int lcm(int x, int y) { return x / gcd(x, y) * y; } int mod_pow(int x, int y, int m) { int res = 1; while (y) { if (y & 1) { res = res * x % m; } x = x * x % m; y >>= 1; } return res; } int kai(int x, int y) { int res = 1; for (int i = x - y + 1; i <= x; i++) { res *= (i % mod); res %= mod; } return res; } int comb(int x, int y) { if (y > x)return 0; return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod; } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) class UnionFind { protected: int* par, * rank, * size; public: UnionFind(unsigned int size) { par = new int[size]; rank = new int[size]; this->size = new int[size]; rep(i, size) { par[i] = i; rank[i] = 0; this->size[i] = 1; } } int find(int n) { if (par[n] == n)return n; return par[n] = find(par[n]); } void unite(int n, int m) { n = find(n); m = find(m); if (n == m)return; if (rank[n] < rank[m]) { par[n] = m; size[m] += size[n]; } else { par[m] = n; size[n] += size[m]; if (rank[n] == rank[m])rank[n]++; } } bool same(int n, int m) { return find(n) == find(m); } int getsize(int n) { return size[find(n)]; } }; int n, m, ans; int p[114514]; int memo[114514]; signed main() { UnionFind uf(114514); cin >> n >> m; rep(i, n)cin >> p[i]; rep(i, m) { int x, y; cin >> x >> y; uf.unite(x, y); } rep(i, n)memo[p[i]] = i + 1; for (int i = 1; i <= n; i++) { if (uf.same(memo[i], i))ans++; } cout << ans << endl; ggr }
0
39,604,492
#define fi first #define se second #define mp make_pair #define pb push_back #define LOCAL 1 #include<bits/stdc++.h> using namespace std; #ifdef LOCAL #define dbg(...) cout<<#__VA_ARGS__ ": ["; for(auto e: __VA_ARGS__){cout<<e<<", ";} cout<<"]\n" #define dbg1(...) cout<<#__VA_ARGS__ " "<< __VA_ARGS__ #else #define dbg(...) 1; #define dbg1(...) 1; #endif typedef long long ll; typedef unsigned long long ull; constexpr int R=5e6+69, INF=2e9+6969; int qq; int main() { string s; cin >> s; if(s[0]==s[1] && s[1]==s[2]) puts("Yes"); else if(s[2]==s[3] && s[1]==s[2]) puts("Yes"); else puts("No"); return 0; }
#include <iostream> #include <cstdio> #include <algorithm> #include <cmath> #include <vector> #include <list> #include <set> #include <map> #include <queue> #include <stack> #include <cctype> #include <cassert> #include <climits> #include <iostream> #include <cstdio> #include <algorithm> #include <cmath> #include <vector> #include <list> #include <set> #include <map> #include <queue> #include <stack> #include <cctype> #include <cassert> #include <climits> #include <string> #include <bitset> #include <cfloat> #include <unordered_set> #pragma GCC optimize('Ofast') using namespace std; typedef long double ld; typedef long long int ll; typedef unsigned long long int ull; typedef vector<int> vi; typedef vector<char> vc; typedef vector<bool> vb; typedef vector<double> vd; typedef vector<string> vs; typedef vector<ll> vll; typedef vector<pair<int,int> > vpii; typedef vector<vector<int> > vvi; typedef vector<vector<char> > vvc; typedef vector<vector<string> > vvs; typedef vector<vector<ll> > vvll; #define rep(i,n) for(int i = 0; i < (n); ++i) #define rrep(i,n) for(int i = 1; i <= (n); ++i) #define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++) #define drep(i,n) for(int i = (n) - 1; i >= 0; --i) #define fin(ans) cout << (ans) << endl #define mp(p,q) make_pair(p, q) #define pb(n) push_back(n) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define Sort(a) sort(a.begin(), a.end()) #define Rort(a) sort(a.rbegin(), a.rend()) #define MATHPI acos(-1) int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; 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(a>b){a=b;return 1;} return 0;} struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}}; const int INF = INT_MAX; const ll LLINF = 1LL<<60; const ll MOD = 1000000007; const double EPS = 1e-9; int main(void) { ll N,K; cin >> N >> K; vll A(N),Max(N+1); int m = -1; rep(i,N){ cin >> A[i]; Max[i+1] = A[i]; }; rep(i,N) { Max[i+1] = max(Max[i+1],Max[i]); } ll value=LLINF; rep(bit,1<<N){ vll idxs; rep(i,N){ if(bit&1<<i){ idxs.push_back(i); } } if(idxs.size() != K) continue; ll maxH = 0 ,res=0; rep(i,K){ maxH = max(maxH,Max[idxs[i]]); if(A[idxs[i]] <= maxH){ maxH++; res += maxH - A[idxs[i]]; }else{ maxH = A[idxs[i]]; } } value = min(value,res); } fin(value); }
0
81,564,028
#include <bits/stdc++.h> using namespace std; #define DUMP(x) cerr << #x << "=" << x << endl #define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl #define BINARY(x) static_cast<bitset<16> >(x) #define rep(i,n) for(int i=0;i<(int)(n);i++) #define REP(i,m,n) for (int i=m;i<(int)(n);i++) #define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h)) #define ALL(a) (a).begin(),(a).end() typedef long long ll; const int INF = 1e9; typedef pair<int, int> PII; int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1}; int main() { ios::sync_with_stdio(false); int dp[50] = {}; dp[0] = dp[1] = 1; REP(i, 2, 50) dp[i] = dp[i-1] + dp[i-2]; int N; cin >> N; cout << dp[N] << endl; }
#include <stdio.h> int selectionSort(int arr[], int n) { int i, j, tmp, count = 0, min; for (i = 0; i < n - 1; i++) { min = i; for (j = i; j < n; j++) { if (arr[j] < arr[min]) { min = j; } } tmp = arr[i]; arr[i] = arr[min]; arr[min] = tmp; if (i != min) { count++; } } return count; } int main() { int arr[100], n, i, count; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d", &arr[i]); } count = selectionSort(arr, n); for (i = 0; i < n; i++) { if (i > 0) { printf(" "); } printf("%d", arr[i]); } printf("\n"); printf("%d\n", count); return 0; }
0
12,957,633
#include<cstdio> #include<cstring> using namespace std; const int MAXN=3000; typedef unsigned long long ull; const int maxn=1e5+5; typedef long long ll; int ans[200][200]; int main(){ memset(ans,0,sizeof(ans)); int a,b; scanf("%d%d",&a,&b); printf("100 100\n"); int i,j; for (i=0;i<100;i++){ for (j=0;j<100;j++){ if (i%2) ans[i][j]=0; else { if (a==1) ans[i][j]=0; else { if (j%2==0) { ans[i][j]=1; a--; } else ans[i][j]=0; } } } if (a==1) break; } i++; if (i%2){ for (j=0;j<100;j++) ans[i][j]=0; i++; } for (j=0;j<100;j++) ans[i][j]=1; i++; b--; for (;i<100;i++) for (j=0;j<100;j++){ if (i%2==0) ans[i][j]=1; else { if (b==0) ans[i][j]=1; else { if (j%2==0) { ans[i][j]=0; b--; } else ans[i][j]=1; } } } for (i=0;i<100;i++){ for (j=0;j<100;j++) if (ans[i][j]) printf("."); else printf("#"); printf("\n"); } }
#include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include <iostream> #include <complex> #include <string> #include <algorithm> #include <numeric> #include <vector> #include <queue> #include <stack> #include <map> #include <set> #include <unordered_map> #include <unordered_set> #include <functional> #include <cassert> typedef long long ll; using namespace std; #ifndef LOCAL #define debug(x) ; #else #define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl; template <typename T1, typename T2> ostream &operator<<(ostream &out, const pair<T1, T2> &p) { out << "{" << p.first << ", " << p.second << "}"; return out; } template <typename T> ostream &operator<<(ostream &out, const vector<T> &v) { out << '{'; for (const T &item : v) out << item << ", "; out << "\b\b}"; return out; } #endif #define mod 1000000007 #define INF 1000000000 #define LLINF 2000000000000000000LL #define SIZE 200010 typedef double P_type; typedef double G_real; typedef complex<P_type> P; const G_real P_eps = 1e-8; namespace std{ template<class T> bool operator<(const complex<T> &a, const complex<T> &b){ return abs(a.real() - b.real()) < P_eps ? a.imag() + P_eps < b.imag() : a.real() + P_eps < b.real(); } }; P rotate(P p, double theta){ return p * P(cos(theta), sin(theta)); } P_type dot(P a, P b) { return (a * conj(b)).real(); } P_type cross(P a, P b) { return (conj(a) * b).imag(); } int ccw(P a, P b, P c){ if(cross(b-a, c-a) > P_eps) return 1; if(cross(b-a, c-a) < -P_eps) return -1; if(dot(b-a, c-a) < -P_eps) return -2; if(dot(a-b, c-b) < -P_eps) return 2; return 0; } int main(){ int N, x[100], y[100]; pair<P,int> p[200]; cin >> N; for (int i=0; i<N; i++) { cin >> x[i] >> y[i]; p[i] = {arg(P(x[i], y[i])), i}; } sort(p, p+N); for (int i=0; i<N; i++) { p[i+N] = p[i]; p[i+N].first += M_PI * 2; } double ans = 0; int r = 0; for (int i=0; i<N; i++) { while(abs(p[i].first - p[r].first) < M_PI + P_eps) { r++; } ll sumx = 0, sumy = 0; for (int j=i; j<r; j++) { sumx += x[p[j].second]; sumy += y[p[j].second]; ans = max(ans, sqrt(sumx * sumx + sumy * sumy)); } } printf("%.15lf\n", ans); return 0; }
0
6,888,413
#include <iostream> int main(){ int n,count=0; std::cin >> n; for(int i=1; i<=n; i++){ count += i; } std::cout << count << std::endl; return 0; }
#include "bits/stdc++.h" using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll; typedef pair< int, int > pii; typedef vector<pii>vip; typedef pair< pii, int > ppi; #define fill(a,b) memset(a,b,sizeof(a)) #define all(v) (v).begin(),(v).end() #define sp(k) cout<<setprecision(k)<<fixed; #define rep(i,a) for(int i=0;i<a;i++) #define rep1(i,a,b) for(int i=(a);i<=(b);++i) #define irep(i,b,a) for(int i=(b);i>=(a);--i) #define minv(v) *min_element(all(v)) #define maxv(v) *max_element(all(v)) #define unq(v) sort(all(v)),(v).erase(unique(all(v)),(v).end()) #define _ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define endl "\n" #define sqr(a) ((a)*(a)) #define sz(a) int(a.size()) #define ff first #define ss second #define pb push_back const double pi = acos(-1.0); const int mod = 1000000007; const int inf = 0x3f3f3f3f; const int maxn = 200005; void task(){ string a,b; cin >> a >> b; int mx = 0,mx2 =0; for(int i = 0; i<a.size();i++){ mx = max(mx,a[i]-'a'); } for(int i = 0; i<b.size();i++){ mx2 = max(mx2,b[i]-'a'); } sort(all(a)); sort(all(b)); reverse(all(b)); if(a<b) cout << "Yes" << endl; else cout <<"No" << endl; } int main(){ _ #ifdef OJ freopen("inputf.in", "r", stdin); freopen("outputf.in", "w", stdout); #endif int T = 1; while(T--){ task(); } return 0; }
0
76,837,769
#include <bits/stdc++.h> #define REP(i,n) for(ll i=0;i<(ll)(n);i++) #define REPD(i,n) for(ll i=n-1;i>=0;i--) #define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++) #define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--) #define ALL(x) (x).begin(),(x).end() #define SIZE(x) ((ll)(x).size()) #define MAX(x) *max_element(ALL(x)) #define MIN(x) *min_element(ALL(x)) #define INF 1000000000 using namespace std; typedef long long ll; int main() { int N, A, B; cin >> N >> A >> B; int mid = abs(A - B) - 1; if (mid%2 != 0){ cout << "Alice" << endl; } else{ cout << "Borys" << endl; } }
#include <bits/stdc++.h> using namespace std; const long long int INF = 1e6; int V,E; vector<vector<long long int>> d; int main(){ cin >> V >> E; d.assign(V, vector<long long int>(V, INF)); for (int i=0; i<V; i++){ d[i][i] = 0; } vector<int> a(E), b(E), c(E); for (int i=0; i<E; i++){ int u, v, w; cin >> u >> v >> w; u -= 1; v -= 1; d[u][v] = w; d[v][u] = w; a[i] = u; b[i] = v; c[i] = w; } for (int k=0; k<V; k++){ for (int i=0; i<V; i++){ for (int j=0; j<V; j++){ d[i][j] = min( d[i][j], d[i][k] + d[k][j] ); } } } int ans = E; for (int i=0; i<E; i++){ bool used = false; for (int j=0; j<V; j++){ if(d[j][a[i]] + c[i] == d[j][b[i]]) used = true; } if(used == true) ans -= 1; } cout << ans << endl; return 0; }
0
55,516,854
#include<bits/stdc++.h> using namespace std; int main() { string s,c; cin>>s; cin>>c; c.erase(c.begin()+s.length(),c.end()); if(c==s) cout<<"Yes\n"; else cout<<"No\n"; return 0; }
#include <iostream> #include <vector> #include <bitset> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main(){ int N, M; cin >> N >> M; vector<vector<int>> s(M, vector<int>(N)); rep(i, M){ int k; cin >> k; s.at(i).resize(k); rep(j, k){ cin >> s.at(i).at(j); } } vector<int> p(M); rep(i, M){ cin >> p.at(i); } int ans = 0; for(int tmp=0; tmp<(1<<10); tmp++){ bitset<10> o(tmp); bool x = true; rep(i, M){ int on = 0; rep(j, s.at(i).size()){ if(o.test(s.at(i).at(j)-1)){ on++; } } if(on%2!=p.at(i)){ x = false; break; } } if(x){ ans++; } } int m = 1; rep(i, 10-N){ m *= 2; } cout << ans/m; return 0; }
0
47,532,371
#include <bits/stdc++.h> using namespace std; using ll = long long; #define countof(a) (sizeof(a)/sizeof((a)[0])) #define rep(i, n) for(int i = 0; i < (n); i++) #define SP << " " << signed main() { cin.tie(0); ios::sync_with_stdio(false); ll AB[2], K; cin >> AB[0] >> AB[1] >> K; rep(i, K) { AB[i%2] = (AB[i%2] & 0xfffffffffffffffe) >> 1; AB[(i+1)%2] += AB[i%2]; } cout << AB[0] SP AB[1] << endl; }
#include <bits/stdc++.h> using namespace std; long long arr[100005]; int main(){ long long n; scanf("%lld",&n); long long sum=0; for (int x = 0; x<n; x++){ scanf("%lld",&arr[x]); sum += arr[x]; } if (sum%((n*(n+1LL))/2LL)!=0LL){ printf("NO"); return 0; } long long t = sum/((n*(n+1))/2); for (int x = 0; x<n; x++){ long long diff; if (x==0) diff = arr[0]-arr[n-1]; else diff = arr[x]-arr[x-1]; if (diff>t){ printf("NO"); return 0; } diff-=t; diff = -diff; if (diff%n!=0){ printf("NO"); return 0; } } printf("YES"); }
0
24,094,553
#include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<algorithm> #include<map> #include<set> #include<queue> using namespace std; using ll=long long; using vi=vector<int>; using vvi=vector<vi>; using pii=pair<int,int>; using vll=vector<ll>; using vvll=vector<vll>; using vpii=vector<pii>; #define PI 3.1415926535897932384626433832795 int main(void) { int k, x; while(scanf("%d%d", &k, &x)==2) { bool ans=(k*500>=x); printf("%s\n", ans?"Yes":"No"); } return 0; }
#include <bits/stdc++.h> #define ll long long int #define pb emplace_back #define mk make_pair #define pq priority_queue #define FOR(i, a, b) for(int i=(a);i<(b);++i) #define rep(i, n) FOR(i, 0, n) #define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--) #define all(x) (x).begin(),(x).end() #define sz(x) ((int)(x).size()) #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) #define FI first #define SE second using namespace std; typedef pair<int, int> P; typedef pair<ll, int> Pl; typedef pair<ll, ll> Pll; typedef pair<double, double> Pd; const int inf = 1e9; const ll linf = 1LL << 50; const double EPS = 1e-10; const int mod = 1e9 + 7; 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(a > b){a = b; return 1;} return 0;} template <typename T> istream &operator>>(istream &is, vector<T> &vec){for(auto &v: vec)is >> v; return is;} typedef struct UnionFind_ { vector<int> par; vector<int> rank_; UnionFind_(int n): rank_(n, 0) { for(int i = 0; i < n; i++)par.push_back(i); } int find(int x) { if(par[x] == x)return x; else return par[x] = find(par[x]); } bool same(int x, int y) { if(find(x) == find(y))return true; else return false; } bool unite(int x, int y){ int xp = find(x); int yp = find(y); if(xp == yp)return false; if(rank_[xp] > rank_[yp])par[yp] = xp; else if(rank_[xp] < rank_[yp])par[xp] = yp; else { par[yp] = xp; rank_[xp]++; } return true; } } UnionFind; int main(int argc, char const* argv[]) { ios_base::sync_with_stdio(false); cin.tie(0); int n, q; cin >> n >> q; UnionFind uf(n); rep(i, q){ int c, x, y; cin >> c >> x >> y; if(c == 0)uf.unite(x, y); else { if(uf.same(x, y))cout << 1 << endl; else cout << 0 << endl; } } return 0; }
0
28,137,551
#include <bits/stdc++.h> using namespace std; int main(){ string S; cin >> S; int start; if ((int)(S.length()) % 2 == 1){ start = (int)(S.length()) - 1; } else{ start = (int)(S.length()) - 2; } for (int i = start; i > 0; i -= 2){ int num = 1; while (num <= i / 2){ if (S.at(num - 1) != S.at(num - 1 + i / 2)){ break; } num++; } if (num == i / 2 + 1){ cout << i << endl; exit(0); } } }
#include <bits/stdc++.h> using namespace std; typedef long long LL; const int N = 200005; int a[N]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); LL ans = 0, tot = 0; for (int i = 1, j = 1; i <= n; i++) { for (; (a[j] ^ tot) == (a[j] + tot) && (j <= n); j++) tot ^= a[j]; ans += j - i; tot ^= a[i]; } printf("%lld\n", ans); return 0; }
0
16,279,169
#include <bits/stdc++.h> using namespace std; int main() { double r = 0.0; double g = 0.0; cin >> r; cin >> g; cout << 2 * g -r << endl; }
#include <iostream> using namespace std; int main(int argc, const char * argv[]) { int n; cin>>n; int a[n]; int count = 0; for(int i=0;i<n;i++){ cin>>a[i]; } for(int i=0;i<n;i++){ int minj = i; for(int j=i;j<n;j++){ if(a[j]<a[minj]){ minj = j; } } if(a[i]!=a[minj]){ int tmp = a[i]; a[i]=a[minj]; a[minj]=tmp; count++; } } cout<<a[0]; for(int i = 1;i<n;i++){ cout<<' '<<a[i]; } cout<<endl; cout<<count<<endl; }
0
39,962,307
#include<iostream> #include<algorithm> #include<vector> #include<string> #include<cmath> #include<cstdio> #include<queue> #include<deque> using namespace std; typedef pair<int,int> ii; typedef long long ll; typedef pair<ll,ll> pll; const int INF=1e9; const ll MOD=1e9+7; ll gcd(ll x,ll y){ if(y==0) return 0; return gcd(y,x%y); } int dis2(int x1,int y1,int x2,int y2){ return (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2); } int main(){ string s;cin>>s; if(s.size()>=4&&s.substr(0,4)=="YAKI"){ cout<<"Yes"<<endl; }else cout<<"No"<<endl; return 0; }
#include <bits/stdc++.h> #include <vector> # include <cstdint> #define FOR(i,l,r) for(int i=(l);i<(r);++i) #define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--) #define rep(i,n) FOR(i,0,n) #define rrep(i,n) RFOR(i,n-1,0) #define int long long using namespace std; const int MX = 1e6; const int inf = 1e13; const int mod = 1e9+7; #define ll long long map<char, int> m; signed main() { int n,h,w; cin >> n >> h >> w; int ans = 0; rep(i,n) { int a,b; cin >> a >> b; if(h<=a && w<=b) { ans++; } } cout << ans << endl; }
0
33,232,903
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { long long N, ans = 1000000007; cin >> N; vector<long long> W(N), W_sum(N+1,0); rep(i, N){ cin >> W[i]; } rep(i,N) { W_sum[i+1] = W_sum[i] + W[i]; } for(int i = 1; i <= N+1; ++i) { ans = min(ans, abs((W_sum[N] - W_sum[i]) - W_sum[i])); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0; i<n; i++) #define cans cout << ans << endl #define cyes cout << "Yes" << endl #define cno cout << "No" << endl typedef long long ll; const ll MOD = 1000000007; int main(){ int n,m; cin >> n >> m; vector<int> a(m+2); for(int i=1; i<=m; i++) cin >> a[i]; a[0] = -1; a[m+1] = n+1; vector<ll> mfib(100001); mfib[0] = 1; mfib[1] = 1; for(int i=2; i<=100000; i++){ mfib[i] = ((mfib[i-1]%MOD) + (mfib[i-2]%MOD))%MOD; } ll ans = 1; for(int i=0; i<=m; i++){ int dif = a[i+1]-a[i]-2; if(dif==-1) { cout << 0 << endl; return 0; } ans *= mfib[dif]; ans %= MOD; } cout << ans << endl; return 0; }
0
37,703,401
#include<bits/stdc++.h> using namespace std; int main(){ long long L,R; cin >> L >> R; long long ans = 9999999999; for(long long i = L; i <= R - 1; i++){ for(long long j = i + 1; j <= R; j++){ if( ((i % 2019) * (j % 2019) % 2019) == 0){ cout << 0 <<endl; return 0; } else if(((i % 2019) * (j % 2019) % 2019) < ans){ ans = ((i % 2019) * (j % 2019) % 2019); } } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main(){ int N,b_num=0,ans=0,i=0; cin >> N; int data[N]; for(int i=0;i<N;i++) cin >> data[i]; for(int i=0;i<N;i++) data[i]--; while(1){ ans++; if(data[b_num] == 1) break; int next = data[b_num]; if(i > 1000000){ans = -1; break;} b_num = next; i++; } cout << ans << endl; }
0
77,869,763
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/trie_policy.hpp> #include <ext/rope> #pragma GCC optimize("Ofast") #pragma GCC optimize ("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; using namespace __gnu_pbds; using namespace __gnu_cxx; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define fi first #define se second #define pb push_back #define mp make_pair #define gcd __gcd #define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define rep(i, n) for (int i=0; i<(n); i++) #define rep1(i, n) for (int i=1; i<=(n); i++) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define endl "\n" typedef long long ll; typedef unsigned long long ull; typedef unsigned uint; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef vector<ll> vll; typedef vector<vector<ll>> vvll; typedef vector<bool> vb; typedef vector<vector<bool>> vvb; template<typename _def> using ordered_set=tree<_def, null_type, less<_def>, rb_tree_tag, tree_order_statistics_node_update>; typedef trie<string, null_type, trie_string_access_traits<>, pat_trie_tag, trie_prefix_search_node_update> pref_trie; const int bits=40; int32_t main() { int n, k; cin>>n>>k; int a[n]; rep(i, n) cin>>a[i]; vll elem; elem.reserve(n*(n+1)/2); ll pf[n+1]={0}; rep1(i, n) { pf[i]=pf[i-1]+a[i-1]; rep(j, i) elem.pb(pf[i]-pf[j]); } ll ans=0; for(int i=bits; i>=0; i--) { int cnt=0; bool vis[elem.size()]={0}; rep(j, elem.size()) if(elem[j]&(1LL<<i)) cnt++, vis[j]=1; if(cnt<k) continue; ans|=(1LL<<i); vll cur; cur.reserve(cnt); rep(j, elem.size()) if(vis[j]) cur.pb(elem[j]); elem=cur; } cout<<ans<<endl; }
#include <algorithm> #include <iostream> #include <stdio.h> using namespace std; int main(void){ int i,IMAX=0,num[100]={0},a,ans=0,max=0; while(cin >> a){ num[a-1]++; IMAX++; } for(i=0;i<IMAX;i++){ if(max<num[i]){ max=num[i]; ans=i+1; } } cout << ans << endl; for(i=ans;i<IMAX;i++){ if(max==num[i]) cout << i+1 << endl; } return 0; }
0
15,359,326
#include <iostream> using namespace std; int main(){ int n; float x1,x2,x3,x4,y1,y2,y3,y4; cin >> n; for(int i=0;i<n;i++) { cin>>x1>>y1>>x2>>y2>>x3>>y3>>x4>>y4; if( (y2-y1)/(x2-x1) == (y4-y3)/(x4-x3) ) cout<<"YES\n"; else cout<<"NO\n"; } return 0; }
#include<stdio.h> #include<vector> #include<algorithm> using lint = long long; using std::pair; using std::vector; using pll = pair<lint, lint>; int main() { int n, k; scanf("%d%d", &n, &k); vector<pll> vec; for (int i = 0; i < n; i++) { lint a, b; scanf("%lld%lld", &a, &b); vec.push_back({ a,b }); } lint ans = 0; for (pll p : vec) { if ((p.first|k) == k) { ans += p.second; } } for (int i = 0; i <= 30; i++) { if (k&(1 << i)) { int q = (1 << i) - 1; int tmp = (k | q) ^ (1<<i); lint sum = 0; for (pll p : vec) { if ((p.first|tmp) == tmp) { sum += p.second; } } ans = std::max(ans, sum); } } printf("%lld", ans); }
0
20,119,211
#include <bits/stdc++.h> #define rep(i, n) for(int i = 0; i < (int)(n); i++) #define copy(from, to) copy(from.begin(), from.end(), back_inserter(to)) #define sort(a) sort(a.begin(), a.end()) #define reverse(s) reverse(s.begin(), s.end()) #define p(s) cout << (s) << endl typedef long long ll; using namespace std; template<class T> void load(vector<T> &v, int n) { for (int i = 0; i < n; ++i) { T t; cin >> t; v.push_back(t); } } template<class T> T max(vector<T> &v) { return *max_element(v.begin(), v.end()); } template<class T> T min(vector<T> &v) { return *min_element(v.begin(), v.end()); } int main() { int n, k; cin >> n >> k; p(n - k + 1); }
#include <iostream> #include <algorithm> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <string.h> #include <vector> #include <queue> #include <cmath> #include <bitset> #include <complex> #include <functional> #include <numeric> #include <iomanip> #define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' '); #define YES cout << "YES" << endl #define Yes cout << "Yes" << endl #define NO cout << "NO" << endl #define No cout << "No" << endl #define ALL(i) (i).begin(), (i).end() #define FOR(i, a, n) for(int i=(a);i<(n);++i) #define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i) #define REP(i, n) for(int i=0;i<int(n);++i) #define RREP(i, n) for(int i=int(n)-1;i>=0;--i) #define IN(a, x, b) (a<=x && x<b) #define OUT(a, x, b) (x<a || b<=x) 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 (a > b) { a = b; return 1; } return 0; } #define int ll using ll = long long; using ull = unsigned long long; using ld = long double; const int MOD = 1000000007; const int INF = 1e18; const double PI = acos(-1); using namespace std; struct INIT { INIT(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(10); }}INIT; signed main() { int N, M; cin >> N >> M; map<int, int> m; m[0] = 1; int sum = 0; REP(i, N){ int A; cin >> A; sum += A; m[sum%M]++; } int ans = 0; for(auto p : m) ans += p.second*(p.second-1)/2; cout << ans << "\n"; return 0; }
0
24,838,573
#include<bits/stdc++.h> #define PI 3.14159265359 using namespace std; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) const long long INF= 1e+18+1; typedef long long ll; typedef vector<ll> vl; typedef vector<vector<ll> >vvl; typedef pair<ll,ll> P; typedef tuple<ll,ll,ll> T; const ll MOD=1000000007LL; string abc="abcdefghijklmnopqrstuvwxyz"; string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ"; int main(){ ll n;cin>>n; vl a(n),b(n); rep(i,n)cin>>a[i]; rep(i,n)cin>>b[i]; vector<bool>vec(n,true); vec[0]=false; vec[n-1]=false; vector<bool>vec1(n,true); vector<bool>vec2(n,true); vec1[0]=false; vec2[n-1]=false; rep(i,n-1){ if(a[i+1]!=a[i]){ vec[i+1]=false; vec1[i+1]=false; } } for(ll i=n-2;i>=0;i--){ if(b[i+1]!=b[i]){ vec[i]=false; vec2[i]=false; } } rep(i,n){ if(vec1[i]==false){ if(a[i]>b[i]){ cout<<0<<endl; return 0; } } if(vec2[i]==false){ if(a[i]<b[i]){ cout<<0<<endl; return 0; } } if(a[n-1]!=b[0]){ cout<<0<<endl; return 0; } } ll ans=1; rep(i,n){ if(vec[i]){ ans*=min(a[i],b[i]); ans%=MOD; } } cout<<ans<<endl; }
#include <bits/stdc++.h> #include <math.h> #include <algorithm> using namespace std; int main(){ int n;cin >> n; int arr[n]; for(int i=0;i<n;i++){ cin >> arr[i]; } sort(arr,arr+n); int mid1 = arr[n/2-1]; int mid2 = arr[n/2]; int ans = 0; if(mid1 < mid2){ for(int i=mid1+1;i<=mid2;i++){ ans++; } } cout << ans << endl; }
0
88,537,824
#include <stdio.h> #include <string.h> int main(){ char S[100]; scanf("%s",&S); if (strcmp(S, "AAA")==0 || strcmp(S,"BBB")==0){ printf("No\n"); } else { printf("Yes\n"); } return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define zero_pad(num) setfill('0') << std::right << setw(num) using namespace std; using ll = long long; using ld = long double; using P = pair<int, int>; int main() { string s; cin >> s; int n = s.size(); vector<vector<ll>> dp(n, vector<ll>(2, 0)); dp[0][0] = 2; dp[0][1] = 1; ll mod = 1000000007; for(int i = 1; i < n; i++){ if(s[i] == '0'){ dp[i][0] = dp[i-1][0]; dp[i][1] = dp[i-1][1] * 3 % mod; }else{ dp[i][0] = dp[i-1][0] * 2 % mod; dp[i][1] = dp[i-1][0] + dp[i-1][1] * 3 % mod; dp[i][1] %= mod; } } cout << (dp[n-1][0] + dp[n-1][1]) % mod << endl; }
0
47,580,856
#include <iostream> #include <algorithm> using namespace std; int main() { long long a,b,c,d; cin>>a>>b>>c>>d; long long s1=min(a,b); long long s2=min(c,d); cout<<s1+s2<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i)) #define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i)) #define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i)) #define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i)) #define ALL(x) (x).begin(),(x).end() #define Ceil(x, n) (((((x))+((n)-1))/n)) #define CeilN(x, n) (((((x))+((n)-1))/n)*n) #define INF 2e7 #define INF_LL 1LL<<60 #define ll long long typedef pair<ll, ll> P; int main(){ ll h, w, m; cin >> h >> w >> m; vector<ll> yoko(h), tate(w); vector<P> bomb(m); REP(i, h) yoko[i] = 0; REP(i, w) tate[i] = 0; REP(i, m) { ll x, y; cin >> x >> y; x--, y--; yoko[x]++, tate[y]++; bomb[i].first = x, bomb[i].second = y; } ll yoko_max = 0, tate_max = 0, yoko_max_num = 0, tate_max_num = 0; REP(i, h) yoko_max = max(yoko_max, yoko[i]); REP(i, w) tate_max = max(tate_max, tate[i]); REP(i, h) if(yoko_max == yoko[i]) yoko_max_num++; REP(i, w) if(tate_max == tate[i]) tate_max_num++; ll num = yoko_max_num * tate_max_num; REP(i, m) { int x = bomb[i].first; int y = bomb[i].second; if(yoko[x] == yoko_max && tate[y] == tate_max) { num--; } } ll ans = 0; if(num > 0) { ans = yoko_max + tate_max; } else { ans = yoko_max + tate_max - 1; } cout << ans << endl; return 0; }
0
73,723,644
#include <bits/stdc++.h> using namespace std; int num_of_div(int n) { int res = 0; for (int i = 1; i * i <= n; i++) { if (i * i == n) { res++; continue; } if (n % i == 0) res += 2; } return res; } int main() { int N; cin >> N; int ans = 0; for (int i = 1; i <= N; i += 2) { if (num_of_div(i) == 8) ans++; } cout << ans << endl; }
#include<bits/stdc++.h> #define ll long long #define pb push_back #define ff first #define ss second #define pll pair<ll,ll> #define v vector<ll> #define st stack<ll> #define pq priority_queue <int> #define q queue<ll> #define mod 1000000005 using namespace std; int solve(int arr[],int n){ int res=0; for (int i =0; i<= n - 1; i++) { int val = 0; for (int j =i; j<= n - 1; j++) { val = val + arr[j]; if (val % 2 != 0) res++; } } return (res); } int main(){ int a,b,c; cin>>a>>b>>c; if(c>=a && c<=b){ cout<<"Yes"<<endl; return 0; } cout<<"No"<<endl; return 0; }
0
3,481,124
#include <bits/stdc++.h> using namespace std; typedef long long int64; typedef vector<int> vec; typedef vector<int64> vec64; #define db(x) cout << "> " << #x << ": " << x << "\n"; #define ss cout << " "; #define ct(x) cout << x; #define nn cout << "\n"; #define cts(x) cout << x << " "; #define ctn(x) cout << x << "\n"; #define qr queries(); void solve(); void YN(bool b){if (b){ctn("YES");}else{ctn ("NO");}}; void yn(bool b){if (b){ctn("Yes");}else{ctn ("No");}}; void queries(){int n;cin >> n;while (n--)solve();} int64 q, n; void solve(){ return; } int main(){ ios_base::sync_with_stdio(0);cin.tie(0); int64 n; cin >> n; if (n % 2 == 1){ ctn(0); return 0; } int64 rs = 0; for (int64 i = 5; i <=n; i*=5){ rs+= n / (i * 2); } ctn(rs); return 0; }
#include <bits/stdc++.h> #if DEBUG template <typename T> void debug(const T& value) { std::cerr << value; } template <typename T, typename... Ts> void debug(const T& value, const Ts&... args) { std::cerr << value << ", "; debug(args...); } #define dbg(...) \ do { \ cerr << #__VA_ARGS__ << ": "; \ debug(__VA_ARGS__); \ cerr << " (L" << __LINE__ << ")\n"; \ } while (0) #else #define dbg(...) #endif void read_from_cin() {} template <typename T, typename... Ts> void read_from_cin(T& value, Ts&... args) { std::cin >> value; read_from_cin(args...); } #define rd(type, ...) \ type __VA_ARGS__; \ read_from_cin(__VA_ARGS__); template <typename T> void write_to_cout(const T& value) { std::cout << value << '\n'; } template <typename T, typename... Ts> void write_to_cout(const T& value, const Ts&... args) { std::cout << value << ' '; write_to_cout(args...); } #define wt(...) write_to_cout(__VA_ARGS__); #define all(x) (x).begin(), (x).end() #define rep(i, n) for (int i = 0; i < (int)(n); ++i) using ll = long long; template <typename T> using V = std::vector<T>; template <typename T> using VV = V<V<T>>; using namespace std; int main() { rd(int, a, b, c); int ans = 0; while (true) { if (a > b) swap(a, b); if (b > c) swap(b, c); if (a > b) swap(a, b); if (a > 0) c -= a, b -= a, a = 0; if (c == 0) break; if (a == b) { ++a, ++b; } else { a += 2; } ++ans; }; wt(ans); }
0
17,974,893
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> B(n-1); for(int i = 0; i < n-1; i++) cin >> B[i]; vector<int> A(n); A[0] = B[0]; A[n-1] = B[n-2]; for (int i = 1; i < n - 1; i++) { A[i] = min(B[i], B[i - 1]); } cout << accumulate(A.begin(), A.end() , 0) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll MOD = 1e9 + 7; map<pair<int,int>,int> mp; int dy[9] = {0,1,1,0,-1,-1,-1,0,1}; int dx[9] = {0,0,1,1,1,0,-1,-1,-1}; vector<ll> ans(10); int main(){ ll h, w, n; cin >> h >> w >> n; for (int i = 0; i < n; i++) { ll a, b; cin >> a >> b; for (int j = 0; j < 9; j++) { mp[make_pair(a + dx[j], b + dy[j])]++; } } ans[0] = (h - 2) * (w - 2); for (auto p : mp) { if (p.first.first >= 2 && p.first.first <= h - 1 && p.first.second >= 2 && p.first.second <= w - 1) { ans[p.second]++; ans[0]--; } } for (int i = 0; i <= 9; i++) { cout << ans[i] << endl; } return 0; }
0
11,546,090
#include <iostream> #include <vector> #include <map> using namespace std; struct UnionFind { vector<int> par; UnionFind(int n) : par(n) { for (int i = 0; i < n; ++i) par[i] = i; } void init(int n) { par.resize(n); for (int i = 0; i < n; ++i) par[i] = i; } int root(int x) { if (par[x] == x) return x; else return par[x] = root(par[x]); } bool issame(int x, int y) { return root(x) == root(y); } bool merge(int x, int y) { x = root(x); y = root(y); if (x == y) return false; par[x] = y; return true; } }; int main() { int N, Q; cin >> N >> Q; UnionFind uf(N); for (int q = 0; q < Q; ++q) { int com, x, y; cin >> com >> x >> y; if (com == 0) uf.merge(x, y); else { if (uf.issame(x, y)) cout << 1 << endl; else cout << 0 << endl; } } }
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define F first #define S second const int A = 2e5 + 5; const int mod = 1e9 + 7; int add(int x, int y) { return ((x + y) % mod + mod) % mod; } int mul(int x, int y) { return (1LL * x * y) % mod; } int fp (int x, int y) { if (!y) return 1; int acc = fp(x, y / 2); acc = mul(acc, acc); if (y & 1) acc = mul(acc, x); return acc; } int fact[A], inv[A]; void pre() { fact[0] = inv[0] = 1; for (int i = 1; i < A; i++) { fact[i] = mul(fact[i - 1], i); inv[i] = fp(fact[i] , mod - 2); } } int ncr(int n, int r) { return mul(fact[n], mul(inv[n - r], inv[r])); } int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); int n, k; cin >> n >> k; n++, pre(); int ans = 0; for (int i = k; i <= n; i++) { int l = ncr(i, 2) , r = add(ncr(n, 2), -ncr(n - i, 2)); ans = add(ans, add(add(r, -l), 1)); } cout << ans; return 0; }
0
58,718,578
#include <bits/stdc++.h> #define ll long long int #define MOD 1000000007 #define INF 1e18 using namespace std; ll ans = INF; ll n; ll a, b, c; vector<ll> l; void dfs(int x, int y, int z, int u){ if (u == n){ if (x == 0 || y == 0 || z == 0) return; ll A = 0, B = 0, C = 0; ll t = 0; for (int i = 0; i < n; i++){ if ((x >> i) & 1){ A += l[i]; t++; } if ((y >> i) & 1){ B += l[i]; t++; } if ((z >> i) & 1){ C += l[i]; t++; } } ans = min(ans, (t-3)*10 + abs(A - a) + abs(B - b) + abs(C - c)); } else { dfs(x, y, z, u + 1); dfs(x | (1 << u), y, z, u + 1); dfs(x, y | (1 << u), z, u + 1); dfs(x, y, z | (1 << u), u + 1); } } int main(void){ cin >> n >> a >> b >> c; l = vector<ll>(n); for (int i = 0; i < n; i++){ cin >> l[i]; } dfs(0, 0, 0, 0); cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair< ll, ll > Pi; #define rep(i,n) for(int i=0;i<(n);i++) #define rep2(i,n) for(int i=1;i<=(n);i++) #define rep3(i,i0,n) for(int i=i0;i<(n);i++) #define pb push_back #define mod 1000000007 const ll INF = 1LL << 60; 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; } ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;} ll lcm(ll a, ll b) {return a/gcd(a,b)*b;} #define all(x) x.begin(), x.end() #define mp make_pair bool compare(Pi a, Pi b) { if(a.first != b.first){ return a.first < b.first; }else{ return a.second < b.second; } } bool In_map(ll y,ll x,ll h,ll w){ if(y<0 || x<0 || y>=h || x>=w){ return 0; }else{ return 1; } } const vector<ll> dx{1,0,-1,0}; const vector<ll> dy{0,1,0,-1}; int main() { char N; cin >>N; if(N>='A' && N<='Z'){ cout<<'A'<<endl; }else{ cout<<'a'<<endl; } return 0; }
0
83,922,356
#include <bits/stdc++.h> using namespace std; using ll = long long; int main(){ int n, m, d; cin >> n >> m >> d; ll cnt = 0; for(int i=1; i<=n; ++i){ if(d == 0){ ++cnt; continue;} if(i-d >=1) ++cnt; if(i+d <=n) ++cnt; } cnt *= m-1; double ans = (double)cnt /n /n; printf("%.10f", ans); }
#include <bits/stdc++.h> using namespace std; int main(){ long long h, w; cin >> h >> w; long long ans = h*w; vector<long long> area(3); for (int i = 0; i < 2; i++){ for (long long t = 1; t < h; t++){ area[0] = t * w; area[1] = (h-t)*(w/2); area[2] = h*w - area[0] - area[1]; sort(area.begin(),area.end()); ans = min (ans, area[2]-area[0]); area[0] = t*w; area[1] = ((h-t)/2) * w; area[2] = h*w - area[0] - area[1]; sort(area.begin(),area.end()); ans = min(ans, area[2]-area[0]); } swap(h,w); } cout << ans << endl; return 0; }
0
22,937,997
#include<iostream> using namespace std; int main(){ string str,str2; cin >> str; int n = str.size(); for(int i = 0;i < n;i++){ str2.push_back(str[n-i-1]); } cout << str2 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define fastio {\ ios::sync_with_stdio(0);\ cin.tie(0);\ } #define file {\ freopen("io\\in.txt", "r", stdin);\ freopen("io\\out.txt", "w", stdout);\ freopen("io\\err.txt", "w", stderr);\ } #ifdef LOCAL #define debug(args...) {\ string _s(#args);\ replace(_s.begin(), _s.end(), ',', ' ');\ stringstream _ss(_s);\ istream_iterator<string> _it(_ss);\ debug1(_it, args);\ } #pragma GCC diagnostic ignored "-Wunused-parameter" void debug1(istream_iterator<string> it) { cerr << endl; } #pragma GCC diagnostic pop template<class T, class... Args> void debug1(istream_iterator<string> it, T a, Args... args) { cerr << '>' << *it << " = " << a << "; "; debug1(++it, args...); } #else #define debug(args...) #define cerr if (false) cerr #endif using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using si = set<int>; using ii = pair<int, int>; using vii = vector<ii>; #define rep(i, n) for (int i = 0; i < n; i++) #define dotc() int tcs; if (cin >> tcs) rep(tc, tcs) #define sz(x) (int)x.size() #define eb emplace_back #define pb push_back #define mp make_pair #define mt make_tuple #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define fi first #define se second const int inf(0x3fffffff); const int mod(1000000007); const double pi(acos(-1.0)); signed main() { fastio; #ifdef LOCAL file; #endif string s; cin >> s; cout << (count(all(s), '7') ? "Yes" : "No"); return 0; }
0
82,686,739
#include <bits/stdc++.h> using namespace std; int main() { int X[3][3]; for(int i=0; i<3; i++) { for(int j=0; j<3; j++) { cin >> X[i][j]; } } int n; cin >> n; for(int b=0; b<n; b++) { int y; cin >> y; for(int i=0; i<3; i++) { for(int j=0; j<3; j++) { if(X[i][j] == y) X[i][j] = 0; } } } for(int i=0; i<3; i++) { int row_sum = 0; int column_sum = 0; for(int j=0; j<3; j++) { row_sum += X[i][j]; column_sum += X[j][i]; } if(row_sum == 0 || column_sum == 0) { cout << "Yes" << endl; return 0; } } if(X[0][0] + X[1][1] + X[2][2] == 0 || X[0][2] + X[1][1] + X[2][0] == 0) { cout << "Yes" << endl; return 0; } cout << "No" << endl; }
#include <bits/stdc++.h> #define REP(i,n) for (int i=0;i<(n);++i) #define all(a) (a).begin(),(a).end() using namespace std; using ll = long long; int main() { cin.tie(0); ios::sync_with_stdio(false); int N, K; cin >> N >> K; K = min(K, 50); vector<int> A(N); REP(i, N) cin >> A[i]; while (K-- > 0) { vector<int> B(N + 1); REP(i, N) { B[max(i - A[i], 0)] += 1; B[min(i + A[i] + 1, N)] -= 1; } REP(i, N) { B[i + 1] += B[i]; } A = B; } REP(i, N) { cout << A[i] << " "; } cout << endl; return 0; }
0
77,873,686
#include<iostream> #define rep(i,n) for(int i=0; i<(n); ++i) int main(){ int n,m; std::cin >> n >> m; int a, total=0; rep(i,m){ std::cin >> a; total += a; } std::cout << (total > n ? -1 : n-total) << std::endl; return 0; }
#include<bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; typedef long long ll; typedef pair<ll, ll> PLL; typedef vector<int> VI; typedef vector<char> VC; typedef vector<double> VD; typedef vector<string> VS; typedef vector<ll> VLL; typedef vector<PLL> VP; const static int INF = 1000000000; const static int MOD = 1000000007; const int dx[4]={1, 0, -1, 0}; const int dy[4]={0, 1, 0, -1}; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } #define rep(i,n) for (ll i=0; i<(ll)(n); i++) #define repd(i,n) for (ll i=n-1; i>=0; i--) #define rept(i,m,n) for(ll i=m; i<n; i++) #define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr) #define all(x) (x).begin(), (x).end() #define F first #define S second #define PF push_front #define PB push_back #define SORT(V) sort((V).begin(), (V).end()) #define RVERSE(V) reverse((V).begin(), (V).end()) #define paired make_pair #define PRINT(V) for(auto v : (V)) cout << v << " " int ctoi(char c) { if (c >= '0' && c <= '9') { return c - '0'; } return 0; } void cum_sum(int N,vector<ll> a, vector<ll> &s){ for(int i=0; i<N; i++){ s[i+1]=s[i]+a[i];}} ll gcd(ll a,ll b){ if(b == 0) return a; return gcd(b,a%b); } ll lcm(ll a,ll b){ ll g = gcd(a,b); return a / g * b; } bool is_prime(long long n) { if (n <= 1) return false; for (long long p = 2; p * p <= n; ++p) { if (n % p == 0) return false; } return true; } int getdigit(ll num){ unsigned digit=0; while(num!=0){ num /= 10; digit++; } return digit; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int N, K; cin >> N >> K; VLL A(N+1); rep(i,N+1){ A[i]=i; } VLL S(N+2); cum_sum(N+1,A,S); ll ans=0; rept(i,K,N+2){ ll mini=S[i]-S[0]; ll maxi=S[N+1]-S[N+1-i]; ll count=maxi-mini+1; ans+=count; } cout << ans%(MOD) << endl; }
0
94,491,151
#include <algorithm> #include <cstdio> #include <cstdlib> #include <cmath> #include <fstream> #include <iostream> #include <map> #include <queue> #include <string> #include <stack> #include <vector> using namespace std; typedef long long ll; int main(){ int n; cin >> n; priority_queue<pair<ll,pair<ll,ll>>> que; ll sum1 = 0; ll sum2 = 0; for(int i = 0;i < n;i++){ ll a,b; cin >> a >> b; que.push(make_pair(a+b,make_pair(a,b))); } for(int i = 0;i < n;i++){ pair<ll,pair<ll,ll>> p = que.top(); que.pop(); if(i % 2 == 0)sum1 += p.second.first; else sum2 += p.second.second; } cout << sum1 - sum2 << endl; }
#include "bits/stdc++.h" using namespace std; typedef long long ll; typedef pair<int, int> P; typedef vector<int> VI; typedef vector<VI> VVI; const double PI = 3.14159265358979323846; const double EPS = 1e-12; const int INF = numeric_limits<int>::max() / 2; const int NEG_INF = numeric_limits<int>::min() / 2; const int MOD = 1e9 + 7; int main() { cin.tie(0); ios::sync_with_stdio(false); int n,a,b,c,x; while(cin>>n>>a>>b>>c>>x,n||a||b||c||x){ vector<int> y(n); for(int i=0;i<n;i++) cin>>y[i]; int cnt=0,idx=0;; while(true){ if(x==y[idx]) idx++; if(idx==n) break; cnt++; if(cnt>10000) break; x = (a*x+b)%c; } if(cnt>10000) cout<<-1<<endl; else cout<<cnt<<endl; } }
0
84,558,321
#include <bits/stdc++.h> using namespace std; using ll=long long; #define rep(i,n) for(int i=0;i<(int)(n);i++) #define inf 1001001001 #define mod 1000000007 #define mod2 998244353 #define pi acos(-1) #define all(v) v.begin(),v.end() ll gcd(ll a,ll b){ if(b>a) swap(a,b); if(b==0) return a; return gcd(b,a%b); } ll lcm(ll a,ll b){ ll g=gcd(a,b); return a/g*b; } ll rep_jijo(ll n,ll x){ if(x==0) return 1; if(x%2==0){ ll t=rep_jijo(n,x/2); return t*t; } return n*rep_jijo(n,x-1); } int main(){ ll n,k,s; cin >> n >> k >> s; ll x = n-k; rep(i,k){ cout << s << " "; } rep(i,x){ cout << 1000000000-1 <<" "; } cout << endl; }
#include <bits/stdc++.h> using namespace std; int INF = 100000; vector<int> dx = {0, 1, 0, -1}; vector<int> dy = {1, 0, -1, 0}; int main(){ int H, W; cin >> H >> W; vector<string> A(H); for (int i = 0; i < H; i++){ cin >> A[i]; } vector<vector<int>> d(H, vector<int>(W, INF)); queue<pair<int, int>> Q; for (int i = 0; i < H; i++){ for (int j = 0; j < W; j++){ if (A[i][j] == '#'){ d[i][j] = 0; Q.push(make_pair(i, j)); } } } while (!Q.empty()){ int y = Q.front().first; int x = Q.front().second; Q.pop(); for (int i = 0; i < 4; i++){ int y2 = y + dy[i]; int x2 = x + dx[i]; if (0 <= y2 && y2 < H && 0 <= x2 && x2 < W){ if (d[y2][x2] == INF){ d[y2][x2] = d[y][x] + 1; Q.push(make_pair(y2, x2)); } } } } int ans = 0; for (int i = 0; i < H; i++){ for (int j = 0; j < W; j++){ ans = max(ans, d[i][j]); } } cout << ans << endl; }
0
36,348,242
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll,ll> P; typedef pair<int,int> Pi; #define rep(i,n) for(ll i=0;i<n;i++) #define FOR(i,a,b) for(ll i=a;i<b;i++) #define fi first #define se second #define endl "\n" template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;} template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;} template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";} template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";} template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;} template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;} template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;} template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;} template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;} const ll mod=1'000'000'007; const ll inf=1'000'000'000'000'000'00; const int INF=1'000'000'000; const double EPS=1e-10; const double PI=acos(-1); int main(){ cin.tie(0);ios::sync_with_stdio(false); string s,t; cin>>s>>t; int n=s.size(); map<char,char> mp1,mp2; rep(i,n){ if(mp1.count(s[i])){ if(mp1[s[i]]!=t[i]){ cout<<"No"<<endl; return 0; } } mp1[s[i]]=t[i]; if(mp2.count(t[i])){ if(mp2[t[i]]!=s[i]){ cout<<"No"<<endl; return 0; } } mp2[t[i]]=s[i]; } cout<<"Yes"<<endl; }
#include<bits/stdc++.h> using namespace std; const bool DBG = 1; #define TRACE(x) x #define WATCH(x) TRACE(cout << #x" = " << x << endl) #define WATCHR(a,b) TRACE(for(auto it=a; it!=b;) cout<<*(it++)<<" ";cout<<endl) #define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());}) #define all(x) (x).begin(), (x).end() #define pb push_back #define eb emplace_back #define mp make_pair #define mt make_tuple #define lb lower_bound #define ub upper_bound #define f first #define s second #define resz resize #define sz(x) int((x).size()) #define all(x) (x).begin(), (x).end() #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define F0R(i, a) for (int i = 0; i < (a); i++) #define FORd(i, a, b) for (int i = (b)-1; i >= (a); i--) #define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--) #define trav(a, x) for (auto& a : x) #define sort_by(x, y) sort(all(x), [&](const auto& a, const auto& b) { return y; }) using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vll = vector<ll>; using vvll = vector<vll>; using vb = vector<bool>; using vd = vector<double>; using vs = vector<string>; using pii = pair<int, int>; using pll = pair<ll, ll>; using pdd = pair<double, double>; using vpii = vector<pii>; using vvpii = vector<vpii>; using vpll = vector<pll>; using vvpll = vector<vpll>; using vpdd = vector<pdd>; using vvpdd = vector<vpdd>; template<typename T> void ckmin(T& a, const T& b) { a = min(a, b); } template<typename T> void ckmax(T& a, const T& b) { a = max(a, b); } void solve() { } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << fixed << setprecision(15); int n,m; cin >> n >> m; if(n % 2) { F0R(i,m) { cout << i+1 << " " << 2*m-i << "\n"; } } else { int max_odd_m = m, max_even_m = m; if(m % 2 == 0) max_odd_m--; else max_even_m--; for(int i = 0; 2*i+1 <= m; i++) { cout << i+1 << " " << max_odd_m+1-i << "\n"; } for(int i = 0; 2*i+2 <= m; i++) { cout << max_odd_m+2+i << " " << max_odd_m+2+max_even_m-i << "\n"; } } return 0; }
0
92,905,244
#include <iostream> #include <cstring> #include <queue> using namespace std; int main(){ priority_queue<int> priorityqueue; char loader[8]; int loadnum; while (1){ cin >> loader; if (strcmp(loader, "insert") == 0){ cin >> loadnum; priorityqueue.push(loadnum); } if (strcmp(loader, "extract") == 0){ cout << priorityqueue.top() << endl; priorityqueue.pop(); } if (strcmp(loader, "end") == 0){ break; } } }
#include<iostream> #include<queue> #include<limits> #include<algorithm> #include<vector> #include<cmath> #include<math.h> #include<iomanip> #include<deque> #include<stack> #include<string> #include<string.h> #include<map> #include<set> #include<unordered_map> #include<utility> #define ll long long #define tc(t) while(t--) #define V vector #define Vp vector< pair<int,int> > #define pb push_back #define UM unordered_map #define IT iterator #define F first #define S second #define forn(i, n) for (int i = 0; i < int(n); i++) #define PQ priority_queue #define _FI ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); using namespace std; char ar[140000]; vector<ll> SieveOfEratosthenes(ll n) { vector<ll> result; bool prime[n+1]; memset(prime, true, sizeof(prime)); int count=1; for (ll p=2; p*p<=n; p++) { if (prime[p] == true) { for (ll i=p*p; i<=n; i += p) { prime[i] = false; } count++; } } for (ll p=2; p<=n; p++) if (prime[p]) { result.push_back(p); } return result; } vector<ll> Divisors (ll n) { vector<ll> res; for(ll i=1;i<=sqrt(n);i++) { if(n%i==0) { if(n/i==i) { res.pb(i); } else { res.pb(i); res.pb(n/i); } } } return res; } int a[4][2]={ {1,0}, {1,-1}, {1,1}, {2,0} } ; bool validPoint(int x,int y, int N) { return (x>=0 && x<N && y>=0 && y<N); } int main() { _FI int h; cin>>h; int n; cin>>n; V<ll> v(n); ll sum=0; forn(i,n) { cin>>v[i]; sum+=v[i]; } if(h<=sum) { cout<<"Yes"; } else { cout<<"No"; } return 0; }
0
57,753,764
#include<bits/stdc++.h> using namespace std; 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 (a > b) { a = b; return 1; } return 0; } #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++) #define INF 10000000000 #define MOD 1000000007 using ll = long long; using pint = pair<int,int>; using pll = pair<ll,ll>; using Graph = vector<vector<int>>; int main(){ ll x,t; cin>>x>>t; cout<<max((ll)0,x-t)<<endl; }
#include <iostream> #include <vector> #include <string> #include <cmath> #include <algorithm> #include <map> #include <iomanip> #include <stdlib.h> #include <queue> using namespace std; const int nmax = 1e9 + 7; typedef long long ll; int main(){ int N; cin >> N; vector <ll> T(N), A(N); for (int i = 0; i < N; i++) cin >> T[i]; for (int i = 0; i < N; i++) cin >> A[i]; vector <ll> H1(N), H2(N); H1[0] = T[0]; for (int i = 1; i < N; i++){ if (T[i - 1] < T[i]){ H1[i] = T[i]; } } H2[N - 1] = A[N - 1]; for (int i = N - 2; i >= 0; i--){ if (A[i] > A[i + 1]){ H2[i] = A[i]; } } ll ans = 1; for (int i = 0; i < N; i++){ if (H1[i] == 0 && H2[i] == 0){ ans *= min(T[i], A[i]); }else if(H1[i] != 0 && H2[i] != 0 && H1[i] != H2[i]){ ans = 0; }else if(H1[i] != 0 && H2[i] == 0 && H1[i] > A[i]){ ans = 0; }else if(H1[i] == 0 && H2[i] != 0 && T[i] < H2[i]){ ans = 0; } ans %= nmax; } cout << ans << endl; return 0; }
0
7,639,138
#include<iostream> #include<vector> using namespace std; int main() { int n, m = 0; cin >> n >> m; vector<int>duck; for (int i = 0; i < m; i++) { int a = 0; cin >> a; duck.push_back(a); } for (int i = 0; i < m; i++) { n -= duck[i]; } if (n < 0)n = -1; cout << n; return 0; }
#include <bits/stdc++.h> using namespace std; typedef pair<int, char> P; int n = 0; int encode(string a){ vector<int> l; for(int i = 0; i < a.size(); i++){ switch(a[i]){ case 'm': l.push_back(1000); break; case 'c': l.push_back(100); break; case 'x': l.push_back(10); break; case 'i': l.push_back(1); break; default : l.push_back(int(a[i] - '0')); break; } } int i = 0; int sum = 0; while(1){ bool flag = false; if(i == l.size()) break; if(2 <= l[i] && l[i] <= 9){ sum += l[i] * l[i + 1]; flag = true; } else{ sum += l[i]; } if(flag){ i += 2; } else i++; } return sum; } int keisu(int a){ if(2 <= a && a <= 9) return 1; else if(a == 1) return 2; return 0; } vector<char> decode(int a){ int m = a / 1000; int c = (a % 1000) / 100; int x = ((a % 1000) % 100) / 10; int i = ((a % 1000) % 100) % 10; vector<P> tmp; tmp.push_back(P(m, 'm')); tmp.push_back(P(c, 'c')); tmp.push_back(P(x, 'x')); tmp.push_back(P(i, 'i')); vector<char> res; for(int i = 0; i < 4; i++){ if(keisu(tmp[i].first) == 1){ res.push_back(char(tmp[i].first + '0')); res.push_back(tmp[i].second); } else if(keisu(tmp[i].first) == 2){ res.push_back(tmp[i].second); } } return res; } void display(vector<char> res){ for(int i = 0; i < res.size(); i++){ cout << res[i]; } cout << endl; } int main(){ cin >> n; for(int i = 0; i < n; i++){ string a, b; cin >> a >> b; int sum = encode(a) + encode(b); vector<char> res = decode(sum); display(res); } return 0; }
0
3,480,355
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { int N, M; cin >> N >> M; ll A[N], B[N]; for (int i = 0; i < N; i++) cin >> A[i] >> B[i]; vector<vector<ll>> G(M+1); for (int i = 0; i < N; i++){ if (A[i] <= M) G[A[i]].push_back(B[i]); } ll ans = 0; priority_queue<ll> pq; for (int i = M-1; i >= 0; i--) { for (ll j : G[M-i]) pq.emplace(j); if (!pq.empty()) { ans += pq.top(); pq.pop(); } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define endl "\n" #define pb push_back #define f(i,n) for(i=0;i<n;i++) #define F(i,a,b) for(i=a;a<=b;i++) #define arr(a,n) for( i=0;i<n;i++)cin>>a[i]; #define fi first #define se second #define mp make_pair #define mod 1000000007 #define YES cout<<"YES"<<endl; #define Yes cout<<"Yes"<<endl; #define NO cout<<"NO"<<endl; #define No cout<<"No"<<endl; #define yes cout<<"yes"<<endl; #define no cout<<"no"<<endl; #define vi vector<ll> #define ed end() #define bg begin() #define sz size() #define ln length() #define s() sort(a,a+n); #define sr() sort(a,a+n,greater<ll>()); #define v() sort(v.begin(),v.end()); #define vr() sort(v.begin(),v.end(),greater<ll>()); #define mod 1000000007 #define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);} ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;} int main() { fast(); { ll n,k,ans=1; cin>>n>>k; ans=(1ll*ans)*(1ll*k); k-=1; for(int i=2;i<=n;i++) { { ans=(1ll*ans)*(1ll*k); } } cout<<ans<<endl; } return 0; }
0
1,388,169