code1
stringlengths 54
12k
| code2
stringlengths 65
12k
| similar
int64 0
1
| __index_level_0__
int64 45
101M
|
---|---|---|---|
#include <iostream>
#include <cmath>
using namespace std;
#define NUM 600
int main(){
long n;
while(cin >> n){
long a = NUM/n;
long b = 0;
for(long i=1;i<a;i++) b += n*n*n*i*i;
cout << b << endl;
}
} | #include<bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]){
int d;
while(std::cin >> d){
int ans = 0, cnt = 1;
while(d*cnt < 600){
ans += d*d*d*cnt*cnt++;
}
std::cout << ans << std::endl;
}
return 0;
} | 1 | 67,936,204 |
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
string str,ans="";
stack<char> sta;
cin>>str;
for(int i=0;i<str.size();i++){
if(str[i] == 'B'){
if(sta.size() >0){
sta.pop();
}
}else{
sta.push(str[i]);
}
}
while(!sta.empty()){
ans += sta.top();
sta.pop();
}
reverse(ans.begin(),ans.end());
cout<<ans<<endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main() {
string S;
cin >> S;
deque<int> dq;
for(int i=0;i<S.size();i++){
if(S[i] =='B'){
if(dq.empty()){
continue;
}
dq.pop_back();
}else{
dq.push_back(S[i]-'0');
}
}
while(!dq.empty()){
cout <<dq.front();
dq.pop_front();
}
cout<<endl;
return 0;
} | 1 | 67,984,015 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout << fixed
#define endl '\n'
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
void solve(istream& cin, ostream& cout) {
int n;
cin >> n;
vector<int> a(n);
REP(i, n) cin >> a[i];
ll ans = 0;
int now = a[0];
FOR(i, 1, n - 1) {
if (now >= a[i]) ans += now - a[i];
else {
now = a[i];
}
}
cout << ans << endl;
}
#ifndef TEST
int main() {
OPTIMIZE_STDIO;
solve(cin, cout);
return 0;
}
#endif | #include<bits/stdc++.h>
using namespace std;
long long int a[100000000],n,m=0;
int main()
{
cin>>n;
cin>>a[1];
for (int i=2;i<=n;i++)
{
cin>>a[i];
if (a[i]<a[i-1])
{
m=a[i-1]-a[i]+m;
a[i]=a[i-1];
}
}
cout<<m;
return 0;
} | 1 | 22,768,045 |
#include <bits/stdc++.h>
using namespace std;
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
uint R; cin >> R;
if (R<1200){ cout << "ABC" << endl;
}else if(R<2800){ cout << "ARC" << endl;
}else { cout << "AGC" << endl; }
return 0;
} | #include<bits/stdc++.h>
using namespace std;
int main()
{
int r;
cin>>r;
if(r<1200)
cout<<"ABC";
else if(r>=1200 && r<2800)
cout<<"ARC";
else if(r>=2800 && r<=4208)
cout<<"AGC";
} | 1 | 21,424,963 |
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};
ll dp[1002][10002];
void solve() {
int h, n;
cin >> h >> n;
vector<ll> a(n), b(n);
rep(i,n) cin >> a[i] >> b[i];
for (int i = n; i >= 0; i--) {
for (int j = 0; j <= h; j++) {
if (j == 0) dp[i][j] = 0;
else if (i == n) {
dp[i][j] = INF;
} else {
dp[i][j] = min(dp[i][max(0ll, j - a[i])] + b[i], dp[i + 1][j]);
}
}
}
cout << dp[0][h] << endl;
}
int main() {
solve();
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
int main() {
int h, n;
cin >> h >> n;
int a[n], b[n];
int mx = 0;
for ( int i = 0; i < n; i++ ) {
cin >> a[i] >> b[i];
mx = max(mx, a[i]);
}
vector<int> dp(h+mx+1, INF);
dp[0] = 0;
for ( int i = 0; i < h+mx; i++ ) {
for ( int k = 0; k < n; k++ ) {
int tmp = dp[i] + b[k];
int pos = i + a[k];
if ( pos <= h+mx ) {
dp[pos] = min(tmp, dp[pos]);
}
}
}
int ans = INF;
for ( int i = h; i <= h+mx; i++ ) {
ans = min(dp[i], ans);
}
cout << ans << endl;
return 0;
} | 1 | 94,220,021 |
#include <iostream>
using namespace std;
long long int n,a[5000];
int main(){
long long int i,j,t,tmp;
while(cin >> n && n){
tmp = 0;
t = -1000000;
for(i=0;i<n;i++){
cin >> a[i];
}
for(i=0;i<n;i++){
tmp += a[i];
if(t < tmp) t = tmp;
for(j=i+1;j<n;j++){
tmp += a[j];
if(t < tmp) t = tmp;
}
tmp = 0;
}
cout << t << endl;
}
return 0;
} | #include <iostream>
#include <algorithm>
using namespace std;
int main() {
int N;
while (cin >> N) {
if (N == 0) break;
int num[5000];
for (int i = 0; i < N; i++) {
cin >> num[i];
}
int m = num[0];
for (int i = 0; i < N; i++) {
int sum = 0;
for (int j = i; j < N; j++) {
sum += num[j];
m = max(m, sum);
}
}
cout << m << endl;
}
return 0;
} | 1 | 53,787,413 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define rep(i, n) REP(i, 0, n)
#define REP(i, x, n) for(int i = x; i < n; i++)
#define FOREACH(x, a) for(auto &(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define COUT(x) cout << (x) << endl
template <class T> inline bool chmax(T &a, T b) {
if(a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if(a > b) {
a = b;
return 1;
}
return 0;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int S, W;
cin >> S >> W;
if(W >= S)
COUT("unsafe");
else
COUT("safe");
} | #include <bits/stdc++.h>
using namespace std;
int main()
{
int s, w;
cin >> s >> w;
if (w >= s)
{
printf("unsafe");
}
else
{
printf("safe");
}
return 0;
} | 1 | 91,696,257 |
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mk make_pair
#define pb push_back
#define pf push_front
typedef pair<int, int> pii;
const int mod = 1000000007;
const int INF = 1000000009;
const long long INFL = 1000000000000000018ll;
int N;
int d[100100];
deque<int> dque;
signed main()
{
cin >> N;
for(int i = 0; i < N; i++){
d[i] = INF;
}
d[1] = 1;
dque.pf(1);
while(dque.size()){
int cur = dque.front();
dque.pop_front();
int nxt = cur * 10 % N;
if(d[nxt] > d[cur]){
d[nxt] = d[cur];
dque.pf(nxt);
}
nxt = (cur + 1) % N;
if(d[nxt] > d[cur] + 1){
d[nxt] = d[cur] + 1;
dque.pb(nxt);
}
}
cout << d[0] << endl;
return 0;
} | #include <bits/stdc++.h>
#define INF 1e7
using namespace std;
const int maxn = 100005;
int main()
{
int dist[maxn],k,temp,mul_ten,plus_one,ans;
deque<int> q;
scanf("%d",&k);
for (int i=0;i<maxn;i++) dist[i]=INF;
dist[1]=0;
q.push_front(1);
while (!q.empty())
{
temp=q.front();
q.pop_front();
mul_ten=(temp*10)%k;
plus_one=(temp+1)%k;
if (dist[temp]<dist[mul_ten])
{
q.push_front(mul_ten);
dist[mul_ten]=dist[temp];
}
if (dist[temp]+1<dist[plus_one])
{
q.push_back(plus_one);
dist[plus_one]=dist[temp]+1;
}
}
ans=dist[0]+1;
printf("%d",ans);
return 0;
} | 1 | 30,005,738 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int rate,goal;
cin >> rate >> goal;
cout << 2*goal - rate;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int R;
int G;
cin >> R;
cin >> G;
cout << 2*G-R<< endl;
} | 1 | 55,303,063 |
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
#include <array>
#include <numeric>
#include <regex>
#include <bitset>
#include <deque>
using namespace std;
typedef long long ll;
typedef pair<int, int> p_ii;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
const int INF = 1e9;
const double PI = acos(-1.0);
const ll MOD = 1e9 + 7;
int main() {
int h, w;
cin >> h >> w;
string str[26][26];
rep(i, h)rep(j, w)cin >> str[i][j];
rep(i, h)rep(j, w) {
if (str[i][j] == "snuke") {
cout << (char)(j + 'A') << i + 1 << endl;
return 0;
}
}
return 0;
} | #include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>
#ifndef UTIL_HPP
#define UTIL_HPP
typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;
namespace tools {
template <typename T>
void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
vector.reserve(size);
::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
}
template <typename T>
void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
::tools::read(::std::cin, vector, size);
}
template <typename T, ::std::size_t N>
void read(::std::istream& is, ::std::array<T, N>& array) {
::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
}
template <typename T, ::std::size_t N>
void read(::std::array<T, N>& array) {
::tools::read(::std::cin, array);
}
}
#endif
const std::string A_to_Z = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main() {
i64 H, W;
std::cin >> H >> W;
std::vector<std::vector<std::string>> S(H, std::vector<std::string>(W));
for (i64 y = 0; y < H; ++y) {
for (i64 x = 0; x < W; ++x) {
std::cin >> S[y][x];
}
}
for (i64 y = 0; y < H; ++y) {
for (i64 x = 0; x < W; ++x) {
if (S[y][x] == "snuke") {
std::cout << A_to_Z[x] << (y + 1) << std::endl;
return 0;
}
}
}
return EXIT_FAILURE;
} | 1 | 83,487,893 |
#include <iostream>
using namespace std;
long long max(long long x,long long y){
if(x > y){
return x;
}else{
return y;
}
}
int main(){
while(1){
int n,k;
long long array[100001]={};
long long total[100001]={};
cin >> n >> k;
if(n == 0 && k == 0)break;
for(int i=0;i<n;i++){
cin >> array[i];
}
long long x=0;
for(int i=0;i<k;i++){
x += array[i];
}
total[0] = x;
for(int i=1;i<=n-k;i++){
total[i] = total[i-1] - array[i-1] + array[i+k - 1];
}
long long answer = -10000000000;
for(int i=0;i<100001;i++){
answer = max(answer,total[i]);
}
cout << answer << endl;
}
return 0;
} | #include<iostream>
using namespace std;
int main(){
int n,k,data[100000],sum,max;
while(1){
cin >> n >> k;
sum = 0;
max = -10000000;
if(n == 0&&k == 0)break;
for(int i = 0; i < n;i++)
cin >> data[i];
for(int i = 0;i < k;i++)
sum += data[i];
if(sum > max) max = sum;
for(int i = 0; i < n-k;i++){
sum = sum-data[i]+data[i+k];
if(sum > max)
max = sum;
}
cout << max <<endl;
}
return 0;
} | 1 | 58,856,309 |
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
using namespace std;
int main() {
int h,w; cin >> h >> w;
char s[51][51];
int f = true;
int fb = false;
rep(i,h){
rep(j,w){
cin >> s[i][j];
}
}
rep(i,h){
rep(j,w){
fb = false;
if(s[i][j] == '#') {
if (i != 0 && s[i - 1][j] == '#') fb = true;
if (i != h - 1 && s[i + 1][j] == '#') fb = true;
if (j != 0 && s[i][j - 1] == '#') fb = true;
if (j != w - 1 && s[i][j + 1] == '#') fb = true;
if (!fb) {
f = false;
break;
}
}
}
}
cout << ((f)?"Yes":"No");
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const long long INF = 1LL << 60;
const ll MOD = 1000000007;
using pint = pair<ll, ll>;
const ll dx[4] = {1, 0, -1, 0};
const ll dy[4] = {0, 1, 0, -1};
int main() {
ll H, W;
cin >> H >> W;
vector<string> s(H);
bool check = true;
for (int i = 0; i < H; i++) cin >> s[i];
for (int i = 0; i<H; i++){
for(int j=0; j<W; j++){
if (s[i][j] == '.') continue;
bool next = false;
for (int idx = 0; idx < 4; idx++) {
ll next_x = j + dx[idx];
ll next_y = i + dy[idx];
if (next_y < 0 || next_y >= H || next_x < 0 || next_x >= W) continue;
if (s[i][j] == s[next_y][next_x] && s[i][j] == '#') {
next = true;
}
}
if (!next) check = false;
}
}
if (check) cout << "Yes" << endl;
else cout << "No" << endl;
return 0;
} | 1 | 32,434,486 |
#include <bits/stdc++.h>
#define int long long
#define endl "\n"
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define VVi vector<Vi>
#define Vs vector<string>
#define Pii pair<int,int>
#define VPii vector<Pii>
#define Tiii tuple<int,int,int>
#define PQi priority_queue<int>
#define PQir priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define itos to_string
#define stoi stoll
#define FI first
#define SE second
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define sortr(v) sort(v,greater<>())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define dem(a,b) ((a+b-1)/(b))
#define Vin(a) rep(iI,0,a.size())cin>>a[iI]
#define Vout(a) rep(lZ,0,a.size()-1)cout<<a[lZ]<<' ';cout<<a.back()<<endl
#define VVout(a) rep(lY,0,a.size()){Vout(a[lY]);}
#define VPout(a) rep(lX,0,a.size())cout<<a[lX].FI<<' '<<a[lX].SE<<endl
#define INF 3000000000000000000
#define MAX LLONG_MAX
#define MOD 1000000007
using namespace std;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
void uniq(Vi &v){sort(ALL(v)); v.erase(unique(ALL(v)),v.end());}
int mypow(int x, int n, int m){
if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}
signed main() {
cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(12);
string s;
cin >> s;
int l = s.size();
int ans = l*(l-1)/2;
Vi a(26);
rep(i,0,l){
a[s[i]-'a']++;
}
rep(i,0,26){
if(a[i]!=0){
ans -= a[i]*(a[i]-1)/2;
}
}
cout << ans+1 << endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define num 1000000007
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define inarr(i,a,n,A) for(ll i=a;i<n;i++) { cin>>A[i]; }
#define vll vector<long long>
#define pii pair <int,int>
#define pll pair<long long, long long>
#define vpii vector< pair <int,int>>
#define vpll vector< pair<long long, long long>>
#define max3(a,b,c) ((a>b)?(a>c)?a:c:(b>c)?b:c)
#define min3(a,b,c) ((a<b)?(a<c)?a:c:(b<c)?b:c)
#define avg(a,b) ((a)+(b))/2
#define pb push_back
#define pob pop_back
#define sf int flag=0
#define f first
#define s second
#define fix(f,n) std::fixed<<std::setprecision(n)<<f
#define all(x) x.begin(), x.end()
#define M_PI 3.14159265358979323846
#define epsilon (double)(0.00000000001)
#define side 1e9
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
ll mod(ll a, ll b)
{
if(a%b<0)
{
return a%b + b;
}
return a%b;
}
ll mod_exp(ll a, ll b, ll c)
{
ll res=1;
a=a%c;
while(b>0)
{
if(b%2==1)
{
res=(res*a)%c;
}
b/=2;
a=(a*a)%c;
}
return res;
}
ll mymod(ll a,ll b)
{
return ((a%b)+b)%b;
}
bool prime[200001];
void SieveOfEratosthenes()
{
memset(prime, true, sizeof(prime));
prime[1]=false;
for (int p=2; p*p<=200000; p++)
{
if (prime[p] == true)
{
for (int i=p*p; i<=200000; i += p)
prime[i] = false;
}
}
return;
}
ll powe[200005];
void power()
{
powe[0]=1;
REP(i,1,200005)
{
powe[i]=mymod(2*powe[i-1],num);
}
}
ll gcdExtended(ll,ll,ll *,ll *);
ll modInverse(ll a, ll m)
{
ll x, y;
ll g = gcdExtended(a, m, &x, &y);
ll res = (x%m + m) % m;
return res;
}
ll gcdExtended(ll a, ll b, ll *x, ll *y)
{
if (a == 0)
{
*x = 0, *y = 1;
return b;
}
ll x1, y1;
ll gcd = gcdExtended(b%a, a, &x1, &y1);
*x = y1 - (b/a) * x1;
*y = x1;
return gcd;
}
struct node
{
vll adj;
ll indegree;
};
ll find(ll n, ll wt, ll nm)
{
ll st = 1;
ll en = nm;
ll mid = (st) + (en - st)/2;
while(st<=en)
{
if(wt+3*(nm+mid)>=n && wt+2*(nm+mid)<=n)
{
return mid;
}
else if(wt+3*(nm+mid)<n)
{
st = mid+1;
}
else
{
en = mid-1;
}
mid = (st) + (en - st)/2;
}
if(wt+3*(nm+mid)>=n && wt+2*(nm+mid)<=n)
{
return mid;
}
return 0;
}
bool my(pair<ll, char> p1, pair<ll, char> p2)
{
return p1.first > p2.first;
}
struct segment
{
ll l,r,v;
};
bool my(segment a, segment b)
{
return a.l<b.l;
}
ll convert(string s)
{
ll n = 0;
REP(i,0,s.size())
{
if(!(n>>(s[i]-97)&1))
{
n+=(1<<(s[i]-97));
}
}
return n;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string s;
cin>>s;
ll n = s.size();
ll ans = (n*(n+1))/2;
ll count[26]={0};
for(ll i=n-1; i>=0; i--)
{
count[s[i]-97]++;
ans-=count[s[i]-97];
}
cout<<ans+1<<"\n";
return 0;
} | 1 | 7,781,850 |
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
int main() {
int N, A;
cin >> N >> A;
cout << (N * N - A) << endl;
} | #include<stdio.h>
#include<string.h>
#include<cmath>
#include<iostream>
#include<iomanip>
using namespace std;
typedef long long LL;
typedef double db;
double pp[2500001];
int main()
{
int n, m;
cin >> n;
cin >> m;
cout << n * n - m << endl;
} | 1 | 21,654,151 |
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll = long long;
int main() {
int N;
cin >> N;
ll Nsum = 0;
rep(i, N + 1) Nsum += i;
vector<ll> A(N + 1);
ll Asum = 0;
rep(i, N) {
cin >> A[i];
Asum += A[i];
}
A[N] = A[0];
if (Asum % Nsum != 0) {
cout << "NO" << endl;
return 0;
}
ll n = Asum / Nsum;
ll s = 0;
rep(i, N) {
ll d = A[i + 1] - A[i];
if ((n - d) % N != 0 || n - d < 0) {
cout << "NO" << endl;
return 0;
}
s += (n - d) / N;
}
if (s == n) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
typedef int_fast32_t int32;
typedef int_fast64_t int64;
const int32 inf = 1e9+7;
const int32 MOD = 1000000007;
const int64 llinf = 1e18;
#define YES(n) cout << ((n) ? "YES\n" : "NO\n" )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n" )
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n" )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define all(obj) (obj).begin(),(obj).end()
#define rall(obj) (obj).rbegin(),(obj).rend()
#define fi first
#define se second
#define pb(a) push_back(a)
typedef pair<int32,int32> pii;
typedef pair<int64,int64> pll;
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;
}
int64 sum(int32 x){
return (int64)(1+x) * x / 2;
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int32 n;
cin >> n;
vector<int32> a(n);
int64 asum = 0;
REP(i,n){
cin >> a[i];
asum += a[i];
}
if(asum % sum(n) != 0){
YES(false);
return 0;
}
int64 m = asum / sum(n);
vector<int32> d(n);
REP(i,n)d[i] = a[(i+1)%n] - a[i];
REP(i,n)d[i] -= m;
bool flg = true;
REP(i,n){
if(d[i] > 0 || d[i] % n)flg = false;
}
YES(flg);
return 0;
} | 1 | 3,329,829 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ios_base::sync_with_stdio(0);
int n;
cin>>n;
cout<<(n-2)*180<<endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
typedef long long ll;
typedef pair<ll,ll> pll;
int main(int argc, char const *argv[])
{
ll a;
cin >> a;
cout << 180*(a-2) << endl;
return 0;
} | 1 | 70,294,110 |
#include <iostream>
using namespace std;
int main()
{
string s;
cin >> s;
int t = s.size();
while(t > 1){
t -= 2;
if(s.substr(0, t/2) == s.substr(t/2, t/2)) break;
}
cout << t << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const long long INF = 1e18;
# define len(x) ((int)(x).size())
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define foreps(i, m, n) for(int i = m;i < n;i++)
# define ALL(x) (x).begin(), (x).end()
# define rall(x) (x).rbegin(), (x).rend()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int ssChecker(string &S) {
int cnt = 0;
while (true) {
S.pop_back();
if (len(S) % 2 != 0) continue;
string st = S.substr(0, len(S) / 2);
string str = S.substr(len(S) / 2);
if (st == str) {
return len(st) + len(str);
}
}
}
int main() {
string S; cin >> S;
cout << ssChecker(S) << endl;
} | 1 | 52,352,526 |
#include "bits/stdc++.h"
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<VVLL> VVVLL;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
#define SORT_ASC(c) sort((c).begin(), (c).end())
#define SORT_DESC(c) sort((c).begin(), (c).end(), greater<typeof((c).begin())>())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define FORL(i,a,b) for(LL i=(a);i<(b);++i)
#define REPL(i,n) FORL(i,0,n)
#define SIZE(a) int((a).size())
#define ALL(a) (a).begin(),(a).end()
const double EPS = 1e-10;
const double PI = acos(-1.0);
template<typename T>
void vprint(vector<T> v) {
for(auto x : v) {
cerr << x << " ";
}
cerr << endl;
}
template<typename T>
void vvprint(vector<vector<T>> vv) {
REP(i, SIZE(vv)) {
REP(j, SIZE(vv[i])) {
cerr << vv[i][j] << " ";
}
cerr << endl;
}
}
template<typename T1, typename T2>
void vpprint(vector<pair<T1, T2>> vp) {
REP(i, SIZE(vp)) {
cerr << vp[i].first << ", " << vp[i].second << endl;
}
}
template<typename T1, typename T2>
void mprint(map<T1, T2> m) {
for(auto x : m) cerr << x.first << ", " << x.second << endl;
}
template <typename Iterator>
inline bool next_combination(const Iterator first, Iterator k, const Iterator last)
{
if ((first == last) || (first == k) || (last == k))
return false;
Iterator itr1 = first;
Iterator itr2 = last;
++itr1;
if (last == itr1)
return false;
itr1 = last;
--itr1;
itr1 = k;
--itr2;
while (first != itr1)
{
if (*--itr1 < *itr2)
{
Iterator j = k;
while (!(*itr1 < *j)) ++j;
iter_swap(itr1,j);
++itr1;
++j;
itr2 = k;
rotate(itr1,j,last);
while (last != j)
{
++j;
++itr2;
}
rotate(k,itr2,last);
return true;
}
}
rotate(first,k,last);
return false;
}
inline double get_time_sec(void){
return static_cast<double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count())/1000000000;
}
template<typename T>
T gcd(T a, T b) {
if(a > b) swap(a, b);
if(a == 0) return b;
else return gcd(b%a, a);
}
template<typename T>
T lcm(T a, T b) {
return (a / gcd(a, b)) * b;
}
template<typename T>
map<T, T> prime_list(T n) {
map<T, T> ret;
for(T i = 2; i*i <= n; i++) {
if(n % i == 0) {
ret[i] = 0;
while(n % i == 0) {
n /= i;
ret[i]++;
}
}
}
if(n != 1) ret[n]++;
return ret;
}
#define MOD 1000000007
LL mypow(LL a, LL n) {
if(n == 0) return 1;
if(n == 1) return a % MOD;
if(n % 2 == 1) return (a * mypow(a, n-1)) % MOD;
LL t = mypow(a, n/2);
return (t * t) % MOD;
}
#define FACT_SZ 100010
VLL _fact, _inv;
bool _fact_flg = true;
void _fact_init() {
_fact = VLL(FACT_SZ);
_inv = VLL(FACT_SZ);
_fact[0] = 1;
FOR(i, 1, FACT_SZ) _fact[i] = (_fact[i-1] * i) % MOD;
_inv[FACT_SZ-1] = mypow(_fact[FACT_SZ-1], MOD - 2);
for(int i = FACT_SZ - 2; i >= 0; i--) {
_inv[i] = ((i + 1) * _inv[i + 1]) % MOD;
}
}
LL mycomb(LL n, LL k) {
if(_fact_flg) {
_fact_flg = false;
_fact_init();
}
if(n < k) return 0;
return (((_fact[n] * _inv[k]) % MOD) * _inv[n-k]) % MOD;
}
VLL par, rnk, sz;
int root(int x) {
if(par[x] == x) return x;
else return par[x] = root(par[x]);
}
bool same(int x, int y) {
x = root(x);
y = root(y);
return x == y;
}
void unite(int x, int y) {
x = root(x);
y = root(y);
if(rnk[x] < rnk[y]) {
par[x] = y;
} else {
par[y] = x;
if(rnk[x] == rnk[y]) rnk[x]++;
}
}
#define INF 1e15
int main(void) {
int n;
string s;
cin >> n >> s;
int minl = 0;
VI level(n+1, 0);
REP(i, n) {
level[i+1] = level[i] + (s[i] == '(' ? 1 : -1);
minl = min(minl, level[i+1]);
}
REP(i, level[0] - minl) cout << '(';
cout << s;
REP(i, level[n] - minl) cout << ')';
cerr << endl;
} | #include <bits/stdc++.h>
using namespace std;
void solve(long long N, std::string S){
int pointer = 0;
int need_left = 0;
for(int i = 0; i < S.size(); ++i){
if(S[i] == '(') pointer++;
else
{
if(pointer == 0) need_left++;
else pointer--;
}
}
int need_right = pointer;
string res = "";
for(int i = 0; i < need_left; ++i) res += '(';
res += S;
for(int i = 0; i < need_right; ++i) res += ')';
cout << res << endl;
}
int main(){
long long N;
scanf("%lld",&N);
std::string S;
std::cin >> S;
solve(N, S);
return 0;
} | 1 | 22,723,193 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
string S;
cin >> S;
bool isRotated = false;
if (N % 2 == 1) {
cout << "No" << endl;
return 0;
} else {
for (int i = 0; i < N / 2; i++) {
if (S.at(i) != S.at(N / 2 + i)) {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
}
} | #include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string s;
cin >> n >> s;
int test = 0;
for(int i=0; i<n/2; i++){
if(s[i]!=s[i+(n/2)]){
test = 1;
break;}
}
if(test==0 && n%2==0) cout << "Yes" << endl;
else cout << "No" << endl;
return 0;
} | 1 | 22,413,666 |
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s;
cin>>s;
int sum =0;
for(int i=0;i<s.length();i++)
{
sum = (sum%9+(s[i]-'0'))%9;
}
if(sum%9 == 0) cout<<"Yes\n";
else cout<<"No\n";
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); i++)
using ll = long long;
int main() {
string n; cin >> n;
int ans = 0;
rep(i, n.size()) ans += n[i] - '0';
if(ans%9 == 0) cout << "Yes" << endl;
else cout << "No" << endl;
return 0;
} | 1 | 78,456,867 |
#include<bits/stdc++.h>
using namespace std;
#define int long long int
int32_t main()
{
int n;
cin>>n;
set<string>s ;
vector<string> v;
for(int i=0;i<n;i++)
{
string str;
cin>>str;
v.push_back(str);
s.insert(str);
}
if(s.size()!=n)
{
cout<<"No"<<endl;
exit(0);
}
for(int i=1;i<n;i++)
if(v[i-1][v[i-1].size()-1]!=v[i][0])
{
cout<<"No"<<endl;
return 0;
}
cout<<"Yes"<<endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
char next;
set<string> SE;
for (int i = 0; i < N; i++) {
string S;
cin >> S;
if (SE.count(S)>0){
cout << "No" << "\n";
return 0;
}
if (i>0 && S.front() != next){
cout << "No" << "\n";
return 0;
}
SE.insert(S);
next = S.back();
}
cout << "Yes" << "\n";
} | 1 | 74,306,470 |
#include <bits/stdc++.h>
using namespace std;
#define len(s) int(s.size())
#define res(x) cout<<((x)?"No\n":"Yes\n")
#define all(v) v.begin(),v.end()
typedef long long ll;
typedef long double ld;
ll mod = 1e9+7;
void solution() {
int a, b, c, k;
cin >> a >> b >> c >> k;
int ans = 0;
if(k > 0) {
ans = min(k, a);
k -= min(k, a);
}
if(k > 0) {
k -= min(k, b);
}
if(k > 0) {
ans -= min(k, c);
}
cout << ans << endl;
}
int main(){
int t = 1;
while(t--)
solution();
return 0;
} | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ll a,b,c,k;
cin>>a>>b>>c>>k;
if(a>=k)cout<<k<<endl;
else if(a+b>=k)cout<<a<<endl;
else{
ll s = k-(a+b);
cout<<a-s<<endl;
}
} | 1 | 5,132,028 |
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define rep(i, a, n) for (int i=(a); i<(n); i++)
#define per(i, a, n) for (int i=(a); i>(n); i--)
typedef long long ll;
const int maxn = 2e5+5;
const int mod = 1e9+7;
using namespace std;
ll p[maxn], c[maxn], sum[maxn];
vector<ll> v;
void solve() {
ll n,k,ans=-1e18; cin >> n >> k;
rep(i,1,n+1) cin >> p[i];
rep(i,1,n+1) cin >> c[i];
rep(i,1,n+1) {
ll t = p[i], cnt=1, res=c[i];
v.clear();
v.push_back(0); v.push_back(c[i]);
ans = max(ans, c[i]);
while(t != i && cnt < k) {
res += c[t];
ans = max(res, ans);
v.push_back(c[t]);
t = p[t];
cnt++;
}
ll mxi = 1;
rep(j,1,cnt+1) {
sum[j] = sum[j-1] + v[j];
if (sum[j] > sum[mxi]) {
mxi = j;
}
}
ll tmp = res;
if (k - cnt > 0) {
if (sum[cnt] > 0) {
res += sum[cnt]*((k-cnt)/cnt);
ans = max(ans, res);
rep(j,1,(k-cnt)%cnt+1) {
res += v[j];
ans = max(ans, res);
}
if ((k-cnt)%cnt==0) {
res = tmp + sum[cnt]*((k-cnt)/cnt-1);
ans = max(ans, res);
rep(j,1,cnt+1) {
res += v[j];
ans = max(ans, res);
}
}
}
res = tmp;
rep(j,1,min(cnt,k-cnt)+1) {
res += v[j];
ans = max(ans, res);
}
}
}
cout << ans << '\n';
}
int main(int argc, char * argv[])
{
#ifdef DEBUG
freopen("C:/Users/Fish_Brother/Desktop/in", "r", stdin);
#endif
solve();
return 0;
} | #include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define ALL(x) x.begin(), x.end()
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;
const int N = 100010, M = 1010;
int n, k;
int nxt[N], c[N];
int main()
{
cin >> n >> k;
for (int i = 1; i <= n; i ++ ) cin >> nxt[i];
for (int i = 1; i <= n; i ++ ) cin >> c[i];
LL res = -1e18;
for (int i = 1; i <= n; i ++ )
{
int cycle_cnt = 0, v = i;
LL cycle_sum = 0;
while (true)
{
cycle_cnt ++ ;
cycle_sum += c[v];
v = nxt[v];
if (v == i) break;
}
int cnt = 0;
LL sum = 0;
v = i;
while (true)
{
cnt ++ ;
sum += c[v];
if (cnt > k) break;
int num = (k - cnt) / cycle_cnt;
LL t = sum + max(0LL, cycle_sum) * num;
res = max(res, t);
v = nxt[v];
if (v == i) break;
}
}
cout << res << '\n';
return 0;
} | 1 | 82,828,082 |
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;
#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int H,W;
cin>>H>>W;
for(int y=0;y<H;y++){
for(int x=0;x<W;x++){
string s;
cin>>s;
if(s=="snuke"){
cout<<(char)(x+'A')<<y+1<<endl;
return 0;
}
}
}
return 0;
} | #include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
int main() {
int h, w;
cin >> h >> w;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
string name;
cin >> name;
if (name == "snuke") {
cout << char('A' + j) << (i + 1) << endl;
}
}
}
return 0;
} | 1 | 46,495,913 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a,b;
cin >> a >> b;
cout << (((a%3==0)||(b%3==0)||((a+b)%3==0))?"Possible":"Impossible") << endl;
} | #include<bits/stdc++.h>
using namespace std;
int main(void){
int A,B;
cin>>A>>B;
if(A%3==0||B%3==0||(A+B)%3==0){
cout<<"Possible"<<endl;
}else{
cout<<"Impossible"<<endl;
}
return 0;
} | 1 | 97,351,176 |
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;
#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll>
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a)
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b)
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}
string YN(bool v) { return v ? "Yes":"No"; }
#define INF (1LL<<60)
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll N;
string s, t;
while(cin>>N>>s>>t) {
ll ans=INF;
RANGE(l, N, N*2+1) {
ll ok=1;
string v(l, ' ');
REP(i, N) v[i]=s[i];
REP(i, N) if(v[l-N+i]!=' '&&v[l-N+i]!=t[i]) ok=0;
if(ok) minUpdate(ans, l);
}
cout<<ans<<endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int N;
cin >> N;
string s, t;
cin >> s >> t;
int ans = 2*N;
for(int i=1; i<=N; i++)
{
if(s.substr(N-i, i) == t.substr(0, i)) ans = 2*N-i;
}
cout << ans << endl;
return 0;
} | 1 | 20,402,976 |
#include <stdlib.h>
#include <string>
#include <iostream>
using namespace std;
class node{
public:
int data;
node *prev;
node *next;
node(){
prev = 0;
next = 0;
data = 0;
}
node(int data){
prev = 0;
next = 0;
this->data = data;
}
node(int data, node *next){
prev = 0;
this->next = next;
this->data = data;
} friend class double_linked_list;
};
class double_linked_list{
public:
node *first;
node *last;
double_linked_list(){
first = 0;
last = 0;
}
void insert_value(int data);
void delete_value(int data);
void delete_first();
void delete_last();
};
void double_linked_list::insert_value(int data){
if(first == 0){
node *new_first = new node(data);
first = new_first;
last = new_first;
}else{
node *new_first = new node(data, first);
first->prev = new_first;
first = new_first;
}
}
void double_linked_list::delete_value(int data){
node *current_node = first;
if(current_node == 0){
return;
}
if(current_node->data == data){
this->delete_first();
return;
}
current_node = current_node->next;
while(current_node != 0){
if(current_node->data == data){
if(current_node->next != 0){
current_node->prev->next = current_node->next;
current_node->next->prev = current_node->prev;
}else{
current_node->prev->next = 0;
last = current_node->prev;
}
return;
}
current_node = current_node->next;
}
}
void double_linked_list::delete_first(){
node *current_node = first;
if(current_node == 0){
return;
}
if(current_node->next != 0){
current_node->next->prev = 0;
first = current_node->next;
return;
}
first = 0;
last = 0;
return;
}
void double_linked_list::delete_last(){
if(this->last == 0){
return;
}
if(last->prev != 0){
last->prev->next = 0;
last = last->prev;
}else{
last = 0;
first = 0;
}
}
int main(){
int num;
cin >> num;
char command[12];
int value;
double_linked_list *result_list = new double_linked_list();
for(int i = 0; i < num; ++i){
cin >> command;
if(command[0] == 'i'){
cin >> value;
result_list->insert_value(value);
}else{
if(command[6] == '\0'){
cin >> value;
result_list->delete_value(value);
}
else if(command[6] == 'F'){
result_list->delete_first();
}
else if(command[6] == 'L'){
result_list->delete_last();
}
}
}
node *test = result_list->first;
while(test != 0){
cout << test->data;
if(test->next != 0){
cout << " ";
}
test = test->next;
}
cout << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
list<int> l;
int n;
cin >> n;
for(int i=0;i<n;i++){
string comm;
int x;
cin >> comm;
if(comm=="insert"){
cin >> x;
l.push_front(x);
}else if(comm=="delete"){
cin >> x;
for(auto it=l.begin();it!=l.end();it++){
if(*it==x){
l.erase(it);
break;
}
}
}else if(comm=="deleteFirst"){
l.pop_front();
}else{
l.pop_back();
}
}
for(auto it=l.begin();it!=l.end();it++){
if(it!=l.begin()) cout << ' ';
cout << *it;
}
cout << endl;
return 0;
} | 1 | 75,698,762 |
#include <algorithm>
#include <iostream>
#include <limits>
#include <stack>
#include <vector>
using namespace std;
using ll = long long;
template <typename T>
class LIS
{
struct Cache_LIS
{
typename vector<T>::iterator it;
T value;
};
int n;
T infty;
vector<T> dp;
stack<Cache_LIS> st;
public:
LIS() {}
LIS(int n, T infty = numeric_limits<T>::max()) : n{n}, infty{infty}, dp(n, infty) {}
T query(T a)
{
auto it{lower_bound(dp.begin(), dp.end(), a)};
auto value{*it};
st.push(Cache_LIS{it, value});
*it = a;
return lower_bound(dp.begin(), dp.end(), infty) - dp.begin();
}
bool rollback()
{
if (st.empty())
{
return false;
}
auto const &c{st.top()};
*c.it = c.value;
st.pop();
return true;
}
private:
};
#define PROBLEM "http:
int main()
{
int n;
cin >> n;
vector<int> a(n);
for (auto i{0}; i < n; ++i)
{
cin >> a[i];
}
LIS<int> lis(n);
for (auto i{0}; i < n - 1; ++i)
{
lis.query(a[i]);
}
cout << lis.query(a[n - 1]) << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
return firstElof.second < secondElof.second;
}
#define MAX_N 100100
#define MOD 998244353
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
ll dp[30][51000];
int main(){
ll n;
cin >> n;
ll a[n];
for (ll i=0;i<n;i++)cin >> a[i];
ll dp[n+1];
fill(dp,dp+n,INF);
for (ll i=0;i<n;i++){
*lower_bound(dp,dp+n,a[i])=a[i];
}
cout << lower_bound(dp,dp+n,INF)-dp << endl;
return 0;
} | 1 | 55,123,132 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<ll,ll> P;
#define pb push_back
#define ft first
#define sd second
#define mp make_pair
#define fr(i,n) for(int i=0;i<n;i++)
#define Fr(i,n) for(int i=0;i++<n;)
#define ifr(i,n) for(int i=n-1;i>=0;i--)
#define iFr(i,n) for(int i=n;i>0;i--)
ll hb(ll x){
ll l=-1,r=32,m;
while(r-l>1){
m=(l+r)/2;
if(x<(1<<m)) r=m;
else l=m;
}
return r;
}
int main(){
ll n,k,a,b,ka,k2,ans=0;
ll s[32]={};
vector<P> v[32];
cin>>n>>k;
fr(i,n){
cin>>a>>b;
ka=hb(a);
v[ka].pb(mp(a,b));
s[ka]+=b;
}
ifr(i,32){
if(i==0){ans=max(ans,s[0]);break;}
if(1-((k>>(i-1))&1)) continue;
ka=0;
fr(j,i) ka+=s[j];
ans=max(ans,ka);
ka=1<<(i-1);
fr(j,v[i].size()){
k2=hb(v[i][j].ft-ka);
v[k2].pb(mp(v[i][j].ft-ka,v[i][j].sd));
s[k2]+=v[i][j].sd;
}
}
cout<<ans<<endl;
} | #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
#define MOD 1000000007
typedef long long ll;
using namespace std;
int main(){
ll n,k;
cin>>n>>k;
ll a[n+1]={};
ll b[n+1]={};
ll ans=0;
for(int i=0;i<n;i++){
cin>>a[i]>>b[i];
if((a[i]|k)==k) ans+=b[i];
}
for(int i=30;i>=0;i--){
if(((1<<i)&k)==0) continue;
ll x=(k/(1<<i)-1)*(pow(2,i))+pow(2,i)-1;
ll tmp=0;
for(int i=0;i<n;i++){
if((a[i]|x)==x) tmp+=b[i];
}
ans=max(ans,tmp);
}
cout<<ans<<endl;
return 0;
} | 1 | 5,537,782 |
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<iomanip>
using namespace std;
int main(){
int n,k;
cin>>n>>k;
int a[n];
const long long INF=1LL<<60;
long long dp[n];
for(int i=0;i<n;i++)cin>>a[i];
for(int i=0;i<n;i++)dp[i]=INF;
dp[0]=0;
for(int i=0;i<n;i++){
for(int j=1;j<=k;j++){
if(i+j>=n)continue;
dp[i+j]=min(dp[i+j],dp[i]+abs(a[i]-a[i+j]));
}
}
cout<<dp[n-1]<<endl;
return 0;
} | #include<bits/stdc++.h>
#define int long long int
#define endl "\n"
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define mem(a,b) memset(a,b,sizeof(a))
#define loop(i,n) for(int i=0;i<(n);i++)
#define fors(a,b,i) for(int i=(a);i<=(b);i++)
#define ford(a,b,i) for(int i=(a);i>=(b);i--)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fastm_fast ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL)
using namespace std;
const int mod = 1e9 + 7;
#define pb push_back
#define mp make_pair
#define S second
#define F first
const int MAX = 1e5;
void sujho()
{
int n,k;
cin >> n >> k;
vector<int> v(n);
loop(i,n) cin >> v[i];
vector<int> dp(n+1,INT_MAX);
dp[0] = 0;
for(int i = 1; i < n; i++)
{
for(int j = 1; j <= k; j++)
{
if(i - j < 0 ) break;
dp[i] = min(dp[i] , dp[i-j] + abs(v[i] - v[i-j]));
}
}
cout<<dp[n-1]<<endl;
}
int32_t main()
{
fastm_fast;
{
sujho();
}
return 0;
} | 1 | 37,777,856 |
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
int main(){
int n;
cin >> n;
vector<pair<int,int>> gusu(100000);
vector<pair<int,int>> kisu(100000);
rep(i,0,100000){
gusu[i].second = i;
kisu[i].second = i;
}
rep(i,0,n){
int a;
cin >> a;
if(i%2==0){
gusu[a].first++;
}else{
kisu[a].first++;
}
}
sort(gusu.begin(),gusu.end());
reverse(gusu.begin(),gusu.end());
sort(kisu.begin(),kisu.end());
reverse(kisu.begin(),kisu.end());
if(gusu[0].second==kisu[0].second){
int M = max(gusu[1].first,kisu[1].first);
cout<<n-M-gusu[0].first<<endl;
}else{
cout<<n-gusu[0].first-kisu[0].first<<endl;
}
return 0;
} | #include <iostream>
#include <functional>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
using namespace std;
int n; vector<int> odd,even;
void input()
{
cin >> n;
for(int i=0; i<n/2; ++i){
int a,b; cin >> a >> b;
odd.emplace_back(a);
even.emplace_back(b);
}
}
bool pair_compare(pair<int,int> a, pair<int,int> b)
{
return a.first > b.first;
}
void solve()
{
map<int,int> Modd,Meven;
Modd[0]; Meven[0];
for(auto x: odd) Modd[x]++;
for(auto x: even) Meven[x]++;
vector<pair<int,int>> oddMap, evenMap;
for(auto m: Modd){
oddMap.emplace_back(make_pair(m.second,m.first));
}
sort(oddMap.begin(),oddMap.end(),pair_compare);
for(auto m: Meven){
evenMap.emplace_back(make_pair(m.second,m.first));
}
sort(evenMap.begin(),evenMap.end(),pair_compare);
if(oddMap[0].second == evenMap[0].second){
cout << min(n - oddMap[0].first - evenMap[1].first, n - oddMap[1].first - evenMap[0].first) << endl;
}
else cout << n - oddMap[0].first - evenMap[0].first << endl;
}
int main()
{
cin.tie();
ios::sync_with_stdio(false);
input();
solve();
return 0;
} | 1 | 6,106,585 |
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <assert.h>
#include <memory.h>
#include <queue>
#include <string.h>
using namespace std;
#define N 2003
#define mod 1000000007
int dp[N][N];
int add(int x,int y) {
int ret = x+y;
if(ret>=mod) {
ret -= mod;
}
if(ret<0) {
ret += mod;
}
return ret;
}
int s[N],t[N];
void solve() {
int n,m;scanf("%d %d",&n,&m);
for(int i=0;i<n;++i) scanf("%d ", &s[i]);
for(int i=0;i<m;++i) scanf("%d ", &t[i]);
for(int i=n-1;i>=0;--i) {
for(int j = m-1;j>=0;--j) {
int tmp = 0;
if(s[i]==t[j]) {
tmp = dp[i+1][j+1] + 1;
}
dp[i][j] = add(dp[i+1][j],dp[i][j+1]);
dp[i][j] = add(dp[i][j],-dp[i+1][j+1]);
dp[i][j] = add(dp[i][j],tmp);
}
}
int ret = add(dp[0][0],1);
printf("%d\n", ret);
}
int main() {
solve();
return 0;
} | #include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef multiset<ll> msll;
typedef set<ll> sll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef priority_queue<ll> pqll;
typedef vector<int> vi;
typedef set<int> si;
typedef multiset<int> msi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef set<pi> spi;
typedef priority_queue<int> pqi;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ind_set;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ind_setll;
#define in insert
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define be begin
#define en end
#define itr iterator
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mo 1000000007
#define inf 9223372036854775807
#define ninf -inf
#define ima 2147483647
#define imi -ima
#define oncnt __builtin_popcount
#define zerobegin __builtin_clz
#define zeroend __builtin_ctz
#define parity __builtin_parity
#define all(x) x.be(),x.en()
#define eps 1e-9
#define coutd cout<<setprecision(10)<<fixed
#define debg(x) cout<<"#x = "<<x<<"\n";
const ld PI=3.14159265359;
inline ll modpow(ll x,ll n){if(n==0)return 1;if(n==1)return(x%mo);ll u=(modpow(x,n/2));u=(u*u)%mo;if(n%2!=0)u=(u*x%mo)%mo;return u;}
inline ll modinv(ll x){return modpow(x,mo-2);}
inline ll mmul(ll a,ll b){ if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);}
inline ll madd(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a+b>=mo)return(a+b)%mo;return(a+b);}
inline ll msub(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;return(((a-b)%mo+mo)%mo);}
inline ll mdiv(ll a,ll bb){if(a>=mo)a=a%mo;ll b=modinv(bb);if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);}
inline ll gcd(ll a,ll b){return __gcd(a,b);}
ll dp[2001][2001];
int main()
{
io
int testcases=1;
while(testcases--)
{
int n,m;
cin>>n>>m;
int s[n];
int t[m];
for(int i=0;i<n;i++)
cin>>s[i];
for(int i=0;i<m;i++)
cin>>t[i];
for(int i=0;i<=n;i++)
{
for(int j=0;j<=m;j++)
dp[i][j]=0;
}
for(int i=0;i<=n;i++)
{
for(int j=0;j<=m;j++)
{
if(i==0||j==0)
dp[i][j]=1;
else
{
dp[i][j]=madd(dp[i][j],madd(dp[i-1][j],dp[i][j-1]));
if(s[i-1]!=t[j-1])
dp[i][j]=msub(dp[i][j],dp[i-1][j-1]);
}
}
}
cout<<dp[n][m];
}return 0;} | 1 | 76,493,966 |
#include <bits/stdc++.h>
#define rep(l, r) for (int i = (l); i < (r); i++)
typedef long long ll;
using namespace std;
int main() {
char c;
cin >> c;
switch (c) {
case 'a':
case 'i':
case 'u':
case 'e':
case 'o':
cout << "vowel" << endl;
break;
default:
cout << "consonant" << endl;
break;
}
return 0;
} | #include <algorithm>
#include <iostream>
#include <string>
using namespace std;
#define PI 3.14159265359
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
string str[5] = {"a", "e", "i", "o", "u"};
int main() {
string c;
cin >> c;
string ans = "consonant";
rep(i, 5) {
if (str[i] == c) ans = "vowel";
}
cout << ans << endl;
return 0;
} | 1 | 27,309,089 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout << fixed
#define endl '\n'
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
struct UnionFind {
vector<int> par;
UnionFind(int n) : par(n) {
REP(i, n) 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;
}
};
void solve(istream& cin, ostream& cout) {
int n, m;
cin >> n >> m;
vector<int> p(n);
REP(i, n) {
cin >> p[i];
p[i]--;
}
UnionFind uf(n);
REP(i, m) {
int x, y;
cin >> x >> y;
uf.unite(x - 1, y - 1);
}
int ans = 0;
REP(i, n) {
if (uf.same(i, p[i])) ans++;
}
cout << ans << endl;
}
#ifndef TEST
int main() {
OPTIMIZE_STDIO;
solve(cin, cout);
return 0;
}
#endif | #include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
struct UnionFind {
vector<int> par;
UnionFind(int n) : par(n, -1) {}
int root(int x) {
if (par[x] < 0) return x;
else return par[x] = root(par[x]);
}
bool same(int x, int y) {
return root(x) == root(y);
}
bool merge(int x, int y) {
x = root(x); y = root(y);
if (x == y) return false;
if (par[x] > par[y]) swap(x, y);
par[x] += par[y];
par[y] = x;
return true;
}
int size(int x) {
return -par[root(x)];
}
};
int main(){
ll n,m;cin >> n >>m;
vl v(n);
rep(i,n){
ll a;cin >> a;a--;
v[i]=a;
}
UnionFind uf(n);
rep(i,m){
ll a,b;cin >>a >>b;a--;b--;
uf.merge(a,b);
}
ll ans=0;
rep(i,n){
if(uf.same(v[i],i))ans++;
}
cout <<ans <<endl;
} | 1 | 81,443,558 |
#include<stdio.h>
#include<algorithm>
using namespace std;
int main(){
int a[5];
for(int i=0;i<5;i++){
scanf("%d",&a[i]);
}
sort(a,a+5);
printf("%d %d %d %d %d\n",a[4],a[3],a[2],a[1],a[0]);
return 0;
} | #include <iostream>
#include <algorithm>
int main()
{
int n[5] = {};
std::cin >> n[0] >> n[1] >> n[2] >> n[3] >> n[4];
std::sort(std::begin(n), std::end(n), [](int a, int b){return a > b;}) ;
std::cout << n[0] << " " << n[1] << " " << n[2] << " " << n[3] << " " << n[4] << std::endl;
return 0;
} | 1 | 73,083,136 |
#include<stdio.h>
#include<iostream>
using namespace std;
const static int MAX = 100000;
const static int NIL = -1;
typedef struct {
int parent;
int left;
int right;
} Node;
Node T[MAX];
int D[MAX];
void printChildren(int u) {
int c = T[u].left;
int i = 0;
printf("[");
while (c != NIL) {
if (i > 0) printf(", ");
i++;
printf("%d", c);
c = T[c].right;
}
printf("]");
}
void setDepth(int u, int p) {
D[u] = p;
if (T[u].left != NIL) {
setDepth(T[u].left, p + 1);
}
if (T[u].right != NIL) {
setDepth(T[u].right, p);
}
}
int main() {
int n, id, m, node1, node2, root;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
T[i].parent = NIL;
T[i].left = NIL;
T[i].right = NIL;
}
for (int i = 0; i < n; i++) {
scanf("%d", &id);
scanf("%d", &m);
node1 = NIL;
for (int j = 0; j < m; j++) {
scanf("%d", &node2);
if (T[id].left == NIL) {
T[id].left = node2;
}
T[node2].parent = id;
if (node1 != NIL)
T[node1].right = node2;
node1 = node2;
}
}
for (int i = 0; i < n; i++) {
if (T[i].parent == NIL) {
root = i;
break;
}
}
setDepth(root, 0);
for (int i = 0; i < n; i++) {
printf("node %d: parent = %d, depth = %d, ", i, T[i].parent, D[i]);
if (T[i].parent == NIL) printf("root, ");
else if (T[i].left == NIL) printf("leaf, ");
else printf("internal node, ");
printChildren(i);
printf("\n");
}
return 0;
} | #include <algorithm>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <queue>
#include <string>
#include <set>
#include <vector>
#define FOR(i, l, r) for (i = (l); i < r; i++ )
using namespace std;
typedef long long ll;
#define MAX_N (100010)
#define NIL (-1)
typedef struct {
int par;
int l_c;
int r_s;
int dep;
} Node;
Node tree[MAX_N];
int get_depth( int id ) {
if ( id == NIL ) return -1;
if ( tree[id].dep != -1 ) return tree[id].dep;
else {
int r_s = tree[id].r_s;
tree[id].dep = 1 + get_depth( tree[id].par );
while ( r_s != NIL ) {
tree[r_s].dep = tree[id].dep;
r_s = tree[r_s].r_s;
}
return tree[id].dep;
}
}
void output( int id ) {
char type[100];
vector<int> children;
int cur_chi = tree[id].l_c;
if ( tree[id].par == NIL ) sprintf( type, "root" );
else if ( tree[id].l_c == NIL ) sprintf( type, "leaf" );
else sprintf( type, "internal node" );
while ( cur_chi != NIL ) {
children.push_back( cur_chi );
cur_chi = tree[cur_chi].r_s;
}
printf("node %d: ", id);
printf("parent = %d, ", tree[id].par );
printf("depth = %d, ", tree[id].dep );
printf("%s, ", type );
printf("[");
for ( int i = 0; i < children.size(); i++ ) {
printf("%d", children[i]);
if ( i < children.size() - 1 ) printf(", ");
}
printf("]\n");
return;
}
int main()
{
int n;
scanf("%d", &n);
for ( int i = 0; i < n; i++ ) {
tree[i].par = tree[i].l_c = tree[i].r_s = NIL;
tree[i].dep = -1;
}
for ( int i = 0; i < n; i++ ) {
int id;
int k;
int pre_chi = NIL;
scanf("%d %d", &id, &k);
for ( int j = 0; j < k; j++ ) {
int chi;
scanf("%d", &chi);
tree[chi].par = id;
if ( j == 0 ) {
tree[id].l_c = chi;
}
else if ( j < k ) {
tree[pre_chi].r_s = chi;
}
pre_chi = chi;
}
}
int root = NIL;
{
int cur = 0;
while ( true ) {
if ( tree[cur].par == NIL ) {
root = cur;
break;
}
cur = tree[cur].par;
}
}
for ( int i = 0; i < n; i++ ) {
if ( tree[i].dep == -1 ) get_depth( i );
}
for ( int i = 0; i < n; i++ ) {
output(i);
}
return 0;
} | 1 | 67,033,795 |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
const int N = 1e6 + 10, OO = 0x3f3f3f3f, mod = 1e9 + 7;
#define PI acos(-1)
#define clr(arr, val) memset(arr, val, sizeof(arr))
#define loop(i, n) for (int i = 0; i < int(n); i++)
#define rloop(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define xloop(i, a, b) for (int i = int(a); i <= int(b); i++)
#define ALL(v) ((v).begin()), ((v).end())
#define SZ(v) ((int)((v).size()))
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int n, total;
int main()
{
string s, t;
cin >> s >> t;
sort(ALL(s));
sort(ALL(t));
reverse(ALL(t));
if(s < t)
cout << "Yes\n";
else
cout << "No\n";
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
string s,t;
cin >> s >> t;
sort(s.begin(),s.end());
sort(t.begin(),t.end());
reverse(t.begin(),t.end());
string ans="No";
if(s<t){
ans="Yes";
}
cout << ans;
} | 1 | 65,527,196 |
#include <iostream>
using namespace std;
int main (void) {
int a, b, c, d, ttl;
cin >> a >> b >> c >> d;
if (a < b) {
ttl += a;
} else {
ttl += b;
}
if (c < d) {
ttl += c;
} else {
ttl += d;
}
int ans = ttl;
cout << ans << endl;
} | #include <iostream>
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int A, B, C, D; cin >> A >> B >> C >> D;
cout << min(A, B) + min(C, D) << "\n";
} | 1 | 35,914,807 |
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7;
ll q_pow(ll a, ll b) {
ll res = 1;
while(b>0) {
if(b&1) (res*=a)%=MOD;
(a*=a)%=MOD;
b>>=1;
}
return res;
}
int main() {
ll x,y; cin>>x>>y;
ll ans;
if((x+y)%3!=0) ans=0;
else {
if(max(x,y)>min(x,y)*2) ans=0;
else {
int numMove = (x+y)/3;
int numMove12 = 2*numMove-x;
ll fac=1;
vector<ll> inv(numMove+1);
for(int i=1; i<=numMove; i++) (fac*=i)%=MOD;
inv[numMove]=q_pow(fac,MOD-2);
for(int i=numMove-1; i>=0; i--) inv[i]=inv[i+1]*(i+1)%MOD;
ans = (fac*inv[numMove-numMove12])%MOD*inv[numMove12]%MOD;
}
}
cout << ans << endl;
} | #include<bits/stdc++.h>
#define rep(i,n) for(ll i = 0;i < n;++i)
using namespace std;
using ll = long long;
const ll M = 1e9+7;
ll mpow(ll x,ll y){
ll ans = 1;
while(y != 0){
if(y&1){
ans = ans * x % M;
}
x = x * x % M;
y = y >> 1;
}
return ans % M;
}
ll comb(ll n,ll k){
ll a=1,b=1,c=1;
if(n == 0 && k == 0) return 1;
if(n < k|| n < 0) return 0;
for(ll i = 1;i <= n;++i){
a = a * i % M;
}
for(ll i = 1;i <= k;++i){
b = b * i % M;
}
for(ll i = 1;i <= (n-k);++i){
c = c * i % M;
}
b = mpow(b,M-2);
c = mpow(c,M-2);
return (a * b) % M * c % M;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
ll x, y;
cin >> x >> y;
ll n = (x+y) / 3;
if((x+y)%3 != 0){
cout << 0 << endl;
return 0;
}
x -= n;
y -= n;
if(x < 0 || y < 0) {
cout << 0 << endl;
return 0;
}
ll ans = comb(x+y,y)%M;
cout << ans << endl;
cout << endl;
return 0;
} | 1 | 70,952,449 |
#include <iostream>
using namespace std;
int main(){
string s;
cin >> s;
if(s=="abc"||s=="acb"||s=="bac"||s=="bca"||s=="cab"||s=="cba") cout << "Yes" << "\
\n";
else cout << "No" << "\n";
return 0;
} | #include <iostream>
#include <algorithm>
#include <iomanip>
using namespace std;
string alphabet = "abcdefghijklmnopqrstuvwxyz";
string ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main(){
string s;
cin >> s;
if(s[0] != s[1] && s[1] != s[2] && s[0] != s[2])cout << "Yes" << endl;
else cout << "No" << endl;
} | 1 | 18,544,801 |
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;
#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define rep(i,N) for(int i=0;i<N;i++)
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int K;
cin>>K;
vector<int>A(K);
for(int i=0;i<K;i++)cin>>A[i];
ll r=pow(10,15);
ll l=-1;
ll m;
while(r-l>1){
m=(r+l)/2;
vector<ll>dp(K+1);
dp[0]=m;
for(int i=1;i<=K;i++)dp[i]=(dp[i-1]/A[i-1])*A[i-1];
if(dp[K]<2)l=m;
else r=m;
}
ll down=r;
r=pow(10,15);
l=-1;
m;
while(r-l>1){
m=(r+l)/2;
vector<ll>dp(K+1);
dp[0]=m;
for(int i=1;i<=K;i++)dp[i]=(dp[i-1]/A[i-1])*A[i-1];
if(dp[K]<=2)l=m;
else r=m;
}
ll up=l;
bool ok=true;
vector<ll>dp(K+1);
dp[0]=down;
for(int i=1;i<=K;i++)dp[i]=(dp[i-1]/A[i-1])*A[i-1];
if(dp[K]!=2)ok=false;
dp[0]=up;
for(int i=1;i<=K;i++)dp[i]=(dp[i-1]/A[i-1])*A[i-1];
if(dp[K]!=2)ok=false;
if(ok)cout<<down<<" "<<up<<endl;
else cout<<-1<<endl;
return 0;
} | #pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
#define int long long
#define F first
#define S second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
void accell() {
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
}
int get(int x, vector<int>&a) {
for (int i = 0; i < a.size(); ++i) {
x = x / a[i] * a[i];
}
return x;
}
signed main() {
accell();
int n;
cin >> n;
vector<int>a(n);
for (int i = 0; i < n; ++i)
cin >> a[i];
int l = 1;
int r = 1e18 + 1;
while (r - l > 1) {
int m = l + r >> 1;
if (get(m, a) >= 2)
r = m;
else
l = m;
}
if (get(r, a) != 2) {
cout << -1;
return 0;
}
int ansl = r;
l = 1;
r = 1e18 + 1;
while (r - l > 1) {
int m = l + r >> 1;
if (get(m, a) > 2)
r = m;
else
l = m;
}
int ansr = l;
cout << ansl << ' ' << ansr << endl;
return 0;
} | 1 | 78,988,602 |
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#ifdef DEBUG
#define debug(x) cerr << #x << " " << x << '\n'
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using pii = pair<int,int>;
const int INF = 0x3f3f3f3f, N = 3e5 + 5;
int n, a[N], cnt[N], suf[N], cnt2[N], cnt3[N], pre[N];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for(int i=1;i<=n;i++)
{
cin >> a[i];
cnt[a[i]]++;
}
for(int i=1;i<=n;i++)
{
if(cnt[i])
{
cnt2[cnt[i]] += cnt[i];
cnt3[cnt[i]]++;
}
}
for(int i=1;i<=n;i++) pre[i] = pre[i-1] + cnt2[i];
for(int i=n;i>=1;i--) suf[i] = suf[i+1] + cnt3[i];
for(int k=1;k<=n;k++)
{
int l = 1, r = n, ans = 0;
while(l<=r)
{
int mid = (l+r) >> 1;
if(suf[mid]+pre[mid-1]/mid>=k) ans = mid, l = mid + 1;
else r = mid - 1;
}
cout << ans << '\n';
}
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define ignore ignore
#define pb emplace_back
#define mt make_tuple
#define gcd __gcd
#define in(a) scanf("%d",&a)
#define in2(a,b) scanf("%d%d",&a,&b)
#define in3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define in4(a,b,c,d) scanf("%d%d%d%d",&a,&b,&c,&d)
#define inp(p) in2(p.F,p.S)
#define llin(a) cin >> a
#define llin2(a,b) cin >> a >> b
#define llin3(a,b,c) cin >> a >> b >> c
#define inl(a) scanf("%lld",&a)
#define read(v,i,n) for(i=0;i<n;i++)in(v[i])
#define twodread(mat,i,j,n,m) rep(i,n){rep(j,m)in(mat[i][j]);}
#define sc(ch) scanf("%c",&ch)
#define sstr(str) scanf("%s",str)
#define pr(a) printf("%d ",a)
#define pr2(a,b) printf("%d %d\n",a,b)
#define pr3(a,b,c) printf("%d %d %d\n",a,b,c)
#define prp(p) pr2(p.F,p.S)
#define out(a) printf("%d\n",a)
#define outl(a) printf("%lld\n",a)
#define llpr(a) cout << a << " "
#define llpr2(a,b) cout << a << " " << b << " "
#define llout(a) cout << a << "\n"
#define pinttwod(mat,i,j,n,m) rep(i,n){rep(j,m)pr(mat[i][j]); lin;}
#define plltwod(mat,i,j,n,m) rep(i,n){rep(j,m)llpr(mat[i][j]); lin;}
#define byes printf("YES\n")
#define bno printf("NO\n")
#define yes printf("Yes\n")
#define no printf("No\n")
#define lin printf("\n")
#define test(q) cout << "Case #" << q << ": "
#define rep(i,n) for(i=0;i<n;++i)
#define fone(i,n) for(i=1;i<=n;++i)
#define rrep(i,n) for(i=n-1;i>=0;--i)
#define lp(i,a,b) for(i=a;i<b;++i)
#define rlp(i,a,b) for(i=a;i>=b;--i)
#define all(vec) vec.begin(),vec.end()
#define lower(v,k) lower_bound(v.begin(),v.end(),k)-v.begin()
#define upper(v,k) upper_bound(v.begin(),v.end(),k)-v.begin()
#define tf(mytuple) get<0>(mytuple)
#define ts(mytuple) get<1>(mytuple)
#define tt(mytuple) get<2>(mytuple)
#define sz(x) (int)x.size()
#define inrange(i,a,b) (i>=a && i<=b)
#define FLUSH fflush(stdout)
#define precision(x) cout << setprecision(x) << fixed
#define remax(a,b) a=max(a,b)
#define remin(a,b) a=min(a,b)
#define middle() ((l+h)/2)
#define lchild(p) 2*p
#define rchild(p) 2*p+1
#define lseg l,m,2*p
#define rseg m+1,h,2*p+1
#define bhardo(mat,i,j,n,m,t) rep(i,n){rep(j,m)mat[i][j]=t;}
#define bitcount(x) __builtin_popcount(x)
#define bitcountll(x) __builtin_popcountll(x)
#define biton(mask,i) ((mask>>i)&1)
#define bitoff(mask,i) (!((mask>>i)&1))
#define toggle(mask,i) (mask^=(1<<(i)))
#define mul(p,q) ((ll)(p)*(ll)(q))
#define dbg(v,i,n) for(i=0;i<n;i++)pr(v[i]); lin
#define ck printf("continue\n")
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
cerr << *it << " = " << a << "\n";
err(++it, args...);
}
#define ll long long int
#define ii pair<int,int>
#define pli pair<ll,int>
#define lii pair<ll,ll>
#define triple tuple<int,int,int>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define viii vector<pair<pair<int,int>,int> >
#define vvii vector<vector<pair<int,int> > >
const double PI = acos(-1);
const double eps = (1e-9);
const ll INF = 2e18;
const int M = (1e9)+7;
const int N = (3e5)+3;
int cnt[N];
int ar[N];
int query[N];
int ans[N];
void solve()
{
int i,n,a,k;
in(n);
rep(i,n)
in(a),cnt[a]++;
int m=0;
rep(i,N)
if(cnt[i]>0)ar[cnt[i]]++,m++;
lp(i,1,N)
ar[i]+=ar[i-1];
rep(i,N-1)
query[i+1]=query[i]+(m-ar[i]);
lp(i,1,N)
query[i]/=i;
lp(i,1,N)
a=query[i],ans[a]=i;
rrep(k,n)
remax(ans[k],ans[k+1]);
fone(k,n)
out(ans[k]);
}
int main()
{
int t=1;
while(t--)
solve();
} | 1 | 10,078,641 |
#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
#include <complex>
#include <random>
#include <bitset>
#include <list>
#include <assert.h>
using namespace std;
#define repi(i,n) for(int i=0;i<n;++i)
#define rep(i,n) for(ll i=0;i<n;++i)
#define repinvi(i,n) for(int i=n-1;i>=0;--i)
#define sll(n) scanf("%lld", &n);
#define sii(n) scanf("%d", &n);
#define slf(n) scanf("%lf", &n);
#define pll pair<ll,ll>
#define pii pair<int,int>
#define psi pair<si,si>
typedef long long ll;
typedef double lf;
typedef short int si;
void Main(){
ll N, X, T;
cin >> N >> X >> T;
cout << (N + (X-1)) / X * T << endl;
}
int main(){
Main();
} | #include<iostream>
#include<string>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<vector>
#include<iomanip>
#include<map>
#include<set>
#include<utility>
#include<iterator>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define nn cout<<endl;
#define ff(a,n) for(ll i=a;i<n;i++)
#define cY cout<<"YES\n"
#define cN cout<<"NO\n"
#define cy cout<<"Yes\n"
#define cn cout<<"No\n"
#define sc second
#define fs first
#define c(a) cout<<a<<endl
void solve()
{
ll n,x,t; cin>>n>>x>>t;
ll ans=0;
ll i=0;
while(1)
{
i++;
ans+=x;
if(ans>=n) break;
}
ans=i*t;
cout<<ans;
}
int main()
{
solve();
} | 1 | 17,505,296 |
#include <stdio.h>
long long int ans[22] ;
void init ( ) ;
int main ( )
{
long long int s ;
init ( ) ;
while ( scanf ( "%lld" , &s ) == 1 ) {
printf ( "%lld\n" , ans[s] ) ;
}
return 0 ;
}
void init ( )
{
ans[0] = 0 ;
ans[1] = 1 ;
for ( long long int i = 2 ; i <= 20 ; i++ ) {
ans[i] = ans[i-1] * i ;
}
} | #include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
ll factorial(int n)
{
if(n == 0)
return 1;
return n * factorial(n - 1);
}
int main(void)
{
int n;
cin >> n;
cout << factorial(n) << endl;
return 0;
} | 1 | 63,475,168 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int a,b;
cin >> a >> b;
cout << a-b+1;
} | #include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) (v).begin(),(v).end()
const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);
int main(void)
{
ll n,k;
cin>>n>>k;
cout<<n-k+1<<endl;
return 0;
} | 1 | 26,275,664 |
#include <bits/stdc++.h>
using namespace std;
const int OO = 1e9;
const double EPS = 1e-9;
#define ndl cout << '\n'
#define sz(v) int(v.size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define present(a, x) (a.find(x) != a.end())
#ifdef LOCAL
#define db(...) ({cout << "> Line " << __LINE__ \
<< ": "; _db(#__VA_ARGS__, __VA_ARGS__);})
#define RNG() rng()
#else
#define db(...) true
#define RNG() true
#endif
template<class T>
void _db(const char *dbStr, T e) {
cout << dbStr << " = " << e << endl;
}
template<class T, class... L>
void _db(const char *dbStr, T e, L... r) {
while(*dbStr != ',') cout << *dbStr++;
cout << " = " << e << ','; _db(dbStr + 1, r...);
}
template<class S, class T>
ostream& operator<<(ostream& o, const map<S, T>& v) {
o << "["; int i = 0;
for (const pair<S, T>& pr : v) o << (!i++ ? "" : ", ") << "{"
<< pr.fs << " : " << pr.sc << "}"; return o << "]";
}
template<template <class, class...> class S, class T, class... L>
ostream& operator<<(ostream& o, const S<T, L...>& v) {
o << "["; int i = 0;
for (const auto& e : v) o << (!i++ ? "" : ", ") << e;
return o << "]";
}
template<class S, class T>
ostream& operator<<(ostream& o, const pair<S, T>& pr) {
return o << "(" << pr.fs << ", " << pr.sc << ")";
}
ostream& operator<<(ostream& o, const string& s) {
for (const char& c : s) o << c;
return o;
}
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
template<class T> using VVV = VV<V<T>>;
using ll = long long;
using pii = pair<int, int>;
using vi = V<int>;
using vii = V<pii>;
using vvi = VV<int>;
using mii = map<int, int>;
using umii = unordered_map<int, int>;
using si = set<int>;
using usi = unordered_set<int>;
int main() {
#ifdef LOCAL
auto stTime = clock();
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#endif
ios::sync_with_stdio(false);
cout.precision(10);
cin.tie(0);
ll K;
cin >> K;
cout << "50\n";
V<ll> ans(50, 0);
for (int i = 0; i < 50; ++i) {
ans[i] = i + (K / 50);
}
for (int i = 50 - (K % 50); i < 50; ++i) {
++ans[i];
}
for (int i = 0; i < 50; ++i) {
cout << ans[i] << " \n"[i + 1 == 50];
}
#ifdef LOCAL
cout << "\n\n\nExecution time: " <<
(clock() - stTime) * 1e3 / CLOCKS_PER_SEC << " ms" << endl;
#endif
return 0;
} | #include<iostream>
#include<cstdio>
using namespace std;
long long k,a[50][51];
int main()
{
ios::sync_with_stdio(false);
cin>>k;
for(int i=1;i<=50;++i)
a[0][i]=49;
for(int i=1;i<50;++i)
for(int j=1;j<=50;++j)
{
if(i==j) a[i][j]=a[i-1][j]+50;
else a[i][j]=a[i-1][j]-1;
}
long long w=k/50,g=k%50;
cout<<50<<endl;
for(int i=1;i<=50;++i)
cout<<w+a[g][i]<<' ';
cout<<endl;
return 0;
} | 1 | 22,827,376 |
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define FOR(i, m, n) for(ll i = m; i < (n); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vii = vector<vi>;
using pii = pair<int, int>;
using vl = vector<ll>;
using vll = vector<vl>;
using pll = pair<ll, ll>;
int main() {
ll N, A;
cin >> N >> A;
ll ans = N*N - A;
cout << ans;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N,A ;
cin >> N >> A ;
int x= std::pow(N,2)-A;
cout << x << endl;
} | 1 | 66,128,360 |
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string s,t;
cin>>s>>t;
vector<ll>ser(26,-1),ter(26,-1);
for(int i=0;i<s.size();i++){
ll x=s[i]-'a';
ll y=t[i]-'a';
if(ser[x]!=-1&&ser[x]!=y){
cout<<"No\n";return 0;
}
if(ter[y]!=-1&&ter[y]!=x){
cout<<"No\n";return 0;
}
ser[x]=y;
ter[y]=x;
}
cout<<"Yes\n";
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#ifdef LOCAL
#define debug(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<(x)<<endl
#define debug_vec(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = ";\
rep(i,sz(x)){cerr<<x[i]<<" ";}cerr<<endl
#define debug_mat(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<endl;\
rep(i,sz(x)){rep(j,sz(x[i])){cerr<<x[i][j]<<" ";}cerr<<endl;}cerr<<endl
#else
#define debug(x) void(0)
#define debug_vec(x) void(0)
#define debug_mat(x) void(0)
#endif
template<class T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
int main(){
ios_base::sync_with_stdio(false);cin.tie(0);
string S,T;
cin >> S >> T;
vector<int> to(26,-1);
vector<int> from(26,-1);
rep(i,sz(S)){
int a=S.at(i)-'a';
int b=T.at(i)-'a';
if(to.at(a)==-1) to.at(a)=b;
else if(to.at(a)!=b){
cout << "No" << endl;
return 0;
}
if(from.at(b)==-1) from.at(b)=a;
else if(from.at(b)!=a){
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
return 0;
} | 1 | 83,464,566 |
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>
using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "]"; return os; }
int main(){
LL n;
cin >> n;
if(n == 1){
cout << "Yes" << endl;
cout << "2" << endl;
cout << "1 1" << endl;
cout << "1 1" << endl;
return 0;
}
LL total = 0;
for(LL i = 1; i <= n; ++i){
total += i;
if(total > n) break;
if(total == n){
cout << "Yes" << endl;
LL c = n * 2 / i;
cout << c << endl;
vector<vector<LL> > a(c, vector<LL>(i));
LL next = 1;
for(LL j = 0; j < c; ++j){
cout << i;
for(LL k = 0; k < j; ++k){
a[j][k] = a[k][j-1];
cout << " " << a[j][k];
}
for(LL k = j; k < i; ++k){
a[j][k] = next;
cout << " " << a[j][k];
next++;
}
cout << endl;
}
return 0;
}
}
cout << "No" << endl;
return 0;
} | #include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
typedef long long ll;
vector<int> vs[500];
int main(void) {
int n;
scanf("%d", &n);
ll k = 1;
while(k*(k-1) < 2*n) {
++k;
}
if(k*(k-1) != 2*n) {
puts("No");
return 0;
}
int cur = 1;
REP(i, k-1) {
int start = cur;
while((int)vs[i].size() < k-1) {
vs[i].push_back(cur);
++cur;
}
REP(j, cur-start) {
vs[i+j+1].push_back(start+j);
}
}
puts("Yes");
printf("%lld\n", k);
REP(i, k) {
printf("%lld", k-1);
REP(j, k-1) {
printf(" %d", vs[i][j]);
}
puts("");
}
return 0;
} | 1 | 94,270,446 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int mxn= 1e5+5;
#define mod 1000000007
ll INF = 1000000000000000005LL;
#define endl '\n'
void rishabh(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int main(){
rishabh();
ll n;
cin>>n;
cout<<((n-1)*n)/2;
} | #include<bits/stdc++.h>
using namespace std;
long long n;
int main()
{
scanf("%lld",&n);
printf("%lld\n",n*(n-1)/2);
return 0;
} | 1 | 90,015,303 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
vector<int> data(n);
for (int i = 0; i < n; i++) {
cin >> data[i];
}
int sum = 0;
for (int i = 0; i < n; i++) {
if (k <= data[i]) {
sum++;
}
}
cout << sum << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define FOR(i,n) for(ll i=0;i<n;i++)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define popcount(x) __builtin_popcountll(x)
const int M=1000000007;
const int MM=998244353;
ll newmod(ll a,ll b)
{
return ((a%b)+b)%b;
}
ll powM(ll a,ll b,ll m )
{
if(m<=1)return 0;
a%=m;
ll ans=1LL;
while(b)
{
if(b&1)ans=ans*a%m;
a=a*a%m;
b>>=1;
}
return ans;
}
ll poww(ll a,ll b)
{
ll ans=1;
while(b)
{
if(b&1)ans=ans*a;
a=a*a;
b>>=1;
}
return ans;
}
template<typename T,typename F>
void chmax( T &a,F b){
if(b>a)a=b;
}
template<typename T,typename F>
void chmin( T &a,F b){
if(b<a)a=b;
}
const ll N=1e5+5;
ll sp[N];
void fill(){
for(int i=1;i<N;i++)sp[i]=i;
for(int i=2;i<N;i++){
for(int j=i;j<N;j+=i){
if(sp[j]==j)sp[j]=i;
}
}
}
int main()
{
IOS;
ll n;cin>>n;
ll k;cin>>k;
ll c=0;
FOR(i,n){
ll x;cin>>x;
c+=(x>=k);
}
cout<<c;
return 0;
} | 1 | 56,244,632 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int a,b,c,d; cin >> a >> b >> c >> d;
int begin = max(a, c);
int end = min(b, d);
if ((end - begin) > 0) cout << end - begin << endl;
else cout << 0 << endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
using ll = long long;
using P = pair<int,int>;
using mp = map<string,int>;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
int main(void){
int a, b, c, d;
cin >> a >> b >> c >> d;
int ans = min(b, d) - max(a, c);
if(ans < 0){
cout << 0 << "\n";
}else{
cout << ans << "\n";
}
return 0;
} | 1 | 81,096,069 |
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
void CountingSort(vector<int>& A, vector<int>& B){
int n = *max_element(A.begin(), A.end()) + 1;
vector<int> C(n, 0);
for (const auto& a : A) C[a]++;
for (int i = 1; i < n; i++) C[i] += C[i-1];
for (const auto& a : A) {
B[C[a]-1] = a;
C[a]--;
}
}
int main(){
int n;
cin >> n;
vector<int> A(n);
for (auto& a : A) cin >> a;
vector<int> B(n);
CountingSort(A, B);
for (int i = 0; i < n; i++) {
cout << B[i] << (i < n - 1 ? " " : "\n");
}
return 0;
} | #include<iostream>
using namespace std;
int bukket[10001];
int main(){
ios_base::sync_with_stdio(false);
int num;
cin >> num;
while(cin >> num){
bukket[num] ++;
}
for(int i = 0; i < 10001; i++){
if(bukket[i] > 0){
cout << i;
bukket[i] --;
break;
}
}
for(int i = 0; i < 10001; i++){
while(bukket[i] > 0){
cout << " " << i;
bukket[i] --;
}
}
cout << endl;
return 0;
} | 1 | 86,541,865 |
#include<cstdio>
int main()
{
int n; scanf("%d", &n);
int now = 0;
for(int i = 0; i < n; i++){
int inp; scanf("%d", &inp);
if(inp == now + 1) now++;
}
if(now == 0) printf("-1\n");
else printf("%d\n", n - now);
} | #include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define allr(a) a.rbegin(), a.rend()
#define rev(v) reverse(v.begin(), v.end());
#define io() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); srand(time(NULL));
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
signed main(){
io();
int n; cin >> n;
int aux = 1;
bool ok = 0;
for(int i = 0; i < n; ++i){
int x; cin >> x;
if(x == aux){
++aux;
ok = 1;
}
}
cout << (ok ? n - aux + 1 : -1) << '\n';
return 0;
} | 1 | 42,498,656 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
int r; cin >> r;
string ans;
if (r < 1200) ans = "ABC";
else if (r < 2800) ans = "ARC";
else ans = "AGC";
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int r;
cin >> r;
if (r < 1200) cout << "ABC" << endl;
else if (r < 2800) cout << "ARC" << endl;
else cout << "AGC" << endl;
return 0;
} | 1 | 68,465,431 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INTINF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007
int main() {
int ans = 0;
int tmp;
int n;
cin >> n;
vector<int> h(n+1);
REP1(i, n) cin >> h[i];
h[0] = 0;
REP1(i, 100){
REP1(j, n){
if(h[j-1] < i && h[j] >= i) ans ++;
}
}
cout << ans << endl;
} | #include<bits/stdc++.h>
using namespace std;
int main(){
int T,i,j;
int n,mn=107,cnt=0;
cin>>n;
int a[n+1];
for(i=1;i<=n;i++){
scanf("%d",&a[i]);
if(a[i]<mn) mn=a[i];
}
cnt=mn;
for(i=1;i<=n;i++)
a[i]-=mn;
int x;
for(i=1;i<=n;i++){
if(a[i]!=0){
x=a[i];
cnt+=x;
int l=i;
while(a[l+1]!=0 && l<n) l++;
j=i+1;
while(j<=l){
if(a[j]<x){
x=a[j];
a[j]=0;
}
else{
a[j]-=x;
}
j++;
}
}
}
printf("%d\n",cnt);
return 0;
} | 1 | 24,927,457 |
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
map<ll, int> a;
rep(i, n){
ll tmp;
cin >> tmp;
a[tmp]++;
}
vector<ll>c;
for(auto v:a){
int num=v.second;
if(num>=2){
rep(i,(int)(num/2)){
c.pb(v.first);
}
}
}
sort(c.begin(),c.end(),greater<ll>());
ll ans=0;
if(c.size()>0){
ans=c[0]*c[1];
}
cout<<ans<<endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n; cin >> n;
map<int, int, greater<int>> cnt;
for (int i = 0; i < n; i++) {
int a; cin >> a;
(cnt.find(a) != cnt.end()) ? cnt[a]++ : cnt[a] = 1;
}
long long y = 0, x = 0;
for (auto &lc : cnt) {
auto l = lc.first;
auto c = lc.second / 2;
if (!y && c) {y = l; c--;}
if (!x && c) {x = l; break;}
}
cout << y * x << '\n';
return 0;
} | 1 | 37,681,230 |
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(int argc, char const* argv[]) {
int A, B;
char op;
scanf("%d %c %d", &A, &op, &B);
if (op == '+') printf("%d\n", A + B);
else printf("%d\n", A - B);
return 0;
} | #include<bits/stdc++.h>
using namespace std;
int main(){
int a,b;
string s;
cin>>a>>s>>b;
if(s=="+"){
cout<<a+b;
}
else{
cout<<a-b;
}
return 0;
} | 1 | 12,337,765 |
#include <bits/stdc++.h>
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORR(i,n) for(int i=n;i>=0;i--)
#define pb push_back
#define vlli vector<int>
#define slli set<int>
#define mlli map<int,int>
#define int long long int
#define test int tt1234; cin>>tt1234;while(tt1234--)
#define endl "\n"
#define all(zz) zz.begin(),zz.end()
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define error(x) cerr << #x <<" is " << x << endl;
#define Error(a,b) cerr<<"( "<<#a<<" , "<<#b<<" ) = ( "<<(a)<<" , "<<(b)<<" )\n";
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fint fast;test
#define SI(a,n) int a[n];FOR(i,n) cin>>a[i];
#define input(a,n) int n;cin>>n; SI(a,n)
#define set(a,x) memset(a,x,sizeof(a))
#define L(x) ((x)<<1)
#define R(x) (((x)<<1)+1)
#define ft first
#define se second
#define MOD 1000000007
using namespace std;
void solve(){
int n;
cin>>n;
int arr[n];
FOR(i,n)cin>>arr[i];
sort(arr,arr+n);
int M=arr[n/2];
int m=arr[(n/2)-1];
cout<<M-m;
return;
}
int32_t main() {
fast;
solve();
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
ll n;
cin>>n;
ll arr[n+5]={0};
for(int i=0;i<n;i++)
{
cin>>arr[i];
}
sort(arr,arr+n);
ll x=n/2;
ll diff=arr[x]-arr[x-1];
cout<<diff<<endl;
} | 1 | 1,220,847 |
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
int n;
int cnt = 0;
while(scanf("%d",&n) != EOF){
cnt = 0;
for(int a = 0;a < 10;a++){
for(int b = 0;b < 10;b++){
for(int c = 0;c < 10;c++){
for(int d = 0;d < 10;d++){
if(a+b+c+d == n){
cnt++;
}
}
}
}
}
cout << cnt << endl;
}
} | #include <stdio.h>
#include <stdlib.h>
int main(void)
{
int n;
char buf[256];
while (fgets(buf, 256, stdin) != NULL){
int ans;
n = atoi(buf);
ans = 0;
for (int i = 0; i < 10; i++){
for (int j = 0; j < 10; j++){
for (int k = 0; k < 10; k++){
for (int l = 0; l < 10; l++){
if (i + j + k + l == n){
ans++;
}
}
}
}
}
printf("%d\n", ans);
}
return (0);
} | 1 | 83,780,305 |
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
int m,n_min,n_max;
while(cin>>m>>n_min>>n_max,m){
vector<int> V(m);
for(int i=0;i<m;i++) cin>>V[i];
sort(V.begin(), V.end(),greater<int>());
int ans=-1;
int gap=0;
for(int i=n_min-1;i<n_max;i++){
if(V[i+1]==V[i]) continue;
if(V[i]-V[i+1]>=gap){
gap=V[i]-V[i+1];
ans=i+1;
}
}
cout<<ans<<endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main(){
while(1){
int m,nmin,nmax;
cin >> m >> nmin >> nmax;
if(!m) break;
vector<int> p(m);
for(int i=0; i<m; i++) cin >> p[i];
int gap = 0,ans = 0;
for(int i=nmin-1; i<nmax; i++){
if( gap <= p[i]-p[i+1] ) {
gap = p[i] - p[i+1];
ans = i;
}
}
cout << ans+1 << endl;
}
} | 1 | 77,245,202 |
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#define PI 3.14159265359
using namespace std;
double func_area(double base, double height) {
double area = base * height / 2.0;
return area;
}
double func_circumference(double a, double b, double c_x, double c_y) {
double left_base = fabs(b - c_x);
double third_line = sqrt(pow(left_base, 2.0) + pow(c_y, 2.0));
double sum = a + b + third_line;
return sum;
}
int main() {
double a, b, c;
double c_x, c_y, c_y2;
cin >> a >> b >> c;
double rad = c * PI / 180;
double radius_a = a;
double radius_b = b;
c_x = cos(rad) * radius_a;
c_y = sin(rad) * radius_a;
c_y2 = sin(rad) * radius_b;
printf("%f\n%f\n%f\n", func_area(b, c_y), func_circumference(a, b, c_x, c_y), c_y2);
} | #include <bits/stdc++.h>
using namespace std;
using LL = long long;
using VI = vector<int>;
using PI = pair<int, int>;
int main() {
double a, b, c;
cin >> a >> b >> c;
double s = 0.5 * a * b * sin(M_PI * c / 180);
cout << setprecision(8) << fixed << s << '\n'
<< a + b + sqrt(pow(a, 2) + pow(b, 2) - 2 * a * b * cos(M_PI * c / 180)) << '\n'
<< 2 * s / a << endl;
return 0;
} | 1 | 41,929,817 |
#include <iostream>
int main()
{
int a, b;
std::cin >> a >> b;
int ans = a * b;
std::cout << ((ans % 2) ? "Odd" : "Even");
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(){
int a,b; cin>>a>>b;
cout<<(a*b%2==0 ? "Even" : "Odd")<<endl;
} | 1 | 95,834,004 |
#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>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
int dp[1001][1001];
int main() {
string a, b; cin >> a >> b;
memset(dp, 0x3f, sizeof(dp));
dp[0][0] = 0;
rep(i, a.size() + 1)rep(j, b.size() + 1) {
if (i < a.size())dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + 1);
if (j == b.size())continue;
dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + 1);
if (i == a.size())continue;
if (a[i] == b[j])dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j]);
dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j] + 1);
}
printf("%d\n", dp[a.size()][b.size()]);
} | 1 | 54,953,888 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int main(void){
char s,t; cin>>s>>t;
int x=s-'A',y=t-'A';
if(x<y){
cout<<"<"<<endl;
}else if(x>y){
cout<<">"<<endl;
}else{
cout<<"="<<endl;
}
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep2(i, a, b) for(int i = (a); i < (b); i++)
typedef long long ll;
int main() {
char x, y;
cin >> x >> y;
if (x < y) {
cout << "<" << endl;
} else if (x == y) {
cout << "=" << endl;
} else {
cout << ">" << endl;
}
} | 1 | 94,865,453 |
#include <bits/stdc++.h>
#include<cmath>
#define N 100005
#define A 1000005
#define MOD 1000000007
#define inf 1000000000000000000
#define ll long long
using namespace std;
#define pii pair<ll, ll>
#define piii pair<ll, pii>
#define ft first
#define sd second
#define pb push_back
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n-1; i >= 0; i--)
#define itr(it, x) for(auto it = x.begin(); it != x.end(); it++)
#define mem(a, b) memset(a, (ll)b, sizeof(a))
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define edge(v, x, y) v[x].pb(y); v[y].pb(x);
#define popcount __builtin_popcount
#define ANS(s) {cout << s << "\n"; return;}
#define printpii(a) cout << a.ft << " " << a.sd << endl;
#define printpiii(a) cout << a.ft << " " << a.sd.ft << " " << a.sd.sd << endl;
#define print(a, n) rep(i, n) cout << a[i] << " "; cout << endl;
#define printv(v) for(auto x: v)cout << x << " "; cout << endl;
#define printm(a, n, m) rep(i, n) { rep(j, m) cout << a[i][j] << "\t"; cout << endl;}
ll lx[4] = {0, 0, 1, -1};
ll ly[4] = {1, -1, 0, 0};
ll dx[8] = {0, 0, 1, -1, 1, -1, 1, -1};
ll dy[8] = {1, -1, 0, 0, 1, 1, -1, -1};
void fast(){ios_base::sync_with_stdio(false);cin.tie(0);cout << setprecision(12) << fixed;}
ll lcm(ll a, ll b) {return (a/__gcd(a, b))*b; }
void solve()
{
ll n;
cin >> n;
ll l = 1;
rep(i, n){
ll x; cin >> x;
l = lcm(l, x);
}cout << l << " ";
}
int main(){
fast();
ll t = 1;
while(t--){
solve();
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n-1; i >= 0; i--)
#define ALL(x) x.begin(),x.end()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
const int mod = 1e9+7;
const int INF = 2e9;
const int MAX = 1e6;
ll gcd(ll a, ll b) {
if (b == 0) return a;
return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
return a / gcd(a, b) * b;
}
ll lcm(vl &a) {
ll r = 1;
rep(i, (int)a.size()) {
r = lcm(r, a[i]);
}
return r;
}
int main() {
int n;
cin >> n;
vl t(n);
rep(i, n) {
cin >> t[i];
}
ll ans = lcm(t);
cout << ans << endl;
} | 1 | 85,375,271 |
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
const ll nmax = 1e9 + 7;
const ll Mod = 998244353;
const double PI = 2 * asin(1);
int main(){
int A, B, C; cin >> A >> B >> C;
if (A <= C && C <= B){
cout << "Yes" << endl;
}else{
cout << "No" << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;
int main(){
int a, b, c;
cin >> a >> b >> c;
if(c >= a && b >= c) cout << "Yes" << endl;
else cout<< "No" << endl;
} | 1 | 9,385,326 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
int main(){
int N, T;
cin >> N >> T;
int sum = 0;
int t, bt;
cin >> bt;
rep(i, N-1){
cin >> t;
sum += min(T, t - bt);
bt = t;
}
sum += T;
cout << sum << endl;
return 0;
} | #include<cstdio>
#include<iostream>
using namespace std;
const int N = 2e5+10;
int n,t,a[N];
int main()
{
cin>>n>>t;
for (int i = 0 ; i < n ; i++)
scanf("%d",&a[i]);
if (n == 1) { cout<< t<< endl; return 0;}
int left = 0;
long long curr = t;
long long ans = 0;
for (int i = 0; i < n ; i++)
{
if (a[i] <= curr) { curr = a[i] + t; continue; }
ans += curr - a[left];
left = i;
curr = a[left] + t;
if (i == n-1) ans+=t;
}
if (left != n-1) ans += a[n-1] + t - a[left];
cout<<ans<<endl;
return 0;
} | 1 | 71,703,532 |
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
#include <random>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define REPE(i, n) for (int (i)=0; (i) <= (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
#define CONTAINS_SET(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
signed main()
{
string s;
cin >> s;
YesNo((s[0] == s[1] && s[1] == s[2]) || s[1] == s[2] && s[2] == s[3]);
} | #include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<string> VS;
typedef vector<pair<LL, LL> > VP;
#define For(in) for (LL i = 0; i < (n); i++)
#define FOR(in) for(LL i=1; i <= (n); i++)
#define pb push_back
#define srt(v) sort(v.begin(), v.end())
#define rev(v) reverse(v.begin(), v.end())
#define uniq(v) v.erase(unique(v.begin(), v.end()), v.end());
#define exit(); return 0;
#define no "NO"
#define yes "YES"
#define con continue;
LL concate(LL a, LL b)
{
ostringstream os;
os <<a <<b;
istringstream is(os.str());
LL c;
is>> c;
return c;
}
LL check(char vowel)
{
return vowel=='a' || vowel=='e' || vowel=='i' || vowel=='o' || vowel=='u';
}
LL mod = 1e9+7;
int main()
{
LL a=0,b=0,c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,r=0,u=0,w=0,x=0,y=0,z=0;
LL aa[1000];
LL flag=0, flag1=0, co=0, co1=0, co2=0, co3=0, x1=0, x2=0, y1=0, y2=0, z1=0, z2=0;
LL ma=0, mi=100000000;
LL mid=0, temp=0, stop=0, start=0;
double pi= 3.141592653589793;
double d1=0.0, d2, d3, d4;
VLL v,v1,v2,v3,v4,v5,v6,v7,v8,v9,v10;
VS vs, vs1, vs2, vs3, vs4;
VP vp, vp1,vp2;
char ch, ch1, ch2[1001];
string str, str1, str2, str3, str4, str5;
pair<LL, LL> pa;
list<LL> li, li1;
map<LL, LL> mp, mp1;
set<LL> st;
map<LL ,LL> :: iterator imll;
VLL :: iterator ivll;
set<LL> :: iterator isll;
VP :: iterator ivp;
cin>>str;
if((str[0]==str[1] && str[1]==str[2]) || (str[1]==str[2] && str[2]==str[3]))cout<<"Yes"<<endl;
else cout<<"No"<<endl;
exit()
} | 1 | 66,061,585 |
#include <bits/stdc++.h>
using namespace std;
#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
typedef long long ll;
const int INT_INF = 1e9;
const ll INF = 1LL << 30;
const ll MOD = 1e9 + 7;
V<ll> len, pat;
ll rec(ll n, ll x){
if(n == 0){
if(x == 1) return 1;
else return 0;
}
if(x == 1) return 0;
if(x == len[n]) return pat[n];
ll ans = 0;
if(len[n] / 2 + 1 <= x){
ans += pat[n - 1] + 1 + rec(n - 1, x - len[n] / 2 - 1);
}
if(len[n] / 2 + 1 > x){
ans += rec(n - 1, x - 1);
}
return ans;
}
int main() {
ll n, x; cin >> n >> x;
len.resize(n + 1);
pat.resize(n + 1);
len[0] = pat[0] = 1;
for(int i = 1; i <= n; i++){
len[i] = len[i - 1] * 2 + 3;
pat[i] = pat[i - 1] * 2 + 1;
}
cout << rec(n, x) << endl;
} | #include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;
ll solve(ll n,ll x,ll sum){
if(sum==1){
return 1;
}
if(x==1){
return 0;
}else if(x<=(sum-3)/2+1){
return solve(n-1,x-1,(sum-3)/2);
}else if(x==(sum-3)/2+2){
return solve(n-1,(sum-3)/2,(sum-3)/2)+1;
}else if(x==sum){
return 2*solve(n-1,(sum-3)/2,(sum-3)/2)+1;
}else{
return solve(n-1,(sum-3)/2,(sum-3)/2)+1+solve(n-1,x-2-(sum-3)/2,(sum-3)/2);
}
}
int main()
{
ll N,X;
cin >> N >> X;
ll sum=1;
REP(i,N){
sum=2*sum+3;
}
cout << solve(N,X,sum) << endl;
} | 1 | 68,809,376 |
#include <iostream>
using namespace std;
int main(){
while(true){
string s;
string bottom;
string top;
int m;
int h;
cin >> s;
if(s=="-")break;
cin >> m;
for(int i=0; i<m; i++){
cin >> h;
bottom = s.substr(0, h);
top = s.substr(h, s.length()-h);
for(int i=0; i<s.length()-h;i++){
s[i] = top[i];
}
for(int i=0; i<h; i++){
s[i+s.length()-h]=bottom[i];
}
}
cout << s << endl;
}
} | #include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
using namespace std;
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
int main() {
while(1) {
char s[210];
int n, a;
scanf("%s", s);
if(s[0] == '-' && s[1] == '\0') break;
cin >> n;
string s1 = s;
rep(i,n) {
cin >> a;
string s2 = s1.substr(0, a);
string s3 = s1.substr(a);
s1 = s3 + s2;
}
cout << s1 << endl;
}
return 0;
} | 1 | 49,088,344 |
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const double PI = 3.14159265358979323846;
int main() {
char a, b;
cin >> a >> b;
if(a == 'D') {
if(b == 'H') cout << 'D' << endl;
else cout << 'H' << endl;
}
else {
if(b == 'H') cout << 'H' << endl;
else cout << 'D' << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
char a, b; cin >> a >> b;
char ans;
if (a == 'H' && b == 'H') ans = 'H';
if (a == 'H' && b == 'D') ans = 'D';
if (a == 'D' && b == 'H') ans = 'D';
if (a == 'D' && b == 'D') ans = 'H';
cout << ans << endl;
return 0;
} | 1 | 31,870,939 |
#include <iostream>
using namespace std;
int main(void) {
int n;
int score, sum_score;
int max_score, min_score;
int i;
cin >> n;
while (n) {
sum_score = 0;
max_score = 0;
min_score = 1000;
for (i=0; i<n; i++) {
cin >> score;
sum_score += score;
if (score < min_score) {
min_score = score;
}
if (score > max_score) {
max_score = score;
}
}
sum_score -= min_score + max_score;
cout << sum_score / (n-2) << endl;
cin >> n;
}
return 0;
} | #include <iostream>
using namespace std;
int main() {
int n, s;
while (cin >> n) {
if (n == 0) {
break;
}
int mins = 1000, maxs = 0, sum = 0;
for (int i = 0; i < n; i++) {
cin >> s;
sum += s;
mins = min(s, mins);
maxs = max(s, maxs);
}
sum -= mins + maxs;
cout << sum / (n - 2) << endl;
}
return 0;
} | 1 | 44,223,916 |
#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
int main() {
int a[6];
for (int i=0; i<6; i++) {
cin >> a[i];
}
int n;
cin >> n;
int x,y;
for (int i=0; i<n; i++) {
cin >> x >> y;
if(x==a[0]){
if(y==a[1]){
cout <<a[2];
}
if(y==a[2]){
cout <<a[4];
}
if(y==a[3]){
cout <<a[1];
}
if (y==a[4]) {
cout <<a[3];
}
}
if(x==a[1]){
if(y==a[0]){
cout <<a[3];
}
if(y==a[2]){
cout <<a[0];
}
if(y==a[3]){
cout <<a[5];
}
if (y==a[5]) {
cout <<a[2];
}
}
if(x==a[2]){
if(y==a[1]){
cout <<a[5];
}
if(y==a[5]){
cout <<a[4];
}
if(y==a[4]){
cout <<a[0];
}
if (y==a[0]) {
cout <<a[1];
}
}
if(x==a[3]){
if(y==a[1]){
cout <<a[0];
}
if(y==a[0]){
cout <<a[4];
}
if(y==a[4]){
cout <<a[5];
}
if (y==a[5]) {
cout <<a[1];
}
}
if(x==a[4]){
if(y==a[2]){
cout <<a[5];
}
if(y==a[5]){
cout <<a[3];
}
if(y==a[3]){
cout <<a[0];
}
if (y==a[0]) {
cout <<a[2];
}
}
if(x==a[5]){
if(y==a[2]){
cout <<a[1];
}
if(y==a[4]){
cout <<a[2];
}
if(y==a[1]){
cout <<a[3];
}
if (y==a[3]) {
cout <<a[4];
}
}
cout << endl;
}
} | #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
class Dice{
public:
long top, front, right, left, back, bottom;
Dice(long top, long front);
void north();
void south();
void west();
void east();
void showTop();
void guessRightFromTopAndFront(long top, long front, long *right);
};
Dice::Dice(long top, long front)
{
long r = 0;
this->top = top;
this->front = front;
if (top == 1){
if (front == 2) r = 3;
else if (front == 5) r = 4;
else if (front == 3) r = 5;
else if (front == 4) r = 2;
}
else if (top == 6){
if (front == 2) r = 4;
else if (front == 5) r = 3;
else if (front == 3) r = 2;
else if (front == 4) r = 5;
}
else if (top == 2){
if (front == 1) r = 4;
else if (front == 6) r = 3;
else if (front == 3) r = 1;
else if (front == 4) r = 6;
}
else if (top == 5){
if (front == 1) r = 3;
else if (front == 6) r = 4;
else if (front == 3) r = 6;
else if (front == 4) r = 1;
}
else if (top == 3){
if (front == 1) r = 2;
else if (front == 6) r = 5;
else if (front == 2) r = 6;
else if (front == 5) r = 1;
}
else if (top == 4){
if (front == 1) r = 5;
else if (front == 6) r = 2;
else if (front == 2) r = 1;
else if (front == 5) r = 6;
}
this->right = r;
this->left = 7 - r;
this->back = 7 - front;
this->bottom = 7 - top;
}
void Dice::north(){
long sv[6];
sv[0] = this->front;
sv[1] = this->bottom;
sv[2] = this->right;
sv[3] = this->left;
sv[4] = this->top;
sv[5] = this->back;
this->top = sv[0];
this->front = sv[1];
this->right = sv[2];
this->left = sv[3];
this->back = sv[4];
this->bottom = sv[5];
}
void Dice::south(){
long sv[6];
sv[0] = this->back;
sv[1] = this->top;
sv[2] = this->right;
sv[3] = this->left;
sv[4] = this->bottom;
sv[5] = this->front;
this->top = sv[0];
this->front = sv[1];
this->right = sv[2];
this->left = sv[3];
this->back = sv[4];
this->bottom = sv[5];
}
void Dice::west(){
long sv[6];
sv[0] = this->right;
sv[1] = this->front;
sv[2] = this->bottom;
sv[3] = this->top;
sv[4] = this->back;
sv[5] = this->left;
this->top = sv[0];
this->front = sv[1];
this->right = sv[2];
this->left = sv[3];
this->back = sv[4];
this->bottom = sv[5];
}
void Dice::east(){
long sv[6];
sv[0] = this->left;
sv[1] = this->front;
sv[2] = this->top;
sv[3] = this->bottom;
sv[4] = this->back;
sv[5] = this->right;
this->top = sv[0];
this->front = sv[1];
this->right = sv[2];
this->left = sv[3];
this->back = sv[4];
this->bottom = sv[5];
}
void Dice::showTop(){
cout << this->top << endl;
}
void Dice::guessRightFromTopAndFront(long top, long front, long *right){
if (top == 1){
if (front == 2) *right = 3;
else if (front == 5) *right = 4;
else if (front == 3) *right = 5;
else if (front == 4) *right = 2;
}
else if (top == 6){
if (front == 2) *right = 4;
else if (front == 5) *right = 3;
else if (front == 3) *right = 2;
else if (front == 4) *right = 5;
}
else if (top == 2){
if (front == 1) *right = 4;
else if (front == 6) *right = 3;
else if (front == 3) *right = 1;
else if (front == 4) *right = 6;
}
else if (top == 5){
if (front == 1) *right = 3;
else if (front == 6) *right = 4;
else if (front == 3) *right = 6;
else if (front == 4) *right = 1;
}
else if (top == 3){
if (front == 1) *right = 2;
else if (front == 6) *right = 5;
else if (front == 2) *right = 6;
else if (front == 5) *right = 1;
}
else if (top == 4){
if (front == 1) *right = 5;
else if (front == 6) *right = 2;
else if (front == 2) *right = 1;
else if (front == 5) *right = 6;
}
return;
}
int main(){
vector<long> roll(6, 0);
Dice *d;
long right;
for (long i = 0; i < 6; i++) cin >> roll[i];
d = new Dice(roll[0], roll[1]);
long q;
cin >> q;
for (long i = 0; i < q; i++){
long a = 0, b = 0;
cin >> a >> b;
long ra = 0, rb = 0;
for (long j = 0; j < 6; j++){
if (a == roll[j]) ra = j + 1;
if (b == roll[j]) rb = j + 1;
}
d->guessRightFromTopAndFront(ra, rb, &right);
cout << roll[right - 1] << endl;
}
delete d;
return 0;
} | 1 | 26,565,933 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long ;
int main(){
int n,k;
cin >> n >> k;
int R,S,P;
cin >> R >> S >> P;
string kyotai;
cin >> kyotai;
ll ans=0;
rep(i,n){
if(i>=k){
if(kyotai[i] == kyotai[i-k]){
kyotai[i] = '?';
}
else{
if(kyotai[i] == 'r') ans += P;
else if(kyotai[i] == 's') ans += R;
else if (kyotai[i] == 'p') ans += S;
}
}
else{
if(kyotai[i] == 'r') ans += P;
else if(kyotai[i] == 's') ans += R;
else if (kyotai[i] == 'p') ans += S;
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
int main()
{
int n,k,r,s,p;
cin >> n >> k >> r >> s >> p;
string t;
cin >> t;
int ans = 0;
for (int i = 0; i < k; i++){
char pre ='x';
for (int j = i; j < n; j += k){
char c = t[j];
if(c==pre){
pre = 'x';
continue;
}
if(c=='r'){
ans += p;
}
if (c == 's'){
ans += r;
}
if (c == 'p'){
ans += s;
}
pre = c;
}
}
cout << ans << "\n";
return 0;
} | 1 | 7,694,912 |
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()
int main() {
int m;
cin >> m;
ll sum = 0, digit = 0;
while (m--) {
ll d, c;
cin >> d >> c;
sum += d * c;
digit += c;
}
cout << (digit - 1) + ((sum - 1) / 9) << endl;
return 0;
} | #include <iostream>
#include <iomanip>
#include <algorithm>
#include <stdio.h>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <tuple>
#include <math.h>
#include <set>
#include <map>
using namespace std ;
using ll = long long ;
using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
using vc = vector<char> ;
using vvc = vector<vc> ;
using vb = vector<bool> ;
using vvb = vector<vb> ;
using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end()
const ll INF = 1e18 ;
const ll mod = 1e9+7 ;
const double pie = acos(-1);
vll dx4 = {-1,0,1,0} ;
vll dy4 = {0,-1,0,1} ;
vll dx8 = {-1,0,1,1,1,0,-1,-1} ;
vll dy8 = {-1,-1,-1,0,1,1,1,0} ;
void fix_cout(){cout << fixed << setprecision(20) ; }
ll gcd(ll a,ll b){if(b==0) return a ; return gcd(b,a%b) ; }
ll lcm(ll a,ll b){return a/gcd(a,b)*b ; }
void chmax(ll &a,ll b){if(a<b) a = b ; }
void chmin(ll &a,ll b){if(a>b) a = b ; }
int main(){
ll m ; cin >> m ;
ll d=0,s=0 ;
while(m--){
ll a,b ;
cin >> b >> a ;
d += a ;
s += a*b ;
}
cout << (d-1)+(s-1)/9 << endl ;
} | 1 | 75,630,092 |
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int main() {
int A, B;
cin >> A >> B;
cout << (A - 1) * (B - 1) << endl;
return 0;
} | #include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;
template<class T> inline bool chmin(T& a,T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if (a < b) {a = b; return true;} return false;}
const ll MOD = 1000000007;
const int INF = 1<<30;
int main(){
int A, B; cin >> A >> B;
cout << A * B - A - B + 1 << endl;
} | 1 | 77,210,004 |
#include <bits/stdc++.h>
using namespace std;
#define IO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define ull unsigned long long int
const int INF = 1e9 + 7;
const int N = 1e5+5;
int main() {
IO;
int n, m;
cin >> n >> m;
if (n <= m) {
for (int i = 1; i <= m; ++i)
cout << n;
}
else {
for (int i = 1; i <= n; ++i)
cout << m;
}
} | #include<bits/stdc++.h>
using namespace std;
#define li long long int
#define rep(i,to) for(li i=0;i<((li)(to));i++)
#define repp(i,start,to) for(li i=(li)(start);i<((li)(to));i++)
#define pb push_back
#define sz(v) ((li)(v).size())
#define bgn(v) ((v).begin())
#define eend(v) ((v).end())
#define allof(v) (v).begin(), (v).end()
#define dodp(v,n) memset(v,(li)n,sizeof(v))
#define bit(n) (1ll<<(li)(n))
#define mp(a,b) make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;
#define INF bit(60)
#define DBGP 1
#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b) idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c) idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d) idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e) idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f) idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g) idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h) idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i) idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j) idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v) for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x) idp p2((x).F, (x).S)
#define dump(x,n) idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n) idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x) idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x) idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}
#define read2d(a,w,h) rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h) rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}
typedef pair<li, li> PI;
int main() {
li a,b;
cin>>a>>b;
if(a<b)swap(a,b);
rep(i,a){
cout<<b;
}
cout<<endl;
return 0;
} | 1 | 51,288,147 |
#include <iostream>
#include <vector>
typedef long long ll;
typedef unsigned long long ull;
constexpr size_t MAXN = 1e5;
constexpr size_t MAXM = 1e5;
constexpr int MOD = 1e9 + 7;
void solve() {
int H, W;
std::cin >> H >> W;
std::vector<std::vector<int>> grid;
grid.reserve(H);
for (int y = 0; y < H; ++y) {
grid.push_back(std::vector<int>());
grid.back().reserve(W);
for (int x = 0; x < W; ++x) {
char a;
std::cin >> a;
grid[y].push_back(a == '.' ? 0 : -1);
}
}
grid[0][0] = 1;
for (int y = 0; y < H; ++y) {
for (int x = 0; x < W; ++x) {
if (grid[y][x] == -1 || y + x == 0) continue;
if (y == 0) {
grid[y][x] = grid[y][x - 1];
continue;
}
if (x == 0) {
grid[y][x] = grid[y - 1][x];
continue;
}
int top = grid[y - 1][x] == -1 ? 0 : grid[y - 1][x];
int left = grid[y][x - 1] == -1 ? 0 : grid[y][x - 1];
grid[y][x] = (top + left) % MOD;
}
}
std::cout << grid.back().back() << "\n";
}
void warp() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
}
int main() {
warp();
solve();
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define FasterIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define bug(a,b) cout<<a<<"\t"<<b<<"\n";
#define Case(a,b) cout<<"Case "<<a<<": "<<b<<"\n";
#define precision(a,b) fixed<<setprecision(a)<<b
#define lp(i,a,b) for(int i=a;i<b;i++)
#define Endl "\n"
#define tab "\t"
#define reset(a,b) memset(a,b,sizeof(a));
#define sf(a) scanf(" %d", &a);
#define sfl(a) scanf(" %lld", &a);
#define srt(a) sort(a.begin(),a.end());
#define ALL(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pi 2*acos(0.0)
typedef long long int ll;
typedef unsigned long long int ull;
const int sz=1e5+9 , infP=INT_MAX , infN=INT_MIN ,mod=1e9+7, eps=1e-9;
void ini(){
return;
}
int dp[1005][1005];
void solve(){
ll n , m, k, l, ans=0,r,c;
cin>>r>>c;
string g[r];
for(auto &i:g)cin>>i;
dp[0][0]=1;
for(int i=0;i<r;i++){
for(int j=0;j<c;j++){
if(g[i][j]=='#')continue;
if(i!=0)dp[i][j]+=dp[i-1][j];
dp[i][j]%=mod;
if(j!=0)dp[i][j]+=dp[i][j-1];
dp[i][j]%=mod;
}
}
cout<<dp[r-1][c-1]<<Endl;
}
int main(){
FasterIO;
#ifndef ONLINE_JUDGE
freopen("input.in","r",stdin);
freopen("output.in","w",stdout);
#endif
int t=1;
while(t--)
solve();
} | 1 | 14,492,563 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int H, W;
cin >> H >> W;
vector<vector<char>> data(H, vector<char>(W));
int flag;
vector<int> h_vec;
for (int i=0; i<H; i++) {
flag = 0;
for (int j=0; j<W; j++) {
cin >> data.at(i).at(j);
if (data.at(i).at(j) == '#') flag = 1;
}
if (flag == 1) h_vec.push_back(i);
}
vector<int> w_vec;
for (int j=0; j<W; j++) {
flag = 0;
for (int i : h_vec) {
if (data.at(i).at(j) == '#') flag = 1;
}
if (flag == 1) w_vec.push_back(j);
}
for (auto i = h_vec.begin(); i != h_vec.end(); i++) {
for (auto j = w_vec.begin(); j != w_vec.end(); j++) {
cout << data.at(*i).at(*j);
}
cout << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int main() {
int H, W;
cin >> H >> W;
vector<vector<char>> a(H, vector<char>(W));
for(int i = 0; i < H; i++){
for(int j = 0; j < W; j++){
cin >> a.at(i).at(j);
}
}
vector<char> temp(H), white(W, '.');
for(int i = 0; i < H; i++){
if(a.at(i) == white){
for(int j = i; j < H-1; j++){
swap(a.at(j), a.at(j+1));
}
i--;
H--;
}
}
int check;
for(int i = 0; i < W; i++){
check = 0;
for(int j = 0; j < H; j++){
if(a.at(j).at(i) == '.') check++;
}
if(check == H){
for(int j = 0; j < H; j++){
for(int k = i; k < W-1; k++){
swap(a.at(j).at(k), a.at(j).at(k+1));
}
}
i--;
W--;
}
}
for(int i = 0; i < H; i++){
for(int j = 0; j < W; j++){
cout << a.at(i).at(j);
}
cout << endl;
}
} | 1 | 22,400,275 |
#include <bits/stdc++.h>
using namespace std;
const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;
double equal(double a, double b) {
return fabs(a - b) < DBL_EPSILON;
}
std::istream &operator>>(std::istream &in, set<int> &o) {
int a;
in >> a;
o.insert(a);
return in;
}
std::istream &operator>>(std::istream &in, queue<int> &o) {
ll a;
in >> a;
o.push(a);
return in;
}
bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }
typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;
struct Monster {
ll x, h;
};
std::istream &operator>>(std::istream &in, Monster &o) {
cin >> o.x >> o.h;
return in;
}
int main() {
int n;
ll d, a;
cin >> n >> d >> a;
vector<Monster> monsters(n);
rep(i, n) cin >> monsters[i];
sort(monsters.begin(), monsters.end(), [](Monster &m1, Monster &m2) {
return m1.x < m2.x;
});
vector<ll> positions(n);
rep(i, n) positions[i] = monsters[i].x;
vector<ll> damages(n);
ll ans = 0;
rep(i, n) {
if (i != 0) damages[i] += damages[i - 1];
ll h = monsters[i].h;
ll da = damages[i] * a;
h -= da;
if (h <= 0) continue;
ll c = (h + a - 1) / a;
ans += c;
damages[i] += c;
ll r = monsters[i].x + (d * 2);
auto it = upper_bound(positions.begin(), positions.end(), r);
if (it == positions.end()) continue;
int ri = distance(positions.begin(), it);
damages[ri] -= c;
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long lint;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
const lint MOD =1000000007;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
typedef map<lint,lint> M;
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
lint fac[MAX], finv[MAX], inv[MAX];
void COMinit()
{
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (lint i = 2; i < MAX; i++)
{
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
long long COM(lint n, lint k)
{
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
lint primary(lint num)
{
if (num < 2) return 0;
else if (num == 2) return 1;
else if (num % 2 == 0) return 0;
double sqrtNum = sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2)
{
if (num % i == 0)
{
return 0;
}
}
return 1;
}
long long modpow(long long a, long long n, long long mod) {
long long res = 1;
while (n > 0) {
if (n & 1) res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
lint lcm(lint a,lint b){
return a/__gcd(a,b)*b;
}
lint gcd(lint a,lint b){
return __gcd(a,b);
}
int main(){
lint n,d,a;
cin>>n>>d>>a;
d*=2;
P p[n];
rep(i,n){
lint x,h;
cin>>x>>h;
p[i]={x,h};
}
vector<lint> x;
vector<lint> h;
sort(p,p+n);
rep(i,n){
x.push_back(p[i].first);
h.push_back(p[i].second);
}
lint damage[n+1];
fill(damage,damage+n+1,0);
lint ans=0;
rep(i,n){
if(i!=0)damage[i]+=damage[i-1];
lint add=max(0LL,(h[i]-damage[i]+a-1)/a);
ans+=add;
auto it=upper_bound(all(x),x[i]+d);
lint g=it-x.begin();
damage[i]+=add*a;
damage[g]-=add*a;
}
cout<<ans<<endl;
} | 1 | 36,581,271 |
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<stack>
#include<queue>
using namespace std;
typedef long long ll;
const int maxn = 101000;
int n,m,x;
int lt,rt,dis[maxn];
string S,S1,S2;
ll read(){ ll s=0,f=1; char ch=getchar(); while(ch<'0' || ch>'9'){ if(ch=='-') f=-1; ch=getchar(); } while(ch>='0' && ch<='9'){ s=s*10+ch-'0'; ch=getchar(); } return s*f; }
int main(){
x=10000;
n=read();
cin>>S;
for(int i=0;i<n;i++){
if(S[i]=='('){
++lt;
}
if(S[i]==')'){
++rt;
}
dis[i]=lt-rt;
x=min(x,dis[i]);
}
if(x>=0){
cout<<S;
for(int i=0;i<dis[n-1];i++){
printf("%c",')');
}
printf("\n");
}
if(x<0){
for(int i=0;i<(-1*x);i++) printf("%c",'(');
cout<<S;
for(int i=0;i<dis[n-1]-x;i++) printf("%c",')');
printf("\n");
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REPS(i, n) for(int i = 1; i <= (n); i++)
#define RREP(i, n) for(int i = (n)-1; i >= 0; i--)
#define RREPS(i, n) for(int i = (n); i > 0; i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl
using ll = long long;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const ll INFL = 1e18;
const double PI = 3.141592653589793;
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if(a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if(a > b) { a = b; return true; } return false; }
signed main()
{
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
int N; cin >> N;
string s; cin >> s;
int nest = 0;
string ans = "";
REP(i, N)
{
if(s[i] == '(') nest++;
else nest--;
if(nest < 0) ans.pb('('), nest++;
}
ans += s;
while(nest > 0) ans.pb(')'), nest--;
cout << ans << endl;
} | 1 | 98,363,559 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N, M;
cin >> N;
M = N;
int sum = 0;
for (int i=8; i>=0; i--) {
int W=1;
for (int j=0; j<i; j++){
W *= 10;
}
int x;
x = N / W;
sum += x;
N = N - x*W;
}
if (M % sum == 0) {
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 < (int)(N); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int main() {
int N;
cin >> N;
int Nini = N;
int f = 0;
while ( N > 0 ){
int x = N % 10, y = N / 10;
f += x;
N = y;
}
bool flg = false;
if ( Nini % f == 0 ) flg = true;
if ( flg ) cout << "Yes" << endl;
else cout << "No" << endl;
return 0;
} | 1 | 41,100,890 |
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;
int main(){
int n, d, a;
cin >> n >> d >> a;
vector<pair<int, int>> vp(n);
rep(i, n){
int x, h;
cin >> x >> h;
vp.at(i) = make_pair(x, h);
}
sort(vp.begin(), vp.end());
vector<ll> za;
vector<ll> co;
ll ans = 0;
rep(i, n){
ll x, h;
tie(x, h) = vp.at(i);
int n = lower_bound(za.begin(), za.end(), x) - za.begin();
ll atkc = 0;
if(co.size() != 0) atkc = co.back();
if(n != 0) atkc -= co.at(n-1);
h -= (ll)atkc * a;
if(h <= 0) continue;
ll ac = (h+a-1)/a;
ans += ac;
za.push_back((ll)x+2*d);
if(co.size() != 0)ac += co.back();
co.push_back(ac);
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define rep(i, n) repl(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
const ll MOD = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 4e18 + 10;
const int dx[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
const int dy[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
int main() {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
ll d, a;
cin >> d >> a;
pair<ll, ll> p[n];
rep(i, n) cin >> p[i].first >> p[i].second;
sort(p, p + n);
vector<ll> x(n), cnt(n + 1);
rep(i, n) x[i] = p[i].first;
ll ans = 0;
rep(i, n) {
cnt[i + 1] += cnt[i];
p[i].second -= a * cnt[i + 1];
if (p[i].second > 0) {
ll now = (p[i].second + a - 1) / a;
ans += now;
cnt[i + 1] += now;
int it = upper_bound(all(x), p[i].first + d * 2) - x.begin();
if (it == n + 1)
continue;
else
cnt[it + 1] -= now;
}
}
cout << ans << endl;
return 0;
} | 1 | 66,559,003 |
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <iomanip>
#include <math.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
int main(){
int n;
cin>>n;
vector<double>v(n);
rep(i,n)cin>>v[i];
sort(v.begin(),v.end());
double sum=(v[0]+v[1])/2;
rep(i,n-2){
sum+=v[i+2];
sum/=2.0;
}
cout<<sum;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main()
{int N; cin >> N;
double V[N], r; for (auto &v: V) cin >> v; sort(V, V + N); r = V[0];
for (int i{1}; i < N; ++i) r = (r + V[i]) / 2;
printf("%.9f", r);} | 1 | 24,587,869 |
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
ll n, a[200010], ruiseki[200010];
ll sum, ans = 2000000000000000000;
int main() {
cin >> n;
cin >> a[0];
sum = a[0];
ruiseki[0] = a[0];
for (int i = 1; i < n; i++) {
cin >> a[i];
sum += a[i];
ruiseki[i] = ruiseki[i - 1] + a[i];
}
for (int i = 0; i < n - 1; i++)if (abs(ruiseki[i] - (sum - ruiseki[i])) < ans)ans = abs(ruiseki[i] - (sum - ruiseki[i]));
cout << ans << endl;
return 0;
} | #include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<map>
#include<vector>
#include<string>
#define ll long long
#define For(i,x,y) for(ll i=x;i<=y;++i)
#define FOr(i,x,y) for(ll i=x;i>=y;--i)
using namespace std;
inline ll read(){ ll 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; }
inline void write(ll x){ if (x<0) putchar('-'),x=-x; if (x>=10) write(x/10); putchar(x%10+'0'); }
inline void writeln(ll x){ write(x); puts(""); }
const ll N=400010;
ll n,sum[N],ans=1e18;
int main(){
n=read();
For(i,1,n) sum[i]=sum[i-1]+read();
For(i,1,n-1) ans=min(ans,abs(sum[i]-(sum[n]-sum[i])));
writeln(ans);
} | 1 | 28,183,755 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define reset(x) memset(x,-1,sizeof(x))
#define CheckBit(a,b) (a&(1ll<<b))
#define SetBit(a,b) a=(a|(1ll<<b))
#define UnSetBit(a,b) a=(a&(~(1ll<<b)))
#define maxx 10000006
#define PI 2*acos(0.0)
const long long INF = 2000000000000000000LL;
const int inf = 0x3f3f3f3f;
const long double EPS = 1e-9;
inline ll mulmod(ll a, ll b, ll c) {
ll ret = 0 , cur = a % c ;
while(b) { if(b%2) ret=(ret+cur)%c; cur=(cur<<1)%c; b=b>>1; }
return ret%c;
}
inline ll bigmod(ll b, ll p, ll m){
ll ret = 1, cur = b % m;
while(p) { if(p&1) ret=(ret*cur)%m; cur=(cur*cur)%m; p=p>>1; }
return ret;
}
inline ll modulo(ll a,ll b,ll c) {
ll ret = 1 , cur = a%c ;
while(b) { if(b%2) ret=mulmod(ret,cur,c); cur=mulmod(cur,cur,c); b=b>>1; }
return ret%c ;
}
inline ll power(ll b, ll p){
ll ret = 1, cur = b;
while(p) { if(p&1) ret=(ret*cur); cur=(cur*cur); p=p>>1; }
return ret;
}
ll lcm(ll a,ll b)
{
return (a/__gcd(a,b))*b;
}
ll gcd(ll a,ll b)
{
return __gcd(a,b);
}
ll f(ll a,ll b)
{
ll cnt=0,cnt2=0;
while(a){
a/=10;
cnt++;
}
while(b){
b/=10;
cnt2++;
}
return max(cnt2,cnt);
}
void Dufaux()
{
ll n,minn=INT_MAX;
cin>>n;
ll limit=sqrt(n);
for(int i=1;i<=limit;i++){
if(n%i==0){
ll ans=f(i,n/i);
minn=min(ans,minn);
}
}
cout<<minn<<endl;
}
int main()
{
FastIO;
int test=1;
while(test--){
Dufaux();
}
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll dg(ll a)
{
int cnt=0;
while(a>0)
{
a/=10;
cnt++;
}
return cnt;
}
int main()
{
FastRead
ll n,ans=INT_MAX;
cin>>n;
for(int i=1; i<=sqrt(n); i++)
{
if(n%i==0)
{
ll x=i;
ll y=n/x;
ans=min(ans,max(dg(x),dg(y)));
}
}
cout<<ans<<endl;
return 0;
} | 1 | 23,385,906 |
#include<bits/stdc++.h>
using namespace std;
main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long i,j,k,l,m,n,o,p,q;
while(cin>>m)
{
cout<<m/3<<endl;
}
return 0;
} | #include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX
#define INFLL LLONG_MAX
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;
int main(){
Init();
ll n; cin >> n;
cout << n/3 << endl;
} | 1 | 79,651,544 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int a, b, c, d;
cin >> a >> b >> c >> d;
int res = 0;
if(a < b) res += a;
else res += b;
if(c < d) res += c;
else res += d;
cout << res << endl;
return 0;
} | #include <iostream>
using namespace std;
int main()
{
int A , B , C , D;
cin >> A >> B >> C >> D;
if ((A >= B) && (C >= D)) {cout << B + D;}
else if ((A <= B) && (C >= D)) {cout << A + D;}
else if ((A >= B) && (C <= D)) {cout << B + C;}
else if ((A <= B) && (C <= D)) {cout << A + C;}
} | 1 | 3,512,746 |
#include <stack>
#include <utility>
#include <iostream>
#include <string>
#include <set>
#include <algorithm>
#include <vector>
#include <queue>
#include <functional>
#include <cstdio>
using namespace std;
int main()
{
int n;
typedef pair <int, int> p;
while (cin >> n, n != 0) {
vector <p> map[12];
int a, b, c;
for (int i = 0; i < n; i++) {
cin >> a >> b >> c;
map[a].push_back(p(b, c));
map[b].push_back(p(a, c));
}
p ans = p(0, 9999999);
for (int z = 0; z < 10; z++) {
if (map[z].size() == 0)break;
int d[12] ;
for (int i = 0; i < 12; i++)d[i] = 9999999;
priority_queue<p, vector<p>, greater<p> > que;
que.push(p(0, z));
d[z] = 0;
while (!que.empty()) {
p now = que.top();
que.pop();
if (now.first > d[now.second])continue;
for (int i = 0; i < map[now.second].size(); i++) {
p dst = map[now.second][i];
if (d[dst.first] > now.first + dst.second) {
que.push(p(now.first + dst.second, dst.first));
d[dst.first] = now.first + dst.second;
}
}
}int cnt = 0;
for (int i = 0; i < 10; i++) { if (d[i] != 9999999)cnt += d[i]; }
if (ans.second > cnt)ans = p(z, cnt);
}
cout << ans.first << " " << ans.second << endl;
}
} | #include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define VV(T) vector<vector< T > >
template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
v.assign(a, vector<T>(b, t));
}
template <class F, class T>
void convert(const F &f, T &t){
stringstream ss;
ss << f;
ss >> t;
}
#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x) cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x)
#define debug(x)
#endif
#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
void mainmain(){
int n;
while(cin>>n,n){
vvint vv;
vint used(100);
initvv(vv,100,100,INF);
rep(i,100) vv[i][i]=0;
rep(i,n){
int a,b,c;
cin>>a>>b>>c;
used[a]=1;
used[b]=1;
mins(vv[a][b],c);
mins(vv[b][a],c);
}
rep(k,100){
rep(i,100){
rep(j,100){
mins(vv[i][j],vv[i][k]+vv[k][j]);
}
}
}
pii ans(INF,INF);
rep(i,100){
if(!used[i]) continue;
int tmp=0;
rep(j,100){
if(used[j]){
tmp+=vv[i][j];
}
}
mins(ans,pii(tmp,i));
}
cout<<ans.S<<" "<<ans.F<<endl;
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout<<fixed<<setprecision(20);
mainmain();
} | 1 | 90,165,777 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string TKSS;
cin >> TKSS;
if(TKSS == "a" || TKSS == "e" || TKSS == "i" || TKSS == "o" || TKSS == "u"){
cout << "vowel" << endl;
}
else{
cout << "consonant" << endl;
}
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
int main() {
char c;
cin >> c;
cout << ((c=='a'||c=='i'||c=='u'||c=='e'||c=='o')?"vowel":"consonant") << endl;
} | 1 | 76,794,953 |
#include<bits/stdc++.h>
using namespace std;
#define l1 long long
int main(){
int x;
int k;
cin>>k>>x;
k=500*k;
if(k>=x)cout<<"Yes";
else cout<<"No";
} | #include <iostream>
using namespace std;
int main(){
int k,x;
cin>>k>>x;
if(k*500<x){
cout<<"No\n";
}
else{
cout<<"Yes\n";
}
} | 1 | 20,283,005 |
#include <bits/stdc++.h>
#define rep(i,s,n) for (int i = s; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main() {
int h,n;
cin >> h >> n;
int attack = 0;
rep(i,0,n) {
int a;
cin >> a;
attack += a;
}
if (attack >= h) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()
int main(){
int H,N;cin>>H>>N;
int sum=0;
rep(i,N){
int a;
cin>>a;
sum+=a;
}
if(H<=sum)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
} | 1 | 89,100,623 |
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
const long long INF = 1LL << 60;
string s;
int main()
{
cin >> s;
if(s[0] == s[1] && s[1] == s[2]) cout << "No" << endl;
else cout << "Yes" << endl;
} | #include<iostream>
using namespace std;
int main(){
string S;
cin >> S;
char c = S[0];
int count = 0;
for (int i = 1; i < S.size(); i++){
if(c != S[i]){
count++;
}
c = S[i];
}
if(count == 0){
cout << "No" << endl;
}
else{
cout << "Yes" << endl;
}
} | 1 | 47,956,573 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
int x, y;
x = a % 2;
y = b % 2;
if(x==0 || y==0) {
cout << "Even" << endl;
}
else {
cout << "Odd" << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
if (a%2 != 1 || b%2 != 1) {
cout << "Even";
} else {
cout << "Odd";
}
} | 1 | 74,414,652 |
#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 MAX 5100000
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<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
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;}
int main(){
ll N,M;
cin>>N>>M;
Graph G(N);
REP(i,M){
ll A,B;
cin>>A>>B;
A--,B--;
G[A].PB(B);
G[B].PB(A);
}
ll ANS[N];
REP(i,N) ANS[i]=INF;
ANS[0]=0;
queue<ll> Q;
Q.push(0);
while(!Q.empty()){
ll v=Q.front();
Q.pop();
FORE(nv,G[v]){
if(ANS[nv]!=INF) continue;
ANS[nv]=v;
Q.push(nv);
}
}
cout<<"Yes"<<endl;
RREP(i,N-1) co(ANS[i]+1);
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define pb push_back
signed main()
{
int n,m ; cin>>n>>m;
vector<int>adj[n+1];
for(int i = 0 ; i < m ;i++)
{
int u , v;cin>>u>>v;
adj[u].pb(v);
adj[v].pb(u);
}
vector<int>dis(n+1,INT_MAX);
vector<int>par(n+1);
vector<int>vis(n+1);
priority_queue<pair<int,int>, vector<pair<int,int>> , greater<pair<int,int>>>pq;
pq.push({0,1});
dis[1] = 0;
while(!pq.empty())
{
int cost = pq.top().first;
int tp = pq.top().second;
pq.pop();
vis[tp] = 1;
for(auto it : adj[tp])
{
if(dis[it] > dis[tp] + 1)
{
dis[it] = dis[tp] +1 ;
par[it] = tp;
pq.push({dis[tp] + 1 ,it});
}
}
}
for(int i = 2 ; i <=n ;i++ )
{ if(vis[i] != 1 ) { cout<<"No"<<endl; return 0 ;} }
cout<<"Yes"<<endl;
for(int i = 2 ; i <=n ;i++)
cout<<par[i]<<endl;
} | 1 | 96,372,301 |
#include <iostream>
#include <algorithm>
using namespace std;
int main(void) {
int d[3];
for (int i = 0; i < 3; i++) cin >> d[i];
sort(d, d + 3);
cout << d[0] << ' ' << d[1] << ' ' << d[2] << endl;
return 0;
} | #include <algorithm>
#include <iostream>
using namespace std;
int main() {
int arr[3];
for (int i = 0; i < 3; i++) {
cin >> arr[i];
}
sort(begin(arr), end(arr));
cout << arr[0] << " " << arr[1] << " " << arr[2] << endl;
return 0;
} | 1 | 69,006,153 |
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
using namespace std;
#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;
int main(){
int a,b,c,d; cin >> a >> b >> c >> d;
bool ok = false;
if(abs(a-c) <= d) ok = true;
if(abs(a-b) <= d && abs(b-c) <= d) ok = true;
cout << (ok?"Yes":"No") << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
#define endl '\n'
#define all(a, n) for (int i = 0; i < n; i++) cout << a[i] << " "; cout << endl;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const ll MAXN = 1e6 + 10;
const ll INF = 8e18;
const ll MOD = 1e9 + 7;
int main() {
IOS ;
ll a , b , c , d ;
cin >> a >> b >> c >> d ;
if(abs(a-c) <= d || (abs(a-b)<=d && abs(b-c) <=d))cout <<"Yes" ;
else cout << "No" ;
return 0 ;
} | 1 | 88,896,554 |
#include <iostream>
using namespace std;
int main(){
int n,y,m,d,a;
cin>>n;
for(int i=0;i<n;i++){
cin>>y>>m>>d;
a=0;
for(int j=1;j<y;j++){
if(j%3==0){
a=a+200;
}
else{
a=a+195;
}
}
for(int j=1;j<m;j++){
if(y%3==0||j%2==1){
a=a+20;
}
else{
a=a+19;
}
}
a=a+d;
cout<<196471-a<<endl;
}
return 0;
} | #include<bits/stdc++.h>
#define rep(i,n) for(int i=1; i<=n; i++)
using namespace std;
int every=0;
void make(){
int last=0;
rep(i,999){
rep(j,10){
if (i%3==0) last = 20;
else if(j%2==0) last=19;
else last = 20;
rep(k,last){
every++;
}
}
}
}
int main(){
int n;
cin >> n;
make();
rep(i,n){
int y,m,d,count=0,last;
cin >> y >> m >> d;
rep(i,y){
rep(j,10){
if(i==y && j==m){
count += d;
cout << every-count+1 << endl;
break;
}
else{
if(i%3==0) last=20;
else if(j%2==0) last=19;
else last = 20;
}
rep(i,last) count++;
}
}
}
return 0;
} | 1 | 66,530,184 |
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
vector<int> num = {0,2,5,5,4,5,6,3,7,6};
vector<char> nchar = {'0','1','2','3','4','5','6','7','8','9'};
bool check(string s,string t){
int n1 = s.size(), n2 = t.size();
if(n1 > n2) return false;
if(n1 < n2) return true;
if(s > t) return false;
return true;
}
int main(){
int n,m; cin >> n >> m;
vector<string> dp;
vector<int> match(m);
rep(i,m) cin >> match[i];
dp.push_back("");
for(int i = 1;i <= n;++i){
string s = "";
rep(j,m) {
if(num[match[j]] <= i) {
if(dp[i-num[match[j]]] == "" && i != num[match[j]]) continue;
if(check(s,dp[i-num[match[j]]]+nchar[match[j]])) s = dp[i-num[match[j]]]+nchar[match[j]];
}
}
dp.push_back(s);
}
cout << dp[n] << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i < n; i++)
int main(){
int num[10];
num[1] = 2, num[2] = 5, num[3] = 5, num[4] = 4, num[5] = 5;
num[6] = 6, num[7] = 3, num[8] = 7, num[9] = 6;
int N, M;
cin >> N >> M;
int A[M];
rep(i, M){
cin >> A[i];
}
long long dp[N+1];
dp[0] = 0;
rep2(i, 1, N+1){
long long ans = -10000000000;
rep(j, M){
int k = i - num[A[j]];
if(k >= 0){
ans = max(ans, dp[k]+1);
}
}
dp[i] = ans;
}
sort(A, A+M, greater<int>());
long long n = dp[N];
long long x = N;
int res[n];
while(n > 0){
rep(i, M){
if(dp[x-num[A[i]]] == n-1){
x -= num[A[i]];
n--;
res[n] = A[i];
break;
}
}
}
for(int i = dp[N]-1; i >= 0; i--){
cout << res[i];
}
} | 1 | 99,586,648 |