code1
stringlengths 54
12k
| code2
stringlengths 65
12k
| similar
int64 0
1
| __index_level_0__
int64 137
101M
|
|---|---|---|---|
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
typedef pair<int, int> P;
struct Graph
{
int n;
vector<vector<int>> g;
Graph(int n) : n(n){
g.resize(n);
}
void init(int n_){
n = n_;
g.resize(n_);
}
void add_edge(int from, int to){
g[from].push_back(to);
}
};
struct Tree
{
int n;
int root;
vector<vector<int>> t;
vector<int> par;
vector<int> dpt;
void init(Graph &g, int root_){
n = g.n;
root = root_;
t.resize(n);
par.resize(n);
dpt.resize(n);
fill(dpt.begin(), dpt.end(), -1);
queue<int> que;
par[root] = -1;
dpt[root] = 0;
que.push(root);
while(que.size()){
int pa = que.front();
que.pop();
for(int ch : g.g[pa]){
if(dpt[ch] == -1){
t[pa].push_back(ch);
par[ch] = pa;
dpt[ch] = dpt[pa] + 1;
que.push(ch);
}
}
}
}
Tree(){}
Tree(Graph &g, int root_){
init(g, root_);
}
};
int main()
{
int n;
cin >> n;
Graph g(n);
for(int i = 0; i < n - 1; i++){
int a, b;
cin >> a >> b;
a--; b--;
g.add_edge(a, b);
g.add_edge(b, a);
}
if(n == 2){
cout << "Second" << endl;
return 0;
}
Tree t(g, 0);
P p[100002];
for(int i = 0; i < n; i++) p[i] = P(t.dpt[i], i);
sort(p, p + n, greater<P>());
bool del[100002]{0};
for(int i = 0; i < n; i++){
int u = p[i].second;
int k = 0;
for(int v : t.t[u]){
if(!del[v]) k++;
del[v] = true;
}
if(k >= 2){
cout << "First" << endl;
return 0;
}
if(k == 1){
del[u] = true;
}
if(k == 0 && u == 0){
cout << "First" << endl;
return 0;
}
}
cout << "Second" << endl;
}
|
#include<string.h>
#include<stdio.h>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int n,m,d;
int a[2111][2111];
int B=1010;
char ans[511][511];
int main()
{
int i,j,k;
cin>>n>>m>>d;
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
int xx,yy;
xx=i+j+B;yy=i-j+B;
xx/=d;yy/=d;
if(xx%2==0 && yy%2==0)
{
ans[i][j]='R';
}
else if(xx%2==0 && yy%2==1)
{
ans[i][j]='Y';
}
else if(xx%2==1 && yy%2==0)
{
ans[i][j]='G';
}
else
{
ans[i][j]='B';
}
}
}
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
cout<<ans[i][j];
}
cout<<endl;
}
return 0;
}
| 0
| 33,500,699
|
#include <bits/stdc++.h>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long int ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
const int MOD=1000000007;
bool isPowerOfTwo (ll x)
{
return x && (!(x&(x-1)));
}
bool isPrime(int n)
{
if (n <= 1) return false;
if (n <= 3) return true;
if (n%2 == 0 || n%3 == 0) return false;
for (int i=5; i*i<=n; i=i+6)
if (n%i == 0 || n%(i+2) == 0)
return false;
return true;
}
int highestPowerof2(unsigned int n)
{
if (n < 1)
return 0;
int res = 1;
for (int i=0; i<8*sizeof(unsigned int); i++)
{
int curr = 1 << i;
if (curr > n)
break;
res = curr;
}
return res;
}
long long binpow(long long a, long long b) {
long long res = 1;
while (b > 0) {
if (b & 1)
res = res * a;
a = a * a;
b >>= 1;
}
return res;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll t=1;
while(t--)
{
int n;
cin>>n;
int a[n+1];
map<int,int> mp;
int x;
for(int i=1;i<=n;i++)
{
cin>>x;
mp[i]=x;
}
int count=0;
for(auto i:mp)
{
if(mp[i.second]==i.first)
count++;
}
cout<<count/2;
}
return 0;
}
|
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cstring>
#include <cmath>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define reps(i,s,n) for(int i=s; i<n; i++)
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
int cnt[86400];
int main() {
int n;
while( scanf("%d", &n), n ) {
memset( cnt, 0, sizeof(cnt) );
rep(i,n) {
int sh, sm, ss, eh, em, es;
scanf("%d:%d:%d %d:%d:%d", &sh, &sm, &ss, &eh, &em, &es);
int st = sh*3600+sm*60+ss;
int et = eh*3600+em*60+es;
for(int t=st; t<et; t++) {
cnt[t]++;
}
}
int maxi = 0;
rep(i, 86400) {
if( maxi < cnt[i] )
maxi = cnt[i];
}
cout << maxi << endl;
}
return 0;
}
| 0
| 56,590,465
|
#include<bits/stdc++.h>
using namespace std;
int main(){
int x,t;
cin>>x>>t;
if(x>=t){
cout<<x-t<<endl;}
else{cout<<"0"<<endl;}
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
if(a<b)return b;
else return a;
}
ll lmin(ll a,ll b){
if(a<b)return a;
else return b;
}
ll gcd(ll a,ll b){
if(a<b)swap(a,b);
if(b==0)return a;
if(a%b==0)return b;
return gcd(b,a%b);
}
ll Pow(ll n,ll k){
ll ret=1;
ll now=n;
while(k>0){
if(k&1)ret*=now;
now*=now;
k/=2;
}
return ret;
}
int main(){
int n;cin>>n;
int a[n];
vector<int> v;
rep(i,0,n){
cin>>a[i];
v.push_back(a[i]);
}
if(n==2){
cout<<"Possible"<<endl;
return 0;
}
sort(v.begin(),v.end());
int ma=v.back();
if(ma==1){
cout<<"Impossible"<<endl;
return 0;
}
if(v[0]<(ma+1)/2){
cout<<"Impossible"<<endl;
return 0;
}
int cnt[ma+1];
fill(cnt,cnt+ma+1,0);
rep(i,0,n)cnt[a[i]]++;
int t=ma/2+1;
rep(i,t+1,ma+1){
if(cnt[i]<=1){
cout<<"Impossible"<<endl;
return 0;
}
}
if(ma%2==0){
if(cnt[t-1]!=1){
cout<<"Impossible"<<endl;
return 0;
}
}
else{
if(cnt[t]!=2){
cout<<"Impossible"<<endl;
return 0;
}
}
cout<<"Possible"<<endl;
}
| 0
| 42,269,750
|
#include "bits/stdc++.h"
using namespace std;
long long P[5010];
long long C[5010];
int main() {
long long N, K;
cin >> N >> K;
for (long long i = 1; i <= N; i++) {
cin >> P[i];
}
for (long long i = 1; i <= N; i++) {
cin >> C[i];
}
long long nmax = -1000000000;
long long ntemp = 0;
long long allmax = -1000000000;
int flag;
int cnt;
for (int i = 1; i <= N; i++) {
nmax = -1000000000;
ntemp = 0;
flag = 1;
cnt = 1;
int temp = i;
int now = temp;
now = P[now];
ntemp += C[now];
nmax = max(nmax, ntemp);
do {
if (cnt == K) {
flag = 0;
break;
}
now = P[now];
ntemp += C[now];
nmax = max(nmax, ntemp);
cnt++;
} while (now != temp);
if (flag != 1) {
allmax = max(allmax, nmax);
continue;
}
if (ntemp <= 0) {
allmax = max(allmax, nmax);
continue;
}
if (ntemp > 0) {
long long sc = K / cnt;
long long zc = K - (sc - 1) *cnt;
ntemp = (sc - 1)*ntemp;
nmax = max(nmax, ntemp);
for (int j = 0; j < zc; j++) {
now = P[now];
ntemp += C[now];
nmax = max(nmax, ntemp);
}
allmax = max(allmax, nmax);
continue;
}
}
cout << allmax << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define XDAY 196471
void solve(int y,int m,int d){
int today=1;
for(int i=1;i<y;i++){
if(i%3) today+=195;
else today+=200;
}
for(int i=1;i<m;i++){
if(i%2||!(y%3)) today+=20;
else today+=19;
}
today+=(d-1);
cout<<XDAY-today<<endl;
}
int main(void){
int n;
int a,b,c;
cin>>n;
for(int i=0;i<n;i++){
cin>>a>>b>>c;
solve(a,b,c);
}
}
| 0
| 18,999,503
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)
bool sort_by(pi c, pi d){
return c.S < d.S;
}
int main() {
int n, m;
cin >> n >> m;
cout << (100*(n-m) + 1900*m)*pow(2, m);
}
|
#include<bits/stdc++.h>
using namespace std;
int cal(string str){
int sum=0;
stack<char> c;
c.push('e');
for(int i=0;i<str.size();i++){
c.push(str[i]);
}
while(c.size()!=1){
if(c.top()=='i' || c.top()=='x' || c.top()=='c' || c.top()=='m'){
char tmp=c.top();
c.pop();
int tmp2=1;
for(char j='2';j<='9';j++){
if(j==c.top()){
tmp2=j-'0';
c.pop();
break;
}
}
if(tmp=='i'){
sum+=tmp2*1;
}
else if(tmp=='x'){
sum+=tmp2*10;
}
else if(tmp=='c'){
sum+=tmp2*100;
}
else if(tmp=='m'){
sum+=tmp2*1000;
}
}
}
return sum;
}
void cal2(int a,int b){
int sum=a+b;
vector<char> ans;
if(sum/1000>1) cout<<sum/1000<<"m";
if(sum/1000==1) cout<<"m";
sum%=1000;
if(sum/100>1) cout<<sum/100<<"c";
if(sum/100==1) cout<<"c";
sum%=100;
if(sum/10>1) cout<<sum/10<<"x";
if(sum/10==1) cout<<"x";
sum%=10;
if(sum>1) cout<<sum<<"i";
if(sum==1) cout<<"i";
cout<<endl;
return ;
}
int main(){
int n;
cin>>n;
string mcxl1,mcxl2;
for(int i=0;i<n;i++){
cin>>mcxl1>>mcxl2;
cal2(cal(mcxl1),cal(mcxl2));
}
return 0;
}
| 0
| 83,811,933
|
#include <bits/stdc++.h>
#define ROOP(i, N) for(int i=0; i++; i<N)
#define RVROOP(i, N) for(int i=N; i--; i>=0)
#define ALL(v) v.begin(), v.end()
const int INF = 1e9;
const int MAX = 510000;
const int MOD = 1000000007;
const double PI = acos(-1);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int main(){
int K; cin>>K;
string S, ans; cin>>S;
if(S.size()<=K){
ans=S;
}
else{
ans=S.substr(0, K)+"...";
}
cout<<ans<<endl;
}
|
#include <bits/stdc++.h>
#define boost_ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define iter_(i,n) for (int i = 0; i < int(n); i++)
#define for_n(i, n) for (int i = 1; i <= int(n); i++)
#define pb push_back
#define mp make_pair
#define itr ::iterator
#define s_sort(s) sort(s.begin(),s.end())
#define n_sort(a) sort(a,a+n)
#define thank_you return 0
#define thanks return
#define pii pair<int,int>
#define precise_impact cout<<setprecision(10)<<fixed;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ulli;
typedef double db;
#define PI acos(-1.00)
#define MOD 1000000007
ll bigmod(ll a,ll b){
if(b==0){
return 1;
}
ll tm=bigmod(a,b/2);
tm=(tm*tm)%MOD;
if(b%2==1)
tm=(tm*a)%MOD;
return tm;
}
int egcd(int a,int b,int &x,int &y){
if(a==0){
x=0;
y=1;
return b;
}
int x1,y1;
int d=egcd(b%a,a,x1,y1);
x=y1-(b/a)*x1;
y=x1;
return d;
}
void solve();
int main()
{
boost_;
precise_impact;
int t=1;
while(t--)
solve();
thank_you;
}
void solve()
{
int a,b;
cin>>a>>b;
string s,p;
iter_(i,b){
s+=(char)(a+48);
}
iter_(i,a){
p+=(char)(b+48);
}
if(p<s){
cout<<p<<endl;
}
else
cout<<s<<endl;
}
| 0
| 78,828,040
|
#include <stdio.h>
#include <bitset>
using namespace std;
int dp[1010][1010];
bitset<1010> went[1010];
int min(int a,int b){
if(a>b)return b;
return a;
}
int dis(int n,int m,char l[],char r[]){
if(n<0&&m<0)return 0;
if(n<0)return m+1;
if(m<0)return n+1;
if(went[n][m])return dp[n][m];
went[n][m]=true;
return dp[n][m]=min(min(dis(n-1,m,l,r),dis(n,m-1,l,r))+1,dis(n-1,m-1,l,r)+(l[n]!=r[m]));
}
int main(){
int n=0,m=0;
char l[1010],r[1010];
for(int i=0;i<1010;i++){
l[i]=r[i]='\0';
went[i].reset();
}
scanf("%s",l);
scanf("%s",r);
while(l[n]!='\0')n++;
while(r[m]!='\0')m++;
printf("%d\n",dis(n-1,m-1,l,r));
}
|
#include<bits/stdc++.h>
using namespace std;
#define M 1000000007
#define ll long long
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ifor(st,lim) for(int i=st;i<lim;i++)
#define jfor(stt,llim) for(int j=stt;j<llim;j++)
#define eifor(st,lim) for(int i=st;i<=lim;i++)
#define ejfor(stt,llim) for(int j=stt;j<=llim;j++)
#define blank cout<<'\n'
void solve()
{
string s; cin>>s;
if(s[0] == s[1] && s[1] == s[2] && s[0] == 'R') cout<<"3";
else if(s[0] == s[1] && s[0] == 'R') cout<<"2";
else if(s[1] == s[2] && s[1] == 'R') cout<<"2";
else if(s[0] == 'R' || s[1] == 'R' || s[2] == 'R') cout<<"1";
else cout<<"0";
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int t=1;
while(t--){
solve();
}
}
| 0
| 27,304,129
|
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <cmath>
#include <map>
using namespace std;
int H, W;
string s;
string mozi="snuke";
string alpha="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main()
{
cin >> H >> W;
for(int i=1; i<H+1; i++){
for(int j=0; j<W; j++){
string inp;
cin >> inp;
if(inp==mozi){
cout << alpha[j] << i << endl;
return 0;
}
}
}
}
|
#include<bits/stdc++.h>
using namespace std;
int main(){
int k,n;
cin>>k>>n;
set<int> st;
int a[n],min=INT_MAX,res;
if(n==0){
cout<<k;
return 0;
}
for(int i=0;i<n;i++){
cin>>a[i];
st.insert(a[i]);
if(abs(a[i]-k)<min){
min = abs(a[i]-k);
res = a[i];
}
}
int i=res+1,j=res-1;
while(true){
if(st.find(j)==st.end()){
cout<< j ;
break;
}
else if(st.find(i)==st.end()){
cout<<i;
break;
}
i++,j--;
}
}
| 0
| 47,958,655
|
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
int ans = 1000000;
string sans;
char ask(string xs){
ll x = 0;
REP(i,xs.length()) x = 10 * x + (xs[i] - '0');
if ((ans <= x && sans <= xs) || (ans > x && sans > xs)) return 'Y';
return 'N';
}
int main() {
int p = ans;
while (p){
char c = (p % 10) + '0';
sans = c + sans;
p /= 10;
}
string s(11,'0');
REP(i,10){
int l = 0, r = 10;
if (i == 0) l = 1;
while (r - l > 1){
int m = (l + r) / 2;
s[i] = m + '0';
cout << "? " << s << endl;
char c;
cin >> c;
if (c == 'Y') r = m;
else l = m;
}
s[i] = l + '0';
string t = s.substr(0,i+1);
while (t.length() < 10) t += '9';
cout << "? " << t << endl;
char c;
cin >> c;
if (c == 'Y') continue;
string nine(i, '9');
nine += '8';
if (s.substr(0,i+1) == nine){
FOR(j,i+1,10){
string u = '1' + string(j,'0');
cout << "? " << u << endl;
cin >> c;
if (c == 'N'){
string ans(i+1, '9');
while (ans.length() < j) ans += '0';
cout << "! " << ans << endl;
return 0;
}
}
}
FOR(j,i+1,10){
string u(j, '9');
cout << "? " << u << endl;
cin >> c;
if (c == 'Y'){
s = s.substr(0,i+1);
s[i]++;
while (s.length() < j) s += '0';
cout << "! " << s << endl;
return 0;
}
}
}
FOR(j,1,10){
string u(j, '9');
cout << "? " << u << endl;
char c;
cin >> c;
if (c == 'Y'){
string ans = "1";
while (ans.length() < j) ans += '0';
cout << "! " << ans << endl;
return 0;
}
}
return 0;
}
|
#include "bits/stdc++.h"
using namespace std;
#ifndef LOCAL
#define endl '\n'
#endif
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define rf(i, a, b) for(int i = a; i >= b; i--)
#define pf push_front
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)x.size()
#define lb lower_bound
#define ub upper_bound
typedef long long ll;
typedef long double f80;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int pct(int x) { return __builtin_popcount(x); }
int pct(ll x) { return __builtin_popcountll(x); }
int bt(int x) { return 31 - __builtin_clz(x); }
int bt(ll x) { return 63 - __builtin_clzll(x); }
int cdiv(int a, int b) { return a / b + !(a < 0 || a % b == 0); }
ll cdiv(ll a, ll b) { return a / b + !(a < 0 || a % b == 0); }
int nxt_C(int x) { int c = x & -x, r = x + c; return (((r ^ x) >> 2) / c) | r; }
ll nxt_C(ll x) { ll c = x & -x, r = x + c; return (((r ^ x) >> 2) / c) | r; }
vector<int> get_bits(int mask) {
vector<int> bb;
while(mask) { int b = bt(mask); bb.pb(b); mask ^= (1 << b); }
reverse(all(bb));
return bb;
}
int get_mask(vector<int> v) {
int mask = 0;
for(int x : v) { mask ^= (1 << x); }
return mask;
}
template<typename T>
void uniq(vector<T> &v) { sort(all(v)); v.resize(unique(all(v)) - v.begin()); }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll rand(ll l, ll r){
uniform_int_distribution<ll> uid(l, r);
return uid(rng);
}
void sc() {}
template <typename Head, typename... Tail>
void sc(Head &H, Tail &... T) { cin >> H; sc(T...); }
#ifdef LOCAL
#define debug(...) cerr << "[L:" << __LINE__ << "][" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
const int mod = 1e9 + 7;
int pwr(int a,ll b) {
int ans = 1;
while(b) {
if(b & 1) ans = (ans * 1LL * a) % mod;
a = (a * 1LL * a) % mod;
b >>= 1;
}
return ans;
}
const int N = 1e5 + 5;
ll a[N];
ll dp[N][2];
void solve() {
int n;
sc(n);
fr(i, 1, n) {
sc(a[i]);
}
fr(i, 2, n + 1) {
fr(j, 0, 1) {
fr(k, 0, 1) {
if(a[i - 1] >= j + k) {
dp[i][k] = max(dp[i][k], dp[i - 1][j] + k + (a[i - 1] - j - k) / 2);
}
}
}
}
cout << dp[n + 1][0];
}
int main() {
ios :: sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
for(int tt = 1; tt <= t; tt++) {
solve();
}
return 0;
}
| 0
| 71,781,625
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;
int main(){
int n; cin>>n;
vector<int> p(n,0),a(n,0),b(n,0);
rep(i,n){
cin>>p[i]; p[i]--;
}
rep(i,n) a[i]=i*20000+1;
for(int i=n-1;i>=0;i--) b[i]=(n-i)*20000+a.back();
rep(i,n) b[p[i]]+=i;
rep(i,n){
cout<<a[i];
if(i<n-1) cout<<" ";
}
cout<<endl;
rep(i,n){
cout<<b[i];
if(i<n-1) cout<<" ";
}
cout<<endl;
}
|
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <cmath>
#include <iomanip>
#define vec vector
using namespace std;
using ll = long long;
using vl = vector<long long>;
using vi = vector<int>;
using vvl = vector<vl>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
using ld = long double;
int n;
vvi adj;
ll mod = 1e9 + 7;
pll doofus(int node, int parent)
{
pll ways = {1, 1};
if (adj[node].size() == 1)
return {1, 1};
for (int i = 0; i < adj[node].size(); i++)
{
if (adj[node][i] != parent)
{
pll w = doofus(adj[node][i], node);
ways.first = (ways.first * ((w.first + w.second) % mod)) % mod;
ways.second = (ways.second * w.first) % mod;
}
}
return ways;
}
int main()
{
cin >> n;
adj = vvi(n + 1, vi());
for (int i = 0; i < n - 1; i++)
{
int x, y; cin >> x >> y;
adj[x].push_back(y);
adj[y].push_back(x);
}
adj[1].push_back(0);
pll w = doofus(1, 0);
cout << (w.first + w.second) % mod;
return 0;
}
| 0
| 92,211,266
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int current_a;
int goal_b;
cin >> current_a >> goal_b;
cout << 2 * goal_b - current_a << endl;
}
|
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996)
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;
int main(int argc, char* argv[])
{
int n;
scanf("%d", &n);
const double PI=acos((double)-1);
const double eps=1e-14;
vector<pair<double, pair<int,int> > > z(n);
int i,j;
for(i=0; i<n; i++) {
int x,y;
scanf("%d%d", &x, &y);
double t=0;
if(x!=0 || y!=0) {
t=atan2((double)y,(double)x);
if(t<-PI+eps) t+=2*PI;
}
z[i]=make_pair(t, make_pair(x,y));
}
sort(z.begin(), z.end());
vector<double> sx(n+1,0), sy(n+1,0);
for(i=0; i<n; i++) {
sx[i+1]=sx[i]+z[i].second.first;
sy[i+1]=sy[i]+z[i].second.second;
}
vector<double> args;
args.push_back(-PI-eps*2);
for(i=0; i<n; i++) {
double tmp=z[i].first;
args.push_back(tmp);
args.push_back(tmp>=0? tmp-PI: tmp+PI);
}
args.push_back(PI+eps*2);
double ans=0;
for(i=0; i<(int)args.size(); i++) {
j=lower_bound(z.begin(),z.end(),make_pair(args[i]-eps, make_pair(0,0)))-z.begin();
int k=lower_bound(z.begin(),z.end(),make_pair(args[i]+PI-eps, make_pair(0,0)))-z.begin();
double sumx=sx[k]-sx[j];
double sumy=sy[k]-sy[j];
double ans0=sumx*sumx+sumy*sumy;
ans=MAX(ans,ans0);
sumx=sx[n]-sumx;
sumy=sy[n]-sumy;
ans0=sumx*sumx+sumy*sumy;
ans=MAX(ans,ans0);
}
printf("%.16lf\n", sqrt(ans));
return 0;
}
| 0
| 68,873,783
|
#include <iostream>
#include <list>
#include <numeric>
#include <algorithm>
int main()
{
int n;
std::cin >> n;
std::list<int> p(n), q(n);
for (auto &e : p) std::cin >> e;
for (auto &e : q) std::cin >> e;
if (p > q) std::swap(p, q);
int diff = 0;
int k = 1;
for (int i = 2; i < n; i++) k *= i;
std::list<int> lsp(n), lsq(n);
std::iota(lsp.begin(), lsp.end(), 1);
std::iota(lsq.begin(), lsq.end(), 1);
int d;
for (auto itp = p.begin(), itq = q.begin(); *itp != p.back(); itp++, itq++) {
d = std::distance(lsq.begin(), std::find(lsq.begin(), lsq.end(), *itq))
- std::distance(lsp.begin(), std::find(lsp.begin(), lsp.end(), *itp));
diff += d * k;
lsp.remove(*itp);
lsq.remove(*itq);
n--;
k /= n;
}
std::cout << diff << std::endl;
return 0;
}
|
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10
#define ll long long
#define ull unsigned long long
#define all(a) (a).begin(), (a).end()
int main() {
int h, w;
while (cin >> h >> w && h > 0) {
for (int i = 0; i < h; ++i)
cout << string(w, '#') << endl;
cout << endl;
}
return 0;
}
| 0
| 81,861,322
|
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n, l, q, ai, bi;
int a[1000010];
int f[1000010][40];
void prepare() {
for(int i = 1; i <= n; i++){
int id = upper_bound(a + 1,a + 1 + n, a[i] + l) - a - 1;
if(a[i] + l > a[n]) f[i][0] = n;
else f[i][0] = id;
}
for(int i = 1; i <= 32; i++)
for(int j = 1; j <= n; j++)
f[j][i] = f[f[j][i - 1]][i - 1];
}
int main() {
scanf("%d", &n);
for(int i = 1; i <= n; i++)
scanf("%d", &a[i]);
scanf("%d%d", &l, &q);
prepare();
while(q--) {
scanf("%d%d", &ai, &bi);
if(ai > bi) swap(ai, bi);
int ans = 0;
for(int j = 30; j >= 0; j --)
if(f[ai][j] < bi) { ans += (1 << j); ai = f[ai][j];}
printf("%d\n", ans + 1);
}
return 0;
}
|
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>
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 ALL(x) x.begin(),x.end()
#define ll long long
typedef pair<int,int> P;
const int inf=1000000007;
const int MOD=1000000007;
int n;
string s;
string res;
bool solve(bool f,bool sec){
bool last=false;
bool nxt=sec;
bool bef=f;
bool cur=sec;
bool hoge;
string ans;
if(f&&sec){
if(s[0]=='o')last=true;
}
else if(f&&(!sec)){
if(s[0]=='x')last=true;
}
else if((!f)&&sec){
if(s[0]=='x')last=true;
}
else{
if(s[0]=='o')last=true;
}
if(f){
ans+='S';
}
else{
ans+='W';
}
rep1(i,n-1){
if(cur){
ans+='S';
}
else{
ans+='W';
}
if(s[i]=='o'&&cur){
nxt=bef;
bef=cur;
cur=nxt;
}
else if(s[i]=='x'&&!cur){
nxt=bef;
bef=cur;
cur=nxt;
}
else if(s[i]=='x'&&cur){
nxt=!bef;
bef=cur;
cur=nxt;
}
else if(s[i]=='o'&&!cur){
nxt=!bef;
bef=cur;
cur=nxt;
}
}
if(f==nxt){
if(last&&ans[n-1]=='S'){
res=ans;
return true;
}
else if(!last&&ans[n-1]=='W'){
res=ans;
return true;
}
}
return false;
}
signed main(){
cin>>n;
cin>>s;
bool flag=false;
flag=flag||solve(true,true);
flag=flag||solve(false,true);
flag=flag||solve(true,false);
flag=flag||solve(false,false);
if(flag){
cout<<res<<endl;
}
else{
cout<<"-1"<<endl;
}
return 0;
}
| 0
| 38,341,847
|
#include <stdio.h>
int main(){
int hi[10];
int n,count=0;
while(scanf("%d",&n) != EOF){
if(n == 0){
printf("%d\n",hi[count-1]);
hi[count-1]=0;
count--;
}
else{
hi[count]=n;
count++;
}
}
return 0;
}
|
#include <bits/stdc++.h>
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
#ifdef DEBUG
#define dump(...) fprintf(stderr, __VA_ARGS__)
#else
#define dump(...)
#endif
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
int main(void){
cin.tie(0);
ios::sync_with_stdio(false);
int n, m; cin >> n >> m;
using YPI = tuple<int ,int, int>;
vector<YPI> ypi(m);
rep(i, m){
int p, y; cin >> p >> y;
p--;
ypi[i] = YPI(y, p, i);
}
sort(_all(ypi));
vi idx(n);
vector<string> res(m);
for(auto& e : ypi){
int p, k; tie(ignore, p, k) = e;
int i = idx[p]++;
stringstream ss;
ss << setw(6) << setfill('0') << p+1;
ss << setw(6) << setfill('0') << i+1;
res[k] = ss.str();
}
for(auto& e : res){
cout << e << endl;
}
return 0;
}
| 0
| 13,609,002
|
#include <iostream>
#include <string>
using ll=long long;
#define rep(i,a,b) for(ll i=a;i<ll(b);i++)
#define repr(i,a,b) for(ll i=a;i>=ll(b);i--)
#define endl "\n"
#define ALL(x) x.begin(),x.end()
using namespace std;
string s, t;
int ans;
int main() {
cin >> s >> t;
int lengh = s.length();
rep(i, 0, lengh) if(s[i] != t[i]) ans++;
cout << ans << endl;
return 0;
}
|
#include <iostream>
#include <math.h>
#include <vector>
typedef long long LL;
using namespace std;
int main() {
LL n;
vector<LL> a;
LL tmp_a;
LL orig=0;
LL ans;
cin >> n;
a.push_back(0);
for(int i=0; i<n; i++){
cin >> tmp_a;
a.push_back(tmp_a);
}
a.push_back(0);
for(int i=0; i<a.size()-1; i++){
orig+=(int)abs(a[i]-a[i+1]);
}
for(int i=1; i<=n; i++){
ans=orig-(int)abs(a[i-1]-a[i])-(int)abs(a[i]-a[i+1]);
ans+=(int)abs(a[i-1]-a[i+1]);
cout << ans << endl;
}
return 0;
}
| 0
| 79,765,158
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
int A, B, C;
cin >> A >> B >> C;
int max_num = max(max(A, B), C);
int remaining = (A + B + C) - max_num;
int diff_num = (max_num * 2) - remaining;
int ans = 0;
if (diff_num % 2 == 0) {
ans = diff_num / 2;
} else {
max_num += 2;
remaining += 1;
diff_num = (max_num * 2) - remaining;
ans = diff_num / 2;
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
void solve() {
ll n, h;
cin >> n >> h;
vector<ll> a(n), b(n);
rep(i, n) cin >> a[i] >> b[i];
ll maxa = -1;
rep(i, n) maxa = max(maxa, a[i]);
sort(b.rbegin(), b.rend());
int last = 0;
bool update = false;
rep(i, n) {
last = i;
if (b[i] <= maxa) {
update = true;
break;
}
}
if (!update) last++;
ll tot = 0;
rep(i, last) {
tot += b[i];
if (tot >= h) {
cout << i + 1 << endl;
return;
}
}
cout << (h - tot + maxa - 1) / maxa + last << endl;
}
int main() {
solve();
return 0;
}
| 0
| 61,351,197
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define sizeOf(A) (sizeof(A))/(sizeof(A[0]))
#define odd(x) ((x) % (2))
#define fastio ios_base::sync_with_stdio(false), cin.tie(0);
int main() {
fastio;
int x, a, b;
cin >> x >> a >> b;
if (b - a <= 0) {
cout << "delicious\n";
} else if (b - a <= x) {
cout << "safe\n";
} else {
cout << "dangerous\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;
int main(){
ll n,p,o=0,e=0,ans=1; cin>>n>>p;
rep(i,n){
ll a; cin>>a;
if(a%2) o++;
else e++;
}
rep(i,n-1) ans*=2;
if(o==0){
if(p==1) ans=0;
else ans*=2;
}
cout<<ans<<endl;
}
| 0
| 33,907,564
|
#include <bits/stdc++.h>
using namespace std;
class UnionFind {
public:
vector<int> par;
UnionFind(int n) {
par.resize(n);
for(int i=0;i<n;i++) {
par[i] = i;
}
}
int root(int x) {
return par[x] == x ? x:par[x] = root(par[x]);
}
bool same(int x, int y) {
return root(x) == root(y);
}
void unite(int x, int y) {
x = root(x);
y = root(y);
if(x==y) return ;
par[x] = y;
}
};
int main(void) {
int N,M,p,x,y;
int cnt = 0;
cin >> N >> M;
UnionFind uf(N);
vector<int> tr(N);
for(int i=0;i<N;i++) {
cin >> p;
p--;
tr[i] = p;
}
for(int i=0;i<M;i++) {
cin >> x >> y;
x--;y--;
uf.unite(x,y);
}
for(int i=0;i<N;i++) {
if(uf.same(i, tr[i])) {
cnt++;
}
}
cout << cnt << endl;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<ll>;
using VV = vector<VI>;
using VS = vector<string>;
template <typename A, typename B>
string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(const string& s) {
return '"' + s + '"';
}
string to_string(const char* s) {
return to_string((string) s);
}
string to_string(bool b) {
return (b ? "true" : "false");
}
string to_string(vector<bool> v) {
bool first = true;
string res = "{";
for (int i = 0; i < static_cast<int>(v.size()); i++) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(v[i]);
}
res += "}";
return res;
}
template <size_t N>
string to_string(bitset<N> v) {
string res = "";
for (size_t i = 0; i < N; i++) {
res += static_cast<char>('0' + v[i]);
}
return res;
}
template <typename A>
string to_string(A v) {
bool first = true;
string res = "{";
for (const auto &x : v) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(x);
}
res += "}";
return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
void debug_out() { cerr << '\n'; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
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; }
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,b) FOR(i, 0, b)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<'\n'
#define p2(s, t) cout << (s) << " " << (t) << '\n'
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << '\n'
#define p_yes() p("YES")
#define p_no() p("NO")
#define SZ(x) ((int)(x).size())
void no(){p_no(); exit(0);}
void yes(){p_yes(); exit(0);}
const ll mod = 1e9 + 7;
const ll inf = 1e18;
ll max_min(ll a, ll b, ll c){
VI A;
A.push_back(a);
A.push_back(b);
A.push_back(c);
sort(ALL(A));
return A.back() - A[0];
}
ll f(ll H, ll W){
ll mi = inf;
rep(h, H){
ll area = h * W;
ll rest_H = H - h;
ll h0 = rest_H/2;
ll h1 = rest_H - h0;
ll area0 = h0 * W;
ll area1 = h1 * W;
ll a = max_min(area, area0, area1);
chmin(mi, a);
ll w0 = W/2;
ll w1 = W - w0;
area0 = rest_H * w0;
area1 = rest_H * w1;
a = max_min(area, area0, area1);
chmin(mi, a);
}
return mi;
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
ll H, W;
cin >> H >> W;
ll mi = f(H, W);
chmin(mi, f(W, H));
p(mi);
return 0;
}
| 0
| 12,066,305
|
#include<iostream>
#include<cstdio>
using namespace std;
int main() {
int n, people[4][3][10] = {};
cin >> n;
for (int i = 0; i < n; i++) {
int b, f, r, v;
cin >> b >> f >> r >> v;
people[b-1][f-1][r-1] += v;
}
for (int b = 0; b < 4; b++) {
for (int f = 0; f < 3; f++) {
for (int r = 0; r < 10; r++) {
cout << " " << people[b][f][r];
}
cout << endl;
}
if (b < 3) printf("####################\n");
}
}
|
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
int main(){
long long n;
cin >> n;
long long a[n+1], b[n+1];
for(long long i = 0; i <= n; i++){
cin >> a[i];
}
if(n == 0){
if(a[0] == 1){
cout << 1 << endl;
return 0;
}
else{
cout << -1 << endl;
return 0;
}
}
if(a[0] != 0){
cout << -1 << endl;
return 0;
}
b[0] = 1 - a[0];
vector<long long> A(n+2, 0);
for(long long i = 0; i <= n; i++){
A[i+1] = A[i] + a[i];
}
bool flag = true;
for(long long i = 1; i <= n; i++){
long long sum = A[n+1] - A[i+1];
b[i] = min(sum, 2*b[i-1] - a[i]);
if(b[i] < 0){
flag = false;
break;
}
}
if(flag == false){
printf("-1\n");
return 0;
}
long long count = 0;
for(long long i = 0; i <= n; i++){
count += a[i] + b[i];
}
cout << count << endl;
return 0;
}
| 0
| 78,979,531
|
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
string s;
cin >> s;
int w;
cin >> w;
int n=s.size();
for(int i=0;i<n;i=i+w){
cout << s[i];
}
cout << endl;
return 0;
}
|
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <iostream>
#define NIL -1
struct Node{
int parent, leftChild, rightSibling;
};
void getDepth(int *arr, Node *nodes, int label, int depth);
std::string getProperty(Node node);
std::vector<int> getChildren(Node *nodes, int label);
int main(int argc, char** argv) {
Node* nodes;
int len, *depth, root = NIL;
scanf("%d", &len);
nodes = (Node *) calloc(sizeof(Node), len + 1);
depth = (int *) calloc(sizeof(int), len + 1);
for (int i = 0; i < len; i++) {
nodes[i].parent = nodes[i].leftChild = nodes[i].rightSibling = NIL;
}
for (int i = 0; i < len; i++) {
int label, degree, child1 = NIL, child2 = NIL;
scanf("%d %d", &label, °ree);
for (int j = 0; j < degree; j++) {
scanf("%d", &child1);
nodes[child1].parent = label;
if (j == 0) {
nodes[label].leftChild = child1;
} else {
nodes[child2].rightSibling = child1;
}
child2 = child1;
}
}
for (int i = 0; i < len; i++) {
if (nodes[i].parent == NIL) {
root = i;
break;
}
}
getDepth(depth, nodes, root, 0);
for (int i = 0; i < len; i++) {
printf("node %d: parent = %d, depth = %d, ", i, nodes[i].parent, depth[i]);
std::cout << getProperty(nodes[i]) << ", ";
std::vector<int> children = getChildren(nodes, i);
std::cout << "[";
if (children.size() > 0) {
std::cout << children[0];
}
if (children.size() > 1) {
for (std::vector<int>::iterator it = children.begin() + 1; it != children.end(); it++) {
std::cout << ", " << *it;
}
}
std::cout << "]" << std::endl;
}
free(nodes);
free(depth);
return 0;
}
void getDepth(int *arr, Node *nodes, int label, int depth) {
arr[label] = depth;
if (nodes[label].leftChild != NIL) {
getDepth(arr, nodes, nodes[label].leftChild, depth + 1);
}
if (nodes[label].rightSibling != NIL) {
getDepth(arr, nodes, nodes[label].rightSibling, depth);
}
}
std::string getProperty(Node node) {
if (node.parent == NIL) {
return "root";
} else {
if (node.leftChild == NIL) {
return "leaf";
} else {
return "internal node";
}
}
}
std::vector<int> getChildren(Node *nodes, int label) {
std::vector<int> results;
Node node = nodes[label];
if (node.leftChild != NIL) {
results.push_back(node.leftChild);
node = nodes[node.leftChild];
while (node.rightSibling != NIL) {
results.push_back(node.rightSibling);
node = nodes[node.rightSibling];
}
}
return results;
}
| 0
| 20,914,492
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
constexpr ll mod = 998244353;
ll mod_pow(ll a, ll n){
ll ret = 1;
while(n > 0){
if(n & 1) ret = (ret*(a % mod))%mod;
a = ((a%mod)*(a%mod)) % mod;
n = n >> 1;
}
return ret;
}
int main(){
ll N;
cin >> N;
map<ll, ll> mp;
bool f = false;
ll mx = 0;
rep(i, 0, N){
ll d; cin >> d;
mp[d]++;
mx = max(mx, d);
if(i != 0 && d == 0) f = true;
if(i == 0 && d != 0) f = true;
}
if(f){
cout << 0 << endl;
return 0;
}
ll ans = 1;
rep(i, 1, mx+1){
if(mp.count(i) == 0){
cout << 0 << endl;
return 0;
}
ans *= mod_pow(mp[i-1], mp[i]);
ans %= mod;
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repr(i, s, e) for(int i=s; i>=e; i--)
#define reps(i, s, e) for(int i=s; i<=e; i++)
#define inf 1e18
#define all(v) v.begin(),v.end()
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<ll>())
#define sz(x) x.size()
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T &a, T b){ if(a<b){ a=b; return true; } return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){ a=b; return true; } return false; }
template<typename T> T gcd(T a, T b){ if(b==0) return a; return gcd(b, a%b); }
template<typename T> T lcm(T a, T b){ return a*b/gcd(a, b); }
template<typename T> void vdebug(vector<T> v){ for(auto vv : v){ cout << vv << " "; } cout << endl; }
template<typename T> void adebug(T arr[], int n){ rep(i, n){ cout << arr[i] << " "; } cout << endl; }
void ans(bool b){ if(b) cout << "Yes" << endl; else cout << "No" << endl; }
void ans2(bool b){ if(b) cout << "YES" << endl; else cout << "NO" << endl; }
int keta(ll num){ int k=0; while(num>0){ num/=10; k++; } return k; }
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
ll h, w, a, b;
int n;
map<pair<ll, ll>, int> ab;
ll cnt[100010];
int delx[] = {0, -1, -2, 0, 0, -1, -1, -2, -2};
int dely[] = {0, 0, 0, -1, -2, -1, -2, -1, -2};
int cntit = 0;
cin >> h >> w >> n;
rep(i, n){
cin >> a >> b;
rep(i, 9){
if(a + dely[i] <= 0 || h-2 < a + dely[i] || b + delx[i] <= 0 || w-2 < b + delx[i]) continue;
ab[make_pair(a + dely[i], b + delx[i])]++;
}
}
ll res[10];
rep(i, 10){
res[i] = 0;
}
for(auto m : ab){
res[m.second]++;
}
ll sum = 0;
rep(i, 10){
sum += res[i];
}
rep(i, 10){
if(i == 0 && (h-2)*(w-2) - sum > 0){
cout << (h-2)*(w-2) - sum << endl;
}else{
cout << res[i] << endl;
}
}
return 0;
}
| 0
| 13,201,655
|
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define DD long double
#define M 1000000007
#define INF 1e18
void setIO(string s = "") {
cin.sync_with_stdio(0); cin.tie(0);
if (s.size()) s += ".in", freopen(s.c_str(), "r", stdin);
}
int tt = 1;
void solve() {
int n;
cin >> n;
set<int> f;
for (int i = 0; i < n; i++) {
int aa; cin >> aa;
f.insert(aa);
}
cout << ((f.size() == n) ? "YES" : "NO") << endl;
}
int main() {
setIO();
while (tt--) {
solve();
}
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define ft ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
ll a[105];
int main()
{
ft
ll t,i,j,n,m,l,r,s=0,x=0,y=0,z=0;
cin>>n;
for(l=2; l<=n; l++)
{
r=l;
for(i=2; i<=(r/i); i++)
{
while(r%i==0)
{
r/=i;
a[i]++;
}
}
if(r>1)
{
a[r]++;
}
}
l=0,r=0;
for(i=2; i<=n; i++)
{
if(a[i]>=74)
{
z++;
}
if(a[i]>=24)
{
x++;
}
if(a[i]>=14)
{
y++;
}
if(a[i]>3)
{
r++;
}
if(a[i]>1)
{
l++;
}
}
s=z+x*(l-1)+y*(r-1)+(r*(r-1)*(l-2))/2;
cout<<s<<"\n";
return 0;
}
| 0
| 16,077,121
|
#include <bits/stdc++.h>
typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;
#define MAX_NUM (1000000007)
#define PI 3.14159265358979323846
using namespace std;
template <typename T>
static inline void ArrayInput(vector<T>& A) {
for (auto itr = A.begin(); itr < A.end(); ++itr) cin >> *itr;
}
template <typename T>
static inline void ArrayPut(const vector<T>& A) {
for (auto itr = A.begin(); itr < A.end(); ++itr) cout << *itr << " ";
cout << endl;
}
template <typename T>
static inline T ArraySum(vector<T>& A) {
T res = 0;
for (auto itr = A.begin(); itr < A.end(); ++itr) res += *itr;
return res;
}
bool Sec_compare(pair<uint64_t, uint64_t> a, pair<uint64_t, uint64_t> b) {
if (a.second != b.second) {
return a.second < b.second;
} else {
return a.first < b.first;
}
}
u64 dec_dig(u64 num) {
u64 res = 0;
while (num > 0) {
num /= 10;
++res;
}
return res;
}
i64 modinv(i64 a, i64 m) {
i64 b = m, u = 1, v = 0;
while (b) {
i64 t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0) u += m;
return u;
}
u64 gcd(u64 a, u64 b) {
if (a < b) {
a ^= b;
b ^= a;
a ^= b;
}
return b ? gcd(b, a % b) : a;
}
i64 My_Comb(u64 n, u64 k, i64 m) {
if (n < k) return 0;
if (k == 0 || n == k) return 1;
u64 res = 1;
k = (n / 2 < k) ? n - k : k;
for (u64 i = 1; i <= k; ++i)
res = (((res * (n + 1 - i)) % m) * modinv(i, m)) % m;
return res;
}
i64 My_Pow(u64 a, u64 n, i64 m) {
u64 tmp = n, calc = 1;
while (tmp > 0) {
if (tmp % 2) {
tmp--;
calc *= a;
calc %= m;
} else {
a *= a;
a %= m;
tmp /= 2;
}
}
return calc;
}
int main() {
cout << setprecision(18);
string S;
cin >> S;
u32 R = 0, B = 0;
for (u32 i = 0; i < S.size(); ++i) {
if (S[i] == '0') R++;
if (S[i] == '1') B++;
}
cout << ((R < B) ? R * 2 : B * 2) << endl;
return 0;
}
|
#include <iostream>
int mcxi2int(std::string s) {
int ret = 0;
int tmp = 1;
for (int i = 0; i < s.size(); i++) {
switch (s[i]) {
default: {
tmp = s[i] - '0';
break;
}
case 'm': { ret += tmp * 1000, tmp = 1; break; }
case 'c': { ret += tmp * 100, tmp = 1; break; }
case 'x': { ret += tmp * 10, tmp = 1; break; }
case 'i': { ret += tmp * 1, tmp = 1; break; }
}
}
return ret;
}
std::string int2mcxi(int n) {
char s[16];
int count = 0;
if (n / 1000 > 0) {
if (n / 1000 != 1) {
s[count++] = n / 1000 + '0';
}
s[count++] = 'm';
n -= (n / 1000) * 1000;
}
if (n / 100 > 0) {
if (n / 100 != 1) {
s[count++] = n / 100 + '0';
}
s[count++] = 'c';
n -= (n / 100) * 100;
}
if (n / 10 > 0) {
if (n / 10 != 1) {
s[count++] = n / 10 + '0';
}
s[count++] = 'x';
n -= (n / 10) * 10;
}
if (n > 0) {
if (n != 1) {
s[count++] = n + '0';
}
s[count++] = 'i';
}
s[count] = '\0';
return s;
}
int main() {
int n;
std::cin >> n;
while (n--) {
std::string inputs[2];
std::cin >> inputs[0] >> inputs[1];
int sum = mcxi2int(inputs[0]) + mcxi2int(inputs[1]);
std::cout << int2mcxi(sum) << std::endl;
}
return 0;
}
| 0
| 99,094,142
|
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> arr;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
arr.push_back(a);
}
if (n == 1) {
cout << 0;
return 0;
}int i = 0;
int j = 1;
int ans = 0;
while (i < arr.size()) {
if (arr.at(i) != j) {
arr.erase(arr.begin() + i);
ans++;
}
else {
i++;
j++;
}
}if (n == ans) {
ans = -1;
}
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
#include <iostream>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define fix(f,n) std::fixed<<std::setprecision(n)<<f
ll mod = 1e9 + 7;
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update> ordered_set;
#ifndef ONLINE_JUDGE
template<typename T>
void __p(T a) {
cout<<a;
}
template<typename T, typename F>
void __p(pair<T, F> a) {
cout<<"{";
__p(a.first);
cout<<",";
__p(a.second);
cout<<"}";
}
template<typename T>
void __p(std::vector<T> a) {
cout<<"{";
for(auto it=a.begin(); it<a.end(); it++)
__p(*it),cout<<",}"[it+1==a.end()];
}
template<typename T, typename ...Arg>
void __p(T a1, Arg ...a) {
__p(a1);
__p(a...);
}
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
cout<<name<<" : ";
__p(arg1);
cout<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
int bracket=0,i=0;
for(;; i++)
if(names[i]==','&&bracket==0)
break;
else if(names[i]=='(')
bracket++;
else if(names[i]==')')
bracket--;
const char *comma=names+i;
cout.write(names,comma-names)<<" : ";
__p(arg1);
cout<<" | ";
__f(comma+1,args...);
}
#define trace(...) cout<<"Line:"<<__LINE__<<" ", __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...)
#endif
struct edge{
int a, b, weight;
};
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);
}
};
long long modInverse(long long a, long long m) {
if(__gcd(a, m) != 1){
throw "modular inverse does not exist.";
}
long long m0 = m;
long long y = 0, x = 1;
if (m == 1) return 0;
while (a > 1) {
long long q = a / m;
long long t = m;
m = a % m, a = t;
t = y;
y = x - q * y;
x = t;
}
if (x < 0)
x += m0;
return x;
}
vector<int> sieveOfEratosthenes(int n) {
vector<int> primes;
bool prime[n + 1];
memset(prime, true, sizeof(prime));
for (int p = 2; p * p <= n; p++) {
if (prime[p] == true) {
for (int i = p * p; i <= n; i += p)
prime[i] = false;
}
}
for (int p = 2; p <= n; p++)
if (prime[p])
primes.push_back(p);
return primes;
}
int add(int a, int b) {
a += b;
if (a >= mod) a -= mod;
return a;
}
int sub(int a, int b) {
a -= b;
if (a < 0) a += mod;
return a;
}
int mul(ll a, int b) {
return (a * b) % mod;
}
int pwr(int x, int e) {
int res = 1;
while (e) {
if (e & 1) {
res = mul(res, x);
}
x = mul(x, x);
e /= 2;
}
return res;
}
vector<vector<int>> adj;
vector<vector<int>> dp;
void dfs(int u, int p){
dp[u][0] = dp[u][1] = 1;
for(int v: adj[u]) if(v != p) {
dfs(v, u);
dp[u][0] = mul(dp[u][0], add(dp[v][0], dp[v][1]));
dp[u][1] = mul(dp[u][1], dp[v][0]);
}
}
void solve() {
int n;
cin >> n;
adj.resize(n);
dp.resize(n, vector<int>(2));
int u ,v;
for(int i = 0; i < n-1; i++){
cin >> u >> v;
u--;
v--;
adj[u].push_back(v);
adj[v].push_back(u);
}
dfs(0, -1);
cout << add(dp[0][0], dp[0][1]) << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
for (int i = 0; i < t; i++) {
solve();
}
return 0;
}
| 0
| 55,888,387
|
#include<bits/stdc++.h>
using namespace std;
int main(){
string s;
int n;
cin>>n>>s;
for(int i=0;i<2;i++)
for(int j=0;j<2;j++)
{
string t;
t+=(i+'0');
t+=(j+'0');
for(int k=1;k<n-1;k++)
{
if(t[k]=='0')
{
if(s[k]=='o')
t+=t[k-1];
else
t+=(t[k-1]=='0'?'1':'0');
}
else
{
if(s[k]=='x')
t+=t[k-1];
else
t+=(t[k-1]=='0'?'1':'0');
}
}
if(t[n-1]=='1')
{
if(s[n-1]=='o'&&t[0]=='0'&&t[n-2]=='1'||s[n-1]=='o'&&t[0]=='1'&&t[n-2]=='0')
{
if(t[0]=='0')
{
if(s[0]=='o'&&t[1]=='1'&&t[n-1]=='1'||s[0]=='o'&&t[1]=='0'&&t[n-1]=='0')
{
for(int i=0;i<n;i++)
{
if(t[i]=='0')
cout<<"S";
else
cout<<"W";
}
return 0;
}
if(s[0]=='x'&&t[1]=='0'&&t[n-1]=='1'||s[0]=='x'&&t[1]=='1'&&t[n-1]=='0')
{
for(int i=0;i<n;i++)
{
if(t[i]=='0')
cout<<"S";
else
cout<<"W";
}
return 0;
}
}
else
{
if(s[0]=='x'&&t[1]=='1'&&t[n-1]=='1'||s[0]=='x'&&t[1]=='0'&&t[n-1]=='0')
{
for(int i=0;i<n;i++)
{
if(t[i]=='0')
cout<<"S";
else
cout<<"W";
}
return 0;
}
if(s[0]=='o'&&t[1]=='0'&&t[n-1]=='1'||s[0]=='o'&&t[1]=='1'&&t[n-1]=='0')
{
for(int i=0;i<n;i++)
{
if(t[i]=='0')
cout<<"S";
else
cout<<"W";
}
return 0;
}
}
}
if(s[n-1]=='x'&&t[0]=='1'&&t[n-2]=='1'||s[n-1]=='x'&&t[0]=='0'&&t[n-2]=='0')
{
if(t[0]=='0')
{
if(s[0]=='o'&&t[1]=='1'&&t[n-1]=='1'||s[0]=='o'&&t[1]=='0'&&t[n-1]=='0')
{
for(int i=0;i<n;i++)
{
if(t[i]=='0')
cout<<"S";
else
cout<<"W";
}
return 0;
}
if(s[0]=='x'&&t[1]=='0'&&t[n-1]=='1'||s[0]=='x'&&t[1]=='1'&&t[n-1]=='0')
{
for(int i=0;i<n;i++)
{
if(t[i]=='0')
cout<<"S";
else
cout<<"W";
}
return 0;
}
}
else
{
if(s[0]=='x'&&t[1]=='1'&&t[n-1]=='1'||s[0]=='x'&&t[1]=='0'&&t[n-1]=='0')
{
for(int i=0;i<n;i++)
{
if(t[i]=='0')
cout<<"S";
else
cout<<"W";
}
return 0;
}
if(s[0]=='o'&&t[1]=='0'&&t[n-1]=='1'||s[0]=='o'&&t[1]=='1'&&t[n-1]=='0')
{
for(int i=0;i<n;i++)
{
if(t[i]=='0')
cout<<"S";
else
cout<<"W";
}
return 0;
}
}
}
}
else
{
if(s[n-1]=='o'&&t[0]=='0'&&t[n-2]=='0'||s[n-1]=='o'&&t[0]=='1'&&t[n-2]=='1')
{
if(t[0]=='0')
{
if(s[0]=='o'&&t[1]=='1'&&t[n-1]=='1'||s[0]=='o'&&t[1]=='0'&&t[n-1]=='0')
{
for(int i=0;i<n;i++)
{
if(t[i]=='0')
cout<<"S";
else
cout<<"W";
}
return 0;
}
if(s[0]=='x'&&t[1]=='0'&&t[n-1]=='1'||s[0]=='x'&&t[1]=='1'&&t[n-1]=='0')
{
for(int i=0;i<n;i++)
{
if(t[i]=='0')
cout<<"S";
else
cout<<"W";
}
return 0;
}
}
else
{
if(s[0]=='x'&&t[1]=='1'&&t[n-1]=='1'||s[0]=='x'&&t[1]=='0'&&t[n-1]=='0')
{
for(int i=0;i<n;i++)
{
if(t[i]=='0')
cout<<"S";
else
cout<<"W";
}
return 0;
}
if(s[0]=='o'&&t[1]=='0'&&t[n-1]=='1'||s[0]=='o'&&t[1]=='1'&&t[n-1]=='0')
{
for(int i=0;i<n;i++)
{
if(t[i]=='0')
cout<<"S";
else
cout<<"W";
}
return 0;
}
}
}
if(s[n-1]=='x'&&t[0]=='1'&&t[n-2]=='0'||s[n-1]=='x'&&t[0]=='0'&&t[n-2]=='1')
{
if(t[0]=='0')
{
if(s[0]=='o'&&t[1]=='1'&&t[n-1]=='1'||s[0]=='o'&&t[1]=='0'&&t[n-1]=='0')
{
for(int i=0;i<n;i++)
{
if(t[i]=='0')
cout<<"S";
else
cout<<"W";
}
return 0;
}
if(s[0]=='x'&&t[1]=='0'&&t[n-1]=='1'||s[0]=='x'&&t[1]=='1'&&t[n-1]=='0')
{
for(int i=0;i<n;i++)
{
if(t[i]=='0')
cout<<"S";
else
cout<<"W";
}
return 0;
}
}
else
{
if(s[0]=='x'&&t[1]=='1'&&t[n-1]=='1'||s[0]=='x'&&t[1]=='0'&&t[n-1]=='0')
{
for(int i=0;i<n;i++)
{
if(t[i]=='0')
cout<<"S";
else
cout<<"W";
}
return 0;
}
if(s[0]=='o'&&t[1]=='0'&&t[n-1]=='1'||s[0]=='o'&&t[1]=='1'&&t[n-1]=='0')
{
for(int i=0;i<n;i++)
{
if(t[i]=='0')
cout<<"S";
else
cout<<"W";
}
return 0;
}
}
}
}
}
cout<<-1;
return 0;
}
|
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdio>
using namespace std;
int main(){
int n, m, l;
while (1) {
cin >> n >> m >> l;
if((n == -1) && (m == -1) && (l == -1)) {
break;
} else if ((n == -1) || (m == -1)) {
cout << 'F' << endl;
} else if (n + m >= 80) {
cout << 'A' << endl;
} else if (n + m >= 65) {
cout << 'B' << endl;
} else if (n + m >= 50) {
cout << 'C' << endl;
} else if (n + m >= 30) {
if (l >= 50) {
cout << 'C' << endl;
} else {
cout << 'D' << endl;
}
} else {
cout << 'F' << endl;
}
}
}
| 0
| 40,064,134
|
#include <cstdio>
#include <iostream>
using namespace std;
int main()
{
string s;
cin >> s;
string t = "2019/04/30";
if(s>t)
{
cout << "TBD" << "\n";
}
else
{
cout << "Heisei" << "\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
inline int read() {
int x = 0, fh = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-')
fh = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = (x << 1) + (x << 3) + c - '0';
c = getchar();
}
return x * fh;
}
const int N = 2010, MOD = 1e9 + 7;
int n, i;
LL f[N];
int main() {
n = read();
f[3] = f[4] = 1;
for (i = 5; i <= n; i++) f[i] = ((f[i - 2] + f[i - 3]) % MOD + f[i - 4]) % MOD;
cout << f[n] << '\n';
return 0;
}
| 0
| 31,976,928
|
#include<bits/stdc++.h>
using namespace std;
int main(){
int apple, fragment, pie;
cin >> apple >> fragment;
pie = (apple * 3 + fragment)/2;
cout << pie << endl;
}
|
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long int
#define pb push_back
#define fi first
#define se second
#define ld long double
#define vi vector<vector<ll> >
using namespace std;
const int MOD=1000000007;
const int MOD2=998244353;
const ll MAX=9187201950435737471;
const int N=100005;
const int INF=1e9+7;
const long double PI=acos(-1);
void solve(int T){
int n;
cin>>n;
vector<int>a(n+1);
for(int i=1;i<=n;i++){
int x;
cin>>x;
a[x]=i;
}
for(int i=1;i<=n;i++){
cout<<a[i]<<" ";
}
}
int main() {
fastio
int T=1;
for(int i=1;i<=T;i++){
solve(i);
}
return 0;
}
| 0
| 81,001,820
|
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
signed main(void)
{
set<char> st;
string s;
cin >> s;
st.insert(s[0]);
st.insert(s[1]);
st.insert(s[2]);
if (st.size() == 3)
cout << "Yes" << endl;
else
cout << "No" << endl;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using Graph=vector<vector<int>>;
typedef long long ll;
int rui(int N,int K){
int A=1;
if(K==0){
return 1;
}
else{
rep(i,K){
A=A*N;
}
return A;
}
}
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
int main(){
int N;
cin>>N;
vector<int>list;
rep(i,5){
list.push_back(rui(9,i+1));
}
rep(j,6){
list.push_back(rui(6,j+1));
}
sort(list.begin(),list.end());
reverse(list.begin(),list.end());
vector<int>dp(N+1,1e9+7);
dp[0]=0;
for(int i=1;i<N+1;i++){
dp[i]=1+dp[i-1];
rep(j,list.size()){
if(i>=list[j]){
chmin(dp[i],dp[i-list[j]]+1);
}
}
}
cout<<dp[N]<<endl;
}
| 0
| 15,612,176
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repe(i, n) for (int i = 0; i <= (n); ++i)
#define repe1(i, n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
const int INF = 1e9;
const ll mod = 1000000007;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a * b / gcd(a, b);}
int main() {
string s;
cin >> s;
int res = count(s.begin(), s.end(), 'o');
if (15-s.size()+res >= 8) {
cout << "YES" << "\n";
} else {
cout << "NO" << "\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
int main(){
int N;
cin >> N;
vec<int> cnt(26,100);
for(int i=0;i<N;i++){
string S;
cin >> S;
vec<int> v(26);
for(auto& c:S) v[c-'a']++;
for(int j=0;j<26;j++) cnt[j] = min(cnt[j],v[j]);
}
string ans = "";
for(int i=0;i<26;i++){
char c = 'a'+i;
for(int j=0;j<cnt[i];j++) ans += c;
}
cout << ans << "\n";
}
| 0
| 18,123,614
|
#include<iostream>
using namespace std;
int main(void) {
int A, B, C, D;
scanf("%d%d%d%d", &A, &B, &C, &D);
printf("%d\n", min(A, B) + min(C, D));
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
int n, q;
long long x[100005], l, y[100005][20];
vector<int> vec;
signed main() {
cin.tie(0), ios::sync_with_stdio(0);
cin >> n;
for(int i = 1; i <= n; i++){
cin >> x[i];
vec.pb(x[i]);
}
vec.pb(-1);
sort(vec.begin(), vec.end());
cin >> l;
cin >> q;
for(int i = 1; i <= n; i++){
int it = upper_bound(vec.begin(), vec.end(), x[i] + l) - vec.begin() - 1;
y[i][0] = it;
}
for(int i = 1; i <= 18; i++){
for(int j = 1;j <= n; j++)
y[j][i] = y[y[j][i - 1]][i - 1];
}
while(q--){
int a, b, sum = 0;
cin >> a >> b;
if(a == b){
cout << sum << "\n";
continue;
}
if(b < a)
swap(a, b);
for(int i = 18; i >= 0; i--){
if(y[a][i] < b){
a = y[a][i];
sum += (1 << i);
}
}
sum++;
cout << sum << "\n";
}
}
| 0
| 29,254,747
|
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
char s[303][303];
int ans = 0;
for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) cin >> s[i][j];
for(int l = 0; l < n; l++){
bool yes = true;
for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) if(s[(i + l) % n][j] != s[(j + l) % n][i]) yes = false;
if(yes) ans += n;
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
#include<math.h>
#include<algorithm>
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
#define PI 3.14159265358979323846264338327950
#define INF 1e18
#define mod 1000000007
int r, p, s;
int c (char x){
if(x == 'r') return p ;
if(x == 's') return r ;
if(x == 'p') return s ;
}
char f (char x){
if(x == 'r') return 'p' ;
if(x == 's') return 'r' ;
if(x == 'p') return 's' ;
}
char find(char x, char y){
if((x == 'r' && y == 's') ||(x == 's' && y == 'r')) return 'p' ;
if((x == 'p' && y == 's') ||(x == 's' && y == 'p')) return 'r' ;
if((x == 'r' && y == 'p') ||(x == 'p' && y == 'r')) return 's' ;
}
int main() {
int n, k ;
cin >> n >> k ;
cin >> r >> s >> p ;
string t ;
cin >> t ;
ll ans = 0 ;
vector<char> vec(n) ;
rep(i, n){
if(i - k >= 0 && f(t[i]) == vec[i - k]){
if(i + k > n || f(t[i + k]) == vec[i - k]) vec[i] = t[i] ;
else {
vec[i] = find(f(t[i + k]), vec[i - k]) ;
}
}
else{
vec[i] = f(t[i]) ;
ans += c(t[i]) ;
}
}
cout << ans << endl ;
}
| 0
| 31,147,815
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007
int main(){
string S;
ll K;
cin >> S >> K;
ll cnt=0;
char bf=S[0];
ll ac=0;
for(int i=0;i<S.size();i++){
if(i==S.size()-1){
if(S[i-1]==S[i]){
cnt++;
}
ac+=cnt/2;
break;
}
if(S[i]!=bf){
ac+=cnt/2;
cnt=1;
bf=S[i];
}else{
cnt++;
}
}
if(S[0]==S[S.size()-1]){
ll cnt_h=0;
for(int i=0;i<S.size();i++){
if(S[i]!=S[0]){
break;
}else{
cnt_h++;
}
}
if(cnt_h==S.size()){
cout << S.size()*K/2 << endl;
return 0;
}
ll cnt_t=0;
for(int i=S.size()-1;i>=0;i--){
if(S[i]!=S[S.size()-1]){
break;
}else{
cnt_t++;
}
}
cout << K*ac - (cnt_h/2 + cnt_t/2 - (cnt_h+cnt_t)/2)*(K-1) << endl;
}else{
cout << K*(ac) << endl;
}
return 0;
}
|
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;i<n;i++)
#define endl "\n"
#define ff first
#define ss second
#define int long long
#define pb push_back
#define mp make_pair
#define vec(x) vector<x>
#define matrix(x) vector<vector<x>>
#define sz(x) (int)x.size()
#define mem(a,b) memset(a, b, sizeof a)
#define vii vector<pair<int,int>>
#define pii pair<int,int>
#define vi vector<int>
#define mii map<int,int>
#define pqb priority_queue<int>
#define pqs priority_queue<int,vi,greater<int> >
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define MOD 998244353
#define deb(x) cerr <<#x<<" = "<<x<<"\n"
#define inf 1e18
#define ps(x,y) fixed<<setprecision(y)<<x
#define mk(arr,n,type) type *arr=new type[n];
#define w(x) int x; cin>>x; while(x--)
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for (int i = a; i<b; ++i)
#define len(s) s.length()
#define watch(x) cout << #x << " = " << x << endl
#define trace(x) cerr << #x << " = " << x << endl
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
int power(int a,int b,int m=mod)
{int ans=1;while(b>0){if(b&1)ans=(ans*a)%m;a=(a*a)%m;b>>=1;}
return ans;}
void angshuGod()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
const int N = 1e5+1;
const double pi = acos(-1);
void solve(){
string s; cin>>s;
int n = len(s);
int a[n+1] = {0}, b[n+1] = {0};
for(int i = 1;i<=n;i++){
if(s[i-1]=='<') a[i] = a[i-1] + 1;
}
for(int i = n-1;i>=0;i--){
if(s[i]=='>') b[i] = b[i+1] + 1;
}
int sum = 0;
for(int i = 0;i<=n;i++) sum += max(a[i],b[i]);
cout<<sum;
}
int32_t main()
{
angshuGod();
int t;
t = 1;
while(t--){
solve();
}
return 0;
}
| 0
| 4,712,399
|
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<ll>;
using VV = vector<VI>;
using VS = vector<string>;
template <typename A, typename B>
string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(const string& s) {
return '"' + s + '"';
}
string to_string(const char* s) {
return to_string((string) s);
}
string to_string(bool b) {
return (b ? "true" : "false");
}
string to_string(vector<bool> v) {
bool first = true;
string res = "{";
for (int i = 0; i < static_cast<int>(v.size()); i++) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(v[i]);
}
res += "}";
return res;
}
template <size_t N>
string to_string(bitset<N> v) {
string res = "";
for (size_t i = 0; i < N; i++) {
res += static_cast<char>('0' + v[i]);
}
return res;
}
template <typename A>
string to_string(A v) {
bool first = true;
string res = "{";
for (const auto &x : v) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(x);
}
res += "}";
return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
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; }
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,b) FOR(i, 0, b)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")
#define pb(s) push_back(s)
#define SZ(x) ((int)(x).size())
void no(){p_no(); exit(0);}
void yes(){p_yes(); exit(0);}
const ll mod = 1e9 + 7;
const ll inf = 1e18;
void vprint(vector<ll> A){
ll L = A.size();
FOR(i, 0, L){
if(i) cout << ' ';
cout << A[i];
}
cout << endl;
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
ll N;
cin >> N;
VI A(N);
rep(i, N){
cin >> A.at(i);
}
ll cnt = 0;
ll LOOP = 1000000;
while(LOOP--){
rep(i, N){
if(A[i]>=N){
ll num = A[i]/N;
A[i] %= N;
cnt += num;
rep(j, N){
if(i!=j){
A[j] += num;
}
}
}
}
}
p(cnt);
return 0;
}
|
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x) cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
int main(void)
{
cin.tie(0);
ios::sync_with_stdio(false);
int N; cin >> N;
ll ans = 0;
ll num = 0;
ll A[100010], B[100010];
rep(i, N) cin >> A[i] >> B[i];
RREP(i, N - 1, 0) {
A[i] += num;
ll tmp = (B[i] - A[i] % B[i]) % B[i];
num += tmp;
ans += tmp;
}
cout << ans << endl;
return 0;
}
| 0
| 23,229,773
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a[3][3];
bool s[3][3];
int i, j;
for(i = 0; i < 3; i++) {
for(j = 0; j < 3; j++) {
cin >> a[i][j];
}
}
for(i = 0; i < 3; i++) {
for(j = 0; j < 3; j++) {
s[i][j] = false;
}
}
int n;
cin >> n;
int b[n];
int k;
for(i = 0; i < n; i++) {
cin >> b[i];
for(j = 0; j < 3; j++) {
for(k = 0; k < 3; k++) {
if (b[i] == a[j][k]) {
s[j][k] = true;
}
}
}
}
string ans = "No";
for(i = 0; i < 3; i++) {
bool tmp = true;
for(j = 0; j < 3; j++) {
if (s[i][j] == false) {
tmp = false;
}
}
if (tmp) {
ans = "Yes";
}
}
for(i = 0; i < 3; i++) {
bool tmp = true;
for(j = 0; j < 3; j++) {
if (s[j][i] == false) {
tmp = false;
}
}
if (tmp) {
ans = "Yes";
}
}
if (s[0][0] == true && s[1][1] == true && s[2][2] == true) {
ans = "Yes";
}
if (s[0][2] == true && s[1][1] == true && s[2][0] == true) {
ans = "Yes";
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int) (n); i++)
#define _GLIBCXX_DEBUG
template <typename T>
bool chmax(T &a, const T& b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T>
bool chmin(T &a, const T& b) {
if (a > b) {
a = b;
return true;
}
return false;
}
const int max_n = 15, INF = 1e8;
int n, m, x, ans = INF;
int c[max_n], a[max_n][max_n];
bool poss = false;
int main(){
cin >> n >> m >> x;
rep(i, n){
cin >> c[i];
rep(j, m){
cin >> a[i][j];
}
}
for(int bit = 0; bit < (1 << n); bit++){
int sum = 0;
int pts[m] = {0};
for(int i = 0; i < n; i++){
if((bit >> i) & 1) {
sum += c[i];
for(int j = 0; j < m; j++) pts[j] += a[i][j];
}
}
auto iter = min_element(pts, pts+m);
if(*iter >= x && ans > sum) poss = true, ans = sum;
}
if(poss) cout << ans << endl;
else cout << -1 << endl;
return 0;
}
| 0
| 52,369,267
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string a,b,c;
string kekka;
cin >> a >> b >> c;
kekka = toupper(a.at(0));
kekka += toupper(b.at(0));
kekka += toupper(c.at(0));
cout << kekka;
}
|
#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
int n,x;
while(cin >> n >>x,(n!=0)||(x!=0)){
int answer = 0;
for(int a = 1;a<=n;a++){
for(int b = a+1;b <=n;b++){
for(int c=b+1;c <=n;c++){
if(x == a+b+c){answer++;
}
}
}
}
cout << answer << endl;
}
return 0;
}
| 0
| 32,254,771
|
#include <iostream>
using namespace std;
int main (){
int a, b, c, x ;
cin >>a >>b >>c;
if(a > b ) {
x=a;
a=b;
b=x;
};
if(b > c ) {
x=c;
c=b;
b=x;
};
if(a > b) {
x=a;
a=b;
b=x;
};
cout <<a <<" " << b << " " << c <<"\n";
return 0 ;
}
|
#include <iostream>
using namespace std;
int main() {
int N, A, B;
cin >> N >> A >> B;
int total = 0;
for (int n=1; n<=N; ++n) {
int r = n;
int sub = 0;
while (r != 0) {
sub += r % 10;
r /= 10;
}
if (((A <= sub) && (sub <= B))) {
total += n;
}
}
cout << total << endl;
}
| 0
| 4,710,282
|
#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 x;
cin >> x;
if(x < 1200) cout << "ABC" << endl;
else cout << "ARC" << endl;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
const int inf=1e9;
const int mod=998244353;
int x,m;
ll n;
int pre[maxn];
ll sum1[maxn];
int main(){
scanf("%lld%d%d",&n,&x,&m);
pre[x]=1;sum1[1]=x;
int cnt=0,pos=inf;
ll sum=0;
for(int i=2;i<=n;i++){
x=1ll*x*x%m;
sum1[i]=sum1[i-1]+x;
if(pre[x]){
cnt=i-pre[x];
pos=i;
sum=sum1[i]-sum1[pre[x]];
break;
}
pre[x]=i;
}
ll sumr=0;
int cntr=0;
for(int i=0;i<maxn;i++)
if(pre[i]&&pre[i]+cnt<pos)cntr++,sumr+=i;
if(!cnt){
sum+=sumr;
printf("%lld\n",sum);
return 0;
}
sum*=(n-cntr)/cnt;
sum+=sumr;
int r=(n-cntr)%cnt;
for(int i=1;i<=r;i++){
sum+=x;
x=1ll*x*x%m;
}
printf("%lld\n",sum);
return 0;
}
| 0
| 79,392,530
|
#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <bitset>
#include <iterator>
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<int,int> pii;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int MAXN = 2e5+50;
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define f first
#define s second
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define per(i,r,l) for(int i=r;i>=l;--i)
#define rep0(i,l,r) for(int i=l;i<r;++i
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int lcm(int a, int b) { return a * (b / gcd(a, b)); }
int solve(){
int n;
cin>>n;
vector<int> vec(n);
for(int i=0;i<n;++i)
cin>>vec[i];
set<int> st;
for(int i=0;i<vec.size();++i){
if(st.find(vec[i])==st.end()){
st.insert(vec[i]);
}
else
return 1;
}
return 0;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
if(solve()==1)
cout<<"NO"<<endl;
else
cout<<"YES"<<endl;
}
|
#include<bits/stdc++.h>
using namespace std;
int main(){
cin.tie(NULL);
ios::sync_with_stdio(false);
string s;
int h,w;
char x='A';
cin>>h>>w;
for(int i=1;i<=h;i++){
for(int j=0;j<w;j++){
cin>>s;
if(s=="snuke"){
cout<<char(x+j)<<i<<'\n';
}
}
}
return 0;
}
| 0
| 91,963,157
|
#include <bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define IO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
const int INF = 1e9 + 7;
const int N = 1e5+5;
int main() {
IO;
int n, x;
cin >> n >> x;
if (x%2 == 0 && x <= 4*n && x >= 2*n)
cout << "Yes";
else
cout << "No";
}
|
#include <iostream>
#include <algorithm>
int main()
{
int w, h, n;
std::cin >> w >> h >> n;
int x_l = 0, x_u = w, y_l = 0, y_u = h;
for (int i = 0; i < n; ++i)
{
int x, y, a;
std::cin >> x >> y >> a;
switch (a)
{
case 1:
x_l = std::max(x, x_l);
break;
case 2:
x_u = std::min(x, x_u);
break;
case 3:
y_l = std::max(y, y_l);
break;
case 4:
y_u = std::min(y, y_u);
break;
default:
break;
}
}
if (x_l >= x_u || y_l >= y_u)
{
std::cout << 0 << std::endl;
}
else
{
std::cout << (x_u - x_l) * (y_u - y_l) << std::endl;
}
return 0;
}
| 0
| 34,314,228
|
#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;
string s;
cin >> n >> s;
if(s.size() % 2 == 1) {
cout << "No" << endl;
return 0;
}
int x = s.size() / 2;
rep(i, x) {
if(s[i] != s[i + x]) {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=105;
struct node{
int x,y;
bool operator<(const node&o)const{
return atan2(y,x)<atan2(o.y,o.x);
}
}a[N<<1];
int n;
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d%d",&a[i].x,&a[i].y);
sort(a+1,a+1+n);
for(int i=1;i<=n;i++) a[i+n]=a[i];
double ans=0;
for(int i=1;i<=n;i++){
ll x=0,y=0;
for(int j=i;j<i+n;j++){
x+=a[j].x;y+=a[j].y;
ans=max(ans,sqrt(x*x+y*y));
}
}
printf("%.15f\n",ans);
}
| 0
| 77,519,692
|
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
#define ft first
#define sd second
#define pb push_back
#define pob pop_back()
#define pf push_front
#define pof pop_front()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<char,char> pcc;
typedef pair<long long,long long> pll;
int main() {
fastIO;
int n, aux, rta = 0;
cin >> n;
for(int i = 1; i <= n; i++){
aux = log10(i)+1;
if(aux%2) rta++;
}
cout << rta << endl;
return 0;
}
|
#include <cstdio>
using namespace std;
int main(int argc, char** argv)
{
char a = getchar();
if('a' <= a && a <= 'z') putchar('a');
else putchar('A');
return 0;
}
| 0
| 94,624,401
|
#include<bits/stdc++.h>
using namespace std;
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first
#define se second
#define co(a) cout<<a<<endl
#define sz size()
#define bgn begin()
#define en end()
#define pb(a) push_back(a)
#define pop pop_back
#define V vector
#define P pair
#define V2(a,b,c) V<V<int>> a(b,V<int>(c))
#define V2a(a,b,c,d) V<V<int>> a(b,V<int>(c,d))
#define incin(a) int a; cin>>a
template<class T>
void cou(vector<vector<T>> a){
int b=a.size();
int c=a[0].size();
fo(i,b){
fo(j,c){
cout<<a[i][j];
if(j==c-1)
cout<<endl;
else
cout<<' ';
}
}
}
int wari(int a,int b) {
if(a%b==0)
return a/b;
else
return a/b+1;
}
int keta(int a){
double b=a;
b=log10(b);
int c=b;
return c+1;
}
int souwa(int a){
return a*(a+1)/2;
}
int lcm(int a,int b){
int d=a,e=b,f;
if(a<b)
swap(a,b);
int c,m=1;
while(m){
c=a%b;
if(c==0){
f=b;
m--;
}
else{
a=b;
b=c;
}
}
return d*e/f;
}
int gcm(int a,int b){
int d=a,e=b,f;
if(a<b)
swap(a,b);
int c,m=1;
while(m){
c=a%b;
if(c==0){
f=b;
m--;
}
else{
a=b;
b=c;
}
}
return f;
}
bool prime(int a){
if(a<2)
return false;
else if(a==2)
return true;
else if(a%2==0)
return false;
double b=sqrt(a);
for(int i=3;i<=b;i+=2){
if(a%i==0){
return false;
}
}
return true;
}
struct Union{
vector<int> par;
Union(int n){
par= vector<int>(n, -1);
}
int find(int x){
if(par[x]<0)
return x;
else
return par[x]=find(par[x]);
}
bool same(int a,int b){
return find(a)==find(b);
}
int Size(int a){
return -par[find(a)];
}
void unite(int a,int b){
a=find(a);
b=find(b);
if(a==b)
return;
if(Size(b)>Size(a))
swap<int>(a,b);
par[a]+=par[b];
par[b]=a;
}
};
int ketas(int a){
string b=to_string(a);
int c=0;
fo(i,keta(a)){
c+=b[i]-'0';
}
return c;
}
signed main(){
string a;
cin>>a;
if(a.sz>=4){
if(a[0]=='Y'&&a[1]=='A'&&a[2]=='K'&&a[3]=='I')
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
else
cout<<"No"<<endl;
}
|
#include<bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define watch(x); cout << "\n" << #x << " is: " << x << "\n";
#define ll long long int
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define pb push_back
#define nl cout<<"\n"
#define gcd(a,b) __gcd(a,b)
#define sq(a) (a)*(a)
#define loop(i,a,b) for (int i = a; i <= b; i++)
#define rloop(i,a,b) for (int i = a; i >= b; i--)
#define sz(a) a.size()
#define mod 1000000007
#define PI 2*acos(0.0)
vector<ll> factorize(ll x) {
vector<ll> res;
for(ll i=2;i*i<=x;i++)
{
if(x%i!=0) continue;
int num=0;
while(x%i==0)
{
num++;
x/=i;
}
res.pb(num);
}
if(x!=1) res.pb(1);
return res;
}
int main()
{
IOS
int T=1;
while(T--)
{
ll n;
cin>>n;
if(n==1)
{
cout<<0;
nl;
continue;
}
vector<ll>v=factorize(n);
ll cnt=0;
for(auto a:v)
{
ll temp=a;
ll i=1;
while(i<=temp)
{
temp-=i;
i++;
cnt++;
}
}
cout<<cnt;
nl;
}
return 0;
}
| 0
| 19,274,968
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define MOD 1000000007
int main() {
int n;
cin >> n;
vector<int> a(n);
vector<ll> cnt(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
a[i]--;
cnt[a[i]]++;
}
ll total = 0;
for (int i = 0; i < n; ++i) {
total += cnt[i] * (cnt[i] - 1) / 2;
}
for (int i = 0; i < n; ++i) {
ll ans = total;
ans -= cnt[a[i]] * (cnt[a[i]] - 1) / 2;
ans += max(0ll, (cnt[a[i]] - 1) * (cnt[a[i]] - 2) / 2);
cout << ans << endl;
}
return 0;
}
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MMOD 998244353
#define MAX 2010101
using namespace std;
using Edge=pair<ll,ll>;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
struct UnionFind{
vector<int> par,siz;
UnionFind(int N):par(N),siz(N,1ll){
for(int i=0; i<N; i++) par[i]=i;
}
int root(int x){
if(par[x]==x) return x;
return par[x]=root(par[x]);
}
void unite(int x,int y){
int rx=root(x);
int ry=root(y);
if(rx==ry) return;
if(siz[rx]<siz[ry]) swap(rx,ry);
siz[rx]+=siz[ry];
par[ry]=rx;
}
bool same(int x,int y){
int rx=root(x);
int ry=root(y);
return rx==ry;
}
int size(int x){
return siz[root(x)];
}
};
int main(){
int N,M;
cin>>N>>M;
UnionFind U(N);
REP(i,M){
int A,B;
cin>>A>>B;
A--,B--;
U.unite(A,B);
}
int ans=0;
REP(i,N) chmax(ans,U.size(i));
co(ans);
return 0;
}
| 0
| 36,868,022
|
#include <bits/stdc++.h>
using namespace std;
signed main () {
string s, t;
cin >> s >> t;
int n = s.size();
map < char, char > assigned;
bool fucked = 0;
for (int i = 0; i < n; ++i) {
if (assigned.find(s[i]) == assigned.end())
assigned[s[i]] = t[i];
else if (assigned[s[i]] != t[i])
fucked = 1;
}
assigned.clear();
for (int i = 0; i < n; ++i) {
if (assigned.find(t[i]) == assigned.end())
assigned[t[i]] = s[i];
else if (assigned[t[i]] != s[i])
fucked = 1;
}
if (!fucked)
cout << "Yes\n";
else
cout << "No\n";
}
|
#include <iostream>
#include <string>
using namespace std;
string str;
void change(){
for(char i = 'a' ; i <= 'z' ; i++) str[i] = i;
for(char i = 'A' ; i <= 'Z' ; i++) str[i] = i;
for(char i = '0' ; i <= '9' ; i++) str[i] = i;
}
int main(){
int n;
while(cin >> n,n){
str = "";
change();
char a,b;
for(int i = 0 ; i < n ; i++){
cin >> a >> b;
str[a] = b;
}
string tmp = "";
int m; char c;
cin >> m;
for(int i = 0 ; i < m; i++){
cin >> c;
tmp += str[c];
}
cout << tmp << endl;
}
return 0;
}
| 0
| 50,021,492
|
#include <bits/stdc++.h>
using namespace std;
typedef long lint;
typedef long long llint;
bool compPair(const pair<int, int>& arg1, const pair<int, int>& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }
int main(void) {
int a, b, c;
cin >> a >> b >> c;
vector<int> p;
p.push_back(a);
p.push_back(b);
p.push_back(c);
sort(p.begin(), p.end(), greater<int>());
cout << p.at(0)*10+p.at(1)+p.at(2) << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
#define inputv(v, n) \
vl v; \
rep(i, n) { \
ll x; \
cin >> x; \
v.push_back(x); \
}
bool chmin(ll& a, ll& b) { if (b < a) { a = b; return 1; } return 0; }
bool chmax(ll& a, ll& b) { if (b > a) { a = b; return 1; } return 0; }
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
int main(){
string S,S1;
cin >> n;
r = n - 1;
l = 0;
cout << r << endl;
cin >> S;
if (S[0] == 'V')return 0;
cout << l << endl;
cin >> S;
if (S[0] == 'V')return 0;
S1 = S;
t = 0;
while (1) {
x = (l + r) / 2;
cout << x << endl;
cin >> S;
if (S[0] == 'V')return 0;
if (((x - l) % 2 == 0) ^ (S[0] == S1[0]))r = x;
else{
l = x;
S1=S;
}
}
}
| 0
| 24,361,971
|
#include <iostream>
#include <algorithm>
#define INF 2147483647
#define MAX_N 100001
using namespace std;
int tree[(1<<18)];
int n,q;
void update(int i,int x) {
i+=(n-1);
tree[i] = x;
while(i!=0){
i=(i-1)/2;
tree[i] = min(tree[i*2+1],tree[i*2+2]);
}
}
int find(int a ,int b,int M,int L,int R){
if(R<=a || b<=L) return INF;
if(a<=L && R<=b) return tree[M];
int nx = (R+L)/2;
return min(find(a,b,M*2+1,L,nx),find(a,b,M*2+2,nx,R));
}
int par[MAX_N];
int rank[MAX_N];
void init(int n){
for(int i=0;i<n;i++) par[i]=i, rank[i]=0;
}
int find(int x){
if(par[x] == x) return x;
return par[x] = find(par[x]);
}
void unite(int x,int y){
x = find(x);
y = find(y);
if(x == y) return;
if(rank[x] < rank[y]) par[x] = y;
else {
par[y] = x;
if(rank[x] == rank[y]) rank[x]++;
}
}
bool same(int x,int y){
return find(x) == find(y);
}
int main(){
cin >> n >>q;
init(n);
while(q--){
int com,x,y;
cin >>com >> x >> y;
if(com == 0) unite(x,y);
if(com == 1) cout << same(x,y) <<endl;
}
return 0;
}
|
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
void Main()
{
ll n, K;
cin >> n >> K;
vector<ll> x(n), y(n);
rep(i, n) cin >> x[i] >> y[i];
vector<ll> dict;
rep(i, n) {
dict.push_back(x[i]);
dict.push_back(x[i]-1);
dict.push_back(x[i]+1);
dict.push_back(y[i]);
dict.push_back(y[i]-1);
dict.push_back(y[i]+1);
}
sort(all(dict));
vector<ll> u(n), v(n);
rep(i, n) {
u[i] = lower_bound(all(dict), x[i]) - dict.begin();
v[i] = lower_bound(all(dict), y[i]) - dict.begin();
}
ll m = dict.size();
vector<vector<ll> > S(m, vector<ll>(m));
rep(i, n) {
S[v[i]][u[i]]++;
}
rep(y, m) {
repi(x, m) {
S[y][x] = S[y][x-1] + S[y][x];
}
}
rep(x, m) {
repi(y, m) {
S[y][x] = S[y-1][x] + S[y][x];
}
}
ll res = -1;
auto us = u;
auto vs = v;
sort(all(us));
sort(all(vs));
for (ll i = 0; i < n - 1; i++) {
for (ll j = i + 1; j < n; j++) {
for (ll iy = 0; iy < n - 1; iy++) {
for (ll jy = iy + 1; jy < n; jy++) {
ll l = us[i];
ll r = us[j];
ll b = vs[iy];
ll t = vs[jy];
ll cnt = S[t][r] - S[b-1][r] - S[t][l-1] + S[b-1][l-1];
if (cnt >= K) {
ll L = dict[l];
ll R = dict[r];
ll B = dict[b];
ll T = dict[t];
ll area = (R - L) * (T - B);
if (res < 0) {
res = area;
}
else {
res = min(area, res);
}
}
}
}
}
}
put(res);
}
signed main(){ Main();return 0;}
| 0
| 19,146,515
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int n, m, k; cin >> n >> m >> k;
for (int i = 0; i <= n; i++) for (int j = 0; j <= m; j++) {
if (i * m + j * n - 2 * i * j == k) {
cout << "Yes\n";
return 0;
}
}
cout << "No\n";
return 0;
}
|
#include <iostream>
#include <string>
using namespace std;
int main(){
int t;
cin >> t;
int p1=0,p2=0;
for (int i=0;i<t;i++){
string s1,s2;
cin >> s1 >> s2;
if (s1>s2)
p1+=3;
else if (s1<s2)
p2+=3;
else {
p1+=1;
p2+=1;
}
}
cout << p1 << ' ' << p2 << endl;
return 0;
}
| 0
| 52,616,002
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[100],b[100],ra[100];
int kt(int a[],int n){
int ret=0;
for(int i=1;i<=n;i++){
int cnt=0;
for(int j=i+1;j<=n;j++){
if(a[j]<a[i]) cnt++;
}
ret+=cnt*ra[n-i];
}
return ret;
}
void init(int n){
ra[0]=1;
for(int i=1;i<=n;i++) ra[i]=i*ra[i-1];
}
int main()
{
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n;
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i];
for(int i=1;i<=n;i++) cin>>b[i];
init(30);
int num1=kt(a,n);
int num2=kt(b,n);
cout<<abs(num1-num2)<<'\n';
return 0;
}
|
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#include <iomanip>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int mx2[] = {1,0};
int my2[] = {0,1};
class AHaiku {
public:
void solve(istream& in, ostream& out) {
string s; in >> s;
rep(i,5) out << s[i];
out << " ";
for(int i = 6; i < 13; i++) out << s[i];
out << " ";
for(int i = 14; i < 19; i++) out << s[i];
out << endl;
}
};
int main() {
AHaiku solver;
std::istream& in(std::cin);
std::ostream& out(std::cout);
solver.solve(in, out);
return 0;
}
| 0
| 77,746,101
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using V = vector<ll>;
#define _GLIBCXX_DEBUG
#define rep(i, a) for(int i = 0; i < a; i++)
#define ALL(v) v.begin(), v.end()
int main(){
int a,b,c; cin>>a>>b>>c;
if(a+b>=c) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;
int main()
{
string s;
vector<int> v(26, 0);
cin >> s;
rep(i, s.size())
{
v[s[i] - 'a']++;
}
rep(i, v.size())
{
if (v[i] > 1)
{
cout << "no" << endl;
return (0);
}
}
cout << "yes" << endl;
return (0);
}
| 0
| 78,872,063
|
#include<iostream>
#include<string>
using namespace std;
int main(void){
int count = 0;
string s, keyence = "keyence";
cin >> s;
int len = s.size();
int i = 0;
while(s[i] == keyence[i++]){
count++;
if(count == 7){
cout << "YES" << endl;
return 0;
}
}
i = 0;
while(s[len-1-i] == keyence[6-i]){
i++;
count++;
if(count == 7){
cout << "YES" << endl;
return 0;
}
}
cout << "NO" << endl;
return 0;
}
|
#include<iostream>
#include<string>
using namespace std;
struct Node{
int key;
Node* prev;
Node* next;
};
class List{
Node* nil;
void delete_node(Node* n){
n->prev->next = n->next;
n->next->prev = n->prev;
delete n;
}
public:
List(){
nil = new Node;
nil->prev = nil;
nil->next = nil;
}
void insert_key(int key){
Node* n = new Node;
n->key = key;
nil->next->prev = n;
n->next = nil->next;
nil->next = n;
n->prev = nil;
}
void delete_key(int key){
for (Node* n = nil->next; n != nil; n = n->next) {
if (n->key == key) {
delete_node(n);
return;
}
}
}
void print_all(){
for (Node* n = nil->next; n != nil; n = n->next) {
if (n != nil->next) cout << " ";
cout << n->key;
}
cout << endl;
}
void deleteFirst(){
delete_node(nil->next);
}
void deleteLast(){
delete_node(nil->prev);
}
};
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
List l;
for (int i = 0; i < n; i++) {
string command;
cin >> command;
if (command == "deleteFirst") {
l.deleteFirst();
continue;
}
if (command == "deleteLast") {
l.deleteLast();
continue;
}
int key;
cin >> key;
if (command == "insert") {
l.insert_key(key);
continue;
}
if (command == "delete") {
l.delete_key(key);
continue;
}
}
l.print_all();
return 0;
}
| 0
| 83,232,629
|
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0
using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>a
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll a, ll b) {
if (b == 0) return a;
else return gcd(b, a % b);
}
ll keta(ll n){
string s = to_string(n);
ll num = s.size();
return num;
}
const ll INF = 1LL << 60;
const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};
struct Edge{
int to;
int weight;
Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;
class UnionFind{
public:
vi Parent;
UnionFind(int n){
Parent = vi(n,-1);
}
int root(int a){
if(Parent[a] < 0) return a;
return Parent[a] = root(Parent[a]);
}
int size(int a){
a = root(a);
return -Parent[a];
}
bool merge(int a, int b){
a = root(a);
b = root(b);
if(a == b) return false;
if(a < b) swap(a,b);
Parent[a] += Parent[b];
Parent[b] = a;
return true;
}
bool issame(int a, int b){
return root(a) == root(b);
}
};
int main(){
int n; cin >> n;
vi a(n); rep(i,n) cin >> a[i];
int color = 1e5;
int ans = 0;
rep(i,n-1) {
if(a[i] == a[i+1]){
a[i+1] = color--;
ans++;
}
}
cout << ans << endl;
}
|
#include<iostream>
using namespace std;
int main(void){
while(1){
int a;
int n;
int c=0;
cin>>a;
if(a==0)break;
int count=0;
for(n=1000-a;n!=0;c++){
if(n>=500)n-=500;
else if(n>=100)n-=100;
else if(n>=50)n-=50;
else if(n>=10)n-=10;
else if(n>=5)n-=5;
else if(n>=1)n-=1;
}
cout << c << endl;
}
return 0;
}
| 0
| 66,415,109
|
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
const int INFint = 2e9+1;
const ll INFll = 2e18+1;
ll MOD=1e9+7;
int main(){
int N;
cin>>N;
vector<int> A(N+1);
for(int i(1);i<=N;i++){
cin>>A[i];
}
vector<bool> used(N+1,0);
int cnt(0);
for(int i(1);i<=N;i++){
if(used[i] == false){
if(A[A[i]] == i){
cnt++;
used[i] = true;
used[A[i]] = true;
}
}
}
cout << cnt << endl;
return 0;
}
|
#include <bits/stdc++.h>
const std::int64_t INF = 1e18;
int main() {
std::int32_t N; std::cin >> N;
std::vector<std::int64_t> A(N + 1), B(N + 1);
for (std::int32_t i = 0; i <= N; ++i) {
std::cin >> A[i];
}
B[N] = A[N];
for (std::int32_t i = N - 1; i >= 0; --i) {
B[i] = B[i + 1] + A[i];
}
B[0] = 1;
for (std::int32_t i = 1; i <= N; ++i) {
B[i] = std::min(B[i], 2 * (B[i - 1] - A[i - 1]));
}
std::int64_t ans = 0;
for (std::int32_t i = 0; i <= N; ++i) {
if (B[i] < A[i]) {
std::cout << -1 << std::endl;
return 0;
}
ans += B[i];
}
std::cout << ans << std::endl;
return 0;
}
| 0
| 63,508,926
|
#include <bits/stdc++.h>
using namespace std;
const int INF=999999999;
int main() {
string S;
cin>>S;
bool ok =true;
if(S[0]!='A'){ok=false;}
int count1=0;
for(int i=2;i<S.size()-1;i++){
if(S[i]=='C'){count1++;}
}
if(count1!=1){ok=false;}
int count2=0;
for(int i=0;i<S.size();i++){
if(S[i]>='A'&&S[i]<='Z'){count2++;}
}
if(count2!=2){ok=false;}
if(ok){cout<<"AC"<<endl;}
else{cout<<"WA"<<endl;}
return 0;}
|
#include <iostream>
using namespace std;
int main() {
int A, B;
cin >> A >> B;
if(A==1 || B==1) {
if(A==1 && B!=1) {
cout << "Alice" << endl;
} else if(A!=1 && B==1) {
cout << "Bob" << endl;
} else {
cout << "Draw" << endl;
}
} else {
if(A>B) {
cout << "Alice" << endl;
} else if(A<B) {
cout << "Bob" << endl;
} else {
cout << "Draw" << endl;
}
}
return 0;
}
| 0
| 80,253,155
|
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
int main()
{
int N, M;
cin >> N;
map<string, int> m;
for (int i = 0; i < N; i++)
{
string s;
cin >> s;
m[s]++;
}
cin >> M;
for (int i = 0; i < M; i++)
{
string s;
cin >> s;
m[s]--;
}
int max = 1 << 31;
for (auto i = m.begin(); i != m.end(); i++)
{
max = std::max(max, i->second);
}
if (max < 0)
{
max = 0;
}
cout << max << endl;
return 0;
}
|
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
#define setbits(x) __builtin_popcountll(x)
#define mod 1000000007
#define ps(x,y) fixed<<setprecision(y)<<x
#define w(x) int x; cin>>x; while(x--)
#define INF (int)1e9 + (int)1e8
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
void cpp(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
ll dp[101][100004];
int main(){
cpp();
ll n, k;
cin>>n>>k;
vector<ll> v(n);
for(ll i=0; i<n; i++){
cin>>v[i];
}
dp[0][0] = 1;
for(ll i=1; i<=n; i++){
for(ll j=0; j<=k; j++){
if(j==0){
dp[i][j] = dp[i-1][j];
dp[i][j]%=mod;
continue;
}
dp[i][j] = dp[i][j-1]+dp[i-1][j]-((j-1-v[i-1]>=0)?dp[i-1][j-1-v[i-1]]:0);
dp[i][j]%=mod;
dp[i][j]=(dp[i][j]+mod)%mod;
}
}
cout<<dp[n][k]<<endl;
return 0;
}
| 0
| 83,108,054
|
#include <iostream>
#include <string>
using namespace std;
int main() {
string s, t;
cin >> s >> t;
int p = -1;
for (int i = 0; i < int(s.size()) - int(t.size()) + 1; ++i) {
int cnt = 0;
for (int j = 0; j < int(t.size()); ++j)
cnt += s[i+j] == '?' || s[i+j] == t[j];
if (cnt == int(t.size()))
p = i;
}
if (p == -1) {
cout << "UNRESTORABLE" << endl;
} else {
for (int i = 0; i < p; ++i)
cout << (s[i] == '?' ? 'a' : s[i]);
cout << t;
for (int i = p + int(t.size()); i < int(s.size()); ++i)
cout << (s[i] == '?' ? 'a' : s[i]);
cout << endl;
}
}
|
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define show(x) cout << #x << " = " << x << endl;
#define print(x) cout << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T> >
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
ll d[210][210];
int main() {
int n, m, r;
cin >> n >> m >> r;
vi R(r);
rep(i, r) {
cin >> R[i];
R[i]--;
}
rep(i, n) {
rep(j, n) {
if (i == j)
d[i][j] = 0;
else
d[i][j] = 1LL << 60;
}
}
rep(i, m) {
int a, b;
ll c;
cin >> a >> b >> c;
a--;
b--;
d[a][b] = c;
d[b][a] = c;
}
rep(k, n) {
rep(i, n) {
rep(j, n) { d[i][j] = min(d[i][j], d[i][k] + d[k][j]); }
}
}
ll ans = 1LL << 60;
sort(rng(R));
do {
ll cost = 0;
rep(i, r - 1) { cost += d[R[i]][R[i + 1]]; }
mins(ans, cost);
} while (next_permutation(R.begin(), R.end()));
cout << ans << endl;
return 0;
}
| 0
| 90,911,713
|
#include"bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using ll = long long;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
int main() {
int n, h, w, a, b;
int cnt = 0;
int ac, bc;
cin >> n >> h >> w;
rep(i, n) {
cin >> a >> b;
ac = a / h;
bc = b / w;
cnt += min(ac, bc);
}
cout << cnt << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define ll long long
#define pq priority_queue
using namespace std;
const ll INF=(ll)1e9;
const ll MOD=(ll)1e9+7;
const ll MAX=510000;
vector<int> dx={1,0,-1,0,1,-1,1,-1},dy={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; }
int main(){
ll H,W,ans;
cin>>H>>W;
if(H%3==0||W%3==0){
cout<<"0"<<endl;
return 0;
}
ans=min(H,W);
for(ll i=1;i<H;i++){
ll a,b,c,M,m;
a=W/2*i;
b=(W-W/2)*i;
c=W*(H-i);
M=max(a,max(b,c));
m=min(a,min(b,c));
ans=min(ans,M-m);
}
for(ll i=1;i<W;i++){
ll a,b,c,M,m;
a=H/2*i;
b=(H-H/2)*i;
c=H*(W-i);
M=max(a,max(b,c));
m=min(a,min(b,c));
ans=min(ans,M-m);
}
cout<<ans<<endl;
}
| 0
| 24,100,833
|
#include<iostream>
#include<cstdio>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include <string>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include<bits/stdc++.h>
#include <set>
#define ll long long
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define inf 0x3f3f3f
#define pi 3.1415926535898
using namespace std;
const int N=2e5+10;
struct A
{
ll to,next,w;
} a[2*N];
ll head[2*N];
ll res[2*N];
ll r[2*N];
ll vis[2*N];
ll n,m;
ll tot;
void add(int u,int v)
{
tot++;
a[tot].to=v;
a[tot].next=head[u];
head[u]=tot;
}
void bfs()
{
queue<ll> q;
q.push(1);
while(!q.empty())
{
int x=q.front();
q.pop();
vis[x]=1;
for(int i=head[x];i!=-1; i=a[i].next)
{
ll y=a[i].to;
if(!vis[y])
{
res[y]+=res[x];
q.push(y);
}
}
}
}
int main()
{
memset(head,-1,sizeof(head));
cin>>n>>m;
int a,b;
for(int i=0;i<n-1;i++)
{
cin>>a>>b;
add(a,b);
add(b,a);
}
for(int i=0;i<m;i++)
{
cin>>a>>b;
res[a]+=b;
}
bfs();
for(int i=1;i<=n;i++)
{
cout<<res[i]<<" ";
}
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define repr(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
const int IINF = 1e9 + 100;
const long long LLINF = 2e18 + 129;
const long long MOD = 1e9 + 7;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
vector<lint> x(n), y(m);
rep(i, n){
cin >> x[i];
}
rep(i, m){
cin >> y[i];
}
vector<lint> xsum(n + 1), ysum(m + 1);
REP(i, 1, n + 1){
xsum[i] = x[i - 1] + xsum[i - 1];
}
REP(i, 1, m + 1){
ysum[i] = y[i - 1] + ysum[i - 1];
}
lint dxsum = 0, dysum = 0;
REP(i, 1, n){
dxsum += x[i] * i - xsum[i];
dxsum %= MOD;
}
REP(i, 1, m){
dysum += y[i] * i - ysum[i];
dysum %= MOD;
}
lint ans = (dxsum * dysum) % MOD;
cout << ans << endl;
return 0;
}
| 0
| 100,795,038
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
ll N,K;
cin >> N >> K;
ll A[N];
ll gcd = A[0];
ll m = -1;
for (int i = 0; i < N; i++) {
cin >> A[i];
m = max(A[i],m);
}
for (int i = 1; i < N; i++) {
gcd = __gcd(gcd,A[i]);
}
if (m >= K && (K - m) % gcd == 0) {
cout << "POSSIBLE" << endl;
} else {
cout << "IMPOSSIBLE" << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
using ll = long long;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
ll dp[1005][10005];
int main() {
ll H,N;
cin>>H>>N;
vector<vector<ll>> v(N,vector<ll>(2));
rep(i,N) cin>>v[i][0]>>v[i][1];
rep(i,10005){
dp[0][i]=((i-1)/v[0][0]+1)*v[0][1];
}
rep(i,1005) dp[i][0] = 0;
for(int i = 1; i < N; i++){
for(int j = 1; j <= H; j++){
if(j>v[i][0]) dp[i][j]=min(dp[i-1][j],dp[i][j-v[i][0]]+v[i][1]);
else dp[i][j] = min(dp[i-1][j],v[i][1]);
}
}
cout<<dp[N-1][H]<<endl;
}
| 0
| 24,627,155
|
#include <bits/stdc++.h>
#define uint uint64_t
#define mx 100001
#define ll long long int
#define ull unsigned long long int
#define pii pair<int, int>
#define pll pair<long long int, long long int>
#define mp make_pair
#define pb push_back
#define inf INT_MAX
#define pi acos(-1)
#define eps 1e-8
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * b) / __gcd(a, b)
#define input(ara, n) \
for (int i = 0; i < n; i++) \
scanf("%d", &ara[i])
#define inputl(ara, n) \
for (long long int i = 0; i < n; i++) \
scanf("%lld", &ara[i])
#define pf(a) printf("%d\n", a);
#define pfl(a) printf("%lld\n", a);
#define pfi(a) printf("%d ", a);
#define pfll(a) printf("%lld ", a);
#define sc(a) scanf("%d", &a)
#define scc(a, b) scanf("%d %d", &a, &b)
#define sccdbl(a, b) scanf("%lf %lf", &a, &b)
#define sccc(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define scccdbl(a, b, c) scanf("%lf %lf %lf", &a, &b, &c)
#define scl(a) scanf("%lld", &a)
#define sccl(a, b) scanf("%lld %lld", &a, &b)
#define scccl(a, b, c) scanf("%lld %lld %lld", &a, &b, &c)
using namespace std;
int main()
{
int n,count=0;
sc(n);
string str;
cin>>str;
char a=str[0];
for(int i=1;i<n;i++){
if(str[i]!=a){
count++;
a=str[i];
}
}
count++;
pf(count);
return 0;
}
|
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair<ll, ll>
#define vi vector<ll>
#define vii vector<pii>
#define mi map<ll, ll>
#define mii map<pii, ll>
#define all(a) (a).begin(),(a).end()
#define x first
#define y second
#define sz(x) (int)x.size()
#define endl '\n'
#define hell 1000000007
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rev(i,a,b) for(int i=a;i>=b;i--)
#define lb lower_bound
#define ub upper_bound
#define bg(i) i.begin()
#define fset(it,s) for(auto it = s.begin(); it != s.end(); it++)
#define track(x) cerr<<#x<<": "<<x<<endl
#define track2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define track3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define track4(a, b, c, d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define ed(i) i.end()
#define mem(a) memset(a, 0, sizeof(a))
#define MOD 1000000007
ll mult(ll a,ll b, ll p=MOD){return ((a%p)*(b%p))%p;}
ll add(ll a, ll b, ll p=MOD){return (a + b + p)%p;}
ll fpow(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1LL) {if (k & 1LL) r = mult(r,n,p); n = mult(n,n,p);} return r;}
ll inv(ll a, ll p = MOD) {return fpow(a, p - 2, p);}
void self_max(int &a, int b) {a = max(a, b); }
void self_min(int &a, int b) {a = min(a, b); }
void self_add(int &a, int b, int p = MOD) { a += b; if(a >= p) a -= p;}
void self_sub(int &a, int b, int p = MOD) { a -= b; if(a < 0) a += p;}
const int INF = 1e9 + 5;
#define N 400001
void solve(){
ll n, m;
cin>>n>>m;
vector<pair<ll, ll> > v;
rep(i, 0, n) {
int a, b;
cin>>a>>b;
v.pb(mp(a, b));
}
sort(all(v));
ll amount = 0;
rep(i, 0, n) {
ll curr = min((ll)v[i].y, (ll)m);
amount += v[i].x * curr;
m = m - curr;
}
cout<<amount<<endl;
}
int main() {
ios::sync_with_stdio(false);
cout<<fixed<<setprecision(20);
cin.tie(0);
cout.tie(0);
int t = 1;
while(t--){
solve();
}
}
| 0
| 1,152,575
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){
while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={1,0,-1,0,1,-1,-1,1};
int dy[]={0,1,0,-1,1,1,-1,-1};
const int MOD = 1e9+7;
const long long INF = 1e18+10;
signed main(){
int a,b,k;
cin>>a>>b>>k;
if(k<=a){
cout<<a-k<<' '<<b<<endl;
}else{
cout<<0<<' '<<max(0ll,a+b-k)<<endl;
}
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define fo(i,a,n) for(i=a;i<n;i++)
#define ll long long
#define deb(x) cout << #x << "=" << x << endl
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define sortrev(x) sort(all(x),greater<int>())
#define pi 3.1415926535897932384626
typedef pair<int,int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<double> vd;
const int mod = 1000000007;
const int inf = 1000000000;
const int N = 200007, M = N;
ll i,j,cnt,par,n;
void solve() {
ll n;
cin>>n;
vi vec(n) , temp(n);
for(int i=0;i<n;i++) cin>>vec[i];
temp[0] = vec[0];
for(int i=1;i<n;i++) temp[i] = max(temp[i-1] , vec[i]);
ll ans = 0;
for(int i=n-1;i>=0;i--) {
ans+=abs(temp[i] - vec[i]);
}
cout<<ans<<"\n";
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t = 1;
while(t--) {
solve();
}
return 0;
}
| 0
| 5,239,286
|
#include <iostream>
using namespace std;
int h, w, d;
char c[500][500], a[2][2]={{'R', 'Y'}, {'G', 'B'}};
void f(int y, int x, char z){
for(int i=0;i<d;i++){
int s=i;
if(i>=d/2)s=d-i-1;
for(int j=-s;j<=s;j++){
int ny=y+j, nx=x+i;
if(ny>=0&&ny<h&&nx>=0&&nx<w){
c[ny][nx]=z;
}
}
}
}
int main(void){
cin>>h>>w>>d;
if(d%2==1){
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
cout<<a[(i+j)%2][0];
}
cout<<endl;
}
return 0;
}
for(int k=0;k<2;k++){
for(int i=-d;i<=h+d;i+=d){
for(int j=-d;j<=w+d;j+=d){
f(i+k*d/2, j+k*d/2, a[k][((i+d)/d+(j+d)/d)%2]);
}
}
}
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
cout<<c[i][j];
}
cout<<endl;
}
}
|
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
struct Node
{
int value;
Node* prev,* next;
};
Node* head;
void Init()
{
head=(Node*)malloc(sizeof(Node));
head->next=head;
head->prev=head;
}
Node* FindNode(int x)
{
Node*temp=head->next;
while(temp!=head&&temp->value!=x)
temp=temp->next;
return temp;
}
void Insert(int x)
{
Node*temp=(Node*)malloc(sizeof(Node));
temp->value=x;
head->next->prev=temp;
temp->next=head->next;
head->next=temp;
temp->prev=head;
}
void Delete(Node*temp)
{
if(temp==head)
return ;
temp->next->prev=temp->prev;
temp->prev->next=temp->next;
free(temp);
}
void DeleteFirst()
{
Delete(head->next);
}
void DeleteLast()
{
Delete(head->prev);
}
int main()
{
int n;
int i;
scanf("%d",&n);
char str[12];
int x;
Init();
while(n--)
{
scanf("%s%d",str,&x);
if(str[0]=='i'){Insert(x);}
else if(str[0]=='d'&&str[6]=='F')DeleteFirst();
else if(str[0]=='d'&&str[6]=='L')DeleteLast();
else if(str[0]=='d'){Delete(FindNode(x));}
}
Node* temp=head->next;
while(temp->next!=head)
{
printf("%d ",temp->value);
temp=temp->next;
}
printf("%d\n",temp->value);
return 0;
}
| 0
| 69,376,704
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
int main(){
int N;
cin >> N;
vec<int> T(N+2),V(N+2),S(N+3);
int tsum = 0;
for(int i=1;i<=N;i++){
cin >> T[i];
T[i] *= 2;
tsum += T[i];
S[i+1] = S[i]+T[i];
}
for(int i=1;i<=N;i++) cin >> V[i];
T[0] = 0,V[0] = 0;
T[N+1] = tsum,V[N+1] = 0;
S[N+2] = S[N+1];
vec<double> mi(tsum+1,2e9);
for(int i=0;i<=N+1;i++){
int l = S[i],r = S[i+1];
auto f = [&](int t)->double{
if(l<=t && t<=r) return V[i];
if(t<l) return -0.5*(t-l)+V[i];
else return 0.5*(t-r)+V[i];
};
for(int j=0;j<=tsum;j++) mi[j] = min(mi[j],max(0.0,f(j)));
}
double ans = 0;
for(int j=0;j<tsum;j++){
ans += (mi[j]+mi[j+1])*0.25;
}
cout << fixed << setprecision(10) << ans << "\n";
}
|
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
const double EPS = 1e-10;
const double PI = acos(-1.0);
int main(){
cin.tie(0);
ios_base::sync_with_stdio(false);
int N; cin >> N;
VI A(N);
REP(i,N) cin >> A[i];
int ans = 0;
REP(i,N){
int minj = i;
FOR(j,i,N)
if(A[j] < A[minj])
minj = j;
if(i != minj) ++ans;
swap(A[i], A[minj]);
}
cout << A[0];
REP(i,N-1) cout << " " << A[i+1];
cout << endl;
cout << ans << endl;
return 0;
}
| 0
| 46,366,127
|
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
#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--)
int main(){
int ai,am,as,ae,bi,bm,bs,be;
scanf("%d%d%d%d%d%d%d%d",&ai,&am,&as,&ae,&bi,&bm,&bs,&be);
int S = ai + am + as + ae;
int T = bi + bm + bs + be;
printf("%d\n",S > T ? S : T);
return 0;
}
|
#include <stdio.h>
int main() {
char a[10];
scanf("%s", &a);
(a[2] == a[3] && a[4] == a[5]) ? puts("Yes") : puts("No");
return 0;
}
| 0
| 63,257,514
|
#include <bits/stdc++.h>
#define slld(longvalue) scanf("%lld", &longvalue)
#define ll long long
#define ull unsigned long long
#define pll pair < long long, long long >
#define fastio ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define pb push_back
#define bug printf("BUG\n")
#define mxlld LLONG_MAX
#define mnlld -LLONG_MAX
#define mxd 2e8
#define mnd -2e8
#define pi 3.14159265359
using namespace std;
bool check(ll n, ll pos)
{
return n & (1LL << pos);
}
ll Set(ll n, ll pos)
{
return n = n | (1LL << pos);
}
int main()
{
ll i, j, k, l, m, n, o, r, q;
ll testcase;
ll input, flag, tag, ans;
while(cin >> k)
{
ans = 1;
for(ll i = 1; i <= 10000000; i++)
{
if((i * k) % 360 == 0)
{
ans = i;
break;
}
}
cout << ans << "\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const long long mod = 1000000007LL;
int main() {
int n, k;
cin >> n >> k;
deque<int> deq;
rep(i,n) {
int v;
cin >> v;
deq.push_back(v);
}
int ans = 0;
for(int i = 0; i<=k; i++) {
for(int j = 0; j<=k-i; j++) {
deque<int> d = deq;
vi have;
rep(m,i) {
if(!d.empty()) {
have.push_back(d.front());
d.pop_front();
}
}
rep(l,j) {
if(!d.empty()) {
have.push_back(d.back());
d.pop_back();
}
}
sort(have.begin(),have.end());
int tmp = 0;
rep(m,have.size()) tmp += have[m];
rep(m,k-i-j) {
if(m<have.size() && have[m]<0) tmp -= have[m];
}
ans = max(ans,tmp);
}
}
cout << ans << endl;
return 0;
}
| 0
| 41,575,059
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
int total = 0;
for (int i = 0; i < N; i++) {
int r, l;
cin >> r >> l;
int part = l - r + 1;
total += part;
}
cout << total << endl;
}
|
#include<iostream>
int main(){
int a=0,i,b;
for(i=1;i<10;i++){
a=a+1;
for(b=1;b<10;b++){
std::cout<<a<<"x"<<b<<"=";
std::cout<<a*b<<std::endl;
}
}
return 0;
}
| 0
| 84,454,622
|
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
cin >> N;
vector<int64_t> data2(N);
vector<int64_t> data1(N);
for(int i=0; i<N; i++){
cin >> data2.at(i);
}
for(int i=0; i<N; i++){
cin >> data1.at(i);
}
int64_t sum2= 0;
int64_t sum1= 0;
int64_t cnt2= 0;
int64_t cnt1= 0;
for(int i=0; i<N; i++){
sum2+= data2.at(i);
sum1+= data1.at(i);
int64_t diff= data1.at(i)- data2.at(i);
if(diff < 0){
cnt1+= -diff;
}
else if(diff % 2==0){
cnt2+= diff/2;
}
else{
cnt2+= (diff+1)/ 2;
cnt1++;
}
}
int64_t Nop= sum1- sum2;
string ans= (cnt1 <= Nop && cnt2 <= Nop) ? "Yes"
: "No";
cout << ans << endl;
}
|
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstring>
using namespace std;
const int N_MAX = 200005;
int counter[N_MAX];
int plusc[N_MAX];
vector<int> root[N_MAX];
void dfs(int n, int p, int num){
int nownum = num + plusc[n];
counter[n] = nownum;
for(auto u: root[n]){
if (u == p)continue;
dfs(u, n, nownum);
}
}
int main(){
int n, q;
cin >> n >> q;
for(int i = 0; i < n-1; i++){
int a, b;
cin >> a >> b;
root[a].push_back(b);
root[b].push_back(a);
}
memset(plusc, 0, sizeof(plusc));
for(int i = 0; i < q; i++){
int p, x;
cin >> p >> x;
plusc[p] += x;
}
dfs(1, -1, 0);
for(int i = 1; i <= n; i++){
cout << counter[i];
if (i != n)cout << " ";
}
return 0;
}
| 0
| 53,968,018
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
if (s.size() == 2) {
if (s.at(0) == s.at(1)) {
cout << 1 << " " << 2 << endl;
return 0;
}
else
{
cout << -1 << " " << -1 << endl;
return 0;
}
}
else {
for (int i = 0; i < s.size() - 1; i++) {
if(s.at(i) == s.at(i + 1)) {
cout << i + 1 << " " << i + 2 << endl;
return 0;
}
else if (i < s.size() - 2 && s.at(i) == s.at(i + 2)) {
cout << i + 1 << " " << i + 3 << endl;
return 0;
}
}
}
cout << -1 << " " << -1 << endl;
}
|
#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 CIN(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 COUT(...) 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;
template <typename X, typename M>
struct SegTreeLazyProportional {
using FX = function<X(X, X)>;
using FA = function<X(X, M)>;
using FM = function<M(M, M)>;
using FP = function<M(M, int)>;
int n;
FX fx;
FA fa;
FM fm;
FP fp;
const X ex;
const M em;
vector<X> dat;
vector<M> lazy;
SegTreeLazyProportional(int n_, FX fx_, FA fa_, FM fm_, FP fp_, X ex_, M em_)
: n(), fx(fx_), fa(fa_), fm(fm_), fp(fp_), ex(ex_), em(em_), dat(n_ * 4, ex), lazy(n_ * 4, em) {
int x = 1;
while (n_ > x) x *= 2;
n = x;
}
void set(int i, X x) { dat[i + n - 1] = x; }
void build() {
for (int k = n - 2; k >= 0; k--) dat[k] = fx(dat[2 * k + 1], dat[2 * k + 2]);
}
void eval(int k, int len) {
if (lazy[k] == em) return;
if (k < n - 1) {
lazy[k * 2 + 1] = fm(lazy[k * 2 + 1], lazy[k]);
lazy[k * 2 + 2] = fm(lazy[k * 2 + 2], lazy[k]);
}
dat[k] = fa(dat[k], fp(lazy[k], len));
lazy[k] = em;
}
void update(int a, int b, M x, int k, int l, int r) {
eval(k, r - l);
if (a <= l && r <= b) {
lazy[k] = fm(lazy[k], x);
eval(k, r - l);
} else if (a < r && l < b) {
update(a, b, x, k * 2 + 1, l, (l + r) / 2);
update(a, b, x, k * 2 + 2, (l + r) / 2, r);
dat[k] = fx(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
void update(int a, int b, M x) { update(a, b, x, 0, 0, n); }
X query_sub(int a, int b, int k, int l, int r) {
eval(k, r - l);
if (r <= a || b <= l) {
return ex;
} else if (a <= l && r <= b) {
return dat[k];
} else {
X vl = query_sub(a, b, k * 2 + 1, l, (l + r) / 2);
X vr = query_sub(a, b, k * 2 + 2, (l + r) / 2, r);
return fx(vl, vr);
}
}
X query(int a, int b) { return query_sub(a, b, 0, 0, n); }
};
struct Monster {
ll X, H;
bool operator<(const Monster& m) const {
return X < m.X;
}
};
Monster monster[200000];
int main() {
CIN(ll, N, D, A);
REP(i, N) cin >> monster[i].X >> monster[i].H;
sort(monster, monster + N);
auto add = [](ll a, ll b) -> ll { return a + b; };
auto mul = [](ll a, int size) -> ll { return a * size; };
SegTreeLazyProportional<ll, ll> tree(N, add, add, add, mul, 0, 0);
REP(i, N) tree.set(i, monster[i].H);
ll ans = 0;
int mi = 0;
while (mi < N) {
int h = tree.query(mi, mi + 1);
if (h <= 0) {
++mi;
continue;
}
Monster max_m = {monster[mi].X + D * 2, 0};
int ub = upper_bound(monster, monster + N, max_m) - monster;
ll cnt = (h + A - 1) / A;
tree.update(mi, ub, -cnt * A);
ans += cnt;
}
COUT(ans);
}
| 0
| 38,568,940
|
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
int main(void)
{
IOS
int n, x, y;
cin >> n >> x >> y;
vector<int> v(n);
REP(i,n) cin >> v[i];
if (n == 1) {
x = v.back();
} else {
if (abs(v[n-2] -v [n-1]) >= abs(v[n-1] - y)) {
x = v[n-2]; y = v[n-1];
} else {
x = v[n-1];
}
}
cout << abs(x - y) << endl;
return 0;
}
|
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <numeric>
#include <string>
#include <complex>
#include <algorithm>
#include <iostream>
#include <vector>
#include <bitset>
#include <deque>
#include <queue>
#include <map>
#include <utility>
#include <functional>
#include <iomanip>
#include <unordered_map>
#include <set>
using namespace std;
using ull = unsigned long long;
using ll = long long;
using prll = pair<ll, ll>;
constexpr ll MOD = 1000000007;
constexpr ll mINF = -922337200085470000;
constexpr ll pINF = 1LL << 60;
constexpr ull uINF = 1844674407399900000;
constexpr double pi = 3.1415926535897932384;
constexpr ll juu = 100000;
constexpr ll hyaku = 1000000;
constexpr ll dx[4] = {0, 0, 1, -1};
constexpr ll dy[4] = {1, -1, 0, 0};
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define Debug(xx) cerr << " DEBUG:"<< xx <<endl;
ll factor[300];
ll memory[300];
void primefac(ll num)
{
int i = 0, kosuu = 0;
while (*(factor + i) != 0)
{
while (num % *(factor + i) == 0)
{
num /= *(factor + i);
memory[*(factor + i)] += 1;
}
if (num == 1)
break;
i++;
}
}
int elast(ll number)
{
ll tmp = 0;
int flag = 0;
*factor = 2;
for (int i = 3; i <= number; i++)
{
flag = 0;
for (int j = 0; j <= tmp; j++)
{
if (i % (*(factor + j)) == 0)
{
flag = 1;
break;
}
}
if (flag)
continue;
tmp += 1;
*(factor + tmp) = i;
}
return tmp + 2;
}
ll powpow(ll n, ll p)
{
if (p == 1)
return n % MOD;
if (p % 2 == 1)
{
return (n * powpow(n, p - 1)) % MOD;
}
ll dob = powpow(n, p / 2);
return (dob * dob) % MOD;
}
ll nCrMod(ll n, ll r)
{
ll child = 1;
ll parent = 1;
if (r == 0)
return 1;
for (ll i = 0; i < r; ++i)
{
child = child * (n - i) % MOD;
parent = parent * (r - i) % MOD;
}
ll ans = child * powpow(parent, MOD - 2);
return ans % MOD;
}
ll nCr(ll n, ll r)
{
ll val = 1;
ll i;
if (r == 0)
return 1;
for (i = 0; i < r; ++i)
{
val *= (n - i);
val /= (r - i);
}
return val;
}
ll nPr(ll n, ll r)
{
ll val = 1;
ll i;
for (i = 0; i < r; ++i)
{
val *= (n - i);
}
return val;
}
template <typename T>
bool chmin(T &a, const T b)
{
if (a > b)
{
a = b;
return true;
}
return false;
}
template <typename T>
bool chmax(T &a, const T b)
{
if (a < b)
{
a = b;
return true;
}
return false;
}
template <typename T>
void eraseSame(T &a)
{
sort(all(a));
a.erase(unique(all(a)), a.end());
}
template <typename T>
bool swapmax(T &a, T &b)
{
T temp;
temp = a;
if (a > b)
{
a = b;
b = temp;
return false;
}
return true;
}
ll gcd(ll x, ll y) { return (x % y) ? gcd(y, x % y) : y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
template <typename T>
void splitIn(ll N, vector<T> &array)
{
T temp;
int i = 0;
if (N == 0)
{
return;
}
array.resize(N);
while (cin >> temp)
{
array[i] = temp;
i++;
if (i >= N)
{
break;
}
}
return;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
ll n, k, m, l=0,
ans = 0,
sum = 0;
ll a= 0,b=0,c=0;
vector<double> v;
cin >> n >>m >> l;
splitIn(n,v);
sort(all(v));
for(auto &o:v){
if(o <=m)a++;
else if(o >= m+1 && o <= l)b++;
else c++;
}
cout << min(a,min(b,c));
return 0;
}
| 0
| 19,322,877
|
#include <bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ii pair<int,int>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<ii>
using namespace std;
ll dp[111][4][2];
string n;
int k;
ll solve(int i, int n0, bool less){
if(n0 > k) return 0;
if(i == (int) n.size()) return n0==k;
ll &aux = dp[i][n0][less];
if(aux!=-1) return aux;
aux =0;
if(less){
for(int j=0;j<10;j++){
aux += solve(i + 1, n0 + (j > 0), true);
}
}
else{
int dig = int(n[i] - '0');
for(int j=0;j<dig;j++){
aux+= solve(i+1, n0 + (j > 0), true);
}
aux+= solve(i + 1, n0 + (dig>0), false);
}
return aux;
}
int32_t main(){
memset(dp,-1, sizeof dp);
cin >> n >> k;
cout << solve(0,0,0) << endl;
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;
int main() {
int M, K;
cin >> M >> K;
if(M == 0 && K == 0) {
cout << 0 << " " << 0 << endl;
return 0;
} else if(M == 1 && K == 0) {
cout << 1 << " " << 0 << " " << 0 << " " << 1 << endl;
return 0;
} else if(M >= 2 && K < (1 << M)) {
int now = (1 << M) - 1;
while(now >= 0) {
if(now != K)
cout << now << " ";
now--;
}
cout << K << " ";
now = 0;
while(now <= (1 << M) - 1) {
if(now != K)
cout << now << " ";
now++;
}
cout << K << endl;
} else {
cout << -1 << endl;
}
return 0;
}
| 0
| 74,203,293
|
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<map>
#include<iostream>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
int main() {
int N, s, e, r;
cin >> N;
vector<int> A(N), B(N), D(N);
rep(i, 0, N)cin >> A[i];
rep(i, 0, N)cin >> B[i];
rep(i, 0, N) {
D[i] = A[i] - B[i];
}
sort(all(D));
e = N - 1, s = 0;
r = 0;
while (D[s] < 0) {
if (D[e] <= 0) {
puts("-1");
return 0;
}
r += D[e];
e--;
while (D[s] < 0 && r + D[s] > 0) {
r += D[s];
s++;
}
}
printf("%d\n", N - e - 1 + s);
return 0;
}
|
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
vector<vector<long long> > G(200000);
vector<long long> counter(200000 ,0);
void dfs(long long i , long long p){
for(long long v = 0; v < G[i].size(); v++){
if(p == G[i][v]){
continue;
}
counter[G[i][v]] += counter[i];
dfs(G[i][v], i);
}
return;
}
int main(){
long long n ,q;
cin >> n >> q;
vector<vector<long long> > children(n);
for(long long i = 0; i < n-1; i++){
long long a, b;
cin >> a >> b;
a -= 1;
b -= 1;
children[a].push_back(b);
G[a].push_back(b);
G[b].push_back(a);
}
for(long long i = 0; i < q; i++){
long long p, x;
cin >> p >> x;
p -= 1;
counter[p] += x;
}
dfs(0, -1);
for(long long i = 0; i < n; i++){
printf("%lld ", counter[i]);
}
printf("\n");
return 0;
}
| 0
| 49,047,428
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define endl '\n'
#define debug(x) cerr << #x << ": " << x << endl;
#define fast_io; ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const ll MAXN=1e6 + 10;
const ll LOG=22;
const ll INF=8e18;
const ll MOD=1e9 + 7;
int main(){
fast_io;
int a,b;
char c;
cin>>a>>c>>b;
if(c=='+'){
cout<<a+b;
return 0;
}
cout<<a-b;
return 0;
}
|
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define mod 998244353
#define int long long
#define ld long double
#define pb push_back
#define vi vector<int>
#define dbg(x) cerr << #x << " = " << x << '\n'
#define sz(x) (int)x.size()
#define all(a) (a.begin(),a.end())
#define ff first
#define ss second
#define pii pair<int,int>
#define lcm(a,b) (a*b)/__gcd(a,b)
using namespace std;
inline void solve(){
int n,ans=0;
cin >> n ;
if (n&1^1) {
while (n>9){
ans += n/10;
n /= 5;
}
}
cout << ans << endl;
}
signed main()
{
int n=1;
while (n--) solve();
return 0;
}
| 0
| 86,242,649
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < n; i++)
int main()
{
int n,m,ans=0;
cin >> n>>m;
vector<int> a(n);
vector<vector<int>> p(n,vector<int>(n,0));
rep(i,m){
int a,b;
cin>> a>>b;
a--;b--;
p[a][b]=p[b][a]=1;
}
rep(i,n) a[i]=i;
do{
if(a[0]!=0) break;
bool ok=true;
rep(i,n-1){
if(p[a[i]][a[i+1]]==0) ok=false;
}
if(ok) ans++;
} while(next_permutation(a.begin(),a.end()));
cout<<ans<<endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main(){
int n,a,b,aa=0,bb=0,j=0,k=0,l=0,s,t,u,v;
cin>>n;
vector<int> A(100005,0),B(100005,0),AA(100005,-1),BB(100005,-1);
for(int i=0;i<n/2;i++){
cin>>a>>b;
A[a-1]++;
B[b-1]++;
aa=max(aa,A[a-1]);
bb=max(bb,B[b-1]);
}
for(int i=0;i<100005;i++){
if(A[i]==aa) {
AA[j]=i;j++;
}
if(B[i]==bb){
BB[k]=i;k++;
}
}
sort(A.begin(), A.end());
sort(B.begin(), B.end());
sort(AA.begin(), AA.end());
sort(BB.begin(), BB.end());
if(AA[100004]!=BB[100004]){
cout<<n-aa-bb;
}
else{
cout<<min(n-A[100004]-B[100003],n-A[100003]-B[100004]);
}
}
| 0
| 45,243,334
|
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <cmath>
double PI = acos(-1);
using namespace std;
class point{
public:
double x, y;
point(){ x = 0, y = 0; }
point(double a, double b){ x = a, y = b; }
friend point operator+(point a, point b){
return point(a.x + b.x, a.y + b.y);
}
friend point operator/(point a, double b){
return point(a.x / b, a.y / b);
}
friend point operator*(point a, double b){
return point(a.x * b, a.y * b);
}
};
void koch(int m, point p1, point p2){
if (m == 0) return;
point s, t, u;
s = (p1 * 2.0 + p2) / 3.0;
t = (p1 + p2 * 2.0) / 3.0;
u.x = (t.x - s.x)*cos(PI / 3) - (t.y - s.y)*sin(PI / 3)+s.x;
u.y = (t.x - s.x)*sin(PI / 3) + (t.y - s.y)*cos(PI / 3) + s.y;
koch(m - 1, p1, s);
cout << s.x << ' ' << s.y << '\n';
koch(m - 1, s, u);
cout << u.x << ' ' << u.y << '\n';
koch(m - 1, u, t);
cout << t.x << ' ' << t.y << '\n';
koch(m - 1, t, p2);
}
int main(){
int n; cin >> n;
point P1, P2;
P1.x = P1.y = 0;
P2.x = 100; P2.y = 0;
cout << fixed << setprecision(8);
cout << P1.x << ' ' << P1.y << '\n';
koch(n, P1, P2);
cout << P2.x << ' ' << P2.y << '\n';
}
|
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define PB pop_back
#define nn "\n"
#define all(p) p.begin(),p.end()
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define pi acos(-1.0)
typedef long long ll;
typedef vector<ll> vll;
int main()
{
string s,ss;
ll n,i=0,j=0;
cin>>s; cin>>n;
cout<<nn;
while(i<s.size())
{
cout<<s[i];
i+=n;
if(i>s.size()||i==s.size()) break;
}
return 0;
}
| 0
| 73,840,003
|
#include <bits/stdc++.h>
using namespace std;
int main(){
int a,b,c;
cin >> a >> b >> c;
if(a==max(a,max(b,c)))cout << a*10+b+c << endl;
else if(b==max(a,max(b,c)))cout << b*10+a+c << endl;
else if(c==max(a,max(b,c)))cout << c*10+a+b << endl;
}
|
#include<iostream>
#include<bits/stdc++.h>
#define fl(k, n) for(int i = k; i < n; i++)
#define flr(k, n) for(int i = n - 1; i >= k; i--)
#define vi vector<int>
#define vp vector<pair<int, int>>
#define mp make_pair
#define ll long long
using namespace std;
int binary_search(vector<int> nums, int target_val){
int begin = 0;
int end = nums.size();
int mid;
while(begin <= end){
mid = begin + (end - begin) / 2;
if(nums[mid] == target_val)
return mid;
else if(nums[mid] <= target_val && nums[mid + 1] > target_val)
return mid;
else if(nums[mid] > target_val)
end = mid - 1;
else
begin = mid + 1;
}
if(begin == 0)
return -1;
else
return nums.size();
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
vi heights(n);
fl(0, n)
cin >> heights[i];
vi costs(n);
costs[0] = 0;
costs[1] = abs(heights[1] - heights[0]);
fl(2, n){
int costj2 = costs[i - 2] + abs(heights[i] - heights[i - 2]);
int costj1 = costs[i - 1] + abs(heights[i] - heights[i - 1]);
costs[i] = min(costj2, costj1);
}
cout << costs[n - 1] << "\n";
}
| 0
| 78,428,730
|
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln = '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define fo(i,j,n) for (int i=(j); i < (n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int main() {
string s; cin >> s;
if(s == "abc" || s == "acb" || s == "bac" || s == "bca" || s == "cab" || s == "cba")
cout << "Yes" << ln;
else cout << "No" << ln;
}
|
#include <bits/stdc++.h>
using namespace std;
#define MAX 2000001
#define VMAX 10000
int main(void)
{
int C[VMAX + 1];
int n;
cin >> n;
unsigned short A[n + 1], B[n + 1];
for (int i = 0; i <= VMAX; ++i) C[i] = 0;
for (int i = 0; i < n; ++i) {
cin >> A[i + 1];
C[A[i + 1]]++;
}
for (int i = 1; i <= VMAX; ++i) C[i] = C[i] + C[i - 1];
for (int j = 1; j <= n; ++j) {
B[C[A[j]]] = A[j];
C[A[j]]--;
}
for (int i = 1; i <= n; ++i) {
if (i > 1) cout << " ";
cout << B[i];
}
cout << endl;
return 0;
}
| 0
| 81,154,953
|
#include <bits/stdc++.h>
using namespace std;
int x,y;
int main() {
cin >> x >> y;
if (y>=x*2 && y<=x*4 && y%2==0) cout<<"Yes"; else cout<<"No";
}
|
#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second
using namespace std;
const int maxN = 1e5 + 10;
const int inf = 3e18 + 10;
typedef pair<int, int> ii;
int k;
int dist[maxN];
vector<ii> adj[maxN];
void dijkstra(int src){
priority_queue<ii , vector<ii> , greater<ii> > pq ;
for(int i = 0; i < maxN; ++i)
dist[i] = inf;
pq.push({0,src});
dist[src] = 0 ;
while(!pq.empty()){
int u = pq.top().se;
pq.pop();
for(auto &t : adj[u]){
int v = t.fi;
int w = t.se;
if(dist[v] > dist[u] + w){
dist[v] = dist[u] + w ;
pq.push({dist[v], v});
}
}
}
cout << dist[0] + 1 << endl;
}
int32_t main()
{
ios_base::sync_with_stdio(false); cin.tie(); cout.tie();
cin >> k;
for(int i = 1; i <= k; ++i){
int u = i % k;
int v = (i + 1) % k;
adj[u].push_back({v,1});
}
for(int i = 1; i <= k; ++i){
int u = i % k;
int v = (10 * i) % k;
adj[u].push_back({v,0});
}
dijkstra(1);
}
| 0
| 34,730,008
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
ll x;
cin >> x;
ll ta=x%100;
ll judge=0;
while(ta>=5){
ta-=5;
judge++;
}
if(ta>0) judge++;
if(100*judge>x){
cout << 0 << endl;
}
else {
cout << 1 << endl;
}
}
|
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln = '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define fo(i,j,n) for (int i=(j); i < (n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int main() {
int n; cin >> n;
vector<string> S(n);
rep(i, n) cin >> S[i];
vector<char> alp;
for(char c = 'a'; c <= 'z'; c++)
alp.push_back(c);
vector<vector<int>> count(n, vector<int>(26, 0));
rep(i, n){
rep(j, S[i].size()){
int index = S[i][j] - 'a';
count[i][index]++;
}
}
rep(i, 26){
int mx = INF;
rep(j, n){
chmin(mx, count[j][i]);
}
rep(j, mx){
cout << alp[i];
}
}
cout << ln;
}
| 0
| 61,387,085
|
#include <cstring>
#include <iostream>
using namespace std;
char s[200005];
long long t[35];
int main()
{
cin>>s;
long long n=strlen(s);
long long ans=1+n*(n-1)/2;
for(int i=0;i<n;i++)
t[s[i]-'a']++;
for(int i=0;i<26;i++)
ans-=t[i]*(t[i]-1)/2;
cout<<ans<<endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
os << "(" << p.first << "," << p.second << ")";
return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n) \
cerr << __LINE__ << ": " << #x << " = {"; \
for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
cerr << ((hoge) ? "," : "") << x[hoge]; \
cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
int K;
string S;
cin >> K >> S;
if (K < S.length()) S = S.substr(0, K) + "...";
cout << S << endl;
return 0;
}
| 0
| 10,301,258
|
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
#define vec vector<ll>
#define mat vector<vector<ll> >
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=998244353;
const ll mod=1e9+7;
signed main(){
ll h,n;cin>>h>>n;
vector<ll>a(n);
vector<ll>b(n);
rep(i,n){
cin>>a[i]>>b[i];
}
vector<vector<ll> >dp(n+1,vector<ll>(h+1,mod*mod));
dp[0][0]=0;
rep(i,n){
rep(j,h+1){
dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
if(j+a[i]<=h){
dp[i][j+a[i]]=min(dp[i][j+a[i]],dp[i][j]+b[i]);
}else{
dp[i][h]=min(dp[i][h],dp[i][j]+b[i]);
}
}
}
cout<<dp[n][h]<<endl;
}
|
#include "bits/stdc++.h"
using namespace std;
const int INF = numeric_limits<int>::max() / 2;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
while(cin>>n,n){
vector<int> a(n);
for(int i=0;i<n;i++) cin>>a[i];
sort(a.begin(),a.end());
int res=INF;
for(int i=1;i<n;i++){
if(a[i]-a[i-1]<res){
res=a[i]-a[i-1];
}
}
cout<<res<<endl;
}
}
| 0
| 36,575,817
|
#include<algorithm>
#include<iostream>
#include<vector>
using namespace std;
typedef long long lint;
typedef vector<int>vi;
typedef pair<int,int>pii;
#define rep(i,n)for(int i=0;i<(int)(n);++i)
int main(){
int n;
lint k;
cin>>n>>k;
vector<lint>a(n),b(n);
rep(i,n){
cin>>a[i]>>b[i];
}
lint m=0;
while(1){
lint sum=0;
rep(i,n)
if((a[i]&k)==a[i])sum+=b[i];
m=max(m,sum);
if(k==0)break;
k+=1;
k&=k-1;
k=max(k-1,0LL);
}
cout<<m<<endl;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;
#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846
#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back
int main()
{
string S;
cin >> S;
ll zero = 0, one = 0;
REP(i,0,SZ(S)) {
if(S[i] == '0') ++zero;
else ++one;
}
PR(MIN(zero,one)*2);
return 0;
}
| 0
| 10,661,362
|
#include<iostream>
#include<string>
using namespace std;
int main()
{
string S;
cin >> S;
if(S == "SSS") cout << 0 << endl;
else if(S == "SSR") cout << 1 << endl;
else if(S == "SRS") cout << 1 << endl;
else if(S == "SRR") cout << 2 << endl;
else if(S == "RSS") cout << 1 << endl;
else if(S == "RSR") cout << 1 << endl;
else if(S == "RRS") cout << 2 << endl;
else cout << 3 << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())
void yes() {
cout << "Yes" << endl;
exit(0);
}
void no() {
cout << "No" << endl;
exit(0);
}
int main() {
ll n;
cin >> n;
ll ct = 0, cx = 0, cy = 0;
vector<ll> t(n), x(n), y(n);
REP(i, n) { cin >> t[i] >> x[i] >> y[i]; }
REP(i, n) {
ll dt = t[i] - ct, dx = x[i] - cx, dy = y[i] - cy;
ll d = abs(dx) + abs(dy);
if (d > dt) {
no();
}
if ((dt - d) % 2 == 1) {
no();
}
cx = x[i];
cy = y[i];
ct = t[i];
}
yes();
}
| 0
| 45,537,490
|
#include <bits/stdc++.h>
using namespace std;
#define N 1010
int x[N],y[N],d[N];
bool flag[2];
int read(){
int x=0,f=1;
char ch=getchar();
while (ch<'0' || ch>'9'){
if (ch=='-') f=-1;
ch=getchar();
}
while (ch>='0' && ch<='9'){
x=x*10+ch-'0';ch=getchar();
}
return x*f;
}
signed main(){
int n=read(),m=0;
for (int i=1;i<=n;++i){
x[i]=read(),y[i]=read();
flag[(x[i]+y[i])&1]=1;
}
if (flag[0] && flag[1]){
puts("-1");return 0;
}
if (flag[0]) d[++m]=1;
for (int i=30;i>=0;--i) d[++m]=1<<i;
cout<<m<<endl;
for (int i=1;i<m;++i) printf("%d ",d[i]);
printf("%d\n",d[m]);
for (int i=1;i<=n;++i){
for (int j=1;j<=m;++j){
if (abs(x[i])>abs(y[i])){
if (x[i]>0) x[i]-=d[j],putchar('R');
else x[i]+=d[j],putchar('L');
}else{
if (y[i]>0) y[i]-=d[j],putchar('U');
else y[i]+=d[j],putchar('D');
}
}
putchar('\n');
}
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define eps 1e-9
#define maxp 99940000
#define mod 1000000007
#define pi 3.141592653589793238
#define sin(s) scanf("%lld",&s);
#define sout(s) printf("%lld\n",s);
#define in(s) cin>>s
#define in2(a,b) cin>>a>>b
#define in3(a,b,c) cin>>a>>b>>c
#define vll vector<ll>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define endl '\n'
#define sp ' '
#define gear_change ios_base::sync_with_stdio(false),cin.tie(0)
#define nfl(i,n) for(i=0;i<n;i++)
#define sfl(i,s,e) for(i=s;i<e;i++)
#define ufl(i,n) for(i=n-1;i>=0;i--)
ll power(ll x,ll y){
ll ret=1;
while(y>0){
if(y&1)
ret=(ret*x);
y/=2;
x=(x*x);
}
return ret;
}
string rot(string s){
string ret="";
ll i;
for(i=1;s[i];i++){
ret+=s[i];
}
ret+=s[0];
return ret;
}
void solve(){
ll arr[3]={0};
ll a,b,c;
cin>>a>>b>>c;
arr[0]=abs(a-b);
arr[1]=abs(b-c);
arr[2]=abs(c-a);
sort(arr,arr+3);
cout<<arr[0]+arr[1]<<endl;
}
int main(){
gear_change;
ll test=1;
while(test--){
solve();
}
}
| 0
| 43,524,115
|
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
int n;
cin >> n;
if(n < 1200)
cout << "ABC" << endl;
else
cout << "ARC" << endl;
return 0;
}
|
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <limits>
#include <queue>
#include <iomanip>
#include <set>
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
using namespace std;
#define ALL(X) X.begin(),X.end()
using ll = long long int;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
const int MOD=1000000007;
const int INTMAX=2147483647;
const ll LLMAX=9223372036854775807;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
ll N;
cin>>N;
vll L(2*N);
for(ll i=0;i<2*N;i++)cin>>L[i];
sort(ALL(L));
ll ans=0;
for(ll i=0;i<2*N;i++){
ans+=L[i];
i++;
}
cout<<ans<<endl;
return 0;
}
| 0
| 13,012,713
|
#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)++)
#define frep(i,m,n) for(ll (i)=(m); (i)<=(ll)(n); (i)++)
#define rrep(i,n) for(ll (i)=(n)-1; (i)>-1; (i)--)
#define frrep(i,m,n) for(ll (i)=(n); (i)>(ll)(m); (i)--)
#define ALL(x) (x).begin(), (x).end()
const ll INF = 100100100100100100;
const ll MOD = 1000000007;
ll my_abs(ll a);
ll a_n(ll a, ll n);
ll my_gcd(ll a, ll b);
ll inv(ll a);
ll madd(ll a, ll b, ll c);
ll msub(ll a, ll b);
ll mtime(ll a, ll b, ll c);
int main() {
ll d;
cin >> d;
cout << "Christmas";
frep(i, d, 24) {
cout << " Eve";
}
cout << endl;
return 0;
}
ll my_abs(ll a) {
if(a >= 0) return a;
else return -1 *a;
}
ll a_n(ll a, ll n) {
if(n == 0) return 1;
ll ret = a, count = 1;
while(count * 2 < n) {
ret *= ret;
count *= 2;
}
if(count == n) return ret;
else return (ret * a_n(a, n-count));
}
ll my_gcd(ll a, ll b) {
if(b == 0) return a;
return my_gcd(b, a%b);
}
ll inv(ll a) {
return a_n(a, MOD-2);
}
ll madd(ll a, ll b, ll c) {
ll ret = (a+b) % MOD;
return (ret+c) % MOD;
}
ll msub(ll a, ll b) {
if(a < b) return (a-b+MOD) % MOD;
else return (a-b) % MOD;
}
ll mtime(ll a, ll b, ll c) {
ll ret = (a*b) % MOD;
return (ret*c) % MOD;
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
struct edge {
int to, cost;
};
signed main() {
int K;
cin >> K;
vector<bool> vis(K, false);
deque<pair<int, int>> dq;
dq.push_back({1, 1});
while (!dq.empty()) {
pair<int, int> p = dq.front();
dq.pop_front();
int x = p.first, d = p.second;
if (vis[x]) continue;
vis[x] = true;
if (x == 0) {
cout << d << endl;
return 0;
}
dq.push_back({(x + 1) % K, d + 1});
dq.push_front({(x * 10) % K, d});
}
return 0;
}
| 0
| 32,786,889
|
#include <bits/stdc++.h>
#define rep(i, s, n) for(int i = (s); i < (int)(n); i++)
#define INF INT_MAX/2
using namespace std;
int N, K;
int main() {
cin >> N >> K;
queue<int> que1;
que1.push(1);
rep(i, 0, N) {
queue<int> que0;
while (!que1.empty()) {
int x = que1.front(); que1.pop();
que0.push(x * 2);
que0.push(x + K);
}
swap(que1, que0);
}
int ans = INF;
while (!que1.empty()) {
int x = que1.front(); que1.pop();
ans = min(ans, x);
}
cout << ans << endl;
}
|
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define F(i,s,e) for(ll i=s;i<e;++i)
int main()
{
ll N,M;
cin >> N >> M;
ll A[M],B[M];
F(i,0,M) cin >> A[i] >> B[i];
vector<ll> G[N];
F(i,0,M){
G[A[i]-1].push_back(B[i]-1);
G[B[i]-1].push_back(A[i]-1);
}
ll S[N]={0};
bool seen[N];
F(i,0,N) seen[i]=false;
queue<ll> q;
q.push(0);
seen[0]=true;
while(!q.empty()){
ll t=q.front(); q.pop();
for(auto nv : G[t]){
if(!seen[nv]){
seen[nv]=true;
S[nv]=t;
q.push(nv);
}
}
}
bool f=true;
F(i,0,N){
if(!seen[i]) f=false;
}
if(f){
cout << "Yes" << endl;
F(i,1,N){
cout << S[i]+1 << endl;
}
}
else{
cout << "No" << endl;
}
return 0;
}
| 0
| 62,481,354
|
#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 h,w;
cin>>h>>w;
char fi[h][w];
rep(i,h) rep(j,w) cin>>fi[i][j];
int cw[h][w];
rep(i,h) rep(j,w) cw[i][j]=0;
rep(i,h){
int c=1;
rep(j,w){
if(fi[i][j]=='#') c=1;
else{
cw[i][j]=c;
c++;
}
}
}
rep(i,h){
for(int j=w-2;j>=0;j--){
if(cw[i][j]==0) continue;
if(cw[i][j+1]==0) continue;
cw[i][j]=cw[i][j+1];
}
}
int ch[h][w];
rep(i,h) rep(j,w) ch[i][j]=0;
rep(j,w){
int c=1;
rep(i,h){
if(fi[i][j]=='#') c=1;
else{
ch[i][j]=c;
c++;
}
}
}
rep(j,w){
for(int i=h-2;i>=0;i--){
if(ch[i][j]==0) continue;
if(ch[i+1][j]==0) continue;
ch[i][j]=ch[i+1][j];
}
}
int ans=0;
rep(i,h){
rep(j,w){
ans=max(ans,ch[i][j]+cw[i][j]);
}
}
cout<<ans-1<<endl;
}
|
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
long long n, m, adj[101][101], dst[101][101], pre[101][101];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
set<pair<long long, long long>> st;
for(long long i = 0; i < m; i++){
long long a, b, c;
cin >> a >> b >> c;
adj[a][b] = c, adj[b][a] = c;
if(a > b) swap(a, b);
st.insert({a, b});
}
for(long long i = 1; i <= n; i++)
for(long long j = 1; j <= n; j++){
if(i == j) dst[i][j] = 0;
else if(adj[i][j]) dst[i][j] = adj[i][j];
else dst[i][j] = 1e14;
pre[i][j] = i;
}
for(long long k = 1; k <= n; k++)
for(long long i = 1; i <= n; i++)
for(long long j = 1; j <= n; j++)
if(dst[i][k] + dst[k][j] < dst[i][j]){
dst[i][j] = dst[i][k] + dst[k][j];
pre[i][j] = pre[k][j];
}
for(long long i = 1; i < n; i++)
for(long long j = 1; j <= n; j++)
st.erase({pre[i][j], j});
cout << st.size() << "\n";
return 0;
}
| 0
| 98,250,801
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
int main() {
int n;
string s, t;
cin >> n >> s >> t;
for (int i = 0; i <= n; i++) {
string u = s + t.substr(n-i, i);
int m = u.size();
if (u.substr(m-n, n) == t) {
cout << u.size() << endl;
return 0;
}
}
}
|
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
using namespace std;
typedef long long ll;
vector<ll> v;
int main() {
int n;
cin >> n;
ll a[n],sum=0;
for(int i=0;i<n;i++){
cin >> a[i];
sum += a[i];
}
for(int i=0;i<n-1;i++){
sum -= 2*a[i];
ll abs = max(sum, -sum);
v.push_back(abs);
}
sort(v.begin(),v.end());
cout << v.at(0) << endl;
}
| 0
| 87,783,045
|
#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 res(i,n) for(int i=n;;i++)
#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 REV(i,n) for(int i=n-1;i>0;i--)
#define req(i,n,m) for(int i=n;i<m;i++)
#define REQ(i,n,m,l) for(int i=n;i<m;i+=l)
#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;
}
signed gcd(long long x, long long y) {
if (y == 0)return x;
return gcd(y, x % y);
}
signed lcm(long long x, long long y) {
return x / gcd(x, y) * y;
}
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;
REP(i, 8) {
if (N < pow(2, i)) {
cout << pow(2, i - 1) << endl;
return 0;
}
}
}
|
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
template <typename T> constexpr bool chmax(T &a, const T b) {
if(a >= b) return false;
a = b;
return true;
}
template <typename T> constexpr bool chmin(T &a, const T b) {
if(a <= b) return false;
a = b;
return true;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(0);
int n;
cin >> n;
ll a[n], sum = 0, A = 0, B = 0;
rep(i, n) cin >> a[i], sum -= a[i];
rep(i, n) {
ll b;
cin >> b;
sum += b;
if(b < a[i])
B += a[i] - b;
else
A += b - a[i] + 1 >> 1;
}
cout << (sum >= A && sum >= B ? "Yes" : "No") << endl;
return 0;
}
| 0
| 12,921,854
|
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int dp[111][111],n,L[111],R[111];
int dfs(int l,int r){
if(dp[l][r]!=-1)return dp[l][r];
int res=1e9;
for(int i=l;i<r;i++){
res=min(res,dfs(l,i)+dfs(i+1,r)+L[l]*R[i]*R[r]);
}
return dp[l][r]=res;
}
signed main(){
memset(dp,-1,sizeof(dp));
r(i,111)dp[i][i]=0;
cin>>n;
r(i,n)cin>>L[i]>>R[i];
cout<<dfs(0,n-1)<<endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#define BIG 100000000000
int main(void){
int N, K;
vector<int64_t> h;
vector<int64_t> cost(100001);
cin >>N >>K;
for(int i=0;i<N;i++){
int tmp;
cin >>tmp;
h.push_back(tmp);
}
cost[0]=0;
for(int i=1;i<K;i++){
cost[i]=BIG;
for(int j=0;j<i;j++) cost[i]=min(abs(h[i]-h[j])+cost[j], cost[i]);
}
for(int i=K;i<N;i++){
cost[i]=BIG;
for(int j=i-K;j<i;j++) cost[i]=min(abs(h[i]-h[j])+cost[j], cost[i]);
}
cout <<cost[N-1]<<endl;
return 0;
}
| 0
| 8,316,783
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int A,B,C,D;
1 <= A,B,C,D <= 10;
cin >> A >> B >> C >> D;
if (A+B > C+D) {
cout << "Left" << endl;
} else if (A+B == C+D) {
cout << "Balanced" << endl;
} else {
cout << "Right" << endl;
}
}
|
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
short dp[1010][1010];
int main(void)
{
int q;
cin >> q;
while (q)
{
string X, Y;
cin >> X >> Y;
int Xs = X.size(), Ys = Y.size();
for (int i = 0; i < Xs; i++) dp[i][0] = 0;
for (int j = 0; j < Ys; j++) dp[0][j] = 0;
for (int i = 0; i < Xs; i++)
{
for (int j = 0; j < Ys; j++)
dp[i + 1][j + 1] = ((X[i] == Y[j]) ? dp[i][j] + 1 : max(dp[i + 1][j], dp[i][j + 1]));
}
cout << dp[Xs][Ys] << endl;
q--;
}
return 0;
}
| 0
| 19,543,030
|
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
vector<ll> S(10000006, 0);
vector<ll> A(10000006, 0);
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n;
cin>>n;
const ll N=n+1;
A[0]=A[1]=0;
for(ll i=2;i<N;i++){
if(A[i]==0){
for(ll j=2*i;j<N;j+=i){
A[j]=i;
}
}
}
S[1]=1;
for(ll i=2;i<N;i++){
if(A[i]==0)
S[i]=2;
else {
ll x=i;
while(x%A[i]==0)
x/=A[i];
if(x==1)
S[i]=S[i/A[i]]+1;
else
S[i]=S[x]*S[i/x];
}
}
ll ans=0;
for(ll i=1;i<=n;i++)
ans+=i*S[i];
cout<<ans;
}
|
#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*b/gcd(a, b);
}
int main()
{
cout << fixed << setprecision(15);
ll N;
cin >> N;
vector<ll> A(N+1, 0);
for(ll i=1; i<=N; i++){
ll t = i;
for(ll j=2; j<=t; j++){
while(t%j ==0){
t = t/j;
A[j]++;
}
}
}
ll a=0;
ll b=0;
ll c=0;
ll d=0;
ll e=0;
for(ll i=2; i<=N; i++){
if(A[i] >= 2) a++;
if(A[i] >= 4) b++;
if(A[i] >= 14) c++;
if(A[i] >= 24) d++;
if(A[i] >= 74) e++;
}
ll ans = 0;
ans += b*(b-1)/2 * (a-2);
ans += d * (a-1);
ans += c * (b-1);
ans += e;
cout << ans << endl;
return 0;
}
| 0
| 14,091,415
|
#include <bits/stdc++.h>
using namespace std;
int main(){
string S;
cin>>S;
int X=S.size();
vector<char>A((X-1)/2);
vector<char>B((X-1)/2);
for(int i=0; i<(X-1)/2; i++){
A.at(i)=S.at(i);
}
for(int i=0; i<(X-1)/2; i++){
B.at(i)=S.at(i+(X+1)/2);
}
bool a=true;
for(int i=0; i<(X-1)/2; i++){
if(A.at(i)!=B.at(i)){
a=false;
}
}
if(a==true){
if((X-1)/2%2==0){
for(int i=0; i<(X-1)/2/2; i++){
if(S.at(i)==S.at((X-1)/2-i-1)){
}
else{
cout<<"No"<<endl;
break;
}
}
cout<<"Yes"<<endl;
}
else{
for(int i=0; i<((X-1)/2-1)/2; i++){
if(S.at(i)==S.at((X-1)/2-i-1)){
}
else{
cout<<"No"<<endl;
break;
}
}
cout<<"Yes"<<endl;
}
}
else
cout<<"No"<<endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = a; i < (int)(b); i++)
#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(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using ll = long long;
int pow(int a, int b, int mod) {
if (b == 0) {
return 1;
} else if (b % 2 == 1) {
return pow(a, b - 1, mod) * a % mod;
}
int c = pow(a, b / 2, mod);
return c * c % mod;
}
int main() {
int k;
cin >> k;
queue<ll> que;
REP1(i, 9) { que.push(i); }
REP(i, k - 1) {
ll x = que.front();
que.pop();
if (x % 10 > 0) {
que.push(10 * x + x % 10 - 1);
}
que.push(10 * x + x % 10);
if (x % 10 < 9) {
que.push(10 * x + x % 10 + 1);
}
}
cout << que.front() << endl;
return 0;
}
| 0
| 48,030,666
|
#include<bits/stdc++.h>
using namespace std;
int main(){
long long n,t,i;
cin >> n >> t;
vector<long long> ti(n);
for(i=0;i<n;++i){
cin >> ti[i];
}
long long ans=0;
bool bet=false;
for(i=0;i<n-1;++i){
ans+=min(t,ti[i+1]-ti[i]);
}
ans+=t;
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define ll unsigned long long int
#define mod 1000000007
bool isPrime[1000001];
ll power(ll a,ll b)
{
ll result = 1;
while(b>0)
{
if(b%2)
{
result = (a*result)%mod;
}
a = (a*a)%mod;
b = b/2;
}
return result;
}
int gcd(int a,int b)
{
if(b==0)
{
return a;
}
return gcd(b,a%b);
}
void sieve()
{
memset(isPrime,1,sizeof(isPrime));
isPrime[0] = isPrime[1] = 0;
for(int i=2;i*i<=1000000;i++)
{
if(isPrime[i])
{
for(int j=i*i;j<=1000000;j+=i)
{
isPrime[j] = 0;
}
}
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL),cout.tie(NULL);
int t,n;
t = 1;
for(int i=0;i<t;i++)
{
sieve();
cin>>n;
int arr[n];
int z;
unordered_map <int,int> mp,mp2;
for(int i=0;i<n;i++)
{
cin>>arr[i];
mp[arr[i]]++;
}
vector <int> v;
for(auto i = mp.begin();i!=mp.end();i++)
{
v.push_back(i->first);
}
sort(v.begin(),v.end());
for(int i=0;i<v.size();i++)
{
for(int j=2;j<=1000000;j++)
{
if(v[i]*j>1000000)
{
break;
}
mp2[v[i]*j] = 1;
}
}
int cnt = 0;
for(int i=0;i<v.size();i++)
{
if(mp[v[i]]>=2)
{
continue;
}
if(!mp2[v[i]])
{
cnt++;
}
}
cout<<cnt;
}
return 0;
}
| 0
| 68,987,466
|
#include <iostream>
#include <map>
using namespace std;
int main(int argc, char const* argv[])
{
int table_size;
while(cin >> table_size) {
if (table_size == 0) break;
map<char, char> table;
char key, val;
for (int i = 0; i < table_size; i++) {
cin >> key >> val;
table.insert( map<char, char>::value_type( key, val ) );
}
int input_size;
cin >> input_size;
char c;
for (int i = 0; i < input_size; i++) {
cin >> c;
if (table.find(c) == table.end()) {
cout << c;
} else {
cout << table[c];
}
}
cout << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;
int main(){
ll N,K;
cin >> N >> K;
vector<ll> x(N);
vector<ll> y(N);
rep(i,N) cin >> x[i] >> y[i];
ll ans = 4000000000000000001;
for (ll i = 0; i < N; i++){
for (ll j = i + 1; j < N; j++){
for (ll k = 0; k < N; k++){
for (ll l = k + 1; l < N; l++){
ll ans_sub = abs(y[l] - y[k]) * abs(x[j] - x[i]);
ll cnt = 0;
rep(m,N){
ll min_x = min(x[i], x[j]);
ll max_x = max(x[i], x[j]);
ll min_y = min(y[k], y[l]);
ll max_y = max(y[k], y[l]);
if (min_x <= x[m] && x[m] <= max_x && min_y <= y[m] && y[m] <= max_y){
cnt++;
}
if (cnt >= K) ans = min(ans, ans_sub);
}
}
}
}
}
cout << ans << endl;
}
| 0
| 66,862,623
|
#include<bits/stdc++.h>
#define lld long long int
#define llf long double
#define pb push_back
#define mp make_pair
#define IN insert
#define loopN(n) for(lld i=0;i<n;i++)
#define loop(p,n) for(lld i=p;i<=n;i++)
#define rloop(p,n) for(lld i=n;i>=p;i--)
#define loop2(p,n) for(lld j=p;j<=n;j++)
#define all(v) v.begin(),v.end()
#define F1 first
#define F2 second
#define INF 2e18
#define FILE freopen("input.txt","r",stdin);freopen("output.txt","w",stdout)
#define PI 2*acos(0.0)
#define ISO ios::sync_with_stdio(false);cin.tie(0)
#define mod 100000007
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
bool pal(lld n)
{
vector<lld>a;
while(n!=0)
{
a.pb(n%10);
n/=10;
}
lld p=0,q=a.size()-1;
while(p<=q)
{
if(a[p]!=a[q])return 0;
p++;
q--;
}
return 1;
}
int main()
{
ISO;
lld a,b;
cin>>a>>b;
lld ans=0;
loop(a,b)
{
if(pal(i))ans++;
}
cout<<ans<<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)
#define INF (1LL<<50)
#define MOD 1000000007
int main(){
string S;
cin >> S;
if(S=="zyxwvutsrqponmlkjihgfedcba"){
cout << -1 << endl;
return 0;
}
map<char,int> m,m2;
rep(i,S.size()){
m[S[i]]++;
}
if(m.size()<26){
string ans = S;
for(char c='a';c<='z';c++){
if(m[c]==0){
ans+=c;
cout << ans << endl;
return 0;
}
}
}else{
for(int i=25;i>0;i--){
if(S[i]>S[i-1]){
string ans = S.substr(0,i-1);
rep(i,ans.size()){
m2[ans[i]]++;
}
for(char c=S[i-1]+1;c<='z';c++){
if(m2[c]==0){
ans+=c;
break;
}
}
cout << ans << endl;
return 0;
}
}
}
return 0;
}
| 0
| 10,481,478
|
#include <bits/stdc++.h>
using namespace std;
#define sws ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define INFINITO 1000000000
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define vvi vector<vi>
#define all(x) x.begin(), x.end()
#define fo(i, n) for( int i = 0; i < n; i++ )
int main() {
string s;
cin >> s;
int cont = 0;
for ( size_t i = 0; i < s.size() - 1; i++ ) {
if ( s[i] == s[i + 1] ) {
s[i + 1] = (s[i + 1] == '0' ? '1' : '0');
cont++;
}
}
cout << cont << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
using ll = long long;
#define chmin(i, j) i = min(i, j);
#define chmax(i, j) i = max(i, j);
#define rep(i, n) for(int i=0;i<n;i++)
ll X, Y, Z, K;
vector<ll> a, b, c;
vector<ll> ans;
bool solve(ll T, bool sp) {
int cnt = 0;
rep(i, X) {
rep(j, Y) {
rep(k, Z) {
if(a[i]+b[j]+c[k]<T) break;
if(sp) ans.emplace_back(a[i]+b[j]+c[k]);
cnt++;
if(!sp && cnt >= K) return true;
}
}
}
return false;
}
int main() {
cin >> X >> Y >> Z >> K;
a.resize(X);b.resize(Y);c.resize(Z);
rep(i, X) cin >> a[i];
rep(i, Y) cin >> b[i];
rep(i, Z) cin >> c[i];
sort(a.rbegin(), a.rend());
sort(b.rbegin(), b.rend());
sort(c.rbegin(), c.rend());
ll front = 0;
ll back = 30000000000;
while(front != back) {
ll half = (back + front) / 2;
if(back == front+1) {
back = front;
}
else if(solve(half, false)) front = half;
else back = half - 1;
}
solve(front, true);
sort(ans.rbegin(), ans.rend());
rep(i, K) cout << ans[i] << endl;
return 0;
}
| 0
| 43,993,746
|
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
int A, B, C;
cin >> A >> B >> C;
int ans = A + B + C;
cout << ans - max(A, max(B, C)) << endl;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout<<fixed; cout<<setprecision(12);
#define randomINT mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define newl cout<<"\n"
#define DISP(as) for(auto it : as) cout<<it<<" ";newl;
#define all(x) (x).begin(),(x).end()
#define mset(x,val) memset(x,val,sizeof(x))
#define newl cout<<"\n"
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define dline cerr<<"
#define deb1(x) cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y) cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z) cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';
typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll , ll> pll;
typedef pair<ld, ld> pld;
typedef unordered_map<ll, ll> um;
typedef vector<pll> vpll;
const ll MAX5 = 1e+5 + 7;
const ll MAX7 = 1e+7 + 7;
const ll MAXN = MAX7;
const ll INF = 0x7f7f7f7f7f7f7f7f;
const int INFi = 0x7f7f7f7f;
const ll MOD = 1e+9 + 7;
vll adj[MAXN]; ll visit[MAXN] = {};
int dx8[] = {0, 1, 1, 1, 0, -1, -1, -1}, dy8[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dx4[] = {0, 1, 0, -1}, dy4[] = {1, 0, -1, 0};
ll T = 1;
ll n, x, m, y, k;
string s, t;
void MAIN() {
cin >> s >> t;
sort(all(s));
sort(all(t));
reverse(all(t));
if(s < t) cout<<"Yes";
else cout<<"No";
}
int main() {
fastio; randomINT;
while (T--) {
MAIN();
}
return 0;
}
| 0
| 64,706,716
|
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define fi first
#define se second
#define pb push_back
#define soo(v) sort(v.rbegin(),v.rend())
#define so(v) sort(v.begin(),v.end())
#define lb(v,x) lower_bound(v.begin(),v.end(),x)
#define ub(v,x) upper_bound(v.begin(),v.end(),x)
#define endl '\n'
#define dbv(v) cout<<endl;cout<<#v<<"-->> ";for(auto it:v){cout<<it<<" ";}cout<<endl;
#define dbm(m)cout<<endl;cout<<#m<<"-->> ";for(auto it:m){cout<<it.fi<<" "<<it.se.fi<<" "<<it.se.se<<endl;}
#define dbs(s)cout<<endl;cout<<#s<<"-->> ";for(auto it:s){cout<<it<<" ";}cout<<endl;
#define mod 1000000007
#define db1(x) cout<<#x<<"="<<x<<endl;
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl;
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<endl;
#define mx 1e18
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define double long double
#define io std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define re(s) reverse(s.begin(),s.end())
int powe(int x,int n)
{
if(n==0)return 1;
if(n%2==0)
return powe((x%mod*x%mod)%mod,n/2)%mod;
return (x%mod*powe((x%mod*x%mod)%mod,(n-1)/2)%mod)%mod;
}
int fun(int s,vector<int>&dp)
{
if(s<0)return 0;
if(dp[s]!=-1)return dp[s];
if(s==0)return dp[s]=1;
int pp=0;
for(int i=3;i<=s;i++)
{
pp+= fun(s-i,dp);
pp%=mod;
}
return dp[s]=pp;
}
int32_t main()
{
io
int n;
cin>>n;vector<int>dp(n+1,-1);
cout<<fun(n,dp);
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int mod = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define ALL(a) (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll Len(ll n) {
ll s=0;
while(n!=0) s++, n/=10;
return s;
}
ll Sint(ll n) {
ll m=0,s=0,a=n;
while(a!=0) s++, a/=10;
for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
return m;
}
ll Svec(vector<ll> v){
ll n=0;
for(ll i=0;i<v.size();i++) n+=v[i];
return n;
}
ll GCD(ll a,ll b){
ll r,tmp;
if(a<b){
tmp=a,a=b,b=tmp;
}
r=a%b;
while(r!=0){
a=b,b=r,r=a%b;
}
return b;
}
ll LCM(ll a,ll b){
ll c=a,d=b,r,tmp;
if(a<b){
tmp=a,a=b,b=tmp;
}
r=a%b;
while(r!=0){
a=b,b=r,r=a%b;
}
return c/b*d;
}
ll Factorial(ll n){
ll m=1;
while(n>=1) m*=n,n--;
return m;
}
vector<pair<char,ll>> runlength(string s,vector<pair<char,ll>> p){
ll x=1;
if(s.size()==1){
p.push_back(pair<char,ll>(s[0],1));
return p;
}
for(ll i=0;i<s.size()-1;i++){
if(s[i]==s[i+1]){
x++;
if(i==s.size()-2){
p.push_back(pair<char,ll>(s[i],x));
}
}else{
p.push_back(pair<char,ll>(s[i],x));
x=1;
if(i==s.size()-2){
p.push_back(pair<char,ll>(s[s.size()-1],x));
}
}
}
return p;
}
int main() {
IOS;
string s,ans="";
ll n;
cin>>s>>n;
rep(i,(s.size()+n-1)/n){
ans+=s[i*n];
}
cout<<ans<<endl;
}
| 0
| 32,855,224
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define vt vector
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fi first
#define se second
#define die return cout << "Yes", 0
signed main() {
ios::sync_with_stdio(0), cin.tie(0);
vt<int> a(9);
for (int &i : a) cin >> i;
int n;
cin >> n;
while (n--) {
int x;
cin >> x;
for (int i = 0; i < 9; i++) {
if (a[i] == x) a[i] = 0;
}
}
for (int i = 0; i < 3; i++) {
if (!a[i * 3] && !a[i * 3 + 1] && !a[i * 3 + 2]) die;
if (!a[i] && !a[i + 3] && !a[i + 6]) die;
}
if (!a[0] && !a[4] && !a[8]) die;
if (!a[2] && !a[4] && !a[6]) die;
cout << "No";
}
|
#include<iostream>
#include<algorithm>
#include<vector>
using ll = long long;
using namespace std;
constexpr ll INFI = 1e18;
ll calc(int n, int k, vector<int> v, int* a);
int main() {
int n, k;
ll lcost;
ll cost;
cin >> n >> k;
int* a = new int[n];
for (int i = 0;i < n;i++) {
cin >> a[i];
}
vector<int> v;
v.push_back(0);
cout << calc(n, k, v, a) << endl;
}
ll calc(int n, int k, vector<int> v, int* a) {
if (v.size() == k) {
int index = 0;
int height = 0;
ll cost = 0;
for (int i = 0;index<k;i++) {
if (v[index] == i) {
if (a[i] > height) {
height = a[i];
}
else {
height++;
cost += height - a[i];
}
index++;
}
else {
if (a[i] > height) {
height = a[i];
}
}
}
return cost;
}else {
ll mi=INFI;
for (int i = v[v.size() - 1] + 1;i < n;i++) {
vector<int> v2(v);
v2.push_back(i);
mi = min(mi,calc(n, k, v2, a));
}
return mi;
}
}
| 0
| 31,935,348
|
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
distance(v.begin(), upper_bound(v.begin(), v.end(), x))
using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;
ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
const ll INF = 1LL << 50;
int main() {
cout << fixed << setprecision(15);
ll n, m;
cin >> n >> m;
ll ans = (1900 * m + 100 * (n - m))*(1LL << m);
cout << ans << endl;
return 0;
}
|
#include<iostream>
#include<string>
#include<vector>
#include <algorithm>
using namespace std;
int main() {
string S;
cin >> S;
int size = S.size() ;
vector<int> alphabet(26);
for(int i=0;i<size;i++){
int num = S[i] -'a' ;
alphabet.at(num) = 1;
}
char min_char;
bool judge = false;
for(int i=0;i<26;i++){
if(alphabet.at(i) == 0){
min_char = i + 'a';
judge = true;
break;
}
else if(i == 25){
cout << "None" << endl;
}
}
if(judge){
cout << min_char << endl;
}
}
| 0
| 18,657,857
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.