code1
stringlengths 54
12k
| code2
stringlengths 71
12k
| similar
int64 0
1
| __index_level_0__
int64 0
101M
|
---|---|---|---|
#include <bits/stdc++.h>
#define rep_override(x, y, z, name, ...) name
#define rep2(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, r) for (int i = (l); i < (r); ++i)
#define rep(...) rep_override(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003;
template <class T> inline bool chmin(T &x, const T &y) {if (x > y) {x = y; return 1;} return 0;}
template <class T> inline bool chmax(T &x, const T &y) {if (x < y) {x = y; return 1;} return 0;}
struct IOSET {IOSET() {cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10);}} ioset;
int main() {
string s;
int w;
cin >> s >> w;
string ans;
rep(i, sz(s)) {
if (i % w == 0) ans.push_back(s[i]);
}
cout << ans << "\n";
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
using namespace std;
int main()
{
int n;
cin >> n;
int a;
vector<int> p(n + 1);
rep(i, n)
{
cin >> p[i] >> a;
}
p[n] = a;
vector <vector <int> > m(n, vector<int>(n));
for (int l = 0; l < n; l++)
{
for (int i = 0; i < n; i++)
{
int j = i + l;
if(j>=n)break;
if (i == j) m[i][j] = 0;
else
{
m[i][j]=m[i][i]+m[i+1][j]+p[i]*p[i+1]*p[j+1];
for (int k = i;k < j;k++){
m[i][j]=min(m[i][k] + m[k+1][j] + p[i] * p[k + 1] * p[j + 1],m[i][j]);
}
}
}
}
cout<<m[0][n-1]<<endl;
} | 0 | 35,587,757 |
#include <iostream>
using namespace std;
int main(void){
int n, x, cnt=0;
while(1){
cin >>n >>x;
if(n==0 && x==0){
break;
}
for(int i=1; i<n-1; i++){
for(int j=i+1; j<n; j++){
for(int k=j+1; k<n+1; k++){
if(i+j+k==x){
cnt++;
}
}
}
}
cout <<cnt <<endl;
cnt=0;
}
return 0;
} | #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <list>
#include <utility>
#include <tuple>
#include <cstdio>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <cmath>
#include <limits>
#include <iomanip>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
const long long INF = 1LL << 60;
typedef long long ll;
int main() {
string ABCD;
cin >> ABCD;
int total = 0;
int A= (int)ABCD[0]-(int)'0';
int B =(int)ABCD[1]-(int)'0';
int C =(int)ABCD[2]-(int)'0';
int D =(int)ABCD[3]-(int)'0';
if( (A+B+C+D)==7){
cout<< A << "+" << B << "+" << C << "+" << D <<"=7" << endl;
}
else if( (A+B+C-D)==7){
cout<< A << "+" << B << "+" << C << "-" << D <<"=7" << endl;
}
else if( (A+B-C+D)==7){
cout<< A << "+" << B << "-" << C << "+" << D <<"=7" << endl;
}
else if( (A+B-C-D)==7){
cout<< A << "+" << B << "-" << C << "-" << D <<"=7" << endl;
}
else if( (A-B+C+D)==7){
cout<< A << "-" << B << "+" << C << "+" << D <<"=7" << endl;
}
else if( (A-B+C-D)==7){
cout<< A << "-" << B << "+" << C << "-" << D <<"=7" << endl;
}
else if( (A-B-C+D)==7){
cout<< A << "-" << B << "-" << C << "+" << D <<"=7" << endl;
}
else if( (A-B-C-D)==7){
cout<< A << "-" << B << "-" << C << "-" << D <<"=7" << endl;
}
} | 0 | 44,240,308 |
#include <iostream>
using namespace std;
int main() {
int v[5];
for (int i = 0; i < 5; i++) {
cin >> v[i];
}
int minIdx = -1;
int minRest = 10;
for (int i = 0; i < 5; i++) {
if(v[i]%10!=0 && v[i]%10<minRest) {
minIdx = i;
minRest = v[i]%10;
}
}
int ans = 0;
for (int i = 0; i < 5; i++) {
if(i==minIdx) {
ans += v[i];
continue;
}
ans += ((v[i]+10-1)/10)*10;
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#include <cmath>
const double PI = 3.14159265358979323846;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;
std::istream &operator>>(std::istream &in, set<int> &o) {
ll a;
in >> a;
o.insert(a);
return in;
}
std::istream &operator>>(std::istream &in, queue<int> &o) {
ll a;
in >> a;
o.push(a);
return in;
}
bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }
typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n;
cin >> n;
vector<ll> numbers(n);
rep(i, n) cin >> numbers[i];
sort(numbers.begin(), numbers.end());
vector<P> build;
queue<ll> plus, minus;
rep(i, n) {
if (i == 0) {
minus.push(numbers[i]);
} else if (i == n - 1) {
plus.push(numbers[i]);
} else {
if (numbers[i] < 0) minus.push(numbers[i]);
else plus.push(numbers[i]);
}
}
while (plus.size() > 1) {
ll pf = plus.front(), mf = minus.front();
plus.pop();
minus.pop();
minus.push(mf - pf);
build.emplace_back(mf, pf);
}
ll ans;
while (!minus.empty()) {
ll pf = plus.front(), mf = minus.front();
plus.pop();
minus.pop();
ans = pf - mf;
plus.push(ans);
build.emplace_back(pf, mf);
}
cout << ans << endl;
for (P p : build) {
printf("%lld %lld\n", p.first, p.second);
}
} | 0 | 1,801,321 |
#include<bits/stdc++.h>
#include<ctype.h>
# define pb push_back
#define fst first
#define sec second
#define For(i,a,b) for(int i=a;i<b;i++)
#define ll long long int
#define ull unsigned long long int
#define mod 1000000007
#define fo(i,n) for(ll i=0;i<n;i++)
#define endl "\n"
#define rev(i,n) for(ll i=n-1;i>=0;i--)
#define fo1(i,n) for(ll i=1;i<=n;i++)
#define boolsize 1000001
#define pi pair<ll,ll>
#define vi vector<ll>
#define vii vector<pi>
using namespace std;
template<typename T>
void showvector(vector <T> v)
{
for(T x:v)
cout<<x<<" ";
cout<<endl;
}
template<typename T>
void showvector1(vector <T> v)
{
ll n=v.size();
fo1(i,n-1)
cout<<v[i]<<endl;
}
template<typename T>
void showset(set <T> s)
{
for(T x: s)
cout<<x<<" ";
cout<<endl;
}
template<class T>
void showvectorpair(vector<T> v)
{
for(auto it=v.begin();it!=v.end();it++)
cout<<it->first<<" "<<it->second<<endl;
cout<<endl;
}
template<typename T,typename P>
void showmap(map <T,P> m)
{
for(auto it=m.begin();it!=m.end();it++)
cout<<it->first<<" "<<it->second<<endl;
cout<<endl;
}
template<typename T>
bool comp(T a,T b)
{
return (a>b);
}
template<class T>
bool comppair(T a,T b)
{
if(a.first==b.first)
return(a.second>b.second);
return (a.first>b.first);
}
bool sameparity(ll a,ll b)
{
return (a%2==b%2);
}
bool difparity(ll a,ll b)
{
return !(a%2==b%2);
}
bool isprime(ll x)
{ if(x<=1)
return false;
for(ll i=2;i<=sqrt(x);i++)
{
if(x%i==0)
return false;
}
return true;
}
bool iseven(ll x)
{
return !(x%2);
}
bool isodd(ll x)
{
return (x%2);
}
void vfun()
{
ll n,k;
cin>>n;
vector <ll> v(n);
fo(i,n)
cin>>v[i];
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("inputh.txt", "r", stdin);
freopen("outputh.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
ll test=1;
while(test--)
{
set <ll> s;
vector <ll> v;
ll x;
ll n;
cin>>n;
fo(i,n)
{
cin>>x;
if(s.count(x))
{v.pb(x);s.erase(x);}
else
s.insert(x);
}
ll ans=0;
sort(v.begin(),v.end());
if(v.size()>=2)
{
ll n=v.size();
ans=v[n-1]*v[n-2];
}
cout<<ans;
}
} | #include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int mod = 1e9+7;
const ll inf = 1e18;
const double pi = 3.1415926535897932384626;
ll mpow(ll a,ll b,ll m){
ll res=1;
while(b){
if(b%2) res=res*a%m;
a=a*a%m;
b/=2;
}
return res;
}
ll inv(ll a,ll m){
return mpow(a,m-2,m);
}
ll gcd(ll a,ll b){
if(b==0) return a;
return gcd(b,a%b);
}
ll ncr(ll n,ll k)
{
if(n<k)
return 0;
ll C[n + 1][k + 1];
ll i,j;
for(i=0;i<=n;i++){
for(j=0;j<=min(i,k);j++){
if (j==0 || j==i)
C[i][j]=1;
else
C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
}
}
return C[n][k];
}
void solve(){
string s;
cin>>s;
for(int i=0;i<s.length();i++){
if(s[i]=='1')
s[i]='9';
else if(s[i]=='9')
s[i]='1';
}
cout<<s;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
solve();
return 0;
} | 0 | 10,671,659 |
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);
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 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/gcd(a,b)*b;
}
int main()
{
ll N,M; cin>>N>>M;
vector<ll> b(N); rep(i,N) {cin>>b[i]; b[i]/=2;}
if(N==1){
ll ans=M/b[0];
ans=(ans+1)/2;
cout<<ans<<endl;
return 0;
}
vector<ll> cou(N);
rep(i,N){
ll sb=b[i];
ll count=0;
while(sb%2==0){
sb/=2,count++;
}
cou[i]=count;
}
int judge=0;
rep(i,N-1) if(cou[i]!=cou[i+1]) judge=1;
if(judge){cout<<0<<endl; return 0;}
ll B=1;
rep(i,N) B=lcm(B,b[i]);
ll ans=M/B;
ans=(ans+1)/2;
cout<<ans<<endl;
return 0;
} | #include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<numeric>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)
#define inf (1<<29)
int main(int argc,char* argv[]){
cin.tie(0);
ios::sync_with_stdio(0);
cout << fixed << setprecision(20);
int n;
cin >> n;
vector<int> h(n);
int minheight=inf;
for(auto &x:h){
cin >> x;
minheight=min(minheight,x);
}
for(auto &x:h){
x-=minheight;
}
int ans=minheight;
for(int i=0;i<n;i++){
if(i==0){
ans+=h[i];
}else{
if(h[i]>h[i-1]){
ans+=h[i]-h[i-1];
}
}
}
cout << ans << endl;
return 0;
} | 0 | 62,272,158 |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << " = " << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define SP << " " <<
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vec;
typedef vector<P> pvec;
typedef vector<vector<int>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<int> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<int,vector<int>,greater<int>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;
const vector<int> DX = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> DY = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr int MOD = (1000000007);
const ll INF = (1LL << 60);
const double PI = (3.141592653589794);
const double EPS = (0.0000000001);
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> inline T ceil(T a, T b) {return T((a + b - 1) / b);}
template<class T> inline T round(T a, T b) {return T(a / b);}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }
template <class T> inline void out(T &a) { bool flag=true; for(auto&x:a){if(flag) {flag=false;} else{ cout << ' '; } cout<<x; } cout << endl; }
int nmax=200000;
vvec G(nmax);
void solve4ts()
{
int n,m;
cin>>n>>m;
int i1=1;
int i2=m+2;
for(int i=m;i>=1;i--){
cout<<i1<<" "<<i1+i<<endl;
i1++;
swap(i1,i2);
}
}
signed main(){ ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15);
int repeat = 1;
while(repeat--) solve4ts();
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Matrix;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
ll gcd(ll a, ll b){
if(a % b == 0) return b;
else return gcd(b, a%b);
}
ll lcm(ll a, ll b){
ll g = gcd(a, b);
return a / g * b;
}
int f(ll x){
int res = 0;
while (x % 2 == 0){
res++;
x /= 2;
}
return res;
}
int main(){
int n, m;
cin >> n >> m;
vector<ll> a(n);
rep(i, n) {
cin >> a[i];
a[i] /= 2;
}
ll x = 1;
rep(i, n){
x = lcm(x, a[i]);
if (f(x) != f(a[i])){
cout << 0 << endl;
return 0;
}
}
ll ans = (m / x + 1) / 2;
cout << ans << endl;
} | 0 | 25,232,506 |
#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(){
cin.tie(0);
ios::sync_with_stdio(false);
int n, m, v, p;
cin >> n >> m >> v >> p;
vector<int> a(n);
rep(i, n) cin >> a[i];
sort(a.rbegin(), a.rend());
int low = p, high = n;
while(low < high){
int mid = (low + high + 1) >> 1;
ll total = 0;
rep(i, n){
if(i < p-1 || i >= mid-1) total += m;
else{
if(a[i] > a[mid-1]+m){
total = -1;
break;
}
total += (a[mid-1] + m) - a[i];
}
}
if(total >= (ll) m * v) low = mid;
else high = mid - 1;
}
cout << low << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long lol;
#define REP(i,n) for(lol i=0;i<lol(n);i++)
#define REPD(i,n) for(lol i=n-1;i>=0;i--)
#define FOR(i,a,b) for(lol i=a;i<=lol(b);i++)
#define FORD(i,a,b) for(lol i=a;i>=lol(b);i--)
#define ALL(x) x.begin(),x.end()
#define SIZE(x) lol(x.size())
#define PI 3.1415926535897932385
#define INF 1000000000000
#define MOD 1000000007
#define MAXR 100000
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 gcd(int a,int b){return b?gcd(b,a%b):a;}
int main()
{
lol result{0};
lol k, n; cin >> k >> n;
vector<lol> a(n), b(n);
REP(i, n)
{
cin >> a[i];
if(i)
b[i] = a[i] - a[i-1];
}
b[0] = a[0] + (k - a[n-1]);
lol maxi = a[0];
REP(i, n)
{
maxi = max(maxi, b[i]);
}
result = k - maxi;
cout << result << endl;
return 0;
} | 0 | 4,549,373 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d;
cin >> a >> b >> c >> d;
int ans = 0;
if (a >= b) {
ans += b;
} else {
ans += a;
}
if (c >= d) {
ans += d;
} else {
ans += c;
}
cout << ans << endl;
} | #include <iostream>
#include <ctype.h>
using namespace std;
int main(void){
char data[1200];
cin.getline(data, sizeof(data));
for (int i = 0; i < 1200; i++)
{
if (islower(data[i]) != 0)
{
data[i] = toupper(data[i]);
}
else
{
data[i] = tolower(data[i]);
}
}
cout << data << endl;
} | 0 | 60,286,294 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int M=1e9+7,n,m;
cin>> n >> m;
vector<int> s(n),t(m);
for (int i=0; i<n; i++) cin>> s[i];
for (int i=0; i<m; i++) cin>> t[i];
vector<vector<int>> dp(n,vector<int>(m));
if (s[0]==t[0]) dp[0][0]=1;
for (int i=1; i<n; i++){
dp[i][0]=dp[i-1][0];
if (s[i]==t[0]) dp[i][0]++;
}
for (int i=1; i<m; i++){
dp[0][i]=dp[0][i-1];
if (s[0]==t[i]) dp[0][i]++;
}
for (int i=1; i<n; i++){
for (int j=1; j<m; j++){
dp[i][j]=dp[i-1][j]+dp[i][j-1];
if (s[i]==t[j]) dp[i][j]+=1;
else dp[i][j]-=dp[i-1][j-1];
dp[i][j]%=M;
if (dp[i][j]<0) dp[i][j]+=M;
}
}
cout<< (dp[n-1][m-1]+1)%M <<endl;
} | #include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <queue>
using namespace std;
int main(void){
long long v,e,a[101][101],INF=1e12;
cin>>v>>e;
for(int i=0;i<101;i++){
for(int j=0;j<101;j++){
a[i][j]=INF;
if(i==j)a[i][j]=0;
}
}
for(int i=0;i<e;i++){
int s,t,d;
cin>>s>>t>>d;
a[s][t]=d;
}
for(int i=0;i<v;i++){
for(int j=0;j<v;j++){
for(int k=0;k<v;k++){
if(a[j][i]==INF||a[i][k]==INF)continue;
if(a[j][k]>a[j][i]+a[i][k]){
a[j][k]=a[j][i]+a[i][k];
}
}
}
}
for(int i=0;i<v;i++){
for(int j=0;j<v;j++){
for(int k=0;k<v;k++){
if(a[j][i]==INF||a[i][k]==INF)continue;
if(a[j][k]>a[j][i]+a[i][k]){
cout<<"NEGATIVE CYCLE"<<endl;
return 0;
}
}
}
}
for(int i=0;i<v;i++){
for(int j=0;j<v;j++){
if(a[i][j]==INF)cout<<"INF";
else cout<<a[i][j];
if(j<v-1)cout<<" ";
}
cout<<endl;
}
return 0;
} | 0 | 20,709,170 |
#include<bits/stdc++.h>
using namespace std;
int main() {
int A, N, r;
cin >> N;
cin >> A;
r = N % 500;
if (r <= A) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll =long long;
int main(){
ll N; cin>>N;
vector<ll> H(N);
for (ll i = 0; i < N; i++){
cin>>H[i];
}
ll ans=0,cnt=0;
ll i=0;
while(i<N-1){
if(H[i]>=H[i+1]){
cnt++;
}else{
ans=max(ans,cnt);
cnt=0;
}
i++;
}
ans=max(ans,cnt);
cout<<ans<<endl;
} | 0 | 28,087,610 |
#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 vll = vector<ll>;
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 gcd(ll x, ll y) {
return y ? gcd(y, x % y) : x;
}
ll lcm(ll a, ll b) {
return a / gcd(a, b) * b;
}
vector<P> factorize(ll n) {
vector<P> result;
for (ll i = 2; i * i <= n; ++i) {
if (n % i == 0) {
result.pb({i, 0});
while (n % i == 0) {
n /= i;
result.back().second++;
}
}
}
if (n != 1) {
result.pb({n, 1});
}
return result;
}
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 <typename T>
void debugV(const vector<T> v) {
#ifdef _DEBUG
rep(i, v.size()) {
cout << i << ":" << v[i] << " ";
}
cout << endl;
#else
(void)v;
#endif
}
signed main() {
ll A, B, C;
cin >> A >> B >> C;
ll a = C - A + B;
if (a < 0) {
COUT(0);
} else {
COUT(a);
}
return 0;
} | #include <stdio.h>
int main(){
char str[15];
char ans[15];
scanf("%s", str);
int j = 0;
for (int i=0; str[i]!='\0'; i++){
if (str[i] != 'B'){
ans[j++] = str[i];
if (str[i+1] == 'B'){
j--;
}
ans[j] = '\0';
}
else{
if (j >= 0){
ans[j] = '\0';
if (str[i+1] == 'B'){
(j == 0) ? j = 0 : j--;
}
}
}
}
printf("%s\n", ans);
return 0;
} | 0 | 56,683,384 |
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
#define eb emplace_back
#define pb push_back
#define pob pop_back
#define mp make_pair
#define upb upper_bound
#define lwb lower_bound
#define fi first
#define se second
#define For(i, l, r) for (int i = l; i < r; i++)
#define ForE(i, l, r) for (int i = l; i <= r; i++)
#define Ford(i, r, l) for (int i = r; i > l; i--)
#define FordE(i, r, l) for (int i = r; i >= l; i--)
#define Fora(i, a) for (auto i : a)
#define PrintV(a) Fora(iiii, a) cout << iiii << ' '; cout << endl;
#define PrintVl(a) Fora(iiii, a) cout << iiii << endl;
#define PrintA(a, l, r) for (int iiii = l; iiii <= r; iiii++) cout << a[iiii] << ' '; cout << endl;
#define PrintAl(a, l, r) for (int iiii = l; iiii <= r; iiii++) cout << a[iiii] << endl;
#define Ptest(x) return cout << x, 0;
#define gl(s) getline(cin, s);
#define setpre(x) fixed << setprecision(x)
#define bend(a) a.begin(), a.end()
#define rbend(a) a.rbegin(), a.rend()
#define mset(a) memset(a, 0, sizeof(a))
#define mset1(a) memset(a, 1, sizeof(a))
#define msetn1(a) memset(a, -1, sizeof(a))
#define msetinf(a) memset(a, 0x3f, sizeof(a))
#define gcd __gcd
#define __builtin_popcount __builtin_popcountll
#define pque priority_queue
#define mts multiset
#define y0 _y0_
#define y1 _y1_
#define div divi
typedef long long ll;
typedef long double ld;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <ld> vld;
typedef vector <string> vs;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <vi > vvi;
typedef vector <vll > vvll;
typedef vector <pii > vpii;
typedef vector <pll > vpll;
const int N = 1e5 + 5, mod = 1e9 + 7, mod1 = 998244353, mod2 = 1e9 + 9, inf = 1e9 + 7;
const ll infll = 1e18 + 7;
int n;
int a[N];
int b[N];
int ans[N];
int mx, mxidx;
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
ForE(i, 1, n){
cin >> a[i];
}
if (n == 1){
cout << a[1] << endl;
return 0;
}
map <int, int> mpp;
b[1] = 0;
mpp[a[1]] = 1;
ForE(i, 2, n){
if (mpp.lwb(a[i]) == mpp.begin()){
b[i] = 0;
}
else{
b[i] = (*(--mpp.lwb(a[i]))).se;
}
if (mpp.find(a[i]) == mpp.end()){
mpp[a[i]] = i;
}
}
ForE(i, 1, n){
if (mx < a[i]){
mx = a[i];
mxidx = i;
}
}
int val = mx, idx = mxidx, cnt = 0;
pque <int> pq;
ForE(i, mxidx, n){
if (a[i] >= val){
cnt++;
ans[idx] += a[i] - val;
}
else{
pq.push(a[i]);
}
}
while (idx != 0){
int newidx = b[idx];
int newval = a[newidx];
ans[idx] += cnt * (val - newval);
For(i, newidx, idx){
pq.push(a[i]);
}
while (!pq.empty() && pq.top() >= newval){
cnt++;
ans[idx] += pq.top() - newval;
pq.pop();
}
idx = newidx;
val = newval;
}
ans[idx] += val * cnt;
PrintAl(ans, 1, n);
} | #include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;
int k;
int n;
vector<int> a;
void solve() {
vector<int> diff;
diff.push_back(k+*a.begin()-a[n-1]);
for (auto i=a.begin();i!=a.end();i++) {
diff.push_back(*(i+1) - *i);
}
sort(diff.begin(), diff.end()-1);
int sum = accumulate(diff.begin(), diff.end()-2, 0);
printf("%d\n", sum);
}
int main() {
scanf("%d", &k);
scanf("%d", &n);
for (int i=0;i<n;i++) {
int tmp;
scanf("%d", &tmp);
a.push_back(tmp);
}
solve();
} | 0 | 93,252,071 |
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;
int main() {
int hour[3];
cin >> hour[0] >> hour[1] >> hour[2];
int ans = 1000;
for (int i = 0; i < 2; i++) {
for (int j = i + 1; j < 3; j++) {
ans = min(ans, hour[i] + hour[j]);
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define loop(v, st, en) for (int v = st; v < en; v++)
#define loopdesc(v, st, en) for (int v = st; v >= en; v--)
#define INF 1E9
#define clr(v, d) memset(v, d, sizeof(v))
#define P(x) cout << #x << " = { " << x << " }\n"
#define PI acos(-1)
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
const int M = 2e5 + 5;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int x;
cin >> x;
if (x < 600)
cout << "8";
else if (x < 800)
cout << "7";
else if (x < 1000)
cout << "6";
else if (x < 1200)
cout << "5";
else if (x < 1400)
cout << "4";
else if (x < 1600)
cout << "3";
else if (x < 1800)
cout << "2";
else cout <<"1";
return 0;
} | 0 | 1,324,849 |
#include<iostream>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
int main(){
string T[4]={"dream","dreamer","erase","eraser"};
string S;
cin>>S;
reverse(S.begin(),S.end());
for(int i=0;i<4;i++){
reverse(T[i].begin(),T[i].end());
}
bool ans2 =true;
for(int i=0;i<S.size();){
bool ans=false;
for(int j =0;j<4;j++){
string tmp=T[j];
if(S.substr(i,tmp.size())==tmp){
ans=true;
i+=tmp.size();
}
}
if(!ans){
ans2=false;
break;
}
}
if(ans2) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
return 0;
} | #include <iostream>
#include <algorithm>
#include <queue>
#define rep(i,n) for (int i=0; i < (n); ++i)
using ll = long long ;
using namespace std;
const int INF = 1001001001;
const int MOD = 1e9+7;
int dp[110000] ;
int main() {
int n,k ;
cin >> n >> k ;
int h[n];
rep(i,n) cin >> h[i] ;
dp[0] = 0 ;
for(int i=1;i<n;i++){
dp[i] = INF ;
for(int j=1;j<=k;j++){
if(i-j>=0){
dp[i] = min(dp[i],dp[i-j]+abs(h[i]-h[i-j])) ;
}
}
}
cout << dp[n-1] << endl ;
return 0 ;
} | 0 | 64,390,328 |
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"
#include "random"
using namespace std;
const long long int MOD = 1000000007;
const long double EPS = 0.00000001;
const long double PI = 3.1415926535897932384626433;
long long int N, M, K, H, W, L, R;
vector<long long int>box;
vector<vector<int>>edge;
vector<long long int>up;
vector<bool>flag;
bool can = true;
long long int Search(int num) {
if (up[num] != -1) {
return up[num];
}
if (edge[num].size() == 1) {
up[num] = box[num];
return up[num];
}
flag[num] = false;
long long int sum = 0;
long long int ma = 0;
for (auto i : edge[num]) {
if (flag[i]) {
long long int fig = Search(i);
sum += fig;
ma = max(ma, fig);
}
}
R = sum;
L = max((sum + 1) / 2, ma);
if (L > box[num] || R < box[num]) {
can = false;
}
up[num] = box[num] * 2 - sum;
if (up[num] < 0) {
can = false;
}
return up[num];
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> N;
box.resize(N + 1);
edge.resize(N + 1);
up.resize(N + 1,-1);
flag.resize(N + 1, true);
for (int i = 1; i <= N; i++) {
cin >> box[i];
}
for (int i = 0; i < N - 1; i++) {
cin >> L >> R;
edge[L].push_back(R);
edge[R].push_back(L);
}
if (N == 2) {
if (box[1] == box[2]) {
cout << "YES\n";
}
else {
cout << "NO\n";
}
return 0;
}
for (int i = 1; i <= N; i++) {
if (edge[i].size() != 1) {
if (!Search(i) && can) {
cout << "YES\n";
return 0;
}
cout << "NO\n";
return 0;
}
}
return 0;
} | #include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>
#include <bitset>
#define rep(i, a, b) for ( ll i = (a); i < (b); i++ )
#define per(i, a, b) for ( ll i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()
using namespace std;
typedef long long ll;
typedef long double ld;
using P = pair<int, int>;
static const long long MOD = 1000000007;
static const long long LINF = (ll)(1e18+99);
static const int INF = 1e9+99;
const int MAX_ROW = 100005;
const int MAX_COL = 100;
struct BitMatrix {
int H, W;
bitset<MAX_COL> val[MAX_ROW];
BitMatrix(int h = 1, int w = 1) : H(h), W(w) {}
inline bitset<MAX_COL>& operator [] (int i) { return val[i]; }
};
int xor_elimination(BitMatrix &A) {
int COL = A.W, ROW = A.H;
int rank = 0;
for (int col = COL-1; col>=0; col--) {
int pivot = -1;
for (int row = rank; row<ROW; row++) {
if (A[row][col]) {
pivot = row;
break;
}
}
if (pivot == -1) continue;
swap(A[pivot], A[rank]);
for (int row = 0; row<ROW; row++) {
if (row != rank && A[row][col]) A[row] ^= A[rank];
}
rank++;
}
return rank;
}
int n;
ll a[100005], ans;
int main(void) {
cin >> n;
BitMatrix M(n, MAX_COL);
rep (i, 0, n) {
cin >> a[i];
M[i] = a[i];
}
for (int d=61; d>=0; d--) {
int num = 0;
for (int i=0; i<n; i++) num += M[i][d];
if (num%2) {
ans += (1LL<<d);
for (int i=0; i<n; i++) M[i][d] = 0;
}
}
int rank = xor_elimination(M);
bitset<MAX_COL> b;
rep(i, 0, rank) b ^= M[i];
rep(i, 0, 62) ans += (1LL<<(i+1))*b[i];
cout << ans << endl;
return 0;
} | 0 | 39,702,524 |
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
using namespace std;
int main(int argc, char const* argv[])
{
ios::sync_with_stdio(false);
cin.tie(0);
vector<int> nl;
int mx = 0;
do{
int n;
cin >> n;
if (!cin.eof()){
nl.push_back(n);
mx = max(mx, n);
}else{
break;
}
}while(1);
double r = sqrt(mx);
list<int> sl;
vector<int> primes;
for (int i = 2; i <= mx; i++) {
sl.push_back(i);
}
while (sl.front() <= r) {
int p = sl.front();
primes.push_back(p);
sl.pop_front();
auto i = sl.begin();
while(i != sl.end()){
if(*i % p == 0){
i = sl.erase(i);
}
else {
i++;
}
}
}
for (auto&& i : sl) {
primes.push_back(i);
}
for (auto&& n : nl) {
auto p = upper_bound(primes.begin(), primes.end(), n);
cout << p - primes.begin() << endl;
}
return 0;
} | #include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
os << std::endl;
}
int main() {
int n;
cin >> n;
vl a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
ll ret = a[0] - 1;
ll price = 2;
for (int i = 1; i < n; ++i) {
if (a[i] == price)
price++;
else {
if (a[i] % price == 0) {
ret++;
a[i] -= price + 1;
}
ret += a[i] / price;
}
}
cout << ret << "\n";
return 0;
} | 0 | 34,840,107 |
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue;
#define LINF 1e18
#define INF 1e9
using namespace std;
#define fs first
#define sc second
using P = pair<ll,ll>;
using Pll = pair<P,ll>;
using PQ = priority_queue<P,vector<P>,greater<P>>;
signed main(){
ll n,m;
cin >> n >> m;
bool is_solved[n] = {false};
ll wa_cnt[n] = {};
rep(i,0,m){
ll p;
string s;
cin >> p >> s;
if(!is_solved[p-1]){
if(s == "AC"){
is_solved[p-1] = true;
}
else{
wa_cnt[p-1]++;
}
}
}
ll wa_ans = 0,ac_ans = 0;
rep(i,0,n){
if(is_solved[i]){
ac_ans++;
wa_ans += wa_cnt[i];
}
}
cout << ac_ans << " " << wa_ans << endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout<<fixed; cout<<setprecision(12);
#define randomINT mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define newl cout<<"\n"
#define DISP(as) for(auto it : as) cout<<it<<" ";newl;
#define all(x) (x).begin(),(x).end()
#define mset(x,val) memset(x,val,sizeof(x))
#define newl cout<<"\n"
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define dline cerr<<"
#define deb1(x) cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y) cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z) cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';
typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll ,ll> pll;
typedef pair<ld,ld> pld;
typedef unordered_map<ll,ll> um;
typedef vector<pll> vpll;
const ll MAX5 = 1e+5+7;
const ll MAX7 = 1e+7+7;
const ll MAXN = MAX7;
const ll INF = 0x7f7f7f7f7f7f7f7f;
const int INFi = 0x7f7f7f7f;
const ll MOD = 1e+9+7;
vll adj[MAXN];ll visit[MAXN]={};
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1};
int dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};
ll T=1;
ll n,x;
string s;
void MAIN() {
cin >> n;
vll a(n+1);
vll vis(n+1,0);
for(ll i=1;i<=n;i++) cin >> a[i];
ll cou = 0;
ll ss = 1;
while(vis[ss] == 0) {
vis[ss] = 1;
if(ss == 2) {
cout<<cou;return;
}
cou++;
ss = a[ss];
}
cout<<-1;
}
int main() {
fastio;randomINT;
while(T--) {
MAIN();
}
return 0;
} | 0 | 53,103,452 |
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
ll dp[2020];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout << fixed << setprecision(25);
ll s;
cin >> s;
dp[0] = 1;
rep(i, s) {
FOR(j, i + 3, s + 1) {
dp[j] = (dp[j] + dp[i]) % mod;
}
}
cout << dp[s] << '\n';
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define _GLIBCXX_DEBUG
const lli INF = 2147483647;
const lli MINF = -2147483648;
const lli LINF = 9223372036854775807;
const lli MOD = 1000000007;
const double PI = acos(-1);
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define pb push_back
#define eb emplace_back
#define mp make_pair
#pragma GCC optimize("Ofast")
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using vvli = vector<vlli>;
using vs = vector<string>;
using vvs = vector<vs>;
using vb = vector<bool>;
using vvb = vector<vb>;
using ll = long long;
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
for (T &x : vec)
is >> x;
return is;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
for (int i = 0; i < vec.size(); i++)
{
os << vec[i] << (i + 1 == vec.size() ? "" : "");
}
return os;
}
template <typename T>
bool chmax(T &a, const T &b)
{
if (a < b)
{
a = b;
return true;
}
return false;
}
template <typename T>
bool chmin(T &a, const T &b)
{
if (a > b)
{
a = b;
return true;
}
return false;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
lli a, b, c, d, h, n, m, w, ans = INF, count = 0;
string s, t;
vector<pair<lli, pair<lli, lli>>> pr, ch;
cin >> n >> m;
rep(i, 0, n)
{
cin >> a >> b;
pr.eb(make_pair(i + 1, make_pair(a, b)));
}
rep(i, 0, m)
{
cin >> c >> d;
ch.eb(make_pair(i + 1, make_pair(c, d)));
}
for (auto x : pr)
{
ans = INF;
for (auto y : ch)
{
count = abs(x.second.first - y.second.first) + abs(x.second.second - y.second.second);
ans = min(ans, count);
}
for (auto y : ch)
{
count = abs(x.second.first - y.second.first) + abs(x.second.second - y.second.second);
if (count == ans)
{
cout << y.first << endl;
break;
}
}
}
} | 0 | 89,524,592 |
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> 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; }
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
vector<P> a(n);
rep(i,n){
cin >> a[i].first;
a[i].second = i+1;
}
sort(a.begin(), a.end());
rep(i,n) cout << a[i].second << " ";
cout << endl;
return 0;
} | #include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define mm(arr) memset(arr, 0, sizeof(arr))
#define scanArray(a,n) for(int i = 0; i < n; i++){cin >> a[i];}
#define pb push_back
#define PI 3.141592653589793
#define MOD 1000000007
using namespace std;
int main(){
FAST
ll n; cin >> n;
string s[n];
vector<string>vec;
for(ll i=0;i<n;i++){
cin >> s[i];
sort(s[i].begin(), s[i].end());
vec.pb(s[i]);
}
map<string,ll>mpp;
sort(vec.begin(),vec.end());
ll cnt=0;
ll j=1;
map<string,ll>mpp2;
for(ll i=0;i<n;i++){
mpp2[s[i]]=1;
}
for(ll i=0;i<n;i++){
mpp[s[i]]++;
if(mpp[s[i]]>1){
cnt+=mpp2[s[i]];
mpp2[s[i]]++;
}
}
cout << cnt << endl;
return 0;
} | 0 | 69,302,560 |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll l1[10];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n,x=0,s2=0,k;
cin>>n>>k;
ll l1[n+1];
map<ll,ll>m;
map<ll,ll>m2;
vector<ll>v;
vector<ll>v2;
set<ll>s;
for(int i=1;i<=n;i++){
cin>>x;m2[x]++;
if(m[x]==0){
m[x]=1;
v.push_back(x);
}
s.insert(x);
}
if(k>=s.size())cout<<0<<endl;
else{
for(int i=0;i<v.size();i++){
v2.push_back(m2[v[i]]);
}
sort(v2.begin(),v2.end());
for(int i=0;i<s.size()-k;i++){
s2+=v2[i];
}
cout<<s2<<endl;
}
} | #include <bits/stdc++.h>
typedef long long ll;
#define endl '\n'
using namespace std;
const int MOD = 1000000007, MAX = 2000000007, MAXN = 2005;
ll s[MAXN], t[MAXN],sum[MAXN][MAXN];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n,m;
cin>>n>>m;
for(int i=0; i<n; i++)
cin>>s[i];
for(int i=0; i<m; i++)
cin>>t[i];
for(int i=0; i<=n; i++)
sum[i][0] = 0;
for(int i=0; i<=m; i++)
sum[0][i] = 0;
for(int i=1; i<=n; i++)
{
for(int j=1; j<=m; j++)
{
sum[i][j] = (sum[i-1][j] + sum[i][j-1] + MOD - sum[i-1][j-1])%MOD;
if(s[i-1] == t[j-1])
{
sum[i][j] += (sum[i-1][j-1] + 1)%MOD;
}
sum[i][j]%=MOD;
}
}
cout<<(sum[n][m]+1)%MOD;
return 0;
} | 0 | 19,657,458 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int h, w; cin >> h >> w;
vector<string> mas;
for(int i = 0; i < h; i++){
string line; cin >> line;
int num = count(line.begin(), line.end(), '.');
if(num != line.size())
mas.push_back(line);
}
for(int i = 0; i < w; i++){
int count = 0;
for(int j = 0; j < mas.size(); j++){
if(mas.at(j).at(i)=='.') count++;
}
if( count == mas.size() ){
for(int j = 0; j < mas.size(); j++){
if(mas.at(j).at(i)=='.') mas.at(j).at(i) = '-';
}
}
}
for(int i = 0; i < mas.size(); i++){
for(int j = 0; j < mas.at(i).size(); j++){
if(mas.at(i).at(j) != '-'){
cout << mas.at(i).at(j);
}
} cout << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<typename T>
class UnionFindTreeWithPotential {
const int n;
std::vector<int> par, size;
std::vector <T> diff_potential;
public:
UnionFindTreeWithPotential(int n) : n(n), par(n), size(n), diff_potential(n) {
for (int i = 0; i < n; i++) {
par[i] = i;
size[i] = 1;
diff_potential[i] = T();
}
}
int getRoot(int i) {
if (par[i] == i) {
return i;
} else {
int r = getRoot(par[i]);
diff_potential[i] += diff_potential[par[i]];
return par[i] = r;
}
}
T getPotential(int i) {
getRoot(i);
return diff_potential[i];
}
T getDiff(int i, int j) {
return getPotential(j) - getPotential(i);
}
void unite(int i, int j, T d) {
d -= getDiff(i, j);
i = getRoot(i);
j = getRoot(j);
if (i == j)return;
if (size[i] < size[j])swap(i, j), d = -d;
par[j] = i;
size[i] += size[j];
diff_potential[j] = d;
}
bool isSame(int i, int j) {
return getRoot(i) == getRoot(j);
}
int getSize(int i) {
return size[getRoot(i)];
}
};
int N, M;
int L[220000], R[220000], D[220000];
signed main() {
cin >> N >> M;
UnionFindTreeWithPotential<int> uf(N + 1);
for (int i = 0; i < M; i++) {
cin >> L[i] >> R[i] >> D[i];
if (uf.isSame(L[i], R[i])) {
if (uf.getDiff(L[i], R[i]) != D[i]) {
cout << "No" << endl;
return 0;
}
} else {
uf.unite(L[i], R[i], D[i]);
}
}
cout << "Yes" << endl;
} | 0 | 64,911,899 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i, n) for (int i = 0; i < (n); i++)
using pint = pair<int, int>;
using Graph = vector<vector<int>>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
int main() {
int n;
cin >> n;
ll a[n], b[n];
rep (i, n) cin >> a[i];
rep (i, n) cin >> b[i];
ll sa = 0, sb = 0;
rep (i, n) {
if (a[i] > b[i]) sa += (a[i] - b[i]);
else {
sb += (b[i] - a[i]) / 2;
}
}
if (sb >= sa) cout << "Yes\n";
else
cout << "No\n";
} | #pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 1<<30
#define MOD 1000000007
#define mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef long long int LL;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp(pair<ll,ll>a,pair<ll,ll> b){
if(a.se!=b.se)
return a.se<b.se;
else
return a.fi<b.fi;
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n;cin>>n;
V<int>a(n);
for(int i=0;i<n;i++)cin>>a[i];
V<int>cal;
int cnt=1,pre=a[0];
for(int i=1;i<n;i++){
if(a[i]==pre){
cnt++;
}
else{
cal.pb((cnt));
cnt=1;
pre=a[i];
}
}
if(cnt)cal.pb((cnt));
int ans=0;
for(int i=0;i<cal.size();i++){
ans+=cal[i]/2;
}
cout<<ans<<Endl;
return 0;
} | 0 | 71,952,424 |
#include<iostream>
#include <string>
#include <algorithm>
using namespace std;
void Reverse()
{
string str;
cin>>str;
reverse(str.begin(), str.end());
cout<<str<<endl;
return;
}
int main()
{
Reverse();
return 0;
} | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
ll mod=1e9+7;
int main() {
ll n;
cin >> n;
pll l,r;
ll temp;
string s;
map<string,ll> c;
c["Vacant"]=0;
c["Male"]=1;
c["Female"]=-1;
cout << 0 << endl;
cin >> s;
if(c[s]==0) {
return 0;
}
l=pll(0,c[s]);
cout << n-1 << endl;
cin >> s;
if(c[s]==0) {
return 0;
}
r=pll(n-1, c[s]);
temp=(n-1)/2;
while(1) {
cout << temp << endl;
cin >> s;
ll ans=c[s];
if(ans==0) break;
if((temp-l.first)%2) {
if(ans!=l.second) {
l=pll(temp,ans);
}
else {
r=pll(temp,ans);
}
}
else {
if(ans==l.second){
l=pll(temp,ans);
}
else {
r=pll(temp,ans);
}
}
temp=(l.first+r.first)/2;
}
} | 0 | 38,258,485 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using G = vector<vector<int>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const ll MOD = 1000000007;
ll GCD(ll x, ll y){
return y ? GCD(y, x%y) : x;
}
int main() {
int a, b; cin >> a >> b;
for(int i=1;i<=1300;i++){
int c = i*0.08;
int d = i*0.1;
if(c==a && d==b){
cout << i << endl;
return 0;
}
}
cout << -1 << endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
namespace FAST_IO
{
template<typename T> void read(T &a)
{
a=0;
int f=1;
char c=getchar();
while(!isdigit(c))
{
if(c=='-')
{
f=-1;
}
c=getchar();
}
while(isdigit(c))
{
a=a*10+c-'0';
c=getchar();
}
a=a*f;
}
template <typename T> void write(T a)
{
if(a<0)
{
a=-a;
putchar('-');
}
if(a>9)
{
write(a/10);
}
putchar(a%10+'0');
}
template <typename T> void writeln(T a)
{
write(a);
puts("");
}
}
int main()
{
int a,b,c;
cin>>a>>b>>c;
if(a==b&&b==c)
{
cout<<"Yes";
}
else
{
cout<<"No";
}
} | 0 | 41,759,325 |
#include <iostream>
#include <string>
#include <vector>
class Card{
public:
Card( const std::string str );
char GetSymbol();
int GetNumber();
std::string GetString();
private:
std::string pair;
};
void MySwap( Card& a, Card& b );
void BubbleSort( std::vector<Card>& vec );
void SelectionSort( std::vector<Card>& vec );
std::string CheckStable( std::vector<Card> initial, std::vector<Card> sorted );
int main(){
int n;
std::cin >> n;
std::string str;
std::vector<Card> input;
std::vector<Card> bubble;
std::vector<Card> select;
int i = 0;
for( ; i < n; ++i ){
std::cin >> str;
input.push_back( Card(str) );
bubble.push_back( Card(str) );
select.push_back( Card(str) );
}
BubbleSort(bubble);
SelectionSort(select);
for( i = 0; i < n; ++i ){
std::cout << bubble[i].GetString() << ( ( i != n-1 )? " " : "" );
}
std::cout << "\n" << CheckStable( input, bubble ) << "\n";
for( i = 0; i < n; ++i ){
std::cout << select[i].GetString() << ( ( i != n-1 )? " " : "" );
}
std::cout << "\n" << CheckStable( input, select ) << std::endl;;
}
Card::Card( const std::string str ){
pair = str;
}
char Card::GetSymbol(){
return pair[0];
}
int Card::GetNumber(){
return static_cast<int>( pair[1] - '0' );
}
std::string Card::GetString(){
return pair;
}
void MySwap( Card& a, Card& b ){
Card tmp = std::move(a);
a = std::move(b);
b = std::move(tmp);
}
void BubbleSort( std::vector<Card>& vec ){
int n = vec.size();
for( int i = 0; i < n; ++i ){
for( int j = n - 1; j > i; --j ){
if( vec[j].GetNumber() < vec[j-1].GetNumber() ){
MySwap( vec[j], vec[j-1] );
}
}
}
}
void SelectionSort( std::vector<Card>& vec ){
int n = vec.size();
int minj;
int j;
for( int i = 0; i < n; ++i ){
minj = i;
for( j = i; j < n; ++j ){
if( vec[j].GetNumber() < vec[minj].GetNumber() ){
minj = j;
}
}
if( i != minj ){
MySwap( vec[i], vec[minj] );
}
}
}
std::string CheckStable( std::vector<Card> initial, std::vector<Card> sorted ){
int N = sorted.size();
for( int i = 0; i < N; ++i ){
for( int j = i+1; j < N; ++j ){
for( int a = 0; a < N; ++a ){
for( int b = a+1; b < N; ++b ){
if( initial[i].GetNumber() == initial[j].GetNumber() &&
initial[i].GetString() == sorted[b].GetString() &&
initial[j].GetString() == sorted[a].GetString() ){
return "Not stable";
}
}
}
}
}
return "Stable";
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i ++)
int main(){
int n, q; cin >> n >> q;
vector <vector<int>> G(n + 1);
vector <int> point(n + 1);
rep(i, n - 1){
int a, b; cin >> a >> b;
G.at(a).push_back(b);
G.at(b).push_back(a);
}
rep(i, q){
int x, p; cin >> x >> p;
point.at(x) += p;
}
deque <int> d;
vector <long long> ans(n + 1, 0);
vector <int> seen(n + 1, -1);
d.push_back(1);
ans.at(1) += point.at(1);
seen.at(1) = 1;
while(!d.empty()){
int v = d.front();
d.pop_front();
int v_child_cnt = G.at(v).size();
for(int i = 0; i < v_child_cnt; i ++){
int next = G.at(v).at(i);
if(seen.at(next) != -1)continue;
ans.at(next) += point.at(next) + ans.at(v);
d.push_back(next);
seen.at(next) = 1;
}
}
for(int i = 1; i < n + 1; i ++){
cout << ans.at(i) << " ";
}
cout << endl;
} | 0 | 76,819,088 |
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;
void solve(){
}
int main (){
ios::sync_with_stdio(0);
cin.tie(0);
int n,m;
cin >> n >> m;
vector<int> a(n+2);
rep(i,m){
int q,w;
cin >> q >> w;
a[q]++,a[w+1]--;
}
int cnt=0;
rep(i,n){
a[i+1]=a[i]+a[i+1];
}
rep(i,n+1){
if(a[i]==m){
cnt++;
}
}
cout << cnt;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
int main(){
int N;
cin >> N;
vector<int> p(N);
for (int i = 0; i < N; i++) {
int a; cin >> a;
p[a-1] = i+1;
}
for (int i = 0; i < N; i++) {
if (i) cout << ' ';
cout << p[i];
}
cout << '\n';
} | 0 | 58,455,066 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE \
ifstream in("atcoder-problems/abc132_a.txt"); \
cin.rdbuf(in.rdbuf());
#define print_vec(v) \
rep(l, v.size()) { cout << v[l] << " "; } \
cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
cin.tie(0); \
ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18+100;
const int MOD = 1e9 + 7;
int main() {
INPUT_FILE CIN_OPTIMIZE;
set<char> c;
rep(i, 4) {
char x;
cin >> x;
c.insert(x);
}
cout << (c.size() == 2 ? "Yes" : "No") << endl;
} | #include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <bitset>
#include <cstdint>
#include <initializer_list>
using namespace std;
using namespace __gnu_pbds;
#define data_set(type) tree<type,null_type,less<type>,rb_tree_tag,tree_order_statistics_node_update>
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long int
#define ld long double
#define f(i,x,n) for(int i=x;i<=n;i++)
#define fe(x,v) for(auto &x :v)
#define nf(i,x,n) for(int i=n;i>=x;i--)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define ook(num) order_of_key(num)
#define fbo(num) find_by_order(num)
#define gcd(a,b) __gcd(a,b)
#define bits(n) __builtin_popcountll(n)
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define RE rend()
#define RB rbegin()
#define B begin()
#define E end()
#define acc(v, x) accumulate(all(v), x)
#define p(a,b) pair<a,b>
#define F first
#define S second
#define sz size()
#define v(x) vector<x>
#define m(a,b) map<a,b>
#define u_m(a,b) unordered_map<a,b>
#define mm(a,b) multimap<a,b>
#define s(a) set<a>
#define us(a) unordered_set<a>
#define ms(a) multiset<a>
#define maxy __LONG_LONG_MAX__
#define miny INT_MIN
#define PI 3.14159265358979323846
const int inf= 1e9 +1;
const int inf64= 1e18 -1;
const int MOD= 1e9 +7;
void Solve()
{
int a[]={8,7,6,5,4,3,2,1};
int n;
cin>>n;
n -=400;
cout<<a[n/200];
}
signed main()
{
speed
int q=1;
while(q--)
Solve();
return 0;
} | 0 | 52,972,046 |
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;
typedef long long ll;
int main(){
int N,M;
cin >> N >> M;
int a;
int b[N];
ll dp[N+1];
for(int i=0;i<N;i++){
b[i]=1;
dp[i]=0;
}
for(int i=0;i<M;i++){
cin >> a;
b[a]=0;
}
if(N>1){
dp[0]=b[0];
dp[1]=b[1];
for(int n=2;n<N+1;n++){
dp[n]=dp[n-1]*b[n-1]+dp[n-2]*b[n-2];
dp[n]=dp[n]%1000000007;
}
cout << dp[N] << endl;
}else cout << b[0] << endl;
} | #include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
int main() {
fast_io;
ll a,b,c,k;
cin>>a>>b>>c>>k;
ll ans=0;
if(k<=a) {
ans+=k;
cout<<ans<<endl;
return 0;
}
else {
k-=a;
ans+=a;
}
if(k<=b) {
cout<<ans<<endl;
return 0;
}
else {
k-=b;
}
if(k<=c) {
ans-=k;
cout<<ans<<endl;
return 0;
}
} | 0 | 91,490,577 |
#include <iostream>
#include <vector>
#include <map>
using namespace std;
int main(void) {
int N;
cin >> N;
vector<string> W(N);
map<string, int> S;
for(int i = 0; i < N; i++){
cin >> W[i];
}
for (int i = 0; i < N - 1; i++) {
if (W[i][W[i].size() - 1] != W[i + 1][0]) {
cout << "No" << endl;
return 0;
}
}
for (int i = 0; i < N; i++) {
S[W[i]]++;
if(S[W[i]] == 2){
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
return 0;
} | #define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>
#include <string>
#include <cstring>
#include <vector>
#include <bitset>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>
#include <ctime>
#define R(i,n) for(int i=0;i<(n);i=i+1)
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9;
using namespace::std;
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);
}
template<typename T>
void IN(vector<T> &A,int N=-1) {
if (N == -1) {
N = A.size();
}
for (int i = 0; i < N; ++i) {
cin >> A[i];
}
}
template<typename T>
void SO(vector<T> &A,bool F=false) {
sort(A.begin(), A.end());
if (F) {
reverse(A.begin(), A.end());
}
}
void solve() {
string S, T;
cin >> S >> T;
int N = S.size();
vector<int> SS(26, -1);
vector<int> TT(26, -1);
R(i, N) {
int s, t;
s = S[i] - 'a';
t = T[i] - 'a';
if (TT[t] == -1) {
TT[t] = s;
}
else if(TT[t]!=s){
cout << "No" << endl;
return;
}
if (SS[s] == -1) {
SS[s] = t;
}
else if (SS[s] != t) {
cout << "No" << endl;
return;
}
}
cout << "Yes" << endl;
}
signed main(void) {
std::cin.tie(0);
std::ios::sync_with_stdio(false);
std::cout << std::fixed;
cout << setprecision(16);
solve();
} | 0 | 2,040,536 |
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int judge(string t, string h)
{
int comp_num;
int ret_if_draw;
if (t.size() > h.size())
{
comp_num = h.size();
ret_if_draw = 1;
}
else if (t.size() < h.size())
{
comp_num = t.size();
ret_if_draw = -1;
}
else
{
comp_num = t.size();
ret_if_draw = 0;
}
transform(t.begin(), t.end(), t.begin(), ::tolower);
transform(h.begin(), h.end(), h.begin(), ::tolower);
for (int i = 0; i < comp_num; i++)
{
if (t[i] != h[i])
{
return (int)(t[i] - h[i]);
}
}
return ret_if_draw;
}
int main()
{
int n;
cin >> n;
string hand_t, hand_h;
int point_t = 0;
int point_h = 0;
int res;
for (int i = 0; i < n; i++)
{
cin >> hand_t >> hand_h;
res = judge(hand_t, hand_h);
if (res > 0)
{
point_t += 3;
}
else if (res < 0)
{
point_h += 3;
}
else
{
point_t++;
point_h++;
}
}
cout << point_t << " " << point_h << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
int64_t a = 2;
int64_t b = 1;
int64_t c = a + b;
if(N == 1){
cout << 1 << endl;
}else if(N == 2){
cout << 3 << endl;
}else{
for(int i = 0; i < N - 2; i++){
a = b;
b = c;
c = a + b;
}
cout << c << endl;
}
} | 0 | 69,894,744 |
#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>
using namespace std;
using ll=long long;
#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279;
int fact(int i) {
if (i == 0) return 1;
return (fact(i - 1)) * i;
}
int gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int lcm(int a, int b) {
return a * b / gcd(a, b);
}
int keta(int n) {
if (n == 0) return 1;
int count = 0;
while (n != 0) {
n /= 10;
count++;
}
return count;
}
int ketasum(int n) {
int sum = 0;
while (n != 0) {
sum += n % 10;
n /= 10;
}
return sum;
}
int main(void) {
int x;
cin>>x;
if(x<1200) cout<<"ABC"<<endl;
else cout<<"ARC"<<endl;
return 0;
} | #pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))
template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int r;
cin >> r;
if(r < 1200) cout << "ABC" << endl;
else if(r < 2800) cout << "ARC" << endl;
else cout << "AGC" << endl;
return 0;
} | 0 | 5,912,908 |
#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 h, w;
cin >> h >> w;
vector<string> s(h);
rep(i,h) cin >> s[i];
vector<vector<int>> cnt(h, vector<int>(w));
rep(i,h) {
vector<int> done(w);
rep(j,w) {
if (s[i][j] == '#') continue;
if (done[j]) continue;
int l = 0;
while (j+l < w) {
if (s[i][j+l] == '#') break;
l++;
}
rep(k,l) {
cnt[i][j+k] += l;
done[j+k] = 1;
}
}
}
rep(j,w) {
vector<int> done(h);
rep(i,h) {
if (s[i][j] == '#') continue;
if (done[i]) continue;
int l = 0;
while (i+l < h) {
if (s[i+l][j] == '#') break;
l++;
}
rep(k,l) {
cnt[i+k][j] += l;
done[i+k] = 1;
}
}
}
int ans = 0;
rep(i,h)rep(j,w) {
ans = max(ans, cnt[i][j]-1);
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main()
{
char b;
cin >> b;
if ('A' == b) {
cout << 'T' <<endl;
return 0;
}
if ('T' == b) {
cout << 'A' <<endl;
return 0;
}
if ('C' == b) {
cout << 'G' <<endl;
return 0;
}
if ('G' == b) {
cout << 'C' <<endl;
return 0;
}
return 0;
} | 0 | 79,837,458 |
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
#define INF 10e7
#define MOD 1000000000 + 7
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))
using namespace std;
void solve(void)
{
string s;
int k;
cin >> s >> k;
int cta = 0;
rep(i, min((int)s.length(), k)) if (s[i] == '1') cta++;
if (cta == k)
cout << 1 << endl;
else
{
rep(i, k)
{
if (s[i] != '1')
{
cout << s[i] << endl;
return;
}
}
}
}
int main(void)
{
solve();
} | #include<iostream>
int main(){
int n, count = 0;
bool isprime [1000000];
for(int i = 0; i < 1000000; i++)
isprime[i] = true;
isprime[0] = isprime[1] = false;
for(int i = 2; i <= 1000; i++){
if(isprime[i]){
for(int j = i * 2; j < 1000000; j += i){
isprime[j] = false;
}
}
}
while(std::cin >> n){
count = 0;
for(int i = 2; i <= n; i++){
if(isprime[i])
count++;
}
std::cout << count << std::endl;
}
} | 0 | 6,189,091 |
#include<iostream>
#include<algorithm>
using namespace std;
int main (void)
{
int a,x;
cin>>x>>a;
if(x<a)cout<<"0"<<endl;
else cout<<"10";
} | #include <bits/stdc++.h>
using namespace std;
struct UnionFind{
int num;
vector<int> rs,ps;
UnionFind(){}
UnionFind(int n) : num(n),rs(n,1),ps(n,0){iota(ps.begin(),ps.end(),0);}
int find(int x){
return ( x==ps[x] ? x: ps[x] = find(ps[x]));
}
bool same(int x, int y){
return find(x) == find(y);
}
void unite(int x, int y){
x = find(x);
y = find(y);
if(x == y) return;
if(rs[x] < rs[y]) swap(x,y);
rs[x] += rs[y];
ps[y] = x;
num--;
}
int size(int x){
return rs[find(x)];
}
int count() const{
return num;
}
};
int main(){
int N,M;
cin>>N>>M;
vector<int> p(N);
UnionFind U(N);
for(int i=0; i<N; i++){
cin>>p[i];
p[i]--;
}
for(int i=0; i<M; i++){
int x,y;
cin>>x>>y;
x--,y--;
U.unite(x,y);
}
int cnt = 0;
for(int i=0; i<N; i++){
if(U.same(p[i],i)) cnt++;
}
cout<<cnt<<endl;
return 0;
} | 0 | 100,246,227 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int A, B, K;
cin >> A >> B >> K;
for(int i=0; i<K; i++) {
if(i%2 ==0 && A%2 !=0) { A--; B += A/2; A /=2;}
else if(i%2 ==0 && A%2 ==0) { B += A/2; A /=2;}
else if(i%2 !=0 && B%2 !=0) { B--; A += B/2; B /=2;}
else if(i%2 !=0 && B%2 ==0) { A += B/2; B /=2;}
}
cout << A << " " << B << endl;
} | #include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using ll = unsigned long long int;
using namespace std;
int harshad(int n) {
int sum = 0;
while (n > 0) {
sum += n % 10;
n /= 10;
}
return sum;
}
int main() {
fastIO;
int x;
cin >> x;
if (x % harshad(x) == 0)
cout << "Yes";
else
cout << "No";
} | 0 | 57,100,302 |
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e8;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int dx[]={0,0,-1,1};
int dy[]={-1,1,0,0};
int n,m,a;
int solve(){
vector<int>x(a+1);
vector<int>y(a+1);
vector<vector<char> >in(n+2,vector<char>(m+2));
rep(i,n+2)rep(j,m+2){
if(!i||!j||i==n+1||j==m+1)in[i][j]='X';
else cin>>in[i][j];
if(in[i][j]=='S')in[i][j]='0';
if(isdigit(in[i][j])){
int d=in[i][j]-'0';
x[d]=i;y[d]=j;
}
}
int out=0;
rep(i,a){
vector<vector<int> >tmp(n+2,vector<int>(m+2));
vector<int>nx;
vector<int>ny;
rep(j,n+2)rep(k,m+2)tmp[j][k]=inf;
tmp[x[i]][y[i]]=0;
nx.pb(x[i]);
ny.pb(y[i]);
while(nx.size()){
if(nx[0]==x[i+1]&&ny[0]==y[i+1]){out+=tmp[nx[0]][ny[0]];break;}
rep(j,4){
if(in[nx[0]+dx[j]][ny[0]+dy[j]]!='X'&&tmp[nx[0]+dx[j]][ny[0]+dy[j]]>tmp[nx[0]][ny[0]]+1){
tmp[nx[0]+dx[j]][ny[0]+dy[j]]=tmp[nx[0]][ny[0]]+1;
nx.pb(nx[0]+dx[j]);
ny.pb(ny[0]+dy[j]);
}
}
nx.erase(nx.begin());
ny.erase(ny.begin());
}
}
return out;
}
int main(){
cin>>n>>m>>a;
cout<<solve()<<endl;
} | #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>
#include <ios>
#include <iomanip>
#include <numeric>
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;
int main() {
string b;
cin>>b;
string a = "";
for (int i = 0; i < b.size(); ++i) {
if(b[i] == 'A'){
a += 'T';
}else if(b[i] == 'T'){
a += 'A';
}else if(b[i] == 'C'){
a += 'G';
}else{
a += 'C';
}
}
cout<<a<<endl;
return 0;
} | 0 | 14,722,898 |
#include <bits/stdc++.h>
#define rep(i,n) for(long long i=0; i<n; i++)
#define Rep(i,n) for(long long i=1; i<n; i++)
#define ll long long
#include <math.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
#define PI acos(-1)
using P =pair<ll,ll>;
ll m=1000000007;
ll mod=1e9+7;
ll dp[2000+4];
int main()
{
ll n;
cin>>n;
ll sum=0;
Rep(i,n+1){
ll e=n/i;
sum+=(i+e*i)*e/2;
}
cout<<sum<<endl;
} | #include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N=5e5+50;
int gi(){
char ch=getchar(); int x=0,q=0;
while(ch<'0'||ch>'9') q=ch=='-'?1:q,ch=getchar();
while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
return q?-x:x;
}
int vis[N],d[N],head[N],nn[N][2],cnt=1,flag;
ll ans;
#define link(u,v) (nn[++cnt][1]=v,nn[cnt][0]=head[u],head[u]=cnt)
void dfs(int x,int op){
if (vis[x]){
if (op!=d[x]) flag=1;
return;
}
vis[x]=1,d[x]=op;
for (int i=head[x]; i; i=nn[i][0])
dfs(nn[i][1],op^1);
return;
}
int main(){
int n=gi(),m=gi(),u,v;
for (int i=1; i<=m; ++i)
u=gi(),v=gi(),link(u,v),link(v,u);
int a=0,b=0,c=0;
for (int i=1; i<=n; ++i)
if (!head[i]) ++a;
for (int i=1; i<=n; ++i)
if (head[i]&&!vis[i]){
flag=0,dfs(i,0);
if (flag) ++b;
else ++c;
}
cout<<2ll*a*n-1ll*a*a+1ll*b*b+2ll*c*(b+c);
return 0;
} | 0 | 29,169,808 |
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repe(i, n) for (int i = 0; i <= (n); ++i)
#define repe1(i, n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
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; }
typedef long long ll;
const int INF = 1e9;
const ll mod = 1000000007;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a * b / gcd(a, b);}
int main() {
int a,b,c;
cin >> a >> b >> c;
if (a==b && a==c && b==c) {
cout << "Yes" << "\n";
} else {
cout << "No" << "\n";
}
} | #include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
const double pi = 4 * atan(1.0);
int
main(int argc, const char *argv[])
{
int a, b, C;
cin >> a >> b >> C;
double S, L, h;
if (C == 90) {
S = a * b / 2;
L = a + b + sqrt(a*a + b*b);
h = b;
} else if (C < 90) {
h = b * sin(C / 180.0 * pi);
S = a * h / 2;
double x = b * cos(C / 180.0 * pi);
L = a + b + sqrt(h * h + (a - x) * (a - x));
} else {
h = b * sin((180 - C) / 180.0 * pi);
S = a * h / 2;
double x = b * cos((180 - C) / 180.0 * pi);
L = a + b + sqrt(h * h + (x + a) * (x + a));
}
printf("%.8lf\n%.8lf\n%.8lf\n", S, L, h);
return 0;
} | 0 | 10,456,011 |
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
int ans = 100000;
cin >> n;
while( n-- ) {
ans += ans / 100 * 5;
if( ans % 1000 > 0 ) {
ans = ans / 1000 * 1000;
ans += 1000;
}
}
cout << ans << endl;
} | #include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int s_num[26];
int p_num[26];
int main()
{
int i, j;
char c;
bool is=false;
string s, p, comp;
getline(cin, s);
getline(cin, p);
for (i = 0; i < s.size(); i++) {
j = i;
comp.clear();
while (comp.size()!=p.size()) {
comp += s[j];
if (j==s.size()-1) j=-1;
j++;
}
if (comp == p) {
is = true;
break;
} else {
is = false;
}
}
if (is) cout << "Yes\n";
else cout << "No\n";
} | 0 | 10,530,471 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ldbl;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for (typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,m,n) for (ll (i) = ((ll) m); (i) < ((ll) n); ++(i))
#define RFOR(i,m,n) for (ll (i) = ((ll) (m)-1); (i) >= ((ll) n); --(i))
#define REP(i,n) FOR(i,0,n)
#define TFOUT(b,t,f) cout << ((b)? (t) : (f)) << endl
const double PI = acos(-1.0);
const int MOD = (int)(1e9 + 7);
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x) cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
template<typename T>
inline vector<T> cin_vector(const size_t n) {
vector<T> vec;
vec.reserve(n);
REP(i, n) {
T element; cin >> element;
vec.push_back(element);
}
return vec;
}
template<typename T>
inline vector< vector<T> > cin_matrix(const size_t m, const size_t n) {
vector< vector<T> > matrix;
matrix.reserve(m);
REP(i, m) {
vector<T> vec = cin_vector<T>(n);
matrix.push_back(vec);
}
return matrix;
}
template<typename T>
inline void cout_vector(const vector<T>& vec) {
REP(i, SZ(vec)-1) {
cout << vec[i] << ' ';
}
cout << vec[SZ(vec)-1] << endl;
}
template<typename T>
inline void cout_matrix(vector< vector<T> > matrix) {
for(const vector<T>& vec : matrix) {
cout_vector<T>(vec);
}
}
int main() {
ll n, m; cin >> n >> m;
unordered_map<ll, ll> mod_map;
ll mod_sum = 0;
mod_map[0]++;
REP(i, n) {
ll e; cin >> e;
mod_sum = (mod_sum + e) % m;
mod_map[mod_sum]++;
}
ll ans = 0;
for (const auto& p : mod_map) {
ll c = p.second;
ans += (c-1) * c / 2;
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<int, int>;
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }
int x, y, z, k;
int main() {
cin >> x >> y >> z >> k;
vector<ll> A(x, 0);
vector<ll> B(y, 0);
vector<ll> C(z, 0);
for(int i = 0; i < x; ++i) cin >> A.at(i);
for(int i = 0; i < y; ++i) cin >> B.at(i);
for(int i = 0; i < z; ++i) cin >> C.at(i);
sort(A.begin(), A.end(), greater<ll>());
sort(B.begin(), B.end(), greater<ll>());
sort(C.begin(), C.end(), greater<ll>());
vector<ll> AB;
for(int i = 0; i < x; ++i) {
for(int j = 0; j < y; ++j) {
ll sum = A.at(i)+B.at(j);
AB.emplace_back(sum);
}
}
sort(AB.begin(), AB.end(), greater<ll>());
vector<ll> ABC;
for(int i = 0; i < min(x*y, 3000); ++i) {
for(int j = 0; j < z; ++j) {
ll sum = AB.at(i) + C.at(j);
ABC.emplace_back(sum);
}
}
sort(ABC.begin(), ABC.end(), greater<ll>());
for(int i = 0; i < k; ++i) {
cout << ABC.at(i) << endl;
}
} | 0 | 77,945,906 |
#include <cstdio>
#include <algorithm>
#include <stack>
using namespace std;
typedef pair<int, int> ii;
int main() {
int N;
scanf("%d", &N);
int A[N + 1];
A[0] = 0;
for (int i = 1; i <= N; ++i) scanf("%d", &A[i]);
int l = 1, u = N, m;
while (l != u) {
m = (l + u) / 2;
stack<ii> st;
bool can = true;
for (int i = 1; i <= N; ++i) {
if (A[i] > A[i - 1]) continue;
else if (m == 1) {
can = false;
break;
}
while (!st.empty() && st.top().first > A[i]) st.pop();
int lidx = A[i];
while (!st.empty() && st.top().first == lidx && st.top().second == m - 1) st.pop(), --lidx;
if (lidx == 0) {
can = false;
break;
} else if (!st.empty() && st.top().first == lidx) {
ii a = st.top();
++a.second;
st.pop();
st.push(a);
} else st.push(ii(lidx, 1));
}
if (can) u = m;
else l = m + 1;
}
printf("%d", l);
return 0;
} | #include <iostream>
#include <bits/stdc++.h>
#define ll long long
#define inf 100000000000000000
#define mod 1000000007
#define ld long double
#define point complex<long double>
#define pi acos(-1)
#define IO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
using namespace std;
int main(){
string s;
cin>>s;
ll resa=0;
ll resb=0;
for(int i=0;i<s.size();i++)
{
if(i%2==0)
{
if(s[i]=='0')resa++;
else resb++;
}
else
{
if(s[i]=='1')resa++;
else resb++;
}
}
cout<< min(s.size()-resa,s.size()-resb);
return 0;
} | 0 | 97,428,169 |
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef pair<int,int> P;
const int INF=1e9;
int main(){
int n,now=1,ans=0;
cin>>n;
vector<int> a(n);
rep(i,n) cin>>a[i];
for(int i=0;i<n;i++){
if(a[i]==now){
now++;
}
else ans++;
}
if(ans==n) cout<<"-1";
else cout<<ans;
} | #include <cstdlib>
#include <iostream>
using namespace std;
int cmp(int* a, int* b)
{
return (*a < *b) ? 1 : ((*a > *b) ? -1 : 0);
}
int main()
{
int dat[10];
for (int i = 0; i < 10; i++)
{
cin >> dat[i];
}
qsort(dat, 10, sizeof(int), reinterpret_cast<int(*) (const void*, const void*)>(cmp));
for (int i = 0; i < 3; i++)
{
cout << dat[i] << endl;
}
return 0;
} | 0 | 4,070,617 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD (1000000007)
#define INF (1e9)
#define INFL (1e18)
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template<class T>using arr=vector<vector<T>>;
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} pr(a[a.size()-1]);}
template<class T>void prarr(arr<T>& a){rep(i, a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int n;
arr<int> G;
vector<bool> seen;
arr<ll> dp;
void dfs(int s, int p){
seen[s] = true;
if(p != -1 && G[s].size()==1){
dp[s][0] = 1;
dp[s][1] = 1;
}else{
for(int i: G[s]){
if(seen[i]) continue;
dfs(i, s);
}
ll white = 1, black = 1;
for(int i: G[s]){
if(i==p) continue;
white *= (dp[i][0] + dp[i][1]);
white %= MOD;
black *= (dp[i][1]);
black %= MOD;
}
dp[s][0] = black;
dp[s][1] = white;
}
}
int main()
{
cin >> n;
G.resize(n);
rep(i, n-1){
int x, y; cin >> x >> y;
x--; y--;
G[x].push_back(y);
G[y].push_back(x);
}
dp.assign(n, vector<ll>(2, 1));
seen.assign(n, false);
dfs(0, -1);
pr((dp[0][0] + dp[0][1])%MOD);
return 0;} | #include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const long long INF = 1e9;
const long long MOD = 1e9+7;
using Graph = vector<vector<ll>>;
template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true;} return false;}
int main() {
std::cout << std::fixed << std::setprecision(15);
ll n, k;
cin >> n >> k;
string s; cin >> s;
vector<long long> vec(n);
for(long long i = 0; i < n; i ++){
vec[i] = (ll)(s[i] - 48);
}
vector<ll> vec2;
vector<ll> vec2_sum;
vec2_sum.push_back(0);
ll now = vec[0];
ll count = 0;
for(ll i = 0; i < n; i++){
if(vec[i] == now){
count++;
}else{
vec2.push_back(count);
vec2_sum.push_back(vec2_sum[vec2_sum.size() - 1] + count);
now = vec[i];
count = 1;
}
}
vec2.push_back(count);
vec2_sum.push_back(vec2_sum[vec2_sum.size() - 1] + count);
ll ans = 0;
if(vec[0] == 1){
if(vec2.size() / 2 <= k){
cout << n << endl;
return 0;
}
ll seq = (k * 2) + 1;
for(ll i = 0; i + seq < vec2_sum.size(); i+=2){
ans = max(ans, vec2_sum[i + seq] - vec2_sum[i]);
}
if(vec[n-1] == 0 && vec2_sum.size() - 1 - (k*2) >= 0){
ans = max(ans, vec2_sum[vec2_sum.size() - 1] - vec2_sum[vec2_sum.size() - 1 - (k*2)]);
}
}
if(vec[0] == 0){
if((vec2.size() + 1) / 2 <= k){
cout << n << endl;
return 0;
}
ll seq = (k * 2) + 1;
for(ll i = 1; i + seq < vec2_sum.size(); i+=2){
ans = max(ans, vec2_sum[i + seq] - vec2_sum[i]);
}
ans = max(ans, vec2_sum[k * 2] - vec2_sum[0]);
if(vec[n-1] == 0 && vec2_sum.size() - 1 - (k*2) >= 0){
ans = max(ans, vec2_sum[vec2_sum.size() - 1] - vec2_sum[vec2_sum.size() - 1 - (k*2)]);
}
}
cout << ans << endl;
} | 0 | 1,924,278 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a;
int n;
1<=n<=100;
0<=a<=n*n;
cin>>n;
cin>>a;
cout <<n*n-a<< endl;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (ll)(n); i++)
int main() {
ll n, h; cin >> n >> h;
vector <pair <ll, ll>> a(n, pair <ll, ll> ());
vector <pair <ll, ll>> b(n, pair <ll, ll> ());
rep(i, n) {
cin >> a.at(i).first >> b.at(i).first;
a.at(i).second = i; b.at(i).second = i;
}
sort(a.begin(), a.end());
sort(b.begin(), b.end());
ll tmp_a = a.at(n-1).first, tmp_loc = a.at(n-1).second, tmp_b;
rep(i, n) {
if (b.at(i).second == tmp_loc) {
tmp_b = b.at(i).first;
break;
}
}
ll res = 0;
for (ll i = n-1; i >= 0; i--) {
if (b.at(i).second != tmp_loc) {
if (b.at(i).first > tmp_a) {
h -= b.at(i).first;
res++;
}
}
if (h>0 && h-tmp_b<=0) {
h = 0;
res++;
}
if (h <= 0) break;
}
if (h > 0) {
h -= tmp_b;
res++;
if (h > 0) {
if (h%tmp_a) res += h/tmp_a+1;
else res += h/tmp_a;
}
}
cout << res << endl;
} | 0 | 95,819,040 |
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int INF = (int)1e9;
const ll inf = (ll)1e18;
const int mod = 1000000007;
const int MAX_N = 100010;
const double PI = acos(-1);
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
int n, c, k;
cin >> n >> c >> k;
vector<int> t(n);
rep(i, n) cin >> t[i];
sort(all(t));
int res = 0;
int i = 0;
while (i < n)
{
res++;
int start = i;
while (i < n
&& t[i] - t[start] <= k
&& i - start < c) {
i++;
}
}
out(res);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
const int INF=1e9+7;
const ll LINF=9223372036854775807;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld EPS = 1e-10;
int ii() { int x; if (scanf("%d", &x)==1) return x; else return 0; }
long long il() { long long x; if (scanf("%lld", &x)==1) return x; else return 0; }
string is() { string x; cin >> x; return x; }
char ic() { char x; cin >> x; return x; }
void oi(int x) { printf("%d ", x); }
void ol(long long x) { printf("%lld ", x); }
void od_nosp(double x) { printf("%.15f", x); }
void od(double x) { printf("%.15f ", x); }
void os(const string &s) { printf("%s ", s.c_str()); }
void oc(const char &c) { printf("%c ", c); }
#define o_map(v){cerr << #v << endl; for(const auto& xxx: v){cout << xxx.first << " " << xxx.second << "\n";}}
void br() { putchar('\n'); }
int lcm(int a, int b){return a / gcd(a, b) * b;}
#define begin_end(a) a.begin(),a.end()
#define REP(i,m,n) for(ll i=(ll)(m) ; i < (ll) (n) ; i++ )
#define rep(i,n) REP(i,0,n)
#define m_p(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define p_b push_back
#define SZ(x) ((int)(x).size)
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << " " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
int len = v.size();
for (int i = 0; i < len; ++i) {
s << v[i]; if (i < len - 1) s << " ";
}
return s;
}
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
int len = vv.size();
for (int i = 0; i < len; ++i) {
s << vv[i] << endl;
}
return s;
}
template<typename T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<typename T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}
vector<int> dx_4 = {1, 0, -1, 0};
vector<int> dy_4 = {0, 1, 0, -1};
int main(){
ll N = il();
ll X = il();
vector<pair<ll, ll> > sum_p;
sum_p.p_b(m_p(1, 1));
ll s = 1;
ll p = 1;
rep(i, 51){
if (i==0) continue;
s = s * 2 + 3;
p = p * 2 + 1;
sum_p.p_b(m_p(s, p));
}
ll ans = 0;
ll k = N;
while (0 < X){
if (X >= sum_p[k].first){
X -= sum_p[k].first;
ans += sum_p[k].second;
if (X==0) break;
else{
ans++;
X--;
}
}
else{
X--;
k--;
}
}
cout << ans << endl;
} | 0 | 76,885,505 |
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int mod = 1e9+7;
typedef pair<ll, ll> pairs;
typedef vector<pairs> p;
struct Edge{
ll to, weight;
Edge(ll t, ll w) : to(t), weight(w){}
};
using graph = vector<vector<ll>>;
using Graph = vector<vector<Edge>>;
ll gcd(ll a,ll b){
if(b == 0){
return a;
}else{
return gcd(b, a%b);
}
}
ll lcm(ll a, ll b){
return a / gcd(a, b) * b;
}
ll keta(ll N){
int tmp{};
while( N > 0 ){
tmp += ( N % 10 );
N /= 10;
}
N = tmp;
return N;
}
bool kai(string S){
bool flag = true;
for(ll i=0;i<S.size()/2;++i){
if(S[i] != S[S.size()-i-1]){
flag = false;
break;
}
}
return flag;
}
int main(){
ll x, y;
cin>>x>>y;
ll ans = 0;
if(x == y){
ans = 0;
}else if(x == -y){
ans += 1;
}else if(abs(x) > abs(y)){
ans += abs(x) - abs(y);
if(x > 0){
ans++;
}
if(y > 0){
ans++;
}
}else{
ans += abs(abs(x) - abs(y));
if(x < 0){
ans++;
}
if(y < 0){
ans++;
}
}
cout<<ans<<endl;
return 0;
} | #include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <list>
#include <iomanip>
#include <fstream>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
template<class T> inline T sqr(T x) { return x*x; }
typedef pair<int, int> P;
typedef long long ll;
typedef unsigned long long ull;
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define clr(a) memset((a), 0 ,sizeof(a))
#define mclr(a) memset((a), -1 ,sizeof(a))
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define sz(a) (sizeof(a))
#define Fill(a,v) fill((int*)a,(int*)(a+(sz(a)/sz(*(a)))),v)
bool cheak(int x, int y, int xMax, int yMax){ return x >= 0 && y >= 0 && xMax > x && yMax > y; }
const int dx[4] = { -1, 0, 1, 0 }, dy[4] = { 0, 1, 0, -1 };
const int mod = 1000000007;
const int INF = 2147483647;
int main()
{
int n;
cin >> n;
rep(_, n){
string s[2];
cin >> s[0] >> s[1];
int m = 0, c = 0, x = 0, i = 0;
rep(j, 2){
int t = 1;
rep(q, s[j].size()){
if (s[j][q] == 'm'){
m += t; t = 1;
}else
if (s[j][q] == 'c'){
c += t; t = 1;
}else
if (s[j][q] == 'x'){
x += t; t = 1;
}else
if (s[j][q] == 'i'){
i += t; t = 1;
}else{
t = s[j][q] - '0';
}
}
}
while (c >= 10 || x >= 10 || i >= 10){
m += c / 10; c -= c / 10 * 10;
c += x / 10; x -= x / 10 * 10;
x += i / 10; i -= i / 10 * 10;
}
stringstream ans;
if (m > 1){ ans << m; }
if (m){ ans << 'm'; }
if (c > 1){ ans << c; }
if (c){ ans << 'c'; }
if (x > 1){ ans << x; }
if (x){ ans << 'x'; }
if (i > 1){ ans << i; }
if (i){ ans << 'i'; }
cout << ans.str() << endl;
}
return 0;
} | 0 | 62,871,786 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int N,K;
cin>>N>>K;
vector<int>data(60);
for(int i=0;i<N;i++){
cin>>data.at(i);
}
sort(data.begin(),data.end());
reverse(data.begin(),data.end());
int count;
for(int i=0;i<K;i++){
count =count+data.at(i);
}
cout<<count<<endl;
} | #include<iostream>
using namespace std;
int main(){
double p[4][2];
while(cin>>p[0][0]>>p[0][1]){
for(int i=1; i<4; i++)
for(int j=0; j<2; j++)
cin >>p[i][j];
for(int i=1; i<4; i++)
for(int j=0; j<2; j++)
p[i][j]-=p[0][j];
double det,im[2][2],s[2];
det = p[1][0]*p[2][1]-p[1][1]*p[2][0];
im[0][0] = p[2][1]/det;
im[1][0] = -p[1][1]/det;
im[0][1] = -p[2][0]/det;
im[1][1] = p[1][0]/det;
for(int i=0; i<2; i++)
s[i] = im[i][0]*p[3][0]+im[i][1]*p[3][1];
if(s[0]>0 && s[1]>0 && s[0]+s[1]<1) cout <<"YES"<<endl;
else cout <<"NO"<<endl;
}
return 0;
} | 0 | 84,779,363 |
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;
int main(int argc, char const *argv[]) {
string s;std::cin >> s;
if(s.size()>=4&&s[0]=='Y'&&s[1]=='A'&&s[2]=='K'&&s[3]=='I') std::cout << "Yes" << '\n';
else std::cout << "No" << '\n';
} | #include <iostream>
#include <cmath>
using namespace std;
long long n;
int ans;
int main() {
cin >> n;
if(n == 1) {
cout << 0;
return 0;
}
long long x = sqrt(n);
for(long long i = 2; i < x; i++) {
int e = 0;
long long pow = i;
while(n%pow == 0) {
e++;
n /= pow;
pow *= i;
}
while(n%i == 0) n /= i;
ans += e;
if(n == 1) {
cout << ans;
return 0;
}
}
ans++;
cout << ans;
} | 0 | 69,920,020 |
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main() {
int n;
int c[500], s[500], f[500];
cin >> n;
for (int i = 0; i < n - 1; i++) {
cin >> c[i] >> s[i] >> f[i];
}
for (int i = 0; i < n - 1; i++) {
int now = 0;
for (int j = i; j < n - 1; j++) {
if (now <= s[j]) {
now = s[j] + c[j];
}
else {
int co1 = 0;
for (;;) {
co1 += f[j];
if (now - co1 <= s[j]) {
now = s[j] + c[j] + co1;
break;
}
}
}
}
cout << now << endl;
}
cout << "0" << endl;
return 0;
} | #define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
#define vec(s) vector<s>
#define vvec(s) vector<vector<s>>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes(x) cout<<(x?"Yes":"No")<<endl;
#define YES(x) cout<<(x?"YES":"NO")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " "
#define INF 10000000000
#define LINF 9000000000000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
for(lli i=0;i<v.size();i++)
cout<<v.at(i)<<endl;
}
int main(){
cout << std::fixed << std::setprecision(10);
lli l=0, r=0;
lli n;
cin>>n;
vi a(n);
rep(i,n){
cin>>a[i];
r+=a[i];
}
lli ans;
l=a[0];
r-=a[0];
ans=abs(l-r);
rep(i,n-1){
l+=a[i+1];
r-=a[i+1];
ans=min(ans, abs(l-r));
}
out(ans);
} | 0 | 69,312,969 |
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9;
using namespace std;
using ll = long long;
int main() {
int x , y;
cin >> x >> y;
int t = abs(abs(x)-abs(y));
if((x > 0 && y < 0) || (x < 0 && y > 0)){
t++;
}
else if((x == 0 || y == 0) && y < x){
t++;
}
else if (y < x){
t+=2;
}
cout << t << endl;
return 0;
} | #include<iostream>
#include<cctype>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
int main(){
string alpha;
int n;
string taro;
string hanako;
int ptaro = 0;
int phanako = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> taro >> hanako;
if(taro > hanako) {
ptaro += 3;
} else if(taro < hanako) {
phanako += 3;
} else {
ptaro += 1;
phanako += 1;
}
}
cout << ptaro << " " << phanako << endl;
return 0;
} | 0 | 70,764,659 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
int main(){
int n, i; cin >> n >> i;
cout << n-i+1 << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
long long N;
cin >> N;
long long ans = 0;
vector<long long> a(N);
for (int i=0; i<N; i++) {
cin >> a[i];
}
long long term = 0;
bool loop_end = false;
for (int jsndfjn = 0; jsndfjn <= 100000000000; jsndfjn++) {
loop_end = true;
term = 0;
for (int i=0; i<N; i++) {
if (a[i] >= N) {
term += (a[i] / N);
a[i] -= (N+1) * (a[i]/N);
loop_end = false;
}
}
cerr << term << endl;
if (loop_end) {
break;
}
ans += term;
for (int i=0; i<N; i++) {
a[i] += term;
}
}
cout << ans << endl;
return 0;
} | 0 | 43,553,309 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int main(){
int a;
cin >> a;
if(a<1200){
cout << "ABC" << endl;
}
else if(a<2800){
cout << "ARC" << endl;
}
else{
cout << "AGC" << endl;
}
} | #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cctype>
#include <iostream>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <iterator>
#include <cmath>
using namespace std;
const int mod = 1000000007;
int ipow(int x, int y)
{
if(y == 0)
return 1;
if(y % 2)
return 1LL * ipow(x, y - 1) * x % mod;
int t = ipow(x, y / 2);
return 1LL * t * t % mod;
}
int inv(int x)
{
return ipow(x, mod - 2);
}
int arr[100010];
int pos[100010];
int res[100010];
int fac[100010];
int caf[100010];
int ncr(int n, int r)
{
return 1LL * fac[n] * caf[r] % mod * caf[n - r] % mod;
}
int main()
{
int n, i;
scanf("%d", &n);
for(i = 1; i <= n + 1; i++)
scanf("%d", &arr[i]);
int x, y;
for(i = 1; i <= n + 1; i++)
{
if(!pos[arr[i]])
pos[arr[i]] = i;
else
{
x = pos[arr[i]];
y = i;
break;
}
}
fac[0] = 1;
for(i = 1; i <= n + 1; i++)
fac[i] = 1LL * fac[i - 1] * i % mod;
for(i = 0; i <= n + 1; i++)
caf[i] = inv(fac[i]);
int t = n + 1 - (y - x + 1);
for(i = 1; i <= n + 1; i++)
{
res[i] = ncr(n + 1, i);
if(1 <= i && i - 1 <= t)
res[i] = (res[i] - ncr(t, i - 1) + mod) % mod;
}
for(i = 1; i <= n + 1; i++)
printf("%d\n", res[i]);
return 0;
} | 0 | 74,846,815 |
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln = '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1001001001001001001;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int main(){
set<int> st;
rep(i, 3){
int a; cin >> a;
st.insert(a);
}
cout << st.size() << ln;
} | #include <bits/stdc++.h>
using namespace std;
int main () {
int N;
cin >> N;
vector<long long> a(N+1, 0);
for (int i = 1; i <= N; i++) {
cin >> a[i];
a[i] += a[i-1];
}
long long ans;
for (int i = 1; i+1 <= N; i++) {
long long x = a[i];
long long y = a[N]-a[i];
if (i == 1) {
ans = abs(x-y);
}
else {
ans = min(ans, abs(x-y));
}
}
cout << ans << endl;
} | 0 | 91,785,620 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int n,m,x;
cin >> n >> m >> x;
long long ans=99999999999999999;
vector<vector<int>> data(13,vector<int>(13));
for(int i=0;i<n;i++){
for(int j=0;j<=m;j++){
cin >> data.at(i).at(j);
}
}
bool over = true;
for(int bit=0;bit < (1<<n) ;bit++){
vector<long long> sum(14,0);
long long money=0;
over = true;
for(int i=0;i<n;i++){
if(bit & (1<<i)){
money += data.at(i).at(0);
for(int j=1;j<=m;j++){
sum[j-1] += data.at(i).at(j);
}
}
}
for(int i=0;i<m;i++){
if(sum[i]<x) over = false;
}
if(over) ans = min(ans,money);
}
if(ans==99999999999999999) cout << -1 << endl;
else cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
int n,k;
cin >> n >> k;
string s;
cin >> s;
vector<int>nums;
int now = 1;
int count = 0;
for(int i=0; i<n; i++){
if(s[i]==('0'+now)) count++;
else{
nums.push_back(count);
now = 1-now;
count = 1;
}
}
if(count != 0) nums.push_back(count);
if(nums.size()%2==0)nums.push_back(0);
int add = 2*k+1;
vector<int>sum(nums.size()+1);
for(int i=0; i<nums.size(); i++){
sum[i+1]=sum[i]+nums[i];
}
int ans =0;
for(int i=0; i<nums.size(); i+=2){
int left = i;
int right = min(i+add,(int)nums.size());
int tmp = sum[right]-sum[left];
ans = max(tmp,ans);
}
cout << ans << endl;
return 0;
} | 0 | 75,060,761 |
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b,d=0;
string c;
cin>>a>>c>>b;
if(c[0]=='+')
{
d=a+b;
}
else
{
d=a-b;
}
cout<<d<<endl;
return 0;
} | #include <iostream>
#include <cmath>
using namespace std;
#define ll long long
int res(ll n){
int ans =0;
for(int i=2;i<=sqrt(n);i++){
if(n%i==0){
int fac =0;
while(n%i==0){
n/=i;
fac++;
}
ans+=(sqrt(8*fac+1)-1)/2;
}
}
if(n>1) ans++;
return ans;
}
int main(){
ll n;
cin >> n;
cout << res(n) << endl;
} | 0 | 28,208,994 |
#include <bits/stdc++.h>
#define rep_n(_1, _2, _3, NAME,...) NAME
#define rep_2(i, n) for(int i = 0; i < (int)(n); ++i)
#define rep_3(i, initial, n) for(int i = (int)(initial); i < (int)(n); ++i)
#define repeat(...) rep_n(__VA_ARGS__, rep_3, rep_2, rep_1)(__VA_ARGS__)
#define rep_r_n(_1, _2, _3, NAME,...) NAME
#define rep_r_2(i, n) for(int i = (int)(n); i > 0; i--)
#define rep_r_3(i, initial, n) for(int i = (int)(initial); i > (int)(n); i--)
#define repeat_r(...) rep_r_n(__VA_ARGS__, rep_r_3, rep_r_2)(__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const double EPS = numeric_limits<double>::epsilon();
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main() {
int N;
cin >> N;
ll sum = 0;
vector<int> A(N, 0);
int b = 0;
repeat(i, N) {
int a = 0;
cin >> a;
sum += abs(a - b);
b = a;
A[i] = a;
}
sum += abs(b - 0);
ll result = 0;
int prev = 0;
int next = 0;
repeat(i, N) {
prev = (i == 0) ? 0 : A[i-1];
next = ((i+1) == N) ? 0 : A[i+1];
ll a = abs(prev - A[i]);
ll b = abs(A[i] - next);
ll c = abs(next - prev);
result = sum - (a + b) + c;
cout << result << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
#define f first
#define s second
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (int i = (b); i >= (a); i--)
#define R0F(i, a) ROF(i, 0, a-1)
#define trav(x, a) for (auto& x: a)
const int MX = 2e5+5;
const int MOD = 1e9+7;
const ll INF = 1061109567;
const ld EPS = 1e-9;
const ld PI = acos(-1);
int N;
vi adj[MX];
ll dp[2][MX];
void solve_dp(int u, int p) {
dp[0][u] = dp[1][u] = 1;
trav(v,adj[u]) if (v != p) {
solve_dp(v,u);
dp[0][u] = (dp[0][u]*(dp[0][v]+dp[1][v])%MOD)%MOD;
dp[1][u] = (dp[1][u]*dp[0][v])%MOD;
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> N;
F0R(i,N-1) {
int u,v; cin >> u >> v;
--u,--v;
adj[u].pb(v); adj[v].pb(u);
}
solve_dp(0,-1);
cout << (dp[0][0]+dp[1][0])%MOD << "\n";
} | 0 | 34,429,474 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
#define pb push_back
#define ff first
#define ss second
#define INF int(3e9)
#define BIG_INF ll(9e18)
#define SIZE 100001
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define len(v) int((v).size())
#define sqr(x) (x) * (x)
#define cube(x) (x) * (x) * (x)
#define filein freopen("input.txt", "r", stdin)
#define fileout freopen("output.txt", "w", stdout);
ll binpow(ll a, ll b, ll MOD = BIG_INF)
{
ll res = 1;
while(b)
{
if(b & 1)
res *= a;
a *= a;
b >>= 1;
a %= MOD;
res %= MOD;
}
return res % MOD;
}
const ll mod = 1e9 + 7;
int T = 1;
int n, m, k;
vector<int> g[SIZE], b[SIZE];
int p[SIZE];
int cnt[SIZE];
bool used[SIZE];
void dfs(int u, int P, int &kol)
{
used[u] = 1;
p[u] = P;
for(int v: g[u])
{
if(!used[v])
{
kol++;
dfs(v, P, kol);
}
}
}
void solve()
{
cin >> n >> k;
vector<ll> pref(n + 1, 0);
for(ll i = 1; i <= n; i++)
{
pref[i] = pref[i - 1] + i;
}
ll ans = 0;
for(int i = k; i <= n; i++)
{
ll x = pref[i - 1];
ll y = pref[n] - pref[n - i];
ans += y - x + 1;
ans %= mod;
}
cout << ans + 1;
return;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
while(T--)
{
solve();
}
return 0;
} | #include<bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int cnt = 0;
for(int i =1;i < n ;i++) {
int add = (n+i-1)/i -1;
cnt+=add;
}
cout << cnt;
return 0;
} | 0 | 76,820,804 |
#include <algorithm>
#include <iostream>
#include <cctype>
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)
const string YES = "Yes";
const string NO = "No";
void solve(ll A, ll B, string S) {
bool pred = all_of(begin(S), begin(S)+A, [](unsigned char c){return isdigit(c);}) && all_of(rbegin(S), rbegin(S)+B, [](unsigned char c){return isdigit(c);}) && S[A]=='-';
cout << (pred ? YES : NO) << endl;
}
int main() {
ll A;
cin >> A;
ll B;
cin >> B;
string S;
cin >> S;
solve(A, B, S);
return 0;
} | #include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;
using std::bitset;
#define rep(i,n) for(int i=0; i<(int)n; i++)
#define reps(i,s,e) for(int i=s; i<(int)e; i++)
#define coutd(i) cout << std::fixed << std::setprecision(i)
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll> pll;
template<class T>
using Set = std::set<T>;
template<class T, class U>
using Map = std::map<T, U>;
template<class T>
using Graph = vector<vector<T>>;
const int INT_BIG = 1<<28;
int main() {
int N;
cin >> N;
vll As(N);
vll Bs(N);
ll asum = 0;
ll bsum = 0;
rep(i, N) {
cin >> As[i];
asum += As[i];
}
rep(i, N) {
cin >> Bs[i];
bsum += Bs[i];
}
ll count = 0;
rep(i, N) {
if (As[i] < Bs[i]) count += std::ceil((Bs[i] - As[i])/2.0);
}
cout << ((count <= bsum - asum) ? "Yes" : "No") << endl;
} | 0 | 87,507,077 |
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>
using namespace std;
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (int64_t)(n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)
#define chmax(a, b) (a) = max(a, b)
#define chmin(a, b) (a) = min(a, b)
int main() {
string s;
cin >> s;
string result;
for (const char c : s) {
if (c == 'B') {
if (!result.empty()) {
result.pop_back();
}
} else {
result.push_back(c);
}
}
cout << result << endl;
return 0;
} | #include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define reps(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define repi(i, x) \
for (auto i = (x).begin(), i##_fin = (x).end(); i != i##_fin; i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
string solve(bool a) { return ((a) ? "Yes" : "No"); }
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int, int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long, long long> P;
typedef vector<P> VP;
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 <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
os << "(" << p.first << "," << p.second << ")";
return os;
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
os << "{";
rep(i, v.size()) {
if (i) os << ",";
os << v[i];
}
os << "}";
return os;
}
template <class T, class U>
istream& operator>>(istream& is, pair<T, U>& p) {
is >> p.first >> p.second;
return is;
}
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
rep(i, v.size()) { is >> v[i]; }
return is;
}
const long long INFLL = 1LL << 60;
const int INF = 1 << 30;
const double PI = acos(-1);
int main() {
int x, y, a, b, c;
cin >> x >> y >> a >> b >> c;
priority_queue<ll, vector<ll>, greater<ll>> p, q;
V r(c);
ll cnt;
ll ans = 0LL;
rep(i, a) {
cin >> cnt;
p.push(cnt);
};
rep(i, b) {
cin >> cnt;
q.push(cnt);
}
cin >> r;
sort(all(r));
while (p.size() > x) {
p.pop();
}
while (q.size() > y) {
q.pop();
}
clog << "A" << endl;
rep(i, c) {
if (q.top() > p.top()) {
p.push(r[i]);
p.pop();
} else {
q.push(r[i]);
q.pop();
}
}
clog << "A" << endl;
while (!q.empty()) {
ans += q.top();
q.pop();
}
while (!p.empty()) {
ans += p.top();
p.pop();
}
cout << ans << endl;
} | 0 | 90,239,250 |
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, a, b) for (int i = (a); i < (b); ++i)
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using tl = tuple<ll, ll, ll>;
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
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 INF = 1001001001;
ll LINF = 1001001001001001001ll;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll n; cin>>n;
vl as(n); cin>>as;
priority_queue<LP> q;
rep(i, n) q.push(LP(as[i], i));
ll h = q.top().fi;
ll cur = q.top().se;
ll cnt = 0;
map<ll, ll> mp;
while (!q.empty()) {
LP p = q.top(); q.pop();
mp[cur] += cnt * (h - p.fi);
cnt++;
chmin(cur, p.se);
h = p.fi;
}
mp[cur] += cnt * h;
rep(i, n) cout<<mp[i]<<endl;
} | #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <utility>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) loop(i,0,b)
#define each(e,c) for(auto&e:c)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#ifdef DEBUG
#define dump(...) (cerr<<#__VA_ARGS__<<" = "<<(DUMP(),__VA_ARGS__).str()<<" ["<<__LINE__<<"]"<<endl)
struct DUMP:ostringstream{template<class T>DUMP &operator,(const T&t){if(this->tellp())*this<<", ";*this<<t;return *this;}};
#else
#define dump(...)
#endif
int main(){
int n; cin>>n;
rep(_,n){
ll x[2][2], y[2][2];
rep(i,2){
rep(j,2){
double x_,y_;
cin >> x_ >> y_;
x[i][j] = x_*1000000;
y[i][j] = y_*1000000;
}
}
ll dx1=x[0][0]-x[0][1], dy1=y[0][0]-y[0][1];
ll dx2=x[1][0]-x[1][1], dy2=y[1][0]-y[1][1];
dump(dx1,dx2,dy1,dy2);
puts(dx1*dy2==dx2*dy1 ? "YES" : "NO");
}
} | 0 | 13,306,856 |
#include<iostream>
#include<vector>
#include<string>
#include<bitset>
#include<algorithm>
#include<map>
#include<queue>
#include<cmath>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int main() {
int h, w;
cin >> h >> w;
vector<vector<char>> grid(h,vector<char>(w));
queue<vector<int>> black;
vector<vector<int>> dist(h, vector<int>(w, -1));
rep(i, h)
rep(j, w) {
cin >> grid[i][j];
if (grid[i][j] == '#') {
black.push({ i, j });
dist[i][j] = 0;
}
}
int distance = 0;
while(black.size()){
int y = black.front()[0];
int x = black.front()[1];
black.pop();
distance = dist[y][x];
for(int i=0;i<4;i++){
int new_y = y + dy[i];
int new_x = x + dx[i];
if (new_y < 0 || new_y >= h || new_x < 0 || new_x >= w)
continue;
if (dist[new_y][new_x] == -1) {
dist[new_y][new_x] = distance + 1;
black.push({ new_y,new_x });
}
}
}
cout << distance << endl;
return 0;
} | #include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int prime[1000000];
int Prime_creat()
{
int i,j;
for(i=2;i<=1000000;i++)
{
if(prime[i])
{
for(j=i+i;j<=1000000;j+=i)
prime[j]=0;
}
}
}
int main()
{
int i,n,ans;
memset(prime,1,sizeof(prime));
Prime_creat();
while(scanf("%d",&n)!=EOF)
{
ans=0;
for(i=2;i<=n;i++)
{
if(prime[i])
ans++;
}
cout<<ans<<endl;
}
return 0;
} | 0 | 24,227,969 |
#include <bits/stdc++.h>
#define M_PI 3.14159265358979323846
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;
typedef tuple<ll, ll, ll, ll, ll> t5;
#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)
using namespace std;
static const ll INF = 1e15;
int main() {
int n;
cin >> n;
vector<double> vs(n);
vector<double> os(n);
rep(i, n) {
cin >> vs[i];
}
rep(i, n) {
cin >> os[i];
}
vector<int> visit;
rep(i, n) visit.push_back(i+1);
ll id1 = -1, id2 = -1;
ll index = 0;
do {
index++;
{
if (id1 < 0) {
bool ok = true;
rep(i, n) {
if (vs[i] != visit[i]) ok = false;
}
if (ok) {
id1 = index;
}
}
}
{
if (id2 < 0) {
bool ok = true;
rep(i, n) {
if (os[i] != visit[i]) ok = false;
}
if (ok) {
id2 = index;
}
}
}
} while (std::next_permutation(visit.begin(), visit.end()));
cout << abs(id2- id1) << endl;
return 0;
} | #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;
ld k;
cin>>len>>k;
vector<ld> arr(len);
for(auto &i:arr) cin>>i;
ld sum = accumulate(arr.begin(),arr.end(),0);
sort(arr.begin(),arr.end(),greater<ld>());
ll cnt = 0;
for(auto i:arr){
if(i >= (sum/(k*4))) cnt++;
}
(cnt >= k)? cout<<"Yes\n":cout<<"No\n";
}
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;
} | 0 | 14,194,936 |
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
int main() {
long long N;
cin >> N;
int m = INFINITY;
for(long long i=1; i<=sqrt(N)+1; i++) {
if(N%i==0) {
int x = max(log10(i)+1,log10(N/i)+1);
m = min(m,x);
}
else continue;
}
cout << m << endl;
} | #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 <numeric>
#include <cmath>
#include <iomanip>
#include "atcoder/all"
#define ll long long int
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
using namespace std;
using namespace atcoder;
int main(){
int n, q;
cin >> n >> q;
dsu tree(n);
while(q--){
int t, u, v;
cin >> t >> u >> v;
if(t){
if(tree.same(u,v)) cout << 1 << endl;
else cout << 0 << endl;
}else{
int a = tree.merge(u,v);
}
}
} | 0 | 8,574,793 |
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
using namespace std;
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;
int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};
static const double EPS = 1e-8;
int main(){
int player_num;
int winner_idx;
int cut_off_rate;
while(~scanf("%d %d %d",&player_num,&winner_idx,&cut_off_rate)){
if(player_num == 0) break;
int vote_num[101];
int carry = 0;
for(int i=1;i<=player_num;i++){
scanf("%d",vote_num + i);
carry += vote_num[i]*100;
}
carry *= (double)(100-cut_off_rate)/100.0 + EPS;
printf("%d\n",vote_num[winner_idx] == 0 ? 0 : carry/vote_num[winner_idx]);
}
} | #include <bits/stdc++.h>
#define pb emplace_back
#define ll long long
#define fi first
#define se second
#define mp make_pair
using namespace std;
typedef pair<int, int> pii;
const int N = int(2e5 + 7);
const int nAlpha = 'z' - 'a' + 1;
const int mod = int(1e9 + 7);
unordered_map<int, int> minf;
int f, sumxor, n;
string s;
int Get(int x) {
if(minf.count(x)) return minf[x];
return N;
}
void Update(int x, int f) {
if(minf.count(x)) minf[x] = min(minf[x], f);
else minf[x] = f;
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
#define Task "test"
if(fopen(Task".inp", "r")) {
freopen(Task".inp", "r", stdin);
freopen(Task".out", "w", stdout);
}
cin >> s; n = int(s.size());
s = ' ' + s; minf[0] = 0;
for(int i = 1; i <= n; ++i) {
s[i] -= 'a';
sumxor ^= (1 << s[i]);
f = min(Get(sumxor) + 1, f + 1);
for(int j = 0; j < nAlpha; ++j) f = min(f, Get(sumxor ^ (1 << j)) + 1);
Update(sumxor, f);
}
cout << f;
} | 0 | 74,344,711 |
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 1<<30
#define MOD 1000000007
#define mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef long long int LL;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp(pair<ll,ll>a,pair<ll,ll> b){
if(a.se!=b.se)
return a.se<b.se;
else
return a.fi<b.fi;
}
bool color[200001];
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int a,b,c;cin>>a>>b>>c;
if(a==b&&b==c){
cout<<"Yes"<<endl;
}
else cout<<"No"<<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 main() {
int n;
cin >> n;
vector<int> a(n+1), b(n);
ll count = 0;
rep(i,n+1) {
cin >> a[i];
count += a[i];
}
rep(i,n) cin >> b[i];
rep(i,n) {
if (a[i] >= b[i]) {
a[i] -= b[i];
b[i] = 0;
}
else {
b[i] -= a[i];
a[i] = 0;
if (a[i+1] >= b[i]) {
a[i+1] -= b[i];
b[i] = 0;
}
else {
b[i] -= a[i+1];
a[i+1] = 0;
}
}
}
ll count2 = 0;
rep(i,n+1) {
count2 += a[i];
}
cout << count - count2 << endl;
return 0;
} | 0 | 82,909,177 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef pair<int, int> P;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}
int main()
{
int n;
cin >> n;
vs s(n);
rep(i, n) cin >> s[i];
vvi cnt(n, vi(26));
rep(i, n) {
rep(j, s[i].size()) {
int c = s[i][j] - 'a';
cnt[i][c]++;
}
}
string ans = "";
rep(i, 26) {
int t = 114514;
rep(j, n) {
t = min(t, cnt[j][i]);
}
if(t == 0) continue;
rep(k, t) {
ans += char(i + 'a');
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define LL_HALFMAX 9223372036854775807 / 2
int main()
{
ll n,k;
cin >> n >> k;
vector<ll>a(n);
for(ll i = 0; i < n; i++)
{
cin >> a[i];
}
ll result = LL_HALFMAX;
ll addcost = 0;
for(ll bit = 0; bit <(1<<n); bit++)
{
ll cost = 0;
ll look = 0;
ll hmax = a[0] - 1;
for(ll i = 0; i < n; i++)
{
if(a[i] > hmax)
{
hmax = a[i];
look++;
}
else if(bit&(1<<i))
{
addcost = hmax - a[i] + 1;
look++;
hmax += 1;
cost += addcost;
}
}
if(look >= k)
{
result = min(result,cost);
}
}
cout << result << endl;
return 0;
} | 0 | 55,217,286 |
#include <iostream>
#include <cmath>
using namespace std;
inline bool is_right_triangle(int a, int b, int c){
return (a*a == b*b + c*c || b*b == a*a + c*c || c*c == a*a + b*b) ? true : false;
}
int main() {
ios::sync_with_stdio(false);
int n, a, b, c;
cin >> n;
for(int i=0; i<n; i++){
cin >> a >> b >> c;
if(is_right_triangle(a,b,c)) cout << "YES" << "\n";
else cout << "NO" << "\n";
}
} | #include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,n) for (int i=(n-1);i >= 0;i--)
#define all(v) v.begin(),v.end()
#define sz(v) (int)((v).size())
#define MAX(v) *max_element(all(v))
#define MIN(v) *min_element(all(v))
using namespace std; using ll = long long; using P = pair<int,int>;
using vl = vector<ll>; using vvl = vector<vl>;
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cout << H << " ";
debug_out(T...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
return os;
}
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
template<class T>bool chmax(T &a, const T &b) {if(a<b){a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if(b<a){a=b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll mod = 1000000007;
const int dx[8] = {1,0,-1,0,1,1,-1,-1}; const int dy[8] = {0,1,0,-1,1,1,-1,-1};
int main(){
cin.tie(0); ios::sync_with_stdio(false);
ll r,g,b,n;
IN(r,g,b,n);
ll ans = 0;
for(int i = 0;i*r <= n;i++){
for(int j = 0;j*g<=n;j++){
int v = n-i*r-j*g;
if(v>=0 && v%b==0) ans++;
}
}
cout << ans << endl;
} | 0 | 12,235,379 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string S;
cin >> S;
S = regex_replace(S, regex("9"), "x");
S = regex_replace(S, regex("1"), "9");
S = regex_replace(S, regex("x"), "1");
cout << S << "\n";
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5+5;
int n , k;
int ar[N];
int cnt[N];
int main(){
int dif = 0;
scanf("%d%d" , &n , &k);
for(int i = 1; i <= n; i++){
scanf("%d" , &ar[i]);
if(cnt[ar[i]] == 0)
dif ++;
cnt[ar[i]]++;
}
if(dif <= k){
puts("0");
return 0;
}
vector < int > all;
for(int i = 1; i <= n; i++){
if(cnt[ar[i]]){
all.push_back(cnt[ar[i]]);
cnt[ar[i]] = 0;
}
}
sort(all.begin() , all.end());
int ans = 0;
for(auto v : all){
ans += v;
dif--;
if(dif <= k)
break;
}
printf("%d\n" , ans);
} | 0 | 89,361,250 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i = (a); i < (int)(b); ++i)
#define endl "\n"
typedef long long ll;
const double pi=3.14159265358979323846;
int ctoi(const char c) {
if ('0' <= c && c <= '9') return (c - '0');
return -1;
}
vector<int> input(int n) {
vector<int> vec(n);
for (int i = 0; i < n; i++) {
cin >> vec.at(i);
}
return vec;
}
void output(vector<int> vec) {
for (int i = 0; i < int(vec.size()); i++) {
cout << vec[i] << " ";
}
return;
}
vector<vector<int>> input(int n, int m) {
vector<vector<int>> table(n, vector<int>(m));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> table. at(i).at(j);
}
}
return table;
}
void output(vector<vector<int>> table) {
for (int i = 0; i < int(table.size()); i++) {
for (int j = 0; j < int(table.at(0).size()); j++) {
cout << table.at(i).at(j) << " ";
}
cout << endl;
}
}
long long perm(int n, int r) {
if (n < r) {
cout << "error" << endl;
return 0;
}
long long perm = 1;
for (int i = n; i > n - r; i--) {
perm *= i;
}
return perm;
}
long long comb(int n, int r) {
if (n < r) {
cout << "error" << endl;
return 0;
}
long long comb = perm(n,r);
for (int i = r; i > 0; i--) {
comb /= i;
}
return comb;
}
long long homo(int n, int r) {
return comb(n + r - 1, n - 1);
}
long long fact(int n) {
long long fact = 1;
for (int i = n; i > 0; i--) {
fact *= i;
}
return fact;
}
int gcd(int a, int b){
if (a % b == 0){
return(b);
}else{
return(gcd(b, a % b));
}
}
int lcm(int a, int b) {
return a * b / gcd(a, b);
}
bool isprime(int n){
if (n < 2) return false;
else if (n == 2) return true;
else if (n % 2 == 0) return false;
for (int i = 3; i <= sqrt(n); i += 2){
if (n % i == 0){
return false;
}
}
return true;
}
vector<long long> 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;
}
vector<pair<long long, long long> > prime_factorize(long long N) {
vector<pair<long long, long long> > res;
for (long long a = 2; a * a <= N; ++a) {
if (N % a != 0) continue;
long long ex = 0;
while (N % a == 0) {
++ex;
N /= a;
}
res.push_back({a, ex});
}
if (N != 1) res.push_back({N, 1});
return res;
}
void sayYes(bool f) {
if (f) {
cout << "Yes" << endl;
}
else {
cout << "No" << endl;
}
}
void sayYES(bool f) {
if (f) {
cout << "YES" << endl;
}
else {
cout << "NO" << endl;
}
}
int main() {
int n;
cin >> n;
vector<int> d=input(n);
sort(d.begin(),d.end());
cout << d[n/2]-d[n/2-1] << endl;
} | #include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
LL a[101010], b[101010];
int main(){
int N;
scanf("%d", &N);
rep(i, N) scanf("%lld %lld", &a[i], &b[i]);
LL ans = 0;
repr(i, N - 1, 0){
LL o = a[i] + ans;
LL q = o / b[i];
LL r = o % b[i];
if(r) ans += (q + 1) * b[i] - o;
}
printf("%lld\n", ans);
return 0;
} | 0 | 10,233,434 |
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main() {
string s;
ll k;
cin >> s >> k;
ll n = s.size();
rep(i, min(k, n)) {
if (s[i] >= '2') {
cout << s[i] << endl;
return 0;
}
}
cout << '1' << endl;
return 0;
} | #include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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 namespace std;
int main(){
Init();
ll n, a, b; cin >> n >> a >> b;
vi cnt(3);
rep(i, n){
ll p; cin >> p;
if(p <= a) cnt[0]++;
else if(p >= b+1) cnt[2]++;
else cnt[1]++;
}
sort(all(cnt));
cout << cnt[0] << endl;
} | 0 | 66,300,927 |
#include <iostream>
using namespace std;
const int N_MAX = 100000;
long long gcd(long long a, long long b) {
if (a < 0) a = -a;
if (b < 0) b = -b;
while (a != 0) {
long long tmp = b % a;
b = a;
a = tmp;
}
return b;
}
long long lcm(long long a, long long b) {
return a / gcd(a, b) * b;
}
int factor2(long long x) {
int i = 0;
while (x % 2 == 0) {
x /= 2;
i++;
}
return i;
}
int main() {
long long n, m, a[N_MAX], f;
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> a[i];
a[i] /= 2;
if (i == 0) f = factor2(a[i]);
else if (f != factor2(a[i])) {
cout << 0 << endl;
return 0;
}
}
long long l = 1;
for (int i = 0; i < n; i++) {
l = lcm(l, a[i]);
if (l > m) {
cout << 0 << endl;
return 0;
}
}
long long ans = m / l / 2;
if ((m/l)%2 == 1) ans++;
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define LL long long
#define N 100005
#define MOD 1000000007
#define dd double
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b) for(int i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define F first
#define S second
void debug(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
int main() {
debug();
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int n,a,b,count=0;
cin>>n>>a>>b;
if(a==0){
cout<<0<<endl;
return 0;
}else{
count=((n/(a+b))*a);
if((n%(a+b))==0){
cout<<count<<endl;
return 0;
}else{
long long int x=(n%(a+b));
if(x>=a){
count+=a;
}else{
count+=x;
}
}
}
cout<<count<<endl;
return 0;
} | 0 | 53,528,202 |
#include <bits/stdc++.h>
#define sp ' '
#define nyan "(=^・ω・^=)"
#define mkp make_pair
#define intmax 2147483647
#define llmax 9223372036854775807
#define lP pair<ll,ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;
const int mod = 1000000007, mod998 = 998244353;
int N, A, t;
ll res;
int main() {
cin >> N;
cin >> res;
--N;
--res;
t = 2;
while (N--) {
cin >> A;
res += (A - 1) / t;
if (A == t)++t;
}
cout << res << endl;
return 0;
} | #include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
typedef long long int lint;
using namespace std;
int main() {
vector<string> s = {"NO", "YES"};
lint n;
cin >> n;
vector<lint> a(n + 1);
lint sum = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
}
a[n] = a[0];
lint num_op = sum / (n * (n + 1) / 2);
vector<lint> op(n, 0);
for (int i = 0; i < n; i++) {
int expect = a[i] + num_op;
if (a[i + 1] > expect || (a[i + 1] - expect) % n != 0) {
cout << s[0] << endl;
return 0;
} else {
op[i] = (expect - a[i + 1]) / n;
}
}
lint test = 0;
for (int i = 1; i <= n; i++) {
test += op[n - i] * i;
}
if (test == a[0]) {
cout << s[1] << endl;
} else {
cout << s[0] << endl;
}
return 0;
} | 0 | 58,580,495 |
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>
#define int64 long long
#define uint64 unsigned long long
#define PI 3.1415926535897932384626433832795
using namespace std;
int main()
{
int64 nn, sum = 0;
cin >> nn;
vector<int64> bb(nn - 1);
for(int64 ii = 0;ii < nn - 1;ii++)
{
cin >> bb[ii];
}
sum += bb[0];
for(int64 ii = 1;ii < nn - 1;ii++)
{
sum += min(bb[ii], bb[ii - 1]);
}
sum += bb[nn - 2];
cout << sum << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> ii;
#define fi first
#define se second
#define pb push_back
#define sqr(x) ((x) * (x))
const char *fin = "arc077_b.inp";
const char *fon = "arc077_b.out";
#define oo (int) (1e9+7)
#define maxn (int) (1e5+5)
int n, A, B;
int a[maxn], pos[maxn];
long long fact[maxn], inverse[maxn];
int getbit(int x, int y) {
return (x >> y) & 1;
}
long long power(long long a, int x) {
long long res = a;
int cnt = 0;
long long p = 1;
while ((p << 1) <= x) p <<= 1, ++cnt;
for(int i = cnt; i > 0; --i) {
res = (res * res) % oo;
if (getbit(x, i - 1) == 1) res = (res * a) % oo;
}
return res;
}
long long C(int n, int k) {
if (k > n) return 0;
long long tmp = (inverse[k] * inverse[n - k]) % oo;
return (fact[n] * tmp) % oo;
}
void sol() {
fact[0] = 1;
inverse[0] = 1;
for(int i = 1; i <= n + 1; ++i) {
fact[i] = (fact[i - 1] * i) % oo;
inverse[i] = power(fact[i], oo - 2);
}
for(int l = 1; l <= n + 1; ++l) {
long long res = C(n + 1, l);
long long sub = C(A + B, l - 1);
printf("%I64d\n", (res - sub + oo) % oo);
}
}
void inp() {
scanf("%d", &n);
for(int i = 1; i <= n + 1; ++i) {
scanf("%d", a + i);
if (pos[a[i]] != 0) B = n - i + 1, A = pos[a[i]] - 1;
else pos[a[i]] = i;
}
sol();
}
int main() {
inp();
return 0;
} | 0 | 18,529,165 |
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n)for(int i=0;i<(int)(n);i++)
#define PI 3.141592653589793
int main()
{
int a, b, c;
cin >> a >> b >> c;
int cnt = 3;
if (a == b && b == c)
cnt = 1;
else if (a == b || b == c || c == a)
cnt = 2;
else
cnt = 3;
cout << cnt << endl;
} | #include"bits/stdc++.h"
using namespace std;
using ll = int64_t;
int main() {
ll N;
cin >> N;
vector<ll> A(N), C(N + 1, 0);
for (ll i = 0; i < N; i++) {
cin >> A[i];
C[A[i]]++;
}
vector<ll> D(N + 1, 0);
for (ll i = 1; i <= N; i++) {
D[C[i]]++;
}
vector<ll> sum_D(N + 2, 0), sum_kD(N + 2, 0);
for (ll i = 0; i <= N; i++) {
sum_D[i + 1] = sum_D[i] + D[i];
sum_kD[i + 1] = sum_kD[i] + i * D[i];
}
vector<ll> f(N + 1);
for (ll X = 1; X <= N; X++) {
f[X] = (sum_kD[X + 1] + X * (sum_D[N + 1] - sum_D[X + 1])) / X;
}
for (ll K = 1; K <= N; K++) {
ll ok = 0, ng = N + 1;
while (ng - ok != 1) {
ll mid = (ok + ng) / 2;
(K <= f[mid] ? ok = mid : ng = mid);
}
cout << ok << endl;
}
} | 0 | 34,542,917 |
#include<iostream>
using namespace std;
int main()
{
int a[4][3][10] = {0};
int n, b, f, r, v;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> b >> f >> r >> v;
a[b-1][f-1][r-1] += v;
}
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 3; j++) {
for (int k = 0; k < 10; k++) {
cout << " " << a[i][j][k];
}
cout << "\n";
}
if(!(i == 3))
cout << "####################\n";
}
} | #include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;
#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define rep(i,N) for(int i=0;i<N;i++)
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int N,M,R;
cin>>N>>M>>R;
vector<int>r(R);
for(int i=0;i<R;i++)cin>>r[i];
vector<vector<int>>g(N,vector<int>(N,INT_MAX));
for(int i=0;i<N;i++)g[i][i]=0;
for(int i=0;i<M;i++){
int A,B,C;
cin>>A>>B>>C;
A--,B--;
g[A][B]=C;
g[B][A]=C;
}
for(int k=0;k<N;k++){
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
if(g[i][k]==INT_MAX||g[k][j]==INT_MAX)continue;
g[i][j]=min(g[i][j],g[i][k]+g[k][j]);
}
}
}
sort(rng(r));
int ans=INT_MAX;
do{
int res=0;
for(int i=0;i<R-1;i++){
res+=g[r[i]-1][r[i+1]-1];
}
ans=min(ans,res);
}while(next_permutation(rng(r)));
cout<<ans<<endl;
return 0;
} | 0 | 52,946,089 |
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
ll INF = (ll)pow(10, 15);
void dfs(vvl dist, vl r, vl &used, ll prev, ll depth, ll cost, ll &ans){
if(depth == used.size() - 1){
ans = min(ans, cost);
return;
}
rep(i, used.size()){
if(used[i] == 1) continue;
used[i] = 1;
dfs(dist, r, used, i, depth + 1, cost + dist[prev][r[i]], ans);
used[i] = 0;
}
}
int main(){
ll N, M, R;
cin >> N >> M >> R;
vl r(R);
rep(i, R) cin >> r[i];
ll A, B, C;
map<ll, vpll> G;
rep(i, M){
cin >> A >> B >> C;
G[A].push_back({B, C});
G[B].push_back({A, C});
}
vvl dist(R, vl(N + 1, INF));
rep(i, R){
dist[i][0] = 0;
dist[i][r[i]] = 0;
vl vis(N + 1, 0);
priority_queue<pll, vpll, greater<pll>> que;
que.push({0, r[i]});
while(!que.empty()){
pll top = que.top();
que.pop();
if(vis[top.second] == 1) continue;
vis[top.second] = 1;
for(auto x : G[top.second]){
if(dist[i][x.first] > top.first + x.second)
dist[i][x.first] = top.first + x.second;
que.push({dist[i][x.first], x.first});
}
}
}
ll ans = INF;
rep(i, R){
vl used(R, 0);
used[i] = 1;
dfs(dist, r, used, i, 0, 0, ans);
}
cout << ans << endl;
return 0;
} | #define TEMPLATE_USED
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(n);++i)
#define _repe3(i,a,b) for(ll i=(a);i<=(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).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>
using pq=priority_queue<T,vector<T>,greater<T>>;
void solve();
int main(){
cin.tie(0);
ios::sync_with_stdio(0);
solve();
}
void solve(){
ll n;cin>>n;
vl c(n-1),s(n-1),f(n-1);
rep(i,n-1)cin>>c[i]>>s[i]>>f[i];
rep(i,n-1){
ll t=0;
rep(j,i,n-1){
chmax(t,s[j]);
t=(t+f[j]-1)/f[j]*f[j];
t+=c[j];
}
cout<<t<<endl;
}
cout<<0<<endl;
} | 0 | 96,274,802 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> buttons(N);
for (int n = 0; n < N; n++) cin >> buttons.at(n);
int answer = 0;
int pushedButton = 0;
for (int n = 0; n < N; n++) {
answer++;
if (buttons.at(pushedButton) == 2) {
cout << answer << endl;
return 0;
} else {
pushedButton = buttons.at(pushedButton) - 1;
}
}
cout << -1 << endl;
} | #include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<ll,ll> P;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define EFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i, n) FOR(i,0,n)
#define INF 1e9
const int MOD = 998244353;
int main(void){
string org;
char op[3];
int res = 0;
cin >> org;
FOR(b,0,(1 << 3)){
res = org[0] - '0';
REP(i,3){
if((b >> i) & 1){
res += (org[i+1] - '0');
op[i] = '+';
}else{
res -= (org[i+1] - '0');
op[i] = '-';
}
}
if(res == 7) break;
}
cout << org[0] << op[0] << org[1] << op[1] << org[2] << op[2] << org[3] << "=7" << endl;
return 0;
} | 0 | 61,008,256 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N,Y,A=-1,B=-1,C=-1;
cin>>N>>Y;
Y/=1000;
for(int i=0;i<=N;i++){
for(int j=0;j+i<=N;j++){
if(i*5+j*10+N-i-j==Y){
A=j,B=i,C=N-i-j;
}
}
}
cout<<A<<" "<<B<<" "<<C<<endl;
} | #include<bits/stdc++.h>
using namespace std;
int main(){
int a;
while(true){
cin >> a;
if(a==0)break;
int k[a];
for(int i=0;i<a;i++)cin >> k[i];
sort(k,k+a);
int ans=10000000;
for(int i=0;i<a-1;i++){
if(k[i+1]-k[i]<ans)ans=k[i+1]-k[i];
}
cout << ans << endl;
}
} | 0 | 52,490,916 |
#define _USE_MATH_DEFINES
#include <cmath>
#include <iostream>
using namespace std;
int main()
{
unsigned int n;
cin >> n;
double a = 100000;
for (int i = 0; i < n; i++)
{
a *= 1.05;
a /= 1000;
a = ceil(a);
a *= 1000;
}
cout << (int)a << endl;
return 0;
} | #pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;
using vi = vector<int>;
constexpr char newl = '\n';
constexpr double eps = 1e-10;
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define show(x) cout << #x << " = " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define sz(x) (int)(x).size()
#define YesNo {cout<<"Yes";}else{cout<<"No";}
#define YESNO {cout<<"YES";}else{cout<<"NO";}
#define v(T) vector<T>
template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> bool lcmp(const pair<T, T>& l, const pair<T, T>& r) {
return l.first < r.first;
}
template<class T> istream& operator>>(istream& i, v(T)& v) {
F0R(j, sz(v)) i >> v[j];
return i;
}
template<class A, class B> istream& operator>>(istream& i, pair<A, B>& p) {
return i >> p.first >> p.second;
}
template<class A, class B, class C> istream& operator>>(istream& i, tuple<A, B, C>& t) {
return i >> get<0>(t) >> get<1>(t) >> get<2>(t);
}
template<class T> ostream& operator<<(ostream& o, const vector<T>& v) {
F0R(i, v.size()) {
o << v[i] << ' ';
}
o << newl;
return o;
}
template<class T1, class T2> ostream& operator<<(ostream& o, const map<T1, T2>& m) {
for (auto& p : m) {
o << p.first << ": " << p.second << newl;
}
o << newl;
return o;
}
#if 1
signed main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
int H, W;
cin >> H >> W;
v(string) s(H);
string a(W, '.');
F0R(i, H) {
cin >> s[i];
}
F0R(i, H) {
if (s[i] == a) {
s.erase(s.begin() + i);
i--; H--;
}
}
F0R(c, W) {
bool del = true;
F0R(r, H) {
if (s[r][c] != '.') {
del = false;
break;
}
}
if (del) {
F0R(r, H) {
s[r].erase(s[r].begin() + c);
}
c--; W--;
}
}
F0R(r, H) {
cout << s[r] << newl;
}
}
#endif | 0 | 66,655,209 |
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include <iomanip>
using namespace std;
int main(){
int n,m;
cin>>n>>m;
vector<int>a(1000000);
vector<int>b(1000000);
cin>>a[0]>>b[0];
for(int i=0;i<n;i++){
cin>>a[i+1];
}
for(int i=0;i<=n;i++){
a[i]+=100;
}
for(int i=0;i<m;i++){
cin>>b[i+1];
}
for(int i=0;i<=m;i++){
b[i]+=100;
}
sort(a.begin(),a.end(),greater<>());
sort(b.begin(),b.end(),greater<>());
if(a[0]>=b[m]){
cout<<"War"<<endl;
}
else{
cout<<"No War"<<endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<string> vs;
typedef pair<int, int> P;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << 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 n;
cin >> n;
vi a(n);
rep(i, n) cin >> a[i];
ll ans = 0, r = 0;
ll x = 0, sum = 0;
rep(l, n) {
while(r < n && ((x^a[r]) == (sum+a[r]))) {
x ^= a[r];
sum += a[r];
r++;
}
ans += (r-l);
if(l >= r) r++;
else {
x ^= a[l];
sum -= a[l];
}
}
cout << ans << endl;
return 0;
} | 0 | 4,383,416 |
#include <bits/stdc++.h>
int main()
{
int N;
scanf("%d", &N);
int sum{};
for (int i{1}; i <= N; i++)
{
sum += i;
if (sum >= N)
{
for (int j{1}; j <= i; j++)
if (j != sum - N)
printf("%d\n", j);
return 0;
}
}
return 0;
} | #include <iostream>
#include <queue>
#include <vector>
using namespace std;
#define MAX 1001
const char INF = '#';
const int MM = 10000000;
typedef pair<int,int> P;
int num,d[MAX][MAX],n,m;
int dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};
char field[MAX+1][MAX+1];
int bfs(int sy,int sx,int gy,int gx){
queue<P> que;
for(int i = 0 ; i < n ; i++){
for(int j = 0 ; j < m ; j++){
d[i][j] = MM;
}
}
que.push(P(sy,sx));
d[sy][sx] = 0;
while(que.size()){
P p = que.front(); que.pop();
if(p.first == gy && p.second == gx) break;
for(int i = 0 ; i < 4 ; i++){
int nx = p.first+dx[i];
int ny = p.second+dy[i];
if(0 <= nx && nx < n && 0 <= ny && ny < m && field[nx][ny] != 'X'
&&d[nx][ny] == MM){
que.push(P(nx,ny));
d[nx][ny] = d[p.first][p.second]+1;
}
}
}
return d[gy][gx];
}
int main(){
fill(field[0],field[MAX],INF);
cin >> n >> m >> num;
vector<P> v(num+1);
for(int i = 0 ; i < n ; i++){
for(int j = 0 ; j < m ; j++){
cin >> field[i][j];
if(field[i][j]=='S'){
v[0].first = i;
v[0].second = j;
}
if('0' <= field[i][j] && field[i][j] <= '9'){
v[field[i][j]-'0'].first = i;
v[field[i][j]-'0'].second = j;
}
}
}
int ans = 0;
for(int i = 1 ; i < num+1 ; i++){
ans += bfs(v[i-1].first,v[i-1].second,v[i].first,v[i].second);
}
cout << ans << endl;
return 0;
} | 0 | 83,115,410 |
#include<bits/stdc++.h>
using namespace std;
int main(){
string s;
cin >> s;
int ans = 0;
if(s == "RSR"){
cout<<1<<endl;
return 0;
}
for(int i=0;i<3;i++){
if(s[i] == 'R')ans++;
}
cout << ans << endl;
return 0;
} | #include <cstdio>
using namespace std;
int main() {
int n;
int i, j, k, m;
int counter;
while (scanf("%d", &n) != EOF) {
counter = 0;
for (i = 0; i < 10; i++) {
for (j = 0; j < 10; j++) {
for (k = 0; k < 10; k++) {
for (m = 0; m < 10; m++) {
if ((i + j + k + m) == n) counter++;
}
}
}
}
printf("%d\n", counter);
}
return 0;
} | 0 | 58,904,169 |
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
string s;
cin >> s;
int N = s.size();
int cnt = 0;
for (int i = 0; i < N; ++i) {
if ((s[i] + i) % 2 == 0) ++cnt;
}
cout << min(cnt, N - cnt) << endl;
return 0;
} | #include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
#define rep0(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll =vector<vvll>;
const double PI=3.14159265358979323846;
int main() {
cout << fixed << setprecision(5);
int n;cin>>n;
vector<double> x(n);
vector<string> u(n);
rep0(i,n){
cin>>x[i]>>u[i];
}
double sum=0;
rep0(i,n){
if(u[i]=="JPY"){
sum+=x[i];
}
else{
sum+=x[i]*380000;
}
}
cout << fixed << setprecision(5)<<sum<<endl;
} | 0 | 43,296,447 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,ll>pa;
const int N=2e5+100;
const int mod=1e9+7;
vector<pa>ve[N];
int n;
ll vis[N];
queue<pa>q;
void bfs(int k)
{
memset(vis,-1,sizeof vis);
vis[k]=0;
q.push(make_pair(k,0));
while(q.size()){
pa kk=q.front();q.pop();
for(auto v:ve[kk.first]){
if(vis[v.first]==-1){
q.push(v);
vis[v.first]=vis[kk.first]+v.second;
}
}
}
}
int main()
{
ios::sync_with_stdio(0);cin.tie(0);
cin>>n;
for(int i=1;i<n;i++){
int a,b,c;
cin>>a>>b>>c;
ve[a].push_back(make_pair(b,c));
ve[b].push_back(make_pair(a,c));
}
int qq,k;
cin>>qq>>k;
bfs(k);
while(qq--){
int x,y;
cin>>x>>y;
cout<<vis[x]+vis[y]<<endl;
}
return 0;
} | #include <iostream>
#include <algorithm>
using namespace std;
int selectionSort(int a[],int n){
int i,j,sw=0,minj;
for(i=0;i<n-1;++i){
minj=i;
for(j=i;j<n;++j)
if(a[j]<a[minj]) minj=j;
swap(a[i],a[minj]);
if(i!=minj) ++sw;
}
return sw;
}
int main(){
int n,a[100],i,sw;
cin>>n;
for(i=0;i<n;++i) cin>>a[i];
sw=selectionSort(a,n);
for(i=0;i<n;++i){
if(i>0) cout<<" ";
cout<<a[i];
}
cout<<endl<<sw<<endl;
return 0;
} | 0 | 20,656,938 |
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
ll a,b;
cin >> a >> b;
a %= 3;
b %= 3;
ll c = a + b;
c %= 3;
if(a*b*c == 0)cout << "Possible" << endl;
else cout << "Impossible" << endl;
} | #include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<(n);i++)
typedef long long ll;
ll gcd(ll a, ll b){
if(a<b) swap(a,b);
if(a%b == 0) return b;
else return gcd(b,a%b);
}
int main(){
int h,w,k,ans=0; cin >> h >> w >> k;
vector<string> c(h);
rep(i,h) cin >> c[i];
rep(is,1<<h)rep(js,1<<w){
int cnt = 0;
rep(i,h)rep(j,w){
if(is>>i&1) continue;
if(js>>j&1) continue;
if(c[i][j] == '#') cnt++;
}
if(cnt == k) ans++;
}
cout << ans << endl;
} | 0 | 98,885,221 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000001;
const float PI = 3.14;
const int mod = 1e9+7;
typedef long long LL;
typedef vector<int> vi;
typedef list<int> li;
typedef queue<int> qi;
typedef pair<int,int> ii;
typedef map<string,int> msi;
typedef vector<ii> vii;
typedef priority_queue< ii, vector<ii>, greater<ii> > pq;
vector<ii>::iterator iter;
#define print_list(x) for(it = (x).begin(); it != (x).end(); it++) {cout << *it << " ";}
#define print_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++) {cout << *it2 << " ";}
#define search_list(x) for(it = (x).begin(); it != (x).end(); it++)
#define search_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++);
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define mp(x, y) make_pair(x, y)
int main(int argc, char* argv[])
{ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int a, b;
cin >> a >> b;
cout << a - b + 1 << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
#define mod 1000000007
#define pi 3.141592653589793
ll gcd(ll a,ll b){
if(b>a) swap(a,b);
if(b==0) return a;
return gcd(b,a%b);
}
ll lcm(ll a,ll b){
ll g=gcd(a,b);
return a/g*b;
}
ll rep_jijo(ll n,ll x){
if(x==0) return 1;
if(x%2==0){
ll t=rep_jijo(n,x/2);
return t*t%mod;
}
return n*rep_jijo(n,x-1)%mod;
}
ll com(ll n,ll r){
ll x=1,y=1;
ll tmp=n;
while(tmp>=n-r+1){
x=x*tmp%mod;
tmp--;
}
while(r>0){
y=y*r%mod;
r--;
}
return x*rep_jijo(y,mod-2)%mod;
}
int main (){
ll n,m;
cin >> n >>m;
ll cc=m/2;
if(n>=cc) cout << cc <<endl;
else cout << (n+cc)/2 <<endl;
return 0;
} | 0 | 93,206,479 |
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAX_N = 1005;
int c[MAX_N][MAX_N];
int main()
{
string X,Y;
cin >> X;
cin >> Y;
for(int i=0;i<=X.length();i++){
c[i][0] = i;
}
for(int j=0;j<=Y.length();j++){
c[0][j] = j;
}
for(int i=1;i<=X.length();i++){
for(int j=1;j<=Y.length();j++){
int p,q,r;
if(X[i-1] == Y[j-1]){
p = c[i-1][j-1];
}else{
p = c[i-1][j-1] + 1;
}
q = c[i][j-1] + 1;
r = c[i-1][j] + 1;
c[i][j] = min(min(p,q),r);
}
}
cout << c[X.length()][Y.length()] << "\n";
} | #pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#include <fstream>
#include<string.h>
#include <algorithm>
#include<math.h>
#include<vector>
#include <queue>
#include <deque>
#define ll long long
#define M 1000000007
#define MM 998244353
#define INF 4e18
using namespace std;
typedef tree<ll, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_multiset;
ll prck(ll n)
{
ll f=1;
if(n==1)
f=0;
else if(n==2)
f=1;
else if(n%2==0)
f=0;
else
{
ll i;
for(i=3;(i*i<=n) && (f==1);i+=2)
{
if(n%i==0)
f=0;
}
}
return f;
}
int main()
{
std::ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll n,i,j,x,m;
cin>>n>>x>>m;
vector<ll> sm;
map<ll,ll> mp;
bool printed=false;
sm.push_back(0LL);
for(i=1;i<=n;i++)
{
sm.push_back(x);
if(i)sm[i]+=sm[i-1];
if(mp.count(x))
{
ll repeat=mp[x];
ll ans=sm[repeat-1];
ll pattern=sm[i-1]-sm[repeat-1];
ll block=i-1-repeat+1;
ans+=((n-repeat+1)/block)*pattern;
ll rem=(n-repeat+1)%block;
ans+=sm[repeat-1+rem]-sm[repeat-1];
cout<<ans<<"\n";
printed=true;
break;
}
else
{
mp[x]=i;
x=(x*x)%m;
}
}
if(!printed)cout<<sm[n]<<"\n";
return 0;
} | 0 | 60,420,588 |
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
const LL INF = 10000000000;
const int V = 110;
const int E = 10000;
LL d[V][V];
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
int v, e;
cin >> v >> e;
for(int i = 0; i < v; ++i){
for(int j = 0; j < v; ++j){
d[i][j] = INF;
}
d[i][i] = 0;
}
int a, b;
LL c;
for(int i = 0; i < e; ++i){
cin >> a >> b >> c;
d[a][b] = c;
}
for(int k = 0; k < v; ++k){
for(int i = 0; i < v; ++i){
for(int j = 0; j < v; ++j){
if(d[i][k] != INF && d[k][j] != INF)
d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}
}
}
for(int i = 0; i < v; ++i){
if(d[i][i] < 0){
cout << "NEGATIVE CYCLE" << endl;
return 0;
}
}
for(int i = 0; i < v; ++i){
for(int j = 0; j < v; ++j){
if(d[i][j] != INF)
cout << d[i][j];
else
cout << "INF";
if(j != v - 1)
cout << " ";
}
cout << endl;
}
return 0;
} | #include<iostream>
#include<queue>
#include<string>
#include<vector>
#include<math.h>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include<stack>
#include<sstream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<list>
#include<numeric>
typedef long long ll;
#define pi 3.14159265358979323846264338327950L
#define VI vector<int>
#define VLL vector<long long>
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
const ll MOD = 1e9 + 7;
using namespace std;
template<typename T>
T gcd(T a, T b) {
if (b == 0) return a;
return gcd(b, a % b);
}
template<typename T>
T lcm(T a, T b) {
ll g = gcd(a, b);
return a / g * b;
}
template<typename T>
T binarysearch(vector<T> A, T key) {
ll left = 0;ll right = 4;ll mid;
while (left < right) {
mid = (left + right) / 2;
if (key == A[mid]) return 1;
if (key > A[mid]) left = mid + 1;
else if (key < A[mid]) right = mid;
}
return 0;
}
template<typename T>
T finder(vector<T> vec, T number) {
auto itr = find(vec.begin(), vec.end(), number);
size_t index = distance(vec.begin(), itr);
if (index != vec.size()) {
return 1;
}
else {
return 0;
}
}
ll frac(ll n)
{
if (n == 0) {
return 1;
}
return (n * frac(n - 1)) % MOD;
}
template<typename T>
T keta(T a) {
ll kazu = 1;
while (1) {
if (a / 10 != 0) { a /= 10;kazu++; }
else break;
}
return kazu;
}
template<typename T>
bool IsPrime(T num)
{
if (num < 2) return false;
else if (num == 2) return true;
else if (num % 2 == 0) return false;
double sqrtNum = sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2)
{
if (num % i == 0)
{
return false;
}
}
return true;
}
template<typename T>
T nCr(ll n, T r) {
ll ans = 1;
for (int i = n; i > n - r; --i) {
ans = ans * i;
}
for (int i = 1; i < r + 1; ++i) {
ans = ans / i;
}
return ans;
}
int main() {
ll N;cin >> N;
ll ans = 0;
if (N % 2 != 0)ans += N * (N / 2);
else ans += N * ((N - 1) / 2) + (N / 2);
cout << ans << endl;
} | 0 | 69,275,839 |
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<stdio.h>
#include<locale.h>
#include<set>
#include<stack>
#include<queue>
using namespace std;
int prime[1000000]={};
int spf[10000001];
bool is_prime[1000001];
void sieve(int n)
{
int p=0;
for(int i=0; i<=n;i++){ is_prime[i]=true; spf[i]=i;}
is_prime[0]=is_prime[1]=false;
for(int i=2;i<=n;i++)
{
if(is_prime[i])
{
prime[p++]=i;
for(int j=2*i;j<=n;j+=i){ is_prime[j]=false; spf[j]=i;}
}
}
}
int main()
{
int x,ans=0;
scanf("%d",&x);
sieve(x);
for(int i=1;i<x;i++)
{
int rep=x-i,med=1,tet=0,mae=1;
if(rep==1){ans++; break;}
if(is_prime[rep]){med=2;}
else{
for(;;)
{
mae=spf[rep];
rep/=mae;
tet++;
if(mae!=spf[rep]){med=med*(tet+1);tet=0;}
if(rep==1){break;}
}
}
ans+=med;
}
printf("%d",ans);
} | #include <bits/stdc++.h>
using namespace std;
using VS = vector<string>; using LL = long long;
using VI = vector<int>; using VVI = vector<VI>;
using PII = pair<int, int>; using PLL = pair<LL, LL>;
using VL = vector<LL>; using VVL = vector<VL>;
#define ALL(a) begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x)
#endif
const int INF = 1e9; const LL LINF = 1e16;
const LL MOD = 1000000007; const double PI = acos(-1.0);
LL ans = 0LL;
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
LL H, W, N; cin >> H >> W >> N;
int DX[] = { 0, 0, 1, -1, 1, 1, -1, -1,0 }; int DY[] = { 1, -1, 0, 0, 1, -1, 1, -1,0 };
map<PII, int>Map;
FOR(i, 0, N) {
int y, x; cin >> y >> x;
y--, x--;
FOR(k, 0, 9) {
int ny = y + DY[k];
int nx = x + DX[k];
if (1 <= ny && ny < H - 1 && 1 <= nx && nx < W - 1) {
Map[PII(ny, nx)]++;
}
}
}
VL ans(10, 0);
const auto MM = Map;
for (auto m : MM) {
ans[m.second]++;
}
ans[0] = ((H - 2)*(W - 2) - accumulate(ALL(ans), 0LL));
FOR(i, 0, 10) {
cout << ans[i] << endl;
}
return 0;
} | 0 | 79,149,899 |
#pragma GCC optimize("Ofast")
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
#define FORA(i,I) for(const auto& i:I)
#define ALL(x) x.begin(),x.end()
#define SIZE(x) ll(x.size())
#define INF 1000000000000
#define MOD 1000000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
signed main(){
int a,b,c;
cin>>a>>b>>c;
rep(i,b+1){
if(a*i%b==c){
cout<<"YES"<<endl;
return 0;
}
}
cout<<"NO"<<endl;
return 0;
} | #include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0
using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define vvb vector<vb>
#define pii pair<int, int>
#define pli pair<ll, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
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) {
if (b == 0) return a;
else return gcd(b, a % b);
}
ll keta(ll n){
string s = to_string(n);
ll num = s.size();
return num;
}
const ll INF = 1LL << 60;
const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};
struct Edge{
int to;
int weight;
Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;
class UnionFind{
public:
vi Parent, diff_weight;
UnionFind(int n){
Parent = vi(n,-1);
diff_weight = vi(n,0);
}
int root(int a){
if(Parent[a] < 0) return a;
int r = root(Parent[a]);
diff_weight[a] += diff_weight[Parent[a]];
return Parent[a] = r;
}
int weight(int a){
root(a);
return diff_weight[a];
}
bool issame(int a, int b){
return root(a) == root(b);
}
int size(int a){
return -Parent[root(a)];
}
bool merge(int a, int b, int w = 0){
w += weight(a); w -= weight(b);
a = root(a);
b = root(b);
if(a == b) return false;
if(size(a) < size(b)) swap(a,b), w = -w;
Parent[a] += Parent[b];
Parent[b] = a;
diff_weight[b] = w;
return true;
}
int diff(int a, int b){
return weight(b) - weight(a);
}
};
vi MP(string s){
vi A(s.size()+1);
A[0] = -1;
int j = -1;
rep(i,s.size()) {
while(j >= 0 && s[i] != s[j]) j = A[j];
j++;
A[i+1] = j;
}
return A;
}
vi Manacher(string s){
vi R(s.size());
int i = 0, j = 0;
while(i < s.size()){
while(i-j >= 0 && i+j < s.size() && s[i-j] == s[i+j]) ++j;
R[i] = j;
int k = 1;
while(i-k >= 0 && i+k < s.size() && k+R[i-k] < j) R[i+k] = R[i-k], k++;
i += k; j -= k;
}
return R;
}
vi Z_algorithm(string &s){
vi Z(s.size());
Z[0] = s.size();
int i = 1, j = 0;
while(i < s.size()){
while(i+j < s.size() && s[j] == s[i+j]) j++;
Z[i] = j;
if(j == 0){++i; continue;}
int k = 1;
while(i+k < s.size() && k+Z[k] < j) Z[i+k] = Z[k], ++k;
i += k; j -= k;
}
return Z;
}
const int MAX = 1e6+1;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++){
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
long long COM(ll n, ll k){
if(n >= MAX){
ll tmp = 1;
rep(i,k){
tmp *= (n-i);
tmp %= MOD;
}
return tmp*finv[k]%MOD;
}
if (n < k) return 0;
if (n < 0 || k < 0) return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll POW(ll x, ll n){
ll ret = 1;
if(n < 0){
n *= -1;
x = inv[x];
}
while(0 < n){
if(n%2 == 0){
x = x*x%MOD;
n /= 2;
}
else{
ret = ret*x%MOD;
n--;
}
}
return ret;
}
int s1[5005][5005], s2[5005][5005];
bitset<5005> dp1, dp2;
int main(){
int n, K; cin >> n >> K;
vi a(n); rep(i,n) cin >> a[i];
dp1[0] = 1; s1[0][0] = 1;
rep(i,n){
dp1 |= (dp1 << a[i]);
rep(k,K){
s1[i+1][k+1] = s1[i+1][k] + dp1[k];
}
}
dp2[0] = 1; s2[n][0] = 1;
rrep(i,n){
dp2 |= (dp2 << a[i]);
rep(k,K) {
s2[i][k+1] = s2[i][k] + dp2[k];
}
}
int ans = n;
rep(i,n) {
if(a[i] >= K){
ans--;
continue;
}
rep(x,K) {
if(!(s1[i][x+1]-s1[i][x])) continue;
if(s2[i+1][K-x] - s2[i+1][max(K-a[i]-x,0)]){
ans--;
break;
}
}
}
cout << ans << endl;
} | 0 | 10,823,454 |
#include <stdio.h>
#include <string.h>
int main() {
int leng, x = 0, y = 0;
int counter = 0;
int a1 = 0;
int a2 = 0;
char str[105];
char str2[105];
char str3[105];
scanf("%d", &leng);
scanf("%s", str);
for(int j = leng/2; j < leng;j++){
str2[x] = str[j];
a1 += str2[x];
x++;
}
for(int i = 0;i < leng/2;i++){
str3[y] = str[i];
a2 += str3[y];
y++;
}
if(a1 == a2 && (a1 != 0 && a2!= 0)){
printf("Yes");
}else{
printf("No");
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1LL << 60;
const int MAX = 1000000010;
const ll MOD = 1000000007;
const double PI = acos(-1);
int main() {
int n; cin >> n;
vector<int> A(n);
for (int i = 0; i < n; i++) cin >> A[i];
if (n % 2 == 0) {
for (int i = n - 1; i >= 1; i = i - 2) {
cout << A[i] << " ";
}
for (int i = 0; i < n; i = i + 2) {
cout << A[i] << " ";
}
cout << endl;
} else {
for (int i = n - 1; i >= 0; i = i - 2) {
cout << A[i] << " ";
}
for (int i = 1; i < n; i = i + 2) {
cout << A[i] << " ";
}
cout << endl;
}
return 0;
} | 0 | 89,094,876 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;
int main(){
int n;
cin >> n;
multiset<int> S;
vector<pii> v(n);
for (int i = 0; i < n; ++i) {
int p;
cin >> p;
v[i] = pii(p, i);
}
sort(rall(v));
S.insert(-1);
S.insert(-1);
S.insert(n);
S.insert(n);
ll res = 0;
for (auto x : v) {
ll val = x.first;
int id = x.second;
auto itr = S.upper_bound(id);
int r1 = *itr;
itr++;
int r2 = *itr;
itr--; itr--;
int l1 = *itr;
itr--;
int l2 = *itr;
res += val * (r2 - r1) * (id - l1);
res += val * (r1 - id) * (l1 - l2);
S.insert(id);
}
cout << res << endl;
} | #include"bits/stdc++.h"
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;
int main() {
int n;
bool ans = true;
cin >> n;
string before, now;
set<string>dist;
cin >> before;
dist.insert(before);
rep(i, n-1) {
cin >> now;
if (dist.count(now)) {
ans = false;
break;
}
if (before.back() != now[0]) {
ans = false;
break;
}
dist.insert(now);
before = now;
}
if (ans) {
cout << "Yes" << endl;
}
else {
cout << "No" << endl;
}
return 0;
} | 0 | 70,028,511 |
#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>
using namespace std;
using ll=long long;
using ld=long double;
#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
#define ALL(x) (x).begin(), (x).end()
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279;
int fact(int i) {
if (i == 0) return 1;
return (fact(i - 1)) * i;
}
int gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int lcm(int a, int b) {
return a * b / gcd(a, b);
}
int keta(int n) {
if (n == 0) return 1;
int count = 0;
while (n != 0) {
n /= 10;
count++;
}
return count;
}
int ketasum(int n) {
int sum = 0;
while (n != 0) {
sum += n % 10;
n /= 10;
}
return sum;
}
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;
}
char toSmall(char c) {
return (c + 0x20);
}
char toLarge(char c) {
return (c - 0x20);
}
float myPower(int a, int n) {
float x = 1;
while (n > 0) {
if (n & 1) {
x *= a;
}
a *= a;
n >>= 1;
}
return x;
}
int main(void) {
int n;
cin >> n;
int N = n / 4 + 1;
rep(i, n) {
rep(j, n) {
if (i * 4 + j * 7 == n) {
cout << "Yes" << endl;
return 0;
}
}
}
cout << "No" << endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#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, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m; i >= n; --i)
#define ALL(v) (v).begin(),(v).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; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
ll n;cin >> n;
vector<ll> a(n);
REP(i,n){
cin >> a[i];
}
sort(ALL(a));
int ans=1;
ll sum=0;
REP(i,n-1){
sum+=a[i];
if(sum*2>=a[i+1]){
ans++;
}
else{
ans=1;
}
}
cout << ans << endl;
} | 0 | 5,675,930 |
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <functional>
#include <cmath>
#include <cstring>
#include <numeric>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <complex>
#include <list>
#include <cassert>
#include <deque>
#include <iomanip>
#define addf(T) [](T a, T b){return (a + b);}
#define minf(T) [](T a, T b){return min(a, b);}
#define maxf(T) [](T a, T b){return max(a, b);}
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define INF 2000000000
#define LLINF 2000000000000000000ll
#define sq(x) ((x)*(x))
using namespace std;
using ll = long long;
ll gcd(ll x, ll y) { return y ? gcd(y,x%y) : x;}
int main() {
ll n,m;
cin >> n >> m;
ll tempsum = 0;
vector<ll> mods;
mods.push_back(0);
rep(i,n){
ll ai ;
cin >> ai;
tempsum += ai;
mods.push_back(tempsum % m);
}
map<ll,ll> mp;
rep(i,mods.size()){
mp[mods[i]] = 0;
}
ll ans = 0;
rep(i,mods.size()){
mp[mods[i]] = mp[mods[i]] + 1;
ll c = mp[mods[i]];
ans = ans - (c-1)*(c-2)/2 + c*(c-1) / 2;
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main(){
int n; ll k;
cin>>n>>k;
map<int,ll>mp;
rep(i,n){
int a,b;
cin>>a>>b;
mp[a]+=b;
}
ll cnt=0;
for(auto&p:mp){
cnt+=p.second;
if(cnt>=k){
cout<<p.first<<endl;
return 0;
}
}
} | 0 | 8,293,947 |
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }
int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60
typedef long long ll;
map< ll, ll > prime_factor(ll n) {
map< ll, ll > ret;
for(ll i = 2; i * i <= n; i++) {
while(n % i == 0) {
ret[i]++;
n /= i;
}
}
if(n != 1) ret[n] = 1;
return ret;
}
int main() {
ll N;
cin >> N;
ll ans = 0;
if (N == 0) {
ans = 0;
}
else if(N%2 == 1)
ans = 0;
else {
ll denom = 10;
while(denom <= N) {
ans += N / denom;
denom *= 5;
}
}
cout << ans << endl;
return 0;
} | #include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
#include <complex>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;++i)
#define repi(i,n) for(ll i=n-1;i>=0;--i)
#define sll(n) scanf("%lld", &n);
#define slf(n) scanf("%lf", &n);
typedef long long ll;
typedef double lf;
static const ll max_n = 100010;
vector<ll> ants(max_n);
vector<ll> after(max_n);
vector<ll> ans(max_n);
vector<ll> directions(max_n);
ll N, M;
void Main(){
ll N, L, T, x, w;
sll(N);
sll(L);
sll(T);
ll id = -1;
rep(i, N){
sll(x);
sll(w);
ants[i] = x;
directions[i] = w;
if(w==1){
id = i;
}
}
if(id==-1){
rep(i,N){
cout << ((ants[i] - T) % L + L) % L << endl;
}
}else{
ll st_a = ants[id];
ll target_coord = (st_a + T) % L;
ll num = id;
rep(i, N){
if(directions[i]==1){
after[i] = (ants[i] + T) % L;
}else{
after[i] = ((ants[i] - T) % L + L) % L;
ll dist = (st_a - ants[i] + L) % L;
num += (T * 2 + dist)/ L;
num %= N;
}
}
sort(after.begin(), after.begin()+N);
ll id_dist = upper_bound(after.begin(), after.begin()+N, target_coord) - after.begin() -1;
for(ll i=id_dist;i<id_dist+N;i++, num++){
num %= N;
ans[num] = after[i%N];
}
rep(i,N){
printf("%lld\n", ans[i]);
}
}
}
int main(){
Main();
return 0;
} | 0 | 85,313,531 |
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using ll = long long int;
using vec = vector<int>;
using P = pair<int,int>;
const int INF = 1e9+7;
int main() {
int n, k;
cin >> n >> k;
vec a(n);
rep(i,n) {
cin >> a[i];
}
rep(ki,k) {
vec b(n);
rep(i,n) {
int l = max(0, i - a[i]);
int r = min(n, i + a[i] + 1);
b[l]++;
if (r < n) b[r]--;
}
bool f = true;
rep(i,n-1) {
b[i+1] += b[i];
}
if (a == b) break;
a = b;
}
rep(i,n) {
cout << a[i] << endl;
}
} | #include<bits/stdc++.h>
using namespace std;
#define fast() ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define test() ll t; cin>>t; while(t--)
#define lp0(i,begin,end) for(ll i=begin;i<end;i++)
#define lp1(i,begin,end) for(ll i=begin;i<=end;i++)
#define rlp(i,begin,end) for(ll i=end;i>=begin;i--)
#define prec(n) fixed<<setprecision(n)
#define initial(a,i) memset(a,i,sizeof(a))
#define pb push_back
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define F first
#define S second
#define all(a) (a).begin(),(a).end()
#define BPC(x) __builtin_popcountll(x)
#define gcd(a,b) __gcd(a,b)
ll gcd(ll a,ll b) {if (a==0) return b;return gcd(b%a,a);}
ll power(ll x,ll n)
{
ll result = 1;
while (n)
{
if (n & 1)
result = result * x;
n = n / 2;
x = x * x;
}
return result;
}
void solution(ll compte)
{
ll a,p;
cin >> a >>p;
cout << (a*3 + p)/2 << endl;
}
int main()
{
ll compte = 1;
solution(compte);
compte++;
return 0;
} | 0 | 36,951,434 |
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>
#include <random>
#include <complex>
#include <functional>
#include <tuple>
#include <new>
using namespace std;
#define EPS (1e-9)
#define INF (1e9)
#define MOD (ll)(1e9 + 7)
#define PI (acos(-1))
#define REP(i,a,n) for(int i=a;i<n;i++)
#define rep(i, n) REP(i,0,n)
#define allof(a) (a).begin(), (a).end()
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" ; "IMPOSSIBLE")
using ll = long long int;
ll gcd(ll a, ll b) {
if (a < b) swap(a, b);
if (b == 0) return a;
return gcd(b, a % b);
}
ll beki(ll a, ll b) {
ll tmp = 1;
rep(i, b) tmp *= a;
return tmp;
}
ll modPow(ll x, ll a) {
if (a == 1) return x;
if (a % 2) return (x * modPow(x, a - 1)) % MOD;
ll t = modPow(x, a / 2);
return ((t % MOD) * (t % MOD)) % MOD;
}
ll modInv(ll x) {
return modPow(x, MOD - 2);
}
int A, B;
int main() {
cin >> A >> B;
REP(i, 1, 10000 + 1) {
int a, b;
a = (float)i * 0.08f;
b = (float)i * 0.1f;
if (a == A && b == B) {
cout << i << endl;
return 0;
}
}
cout << -1 << endl;
} | #include<iostream>
using namespace std;
int main() {
int H,W;
int i,n,m;
while (1) {
cin>>H>>W;
if (H == 0 && W == 0) break;
for (n = 0; n < H; n++) {
for (m = 0; m < W; m++) {
cout << "#";
}
cout << endl;
}
cout << endl;
}
return 0;
} | 0 | 31,382,741 |
#include <iostream>
#include <algorithm>
#include <vector>
#include <climits>
#include <queue>
#include <list>
using namespace std;
static const int MAX = 10000;
static const int INFTY = 1 << 29;
vector<int> g[MAX];
list<int> out;
bool v[MAX];
int n;
int deg[MAX];
void bfs(int s)
{
queue<int> q;
q.push(s);
v[s] = true;
while (!q.empty()) {
int u = q.front(); q.pop();
out.push_back(u);
for (int i = 0; i < g[u].size(); i++) {
int w = g[u][i];
deg[w]--;
if (deg[w] == 0 && !v[w]) {
v[w] = true;
q.push(w);
}
}
}
}
void tsort()
{
for (int i = 0; i < n; i++) {
deg[i] = 0;
}
for (int u = 0; u < n; u++) {
for (int i = 0; i < g[u].size(); i++) {
int w = g[u][i];
deg[w]++;
}
}
for (int u = 0; u < n; u++) {
if (deg[u] == 0 && !v[u]) bfs(u);
}
for (list<int>::iterator it = out.begin(); it != out.end(); it++) {
cout << *it << endl;
}
}
int main()
{
int s, t, m;
cin >> n >> m;
for (int i = 0; i < n; i++) v[i] = false;
for (int i = 0; i < m; i++) {
cin >> s >> t;
g[s].push_back(t);
}
tsort();
return 0;
} | #include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
using namespace __gnu_pbds;
const ll Mod = (int)1e9;
ll CaseN=1;
ll fast_power(ll a,ll b,ll mod){
ll ans=1;
while(b>0){
if(b&1){
ans=(a*ans)%mod;
}
b=b>>1;
a=(a*a)%mod;
}
return ans;
}
ll nCr(ll n ,ll r)
{
ll p= n;
r = min(r,n-r);
ll a =1;
ll b=1;
while(r)
{
a = a*p;
b = b*r;
ll g = __gcd(a,b);
a = a/g;
b = b/g;
p--;
r--;
}
return a;
}
void solve()
{
ll w,h,n;
cin>>w>>h>>n;
ll x[n+4],y[n+4],a[n+4];
ll ans =0;
ll a1=0,a2=0,b1=w, b2 =h;
for(ll i=0;i<n;i++)
{
cin>>x[i]>>y[i]>>a[i];
if(a[i]==1)
{
a1=max(x[i],a1);
}
else if(a[i]==2)
{
b1 = min(x[i],b1);
}
else if(a[i]==3)
{
a2 = max(y[i],a2);
}
else
{
b2 = min(y[i],b2);
}
}
if(b1>a1 && b2>a2)
{
ans = (b1-a1)*(b2-a2) ;
}
cout<<ans<<endl;
CaseN++;
return ;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t=1;
while(t--)
{
solve();
}
} | 0 | 82,682,109 |
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
int main(){
int n;
cin>>n;
vector<int> a(n,0);
int min_cost=1001001;
for(int i=0;i<n;i++){
cin>>a[i];
}
for(int i=-100;i<=100;i++){
int cost=0;
for(int j=0;j<n;j++){
int re=i-a[j];
cost+=pow(re,2);
}
min_cost=min(min_cost,cost);
}
cout<<min_cost<<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;}
struct UnionFindTree{
vector<int>par,sz;
UnionFindTree(int n){
par.resize(n);
sz.resize(n);
for(int i=0;i<n;i++){
par[i]=i;
sz[i]=1;
}
}
int find(int x){
return x==par[x]?x:par[x]=find(par[x]);
}
void unite(int x,int y){
x=find(x);y=find(y);
if(x==y)return;
if(sz[x]<sz[y])swap(x,y);
sz[x]+=sz[y];
par[y]=x;
}
bool areSame(int x,int y){
return find(x)==find(y);
}
int size(int x){
return sz[find(x)];
}
};
int N,M;
int A[222222],B[222222];
vint G[111111];
int col[111111];
bool dfs(int v,int c){
col[v]=c;
for(auto u:G[v]){
if(col[u]!=-1){
if(col[u]==c)return false;
}
else if(!dfs(u,1-c))return false;
}
return true;
}
signed main(){
cin>>N>>M;
UnionFindTree uf(N);
rep(i,M){
cin>>A[i]>>B[i];
A[i]--;B[i]--;
G[A[i]].pb(B[i]);
G[B[i]].pb(A[i]);
uf.unite(A[i],B[i]);
}
memset(col,-1,sizeof(col));
int a=0,b=0,k=0;
rep(i,N){
if(uf.find(i)!=i)continue;
if(uf.size(i)==1)k++;
else{
if(dfs(i,0))b++;
else a++;
}
}
cout<<a*a+2*a*b+2*b*b+2*N*k-k*k<<endl;
return 0;
} | 0 | 16,800,419 |
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <ctype.h>
#include <math.h>
#include <stack>
#include <string>
#include <string.h>
using namespace std;
double PI = 3.1415926535897932;
long mod = 1000000007;
const long INF = (1<<30);
int main() {
int s;
cin >> s;
if(s == 25)
cout << "Christmas" << endl;
else if(s == 24)
cout << "Christmas Eve" << endl;
else if(s == 23)
cout << "Christmas Eve Eve" << endl;
else if(s == 22)
cout << "Christmas Eve Eve Eve" << endl;
} | #include <iostream>
#include <vector>
using namespace std;
int d[110][110],e[110][110] = {};
int main(){
int i,j,k,n,m; cin >> n >> m;
for(i=0;i<m;i++){
int a,b,c; cin >> a >> b >> c;
a--; b--;
e[a][b] = c; e[b][a] = c;
}
for(i=0;i<n;i++){
for(j=0;j<n;j++){
d[i][j] = 10000000;
}
}
for(i=0;i<n;i++){
for(j=0;j<n;j++){
if(e[i][j]!=0) d[i][j] = e[i][j];
}
}
for(i=0;i<n;i++){
for(j=0;j<n;j++){
for(k=0;k<n;k++){
d[j][k] = min(d[j][k],d[j][i] + d[i][k]);
}
}
}
int ans = 0;
for(i=0;i<n;i++){
for(j=0;j<n;j++){
if(e[i][j]>d[i][j]) ans++;
}
}
cout << ans/2 << endl;
} | 0 | 821,897 |