code1
stringlengths 54
12k
| code2
stringlengths 71
12k
| similar
int64 0
1
| __index_level_0__
int64 0
101M
|
---|---|---|---|
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<(n);i++)
typedef long long ll;
ll gcd(ll a, ll b){
if(a<b) swap(a,b);
if(a%b == 0) return b;
else return gcd(b,a%b);
}
int main(){
int n; cin >> n;
int ans=0;
if(n>=105) ans++;
if(n>=135) ans++;
if(n>=165) ans++;
if(n>=189) ans++;
if(n>=195) ans++;
cout << ans << endl;
}
|
#include<bits/stdc++.h>
using namespace std;
int main(){
int w, h, x, y, r;
cin >> w >> h >> x >> y >> r;
int circle_left = x - r;
int circle_right = x + r;
int circle_top = y + r;
int circle_bottom = y - r;
if(circle_left < 0 || circle_right > w || circle_top > h || circle_bottom < 0){
cout << "No" << endl;
}else{
cout << "Yes" << endl;
}
}
| 0 | 98,177,623 |
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define rep(i,n) for(int i=0;i<n;++i)
#define repa(i,a,n) for(int i=a;i<n;++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define repba(i,b,a) for(int i=b;i>=a;--i)
#define repab(i,a,b) for(int i=a;i<b;++i)
#define ll long long
#define pi pair<int,int>
#define pii pair<pi,int>
#define ull unsigned long long
#define vi vector<int>
#define viip vector<pair<int,pair<int,int> > >
#define mp make_pair
#define vip vector<pair<int,int> >
#define pb push_back
#define fi first
#define sec second
#define all(v) v.begin(),v.end()
#define s(v) v.size()
ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll gcd(ll a,ll b){
if(b==0)return a;
return gcd(b,a%b);
}
ll fastexp(ll x,ll a){
ll res = 1;
while(a>0){
if(a&1){
res = (res*x)%mod;
}
a=a>>1;
x=(x*x)%mod;
}
return res;
}
ll inverse(ll n){
return fastexp(n,mod-2);
}
template <typename T>
void add(T &a, T b){
a += b;
if(a >= mod)a -= mod;
}
template <typename T>
void sub(T &a, T b){
a -= b;
if(a < 0)a += mod;
}
template <typename T>
void mul(T &a, T b){
a *= b;
if(a >= mod)a %= mod;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin>>n;
string s;
cin>>s;
int c = 0;
rep(i,n){
int j = i;
c++;
while(j+1 < n && s[j+1] == s[i]){
j++;
}
i = j;
}
cout<<c;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main(void) {
int X, N;
cin >> X >> N;
vector<int> p(N);
for (int i = 0; i < N; i++) cin >> p.at(i);
for (int i = 0; i <= 50; i++) {
bool flag1 = true;
bool flag2 = true;
for (int j = 0; j < N; j++) {
if (X - i == p.at(j)) {
flag1 = false;
}
if (X + i == p.at(j)) {
flag2 = false;
}
}
if (flag1) {
cout << X - i << endl;
break;
} else if (flag2) {
cout << X + i << endl;
break;
}
}
}
| 0 | 76,704,759 |
#include <bits/stdc++.h>
using namespace std;
int main(void){
ios::sync_with_stdio(false);
cin.tie(0);
cout<<fixed<<setprecision(15);
long long n;
cin>>n;
if(n%2!=0){
cout<<0<<endl;
return 0;
}
long long ans=0,fives=10;
while(fives<=n){
ans+=n/fives;
fives*=5;
}
cout<<ans<<endl;
return 0;
}
|
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
long long int mod = (long long int)1000000007;
using namespace std;
void solve()
{
ll i,j,k,n;
std::cout.precision(10);
string s;
cin>>s;
n=s.size();
int yes=1;
int l=0,r=n-1;
while(l<r)
{
if(s[l]!=s[r])
{
yes=0;
}
l++;
r--;
}
l=0;
r=(n-1)/2-1;
while(l<r)
{
if(s[l]!=s[r])
{
yes=0;
}
l++;
r--;
}
l=(n+3)/2-1;
r=(n-1);
while(l<r)
{
if(s[l]!=s[r])
{
yes=0;
}
l++;
r--;
}
if(yes==1)
{
cout<<"Yes";
}
else
{
cout<<"No";
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int i,j,k;
int t;
std::cout.precision(10);
t=1;
while(t--)
{
solve();
cout<<"\n";
}
}
| 0 | 35,836,693 |
#include <stdio.h>
int main() {
int n,k;
int angka = 1;
scanf("%d %d", &n, &k);
for(int i = 0; i < n; i++) {
(angka+k>angka*2) ? angka *= 2 : angka += k;
}
printf("%d\n", angka);
return 0;
}
|
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
#define ll long long
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define si size()
#define bk back()
#define popb pop_back()
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"
#define lb lower_bound
#define ub upper_bound
#define emp empty()
#define beg begin()
#define en end()
#define ump unordered_map
#define forl(i,a,n) for(int i=a;i<n;i++)
#define rfor(i,n,a) for(int i=n;i>=a;i--)
#define fore(i,a,n) for(int i=a;i<=n;i++)
#define len length()
#define ld long double
const long double PI=3.14159265358979323846;
double doINF = 1.0/0.0 ;
ostream_iterator <int> outp(cout," ");
inline ll modadd(ll n,ll m,ll mod){
ll sum = (((n%mod)+(m%mod))%mod+mod)%mod;
return sum;
}
inline ll modsub(ll n,ll m, ll mod){
ll diff = (((n%mod)-m+mod)%mod+mod)%mod;
return diff;
}
inline ll modpro(ll n,ll m,ll mod){
ll pro = ((((n+mod)%mod)*((m+mod)%mod)+mod)%mod+mod)%mod;
return pro;
}
inline ll pow(int x,int y){
ll res = 1;
while (y > 0) {
if (y & 1)
res = res * x;
y = y >> 1;
x = x * x;
}
return res;
}
inline ll powmod(ll x,ll y,ll mod){
ll res = 1;
while (y > 0) {
if (y & 1)
res = modpro(res , x,mod);
y = y >> 1;
x = modpro(x , x,mod);
}
return res;
}
long long power(long long a,long long b)
{
if(b==0) return 1;
long long p = power(a, b/2);
if(b&1) return p*p*a;
else return p*p;
}
ll min(ll a, ll b){
if(a>b){
return b;
}
return a;
}
ll max(ll a, ll b){
if(a>b){
return a;
}else return b;
}
bool pairdec(const pair<int,int> &a,
const pair<int,int> &b)
{ if(a.fi!=b.fi)
return (a.fi> b.fi);
else return a.se>b.se;
}
ll power(ll x, ll y, ll mod)
{
ll res = 1;
x = (x+mod)%mod;
while (y > 0) {
if (y & 1)
res =modpro(res,x,mod);
y = y >> 1;
x =modpro(x,x,mod);
}
return res;
}
ll modInverse(ll a, ll mod)
{
return powmod(a, mod - 2, mod);
}
ll modFact(ll n, ll mod)
{
if (n >=mod) return 0;
ll result = 1;
for (ll i = 1; i <= n; i++)
result = (result * i) %mod;
return result;
}
ll modcomb(ll n,ll r, ll mod)
{
if (r==0) return 1;
ll val1=modFact(n,mod);
ll val2=modInverse(modFact(r,mod),mod);
ll val3=modInverse(modFact(n-r,mod),mod);
ll val4=modpro(val1,val2,mod);
return modpro(val4,val3,mod);
}
void modInverse2(ll n,ll mod)
{
ll dp[n+1];
dp[0]=dp[1]=1;
fore(i,2,n)
{
dp[i]=dp[mod%i]*((mod-mod/i)%mod);
}
}
bool comp(const pair<int,int>pia,const pair<int,int>pib)
{
if(pia.fi==pib.fi) return pia.se<=pib.se;
else return pia.fi<pib.fi;
}
ll mod=1e9+7;
int main()
{
ll n,k;
cin>>n>>k;
ll ans=0;
ll t=k;
while(t<=n)
{
ll val=modpro(t,(n-t+1),mod);
ans=modadd(ans,val,mod);
ans=modadd(ans,1,mod);
t++;
}
ans=modadd(ans,1,mod);
cout<<ans<<endl;
}
| 0 | 43,788,721 |
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
ll n;
cin >> n;
map<ll,ll> a;
vector<ll> m;
for(ll i=0;i<n;++i){
ll num;
cin >> num;
a[num]++;
if( a[num] == 1 ) m.push_back(num);
}
sort(m.begin(),m.end());
reverse(m.begin(),m.end());
ll cnt = 0;
ll ans = 1;
ll ans2 = 0;
for(ll i=0;i<a.size();++i){
ll num = m.at(i);
if( a[num] >= 4 && ans2 == 0 ){
ans2 = num*num;
}
if( a[num] >= 2 && cnt != 2 ){
cnt++;
ans *= num;
}
}
if( cnt != 2 && ans2 == 0 ){
cout << 0 << endl;
}else{
cout << max(ans,ans2) << endl;
}
return 0;
}
|
#include "bits/stdc++.h"
using namespace std;
void Main() {
int A, B;
cin >> A >> B;
int ans = 0;
for (int i = A; i <= B; ++i) {
string s = to_string(i);
if (s[0] == s[4] && s[1] == s[3]) {
++ans;
}
}
cout << ans << endl;
}
int main() {
std::cout << std::fixed << std::setprecision(15);
Main();
return 0;
}
| 0 | 54,001,872 |
#include<bits/stdc++.h>
using namespace std ;
template <typename A, typename B>
string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(const string& s) {
return '"' + s + '"';
}
string to_string(const char* s) {
return to_string((string) s);
}
string to_string(bool b) {
return (b ? "true" : "false");
}
string to_string(vector<bool> v) {
bool first = true;
string res = "{";
for (int i = 0; i < static_cast<int>(v.size()); i++) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(v[i]);
}
res += "}";
return res;
}
template <size_t N>
string to_string(bitset<N> v) {
string res = "";
for (size_t i = 0; i < N; i++) {
res += static_cast<char>('0' + v[i]);
}
return res;
}
template <typename A>
string to_string(A v) {
bool first = true;
string res = "{";
for (const auto &x : v) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(x);
}
res += "}";
return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
#ifndef ONLINE_JUDGE
#define debug(...) cerr<<"LINE ("<< __LINE__ << ") : [" << #__VA_ARGS__ << "] -> ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
vector<int> a = {111, 222, 333, 444, 555, 666, 777, 888, 999};
int n;
cin >> n;
auto it = lower_bound(a.begin(), a.end(), n);
cout << *it;
return 0;
}
|
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using Order_Set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define PI acos(-1.0)
#define O_O \
ios_base::sync_with_stdio(false); \
cin.tie(NULL)
#define precision(a) fixed << setprecision(a)
#define endl '\n'
#define Flush cout << flush
#define LLMX 0x3fffffffffffffff
long long N;
int main()
{
O_O;
string S;
cin >> S;
string mask1;
string mask2;
for (int i = 0; i < S.size(); i++)
{
if (i % 2 == 0)
mask1.push_back('0'), mask2.push_back('1');
else
mask1.push_back('1'), mask2.push_back('0');
}
long long ans = S.size(), x = 0, y = 0;
for (int i = 0; i < S.size(); i++)
{
if (S[i] != mask1[i])
x++;
if (S[i] != mask2[i])
y++;
}
cout << min(x, y) << endl;
return 0;
}
| 0 | 47,276,955 |
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define debug(var) cerr << #var << " = " << var << endl;
#else
#define debug(var)
#endif
void init() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
}
void solve() {
int a, b; cin >> a >> b;
if (a%3 == 0 || b%3 == 0 || (a+b)%3 == 0) cout << "Possible";
else cout << "Impossible";
}
int main() {
init();
int t = 1;
while (t--) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#ifdef DEBUG_MODE
#define DEBUG(...) debug_func_mult(split_names(#__VA_ARGS__), __VA_ARGS__)
#define DEBUG_ENDL endl << flush
#define DEBUG_SEPARATOR_LINE cout<<"=================\n"
#else
#define DEBUG(...) 0
#define DEBUG_ENDL 0
#define DEBUG_SEPARATOR_LINE 0
#endif
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
#define DEBUG_ENDL_S(S) ((S).size() ? "\n" : "") << flush;
template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T, typename U> using P = pair<T, U>;
using ll = int64_t;
using PLL = P<ll, ll>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename Head, typename... Tail> const Head& var_min(const Head &head, const Tail&... tail) { return min(head, var_min(tail...)); }
template <typename Head, typename... Tail> const Head& var_max(const Head &head, const Tail&... tail) { return max(head, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
string to_string(const string &s) { return s; }
template <typename T, typename U>
string to_string(const P<T, U> &p) {
string ret = "(";
ret += to_string(p.first);
ret += ", ";
ret += to_string(p.second);
ret += ")";
return move(ret);
}
template <typename T>
string to_string(const V<T> &v) {
string ret = "{";
for(const T &t : v) {
ret += to_string(t);
ret += ", ";
}
ret += "}";
return move(ret);
}
template <typename T>
void debug_func(const T &t, const string &s = "") {
if(s.size()) cout << s << " = ";
cout << to_string(t) << DEBUG_ENDL_S(s);
}
template <typename T>
void debug_func_mult(int idx, const V<string> &names, const T &t) {
debug_func(t, names[idx]);
}
template <typename T>
void debug_func_mult(const V<string> &names, const T &t) {
debug_func(t, names[0]);
}
template <typename Head, typename... Tail>
void debug_func_mult(int idx, const V<string> &names, const Head &head, const Tail&... args) {
debug_func(head, names[idx]);
debug_func_mult(idx + 1, names, args...);
}
template <typename Head, typename... Tail>
void debug_func_mult(const V<string> &names, const Head &head, const Tail&... args) {
debug_func(head, names[0]);
debug_func_mult(1, names, args...);
}
V<string> split_names(string &&s) {
replace(ALL(s), ' ', ',');
V<string> ret;
istringstream ss(s);
string t;
while(getline(ss, t, ',')) if(t.size()) ret.push_back(move(t));
return move(ret);
}
void init_io() {
cin.tie(0);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(30);
}
ll H, W, D;
V<string> ans;
void set_color(ll h, ll left, ll right, char c) {
if(!(0 <= h && h < H)) return;
for(ll w = left; w < right; w++) {
if(!(0 <= w && w < W)) continue;
ans[h][w] = c;
}
}
void solve() {
cin >> H >> W >> D;
ans = V<string>(H, string(W, '.'));
VV<char> color = {
{ 'R', 'Y' },
{ 'G', 'B' },
{ 'Y', 'R' },
{ 'B', 'G' },
};
if(D & 1) {
string s = "RYGB";
for(ll i = 0; i < H; i++) for(ll j = 0; j < W; j++) ans[i][j] = s[(j - i + 4444444444ll) % 4];
return;
}
ll cidx = 0;
for(ll uh = -(!(D & 1)); uh < H + D; uh += D / 2) {
ll dh = uh;
for(ll delh = 0; delh < D / 2; delh++) {
ll len = D - 2 * delh;
ll ccidx = 0;
ll left = delh;
if(cidx % 4 % 2 == 0) left -= D / 2;
for(; left < W; left += D) {
char col = color[cidx % 4][ccidx % 2];
ccidx++;
ll right = left + len;
for(ll j = left; j < right; j++) {
set_color(uh - delh, left, right, col);
set_color(dh + delh, left, right, col);
}
}
}
cidx++;
}
}
inline void debug() {
#ifdef DEBUG_MODE
for(auto &s : ans) for(char &c : s) if(c != 'R') c = '.';
#endif
}
int main() {
init_io();
solve();
debug();
for(const auto &s : ans) cout << s << endl;
return 0;
}
| 0 | 88,770,432 |
#include<stdio.h>
#include<string.h>
#include<ctype.h>
int main()
{
char a[1000],b[1000],c[10000];
int size=0,sp,i;
scanf("%s",&a);
scanf("%s",&b);
scanf("%s",&c);
a[0]=a[0]-32;
b[0]=b[0]-32;
c[0]=c[0]-32;
printf("%c",a[0]);
printf("%c",b[0]);
printf("%c",c[0]);
}
|
#include <bits/stdc++.h>
using namespace std;
#define hs ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = 1e18;
const ll MAX = 100001;
void solve(){
int a, b;
cin>>a>>b;
a = max(a, b);
b = max(b, a);
if(a+b <= 16)
cout<<"Yay!";
else
cout<<":(";
}
int main(){
hs;
ll t;
t=1;
for (int i=1; i<=t; i++){
solve();
}
return 0;
}
| 0 | 55,500,024 |
#include <iostream>
int main() {
long long n, a, b;
std::cin >> n >> a >> b;
if (n == 1 || a > b)
std::cout << (a == b ? 1 : 0) << '\n';
else
std::cout << b * (n - 2) + a * (2 - n) + 1 << '\n';
}
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
int main(){
int n;
cin >> n;
vector<int> p(n);
rep(i, n) cin >> p[i];
int ans = 0;
int min = 10010010;
rep(i, n){
if(p[i] > min){
continue;
}else{
ans++;
}
if(min > p[i]){
min = p[i];
}
}
cout << ans << endl;
return 0;
}
| 0 | 23,113,713 |
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
using namespace std;
using ll = long long;
const ll MOD = 1000000007LL;
const double PI = 3.14159265358979;
void solve()
{
ll n, k;
cin >> n >> k;
if (n == k) cout << 1;
else cout << 1 + (n - k - 1) / (k - 1) + 1;
}
int main()
{
fastio;
solve();
return 0;
}
|
#include<stdio.h>
#include<iostream>
#include<string>
#include<memory>
#include<cmath>
#include<algorithm>
#include<vector>
int main(){
int N,K;
std::cin>>N>>K;
double ans=0;
double cal=0;
for(int i=1;i<=N;i++){
int ed=0;
int score=i;
double coin=1.0;
while(score<K){
score*=2;
coin/=2;
}
cal+=coin;
}
ans=cal/N;
printf("%.12f\n",ans);
return 0;
}
| 0 | 44,345,876 |
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}
void solve() {
int N;
cin >> N;
vector<double> T(N), V(N);
double tmax = 0;
for (int i = 0; i < N; i++) {
cin >> T[i];
tmax += T[i];
}
for (int i = 0; i < N; i++) {
cin >> V[i];
}
map<double, double> ma;
for(double t = 0.0; t <= tmax; t += 0.5) {
ma[t] = t;
}
for(double t = tmax; t >= 0; t -= 0.5) {
ma[t] = min(ma[t], tmax - t);
}
double s = 0;
for (int i = 0; i < N; i++) {
double t = s + T[i];
for(double x = s; x >= 0; x -= 0.5) {
ma[x] = min(ma[x], V[i] + s - x);
}
for(double x = t; x <= tmax; x += 0.5) {
ma[x] = min(ma[x], V[i] + x - t);
}
for(double x = s; x <= t; x += 0.5) {
ma[x] = min(ma[x], V[i]);
}
s = t;
}
vector<double> A;
for(auto m : ma) {
A.push_back(m.second);
}
double ans = 0;
for (int i = 0; i + 1 < A.size(); i++) {
ans += (A[i] + A[i + 1]) / 4.0;
}
cout << ans << endl;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout.setf(ios::fixed);
cout.precision(16);
solve();
return 0;
}
|
#include <iostream>
#include <vector>
#include <cmath>
using ll = long long;
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
const int MAX = 1100000;
const int mod = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit(){
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++){
fac[i] = fac[i - 1] * i % mod;
inv[i] = mod - inv[mod%i] * (mod / i) % mod;
finv[i] = finv[i - 1] * inv[i] % mod;
}
}
long long COM(int n, int k){
if (n < k) return 0;
if (n < 0 || k < 0) return 0;
return fac[n] * (finv[k] * finv[n-k] % mod) % mod;
}
int main(){
ll x, y;
cin >> x >> y;
if ((x + y) % 3 == 0){
ll n = (x + y) / 3;
ll m = abs(x - y);
ll r = (n + m) / 2;
COMinit();
cout << COM(n, r) << endl;
}
else {
cout << 0 << endl;
}
return 0;
}
| 0 | 41,810,075 |
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long int
#define all(v) v.begin(),v.end()
#define rev(v) v.rbegin(),v.rend()
#define ssd ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define ordered_set tree<ll, null_type, less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define trace(x) cerr<<#x<<" : "<<x<<endl;
#define inp 100005
#define en "\n"
using namespace std;
using namespace __gnu_pbds;
signed main()
{
ssd
int i,j,n,k;
cin>>n>>k;
vector<int> val(n+5);
for(i=1;i<=n;i++) cin>>val[i];
vector<vector<int>> dp(n+5, vector<int>(k+5,0));
for(i=0;i<=n;i++) dp[i][0]=1;
int pre[k+5];
for(i=1;i<=n;i++)
{
memset(pre,0,sizeof(pre));
pre[0] = 1;
for(j=1;j<=k;j++)
{
pre[j] = pre[j-1] + dp[i-1][j];
pre[j] %= mod;
}
for(j=1;j<=k;j++)
{
int r = j;
int l = max(j-val[i], (int)0);
if(l!=0)
{
l--;
dp[i][j] = pre[r] - pre[l];
}
else
{
dp[i][j] = pre[r];
}
dp[i][j] = (dp[i][j] + mod) % mod;
}
}
cout<<dp[n][k];
return 0;
}
|
#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(0);cout.tie(0);cin.tie(0);srand(time(NULL));
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
signed main(){
io();
int h, a; cin >> h >> a;
int ans = 0;
vector<int> v(a);
for(int i = 0; i < a; ++i){
cin >> v[i];
ans += v[i];
}
cout << (ans >= h ? "Yes" : "No") << '\n';
return 0;
}
| 0 | 79,444,537 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int k,s;
cin >> k >> s;
int x,y,z,ans=0;
for(x=0;x<=k;x++){
if(x>s){
break;
}
for(y=0;y<=k;y++){
if(s-x-y<0){
break;
}else if(s-x-y<=k){
ans++;
}
}
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
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; }
ll n, Q, k;
struct treedata {
int pos; ll dist;
};
vector< vector<treedata> > graphlist(100100, vector<treedata>());
vector<ll> distgraph(100100, -1);
int main() {
cin >> n;
for(int i = 0; i < n-1; ++i) {
int aa, bb;
ll cc;
cin >> aa >> bb >> cc;
aa--; bb--;
treedata indata;
indata.pos = bb; indata.dist = cc;
graphlist.at(aa).emplace_back(indata);
indata.pos = aa;
graphlist.at(bb).emplace_back(indata);
}
cin >> Q >> k;
k--;
queue<treedata> que;
treedata first;
first.pos = k; first.dist = 0;
que.push(first);
distgraph.at(k) = 0;
while(!que.empty()) {
treedata now = que.front();
que.pop();
for(int i = 0; i < (int)graphlist.at(now.pos).size(); ++i) {
int npos = graphlist.at(now.pos).at(i).pos;
ll ndist = graphlist.at(now.pos).at(i).dist + now.dist;
if(distgraph.at(npos) == -1) {
distgraph.at(npos) = ndist;
treedata next;
next.pos = npos; next.dist = ndist;
que.push(next);
}
}
}
for(int i = 0; i < Q; ++i) {
int xx, yy;
cin >> xx >> yy;
xx--; yy--;
ll ans = 0;
ans += distgraph.at(xx);
ans += distgraph.at(yy);
cout << ans << endl;
}
}
| 0 | 18,761,601 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int h1, m1, h2, m2, k;
cin >> h1 >> m1 >> h2 >> m2 >> k;
int dh = h2 - h1;
int dm = m2 - m1;
int res = dh * 60 + dm;
cout << res - k << '\n';
return 0;
}
|
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
using namespace std;
constexpr int64_t MOD = 998'244'353;
int main(void) {
int N;
cin >> N;
vector<int> D(N);
for(int i=0; i<N; i++) {
cin >> D[i];
}
if(D[0] != 0) {
cout << 0 << endl;
return 0;
}
vector<int64_t> num(N);
for(int i=0; i<N; i++) {
num[D[i]]++;
}
if(num[0] != 1) {
cout << 0 <<endl;
return 0;
}
int64_t ans = 1;
int max = *max_element(D.begin(), D.end());
for(int i=0; i<max; i++) {
for(int j=0; j<num[i+1]; j++) {
ans = (ans*num[i]) % MOD;
}
}
cout << ans << endl;
return 0;
}
| 0 | 8,642,984 |
#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;
string word, previous_word;
bool flag = true;
map<string, bool> history;
cin >> previous_word;
history[previous_word] = true;
rep(i, n - 1) {
cin >> word;
if(word[0] != previous_word[previous_word.size() - 1]) {
flag = false;
} else if(history[word]) {
flag = false;
}
previous_word = word;
history[previous_word] = true;
}
if(flag)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i,l,r) for(i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define P pair<ll,ll>
#define F first
#define S second
signed main(){
ll N,i,j,ans=0;cin>>N;
vector<P>BLUE(N),RED(N);
REP(i,N)cin>>RED.at(i).S>>RED.at(i).F;
REP(i,N)cin>>BLUE.at(i).F>>BLUE.at(i).S;
sort(ALL(BLUE));sort(ALL(RED));reverse(ALL(RED));
REP(i,N)REP(j,N)if(BLUE.at(i).F>RED.at(j).S&&BLUE.at(i).S>RED.at(j).F){
RED.at(j)=P(2*N,2*N);ans++;break;
}
cout<<ans<<endl;
return 0;
}
| 0 | 23,985,184 |
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
int main(){
int a,b,c,d;
cin >> a >> b >> c >> d ;
bool q = true;
if(abs(a-c) >d){
if(abs(a-b)>d|| abs(b-c) >d){
q = false;
}
}
if(q ==true)cout << "Yes" << endl;
else cout << "No" << endl;
}
|
#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll a,b,c,d,e,n,k,maxi=0,f=0,mini=INF,sum=0,q;
string str,stra,straa;
ll x,y,w,z;
char ca,cb,cc;
cin>>a;
if(1200>a) cout<<"ABC"<<endl;
else if(2800>a) cout<<"ARC"<<endl;
else cout<<"AGC"<<endl;
return 0;
}
| 0 | 86,428,358 |
#include <bits/stdc++.h>
#define rep0(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<string, int, int> TU;
typedef tuple<int, int, int> TI;
int main()
{
int A,B,X;
cin >> A >> B >> X;
if(A<=X&&X<=A+B){
cout << "YES" << endl;
}else{
cout << "NO" << endl;
}
}
|
#include <bits/stdc++.h>
#define boost_io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define int long long
#define num(a) a-'0'
#define charr(a) (a - 'A' + 1)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define maxs(a,b) if(b>a)a=b
#define mins(a,b) if(b<a)a=b
#define debug(x) cerr<<"["<<#x<<":"<<x<<"] "
#define debug2(a,b) debug(a);debug(b)
#define debug3(a,b,c) debug2(a,b);debug(c)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/(__gcd(a,b))
#define print(arr) for(auto it = arr.begin();it < arr.end();it ++){cout << *it << " ";}cout << ln;
#define all(a) (a).begin(), (a).end()
#define vi vector<long long>
#define v vector
#define p pair
#define pb push_back
#define mk make_pair
#define f first
#define s second
#define ln "\n"
typedef long double ld;
typedef double d;
using namespace std;
int modF=1e9+7;
int INF=1e11;
void solve(){
string s;
cin>>s;
int k;
cin>>k;
int l=s.length();
int ans=1;
int li=-1;
rep(i,0,l){
if(s[i]!='1'){
ans=num(s[i]);
break;
}
else{
li=i+1;
}
}
if(k<=li)
ans=1;
cout<<ans<<ln;
}
signed main(){
boost_io;
solve();
return 0;
}
| 0 | 35,359,989 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265359
bool isPrime(int num){
if (num < 2) return false;
else if (num == 2) return true;
else if (num % 2 == 0) return false;
double sqrtNum = sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2){
if (num % i == 0) return false;
}
return true;
}
int main(){
ll n,m;
cin >> n >> m;
vector<bool> ok(n);
vector<int> pena(n);
rep(i,n) ok[i] = false;
rep(i,n) pena[i] = 0;
int penalty = 0;
int answer = 0;
rep(i,m){
int p; string s;
cin >> p >> s;
if(!ok[p-1] && s == "WA"){
pena[p-1]++;
}
if(!ok[p-1] && s == "AC"){
penalty += pena[p-1];
answer++;
ok[p-1] = true;
}
}
cout << answer << " " << penalty << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, start, n) for (int i = (int)(start); i < (int)(n); ++i)
static const int INFTY = (1 << 30);
int N, M;
void func()
{
cin>>N;
ll a[N];
rep(i, 0, N)cin>>a[i];
ll dp[N]={};
dp[0]=1000;
rep(i, 1, N) {
dp[i]=dp[i-1];
rep(j, 0, i) {
dp[i]=max(dp[i], dp[j]+(a[i]-a[j])*(dp[j]/a[j]));
}
}
cout<<dp[N-1]<<endl;
}
int main()
{
func();
}
| 0 | 26,016,349 |
#include <iostream>
using namespace std;
const int MAXN=1e3+7;
const long long MOD=1e9+7;
int h,w,f[MAXN][MAXN];
char a[MAXN][MAXN];
int main()
{
ios_base::sync_with_stdio(false),cin.tie(0);
cin>>h>>w;
for(int i=1;i<=h;i++) cin>>(a[i]+1);
f[0][1]=1;
for(int i=1;i<=h;i++)
for(int j=1;j<=w;j++)
if(a[i][j]!='#')
f[i][j]=(f[i-1][j]+f[i][j-1])%MOD;
cout<<f[h][w]<<endl;
return 0;
}
|
#line 1 "test/atcoder/practive2-a.cpp"
#include <iostream>
#include <atcoder/dsu>
using namespace std;
using namespace atcoder;
int main() {
int n, q; cin >> n >> q;
dsu d(n);
for (int i = 0; i < q; ++i) {
int t, u, v; cin >> t >> u >> v;
if (t == 0) {
d.merge(u, v);
}
else {
cout << d.same(u, v) << endl;
}
}
}
| 0 | 60,260,853 |
#include<bits/stdc++.h>
#define INF 2147483647
#define SYOU(x) setprecision(x)
using namespace std;
long long i[300000];
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
long long a,b,c,d=0,e=0;
string s;
cin >>s;
if(s[0]=='Y'&&s[1]=='A'&&s[2]=='K'&&s[3]=='I') cout <<"Yes\n";
else cout <<"No\n";
return (0);
}
|
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <stdio.h>
#include <math.h>
#include <iomanip>
#include <queue>
#include <string.h>
#include <string>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define endl "\n"
#define lb lower_bound
#define ub upper_bound
#define fo(i,a,b) for(i=a;i<b;i++)
#define all(v) (v).begin(),(v).end()
#define sort0(v) sort(all(v))
#define lbb(a,b,arr,x) lower_bound(arr+a,arr+b+1,x)-arr
#define ubb(a,b,arr,x) upper_bound(arr+a,arr+b+1,x)-arr
#define freq(a,b,arr,x) upper_bound(arr+a,arr+b+1,x)-lower_bound(arr+a,arr+b+1,x)
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define d0(x) cout<<(x)<<" "
#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 d5(a,b,c,d,e) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<" "<<(e)<<endl
#define d6(a,b,c,d,e,f) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<" "<<(e)<<" "<<(f)<<endl
#define max3(a,b,c) max(max((a),(b)),(c))
#define max4(a,b,c,d) max(max((a),(b)),max((c),(d)))
#define ss second
#define ff first
#define pb push_back
#define mp make_pair
#define printp(x) cout << x.ff << " " << x.ss << endl
const ll mod=998244353;
#define inf 9999999999999
#define MAXN 100001
ll inv(ll i){if(i==1) return 1;return (mod-((mod/i)*inv(mod%i))%mod)%mod;}
ll gcd(ll a,ll b){if(a==0) return b;return gcd(b,b%a);}
inline void fastio(){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
const int MN = 2e5+7;
int main(){
fastio();
char a,b; cin>>a>>b;
int val=a-'0';
int val1=b-'0';
string p,q;
for(int i=0;i<val;i++){
p+=b;
}
for(int i=0;i<val1;i++){
q+=a;
}
if(p>q){
cout<<q<<endl;
}else{
cout<<p<<endl;
}
return 0;
}
| 0 | 28,388,825 |
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
using pi=pair<int,int>;
using vi=vc<int>;
signed main() {
cin.tie(0);
ios::sync_with_stdio(0);
cout<<fixed<<setprecision(20);
int A,B; cin >> A >> B;
char c[100][100];
rep(i,50){
rep(j,100){
c[i][j]='#';
}
}
rng(i,50,100){
rep(j,100){
c[i][j]='.';
}
}
int cnt=A-1;
for(int i=1;i<50;i+=2){
for(int j=1;j<100;j+=2){
if(cnt==0) break;
c[i][j]='.';
cnt--;
}
if(cnt==0) break;
}
cnt=B-1;
for(int i=51;i<100;i+=2){
for(int j=1;j<100;j+=2){
if(cnt==0) break;
c[i][j]='#';
cnt--;
}
if(cnt==0) break;
}
cout << 100 << " " << 100 << endl;
rep(i,100) {
rep(j,100){
cout << c[i][j];
}
cout << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
#define mod 998244353
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fll
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
const int maxn=2e5+10;
int n;
int A[maxn];
map<int,int> mp;
vector<int> ids,toe;
bool check(int ans)
{
mp.clear();
for(int i=0;i<ids.size();i++)
{
int pos=A[ids[i]];
toe.clear();
for(map<int,int>::iterator it=mp.begin();it!=mp.end();it++)
{
if(it->first>pos)toe.push_back(it->first);
}
for(int j=0;j<toe.size();j++)
mp.erase(toe[j]);
while(pos>=1&&mp.count(pos)&&mp[pos]+1>=ans)pos--;
if(pos<1)pos=1;
mp[pos]++;
if(mp[pos]>=ans)return 0;
toe.clear();
for(map<int,int>::iterator it=mp.begin();it!=mp.end();it++)
{
if(it->first>pos)toe.push_back(it->first);
}
for(int j=0;j<toe.size();j++)
mp.erase(toe[j]);
}
return 1;
}
int main()
{
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%d",&A[i]);
if(i&&A[i]<=A[i-1])
ids.push_back(i);
}
int l=0,r=n;
while(r-l>1)
{
int mid=(l+r)/2;
if(check(mid))r=mid;
else l=mid;
}
printf("%d\n",r);
return 0;
}
| 0 | 61,793,354 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<n; i++)
#define pb push_back
#define int long long
char C[2][3];
signed main() {
cin.tie(0); ios::sync_with_stdio(false);
rep(i, 2) rep(j, 3) cin >> C[i][j];
if (C[0][0]==C[1][2] && C[0][1]==C[1][1] && C[0][2]==C[1][0]) cout << "YES" << endl;
else cout << "NO" << endl;
}
|
#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 N;cin>>N;
vector<double>x(N);
vector<string>u(N);
double ans=0;
rep(i,N){
cin>>x.at(i)>>u.at(i);
}
rep(i,N){
if(u.at(i)=="JPY"){
ans+=x.at(i);
}else{
ans+=x.at(i)*380000.0;
}
}
cout<<ans<<endl;
}
| 0 | 59,184,573 |
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
int main() {
int N;
cin >> N;
vector<ll> L(87);
L.at(0) = 2;
L.at(1) = 1;
for (int i = 2; i <= N; i++) {
L.at(i) = L.at(i - 1) + L.at(i - 2);
}
cout << L.at(N) << endl;
return 0;
}
|
#include<cstdio>
#include<iostream>
using namespace std;
int n,s,ans=0;
class SumofIntegers{
public:
void solve(){
dfs(0,0,0);
cout<<ans<<endl;
ans=0;
}
void dfs(int d,int sum,int idx){
if(d==n){
if(sum==s)ans++;
return;
}
for(int i=idx;i<10;i++)dfs(d+1,sum+i,i+1);
}
};
int main(){
SumofIntegers inst;
while(cin>>n>>s){
if(n==0&&s==0)break;
inst.solve();
}
}
| 0 | 75,154,460 |
#include <iostream>
#include <string>
#include <list>
using namespace std;
int
main()
{
ios_base::sync_with_stdio(false);
int n;
cin >> n; cin.ignore();
list<int> lst;
for (int i = 0; i < n; i++) {
string cmd;
getline(cin, cmd);
switch (cmd[6]) {
case 'F':
lst.pop_front();
break;
case 'L':
lst.pop_back();
break;
default:
int k = stoi(cmd.substr(7));
if(cmd[0] == 'i') {
lst.push_front(k);
} else {
for (auto it = lst.cbegin(); it != lst.cend(); it++) {
if (*it == k) {
lst.erase(it);
break;
}
}
}
}
}
for (auto it = lst.begin(); it != lst.end(); it++) {
if (it != lst.begin()) { cout << ' '; }
cout << *it;
}
cout << endl;
return 0;
}
|
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
int main() {
ll h, w;
cin >> h >> w;
vvl dp(h+1, vl(w+1));
rep(i, h) {
string s;
cin >> s;
rep(j, w) {
if(s[j] == '.') {
dp[i+1][j+1] = -1;
}
}
}
dp[1][1] = 1;
exrep(i, 1, h) {
exrep(j, 1, w) {
if(dp[i][j] == -1) {
dp[i][j] = dp[i-1][j] + dp[i][j-1];
dp[i][j] %= mod;
}
}
}
out(dp[h][w]);
re0;
}
| 0 | 39,184,302 |
#include <iostream>
using namespace std;
int lcs(string X, string Y) {
X = ' ' + X;
Y = ' ' + Y;
int memo[1010][1010];
int maxl = 0;
for (int i = 0; i < X.size(); i++) memo[i][0] = 0;
for (int j = 0; j < Y.size(); j++) memo[0][j] = 0;
for (int i = 1; i < X.size(); i++) {
for (int j = 1; j < Y.size(); j++) {
if (X[i] == Y[j]) {
memo[i][j] = memo[i-1][j-1] + 1;
} else {
memo[i][j] = max(memo[i-1][j], memo[i][j-1]);
}
maxl = max(maxl, memo[i][j]);
}
}
return maxl;
}
int main() {
int q; cin >> q;
for (int i = 0; i < q; i++) {
string X, Y; cin >> X >> Y;
cout << lcs(X, Y) << endl;
}
}
|
#include<iostream>
#include<string>
#include<cstring>
using namespace std;
string S,R;
char T[5]="ACGT";
int U,a,q;
int power[12]={1,4,16,64,256,1024,4096,16384,65536,262144,1048576,4194304};
bool V;
bool x1[4];
bool x2[16];
bool x3[64];
bool x4[256];
bool x5[1024];
bool x6[4096];
bool x7[16384];
bool x8[65536];
bool x9[262144];
bool x10[1048576];
bool x11[4194304];
bool x12[16777216];
void insert(){
U=0;
for(int i=0;i<S.size();i++){
for(int j=0;j<4;j++){
if(T[j]==S[i]){
U += power[i]*j;
}
}
}
a=S.size();
if(a==1){
x1[U]=true;
}
if(a==2){
x2[U]=true;
}
if(a==3){
x3[U]=true;
}
if(a==4){
x4[U]=true;
}
if(a==5){
x5[U]=true;
}
if(a==6){
x6[U]=true;
}
if(a==7){
x7[U]=true;
}
if(a==8){
x8[U]=true;
}
if(a==9){
x9[U]=true;
}
if(a==10){
x10[U]=true;
}
if(a==11){
x11[U]=true;
}
if(a==12){
x12[U]=true;
}
}
void find(){
U=0;
V=false;
for(int i=0;i<S.size();i++){
for(int j=0;j<4;j++){
if(T[j]==S[i]){
U += power[i]*j;
}
}
}
a=S.size();
if(a==1 && x1[U]==true){
V=true;
}
if(a==2 && x2[U]==true){
V=true;
}
if(a==3 && x3[U]==true){
V=true;
}
if(a==4 && x4[U]==true){
V=true;
}
if(a==5 && x5[U]==true){
V=true;
}
if(a==6 && x6[U]==true){
V=true;
}
if(a==7 && x7[U]==true){
V=true;
}
if(a==8 && x8[U]==true){
V=true;
}
if(a==9 && x9[U]==true){
V=true;
}
if(a==10 && x10[U]==true){
V=true;
}
if(a==11 && x11[U]==true){
V=true;
}
if(a==12 && x12[U]==true){
V=true;
}
if(V==true){
cout<<"yes"<<endl;
}
else{
cout<<"no"<<endl;
}
}
int main(){
cin>>q;
for(int i=0;i<q;i++){
cin>>R>>S;
if(R=="insert"){
insert();
}
if(R=="find"){
find();
}
}
return 0;
}
| 0 | 83,272,165 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define all(x) (x).begin(),(x).end()
#define rall(v) (v).rbegin(), (v).rend()
#define FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
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; }
int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy[] = {0, 1, 1, 1, 0, -1, -1, -1};
int main(){
int n, k;
cin >> n >> k;
cout << ceil(((double)n-1)/(k-1)) << endl;
}
|
#include <bits/stdc++.h>
#include <numeric>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep1(i,n) for (int i = 1; i <= n; ++i)
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
const long long MOD = 1e9+7;
#define precout(val) cout << std::fixed << std::setprecision(20) << val;
const int dy[4] = { 0, 1, 0, -1 };
const int dx[4] = { 1, 0, -1, 0 };
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n; cin >> n;
vector<int> A(n);
vector<int> B(n);
ll have = 0;
rep(i, n) {
cin >> A[i];
have += A[i];
}
vector<int> S;
ll need = 0;
rep(i, n) {
cin >> B[i];
need += B[i];
if(B[i] <= A[i]) {
S.push_back(A[i] - B[i]);
}
}
if(need > have) {
cout << -1 << endl;
return 0;
}
sort(S.begin(), S.end());
int ans = n;
rep(i, S.size()) {
if(need + S[i] <= have) {
need += S[i];
--ans;
}
}
cout << ans << endl;
return 0;
}
| 0 | 17,335,874 |
#include<iostream>
using namespace std;
int a[100000], b[100000];
int main() {
int A, B, M;
int x, y, c;
cin >> A >> B >> M;
int i;
int amin = 100001, bmin = 100001, MIN = 200002;
for (i = 0; i < A; i++) {
cin >> a[i];
if (a[i] < amin)amin = a[i];
}
for (i = 0; i < B; i++) {
cin >> b[i];
if (b[i] < bmin)bmin = b[i];
}
MIN = amin + bmin;
for (i = 0; i < M; i++) {
cin >> x >> y >> c;
if (a[x - 1] + b[y - 1] - c < MIN)MIN = a[x - 1] + b[y - 1] - c;
}
cout << MIN << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define piii pair<int,pii>
#define pll pair<ll,ll>
#define plii pair<ll,pii>
#define vi vector<int>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define lw(vc,num) lower_bound(vc.begin(), vc.end(), num) - vc.begin();
#define hg(vc,num) upper_bound(vc.begin(), vc.end(), num) - vc.begin();
#define bn(v,x) binary_search (v.begin(), v.end(), x)
#define mx 100001
#define eps 0.00000000001
#define mod 1000000007
#define pi acos(-1)
#define inf 100000000
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
bool isprime(int n)
{
if(n == 1) return false;
if(n == 2 || n == 3) return true;
if(n%2 == 0 || n%3 == 0) return false;
for(int i=5; i*i<=n; i+=6){
if((n%i == 0)||(n%(i+2) == 0)) return false;
}
return true;
}
long long binpow(long long a, long long b) {
if (b == 0)
return 1;
long long res = binpow(a, b / 2);
if (b % 2)
return res * res * a;
else
return res * res;
}
int main()
{
fio;
int n;
cin>>n;
vi v1(n);
loop(i,0,n)
{
cin>>v1[i];
}
int ans = 0,k1 = INT_MAX;
loop(i,0,n)
{
if(k1>v1[i])
{
k1 = v1[i];
ans++;
}
}
cout<<ans<<endl;
return 0;
}
| 0 | 78,811,425 |
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
int main() {
ll n,k;
std::cin >> n>>k;
vector<ll> a(n);
vector<string> as(n);
vector<ll> b(n);
for (int i = 0; i < n; i++) {
std::cin >> a[i]>> b[i];
as[i] = bitset<30>(a[i]).to_string();
}
string ks = bitset<30>(k).to_string();
ll res = 0;
for (int i = 0; i < n; i++) {
if(a[i]<=k && (a[i] | k) <=k){
res+=b[i];
}
}
for (int i = 0; i < 30; i++) {
ll ca = 0;
ll now = 0;
if(ks[i]=='1'){
for (int j = 0; j < 30; j++) {
if(j<i){
if(ks[j]=='1')now += (ll)pow(2,29-j);
}else if(j==i){
}else{
now += (ll)pow(2,29-j);
}
}
for (int j = 0; j < n; j++) {
if(a[j]<=now && (a[j] | now) <= now){
ca += b[j];
}
}
}
res = max(res,ca);
}
std::cout << res << std::endl;
}
|
#include"bits/stdc++.h"
#include<unordered_set>
#include<unordered_map>
#include<random>
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9+7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
int dx[4]={ 1,0,-1,0 };
int dy[4]={ 0,1,0,-1 };
int N, Q, K;
vector<pair<int, int>> e[100000];
ll dep[100000];
void depth(int n, int p, ll d){
dep[n] = d;
rep(i, e[n].size()){
if(e[n][i].first == p) continue;
depth(e[n][i].first, n, d+e[n][i].second);
}
}
signed main(){
cin >> N;
rep(i, N-1){
int a, b, c;
cin >> a >> b >> c;
a--; b--;
e[a].pb({ b, c });
e[b].pb({ a, c });
}
cin >> Q >> K;
depth(K-1, -1, 0);
rep(i, Q){
int a, b;
cin >> a >> b;
cout << dep[a-1] + dep[b-1] << endl;
}
}
| 0 | 59,369,628 |
#include<bits/stdc++.h>
using namespace std;
const int MOD = 1e9+7;
int main(){
int n,m;
cin>>n>>m;
vector<string> maze;
for(int i=0;i<n;i++){
string row;
cin>>row;
maze.push_back(row);
}
int dp[n+1][m+1];
for(int i=0;i<=n;i++){
for(int j=0;j<=m;j++){
dp[i][j]=0;
}
}
for(int i=1;i<n+1;i++){
for(int j=1;j<m+1;j++){
if(i==0 || j==0){
dp[i][j]=0;
}else if(i==1 && j==1){
dp[i][j]=1;
}else if(maze[i-1][j-1]=='#'){
dp[i][j]=0;
}else{
dp[i][j]=(dp[i-1][j]+dp[i][j-1])%MOD;
}
}
}
cout<<dp[n][m];
return 0;
}
|
#include <vector>
#include <algorithm>
using namespace std;
using Int = long long;
struct edge{
int to;
Int cost;
};
vector<Int> Potential(const vector<vector<edge>>& G){
vector<Int> dist(G.size(),0);
for(int i = 1;i < G.size();i++){
for(int v = 0;v < G.size();v++){
for(auto & e : G[v]){
dist[e.to] = min(dist[e.to],dist[v] + e.cost);
}
}
}
for (int v = 0; v < G.size(); v++) {
for (auto &e : G[v]) {
if(dist[e.to] > dist[v] + e.cost){
return vector<Int>();
}
}
}
return dist;
}
#include <functional>
#include <queue>
#include <set>
#include <vector>
using namespace std;
Int INF = 1LL << 40;
using Pii = pair<Int, int>;
vector<Int> Potential_Dijkstra(const vector<vector<edge>> &G, const vector<Int> &pot,int s) {
vector<Int> dist(G.size(), INF);
dist[s] = 0;
priority_queue<Pii, vector<Pii>, greater<Pii>> que;
que.emplace(dist[s], s);
while (!que.empty()) {
auto d = que.top().first;
auto v = que.top().second;
que.pop();
if (dist[v] < d)
continue;
for (auto &e : G[v]) {
Int co = e.cost + pot[v] - pot[e.to];
if (dist[e.to] > d + co) {
dist[e.to] = d + co;
que.emplace(dist[e.to], e.to);
}
}
}
return dist;
}
vector<vector<Int>> AllPairsShortestPaths(const vector<vector<edge>> &G){
vector<vector<Int>> res(G.size());
auto pot = Potential(G);
if(pot.empty()) return vector<vector<Int>>();
for(int s = 0;s < G.size();s++){
res[s] = Potential_Dijkstra(G,pot,s);
for(int t = 0;t < G.size();t++){
if(res[s][t] == INF) continue;
res[s][t] += pot[t] - pot[s];
}
}
return res;
}
#include <iostream>
int main(){
int v,e;
cin >> v >> e;
vector<vector<edge>> G(v);
for(int i = 0;i < e;i++){
int s,t;
Int d;
cin >> s >> t >> d;
G[s].push_back({t,d});
}
auto res = AllPairsShortestPaths(G);
if(res.empty()){
cout << "NEGATIVE CYCLE" << endl;
return 0;
}
for(auto & d : res){
for(int i = 0;i < G.size();i++){
if(d[i] == INF) cout << "INF";
else cout << d[i];
cout << " \n"[i + 1 == G.size()];
}
}
}
| 0 | 14,288,697 |
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>
using namespace std;
int main()
{
int a, b, c;
cin >> a >> b >> c;
set<int> N;
N.insert(a);
N.insert(b);
N.insert(c);
cout << N.size() << endl;
}
|
# include <bits/stdc++.h>
typedef long long lint;
using namespace std;
lint gcd(lint x, lint y) {
if(x == 0) { return y; }
else { return gcd(y%x,x); }
}
lint lcm(lint x, lint y) { return x/gcd(x,y)*y; }
lint C(lint n, lint k) {
if(n == k) { return 1; }
else if(n < k) { return 0; }
else if(k == 0) { return 1; }
else if(k == 1) { return n; }
else return C(n-1,k-1) + C(n-1,k);
}
lint P(lint n, lint k) {
if(k == 1) { return n; }
return (n*(P(n-1,k-1)%1000000007)%1000000007);
}
int main() {
int n,m; cin >> n >> m;
string s;
vector<string> a; for(int i=0;i<n;i++) { cin >> s; a.push_back(s); }
vector<string> b; for(int i=0;i<m;i++) { cin >> s; b.push_back(s); }
for(int i=0;i+m<=n;i++) {
for(int j=0;j+m<=n;j++) {
int chk=1;
for(int k=0;k<m;k++) {
if(a[j+k].substr(i,m) != b[k]) {
chk *= 0;
break;
}
}
if(chk == 1) {
cout << "Yes" << endl;
return 0;
}
}
}
cout << "No" << endl;
return 0;
}
| 0 | 9,153,602 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define IN(type, n) type n; cin >> n
ll solve(int N, int K, vector<int> P, vector<int>C) {
vector<vector<int> > loops = {};
vector<ll> sum = {};
bitset<5000> flag_check;
ll max_score = LLONG_MIN;
REP (i, N) {
if (flag_check[i]) continue;
int next = P.at(i) - 1;
ll tmp_sum = 0;
vector<int> tmp_vec = {};
while (true) {
if (flag_check[next]) break;
flag_check.set(next);
tmp_vec.push_back(next);
tmp_sum += C.at(next);
next = P.at(next) - 1;
}
loops.push_back(tmp_vec);
sum.push_back(tmp_sum);
}
REP (i, loops.size()) {
vector<int> v = loops.at(i);
int size = v.size();
ll max_all = LLONG_MIN;
ll max_limit = LLONG_MIN;
REP (j, size) {
ll tmp_sum = 0;
int next = v.at(j);
REP (k, size) {
tmp_sum += C.at(next);
if (k < K % size) {
max_limit = max(max_limit, tmp_sum);
}
max_all = max(max_all, tmp_sum);
next = P.at(next) - 1;
}
}
ll sum_v = sum.at(i);
ll max_v;
if (sum_v > 0) {
max_v = max(sum_v * (K / size) + max_limit, sum_v * (K / size - 1) + max_all);
} else {
max_v = max(max_limit, max_all);
}
max_score = max(max_score, max_v);
}
return max_score;
}
int main() {
IN(int, N);
IN(int, K);
vector<int> P(N);
vector<int> C(N);
vector<int> sumv(N);
long long sum = 0;
REP(i, N) {
cin >> P.at(i);
}
REP(i, N) {
cin >> C.at(i);
sum += C.at(i);
}
cout << solve(N, K, P, C) << endl;;
return 0;
}
|
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <math.h>
#include <algorithm>
#include <deque>
#include <climits>
using namespace std;
#define ll long long
#define ve vector
#define umap unordered_map
const int MxN=105;
char a[MxN];
int main() {
int h,w;
cin>>h>>w;
for(int i=0;i<h;i++) {
for(int j=0;j<w;j++) {
cin>>a[j];
cout<<a[j];
}
cout<<endl;
for(int j=0;j<w;j++) {
cout<<a[j];
}
cout<<endl;
}
return 0;
}
| 0 | 78,802,715 |
#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;
cin >> n;
cout << 0 << endl;
string res;
bool frg;
cin >> res;
if(res == "Vacant") return 0;
else if(res == "Male") frg = true;
else frg = false;
cout << n-1 << endl;
cin >> res;
if(res == "Vacant") return 0;
int l = 0, r = n-1;
int co = 1;
while(co < 20){
co++;
int mid = (l+r)/2;
bool mig;
cout << mid << endl;
cin >> res;
if(res == "Vacant") return 0;
else if(res == "Male") mig = true;
else mig = false;
int lw = mid - l;
bool m2 = (lw % 2 == 0);
bool ge = (frg == mig);
if((m2 ^ ge) == true){
r = mid;
}else{
frg = mig;
l = mid;
}
}
return 1;
}
|
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
int H, W;
while (1) {
cin >> H >> W;
if (H == 0 && W == 0) break;
for (int i = 0; i < H; i++) {
if (0 < i && i < H-1) {
for (int j = 0; j < W; j++) {
if (0 < j && j < W-1) {
cout << "." ;
}
else {
cout << "#";
}
}
}else if (i == 0 || i == H-1) {
for (int j = 0; j < W; j++) {
cout << "#";
}
}
cout << endl;
}
cout << endl;
}
return 0;
}
| 0 | 49,865,893 |
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
#include <deque>
#include <queue>
#include <list>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
int main() {
ios::sync_with_stdio(false);
int n;
cin >> n;
int a[n + 2];
a[0] = 0;
a[n + 1] = 0;
for (int i = 1 ; i <= n ; i++) cin >> a[i];
int b = 0;
for (int i = 1 ; i <= n + 1 ; i++) b += abs(a[i] - a[i - 1]);
for (int i = 1 ; i <= n ; i++) {
int ans = b;
ans = ans - abs (a[i] - a[i - 1]) - abs (a[i] - a[i + 1]) + abs (a[i - 1] - a[i + 1]);
cout << ans << endl;
}
}
|
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for (int i = (n); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
int main()
{
int n, m;
cin >> n >> m;
int cost[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int num[m];
rep(i, m) cin >> num[i];
string dp[n + 1];
dp[0] = "";
for (int i = 1; i <= n; i++)
{
dp[i] = "";
rep(j, m)
{
int t = i - cost[num[j]];
if (t < 0 || (t != 0 && dp[t] == ""))
continue;
if (dp[i].size() < dp[t].size() + 1)
dp[i] = dp[t] + to_string(num[j]);
else if (dp[i].size() == dp[t].size() + 1)
dp[i] = max(dp[i], dp[t] + to_string(num[j]));
}
}
OP(dp[n]);
return 0;
}
| 0 | 6,053,532 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n,a,b;
cin>>n>>a>>b;
cout<<(abs(a-b)&1 ? "Borys" : "Alice")<<endl;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1LL << 60;
const int MAX = 1000000010;
const ll MOD = 1000000007;
const double PI = acos(-1);
int main() {
string s; cin >> s;
for (int i = 0; i < s.length(); i++) {
if (i == 5 || i == 13) {
cout << " ";
} else {
cout << s[i];
}
}
cout << endl;
return 0;
}
| 0 | 25,801,502 |
#include <stdio.h>
long long n, x, a, b, c, ans;
int main() {
scanf("%lld%lld", &n, &x);
ans = n;
if (x < n - x) {
a = n - x;
b = x;
}
else {
a = x;
b = n - x;
}
while (true) {
if (a % b == 0) {
ans += (2 * a / b - 1) * b;
break;
}
else {
ans += 2 * (a / b) * b;
c = a % b;
a = b;
b = c;
}
}
printf("%lld\n", ans);
}
|
#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
#define inputInt(a) int a; cin >> a;
#define inputInt2(a,b) int a; int b; cin >> a >> b;
#define inputInt3(a,b,c) int a; int b; int c; cin >> a >> b >> c;
#define inputLong(a) long a;cin >> a;
#define inputIntArray(a,N) int a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputLongArray(a,N) long a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputIntArray2(a,b,N) int a[N]; int b[N]; for(int i=0;i<N;i++){cin >> a[i] >> b[i];}
#define output(answer) cout << answer << endl;
#define fN(i,N) for(int i=0; i<N; i++)
#define fSE(i,s,e) for(int i=s; i<=e; i++)
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define FOR(i,N) for(int i=0; i<N; i++)
#define cinv(v,N) vector<int> v(N); for(int i=0; i<N; i++){ cin >> v[i]; }
#define mt make_tuple
#define vll vector<long long int>
#define vvll vector<vector<long long int>>
#define all(v) (v).begin(),(v).end()
#define show(v) FOR(i,v.size()){ cout << v[i] << " "; } cout << endl;
#define showshow(v) FOR(i,v.size()){ FOR(j,v[i].size()){ cout << v[i][j] << " "; } cout << endl; }
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
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; }
const int LIMIT = 1e6;
vector<ll> FacMod(LIMIT), InvMod(LIMIT), FacInvMod(LIMIT);
const int dpComTableLIMIT = 3e3+1;
vector<vector<ll>> Com(dpComTableLIMIT,vector<ll>(dpComTableLIMIT,0));
const int ComKTableLIMIT = 1e7;
vector<ll> ComK(ComKTableLIMIT);
void DPComInit(){
for(int i=0; i<dpComTableLIMIT; i++){ Com[i][0] = 1; }
for(int i=1; i<dpComTableLIMIT; i++){
for(int j=1; j<dpComTableLIMIT; j++){
Com[i][j] = (Com[i-1][j-1]+Com[i-1][j])%MOD;
}
}
}
void ComKInit(ll N){
for(int i=0; i<=ComKTableLIMIT; i++){
if(0<i && i<=N/2){
ComK[i] = (ComK[i-1]*(N-i+1)/i)%MOD;
}else if(i==0){
ComK[i] = 1;
}else if(N/2<i && i<=N){
ComK[i] = ComK[N-i];
}else{
ComK[i] = -1;
}
}
}
void ComInit(){
FacMod[0] = FacMod[1] = 1;
InvMod[0] = 0; InvMod[1] = 1;
FacInvMod[0] = FacInvMod[1] = 1;
for(int i=2; i<LIMIT; i++){
FacMod[i] = FacMod[i-1]*i%MOD;
InvMod[i] = -InvMod[MOD%i]*(MOD/i)%MOD + MOD;
FacInvMod[i] = FacInvMod[i-1] * InvMod[i]%MOD;
}
}
ll ComMod(int n, int k){
if(n>=0 && k>=0 && n>=k){
return FacMod[n]*(FacInvMod[k]*FacInvMod[n-k]%MOD)%MOD;
}else{
return 0;
}
}
ll power(ll x, ll y){
if(y < 0){
return 0;
}else if(y == 0){
return 1LL;
}else if(y%2 == 0){
return power(x,y/2)*power(x,y/2);
}else{
return power(x,y-1)*x;
}
}
ll mpower(ll x, ll y, ll m){
if(y < 0){
return 0;
}else if(y == 0){
return 1LL;
}else if(y%2 == 0){
return mpower(x,y/2,m)*mpower(x,y/2,m)%m;
}else{
return mpower(x,y-1,m)*x%m;
}
}
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;
}
pair<map<ll,ll>,bool> PrimeFactorization(ll N){
pair<map<ll,ll>,bool> ret;
ret.second = true;
if(N != 2){
while(N%2 == 0){
N /= 2;
ret.first[2] ++;
ret.second = false;
}
}
for(ll i=3; i*i<=N; i+=2){
while(N%i == 0){
N /= i;
ret.first[i] ++;
ret.second = false;
}
}
if(N != 1){
ret.first[N] ++;
}
return ret;
}
bool compare_by_second(pair<ll,ll> a, pair<ll,ll> b){
return a.second != b.second ? a.second < b.second : a.first < b.first;
}
class UnionFind {
vector<int> parent;
vector<int> rank;
public:
UnionFind(int N);
int root(int x);
void unite(int x, int y);
bool isUnited(int x, int y);
int getRank(int x);
};
UnionFind::UnionFind(int N):parent(N),rank(N,1){
for(int i=0; i<N; i++){parent[i]=i;}
}
int UnionFind::root(int x){
if(parent[x] == x) return x;
return root(parent[x]);
}
void UnionFind::unite(int x, int y) {
int rx = root(x);
int ry = root(y);
if (rx == ry) return;
if(rank[x] >= rank[y]){parent[ry] = rx; rank[y]+=1;}
else{parent[rx] = ry; rank[x]+=1;}
}
bool UnionFind::isUnited(int x, int y) {
int rx = root(x);
int ry = root(y);
parent[x]=rx; parent[y]=ry;rank[x]=2;rank[y]=2;
return rx == ry;
}
int UnionFind::getRank(int x){
return rank[x];
}
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
ll N; cin >> N;
vector<ll> A(N); FOR(i,N){ cin >> A[i]; }
sort(all(A));
vector<bool> table(A[N-1]+1,false);
ll ans = 0;
for(int i=0; i<N; i++){
ll n = distance( lower_bound(all(A),A[i]), lower_bound(all(A),A[i]+1) );
if(!table[A[i]] && n == 1) ans ++;
ll j = 1;
while(A[i]*j <= A[N-1]){
table[A[i]*j] = true;
j ++;
}
}
cout << ans << endl;
return 0;
}
| 0 | 18,210,407 |
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
using namespace std;
int main() {
int R, G;
cin >> R >> G;
cout << R*R - G << endl;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second
template <class T>
void cout_vec(const vector<T> &vec){
for(auto itr:vec) cout<<itr<<' ';
cout<<'\n';
}
typedef pair<ll,ll> P;
const ll mod=1e9+7;
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
ll n,k;
cin>>n>>k;
vector<ll> a(n+1);
vector<ll> s1(n+1,0),s2(n+1,0);
FOR(i,1,n+1){
cin>>a[i];
s1[i]=s1[i-1]+a[i];
if(a[i]>0) s2[i]=s2[i-1]+a[i];
else s2[i]=s2[i-1];
}
ll ans=0;
FOR(i,1,n+1){
if(i+k-1>n) break;
ans=max(ans,s1[i+k-1]-s1[i-1]+s2[i-1]+s2[n]-s2[i+k-1]);
ans=max(ans,s2[i-1]+s2[n]-s2[i+k-1]);
}
cout<<ans<<endl;
}
| 0 | 92,033,744 |
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std ;
using ll = long long ;
using vll = vector<ll> ;
using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end()
int main(){
ll n ; cin >> n ;
vll a(n),b(n) ;
vector<pll> p(n) ;
for(int i=0;i<n;i++){
cin >> a.at(i) >> b.at(i) ;
p.at(i).first = a.at(i)+b.at(i) ;
p.at(i).second = i ;
}
sort(all(p)) ;
reverse(all(p)) ;
ll ans = 0 ;
for(int i=0;i<n;i++){
if(i&1) ans -= b.at(p.at(i).second) ;
else ans += a.at(p.at(i).second) ;
}
cout << ans << endl ;
}
|
#include<bits/stdc++.h>
using namespace std;
long long dp[101][100020];
vector<int> a(102);
vector<long long> pref(100050);
long long mod = 1e9 + 7;
int main()
{
int N, K;
cin >> N >> K;
for(int i = 1; i <= N; i++)
cin >> a[i];
for(int i = 0; i <= K; i++)
pref[i] = 0;
for(int i = 0; i <= N; i++)
{
for(int j = 0; j <= K; j++)
{
dp[i][j] = 0;
}
}
for(int j = 0; j <= a[N]; j++)
{
dp[N][j] = 1;
}
long long res = 0;
for(int i = N-1; i >= 0; i--)
{
pref[0] = 1;
for(int j = 1; j <= K; j++)
pref[j] = (pref[j-1] + dp[i+1][j]) % mod;
for(int j = 0; j <= K; j++)
{
if(j-1-a[i] < 0) dp[i][j] = pref[j];
else dp[i][j] = (pref[j] - pref[j - 1 - a[i]] + mod) % mod;
}
}
cout << dp[1][K] << endl;
return 0;
}
| 0 | 4,918,283 |
#include<bits/stdc++.h>
using namespace std;
#define fast() ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define test() ll t; cin>>t; while(t--)
#define lp0(i,begin,end) for(ll i=begin;i<end;i++)
#define lp1(i,begin,end) for(ll i=begin;i<=end;i++)
#define rlp(i,begin,end) for(ll i=end;i>=begin;i--)
#define prec(n) fixed<<setprecision(n)
#define initial(a,i) memset(a,i,sizeof(a))
#define pb push_back
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define F first
#define S second
#define all(a) (a).begin(),(a).end()
#define BPC(x) __builtin_popcountll(x)
#define gcd(a,b) __gcd(a,b)
ll gcd(ll a,ll b) {if (a==0) return b;return gcd(b%a,a);}
ll power(ll x,ll n)
{
ll result = 1;
while (n)
{
if (n & 1)
result = result * x;
n = n / 2;
x = x * x;
}
return result;
}
void solution(ll compte)
{
string s,t;
cin >> s >> t;
cout << t << s << endl;
}
int main()
{
ll compte = 1;
solution(compte);
compte++;
return 0;
}
|
#include <bits/stdc++.h>
#include <bitset>
#include <cassert>
#include <cstring>
#include <functional>
#include <iomanip>
#include <list>
#include <cmath>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define REP(i, n) for (int64_t i = 0; i < (int64_t)n; i++)
#define REP_FOR(i, a, b) for (int64_t i = (int64_t)a; i < (int64_t)b; i++)
#define REP_REV(i, a, b) for (int64_t i = (int64_t)a; i > (int64_t)b; i--)
#define FORALL(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int64_t, int64_t> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int64_t> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int64_t infi = 1147483600;
const ll infl = 4e18 + 5;
const char EOL = '\n';
int main() {
ll n, m;
cin >> n >> m;
vector<string> A(m);
for (auto & a: A) cin >> a;
ll matches[10] = {0,2,5,5,4,5,6,3,7,6};
vector<pair<string,ll>> keys;
for (auto a : A) {
keys.push_back(make_pair(a, matches[a[0]-'0']));
}
vector<string> dp(n + 1, "NA");
dp[0] = "";
for (ll i = 1; i <= n; ++i) {
for (auto k : keys) {
ll j = i - k.second;
if (j >= 0 && dp[j] != "NA") {
if (dp[i] == "NA") {
dp[i] = dp[j] + k.first;
} else {
if (dp[i].length() < dp[j].length() + 1) {
dp[i] = dp[j] + k.first;
} else if (dp[i].length() == (dp[j].length() + 1)) {
auto tmp = dp[j] + k.first;
if (dp[i].compare(tmp) < 0) {
dp [i] = tmp;
}
tmp = k.first + dp[j];
if (dp[i].compare(tmp) < 0) {
dp [i] = tmp;
}
}
}
}
}
}
cout << dp[n] << endl;
}
| 0 | 60,985,427 |
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define pb push_back
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
void debug_out() {cerr << endl;}
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {cerr << " " << to_string(H), debug_out(T...);}
int main() {
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
freopen("in.txt", "r", stdin);
#else
#define debug(...) 3
fastIO;
#endif
ll a,b,c,d;
cin>>a>>b>>c>>d;
ll ans=-2e18;
ans=max(ans,a*c);
ans=max(ans,a*d);
ans=max(ans,b*c);
ans=max(ans,b*d);
cout<<ans<<endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
class Point {
public:
double x, y;
};
void kochCurve(int n, Point p1, Point p2) {
Point s, t, u;
if (n == 0) {
return;
}
s.x = (p2.x + 2 * p1.x) / 3.0;
s.y = (p2.y + 2 * p1.y) / 3.0;
t.x = (p1.x + 2 * p2.x) / 3.0;
t.y = (p1.y + 2 * p2.y) / 3.0;
u.x = (t.x - s.x)*0.5 - (t.y - s.y)*sqrt(3)*0.5 + s.x;
u.y = (t.x - s.x)*sqrt(3)*0.5 + (t.y - s.y)*0.5 + s.y;
kochCurve(n - 1, p1, s);
cout << fixed << setprecision(6) << s.x << " " << s.y << endl;
kochCurve(n - 1, s, u);
cout << fixed << setprecision(6) << u.x << " " << u.y << endl;
kochCurve(n - 1, u, t);
cout << fixed << setprecision(6) << t.x << " " << t.y << endl;
kochCurve(n - 1, t, p2);
}
int main() {
int n;
Point p1, p2;
p1.x = 0;
p1.y = 0;
p2.x = 100;
p2.y = 0;
cin >> n;
cout << fixed << setprecision(6) << p1.x << " " << p1.y << endl;
kochCurve(n, p1, p2);
cout << fixed << setprecision(6) << p2.x << " " << p2.y << endl;
return 0;
}
| 0 | 5,420,030 |
#include<bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for (int i=0;i<(n);i++)
#define PI 3.14159265358979323846264338327950L
using namespace std;
using P = pair<int,int>;
using ll = long long;
using namespace std;
int main(void){
ll a, b, k;
cin >> a >> b >> k;
ll zero = 0;
if(a >= k){cout << a-k << " " << b << endl; return 0;}
else {cout << 0 << " " << max(zero, b-(k-a)) << endl; return 0;}
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF = 1 << 29;
const int MOD = 1000000007;
long long calcGcd(long long a, long long b) {
if (a < b) {
int tmp = a;
a = b;
b = tmp;
}
int r = a % b;
while (r != 0) {
a = b;
b = r;
r = a % b;
}
return b;
}
long long calcLcm(long long a, long long b) {
return a * b / calcGcd(a, b);
}
int main() {
long long a, b, c, d;
cin >> a >> b >> c >> d;
long long all = b - a + 1;
long long divided_c, divided_d, divided_lcm;
divided_c = b / c - (a - 1) / c;
divided_d = b / d - (a - 1) / d;
divided_lcm = b / calcLcm(c, d) - (a - 1) / calcLcm(c, d);
long long ans = all - (divided_c + divided_d - divided_lcm);
cout << ans << endl;
}
| 0 | 11,100,986 |
#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(){
ll n,m;
cin >> n >> m;
if(n==1){
cout << max(m-2,n);
return 0;
}
if(m==1){
cout << max(n-2,m);
return 0;
}
cout << n*m-(2*n+2*m-4);
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};
int main(){
int n, m, x, y;
cin >> n >> m >> x >> y;
rep(i, n) {
int a;
cin >> a;
chmax(x, a);
}
rep(i, m) {
int a;
cin >> a;
chmin(y, a);
}
string ans = "No War";
if (x>=y) ans = "War";
cout << ans << endl;
return 0;
}
| 0 | 66,017,426 |
#include <iostream>
using namespace std;
int main(){
int a=0, b=0, c=0;
string d;
cin >> d;
for(int i = 0;i<3;i++){
if(d.at(i)=='a')a++;
else if(d.at(i)=='b')b++;
else c++;
}
if(a==1&&b==1&&c==1)cout << "Yes";
else cout << "No";
}
|
#include <bits/stdc++.h>
using namespace std;
int main(){
int A, B, K;
cin >> A >> B >> K;
vector<int> Ks(max(A,B));
int i = 1;
while (i <= max(A,B) ){
if (A%i == 0 && B%i == 0){
Ks.push_back(i);
}
i += 1;
}
reverse(Ks.begin(), Ks.end());
cout << Ks.at(K-1) << endl;
}
| 0 | 18,222,378 |
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
int tod(string a){
int n=a.size();
int res=0;
size_t cur=0;
while(cur<n){
int tmp=1;
if(isdigit(a[cur]))
tmp=(a[cur++]-'0');
if(a[cur]=='m')
tmp*=1000;
else if(a[cur]=='c')
tmp*=100;
else if(a[cur]=='x')
tmp*=10;
res+=tmp;
cur++;
}
return res;
}
string tos(int a){
string res="";
int cur=1000;
while(a){
int tmp=a/cur;
if(tmp>=2)
res+=(tmp+'0');
if(tmp){
switch(cur){
case 1000:
res+='m';
break;
case 100:
res+='c';
break;
case 10:
res+='x';
break;
case 1:
res+='i';
break;
}
}
a-=tmp*cur;
cur/=10;
}
return res;
}
int main(void){
int n;
cin >> n;
for(int loop=0;loop<n;loop++){
string a,b;
cin >> a >> b;
int aa,bb,cc;
aa=tod(a);bb=tod(b);
cc=aa+bb;
string c=tos(cc);
cout << c << endl;
}
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout<<fixed; cout<<setprecision(12);
#define randomINT mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define newl cout<<"\n"
#define DISP(as) for(auto it : as) cout<<it<<" ";newl;
#define all(x) (x).begin(),(x).end()
#define mset(x,val) memset(x,val,sizeof(x))
#define newl cout<<"\n"
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define dline cerr<<"
#define deb1(x) cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y) cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z) cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';
typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll , ll> pll;
typedef pair<ld, ld> pld;
typedef unordered_map<ll, ll> um;
typedef vector<pll> vpll;
const ll MAX5 = 1e+5 + 7;
const ll MAX7 = 1e+7 + 7;
const ll MAXN = MAX7;
const ll INF = 0x7f7f7f7f7f7f7f7f;
const int INFi = 0x7f7f7f7f;
const ll MOD = 1e+9 + 7;
ll T = 1;
ll n, x, m, y, k, z, N;
ll s, t, d;
void MAIN() {
cin >> n >> m ;
if(n == 0 && m == 0) cout<<0;
else if(n == 0) {
if((m+1)%4==0) {
cout<<0;
}
else if((m+1)%2==0) {
cout<<1;
}
else {
m/=2;
if(m&1) cout<<((2*m)^1);
else cout<<(2*m);
}
}
else {
n--;
ll L,R;
if((n+1)%4==0) {
L=0;
}
else if((n+1)%2==0) {
L=1;
}
else {
n/=2;
if(n&1) L=((2*n)^1);
else L=2*n;
}
if((m+1)%4==0) {
R=0;
}
else if((m+1)%2==0) {
R=1;
}
else {
m/=2;
if(m&1) R=((2*m)^1);
else R=2*m;
}
cout<<(L^R);
}
}
int main() {
fastio; randomINT;
while (T--) {
MAIN();
}
return 0;
}
| 0 | 61,666,141 |
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
void Main()
{
ll H, W;
cin >> H >> W;
vector<string> S(H);
rep(i, H) cin >> S[i];
vector<vector<int>> L(H, vector<int>(W));
vector<vector<int>> R(H, vector<int>(W));
vector<vector<int>> U(H, vector<int>(W));
vector<vector<int>> D(H, vector<int>(W));
rep(y, H) {
int cnt = 0;
rep(x, W) {
if (S[y][x] == '.') {
cnt++;
}
else {
cnt = 0;
}
L[y][x] = cnt;
}
}
rep(y, H) {
int cnt = 0;
for (int x = W - 1; x >= 0; x--) {
if (S[y][x] == '.') {
cnt++;
}
else {
cnt = 0;
}
R[y][x] = cnt;
}
}
rep(x, W) {
int cnt = 0;
rep(y, H) {
if (S[y][x] == '.') {
cnt++;
}
else {
cnt = 0;
}
U[y][x] = cnt;
}
}
rep(x, W) {
int cnt = 0;
for (int y = H - 1; y >= 0; y--) {
if (S[y][x] == '.') {
cnt++;
}
else {
cnt = 0;
}
D[y][x] = cnt;
}
}
int res = 0;
rep(y, H) rep(x, W) {
res = max(res, U[y][x] + D[y][x] + L[y][x] + R[y][x] - 3);
}
put(res);
}
signed main(){ Main();return 0;}
|
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);
int main() {
int H, W, D; cin>>H>>W>>D;
vector<vector<int> > A(H, vector<int>(W));
map<int, pair<int, int> > amap;
for(int i=0;i<H;++i) {
for(int j=0;j<W;++j) {
cin>>A[i][j];
if(A[i][j]>D) {
amap[A[i][j]-D] = mp(i, j);
}
}
}
int ans[H*W+1];
for(int i=0;i<=H*W;++i) ans[i] = 0;
for(int i=0;i<H;++i) {
for(int j=0;j<W;++j) {
if(A[i][j]+D>H*W) continue;
ans[A[i][j]] = abs(amap[A[i][j]].fi-i)+abs(amap[A[i][j]].se-j);
}
}
vector<vector<int> > ansarr(D);
for(int i=0;i<D;++i) ansarr[i].push_back(0);
for(int i=1;i<H*W;++i) {
if(ans[i]==0) break;
ansarr[i%D].push_back(ans[i]);
}
for(int i=0;i<D;++i) {
for(int j=1;j<ansarr[i].size();++j) ansarr[i][j] += ansarr[i][j-1];
}
int Q;
cin>>Q;
int l, r;
int ans1[Q];
for(int i=0;i<Q;++i) {
cin>>l>>r;
if(l%D==0) ans1[i] = ansarr[l%D][r/D-1]-ansarr[l%D][l/D-1];
else ans1[i] = ansarr[l%D][(r-l%D)/D]-ansarr[l%D][(l-l%D)/D];
}
for(int i=0;i<Q;++i) cout<<ans1[i]<<endl;
}
| 0 | 79,932,090 |
#include<bits/stdc++.h>
using namespace std;
using ll=long long int;
#define rep(i,n) for(int i=0;i<(n);i++)
int main(){
int n;
cin>>n;
vector<int>a(n);
rep(i,n)cin>>a[i];
sort(a.begin(),a.end());
int ans;
ans=abs(a[0]-a[n-1]);
cout<<ans<<endl;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
signed main(){
string s; cin>>s;
string t; cin>>t;
int n=s.size();
if(s==t){
cout<<"Yes"<<endl;
return 0;
}
else{
rep(i,0,n){
string c;
c.push_back(s[n-1]);
s.insert(0,c);
s.pop_back();
if(s==t){
cout<<"Yes"<<endl;
return 0;
}
}
cout<<"No"<<endl;
}
return 0;
}
| 0 | 66,104,618 |
#include <iostream>
#include <algorithm>
#include <stdio.h>
using namespace std;
int v[5];
int main(void) {
for(int i = 0; i < 5; i++) {
cin >> v[i];
}
sort(v, v + 5);
reverse(v, v + 5);
printf("%d %d %d %d %d\n", v[0], v[1], v[2], v[3], v[4]);
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define fast {ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
typedef long long int ll;
typedef string S;
#define M 1e18
#define AS 250005
#define in(x) cin>>x
#define o(x) cout<<x
#define sp cout<<' '
#define nw cout<<endl
#define rt return
#define fr(i,a,n) for(ll i=a;i<=n;i++)
#define frm(i,a,n) for(ll i=n;i>=a;i--)
#define P pair<ll,ll>
#define vc vector<ll>
#define pb push_back
#define MP map<ll,ll>
bool sortin(const pair<ll,ll> &e,const pair<ll,ll> &f){return (e.first<f.first);}
bool POT(ll x){return x && (!(x&(x-1)));}
ll i,j,k,l,m,n,p,q,r,a,b,c,x,y,z,ts,mn=1e18,mod=1e9+7;
ll ar[AS],br[AS],xr[AS];
int main()
{
fast;
in(n);
fr(i,0,2*n-1)in(ar[i]);
sort(ar,ar+2*n);
fr(i,0,2*n-1)c+=ar[i++];
o(c);
}
| 0 | 57,222,342 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;
int main(){
string n;
cin >> n;
if((n[0] == n[1]) && (n[1] == n[2])) cout << n << endl;
else{
int v;
v = stoi(n);
while((n[0] != n[1]) || (n[0] != n[2])){
v++;
n = to_string(v);
}
cout << n << endl;
}
return 0;
}
|
#include <iostream>
#include <vector>
using namespace std;
vector<int> parents;
int root(int k)
{
while (parents[k] != k) {
k = parents[k];
}
return k;
}
int main()
{
int n, q;
cin >> n >> q;
for (int i = 0; i < n; i++) {
parents.push_back(i);
}
for (int j = 0; j < q; j++) {
int c, x, y;
cin >> c >> x >> y;
if (c) {
if (root(x) == root(y))
cout << 1 << endl;
else
cout << 0 << endl;
} else {
int rx = root(x);
int ry = root(y);
if (rx != ry) {
parents[rx] = ry;
}
}
}
}
| 0 | 23,389,769 |
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define endl "\n"
typedef long long ll;
using namespace std;
int static fast = [](){
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0); return 0;
}();
int main() {
int n;
string s, t;
cin >> n >> s >> t;
int overlap = 0;
for(int i = 1; i <= n; i++) {
if (s.substr(n-i, i) == t.substr(0, i)) {
overlap = i;
}
}
cout << n*2 - overlap << endl;
return 0;
}
|
#include<iostream>
#include <iosfwd>
#include<limits.h>
#include <sstream>
#include <iomanip>
#include <iterator>
#include <algorithm>
#include <limits>
#include<stdio.h>
#include <queue>
#include <stack>
#include <math.h>
#include<string.h>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include <set>
#include<vector>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;
#define fr(i,j,n) for(lli i=j;i<(n);++i)
#define bk(i,j,n) for(lli i=j;i>=n&&j>=n;--i)
#define pb push_back
#define m_p make_pair
#define F first
#define S second
#define endl "\n"
#define MOD 1000000007
#define mem(p,v) memset(p,v,sizeof(p))
#define present(c,x) ((c).find(x) != (c).end())
#define run ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ordered_set tree<lli, null_type,less<lli>, rb_tree_tag,tree_order_statistics_node_update>
#define debug1(x) cout<<#x<<" "<<x<<endl;
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define debug4(x,y,z,a) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<#a<<" "<<a<<endl;
#define ub upper_bound
#define lb lower_bound
typedef long long int lli;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<lli> vl;
typedef pair<lli,lli> pl;
inline lli max(lli a,lli b){ return a>b?a:b;}
inline lli min(lli a,lli b){ return a<b?a:b;}
const long long inf = 9e18;
double pie = 2*acos(0.0);
void show(vector<lli> v){fr(i,0,v.size())cout<<v[i]<<" ";cout<<endl;}
void show(vector<int> v){fr(i,0,v.size())cout<<v[i]<<" ";cout<<endl;}
void show(int a[], int arraysize){for (int i = 0; i < arraysize; ++i)cout << a[i] << " ";cout<<endl;}
void show(lli a[], lli arraysize){for (lli i = 0; i < arraysize; ++i)cout << a[i] << " ";cout<<endl;}
void show(bool a[], lli arraysize){for (lli i = 0; i < arraysize; ++i)cout << a[i] << " ";cout<<endl;}
void show(set<int> s){for (auto it = s.begin(); it != s.end(); it++){cout << *it << " ";}cout<<endl;}
void show(map<lli,lli> mp){for (auto it = mp.begin(); it != mp.end(); it++){cout << it->first << " "<<it->second<<endl;}cout<<endl;}
lli modpow(lli x,lli n){lli res=1;while(n>0){if(n&1) res=((res%MOD)*(x%MOD))%MOD;x=((x%MOD)*(x%MOD))%MOD;n>>=1;}return res;}
lli power(lli x, lli n){lli res=1;while(n>0){if(n&1) res=res*x;x=x*x;n>>=1;}return res;}
void solve()
{
lli n,k;
cin>>n>>k;
vl a(n);
vector<vl> dp(n,vl(k+1));
vector<vl> pf(n,vl(k+1));
fr(i,0,n)
{
cin>>a[i];
}
fr(i,0,n)
{
fr(j,0,k+1)
{
if(i==0)
{
if(j<=a[i])
dp[i][j]=1;
else
dp[i][j]=0;
}
else if(j==0)
dp[i][j]=dp[i-1][j];
else
{
dp[i][j]=pf[i-1][j];
if(a[i]<j)
{
dp[i][j]=(dp[i][j]-pf[i-1][j-a[i]-1]+MOD)%MOD;
}
}
}
lli s=0;
fr(j,0,k+1)
{
s+=dp[i][j];
s%=MOD;
pf[i][j]=s;
}
}
cout<<dp[n-1][k]<<endl;
}
int main()
{
run;cout<<fixed<<setprecision(12);
int t;
t=1;
while(t){solve();t--;}
return 0;
}
| 0 | 53,745,302 |
#include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7;
int main() {
ios::sync_with_stdio(0);
cout.tie(0);
cin.tie(0);
int n, k;
cin >> n >> k;
vector<int> dp(k + 1, 0);
dp[0] = 1;
for (int i = 0; i < n; ++i) {
int x;
cin >> x;
for (int j = 1; j <= k; ++j) dp[j] = (dp[j] + dp[j-1]) % M;
vector<int> tmp(k + 1, 0);
for (int j = 0; j <= k; ++j) {
int l = j - x;;
tmp[j] = dp[j];
if (l > 0) tmp[j] = (tmp[j] - dp[l-1] + M) % M;
}
swap(tmp, dp);
}
cout << dp[k] << '\n';
}
|
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint INF = 1e18;
signed main(){
int n, k, ans = 0; cin >> n >> k;
for(int i = 0; i < n; i++){
int x; cin >> x;
if(x >= k) ans++;
}
cout << ans << endl;
}
| 0 | 68,484,674 |
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i< (n); i++)
using namespace std;
using ll = long long;
typedef pair<int,int> P;
int main(void) {
queue<ll> qq;
ll K; cin >> K;
ll ans;
for(int i=1;i<=9;i++) qq.push(i);
for(int i=0; i<K; i++) {
ll x=qq.front();
ans = x;
qq.pop();
if(x%10!=0) qq.push(10*x+x%10-1);
qq.push(10*x+x%10);
if(x%10!=9) qq.push(10*x+x%10+1);
}
cout << ans << endl;
}
|
#include <stdio.h>
int main(){
int N;
scanf("%d", &N);
if (N / 100 == 7){
puts("Yes");
}else if ((N % 100)/10 == 7){
puts("Yes");
}else if (N % 10 == 7){
puts("Yes");
}else{
puts("No");
}
return 0;
}
| 0 | 16,249,129 |
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main()
{
int n;
string s;
int count = 0;
cin >> n >> s;
rep(i, 1000)
{
int c[3] = {i / 100, (i / 10) % 10, i % 10};
int f = 0;
rep(j, n)
{
if (s[j] == '0' + c[f])
f++;
if (f == 3)
break;
}
if (f == 3)
count++;
}
cout << count << endl;
return 0;
}
|
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define endl ("\n")
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define mp make_pair
#define mod 1000000007
#define L(x) x.length()
#define B(x) x.begin()
#define E(x) x.end()
#define F(x) x.front()
#define SZ(x) x.size()
#define CLR(x) x.clear()
#define all(x) x.begin(),x.end()
#define sortD(x) sort(x.begin(),x.end(),greater<int>)
#define rev(x) reverse(x.begin(),x.end())
#define intV vector<int>
#define PI (3.141592653589)
#define PMAX priority_queue<int>
#define PMIN priority_queue<int,vi,greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define KING(i, n) for (int(i) = 0; (i) < n; (i)++)
#define MAHAKAL(i, n) for (int(i) = n-1; (i) >= 0; (i)--)
#define Anshu int t; cin>>t; while(t--)
#define SITARAM(n,type) type* input=new type[n]
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
void ViLiFY_KiNG()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
freopen("error.txt","w",stderr);
#endif
}
bool isPalindrome(string str) {
int i=0;
int j=str.length()-1;
while(i<=j) {
if(str[i] != str[j]) {
return false;
}
i++;
j--;
}
return true;
}
int32_t main()
{
ViLiFY_KiNG();
string str;
cin>>str;
if(L(str)%2 == 0) {
cout<<"No"<<endl;
return 0;
}
if(isPalindrome(str)) {
if(isPalindrome(str.substr(0,(L(str)-1)/2))) {
cout<<"Yes"<<endl;
} else {
cout<<"No"<<endl;
}
} else {
cout<<"No"<<endl;
}
return 0;
}
| 0 | 32,007,189 |
#include<iostream>
#include<string>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
int main(){
long int mod = 1000000007;
string l;
cin >> l;
long int dp[l.size()][2];
dp[0][0] = 1;
dp[0][1] = 2;
for(int i = 1; i < l.size(); i++){
if (l[i] == '0') {
dp[i][0] = dp[i-1][0] * 3;
dp[i][1] = dp[i-1][1];
}else{
dp[i][0] = dp[i-1][0] * 3 + dp[i-1][1];
dp[i][1] = dp[i-1][1] * 2;
}
dp[i][0] %= mod;
dp[i][1] %= mod;
}
long int ans = dp[l.size()-1][0] + dp[l.size()-1][1];
ans %= mod;
cout << ans << endl;
}
|
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n);i++)
using namespace std;
int main(){
int n, m;
cin >> n >> m;
vector<int> l(m), r(m);
int l_max=0, r_min=10000000;
rep(i, m){
cin >> l[i] >> r[i];
if(l[i]>l_max) l_max = l[i];
if(r[i]<r_min) r_min = r[i];
}
int res=0;
if(r_min >= l_max)
res = r_min - l_max + 1;
else
res = 0;
cout << res << endl;
}
| 0 | 30,822,777 |
#include <iostream>
using namespace std;
int main(void) {
int64_t N, A, B;
cin >> N >> A >> B;
int64_t answer;
if (A > B) {
answer = 0;
} else if (N == 1) {
answer = (A == B) ? 1 : 0;
} else {
N -= 2;
answer = (B * N) - (A * N) + 1;
}
cout << answer << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void solve () {
int n;
cin >> n;
vector<long double> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort (a.begin(), a.end());
long double ans = a[0];
for (int i = 1; i < n; i++) {
ans = (ans + a[i]) / 2;
}
cout << ans;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
solve();
return 0;
}
| 0 | 63,411,310 |
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mp make_pair
#define pb push_back
#define st first
#define nd second
typedef long long ll;
typedef pair < ll , ll > pp;
const int mod = 1e9 + 7;
const int N = 2e5 + 5;
int q,a,b,j,n,n2,x,y,mx,t;
signed main(){
cin >> q;
for(; q-- ;){
cin >> a >> b;
if(a > b) swap(a,b);
t = 2*sqrt(a*b) + 1;
for(j=t; j && j > t-20; j--){
n = j;
n2 = (n+1)/2;
mx = 0;
x = n2+1; y = n-x+1;
if(x >= a) x++;
if(y >= b) y++;
mx = x * y;
x = n2; y = n-x+1;
if(x >= a) x++;
if(y >= b) y++;
mx = max(mx , x * y);
x = n2-1; y = n-x+1;
if(x >= a) x++;
if(y >= b) y++;
mx = max(mx , x * y);
x = a; y = n-x+1;
if(x >= a) x++;
if(y >= b) y++;
mx = max(mx , x * y);
x = n-b+1; y = n-x+1;
if(x >= a) x++;
if(y >= b) y++;
mx = max(mx , x * y);
if(mx < a*b) break;
}
cout << j << endl;
}
return 0;
}
|
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <random>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef
tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> orderedSet;
#define pb push_back
#define F first
#define S second
#define all(a) (a).begin(), (a).end()
#define for1(i0, l0, r0) for (int i0 = l0; i0 < r0; ++i0)
#define for2(i0, l0, r0) for (int i0 = l0; i0 <= r0; ++i0)
#define forn(i0, n0) for (int i0 = 0; i0 < n0; ++i0)
#define forn1(i0, n0) for (int i0 = 1; i0 < n0; ++i0)
#define forr(i0, n0) for (int i0 = n0; i0 >= 0; --i0)
#define forr1(i0, r0, l0) for (int i0 = r0; i0 > l0; --i0)
#define forr2(i0, r0, l0) for (int i0 = r0; i0 >= l0; --i0)
#define Sort(a) sort(all(a))
#define Reverse(a) reverse(all(a))
typedef long double ld;
#define ui unsigned int
#define ull unsigned long long
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<pdd> vpdd;
typedef vector<vi> vvi;
typedef vector<vd> vvd;
typedef vector<vll> vvll;
typedef vector<vb> vvb;
#define vpss vector<pss>
#define vvs vector<vs>
#define vvpii vector<vpii>
#define vvpll vector<vpll>
#define vpt vector<pt>
#define vvvi vector<vvi>
#define vsi vector<set<int>>
#define ss second
#define ff first
#define printvi(arr) for (int x0 : arr) cout << x0 << ' '; cout << '\n';
#define printvll(arr) for (ll x0 : arr) cout << x0 << ' '; cout << '\n';
#define printpair(pair0) cout << pair0.F << ' ' << pair0.S << '\n';
#define printvp(arr) for (auto pair0 : arr) printpair(pair0);
#define initArray(arr, N0, X0) memset(arr, X0, N0 * sizeof(int))
void init() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
void solve() {
int n, m;
cin >> n >> m;
vpll a(n + m);
forn(i, n){
cin >> a[i].F;
}
forn(i, m){
cin >> a[i + n].F;
a[i + n].S = 1;
}
Sort(a);
ll ans = 0;
int N = n + m;
n++, m++;
forn(i, N){
ll k;
if (a[i].S == 0) k = m; else k = n;
ans += a[i].F * k;
if (a[i].S == 0) n--; else m--;
}
cout << ans << '\n';
}
bool multitest = false;
int main() {
init();
int t = 1;
if (multitest) cin >> t;
forn(i, t) solve();
}
| 0 | 60,082,533 |
#include<iostream>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{
int64_t n,ans=10000000000000;
cin>>n;
for(int64_t i=1;i*i<=n;++i){
if(n%i==0)
ans=min(ans,i+n/i-2);
}
cout<<ans<<endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
char X, Y;
cin >> X >> Y;
int x, y;
if(X == 'A'){
x = 10;
}
if(X == 'B'){
x = 11;
}
if(X == 'C'){
x = 12;
}
if(X == 'D'){
x = 13;
}
if(X == 'E'){
x = 14;
}
if(X == 'F'){
x = 15;
}
if(Y == 'A'){
y = 10;
}
if(Y == 'B'){
y = 11;
}
if(Y == 'C'){
y = 12;
}
if(Y == 'D'){
y = 13;
}
if(Y == 'E'){
y = 14;
}
if(Y == 'F'){
y = 15;
}
if(x == y){
cout << '=';
}
if(x < y){
cout << '<';
}
if(x > y){
cout << '>';
}
}
| 0 | 83,673,555 |
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <deque>
#include <queue>
#include <fstream>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#define endl "\n"
typedef long long ll;
using namespace std;
void Lancer() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); }
bool isPrime(ll n){
if (n == 2 || n == 3 || n == 5)
return true;
else if (n % 2 == 0 || n % 3 == 0 || n % 5 == 0 || n == 1)
return false;
else {
for (int i = 5; i <= sqrt(n); i += 2){
if (n%i == 0)
return false;
}
return true;
}
}
int main(){
Lancer();
string str,num;
ll n, res = 10000000;
cin >> str;
for (int i = 0; i < str.size(); i++){
num = str.substr(i, 3);
n = stoi(num);
n = abs(n - 753);
res = min(res, n);
}
cout << res;
cout << endl;
return 0;
}
|
#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*b)/__gcd(a, b); }
void solve()
{
ll n;
cin >> n; ll c, k; cin >> c >> k;
ll a[n];
rep(i, n) cin >> a[i];
ll ans = 0;
sort(a, a+n);
for(ll i = 0, j = 0; i < n; )
{
while(j < n && (j-i+1) <= c && a[j]-a[i] <= k) j++;
ans++;
i = j;
}
cout << ans;
}
int main(){
fast();
ll t = 1;
while(t--){
solve();
}
return 0;
}
| 0 | 75,807,086 |
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <climits>
#include <bitset>
#include <list>
#include <map>
#include <set>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
int main(){
int n, k;
cin >> n >> k;
if(k==1) cout << 0 << endl;
else cout << n-k << endl;
return 0;
}
|
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N=1e5+10;
void io(){
ios::sync_with_stdio(0);
cin.tie();
cout.tie();
}
struct node{
double x;
double y;
}p[N];
bool cmp(node a,node b)
{
return atan2(a.x,a.y)>atan2(b.x,b.y);
}
int main()
{
int n;cin>>n;
for(int i=0;i<n;i++) cin>>p[i].x>>p[i].y;
sort(p,p+n,cmp);
double ans=0;
for(int i=0;i<n;i++){
double a=0,b=0;
int now=i;
do{
a+=p[now].x;
b+=p[now].y;
ans=max(ans,a*a+b*b);
if(now+1<n)now++;
else now=0;
}while(now!=i);
}
printf("%.15f\n",sqrt(ans));
return 0;
}
| 0 | 66,234,904 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<int> elevations;
vector<bool> hill(n,true);
for (int i = 0; i < n; i++) {
int h;
cin >> h;
elevations.push_back(h);
}
int a, b;
for (int i = 0; i < m; i++) {
cin >> a >> b;
if (elevations[a-1] <= elevations[b-1]) {
hill[a-1] = false;
}
if (elevations[b-1] <= elevations[a-1]) {
hill[b-1] = false;
}
}
int peaks = 0;
for (int i = 0; i < n; i++) {
if (hill[i] == true) {
peaks += 1;
}
}
cout << peaks;
}
|
#include <iostream>
#include<vector>
using namespace std;
int main(void){
int n;
cin>>n;
std::vector<int> vec(n) ;
for(int i=0;i<n;i++){
cin>>vec[i];
}
int ans=-1, count=0;
for(int i=1;i<n;i++){
if(vec[i]<=vec[i-1]){
count++;
}
else{
ans= max(ans, count);
count=0;
}
}
ans= max(ans, count);
cout<<ans;
}
| 0 | 73,634,052 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define F first
#define S second
#define in freopen("input.txt", "r", stdin)
#define out freopen("output.txt", "w", stdout)
#define minheap int,vector<int>,greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x) (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
#define bug cout<<"BUG"<<endl;
const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const double PI =3.141592653589793238463;
bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
return (a.first > b.first);
}
ll lcm(ll a,ll b)
{
if(a==0 || b==0)return 0;
return a/__gcd(a,b)*b;
}
void input(ll ara[],ll n)
{
for(ll i=0; i<n; i++)cin>>ara[i];
}
void print(ll ara[],ll n)
{
for(ll i=0; i<n; i++)
cout<<ara[i]<<" ";
cout<<endl;
}
int main()
{
fastread();
ll i,j,n,m,p,a,k,t,b,c,d,cnt=0,q,l,r;
double ans=0;
bool flag=false;
string str;
long double sum=0;
cin>>n>>k;
for(i=1; i<=n; i++)
{
if(i>k)
{
sum+=n-i+1;
break;
}
long double value=1.0;
a=i;
while(a<k)
{
a*=2;
value/=2.0;
}
sum+=value;
}
sum/=n;
cout<<setprecision(12)<<fixed<<sum<<endl;
}
|
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>
#include<limits>
#include<bitset>
#include<functional>
#include<type_traits>
#include<queue>
#include<stack>
#include<array>
#include<random>
#include<utility>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define all(a) (a).begin(),(a),end()
#define rep(i,n) for (int i = 0; i < (n); ++i)
int max(ll a, ll b) {
ll max;
if (a > b) max = a;
else max = b;
return max;
}
int min(ll a, ll b) {
ll min;
if (a < b) min = a;
else min = b;
return min;
}
int main() {
int n;
double a[110];
cin >> n;
rep(i, n) cin >> a[i];
double ans = 0;
double sum = 0;
rep(i, n) {
sum += 1 / a[i];
}
ans = 1 / sum;
printf("%.8lf", ans);
}
| 0 | 18,861,779 |
#include<iostream>
#include<string>
using namespace std;
int i,j,w,h;
string tile[21];
int cnt=0;
int result=0;
int si,sj;
void rec(int i,int j){
if(tile[i][j]=='.'){
tile[i][j]='#';
cnt++;
}
if(i+1 < h && tile[i+1][j]=='.') rec(i+1,j);
if(j+1 <w && tile[i][j+1]=='.') rec(i,j+1);
if(j-1 >=0 && tile[i][j-1]=='.') rec(i,j-1);
if(i-1 >=0 && tile[i-1][j]=='.' ) rec(i-1,j);
}
int main(){
while(1){
cnt=0;
result=0;
cin >> w >> h;
if(w==0 && h==0)break;
for(i = 0; i < h; i++){
cin >> tile[i];
for(j = 0; j < w; j++){
if(tile[i][j]=='@'){
si=i;
sj=j;
}
}
}
rec(si,sj);
cout << cnt+1 << endl;
}
return 0;
}
|
#include<iostream>
#include<vector>
#include<cstdio>
using namespace std;
int p[10001];
int root(int x){
vector <int> v;
while(p[x]!=x){
v.push_back(x);
x=p[x];
}
for(int i=0;i<v.size();i++)p[v[i]]=x;
return x;
}
void unite(int x,int y){
x=root(x);
y=root(y);
if(x!=y){
p[y]=x;
}
}
bool same(int x,int y){
x=root(x);
y=root(y);
if(x==y)return true;
else return false;
}
int main(){
int n,q,com,x,y;
for(int i=0;i<10001;i++)p[i]=i;
cin>>n>>q;
for(int i=0;i<q;i++){
scanf("%d %d %d",&com,&x,&y);
if(com==0){
unite(x,y);
}else{
if(same(x,y))printf("%d\n",1);
else printf("%d\n",0);
}
}
return 0;
}
| 0 | 67,231,934 |
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a[11][11];
int i,j,n,d,ans,chek,cnt=0;
cin>>n>>d;
for(i=0;i<n;i++){
for(j=0;j<d;j++) cin>>a[i][j];
}
for(i=0;i<n;i++){
for(j=i+1;j<n;j++){
ans=0;
for(int k=0;k<d;k++){
ans+=((a[i][k]-a[j][k])*(a[i][k]-a[j][k]));
}
chek=sqrt(ans);
if(chek*chek==ans) cnt++;
}
}
cout<<cnt;
}
|
#include <cstdio>
#include <iostream>
#include <utility>
using namespace std;
const int MAX_N = 40;
pair<char, int> cardB[MAX_N], cardS[MAX_N];
int N;
pair<char, int> pattern[MAX_N];
void show(pair<char, int> *C) {
for (int i = 0; i < N; i++) {
printf("%c%d", C[i].first, C[i].second);
if (i != N - 1) {
printf(" ");
}
}
printf("\n");
}
void input() {
cin >> N;
for (int i = 0; i < N; i++) {
cin >> cardB[i].first >> cardB[i].second;
cardS[i] = cardB[i];
pattern[i] = cardB[i];
}
}
void BubbleSort(pair<char, int> *C, int n) {
pair<char, int> temp;
for (int i = 0; i < n; i++) {
for (int j = n - 1; j >= 0; j--) {
if (C[j].second < C[j - 1].second) {
temp = C[j];
C[j] = C[j - 1];
C[j - 1] = temp;
}
}
}
}
void SelectionSort(pair<char, int> *C, int n) {
pair<char, int> temp;
for (int i = 0; i < n; i++) {
int minj = i;
for (int j = i; j < n; j++) {
if (C[j].second < C[minj].second) {
minj = j;
}
}
if (i != minj) {
temp = C[i];
C[i] = C[minj];
C[minj] = temp;
}
}
}
void isStable(pair<char, int> *C) {
bool f = true;
for (int i = 0; i < N - 1; i++) {
if (C[i].second == C[i + 1].second) {
for (int j = 0; j < N; j++) {
for (int k = 0; k < N; k++) {
if (pattern[j] == C[i] && pattern[k] == C[i + 1]) {
if (j > k) {
f = false;
}
}
}
}
}
}
if (f) {
printf("Stable\n");
}
else {
printf("Not stable\n");
}
}
void solve() {
input();
BubbleSort(cardB, N);
show(cardB);
isStable(cardB);
SelectionSort(cardS, N);
show(cardS);
isStable(cardS);
}
int main() {
solve();
}
| 0 | 57,526,979 |
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
using namespace std;
int main() {
string n;
int co = 1;
cin >> n;
int tmp = n[0];
for (int i = 1; i < 4; ++i) {
if (tmp == n[i])
co++;
if (co >= 3)
break;
if (tmp != n[i]) {
tmp = n[i];
co = 1;
}
}
if (co >= 3)
cout << "Yes" << endl;
else
cout << "No" << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main(void){
string S;
long long K;
cin >> S >> K;
long long cont = 0;
long long contS = 0;
long long contE = 0;
if(K == 1){
for(int i = 0; i < S.size();i++){
if(i != S.size()-1){
if(S[i] == S[i+1]){
S[i+1] = '#';
cont++;
}
}
}
cout << cont << endl;
return 0;
}
if(S[0]==S[S.size()-1]){
contS = 1;
contE = 1;
while(S[contS-1] == S[contS])contS++;
while(S[S.size() - contE] == S[S.size() - contE - 1])contE++;
if(S.size()==contS){
if(S.size()==1){
cout << K/2 <<endl;
return 0;
}
if(S.size()%2==0)cout << (S.size()/2)*K <<endl;
else{
long long difA = S.size()/2;
long long difB = S.size() - difA;
long long sum = 0;
for(int i = 0; i < K;i++){
if(i%2==0)sum += difA;
else sum += difB;
}
cout << sum <<endl;
}
return 0;
}
}
for(int i = contS; i < S.size()-contE;i++){
if(i != S.size()-1){
if(S[i] == S[i+1]){
S[i+1] = '#';
cont++;
}
}else{
if(S[0] == S[i]){
S[0] = '#';
cont++;
}
}
}
cout << cont * K + (contS+contE)/2*(K-1)+ contS/2+contE/2 <<endl;
}
| 0 | 67,635,839 |
#include <bits/stdc++.h>
#define int long long
typedef long long ll;
using namespace std;
const ll MAX = 200000;
const ll INF = 1001001001;
const ll MOD = 1000000007;
ll N, ans=0, tmp=0, ct=0;
vector<ll> A, S;
signed main(){
cin >> N;
if(N==1) {
cout << "YES" << endl;
return 0;
}
for(int i=0;i<N;i++) {
ll a;
cin >> a;
A.push_back(a);
tmp += a;
}
ct = N*(N+1)/2;
if(tmp%ct==0) ct = tmp/ct;
else {
cout << "NO" << endl;
return 0;
}
for(int i=0;i<N-1;i++) {
S.push_back(ct-(A[i+1]-A[i]));
}
S.push_back(ct-(A[0]-A[N-1]));
for(int i=0;i<N;i++) {
if(S[i]%N!=0) {
cout << "NO" << endl;
return 0;
}
else {
if(S[i]<0||S[i]>ct*N) {
cout << "NO" << endl;
return 0;
}
ans += S[i]/N;
}
}
if(ans==ct) cout << "YES" << endl;
else cout << "NO" << endl;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
int n, A, B, C;
int l[8] = {0};
int cost = 1000000;
int how_many_bamboos = 0;
void dfs(int i, int a, int b, int c){
if(i == n){
if(a*b*c == 0) return ;
cost = min (cost ,10*max(0,how_many_bamboos-3) + abs(a-A) + abs(b-B) + abs(c-C));
}
else{
dfs(i+1,a,b,c);
how_many_bamboos += 1;
dfs(i+1,a+l[i],b,c);
dfs(i+1,a,b+l[i],c);
dfs(i+1,a,b,c+ l[i]);
how_many_bamboos -= 1;
}
}
int main(){
cin >> n >> A >> B >> C;
for (int i = 0; i < n; i++)
{
cin >> l[i];
}
dfs(0,0,0,0);
cout << cost << endl;
}
| 0 | 47,679,017 |
#include <bits/stdc++.h>
#include <unordered_set>
#include <stdio.h>
using namespace std;
#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;
#define f first
#define s second
#define ll long long
#define ull unsigned long long
#define endl "\n"
#define PI 3.141592653589793
#define vi vector<int>
#define vll vector<long long>
#define p pair<int,int>
const ll MOD = 1000000007;
inline double degcos(double ang) {return cos(ang*PI/180);}
inline double degsin(double ang) {return sin(ang*PI/180);}
#define rep(i,j,k,in) for (int i = j; i < k; i += in)
#define repr(i,j,k,in) for (int i = j; i > k; i -= in)
#define repll(i,j,k,in) for (ll i = j; i < k; i += in)
#define repllr(i,j,k,in) for (ll i = j; i > k; i -= in)
int N;
const int MAXN = 100001;
vector<int> tree[MAXN];
ll dp[MAXN][2];
const int WHITE = 0, BLACK = 1;
ll solve(int v, int color, int parent) {
if (v == 0) {
return (solve(1,WHITE,0) + solve(1,BLACK,0)) % MOD;
}
ll tot = 1, totWhite, totBlack;
if (dp[v][color] != -1) return dp[v][color];
rep(i,0,tree[v].size(),1) {
if (tree[v][i] != parent) {
if (color == WHITE) {
totBlack = solve(tree[v][i],BLACK,v);
}
else totBlack = 0;
totWhite = solve(tree[v][i],WHITE,v);
tot = (tot * (totWhite + totBlack)) % MOD;
}
}
return dp[v][color] = tot;
}
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
scan(N);
int v1,v2;
rep(i,0,N-1,1) {
scan(v1); scan(v2);
tree[v1].push_back(v2);
tree[v2].push_back(v1);
}
memset(dp,-1,sizeof(dp));
cout << solve(0,0,0);
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define PB push_back
#define MP make_pair
const ll MOD = 1000000007;
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
ll n, m; cin >> n >> m;
unordered_set<ll> a;
for (ll i = 0; i < m; ++i) {
ll ai; cin >> ai;
a.insert(ai);
}
vector<ll> dp(n+1);
dp[0] = 1;
for (ll i = 0; i < n; ++i) {
for (ll j = i + 1; j <= min(n, i + 2); ++j) {
if (a.count(j) == 0) {
dp[j] += dp[i];
dp[j] %= MOD;
}
}
}
cout << dp[n] << "\n";
}
| 0 | 51,783,396 |
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define F first
#define S second
using namespace std;
using P = pair<int,int>;
using ivec = vector<int>;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
const int MOD=1000000007;
int INF=100100100100100;
int a[200010];
int b[200010];
signed main(){
int n;cin>>n;
rep(i,n){
cin>>a[i];
b[i]=a[i];
}
sort(b,b+n);
rep(i,n){
if(a[i]!=b[n-1])cout<<b[n-1]<<endl;
else{
if(b[n-2]==b[n-1])cout<<b[n-1]<<endl;
else cout<<b[n-2]<<endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define all(x) (x).begin(),(x).end()
#define rall(v) (v).rbegin(), (v).rend()
#define FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
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; }
int dx[] = {0, 1};
int dy[] = {1, 0};
int main(){
int h, w;
cin >> h >> w;
vector<string> s(h);
rep(i,h) cin >> s[i];
queue<P> q, q_next;
vector<vector<int>> dist(h, vector<int>(w, -1)), ok(h, vector<int>(w, -1));
if (s[0][0] == '.') dist[0][0] = 0;
else dist[0][0] = 1;
q_next.push(make_pair(0, 0));
while(!q_next.empty()){
P pos = q_next.front(); q_next.pop();
int px = pos.first, py = pos.second;
if (ok[py][px] == 1) continue;
char c = s[py][px];
ok[py][px] = 1;
q.push(pos);
while(!q.empty()){
P p = q.front(); q.pop();
int sx = p.first, sy = p.second;
rep(i,2){
int x = sx+dx[i], y = sy+dy[i];
if (x >= w || y >= h) continue;
if (ok[y][x] == 1) continue;
if (s[y][x] == c){
q.push(make_pair(x, y));
ok[y][x] = 1;
dist[y][x] = dist[sy][sx];
}else{
q_next.push(make_pair(x, y));
ok[y][x] = 0;
if (c == '.') dist[y][x] = dist[sy][sx] + 1;
else dist[y][x] = dist[sy][sx];
}
}
}
}
cout << dist[h-1][w-1] << endl;
return 0;
}
| 0 | 81,145,535 |
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <iterator>
#include <stack>
#include <string.h>
#include <cstdlib>
#include <queue>
#include <list>
#include <string>
using namespace std;
int h;
int w;
char f[2005][2005];
int d[2005][2005];
int u[2005][2005];
int r[2005][2005];
int l[2005][2005];
int main()
{
cin >> h >> w;
for (int i = 0;i < h;i++){
for (int j = 0;j < w;j++){
cin >> f[i][j];
}
}
for (int i = 0;i < w;i++){
if (f[h-1][i] == '.'){
d[h-1][i] = 1;
}
else {
d[h-1][i] = 0;
}
if (f[0][i] == '.'){
u[0][i] = 1;
}
else {
u[0][i] = 0;
}
}
for (int j = 0;j < h;j++){
if (f[j][0] == '.'){
l[j][0] = 1;
}
else {
l[j][0] = 0;
}
if (f[j][w-1] == '.'){
r[j][w-1] = 1;
}
else {
r[j][w-1] = 0;
}
}
for (int i = 0;i < h;i++){
for (int j = 0;j < w;j++){
if (f[i][j] == '.' && j >= 1){
l[i][j] = l[i][j-1] + 1;
}
if (f[i][w-j-1] == '.' && j >= 1){
r[i][w-j-1] = r[i][w-j] + 1;
}
if (f[i][j] == '#'){
l[i][j] = 0;
u[i][j] = 0;
r[i][j] = 0;
d[i][j] = 0;
}
if (f[i][j] == '.' && i >= 1){
u[i][j] = u[i-1][j] + 1;
}
if (f[h-i-1][j] == '.' && i >= 1){
d[h-i-1][j] = d[h-i][j] + 1; }
}
}
int ans = 0;
for (int i = 0;i < h;i++){
for (int j = 0;j < w;j++){
ans = max(l[i][j] + r[i][j] + d[i][j] + u[i][j]-3,ans);
}
}
cout << ans << endl;
}
|
#include<iostream>
#include<string>
#include<cstdio>
#include<stdio.h>
using namespace std;
int main(){
int sum=0;
string str;
while(1){
getline(cin,str);
for(int i=0;i<str.size();i++){
str[i]-='0';
sum+=str[i];
}
if(str[0]==0)break;
cout<<sum<<endl;
sum=0;
}
return 0;
}
| 0 | 31,048,642 |
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <numeric>
#include <queue>
#include <numeric>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <map>
#include <functional>
#include <limits>
#include <set>
#include <stack>
#include <cctype>
#define rep(i,a,b) for((i)=a;i<(int)(b);i++)
#define AAA (1000000007)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pairII;
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 powD(ll a, ll b) {
ll ans = 1;
a %= AAA;
for (int i = 0; i < b; i++)
{
ans *= a;
ans %= AAA;
}
return ans;
}
int main() {
int i, j, k;
int N, M, K;
int P;
int A[50];
ll a = 0, b = 0;
cin >> N >> P;
rep(i, 0, N) {
cin >> A[i];
if (A[i] % 2 == 0) {
a++;
}
else {
b++;
}
}
ll tmp = 1;
ll ans = 0;
if (P == 0) {
j = 0;
}
else {
j = 1;
}
while (j <= b) {
if (j != 0)
tmp *= max((ll)1, (b - j +1));
tmp /= max(1, j);
ans += tmp;
j++;
tmp *= max((ll)1,(b - j+1));
tmp /= j;
j++;
}
ans *= pow(2, a);
cout << ans;
return 0;
}
|
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <math.h>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <functional>
using namespace std;
typedef long long int ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, int> pli;
typedef std::pair<ll, ll> pll;
#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)
const ll MOD = 1000000007;
const ll INF = (ll)1e15;
int main()
{
int n;
cin >> n;
int p[2] = { 0 };
REP(i, n)
{
string s[2];
cin >> s[0] >> s[1];
if (s[0] == s[1])
{
p[0] += 1; p[1] += 1;
}
else if (s[0] > s[1])
{
p[0] += 3;
}
else
{
p[1] += 3;
}
}
cout << p[0] << " " << p[1] << endl;
return 0;
}
| 0 | 41,098,040 |
#include <bits/stdc++.h>
#define ll long long
#define REP(i, n) for (ll i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (ll i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define fi first
#define se second
#define pb push_back
#define debug(x) cerr << #x << ": " << (x) << endl
#define int long long
using namespace std;
using II = pair<int, int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
template <class T = int> inline T in() { T x; cin >> x; return x; }
template <class T = int> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <class T = int> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <class T> ostream& operator<<(ostream &s, const vector<T>& d) { int n = d.size(); REP (i, n) s << d[i] << " "; return s; }
template <class T> ostream& operator<<(ostream &s, const vector<vector<T>>& dd) { for (vector<T> d: dd) s << d << endl; return s; }
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); } } fast;
const int MOD = 1e9 + 7;
signed main() {
int N = in();
VI tri(1e4); tri[1] = 1;
REPI (i, 2, 1e4 - 1) {
tri[i] = tri[i - 1] + i;
}
int num = -1;
REPI (i, 1, 1e4) {
if (N == tri[i]) {
num = i; break;
}
}
if (num == -1) {
cout << "No" << endl; return 0;
}
VVI ans(num + 1);
int i = 0;
for (int k = num; k > 0; k--) {
REP (j, k) {
i++;
ans[num - k].push_back(i);
ans[num - k + j + 1].push_back(i);
}
}
cout << "Yes" << endl;
cout << ans.size() << endl;
for (auto an: ans) {
cout << an.size() << ' ';
for (auto x: an) {
cout << x << ' ';
}
cout << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef pair<int,int> P;
int main(){
ll N;
string S;
cin >> N >> S;
map<char,ll> mp;
rep(i,N){
mp[S[i]]++;
}
ll cnt = 1;
for(auto& e:mp){
cnt *= (e.second+1);
cnt %= mo;
}
cnt--;
cnt %= mo;
cout <<cnt<<endl;
}
| 0 | 99,014,510 |
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
#define maxll pow(10,18)
int main(){
vector<ll> dish(5);
for(int i = 0;i < 5;i++)cin >> dish[i];
vector<ll> num = {0,1,2,3,4};
ll res = 0;
res = maxll;
do{
ll before = 0;
for(int i = 0;i < 5;i++){
if(before % 10 != 0)before += 10 - before % 10;
before += dish[num[i]];
}
res = min(res,before);
}while(next_permutation(num.begin(),num.end()));
cout << res << endl;
}
|
#include<bits/stdc++.h>
#define rep(i,f,n) for(ll i=(f); (i) < (n); i++)
#define repe(i,f,n) for(ll i=(f); (i) <= (n); i++)
using namespace std;
using ll = long long;
ll INF = 1LL << 60;
int
main() {
int N, Q; cin >> N >> Q;
vector<vector<ll>> tree(N + 1);
rep(i, 0, N - 1){
ll a, b; cin >> a >> b;
tree[a].push_back(b);
tree[b].push_back(a);
}
vector<ll> imos(N + 1, 0);
rep(i, 0, Q){
int p, q; cin >> p >> q;
imos[p] += q;
}
queue<ll> q;
vector<bool> seen(N + 1, false);
seen[1] = true;
q.push(1);
while(! q.empty()){
ll nodes = q.front();
q.pop();
for(auto node: tree[nodes]){
if(seen[node])continue;
imos[node] += imos[nodes];
seen[node] = true;
q.push(node);
}
}
rep(i, 1, N + 1){
cout << imos[i] << endl;
}
}
| 0 | 98,657,619 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
const long long INF = 1LL << 60;
const int MOD = 1e9 + 7;
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 H,W,M;
cin >> H >> W >> M;
set<pair<int,int>> table;
vector<int> h_cnt(H+1,0);
vector<int> w_cnt(W+1,0);
int h_max = 0;
int w_max = 0;
rep(i,M){
int h,w;
cin >> h >> w;
table.insert({h,w});
h_cnt.at(h) += 1;
w_cnt.at(w) += 1;
chmax(h_max,h_cnt.at(h));
chmax(w_max,w_cnt.at(w));
}
if(H == 1 || W == 1){
cout << M << endl;
return 0;
}
vector<int> maxHs(0);
vector<int> maxWs(0);
rep(i,H+1){
if(h_cnt.at(i) == h_max){
maxHs.push_back(i);
}
}
rep(i,W+1){
if(w_cnt.at(i) == w_max){
maxWs.push_back(i);
}
}
int ans = h_max + w_max - 1;
rep(i,maxHs.size()){
rep(j,maxWs.size()){
if(table.find({maxHs[i],maxWs[j]}) == table.end()){
ans += 1;
cout << ans << endl;
return 0;
}
}
}
cout << ans << endl;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
ll n;
cin >> n;
bool exist=false;
ll groups = 0, crr = 0;
queue<ll> q, tpq;
if(n>2){
for(ll i=2;i<2*n;i++){
if((2*n)%i!=0) continue;
else{
if(abs((2*n)/i - i) == 1) {
groups = i;
exist = true;
break;
}
}
}
}
if(exist){
cout << "Yes" << endl;
cout << 2*n/groups << endl;
for(ll i=0;i<2*n/groups;i++){
ll cnt = 0;
cout << groups << " ";
if(i == 0){
for(crr=1;crr<=groups;crr++){
cout << crr << " ";
}
cout << endl;
q.push(1);
continue;
}
while(!q.empty()){
cnt += 1;
cout << q.front() << " ";
tpq.push(q.front() + 1);
q.pop();
}
ll tar = crr + groups - cnt;
tpq.push(crr);
for(;crr < tar; crr++){
cout << crr << " ";
}
cout << endl;
q = tpq;
while(!tpq.empty()){
tpq.pop();
}
}
}else{
if(n == 1){
cout << "Yes" << endl;
cout << 2 << endl;
cout << 1 << " " << 1 << endl;
cout << 1 << " " << 1 << endl;
}else{
cout << "No" << endl;
}
}
}
| 0 | 49,120,921 |
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b,c,d,ans;
while(cin >> a >> b >> c >> d){
ans = 0;
ans+=min(a,b);
ans+=min(c,d);
cout << ans << endl;
}
}
|
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>
const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;
using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
if (a.first == b.first)
return a.second < b.second;
return a.first < b.first;
}
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec) \
std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec) \
std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VV(T, a, b, c) vector<vector<T>>(a, vector<T>(b, c))
#define VVVL(a, b, c, d) \
vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define VVV(T, a, b, c, d) \
vector<vector<vector<T>>>(a, vector<vector<T>>(b, vector<T>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec) \
do { \
sort(ALL((vec))); \
(vec).erase(std::unique(ALL((vec))), (vec).end()); \
} while (0)
ll POW(ll n, ll m) {
if (m == 0) {
return 1;
} else if (m % 2 == 0) {
ll tmp = POW(n, m / 2);
return (tmp * tmp);
} else {
return (n * POW(n, m - 1));
}
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll N;
cin >> N;
vl A(N, 0);
REP(i, N) {
ll x;
cin >> x;
A[x - 1]++;
}
sort(ALL(A));
vl sum(N, 0);
sum[0] = A[0];
FOR(i, 1, N) sum[i] = sum[i - 1] + A[i];
ll ans = N;
FOR(k, 1, N + 1) {
while (true) {
if (ans == 0)
break;
else {
ll index = upper_bound(ALL(A), ans) - A.begin();
ll x = sum[index - 1] + ans * (N - index);
if (x >= ans * k)
break;
}
ans--;
}
cout << ans << endl;
}
return 0;
}
| 0 | 41,798,522 |
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using LL = long long;
using P = pair<int,int>;
int main(){
string S;
cin >> S;
if(S[2]==S[3]&&S[4]==S[5]) cout << "Yes" << endl;
else cout << "No" << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#define INF 1e9
bool solve(char c1,char c2){
if(c1=='(')return c2==')';
else return c2==']';
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
while(1){
string s;
getline(cin,s);
if(s==".")break;
stack<char> st;
bool ans=true;
for(int i=0;i<s.size();i++){
if(s[i]=='(' || s[i]=='[')st.push(s[i]);
else if(s[i]==')' || s[i]==']'){
if(st.empty())ans=false;
else{
if(solve(st.top(),s[i])){
st.pop();
}
else{
ans=false;
}
}
}
}
if(!st.empty())ans=false;
if(ans)cout<<"yes"<<endl;
else cout<<"no"<<endl;
}
}
| 0 | 100,435,692 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int H, N, O = 0;
cin >> H >> N;
vector<int> A(N);
for (int i = 0; i < N; i++) {cin >> A.at(i);}
for (int i = 0; i < N; i++) {O += A.at(i);}
if (O >= H) {cout << "Yes" << endl;}
else {cout << "No" << endl;}
}
|
#include <iostream>
#include <string>
using namespace std;
int main() {
string s,left,right;
int a, b;
while (cin >> s, s != "-") {
cin >> a;
for (int i = 0; i < a; i++) {
cin >> b;
left = s.substr(0, b);
right = s.substr(b);
s = right + left;
}
cout << s << endl;
}
return 0;
}
| 0 | 16,668,223 |
#include <iostream>
#include <string>
#include <queue>
#define llint long long
using namespace std;
llint n;
llint a[100005];
void GaussianElimination(llint a[], int n)
{
llint r = 0;
for(int i = 59; i >= 0 && r < n; i--){
if((a[r]&(1LL<<i)) == 0){
int p = -1;
for(int j = r+1; j < n; j++){
if(a[j] & (1LL<<i)){
p = j;
break;
}
}
if(p == -1) goto end;
swap(a[r], a[p]);
}
for(int j = 0; j < n; j++){
if(j == r) continue;
if(a[j]&(1LL<<i)) a[j] ^= a[r];
}
r++;
end:;
}
}
int main(void)
{
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for(int i = 0; i < n; i++) cin >> a[i];
llint ans = 0;
for(int i = 0; i < 60; i++){
llint cnt = 0;
for(int j = 0; j < n; j++) if(a[j] & (1LL<<i)) cnt++;
if(cnt % 2){
ans += (1LL<<i);
for(int j = 0; j < n; j++) a[j] &= ~(1LL<<i);
}
}
GaussianElimination(a, n);
llint tmp = 0, pre = 0;
for(int i = 59; i >= 0; i--){
if(tmp & (1LL<<i)) continue;
for(int j = pre; j < n; j++){
for(int k = 59; k >= i+1; k--){
if(a[j] & (1LL<<k)) goto pass;
}
if(a[j] & (1LL<<i)) tmp ^= a[j], pre = j;
break;
pass:;
}
}
ans += tmp * 2;
cout << ans << endl;
return 0;
}
|
#include <algorithm>
#include <iostream>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
int N, A, B, C, X;
int Y[101];
int next(int x) { return (A * x + B) % C; }
void solve() {
int cnt = 0;
int ans;
int pos = 0;
while (1) {
if (cnt == 10001) {
cnt = -1;
break;
}
if (X == Y[pos]) pos++;
X = next(X);
if (pos == N) break;
cnt++;
}
cout << cnt << endl;
}
int main() {
while (cin >> N >> A >> B >> C >> X) {
if (N == 0) break;
rep(i, N) cin>>Y[i];
solve();
}
}
| 0 | 93,906,559 |
#include <iostream>
#include <queue>
#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define REP(i,n) FOR(i,0,n)
using namespace std;
int main(){
int n,u,k,v,src=0;
cin >> n;
int D[n],g[n][n];
REP(i,n){
D[i] = -1;
REP(j,n){
g[i][j] = 0;
}
}
REP(i,n){
cin >> u >> k;
REP(j,k){
cin >> v;
g[v-1][u-1] = 1;
}
}
queue<int> Q;
Q.push(src);
D[src] = 0;
while (!Q.empty()) {
int cur = Q.front();
Q.pop();
REP(i,n){
if(g[i][cur] == 1 && D[i] < 0){
D[i] = D[cur] + 1;
Q.push(i);
}
}
}
REP(i,n){
cout << i+1 << " " << D[i] << endl;
}
}
|
#include <bits/stdc++.h>
#define NREP() for(ll i = 0; i < n; i++)
#define MREP() for(ll j = 0; j < m; j++)
#define REP(i, x, y) for(ll i = x; i < y; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define MSGF(x, n) MSG(fixed << setprecision(n) << x)
#define END(x) cout << x << endl; exit(0);
#define IPT(v, n) REP(i, 0, n){ cin >> v[i]; }
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<ull> vul;
typedef vector<vector<ull>> vvul;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
const static ll MOD = 1e9 + 7;
const static ll INF = 1LL << 30;
ll a, b, c, d, k, l, m, n, h, w, q, x, y;
string s, t;
ll ans = 0;
ll sum = 0;
ll cnt = 0;
ll cur = 0;
ll tmp = 0;
ll mini = INF;
ll maxi = 0;
double ave = 0.0;
ll mod_pow(ll base, ll power) {
if (power == 0) return 1;
if (power == 1) return base % MOD;
if (power % 2 == 0) return ((mod_pow(base % MOD, (power / 2)) % MOD) * (mod_pow(base, (power / 2)) % MOD)) % MOD;
return (base % MOD * (mod_pow(base % MOD, power - 1) % MOD)) % MOD;
}
ll mod_fact(ll number) {
ll ret = 1;
ll count = 1;
while (count <= number) {
ret *= (count % MOD);
ret %= MOD;
count++;
}
return ret % MOD;
}
int main() {
cin >> n >> s >> k;
char target = s.at(k-1);
REP(i, 0, s.size()) {
if (s.at(i) != target) cout << "*";
else cout << s.at(i);
}
cout << endl;
}
| 0 | 43,176,082 |
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
vector<string> key={".,!? ","abc","def","ghi","jkl","mno",
"pqrs","tuv","wxyz"};
int main(){
int n; cin>>n;
while(n--){
string s; cin>>s;
s+='0';
string ret="";
for(int i=1;i<s.size();i++){
while(i<s.size()&&s[i]==s[i-1]&&s[i]=='0'){
s.erase(s.begin()+i);
}
}
while(s[0]=='0') s.erase(s.begin());
int type=s[0]-'0'-1;
int push=0;
for(int i=1;i<s.size();i++){
if(type==s[i]-'0'-1) push=(push+1)%key[type].size();
else if(s[i]=='0'){
ret+=key[type][push];
if(i+1<s.size()){
type=s[i+1]-'0'-1;
push=-1;
}
else type=-1;
}
else{
ret+=key[type][push];
type=s[i]-'0'-1;
push=0;
}
}
if(type!=-1){
ret+=key[type][push];
}
cout<<ret<<endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(j, m) for (int j = 0; j < (int)(m); j++)
#define rep2(i, l, n) for (int i = l; i < (int)(n); i++)
int main() {
string S;
cin >> S;
rep2(i,'a','z' + 1) {
int flag = 0;
rep(j,S.size()) {
if (S[j] == i) {
flag++;
}
}
if (flag == 0) {
char c = i;
cout << c << endl;
break;
}
if (i == 'z') {
cout << "None" << endl;
}
}
}
| 0 | 89,094,916 |
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int main()
{
string s;
cin >> s;
if (s[3] == s[2] && s[4] == s[5])
cout << "Yes";
else
cout << "No";
}
|
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
int main(){
string A,B;
cin>>A>>B;
if(A.length()>B.length()){
cout<<"GREATER";
return 0;
}
if(A.length()<B.length()){
cout<<"LESS";
return 0;
}
if(A.length()==B.length()){
rep(i,A.length()){
if(A[i]>B[i]){
cout<<"GREATER";
return 0;
}
if(A[i]<B[i]){
cout<<"LESS";
return 0;
}
}
}
cout<<"EQUAL"<<endl;
}
| 0 | 75,052,036 |
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0; i<n; i++)
#define REP(i,x,n) for (int i=x; i<n; i++)
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
ll gcd(ll a, ll b){
if (b == 0){
return a;
}
return gcd(b, a%b);
}
ll lcm(ll a, ll b){
ll c = gcd(a, b);
return a / c * b;
}
int main(){
int n;
cin >> n;
ll ans = 1LL;
rep(i,n){
ll t;
cin >> t;
ans = lcm(ans, t);
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
#define FOR(i,a,b) for(int64_t i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
struct Edge {
ll st,tr;
Edge(ll s, ll t)
: st(s), tr(t)
{}
};
struct Node{
vector<Edge> edges;
};
using Graph = vector<Node>;
vector<ll> tsort_tarjan(Graph& g){
auto num = g.size();
enum class State { NEW, ACTIVE, FINISHED };
vector<State> state(num, State::NEW);
vector<ll> res(num);
function<bool(int)> dfs = [&](ll v){
state[v]=State::ACTIVE;
for(const auto& e : g[v].edges){
auto w = e.tr;
if (state[w] == State::ACTIVE) return false;
else if (state[w] == State::NEW) if (!dfs(w)) return false;
}
state[v]=State::FINISHED;
res.push_back(v);
return true;
};
for (ll n=0;n<num;++n) {
if(state[n]==State::NEW && !dfs(n)) return {};
}
std::reverse(res.begin(),res.end());
return res;
}
int main() {
ll vn, en; cin>>vn>>en;
Graph graph(vn);
REP(i,en){
ll s,t; cin>>s>>t;
graph.at(s).edges.emplace_back(s,t);
}
auto ord = tsort_tarjan(graph);
for(const auto& o:ord){
cout<<o<<endl;
}
return 0;
}
| 0 | 98,098,893 |
#include <bits/stdc++.h>
using namespace std;
void solve(std::string S, std::string T){
int cnt = 0;
for(int i = 0; i < S.size(); ++i){
if(S[i] == T[i]) cnt++;
}
cout << cnt << endl;
}
int main(){
std::string S;
std::cin >> S;
std::string T;
std::cin >> T;
solve(S, T);
return 0;
}
|
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = LLONG_MAX/4;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
string s;cin >> s;
ll n = s.size();
Pll res;
bool ok = false;
rep(i,n-1){
if(s[i] == s[i+1]){
res = Pll(i+1,i+2);
ok = true;
break;
}
}
rep(i,n-2){
if(s[i] == s[i+2]){
res = Pll(i+1,i+3);
ok = true;
break;
}
}
auto print = [&](Pll x){
cout << x.first << " " << x.second << endl;
};
ok ? print(res) : print(Pll(-1,-1));
}
| 0 | 55,240,007 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
using pii = pair<int, int>;
int main() {
ll a, b;
cin >> a >> b;
cout << a * b / __gcd(a, b) << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int n;
string s[100005];
int t[100005];
string S;
bool x=false;
ll ans;
int main(void){
cin>>n;
for(int i=0;i<n;i++){
cin>>s[i]>>t[i];
}
cin>>S;
for(int i=0;i<n;i++){
if(x) ans+=t[i];
if(s[i]==S){
x=true;
}
}
cout<<ans<<endl;
}
| 0 | 77,266,876 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define SQ(a) (a)*(a)
template <class T, class U> ostream& operator<< (ostream &out, pair<T,U> c) { out << "(" << c.first << " "; out << c.second << ")"; return out; }
template <class T> ostream& operator<< (ostream &out, vector<T> c) { for (auto it = c.begin(); it != c.end(); ++it) { if (it != c.begin()) out << " "; out << *it; } return out; }
template <class T> ostream& operator<< (ostream &out, set<T> c) { for (auto it = c.begin(); it != c.end(); ++it) { if (it != c.begin()) out << " "; out << *it; } return out; }
const double PI = 3.141592653589793238463;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
string s;
cin >> s;
int end = s.size() - 2, mid = end/2;
bool t;
while(mid > 0){
t = true;
FOR(i,0,mid){
if(s[i] != s[i+mid]){
t = false;
}
}
if(t){
cout << end;
break;
}
else
{
end -= 2;
mid = end/2;
}
}
cout << endl;
}
|
#include <bits/stdc++.h>
#define f(i,n) for(int i=0;i<(n);i++)
#define inf (int)(3e18)
#define int long long
#define mod (int)(1000000007)
#define intt long long
#define P pair<int,int>
using namespace std;
int modpow(int x, int y, int m = mod) {
int res = 1;
while (y) {
if (y % 2) {
res *= x;
res %= m;
}
x = x * x % mod;
y /= 2;
}
return res;
}
int mypow(int x, int y) {
int res = 1;
while (y) {
if (y % 2) {
res *= x;
}
x = x * x;
y /= 2;
}
return res;
}
bool prime(int x) {
for (int i = 2; i * i <= x; i++) {
if (!(x % i)) {
return false;
}
}
return true;
}
double kyori(pair<int, int> f, pair<int, int> s) {
double ans = 0;
double t = fabs(f.first - s.first);
double y = fabs(f.second - s.second);
ans = sqrt(t * t + y * y);
return ans;
}
inline int gcd(int x, int y) {
if (!y) {
return x;
}
return gcd(y, x % y);
}
class Union_Find {
vector<int> par;
vector<int> rankmy;
public:
Union_Find(int size) {
par = vector<int>(size);
rankmy = vector<int>(size);
for (int i = 0; i < size; i++) {
par[i] = i;
}
}
int find(int x) {
if (par[x] == x) {
return x;
}
return par[x] = find(par[x]);
}
void unite(int x, int y) {
x = find(x);
y = find(y);
if (x == y) {
return;
}
if (rankmy[x] < rankmy[y]) {
par[x] = y;
}
else {
par[y] = x;
if (rankmy[x] == rankmy[y]) {
rankmy[x]++;
}
}
}
bool same(int x, int y) {
return find(x) == find(y);
}
};
template <class T>
class SegTree {
int n;
vector<T> data;
T def;
function<T(T, T)> operation;
function<T(T, T)> update;
T _query(int a, int b, int k, int l, int r) {
if (r <= a || b <= l) return def;
if (a <= l && r <= b)
return data[k];
else {
T c1 = _query(a, b, 2 * k + 1, l, (l + r) / 2);
T c2 = _query(a, b, 2 * k + 2, (l + r) / 2, r);
return operation(c1, c2);
}
}
public:
SegTree(size_t _n, T _def, function<T(T, T)> _operation,
function<T(T, T)> _update)
: def(_def), operation(_operation), update(_update) {
n = 1;
while (n < _n) {
n *= 2;
}
data = vector<T>(2 * n - 1, def);
}
void change(int i, T x) {
i += n - 1;
data[i] = update(data[i], x);
while (i > 0) {
i = (i - 1) / 2;
data[i] = operation(data[i * 2 + 1], data[i * 2 + 2]);
}
}
T query(int a, int b) {
return _query(a, b, 0, 0, n);
}
T operator[](int i) {
return data[i + n - 1];
}
};
#define R_MIN ([](long long a, long long b) { return min(a, b); })
#define R_MAX ([](long long a, long long b) { return max(a, b); })
#define R_SUM ([](long long a, long long b) { return a + b; })
#define NORMAL_UPDATE ([](long long a, long long b) { return b; })
#define ADD_UPDATE ([](long long a, long long b) { return a + b; })
#define MINUS_UPDATE ([](long long a, long long b) { return a - b; }
int keta(int x) {
int ans = 0;
while (x) {
x /= 10;
ans++;
}
return ans;
}
int ketasum(int x) {
int ans = 0;
while (x) {
ans += x % 10;
x /= 10;
}
return ans;
}
inline int lcm(int x, int y) {
int ans = x / gcd(x, y) * y;
return ans;
}
int twobeki(int x) {
int ans = 0;
while (1) {
if (!(x & 1)) {
ans++;
x /= 2;
}
else {
break;
}
}
return ans;
}
int kai(int x, int y) {
int res = 1;
for (int i = x - y + 1; i <= x; i++) {
res *= i; res %= mod;
}
return res;
}
int comb(int x, int y) {
if (y > x)return 0;
return kai(x, y) * modpow(kai(y, y), mod - 2) % mod;
}
int fukugen(vector<int> l) {
int ans = 0;
for (int i = 0; i < (int)l.size(); i++) {
ans *= 10;
ans += l[i];
}
return ans;
}
int nanjyo(int n){
int ans=0;
while (n>1) {
ans++;
n/=2;
}
return ans;
}
bool intersect(pair<pair<int,int>, pair<int,int>>p1 ,pair<pair<int,int>,pair<int,int>>p2){
int men11=(p2.first.first-p1.first.first)*(p2.second.second-p1.first.second)-(p2.second.first-p1.first.first)*(p2.first.second-p1.first.second);
int men12=(p2.first.first-p1.second.first)*(p2.second.second-p1.second.second)-(p2.second.first-p1.second.first)*(p2.first.second-p1.second.second);
int men21=(p1.first.first-p2.first.first)*(p1.second.second-p2.first.second)-(p1.second.first-p2.first.first)*(p1.first.second-p2.first.second);
int men22=(p1.first.first-p2.second.first)*(p1.second.second-p2.second.second)-(p1.second.first-p2.second.first)*(p1.first.second-p2.second.second);
return ((signbit(men11)) ^ (signbit(men12))) && ((signbit(men21)) ^ (signbit(men22)));
}
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
if (lhs < rhs) {
lhs = rhs;
return 1;
}
return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
if (lhs > rhs) {
lhs = rhs;
return 1;
}
return 0;
}
void Yes(){
cout<<"Yes"<<endl;
}
void No(){
cout<<"No"<<endl;
}
void YES(){
cout<<"YES"<<endl;
}
void NO(){
cout<<"NO"<<endl;
}
int yakusuu(int x){
int ans=0;
for (int i=1; i*i<=x; i++) {
if (!(x%i)) {
if (i*i==x) {
ans++;
}
else ans+=2;
}
}
return ans;
}
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
int n,m,x[100004],y[100004],z[100004],ans;
signed main(){
cin>>n>>m;
ans=0-inf;
rep(i, n)scanf("%lld%lld%lld",&x[i],&y[i],&z[i]);
rep(i, 8){
bitset<4> bits(i);
vector<int> vec;
rep(j, n){
int ad=0;
if (!bits[0]) {
ad+=x[j];
}else{
ad-=x[j];
}
if (!bits[1]) {
ad+=y[j];
}else{
ad-=y[j];
}
if (!bits[2]) {
ad+=z[j];
}else{
ad-=z[j];
}
vec.push_back(ad);
}
sort(vec.begin(), vec.end(),greater<int>());
int karians=0;
rep(j, m){
karians+=vec[j];
}
chmax(ans, karians);
}
cout<<ans<<endl;
}
| 0 | 78,122,395 |
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
using namespace std;
using ll = long long;
int gcd(int a, int b){
if(b == 0) return a;
return gcd(b, a % b);
}
int lcm(int a, int b){
return a * b / gcd(a, b);
}
int main()
{
ll a,b,c,d;
cin >> a >> b >> c >> d;
ll cn,dn,cdn;
cn = b/c - (a-1)/c;
dn = b/d - (a-1)/d;
cdn = b/lcm(c,d) - (a-1)/lcm(c,d);
ll ans = b-a+1-(cn+dn-cdn);
cout << ans << endl;
return 0;
}
|
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<string.h>
using namespace std;
#define INF 1000000
int E,V,r[50][3],d[12][12];
void warshall_floyd(){
for(int k=0;k<V;k++)
for(int i=0;i<V;i++)
for(int j=0;j<V;j++)
d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
}
void init(){
for(int i=0;i<12;i++)
for(int j=0;j<12;j++)
d[i][j]=INF;
memset(r,0,sizeof(r));
V=0;
E=0;
}
void solve(){
warshall_floyd();
int res[12];
fill(res,res+12,0);
for(int i=0;i<V;i++){
for(int j=0;j<V;j++){
res[i]+=d[i][j];
}
}
int res1=INF;
int res2=INF;
for(int i=0;i<V;i++){
if(res[i]<res2){
res1=i;
res2=res[i];
}
}
printf("%d %d\n",res1,res2);
}
int main(){
while(true){
init();
scanf("%d",&E);
if(E==0) break;
for(int i=0;i<E;i++){
scanf("%d%d%d",&r[i][0],&r[i][1],&r[i][2]);
}
for(int i=0;i<10;i++){
V=max(V,r[i][1]);
}
V++;
for(int i=0;i<E;i++){
d[r[i][0]][r[i][1]]=r[i][2];
d[r[i][1]][r[i][0]]=r[i][2];
}
for(int i=0;i<V;i++)
d[i][i]=0;
solve();
}
return 0;
}
| 0 | 27,856,119 |
#include <iostream>
using namespace std;
int main(){
string s; cin >> s;
while (s.size() >= 5) {
string fi, si, sv;
if (s.size() >= 5) fi = s.substr(0, 5);
if (s.size() >= 6) si = s.substr(0, 6);
if (s.size() >= 7) sv = s.substr(0, 7);
if (sv == "dreamer" && s[7] != 'a') s.erase(0, 7); else
if (si == "eraser" && s[6] != 'a') s.erase(0, 6); else
if (fi == "erase" || fi == "dream") s.erase(0, 5);
else break;
}
cout << (s.size() ? "NO" : "YES") << '\n';
}
|
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
int main(){
string s;
cin >> s;
deque<ll> q;
rep(i, s.size()){
switch(s[i]){
case '0':
q.push_back(0);
break;
case '1':
q.push_back(1);
break;
case 'B':
if(!q.empty()){
q.pop_back();
}
break;
}
}
while(!q.empty()){
cout << q.front();
q.pop_front();
}
cout << endl;
return 0;
}
| 0 | 82,897,567 |
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <math.h>
#include <queue>
#include <deque>
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; }
using namespace std;
int main(){
int n, k;
cin >> n >> k;
cout << n-k+1 << endl;
return 0;
}
|
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include<chrono>
using namespace std;
using namespace std::chrono;
using namespace __gnu_pbds;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define fi first
#define se second
#define int long long
#define pb push_back
#define emp emplace_back
#define vv(x) vector<x>
#define mp(x,y) map<x,y>
#define dq(x) deque<x>
#define pql(x) priority_queue<x>
#define pqs(x) priority_queue<x,vv(x),greater<x> >
#define M 1000000007
#define forf(i,a,b) for(int i=a;i<b;i++)
#define it(x) x::iterator
#define ll long long
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
#define vii vector<int>
#define big 3e18
#define sm -2e9
#define mkr make_pair
#define vpi vector<pair<int,int> >
#define pii pair<int,int>
#define rng 500005
#define sz(x) (int)x.size()
#define rv(x) reverse(x.begin(),x.end())
#define out(x) cout<<x.fi<<" "<<x.se<<endl;
void pr_init()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
}
#define inv 500000004
int cum(int n)
{
return ((n%M*(n+1)%M)%M*inv)%M;
}
void solve()
{
int n,k;
cin >> n >> k;
int an = 0;
for(int cc = k; cc <= n+1 ; cc++)
{
int ex = (cum(n) - cum(n-cc) - cum(cc-1) +M)%M + 1;
an += ex;
an%=M;
}
cout<<an<<endl;
}
int32_t main()
{
pr_init();
fastio;
solve();
}
| 0 | 83,649,127 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int a, b, c, min=5000;
cin>>a>>b>>c;
vector<int> v(3);
v[0] = a+b;
v[1] = b+c;
v[2] = c+a;
sort(v.begin(), v.end());
cout<<v[0]<<endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
int main() {
int N;
cin >> N;
vector<ll> A(N);
rep(i, N) cin >> A[i];
ll mx = 1;
ll ans = 0;
rep(i, N) {
if(A[i] == mx) {
mx++;
} else {
ans += A[i]/mx-(A[i]%mx==0);
if(i == 0) mx++;
}
}
cout << ans << endl;
return 0;
}
| 0 | 32,145,883 |
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
using ll = long long;
using Graph = vector<vector<pair<int, int>>>;
const ll INF = 1001001001;
int main(){
int n, k; cin >> n >> k;
vector<int> a(n);
for(int i = 0; i < n; i++) cin >> a[i];
sort(a.begin(), a.end());
ll ans = 0;
for(int i = 0; i < k; i++){
ans += a[i];
}
cout << ans << endl;
}
|
#include <iostream>
using namespace std;
int main()
{
int i, n, h, w, check=0;
cin >> n >> h >> w;
int A, B;
for(i=0;i<n;i++)
{
cin >> A >> B;
if(h<=A && w<= B)
{
check++;
}
}
cout << check << endl;
}
| 0 | 22,432,216 |
#include <iostream>
using namespace std;
#include <string>
int main(){
int n;cin >> n;
string s,t;cin >> s >> t;
for(int i=0; i<n; i++){
cout << s.at(i) << t.at(i);
}
printf("\n");
return 0;
}
|
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define pii pair<int,int>
#define pqi priority_queue<int>
#define pb push_back()
#define INF 1000000000000000000
#define pi acos(-1)
#define deb(x) cout<<#x" = "<<x<<" "
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
#define all(x) x.begin(),x.end()
const int modu=1e9+7;
#define ull unsigned long long
void clesize(vector<int>&v,int n,int val=0){ v.clear(),v.resize(n,val); }
int bigmod(int n,int p){
if(p==0) return 1;
int x=bigmod(n,p/2)%modu;
x=(x*x)%modu;
if(p%2) return (x*n)%modu;
return x;
}
int modInverse(int a){
return bigmod(a,modu-2)%modu;
}
int add(int a,int b){
int ans=(a%modu + b%modu)%modu;
while(ans<0) ans+=modu;
return ans;
}
int mul(int a,int b){
int ans=(a%modu * b%modu)%modu;
while(ans<0) ans+=modu;
return ans;
}
int32_t main(){
ios_base::sync_with_stdio(false);cin.tie();cout.tie();
int n,m;
cin>>n>>m;
int grid[n][m],ans[n][m];
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
ans[i][j]=INF;
char x;
cin>>x;
grid[i][j] = (x=='.') ? 0:1;
}
}
ans[0][0]=grid[0][0];
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(j+1<m){
int now=ans[i][j];
if(grid[i][j+1] && !grid[i][j]) now++;
ans[i][j+1]=min(ans[i][j+1],now);
}
if(i+1<n){
int now=ans[i][j];
if(grid[i+1][j] && !grid[i][j]) now++;
ans[i+1][j]=min(ans[i+1][j],now);
}
}
}
cout<<ans[n-1][m-1];
return 0;
}
| 0 | 35,696,084 |
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < n; i++)
int main(){
string S;
cin >> S;
int N = (int)S.size();
vector<bool> used(30, false);
if(N != 26){
char w;
rep(i, N) used[S[i] - 'a'] = true;
rep(i, 26){
if(!used[i]){
w = char(i + 'a');
break;
}
}
S.push_back(w);
cout << S << endl;
return 0;
}else{
string T;
T = S;
bool exist = next_permutation(S.begin(), S.end());
if(!exist){
cout << -1 << endl;
return 0;
}
string ans;
rep(i, N){
ans.push_back(S[i]);
if(S[i] > T[i]){
break;
}
}
cout << ans << endl;
return 0;
}
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr ll inf = LLONG_MAX;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
ll fact(int i) {
if (i == 0) return 1;
return (fact(i - 1)) * i;
}
ll gcd(ll a, ll b) {
if(b == 0) return a;
return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
return a * b / gcd(a, b);
}
int keta(ll n) {
if(n == 0) return 1;
int count = 0;
while(n != 0) {
n /= 10;
count++;
}
return count;
}
ll ketasum(ll n) {
ll sum = 0;
while(n != 0) {
sum += n % 10;
n /= 10;
}
return sum;
}
int main() {
int n;
cin >> n;
vi a(n);
rep(i, n) cin >> a[i];
int k = 1;
int count = 0;
rep(i, n) {
if(k!=a[i]) count++;
else k++;
}
if(count == n)count= -1;
cout << count << endl;
}
| 0 | 66,921,695 |
#include <iostream>
#include <string>
using namespace std;
int W, H, ans;
int tile[20][20];
void DPS(int x, int y);
int main() {
int sx = 0, sy = 0;
string str;
while (cin >> W >> H, W, H) {
for (int i = 0; i < H; i++) {
cin >> str;
for (int j = 0; j < W; j++) {
tile[i][j] = (str[j] == '#') ? 0 : 1;
if (str[j] == '@') {
sx = j;
sy = i;
}
}
}
ans = 0;
DPS(sx, sy);
cout << ans << endl;
}
}
void DPS(int x, int y) {
if (tile[y][x]) {
tile[y][x] = 0;
ans++;
if (x - 1 >= 0) DPS(x - 1, y);
if (x + 1 < W) DPS(x + 1, y);
if (y - 1 >= 0) DPS(x, y - 1);
if (y + 1 < H) DPS(x, y + 1);
}
return;
}
|
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long LL;
typedef pair<int,int> P;
const int S=1e5;
LL X[S];
int W[S];
vector<int> ps[2];
vector<int> xs[2];
LL N,L;
int f(LL T, LL s)
{
if(ps[0].size()==0||ps[1].size()==0){
return 0;
}
int f=0;
int a;
int b;
if(W[s]==1){
a=lower_bound(ps[0].begin(),ps[0].end(),s)-ps[0].begin();
b=(lower_bound(xs[1].begin(),xs[1].end(),X[s])-xs[1].begin())%xs[1].size();
}
else
{
f=1;
a=lower_bound(ps[1].begin(),ps[1].end(),s)-ps[1].begin();
b=(lower_bound(xs[0].begin(),xs[0].end(),X[s])-xs[0].begin()+xs[0].size()-1)%ps[0].size();
}
LL c=0;
int sg[2]={1,-1};
while(c<T){
LL p=sg[f]*c+X[ps[f][a]];
LL q=sg[f^1]*c+X[ps[f^1][b]];
p%=L;
if(p<0){
p+=L;
}
q%=L;
if(q<0){
q+=L;
}
if(f==0&&q<=p){
q+=L;
}
else if(f==1&&p<=q){
p+=L;
}
if(abs(p-q)/2+c<T){
c+=abs(p-q)/2;
int t=(ps[f].size()+sg[f^1]+a)%ps[f].size();
a=b;
b=t;
f^=1;
}
else{
break;
}
}
return ps[f][a];
}
P od[S];
int main() {
LL T;
cin >> N >> L >> T;
L*=2;
T*=2;
for(int i=0;i<N;i++){
cin >> X[i] >> W[i];
X[i]*=2;
if(W[i]==1){
ps[0].push_back(i);
xs[0].push_back(X[i]);
}
else{
ps[1].push_back(i);
xs[1].push_back(X[i]);
}
}
LL o=f(T%L,(T/L*f(L,0))%N)%N;
for(int i=0;i<N;i++){
LL v=X[i];
if(W[i]==1){
v+=T;
}
else{
v-=T;
}
v%=L;
if(v<0){
v+=L;
}
od[i]=P(v/2,W[i]);
}
P key=od[o];
sort(od,od+N);
int s=lower_bound(od,od+N,key)-od;
for(int i=0;i<N;i++){
cout << od[(s+i)%N].first << endl;
}
return 0;
}
| 0 | 66,842,668 |
#include<bits/stdc++.h>
using namespace std;
#define inf 1e9
#define ll long long
#define ull unsigned long long
#define M 1000000007
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(n,a) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
void f(){
string x,y;
cin>>x>>y;
int dp[1100][1100]={};
rep(i,x.length()+1){
rep(j,y.length()+1){
if(i==0||j==0) continue;
if(x[i-1]==y[j-1]) dp[i][j]=dp[i-1][j-1]+1;
else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
}
}
cout<<dp[(int)x.length()][(int)y.length()]<<endl;
}
int main(){
int q;
cin>>q;
while(q--){
f();
}
}
|
#include<iostream>
#include<string>
using namespace std;
int main(){
int m;
int s=100000;
cin>>m;
for(int i=0;i<m;i++){
s = s*1.05;
if(s%1000!=0)
s = ((s/1000)+1)*1000;
}
cout<<s<<endl;
return 0;
}
| 0 | 88,565,693 |
#include<iostream>
#include <map>
#include <string>
using namespace std;
int main() {
int n;
string com;
map<string, int> dic;
cin >> n;
string str;
int cnt = 0;
for (int i = 0; i < n; i++) {
cin >> com >> str;
if (com[0] == 'i') {
dic[str]= cnt;
cnt++;
}
else {
int ret = dic.count(str);
if (ret == 1)
cout << "yes" << endl;
else
cout << "no" << endl;
}
}
return 0;
}
|
#include <iostream>
#include <string>
using namespace std;
class Dice{
public:
int dice[6];
int buf;
void north(){
buf = dice[0];
dice[0] = dice[1];
dice[1] = dice[5];
dice[5] = dice[4];
dice[4] = buf;
}
void south(){
buf = dice[0];
dice[0] = dice[4];
dice[4] = dice[5];
dice[5] = dice[1];
dice[1] = buf;
}
void east(){
buf = dice[0];
dice[0] = dice[3];
dice[3] = dice[5];
dice[5] = dice[2];
dice[2] = buf;
}
void west(){
buf = dice[0];
dice[0] = dice[2];
dice[2] = dice[5];
dice[5] = dice[3];
dice[3] = buf;
}
void rotate_R(){
buf = dice[4];
dice[4] = dice[2];
dice[2] = dice[1];
dice[1] = dice[3];
dice[3] = buf;
}
};
int main(){
int num;
int upper, front;
string::iterator itr;
Dice d;
for(int i=0; i<6; i++){
cin >> d.dice[i];
}
cin >> num;
for(int i=0; i<num; i++){
cin >> upper >> front;
for(int j=0; j<6; j++){
if(d.dice[j] == upper){
if(j == 0) break;
if(j == 1) d.north();
if(j == 2) d.west();
if(j == 3) d.east();
if(j == 4) d.south();
if(j == 5){
d.north();
d.north();
}
}
}
while(1){
if(front == d.dice[1]){
break;
}
d.rotate_R();
}
cout << d.dice[2] << endl;
}
return 0;
}
| 0 | 20,969,534 |
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define Rep(i,s,f) for(int i=(int)s;i<(int)f;i++)
#define INF 1e6
using ll=long long;
using namespace std;
vector<int> cost;
void bfs(vector<vector<int>> g)
{
cost[0]=0;
queue<int> que;
que.push(0);
while(!que.empty())
{
int p=que.front();que.pop();
for(int v : g[p])
{
if(cost[v]!=INF) continue;
cost[v]=cost[p]+1;
que.push(v);
}
}
}
int main()
{
int N,M;
cin>>N>>M;
vector<vector<int>> g(N,vector<int>());
rep(i,M)
{
int a,b;
cin>>a>>b;
a--;
b--;
g[a].push_back(b);
g[b].push_back(a);
}
cost.resize(N,INF);
bfs(g);
if(cost[N-1]==2)
{
cout<<"POSSIBLE"<<endl;
}
else
{
cout<<"IMPOSSIBLE"<<endl;
}
return 0;
}
|
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <ctime>
#include <list>
#include <numeric>
#include <utility>
#include <ctime>
#define INF 100000000
#define LINF 9000000000000000000
#define mod 1000000007
#define rep(i,n) for(int i=0;i<int(n);i++)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;
int a,b;
int dp[20][20];
bool no[20][20];
void init(){
rep(i,20){
rep(j,20){
dp[i][j]=no[i][j]=0;
}
}
}
void DP(){
REP(i,1,a+1){
REP(j,1,b+1){
if(no[i][j])dp[i][j]=0;
else if(i==1&&j==1)dp[i][j]=1;
else dp[i][j]=dp[i-1][j]+dp[i][j-1];
}
}
}
int main(){
int n,x,y;
while(1){
scanf("%d%d",&a,&b);
if(a==0&&b==0)break;
init();
cin>>n;
rep(i,n){
scanf("%d%d",&x,&y);
no[x][y]=true;
}
DP();
cout<<dp[a][b]<<endl;
}
return 0;
}
| 0 | 55,618,548 |
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define rrep(i,n) for(int i=n-1; i>=0; i--)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef long double lb;
const int INF=1<<27;
const int MOD=(int)1e9+7;
int parent[100010];
int depth[100010];
int find_root(int x)
{
if(parent[x] == x) return x;
else return find_root(parent[x]);
}
void unite(int x, int y)
{
int x_root = find_root(x);
int y_root = find_root(y);
if(depth[x_root] < depth[y_root]){
parent[x_root] = y_root;
depth[y_root] = max(depth[y_root], depth[x_root]+1);
}else{
parent[y_root] = x_root;
depth[x_root] = max(depth[y_root]+1, depth[x_root]);
}
return;
}
int same(int x, int y)
{
if(find_root(x) == find_root(y)) return 1;
else return 0;
}
int main(void)
{
int n, q;
cin >> n >> q;
int query, x, y;
rep(i,n){
parent[i] = i;
depth[i] = 0;
}
rep(i,q) {
cin >> query >> x >> y;
if(query == 0) unite(x, y);
else if(query == 1) cout << same(x, y) << endl;
}
return 0;
}
|
#include <cstdio>
#include <iostream>
using namespace std;
struct card {
char c;
int v;
};
void BubbleSort(card A[], int n) {
for (int i = 0; i < n; ++i) {
for (int j = n - 1; j > i; --j) {
if (A[j - 1].v > A[j].v)
swap(A[j - 1], A[j]);
}
}
}
void SelectionSort(card A[], int n) {
for (int i = 0; i < n; ++i) {
int minIdx = i;
int minv = A[i].v;
for (int j = i + 1; j < n; ++j) {
if (A[j].v < minv) {
minv = A[j].v;
minIdx = j;
}
}
swap(A[i], A[minIdx]);
}
}
int main() {
int n;
scanf("%d", &n);
card A[n];
for (int i = 0; i < n; ++i) {
char c;
int v;
cin >> c >> v;
card cd;
cd.c = c;
cd.v = v;
A[i] = cd;
}
card B[n];
for (int i = 0; i < n; ++i) {
B[i] = A[i];
}
BubbleSort(A, n);
for (int i = 0; i < n; ++i) {
if (i != 0)
cout << " " << A[i].c << A[i].v;
else
cout << A[i].c << A[i].v;
}
cout << endl << "Stable" << endl;
SelectionSort(B, n);
for (int i = 0; i < n; ++i) {
if (i != 0)
cout << " " << B[i].c << B[i].v;
else
cout << B[i].c << B[i].v;
}
cout << endl;
bool stable = true;
for (int i = 0; i < n; ++i) {
if (A[i].c != B[i].c || A[i].v != B[i].v) {
cout << "Not stable" << endl;
stable = false;
break;
}
}
if (stable)
cout << "Stable" << endl;
return 0;
}
| 0 | 12,311,743 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<long long> vll;
typedef vector<int> vi;
#define io ios_base::sync_with_stdio(false)
#define pb push_back
#define eb emplace_back
#define mod 1000000007
#define PI 2*acos(0.0)
#define all(r)(r).begin(),(r).end()
#define dbg(a) cout<<#a<<" ->->->-> "<<a<<"\n"
#define inf 1000000000000000000
#define N 20000
int dirx[] = {1, -1,0, 0}, diry[] = {0, 0, 1, -1};
int32_t main()
{
io;
ll n, k;
cin>>n>>k;
vll inp(n);
for(auto& x: inp) cin>>x;
if(k >= n)
return cout<<0, 0;
sort(all(inp));
ll ans = 0;
for(int i= 0; i< n-k; i++)
ans += inp[i];
cout<<ans;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define rrep(i,n) for(int i=int(n-1);i>=0;i--)
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7
using ll = long long;
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;
ll const mod=998244353;
const ll MAX=300000;
using vi=vector<int>;
using vc=vector<char>;
using vd=vector<double>;
using vs=vector<string>;
using vp=vector<P>;
using vb=vector<bool>;
using vvi =vector<vector<int>>;
using vvd=vector<vector<double>>;
using vvc=vector<vector<char>>;
using vvp =vector<vector<P>>;
using vvb=vector<vector<bool>>;
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
int main(){
int n,b;
cin>>n;
vi a(n);
rep(i,n){
cin>>a[i];
a[i]-=(i+1);
}
sort(all(a));
b=a[n/2];
ll sum=0;
rep(i,n){
sum+=abs(a[i]-b);
}
cout<<sum<<endl;
return 0;
}
| 0 | 19,412,643 |
#include <bits/stdc++.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;
typedef vector < vector<ll> > Mat;
#define fi first
#define se second
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);
void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}
int N, M;
vector <int> Graph[int(2e5+5)];
int Group[int(2e5+5)];
int cnt[int(2e5+5)];
int DFS(int num){
Group[num] = num;
queue <int> que; que.push(num);
while (!que.empty()){
int Q = que.front(); que.pop();
for (int j : Graph[Q]){
if (Group[j] != 0) continue;
Group[j] = num;
que.push(j);
}
}
return 0;
}
int main(){
cin >> N >> M;
for (int i = 0; i < M; i++){
int A, B; cin >> A >> B;
Graph[A].push_back(B);
Graph[B].push_back(A);
}
for (int i = 1; i <= N; i++){
if (Group[i] != 0) continue;
DFS(i);
}
for (int i = 1; i <= N; i++){
cnt[Group[i]]++;
}
sort(cnt + 1, cnt + N + 1, greater<int>());
cout << cnt[1] << endl;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<n;i++)
int main(){
string s; cin>>s;
if(sz(s)<4) cout<<"No";
else{
string t="";
rep(i,4){
t+=s[i];
}
if(t=="YAKI") cout<<"Yes";
else cout<<"No";
}
}
| 0 | 100,449,528 |
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define FOR(i, a, b) for (int i = a; i <= (b); i++)
#define ROF(i, a, b) for (int i = a; i >= (b); i--)
using pii = pair<int, int>; using vpii = vector<pii>;
using vi = vector<int>; using vvi = vector<vi>;
using ll = long long;
using pll = pair<ll, ll>; using vpll = vector<pll>;
using vll = vector<ll>; using vvll = vector<vll>;
int main() {
int n; cin >> n;
int x = 0, y = 0;
vi t(n + 1);
FOR(i, 1, n) {
int tx, ty; cin >> t[i] >> tx >> ty;
int d = abs(x - tx) + abs(y - ty), dt = t[i] - t[i - 1];
if (d > dt || abs(dt - d) % 2 == 1)
return cout << "No\n", 0;
x = tx, y = ty;
}
cout << "Yes\n";
}
|
#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;
int main(){
int n;
cin >> n;
string s1, s2;
for(int i=0; i<n; i++){
cin >> s1 >> s2;
int num = 1;
int i1 = 0;
int i2 = 0;
for(unsigned int j=0; j<s1.length(); j++){
if(isdigit(s1[j])){
num = atoi(&s1[j]);
}else{
if(s1[j] == 'm'){
i1 += num*1000;
}else if(s1[j] == 'c'){
i1 += num*100;
}else if(s1[j] == 'x'){
i1 += num*10;
}else if(s1[j] == 'i'){
i1 += num;
}
num = 1;
}
}
num = 1;
for(unsigned int j=0; j<s2.length(); j++){
if(isdigit(s2[j])){
num = atoi(&s2[j]);
}else{
if(s2[j] == 'm'){
i2 += num*1000;
}else if(s2[j] == 'c'){
i2 += num*100;
}else if(s2[j] == 'x'){
i2 += num*10;
}else if(s2[j] == 'i'){
i2 += num;
}
num = 1;
}
}
num = i1 + i2;
int m[4] = {0};
if(num/1000 > 0){
m[0] = num/1000;
num %= 1000;
}
if(num/100 > 0){
m[1] = num/100;
num %= 100;
}
if(num/10 > 0){
m[2] = num/10;
num %= 10;
}
if(num > 0){
m[3] = num;
}
string aaa[4] = {"m", "c", "x", "i"};
for(int j=0; j<4; j++){
if(m[j] > 1){
cout << m[j];
}
if(m[j] > 0){
cout << aaa[j];
}
}
cout << endl;
}
return 0;
}
| 0 | 49,643,973 |
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
void solve(){
int a,b;
cin>>a>>b;
if(a%3==0||b%3==0||(a+b)%3==0){
cout<<"Possible"<<endl;
}else{
cout<<"Impossible"<<endl;
}
}
signed main(){
solve();
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e9;
int main(){
ll x, y; cin >> x >> y;
ll ans = 0;
if(x == 0 || y == 0){
if(x == 0 && y == 0) {cout << 0 << endl; return 0;}
if(x == 0){
if(y < 0) {cout << abs(y) + 1 << endl; return 0;}
else if(y > 0) {cout << y << endl;return 0;}
}
else if(y == 0){
if(x < 0) {cout << -x << endl; return 0;}
else if(x > 0) {cout << abs(x) + 1 << endl;return 0;}
}
}
if(x < y){
if(0 < x) ans = y-x;
else if(x < 0 && 0 < y){
if(abs(x) <= abs(y)) ans = 1+abs(abs(x)-abs(y));
else ans = abs(abs(x)-abs(y))+1;
}
else if(y < 0) ans = abs(abs(x)-abs(y));
}
else if(y < x){
if(0 < y) {
ans = abs(x-y) + 2;
}
else if(y < 0 && 0 < x) {
ans = 1+ abs(abs(y) - abs(x));
}
else if(x < 0) ans = 1 + abs(abs(y) - abs(x)) + 1;
}
cout << ans << endl;
}
| 0 | 63,207,315 |
#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>;
int main()
{
ll n,m,d;
cin >> n >> m >> d;
double x = (n-d)*(m-1);
if(d!=0){
x*=2;
}
double ans=x/(n*n);
cout << fixed << setprecision(10) << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
string V="Vacant",Ma="Male",Fe="Female";
int main(){
int N;cin >> N;
int U=0,L=N;
vector<int> T(N+1,0);
cout << 0 << endl;
string S;
cin >> S;
if(S==V){
return 0;
}else if(S==Ma){
T[0] = 1;
T[N] = 1;
}else{
T[0] = 2;
T[N] = 2;
}
while(true){
int M = (U+L)/2;
cout << M << endl;
cin >> S;
if(S==V){
return 0;
}else if(S==Ma){
T[M] = 1;
}else{
T[M] = 2;
}
if((T[U]==T[M]&&(M-U)%2==1)||(T[U]!=T[M]&&(M-U)%2==0)){
L=M;
}else{
U=M;
}
}
}
| 0 | 68,037,122 |
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll mod=1000000007;
ll gcd(ll a, ll b){
if(a%b == 0){
return b;
}else{
return gcd(b, a%b);
}
}
ll lcm(ll a,ll b){
return (a*b)/gcd(a,b);
}
int main(){
int N;
cin>>N;
map<int,int> m;
for(int n=1;n<=N;n++){
int p=n;
for(int i=2;i*i<=n;i++){
int count=0;
if(p%i!=0)continue;
while(p%i==0){
++count;
p/=i;
}
m[i]+=count;
}
if(p!=1)++m[p];
}
vector<int> vec(6,0);
for(map<int,int>::iterator itr=m.begin();itr!=m.end();++itr){
if(itr->second>=74){
++vec[0];
}else if(itr->second>=24){
++vec[1];
}else if(itr->second>=14){
++vec[2];
}else if(itr->second>=4){
++vec[3];
}else if(itr->second>=2){
++vec[4];
}else{
++vec[5];
}
}
int ans=(vec[0]+vec[1])*(vec[0]+vec[1]+vec[2]+vec[3]+vec[4]-1);
ans+=(vec[0]+vec[1]+vec[2])*(vec[0]+vec[1]+vec[2]+vec[3]-1);
ans+=(vec[0]+vec[1]+vec[2]+vec[3])*(vec[0]+vec[1]+vec[2]+vec[3]-1)/2*(vec[0]+vec[1]+vec[2]+vec[3]+vec[4]-2);
ans+=vec[0];
cout<<ans<<endl;
}
|
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
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; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;
const double PI = 3.1415926535897932;
const int MOD = 1e9 + 7;
int main() {
int n;
cin >> n;
vector<int> C(n - 1);
vector<int> S(n - 1);
vector<int> F(n - 1);
rep (i, n - 1) {
cin >> C[i] >> S[i] >> F[i];
}
for (int i = 0; i < n - 1; i++) {
ll ans = 0;
for (int j = i; j < n - 1; j++) {
if (j == i) {
ans += C[j] + S[j];
} else {
if (ans < S[j]) {
ans += S[j] - ans;
} else {
int tmp = ans % F[j];
if (tmp != 0) {
ans += F[j] - tmp;
}
}
ans += C[j];
}
}
cout << ans << endl;
}
cout << 0 << endl;
return 0;
}
| 0 | 50,266,754 |
#include <bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
#define MAXX 10005
#define PI 3.14159265358979323846264338327950
#define F first
#define S second
#define ll long long int
#define mod 1000000007
int main()
{
FAST;
ll n;
cin >> n;
cout << n * n;
return 0;
}
|
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug" << x << endl;
using namespace std;
int main(){
int n;
while(cin >> n){
int info[4][3][10] = {0};
rep(i,n){
int a, b, c, d;
cin >> a >> b >> c >> d;
a--; b--; c--;
info[a][b][c] += d;
}
rep(i,4){
rep(j,3){
rep(k,10){
cout << ' ' << info[i][j][k];
}
cout << endl;
}
if(i != 3){
rep(l,20) cout << '#';
cout << endl;
}
}
}
}
| 0 | 75,849,213 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.