code1
stringlengths 54
12k
| code2
stringlengths 65
12k
| similar
int64 0
1
| __index_level_0__
int64 1
101M
|
|---|---|---|---|
#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve() {
int a, b, c, d;
cin >> a >> b >> c >> d;
int result = max(a * c, max(a * d, max(b * c, b * d)));
cout << result;
}
signed main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int t = 1;
while (t--) {
solve();
}
return 0;
}
|
#include<iostream>
using namespace std;
int main() {
int a,b,c,min,mid,max;
cin >> a >> b >> c;
max = a;
if(max < b) {
max = b;
}
if(max < c) {
max = c;
}
min = a;
if(min > b) {
min = b;
}
if(min > c) {
min = c;
}
mid = a;
if((min == a || min == b) && (max == a || max == b)) {
mid = c;
}
if((min == b || min == c) && (max == b || max == c)) {
mid = a;
}
if((min == c || min == a) && (max == c || max == a)) {
mid = b;
}
cout << min << " " << mid << " " << max << endl;
return 0;
}
| 0
| 72,415,126
|
#define LOCAL
#undef _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define MOD 1000000007LL
#define LLINF 100000000000000005LL
#define INF (int)1e9+1
#define pb push_back
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 += "}\n";
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 += "}\n";
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)) + ")";
}
template <typename A, typename B, typename C, typename D, typename E>
string to_string(tuple<A, B, C, D, E> p) {
return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + "," + to_string(get<4>(p)) + ")";
}
void debug_out() {
cerr << endl;
}
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "\n[" << #__VA_ARGS__ << "]:\n", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
using llong = long long;
using PII = pair<int, int>;
using db = double;
int main() {
IOS;
int n, k; cin >> n >> k;
vector<int> h(n);
for (int i = 0; i < n; i++) cin >> h[i];
vector<int> dp(n);
for (int i = 1; i < n; i++) {
int mmin = INF;
for (int j = i - 1; j >= i - k && j >= 0; j--) {
mmin = min(dp[j] + abs(h[i]-h[j]), mmin);
}
dp[i] = mmin;
}
cout << dp[n - 1];
}
|
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string>
#include<tuple>
#include<vector>
#include<cstdlib>
#include<cstdint>
#include<stdio.h>
#include<cmath>
#include<limits>
#include<iomanip>
#include<ctime>
#include<climits>
#include<random>
#include<queue>
#include<map>
using namespace std;
template <class T> using V = vector<T>;
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
const long long INF = 1LL << 60;
const double pi=acos(-1);
using ll = long long;
using db = long double;
using st = string;
using ch = char;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
using graph = V<V<int>>;
using pq = priority_queue<ll>;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define pb(a) push_back(a);
#define ALL(a) (a).begin(),(a).end()
ll Sum(ll n) {
ll m=0;
while(n){
m+=n%10;
n/=10;
}
return m;
}
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void Comuse() {
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;
}
}
#define comuse Comuse()
ll combi(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;
}
ll perm(int n,int k){
if(n < k) return 0;
if(n < 0 || k < 0) return 0;
return fac[n] * (finv[k] % MOD) % MOD;
}
ll modpow(ll a,ll n,ll mod){
ll ans=1;
while(n>0){
if(n&1){
ans=ans*a%mod;
}
a=a*a%mod;
n>>=1;
}
return ans;
}
ll modinv(ll a, ll mod) {
return modpow(a, mod - 2, mod);
}
ll modcombi(int n,int k,int mod){
ll ans=1;
for(ll i=n;i>n-k;i--){
ans*=i;
ans%=mod;
}
for(ll i=1;i<=k;i++){
ans*=modinv(i,mod);
ans%=mod;
}
return ans;
}
ll lcm(ll a,ll b){
ll n;
n=a/gcd(a,b)*b;
return n;
}
vll div(ll n){
vll ret;
for(ll i=1;i*i<=n;i++){
if(n%i==0){
ret.push_back(i);
if(i*i!=n){
ret.push_back(n/i);
}
}
}
SORT(ret);
return (ret);
}
vector<bool> isprime(MAX+100,true);
void primeuse(){
isprime[0]=false;
isprime[1]=false;
for(int i=2;i<MAX+50;i++){
int up=sqrt(i)+1;
for(int j=2;j<up;j++){
if(i%j==0){
isprime[i]=false;
}
}
}
}
void bf(ll n,string s){
for(ll i=0;i<n;i++){
cout<<s;
}
cout<<"\n";
}
void Solve();
const int MAX_N = 131072;
int NN;
int seg[MAX_N*2-1];
void seguse(){
for(int i=0;i<2*NN-1;i++){
seg[i]=INT_MAX;
}
}
signed main(){
cin.tie(0);
ios::sync_with_stdio(false);
cout<<setprecision(20)<<fixed;
Solve();
}
void Solve(){
string s;
cin>>s;
ll n=s.size();
FOR(i,0,n-1){
if(s[i]==s[i+1]){
cout<<i+1<<" "<<i+2<<"\n";
return;
}
}
FOR(i,0,n-2){
if(s[i]==s[i+2]){
cout<<i+1<<" "<<i+3<<"\n";
return;
}
}
cout<<"-1 -1\n";
}
| 0
| 11,644,147
|
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define f first
#define s second
#define mp make_pair
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin>>n;
n *= 2;
int a[n];
for(int i =0;i <n ;i++)
{
cin>>a[i];
}
sort(a,a+n);
ll ans =0;
for(int i =0;i<n;i+=2)
ans +=a[i];
cout<<ans<<endl;
return 0;
}
|
#include <iostream>
#include <string>
#include <array>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <cctype>
#include <map>
#include <stdio.h>
#include <string.h>
#include <math.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define FOR(i,l,r) for(size_t i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
using namespace std;
bool is_integer( float x ){
return floor(x)==x;
}
int main() {
int a,b;
int flag = false;
vector<int> vc;
cin >> a >> b;
for(int i = a; i < 10000; i ++){
if((int)(i*0.08) == a) vc.push_back(i);
}
for(int i = 0; i < vc.size(); i ++){
if((int)(vc[i]*0.1) == b){
cout << vc[i];
flag = true;
break;
}
}
if(!flag) cout << -1;
return 0;
}
| 0
| 20,601,253
|
#include <cstdio>
int main(void) {
int score[2] = { 0 };
for(int i = 0; i < 2; i++) {
for(int j = 0; j < 4; j++) {
int buf;
scanf("%d", &buf);
score[i] += buf;
}
}
printf("%d\n", score[0] > score[1] ? score[0] : score[1]);
return 0;
}
|
#include <assert.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define rep(i, n) for (ll i = 0; i < n; i++)
#define debugA cerr << "AAAAA" << endl
#define debug_ cerr << "-------------" << endl
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v) \
cout << #v << endl; \
for (int i = 0; i < v.size(); i++) \
{ \
cout << v[i] << " "; \
} \
cout << endl;
#define debug_vec2(v) \
cout << #v << endl; \
for (int i = 0; i < v.size(); i++) \
{ \
for (int j = 0; j < v[i].size(); j++) \
{ \
cout << v[i][j] << " "; \
} \
cout << endl; \
}
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;
}
template <typename T>
void quit(T a)
{
cout << a << endl;
exit(0);
}
using Graph = vector<vector<int>>;
using P = pair<int, int>;
using P1 = pair<int, pair<int, int>>;
const ll LINF = 10010020030040056ll;
const int INF = 1001001001;
const double pi = acos(-1);
void solve()
{
int n;
cin >> n;
vector<int> h(n);
int ans = 0;
int tmp = 0;
cin >> h[0];
for (int i = 1; i < n; i++)
{
cin >> h[i];
if (h[i - 1] >= h[i])
{
tmp++;
}
else
{
tmp = 0;
}
chmax(ans, tmp);
}
cout << ans << endl;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(20);
solve();
return 0;
}
| 0
| 29,368,888
|
#include <bits/stdc++.h>
using namespace std;
int main()
{
long long int n,p;
cin>>n>>p;
cout<<(n+1)-p<<endl;
}
|
#include <bits/stdc++.h>
#include <type_traits>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))
using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vs = vector<string>;
using vvs = vector<vs>;
using ld = long double;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
os << "(" << p.first << "," << p.second << ")";
return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
os << "{";
rep(i, (int)v.size()) {
if (i)
os << ",";
os << v[i];
}
os << "}";
return os;
}
template <typename T, size_t S> void printArray(const T (&array)[S]) {
for (auto val : array)
std::cout << val << ", ";
std::cout << "\n";
}
const int mod = 1e9 + 7;
const int inf = 1e9 + 5;
int n, m;
vvi to, cost;
set<pi> walked;
void dfs(int cur, int g) {
rep(k, n) {
if (k == cur || to[cur][k]+cost[k][g] != cost[cur][g])
continue;
walked.insert({min(cur, k), max(cur, k)});
dfs(k, g);
}
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << std::setprecision(10);
std::cin >> n >> m;
to.resize(n, vi(n, inf));
rep(i, n) to[i][i] = 0;
rep(i, m) {
int a, b, c; std::cin >> a >> b >> c;
--a, --b;
to[a][b] = to[b][a] = c;
}
cost = to;
rep(k, n) rep(i, n) rep(j, n) chmin(cost[i][j], cost[i][k] + cost[k][j]);
rep(i, n) srep(j, i+1, n) {
dfs(i, j);
}
std::cout << m-(int)walked.size() << "\n";
}
| 0
| 92,389,922
|
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using vi = vector<int64_t>;
using vvi = vector<vi>;
using ll = int64_t;
using P = pair<ll,ll>;
int64_t INF = 1000000007;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll n;
cin >> n;
vector<string> s(n);
rep(i,n) cin >> s.at(i);
vvi a(26,vector<ll>(s.size()));
rep(i,n) sort(s.begin(), s.end());
rep(i,26){
char c = 'a'+i;
rep(j,s.size()){
rep(k,s.at(j).size()){
if(s.at(j).at(k)==c) a.at(i).at(j)++;
}
}
}
string res = "";
rep(i,26){
vi b = a.at(i);
sort(a.at(i).begin(), a.at(i).end());
rep(j,a.at(i).at(0)){
res += 'a' + i;
}
}
cout << res << endl;
}
|
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
string a = "AtCoder Beginner Contest ";
string b = "AtCoder Regular Contest";
int s1 = a.size();
int s2 = b.size();
a[0] = toupper(a[0]);
b[0] = toupper(b[0]);
int x;
cin >> x;
if(x<1200)
{
for(int i =0; i<s1; i++)
{
if(a[i-1] == ' ')
a[i] = toupper (a[i]);
}
cout << "ABC" <<endl;
}
else if(x>=1200)
{
for(int j =0; j<s2; j++)
{
if(b[j-1] == ' ')
b[j] = toupper (b[j]);
}
cout << "ARC" <<endl;
}
return 0;
}
| 0
| 16,897,934
|
# include <bits/stdc++.h>
# define sz(x) (int)((x).size())
# define F first
# define S second
# define pb push_back
# define ub upper_bound
# define lb lower_bound
# define all(x) x.begin(), x.end()
# define pqueue priority_queue
# define mset multiset
# define umap unordered_map
# define Speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
# define rep(i,n) for(int i=0;i<n;++i)
# define forn(i,n) for(int i=1;i<=n;++i)
# define lr(i,l,r) for(int i=l;(l>r?i>=r:i<=r);(l>r?--i:++i))
using namespace std;
template<class T> void umin(T &a, T b) { a = min(a, b); }
template<class T> void umax(T &a, T b) { a = max(a, b); }
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1e9+7;
const int N = 1e5+5;
int n,m;
ll ans;
void solve(){
cin>>n>>m;
vector<pii>v;
forn(i,n){
int x,y;
cin>>x>>y;
v.pb({x,y});
}
sort(all(v));
rep(i,n){
if(!m)break;
if(m-v[i].S>=0){
m-=v[i].S;
ans+=v[i].S*1LL*v[i].F;
}
else{
ans+=v[i].F*1LL*m;
m=0;
}
}
cout<<ans;
}
int main(){
Speed();
int T=1;
while(T--)
solve();
return 0;
}
|
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;
using ll = long long;
class Stream{
public:
Stream(){
}
void read(){
}
template<typename First, typename... Rest>
void read(First& first, Rest&... rest){
cin >> first;
read(rest...);
}
template<typename T>
void write_vec(vector<T>& v, char divider){
for(size_t i = 0; i < v.size(); i++){
cout << v[i] << divider;
}
}
};
struct UF{
const int node_num;
vector<int> parent;
vector<int> size;
UF(int N) : node_num(N), parent(N), size(N, 1) {
for(int i = 0; i < N; ++i) parent[i] = i;
}
int root(int x){
if(parent[x] == x) return x;
return parent[x] = root(parent[x]);
}
void unite(int x, int y){
int root_x = root(x);
int root_y = root(y);
if(root_x == root_y) return;
parent[root_y] = root_x;
size[root_x] += size[root_y];
}
bool same(int x, int y){
int root_x = root(x);
int root_y = root(y);
return root_x == root_y;
}
int same_size(int x){
int root_x = root(x);
return size[root_x];
}
};
int main(){
Stream io;
int N, M;
io.read(N, M);
vector<int> P(M);
vector<int> Y(M);
for(int i = 0; i < M; i++){
io.read(P[i], Y[i]);
}
vector<vector<int>> v(N);
for(int i = 0; i < M; i++){
v[P[i] - 1].push_back(Y[i]);
}
for(int i = 0; i < N; i++){
sort(v[i].begin(), v[i].end());
}
for(int i = 0; i < M; i++){
auto p = lower_bound(v[P[i] - 1].begin(), v[P[i] - 1].end(), Y[i]);
int x = p - v[P[i] - 1].begin() + 1;
cout << setw(6) << setfill('0') << P[i];
cout << setw(6) << setfill('0') << x << '\n';
}
return 0;
}
| 0
| 85,108,597
|
#include <bits/stdc++.h>
using namespace std;
#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl
typedef long long ll;
int main()
{
int n;
int a[101010];
int dp[101010];
memset(a, 0, sizeof(a));
scanf("%d", &n);
fill_n(dp, n, 1e9+1);
REP(i, n) {
scanf("%d", &a[i]);
}
REP(i, n) {
*lower_bound(dp, dp+n, a[i]) = a[i];
}
printf("%d\n", distance(dp, lower_bound(dp, dp + n, 1e9+1)));
return 0;
}
|
#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;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
int main(){
int n;
int a, b;
cin >> n >> a >> b;
int p = 0, q = 0, r = 0;
rep(i, n){
int x;
cin >> x;
if (x <= a) p++;
else if (x <= b) q++;
else r++;
}
cout << min({p, q, r}) << endl;
return 0;
}
| 0
| 24,122,945
|
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<string>
#define mx_ari(a) *max_element(a , a+sizeof(a)/4)
#define mn_ari(a) *min_element(a , a+sizeof(a)/4)
#define mx_arl(a) *max_element(a , a+sizeof(a)/8)
#define mn_arl(a) *min_element(a , a+sizeof(a)/8)
#define mx_vec(v) *max_element(v.begin() , v.end())
#define mn_vec(v) *min_element(v.begin() , v.end())
#define cnt_ari(a,b) count(a , a+sizeof(a)/4 , b)
#define cnt_arl(a,b) count(a , a+sizeof(a)/8 , b)
#define cnt_vec(v,b) count(v.begin() , v.end() , b)
#define sci(a) scanf("%d",&a)
#define scii(a,b) scanf("%d %d",&a,&b)
#define sciii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define scl(a) scanf("%lld",&a)
#define scll(a,b) scanf("%lld %lld",&a,&b)
#define sclll(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define scf(a) scanf("%f",&a)
#define scff(a,b) scanf("%f %f",&a,&b)
#define scfff(a,b,c) scanf("%f %f %f",&a,&b,&c)
#define scd(a) scanf("%ld",&a)
#define scdd(a,b) scanf("%lf %lf",&a,&b)
#define scddd(a,b,c) scanf("%lf %lf %lf",&a,&b,&c)
#define pri(a) printf("%d ",a)
#define prii(a,b) printf("%d %d ",a,b)
#define priii(a,b,c) printf("%d %d %d ",a,b,c)
#define prl(a) printf("%lld ",a)
#define prll(a,b) printf("%lld %lld ",a,b)
#define prlll(a,b,c) printf("%lld %lld %lld ",a,b,c)
#define prd(a) printf("%.4lf ",a)
#define prdd(a,b) printf("%.4lf %.4lf ",a,b)
#define prddd(a,b,c) printf("%.4lf %.4lf %.4lf ",a,b,c)
#define prf(a) printf("%.4f ",a)
#define prff(a,b) printf("%.4f %.4f ",a,b)
#define prfff(a,b,c) printf("%.4f %.4f %.4f ",a,b,c)
#define foi(i,n) for(int i=0;i<n;i++)
#define fol(i,n) for(long long int i=0;i<n;i++)
#define fod(i,n) for(double i=0;i<n;i++)
#define fof(i,n) for(float i=0;i<n;i++)
#define nwl << "\n"
#define nl printf("\n");
#define mp make_pair
#define pb emplace_back
#define ll long long
#define ull unsigned long long int
#define mod 1000000007
#define lcm(a,b) (a*b) / __gcd(a,b)
using namespace std;
int cost[100010];
int chi(int i , int n , int a[]){
if(i < 0){
return cost[0];
}
cost[i] = min(abs(a[i] - a[i+1])+cost[i+1] , abs(a[i] - a[i+2])+cost[i+2]);
return chi(i-1 , n , a);
}
int main()
{
int n;
cin >> n;
int a[n];
foi(i,n){
cin >> a[i];
}
cost[n-1] = 0;
cost[n-2] = abs(a[n-1] - a[n-2]);
cout << chi(n-3 , n , a);
return 0;
}
|
#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
| 91,341,739
|
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vl = vector<ll>;
using vi = vector<int>;
using Graph = vector<vi>;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
string s;
cin >> s;
for (auto c : s) {
if (c == '1')
cout << '9';
else
cout << 1;
}
cout << endl;
}
|
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;
int main() {
int A[3][3];
vector<vector<bool>> field(3, vector<bool>(3));
int n;
REP(i, 3){
REP(j, 3){
cin >> A[i][j];
}
}
cin >> n;
int b[n];
map<int, int> mp;
REP(i, n){
cin >> b[i];
mp[b[i]] = 1;
}
REP(i, 3){
REP(j, 3){
if(mp[A[i][j]] != 0){
field[i][j] = true;
}
}
}
bool flag = false;
if(field[0][0] == true && field[1][1] == true && field[2][2] == true){
flag = true;
}
if(field[0][2] == true && field[1][1] == true && field[2][0] == true){
flag = true;
}
REP(i, 3){
if(field[i][0] == true && field[i][1] == true && field[i][2] == true){
flag = true;
}
if(field[0][i] == true && field[1][i] == true && field[2][i] == true){
flag = true;
}
}
if (flag) cout << "Yes" << endl;
else cout << "No" << endl;
}
| 0
| 43,443,546
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;
int main(){
ll N;
cin >> N;
vector<ll> A(N);
rep(i,N){
cin >> A[i];
}
ll ans = 0;
rep(i,60){
ll x = 0;
rep(j,N){
if(((A[j] >> i)&1LL)) x++;
}
ll now = x*(N-x)%mo;
rep(j,i){
now *= 2;
now %= mo;
}
ans += now;
ans %= mo;
}
cout << ans << endl;
}
|
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define N 1000000007
#define N2 998244353
#define Nmax 100001
#define INF (ll)1e18
#define pll pair<ll,ll>
#define pii pair<ll,ll>
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(ll i=m;i<(n);i++)
#define get(n) ll (n); scanf("%lld",&(n));
#define get2(n,k) ll (n),(k); scanf("%lld%lld",&(n),&(k));
#define get3(n,m,k) ll (n),(m),(k); scanf("%lld%lld%lld",&(n),&(m),&(k));
#define gets(s) string (s); cin >> (s);
#define ALL(c) (c).begin(),(c).end()
#define fill_nums(A,n) vector<ll> A((n)); for(ll i=0;i<n;i++) scanf("%lld",&A[i]);
#define fill_edges(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1); adj[b-1].pb(a-1);}
#define fill_direct(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1);}
#define pi 3.1415926535897
int main() {
get2(n,k);
fill_nums(A,n);
if(k>=n) {
printf("0\n");
return 0;
}
vector<vector<ll>> dp(n-k+1, vector<ll>(n+1,INF));
dp[0][0] = 0;
for(int i=1;i<=n-k;i++) {
for(int j=1;j<=n;j++) {
for(int k=0;k<j;k++) {
dp[i][j] = min(dp[i][j], dp[i-1][k] + max((ll)0, (A[j-1]-(k-1>=0 ? A[k-1] : 0))));
}
}
}
ll res = INF;
for(int j=1;j<=n;j++)
res = min(res, dp[n-k][j]);
printf("%lld\n", res);
return 0;
}
| 0
| 70,705,275
|
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main() {
int n;
cin >> n;
string s, t;
cin >> s >> t;
bool flag = true;
int c = 0;
for (int i = 0; i < int(s.size()); ++i) {
flag = true;
c = 0;
for (int j = 0;; ++j) {
if (s[i + j] != t[j]) {
flag = false;
break;
}
++c;
if (i + j == int(s.size()) - 1) {
break;
} else if (j == int(t.size()) - 1) {
flag = false;
break;
}
}
if (flag)
break;
}
cout << max(int(s.size() + t.size()) - c, n) << endl;
}
|
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
int n;
cin >> n;
vector<int> p(n), idx(n);
rep(i, n) {
cin >> p[i];
p[i]--;
idx[p[i]] = i;
}
set<int> st;
ll ans = 0;
for (int i = n-1; i >= 0; --i) {
int id = idx[i];
st.insert(id);
int l1, l2, r1, r2;
l1 = l2 = -1;
r1 = r2 = n;
auto it_l = st.find(id);
auto it_r = st.find(id);
if (it_l != st.begin()) {
it_l--;
l1 = *it_l;
if (it_l != st.begin()) {
it_l--;
l2 = *it_l;
}
}
it_r++;
if (it_r != st.end()) {
r1 = *it_r;
it_r++;
if (it_r != st.end()) {
r2 = *it_r;
}
}
if (ll(id-l1) * (r2-r1) + ll(l1-l2) * (r1-id) < 0) {
cout << id << endl;
cout << l1 << endl;
cout << l2 << endl;
cout << r1 << endl;
cout << r2 << endl;
cout << "OK" << endl;
}
ans += (ll(id-l1) * (r2-r1) + ll(l1-l2) * (r1-id)) * (i+1);
}
cout << ans << endl;
return 0;
}
| 0
| 41,405,588
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define all(v) begin(v),end(v)
using ll = long long;
int main() {
string s;cin>>s;
while(1){
s.pop_back();
int n=s.size();
if(s.substr(0,n/2)==s.substr(n/2)){
cout<<n<<endl;
return 0;
}
}
}
|
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,N-1,0)
#define RREPS(i,n) RFOR(i,N,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
const int INF=1e18;
const int MOD=1e9+7;
signed main(){
int N;string S;cin>>N>>S;
int ans=1;
for(char c='a';c<='z';c++){
int k=1;
REP(i,S.size()){
if(S[i]==c)k++;
}
ans*=k;
ans%=MOD;
}
ans--;
while(ans<0)ans+=MOD;
cout<<ans<<endl;
}
| 0
| 89,241,060
|
#include <bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define e "\n"
#define MaRiaMa { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); }
#define fix(n) cout << fixed << setprecision(n);
using namespace std;
int main()
{
MaRiaMa;
int a, b, c;
cin >> a >> b >> c;
multiset<int> p;
p.insert(a); p.insert(b); p.insert(c);
int n= max({ p.count(a), p.count(b), p.count(c) });
if (n == 1)
cout << "3";
else if (n == 3)
cout << "1";
else
cout << n;
}
|
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<bits/stdc++.h>
using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pcc pair<char,char>
#define F first
#define S second
#define int long long
#define pi 3.141592653589793238462643383279502
#define M 1000000007
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 10000000000000
#define N 100005
#define vi vector<int>
#define all(v) v.begin(),v.end()
signed main()
{
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int n;
cin>>n;
int a[n];
int tot=0;
rep(i,0,n){cin>>a[i];tot+=a[i];}
int mn=1e9;
for(int i=0;i<n;i++)
{ int sum=0;
for(int j=0;j<i;j++)
{
sum+=a[j];
}
mn=min(mn,abs(tot-2*sum));
}
cout<<mn<<endl;
}
| 0
| 75,315,042
|
#include<bits/stdc++.h>
using namespace std;
int main(){
int A = 0, B = 0;
char c;
cin >> A >> c >> B;
if(c == '+'){
cout << A + B << endl;
}
if(c == '-'){
cout << A - B << endl;
}
}
|
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i,a,n) for(ll i=a;i<(ll)(n);i++)
int main(){
int s;
cin>>s;
vector<bool> check(1000000, false);
int a = s;
check[a-1] = true;
for(int i=2;;i++){
if(a%2 == 0) a = a/2;
else a = 3*a+1;
if(check[a-1]){
cout << i << endl;
return 0;
}
check[a-1] = true;
}
}
| 0
| 62,094,423
|
#include<bits/stdc++.h>
#define PI 3.141592653589
#define ll long long
using namespace std;
template<typename T_char>
T_char ToUpper(T_char cX){return toupper(cX);}
int main(){
ll h, w;
cin >> h >> w;
if(h==1 || w==1){
cout << 1 << endl;
return 0;
}
ll masu = h*w;
ll res = masu / 2;
cout << masu - res << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve(long long N, long long K, std::vector<long long> a) {
sort(a.begin(), a.end());
reverse(a.begin(), a.end());
ll sum = 0;
ll res = N;
for (int i = 0; i < N; i++) {
if (sum + a[i] < K) {
sum += a[i];
} else {
res = min(res, N - i - 1);
}
}
cout << res << endl;
}
int main() {
long long N;
scanf("%lld", &N);
long long K;
scanf("%lld", &K);
std::vector<long long> a(N);
for (int i = 0; i < N; i++) {
scanf("%lld", &a[i]);
}
solve(N, K, std::move(a));
return 0;
}
| 0
| 323,489
|
#include <bits/stdc++.h>
using namespace std;
int main(){
string S;
cin>>S;
map<char,int>mp;
vector<int>A(0);
for(int X=0;X<S.size();X++){
mp[S[X]]++;
}
for(auto p:mp){
auto V=p.second;
A.push_back(V);
}
if(A.size()==2&&A[0]==2&&A[1]==2){
cout<<"Yes"<<endl;
}
else{
cout<<"No"<<endl;
}
}
|
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);
int main() {
string s;
cin >> s;
int n = s.size();
vector<int> ans(n+1, 0);
int cntR = 0, cntL = 0;
for(int i = 0; i < n; i++) {
if (s[i] == '<') cntR++;
else cntR = 0;
ans[i+1] = cntR;
}
for(int i = n-1; i >= 0; i--) {
if (s[i] == '>') cntL++;
else cntL = 0;
ans[i] = max(cntL, ans[i]);
}
ll sum = 0;
for(int i = 0; i <= n; i++) {
sum += ans[i];
}
cout << sum << endl;
return 0;
}
| 0
| 95,124,066
|
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)
int main(){
int n;
cin >> n;
int p = -1;
int s = 0;
for(int i=1;i<=1000;i++){
s +=i;
if(s==n){
p = i;
break;
}
}
if(p==-1){
cout << "No" << endl;
}else{
cout << "Yes" << endl;
cout << p+1 << endl;
cout << p << " ";
for(int j=1;j<=p;j++){
cout << j;
if(j!=p){
cout << " ";
}
}
cout << endl;
for(int i=1;i<=p;i++){
cout << p << " ";
int zz = 0;
for(int j=0;j<p;j++){
if(j==0){
cout << i;
zz = i;
}else{
if(j<=i){
if(j==i){
zz += p-j+1;
}else{
zz += p-j;
}
cout << zz;
}else{
zz++;
cout << zz;
}
}
if(j!=p-1)cout << " ";
}
cout << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
#define rep_override(x, y, z, name, ...) name
#define rep2(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep3(i, l, r) for (int i = (int)(l); i < (int)(r); ++i)
#define rep(...) rep_override(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define per(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003;
template <typename T> inline bool chmin(T& x, const T& y) {if (x > y) {x = y; return 1;} return 0;}
template <typename T> inline bool chmax(T& x, const T& y) {if (x < y) {x = y; return 1;} return 0;}
struct IOSET {IOSET() {cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10);}} ioset;
int main() {
int n, m;
cin >> n >> m;
vector<vector<int>> g(n, vector<int>(n, inf));
rep(i, m) {
int a, b, c;
cin >> a >> b >> c;
--a; --b;
g[a][b] = c; g[b][a] = c;
}
rep(i, n) g[i][i] = 0;
vector<vector<int>> dist = g;
rep(k, n) rep(i, n) rep(j, n) chmin(dist[i][j], dist[i][k] + dist[k][j]);
int ans = m;
rep(i, n) rep(j, i + 1, n) {
if (g[i][j] == inf) continue;
rep(x, n) rep(y, n) {
if (dist[x][i] + g[i][j] + dist[j][y] == dist[x][y]) {
--ans;
goto ioi;
}
}
ioi:;
}
cout << ans << "\n";
}
| 0
| 98,805,061
|
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <cassert>
#include <fstream>
#include <iomanip>
#include <stack>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 1e9 + 7;
const ll mmod = 998244353;
vector<ll> dx = {1, -1, 0, 0};
vector<ll> dy = {0, 0, 1, -1};
vector<string> g;
vector<vector<bool>> used;
vector<ll> d;
int main() {
ifstream in("input.txt");
cin.rdbuf(in.rdbuf());
cin.tie(0);
ios_base::sync_with_stdio(0);
ll n;
cin >> n;
ll ret = 0;
for (ll i = 1; i <= n; ++i)
{
ll c = n / i;
ret += ((i + i * c) * c) / 2ll;
}
cout << ret << endl;
return 0;
}
|
#include <iostream>
int main() {
int N, A;
std::cin >> N >> A;
if (N % 500 > A) {
std::cout << "No" << std::endl;
}
else if (N % 500 <= A) {
std::cout << "Yes" << std::endl;
}
}
| 0
| 6,520,163
|
#include <iostream>
using namespace std;
#define INPUT_MIN 0
#define INPUT_MAX 100
int main()
{
int a = 0, b = 0, c = 0;
cin >> a;
cin >> b;
cin >> c;
if( (INPUT_MIN > a) || (INPUT_MAX < a) )
{
return 1;
}
if( (INPUT_MIN > b) || (INPUT_MAX < b) )
{
return 1;
}
if( (INPUT_MIN > c) || (INPUT_MAX < c) )
{
return 1;
}
if(a >= c)
{
cout << "No" << endl;
}
else if( (a >= b) || (c <= b) )
{
cout << "No" << endl;
}
else
{
cout << "Yes" << endl;
}
return 0;
}
|
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <cmath>
#include <stack>
#include <map>
#include <iomanip>
using namespace std;
int64_t min(int64_t a,int64_t b) {
if (a > b)
{
return b ;
}else
{
return a ;
}
}
const int MAX = 510000;
const int MOD = 1000000007;
int64_t 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(){
int n,d,x ;
cin >> n >> d >> x ;
int a ;
int ans = n + x ;
for (int i = 0; i < n; i++)
{
cin >> a ;
ans += (d-1)/a ;
}
cout << ans << endl ;
}
| 0
| 83,535,375
|
#include <iostream>
using namespace std;
int main() {
int a , b , x;
cin >> a >> b >> x;
if ( a > x ) cout << "NO";
else if ( a == x ) cout << "YES";
else if ( a < x && a + b >= x ) cout << "YES";
else if ( a < x && a + b < x ) cout << "NO";
return 0;
}
|
const int LG = 21;
const int FN = 400005;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
const long long INFLL = 1e18;
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <time.h>
#include <unordered_set>
#include <bitset>
#include <deque>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vi;
#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return
#define uniq(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin())
#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif
int cx[4] = {-1, 0, 1, 0};
int cy[4] = {0, -1, 0, 1};
ll inq(ll x, ll y)
{
if (!y) re 1 % MOD;
ll l = inq(x, y / 2);
if (y % 2) re l * l % MOD * x % MOD;
re l * l % MOD;
}
ll rev(ll x)
{
return inq(x, MOD - 2);
}
bool __precomputed_combinatorics = 0;
vector<ll> __fact, __ufact, __rev;
void __precompute_combinatorics()
{
__precomputed_combinatorics = 1;
__fact.resize(FN);
__ufact.resize(FN);
__rev.resize(FN);
__rev[1] = 1;
for (int i = 2; i < FN; i++) __rev[i] = MOD - __rev[MOD % i] * (MOD / i) % MOD;
__fact[0] = 1, __ufact[0] = 1;
for (int i = 1; i < FN; i++) __fact[i] = __fact[i - 1] * i % MOD, __ufact[i] = __ufact[i - 1] * __rev[i] % MOD;
}
ll fact(int x)
{
if (!__precomputed_combinatorics) __precompute_combinatorics();
return __fact[x];
}
ll cnk(int n, int k)
{
if (!__precomputed_combinatorics) __precompute_combinatorics();
return __fact[n] * __ufact[n - k] % MOD * __ufact[k] % MOD;
}
const int N = 100500;
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
string S;
cin >> n >> S;
for (int a = 0; a < 2; a++)
{
for (int b = 0; b < 2; b++)
{
string s(n, ' ');
if (a == 0) s[0] = 'S'; else s[0] = 'W';
if (b == 0) s[1] = 'S'; else s[1] = 'W';
for (int i = 1; i + 1 < n; i++)
{
if ((s[i] == 'S' && S[i] == 'o') || (s[i] == 'W' && S[i] == 'x')) s[i + 1] = s[i - 1];
else s[i + 1] = 'S' + 'W' - s[i - 1];
}
int t = 1;
if ((s.back() == 'S' && S.back() == 'o') || (s.back() == 'W' && S.back() == 'x')) t &= (s[n - 2] == s[0]);
else t &= (s[n - 2] != s[0]);
if ((s[0] == 'S' && S[0] == 'o') || (s[0] == 'W' && S[0] == 'x')) t &= (s[1] == s.back());
else t &= (s[1] != s.back());
if (t) cout << s, exit(0);
}
}
cout << -1 << "\n";
}
| 0
| 7,341,852
|
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,ll>
const ll MOD=998244353;
const int INF=1e9;
const double PI=acos(-1);
int main() {
ios_base::sync_with_stdio(false);
int a,b,c;
cin >> a >> b >> c;
if (a+b>=c) cout << "Yes" << endl;
else cout << "No" << endl;
return 0;
}
|
#include<iostream>
using namespace std;
int h,w,d;
char a[4]={'R','Y','G','B'};
int main()
{
cin>>h>>w>>d;
for(int i=1;i<=h;++i,cout<<endl)
for(int j=1;j<=w;++j)
{
int x=i+j+w,y=i-j+w;
cout<<a[((x/d)&1)*2+((y/d)&1)];
}
return 0;
}
| 0
| 66,423,707
|
#include<bits/stdc++.h>
using namespace std;
int main(){
string S;
cin>>S;
int s=S.size();
map<char,int> ma;
for(int i=0;i<s;i++){
ma[S[i]]++;
}
for(char c='a';c<='z';c++){
if(ma[c]==0){
cout<<c<<endl;
return 0;
}
}
cout <<"None"<<endl;
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
ll n,y;
cin>>n>>y;
vector<ll> a(3,-1);
for(ll i=0;i<=n;i++){
for(ll j=0;j<=n&&j+i<=n;j++){
ll k=n-(i+j);
if(i*10000LL+j*5000LL+k*1000LL==y){
a[0]=i;
a[1]=j;
a[2]=k;
}
}
}
for(int i=0;i<3;i++) cout<<a[i]<<' ';
cout<<endl;
}
| 0
| 85,645,506
|
#include <bits/stdc++.h>
using namespace std;
bool Check(string input){
if(input.size()%2 == 1){
return false;
}
else{
int len = input.size() / 2;
for(int i=0;i<len;i++){
if(input[i] != input[i+len]) return false;
}
return true;
}
}
int main(void){
string S;
cin >> S;
int N = S.size();
for(int i=N-1;i>=0;i--){
if(Check(S.substr(0,i))){cout << S.substr(0,i).size() << endl; return 0;}
}
}
|
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std; using ll=long long; using P=pair<ll,ll>; const int INF=1e9; const ll LNF=1e18;
int main(){
string s; cin>>s; s+='T';
int x,y; cin>>x>>y;
vector<int> v[2];
int tt=0, nw=0; bool fs=true;
for(char ch : s) {
if (ch == 'F') nw++;
else if (fs) {
x -= nw; nw=0; tt^=1; fs=false;
} else {
if (nw > 0) v[tt].push_back(nw);
nw=0; tt^=1;
}
}
set<int> val[2];
int n0 = v[0].size(), n1 = v[1].size();
val[0].insert(0);
for(int i=0;i<n0;i++) {
int now = i%2, nex = (i+1)%2;
val[nex].clear();
for(int z:val[now]) {
val[nex].insert(z+v[0][i]);
val[nex].insert(z-v[0][i]);
}
}
if (val[n0%2].find(x) == val[n0%2].end()) {
cout<<"No"<<endl;
return 0;
}
val[0].clear(); val[1].clear();
val[0].insert(0);
for(int i=0;i<n1;i++) {
int now = i%2, nex = (i+1)%2;
val[nex].clear();
for(int z:val[now]) {
val[nex].insert(z+v[1][i]);
val[nex].insert(z-v[1][i]);
}
}
if (val[n1%2].find(y) == val[n1%2].end()) {
cout<<"No"<<endl;
return 0;
}
cout<<"Yes"<<endl;
}
| 0
| 49,963,272
|
#include <bits/stdc++.h>
typedef long long ll;
const int kN = 1e5 + 5;
int a[kN]; ll ans = 0;
int main() {
int n, lst = 0; scanf("%d", &n);
for(int i = 1; i <= n; ++i) {
int x; scanf("%d", &x);
if(lst && x) lst = 0, --x, ++ans;
lst = x % 2; ans += x / 2;
}
printf("%lld", ans);
return 0;
}
|
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <iomanip>
#include <math.h>
#include <fstream>
using namespace std;
class pqComp
{
public:
bool operator()(pair<int, int> &a, pair<int, int> &b)
{
return a.second < b.second;
}
};
bool sorting(pair<int, int> a, pair<int, int> b)
{
return a.second < b.second;
}
int main()
{
ios::sync_with_stdio(false);
cout << fixed << setprecision(12);
cin.tie();
cout.tie();
int k;
string s;
cin >> k >> s;
if (s.size() <= k)
{
cout << s << '\n';
}
else
{
cout << s.substr(0, k) << "...\n";
}
return 0;
}
| 0
| 2,965,274
|
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0)
#define endl "\n";
#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define int long long
const int MOD=1e9+7;
const int N=3e5+10;
int32_t main()
{
IOS;
int n;
cin>>n;
cout<<n*(n-1)/2<<endl;
}
|
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;
#define ANS(f) if(f) cout << "YES" << endl; else cout << "NO" << endl;
typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;
template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }
void debug(mat m){REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl; }}
vec slide(vec v, int n){
int N = v.size();
vec w(N);
REP(i, n) w[N - 1 - i] = v[i];
REP(i, N - n) w[i] = v[n + i];
return w;
}
signed main(){
int N, A, B; cin >> N >> A >> B;
if(A + B > N + 1 || A * B < N){
cout << -1 << endl;
return 0;
}
int n = (N - 1) / B + 1;
mat ans(n);
int v = 1;
REP(i, n){
int m = min(N, B);
ans[i] = vec(m);
IREP(j, m){
ans[i][j] = v;
v++;
}
N -= m;
}
int a = n;
IREP(i, n){
int k = min((int)ans[i].size() - 1, A - a);
ans[i] = slide(ans[i], k);
a += k;
}
REP(i, n) REP(j, ans[i].size()) cout << ans[i][j] << " ";
return 0;
}
| 0
| 68,359,929
|
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main() {
long long k, a, b;
cin >> k >> a >> b;
k++;
long long co = 0;
if (a + 2 >= b) {
cout << k << endl;
}
else {
co += a;
k -= a;
co += k / 2 * b - a * (k / 2);
co += k % 2;
cout << co << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using namespace std;
int main() {
fastIO;
int n, m, x, y;
cin >> n >> m >> x >> y;
vector<int> X(n);
vector<int> Y(m);
rep(i, n) cin >> X.at(i);
rep(i, m) cin >> Y.at(i);
sort(X.begin(), X.end());
sort(Y.begin(), Y.end());
int x_max = X.back();
int y_min = Y.front();
vector<int> possible;
for (int i = x_max + 1; i <= y_min; i++) {
possible.push_back(i);
}
for (auto p : possible) {
if (x < p && p <= y) {
cout << "No War";
return 0;
}
}
cout << "War";
return 0;
}
| 0
| 6,969,913
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
char x;
cin >> x;
cout << (char) (++x);
return 0;
}
|
#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 repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
template<class T>bool chmax(T &a, const T &b) {
if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) {
if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
}return (N * jou(N, P-1)) % mod;}
int main() {
int n;
cin>>n;
vector<ll> p(70);
rep(i,n){
ll x;
cin>>x;
int cnt=0;
while(x>0){
p[cnt]+=x%2;
x/=2;
cnt++;
}
}
ll ans=0;
rep(i,70){
ll x=jou(2,i);
x*=p[i];
if(x>mod) x%=mod;
x*=n-p[i];
if(x>mod) x%=mod;
ans+=x;
if(ans>mod) ans%=mod;
}
cout << ans << endl;
}
| 0
| 98,086,878
|
#include<iostream>
using namespace std;
#define MAX 256
int miku(int x){
if(x > 36)return 0;
if(x < 10)return (x + 3)*(x + 2)*(x + 1) / 6;
if(x > 18)return miku(36 - x);
if(x > 9 && x < 19)return (x + 3)*(x + 2)*(x + 1) / 6 - (miku(x - 10) * 4);
}
int main(void){
int n,i = 0;
int ans[MAX];
while(cin >> n){
ans[i] = miku(n);
i++;
}
for(int j = 0;j < i;j++){
cout << ans [j] <<endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;
int main(){
int n,d;
cin >> n >> d;
vector<vector<int>> x(n,vector<int>(d));
rep(i,n){
rep(j,d){
cin >> x[i][j];
}
}
int ans = 0;
for(int i=0; i<n; i++){
for(int j=i+1; j<n; j++){
double dist = 0.0;
for(int k=0; k<d; k++){
dist += (x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
}
dist = sqrt(dist);
if((dist-(int)dist) < 0.00001){
ans++;
}
}
}
cout << ans << endl;
return 0;
}
| 0
| 55,914,864
|
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
signed main()
{
int n;
cin >> n;
vector<int> w(n);
rep(i, n) cin >> w[i];
int best = 1e8;
rep(i, n) {
int sum0 = 0, sum1 = 0;
rep(j, i) {
sum0 += w[j];
}
rep (j, n - i) {
sum1 += w[n - j - 1];
}
if (abs(best) > abs(sum1 - sum0)) {
best = abs(sum1 - sum0);
}
}
cout << best << endl;
return 0;
}
|
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
char hand[100005];
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n, k;
ll r, p, s;
string t;
cin >> n >> k >> r >> s >> p >> t;
ll ans = 0;
rep(i,n){
if(t[i] == 'r'){
if(i-k < 0 || hand[i-k] != 'p'){
ans += p;
hand[i] = 'p';
}
else hand[i] = '!';
}
else if(t[i] == 's'){
if(i-k < 0 || hand[i-k] != 'r'){
ans += r;
hand[i] = 'r';
}
else hand[i] = '!';
}
else{
if(i-k < 0 || hand[i-k] != 's'){
ans += s;
hand[i] = 's';
}
else hand[i] = '!';
}
}
cout << ans << endl;
return 0;
}
| 0
| 60,141,637
|
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define PI 3.1415926535897932384626433832795028841971693993
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9+7;
int main(){
int n,k,r,s,p,ans=0;
string t;
cin>>n>>k>>r>>s>>p>>t;
vector<bool> dat(n,true);
rep(i,n){
if(i-k>=0){
if(t[i-k]==t[i]&&dat[i-k]){
dat[i]=false;
continue;
}
}
if(t[i]=='r') ans+=p;
else if(t[i]=='s') ans+=r;
else ans+=s;
}
cout<<ans<<endl;
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define fast_io(); std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);
const std::string yes = "Yes";
const std::string no = "No";
int main(){
int n,m;
std::cin >> n;
std::set<std::string> st;
std::multiset<std::string> s,t;
rep(i,n){
std::string si;
std::cin >> si;
s.insert(si);
st.insert(si);
}
std::cin >> m;
rep(i,m){
std::string ti;
std::cin >> ti;
t.insert(ti);
}
int ans = 0;
for(auto itr=st.begin(); itr!=st.end(); itr++){
int buf = s.count(*itr);
buf -= t.count(*itr);
ans = std::max(ans, buf);
}
std::cout << ans << "\n";
return 0;
}
| 0
| 18,768,995
|
#include<bits/stdc++.h>
using namespace std;
int main()
{
double n;
cin>>n;
printf("%lf",(n/3)*(n/3)*(n/3));
return 0;}
|
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
#include <deque>
#include <queue>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)
struct Pair
{
int I;
int U;
};
int main(void)
{
int N;
cin >> N;
vector<int> a;
int tmp;
for (int i = 0; i < N; i++)
{
cin >> tmp;
a.push_back(tmp);
}
int count = 0;
for (int i = 0; i < N; i++)
{
if (a[a[i] - 1] == i + 1)
{
count++;
}
}
cout << count / 2 << endl;
return 0;
}
| 0
| 44,526,631
|
#include <iostream>
#include <vector>
using namespace std;
int main(void){
int n,t;
cin>>n>>t;
vector<int>time(n);
for(int i=0;i<n;i++){
cin>>time[i];
}
int dif;
long long sum=t;
for(int i=1;i<n;i++){
dif=time[i]-time[i-1];
if(dif<=t)sum+=dif;
else sum+=t;
}
cout<<sum<<endl;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
const int INF=1e9;
int main() {
int n,m,r;
cin >> n >> m >> r;
vector<vector<int>> G(n+1, vector<int>(n+1,INF));
vector<int> R(r);
for ( int i=0; i<r; i++ ) {
cin >> R[i];
}
for ( int i=0; i<=n; i++ ) G[i][i]=0;
for ( int i=0; i<m; i++ ) {
int a,b,c;
cin >> a >> b >> c;
G[a][b]=c;
G[b][a]=c;
}
for ( int k=1; k<=n; k++ )
for ( int i=1; i<=n; i++ )
for ( int j=1; j<=n; j++ )
G[i][j]=min(G[i][j],G[i][k]+G[k][j]);
vector<vector<int>> dp(1<<r, vector<int>(n+1,INF));
for ( int i=0; i<=n; i++ ) dp[0][i]=0;
for ( int i=0; i<r; i++ ) dp[1<<i][R[i]]=0;
for ( int mask=1; mask<(1<<r); mask++ ) {
for ( int i=0; i<r; i++ ) {
if ( mask>>i&1 ) {
for ( int j=0; j<r; j++ ) {
dp[mask][R[i]]=min(dp[mask][R[i]],dp[mask^(1<<i)][R[j]]+G[R[j]][R[i]]);
}
}
}
}
int mi=INF;
for ( int i=1; i<=n; i++ ) {
mi=min(mi,dp[(1<<r)-1][i]);
}
cout << mi << '\n';
return 0;
}
| 0
| 91,036,711
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
typedef long long int ll;
typedef pair<int,int> P;
const int INF = 1e9+7;
int main(){
int N,K;
cin >> N >> K;
if(N%K){
cout << "1";
}else{
cout << "0";
}
}
|
#include <bits/stdc++.h>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
const ll MOD=1e9+7;
const ll INF=1e18;
int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
template <typename T> inline string toString(const T &a){ostringstream oss; oss<<a; return oss.str();};
int main(){
int n; cin>>n;
vector<int> t(n), v(n);
for(int i=0; i<n; i++) cin>>t[i];
for(int i=0; i<n; i++) cin>>v[i];
vector<int> sumt(n+10, 0);
for(int i=1; i<=n; i++){
sumt[i]=sumt[i-1]+t[i-1];
}
vector<double> maxv(40010, 0);
int cnt=0;
for(int i=1; i<sumt[n]*2; i++){
if(2*sumt[cnt]<i && i<2*sumt[cnt+1]){
maxv[i]=v[cnt];
}
else if(i==2*sumt[cnt+1]){
maxv[i]=min(v[cnt], v[cnt+1]);
cnt++;
}
}
for(int i=1; i<=sumt[n]*2; i++){
maxv[i]=min(maxv[i], maxv[i-1]+0.5);
}
for(int i=sumt[n]*2-1; i>=0; i--){
maxv[i]=min(maxv[i], maxv[i+1]+0.5);
}
double ans=0;
for(int i=0; i<sumt[n]*2; i++){
ans+=1.*(maxv[i]+maxv[i+1])/4;
}
cout << fixed << setprecision(10) << ans << endl;
}
| 0
| 2,671,876
|
#include <iostream>
#include <string>
#include <cctype>
#include <vector>
using namespace std;
int transform(string str){
int num=0;
for(int j=0;j<str.length();j++){
if(isdigit((int)str[j])){
if(str[j+1]=='m') num += (str[j]-48)*1000;
else if(str[j+1]=='c') num += (str[j]-48)*100;
else if(str[j+1]=='x') num += (str[j]-48)*10;
else if(str[j+1]=='i') num += (str[j]-48);
j++;
}else{
if(str[j]=='m') num+=1000;
else if(str[j]=='c') num+=100;
else if(str[j]=='x') num+=10;
else if(str[j]=='i') num++;
}
}
return num;
}
int retrans(int num){
vector<char> ans;
int kurai[4];
for(int k=0;k<4;k++){
kurai[k]=num%10;
num/=10;
}
for(int k=0;k<4;k++){
if(kurai[3-k]==0) continue;
else if(kurai[3-k]==1){
if(k==0) ans.push_back('m');
else if(k==1) ans.push_back('c');
else if(k==2) ans.push_back('x');
else if(k==3) ans.push_back('i');
}else{
ans.push_back(kurai[3-k]+48);
if(k==0) ans.push_back('m');
else if(k==1) ans.push_back('c');
else if(k==2) ans.push_back('x');
else if(k==3) ans.push_back('i');
}
}
for(int k=0;k<ans.size();k++){
cout<<ans[k];
}
cout<<endl;
return 0;
}
int main(){
int n;
cin>>n;
for(int i=0;i<n;i++){
string mcxi1,mcxi2;
cin>>mcxi1>>mcxi2;
int a=transform(mcxi1);
int b=transform(mcxi2);
retrans(a+b);
}
return 0;
}
|
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
using namespace std;
#define mp make_pair
#define fi first
#define se second
#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) (((a) * (b)) / (__gcd((a), (b))))
#define in_range(x, y, r, c) (x < r && y < c && x >= 0 && y >= 0)
#define setbits(x) __builtin_popcountll(x)
#define unsetend(x) __builtin_ctzll(x)
#define unsetfront(x) __builtin_clzll(x)
#define f first
#define s second
#define pb push_back
#define pf push_front
#define ll long long
#define endl "\n"
#define Endl "\n"
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int i, j, n, m, mod = 1e9 + 7;
cin >> n >> m;
char arr[n][m];
int dp[n][m];
for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
{
cin >> arr[i][j];
dp[i][j] = 0;
}
}
dp[0][0] = 1;
for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
{
if (i == 0 && j == 0)
dp[i][j] = 1;
else
{
if (arr[i][j] != '#')
{
if (in_range(i - 1, j, n, m))
dp[i][j] = (dp[i][j] + dp[i - 1][j]) % mod;
if (in_range(i, j - 1, n, m))
dp[i][j] = (dp[i][j] + dp[i][j - 1]) % mod;
}
}
}
}
cout << dp[n - 1][m - 1] << endl;
}
| 0
| 76,220,790
|
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;
int main() {
int N;
cin >> N;
int H[N];
REP(i, N){
cin >> H[i];
}
int res = 0, ans = 0;
REP(i, N-1){
if(H[i] >= H[i+1]){
res++;
}
else{
ans = max(ans, res);
res = 0;
}
}
ans = max(ans, res);
cout << ans << endl;
}
|
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>
#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x) cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR
#endif
using namespace std;
using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void solve() {
int n,k;
cin >> n >> k;
VLL a(n);
REP(i,0,n) cin >> a[i];
VLL ru(n+1), ss(n);
REP(i,0,n) ru[i+1] = ru[i] + max(0LL, a[i]);
REP(i,0,k) ss[k-1] += a[i];
REP(i,k,n) ss[i] = ss[i-1] + a[i] - a[i-k];
LL ans = ru[n-k];
REP(i,k-1,n) {
chmax(ans, ru[n]-ru[i+1]+ru[i+1-k] + max(0LL, ss[i]));
}
cout << ans << endl;
}
signed main() {
solve();
return 0;
}
| 0
| 2,054,913
|
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define INF (1 << 30) - 1
#define LINF 1LL << 60
const int MOD = 1000000007;
using ll = long long;
using P = pair<int, int>;
int dp[1010][1010];
int main(){
string s, t;
cin >> s >> t;
int ss = s.size();
int ts = t.size();
for(int i = 0; i <= ss; ++i)dp[i][0] = i;
for(int j = 0; j <= ts; ++j)dp[0][j] = j;
for(int i = 0; i < ss; ++i){
for(int j = 0; j < ts; ++j){
int cost = (s[i] == t[j]) ? 0 : 1;
dp[i + 1][j + 1] = min({dp[i][j] + cost, dp[i + 1][j] + 1, dp[i][j + 1] + 1});
}
}
cout << dp[ss][ts] << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> Pair;
typedef vector<ll> vll;
typedef vector<vector<ll>> Graph;
typedef vector<string> vs;
typedef vector<pair<ll, ll>> Pll;
typedef queue<ll> qll;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REPA(i,a) for(ll i=0;i<(ll)(a.size());i++);
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define COUT(a) cout << (a) << endl;
#define ENDL(a) cout << endl;
#define COUTA(i,a) for(ll i=0;i<(ll)(a.size());i++) {cout << (a)[i] << " ";} cout << endl;
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define RSORT(a) sort((a).rbegin(), (a).rend())
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
template <typename T>
void debugV(const vector<T> v) {
#ifdef _DEBUG
rep(i, v.size()) {
cout << i << ":" << v[i] << " ";
}
cout << endl;
#else
(void)v;
#endif
}
const unsigned int BIT_FLAG_0 = (1 << 0);
const unsigned int BIT_FLAG_1 = (1 << 1);
const unsigned int BIT_FLAG_2 = (1 << 2);
const unsigned int BIT_FLAG_3 = (1 << 3);
const unsigned int BIT_FLAG_4 = (1 << 4);
const unsigned int BIT_FLAG_5 = (1 << 5);
const unsigned int BIT_FLAG_6 = (1 << 6);
const unsigned int BIT_FLAG_7 = (1 << 7);
const unsigned int BIT_FLAG_8 = (1 << 8);
const unsigned int BIT_FLAG_9 = (1 << 9);
const unsigned int BIT_FLAG_10 = (1 << 10);
const unsigned int BIT_FLAG_11 = (1 << 11);
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI=3.14159265358979323846;
constexpr int MOD = 1000000007;
void Main() {
ll n;
cin >> n;
ld total = 0;
REP(i, n) {
ll a_in;
cin >> a_in;
total += (ld)1 / a_in;
}
COUT(1/total);
}
int main()
{
cin.tie(0);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(15);
Main();
}
| 0
| 77,908,413
|
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0
using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vd vector<double>
#define vvi vector<vi>
#define vvl vector<vl>
#define vvb vector<vb>
#define vvd vector<vd>
#define pii pair<int, int>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define pb push_back
#define sz(s) (int)(s.size())
#define mp make_pair
#define all(a) (a).begin(),(a).end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll a, ll b) {
if (b == 0) return a;
else return gcd(b, a % b);
}
ll keta(ll n){
string s = to_string(n);
ll num = s.size();
return num;
}
const ll INF = 1LL << 60;
const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};
struct Edge{
int to;
int weight;
Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;
class UnionFind{
public:
vi Parent, diff_weight;
UnionFind(int n){
Parent = vi(n,-1);
diff_weight = vi(n,0);
}
int root(int a){
if(Parent[a] < 0) return a;
int r = root(Parent[a]);
diff_weight[a] += diff_weight[Parent[a]];
return Parent[a] = r;
}
int weight(int a){
root(a);
return diff_weight[a];
}
bool issame(int a, int b){
return root(a) == root(b);
}
int size(int a){
return -Parent[root(a)];
}
bool merge(int a, int b, int w = 0){
w += weight(a); w -= weight(b);
a = root(a);
b = root(b);
if(a == b) return false;
if(size(a) < size(b)) swap(a,b), w = -w;
Parent[a] += Parent[b];
Parent[b] = a;
diff_weight[b] = w;
return true;
}
int diff(int a, int b){
return weight(b) - weight(a);
}
};
vi MP(string s){
vi A(s.size()+1);
A[0] = -1;
int j = -1;
rep(i,s.size()) {
while(j >= 0 && s[i] != s[j]) j = A[j];
j++;
A[i+1] = j;
}
return A;
}
vi Manacher(string s){
vi R(s.size());
int i = 0, j = 0;
while(i < s.size()){
while(i-j >= 0 && i+j < s.size() && s[i-j] == s[i+j]) ++j;
R[i] = j;
int k = 1;
while(i-k >= 0 && i+k < s.size() && k+R[i-k] < j) R[i+k] = R[i-k], k++;
i += k; j -= k;
}
return R;
}
vi Z_algorithm(string &s){
vi Z(s.size());
Z[0] = s.size();
int i = 1, j = 0;
while(i < s.size()){
while(i+j < s.size() && s[j] == s[i+j]) j++;
Z[i] = j;
if(j == 0){++i; continue;}
int k = 1;
while(i+k < s.size() && k+Z[k] < j) Z[i+k] = Z[k], ++k;
i += k; j -= k;
}
return Z;
}
const int MAX = 1e6+1;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++){
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
long long COM(ll n, ll k){
if(n >= MAX){
ll tmp = 1;
rep(i,k){
tmp *= (n-i);
tmp %= MOD;
}
return tmp*finv[k]%MOD;
}
if (n < k) return 0;
if (n < 0 || k < 0) return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll POW(ll x, ll n){
ll ret = 1;
if(n < 0){
n *= -1;
x = inv[x];
}
while(0 < n){
if(n%2 == 0){
x = x*x%MOD;
n /= 2;
}
else{
ret = ret*x%MOD;
n--;
}
}
return ret;
}
ll dp[2020][2020];
int main(){
int n, m; cin >> n >> m;
vi s(n+1), t(m+1);
rep(i,n) cin >> s[i];
rep(i,m) cin >> t[i];
dp[0][0] = 1;
rep(i,n+1) rep(j,m+1) {
if(i-1 >= 0 && j-1 >= 0 && s[i-1] == t[j-1]) dp[i][j] += dp[i-1][j-1];
if(i-1 >= 0) dp[i][j] += dp[i-1][j];
if(j-1 >= 0) dp[i][j] += dp[i][j-1];
if(i-1 >= 0 && j-1 >= 0) dp[i][j] -= dp[i-1][j-1];
dp[i][j] %= MOD;
}
while(dp[n][m] < 0) dp[n][m] += MOD;
cout << dp[n][m] << endl;
}
|
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
vector<ll> enumerate_divisors(ll n) {
vector<ll> divisor_1, divisor_2;
ll e, root_n = (ll)(sqrt(n) + 0.5);
for (int d = 1; d <= root_n; d++) {
if (n % d == 0) {
divisor_1.push_back(d);
e = n / d;
if (e != d) divisor_2.push_back(e);
}
}
reverse(divisor_2.begin(), divisor_2.end());
divisor_1.insert(divisor_1.end(), divisor_2.begin(), divisor_2.end());
return divisor_1;
}
int main() {
ll N;
cin >> N;
auto F = [](ll A, ll B) -> int {
return max(to_string(A).size(), to_string(B).size());
};
vector<ll> divisors = enumerate_divisors(N);
int ans = 1 << 30;
for (ll d: divisors) {
ans = min(ans, F(d, N / d));
}
cout << ans << endl;
return 0;
}
| 0
| 24,622,535
|
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
int n,m,x,y,ind[maxn];
signed main()
{
cin>>n>>m;
for(int i=1;i<=m;i++)cin>>x>>y,ind[x]++,ind[y]++;
for(int i=1;i<=n;i++)
if(ind[i]&1)puts("NO"),exit(0);
puts("YES");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
static const int INF (1<<30);
int main() {
int N, K;
cin >> N >> K;
if (K > (N-1)*(N-2)/2) {
cout << -1 << endl;
return 0;
}
vector<vector<int>> ans(N);
for (int i = 1; i < N; i++) {
ans[0].push_back(i+1);
}
int now = (N-1)*(N-2)/2;
int id = 1;
while (now > K) {
int cnt = ans[id].size();
ans[id].push_back(cnt+id+2);
now--;
if ((cnt+1) == (N-id-1)) id++;
}
int cntE = 0;
rep(i, N) {
cntE += ans[i].size();
}
cout << cntE << endl;
rep(i, N) {
for (auto x : ans[i]) {
cout << (i+1) << " " << x << endl;
}
}
return 0;
}
| 0
| 46,765,739
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n; cin >> n;
vector<ll> A(n+1); rep(i, n+1) cin >> A[i];
auto no = [&]() {
cout << -1 << "\n";
exit(0);
};
vector<ll> mn(n+2), mx(n+2);
mn[0] = 1, mx[0] = 1;
rep(i, n+1) {
if(i==n) {
if(mn[i]<=A[i] && A[i]<=mx[i]) {
break;
} else {
no();
}
}
if(mx[i]-A[i]<0) no();
mn[i+1] = max(mn[i]-A[i], 0LL);
mx[i+1] = min((mx[i]-A[i])*2, longinf);
}
ll ans = 0;
ll tmp = A[n];
rrep(i, n+1) {
ans += tmp;
if(i) tmp = min(mx[i-1], tmp+A[i-1]);
}
cout << ans << "\n";
return 0;
}
|
#include<bits/stdc++.h>
#define l long
#define ll long long
#define ld long double
#define INF 1000000000000
#define MOD 1000000007
#define MAX_N 1000006
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main()
{
l n,k;
cin>>n>>k;
vector<l> a;
l x;
for(l i=0;i<n;i++)
{
cin>>x;
a.push_back(x);
}
vector<ll> dp(k+1),prf(k+1);
dp[0]=1;
l lo,hi;
for(l i=0;i<n;i++)
{
for(l s=0;s<=k;s++)
prf[s]=0;
for(l s=0;s<=k;s++)
{
lo=s+1;
hi=s+min(a[i],k-s);
if(lo<=hi)
{
prf[lo]=(prf[lo]+dp[s])%MOD;
if(hi<k)
prf[hi+1]=(prf[hi+1]-dp[s])%MOD;
}
}
dp[0]=(dp[0]+prf[0])%MOD;
for(l s=1;s<=k;s++)
{
prf[s]=(prf[s-1]+prf[s])%MOD;
dp[s]=(dp[s]+prf[s])%MOD;
}
}
if(dp[k]<0)
dp[k]+=MOD;
cout<<dp[k]<<endl;
}
| 0
| 72,063,861
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++)
#define frep(i,m,n) for(ll (i)=(m); (i)<=(ll)(n); (i)++)
#define rrep(i,n) for(ll (i)=(n)-1; (i)>-1; (i)--)
#define frrep(i,m,n) for(ll (i)=(n); (i)>(ll)(m); (i)--)
#define ALL(x) (x).begin(), (x).end()
const ll INF = 100100100100100100;
const ll MOD = 1000000007;
ll my_abs(ll a);
ll a_n(ll a, ll n);
ll my_gcd(ll a, ll b);
ll inv(ll a);
ll madd(ll a, ll b, ll c);
ll msub(ll a, ll b);
ll mtime(ll a, ll b, ll c);
int main() {
ll x, y;
cin >> x >> y;
cout << x+(y/2) << endl;
return 0;
}
ll my_abs(ll a) {
if(a >= 0) return a;
else return -1 *a;
}
ll a_n(ll a, ll n) {
if(n == 0) return 1;
ll ret = a, count = 1;
while(count * 2 < n) {
ret *= ret;
count *= 2;
}
if(count == n) return ret;
else return (ret * a_n(a, n-count));
}
ll my_gcd(ll a, ll b) {
if(b == 0) return a;
return my_gcd(b, a%b);
}
ll inv(ll a) {
return a_n(a, MOD-2);
}
ll madd(ll a, ll b, ll c) {
ll ret = (a+b) % MOD;
return (ret+c) % MOD;
}
ll msub(ll a, ll b) {
if(a < b) return (a-b+MOD) % MOD;
else return (a-b) % MOD;
}
ll mtime(ll a, ll b, ll c) {
ll ret = (a*b) % MOD;
return (ret*c) % MOD;
}
|
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cstring>
using namespace std;
struct node{
int key;
node *next;
node *prev;
};
node *a;
void insert(int key){
node *x = (node *)malloc(sizeof(node));
x->key = key;
x->next = a->next;
a->next->prev = x;
a->next = x;
x->prev = a;
}
node *Searchlist(int key){
node *search = a->next;
while(search != a && search->key != key){
search = search->next;
}
return search;
}
void init(){
a = (node *)malloc(sizeof(node));
a->next = a;
a->prev = a;
}
void delNode(node *search){
if(search == a) return;
search->prev->next = search->next;
search->next->prev = search->prev;
free(search);
}
void delKey(int key){
delNode(Searchlist(key));
}
void delFirst(){
delNode(a->next);
}
void delLast(){
delNode(a->prev);
}
void print(){
node *out = a->next;
int j = 0;
while(1){
if(out == a) break;
if(j++ > 0) printf(" ");
printf("%d", out->key);
out = out->next;
}
printf("\n");
}
int main(){
int n;
scanf("%d", &n);
int key;
int cnt = 0;
int p = 0;
int d = 0;
char s[50];
init();
for(int i = 0; i < n; i++){
scanf("%s%d", s, &key);
if(s[0] == 'i'){
insert(key);
p++;
cnt++;
}
else if(s[0] == 'd'){
if(strlen(s) > 7){
if(s[6] == 'F') delFirst();
else if(s[6] == 'L') delLast();
}
else{
delKey(key);
d++;
}
cnt--;
}
}
print();
return 0;
}
| 0
| 9,225,868
|
#include<bits/stdc++.h>
#define MAXN ((int)(1e5+10))
#define INF ((int)(1e9))
using namespace std;
typedef long long LL;
int n,k;
LL a[MAXN],sum=0,ans=-INF,tmp=0;
int main()
{
cin>>n>>k;
for(int i=0;i<n;i++)
{
cin>>a[i];
tmp+=a[i];
if(a[i]>0)
sum+=a[i];
}
LL integer=0,fu=0;
for(int i=0;i<k;i++)
{
if(a[i]>0)
integer+=a[i];
else
fu+=(0-a[i]);
}
for(int i=0;i<=n-k;i++)
{
LL rec;
if(integer>=fu)
rec=sum-fu;
else
rec=sum-integer;
ans=max(ans,rec);
if(a[i]>0)
integer-=a[i];
else
fu-=(0-a[i]);
if(a[i+k]>0)
integer+=a[i+k];
else
fu+=(0-a[i+k]);
}
cout<<ans<<endl;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
int jumps(int N, int a[],int k) {
int x,y;
int dp[N+1] = {0};
for(int i=2; i<=N; i++) {
x = y = INT_MAX;
for(int j=1; j<=k; j++) {
if(i-j>=1) x = dp[i-j] + abs(a[i] - a[i-j]);
y = min(x,y);
}
dp[i] = y;
}
return dp[N];
}
int main() {
int N,k;
cin>>N>>k;
int a[N+1];
for(int i=1; i<=N; i++) cin>>a[i];
cout<<jumps(N,a,k);
return 0;
}
| 0
| 21,080,548
|
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const ll MAX = 1000000000000000;
static const int NIL = -1;
using namespace std;
ll gcd(ll a, ll b) {
if (a % b == 0) {
return b;
} else {
return gcd(b, a % b);
}
}
ll lcm(ll a, ll b){
return (a/gcd(a, b))*b;
}
int main() {
int n; cin >> n;
ll tmp;
ll ans;
rep(i,n){
cin >> tmp;
if(i == 0) ans = tmp;
else ans = lcm(ans,tmp);
}
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
int sex[100000];
bool check(int l, int r) {
int len = r - l + 1;
if (len % 2) {
return sex[l] != sex[r];
} else {
return sex[l] == sex[r];
}
}
int main() {
int N;
cin >> N;
string ans;
cout << 0 << endl;
cin >> ans;
if (ans == "Vacant") {
return 0;
} else if (ans == "Male") {
sex[0] = 1;
}
cout << N - 1 << endl;
cin >> ans;
if (ans == "Vacant") {
return 0;
} else if (ans == "Male") {
sex[N - 1] = 1;
}
int l = 0, r = N - 1;
while (r - l >= 4) {
int m = (l + r) / 2;
cout << m << endl;
cin >> ans;
if (ans == "Vacant") {
return 0;
} else if (ans == "Male") {
sex[m] = 1;
}
int len = r - l + 1;
sex[m - 1] = sex[m + 1] = !sex[m];
if (check(l, m - 1)) {
r = m - 1;
} else {
l = m + 1;
}
}
for (int i = l; i <= r; i++) {
cout << i << endl;
cin >> ans;
if (ans == "Vacant") return 0;
}
}
| 0
| 69,956,258
|
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
const int mod = 1e9 + 7;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
int main(){
ll n; cin >> n;
vll l(2*n);
rep(i,2*n)cin >> l[i];
sort(all(l));
ll ans = 0;
rep(i,n){
ans += l[2*i];
}
cout << ans << endl;
return 0;
}
|
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define eb emplace_back
using ll = int64_t;
using namespace std;
ll n,m;
ll a[100010];
int main(void){
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n >> m;
REP(i,n)cin >> a[i];
int two = 0;
REP(i,n){
if(i == 0){
ll x = a[i];
while(x % 2 == 0){
two++;
x /= 2;
}
}else{
ll x = a[i];
int y = 0;
while(x % 2 == 0){
y++;
x /= 2;
}
if(y != two){
cout << 0 << '\n';
return 0;
}
}
}
if(two != 0){
REP(i,n) a[i] /= 2;
}
ll L = 1;
REP(i,n){
L = (L * a[i]) / gcd(L,a[i]);
}
cout << (1 + m/L)/2 << '\n';
}
| 0
| 25,700,723
|
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
string s;
cin>>s;
int n=s.size(),cnt=0;
rep(i,n-1){
if(s[i]!=s[i+1]) cnt++;
}
cout<<cnt;
}
|
#include <bits/stdc++.h>
using namespace std;
int main(){
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
int x3, y3, x4, y4;
int difx, dify;
difx = abs(x1-x2);
dify = abs(y1-y2);
if (x1 > x2){
if (y1 > y2){
x3 = x2 + dify;
y3 = y2 - difx;
x4 = x1 + dify;
y4 = y1 - difx;
}
else{
x3 = x2 - dify;
y3 = y2 - difx;
x4 = x1 - dify;
y4 = y1 - difx;
}
}
else{
if (y1 > y2){
x3 = x2 + dify;
y3 = y2 + difx;
x4 = x1 + dify;
y4 = y1 + difx;
}
else{
x3 = x2 - dify;
y3 = y2 + difx;
x4 = x1 - dify;
y4 = y1 + difx;
}
}
cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
return 0;
}
| 0
| 10,179,168
|
#include <iostream>
#include <string.h>
#include <algorithm>
#include <vector>
#include <fstream>
using namespace std;
ifstream fin("../data.txt");
int k, s, x, y, z, ways;
int main() {
cin >> k >> s;
for (x = 0; x <= k; x++) {
for (y = 0; y <= k; y++) {
if (s - x - y >= 0 && s - x - y <= k) ways++;
}
}
cout << ways;
return 0;
}
|
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 10e17
#define MOD 1000000007
#define mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef long long int LL;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
if(a.fi!=b.fi)
return a.fi<b.fi;
else
return a.se<b.se;
}
ll sum[200001];
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
ll n;cin>>n;
V<ll>a(n);
for(ll i=0;i<n;i++)cin>>a[i];
sum[0]=a[0];
for(ll i=1;i<n;i++){
sum[i]=sum[i-1]+a[i];
}
ll ans=0;
ll cnt=0;
ll now=0;
ll precnt=0;
ll right=0;
for(ll i=0;i<n;i++){
while(right<n&&(now^a[right])==now+a[right]){
now+=a[right];
right++;
}
ans+=right-i;
if(i==right)right++;
else{
now-=a[i];
}
}
cout<<ans<<endl;
return 0;
}
| 0
| 70,820,154
|
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main(){
int a[3][3];
rep(i,3) rep(j,3) cin >> a[i][j];
int n;
cin >> n;
rep(i,n){
int b;
cin >> b;
rep(j,3) rep(k,3) if(a[j][k] == b) a[j][k] = 0;
}
rep(i,3){
if(a[i][0] == a[i][1] && a[i][1] == a[i][2]){
cout << "Yes" << endl;
return 0;
}
}
rep(j,3){
if(a[0][j] == a[1][j] && a[1][j] == a[2][j]){
cout << "Yes" << endl;
return 0;
}
}
if(a[0][0] == a[1][1] && a[1][1] == a[2][2]){
cout << "Yes" << endl;
return 0;
}
if(a[0][2] == a[1][1] && a[1][1] == a[2][0]){
cout << "Yes" << endl;
return 0;
}
cout << "No" << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1e9+7;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);
template<class T> inline bool chmin(T &a,T b){
if (a>b){
a=b;
return true;
}
return false;
}
template<class T> inline bool chmax(T &a,T b){
if (a<b){
a=b;
return true;
}
return false;
}
int main(){
int N;
cin >> N;
vector<int> cnt(N,0);
int M=0;
rep(i,N){
int a;
cin >> a;
++cnt[a],chmax(M,a);
}
bool ans=true;
rep(i,M+1){
if (i<(M+1)/2&&cnt[i]>0) ans=false;
if (i==(M+1)/2){
if (M%2==0&&cnt[i]!=1) ans=false;
if (M%2==1&&cnt[i]!=2) ans=false;
continue;
}
if (i>(M+1)/2&&cnt[i]<2){
ans=false;
}
}
if (ans) cout << "Possible" << endl;
else cout << "Impossible" << endl;
}
| 0
| 95,280,806
|
#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>
#include <cmath>
const double PI = 3.14159265358979323846;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;
std::istream &operator>>(std::istream &in, set<int> &o) {
ll a;
in >> a;
o.insert(a);
return in;
}
std::istream &operator>>(std::istream &in, queue<int> &o) {
ll a;
in >> a;
o.push(a);
return in;
}
bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }
const int mod = 1000000007;
typedef priority_queue<string, vector<string>, greater<string> > PQ_ASK;
int main() {
int n;
ll z, w;
cin >> n >> z >> w;
vector<ll> cards(n);
rep(i, n) cin >> cards[i];
if (n == 1) {
cout << abs(cards.back() - w) << endl;
ret();
}
ll a1 = abs(cards.back() - w);
ll a2 = abs(cards[n - 1] - cards[n - 2]);
cout << max(a1, a2) << endl;
}
| 0
| 44,580,080
|
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0LL)
#define mapmin(v) v.rbegin()->first
#define mapmax(v) v.begin()->first
#define pb push_back
#define pf push_front
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK cerr<<"OK\n"
#define OK1 cerr<<"OK1\n"
#define OK2 cerr<<"OK2\n"
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n
#define endl '\n'
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;
const double pi = acos(-1.0);
const ll mod=1000000007;
const ll mod2=998244353;
template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
ost << "{" << p.first << ", " << p.second << "} ";
return ost;
}
template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
ost << "{";
for (int i = 0; i<(int)v.size(); i++) {
if (i)ost << " ";
ost << v[i];
}
ost << "} \n";
return ost;
}
template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
ost << "{";
for (auto p:v) {
ost << "{" << p.first << ", " << p.second << "} ";
}
ost << "} ";
return ost;
}
template<class T>
inline bool chmax(T& a, T b){if(a<b){a=b;return true;} return false;}
template<class T>
inline bool chmin(T& a, T b){if(a>b){a=b;return true;} return false;}
void YES(bool b) {cout << ((b)?"YES\n":"NO\n");}
void Yes(bool b) {cout << ((b)?"Yes\n":"No\n");}
void yes(bool b) {cout << ((b)?"yes\n":"no\n");}
void Yay(bool b) {cout << ((b)?"Yay!\n":":(\n");}
ll powmod(ll a,ll b){ll c=1; while(b>0){ if(b&1){ c=a*c%mod; } a=a*a%mod; b>>=1; } return c;}
ll nCrmod(ll n,ll r){ll x=1,y=1; rep(i,r){x=x*(n-i)%mod; y=y*(i+1)%mod;} return x*powmod(y,mod-2)%mod;}
ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}
long long LIS(vector<long long> a) {
long long n=(int)a.size();
vector<long long> dp(n,1e18);
for (long long i=0;i<n;i++){
long long tmp =lower_bound(dp.begin(),dp.end(),a[i])-dp.begin();
dp[tmp] =a[i];
}
long long k=0;
while (k<n && dp[k]!= 1e18) k++;
return k;
}
int main()
{
ll n;
cin >> n;
vll a(n);
rep(i,n) cin >> a[i];
cout << LIS(a) << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void chmin (int& a, int b) {
if (a > b) a = b;
}
int main() {
string S;
cin >> S;
int ans = 999;
for (int i = 0; i < S.size()-2; i++) {
if (S[i] > '7') {
chmin(ans, (S[i]-'7') * 100 + (S[i+1]-'5') * 10 + S[i+2]-'3');
} else if (S[i] < '7') {
chmin(ans, ('7'- S[i]) * 100 + ('5'-S[i+1]) * 10 + '3'-S[i+2]);
} else {
if (S[i+1] > '5') {
chmin(ans, (S[i]-'7') * 100 + (S[i+1]-'5') * 10 + S[i+2]-'3');
} else if (S[i+1] < '5') {
chmin(ans, ('7'- S[i]) * 100 + ('5'-S[i+1]) * 10 + '3'-S[i+2]);
} else {
if (S[i+2] >= '3') {
chmin(ans, (S[i]-'7') * 100 + (S[i+1]-'5') * 10 + S[i+2]-'3');
} else {
chmin(ans, (S[i]-'7') * 100 + (S[i+1]-'5') * 10 + '3'-S[i+2]);
}
}
}
}
cout << ans << endl;
}
| 0
| 57,484,450
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n; cin >> n;
string s; cin >> s;
if(s.size()%2!=0){
cout << "No";
return 0;
}
string t=s.substr(0,n/2);
if(t==s.substr(n/2,n/2)) cout << "Yes";
else cout << "No";
}
|
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll=long long;
using ld=long double;
#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
#define ALL(x) (x).begin(), (x).end()
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279;
int fact(int i) {
if (i == 0) return 1;
return (fact(i - 1)) * i;
}
int gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int lcm(int a, int b) {
return a * b / gcd(a, b);
}
int keta(int n) {
if (n == 0) return 1;
int count = 0;
while (n != 0) {
n /= 10;
count++;
}
return count;
}
int ketasum(int n) {
int sum = 0;
while (n != 0) {
sum += n % 10;
n /= 10;
}
return sum;
}
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
char toSmall(char c) {
return (c + 0x20);
}
char toLarge(char c) {
return (c - 0x20);
}
float myPower(int a, int n) {
float x = 1;
while (n > 0) {
if (n & 1) {
x *= a;
}
a *= a;
n >>= 1;
}
return x;
}
bool is_prime(const unsigned n) {
switch (n) {
case 0:
case 1: return false;
case 2:
case 3: return true;
}
if (n % 2 == 0 || n % 3 == 0) return false;
for (unsigned i = 5; i * i <= n; i += 6) {
if (n % i == 0) return false;
if (n % (i + 2) == 0) return false;
}
return true;
}
int main(void){
int A, B, N, x;
cin >> A >> B;
N = B - A;
x = 0;
for (int i = -1; i < N; i++) {
if ((A / 10000 == A % 10) && (A % 10000 / 1000 == A % 100 / 10)) {
x++;
}
A++;
}
cout << x << endl;
return 0;
}
| 0
| 7,917,527
|
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
while(1){
string str;
getline(cin,str);
if(str==".") break;
int i=0;
int sum = 0;
vector<int> inkakko;
while(1){
if(str[i]=='('){
inkakko.push_back(1);
sum++;
}else if(str[i]==')'){
if(inkakko.size()){
if(inkakko[inkakko.size()-1]==1){
inkakko.pop_back();
sum--;
}else{
cout << "no" << endl;
break;
}
}else{
cout << "no" << endl;
break;
}
}else if(str[i]=='['){
inkakko.push_back(2);
sum++;
}else if(str[i]==']'){
if(inkakko.size()){
if(inkakko[inkakko.size()-1]==2){
inkakko.pop_back();
sum--;
}else{
cout << "no" << endl;
break;
}
}else{
cout << "no" << endl;
break;
}
}else if(str[i]=='.'){
if(inkakko.size()){
cout << "no" << endl;
}else{
cout << "yes" << endl;
}
break;
}
i++;
}
}
}
|
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define M_PI 3.14159265358979
#define deg_to_rad(deg) (((deg)/360)*2*M_PI)
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
const double PI = 3.1415926535897932;
long long GCD(long long a, long long b) {
if (b == 0) return a;
else return GCD(b, a % b);
}
int main()
{
int N;
cin >> N;
string S;
cin >> S;
int ans = 1;
for (int i = 1; i < N; ++i) {
if (S[i] != S[i - 1]) {
ans += 1;
}
}
cout << ans << endl;
return 0;
}
| 0
| 65,590,391
|
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#include <bitset>
#define M 1000000007
#define M1 998244353
#define tr(container, it) \
for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
ll power(ll x, ll n)
{
ll result = 1;
while (n)
{
if (n % 2 == 1)
result = result * x;
n = n / 2;
x = x * x;
}
return result;
}
ll gcd(ll a, ll b)
{
if (!b)
return a;
return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
return (a * b) / gcd(a, b);
}
inline ll mul(ll x, ll y, ll m)
{
ll z = 1LL * x * y;
if (z >= m)
{
z %= m;
}
return z;
}
ll powmod(ll x, ll y, ll m)
{
ll r = 1;
while (y)
{
if (y & 1)
{
r = mul(r, x, m);
}
y >>= 1;
x = mul(x, x, m);
}
return r;
}
void start()
{
fast;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
int main()
{
start();
int n, m;
cin>>n>>m;
int a[n][m];
for (int i=0;i<n;i++)
{
for (int j=0;j<m;j++)
{
cin>>a[i][j];
}
}
int c=0;
for (int k=0;k<n-1;k++)
{
for (int i=k+1;i<n;i++)
{
int x=0;
for (int j=0;j<m;j++)
{
x+=pow(a[i][j]-a[k][j], 2);
}
if (sqrt(x)==floor(sqrt(x)))
{
c++;
}
}
}
cout<<c;
return 0;
}
|
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>
#include<iomanip>
#include<queue>
const long long INF = 1e6+7;
const long long MOD = 1e9+7;
const double PI=acos(-1);
using namespace std;
int main(){
string s;
cin >> s;
long long k;
cin >> k;
s+=s;
bool f=true;
for(int i=0;i<s.size()/2;i++){
if(s[i]==s[i+1])continue;
f=false;
break;
}
if(f){
long long ans=s.size()/2*k/2;
cout << ans << endl;
return 0;
}
string t;
for(int i=0;i<s.size();i++){
t+=s[i];
if(s[i]==s[i+1]){
t+='*';
i++;
}
}
long long cnt_first=0;
for(int i=0;i<t.size()/2;i++){
if(t[i]=='*')cnt_first++;
}
long long cnt_second=0;
for(int i=t.size()/2;i<t.size();i++){
if(t[i]=='*')cnt_second++;
}
long long ans=cnt_first+(k-1)*cnt_second;
cout << ans << endl;
return 0;
}
| 0
| 54,383,209
|
#include <bits/stdc++.h>
using namespace std;
int solve(const vector<vector<int>> &v_positions,
const vector<vector<int>> &h_positions, const pair<int, int> &pos) {
int pos_x = pos.first, pos_y = pos.second, ans = 0;
const vector<int> &v_pos = v_positions[pos_x], &h_pos = h_positions[pos_y];
ans +=
pos_y - *lower_bound(v_pos.rbegin(), v_pos.rend(), pos_y, greater<int>());
ans += *lower_bound(v_pos.begin(), v_pos.end(), pos_y) - pos_y;
ans +=
pos_x - *lower_bound(h_pos.rbegin(), h_pos.rend(), pos_x, greater<int>());
ans += *lower_bound(h_pos.begin(), h_pos.end(), pos_x) - pos_x;
return max(0, ans - 3);
}
int main(int argc, const char *argv[]) {
int h, w;
cin >> h >> w;
vector<vector<int>> v_positions(w), h_positions(h);
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
char ch;
cin >> ch;
if (ch == '#') {
v_positions[j].push_back(i);
h_positions[i].push_back(j);
}
}
}
for (int i = 0; i < h; ++i) {
h_positions[i].push_back(-1);
h_positions[i].push_back(w);
sort(h_positions[i].begin(), h_positions[i].end());
}
for (int i = 0; i < w; ++i) {
v_positions[i].push_back(-1);
v_positions[i].push_back(h);
sort(v_positions[i].begin(), v_positions[i].end());
}
int ans = 0;
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
ans = max(ans, solve(v_positions, h_positions, {j, i}));
}
}
cout << ans << '\n';
return 0;
}
|
#include "bits/stdc++.h"
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<VVLL> VVVLL;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
#define SORT_ASC(c) sort((c).begin(), (c).end())
#define SORT_DESC(c) sort((c).begin(), (c).end(), greater<typeof((c).begin())>())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define FORL(i,a,b) for(LL i=(a);i<(b);++i)
#define REPL(i,n) FORL(i,0,n)
#define SIZE(a) int((a).size())
#define ALL(a) (a).begin(),(a).end()
const double EPS = 1e-10;
const double PI = acos(-1.0);
template<typename T>
void vprint(vector<T> v) {
for(auto x : v) {
cerr << x << " ";
}
cerr << endl;
}
template<typename T>
void vvprint(vector<vector<T>> vv) {
REP(i, SIZE(vv)) {
REP(j, SIZE(vv[i])) {
cerr << vv[i][j] << " ";
}
cerr << endl;
}
}
template<typename T1, typename T2>
void vpprint(vector<pair<T1, T2>> vp) {
REP(i, SIZE(vp)) {
cerr << vp[i].first << ", " << vp[i].second << endl;
}
}
template<typename T1, typename T2>
void mprint(map<T1, T2> m) {
for(auto x : m) cerr << x.first << ", " << x.second << endl;
}
template <typename Iterator>
inline bool next_combination(const Iterator first, Iterator k, const Iterator last)
{
if ((first == last) || (first == k) || (last == k))
return false;
Iterator itr1 = first;
Iterator itr2 = last;
++itr1;
if (last == itr1)
return false;
itr1 = last;
--itr1;
itr1 = k;
--itr2;
while (first != itr1)
{
if (*--itr1 < *itr2)
{
Iterator j = k;
while (!(*itr1 < *j)) ++j;
iter_swap(itr1,j);
++itr1;
++j;
itr2 = k;
rotate(itr1,j,last);
while (last != j)
{
++j;
++itr2;
}
rotate(k,itr2,last);
return true;
}
}
rotate(first,k,last);
return false;
}
inline double get_time_sec(void){
return static_cast<double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count())/1000000000;
}
template<typename T>
T gcd(T a, T b) {
if(a > b) swap(a, b);
if(a == 0) return b;
else return gcd(b%a, a);
}
template<typename T>
T lcm(T a, T b) {
return (a / gcd(a, b)) * b;
}
template<typename T>
map<T, T> prime_list(T n) {
map<T, T> ret;
for(T i = 2; i*i <= n; i++) {
if(n % i == 0) {
ret[i] = 0;
while(n % i == 0) {
n /= i;
ret[i]++;
}
}
}
if(n != 1) ret[n]++;
return ret;
}
#define MOD 1000000007
LL mypow(LL a, LL n) {
if(n == 0) return 1;
if(n == 1) return a % MOD;
if(n % 2 == 1) return (a * mypow(a, n-1)) % MOD;
LL t = mypow(a, n/2);
return (t * t) % MOD;
}
#define FACT_SZ 100010
VLL _fact, _inv;
bool _fact_flg = true;
void _fact_init() {
_fact = VLL(FACT_SZ);
_inv = VLL(FACT_SZ);
_fact[0] = 1;
FOR(i, 1, FACT_SZ) _fact[i] = (_fact[i-1] * i) % MOD;
_inv[FACT_SZ-1] = mypow(_fact[FACT_SZ-1], MOD - 2);
for(int i = FACT_SZ - 2; i >= 0; i--) {
_inv[i] = ((i + 1) * _inv[i + 1]) % MOD;
}
}
LL mycomb(LL n, LL k) {
if(_fact_flg) {
_fact_flg = false;
_fact_init();
}
if(n < k) return 0;
return (((_fact[n] * _inv[k]) % MOD) * _inv[n-k]) % MOD;
}
VLL par, rnk, sz;
int root(int x) {
if(par[x] == x) return x;
else return par[x] = root(par[x]);
}
bool same(int x, int y) {
x = root(x);
y = root(y);
return x == y;
}
void unite(int x, int y) {
x = root(x);
y = root(y);
if(rnk[x] < rnk[y]) {
par[x] = y;
sz[y] += sz[x];
} else {
par[y] = x;
sz[x] += sz[y];
if(rnk[x] == rnk[y]) rnk[x]++;
}
}
#define INF 1e15
int main(void) {
string n;
LL k;
cin >> n >> k;
VVVLL dp(110, VVLL(2, VLL(4, 0)));
LL x0 = n[0] - '0';
dp[0][0][0] = 1;
dp[0][0][1] = x0 - 1;
dp[0][1][1] = 1;
FOR(i, 1, n.size()) {
LL x = n[i] - '0';
if(x != 0) {
dp[i][0][0] = dp[i-1][0][0] * 1 + dp[i-1][1][0] * 1;
dp[i][1][0] = 0;
dp[i][0][1] = dp[i-1][0][0] * 9 + dp[i-1][1][0] * (x - 1) + dp[i-1][0][1] * 1 + dp[i-1][1][1] * 1;
dp[i][1][1] = dp[i-1][1][0] * 1;
dp[i][0][2] = dp[i-1][0][1] * 9 + dp[i-1][1][1] * (x - 1) + dp[i-1][0][2] * 1 + dp[i-1][1][2] * 1;
dp[i][1][2] = dp[i-1][1][1] * 1;
dp[i][0][3] = dp[i-1][0][2] * 9 + dp[i-1][1][2] * (x - 1) + dp[i-1][0][3] * 1 + dp[i-1][1][3] * 1;
dp[i][1][3] = dp[i-1][1][2] * 1;
} else {
dp[i][0][0] = dp[i-1][0][0] * 1;
dp[i][1][0] = dp[i-1][1][0] * 1;
dp[i][0][1] = dp[i-1][0][0] * 9 + dp[i-1][0][1] * 1;
dp[i][1][1] = dp[i-1][1][1] * 1;
dp[i][0][2] = dp[i-1][0][1] * 9 + dp[i-1][0][2] * 1;
dp[i][1][2] = dp[i-1][1][2] * 1;
dp[i][0][3] = dp[i-1][0][2] * 9 + dp[i-1][0][3] * 1;
dp[i][1][3] = dp[i-1][1][3] * 1;
}
}
cout << dp[n.size()-1][0][k] + dp[n.size()-1][1][k] << endl;
}
| 0
| 86,790,843
|
#include<bits/stdc++.h>
using namespace std;
#define M_PI 3.1415926535
#define ll long long
#define ld long double
#define Summon_Tourist ios::sync_with_stdio(false);cin.tie(0);
ll gcd(ll a , ll b) { return b==0?a: gcd( b, a%b); }
ll lcm(ll a , ll b) { return a/gcd(a,b) * b ; }
ll inf = 1e9 + 7;
ll modexp( ll base ,ll power)
{
if( power == 0 ) return 1;
if( power & 1) return base*modexp( base , power-1 )%inf;
return modexp(base*base%inf,power/2);
}
ll n,k;
ll check( ll x , ll y ) { return (x<n && y<n); }
vector<pair<ll,ll > > func( ll r , ll c )
{
vector<pair<ll,ll > > temp ;
while( check(r,c) )
{
temp.push_back( make_pair(r,c) ) ;
r++;c++;
}
return temp;
}
int main()
{
Summon_Tourist
ll t = 1;
while(t--)
{
ll k,a,b;
cin>>k>>a>>b;
ll c ;
if( a%k != 0)
c = k - (a%k) ;
else c = 0 ;
if( a + c <=b ) cout<<"OK\n";
else cout<<"NG\n";
}
return 0;
}
|
#include <iostream>
#include <string>
#include <sstream>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
int main()
{
int N;
int data[251];
cin>>N;
for(int i=1;i<=N;i++){
cin>>data[i];
}
for(int i=1;i<=N;i++){
cout<<"node "<<i<<": key = "<<data[i];
if(i/2){
cout<<", parent key = "<<data[i/2];
}
if(i*2<=N){
cout<<", left key = "<<data[i*2];
}
if(i*2+1<=N){
cout<<", right key = "<<data[i*2+1];
}
cout<<", "<<endl;
}
}
| 0
| 95,265,918
|
#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() {
int n, m;
int ans = 0;
cin >> n >> m;
rep(i, n) {
ans += i;
}
rep(i, m) {
ans += i;
}
cout << ans << endl;
return 0;
}
|
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
#include <math.h>
#include <stdio.h>
using namespace std;
#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;
ll MODP = 998244353;
ll kai(ll x,ll y){
if(y == 0)return 1;
if(y == 1)return x;
if(y&1){
return (x*kai(x,y-1))%MOD;
}else{
ll t = kai(x,y/2);
return (t*t)%MOD;
}
}
ll comb(ll a,ll b,vector<ll> &p){
if(a == 0)return 1;
if(b == 0)return 1;
ll ans = p[a+b];
ans = (ans*kai(p[a],MOD-2))%MOD;
ans = (ans*kai(p[b],MOD-2))%MOD;
return ans;
}
ll mind(int x,vector<int> &v){
int ok = v.size()-1,ng = -1;
while(ok - ng > 1){
int next = (ok+ng)/2;
if(v[next] > x){
ok = next;
}else{
ng = next;
}
}
return ok;
}
ll maxd(int x,vector<int> &v){
int ok = 0,ng = v.size();
while(ng - ok > 1){
int next = (ok+ng)/2;
if(v[next] < x){
ok = next;
}else{
ng = next;
}
}
return ok;
}
int main(){
int a,b,c,k;
cin >> a >> b >> c >> k;
bool flag = false;
while(k > 0){
if(a < b){
c *= 2;
k--;
}else{
b *= 2;
k--;
}
}
if(a < b && b < c){
flag = true;
}
if(flag){
cout << "Yes" << endl;
}else{
cout << "No" << endl;
}
return 0;
}
| 0
| 70,698,839
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
void dijkstra(vector<vector<pair<long long,long long>>> &g, vector<long long> &dist, long long st){
long long INF=1e17;
long long n=g.size();
dist.assign(n,INF);
priority_queue<pair<long long,long long>,vector<pair<long long,long long>>,greater<pair<long long,long long>>> pq;
dist[st]=0;
pq.emplace(dist[st],st);
while(!pq.empty()) {
pair<long long,long long> p=pq.top();
pq.pop();
long long v=p.second;
long long d=p.first;
if(dist[v] < d) continue;
for(auto &np:g[v]) {
long long nv=np.first;
long long nd=np.second;
if(dist[nv]>dist[v]+nd){
dist[nv]=dist[v]+nd;
pq.push(make_pair(dist[nv],nv));
}
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n;
cin >> n;
vector<vector<pair<ll,ll>>> g(n);
for(ll i = 0; i < n-1; i++) {
ll a,b,c;
cin >> a >> b >> c;
a--;
b--;
g[a].emplace_back(b,c);
g[b].emplace_back(a,c);
}
ll q,k;
cin >> q >> k;
k--;
vector<ll> d(n);
dijkstra(g,d,k);
for(ll i = 0; i < q; i++) {
ll x,y;
cin >> x >> y;
x--;
y--;
ll dist=d[x]+d[y];
cout << dist << "\n";
}
return 0;
}
|
#include<vector>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<bits/stdc++.h>
#include<cstring>
#include<map>
#include<cmath>
#include<set>
using namespace std;
#define ll long long int
#define ld long double
#define MOD 1000000007
#define PI 3.1415926535897932384626433832795
#define YY cout<<"YES"
#define NN cout<<"NO"
#define EE cout<<"\n"
#define ee cout<<"\n"
#define ne cout<<"-1"
#define pb push_back
#define fi first
#define se second
#define mkp make_pair
#define mkt make_tuple
#define sall(v ) sort(v.begin(), v.end())
#define all(v ) v.begin(), v.end()
#define fo(i , n) for(ll i = 0 ; i < n ; i++)
#define vl vector<ll>
#define vc vector<char>
#define vll vector< pair<ll,ll> >
#define mps map<string ,ll>
#define mpc map<char ,ll>
#define mpl map<ll, ll>
#define pr pair<ll,ll>
#define tpl tuple<ll,ll,ll>
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b) {return (a.second < b.second); }
ll containsDigit(ll number, ll digit){while (number != 0){int curr_digit = number % 10;if (curr_digit == digit) return 1;number /= 10;}return 0;}
ll soltn(ll x, ll n) {if(x>=0) return x%n; else return n+x%n;}
ll bin_srch(ll L[], ll N,ll item){ll flag=-2;int l=0,u=N-1,m;while(l<=u) {m=(l+u)/2;if(item==L[m]) {flag=m-1; break;} else if(item>L[m]) l=m-1; else u=m+1;} return flag;}
ll pd(ll x,ll y){if(x%y==0) return x/y;else return x/y+1;}
ll coda(ll n,ll d){ll count=0;while(n!=0){if(n%10==d)count++;n/=10;}return count;}
ll minDissame(ll a[], ll n) {map<ll,ll> hmap; ll minDistance = INT_MAX; ll previousIndex = 0, currentIndex = 0; for (ll i = 0; i < n; i++) { if (hmap.find(a[i])!=hmap.end()) { currentIndex = i; previousIndex = hmap[a[i]]; minDistance = min((currentIndex - previousIndex),minDistance); }hmap[a[i]] = i; } return (minDistance == INT_MAX ? -1 : minDistance); }
ll minDistanytwo(ll arr[], ll n, ll x, ll y) {ll p = -1, min_dist = INT_MAX; for(ll i=0 ; i<n ; i++) {if(arr[i]==x || arr[i]==y) {if( p != -1 && arr[i] != arr[p]) min_dist = min(min_dist , i-p); p=i; }} if(min_dist==INT_MAX) return -1; return min_dist; }
ll mdls(ll x){return max(x,-x);}
ll pow1(ll n,ll p){if(p==0)return 1;ll x=pow1(n, p/2);x=(x*x);if(p%2==0) return x;else return (x*n);}
string fumn(string s){string p;for(ll i = 0; i < s.length(); i++)if(isalpha(s[i]))p+=toupper(s[i]);return p;}
ll turns(string S,string SS){ ll i,cc=0,l=S.length();fo(i,l){ if(S[i]!=SS[i]) cc++; } return cc/2;}
ll isSubstr(string s1, string s2) { ll M = s1.length(); ll N = s2.length(); for (ll i = 0; i <= N - M; i++) { ll j; for (j = 0; j < M; j++) if (s2[i + j] != s1[j]) break; if (j == M) return i; } return -1; }
ll hhh2(unsigned ll n) { if (n < 1) return 0; ll res = 1; ll u=0; for (ll i=0; i<8*sizeof(unsigned ll); i++) { ll curr = 1 << i; if (curr > n) break; u++; res = curr;} return u; }
ld ldgcd(ld a,ld b){ return a<0.0001?b:ldgcd(fmod(b,a),a);}
void onesol(ll a,ll b,ll& x,ll& y,ll& g) {if(!b) {g=a;x=1;y=0;} else{onesol(b,a%b,y,x,g);y-=a/b*x;}}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
ll tt=1;
while(tt--)
{
ll n,m,j,k,l,i;
cin>>n;
ll a[n];
ll b[n];
map<ll,ll> M;
ll c1=0,c2=0;
ll aa;
fo(i,n)
cin>>a[i];
for(i=0;i<n;i++)
{aa=0;
M[a[i]]=1;
for(j=0;j<a[i];j++)
{
if(M[j+1]==0)
aa++;
}
ll d=1;
for(j=0;j<n-i-1;j++)
{
d*=(j+1);
}
c1+=d*aa;
c1++;
}
mpl MM;
fo(i,n)
cin>>b[i];
for(i=0;i<n;i++)
{aa=0;
MM[b[i]]=1;
for(j=0;j<b[i];j++)
{
if(MM[j+1]==0)
aa++;
}
ll d=1;
for(j=0;j<n-i-1;j++)
{
d*=(j+1);
}
c2+=d*aa;
c2++;
}
cout<<mdls(c1-c2);
}
return 0;
}
| 0
| 97,396,646
|
#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;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
ll dist[100010];
int l[100010], r[100010];
int main(){
int h, w, d;
cin >> h >> w >> d;
vector<P> b(h * w + 1);
rep(i, h){
rep(j, w){
int a;
cin >> a;
P p;
p = make_pair(j, i);
b[a] = p;
}
}
int q;
cin >> q;
rep(i, q) cin >> l[i] >> r[i];
for(int i = 1; i <= h * w; i++){
if (i <= d) dist[i] = 0;
else dist[i] = dist[i - d] + abs(b[i].first - b[i - d].first) + abs(b[i].second - b[i - d].second);
}
rep(i, q){
cout << dist[r[i]] - dist[l[i]] << endl;
}
return 0;
}
|
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 10e16
#define MOD 1000000007
#define mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
if(a.fi!=b.fi)
return a.fi<b.fi;
else
return a.se<b.se;
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int a,b,c;cin>>a>>b>>c;
if(c>=a&&c<=b)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
return 0;
}
| 0
| 38,780,369
|
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <ctype.h>
#include <math.h>
#include <stack>
#include <string>
#include <string.h>
using namespace std;
double PI = 3.1415926535897932;
long mod = 1000000007;
const long INF = 1e9 + 1;
int main() {
string n;
cin >> n;
while(1) {
if(n[0] == n[1] & n[1] == n[2]){
cout << n << endl;
return 0;
}
else {
int t = stoi(n);
t++;
n = to_string(t);
}
}
}
|
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
using Graph = vector<vector<int>>;
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}
struct edge{ll to, cost;};
typedef pair<ll,ll> P;
struct graph{
ll V;
vector<vector<edge> > G;
vector<ll> d;
graph(ll n){
init(n);
}
void init(ll n){
V = n;
G.resize(V);
d.resize(V);
rep(i,V){
d[i] = INF;
}
}
void add_edge(ll s, ll t, ll cost){
edge e;
e.to = t, e.cost = cost;
G[s].push_back(e);
}
void dijkstra(ll s){
rep(i,V){
d[i] = INF;
}
d[s] = 0;
priority_queue<P,vector<P>, greater<P> > que;
que.push(P(0,s));
while(!que.empty()){
P p = que.top(); que.pop();
ll v = p.second;
if(d[v]<p.first) continue;
for(auto e : G[v]){
if(d[e.to]>d[v]+e.cost){
d[e.to] = d[v]+e.cost;
que.push(P(d[e.to],e.to));
}
}
}
}
};
class UnionFind
{
public:
int par[100005];
int depth[100005];
int nGroup[100005];
UnionFind(int n) {
init(n);
}
void init(int n) {
for(int i=0; i<n; i++) {
par[i] = i;
depth[i] = 0;
nGroup[i] = 1;
}
}
int root(int x) {
if(par[x] == x) {
return x;
} else {
return par[x] = root(par[x]);
}
}
bool same(int x, int y) {
return root(x) == root(y);
}
void unite(int x, int y) {
x = root(x);
y = root(y);
if(x == y) return;
if(depth[x] < depth[y]) {
par[x] = y;
nGroup[y] += nGroup[x];
nGroup[x] = 0;
} else {
par[y] = x;
nGroup[x] += nGroup[y];
nGroup[y] = 0;
if(depth[x] == depth[y])
depth[x]++;
}
}
};
int main(){
ll n,m; cin>>n>>m;
ll a = 0, b = n - 2;
ll k;
if(n%2==1){
rep(i,m)cout << i+1 << " " << n - i << endl;}
else{
rep(i,m){
if(a < b ){
cout << i+1 << " " << n - i << endl;
a+=2;
b-=2;}
else{
k = i;
break;}}
repl(i,k,m){
cout << i+1 << " " << n - i - 1 << endl;}
}}
| 0
| 82,238,294
|
#include<bits/stdc++.h>
#define fr(i,n) for (int i = 1; i <= n; i++)
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define ii pair<ll,ll>
#define vi vector<int>
#define vii vector<ii>
#define ll long long int
#define INF 1000000000
#define endl '\n'
using namespace std;
vector<int>v[2000001];
vector<int>parent(2000001,-1);
int R[2000001]={1};
ll ct=0;
int find(int a){
if(parent[a]<0)
return a;
return parent[a]=find(parent[a]);
}
void u(int a,int b){
parent[a]=-(abs(parent[a])+abs(parent[b]));
if(R[a]>=R[b]){
parent[b]=a;
R[a]+=R[b];
}
else{
parent[a]=b;
R[b]+=R[a];
}
}
int main()
{
ll n,m,a,b;
cin>>n>>m;
for(int i=1;i<=n;i++){
v[i].pb(i);
}
for(int i=1;i<=m;i++){
cin>>a>>b;
a=find(a);
b=find(b);
if(a!=b)
u(a,b);
}
int maxi=INT_MIN;
for(int i=1;i<=n;i++){
if(parent[i]<0){
maxi=max(maxi,abs(parent[i]));
}
}
cout<<maxi<<endl;
}
|
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define forE(i,x) for(int i=head[x];i!=-1;i=ne[i])
using namespace std;
typedef long long i64;
typedef unsigned long long u64;
typedef unsigned u32;
typedef pair<int,int> pin;
#define mk(a,b) make_pair(a,b)
#define lowbit(x) ((x)&(-(x)))
#define sqr(a) ((a)*(a))
#define clr(a) (memset((a),0,sizeof(a)))
#define ls ((x)<<1)
#define rs (((x)<<1)|1)
#define mid (((l)+(r))>>1)
#define pb push_back
#define w1 first
#define w2 second
inline void read(int &x){
x=0;int f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
x*=f;
}
inline void judge(){
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
}
const int maxn=200005;
int n,m;
int head[maxn],t[maxn<<1],ne[maxn<<1],num,col[maxn],size[maxn];
int sumb,numb,sumn,numn;
i64 ans=0;
inline bool dfs(int x, int fa, int c){
if(col[x]!=-1)return col[x]==c;
col[x]=c;size[x]=1;
bool res=true;
forE(i,x){
if(col[t[i]]==-1)
res&=dfs(t[i],x,c^1),size[x]+=size[t[i]];
else
res&=dfs(t[i],x,c^1);
}
return res;
}
inline void addedge(int x,int y){
ne[++num]=head[x];head[x]=num;t[num]=y;
ne[++num]=head[y];head[y]=num;t[num]=x;
}
int main(){
read(n);read(m);rep(i,1,n)head[i]=-1;
rep(i,1,m){
int x,y;
read(x);read(y);
addedge(x,y);
}
memset(col,-1,sizeof(col));
rep(i,1,n)if(col[i] == -1){
bool flag=dfs(i, 0, 0);
int sz=size[i];
if(sz>1){
if(flag)
sumb+=sz,numb+=1;
else
sumn+=sz,numn+=1;
}
}
ans=1ll*n*n;
ans-=1ll*(sumb+sumn)*(sumb+sumn);
ans+=1ll*(numb+numn)*(numb+numn);
ans+=1ll*numb*numb;
printf("%lld\n",ans);
return 0;
}
| 0
| 65,235,846
|
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
#include<map>
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const ll MOD = 1000000007;
using namespace std;
int main(){
int N, M, K; cin >> N >> M >> K;
for(int i=0; i<N+1; i++){
for(int j=0; j<M+1; j++){
if(i*j + (N-i)*(M-j) == K){
cout << "Yes";
return 0;
}
}
}
cout << "No";
}
|
#include <iostream>
#include <stdlib.h>
using namespace std;
struct Node {
int parent;
int number;
struct Node *left;
struct Node *right;
};
struct Node * N[100000];
int getDepth(struct Node *node){
int count = 0;
while (node->parent != -1) {
count++;
node = N[node->parent];
}
return count;
}
int main() {
struct Node *node1, *node2, *node3, *prev_node, *parent;
int n, m, node, parent_number, node_count, child_node;
cin >> n;
for (int i = 0; i < n; i++) {
N[i] = NULL;
}
for (int i = 0; i < n; i++) {
cin >> parent_number;
cin >> node_count;
if (N[parent_number] == NULL) {
node2 = (struct Node*)malloc(sizeof(struct Node));
node2->number = parent_number;
node2->right = NULL;
node2->left = NULL;
node2->parent = -1;
N[parent_number] = node2;
}
for (int j = 0; j < node_count; j++) {
cin >> child_node;
node1 = (struct Node*)malloc(sizeof(struct Node));
node1->number = child_node;
if (j == 0) {
N[parent_number]->left = node1;
}
else {
prev_node->right = node1;
}
node1->parent = parent_number;
prev_node = node1;
if (N[child_node] == NULL){
node1->right = NULL;
node1->left = NULL;
N[child_node] = node1;
}
N[child_node]->parent = parent_number;
}
}
for (int i = 0; i < n; i++) {
struct Node *a = N[i];
struct Node *b;
cout << "node " << i << ":";
cout << " parent = " << a->parent;
cout << ", depth = ";
cout << getDepth(a);
if (a->parent == -1) {
cout << ", root";
}
else if (a->left) {
cout << ", internal node";
}
else if (a->left == NULL) {
cout << ", leaf";
}
cout << ", [";
b = a->left;
while (b != NULL){
cout << b->number;
b = b->right;
if (b) {
cout << ", ";
}
}
cout << "]" ;
cout << endl;
}
return 0;
}
| 0
| 30,135,260
|
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
int n;
string s;
cin >> n >> s;
if(s.size() % 2 == 1) {
cout << "No" << endl;
return 0;
}
int x = s.size() / 2;
rep(i, x) {
if(s[i] != s[i + x]) {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;
#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846
#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back
int main()
{
ll N;
cin >> N;
vec t(N+1,0), x(N+1,0), y(N+1,0);
REP(i,1,N+1) cin >> t[i] >> x[i] >> y[i];
bool f = true;
REP(i,1,N+1) {
ll dt = t[i] - t[i-1];
ll d = abs(x[i]-x[i-1]) + abs(y[i]-y[i-1]);
if(dt - d >= 0 && (dt - d) % 2 == 0) continue;
else {
f = false;
break;
}
}
if(f) PR("Yes");
else PR("No");
return 0;
}
| 0
| 32,992,162
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
int main() {
int s;
cin>>s;
map<int,bool>mp;
int cnt=0;
while(0==0){
if(mp[s]==true){
break;
}
mp[s]=true;
if(s%2==0){
s/=2;
}
else{
s=(3*s)+1;
}
cnt++;
}
cout << cnt+1 << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<int,int>;
using Pll = pair<ll,ll>;
using ld=long double;
int main() {
int a,b,c;cin>>a>>b>>c;
int mx=max({a,b,c});
mx*=3;
int sum=a+b+c;
int ans=0;
while(mx>sum){
ans++;
sum+=2;
}
while(sum%3!=0){
ans++;
sum+=2;
}
cout <<ans <<endl;
}
| 0
| 48,111,557
|
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <string>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>
#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)
#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))
using namespace std;
typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;
void io_init()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
};
const int _infinity = 1000000;
int A, B, C;
VEC(int) sticks;
int cost(int have, int need)
{
if (have == 0)
return _infinity;
return abs(have - need);
}
int recurse(int i, int a, int b, int c)
{
int ret = cost(a, A) + cost(b, B) + cost(c, C);
if (i == sticks.size())
{
return ret;
}
ret = min(ret, recurse(i + 1, a, b, c));
int s = sticks[i];
ret = min(ret, (a == 0 ? 0 : 10) + recurse(i + 1, a + s, b, c));
ret = min(ret, (b == 0 ? 0 : 10) + recurse(i + 1, a, b + s, c));
ret = min(ret, (c == 0 ? 0 : 10) + recurse(i + 1, a, b, c + s));
return ret;
}
int main(int argc, char **argv)
{
io_init();
int N;
cin >> N >> A >> B >> C;
sticks.resize(N);
READVEC(sticks);
int ret = recurse(0, 0, 0, 0);
cout << ret << endl;
return 0;
};
|
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define MAX 1e18
#define MIN -1e18
#define MOD 1000000007
#define base 139
#define base2 31
#define memz(a) memset(a, 0, sizeof(a))
#define memn(a) memset(a, -1, sizeof(a))
#define in1(a) scanf("%lld", &a)
#define in2(a, b) scanf("%lld%lld", &a, &b)
#define TC(c) printf("Case #%lld: ", ++c)
#define out(x) cout << #x << " -> " << x << endl;
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FILE freopen("input.txt", "r", stdin); freopen("out.txt", "w", stdout);
using namespace std;
const ll B = 20, N = 300010, M = 2000000;
ll a, b, res = MAX;
int solve()
{
cin >> a >> b;
for (int i = 1; i <= 10000; i++)
{
if ((ll)(i * .08) == a && (ll)(i * 0.1) == b)
{
printf("%d\n", i);
return 0;
}
}
printf("-1\n");
return 0;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
return solve();
}
| 0
| 64,004,734
|
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b,c,k,sum=0;
cin>>a>>b>>c>>k;
while(k--)
{
if(a>0)
{
sum=sum+1;
a--;
}
else if(b>0)
{
sum=sum+0;
b--;
}
else if(c>0)
{
sum=sum-1;
c--;
}
}
cout<<sum<<endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define forn(i,n) for(int i=0;i<n;++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend();
#define isSubstring(s1,s2) s1.find(s2) != std::string::npos
#define pb push_back
#define pf push_front
#define mp make_pair
#define fr first
#define sc second
#define vpi <vector<pair<int,int>>
#define vi vector<int>
#define sz(a) (int)a.size()
#define endl "\n"
#define nl cout<<"\n";
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define MN INT_MIN
#define MX INT_MAX
bool isPrime(ll n){if(n<2)return false;for(ll x = 2;x*x <=n;x++){if(n%x == 0)return false;}return true;}
bool isPerfectSquare(long double x){long double sr=sqrt(x);return((sr-floor(sr))==0);}
int gcd(int a, int b){if(a==0)return b;if(b==0) return a;if(a==b)return a;if(a>b)return gcd(a-b,b);return gcd(a,b-a);}
int32_t main()
{
int n;
cin >> n;
int a[n];
for(int i = 0;i<n;i++)
cin >> a[i];
int mn = MX,cnt = 0;
for(int i = 0;i<n;i++)
{
mn = min(mn,a[i]);
if(a[i] <= mn)
{
cnt++;
}
}
cout <<cnt<<endl;
}
| 0
| 84,532,962
|
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF (1<<30)-1
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(b<a) { a=b; return 1; } return 0; }
int main(){
int n,k,s; cin >> n >> k >> s;
if(s < 1e9){
rep(i,k) cout << s << " ";
rep(i,n-k) cout << s+1 << " ";
}else{
rep(i,k) cout << s << " ";
rep(i,n-k) cout << 1 << " ";
}
cout << "\n";
return 0;
}
|
#include <set>
#include <string>
#include <iostream>
int main()
{
std::cin.tie(0);
std::ios::sync_with_stdio(false);
std::set<std::string> dic;
int n;
std::cin >> n;
for(int i = 0; i < n; ++i){
std::string command, str;
std::cin >> command >> str;
if(command[0] == 'i'){
dic.insert(str);
}else
if(command[0] == 'f'){
std::cout << (dic.find(str) != dic.end() ? "yes" : "no") << std::endl;
}
}
return 0;
}
| 0
| 38,124,803
|
#include <iostream>
#include <string>
using namespace std;
int main(){
int m;
string s;
int h;
while(1){
cin >> s;
if(s == "-") break;
cin >> m;
for(int i = 0; i < m; i++){
cin >> h;
for(int k = 0; k < h; k++){
s += s[0];
s.erase(0,1);
}
}
cout << s << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
int main(){
int n;
cin >> n;
string s[55];
int t[55];
int result = 0;
for(int i = 0; i < n; i++){
cin >> s[i] >> t[i];
}
string x;
cin >> x;
for(int i = n - 1; i >= 0; i--){
if(s[i] == x)
break;
result += t[i];
}
cout << result << endl;
}
| 0
| 61,955,556
|
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n,a=0,b=0,counter=0;
cin>>n;
vector<int>p(n),q(n),s(n);
for(int i = 0; i < n; i++) cin >> p[i];
for(int i = 0; i < n; i++) cin >> q[i];
iota(s.begin(), s.end(), 1);
do
{
if(s == p)
a = counter;
if(s == q)
b = counter;
counter++;
}while(next_permutation(s.begin(), s.end()));
cout<<abs(b-a)<<endl;
}
|
#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 ;
}
| 0
| 90,728,242
|
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;
int main() {
int n, m; cin >> n >> m;
vector<int> s(n), t(m);
REP(i, 0, n) cin >> s[i];
REP(i, 0, m) cin >> t[i];
ll dp[n + 1][m + 1] = {};
REP(i, 0, n + 1) dp[i][0] = 1;
REP(i, 0, m + 1) dp[0][i] = 1;
REP(i, 0, n) {
REP(j, 0, m) {
if (s[i] == t[j]) {
dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j]) % MOD;
}
dp[i + 1][j + 1] = ((dp[i + 1][j + 1] + dp[i + 1][j]) % MOD + dp[i][j + 1]) % MOD;
dp[i + 1][j + 1] = (MOD + dp[i + 1][j + 1] - dp[i][j]) % MOD;
}
}
cout << dp[n][m] << endl;
return 0;
}
|
#include <iostream>
#include <cmath>
using ll = long long;
using namespace std;
int n;
struct point {double x, y;};
void koch(int d, point p1, point p2){
if (d == 0) return;
point s{0,0}, t{0,0}, u{0,0};
double th = M_PI * 60.0 / 180.0;
s.x = (2.0 * p1.x + 1.0 * p2.x) / 3.0;
s.y = (2.0 * p1.y + 1.0 * p2.y) / 3.0;
t.x = (1.0 * p1.x + 2.0 * p2.x) / 3.0;
t.y = (1.0 * p1.y + 2.0 * p2.y) / 3.0;
u.x = (t.x -s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
u.y = (t.x -s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;
koch(d-1,p1 ,s);
printf("%.8f %.8f\n", s.x, s.y);
koch(d-1,s ,u);
printf("%.8f %.8f\n", u.x, u.y);
koch(d-1,u,t);
printf("%.8f %.8f\n", t.x, t.y);
koch(d-1,t,p2);
}
int main() {
cin >> n;
point s1{0, 0};
point s2{100, 0};
printf("%.8f %.8f\n", s1.x, s1.y);
koch(n,s1,s2);
printf("%.8f %.8f\n", s2.x, s2.y);
return 0;
}
| 0
| 26,613,464
|
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>
#include <bitset>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;
template<class T> inline bool chmin(T& a,T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if (a < b) {a = b; return true;} return false;}
const ll MOD = 1000000007;
const int INF = 1<<30;
int main(){
ll N, Z, W; cin >> N >> Z >> W;
vector<ll> a(N); rep(i, N) cin >> a[i];
if (N >= 2){
cout << max(abs(a[N - 1] - W), abs(a[N - 1] - a[N - 2])) << endl;
}
else cout << abs(a[0] - W) << endl;
}
|
#include<iostream>
using namespace std;
int main(){
int n;
int nn[100];
int max = 0;
for(int i=0;i<100;i++){
nn[i] = 0;
}
while(cin >> n){
nn[n-1] += 1;
if(nn[n-1] > max){
max = nn[n-1];
}
}
for(int i=0;i<100;i++){
if(nn[i] == max){
cout << i+1 << endl;
}
}
return 0;
}
| 0
| 46,284,905
|
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i < b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int INF = INT_MAX / 2;
const ll inf = LLONG_MAX / 2;
const int mod = 1000000007;
const int MAX_N = 101010;
const long double PI = acos(-1);
int MAX = 1000000000;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
ll n, k, s;
cin >> n >> k >> s;
vector<int> ans(n);
if (s == MAX) {
REP(i, 0, k) {
ans[i] = MAX;
}
REP(i, k, n) {
ans[i] = 1;
}
}
else {
REP(i, 0, k) {
ans[i] = s;
}
REP(i, k, n) {
ans[i] = MAX;
}
}
rep(i, n) {
cout << ans[i] << " ";
}
cout << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main(){
int n, m;
cin >> n >> m;
priority_queue<int> que;
vector<vector<int>> ba(100005);
rep(i,n){
int a, b;
cin >> a >> b;
ba[a].emplace_back(b);
}
int ans = 0;
for(int i = 1; i <= m; i++){
for(auto p : ba[i]) que.push(p);
if(que.empty()) continue;
int t = que.top();
que.pop();
ans += t;
}
cout << ans << endl;
}
| 0
| 59,136,215
|
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
vector<vector<int>>G;
list<int>out;
vector<bool>V;
int N;
vector<int>indeg;
void bfs(int s) {
queue<int>q;
q.push(s);
V[s] = true;
while (!q.empty()) {
int u = q.front(); q.pop();
out.push_back(u);
for (int i = 0; i < G[u].size(); i++) {
int v = G[u][i];
indeg[v]--;
if (indeg[v] == 0 && !V[v]) {
V[v] = true;
q.push(v);
}
}
}
}
void tsort() {
indeg = vector<int>(N, 0);
rep(u, 0, N) {
rep(i, 0, G[u].size()) {
int v = G[u][i];
indeg[v]++;
}
}
rep(u, 0, N) {
if (indeg[u] == 0 && !V[u])bfs(u);
}
each(it,out)cout << *it << endl;
}
signed main() {
int s, t, M;
cin >> N >> M;
V = vector<bool>(N, false); G = vector<vector<int>>(N, vector<int>());
rep(i, 0, M) {
cin >> s >> t;
G[s].push_back(t);
}
tsort();
return 0;
}
|
#include<stdio.h>
int main(){
int N, G[10];
int a[3][3], ck[3][3];
for(int i = 0 ; i < 3 ; i++ ) {
scanf("%d %d %d",&a[i][0],&a[i][1],&a[i][2]);
}
scanf("%d",&N);
for(int j = 0 ; j < N ; j++ ){
scanf("%d",&G[j]);
for(int x = 0 ; x < 3 ; x++ ) {
for(int z = 0 ; z < 3 ; z++ ){
if( G[j] == a[x][z] ) {
ck[x][z] = 1;
}
}
}
}
if( (ck[1][1] == 1 && ck[2][2] == 1 && ck[0][0] == 1 )
||(ck[2][0] == 1 && ck[1][1] == 1 && ck[0][2] == 1 )
||(ck[0][0] == 1 && ck[0][1] == 1 && ck[0][2] == 1 )
||(ck[1][0] == 1 && ck[1][1] == 1 && ck[1][2] == 1 )
||(ck[2][0] == 1 && ck[2][1] == 1 && ck[2][2] == 1 )
||(ck[0][0] == 1 && ck[1][0] == 1 && ck[2][0] == 1 )
||(ck[0][1] == 1 && ck[1][1] == 1 && ck[2][1] == 1 )
|| (ck[0][2] == 1 && ck[1][2] == 1 && ck[2][2] == 1 )
) {
printf("Yes\n");
} else {
printf("No\n");
}
return 0;
}
| 0
| 75,849,665
|
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define pb push_back
#define endl '\n'
#define snd second
#define fst first
#define fastio cin.tie(NULL),cout.sync_with_stdio(true)
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector <int> vi;
typedef pair <ll,int> ii;
typedef pair <ii,int> iii;
const int mod = 1e9 + 7;
const int N = 100005;
int v[N];
void solve(){
int n,m;
cin >> n >> m;
int total = 0, ans = 0;
for(int i = 0; i < n; i++){
cin >> v[i];
total += v[i];
}
double x = (double)total/(4.0*(double)m);
for(int i = 0; i < n; i++)
ans += (double)v[i]>=x;
cout << (ans >= m ? "Yes":"No") << "\n";
}
int main(){
fastio;
int t = 1;
while(t--)
solve();
return 0;
}
|
#include<bits/stdc++.h>
#define fastio ios::sync_with_stdio(false); cin.tie(NULL)
#define testcases freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout)
#define ui unsigned int
#define ll long long
#define pb push_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define sz(x) (int)x.size()
#define pq priority_queue
#define pqmax priority_queue<int, vector<int>, greater<int>>
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define asc(x) sort(all(x))
#define desc(x) sort(all(x), greater<int>())
#define time_el (double)time/CLOCKS_PER_SEC
using namespace std;
const int MAX=2e6;
const ll M=1e9+7, inf=1e18;
const char nl='\n';
ll apbmc(ll a, ll b, ll c){ a%=c; ll res=1; while(b){ if(b&1) res=res*a%c; a=a*a%c; b>>=1; } return res;}
ll apb(ll x, ll y){ ll temp; if(y==0) return 1; temp=apb(x, y/2); if(y%2==0) return temp*temp; else return temp*temp*x;}
struct act{
int a, b, c;
};
void solve(){
int n; cin>>n;
vvi v(n, vi(3));
for(int i=0; i<n; i++){
for(int j=0; j<3; j++){
cin>>v[i][j];
}
}
vvi dp(n, vi(3));
dp[0][0]=v[0][0];
dp[0][1]=v[0][1];
dp[0][2]=v[0][2];
for(int i=1; i<n; i++){
dp[i][0]=max(v[i][0]+dp[i-1][1], v[i][0]+dp[i-1][2]);
dp[i][1]=max(v[i][1]+dp[i-1][0], v[i][1]+dp[i-1][2]);
dp[i][2]=max(v[i][2]+dp[i-1][0], v[i][2]+dp[i-1][1]);
}
cout<<max({dp[n-1][0], dp[n-1][1], dp[n-1][2]});
}
int main(){
fastio;
cout<<fixed<<setprecision(9);
solve();
return 0;
}
| 0
| 12,078,627
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
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 ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;
int main() {
ll a, b;
string s;
cin >> a >> b >> s;
rep(i, a) {
if(s[i] < '0' || s[i] > '9') {
cout << "No" << endl;
return 0;
}
}
if (s[a] != '-' ) {
cout << "No" << endl;
return 0;
}
repI(i, a+1, a+b+1) {
if(s[i] < '0' || s[i] > '9') {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
return 0;
}
|
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
#define REP(i,n) for(ll i=0; i<(n); i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define ALL(n) begin(n),end(n)
#define IN(a, x, b) (a<=x && x<b)
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
template<class T> inline T CHMAX(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T CHMIN(T & a, const T b) { return a = (a > b) ? b : a; }
const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
const long long MOD = 1000000007;
ll numbers[100010];
int main(void){
ll n;
ll k;
cin >> n >> k;
REP(i, n){
ll a;
ll b;
cin >> a >> b;
numbers[a] += b;
}
ll i =0;
ll ans=0;
while(true){
if(numbers[i] >= k){
ans = i;
break;
}
k -= numbers[i];
i++;
}
cout << ans << endl;
return 0;
}
| 0
| 55,186,554
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
void printv(vector<ll> v) {
for (ll i : v)
cout << i << endl;
}
int main() {
string s;
cin >> s;
ll n = s.size() + 1;
vector<ll> a(n, 0);
rep(i, s.size()) {
if ((s[i] == '<') && !(a[i] < a[i + 1]))
a[i + 1] = a[i] + 1;
}
for (int i = s.size() - 1; i >= 0; i--) {
if ((s[i] == '>') && !(a[i] > a[i + 1]))
a[i] = a[i + 1] + 1;
}
ll ans=0;
rep(i,s.size()+1) ans+=a[i];
cout<<ans<<endl;
}
|
#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;
ll gcd(ll a,ll b){
if(a % b == 0)return b;
else{
return(gcd(b,a% b));
}
}
int main(){
ll n,k;
cin >> n >> k;
vector<ll> m(n);
for(int i = 0;i < n;i++){
cin >> m[i];
}
sort(m.begin(),m.end());
if(n == 1){
if(m[0] == k)cout << "POSSIBLE" << endl;
else cout << "IMPOSSIBLE" << endl;
return 0;
}
if(m[0] == k){
cout << "POSSIBLE" << endl;
return 0;
}
ll now = 0;
now = m[0];
for(int i = 1;i < n - 1;i++){
now = gcd(now,m[i]);
if(m[i] == k){
cout << "POSSIBLE" << endl;
return 0;
}
}
if(k > m[m.size() - 1] || k % now != 0){
cout << "IMPOSSIBLE" << endl;
}
else{
cout << "POSSIBLE" << endl;
}
}
| 0
| 30,369,577
|
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdint>
#include <unordered_set>
#include <unordered_map>
using namespace std;
typedef long long i64;
typedef vector<int> ivec;
typedef vector<string> svec;
struct Card {
char suit;
int value;
};
void bubblesort(struct Card A[], int N){
int flag = 1;
while(flag){
flag = 0;
for(int j = N-1; j > 0; j--){
if (A[j].value < A[j-1].value){
swap(A[j], A[j-1]);
flag = 1;
}
}
}
}
void selectionsort(struct Card A[], int N){
for(int i=0; i<N; i++){
int minj = i;
for(int j=i; j<N; j++){
if (A[j].value < A[minj].value) minj =j;
}
if(i != minj){
swap(A[i], A[minj]);
}
}
}
void presentation_card(struct Card A[], int N){
for(int i=0; i<N; i++){
if(i > 0) printf(" ");
printf("%c", A[i].suit);
printf("%d", A[i].value);
}
printf("\n");
}
int main(){
Card A1[36];
Card A2[36];
int N;
bool stable = true;
scanf("%d", &N);
for(int i = 0; i < N; i++) scanf(" %c%d", &A1[i].suit, &A1[i].value);
for(int i = 0; i < N; i++) A2[i] = A1[i];
bubblesort(A1, N);
selectionsort(A2, N);
for (int i=0; i<N; i++){
if (A1[i].suit != A2[i].suit) stable = false;
}
presentation_card(A1, N);
printf("Stable\n");
presentation_card(A2, N);
if (stable) printf("Stable\n");
else printf("Not stable\n");
return 0;
}
|
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL;
LL ll[400005],rr[400005],l[400005],r[400005];
LL stk[400005],tp = 0;
LL n,a[400005],tot = 0;
LL dp[25][400005];
LL LOG[400005];
void init(){
LOG[0] = -1;
for(LL i = 1;i <= n;i ++) LOG[i] = LOG[i >> 1] + 1;
for(LL i = 0;i <= n;i ++) dp[0][i] = a[i];
for(LL i = 1;i <= 20;i ++){
for(LL j = 0;j <= n;j ++){
if(j + (1 << (i - 1)) > n) break;
dp[i][j] = max(dp[i - 1][j],dp[i - 1][j + (1 << (i - 1))]);
}
}
}
LL query(LL x,LL y){
LL k = LOG[y - x + 1];
return max(dp[k][x],dp[k][y - (1LL << k) + 1]);
}
int main(){
cin >> n;
for(LL i = 1;i <= n;i ++) cin >> a[i];
for(LL i = 1;i <= n;i ++){
l[i] = 0;
r[i] = n + 1;
}
l[0] = 0; r[n + 1] = n + 1;
tp = 0;
for(LL i = 1;i <= n;i ++){
while(tp && a[stk[tp]] < a[i]){
r[stk[tp]] = i;
tp --;
}
stk[++ tp] = i;
}
tp = 0;
for(LL i = n;i >= 1;i --){
while(tp && a[stk[tp]] < a[i]){
l[stk[tp]] = i;
tp --;
}
stk[++ tp] = i;
}
init();
for(LL i = 1;i <= n;i ++){
LL L = 0,R = l[i] - 1,mid,tmp = 0;
while(L <= R){
mid = (L + R) >> 1;
if(query(mid,l[i] - 1) > a[i]){
tmp = mid;
L = mid + 1;
}
else R = mid - 1;
}
ll[i] = tmp;
}
for(LL i = 1;i <= n;i ++){
LL L = r[i] + 1,R = n + 1,mid,tmp = n + 1;
while(L <= R){
mid = (L + R) >> 1;
if(query(r[i] + 1,mid) > a[i]){
tmp = mid;
R = mid - 1;
}
else L = mid + 1;
}
rr[i] = tmp;
}
for(LL i = 1;i <= n;i ++){
tot += a[i] * ((rr[i] - r[i]) * (i - l[i]));
tot += a[i] * ((r[i] - i) * (l[i] - ll[i]));
}
cout << tot << endl;
return 0;
}
| 0
| 69,808,329
|
#include <bits/stdc++.h>
#define fi first
#define se second
#define MP make_pair
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 1e5 + 5;
int n;
ll a[N], p[62];
void insert(ll x) {
for(int i = 60; i >= 0; i--) {
if(x >> i & 1) {
if(!p[i]) {
p[i] = x;
break;
}
x ^= p[i];
}
}
}
int main() {
ios::sync_with_stdio(false); cin.tie(0);
cin >> n;
ll all = 0;
for(int i = 1; i <= n; i++) cin >> a[i], all ^= a[i];
for(int i = 0; i <= 60; i++) {
if(all >> i & 1) {
for(int j = 1; j <= n; j++) {
if(a[j] >> i & 1) a[j] -= (1ll << i);
}
}
}
for(int i = 1; i <= n; i++) insert(a[i]);
ll ans = 0;
for(int i = 60; i >= 0; i--) {
if((p[i]!=0)&&((ans&(1ll<<i))==0))
{
ans=p[i]^ans;
}
}
cout << ans + (ans ^ all);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long int a[45];
long long int b[45];
int main(){
long long int A,B;
cin >> A >> B;
A--;
long long int ans=0;
for(long long int i=0;i<45;i++){
if(i==0)a[0]=A%(1LL<<2);
else a[i]=A%(1LL<<(i+1));
if((1LL<<(i+1))>A)break;
}
for(long long int i=0;i<45;i++){
if(i==0)b[0]=B%(1<<2);
else b[i]=B%(1LL<<(i+1));
if((1LL<<(i+1))>B)break;
}
long long int aa,bb;
for(long long int i=0;i<45;i++){
if(i==0){
if(a[0]==1 || a[0]==2)aa=1;
else aa=0;
if(b[0]==1 || b[0]==2)bb=1;
else bb=0;
ans += (1<<0)*(aa^bb);
}
else{
if(a[i]>=(1LL<<i))aa=(a[i]-(1LL<<i)+1)%2;
else aa=0;
if(b[i]>=(1LL<<i))bb=(b[i]-(1LL<<i)+1)%2;
else bb=0;
ans += (1LL<<i)*(aa^bb);
}
}
cout << ans << endl;
}
| 0
| 58,618,512
|
#include <bits/stdc++.h>
using namespace std;
int main(){
int A,B;
cin>>A>>B;
int C=A-B;
if(C<0){
cout<<0<<endl;
}
else {
cout<<C<<endl;
}
}
|
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rep3(var, min, max) for (ll (var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll (var) = (max) - 1; (var) + 1 > (min); --(var))
#define Mp(a,b) make_pair((a),(b))
#define F first
#define S second
#define Icin(s) ll (s);cin>>(s);
#define Scin(s) ll (s);cin>>(s);
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll MOD = 1e9 + 7;
ll INF =1e18;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll x,y;
cin>>x>>y;
if(abs(x-y)<=1){
cout<<"Brown"<<endl;
}else{
cout<<"Alice"<<endl;
}
}
| 0
| 98,067,492
|
#include <bits/stdc++.h>
using namespace std;
int main()
{
string s; cin >> s;
int k; cin >> k;
for (int i = 0; i < k; i++)
{
char c = s[i];
if (c != '1')
{
cout << c << endl;
return 0;
}
}
cout << 1 << endl;
}
|
#include <iostream>
#include <stack>
using namespace std;
int main() {
int A;
int B;
int K;
cin >> A >> B >> K;
int cnt = 0;
stack<int> s;
for (int i = 1; i <= 100; i++) {
if(A % i == 0 && B % i == 0){
s.push(i);
}
}
for (int i = 0; i < K - 1; i++) {
s.pop();
}
cout << s.top() << endl;
return 0;
}
| 0
| 87,216,900
|
#include <iostream>
using namespace std;
void swap(int& x, int& y){
int tmp = x;
x=y;
y=tmp;
}
int main(){
int a, b, c;
cin >> a >> b >> c;
if(a>b) swap(a,b);
if(b>c) swap(b,c);
if(a>b) swap(a,b);
cout << a << " " << b << " " << c << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main(){
int n, k;
int64_t c=0, w;
cin >> n >> k;
priority_queue<int64_t> hs;
for(int i=0; i<n; i++){
cin >> w;
hs.push(w);
}
if (k >= n){
cout << c << '\n';
return 0;
}
n -= k;
for(int i=0; i<k; i++){
hs.pop();
}
for(int i=0; i<n; i++){
c += hs.top();
hs.pop();
}
cout << c << '\n';
return 0;
}
| 0
| 70,273,947
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)
bool sort_by(pi c, pi d){
return c.S < d.S;
}
int main() {
int n;
ll ans = 1, mod=pow(10, 9) + 7;
string s;
cin >> n >> s;
unordered_map<char, int> m;
REP(i, 0, n) ++m[s[i]];
for(auto it = m.begin(); it != m.end(); it++){
ans *= (it->S+1);
ans %= mod;
}
cout << ans-1;
}
|
#include <algorithm>
#include <iostream>
#include <vector>
#include <iomanip>
using namespace std;
struct item {
int p;
int y;
int idx;
int rank;
};
int main() {
int n, m;
cin >> n >> m;
vector<item> vec(m);
for (int i = 0; i < m; ++i) {
int p, y;
cin >> p >> y;
vec[i] = {p, y, i, 1};
}
sort(vec.begin(), vec.end(), [](auto &lhs, auto &rhs) {
return lhs.p != rhs.p ? lhs.p < rhs.p : lhs.y < rhs.y;
});
for (int i = 1; i < m; ++i)
if (vec[i - 1].p == vec[i].p)
vec[i].rank = vec[i - 1].rank + 1;
sort(vec.begin(), vec.end(),
[](auto &lhs, auto &rhs) { return lhs.idx < rhs.idx; });
for (auto &v : vec) {
cout << setfill('0') << right << setw(6) << v.p;
cout << setfill('0') << right << setw(6) << v.rank << endl;
}
}
| 0
| 91,762,235
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;
int main(){
int n,k;
cin>>n>>k;
if(n%k==0) cout<<0<<endl;
else cout<<1<<endl;
}
|
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
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;}
int main() {
int n;
cin >> n;
vector<int>a(n);
rep(i,n) cin >> a[i];
vector<int>b;
for(int i = 1;i<n;i += 2) {
b.push_back(a[i]);
}
reverse(b.begin(),b.end());
for(int i = 0;i<n; i+= 2) {
b.push_back(a[i]);
}
if(n%2 == 1) reverse(b.begin(),b.end());
rep(i,n) {
cout << b[i] << " ";
}
cout << endl;
}
| 0
| 35,139,575
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}
const ll INF = 1LL << 60;
const double pi = acos(-1.0);
int main() {
string s; cin >> s;
rep(i, (1<<3)) {
int sum = s[0] - '0';
rep(j, 3) {
if(i & (1<<j)) sum += s[j+1] - '0';
else sum -= s[j+1] - '0';
}
if(sum == 7) {
cout << s[0];
rep(j, 3) cout << (i&(1<<j) ? '+' : '-') << s[j+1];
cout << "=7" << endl;
return 0;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;
int X,Y,Z;
ll K;
ll A[1010],B[1010],C[1010];
bool solve(ll mid){
ll sum=0;
rep(i,X) rep(j,Y){
int k=lower_bound(C,C+Z+1,mid-(A[i]+B[j]))-C;
sum+=Z-k;
}
return (sum>=K);
}
void ans(ll l){
vector<ll> res;
rep(i,X) rep(j,Y){
int tmp=upper_bound(C,C+Z+1,l-(A[i]+B[j]))-C;
for(int k=tmp;k<Z;k++) res.push_back(A[i]+B[j]+C[k]);
}
int siz=res.size();
for(int i=0;i+siz<K;i++) res.push_back(l);
sort(res.rbegin(),res.rend());
for(ll r:res) cout<<r<<endl;
}
int main(){
cin>>X>>Y>>Z>>K;
rep(i,X) cin>>A[i];
rep(i,Y) cin>>B[i];
rep(i,Z) cin>>C[i];
sort(C,C+Z);
C[Z]=1e15;
ll l=0,r=1e11;
while(r-l>1){
ll mid=(l+r)/2;
if(solve(mid)) l=mid;
else r=mid;
}
ans(l);
return 0;
}
| 0
| 13,024,570
|
#include "bits/stdc++.h"
using namespace std;
void Main() {
int N, Y;
cin >> N >> Y;
for (int i = 0; i <= N; ++i) {
for (int j = 0; j <= N - i; ++j) {
int k = N - i - j;
if (k * 10000 + j * 5000 + i * 1000 == Y) {
cout << k << " " << j << " " << i << endl;
return;
}
}
}
cout << "-1 -1 -1" << endl;
}
int main() {
std::cout << std::fixed << std::setprecision(15);
Main();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v() sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
bool sortinrev(const pair<ll,ll> &a,
const pair<ll,ll> &b)
{
return (a.first > b.first);
}
int main() {
fast();
{
ll n,c=0;
cin>>n;
ll a[n];
set<ll>st;
map<ll,ll>o,e;
for(int i=0;i<n;i++)
{
cin>>a[i];
st.insert(a[i]);
}
for(int i=0;i<n;i++)
{
if(i%2==0)
{
e[a[i]]++;
}
else
{
o[a[i]]++;
}
}
vector<pair<ll,ll> >vo,ve;
for(auto t:e)
ve.pb(mp(t.se,t.fi));
for(auto t:o)
vo.pb(mp(t.se,t.fi));
sort(vo.begin(),vo.end(),sortinrev);
sort(ve.begin(),ve.end(),sortinrev);
auto it=vo.begin();
auto itt=ve.begin();
auto ttt=itt;
auto tat=it;
tat++;ttt++;
ll f=0,s=0;
if(it->se==itt->se)
{
if(it->fi>itt->fi)
{
f=it->fi;
itt++;
s=itt->fi;
}
else if(it->fi<itt->fi)
{
f=itt->fi;
it++;
s=it->fi;
}
else
{
auto its=it;
its++;
auto itts=itt;
itts++;
if(its->fi>itts->fi)
{
f=itt->fi;
s=its->fi;
}
else if (its->fi<itts->fi)
{
f=it->fi;
s=itts->fi;
}
else
{
f=it->fi;
s=itts->fi;
}
}
}
else
{
f=it->fi;
s=itt->fi;
}
{
if(st.size()==2)
{
cout<<0<<endl;
}
else if(st.size()==1)
{
cout<<n/2<<endl;}
else
{
f=max(0ll,n/2-f);
s=max(0ll,n/2-s);
cout<<(f+s)<<endl;
}
}
}
return 0;
}
| 0
| 91,775,520
|
#include <stdio.h>
#include <string.h>
int main()
{
char s[100];
int k;
scanf("%d", &k);
scanf("%s", &s);
if (k >= strlen(s)){
printf("%s", s);
}else if (k<strlen(s)){
s[k]='\0';
printf("%s...", s);
}
}
|
#include <iostream>
#include <stdio.h>
#include <vector>
#include <math.h>
#include <algorithm>
using namespace std;
int main(void){
string S; cin >> S;
int i = 0;
int a, b; a = 0; b = 0;
while (i < S.size()) {
if (i % 2 == 0) {
if (S[i] == '0') {
a++;
}
} else {
if (S[i] == '1') {
a++;
}
}
i++;
}
i = 0;
while (i < S.size()) {
if (i % 2 == 0) {
if (S[i] == '1') {
b++;
}
} else {
if (S[i] == '0') {
b++;
}
}
i++;
}
cout << min(a,b) << endl;
}
| 0
| 8,326,546
|
#include <bits/stdc++.h>
using namespace std;
long n,k,ans=0,mod=1000000007;
long modpow(long modpow_x,long modpow_y) {
long modpow_return=1;
for(long i=1;i<=modpow_y;i*=2) {
if(modpow_y/i%2==1) modpow_return=modpow_return*modpow_x%mod;
modpow_x=modpow_x*modpow_x%mod;
}
return modpow_return;
}
int main() {
cin >> n >> k;
vector<long> a(k);
for(long i=k;i>0;i--) {
a[i-1]=modpow(k/i,n);
}
for(long i=k;i>0;i--) {
for(long j=i*2;j<=k;j+=i) {
a[i-1]=(a[i-1]+mod-a[j-1])%mod;
}
ans=(ans+(a[i-1]*i))%mod;
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int N; cin >> N;
vector<int> P(N),Q(N);
for(int i=0; i<N; i++){
cin >> P.at(i);
}
for(int i=0; i<N; i++){
cin >> Q.at(i);
}
vector<int> order(N);
for(int i=0; i<N; i++){
order.at(i)=i+1;
}
int a,b;
int now=1;
do{
int cntp=1; int cntq=1;
for(int i=0; i<N; i++){
if(order.at(i)!=P.at(i)) cntp=0;
if(order.at(i)!=Q.at(i)) cntq=0;
}
if(cntp==1) a=now;
if(cntq==1) b=now;
now++;
}while(next_permutation(order.begin(),order.end()));
cout << abs(a-b) << endl;
}
| 0
| 60,429,194
|
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;
using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000, boost::int128_type>>;
typedef uintmax_t ull;
typedef intmax_t ll;
typedef uint64_t ul;
typedef uint32_t ui;
typedef uint8_t uc;
constexpr char CRLF = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;
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; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }
template<class T> inline bool isSosuu(const T& n) { if (n == T(1)) { return false; } for (T i = 2; i*i <= n; ++i) { if (n % i == 0) { return false; } } return true; }
template<class T> vector<vector<T>> split (const vector<T>& S, T delim) { vector<vector<T>> ret{}; vector<T> buff{}; for (auto c : S) { if (c == delim) { if (!buff.empty()) ret.push_back(buff); buff.clear(); } else { buff.push_back(c); } } if (!buff.empty()) ret.push_back(buff); return ret; }
template<class T> inline void printYesNo(const T& t) { cout << (t ? "Yes" : "No") << CRLF; }
template<class T = int64_t> T modpow(T N, T P, T M) { T ret{1}; N %= M; while (P) { if (P & 0x01) { ret *= N; ret %= M; } P >>= 1; N *= N; N %= M; } return ret; }
int gErr = 0;
#define ASSERT(p) if(!(p)){ gErr = 1; }else{ ; }
struct Tmp
{
public:
int N;
Tmp(int N)
: N(N)
{}
};
void solve(void)
{
string S; cin >> S;
int N = S.size();
int l = 0, r = N-1;
int res = 0;
while (l <= r) {
if (S[l] == S[r]) {
++l; --r;
continue;
}
auto p = S[l] == 'x';
auto q = S[r] == 'x';
if (!p && !q) {
cout << -1 << CRLF;
return;
}
while (p = (S[l] == 'x')) {
++l;
++res;
}
while (q = (S[r] == 'x')) {
--r;
++res;
}
}
cout << res << CRLF;
return;
}
int main(void)
{
std::ios_base::sync_with_stdio(false);
std::cin.tie(0);
solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;
int main(){
int n,v,p;
ll m;
cin>>n>>m>>v>>p;
ll a[n];
rep(i,0,n) cin>>a[i];
sort(a,a+n);
int b=0;
int c=n-p;
while(c>b){
int d=(b+c)/2;
int e=upper_bound(a,a+n,a[d]+m)-a;
if(n-e>=p){
b=d+1;
}
else{
ll cur=0;
rep(i,0,n-p+1){
cur+=min(a[d]+m-a[i],m);
}
if(cur-m<m*(v-p)){
b=d+1;
}
else{
c=d;
}
}
}
cout<<n-b<<endl;
}
| 0
| 2,799,642
|
#include <bits/stdc++.h>
using namespace std;
int x[3];
int main()
{
cin >> x[0] >> x[1] >> x[2];
sort(x, x + 3);
int cnt = 0;
int a = (x[2] - x[1]) / 2;
cnt += a;
int b = (x[2] - x[1]) % 2;
if (b % 2 != 0)
{
x[1]++;
x[0]++;
cnt++;
}
if ((x[2] - x[0]) % 2 == 0)
{
cnt += (x[2] - x[0]) / 2;
}
else
{
cnt++;
cnt += (x[2] + 1 - x[0]) / 2;
}
cout << cnt << endl;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define PH push
#define MP make_pair
#define PB push_back
#define fst first
#define snd second
#define FOR(i, x, y) for(int i = (x); i < (y); ++i)
#define REP(i, x, y) for(int i = (x); i <= (y); ++i)
#define x0 x0123456789
#define y0 y0123456789
#define x1 x1234567890
#define y1 y1234567890
#define x2 x2345678901
#define y2 y2345678901
typedef double db;
typedef long long ll;
typedef long double ldb;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int maxn = 1e5 + 5;
const ll INF = 1e12 + 7;
int n;
int par[maxn], sz[maxn];
bool used[maxn];
ll mn = INF, sum = 0;
ll d[maxn], sub[maxn], dis[maxn];
vector<pair<ll, int> > vec;
int main(){
scanf("%d", &n);
FOR(i, 0, n){
scanf("%lld", d + i);
vec.PB(MP(d[i], i));
mn = min(d[i], mn);
}
sort(vec.begin(), vec.end());
FOR(i, 0, n) sz[i] = 1;
FOR(i, 0, n) sub[i] = -INF;
memset(par, -1, sizeof(par));
for(int i = vec.size() - 1; i >= 0; --i){
int id = vec[i].snd;
if(d[id] == mn){
FOR(i, 1, vec.size()){
int u = vec[i].snd;
dis[u] = dis[par[u]] + 1;
sum += dis[u];
}
if(sum != d[id]){
puts("-1");
return 0;
}
break;
}
if(sub[id] == -INF) sub[id] = n - 2;
int pos = lower_bound(vec.begin(), vec.end(), MP(d[id] - sub[id], -1)) - vec.begin();
if(pos >= i || vec[pos].fst != d[id] - sub[id]){
puts("-1");
return 0;
}
par[id] = vec[pos].snd;
sz[par[id]] += sz[id];
sub[par[id]] = (n - sz[par[id]] - sz[par[id]]);
}
FOR(i, 0, n) if(d[i] != mn) printf("%d %d\n", i + 1, par[i] + 1);
return 0;
}
| 0
| 71,346,035
|
#include<iostream>
#include<algorithm>
int main()
{
int j1, m1, s1, e1;
std::cin >> j1 >> m1 >> s1 >> e1;
int s = j1 + m1 + s1 + e1;
int j2, m2, s2, e2;
std::cin >> j2 >> m2 >> s2 >> e2;
int t = j2 + m2 + s2 + e2;
std::cout << std::max(s, t) << std::endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;
double equal(double a, double b) {
return fabs(a - b) < DBL_EPSILON;
}
std::istream &operator>>(std::istream &in, set<int> &o) {
int a;
in >> a;
o.insert(a);
return in;
}
std::istream &operator>>(std::istream &in, queue<int> &o) {
ll a;
in >> a;
o.push(a);
return in;
}
bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }
typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;
vector<ll> gf2_rank(vector<ll> &v) {
int n = v.size();
rep(i, n) {
int x = max_element(v.begin() + i, v.end()) - v.begin();
if (v[x] == 0) break;
swap(v[i], v[x]);
ll msb = 1;
while (msb << 1 <= v[i]) msb <<= 1;
rep(j, n) if (j != i) if (v[j] & msb) v[j] ^= v[i];
}
while (v.size() && v.back() == 0) v.pop_back();
return v;
}
int main() {
int n;
cin >> n;
vector<ll> v;
vector<ll> a(n);
ll x = 0;
rep(i, n) {
cin >> a[i];
x ^= a[i];
}
rep(i, n) {
a[i] &= ~x;
v.push_back(a[i]);
}
gf2_rank(v);
ll ret = 0;
for (ll l: v) ret = max(ret, ret ^ l);
cout << ret * 2 + x << endl;
}
| 0
| 63,176,728
|
#include <cstdio>
#include <algorithm>
using namespace std;
int main(){
int n;
const int t = 86400;
while( scanf("%d",&n) , n ){
int table[t] = {};
for(int i=0 ; i<n ; ++i ){
int h1,m1,s1,h2,m2,s2,start,end;
scanf("%d:%d:%d %d:%d:%d", &h1 , &m1 , &s1 , &h2 , &m2 , &s2 );
start = s1 + m1*60 + h1*60*60 + 1;
end = s2 + m2*60 + h2*60*60;
for(int j = start ; j <= end ; ++j ){
table[j]++;
}
}
int ans = 0;
for(int i=0 ; i<t ; ++i ){
ans = max( ans , table[i] );
}
printf("%d\n", ans );
}
}
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
int main() {
string s;
cin >> s;
if(s == "zyxwvutsrqponmlkjihgfedcba"){
cout << -1 << endl;
return 0;
}
if(s.size() < 26){
vector<bool> vis(26, false);
rep(i, s.size())vis[s[i]-'a'] = true;
char c;
rep(i, 26)if(!vis[i]){
c = 'a' + i;
break;
}
cout << s + c << endl;
}else{
int idx = 0;
rep(i, s.size()-1)if(s[i] < s[i+1])idx = i;
vector<bool> vis(26, false);
rep(i, idx+1)vis[s[i]-'a'] = true;
for(char c = s[idx] + 1; c <= 'z'; c++){
if(!vis[c-'a']){
string ans = s.substr(0, idx);
cout << ans + c << endl;
return 0;
}
}
}
}
| 0
| 10,954,913
|
#include <iostream>
#include <cmath>
#include <string.h>
#include <iomanip>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <tuple>
using namespace std;
#define INF 100000000;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef long long ll;
#define eps 1.0e-14;
int main(){
int A,B,C;
cin >> A >> B >> C;
int M = max(max (A , B), C);
int ans;
if((A + B + C) % 2 == (3 * M) % 2){
ans = ((3 * M) - (A + B + C)) / 2;
}else{
ans = ((3 * (M + 1)) - (A + B + C)) / 2;
}
cout << ans << endl;
return 0;
}
|
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define LL long long
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
const int maxn = 2e5 + 7;
const int INF = 0x3f3f3f3f;
struct node {
int pos,val;
}a[maxn];
bool cmp(node aa,node bb) {
return aa.pos < bb.pos;
}
LL q[maxn];
int main() {
int n,d,x;
scanf("%d%d%d",&n,&d,&x);
for(int i = 1 ; i <= n ; i++) {
scanf("%d%d",&a[i].pos,&a[i].val);
}
d <<= 1;
sort(a+1,a+n+1,cmp);
LL ans = 0;
for(int i = 1 ; i <= n ; i++) {
q[i] += q[i-1];
a[i].val -= q[i] * x;
if(a[i].val <= 0) continue;
LL temp = (a[i].val + x - 1) / x;
ans += temp;
q[i] += temp;
int l = i , r = n;
int res = 0;
while(l <= r) {
int mid = (l + r) >> 1;
if(a[mid].pos <= a[i].pos + d) {
res = mid;
l = mid + 1;
} else {
r = mid - 1;
}
}
q[res+1] -= temp;
}
printf("%lld\n",ans);
return 0;
}
| 0
| 52,811,248
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define fin(ans) cout << (ans) << endl;
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
typedef long long ll;
typedef long long lli;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<ll> vll;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<ll, str>> vpls;
typedef vector<tuple<str, ll, ll>> vtsl;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;
void Main()
{
vc a(3); rep(i, 3) cin >> a[i];
sort(all(a));
if(a[0] == 'a'&&a[1] == 'b'&&a[2] == 'c')
fin("Yes")
else
fin("No")
}
int main()
{
cout << fixed << setprecision(20);
Main();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const int INF =1001001001;
using P = pair<int,int>;
int N, M, R;
int dist[201][201];
bool visit[8];
int ans = INF;
vector<int> r(9);
void dfs(int v, int prev, int d){
if(v == R + 1){
if(ans > d) ans = d;
return;
}
for ( int i =1; i <= R ; i ++) if (! visit [ i ])
{
visit[i]= true;
if ( prev == -1) dfs ( v +1 ,i ,0);
else dfs ( v +1 ,i , d + dist[r[prev]][r[i]]);
visit[i]= false;
}
}
int main()
{
cin >> N >> M >> R;
rep(i,R) {
cin >> r[i+1];
}
rep(i,8) visit[i] = false;
rep(i,N)rep(j,N) if(i != j)dist[i+1][j+1] = INF;
rep(i,M){
int a, b, c;
cin >> a >> b >> c;
if(dist[a][b] > c) dist[a][b] = dist[b][a] = c;
}
rep(k,N) rep(i,N) rep(j,N) dist[i+1][j+1] = min(dist[i+1][j+1], dist[i+1][k+1] + dist[k+1][j+1]);
dfs(1,-1,0);
cout << ans << endl;
}
| 0
| 71,475,591
|
#include <bits/stdc++.h>
using namespace std;
int main()
{
int a, b, ex, area, r;
scanf("%d %d", &a, &b);
area = a*b;
ex = a+b-1;
r = area-ex;
printf("%d\n", r);
return 0;
}
|
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=100050;
int main() {
int N;
cin>>N;
vll A;
ll sxor=0;
for(int i=0;i<N;i++){
ll a;
cin>>a;
A.pb(a);
sxor^=a;
}
for(int i=0;i<N;i++)
A[i]&=~sxor;
int r=0;
for(int idx=60;idx>=0;idx--){
bool flag=0;
for(int i=r;i<N;i++){
if((A[i]>>idx)&1){
swap(A[i],A[r]);
flag=1;
break;
}
}
if(flag){
for(int i=0;i<N;i++){
if(i!=r && ((A[i]>>idx)&1))
A[i]^=A[r];
}
r++;
}
}
ll ans=0;
for(int i=0;i<N;i++)
ans^=A[i];
cout<<2LL*ans+sxor<<endl;
return 0;
}
| 0
| 83,141,408
|
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
const ll mod=1000000007;
const ll inf=LONG_LONG_MAX;
ll dx4[4]={1,0,-1,0};
ll dy4[4]={0,-1,0,1};
ll dx8[8]={1,0,-1,1,-1,1,0,-1};
ll dy8[8]={1,1,1,0,0,-1,-1,-1};
int main(){
vector<vector<ll>> dp(11);
for(ll i=1;i<10;i++)dp[1].push_back(i);
for(ll i=2;i<11;i++){
for(ll j=0;j<dp[i-1].size();j++){
ll a=dp[i-1][j];
if(a%10==0){
dp[i].push_back(a*10);
dp[i].push_back(a*10+1);
}
else if(a%10==9){
dp[i].push_back(a*10+8);
dp[i].push_back(a*10+9);
}
else{
dp[i].push_back(a*10+a%10);
dp[i].push_back(a*10+a%10-1);
dp[i].push_back(a*10+a%10+1);
}
}
}
vector<long long int> b;
for(int i=1;i<11;i++){
for(int j=0;j<dp[i].size();j++){
b.push_back(dp[i][j]);
}
}
sort(b.begin(),b.end());
int d;
cin >> d ;
cout << b[d-1] << endl;
}
|
#include<bits/stdc++.h>
#define int(x) int x; scanf("%d",&x);
#define lnt(x) long long x; scanf("%lld",&x);
#define dbl(x) double x; scanf("%lf",&x);
#define str(x) string x; cin >> x;
#define fo(i,a,b) for (int i=(a);i<(b);i++)
#define rf(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define rp(i,n) for (int i=0;i<(n);i++)
#define rrp(i,n) for (int i=(n)-1;i>=0;i--)
#define inf INT_MAX/3
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pcc pair<char,char>
#define pci pair<char,int>
#define vs vector<string>
#define vi vector<int>
#define ll long long
#define in(x) cin>>x;
#define ot(x) cout<<x;
#define eot(x) cout<<x<<endl;
#define sot(x) cout<<x<<" ";
using namespace std;
int main(){
string s1="yuiophjklnm";
while(1){
str(s)
if(s=="#")break;
int c[33]={},ans=0;
rp(i,s.size()){
rp(j,s1.size()){
if(s[i]==s1[j]){
c[i]=1;
break;
}
}
}
fo(i,1,s.size()){
if((c[i]-c[i-1])!=0){
ans++;
}
}
eot(ans)
}
return 0;
}
| 0
| 23,703,002
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
ll n, a, b;
cin >> n >> a >> b;
ll ans;
if (a > b) {
ans = 0;
} else if (n == 1) {
if (a != b) {
ans = 0;
} else {
ans = 1;
}
} else {
ans = (b - a) * (n - 2) + 1;
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll ;
ll arr[5001] , score [5001] , vis[5001];
ll n , k ;
const ll OO =-1e18;
ll mx;
ll cycleLen(ll idx)
{
if(vis[idx])
return 0;
vis[idx]++;
ll cnt=cycleLen(arr[idx])+1;
return cnt;
}
ll cycleVal( ll idx , ll num , ll scsofar , ll MX)
{
if(vis[idx])
return 0;
vis[idx]++;
scsofar+=score[arr[idx]];
num++;
if(num<=MX)mx=max(mx , scsofar);
ll ans=cycleVal(arr[idx] , num , scsofar , MX)+score[arr[idx]];
return ans;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
ll n, k ;
cin >> n >>k ;
for(int i = 1 ; i <=n ;i++)
{
cin >> arr[i];
}
for(int i = 1 ; i <=n ;i++)
{
cin >> score[i];
}
ll ans=OO , len , cyc;
pair<int,int>p;
for(int i = 1 ; i <=n ; i++)
{
memset(vis , 0 , sizeof vis);
mx=OO;
len=cycleLen(i);
memset(vis , 0 , sizeof vis);
cyc=cycleVal(i , 0 , 0 , k%len );
ll x= k/len ;
ans=max(ans , cyc*(x)+mx);
memset(vis , 0 , sizeof vis);
mx=OO;
cyc=cycleVal(i , 0 , 0 , min(k,len) );
ans=max(ans , cyc*max(x-1 , (long long)0)+mx);
ans=max(ans , mx);
}
cout << ans ;
return 0;
}
| 0
| 35,133,993
|
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <cassert>
#include <random>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long int ll;
const ll INF = 10000000000;
const double PI = acos(-1);
const ll mod = 1000000007;
int main()
{
int n, m;
cin >> n >> m;
vector<vector<int>> to(n);
rep(i, m) {
int a, b;
cin >> a >> b;
a--;
b--;
to[a].push_back(b);
to[b].push_back(a);
}
for (auto i : to[0]) {
for (auto j : to[i]) {
if (j == n - 1) {
cout << "POSSIBLE" << endl;
return 0;
}
}
}
cout << "IMPOSSIBLE" << endl;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s , t;
cin>>s>>t;
bool equal = false;
for(int i=0;i<s.length();i++)
{
if( s== t)
{
equal = true;
break;
}
s = s.back() + s.substr(0,s.length()-1 );
}
if( equal)
cout<<"Yes";
else cout<<"No";
}
| 0
| 23,094,707
|
# include "bits/stdc++.h"
using namespace std;
#define endl "\n"
typedef long long int ll;
#define f first
#define s second
inline void fastio(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
inline void setPrecision(int n){cout.precision(n);}
#define BR cerr<<endl
#define dbg(x) cerr<<(#x)<<": "<<x<<endl
#define dbgV(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<it<<" "; cerr<<endl;
#define dbgS(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<it<<" "; cerr<<endl;
#define dbgM(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<"["<<it.f<<", "<<it.s<<"] "; cerr<<endl;
#define dbg2D(x) cerr<<(#x)<<": \n"; for(auto y: x) { for(auto it: y) cerr<<it<<" "; cerr<<endl; } cerr<<endl;
#define dbgA(x, n) cerr<<(#x)<<": "; for(int i=0;i<n;++i) cerr<<x[i]<<" "; cerr<<endl;
#define dbgVP(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<"["<<it.f<<", "<<it.s<<"] "; cerr<<endl;
ll INF = 1e10;
int MOD = 1e9+7;
int main(){
#ifndef ONLINE_JUDGE
freopen("inputf.in", "r", stdin);
#endif
fastio();
ll a, b, k;
cin >> a >> b >> k;
ll p, q;
if(k <= a){
p = a - k;
q = b;
}
else{
p = 0;
k -= a;
if(k <= b){
q = b - k;
}
else{
q = 0;
}
}
cout << p << " " << q;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;
using pll=pair<ll,ll>;
#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define MOD 1000000007
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int main() {
char a;
cin >> a;
if(a < 'a') cout << 'A' << endl;
else cout << 'a' << endl;
return 0;
}
| 0
| 45,152,969
|
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define rep(i, n) FOR(i, 0, n - 1)
using namespace std;
typedef long long ll;
template <class T> inline bool dpmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool dpmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
void solve(long long N, vector<long long> d) {
sort(d.begin(), d.end());
ll center = d.size() / 2;
ll ans = 0;
if (N%2 == 0) {
ans = d[center] - d[center-1];
}
cout << ans << endl;
}
int main() {
long long N;
cin >> N;
vector<long long> d(N);
for (int i = 0; i < N; i++) {
cin >> d[i];
}
solve(N, move(d));
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define ve vector
int ans,n;
int a[3];
void dfs(ve<int> &l, string s){
if(s.size() == n){
ve<int> l0(4,0),cnt(4,0);
rep(i,n){
l0[s[i]-'0'] += l[i];
cnt[s[i]-'0']++;
}
rep(i,3)if(cnt[i] == 0) return;
int memo = 0;
rep(i,3) {
memo += 10 * (cnt[i]-1);
memo += abs(a[i]-l0[i]);
}
ans = min(ans,memo);
return;
}
dfs(l,s+'0');
dfs(l,s+'1');
dfs(l,s+'2');
dfs(l,s+'3');
return;
}
int main(){
cin >> n >> a[0] >> a[1] >> a[2];
ve<int> l(n);
rep(i,n) cin >> l[i];
ans = 1e9;
dfs(l,"");
cout << ans << endl;
return 0;
}
| 0
| 88,631,785
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
int main() {
int n, k;
cin >> n >> k;
vector<pair<ll, ll>> x(n);
rep(i, n)cin >> x[i].first >> x[i].second;
sort(x.begin(), x.end());
ll ans = 4001001001001001001;
rep(i, n-1)for(int j = i+1; j < n; j++){
if(j-i+1 < k)continue;
vector<ll> yy;
for(int l = i; l <= j; l++)yy.push_back(x[l].second);
sort(yy.begin(), yy.end());
ll dy = 2002002002;
rep(l, yy.size()-k+1)dy = min(dy, yy[l+k-1]-yy[l]);
ans = min(ans, dy * (x[j].first-x[i].first));
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main()
{
int N;
cin >> N;
vector<int> A(N), B(N);
for (int i = 0; i < N; i++)
{
cin >> A[i] >> B[i];
}
long long Ans = 0;
for (int i = 0; i < N; i++)
{
int j = N - i - 1;
if ((A[j] + Ans) % B[j] != 0)
Ans += B[j] - ((A[j] + Ans) % B[j]);
}
cout << Ans << endl;
}
| 0
| 10,088,129
|
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define fore(i,a) for(auto &i:a)
const double EPS = 1e-10;
const double PI = acos(-1.0);
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
LL gcd(LL a, LL b){
if(b == 0) return a;
return gcd(b,a%b);
}
LL lcm(LL a, LL b){
LL g = gcd(a,b);
return a/g *b;
}
int main(){
LL N;
cin >> N;
LL a[N];
REP(i,N) cin >> a[i];
LL sum=0;
REP(i,N) sum+=a[i];
LL ans=10000000000;
LL tmp=0;
LL res=0;
for(int i=0;i<N;++i){
tmp+=a[i];
res=sum-tmp;
if(i+1<N)
ans=min(ans,abs(res-tmp));
}
cout << ans << endl;
}
|
#include<bits/stdc++.h>
using namespace std;
int n,sum,a[100005];
int main(){
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i];
a[0]=0,a[n+1]=0;
for(int i=1;i<=n+1;i++) sum+=abs(a[i]-a[i-1]);
for(int i=1;i<=n;i++)
{
int t1=abs(a[i+1]-a[i]);
int t2=abs(a[i]-a[i-1]);
int t3=abs(a[i+1]-a[i-1]);
cout<<sum-t1-t2+t3<<endl;
}
return 0;
}
| 0
| 6,255,086
|
#include <bits/stdc++.h>
using namespace std;
int main(){
string S, T;
cin >> S >> T;
vector<int> check((int)S.size(), 0);
int count = 0;
for (int i=0; i<S.size() - T.size()+1; i++){
for (int j=0; j<T.size(); j++){
if (S.at(i+j) == T.at(j)) count++;
}
check.at(i) = count;
count = 0;
}
sort(check.begin(), check.end(), greater<int>());
cout << (int)T.size() - check.at(0) << endl;
}
|
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
bool isPalindrome(string s) {
int upper,lower,len;
len=s.length();
if(len==1) {
return true;
}
if(len%2==0) {
lower=(len/2)-1;
upper=lower+1;
}
else {
int mid=len/2;
lower=mid-1;
upper=mid+1;
}
while(s[lower]==s[upper]&&lower>0&&upper<len) {
upper++;
lower--;
}
if(upper==len-1&&lower==0&&(s[upper]==s[lower])) {
return true;
}
else {
return false;
}
}
int main() {
fast_io;
string s;
cin>>s;
int len=s.length();
int pt1=((len-1)/2);
int pt2=((len+3)/2)-1;
if(isPalindrome(s)&&isPalindrome(s.substr(0,pt1))&&isPalindrome(s.substr(pt2, len-pt2))) {
cout<<"Yes"<<endl;
}
else {
cout<<"No"<<endl;
}
}
| 0
| 40,067,272
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.