code1
stringlengths 54
12k
| code2
stringlengths 65
12k
| similar
int64 0
1
| __index_level_0__
int64 32
101M
|
---|---|---|---|
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
struct Eng {
Eng(const double th_, const int x_, const int y_) : th(th_), x(x_), y(y_) {}
double th;
int x, y;
};
int main() {
int N;
std::cin >> N;
std::vector<Eng> engs;
for (int i = 0; i < N; i++) {
int x, y;
std::cin >> x >> y;
engs.push_back(Eng(atan2(y, x), x, y));
}
std::sort(engs.begin(), engs.end(),
[](const Eng &a, const Eng &b) -> bool { return a.th < b.th; });
double max = 0;
for (int i = 0; i < N; i++) {
long xsum = engs[i].x, ysum = engs[i].y;
double pre = xsum * xsum + ysum * ysum;
if (pre > max) max = pre;
for (int j = 1; j < N; j++) {
int k = i + j < N ? i + j : i + j - N;
xsum += engs[k].x;
ysum += engs[k].y;
double tmp = xsum * xsum + ysum * ysum;
if (tmp > max) max = tmp;
pre = tmp;
}
}
printf("%0.12f\n", sqrt(max));
return 0;
} | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+10;
struct point
{
ll x;
ll y;
}p[N];
bool cmp(point a,point b)
{
return atan2(a.x,a.y)>atan2(b.x,b.y);
}
int main()
{
int n; cin>>n;
for(int i=1;i<=n;i++)
scanf("%lld%lld",&p[i].x,&p[i].y);
int nx[N];
for(int i=1;i<=n;i++)
nx[i]=i+1; nx[n]=1;
sort(p+1,p+1+n,cmp);
ll ans=0;
for(int i=1;i<=n;i++)
{
ll x=p[i].x;
ll y=p[i].y;
ans=max(ans,x*x+y*y);
for(int j=nx[i];j!=i;j=nx[j])
{
x=x+p[j].x;
y=y+p[j].y;
ans=max(ans,x*x+y*y);
}
}
printf("%.10lf\n",sqrt(ans));
return 0;
} | 1 | 69,814,036 |
#include <stdio.h>
int main()
{
int a[5], t;
scanf("%d %d %d %d %d", &a[0], &a[1], &a[2], &a[3], &a[4]);
for (int i = 0; i < 5; ++i){
for (int i = 0; i < 4; i++){
if(a[i] < a[i+1]){
t = a[i];
a[i] = a[i+1];
a[i+1] = t;
}
}
}
printf("%d %d %d %d %d\n", a[0], a[1], a[2], a[3], a[4]);
return 0;
} | #include<iostream>
using namespace std;
int main()
{
int a[5],j;
cin>>a[0]>>a[1]>>a[2]>>a[3]>>a[4];
for(int i=1;i<5;i++){
if(a[0]<a[i]){
j=a[0];
a[0]=a[i];
a[i]=j;
}
}
for(int k=2;k<5;k++){
if(a[1]<a[k]){
j=a[1];
a[1]=a[k];
a[k]=j;
}
}
for(int l=3;l<5;l++){
if(a[2]<a[l]){
j=a[2];
a[2]=a[l];
a[l]=j;
}
}
if(a[3]<a[4]){
j=a[3];
a[3]=a[4];
a[4]=j;
}
cout<<a[0]<<" "<<a[1]<<" "<<a[2]<<" "<<a[3]<<" "<<a[4]<<endl;
return 0;
} | 1 | 90,230,315 |
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
int height[10];
for (int i = 0; i < 10; i++) {
cin >> height[i];
}
sort(height, height+10, greater<int>());
for (int i = 0; i < 3; i++) {
cout << height[i] << endl;
}
return 0;
} | #include <iostream>
#include <array>
#include <functional>
#include <algorithm>
using namespace std;
int main(){
array<int,10> list;
for (int i = 0; i < 10; i++){
cin >> list[i];
}
sort(list.begin(), list.end(),greater<int>());
for (int i = 0; i < 3; i++){
cout << list[i] << endl;
}
return 0;
} | 1 | 22,972,966 |
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) (v).begin(),(v).end()
const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);
int main(void)
{
string s; cin>>s;
set<char> st;
rep(i,s.size()){
st.insert(s[i]);
}
if(st.size()==s.size()) cout<<"yes"<<endl;
else cout<<"no"<<endl;
return 0;
} | #include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;
#define INF 1e9
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
string s;
cin >> s;
vector<bool> a(26, false);
rep(i, s.size()) {
if (a.at(s.at(i) - 'a')) {
cout << "no" << endl;
return 0;
}
else a.at(s.at(i) - 'a') = true;
}
cout << "yes" << endl;
} | 1 | 21,623,077 |
#include <bits/stdc++.h>
#include <boost/integer/common_factor_rt.hpp>
using namespace std;
using ll=long long;
int main() {
int a,b,c;
cin >> a >> b >> c;
vector<int> x={a,b,c};
sort(x.begin(),x.end());
int sa=x[2]-x[1]+x[2]-x[0];
if(sa%2==0)
cout << sa/2 << endl;
else
cout << sa/2+2 << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;
#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=n-1;i>=0;--i)
#define FOR(i,s,n) for(int i=s;i<n;++i)
#define FORR(i,s,n) for(int i=n-1;i>=s;--i)
#define ALL(c) (c).begin(),(c).end()
#define CLEAR(v) memset(v,0,sizeof(v))
#define MP(a,b) make_pair((a),(b))
#define ABS(a) ((a)>0?(a):-(a))
#define F first
#define S second
int main(int argc, char **argv) {
ll a[3];
cin >> a[0] >> a[1] >> a[2];
sort(a, a+3);
cout << (a[2] - a[1] + (a[1] + 1 - a[0]) / 2 + (a[1] - a[0]) % 2) << endl;
return 0;
} | 1 | 94,911,357 |
#include <iostream>
#include <cstdio>
using namespace std;
typedef long long ll;
const int INF = 1e12;
ll f(ll a, ll b, ll m)
{
ll res = m - a;
if (res == b) --res;
return res;
}
bool check(ll m, ll a, ll b)
{
ll mx = 0;
if (m == a) return false;
if (m <= b)
{
mx = max((a + 1) * (m - a), (a - 1) * (m - a + 1));
for (ll x = (m + 1) / 2 - 2; x <= (m + 1) / 2 + 2; ++x)
{
mx = max(mx, (m - x) * (x + (x >= a)));
}
return mx < a * b;
}
else
{
for (ll x = (m + 1) / 2 - 2; x <= (m + 1) / 2 + 2; ++x)
{
if (x <= 0 || x >= m) continue;
mx = max(mx, (m + 1 - x - (x >= (m - b))) * (x + (x >= a)));
}
return mx < a * b;
}
}
int main()
{
int q;
cin >> q;
ll a, b, l, r, m;
ll ans;
while(q--)
{
cin >> a >> b;
if (a > b) swap(a, b);
l = a, r = INF;
ans = 1;
while(r - l > 1)
{
m = (r + l) / 2;
if (check(m, a, b))
{
ans = max(ans, m);
l = m;
}
else
r = m;
}
cout << ans - 1 << '\n';
}
} | #define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <deque>
#include <bitset>
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) v.erase(remove(v.begin(), v.end(), a), v.end())
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define REPE(i, n) for (int (i) = 0; (i) <= (n); (i)++)
using namespace std;
int Q;
int func(int a, int b)
{
int sum = 0;
sum += (a - 1) * 2;
int min = 0;
int max = (b - 1 - a) + 1;
while (true)
{
int x = ((max - min) / 2) + min;
if (max - min <= 1)
{
sum += b - 1 - a - x;
return sum;
}
int n = MAX(0, (((a + 1) + (b - 1 - x)) / 2) - (a + 1));
int k = (a + 1 + n) * (b - 1 - n - x);
if (k >= a * b)
{
min = x;
}
else
{
max = x;
}
}
}
signed main()
{
cin >> Q;
REP(i, Q)
{
int a_, b_;
cin >> a_ >> b_;
int a = MIN(a_, b_);
int b = MAX(a_, b_);
if (a == b)
{
cout << (2 * a - 2) << endl;
}
else if (a == b - 1)
{
cout << (2 * a - 2) << endl;
}
else
{
cout << func(a, b) << endl;
}
}
} | 1 | 100,168,149 |
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const int INF=1e9;
const ll llINF=1e18;
const int MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
int main() {
string s,t;
cin>>s>>t;
int ans=0;
rep(i,len(s)){
if(s[i]!=t[i])ans++;
}
cout<<ans<<endl;
} | #include <iostream>
#include <cstring>
using namespace std;
int main()
{
int c=0 ;
string S ,T ;
cin>> S >> T ;
for(int i=0 ; i< S.length() ; i++){
if(S[i]!=T[i])
c+=1 ;
}
cout<< c ;
return 0;
} | 1 | 91,653,018 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
int l;
cin >> l;
double ans = l*l*l / 27.0;
printf("%.10f\n",ans);
return 0;
} | #include <iostream>
#define N 100010
using namespace std;
int main(void){
double l;
cin >> l;
printf("%.12f",(double)l * l * l / 27);
} | 1 | 18,682,489 |
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
#define endl "\n"
#define all(V) V.begin(),V.end()
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
const int MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const int inf = 1 << 25;
constexpr long double pi = 3.141592653589793238462643383279;
int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
ll fact_mod(ll n, ll mod) {
ll f = 1; for (int i = 2; i <= n; i++) f = f * (i % mod) % mod;
return f;
}
ll gcd(ll a, ll b) {
if (b == 0) return a;
return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
return a * b / gcd(a, b);
}
ll keta(ll n) {
if (n == 0) return 1;
ll count = 0;
while (n != 0) {
n /= 10;
count++;
}
return count;
}
ll ketasum(ll n) {
ll sum = 0;
while (n != 0) {
sum += n % 10;
n /= 10;
}
return sum;
}
ll mch(ll n) {
if (n == 1) return 1;
else return n * mch(n - 1);
}
ll powmod(ll x, ll n, ll mod) {
ll res = 1;
while (n > 0) {
if (n & 1) res = (res * x) % mod;
x = (x * x) % mod;
n >>= 1;
}
return res;
}
ll inv_mod(ll a, ll mod) {
ll b = mod, u = 1, v = 0;
while (b) {
ll t = a / b;
a -= t * b; swap(a, b);
u -= t * v; swap(u, v);
}
u %= mod;
if (u < 0) u += mod;
return u;
}
bool is_prime(const unsigned n) {
switch (n) {
case 0:
case 1: return false;
case 2:
case 3: return true;
}
if (n % 2 == 0 || n % 3 == 0) return false;
for (unsigned i = 5; i * i <= n; i += 6) {
if (n % i == 0) return false;
if (n % (i + 2) == 0) return false;
}
return true;
}
struct UnionFind {
vector<int> par;
UnionFind(int N) : par(N) {
for (int i = 0; i < N; i++) par[i] = i;
}
int root(int x) {
if (par[x] == x) return x;
return par[x] = root(par[x]);
}
void unite(int x, int y) {
int rx = root(x);
int ry = root(y);
if (rx == ry) return;
par[rx] = ry;
}
bool same(int x, int y) {
int rx = root(x);
int ry = root(y);
return rx == ry;
}
};
int main(void) {
string s;
cin >> s;
reverse(s.begin(), s.end());
bool ok = true;
while (s.size()!=0) {
if (s.find("maerd") == 0) {
s = s.erase(0, 5);
}
else if (s.find("esare") == 0) {
s = s.erase(0, 5);
}
else if (s.find("remaerd") == 0) {
s = s.erase(0, 7);
}
else if (s.find("resare") == 0) {
s = s.erase(0, 6);
}
else {
ok = false;
break;
}
}
(ok ? puts("YES") : puts("NO"));
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
#define For(i, a, b) for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n) For(i, 0, n)
#define debug(x) cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main()
{
string s;
cin >> s;
REV(s);
vector<string> a={"dream","dreamer","erase","eraser"};
rep(i,4) REV(a[i]);
int count = 0;
while(count < s.size()){
bool check = false;
rep(i,4){
string now = s.substr(count, a[i].size());
if(s.substr(count,a[i].size()) == a[i]){
count += a[i].size();
check = true;
break;
}
}
if(check) continue;
if(!check){
cout << "NO" << endl;
return 0;
}
}
cout << "YES" << endl;
} | 1 | 22,453,148 |
#include<bits/stdc++.h>
using namespace std;
int main() {
string s, t, r;
int a, b;
cin>>s>>t;
map<string, int> cnt;
cin>>a>>b;
cnt[s] = a, cnt[t] = b;
cin>>r;
cnt[r]--;
cout<<cnt[s]<<' '<<cnt[t];
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
string s,t;
int a,b;
cin>>s>>t>>a>>b;
string u;
cin>>u;
if(s==u){
cout<<a-1<<' '<<b<<endl;
}
else if(t==u){
cout<<a<<' '<<b-1<<endl;
}
} | 1 | 15,070,402 |
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
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;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> pw2(62,1);vector<ll> pw_2(62,1);
int main(){
ll N,A,B; cin>>N>>A>>B;
if(N==1){
if(A!=B) cout<<0;
else cout<<1;
}
else{
if(A>B) cout<<0;
else cout<<(B-A)*(N-2)+1<<endl;
}
} | #include <bits/stdc++.h>
#include <math.h>
#define rep(i,n) for (int i=0;i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
int main() {
ll a,b,c;
cin >> a >> b >> c;
if(b > c || (a==1&&c!=b)){
cout << 0 << endl;
} else {
cout << (c*(a-1)+b) - (b*(a-1)+c) + 1 << endl;
}
} | 1 | 45,641,897 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
int main(){
ll h,w;
cin >> h >> w;
ll ans=0;
if(h==1 || w==1){
cout << 1;
return 0;
}
if(w%2==0){
rep(i,h){
ans+=w/2;
}
}else{
rep(i,h){
if(i%2==0){
ans+=(w+1)/2;
}else{
ans+=w/2;
}
}
}
cout << ans;
} | #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
int main() {
long long h, w, t;
cin >> h >> w;
t = h*w;
if (h == 1 || w == 1)
{
cout << 1 << endl;
}else if (t%2 == 0)
{
cout << t/2 << endl;
}else
{
cout << t/2+1 << endl;
}
return 0;
} | 1 | 5,606,656 |
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
using ll=long long;
int main()
{
ll n,m;
cin>>n>>m;
vector<ll> a(n),memo(n+10);
rep(i,m){
int b;
cin>>b;
a[b]=1;
}
memo[0]=1;
if(a[1]==0){
memo[1]=1;
}
for(ll i=2;i<=n+3;i++){
if(a[i]==1) continue;
memo[i]=memo[i-1]+memo[i-2];
memo[i]%=1000000007;
}
cout<<memo[n];
} | #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(){
int n, m;
cin >> n >> m;
vector<int> broken(n+1);
rep(i,m){
int a;
cin >> a;
broken[a]=1;
}
vector<int> dp(n+2);
const int mod=1000000007;
dp[n]=1;
for(int i=n-1; i>=0; i--){
if(broken[i]){
dp[i]=0;
continue;
}
dp[i]=(dp[i+1]+dp[i+2]) %mod;
}
cout << dp[0] << endl;
return 0;
} | 1 | 24,816,634 |
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <algorithm>
using namespace std;
#define mod 1e9+7
#define ll long long int
#define epsilon 1e-7
ll min(ll x, ll y){
if(x<y)return x;
return y;
}
char s[8001];
int xx[4001];
int yy[4001];
int dx[16001][4001];
int dy[16001][4001];
int main(void){
int x, y;
scanf("%s", &s);
scanf("%d %d", &x, &y);
int fo = 1;
int xxx = 0;
int yyy = 0;
int me = 0;
for(int i = 0;s[i]!='\0';i++){
if(s[i]=='F')me++;
else{
if(fo == 1){
xx[xxx] = me;
me = 0;
fo = 2;
xxx++;
}else{
yy[yyy] = me;
me = 0;
fo = 1;
yyy++;
}
}
}
if(me!=0){
if(fo == 1){
xx[xxx] = me;
me = 0;
fo = 2;
xxx++;
}else{
yy[yyy] = me;
me = 0;
fo = 1;
yyy++;
}
}
int xmax = 0;
int ymax = 0;
for(int i = 0;i < xxx;i++){
xmax += xx[i];
}
for(int i = 0;i < yyy;i++){
ymax += yy[i];
}
for(int i = 0;i < xxx + 1;i++){
for(int j = 0;j < 2*xmax + 1;j++){
dx[j][i] = 0;
}
}
for(int i = 0;i < yyy + 1;i++){
for(int j = 0;j < 2*ymax + 1;j++){
dy[j][i] = 0;
}
}
dx[xmax + xx[0]][1] = 1;
dy[ymax][0] = 1;
for(int i = 0;i < xxx;i++){
for(int j = 0;j < 2*xmax + 1;j++){
if(dx[j][i]){
dx[j - xx[i]][i+1] = 1;
dx[j + xx[i]][i+1] = 1;
}
}
}
for(int i = 0;i < yyy;i++){
for(int j = 0;j < 2*ymax + 1;j++){
if(dy[j][i]){
dy[j - yy[i]][i+1] = 1;
dy[j + yy[i]][i+1] = 1;
}
}
}
if(x + xmax < 0 || y + ymax < 0)printf("No\n");
else if(dx[x+ xmax][xxx] && dy[y+ ymax][yyy])printf("Yes\n");
else printf("No\n");
return 0;
} | #include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
#define mem(a,n) memset(a,n,sizeof(a,n,sizeof(a))
#define rep(i,a,n) for(int i=a;i<n;i++)
#define pb push_back
#define fi first
#define se second
typedef long long ll;
const int mod=1e9+7;
const double eps=1e-6;
const int N=1e4+5;
const int w=20003;
char s[N];
bool flag[2][2][40009];
int main()
{
int _x=0,x,y,p,q,sum,now=1;
scanf("%s%d%d",s+1,&x,&y);
int len=strlen(s+1);
x+=w,y+=w;
while(now<=len&&s[now]=='F') now++,_x++;
flag[0][0][w+_x]=flag[1][0][w]=1;
while(now<=len)
{
now++;
sum=0;
p^=1;
q^=p;
while(now<=len&&s[now]=='F') sum++,now++;
for(int i=w-len;i<=w+len;i++)
flag[p][q][i]=flag[p][q^1][i+sum]|flag[p][q^1][i-sum];
}
if(p==1&&flag[0][q^1][x]&&flag[1][q][y]||p==0&&flag[0][q][x]&&flag[1][q][y])
puts("Yes");
else puts("No");
return 0;
} | 1 | 71,488,675 |
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long 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; }
int main(void){
int n;
cin >> n;
int b[n+1];
REP(i,n-1) cin >> b[i+1];
b[0]=b[1];b[n]=b[n-1];
int ans=0;
REP(i,n)ans+=min(b[i],b[i+1]);
cout << ans;
return 0;
} | #include <bits/stdc++.h>
#include<vector>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(j, m) for (int j = 0; j <= (int)(m); j++)
int main(){
int n;
cin >> n;
vector<int>a;
vector<int>b(n-1);
rep(i,n-1){
int tmp;
cin >> tmp;
b[i] = tmp;
}
int ans = 0;
rep(i,n){
if(i==0){
ans += b[0];
continue;
}
if(i==n-1){
ans += b[i-1];
continue;
}
ans += min(b[i],b[i-1]);
}
cout << ans << endl;
} | 1 | 87,275,401 |
#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<ll, ll>;
const ll INF = ll(1e18) + 5;
int main() {
ll N, K;
cin >> N >> K;
vector<P> td(N);
rep(i, N) {
cin >> td[i].second >> td[i].first;
}
sort(td.rbegin(), td.rend());
vector<ll> first, second;
unordered_map<ll, ll> mp;
rep(i, N) {
if (mp.find(td[i].second) == mp.end()) {
mp[td[i].second]++;
first.push_back(td[i].first);
} else {
second.push_back(td[i].first);
}
}
vector<ll> fSum(K + 1, 0), sSum(K + 1, 0);
rep(i, K) {
fSum[i + 1] = fSum[i];
if (i < first.size()) {
fSum[i + 1] += first[i];
}
sSum[i + 1] = sSum[i];
if (i < second.size()) {
sSum[i + 1] += second[i];
}
}
ll ans = 0;
ll e = min(K, (ll)first.size());
for (ll i = 1ll; i <= e; i++) {
ans = max(ans, i * i + fSum[i] + sSum[K - i]);
}
cout << ans << endl;
return 0;
} | #define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; typedef pair<ll, ll> P;
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; }
template<typename A,size_t N,typename T>void Fill(A(&array)[N],const T &val){fill((T*)array, (T*)(array+N), val);}
const int inf = INT_MAX / 2; const ll INF = LLONG_MAX / 2;
int main(){
int n,k; scanf("%d%d",&n,&k);
vector<P> td(n);
rep(i,0,n)scanf("%lld%lld",&td[i].second,&td[i].first);
sort(ALL(td),greater<P>());
ll sub=0,kind=0; bool used[100010]={};
priority_queue<ll,vector<ll>,greater<ll>> pq;
rep(i,0,k){
sub+=td[i].first;
if(used[td[i].second])pq.push(td[i].first);
else used[td[i].second]=1,kind++;
}
ll ans=sub+kind*kind;
rep(i,k,n){
if(!used[td[i].second]){
if(pq.empty())break;
used[td[i].second]=1; kind++;
sub+=td[i].first-pq.top(); pq.pop();
chmax(ans,sub+1LL*kind*kind);
}
}
printf("%lld\n",ans);
return 0;
} | 1 | 14,730,944 |
#include <iostream>
using namespace std;
int appear[100];
int main(void){
int input, max = 0, count = 0;
while(cin >> input){
appear[input-1]++;
count++;
}
for(int i = 0 ; i < count; i++){
if(appear[i] > max){
max = appear[i];
}
}
for(int i = 0; i < count; i++){
if(appear[i] == max) cout << i + 1 << endl;
}
return 0;
} | #include<iostream>
using namespace std;
int main(){
int ans[101] = {0};
int n,max = 0;
while(cin >>n){
ans[n]++;
if(max<ans[n]){max = ans[n];}
}
for(int i=0; i<101; i++){
if(ans[i] == max){cout <<i<<endl;}
}
return 0;
} | 1 | 17,329,713 |
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string s,t;
cin>>s>>t;
vector<ll>ser(26,-1),ter(26,-1);
for(int i=0;i<s.size();i++){
ll x=s[i]-'a';
ll y=t[i]-'a';
if(ser[x]!=-1&&ser[x]!=y){
cout<<"No\n";return 0;
}
if(ter[y]!=-1&&ter[y]!=x){
cout<<"No\n";return 0;
}
ser[x]=y;
ter[y]=x;
}
cout<<"Yes\n";
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;
#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=n-1;i>=0;--i)
#define FOR(i,s,n) for(int i=s;i<n;++i)
#define FORR(i,s,n) for(int i=n-1;i>=s;--i)
#define ALL(c) (c).begin(),(c).end()
#define CLEAR(v) memset(v,0,sizeof(v))
#define MP(a,b) make_pair((a),(b))
#define ABS(a) ((a)>0?(a):-(a))
#define F first
#define S second
string s, t;
int p[256], q[256];
int main(int argc, char **argv) {
cin >> s >> t;
memset(p, -1, sizeof(p));
memset(q, -1, sizeof(q));
REP(i, s.length()) {
if (p[s[i]] != q[t[i]]) {
cout << "No" << endl;
return 0;
}
p[s[i]] = i;
q[t[i]] = i;
}
cout << "Yes" << endl;
return 0;
} | 1 | 42,319,979 |
#include<bits/stdc++.h>
using namespace std;
#define INFS (1LL<<28)
#define INF (1LL<<60)
#define DEKAI 1000000007
#define lp(i,n) for(int i=0;i<n;i++)
#define int long long
#define double long double
#define all(n) n.begin(),n.end()
typedef complex<double> P;
vector<pair<double,pair<double,double>>> ans;
double max(double a,double b){
if(a>b)return a;
else return b;
}
double rot(double x,double y){
double angle=acos(x/(sqrt(x*x+y*y)));
angle=angle*180.0/acos(-1);
if(y<0)angle=360.0-angle;
return angle;
}
signed main(){
cout << fixed << setprecision(15);
int n;
cin>>n;
lp(i,n){
int x,y;
cin>>x>>y;
ans.push_back({arg(P(x,y)),{x,y}});
}
sort(ans.begin(),ans.end());
lp(i,n){
ans.push_back(ans[i]);
}
double r=0;
lp(i,n){
double sum[2]={0,0};
for(int j=i;j<n+i;j++){
sum[0]+=ans[j].second.first;
sum[1]+=ans[j].second.second;
r=max(r,(double)sqrt(sum[0]*sum[0]+sum[1]*sum[1]));
}
}
cout<<r<<endl;
return 0;
} | #include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;
int n, a[N];
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rand(int l, int r){
uniform_int_distribution<int> uid(l, r);
return uid(rng);
}
int dist(int x, int y){
return (x) * (x) + (y) * (y);
}
int32_t main(){_
cin>>n;
vector<P> v;
for (int i = 0; i < n; ++i)
{
int x, y;
cin >> x >> y;
v.push_back({x, y});
}
int ans = 0;
for (int i = 0; i < N; ++i)
{
shuffle(v.begin(), v.end(), rng);
int X = 0, Y = 0;
for (int j = 0; j < sz(v); ++j)
{
if(dist(X+v[j].F, Y+v[j].S) > dist(X, Y)){
X += v[j].F;
Y += v[j].S;
}
}
smax(ans, dist(X, Y));
}
cout << fixed << setprecision(15);
cout<<sqrtl(ans);
return 0;
} | 1 | 30,280,109 |
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
#define D10 fixed<<setprecision(10)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
const int dx[] = { -1, 0, 0, 1 }, dy[] = { 0, -1, 1, 0 };
bool valid(int x, int y, int h, int w) { return (x >= 0 && y >= 0 && x < h&&y < w); }
int place(int x, int y, int w) { return w*x + y; }
struct UnionFind
{
vector<int> par;
UnionFind(int n) :par(n, -1) {}
int find(int x) { return par[x] < 0 ? x : par[x] = find(par[x]); }
void unite(int x, int y)
{
x = find(x); y = find(y);
if (x == y) return;
if (par[y] < par[x]) swap(x, y);
if (par[x] == par[y]) par[x]--;
par[y] = x;
if (find(x) != find(y)) par[find(y)] = x;
}
int count()
{
int cnt = 0;
REP(i, par.size()) if (par[i] < 0) cnt++;
return cnt;
}
bool same(int x, int y)
{
return find(x) == find(y);
}
};
int main()
{
cin.sync_with_stdio(false);
int h, w;
while (cin >> w >> h, h)
{
vs fld(h);
REP(i, h) cin >> fld[i];
int st;
REP(i, h)REP(j, w)
{
if (fld[i][j] == '@')
{
st = place(i, j, w);
fld[i][j] = '.';
}
}
UnionFind uf(h*w);
REP(i, h)REP(j, w)
{
if (fld[i][j] == '#') continue;
REP(k, 4)
{
int nx = i + dx[k], ny = j + dy[k];
if (!valid(nx, ny, h, w) || fld[nx][ny] == '#') continue;
uf.unite(place(i, j, w), place(nx, ny, w));
}
}
int cnt = 0;
REP(i, h*w)
{
if (uf.same(i, st)) cnt++;
}
cout << cnt << endl;
}
return 0;
} | #include<bits/stdc++.h>
using namespace std;
struct UnionFind {
vector< int > data;
UnionFind(int sz) {
data.assign(sz, -1);
}
int Size(int x) {
return(-data[Find(x)]);
}
int Find(int k) {
return(data[k] < 0 ? k : data[k] = Find(data[k]));
}
void Unite(int a, int b) {
a = Find(a), b = Find(b);
if(a == b) return;
data[a] += data[b];
data[b] = a;
}
};
int main() {
int W, H;
while(cin >> W >> H, W) {
string mas[50];
for(int i = 0; i < H; i++) cin >> mas[i];
UnionFind uf(W * H);
for(int i = 0; i < H; i++) {
for(int j = 1; j < W; j++) {
if(mas[i][j - 1] != '#' && mas[i][j] != '#') uf.Unite(i * W + j - 1, i * W + j);
}
}
for(int i = 1; i < H; i++) {
for(int j = 0; j < W; j++) {
if(mas[i - 1][j] != '#' && mas[i][j] != '#') uf.Unite(i * W - W + j, i * W + j);
}
}
for(int i = 0; i < H; i++) {
for(int j = 0; j < W; j++) {
if(mas[i][j] == '@') cout << uf.Size(i * W + j) << endl;
}
}
}
} | 1 | 28,630,514 |
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n, k;
string s;
cin >> n >> k >> s;
vector<int> x;
int count = 1;
for (int i = 1; i < n; i++) {
if (s.at(i - 1) == s.at(i)) count++;
else {
x.emplace_back(count);
count = 1;
}
}
x.emplace_back(count);
int ans = 0;
if (s.at(0) == '0') {
if ((x.size() + 1) / 2 <= k) {
cout << n << '\n';
return 0;
}
int ans = 0;
int left = 0, count = 0, sum = 0;
for (int right = 0; right < x.size(); right++) {
sum += x.at(right);
if (right % 2 == 0) count++;
if (count > k) {
if (left == 0) {
sum -= x.at(left);
left++;
count--;
}
else {
sum -= x.at(left) + x.at(left + 1);
left += 2;
count--;
}
}
ans = max(ans, sum);
}
cout << ans << '\n';
}
else {
if (x.size() / 2 <= k) {
cout << n << '\n';
return 0;
}
int ans = 0;
int left = 0, count = 0, sum = 0;
for (int right = 0; right < x.size(); right++) {
sum += x.at(right);
if (right % 2 == 1) count++;
if (count > k) {
sum -= x.at(left) + x.at(left + 1);
left += 2;
count--;
}
ans = max(ans, sum);
}
cout << ans << '\n';
}
} | #include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
void func(long long N, long long K, std::string S){
vector<lli> d;
if(S[0]=='0')d.push_back(0);
lli now=0;
lli nex=1;
while(now<N && nex<N){
if(S[now]!=S[nex]){
d.push_back(nex-now);
now=nex;
}
nex++;
}
d.push_back(nex-now);
if(S[N-1]=='0')d.push_back(0);
lli ans = 0;
lli sum = 0;
REP(i,0,min((int)(2*K+1),(int)d.size())){
sum+=d[i];
}
chmax(ans,sum);
for(lli i=2*K+1;i<d.size();i+=2){
LOG2(ans,sum);
sum-=d[i-2*K-1];
sum-=d[i-2*K];
sum+=d[i];
sum+=d[i+1];
chmax(ans,sum);
}
cout<<ans<<endl;
}
int main(){
long long N;
scanf("%lld",&N);
long long K;
scanf("%lld",&K);
std::string S;
std::cin >> S;
func(N, K, S);
return 0;
} | 1 | 7,226,512 |
#include <iostream>
using namespace std;
#define N_MAX 100
int main()
{
int n, i, j, u, k, v;
int Adj[N_MAX][N_MAX] = {};
cin >> n;
for (i = 0; i < n; i++) {
cin >> u >> k;
while (k-- > 0) {
cin >> v;
Adj[u-1][v-1] = 1;
}
}
for (i = 0; i < n; i++) {
for (j = 0; j < n ; j++) {
if (j == n - 1)
cout << Adj[i][j] << endl;
else
cout << Adj[i][j] << ' ';
}
}
return 0;
} | #include <iostream>
using namespace std;
int main(){
int graph[100][100] = {};
int n;
cin >> n;
for(int i = 0;i < n;i++){
int now,m;
cin >> now >> m;
for(int j = 0;j < m;j++) {
int t;
cin >> t;
graph[now - 1][t - 1] = 1;
}
}
for(int i = 0;i < n;i++){
cout << graph[i][0];
for(int j = 1;j < n;j++){
cout << " " << graph[i][j];
}
cout << endl;
}
return 0;
} | 1 | 26,493,457 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define FOR(i,n) for(ll i=0;i<n;i++)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define rev(p) reverse(p.begin(),p.end());
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define popcount(x) __builtin_popcountll(x)
#define sz(x) ((ll)x.size())
const ll M=1000000007;
const ll MM=998244353;
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
ll newmod(ll a,ll b)
{
return ((a%b)+b)%b;
}
ll powM(ll a,ll b,ll m )
{
if(m<=1)return 0;
a%=m;
ll ans=1LL;
while(b)
{
if(b&1)ans=ans*a%m;
a=a*a%m;
b>>=1;
}
return ans;
}
ll poww(ll a,ll b)
{
ll ans=1;
while(b)
{
if(b&1)ans=ans*a;
a=a*a;
b>>=1;
}
return ans;
}
template<typename T,typename F>
void chmax( T &a,F b){
if(b>a)a=b;
}
template<typename T,typename F>
void chmin( T &a,F b){
if(b<a)a=b;
}
const ll N=5e5+5;
set<pll>s;
ll solve(ll p,ll q,vpll& a,ll i){
ll c=0;
for(int j=0;j<sz(a);j++){
ll x=a[j].ff,y=a[j].ss;
if(s.count({x+p,y+q}))c++;
}
return c;
}
int main()
{
IOS;
ll n;cin>>n;
ll k;cin>>k;
if(k==1)cout<<0;
else cout<<(n-k);
return 0;
} | #include<bits/stdc++.h>
#define pi acos(-1.0)
#define pb push_back
#define LL long long
#define LIM 50000
#define dbg(x) cout<<#x<<" = "<<x<<'\n';
using namespace std;
int _I(){int x; scanf("%d",&x); return x;}
LL _L(){LL x; scanf("%lld",&x); return x;}
LL gcd(LL a, LL b){ while(b) b ^= a ^= b ^= a %= b; return a; }
LL lcm(LL x,LL y){x/=gcd(x,y); return x*y;}
int kdx[8]={-2,-2,-1,-1,1,1,2,2};
int kdy[8]={-1,1,-2,2,-2,2,-1,1};
bool prime[LIM+7];
long long _pow(long long a, long long b){
if(b == 0) return 1;
long long ret = 1;
ret *= _pow(a, b/2);
ret = ret*ret;
if(b&1){
ret *= a;
}
return ret;
}
bool inrng(LL x, LL y, LL c){
return (x <= c && c <= y);
}
bool inRng(int a, int b, int x, int y){
return ( inrng(a,b,x) || inrng(a,b,y) || inrng(x,y,a) || inrng(x,y,b) );
}
vector<int> v;
map<int, int> mp;
void sieve(){
int i,j; prime[1]=1; v.pb(2);
for(i=4;i<=LIM;i+=2) prime[i]=1;
for(i=3;i<=LIM;i+=2) if(!prime[i]){ v.pb(i); for(j=i+i+i;j<=LIM;j+=i+i) prime[j]=1;}
}
int cases;
void fun(){
int n,k,mn,mx;
n = _I();
k = _I();
if(k == 1) puts("0");
else {
printf("%d\n",n-k);
}
}
int main()
{
fun();
return 0;
} | 1 | 25,395,045 |
#include<bits/stdc++.h>
using namespace std;
string s;
int n;
bool zz[100000];
int main(){
int n;
cin>>n>>s;
for(int i=0;i<2;i++)
for(int j=0;j<2;j++)
{
zz[0]=i;
zz[1]=j;
for(int k=1;k<n-1;k++)
{
zz[k+1]=zz[k-1]^zz[k]^(s[k]=='x');
}
if((s[n-1]=='x')==(zz[n-2]^zz[n-1]^zz[0])&&(s[0]=='x')==(zz[n-1]^zz[0]^zz[1]))
{
for(int k=0;k<n;k++)
cout<<(zz[k]?'W':'S');
return 0;
}
}
cout<<-1;
return 0;
} | #include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <climits>
using namespace std;
#define MOD1097 1000000007
#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mpair make_pair
#define pm(first, second) pb(mpair(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second
#define all(X) (X).begin(), (X).end()
#define reall(X) (X).rbegin(), (X).rend()
#define divcel(a, b) (((a) + ((b) - 1)) / (b))
int main(){
int N;
string S;
cin >> N >> S;
vector<int> V(N);
bool able = false, flag1, flag2;
V[0] = 1;
V[1] = 1;
for(int i = 1; i < N - 1; i++){
if(V[i] == 1){
if(S[i] == 'o'){
V[i + 1] = V[i - 1];
}
else{
V[i + 1] = -V[i - 1];
}
}
else{
if(S[i] == 'o'){
V[i + 1] = -V[i - 1];
}
else{
V[i + 1] = V[i - 1];
}
}
}
flag1 = false;
flag2 = false;
if(V[0] == 1){
if(S[0] == 'o'){
if(V[1] == V[N-1])flag1 = true;
}
else{
if(V[1] != V[N-1])flag1 = true;
}
}
else{
if(S[0] == 'o'){
if(V[1] != V[N-1])flag1 = true;
}
else{
if(V[1] == V[N-1])flag1 = true;
}
}
if(V[N-1] == 1){
if(S[N-1] == 'o'){
if(V[N-2] == V[0])flag2 = true;
}
else{
if(V[N-2] != V[0])flag2 = true;
}
}
else{
if(S[N-1] == 'o'){
if(V[N-2] != V[0])flag2 = true;
}
else{
if(V[N-2] == V[0])flag2 = true;
}
}
if(flag1 && flag2){
for(int i = 0; i < N; i++){
if(V[i] == 1)cout << "S";
else cout << "W";
}
cout << endl;
return 0;
}
V[0] = 1;
V[1] = -1;
for(int i = 1; i < N - 1; i++){
if(V[i] == 1){
if(S[i] == 'o'){
V[i + 1] = V[i - 1];
}
else{
V[i + 1] = -V[i - 1];
}
}
else{
if(S[i] == 'o'){
V[i + 1] = -V[i - 1];
}
else{
V[i + 1] = V[i - 1];
}
}
}
flag1 = false;
flag2 = false;
if(V[0] == 1){
if(S[0] == 'o'){
if(V[1] == V[N-1])flag1 = true;
}
else{
if(V[1] != V[N-1])flag1 = true;
}
}
else{
if(S[0] == 'o'){
if(V[1] != V[N-1])flag1 = true;
}
else{
if(V[1] == V[N-1])flag1 = true;
}
}
if(V[N-1] == 1){
if(S[N-1] == 'o'){
if(V[N-2] == V[0])flag2 = true;
}
else{
if(V[N-2] != V[0])flag2 = true;
}
}
else{
if(S[N-1] == 'o'){
if(V[N-2] != V[0])flag2 = true;
}
else{
if(V[N-2] == V[0])flag2 = true;
}
}
if(flag1 && flag2){
for(int i = 0; i < N; i++){
if(V[i] == 1)cout << "S";
else cout << "W";
}
cout << endl;
return 0;
}
V[0] = -1;
V[1] = 1;
for(int i = 1; i < N - 1; i++){
if(V[i] == 1){
if(S[i] == 'o'){
V[i + 1] = V[i - 1];
}
else{
V[i + 1] = -V[i - 1];
}
}
else{
if(S[i] == 'o'){
V[i + 1] = -V[i - 1];
}
else{
V[i + 1] = V[i - 1];
}
}
}
flag1 = false;
flag2 = false;
if(V[0] == 1){
if(S[0] == 'o'){
if(V[1] == V[N-1])flag1 = true;
}
else{
if(V[1] != V[N-1])flag1 = true;
}
}
else{
if(S[0] == 'o'){
if(V[1] != V[N-1])flag1 = true;
}
else{
if(V[1] == V[N-1])flag1 = true;
}
}
if(V[N-1] == 1){
if(S[N-1] == 'o'){
if(V[N-2] == V[0])flag2 = true;
}
else{
if(V[N-2] != V[0])flag2 = true;
}
}
else{
if(S[N-1] == 'o'){
if(V[N-2] != V[0])flag2 = true;
}
else{
if(V[N-2] == V[0])flag2 = true;
}
}
if(flag1 && flag2){
for(int i = 0; i < N; i++){
if(V[i] == 1)cout << "S";
else cout << "W";
}
cout << endl;
return 0;
}
V[0] = -1;
V[1] = -1;
for(int i = 1; i < N - 1; i++){
if(V[i] == 1){
if(S[i] == 'o'){
V[i + 1] = V[i - 1];
}
else{
V[i + 1] = -V[i - 1];
}
}
else{
if(S[i] == 'o'){
V[i + 1] = -V[i - 1];
}
else{
V[i + 1] = V[i - 1];
}
}
}
flag1 = false;
flag2 = false;
if(V[0] == 1){
if(S[0] == 'o'){
if(V[1] == V[N-1])flag1 = true;
}
else{
if(V[1] != V[N-1])flag1 = true;
}
}
else{
if(S[0] == 'o'){
if(V[1] != V[N-1])flag1 = true;
}
else{
if(V[1] == V[N-1])flag1 = true;
}
}
if(V[N-1] == 1){
if(S[N-1] == 'o'){
if(V[N-2] == V[0])flag2 = true;
}
else{
if(V[N-2] != V[0])flag2 = true;
}
}
else{
if(S[N-1] == 'o'){
if(V[N-2] != V[0])flag2 = true;
}
else{
if(V[N-2] == V[0])flag2 = true;
}
}
if(flag1 && flag2){
for(int i = 0; i < N; i++){
if(V[i] == 1)cout << "S";
else cout << "W";
}
cout << endl;
return 0;
}
cout << "-1" << endl;
return 0;
} | 1 | 15,503,043 |
#pragma region header
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define int long long
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr int inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
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;
}
ll fact(int i) {
if (i == 0) return 1;
return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {
if(b == 0) return a;
return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
return a / gcd(a, b) * b ;
}
int keta(ll n) {
if(n == 0) return 1;
int count = 0;
while(n != 0) {
n /= 10;
count++;
}
return count;
}
ll ketasum(ll n) {
ll sum = 0;
while(n != 0) {
sum += n % 10;
n /= 10;
}
return sum;
}
#pragma endregion
signed main() {
int n;cin >> n;
vi v(n);
rep(i, n) {
cin >> v[i];
v[i]-=i+1;
}
sort(all(v));
int k = v[n/2],l=v[(n+1)/2];
int a = 0,b = 0;
rep(i, n) a+=abs(k-v[i]),b+=abs(l-v[i]);
cout << min(a,b) << endl;
return 0;
} | #include "bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
#define ALL(v) v.begin(), v.end()
#define N 100007
#define INF 10000007
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll fceil(ll a, ll b) { return (a % b == 0 ? a / b : a / b + 1); }
int main()
{
ll n, ans = 0;
cin >> n;
vector<ll> a(n, 0LL), c(n, 0LL);
for (ll i = 0LL; i < n; i++)
{
cin >> a[i];
c[i] = a[i] - i - 1LL;
}
sort(c.begin(), c.end());
for(ll i = 0; i < n; i++)
ans += abs(c[i]-c[n/2LL]);
cout << ans << endl;
return 0;
} | 1 | 46,583,651 |
#include<bits/stdc++.h>
using namespace std;
int main(void) {
string S1, S2;
cin >> S1 >> S2;
if(S1.length()+1 != S2.length()) {
cout << "No" << endl;
} else if(S2.substr(0, S1.length()) == S1) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main()
{
string s,t;
cin >> s >> t;
int flag = 0;
if(s.size() + 1 != t.size()){
flag = 1;
}
int n = s.size();
for(int i = 0; i < n; i++){
if(s[i] != t[i]){
flag = 1;
break;
}
}
if(flag == 0){
cout << "Yes" << endl;
}else{
cout << "No" << endl;
}
} | 1 | 51,268,879 |
#include <bits/stdc++.h>
using namespace std;
void solve(long long A, long long B, long long K){
if(A > K){
A = A - K;
}else{
if(B > K - A){
B = B - (K - A);
}else{
B = 0;
}
A = 0;
}
cout << A << " " << B << endl;
return;
}
int main(){
long long A;
scanf("%lld",&A);
long long B;
scanf("%lld",&B);
long long K;
scanf("%lld",&K);
solve(A, B, K);
return 0;
} | #include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
int main()
{
ll a, b, k;
cin >> a >> b >> k;
cout << max(0ll, a - k) << ' ' << max(0ll, min(b, a + b - k)) << endl;
return 0;
} | 1 | 1,661,249 |
#include <iostream>
#include <string>
using namespace std;
int main()
{
string Card;
int n = 0, t = 0;
cin >> Card;
while (Card != "-") {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> t;
Card = Card.substr(t, Card.size() - t) + Card.substr(0, t);
}
cout << Card << endl;
cin >> Card;
}
return 0;
} | #include <stdio.h>
#include <string.h>
#include <ctype.h>
int main(){
char W[201],Wbuf[201];
int h;
int n,i,j,k;
while(1)
{
scanf("%s\n%d",W,&n);
if(W[0]=='-') break;
for(i=0;i<n;i++)
{
scanf("%d",&h);
for(j=h;W[j]!='\0';j++) Wbuf[j-h]=W[j];
for(k=0;k<h;k++) Wbuf[j-h+k]=W[k];
for(j=0;W[j]!='\0';j++) W[j]=Wbuf[j];
}
printf("%s\n",W);
}
return 0;
} | 1 | 92,448,911 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void out(deque<int> v) {
int sz = v.size();
for (int i = 0; i < sz; i++) {
cout << v.front() << " \n"[i == sz - 1];
v.pop_front();
}
}
int main() {
ll n,a,b;
cin >> n >> a >> b;
if (a * b < n) {
cout << -1 << endl;
return 0;
}
if (a + b - 1 > n) {
cout << -1 << endl;
return 0;
}
int pos = n;
deque<int> dq;
for (int i = 0; i < a; i++) {
dq.push_front(pos--);
}
while (--b) {
int tmp = a;
vector<int> v;
while (tmp-- > 0 && pos >= b) {
v.push_back(pos--);
}
for (int i = 0; i < v.size(); i++) {
dq.push_back(v[v.size() - i - 1]);
}
}
out(dq);
return 0;
} | #include<bits/stdc++.h>
using namespace std;
int n,a,b;
int main() {
cin>>n>>a>>b;
if (a+b-1>n||1ll*a*b<n) return cout<<-1,0;
int d=n-a;
for (int i=n-a+1;i<=n;++i) cout<<i<<' ';
for (int i=2;i<=b;++i) {
int t=min(d-(b-i),a);
for (int j=d-t+1;j<=d;++j) cout<<j<<' ';
d-=t;
}
} | 1 | 45,919,353 |
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(int argc, char *argv[])
{
int h, w;
cin >> h >> w;
vector<vector<string>> s(h, vector<string>(w));
rep(i, h) {
rep(j, w) {
cin >> s.at(i).at(j);
}
}
rep(i, h) {
rep(j, w) {
if (s.at(i).at(j) == "snuke") {
cout << (char)('A' + j) << i+1 << endl;
}
}
}
return 0;
} | #include <cstdio>
#include <iostream>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <map>
using namespace std;
#define maxn 30
char a[maxn][maxn][5];
int main()
{
int h, w;
cin >> h >> w;
for (int i = 1; i <= h; i++)
{
for (int j = 1; j <= w; j++)
{
scanf("%s",a[i][j]);
if (strcmp("snuke", a[i][j]) == 0)
{
printf("%c%d\n", j - 1 + 'A', i); break;
}
}
}
return 0;
} | 1 | 16,917,490 |
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
int N, K;
cin >> N >> K;
set<int> st;
rep(i, K) {
int D;
cin >> D;
rep(i, D) {
int a;
cin >> a;
st.insert(a);
}
}
int ans = N - sz(st);
cout << ans << '\n';
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
scanf("%d %d", &n, &k);
set<int> snk;
for(int i = 0; i < k; i++) {
int d;
cin >> d;
for(int j = 0; j < d; j++) {
int a;
cin >> a;
snk.insert(a);
}
}
cout << (n - snk.size());
} | 1 | 3,355,338 |
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
int main(){
int n;
cin >> n;
vector<vector<int> > adj(110);
int D[110];
for(int i = 0; i < n; i++){
int u, k;
cin >> u >> k;
D[u] = -1;
for(int j = 0; j < k; j++){
int v;
cin >> v;
adj[u].push_back(v);
}
}
queue<int> Q;
Q.push(1);
D[1] = 0;
while(!Q.empty()){
int cur = Q.front();
Q.pop();
for(int i = 0; i < adj[cur].size(); i++){
int dst = adj[cur][i];
if(D[dst] == -1){
D[dst] = D[cur]+1;
Q.push(dst);
}
}
}
for (int i = 1; i < n+1; i++){
cout << i << " " << D[i] << endl;
}
} | #include <iostream>
#include <vector>
#include <queue>
using namespace std;
const int nIMPOS = -1;
struct StDist
{
int m_nDist;
int m_nDone;
StDist(int nDist) : m_nDist(nDist), m_nDone(0)
{ }
};
void fnInput(vector<vector<int>>& rvvnAdjcy, vector<StDist>& rvoDist)
{
int nxSiz;
cin >> nxSiz;
rvvnAdjcy.resize(nxSiz + 1, vector<int>(nxSiz + 1, 0));
for (int i = 0; i < nxSiz; ++i)
{
int nx, nySiz;
cin >> nx >> nySiz;
for (int j = 0; j < nySiz; ++j)
{
int ny;
cin >> ny;
rvvnAdjcy[nx][ny] = 1;
}
}
StDist oDist(nIMPOS);
rvoDist.resize(nxSiz + 1, oDist);
}
void fnBreadthFirstSearch(const vector<vector<int>>& cnrvvnAdjcy,
queue<int>& rqnBFSrch, vector<StDist>& rvoDist)
{
while (rqnBFSrch.size())
{
int nx = rqnBFSrch.front(); rqnBFSrch.pop();
if (rvoDist[nx].m_nDist == nIMPOS) continue;
for (int ny = 1; ny < cnrvvnAdjcy[nx].size(); ++ny)
{
if (cnrvvnAdjcy[nx][ny] == 1 &&
rvoDist[nx].m_nDone == 0)
{
int nDist = rvoDist[nx].m_nDist + 1;
if (rvoDist[ny].m_nDist == nIMPOS)
rvoDist[ny].m_nDist = nDist;
else
rvoDist[ny].m_nDist = min(rvoDist[ny].m_nDist, nDist);
rqnBFSrch.push(ny);
}
}
rvoDist[nx].m_nDone = 1;
}
}
void fnResult(const vector<StDist>& cnrvoDist)
{
for (int i = 1; i < cnrvoDist.size(); ++i)
cout << i << " " << cnrvoDist[i].m_nDist << endl;
}
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
vector<vector<int>> vvnAdjcy;
queue<int> qnBFSrch;
vector<StDist> voDist;
fnInput(vvnAdjcy, voDist);
voDist[1].m_nDist = 0;
qnBFSrch.push(1);
fnBreadthFirstSearch(vvnAdjcy, qnBFSrch, voDist);
fnResult(voDist);
return 0;
} | 1 | 53,588,360 |
#include <cstdio>
#include <memory.h>
#include <algorithm>
using namespace std;
typedef long long ll;
ll bulb[300010];
ll bkt[300010];
ll operate(int n) {
memset(bkt, 0, sizeof bkt);
for (int i = 0; i < n; ++i) {
ll op1 = i - bulb[i];
ll op2 = i + bulb[i];
if (op1 < 0) op1 = 0;
++bkt[op1];
if (op2 >= n) op2 = n - 1;
--bkt[op2 + 1];
}
bulb[0] = bkt[0];
for (int i = 1; i < n; ++i)
bulb[i] = bulb[i - 1] + bkt[i];
return *min_element(bulb, bulb + n);
}
int main() {
int n, k, i;
scanf("%d%d", &n, &k);
for (i = 0; i < n; ++i)
scanf("%lld", bulb + i);
for (i = 0; i < k; ++i)
if (operate(n) >= n)
break;
for (int i = 0; i < n; ++i)
printf("%lld%c", bulb[i], " \n"[i == n - 1]);
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
using ll = long long;
using P = pair<int, int>;
const int mod = 998244353;
int main(int, char**)
{
int n, k;
cin >> n >> k;
vector<int> a(n);
rep(i,n) cin >> a[i];
rep(_,k) {
vector<int> d(n, 0);
int endcntl = 0, endcntr = 0;
rep(i,n) {
int l = max(0, i-a[i]);
int r = min(n-1, i+a[i]);
d[l]++;
if (r+1 < n) d[r+1]--;
if (l==0) endcntl++;
if (r+1 >= n) endcntr++;
}
rep(i,n) {
if (!i) a[i] = d[i];
else a[i] = a[i-1] + d[i];
}
if (endcntl == n && endcntr == n) break;
}
rep(i,n) {
if (i) cout << " ";
cout << a[i];
}
cout << endl;
return 0;
} | 1 | 32,231,636 |
#include<bits/stdc++.h>
using namespace std;
int main(){
string s;
cin >> s;
if(s<="2019/04/30") cout << "Heisei" << endl;
else cout << "TBD" << endl;
return 0;
} | #include <bits/stdc++.h>
#define int long long int
#define gif(a,b) (a/b +(a%b?1:0))
#define pi 3.14159265358
#define watch(x) cout<<(#x)<<" is "<<(x)<<"\n";
#define float long double
using namespace std;
int32_t main()
{
cin.tie(NULL);
std::ios::sync_with_stdio(false);
int y , m , d;
char a , b;
string s;
cin >> s;
stringstream ss(s);
ss >> y >> a >> m >> b >> d;
int flag = 0;
if(y > 2019)
flag = 1;
else if(y == 2019 && m > 04)
flag = 1;
if(flag == 1)
cout << "TBD";
else
cout <<"Heisei";
return 0;
} | 1 | 95,504,524 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> T(N);
for(int i=0;i<N;i++) cin >> T.at(i);
int Ans=0;
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
Ans += T.at(i)*T.at(j);
}
}
for(int i=0;i<N;i++){
Ans -= T.at(i) * T.at(i);
}
Ans /= 2;
cout << Ans << endl;
} | #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define vlli vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vplli vector< pair< ll,ll> >
#define plli pair< ll,ll >
#define vps vector< pair< string, string> >
#define vpi vector< pair< int, int> >
#define all(x) x.begin(), x.end()
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn(i,a,n) for(ll i=a;i<n;i++)
#define scan(arr,a,n) for(ll i=(a);i<(n);i++)cin>>(arr)[i];
#define print(arr,a,n) for(ll i=(a);i<(n);i++)cout<<(arr)[i]<<" ";
ll add(ll x, ll y) {ll res = x + y; return (res >= mod ? res - mod : res);}
ll mul(ll x, ll y) {ll res = x * y; return (res >= mod ? res % mod : res);}
ll sub(ll x, ll y) {ll res = x - y; return (res < 0 ? res + mod : res);}
ll power(ll x, ll y) {ll res = 1; x %= mod; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;}
ll mod_inv(ll x) {return power(x, mod - 2);}
int main(){
fast;
ll n;
cin>>n;
ll a[n], ans = 0;
scan(a, 0, n);
forn(i, 0, n-1){
forn(j, i+1, n){
ans = ans+(a[i]*a[j]);
}
}
cout<<ans<<endl;
} | 1 | 24,945,950 |
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std ;
using ll = long long ;
using vll = vector<ll> ;
ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
int main(){
ll n ; cin >> n ;
ll x,y ; cin >> x >> y ;
if(n==1){
ll a ; cin >> a ;
cout << sa(y,a) << endl ;
}else{
vll a(n) ;
for(auto &i:a) cin >> i ;
cout << max(sa(a.at(n-1),y),sa(a.at(n-2),a.at(n-1))) << endl ;
}
} | #include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define P pair<ll,ll>
#define INF 1000000000000000000
using namespace std;
int main(void){
ll n, z, w;
cin >> n >> z >> w;
vector<ll> a(n);
for (int i = 0; i < n; i++){
cin >> a[i];
}
if (n == 1)
cout << abs(a[n-1]- w) << endl;
else
cout << max(abs(a[n-1]-w), abs(a[n-2]- a[n-1])) << endl;
return 0;
} | 1 | 17,369,956 |
#include<bits/stdc++.h>
typedef long long ll;
#define pb push_back
#define mod 1000000007ll
const ll maxn = 9e18;
using namespace std;
const ll maxsize = 100000009;
vector<bool> mark(100005, 0);
int wa[100005];
void solve() {
int n, k;
cin >> n >> k;
map<string,ll> m;
m["AC"] = 0;
int ac_cnt = 0, wa_cnt = 0;
m["WA"] = 0;
int t = 0;
for(int i = 0; i < k; ++i) {
int x;
string s;
cin >> x >> s;
if(mark[x]) continue;
if(s == "AC") {
mark[x] = 1;
ac_cnt++;
wa_cnt += wa[x];
}
else wa[x]++;
}
cout << ac_cnt <<" "<< wa_cnt << endl;
cout << endl;
}
int main() {
ios_base :: sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cout.precision(35);
solve();
return 0;
} | #include <iostream>
#include <vector>
#include <algorithm>
#include <bitset>
#include <math.h>
#include <iomanip>
#include <map>
#include <queue>
#include <tuple>
#include <math.h>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
int N,M;
cin >> N >> M;
vector<int> cnt(N,0),flag(N,0);
for(int i=0; i<M; i++){
int p;string s;
cin >> p >> s;
p--;
if(s=="WA" && flag[p]==0){
cnt[p]++;
}else{
flag[p]=1;
}
}
int wa=0,ac=0;
for(int i=0; i<N; i++){
if(flag[i]==1){
ac++;
wa+=cnt[i];
}
}
cout << ac << ' ' << wa << endl;
return 0;
} | 1 | 6,044,470 |
#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;
const ll mod = 1000000007;
int main(){
ll n;
cin >> n;
ll a[n+1], b[n];
rep(i, n+1) cin >> a[i];
rep(i, n) cin >> b[i];
ll ans = 0;
rep(i, n){
ans += min(a[i], b[i]);
b[i] = max((ll)0, b[i] - a[i]);
ans += min(a[i+1], b[i]);
a[i+1] = max((ll)0, a[i+1] - b[i]);
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<long long>a(n + 1);
vector<long long>b(n);
for(int i = 0;i < n + 1;i++){
cin >> a[i];
}
for(int i = 0;i < n;i++){
cin >> b[i];
}
long long count = 0;
for(int i = 0;i < n;i++){
count += min(a[i],b[i]);
b[i] -= min(a[i],b[i]);
count += min(a[i + 1],b[i]);
a[i + 1] -= min(a[i + 1],b[i]);
}
cout << count << endl;
} | 1 | 56,750,036 |
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long int
#define pb push_back
#define fi first
#define se second
#define ld long double
#define vi vector<vector<ll> >
using namespace std;
const int MOD=1000000007;
const int MOD2=15000007;
const ll MAX=9187201950435737471;
const int N=100005;
const int INF=1e17;
const long double PI=acos(-1);
void solve(int T){
ll a,b;
cin>>a>>b;
ll x=__gcd(a,b);
cout<<(a*b)/x<<"\n";
}
int main() {
fastio
int T=1;
for(int i=1;i<=T;i++){
solve(i);
}
return 0;
} | #include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
ll t,n,m,i,a,b;
cin>>a>>b;
cout<<(a*b)/__gcd(a,b);
} | 1 | 46,755,788 |
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#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 ll long long int
#define ld long double
#define vi vector<ll>
#define vii vector <pair<ll,ll> >
#define sedes set <ll, greater <ll> >
#define seasc set <ll>
#define pb push_back
#define mkp make_pair
#define ff first
#define ss second
#define MOD 1000000007
#define prec(n) fixed<<setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define umap unordered_map<ll, ll>
#define map map<ll, ll>
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define mems(a, i) memset(a, i, sizeof(a))
#define endl '\n'
#define all(v) v.begin(),v.end()
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define deba(a) cout << #a << " " << a << endl;
int main()
{
fast;
#ifndef ONLINE_JUDGE
freopen("/home/kushagra/Desktop/Kushagra/input.txt", "r", stdin);
freopen("/home/kushagra/Desktop/Kushagra/output.txt", "w", stdout);
#endif
int t = 1;
while (t--)
{
ll n, m;
cin >> n >> m;
vii ab;
rep(i, 0, n)
{
ll x, y;
cin >> x >> y;
ab.pb({x, y});
}
sort(all(ab));
ll ans = 0;
for (auto it : ab)
{
ll x = min(m, it.ss);
ans += x * it.ff;
m -= x;
if (m == 0)
break;
}
cout << ans << endl;
}
return 0;
} | #include <bits/stdc++.h>
#include <iostream>
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--)
using namespace std;
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
int main()
{
ll n,m,a,b;
cin>>n>>m;
vector<pair<ll, ll>> nums(n);
rep(i,0, n-1){
cin>>a>>b;
nums[i] = make_pair(a, b);
}
sort(nums.begin(), nums.end());
ll count = 0, cost = 0,i = 0;
while(count < m)
{
if(count + nums[i].second > m)
{
cost += (m - count) * nums[i].first;
count = m;
}
else
{
cost += nums[i].first * nums[i].second;
count += nums[i].second;
}
i++;
}
cout<<cost;
} | 1 | 24,689,629 |
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
vector<pair<ll, int>> factorize(ll n) {
vector<pair<ll, int>> res;
for(ll i = 2; i*i <= n; i++) {
if (n%i != 0) continue;
res.emplace_back(i,0);
while (n%i == 0) {
n/=i;
res.back().second++;
}
}
if (n!=1) res.emplace_back(n,1);
return res;
}
int main()
{
int n;
cin >> n;
map<ll, int> mp;
for (int i=1; i<=n; i++) {
auto fact =factorize(i);
for (auto p : fact) {
mp[p.first] += p.second;
}
}
int over3 = 0;
int over5 = 0;
int over15 = 0;
int over25 = 0;
int over75 = 0;
for(auto v : mp) {
int x = v.second+1;
if (x>=3) over3++;
if (x>=5) over5++;
if (x>=15) over15++;
if (x>=25) over25++;
if (x>=75) over75++;
}
ll ans = 0;
ans += over75;
ans += over25 * max(0, (over3-1));
ans += over15 * max(0, (over5-1));
ans += over5*(over5-1)/2 * max(0, (over3-2));
cout << ans << endl;
return 0;
} | #include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(f,c,...) (([&](decltype((c)) cccc) { return (f)(begin(cccc), end(cccc), ## __VA_ARGS__); })(c))
int main() {
int N; cin >> N;
map<int, int> count;
rep(i, N) {
int n = i+1;
for (int j = 2; j * j <= n; ++j) {
while (n % j == 0) {
n /= j;
++count[j];
}
}
if (n > 1)
++count[n];
}
vector<int> v;
for (const auto& e : count) v.push_back(e.second);
all(reverse, v);
int two = v.end() - all(lower_bound, v, 3-1);
int four = v.end() - all(lower_bound, v, 5-1);
int ans = four * (four-1) * (two - 2) / 2;
int fst = v.end() - all(lower_bound, v, 3-1);
int snd = v.end() - all(lower_bound, v, 25-1);
ans += (fst-1) * snd;
fst = v.end() - all(lower_bound, v, 5-1);
snd = v.end() - all(lower_bound, v, 15-1);
ans += (fst-1) * snd;
fst = v.end() - all(lower_bound, v, 75-1);
ans += fst;
cout << ans << endl;
return 0;
} | 1 | 90,591,683 |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF 9223372036854775807
bool f=true;
string s,hoge="YAKI";
signed main() {
cin >> s;
if (s.size() < 4) {cout << "No" << endl;return 0;}
rep(i,4) if (s[i] != hoge[i]) f = false;
if (f) cout << "Yes" << endl;
else cout << "No" << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define LONGLONGMAX 9223372036854775807
#define LONGLONGMIN -9223372036854775807
#define INTMAX 32767
#define INTMIN -32767
#define ROUNDUP(divisor,dividend) (divisor + (dividend - 1)) / dividend
string s;
int main(){
cin >> s;
cout << (s[0]=='Y'&&s[1]=='A'&&s[2]=='K'&&s[3]=='I' ? "Yes":"No") << endl;
} | 1 | 2,373,850 |
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
void outStr(vector<string>& ary) {
string aryStr = "";
for (int i = 0; i < ary.size(); i++)
{
aryStr = aryStr + ary[i];
if (i < ary.size() - 1) aryStr = aryStr + " ";
}
cout << aryStr << endl;
return;
}
bool isSmaller(string s1, string s2) {
int v1 = stoi(s1.substr(1));
int v2 = stoi(s2.substr(1));
bool rtn = false;
if (v1 < v2) rtn = true;
return rtn;
}
void bubbleSort(vector<string>& ary) {
bool flag = 1;
int swTime = 0;
while (flag)
{
flag = 0;
for (int j = ary.size() - 1; j >= 1; j--)
{
if (isSmaller(ary[j], ary[j - 1])) {
string sw = ary[j - 1];
ary[j - 1] = ary[j];
ary[j] = sw;
flag = 1;
}
}
}
return;
}
void selectionSort(vector<string>& ary) {
for (int i = 0; i < ary.size(); i++)
{
int minj = i;
bool needSw = false;
for (int j = i; j < ary.size(); j++) {
if (isSmaller(ary[j], ary[minj])) {
minj = j;
needSw = true;
}
}
if (needSw) {
string sw = ary[i];
ary[i] = ary[minj];
ary[minj] = sw;
}
}
return;
}
int main() {
int N;
cin >> N;
vector<string> bb(N);
vector<string> ss;
for (int i = 0; i < N; i++) {
cin >> bb[i];
ss.push_back(bb[i]);
}
bubbleSort(bb);
outStr(bb);
string stb = "Stable";
cout << stb << endl;
selectionSort(ss);
outStr(ss);
bool isSame = true;
for (int i = 0; i < bb.size(); i++)
{
if (bb[i] != ss[i]) isSame = false;
}
if (!isSame) stb = "Not stable";
cout << stb << endl;
return 0;
} | #include <iostream>
#include <string>
#include <vector>
using namespace std;
struct Card
{
string val;
size_t order;
};
bool is_smaller(Card a, Card b)
{
if (stoi(a.val.substr(1,1)) < stoi(b.val.substr(1,1)))
return true;
else
return false;
}
void bubble_sort(vector<Card> *cards, size_t n)
{
for (size_t i=0; i<n; i++) {
for (size_t j=n-1; j>i; j--) {
if (is_smaller((*cards)[j], (*cards)[j-1]))
swap((*cards)[j], (*cards)[j-1]);
}
}
}
void selection_sort(vector<Card> *cards, size_t n)
{
for (size_t i=0; i<n; i++) {
size_t minj = i;
for (size_t j=i; j<n; j++) {
if (is_smaller((*cards)[j], (*cards)[minj]))
minj = j;
}
swap((*cards)[i], (*cards)[minj]);
}
}
bool is_stable(vector<Card> cards, size_t n)
{
for (size_t i=0; i<n-1; i++) {
if (cards[i].val[1] == cards[i+1].val[1]) {
if (cards[i].order > cards[i+1].order)
return false;
}
}
return true;
}
void print_cards(vector<Card> cards, size_t n)
{
for (size_t i=0; i<n-1; i++)
cout << cards[i].val << " ";
cout << cards[n-1].val << endl;
}
int main(void)
{
size_t n, order = 0;
vector<Card> cards1, cards2;
string buf;
cin >> n;
for (size_t i=0; i<n; i++) {
cin >> buf;
Card card;
card.val = buf;
card.order = order++;
cards1.push_back(card);
cards2.push_back(card);
}
bubble_sort(&cards1, n);
print_cards(cards1, n);
cout << (is_stable(cards1, n) ? "Stable" : "Not stable") << endl;
selection_sort(&cards2, n);
print_cards(cards2, n);
cout << (is_stable(cards2, n) ? "Stable" : "Not stable") << endl;
return 0;
} | 1 | 74,873,700 |
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <algorithm>
#define rep(i, n) for(i = 0; i < (n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define MOD 1000000007
#define PI 3.14159265358979323846
#define INF 1 << 30
using namespace std;
typedef long long ll;
typedef pair<int, int> pp;
int main(void) {
ll num, i, ans = 0;
cin >> num;
for (i = 1; i < num; i++) {
ans += num / i;
if (num % i == 0)
ans--;
}
cout << ans << "\n";
return 0;
} | #include <iostream>
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
#define int long long
using namespace std;
vector<long long> enum_divisors(long long N) {
vector<long long> res;
for (long long i = 1; i * i <= N; ++i) {
if (N % i == 0) {
res.push_back(i);
if (N/i != i) res.push_back(N/i);
}
}
sort(res.begin(), res.end());
return res;
}
signed main() {
int N;
cin>>N;
int ans=0;
for(int i=1;i<N;i++){
ans+=(N-1)/i;
}
cout<<ans<<endl;
} | 1 | 14,790,736 |
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD 1000000007
const ll INF=1e18;
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<endl;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }
int main(int argc, char const *argv[]) {
int h, n;
cin >> h >> n;
ll sum = 0;
rep(i,n){
ll a;
cin >> a;
sum += a;
}
if (sum >= h) puts("Yes");
else
puts("No");
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using i64 = int64_t;
using ll = long long;
int main() {
int H,N;
cin >> H >> N;
int A;
int sum = 0;
rep(i,N){
cin >> A;
sum += A;
}
if(H <= sum){
cout << "Yes" << endl;
}
else{
cout << "No" << endl;
}
return 0;
} | 1 | 56,770,787 |
#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>;
const int mod = 1000000007;
int main() {
ll N, K;
cin >> N >> K;
ll ans = 0;
for (ll i = K; i <= N + 1; ++i) {
ans = (ans + (i * ((N + 1 - i + 1) + N + 1) / 2 - i * (i + 1) / 2 + 1) %
mod) %
mod;
}
cout << ans << endl;
} | #include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
return x == 0 ? 1 : log10(x) + 1;
}
ll sum(ll a, ll b) {
return (b + a) * (b - a + 1) / 2;
}
signed main() {
ll N, K;
cin >> N >> K;
ll ans = 0;
rep2(i, K, N + 2) {
ll min = sum(0, i - 1);
ll max = sum(N - i + 1, N);
ans += (max - min + 1) % 1000000007;
ans = ans % 1000000007;
}
COUT(ans);
return 0;
} | 1 | 70,816,965 |
#include<bits/stdc++.h>
using namespace std;
int n,a,b;
bool test(int num)
{
int total=0;
while (num)
{
total = total +num%10;
num = num/10;
}
if(total >=a&&total<=b)
{
return true;
}
else
{
return false;
}
}
int main()
{
cin>>n>>a>>b;
int answer=0;
for (size_t i = 1; i <= n; i++)
{
if(test(i))
{
answer = answer + i;
}
}
cout<<answer<<endl;
} | #include <bits/stdc++.h>
using namespace std;
int digitSum(int n)
{
if(n < 10)
{
return n;
}
return digitSum(n / 10) + n % 10;
}
int main()
{
int n, a, b, tmp, res = 0;
cin >> n >> a >> b;
for(int i = 1; i <= n; ++i)
{
tmp = digitSum(i);
if(tmp >= a && tmp <= b)
{
res += i;
}
}
cout << res << "\n";
return 0;
} | 1 | 58,143,846 |
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
int n, k;
cin >> n >> k;
vector<vector<int>> hen(n);
if(k > (n - 1) * (n - 2) / 2) {
cout << -1 << endl;
return 0;
}
int m = n - 1;
for(int i = 1; i < n; i++) {
hen[0].push_back(i);
}
int t = (n - 1) * (n - 2) / 2;
for(int i = 1; i < n; i++) {
for(int j = i + 1; j < n; j++) {
if(t == k)goto LAST;
hen[i].push_back(j);
m++;
t--;
}
}
LAST:;
cout << m << endl;
for(int i = 0; i < n; i++) {
for(auto j : hen[i]) {
cout << i + 1 << " " << j + 1 << endl;
}
}
} | #include <bits/stdc++.h>
#define reg register
#define ll long long
#define ull unsigned long long
#define db double
#define pi pair<int, int>
#define pl pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vpi vector<pi>
#define vpl vector<pl>
#define pb push_back
#define er erase
#define SZ(x) (int) x.size()
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define mkp make_pair
#define dmin(x, y) ((x) < (y) ? (x) : (y))
#define dmax(x, y) ((x) > (y) ? (x) : (y))
#define checkmax(x, y) ((x) < (y) ? ((x) = (y)) : (x))
#define checkmin(x, y) ((x) > (y) ? ((x) = (y)) : (x))
#define ms(data_name) memset(data_name, 0, sizeof(data_name))
#define msn(data_name, num) memset(data_name, num, sizeof(data_name))
#define For(i, j) for(reg int (i) = 1; (i) <= (j); ++(i))
#define For0(i, j) for(reg int (i) = 0; (i) < (j); ++(i))
#define Forx(i, j, k) for(reg int (i) = (j); (i) <= (k); ++(i))
#define Forstep(i , j, k, st) for(reg int (i) = (j); (i) <= (k); (i) += (st))
#define fOR(i, j) for(reg int (i) = (j); (i) >= 1; (i)--)
#define fOR0(i, j) for(reg int (i) = (j) - 1; (i) >= 0; (i)--)
#define fORx(i, j, k) for(reg int (i) = (k); (i) >= (j); (i)--)
#define tour(i, u) for(reg int (i) = head[(u)]; (i) != -1; (i) = nxt[(i)])
using namespace std;
char ch, B[1 << 20], *S = B, *T = B;
#define getc() (S == T && (T = (S = B) + fread(B, 1, 1 << 20, stdin), S == T) ? 0 : *S++)
#define isd(c) (c >= '0' && c <= '9')
int rdint() {
int aa, bb;
while(ch = getc(), !isd(ch) && ch != '-');
ch == '-' ? aa = bb = 0 : (aa = ch - '0', bb = 1);
while(ch = getc(), isd(ch))
aa = aa * 10 + ch - '0';
return bb ? aa : -aa;
}
ll rdll() {
ll aa, bb;
while(ch = getc(), !isd(ch) && ch != '-');
ch == '-' ? aa = bb = 0 : (aa = ch - '0', bb = 1);
while(ch = getc(), isd(ch))
aa = aa * 10 + ch - '0';
return bb ? aa : -aa;
}
const int MAXN = 110;
int n, k;
inline void work() {
n = rdint();
k = rdint();
int m = n * (n - 1) / 2 - k;
if(m < n - 1) {
m = -1;
}
printf("%d\n", m);
if(m != -1) {
int tmp = n - 1;
while(m > 0) {
Forx(i, n - tmp + 1, min(n, n - tmp + m)) {
printf("%d %d\n", n - tmp, i);
}
m -= tmp--;
}
}
}
int main() {
work();
return 0;
} | 1 | 88,934,753 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, c) for (int i = 0; i < (int)c; i++)
int main()
{
int n, d, x;
scanf("%d %d %d", &n, &d, &x);
int a[n];
rep(i, n) scanf("%d", &a[i]);
int ans = x;
rep(i, n)
{
int temp = 1;
temp += (d - 1) / a[i];
ans += temp;
}
printf("%d\n", ans);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main()
{
long long i,j,k,a,b,c=0,d,n,m,t=1,x;
cin>>n>>d>>x;
long long A[n];
for(i=0;i<n;i++)
cin>>A[i];
for(i=0;i<n;i++)
{
t=1;
while(t<=d)
{
x++;
t+=A[i];
}
}
cout<<x<<endl;
return 0;
} | 1 | 38,326,565 |
#include <iostream>
using namespace std;
int main(void)
{
int a1, a2, a3, a4, a;
int b1, b2, b3, b4, b;
cin >> a1 >> a2 >> a3 >> a4;
cin >> b1 >> b2 >> b3 >> b4;
a = a1 + a2 + a3 + a4;
b = b1 + b2 + b3 + b4;
if(a <= b){
cout << b << endl;
}
else if(a > b){
cout << a << endl;
}
return (0);
} | #include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
using namespace std;
int main()
{
int A,B,a,b,c,d,cnt = 0;
scanf("%d%d%d%d",&a,&b,&c,&d);
A = a + b + c + d;
scanf("%d%d%d%d",&a,&b,&c,&d);
B = a + b + c + d;
if(A<B){
printf("%d\n",B);
}
else printf("%d\n",A);
return 0;
} | 1 | 89,531,694 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
#define i_5 i_7-2
ll mod(ll a){
ll c=a%i_7;
if(c>=0)return c;
return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int main(){fastio
string s;
ll n,k;cin>>n>>s>>k;
string t;
rep(i,0,n-1){
if(s[i]==s[k-1])t+=s[i];
else t+='*';
}
cout<<t<<endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
typedef long long ll;
ll N[maxn];
int main()
{
int n,k;string s;cin>>n;cin>>s;cin>>k;
char c=s[k-1];
for(int i=0;i<s.length();i++)
{
if(c==s[i]) printf("%c",s[i]);
else printf("*");
}
} | 1 | 8,448,841 |
#include<bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define F first
#define S second
#define f(i,s,n) for(int i=(int)s;i<=(int)n;++i)
#define Fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int N=2e5+5;
vector< set<int> > adj(N);
vector<bool> vis(N,false);
int S=0;
void dfs(int s){
vis[s]=1;
for(auto it:adj[s]){
if(!vis[it]){
++S;
dfs(it);
}
}
}
void solve()
{
int n,m;cin>>n>>m;
f(i,1,m){
int u,v;cin>>u>>v;
adj[u].insert(v);
adj[v].insert(u);
}
int mx=-1;
f(i,1,n){
dfs(i);
mx=max(S,mx);
S=0;
}
++mx;
cout<<mx<<'\n';
}
int main()
{ Fast;
solve();
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define reps(i,n) for(ll i=0;i<=n;i++)
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647;
const double PI = acos(-1);
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
struct UnionFind{
vector<ll> par;
vector<ll> siz;
UnionFind(ll N):par(N),siz(N,1){
for(int i = 0;i<N;i++){
par[i] = i;
}
}
ll root(ll x){
if(par[x]==x)
return x;
return par[x]=root(par[x]);
}
void unite(ll x, ll y){
x = root(x);
y = root(y);
if(x == y) return;
if(siz[x]<siz[y])swap(x,y);
siz[x]+=siz[y];
par[y]=x;
}
ll size(ll x){
return siz[root(x)];
}
bool same(ll x,ll y){
ll rx = root(x);
ll ry = root(y);
return rx == ry;
}
};
int main(){
ios_base::sync_with_stdio(false);
ll N,M,ans=0;
ll x,y;
cin >> N >> M;
UnionFind rel(N);
for(ll i=0;i<M;i++){
cin >> x >> y;
rel.unite(x-1,y-1);
}
for(ll i=0;i<N;i++){
ans = max(ans,rel.size(i));
}
cout << ans << endl;
return 0;
} | 1 | 63,096,945 |
#include<bits/stdc++.h>
using namespace std;
#define FOR(a, b, c) for(int a = b; a <= c; ++a)
#define FORW(a, b, c) for(int a = b; a >= c; --a)
#define fi first
#define se second
#define pb push_back
#define int long long
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
const int N = 1e5 + 10;
const int oo = 1e18;
const int mod = 1e9 + 7;
int n, suma, sumb;
int a[N], b[N];
signed main() {
ios_base::sync_with_stdio(false); cout.tie(0);
cin >> n;
bool flag = true;
FOR(i, 1, n) cin >> a[i], suma += a[i];
FOR(i, 1, n) {
cin >> b[i], sumb += b[i];
if(b[i] != a[i]) flag = false;
}
if(suma > sumb) return cout << "No", 0;
if(suma == sumb) return cout << ((flag) ? "Yes" : "No"), 0;
int cnt = sumb - suma;
FOR(i, 1, n) if(b[i] > a[i]) cnt -= (b[i] - a[i] + 1) / 2;
return cout << ((cnt >= 0) ? "Yes" : "No"), 0;
} | #include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define SZ(x) ((int)(x).size())
#define rep(i,n) for(int i=0;i<(n);++i)
#define fore(i,a) for(auto &i:a)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define answer cout << ans << endl;
signed _main(); signed main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
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> using v = vector<T>;
template<class T> using vv = vector<v<T>>;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
signed _main(){
int N; cin >> N;
v<int> a(N),b(N);
rep(i,N) cin >> a[i];
rep(i,N) cin >> b[i];
int res=0,dif=0;
rep(i,N){
if(b[i]-a[i]>=2){
res+=(b[i]-a[i])/2;
}
if(a[i]>b[i]) dif+=a[i]-b[i];
}
if(res>=dif) Yes
else No
return 0;
} | 1 | 72,371,692 |
#include <bits/stdc++.h>
using namespace std;
signed main(){
string S, T;
cin >> S;
cin >> T;
cout << T << S << endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
int main()
{
string s,t;
cin>>s>>t;
t=t+s;
cout<<t;
return 0;
} | 1 | 60,663,304 |
#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll mod= 1e9 + 7;
int main(){
int n;
cin >>n;
ll ans=1;
ll a[n];
rep(i,n)cin >> a[i];
rep(i,n){
ans=ans / __gcd(ans,a[i]) * a[i];
}
cout << ans << endl;
} | #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define NIL = -1;
#define all(x) x.begin(),x.end()
const ll INF = 1e9;
const ll mod = 1e9 + 7;
int digit(ll x) {
if (x / 10 == 0) return 1;
return digit(x / 10) + 1;
}
ll gcd(long long a,long long b) {
if (a < b) swap(a,b);
if (b == 0) return a;
return gcd(b,a%b);
}
bool is_prime(long long N){
if (N == 1) return false;
for (long long i = 2;i * i <= N;i++){
if (N % i == 0) return false;
}
return true;
}
ll lcm(ll a,ll b){
return ((a * b == 0)) ? 0 : (a / gcd(a,b) * b);
}
double DegreeToRadian(double degree){
return degree * M_PI / 180.0;
}
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};
int main(){
int n;
cin >> n;
int64_t ans;
for (int i = 0;i < n;i++){
int64_t t;
cin >> t;
if (i == 0){
ans = t;
continue;
}
ans = lcm(ans, t);
}
cout << ans << endl;
} | 1 | 47,962,260 |
#include <bits/stdc++.h>
#define F first
#define S second
#define pii pair<int, int>
#define pb push_back
using namespace std;
typedef long long ll;
const int N = 2e5 + 10;
ll ans, cnt, gr[N];
ll a[N];
vector<int> adj[N];
void DFS(int v, int p = -1)
{
gr[v] = 0;
for(auto u : adj[v])
{
if(u == p)continue;
DFS(u, v);
gr[v] ^= (gr[u] + 1);
}
return ;
}
int main()
{
int t = 1;
while(t--)
{
int ted = 0, n, root = 0; cin >> n;
for(int i=0; i<n; i++)adj[i].clear();
for(int i=0; i<n-1; i++)
{
int u, v; cin >> u >> v;
--u; --v;
adj[u].pb(v);
adj[v].pb(u);
}
DFS(root);
if(gr[root])cout << "Alice\n";
else cout << "Bob\n";
}
} | #include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<stack>
#include<set>
using namespace std ;
using ll = long long ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
using pll = pair<ll,ll> ;
ll INF = 1e15 ;
void chmin(ll &a,ll b){if(a>b) a = b ;}
void chmax(ll &a,ll b){if(a<b) a = b ;}
void YorN(bool a){cout << (a?"YES":"NO") << "\n" ;}
ll DFS(vvll &g,int cur,int pre){
ll res = 0 ;
for(int i=0;i<g[cur].size();i++){
if(pre==g[cur][i]) continue ;
res ^= DFS(g,g[cur][i],cur)+1 ;
}
return res ;
}
int main(){
ll n ; cin >> n ;
vvll g(n) ;
for(int i=1;i<n;i++){
ll a,b ;
cin >> a >> b ;
a-- ; b-- ;
g[a].push_back(b) ;
g[b].push_back(a) ;
}
cout << (DFS(g,0,-1)?"Alice":"Bob") << endl ;
} | 1 | 76,192,601 |
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mx 100000000
#define pb push_back
#define mp make_pair
#define YES cout<<"YES\n";
#define Yes cout<<"Yes\n";
#define NO cout<<"NO\n";
#define No cout<<"No\n";
#define all(v) (v).begin(),(v).end()
ll md=1e9+7;
ll __gcd(ll a, ll b) {if(b==0) return a; return __gcd(b, a%b);}
ll poww(ll a, ll b) {ll res=1;while(b) {if(b&1){res*=a;res%=md;}a*=a;a%=md;b>>=1;}return res;}
void ainp(int arr[], int n) {for(int i=0;i<n;i++) cin>>arr[i];}
const ll N=3e5+5;
void fun()
{ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
signed main()
{
fun();
int t;
t=1;
while(t--)
{
ll sum=0,i;
string s;
cin>>s;
for(i=0;i<s.length();i++)
{
sum+=(s[i]-'0');
}
if(sum%9==0)
Yes
else
No
}
} | #include<bits/stdc++.h>
using namespace std;
void solve()
{
string s;
cin>>s;
int i=0;
int sum=0;
while(s[i]!='\0')
{
sum+=s[i]-'0';
i++;
}
if(sum%9==0)
cout<<"Yes";
else
cout<<"No";
return;
}
int main()
{
solve();
} | 1 | 30,671,196 |
#include<bits/stdc++.h>
template<typename First, typename Second, typename Third>
struct triple {
First first;
Second second;
Third third;
};
using namespace std;
void solve(){
int a,b;
cin>>a>>b;
cout<<(a*b)-(a+b)+1;
}
int main(){
std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
solve();
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main(){
int a,b;
scanf("%d%d",&a,&b);
printf("%d\n",a*b-a-b+1);
} | 1 | 20,648,075 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<char> cvec;
typedef vector<double> dvec;
typedef pair<ll, ll> LP;
typedef tuple<ll, ll, ll> LT;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
#define fs first
#define sc second
int main() {
string s,t;
cin>>s>>t;
t+=s;
cout<<t<<endl;
} | #include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define piii pair<int,pii>
#define pll pair<ll,ll>
#define plii pair<ll,pii>
#define vi vector<int>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define lw(vc,num) lower_bound(vc.begin(), vc.end(), num) - vc.begin();
#define hg(vc,num) upper_bound(vc.begin(), vc.end(), num) - vc.begin();
#define bn(v,x) binary_search (v.begin(), v.end(), x)
#define mx 100001
#define eps 0.00000000001
#define mod 1000000007
#define pi acos(-1)
#define inf 100000000
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
bool isprime(int n)
{
if(n == 1) return false;
if(n == 2 || n == 3) return true;
if(n%2 == 0 || n%3 == 0) return false;
for(int i=5; i*i<=n; i+=6){
if((n%i == 0)||(n%(i+2) == 0)) return false;
}
return true;
}
long long binpow(long long a, long long b) {
if (b == 0)
return 1;
long long res = binpow(a, b / 2);
if (b % 2)
return res * res * a;
else
return res * res;
}
ll ncr(ll x, ll y) {
ll ans = 1;
for (ll i = 1; i <= y; ++i) {
ans *= (x - y + i);
ans /= i;
}
return ans;
}
int main()
{
fio;
string s1,s2;
cin>>s1>>s2;
cout<<s2<<s1<<endl;
return 0;
} | 1 | 96,395,070 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
int N;
vector<int> L, R;
void input() {
cin >> N;
L = R = vector<int>(N);
rep(i, N) cin >> L[i] >> R[i];
}
int main() {
input();
int ans = 0;
rep(i, N) ans += R[i] - L[i] + 1;
cout << ans << endl;
} | #include <iostream>
#include <cstdio>
using namespace std;
int main(){
long long n;
cin >> n;
long long ans = 0;
for(long long i = 0; i < n; i++){
long long l, r;
cin >> l >> r;
ans += r - l + 1;
}
cout << ans << endl;
return 0;
} | 1 | 12,587,762 |
/*https:
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
string a, b;
cin >> a >> b;
if (a.length() != b.length())
{
if (a.length() > b.length())
cout << "GREATER";
else if (a.length() < b.length())
cout << "LESS";
}
else if (a.length() == b.length())
{
if (a > b)
cout << "GREATER";
else if (a < b)
cout << "LESS";
else if (a == b)
cout << "EQUAL";
}
} | #include <iostream>
#include <string>
using namespace std;
int main(){
string A, B;
cin >> A >> B;
if (A.size() > B.size()){
printf("GREATER\n");
}else if (A.size() < B.size()){
printf("LESS\n");
}else{
int flg = 0;
for (int i = 0; i < A.size(); i++){
if(A[i] > B[i]){
flg = 1;
break;
}else if(A[i] < B[i]){
flg = 2;
break;
}
}
if (flg == 1){
printf("GREATER\n");
}else if(flg == 2){
printf("LESS\n");
}else{
printf("EQUAL\n");
}
}
} | 1 | 80,042,137 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll ;
typedef double db;
const double pi = 3.141592654;
#define pb push_back
#define forab(i,a,b) for(int i=(a);i<=(b);i++)
#define CIN ios_base::sync_with_stdio(0); cin.tie(0)
#define pcase(z,x) printf("Case %ld: %lld\n",z,x)
#define nw "\n"
int main(void)
{
CIN;
ll tc,l,k,sum=0,x=0,y,z=0,m=1,n=0,ans=0,cnt=0;
string s;
ll a,b;
cin>>a>>b;
cin>>s;
l=s.size();
if(s[a]=='-')x=1;
for(ll i=0;i<l;i++){
if(i==a)continue;
if(!(s[i]>='0'&&s[i]<='9'))return cout<<"No",0;
}
if(x==1)cout<<"Yes";
else cout<<"No";
} | #define _GIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void) {
int A, B;
string S;
cin >> A >> B >> S;
bool ok = true;
for (int i = 0; i < A; ++i) {
if (!isdigit(S[i])) ok = false;
}
if (S[A] != '-') ok = false;
for (int i = A + 1; i < A + B + 1; ++i) {
if (!isdigit(S[i])) ok = false;
}
if (ok) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
} | 1 | 30,380,303 |
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int main(void) {
ios::sync_with_stdio(false);
int N;
cin >> N;
vector<int> A;
int abs_sum = 0;
vector<int> pA;
vector<int> mA;
rep(i, N) {
int A;
cin >> A;
abs_sum += abs(A);
if (0 <= A)
pA.emplace_back(A);
else
mA.emplace_back(A);
}
sort(pA.begin(), pA.end());
sort(mA.begin(), mA.end(), greater<int>());
int plus = pA.size();
int minus = mA.size();
int pi = 0;
int mi = 0;
if (plus == 0) {
if (minus == 2) {
cout << mA[1] - mA[0] << endl;
cout << mA[1] << " " << mA[0] << endl;
return 0;
}
abs_sum += (2 * mA[0]);
cout << abs_sum << endl;
cout << mA[0] << " " << mA[1] << endl;
pA.emplace_back(mA[0] - mA[1]);
mi = 2;
minus -= 2;
plus = 1;
} else if (minus == 0) {
if (plus == 2) {
cout << pA[1] - pA[0] << endl;
cout << pA[1] << " " << pA[0] << endl;
return 0;
}
abs_sum -= (2 * pA[0]);
cout << abs_sum << endl;
cout << pA[0] << " " << pA[1] << endl;
mA.emplace_back(pA[0] - pA[1]);
pi = 2;
plus -= 2;
minus = 1;
} else {
cout << abs_sum << endl;
}
while (plus && minus) {
if (plus <= minus) {
cout << pA[pi] << " " << mA[mi] << endl;
pA[pi] -= mA[mi++];
--minus;
} else {
cout << mA[mi] << " " << pA[pi] << endl;
mA[mi] -= pA[pi++];
--plus;
}
}
return 0;
} | #include <bits/stdc++.h>
using namespace std; inline void fileio(const char* in, const char* out) { freopen(in, "r", stdin); freopen(out, "w", stdout); }
#define TD typedef
#define forx(i,n) for(int i = 0; i < (n); ++i)
TD long long ll; TD long double ld; TD pair<int,int> pii; TD pair<ll, ll> pll; TD vector<int> VI; TD vector<bool> VB; TD vector<ll> VL;
const char nl = '\n'; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fll; const ld EPS = 1e-9, PI = acos(-1);
#define ff first
#define ss second
int main() {
atexit([](){ cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << nl; });
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n;
cin>> n;
vector<int> balls(n);
for (int i = 0; i <n; i++) {
cin >> balls[i];
}
sort(balls.begin(), balls.end());
int x = balls[n-1];
int y = balls[0];
vector<pii> ops;
for (int i = 1; i<n-1; i++) {
if (balls[i] < 0) {
ops.push_back({x, balls[i]});
x = x - balls[i];
} else {
ops.push_back({y, balls[i]});
y = y - balls[i];
}
}
cout << x - y << endl;
for (pii o: ops) {
cout << o.ff <<" " << o.ss << endl;
}
cout << x << " " << y << endl;
return 0;
} | 1 | 66,289,581 |
#include <iostream>
using namespace std;
int main() {
long long N;
cin >> N;
long long ans = N - 1;
for (long long i = 1; i * i <= N; i++) {
if (N % i) continue;
long long j = N / i;
ans = min(ans, i + j - 2);
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int INF = 1e9;
int main(){
long long n;
long long ans = 1e13;
cin >> n;
vector<long long> sum;
for(long long i = 1; i * i <= n; i++){
if(n%i == 0){
sum.push_back(i + n / i);
}
}
for(int i = 0; i < sum.size(); i++){
ans = min(ans, sum[i]);
}
cout << ans - 2 << endl;
return 0;
} | 1 | 70,632,175 |
#include<bits/stdc++.h>
#include<string>
using namespace std;
char N [9999];
void solve(){
if ((N[0] == N[1] && N[1] == N[2]) || (N[1] == N[2] && N[2] == N[3])) {
cout << "Yes"<< endl;
}
else {
cout << "No" << endl;
}
}
int main() {
cin >> N;
solve();
} | #include<bits/stdc++.h>
using namespace std;
int main(){
int A,s;
cin>>A;
s=A%1000;
if(A%1110<10 || s%111==0 || s==0 ){
cout<<"Yes"<<endl;
}else {
cout<<"No"<<endl;
}
} | 1 | 25,397,691 |
#include<bits/stdc++.h>
using namespace std;
int n,k;
int a[233333];
int main()
{
ios_base::sync_with_stdio(false);
cin>>n>>k;
for(int i=1;i<=n;i++)cin>>a[i];
int pos=-1;
for(int i=1;i<n;i++)
{
if(a[i]+a[i+1]>=k)
{
pos=i;
break;
}
}
if(pos==-1)
{
return cout<<"Impossible"<<endl,0;
}
cout<<"Possible"<<endl;
for(int i=1;i<pos;i++)cout<<i<<endl;
for(int i=n-1;i>pos;i--)cout<<i<<endl;
cout<<pos<<endl;
return 0;
} | #include<bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1000000000000;
const int mod = 1000000007;
int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
int bb[1234][1234], cc[123][123][123];
int res[123456], uio[1234][1234];
signed main() {
int n, m, a, b, x = INF, mae = 0, ans = 0; cin >> n >> m;
for (int h = 0; h < n; h++) {
cin >> a;
if (h > 0 && (a + mae) >= m) { x = h; }
mae = a;
}
if (x == INF) { cout << "Impossible" << endl; return 0; }
cout << "Possible" << endl;
for (int h = 1; h < x; h++) {
cout << h << endl;
}
for (int h = n - 1; h > x; h--) {
cout << h << endl;
}
cout << x << endl;
return 0;
} | 1 | 69,500,071 |
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) (v).begin(),(v).end()
const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);
int main(void)
{
ll n; cin>>n;
long double ans=0;
rep(i,n){
long double x;
string y;
cin>>x>>y;
if(y=="JPY") ans+=x;
else ans+=380000.0*x;
}
cout<<ans<<endl;
return 0;
} | #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include<math.h>
using namespace std;
#define int long long
#define endl "\n"
#define fir first
#define sec second
#define fro front
#define m_p make_pair
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define rep(i,n) for(int i=0; i<(int) (n); i++)
#define all(v) v.begin(),v.end()
#define vecin(v) for(int i=0; i<(int)v.size(); i++)cin>>v[i];
using namespace std;
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
int jousu(int x00, int y00) {
int z00 = 1;
for (int i = 0; i < y00; i++) {
z00 *= x00;
}
return z00;
}
int keta(int x00) {
int z00 = x00;
int w00 = 0;
while (z00 != 0) {
z00 /= 10;
w00++;
}
return w00;
}
int modinv(int a, int m) {
int b = m, u = 1, v = 0;
while (b) {
int t = a / b;
a -= t * b; swap(a, b);
u -= t * v; swap(u, v);
}
u %= m;
if (u < 0) u += m;
return u;
}
int modpow(int a, int n) {
int res = 1;
while (n > 0) {
if (n & 1) res* a% mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
int gcd(int xx, int yy) {
int p = xx;
int q = yy;
if (q > p)swap(p, q);
while (p % q != 0) {
p %= q;
swap(p, q);
}
return q;
}
int lcm(int xx, int yy) {
return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
int a = xx;
for (int i = 2; i * i <= xx; i++) {
if (xx % i == 0) {
return 0;
}
}
return 1;
}
int com(int xx, int yy) {
int zz = 1;
for (int i = xx; i > xx - yy; i--) {
zz *= i;
zz %= mod;
}
for (int i = 1; i <= yy; i++) {
zz *= modinv(i, mod);
zz %= mod;
}
return zz;
}
signed main() {
int n;
double a,t=0;
string b;
cin >> n;
rep(i, n) {
cin >> a >> b;
if (b == "JPY") {
t += a;
}
if (b == "BTC") {
t += 380000 * a;
}
}
printf("%.10lf", t);
} | 1 | 61,809,533 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
static const int Infinity=2000000000;
int main(){
int n;cin>>n;
int P[n+1],DP[n][n];
rep(i,n){
scanf("%d %d",&P[i],&P[i+1]);
}
rep(i,n){
DP[i][i]=0;
}
for(int i=1;i<n;i++){
for(int j=0;j+i<n;j++){
int minc=Infinity;
for(int k=j;k<j+i;k++){
minc=min(minc,DP[j][k]+DP[k+1][j+i]+P[j]*P[k+1]*P[j+i+1]);
}
DP[j][j+i]=minc;
}
}
cout<<DP[0][n-1]<<endl;
} | #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define INF 1e9
int main(void){
int n;
cin >> n;
int unwanted;
vector<int> c(n + 1);
cin >> c[0] >> c[1];
for(int i = 2; i <= n; i++){ cin >> unwanted >> c[i]; }
vector<vector<int> > dp(n, vector<int>(n + 1, INF));
for(int i = 0; i < n; i++){ dp[i][i + 1] = 0; }
for(int k = 2; k <= n; k++){
for(int i = 0; i < n; i++){
for(int j = 1; j < k; j++){
if(i + k <= n){
dp[i][i + k] = min(dp[i][i + k], dp[i][i + j] + dp[i + j][i + k] + c[i] * c[i + j] * c[i + k]);
}
}
}
}
cout << dp[0][n] << endl;
return 0;
} | 1 | 6,123,027 |
#include<stdio.h>
int main()
{
int n, b[512], f[512], r[512], v[512];
int j[4][3][10] = { 0 };
int a=0,i,m,k;
scanf("%d",&n);
for (i = 0; i < n; i++){
scanf("%d%d%d%d",&b[i],&f[i],&r[i],&v[i]);
}
for (i = 0; i < n; i++){
j[b[i]-1][f[i]-1][r[i]-1]+=v[i];
}
for (i = 0; i < 4; i++){
if (a)printf("####################\n");
for (m = 0; m < 3; m++){
for (k = 0; k < 10; k++){
printf(" %d",j[i][m][k]);
}
printf("\n");
a = 1;
}
}
return 0;
} | #include <iostream>
#include <vector>
using namespace std;
class build
{
public:
build(int s)
{
n = s;
for(int i = 0;i < 10;i++)
{
f1[i] = 0;
f2[i] = 0;
f3[i] = 0;
}
}
void set(int fn,int rn,int mn);
int get(int fn,int rn);
int n;
int f1[10];
int f2[10];
int f3[10];
};
void build::set(int fn, int rn, int mn)
{
switch(fn)
{
case 1:
f1[rn] += mn;
break;
case 2:
f2[rn] += mn;
break;
case 3:
f3[rn] += mn;
break;
default:
break;
}
}
int build::get(int fn, int rn)
{
switch(fn)
{
case 0:
return f1[rn];
case 1:
return f2[rn];
case 2:
return f3[rn];
default:
break;
}
return 0;
}
int main()
{
int n;
cin >> n;
build a(1);
build b(2);
build c(3);
build d(4);
for(int i = 0;i < n;i++)
{
int bn;
int fn;
int rn;
int mn;
cin >> bn >> fn >> rn >> mn;
switch(bn)
{
case 1:
a.set(fn,rn - 1,mn);
break;
case 2:
b.set(fn,rn - 1,mn);
break;
case 3:
c.set(fn,rn - 1,mn);
break;
case 4:
d.set(fn,rn - 1,mn);
default:
break;
}
}
for(int i = 0;i < 3;i++)
{
for(int j = 0;j < 10;j++)
{
cout << " " << a.get(i,j);
}
cout << endl;
}
cout << "####################" << endl;
for(int i = 0;i < 3;i++)
{
for(int j = 0;j < 10;j++)
{
cout << " " << b.get(i,j);
}
cout << endl;
}
cout << "####################" << endl;
for(int i = 0;i < 3;i++)
{
for(int j = 0;j < 10;j++)
{
cout << " " << c.get(i,j);
}
cout << endl;
}
cout << "####################" << endl;
for(int i = 0;i < 3;i++)
{
for(int j = 0;j < 10;j++)
{
cout << " " << d.get(i,j);
}
cout << endl;
}
return 0;
} | 1 | 78,668,174 |
#include <bits/stdc++.h>
using namespace std;
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>; using Vi = vector<long long int>;
using P = pair<int, int>; using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>())
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";};
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
void solve(){
int a,b,c,d;
cin >> a >> b >> c >> d;
print(min(a,b)+min(c,d));
return;
}
int main(){
cin.tie(0);ios::sync_with_stdio(false);
std::cout<<std::fixed<<std::setprecision(30);
solve();
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);
struct fastio {
fastio() {
ios::sync_with_stdio(false);
cout << setprecision(10) << fixed;
cin.tie(0);
}
};
fastio _fast_io;
int a, b, c, d;
int main() {
cin >> a >> b >> c >> d;
cout << min(a, b) + min(c, d) << endl;
return 0;
} | 1 | 90,492,838 |
#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>
#include<functional>
#include<assert.h>
#include<numeric>
#include <bits/stdc++.h>
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)
#define pll pair<ll,ll>
#define pint pll
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
double v[200020];
int main(){
rep(i,200020)v[i]=longinf;
int n;
cin >> n;
pair<double,pair<double,double>> p[n];
double t=0;
rep(i,n){
double x;
cin >> x;
double s=t;
double e=t+x;
t+=x;
p[i].second.first=s;
p[i].second.second=e;
}
rep(i,n)cin >> p[i].first;
rep(i,n){
rep(j,2*t+1){
if(p[i].second.first<=0.5*j && 0.5*j<=p[i].second.second){
v[j]=min(v[j],p[i].first);
}
}
}
rep(i,n){
rep(j,2*t+1){
v[j]=min(v[j],p[i].first+min(abs(0.5*j-p[i].second.first),abs(0.5*j-p[i].second.second)));
}
}
rep(j,2*t+1)v[j]=min(v[j],-0.5*j+t);
rep(j,2*t+1)v[j]=min(v[j],0.5*(double)j);
double ans=0.0;
rep(i,2*t){
ans+=(v[i]+v[i+1])/2.0;
}
cout << setprecision(12) << ans/2.0 << endl;
return 0;} | #include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
const double INF=1e20;
int N;
int T[222];
int V[222];
double dp[222][222];
signed main(){
cin>>N;
rep(i,N)cin>>T[i];
rep(i,N)cin>>V[i];
fill_n(*dp,222*222,-INF);
dp[0][0]=0;
rep(i,N){
rep(j,V[i]+1){
rep(k,min(V[i],V[i+1])+1){
if(abs(j-k)>T[i])continue;
double tmp=dp[i][j];
int d=abs(j-k);
int M=max(j,k);
int m=min(j,k);
tmp+=(j+k)*0.5*d;
d=T[i]-d;
if((V[i]-M)*2>d)tmp+=d*d*0.25+M*d;
else tmp+=(V[i]+M)*(V[i]-M)+(d-(V[i]-M)*2)*V[i];
chmax(dp[i+1][k],tmp);
}
}
}
printf("%.20f\n",dp[N][0]);
return 0;
} | 1 | 46,040,828 |
#include<bits/stdc++.h>
#define ls ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define __ <<" "<<
#define loop(m,n) for(m=0;m<n;m++)
#define case(z) "Case " << z++ << ": "
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define quit return 0
using namespace std;
void showmyDS(set<int> ds)
{
set<int> ::iterator it;
for (it=ds.begin();it!=ds.end();it++)
{
cout << *it << endl ;
}
cout << endl;
}
int main()
{
ls
ll int n;
cin >> n ;
ll int a[n],i,c=1,mn=INT_MAX;
loop(i,n)
{
cin >> a[i];
if(i==0)
mn=a[i];
else
{
if(a[i]<mn)
{
c++;
mn=a[i];
}
}
}
cout<<c;
quit;
} | #include <bits/stdc++.h>
#include <chrono>
using namespace std;
using namespace std::chrono;
#define ll long long
#define ld long double
#define ull unsigned long long
#define endl "\n"
ll google_itr = 1;
#define google(x) cout<<"Case #"<<x<<":"
#define pi 3.14159265358979323846264338327950L
const ll mod = 1e9+7;
const ll inf = 1e18;
ll popcount(ll num){
num = num - ((num >> 1) & 0x55555555);
num = (num & 0x33333333) + ((num >> 2) & 0x33333333);
return ((num + (num >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;
}
vector<pair<ll,ll>> factor_arr;
void myfactor(ll num){
ll count = 0;
while (!(num % 2)) {
num >>= 1; count++;
}
if (count) factor_arr.push_back({2,count});
for (auto i = 3; i <= sqrt(num); i += 2) {
count = 0;
while (num % i == 0) {
count++;
num /= i;
}
if (count) factor_arr.push_back({i,count});
}
if (num > 2) factor_arr.push_back({num,1});
}
void virus(){
ll len;
cin>>len;
vector<ll> arr(len);
for(auto &i:arr) cin>>i;
ll mn = LLONG_MAX, ans = 0;
for(auto i:arr){
if(i <= mn) ans++, mn = i;
}
cout<<ans;
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll t=1;
while(t--){
auto start = high_resolution_clock::now();
virus();
auto stop = high_resolution_clock::now();
auto duration = duration_cast<seconds>(stop - start);
}
return 0;
} | 1 | 13,006,411 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int a , w;
cin >> a >> w;
cout << a * a - w << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n,a;
cin >> n;
cin >> a;
cout << (n*n)-a <<"\n";
return(0);
} | 1 | 18,981,774 |
#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(const string& s) {
return '"' + s + '"';
}
string to_string(const char* s) {
return to_string((string) s);
}
string to_string(bool b) {
return (b ? "true" : "false");
}
string to_string(vector<bool> v) {
bool first = true;
string res = "{";
for (int i = 0; i < static_cast<int>(v.size()); i++) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(v[i]);
}
res += "}";
return res;
}
template <size_t N>
string to_string(bitset<N> v) {
string res = "";
for (size_t i = 0; i < N; i++) {
res += static_cast<char>('0' + v[i]);
}
return res;
}
template <typename A>
string to_string(A v) {
bool first = true;
string res = "{";
for (const auto &x : v) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(x);
}
res += "}";
return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
template<typename T>
void read(T& val){
cin >> val;
}
template<typename T>
void read(vector<T>& a){
for(int i = 0; i < (int)a.size(); ++i){
read(a[i]);
}
}
template<typename Head, typename... Tail>
void read(Head& H, Tail&... T){
read(H);
read(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
#define vec vector
#define i64 long long
#define endl '\n'
#define sz(x) (x).size()
#define times(n) for(int i = 0; i < (n); ++i)
#define bits(x) __builtin_popcount(x)
int test_case_number = 1;
void print_case(){
#ifdef LOCAL
cout << "Case #" << test_case_number++ << ": ";
#endif
}
void to_bin(int n){
cout << n << "\t=\t";
for(int i = 12; i >= 0; --i){
if((n >> i) & 1){
cout << "1";
} else {
cout << "0";
}
}
cout << endl;
}
void solve(){
int n, m, k, ans = 0;
read(n, m, k);
vector<string> g(n);
read(g);
for(int mask = 0; mask < (1 << (n + m)); ++mask){
int count = 0;
for(int i = 0; i < n; ++i){
for(int j = 0; j < m; ++j){
if((mask & (1 << i)) && (mask & (1 << (n + j))) && g[i][j] == '#'){
count ++;
}
}
}
if(count == k){
ans ++;
}
}
cout << ans << endl;
}
int main(){
solve();
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
int H,W,K;
cin>>H>>W>>K;
vector<vector<char>> c(H,vector<char> (W));
for(int i=0;i<H;i++){
for(int j=0;j<W;j++){
cin>>c.at(i).at(j);
}
}
vector<vector<char>> d(H,vector<char> (W));
for(int i=0;i<H;i++){
for(int j=0;j<W;j++){
d.at(i).at(j)=c.at(i).at(j);
}
}
int ans=0;
for(int bit = 0;bit<(1<<H);++bit){
for(int BIT = 0;BIT<(1<<W);++BIT){
for(int i=0;i<H;i++){
if(bit&(1<<i)){
for(int j=0;j<W;j++){
d.at(i).at(j)='r';
}
}
}
for(int j=0;j<W;j++){
if(BIT&(1<<j)){
for(int i=0;i<H;i++){
d.at(i).at(j)='r';
}
}
}
int cnt=0;
for(int i=0;i<H;i++){
for(int j=0;j<W;j++){
if(d.at(i).at(j)=='#'){
cnt++;
}
d.at(i).at(j)=c.at(i).at(j);
}
}
if(cnt==K){
ans++;
}
}
}
cout<<ans<<endl;
} | 1 | 31,629,771 |
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
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>bool even(T n) { return ! (n & 1); }
template<class T>bool odd(T n) { return n & 1; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;}
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;
int main()
{
ll N, M;
cin >> N >> M;
vll x(N), y(N), z(N);
vllvll cands;
vector<tuple<ll, ll, ll, ll>> data(N);
ll ans = -inf;
rep(i, 0, N) {
ll a, b, c;
cin >> a >> b >> c;
x[i] = a;
y[i] = b;
z[i] = c;
data[i] = make_tuple(a, b, c, i);
}
if (M == 0) {
cout << 0 << endl;
return 0;
}
sort(data.rbegin(), data.rend(), [](auto a, auto b) {
ll p = get<0>(a);
ll q = get<1>(a);
ll r = get<2>(a);
ll pp = get<0>(b);
ll qq = get<1>(b);
ll rr = get<2>(b);
return p + q + r < pp + qq + rr;
} );
ll xtmp, ytmp, ztmp;
xtmp = ytmp = ztmp = 0;
ll sm;
sm = 0;
rep(i, 0, M) {
xtmp += get<0>(data[i]);
ytmp += get<1>(data[i]);
ztmp += get<2>(data[i]);
}
sm = abs(xtmp) + abs(ytmp) + abs(ztmp);
chmax(ans, sm);
sort(data.rbegin(), data.rend(), [](auto a, auto b) {
ll p = get<0>(a);
ll q = get<1>(a);
ll r = get<2>(a);
ll pp = get<0>(b);
ll qq = get<1>(b);
ll rr = get<2>(b);
return p + q - r < pp + qq - rr;
} );
xtmp = ytmp = ztmp = 0;
sm = 0;
rep(i, 0, M) {
xtmp += get<0>(data[i]);
ytmp += get<1>(data[i]);
ztmp += get<2>(data[i]);
}
sm = abs(xtmp) + abs(ytmp) + abs(ztmp);
chmax(ans, sm);
sort(data.rbegin(), data.rend(), [](auto a, auto b) {
ll p = get<0>(a);
ll q = get<1>(a);
ll r = get<2>(a);
ll pp = get<0>(b);
ll qq = get<1>(b);
ll rr = get<2>(b);
return p - q + r < pp - qq + rr;
} );
xtmp = ytmp = ztmp = 0;
sm = 0;
rep(i, 0, M) {
xtmp += get<0>(data[i]);
ytmp += get<1>(data[i]);
ztmp += get<2>(data[i]);
}
sm = abs(xtmp) + abs(ytmp) + abs(ztmp);
chmax(ans, sm);
sort(data.rbegin(), data.rend(), [](auto a, auto b) {
ll p = get<0>(a);
ll q = get<1>(a);
ll r = get<2>(a);
ll pp = get<0>(b);
ll qq = get<1>(b);
ll rr = get<2>(b);
return p - q - r < pp - qq - rr;
} );
xtmp = ytmp = ztmp = 0;
sm = 0;
rep(i, 0, M) {
xtmp += get<0>(data[i]);
ytmp += get<1>(data[i]);
ztmp += get<2>(data[i]);
}
sm = abs(xtmp) + abs(ytmp) + abs(ztmp);
chmax(ans, sm);
sort(data.rbegin(), data.rend(), [](auto a, auto b) {
ll p = get<0>(a);
ll q = get<1>(a);
ll r = get<2>(a);
ll pp = get<0>(b);
ll qq = get<1>(b);
ll rr = get<2>(b);
return -p + q + r < -pp + qq + rr;
} );
xtmp = ytmp = ztmp = 0;
sm = 0;
rep(i, 0, M) {
xtmp += get<0>(data[i]);
ytmp += get<1>(data[i]);
ztmp += get<2>(data[i]);
}
sm = abs(xtmp) + abs(ytmp) + abs(ztmp);
chmax(ans, sm);
sort(data.rbegin(), data.rend(), [](auto a, auto b) {
ll p = get<0>(a);
ll q = get<1>(a);
ll r = get<2>(a);
ll pp = get<0>(b);
ll qq = get<1>(b);
ll rr = get<2>(b);
return -p + q - r < -pp + qq -rr;
} );
xtmp = ytmp = ztmp = 0;
sm = 0;
rep(i, 0, M) {
xtmp += get<0>(data[i]);
ytmp += get<1>(data[i]);
ztmp += get<2>(data[i]);
}
sm = abs(xtmp) + abs(ytmp) + abs(ztmp);
chmax(ans, sm);
sort(data.rbegin(), data.rend(), [](auto a, auto b) {
ll p = get<0>(a);
ll q = get<1>(a);
ll r = get<2>(a);
ll pp = get<0>(b);
ll qq = get<1>(b);
ll rr = get<2>(b);
return -p - q + r < -pp - qq +rr;
} );
xtmp = ytmp = ztmp = 0;
sm = 0;
rep(i, 0, M) {
xtmp += get<0>(data[i]);
ytmp += get<1>(data[i]);
ztmp += get<2>(data[i]);
}
sm = abs(xtmp) + abs(ytmp) + abs(ztmp);
chmax(ans, sm);
sort(data.rbegin(), data.rend(), [](auto a, auto b) {
ll p = get<0>(a);
ll q = get<1>(a);
ll r = get<2>(a);
ll pp = get<0>(b);
ll qq = get<1>(b);
ll rr = get<2>(b);
return -p - q - r < -pp - qq -rr;
} );
xtmp = ytmp = ztmp = 0;
sm = 0;
rep(i, 0, M) {
xtmp += get<0>(data[i]);
ytmp += get<1>(data[i]);
ztmp += get<2>(data[i]);
}
sm = abs(xtmp) + abs(ytmp) + abs(ztmp);
chmax(ans, sm);
cout << ans << endl;
} | #include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <sstream>
#include <utility>
#include <deque>
#include <numeric>
#include <map>
#include <stack>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF 100000
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
int main () {
int N, M;
cin >> N >> M;
vector<ll> x(N), y(N), z(N);
rep(i,N) cin >> x[i] >> y[i] >> z[i];
ll rot[8][3] = { {1,1,1}, {1,1,-1}, {1,-1,1}, {1,-1,-1}, {-1,1,1}, {-1,1,-1}, {-1,-1,1}, {-1,-1,-1}};
ll ans = 0;
rep(r, 8) {
vector<ll> v(N);
rep (i,N) {
v[i] = x[i] * rot[r][0] + y[i] * rot[r][1] + z[i] * rot[r][2];
}
sort(v.rbegin(), v.rend());
ll cur = 0;
rep(i,M) {
cur += v[i];
}
ans = max(ans, cur);
}
cout << ans << endl;
return 0;
} | 1 | 34,551,238 |
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <bitset>
using namespace std;
int main()
{
int n;
cin >> n;
int one = n/100;
int two = n%100/10;
int three = n%100%10;
if(one == 1)
{
cout << 9;
}
else if(one == 9)
{
cout << 1;
}
else
{
cout << one;
}
if(two == 1)
{
cout << 9;
}
else if(two == 9)
{
cout << 1;
}
else
{
cout << two;
}if(three == 1)
{
cout << 9;
}
else if(three == 9)
{
cout << 1;
}
else
{
cout << three;
}
cout << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int main() {
int N;
cin >> N;
string sn;
sn = to_string(N);
string ans;
for(int i=0; i<3; i++){
if (sn[i] == '9'){
ans += "1";
}
else ans += "9";
}
cout << ans << endl;
} | 1 | 94,270,027 |
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
#define NUM 1000000000000000000
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
ll a,b,c,k;
cin>>a>>b>>c>>k;
if(abs(a-b)>NUM){
cout<<"Unfair";
return 0;
}
if(k%2==0) cout<<a-b;
else cout<<b-a;
} | #include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define RE(i,n) for (int i = 1; i <= n; i++)
#define RED(i,n) for (int i = n; i > 0; i--)
#define REPS(i,n) for(int i = 1; (i*i) <= n; i++)
#define REP(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)
#define remax(a,b) a = max(a,b)
#define remin(a,b) a = min(a,b)
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define WL(t) while(t --)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << *it << " "; cout << endl;
#define debug(x) cout << x << endl;
#define debug2(x,y) cout << x << " " << y << endl;
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;
#define rep(i,a,n) for(int i=a; i<n; i++)
#define endl "\n"
#define E "\n"
#define show(arr) REP(i,arr.size()){cout<<arr[i]<<" ";}
const int INF = 1e18+1;
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;
const int MAX = 1e18;
#define N 5010
void solve()
{
int a,b,c,k;
cin>>a>>b>>c>>k;
int x = (k%2==1)?-1:1;
if (a<INF&&b<INF&&c<INF){
cout<<x*(a-b);
}
else{
cout<<"Unfair";
}
}
signed main()
{
int t=1;
WL(t)solve();
return 0;
} | 1 | 21,229,224 |
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
ll H, W;
ll calc(ll a, ll b, ll c){
ll mi = min(a, b); mi = min(mi, c);
ll ma = max(a, b); ma = max(ma, c);
return ma - mi;
}
ll divi(ll h, ll w){
ll ans = (ll)1e9;
if(h >= 3){
ans = min(ans, (h%3?w:0));
}
ll a = (w / 3) * h;
ll b = (w - (a / h)) * (h / 2);
ans = min(ans, calc(a, b, h * w - a - b));
a += h;
b = (w - (a / h)) * (h / 2);
ans = min(ans, calc(a, b, h * w - a - b));
return ans;
}
int main(){
cin >> H >> W;
ll ans = 1e9;
ans = min(ans, divi(H, W));
ans = min(ans, divi(W, H));
cout << ans<< endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll h, w;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> h >> w;
if (h % 3 == 0 || w % 3 == 0) {
cout << 0 << endl;
exit(0);
}
ll ans = min(h, w);
for (int i = 1; i < w; ++i) {
ll left = i * h;
ll right1 = (w - i) * (h / 2);
ll right2 = (w - i) * ((h + 1) / 2);
vector<ll> v = {left, right1, right2};
sort(v.begin(), v.end());
ans = min(ans, v[2] - v[0]);
}
for (int i = 1; i < h; ++i) {
ll up = i * w;
ll right1 = (h - i) * (w / 2);
ll right2 = (h - i) * ((w + 1) / 2);
vector<ll> v = {up, right1, right2};
sort(v.begin(), v.end());
ans = min(ans, v[2] - v[0]);
}
cout << ans << endl;
return 0;
} | 1 | 22,005,059 |
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
int main() {
int n;
string s;
cin >> n >> s;
int ans = 0;
for (char c = '0'; c <= '9'; c++) {
auto i = s.find(c);
if (i == s.npos) continue;
for (char d = '0'; d <= '9'; d++) {
auto j = s.find(d, i + 1);
if (j == s.npos) continue;
for (char e = '0'; e <= '9'; e++) {
auto k = s.find(e, j + 1);
if (k == s.npos) continue;
ans++;
}
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
int main(){
int n;
string s;
cin >> n >> s;
auto strTOint = [&](char c){
return c - '0';
};
vector<int> a(s.size());
REP(i,s.size()){
a[i] = strTOint(s[i]);
}
int ans = 0;
REP(key,1000){
bool ok = false;
int key1 = key/100;
int key2 = (key-key1*100)/10;
int key3 = key-key1*100-key2*10;
int f1 = find(a.begin() , a.end(), key1) - a.begin();
if (f1 == n) continue;
int f2 = find(a.begin() + f1 +1, a.end(), key2) - a.begin();
if (f2 == n) continue;
int f3 = find(a.begin() + f2 + 1, a.end(), key3) - a.begin();
if(f3 != n){
++ans;
}
}
cout << ans << endl;
return 0;
} | 1 | 49,919,202 |
#include <bits/stdc++.h>
using namespace std;
int main(){
const string keyword= "keyence";
string S;
cin >> S;
bool is_satisfied= false;
for(size_t len_head=0; len_head<= keyword.size(); len_head++){
size_t len_tail= keyword.size()- len_head;
if(S.substr(0, len_head)==keyword.substr(0, len_head) && S.substr(S.size()-len_tail)==keyword.substr(keyword.size()-len_tail)){
is_satisfied= true;
break;
}
}
string ans= is_satisfied ? "YES"
: "NO";
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
string s;
cin >> s;
int n = s.size();
for(int i = 0; i < n; i++){
for(int j = 0; j < n - i; j++){
string t = s.substr(0, j) + s.substr(j+i, n-1);
if(t == "keyence"){
cout << "YES\n";
return 0;
}
}
}
cout << "NO\n";
return 0;
} | 1 | 30,076,605 |
#include<iostream>
using namespace std;
int main() {
int A, P;
cin >> A >> P;
int P_sum;
P_sum = A * 3 + P;
cout << P_sum / 2;
} | #include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
#define inf 1e18+42
#define endl "\n"
#define pi 3.1415926535897932384626433832795028841971693993751058
#define maxn 100005
#define out1(a) cout<<#a<<" "<<a<<endl
#define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define fori(it,A) for(auto it=A.begin();it!=A.end();it++)
#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define pq priority_queue
#define all(x) (x).begin(),(x).end()
#define zero(x) memset(x,0,sizeof(x));
#define ceil(a,b) (a+b-1)/b
using namespace std;
int binpow(int a, int b) {
int res = 1;
while (b > 0) {
if (b & 1)
res = res * a;
a = a * a;
b >>= 1;
}
return res;
}
void solve()
{
int a,b;
cin>>a>>b;
cout<<(3*a + b)/2<<endl;
}
signed main()
{
fast;
int t = 1;
while(t--)
{
solve();
}
return 0;
} | 1 | 23,429,411 |
#include <bits/stdc++.h>
#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()
using namespace std;
typedef int64_t ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){cerr<<"\n";} template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
int main()
{
cin.tie(0); ios_base::sync_with_stdio(false);
int n, p; string s;
cin >>n >>p >>s;
ll ans = 0;
if(p==2 || p==5){
rep(i, n) if((s[i]-'0')%p==0) ans +=i+1;
cout << ans <<"\n"; return 0;
}
VL ct(p); ll ks=1, cr=0; ct[0]=1;
repr(i, n-1, 0){
int d = s[i]-'0';
cr = (d * ks + cr) % p;
ans += ct[cr];
ct[cr]++;
ks = ks * 10 % p;
}
cout << ans <<"\n";
return 0;
} | #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<V>;
using VVV = vector<VV>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
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; }
const ll MOD = 1e9 + 7;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
ll solve(int n, int p, string s) {
map<int, ll> mp;
mp[0]++;
ll mul = 1;
V mod(n + 1, 0);
rep(i, n) {
int num = (s[i] - '0') * mul % p;
mod[i + 1] = (mod[i] + num) % p;
mp[mod[i + 1]]++;
mul = mul * 10 % p;
}
ll ans = 0;
for (auto c : mp) {
ans += c.second * (c.second - 1) / 2;
}
return ans;
}
ll solve2(int n, int p, string s) {
ll ans = 0;
rep(i, n) {
int digit = s[i] - '0';
if (digit % p == 0) ans += n - i;
}
return ans;
}
int main() {
int n, p;
cin >> n >> p;
string s;
cin >> s;
reverse(all(s));
if (p == 2 || p == 5) cout << solve2(n, p, s) << endl;
else cout << solve(n, p, s) << endl;
return 0;
} | 1 | 44,302,812 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os, const map<T,U>& mp){ os << "{"; for(auto& p : mp){ os << p << ","; } os << "}"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int,int>;
using vi = std::vector<int>;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
constexpr double eps = 1e-10;
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
string N;
int K;
ll dp[128][4][2];
int main(){
cin >> N;
cin >> K;
int n = N.size();
dp[0][0][0] = 1;
for(int i=0;i<n;i++){
for(int j=0;j<=K;j++){
for(int k=0;k<2;k++){
int U = 9;
if(k==0) U = N[i]-'0';
for(int d=0;d<=U;d++){
int nxtc = j + (d != 0);
if(nxtc > K) continue;
dp[i+1][nxtc][k || d < U] += dp[i][j][k];
}
}
}
}
cout << dp[n][K][0] + dp[n][K][1] << endl;
} | #include <iostream>
#include <string>
#include <vector>
using namespace std ;
using ll = long long ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
int main(){
string s ; cin >> s ;
ll n = s.size();
ll k ; cin >> k ;
vvll dp1(n,vll(k+1,0)),dp2(n,vll(k+1,0)) ;
dp1.at(0).at(0) = (s.at(0)!='0') ;
dp1.at(0).at(1) = s.at(0)-'0'-1 ;
dp2.at(0).at(1) = 1 ;
for(int i=1;i<n;i++){
if(s.at(i)=='0'){
for(int j=0;j<=k;j++) dp2.at(i).at(j) += dp2.at(i-1).at(j) ;
for(int j=1;j<=k;j++) dp1.at(i).at(j) += dp1.at(i-1).at(j-1)*9 ;
for(int j=0;j<=k;j++) dp1.at(i).at(j) += dp1.at(i-1).at(j) ;
}else{
for(int j=1;j<=k;j++) dp2.at(i).at(j) += dp2.at(i-1).at(j-1) ;
for(int j=0;j<=k;j++) dp1.at(i).at(j) += dp2.at(i-1).at(j) ;
for(int j=1;j<=k;j++) dp1.at(i).at(j) += dp2.at(i-1).at(j-1)*(s.at(i)-'0'-1) ;
for(int j=0;j<=k;j++) dp1.at(i).at(j) += dp1.at(i-1).at(j) ;
for(int j=1;j<=k;j++) dp1.at(i).at(j) += dp1.at(i-1).at(j-1)*9 ;
}
}
cout << dp1.at(n-1).at(k)+dp2.at(n-1).at(k) << endl ;
} | 1 | 39,955,094 |
#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[3];
rep(i, 3) cin >> a[i];
sort(a, a + 3);
int b = a[2] - a[0], c = a[2] - a[1];
int ans = 0;
if (b % 2 == 0 && c % 2 == 0) ans = b / 2 + c / 2;
if (b % 2 == 0 && c % 2 == 1) ans = b / 2 + (c+1) / 2 + 1;
if (b % 2 == 1 && c % 2 == 0) ans = (b+1) / 2 + c / 2 + 1;
if (b % 2 == 1 && c % 2 == 1) ans = (b-1) / 2 + (c-1) / 2 + 1;
cout << ans << endl;
return 0;
} | #include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main() {
int a,b,c;
cin >> a >> b >> c;
int mi = min({a,b,c}),ma = max({a,b,c});
int v[] = {a,b,c};
int ans = 1e9;
for(int x = mi;x<=ma;++x){
int res = 0;
rep(i,3){
if(v[i]>x){
res += v[i]-x;
}else{
res += (x-v[i]+1)/2;
if((x-v[i])%2) ++res;
}
}
ans = min(ans,res);
}
cout << ans << endl;
} | 1 | 7,533,072 |
#include <bits/stdc++.h>
#include <numeric>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define reps(i,s,n) for (int i = s; i < n; ++i)
#define rep1(i,n) for (int i = 1; i <= n; ++i)
#define per(i,n) for (int i = n - 1; i >= 0; --i)
#define per1(i,n) for (int i = n; i >= 1; --i)
#define all(c) begin(c),end(c)
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline T intceil(T a, T b) { return (a + (b - 1)) / b; }
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const long long MOD = 1e9+7;
#define precout() cout << std::fixed << std::setprecision(20);
const string alphabet = "abcdefghijklmnopqrstuvwxyz";
const int dy[4] = { 0, 1, 0, -1 };
const int dx[4] = { 1, 0, -1, 0 };
static const long double pi = acos(-1.0);
typedef complex<ld> cd;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N; cin >> N;
vector<string> G(N);
rep(i, N) cin >> G[i];
int ans = 0;
rep(sh, N) {
bool ok = 1;
rep(i, N) {
if(!ok) break;
rep(j, N) {
if(G[(i + sh) % N][j] != G[(j + sh) % N][i]) {
ok = 0;
break;
}
}
}
if(ok) ++ans;
}
ans *= N;
cout << ans << endl;
} | #include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int MAX = 1000000;
const int INF = 1e9;
const double pi=acos(-1);
int main(){
int n;
cin >>n;
vector<string>s(n);
rep(i,n)cin >> s[i];
ll ans=0;
rep(k,n){
vector<string>t(n,string(n,' '));
rep(i,n){
rep(j,n){
t[i][(j+k)%n]=s[i][j];
}
}
bool ok=true;
rep(i,n){
rep(j,n){
if(t[i][j]!=t[j][i])ok=false;
}
}
if(ok)ans++;
}
cout << ans*n << endl;
return 0;
} | 1 | 71,724,446 |
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);
int main() {
ll X, A, B;
cin>>X>>A>>B;
if(B<=A) cout<<"delicious"<<endl;
else if(B<=A+X) cout<<"safe"<<endl;
else cout<<"dangerous"<<endl;
} | #include <iostream>
using namespace std;
using ll = long long;
using ld = long double;
#define ALL(x) begin(x), end(x)
#define REP(i, n) for (size_t i = 0, i##_len = (n); i < i##_len; ++i)
void solve(ll X, ll A, ll B) {
if (B - A <= 0) {
cout << "delicious" << endl;
} else if (B - A <= X) {
cout << "safe" << endl;
} else {
cout << "dangerous" << endl;
}
}
int main() {
ll X;
cin >> X;
ll A;
cin >> A;
ll B;
cin >> B;
solve(X, A, B);
return 0;
} | 1 | 31,948,573 |
#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(void){
int a, b;
cin >> a >> b;
int n = gcd(a, b);
if(n == 1) cout << (ll)a*b << endl;
else {
int s = a / n;
int t = b / n;
cout << n*s*t << endl;
}
return 0;
} | #include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define endl '\n'
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define F first
#define S second
#define debug1(a) cout<<#a<<" "<<(a)<<endl;
#define debug2(a,b) cout<<#a<<" "<<(a)<<" "<<#b<<" "<<(b)<<endl;
#define debug3(a,b,c) cout<<#a<<" "<<(a)<<" "<<#b<<" "<<(b)<<" "#c<<" "<<(c)<<endl;
typedef long double ld;
void solve()
{
ll a, b;
cin >> a >> b;
ll val = (a * b) / (__gcd(a, b));
cout << val << endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
t = 1;
while (t--)
{
solve();
}
} | 1 | 55,954,926 |
#include<bits/stdc++.h>
using namespace std;
int main() {
string S;
int w;
cin >> S >> w;
for (int i=0; i<S.length(); i+=w) {
cout << S[i];
}
} | #include<bits/stdc++.h>
using namespace std;
#define ll long long
int ctoi(char c) {return c-'0';}
int gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int lcm(ll a,ll b){return a*b/gcd(a,b);}
int main(){
string s;
cin >> s;
int n;
cin >> n;
for(int i=0;i<s.size();i+=n){
cout<<s.at(i);
}
cout<<endl;
} | 1 | 58,188,310 |
#include <iostream>
using namespace std;
static int N = 250;
int main()
{
int n, tree[N];
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> tree[i];
}
for (int i = 0 ; i < n; i++)
{
cout << "node " << i + 1 << ": "
<< "key = " << tree[i] << ", ";
if (i > 0)
cout << "parent key = " << tree[(i-1) / 2] << ", ";
if (2 * i + 1 < n)
cout << "left key = " << tree[2 * i + 1] << ", ";
if (2 * i + 2 < n)
cout << "right key = " << tree[2 * i + 2] << ", ";
cout << endl;
}
} | #include<stdio.h>
void print (int,int);
#define N 10000
int H[N];
int main(){
int num;
int i;
scanf("%d",&num);
for(i=1;i<=num;i++) {
scanf("%d",&H[i]);
}
for(i=1;i<=num;i++) {
print(i,num);
printf("\n");
}
return 0;
}
void print(int i,int num){
printf("node %d: ",i);
printf("key = %d, ",H[i]);
if(i/2 >= 1){
printf("parent key = %d, ",H[i/2]);
}
if(i*2 <= num){
printf("left key = %d, ",H[2*i]);
}
if((i*2+1) <= num){
printf("right key = %d, ",H[2*i+1]);
}
} | 1 | 89,650,646 |
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;
using pll=pair<ll,ll>;
#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define MOD 998244353
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int main() {
int N;
cin >> N;
vector<int> D(N);
map<int, int> mp;
rep(i,N) {
cin >> D[i];
mp[D[i]]++;
}
int maxi = -1;
rep(i,N) chmax(maxi, D[i]);
if(D[0] != 0 || mp[0] != 1) {
cout << 0 << endl;
return 0;
}
ll ans = 1;
for(int i=1; i<=maxi; i++) {
rep(j, mp[i]) {
ans *= mp[i-1];
ans %= MOD;
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
using ll = long long int;
ll l=998244353;
int main() {
ll n; cin>>n;
vector<ll> v(100000,0);
ll d0;
rep(i,n){
ll d; cin>>d;
if(i==0)d0=d;
v[d]++;
}
ll i=100000-1;
while(v[i]==0){
v.erase(v.begin()+i);
i--;
}
n=v.size();
ll ans=1;
rep(j,n-1){
rep(k,v[j+1]){
ans*= v[j];
ans%=l;
}
}
if(v[0] !=1||d0!=0){ans=0;}
cout<<ans<<endl;
} | 1 | 66,109,680 |
#include <iostream>
#include <cstdio>
using namespace std;
int main(void){
int money = 100000, weeks;
cin >> weeks;
for(int i = 0; i < weeks; i++){
money += (money / 100) * 5;
int underTp = money % 1000;
if(underTp != 0){
money -= underTp;
money += 1000;
}
}
cout << money << endl;
return 0;
} | #include <cstdio>
using namespace std;
typedef long long int LLI;
int n;
LLI debt = 100000;
int main() {
scanf("%d", &n);
for (int i=0; i<n; i++) {
debt = debt/100*105;
if (debt % 1000) debt = (debt/1000+1)*1000;
}
printf("%lld\n", debt);
} | 1 | 40,027,586 |
#include <bits/stdc++.h>
using namespace std;
#define vit vector<int>::iterator
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fr first
#define sc second
#define skip continue
#define PI 3.14159265
typedef unsigned long long ull;
typedef long long ll;
typedef unsigned int ui;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<bool> vb;
const int INF = 1e9 + 5;
const int MAXN = 3e6 + 123;
void faster(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
bool cmp(const string& a, const string& b) {
return (a + b) < (b + a);
}
vector<int> Reversed(const vector<int>& s){
vector<int> d = s;
reverse(all(d));
return d;
}
void solve(){
int n;
cin >> n;
cout << (n * (n + 1)) / 2;
}
int main(){
int n=1;
while(n--){
solve();
}
} | #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 n; cin >> n;
int ans = (n+1)*n/2;
cout << ans << endl;
return 0;
} | 1 | 28,235,698 |
#include<iostream>
using namespace std;
int main(){
int a,b,c,j;
j =0;
cin >> a >> b >> c;
for(int i = 0;i <= b-a;i++){
int n = a + i;
if(c % n == 0){
j = j + 1;
}
}
cout << j << endl;
} | #include <iostream>
#include <cstdio>
using namespace std;
const int M = 100000;
int main()
{
int a, b, c;
cin >> a >> b >> c;
int count = 0;
for (int i = a; i <= b; i++) {
if (c%i == 0) {
count++;
}
}
cout << count << endl;
return 0;
} | 1 | 96,347,184 |
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;
const int N = 100010, M = 1010;
int n, m;
int a[N];
int main()
{
cin >> n >> m;
for (int i = 1; i <= n; i ++ ) cin >> a[i];
int res = 0;
for (int l = 0; l <= min(n, m); l ++ )
for (int r = 0; r <= min(n - l, m - l); r ++ )
{
vector<int> t;
for (int i = 1; i <= l; i ++ ) t.PB(a[i]);
for (int i = n, j = r; j; j -- , i -- ) t.PB(a[i]);
sort(t.begin(), t.end());
int sum = 0, cnt = m - l - r;
for (auto u : t)
if (cnt && u < 0) cnt -- ;
else sum += u;
res = max(res, sum);
}
cout << res << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, K; cin >> N >> K;
int v[N];
for(int i = 0; i < N; i++) {
cin >> v[i];
}
int ans = 0;
for (int i = 0; i <= min(N, K); i++)
{
for (int j = 0; i + j <= min(N, K); j++)
{
vector<int> jewelry;
for(int k = 0; k < i; k++) jewelry.push_back(v[k]);
for(int k = 0; k < j; k++) jewelry.push_back(v[N-1-k]);
sort(jewelry.begin(), jewelry.end());
int s = 0;
for (int k = 0; k < min(K - i - j, (int)jewelry.size()); k++)
{
if(jewelry[k] < 0) s++;
}
int tmp = 0;
for (int k = s; k < jewelry.size(); k++)
{
tmp += jewelry[k];
}
ans = max(ans, tmp);
}
}
cout << ans << endl;
return 0;
} | 1 | 42,404,788 |
#include <bits/stdc++.h>
using namespace std;
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; }
using ll = long long;
using lb = long double;
using P = pair<ll,ll>;
using graph = vector<vector<ll>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll INF = 1LL<<60;
const ll mod = 1000000007LL;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
int A,B;
cin>>A>>B;
string S;
cin>>S;
bool ok = true;
rep(i,A+B+1){
if(i<A||i>A){
int t = S[i] - '0';
if(t<0||t>=10) ok = false;
}
else {
if(S[i]!='-') ok = false;
}
}
if(ok) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
} | #define _GIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void) {
int A, B;
string S;
cin >> A >> B >> S;
bool ok = true;
for (int i = 0; i < A; ++i) {
if (!isdigit(S[i])) ok = false;
}
if (S[A] != '-') ok = false;
for (int i = A + 1; i < A + B + 1; ++i) {
if (!isdigit(S[i])) ok = false;
}
if (ok) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
} | 1 | 16,942,219 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;
int main(){
int N;
cin >> N;
vector<int> A(N+1), B(N);
for(int i=0; i<N+1; i++) cin >> A[i];
for(int i=0; i<N; i++) cin >> B[i];
ll count = 0;
for(int i=0; i<N; i++) {
if(A[i] >= B[i]) {
count += B[i];
A[i] -= B[i];
}
else if(A[i] < B[i]) {
count += A[i] + min(B[i] - A[i], A[i+1]);
A[i+1] = max(A[i+1]-(B[i]-A[i]), 0);
}
}
cout << count << endl;
} | #include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define P pair<int,int>
#define PI 3.141592653589793
const int INF = 1001001001;
const ll MX = 1e18;
const int mod = 1000000007;
int main() {
int n;
cin >> n;
vector<ll>a(n+1),b(n);
rep(i, n+1) {
cin >> a[i];
}
rep(i, n) {
cin >> b[i];
}
ll ans = 0;
rep(i, n) {
if (b[i] > a[i]) {
if (b[i] > a[i] + a[i + 1]) {
ans += a[i + 1];
ans += a[i];
a[i + 1] = 0;
}
else {
ans += b[i];
a[i + 1] =a[i+1] - b[i] + a[i];
}
}
else {
ans += b[i];
}
}
cout << ans << endl;
} | 1 | 69,974,633 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int main() {
int N;
cin >> N;
vector<int> A(N);
REP(i,N){
cin >> A[i];
}
vector<int> cost(N+1),cost2(N),cost3(N);
ll all = 0;
REP(i,N+1){
if ( i == 0 ) {
cost[0] = abs(A[0]);
} else if ( i == N ) {
cost[N] = abs(A[N-1]);
} else {
cost[i] = abs(A[i]-A[i-1]);
}
all += cost[i];
}
REP(i,N){
if ( i == 0 ){
cost2[0] = abs(A[1]);
} else if ( i == N-1 ){
cost2[N-1] = abs(A[N-2]);
} else {
cost2[i] = abs(A[i+1] - A[i-1]);
}
}
REP(i,N){
cost3[i] = cost[i] + cost[i+1];
}
ll ans;
REP(i,N){
ans = all - cost3[i] + cost2[i];
cout << ans << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main(){
int64_t n;
cin >> n;
int64_t a[110000];
a[0] = 0;
for(int i=1; i<=n; i++){
cin >> a[i];
}
a[n+1] = 0;
int64_t allCost = 0;
for(int i=0; i<=n; i++){
allCost += abs(a[i+1] - a[i]);
}
for(int i=0; i<n; i++){
int64_t ans = allCost;
ans -= abs(a[i+1] - a[i]);
ans -= abs(a[i+2] - a[i+1]);
ans += abs(a[i+2] - a[i]);
cout << ans << endl;
}
return 0;
} | 1 | 28,960,555 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int H, W;
cin >> H >> W;
vector<vector<char>> M(H, vector<char>(W));
int dx[4] = {1, 0, 0, -1};
int dy[4] = {0, 1, -1, 0};
for (int i = 0; i < H; i++)
{
for (int j = 0; j < W; j++)
{
cin >> M[i][j];
}
}
bool result = true;
for (int i = 0; i < H; i++)
{
for (int j = 0; j < W; j++)
{
if (M[i][j] == '#') {
int c_n = 0;
for (int d = 0; d < 4; d++)
{
int cx = i + dx[d];
int cy = j + dy[d];
if (cx < 0 || H<= cx)
continue;
if (cy < 0 || W <= cy)
continue;
if (M[cx][cy] == '#')
c_n++;
}
if (c_n == 0) {
result = false;
break;
}
}
}
}
if (result) {
cout << "Yes" << endl;
}
else
{
cout << "No" << endl;
}
} | #include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <map>
#include <vector>
#include <cmath>
using namespace std;
void c_grid_repating2(void) {
int h, w;
char s[51][51];
cin >> h >> w;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) cin >> s[i][j];
}
for (int j = 0; j < h; j++) {
for (int i = 0; i < w; i++) {
char org = s[j][i];
char org_xp1;
char org_xm1;
char org_yp1;
char org_ym1;
if (org == '#') {
if (i == 0) org_xm1 = '.';
else org_xm1 = s[j][i - 1];
if (i == w - 1) org_xp1 = '.';
else org_xp1 = s[j][i + 1];
if (j == 0) org_ym1 = '.';
else org_ym1 = s[j - 1][i];
if (j == h - 1) org_yp1 = '.';
else org_yp1 = s[j + 1][i];
if ((org_xm1 == '#') || (org_xp1 == '#') || (org_ym1 == '#') || (org_yp1 == '#')) continue;
cout << "No" << endl;
return;
}
}
}
cout << "Yes" << endl;
}
int main()
{
c_grid_repating2();
return 0;
} | 1 | 66,973,999 |
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef pair <int, int> PII;
typedef pair <ll, ll> PLL;
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define right(x) x << 1 | 1
#define left(x) x << 1
#define forn(x, a, b) for (int x = a; x <= b; ++x)
#define for1(x, a, b) for (int x = a; x >= b; --x)
#define mkp make_pair
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define y1 kekekek
const ll ool = 1e18 + 9;
const int oo = 1e9 + 9, base = 1e9 + 7;
const ld eps = 1e-7;
const int N = 2e6 + 6;
ll n, m, cnt, sz[N], col[N];
bool u[N], bad[N];
vector < ll > g[N];
void dfs(ll v) {
u[v] = 1;
sz[cnt]++;
for (auto to : g[v]) {
if (!u[to]) {
col[to] = col[v] ^ 1;
dfs(to);
}
if (col[to] == col[v]) bad[cnt] = 1;
}
}
int main() {
ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n >> m;
forn(i, 1, m) {
ll x, y;
cin >> x >> y;
g[x].eb(y);
g[y].eb(x);
}
forn(i, 1, n) {
if (!u[i]) {
++cnt;
dfs(i);
}
}
ll ans = 1ll * n * n, sum = 0, c = 0, b = 1;
forn(i, 1, cnt) {
if (sz[i] == 1) continue;
ans -= 1ll * sz[i] * sum * 2 + 1ll * sz[i] * sz[i];
sum += sz[i];
if (bad[i]) {
ans += 1ll * 2 * (b - 1) + 1;
}
else {
ans += 1ll * (b - c - 1) * 2 + 1ll * c * 4 + 2;
++c;
}
++b;
}
cout << ans << "\n";
return 0;
} | #include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
template <typename T>
using V = vector<T>;
template <typename T, typename U>
using P = pair<T, U>;
template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using GPQ = priority_queue<T, vector<T>, greater<T>>;
using ll = long long;
#define fst first
#define snd second
#define mp make_pair
#define mt make_tuple
#define INT(c) static_cast<int>(c)
#define CHAR(n) static_cast<char>(n)
#define LL(n) static_cast<ll>(n)
#define DOUBLE(n) static_cast<double>(n)
#define ALL(v) (v).begin(), (v).end()
#define SIZE(v) (LL((v).size()))
#define FIND(v, k) (v).find(k) != (v).end()
#define VFIND(v, k) find(ALL(v), k) != (v).end()
#define gsort(b, e) sort(b, e, greater<decltype(*b)>())
#define SORT(v) sort((v).begin(), (v).end())
#define GSORT(v) sort((v).begin(), (v).end(), greater<decltype((v).front())>())
#define FOR(i, a, b) for (ll i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (ll i = (b)-1; i >= (a); --i)
template <class T>
ostream& operator<<(ostream& os, vector<T> v) {
os << "[";
for (auto vv : v)
os << vv << ",";
return os << "]";
}
template <class T>
ostream& operator<<(ostream& os, set<T> v) {
os << "[";
for (auto vv : v)
os << vv << ",";
return os << "]";
}
template <class L, class R>
ostream& operator<<(ostream& os, pair<L, R> p) {
return os << "(" << p.fst << "," << p.snd << ")";
}
template <typename T>
T sq(T a) {
return a * a;
}
template <typename T>
T gcd(T a, T b) {
if (a > b) return gcd(b, a);
return a == 0 ? b : gcd(b % a, a);
}
template <typename T, typename U>
T mypow(T b, U n) {
if (n == 0) return 1;
if (n == 1) return b ;
if (n % 2 == 0) {
return mypow(sq(b) , n / 2);
} else {
return mypow(b, n - 1) * b ;
}
}
ll pcnt(ll b) {
return __builtin_popcountll(b);
}
V<ll> path[100010];
ll d[100010];
bool dfs(ll v, ll t) {
if (d[v] >= 0) {
return t != d[v];
}
d[v] = t;
bool ret = false;
for (ll sv : path[v]) {
ret |= dfs(sv, 1 - t);
}
return ret;
}
void solve() {
ll N, M;
cin >> N >> M;
FOR(i, 0, M) {
ll a, b;
cin >> a >> b;
--a;
--b;
path[a].push_back(b);
path[b].push_back(a);
}
fill(d, d + N, -1);
ll odd = 0, even = 0, one = 0;
FOR(v, 0, N) {
if (d[v] >= 0) continue;
if (path[v].empty()) {
++one;
continue;
}
if (dfs(v, 0)) {
++even;
} else {
++odd;
}
}
cout << sq(N) - sq(N - one) + sq(odd + even) + sq(odd) << endl;
return;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
#ifdef DEBUG
freopen("input.txt", "r", stdin);
int num;
cin >> num;
FOR(_, 0, num) {
cout << "++++++++++++++++++++" << endl;
solve();
}
#else
solve();
#endif
return 0;
} | 1 | 99,779,331 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
#define FOR(i,s,e) for(ll i = s; i <= (ll)e; ++i)
#define DEC(i,s,e) for(ll i = s; i >= (ll)e; --i)
#define IAMSPEED ios_base::sync_with_stdio(false); cin.tie(0);
#define db(x) cerr << #x << "=" << x << "\n"
#define db2(x, y) cerr << #x << "=" << x << " , " << #y << "=" << y << "\n"
#define db3(a,b,c) cerr<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<"\n"
#define dbv(v) cerr << #v << ":"; for (auto ite : v) cerr << ite << ' '; cerr <<"\n"
#define dbvp(v) cerr << #v << ":"; for (auto ite : v) cerr << "{" << ite.f << ',' << ite.s << "} "; cerr << "\n"
#define dba(a,ss,ee) cerr << #a << ":"; FOR(ite,ss,ee) cerr << a[ite] << ' '; cerr << "\n"
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define reach cerr << "LINE: " << __LINE__ << "\n";
typedef pair <ll, ll> pi;
typedef tuple<ll,ll,ll> ti3;
string cts(char x) {string t(1,x); return t;}
ll rand(ll a, ll b) { return a + rng() % (b-a+1); }
const int MOD = 1e9 + 7;
const int inf = (int)1e9 + 500;
const long long oo = (ll)1e18 + 500;
template <typename T> void chmax(T& a, T b) { a = max(a, b); }
template <typename T> void chmin(T& a, T b) { a = min(a, b); }
const int MAXN = 2e5+5;
#ifndef LOCAL
#define cerr if(0)cout
#endif
int A[MAXN];
int sum[MAXN];
int32_t main()
{
IAMSPEED
int n,k; cin >> n >> k;
FOR(i,1,n){
cin>>A[i];
}
bool cont = 1;
while(cont&&k--) {
bool alln = 1;
memset(sum,0,sizeof sum);
FOR(i,1,n) {
int st = max(i-A[i],1ll);
int en = min(i+A[i],(ll)n);
if(en != n || st != 1) alln=0;
sum[st]++;
sum[en+1]--;
}
FOR(i,1,n) {
sum[i]+=sum[i-1];
A[i]=sum[i];
}
if(alln)cont=0;
}
FOR(i,1,n)cout<<A[i]<<' ';
} | #include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main() {
int n,k;
cin >> n >> k;
vector<int> a(n);
rep (i,n) cin >> a[i];
vector<int> ans(n);
rep (i,k){
vector<int> b(n,0);
rep(j,n){
int l = max(0,j-a[j]);
int r = min(n-1,j+a[j]);
b[l]++;
if (r+1<n) b[r+1]--;
}
for (int j=1;j<(n);j++) b[j]+=b[j-1];
a = b;
if (count(a.begin(),a.end(),n) == n) break;
}
ans = a;
rep(i,n) cout << ans[i] << " ";
return 0;
} | 1 | 54,063,797 |