code1
stringlengths 54
12k
| code2
stringlengths 65
12k
| similar
int64 0
1
| __index_level_0__
int64 32
101M
|
---|---|---|---|
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <ctype.h>
#include <math.h>
#include <stack>
#include <string>
#include <string.h>
using namespace std;
double PI = 3.1415926535897932;
long mod = 1000000007;
const long INF = (1<<30);
int main() {
int s;
cin >> s;
if(s == 25)
cout << "Christmas" << endl;
else if(s == 24)
cout << "Christmas Eve" << endl;
else if(s == 23)
cout << "Christmas Eve Eve" << endl;
else if(s == 22)
cout << "Christmas Eve Eve Eve" << endl;
} | #include <iostream>
using namespace std;
void solve(long long D){
if (D == 25) cout << "Christmas" << '\n';
if (D == 24) cout << "Christmas Eve" << '\n';
if (D == 23) cout << "Christmas Eve Eve" << '\n';
if (D == 22) cout << "Christmas Eve Eve Eve" << '\n';
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
long long D;
scanf("%lld",&D);
solve(D);
return 0;
} | 1 | 73,042,477 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
map<int64_t, int64_t> m;
int64_t sum = 0;
m[sum]++;
int64_t res = 0;
for (int i = 0; i < n; ++i) {
int x;
cin >> x;
sum += x;
res += m[sum];
m[sum]++;
}
cout << res << endl;
} | #include <bits/stdc++.h>
using namespace std;
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 n;
vector<long long> A(200200, 0);
vector<long long> sum(200200, 0);
int main() {
cin >> n;
for(int i = 0; i < n; ++i) cin >> A.at(i);
sum.at(0) = A.at(0);
for(int i = 1; i < n; ++i) {
sum.at(i) += sum.at(i-1) + A.at(i);
}
long long cnt = 0;
map<long long, long long> mp;
for(int i = 0; i < n; ++i) {
if(sum.at(i) == 0) cnt++;
mp[sum.at(i)]++;
}
for(auto x : mp) {
long long mcnt = x.second;
cnt += (mcnt*(mcnt-1)) / 2;
}
cout << cnt << endl;
} | 1 | 27,793,415 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9 + 5;
int main() {
int n, k;
cin >> n >> k;
vector<ll> list(n, 0);
for (int i = 0; i < n; i++) {
cin >> list[i];
}
vector<ll> aup;
ll start = list[0] + 1;
for (int i = 1; i < n; i++) {
aup.push_back(list[i]);
}
int uplen = aup.size();
k--;
ll mincost = LLONG_MAX;
for (int bit = 0; bit < (1<<uplen); bit++) {
vector<int> ss(uplen, 0);
int cnt = 0;
for (int i = 0; i < uplen; i++) {
if (bit>>i&1) {
ss[i] = 1;
cnt++;
}
}
if (cnt == k) {
ll cstart = start;
ll sum = 0;
for (int j = 0; j < uplen; j++) {
if (ss[j]) {
if (cstart < aup[j]) {
cstart = aup[j] + 1;
} else {
sum += (cstart - aup[j]);
cstart++;
}
} else {
if (cstart < aup[j]) {
cstart = aup[j] + 1;
}
}
}
mincost = min(mincost, sum);
}
}
cout << mincost << endl;
return 0;
} | #include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
template <typename T> T &chmin(T &a, const T &b) {return a = min(a, b);}
template <typename T> T &chmax(T &a, const T &b) {return a = max(a, b);}
using ll = long long;
using ld = long double;
const int INF = 1e9;
const ld eps = 1e-9, pi = acos(-1.0);
int main(){
int n, k;
cin >> n >> k;
int a[15];
REP(i, n) cin >> a[i];
ll res = 1e11;
REP(i, 1<<n){
ll tmpres = 0;
bitset<15> target(i);
if(target.count()!=k) continue;
int required = 0;
REP(j, n) {
if(target[j]) tmpres += max(0, required-a[j]+1);
chmax(required, max(a[j], required+target[j]));
}
chmin(res, tmpres);
}
cout << res << endl;
return 0;
} | 1 | 73,599,717 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ll n;
cin>>n;
ll pt = 0 , px =0 , py =0;
bool ans = true;
cout<<boolalpha;
for(int i=0;i<n;i++)
{
ll ct , cx , cy;
cin>>ct>>cx>>cy;
if( (ct-pt) < (abs(cx-px)+abs(py-cy)) )
{
ans = false;
} else
{
if( (ct-pt)%2 != (abs(cx-px)+abs(py-cy))%2 )
ans = false;
}
px = cx;
py = cy;
pt = ct;
}
if( ans)
cout<<"Yes";
else cout<<"No";
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};
int main(){
ll N;
cin >> N;
VL t(N+1), x(N+1), y(N+1);
x[0] = 0; y[0] = 0; t[0] = 0;
rep(i, 1, N+1) cin >> t[i] >> x[i] >> y[i];
rep(i, 0, N){
ll diff = abs(x[i+1] - x[i]) + abs(y[i+1] - y[i]);
if(diff > t[i+1] - t[i] || diff % 2 != (t[i+1] - t[i]) % 2){
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
return 0;
} | 1 | 12,339,438 |
#include <bits/stdc++.h>
using namespace std;
#define print cout <<
#define printl(s) cout << s << endl;
#define rep(i,n) for (int i = 0; i < (n); ++i)
template <typename T>
vector<T> getValues(int num){
vector<T> values(num);
for(int i=0;i<num;i++){
cin >> values.at(i);
}
return values;
}
int main(){
int X,Y;
cin >> X >> Y;
if(Y%2!=0){
printl("No");
return 0;
}
int kame = (Y-2*X)/2;
if(kame>X || kame<0){
printl("No");
return 0;
}
int tsuru = X - kame;
if(tsuru>X || tsuru<0){
printl("No");
return 0;
}
printl("Yes");
} | #include<bits/stdc++.h>
#define unsigned long long ull
#define long long ll
#define all(x) (x).begin(),(x).end()
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;i<n;i++)
using namespace std;
void solve(){
int x,y;
cin>>x>>y;
int maxlegs = x*4;
int minlegs = x*2;
if(y>= minlegs && y<= maxlegs && y%2==0)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
return 0;
} | 1 | 85,322,312 |
#include <bits/stdc++.h>
using namespace std;
int main(void){
long long int n,m,i=0,h[200000],ans=0,c=0;
string s;
cin >> n;
for(i=0;i<n;i++)
{
cin >> h[i];
}
h[n]=100000000010;
for(i=0;i<n;i++)
{
if(h[i]>=h[i+1])
{
c++;
if(ans<c)
{
ans=c;
}
continue;
}
c=0;
}
cout << ans << endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define forin(in, n) for(int i=0; i<n; i++) cin>>in[i]
#define forout(out) for(int i=0; i<(int)out.size(); i++) cout<<out[i]<<endl
#define rep(i, n) for(int i=0; i<(n); i++)
int main(){
int n; cin>> n;
vector<ll> h(n);
int ans=0;
int cnt=0;
forin(h, n);
for(int i=0; i<n-1; i++){
if(h[i] >= h[i+1]){
cnt++;
}else{
cnt=0;
}
ans=max(cnt, ans);
}
cout<<ans<<endl;
} | 1 | 12,106,302 |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define empb emplace_back
#define mp make_pair
#define F first
#define S second
#define vii vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define vpii vector<pii>
#define mapii map<int,int>
#define mapll map<ll,ll>
#define all(a) a.begin(),a.end()
#define test int t; cin>>t; while(t--)
#define prec(n) fixed<<setprecision(n)
#define ItsFUN ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mod 1000000007
const int MIN = INT_MIN;
const int MAX = INT_MAX;
bool comp(const pair<ll,ll> &a, const pair<ll,ll> &b) {
return (a.second < b.second) ;
}
ll binpow(ll a, ll b) {
ll res = 1;
while(b) {
if(b&1) res = res * a;
a = a*a;
b = b >> 1;
}
return res;
}
int main(){
ItsFUN;
ll k, x; cin >> k >> x;
if(k*500 >= x) {
puts("Yes");
}
else puts("No");
return 0;
} | #include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int mod = 1e9+7;
const ll inf = 1e18;
const double pi = 3.1415926535897932384626;
ll mpow(ll a,ll b){
ll res=1;
a%=mod;
while(b){
if(b%2) res=res*a%mod;
a=a*a%mod;
b/=2;
}
return res;
}
ll gcd(ll a,ll b){
if(b==0) return a;
return gcd(b,a%b);
}
void solve(){
int n,x;
cin>>n>>x;
if(n*500>=x) cout<<"Yes";
else cout<<"No";
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
solve();
return 0;
} | 1 | 67,652,769 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> V;
#define rep(cnt,e) for(ll cnt=0;cnt<e;cnt++ )
typedef pair<ll,ll> P;
const ll mod = 1e9+7;
const ll INF = INT64_MAX;
ll i,j,k;
int main(){
ll N,i;
cin>>N>>i;
cout<<N-i+1<<endl;
} | #include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
#ifdef TEST
chrono::system_clock::time_point start, end;
start = chrono::system_clock::now();
#endif
long N, i;
cin >> N >> i;
cout << N-i+1 << endl;
#ifdef TEST
end = chrono::system_clock::now();
cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
return 0;
} | 1 | 48,147,084 |
#include <iostream>
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int d[6];
for (int i = 0; i < 6; i++) {
cin >> d[i];
}
int q, tp, ft;
cin >> q;
while (0 < q) {
cin >> tp >> ft;
int i, j;
for (i = 0; i < 6; i++)
if (d[i] == tp)
break;
for (j = 0; j < 6; j++)
if (d[j] == ft)
break;
if (i < 3 && j < 3)
if (i < j)
if (j-i==1)
cout << d[3-i-j] << "\n";
else
cout << d[5-(3-i-j)] << "\n";
else
if (i-j==1)
cout << d[5-(3-i-j)] << "\n";
else
cout << d[3-i-j] << "\n";
else if (2 < i && 2 < j)
if (i < j)
if (j-i==1)
cout << d[12-i-j] << "\n";
else
cout << d[5-(12-i-j)] << "\n";
else
if (i-j==1)
cout << d[5-(12-i-j)] << "\n";
else
cout << d[12-i-j] << "\n";
else if (2 < j) {
int k = 5-j;
if (i < k)
if (k-i==1)
cout << d[5-(3-i-k)] << "\n";
else
cout << d[3-i-k] << "\n";
else
if (i-k==1)
cout << d[3-i-k] << "\n";
else
cout << d[5-(3-i-k)] << "\n";
}
else if (2 < i) {
int k = 5-i;
if (k < j)
if (j-k==1)
cout << d[5-(3-j-k)] << "\n";
else
cout << d[3-j-k] << "\n";
else
if (k-j==1)
cout << d[3-j-k] << "\n";
else
cout << d[5-(3-j-k)] << "\n";
}
q--;
}
} | #include <iostream>
using namespace std;
int main(){
int dice[6];
int pos[6][6] = {{0,3,5,2,4,0},{4,0,1,6,0,3},{2,6,0,0,1,5},{5,1,0,0,6,2},{3,0,6,1,0,4},{0,4,2,5,3,0}};
int a,b,ap,bp,n;
for(int i=0;i<6;i++) cin>>dice[i];
cin>>n;
for(int i=0;i<n;i++){
cin>>a>>b;
for(int j=0;j<6;j++){
if(a==dice[j]) ap=j;
if(b==dice[j]) bp=j;
}
cout<<dice[pos[ap][bp]-1]<<endl;
}
return 0;
} | 1 | 82,958,913 |
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define PI acos(-1)
typedef long long ll;
ll MOD=1000000007;
ll gcd(ll x,ll y){
if(y==0) return x;
else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
return x/gcd(x,y)*y;
}
int main(){
ll n,k;
cin>>n>>k;
ll r[100001];
rep(i,100001){
r[i]=0;
}
rep(i,n){
ll a,b;
cin>>a>>b;
r[a]+=b;
}
ll ans=0;
rep(i,100001){
ans+=r[i];
if(ans>=k){
cout<<i;
break;
}
}
return 0;
} | #include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pb push_back
#define mod 1000000007
#define mod1 1000000009
#define hell 998244353
#define inf 1000000000000000000LL
#define pi 3.14159265358979323
const int N=200005;
using namespace std;
ll n,k,sum,q,res,m,val,ans;
ll x,y;
ll xx[]={1,0,-1,0};
ll yy[]={0,1,0,-1};
ll cnt[1000005];
void solve()
{
cin>>n>>k;
for(int i=0;i<n;i++)
{
cin>>x>>y;
cnt[x]+=y;
}
ans=k;
for(int i=1;i<1000005;i++)
{
ans-=cnt[i];
if(ans<=0) {cout<<i<<"\n";return;}
}
}
int main()
{ ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
ll t=1;
for(ll i=1;i<=t;i++)
solve();
} | 1 | 64,943,454 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
ll N;
cin >> N;
vector<ll> A(N);
vector<ll> B(N);
for(int i=0;i<N;i++){
cin >> A[i];
B[i] = A[i];
}
sort(B.begin(),B.end());
map<ll,int> mp;
for(int i=0;i<N;i++){
mp[B[i]] =i;
}
ll canNotMove =0;
for(int i=0;i<N;i++){
int act = i;
int ideal = mp[A[i]];
if(act%2 != ideal%2){
canNotMove++;
}
}
cout << canNotMove/2 << endl;
return 0;
} | #include <iostream>
#include<algorithm>
#include<vector>
#define int long long
using namespace std;
int re(int i){return (i/2)*2;}
int solve(int i,int j,int l){
return re(i)+re(j)+re(l);
}
#define vel vector<long long>
#define rep(i,n) for(int i=0;i<n;i++)
signed main(void){
int n;cin >>n;
vel a(n);
rep(i,n){cin >>a[i];}
vel s=a;sort(s.begin(),s.end());
int ans=0;
for(int i=0;i<n;i+=2){
int x=lower_bound(s.begin(),s.end(),a[i])-s.begin();
ans+=(x%2);
}
cout <<ans<<endl;
} | 1 | 52,095,656 |
#include<stdio.h>
int main(){
int a;
int b;
int c;
scanf("%d", &a);
scanf("%d", &b);
scanf("%d", &c);
if (a<b){
if (b < c){
printf("Yes\n");
}
else{
printf("No\n");
}
}
else{
printf("No\n");
}
return 0;
} | #include<stdio.h>
int main(void)
{
int a, b, c, d;
scanf("%d %d %d",&a, &b, &c);
if(a<b && b<c && a<c){
printf("Yes\n");
}
else{
printf("No\n");
}
return 0;
} | 1 | 56,050,951 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin>>N;
for(int i=0;i<N;i++){
int A ;
int l,r ;
cin>>l>>r;
A =A + r - l + 1;
if(i+1 ==N){
cout<<A<<endl;
}
}
} | #include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define pb push_back
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
ll ans = 0;
while(t--)
{
int l,r;cin>>l>>r;
ans += r-l+1;
}
cout<<ans<<endl;
return 0;
} | 1 | 94,520,020 |
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
using namespace std;
int main(){
int a,b,c;
cin>>a>>b;
for(int i=1;i<=b;i++){
cin>>c;
a-=c;
if(a<=0){
cout<<"Yes"<<endl;
return 0;
}
}
cout<<"No"<<endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define Blue ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i,a,n) for(int i=a;i<n;++i)
typedef vector<int> vi;
typedef long long ll;
const int mod=1e9+7;
const int dx[]={1,-1,0,0},dy[]={0,0,1,-1};
void solve(){
int n,h;
cin>>h>>n;
vi a(n);
int sum=0;
for(int i=0;i<n;i++){
cin>>a[i];
sum+=a[i];
}
cout<<(sum>=h?"Yes":"No");
}
int main(){
Blue;
int test=1;
while(test--)
solve();
return 0;
} | 1 | 46,371,877 |
#include <iostream>
#include <algorithm>
#define MOD 1000000007
using namespace std;
int main(){
string L;
cin >> L;
long dp[L.length() + 1][2];
for(int i=0; i<=L.length(); i++){
dp[i][0] = 0;
dp[i][1] = 0;
}
dp[0][0] = 0;
dp[0][1] = 1;
for(int i=0; i<L.length(); i++){
if(L[i] == '1') dp[i+1][1] = dp[i][1]*2%MOD;
else dp[i+1][1] = dp[i][1]*1%MOD;
dp[i+1][0] = dp[i][0]*3%MOD;
if(L[i] == '1') dp[i+1][0] += dp[i][1]%MOD;
dp[i+1][0] %= MOD;
dp[i+1][1] %= MOD;
}
cout << (dp[L.length()][0] + dp[L.length()][1]) % MOD;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD (1000000007)
#define MOD2 (998244353)
#define MOD3 (1000000009)
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
ifstream cinn("ride.in");ofstream coutt("ride.out");
int poww(const int &a,int b,const int &m=MOD){if(b==0)return 1;int x=poww(a,b/2,m);x=x*x%m;if(b&1)x=x*a%m;return x;}
int ceil(const int &a,const int &b){return (a+b-1)/b;}
string l;
int n,dp[100005][2];
int f(int i,int tight){
if(i==n)return 1;
int &ans=dp[i][tight];
if(ans!=-1)return ans;
if(tight){
ans=3*f(i+1,1)%MOD;
}else{
if(l[i]=='0')ans=f(i+1,0)%MOD;
else ans=(2*f(i+1,0)+f(i+1,1))%MOD;
}
return ans;
}
signed main(){
FASTER;
memset(dp,-1,sizeof dp);
cin>>l;
n=l.size();
cout<<f(0,0);
} | 1 | 15,522,967 |
#include<bits/stdc++.h>
using namespace std;
int main(){
string n;
cin >> n;
for(int i = 0; i < 3; i++){
if(n.at(i) == '1') cout << 9;
else cout << 1;
}
cout << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep2(i, a, b) for(int i = (a); i < (b); i++)
typedef long long ll;
int main() {
string s;
cin >> s;
rep(i, 3) {
s[i] = (s[i] == '1') ? '9' : '1';
}
cout << s << endl;
} | 1 | 13,370,963 |
#include <iostream>
#include <vector>
#include <string>
using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<unsigned long long int>;
int main(void) {
Int n, a;
cin >> n >> a;
n -= 500 * (n / 500);
if (n <= a) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
} | #include "bits/stdc++.h"
#include <set>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>
void print(T x)
{
std::cout << x << " ";
}
template <typename T>
void println(T x)
{
std::cout << x << "\n";
}
signed main(void) {
int n, a;
cin >> n >> a;
if (n % 500 > a)print("No");
else print("Yes");
} | 1 | 21,351,999 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int a , b, c , d ;
cin >> a >> b >> c >> d ;
if(a+b > c+d)cout << "Left" ;
else if(a+b == c+d)cout << "Balanced" ;
else cout << "Right" ;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int A, B, C, D;
cin >> A >> B >> C >> D;
if(A+B == C+D)
cout << "Balanced" << endl;
else if(A+B >= C+D)
cout << "Left" << endl;
else
cout << "Right" << endl;
return 0;
} | 1 | 13,559,315 |
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;
template<class T> inline bool chmin(T& a,T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if (a < b) {a = b; return true;} return false;}
const ll MOD = 1000000007;
const int INF = 1<<30;
int main(){
int N; cin >> N;
vector<int> h(N);
rep(i, N) cin >> h[i];
int ans = 0;
for (int i = 0; i < N; ++i){
bool flag = true;
for (int j = i; j >= 0; --j){
if (h[j] > h[i]) flag = false;
}
if (flag) ans++;
}
cout << ans << endl;
} | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout<< (x) << " "
int main(){
int n;cin>>n;
int mx=1;
int before=1;
int ans = 0;
rep(i,n){
int tmp;cin>>tmp;
if(before<=tmp)ans++;
before = max(before, tmp);
}
co(ans);
} | 1 | 73,514,003 |
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#include <functional>
#include <set>
#define DB cerr<<"D"<<endl
#define pb push_back
using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6;
template<typename T, typename U, typename O> void caut(T a, U b, O c){cout<<"("<<a<<","<<b<<","<<c<<") ";} template<typename T, typename U> void caut(T a, U b){cout<<"("<<a<<","<<b<<") ";} template<typename T> void caut(T a){cout<<"("<<a<<") ";}
using P=pair<double,int>;
const ll M = 1e9+7;
void add(ll& x, ll y) {x+=y; x%=M;}
void chmax(ll& x, ll y) {if (x<y) x=y;}
int main() {
int v[4]={};
for(int i=0;i<3;i++) {
int a,b; cin>>a>>b; a--; b--;
v[a]++; v[b]++;
}
int o=0,t=0;
for(int i=0;i<4;i++) {
if (v[i]==1) o++;
if (v[i]==2) t++;
}
if (o==2&&t==2) {
cout<<"YES"<<endl;
} else {
cout<<"NO"<<endl;
}
} | #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std;
template <typename Tp> inline void getint(Tp &num){
register int ch, neg = 0;
while(!isdigit(ch = getchar())) if(ch == '-') neg = 1;
num = ch & 15;
while(isdigit(ch = getchar())) num = num * 10 + (ch & 15);
if(neg) num = -num;
}
int deg[5];
int main(){
for(register int i = 1; i <= 3; i++){
int u, v; getint(u), getint(v);
deg[u]++, deg[v]++;
}
for(register int i = 1; i <= 4; i++)
if(deg[i] != 1 && deg[i] != 2) return puts("NO"), 0;
return puts("YES"), 0;
} | 1 | 91,900,571 |
#include <bits/stdc++.h>
using namespace std;
#define for_(i,a,b) for(int i=(a);i<(b);++i)
int coin[6] = {500, 100, 50, 10, 5, 1};
int main() {
int N;
while (cin >> N, N) {
int A = 1000 - N, ans = 0;
for_(i,0,6) {
while (A >= coin[i]) {
A -= coin[i];
++ans;
}
}
cout << ans << endl;
}
} | #include <iostream>
using namespace std;
int main(){
int money;
while(cin >> money && money !=0){
int count =0;
int res = 1000 - money;
for(int i=0;i<3;i++){
count +=res %10;
if(res % 10 >4){ count -= 4;}
res /=10;
}
cout << count << endl;
}
} | 1 | 645,903 |
#include <bits/stdc++.h>
#define int long long
#define ci(m) for(int i=0;i<m;i++)
#define cj(m) for(int j=0;j<m;j++)
#define ck(m) for(int k=0;k<m;k++)
#define cis(m) for(int i=1;i<=m;i++)
#define cjs(m) for(int j=1;j<=m;j++)
#define cks(m) for(int k=1;k<=m;k++)
#define rci(m) for(int i=m-1;i>=0;i--)
#define rcj(m) for(int j=m-1;j>=0;j--)
#define rck(m) for(int k=m-1;k>=0;k--)
#define rcis(m) for(int i=m;i>=1;i--)
#define rcjs(m) for(int j=m;j>=1;j--)
#define rcks(m) for(int k=m;k>=1;k--)
#define gcd __gcd
#define endl "\n"
#define pb emplace_back
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define mod2 998244353
#define maxe *max_element
#define mine *min_element
#define inf 1e18
#define deci(x, y) fixed<<setprecision(y)<<x
#define w(t) int t; cin>>t; while(t--)
#define nitin ios_base::sync_with_stdio(false); cin.tie(NULL)
#define PI 3.141592653589793238
using namespace std;
int e[200000][26];
int32_t main() {
nitin;
string str;
cin>>str;
int n=str.length();
ci(n) e[i][str[i]-'a']++;
rci(n) if(i!=n-1){
cj(26)
e[i][j]+=e[i+1][j];
}
int ans=0;
ci(n) if(i!=n-1){
cj(26) if(j!=str[i]-'a')
ans+=e[i+1][j];
}
cout<<ans+1<<endl;
return 0;
} | #include <iostream>
#include <map>
using namespace std;
using ll = long long;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define out(v) cout<<v<<"\n"
int main() {
cin.tie(0); ios::sync_with_stdio(false);
string S;
cin >> S;
int N = S.size();
map<char, int> m;
rep(i, N) ++m[S[i]];
int sum = N;
ll ans = 1;
for (const auto& v : m) {
sum -= v.second;
ans += (ll)sum * v.second;
}
out(ans);
return 0;
} | 1 | 46,584,108 |
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
int main(){
ll L,R;
cin >> L >> R;
int ans=2019;
if(R-L>=2019){
ans = 0;
}else{
for(ll i=L;i<R;i++){
for(ll j=i+1;j<R+1;j++){
int n = i%2019;
int m = j%2019;
ans=min(ans,(n*m)%2019);
}
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
using pp=pair<int,int>;
using ll=long long;
int main() {
ll L, R, mod=2019;
cin >> L >> R;
ll m=10000;
if (R-L>=2019) {
cout << 0 << endl;
}
else {
R=R-L/mod*mod;
L=L-L/mod*mod;
for (ll i=L; i<=R; i++) {
for (ll j=i+1; j<=R; j++) {
ll n=i*j;
m=min(m, n-n/mod*mod);
}
}
cout << m << endl;
}
} | 1 | 13,125,505 |
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>
using namespace std;
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define P pair<int, int>
typedef vector<int> vec;
typedef vector<vec> mat;
int main(){
int a, p;
cin >> a >> p;
cout << (3 * a + p) / 2 << endl;
} | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int mod=1000000007;
const double PI = 3.14159265359;
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define INF 1000000000000
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define FOR(i,n) for(int i=0;i<(n);i++)
#define FORA(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define count_1(n) __builtin_popcountll(n)
#define parity(n) __builtin_parityll(n)
void show (int a[], int arraysize) { for (int i = 0; i < arraysize; ++i) {cout << a[i] << " ";} cout<<endl;}
int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b);}
void sieve(int n)
{
bool prime[n+1];
memset(prime, true, sizeof(prime));
for (int p=2; p*p<=n; p++)
{
if (prime[p] == true)
{
for (int i=p*p; i<=n; i += p)
prime[i] = false;
}
}
for (int p=2; p<=n; p++)
if (prime[p])
cout << p << " ";
}
int main()
{FAST
int n,p;
cin>>n>>p;
cout<<(n*3+p)/2<<endl;
return 0;
} | 1 | 1,444,946 |
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)
int main()
{
ll n, x, y;
cin >> n;
vec2ll v(2, vecll(100000));
vecll e0(2), e1(2), e2(2);
forll(i, 0, n){
cin >> x;
x--;
y = i & (ll)1;
v[y][x]++;
if(v[y][x] > e1[y]){
e1[y] = v[y][x];
e0[y] = x + 1;
}else if(v[y][x] > e2[y]){
e2[y] = v[y][x];
}
}
cout << n - (e0[0]!=e0[1]? e1[0]+e1[1]: max(e1[0]+e2[1], e2[0]+e1[1])) <<endl;
} | #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() {
ll n;
cin >> n;
map<ll,ll> m, p;
rep(i,n/2) {
ll a, b;
cin >> a >> b;
m[a]++, p[b]++;
}
vector<P> even, odd;
for(auto x : m) even.push_back(make_pair(x.second, x.first));
for(auto x : p) odd.push_back(make_pair(x.second, x.first));
sort(all(even)); sort(all(odd));;
reverse(all(even)); reverse(all(odd));
ll A = 0, B = 0, ans;
if(even[0].second==odd[0].second){
ans = min(n-even[0].first-odd[1].first, n-even[1].first-odd[0].first);
}
else{
A = even[0].first;
B = odd[0].first;
ans = n-A-B;
}
cout << ans << endl;
return 0;
} | 1 | 57,456,321 |
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define PER(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define MOD ((LL)1e9+7)
#define INF ((LL)1e9+7)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define BIT(x) (1LL << (x))
using namespace std;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
LL modpow(LL x, LL b){
LL res = 1;
while(b){
if(b&1)res = res * x % MOD;
x = x * x % MOD;
b>>=1;
}
return res;
}
LL modinv(LL x){
return modpow(x, MOD-2);
}
int main(){
int N;
cin >> N;
vector<LL> L(N), R(N);
vector<LL> low(N, INF), high(N, 0);
foreach(i, L)cin>>i;
foreach(i, R)cin>>i;
low[0] = high[0] = L[0];
LL lh = L[0];
REPA(i, N){
high[i] = L[i];
if(lh==L[i]){
low[i] = 1;
}else{
low[i] = L[i];
}
chmax(lh, L[i]);
}
if(R[N-1] < low[N-1] || high[N-1] < R[N-1]){
cout << 0 << endl;
return 0;
}
low[N-1] = high[N-1] = R[N-1];
lh = R[N-1];
PER(i, N-1){
LL nlow;
LL nhigh =R[i];
if(lh == R[i]){
nlow = 1;
}else{
nlow = nhigh = R[i];
}
if(high[i] < nlow || low[i] > nhigh){
cout << 0 << endl;
return 0;
}
chmax(low[i], nlow);
chmin(high[i], nhigh);
chmax(lh, R[i]);
}
LL ans = 1;
REP(i, N){
ans *= high[i] - low[i] + 1;
ans %= MOD;
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair <ll,ll> P;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = n-1; i > 0; i--)
#define FOR(i, n, m) for(int i = n; i < (int)(m); i++)
#define PRINT(x) cout << x << endl
#define ALL(v) v.begin(), v.end()
#define INF (ll)1e18
#define PI 3.14159265358979
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll MOD = 1000000007;
int main()
{
ll N;
cin >> N;
vector<ll> T(N);
REP(i, N) cin >> T[i];
vector<ll> A(N);
REP(i, N) cin >> A[i];
if (!(T.front() <= A.front()) || !(T.back() >= A.back())) {
PRINT(0);
return 0;
}
vector<ll> v(N);
v[0] = T.front();
v.back() = A.back();
REP(i, N-1) {
if (T[i] < T[i+1]) {
if(T[i+1] > A[i+1]) {
PRINT(0);
return 0;
}
v[i+1] = T[i+1];
}
if (A[i] > A[i+1]) {
if (A[i] > T[i]) {
PRINT(0);
return 0;
}
v[i] = A[i];
}
}
ll ans = 1;
REP(i, N) {
if (v[i] == 0) {
ans *= min(T[i], A[i]);
ans %= MOD;
}
}
PRINT(ans);
return 0;
} | 1 | 43,716,275 |
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
int main(){
int cnt[26]={};
char c;
while(scanf("%c", &c)!=EOF){
if(isupper(c)) cnt[tolower(c)-'a']++;
else cnt[c-'a']++;
}
for(int i=0;i<26;i++) printf("%c : %d\n", 'a'+i, cnt[i]);
return 0;
} | #include <iostream>
int main(int argc, const char * argv[]) {
std::string line;
int chars[26] = {};
for ( ; getline(std::cin, line); ) {
for (size_t i = 0; i < line.length(); i++) {
if ('a' <= line[i] && line[i] <= 'z') {
chars[line[i] - 'a']++;
} else if ('A' <= line[i] && line[i] <= 'Z') {
chars[line[i] - 'A']++;
}
}
}
for (size_t i = 0; i < 26; i++) {
std::cout << (char)(i + 'a') << " : " << chars[i] << std::endl;
}
return 0;
} | 1 | 63,670,552 |
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001;
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;
int main(){
string s;
int n;cin>>n>>s;
int a=0,b=0;
rep(i,n){
if(s[i]=='('){
a++;
}
else{
if(a==0)b++;
else a--;
}
}
rep(i,b){
s='('+s;
}
rep(i,a){
s=s+')';
}
cout<<s<<endl;
} | #include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)
int main() {
int N; cin >> N;
string S; cin >> S;
vector<int> d(N);
int ka = 0, ko = 0;
int x = 0;
rep(i,N) {
if (S.at(i) == '(') ka++; else ko++;
d.at(i) = ka - ko;
x = min(x, d[i]);
}
rep(i, -x) cout << '(';
cout << S;
rep(i, d[N-1]-x) cout << ')';
cout << endl;
} | 1 | 32,403,171 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n); ++i)
typedef long long ll;
const int mod = 1e9+7;
const int INF = 2000000;
const double PI = acos(-1.0);
int main() {
int X;
cin >> X;
int K = 1;
while(X*K%360 != 0) K++;
cout << K << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define lli long long int
#define tc int t;cin>>t;while(t--)
#define all(x) x.begin(),x.end()
#define f first
#define s second
#define pb push_back
#define vi vector<int>
#define vll vector<lli>
#define maxn 300005
#define mod 1000000007
int main()
{
fastio;
int x;
cin>>x;
int t1=360,t2=x;
int an=1;
for(int i=2;i<=sqrt(t2);i++)
{
int c1=0,c2=0;
while(t2%i==0)
{
c1++;
t2/=i;
}
while(t1%i==0)
{
t1/=i;
c2++;
}
if(c1>c2)
{
an*=pow(i,c1-c2);
}
}
if(t2>1)
{
if(t1%t2!=0)
an*=t2;
}
cout<<(an*360)/x<<"\n";
return 0;
} | 1 | 69,828,381 |
#include<bits/stdc++.h>
using namespace std;
#define ms(x,y) memset(x, y, sizeof(x))
#define lowbit(x) ((x)&(-x))
#define sqr(x) ((x)*(x))
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
void run_case() {
int a, b, x;
cin >> a >> b >> x;
double theta;
if(a*a*b<= 2*x)
theta = atan(2.0*(a*a*b-x) / (double)(a*a*a));
else
theta = acos(-1.0)/2.0-atan(2.0*x/(double)(b*b*a));
cout << 180.0*theta/acos(-1.0);
}
int main() {
ios::sync_with_stdio(false), cin.tie(0);
cout.flags(ios::fixed);cout.precision(9);
run_case();
cout.flush();
return 0;
} | #ifdef CREED
#include "creed.h"
#else
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <fstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <utility>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <cassert>
#include <sstream>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#endif
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef string str;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define forn(i,a,b) for (int i = (a); i < ll(b); ++i)
#define fo(i,a) forn(i,0,ll(a))
#define rforn(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define ro(i,a) rforn(i,0,a)
#define trav(a,x) for (auto& a: x)
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define rsz resize
#define ins insert
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define f first
#define s second
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef CREED
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
const ll INF = 9e18;
ll mod = 1000000007;
inline ll fast_expo(ll base,ll power,ll modulo=mod){
base%=modulo;
if (base<0) base+=modulo;
ll x=base,cnt=power,ans=1;
while(cnt){
if (cnt&1) ans=(ans*x)%modulo;
x=(x*x)%modulo;
cnt>>=1;
}
return ans;
}
ll takemod(ll a, ll mo){
a %= mo;
if(a < 0) a+=mo;
return a;
}
ll modinv(ll a, ll mo){
return takemod(fast_expo(takemod(a,mo), mo-2, mo), mo);
}
int main() {
fast_cin();
ll a, b, x;
cin >> a >> b >> x;
db ba = b;
db hi = db(2 * x)/(b * a);
if (hi > a) {
ba = a;
hi = db(2 * (a * b * a - x))/(a * a);
db k = (db((atan(hi/ba))/(2 * M_PI)) * (180));
cout << fixed << setprecision(6) << 2 * k << '\n';
return 0;
}
db k = (db((atan(hi/ba))/(2 * M_PI)) * (180));
debug(k);
db ans = 90 - 2 * (db((atan(hi/ba))/(2 * M_PI)) * (180));
cout << fixed << setprecision(6) << ans << '\n';
return 0;
} | 1 | 85,327,042 |
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
int main() {
int n;
while(cin>>n){
int cnt=0;
for(int a=0;a<=9;a++)
for(int b=0;b<=9;b++)
for(int c=0;c<=9;c++){
if(a+b+c>n)break;
if(n-(a+b+c)>9)continue;
cnt++;
}
cout<<cnt<<endl;
}
return 0;
} | #include <stdio.h>
#include <time.h>
#include <math.h>
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <sstream>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <complex>
#include <cmath>
#include <tuple>
#define all(c) ((c).begin(),(c).end())
#define rall(c) (c).rbegin(),(c).rend()
#define vvsort(v) sort(v.rbegin(),v.rend())
#define ll long long
#define pb(a) push_back(a)
#define fi first
#define se second
#define inf 999999999
using namespace std;
const ll MOD = 1e9 + 7;
const double PI = acos(-1.0);
int n;
int main() {
while (cin >> n) {
ll cont = 0;
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
for (int k = 0; k < 10; k++) {
for (int l = 0; l < 10; l++) {
if (i + j + k + l == n)cont++;
}
}
}
}
cout << cont << endl;
}
} | 1 | 98,485,840 |
#include <iostream>
#include <vector>
using namespace std;
int main()
{
int a;
int b;
int c;
vector<int> array;
cin >> a >> b >> c;
for( a; a <= b ; a++) {
array.push_back(a);
}
int answer = 0;
for( int i = 0; i < array.size(); i++) {
if ( (c % array[i]) == 0){
answer++;
}
}
cout << answer << endl;
} | #include <iostream>
using namespace std;
int main() {
int a,b,c,amo,div,i;
cin>>a>>b>>c;
for(i=a-1;i<b;i++){
div=c%a;
a++;
if(div==0){
amo++;
}
}
cout<<amo<<endl;
} | 1 | 12,025,382 |
#include<bits/stdc++.h>
typedef long long ll;
const int maxn=1e7+5+5e6;
using namespace std;
const ll INF=1e15+7;
const ll mod=998244353;
ll n,m,p;
ll dp[305][305];
ll num[maxn];
int main()
{
scanf("%lld%lld",&n,&m);
for(int i=1;i<=n;i++) scanf("%lld",&num[i]);
for(int i=0;i<=n;i++)
for(int k=0;k<=n;k++) dp[i][k]=INF;
dp[0][0]=0;
for(int i=1;i<=n;i++)
{
for(int k=1;k<=n-m;k++)
{
for(int j=0;j<i;j++)
{
dp[i][k]=min(dp[i][k],dp[j][k-1]+max(0ll,num[i]-num[j]));
}
}
}
ll res=INF;
for(int i=1;i<=n;i++)
res=min(res,dp[i][n-m]);
if(m==n) printf("0\n");
else
printf("%lld\n",res);
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
#define vec vector<ll>
#define mat vector<vector<ll> >
#define fi first
#define se second
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=998244353;
signed main(){
ll n,k;cin>>n>>k;
vector<vector<vector<ll> > >dp(n+2,vector<vector<ll> >(k+1,vector<ll>(n+1,inf*inf)));
vector<ll>a(n+1);
REP(i,1,n+1){
cin>>a[i];
}
dp[0][0][0]=0;
rep(i,n+1){
rep(j,k+1){
rep(l,n+1){
if(dp[i][j][l]==inf*inf)continue;
if(a[l]>=a[i]){
dp[i+1][j][i]=min(dp[i][j][l],dp[i+1][j][i]);
}else{
dp[i+1][j][i]=min(dp[i][j][l]+a[i]-a[l],dp[i+1][j][i]);
}
if(j<k){
dp[i+1][j+1][l]=min(dp[i+1][j+1][l],dp[i][j][l]);
}
}
}
}
ll ans=inf*inf;
rep(i,k+1){
rep(j,n+1){
ans=min(ans,dp[n+1][i][j]);
}
}
cout<<ans<<endl;
} | 1 | 62,221,612 |
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sonic ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
ll a[100010];
int main () {
sonic
int n1,n2,n3,n4;
cin>>n1>>n2>>n3>>n4;
int q = 0;
if(n1 == n2 || n1 == n3 || n1 == n4 || n2 == n3 || n2 == n4 || n3 == n4) {cout<<"NO";return 0;}
if(n1 == 1 || n2 == 1 || n3 == 1 || n4 == 1) { q++;}
if(n1 == 9 || n2 == 9 || n3 == 9 || n4 == 9) {q++;}
if(n1 == 7 || n2 == 7 || n3 == 7 || n4 == 7) {q++;}
if(n1 == 4 || n2 == 4 || n3 == 4 || n4 == 4) {q++;}
if(q == 4) {cout<<"YES";}
else cout<<"NO";
return 0;
} | #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 Reverse(x) reverse(all(x));
#define Sort(x) sort(all(x));
#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);
vi a(4);
vec(bool) c(4, false);
rep(i,4){
cin>>a[i];
}
rep(i,4){
if(a[i]==1){
c[1]=true;
}
if (a[i]==9) {
c[2]=true;
}
if (a[i]==7) {
c[3]=true;
}
if (a[i]==4) {
c[0]=true;
}
}
lli cs=true;
rep(i,4){
if(!c[i]){
cs=false;
break;
}
}
YES(cs);
} | 1 | 18,917,358 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve(long long N, long long K, std::vector<long long> V)
{
vector<vector<vector<ll>>> dp(N + 1, vector<vector<ll>>(N + 1, vector<ll>(N + 1)));
for (ll i = 0; i < N; i++) {
for (ll j = 0; j < N; j++) {
if (i + j >= K || i + j >= N) {
continue;
}
dp[i + 1][j][0] = dp[i][j][0] + V[i];
dp[i][j + 1][0] = dp[i][j][0] + V[N - j - 1];
}
}
for (ll i = 0; i <= N; i++) {
for (ll j = 0; j <= N; j++) {
if (i + j >= K || i + j >= N) {
continue;
}
vector<ll> jewels;
copy(begin(V), begin(V) + i, back_inserter(jewels));
copy(end(V) - j, end(V), back_inserter(jewels));
sort(begin(jewels), end(jewels));
for (ll k = 0; k < N && k < jewels.size(); k++) {
if (i + j + k < K) {
dp[i][j][k + 1] = dp[i][j][k] - jewels[k];
}
}
}
}
ll ans = 0;
for (ll i = 0; i <= N; i++) {
for (ll j = 0; j <= N; j++) {
for (ll k = 0; k <= N; k++) {
ans = max(ans, dp[i][j][k]);
}
}
}
cout << ans << endl;
}
int main(){
long long N;
scanf("%lld",&N);
long long K;
scanf("%lld",&K);
std::vector<long long> V(N);
for(int i = 0 ; i < N ; i++){
scanf("%lld",&V[i]);
}
solve(N, K, std::move(V));
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
if(a < b) {
a = b;
return true;
}
return false;
}
template<class T>
inline bool chmin(T &a, T b) {
if(a > b) {
a = b;
return true;
}
return false;
}
const ll INF = 1e18;
const ll MOD = 998244353;
const ll MX = 1000001;
int N, K, ans;
vector<int> a;
void solve() {
cin >> N >> K;
a.resize(N);
for (auto& i : a) cin >> i;
for (int leftTake = 0; leftTake <= min(N, K); leftTake++) {
int tmp = 0;
multiset<int> lq, rq;
for (int i = 0; i < leftTake; i++) {
lq.insert(a[i]);
tmp += a[i];
}
for (int rightTake = 0; rightTake + leftTake <= min(N, K); rightTake++) {
int rtmp = tmp;
for (int i = 1; i <= rightTake; i++) {
rq.insert(a[N - i]);
rtmp += a[N - i];
}
auto lp = lq.begin(), rp = rq.begin();
for (int i = 0; i < K - leftTake - rightTake; i++) {
bool lv = (lp != lq.end() && *lp < 0), rv = (rp != rq.end() && *rp < 0);
if (lv && rv) {
if (*lp < *rp) {
rtmp -= *lp;
lp++;
} else {
rtmp -= *rp;
rp++;
}
} else if (lv) {
rtmp -= *lp;
lp++;
} else if (rv) {
rtmp -= *rp;
rp++;
} else break;
}
chmax(ans, rtmp);
rq.clear();
}
lq.clear();
}
cout << ans;
}
int main() {
cin.sync_with_stdio(0); cin.tie(0);
ll T = 1;
while (T--) solve();
return 0;
} | 1 | 72,010,058 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 100005;
int n;
bitset<N> eaten;
ll ans;
int main() {
cin.sync_with_stdio(0); cin.tie(0);
eaten.reset();
cin >> n;
vector<pair<int, pair<int, int>>> a, b;
for (int i = 0 ; i < n; i++) {
int x, y;
cin >> x >> y;
a.push_back({x + y, {x, i}});
b.push_back({x + y, {y, i}});
}
sort(a.begin(), a.end(), greater<pair<int, pair<int, int>>>());
sort(b.begin(), b.end(), greater<pair<int, pair<int, int>>>());
int ai = 0, bi = 0;
for (int i = 0; i < n; i++) {
if (!(i % 2)) {
while (eaten[a[ai].second.second]) ai++;
eaten[a[ai].second.second] = true;
ans += a[ai].second.first;
} else {
while (eaten[b[bi].second.second]) bi++;
eaten[b[bi].second.second] = true;
ans -= b[bi].second.first;
}
}
cout << ans;
} | #include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;
using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000, boost::int128_type>>;
typedef uintmax_t ull;
typedef intmax_t ll;
typedef uint64_t ul;
typedef uint32_t ui;
typedef uint8_t uc;
constexpr char CRLF = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }
template<class T> inline bool isSosuu(const T& n) { if (n == T(1)) { return false; } for (T i = 2; i*i <= n; ++i) { if (n % i == 0) { return false; } } return true; }
template<class T> vector<vector<T>> split (const vector<T>& S, T delim) { vector<vector<T>> ret{}; vector<T> buff{}; for (auto c : S) { if (c == delim) { if (!buff.empty()) ret.push_back(buff); buff.clear(); } else { buff.push_back(c); } } if (!buff.empty()) ret.push_back(buff); return ret; }
template<class T> inline void printYesNo(const T& t) { cout << (t ? "Yes" : "No") << CRLF; }
template<class T = int64_t> T modpow(T N, T P, T M) { T ret{1}; N %= M; while (P) { if (P & 0x01) { ret *= N; ret %= M; } P >>= 1; N *= N; N %= M; } return ret; }
int gErr = 0;
#define ASSERT(p) if(!(p)){ gErr = 1; }else{ ; }
struct Tmp
{
public:
int N;
Tmp(int N)
: N(N)
{}
};
void solve(void)
{
int N; cin >> N;
vector<ll> A(N), B(N);
vector<int> idxList(N);
for (int i = 0; i < N; ++i) {
ll a, b; cin >> a >> b;
A[i] = a;
B[i] = b;
idxList[i] = i;
}
auto cmp = [&A, &B](const int i, const int j) {
return A[i] + B[i] > A[j] + B[j];
};
std::sort(idxList.begin(), idxList.end(), cmp);
ll sumA{}, sumB{};
for (int i = 0; i < N; ++i) {
if (i % 2 == 0) {
sumA += A[idxList[i]];
} else {
sumB += B[idxList[i]];
}
}
auto ans = sumA - sumB;
cout << ans << CRLF;
return;
}
int main(void)
{
std::ios_base::sync_with_stdio(false);
std::cin.tie(0);
solve();
return 0;
} | 1 | 25,634,756 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
int a, b;
cin >> a >> b;
string L(b, '0'+a);
string R(a, '0'+b);
cout << min(L, R) << endl;
return 0;
} | #include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
inline int read() {
int x=0;char c=getchar();
while (c<'0'||c>'9') c=getchar();
while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
return x;
}
string x,y;
int main() {
string a,b;
cin>>a>>b;
int n=a[0]-'0',m=b[0]-'0';
for (int i=1;i<=n;++i) x+=b;
for (int i=1;i<=m;++i) y+=a;
if (x<y) cout<<x<<endl;
else cout<<y<<endl;
return 0;
} | 1 | 81,513,120 |
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
ll n = 0;
cin >> n;
ll res = 0;
res = pow(10,18);
for(int i = 1;i <= sqrt(n);i++){
if(n % i == 0){
res = min(res,i + n / i - 2);
}
}
cout << res << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
#define all(x) x.begin(),x.end()
#define YES {cout << "YES\n"; return;}
#define NO {cout << "NO\n"; return;}
const int INF=INT_MAX;
const ld PI=acos(-1);
const ld E=2.71828183;
const int MOD=1e9+7;
vi bfs(vector<vi>adj,int src){
queue<int>q;
q.push(src);
vi dst(adj.size(),INF);
dst[src]=0;
while(!q.empty()){
int c=q.front();
q.pop();
for(int nbr:adj[c]){
if(dst[nbr]==INF){
dst[nbr]=dst[c]+1;
q.push(nbr);
}
}
}
return dst;
}
vi bfsParents(vector<vi>adj,int src){
vi parents=vi(adj.size(),INF);
parents[src]=-1;
queue<int>q;
q.push(src);
vi dst(adj.size(),INF);
dst[src]=0;
while(!q.empty()){
int c=q.front();
q.pop();
for(int nbr:adj[c]){
if(dst[nbr]==INF){
parents[nbr]=c;
dst[nbr]=dst[c]+1;
q.push(nbr);
}
}
}
return parents;
}
vi shortestPath(vector<vi>adj,int src,int dst){
vi bfsParetns=bfsParents(adj,src);
vi ans;
while(src!=dst){
if(bfsParetns[src]==INF)
return {};
ans.push_back(src);
src=bfsParetns[src];
}
return ans;
}
int powMod(int base,int exp,int mod){
int ans=1;
for(int i=0; i<exp; i++)
ans=((ans%mod)*(base%mod))%mod;
return ans;
}
vi divisorsOf(int n){
vi ans;
for(int i=1; i*i<=n; i++){
if(n%i==0)
ans.push_back(i);
if(i*i!=n && i!=1)
ans.push_back(n/i);
}
return ans;
}
ll gcd(ll a,ll b){if(a%b==0) return b; else return gcd(b,a%b);}
ld log (ld a,ld b){return log(b)/log(a);}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}
ll power(ll base, ll exp){ll res=1;while(exp){exp--;res*=base;}return res;}
void solve();
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t=1;
while(t--)
solve();
return 0;
}
void solve (){
ull n;
cin >> n;
ull best=1e13;
for(ull i=1; i*i<=n; i++){
if(n%i==0)
best=min(best,i+n/i);
}
cout << best -2<< "\n";
} | 1 | 59,969,618 |
#include<bits/stdc++.h>
using namespace std;
#define INFLL 1e17
#define MOD 1000000007
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<ll,ll> pr;
vector<vector<pair<int,ll>>>G;
vector<ll>dist;
void DFS(int v){
for(auto &itr:G[v]){
if(dist[itr.first]!=-INFLL){
if(dist[itr.first]!=dist[v]+itr.second){
cout<<"No";
exit(0);
}
continue;
}
dist[itr.first]=dist[v]+itr.second;
DFS(itr.first);
}
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n,m;
int l,r;
ll d;
cin>>n>>m;
G=vector<vector<pair<int,ll>>>(n);
dist=vector<ll>(n,-INFLL);
for(int i=0;i<m;i++){
cin>>l>>r>>d;
G[l-1].push_back(make_pair(r-1,d));
G[r-1].push_back(make_pair(l-1,-d));
}
for(int i=0;i<n;i++){
if(dist[i]==-INFLL){
dist[i]=0;
DFS(i);
}
}
cout<<"Yes";
return 0;
} | #include<iostream>
#include<stdio.h>
#include<vector>
#include<cmath>
#include<queue>
#include<string.h>
#include<map>
#include<set>
#include<algorithm>
#define ll long long
#define pi pair < ll,ll >
#define mp(a,b) make_pair(a,b)
#define mid (low+high)/2
#define rep(i,a,b) for(int i = a;i < b;i++)
#define N 300004
#define INF 1e9+7
using namespace std;
ll n,m;
vector < pi > info[N];
ll a,b,c;
ll dist[N];
bool vis[N];
bool can = true;
void dfs(ll cur,ll d)
{
if(vis[cur])
{
if(dist[cur] != d)
can = false;
return;
}
vis[cur] = true;
dist[cur] = d;
rep(i,0,info[cur].size())
{
dfs(info[cur][i].first,d+info[cur][i].second);
}
return;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
rep(i,0,m)
{
cin >> a >> b >> c;
info[a].push_back(mp(b,c));
info[b].push_back(mp(a,-c));
}
rep(i,1,n+1)
{
if(!vis[i])
{
dfs(i,0);
}
}
if(can)
cout << "Yes\n";
else
cout << "No\n";
return 0;
} | 1 | 10,679,673 |
typedef long long ll;
typedef long double ld;
#include <bits/stdc++.h>
using namespace std;
int main() {
ll n;
std::cin >> n;
vector<ll> a(n+1);
vector<ll> asum(n+2,0);
for (int i = 0; i < n+1; i++) {
std::cin >> a[i];
asum[i+1] = asum[i]+a[i];
}
vector<ll> cnt(n+1,0);
cnt[0] = 1;
ll sum = 1;
cnt[0]-=a[0];
if(n==0&&a[0]!=1){
std::cout << -1 << std::endl;
return 0;
}
for (int i = 1; i < n+1; i++) {
cnt[i] = min(asum[n+1]-asum[i+1],cnt[i-1]*2-a[i]);
sum += a[i];
if((cnt[i]<=0&&i!=n)||cnt[i]<0){
std::cout << -1 << std::endl;
return 0;
}
if(i!=n)sum += cnt[i];
}
std::cout << sum << std::endl;
} | #include <bits/stdc++.h>
using namespace std;
#define ris return *this
#define tmplt template<class T
#define dbgo debug& operator<<
tmplt > struct rge { T b, e; };
tmplt > rge<T> range(T i, T j) { return rge<T>{i, j}; }
struct debug {
#ifdef LOCAL
~debug(){cerr<<endl;}
tmplt > dbgo(T x){cerr<<boolalpha<<x;ris;}
tmplt, class C > dbgo(pair<T, C> x){ris<<"("<<x.first<<", "<<x.second<<")";}
tmplt > dbgo(rge<T> x){*this<<"[";for(auto it=x.b;it!=x.e;it++){*this<<", "+2*(it==x.b)<<*it;}ris<<"]";}
tmplt > dbgo(vector<T> x){ris<<range(x.begin(),x.end());}
#else
tmplt > dbgo(const T&){ris;}
#endif
};
#define nav(...) << "[ " << #__VA_ARGS__ ": " << (__VA_ARGS__) << " ] "
using ll = long long;
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define ford(i, n) for(int i = n-1; i >= 0; i--)
template<typename T>
void min_self(T& a, T b) {
a = min(a, b);
}
template<typename T>
void max_self(T& a, T b) {
a = max(a, b);
}
void no() {
cout << "-1\n";
exit(0);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
++n;
vector<ll> a(n);
forn(i, n) cin >> a[i];
if(n == 1) {
cout << (a[0] == 1 ? 1 : -1) << '\n';
exit(0);
}
if(a[0] == 1) {
no();
}
vector<ll> suf(n);
suf[n-1] = a[n-1];
for(int i = n-2; i >= 0; i--) {
suf[i] = suf[i+1] + a[i];
}
ll ans = 1;
ll prev = 1;
for(int i = 1; i < n; i++) {
ll can_have = 2*prev;
ll maybe = suf[i];
min_self(can_have, maybe);
debug() nav(i) nav(can_have);
if(can_have < a[i]) {
no();
}
else {
ans += can_have;
}
prev = can_have - a[i];
}
cout << ans << endl;
} | 1 | 32,106,382 |
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define MOD 1000000007
int main() {
int n;
cin >> n;
cout << (n - 1) / 2 << endl;
return 0;
} | #include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;
int main(){
ll N;
cin>>N;
cout<<(N-1)/2<<endl;
} | 1 | 50,843,317 |
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
using namespace std;
int main(){
int n;
cin >> n;
string s;
cin >> s;
s+=s[0];
s+=s[1];
bool flag=false;
vector<int> v(n+2);
rep(i,2){
rep(j,2){
v.clear();
v.resize(n+2);
v[0]=i;
v[1]=j;
for(int k=2;k<n+2;k++){
if(s[k-1]=='o' && v[k-2]==0 && v[k-1]==0){
v[k]=0;
}
if(s[k-1]=='o' && v[k-2]==0 && v[k-1]==1){
v[k]=1;
}
if(s[k-1]=='o' && v[k-2]==1 && v[k-1]==0){
v[k]=1;
}
if(s[k-1]=='o' && v[k-2]==1 && v[k-1]==1){
v[k]=0;
}
if(s[k-1]=='x' && v[k-2]==0 && v[k-1]==0){
v[k]=1;
}
if(s[k-1]=='x' && v[k-2]==0 && v[k-1]==1){
v[k]=0;
}
if(s[k-1]=='x' && v[k-2]==1 && v[k-1]==0){
v[k]=0;
}
if(s[k-1]=='x' && v[k-2]==1 && v[k-1]==1){
v[k]=1;
}
}
if(v[0]==v[n] && v[1]==v[n+1]){
rep(i,n){
if(v[i]==0)cout << 'S';
else cout << 'W';
}
cout << endl;
return 0;
}
}
}
cout << -1 << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;
ld pie=3.1415926535;
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;
int main(){
int n,cnt=0; cin>>n;
string s; cin>>s;
vector<string> c={"SS","SW","WS","WW"};
for(auto st:c){
string ans=s;
ans[0]=st[0]; ans[1]=st[1];
for(int i=2;i<n;i++){
if(ans[i-2]=='S' && ans[i-1]=='S' && s[i-1]=='o')
ans[i]='S';
if(ans[i-2]=='S' && ans[i-1]=='S' && s[i-1]=='x')
ans[i]='W';
if(ans[i-2]=='S' && ans[i-1]=='W' && s[i-1]=='o')
ans[i]='W';
if(ans[i-2]=='S' && ans[i-1]=='W' && s[i-1]=='x')
ans[i]='S';
if(ans[i-2]=='W' && ans[i-1]=='S' && s[i-1]=='o')
ans[i]='W';
if(ans[i-2]=='W' && ans[i-1]=='S' && s[i-1]=='x')
ans[i]='S';
if(ans[i-2]=='W' && ans[i-1]=='W' && s[i-1]=='o')
ans[i]='S';
if(ans[i-2]=='W' && ans[i-1]=='W' && s[i-1]=='x')
ans[i]='W';
}
if(ans[n-1]=='S'){
if((ans[n-2]==ans[0] && s[n-1]=='o') ||
(ans[n-2]!=ans[0] && s[n-1]=='x')){
if(ans[0]=='S'){
if((ans[n-1]==ans[1] && s[0]=='o') ||
(ans[n-1]!=ans[1] && s[0]=='x')){
cout<<ans<<endl;
break;
}
}
else{
if((ans[n-1]==ans[1] && s[0]=='x') ||
(ans[n-1]!=ans[1] && s[0]=='o')){
cout<<ans<<endl;
break;
}
}
}
}
else{
if((ans[n-2]==ans[0] && s[n-1]=='x') ||
(ans[n-2]!=ans[0] && s[n-1]=='o')){
if(ans[0]=='S'){
if((ans[n-1]==ans[1] && s[0]=='o') ||
(ans[n-1]!=ans[1] && s[0]=='x')){
cout<<ans<<endl;
break;
}
}
else{
if((ans[n-1]==ans[1] && s[0]=='x') ||
(ans[n-1]!=ans[1] && s[0]=='o')){
cout<<ans<<endl;
break;
}
}
}
}
cnt++;
if(cnt==4) cout<<-1<<endl;
}
} | 1 | 54,504,864 |
#include<iostream>
int main()
{
int result[50];
int num;
for(int i = 0;; i++)
{
result[i] = 0;
int n;
std::cin >> n;
if(std::cin.eof())
{
num = i;
break;
}
for(int j = 0; j <= 9; j++)
{
for(int k = 0; k <= 9; k++)
{
for(int l = 0; l <= 9; l++)
{
for(int m = 0; m <= 9; m++)
{
if(j + k + l + m == n)
{
result[i]++;
}
}
}
}
}
}
for(int i = 0; i < num; i++)
{
std::cout << result[i] << std::endl;
}
return 0;
} | #include<cstdio>
int main(){
int n;
int a[] = {1,4,10,20,35,56,84,120,165,220,282,348,415,480,540,592,633,660,670,660,633,592,540,480,415,348,282,220,165,120,84,56,35,20,10,4,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
while(scanf("%d", &n) + 1){
printf("%d\n", a[n]);
}
return 0;
} | 1 | 3,109,100 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
void solve(); int main() { solve(); return 0; }
void solve() {
int a, b;
string s;
cin >> a >> b >> s;
int i=0;
while (i<a) {
if (s[i++] == '-') {
cout << "No" << endl;
return;
}
}
if (s[i++] != '-') {
cout << "No" << endl;
return;
}
b += 1 + a;
while (i<b) {
if (s[i++] == '-') {
cout << "No" << endl;
return;
}
}
cout << "Yes" << endl;
} | #include "bits/stdc++.h"
using ll = long long;
using namespace std;
const double pi = acos(-1);
pair <double, double> rotate(int x, int y, int degree, double d) {
double theta = (2 * pi / 360) * degree;
double x_ = x * cos (theta) - y * sin(theta);
double y_ = x * sin (theta) + y * cos(theta);
x_ *= d;
y_ *= d;
return {x_, y_};
}
const double eps = 1e-3;
int near(double x) {
for(int i = (int)(x - 2); i < (int)(x + 2); i++) {
if(abs(i - x) < eps) {
return i;
}
}
return 0;
}
void solve() {
string s;
int a, b;
cin >> a >> b >> s;
bool ok = true;
ok &= s[a] == '-';
for(int i = 0; i < s.length(); i++) {
if(i == a)
continue;
else ok &= s[i] >= '0' && s[i] <= '9';
}
cout << (ok?"Yes":"No") << endl;
}
int main() {
cin.tie(0);
cin.sync_with_stdio(0);
int testcase = 1;
for(int i = 0; i < testcase; i++) {
solve();
}
return 0;
} | 1 | 84,279,473 |
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ITER(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))
#define SZ(a) (int)((a).size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
typedef long long LL;
typedef pair<int, int> PII;
const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = (LL)INF * INF;
const int MAX = 1 << 18;
int a[MAX], b[MAX];
int main()
{
int n;
cin >> n;
LL s = 0;
int mn = INF;
FOR(i, 0, n)
{
cin >> a[i] >> b[i];
s += b[i];
if(a[i] > b[i])
mn = min(mn, b[i]);
}
cout << (mn == INF ? 0 : s - mn) << "\n";
return 0;
} | #include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long LL;
LL n;
int main()
{
bool tf=true;
LL ans=0,lalal=(1<<30);
scanf("%lld",&n);
for (LL u=1;u<=n;u++)
{
LL a,b;
scanf("%lld%lld",&a,&b);
if (a!=b) tf=false;
ans=ans+a;
if (a>b) lalal=min(lalal,b);
}
if (tf) printf("0");
else printf("%lld\n",ans-lalal);
return 0;
} | 1 | 53,639,518 |
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;
#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)
ll dp0[110][5], dp1[110][5];
int main() {
string s;
cin >> s;
int K;
cin >> K;
int t = s.length();
int q = s[0] - '0';
dp0[1][0] = 1;
dp0[1][1] = (s[0] - '0') - 1;
dp1[1][0] = 0;
dp1[1][1] = 1;
for(int i=2; i<4; i++) {
dp0[1][i] = 0;
dp1[1][i] = 0;
}
for(int i=1; i<=t-1; i++) {
int p = s[i] - '0';
rep(j, K+1) {
dp0[i+1][j] += dp0[i][j];
dp0[i+1][j+1] += dp0[i][j] * 9;
if(p != 0) {
dp0[i+1][j+1] += dp1[i][j] * (p-1);
dp0[i+1][j] += dp1[i][j];
dp1[i+1][j+1] += dp1[i][j];
}
if(p == 0) {
dp1[i+1][j] += dp1[i][j];
}
}
}
ll ans = dp0[t][K] + dp1[t][K];
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = 1000000007;
const int INF = 1e15;
using Graph = vector<vector<int>>;
int dp[1100][2][6];
signed main(){
string N;
cin >> N;
int K;
cin >> K;
dp[0][0][0] = 1;
for( int i = 0; i < N.size(); i++ ){
for( int k = 0; k <= K; k++ ){
dp[i+1][1][k+1] += dp[i][1][k]*9;
dp[i+1][1][k] += dp[i][1][k];
int NX = N.at(i)-'0';
if( NX != 0 ) dp[i+1][1][k] += dp[i][0][k];
for( int n = 1; n < NX; n++ ){
dp[i+1][1][k+1] += dp[i][0][k];
}
if( NX == 0 ) dp[i+1][0][k] += dp[i][0][k];
else dp[i+1][0][k+1] += dp[i][0][k];
}
}
int A = (int)N.size();
cout << dp[A][0][K] + dp[A][1][K] << endl;
} | 1 | 21,387,051 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
vector<int>arr(n);
for(int i=0; i<n; i++) cin>>arr[i];
int curr = 0;
for(int i=0; i<n; i++){
if(arr[i]==curr+1) curr++;
}
if(!curr) cout<<-1;
else cout<<n-curr;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fix cout << fixed; cout << setprecision(0)
void solve() {
int n;
cin >> n;
int arr[n];
for(int i = 0; i < n; i++) {
cin >> arr[i];
}
int cnt = 0;
int k = 1;
for(int i = 0; i < n; i++) {
if(arr[i] != k) {
cnt++;
}
else {
k++;
}
}
if(cnt == n) {
cout << -1;
}
else {
cout << cnt;
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
fix;
solve();
return 0;
} | 1 | 59,152,951 |
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x)(x).begin(), (x).end()
#define rall(v)(v).rbegin(), (v).rend()
#define INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair < ll, ll >
#define F first
#define S second
const int MOD = 1000000007;
template < class T > bool chmax(T & a,const T & b) { if (a < b) { a = b; return true; } return false; }
template < class T > bool chmin(T & a,const T & b) { if (a > b) { a = b; return true; } return false; }
int main() {
int N;cin >> N;
vector<int> A(N);
vector<int> B(N);
vector<LL> AB(N);
rep(i,N)cin >> A[i] >> B[i];
rep(i,N)AB[i] = A[i] + B[i];
LL ans = 0;
rep(i,N)ans -= B[i];
sort(rall(AB));
rep(i,N){
if(i % 2 == 0)ans += AB[i];
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main(void){
int N;
cin >> N;
vector<long long> A(N),B(N);
vector<pair<long long,long long>> C;
for(int i = 0; i < N;i++){
cin >> A[i] >> B[i];
C.push_back(make_pair(A[i]+B[i],i));
}
sort(C.begin(),C.end());
reverse(C.begin(),C.end());
long long tSum = 0,aSum = 0;
for(int i = 0; i < N;i++){
int index = C[i].second;
if(i % 2 == 0){
tSum += A[index];
}else{
aSum += B[index];
}
}
cout << tSum - aSum << endl;
} | 1 | 91,764,596 |
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
#define REP1(i,a,b) for(int i=(a);i<=(b);i++)
#define em emplace_back
#define ALL(x) (x).begin(),(x).end()
#define F first
#define S second
#define mkp make_pair
#define pii pair<int,int>
#define oi ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pll pair<ll,ll>
int main(){
int n,x[3]={},a,b,y;
cin>>n>>a>>b;
while(n--){
cin>>y;
if(y<=a) x[0]++;
else if(y>a&&y<=b) x[1]++;
else x[2]++;
}
cout<<min(x[0],min(x[1],x[2]))<<"\n";
return 0;
} | #include<bits/stdc++.h>
#include<cmath>
#pragma GCC optimize("Ofast")
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
const ll MOD = 1000000007;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++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; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};
#define print(x) cout << (x) << endl;
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
for(auto &e:u) fill_v<T>(e,v...);
}
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll lcm(ll a, ll b) {
return a * b / gcd(a, b);
}
using pint = pair<int, int>;
using pll = pair<ll, ll>;
int main(void)
{
cout.tie(0);
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
ll n;
cin >> n;
ll a,b;
cin >> a >> b;
vector<ll> p(n);
rep(i,n) cin >> p[i];
ll min1 = 0;
ll min2 = 0;
ll min3 = 0;
rep(i,n){
if(p[i] <= a) min1++;
if(a+1 <= p[i] && p[i] <= b) min2++;
if(p[i] >= b+1) min3++;
}
print(min({min1,min2,min3}));
} | 1 | 100,559,131 |
#include<bits/stdc++.h>
using namespace std;
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) ((a) / gcd(a,b)) * (b)
#define all(x) x.begin(),x.end()
#define ll long long
#define ull unsigned long long
#define VI vector<int>
#define VLL vector<ll>
#define VS vector<string>
#define MPII map<int, int>
#define SET set<int>
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795
#define INF (int)1e9
#define MEM(a, b) memset(a, (b), sizeof(a))
#define fast_io ios_base::sync_with_stdio(false);cin.tie(0),cout.tie(0);
ll MOD = 1e9+7;
ll add(ll a, ll b)
{
a+=b; a%=MOD;
if(a<0) a+=MOD;
return a;
}
ll mult(ll a, ll b)
{
if(a>MOD) a%=MOD;
if(b>MOD) b%=MOD;
ll ans=(a*b)%MOD;
if(ans<0) ans+=MOD;
return ans;
}
ll pw(ll a, ll b)
{
ll r=1;
while(b){
if(b&1) r=mult(r,a);
a=mult(a,a);
b>>=1;
}
return r;
}
void solve(){
string a, b;
cin >> a >> b;
size_t as = a.size();
size_t bs = b.size();
if (as > bs) {
cout << "GREATER" << endl;
} else if (as < bs) {
cout << "LESS" << endl;
} else {
bool eq = true;
for (int i = 0; i < as; i++) {
if (a[i] > b[i]) {
cout << "GREATER" << endl;
eq = false;
break;
} else if (b[i] > a[i]) {
cout << "LESS" << endl;
eq = false;
break;
}
}
if (eq) {
cout << "EQUAL" << endl;
}
}
}
int main(){
fast_io;
ll t, k=0;
t=1;
while(t--){
solve();
}
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<int, int> P;
#define INF 1000000000000
#define MOD 1000000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define Z class
template <typename T>
T square(T x) { return x * x; }
template <class T>
T GCD(T a, T b)
{
T r;
while (a)
r = b, b = a, a = r % a;
return b;
}
template <class T>
T LCM(T a, T b) { return a / GCD(a, b) * b; }
#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repd(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (b); i--)
#define FORA(i, I) for (const auto &i : I)
#define ALL(x) x.begin(), x.end()
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef vector<ll> vl;
#define ERASE(x) x.erase(unique(ALL(x)), x.end());
#define VEC(type, c, n) \
std::vector<type> c(n); \
for (auto &i : c) \
std::cin >> i;
#define INIT \
std::ios::sync_with_stdio(false); \
std::cin.tie(0);
#define VAR(type, ...) \
type __VA_ARGS__; \
MACRO_VAR_Scan(__VA_ARGS__);
template <typename T>
void MACRO_OUT(const T t) { std::cout << t; }
#define OUT(...) MACRO_OUT(__VA_ARGS__);
#define SP std::cout << " ";
#define TAB std::cout << "\t";
#define BR std::cout << "\n";
#define ENDL std::cout << std::endl;
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n", (x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define ln cout << '\n'
template <Z A>
void pr(A a)
{
cout << a;
ln;
}
template <Z A, Z B>
void pr(A a, B b)
{
cout << a << ' ';
}
ll ans = 0;
bool check = 0;
string s, t;
int N = 3;
vector<int> v(N);
int x, y;
int sum;
char ch;
int main()
{
INIT;
char a[100+2], b[100+2];
int r;
cin >>a >> b;
r=strlen(a)-strlen(b);
if(r==0)
{
r=strcmp(a, b);
}
if(r>0) printf("GREATER\n");
if(r<0) printf("LESS\n");
if(r==0) printf("EQUAL\n");
return 0;
} | 1 | 43,193,708 |
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>
using namespace std;
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define P pair<int, int>
typedef vector<int> vec;
typedef vector<vec> mat;
int main(){
int n, m;
cin >> n >> m;
int l[m], r[m];
int mx = n;
int mn = 1;
rep(i, m) {
cin >> l[i] >> r[i];
mx = min(mx, r[i]);
mn = max(mn, l[i]);
}
cout << max(mx - mn + 1, 0) << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<string,int>;
const double PI = acos(-1);
int main() {
int n,m;
cin >> n >> m;
vector<vector<int>> a(m,vector<int>(2));
rep(i,m)rep(j,2) cin >> a.at(i).at(j);
int lft = -1,rgt = 1000000;
rep(i,m)rep(j,2){
lft = max(lft,a.at(i).at(0)) ;
rgt = min(rgt,a.at(i).at(1)) ;
}
int ans = rgt - lft +1;
cout << (ans>=0?ans:0)<< endl;
} | 1 | 2,255,816 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
string s,t;cin>>s>>t;
set<int> st;
int a[26]{};
fill(a,a+26,-1);
for (int i=0;i<s.size();i++) {
if (a[s[i]-'a']==-1) {
if (st.count(t[i]-'a')) {
cout<<"No"<<endl;
return 0;
}
a[s[i]-'a']=t[i]-'a';
st.insert(t[i]-'a');
} else if (a[s[i]-'a']!=t[i]-'a') {
cout<<"No"<<endl;
return 0;
}
}
cout<<"Yes"<<endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
template <typename T> bool chmax(T &u, const T z) { if (u < z) {u = z; return true;} else return false; }
template <typename T> bool chmin(T &u, const T z) { if (u > z) {u = z; return true;} else return false; }
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
const ll INF=1LL<<60;
ll gcd(ll x,ll y){return y? gcd(y,x%y) :x;}
int main(){
string s,t;
cin>>s>>t;
vector<int>start(26,-1);
vector<int>goal(26,-1);
rep(i,s.size()){
int a=s[i]-'a';
int b=t[i]-'a';
if(start[a]!=-1||goal[b]!=-1){
if(start[a]!=b||goal[b]!=a){
cout<<"No"<<endl;
return 0;
}
}else{
start[a]=b;
goal[b]=a;
}
}
cout<<"Yes"<<endl;
return 0;
} | 1 | 14,208,138 |
#include<bits/stdc++.h>
using namespace std;
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
#define gcd __gcd
#define append push_back
#define str to_string
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
typedef long long int ll;
#define int ll
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997;
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI = 3.14159265358979323846L;
constexpr auto oo = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int32_t main(){
fastio();
int n , a , b;
cin >> n >> a >> b;
int ans = (n / (a + b)) * a + min(n%(a + b) , a);
cout << ans;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
#define int long long
signed main() {
int n, a, b;
cin >> n >> a >> b;
int cycle = a + b;
int loop = n / cycle;
int blue = a * loop;
int left = n - cycle * loop;
left = min(left, a);
blue += left;
cout << blue << '\n';
} | 1 | 13,738,324 |
#include<iostream>
using namespace std;
int main(){
int n; cin >> n;
int ans = 0;
while(n--){
int l, r; cin >> l >> r;
ans += r - l + 1;
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
#define ALL(a) (a).begin(),(a).end()
const ll INF = 1e18+18;
const ll MAX = 200000;
const ll MOD = 1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
static const long double pi = 3.141592653589793;
int main(){
ll N;
cin>>N;
ll Ans=0;
rep(i, N){
ll l, r;
cin>>l>>r;
Ans+=(r-l+1);
}
cout<<Ans<<endl;
} | 1 | 37,176,103 |
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;
#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll>
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a)
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b)
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}
string YN(bool v) { return v ? "Yes":"No"; }
void uniq(VI& es) { sort(ALL(es)); es.erase(unique(ALL(es)), es.end()); }
#define INF (1LL<<60)
ll f(ll x, ll y) {
ll v=0;
if(y==x) return 0;
if(0<y) {
if(y<x) return 1+f(-x, y);
if(0<=x) return y-x;
if(abs(x)<y) return 1+f(-x, y);
return abs(-y-x)+1;
} else {
if(abs(y)<x) return 1+f(-x, y);
if(0<=x) return abs(y)-x+1;
if(y<x) return 1+f(-x, y);
return abs(y-x);
}
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll x,y;
while(cin>>x>>y) {
cout<<f(x, y)<<endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
int main(){
int X,Y;
cin >> X >> Y;
int ans = 2e9+1;
for(int i=0;i<2;i++) for(int j=0;j<2;j++){
int x = (i? -X:X),y = (j? -Y:Y);
if(x<=y) ans = min(ans,i+j+y-x);
}
cout << ans << "\n";
} | 1 | 87,108,115 |
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>
using namespace std;
using ll = long long;
constexpr ll INF = 1010000000000000017LL;
constexpr ll mod = 1000000007;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
int main() {
string n;
cin>>n;
ll sum = 0;
rep(i, n.size()){
sum+=n[i]-'0';
}
cout<<((sum%9==0) ? "Yes" : "No")<<endl;
} | #include <bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fod(i,a,b) for(int i=a;i>=b;i--)
#define me0(a) memset(a,0,sizeof(a))
#define me1(a) memset(a,-1,sizeof(a))
#define op freopen("in.txt", "r", stdin)
#define op1 freopen("C:\\acm\\Cproj\\in.txt","r",stdin);
#define pr freopen("C:\\acm\\Cproj\\out.txt","w",stdout)
#define pr2 freopen("C:\\acm\\Cproj\\std.txt","w",stdout)
#define pii pair<int,int>
using namespace std;
const int INF = 0x3f3f3f3f;
typedef long long LL;
template <class T>
void read(T &val) { T x = 0; T bz = 1; char c; for (c = getchar(); (c<'0' || c>'9') && c != '-'; c = getchar()); if (c == '-') { bz = -1; c = getchar(); }for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - 48; val = x * bz; }
const int maxn = 1e6 + 11;
const int mod=1e9+7;
int n,m,x,y,t;
char s[maxn];
int main(){
scanf("%s",s);
int len = strlen(s),ans = 0;
fo(i,0,len-1) ans+=s[i]-'0';
if(ans%9) puts("No");
else puts("Yes");
return 0;
} | 1 | 57,340,940 |
#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define x first
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
return uniform_int_distribution<int>(l, r)(rng);
}
const int INF = 1e9, MOD = 1e9 + 7;
const ll LINF = 1e18;
const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
inline bool inside (int x, int y, int n, int m) {
return 0 <= x && 0 <= y && x < n && y < m;
}
template<class T> bool umin (T &a, T b) {return a > b ? (a = b, true) : false; }
template<class T> bool umax (T &a, T b) {return a < b ? (a = b, true) : false; }
main()
{
ios::sync_with_stdio(0);
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int a, b;
cin >> a >> b;
for (int i = 1; i <= 10000000; i++) {
int A = i * 0.08;
int B = i * 0.1;
if (a == A && b == B) {
cout << i << '\n';
rr;
}
}
cout << "-1\n";
} | #include <bits/stdc++.h>
#define REP( i , nn ) for(int i = 0 ; i < (int) nn; i++)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
template <class T>
void print_vect(std::vector<T> v){
for(int i = 0 ; i < v .size(); i++) cout << v[i] << " ";
cout << endl;
}
constexpr int maxV = 1e4;
void solve(){
int a, b;
cin >> a >> b;
int ans;
for( ans = 0 ; ans <= maxV ; ans++){
if( ans * 8 / 100 == a && ans / 10 == b){
break;
}
}
if( ans <= maxV){
cout << ans << "\n";
}else{
cout << "-1";
}
}
int main()
{
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
#ifdef DEBUG
int TEST_CASES = 2;
while(TEST_CASES--){
#endif
solve();
#ifdef DEBUG
}
#endif
return 0;
} | 1 | 27,427,243 |
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
using namespace std ;
int main()
{
int N,A,B ;
cin>>N>>A>>B ;
vector<int>P(N) ;
for(int i=0;i<N;i++) cin>>P.at(i) ;
sort(P.begin(),P.end()) ;
int num_1=0,num_2=0,num_3=0 ;
for(int i=0;i<N;i++){
if(P.at(i)<=A) num_1++ ;
else if(A+1<=P.at(i)&&P.at(i)<=B) num_2++ ;
else if(B+1<=P.at(i)) num_3++ ;
}
int X=(num_1<num_2?num_1:num_2) ;
cout<<(X<num_3?X:num_3)<<endl ;
return 0 ;
} | #include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define sz(s) (int)s.size()
#define OPTIMIZE ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug(x) cerr << "#" << x << ": " << x << '\n';
#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define FORD(i, a, b) for (int i = b; i >= a; i--)
#define FORL(i, a, b) for (LL i = a; i <= b; i++)
#define FORDL(i, a, b) for (LL i = b; i >= a; i--)
using namespace std;
typedef long long LL;
typedef pair<int,int> ii;
typedef pair<LL,LL> pll;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef vector<ii> vii;
typedef vector<pll> vll;
const LL MODPRIME = 1e9 + 7;
const double EPS = 1e-12;
const LL MAXL = 4e18;
const LL MINL = -4e18;
const int MAXI = 2e9;
const int MINI = -2e9;
int N, A, B, a, b, c;
int arr[105];
int main(){
OPTIMIZE
cin >> N >> A >> B;
for (int i = 0; i < N; i++) cin >> arr[i];
sort(arr, arr + N);
for (int i = 0; i < N; i++){
if (arr[i] <= A) a++;
else if (arr[i] > A && arr[i] <= B) b++;
else if (arr[i] > B) c++;
}
cout << min(min(a, b), c) << '\n';
return 0;
} | 1 | 96,002,120 |
#include "bits/stdc++.h"
using namespace std;
void solve()
{
int n, k;
cin >> n >> k;
vector<int> as(n), bs(n);
for (int i = 0; i < n; i++)
{
cin >> as[i] >> bs[i];
}
long ans = 0;
for (int i = -1; i <= 30; i++)
{
int mask;
if (i == -1)
{
mask = k;
}
else
{
if (!(k >> i & 1))
continue;
mask = (k ^ (1 << i)) | ((1 << i) - 1);
}
long res = 0;
for (int j = 0; j < n; j++)
{
if ((mask | as[j]) == mask)
{
res += bs[j];
}
}
ans = max(ans, res);
}
cout << ans << endl;
}
int main()
{
solve();
return 0;
} | #include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
using ll=long long;
constexpr ll mod=1000000007;
constexpr int inf=1000000000;
constexpr ll linf=1000000000000000000;
int main(){
int n,kd;
cin>>n>>kd;
int k[30],a[n][30];
int b[n];
rep(i,30){
k[29-i]=(kd&1);
kd/=2;
}
rep(i,n){
int s;
cin>>s>>b[i];
rep(j,30){
a[i][29-j]=(s&1);
s/=2;
}
}
ll ans=-1;
rep(i,30){
if(k[i]==0)continue;
int s[30];
rep(j,i){
s[j]=k[j];
}
s[i]=0;
for(int j=i+1;j<30;++j){
s[j]=1;
}
ll mx=0;
rep(j,n){
bool flag=true;
rep(l,30){
if(s[l]==0&&a[j][l]==1){
flag=false;
break;
}
}
if(flag)mx+=b[j];
}
ans=max(mx,ans);
}
ll mx=0;
rep(j,n){
bool flag=true;
rep(l,30){
if(k[l]==0&&a[j][l]==1){
flag=false;
break;
}
}
if(flag)mx+=b[j];
}
ans=max(mx,ans);
cout<<ans<<endl;
} | 1 | 63,543,291 |
#include<stdio.h>
int main()
{
int a,b,c,d,s,s1;
scanf("%d%d%d%d",&a,&b,&c,&d);
if(a<b)
s=a;
else
s=b;
if(c<d)
s1=c;
else
s1=d;
printf("%d\n",(s+s1));
} | #include <bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'
using namespace std;
typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;
const int dx[] = {0, -1, 1, 0};
const int dy[] = {-1, 0, 0, 1};
LL fac[SIZE], finv[SIZE], inv[SIZE];
void combInit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for( int i = 2; i < SIZE; ++i ) {
fac[i] = (fac[i - 1] * i) % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = (finv[i - 1] * inv[i]) % MOD;
}
}
LL comb(int n, int k) {
if( n < k ) return 0;
if( n < 0 || k < 0 ) return 0;
return (fac[n] * (finv[k] * finv[n - k] % MOD)) % MOD;
}
vector< int > Div( int n ) {
vector< int > ret;
for( int i = 1; i * i <= n; ++i ) {
if( n % i == 0 ) {
ret.pb( i );
if( i * i != n ) ret.pb( n / i );
}
}
sort( all( ret ) );
return ret;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int a, b, c, d;
cin >> a >> b >> c >> d;
cout << min(a, b) + min(c, d) << endl;
return 0;
} | 1 | 86,616,716 |
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<string>
#include<cstring>
#include<time.h>
#include<array>
#include<iomanip>
#include<list>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<bitset>
#include <queue>
#include <map>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;
#define PRI(s) cout << s << endl
#define PRIY PRI("Yes")
#define PRIN PRI("No")
int ctoi(char c) {
switch (c)
{
case '0': return 0;
case '1': return 1;
case '2': return 2;
case '3': return 3;
case '4': return 4;
case '5': return 5;
case '6': return 6;
case '7': return 7;
case '8': return 8;
case '9': return 9;
default:
cout << "ERR_ctoi" << endl;
return -1;
}
}
int main() {
char b;
cin >> b;
if (b == 'A')PRI('T');
if (b == 'T')PRI('A');
if (b == 'G')PRI('C');
if (b == 'C')PRI('G');
return 0;
} | #include<bits/stdc++.h>
using namespace std;
int main(){
char b;
cin >> b;
if(b=='A') cout << "T" << endl;
else if(b=='T') cout << "A" << endl;
else if(b=='C') cout << "G" << endl;
else if(b=='G') cout << "C" << endl;
return 0;
} | 1 | 54,291,984 |
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;
ll const MOD=1000000007;
string S;
ll K;
int main(){
cin>>S>>K;
bool flag=true;
rep(i,S.size()) flag&=(S[0]==S[i]);
ll ans=0;
if(flag){
ans=K*S.size()/2;
cout<<ans<<endl;
return 0;
}
ll cnt=1;
rep(i,S.size()-1){
if(S[i]==S[i+1]) cnt++;
else{
ans+=cnt/2;
cnt=1;
}
}
ans+=cnt/2;
ans*=K;
if(S[0]==S[S.size()-1]){
int l=0,r=0;
rep(i,S.size()){
if(S[i]==S[0]) l++;
else break;
}
rep(i,S.size()){
if(S[S.size()-1-i]==S[S.size()-1]) r++;
else break;
}
ans+=(K-1)*((l+r)/2-l/2-r/2);
}
cout<<ans<<endl;
} | #include <iostream>
#include <string>
using namespace std;
typedef long long ll;
int main() {
ll k, l, cnt, a[100], ans = 0LL;
string s;
cin >> s >> k;
l = s.length();
cnt = 0LL;
for (int i = 0; i < l; i++) {
if (s[i] == s[0]) {
cnt++;
}
}
if (cnt == l) {
cout << l * k / 2LL << endl;
return 0;
}
for (ll i = 0LL; i < l; i++) {
if (i == 0) {
a[i] = 0;
} else if (s[i] == s[i - 1]) {
a[i] = a[i - 1];
} else {
a[i] = i;
if (a[i - 1] != 0 || s[0] != s[l - 1]) {
ans += (i - a[i - 1]) / 2LL * k;
} else {
ans += i / 2LL;
}
}
}
if (s[l - 1] == s[0]) {
ans += (l - a[l - 1]) / 2LL;
cnt = 0LL;
for (int i = 0; i < l; i++) {
if (a[i] == 0 || a[i] == a[l - 1]) {
cnt++;
}
}
ans += cnt / 2LL * (k - 1LL);
} else {
ans += (l - a[l - 1]) / 2LL * k;
}
cout << ans << endl;
} | 1 | 14,839,288 |
#include<iostream>
using namespace std;
int main(){
int a,i,j,k;
int s=0;
while(cin>>a){
for(i=a;i<600;i+=a){
s+=i*i*a;
}
cout<<s<<endl;
s=0;
}
return 0;
} | #include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
int y,d,d1,sum=0;
while(cin >> d){
sum = 0;
d1 = d;
for(;d<600;d+=d1){
y = d*d*d1;
sum += y;
}
cout << sum << endl;
}
} | 1 | 66,137,082 |
#include <iostream>
typedef long long ll;
int main(){
ll N, K;
std::cin >> N >> K;
ll resa = 0;
for(ll i = K ; i <= N + 1 ; i++){
ll min = (i - 1) * i / 2;
ll max = (N + 1) * N / 2 - (N - i) * (N - i + 1) / 2;
resa += max - min + 1;
}
std::cout << resa % 1000000007<< std::endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int mod = 1e9+7;
int main(){
ll n , k;
cin >> n >> k;
vector<ll> pre(n+3 , 0);
for(ll i = 0 ; i <= n ; i++){
pre[i+1] = i + pre[i];
}
ll ans = 0;
for (ll i = k ; i <= (n+1) ; i++){
ll mx = pre[n+1] - pre[n+1-i];
ll mn = pre[i];
ans += ((mx - mn + 1)%mod);
ans %= mod;
}
cout << ans%mod << endl;
return 0;
} | 1 | 86,686,512 |
#include<stdio.h>
#include<cctype>
int main(){
char ch;
int sum=0;
while(true){
while((ch = getchar()) != '\n'){
sum += ch - '0';
}
if(sum == 0){
break;
} else {
printf("%d\n",sum);
sum = 0;
}
}
return 0;
} | #include <iostream>
#include <string>
using namespace std;
int main()
{
string str;
int sum;
int array[1000];
int j=0;
while(true)
{
cin >> str;
if(str=="0")
break;
sum=0;
for(int i=0;i<str.size();i++)
sum+=str.at(i)-'0';
array[j]=sum;
j++;
}
for(int i=0;i<j;i++)
cout << array[i] << endl;
return 0;
} | 1 | 21,510,189 |
#include<iostream>
using namespace std;
int N_MAX = 200000;
int main()
{
int n,i;
int a[N_MAX];
cin >> n;
for(i=0;i<n;i++)
cin >> a[i];
for(i=n-1;i>=0;i-=2)
cout << a[i] << " ";
for(i=n%2;i<n-1;i+=2)
cout << a[i] << " ";
cout << endl;
return 0;
} | #include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;
int const INF=1001001001;
ll const LINF=1001001001001001001;
ll const MOD=1000000007;
int n;
int a[200000];
int main(){
cin>>n;
rep(i,n) cin>>a[i];
deque<int> q;
rep(i,n){
if(i%2==0) q.push_back(a[i]);
else q.push_front(a[i]);
}
if(n%2==0) while(!q.empty()){
cout<<q.front()<<' '; q.pop_front();
}else while(!q.empty()){
cout<<q.back()<<' '; q.pop_back();
}
cout<<endl;
} | 1 | 67,352,504 |
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n, fact = 1;
scanf("%d", &n);
int t = n;
while(t) {
t = t / 10;
fact = fact * 10;
}
while(fact > 1) {
fact = fact / 10;
if(n / fact == 7) {
printf("Yes\n");
return 0;
}
n = n % fact;
}
printf("No\n");
return 0;
} | #include<iostream>
#include<cmath>
#include<string>
#include<iomanip>
using namespace std;
int main(){
int n;
cin >> n;
if(n%10==7){cout<<"Yes"; return 0;}
else{n/=10;}
if(n%10==7){cout<<"Yes"; return 0;}
else{n/=10;}
if(n%10==7){cout<<"Yes"; return 0;}
else{n/=10;}
cout<<"No";
return 0;
} | 1 | 13,766,266 |
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main()
{
int a, b;
cin >> a >> b;
cout << 6-a-b << endl;
} | #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long;
const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;
int main(void){
int a; cin >> a;
int b; cin >> b;
for(int i = 1;i<=3;i++){
if(i != a && i != b){
cout << i << endl;
return 0;
}
}
return 0;
} | 1 | 37,616,658 |
#include <bits/stdc++.h>
using namespace std;
int kind[5] = {' ','A','C','G','T'};
typedef struct{
vector<int>data;
}H;
H hash[5000000];
int convertion(string s){
int d = 1;
int sum = 0;
for(int i = s.size() - 1;i >= 0;i--){
for(int j = 1;j < 5;j++){
if(kind[j] == s[i]){sum += d * j;break;}
}
d *= 5;
}
return sum;
}
int main(){
string q,s;
int n;
cin >> n;
while(n--){
cin >> q >> s;
if(q == "insert"){
int sum = convertion(s);
hash[sum / 60].data.push_back(sum);
}
if(q == "find"){
int sum = convertion(s);
bool flag = false;
for(int i = 0;i < hash[sum / 60].data.size();i++){
if(hash[sum / 60].data[i] == sum){cout << "yes" << endl;flag = true;break;}
}
if(!flag)cout << "no" << endl;
}
}
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
int n;
cin >> n;
string s,ss;
set<string> dic;
for(int i=0;i<n;i++){
cin >> s >> ss;
if(s=="insert"){
dic.insert(ss);
}else if(s=="find"){
if(dic.count(ss) == 1){
cout << "yes" << endl;
}else{
cout << "no" << endl;
}
}
}
} | 1 | 24,211,509 |
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
int main(){
int N, M, d, p;
while(cin >> N >> M, (N | M)){
vector<P> vec;
for(int i = 0 ; i < N ; i++){
cin >> d >> p;
vec.push_back(P(-p,d));
}
int res = 0;
sort(vec.begin(),vec.end());
for(int i = 0 ; i < N ; i++){
P now = vec[i];
if(M-now.second >= 0){
M -= now.second;
}else{
if(M){
now.second -= M;
M = 0;
}
res += now.second*(-now.first);
}
}
cout << res << endl;
}
return 0;
} | #include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
using namespace std;
struct Section{
int d;
int p;
};
bool operator<( const Section& s1, const Section& s2 ){
return s1.p < s2.p;
}
int main () {
while ( 1 ){
int n, m;
cin >> n >> m;
if( !n && !m ) { return EXIT_SUCCESS; }
vector<Section> vs;
for( int i = 0; i < n; i++ ) {
Section s;
cin >> s.d >> s.p;
vs.push_back( s );
}
sort( vs.begin(), vs.end() );
int rp = 0;
for(
vector<Section>::iterator it = vs.end() - 1;
it != vs.begin() - 1;
it--
){
if( m >= it->d ){
m -= it->d;
}else{
rp += ( it->p * ( it->d - m ) );
m = 0;
}
}
cout << rp << endl;
}
} | 1 | 50,696,173 |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define all(x) (x).begin(), (x).end()
void shuru_krte_hai_bina_kisi_bakchodi_ke()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
int32_t main()
{
int n;
cin >> n;
int a[n + 1];
for (int i = 1; i <= n; i++)
{
cin >> a[i];
}
int dp[n + 1] = {0};
dp[1] = 0;
dp[2] = abs(a[1] - a[2]);
for (int i = 3; i <= n; i++)
{
dp[i] = min(dp[i - 1] + abs(a[i] - a[i - 1]), dp[i - 2] + abs(a[i] - a[i - 2]));
}
cout<<dp[n];
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define ll long long
ll minm;
ll dp[100001];
int fn(ll a[],ll n)
{
if(n==0)
{
dp[0] = min(minm,dp[0]);
return dp[0];
}
if(dp[n] != -1)
{
return dp[n];
}
else if(n>=2)
{
ll x = abs(a[n]-a[n-1]);
ll y = abs(a[n]-a[n-2]);
return dp[n] = min(x+fn(a,n-1),y+fn(a,n-2));
}
else
{
ll x = abs(a[n]-a[n-1]);
return dp[n] = x + fn(a,n-1);
}
return 0;
}
int main()
{
ll i,n;
cin>>n;
ll a[n];
for(i=0; i<n; i++)
{
cin>>a[i];
}
memset(dp,-1,sizeof(dp));
dp[0] = INT_MAX;
fn(a,n-1);
cout<<dp[n-1]<<"\n";
return 0;
} | 1 | 73,809,715 |
#include <iostream>
#include <string>
#define ll long long
using namespace std;
bool allLettersSame(string s){
for(char c:s) if(c!=s[0]) return false;
return true;
}
int main(){
ll score=0, x=1, n;
int len, size=1;
string a;
cin >> a;
cin >> n;
if(allLettersSame(a)){
cout << n * a.size() / 2 << endl;
return 0;
}
len=a.size()-1;
for(int i=1; i<=len; i++){
if(a[i]==a[i-1]){
size++;
}
else{
score+=size/2;
size=1;
}
}
score+=size/2;
int front = 0, back = 0;
if(a[len]==a[0]){
for(int i=0; a[i]==a[0]; i++) front++;
for(int i=a.size()-1; a[i]==a[0]; i--) back++;
}
score*=n;
if(front%2 == 1 && back%2 == 1){
score+=(n-1);
}
cout << score << endl;
return 0;
} | #define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <stdio.h>
#include <vector>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
int main() {
string S;
ll K;
cin >> S >> K;
ll N = S.length();
ll l = 0;
ll r = 0;
ll out = 0;
if(S[0]==S[N-1]){
rep(i,N){
if(S[i]==S[0]) l++;
else break;
}
if(l!=N){
rep(i,N){
if(S[N-1-i]==S[N-1]) r++;
else break;
}
out += l/2 + r/2 + (l+r)/2*(K-1);
}else{
r=N;
out = N*K/2;
}
}
for(ll i=l;i<N-r;i++){
if(S[i]==S[i+1]){
out += K;
i++;
}
}
cout << out << endl;
return 0;
} | 1 | 41,616,902 |
#include<iostream>
using namespace std;
int main(){
int a,b;
cin >> a >> b;
if(a==b){
cout << "a == b\n";
}else if(a<b){
cout << "a < b\n";
}else{
cout << "a > b\n";
}
return 0;
} | #include <iostream>
int main()
{
int a, b;
std::cin >> a >> b;
if(a < b) std::cout << "a < b\n";
if(a > b) std::cout << "a > b\n";
if(a == b) std::cout << "a == b\n";
return (0);
} | 1 | 83,331,802 |
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <map>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define ll long long
ll solve(ll a,ll b){
if (!a) return 0;
ll res=a*(b/a)*2;
return b%a?res+solve(b%a,a):res-a;
}
ll n,x,ans;
int main(){
scanf("%lld%lld",&n,&x);
ans=n+solve(min(x,n-x),max(x,n-x));
printf("%lld\n",ans);
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
int64_t gcd(int64_t a, int64_t b) {return b?gcd(b, a%b):a;}
int64_t lcm(int64_t a, int64_t b) {return a/gcd(a,b)*b;}
int64_t extgcd(int64_t a, int64_t b, int64_t &x, int64_t &y) {
int64_t d = a;
if(b) {
d = extgcd(b, a%b, y, x);
y -= (a/b)*x;
} else {
x = 1; y = 0;
}
return d;
}
ll saiki(ll n, ll x) {
if(n-x < x) x = n-x;
if(x == 1) {
return 3LL * (n-1);
}
return saiki(x + n%x, x) + (n/x-1) * x * 3LL;
}
int main() {
ll n, x;
cin >> n >> x;
ll ans = 1LL;
ans *= gcd(n, x);
n /= ans;
x /= ans;
cout << saiki(n, x) * ans << endl;
} | 1 | 89,704,638 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
string ans;
for (int i = 0; i < s.length(); i++) {
if (i%2 == 0)
ans += s[i];
}
cout << ans;
} | #include <iostream>
#include <string>
using namespace std;
int main() {
string s;
cin >> s;
string res = "";
for(size_t i = 0; i < s.size(); i += 2) res = res + s[i];
cout << res << endl;
return EXIT_SUCCESS;
} | 1 | 71,637,479 |
#include <stdio.h>
#include <string.h>
int main(){
char a[15];
char b[15];
char c [15];
scanf("%s%s%s", a,b,c);
int d= strlen(a)-1;
int e = strlen(b)-1;
if (a[d]==b[0] && b[e]==c[0]){
printf("YES\n");
}
else{
printf("NO\n");
}
return 0;
} | #include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(vec) (vec).begin(), (vec).end()
#define SUM(...) accumulate(ALL(__VA_ARGS__),0LL)
#define DSUM(...) accumulate(ALL(__VA_ARGS__),0.0)
using namespace std;
using ll = long long;
using P = pair<int, int>;
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> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}
void print() { std::cout << '\n'; }
template <class T>void print(const T &x) {std::cout << x <<'\n';}
template <class T, class... Args>void print(const T &x, const Args &... args) {std::cout << x << " ";print(args...);}
const int INF = 2002002002;
const string YES = "YES";
const string NO = "NO";
void solve(std::string A, std::string B, std::string C){
bool ans1 = false;
bool ans2 = false;
if (A[A.length() - 1] == B[0]) ans1 = true;
if (B[B.length() - 1] == C[0]) ans2 = true;
if (ans1 && ans2) print(YES);
else print(NO);
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
std::string A;
std::cin >> A;
std::string B;
std::cin >> B;
std::string C;
std::cin >> C;
solve(A, B, C);
return 0;
} | 1 | 73,475,923 |
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
int n;
cin >> n;
vector<long> v;
for (int i = 0; i < n; ++i) {
long x;
cin >> x;
v.push_back(x);
}
cout << *min_element(v.begin(), v.end()) << " ";
cout << *max_element(v.begin(), v.end()) << " ";
cout << accumulate(v.begin(), v.end(), 0L) << "\n";
} | #include<iostream>
#include<stdio.h>
using namespace std;
int main(){
int i,n,a[10000];
cin>>n;
for(i=0;i<n;i++){
scanf("%d",&a[i]);
}
int min=a[0],k;
for(k=1;k<n;k++){
if(min>a[k]){
min=a[k];
}
}
int max=a[0],h;
for(h=1;h<n;h++){
if(max<a[h]){
max=a[h];
}
}
int j;
long long sum=0;
for(j=0;j<n;j++){
sum+=a[j];
}
cout<<min<<" "<<max<<" "<<sum<<endl;
} | 1 | 11,077,761 |
#include<bits/stdc++.h>
using namespace std;
int main(){
string s;
cin>>s;
string c1, c2;
int ans1=0, ans0=0;
for(int i=0; i<s.size(); i++){
if(i%2 == 0){
if(s[i] == '0'){
ans1++;
}else{
ans0++;
}
}else{
if(s[i] == '0'){
ans0++;
}else{
ans1++;
}
}
}
cout<<min(ans0, ans1)<<endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=1LL<<60;
const ll mod=1000000007;
int main() {
string s;
cin>>s;
int a1=0,a2=0;
for(int i=0;i<s.size();i++){
if(i%2==0){
if(s[i]=='0') a2++;
else a1++;
}
else{
if(s[i]=='0') a1++;
else a2++;
}
}
cout<<min(a1,a2)<<endl;
} | 1 | 12,310,688 |
#include <bits/stdc++.h>
#define rep(i,x,n) for(int i=x; i<(int)(n); i++)
using namespace std;
int main() {
int A, B, K; cin >> A >> B >> K;
vector<int> Ans;
rep( i, 1, min( A, B )+1 ) {
if ( A%i == 0 && B%i == 0 ) Ans.push_back(i);
}
cout << Ans.at( Ans.size()-K ) << endl;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define forn(i, n) for(int i = 0; i < (int)n; ++n)
int main()
{
int a, b, k;
cin >> a >> b >> k;
vector<int> v;
int mini = min(a, b);
for(int i = 1; i <= mini; ++i){
if(a % i == 0 && b % i == 0) {
v.push_back(i);
}
else continue;
}
sort(v.rbegin(), v.rend());
cout << v[k-1] << "\n";
return 0;
} | 1 | 66,075,081 |
#include <iostream>
#include <vector>
using namespace std;
vector<vector<int> > G;
int *color;
vector<int> L;
void visit(int u);
void toporogical_sort(int s) {
color[s] = 1;
for (int i = 0; i < G[s].size(); i++) {
int u = G[s][i];
if (color[u] == 0) {
visit(u);
}
}
L.push_back(s);
}
void visit(int u) {
color[u] = 1;
for (int i = 0; i < G[u].size(); i++) {
int v = G[u][i];
if (color[v] == 0) {
visit(v);
}
}
L.push_back(u);
}
int main() {
int n, m; cin >> n >> m;
G.resize(n);
int a, b;
for (int i = 0; i < m; i++) {
cin >> a >> b;
G[a].push_back(b);
}
color = new int[n];
for (int i = 0; i < n; i++)
color[i] = 0;
for (int i = 0; i < n; i++) {
if (color[i] == 0)
toporogical_sort(i);
}
for (int i = n-1; i >= 0; i--)
cout << L[i] << endl;
return 0;
} | #include <cstdint>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
#define SIZE 10000
static vector<uint32_t> graph[SIZE];
static vector<uint32_t> connected_num(SIZE, 0);
static queue<uint32_t> q;
static vector<uint32_t> sorted;
int32_t main()
{
uint32_t V, E;
cin >> V >> E;
for (uint32_t i = 0; i < E; i++) {
uint32_t s, t;
cin >> s >> t;
graph[s].push_back(t);
connected_num[t]++;
}
for (uint32_t i = 0; i < V; i++) {
if (connected_num[i] == 0) {
q.push(i);
}
}
while (!q.empty()) {
uint32_t index = q.front();
q.pop();
sorted.push_back(index);
for (uint32_t i = 0; i < graph[index].size(); i++) {
connected_num[graph[index][i]]--;
if (connected_num[graph[index][i]] == 0) {
q.push(graph[index][i]);
}
}
}
for (uint32_t i = 0; i < sorted.size(); i++) {
if (i != 0) cout << " ";
cout << sorted[i];
}
cout << endl;
return 0;
} | 1 | 94,725,959 |
#include <iostream>
using namespace std;
typedef long long LL;
LL fact(int);
int main() {
int n;
cin >> n;
cout << fact(n) << "\n";
return 0;
}
LL fact(int n) {
if (n == 1)
return 1;
return fact(n-1) * n;
} | #include <iostream>
using namespace std;
int main() {
int N;
cin >> N;
long long res = 1;
for (auto i=1; i<=N; i++) {
res *= i;
}
cout << res << endl;
} | 1 | 34,130,565 |
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
vector<int> a(3);
for (int i = 0; i < 3; ++i) cin >> a[i];
sort(a.begin(), a.end());
if (a.back() == a[0]) cout << "Yes" << endl;
else cout << "No" << endl;
} | #include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <string.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back
#define INF (ll)1e18
ll gcd(ll a, ll b) {
if(b == 0) return a;
return gcd(b, a % b);
}
int main() {
ll A,B,C;
cin >>A>>B>>C;
if (A==B & B==C) printf("Yes\n");
else printf("No\n");
} | 1 | 95,924,863 |
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <utility>
using namespace std;
template <typename T>
void print_vec(const vector<T> &v) {
int n = v.size();
for (int i = 0; i < n; ++i) {
if (i > 0) cout << ' ';
cout << v[i];
}
cout << '\n';
}
int main() {
string s;
cin >> s;
int r = 0;
for (int i = 0; i < 3; ++i) {
if (s[i] == 'R') {
++r;
}
}
if (r == 2 && s[1] == 'S') {
r = 1;
}
cout << r << '\n';
return 0;
} | #include <bits/stdc++.h>
#define Tayeb ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
using namespace std;
int main()
{
Tayeb;
int count=0;
string S;
cin >> S;
for(int i=0; i<S.length(); i++)
{
if(S[i]=='R'&&S[i+1]=='R'&&S[i+2]=='R')
{
count=3;
break;
}
else if(S[i]=='R'&&S[i+1]=='R')
{
count=2;
break;
}
else if(S[i]=='R')
count=1;
}
cout << count << "\n";
return 0;
} | 1 | 54,890,577 |
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<long>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
using vc = vector<char>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,s,t) for(int i=s; i<t; i++)
#define RNG(i,s,t,u) for(int i=s; i<t; i+=u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()
const int MAX = 3010000;
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;
}
}
long long COM(int n, int k){
if (n < k) return 0;
if (n < 0 || k < 0) return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main(){
long x,y;
cin >> x >> y;
COMinit();
if((x + y) % 3 != 0) cout << 0 << endl;
else{
long m = (x + y)/3;
long a = x - m;
long b = y - m;
cout << COM(a+b,a) << 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 MAX = 1100000;
const int MOD = 1000000007;
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;
}
}
long long COM(int n, int k){
if (n < k) return 0;
if (n < 0 || k < 0) return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main()
{
int X, Y;
cin >> X >> Y;
if ((X + Y) % 3 != 0)
{
cout << 0 << endl;
return 0;
}
else if (abs(X - Y) > (X + Y) / 3)
{
cout << 0 << endl;
return 0;
}
int N = (X + Y) / 3;
COMinit();
cout << COM(N, min(Y, X) - N) << endl;
return 0;
} | 1 | 86,946,568 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rem(i, m, n) for (int i = m; i < (n); i++)
#define eps (1e-7)
#define inf (1e9)
#define pi (acos(-1))
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
string s;
cin >> s;
int n = s.size();
if (s.front() == 'A')
{
int countC = 0;
int index = 0;
rem(i, 2, n - 1)
{
if (s[i] == 'C')
{
index = i;
countC++;
}
}
if (countC == 1)
{
bool flag = true;
rem(i, 1, n)
{
if (i == index)
continue;
if (!islower(s[i]))
{
flag = false;
break;
}
}
if (flag)
{
cout << "AC"
<< "\n";
return 0;
}
}
}
cout << "WA"
<< "\n";
return 0;
} | #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>;
const int MOD = 1000000007;
int main() {
string S;
cin >> S;
vector<int> ignoreOffset;
string ans = "AC";
if (S.at(0) != 'A') ans = "WA";
if (S.at(0) == 'A') ignoreOffset.push_back(0);
int count = 0;
int offset = 0;
rep(i, S.size()) {
if (2 <= i && i <= S.size() - 2) {
if (S.at(i) == 'C') {
count++;
offset = i;
}
}
}
if (count != 1) ans = "WA";
if (count == 1) {
ignoreOffset.push_back(offset);
}
if (ans == "AC") {
rep(i, S.size()) {
if (S.at(i) < 'a' || 'z' < S.at(i)) {
bool isOk = false;
for (int offset : ignoreOffset) {
if (i == offset) isOk = true;
}
if (!isOk) ans = "WA";
}
}
}
cout << ans << endl;
return 0;
} | 1 | 60,783,542 |
#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>;
typedef vector<int> vi;
using Graph = vector<vector<int>>;
int main() {
int a, b;
cin >> a >> b;
int num_min = min(a, b);
int num_max = max(a, b);
rep (i, num_max) cout << num_min;
cout << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define DESYNC ios::sync_with_stdio(0); cin.tie(0);
#define deb(x) cerr << ">> " << #x << " : " << x << "\n";
#define print(a) for(auto x : a) cout << x << " "; cout << "\n";
const int inf = 1e18 + 5;
void solve()
{
char a, b;
cin >> a >> b;
string aa = "", bb = "";
for(int i = 0; i < (b - '0'); i++)
aa += a;
for(int i = 0; i < (a - '0'); i++)
bb += b;
if(aa > bb) cout << bb << endl;
else cout << aa << endl;
}
int32_t main()
{
DESYNC
int t = 1;
while(t--)
solve();
return 0;
} | 1 | 27,569,341 |
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stdio.h>
typedef long long ll;
const int INF = 1e9+1;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
using namespace std;
int main() {
int a[5];
int ans = 0;
int mini = INF;
for (int i = 0; i < 5; i++) {
cin >> a[i];
if (a[i] % 10 != 0) {
ans += ((a[i] / 10) + 1) * 10;
}
else ans += a[i];
if (a[i] % 10 < mini&&a[i]%10!=0)mini = a[i] % 10;
}
if (mini == INF)cout << ans << endl;
else
{
cout << ans - (10-mini) << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
int64_t MOD=1000000007;
int main() {
int ans=0;
vector<int> S;
for(int i=0;i<5;i++){
int a;
cin>>a;
if(a%10!=0){
S.push_back(a%10);
a+=10-(a%10);
}
ans+=a;
a%=10;
}
if(S.size()!=0){
sort(S.begin(),S.end());
cout<<ans-10+S.at(0);
}
else cout<<ans;
} | 1 | 43,637,204 |
#include <iostream>
#include <math.h>
#include <string>
using namespace std;
int main()
{
int a,b,c;
cin>>a>>b;
c=6-(a+b);
cout<<c;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
struct edge {int to; ll cost; };
int dx[] = {-1, 1, 0, 0};
int dy[] = { 0, 0, 1, -1};
int main(){
int a[3]={};
for(int i=0; i<2; i++){
int b;
cin >> b;
b--;
a[b]++;
}
for(int i=0; i<3; i++){
if(a[i]==0) cout << i+1 << endl;
}
return 0;
} | 1 | 86,125,883 |
#include <bits/stdc++.h>
#define ll long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(0);
#define rep(i, init, n) for (int i = init; i < n; i++)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
#define gcd __gcd
using namespace std;
const ll mod = 1e9 + 7;
const ll N = 1e5 + 10;
const ll MOD = 998244353;
vector<ll> edge[N];
vector<bool> visited(N, 0);
int dp[N][2];
ll POW(ll base, ll exponent){
ll result = 1;
while (exponent > 0)
{
if (exponent % 2 == 1)
result = (result * base) % mod;
exponent = exponent >> 1;
base = (base * base) % mod;
}
return result;
}
ll Inv(ll x){
return POW(x, mod - 2);
}
void DFS(ll src){
visited[src] = 1;
ll ans1 = 1, ans2 = 1;
for(auto i : edge[src]){
if(!visited[i]){
DFS(i);
ans1 = ((ans1 * dp[i][1]) % mod + (ans1 * dp[i][0]) % mod) % mod;
ans2 = (ans2 * dp[i][1]) % mod;
}
}
dp[src][1] = ans1, dp[src][0] = ans2;
}
int main(){
IOS
int n;
cin>>n;
rep(i, 0, n - 1){
int x, y;
cin>>x>>y;
edge[x].pb(y);
edge[y].pb(x);
}
DFS(1);
cout<<(dp[1][0] + dp[1][1]) % mod;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define int long long
int n;
int vis[100005]={0};
vector<int> grph[100005];
int mo=1000000007;
pair<int,int> dfs(int a,int p)
{
if(vis[a]==0)
{
vis[a]=1;
pair<int,int> ans;
ans.first=1;
ans.second=1;
for(auto &k:grph[a])
{
if(k!=p)
{
pair<int,int> temp=dfs(k,a);
ans.first=(ans.first * (temp.first + temp.second)%mo)%mo;
ans.second=(ans.second * temp.first)%mo;
}
}
return ans;
}
}
int32_t main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin>>n;
for(int i=0;i<(n-1);i++)
{
int x,y;
cin>>x>>y;
grph[x].push_back(y);
grph[y].push_back(x);
}
pair<int,int> ans=dfs(1,0);
cout<<(ans.first + ans.second)%mo;
} | 1 | 255,969 |
#include<iostream>
using namespace std;
int main() {
string S, T; cin >> S >> T;
bool canMatch = false;
for (int i = 0; i < S.size(); i++) {
if (S == T) {
canMatch = true;
}
S = S[S.size() - 1] + S.substr(0, S.size() - 1);
}
if (canMatch) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} | #include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
using namespace std;
typedef long long ll;
#define rep(n) for( int i = 0 ; i < n ; i++ )
#define REP(n) for( int i = 1 ; i <= n ; i++ )
#define repll(n) for( ll i = 0 ; i < n ; i++ )
#define REPll(n) for( ll i = 1 ; i <= n ; i++ )
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
string s,t;
cin >> s >> t;
bool c = 0;
for( int i = 0 ; i < s.size() ; i++ ) {
if( s == t ) c = 1;
s = s.back() + s.substr( 0 , s.size() - 1 );
}
if( c == 1 ) cout << "Yes";
else cout << "No";
} | 1 | 90,098,888 |
#include <bits/stdc++.h>
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define dump_1(x1) cerr << #x1 << ": " << x1 << endl
#define dump_2(x1, x2) \
cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define dump_3(x1, x2, x3) \
cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
<< x3 << endl
#define dump_4(x1, x2, x3, x4) \
cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
<< x3 << ", " #x4 << ": " << x4 << endl
#define dump_5(x1, x2, x3, x4, x5) \
cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
<< x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#define dump(...) \
CHOOSE((__VA_ARGS__, dump_5, dump_4, dump_3, dump_2, dump_1, ~))(__VA_ARGS__)
#define check(s) cerr << s << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;
const long long MOD = 998244353;
vector<int> dx = {0, 1, 0, -1};
vector<int> dy = {1, 0, -1, 0};
const ll LINF = 2e18;
const int INF = 1e9;
void solve(ll N, std::vector<ll> D) {
vector<ll> m(N, 0);
ll mx = 0;
rep(i, N) {
m.at(D.at(i))++;
chmax(mx, D.at(i));
}
if (m.at(0) != 1 || D.at(0) != 0) {
cout << 0 << endl;
return;
}
ll answer = 1;
FOR(i, 1, mx + 1) {
if (m.at(i) == 0) {
answer = 0;
break;
}
rep(j, m.at(i)) {
answer *= m.at(i - 1);
answer %= MOD;
}
}
cout << answer << endl;
}
int main() {
ll N;
scanf("%lld", &N);
std::vector<ll> D(N);
for (int i = 0; i < N; i++) {
scanf("%lld", &D[i]);
}
solve(N, std::move(D));
return 0;
} | #include <bits/stdc++.h>
#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;
int const BASE = 998244353;
ll f(int n, int m) {
ll ans = 1;
REP(i, m) { ans = ans * n % BASE; }
return ans;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
vector<int> D(N);
REP(i, N) { cin >> D[i]; }
if (D[0] != 0) {
cout << 0 << endl;
return 0;
}
sort(D.begin(), D.end());
ll ans = 1;
int parent_count = 1;
int children_count = 1;
REPI(i, 0, N - 1) {
if (D[i] == 0 && i > 0) {
cout << 0 << endl;
return 0;
}
if (D[i] != D[i + 1]) {
if (D[i + 1] != D[i] + 1) {
cout << 0 << endl;
return 0;
} else {
ans = ans * f(parent_count, children_count) % BASE;
parent_count = children_count;
}
children_count = 1;
} else {
++children_count;
}
}
ans = ans * f(parent_count, children_count) % BASE;
cout << ans % BASE << endl;
return 0;
} | 1 | 75,004,929 |
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
const int INF=1<<29;
const double EPS=1e-9;
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};
const int mod = 1e9 + 7;
ll f(vector<ll> &X) {
int N = X.size();
ll sum = 0;
for (int k = 1; k <= N; k++) {
sum += (k - 1) * X[k - 1] - (N - k) * X[k - 1];
sum %= mod;
}
return sum;
}
int main() {
int N, M;
cin >> N >> M;
vector<ll> X(N), Y(M);
for (int i = 0; i < N; i++) {
cin >> X[i];
}
for (int i = 0; i < M; i++) {
cin >> Y[i];
}
cout << (f(X) * f(Y)) % mod << endl;
return 0;
} | #include <iostream>
#include <algorithm>
using namespace std;
#define int long long
#define MOD 1000000007
signed main() {
int n, m;
cin >> n >> m;
int x[n + 1], y[m + 1];
for (int i = 1; i <= n; i++) {
cin >> x[i];
}
for (int i = 1; i <= m; i++) {
cin >> y[i];
}
int xsum = 0, ysum = 0;
for (int i = 1; i <= n; i++) {
xsum += (i - 1) * x[i] - (n - i) * x[i];
xsum %= MOD;
}
for (int i = 1; i <= m; i++) {
ysum += (i - 1) * y[i] - (m - i) * y[i];
ysum %= MOD;
}
cout << (xsum * ysum) % MOD << endl;
return 0;
} | 1 | 73,330,468 |
#include <iostream>
#include<bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
long long ncr(int n, int r) {
if(r > n - r) r = n - r;
long long ans = 1;
int i;
for(i = 1; i <= r; i++) {
ans *= n - r + i;
ans /= i;
}
return ans;
}
ll mod(ll a,ll b,ll m){
if(b==0)return 1;
if(b%2==0){
ll y = mod(a,b/2,m);
return (y*y)%m;
}
else{
return ((a%m)*mod(a,b-1,m))%m;
}
}
ll modinv(ll a,ll m){
return mod(a,m-2,m);
}
int main()
{
int n,m;
cin>>n>>m;
vector<ll>a(n);
priority_queue<ll>pq;
for(int i=0;i<n;i++){
cin>>a[i];
pq.push(a[i]);
}
for(int i=0;i<m;i++){
ll k=pq.top();
pq.pop();
k/=2;
pq.push(k);
}
ll sum=0;
while(!pq.empty()){
ll k=pq.top();
pq.pop();
sum+=k;
}
cout<<sum<<endl;
return 0;
} | #include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
#define ll long long
int main()
{
multiset<ll> st;
ll n, m;
cin >> n >> m;
for (ll i = 0; i < n; i++)
{
ll a;
cin >> a;
st.insert(a);
}
for (ll i = 0; i < m; i++)
{
auto it = --st.end();
st.erase(it);
st.insert(*it / 2);
}
ll ans = 0;
for (auto it = st.begin(); it != st.end(); it++) ans += *it;
cout << ans << "\n";
} | 1 | 5,819,368 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll a, b;
cin >> a >> b;
cout << (a%b == 0 ? 0 : 1) << "\n";
return 0;
} | #include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define ll long long
#define vi vector<ll>
#define all(x) x.begin() , x.end()
#define mod(x,m) ((x%m + m )%m)
using namespace std;
void OJ();
#define ld long double
void solve(){
int n ,k; cin >> n >> k;
cout << (bool)(n%k);
}
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int t = 1;
while ( t-- ){
solve();
}
return 0;
}
void OJ(){
#ifndef ONLINE_JUDGE
freopen( "C:\\Users\\ehab\\Desktop\\Code Forces\\CF\\in.txt" , "r" , stdin );
#endif
} | 1 | 69,655,594 |
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;
using ll = long long;
class Stream{
public:
Stream(){
}
void read(){
}
template<typename First, typename... Rest>
void read(First& first, Rest&... rest){
cin >> first;
read(rest...);
}
template<typename T>
void write_vec(vector<T>& v, char divider){
for(size_t i = 0; i < v.size(); i++){
cout << v[i] << divider;
}
}
};
int main(){
Stream io;
int A, B;
io.read(A, B);
cout << A * B - A - B + 1;
return 0;
} | #include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
int main() {
int A, B;
cin >> A >> B;
cout << (A - 1) * (B - 1) << endl;
} | 1 | 35,739,255 |
# include <algorithm>
# include <cassert>
# include <cctype>
# include <cstdio>
# include <cstdlib>
# include <cstring>
# include <cmath>
# include <iostream>
# include <map>
# include <queue>
# include <set>
# include <sstream>
# include <stack>
# include <string>
# include <vector>
# include <iomanip>
# define rep(i, n) for (int i = 0; i < (int)(n); i++)
# define irep(i, n) for (int i = int(n) - 1; i >= 0; i--)
# define FOR(i, m, n) for (int i = int(m); i < (int)(n); i++)
using namespace std;
typedef long long ll;
int num = 0;
void pretty_print(vector<int> &A) {
cout << A[0];
rep (i, A.size()-1) cout << ' ' << A[i+1];
cout << endl;
}
void sort(vector<int> &A) {
rep (i, A.size()) {
int mini = i;
for (int j = i; j < A.size(); j++) {
if (A[j] < A[mini]) {
mini = j;
}
}
if (i != mini) {
swap(A[i],A[mini]);
num++;
}
}
}
int main() {
int N;
cin >> N;
vector<int> A(N);
rep (i, N) cin >> A[i];
sort(A);
pretty_print(A);
cout << num << endl;
} | #include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <cstdlib>
using namespace std;
int main () {
int n,i,c,b=0,j,minj;
cin >> n;
int a[n];
for(i=0;i<n;i++){
cin >> a[i];
}
for(i=0;i<n;i++){
minj=i;
for(j=i;j<n;j++){
if (a[j]<a[minj]){
minj=j;
}
}
if(i==minj) b--;
c=a[i];
a[i]=a[minj];
a[minj]=c;
b++;
}
for(i=0;i<n;i++){
if(i!=n-1) cout << a[i] << " ";
else cout << a[i] << endl;
}
cout << b << endl;
} | 1 | 73,341,569 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;
int square(int a) { return a * a; }
int main() {
int n, d;
cin >> n >> d;
vector<vector<int>> x(n, vector<int>(d));
for (int i = 0; i < n; i++) {
for (int j = 0; j < d; j++) {
cin >> x.at(i).at(j);
}
}
int cnt = 0;
int dis = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
dis = 0;
for (int k = 0; k < d; k++) {
dis += square(x.at(i).at(k) - x.at(j).at(k));
}
for (int k = 0; k * k <= dis; k++) {
if (dis == k * k) {
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 < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const ll INF = 1LL << 60;
int main(){
vector<int> pow(200);
for(int i=1; i<=200; i++){
pow[i] = i*i;
}
int n, d;
cin >> n >> d;
vector<vector<int>> x(n,vector<int>(d,0));
for(int i=0; i<n; i++){
for(int j=0; j<d; j++){
cin >> x[i][j];
}
}
int ans=0;
for(int i=0; i<n-1; i++){
for(int j=i+1; j<n; j++){
int dif=0;
for(int k=0; k<d; k++){
dif += (x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
}
for(int l=1; l<200; l++){
if(pow[l]==dif) ans ++;
}
}
}
cout << ans << endl;
} | 1 | 24,025,800 |
#include <bits/stdc++.h>
#define long long long
#define oo 0x3f3f3f3f
using namespace std;
const double PI = acos(-1.0);
int main() {
#ifndef ONLINE_JUDGE
#endif
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(10), cout << fixed;
int n;
cin >> n;
vector<int> arr(n);
for (int &x : arr)
cin >> x;
int ans = oo;
for (int a = -100; a <= 100; ++a) {
int tmp = 0;
for (int &x : arr) {
tmp += abs(x - a) * abs(x - a);
}
ans = min(ans, tmp);
}
cout << ans << '\n';
return 0;
} | #include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
vector<int> a(n);
for(int i = 0; i < n; i++){
cin >> a[i];
}
int target = 0;
for(int i : a){
target += i;
}
if((10*target / n)% 10 >= 5) target = target/n + 1;
else target = target/n;
int cost = 0;
for(int i : a){
cost += pow(i - target, 2);
}
cout << cost << endl;
} | 1 | 45,586,433 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
signed main() {
string s;
cin >> s;
if(s[2] == s[3] && s[4] == s[5]) cout << "Yes" << '\n';
else cout << "No" << '\n';
} | #include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
const int INF = 1e18;
const double PI = acos(-1);
using namespace std;
struct INIT { INIT(){
cin.tie(0); ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
}}INIT;
signed main() {
string s;
cin >> s;
if(s[2] == s[3] && s[4] == s[5]) Yes;
else No;
return 0;
} | 1 | 44,458,230 |
#include <iostream>
#include <string>
using namespace std;
int main() {
string str;
cin >> str;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
string order;
int a, b;
cin >> order >> a >> b;
if (order == "print") {
for (int j = a; j <= b; j++) {
cout << str[j];
}
cout << endl;
} else if (order == "reverse") {
string s;
for (int j = a; j <= b; j++) {
s[j - a] = str[j];
}
int k = 0;
for (int j = b; j >= a; j--) {
str[j] = s[k];
k++;
}
} else if (order == "replace") {
string q;
cin >> q;
for (int j = a; j <= b; j++) {
str[j] = q[j - a];
}
}
}
return 0;
} | #include <iostream>
#include <string>
using namespace std;
int main(){
string str, d;
int a, b, n;
cin >> str >> n;
for(int i = 0; i < n; i++){
cin >> d >> a >> b;
string p;
if(d == "print"){
for(int j = a; j <= b; j++){
cout << str[j];
}
cout << endl;
}
else if(d == "reverse"){
p = str;
for(int j = 0; j <= b - a; j++){
str[a + j] = p[b - j];
}
}
else if(d == "replace"){
cin >> p;
for(int j = 0; j <= b - a; j++){
str[a + j] = p[j];
}
}
}
return 0;
} | 1 | 86,998,421 |