code1
stringlengths
54
12k
code2
stringlengths
65
12k
similar
int64
0
1
__index_level_0__
int64
45
101M
#include <bits/stdc++.h> #if DEBUG template <typename T> void debug(T value) { std::cerr << value; } template <typename T, typename... Ts> void debug(T value, Ts... args) { std::cerr << value << ", "; debug(args...); } #define dbg(...) \ do { \ cerr << #__VA_ARGS__ << ": "; \ debug(__VA_ARGS__); \ cerr << " (L" << __LINE__ << ")" << endl; \ } while (0) #else #define dbg(...) #endif void read_from_cin() {} template <typename T, typename... Ts> void read_from_cin(T& value, Ts&... args) { std::cin >> value; read_from_cin(args...); } #define in(type, ...) \ type __VA_ARGS__; \ read_from_cin(__VA_ARGS__); template <typename T> void write_to_cout(const T& value) { std::cout << value << std::endl; } template <typename T, typename... Ts> void write_to_cout(const T& value, const Ts&... args) { std::cout << value << ' '; write_to_cout(args...); } #define out(...) write_to_cout(__VA_ARGS__); #define all(x) (x).begin(), (x).end() #define rep(i, n) for (int i = 0; i < (int)(n); ++i) using ll = long long; using namespace std; int main() { in(int, n); vector<int> d(n); rep(i, n) cin >> d[i]; sort(all(d)); out(d[n / 2] - d[n / 2 - 1]); }
#include <bits/stdc++.h> typedef long long ll; using namespace std; const int INF = 1e9; const int MOD = 1e9+7; const ll LINF = 1e18; #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) for(int i=0;i<(n);++i) #define REPR(i,n) for(int i=n;i>=0;i--) #define ALL(v) (v.begin(),v.end()) #define COUT(x) cout<<(x)<<endl int main(){ string s; cin >> s; string t = "keyence"; bool flag = false; REP(i,s.size()-7){ string st = s.substr(i,7); if(st==t) flag = true; } FOR(i,1,7){ string st1 = s.substr(0,i); string st2 = s.substr(s.size()-7+i,7-i); if(st1+st2==t) flag = true; } if(flag)COUT("YES"); else COUT("NO"); return 0; }
0
72,088,376
#include <bits/stdc++.h> #warning !!!check the size of arrayss!!! #define INF 2000000000000000005 #define MOD 1000000007 #define newMOD 998244353 #define MAX 300006 #define pi 3.1415926535897932384626433832795 #define ld long double #define ll long long #define int long long #define P(gg) for(auto rax:gg){cout<<rax<<" ";}cout<<endl; #define Need_for_speed(activated) ios_base :: sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL) #define satisfy ll t; cin>> t; while(t--) #define inp(n) int n;cin >> n #define mp make_pair #define pb push_back #define endl "\n" #define x first #define y second #define fore(i,a,b) for(ll i=a;i<b;i++) #define forci(i,n) for(ll i=0;i<n;i++) #define vi vector<ll> #define Endl endl #define lb lower_bound #define ub upper_bound #define pii pair<ll,ll> #define input freopen("input.txt", "r", stdin),freopen("output.txt", "w", stdout) #define time cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n"; using namespace std; ll gcd(ll a, ll b){if (b == 0)return a;return gcd(b, a % b);} int power(int x, unsigned int y, unsigned int m){ if (y == 0) return 1;int p = power(x, y/2, m) % m; p = (p * p) % m; return (y%2 == 0)? p : (x * p) % m;} ll modInverse(int a, int m){int g = gcd(a, m); { return power(a, m-2, m);}} void solve() { string s;cin>>s; ll n = s.length(); ll dp[n+3][2]; memset(dp,0,sizeof dp); dp[0][0]=1; for(ll i=0;i<n;i++) { if(s[i]=='0') { (dp[i+1][1]+=dp[i][1]*3)%=MOD; (dp[i+1][0]+=dp[i][0])%=MOD; } else { ((dp[i+1][1])+=dp[i][1]*3)%=MOD; (dp[i+1][1]+=dp[i][0])%=MOD; (dp[i+1][0] = 2*dp[i][0])%=MOD; } } cout<<(dp[n][0]+dp[n][1])%MOD<<endl; } signed main() { Need_for_speed(activated); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #define debug(var) cerr << (#var) << " = " << (var) << endl; #else #define debug(var) #endif void init() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } const int mod = 1e9+7; vector<int> a[30]; void solve() { int n; string s; cin >> n >> s; for (int i = 0; i < n; ++i) { a[s[i]-'a'].push_back(i); } long long ans = 0; for (int i = 0; i < n; ++i) { int skip = s[i]-'a'; long long cur = 1; for (int j = 0; j < 26; ++j) { if (j == skip) continue; if (a[j].empty()) continue; int x = a[j].size()-(lower_bound(a[j].begin(), a[j].end(), i)-a[j].begin()); if (!x) continue; (cur *= x+1) %= mod; } (ans += cur) %= mod; } printf("%lld", ans); } int main() { init(); int t = 1; while (t--) { solve(); } return 0; }
0
60,653,800
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep_(i, n, m) for (int i = n; i < (int)(m); i++) #define all(v) v.begin(), v.end() #define int long long #define stoi stoll vector<int> prime(int N) { vector<bool> a(N, true); for(int i=1; i<sqrt(N); i++) { if(a[i]) for(int k=2; (i+1)*k-1<N; k++) a[(i+1)*k-1] = false; } vector<int> p; rep(i, N) if(a[i]) p.push_back(i+1); p.erase(p.begin()); return p; } signed main() { int H, N; cin >> H >> N; vector<int> A(N), B(N); rep(i, N) cin >> A[i] >> B[i]; vector<int> dp(H+1, 0); rep(i, H+1) { if(i == 0) continue; int a = dp[i-1] + 100000; rep(j, N) { if(i < A[j]) a = min(a, B[j]); else a = min(a, dp[i-A[j]]+B[j]); } dp[i] = a; } cout << dp[H] << endl; }
#include<iostream> using namespace std; int main() { int m[10000], f[10000], r[10000]; int n = 0; for (;;n++) { cin >> m[n] >> f[n] >> r[n]; if (m[n] == -1 && f[n] == -1 && r[n] == -1) { break; } } for ( int i = 0; i < n; i++) { if (m[i] == -1 || f[i] == -1) { cout << "F" << endl; } else if(m[i] + f[i] >= 80) { cout << "A" << endl; } else if(m[i] + f[i] >= 65){ cout << "B" << endl; } else if(m[i] + f[i] >= 50){ cout << "C" << endl; } else if(m[i] + f[i] >= 30 && r[i] >= 50) { cout << "C" << endl; } else if(m[i] + f[i] >= 30) { cout << "D" << endl; } else { cout << "F" << endl; } } return 0; }
0
98,333,897
#include<bits/stdc++.h> using namespace std; #define FOR(i,l,r) for(long long i=(l);i<(r);++i) #define REP(i,n) FOR(i,0,n) #define REPS(i,n) FOR(i,1,n+1) #define RFOR(i,l,r) for(long long i=(l);i>=(r);--i) #define RREP(i,n) RFOR(i,n-1,0) #define RREPS(i,n) RFOR(i,n,1) #define int long long #define mp make_pair #define pb push_back #define eb emplace_back #define SZ(x) ((int)(x).size()) #define all(x) (x).begin(),(x).end() template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } const int INF=1e18; const int MOD=1e9+7; signed main(){ string s;cin>>s; int n=s.size(); int ans=0; REP(i,n-1)if(s[i]!=s[i+1])ans++; cout<<ans<<endl; }
#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 VVI = vector<vector<int>>; const int INF = 1001001001; const int MOD = 1000000007; template <typename T> void print(const T &v); bool dp[30009][4][1009]; string s; int n; int main() { cin >> n >> s; dp[0][0][0] = true; for (int i = 0; i < n; i++) { for (int j = 0; j <= 3; j++) { for (int k = 0; k < 1000; k++) { if (dp[i][j][k] == false) { continue; } dp[i + 1][j][k] = true; if (j <= 2) { dp[i + 1][j + 1][k * 10 + (s[i] - '0')] = true; } } } } int cnt = 0; for (int i = 0; i < 1000; i++) { if (dp[n][3][i] == true) cnt++; } cout << cnt << endl; return 0; } template <typename T> void print(T const &v) { for (int i = 0; i < v.size(); i++) { if (i) cout << " "; cout << v[i]; } cout << endl; }
0
73,395,419
#include <bits/stdc++.h> using namespace std; int a, b, c, d; int main() { cin >> a >> b >> c >> d; int ab = a + b; int cd = c + d; if (ab > cd) { cout << "Left" << endl; } else if (ab < cd) { cout << "Right" << endl; } else { cout << "Balanced" << endl; } return 0; }
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> P; typedef pair<int, P> P1; typedef tuple<int, int, int> T; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; typedef vector<P> vp; typedef vector<tuple<int, int, int>> vt; #define fr first #define sc second #define mp make_pair #define pb push_back #define rep(i, x) for (int i = 0; i < x; i++) #define rep1(i, x) for (int i = 1; i <= x; i++) #define srep(i, s, x) for (int i = s; i < x; i++) #define rrep(i, x) for (int i = x - 1; i >= 0; i--) #define rrep1(i, x) for (int i = x; i > 0; i--) #define rsrep(i, s, x) for (int i = x - 1; i >= s; i--) #define maxs(x, y) (x = max(x, y)) #define mins(x, y) (x = min(x, y)) #define limit(x, l, r) max(l, min(x, r)) #define lims(x, l, r) (x = max(l, min(x, r))) #define sor(v) sort(v.begin(), v.end()) #define rev(s) reverse(s.begin(), s.end()) #define lb(vec, a) lower_bound(vec.begin(), vec.end(), a) #define ub(vec, a) upper_bound(vec.begin(), vec.end(), a) #define uniq(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end()) #define mp1(a, b, c) P1(a, P(b, c)) #define dame \ puts("-1"); \ return 0 #define yn \ puts("Yes"); \ else puts("No") #define YN \ puts("YES"); \ else puts("NO") template <typename A, typename B> string to_string(pair<A, B> p); template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p); template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p); string to_string(const string &s) { return '"' + s + '"'; } string to_string(const char *s) { return to_string((string)s); } string to_string(bool b) { return (b ? "true" : "false"); } string to_string(vector<bool> v) { bool first = true; string ret = "{"; for (int i = 0; i < static_cast<int>(v.size()); i++) { if (!first) { ret += ", "; } first = false; ret += to_string(v[i]); } ret += "}"; return ret; } template <size_t N> string to_string(bitset<N> v) { string ret = ""; for (size_t i = 0; i < N; i++) { ret += static_cast<char>('0' + v[i]); } return ret; } template <typename A> string to_string(A v) { bool first = true; string ret = "{"; for (const auto &x : v) { string s = to_string(x); if (!first) { ret += ", "; } if (s[0] == '{') { s = "\n" + s; } first = false; ret += s; } if (ret[ret.size() - 1] == '}') { ret += "\n}"; } else { ret += "}"; } return ret; } template <typename A, typename... Lest> string to_string(A *v, int n, Lest... L) { bool first = true; string ret = "{"; rep(i, n) { auto x = v[i]; string s = to_string(x, L...); if (!first) { ret += ", "; } if (s[0] == '{') { s = "\n" + s; } first = false; ret += s; } if (ret[ret.size() - 1] == '}') { ret += "\n}"; } else { ret += "}"; } return ret; } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")"; } template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")"; } void name_disp(string s) { cerr << "-------" << endl; cerr << s << ": " << endl; } void val_disp() { cerr << endl; } template <typename First, typename... Lest> void val_disp(First F, Lest... L) { cerr << to_string(F) << endl; val_disp(L...); } template <typename A, typename... Lest> void val_disp(A *v, Lest... L) { cerr << to_string(v, L...) << endl; val_disp(); } #define disp(...) \ name_disp(#__VA_ARGS__); \ val_disp(__VA_ARGS__) #define adisp(a, ...) \ name_disp(#a); \ val_disp(a, __VA_ARGS__) #ifdef int const ll INF = 1002003004005006007ll; #else const int INF = 1002003004; #endif const int M = 100000000; const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}; const int dir_8[8][2] = {{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}}; signed main() { int m, k; scanf("%d%d", &m, &k); if (m == 0) { if (k == 0) { printf("0 0\n"); return 0; } else { dame; } } else if (m == 1) { if (k == 0) { printf("0 0 1 1\n"); return 0; } else { dame; } } else { int l = pow(2, m); if (k == 0) { bool first = true; rep(i, l) { if (!first) { printf(" "); } first = false; printf("%d %d", i, i); } printf("\n"); return 0; } else if (k > l - 1) { dame; } else { vi vec; rrep(i, l) { if (i != k) vec.pb(i); } vec.pb(k); rep(i, l) { if (i != k) vec.pb(i); } vec.pb(k); bool fi = true; rep(i, l * 2) { if (!fi) { printf(" "); } fi = false; printf("%d", vec[i]); } printf("\n"); return 0; } } return 0; };
0
54,130,192
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <set> #include <string> #include <vector> #define rep(i, n) for(int i = 0; i < (int)(n); i++) using ll = long long; using namespace std; double average(double a, double b) { return (a + b) / 2.0; } int main() { int n; cin >> n; vector<double> v; double temp; rep(i, n) { cin >> temp; v.push_back(temp); } sort(v.begin(), v.end()); double ans = v[0]; rep(i, n) { ans = average(ans, v[i]); } cout << fixed << setprecision(15) << ans << endl; }
#include<iostream> #include<map> #include<set> #include<string> #include<algorithm> #include<cmath> #include<vector> #include<queue> #include<stack> #include<limits> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef int itn; const int inf = numeric_limits<int>::max() /4; const ll linf = numeric_limits<ll>::max() /4; const ull ulinf = numeric_limits<ull>::max()/4; const double pi = acos(-1); const int dx[4]={1,0,-1,0}; const int dy[4]={0,1,0,-1}; const int dx8[8]={-1,0,1,-1,1,-1,0,1}; const int dy8[8]={-1,-1,-1,0,0,1,1,1}; #define p_queue(i) priority_queue<i> #define rp_queue(i) priority_queue<i, vector<i>, greater<i>> #define P(p) cout<<(p)<<endl #define rep(i,m,n) for(int i = (m); i < (int)(n); i++) #define mod(i) ((i)%(ll)(1e9 + 7)) #define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5)))) #define rsort(a,b,c) sort(a, b, greater<c>()) #define vsort(v) sort(v.begin(), v.end()); #define rvsort(v) sort(v.end(), v.begin()); #define ft first #define sd second #define pb push_back #define it insert #define sz(x) ((int)(x).size()) #define lb(a,n,k) (lower_bound(a,a+n,k) - a) #define vlb(a,k) (lower_bound(a.begin(),a.end(),k) - a.begin()) #define YES cout<<"YES"<< endl #define NO cout<<"NO"<<endl #define Yes cout<<"Yes"<<endl #define No cout<<"No"<<endl #define yes cout<<"yes"<<endl #define no cout<<"no"<<endl #define ret return ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;} 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; } int main(){ int n; cin >> n; int sum = -n; set<int> s; int i = 1; while(sum < 0){ sum += i; s.it(i); i++; } s.erase(sum); for(auto ite:s)P(ite); return 0; }
0
77,568,926
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0; i<(n); i++) #define all(n) begin(n),end(n) using ll = long long; using P = pair<int,int>; int main() { int n; cin >> n; deque<int> q; rep(i,n) { int a; cin >> a; if(i%2==0) q.push_back(a); else q.push_front(a); } if(n&1){ while(!q.empty()){ cout << q.back() << " "; q.pop_back(); } } else { while(!q.empty()){ cout << q.front() << " "; q.pop_front(); } } cout << endl; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; constexpr int Inf = 2000000010; constexpr ll INF= 2000000000000000000; constexpr ll MOD = 1000000007; const double PI = 3.1415926535897; typedef pair<int,int> P; typedef pair<int,P> PP; 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; } ll mod(ll val, ll M) { ll res = val % M; if(res < 0) { res += M; } return res; } template<typename T> T RS(T N, T P, T M){ if(P == 0) { return 1; } if(P < 0) { return 0; } if(P % 2 == 0){ ll t = RS(N, P/2, M); if(M == -1) return t * t; return t * t % M; } if(M == -1) { return N * RS(N,P - 1,M); } return N * RS(N, P-1, M) % M; } int main() { int N; cin >> N; vector<char> vec(2 * N); for(int i = 0;i < 2 * N;i++) { cin >> vec.at(i); } vector<int> cnt(2 * N); int L = 1; int R = 0; for(int i = 0;i < 2 * N - 1;i++) { if(vec.at(i) != vec.at(i + 1)) { cnt.at(i + 1) = cnt.at(i); } else { cnt.at(i + 1) = 1 - cnt.at(i); } if(cnt.at(i + 1) == 0) { L++; } else { R++; } } bool cnt2 = true; if(vec.at(0) == 'W' || vec.at(2 * N - 1) == 'W' || cnt.at(2 * N - 1) == 0 || L != R) { cnt2 = false; } if(cnt2 == false) { cout << 0 << endl; } else { ll ret = 1; ll Lcnt = 0; for(int i = 0;i < 2 * N;i++) { if(cnt.at(i) == 0) { Lcnt++; } else { ret *= Lcnt; Lcnt--; ret %= MOD; } } ll cnt3 = 1; for(ll i = 0;i < N;i++) { cnt3 *= i + 1; cnt3 %= MOD; } cout << ret * cnt3 % MOD << endl; } }
0
93,077,561
#include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define pii pair<int,int> #define fi first #define se second #define int long long #define pb push_back #define mod 1000000007 #define pll pair<long long,long long> using namespace std; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; long long power(long long a,long long b){ long long ans=1; while(b>0){ if(b&1){ans=(ans*a)%mod;} a=(a*a)%mod; b>>=1; } return ans; } int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); string s,t; cin>>s>>t; int n=s.size(),m=t.size(); int z=INT_MAX; for(int i=0;i<=n-m;i++){ int k=0,x=0; for(int j=i;j<i+m;j++){ if((t[k]-'a')!=(s[j]-'a'))x++; k++; } z=min(z,x); } cout<<z; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vll = vector<long long>; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; constexpr long long mod = 1000000007; #define rep(i, n) for (int i = 0; i < n; i++) int main() { ios::sync_with_stdio(false); cin.tie(0); string s; cin >> s; int l = 0, r = s.size() - 1; bool b = true; int cnt = 0; while (l <= r) { if (s[l] == s[r]) { l++; r--; } else { if (s[l] == 'x' && s[r] != 'x') { l++; cnt++; } else if (s[l] != 'x' && s[r] == 'x') { r--; cnt++; } else { b = false; break; } } } if (b) { cout << cnt << endl; } else { cout << -1 << endl; } }
0
68,427,996
#include <bits/stdc++.h> using namespace std; #define int long long const int INF = 1e18; signed main() { int n; while ( cin >> n, n ) { vector<int> a(n); for ( int i = 0; i < n; i++ ) cin >> a[i]; int ans = INF; sort(a.begin(), a.end()); for ( int i = 1; i < n; i++ ) { ans = min(ans, a[i]-a[i-1]); } cout << ans << endl; } return 0; }
#include <bits/stdc++.h> #define rep(i,n) for (int i=0; i<(n); ++i) using namespace std; using ll = long long; using P = pair<int,int>; ll x[100010]; int main(){ int n; ll k; cin>>n>>k; rep(i,n){ int a,b; cin>>a>>b; x[a]+=b; } ll cnt=0; rep(i,100010){ cnt+=x[i]; if(cnt>=k){ cout<<i<<endl; return 0; } } }
0
38,813,245
#include <bits/stdc++.h> using namespace std; struct Fast {Fast() {std::cin.tie(0); ios::sync_with_stdio(false);}} fast; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using pii = pair<int, int>; using vll = vector<long long>; using pll = pair<ll, ll>; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(x) (x).begin(),(x).end() #define pb push_back #define mp make_pair #define F first #define S second #define MOD 1000000007 const int INF = 1e9; int main() { int K; cin >> K; vi d(K, INF); d[1] = 1; deque<pii> q; q.push_front(pii(1, 1)); while (!q.empty()) { pii val = q.front(); q.pop_front(); int s, dist; tie(s, dist) = val; if (d[(s + 1) % K] > dist + 1) { d[(s + 1) % K] = dist + 1; q.push_back(pii((s + 1) % K, dist + 1)); } if (d[(10 * s) % K] > dist) { d[(10 * s) % K] = dist; q.push_front(pii((10 * s) % K,dist)); } } cout << d[0] << endl; }
#include <iostream> #include <algorithm> #include <string> #include <string.h> #include <stdlib.h> #include <math.h> #include <vector> #include <queue> #include <stack> #include <cmath> #include <map> #include <iomanip> #include <set> #include <ctime> #include <tuple> #include <bitset> #include <assert.h> #include <deque> using namespace std; typedef long long ll; #define fi first #define se second #define rep(i, n) for (ll i = 0; i < n; i++) #define debugA() cerr << "AAAAA" << endl #define debug_() cerr << "-------------" << endl #define debug(x) cerr << #x << ": " << x << endl #define debug_vec(v) \ for (int i = 0; i < v.size(); i++) \ { \ cout << v[i] << " "; \ } \ cout << endl; using Graph = vector<vector<int>>; int main() { int n, k; cin >> n >> k; if (k > (n - 1) * (n - 2) / 2) { cout << "-1" << endl; return 0; } int m = (n - 1) + (n - 1) * (n - 2) / 2 - k; cout << m << endl; for (int i = 2; i <= n; i++) { cout << "1 " << i << endl; } int node = (n - 1) * (n - 2) / 2 + 1; for (int i = 2; i <= n; i++) { for (int j = i + 1; j <= n; j++) { node--; if (node == k) { return 0; } if (i == j) { continue; } cout << i << " " << j << endl; } } return 0; }
0
88,134,176
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #define int long long using namespace std; const int N = 1e3 + 5; int read() { int x = 0, f = 1; char ch; while(! isdigit(ch = getchar())) (ch == '-') && (f = -f); for(x = ch ^ 48; isdigit(ch = getchar()); x = (x << 3) + (x << 1) + (ch ^ 48)); return x * f; } template <class T> T Abs(T a) { return a > 0 ? a : -a; } template <class T> T Max(T a, T b) { return a > b ? a : b; } template <class T> T Min(T a, T b) { return a < b ? a : b; } char s[N]; int n, m, x[N], y[N], len[N]; signed main() { n = read(); for(int i = 1; i <= n; ++ i) x[i] = read(), y[i] = read(); int tmp = Abs(x[1] + y[1]) & 1; for(int i = 2; i <= n; ++ i) if((Abs(x[i] + y[i]) & 1) != tmp) return puts("-1"), 0; len[1] = 1; m = 1; printf("%d\n1", 32 - tmp); if(tmp) for(int i = 1; i <= 30; ++ i) printf(" %d", len[++ m] = (1 << i)); else for(int i = 0; i <= 30; ++ i) printf(" %d", len[++ m] = (1 << i)); puts(""); for(int i = 1, nx, ny; i <= n; ++ i) { nx = 0; ny = 0; for(int j = m, dx, dy; j; -- j) { dx = x[i] - nx; dy = y[i] - ny; if(Abs(dx) > Abs(dy)) { if(dx > 0) nx += len[j], s[j] = 'R'; else nx -= len[j], s[j] = 'L'; } else { if(dy > 0) ny += len[j], s[j] = 'U'; else ny -= len[j], s[j] = 'D'; } } printf("%s\n", s + 1); } return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define all(v) (v).begin(), (v).end() #define rep(i,n) for(int i=0;i<n;++i) #define rep1(i,n) for(int i=1;i<n;++i) #define FOR(i, m, n) for(int i = m; i < n; i++) #define EPS (1e-7) #define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); typedef pair<ll, ll> P; typedef vector<ll> vl; typedef vector<vector<ll> > vvl; typedef vector<vector<vector<ll> > > vvvl; ll MOD = 1000000007; const long long L_INF = 1LL << 60; const int INF = 2147483647; const double PI = acos(-1); 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;} template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;} const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1}; const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1}; ll XOR(ll a){ if(a % 4 == 1)return 1; else if(a % 4 == 3)return 0; else if(a == 0)return 0; else return (XOR(a-1)^a); } signed main() { gearup; int n; cin >> n; double res = 0.0; rep(i,n){ double x; string s; cin >> x >> s; if(s=="BTC")res+=x*380000.0; else res+=x; } cout << fixed << setprecision(6) << res << endl; }
0
54,311,994
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d; cin >> a >> b >> c >> d; cout << max({1ll*a*c, 1ll*a*d, 1ll*b*c, 1ll*b*d}); return 0; }
#pragma GCC optimize("O3") #include <bits/stdc++.h> #define ll long long #define rep(i,n) for(ll i=0;i<(n);i++) #define pll pair<ll,ll> #define pq priority_queue #define pb push_back #define eb emplace_back #define fi first #define se second #define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0); #define lb(c,x) distance(c.begin(),lower_bound(all(c),x)) #define ub(c,x) distance(c.begin(),upper_bound(all(c),x)) 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;} const ll INF=1e18; int main(){ ll N,M,R; cin >> N >> M >> R; vector<ll> r(R); rep(i,R){ cin >> r[i]; r[i]--; } sort(r.begin(),r.end()); vector<vector<ll>> d(N,vector<ll>(N,INF)); rep(i,M){ ll a,b,c; cin >> a >> b >> c; a--; b--; d[a][b]=c; d[b][a]=c; } rep(k,N){ rep(i,N){ rep(j,N){ d[i][j]=min(d[i][j],d[i][k]+d[k][j]); } } } ll ans=INF; do{ ll sum=0; rep(i,R-1){ sum+=d[r[i]][r[i+1]]; } ans=min(ans,sum); }while(next_permutation(r.begin(),r.end())); cout << ans << endl; }
0
14,468,295
#include <bits/stdc++.h> #if DEBUG template <typename T> void debug(T value) { std::cerr << value; } template <typename T, typename... Ts> void debug(T value, Ts... args) { std::cerr << value << ", "; debug(args...); } #define dbg(...) \ do { \ cerr << #__VA_ARGS__ << ": "; \ debug(__VA_ARGS__); \ cerr << " (L" << __LINE__ << ")" << endl; \ } while (0) #else #define dbg(...) #endif void read_from_cin() {} template <typename T, typename... Ts> void read_from_cin(T& value, Ts&... args) { std::cin >> value; read_from_cin(args...); } #define in(type, ...) \ type __VA_ARGS__; \ read_from_cin(__VA_ARGS__); template <typename T> void write_to_cout(const T& value) { std::cout << value << std::endl; } template <typename T, typename... Ts> void write_to_cout(const T& value, const Ts&... args) { std::cout << value << ' '; write_to_cout(args...); } #define out(...) write_to_cout(__VA_ARGS__); #define all(x) (x).begin(), (x).end() #define rep(i, n) for (int i = 0; i < (int)(n); ++i) using ll = long long; using namespace std; int main() { in(string, s, t); out(t+s); }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define debug(x) cerr << #x << ": " << x << endl; #define line() cerr << "---------------" << endl; char board[30][30]; bool visited[30][30]; int H, W; int dx[] = {0, 0, 1, -1}; int dy[] = {1, -1, 0, 0}; void dfs(int x, int y) { for (int i = 0; i < 4; i++) { int nx = x + dx[i], ny = y + dy[i]; if (nx < 0 || nx >= H || ny < 0 || ny >= W) continue; if (board[nx][ny] == '#') continue; if (visited[nx][ny]) continue; visited[nx][ny] = true; dfs(nx, ny); } } int main() { while (cin >> W >> H, W || H) { memset(visited, false, sizeof(visited)); int sx = 0, sy = 0; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { cin >> board[i][j]; if (board[i][j] == '@') { sx = i, sy = j; } } } visited[sx][sy] = true; dfs(sx, sy); int ans = 0; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if (visited[i][j]) ans++; } } cout << ans << endl; } return 0; }
0
45,300,753
#include<bits/stdc++.h> #define forr(i, a, b) for(int i = (a); i < (b); i++) #define rep(i,n) for(int i = 0; i < (n); i++) #define rrep(i,n) for(int i = 1; i <= (n); i++) #define ALL(a) (a.begin()),(a.end()) using namespace std; typedef long long ll; typedef pair<int,int> P; typedef pair<ll, ll> LP; const ll LINF = 1LL<<60; const int INF = 1001001001; const int MOD = 1000000007; int main() { vector<int> odd, even; rep(i, 3) { int a; cin >> a; if(a % 2 == 0) even.push_back(a); else odd.push_back(a); } int ans = 0; if(even.size() == 2) { ans++; rep(i, even.size()) even[i]++; } if(even.size() == 1) { ans++; rep(i, odd.size()) odd[i]++; } int maxv = -1; for(auto x : even) maxv = max(x, maxv); for(auto x : odd) maxv = max(x, maxv); for(auto x : even) ans += (maxv - x) / 2; for(auto x : odd) ans += (maxv - x) / 2; cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define inf 1000000000 #define INF 1000000000000000 #define ll long long #define ull unsigned long long #define M (int)(1e9+7) #define P pair<int,int> #define PLL pair<ll,ll> #define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++) #define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--) #define rep(i,n) FOR(i,0,n) #define rrep(i,n) RFOR(i,n,0) #define all(a) a.begin(),a.end() #define IN(a,n) rep(i,n){ cin>>a[i]; } const int vx[4] = {0,1,0,-1}; const int vy[4] = {1,0,-1,0}; #define PI 3.14159265 #define F first #define S second #define PB push_back #define EB emplace_back #define int ll void init(){ cin.tie(0); ios::sync_with_stdio(false); } int fac[310000]; int inv(int x){ if(x==1) return 1; return (M-M/x)*inv(M%x)%M; } int comb(int n,int k){ int x=(fac[k]*fac[n-k])%M; return (fac[n]*inv(x))%M; } int fac_init(int n){ fac[0]=1; FOR(i,1,n+1){ fac[i]=fac[i-1]*i; fac[i]%=M; } } main(){ int n; cin>>n; int c[110000]={}; int r,s; fac_init(n+2); rep(i,n+1){ int a; cin>>a; if(c[a]){ r=c[a]; s=i; }else{ c[a]=i+1; } } r--; s=n-s; FOR(k,1,n+2){ int res=comb(n+1,k); if(r+s>=k-1) res-=comb(r+s,k-1); cout<<(res+M)%M<<endl; } }
0
61,640,502
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define eb emplace_back #define mt make_tuple #define all(x) (x).begin(), (x).end() #define MOD 1000000007 typedef long long ll; typedef pair <int, int> ii; typedef pair <ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vll; typedef long double ld; const ll INF=LLONG_MAX; const int mxn=101; int a[mxn]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; for(int i=0; i<n; i++)cin >> a[i]; sort(a,a+n); cout << a[n-1]-a[0] << endl; }
#include<iostream> #include<vector> int main(){ int h,w,m; std::cin>>h>>w>>m; std::vector<int> yList(m); std::vector<int> xList(m); for(int i=0; i< m; i++) std::cin>>yList[i]>>xList[i]; std::vector<long long> yCount(h, 0); std::vector<long long> xCount(w, 0); for(int i=0; i<m; i++){ yCount[yList[i]-1]++; xCount[xList[i]-1]++; } long long maxX=0; long long maxY=0; for(int i=0; i<w; i++) if(maxX< xCount[i]) maxX= xCount[i]; for(int i=0; i<h; i++) if(maxY< yCount[i]) maxY= yCount[i]; std::vector<int> maxXIdx; std::vector<int> maxYIdx; for(int i=0; i< w; i++) if(xCount[i] == maxX) maxXIdx.push_back(i); for(int i=0; i< h; i++) if(yCount[i] == maxY) maxYIdx.push_back(i); long long duplicateCount= 0; long long duplicateMax= maxXIdx.size() * maxYIdx.size(); for(int i=0; i<m; i++){ bool isExistX= false; bool isExistY= false; auto itrX = std::lower_bound(maxXIdx.begin(), maxXIdx.end(), xList[i]-1); isExistX= (itrX!= maxXIdx.end() && *itrX == xList[i]-1); auto itrY = std::lower_bound(maxYIdx.begin(), maxYIdx.end(), yList[i]-1); isExistY= (itrY!= maxYIdx.end() && *itrY == yList[i]-1); if(isExistX && isExistY) duplicateCount++; } long long ans = maxX + maxY + ((duplicateCount< duplicateMax)? 0 : -1); std::cout<<ans<<std::endl; return 0; }
0
66,236,644
#include <bits/stdc++.h> #define sc(x) scanf("%d", &x) #define pr(x) printf("%d\n", x) #define lowbit(x) (x & -x) #define ll long long #define N 100010 #define memset(x) memset(x, 0, sizeof(x)) using namespace std; int n, a[N], f[N][35], l, q; int main() { sc(n); for (int i = 1; i <= n; i++) sc(a[i]); sc(l); for (int i = 1; i <= n; i++) { int id = (int)(upper_bound(a + 1, a + n + 1, a[i] + l) - a - 1); f[i][0] = id; } for (int j = 1; j <= 30; ++j) for (int i = 1; i <= n; ++i) f[i][j] = f[f[i][j - 1]][j - 1]; sc(q); while (q--) { int x, y; sc(x); sc(y); if (x > y) swap(x, y); int sum = 1; for (int i = 30; i >= 0; i--) if (f[x][i] < y) { sum += 1 << i; x = f[x][i]; } printf("%d\n", sum); } return 0; }
#include <iostream> void show_ret(int home[][10], bool use_partition) { for(int i= 0; i < 3; i++) { for(int j = 0; j < 10; j++) { std::cout << " " << home[i][j]; } std::cout << std::endl; } if(use_partition) std::cout << "####################" << std::endl; } int main(int argc, char *argv[]) { int home1[3][10] = {{0}}; int home2[3][10] = {{0}}; int home3[3][10] = {{0}}; int home4[3][10] = {{0}}; int n, b, f, r, v = 0; std::cin >> n; for(int i = 0; i < n; i++) { std::cin >> b >> f >> r >> v; switch(b) { case 1: home1[f-1][r-1] += v; break; case 2: home2[f-1][r-1] += v; break; case 3: home3[f-1][r-1] += v; break; case 4: home4[f-1][r-1] += v; break; } } show_ret(home1, true); show_ret(home2, true); show_ret(home3, true); show_ret(home4, false); return 0; }
0
79,901,819
#include <bits/stdc++.h> #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 INF 2e9 #define ALL(v) v.begin(), v.end() using namespace std; typedef long long ll; vector<pair<ll, ll> > prime_factorize(ll N) { vector<pair<ll, ll> > res; for (ll a = 2; a * a <= N; ++a) { if (N % a != 0) continue; ll ex = 0; while (N % a == 0) { ++ex; N /= a; } res.push_back({a, ex}); } if (N != 1) res.push_back({N, 1}); return res; } int main() { ll N; cin >> N; int ans = 0; const auto &res = prime_factorize(N); ll z; for (auto p : res) { z = 1; for(int i = 1; i <= p.second ; i++){ z *= p.first; if(N % z == 0){ ans++; N /= z; } } } cout << ans <<endl; }
#include <bits/stdc++.h> using namespace std; #define _GLIBCXX_DEBUG #define rep(i,n) for(int i=0; i<(n); i++) #define all(n) begin(n),end(n) using ll = long long; using P = pair<int,int>; int main() { int a, b; string s; cin >> a >> b >> s; if(s.size()!=a+b+1) {cout << "No" << endl; return 0;} if(s[a]!='-') {cout << "No" << endl; return 0;} rep(i,s.size()){ if(i==a) continue; bool ok = false; if(s[i]>='0' && s[i]<='9') ok = true; if(!ok) { cout << "No" << endl; return 0; } } cout << "Yes" << endl; return 0; }
0
43,871,500
#include <iostream> using namespace std; int main() { int W,H,x,y,r; cin >> W >> H >> x >> y >> r; int maxX,minX,maxY,minY; maxX = x + r; minX = x - r; maxY = y + r; minY = y - r; if(maxX > W || minX < 0 || maxY > H || minY < 0) { cout << "No" << endl; } else { cout << "Yes" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MAXN = 100 * 1000 + 100; vector <int> adj[MAXN]; bool p = true; int good[MAXN], mark[MAXN], cnt[3]; void dfs(int v, bool b) { mark[v] = true; good[v] = b; for(int i : adj[v]) { if(!mark[i]) dfs(i, !b); else if(good[i] == good[v]) p = false; } } int main() { int n, m; cin >> n >> m; for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; a--; b--; adj[a].push_back(b); adj[b].push_back(a); } for (int i = 0; i < n; i++) if (!mark[i]) { if (!adj[i].size()) { cnt[2]++; continue; } p = true; dfs(i, 0); cnt[p]++; } cerr << cnt[0] << ' ' << cnt[1] << ' ' << cnt[2] << endl; ll ans = (ll)cnt[1] * cnt[1] * 2 + (ll)cnt[0] * cnt[1] * 2; ans += (ll)cnt[2] * n * 2 - (ll)cnt[2] * cnt[2]; ans += cnt[0] * cnt[0] * 2 - cnt[0] * cnt[0]; cout << ans << endl; }
0
56,719,080
#include <iostream> unsigned int elevations[100002]; bool reached[100002] = {false}; int main() { int n, m, a, b; std::cin >> n >> m; for (int i = 0; i < n; ++i) { std::cin >> elevations[i + 1]; } int good = n; for (int i = 0; i < m; ++i) { std::cin >> a >> b; if (elevations[a] > elevations[b]) { if (!reached[b]) { good -= 1; reached[b] = true; } } else if (elevations[a] == elevations[b]) { if (!reached[a]) { good -= 1; reached[a] = true; } if (!reached[b]) { good -= 1; reached[b] = true; } } else if (!reached[a]){ good -=1; reached[a] = true; } } std::cout << good; return 0; }
#include <iostream> #include <algorithm> #include <vector> #include <set> #include <map> #include <unordered_map> #include <unordered_set> #include <bitset> #include <chrono> #include <ctime> #include <queue> #include <math.h> #include <deque> #include <stack> #include <iomanip> #include <assert.h> #include <stdio.h> #include <cstring> #include <random> using namespace std; #define int long long #define ld long double #define ull unsigned long long #define endl '\n' #define try tr #define pii pair<int, int> #define ti tuple <int, int, int> #define vi vector <int> #define vpi vector <pii> #define umap unordered_map #define uset unordered_set #define left left11 #define right right11 #define all(c) (c).begin(), (c).end() #define pb push_back #define sqr(a) ((a) * (a)) #define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define fs first #define sc second ld TL = 1.0; bool is_tl = 0; int CALLS = 0; inline bool IS() { if (++CALLS == 1000) { CALLS = 0; is_tl |= clock() > (TL - 0.1) * CLOCKS_PER_SEC; } return is_tl; } template<typename T1, typename T2> inline void amin(T1 &a, T2 b) { if (a > b) a = b; } template<typename T1, typename T2> inline void amax(T1 &a, T2 b) { if (a < b) a = b; } template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> &p) { os << p.first << ' ' << p.second << endl; return os; } template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; } template<typename T> ostream &operator<<(ostream &os, vector<T> &v) { for (auto &u : v) os << u << ' '; os << endl; return os; } mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); const int N = 1e6 + 7, NS = 2e3 + 7, lg = 19, sq = 550, inf = 1e9 + 7, SM = 51; const ld eps = 1e-9; void solve() { int n, k, sum = 0, cur = 0, ans = 0; cin >> n >> k; vi a(n); for (int i = 0; i < n; i++) { cin >> a[i]; if(a[i] > 0) sum += a[i]; } for (int i = 0; i < k; i++) { if(a[i] > 0) sum -= a[i]; cur += a[i]; } amax(ans, max(0ll, cur) + sum); for (int i = k; i < n; i++) { if(a[i] > 0) sum -= a[i]; cur += a[i]; if(a[i - k] > 0) sum += a[i - k]; cur -= a[i - k]; amax(ans, max(0ll, cur) + sum); } cout << ans; } signed main() { fast solve(); }
0
85,214,978
#include <iostream> using namespace std; int main(void){ int a; int b; std::cin >> a >> b; if(a < b) { std::cout << "a < b" << std::endl; } else if(a > b) { std::cout << "a > b" << std::endl; } else if(a == b) { std::cout << "a == b" << std::endl; } }
#include <iostream> using namespace std; void RotateDice(int* a,int n) { int c = a[0]; a[0] = a[n]; a[n] = a[5]; a[5] = a[5 - n]; a[5 - n] = c; } int main() { int a[6], q, top, front; for (int i = 0; i < 6; i++) { cin >> a[i]; } cin >> q; for (int i = 0; i < q; i++) { cin >> top >> front; for (int j = 0; j < 4;j++) { if(a[1] == front) { break; } RotateDice(a, 1); } if (a[1] != front) { RotateDice(a, 3); for (int j = 0; j < 4; j++) { if(a[1] == front) { break; } RotateDice(a, 1); } } for (int j = 0; j < 4; j++) { if (a[0] == top) { break; } RotateDice(a, 3); } cout << a[2] << endl; } return 0; }
0
73,102,049
#include<cstdio> int main(){ int A, B; scanf("%d %d", &A, &B); if (A < 14 && B < 14 && A > 0 && B > 0){ if(A == 1 && B!= 1){ printf("Alice"); } else if (A != 1 && B == 1){ printf("Bob"); } else if (A != 1 && B != 1 && A > B){ printf("Alice"); } else if (A != 1 && B != 1 && A < B){ printf("Bob"); }else if (A == B){ printf("Draw"); } } }
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/trie_policy.hpp> #include<ext/pb_ds/detail/standard_policies.hpp> #define pi acos(-1) #define pb push_back #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define ll long long #define MAX 300005 #define INF 0x3f3f3f3f template <class T> inline T bigmod(T p,T e,T M){ll ret = 1LL;for(; e > 0LL; e >>= 1LL){if(e & 1LL) ret = (ret * p) % M;p = (p * p) % M;}return (T)ret;} template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);} using namespace std; using namespace __gnu_pbds; typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update>pref_trie; typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set; typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset; int main(){ int n,m; cin>>n>>m; int val[10]; val[0]=9999999; val[1]=2; val[2]=5; val[3]=5; val[4]=4; val[5]=5; val[6]=6; val[7]=3; val[8]=7; val[9]=6; vector<pair<int,int> >vec; for(int i=0;i<m;i++){ int a; cin>>a; vec.pb({val[a],a}); } string dp[n+10]; for(int i=0;i<n+10;i++){ dp[i]="-1"; } dp[0]=""; for(int i=0;i<n;i++){ if(dp[i]=="-1")continue; for(int j=0;j<vec.size();j++){ string cur=dp[i]; char ch = (char)('0'+vec[j].second); cur+=ch; int v = i+vec[j].first; if(dp[v]=="-1"){ dp[v]=cur; } else{ if(dp[v].size()==cur.size()){ if(dp[v]<cur){ dp[v]=cur; } } else if(dp[v].size()<cur.size()){ dp[v]=cur; } } } } cout<<dp[n]<<"\n"; }
0
77,383,599
#include <iostream> using namespace std; int main() { int n; cin >> n; int ans = 1; while(ans <= n) { ans *= 2; } cout << ans / 2 << endl; return 0; }
#include <iostream> #include <vector> using namespace std; const long long INFTY = 1e20; int main(){ int N; cin >> N; vector<long long> A(N); long long sum = 0ll; for(int i=0;i<N;i++){ cin >> A[i]; sum += A[i]; } long long x, y, ans; x = A[0]; y = sum - x; ans = abs(x-y); for(int i=1;i<N-1;i++){ x += A[i]; y = sum - x; ans = min(ans, abs(x-y)); } cout << ans << endl; return 0; }
0
34,948,554
#include <iostream> int main() { int x, y; for (std::cin >> x >> y; x != 0 || y != 0; std::cin >> x >> y) { if (x < y) { std::cout << x << ' ' << y << std::endl; } else { std::cout << y << ' ' << x << std::endl; } } }
#include <bits/stdc++.h> using namespace std; #define mem(a,n) memset(a,n,sizeof(a)) #define memc(a,b) memcpy(a,b,sizeof(b)) #define rep(i,a,n) for(int i=a;i<n;i++) #define pb push_back #define IO ios::sync_with_stdio(false) #define fre freopen("in.txt","r",stdin) #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 typedef long long ll; typedef unsigned long long ull; const double PI=acos(-1.0); const double E=2.718281828459045; const double eps=1e-8; const int INF=0x3f3f3f3f; const ll inf=0x3f3f3f3f3f3f3f3f; const int MOD=1e3; const int N=1e5+5; const ll maxn=1e6+5; const int dir[4][2]= {-1,0,1,0,0,-1,0,1}; ll n,a,b; void solve() { if(a+b>n+1||a*b<n) { cout<<-1; return ; } while(n>0) { ll x=min(a,n-b+1); for(ll i=n-x+1;i<=n;i++) cout<<i<<" "; n-=x; b--; } } int main() { while(cin>>n>>a>>b) { solve(); cout<<endl; } return 0; }
0
84,746,322
#include <iostream> #include <map> #include <string> using namespace std; int main() { int num = 0, i = 0; string operation, word; map<string, int> word_map; cin >> num; while ( i < num ) { cin >> operation; cin >> word; if ( operation == "insert" ) { word_map[word] = 1; } else if ( operation == "find" ) { if ( word_map[word] == 1 ) { cout << "yes" << endl; } else if ( word_map[word] == 0 ) { cout << "no" << endl; } } i = i + 1; } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; constexpr long double EPS = 1e-15; const long double PI = acos(-1); constexpr int inf = 1e9; constexpr ll INF = 2e18; constexpr ll MOD = 1e9+7; constexpr ll MOD1 = 998244353; typedef pair<ll,ll> P; #define rep(i,a,b) for (int i = (a); i < (b); i++) #define REP(i,n) rep(i,0,n) #define sz(s) (s).size() #define pb push_back #define fi first #define se second ll n; string s; void solve(); void input() { cin >> n >> s; } void solve() { if (s[0] == 'W') { std::cout << 0 << endl; return; } ll ans = 1; ll cnt = 1; bool left = 1; for (ll i = 1; i < sz(s); i++) { if (s[i] == s[i-1]) { left = !left; } if (left) { cnt++; } else { ans = (ans * cnt) % MOD; cnt--; } } if (cnt != 0) { std::cout << 0 << endl; return; } for (ll i = 2; i <= n; i++) ans = (ans * i) % MOD; std::cout << ans << endl; } int main(int argc, char *argv[]){ input(); solve(); return 0; }
0
74,962,734
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0; i<(n); i++) using ll = long long; using P = pair<int, int>; int main() { ll n, m; cin >> n >> m; vector<pair<ll, ll>> drink(n); rep(i,n) { ll a, b; cin >> a >> b; drink[i] = make_pair(a, b); } sort(drink.begin(), drink.end()); ll ans = 0; rep(i,n) { if (m >= drink[i].second) { m -= drink[i].second; ans += drink[i].first*drink[i].second; } else { ans += drink[i].first*m; m = 0; } if (m == 0) break; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll dp[500][500]; const ll LINF = 1e18+5; int main() { int n,k; cin >> n >> k; int h[500] = {}; for (int i=1;i<=n;i++) cin >> h[i]; for (int i=0;i<=n;i++) for (int j=0;j<=i;j++) dp[i][j] = LINF; dp[0][0] = 0; for (int i=1;i<=n;i++) { for (int j=1;j<=i;j++) { for (int x=j-1;x<i;x++) { dp[i][j] = min(dp[i][j],dp[x][j-1]+max(0,h[i]-h[x])); } } } ll ans = LINF; for (int i=n-k;i<=n;i++) { ans = min(dp[i][n-k],ans); } cout << ans << endl; return 0; }
0
53,223,065
#include <bits/stdc++.h> using namespace std; typedef pair<int,int> P; typedef long long ll; typedef long double ld; const int inf=1e9+7; const ll longinf=1LL<<60; #define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i ) #define rep(i,n) REP(i,0,n) #define F first #define S second const int mx=200010; const ll mod=1e9+7; const int64_t MOD = 1e9+7; void add(int64_t& a, int64_t b){ a = (a+b) % MOD; } void mul(int64_t& a, int64_t b){ a = a*b % MOD; } vector<int64_t> fact, seq_inv, fact_inv; void create_fact_mod(int num){ fact[0] = fact[1] = 1; for(int i=2; i<=num; i++) fact[i] = fact[i-1] * i % MOD; } void create_seq_inv_mod(int num){ seq_inv[0] = seq_inv[1] = 1; for(int i=2; i<=num; i++) seq_inv[i] = (MOD - MOD/i) * seq_inv[MOD%i] % MOD; } void create_fact_inv_mod(int num){ fact_inv[0] = fact_inv[1] = 1; for(int i=2; i<=num; i++) fact_inv[i] = fact_inv[i-1] * seq_inv[i] % MOD; } void create_mod_tables(int num){ fact.resize(num+1); seq_inv.resize(num+1); fact_inv.resize(num+1); create_fact_mod(num); create_seq_inv_mod(num); create_fact_inv_mod(num); } int64_t comb_mod(int n, int k){ return fact[n] * fact_inv[n-k] % MOD * fact_inv[k] % MOD; } int64_t perm_mod(int n, int k){ return fact[n] * fact_inv[n-k] % MOD; } int64_t power_mod(int64_t num, int64_t power){ int64_t prod = 1; num %= MOD; while(power > 0){ if(power&1) prod = prod * num % MOD; num = num * num % MOD; power >>= 1; } return prod; } int64_t extgcd(int64_t a, int64_t b, int64_t& x, int64_t& y){ int64_t d = a; if(b != 0){ d = extgcd(b, a%b, y, x); y -= (a/b) * x; }else{ x = 1; y = 0; } return d; } int64_t inv_mod(int64_t a){ int64_t x, y; extgcd(a, MOD, x, y); return (MOD + x%MOD) % MOD; } int nth_bit(int64_t num, int n){ return (num >> n) & 1; } vector<ll> a(mx); int main(){ int n; cin >> n; for(int i=0; i<n; i++){ cin >> a[i]; } ll ans=0; ll sum=0; ll r=0; rep(i,n){ while(r<n && sum+a[r]==(sum^a[r])){ sum += a[r]; r++; } ans += r-i; sum -= a[i]; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #include <bits/stdc++.h> #define forn(i, n) for (int i = 0; i < n; i++) #define ford(i, n) for (int i = n - 1; i > -1; i--) #define forl(i, l, r) for (int i = l; i <= r; i++) #define vc vector #define f first #define s second #define pb(i) push_back(i) #define mx(ar, n) (*max_element(ar, ar + n)) #define mn(ar, n) (*min_element(ar, ar + n)) #define mnv(v) (*min_element(v.begin(), v.end())) using namespace std; typedef unsigned long long ull; typedef long long ll; typedef long double ld; typedef string S; typedef int I; int x = 1000001 ; bool prime[1000001] ; void sev(){ for(int i = 2; i*i <= x; i++) { for(int j = i*2; j <= x; j+=i) { prime[j] = true ; } } } int main() { sev() ; I n ; while(cin >> n){ int c = 0 ; for(int i = 2; i <= n; i++) { if(!prime[i]){ c++ ; } } cout << c << endl ; } return 0; }
0
37,491,479
#include <bits/stdc++.h> #define rep(i, n) for(int i = 0; i < n; i++) using namespace std; int main() { int n, sum = 0; cin >> n; vector<int> a(n + 2); a.at(0) = 0; a.at(n + 1) = 0; rep(i, n) cin >> a.at(i + 1); rep(i, n + 1) sum += abs(a.at(i + 1) - a.at(i)); rep(i, n) cout << sum - abs(a.at(i + 1) - a.at(i)) - abs(a.at(i + 2) - a.at(i + 1)) + abs(a.at(i + 2) - a.at(i)) << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (int)(n); i++) const int MOD = 1000000007; int main() { int h, w, a, b; cin >> h >> w >> a >> b; rep(i, b) { rep(j, a) cout << 0; for (int j = a; j < w; j++) cout << 1; cout << endl; } for (int i = b; i < h; i++) { rep(j, a) cout << 1; for (int j = a; j < w; j++) cout << 0; cout << endl; } }
0
20,041,953
#define rep(i, n) for(int i = 0; i < n; i++) #include "bits/stdc++.h" using namespace std; using ll = long long; using P = pair<int, int>; int main() { int n; cin >> n; vector<string> s(n); rep(i,n) cin >> s[i]; int ans = 0; int end_A, start_B, haji_AB; end_A = 0, start_B = 0, haji_AB = 0; rep(i,n) { int len = s[i].size(); rep(j,len-1) if (s[i][j]=='A' && s[i][j+1]=='B') ans++; if (s[i][len-1]=='A') { if (s[i][0]=='B') haji_AB++; else end_A++; } else if(s[i][0]=='B') start_B++; } if (haji_AB>=1) { ans += haji_AB-1; if (end_A>=1) { ans++; end_A--; } if (start_B>=1) { ans++; start_B--; } } ans += min(end_A, start_B); cout << ans << endl; return 0; }
#include <iostream> using namespace std; const int MAX_NUM = 2000000; const int MAX_VALUE = 10000; void counting_sort(int* array1, int* array2, int n) { int k = -1, count[MAX_VALUE] = {}; for(int i=0;i<n;++i) { ++count[array1[i]]; k = max(k, array1[i]); } for(int i=0;i<k;++i) { count[i+1] += count[i]; } for(int i=0;i<n;++i) { array2[--count[array1[i]]] = array1[i]; } } int main() { int n, array1[MAX_NUM], array2[MAX_NUM]; cin >> n; for(int i=0;i<n;++i) cin >> array1[i]; counting_sort(array1, array2, n); for(int i=0;i<n;++i) { if(i) cout << " "; cout << array2[i]; } cout << endl; }
0
37,154,328
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<int, int> ii; #define DEBUG freopen("in.txt", "r", stdin); struct fastio { fastio() { ios::sync_with_stdio(false); cout << setprecision(10) << fixed; cin.tie(0); } }; fastio _fast_io; const int N = 51; int n, m; ii s[N], c[N]; int main() { cin >> n >> m; for (int i = 0; i < n; ++i) { cin >> s[i].first >> s[i].second; } for (int i = 0; i < m; ++i) { cin >> c[i].first >> c[i].second; } for (int i = 0; i < n; ++i) { ll ans = LLONG_MAX; ll ri = 0; for (int j = 0; j < m; ++j) { ll x = abs(s[i].first - c[j].first); ll y = abs(s[i].second - c[j].second); if (x + y < ans) { ans = x + y; ri = j; } } cout << ri + 1 << endl; } return 0; }
#include<bits/stdc++.h> using namespace std; #pragma GCC optimize ("Ofast") #define sint( a ) int a; qread(a); #define sint2( a, b ) int a,b; qread(a),qread(b); #define sint3( a, b, c ) int a,b,c; qread(a),qread(b),qread(c); #define int1( a ) qread(a); #define int2( a, b ) qread(a),qread(b); #define int3( a, b, c ) qread(a),qread(b),qread(c); #define mkp make_pair #define mkt make_tuple #define pb emplace_back #define inf INT_MAX #define all( x ) (x).begin(),(x).end() #define F first #define S second #define sdouble( a ) double a; scanf("%lf",&a); #define slong( a ) long long a; scanf("%lld",&a); #define cstring( a, x ) char a[x]; scanf("%s",a); #define sstring( a ) string a;cin>>a; #define rev( s ) reverse(all(s)); #define FOR( a, b, c ) for(int a=b;a<c;a++) #define ROF( a, b, c ) for(int a=b;a>c;a--) #define pause system("pause") #define endl printf("\n") #define fastio {ios::sync_with_stdio(false);cin.tie(NULL);} #define null NULL #ifdef DEBUG #define debug(x) cout<< #x << " = " << x;endl; #else #define debug( x ) #endif #define OPEN freopen("input.txt","r",stdin) #define SEND freopen("output.txt","w",stdout) #ifdef COM #define IN(x) #define OUT(x) #else #define IN( x ) freopen(x,"r",stdin); #define OUT( x ) freopen(x,"w",stdout); #endif typedef pair<int, int> ii; typedef vector<int> vi; typedef vector <ii> vii; typedef long long ll; void qread( int &x ) { int neg = 1; x = 0; register char c = getchar(); while(c < '0' || c > '9') { if(c == '-')neg = -1; c = getchar(); } while(c >= '0' && c <= '9')x = 10 * x + c - '0', c = getchar(); x *= neg; } void Wl( int x ) { printf("%d\n", x); } void Wl( double x ) { printf("%lf\n", x); } void Wl( string x ) { printf("%s\n", x.c_str()); } void Wl( ll x ) { printf("%lld\n", x); } void W( int x ) { printf("%d ", x); } void W( double x ) { printf("%lf ", x); } void W( string x ) { printf("%s ", x.c_str()); } void W( ll x ) { printf("%lld ", x); } int main() { int target = 0 ; target += (1<<1); target += (1<<4); target += (1<<7); target += (1<<9); int tmp=0; for(int i=0;i<4;i++) { sint(x); tmp+=(1<<x); } if(tmp==target)printf("YES\n"); else printf("NO\n"); }
0
73,573,036
#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; vi arr={100,101,102,103,104,105}; bool calc(int sum,int n,vector<vi> &dp){ if(sum==0){ return 1; } if(n<=0 || sum<0){ return false; } if(dp[sum][n]!=-1){return dp[sum][n];} return dp[sum][n]=calc(sum-arr[n-1],n,dp) || calc(sum,n-1,dp); } void solve(){ int sum; cin>>sum; int n=6; vector<vector<int>> dp(sum+1,vector<int> (n+1,-1)); cout<<calc(sum,n,dp)<<endl; } int main() { faster; int t=1; while(t-->0){ solve(); } return 0; }
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace std; typedef long long ll; const int maxn=100005,maxm=400005; int last[maxn],pre[maxm],other[maxm],t,cal[maxn],vis[maxn],q[maxn],head,tail; void add(int x,int y){++t;pre[t]=last[x];last[x]=t;other[t]=y;} int main(){ int n,m,x,y; while(cin>>n>>m){ ll I=0,P=0,Q=0; memset(last,0,sizeof(last));t=0;memset(vis,0,sizeof(vis)); memset(pre,0,sizeof(pre));memset(other,0,sizeof(other)); for(int i=1;i<=m;++i){ scanf("%d%d",&x,&y);add(x,y);add(y,x); } for(int i=1;i<=n;++i)if(!vis[i]){ head=tail=0;q[++tail]=i;cal[i]=0;vis[i]=1; bool flag=1; while(head<tail){ int u=q[++head]; for(int j=last[u];j;j=pre[j]){ int v=other[j]; if(!vis[v]){ q[++tail]=v;vis[v]=1;cal[v]=cal[u]+1; } else{ if((cal[v]-cal[u])%2==0)flag=0; } } } if(head==1){++I;continue;} if(flag)++Q; else ++P; } cout<<2ll*I*n-I*I+P*P+2ll*P*Q+2ll*Q*Q<<endl; } return 0; }
0
50,019,555
#include <iostream> #include <algorithm> using namespace std; int main() { string s; int a, b; cin >> a >> b; if (a > b) swap(a, b); for (int i = 0; i < b; i++) { s += a + '0'; } cout << s << endl; }
#include <bits/stdc++.h> #define rep(i,n) for(int i = 0; i < n; i++) using namespace std; int n, q; int rank[10000], par[10000]; void init(){ rep(i,n) par[i] = i; rep(i,n) rank[i] = 0; } int find(int x){ if(x == par[x]) return x; return par[x] = find(par[x]); } void unite(int x, int y){ x = find(par[x]); y = find(par[y]); if(x == y) return; if(rank[x] < rank[y]){ par[x] = y; } else{ par[y] = x; if(rank[x] == rank[y]) rank[x]++; } } int same(int x, int y){ return find(x) == find(y); } int main(){ scanf("%d%d",&n,&q); init(); rep(i,q){ int com, x, y; scanf("%d%d%d",&com,&x,&y); if(com == 0){ unite(x,y); } else { printf("%d\n",same(x,y)); } } }
0
23,257,864
#include <bits/stdc++.h> using namespace std; #define int long long typedef pair<int,int> P; int INF = 1e16+7; int mod = 1e9+7; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; int gcd(int X,int Y) { if(X%Y == 0) { return Y; } else { return gcd(Y,X%Y); } } signed main() { int N,K; cin >> N >> K; vector<int>A(N); int gd = 0,mx = 0; for(int i = 0; i < N; i++) { cin >> A[i]; mx = max(mx,A[i]); if(i) gd = gcd(gd,A[i]); else gd = A[i]; } if(mx >= K && (K-mx)%gd == 0) { cout << "POSSIBLE" << endl; } else { cout << "IMPOSSIBLE" << endl; } }
#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; ++i) #define ALL(vec) vec.begin(), vec.end() #define rALL(vec) vec.rbegin(), vec.rend() using namespace std; using ll = long long; int main() { int N; cin >> N; int before = 0; int ans = 0; rep(i, N) { int a; cin >> a; if (a == before) ans += 1, before = 0; else before = a; } cout << ans << endl; return 0; }
0
61,940,166
#include<bits/stdc++.h> #define INF 1000000000 using namespace std; int main(){ vector<int> a(5); for(int i=0;i<5;i++)cin >> a[i]; vector<int> P = {0,1,2,3,4}; int ans=INF; do{ int sum=0; for(int i=0;i<5;i++){ while(sum%10!=0)sum++; sum+=a[P[i]]; } ans=min(ans,sum); }while(next_permutation(P.begin(),P.end())); cout << ans << endl; }
#include <iostream> #include <vector> #include <math.h> #include <list> using namespace std; typedef long long int ll; ll MOD = pow(10,9) + 7; void print(vector<ll>& v) { for (auto i:v) { cout<<i<<" "; } cout<<endl; } void helper(vector<list<ll>>& adj,vector<bool>& vis,vector<ll>& W,vector<ll>& B,ll node) { vis[node] = true; list<ll> ngb = adj[node]; if (ngb.empty()) { W[node] = 1; B[node] = 1; return; } W[node] = 1; B[node] = 1; for (ll n:ngb) { if (!vis[n]) { helper(adj,vis,W,B,n); ll new_B_n = (B[n]*W[node]) % MOD; ll new_B_node = (B[node]*W[n]) % MOD; ll new_W_n = ((W[n]*B[node])%MOD + (W[n]*W[node])%MOD)%MOD; ll new_W_node = ((W[node]*B[n])%MOD + (W[node]*W[n])%MOD)%MOD; W[n] = new_W_n; W[node] = new_W_node; B[n] = new_B_n; B[node] = new_B_node; } } } ll solve(vector<list<ll>>& adj) { ll n = adj.size(); vector<bool> visited(n); vector<ll> W(n); vector<ll> B(n); ll root = 0; helper(adj,visited,W,B,root); ll ans = (W[root] + B[root])%MOD; return ans; } int main() { ll N; cin>>N; vector<list<ll>> adj(N); for (int i=0;i<N-1;++i) { ll from; ll to; cin>>from; cin>>to; --from; --to; adj[from].push_back(to); adj[to].push_back(from); } cout<<solve(adj)<<endl; return 0; }
0
368,708
#include <bits/stdc++.h> using namespace std; template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { os << "["; for (int i = 0; i < v.size(); ++i) { os << v[i]; if (i != v.size() - 1) os << ", "; } os << "]"; return os; } template <typename T> void print(T v, string s = "\n") { cout << v << s; } template <typename T> void in(T &v) { cin >> v; } #define ll long long #define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++) int main() { int n;in(n); vector<ll> A(n); loop(i,0,n) in(A[i]); map<ll, int> M; loop(i,0,n) { M[A[i]]++; } ll ans = 0; ll max_ = 0; for (auto&&m: M) { if (m.second >= 4) ans = max(ans, m.first*m.first); else if (m.second >= 2) { ans = max(ans, m.first*max_); } if (m.second >= 2) max_ = max(max_, m.first); } print(ans); return 0; }
#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 n, x, m; cin >> n >> x >> m; map<ll, ll> mv; ll lb = inf, ls = inf; rep(i, n) { if (mv.count(x) > 0) { lb = mv[x]; ls = i - mv[x]; break; } mv[x] = i; x = x * x % m; } ll ans = 0; for(auto &v : mv) { if (v.second < lb) { ans += v.first; } else { ans += v.first * ((n - v.second - 1) / ls + 1); } } cout << ans << endl; return 0; }
0
28,593,520
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); long long h, w; cin >> h >> w; long long a, b, c, ans = 1e15; for(int i = 1; i < h; i++){ a = i * w; b = (w / 2) * (h - i); c = h * w - a - b; ans = min(ans, max({a, b, c}) - min({a, b, c})); b = ((h - i) / 2) * w; c = h * w - a - b; ans = min(ans, max({a, b, c}) - min({a, b, c})); } for(int i = 1; i < w; i++){ a = i * h; b = (h / 2) * (w - i); c = h * w - a - b; ans = min(ans, max({a, b, c}) - min({a, b, c})); b = ((w - i) / 2) * h; c = h * w - a - b; ans = min(ans, max({a, b, c}) - min({a, b, c})); } cout << ans << "\n"; }
#include<bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; #define rep(i,n) for(ll i=0;i<n;++i) #define ocut cout #define ouct cout #define itn int struct Union{ vector<ll> par; Union(ll a){ par=vector<ll>(a,-1); } ll find(ll a){ if(par[a]<0){ return a; } else{ return par[a]=find(par[a]); } } bool same(ll a,ll b){ return (find(a)==find(b)); } ll size(ll a){ return -par[find(a)]; } void unite(ll a,ll b){ ll c=find(a),d=find(b); if(c==d) return; if(size(c)<size(d)){ swap(c,d); } par[c]+=par[d]; par[d]=c; } }; ll euclidean_gcd(ll a, ll b) { if(a < b) return euclidean_gcd(b, a); ll r; while ((r=a%b)) { a = b; b = r; } return b; } ll euclidean_lcm(ll a, ll b) { return a/euclidean_gcd(a,b)*b; } ll binary(ll bina){ ll ans = 0; for (ll i = 0; bina>0 ; i++) { ans += bina%2; bina = bina/2; } return ans; } void revStr(char* str){ int size = strlen(str); int i,j; char tmp = {0}; for(i = 0, j = size - 1; i < size / 2; i++, j--){ tmp = str[i]; str[i] = str[j]; str[j] = tmp; } return; } int main(void){ string s; cin >> s; int n=0; rep(i,s.size()){ n+=(s[i]-'0'); } if(n%9==0)cout << "Yes"; else cout << "No"; }
0
79,174,955
#include <bits/stdc++.h> using namespace std; #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define rep(i,n) FOR(i,0,n) #define pb push_back #define mp make_pair typedef long long ll; typedef pair<int,int> pint; #define MAX_N 10000 struct UnionFind{ int par[MAX_N]; void init(int n){ for (int i=0;i<n;i++) par[i] = i; } int find(int x){ if (x==par[x]) return (x); return (par[x]=find(par[x])); } void unite(int x, int y){ x=find(x);y=find(y); if(x==y) return; par[x] = y; } bool same(int x, int y){ return (find(x) == find(y)); } }; int main(){ int n,q,c,x,y; UnionFind uf; cin>>n>>q; uf.init(n); rep(i,q){ cin>>c>>x>>y; if(c==0) uf.unite(x,y); else{ if(uf.same(x,y)) cout<<1<<endl; else cout<<0<<endl; } } return 0; }
#include<bits/stdc++.h> using namespace std; using ll = long long; #define rep(i,n) for(ll i=0;i<n;i++) #define repl(i,l,r) for(ll i=(l);i<(r);i++) #define per(i,n) for(ll i=n-1;i>=0;i--) #define perl(i,r,l) for(ll i=r-1;i>=l;i--) #define fi first #define se second #define pb push_back #define ins insert #define all(x) (x).begin(),(x).end() using vl=vector<ll>; using vvl=vector<vector<ll>>; const ll MOD=1000000007; const ll MOD9=998244353; const int inf=1e9+10; const ll INF=4e18; const ll dy[8]={1,0,-1,0,1,1,-1,-1}; const ll dx[8]={0,-1,0,1,1,-1,1,-1}; using Graph = vector<vector<int>>; const ll mod=1000000007; const int MAX_N = 1000; double nCk(int n, int k) { double res=1.0; for(int i=0; i<n; i++){ res*=0.5;} for(int i=0; i<k; i++){ res*=(double)(n-i); res/=(double)(k-i); } return res;} int main() { ll n,p; cin>>n; ll a[n]={}; ll b[n]={}; ll ca=0; ll cb=0; ll k=0; ll c[n]={}; rep(i,n){ cin>>a[i]>>b[i]; cb+=b[i]; c[i]=a[i]+b[i];} sort(c,c+n); if(n%2==0){ rep(i,n){ if(i%2==0){ k++;} else{ ca+=c[i];} }} else{ rep(i,n){ if(i%2==0){ ca+=c[i]; } else{ k++; } }} ll ans = ca - cb; cout << ans << endl;}
0
41,372,338
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main(){ int N; cin >> N; vector<int> A(N); for (int i = 0; i < N; i++) { cin >> A[i]; } long long ans = 0; int MaxNum = 0; for (int i = 0; i < N; i++) { MaxNum = max(MaxNum, A[i]); int Bi = MaxNum; ans += Bi - A[i]; } cout << ans << endl; }
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<long long, long long>; constexpr char ln = '\n'; constexpr long long MOD = 1000000007LL; constexpr long long INF = 1000000009LL; #define all(x) (x).begin(),(x).end() #define rep(i,n) for(int i=0;i<(n);i++) #define fo(i,j,n) for (int i=(j); i < (n); i++) 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; } int main() { int n; cin >> n; vector<ll> A(n); rep(i, n) cin >> A[i]; sort(all(A)); ll ans[2] = {A[n-1], -1}; ll half = ans[0]/ 2; rep(i, n){ ll num = A[i]; if(num <= half) chmax(ans[1], num); else{ ll tmp = ans[0] - num; if(ans[1] < tmp) ans[1] = num; break; } } cout << ans[0] << " " << ans[1] << ln; }
0
97,276,571
#include<bits/stdc++.h> using namespace std; #define Bye return 0 #define ll long long const ll MAX = 1e2; void solve(){ string a, b, c; cin>>a>>b>>c; int size_a = a.size(), size_b = b.size(); cout<<(a[size_a-1] == b[0] && b[size_b-1] == c[0] ? "YES" : "NO")<<endl; } int main(){ solve(); Bye; }
#include <bits/stdc++.h> using namespace std; struct Node{ int parent,left,right; Node(){ parent=-1;left=-1;right=-1; } }; int node_depth(Node T[],int D[],int node){ if(D[node]!=-1)return D[node]; if(T[node].parent==-1)D[node]=0; else D[node]=1+node_depth(T,D,T[node].parent); return D[node]; } int main(){ int n;cin>>n; Node Tree[n]; int id,k,children,prec; int Depth[n]; for(int i=0;i<n;i++)Depth[i]=-1; for(int i=0;i<n;i++){ scanf("%d %d",&id,&k); if(k>0){ scanf("%d",&children); Tree[id].left=children; Tree[children].parent=id; } for(int j=1;j<k;j++){ prec=children; scanf("%d",&children); Tree[prec].right=children; Tree[children].parent=id; } } for(int i=0;i<n;i++){ printf("node %d: parent = %d, ",i,Tree[i].parent); printf("depth = %d, ",node_depth(Tree,Depth,i)); if(Tree[i].parent==-1)printf("root"); else{ if(Tree[i].left==-1)printf("leaf"); else printf("internal node"); } printf(", ["); int j=Tree[i].left; while(j!=-1){ if(j!=Tree[i].left)printf(", "); printf("%d",j); j=Tree[j].right; } printf("]\n"); } }
0
53,441,486
#include<iostream> #include<math.h> #define pi 2*acos(0) int main() { int a,b,c; int x=0; std::cin>>a>>b>>c; x = c/a; if(a*x>= b){ std::cout<<"OK"<<std::endl; } else{ std::cout<<"NG"<<std::endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main(void) { string s; cin >> s; int ans = 0; int l = 0, r = s.length() - 1; while (l < r) { if (s[l] == s[r]) { l++; r--; } else if (s[l] == 'x') { ans++; l++; } else if (s[r] == 'x') { ans++; r--; } else { ans = -1; break; } } cout << ans << endl; return 0; }
0
58,826,502
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i,n) for(int i=0;i<n;i++) #define rep2(i,a,b) for(int i=(a);i<(b);++i) template<class T> inline void chmin(T& a, T b) {if (a > b) a = b;} template<class T> inline void chmax(T& a, T b) {if (a < b) a = b;} template <class T>ostream &operator<<(ostream &o,const vector<T>&v){ o<<"{"; for(int i=0;i<(int)v.size();i++) o << (i>0?", ":"") << v[i]; o<<"}"; return o; } int main() { ll K,res=0,cnt=1; string S; cin >> S >> K; vector<ll> ans; if (S[0]==S[S.size()-1]) cnt++; rep2(i,1,S.size()){ if (S[i]!=S[i-1]) { if (cnt>1) ans.push_back(cnt); cnt=0; }; cnt++; } if (cnt==S.size()+1) { res += (cnt-1)*K/2; cout <<res << endl; return 0; } else if (S[0]==S[S.size()-1]) { res+=(ans[0]-1)/2; res+=cnt/2; ll tmp = ans[0]+cnt-1; res+=tmp/2*(K-1); rep2(i,1,ans.size()) res+=ans[i]/2*K; cout <<res << endl; return 0; } else if (cnt>1) ans.push_back(cnt); for (auto i:ans) res+=i/2*K; cout << res << endl; }
#include<bits/stdc++.h> using namespace std; int main(){ int n,m,p,x; int a[100]; int sum; while(1){ cin>>n>>m>>p; if(n==0 && m==0 && p==0) break; sum=0; for(int i=0;i<100;i++){ a[i]=0; } for(int i=0;i<n;i++){ cin>>x; a[i]=x; sum+=x; } if(a[m-1]!=0){ sum=sum*(100-p); cout<<sum/a[m-1]<<endl; } else cout<<0<<endl; } return 0; }
0
17,809,487
#include <iostream> using namespace std; int main (){ int r; cin >> r; printf("%d", r*r); }
#include <bits/stdc++.h> #define REP(i, n) for (long long i = 0; i < (long long)n; i++) using namespace std; using ll = long long; using Pi = pair<int, int>; using Pl = pair<ll, ll>; using Vl = vector<ll>; using vi = vector<int>; using Graph = vector<vi>; int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; vector<string> S(n); REP(i, n) cin >> S.at(i); string ans = ""; sort(S.at(0).begin(), S.at(0).end()); for (auto s : S.at(0)) { bool FLG = true; for (int j = 1; j < n; j++) { bool flag = false; for (int k = 0; k < S.at(j).size(); k++) { if (s == S.at(j).at(k)) { S.at(j).at(k) = '0'; flag = true; break; } } if (!flag) { FLG = false; break; } } if (FLG) ans += s; } cout << ans << endl; }
0
40,636,436
#include<bits/stdc++.h> using namespace std; int main(){ int N, K; string S; cin >> N >> S >> K; char c=S[K-1]; for(int i=0; i<N; i++){ if(S[i]!=c) S[i]='*'; } cout << S << endl; return 0; }
#include<iostream> using namespace std; int main(){ int count[5][4][11], n; for ( int s = 1; s <= 4; s++){ for ( int t = 1; t <= 3; t++) for ( int u = 1; u <= 10; u++) count[s][t][u] = 0; } cin >> n; for ( int i = 0 ; i < n; i++){ int b, f, r, v; cin >> b >> f >> r >> v; count[b][f][r] += v; } for ( int s = 1; s <= 4; s++){ if (s > 1) cout << "####################\n"; for ( int t = 1; t <= 3; t++){ for ( int u = 1; u <= 10; u++){ cout << " " << count[s][t][u]; } cout << endl; } } return 0; }
0
17,837,065
#include <algorithm> #include <iostream> #include <map> #include <vector> #include <utility> using namespace std; int main() { int N; cin >> N; vector<map<int, int>> cnt_map(2); for (int n = 0; n < N; ++n) { int v; cin >> v; ++cnt_map[n % 2][v]; } vector<vector<pair<int, int>>> cnts(2, vector<pair<int, int>>(2, {0, 0})); for (int i = 0; i < 2; ++i) { for (const auto& p : cnt_map[i]) { if (p.second >= cnts[i][0].second) { cnts[i][1] = cnts[i][0]; cnts[i][0] = p; } else if (p.second >= cnts[i][1].second) { cnts[i][1] = p; } } } if (cnts[0][0].first == cnts[1][0].first) { int res = max(cnts[0][0].second + cnts[1][1].second, cnts[0][1].second + cnts[1][0].second); cout << N - res << endl; } else { cout << N - cnts[0][0].second - cnts[1][0].second << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; const int mod = 1e9+7; int main(){ ll n,k; cin >> n >> k; ll sum = min(n,k); ll v[n+10]; ll kotae; ll ans = -1; for(int i = 0; i < n; i++){ ll temp; cin >> temp; v[i] = temp; } for(int i = 0; i <= sum; i++){ for(int j = 0; j <= sum - i; j++){ kotae = 0; vector<ll> minus; for(int k = 0; k < i; k++){ kotae += v[k]; if(v[k] < 0){ minus.push_back(v[k]); } } for(int k = n-1; k >= n-j;k--){ kotae += v[k]; if(v[k] < 0){ minus.push_back(v[k]); } } sort(minus.begin(),minus.end()); ll hoge = minus.size(); ll dokomade = min(k - i - j,hoge); for(int k = 0; k < dokomade; k++){ kotae -= minus[k]; } ans = max(ans,kotae); } } cout << ans << endl; }
0
74,700,205
#include <bits/stdc++.h> using namespace std; using ll = long long; ll a, b, c, d; vector<ll> ans; int main() { cin >> a >> b >> c >> d; ans.emplace_back(a * c); ans.emplace_back(a * d); ans.emplace_back(b * c); ans.emplace_back(b * d); if (a * b <= 0 || c * d <= 0) ans.emplace_back(0); sort(ans.rbegin(), ans.rend()); cout << ans[0] << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,ll> P; typedef pair<P,ll> PLL; typedef pair<P,P> PP; typedef vector<ll> VECLL; typedef vector<P> VECP; typedef priority_queue<P,VECP,greater<P> > PQP; typedef priority_queue<ll, VECLL, greater<ll> > PQll; #define rep(i,a,n) for(ll i = a;i < n;i++) #define rrep(i,a,n) for(ll i = n; i >= a;i--) #define index_check(i,n) if(i > n-1 || i < 0) continue; #define LINF (ll)1e18 #define INF (int)1e9 #define fs first #define sc second int main(){ ll h,w; cin >> h >> w; char c[h][w] = {}; rep(i,0,h) rep(j,0,w) cin >> c[i][j]; ll dp[h+1][w+1] = {}; rep(i,0,h+1) rep(j,0,w+1) dp[i][j] = LINF; dp[0][0] = 0; rep(i,0,h){ rep(j,0,w){ if(i < h-1 && c[i][j] == '#' && c[i+1][j] == '.') dp[i+1][j] = min(dp[i+1][j],dp[i][j]+1); else dp[i+1][j] = min(dp[i+1][j],dp[i][j]); if(j < w-1 && c[i][j] == '#'&& c[i][j+1] == '.') dp[i][j+1] = min(dp[i][j+1],dp[i][j]+1); else dp[i][j+1] = min(dp[i][j+1],dp[i][j]); } } if(c[h-1][w-1] != '#') cout << dp[h-1][w-1] << endl; else cout << dp[h-1][w-1] + 1 << endl; return 0; }
0
90,272,464
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int a,b,c,d; cin>>a>>b>>c>>d; int ans=0; for(int i=0;i<3001;i++){ for(int j=0;j<3001;j++){ if((d-a*i-b*j)%c==0 && (d-a*i-b*j)>=0){ ans++; } } } cout<<ans<<endl; }
#include <bits/stdc++.h> #define _GLIBCXX_DEBUG using namespace std; #define rep(i,n) for(int i=0;i<(int)(n);i++) #define REP(i,m,n) for(int i=m;i<(int)(n);i++) template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } typedef long long ll; typedef pair<ll,ll> pint; const long long INF = 1LL<<60; ll gcd(ll a,ll b){ if(b==0){ return a; } else{ return gcd(b,a%b); } } int main(){ ll n,k;cin>>n>>k; ll cnt = ((n-2)*(n-1))/2; if(cnt<k){ cout<<"-1"<<endl; } else{ k = cnt-k; cout<<k+n-1<<endl; REP(i,2,n+1){ cout<<1<<" "<<i<<endl; } if(k!=0){ for(int i=2;i<=n;i++){ REP(j,i+1,n+1){ cout<<i<<" "<<j<<endl; k--; if(k==0){ break; } } if(k==0){ break; } } } } }
0
905,495
#include<bits/stdc++.h> using namespace std; using ll = long long; int main(){ vector<int> v; while(cin.peek() != '\n')v.push_back(getchar()-'0'); int n = (int)v.size(); int k; cin >> k; ll dp1[101][5] = {}; ll dp2[101][5] = {}; dp1[0][1] = v[0]-1; dp1[0][0] = 1; dp2[0][1] = 1; for(int i = 0; i < n-1; ++i){ for(int j = 0; j <= k; ++j){ dp1[i+1][j] += dp1[i][j]+dp2[i][j]*(v[i+1]!=0); dp1[i+1][j+1] += dp1[i][j]*9+dp2[i][j]*max<ll>(v[i+1]-1,0); dp2[i+1][j] += dp2[i][j]*(v[i+1]==0); dp2[i+1][j+1] += dp2[i][j]*(v[i+1]!=0); } } cout << dp1[n-1][k] + dp2[n-1][k] << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll, ll> Pair; typedef vector<ll> vll; typedef vector<vector<ll>> Graph; typedef vector<string> vs; typedef vector<pair<ll, ll>> Pll; typedef queue<ll> qll; #define REP(i,n) for(ll i=0;i<(ll)(n);i++) #define REPD(i,n) for(ll i=n-1;i>=0;i--) #define REPA(i,a) for(ll i=0;i<(ll)(a.size());i++); #define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++) #define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--) #define COUT(a) cout << (a) << endl; #define ENDL(a) cout << endl; #define COUTA(i,a) for(ll i=0;i<(ll)(a.size());i++) {cout << (a)[i] << " ";} cout << endl; #define pb push_back #define paired make_pair #define ALL(a) (a).begin(),(a).end() #define SORT(a) sort((a).begin(),(a).end()) #define RSORT(a) sort((a).rbegin(), (a).rend()) #ifdef _DEBUG #define debug(x) cout << "[debug] " << #x << ": " << x << endl #else #define debug(x) #endif template <typename T> void debugV(const vector<T> v) { #ifdef _DEBUG rep(i, v.size()) { cout << i << ":" << v[i] << " "; } cout << endl; #else (void)v; #endif } const unsigned int BIT_FLAG_0 = (1 << 0); const unsigned int BIT_FLAG_1 = (1 << 1); const unsigned int BIT_FLAG_2 = (1 << 2); const unsigned int BIT_FLAG_3 = (1 << 3); const unsigned int BIT_FLAG_4 = (1 << 4); const unsigned int BIT_FLAG_5 = (1 << 5); const unsigned int BIT_FLAG_6 = (1 << 6); const unsigned int BIT_FLAG_7 = (1 << 7); const unsigned int BIT_FLAG_8 = (1 << 8); const unsigned int BIT_FLAG_9 = (1 << 9); const unsigned int BIT_FLAG_10 = (1 << 10); const unsigned int BIT_FLAG_11 = (1 << 11); constexpr ll INF = 0x3f3f3f3f3f3f3f3f; constexpr double PI=3.14159265358979323846; constexpr int MOD = 1000000007; void Main() { ll n; cin >> n; vs a(n, ""); REP(i, n) { string s_in; cin >> s_in; sort(s_in.begin(), s_in.end()); a[i] = s_in; } SORT(a); string check = ""; ll count=1; ll total=0; REP(i, n) { if (check == a[i]) { count++; } else { total += (count * (count - 1) / 2); count=1; } check = a[i]; } total += (count * (count - 1) / 2); COUT(total); } int main() { cin.tie(0); ios_base::sync_with_stdio(false); cout << fixed << setprecision(15); Main(); }
0
2,855,811
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using Graph = vector<vector<int>>; const int N = 100005; vector<pair<int, ll> > g[N]; ll dist[N]; void dfs(int v, int p){ for(auto x : g[v]){ if(x.first == p)continue; dist[x.first] = dist[v] + x.second; dfs(x.first, v); } } int main(){ ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout<<setprecision(32); string s, t; cin >> s >> t; cout << t+s << "\n"; return 0; }
#include <iostream> #include <stdlib.h> using namespace std; int main(){ string s, p; getline(cin, s); getline(cin, p); bool judge; for(int j=0; j<s.size(); j++){ if(p[0] == s[j]){ judge = true; int s_index; for(int k=1; k<p.size(); k++){ s_index = j+k; if(s_index >= s.size()){ s_index -= s.size(); } if(p[k] != s[s_index]){ judge = false; break; } } }else{ judge = false; } if(judge){ break; } } if(judge){ cout << "Yes" << endl; }else{ cout << "No" <<endl; } return(0); }
0
40,854,793
#include<stdio.h> int main(){ int N,R,hasil; scanf ("%d %d",&N,&R); if (N<10){ hasil = 100*(10-N); hasil = R + hasil; } else { hasil= R; } printf ("%d", hasil); }
#include<iostream> #include<cstring> #include<string> #include<algorithm> #include<cmath> #include<vector> #include<deque> #include<map> #include<queue> using namespace std; #define rep(i,s,n) for(int i = s;i<n;i++) #define repe(i,s,n) for(int i = s;i<=n;i++) #define pb push_back #define fi first #define se second typedef long long ll; typedef pair<int,int>pint; typedef vector<int>vint; typedef vector<pint>vpint; static const ll maxLL = (ll)1 << 62; const int mod=1000000007; int dy[]={-1,0,1,0}; int dx[]={0,1,0,-1}; #define int ll signed main(){ int n; cin>>n; rep(i,0,n){ int x,y; cin>>x>>y; if(x<y)swap(x,y); int r=floor(sqrt(x*y)); if(r*(r+1)<x*y)cout<<2*r-1<<endl; else if(r*r<x*y)cout<<2*r-2<<endl; else cout<<2*r-3+(r==x)<<endl; } return 0; }
0
62,027,933
#include <bits/stdc++.h> using namespace std; int main() { int A,B; int answer = 0; string op; cin >> A >> op >> B; if (op == "+") { answer = A + B; } if (op == "-") { answer = A - B; } cout << answer << endl; }
#include <bits/stdc++.h> #define endl "\n" #define rep(i,n) for(int i=0;i<int(n);i++) #define e_b emplace_back #define sz(x) ((int)(x).size()) #define all(x) (x).begin(),(x).end() using namespace std; typedef long long ll; typedef long double ld; typedef pair<int,int> ipair; typedef pair<ll,ll> lpair; template <class T>ostream &operator<<(ostream &o,const vector<T>&v) {o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;} void map_p(map<int,int>& d){cout<<"map: ";for(auto a : d){cout<<"{"<<a.first<<":"<<a.second<<"}";}cout<<endl;} void set_p(set<int>& d){cout<<"set: ";for(int a : d){cout<<a<<" ";}cout<<endl;} int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12); ll n,m; cin>>n>>m; int ans=0; vector<ll> a(n); rep(i,n){ cin>>a[i]; a[i]/=2; } bool flag=true; while(a[0]%2==0){ rep(i,n){ if(a[i]%2!=0){ flag=false; break; } a[i]/=2; } m/=2; } rep(i,n) if(a[i]%2==0) flag=false; if(flag){ ll lcm=a[0]; for(int i=1;i<n;i++){ lcm=lcm*a[i]/__gcd(lcm,a[i]); if(m<lcm){ flag=false; break; } } if(flag){ lcm=m/lcm; if(lcm%2==0) lcm--; ans=(lcm-1)/2+1; } } cout<<ans<<endl; return 0; }
0
51,272,542
#include <iostream> #include <cstdint> #include <cstdio> #include <algorithm> #include <cmath> #include <vector> #include <list> #include <set> #include <map> #include <queue> #include <stack> #include <cctype> #include <cassert> #include <climits> #include <string> #include <bitset> #include <cfloat> #include <unordered_set> #pragma GCC optimize("Ofast") using namespace std; typedef long double ld; typedef long long int ll; typedef unsigned long long int ull; typedef vector<int> vi; typedef vector<char> vc; typedef vector<bool> vb; typedef vector<double> vd; typedef vector<string> vs; typedef vector<ll> vll; typedef vector<pair<int, int> > vpii; typedef vector<vector<int> > vvi; typedef vector<vector<char> > vvc; typedef vector<vector<string> > vvs; typedef vector<vector<ll> > vvll; #define rep(i, n) for (int i = 0; i < (n); ++i) #define rrep(i, n) for (int i = 1; i <= (n); ++i) #define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++) #define drep(i, n) for (int i = (n)-1; i >= 0; --i) #define mes(a) cout << (a) << endl #define dmes(a, b) cout << (a) << " " << (b) << endl #define re0 return 0 #define mp(p, q) make_pair(p, q) #define pb(n) push_back(n) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define Sort(a) sort(a.begin(), a.end()) #define rSort(a) sort(a.rbegin(), a.rend()) #define MATHPI acos(-1) #define itn int; int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 }; int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 }; template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } struct io { io() { ios::sync_with_stdio(false); cin.tie(0); } }; const int INF = INT_MAX; const ll LLINF = 1LL << 60; const ll MOD = 1000000007; const double EPS = 1e-9; signed main(void) { ll n; cin >> n; map<ll, ll> mp; ll r = 0; ll a; rep(i, n) { cin >> a; mp[a-1]++; mp[a]++; mp[a+1]++; } for(auto i: mp) { r = max(r, i.second); } mes(r); }
#include<bits/stdc++.h> typedef long long int ll; using namespace std; #define MOD (ll)1000000007 ll arr[1000000]; int main(){ ll n; cin >> n; for(ll i = 0; i < n; i++){ cin >> arr[i]; } ll sum = 0; for(ll i = 0; i < 60; i++){ ll oc = 0, zc = 0; for(ll j = 0; j < n; j++){ if(arr[j]%2 == 0){ zc++; } else{ oc++; } arr[j] /= 2; } sum = (sum + ((zc * oc) % MOD * ((1ll << i) % MOD)) % MOD) % MOD; } cout << sum; }
0
75,648,449
#include <bits/stdc++.h> #define pt(sth) cout << sth << "\n" #define chmax(a, b) {if(a<b) a=b;} #define chmin(a, b) {if(a>b) a=b;} #define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD using namespace std; typedef long long ll; typedef pair<ll, ll> P; static const ll INF=1e18; static const ll MAX=101010; static const ll MOD=1e9+7; static const ll LOGN=55; int main(void) { ll N, K; cin >> N >> K; ll a[1111]; ll s[1111]={}; ll i, j; for(i=1; i<=N; i++) { cin >> a[i]; s[i]=a[i]+s[i-1]; } vector<ll> v; ll cnt[44]={}; for(i=0; i<N; i++) { for(j=i+1; j<=N; j++) { ll t=s[j]-s[i]; v.push_back(t); ll bit=0; while(t>0) { if(t&1) cnt[bit]++; bit++; t>>=1; } } } ll f[MAX*10]; memset(f, 1, sizeof(f)); ll ans=0; for(ll b=40; b>=0; b--) { if(cnt[b]>=K) { ans+=pow(2, b); for(i=0; i<v.size(); i++) { if(!f[i]) continue; if(v[i]>>b&1) continue; f[i]=0; ll t=v[i]; ll bit=0; while(t>0) { if(t&1) cnt[bit]--; bit++; t>>=1; } } } } pt(ans); }
#include <bits/stdc++.h> using namespace std; #define pb push_back #define fi first #define se second #define all(x) (x).begin(), (x).end() #define rep(i, n) for (int i = 0; i < (n); ++i) #define repp(i, a, b) for (int i = a; i <= (b); ++i) #define repr(i, a, b) for (int i = a; i >= (b); --i) #define bit(n) (1LL << (n)) typedef long long ll; const int INF = 1001001001; const ll LINF = 1001001001001001001ll; const int MOD = 1000000007; 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 N; cin >> N; vector<int> t(N + 1); repp(i, 1, N) { cin >> t[i]; t[i] *= 2; t[i] += t[i - 1]; } vector<int> v(N + 1); repp(i, 1, N) { cin >> v[i]; v[i] *= 2; } int MAX_T = t[N]; vector<vector<int>> speed(N + 2, vector<int>(MAX_T + 1)); repp(i, 1, N) { int t1 = t[i - 1]; int t2 = t[i]; rep(j, MAX_T + 1) { speed[i][j] = max({-(j - t1) + v[i], (j - t2) + v[i], v[i]}); } } rep(j, MAX_T + 1) { speed[0][j] = j; speed[N + 1][j] = -(j - MAX_T); } vector<int> max_speed(MAX_T + 1); rep(j, MAX_T + 1) { int temp = INF; rep(i, N + 2) { chmin(temp, speed[i][j]); } max_speed[j] = temp; } double ans = 0; rep(i, MAX_T) { int a = max_speed[i]; int b = max_speed[i + 1]; ans += ((double)(a + b)) / 2.0; } ans /= 4.0; printf("%.10f\n", ans); }
0
80,336,260
#define _GLIBCXX_DEBUG #define rep(i,n) for(int i=0;i<n;i++) #include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int N; cin>>N; int count=0; while(N>=3){ count++; N-=3; if(N-3>=3)continue; else{ count++; break; } } cout<<count<<endl; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define endl "\n" #define rep(i, a, n) for (int i = a; i < n; ++i) int main() { int w, h, n; cin >> w >> h >> n; int x1 = 0, y1 = 0; rep(i, 0, n) { int x, y, a; cin >> x >> y >> a; if (a == 1) { x1 = max(x1, x); } else if (a == 2) { w = min(w, x); } else if (a == 3) { y1 = max(y1, y); } else { h = min(h, y); } } if (w <= x1 || h <= y1) { cout << "0" << endl; return 0; } else { cout << (w - x1) * (h - y1) << endl; } return 0; }
0
27,084,430
#include <iostream> #include <algorithm> using namespace std; const int INF = 1000000007; int main() { int n, k, a[5003]; cin >> n >> k; int least = INF; for(int i = 0; i < n; i++){ cin >> a[i]; if(a[i] >= k) least = min(least, a[i]); } sort(a, a + n, greater<int>()); int dp[10005]; fill(dp, dp + 10005, -1); dp[0] = 0; for(int i = 0; i < n; i++){ for(int j = k * 2; j >= a[i]; j--){ if(dp[j - a[i]] != -1){ if(j - a[i] < k) dp[j] = a[i]; else dp[j] = dp[j - a[i]]; } } } for(int i = k; i <= k * 2; i++){ if(i - k < dp[i]){ least = min(least, dp[i]); } } if(least == INF) cout << n << endl; else{ reverse(a, a + n); cout << lower_bound(a, a + n, least) - a << endl; } }
#include <bits/stdc++.h> #define REP(i, x, n) for (int i = x; i < (int)(n); i++) #define rep(i, n) REP(i, 0, n) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define sz(x) (int)(x.size()) #define popcount(x) __builtin_popcount(x) #define popcountll(x) __builtin_popcountll(x) #define uniq(x) x.erase(unique(x.begin(), x.end()), x.end()) #define F first #define S second #define mp make_pair #define eb emplace_back #define pii pair<int, int> #define pll pair<ll, ll> using namespace std; typedef long long ll; int main() { int N, K; cin >> N >> K; vector<int> a(N); rep(i, N) cin >> a[i]; vector<ll> sum; rep(i, N) { ll s = 0; REP(j, i, N) { s += a[j]; sum.eb(s); } } ll ans = 0; for (int i = 60; i >= 0; i--) { vector<ll> tmp; rep(j, sz(sum)) if ((1LL << i) & sum[j]) tmp.eb(sum[j]); if (sz(tmp) >= K) { ans += (1LL << i); sum = tmp; } } cout << ans << endl; }
0
92,845,821
#include <sys/time.h> #include <iostream> #include <iomanip> #include <algorithm> #include <utility> #include <cmath> #include <string> #include <vector> #include <set> #include <map> #include <queue> #include <stack> #include <deque> #include <utility> #include <cctype> using namespace std; using ll = long long; using P = pair<double, double>; #define rep(i, n) for(int i = 0; i < (int)(n); i++) #define mkp(a, b) make_pair(a, b) ll mod = 1000000007LL; int main() { int n, k; cin >> n >> k; vector<int> vs(n); rep(i, n) { cin >> vs[i]; } int ans = 0; int max_l = min(k, n + 1); rep(l, max_l + 1) { vector<int> vrs; int cur_k_l = k - l; rep(i,l) { vrs.push_back(vs[i]); } int max_r = min(cur_k_l, n - l); rep(r, max_r + 1) { int cur_k_r = cur_k_l - r; vector<int> vrls = vrs; rep(i, r) { vrls.push_back(vs[vs.size() - i - 1]); } sort(vrls.begin(), vrls.end()); int total = 0; rep(i, vrls.size()) { if (cur_k_r > 0 && vrls[i] < 0) { cur_k_r--; continue; } total += vrls[i]; } ans = max(total, ans); } } cout << ans << endl; return 0; }
#include <iostream> #include <algorithm> #include <cmath> using namespace std; int P[10010]; int Rank[10010]; void init(int N){ for(int i = 0; i < N; ++i){ P[i] = i; Rank[i] = 0; } } int root(int a){ if(P[a] == a) return a; return (P[a] = root(P[a])); } bool IsSameSet(int a, int b){ return root(a) == root(b); } void unite(int a, int b){ P[root(a)] = root(b); } void link(int a, int b){ if(Rank[a] > Rank[b]){ P[b] = a; } else { P[a] = b; if(Rank[a] == Rank[b]) Rank[a]++; } } int main() { int n, q; int com, x, y; cin >> n >> q; init(n); for(int i = 0; i < q; i++){ cin >> com >> x >> y; if(com == 0) unite(x,y); else cout << IsSameSet(x,y) << endl; } return 0; }
0
50,013,501
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i=0; i < (int)(n); i++) using ull = unsigned long long; using ll = long long; using P = pair<int, int>; int main() { int x, y; cin >> x >> y; int ans = abs(abs(x) - abs(y)); if (x > y && y > 0) ans += 2; else if (x < 0 && 0 < y) ans++; else if (y <= 0 && 0 <= x) ans++; else if (y < x && x < 0) ans += 2; cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) #define REP(i,n) for (int64_t i=0; i<(n); ++i) #define P pair<int,int> using ll=int64_t; using namespace std; #define ketasuu(n) fixed<<setprecision(n) #define btoe(p) p.begin(),p.end() #define etob(p) p.rbegin(),p.rend() int main(){ int n; cin>>n; vector<int> p(n); rep(i,n) cin>>p[i]; int sum=0; rep(i,n-1){ sum+=abs(p[i]-p[i+1]); } sum+=abs(p[0]); sum+=abs(p[n-1]); if(p[0]*(p[1]-p[0])>=0){ cout<<sum<<endl; }else{ cout<<sum-2*min(abs(p[0]), abs(p[1]-p[0]))<<endl; } for(int i=1; i<n-1; ++i){ if((p[i-1]-p[i])*(p[i]-p[i+1])>=0){ cout<<sum<<endl; }else{ cout<<sum-2*min(abs(p[i-1]-p[i]), abs(p[i]-p[i+1]))<<endl; } } if((p[n-2]-p[n-1])*p[n-1]>=0){ cout<<sum<<endl; }else{ cout<<sum-2*min(abs(p[n-2]-p[n-1]), abs(p[n-1]))<<endl; } return 0; }
0
7,659,398
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<(int)(n);i++) int main() { int n; cin>>n; vector<char> s(n); vector<char> t(n); rep(i,n){ cin>>s[i]; } rep(i,n){ cin>>t[i]; } rep(i,n){ cout<<s[i]<<t[i]; } cout<<endl; }
#include<iostream> using namespace std; const int maxSize = 21; int mapData[maxSize][maxSize] = {0}; int W, H, Ans; void dfs(int hh, int ww) { if(mapData[hh][ww] == 1) { mapData[hh][ww] = 0; Ans++; if(hh+1<H && mapData[hh+1][ww]==1) { dfs(hh+1, ww); } if(ww+1<W && mapData[hh][ww+1]==1) { dfs(hh, ww+1); } if(0<=hh-1 && mapData[hh-1][ww]==1) { dfs(hh-1, ww); } if(0<=ww-1 && mapData[hh][ww-1]==1) { dfs(hh, ww-1); } } } int main() { while(cin>>W>>H && !(W==0 && H==0)) { int startW, startH; Ans = 0; for(int i=0; i<H; i++) { string str; cin>>str; for(int j=0; j<W; j++) { if(str[j] == '.') { mapData[i][j] = 1; } else if(str[j] == '#') { mapData[i][j] = -1; } else { mapData[i][j] = 1; startW = i; startH = j; } } } dfs(startW, startH); cout<<Ans<<endl; } }
0
37,264,476
#include <iostream> #include <vector> #include <algorithm> #include <string> #define MOD 1000000007 using namespace std; typedef long long ll; int main(void) { string s; int num, k = 1, i, j, l, r; ll ans = 1, ansr = 1; cin >> num >> s; vector<int> d(s.size() + 1, 0); l = 0; r = 0; for (i = 0; i < num * 2; i++) { if (s[i] == 'B') { if (d[i] & 1) { d[i + 1] = d[i] - 1; ans *= l - r; r++; } else { d[i + 1] = d[i] + 1; l++; } } else { if (d[i] & 1) { d[i + 1] = d[i] + 1; l++; } else { if (d[i] == 0) { ans = 0; break; } d[i + 1] = d[i] - 1; ans *= l - r; r++; } } if (l > num || r > num) { ans *= 0; break; } ans %= MOD; } for (i = 2; i <= num; i++) { ans *= i; ans %= MOD; } cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "/home/shahraaz/bin/debug.h" #else #define db(...) #endif using ll = long long; #define f first #define s second #define pb push_back #define all(v) v.begin(), v.end() const int NAX = 2e5 + 5, MOD = 1000000007; class Solution { private: public: Solution() {} ~Solution() {} void solveCase() { int a, b; cin >> a >> b; cout << 6 - a - b << '\n'; } }; int32_t main() { #ifndef LOCAL ios_base::sync_with_stdio(0); cin.tie(0); #endif int t = 1; Solution mySolver; for (int i = 1; i <= t; ++i) { mySolver.solveCase(); #ifdef LOCAL cerr << "Case #" << i << ": Time " << chrono::duration<double>(chrono::steady_clock::now() - TimeStart).count() << " s.\n"; TimeStart = chrono::steady_clock::now(); #endif } return 0; }
0
9,157,963
#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; typedef long long int lli; template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; } template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; } int dx[] = {1, 1, 0, -1, -1, -1, 0, 1}; int dy[] = {0, 1, 1, 1, 0, -1, -1, -1}; int main(){ int n, m; cin >> n >> m; vector<pair<int, int>> ab(n); rep(i,n) { int a, b; cin >> a >> b; ab[i] = make_pair(a, b); } sort(all(ab)); int i = 0; ll ans = 0; while(m){ ll num = min(m, ab[i].second); ans += ab[i].first * num; m -= num; i++; } cout << ans << endl; }
#include <iostream> #include <algorithm> using namespace std; int main(void){ int graph[100][100]; for( int i = 0 ; i < 100 ; i++ ) for( int j = 0 ; j < 100 ; j++ ) graph[i][j] = 0; int n; cin >> n; for( int i = 0 ; i < n ; i++ ){ int u, k; cin >> u >> k; u--; while( k-- ){ int v; cin >> v; v--; graph[u][v] = 1; } } for( int i = 0 ; i < n ; i++ ){ for( int j = 0 ; j < n ; j++ ){ if( j == n - 1 ) cout << graph[i][j] << endl; else cout << graph[i][j] << " "; } } return 0; }
0
13,875,525
#include <bits/stdc++.h> #define rep(i,n) for(long long i = 0; i < (long long)(n); ++i) using namespace std; using ll = long long; int main() { ll n, k, ans = 1; const ll mod = 7 + 1e9; cin >> n >> k; vector<int> s(n + 2); rep (i, n + 1) s[i + 1] = (s[i] + i + 1) % mod;; for (int i = k; i <= n; i++) { ans = (ans + 1 + s[n] - s[n - i] - s[i - 1]) % mod; } if (ans < 0) ans += mod; cout << ans << endl; return 0; }
#include <iostream> using namespace std; int main() { int n; int b, f, r, v; int room[4][3][10]; for (int j = 0; j < 4; j++){ for (int k = 0; k < 3; k++){ for (int l = 0; l < 10; l++){ room[j][k][l] = 0; } } } cin >> n; for (int i = 0; i < n; i++) { cin >> b >> f >> r >> v; room[b-1][f-1][r-1] += v; } for (int j = 0; j < 4; j++){ for (int k = 0; k < 3; k++){ for (int l = 0; l < 10; l++){ cout <<" " << room[j][k][l]; } cout << endl; } if(j != 3){for (int m = 0; m < 20; m++){ cout << "#"; } cout << endl;} } return 0; }
0
52,672,406
#include <iostream> #include <vector> #include <queue> #include <algorithm> #include <cmath> #include <iomanip> #include <map> #include <deque> #include <string.h> using namespace std; #define REP(i,n) for(int i = 0; i < n; i++) #define ALL(v) v.begin(),v.end() typedef long long ll; typedef pair<int,int> pi; typedef pair<ll,ll> pll; typedef pair<string,string> pss; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<pi> vpi; typedef vector<ll> vll; typedef vector<vll> vvll; double EPS = 1e-9; int INFi = 1000000005; long long INFll = 1000000000000000005ll; double PI = acos(-1); int dirx[8] = {-1,0,0,1,-1,-1,1,1}; int diry[8] = {0,1,-1,0,-1,1,-1,1}; ll MOD = 1000000007; const int MAX_N = 100000; const int MAX_M = 200000; struct edge{int to, cost;}; vector<edge> G[MAX_N]; int V[MAX_N]; int n, m; int l[MAX_M], r[MAX_M], d[MAX_M]; bool used[MAX_N]; bool dfs(int v) { if(used[v]) return true; used[v] = true; bool res = true; REP(i, G[v].size()){ if(used[G[v][i].to]) res = res & (G[v][i].cost == V[v] - V[G[v][i].to]); else { V[G[v][i].to] = V[v] - G[v][i].cost; res = res & dfs(G[v][i].to); } } return res; } int main(){ cin >> n >> m; REP(i, m) { cin >> l[i] >> r[i] >> d[i]; l[i]--; r[i]--; G[l[i]].push_back(edge{r[i], d[i]}); G[r[i]].push_back(edge{l[i], -d[i]}); } REP(i, n) used[i] = false; bool ans = true; REP(i, n) { if(!used[i]) V[i] = 0; ans = ans & dfs(i); } if(ans) cout << "Yes" << endl; else cout << "No" << endl; return 0; }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; const int INF = 1001001001; const int mod = 1000000007; int main(){ int n,k; cin >> n >> k; vector<int> v(n); rep(i,n) cin >> v.at(i); int ans = 0; for(int l = 0; l <= k;l++){ for(int r = 0; r <= k-l;r++){ if(l+r > n) continue; int d = k - l - r; int now = 0; vector<int> s; for(int i = 0; i < l;i++){ now += v.at(i); s.push_back(v.at(i)); } for(int i = n-r; i < n;i++){ now += v.at(i); s.push_back(v.at(i)); } sort(s.begin(),s.end()); for(int i = 0;i < d;i++){ if(i >= s.size()) break; if(s.at(i) >= 0) break; now -= s.at(i); } ans = max(ans,now); } } cout << ans << endl; }
0
18,851,081
#include <iostream> #include <string> using namespace std ; using ll = long long ; int main(){ string s,t ; cin >> s >> t ; ll n = t.size() ; for(int i=s.size()-n;i>=0;i--){ bool ok = true ; for(int j=0;j<n;j++){ if(s.at(i+j)!='?'&&s.at(i+j)!=t.at(j)){ ok = false ; break ; } } if(ok){ for(int j=0;j<n;j++){ s.at(i+j) = t.at(j) ; } for(int j=0;j<s.size();j++) cout << (s.at(j)=='?'?'a':s.at(j)) ; cout << endl ; return 0 ; } } cout << "UNRESTORABLE\n" ; }
#include <iostream> #include <fstream> #include <bits/stdc++.h> #define se cout << "test ok" << endl; #define sp << " " << #define enl "\n"; using namespace std; using ll=long long; using ld=long double; ll mod = ll(1e9)+7; ll inf = ll(1e18); template<typename T1, typename T2> ll ceill(T1 a, T2 b){ return (a+b-1)/b; } void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; } void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; } template<typename T> inline bool chmax(T &a, T b){ if(a<b){a=b; return true;} return false; } template<typename T> inline bool chmin(T &a, T b){ if(a>b){a=b; return true;} return false; } template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ fill((T*)array, (T*)(array+N), val); } int dx[] = {1, 0, -1, 0, 1, -1, 1, -1}; int dy[] = {0, 1, 0, -1, 1, -1, -1, 1}; #ifndef INCLUDE_DEBUG_HPP #define INCLUDE_DEBUG_HPP #include <iostream> #include <vector> #include <map> using namespace std; namespace dbg { using ll = long long; class Debug { public: Debug(){} template<typename T> void vd(vector<T> vec); template<typename T> void vd2(vector<vector<T>> vec); template<typename T> void ad(T *arr, ll n); template<typename T, size_t N> void ad2(T (&arr)[N], ll n); template<typename T> void md(T mp); }; template<typename T> void Debug::vd(vector<T> vec) { for (auto vv : vec) cout << vv << " "; cout << endl; } template<typename T> void Debug::vd2(vector<vector<T>> vec) { for (auto vv : vec) for (auto vvv : vv) cout << vvv << " "; cout << endl; } template<typename T> void Debug::ad(T *arr, ll n) { for (int i = 0; i <= n; i++) cout << arr[i] << " "; cout << endl; } template<typename T, size_t N> void Debug::ad2(T (&arr)[N], ll n) { for (int i = 0; i <= N; i++) for (int j = 0; j <= n; j++) cout << arr[i][j] << " "; cout << endl; } template<typename T> void Debug::md(T mp) { cout << "key : value" << endl; for (auto const &m : mp) cout << m.first << " : " << m.second << endl; cout << endl; } } #endif using dbg::Debug; Debug debug; class CBBuBBBlesort { public: void solve(std::istream& in, std::ostream& out) { int n; in >> n; vector<ll> a(n); for(int i=0; i<n; i++){ in >> a[i]; } set<int> eve, odd; for(int i=0; i<n; i++){ if(i%2 == 0) eve.insert(a[i]); else odd.insert(a[i]); } sort(a.begin(), a.end()); int res = 0; for(int i=0; i<n; i++){ if(i%2 == 0){ if(eve.find(a[i]) == eve.end()) res++; } } out << res << endl; } }; int main() { CBBuBBBlesort solver; std::istream& in(std::cin); std::ostream& out(std::cout); solver.solve(in, out); return 0; }
0
76,805,556
#include <bits/stdc++.h> using namespace std; int main(){ string S;cin>>S; int l=S.size(); vector<bool> A(26,false); for(int i=0;i<l;i++) A.at(S.at(i)-'a')=true; int m=-1; for(int j=0;j<26;j++){ if(!A.at(j)){ m=j; break; } } if(m==-1) cout<<"None"<<endl; else cout<<(char)('a'+m)<<endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define ull unsigned long long #define ld long double #define lll __int128 #define vi vector<int> #define vl vector<ll> #define vvi vector<vector<int> > #define pii pair<int,int> #define piii pair<int,pair<int,int> > #define pll pair<ll,ll> #define vii vector<pii> #define min_pq priority_queue<int,vector<int>,greater<int> > #define sz(v) ((int)(v).size()) #define all(s) s.begin(),s.end() #define allr(s) s.rbegin(),s.rend() #define unq(c) (sort(all(c)), c.resize(distance(c.begin(),unique(all(c))))) #define get_pos(c,x) (lower_bound(all(c),x)-c.begin()) #define MS0(v) memset((v), 0, sizeof((v))) #define MS1(v) memset((v), -1, sizeof((v))) #define LEN(v) strlen(v) #define MP make_pair #define pb push_back #define pob pop_back #define ff first #define ss second #define sc scanf #define pf printf #define endl "\n" #define gcd(a, b) __gcd(a, b) #define lcm(a, b) ((a)*((b)/gcd(a,b))) #define shuffle(v) (random_shuffle(all(v))) #define min_ele(v) (*min_element(all(v))) #define max_ele(v) (*max_element(all(v))) #define is_equal(x, y) (abs(x-y)<eps) #define cnt_ele(v, x) (count(all(v), x)) #define sum_ele(v) (accumulate(all(v),0)) #define pro_ele(v) (accumulate(all(v),1, multiplies<int>())) #define init_range(v, x) (iota(all(v),x)) #define ran(a, b) ((((rand() << 15) ^ rand()) % ((b) - (a) + 1)) + (a)) inline int random(int _min, int _max) { static bool first = true; if (first) { srand(time(NULL)); first = false; } return _min + rand() % (( _max + 1 ) - _min); } #define TEST_CASE int ___T; cin>>___T; for(int cs=1;cs<=___T;cs++) #define PRINT_CASE cout << "Case " << cs << ": "; #define PRINT_CASEN cout << "Case " << cs << ":\n"; template<class T>inline bool read(T &x) {int c=getchar();int sgn=1;while(~c&&c<'0'||c>'9'){if(c=='-')sgn=-1;c=getchar();}for(x=0;~c&&'0'<=c&&c<='9';c=getchar())x=x*10+c-'0'; x*=sgn; return ~c;} #define vpf(v) for(int i=0;i<v.size();i++){cout<<v[i];if(i!=v.size()-1)cout<<" ";else cout<<"\n";} #define vsc(v) for(int i=0;i<v.size();i++)cin>>v[i]; #define FOR(i, a, b, stp) for(int i = (a); i <= (b); i+=stp) #define ROF(i, a, b, stp) for(int i = (a); i >= (b); i-=stp) #define intmx INT_MAX #define inf 1llu<<61 #define PI 3.14159265358979323846264338327950L #define MOD 1000000007 #define MAX 100010 #define eps 1e-9 inline ll exp(ll a, ll b) { a %= MOD; ll res = 1; while (b > 0) { if(b & 1) { res = res * a % MOD; } a = a * a % MOD; b >>= 1; } return res; } inline int add(int a, int b) { a += b; if(a >= MOD) a -= MOD; return a; } inline int sub(int a, int b) { a -= b; if(a < MOD) a += MOD; return a; } inline int multi(ll a, ll b) { a *= b; if(a >= MOD) a %= MOD; return a; } inline int on_bit(int N,int pos) {return N = N | (1<<pos);} inline int off_bit(int N,int pos) {return N = N & ~(1<<pos);} inline bool check_bit(ll N,int pos) {return (bool)(N & (1<<pos));} #define on_bit_cnt(x) (__builtin_popcount(x)) #define on_bit_cntll(x) (__builtin_popcountll(x)) #define start_clock clock_t tStart = clock() #define end_clock printf("\n>>Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC) #define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define fileio freopen("in.txt","r",stdin);freopen("out.txt","w",stdout) int main() { ll n, k; cin >> n >> k; ll ans = 0; for(ll i = k; i <= n+1; i++) { ll lo = (i*(i-1))/2; ll hi = ((n*(n+1))/2) - (((n-i) * (n-i+1))/2); ans += (hi-lo+1); if(ans > MOD) ans = ans % MOD; } cout << ans << "\n"; return 0; }
0
55,601,695
#include<bits/stdc++.h> using namespace std; #define int long long #define rep(i,n) for(int i=0;i<(n);i++) #define reps(i,a,b) for(int i=(a);i<(b);i++) #define pb push_back #define eb emplace_back #define all(v) (v).begin(),(v).end() #define fi first #define se second using vint=vector<int>; using pint=pair<int,int>; using vpint=vector<pint>; template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;} template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;} template<class A,class B> ostream& operator<<(ostream& ost,const pair<A,B>&p){ ost<<"{"<<p.first<<","<<p.second<<"}"; return ost; } template<class T> ostream& operator<<(ostream& ost,const vector<T>&v){ ost<<"{"; for(int i=0;i<v.size();i++){ if(i)ost<<","; ost<<v[i]; } ost<<"}"; return ost; } signed main(){ int N,K; cin>>N>>K; cout<<N-K+1<<endl; return 0; }
#include <iostream> #include <cstdio> #include <algorithm> #include <cmath> #include <vector> #include <list> #include <set> #include <map> #include <queue> #include <stack> #include <cctype> #include <cassert> #include <climits> #include <string> #include <bitset> #include <cfloat> #include <unordered_set> #pragma GCC optimize("Ofast") using namespace std; typedef long double ld; typedef long long int ll; typedef unsigned long long int ull; typedef vector<int> vi; typedef vector<char> vc; typedef vector<bool> vb; typedef vector<double> vd; typedef vector<string> vs; typedef vector<ll> vll; typedef vector<pair<int, int> > vpii; typedef vector<vector<int> > vvi; typedef vector<vector<char> > vvc; typedef vector<vector<string> > vvs; typedef vector<vector<ll> > vvll; #define rep(i,n) for(int i = 0; i < (n); ++i) #define rrep(i,n) for(int i = 1; i <= (n); ++i) #define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++) #define drep(i,n) for(int i = (n) - 1; i >= 0; --i) #define fin(ans) cout << (ans) << '\n' #define mp(p,q) make_pair(p, q) #define pb(n) push_back(n) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define Sort(a) sort(a.begin(), a.end()) #define Rort(a) sort(a.rbegin(), a.rend()) #define MATHPI acos(-1) #define itn int; int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 }; int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 }; template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } struct io { io() { ios::sync_with_stdio(false); cin.tie(0); } }; const int INF = INT_MAX; const ll LLINF = 1LL << 60; const ll MOD = 1000000007; const double EPS = 1e-9; signed main(void) { ll h, n, r; r = 0; ll sum = 0; cin >>h >>n; vll a(n); rep (i, n) { cin >>a[i]; sum += a[i]; } if (sum >= h) { cout <<"Yes"; return 0; } cout <<"No"; return 0; }
0
37,642
#include <bits/stdc++.h> using namespace std; using ll = long long; constexpr ll MOD = 1000000007; constexpr ll INF = 1ll<<60; struct UnionFind { vector<ll> par; UnionFind(ll N = 20001) : par(N) { for (ll i = 0; i < N; ++i) par[i] = i; } ll root(ll x) { if (par[x] == x) return x; else return par[x] = root(par[x]); } void unite(ll x, ll y) { ll rx = root(x); ll ry = root(y); if (rx == ry) return; else par[rx] = ry; } bool same(ll x, ll y) { return root(x) == root(y); } }; int main(int argc, char **argv) { ll n, m; cin >> n >> m; vector<ll> p(n); for (ll i = 0; i < n; ++i) cin >> p[i], --p[i]; UnionFind tree(n); for (ll i = 0; i < m; ++i) { ll a, b; cin >> a >> b; --a, --b; tree.unite(a, b); } ll cnt{0}; for (ll i = 0; i < n; ++i) { if (tree.same(i, p[i])) ++cnt; } std::cout << cnt << std::endl; }
#include<cstdio> #include<cmath> #include<algorithm> #include<iostream> #include<string> #include<vector> #include<map> #include<cstdlib> #include<iomanip> #include<queue> #include<set> #include <valarray> #include<stack> #include<sstream> #include<math.h> using namespace std; void Solution() { int n, x; while(cin>>n>>x) { int count = 0; if(n == 0 && x == 0) break; for(int a = 1; a <= n; a++) { for(int b = a + 1; b <= n; b++) { for(int c = b + 1; c <= n; c++) { if(a + b + c == x) count++; } } } cout<<count<<endl; } } int main() { Solution(); return 0; }
0
2,254,360
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int lcm(int a, int b) { return a * b / gcd(a, b); } int main() { cin.tie(0); ios::sync_with_stdio(0); int n;cin>>n; int ans;cin>>ans; for(int i=1;i<n;i++) { int a;cin>>a; ans=gcd(ans,a); } cout<<ans<<"\n"; return 0; }
#include <bits/stdc++.h> using namespace std; using ull = unsigned long long; using ll = long long; using lli = long long int; using ld = long double; using pa = pair<int,int>; using ppa = pair<pa,int>; #define SORT(v, n) sort(v, v+n); #define ALL(v) v.begin(),v.end() #define VSORT(v) sort(ALL(v)) #define GRESORT(v) sort(ALL(v),greater<ll>()) #define REVERSE(v) reverse(ALL(v)) #define overlap(v) v.erase(unique(ALL(v)),v.end()) #define debug(x) cout << #x << ": " << x << endl #define FOR(i,a,b) for(int i = (a); i < (b); i++) #define rep(i,n) FOR(i,0,n) #define RFOR(i,a,b) for(int i = (b-1); i >= a; i--) #define rrep(i,n) RFOR(i,0,n) #define INF INT_MAX #define SUP INT_MIN #define mins(a,b) a = min(a,b) #define maxs(a,b) a = max(a,b) const ll MOD = 1000000007; ll pow_mod(ll a,ll b,ll mod){ ll tmp = 1; a %= mod; if(b > 0){ tmp = pow_mod(a, b/2, mod); if(b % 2) tmp = (((tmp*tmp)%mod)*a)%mod; else tmp = (tmp*tmp)%mod; } return tmp; } int mm = 1000000; vector<bool> d(mm); void hoge(){ d[0] = d[1] = true; FOR(i,2,mm){ if(d[i]) continue; for(int j = 2; i*j <= mm; j++){ d[i*j] = true; } } } void solve() { vector<int> dp(mm,INF); int val; int m = 2; dp[0] = dp[1] = 0; hoge(); while(cin >> val){ if(dp[val] == INF){ FOR(i,m,val+1){ dp[i] = dp[i-1] + (!d[i] ? 1 : 0); } m = val; } cout << dp[val] << endl; } } int main(){ std::ios::sync_with_stdio(false); std::cin.tie(0); solve(); return 0; }
0
2,098,033
#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() { ll r, g, b, n, cnt = 0; cin >> r >> g >> b >> n; rep(i, n / r + 1) rep(j, n / g + 1) { if ((n - r * i - g * j) % b == 0 && 0 <= (n - r * i - g * j)) { cnt++; } } cout << cnt << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i,n) for(int i = 0; i < (n); i++) #define rrep(i,n) for(int i = (n); i > 0; i--) #define all(n) n.begin(), n.end() #define print(n) cout << n << endl int main(){ cin.tie(0); ios_base::sync_with_stdio(false); ll n,p; string s; cin >> n >> p >> s; vector<ll> mods(p); ll m=0,order=1,ans=0; rep(i,n){ if(p==2){ if((s[i]-'0')%2==0) ans+=i+1; }else if(p==5){ if((s[i]-'0')%5==0) ans+=i+1; }else{ m = (m + order * (s[n-1-i] - '0')) % p; mods[m]++; order = (order*10)%p; } } if(p==2 || p==5){ print(ans); }else{ mods[0]++; rep(i,p){ ans += mods[i]*(mods[i]-1)/2; } print(ans); } return 0; }
0
24,827,423
#include <cstdio> #include <iostream> using namespace std; int main(int argc, char const *argv[]) { int x, y; while(true) { cin >> x >> y; if (x == 0 && y == 0) { break; } else { if (x <= y) { printf("%d %d\n", x, y); } else { printf("%d %d\n", y, x); } } } return 0; }
#include <bits/stdc++.h> using namespace std; #define _GLIBCXX_DEBUG #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) using ll = long long; using ld = long double; #define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++) #define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++) #define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++) #define repr(i,n) for (ll i = (n-1); i>=0;i--) #define repr3(i,n) for(ll i = (n);i>0;i--) #define stlen(s) ll s.size()-1 #define all(v) v.begin(), v.end() #define cout(n) cout<<std::fixed<<std::setprecision(n) using Graph = vector<vector<int>>; #define INF1 INT_MAX; #define INF2 LLONG_MAX; #define PI 3.14159265358979323846; #define MOD 1000000007; long long gcd(long long a, long long b) { if (b == 0) { return a; } else { return gcd(b, a % b); } } long long gcd_vec(vector<long long> const &A) { int size = (int)A.size(); long long ret = A[0]; for (int i = 1; i < size; i++) { ret = gcd(ret, A[i]); } return ret; } int main() { int N; cin>>N; vector<ll> A(N); rep(i,N){ cin>>A[i]; } cout<<gcd_vec(A)<<endl; return 0; }
0
34,488,945
#include <bits/stdc++.h> using namespace std; int main(void) { cin.tie(0); ios::sync_with_stdio(false); long long int res = 0; long long int n; cin >> n; for(long long int i=1;i<=sqrt(n);i++) { if(n%i==0) { long long int a = i - 1; long long int b = (n/i) - 1; if(a==b) { if(a!=0) { if((n/a)==n%a) { res += a; } } } else { if(a!=0) { if((n/a)==n%a) { res += a; } } if(b!=0) { if((n/b)==n%b) { res += b; } } } } } cout << res << '\n'; return 0; }
#include<bits/stdc++.h> #include<algorithm> #include <fstream> #include <sstream> #include <string> using namespace std; #define pb push_back #define pf push_front #define pob pop_back #define pof pop_front #define is insert #define rep1(i,a,b) for(long long i=a;i<=b;i++) #define mp make_pair #define mh make_heap #define F first #define S second #define file ifstream fin("input.txt");ofstream fout("output.txt"); #define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define fr(n) for(long long i=0;i<n;i++) #define rep(i,a,b) for(long long i=a;i<b;i++) #define ALL(x) (x).begin(), (x).end() typedef long long int ll; typedef long double ld; #define lb lower_bound #define ub uper_bound #define bs lower_bound typedef pair<ll,ll> pairs; typedef vector<ll> vi; typedef vector<pairs> vpair; vi v[500000]; bool vis[500000]; void solve() { ll n,m,a,b; cin>>n>>m; fr(m) { cin>>a>>b; v[a].pb(b); v[b].pb(a); } ll ans[n+1]={0}; ans[1]=1; queue<int>q; q.push(1);vis[1]=1; while(!q.empty()) { ll a=q.front(); q.pop(); for(int i=0;i<v[a].size();i++) { ll ch=v[a][i]; if(!vis[ch]) { vis[ch]=1; ans[ch]=a; q.push(ch); } } } for(int j=1;j<=n;j++) { if(ans[j]==0) { cout<<"No"<<endl; return ; } } cout<<"Yes"<<endl; for(int i=2;i<=n;i++) { cout<<ans[i]<<endl; } } int main() { fast; solve(); }
0
39,219,843
#include <bits/stdc++.h> using namespace std; template <class T> T input() {T t; cin>>t; return t;} #define FOR(i,a,b) for (ll i = a; i < b; i++) #define REP(i,b) FOR(i,0,b) #define RFOR(i,a,b) for (ll i = a-1; i >= b; i--) #define RREP(i,a) RFOR(i,a,0) #define REPALL(i,x) for (ll i = 0; i < x.size(); i++) #define RREPALL(i,x) for (ll i = x.size()-1; i >= 0; i--) #define REPITR(itr,x) for (auto itr = (x).begin(); itr != (x).end(); itr++) #define ALL(x) (x).begin(), (x).end() #define SORT(x) sort(ALL(x)) #define MIN_ELEMENT(x) min_element(ALL(x)) #define MAX_ELEMENT(x) max_element(ALL(x)) #define COUNT(x,num) count(ALL(x), num) #define MEMSET(x,val) memset(x, val, sizeof(x)) #define CHMAX(a,b) a = max(a,b) #define CHMIN(a,b) a = min(a,b) #define debug(x) cerr<<__LINE__<<": "<<(#x)<<" = "<<(x)<<endl; void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;} void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;} void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;} #define e1 first #define e2 second #define newline putchar('\n') typedef long long ll; typedef unsigned long long ull; typedef vector<int> VI; typedef vector<vector<int>> VVI; typedef vector<ll> VLL; typedef vector<vector<ll>> VVLL; const int INF = 1e7; const ll MOD = 1e9 + 7; const double pi = 3.141592653589793; const VI dx = {1, 0, -1, 0}; const VI dy = {0, 1, 0, -1}; int main() { int n; cin>>n; ll ans = 0ll; VLL a; map<ll, ll> mp; REP(i,n) { a.push_back(input<int>()); mp[a[i]]++; } REPITR(itr,mp) { ans += itr->e2 * (itr->e2 - 1) / 2; } REP(i,n) { cout<<ans-mp[a[i]]*(mp[a[i]]-1)/2+(mp[a[i]]-1)*(mp[a[i]]-2)/2<<endl; } return 0; }
#include <bits/stdc++.h> #define mod 1000000007 #define INF LLONG_MAX #define ll long long #define ln cout<<endl #define Yes cout<<"Yes"<<endl #define NO cout<<"NO"<<endl #define YES cout<<"YES"<<endl #define No cout<<"No"<<endl #define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++) #define rep(i,n) REP(i,0,n) #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() using namespace std; ll dx[4]={1,0,-1,0}; ll dy[4]={0,1,0,-1}; int main() { cin.tie(0); ios::sync_with_stdio(false); ll a,b,c,d,e,n,k,maxi=0,f=0,mini=INF,sum=0,q; string str,g,ko; ll x,y; char hoge; cin>>n; REP(i,1,n+1){ sum+=800; if(i%15==0) sum-=200; } cout<<sum<<endl; return 0; }
0
44,104,328
#include<cstdio> #include<iostream> #include<algorithm> #include<cstring> using namespace std; int n,s; int Sum_of_Integers(int i,int sum,int v); int main(){ while(1){ cin >> n >> s; if(!n && !s)break; cout << Sum_of_Integers( 0 , 0 , -1) << endl; } } int Sum_of_Integers(int i,int sum,int v){ int ret = 0; if(i > n || sum > s)return 0; if(i == n && sum == s)return 1; for(int j=0;j<=9;j++){ if(v<j)ret += Sum_of_Integers( i + 1, sum + j , j ); } return ret; }
#include<bits/stdc++.h> using namespace std; #define ll long long using vvll = vector<vector<ll>>; ll mod =1000000007; template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;} 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 ctoi(char c) {return c-'0';} int gcd(ll a,ll b){return b?gcd(b,a%b):a;} int lcm(ll a,ll b){return a*b/gcd(a,b);} bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}} string reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;} int main(){ int n; cin >> n; vector<int>a(n); for(int i=0;i<n;i++){ cin >> a.at(i);} ll che = abs(a.at(n-1))+abs(a.at(0)); for(int i=1;i<n;i++){ che+=abs(a.at(i-1)-a.at(i)); } for(int i=0;i<n;i++){ if(i==0){ ll ans = che; ans-=abs(a.at(i)); ans-=abs(a.at(i)-a.at(i+1)); ans+=abs(a.at(i+1)); cout <<ans<<endl; continue; } if(i==n-1){ ll ans = che; ans-=abs(a.at(i)); ans-=abs(a.at(i)-a.at(i-1)); ans+=abs(a.at(i-1)); cout<< ans<<endl; continue; } ll ans = che; ans-=abs(a.at(i)-a.at(i-1)); ans-=abs(a.at(i)-a.at(i+1)); ans+=abs(a.at(i-1)-a.at(i+1)); cout << ans<<endl; } }
0
19,467,934
#include <utility> #include <iostream> #include <algorithm> using namespace std; int v,A[100][100],u,k,w; int main(){ cin >> v ; for (int i=0; i<v; ++i){ cin >> u >> k; for(int j=0; j<k; ++j){ cin >> w; A[u-1][w-1] = 1; } } for (int i=0; i<v; ++i){ for (int j=0; j<v; ++j){ cout << A[i][j]; if (j < v-1) cout << " "; } cout << endl ; } }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; using ll = long long; int main() { int H, W; cin >> H >> W; vector<string> a(H); rep(i, H) cin >> a[i]; vector<bool> row(H, false); vector<bool> col(W, false); rep(i, H) { rep(j, W) { if (a[i][j] == '#') { row[i] = true; col[j] = true; } } } rep(i, H) { if (row[i]) { rep(j, W) { if (col[j]) { cout << a[i][j]; } } cout << endl; } } return 0; }
0
76,225,353
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++) #define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--) #define rep(i,n) FOR(i,0,n) #define rrep(i,n) RFOR(i,0,n) #define ALL(v) v.begin(), v.end() #define bra(first,second) '(' << first << ',' << second << ')' ll MOD = 1000000007; ll INF = 100100100100100100; long double EPS = 1e-11; long double PI = 3.141592653589793238; template<typename T> void remove(std::vector<T>& vector, unsigned int index){ vector.erase(vector.begin() + index); } using Graph = vector<vector<ll>>; int main(){ ll N; string S; ll K; cin >> N >> S >> K; rep(i,N){ if(S[i] != S[K-1]) S[i] = '*'; } cout << S << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define REP(i,n) for(ll i=0;i<ll(n);i++) #define REPD(i,n) for(ll i=n-1;i>=0;i--) #define FOR(i,a,b) for(ll i=a;i<=ll(b);i++) #define FORD(i,a,b) for(ll i=a;i>=ll(b);i--) #define ALL(x) x.begin(),x.end() #define SIZE(x) ll(x.size()) #define INF 1000000000000 #define MOD 1000000007 #define MAXR 100000 #define PB emplace_back #define MP make_pair #define F first #define S second #define Umap unordered_map #define Uset unordered_set int main(){ ll n, k; cin >> n >> k; double ans = 0; REP(i, n){ ll j = i + 1; while(j < k) j *= 2; ans += 1 / (double(j) / double(i+1)); } cout << fixed << setprecision(11) << ans / double(n); return 0; }
0
94,053,654
#include <bits/stdc++.h> #define rep(i,n) for(int i=0; i<(n); i++) using namespace std; using ll = long long; using v = vector<int>; using P = pair<int,int>; using vp = vector<P>; using vvp = vector<vp>; int main(){ int n; string s; cin>>n>>s; ll r=0,g=0,b=0; rep(i,n){ if(s[i]=='R')r++; else if(s[i]=='G')g++; else b++; } ll del = 0; for(int i=0; i<n; i++){ for(int j=i+1; j<n; j++){ if(j+(j-i)>=n)continue; if(s[i]==s[j])continue; if(s[j]==s[j+j-i])continue; if(s[i]==s[j+j-i])continue; del++; } } cout << r*g*b - del << endl; return 0; }
#include <iostream> #include <vector> #include <string> #include <map> #include <algorithm> #include <queue> #define REP(i,n) for(int i=0;i<(int)(n);i++) using namespace std; int main() { while(1){ int w,h; cin>>w>>h; if(!w)break; vector<string> t(h); REP(i,h)cin>>t[i]; int si,sj; REP(i,h)REP(j,w){ if(t[i][j] == '@'){ si = i; sj = j; } } vector<vector<bool>> vis(h,vector<bool>(w,false)); vis[si][sj] = true; queue<pair<int,int>> q; q.push(make_pair(si,sj)); while(!q.empty()){ auto p = q.front();q.pop(); int i,j; tie(i,j) = p; int di[] = {1,0,-1,0}; int dj[] = {0,1,0,-1}; REP(k,4){ int ni=i+di[k]; int nj=j+dj[k]; if(ni<0||ni>=h||nj<0|nj>=w)continue; if(t[ni][nj] == '#')continue; if(vis[ni][nj]) continue; q.push(make_pair(ni,nj)); vis[ni][nj] = true; } } int cnt = 0; REP(i,h)REP(j,w){ if(vis[i][j])++cnt; } cout << cnt << endl; } return 0; }
0
70,399,806
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using P = pair<int, int>; typedef long long ll; int main() { int n, k, s; cin >> n >> k >> s; rep(i,n){ if(i < k){ cout << s << (i == n - 1 ? "\n" : " "); }else { if(s == 1000000000){ cout << s - 1 << (i == n - 1 ? "\n" : " "); }else { cout << s + 1 << (i == n - 1 ? "\n" : " "); } } } return 0; }
#include <bits/stdc++.h> using namespace std; struct edge{int to;int cost;}; vector<edge> tree[100010]; vector< int> d(100010 , -1e9); bool f; void bfs(int s){ queue<int> q; q.push(s); d[s]=0; while(!q.empty()){ int p=q.front(); q.pop(); for(auto x:tree[p]){ int u=x.to,v=x.cost; if(d[u]==-1e9){ d[u]=d[p]+v; q.push(u); } else{ if(d[u]!=d[p]+v){ f=false; } } } } } int main(){ int n,m; cin >> n >> m; for(int i=0;i<m;i++){ int l,r,d; cin >> l >> r >> d; l--,r--; tree[l].push_back({r,d}); tree[r].push_back({l,-d}); } f=true; for(int i=0;i<n;i++){ if(d[i]!=-1e9){ continue; } bfs(i); if(!f){ cout << "No" << endl; return 0; } } cout << "Yes" << endl; }
0
14,858,617
#include <bits/stdc++.h> using namespace std; using ll = long long; using db = double; #define fi first #define se second #define pb push_back #define eb emplace_back #define all(v) (v).begin(), (v).end() #define siz(v) (ll)(v).size() #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define repi(i, x, n) for (ll i = x; i < (ll)(n); i++) typedef pair<int, int> P; typedef pair<ll, ll> PL; const ll mod = 1000000007; const ll INF = 100000000000000099; vector<ll> dx = {-1, 1, 0, 0}, dy = {0, 0, -1, 1}; ll dp[200020][2] = {}; const ll MAX = 200030; long long fac[MAX], finv[MAX], inv[MAX]; void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++){ fac[i] = fac[i - 1] * i % mod; inv[i] = mod - inv[mod%i] * (mod / i) % mod; finv[i] = finv[i - 1] * inv[i] % mod; } } signed main() { COMinit(); ll n; cin >> n; string s; cin >> s; dp[0][0] = 1; ll nofk = 0; for (int i = 1; i <= 2*n; i++) { if (s.at(i - 1) == 'B') { dp[i][0] = 0; if (nofk%2==0) { dp[i][1] = dp[i - 1][1]+dp[i-1][0]; nofk++; } else { dp[i][1] = ((dp[i - 1][1]+dp[i-1][0])%mod) * nofk; nofk--; } } else { dp[i][1] = 0; if (nofk%2==1) { dp[i][0] = dp[i - 1][1]+dp[i-1][0]; nofk++; } else{ dp[i][0] = ((dp[i - 1][1]+dp[i-1][0])%mod) * nofk; nofk--; } } dp[i][0]%=mod; dp[i][1]%=mod; if(nofk<0 || (nofk!=0 && i==2*n)){ cout<<0<<endl; return 0; } } cout << ((dp[2 * n][1]%mod)*(fac[n]%mod))%mod << endl; }
#include <bits/stdc++.h> 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();} typedef long long ll; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<long long> VL; typedef vector<vector<long long>> VVL; typedef vector<string> VS; typedef pair<ll, ll> P; typedef tuple<int,int,int> tpl; #define ALL(a) (a).begin(),(a).end() #define SORT(c) sort((c).begin(),(c).end()) #define REVERSE(c) reverse((c).begin(),(c).end()) #define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin() #define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin() #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i) #define RREP(i,n) RFOR(i,n,0) #define en "\n" const double EPS = 1e-9; const double PI = acos(-1.0); const int INF = 2147483647; const long long LINF = 1LL<<60; const long long MOD = 1000000007; #define CLR(a) memset((a), 0, sizeof(a)) #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; 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(void){ ll W,H; cin >> W >> H; VL p(W), q(H); REP(i,W) cin >> p[i]; REP(i,H) cin >> q[i]; priority_queue<P,vector<P>,greater<P>> que; REP(i,W) que.push(P(p[i],0)); REP(i,H) que.push(P(q[i],1)); ll ans = 0; ll mx = (H+1)*(W+1) - 1, nx = 0, ny = 0; while(mx > 0){ P a = que.top(); que.pop(); ll cost = a.first; if(a.second){ ans += cost * (W+1 - nx); ny++; mx -= W+1 - nx; } else{ ans += cost * (H+1 - ny); nx++; mx -= H+1 - ny; } } cout << ans << endl; return 0; }
0
48,678,047
#include<stdio.h> int main(){ int n,x; while(true){ scanf("%d%d",&n,&x); if (n==0&&x==0)break; int a=0; for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ for(int k=1;k<=n;k++){ if(i+j+k==x&&i<j&&j<k){ a++; } } } } printf("%d\n",a); } }
#include <iostream> #include <string> #include <algorithm> #include <cmath> #include <math.h> #include <stdlib.h> using namespace std; int main(){ int n; while(cin>>n){ if(n==0) break; string s[n][2]; for(int i=0;i<n;i++){ cin>>s[i][0]>>s[i][1]; } int t; cin>>t; for(int i=0;i<t;i++){ string a; cin>>a; for(int j=0;j<n;j++){ if(s[j][0]==a){ cout<<s[j][1]; goto end; } } cout<<a; end:; } cout<<endl; } return 0; }
0
20,391,318
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { int n, m; cin >> n; vector<string> blue(n); for (int i = 0; i < n; i++) { cin >> blue.at(i); } cin >> m; vector<string> red(m); for (int i = 0; i < m; i++) { cin >> red.at(i); } int max_point=0; for (int i = 0; i < n; i++) { int point = 0; string word = blue.at(i); for (int j = 0; j < n; j++) { if (blue.at(j) == word) { point++; } } for (int k = 0; k < m; k++) { if (red.at(k) == word) { point--; } } if (point > max_point) { max_point = point; } } cout << max_point << endl; }
#include<bits/stdc++.h> #define int long long using namespace std; signed main(){ int ichi=0; int ni=0; int san=0; int yon=0; for(int i=0;i<3;i++){ int a,b; cin>>a>>b; if(a==1||b==1){ ichi++; } if(a==2||b==2){ ni++; } if(a==3||b==3){ san++; } if(a==4||b==4){ yon++; } } if(max({ichi,ni,san,yon})==2){ cout<<"YES"<<endl; } else{ cout<<"NO"<<endl; } }
0
46,063,533
#include <bits/stdc++.h> using namespace std; int n, s; int a[200020]; long long z; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } for (int i = 0, j = 0; i < n; s ^= a[i++]) { while (j < n && (s & a[j]) == 0) { s ^= a[j++]; } z += j - i; } printf("%lld\n", z); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; const ll MOD = 1000000007; const ld PI = acos(-1); const ld EPS = 0.0000000001; int main(){ string s, t; cin >> s >> t; int n=s.size(); vector<set<char>> key(26); for(int i=0; i<n; i++) key[t[i]-'a'].insert(s[i]); string ans="Yes"; for(int i=0; i<26; i++) if(1<key[i].size()) ans = "No"; key = vector<set<char>> (26); for(int i=0; i<n; i++) key[s[i]-'a'].insert(t[i]); for(int i=0; i<26; i++) if(1<key[i].size()) ans = "No"; cout << ans << endl; }
0
86,812,525
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { vector<vector<int>> a(3, vector<int>(3)); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { cin >> a[i][j]; } } int n; cin >> n; vector<int> b(n); for (int i = 0; i < n; i++) { cin >> b[i]; } vector<vector<int>> bingo(3, vector<int>(3)); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { bingo[i][j] = 0; for (int k = 0; k < n; k++) { if (a[i][j] == b[k]) { bingo[i][j] = 1; } } } } string ans = "No"; for (int i = 0; i < 3; i++) { if (bingo[i][0] && bingo[i][1] && bingo[i][2]) { ans = "Yes"; } if (bingo[0][i] && bingo[1][i] && bingo[2][i]) { ans = "Yes"; } } if (bingo[0][2] && bingo[1][1] && bingo[2][0]) { ans = "Yes"; } if (bingo[0][0] && bingo[1][1] && bingo[2][2]) { ans = "Yes"; } cout << ans << endl; }
#include<iostream> #include<vector> #include<algorithm> #include<string> #include<map> #include<cstdio> using namespace std; map<char,int>M; int cnv(string str){ str="."+str; int res=0; for(int i=0;i<str.length();i++){ if(M.find(str[i])!=M.end()){ int a; if(str[i-1]>='0'&&str[i-1]<='9'){ a=str[i-1]-'0'; } else a=1; res+=M[str[i]]*a; } } return res; } int main(){ M['m']=1000;M['c']=100;M['x']=10;M['i']=1; int n; scanf("%d",&n); while(n--){ string s1,s2; cin>>s1>>s2; int val=cnv(s1)+cnv(s2); if(val/1000){ if(val/1000>1)printf("%d",val/1000); printf("m"); } val%=1000; if(val/100){ if(val/100>1)printf("%d",val/100); printf("c"); } val%=100; if(val/10){ if(val/10>1)printf("%d",val/10); printf("x"); } val%=10; if(val){ if(val>1)printf("%d",val); printf("i"); } puts(""); } return 0; }
0
79,373,271
#include "bits/stdc++.h" using namespace std; int main() { int N, A, B, C; cin >> N >> A >> B >> C; vector<int>L(N); for (int n = 0;n<N;++n) { cin >> L[n]; } int ans = 1e9; for (int n = 0;n<(1<<2*N);++n) { int a = 0; int b = 0; int c = 0; int count = 0; int anstmp = 0; for (int m = 0;m<N;++m) { int tmp = (n>>(2*m))&3; if (0 == tmp) { a += L[m]; count++; } else if (1 ==tmp) { b += L[m]; count++; } else if ( 2== tmp){ c += L[m]; count++; } } count -= 3; if ((0 == a)||(0==b)||(0==c)) { continue; } anstmp += abs(a - A) + abs(b - B) + abs(c - C) + 10*count; ans = min(ans,anstmp); } cout << ans <<endl; }
#include "bits/stdc++.h" #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; #define ub upper_bound #define lb lower_bound #define isrt insert #define clr clear #define rsz resize #define ff first #define ss second #define lli long long int #define pb push_back #define pf push_front #define mkp make_pair #define pii pair<int,int> #define vi vector<int> #define mii map<lli,lli> #define pqb priority_queue<int> #define pqs priority_queue<int,vi,greater<int> > #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define mod 1000000007 #define INF 1e9 #define ps(x,y) fixed<<setprecision(y)<<x #define mk(arr,n,type) type *arr=new type[n]; #define w(x) int x; cin>>x; while(x--) #define all(v) v.begin(),v.end() #define endl "\n" typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; lli maxm(lli a, lli b) { return (a >= b ? a : b); } lli minm(lli a, lli b) { return (a <= b ? a : b); } lli power(lli x, lli y, lli p) { lli res = 1; x = x % p; if (x == 0) return 0; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } lli nCrmodp(lli n, lli r, lli p) { if (r == 0) return 1; if (r == 1) return n; lli pro = 1, k = n; while (k > r) { pro *= k; pro %= p; --k; } k = 2; while (k <= (n - r)) { pro *= power(k, (p - 2), p); pro %= p; ++k; } return pro; } string num_str(lli n, lli k) { string str = ""; lli x = n; while (x != 0) { string s = to_string(x % k); str = s + str; x /= k; } return str; } lli first_big(lli n, lli k, lli arr[]) { lli l = 0; lli r = n - 1; lli leftGreater = n; while (l <= r) { lli m = l + (r - l) / 2; if (arr[m] > k) { leftGreater = m; r = m - 1; } else l = m + 1; } return leftGreater; } void c_p_c() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } lli dp[110][100010]; vector<lli> arr; vector<lli> pref_sum; vector<lli> pr; int main() { c_p_c(); lli n, k, s = 0, l, r; memset(dp, -1, sizeof(dp)); cin >> n >> k; arr.rsz(n + 1); pref_sum.rsz(n + 1); for (int i = 0; i <= n; ++i) dp[i][0] = 1; for (int i = 1; i <= k; ++i) dp[0][i] = 0; for (int i = 1; i <= n; ++i) { cin >> arr[i]; s += arr[i]; pref_sum[i] = s; } for (int i = 1; i <= n; ++i) { pr.clr(); pr.rsz(k + 1); s = 0; for (int j = 0; j <= k; ++j) { s += dp[i - 1][j]; s %= mod; pr[j] = s; } for (int j = 0; j <= k; ++j) { if (j <= arr[i]) dp[i][j] = pr[j]; else { if (j > pref_sum[i]) dp[i][j] = 0; else { l = (j - arr[i]); r = j; dp[i][j] = (pr[r] - pr[l - 1] + mod) % mod; } } } } cout << dp[n][k] << endl; return 0; }
0
21,648,085
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n,a,b; cin >> n>>a>>b; cout << (((b-a) % 2) ? "Borys" : "Alice") << '\n'; return (0); }
#include <bits/stdc++.h> using namespace std; bool desc(int a,int b){ return a>b; } int main(){ int n; cin>>n; int a[n],b[n],d1=0,d2=0; string aa,bb,df; for(int i = 1 ; i <= n ; i++){ df+=i+'0'; } for(int i = 0 ; i < n ; i++){ cin>>a[i]; aa += a[i]+'0'; } for(int i = 0 ; i < n ; i++){ cin>>b[i]; bb += b[i]+'0'; } while(1){ if(aa==df) break; prev_permutation(aa.begin(), aa.end()); d1++; }while(1){ if(bb==df) break; prev_permutation(bb.begin(), bb.end()); d2++; } cout<<abs(d1-d2); return 0; }
0
68,131,011
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int INF = 101234567; int main() { ll N; ll ans = 0; vector<ll>v; cin >> N; for (int k = 1; k < (double)sqrt(N); k++) { if (N % k == 0) { ll m = N/k - 1; if (m > k) { ans += m; } } } cout << ans << endl; }
#include<bits/stdc++.h> #define ll long long #define P pair<ll ,ll> using namespace std; int main(){ int n,k; cin >> n >> k; int r,s,p; cin >> r >> s >> p; string t; cin >> t; ll ans = 0; vector<char>was(n ,'x'); for(int i=0;i<n;i++){ if(i-k >=0){ if(was[i-k]!='r' && t[i]=='r'){ ans += p; was[i] = 'r'; } if(was[i-k]!='s' && t[i]=='s'){ ans += r; was[i] = 's'; } if(was[i-k]!='p' && t[i]=='p'){ ans += s; was[i] = 'p'; } }else{ if( t[i]=='r'){ ans += p; was[i] = 'r'; } if( t[i]=='s'){ ans += r; was[i] = 's'; } if( t[i]=='p'){ ans += s; was[i] = 'p'; } } } cout << ans << endl; }
0
17,000,982
#include <iostream> int main() { int n, r; std::cin >> n >> r; int ans = r; if (n < 10) ans = r + 100 * (10 - n); std::cout << ans << std::endl; return 0; }
#include <iostream> #include <algorithm> #include <cmath> #include <string> #include <vector> #include <map> #include <set> #include <queue> #include <stack> #include <bitset> #include <cassert> #define int long long #define rep(i,n) for(int i=0;i<n;i++) #define srep(i,n,m) for(int i=n;i<m;i++) #define elif else if #define INF 1000000007 #define pi 3.141592653589793 using namespace std; int sdkys(int a,int b){ if(b==0) return a; return sdkys(b,a%b); } int sskbs(int a,int b){ return a*b/sdkys(a,b); } int sosu(int a){ if(a==2){ return 1; } for(int i=2;i<sqrt(a)+1;i++){ if(a%i==0){ return 0; } } return 1; } int n,m,cnt=0,aa[220000],ans=0; pair<int,int> pp[220000]; string s,sa[220000]; char c; queue<int> que; signed main(){ cin>>s; rep(i,(s.size()+1)/2-1){ rep(j,i+1){ if(s[j]!=s[j+i+1]){ goto no; } } cnt=(i+1)*2; no:; } cout<<cnt<<endl; }
0
52,773,037
#include<iostream> #include<string> #include<vector> #include<algorithm> #include<bitset> #include<set> #include<map> #include<stack> #include<queue> #include<deque> #include<list> #include<iomanip> #include<cmath> #include<cstring> #include<functional> using namespace std; #define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define rep(i, n) repr(i, 0, n) #define INF 2e9 #define MOD 998244353 #define LINF (long long)4e18 #define jck 3.141592 using ll = long long; using Pi = pair<int,int>; using Pl = pair<ll,ll>; int main(){ int N; cin >> N; vector<int> a(N); rep(i,N) cin >> a[i]; ll ans = 0; int now = 1; int M = 1; rep(i,N){ int d = 0; int cnt = 0; if(i != 0 && a[i] % now == 0){ if(a[i] >= now+1){ a[i] -= now+1; d++; cnt++; } } d += (a[i]+now-1)/now-1; ans += d; int r = a[i]-(d-cnt)*now; now = max(r+1,M); M = max(r+1,M); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; using P = pair<ll,ll>; const ll mod = 1e9+7; #define ALL(x) (x).begin(),(x).end() #define pow(x,y) modpow(x,y) #define REP(i,n) for(ll (i)=0;(i)<(n);(i)++) #define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++) #define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--) #define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--) #define pb push_back #define mp make_pair #define F first #define S second #define UNIQUE(v) v.erase(unique(ALL(v)),v.end()); template<class T> inline void chmin(T& a, T b){ if (a > b){ a = b; } } template<class T> inline void chmax(T& a, T b){ if (a < b){ a = b; } } signed main(){ cin.tie(0); ios::sync_with_stdio(false); cout<<fixed<<setprecision(10); int A,B,X; cin >> A >> B >> X; X -= A; bool ok = 1; if(X < 0)ok = 0; if(X > B)ok = 0; cout << (ok ? "YES" : "NO") << "\n"; }
0
49,155,236
#include <iostream> #include <string.h> using namespace std; int main() { string alphabet; cin >> alphabet; if(alphabet[0] >= 'A' && alphabet[0] <= 'Z') { cout << "A" << endl; } if(alphabet[0] >= 'a' && alphabet[0] <= 'z') { cout << "a" << endl; } }
# include <iostream> # include <map> using namespace std; int main() { int n; cin >> n; map<string, int> cnt_map; string ans = "Yes"; char last_char = '\0'; for (int i = 0; i < n; i++) { string s; cin >> s; if (last_char != '\0' && last_char != s[0]) { ans = "No"; break; } last_char = s[s.size() - 1]; if (cnt_map[s] != 0) { ans = "No"; break; } ++cnt_map[s]; } cout << ans << endl; return 0; }
0
82,987,523
#include<bits/stdc++.h> using namespace std; int main(){ int n; cin >> n; vector<int> w(n); for(int i = 0; i < n; i++) cin >> w[i]; int ans = 1e9; for(int i = 1; i < n; i++){ int l = 0, r = 0; for(int j = 0; j < i; j++){ l += w[j]; } for(int j = i; j < n; j++){ r += w[j]; } ans = min(ans, abs(l - r)); } cout << ans << endl; return 0; }
#include <functional> #include <algorithm> #include <iostream> #include <numeric> #include <iomanip> #include <utility> #include <cstdlib> #include <sstream> #include <bitset> #include <vector> #include <cstdio> #include <ctime> #include <queue> #include <deque> #include <cmath> #include <stack> #include <list> #include <map> #include <set> using namespace std; typedef vector<int> vi; typedef pair<int,int> pii; typedef long long ll; #define dump(x) cerr << #x << " = " << (x) << endl #define rep(i,n) for(int i=0;i<(n);i++) #define all(a) (a).begin(),(a).end() #define pb push_back int main() { int n; int times[101]={}; while(cin>>n){ if(n==0)break; times[n]++; } int maxi=-1; rep(i,100+1){ maxi=max(maxi,times[i]); } rep(i,100+1){ if(times[i]==maxi){ cout<<i<<endl; } } return 0; }
0
99,444,605
#define _GLIBCXX_DEBUG #include<bits/stdc++.h> using namespace std; typedef long long int lli; typedef unsigned long long int ulli; typedef long double ld; #define vec(s) vector<s> #define vvec(s) vector<vector<s>> typedef vector<lli> vi; typedef vector<vi> vvi; typedef pair<lli,lli> pii; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define Yes(x) cout<<(x?"Yes":"No")<<endl; #define YES(x) cout<<(x?"YES":"NO")<<endl; #define out(s) cout<<s<<endl; #define pb(s) push_back(s); #define sp " " #define INF 10000000000 #define LINF 9000000000000000000 #define all(s) s.begin(),s.end() void vout(vi v){ for(lli i=0;i<v.size();i++) cout<<v.at(i)<<endl; } int main(){ cout << std::fixed << std::setprecision(10); string s; cin>>s; lli i=0; lli ans=0; if(s.size()==1){ out(0); return 0; } while (true){ if(i>=s.size()-1){ break; } if(s[i]!=s[i+1]){ ans+=2; if (i+1<s.size()-1) { s.erase(i, 2); i=0; } else{ break; } } else{ i++; } } out(ans); }
#include <bits/stdc++.h> using namespace std; #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define ALL(a) (a).begin(),(a).end() #define RALL(a) (a).rbegin(),(a).rend() #define PRINT(a) cout << (a) << endl #define pb push_back #define eb emplace_back #define mp make_pair #define Fi first #define Se second #define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n'; using ll = long long int; using P = pair<int,int>; using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>; using pii = pair<int, int>; template <typename T> using PQ = priority_queue<T>; template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } const int INF = 1001001001; const ll LINF = 1001001001001001001ll; const int MOD = 998244353; int main(){ int n; cin >> n; vi d(n,0); int mx=0; REP(i,n){ int x; cin >> x; if(i==0 && x != 0){ cout << 0 << endl; return 0; } d[x]++; chmax(mx,x); } ll ans=1; if(d[0] != 1){ cout << 0 << endl; return 0; } REP(i,mx+1){ ll tmp=1; REP(j,d[i+1]){ tmp *= d[i]; tmp %= MOD; } ans *= tmp; ans %= MOD; } cout << ans << endl; }
0
50,563,393
#include <iostream> #include <algorithm> #include <string> #include <vector> #include <climits> #include <cmath> #include <map> #include <queue> #include <iomanip> using namespace std; #define rep(i,n) for(int (i)=0;(i)<(n);(i)++ ) #define repf(i,m,n) for(int (i)=m;(i)<n;(i)++) #define all(v) (v).begin(), (v).end() #define ll long long #define vec(name,num) vector<ll> name((num),0); #define op(i) cout<<(i)<<endl; #define ip(i) cin>>(i); #define opN cout<<"No"<<endl; #define opY cout<<"Yes"<<endl; #define opP cout<<"Possible"<<endl; #define opI cout<<"Impossible"<<endl; #define mat(name,fnum,snum); vector<vector<ll>> name((fnum),vector<ll>((snum),0)); #define matC(name,fnum,snum); vector<vector<char>> name((fnum),vector<char>((snum),0)); #define debugP int debug_point; cin>>debug_point; #define FI first #define SE second const ll MOD= 1e9 + 7; template <typename T> void putv(vector<T>& V){ for(auto x: V) cout << x << " "; cout << endl; } ll pow_mod(ll fi,ll se,ll mod){ if(se==0){ return 1; } if(se%2){ return pow_mod(fi,se-1,mod)*fi%mod; } ll t=pow_mod(fi,se/2,mod); return t*t%mod; } template <class T> vector<T> getv(ll n){ vector<T> Vector_temp; rep(i,n){ T input; cin >> input; Vector_temp.emplace_back(input); } return Vector_temp; } ll gcd(ll c,ll b){ while(1){ if(c%b!=0){ ll tmp=b; b=c%b; c=tmp; }else{ return b; } } } vector<pair<int,int>> Dir={{-1,0},{1,0},{0,1},{0,-1}}; int main(){ ll n; cin>>n; op((n-2)*180); return 0; }
#include "bits/stdc++.h" using namespace std; #define int long long #define pb push_back #define ppb pop_back #define pf push_front #define ppf pop_front #define all(x) (x).begin(),(x).end() #define uniq(v) (v).erase(unique(all(v)),(v).end()) #define sz(x) (int)((x).size()) #define fr first #define sc second #define pii pair<int,int> #define rep(i,a,b) for(int i=a;i<b;i++) #define mem1(a) memset(a,-1,sizeof(a)) #define mem0(a) memset(a,0,sizeof(a)) #define ppc __builtin_popcount #define ppcll __builtin_popcountll template<typename T1,typename T2>istream& operator>>(istream& in,pair<T1,T2> &a){in>>a.fr>>a.sc;return in;} template<typename T1,typename T2>ostream& operator<<(ostream& out,pair<T1,T2> a){out<<a.fr<<" "<<a.sc;return out;} template<typename T,typename T1>T amax(T &a,T1 b){if(b>a)a=b;return a;} template<typename T,typename T1>T amin(T &a,T1 b){if(b<a)a=b;return a;} const long long INF=1e18; const int32_t M=1e9+7; const int32_t MM=998244353; const int N=0; void solve(){ int n,m,k; cin>>n>>m>>k; rep(x,0,n+1){ rep(y,0,m+1){ int c = x*m + y*n - 2*x*y; if(k==c){ cout<<"Yes"; return; } } } cout<<"No"; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0); #ifdef SIEVE sieve(); #endif #ifdef NCR init(); #endif int t=1; while(t--) solve(); return 0; }
0
17,201,459
#include <iostream> #include <cstring> using namespace std; int main() { char Str[21]; int StrLen; cin >> Str; StrLen = strlen( Str ); while( 1 ){ cout << Str[StrLen-1]; StrLen--; if( StrLen == 0 ) break; } cout << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define rep(i,n) for(int i=0;i<n;++i) #define rep1(i,n) for(int i=1;i<n;++i) #define exrep(i, a, b) for(ll i = a; i < b; i++) #define out(x) cout << x << endl #define EPS (1e-7) #define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); typedef long long int ll; typedef long double ld; typedef unsigned long long int ull; typedef vector<int> vi; typedef vector<char> vc; typedef vector<bool> vb; typedef vector<double> vd; typedef vector<string> vs; typedef vector<pair<int,int> > vpii; typedef vector<vector<int> > vvi; typedef vector<vector<char> > vvc; typedef vector<vector<bool> > vvb; typedef vector<vector<double> > vvd; typedef vector<vector<string> > vvs; typedef vector<ll> vl; typedef vector<vector<ll> > vvl; typedef vector<vector<vector<ll> > > vvvl; ll MOD = 1000000007; const long long L_INF = 1LL << 60; const int INF = 2147483647; const double PI = acos(-1); 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;} template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;} const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1}; const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1}; template <class Abel> struct BIT { vector<Abel> dat[2]; Abel UNITY_SUM = 0; BIT(int n) { init(n); } void init(int n) { for (int iter = 0; iter < 2; ++iter) dat[iter].assign(n + 1, UNITY_SUM); } inline void sub_add(int p, int a, Abel x) { for (int i = a; i < (int)dat[p].size(); i += i & -i) dat[p][i] = dat[p][i] + x; } inline void add(int a, int b, Abel x) { sub_add(0, a, x * -(a - 1)); sub_add(1, a, x); sub_add(0, b, x * (b - 1)); sub_add(1, b, x * (-1)); } inline Abel sub_sum(int p, int a) { Abel res = UNITY_SUM; for (int i = a; i > 0; i -= i & -i) res = res + dat[p][i]; return res; } inline Abel sum(int a, int b) { return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1); } void print() { for (int i = 1; i < (int)dat[0].size(); ++i) cout << sum(i, i + 1) << ","; cout << endl; } }; signed main() { gearup; ll n,k; cin >> n >> k; vl a(n); rep(i,n)cin>>a[i]; rep(j,min(1LL*100,k)){ BIT<int> bit(n+1); rep(i,n){ ll left = max(i-a[i],0LL); ll right = min(n,i+a[i]+1); bit.add(left+1,right+1,1); } rep(i,n){ a[i] = bit.sum(i+1,i+2); } } rep(i,n){ if(i) cout << " "; cout << a[i]; } cout << endl; }
0
54,388,025
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> P; #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() int main(){ string s; cin >> s; if(s.size() < 4){ cout << "No" << endl; return 0; } if(s.substr(0,4) == "YAKI"){ cout << "Yes" << endl; }else{ cout << "No" << endl; } return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int main() { ll n{},k{}; cin>>n>>k; ll x = (ll)pow((k-1),(n-1)); cout<<x*k<<endl; return 0; }
0
41,955,031
#include<iostream> #include<string> #include<algorithm> #include<map> #include<set> #include<utility> #include<vector> #include<cmath> #include<cstdio> #define loop(i,a,b) for(int i=a;i<b;i++) #define rep(i,a) loop(i,0,a) #define pb push_back #define mp make_pair #define it ::iterator #define all(in) in.begin(),in.end() const double PI=acos(-1); const double ESP=1e-10; using namespace std; int main(){ string left="mnlkjhyuiop"; string s; while(cin>>s,s.size()!=1||s[0]!='#'){ bool h=true; int co=-1; rep(i,11){if(left[i]!=s[0])continue;co++;break;} rep(i,s.size()){ bool han=true; if(h){han=false;rep(j,11)if(left[j]==s[i])han=true;} else {rep(j,11)if(left[j]==s[i])han=false;} if(!han){co++;h^=1;} } cout<<co<<endl; } }
#include<stdio.h> #include<stdlib.h> #include<string.h> #include <math.h> #define M 1046527 #define L 15 char H[M][L]; long long convertToNum(char* str) { long long result = 0; int i = 0; int len = strlen(str); for (int i = 0; i < len; ++i) { int j = 0; switch (str[i]) { case 'A': j = 1; break; case 'C': j = 2; break; case 'G': j = 3; break; case 'T': j = 4; break; } result += j * pow(5, i); } return result; } int h1(int i) { return i % M; } int h2(long long i) { return 1 + i % (M - 1); } int getHash(long long key, int i) { return (h1(key) + h2(key) * i) % M; } bool find(char* str) { int i = 0; long long num = convertToNum(str); while (int key = getHash(num, i++)) { if (strcmp(H[key], str) == 0) { return true; } if (H[key][0] == '\0') break; } return false; } void insert(char* str) { int i = 0; long long num = convertToNum(str); while (int key = getHash(num, i++)) { if (strcmp(H[key], str) == 0) break; if (H[key][0] == '\0') { strcpy(H[key], str); break; } } return; } int main() { int n; scanf("%d", &n); for (int i = 0; i < M; ++i) { H[i][0] = '\0'; } for (int i = 0; i < n; ++i) { char command[7]; char c[L]; scanf("%s %s", command, c); if (command[0] == 'i') insert(c); if (command[0] == 'f') { if (find(c)) { printf("yes\n"); } else { printf("no\n"); } } } return 0; }
0
79,555,586
#include <bits/stdc++.h> using namespace std; #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int main(){ IOS; int N,a,b; cin >> N >> a >> b; vector<int> nums; for(int i=1; i<=N; i++){ int temp = i; deque<int> digit; while(temp>0){ digit.push_front(temp%10); temp/=10; } int sum = accumulate(digit.begin(),digit.end(),0); if(sum>=a && sum<=b){ nums.push_back(i); } } int ans = accumulate(nums.begin(),nums.end(),0); cout << ans <<endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using vec = vector<ll>; using mat = vector<vec>; using pll = pair<ll,ll>; #define INF (1LL << 60) #define MOD 1000000007 #define PI 3.14159265358979323846 #define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i)) #define FORR(i,v) for(auto (i):v) #define ALL(x) (x).begin(), (x).end() #define PR(x) cout << (x) << endl #define PS(x) cout << (x) << " " #define SZ(x) ((ll)(x).size()) #define MAX(a,b) (((a)>(b))?(a):(b)) #define MIN(a,b) (((a)<(b))?(a):(b)) #define REV(x) reverse(ALL((x))) #define ASC(x) sort(ALL((x))) #define DESC(x) ASC((x)); REV((x)) #define pb push_back #define eb emplace_back int main() { string S; cin >> S; ll N = SZ(S); bool f = false; REP(i,0,N) { REP(j,i,N) { string T = S.substr(0, i); string U = S.substr(j, N-j); if(T+U == "keyence") { f = true; break; } } } if(f) PR("YES"); else PR("NO"); return 0; }
0
89,608,997
#include<bits/stdc++.h> using namespace std; using ll = long long; int main(){ int n,m; cin>>n>>m; vector<ll> a(n); for(auto &i:a) { cin>>i; i/=2; } ll l = a.at(0); for(int i=1; i<n; i++){ if(l%a.at(i)==0&&(l/a.at(i))%2==0){ cout << 0 << endl; return 0; } if(a.at(i)%l==0&&(a.at(i)/l)%2==0){ cout << 0 << endl; return 0; } l = a.at(i)/__gcd(a.at(i),l)*l; if(l>m){ cout << 0 << endl; return 0; } } cout << (m/l+1)/2 << endl; }
#include <bits/stdc++.h> using namespace std; #define FOR(i,a,b) for(ll i=(a);i<(b);++i) #define rep(i, n) for(ll i = 0; i < (ll)(n); i++) #define all(x) (x).begin(),(x).end() typedef long long ll; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<ll> VLL; typedef vector<VLL> VVLL; typedef vector<string> VS; typedef pair<int, int> PII; typedef pair<ll, ll> PLL; inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;} inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;} template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();} template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); } template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); } struct Sum{ ll u = 0; ll d = 0; ll l = 0; ll r = 0; }; ll calc(Sum p) { return p.u + p.d + p.l + p.r; } int main() { ios::sync_with_stdio(false); cin.tie(0); int h, w; cin >> h >> w; string board[h]; rep(i, h) { cin >> board[i]; } struct Sum point[h][w]; rep(i,h){ ll cnt = 0; rep(j, w) { point[i][j].l = cnt; if(board[i][j] == '.') { cnt++; }else{ cnt = 0; } } } rep(i, h) { ll cnt = 0; for(int j = w - 1; j >= 0; j--) { point[i][j].r = cnt; if(board[i][j] == '.') { cnt++; } else { cnt = 0; } } } rep(j, w) { ll cnt = 0; rep(i, h) { point[i][j].u = cnt; if(board[i][j] == '.') { cnt++; } else { cnt = 0; } } } rep(j, w) { ll cnt = 0; for(int i = h - 1; i >= 0; i--) { point[i][j].d = cnt; if(board[i][j] == '.') { cnt++; } else { cnt = 0; } } } ll ans = 0; rep(i, h)rep(j, w) { if(board[i][j] == '#') continue; chmax(ans, calc(point[i][j]) + 1); } cout << ans << endl; return 0; }
0
96,564,421

Dataset Card for "train3"

More Information needed

Downloads last month
43
Edit dataset card