code1
stringlengths 54
12k
| code2
stringlengths 65
12k
| similar
int64 0
1
| __index_level_0__
int64 2
101M
|
---|---|---|---|
#include <iostream>
#include <vector>
int main() {
int n, m;
std::cin >> n >> m;
int odd = (m + 1) / 2;
int even = m / 2;
std::vector<int> a(m), b(m);
int p = 1;
for (int i = 0; i < odd; ++i)
a[i] = p++;
for (int i = odd; i-- > 0;)
b[i] = p++;
for (int i = 0; i < even; ++i)
a[odd + i] = p++;
++p;
for (int i = even; i-- > 0;)
b[odd + i] = p++;
for (int i = 0; i < m; ++i)
std::cout << a[i] << " " << b[i] << "\n";
} | #include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define mod2 998244353
#define PI 3.14159265
#define ll long long
#define ld long double
#define pi pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define sz size()
#define fi first
#define se second
#define lz length()
#define all(x) (x).begin(),(x).end()
#define scf(x) scanf("%lld",&x)
#define rep(i,n) for(ll i=0;i<n;i++)
const int INF = (int)1e9;
const ll IINF=1LL<<62;
const int maxn=10000005;
int divr[maxn];
void divisor()
{for(int i=2;i<sqrt(maxn);i++)
{
if(!divr[i])
{
for(int j=i*i;j<maxn;j+=i)if(!divr[j])divr[j]=i;
}
}
for(int i=1;i<maxn;i++)if(!divr[i])divr[i]=i;
}
ll calc(ll num,ll pr)
{
ll res=0LL;
ll t=pr;
while((num/t)>0)
{
res+=num/t;
t*=pr;
}
return res;
}
int main()
{
ll n;
cin>>n;
ll ct2=0,ct5=0;
ct2=calc(n/2,2LL);
ct5=calc(n/2,5LL);
if(n&1)
{
ll oct2=calc(n,2LL);
ll oct5=calc(n,5LL);
ll to2=max(0LL,oct2-ct2-n/2);
ll to5=max(0LL,oct5-ct5);
ll ans=min(to2,to5);
cout<<ans;
}
else{
ll ct10=min(ct2+n/2,ct5);
cout<<ct10;
}
} | 0 | 88,950,221 |
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cstring>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };
int MOD = 1000000007;
int main() {
int a, b, c; cin >> a >> b >> c;
cout << (a < b && b < c ? "Yes" : "No") << endl;
} | #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <math.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <string>
using namespace std;
#define rep(I,N) for(int I = 0; I < (int)(N); I++)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 30)
typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int main(void){
rep(i, 9){
rep(j, 9){
cout << i+1 << "x" << j+1 << "=" << (i+1)*(j+1) << endl;
}
}
return 0;
} | 0 | 74,412,605 |
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
long long int power(int a,int b)
{
if(b==0)
return 1;
long long int k=power(a,b/2);
if(b%2==0)
return ((k%M)*(k%M))%M;
else
return ((k%M)*(k%M)*(a%M))%M;
}
long long int fact(long long int n)
{
if(n==1 || n==0)
return 1;
else
return ((n%M)*(fact(n-1)%M))%M;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
string str;
cin>>str;
set<char> s;
for(int i=0;i<str.length();i++)
{
s.insert(str[i]);
}
if(s.size()==str.length())
cout<<"yes";
else
cout<<"no";
return 0;
} | #include <iostream>
#include <algorithm>
int main() {
long long int n, k;
std::cin >> n >> k;
long long int a[200010];
for (int i = 0; i < n; ++i)
std::cin >> a[i];
std::sort(a, a + n);
int cnt = std::max(0LL, n - k);
long long int ans = 0;
for (int i = 0; i < cnt; ++i)
ans += a[i];
std::cout << ans;
} | 0 | 5,076,961 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
int A = 1;
for (int i = 0; i < M; i++) {
A *= 2;
}
int B = 1900 * M + 100 * (N - M);
cout << A * B << endl;
} | #include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
ll n, d, a;
cin >> n >> d >> a;
vector < pair < ll, ll > > v;
for(int i = 0; i < n; i++){
ll x, h;
cin >> x >> h;
v.push_back({x, (h + a - 1) / a});
}
sort(v.begin(), v.end());
vector < ll > p(n + 2, 0);
ll bombs = 0, rt;
for(int i = 0; i < n; i++){
ll x = v[i].first, req = v[i].second;
req -= p[i];
if(req <= 0){
p[i + 1] += p[i];
continue;
}
bombs += req;
ll lo = i, hi = n - 1;
while(lo <= hi){
ll mid = (hi - lo) / 2 + lo;
if(v[mid].first <= x + 2 * d){
lo = mid + 1;
rt = mid;
}
else hi = mid - 1;
}
p[rt + 1] -= req;
p[i] += req;
p[i + 1] += p[i];
}
cout << bombs << endl;
} | 0 | 77,853,587 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 2000000010;
constexpr ll INF= 2000000000000000000;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int,int> P;
typedef pair<int,P> PP;
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
ll mod(ll val, ll M) {
ll res = val % M;
if(res < 0) {
res += M;
}
return res;
}
template<typename T>
T RS(T N, T P, T M){
if(P == 0) {
return 1;
}
if(P < 0) {
return 0;
}
if(P % 2 == 0){
ll t = RS(N, P/2, M);
if(M == -1) return t * t;
return t * t % M;
}
if(M == -1) {
return N * RS(N,P - 1,M);
}
return N * RS(N, P-1, M) % M;
}
int main() {
int N;
cin >> N;
vector<char> vec(2 * N);
for(int i = 0;i < 2 * N;i++) {
cin >> vec.at(i);
}
vector<int> cnt(2 * N);
int L = 1;
int R = 0;
for(int i = 0;i < 2 * N - 1;i++) {
if(vec.at(i) != vec.at(i + 1)) {
cnt.at(i + 1) = cnt.at(i);
}
else {
cnt.at(i + 1) = 1 - cnt.at(i);
}
if(cnt.at(i + 1) == 0) {
L++;
}
else {
R++;
}
}
bool cnt2 = true;
if(vec.at(0) == 'W' || vec.at(2 * N - 1) == 'W' || cnt.at(2 * N - 1) == 0 || L != R) {
cnt2 = false;
}
if(cnt2 == false) {
cout << 0 << endl;
}
else {
ll ret = 1;
ll Lcnt = 0;
for(int i = 0;i < 2 * N;i++) {
if(cnt.at(i) == 0) {
Lcnt++;
}
else {
ret *= Lcnt;
Lcnt--;
ret %= MOD;
}
}
ll cnt3 = 1;
for(ll i = 0;i < N;i++) {
cnt3 *= i + 1;
cnt3 %= MOD;
}
cout << ret * cnt3 % MOD << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
int H, W;
char s[50][50];
int check(int x, int y){
bool k=false;
if(x>0 && s[x-1][y]==1){
k=true;
s[x-1][y]=0;
check(x-1, y);
}
if(y<W && s[x][y+1]==1){
k=true;
s[x][y+1]=0;
check(x, y+1);
}
if(x<H && s[x+1][y]==1){
k=true;
s[x+1][y]=0;
check(x+1, y);
}
if(y>0 && s[x][y-1]==1){
k=true;
s[x][y-1]=0;
check(x, y-1);
}
s[x][y]=-1;
return k;
}
int main() {
cin >> H >> W;
for(int i=0 ; i<H ; i++){
string str;
cin >> str;
for(int j=0 ; j<W ; j++){
if(str[j]=='.')
s[i][j]=-1;
else
s[i][j]=1;
}
}
for(int i=0 ; i<H ;i++)
for(int j=0 ; j<W ; j++)
if(s[i][j]==1)
if(!check(i, j)){
cout << "No" << endl;
return 0;
}
cout << "Yes" << endl;
} | 0 | 59,879,117 |
#include <iostream>
using namespace std;
int main() {
char input;
cin >> input;
if (islower(input)) {
cout << "a";
} else {
cout << "A";
}
} | #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int ul;
typedef unsigned long long ull;
typedef vector <int> vi;
typedef map<string,string> mss;
typedef map<int, vector<int> > mvii;
typedef map<int, int> mii;
typedef queue <int> qi;
typedef map <int, vector<string> > mvis;
typedef map <string, vector<int> > mvsi;
typedef vector <string> vs;
typedef pair <int, int> pii;
typedef vector<pair<int,int> > vpii;
#define MP make_pair
#define SORT(a) sort (a.begin(), a.end())
#define REVERSE(a) reverse (a.begin(), a.end())
#define ALL(a) a.begin(), a.end()
#define PI acos(-1)
#define ms(x,y) memset (x, y, sizeof (x))
#define INF 2000000000
#define pb push_back
#define MAX 100002
#define debug cout<<"A"<<"\n"
#define prnt(a) cout<<a<<"\n"
#define mod 1000000007LL
#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 itrALL(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define lc ((node)<<1)
#define rc ((node)<<1|1)
#define VecPrnt(v) FOR(J,0,v.size()) cout<<v[J]<<" "; cout<<endl
#define endl "\n"
#define PrintPair(x) cout<<x.first<<" "<<x.second<<endl
#define ClearQ(x); while(!x.empty()) x.pop()
#define EPS 1e-9
#define ArrPrint(a,st,en) for(int J=st; J<=en; J++) cout<<a[J]<<" "; cout<<endl;
template <class T> inline T bigmod(T p,T e,T M)
{
ll ret = 1;
for(; e > 0; e >>= 1)
{
if(e & 1) ret = (ret * p) % M;
p = (p * p) % M;
} return (T)ret;
}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}
template <class T> inline T lcm(T a,T b) {a=abs(a);b=abs(b); return (a/gcd(a,b))*b;}
template <class T, class X> inline bool getbit(T a, X i) { T t=1; return ((a&(t<<i))>0);}
template <class T, class X> inline T setbit(T a, X i) { T t=1;return (a|(t<<i)); }
template <class T, class X> inline T resetbit(T a, X i) { T t=1;return (a&(~(t<<i)));}
inline ll getnum()
{
char c = getchar();
ll num,sign=1;
for(;c<'0'||c>'9';c=getchar())if(c=='-')sign=-1;
for(num=0;c>='0'&&c<='9';)
{
c-='0';
num = num*10+c;
c=getchar();
}
return num*sign;
}
inline ll power(ll a, ll b)
{
ll multiply=1;
FOR(i,0,b)
{
multiply*=a;
}
return multiply;
}
int n; vi graph[MAX];
int dfs(int u, int p)
{
int ret=0;
for(auto v: graph[u])
{
if(v==p) continue;
ret^=(dfs(v,u)+1);
}
return ret;
}
int main()
{
ios_base::sync_with_stdio(0);
int test, cases=1;
cin>>n;
int u, v;
FOR(i,0,n-1)
{
cin>>u>>v;
graph[u].pb(v);
graph[v].pb(u);
}
if(dfs(1,0)) prnt("Alice");
else prnt("Bob");
return 0;
} | 0 | 41,359,004 |
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include<chrono>
using namespace std;
using namespace std::chrono;
using namespace __gnu_pbds;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define fi first
#define se second
#define int long long
#define pb push_back
#define emp emplace_back
#define vv(x) vector<x>
#define mp(x,y) map<x,y>
#define dq(x) deque<x>
#define pql(x) priority_queue<x>
#define pqs(x) priority_queue<x,vv(x),greater<x> >
#define M 998244353
#define forf(i,a,b) for(int i=a;i<b;i++)
#define it(x) x::iterator
#define ll long long
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
#define vii vector<int>
#define big 1e18
#define sm -1e9
#define mkr make_pair
#define vpi vector<pair<int,int> >
#define pii pair<int,int>
#define rng 500005
#define sz(x) (int)x.size()
#define rv(x) reverse(x.begin(),x.end())
#define out(x) cout<<x.fi<<" "<<x.se<<endl;
#define ordered_set tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update>
void pr_init()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
vector<vector<char> >vmt;
vector<vii> dp;
void solve()
{
int h,w;
cin >> h >> w;
vmt.assign(h,vector<char>(w,'a'));
dp.assign(h,vii(w,0));
forf(i,0,h)
{
forf(j,0,w) cin >> vmt[i][j];
}
if(vmt[h-1][w-1]=='.') dp[h-1][w-1]=0;
else dp[h-1][w-1]=1;
for(int i=1;i < h+w ;i++)
{
for(int j=0;j<h;j++)
{
for(int k=0;k<w;k++)
{
if(abs(h-1-j)+abs(w-1-k) == i)
{
int vl = big;
if(k+1<w)
{
if(vmt[j][k]=='.' || vmt[j][k+1]=='#') vl = min(vl,dp[j][k+1]);
else vl = min(vl,dp[j][k+1]+1);
}
if(j+1<h)
{
if(vmt[j][k]=='.' || vmt[j+1][k]=='#') vl = min(vl,dp[j+1][k]);
else vl = min(vl,dp[j+1][k]+1);
}
dp[j][k] = vl;
}
}
}
}
cout<<dp[0][0]<<endl;
}
int32_t main()
{
fastio;
auto start = high_resolution_clock::now();
solve();
auto stop = high_resolution_clock::now();
auto duration = duration_cast<microseconds>(stop - start);
} | #include<bits/stdc++.h>
#define ll long long
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
using namespace std;
ll divisor(ll n)
{
ll i,cnt=0,lim=sqrt(n);
for(i=1; i<=lim; i++)
{
if(n%i==0)
{
if(n/i==i)
cnt++;
else
cnt+=2;
}
}
return cnt;
}
int main()
{
fast_io
ll i,j,n,ans=0;
cin>>n;
for(i=1; i<=n; i+=2)
{
ll x=divisor(i);
if(x==8){
ans++;
}
}
cout<<ans<<endl;
return 0;
} | 0 | 32,645,077 |
#include <bits/stdc++.h>
using namespace std;
int main()
{
long long int h,w,a,b;
cin>>h>>w;
if(w==1 || h==1)
{
cout<<1<<endl;
return 0;
}
else if(w%2==0)
{
a=h*(w/2);
}
else
{
if(h%2==0)
{
a=(h*w)/2;
}
else
{
b=((w-1)/2)+1;
a=b+(((h-1)/2)*w);
}
}
cout<<a<<endl;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 25;
const int MOD = 1e9+7;
int main() {
ll n;
cin >> n;
ll sum = 0;
for (ll i = 1; i*i <= n; i++)
{
if ((n-i)%i == 0 && i < (n-i)/i) sum += (n-i) / i;
}
cout << sum << endl;
return 0;
} | 0 | 90,310,069 |
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
#define ALL(c) (c).begin(), (c).end()
const int MAX_N = 1e5;
int N;
int P[MAX_N];
ll solve() {
vector<pii> ps;
for (int i = 0; i < N; i++) {
ps.push_back({P[i], i + 1});
}
sort(ALL(ps), greater<pii>());
ll ans = 0;
set<int> s;
s.insert(0);
s.insert(N + 1);
for (int i = 0; i < N; i++) {
auto iter = s.insert(ps[i].second).first;
auto l = iter, r = iter;
int a, b, c, d, e;
b = *(--l);
a = (l == s.begin()) ? b : *(--l);
c = ps[i].second;
d = *(++r);
e = (++r == s.end()) ? d : *r;
ans += 1LL * ((b - a) * (d - c) + (c - b) * (e - d)) * ps[i].first;
}
return ans;
}
int main() {
cin >> N;
for (int i = 0; i < N; i++) {
cin >> P[i];
}
cout << solve() << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
return string(1, val);
}
int char_to_int(char val) {
return val - '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;
}
int vector_finder(std::vector<ll> vec, int number) {
auto itr = std::find(vec.begin(), vec.end(), number);
size_t index = std::distance( vec.begin(), itr );
if (index != vec.size()) {
return 1;
}
else {
return 0;
}
}
int main() {
int N, M, K; cin >> N >> M >> K;
string ans = "No";
for(int i = 0; i <= N; ++i) {
for(int k = 0; k <= M; ++k) {
ll tmp = M * i + N * k - 2 * i * k;
if(tmp == K) {
ans = "Yes";
}
}
}
cout << ans << endl;
} | 0 | 52,248,117 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll n, k, x, y; cin >> n >> k >> x >> y;
if(n < k) cout << n*x << "\n";
else cout << k*x+(n-k)*y << "\n";
return 0;
} | #include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include <string>
using namespace std;
int main(void){
int n;
string in;
while(1){
cin>>n;
if(n==0)break;
char data[n];
char into[n];
for(int i=0;i<n;i++){
cin>>in;
data[i]=in[0];
cin>>in;
into[i]=in[0];
}
int last;
cin >> last;
for(int t=0;t<last;t++){
cin >> in;
bool f=false;
for(int i=0;i<n;i++){
if(data[i]==in[0]){
f=true;
cout<<into[i];
}
}
if(!f)cout<<in[0];
}
cout<<"\n";
}
return 0;
} | 0 | 30,392,623 |
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 30;
int main() {
string s, t;
cin >> s >> t;
vector<char> S;
rep(i,s.size()) S.push_back(s[i]);
sort(S.begin(), S.end());
string ss = "";
rep(i,S.size()) ss += S[i];
vector<char> T;
rep(i,t.size()) T.push_back(t[i]);
sort(T.begin(), T.end());
reverse(T.begin(), T.end());
string tt = "";
rep(i,T.size()) tt += T[i];
if (ss < tt) cout << "Yes" << endl;
else cout << "No" << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
constexpr int B = 20;
int main() {
int n, l, q;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
cin >> l >> q;
vector<vector<int>> data(B, vector<int>(n));
for (int i = 0; i < n; i++) {
int ok = a[i] + l;
data[0][i] = (prev(upper_bound(a.begin(), a.end(), ok)) - a.begin());
}
for (int i = 1; i < B; i++) for (int j = 0; j < n; j++) {
if (data[i-1][j] == n-1) data[i][j] = data[i-1][j];
else data[i][j] = data[i-1][data[i-1][j]];
}
auto bs = [&] (int i, int x) {
for (int s = 0; s < B; s++) {
if (x&(1<<s)) i = data[s][i];
}
return i;
};
auto query = [&] (int a, int b) {
int ok = n, ng = 0;
while (abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (bs(a, mid) >= b) ok = mid;
else ng = mid;
}
return ok;
};
while (q--) {
int a, b;
cin >> a >> b;
if (a > b) swap(a, b);
cout << query(--a, --b) << endl;
}
return 0;
} | 0 | 30,467,515 |
#include<iostream>
#include<vector>
using namespace std;
int main(){
int n;
cin>>n;
vector<int>v(n),visited(n,false);
for(int i=0;i<n;i++)
cin>>v[i];
int index=0;
bool no=false;
int count=0;
while(index!=1){
if(visited[index]==true){
no=true;
break;
}
visited[index]=true;
index=v[index]-1;
count++;
}
if(!no){
cout<<count;
}
else{
cout<<"-1";
}
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)
#define mod 1000000007
typedef long long ll;
int main() {
string s;cin>>s;
int cnt=0;
rep(i,s.size()){
if(s[i]=='o'){
cnt++;
}
}
if(15-s.size()+cnt>=8){
cout<<"YES"<<endl;
return 0;
}
cout<<"NO"<<endl;
} | 0 | 7,967,690 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<=n;i++)
const ll MOD = 1000000007;
long long modinv(long long a, long long m=MOD) {
long long b = m, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b; swap(a, b);
u -= t * v; swap(u, v);
}
u %= m;
if (u < 0) u += m;
return u;
}
int main(){
int P,Q,R;
cin >> P >> Q >> R;
int sum = P + Q + R;
cout << sum - max(P,max(Q,R)) << endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#ifdef LOCAL
#include<debug.h>
#else
#define db(...) 21
#endif
#define sz(a) (int)a.size()
#define found(m,x) ((m).find(x)!=(m).end())
#define uset unordered_set
#define umap unordered_map
#define a(x) x.begin(),x.end()
#define fo(i,n) for(int i=0;i<(int)n;i++)
#define Fo(i,k,n) for(int i=k;k<n?i<=(int)n:i>=(int)n;k<n?i++:i--)
#define input(v,n) fo(i,n)cin>>v[i]
using vi = vector<int>;
using vpi = vector<pair<int,int>>;
using pi = pair<int,int>;
const int nax = 1e5+7;
const int mod = 1e9+7;
const int inf = numeric_limits<int> :: max() - (int)9e6;
void test() {
double L;
cin >> L;
double l,b,h;
l = L/3;
L -= l;
b = L/2;
h = L - b;
cout << fixed << setprecision(12) << l*b*h;
}
signed main() {
ios_base :: sync_with_stdio(false);
cin.tie(NULL);
#ifdef LOCAL
freopen("input.txt","r",stdin);
#endif
int T = 1;
while(T--) {
test();
cout << "\n";
}
return 0;
} | 0 | 38,346,673 |
#include <bits/stdc++.h>
using namespace std;
int main (void) {
int N;
cin >> N;
while ( N >= 0 ) {
if ( N % 4 == 0 ) {
cout << "Yes" << endl;
return 0;
}
N -= 7;
}
cout << "No" << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int>>
#define vvb vector<vector<bool>>
#define vb vector<bool>
#define pii pair<int, int>
#define vpli vector<pair<long long, int>>
#define deb(x) cout << "deb " << #x << " " << x << endl;
#define all(x) x.begin(), x.end()
#define endl "\n"
const ll BIG = 1e18;
void swap(ll &a, ll &b)
{
ll t = a;
a = b;
b = t;
}
ll Min(ll a, ll b, ll c)
{
return min(a, min(b, c));
}
void printvec(vi &vec)
{
for (int x : vec)
{
cout << x << " ";
}
cout << endl;
}
int sum(int a)
{
int ans = 0;
while (a)
{
ans += (a % 10);
a = a / 10;
}
return ans;
}
void print(vi &mp)
{
for (auto x : mp)
{
cout << x;
}
cout << endl;
}
void solve()
{
ll n;
cin >> n;
ll ans = 0;
for(ll i=2;i*i<=n;i++)
{
int power = 0;
while(n%i == 0)
{
power++;
n = n/i;
}
int reqd = 1;
while(power>=reqd)
{
ans ++;
power -= reqd;
reqd++;
}
}
if(n!=1) ans++;
cout<<ans<<endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t = 1;
while (t--)
solve();
return 0;
} | 0 | 60,882,771 |
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
int N;
cin >> N;
vector<int>A(N);
vector<int>B(N+1);
B[0] = 0;
for(int i = 0; i < N; i++) {
cin >> A[i];
B[i+1] = B[i]+A[i];
}
int ans = 0;
int cnt = 1;
sort(B.begin(),B.end());
for(int i = 1; i <= N; i++) {
if(B[i] == B[i-1]) {
cnt++;
}
else {
ans+=(cnt*(cnt-1))/2;
cnt = 1;
}
}
ans+=(cnt*(cnt-1))/2;
cout << ans << endl;
} | #include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pii pair<int,int>
#define pll pair<lli, lli>
#define vi vector<int>
#define vii vector<pair<int,int>>
#define vll vector<lli>
#define pb push_back
#define mpr make_pair
#define ss second
#define ff first
#define INF 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846264338327950L
#define all(x) x.begin(),x.end()
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define testcase() int tc;cin>>tc;while(tc--)
#define clean(x) memset(x,0,sizeof(x))
const lli maxn = 1e5+9;
vector<lli> catlan(int n) {
vector<lli> dp(n + 1, 0);
dp[0] = 1;
dp[1] = 1;
for (int i = 2; i <= n; i ++) {
for (int j = 0; j < i; ++ j) {
dp[i] += dp[j] * dp[i - j - 1];
}
}
return dp;
}
lli b_ex(lli n,lli a){lli res=1;while(n){if(n%2==1)res*=a;n>>=1;a=a*a;}return res;}
lli ncr(lli n,lli k){lli ans=1;if(k>n-k)k=n-k;for(lli i=1;i<=k;i++){ans*=(n-i+1),ans=ans/i;}return ans;}
lli power(lli a , lli n){lli ans = 1;while(n){if(n % 2)ans = (ans * a) % mod;n /= 2;a = (a * a) % mod;}return ans;}
lli set_bits(lli n)
{
int c=0;
if(n==0)return 0;
while(n)
{
if((n&1)==1)
{
cout<<c<<" ";
}
c++;
n=n>>1;
}
return c;
}
lli lcm(lli a,lli b)
{
lli ans=(a*b)/(__gcd(a,b));
return ans;
}
void solve()
{
int a,b;cin>>a>>b;
if(a==1)a+=100;
if(b==1)b+=100;
if(a>b)cout<<"Alice\n";
else if(b>a)cout<<"Bob\n";
else cout<<"Draw\n";
}
int main()
{
FAST;
solve();
} | 0 | 26,726,532 |
#include<bits/stdc++.h>
using namespace std;
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
#define gcd __gcd
#define append push_back
#define str to_string
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
typedef long long int ll;
#define int ll
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997;
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI = 3.14159265358979323846L;
constexpr auto oo = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int32_t main(){
fastio();
int n;
cin >> n;
int m1 = 0, m2 = 0;
int a[n];
forr(i,n){
cin >> a[i];
if(a[i] > m1){
m1 = a[i];
}else if(a[i] >= m2){
m2 = a[i];
}
}
forr(i,n){
if(a[i] == m1) cout << m2 << "\n";
else cout << m1 <<"\n";
}
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
using LP=pair<ll,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;
int main() {
int N;
cin>>N;
vector<int> A(N);
rep(i,N){cin>>A.at(i);}
sort(A.begin(),A.end());
vector<int> plus(0),minus(0);
rep(i,N){
if(i==0){
minus.pb(A.at(i));
}
else if(i==N-1){
plus.pb(A.at(i));
}
else{
if(A.at(i)>0)plus.pb(A.at(i));
else minus.pb(A.at(i));
}
}
ll ans=0;
rep(i,sz(plus)){
ans+=plus.at(i);
}
rep(i,sz(minus)){
ans-=minus.at(i);
}
cout<<ans<<endl;
int pp=1;
while(pp<sz(plus)){
cout<<minus.at(0)<<" "<<plus.at(pp)<<endl;
minus.at(0)-=plus.at(pp);
pp++;
}
rep(i,sz(minus)){
cout<<plus.at(0)<<" "<<minus.at(i)<<endl;
plus.at(0)-=minus.at(i);
}
} | 0 | 55,035,083 |
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
typedef std::pair<float,float> point;
typedef std::vector<point> segments;
void print_array(segments list)
{
for(int i = 0; i < list.size(); ++i){
std::cout << list[i].first<<" "<<list[i].second<< std::endl;
}
}
void print_point(point pt)
{
std::cout << pt.first<<" "<<pt.second<< std::endl;
}
void koch(int n,point p1,point p2) {
if(n==0) {
return;
}
point s=std::make_pair((2*p1.first+p2.first)/3,(2*p1.second+p2.second)/3);
point t=std::make_pair((p1.first+2*p2.first)/3,(p1.second+2*p2.second)/3);
float ux=(s.first+std::cos(M_PI*60/180)*(t.first-s.first)-std::sin(M_PI*60/180)*(t.second-s.second));
float uy=(s.second+std::sin(M_PI*60/180)*(t.first-s.first)+std::cos(M_PI*60/180)*(t.second-s.second));
point u=std::make_pair(ux,uy);
koch(n-1, p1, s);
print_point(s);
koch(n-1, s, u);
print_point(u);
koch(n-1, u, t);
print_point(t);
koch(n-1, t, p2);
}
int main(void){
std::cin.tie(0);
std::ios::sync_with_stdio(false);
int n;
std::cin >> n;
segments segment;
point p1=std::make_pair(0,0);
point p2=std::make_pair(100,0);
print_point(p1);
koch(n,p1,p2);
print_point(p2);
return 0;
} | #include <bits/stdc++.h>
#if DEBUG
template <typename T>
void debug(T value) {
std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
std::cerr << value << ", ";
debug(args...);
}
#define dbg(...) \
do { \
cerr << #__VA_ARGS__ << ": "; \
debug(__VA_ARGS__); \
cerr << " (L" << __LINE__ << ")" << endl; \
} while (0)
#else
#define dbg(...)
#endif
void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
std::cin >> value;
read_from_cin(args...);
}
#define in(type, ...) \
type __VA_ARGS__; \
read_from_cin(__VA_ARGS__);
template <typename T>
void write_to_cout(const T& value) {
std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
std::cout << value << ' ';
write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using ll = long long;
using namespace std;
int main() {
in(ll, n);
vector<ll> p(n + 1);
ll ans = 0;
for (ll i = 1; i <= n; ++i) {
for (ll j = i; j <= n; j += i) {
++p[j];
}
ans += i * p[i];
}
out(ans);
} | 0 | 19,392,491 |
#include <stdio.h>
int main(){
int a,b,c;
scanf("%d",&a);scanf("%d",&b);scanf("%d",&c);
if(a<b&&b<c)printf("Yes\n");
else printf("No\n");
return 0;
} | #include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;
const int INF = INT_MAX;
vector<vector<int>> E;
vector<int> P, A;
void DFS(int cur, int p, int t) {
for (int i = 0; i < E[cur].size(); i++) {
int n = E[cur][i];
if (n == p) continue;
A[n] += t + P[n];
DFS(n, cur, t + P[n]);
}
return;
}
int main() {
int N, Q;
cin >> N >> Q;
E.assign(N, vector<int>());
P.resize(N);
A.assign(N, 0);
for (int i = 0; i < N - 1; i++) {
int a, b;
cin >> a >> b;
a--; b--;
E[a].push_back(b);
E[b].push_back(a);
}
for (int i = 0; i < Q; i++) {
int p, x;
cin >> p >> x;
p--;
P[p] += x;
}
A[0] += P[0];
DFS(0, -1, P[0]);
for (int i = 0; i < N; i++) {
if (i) cout << ' ';
cout << A[i];
}
cout << endl;
} | 0 | 31,177,298 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
int N;
cin >> N;
map<ll, int> mp;
vector<ll> A(N);
for (int i = 0; i < N; i++)
{
ll a;
cin >> a;
if (mp.count(a))
mp[a]++;
else
mp[a] = 1;
A[i] = a;
}
sort(A.begin(), A.end(), greater<ll>());
ll ans;
ll h = 0;
ll w = 0;
for (int i = 0; i < A.size(); i++)
{
if (mp[A[i]] < 2)
continue;
else if (mp[A[i]] >= 4)
{
h = w = A[i];
cout << h * w << endl;
return 0;
}
else
{
h = A[i];
break;
}
}
for (int i = 0; i < A.size(); i++)
{
if (mp[A[i]] < 2 || A[i] == h)
continue;
else
{
w = A[i];
break;
}
}
cout << h * w << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 998244353;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
int N;
cin >> N;
cout << 0 << endl;
string S;
cin >> S;
if(S == "Vacant") {
return 0;
}
int l = 0,r = N;
while(true) {
int mid = (l+r)/2;
cout << mid << endl;
string T;
cin >> T;
if(T == "Vacant") {
return 0;
}
if(mid%2 == 0) {
if(S == T) {
l = mid;
}
else {
r = mid;
}
}
else {
if(S != T) {
l = mid;
}
else {
r = mid;
}
}
}
} | 0 | 93,293,868 |
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;
int main() {
int N, P;
cin >> N >> P;
vector<int> A(N);
rep(i, N) cin >> A[i];
vector<vector<long long>> dp(N + 1, vector<long long>(2, 0));
dp[0][0] = 1;
rep(i, N) {
dp[i + 1][0] += dp[i][0];
dp[i + 1][1] += dp[i][1];
if (A[i] & 1) {
dp[i + 1][0] += dp[i][1];
dp[i + 1][1] += dp[i][0];
} else {
dp[i + 1][0] += dp[i][0];
dp[i + 1][1] += dp[i][1];
}
}
cout << dp[N][P] << endl;
return 0;
} | #include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<iomanip>
#include<map>
#include<cstring>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;
const ll LLINF = 4 * 1e18;
struct cake{
ll bea, del, fav;
};
int main() {
int N, M; cin >> N >> M;
cake x[N];
rep(i, N) cin >> x[i].bea >> x[i].del >> x[i].fav;
ll ans = 0;
for(int bit = 0;bit < 8;++bit) {
ll a[3];
for(int i = 0; i < 3; ++i){
if(1 << i & bit){
a[i] = 1;
}else{
a[i] = -1;
}
}
ll temp[N];
rep(j, N) {
temp[j] = a[0] * x[j].bea + a[1] * x[j].del + a[2] * x[j].fav;
}
sort(temp, temp + N, greater<ll>());
ll tempans = 0;
rep(j, M)tempans += temp[j];
ans = max(tempans, ans);
}
cout << ans << endl;
} | 0 | 68,449,135 |
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using namespace std;
int main(){
int N, M;
cin >> N >> M;
int a[N];
rep(i, N){
a[i] = 0;
}
rep(i, M){
int c, b;
cin >> c >> b;
c--;b--;
a[c] += 1;
a[b] += 1;
}
rep(i, N){
if (a[i] % 2 == 1) {
cout << "NO" << endl;
return 0;
}
}
cout << "YES" << endl;
} | #include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ALLv(a) (a).begin(),(a).end()
#define ALL(a,n) (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
#define INF 1010000000000000017LL
#define MOD 1000000007LL
#define EPS 1e-12
#define PI 3.14159265358979323846
#define FOR(i,m,n) for(ll (i)=(m); (i)<(n); (i)++)
#define REP(i,n) for(ll (i)=0; (i)<(n); (i)++)
#define REPS(i,x) for(ll (i)=1; (i)<=(x); (i)++)
#define RREP(i,x) for(ll (i)=(x)-1; (i)>=0; (i)--)
#define RREPS(i,x) for(ll (i)=(x); (i)> 0; (i)--)
#define WREP(i,in,j,jn) REP(i,in)REP(j,jn)
#define dcml(n) fixed<<setprecision(n)
using namespace std;
struct _RLE{ char c; ll len; };
vector<_RLE> RLE(string S){
ll N=S.size();
vector<_RLE> v;
char prev=S[0];
for(ll i=1,cnt=1;i<=N;i++){
if(i==N){
v.push_back({prev,cnt});
break;
}
while(S[i]==prev){cnt++;i++;}
v.push_back({prev,cnt});
cnt=1;prev=S[i];
}
return v;
}
int main(void){
string S;ll K;cin>>S>>K;
ll c1=0;
vector<_RLE> v=RLE(S);
for(auto r:v){
if(r.len>=2){
c1+=r.len/2;
}
}
ll c2=0;
if(v[v.size()-1].c==v[0].c){
c2+=v[v.size()-1].len/2+v[0].len/2-(v[v.size()-1].len+v[0].len)/2;
}
ll ans=0;
if(v.size()==1)ans=S.size()*K/2;
else{
ans-=c2*(K-1);
ans+=c1*K;
}
cout<<ans<<"\n";
} | 0 | 85,728,333 |
#include<iostream>
#include<vector>
using namespace std;
const long long MOD = 1000000007;
long long cnt[2004][2004];
long long sum[2004][2004];
int same[2004][2004];
int main(){
int n,m;
cin>>n>>m;
vector<int> s(n);
vector<int> t(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++){
for(int j=0;j<m;j++) {
if (s[i] == t[j]) same[i][j] = 1;
else same[i][j] = 0;
}
}
for(int i=0;i<=n;i++) cnt[i][0] = 0LL;
for(int j=0;j<=m;j++) cnt[0][j] = 0LL;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(s[i] != t[j]) {
cnt[i+1][j+1] = 0LL;
} else {
cnt[i+1][j+1] = (sum[i][j] + 1LL) % MOD;
}
sum[i+1][j+1] = (sum[i][j+1] + sum[i+1][j] - sum[i][j] + cnt[i+1][j+1] + MOD + MOD) % MOD;
}
}
cout<<(sum[n][m]+1LL)%MOD<<endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;i++)
int N, K;
ll A[1001];
int main() {
cin >> N >> K;
REP(i,N) cin >> A[i];
vector<ll> B, C;
REP(i,N) {
REP(j, B.size()) {
B[j] += A[i];
}
B.push_back(A[i]);
copy(B.begin(),B.end(),back_inserter(C));
}
ll x = 0;
int m = 40;
for (int i = m; i >= 1; i--) {
int cnt = 0;
REP(j, C.size()) {
if (((x|(1LL<<(i-1))) & C[j]) == (x|(1LL<<(i-1)))) cnt++;
}
if (cnt >= K) x |= (1LL<<(i-1));
}
cout << x << endl;
return 0;
} | 0 | 42,284,109 |
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <string>
#include <numeric>
#include <algorithm>
#include <functional>
#include <iterator>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <complex>
#include <ctime>
#define ll long long
#define inf 0x3f3f3f3f
#define N 100010
using namespace std;
int main(){
ll s;
scanf("%lld",&s);
if(s==1000000000000000000)
{
printf("1000000000 0 0 1000000000 0 0\n");
return 0;
}
ll d=1000000000LL,b=s/1000000000,c=1+b,a=s%1000000000;
printf("0 %lld %lld 0 %lld %lld\n",a,b,c,d);
return 0;
} | #include<bits/stdc++.h>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
ll bpow(ll,ll,ll);
typedef vector<int> vec;
typedef vector<vec> mat;
mat mul(mat &A,mat &B);
mat pow(mat A,ll n);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
bool cmp_P(const P &a,const P &b){
return a.second < b.second;
}
int main()
{
ll N,a[200001],sum[200001],res=INF_LL;
cin >> N;
REP(i,N)cin >> a[i];
sum[0] = 0;
REP(i,N)
sum[i+1] = sum[i] + a[i];
REP(i,N-1){
res = min(res,abs(sum[N]-2*sum[i+1]));
}
cout << res << endl;
return 0;
}
int par[MAX_N];
int ranks[MAX_N];
void init(int n){
REP(i,n){
par[i] = i;
ranks[i] = 0;
}
}
int find(int x){
if(par[x] == x){
return x;
}else{
return par[x] = find(par[x]);
}
}
void unite(int x,int y){
x = find(x);
y = find(y);
if(x == y) return ;
if(ranks[x] < ranks[y]){
par[x] = y;
}else{
par[y] = x;
if(ranks[x] == ranks[y]) ranks[x]++;
}
}
bool same(int x, int y){
return find(x) == find(y);
}
ll bpow(ll a, ll n,ll mod){
int i = 0;
ll res=1;
while(n){
if(n & 1)
res = (res*a) % mod;
a = (a*a) % mod;
n >>= 1;
}
return res;
}
const int MOD = 1000000007;
mat mul(mat &A, mat &B){
mat C(A.size(),vec(B[0].size()));
REP(i,A.size())REP(k,B.size())REP(j,B[0].size()){
C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD;
}
return C;
}
mat pow(mat A,ll n)
{
mat B(A.size(),vec(A.size()));
REP(i,A.size()){
B[i][i] = 1;
}
while(n > 0){
if ( n & 1) B = mul(B,A);
A = mul(A,A);
n >>= 1;
}
return B;
} | 0 | 4,184,348 |
#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#define ynmes(a) (a) ? mes("Yes") : mes("No")
#define YNmes(a) (a) ? mes("YES") : mes("NO")
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
struct io { io() { ios::sync_with_stdio(false); cin.tie(0); } };
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;
signed main() {
ll n, m;
cin >> n >> m;
vll a(n), b(n), c(m), d(m);
rep(i, n) {
cin >> a[i] >> b[i];
}
rep(i, m) {
cin >> c[i] >> d[i];
}
ll r;
rep(i, n) {
ll tmp = 1e9;
rep(j, m) {
ll x = abs(a[i]-c[j])+ abs(b[i]-d[j]);
if (x < tmp) {
tmp = x;
r = j+1;
}
}
mes(r);
}
} | #include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define RREP0(i, n) for (int i = (n)-1; i >= 0; --i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define RREP1(i, n) for (int i = (n); i >= 1; --i)
#define pow10(n) int(1e##n + n)
typedef long long LL;
typedef pair<int, int> P;
const int INTINF = int(1e9) + 1;
const LL LLINF = LL(1e18) + 1;
long double eps = 1.0E-14;
void solve()
{
int N, M, K;
cin >> N >> M >> K;
REP0 (n, N + 1)
{
REP0 (m, M + 1)
{
if (K == m * (N - n) + n * (M - m))
{
std::cout << "Yes" << endl;
return;
}
}
}
std::cout << "No" << endl;
}
int main(int argc, char const *argv[])
{
cin.tie(0);
ios::sync_with_stdio(false);
std::cout << std::fixed << std::setprecision(20);
solve();
return 0;
} | 0 | 7,095,958 |
#include <bits/stdc++.h>
using namespace std;
int main() {
double T, X; cin >> T >> X;
cout << setprecision(5) << T / X << endl;
} | #include <iostream>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int n, k, a;
cin >> n >> k;
map<int, int> mp;
for (int i=0; i<n; i++) {
cin >> a;
mp[a]++;
}
vector<int> v;
for (auto iter=mp.begin(); iter!=mp.end(); iter++) {
v.push_back(iter->second);
}
sort(v.begin(), v.end(), greater<>());
int limit = min(k, (int)v.size());
int result = n;
for (int i=0; i<limit; i++) {
result -= v[i];
}
cout << result << endl;
} | 0 | 92,948,037 |
#include <iostream>
#include <map>
using namespace std;
int fib(int n, map<int, int>& fib_mp)
{
auto itr = fib_mp.find(n);
if (fib_mp.end() != itr) return itr->second;
return fib_mp[n] = fib(n - 1, fib_mp) + fib(n - 2, fib_mp);
}
int main()
{
int n;
cin >> n;
map<int, int> fib_mp;
fib_mp[0] = fib_mp[1] = 1;
cout << fib(n, fib_mp) << endl;
return 0;
} | #include <iostream>
#include <cstring>
using namespace std;
char s[1100],t[1100];
int ans=2333333;
int main(void)
{
cin>>s>>t;
int ls=strlen(s),lt=strlen(t);
for(int i=0;i<=ls-lt;i++)
{
int k=0;
for(int j=0;j<lt;j++)
{
if(s[i+j]!=t[j])k++;
}
ans=min(ans,k);
}
cout<<ans<<endl;
return 0;
} | 0 | 95,471,157 |
#include<bits/stdc++.h>
using namespace std;
long long int A, B, K;
long long int max(long long int A, long long int B) { return A > B ? A : B; }
int main() {
cin >> A >> B >> K;
if (K >= A) cout << 0 << " " << max(0, B-(K-A));
else cout << (long long) (A-K) << " " << B;
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
int main() {
string S, ans = "AC\n";
cin >> S;
if (S[0] != 'A') ans = "WA\n";
if (S[1] < 'a' || S[1] > 'z') ans = "WA\n";
int C = 0, n = S.size();
if (S[n - 1] < 'a' || S[n - 1] > 'z') ans = "WA\n";
for (int i = 2; i < n - 1; i++) {
if (S[i] == 'C') C++;
else if (S[i] < 'a' || S[i] > 'z') ans = "WA\n";
}
if (C != 1) ans = "WA\n";
cout << ans;
} | 0 | 42,410,259 |
#include<iostream>
using namespace std;
int main()
{
int x,y,z=500,a;
cin>>x>>y;
a=x*500;
if(a>=y){
cout<<"Yes"<<endl;
}
else cout<<"No"<<endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
int n,c=0;
cin >> n;
vector<int> a;
for(int i=0; i<n; i++){
int val;
cin >> val;
a.push_back(val);
}
int j=0, now=1;
for(;;){
now = a[now-1];
if(now == 2){
cout << c+1;
break;
}
if(c>=n){
cout << "-1";
break;
}
c++;
}
} | 0 | 60,812,308 |
#include <iostream>
#include <string>
using namespace std;
int main() {
string op;
string ABCD;
int seven;
int a, b, c, d;
cin >> ABCD;
a = ABCD[0] - '0';
b = ABCD[1] - '0';
c = ABCD[2] - '0';
d = ABCD[3] - '0';
for (int bit = 0; bit < (1 << 3); bit++) {
op = "---";
seven = 0;
for (int i = 0; i < 3; i++) {
if (bit & (1 << i)) op[i] = '+';
}
if (op[0] == '+') seven += a + b;
else seven += a - b;
if (op[1] == '+') seven += c;
else seven -= c;
if (op[2] == '+') seven += d;
else seven -= d;
if (seven == 7) break;
}
cout << a << op[0] << b << op[1] << c << op[2] << d << "=7" << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const int MAX = 1001001001;
template<class T> bool chmin(T &a, T b){if(a > b){a = b; return true;} return false;}
int dp[10050];
int main(){
int h, n; cin >> h >> n;
vector<int> a(n), b(n);
for(int i = 1; i <= h + 10; i++) dp[i] = MAX;
for(int i = 0; i < n; i++){
cin >> a.at(i) >> b.at(i);
dp[a[i]] = b[i];
}
for(int i = 1; i <= h; i++){
for(int j = 0; j < n; j++){
if(i-a[j] > 0){
chmin(dp[i], dp[i-a[j]] + b[j]);
}
else{
chmin(dp[i], b[j]);
}
}
}
cout << dp[h] << endl;
} | 0 | 96,493,750 |
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
using namespace std;
typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
const int INF = INT_MAX / 4;
#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); i++ )
#define UREP( i, m, n ) for ( ui i = (ui)( m ); i < (ui)( n ); i++ )
#define EACH( v, c ) for ( __typeof( c.front() ) &v : c )
#define ITER( c ) __typeof( (c).begin() )
#define IREP( c, it ) for ( ITER(c) it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()
#define RALL( c ) (c).rbegin(), (c).rend()
#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )
#define fst first
#define snd second
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl
int main()
{
while ( true )
{
string line;
getline( cin, line );
if ( line == "." )
{
return 0;
}
bool yes = true;
char c;
stack<char> st;
istringstream iss( line );
while ( iss >> c )
{
if ( c == '(' || c == '[' )
{
st.push( c );
}
else if ( c == ')' || c == ']' )
{
int c2 = ( c == ')' ? '(' : '[' );
if ( !st.empty() && st.top() == c2 )
{
st.pop();
}
else
{
yes = false;
}
}
}
if ( yes && st.empty() )
{
cout << "yes" << endl;
}
else
{
cout << "no" << endl;
}
}
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define N 100000 + 5
#define M 20 + 5
#define rep(i, l, r) for(int i = l; i <= r; ++i)
#define dep(i, l, r) for(int i = r; i >= l; --i)
int n, q, l, a, b, ans, x[N], f[N][M];
int read(){
char c; int x = 0, f = 1;
c = getchar();
while(c > '9' || c < '0'){ if(c == '-') f = -1; c = getchar();}
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
int main(){
n = read();
rep(i, 1, n) x[i] = read();
l = read();
rep(i, 1, n){
int pos = upper_bound(x + 1, x + n + 1, x[i] + l) - x;
if(x[pos] < x[i] + l) f[i][0] = n + 1;
else f[i][0] = pos - 1;
}
rep(j, 1, M - 5) rep(i, 1, n) if(f[i][j - 1]) f[i][j] = f[f[i][j - 1]][j - 1];
q = read();
while(q--){
a = read(), b = read(), ans = 0; if(a > b) swap(a, b);
dep(i, 0, M - 5) if(f[a][i] < b && f[a][i]) a = f[a][i], ans += (1 << i);
if(a < b) ++ans;
printf("%d\n", ans);
}
return 0;
} | 0 | 680,285 |
#include "bits/stdc++.h"
using namespace std;
int main() {
string S,T;
cin >> S >>T;
int ans = 0;
for (int n = 0;n< S.size();++n) {
if (S[n] == T[n]) {
ans++;
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define IC ios_base::sync_with_stdio(false); cin.tie(NULL);
#define f(i, a, b) for(int i=a; i<b; i++)
#define ff(i, a, b) for(int i=a-1; i>=b; i--)
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define mp make_pair
#define sz 1005
#define mod 998244353
#define line "\n"
#define ALL(x) x.begin(), x.end()
#define F first
#define S second
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef vector<int> vi;
typedef set<int> si;
typedef map<int, int> mii;
typedef map<char, int> mci;
const double PI = acos(-1);
void solve()
{
ll k, a, b, c, d, n, m=0, cnt=0, flg=0, ans=0, pos=0, sum=0, mx=INT_MIN, mn=INT_MAX;
cin >> a >> b >> c >> d;
cout << max(max(max(a*c, a*d), b*c), b*d);
}
int main()
{
int T=1, k=1;
while(T--)
solve();
return 0;
} | 0 | 44,730,485 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; }
int main()
{
int n;
cin >> n;
if(n == 1){
cout << 1 << endl;
}else if(2 <= n && n <= 3){
cout << 2 << endl;
}else if(4 <= n && n <= 7){
cout << 4 << endl;
}else if(8 <= n && n <= 15){
cout << 8 << endl;
}else if(16 <= n && n <= 31){
cout << 16 << endl;
}else if(32 <= n && n <= 63){
cout << 32 << endl;
}else{
cout << 64 << endl;
}
return 0;
} | #include<iostream>
using namespace std;
int main(){
int x,y,a,b;
while(1){
cin >>x >>y;
if(x==0 && y==0) break;
if(x<=y){
a=x;
b=y;
} else {
a=y;
b=x;
}
cout << a << " " << b <<endl;
}
return 0;
} | 0 | 51,005,635 |
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
int A, B, C, K;
cin >> A >> B >> C >> K;
int ans = min(A, K);
K -= min(A, K);
if (K > 0) {
K -= min(B, K);
}
if (K > 0) {
ans -= K;
}
cout << ans << '\n';
return 0;
} | #include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;
int main() {
vector<int> odd, even;
rep(i, 3) {
int a;
cin >> a;
if(a % 2 == 0) even.push_back(a);
else odd.push_back(a);
}
int ans = 0;
if(even.size() == 2) {
ans++;
rep(i, even.size()) even[i]++;
}
if(even.size() == 1) {
ans++;
rep(i, odd.size()) odd[i]++;
}
int maxv = -1;
for(auto x : even) maxv = max(x, maxv);
for(auto x : odd) maxv = max(x, maxv);
for(auto x : even) ans += (maxv - x) / 2;
for(auto x : odd) ans += (maxv - x) / 2;
cout << ans << endl;
return 0;
} | 0 | 67,482,699 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
int n;
cin >> n;
vector<int> d(n);
for (size_t i = 0; i < n; i++) cin >> d[i];
long long ans = 0;
for (size_t i = 0; i < n; i++) {
for (size_t j = i+1; j < n; j++) {
ans += d[i] * d[j];
}
}
cout << ans << endl;
return 0;
} | #include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<cstdint>
#include<bits/stdc++.h>
#include<queue>
#include<set>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for(int i = n-1; i >= 0; i--)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define INF bit(60)
#define pb push_back
#define mod 1000000007
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;
using uif=uint_fast64_t;
using ll=long long int;
int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mod;a=1ll*a*a%mod;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
#define FACSIZE 2002
ll invfac[FACSIZE];
ll fac[FACSIZE];
ll mod_pow(ll ,ll );
ll mod_add(ll ,ll );
ll mod_mul(ll ,ll );
ll mod_div(ll ,ll );
void make_fact(ll );
void make_invfact(ll );
int main(void){
ll n;
cin>>n;
using pa=pair<ll,ll>;
vector<pa> pos(n);
rep(i,n) cin>>pos[i].first>>pos[i].second;
map<double,pa> m;
for(auto p:pos){
double theta = (double)atan2((double)p.second,(double)p.first);
if(m.find(theta)==end(m)){
m[theta]=p;
}
else{
auto p2=m[theta];
m[theta] = make_pair( p.first+p2.first,p.second+p2.second );
}
}
ll ans=0;
/*
for(auto itr=begin(m);itr!=end(m);itr++){
pa vec=make_pair(0,0);
vec=make_pair(0,0);
auto Ltheta = itr->first;
if(Ltheta>0){
for(auto itr2=itr; itr2!=end(m) ;itr2++){
auto pv=vec;
auto p2=itr2->second;
vec= make_pair(pv.first+p2.first,pv.second+p2.second);
}
for(auto itr2=begin(m); itr2->first < Ltheta - M_PIl && itr2!=end(m) ;itr2++){
auto pv=vec;
auto p2=itr2->second;
vec= make_pair(pv.first+p2.first,pv.second+p2.second);
}
}
else{
for(auto itr2=itr; itr2->first < Ltheta + M_PIl && itr2!=end(m) ;itr2++){
auto pv=vec;
auto p2=itr2->second;
vec= make_pair(pv.first+p2.first,pv.second+p2.second);
}
}
ans=max(ans, vec.first*vec.first + vec.second*vec.second );
}
vector<pa> arr;
for(auto p:m) arr.push_back(p.second);
ll N=arr.size();
for(ll i=0;i<N;i++){
for(ll j=i;j<N;j++){
vector<pa> cand1;
vector<pa> cand2;
cand1.clear();
cand2.clear();
for(ll k=0;k<N;k++){
if( k>=i && k<=j ){
cand1.push_back( arr[k] );
}
else cand2.push_back( arr[k] );
}
pa v;
v=make_pair(0,0);
for(ll k=0;k<cand1.size();k++){
auto p=cand1[k];
v = make_pair( v.first + p.first ,v.second+p.second );
}
ans = max(ans,v.first*v.first+v.second*v.second);
v=make_pair(0,0);
for(ll k=0;k<cand2.size();k++){
auto p=cand2[k];
v = make_pair( v.first + p.first ,v.second+p.second );
}
ans = max(ans,v.first*v.first+v.second*v.second);
}
}
cout << std::setprecision(50) << sqrt(ans) << endl;
return 0;
}
ll mod_pow(ll x,ll r){
if(r==0) return 1;
else if(r==1) return x%mod;
else if(r%2==0){
ll t=mod_pow(x,r/2)%mod;
return t*t %mod;
}
else{
ll t=mod_pow(x,r/2)%mod;
ll k= t*t %mod;
return k*x%mod;
}
}
ll mod_add(ll a,ll b){
return (a+b)%mod;
}
ll mod_mul(ll a,ll b){
return (a*b)%mod;
}
ll mod_div(ll a,ll b){
return mod_mul(a,mod_pow(b,mod-2));
}
void make_fact(ll n){
fac[0]=1;
rep(i,n){
fac[i+1]=mod_mul(fac[i],i+1);
}
}
void make_invfact(ll n){
invfac[n]= mod_pow( fac[n] ,mod-2);
for(int i=n-1;i>=0;i--){
invfac[i]=mod_mul(invfac[i+1],i+1);
}
} | 0 | 56,032,461 |
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define uni(e) e.erase(unique(e.begin(),e.end()),e.end())
#define double long double
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 INF=1e10;
int MOD=1e9+7;
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
int keta(int a){
double b=a;
b=log10(b);
int c=b;
return c+1;
}
int gcd(int a,int b){
if(a%b==0)
return b;
return gcd(b,a%b);
}
int lcm(int a,int b){
return a/gcd(a,b)*b;
}
bool sosuu(int a){
bool b=1;
if(a<=1)
return 0;
else{
rep1(i,sqrt(a)-1){
if(a%(i+1)==0)
b=0;
}
return b;
}
}
int modpow(int a,int b,int m=MOD){
if(!b)return 1; if(b&1)return modpow(a,b-1,m)*a%m;
int memo = modpow(a,b>>1,m);
return memo*memo%m;
}
int fact_mod(int n) {
int f=1;
for(int i=2;i<n+1;i++) f=f*(i%MOD)% MOD;
return f;
}
int mod_pow(int x,int n) {
int res=1;
while(n>0){
if(n&1) res=(res*x)%MOD;
x=(x*x)%MOD;
n>>=1;
}
return res;
}
int c_mod(int n, int r) {
if(r>n-r) r=n-r;
if(r==0) return 1;
int a=1;
rep(i,r)
a=a*((n-i)%MOD)%MOD;
int b=mod_pow(fact_mod(r), MOD-2);
return (a%MOD)*(b%MOD)%MOD;
}
signed main(){
int a,b,c;
cin>>a>>b>>c;
rep(i,c){
if(i%2==0){
if(a%2==0){
a/=2;
b+=a;
}
else{
a--;
a/=2;
b+=a;
}
}
else{
if(b%2==0){
b/=2;
a+=b;
}
else{
b--;
b/=2;
a+=b;
}
}
}
cout<<a<<' '<<b<<endl;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
const ll MOD = (ll)1e9 + 7;
const ll MOD2 = 998244353;
const ll LLINF = (ll)1e18;
const ll INTINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp> class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max<T>(a,b);}
template <class T> void chmin(T& a, const T b){a=min<T>(a,b);}
void YN(bool flg) {cout << ((flg) ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << ((flg) ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << ((flg) ? "yes" : "no") << endl;}
int main() {
int N; cin >> N;
string S; cin >> S;
int K; cin >> K;
char c = S[K-1];
for(auto& e:S) if(e!=c) e = '*';
cout << S << endl;
return 0;
} | 0 | 88,949,198 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pa pair<int, int>
#define pal pair<long long, long long>
#define pali pair<long long, int>
#define pad pair<double, double>
#define pb push_back
#define mp make_pair
#define COUT(v) \
for (int64_t i = 0; i < (v).size(); ++i) \
{ \
cout << v.at(i) << endl; \
}
#define REP(i, n) for (int64_t i = 0; i < n; ++i)
#define FOR(i, r, n) for (int64_t i = (r); i < n; ++i)
#define VIN(v) \
for (int64_t i = 0; i < (v).size(); ++i) \
{ \
cin >> (v).at(i); \
}
typedef vector<bool> bvec;
typedef vector<int> ivec;
typedef vector<long long> lvec;
typedef vector<double> dvec;
typedef vector<pa> pavec;
typedef vector<pali> palivec;
typedef vector<pal> palvec;
typedef vector<vector<bool> > bmat;
typedef vector<vector<int> > imat;
typedef vector<vector<long long> > lmat;
typedef vector<string> svec;
typedef vector<vector<string> > smat;
const ll infll = (1LL << 60) - 1;
const int inf = (1 << 30) - 1;
const ll MOD = 1000000007;
ll gcd(ll x, ll y)
{
ll r = x % y;
if (r == 0)
return y;
else
return gcd(y, r);
}
ll lcm(ll x, ll y)
{
return x * y / gcd(x, y);
}
lvec mfactor(ll n)
{
bvec ip(n, true);
lvec mf(n, -1);
ip[0] = false;
ip[1] = false;
mf[0] = 0;
mf[1] = 1;
REP(i, n)
{
if (ip[i])
{
mf[i] = i;
for (ll j = i * i; j < n; j += i)
{
ip[j] = false;
if (mf[j] == -1)
mf[j] = i;
}
}
}
return mf;
}
palivec get_prime(ll n, const lvec &mf)
{
palivec plist;
while (n != 1)
{
int cnt = 0;
ll m = mf[n];
while (mf[n] == m)
{
cnt++;
n /= m;
}
plist.pb(pali(m, cnt));
}
return plist;
}
void COMinit(int m, lvec &fac, lvec &finv)
{
lvec inv(m);
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < m; i++)
{
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
ll pow_mod(ll a, ll n)
{
ll x = 1;
while (n > 0)
{
if (n & 1)
{
x = x * a % MOD;
}
a = a * a % MOD;
n >>= 1;
}
return x;
}
ll pow_mod2(ll a, ll n)
{
ll x = 1;
while (n > 0)
{
if (n & 1)
{
x = x * a;
}
a = a * a;
n >>= 1;
}
return x;
}
ll COM(int n, int k, const lvec &fac, const lvec &finv)
{
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return (fac[n] * (finv[k] * finv[n - k] % MOD)) % MOD;
}
ll modinv(ll a, ll m)
{
ll b = m, u = 1, v = 0;
while (b)
{
ll t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
class UnionFind {
public:
vector <ll> par;
vector <ll> siz;
UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
for (ll i = 0; i < sz_; ++i) par[i] = i;
}
void init(ll sz_) {
par.resize(sz_);
siz.assign(sz_, 1LL);
for (ll i = 0; i < sz_; ++i) par[i] = i;
}
ll root(ll x) {
while (par[x] != x) {
x = par[x] = par[par[x]];
}
return x;
}
bool merge(ll x, ll y) {
x = root(x);
y = root(y);
if (x == y) return false;
if (siz[x] < siz[y]) swap(x, y);
siz[x] += siz[y];
par[y] = x;
return true;
}
bool issame(ll x, ll y) {
return root(x) == root(y);
}
ll size(ll x) {
return siz[root(x)];
}
};
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
ll n, m;
cin >> n >> m;
bmat adj(n, bvec(n, false));
lvec p(n);
for (int i=0; i<m; i++){
ll a, b;
cin >> a >> b;
--a, --b;
adj[a][b] = true;
adj[b][a] = true;
}
for (int i=0; i<n; i++){
p[i] = i;
}
ll ans = 0;
function<void(int, bvec&)> dfs = [&](int d, bvec &t){
if(d==n){
bool flg = true;
for (int i=1; i<n; i++){
if(!adj[p[i-1]][p[i]]){
flg = false;
break;
}
}
if(flg)++ans;
return;
}
for (int i=1; i<n; i++){
if(t[i]) continue;
p[d] = i;
t[i] = true;
dfs(d+1, t);
t[i] = false;
}
};
bvec t(n, false);
dfs(1, t);
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main()
{
int n, m, x, y;
vector<pair<int, int>> a(50), b(50), c(50);
cin >> n >> m;
for (int i = 0; i < n; i++)
{
cin >> x >> y;
a[i] = make_pair(x, y);
}
for (int i = 0; i < m; i++)
{
cin >> x >> y;
b[i] = make_pair(x, y);
}
for (int i = 0; i < n; i++)
{
c[i] = make_pair(0, abs(a[i].first - b[0].first) + abs(a[i].second - b[0].second));
for (int j = 1; j < m; j++)
{
if (c[i].second > abs(a[i].first - b[j].first) + abs(a[i].second - b[j].second))
c[i] = make_pair(j, abs(a[i].first - b[j].first) + abs(a[i].second - b[j].second));
}
}
for (int i = 0; i < n; i++)
cout << c[i].first + 1 << endl;
} | 0 | 74,960,292 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a;
vector<int> an;
vector<vector<int>> AN;
while (cin >> n) {
if (n == 0)break;
for (int i = 0; i < n; i++) {
cin >> a;
an.push_back(a);
}
AN.push_back(an); an.clear();
}
for (int i = 0; i < AN.size(); i++) {
long long int max = 0, min = INT_MAX, MAX = 0, MIN = 0 , counter = 0, negative = 0;
for (int j = 0; j < AN[i].size(); j++) {
if (AN[i][j] >= 0) {
max += AN[i][j];
if (MAX < max)MAX = max;
counter = 1;
negative = 1;
}
else {
if (negative == 0) {
if(min > abs(AN[i][j]))min=abs(AN[i][j]);
}
else if (counter==1){
if (AN[i][j] + max >= 0)max += AN[i][j];
else {
max = 0;
counter = 0;
}
}
}
}
if (negative == 0)cout << -1*min << endl;
else cout << MAX << endl;
}
return 0;
} | #include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001;
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;
int main(){
string s;
int n;cin>>n>>s;
int a=0,b=0;
rep(i,n){
if(s[i]=='('){
a++;
}
else{
if(a==0)b++;
else a--;
}
}
rep(i,b){
s='('+s;
}
rep(i,a){
s=s+')';
}
cout<<s<<endl;
} | 0 | 54,638,752 |
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>
using namespace std;
#define int long long
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
void solve(void)
{
int H,W; cin>>H; cin>>W;
int A,B; cin>>A; cin>>B;
vector<vector<int> > vvec (H,vector<int>(W,0));
for (int i = 0; i < H; i++)
{
for (int j = 0; j < W; j++)
{
int P = (int)(i>=B);
int Q = (int)(j>=A);
vvec[i][j] = P^Q;
}
}
for (int i = 0; i < H; i++)
{
for (int j = 0; j < W; j++)
{
cout<<vvec[i][j];
}
cout<<endl;
}
return;
}
int32_t main(int32_t argc, const char *argv[])
{
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout << std::fixed;
std::cout << std::setprecision(9);
solve();
return 0;
} | #include <iostream>
#include <queue>
using namespace std;
using ll = long long;
int main(){
ll K,n;
cin >> K;
queue<ll> q;
for(int i=1;i<10;++i) q.push(i);
while(1){
n = q.front();
q.pop(); --K;
if(K==0){
cout << n << endl;
return 0;
}
if(n%10!=0) q.push(n*10+n%10-1);
q.push(n*10+n%10);
if(n%10!=9) q.push(n*10+n%10+1);
}
} | 0 | 49,502,154 |
#include <iostream>
using namespace std;
int main(){
int H,W;
while(cin >> H >> W){
if(H==0&&W==0) break;
for(int i=0;i<H;i++){
for(int j=0; j<W; j++){
if(H==0&&W==0) break;
cout <<"#";
}
cout <<"\n";
}
cout << "\n";
}
} | #include"bits/stdc++.h"
using namespace std;
using ll = int64_t;
int main() {
ll N;
cin >> N;
vector<ll> A(N);
ll sum = 0;
for (ll i = 0; i < N; i++) {
cin >> A[i];
sum ^= A[i];
}
for (ll i = 0; i < N; i++) {
A[i] &= ~sum;
}
ll next_position = 0;
ll rank = -1;
for (ll i = 59; i >= 0; i--) {
for (ll j = next_position; j < N; j++) {
if (A[j] & (1ull << i)) {
swap(A[j], A[next_position]);
for (ll k = next_position + 1; k < N; k++) {
if (A[k] & (1ull << i)) {
A[k] ^= A[next_position];
}
}
if (next_position++ == 0) {
rank = min(i, N - 1);
}
break;
}
}
}
ll ans = 0;
next_position = 0;
for (ll i = 59; i >= 0; i--) {
for (ll j = next_position; j < N; j++) {
if (A[j] & (1ull << i)) {
if ((ans & (1ull << i)) == 0) {
ans ^= A[j];
}
next_position++;
break;
}
}
}
ans = ans * 2 + sum;
cout << ans << endl;
} | 0 | 68,563,621 |
#include<iostream>
#include<vector>
#include<cmath>
#include<iomanip>
#include<string>
using namespace std;
int s(string str, int j) {
int i = j;
if (str[i] == '(') {
while(true) {
i++;
if (str[i] == ')') {
return i;
} else if (str[i] == '[' || str[i] == '(') {
i = s(str, i);
if (i == -1) {
return -1;
}
} else if (str[i] == ']' || str[i] == '.') {
return -1;
}
}
} else {
while(true) {
i++;
if (str[i] == ']') {
return i;
} else if (str[i] == '[' || str[i] == '(') {
i = s(str, i);
if (i == -1) {
return -1;
}
} else if (str[i] == ')' || str[i] == '.') {
return -1;
}
}
}
}
int main() {
while(true) {
int i;
int cntr = 0;
int cntk = 0;
int result = 0;
string ch;
getline(cin, ch);
for (i = 0; i < 100; i++) {
if (ch[i] == '(' || ch[i] == '[') {
result = s(ch, i);
i = result;
if (result == -1) {
break;
}
} else if (ch[i] == ')' || ch[i] == ']') {
result = -1;
break;
} else if (ch[i] == '.') {
result = 0;
break;
}
}
if (ch[0] == '.') {
break;
} else if (result != -1) {
cout << "yes" << endl;
} else {
cout << "no" << endl;
}
}
} | #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <iostream>
using namespace std;
#define mod 1e9+7
#define ll long long int
#define epsilon 1e-7
double min(double x, double y){
if(x<y)return x;
return y;
}
int t[100];
int v[100];
double realv[20000];
int tsum[101];
int main(void){
int n;
scanf("%d", &n);
int tt = 0;
tsum[0] = 0;
for(int i = 0;i < n;i++){
scanf("%d", &t[i]);
tt += t[i];
tsum[i+1] = tt;
}
for(int i = 0;i < n;i++){
scanf("%d", &v[i]);
}
double ans = 0;
for(int i = 0;i < n;i++){
for(int j = tsum[i];j < tsum[i+1];j++){
double real = min(j, min(tsum[n]-j, v[i]));
for(int k = 0;k < n;k++){
if(k < i){
real = min(real, v[k] + j - tsum[k+1]);
}
if(k > i){
real = min(real, v[k] + tsum[k] - j);
}
}
double half = min((double)j + 0.5, min((double)tsum[n]-(double)j - 0.5, (double)v[i]));
for(int k = 0;k < n;k++){
if(k < i){
half = min(half, (double)v[k] + (double)j + 0.5 - (double)tsum[k+1]);
}
if(k > i){
half = min(half, (double)v[k] + (double)tsum[k] - (double)j - 0.5);
}
}
ans += real / 2.0 + half / 2.0;
}
}
printf("%lf\n", ans);
return 0;
} | 0 | 81,525,634 |
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
int A, B;
size_t K;
cin >> A >> B >> K;
vector<int> v;
int upper = min(A, B);
for (int i = 1; i <= upper; ++i) {
if (((A % i) == 0) && ((B % i) == 0)) {
v.push_back(i);
}
}
if (K <= v.size()) {
cout << v[v.size() - K] << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long int intl;
typedef unsigned long long intu;
#define int long long
#define sfi(x) scanf("%lld", &x)
#define sfi2(x, y) sfi(x) , sfi(y)
#define sfi3(x, y, z) sfi(x) , sfi(y) , sfi(z)
#define sfc(x) scanf(" %c", &x)
#define sfs(x) scanf(" %s", x)
#define sfsn(x) scanf(" %[^\n]s", x)
#define pfi(x) printf("%lld", (intl)x)
#define pfis(x) printf("%lld", (intl)x), printf(" ")
#define pfin(x) printf("%lld", (intl)x), printf("\n")
#define pfs(x) printf("%s", x)
#define pfnl printf("\n")
#define pfsp printf(" ")
#define endl '\n'
#define sp ' '
#define watch(x) cout<<"::debug:: "<< #x <<" : "<<x<<endl
#define watchi(i, x) cout<<"::debug:: "<< #x <<"-> ["<<i<<"]"<<" : "<<x<<endl
#define FOR(i, begin, end) for(__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define repit(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); ++it)
#define perit(it, x) for(__typeof((x).rbegin()) it = (x).rbegin(); it != (x).rend(); ++it)
#define rep(i, begin, end) for(int i = (begin), ed = (end); i < (ed); ++i)
#define per(i, end, begin) for(int i = (end)-1, bg = (begin); i >= (bg); --i)
#define setvalue(a, v) for(int i = 0, sz = (sizeof(a)/sizeof(*a)); i<sz; i++){ a[i] = v; }
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define all(a) a.begin(), a.end()
#define min3(x, y, z) min(x,min(y,z))
#define max3(x, y, z) max(x,max(y,z))
#define PI 2*acos(0)
#define INF 1000000007
#define debug if( 1 )
const int mxn = 100010;
void solve(int tc)
{
int n;
cin >> n;
int arr[2*n];
for(int i=0; i<2*n; i++) cin >> arr[i];
sort(arr, arr+2*n);
int tot = 0;
for(int i=0; i<2*n; i+=2) tot += arr[i];
cout << tot << endl;
}
int32_t main()
{
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
solve(1);
return 0;
} | 0 | 83,126,793 |
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void){
int N,K;
cin >> N >> K;
int x = 1;
rep(i,N) x = min(x * 2, x + K);
cout << x << endl;
} | #define _GLIBCXX_DEBUG
#include"bits/stdc++.h"
using namespace std;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define OneToN(i,n) for(ll i=1;i<(ll)(n+1);i++)
#define ZeroToN(i,n) for(ll i=0;i<(ll)(n+1);i++)
#define AToB(i,a,b) for(ll i=a;i<(ll)(b+1);i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define BITSEARCH(bit, n) for (int bit = 0; bit < (1<<n); ++bit)
#define isOne(bit, i) bit & (1<<i)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define add push_back
template<typename T>
std::vector<T> slice(std::vector<T> const &v, int m, int n)
{
auto first = v.cbegin() + m;
auto last = v.cbegin() + n + 1;
std::vector<T> vec(first, last);
return vec;
}
#define remove_unique(v) v.erase(unique(ALL(v)), 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 (a>b) { a=b; return 1; } return 0; }
#define fir first
#define sec second
#define mp make_pair
#define ll long long
#define vec vector
#define cord2d pair<int,int>
#define intP pair<int, int>
template <class T> T get(){ T s; cin >> s; return(s);}
#define gi get<int>()
#define gs get<string>()
#define gll get<ll>()
template <class T> vector<T> getv(int n) { vec<T> v(n); REP(i, n) cin >> v[i]; return v; }
#define gim(n) getv<int>(n)
#define gsm(n) getv<string>(n)
#define gllm(n) getv<ll>(n)
void print(int a){ cout << a << endl; }
void print(long long a){ cout << a << endl; }
void print(string a){ cout << a << endl; }
void print(char a){ cout << a << endl; }
void print(double a){ cout << a << endl; }
void print(double a, int dig){ cout << std::setprecision(dig) << a << endl; }
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
template <class T = int>
void print(vec<T> v){ cout << v << endl; }
template <class T = int>
void print2dVec(vec<vec<T>> v2d){for(vec<T> v: v2d) {print(v);}}
void YesNo1(bool i = true){ return print(i?"Yes":"No"); }
void YESNO2(bool i = true){ return print(i?"YES":"NO"); }
#define var_name(var) #var
template <class T> void debug(T &var, int nest = 0, string before = "") { cout << string(" ", nest) << before; print(var); }
#define y0 y0__
#define y1 y1__
#define j0 j0__
#define j1 j1__
#define lamb(exp) [](auto i){return exp;}
#define isEven [](int i){return i % 2 == 0;}
#define isOdd [](int i){return i % 2 != 0;}
const ll INF = 1e18;
const int MOD = 1000000007;
int factorial(int k){ int sum = 1; for (int i = 1; i <= k; ++i) { sum *= i; } return sum; }
ll gcd(ll a, ll b) { if (b == 0) { return a; } return gcd(b, a % b); }
ll lcm(ll a, ll b) { ll temp = gcd(a, b); return temp ? (a / temp * b) : 0; }
void Main() {
int n = gi;
vec<string> strings = gsm(n);
int abCount = 0;
int topBCount = 0;
int bottomACount = 0;
int bothOK = 0;
REP(i, n) {
string str = strings[i];
REP(i2, str.size() - 1) {
if (str[i2] == 'A' && str[i2+1] == 'B') abCount ++;
}
if (*str.begin() == 'B') topBCount++;
if (*str.rbegin() == 'A') bottomACount++;
if (*str.begin() == 'B' && *str.rbegin() == 'A') bothOK++;
}
if (bothOK * 2 == topBCount + bottomACount) {
print(abCount + max(0, bothOK-1));
return;
}
print(abCount + min(topBCount, bottomACount));
}
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
Main();
} | 0 | 62,122,193 |
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
int main()
{
int n;
cin >> n;
int a, b, c, d;
a = n / 1000;
b = n / 100 - a * 10;
c = n / 10 - a * 100 - b * 10;
d = n - a * 1000 - b * 100 - c * 10;
int op1[8] = {1, 1, 1, 1, -1, -1, -1, -1};
int op2[8] = {1, 1, -1, -1, 1, 1, -1, -1};
int op3[8] = {1, -1, 1, -1, 1, -1, 1, -1};
char ans1 = '+';
char ans2 = '+';
char ans3 = '+';
for (int i = 0; i < 8; ++i)
{
int cal = a + b * op1[i] + c * op2[i] + d * op3[i];
if (cal == 7)
{
if (op1[i] == -1)
{
ans1 = '-';
}
if (op2[i] == -1)
{
ans2 = '-';
}
if (op3[i] == -1)
{
ans3 = '-';
}
break;
}
}
cout << a << ans1 << b << ans2 << c << ans3 << d << "=7" << endl;
} | #include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using ll = long long int;
int main(){
ll N; cin >> N;
vector<string> s(N);
for(int i=0; i<N; i++){
cin >> s[i];
}
ll c = 0;
ll a = 0;
ll b = 0;
ll d = 0;
for(int i=0; i<N; i++){
ll l = s[i].size();
for(int j=0; j<l-1; j++){
if(s[i][j] == 'A'&&s[i][j+1] == 'B'){
c++;
}
}
if(s[i][0] == 'B'){
b++;
}
if(s[i][l-1] == 'A'){
a++;
}
if(s[i][0] == 'B'&&s[i][l-1] == 'A'){
d++;
}
}
c += min(a, b);
if(d == a&&d == b&&d!=0){
c--;
}
cout << c;
} | 0 | 77,911,993 |
#include <iostream>
#include <string>
using namespace std;
int main(){
int N;
cin>>N;
string s[10000];
int a,b,c;
a=0;
b=0;
c=0;
long long answer=0;
for(int i=0;i<N;i++){
cin>>s[i];
for(int j=0;j<s[i].size()-1;j++){
if(s[i][j]=='A'&&s[i][j+1]=='B') answer++;
}
if(s[i][0]=='B') b++;
if(s[i][s[i].size()-1]=='A') a++;
if(s[i][0]=='B'&&s[i][s[i].size()-1]=='A') c++;
}
answer+=min(a,b);
if(a==b&&b==c&&a!=0) answer--;
cout<<answer<<endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int, int>pi;
typedef pair<long long, long long>pl;
#define F first
#define S second
#define pb push_back
#define all(x) x.begin() , x.end()
#define mp make_pair
#define FOR(i,a,b) for(i=a;i<=b;i++)
#define mem(a) memset(a , 0 ,sizeof a)
#define memn(a) memset(a , -1 ,sizeof a)
int main()
{
string s,t;
char ch;
cin>>s>>t;
cout<<t<<s<<endl;
} | 0 | 64,933,967 |
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;
int main() {
int N;
cin >> N;
vector<int> a(N);
rep(i, N) cin >> a[i];
int ans = 0;
REP(i, N) {
if (a[i] == a[i - 1]) {
++ans;
a[i] = 0;
}
}
cout << ans << endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define endl '\n'
#define mem(a,b) memset(a, b, sizeof(a) )
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define MOD 1000000007
const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
const ll mx=1e5+3;
ll k,n,w[mx];
ll dp[mx];
ll ks(ll i)
{
if(i>=n)
return 0;
if(dp[i]!=-1)
return dp[i];
ll c=INT_MAX;
for(int j=1; j<=k; j++)
{
if(i+j<=n)
c=min(c,abs(w[i]-w[i+j])+ks(i+j));
}
return dp[i]=c;
}
int main()
{
optimize();
for(int i=0; i<mx; i++)
{
dp[i]=-1;
}
cin>>n>>k;
for(int i=1; i<=n; i++)
cin>>w[i];
cout<<ks(1)<<endl;
return 0;
} | 0 | 99,144,606 |
#include <fstream>
#include <iostream>
using namespace std;
#define MOD 998244353
#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 lli long long int
#define pii pair<int,int>
#define add(a,b) ((int) (((lli) (a) + (b))%MOD))
#define mul(a,b) ((int) (((lli) (a) * (b))%MOD))
#define PB emplace_back
#define F first
#define S second
int N, M;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> N >> M;
if (N&1) {
N -= N&1;
F0R(i,M) cout << i+1 << ' ' << N-i << '\n';
} else {
F0R(i,M) {
if (N-2*i-1 <= N/2) cout << i+1 << ' ' << N-i-1 << '\n';
else cout << i+1 << ' ' << N-i << '\n';
}
}
} | #include <bits/stdc++.h>
using namespace std;
#define popcnt(a) __builtin_popcount(a)
#define FastIO() ios::sync_with_stdio(false), cin.tie(0);
#define IO() freopen("palindrome.in","rw",stdin)
#define error(args...) \
{ \
cerr<<"LINE "<<__LINE__; \
string _s = #args; \
replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); \
istream_iterator<string> _it(_ss); \
err(_it, args); \
cerr<<endl; \
}
void err(istream_iterator<string> it)
{
}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
cerr<<' '<< *it << " = " << a ;
err(++it, args...);
}
typedef long long ll;
const int N = 1e6+9, M = 1e2+9, OO = 0x3f3f3f3f,MOD = 1e9 + 7;
ll prexor[N],csum[N];
int main()
{
int n;
scanf("%d",&n);
for(int i=1;i<=n;++i)
{
int x;
scanf("%d",&x);
prexor[i]=prexor[i-1]^x;
csum[i]=csum[i-1]+x;
}
int r=1;
ll ans=0;
for(int l=1;l<=n;++l)
{
while(r<=n && (csum[r]-csum[l-1] == (prexor[r]^prexor[l-1]))) r++;
ans+=(r-l);
}
printf("%lld\n",ans);
#ifdef _LOCAL_DEFINE
cerr << (double)clock() * 1.0 / CLOCKS_PER_SEC << endl;
#endif
return 0;
} | 0 | 64,803,012 |
#include <bits/stdc++.h>
using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;
ll gcd(ll a, ll b) {
if(b == 0) return a;
return gcd(b, a % b);
}
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 modpow(ll a, ll n, ll mod) {
ll res = 1;
while (n > 0) {
if (n & 1) res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
vector<int> a(3), b(3);
rep(i, 3){
cin >> a[i] >> b[i];
}
bool ok = false;
for(int i = 0; i < 3; i++){
for(int j = 0; j < 3; j++){
for(int k = 0; k < 3; k++){
if(i==j || j==k || i==k) continue;
if(b[i]==a[j] && b[j]==a[k]){
ok = true;
break;
}
if(b[i]==a[j] && b[j]==b[k]){
ok = true;
break;
}
if(b[i]==b[j] && a[j]==a[k]){
ok = true;
break;
}
if(b[i]==b[j] && a[j]==b[k]){
ok = true;
break;
}
if(a[i]==a[j] && b[j]==a[k]){
ok = true;
break;
}
if(a[i]==a[j] && b[j]==b[k]){
ok = true;
break;
}
if(a[i]==b[j] && a[j]==a[k]){
ok = true;
break;
}
if(a[i]==b[j] && a[j]==b[k]){
ok = true;
break;
}
}
}
}
if(ok){
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 < (n); i++)
using ll = long long;
int main() {
int n;
string s;
cin >> n >> s;
int ans = 0;
rep(i,1000) {
string t;
int x = i;
rep(j,3) {
t += '0'+x%10;
x /= 10;
}
int ti = 0;
rep(j,n) {
if (s[j] == t[ti]) {
ti++;
if (ti == 3) break;
}
}
if (ti == 3) ans++;
}
cout << ans << endl;
} | 0 | 92,023,321 |
#include <cstdio>
#include <algorithm>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define reps(i,f,n) for(int i=(f); i<=(n); ++i)
using namespace std;
main()
{
int N, a[2000001], maxv = 0;
scanf("%d", &N);
rep(i, N)
scanf("%d", a+i),
maxv = max( maxv, a[i] );
int cnt[maxv + 1] = {-1};
int ret[N];
rep(i, N) ++cnt[ a[i] ];
reps(i, 1, maxv) cnt[i] += cnt[i-1];
for(int i=N-1; i>=0; --i){
int& p = cnt[ a[i] ];
ret[p] = a[i];
--p;
}
rep(i, N) printf("%d%c", ret[i], i+1 < N ? ' ' : '\n' );
} | #include <iostream>
#include <string>
#include <cstring>
#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 <cmath>
#include <numeric>
#include <float.h>
#include <math.h>
#include <sstream>
#include <iterator>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define vi vector<int>
#define vl vector<ll>
const long long INF = 1LL << 60;
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
int ctoi(char c) {
switch (c) {
case '0': return 0;
case '1': return 1;
case '2': return 2;
case '3': return 3;
case '4': return 4;
case '5': return 5;
case '6': return 6;
case '7': return 7;
case '8': return 8;
case '9': return 9;
default: return 0;
}
}
bool is_prime(const unsigned n){
switch(n){
case 0:
case 1: return false;
case 2:
case 3: return true;
}
if(n % 2 == 0 || n % 3 == 0) return false;
for(unsigned i = 5; i * i <= n; i += 6) {
if(n % i == 0) return false;
if(n % (i+2) == 0) return false;
}
return true;
}
map<ll,ll> mp;
ll primeFactorization(ll a){
ll i,sq;
if(a%2==0){
if(!mp.count(2)){
mp[2] = 1;
}
else{
mp[2] +=1;
}
return primeFactorization(a/2);
}
sq = sqrt(a);
for(i=3;i<=sq;i+=2){
if(a%i==0){
if(!mp.count(i)){
mp[i] = 1;
}
else{
mp[i] += 1;
}
return primeFactorization(a/i);
}
}
if(a!=1){
if(!mp.count(a))
mp[a] = 1;
else{
mp[a] += 1;
}
}
return 0;
}
ll kaizyou(ll n){
if(n == 1){
return 1;
}
else{
return (n * kaizyou(n-1)) % 1000000007;
}
}
int main(){
double W,H,x,y,a,b,s; cin >> W >> H >> x >> y;
a = W / 2;
b = H / 2;
s = W * H / 2;
if(a == x && b == y){
printf("%.9f 1\n",s);
}
else{
printf("%.9f 0\n",s);
}
} | 0 | 11,798,903 |
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
#define DEB(variable) cout << #variable << '=' << variable << endl
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(long long int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)
using llint = long long int;
constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;
int main(){
string s;cin>>s;
llint n = s.size();
vector<vector<llint>>dp(2, vector<llint>(n + 1, 0));
dp[0][0] = 1;
dp[1][0] = 2;
FOR(i,1,n){
if(s[i]=='1'){
dp[1][i] += dp[1][i - 1] * 2;
dp[0][i] += dp[1][i - 1] + dp[0][i - 1] * 3;
}else{
dp[1][i] = dp[1][i - 1];
dp[0][i] += dp[0][i - 1] * 3;
}
dp[1][i] %= mod;
dp[0][i] %= mod;
}
cout <<(dp[0][n-1]+ dp[1][n - 1])%mod << endl;
return 0;
} | #include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1ll << 60;
const double PI = 2 * asin(1);
int N, K; ll A[15];
int main(){
cin >> N >> K;
for (int i = 0; i < N; i++) cin >> A[i];
ll ans = INF;
for (int i = 0; i < pow(2, N); i++){
int num = i, cnt = 0;
ll Cost = 0, Highest = 0;
for (int j = 0; j < N; j++){
if (num % 2 != 0){
cnt++;
if (Highest < A[j]){
Highest = A[j];
}else{
Cost += Highest - A[j] + 1;
Highest++;
}
}else{
Highest = max(Highest, A[j]);
}
num /= 2;
}
if (cnt >= K) ans = min(Cost, ans);
}
cout << ans << endl;
return 0;
} | 0 | 32,088,541 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const int INF = 2e9;
template<class T> void print(const T& t){ cout << t << 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 gcd(int a,int b){return b?gcd(b,a%b):a;}
int main(){
ll h, w;
cin >> h >> w;
if(h==1||w==1){
print(1);
return 0;
}
ll ans = ((h * w + 1) / 2);
print(ans);
} | #include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <sstream>
#include <numeric>
#include <set>
#include <map>
#define rep(i, j) for(int i = 0; i < j; i++)
#define all(i) i.begin(), i.end()
using namespace std;
int main()
{
int num = 0;
while (cin >> num && num != 0)
{
string dat;
int l = 0, r = 0, h = 0, ans = 0;
rep(i, num)
{
cin >> dat;
switch (dat[0])
{
case 'r':
if (dat[1] == 'u') { r++; h++; }
else { r--; h--; }
break;
case 'l':
if (dat[1] == 'u') { l++; h++; }
else { l--; h--; }
break;
}
if (r + l + h == 4) { ans++; r = 0; l = 0; h = 0; }
else if (r + l + h == -4) {ans++; r = 0; l = 0; h = 0;}
}
printf("%d\n", ans);
}
return 0;
} | 0 | 87,763,747 |
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
void func(long long N, long long Z, long long W, std::vector<long long> a){
if(N==1)cout<<abs(a[N-1]-W)<<endl;
else cout<<max(abs(a[N-1]-W),abs(a[N-2]-a[N-1]))<<endl;
}
int main(){
long long N;
scanf("%lld",&N);
long long Z;
scanf("%lld",&Z);
long long W;
scanf("%lld",&W);
std::vector<long long> a(N);
for(int i = 0 ; i < N ; i++){
scanf("%lld",&a[i]);
}
func(N, Z, W, std::move(a));
return 0;
} | #include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define ALL(a) (a).begin(),(a).end()
int main() {
int n;
cin >> n;
REP(i, n) {
vector<int> v(3);
REP(j, 3) {
cin >> v[j];
}
sort(ALL(v));
if (pow(v[0],2)+pow(v[1],2)==pow(v[2],2)) cout << "YES" << endl;
else cout << "NO" << endl;
}
return 0;
} | 0 | 92,855,363 |
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX
#define INFLL LLONG_MAX
#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 per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; 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();
string s; cin >> s;
s = (s.size()%2 != 0) ? s.substr(0, s.size()-1) : s.substr(0, s.size()-2);
string s1 = "", s2 = "";
while(s.size()>1){
s1 = s.substr(0, s.size()/2);
s2 = s.substr(s.size()/2);
s = s.substr(0, s.size()-2);
if(s1 == s2) break;
}
cout << s1.size()*2 << endl;
} | #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 endl "\n"
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
ll A,B,K;
cin>>A>>B>>K;
for(int i=0;i<K;i++){
if(i%2==0){
if(A%2)A--;
B+=A/2;
A/=2;
}
else{
if(B%2)B--;
A+=B/2;
B/=2;
}
}
cout<<A<<" "<<B<<endl;
return 0;
} | 0 | 94,968,733 |
#include<cstdio>
#include<iostream>
#include<cctype>
#include<cstring>
using namespace std;
int main(){
int s;
char a[1001];
while(1){
scanf("%s",a);
if(a[0]=='0')break;
s=0;
for(int i=0;i<strlen(a);i++){
s+=(a[i]-'0');
}
cout<<s<<endl;
}
return 0;
} | #include <iostream>
using namespace std;
int main()
{
int n, a, b;
cin >>n >>a >>b;
int dist = b - a;
if(dist % 2 == 1){
cout <<"Borys\n";
}
else{
cout <<"Alice\n";
}
return 0;
} | 0 | 7,145,891 |
#include <iostream>
using namespace std;
main () {
int n, x;
while (cin >> n >> x, n) {
int a = 0;
for (int i=1; i<=n-2; i++)
for (int j=i+1; j<=n-1; j++)
for (int k=j+1; k<=n; k++)
if (i+j+k == x) a++;
cout << a << endl;
}
} | #include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
int32_t main()
{
int x,y;
cin>>x>>y;
if(x%y==0)puts("-1");
else cout<<x;
} | 0 | 89,730,101 |
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
#define int long long
signed main() {
string s,t;
cin >> s >> t;
sort(s.begin(),s.end());
sort(t.rbegin(),t.rend());
if(s < t) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} | #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include<numeric>
#include<cmath>
#include<stdio.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> pll;
const ll inf = 1LL << 60;
const int day = 24*3600;
int main(){
vector<int> ans;
while(true){
int n; cin>>n;
if(n == 0)break;
else{
vector<int> imos(day,0);
vector<int> ruiseki(day,0);
REP(i,n){
int a,b,c,d,e,f;
scanf("%d:%d:%d %d:%d:%d", &a,&b,&c,&d,&e,&f);
(void)getchar();
int start = 3600*a + 60*b + c;
int end = 3600*d + 60*e + f;
imos[start] += 1;
imos[end] -= 1;
}
ruiseki[0] = imos[0];
int maxi = 0;
REP(i,day-1){
ruiseki[i+1] = ruiseki[i] + imos[i+1];
maxi = max(maxi,ruiseki[i+1]);
}
ans.push_back(maxi);
}
}
REP(i,ans.size()){
cout<<ans[i] <<endl;
}
} | 0 | 24,445,617 |
#include<stdio.h>
int main(){
int i, n, s;
while (1) {
scanf("%d", &n);
if (n==0) {
break;
}
int ans = 0, maxv = 0, minv = 1000;
int score[n];
for (i = 0; i < n; i++) {
scanf("%d", &s);
if (s > maxv) {
maxv = s;
}
if (s < minv) {
minv = s;
}
score[i] = s;
}
for (i = 0; i < n; i++) {
ans += score[i];
}
printf("%d\n", (ans-maxv-minv)/(n-2));
}
return 0;
} | #include<bits/stdc++.h>
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
int main(){
ios_base::sync_with_stdio(0);
string s;
cin>>s;
int n = s.length();
if(s[0]!='A'){
cout<<"WA\n";
return 0;
}
bool flag = false;
for(int i=1;i<n;i++){
if(i>=2 && i<=n-2){
if(s[i]=='C'){
if(!flag) flag=true;
else{
cout<<"WA\n";
return 0;
}
}
else if(s[i]>=65 && s[i]<=90){
cout<<"WA\n";
return 0;
}
}
else if(s[i]>=65 && s[i]<=90){
cout<<"WA\n";
return 0;
}
}
if(!flag) cout<<"WA\n";
else cout<<"AC\n";
return 0;
} | 0 | 98,959,546 |
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <stack>
#include <functional>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#define rep(i,j,k) for(int i=j;i<k;i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF 1000000000
#define MOD 1000000007
#define pb push_back
#define MP make_pair
typedef long long ll;
typedef std::pair<int,int> pii;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
using namespace std;
int main() {
int n;cin>>n;
vector<vector<char>> v={{},{'.',',','!','?',' '},{'a','b','c'},{'d','e','f'},{'g','h','i'},{'j','k','l'},{'m','n','o'},{'p','q','r','s'},{'t','u','v'},{'w','x','y','z'}};
bool f=false;
rep(j,0,n){
string s;
cin>>s;
int x,t=-1;
rep(i,0,s.length()){
if(!f){
f=true;
x=s[i]-'0';
}
if(s[i]!='0'){
t++;
if(x==9||x==7){
if(t==4)t=0;
}else if(x==1){
if(t==5)t=0;
}else{
if(t==3)t=0;
}
}else {
if(t!=-1)cout<<v[x][t];
f=false;
t=-1;
}
}
cout<<endl;
}
return 0;
} | #include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
int main(){
ll N;
cin >> N;
ll A[N];
ll B[N];
rep(i, N - 1){
cin >> B[i];
}
B[N - 1] = 100001;
ll ans = 0;
rep(i, N){
if(i == 0){
A[i] = B[i];
}else{
A[i] = min(B[i - 1], B[i]);
}
ans += A[i];
}
cout << ans << endl;
return 0;
} | 0 | 55,734,072 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ull unsigned long long
#define ld long double
#define lll __int128
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vector<int> >
#define pii pair<int,int>
#define piii pair<int,pair<int,int> >
#define pll pair<ll,ll>
#define vii vector<pii>
#define min_pq priority_queue<int,vector<int>,greater<int> >
#define sz(v) ((int)(v).size())
#define all(s) s.begin(),s.end()
#define allr(s) s.rbegin(),s.rend()
#define unq(c) (sort(all(c)), c.resize(distance(c.begin(),unique(all(c)))))
#define get_pos(c,x) (lower_bound(all(c),x)-c.begin())
#define MS0(v) memset((v), 0, sizeof((v)))
#define MS1(v) memset((v), -1, sizeof((v)))
#define LEN(v) strlen(v)
#define MP make_pair
#define pb push_back
#define pob pop_back
#define ff first
#define ss second
#define sc scanf
#define pf printf
#define endl "\n"
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a)*((b)/gcd(a,b)))
#define shuffle(v) (random_shuffle(all(v)))
#define min_ele(v) (*min_element(all(v)))
#define max_ele(v) (*max_element(all(v)))
#define is_equal(x, y) (abs(x-y)<eps)
#define cnt_ele(v, x) (count(all(v), x))
#define sum_ele(v) (accumulate(all(v),0))
#define pro_ele(v) (accumulate(all(v),1, multiplies<int>()))
#define init_range(v, x) (iota(all(v),x))
#define ran(a, b) ((((rand() << 15) ^ rand()) % ((b) - (a) + 1)) + (a))
inline int random(int _min, int _max) { static bool first = true; if (first) { srand(time(NULL)); first = false; } return _min + rand() % (( _max + 1 ) - _min); }
#define TEST_CASE int ___T; cin>>___T; for(int cs=1;cs<=___T;cs++)
#define PRINT_CASE cout << "Case " << cs << ": ";
#define PRINT_CASEN cout << "Case " << cs << ":\n";
template<class T>inline bool read(T &x) {int c=getchar();int sgn=1;while(~c&&c<'0'||c>'9'){if(c=='-')sgn=-1;c=getchar();}for(x=0;~c&&'0'<=c&&c<='9';c=getchar())x=x*10+c-'0'; x*=sgn; return ~c;}
#define vpf(v) for(int i=0;i<v.size();i++){cout<<v[i];if(i!=v.size()-1)cout<<" ";else cout<<"\n";}
#define vsc(v) for(int i=0;i<v.size();i++)cin>>v[i];
#define FOR(i, a, b, stp) for(int i = (a); i <= (b); i+=stp)
#define ROF(i, a, b, stp) for(int i = (a); i >= (b); i-=stp)
#define intmx INT_MAX
#define inf 1llu<<61
#define PI 3.14159265358979323846264338327950L
#define MOD 1000000007
#define MAX 100010
#define eps 1e-9
inline ll exp(ll a, ll b) { a %= MOD; ll res = 1; while (b > 0) { if(b & 1) { res = res * a % MOD; } a = a * a % MOD; b >>= 1; } return res; }
inline int add(int a, int b) { a += b; if(a >= MOD) a -= MOD; return a; }
inline int sub(int a, int b) { a -= b; if(a < MOD) a += MOD; return a; }
inline int multi(ll a, ll b) { a *= b; if(a >= MOD) a %= MOD; return a; }
inline int on_bit(int N,int pos) {return N = N | (1<<pos);}
inline int off_bit(int N,int pos) {return N = N & ~(1<<pos);}
inline bool check_bit(ll N,int pos) {return (bool)(N & (1<<pos));}
#define on_bit_cnt(x) (__builtin_popcount(x))
#define on_bit_cntll(x) (__builtin_popcountll(x))
#define start_clock clock_t tStart = clock()
#define end_clock printf("\n>>Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define fileio freopen("in.txt","r",stdin);freopen("out.txt","w",stdout)
int main() {
ll n, k; cin >> n >> k;
ll ans = 0;
for(ll i = k; i <= n+1; i++) {
ll lo = (i*(i-1))/2;
ll hi = ((n*(n+1))/2) - (((n-i) * (n-i+1))/2);
ans += (hi-lo+1);
if(ans > MOD) ans = ans % MOD;
}
cout << ans << "\n";
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
string N;
int64_t K;
cin >> N;
cin >> K;
int64_t n = N.size();
int64_t dp[110][2][4] = {0};
int64_t n0 = N[0] - '0';
dp[0][0][1] = 1;
dp[0][1][0] = 1;
dp[0][1][1] = n0 - 1;
for ( int64_t i = 1; i < n; ++i){
int64_t ni = N[i] - '0';
if ( ni == 0 ){
for ( int64_t j = 0; j <= K; ++j){
dp[i][0][j] = dp[i][0][j] + dp[i-1][0][j];
}
} else {
for ( int64_t j = 0; j <= K - 1 ; ++j){
dp[i][0][j+1] = dp[i][0][j+1] + dp[i-1][0][j];
}
for ( int64_t j = 0; j <= K - 1 ; ++j){
dp[i][1][j+1] = dp[i][1][j+1] + ( ni - 1 ) * dp[i-1][0][j];
}
for ( int64_t j = 0; j <= K; ++j){
dp[i][1][j] = dp[i][1][j] + dp[i-1][0][j];
}
}
for ( int64_t j = 0; j <= K; ++j){
dp[i][1][j] = dp[i][1][j] + dp[i-1][1][j];
}
for ( int64_t j = 0; j <= K-1; ++j){
dp[i][1][j+1] = dp[i][1][j+1] + 9 * dp[i-1][1][j];
}
}
cout << dp[n-1][0][K] + dp[n-1][1][K] << endl;
return 0;
} | 0 | 58,643,748 |
#include <cassert>
#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>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#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>
#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>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
#define Sort(v) sort(all(v))
#define LINF (1LL<<40)
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define MP make_pair
#define int long long
#define umap unordered_map
#define re0 return 0
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
const long long MOD=1000000007LL;
bool isupper(char c){if('A'<=c&&c<='Z')return 1;return 0;}
bool islower(char c){if('a'<=c&&c<='z')return 1;return 0;}
bool isnumber(char c){return ('0'<=c&&c<='9');}
bool isalpha(char c){return (isupper(c)||islower(c));}
bool is_kaibun(string s){string rs = s;reverse(all(rs));if(s == rs)return true;else return false;}
template<typename T>
void printv(vector<T> v, bool is_endl=true){
for(int i=0;i<v.size();i++){
if(i)cout<<" ";
cout<<v[i];
}
if(is_endl)cout<<endl;
}
int INF=1e18;
template<typename T>
void printendl(vector<T> v){
for(auto date:v)cout<<date<<endl;
}
template<typename T>
void printvv(vector<vector<T>> v){
for(int i=0;i<v.size();i++){
for(int j=0;j<v[i].size();j++){
if(j)cout<<" ";
cout<<v[i][j];
}
cout<<endl;
}
}
struct Point{
int x,y,num;
double e_dis(Point other){
return sqrt((x-other.x)*(x-other.x)+(y-other.y)*(y-other.y));
}
};
int gcd(int a,int b){
if(b==0)return a;
else return gcd(b,a%b);
}
bool isPrime(int x){
if(x==1)return 0;
if(x==2)return 1;
if(x%2==0)return 0;
for(int i=3;i*i<=x;i++)if(x%i==0)return 0;
return 1;
}
vector<string> split(string s, char c){
if(s[s.size()-1]!=c)s+=c;
vector<string> v;
int pos=0;
rep(i,0,s.size()){
if(s[i]==c){
v.push_back(s.substr(pos,i-pos));
pos=i+1;
}
if(i==s.size()-1 && s.substr(pos,i-pos)!="")v.push_back(s.substr(pos,i-pos));
}
return v;
}
int f(int x){
return (3*x*x+x)/2;
}
signed main(){
int a,b,c;
cin>>a>>b>>c;
vector<int> va(a),vb(b);
rep(i,0,a)cin>>va[i];
rep(i,0,b)cin>>vb[i];
int ans=1e9;
rep(i,0,c){
int x,y,t;
cin>>x>>y>>t;
x--; y--;
ans=min(ans, max(0LL,va[x]+vb[y]-t));
}
int mia=*min_element(all(va));
int mib=*min_element(all(vb));
ans=min(ans, mia+mib);
cout<<ans<<endl;
} | #pragma GCC optimize("O4")
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define MOD (ll)(1e9+7)
#define INF 1e17
#define int ll
#define EPS (1e-6)
using namespace std;
using ll=long long;
using pii=pair<int,int>;
int gcd(int a,int b) { return b==0?a:gcd(b,a%b); }
int lcm(int a,int b) { return a/gcd(a,b)*b; }
int fpow(int b,int p)
{
if(p==0) return 1;
int h=fpow(b,p/2);
if(p%2) return h*b%MOD*h%MOD;
return h*h%MOD;
}
int dp[5010][5010];
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n; cin>>n;
int all=0;
vector<int> v(n);
for(auto &i:v){
cin>>i;
all^=i;
}
all=(~all);
for(auto &i:v){
i=i&all;
}
int now=0;
for(int i=60;i>=0;i--){
For(j,now,n-1){
if(v[j]&(1ll<<i) && v[j]>v[now])
swap(v[j],v[now]);
}
if(!(v[now]&(1ll<<i))) continue;
For(j,0,n-1){
if(j!=now && v[j]&(1ll<<i))
v[j]^=v[now];
}
now++;
}
int mx=0;
for(auto &i:v) mx^=i;
cout<<(mx*2+(~all))<<"\n";
return 0;
} | 0 | 47,217,956 |
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
#define INF (int)(1e9)
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,start,end) for(int i=(start);i<=(end);i++)
#define all(n) begin(n),end(n)
#define DEBUG
int main()
{
int x,y;
cin >> x >> y;
cout << x + y/2 << endl;
return 0;
} | #include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<sstream>
#include<string>
#include<numeric>
#include<complex>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main(){
int n;
cin >> n;
vector<ll> a(n+1);
a[n] = 0;
ll cnt = 0;
ll ans = 0;
rep(i, n+1) {
cin >> a[i];
if ( a[i] == 0 ) {
ans += cnt / 2;
cnt = 0;
}
else {
cnt += a[i];
}
}
cout << ans << endl;
return 0;
} | 0 | 90,103,358 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char** argv) {
int h1,h2,m1,m2;
int k;
cin>>h1>>m1>>h2>>m2>>k;
cout<<max(0,(h2-h1)*60+(m2-m1)-k);
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define maxn 300005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define pii pair<int,int>
const int mod = 1e9 + 7;
set<int>st;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
st.insert(0);
st.insert(n+1);
vector<pair<int,int>>v;
f1(n) {
int x;
cin >> x;
v.pb({x,i});
}
sort(all(v));
reverse(all(v));
ll ans = 0;
for (auto &i : v) {
auto x = st.lower_bound(i.S);
if (*x != n + 1) {
ans += (ll)i.F * (*next(x)-*x) * (i.S - *prev(x));
}
x = prev(x);
if (*x != 0) {
ans += (ll)i.F * (*next(x) - i.S) * (*x - *prev(x));
}
st.insert(i.S);
}
cout << ans << '\n';
} | 0 | 97,999,816 |
#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>
#define ArraySizeOf(array) (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
unsigned day;
if (dow < dow1) dow += 7;
day = dow - dow1;
day += 7 * n - 6;
return day;
}
unsigned DayToWeekNumber(unsigned day)
{
return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main() {
int N; cin >> N;
long long A = 0;
vector<int>d(N);
rep(i, N)cin >> d[i];
rev(i, N) rev(j, i)A += d[i] * d[j];
cout << A << endl;
} | #include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
if(a>b){
a = b; return true;
}
else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
if(a<b){
a = b; return true;
}
else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
int main(){
string s; cin >> s;
ll left = 0, right = s.size()-1;
ll ans = 0;
while(left < right){
if(s[left] != s[right]){
if(s[left]=='x'){
ans++;
left++;
}else if(s[right]=='x'){
ans++;
right--;
}else{
puts("-1");
return 0;
}
}else{
left++;
right--;
}
}
cout << ans << endl;
} | 0 | 22,786,642 |
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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; }
signed main(){
cin.tie(0);
ios::sync_with_stdio(0);
int n;cin>>n;
vector<ll> a(n);
priority_queue<pair<ll,int>> q;
rep(i,n){
cin>>a[i];
q.push(make_pair(a[i],-i));
}
vector<ll> cnt(n);
int mugen=0,idx=INF;ll num=q.top().first;
while(!q.empty()){
while(!q.empty()&&(q.top()).first==num){
idx=min(idx,-q.top().second);
q.pop();mugen++;
}
ll nextnum=q.empty()?0ll:q.top().first;
cnt[idx]+=(num-nextnum)*mugen;
num=nextnum;
}
for(auto x:cnt)cout<<x<<endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;
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;}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
string s; cin >> s;
int n[4];
rep(i, 4) n[i] = s[i]-'0';
rep(i, 1<<3) {
int sum = n[0];
string ans;
ans += s[0];
rep(j, 3) {
if((i>>j)&1) {
sum += n[j+1];
ans += '+';
} else {
sum -= n[j+1];
ans += '-';
}
ans += s[j+1];
}
if(sum == 7) {
cout << ans << "=7" << endk;
return 0;
}
}
return 0;
} | 0 | 11,835,867 |
#include <bits/stdc++.h>
#define ri register
#define int long long
#define E (n+1)
using namespace std; const int N=200010;
inline int read()
{
int s=0, w=1; ri char ch=getchar();
while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
return s*w;
}
int n,a[N];
signed main()
{
n=read();
for(ri int i=1;i<=n;i++) a[i]=read();
sort(a+1,a+1+n);
int pp=unique(a+1,a+1+n)-a-1;
printf("%lld\n",pp-(pp%2==0));
return 0;
} | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
int main(){
int n,k;
cin>>n>>k;
long double ans=0;
for(int i=1;i<=n;i++){
int x=0;
int tmp=i;
long double xx=1;
while(tmp<k){
x++;
tmp*=2;
xx/=(long double)2;
}
ans+=xx;
}
ans/=(long double)n;
cout<<fixed<<setprecision(12)<<ans<<endl;
} | 0 | 7,663,507 |
#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;
cin >> n;
vector<int> a(n);
rep(i, n) cin >> a[i];
vector<ll> cum(n+1);
cum[0] = 0;
rep(i, n) cum[i+1] = cum[i] + a[i];
sort(cum.begin(), cum.end());
ll ans = 0;
ll now = cum[0];
while (1) {
int ib = lower_bound(cum.begin(), cum.end(), now) - cum.begin();
int ie = upper_bound(cum.begin(), cum.end(), now) - cum.begin();
ans += (ll)(ie - ib) * (ie - ib - 1) / 2;
if (ie == cum.size()) break;
now = cum[ie];
}
cout << ans << endl;
return 0;
} | #include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define elnd endl
const ll INF = 1LL << 60;
void solve(long long N, long long M, std::vector<long long> A){
vll S(N+1, 0);
REP(i, N) S[i+1] = (S[i] + A[i]) % M;
ll total = (S[N] - S[0]) % M;
map<ll, vll> R;
REP(r, N){
ll x = S[N]-S[r+1];
if(x < 0 ) x+= M;
if(R.count(x)){
R[x].push_back(r+1);
}
else{
R[x] = vll(1, r+1);
}
}
ll cnt = 0;
REP(l, N){
ll tmp = (total - S[l]) % M;
if(tmp < 0) tmp += M;
if(!R.count(tmp)) continue;
cnt += R[tmp].end() - upper_bound(ALL(R[tmp]), l);
}
cout<<cnt<<endl;
}
int main(){
long long N;
scanf("%lld",&N);
long long M;
scanf("%lld",&M);
std::vector<long long> A(N);
for(int i = 0 ; i < N ; i++){
scanf("%lld",&A[i]);
}
solve(N, M, std::move(A));
return 0;
} | 0 | 22,777,152 |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double db;
typedef std::string str;
#define sei set<int>
#define sell set<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define vvll vector<vll>
#define vld vector<ld>
#define vstr vector<str>
#define vpii vector<pii>
#define vpll vector<pll>
#define all(v) v.begin(),v.end()
#define foa(i,v) for(auto i : v)
#define fo(i,a,b) for(int i=a;i<b;i++)
#define fo_(i,a,b) for(int i=a;i>b;i--)
#define M(a) memset(a,0,sizeof a)
#define M_(a) memset(a ,-1,sizeof a)
#define deb(x) cerr << #x << " = " << x << endl
#define pb push_back
#define pob pop_back
#define F first
#define S second
#define OK order_of_key
#define FO find_by_order
#define nmax 1000100
const ld PI = 3.141592653589793238462643383279;
const ll inf = std::numeric_limits<ll>::max();
const int infint = std::numeric_limits<int>::max();
const ll mod = 1e9+7;
using namespace __gnu_pbds;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int n,m,a,b;
cin >> n >> m >> a >> b;
fo(i,0,b){
fo(j,0,a) cout << 1;
fo(j,a,m) cout << 0;
cout << '\n';
}
fo(i,b,n){
fo(j,0,a) cout << 0;
fo(j,a,m) cout << 1;
cout << '\n';
}
return 0;
} | #include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>
using namespace std;
#define vsort(v) sort(v.begin(), v.end())
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
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; }
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;
#define MAX_V 1000000
#define MAX_N 16
int n, k;
ll a[MAX_N], copy_a[MAX_N];
void input() {
cin >> n >> k;
rep(i, 0, n) cin >> a[i];
memcpy(copy_a, a, sizeof(a));
}
bool validate(ll a[]) {
int cnt = 1;
ll max_v = a[0];
rep(i, 1, n) {
if(a[i] > max_v) {
max_v = a[i];
++cnt;
}
}
return cnt >= k;
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
input();
ll rsl = 1e18;
for(int bit = 0; bit < (1 << n); ++bit) {
ll tmp = 0, max_v = copy_a[0];
memcpy(copy_a, a, sizeof(a));
for(int mask = 0; mask < n; ++mask) {
if(bit & (1 << mask)) {
if(mask == 0) continue;
tmp += max(0ll, max_v - copy_a[mask] + 1);
copy_a[mask] = max(max_v + 1, copy_a[mask]);
}
max_v = max(max_v, copy_a[mask]);
}
if(validate(copy_a)) {
chmin(rsl, tmp);
}
}
cout << rsl << endl;
} | 0 | 97,191,348 |
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
vector<int> a(n);
for(int i = 0; i < n; i++) {
cin >> a[i];
a[i]--;
}
int ans = 0;
for(int i = 0; i < n; i++)
if (a[a[i]] == i)
ans++;
ans /= 2;
cout << ans << '\n';
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const int INF = 1001001001;
const int MOD = 1000000007;
template <typename T>
void print(const T &v);
int main()
{
ll H, W;
cin >> H >> W;
ll s1, s2, s3, s4, s5, s6;
ll a1, b1;
a1 = H / 3;
b1 = (H - a1 + 1) / 2;
s1 = (abs(b1 - a1) * W);
ll a2, b2;
a2 = W / 3;
b2 = (W - a2 + 1) / 2;
s2 = (abs(b2 - a2) * H);
ll a3, b3, c3;
a3 = (H + 2) / 3;
b3 = (H - a3) * (W / 2);
c3 = (W * H) - (a3 * W) - b3;
a3 *= W;
s3 = max(max(abs(a3 - b3), abs(b3 - c3)), abs(c3 - a3));
ll a4, b4, c4;
a4 = (W + 2) / 3;
b4 = (W - a4) * (H / 2);
c4 = (W * H) - (a4 * H) - b4;
a4 *= H;
s4 = max(max(abs(a4 - b4), abs(b4 - c4)), abs(c4 - a4));
ll a5, b5, c5;
a5 = H / 3;
b5 = (H - a5) * (W / 2);
c5 = (W * H) - (a5 * W) - b5;
a5 *= W;
s5 = max(max(abs(a5 - b5), abs(b5 - c5)), abs(c5 - a5));
ll a6, b6, c6;
a6 = W / 3;
b6 = (W - a6) * (H / 2);
c6 = (W * H) - (a6 * H) - b6;
a6 *= H;
s6 = max(max(abs(a6 - b6), abs(b6 - c6)), abs(c6 - a6));
ll ans = min(min(min(s1, s2), min(s3, s4)), min(s5, s6));
cout << ans << endl;
return 0;
}
template <typename T>
void print(T const &v)
{
for (int i = 0; i < v.size(); i++)
{
if (i)
cout << " ";
cout << v[i];
}
cout << endl;
} | 0 | 74,140,521 |
#include <iostream>
#include<stdio.h>
using namespace std;
int main(void){
int a,b,x,y;
cin>>a>>b;
double z;
x = a/b;
y = a%b;
z = 1.0 * a/b;
cout<<x<<" "<<y<<" ";
printf("%.6lf\n", z);
} | #include <bits/stdc++.h>
#define INF 1e9
using namespace std;
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a) (a).begin(),(a).end()
#define endl "\n"
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
typedef long long ll;
void solve() {
int N,K;
cin >> N >> K;
vector<ll> vmx(N+2,0);
vector<ll> vmn(N+2,0);
REP(i,N+1) {
vmx[i+1] = (N-i) + vmx[i];
vmn[i+1] = i + vmn[i];
}
ll sm = 0;
FOR(i,K,N+2) sm+= (vmx[i]-vmn[i]+1);
cout << (sm%ll(1e9+7)) << endl;
}
int main() {
solve();
return 0;
} | 0 | 58,751,568 |
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s,t;
cin>>s>>t;
int c=0;
if(s.length()==t.length())
{
for(int i=0;i<s.length();i++)
{
if(s[i]!=t[i])
c++;
}
}
cout<<c;
} | #include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 998244353
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
int N; cin>>N;
map<int,int> M;
vi A(N);
int ans=1;
rep(i,0,N){
cin>>A[i];
if(i!=0&&A[i]==0)
ans=0;
M[A[i]]++;
}
for(auto p:M){
if(p.first>0){
rep(i,0,p.second){
ans*=M[p.first-1];
ans%=MOD;
}
}
}
cout<<ans<<endl;
} | 0 | 44,720,967 |
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pll;
#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)
const ll MOD = 1000000007;
const ll INF = (ll) 1e15;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll N, R;
cin >> N >> R;
if (N >= 10)
cout << R << endl;
else
cout << R + 100 * (10 - N) << endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld= long double;
using ull= unsigned long long;
#define endl "\n"
const ll maxn=3e5+100;
const ll maxx=1e13;
const ll mod=1000000007;
map<ll,ll> mp;
ll f[maxn];
ll a[maxn];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll n, k;
cin>>n>>k;
for (int i=1;i<=n;i++)
{
cin>>a[i];
a[i]=a[i]-1+k;
a[i]%=k;
}
f[0]=0;
for (int i=1;i<=n;i++)
{
f[i]=(f[i-1]+a[i])%k;
}
ll kq=0;
for (int i=1;i<=n;i++)
{
ll t=i-k;
if (t>0)
{
mp[f[t]]--;
}
if (f[i]==0)
{
kq=kq+mp[0];
if (i<k) kq++;
}
else
{
kq=kq+mp[f[i]];
}
mp[f[i]]++;
}
cout << kq;
} | 0 | 93,228,989 |
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <cstdlib>
#include <deque>
#include <stack>
#include <bitset>
#include <cassert>
#include <map>
#include <set>
#include <cassert>
#include <iomanip>
#include <random>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
#define __FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define __FileRead freopen ("input.txt", "r", stdin)
#define __FileWrite freopen ("output.txt", "w", stdout)
#define SET(a,v) memset(a,v,sizeof(a))
#define SZ(v) (int)v.size()
#define pii pair<int,int>
#define pil pair <int, ll>
#define pli pair <ll, int>
#define pll pair <ll, ll>
#define debug cout <<"######\n"
#define debug1(x) cout <<"### " << x << " ###\n"
#define debug2(x,y) cout <<"# " << x <<" : "<< y <<" #\n"
#define nl cout << "\n";
#define sp cout << " ";
#define sl(n) scanf("%lld", &n)
#define sf(n) scanf("%lf", &n)
#define si(n) scanf("%d", &n)
#define ss(n) scanf("%s", n)
#define pf(n) scanf("%d", n)
#define pfl(n) scanf("%lld", n)
#define all(v) v.begin(), v.end()
#define rall(v) v.begin(), v.end()
#define srt(v) sort(v.begin(), v.end())
#define r_srt(v) sort(v.rbegin(), v.rend())
#define rev(v) reverse(v.rbegin(), v.rend())
#define Sqr(x) ((x)*(x))
#define Mod(x, m) ((((x) % (m)) + (m)) % (m))
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define un_map unordered_map
#define un_set unordered_set
#define pb push_back
#define mk make_pair
#define F first
#define S second
#define MAX 100005
#define INF 1000000009
#define MOD 1000000007
template<class T>
using min_heap = priority_queue<T, std::vector<T>, std::greater<T>>;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
tree_order_statistics_node_update>;
template <typename T> string toString ( T Number ) {
stringstream ss;
ss << Number;
return ss.str();
}
template<typename T> int toInt (T str) {
stringstream ss;
ss << str;
int num;
ss >> num;
return num;
}
struct custom_hash {
static uint64_t splitmix64 (uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30) ) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27) ) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator() (uint64_t x) const {
static const uint64_t FIXED_RANDOM =
chrono::steady_clock::now().time_since_epoch().count();
return splitmix64 (x + FIXED_RANDOM);
}
};
ll lcm ( ll a, ll b ) {
return ( a / __gcd ( a, b ) ) * b;
}
int main () {
int n;
cin >> n;
ll cnt = 0;
for (int i = 1; i < n; i++) {
cnt += (n - 1) / i;
}
cout << cnt << "\n";
return 0;
} | #include <iostream>
#include <cstdio>
#include <set>
using namespace std;
int main(){
long long n;
cin >> n;
set<string> T;
string pre_word;
for(long long i = 0; i < n; i++){
string word;
cin >> word;
if(i == 0){
T.insert(word);
pre_word = word;
continue;
}
if(T.find(word) != T.end()){
printf("No\n");
return 0;
}
else{
if(word[0] != pre_word[pre_word.size()-1]){
printf("No\n");
return 0;
}
else{
T.insert(word);
pre_word = word;
}
}
}
printf("Yes\n");
return 0;
} | 0 | 40,798,252 |
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define fi first
#define se second
int main(void) {
int A;
int B;
int C;
cin >> A;
cin >> B;
cin >> C;
if ( A == B && B != C ) {
cout << C << endl;
}
else if ( A == C && A != B ) {
cout << B << endl;
}
else {
cout << A << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
vector<int> v(4);
rep(i, 3) {
int a, b;
cin >> a >> b;
a--; b--;
v[a]++; v[b]++;
}
sort(v.rbegin(), v.rend());
if (v[0] == 2 && v[1] == 2) cout << "YES" << endl;
else cout << "NO" << endl;
return 0;
} | 0 | 39,239,291 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main () {
string s, t;
cin >> s >> t;
int ans = 0;
if(s[0] == t[0]) ans++;
if(s[1] == t[1]) ans++;
if(s[2] == t[2]) ans++;
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
int main() {
int N;
cin >> N;
string S;
cin >> S;
vector<int> r(N + 1), g(N + 1), b(N + 1);
for (int i = 1; i < N + 1; i++) {
r[i] += r[i - 1] + (S[i - 1] == 'R');
g[i] += g[i - 1] + (S[i - 1] == 'G');
b[i] += b[i - 1] + (S[i - 1] == 'B');
}
ll ans = 0;
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
if (S[i] == S[j]) continue;
if ((S[i] == 'R' && S[j] == 'G') || (S[j] == 'R' && S[i] == 'G')) {
ans += b[N] - b[j + 1];
if (2 * j - i < N && S[2 * j - i] == 'B') ans--;
}
if ((S[i] == 'G' && S[j] == 'B') || (S[j] == 'G' && S[i] == 'B')) {
ans += r[N] - r[j + 1];
if (2 * j - i < N && S[2 * j - i] == 'R') ans--;
}
if ((S[i] == 'B' && S[j] == 'R') || (S[j] == 'B' && S[i] == 'R')) {
ans += g[N] - g[j + 1];
if (2 * j - i < N && S[2 * j - i] == 'G') ans--;
}
}
}
cout << ans << endl;
} | 0 | 74,459,228 |
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int n;
cin>>n;
if(n<1200) cout<<"ABC";
else cout<<((n<2800)?"ARC":"AGC");
return 0;
} | #include <algorithm>
#include <iostream>
#include <numeric>
#include <unordered_map>
#include <vector>
std::vector<long long> solve(int H, int W, const std::vector<std::pair<int, int>> &points)
{
std::unordered_map<long long, int> map;
for (const auto &p : points)
{
int i1 = std::max(p.first - 2, 0);
int i2 = std::min(p.first, H - 3);
int j1 = std::max(p.second - 2, 0);
int j2 = std::min(p.second, W - 3);
for (int i = i1; i <= i2; ++i)
{
for (int j = j1; j <= j2; ++j)
{
long long key = (long long)i << 32 | j;
if (map.count(key) == 0) { map[key] = 0; }
++map[key];
}
}
}
std::vector<long long> counts(10);
for (const auto &pair : map) { ++counts[pair.second]; }
int sum = std::accumulate(counts.begin(), counts.end(), 0);
counts[0] = (long long)(H - 2) * (long long)(W - 2) - sum;
return counts;
}
int main()
{
int H, W, N;
std::cin >> H >> W >> N;
std::vector<std::pair<int, int>> points(N);
for (int i = 0; i < N; ++i)
{
int a, b;
std::cin >> a >> b;
points[i] = std::make_pair(a - 1, b - 1);
}
for (long long n : solve(H, W, points)) { std::cout << n << std::endl; }
} | 0 | 26,678,820 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(20);
int n,k;
cin>>n>>k;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
ll ans = 1e17;
for(int bit=0;bit<(1<<n);bit++){
int cnt = 0;
int now = 0;
ll cost = 0;
for(int i=0;i<n;i++){
if(a[i] > now){
cnt++;
now = a[i];
}
else if(bit & (1<<i)){
now++;
cost += now - a[i];
cnt++;
}
}
if(cnt >= k)chmin(ans,cost);
}
cout << ans << endl;
} | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset
typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
char to_upper (char x){
if( 97 <= int(x) && int(x) <= 126)return char(x-32);
else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
if( 97 <= int(x) && int(x) <= 126)return x;
else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
if(48 <= int(x) && int(x) <= 57)return int(x-'0');
else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
int k;
vpii adj[100010];
bool vis[100010];
ll dist[100010];
void dijkstra(){
for(int i=0;i<k;i++)dist[i]=INT_MAX;
priority_queue < pii > q;
q.push(mp(0,1));
dist[1] = 0;
while(!q.empty()){
int node = q.top().se;
q.pop();
if(!vis[node]){
vis[node]=true;
for(int i=0;i<adj[node].size();i++){
int nex = adj[node][i].fi;
int w = adj[node][i].se;
if(dist[nex] > dist[node] + w){
dist[nex] = dist[node] + w;
q.push(mp(-dist[nex],nex));
}
}
}
}
}
int main(){
cin>>k;
for(int i=0;i<k;i++){
adj[i].pb(mp((i+1)%k,1));
adj[i].pb(mp((i*10)%k,0));
}
dijkstra();
cout<<dist[0]+1<<newl;
} | 0 | 30,526,674 |
#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(){
double w, h, x, y;
cin >> w >> h >> x >> y;
double s = w*h/2.0;
printf("%.10f ",s);
if(w/2.0 == x && h/2.0 == y) cout << 1;
else cout << 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using Graph = vector<vector<int>>;
using Edge = map<pair<int,int>,int>;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
std::fill( (T*)array, (T*)(array+N), val );
}
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()
{
cout << fixed << setprecision(15);
ll H, W, M;
cin >> H >> W >> M;
vector<ll> Mh(M);
vector<ll> Mw(M);
vector<ll> h(H+1, 0);
vector<ll> w(W+1, 0);
REP(i, M){
ll x;
ll y;
cin >> x >> y;
Mh[i] = x;
Mw[i] = y;
h[x]++;
w[y]++;
}
vector<ll> hq(H+1);
vector<ll> wq(W+1);
REP(i, H+1){
hq.push_back(h[i]);
}
REP(i, W+1){
wq.push_back(w[i]);
}
sort(hq.rbegin(), hq.rend());
sort(wq.rbegin(), wq.rend());
ll now = hq[0];
ll hcount = 0;
REP(i, H){
if(hq[i] == now) hcount++;
else break;
}
now = wq[0];
ll wcount = 0;
REP(i, W){
if(wq[i] == now) wcount++;
else break;
}
ll maxcount = hcount * wcount;
ll ans = hq[0] + wq[0];
ll temp_count = 0;
REP(i, M){
if(h[Mh[i]] + w[Mw[i]] == ans) temp_count++;
}
if(temp_count < maxcount){
cout << ans << endl;
}
else{
cout << ans-1 << endl;
}
return 0;
} | 0 | 48,922,841 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
#define all(v) v.begin(), v.end()
const ll mod=1000000007;
ll countBits(ll in){
int res=0;
for(;in>0;in>>=1){
if((in&0x01)!=0){
res++;
}
}
return res;
}
template<typename T>
void show2dVector(vector<vector<T>>& v){
for(int i=0;i<v.size();i++){
int m=v[i].size();
cout<<i<<" : ";
for(int j=0;i<m;i++){
cout<<v[i][j]<<" ";
}
cout<<endl;
}
}
void bfs(const vector<vector<int>>&g, int v, vector<bool>& seen){
seen[v]=true;
cout<<v<<" ";
for(auto next: g[v]){
if(seen[next]){
continue;
}
bfs(g,next,seen);
}
}
bool dfs(vector<vector<int>> &g,int start,int goal,vector<bool>&seen){
bool res=false;
seen[start]=true;
if(start==goal){
return true;
}
for(auto next: g[start]){
if(seen[next]){
continue;
}
res=dfs(g,next,goal,seen);
if(res){
break;
}
}
return res;
}
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);
}
bool isLowerCase(char c){
return (c>='a'&&c<='z');
}
ll powm(ll a,ll n, ll m){
ll ret=1;
while(n>0){
if(n%2==1){
ret=(ret*a)%m;
}
n>>=1;
a=(a*a)%m;
}
return ret;
}
const string yesno(bool ans){
return (ans?"Yes":"No");
}
int main() {
string s;cin>>s;
sort(all(s));
char ans=-1;
for(int i=0;i<26;i++){
char tar='a'+i;
if(s.find(tar,0)==string::npos){
ans=tar;
break;
}
}
if(ans==-1){
cout<<"None"<<endl;
}else{
cout<<ans<<endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define INF (1<<31)-1
#define LINF (1LL<<63)-1LL
#define MOD 1000000007
#define MOD2 998244353
template<class T,class U>bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U>bool chmin(T &a, const U &b){if(b<a){a=b;return 1;}return 0;}
#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)
#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;
#define all(a) (a).begin(),(a).end()
#define dig(n) to_string(n).length()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> iP;
typedef pair<P,P> PP;
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 dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int main(){
bool flag=false;
ll ans=LINF,sum=0;
int n,k;
cin>>n>>k;
vector<P> po(n);
vector<int> xl(n);
vector<int> yl(n);
rep(i,n){
int x,y;
cin>>x>>y;
po[i] = P(x,y);
xl[i] =x;
yl[i] =y;
}
sort(all(xl));sort(all(yl));
rep(a,n)rep1(b,a,n)rep(c,n)rep1(d,c,n){
ll x2 = xl[b];
ll x1 = xl[a];
ll y2 = yl[d];
ll y1 = yl[c];
int cnt=0;
rep(i,n){
int x = po[i].fi;
int y = po[i].se;
if( x1<=x&&x<=x2 && y1<=y&&y<=y2 ){
++cnt;
}
}
if(cnt >= k){
chmin(ans,(x2-x1)*(y2-y1));
}
}
cout<<ans<<endl;
return 0;
} | 0 | 62,613,321 |
#include <iostream>
using namespace std;
int main()
{
int n, i = 0;
int car[10] = {};
while(cin >> n){
if(n == 0){
cout << car[i - 1] << endl;
car[i - 1] = 0;
i--;
}else{
car[i] = n;
i++;
}
}
} | #include<iostream>
using namespace std;
int main()
{
int s, a[10000];
cin >> s;
a[0] = s;
for(int i = 1; i < 10000; i++)
{
if(s % 2 == 0)
{
s = s / 2;
a[i] = s;
}
else
{
s = 3 * s + 1;
a[i] = s;
}
for(int j = 0; j < i; j++)
{
if(i != j && a[i] == a[j])
{
cout << i + 1;
return 0;
}
}
}
} | 0 | 81,806,391 |
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>
using namespace std;
#define int long long
#define rep(i, n) for (int i=0;i<(int)(n);++i)
#define rep1(i, n) for (int i=1;i<=(int)(n);++i)
#define range(i, l, r) for (int i=l;i<(int)(r);++i)
#define rrange(i, l, r) for (int i=r-1;i>=(int)(l);--i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back
using vi=vector<int>;
using pii=pair<int, int>;
using ll=long long;
bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
int read(){int a;scanf("%lld",&a);return a;}
const int inf = 1e9 + 10;
const int mod = 1e9 + 7;
inline ll mod_pow(ll a, ll x, ll m)
{
if (x == 0) return 1;
ll res = mod_pow(a, x / 2, m);
res *= res;
res %= m;
if (x % 2) {
res *= a;
res %= m;
}
return res;
}
int counter[26];
signed main()
{
int N; cin >> N;
string S; cin >> S;
int ans = 0;
rep(i, N) {
int c = S[i] - 'a';
counter[c]++;
int add = 1;
rep(j, 26) {
if (j == c) continue;
add *= (counter[j] + 1);
add %= mod;
}
ans += add;
ans %= mod;
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);++i)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;i>=(int)(m);--i)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll) 1e9 + 7;
using ld=long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;
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;
}
struct Edge {
ll to, cap, rev;
Edge(ll _to, ll _cap, ll _rev) {
to = _to; cap = _cap; rev = _rev;
}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;
void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
G[from].push_back(Edge(to, cap, (ll)G[to].size()));
if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}
void solve(){
ll n;
cin>>n;
Array a(n);
map<ll,ll> mp;
REP(i,n){
cin>>a[i];
mp[a[i]]++;
}
int id=0;
for(auto& i:mp){
i.second = id;
id++;
}
ll ans=0;
REP(i,n){
if(i%2!=mp[a[i]]%2) ans++;
}
cout<<ans/2<<en;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
solve();
return 0;
} | 0 | 57,118,032 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
const int mod=1000000007;
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
ll x,y;cin >> x >> y;
if(abs(x-y)<=1) cout << "Brown" << endl;
else cout << "Alice" << endl;
} | #include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long ll;
int N, K;
ll height[305];
ll dp[305][305];
ll INF = 0x3f3f3f3f3f3f3f3f;
int main() {
cin >> N >> K;
for (int i=1; i<=N; i++){
scanf("%lld", &height[i]);
}
memset(dp, INF, sizeof(dp));
for (int i=1; i<=N; i++) {
dp[i][0] = 0;
dp[i][1] = height[i];
}
for (int x=1; x<=N; x++){
for (int y=2; y<=N-K; y++){
for (int k=1; k<x; k++){
dp[x][y] = min(dp[x][y], dp[k][y-1]+max(0LL, height[x]-height[k]));
}
}
}
ll ans = LONG_LONG_MAX;
for (int i=1; i<=N; i++){
ans = min(ans, dp[i][N-K]);
}
cout << ans << endl;
return 0;
} | 0 | 55,315,608 |
#include <iostream>
using namespace std;
int main()
{
int a, b;
cin >> a >> b;
while (a != 0 || b != 0)
{
if (b < a)
{
int tmp = a;
a = b;
b = tmp;
}
cout << a << ' ' << b << endl;
cin >> a >> b;
}
return 0;
} | #include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int main() {
int N, M; cin >> N >> M;
vector<vector<int> > to(N);
rep(i, M){
int a, b; cin >> a >> b;
a--;
b--;
to[a].push_back(b);
}
int f = to[0].size();
queue<int> q;
for (int i = 0; i < f; i++){
q.push(to[0][i]);
}
bool ok = false;
while(!q.empty()){
int x = q.front(); q.pop();
int y = to[x].size();
for (int i = 0; i < y; i++){
if(to[x][i] == N-1){
ok = true;
}
}
}
if(ok){
cout << "POSSIBLE" << endl;
} else {
cout << "IMPOSSIBLE" << endl;
}
return 0;
} | 0 | 38,121,957 |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define mod 1000000007LL
#define IN freopen("C.in","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG pf("Hi\n")
#define INF 1000000000
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 17
#define off 8002
using namespace __gnu_pbds;
using namespace std ;
typedef tree< i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef pair<int, int> pii;
#define maxn 200005
int ask(i64 n)
{
printf("? %lld\n",n) ;
fflush(stdout) ;
char s[5] ;
scanf("%s",s) ;
return (s[0]=='Y') ;
}
int findLength1()
{
i64 st = 1 ;
int len = 0 ;
while( 1 )
{
int res = ask(st) ;
if( res )
{
len++ ;
st = st*10 ;
}
else break ;
}
return len ;
}
int findLength2()
{
i64 st = 9 ;
int len = 0 ;
while( 1 )
{
int res = ask(st) ;
len++ ;
if( res == 0 )
{
st = st*10 + 9 ;
}
else break ;
}
return len ;
}
int main()
{
int res = ask(555555555555LL) ;
int len ;
if(res) len = findLength2() ;
else len = findLength1() ;
i64 lo = 1 , hi ;
for(int i=1 ; i<len ; i++) lo = lo*10 ;
hi = 10*lo - 1 ;
while( lo < hi )
{
i64 mid = (lo+hi)/2 ;
int res = ask(mid*10) ;
if(res) hi = mid ;
else lo = mid+1 ;
}
printf("! %lld\n",lo) ;
return 0 ;
} | #include<bits/stdc++.h>
using namespace std;
typedef long long ll ;
typedef double db;
const double pi = 3.141592654;
#define pb push_back
#define forab(i,a,b) for(int i=(a);i<=(b);i++)
#define CIN ios_base::sync_with_stdio(0); cin.tie(0)
#define pcase(z,x) printf("Case %ld: %lld\n",z,x)
#define nw "\n"
int main(void)
{
CIN;
ll tc,l,k,sum=0,x=0,y,z=0,m=1,n=0,ans=0,cnt=0;
cin>>n;
ll arr[n];ll lala[n];
for(auto &i:arr){
cin>>i;
lala[x++]=i;
}
sort(arr,arr+n);
for(ll i=0;i<n;i++){
if(arr[n-1]==lala[i])cout<<arr[n-2]<<nw;
else cout<<arr[n-1]<<nw;
}
} | 0 | 36,210,570 |
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i< (n); i++)
using namespace std;
using ll = long long;
int main(void) {
int A[3][3] = {0};
bool bing[3][3] = {false};
bool ans = false;
for(int i=0; i<3; i++) {
for(int j=0; j<3; j++) {
cin >> A[i][j];
}
}
int N; cin >> N;
int b[N+10] = {0};
for(int i=0; i<N; i++) cin >> b[i];
for(int k=0; k<N; k++) {
for(int i=0; i<3; i++) {
for(int j=0; j<3; j++) {
if(b[k] == A[i][j]) bing[i][j] = true;
}
}
}
if(bing[0][0] && bing[1][0] && bing[2][0]) ans = true;
else if(bing[0][1] && bing[1][1] && bing[2][1]) ans = true;
else if(bing[0][2] && bing[1][2] && bing[2][2]) ans = true;
if(bing[0][0] && bing[0][1] && bing[0][2]) ans = true;
else if(bing[1][0] && bing[1][1] && bing[1][2]) ans = true;
else if(bing[2][0] && bing[2][1] && bing[2][2]) ans = true;
if(bing[0][0] && bing[1][1] && bing[2][2]) ans = true;
else if(bing[0][2] && bing[1][1] && bing[2][0]) ans = true;
if(ans) cout << "Yes" << endl;
else cout << "No" << endl;
} | #include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <chrono>
using namespace std;
using namespace chrono;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
#define loop(x,n) for(int x = 0; x < n; ++x)
#define FORd(i,a,b) for (int i = (b)-1; i >= (a); i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto& a : x)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define sz(x) (int)x.size()
#define beg(x) x.begin()
#define en(x) x.end()
#define all(x) beg(x), en(x)
#define resz resize
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;
string get_str() {
string temp;
cin >> temp;
return temp;
}
int get_int() {
int temp;
cin >> temp;
return temp;
}
void solve() {
}
int n, a[200000], b[200000], ans;
int main() {
cin >> n;
vector<int> interest;
loop(i, n) {
cin >> a[i];
}
sort(a, a+n);
vector<bool> dp(a[n-1]+1, true);
loop(i, n) {
if (!dp[a[i]]) continue;
if (i > 0 && a[i] == a[i-1]) {
dp[a[i]] = false;
ans--;
continue;
}
ans++;
for(int j=a[i]*2; j <= a[n-1]; j+=a[i]) {
dp[j] = false;
}
}
cout << ans << endl;
} | 0 | 71,651,770 |
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int main() {
ll N, k = 0, a, n = 1;
cin >> N;
for (int i = 0; i < N; i++) {
cin >> a;
if (a == n) {
n++;
} else {
k++;
}
}
cout << (k == N ? -1 : k) << endl;
} | #include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0LL)
#define mapmin(v) v.rbegin()->first
#define mapmax(v) v.begin()->first
#define pb push_back
#define pf push_front
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK cerr<<"OK\n"
#define OK1 cerr<<"OK1\n"
#define OK2 cerr<<"OK2\n"
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n
#define endl '\n'
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;
const double pi = acos(-1.0);
const ll mod=1000000007;
const ll mod2=998244353;
template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
ost << "{" << p.first << ", " << p.second << "} ";
return ost;
}
template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
ost << "{";
for (int i = 0; i<(int)v.size(); i++) {
if (i)ost << " ";
ost << v[i];
}
ost << "} \n";
return ost;
}
template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
ost << "{";
for (auto p:v) {
ost << "{" << p.first << ", " << p.second << "} ";
}
ost << "} ";
return ost;
}
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;}
void YES(bool b) {cout << ((b)?"YES\n":"NO\n");}
void Yes(bool b) {cout << ((b)?"Yes\n":"No\n");}
void yes(bool b) {cout << ((b)?"yes\n":"no\n");}
void Yay(bool b) {cout << ((b)?"Yay!\n":":(\n");}
ll powmod(ll a,ll b){ll c=1; while(b>0){ if(b&1){ c=a*c%mod; } a=a*a%mod; b>>=1; } return c;}
ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}
int main()
{
ll n,ans=0;
cin >> n;
vll a(n+1);
map<ll,ll> m;
m[0]++;
rep(i,n){
cin >> a[i+1];
a[i+1]+=a[i];
ans+=m[a[i+1]];
m[a[i+1]]++;
}
cout << ans << endl;
return 0;
} | 0 | 615,648 |
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<math.h>
using namespace std;
int main()
{
int x,y,count=10;
long long ans; cin>>x>>y>>ans;
while(count--)
{
ans=x*ans-y;
cout<<ans<<"\n";
}
} | #include<bits/stdc++.h>
#define int long long
#define pb push_back
#define pf emplace_front
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pii pair<int,int>
#define psi pair<string,int>
#define vi vector<int>
#define vpii vector<pii>
#define vvi vector<vi>
#define sz(x) (int)(x).size()
#define x first
#define y second
#define endl '\n'
#define tezz ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MOD 1000000007
#define hell 998244353
#define prec(n) fixed<<setprecision(n)
#define ini(a, i) memset(a, i, sizeof(a))
#define output(x) cout << (x ? "YES" : "NO")<<endl;
using namespace std;
#define debug(vec) cout<<(#vec)<<" : [ "; for (auto& i: vec) cout<<i<<" "; cout<< "]" << endl
#define debugp(vec) cout<<(#vec)<<" : [ "; for (auto& i: vec) cout<<"("<<i.x<<","<<i.y<<")"<<" "; cout<< "]" << endl
#define trace(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);cout << endl; }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cout << "[" << *it << ": " << a << "]\t";
err(++it, args...);
}
signed main() {
tezz
int n, k;
cin >> n >> k;
int a[n];
for(int i=0; i<n; i++)cin >> a[i];
int dp[k+1], pre[k+1];
ini(pre, 0);
ini(dp, 0);
dp[0]=1;
pre[0]=1;
for(int i=0; i<n; i++){
for(int j=1; j<=k; j++){
pre[j] = (pre[j-1] + dp[j])%MOD;
}
for(int j=k; j>0; j--){
dp[j] = (pre[j] - ((j-a[i]-1>=0) ? pre[j-a[i]-1] : 0)+MOD)%MOD;
}
}
cout << dp[k] << endl;
return 0;
} | 0 | 67,727,773 |
#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/arc094_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;
int N = 3;
vector<int> d(N);
rep(i, N) { cin >> d[i]; }
sort(d.begin(), d.end());
int a = d[0];
int b = d[1];
int c = d[2];
ll ans = 0;
if ((b - a) % 2 == 0) {
ans += (b - a) / 2;
a = b;
} else {
ans += (b - a) / 2 + 1;
c++;
}
ans += c - b;
cout << ans << endl;
} | #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)
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; }
#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert
using namespace std;
int main(void)
{
cin.tie(0);
ios::sync_with_stdio(false);
int n; cin>>n;
vi A(100001,0);
rep(i,n){
int a; cin>>a;
A[a]++;
}
int ans,sum=0;
rep(i,100001){
sum+=max(A[i]-1,0);
}
ans = n-(sum+1)/2*2;
cout<<ans<<endl;
return 0;
} | 0 | 100,667,134 |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
map<ll,ll>f;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n,a,b,s=0,x;
cin>>n>>a>>b;x=a;
for(int i=1;i<=n;i++){
ll s2=0,y;y=i;
while(y>0){
s2+=(y%10);y/=10;
}
if(s2>=a&&s2<=b){s+=i;}
}
cout<<s<<endl;
} | #include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
int n;
cin>>n;
vector<int> w(n);
int all=0,minus=0;
rep(i,n){
cin>>w[i];
all+=w[i];
}
int minw=all;
rep(i,n){
minus+=w[i];
minw=min(minw,abs((all-minus)-minus));
}
cout<<minw;
} | 0 | 81,472,438 |
End of preview. Expand
in Dataset Viewer.
- Downloads last month
- 30