code1
stringlengths
54
12k
code2
stringlengths
65
12k
similar
int64
0
1
__index_level_0__
int64
1
101M
#include <bits/stdc++.h> using namespace std; using ll=long long; #define rep(i,n) for (ll i=0; i<n; ++i) #define all(c) begin(c),end(c) #define PI acos(-1) #define oo LLONG_MAX template<typename T1, typename T2> bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;} template<typename T1, typename T2> bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;} int main(){ cin.tie(0); ios::sync_with_stdio(0); ll o=1e18; ll N; cin>>N; ll ans = 1; vector<ll> A(N, 0); rep(i, N){ cin>>A[i]; if (A[i] == 0){ cout<<0<<endl; return 0; } } double check = 0; rep(i, N){ ans *= A[i]; check += (double)log10(A[i]); if (ans > 1000000000000000000 || ans < 0 || check > 18.00000000){ cout << -1 << endl; return 0; } } cout <<ans << endl; }
#include <stdio.h> #include <string.h> int main(){ int Tc; scanf("%d",&Tc ); long long int data[Tc]={}; long long int Tot=1; for (int i=0; i<Tc; i++){ scanf("%lld", &data[i]); } for (int j=0; j<Tc; j++){ if (data[j]==0){ printf("0"); return 0; } } for(int k=0; k<Tc; k++){ if (data[k]>1000000000000000000/Tot){ printf ("-1"); return 0; } else { Tot *= data[k]; } } printf ("%lld", Tot); return 0; }
1
3,205,600
#include <bits/stdc++.h> using namespace std; #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define sz(x) (int)(x).size() #define F first #define S second #define forn(i, n) for (int i = 0; i < (int)n; i++) #define pb push_back #define fastIO ios::sync_with_stdio(0), cin.tie(0) #define endl '\n' typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; void debug_out() {cerr << endl;} template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cerr << " " << to_string(H), debug_out(T...);} int main() { #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) freopen("in.txt", "r", stdin); #else #define debug(...) 3 fastIO; #endif int L; cin>>L; double ans=(L*L*L)/27.0; cout<<fixed<<setprecision(9)<<ans<<endl; return 0; }
#include <iostream> #include <stdio.h> int main() { int l; std::cin >> l; printf("%.10lf\n", (l*l*l)/27.0); return 0; }
1
84,097,048
#include <bits/stdc++.h> using namespace std; int main() { char s[4]; for(int i=0;i<4;++i) cin >> s[i]; sort(s,s+4); if(s[0]==s[1]&&s[2]==s[3]&&s[1]!=s[2]) cout << "Yes" << endl; else cout << "No" << endl; }
#include <bits/stdc++.h> #include<math.h> #include<algorithm> #define rep(i,n) for (int i = 0; i < (n) ; ++i) using namespace std; using ll = long long ; using P = pair<int, int> ; #define PI 3.14159265358979323846264338327950 #define INF 1e18 int main() { string s ; cin >> s ; int res = 0 ; rep(i,4){ rep(j,4){ if(i == j){ continue ; } else { if(s[i] == s[j]){ res++ ; } } } } if(res == 4){ cout << "Yes" << endl ; } else { cout << "No" << endl ; } }
1
28,683,836
#include <bits/stdc++.h> using namespace std; int main() { int N; int n; cin >> N; n = N % 1000; if (N % 1111 == 0) { cout << "Yes" << endl; } else if ( 0 <= N % 1110 && N % 1110 <= 9){ cout << "Yes" << endl; } else if ( n % 111 == 0) { cout << "Yes" << endl; } else { cout << "No" << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { int x; cin >> x; int a,b,c,d; a = x % 10; b = x / 10 % 10; c = x / 10 / 10 % 10; d = x / 10 / 10 / 10 % 10; int count = 0; if(a == b && a == c){ count = 1; } if(b == c && b == d){ count = 1; } if(count == 1){ cout << "Yes" << endl; }else{ cout << "No" << endl; } }
1
54,695,228
#include<bits/stdc++.h> using namespace std; #define ll long long signed main() { char a,b,c,d,e,f; cin >> a >> b >> c >> d >> e >> f; (a==f&&b==e&&c==d) ? cout<< "YES" : cout<< "NO"; }
#include <bits/stdc++.h> using namespace std; #define rep(i, s, n) for (int i = (s); i < (int)(n); i++) #define all(v) v.begin(), v.end() using ll = long long; const ll MOD = 1e9+7; ll LLINF = 1LL << 60; int INF = INT_MAX; int main(){ string s1,s2; cin>>s1>>s2; if(s1[0]==s2[2] && s1[2]==s2[0] && s1[1]==s2[1]) cout<<"YES"<<endl; else cout<<"NO"<<endl; }
1
88,684,061
#include <bits/stdc++.h> using namespace std; int main(void) { string s; cin >> s; sort(s.begin(), s.end()); char prev = s.at(0); for (int i = 1; i < (int)s.size(); i++) { if (s.at(i) == prev) { cout << "no" << endl; return 0; } prev=s.at(i); } cout << "yes" << endl; return 0; }
#include<iostream> #include<vector> #include<string> #include<algorithm> using namespace std; int main(){ string s; cin>>s; vector<int>a(26); bool flag=true; for(int i=0;i<s.size();i++){ a[s[i]-'a']++; if(a[s[i]-'a']>1)flag=false; } if(flag)cout<<"yes"<<endl; else cout<<"no"<<endl; return 0; }
1
34,756,948
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; using ll = long long; using P = pair<int, int>; using vi = vector<int>; using vvi = vector<vi>; int main() { int n, m; cin >> n >> m; rep(i, m) { int a; cin >> a; n -= a; } if(n >= 0) cout << n << endl; else cout << -1 << endl; }
#include<bits/stdc++.h> using namespace std; #pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") #define int long long #define dip(type,var) type var; cin>>var; #define dipi(x) int x; cin>>x; #define w(x) int x; cin>>x; while(x--) #define mka(arr,n,type) type *arr=new type[n]; #define fo(i,n) for(int i=0;i<n;i++) #define mod pow(10,9)+7 #define inf 1e18 #define pi 3.141592653589793238 #define fo(i,n) for(int i=0;i<n;i++) #define endl "\n" #define ff first #define ss second #define pb push_back #define mp make_pair #define pii pair<int,int> #define vi vector<int> #define mii map<int,int> #define pqb priority_queue<int> #define pqs priority_queue<int,vi,greater<int> > void c_p_c() { ios_base::sync_with_stdio(0); cin.tie(0); cin.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } int32_t main() { c_p_c(); dipi(n); dipi(m); mka(arr, m, int); int sum = 0; fo(i, m) { cin >> arr[i]; sum += arr[i]; } if (sum <= n) cout << n - sum << endl; else cout << "-1" << endl; }
1
12,508,662
#include <iostream> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; long long k; cin >> n >> k; long long arr[100001] = {}; for (int i = 0 ; i < n ; i++){ int num , qty; cin >> num >> qty; arr[num] += qty; } long long count = 0; for (int i = 1 ; i < 100001 ; i++ ){ count += arr[i]; if( count >= k ){ cout << i; return 0; } } }
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for(int i = a; i < (b); ++i) #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; } template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; } template<typename H> void read(H& head) { cin >> head; } template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); } template<typename H> void print(H head) { cout << head << '\n'; } template<typename H, typename ...T> void print(H head, T ...tail) { cout << head << " "; print(tail...); } int main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); map<ll, ll> freq; int n; ll k; read(n, k); rep(i, 0, n) { int a, b; read(a, b); freq[a] += b; } ll ctl = 0; for (auto p : freq) { ctl += p.second; if (ctl >= k) { print(p.first); return 0; } } }
1
99,904,067
#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(int i=0;i<(int)(n);i++) #define all(vec) vec.begin(),vec.end() typedef long long ll; const int MAX=2e5; const ll MOD=1e9+7; const int INF=1<<30; 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 issame(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() { int N, M; cin >> N >> M; UnionFind<int> uf(N); for (int i=0;i<M;++i){ int l,r,d; cin >> l >> r >> d; --l,--r; if (uf.issame(l,r)) { if (uf.diff(l,r)!=d) { cout << "No" << endl; return 0; } } else{ uf.merge(l,r,d); } } cout << "Yes" << endl; }
using namespace std; #include <iostream> #include <bits/stdc++.h> #define infile "../test/sample-1.in" #define int long long #define INF 1000000000000000000LL #define MOD 1000000007LL #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 _rrep(i,n) rrepi(i,0,n) #define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i) #define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__) #define foreach(x,a) for(auto& (x) : (a) ) #define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++) #define all(x) (x).begin(),(x).end() #define sum(v) accumulate(all(v), 0) #define sz(x) ((int)(x).size()) template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; } template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; } template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ std::fill( (T*)array, (T*)(array+N), val ); } #define fill(x,y) memset(x,y,sizeof(x)) #define pb(a) push_back(a) #define mp(a, b) make_pair(a, b) #define uni(x) sort(all(x));x.erase(unique(all(x)),x.end()) #define ten(n) ((int)1e##n) template <class T = int> T in() {T x; cin>>x; return (x);} struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast; #ifdef PCM #include "dump.hpp" #else #define dump(...) 42 #define dump_1d(...) 42 #define dump_2d(...) 42 #endif typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef long double ld; typedef pair<int,int> pii; typedef tuple<int,int,int> iii; template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>; int dx[]={1, -1, 0, 0}; int dy[]={0, 0, 1, -1}; int n,M; int x[100000]={}; int dfs(int i, int pos, const auto& G){ if (x[i]==INF){ x[i] = pos; foreach(p, G[i]){ dfs(p.first, pos + p.second, G); } } return 0; } int solve(){ cin>>n>>M; if (M==0){ cout << "Yes" << endl; return 0; } int l[M],r[M],d[M]; rep(i, n){ x[i]=INF; } vector<vector<pii>> G(n); rep(i, M){ cin>>l[i]>>r[i]>>d[i]; l[i]--;r[i]--; G[l[i]].pb(mp(r[i], d[i])); G[r[i]].pb(mp(l[i], -d[i])); } rep(i, n){ dfs(i, 0, G); } dump_1d(x, n); rep(m, M){ if (x[r[m]] - x[l[m]] != d[m]){ cout << "No" << endl; return 0; } } cout << "Yes" << endl; return 0; } int test(){ return 0; } signed main() { #ifdef INPUT_FROM_FILE std::ifstream in(infile); std::cin.rdbuf(in.rdbuf()); #endif #ifdef PCM test(); #endif solve(); return 0; }
1
63,477,147
#include <bits/stdc++.h> using namespace std; #define FOR(i,o,n) for(long long i = o;i<n;i++) #define oneforall ios::sync_with_stdio(false);cin.tie(0); #define all(v) (v).begin(),(v).end() #define ini(...) int __VA_ARGS__; in(__VA_ARGS__) #define inl(...) long long __VA_ARGS__; in(__VA_ARGS__) #define ins(...) string __VA_ARGS__; in(__VA_ARGS__) #define int long long const long long INF=1e18; void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);} void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);} typedef vector<int> vi; typedef vector<long long> vl; typedef long long ll; typedef vector<pair<long, long > > vpll; typedef vector<pair<int, int > > vpii; int rick[256]; int32_t main() { oneforall oneforall oneforall oneforall oneforall oneforall oneforall oneforall oneforall oneforall oneforall oneforall oneforall oneforall ins(morty); int l = 0; int r = morty.size()-1; int tmp = 0; while(l<r){ if(morty[l] == morty[r]){ l++; r--; } else if(morty[l] == 'x'){ tmp++; l++; } else if(morty[r] == 'x'){ tmp++; r--; } else { out(-1); tmp = -1; break; } } if(tmp>=0)out(tmp); return 0; }
#include <iostream> #include <string> #include <vector> #include <set> #include <stack> #include <queue> #include <map> #include <algorithm> #include <iomanip> #include <math.h> #include <string.h> #include <cstdio> #include <tuple> using namespace std; using ll = long long; using pll = pair<ll, ll>; using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>; #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) void debug_out() { cerr << endl; } template<typename Head, typename... Tail> void debug_out(Head h, Tail... t) { cerr << " " << h; if (sizeof...(t) > 0) cerr << " :"; debug_out(t...); } template <typename T> ostream& operator<<(ostream& os, vector<T> vec) { for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " "); return os; } ll ctoi(char c) { switch (c) { case '0': return 0; case '1': return 1; case '2': return 2; case '3': return 3; case '4': return 4; case '5': return 5; case '6': return 6; case '7': return 7; case '8': return 8; case '9': return 9; default: return 0; } } bool pairCompare(const pll firstElof, pll secondElof) { return firstElof.first > secondElof.first; } ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R; ll MOD = 1000000007; ll INF = 1LL << 62; ll ans = 0; ll z = 0, o = 1; vl flag, color, D; vll path; int main() { string S; cin >> S; N = S.length(); ll left = 0; ll right = N - 1; while (left < right) { if (S[left] == S[right]) { left++; right--; } else if (S[left] == 'x') { ans++; left++; } else if (S[right] == 'x') { ans++; right--; } else { cout << -1; exit(0); } } cout << ans; }
1
87,646,417
#include <iostream> #include <map> #include <vector> #include <cmath> #include <string> #include <cstring> #include <algorithm> #include <climits> #include <stack> #include <queue> #include <set> #include <cctype> #include <bitset> #include <type_traits> #include <list> using namespace std; #define REP(i, n) for (int i = 0; i < (n); ++i) #define rep(i, a, b) for (int i = a; i < (b); ++i) #define YES(j) cout << (j ? "YES" : "NO") << endl; #define Yes(j) std::cout << (j ? "Yes" : "No") << endl; #define yes(j) std::cout << (j ? "yes" : "no") << endl; int main(void) { const int INF = 100000000; int n, m; cin >> n >> m; int a[1000], b[1000], c[1000]; int dist[100][100]; REP(i, m) { cin >> a[i] >> b[i] >> c[i]; a[i]--; b[i]--; } REP(i, n) { REP(j, n) { if (i == j) dist[i][j] = 0; else { dist[i][j] = INF; } } } REP(i, m) { dist[a[i]][b[i]] = min(dist[a[i]][b[i]], c[i]); dist[b[i]][a[i]] = min(dist[b[i]][a[i]], c[i]); } REP(k, n) { REP(i, n) { REP(j, n) { dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]); } } } int ans = m; REP(i, m) { bool shortest = false; REP(j, n) { if (dist[j][a[i]] + c[i] == dist[j][b[i]]) shortest = true; } if (shortest) ans--; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i=0; i<n; i++) #define pb push_back #define int long long typedef pair<int, int> P; typedef tuple<int, int, int> T; int N, M; vector<T> edges; vector<P> G[110]; int dist[110][110]; vector<int> dijkstra(int s) { priority_queue<P, vector<P>, greater<P>> q; vector<int> d(N); rep(i, N) d[i] = 1000000000; d[s] = 0; q.push(P(0, s)); while (!q.empty()) { P p = q.top(); q.pop(); int v = p.second; if (d[v]<p.first) continue; rep(i, G[v].size()) { int nv = G[v][i].first, w = G[v][i].second; if (d[nv]>d[v]+w) { d[nv] = d[v]+w; q.push(P(d[nv], nv)); } } } return d; } signed main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N >> M; rep(i, M) { int a, b, c; cin >> a >> b >> c; edges.pb(make_tuple(a-1, b-1, c)); G[a-1].pb(P(b-1, c)); G[b-1].pb(P(a-1, c)); } rep(i, N) { vector<int> d = dijkstra(i); rep(j, N) dist[i][j] = d[j]; } int ans = 0; rep(i, M) { int a = get<0>(edges[i]), b = get<1>(edges[i]), c = get<2>(edges[i]); bool flag = true; rep(i, N) rep(j, N) { if (dist[i][j]==dist[i][a]+c+dist[b][j]) flag = false; if (dist[i][j]==dist[i][b]+c+dist[a][j]) flag = false; } if (flag) ans++; } cout << ans << endl; }
1
54,835,327
#include <stdio.h> int main() { int arr[3][3]={}; for(int i=0; i<3; i++){ for(int j=0; j<3; j++){ scanf("%d", &arr[i][j]); } } int n; scanf("%d", &n); int call; for(int k=0; k<n; k++){ scanf("%d", &call); for(int i=0; i<3; i++){ for(int j=0; j<3; j++){ if(arr[i][j]==call){ arr[i][j]=0; } } } } if(arr[0][0]==0&&arr[0][1]==0&&arr[0][2]==0 || arr[1][0]==0&&arr[1][1]==0&&arr[1][2]==0 || arr[2][0]==0&&arr[2][1]==0&&arr[2][2]==0 || arr[0][0]==0&&arr[1][0]==0&&arr[2][0]==0 || arr[0][1]==0&&arr[1][1]==0&&arr[2][1]==0 || arr[0][2]==0&&arr[1][2]==0&&arr[2][2]==0 || arr[0][0]==0&&arr[1][1]==0&&arr[2][2]==0 || arr[0][2]==0&&arr[1][1]==0&&arr[2][0]==0){ printf("Yes\n"); } else { printf("No\n"); } return 0; }
#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 + 2; const int mod = 1e9 + 7; int main() { ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0); int n, a[3][3]; for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) cin >> a[i][j]; cin >> n; bool mark[3][3] = {}; while(n--) { int x; cin >> x; for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) if (x == a[i][j]) mark[i][j] = 1; } bool done = ((mark[0][0] && mark[1][1] && mark[2][2]) || (mark[0][2] && mark[1][1] && mark[2][0])); for (int i = 0; i < 3; i++) { int cnt = 0; for (int j = 0; j < 3; j++) if (mark[i][j]) cnt++; if (cnt == 3) done = 1; } for (int j = 0; j < 3; j++) { int cnt = 0; for (int i = 0; i < 3; i++) if (mark[i][j]) cnt++; if (cnt == 3) done = 1; } cout << (done ? "Yes" : "No"); return 0; }
1
16,246,488
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <vector> using namespace std; typedef long long LL; const int MAXN = 1e05 + 10; int N; pair<LL, int> d[MAXN]; int subsize[MAXN]= {0}, fa[MAXN]= {0}; void solve () { for (int i = N; i > 1; i --) { subsize[d[i].second] ++; int up = N - 2 * subsize[d[i].second]; if (up < 0) { puts ("-1"); exit (0); } int p = lower_bound (d + 1, d + N + 1, make_pair (d[i].first - up, 0)) - d; if (p >= i || d[p].first != d[i].first - up) { puts ("-1"); exit (0); } fa[d[i].second] = d[p].second; subsize[d[p].second] += subsize[d[i].second]; } } vector<int> G[MAXN]; LL dist[MAXN]= {0}, total = 0; void DFS (int root) { total += dist[root]; for (int i = 0; i < (int) G[root].size(); i ++) { int v = G[root][i]; dist[v] = dist[root] + 1; DFS (v); } } inline LL getnum () { LL num = 0; char ch = getchar (); while (! isdigit (ch)) ch = getchar (); while (isdigit (ch)) num = (num << 3) + (num << 1) + ch - '0', ch = getchar (); return num; } int main () { N = getnum (); for (int i = 1; i <= N; i ++) d[i].first = getnum (), d[i].second = i; sort (d + 1, d + N + 1); solve (); for (int i = 2; i <= N; i ++) G[fa[d[i].second]].push_back(d[i].second); DFS (d[1].second); if (total != d[1].first) { puts ("-1"); return 0; } for (int i = 2; i <= N; i ++) printf ("%d %d\n", fa[d[i].second], d[i].second); return 0; }
#include <bits/stdc++.h> #define int long long #define INF 1000000000007 using namespace std; int n,d[200010],sz[200010],dp[200010],minv,pos; map<int,int> mp; vector<pair<int,int> > res; vector<int> v[200010]; inline void dfs(int u,int pr) { for(int i=0;i<v[u].size();i++) if(v[u][i]!=pr){ dfs(v[u][i],u); dp[u]+=dp[v[u][i]]+sz[v[u][i]]; } } signed main() { ios::sync_with_stdio(false); cin>>n; for(int i=1;i<=n;i++){cin>>d[i];mp[d[i]]=i;} minv=INF; for(int i=1;i<=n;i++){ if(d[i]<minv){ minv=d[i]; pos=i; } } for(int i=1;i<=n;i++){sz[i]=1;} map<int,int>::iterator it=mp.end(); it--; for(;it!=mp.begin();it--){ int num=it->first,loc=it->second; if(loc==pos) continue; if(sz[loc]*2>=n){ cout<<-1<<endl; return 0; } int cur=num-n+2*sz[loc]; if(!mp.count(cur)){ cout<<-1<<endl; return 0; } int par=mp[cur]; res.push_back(make_pair(par,loc)); sz[par]+=sz[loc]; } for(int i=0;i<res.size();i++){ v[res[i].first].push_back(res[i].second); v[res[i].second].push_back(res[i].first); } for(int i=1;i<=n;i++) dp[i]=0; dfs(pos,-1); if(dp[pos]!=minv){ cout<<-1<<endl; return 0; } for(int i=0;i<res.size();i++){ cout<<res[i].first<<" "<<res[i].second<<endl; } return 0; }
1
61,310,071
#include<bits/stdc++.h> using namespace std; int main() { int n,m; cin>>n>>m; int arra[m+5]; map<int,int>mp; for(int i=0;i<m;i++) { cin>>arra[i]; mp[arra[i]]++; } int fnd=0; int val=n; while(fnd!=1) { if(!mp[val]) { fnd=1; } else { val++; } } fnd=0; int a1=abs(n-val); int one=val; val=n; while(fnd!=1) { if(!mp[val]) { fnd=1; } else { val--; } } int a2=(n-val); int two=val; if(a1>=a2) { cout<<two<<endl; } else cout<<one<<endl; }
#include <iostream> #include <vector> #include <math.h> using namespace std; int main() { int x, n; cin >> x >> n; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } vector<int> b(102, 0); for (int i = 0; i < n; i++) { b[a[i]] = 1; } if (b[x] == 0) { cout << x << endl; return 0; } int f = x; int g = x; while (x) { f--; g++; if (b[f] == 0) { cout << f << endl; return 0; } if (b[g] == 0) { cout << g << endl; return 0; } } return 0; }
1
2,515,274
#include<iostream> #include<cstdio> using namespace std; const int maxn=1e5+5; int h,s[maxn]; int parent(int i) { return i/2; } int left(int i) { return i*2; } int right(int i) { return i*2+1; } int main() { scanf("%d",&h); for(int i=1;i<=h;i++){ scanf("%d",&s[i]); } for(int i=1;i<=h;i++){ cout<<"node "<<i<<": key = "<<s[i]<<", "; if(parent(i)>=1){ cout<<"parent key = "<<s[parent(i)]<<", "; } if(left(i)<=h){ cout<<"left key = "<<s[left(i)]<<", "; } if(right(i)<=h){ cout<<"right key = "<<s[right(i)]<<", "; } cout<<endl; } return 0; }
#include<iostream> using namespace std; int main() { int heap[600]; int h; cin >> h; for (int i = 0; i < 600; i++)heap[i] = 2000000009; for (int i = 1; i <= h; i++) { cin >> heap[i]; } for (int i = 1; i <= h; i++) { cout << "node " << i << ": key = " << heap[i] << ", "; if (i != 1) { cout << "parent key = " << heap[i / 2] << ", "; } if (heap[i * 2] != 2000000009) { cout << "left key = " << heap[i * 2] << ", "; } if (heap[i * 2 + 1] != 2000000009) { cout << "right key = " << heap[i * 2 + 1] << ", "; } cout << endl; } return 0; }
1
46,448,108
#include <iostream> #include <string> #include <stack> using namespace std; typedef stack<char> P; int main() { const char s[5] = "()[]"; string str; while (getline(cin, str), str.size() > 1) { P p; bool flag =true; for (int i = 0; i < str.size(); i++) { if (str[i] == s[0] || str[i] == s[2]) p.push(str[i]); else if (str[i] == s[1] || str[i] == s[3]) { if (p.size() < 1) { flag = false; break; } else if (str[i] == s[1] && p.top() == s[0]) p.pop(); else if (str[i] == s[3] && p.top() == s[2]) p.pop(); else { flag = false; break; } } } if (flag && p.size() == 0) cout << "yes" << endl; else cout << "no" << endl; } return 0; }
#include <iostream> #include <string> #include <stack> using namespace std; int main( void ) { string in; while(getline(cin, in), in[0] != '.') { stack<char> st; bool hit = true; int len = in.size(); for(int i=0; i < len; ++i) { if(in[i] == '(' || in[i] == '[') { st.push(in[i]); } else if(in[i] == ')') { if(st.empty()) { hit = false; } else { if(st.top() != '(') hit = false; st.pop(); } } else if(in[i] == ']') { if(st.empty()) { hit = false; } else { if(st.top() != '[') hit = false; st.pop(); } } } if(st.size() == 0 && hit) cout << "yes" << endl; else cout << "no" << endl; } }
1
38,323,904
#include<cstdio> #include<algorithm> using namespace std; int main(){ long long ans=0,sum=0,a[100000],b[100000]; int n; scanf("%d",&n); for(int i=0;i<n;i++){ scanf("%lld %lld",&a[i],&b[i]); sum+=a[i]; } for(int i=0;i<n;i++){ if(a[i]>b[i]){ ans=max(ans,sum-b[i]); } } printf("%lld\n",ans); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; typedef pair<int, P> P1; typedef pair<P, P> P2; #define pu push #define pb push_back #define mp make_pair #define eps 1e-7 #define INF 10000000000000 #define fi first #define sc second #define rep(i, x) for (long long i = 0; i < x; i++) #define repn(i, x) for (long long i = 1; i <= x; i++) #define SORT(x) sort(x.begin(), x.end()) #define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end()) #define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin()) #define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin()) vector<pair<string, P> > vec; void solve(long long N, std::vector<long long> A, std::vector<long long> B) { { bool flg = true; rep(i, N) { if (A[i] != B[i]) flg = false; } if (flg) { cout << "0" << endl; return; } } ll minb = INF; rep(i, N) { if (A[i] > B[i]) minb = min(minb, B[i]); } ll sum = 0; rep(i, N) sum += A[i]; cout << sum - minb << endl; } int main() { long long N; scanf("%lld", &N); std::vector<long long> A(N); std::vector<long long> B(N); for (int i = 0; i < N; i++) { scanf("%lld", &A[i]); scanf("%lld", &B[i]); } solve(N, std::move(A), std::move(B)); return 0; }
1
29,884,846
#include <bits/stdc++.h> using namespace std; using ll = long long; #define FOR(i, a, b) for(int i=(a);i<(b);++i) #define rep(i, n) FOR(i, 0, n) #define whole(x) (x).begin(),(x).end() #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) using P = pair<int, int>; #define debug(var) cout << "[" << #var << "] " << var << endl const ll mod = 1000000007; int main(){ int a, b; cin >> a >> b; string ans = "Yay!"; if (a>8 || b>8) { ans = ":("; } cout << ans << endl; return 0; }
#include<bits/stdc++.h> #define ll long long const int inf = 1e9+7; const ll INF = 1e18+7; using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(NULL); int a,b; cin >>a>>b; if(a<=8 && b<= 8){ cout<<"Yay!\n"; } else cout<<":(\n"; return 0; }
1
97,880,101
#include<bits/stdc++.h> using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(); int k, n; cin>>k>>n; int a[n]; for(int i = 0; i < n; i++){ cin>>a[i]; } int ans = INT_MIN; for(int i = 0; i < n ; i++){ if(i == n-1){ ans = max(ans, k - a[i] + a[0]); }else { ans = max(ans, abs(a[i] - a[i+1])); } } cout<<k-ans; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef map<int,int> mii; typedef vector<int>vi; #define pb push_back #define sc(n) scanf("%d",&n) #define lsc(n) scanf("%lld",&n) #define all(x) x.begin(),x.end() #define rep(i,n) for(i=0LL;i<n;i++) #define rep1(i,n) for(i=1;i<=n;i++) #define rev(i,n) for(i=n-1;i>=0;i--) #define rev1(i,n) for(i=n;i>0;i--) #define in insert #define IT ::iterator #define pr(n) printf("%d\n",n) #define lpr(n) printf("%lld\n",n); int main() { ll k,n,i; cin >> k >> n; ll a[n],b[n],c[n]; rep(i,n) { cin >> a[i]; } rep(i,n) { if(i==0)b[i]=k-(k-a[n-1]+a[0]); else b[i]=k-(a[i]-a[i-1]); } sort(b,b+n); cout << b[0]; }
1
90,640,470
#include <stdio.h> #include <string.h> int main () { char key[15]; scanf ("%s", key); int a = strlen(key); int p=1; for (int i = 0; i<a; i++ ) { int p=1; if (key[i] == 'B') { key[i] = 'x'; if (key[i-1] != 'x') { key[i-1] = 'x'; } else if (key[i-1] == 'x') { while (key [i-p] != '0' && key [i-p] != '1' ) { p++; } key[i-p]= 'x'; } } } for (int j=0; j<a; j++) { if (key[j] == 'x') { continue; } else { printf("%c", key[j]); } } return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for(int i = 0; i < n; i++) #define REPR(i, n) for(int i = n; i >= 0; i--) #define FOR(i, m, n) for(int i = m; i < n; i++) #define ALL(obj) (obj).begin(), (obj).end() #define INF 1e9 #define LINF 1e18 typedef long long ll; int main() { string s; cin >> s; string ans; int itr = 0; REP(i,s.size()){ if(s[i] == 'B'){ itr = max(0,itr-1); }else{ ans[itr] = s[i]; itr++; } } REP(i,itr){ cout << ans[i]; } cout << endl; return 0; }
1
6,746,190
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; using P = pair<int, int>; int main() { int a, b, c, k, ans = 0; cin >> a >> b >> c >> k; if (k > a) { k -= a; ans += a; } else { cout << k << endl; return 0; } if (k <= b) { cout << ans << endl; } else { k -= b; cout << ans - k << endl; } return 0; }
#include<iostream> using namespace std; int main(){ int a,b,c,k; cin>>a>>b>>c>>k; if(a>=k) cout<<k; else if(k>a){ if(k-a<=b) cout<<a; else if(k-a>b) cout<<2*a+b-k; } }
1
36,767,717
#include<bits/stdc++.h> using namespace std; #define MOD 1000000007 #define ll long long #define pb push_back bool isPrime(ll n) { if (n <= 1) return false; if (n <= 3) return true; if (n%2 == 0 || n%3 == 0) return false; for (ll i=5; i*i<=n; i=i+6) if (n%i == 0 || n%(i+2) == 0) return false; return true; } ll minthis(ll a, ll b){ if(a < b){ return a; } return b; } ll maxthis(ll a, ll b){ if(a > b){ return a; } return b; } int gcd(int a, int b){ if( a<0 ) a = -a; if( b<0 ) b = -b; while( b!=0 ){ a %= b; if( a==0 ) return b; b %= a; } return a; } int findLargestDivisor(int n) { int max = 1; for (int i = 2; i < n; i++) { if(n %(i) == 0) { max = i; } } return max; } ll power(ll x, ll y) { ll temp; if(y == 0) return 1; temp = power(x, y / 2); if (y % 2 == 0) return (temp * temp)%1000000007; else { if(y > 0) return (x * temp * temp)%1000000007; else return (temp * temp)%1000000007 / x; } } bool sortbysec(const pair<int, int>& a, const pair<int, int>& b) { return (a.second < b.second); } void solve(){ int n; cin >> n; int arr[n]; for(int i = 0 ; i < n ; i++){ cin >> arr[i]; } int ans = 0; for(int i = 0 ; i < n ; i++){ for(int j = i+1 ; j < n ; j++){ ans += arr[i]*arr[j]; } } cout << ans << "\n"; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t = 1; while(t--){ solve(); } return 0; }
#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; cin >> n; int a[n]; for(int i = 0;i<n;i++){ cin >> a[i]; } int sum = 0; for(int i = 0;i<n;i++){ for(int k = 0;k<n;k++){ if(i!=k){ sum = sum + a[i]*a[k]; } } } cout << sum/2 << endl; return 0; }
1
7,577,402
#include <bits/stdc++.h> using namespace std; #define modulo 1000000007 #define mod(mod_x) ((((long long)mod_x+modulo))%modulo) #define Inf 10000000000000000 int dfs(auto &E,int now,int p){ int ret = 0; for(int i=0;i<E[now].size();i++){ if(E[now][i]==p)continue; ret ^= dfs(E,E[now][i],now); } return ret+1; } int main(){ int N; cin>>N; vector<vector<int>> E(N,vector<int>()); for(int i=0;i<N-1;i++){ int a,b; cin>>a>>b; a--;b--; E[a].push_back(b); E[b].push_back(a); } if(dfs(E,0,-1)==1)cout<<"Bob"<<endl; else cout<<"Alice"<<endl; return 0; }
#include "bits/stdc++.h" using namespace std; template <typename T> void printv(const vector<T> &v) { int sz = v.size(); for (int i = 0; i < sz; i++) { cout << v[i] << " \n"[i == sz - 1]; } } using Graph = vector<vector<int>>; const int MAX_N = 100010; Graph g(MAX_N); int dfs(int cur, int pre) { if ((int)g[cur].size() == 1) { if (cur == 0) return 1; return 0; } int ch = g[cur].size(); if (cur != 0) ch--; int ok = 0; for (auto nxt : g[cur]) { if (nxt == pre) continue; ok ^= (1+dfs(nxt, cur)); } return ok; } int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; for (int i = 0; i < n - 1; i++) { int a, b; cin >> a >> b; a--; b--; g[a].push_back(b); g[b].push_back(a); } cout << (dfs(0, -1) ? "Alice" : "Bob") << endl; }
1
90,029,280
#include<iostream> using namespace std; int main(){ int n,val; while(cin >> n){ val = 0; for(int i=0;i<=9;i++){ for(int j=0;j<=9;j++){ for(int k=0;k<=9;k++){ for(int l=0;l<=9;l++){ if(i+j+k+l == n){ val += 1; } } } } } cout << val << endl; } return 0; }
#include <algorithm> #include <iostream> #include <vector> namespace { int combination(int a, int b, int c, int d) { if (a == d) { return 1; } else if (a == c || b == d) { return 4; } else if (a == b && c == d) { return 6; } else if (a == b || b == c || c == d) { return 12; } else { return 24; } } int calc(int n) { int com = 0; int a, b, c, d; for (a = 0; a <= 9; ++a) { if (a > n) break; for (b = a; b <= 9; ++b) { if (a + b > n) break; for (c = b; c <= 9; ++c) { if (a + b + c > n) break; for (d = c; d <= 9; ++d) { const int sum = a + b + c + d; if (sum == n) { com += combination(a, b, c, d); } else if (sum > n) { break; } } } } } return com; } } int main() { int n; while (std::cin >> n) { std::cout << calc(n) << std::endl; } return 0; }
1
18,867,155
#include <stdio.h> int main (){ int apple; scanf ("%d",&apple); int potongan; potongan = apple*3; int pieces; scanf ("%d", &pieces); int pie; pie = (pieces+potongan) / 2; printf("%d ", pie); return 0; }
#include<bits/stdc++.h> #include<vector> #include<string> #include<algorithm> #include<cmath> #define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define int long long int #define mod 1000000007 #define inf 1e18+42 #define endl "\n" #define pi 3.1415926535897932384626433832795028841971693993751058 #define maxn 100005 #define out1(a) cout<<#a<<" "<<a<<endl #define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl #define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl #define rep(i,a,b) for(int i=a;i<b;i++) #define repr(i,a,b) for(int i=a;i>=b;i--) #define fori(it,A) for(auto it=A.begin();it!=A.end();it++) #define ft first #define sd second #define pb push_back #define mp make_pair #define pq priority_queue #define all(x) (x).begin(),(x).end() #define zero(x) memset(x,0,sizeof(x)); #define ceil(a,b) (a+b-1)/b using namespace std; int binpow(int a, int b) { int res = 1; while (b > 0) { if (b & 1) res = res * a; a = a * a; b >>= 1; } return res; } void solve() { int a,b; cin>>a>>b; cout<<(3*a + b)/2<<endl; } signed main() { fast; int t = 1; while(t--) { solve(); } return 0; }
1
52,963,263
#include<bits/stdc++.h> using namespace std ; #define async ios_base::sync_with_stdio(false); cin.tie(NULL); #define int long long int #define let auto #define of : #define all(y) y.begin(), y.end() #define present( x, y ) x.find( y ) != x.end() #define _matrix(T) vector<vector<T>> template<class T> auto matrix( int r, int c, T v ){ return vector<vector<T>>( r, vector<T>( c, v ) ) ; } int mod = (int)1e9 + 7 ; #define inf (int)1e18 signed main(){ string s ; cin >> s ; int len = s.size() ; int sum = 0 ; for( int i = 0 ; i < len ; i++ ){ sum += ( s[i] - '0' ) ; } cout << ( sum % 9 == 0 ? "Yes" : "No" ) ; return 0 ; }
#include <iostream> using namespace std; int main(){ string n; cin >> n; long long x=0; int i; for(i=0;i<n.size();i++){ int a = n[i] - '0'; x += a; } if(x%9==0) cout << "Yes" << "\n"; else cout << "No" << "\n"; return 0; }
1
56,394,589
#include <bits/stdc++.h> #define all(a) a.begin(), a.end() #define allr(a) a.rbegin(), a.rend() #define rev(v) reverse(v.begin(), v.end()); #define io() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); srand(time(NULL)); using namespace std; using ll = long long; using ld = long double; using ull = unsigned long long; signed main(){ io(); int n; cin >> n; string s; cin >> s; int k = n/2; cout << (s.substr(0,k) == s.substr(k,n) ? "Yes" : "No") << '\n'; return 0; }
#include<stdio.h> int main(){ int n; scanf("%d", &n); char str[n+1]; scanf("%s", str); int sum1=0, sum2=0; for(int i=0; i<n/2; i++){ sum1+=str[i]; } for(int i=n/2; i<n; i++){ sum2+=str[i]; } if(sum1==sum2){ printf("Yes\n"); } else{ printf("No\n"); } return 0; }
1
69,213,004
#include <bits/stdc++.h> using namespace std; using ll = long long; #define pp pair<int,int> #define rep(i,n) for(int (i)=0;(i)<(n);(i)++) #define ld long double #define al(a) (a).begin(),(a).end() #define mk make_pair #define check cout<<"?"<<endl; ll MOD=1000000007; ll mod=998244353; int inf=1000001000; ll INF=1e18+5; int main(){ int a,p; cin>>a>>p; cout<<(a*3+p)/2<<endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i,x) for(int i=0;i<x;i++) #define put(ans) cout << ans << endl; #define sort(s) sort(s.begin(),s.end()) #define reverse(s) reverse(s.begin(),s.end()) 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; } bool isPrime(int x){ ll i; if(x < 2)return 0; else if(x == 2) return 1; if(x%2 == 0) return 0; for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0; return 1; } int main(){ int a,p,ans(0); cin >> a >> p; p += a*3; ans = p/2; put(ans); return 0; }
1
38,330,160
#include<bits/stdc++.h> using namespace std; #define ll long long vector<int> getDivisors(int n) { vector<int> res; for (int i = 1; i <= sqrt(n); i++) { if (n % i == 0) { if (n / i == i) { res.push_back(i); } else { res.push_back(i); res.push_back(n/i); } } } return res; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, ans = 0; cin >> n; for (int i = 1 ; i <= n; i++) { for (int j = 1 ; i * j <= n; j++) { if (n - i * j > 0) ans++; } } cout << ans << "\n"; }
#include <bits/stdc++.h> #pragma GCC target ("avx2") #pragma GCC optimization ("Ofast") #pragma GCC optimization ("unroll-loops") #define X first #define Y second #define debug(x) cerr << #x << ": " << x << endl; #define ll long long int #define endl '\n' #define mp make_pair #define pb push_back #define rep(i,l,r) for (ll i=l; i<r; i++) #define repr(i,r,l) for (ll i=r; i>=l; i--) using namespace std; const long long int N=2e3+30; pair <ll,ll> d[N]; int main(){ ll n,sq,ans=0; cin >> n; sq = sqrt(n); if (sq*sq == n) sq--; rep (i,1,sq+1){ rep (j,i,n){ if (i*j < n){ if (i!=j) ans+=2; else{ ans+=1; } } } } cout << ans << endl; }
1
81,653,831
#include <bits/stdc++.h> #define ll long long #include<vector> #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); using namespace std; const int mod=1e9+7; int main(){ IOS; set<char> s; string v; cin>>v; for(int i=0;i<3;i++) s.insert(v[i]); if(s.size()==2) cout<<"Yes"; else cout<<"No"; }
#include<bits/stdc++.h> using namespace std; int main(){ char a,b,c; cin >> a>>b>>c; if(a!=b||a!=c) cout << "Yes" << endl; else cout << "No" << endl; }
1
17,826,726
#include <algorithm> #include <cmath> #include <cstdio> #include <deque> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; #define MOD 1000000007 int main() { int r, d, x; cin >> r >> d >> x; int ans = x; for (int i = 0; i < 10; ++i) { x = r * x - d; cout << x << endl; } return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep1(i, n) for (int i = 1; i <= (int)(n); i++) using namespace std; using P = pair<int,int>; typedef long long ll; int main() { int r,D;cin >> r >> D; int x0 ; cin >> x0; rep1(i, 10) { x0 = r*(x0) - D; cout << x0 << endl; } return (0); }
1
14,396,682
#include <bits/stdc++.h> #define arep(a,i,n) for(ll i=(a);i<(n);i++) #define rep(i,n) for(ll i=0;i<(n);i++) #define cinf(x,n) for(ll i=0;i<(n);i++)cin>>x[i]; #define coutf(x,n) for(ll i=0;i<(n);i++)cout<<x[i]<<endl; typedef long long ll; typedef unsigned long long ull; typedef long double ld; using namespace std; int main(){ int a,b; char op; cin >> a >> op >> b; switch(op){ case '+':cout << a+b << endl;break; case '-':cout << a-b << endl;break; } }
#include"bits/stdc++.h" using namespace std; #define ll long long #define pb push_back #define empb emplace_back #define mp make_pair #define F first #define S second #define endl "\n" #define vii vector<int> #define vll vector<ll> #define pii pair<int,int> #define pll pair<ll,ll> #define vpll vector<pll> #define vpii vector<pii> #define mapii map<int,int> #define mapll map<ll,ll> #define all(a) a.begin(),a.end() #define test ll t; cin>>t; while(t--) #define prec(n) fixed<<setprecision(n) #define jaldibazi ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define mod 1000000007 int main(){ jaldibazi; int a, b; cin >> a; char c; cin >> c; cin >> b; cout << (c == '+' ? (a+b) : (a-b) ) << "\n"; return 0; }
1
16,047,019
#include <bits/stdc++.h> #include <math.h> using namespace std; long long inf=1000000000; int main(){ long long s; cin>>s; cout<<0<<" "<<0<<" "<<inf<<" "<<1<<" "<<(inf-s%inf)%inf<<" "<<(s+(inf-s%inf)%inf)/inf<<endl; return 0; }
#include <bits/stdc++.h> #define ll long long #define li long int #define ld long double #define pl pair<long long, long long> #define pi pair<int, int> #define ppl pair<pl, ll> #define ppi pair<int, pi> #define FOR(i,a,b) for(int i=a;i<b;i++) #define LLFOR(i,a,b) for(ll i=a;i<b;i++) #define fi first #define se second #define MOD 1000000007 #define M2 998244353 using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll s; cin >> s; ll y3, x3; ll k = 1e9; if(s%k==0){ x3=0; y3=s/k; }else{ x3 = k-(s+k)%k; y3 = (s+k)/k; } cout << "0 0 " << k << " " << 1 << " " << x3 << " " << y3 << endl; }
1
2,398,778
#include<iostream> using namespace std; int dfs(int x,int y); int h,w; char ta[22][22]; int cheak[22][22]={0}; int dx[4]={-1,0,1,0}; int dy[4]={0,-1,0,1}; int cou=0; int main(){ int a,b; while(1){ cin >> w >> h; if(w==0 && h==0) break; cou=0; for(int i=0;i<h;i++){ for(int j=0;j<w;j++){ cin >> ta[i][j]; cheak[i][j]=0; if(ta[i][j] == '@'){ a=i,b=j; } } } cout << dfs(a,b) << endl; } } int dfs(int x,int y){ cheak[x][y]=1; cou++; for(int i=0;i<4;i++){ int nx=x+dx[i]; int ny=y+dy[i]; if(nx>=0 && nx<h && ny>=0 && ny<w && ta[nx][ny]=='.' && cheak[nx][ny]==0){ dfs(nx,ny); } } return cou; }
#include<iostream> #include <cstdio> #include<algorithm> #include<vector> #include<set> #include<utility> #include<queue> #define REP(i,n) for(int i = 0;i < n ;i++) #define pa pair<int,int> #define pq queue< pair<int,int> > using namespace std; int w,h; char mp[22][22]; bool dp[22][22]; int dx[]={1,0,-1,0},dy[] = {0,1,0,-1}; int sx,sy; int cou; int main() { for(;;) { cin >> w >>h; if(w == 0 && h == 0) break; cou = 1;sx = 0;sy = 0; REP(i,22)REP(j,22)dp[i][j] = 0; REP(i,h)REP(j,w) { cin >> mp[i][j]; if(mp[i][j] == '@'){sx = i;sy = j;} } pq p; p.push(make_pair(sx,sy)); dp[sx][sy] = 1; while(!p.empty()) { pa t = p.front();p.pop(); REP(i,4) { int cx = t.first+dx[i],cy = t.second+dy[i]; if(cx >= 0 && cx < h && cy >= 0 && cy < w) if( dp[cx][cy] == 0&& mp[cx][cy] != '#') { p.push(make_pair(cx,cy)); dp[cx][cy] = 1; cou++; } } } cout << cou << endl; } return 0; }
1
31,622,459
#include <iostream> #include <algorithm> #include <cstdio> #include <cstdlib> #include <cstring> #include <queue> using namespace std; const int INF = 0x3f3f3f3f; struct Node{ int key; Node *prev, *next; }; Node *nil; void init() { nil = (Node *)malloc(sizeof(Node)); nil->next = nil; nil->prev = nil; } void insert(int key) { Node *x = (Node *)malloc(sizeof(Node)); x->key = key; x->next = nil->next; nil->next->prev = x; nil->next = x; x->prev = nil; } Node* listSearch(int key) { Node *cur = nil->next; while( cur != nil && cur->key != key) { cur = cur->next; } return cur; } void deleteNode(Node *t) { if ( t == nil) return; t->prev->next = t->next; t->next->prev = t->prev; free(t); } void deleteFirst() { deleteNode(nil->next); } void deleteLast() { deleteNode(nil->prev); } void deleteKey(int Key) { deleteNode(listSearch(Key)); } int main(){ int n, temp; char s[15]; scanf("%d", &n); init(); for(int i = 0; i < n; i ++) { scanf("%s", s); if(!strcmp(s, "insert")) { cin >> temp; insert(temp); } else if(!strcmp(s, "delete")) { cin >> temp; deleteKey(temp); } else if(!strcmp(s, "deleteFirst")) deleteFirst(); else deleteLast(); } Node *node = nil->next; while(node != nil) { printf("%d", node->key); if(node->next != nil) printf(" "); node = node->next; } printf("\n"); return 0; }
#define _CRT_SECURE_NO_WARNINGS #include <cstdio> #include <cstdlib> #include <cstring> using namespace std; struct node { int key; node *pre, *nex; }; node *nil; void init() { nil = (node *)malloc(sizeof(node)); nil->nex = nil; nil->pre = nil; } void insert(int key) { node *a = (node*)malloc(sizeof(node)); a ->key = key; a->nex = nil->nex; nil->nex->pre = a; nil->nex = a; a->pre = nil; } node* search(int key) { node *cur; cur = nil->nex; while (cur != nil && cur->key != key) { cur = cur->nex; } return cur; } void deletenode(node *pt) { if (pt == nil) return; pt->nex->pre = pt->pre; pt->pre->nex = pt->nex; free(pt); } void deleteFirst() { deletenode(nil->nex); } void deleteLast() { deletenode(nil->pre); } void deletekey(int key) { deletenode(search(key)); } void printNode() { node *cur = nil->nex; int i = 0; while (1) { if(cur == nil)break; if (i++ > 0) printf(" "); printf("%d", cur->key); cur = cur->nex; } printf("\n"); } int main() { int size = 0, np = 0, nd = 0; int n, key; char com[20]; scanf("%d", &n); init(); for (int i = 0; i < n; i++) { scanf("%s%d", com, &key); if (com[0] == 'i') { insert(key); np++; size++; } else if (com[0] == 'd') { if (strlen(com) > 6) { if (com[6] == 'F') { deleteFirst(); } else if (com[6] == 'L') { deleteLast(); } } else { deletekey(key); nd++; } size--; } } printNode(); return 0; }
1
32,826,953
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--) #define rrep(i,n) RREP(i,n-1,0) #define all(v) v.begin(), v.end() const int inf = 1e9+7; const ll longinf = 1LL<<60; const ll mod = 1e9+7; const ld eps = 1e-10; int main() { cin.tie(0); ios::sync_with_stdio(false); string s; cin >> s; s = s.substr(0, s.size()-2); while(1) { string s1 = s.substr(0, s.size()/2); string s2 = s.substr(s.size()/2); if(s1 == s2) { cout << s.size() << "\n"; break; } s = s.substr(0, s.size()-2); } return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long const int MAX =2000007; const int MOD = 998244353; int modpow(int a, int n, int mod) { int res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } signed main(){ string s; cin>>s; for(int i=s.size()/2-1;i>=0;i--){ bool t=true; for(int j=0;j<i;j++){ if(s[j]!=s[i+j])t=false; } if(t){ cout<<i*2<<endl; return 0; } } }
1
96,251,599
#include <bits/stdc++.h> using namespace std; using ll =long long; typedef pair<int,int> P; #define SORT(a) sort((a).begin(),(a).end()) #define rSORT(a) reverse((a).begin(),(a).end()) #define For(i, a, b) for(int i = (a) ; i < (b) ; ++i) #define rep(i, n) For(i, 0, n) #define debug(x) cerr << #x << " = " << (x) << endl; 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; } int main() { string s; cin >> s; int n = 3; bool A = false; rep(i,n){ if(s[i] == 'A'){ A = true; } } rep(i,n){ if(A){ if(s[i] == 'B'){ cout << "Yes" << endl; return 0; } } } cout << "No" << endl; }
#include "bits/stdc++.h" using namespace std; int main(void){ string str; cin >> str; if(str[0] == str[1] && str[1] == str[2]){ cout << "No" << endl; } else cout << "Yes" << endl; return 0; }
1
47,085,225
#include <bits/stdc++.h> using namespace std; #define lli long long int #define N 44 lli F[N]={0}; lli fibonacci(int n){ if(n==0 || n==1)return F[n] = 1; if(F[n]!=0)return F[n]; return F[n] = fibonacci(n-2) + fibonacci(n-1); } int main(){ int n; cin >> n; cout << fibonacci(n) << endl; return 0; }
#include <bits/stdc++.h> #define REP(i ,n) for(int i=0 ;i < n; i++) #define REPB(i ,n) for(int i=n; i >= 0; i--) #define FOR(i ,m ,n) for(int i=m; i < n; i++) #define FORB(i, m, n) for(int i=m; i>= m; i--) #define ll long long #define pb push_back #define popb pop_back using namespace std; vector<int> f; int makeFib(int k){ f.pb(1); f.pb(1); if(k >= 2){ FOR(i,2,(k + 1)){ f.pb(f[i - 2] + f[i - 1]); } } return f[k]; } int main(){ int n; cin >> n; cout << makeFib(n) << endl; }
1
11,992,219
#include <bits/stdc++.h> using namespace std; #define endl "\n" #define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); typedef long long ll; typedef vector<int> vi;; typedef vector<ll> vll; #define l() length() #define sz() size() #define b() begin() #define e() end() #define all(x) x.begin(), x.end() #define pb(i) push_back(i) #define PB() pop_back() typedef pair<int, int> pii; typedef pair<ll,ll> pll; #define mp make_pair #define Fi first #define Se second const int maxx=1e6+9; bool _find(string &str,int a,int b){ int l=str.l(); if(l!=a+b+1){return false;} if(l<a+1){return false;} if(str[a]!='-'){return false;} for(int i=0;i<str.l();i++){ if(i==a){continue;} if(!isdigit(str[i])){ return false; } } return 1; } void solve(){ int a,b; cin>>a>>b; string str; cin>>str; cout<<(_find(str,a,b)?"Yes":"No")<<endl; } int main() { faster; int t=1; while(t-->0){ solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll LINF = 1e18; const int INF = 1e9; const ll MOD = 1000000007; int main(){ int a, b; cin >> a >> b; string s; cin >> s; bool ok = true; if(a+b+1 != (int)s.size()) ok = false; else{ if(s[a] != '-') ok = false; else{ for(int i = 0; i < a; i++){ if((s[i] < '0') || ('9' < s[i])) ok = false; } for(int i = a+1; i < (int)s.size()-1; i++){ if((s[i] < '0') || ('9' < s[i])) ok = false; } } } if(ok) cout << "Yes" << endl; else cout << "No" << endl; return 0; }
1
83,035,248
#include <iostream> #include <string> #include <vector> #include <cmath> using namespace std; long long mod = 1000000007; int main() { string s; cin >> s; long long n = s.length(); long long rez = (n*(n-1))/2 + 1; vector <long long> bs(26, 0); for (int i = 0; i < n; i++) bs[s[i] - 'a']++; for (int i = 0; i < 26; i++) if (bs[i] > 1) rez -= (bs[i]*(bs[i]-1))/2; cout << rez; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++) #define all(v) v.begin(), v.end() #define sz(v) v.size() #define INF 100000000000000 template <typename T> bool chmax(T &a, const T& b) { if (a < b) { a = b; return true; } return false; } template <typename T> bool chmin(T &a, const T& b) { if (a > b) { a = b; return true; } return false; } int main() { string A; cin >> A; ll N = sz(A); vector<vector<ll>> s(26, vector<ll>(N+1, 0)); rep(i, N){ rep(j, 26){ if(j == A.at(i)-'a'){ s.at(j).at(i+1) = s.at(j).at(i)+1; } else{ s.at(j).at(i+1) = s.at(j).at(i); } } } ll ans = 0; rep(i, N){ rep(j, 26){ if(j == A.at(i) - 'a'){ continue; } ans += s.at(j).at(N) - s.at(j).at(i+1); } } cout << ans+1 << endl; }
1
40,319,630
#include<bits/stdc++.h> using namespace std; #define ll long long #define DEBUG(x) cout << '>' << #x << ':' << x << endl; #define REP(i,n) for(ll i=0;i<(n);i++) #define FOR(i,a,b) for(ll i=(a);i<(b);i++) #define FORC(i,a,b,c) for(ll i=(a);i<(b);i+=(c)) #define pb(x) push_back(x) #define mp(x,y) make_pair(x,y) #define ff first #define ss second #define dd long double #define mod 1000000007 const ll N=2e3+10; ll dp[N]; ll ans(ll n){ if(dp[n]!=-1){ return dp[n]; } if(n==0){ return 1; } ll sum=0; for(ll i=3;i<=n;i++){ if(n-i==0 || n-i>=3){ sum=(sum+ans(n-i))%mod; } } return dp[n]=sum; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); REP(i,N){ dp[i]=-1; } ll n; cin>>n; cout<<ans(n)<<endl; }
#include <bits/stdc++.h> using namespace std; int main(){ int s; cin >> s; vector<int> dp(2005); for (int i = 3; i <= 2000; i++) { int cnt = 0; for (int j = 3; j <= i; j++) { cnt+=dp[i-j]; cnt%=1000000007; } dp[i] = cnt+1; } cout << dp[s] << endl; }
1
30,432,110
#include <iostream> #include <algorithm> using namespace std; int main() { int n, h, maxA = 1; cin >> n >> h; int b[n]; for (int a, i = 0; cin >> a >> b[i]; ++i) { maxA = max(maxA, a); } sort(b, b + n); for (int i = 0; i < n; ++i) { if (b[i] >= maxA) { int result = 0; for (int j = n - 1; j >= i && h > 0; --j) { h -= b[j]; ++result; } if (h > 0) { result += (h - 1) / maxA + 1; } cout << result; break; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, h, ans=0, am=0; cin >> n >> h; vector<int> a(n), b(n); for(int i=0; i<n; i++) { int x, y; cin >> x >> y; a[i]=x; am=max(a[i], am); b[i]=y; } sort(b.begin(), b.end()); reverse(b.begin(), b.end()); for(int i=0; i<n; i++) { if(b[i]>am) { ans++; h-=b[i]; if(h<=0) break; } } if(h>0){ ans+=(h+am-1)/am; } cout << ans; }
1
10,451,886
#include <bits/stdc++.h> using namespace std; using ll = long long; #define SORT(c) sort((c).begin(),(c).end()) #define all(a) (a).begin(), (a).end() #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define pv(val) cerr << #val << '=' << (val) << endl const int INF = 1e9; int main(void){ string S; cin >> S; int ans = 0; REP(i,S.length()){ if(S[i] == 'o') ans++; } ans += 15 - S.length(); if(ans > 7) cout << "YES" << endl; else cout << "NO" << endl; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; typedef vector<ll> vi; typedef vector<string> vs; typedef pair<ll,ll> P; typedef vector<P> vp; #define REP(i,n) for(int i=0;i<n;i++) #define FOR(i,m,n) for(int i=m;i<n;i++) #define REPR(i,n) for(int i=n-1;i>=0;i--) #define FORR(i,n,m) for(int i=n-1;i>=m;i--) #define ARR(array) for(int i=0;i<array.size();i++) #define all(in) (in).begin(),(in).end() #define ALL(in,K) (in),(in)+(K) #define INF 1e18 #define MOD 1000000007 #define SIZE 10005 #define PI 3.14159265358979323846 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; } ll input(){ ll a; cin >> a; return a; } int main(){ string s; cin >> s; int ans = 0; for(char c: s)if(c=='x')ans++; cout << ((ans<8)?"YES":"NO") << endl; }
1
42,634,081
#include <algorithm> #include <cmath> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <set> #include <stack> #include <string> #include <vector> #define REP(i, n) for(int i = 0; i < n; ++i) using namespace std; using LLONG = long long; const LLONG MOD = 1000000007; void Solve(string s, vector<int> &xNums, string &seps) { int xNum = 0; for (const char ch : s) { if (ch == 'x') { ++xNum; } else { xNums.push_back(xNum); seps.push_back(ch); xNum = 0; } } xNums.push_back(xNum); } int main() { string s; cin >> s; int l = 0, r = s.length() - 1; int ans = 0; while (l < r) { if (s[l] == s[r]) { ++l; --r; } else if (s[l] == 'x') { ++l; ++ans; } else if (s[r] == 'x') { --r; ++ans; } else { ans = -1; break; } } cout << ans << endl; }
#include <iostream> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; int main(void) { ios::sync_with_stdio(false); string S; cin >> S; int left = 0; int right = S.size() - 1; int answer = 0; while (left <= right) { if (S[left] == S[right]) { left++; right--; } else { if (S[left] == 'x') { answer++; left++; } else if (S[right] == 'x') { answer++; right--; } else { cout << -1 << endl; return 0; } } } cout << answer << endl; return 0; }
1
34,262,931
#include <iostream> #include <math.h> #include <algorithm> #include <string> #include <queue> using namespace std; int main(){ int H,W; cin>>H>>W; string A[1000]; queue<pair<int,pair<int,int>>> que; for(int i=0;i<H;i++){ cin>>A[i]; for(int j=0;j<W;j++){ if(A[i][j]=='#'){ que.push(make_pair(i,make_pair(j,0))); } } } int count=0; int dy[4]={-1,1,0,0}; int dx[4]={0,0,-1,1}; while(!que.empty()){ int y=que.front().first; int x=que.front().second.first; int z=que.front().second.second; que.pop(); for(int i=0;i<4;i++){ if(y+dy[i]>=0&&x+dx[i]>=0&&y+dy[i]<H&&x+dx[i]<W){ if(A[y+dy[i]][x+dx[i]]=='.'){ count++; A[y+dy[i]][x+dx[i]]='#'; que.push(make_pair(y+dy[i],make_pair(x+dx[i],z+1))); count=z+1; } } } } cout<<count<<endl; return 0; }
#include <bits/stdc++.h> #include <string> #include <vector> #include <algorithm> #define rep(i,n) for (int i = 0;i < (n); ++i) using namespace std; using ll = long long; using P = pair<int,int>; int INF = 1e9; int dist[1005][1005]; int dx[4] = {-1,1,0,0}; int dy[4] = {0,0,-1,1}; int main(){ int h,w;cin >> h >> w; queue<int> q; rep(i,h)rep(j,w){ char ch;cin >> ch; if(ch == '#'){ dist[i][j]=0; q.push(w*i+j); }else dist[i][j] = -1; } while(q.size()){ int ind = q.front(); q.pop(); int y = ind/w; int x = ind%w; for(int i = 0;i < 4;i++){ int ny = y + dy[i]; int nx = x + dx[i]; if(ny < 0 || nx < 0 || h <= ny || w <= nx) continue; if(dist[ny][nx]!=-1) continue; dist[ny][nx] = dist[y][x] + 1; q.push(w*ny+nx); } } int ans = 0; rep(i,h){ rep(j,w){ ans = max(ans,dist[i][j]); } } cout << ans << endl; }
1
60,477,021
#include<bits/stdc++.h> using namespace std; using ull=unsigned long long; #define mod 1000000007 #define mod2 998244353 #define PI 3.14159265 #define ll long long #define ld long double #define pi pair<ll,ll> #define pb push_back #define vi vector<ll> #define sz size() #define setbits(x) __builtin_popcount(x) #define fi first #define se second #define lz length() #define all(x) (x).begin(),(x).end() #define scf(x) scanf("%lld",&x) #define rep(i,n) for(ll i=0;i<n;i++) const int INF = (int)1e9; const ll IINF=1LL<<62; const int maxn=10000005; int s[200005],t[200005],c[100005]; int res[200005],tmp[200005]; int main(){ int n; cin>>n; int a[n+1]; int b[n+1]={0}; for(int i=1;i<=n;i++){cin>>a[i]; b[i]=a[i];} sort(b+1,b+n+1); int res=0; for(int i=1;i<=n;i++){ int t=a[i]; int idx=lower_bound(b+1,b+n+1,t)-b; res+=(i%2==idx%2)?0:1; } cout<<res/2; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define INF 1LL<<62 #define inf 1000000007 int main() { ll n; cin>>n; vector<ll>a,b; for(ll i=0;i<n;i++){ ll x; cin>>x; a.push_back(x); b.push_back(x); } sort(b.begin(),b.end()); ll ans=0; for(ll i=0;i<n;i++){ ll now=a[i]; auto itr=lower_bound(b.begin(),b.end(),now); ll iti=itr-b.begin(); if(abs(iti-(i))%2!=0){ ans++; } } cout <<ans/2; return 0; }
1
50,814,033
#include <stdio.h> #include <iostream> #include <math.h> #include <string> #include <vector> #include <algorithm> #include <iomanip> #include <queue> using namespace std; #define rep(i, n) for(int i = 0; i < (int)n; i++) #define ll long long int #define pb push_back int main() { ll N, t; cin >> N; vector<ll> a(N); rep(i, N){ cin >> t; a[i] = t - i - 1; } sort(a.begin(), a.end()); ll mid; if (N % 2 == 0) mid = (a[N/2]+a[N/2-1])/2; else mid = a[N/2]; ll ans = 0; rep(i, N){ ans += abs(a[i] - mid); } cout << ans << endl; }
#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<double> a, vector<double> &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; cin >> N; VLL A(N); rep(i,N){ cin >> A[i]; A[i]=A[i]-(i+1); } sort(all(A)); ll key=0; ll sum=0; key=A[N/2]; rep(i,N){ sum+=abs(A[i]-key); } cout << sum << endl; }
1
81,645,879
#include <iostream> #include <bitset> #include <fstream> #include <string> #include <cstring> #include <cmath> #include <cstdlib> #include <ctime> #include <vector> #include <algorithm> #include <numeric> #include <map> #include <set> #include <stack> #include <queue> #include <deque> #include <functional> #include <cctype> #include <list> #include <limits> const double EPS = (1e-10); using namespace std; using Int = long long; const Int MOD = 1000000007; Int mod_pow(Int x, Int n) { Int res = 1; while(n > 0) { if(n & 1) res = (res * x) % MOD; x = (x * x) % MOD; n >>= 1; } return res; } vector<vector<int>> ss; int main(){ cin.tie(0); Int N; cin >> N; Int S; int flag = 1; for (Int i = 1; i*(i-1) <= 2*N; i++){ if (i*(i-1) == 2*N){ cout << "Yes" << endl; S = i; flag = 0; break; } } if (flag){ cout << "No" << endl; return 0; } int cnt = 1; ss = vector<vector<int>> (S); for (int i = 0; i < S; i++){ for (int j = i+1; j < S; j++){ ss[i].push_back(cnt); ss[j].push_back(cnt); cnt++; } } cout << ss.size() << endl; for (auto i : ss){ cout << i.size() << " "; for (int j = 0; j < i.size(); j++){ cout << i[j]; if (j != i.size()-1) cout << " "; } cout << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int k = 1; while(k * (k - 1) / 2 < n) { k += 1; } if(k * (k - 1) / 2 != n) { cout << "No" << endl; return 0; } const int m = n * 2 / k; vector<vector<int>> ans(k); vector<int> cnt(n); for(int i = 0; i < k; ++i) { for(int j = 0; j < i; ++j) { for(auto x : ans[j]) { if(cnt[x] != 2) { ans[i].push_back(x); cnt[x] += 1; break; } } } for(int j = 0; j < n && (int)ans[i].size() != m; ++j) { if(cnt[j] == 0) { ans[i].push_back(j); cnt[j] += 1; } } } cout << "Yes\n" << k << endl; for(int i = 0; i < k; ++i) { cout << m << ' '; for(int j = 0; j < m; ++j) { cout << ans[i][j] + 1 << " \n"[j + 1 == m]; } } }
1
40,580,414
#include<bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; int x[n]; for(int i=0;i<n;i++) x[i]=i+1; int p[n],q[n]; for(int i=0;i<n;i++) cin>>p[i]; for(int i=0;i<n;i++) cin>>q[i]; int a,b,count=1; do{ int count1=0,count2=0; for(int i=0;i<n;i++){ if(x[i]==p[i]) count1++; if(x[i]==q[i]) count2++; } if(count1==n) a=count; if(count2==n) b=count; count++; }while(next_permutation(x,x+n)); cout<<abs(a-b)<<endl; }
#include<bits/stdc++.h> #define ll long long int #define vec vector<ll> #define f(a,b) for(ll i = a ; i < b ; i++ ) #define fj(a,b) for(ll j = a ; j < b ; j++ ) #define fk(a,b) for(ll k = a ; k < b ; k++ ) #define fasthoja ios_base::sync_with_stdio(false); cin.tie(NULL); using namespace std; vector<string> v; void permute(string a, int l, int r) { if (l == r) { v.push_back(a); } else { for (int i = l; i <= r; i++) { swap(a[l], a[i]); permute(a, l+1, r ); swap(a[l], a[i]); } } } int main(void){ fasthoja; ll n; cin >> n; string sn = ""; f(1,n+1) sn += to_string(i); vec p(n), q(n); string tp = ""; string tq = ""; f(0,n) cin >> p[i],tp += to_string(p[i]); f(0,n) cin >> q[i],tq += to_string(q[i]); string str = to_string(n); permute(sn , 0 , sn.length() - 1); sort( v.begin() , v.end() ); ll i1 = 0, i2 = 0; f(0,v.size()) { if( v[i] == tp ) i1 = i; if( v[i] == tq ) i2 = i; } cout << abs(i1 - i2) << "\n"; return 0; }
1
2,752,732
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++) #define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++) #define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--) #define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define sz(x) ((ll)(x).size()) #define len(x) ((ll)(x).length()) #define endl "\n" template<class T> void chmax(T &a, const T b){ a = max(a, b); } template<class T> void chmin(T &a, const T b){ a = min(a, b); } int main() { cin.tie(0); ios::sync_with_stdio(false); const ll inf = LONG_LONG_MAX / 2 - 1; ll h, n; cin >> h >> n; vector<ll> a(n), b(n); rep(i, n) cin >> a[i] >> b[i]; vector<ll> dp(h + 1, inf); dp[0] = 0; rep(i, n) { rep(j, h) { if (dp[j] == inf) continue; ll v = min(h, j + a[i]); chmin(dp[v], dp[j] + b[i]); } } cout << dp[h] << endl; return 0; }
#include <bits/stdc++.h> #define rep(i,e,n) for (int i = e; i < (n); ++i) using namespace std; typedef long long ll; using P = pair<int,int>; const int inf=1000000007; int main(){ int n,h; cin >> h >> n; vector<int> hp(h+1,inf); vector<int> attack(n); vector<int> mahou(n); rep(i,0,n) cin >> attack[i] >> mahou[i]; hp[0]=0; rep(i,1,h+1){ rep(j,0,n){ if(attack[j]>=i) hp[i]=min(mahou[j],hp[i]); else hp[i]=min(hp[i-attack[j]]+mahou[j],hp[i]); } } cout << hp[h] << endl; return 0; }
1
95,551,986
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repr(i, a, b) for(int i = a; i < b; 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>; 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; } const int mod = 1000000007; int main(){ int n, m; cin >> n >> m; vector<int> a(n+1); rep(i,m){ int j; cin >> j; a[j] = 1; } vector<int> dp(n+1); dp[0] = 1; for(int i = 0; i <= n; i++){ if (i + 1 <= n && a[i+1] != 1) { dp[i+1] += dp[i]; dp[i+1] %= mod; } if (i + 2 <= n && a[i+2] != 1){ dp[i+2] += dp[i]; dp[i+2] %= mod; } } cout << dp[n] << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define fastio ios_base::sync_with_stdio(0);cin.tie(0) #define mod 1000000007LL #define nax 500009LL #define FOR(i,n,m) for(int i = (n); i < (m); i++) #define REP(i,n) FOR(i,0,n) #define pb push_back #define mp make_pair #define fst first #define snd second #define all(v) v.begin(),v.end() #define sz(v) int(v.size()) typedef long long ll; typedef vector<int> vi; typedef pair<int,int> ii; int main(){ fastio; int n, m; cin>>n>>m; bool p[nax]; memset(p, 0, sizeof p); int x; REP(i,m) cin>>x, p[x]=1; int dp[nax]; dp[0]=1; if(p[1]){ dp[1]=0; } else{ dp[1]=1; } FOR(i,2,n+1){ if(p[i]){ dp[i]=0; } else{ if(!p[i-1]){ dp[i]+=dp[i-1]; dp[i]=dp[i]%mod; } if(!p[i-2]){ dp[i]+=dp[i-2]; dp[i]=dp[i]%mod; } } } cout<<dp[n]; return 0; }
1
8,159,496
#include <cstdio> #include <iostream> #include <iomanip> #include <string> #include <cmath> #include <vector> using namespace std; int main() { int N=0; cin>>N; long long count=0; for(int i=0;i<N;i++){ long long a,b; cin>>a>>b; count+=b-a+1; } cout<<count<<endl; return 0; }
#include <iostream> #include <cmath> #include <climits> #include <string> #include <numeric> #include <vector> #include <queue> #include <map> #include <algorithm> #include <functional> using namespace std; using ll = long long; int main() { int N; cin >> N; int people; int total=0; for (int i = 0; i < N; i++) { int l, r; cin >> l >> r; people = r - l + 1; total += people; } cout << total << endl; }
1
43,665,988
#include <bits/stdc++.h> using namespace std; int main() { int a,b,c; cin >> a >> b; int ans = 0; if(a>= b)ans =10; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main(void){ int a, b; cin >> a >> b ; /* vector<int> vec(3); cin >> vec.at(0) >> vec.at(1) >> vec.at(2) ; sort(vec.begin(), vec.end()); if( a < b ){ cout << 0 << endl; } else { cout << 10 << endl; } return 0; }
1
11,881,862
#include<bits/stdc++.h> using namespace std; #define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++) #define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++) #define MOD 1000000007 #define int long long #define ALL(a) (a).begin(),(a).end() #define vi vector<int> #define vii vector<vi> #define pii pair<int,int> #define priq priority_queue<int> #define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key))) #define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key))) #define tii tuple<int,int,int> #define Priq priority_queue<int,vi,greater<int>> #define pb push_back #define mp make_pair #define INF (1ll<<60) signed main(){ int N; cin>>N; vi C(N); rep(i,0,N) cin>>C[i]; sort(ALL(C)); vi A(N-1),B(N-1); int j=0; rep(i,1,N-1){ if(C[i]>0) break; A[j]=C[N-1]; B[j++]=C[i]; C[N-1]-=C[i]; } rep(i,1,N-1){ if(C[i]>0){ A[j]=C[0]; B[j++]=C[i]; C[0]-=C[i]; } } A[N-2]=C[N-1]; B[N-2]=C[0]; cout<<C[N-1]-C[0]<<endl; rep(i,0,N-1) cout<<A[i]<<" "<<B[i]<<endl; }
#include <vector> #include <list> #include <map> #include <set> #include <deque> #include <queue> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <fstream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <string> #include <cstring> #include <ctime> #include <climits> #include <limits> using namespace std; inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } template<class T> inline T sqr(T x) { return x * x; } typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef long long LL; #define ALL(a) (a).begin(),(a).end() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define SZ(a) int((a).size()) #define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i) #define EXIST(s,e) ((s).find(e)!=(s).end()) #define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0) #define SORT(c) sort((c).begin(),(c).end()) #define REP(i,n) for(int i=0;i<(int)n;++i) #define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i) const double EPS = 1e-10; const double PI = acos(-1.0); const int INF = (int)1000000007; const LL MOD = (LL)1000000007; const LL INF2 = (LL)100000000000000000; int main() { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a.begin(), a.end()); vector<int> pos; vector<int> neg; for (int i = 1; i < n - 1; i++) { if (a[i] >= 0) { pos.push_back(a[i]); } else { neg.push_back(a[i]); } } vector<pair<int, int>> res; int base=0; if (pos.size() > 0) { base =a[0]-a[n-1]; res.push_back(make_pair(a[0], a[n - 1])); } else { base = a[n - 1] - a[0]; res.push_back(make_pair(a[n - 1], a[0])); } if (pos.size() > 0) { for (int i = 0; i < pos.size() - 1; i++) { res.push_back(make_pair(base, pos[i])); base -= pos[i]; } res.push_back(make_pair(pos[pos.size() - 1], base)); base = pos[pos.size() - 1] - base; } for (int i = 0; i < neg.size(); i++) { res.push_back(make_pair(base, neg[i])); base -= neg[i]; } cout << base << endl; for (int i = 0; i < res.size(); i++) { cout << res[i].first << " " << res[i].second << endl; } return 0; }
1
9,225,151
#include <iostream> #include <string> #include <array> #include <algorithm> #include <vector> #include <string> #include <set> #include <cctype> #include <map> #include <stdio.h> #include <string.h> #include <math.h> #include <ctype.h> #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #define FOR(i,l,r) for(size_t i=(l);i<(r);++i) #define REP(i,n) FOR(i,0,n) using namespace std; bool is_integer( float x ){ return floor(x)==x; } int main() { string s; bool ans = true; int count = 0; cin >> s; if(s[0] != 'A') ans = false; for(int i = 2; i < s.length()-1; i ++ ){ if(s[i] == 'C') count ++; } if(count != 1) ans = false; for(int i = 0; i < s.length(); i ++){ if(s[i] != 'A' && s[i] != 'C'){ if(!islower(s[i])) ans = false; } } cout << ((ans)?"AC":"WA"); return 0; }
#include <iostream> #include <vector> #include <utility> #include <algorithm> #include <cmath> #include <string> #include <map> #include <cctype> #define pb push_back #define mp make_pair using namespace std; typedef vector<int> vi; typedef pair<int, int> ii; typedef vector<ii> vii; typedef unsigned long long ull; typedef long long ll; int main() { string s; cin >> s; char init = s.at(0); int occ = 0; for (int i = 2; i < s.size()-1; ++i) { if (s.at(i) == 'C') { occ++; } } int lowocc = 0; for (int i = 0; i < s.size(); ++i) { if (islower(s.at(i))) { lowocc++; } } if (init == 'A' && occ == 1 && lowocc == s.size()-2) { cout << "AC" << endl; } else { cout << "WA" << endl; } return 0; }
1
9,432,065
#include<bits/stdc++.h> using namespace std; #define sync ios_base::sync_with_stdio(false), cin.tie(NULL) #define F first #define S second #define pb emplace_back #define mt make_tuple #define mp make_pair #define gcd __gcd #define PI 3.141592653589 #define in(a) scanf("%d",&a) #define in2(a,b) scanf("%d%d",&a,&b) #define in3(a,b,c) scanf("%d%d%d",&a,&b,&c) #define llin(a) cin >> a #define inl(a) scanf("%lld",&a) #define read(v,i,n) for(i=0;i<n;i++)in(v[i]) #define twod(mat,i,j,n,m) rep(i,n){rep(j,m)in(mat[i][j]);} #define sc(ch) scanf("%c",&ch) #define sstr(str) scanf("%s",str) #define pr(a) printf("%d ",a) #define pr2(a,b) printf("%d %d\n",a,b) #define pr3(a,b,c) printf("%d %d %d\n",a,b,c) #define out(a) printf("%d\n",a) #define outl(a) printf("%lld\n",a) #define llpr(a) cout << a << " " #define llout(a) cout << a << "\n" #define yes printf("YES\n") #define no printf("NO\n") #define lin printf("\n") #define lp(i,a,b) for(i=a;i<b;i++) #define rep(i,n) for(i=0;i<n;i++) #define all(vec) vec.begin(),vec.end() #define lower(v,k) lower_bound(v.begin(),v.end(),k)-v.begin() #define upper(v,k) upper_bound(v.begin(),v.end(),k)-v.begin() #define tf(mytuple) get<0>(mytuple) #define ts(mytuple) get<1>(mytuple) #define tt(mytuple) get<2>(mytuple) #define dbg(v,i,n) for(i=0;i<n;i++)pr(v[i]); lin #define what(x) cerr << #x << " : " << x << "\n" #define ck printf("continue\n") #define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); } void err(istream_iterator<string> it) {} template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << "\n"; err(++it, args...); } #define ll long long int #define ii pair<int,int> #define pli pair<ll,int> #define triple tuple<int,int,int> #define vi vector<int> #define vii vector<pair<int,int> > #define vvi vector<vector<int> > #define viii vector<pair<pair<int,int>,int> > #define vvii vector<vector<pair<int,int> > > #define M 1000000007 #define N 100005 const ll INF = 1e18; int main() { int i,j,n,a; in(n); vi ar(n); vi v(n); read(ar,i,n); vii asc; v[0]=ar[0]; asc.pb(v[0],0); vector<ll> ans(n,0),bit(n+1,0); ii temp; lp(i,1,n) { v[i]=max(ar[i],v[i-1]); if(v[i]>v[i-1]) asc.pb(v[i],i); else { temp=make_pair(ar[i],n); j=upper(asc,temp); bit[0]++,bit[j]--; if(j>0) ans[asc[j].S]+=(ar[i]-asc[j-1].F); else ans[asc[j].S]+=(ar[i]); } } int m=asc.size(); lp(i,1,m) bit[i]+=bit[i-1]; rep(i,m) bit[i]+=(m-i); lp(i,1,m) bit[i]*=(asc[i].F-asc[i-1].F); bit[0]*=asc[0].F; rep(i,m) a=asc[i].S,ans[a]+=bit[i]; rep(i,n) llout(ans[i]); }
#include<bits/stdc++.h> using namespace std; typedef long long ll; int main(){ ll n;cin>>n; ll a[n];for(ll i=0;i<n;i++)cin>>a[i]; ll sai[n]; sai[0]=a[0]; for(ll i=1;i<n;i++)sai[i]=max(sai[i-1],a[i]); vector<ll> v; for(ll i=0;i<n;i++)v.push_back(sai[i]); v.erase(unique(v.begin(),v.end()),v.end()); ll tai[v.size()]; ll now=0; for(ll i=0;i<n;i++){ if(now==v.size())break; if(sai[i]==v[now]){ tai[now]=i; now++; } } ll ko[v.size()]; ll wa[v.size()]; vector<ll> w; for(ll i=0;i<n;i++)w.push_back(a[i]); sort(w.begin(),w.end()); for(ll i=0;i<n;i++){ if(w[i]==v[0]){ now=i; break; } } for(ll i=0;i<v.size();i++){ if(i<v.size()-1){ ll sum=0; for(ll j=now;;j++){ if(w[j]==v[i+1]){ ko[i]=j-now-1; wa[i]=sum; now=j; break; } sum+=w[j]-v[i]; } } else{ ko[i]=n-now; wa[i]=0; } } ll ans[n]; fill(ans,ans+n,0); ll hav=ko[v.size()-1]; for(ll i=v.size()-1;i>0;i--){ ans[tai[i]]=wa[i-1]+hav*(v[i]-v[i-1]); hav=hav+ko[i-1]+1; } ll ss=0; for(ll i=0;i<n;i++){ ss+=min(v[0],a[i]); } ans[0]=ss; for(ll i=0;i<n;i++){ cout<<ans[i]<<endl; } }
1
76,147,032
#include <bits/stdc++.h> using namespace std; using ull = unsigned long long; int main() { string S; cin >> S; ull K; cin >> K; ull ans = 0; for(int i=0; i<(int)S.size(); i++){ if(S.at(i) != '1'){ cout << S.at(i) << endl; return 0; } else{ ans += 1; } if(ans >=K){ cout << 1 << endl; return 0; } } cout << 1 << endl; }
#include <bits/stdc++.h> using namespace std; #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 _rrep(i, n) rrepi(i, n, 0) #define rrepi(i, a, b) for (int i = int(a) - 1; i >= int(b); --i) #define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__) #define rrep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__) #define each(xi, x) for (auto &&xi : x) template <class T> using vec = vector<T>; using ll = long long; using vi = vec<ll>; using vvi = vec<vi>; using vvvi = vec<vvi>; using pii = pair<ll, ll>; #define pb push_back #define mp make_pair #define all(x) (x).begin(), (x).end() #define uniq(v) v.erase(unique(all(v)), v.end()) #define perm(c) \ sort(all(c)); \ for (bool c##p = 1; c##p; c##p = next_permutation(all(c))) template <class T> pair<T, size_t> max(vector<T> &x) { auto it = max_element(all(x)); return mp(*it, it - x.begin()); } template <class T> pair<T, size_t> min(vector<T> &x) { auto it = min_element(all(x)); return mp(*it, it - x.begin()); } template <class T> inline bool chmax(T &maxval, const T &newval) { if (maxval < newval) { maxval = newval; return 1; } return 0; } template <class T> inline bool chmin(T &minval, const T &newval) { if (minval > newval) { minval = newval; return 1; } return 0; } int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 0}; #define inside(H, W, y, x) 0 <= (x) && (x) < (W) && 0 <= (y) && (y) < (H) #ifdef LOCAL #include "dump.hpp" #define debug(x) cerr << #x << ": " << x << '\n' #else #define dump(...) #define debug(x) #endif void yesno(bool ok, string yes = "Yes", string no = "No") { cout << (ok ? yes : no) << endl; } void solve(string S, long long K) { char ret='1'; rep(k,min(K,(ll)S.size())){ if(S[k]!='1'){ret = S[k]; break;} } cout << ret << endl; } int main() { cin.tie(0); ios::sync_with_stdio(false); cout.precision(12); string S; std::cin >> S; long long K; std::cin >> K; solve(S, K); return 0; }
1
24,455,365
#include <iostream> #include <vector> #include <climits> #include <algorithm> #include <cmath> #include <map> #include <set> #include <string> #include <bitset> #include <utility> #include <numeric> #include <queue> #include <stack> using ll = long long; using namespace std; constexpr int MOD = 1e9 + 7; constexpr ll MOD_LL = ll(1e9) + 7; int main(void) { int n, h; cin >> n >> h; vector<int> a(n), b(n); for(int i = 0; i < n; ++i) { cin >> a[i] >> b[i]; } sort(b.begin(), b.end(), greater<int>()); int x = *max_element(a.begin(), a.end()); int ans = 0; for(int i = 0; i < n; ++i) { if( h > 0 && x < b[i] ) { h -= b[i]; ans++; } } if( h > 0 ) { if( h % x == 0 ) ans += h / x; else ans += h / x + 1; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i,n)for(long long i=0;i<(long long)(n);++i) #define all(a) a.begin(), a.end() using namespace std; typedef long long ll; typedef pair<ll, ll> P; 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; } const int MOD=1e9+7; const ll INF=1e18; const ll inf=1e9; const double pi=acos(-1); int dx[8] = {1,0,-1,0,1,1,-1,-1}; int dy[8] = {0,1,0,-1,-1,1,1,-1}; const int MAX=510000; int main(){ cin.tie(0); ios::sync_with_stdio(false); ll n,h; cin >> n >> h; vector<ll> a(n),b(n); rep(i,n) cin >> a[i] >> b[i]; sort(a.begin(),a.end(),greater<ll>()); sort(b.begin(),b.end(),greater<ll>()); vector<ll>s(n+1); ll num = 0; rep(i,n){ if(b[i]>a[0]){ s[i+1] = s[i] + b[i]; num++; } else break; } ll ok = inf, ng = 0; while(abs(ok-ng)>1){ ll mid = (ok+ng)/2; if(mid*a[0]>=h) ok=mid; else{ if(mid<=num){ if(s[mid]<h)ng=mid; else ok = mid; } else{ if(s[num]+(mid-num)*a[0]<h)ng=mid; else ok = mid; } } } cout << ok << endl; return 0; }
1
98,310,994
#include <bits/stdc++.h> using namespace std; using ll = long long; ll g(ll n, int p) { if (n == 0) return 0; return g(n / p, p) + n / p; } ll g2(ll n, int p) { ll ret = g(n / 2, p); if (p == 2) ret += n / 2; return ret; } int main() { ll n; cin >> n; if (n % 2 == 1) { cout << 0 << endl; return 0; } ll ans = min(g2(n, 2), g2(n, 5)); cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ long long n; cin >> n; if(n % 2 == 1){ cout << 0 << endl; return 0; } long long cnt = 0; long long waru = 10; while(true){ if(n/waru > 0){ cnt += n / waru; waru *= 5; }else{ break; } } cout << cnt << endl; return 0; }
1
20,906,218
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = (int)1e5 + 50, INF = (int)1e9 + 50; typedef pair<int, int> P; int n; P p[N]; ll res[N]; int main() { cin >> n; for(int i = 0; i < n; i++) cin >> p[i].first, p[i].second = i; sort(p, p + n, greater<>()); int r = 0; int mn = INF; for(int i = 0; i < n; ) { while(r < n && p[r].first == p[i].first) { mn = min(mn, p[r].second); r++; } res[mn] += 1LL * (p[i].first - p[r].first) * r; i = r; } for(int i = 0; i < n; i++) cout << res[i] << "\n"; }
#include<bits/stdc++.h> using namespace std; #define MOD 1000000007 #define INF 1000000010 #define EPS 1e-9 #define fst first #define scd second #define debug(x) cout<<x<<endl; #define repi(i,x,n) for(int i=x;i<n;i++) #define rep(i,n) repi(i,0,n) #define lp(i,n) repi(i,0,n) #define repn(i,n) for(int i=n;i>=0;i--) #define int long long #define endl "\n" bool comp(const pair<int,int> a,const pair<int,int> b){ if(a.first > b.first) return true; else if(a.first < b.first) return false; else{ if(a.second>b.second) return false; else return true; } }; signed main(){ cin.tie(0); ios::sync_with_stdio(false); int n; cin>>n; int a[n]; rep(i,n) cin>>a[i]; int ans[n]={}; vector<pair<int,int>> x; rep(i,n){ x.push_back({a[i],i}); } sort(x.begin(),x.end(),comp); int prevheight,nownum; prevheight=x[0].first; nownum=x[0].second; rep(i,x.size() ){ if(prevheight!=x[i].first){ ans[nownum]+=(prevheight-x[i].first)*i; prevheight=x[i].first; if(x[i].second < nownum) nownum=x[i].second; } } ans[nownum]+=prevheight*n; rep(i,n){ cout<<ans[i]<<endl; } return 0; }
1
32,853,386
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int,int> P; typedef pair<ll,ll> l_l; const int INF=1001001000; const int mINF=-1001001000; const ll LINF=1010010010010010000; 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; } int main(){ int a,b;cin >> a >> b; vector<vector<char>> grid(100,vector<char>(100)); for(int i=0;i<100;i++){ for(int j=0;j<100;j++){ if(j<50) grid[i][j]='.'; else grid[i][j]='#'; } } int needa=a-1; int needb=b-1; for(int i=0;i<100;i++){ if(i%2==0) continue; for(int j=0;j<100;j++){ if(j<49){ if(needb>0&&j%2==1){ grid[i][j]='#'; needb--; } } else if(j>=51&&j<=98){ if(needa>0&&j%2==1){ grid[i][j]='.'; needa--; } } } } cout << 100 << " " << 100 << endl; for(int i=0;i<100;i++){ for(int j=0;j<100;j++){ cout << grid[i][j]; } cout << endl; } return 0; }
#include <iostream> #include <vector> #include <algorithm> #include <cmath> #include <numeric> #include <set> #include <map> #include <stack> #include <queue> #include <time.h> #include <list> using namespace std; typedef long long ll; #define rep(i,n) for(int i=0;i<(n);++i) #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define reps(x,c) for(auto x:c) #define all(x) begin(x), end(x) #define pb(a) emplace_back(a) #define mp(a,b) make_pair((a),(b)) #define pl pair<ll,ll> #define INF 2147483600 #define MOD 1000000007 #define fi first #define se second #define dbg(x) cout << #x"="<< (x) << endl #define dbgv(x) cout<<#x<<endl;reps(y,x){cout<<y<<" ";}cout<<endl int table[110][110]; int main(){ ll a,b;cin>>a>>b; cout<<100<<" "<<100<<endl; rep(i,100){ rep(j,100){ if(i<50){ table[i][j]=1; } } } a--; b--; rep(i,50){ if(i%2==0){ rep(j,100){ if(a==0){ break; } if(j%2==0){ table[i][j]=0; a--; } } } } FOR(i,50,100){ if(i%2==1){ rep(j,100){ if(b==0){ break; } if(j%2==0){ table[i][j]=1; b--; } } } } rep(i,100){ rep(j,100){ if(table[i][j]==0){ cout<<"."; }else{ cout<<"#"; } } cout<<endl; } return 0; }
1
25,949,908
#include <iostream> #include <vector> #include <math.h> using namespace std; int factorial(int n){ if(n <= 1) return 1; return factorial(n-1) * n; } int findPosition(vector<int> &a){ int n = a.size(); int index = 0; vector<bool> occ(n, false); for(int i = 0; i < n-1;i++){ int x = a[i] - 1; int cc = 0; for(int j =0; j < x; j++){ if(!occ[j]) cc++; } occ[x] = true; index += cc*factorial(n-i-1); } return index; } int main() { int n; cin >> n; if(n == 1){ cout << 0 << endl; return 0; } vector<int> p(n); vector<int> q(n); for(auto &i: p){ cin >> i; } for(auto &i: q){ cin >> i; } cout << abs(findPosition(p) -findPosition(q) )<< endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main(void) { int n; cin >> n; vector<int> id(n), id2(n); for (int i = 1; i <= n; i++) { id.at(i - 1) = i; id2.at(i - 1) = i; } vector<int> p(n), q(n); for (int i = 0; i < n; i++) { cin >> p.at(i); } for (int i = 0; i < n; i++) { cin >> q.at(i); } int pi = 1; if (p != id) { while (next_permutation(id.begin(), id.end())) { pi++; if (id == p) break; } } id = id2; int qi = 1; if (q != id) { while (next_permutation(id.begin(), id.end())) { qi++; if (id == q) break; } } cout << abs(pi - qi) << endl; return 0; }
1
35,965,472
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; template <class T> using V = vector<T>; template <class T> using VV = V<V<T>>; #define pb push_back #define eb emplace_back #define mp make_pair #define fi first #define se second #define rep(i, n) rep2(i, 0, n) #define rep2(i, m, n) for (int i = m; i < (n); i++) #define per(i, b) per2(i, 0, b) #define per2(i, a, b) for (int i = int(b) - 1; i >= int(a); i--) #define ALL(c) (c).begin(), (c).end() #define SZ(x) ((int)(x).size()) constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); } template <class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; } template <class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; } 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 << "{"; rep(i, v.size()) { if (i) os << ","; os << v[i]; } os << "}"; return os; } #ifdef LOCAL void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...); } #define debug(...) \ cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl #else #define debug(...) (void(0)) #define dump(x) (void(0)) #endif int main() { string S, T, U; int A, B; cin >> S >> T >> A >> B >> U; if (U == S) --A; else --B; cout << A << " " << B << 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++) typedef long long int ll; typedef unsigned long long int ull; int main(){ ios::sync_with_stdio(false); cin.tie(0); int a,b,c; string s,t,u; cin >>s>>t>>a>>b>>u; if(s==u){ a--; }else{ b--; } cout <<a<<' '<<b; }
1
33,028,360
#include <iostream> #include <cstdio> #include <vector> #include <cmath> #include <cstring> #include <numeric> #include <algorithm> #include <functional> #include <array> #include <map> #include <queue> #include <limits.h> #include <set> #include <stack> using namespace std; #define Getsign(n) ((n > 0) - (n < 0)) #define QWERTYR(c) (c == 'y' || c == 'u' || (c >= 'h' && c <= 'p') ? true : false) map<string, int> roma_time = { { "I",1 },{ "II",2 },{ "III",3 },{ "IIII",4 },{ "V",5 },{ "VI",6 },{ "VII",7 },{ "VIII",8 },{ "IX",9 },{ "X",10 },{ "XI",11 },{ "XII",12 } }; typedef vector<int> Ivec; typedef pair<int, int> pii; int main() { int n, Max, Min; while (scanf("%d %d %d", &n, &Min, &Max)) { if (n == 0) return 0; vector<int> points; for (int i = 0; n > i; i++) { int p; scanf("%d", &p); points.push_back(p); } int num, Maxim = -1; for (int i = Min-1; Max-1 >= i; i++) { if (points[i] - points[i + 1] >= Maxim) { num = i; Maxim = points[i] - points[i + 1]; } } printf("%d\n", num + 1); } return 0; }
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main(int argc, char *argv[]) { for(;;) { int m, nm, nx; cin >> m >> nm >> nx; if(m == 0) break; vector<int> cs; for(int i = 0; i < m; i++) { int p; cin >> p; cs.push_back(p); } int dx = 0; int nn = nm; for(int i = nm - 1; i < nx; i++) { int d = cs[i] - cs[i+1]; if(d >= dx) { dx = d; nn = i + 1; } } cout << nn << endl; } return 0; }
1
64,762,865
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int, int>; int main() { int n, k; cin >> n >> k; vector<int> cnt(n, 1); rep(i, k) { int d; cin >> d; rep(j, d) { int a; cin >> a, --a; cnt[a] = 0; } } int ans = 0; rep(i, n) ans += cnt[i]; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, N) for (long long i = 0; i < N; i++) using ll = long long; int main() { ll N, K; cin >> N >> K; vector<ll> sunuke(N + 1); rep(i, K) { ll d; cin >> d; vector<ll> A(d); rep(j, d) { ll a; cin >> a; sunuke[a]++; } } ll ans = 0; for (ll i = 1; i <= N; i++) { if (sunuke[i] == 0) { ans++; } } cout << ans << endl; return 0; }
1
13,503,505
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i) #define xrep(i,a,b) for(int i=int(a);i<int(b);++i) using ll = long long; int main() { int N, M; cin >> N >> M; vector<vector<string>> JUDGES(N); rep(i, M) { int p; string s; cin >> p >> s; --p; JUDGES[p].push_back(s); } int AC = 0; int WA = 0; for(auto jds: JUDGES) { int wacnt = 0; for(string jd: jds) { if(jd == "AC") { ++AC; break; } else { ++wacnt; } } if(wacnt==jds.size()) { continue; } else { WA += wacnt; } } cout << AC << " " << WA << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define FOR(i, a, b) for (int i = a; i < (b + a); i++) #define W1 while (1) #define COUT(x) cout << x << endl using namespace std; using ll = long long; using ld = long double; #define ALL(x) x.begin(),x.end() #define P pair<int,int> #define mod 1000000007 #define PB push_back #define F first #define S second int main() { int n, m, tmp1; string tmp2; cin >> n >> m; vector<bool> acflg(n + 1, false); vector<int> wa(n + 1, 0); rep(i, m) { cin >> tmp1 >> tmp2; if (tmp2 == "AC") acflg[tmp1] = true; if (!acflg[tmp1]) { if (tmp2 == "WA") wa[tmp1]++; } } int acsum = 0; int wasum = 0; FOR(i, 1, n) { if (acflg[i]) { acsum++; wasum += wa[i]; } } cout << acsum << " " << wasum << endl; return 0; }
1
72,948,917
#include<iostream> using namespace std; int main() { int N; cin >> N; int A[N]; for (int i = 0; i < N; i++) { cin >> A[i]; } int ans = 0; for (int i = 0; i < N - 1; i++) { for (int j = i + 1; j < N; j++) { ans = max(ans, abs(A[i] - A[j])); } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin>>n; int A[n]; int m=1000000000,M=0; for (int i = 0; i < n; i++) { cin>>A[i]; if(m>A[i])m=A[i]; if(M<A[i])M=A[i]; } cout<<M-m<<endl; }
1
65,728,021
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m, item_popular, sum = 0, cont = 0; cin >> n >> m; vector<int> v(n); for(int i=0; i < n; i++) { cin >> v[i]; sum+= v[i]; } item_popular = 4 * m; bool popular = false; for(int i=0; i<n; i++) { if(v[i] * 1LL * item_popular >= sum) cont++; if(cont == m) { popular = true; break; } } popular ? cout << "Yes\n" : cout << "No\n"; return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ int n, m, sum = 0; cin >> n >> m; vector<int> a(n); for (int i=0 ; i<n ; i++){ cin >> a.at(i); sum += a.at(i); } int pop = 0; float basis = sum*0.25/m; for (int i=0 ; i<n ; i++){ if (a.at(i) >= basis) pop++; } if (pop >= m) cout << "Yes" << endl; else cout << "No" << endl; }
1
85,766,817
#include <bits/stdc++.h> using namespace std; int main() { int N,M,Z=0; cin>>N>>M; vector<int> p(N); for(int i=0;i<N;i++){ int a; cin>>a; p.at(i)=a-1; } vector<vector<int>> G(N); for(int i=0;i<M;i++){ int a,b; cin>>a>>b; a--; b--; G.at(a).push_back(b); G.at(b).push_back(a); } vector<int> c(N); for(int i=0;i<N;i++){ if(c.at(i)==0){ c.at(i)=1; queue<int> q; vector<int> w; vector<int> e; q.push(i); w.push_back(i); e.push_back(p.at(i)); while(!(q.empty())){ int a=q.front(); q.pop(); for(int x:G.at(a)){ if(c.at(x)==0){ c.at(x)=1; q.push(x); w.push_back(x); e.push_back(p.at(x)); } } } sort(w.begin(), w.end()); sort(e.begin(), e.end()); int a=0,b=0; while(a<w.size()&&b<e.size()){ if(w.at(a)>e.at(b)){ b++; } else if(w.at(a)<e.at(b)){ a++; } else{ Z++; a++; b++; } } } } cout<<Z<<endl; }
#include <bits/stdc++.h> using namespace std; struct UnionFind { vector<int> parent; vector<int> size; UnionFind(int n) : parent(n, -1), size(n, 1) {} int find(int i) { if (parent[i] == -1) { return i; } return parent[i] = find(parent[i]); } void unite(int i, int j) { i = find(i); j = find(j); if (i == j) { return; } if (size[i] < size[j]) { parent[i] = j; size[j] += size[i]; } else { parent[j] = i; size[i] += size[j]; } } }; int main() { int n, m; cin>>n>>m; int p[n+1]; for (int i=0; i<n; i++) cin>>p[i+1]; UnionFind uf(n+1); for (int i=0; i<m; i++) { int x, y; cin>>x>>y; uf.unite(x, y); } int cnt = 0; for (int i=1; i<=n; i++) { if (uf.find(i) == uf.find(p[i])) { ++cnt; } } cout<<cnt<<endl; }
1
92,478,753
#include<bits/stdc++.h> using namespace std; int main() { int a,b,c; cin>>a>>b; if(a==1 || b==1){ if(a==1 && b==1)cout<<"Draw"; else if(a<b)cout<<"Alice"; else if(a>b)cout<<"Bob"; } else { if(a>b)cout<<"Alice"; else if(a==b)cout<<"Draw"; else if(a<b)cout<<"Bob"; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int A, B; cin >> A >> B; if (A != 1 && B != 1) { if (A > B) {cout << "Alice" << endl;} else if (A == B) {cout << "Draw" << endl;} else {cout << "Bob" << endl;} } else { if (A == 1 && B != 1) {cout << "Alice" << endl;} else if (A == 1 && B == 1) {cout << "Draw" << endl;} else {cout << "Bob" << endl;} } }
1
53,368,469
#include <bits/stdc++.h> using namespace std; int main(void){ string S; cin >> S; reverse(S.begin(),S.end()); for(int i = 0 ; i < S.size() ; ){ if(S.substr(i,7) == "remaerd"){ i+=7; } else if(S.substr(i,6) == "resare"){ i+=6; } else if(S.substr(i,5) == "maerd"){ i+=5; } else if(S.substr(i,5) == "esare"){ i+=5; } else{ cout << "NO" << endl; return 0; } } cout << "YES" << endl; return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<n;i++) #define all(x) (x).begin(),(x).end() #define cyes cout<<"YES"<<endl #define cno cout<<"NO"<<endl #define sp <<" "<< #define cst(x) cout<<fixed<<setprecision(x) #define pi 3.14159265359 #define mod 1000000007 using namespace std; using ll = long long; using ld = long double; using Graph = vector<vector<int>>; using que_a = priority_queue<int, vector<int>, greater<int> >; using que_d = priority_queue<int>; using pint = pair<int,int>; vector<string> word = {"dream","dreamer","erase","eraser"}; string s; bool dfs(int n){ if(n == s.size()) return true; for(string wo : word){ if(s.substr(n,wo.size()) == wo) if(dfs(n + wo.size())) return true; } return false; } int main(){ cin >> s; dfs(0) ? cyes : cno; return 0; }
1
20,655,856
#include "bits/stdc++.h" #include "math.h" using namespace std; typedef long long ll; typedef vector<ll> vll; typedef vector<vll> vvll; typedef vector<bool> vb; typedef vector<vb> vvb; typedef vector<int> vin; typedef pair<ll,ll> P; typedef vector<P> vp; #define rep(i,a,b) for(ll i=(a);i<(b);++i) #define drep(i,a,b) for(ll i=(a);i>=(b);--i) #define SIZE(a) int((a).size()) #define out(a) cout<<(a)<<endl; const int INF=INT_MAX; const int MAX = 510000; const ll MOD = 1000000007; ll fac[MAX], finv[MAX], inv[MAX]; int main(){ ll n;cin>>n; vll h(n); rep(i,0,n){ cin>>h[i]; } ll ans=h[0]; rep(i,1,n){ if(h[i]>h[i-1]){ ans+=h[i]-h[i-1]; } } cout<<ans<<endl; }
#include <limits.h> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <algorithm> #include <cassert> #include <cfloat> #include <complex> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <regex> #include <set> #include <stack> #include <string> #include <unordered_map> #include <vector> using namespace std; #define chmax(x, y) x = max(x, y) #define chmin(x, y) x = min(x, y) #define rep(i, n) for (ll i = 0; i < (n); ++i) #define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i) #define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i) #define Sort(v) sort(v.begin(), v.end()) #define rSort(v) sort(v.rbegin(), v.rend()) #define Reverse(v) reverse(v.begin(), v.end()) #define Lower_bound(v, x) \ distance(v.begin(), lower_bound(v.begin(), v.end(), x)) #define Upper_bound(v, x) \ distance(v.begin(), upper_bound(v.begin(), v.end(), x)) using ll = long long; using ull = unsigned long long; using P = pair<ll, ll>; using T = tuple<ll, ll, ll>; using vll = vector<ll>; using vP = vector<P>; using vT = vector<T>; using vvll = vector<vector<ll>>; using vvP = vector<vector<P>>; using dqll = deque<ll>; ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0}; ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0}; const ll INF = 1LL << 50; int main() { cout << fixed << setprecision(15); ll n; cin >> n; vll hs(n); rep(i, n) cin >> hs[i]; ll l = 0, ysf = 0; while (l < n) { if (hs[l] == 0) { l++; continue; } ll r = l; while (r < n && hs[r] > 0) { r++; } for (ll i = l; i < r; i++) { hs[i]--; } ysf++; } cout << ysf << endl; return 0; }
1
83,789,562
#include<bits/stdc++.h> using namespace std; using ll = long long; ll gcd(ll x, ll y) { if (x < y) swap(x, y); while (y) swap(x %= y, y); return x; } int main() { ll x, y; cin >> x >> y; ll g = gcd(x, y); ll ans = x / g * y - x; if (ans > 0) { cout << ans << endl; } else { cout << -1 << endl; } }
#include <bits/stdc++.h> using namespace std; int a, b; int main() { scanf("%d %d",&a,&b); if(a%b == 0) printf("-1\n"); else printf("%d\n",a); }
1
11,051,149
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll INF = 1010000000000000017LL; const ll MOD = 1000000007LL; #define REP(i, n) for(ll i = 0 ; i < n; i++) #define DEBUG(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__) int main(){ std::cout<<std::fixed<<std::setprecision(10); ll A, P; cin >> A >> P; cout << (A*3+P)/2 << endl; }
#include <bits/stdc++.h> #include <iostream> #include <string> #include <string.h> #include <ctype.h> #include <algorithm> #include <math.h> using namespace std; int main() { int a,p; cin >> a >> p; int sum = (a*3+p)/2; cout << sum << endl; }
1
33,917,973
#include <bits/stdc++.h> #define ll long long using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) using P = pair <int, int>; int main() { int a,b; cin >>a>>b; if(a>b) swap(a,b); if (b==1) {cout <<1 << endl; return 0;} if (a==1) {cout << b-2 << endl; return 0;} ll ans = (ll)(a-2)*(b-2); cout << ans << endl; return 0; }
#include <bits/stdc++.h> #include <boost/range/algorithm.hpp> #include <boost/range/numeric.hpp> #include <boost/integer/common_factor.hpp> #include <boost/integer/common_factor_rt.hpp> #include <boost/multiprecision/cpp_dec_float.hpp> #include <boost/multiprecision/cpp_int.hpp> using std::string; using std::vector; using std::set; using std::multiset; using std::unordered_set; using std::map; using std::multimap; using std::unordered_map; using std::pair; using std::cin; using std::cout; using boost::multiprecision::cpp_int; using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>>; typedef uintmax_t ull; typedef intmax_t ll; typedef uint64_t ul; typedef uint32_t ui; typedef uint8_t uc; constexpr char CRLF = '\n'; constexpr char SPACE = ' '; constexpr char VECTOR_COUT_SEPARATOR = SPACE; constexpr ll INF = 1000'000'007; constexpr int MOD = 1000'000'007; 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> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; } template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; } template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; } struct Tmp { public: Tmp(int N); }; Tmp::Tmp(int N){} void solve(void) { int N, M; cin >> N >> M; ll nN = N == 1 ? 1 : N - 2; ll nM = M == 1 ? 1 : M - 2; auto ans = nN * nM; cout << ans << CRLF; return; } int main(void) { std::ios_base::sync_with_stdio(false); std::cin.tie(0); solve(); return 0; }
1
42,447,153
#include <bits/stdc++.h> #define repr(i,a,b) for(int i=a;i<b;i++) #define rep(i,n) for(int i=0;i<n;i++) #define reprrev(i,a,b) for(int i=b-1;i>=a;i--) #define reprev(i,n) reprrev(i,0,n) using ll = long long; using ull = unsigned 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; } const ll mod = 1e9+7; void chmod(ll &M){ if(M >= mod) M %= mod; else if(M < 0){ M += (abs(M)/mod + 1)*mod; M %= mod; } } ll modpow(ll x, ll n){ if(n==0) return 1; ll res=modpow(x, n/2); if(n%2==0) return res*res%mod; else return res*res%mod*x%mod; } int getl(int i, int N) { return i==0? N-1:i-1; }; int getr(int i, int N) { return i==N-1? 0:i+1; }; long long GCD(long long a, long long b) { if (b == 0) return a; else return GCD(b, a % b); } using namespace std; int main() { string N; cin >> N; int sum = 0; int n = N.length(); for (int i = 0; i < n; i++) { int a = N[i] - '0'; sum += a; } if (sum % 9 == 0) cout << "Yes" << endl; else cout << "No" << endl; }
#include <bits/stdc++.h> #define rep(i, ns, ne) for (int i = ns; i < ne; ++i) using namespace std; int main() { string s; cin >> s; unsigned long long sum; rep(i, 0, s.size()) { sum += s[i] - '0'; } cout << ((sum % 9) ? "No" : "Yes") << endl; getchar(); }
1
96,894,750
#include <bits/stdc++.h> using namespace std; #define int long long #define ll long long #define FOR(i,a,b) for(int i=(a); i<=(b); i++) #define rep(i,n) for(int i = 0; i < (n); i++) #define loop(k) rep(author_is_masa,k) #define chmin(a,b) if((a)>(b)) (a)=(b); #define chmax(a,b) if((a)<(b)) (a)=(b); #define vi vector<int> #define pii pair<int,int> #define all(v) (v).begin(),(v).end() #define allr(v) (v).rbegin(),(v).rend() #define pb push_back #define pf push_front int gcd(int a,int b){ while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b); } int dx[]={1,0,-1,0,1,-1,-1,1}; int dy[]={0,1,0,-1,1,1,-1,-1}; const int MOD = 1e9+7; const long long INF = 1e18+10; signed main(){ int n,k; cin>>n>>k; int ans=0; rep(i,n){ int h;cin>>h; ans+=h>=k; } cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> #include <vector> #define rep(i,n) for (int i = 0; i < (n); ++i) #define size_of_array(array) (sizeof(array)/sizeof(array[0])) using ll =long long; using namespace std; using Graph=vector<vector<int>>; using Field=vector<vector<int>>; int main(){ int n,k; cin>>n>>k; vector<int> h(n); rep(i,n)cin>>h[i]; int cnt=0; rep(i,n){ if(h[i]>=k)++cnt; } cout<<cnt<<endl; }
1
42,315,575
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main(){ int N, M; cin >> N >> M; int INF = -1e9; vector<int> dpk(N + 1, INF), A(M); for(int i = 0; i < M; i++) cin >> A[i]; sort(A.begin(), A.end()); vector<int> cost(M); for(int i = 0; i < M; i++){ if(A[i] == 1) cost[i] = 2; else if(A[i] == 2 || A[i] == 3 || A[i] == 5) cost[i] = 5; else if(A[i] == 4) cost[i] = 4; else if(A[i] == 6 || A[i] == 9) cost[i] = 6; else if(A[i] == 7) cost[i] = 3; else cost[i] = 7; } dpk[0] = 0; for(int i = 1; i < N + 1; i++){ for(int j = 0; j < M; j++){ if(i - cost[j] >= 0) dpk[i] = max(dpk[i], dpk[i - cost[j]] + 1); } } int keta = dpk[N]; vector<int> ke(keta); int i = 0; while(N > 0){ for(int j = M - 1; j >= 0; j--){ if(i == keta - 1){ for(int j = M - 1; j >= 0; j--){ if(cost[j] == N){ ke[i] = A[j]; N -= cost[j]; i++; break; } } } else if(N - cost[j] >= 0 && dpk[N] == dpk[N - cost[j]] + 1){ ke[i] = A[j]; i++; N -= cost[j]; break; } } } for(int i = 0; i < keta; i++){ cout << ke[i]; } cout << endl; }
#include "bits/stdc++.h" using namespace std; string dp[11000]; const string MINUSINF = "-"; string compare(string str1 ,string str2) { if (MINUSINF == str1) { return str2; } if (str1.size() <str2.size()) { return str2; } if (str1.size() > str2.size()) { return str1; } if (str1 < str2) { return str2; } else { return str1; } } int main() { int N, M; cin >> N >> M; vector<int>A(M); map<int, int>mp; mp[1] = 2; mp[2] = 5; mp[3] = 5; mp[4] = 4; mp[5] = 5; mp[6] = 6; mp[7] = 3; mp[8] = 7; mp[9] = 6; for (int m = 0;m<M;++m) { cin >> A[m]; } for (int i = 0; i < 11000; ++i) { dp[i] = MINUSINF; } dp[0] = ""; for (int i = 0;i<N;++i) { if (dp[i] == MINUSINF) continue; for (int n = 0;n<A.size();++n) { string strcopy = dp[i]; strcopy += ('0' + A[n]); dp[i + mp[A[n]]] = compare(dp[i + mp[A[n]]], strcopy); } } cout << dp[N]<<endl; return 0; }
1
26,776,300
#include <iostream> #include <cmath> #include <queue> #include <string> #include <algorithm> #include <iomanip> void extract(std::priority_queue<int>& S) { printf("%d\n", S.top()); S.pop(); } int main() { std::ios::sync_with_stdio(false); std::cin.tie(0); std::string s; std::priority_queue<int> S; while (true) { std::cin >> s; if (s == std::string("insert")) { int operand; std::cin >> operand; S.push(operand); } else if (s == std::string("extract")) { extract(S); } else { break; } } return 0; }
#include<iostream> #include<cstdio> #include<algorithm> #define INFTY (1>>30) using namespace std; int H,heap[2000001]; void maxHeapify(int i){ int l,r,largest; l=i*2; r=i*2+1; if(l<=H&&heap[l]>heap[i]) largest=l; else largest=i; if(r<=H&&heap[r]>heap[largest]) largest=r; if(largest!=i){ swap(heap[i],heap[largest]); maxHeapify(largest); } } void increasekey(int i,int key){ if(key<heap[i]) return; heap[i]=key; while(i>1&&heap[i/2]<heap[i]){ swap(heap[i/2],heap[i]); i=i/2; } } void insert(int key){ H++; heap[H]=-INFTY; increasekey(H,key); } int extract(){ int maxv; if(H<1) return -INFTY; maxv=heap[1]; heap[1]=heap[H--]; maxHeapify(1); return maxv; } int main(){ int key; string com; while(1){ cin>>com; if(com=="end") break; if(com=="insert"){ scanf("%d",&key); insert(key); }else printf("%d\n",extract()); } return 0; }
1
69,816,482
#include<iostream> #include<string> using namespace std; int main(){ string str; while(cin>>str,str!="-"){ int n; cin>>n; char str2[1300]; for(int i=0;i<n;i++){ int shu; cin>>shu; for(int i=0;i<shu;i++) str2[str.size()-shu+i]=str[i]; for(int i=0;i<str.size()-shu;i++) str2[i]=str[shu+i]; str2[str.size()]='\0'; str=str2; } cout<<str2<<endl; } return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ while(1){ string s; int m, sum=0; cin>>s; if(s=="-")break; cin>>m; for(int i=0;i<m;i++){ int x; cin>>x; sum+=x; } int n=s.size(); for(int i=0;i<n;i++){ cout<< s[ (i+sum)%n ]; } cout<<endl; } return 0; }
1
11,672,347
#include<iostream> #include<algorithm> using namespace std; main(){ int w,h,x,y,r,flag=0; cin>>w>>h>>x>>y>>r; if(x+r>w || x-r<0 || y+r>h || y-r<0)flag=1; if(flag==1)cout<<"No"<<endl; else cout<<"Yes"<<endl; }
#include<stdio.h> main(){ int W,H,x,y,r; int left,right,top,bottom; scanf("%d %d %d %d %d",&W,&H,&x,&y,&r); left = x - r; right = x + r; top = y + r; bottom = y - r; if(left >= 0 && right <= W && top <= H && bottom >= 0){ printf("Yes\n"); } else { printf("No\n"); } return 0; }
1
45,517,184
#include<iostream> #include<string> #include<cmath> #include<iomanip> using namespace std; const double PI = 3.1415926535; class Point { public: double x; double y; Point(double x=0, double y=0) { this->x = x; this->y = y; } }; void koch(int n, Point a, Point b) { if (n == 0) return; Point s, t, u; double th =PI* 60.0 / 180.0; s.x = (2.0 * a.x + 1.0 * b.x) / 3.0; s.y = (2.0 * a.y + 1.0 * b.y) / 3.0; t.x = (2.0 * b.x + 1.0 * a.x) / 3.0; t.y = (2.0 * b.y + 1.0 * a.y) / 3.0; u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x; u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y; koch(n - 1, a, s); cout << s.x << " " << s.y << endl; koch(n - 1, s, u); cout << u.x << " " << u.y << endl; koch(n - 1, u, t); cout << t.x << " " << t.y << endl; koch(n - 1, t, b); } int main() { cout << setprecision(10); Point a(0, 0), b(100, 0); int n; cin >> n; cout << a.x << " " << a.y << endl; koch(n, a, b); cout << b.x << " " << b.y << endl; return 0; }
#include <stdio.h> #include <math.h> #include <utility> using namespace std; typedef pair<double, double> Point; int n; const double cos60 = cos( M_PI / 3.0 ); const double sin60 = sin( M_PI / 3.0 ); void solve( int i, Point p0, Point p1 ); int main() { Point p0, p1; p0.first = 0.0; p0.second = 0.0; p1.first = 100.0; p1.second = 0.0; scanf("%d", &n); printf("%.10lf %.10lf\n", 0.0, 0.0); solve( 0, p0, p1 ); return 0; } void solve( int i, Point p0, Point p1 ) { if ( i == n ) { printf("%.10lf %.10lf\n", p1.first, p1.second); } else { Point np0, np1, np2; double vx = p1.first - p0.first; double vy = p1.second - p0.second; double ex = vx / 3.0; double ey = vy / 3.0; np0.first = p0.first + ex; np0.second = p0.second + ey; np1.first = np0.first + cos60 * ex - sin60 * ey; np1.second = np0.second + sin60 * ex + cos60 * ey; np2.first = p0.first + 2.0 * ex; np2.second = p0.second + 2.0 * ey; solve( i + 1, p0, np0 ); solve( i + 1, np0, np1 ); solve( i + 1, np1, np2 ); solve( i + 1, np2, p1 ); } }
1
4,973,331
#define _GLIBCXX_DEBUG #include<bits/stdc++.h> #include<algorithm> #define rep(i,n) for (int i = 0;i < (n);i++) #define all(v) v.begin(),v.end() #define dec(n) cout << fixed << setprecision(n); #define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ" #define small "abcdefghijklmnopqrstuvwxyz" using namespace std; using ll = long long; using P = pair<ll,ll>; using vl = vector<ll>; using vvl = vector<vl>; ll gcd(ll a,ll b){ if(b == 0) return a; return gcd(b , a % b); } const ll MOD = 1000000007; const ll MAX = 2000001; ll mod(ll a){ return a % MOD; } ll lcm(ll a,ll b){ return (a*b)/gcd(a,b); } int main(){ ll k; cin >> k; ll ans = 0; queue<ll> q; rep(i,9) q.push(i+1); while(k != 0){ ll now = q.front(); k--; q.pop(); if(k == 0){ ans = now; break; } ll per = now % 10; if(per != 0){ q.push(now*10 + per-1); } q.push(now*10 + per); if(per != 9){ q.push(now*10 + per+1); } } cout << ans << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define sz(x) int(x.size()) #define show(x) {for(auto i: x){cout << i << " ";} cout << endl;} using namespace std; using ll = long long; using P = pair<int, int>; int main() { int K; cin >> K; queue<ll> que; for (int i = 1; i < 10; i++) { que.push(i); } rep(i, K-1) { ll x = que.front(); que.pop(); int first = x % 10; if (first >= 1) que.push(x*10 + first - 1); que.push(x*10 + first); if (first <= 8) que.push(x*10 + first + 1); } ll ans = que.front(); cout << ans << '\n'; return 0; }
1
100,781,352
#include <bits/stdc++.h> using namespace std; #define REP(i,m,n) for(int i=(m); i<(int)(n); i++) #define RREP(i,m,n) for(int i=(int)((n)-1); i>=m; i--) #define rep(i,n) REP(i,0,n) #define rrep(i,n) RREP(i,0,n) #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(),(a).rend() #define fi first #define se second #define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);} template<typename T> string join(const vector<T>&v, string del=", "){ stringstream s; for(auto x : v) s << del << x; return s.str().substr(del.size()); } template<typename T> ostream& operator<<(ostream& o, const vector<T>&v){ if(v.size()) o << "[" << join(v) << "]"; return o; } template<typename T> ostream& operator<<(ostream& o, const vector<vector<T> >&vv){ int l = vv.size(); if(l){ o<<endl; rep(i,l) o << (i==0 ? "[ " : ",\n " ) << vv[i] << (i==l-1 ? " ]" : ""); } return o; } template<typename T1, typename T2> ostream& operator<<(ostream& o, const pair<T1, T2>& p){ return o << "(" << p.first << ", " << p.second << ")"; } inline void _debug(){cerr<<endl;} template<class First, class... Rest> void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);} typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; typedef vector<vl> vvl; const double PI = (1*acos(0.0)); const double EPS = 1e-9; const int INF = 0x3f3f3f3f; const ll INFL = 0x3f3f3f3f3f3f3f3fLL; const ll mod = 1e9 + 7; inline void finput(string filename) { freopen(filename.c_str(), "r", stdin); } vi get_primes(int n){ vi res; int x = 2; while(n >= x*x){ while(n % x == 0){ n /= x; res.push_back(x); } x++; } if(n != 1) res.push_back(n); return res; } int main(){ ios_base::sync_with_stdio(0); int n; cin >> n; map<int,int> mp; REP(i,1,n+1){ auto primes = get_primes(i); for(auto prime : primes) ++mp[prime]; } int c2=0,c4=0,c14=0,c24=0,c74=0; for(auto p : mp){ int cnt = p.se; if(cnt >= 2) c2++; if(cnt >= 4) c4++; if(cnt >= 14) c14++; if(cnt >= 24) c24++; if(cnt >= 74) c74++; } int ans = 0; if(c4 >= 2 && c2 >= 3) ans += c4*(c4-1)/2 * (c2-2); if(c14 >= 1 && c4 >= 2) ans += c14 * (c4-1); if(c24 >= 1 && c2 >= 2) ans += c24 * (c2-1); if(c74 >= 1) ans += c74; cout << ans << endl; return 0; }
#include <iostream> #include <cmath> #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> #define rep(i,n) for(int i = 0; i < n; i++) #define vi vector<int> #define vvi vector<vi> #define pii pair<int, int> #define mod 1000000007 using ll = long long; using namespace std; int cnt(int n, vi &sosu){ int ans = 0; for(int i : sosu){ if(i >= n - 1) ans++; } return ans; } int main(){ int n; cin >> n; vi sosu(n + 1, 0); for(int i = 2; i <= n; i++){ int num = i; for(int j = 2; j <= n; j++){ while(num % j == 0){ num /= j; sosu[j]++; } } } int v5 = cnt(5, sosu), v3 = cnt(3, sosu) - 1; int ans = cnt(75, sosu); ans += cnt(25, sosu) * v3; ans += cnt(15, sosu) * (v5 - 1); ans += v5 * (v5 - 1) / 2 * (v3 - 1); cout << ans << endl; }
1
85,378,327
#include <iostream> #include <iomanip> #include <cassert> #include <cstring> #include <vector> #include <algorithm> #include <string> #include <cmath> #include <limits> #include <queue> #include <unordered_map> #include <list> #include <set> using namespace std; using ll = long long; #define rep_init(i, init, n) for(int i = (init); i < (n); ++i) #define rep(i, n) rep_init(i, 0, n) int main() { string S, T; cin >> S >> T; unordered_map<char, char> table1, table2; string ans = "Yes"; rep(i, S.size()) { if (table1.find(S[i]) == table1.end()) { table1[S[i]] = T[i]; } else { if (table1[S[i]] != T[i]) { ans = "No"; break; } } if (table2.find(T[i]) == table2.end()) { table2[T[i]] = S[i]; } else { if (table2[T[i]] != S[i]) { ans = "No"; break; } } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define all(v) v.begin(), v.end() #define V vector #define P pair typedef long long ll; const int INT_INF = 1e9; const ll INF = 1LL << 30; int main() { string s, t; cin >> s >> t; V<char> v1(100), v2(100); for(int i = 0; i < s.size(); i++){ if(v1[t[i] - 'a'] == 0){ v1[t[i] - 'a'] = s[i]; }else if(v1[t[i] - 'a'] != s[i]){ cout << "No" << endl; return 0; } if(v2[s[i] - 'a'] == 0){ v2[s[i] - 'a'] = t[i]; }else if(v2[s[i] - 'a'] != t[i]){ cout << "No" << endl; return 0; } } cout << "Yes" << endl; }
1
79,487,937
#include <bits/stdc++.h> using namespace std; #define rep(i,b) for(long long i = 0; i < (b); i++) #define all(a) a.begin(),a.end() #define allr(a) a.rbegin(),a.rend() using ll = long long; ll lcm(ll a,ll b){ return (a*b)/(__gcd(a,b)); } void solve() { int n; cin>>n; string a,b; cin>>a>>b; string out=""; int flag=0; int i=0; int j=0; while(i<=n){ if(flag==0){ out=out+a[i]; i++; flag=!flag; } else{ out=out+b[j]; j++; flag=!flag; } } out.resize(2*n); cout<<out; } int main(){ solve(); cout<<endl; }
#include <bits/stdc++.h> #include <vector> #include <algorithm> #include <iostream> using namespace std; int main() { int N; string S, T; cin >> N >> S >> T; if (N==1) { cout << S.at(0) << T.at(0) << endl; } else { for (int i=0; i<N-1; i++) { cout << S.at(i) << T.at(i); } cout << S.at(N-1) << T.at(N-1) << endl; } }
1
621,177
#include<iostream> #include<vector> using namespace std; int main(){ int x,a,b,c,n,f,I; vector<int> y; int dam; while(1){ I=0; f=0; y.clear(); cin >> n >> a >> b >> c >> x; if(n==0&&a==0&&b==0&&c==0&&x==0)break; for(int i=0;i<n;i++){ cin >> dam; y.push_back(dam); } while(1){ if(y[I]==x){ I++; if(I==n){ cout << f << endl; break; } } x=(a*x+b)%c; f++; if(f==10001){ cout << -1 << endl; break; } } } return 0; }
#include <bits/stdc++.h> using namespace std; #define PI 4*atan(1) #define INF 1e8 int dx[4] = {1,0,-1,0}; int dy[4] = {0,1,0,-1}; int main(){ 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 x = X, index = 0, frame = -1; for(int i = 0; i <= 10000; i++){ if(x == Y[index])index++; if(index == N){ frame = i; break; } x = (A * x + B) % C; } cout << frame << endl; } }
1
56,717,617
#include<iostream> using namespace std; int main(){ int x1,y1,x2,y2; cin>>x1>>y1>>x2>>y2; int xdis=(x2-x1); int ydis=(y2-y1); int x3=x2-ydis; int y3=y2+xdis; int x4=x1-ydis; int y4=y1+xdis; cout<<x3<<" "<<y3<<" "<<x4<<" "<<y4; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define MOD_NUMBER 1000000007 template <class T> void vector_print(vector<T> vec) { for (unsigned int i = 0; i < vec.size(); i++) { cout << vec.at(i); if (i < vec.size()-1) { cout << " "; } else if (i == vec.size()-1) { cout << endl; } } } int main() { ll x1, x2, x3, x4, y1, y2, y3, y4; cin >> x1 >> y1 >> x2 >> y2; x3 = x2-(y2-y1); y3 = y2-(x1-x2); x4 = x3-(y3-y2); y4 = y3-(x2-x3); cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl; return 0; }
1
43,086,827
#include <bits/stdc++.h> using namespace std; #define vit vector<int>::iterator #define pb push_back #define ppb pop_back #define mp make_pair #define all(x) (x).begin(), (x).end() #define forn(i, n) for(int i = 0; i < int(n); i++) #define fr first #define sc second #define skip continue #define PI 3.14159265 typedef unsigned long long ull; typedef long long ll; typedef unsigned int ui; typedef long double ld; typedef vector<int> vi; typedef vector<long long> vll; typedef vector<bool> vb; const int INF = 1e9 + 5; const int MAXN = 3e6 + 123; void faster(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } bool cmp(const string& a, const string& b) { return (a + b) < (b + a); } vector<int> Reversed(const vector<int>& s){ vector<int> d = s; reverse(all(d)); return d; } void solve(){ int n,k; cin >> n >> k; ull ans = pow(k-1,n-1); ull cnt = ans * k; cout << cnt; } int main(){ int n=1; while(n--){ solve(); } }
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { ios_base::sync_with_stdio(0);cin.tie(0); int n,k; cin>>n>>k; ll res=k; for(int i=0;i<n-1;++i) res*=(k-1); cout<<res<<'\n'; }
1
79,909,848
#include <iostream> #include <algorithm> using namespace std; long long lcm(long long a, long long b) { return a / __gcd(a, b) * b; } int main() { long long A, B; cin >> A >> B; cout << lcm(A, B) << endl; return 0; }
#include<bits/stdc++.h> #define l(i,a,n)for(int i=a;i<n;i++) #define pb push_back #define in insert #define mp make_pair #define lw(v) sort(v.begin(),v.end()); #define hi(v) sort(v.begin(),v.end(),greater<long long>()); #define all(v) v.begin(),v.end() #define filein freopen ("input.txt", "r", stdin) #define fileout freopen ("output.txt", "w", stdout) using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); long long t,r=1,r1=0,r2=0,k=0,a,b,c=1,m,d=0,n,e,f,x=0,g,p=0,q=0,y=0,z=0; vector<long long>v; vector<long long>u; set<char>s; std::vector<int>::iterator it; string s1,s2,s3,s4; cin>>n>>m; cout<<(n*m)/__gcd(m,n)<<endl; }
1
71,308,271
#include <bits/stdc++.h> using namespace std; int main() { int H, W; cin >> H >> W; vector<vector<char>>a(H, vector<char>(W)); for(int i=0; i<H; i++){ for(int j=0; j<W; j++){ cin >> a.at(i).at(j); } } for(int i=0; i<H; i++){ for(int j=0; j<W; j++){ if(a.at(i).at(j) == '.'){ bool isWhiteRow = true; for(int tj=0; tj<W; tj++){ if(a.at(i).at(tj) == '#'){ isWhiteRow = false; break; } } if(isWhiteRow){ for(int tj=0; tj<W; tj++){ a.at(i).at(tj) = '\0'; } } bool isWhiteColumn = true; for(int ti=0; ti<H; ti++){ if(a.at(ti).at(j) == '#'){ isWhiteColumn = false; break; } } if(isWhiteColumn){ for(int ti=0; ti<H; ti++){ a.at(ti).at(j)='\0'; } } } } } for(int i = 0; i < H; i++){ int charNum = 0; for(int j = 0; j < W; j++){ char out = a.at(i).at(j); if(out != '\0'){ charNum++; cout << a.at(i).at(j); } } if(charNum != 0){ cout << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int H, W; cin >> H >> W; vector<vector<char>> a(H, vector<char>(W)); for (int i=0; i<H; i++){ for(int j=0; j<W; j++){ cin >> a.at(i).at(j); } } vector<bool> row(H), col(W); bool flag_row=false, flag_col=false; for (int i=0; i<H; i++){ for (int j=0; j<W; j++){ if (j==0 && a.at(i).at(j) == '.') flag_row = true; if (a.at(i).at(j) == '#') flag_row = false; } row.at(i) = flag_row; flag_row = false; } for (int i=0; i<W; i++){ for (int j=0; j<H; j++){ if (j==0 && a.at(j).at(i) == '.') flag_col = true; if (a.at(j).at(i) == '#') flag_col = false; } col.at(i) = flag_col; flag_col = false; } for (int i=0; i<H; i++){ for(int j=0; j<W; j++){ if (!(row.at(i) || col.at(j))){ cout << a.at(i).at(j); } } if (!(row.at(i))) cout << endl; } }
1
25,209,589
#include<iostream> #include<cstdio> #include<cmath> using namespace std; int main(){ int a, b, C; double c, S, L, h, rad; cin >> a >> b >> C; double PI = acos(-1); rad = C*PI/180.0; S = a*b*sin(rad)/2.0; c = sqrt(a*a + b*b - 2*a*b*cos(rad)); L = a+b+c; h = 2*S/a; printf("%f\n", S); printf("%f\n", L); printf("%f\n", h); return 0; }
#include "iostream" #include "math.h" int main() { double a, b, C, S, L, h, rad; std::cin >> a >> b >> C; rad = C / 180.0 * 3.14159265358979; S = ((a * b) * sin(rad)) / 2; L = a + b + sqrt((a*a) + (b*b) - (2 * a * b * cos(rad))); h = b * sin(rad); std::cout << std::fixed << S << std::endl << std::fixed << L << std::endl << std::fixed << h << std::endl; return 0; }
1
82,594,886
#include <iostream> using namespace std; int main() { char c; cin >> c; if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o') printf("%s\n", "vowel"); else printf("%s\n", "consonant"); }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i = 0; i < n; i++) #define rep1(i, n) for(int i = 1; i < n+1; i++) #define sort(A) sort(A.begin(),A.end()) #define reverse(A) reverse(A.begin(),A.end()) #define vecmin(A) *min_element(A.begin(),A.end()) #define vecmax(A) *max_element(A.begin(),A.end()) typedef long long ll; int main(){ char c; cin >> c; bool sub1 = c == 'a'; bool sub2 = c == 'e'; bool sub3 = c == 'i'; bool sub4 = c == 'o'; bool sub5 = c == 'u'; if(sub1 || sub2 || sub3 || sub4 || sub5) cout << "vowel" << endl; else cout << "consonant" << endl; }
1
40,622,787
#include <iostream> #include <algorithm> #include <math.h> #include <vector> #include <string> #include <queue> #include <map> #include <utility> #include <iomanip> using namespace std; using ll = long long; #define rep(i,a,b) for(int i=(a); i<(b); i++) #define YES cout << "YES" << endl; #define NO cout << "NO" << endl; #define yes cout << "Yes" << endl; #define no cout << "No" << endl; #define pai 3.14159265358979323846 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() { int n,m; cin >> n >> m; multimap <ll, int> ab; rep(i,0,n) { ll a; int b; cin >> a >> b; ab.insert(make_pair(a,b)); } ll ans =0; for(auto i = ab.begin(); i!= ab.end(); i++) { if (i->second >= m) { ans += m * i->first; break; } else { ans += i->second * i->first; m -= i->second; } } cout << ans << endl; }
#include <iostream> #include <cstdio> #include <string> #include <algorithm> #include <utility> #include <cmath> #include <vector> #include <queue> #include <set> #include <map> #include <numeric> #include <functional> using namespace std; typedef long long ll; typedef vector<ll> vl; typedef vector<vector<ll>> vvl; typedef pair<ll, ll> P; #define rep(i, n) for(ll i = 0; i < n; i++) #define exrep(i, a, b) for(ll i = a; i <= b; i++) #define out(x) cout << x << endl #define exout(x) printf("%.10f\n", x) #define chmax(x, y) x = max(x, y) #define chmin(x, y) x = min(x, y) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define pb push_back #define re0 return 0 const ll mod = 1000000007; const ll INF = 1e16; const ll MAX_N = 100010; int main() { ll n, m; cin >> n >> m; vector<P> p(n); rep(i, n) { ll a, b; cin >> a >> b; p[i] = make_pair(a, b); } sort(all(p)); ll ans = 0; ll cnt = 0; rep(i, n) { ll a = p[i].first; ll b = p[i].second; if(cnt + b > m) { ans += a*(m - cnt); break; } else { ans += a*b; cnt += b; } } out(ans); re0; }
1
11,023,656
#include<bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int sum = 0; for(char c : s) { sum += (c - '0'); } cout << (sum % 9 == 0 ? "Yes" : "No"); return 0; }
#include <iostream> #include <bits/stdc++.h> using namespace std; char a[200010]; int main() { scanf("%s",&a); int sum = 0; int len = strlen(a); for(int i = 0;i < len;i++){ sum += (a[i] - '0'); } if(sum % 9 == 0) printf("Yes\n"); else printf("No\n"); return 0; }
1
90,852,774
#include <cstdio> const int maxn = 1e5+5; inline int max(int a,int b){return a>b?a:b;} inline int min(int a,int b){return a<b?a:b;} int n,m,l[maxn],r[maxn]; int main(){ scanf("%d %d",&n,&m); for(int i=1;i<=m;++i)scanf("%d %d",&l[i],&r[i]); int L = 1,R = n; for(int i=1;i<=m;++i) L = max(l[i],L),R = min(r[i],R); printf("%d",max(0,R-L+1)); return 0; }
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <string> #include <sstream> #include <complex> #include <vector> #include <list> #include <queue> #include <deque> #include <stack> #include <map> #include <set> #include <iomanip> #include <limits> using namespace std; typedef pair<long long, long long> P; vector<P> prime_factorize(long long n) { vector<P> res; for (long long p = 2; p * p <= n; ++p) { if (n % p != 0) continue; int num = 0; while (n % p == 0) { ++num; n /= p; } res.push_back(make_pair(p, num)); } if (n != 1) res.push_back(make_pair(n, 1)); return res; } long long gcd(long long x, long long y) { if (y == 0) { return x; } else { return gcd(y, x % y); } } 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; } const int MOD = 1000000007; typedef long long int ll; #define EPS (1e-7) #define INF (1e9) #define PI (acos(-1)) #define rep(i, n) for (int i = 0; i < (n); i++) 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; } int main() { int N, M; cin >> N >> M; int ans = 0; int minlimit=0, maxlimit=N+1; rep(i,M){ int L, R; cin >> L >> R; minlimit = max(minlimit, L); maxlimit = min(maxlimit, R); } if(maxlimit-minlimit<0){ cout << 0 << endl; return 0; } cout << maxlimit - minlimit + 1 << endl; return 0; }
1
35,059,218
#include <bits/stdc++.h> using namespace std; int main(){ int num; scanf("%d", &num); vector <int> arr(num+1), dp(num+1); for(int i = 1; i <= num; i++){ scanf("%d", &arr[i]); } dp[1] = 0; dp[2] = abs(arr[2] - arr[1]); for(int i = 3; i <= num; i++){ int tempA = abs(arr[i] - arr[i-1]) + dp[i-1]; int tempB = abs(arr[i] - arr[i-2]) + dp[i-2]; dp[i] = min(tempA, tempB); } printf("%d\n", dp[num]); }
#include <bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; vector<int> v(n+1); for(int i=0;i<n;++i){ cin>>v[i]; } vector<int> dp(n+1,INT_MAX); dp[0]=0; for(int i=0;i<n;++i){ for(int j=i+1;j<n && j<=i+2;++j){ dp[j]=min(dp[j],abs(v[j]-v[i])+dp[i]); } } cout<<dp[n-1]; return 0; }
1
15,989,330
#include<bits/stdc++.h> using namespace std; #define Bye return 0 #define ll long long void solve(){ string str; getline(cin, str); int a = 0, b = 0, i = 0; while(str[i] != ' ') a = a*10 + (str[i] - '0'), i++; bool oper = (str[i+1] == '+') ? true : false; i += 3; while(i<str.size()) b = b*10 + (str[i] - '0'), i++; cout<<((oper) ? a + b : a - b)<<endl; } int main() { solve(); Bye; }
#include<iostream> #include<cmath> #include<vector> #include<climits> #include<algorithm> #include<numeric> #include<iomanip> #include<map> #include<set> #include<random> #include<cassert> using namespace std; #define ll long long int #define ld long double const ll Mod = 1000000007; ll CaseN=1; const ld PI = 22/7.0; bool mycmp(string s,string t) { if(s.size()<t.size()) { return true; } return false; } void solve() { ll a,b,ans=0; char ch; cin>>a>>ch>>b; if(ch=='+') { ans = a+b; } else { ans = a-b; } cout<<ans<<endl; CaseN++; return ; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t=1; while(t--) { solve(); } }
1
42,114,807
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define sz(x) int(x.size()) #define show(x) {for(auto i: x){cout << i << " ";} cout << endl;} using namespace std; using ll = long long; using P = pair<int, int>; int main() { string S; cin >> S; bool bl = false; for (char s : S) { if (s == '7') bl = true; } puts(bl ? "Yes" : "No"); return 0; }
#include <stdio.h> int main(){ char arr[4]; scanf ("%[^\n]", arr); for (int i = 0; arr[i] != '\0'; i++) if (arr[i] == '7') return puts ("Yes"), 0; puts ("No"); }
1
97,880,789
#include <algorithm> #include <iostream> #include <cstring> #include <vector> using namespace std; typedef long long ll; typedef pair <ll, ll> pii; const ll MAX_N = 1e5 + 5; ll n, tmp, val; ll Arr[MAX_N]; int main() { ios::sync_with_stdio(false), cin.tie(0); cin >> n; for (int i = 0; i < n; i++) cin >> Arr[i]; sort(Arr, Arr + n); tmp = 0, val = -1; for (int i = 0; i + 1 < n; i++) if (val < min(Arr[i], Arr[n - 1] - Arr[i])) { val = min(Arr[i], Arr[n - 1] - Arr[i]); tmp = Arr[i]; } cout << Arr[n - 1] << " " << tmp << "\n"; return 0; }
#include <iostream> #include <algorithm> using namespace std; int main(void){ int n, a[100000], b; cin >> n; for(int i=0;i<n;i++){ cin >> a[i]; } sort(a, a+n); b = a[0]; for(int i=1;i<n-1;i++){ if(abs(a[i]-a[n-1]/2) <= abs(b-a[n-1]/2))b = a[i]; } cout << a[n-1] << " " << b << endl; }
1
54,222,786