code_file1
stringlengths 87
4k
| code_file2
stringlengths 82
4k
|
---|---|
#include<bits/stdc++.h>
using namespace std;
inline int read(){
int res=0;
char c;
bool zf=0;
while(((c=getchar())<'0'||c>'9')&&c!= '-');
if(c=='-')zf=1;
else res=c-'0';
while((c=getchar())>='0'&&c<='9')res=(res<<3)+(res<<1)+c-'0';
if(zf)return -res;
return res;
}
const int maxn=505;
int c[maxn][maxn];
int a[maxn],b[maxn];
signed main(){
int n=read();
for(register int i=1;i<=n;++i){
for(register int j=1;j<=n;++j){
c[i][j]=read();
}
}
int p=0;
for(register int i=1;i<=n;++i){
if(!p||c[i][1]<c[p][1]){
p=i;
}
}
for(register int i=1;i<=n;++i){
a[i]=c[i][1]-c[p][1];
}
for(register int i=1;i<=n;++i){
b[i]=c[i][i]-a[i];
}
for(register int i=1;i<=n;++i){
if(a[i]<0||b[i]<0){
puts("No");
return 0;
}
}
for(register int i=1;i<=n;++i){
for(register int j=1;j<=n;++j){
if(a[i]+b[j]!=c[i][j]){
puts("No");
return 0;
}
}
}
puts("Yes");
for(register int i=1;i<=n;++i){
printf("%d ",a[i]);
}
puts("");
for(register int i=1;i<=n;++i){
printf("%d ",b[i]);
}
puts("");
return 0;
} | #include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<iomanip>
#include<queue>
#include<cmath>
#include<stack>
#include<map>
#define ll long long
#define skip cin>>ws;
#define vll vector<ll>
#define vb vector<bool>
#define vpll vector<pair<ll,ll>>
#define vi vector<int>
#define vpi vector<pair<int, int>>
#define vvll vector<vector<ll>>
#define vvi vector<vector<int>>
#define vvvll vector<vector<vector<ll>>>
#define pll pair<ll,ll>
#define vs vector<string>
#define vvpll vector<vector<pair<ll, ll>>>
#define vvpi vector<vector<pair<int, int>>>
#define pb push_back
#define pob pop_back()
#define MOD (ll)(1e9 + 7)
#define MOD2 (ll)(998244353)
#define INF (ll)(1e18 + 5)
#define count1(n) __builtin_popcountll(n)
#define test ll t; cin>>t; while(t--)
#define all(x) begin(x), end(x)
using namespace std;
void inline show(vll &a){for(ll e: a){if(e == INF) cout<<"INF ";else cout<<e<<" ";}cout<<"\n";}
void inline show(vi &a){for(int e: a){if(e == MOD) cout<<"MOD ";else cout<<e<<" ";}cout<<"\n";}
template<typename T> void enter(vector<T> &a){ for(T &e: a) cin>>e; }
ll inline mo(ll a){ return a%MOD;}
ll inline po(ll x, ll y, ll p)
{
ll res = 1; x = x % p;
while (y > 0) { if (y & 1) res = (res * x) % p; y >>= 1; x = (x * x) % p; }
return res%p;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
vll a(3);
enter(a);
sort(all(a));
if(a[0] == a[1]) cout<<a[2]<<"\n";
else if(a[2] == a[1]) cout<<a[0]<<"\n";
else cout<<0<<"\n";
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;
const ll mod = 1e9+7;
const ll N = 1e5+2;
//My tools
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repe(i,s,e) for(ll i=s;i<=e;i++)
#define all(v) (v).begin(),(v).end()
ll merge(int a[],int l,int r,int mid){
int p,q,k=0;
ll inv = 0;
p = l,q = mid+1;
int temp[r-l+1];
for(int i=l;i<=r;i++){
if(p>mid) temp[k++] = a[q++];
else if(q>r) temp[k++] = a[p++];
else if(a[p]<=a[q]) temp[k++] = a[p++];
else if(a[p]>a[q]){
inv+= (mid - p +1);
temp[k++] = a[q++];
}
}
for(int i=0;i<k;i++){
a[l++] = temp[i];
}
return inv;
}
ll mergesort(int a[],int l,int r){
ll inv = 0;
if(r>l){
int mid = (l + r)/2;
inv+= mergesort(a,l,mid);
inv+= mergesort(a,mid+1,r);
inv+= merge(a,l,r,mid);
}
return inv;
}
main(){
int n;cin>>n;
int a[n],b[n];
rep(i,0,n){
cin>>a[i];
b[i] = a[i];
}
ll inv = mergesort(a,0,n-1);
cout<<inv<<"\n";
rep(i,0,n-1){
inv+= (n - 2*b[i] - 1);
cout<<inv<<"\n";
}
} | #include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL_
void debug_out() {cerr << endl;}
template<typename Head,typename... Tail> void debug_out(Head H,Tail... T){cerr << ' ' << H; debug_out(T...);}
#define debug(...) cerr << 'L' << __LINE__ << " [" << #__VA_ARGS__ << "]:",debug_out(__VA_ARGS__)
#define dump(x) cerr << 'L' << __LINE__ << " " << #x << " = " << (x) << endl;
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif
#define rep(i,n) for (int i = 0; i < (int)(n); i ++)
#define irep(i,n) for (int i = (int)(n) - 1;i >= 0;--i)
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;// = 998244353;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int N; cin >> N;
vector<ll> A(N);
rep(i,N) cin >> A[i];
vector<ll> B(N+1,0);
rep(i,N) B[i+1] = B[i] + A[i];
ll ans = 0;
ll ret = 0;
ll bfmax = 0;
rep(i,N) {
bfmax = max(bfmax,B[i+1]);
ans = max(ans,ret + bfmax);
ret += B[i+1];
}
cout << ans << '\n';
return 0;
} |
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<set>
#include<queue>
#include<stack>
#include<math.h>
#include<time.h>
#include<deque>
#include<cstring>
#define ll long long
#define DB double
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define pf push_front
#define MOD (ll)(998244353)
#define INF (ll)(1e9)
#define M 5000005
#define endl "\n"
#define AC ios::sync_with_stdio(0);cin.tie(0);
using namespace std;
template<class T> using PQ=priority_queue<T,vector<T>,greater<T> >;
int e[20],dp[(1<<19)];
signed main(){
AC;
int n,m;
cin>>n>>m;
FOR(i,0,m){
int a,b;
cin>>a>>b;
a--; b--;
e[a]|=(1<<b);
e[b]|=(1<<a);
}
FOR(i,0,(1<<n)) dp[i]=INF;
dp[0]=1;
FOR(i,0,n)FOR(j,0,(1<<n)){
if(dp[j]==1&&(e[i]&j)==j) dp[j|(1<<i)]=1;
}
FOR(i,1,(1<<n))for(int j=i-1;j&=i;j--){
dp[i]=min(dp[i],dp[i^j]+dp[j]);
}
cout<<dp[(1<<n)-1]<<endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = false;
//---------------------------------//
int main() {
int N, M, K;
cin >> N >> M >> K;
vector<int> A(K);
REP(i, K) cin >> A[i];
vector<bool> inA(N);
for (int a : A) inA[a] = true;
{
int p = 0;
while (p < N) {
bool update = false;
for (int i = M; i >= 1; --i) {
if (p + i < N && inA[p + i]) continue;
update = true;
p += i;
break;
}
if (!update) { puts("-1"); return 0; }
}
}
vector<double> dp0(N + 1), dp(N + 1);
double s0 = 0, s = 0;
for (int i = N - 1; i >= 0; --i) {
if (i + M + 1 <= N) { s0 -= dp0[i + M + 1] / M; s -= dp[i + M + 1] / M; }
if (inA[i]) { dp0[i] = 1; dp[i] = 0; }
else { dp0[i] = s0; dp[i] = s + 1; }
s0 += dp0[i] / M;
s += dp[i] / M;
}
double ans = dp[0] / (1 - dp0[0]);
printf("%.16f\n", ans);
} |
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define fz(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
#define ffe(it,v) for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)
#define fill0(a) memset(a,0,sizeof(a))
#define fill1(a) memset(a,-1,sizeof(a))
#define fillbig(a) memset(a,63,sizeof(a))
#define pb push_back
#define ppb pop_back
#define mp make_pair
template<typename T1,typename T2> void chkmin(T1 &x,T2 y){if(x>y) x=y;}
template<typename T1,typename T2> void chkmax(T1 &x,T2 y){if(x<y) x=y;}
typedef pair<int,int> pii;
typedef long long ll;
template<typename T> void read(T &x){
x=0;char c=getchar();T neg=1;
while(!isdigit(c)){if(c=='-') neg=-1;c=getchar();}
while(isdigit(c)) x=x*10+c-'0',c=getchar();
x*=neg;
}
const int MAXN=1e5;
int n,hd[MAXN+5],to[MAXN+5],nxt[MAXN+5],ec=0,dp[MAXN+5],siz[MAXN+5];
void adde(int u,int v){to[++ec]=v;nxt[ec]=hd[u];hd[u]=ec;}
void dfs(int x){
dp[x]=siz[x]=1;int cnt=0;
for(int e=hd[x];e;e=nxt[e]){
int y=to[e];dfs(y);
if(siz[y]&1) cnt++;
siz[x]+=siz[y];
} vector<int> v;
for(int e=hd[x];e;e=nxt[e]){
int y=to[e];
if(!(siz[y]&1)&&dp[y]<=0) dp[x]+=dp[y];
else if(!(siz[y]&1)){
if(!(cnt&1)) dp[x]+=dp[y];
else dp[x]-=dp[y];
}
else v.pb(dp[y]);
}
sort(v.begin(),v.end());
for(int i=0,t=1;i<v.size();i++,t=-t) dp[x]+=t*v[i];
// printf("%d %d\n",x,dp[x]);
}
int main(){
scanf("%d",&n);
for(int i=2;i<=n;i++){
int f;scanf("%d",&f);adde(f,i);
} dfs(1);printf("%d\n",(n+dp[1])/2);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, k, n) for(ll i = ll(k); i <= ll(n); i++)
#define all(v) (v).begin(), (v).end()
const char newl = '\n';
vl S;
vvl G;
void dfs(ll v) {
S[v] = 1;
for(ll u: G[v]) {
dfs(u);
S[v] += S[u];
}
}
ll cnt(ll v) {
ll income = -1;
vvl vec(3);
for(ll u: G[v]) {
ll num = cnt(u);
if(S[u] & 1) vec[0].push_back(num);
else if(num >= 0) vec[1].push_back(num);
else vec[2].push_back(num);
}
sort(all(vec[0]), greater<ll>());
bool f = 0;
for(ll num: vec[0]) income += ((f = 1-f) ? 1 : -1) * num;
for(ll num: vec[1]) income += num;
for(ll num: vec[2]) income += ((vec[0].size() & 1) ? -1 : 1) * num;
return income;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
ll n, p;
cin >> n;
S = vl(n);
G = vvl(n);
rep2(i, 1, n-1) {
cin >> p;
p--;
G[p].push_back(i);
}
dfs(0);
cout << (n-cnt(0))/2 << newl;
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
if(n%2==1)cout<<"Black";
else cout<<"White";
} | #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--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)
#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>
#define MOD 1000000007
#define INF 1000000000000000LL
using namespace std;
int main(){
int n;cin>>n;
if(n%2==0)cout<<"White"<<endl;
else cout<<"Black"<<endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define int long long int
#define ld long double
#define pb push_back
#define MOD 1000000007
#define inf 3e18
#define vi vector<int>
#define vld vector<ld>
#define pii pair<int,int>
#define mii map<int,int>
#define fi first
#define se second
#define fastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define db(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << " "<< name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> pbds;
//order_of_key (k) : Number of items strictly smaller than k .
//find_by_order(k) : K-th element in a set (counting from zero) (returns an iterator)
void inp_out()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
freopen("debug.txt", "w", stderr);
#endif
}
bool isPalindrome(string s)
{
int i,j;
for(i=0,j=s.length()-1;i<=j;i++,j--)
if(s[i]!=s[j])
return 0;
return 1;
}
int32_t main()
{
fastIO
inp_out();
int r, x, y;
cin >> r >> x >> y;
ld val = sqrt((ld)(x * x + y * y));
if(val < r)
val = 2;
else
val = ceil(val / r);
cout << val;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using ll = long long;
using vl = vector<long long>;
using vi = vector<int>;
int main(){
ll r,x,y; cin >> r >> x >> y;
ll l = x*x + y*y;
int ans;
for(ll ix=1;;ix++){
if(l < r*r){
ans = 2;
break;
}
else if(l <= ix*ix*r*r){
ans = ix;
break;
}
}
cout << ans << endl;
} |
#include<bits/stdc++.h>
using namespace std;
int n;
int h[1000001];
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int a,b,c;
cin>>a>>b>>c;
if(a==b||c==0)
{
cout<<"=";
return 0;
}
if(c%2)
{
if(a>b)
{
cout<<">";
return 0;
}
else
{
cout<<"<";
return 0;
}
}
else
{
a=abs(a);
b=abs(b);
if(a==b)
{
cout<<"=";
return 0;
}
if(a>b)
{
cout<<">";
return 0;
}
else
{
cout<<"<";
return 0;
}
}
}
| #include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
const int N = 2000 + 5, mod = 1e9 + 7;
ll a, b, c, d;
bool check1(int a, int b, int c, int d){
if(a + b == c + d) return 1;
if(a - b == c - d) return 1;
if(abs(a - c) + abs(b - d) <= 3) return 1;
return 0;
}
bool check2(ll a, ll b, ll c, ll d){
for(int i = a - 3; i <= a + 3; i++){
for(int j = b - 3; j <= b + 3 ; j++){
if(abs(i - a) + abs(j - b) > 3) continue;
if(check1(i, j, c, d)) return 1;
}
}
return 0;
}
int main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> a >> b >> c >> d;
if(a == c && b == d) cout << 0;
else if(check1(a, b, c, d)) cout << 1;
else if(((a + b + c - d) & 1) == 0) cout << 2;
else if(((c + d + a - b) & 1) == 0) cout << 2;
else if(check2(a, b, c, d)) cout << 2;
else cout << 3;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long N, A, m, b = 0, c = 0;
cin >> N;
m = N;
while (m) {
m--;
cin >> A;
b += A;
c += A * A;
}
cout << N * c - b * b << endl;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define len(a) (int)a.size()
#define all(a) a.begin(), a.end()
const int INF32 = 1 << 30;
const long long INF64 = 1LL << 60;
const double PI = acos(-1);
int main() {
string N;
cin >> N;
int n = len(N);
int p = 2;
ll ans = 0;
while (1) {
if (p > n) {
break;
}
else if (p < n) {
ans += pow(10, p / 2) - pow(10, p / 2 - 1);
}
else {
ll i1 = stoll(N.substr(0, p / 2));
ll i2 = stoll(N.substr(p / 2));
ll i0 = pow(10, p / 2 - 1);
ans += i1 - i0;
if (i2 >= i1) ans++;
}
p += 2;
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)
template<class T1, class T2> inline bool chmax(T1 &a, const T2 &b) {if (a<b) { a=b; return 1;} return 0;}
template<class T1, class T2> inline bool chmin(T1 &a, const T2 &b) {if (b<a) { a=b; return 1;} return 0;}
struct init{init(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);cerr<<fixed<<setprecision(15);}}init_;
#ifdef DEBUG
template <class T> void verr(const set<T> &st) { repa(a, st) cerr << a << " "; cerr << endl; }
template <class S, class T> void verr(const map<S, T> &mp) { repa(a, mp) cerr << "{" << a.first << ", " << a.second << "} "; cerr << endl; }
template <class S, class T, class N> void verr(const vector<pair<S,T>>& a, const N& n) { rep(i, n) cerr << "{" << a[i].first << ", " << a[i].second << "} "; cerr << endl; }
template <class T, class N> void verr(const vector<T>& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << endl; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << endl; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif
const ll INF = 4e18;
const ld EPS = 1e-5;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
int main() {
ll N;
cin >> N;
vc<complex<ld>> S(N), T(N);
rep(i, N) {
ld a, b;
cin >> a >> b;
S[i] = {a, b};
}
rep(i, N) {
ld a, b;
cin >> a >> b;
T[i] = {a, b};
}
complex<ld> sc(0, 0), tc(0, 0);
rep(i, N) sc += S[i], tc += T[i];
sc /= N, tc /= N;
rep(i, N){
S[i] -= sc;
T[i] -= tc;
}
rep(i, N) rep(j, N){
vc<complex<ld>> ss(N), tt(N);
rep(si, N) ss[si] = S[si] * polar(1.0L, -arg(S[i]));
rep(ti, N) tt[ti] = T[ti] * polar(1.0L, -arg(T[j]));
bool ok = true;
rep(si, N) {
bool isok = false;
rep(ti, N){
if (abs(ss[si] - tt[ti]) < EPS) isok = true;
}
if(!isok){
ok = false;
break;
}
}
if(ok){
cout << "Yes" << endl;
return 0;
}
}
cout << "No" << endl;
} |
/**
* Coded by : lucky_21
* --------Lokesh Singh
**/
#include<bits/stdc++.h>
using namespace std;
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
#define F first
#define S second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define vi vector<int>
#define all(x) x.begin(),x.end()
#define fix fixed<<setprecision(10)
#define rep(i,a,b) for(int i=int(a);i<=int(b);i++)
#define repb(i,b,a) for(int i=int(b);i>=int(a);i--)
#define FastIO ios_base::sync_with_stdio(0),cin.tie(0)
typedef double db;
typedef long long ll;
const int N=2e5+5;
const int mod=1e9+7;
vi p;
ll mini=1e18;
int n,x[N];
void rec(int i,ll pr){
if(i==p.size()){
int ok=1;
rep(j,1,n) if(__gcd(pr,1ll*x[j])==1){
ok=0;
break;
}
if(ok) mini=min(mini,pr);
return;
}
rec(i+1,pr);
rec(i+1,pr*p[i]);
}
signed main(){
FastIO;
rep(j,2,50){
int ok=1;
rep(i,2,j-1) if(j%i==0) ok=0;
if(ok) p.pb(j);
}
cin>>n;
rep(i,1,n) cin>>x[i];
rec(0,1);
cout<<mini;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define MS(a, b) memset(a, b, sizeof(a))
#define REP(a, b, c) for (register int a = b, _n = c; a <= _n; ++a)
#define DREP(a, b, c) for (register int a = b, _n = c; a >= _n; --a)
#define FOR(a, b, c) for (register int a = b, _n = c; a < _n; ++a)
#define EREP(a, b) for (register int a = head[b]; a; a = edge[a].nxt)
#define ll long long
inline int rd () {
int x = 0; char c = getchar(); bool f = 0;
while (c < '0' && c != '-') c = getchar();
if (c == '-') f = 1, c = getchar();
while (c >= '0') x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
return f ? -x : x;
}
const int SIZE = 2e5 + 100;
int n;
int a[SIZE], b[SIZE];
int x[SIZE], y[SIZE];
struct cmp1 {
bool operator () (const int& x1, const int& x2) const {
if (a[x1] == a[x2]) return x1 < x2;
return a[x1] < a[x2];
}
};
struct cmp2 {
bool operator () (const int& x1, const int& x2) const {
if (b[x1] == b[x2]) return x1 < x2;
return b[x1] < b[x2];
}
};
int sum[SIZE];
void Add (int x) {
while (x <= n) {
++sum[x];
x += x & -x;
}
}
int Sum (int x) {
int res = 0;
while (x) {
res += sum[x];
x -= x & -x;
}
return res;
}
void _main () {
n = rd();
REP (i, 1, n) a[i] = rd() + i, x[i] = i;
REP (i, 1, n) b[i] = rd() + i, y[i] = i;
sort(x + 1, x + n + 1, cmp1());
sort(y + 1, y + n + 1, cmp2());
bool flag = 1;
ll ans = 0;
REP (i, 1, n) {
if (a[x[i]] != b[y[i]]) flag = 0;
a[x[i]] = y[i];
}
DREP (i, n, 1) {
ans += Sum(a[i]);
Add(a[i]);
}
if (flag) printf ("%lld\n", ans);
else puts("-1");
}
int main () {
#ifdef LOCAL
freopen("in.txt", "r", stdin);
#endif
_main();
return 0;
}
| #pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
#define DEBUG
#ifdef DEBUG
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 << '{';
for(int i = 0; i < (int)v.size(); i++) {
if(i) { os << ','; }
os << v[i];
}
os << '}';
return os;
}
void debugg() { cerr << endl; }
template <class T, class... Args>
void debugg(const T &x, const Args &... args) {
cerr << " " << x;
debugg(args...);
}
#define debug(...) \
cerr << __LINE__ << " [" << #__VA_ARGS__ << "]: ", debugg(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = (1<<30)-1;
const ll linf = 1LL<<61;
const int MAX = 510000;
int dy[8] = {0,1,0,-1,1,-1,-1,1};
int dx[8] = {-1,0,1,0,1,-1,1,-1};
const double pi = acos(-1);
const double eps = 1e-9;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
if(a>b){
a = b; return true;
}
else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
if(a<b){
a = b; return true;
}
else return false;
}
template<typename T> inline void print(T &a){
int sz = a.size();
for(auto itr = a.begin(); itr != a.end(); itr++){
cout << *itr;
sz--;
if(sz) cout << " ";
}
cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){
cout << a << " " << b << "\n";
}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
cout << a << " " << b << " " << c << "\n";
}
void mark() {cout << "#" << "\n";}
ll pcount(ll x) {return __builtin_popcountll(x);}
//const int mod = 1e9 + 7;
const int mod = 998244353;
template<typename T> struct BIT{
vector<T> dat;
ll sz;
//all 1-indexed
BIT(ll sz) : sz(sz){
dat.assign(++sz, 0);
}
T sum(ll k){
T ret = 0;
for(++k; k > 0; k -= k & -k) ret += dat[k];
return (ret);
}
void add(ll k, T x){
for(++k; k < dat.size(); k += k & -k) dat[k] += x;
}
ll get(T k){
if(k <= 0) return 0;
ll ret = 0;
int n = 1; while(n < sz) n *= 2;
for(int i=n/2; i>0; i/=2){
if(ret+i < sz && dat[ret+i] < k){
k -= dat[ret+i];
ret += i;
}
}
return ret;
}
};
int main(){
int n; cin >> n;
map<int,vector<int>> mp;
vl a(n);
rep(i,n){
int b; cin >> b;
b += i;
mp[b].push_back(i);
}
rep(i,n){
cin >> a[i];
a[i] += i;
}
for(auto &x : mp) reverse(all(x.second));
ll ans = 0;
BIT<ll> bit(n+1);
//8 6 6 10 8 10
//10 6 8 10 8 6
rep(i,n){
if(mp[a[i]].empty()){
ans = -1;
break;
}
ll ba = mp[a[i]].back();
mp[a[i]].pop_back();
ans += max(0LL, ba-i + bit.sum(n) - bit.sum(ba));
//debug(ba,ans,a[i],i,bit.sum(n)-bit.sum(i));
bit.add(ba,1);
}
cout << ans << endl;
//4 6 8 6 5
//5 8 6 6 4
//5 4 6 8 6
//5 8 4 6 6
//5 8 6 4 6
//5 8 6 6 4
} |
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
// your code goes here
int n;
cin >> n;
string s[n];
int a[n],b[n];
for(int i=0;i<n;i++){
cin >> s[i] >> a[i];
b[i]=a[i];
}
sort(a,a+n);
for(int i=0;i<n;i++){
if(b[i]==a[n-2]){
cout << s[i] << endl;
}
}
return 0;
} | #include<bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int mx = -1;
int prev = -1;
map<int, string> m;
while(n--) {
string s;
int temp;
cin >> s ;
cin >> temp;
m[temp] = s;
if(mx<temp){
prev = mx;
mx = temp;
}
else if(temp < mx && temp > prev)
prev = temp;
}
cout << m[prev];
return 0;
}
|
#include<iostream>
using namespace std;
int main()
{
long long int n,d,h,i,j,k,a[200],b[200];
double s=0;
cin>>n>>d>>h;
for(i=0;i<n;i++)
{
cin>>a[i]>>b[i];
double x=d-a[i];
double y=h-b[i];
double m=y/x;
double k=m*(-1)*d+h;
s=max(s,k);
}
if(s==0)cout<<"0.0"<<endl;
else
printf("%.13lf\n",s);
}
| #include<stdio.h>
#define rep(i,N) for(int i=0;i<(int)N;i++)
const int MOD=1e9+7;
static long IN(void)
{
long x=0,f=1,c=getchar();while(c<48||c>57){if(c==45){f=-f;}c=getchar();}
while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f*x;
}
static void OUT(int x){if(x<0){putchar('-'),x=-x;}if(x>=10){OUT(x/10);}putchar(x-x/10*10+48);}
int Nx[1000000],Ls[200001],To[1000000],pos=1;long pow2[61],b[61][2],dat[1000000];
static void Set(int x,int y,long z){Nx[++pos]=Ls[x];Ls[x]=pos;To[pos]=y;dat[pos]=z;}
static void DG(int x,int fa,long w)
{
rep(i,61){b[i][(w&pow2[i])>0?1:0]++;}
for(int i=Ls[x];i;i=Nx[i]){int y=To[i];if(y==fa){continue;}DG(y,x,w^dat[i]);}
}
int main(void)
{
int N=IN(),x=0,y=0,a=0;long z=0;pow2[0]=1l;
rep(i,60){pow2[i+1]=2*pow2[i];}N--;
while(N--){x=IN(),y=IN(),z=IN();Set(x,y,z);Set(y,x,z);}
DG(1,0,0);
rep(i,61)
{
z=pow2[i]-pow2[i]/MOD*MOD;z=z*b[i][0]-z*b[i][0]/MOD*MOD;
z=z*b[i][1]-z*b[i][1]/MOD*MOD;z+=a;if(z+1l>1l*MOD){z-=MOD;}a=z;
}
OUT(a);
} |
#include <bits/stdc++.h>
#define clog(x) std::clog << (#x) << " is " << (x) << '\n';
using LL = long long;
constexpr int M = 1e9 + 7;
int main() {
//freopen("in", "r", stdin);
std::cin.tie(nullptr)->sync_with_stdio(false);
int n;
std::cin >> n;
std::vector<LL> a(n + 1);
for (int i = 1; i <= n; ++i) {
std::cin >> a[i];
a[i] += a[i - 1];
}
auto add = [&](int &x, int y) {
x += y;
if (x >= M) x -= M;
};
std::vector<std::vector<int>> dp(n + 1, std::vector<int>(n + 2));
dp[0][1] = 1;
int ans = 0;
for (int i = 1; i <= n; ++i) {
for (int j = n; j >= 1; --j) {
add(dp[a[i] % (j + 1)][j + 1], dp[a[i] % j][j]);
if (i == n) {
add(ans, dp[a[n] % j][j]);
}
}
}
std::cout << ans << '\n';
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------
int N;
vector<ll> A[3];
string C[201010];
void solve() {
int i,j,k,l,r,x,y; string s;
cin>>N;
FOR(i,2*N) {
ll B;
cin>>B>>s;
if(s=="R") A[0].push_back(B);
if(s=="G") A[1].push_back(B);
if(s=="B") A[2].push_back(B);
}
sort(ALL(A[0]));
sort(ALL(A[1]));
sort(ALL(A[2]));
if(A[0].size()%2) {
if(A[1].size()%2==0) swap(A[0],A[1]);
else swap(A[0],A[2]);
}
if(A[1].size()%2==0) {
cout<<0<<endl;
return;
}
ll mi=1LL<<60;
FORR(a,A[1]) {
x=lower_bound(ALL(A[2]),a)-A[2].begin();
if(x<A[2].size()) mi=min(mi,abs(A[2][x]-a));
x--;
if(x>=0) mi=min(mi,abs(A[2][x]-a));
}
ll mia=1LL<<60,mib=1LL<<60;
FORR(a,A[1]) {
x=lower_bound(ALL(A[0]),a)-A[0].begin();
if(x<A[0].size()) mia=min(mia,abs(A[0][x]-a));
x--;
if(x>=0) mia=min(mia,abs(A[0][x]-a));
}
FORR(a,A[2]) {
x=lower_bound(ALL(A[0]),a)-A[0].begin();
if(x<A[0].size()) mib=min(mib,abs(A[0][x]-a));
x--;
if(x>=0) mib=min(mib,abs(A[0][x]-a));
}
// cout<<mia<<" "<<mib<<"\n";
cout<<min(mi,mia+mib)<<endl;
}
int main(int argc,char** argv){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
string s;int i;
if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
cout.tie(0); solve(); return 0;
}
|
#include <cstdio>
#include <algorithm>
using namespace std;
int a[400005];
int f[400005];
pair<int,int> p[400005];
int c[3];
int main()
{
int n;
scanf("%d",&n);
for(int i=1;i<=2*n;i++)
scanf("%d",&a[i]);
for(int i=1;i<=2*n;i++)
p[i]=make_pair(a[i],i);
sort(p+1,p+2*n+1);
for(int i=1;i<=2*n;i++)
if(i<=n)
f[p[i].second]=1;
else f[p[i].second]=2;
for(int i=1;i<=2*n;i++)
if(!c[3-f[i]])
{
printf("(");
c[f[i]]++;
}
else
{
printf(")");
c[3-f[i]]--;
}
printf("\n");
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
long long int tab[200007];
int main()
{
long long int i, n, k=0, w=0;
cin >> n;
for(i=0; i<n; i++){
cin >> tab[i];
tab[i]%=200;
}
sort(tab, tab+n);
for(i=1; i<n; i++){
if(tab[i]==tab[i-1]){
k++;
}
else{
k=0;
}
w+=k;
}
cout << w << '\n';
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pll;
#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)
const ll MOD = 1000000007;
const ll INF = (ll) 1e15;
struct vec3 {
ll x;
ll y;
ll z;
};
ll S[20][1LL << 18];
ll cost(vec3 from, vec3 to) {
ll ret = abs(to.x - from.x) + abs(to.y - from.y) + std::max(0LL, to.z - from.z);
return ret;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll N;
cin >> N;
vector<vec3> v(N);
REP(i, N) {
cin >> v[i].x >> v[i].y >> v[i].z;
}
ll p = pow(2LL, N);
REP(i, N) {
REP(j, p) {
S[i][j] = INF;
}
}
S[0][1] = 0;
REP(i, p) {
REP(j, N) {
if (((i >> j) & 1) == 0)
continue;
ll b = (i & (~(1LL << j)));
REP(k, N) {
if (((b >> k) & 1) == 0)
continue;
ll cst = cost(v[k], v[j]) + S[k][b];
S[j][i] = std::min(S[j][i], cst);
}
}
}
ll ans = INF;
REP(i, N) {
ans = std::min(ans, S[i][p - 1] + cost(v[i], v[0]));
}
cout << ans << endl;
return 0;
} | #include<bits/stdc++.h>
#define pb push_back
#define eb emplace_back
using namespace std;
//#define DEBUG
#ifdef DEBUG
template<typename ...Args>
int debug(const Args &...args){
return fprintf(stderr,args...);
}
#else
#define debug(...) void()
#endif
typedef unsigned long long ull;
typedef unsigned uint;
typedef long long ll;
#define G getchar()
int read()
{
int x=0; bool flg=false; char ch=G;
for (;!isdigit(ch);ch=G) if (ch=='-') flg=true;
for (;isdigit(ch);ch=G) x=(x<<3)+(x<<1)+(ch^48);
return flg?-x:x;
}
#undef G
#define fi first
#define se second
const int mod=998244353;
inline int upd(const int &x){return x+(x>>31&mod);}
inline void add(int &x,const int &y){x=upd(x+y-mod);}
inline void iadd(int &x,const int &y){x=upd(x-y);}
int qpow(int x,int y){
int res=1;
for (;y;y>>=1,x=1LL*x*x%mod)
if (y&1) res=1LL*res*x%mod;
return res;
}
//typedef pair<int,int> P;
#define rep(i,l,r) for (int i(l),_##i(r);i<=_##i;i++)
#define per(i,l,r) for (int i(r),_##i(l);i>=_##i;i--)
#define all(x) (x).begin(),(x).end()
#define forall(x,y) for (const int &y: e[x])
int n,w[110];
int dp[110][10010];
void solve(){
n=read(); int S=0;
rep(i,1,n) w[i]=read(),S+=w[i];
if (S&1) return puts("0"),void();
auto F=dp;
F[0][0]=1;
rep(_,1,n){
const int &W=w[_];
per(i,0,n){
rep(j,0,n*100){
if (i<n&&j+W<=n*100);
else continue;
add(F[i+1][j+W],F[i][j]);
}
}
}
static int fac[110];
fac[0]=1; rep(i,1,n) fac[i]=1LL*fac[i-1]*i%mod;
int z=0;
rep(i,0,n) add(z,1LL*F[i][S>>1]*fac[i]%mod*fac[n-i]%mod);
printf("%d\n",z);
}
int main()
{
for (int T=1;T--;) solve();
return 0;
} |
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;
const int N = 210, M = 810;
int h[N], e[M], ne[M], w[M], idx;
int a, b, x, y;
bool st[N];
int d[N];
void add(int a, int b, int c) {
e[idx] = b, w[idx] = c, ne[idx] = h[a], h[a] = idx ++ ;
}
void spfa(int a) {
memset(d, 0x3f, sizeof d);
queue<int> q;
q.push(a);
st[a] = true;
d[a] = 0;
while (q.size()) {
int t = q.front();
q.pop();
st[t] = false;
for (int i = h[t]; ~i; i = ne[i]) {
int j = e[i];
if (d[j] > d[t] + w[i]) {
d[j] = d[t] + w[i];
if (!st[j]) {
q.push(j);
st[j] = true;
}
}
}
}
}
int main() {
cin >> a >> b >> x >> y;
memset(h, -1, sizeof h);
int n = 100;
for (int i = 1; i < n; i++) add(i, i + 1, y), add(i + 1, i, y);
for (int i = 1 + n; i < n + n; i++) add(i, i + 1, y), add(i + 1, i, y);
for (int i = 1; i <= n; i++) add(i, i + n, x), add(i + n, i, x);
for (int i = 2; i <= n; i++) add(i, i + n - 1, x), add(i + n - 1, i, x);
spfa(a);
cout << d[b + n] << endl;
return 0;
} | //! 尺卂乃卂.卂フ乇乇ㄒ
#include<bits/stdc++.h>
//#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
//Using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> Ordered_set;
#define ll long long
#define int long long
#define ld long double
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<vi>
#define vip vector<pii>
#define mii map<int,int>
#define mip map<pair<int,int>,int>
#define mic map<char,int>
#define all(v) v.begin(),v.end()
#define pqb priority_queue<int>
#define pqs priority_queue<int,vi,greater<int> >
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define lb(x) (x&(-x))
#define mod 1000000007
#define inf 1e18
#define ps(x,y) fixed<<setprecision(y)<<x
#define w(x) int x; cin>>x; while(x--)
#define itr(it,v) for(auto it:v)
#define show(arr,n) for(int i=0;i<n;i++) cout<<arr[i]<<" "; cout<<"\n";
#define fi(i,n) for(int i=0;i<n;i++)
#define fir(i,k,n) for(int i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ff first
#define ss second
#define deb(x) cout << #x << "=" << x << endl
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define check(x) (x && cout<<"Yes\n")||(cout<<"No\n");
#define fin(s) freopen(s,"r",stdin);
#define fout(s) freopen(s,"w",stdout);
const ld pi = 3.141592653589793238462643383279502884;
const int xd[]={-1,0,1,0};
const int yd[]={0,-1,0,1};
int XX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int YY[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
int expo(int a,int b,int m);
int mmi(int a,int m);
void ipgraph(int m);
const int N=5*(1e5)+10;
vii adj(N);
int a[N];
void solve(){
}
int32_t main()
{
FIO
int a,b,c;
cin>>a>>b>>c;
if((a*a+b*b)<(c*c)) cout<<"Yes\n";
else cout<<"No\n";
return 0;
}
void ipgraph(int m){
int i, u, v;
while(m--){
cin>>u>>v;
u--, v--;
adj[u].pb(v);
adj[v].pb(u);
}
}
int expo(int a,int b,int m){
if(b==0) return 1;
if(b==1) return a;
int val=(expo(a,b/2,m)*expo(a,b/2,m))%m;
if(b & 1) return (val*a)%m;
else return val;
}
int mmi(int a,int m){
return expo(a,m-2,m);
} |
#include <iostream>
using namespace std;
int main(void) {
int x;
cin >> x;
if (x < 0) cout << 0 << endl;
else cout << x << endl;
return 0;
} | #include <bits/stdc++.h>
#pragma GCC optimize("-Ofast")
#pragma GCC optimize("-O1")
using namespace std;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin>>n;
n=floor(n*1.08);
if(n<206)cout<<"Yay!";
else if(n==206)cout<<"so-so";
else cout<<":(";
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int x ,y ;
cin >> x >> y ;
if (x != y){
if (x < y){
if (x+3 > y){
cout<< "Yes"<<endl;
} else if (x+3 <= y){
cout << "No" <<endl;
}
}
else if(y < x){
if (y+3 > x){
cout<< "Yes"<<endl;
} else if (y+3 <= x){
cout << "No" <<endl;
}
}
}
} | #include<bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)
int main(){
int X,Y; cin>>X>>Y;
if(abs(X-Y)<=2) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
return 0;
}
|
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define Mp make_pair
#define e "\n"
#define fl(x,n) for(ll i=x;i<=n;i++)
#define fl2(x,n) for(ll i=x;i>=n;i--)
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
template<class X>
void temfunc(const X a)
{
for(auto it=a.begin();it!=a.end();it++)
cout << *it << " ";
cout << e;
}
int main()
{
FIO;
int a,b,c;
cin >> a >> b >> c;
if(c-b==b-a||c-a==a-b||a-c==c-b||b-c==c-a||a-b==b-c||b-a==a-c)
cout << "Yes\n";
else
{
cout << "No\n";
}
return 0;
}
| #include<bits/stdc++.h>
#include<unordered_map>
#define sz(s) (int)s.size()
#define all(s) s.begin(),s.end()
using namespace std;
typedef long long ll;
void fast(){
std::ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
}
void Men7a()
{
double r, x, y,d;
int ans;
cin >> r >> x >> y;
d = sqrt((x*x)+(y*y));
if (d - int(d))
d++;
ans = int(d) / int(r);
if(int(d) % int(r))
ans++;
if(d!=r && ans==1)
ans++;
cout << ans << "\n";
}
int main()
{
fast();
int test_case = 1;
//freopen("","r",stdin);
//cin >> test_case;
while (test_case--)
Men7a();
} |
#define DEBUG 0
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i, begin, end) for(int i = int(begin); i < int(end); i++)
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<class T>using numr=std::numeric_limits<T>;
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; }
const int INF = 1e9;
const ll LLINF = 1e16;
const int mod = 1000000007;
const int mod2 = 998244353;
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#if DEBUG
#define debug(...)\
do {\
std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
debug_impl(__VA_ARGS__);\
std::cerr << std::noboolalpha;\
} while (false)
#else
#define debug(...) {}
#endif
template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
{ for (auto & x : v) { is >> x; } return is; }
template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
os << "{";
for (auto it = v.begin(); it != v.end(); it++)
{os << (it != v.begin() ? "," : "") << *it;}
return os << "}";
}
int main() {
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
int n;
cin >> n;
vector<ll> a(n);
cin >> a;
ll best = 0;
ll now = 0,sum = 0,mx = 0;
for(int i = 0;i<n;i++){
sum += a[i];
chmax(mx,sum);
chmax(best,now + mx);
now += sum;
}
cout << best << endl;
} | #include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <utility>
#include <string>
#include <fstream>
#include <map>
#include <set>
#include <queue>
#include <memory.h>
using namespace std;
typedef vector<int> VI;
typedef pair<int, int> PI;
typedef vector<PI> VPI;
#define FOR(i,a,n) for (int i = (a); i < (n); ++i)
#define FORE(i,a,n) for (int i = (a); i <= (n); ++i)
#define FORD(i,a,b) for (int i = (a); i >= (b); --i)
#define REP(i,n) FOR(i,0,n)
#define REPE(i,n) FORE(i,0,n)
#define LL long long
#define FIR(n) REP(i,n)
#define FJR(n) REP(j,n)
#define ALL(v) v.begin(), v.end()
#define FI FIR(n)
#define FJ FJR(n)
#define FR(i,a) FOR(i,a,n)
#define REPN(i) REP(i,n)
#define GI(n) scanf("%d", &n)
#define GI2(n,m) scanf("%d %d", &n, &m)
const int MOD = 1e9 + 7;
LL a[3010];
int f[3010];
LL fn[3010];
int main() {
#ifdef LOCALF
freopen("input.txt", "rt", stdin);
#endif
ios::sync_with_stdio(false); cin.tie(0);
int n;
cin >> n;
FI cin >> a[i];
//n = 3000; FI a[i] = 4LL * 3 * 5 * 7 * 11 * 13 * 17 * 19*23*29*31*37;
FI f[i] = 1;
LL res = 0;
res = f[n - 1];
map<int, LL> sums;
FORE(d, 2, n) {
memset(fn, 0, sizeof fn);
sums.clear();
LL s = 0;
FI{
s += a[i];
fn[i] += sums[s % d];
(sums[s % d] += f[i]) %= MOD;
}
FI f[i] = fn[i] % MOD;
res += f[n - 1];
}
cout << res % MOD << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
const int mod = 1e9 + 7;
int add (int x, int y) {return x + y >= mod ? x + y - mod : x + y;}
int mul (int x, int y) {return 1LL * x * y % mod;}
int sub (int x, int y) {return x - y < 0 ? x - y + mod : x - y;}
int n, a[maxn];
int f[maxn][2], g[maxn][2];
int main ()
{
scanf ("%d", &n);
for (int i = 1; i <= n; i++) scanf ("%d", a + i);
f[1][0] = a[1];
g[1][0] = 1;
for (int i = 2; i <= n; i++)
{
g[i][0] = add (g[i - 1][1], g[i - 1][0]);
g[i][1] = g[i - 1][0];
f[i][0] = add (f[i - 1][1], f[i - 1][0]);
f[i][0] = add (f[i][0], mul (g[i][0], a[i]));
f[i][1] = sub (f[i - 1][0], mul (g[i][1], a[i]));
}
int ans = add (f[n][0], f[n][1]);
printf ("%d\n", ans);
}
| #include <bits/stdc++.h>
const int N = 200005;
int n, a[N * 2], b[N * 2], ok[N * 2], st[N], top = 0;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n * 2; i++)
scanf("%d", &a[i]), b[i] = i;
std::sort(b + 1, b + n * 2 + 1, [](int x, int y) { return a[x] < a[y]; });
for (int i = 1; i <= n; i++) ok[b[i]] = 1;
for (int i = 1; i <= n * 2; i++) {
char c;
if (!top) st[++top] = i, c = '(';
else if (ok[st[top]] ^ ok[i]) top--, c = ')';
else st[++top] = i, c = '(';
putchar(c);
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldbl;
typedef pair<int, int> pii;
typedef pair<uint, uint> puu;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<uint> vu;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pii> vpii;
typedef vector<puu> vpuu;
typedef vector<pll> vpll;
typedef vector<pull> vpull;
typedef vector<string> vstr;
typedef vector<double> vdbl;
typedef vector<ldbl> vldbl;
#define pb push_back
#define ppb pop_back
#define pfr push_front
#define ppfr pop_front
#define emp emplace
#define empb emplace_back
#define be begin
#define rbe rbegin
#define all(x) (x).be(), (x).end()
#define rall(x) (x).rbe(), (x).rend()
#define fir first
#define sec second
#define mkp make_pair
#define brif(cond) if (cond) break
#define ctif(cond) if (cond) continue
#define retif(cond) if (cond) return
void canhazfast() {ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);}
template<typename T> T gcd(T a, T b) {return b ? gcd(b, a%b) : a;}
template<typename T> T extgcd(T a, T b, T &x, T &y)
{
T x0 = 1, y0 = 0, x1 = 0, y1 = 1;
while (b) {
T q = a/b; a %= b; swap(a, b);
x0 -= q*x1; swap(x0, x1);
y0 -= q*y1; swap(y0, y1);
}
x = x0; y = y0; return a;
}
int ctz(uint x) {return __builtin_ctz(x);}
int ctzll(ull x) {return __builtin_ctzll(x);}
int clz(uint x) {return __builtin_clz(x);}
int clzll(ull x) {return __builtin_clzll(x);}
int popcnt(uint x) {return __builtin_popcount(x);}
int popcntll(ull x) {return __builtin_popcountll(x);}
int bsr(uint x) {return 31^clz(x);}
int bsrll(ull x) {return 63^clzll(x);}
#define N 100032
char dir[N];
int a[N], b[N];
ll calc(int i, int j, int e)
{
//cerr << "calc, e = " << e << '\n';
//cerr << " a = ["; for (int k = i; k < j; ++k) cerr << ' ' << a[k]; cerr << " ]\n";
//cerr << " b = ["; for (int k = i; k < j; ++k) cerr << ' ' << b[k]; cerr << " ]\n";
ll res = 0;
set<int> x;
for (int k = i; k < j; ++k) {
x.erase(a[k]);
x.insert(b[k]);
res += x.size();
}
if (x.size() > 1 || b[j-1] != e) res = -1;
//cerr << " res = " << res << '\n';
return res;
}
void flip(int x[], int i, int j)
{
reverse(x+i, x+j);
for (int k = i; k < j; ++k) x[k] = -x[k];
}
int main()
{
canhazfast();
int n, w;
ll ans = 0;
cin >> n >> w;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
a[i] -= i;
}
for (int i = 1; i <= n; ++i) {
cin >> b[i];
b[i] -= i;
}
//cerr << "shifted:\n";
//cerr << "a = ["; for (int i = 1; i <= n; ++i) cerr << ' ' << a[i]; cerr << " ]\n";
//cerr << "b = ["; for (int i = 1; i <= n; ++i) cerr << ' ' << b[i]; cerr << " ]\n";
a[n+1] = b[n+1] = w-n;
for (int i = 1; i <= n; ++i) {
dir[i] = '-';
if (a[i] < b[i]) dir[i] = 'R';
if (a[i] > b[i]) dir[i] = 'L';
}
//cerr << "dir = " << dir+1 << '\n';
for (int i = 1; i < n; ++i) {
retif(dir[i] == 'R' && dir[i+1] == 'L') cout << "-1\n", 0;
}
for (int i = 1, j = 1; i <= n; i = j) {
while (j <= n && dir[j] == dir[i]) ++j;
ctif(dir[i] == '-');
int e = a[j];
if (dir[i] == 'L') {
flip(a, i, j);
flip(b, i, j);
e = -a[i-1];
}
ll res = calc(i, j, e);
retif(res < 0) cout << "-1\n", 0;
ans += res;
}
cout << ans << '\n';
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<string> vs;
typedef vector<double> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<vp> vvp;
// input
int N, Q;
vl A;
void input() {
cin >> N >> Q;
A = vl(N);
rep(i, N) cin >> A[i];
}
struct SegmentTree {
int n;
vector<int> left, right;
vector<ll> dat;
SegmentTree(int n_) {
n = 1;
while (n < n_) n *= 2;
left = right = vector<int>(2 * n - 1);
dat = vector<ll>(2 * n - 1, 0);
set_range(0, 0, n);
}
void set_range(int i, int l, int r) {
left[i] = l;
right[i] = r;
if (i < n - 1) {
set_range(2 * i + 1, l, (l + r) / 2);
set_range(2 * i + 2, (l + r) / 2, r);
}
}
void add(int i, ll x) {
i += n - 1;
dat[i] ^= x;
while (i > 0) {
i = (i - 1) / 2;
dat[i] ^= x;
}
}
ll sum_recur(int i, int l, int r) {
if (left[i] == l && right[i] == r) return dat[i];
int c = (left[i] + right[i]) / 2;
ll ret = 0;
if (l < c) ret ^= sum_recur(2 * i + 1, l, min(c, r));
if (c < r) ret ^= sum_recur(2 * i + 2, max(c, l), r);
return ret;
}
ll sum(int l, int r) {
return sum_recur(0, l, r);
}
};
int main() {
input();
SegmentTree st(N);
rep(i, N) st.add(i, A[i]);
rep(i, Q) {
int t, x, y;
cin >> t >> x >> y;
if (t == 1) {
st.add(x - 1, y);
} else {
ll ans = st.sum(x - 1, y);
cout << ans << endl;
}
}
}
|
#include <iostream>
using namespace std;
int main()
{
int N;
cin >> N;
int A[N];
int i = 0;
int max_num = 2;
while (i != N)
{
scanf("%d", &A[i]);
if (max_num < A[i])
{
max_num = A[i];
}
i++;
if (i != N)
{
scanf(" ");
}
}
int ans = -1;
int counter = 0;
int max_counter = 0;
for (int k = 2; k <= max_num; k++)
{
for (i = 0; i < N; i++)
{
if (A[i] % k == 0)
{
counter++;
}
}
if (max_counter <= counter)
{
max_counter = counter;
ans = k;
}
counter = 0;
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define int long long
const int maxn=200005;
inline int read() {
register int r=0,f=1;
register char ch=getchar();
while(ch<'0' || ch>'9') {
if(ch=='-') f=-1;
ch=getchar();
}
while(ch>='0' && ch<='9') {
r=(r<<1)+(r<<3)+(ch^48);
ch=getchar();
}
return r*f;
}
int n;
int a[maxn];
int tong[maxn],tot;
int ans;
int fa[maxn];
struct nod{
int x,y;
nod(){}
nod(int a,int b) {x=a,y=b;}
}edge[maxn];
int find(int x) {
return fa[x]==x ? x : fa[x]=find(fa[x]);
}
void merge(int x,int y) {
fa[find(x)]=find(y);
return;
}
inline void k() {
for(int i=1;i<=tot;++i) {
int x=edge[i].x,y=edge[i].y;
int fx=find(x);
int fy=find(y);
if(fx!=fy) {
merge(fx,fy);
++ans;
}
}
cout<<ans<<endl;
return;
}
signed main()
{
n=read();
for(int i=1;i<=n;++i) a[i]=read();
for(int i=0;i<maxn;++i) fa[i]=i;
for(int i=1;i<=n+1-i;++i)
if(a[i]!=a[n+1-i]) edge[++tot]=nod(a[i],a[n+1-i]);
k();
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define prin(a) cout<<a<<"\n"
#define kaigyo cout<<"\n"
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define mem(x) memset(x,0,sizeof(x))
#define mem1(x) memset(x,-1,sizeof(x))
const int INF=1<<28;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<string> vst;
typedef vector<char> vc;
typedef vector<long double> vd;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
typedef vector<vector<int>> vint2;
ll mod=1e9+7;
#define int1(x) int x;cin>>x;
#define int2(x,y) int x,y;cin>>x>>y;
#define int3(x,y,z) int x,y,z;cin>>x>>y>>z;
#define int4(x,y,z,w) int x,y,z,w;cin>>x>>y>>z>>w;
#define ll1(x) ll x;cin>>x;
#define ll2(x,y) ll x,y;cin>>x>>y;
#define vint1(a,n) vint a(n);rep(i,n)cin>>a[i];
#define vint2(a,b,n) vint a(n),b(n);rep(i,n)cin>>a[i]>>b[i];
#define vll1(a,n) vll a(n);rep(i,n)cin>>a[i];
const double pi=acos(-1.0);
const ll infl=1LL<<60;
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;}
ll kaizyo(ll k){ll sum=1;rep1(i,k){sum*=i;sum%=mod;}return sum;}
ll ncr(ll n,ll r){return kaizyo(n)/(kaizyo(r)*kaizyo(n-r));}
unsigned keta(unsigned num){
return log10(num)+1;
}
ll gcd(ll a, ll b) {
if (b==0) return a;
else return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
return a * b / gcd(a, b);
}
int main(){
cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
int3(a,b,c);
if(a==b)cout<<'=';
else if(c%2==0){
if(abs(a)>abs(b))cout<<'>';
if(abs(a)<abs(b))cout<<'<';
if(abs(a)==abs(b))cout<<'=';
}
else{
if(c>=1)cout<<((a>b)?'>':'<');
else if(c<=-1)cout<<((a>b)?'<':'>');
else cout<<'=';
}
}
| #ifdef __LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b) {if(a<b) {a=b; return true;} return false;}
template<typename T> bool chmin(T &a,T b) {if(a>b) {a=b; return true;} return false;}
#define itn int
#define fi first
#define se second
#define intmax numeric_limits<int>::max()
#define llmax numeric_limits<ll>::max()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>=1;i--)
#define all(vec) vec.begin(),vec.end()
#define sortt(vec) sort((vec).begin(),(vec).end())
#define rsort(vec) sort((vec).rbegin(), (vec).rend())
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;
const ll lnf=1ll<<60;
int main(){
ll n,t; cin >> n >> t;
vector<ll> a(n);
rep(i,n) cin >> a[i];
vector<ll> b(0);
vector<ll> c(0);
rep(i,n){
if(i<20) b.push_back(a[i]);
else c.push_back(a[i]);
}
set<ll> st1;
set<ll> st2;
rep(i,1ll<<b.size()){
ll sum=0;
rep(j,b.size()){
if(i&(1ll<<j)) sum+=b[j];
}
if(sum<=t) st1.insert(sum);
}
if(c.empty()){
ll ans=0;
for(auto v:st1){
if(v<=t&&ans<v) ans=v;
}
cout << ans << endl;
return 0;
}
rep(i,1ll<<c.size()){
ll sum=0;
rep(j,c.size()){
if(i&(1ll<<j)) sum+=c[j];
}
if(sum<=t) st2.insert(sum);
}
ll ans=0;
for(auto v:st1){
auto itr=st2.upper_bound(t-v);
if(itr!=st2.begin()){
ll x=*(--itr);
if(ans<v+x) ans=v+x;
}
else if(ans<v) ans=v;
}
cout << ans << endl;
} |
#include<bits/stdc++.h>
using namespace std;
int gcd(int a,int b){
while(b){
a=a%b;
swap(a,b);
}
return a;
}
int n,a[2005],mn;
map<int,int> mp;
set<int> s;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++)cin>>a[i];
mn=*min_element(a+1,a+1+n);
for(int i=1;i<=n;i++){
for(int j=1;j*j<=a[i];j++)if(a[i]%j==0){
mp[j]=gcd(mp[j],a[i]);
mp[a[i]/j]=gcd(mp[a[i]/j],a[i]);
}
}
for(pair<int,int> p:mp)if(p.first==p.second)s.insert(min(p.first,mn));
cout<<s.size()<<endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define ld long double
#define forr(i,a,n) for(int i=a;i<n;i++)
#define rep(i,n) forr(i,0,n)
#define repp(i,n) forr(i,1,n+1)
#define pb push_back
#define mp make_pair
#define vvi vector<vector<int> >
#define MAXN 0x3f3f3f3f
int n,a[2010],ans=0;
set<int>s;
int main(){
cin>>n;
rep(i,n)cin>>a[i];
sort(a,a+n);
rep(i,n){
for(int j=1;j*j<=a[i]&&j<=a[0];j++){
if(a[i]%j)continue;
s.insert(j);
if(a[i]/j<=a[0])s.insert(a[i]/j);
}
}
set<int>::iterator it;
for(it=s.begin();it!=s.end();it++){
int now=0;
rep(i,n)if(a[i]%(*it)==0)now=__gcd(now,a[i]);
if(now==(*it))ans++;
}
cout<<ans;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define reg register
typedef long long ll;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++)
static char buf[100000],*p1=buf,*p2=buf;
inline int read(void){
reg char ch=getchar();
reg int res=0;
while(!isdigit(ch))ch=getchar();
while(isdigit(ch))res=10*res+(ch^'0'),ch=getchar();
return res;
}
int main(void){
reg int a=read(),b=read(),c=read();
const int mod=4;
if((b&3)==2)
if(c==1)
b=2;
else
b=mod;
else{
if(!(c&1))
b=1ll*b*b%mod;
else
b%=mod;
if(!b)
b=mod;
}
a%=10;
reg int ans=1;
for(reg int i=1;i<=b;++i)
ans=1ll*ans*a%10;
printf("%d\n",ans);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.first << ' ' << p.second << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}
#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"
#define ll long long
#define ld long double
#define ull unsigned long long
#define pii pair<int,int>
#define MOD 998244353
#define zeros(x) x&(x-1)^x
#define fi first
#define se second
#define NMAX 500005
const long double PI = acos(-1);
int ans = 0, n, mat[55][55], k, mat2[55][55], uz[55], uz2[55], p[55];
bool canSwap(int x, int y, int mat[][55]){
for (int i=1;i<=n;i++){
if (mat[i][x] + mat[i][y] > k){
return false;
}
}
return true;
}
int main(){
ios::sync_with_stdio(false);
cin >> n >> k;
for (int i=1;i<=n;i++){
uz[i] = uz2[i] = i;
for (int j=1;j<=n;j++){
cin >> mat[i][j];
mat2[j][i] = mat[i][j];
}
}
p[0] = 1;
for (int i=1;i<=n;i++){
p[i] = 1LL * i * p[i-1] % MOD;
}
dbg(canSwap(1,2,mat));
ans = 1;
for (int i=1;i<=n;i++){
int cnt = 1, cnt2 = 1;
for (int j=i+1;j<=n;j++){
if (canSwap(i,j,mat)){
int sav = uz[j];
for (int k=1;k<=n;k++){
if (uz[k] == sav)
uz[k] = uz[i];
}
}
if (canSwap(i,j,mat2)){
int sav = uz2[j];
for (int k=1;k<=n;k++){
if (uz2[k] == sav)
uz2[k] = uz2[i];
}
}
}
}
for (int i=1;i<=n;i++){
int cnt = 0, cnt2 = 0;
for (int j=1;j<=n;j++){
if (uz[j] == i) cnt++;
if (uz2[j] == i) cnt2++;
}
dbg(cnt, cnt2);
ans = 1LL * ans * p[cnt] % MOD;
ans = 1LL * ans * p[cnt2] % MOD;
}
cout << ans << '\n';
return 0;
} |
#include<iostream>
#include<string>
using namespace std;
typedef long long ll;
int main()
{
int n,m,t,i,j;
ll r[2];
string s;
cin >> n >> m;
r[0]=0; r[1]=0;
for(i=0;i<n;i++){
cin >> s;
t=0;
for(j=0;j<m;j++)
if(s[j]=='1')
t++;
r[t%2]++;
}
cout << r[0]*r[1] << endl;
return 0;
} | #include "bits/stdc++.h"
using namespace std;
#define ll long long
#define pb push_back
#define all(_obj) _obj.begin(),_obj.end()
#define F first
#define S second
#define INF 1e18
#define pll pair<ll, ll>
#define vll vector<ll>
ll n,m,a,b,c,k,temp,x,y;
const int MAXN=1e5+11,mod=998244353;
ll max(ll a,ll b) {return ((a>b)?a:b);}
ll min(ll a,ll b) {return ((a>b)?b:a);}
vll read(int n) {vll v(n);for (int i = 0; i < v.size(); i++)cin>>v[i];return v;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int dp[3001][7000];
ll rec(int n,int k)
{
if(dp[n][k]!=-1) return dp[n][k];
if(n && !k) return dp[n][k]=0;
if(n<k) return dp[n][k]= 0;
if(n==k) return dp[n][k]=1;
return dp[n][k]=(rec(n-1,k-1)+rec(n,2*k))%mod;
}
void sol(void)
{
memset(dp,-1,sizeof(dp));
cin>>n>>k;
cout<<rec(n,k);
return ;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int test=1;
//cin>>test;
for(int i=1;i<=test;i++)
sol();
}
|
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
using LL = long long;
using VI = vector<int>;
using VS = vector<string>;
using VLL = vector<LL>;
using VC = vector<char>;
using VD = vector<double>;
using PII = pair<int, int>;
using PSS = pair<string, string>;
using PIS = pair<int , string>;
using PSI = pair<string, int>;
using PLL = pair<LL, LL>;
using PCC = pair<char, char>;
using VVI = vector<VI>;
using VVS = vector<VS>;
using VVLL = vector<VLL>;
using VVC = vector<VC>;
using VVD = vector<VD>;
using VPII = vector<PII>;
using VPSS = vector<PSS>;
using VPIS = vector<PIS>;
using VPLL = vector<PLL>;
template<class T> void chmin(T &a, T b)
{
if(a > b) a = b;
}
template<class T> void chmax(T &a, T b)
{
if(a < b) a = b;
}
//const double PI = 3.141592653589793;
//LL INF = 1LL << 60;
//-----------------------------------------
int main()
{
cout << fixed << setprecision(12);
int H, W;
cin >> H >> W;
VVC S(H, VC(W));
for(int i = 0; i < H; i++)
{
for(int j = 0; j < W; j++)
{
cin >> S[i][j];
}
}
int n = 0;
for(int i = 0; i < H - 1; i++)
{
for(int j = 0; j < W - 1; j++)
{
int cnt = 0;
if(S[i][j] == '#') cnt++;
if(S[i + 1][j] == '#') cnt++;
if(S[i][j + 1] == '#') cnt ++;
if(S[i + 1][j + 1] == '#') cnt++;
if(cnt == 1 || cnt == 3) n++;
}
}
cout << n << endl;
return 0;
} | #include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define isPossible(x) printf("%s\n",(x) ? "Possible" : "Impossible")
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
// #define INF (1<<9+9)
const int INF = 0x3fffffff;
// const long long INF = 1LL<<50;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define pie 3.14159265358979323846
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}
const int MOD =(int)998244353;
// const int mod =(int)998244353;
const int mod =(int)1e9+7;
const int MAX =510000;
ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
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;
}
}
ll 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;
}
ll gcd(ll a,ll b){
if(a<0)a=-a;
if(b<0)b=-b;
if(b==0)return a;
if(a>b){
swap(a,b);
}
return gcd(a,b%a);
}
ll lcm(ll a,ll b){
if(a<0)a=-a;
if(b<0)b=-b;
ll g;g=gcd(a,b);
return b/g*a;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
if(a.second != b.second){
return a.second < b.second;
}else{
return a.first < b.first;
}
}
bool compare_by_a(pair<int, int> a, pair<int, int> b) {
if(a.first != b.first){
return a.first < b.first;
}else{
return a.second < b.second;
}
}
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 N, M, K, T, H, W, L, R;
// long long int N, M, K, T, H, W, L, R
ll RS(ll N,ll P,ll m){
if(P==0){
return 1;
}else{
if(P%2==0){
ll t=RS(N,P/2,m);
return t*t%m;
}else{
return N*RS(N,P-1,m)%m;
}
}
}
struct BIT{
private:
vector<int> bit;
int N;
public:
BIT(int size){
N=size;
bit.resize(N+1);
}
void add(int a,int w){
for(int x=a;x<=N;x+=(x&-x)){
bit[x]+=w;
}
}
int sum(int a){
int ret=0;
for(int x=a;x>0;x-=(x&-x))ret+=bit[x];
return ret;
}
};
int main() {
ios::sync_with_stdio(false);
int H,W;
cin>>H>>W;
vector<string>S(H);
REP(i,H)cin>>S[i];
int ans=0;
int dh[]={0,0,1,1};
int dw[]={0,1,0,1};
REP(ih,H-1){
REP(iw,W-1){
int cnt=0;
REP(i,4){
if(S[ih+dh[i]][iw+dw[i]]=='#')cnt++;
}
if(cnt&1)ans++;
}
}
cout<<ans<<endl;
return 0;
}
|
#include<iostream>
using namespace std;
int n;
int a(int m){
if(m%n==0)return n;
else return m%n;
}
int main(){
cin>>n;
for(int i=1;i<=n;i++)cout<<a(2*i)<<" "<<a(2*i+1)<<endl;
} | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int MAXN = 1e3 + 5;
#define bbit(i) (1<<(i))
#define bdig(x,i) (((x)>>(i))&1)
inline int get_lb(int x)
{
int lb = 0;
while(x>>lb) ++lb;
return lb-1;
}
int n;
inline int tidy(int x){ while(x>n) x ^= bbit(get_lb(x)); return max(x, 1);}
int main(void)
{
scanf("%d",&n);
for(int i=1; i<=n; ++i)
printf("%d %d\n",tidy(i<<1),tidy(i<<1|1));
return 0;
} |
#include<bits/stdc++.h>
#define int long long
using namespace std;
constexpr int mod=1000000007;
struct edge{int to,cost;};
void dfs(int v,int p,auto&G,auto&x){
for(edge e:G[v])if(e.to!=p){
x[e.to]=x[v]^e.cost;
dfs(e.to,v,G,x);
}
}
int mod_pow(int a,int b){
if(!b)return 1;
if(b&1)return mod_pow(a,b-1)*a%mod;
int c=mod_pow(a,b/2);
return c*c%mod;
}
signed main(){
int N; cin>>N;
vector<vector<edge>> G(N);
for(int i=0;i<N-1;i++){
int a,b,c; cin>>a>>b>>c;
G[--a].push_back({--b,c});
G[b].push_back({a,c});
}
vector<int>x(N);
dfs(0,-1,G,x);
int ans=0;
for(int i=0;i<60;i++){
int sum=0;
for(int j:x)if((j>>i)&1)sum++;
(ans+=(sum*(N-sum))%mod*mod_pow(2,i)%mod)%=mod;
}
cout<<ans<<endl;
} | #include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define ROF(i,a,b) for(int i=(a); i>=(b); --i)
#define pb push_back
#define eb emplace_back
#define SZ(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define make_unique(a) sort(all((a))), (a).erase(unique(all((a))),(a).end())
#define x first
#define y second
#define MP make_pair
#define MT make_tuple
#define debug(x) cout << #x << " = " << x << endl
#define debug2(x,y) FOR(i,1,y) cout << "##"; cout << #x << " = " << x << endl
#define mset(x,y) memset((x), (y), sizeof(x))
using namespace std;
typedef long long i64;
typedef long double ld;
typedef tuple<int,int,int> iii;
typedef pair<int,int> pii;
typedef pair<i64,i64> pll;
typedef vector<int> vi;
typedef vector<i64> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<i64>> vvl;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<i64,i64>> vpll;
int readInt(){ int a; scanf("%d",&a); return a; }
i64 readLong(){ i64 a; scanf("%lld",&a); return a;}
void readString(char *s){ scanf(" %s",s); }
const int mod = 998244353;
int add(int a, int b){ return ((a+=b)>=mod)?a-mod:a; }
int mul(int a, int b){ return a*1ll*b%mod; }
void adding(int &a, int b){ a = add(a, b); }
int pw(int a, int b){
if(a==0) return 0;
int ans = 1, res = a;
for(int i = 1; i <= b; i<<=1, res=mul(res,res)){
if(i&b) ans = mul(ans,res);
}
return ans;
}
int play(vi w){
int n = SZ(w);
vi p(n);
iota(all(p),0);
int cnt = 0;
do{
int sum = 0;
FOR(i,0,n-1){
if(sum <= 0) sum += w[p[i]];
else sum -= w[p[i]];
}
if(sum == 0) ++cnt;
else{
printf("{ ");
FOR(i,0,n-1) printf("%d ",w[p[i]]);
printf("}\n");
}
}while(next_permutation(all(p)));
return cnt;
}
const int N = 105;
int fac[N];
const int zero = 5000;
int dp[N][N*N];
int sav[N][N*N];
int main(){
//printf("%d\n",play({1,2,3,4}));
fac[0] = 1;
FOR(i, 1, 100) fac[i] = mul(fac[i-1],i);
int n = readInt();
dp[0][zero] = 1;
int mx = N*N;
FOR(i, 1, n){
int a = readInt();
FOR(j, 0, i-1){
FOR(k, 0, mx-1){
if(k >= a) adding(sav[j][k-a], dp[j][k]);
if(k+a < mx) adding(sav[j+1][k+a], dp[j][k]);
}
}
FOR(j, 0, i){
FOR(k, 0, mx-1){
dp[j][k] = sav[j][k];
sav[j][k] = 0;
}
}
}
int ans = 0;
FOR(i, 1, n-1){
//printf("%d\n",dp[i][zero]);
adding(ans, mul(mul(fac[i],fac[n-i]),dp[i][zero]));
}
printf("%d",ans);
return 0;
}
/*
5
3 3 3 3 6
(96)
*/
|
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;
//container util
//------------------------------------------
#define PB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define ALL(a) (a).begin(),(a).end()
//constant
//--------------------------------------------
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
int main(){
int N;cin>>N;
if(N%2==0)cout<<"White"<<endl;
else cout<<"Black"<<endl;
return 0;
}
| #include <iostream>
using namespace std;
int main()
{
int N;
cin >> N;
if (N%2==1) {
cout << "Black" << endl;
} else {
cout << "White" << endl;
}
return 0;
}
|
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_multi_set;
#define mod 998244353
#define pi 3.1415926535898
#define eps 1e-9
#define fast ios::sync_with_stdio(0); cin.tie(0);cout.tie(0)
#define vt vector
#define ar array
#define fs first
#define sc second
#define pb push_back
#define sp printf(" ")
#define nl '\n'
#define all(a) a.begin(),a.end()
#define unique(c) (c).resize(unique(all(c)) - (c).begin())
#define sz(x) (int)(x).size()
#define revsort(x) sort(all(x));reverse(all(x))
#define set0(a) memset(a,0,sizeof(a))
#define setneg(a) memset(a,-1,sizeof(a))
#define setinf(a) memset(a,126,sizeof(a))
#define REP(i,start,end) for (int i = start; i <=end; i++)
#define RREP(i,end,start) for (int i=end; i>=start ;i--)
#define EACH(x, a) for (auto& x: a)
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<LL> vll;
typedef vector<double> vd;
typedef vector<vector<LL> > matrix;
typedef vector<vector<int> > graph;
template<class A> void read(vt<A>& v);
template<class A, size_t S> void read(ar<A, S>& a);
template<class T> void read(T& x) {
cin >> x;
}
void read(double& d) {
string t;
read(t);
d=stod(t);
}
void read(long double& d) {
string t;
read(t);
d=stold(t);
}
template<class H, class... T> void read(H& h, T&... t) {
read(h);
read(t...);
}
template<class A> void read(vt<A>& x) {
EACH(a, x)
read(a);
}
template<class A, size_t S> void read(array<A, S>& x) {
EACH(a, x)
read(a);
}
LL powm(LL x, LL y,LL m) {
if (y==0) return 1;
if (y==1) return x%m;
if (y&1) return (x*(powm((x*x)%m,y/2,m)))%m;
return powm((x*x)%m,y/2,m)%m;
}
LL inv(LL x, LL m) {
return powm(x,m-2,m);
}
int add(int var1, int var2) {
return (((((LL)(var1)) % mod + (LL)(var2)) % mod) + mod) % mod;
}
int mul(int var1, int var2) {
return (((LL)(var1)) % mod * (LL)(var2)) % mod;
}
LL INF=1e9;
LL func (LL x) {
return (x*(x+1)/2)%mod;
}
void solve() {
LL a, b, c;
read(a, b, c);
LL ans = 1;
ans = mul(ans, func(a));
ans = mul(ans, func(b));
ans = mul(ans, func(c));
cout << ans << nl;
}
int main() {
fast;
solve();
}
| /**
____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 998244353;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll a, b, c;
cin >> a >> b >> c;
a = a * (a + 1) / 2 % MOD;
b = b * (b + 1) / 2 % MOD;
c = c * (c + 1) / 2 % MOD;
cout << a * b % MOD * c % MOD << "\n";
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
const long long mod=1e9+7;
int a[2001][2001];
long long dp[2001][2001];
long long h[2001],l[2001],hjl[4001];
int main()
{
int n,m;scanf("%d%d",&n,&m);getchar();
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
a[i][j]=getchar();
getchar();
}
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
if(a[i][j]=='#')h[i]=0,l[j]=0,hjl[i-j+2000]=0;
else
{
if(i==1&&j==1)dp[i][j]=1;else
dp[i][j]=(h[i]+l[j]+hjl[i-j+2000])%mod;
h[i]=(dp[i][j]+h[i])%mod;
l[j]=(dp[i][j]+l[j])%mod;
hjl[i-j+2000]=(dp[i][j]+hjl[i-j+2000])%mod;
}
cout<<dp[n][m];
return 0;
} | #pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<cstdint>
#include<cstddef>
#include<vector>
//#include<atcoder/all>
//using namespace atcoder;
using namespace std;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using usize = uint_fast64_t;
template<typename T>
using vec = vector<T>;
#define rep(i, n) for (i64 i = 0; i < (i64)(n); ++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using P = pair<i64,i64>;
void solve(){
}
using i64 = int_fast64_t;
constexpr i64 MAX = 10000000;
constexpr i64 MOD = 1000000007;
i64 fac[MAX], finv[MAX], inv[MAX];
template <i64 modulus>
class modcal
{
public:
i64 a;
constexpr modcal(const i64 x = 0) noexcept : a(x % modulus) {}
constexpr i64 &value() noexcept { return a; }
constexpr const i64 &value() const noexcept { return a; }
constexpr modcal operator+(const modcal rhs) const noexcept
{
return modcal(*this) += rhs;
}
constexpr modcal operator-(const modcal rhs) const noexcept
{
return modcal(*this) -= rhs;
}
constexpr modcal operator*(const modcal rhs) const noexcept
{
return modcal(*this) *= rhs;
}
constexpr modcal operator/(const modcal rhs) noexcept
{
return modcal(*this) /= rhs;
}
constexpr modcal &operator+=(const modcal rhs) noexcept
{
a += rhs.a;
if (a >= modulus)
{
a -= modulus;
}
return *this;
}
constexpr modcal &operator-=(const modcal rhs) noexcept
{
if (a < rhs.a)
{
a += modulus;
}
a -= rhs.a;
return *this;
}
constexpr modcal &operator*=(const modcal rhs) noexcept
{
a = a * rhs.a % modulus;
return *this;
}
constexpr modcal &operator/=(modcal rhs) noexcept
{
i64 exp = modulus - 2;
while (exp)
{
if (exp % 2)
{
*this *= rhs;
}
rhs *= rhs;
exp /= 2;
}
return *this;
}
void COMninit()
{
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 % modulus;
inv[i] = MOD - inv[modulus % i] * (modulus / i) % modulus;
finv[i] = finv[i - 1] * inv[i] % modulus;
}
}
i64 COMn(i64 n, i64 k)
{
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % modulus) % modulus;
}
constexpr modcal<1000000007> modpow(const modcal<1000000007> &a, i64 n)
{
if (n == 0)
return 1;
auto t = modpow(a, n / 2);
t = t * t;
if (n & 1)
t = t * a;
return t;
}
};
using modc = modcal<1000000007>;
int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
i64 h,w;
cin >> h >> w;
vec<string> s(h);
rep(i,h)cin >> s[i];
i64 dx[3] = {1,1,0};
i64 dy[3] = {0,1,1};
vec<vec<vec<modc>>> dp(h,vec<vec<modc>>(w,vec<modc>(4,0)));
dp[0][0][3] = 1;
rep(i,h){
rep(j,w){
rep(k,4){
if(dp[i][j][k].a == 0)continue;
rep(v,3){
i64 ny = dy[v] + i;
i64 nx = dx[v] + j;
if(nx < 0 || nx >= w || ny < 0 || ny >= h)continue;
if(s[ny][nx] == '#')continue;
dp[ny][nx][v] += dp[i][j][k];
if(k == v)dp[ny][nx][v] += dp[i][j][k];
}
}
}
}
modc ans = 0;
rep(i,3){
ans += dp[h - 1][w - 1][i];
}
cout << ans.a << endl;
} |
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#define f(x, m) for(auto x : m)
#define cpu() ios::sync_with_stdio(false); cin.tie(nullptr)
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pair<int ,int>>
#define vll vector<pair<ll ,ll>>
#define all(v) v.begin(),v.end()
#define sor(a) sort( a.begin(), a.end() )
#define ros(a) sort( a.rbegin(), a.rend())
#define prec(n) fixed << setprecision(n)
#define ff first
#define ss second
#define print(x) for(auto it : x) cout << it << " ";
#define debug(x) cerr << #x << " is " << x << endl;
typedef long long ll;
using namespace std;
// using namespace __gnu_pbds;
#define dbg(args...){ string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {cout << "NEXT\n"; }
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << ", ";
err(++it, args...);
}
template<typename... T>
void rd(T& ... args){
((cin >> args), ...);
}
template<typename... T>
void ps(T ... args){
((cout << args << ' '), ...);
cout << '\n';
}
// using ordered_set = tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update>;
const ll MOD = 1e9 + 7, MOD1 = 998244353LL, MAX = 1e6+ 5;
const char nl = '\n';
const int INF = 1e9 + 5;
int n, m, k;
ll mu(ll x, ll y){
return (x * y) % MOD1;
}
int re(int x, int y){
x -= y;
if(x < 0){
x += MOD1;
}
return x;
}
void add(int& x, int y){
x += y;
if(x >= MOD1){
x -= MOD1;
}
}
ll pot(ll x, ll y){
if(y == 0) return 1;
if(y & 1) return (pot(x, y - 1) * x) % MOD1;
ll k = pot(x, y / 2);
return (k * k) % MOD1;
}
ll inv(ll x){
return pot(x, MOD1 - 2);
}
void solve(){
cin >> n >> m >> k;
if(n == m && n == 1){
cout << k << '\n';
return;
}
if(n == 1 || m == 1){
int ans = 0;
for(int i = 1; i <= k; i++){
add(ans, mu(re(pot(i, n), pot(i - 1, n)), re(pot(k - i + 1, m), pot(k - i, m))));
}
cout << ans << '\n';
return;
}
int ans = 0;
for(int i = 1; i <= k; i++){
add(ans, mu(re(pot(i, n), pot(i - 1, n)), pot(k - i + 1, m)));
}
cout << ans << '\n';
}
int main(){
cpu();
int __ = 1;
// cin >> __;
while(__--){
solve();
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = (2e5 + 10), INF = 0x3f3f3f3f3f3f3f3f, mod = 998244353;
int ksm(int a, int b) {
int res = 1;
while (b) {
if (b & 1) res = (res * a) % mod;
a = (a * a) % mod;
b >>= 1;
}
return res;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int n, m, k;
cin >> n >> m >> k;
int ans = 0;
if (n == 1) {
for (int i = 1; i <= k; i++)
ans = (ans + (ksm(i, m) - ksm(i - 1, m))) % mod;
} else if (m == 1) {
for (int i = 1; i <= k; i++)
ans = (ans + (ksm(i, n) - ksm(i - 1, n))) % mod;
} else {
for (int i = 1; i <= k; i++)
ans =
(ans + (ksm(i, n) - ksm(i - 1, n)) * (ksm(k - i + 1, m))) % mod;
}
cout << (ans % mod + mod) % mod << "\n";
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define endl '\n'
#define all(v) (v).begin(), (v).end()
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, k;
cin >> n >> k;
int sum = 0;
for(int floor = 1; floor <= n; ++floor) {
int floor_no = 100 * floor;
for(int room = 1; room <= k; ++room) {
int value = (floor_no + room);
// cout << imie(value);
sum += value;
}
}
cout << sum << endl;
return 0;
}
| #include <bits/stdc++.h>
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
using namespace std;
using ll = long long;
struct Edge{
ll to;
ll cost;
};
using Graph = vector<vector<Edge>>;
using P =pair<ll,ll>;
#define mp make_pair
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(),v.end()
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = LLONG_MAX;
const int MAX = 510000;
bool graph[nmax][nmax];
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;
}
}
ll 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;
}
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
for (size_t i = 0; i < n; i++)
{
for (size_t j = 0; j < n; j++)
{
for (size_t k = 0; k < n; k++)
{
dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
}
}
}
}
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;
}
ll mulMod(ll a, ll b)
{
return (((a % MOD) * (b % MOD)) % MOD);
}
ll powMod(ll a, ll p)
{
if (p == 0)
{
return 1;
}
else if (p % 2 == 0)
{
ll half = powMod(a, p / 2);
return mulMod(half, half);
}
else
{
return mulMod(powMod(a, p - 1), a);
}
}
ll ceil(ll a, ll b)
{
return (a + b - 1) / b;
}
int main(){
char S,T;
cin >> S >> T;
if(S=='Y'){
cout << (char)(T + 'A' - 'a') << endl;
}else{
cout << T << endl;
}
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define Mod 1000000007
ll cmod(ll a){return (a%Mod+Mod)%Mod;}
inline ll read(){ll x;scanf("%lld",&x);return x;}
ll solve()
{
ll N=read(),A=read(),B=read();
if(N-A-B<0) return 0;
if(A<B) swap(A,B);
ll x1=(B-1)*(B-1)%Mod*(2*N+2-2*A-B)%Mod*(2*N+2-2*A-B)%Mod;
ll x2=(A-B+1)*(N-A+1)%Mod*(B-1)%Mod*(4*N+4-4*A-2*B)%Mod;
ll x3=(N-A+1)*(N-A+1)%Mod*(A-B+1)%Mod*(A-B+1)%Mod;
ll x=(N-A+1)*(N-A+1)%Mod*(N-B+1)%Mod*(N-B+1)%Mod;
return cmod(x-x1-x2-x3);
}
int main()
{
ll t=read();
while(t--) cout<<solve()<<endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int T;
cin >> T;
int64_t N, A, B;
const int64_t mod = 1000000007;
for (int Case = 0; Case < T; Case++) {
cin >> N >> A >> B;
if (A+B>N) {
cout << 0 << endl;
continue;
}
int64_t Count = (N+1-A)*(N+1-A) % mod;
Count = Count * (N+1-B) % mod;
Count = Count * (N+1-B) % mod;
int64_t Del;
Del = (N+1-A)*(A+B-1) % mod;
Del = (Del - (B-1)*B%mod + mod) % mod;
Del = Del*Del % mod;
Count = (Count - Del + mod) % mod;
cout << Count << endl;
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<ll, ll> P;
typedef vector<P> vp;
typedef tuple<int, int, P> T;
typedef vector<T> vt;
typedef vector<vl> vvl;
// input
int N;
vl X, Y;
int M;
vp op;
int Q;
vi A, B;
void input() {
cin >> N;
X = Y = vl(N);
rep(i, N) cin >> X[i] >> Y[i];
cin >> M;
op = vp(M);
rep(i, M) {
cin >> op[i].first;
if (op[i].first > 2) cin >> op[i].second;
}
cin >> Q;
A = B = vi(Q);
rep(i, Q) cin >> A[i] >> B[i];
}
vvl multi(vvl &a, vvl &b) {
int r1 = a.size(), c1 = a[0].size();
int r2 = b.size(), c2 = b[0].size();
assert(c1 == r2);
vvl ret(r1, vl(c2, 0));
rep(i, r1) rep(j, c2) {
rep(k, c1) ret[i][j] += a[i][k] * b[k][j];
}
return ret;
}
int main() {
input();
vector<vvl> w(M + 1);
w[0] = {
{1, 0, 0},
{0, 1, 0},
{0, 0, 1},
};
rep(i, M) {
ll o, p;
tie(o, p) = op[i];
vvl d;
if (o == 1) {
d = {
{0, 1, 0},
{-1, 0, 0},
{0, 0, 1},
};
} else if (o == 2) {
d = {
{0, -1, 0},
{1, 0, 0},
{0, 0, 1},
};
} else if (o == 3) {
d = {
{-1, 0, 2 * p},
{0, 1, 0},
{0, 0, 1},
};
} else {
d = {
{1, 0, 0},
{0, -1, 2 * p},
{0, 0, 1},
};
}
w[i + 1] = multi(d, w[i]);
}
rep(i, Q) {
vvl mat = {
{X[B[i] - 1]},
{Y[B[i] - 1]},
{1},
};
vvl ans = multi(w[A[i]], mat);
printf("%lld %lld\n", ans[0][0], ans[1][0]);
}
}
| #include <iostream>
using namespace std;
typedef long long ll;
struct State{
int dir;
bool xrev, yrev;
ll dx, dy;
};
int main()
{
int n;
cin >> n;
ll x[200005], y[200005];
for(int i = 0; i < n; i++) cin >> x[i] >> y[i];
int m;
cin >> m;
State state[200005];
state[0] = (State){0, false, false, 0, 0};
for(int i = 1; i <= m; i++){
state[i] = state[i - 1];
int t;
cin >> t;
if(t == 1) state[i].dir = (state[i].dir + 1) % 4;
if(t == 2) state[i].dir = (state[i].dir + 3) % 4;
if(t == 3){
ll p;
cin >> p;
if(state[i].dir >= 2) p = -p;
if(!(state[i].dir % 2)){
if(state[i].xrev) state[i].dx += p * 2;
else state[i].dx -= p * 2;
state[i].xrev ^= true;
}
else{
if(state[i].yrev) state[i].dy += p * 2;
else state[i].dy -= p * 2;
state[i].yrev ^= true;
}
}
if(t == 4){
ll p;
cin >> p;
if(state[i].dir == 1 || state[i].dir == 2) p = -p;
if(state[i].dir % 2){
if(state[i].xrev) state[i].dx += p * 2;
else state[i].dx -= p * 2;
state[i].xrev ^= true;
}
else{
if(state[i].yrev) state[i].dy += p * 2;
else state[i].dy -= p * 2;
state[i].yrev ^= true;
}
}
}
int q;
cin >> q;
while(q--){
int a, b;
cin >> a >> b;
b--;
ll u, v;
if(state[a].xrev) u = -x[b] - state[a].dx;
else u = x[b] + state[a].dx;
if(state[a].yrev) v = -y[b] - state[a].dy;
else v = y[b] + state[a].dy;
for(int i = 0; i < state[a].dir; i++){
swap(u, v);
v = -v;
}
cout << u << " " << v << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
vector<int> x(n);
vector<int> y(n);
vector<int> r(n);
for (int i = 0; i < n; i++) {
cin >> x.at(i) >> y.at(i) >> r.at(i);
}
int maxx = 0;
int minx = 114514;
for (int i = 0; i < n; i++) {
maxx = max(maxx, x.at(i));
minx = min(minx, x.at(i));
}
int maxi = 0;
int mini = 0;
for (int i = 0; i < n; i++) {
if (x.at(i) == maxx) {
maxi = i;
break;
}
}
for (int i = 0; i < n; i++) {
if (x.at(i) == minx) {
mini = i;
break;
}
}
for (int i = 0; i < n; i++) {
if (i == maxi) {
cout << maxx << " " << 0 << " " << 10000 << " " << 10000 << endl;
}
else if(i == mini){
cout << 0 << " " << 0 << " " << minx << " " << 10000 << endl;
}
else if (x.at(i) == maxx && i != maxi) {
cout << x.at(i) - 1 << " " << y.at(i) << " " << x.at(i) << " " << y.at(i)+1 << endl;
}
else if (x.at(i) == minx && i != mini) {
cout << x.at(i)+1 << " " << y.at(i) << " " << x.at(i)+2 << " " << y.at(i) + 1 << endl;
}
else {
cout << x.at(i) << " " << y.at(i) << " " << x.at(i) + 1 << " " << y.at(i) + 1 << endl;
}
}
} | #define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
const int MOD = 1'000'000'007;
const int MOD2 = 998'244'353;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;
template<class T, class S> inline bool chmax(T &a, const S &b){
if(a < b){
a = b; return true;
}
return false;
}
template<class T, class S> inline bool chmin(T &a, const S &b){
if(b < a){
a = b; return true;
}
return false;
}
int main(){
int n; std::cin >> n;
int x, y, r;
for(int i(0); i < n; ++i){
std::cin >> x >> y >> r;
std::cout << x << " " << y << " " << x + 1 << " " << y + 1 << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
std::fill( (T*)array, (T*)(array+N), val );
}
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;
}
int main(){
string s;
cin >> s;
int res = 0;
rep(i,9){
if(s.substr(i,4)=="ZONe"){
res++;
}
}
cout << res << endl;
return 0;
} | #include <bits/stdc++.h>
#include <string>
typedef long long ll;
typedef long double ldb;
typedef double db;
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define ins insert
#define mp make_pair
#define len(s) s.length()
#define forp(i, a, b) for (ll i = a; i <= b; i++)
#define rep(i, n) for (ll i = 0; i < n; i++)
#define ren(i, n) for (ll i = n - 1; i >= 0; i--)
#define forn(i, a, b) for (ll i = a; i >= b; i--)
#define on cout << endl
#define o2(a, b) cout << a << " " << b
#define os cout << " "
#define all(v) v.begin(), v.end()
#define mem(n, m) memset(n, m, sizeof(n))
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vld vector<ld>
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define vvld vector<vector<ld>>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define mll map<ll, ll>
#define lb lower_bound
#define ub upper_bound
#define ret return 0
#define present(s, x) (s.find(x) != s.end())
#define cpresent(s, x) (find(all(s), x) != s.end())
#define ford(container, it) for (__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define fors(container, it, a, b) for (__typeof(container.begin()) it = a; it != b; it++)
#define d1(x) cout << (x) << endl
#define d2(x, y) cout << (x) << " " << (y) << endl
#define d3(x, y, z) cout << (x) << " " << (y) << " " << (z) << endl
#define d4(a, b, c, d) cout << (a) << " " << (b) << " " << (c) << " " << (d) << endl
#define max3(a, b, c) max(max(a, b), c)
#define min3(a, b, c) min(min(a, b), c)
#define itoa(x) to_string(x);
#define atoi(x) stoll(x);
#define boost ios_base::sync_with_stdio(0)
#define MOD 1000000007
#define EPSILON 1e-9
#define PI 3.14159265358979323846
#define inf 999999999999999999
#define siz 100001
#define SIZ 1000001
#define SIZE 200001
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define w(x) \
int x; \
cin >> x; \
while (x--)
ll power(ll x, ll y, ll p)
{
ll res = 1;
x = x % p;
while (y > 0)
{
if (y & 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
ll pwr(ll x, ll y)
{
ll res = 1;
x = x;
while (y > 0)
{
if (y & 1)
res = (res * x);
y = y >> 1;
x = (x * x);
}
return res;
}
ll modInverse(ll n, ll p)
{
return power(n, p - 2, p);
}
ll gcd(ll a, ll b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
ll lcm(ll a, ll b)
{
return (b * a) / gcd(a, b);
}
ll fact(ll n)
{
if (n <= 1)
return 1;
return n * fact(n - 1);
}
ll nPr(ll n, ll r)
{
return fact(n) / fact(n - r);
}
void c_p_c()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
c_p_c();
ll t;
t = 1;
// cin >> t;
while (t-- > 0)
{
string s;
cin>>s;
ll c=0;
rep(j, s.size())
{
if(s.substr(j, 4)=="ZONe")
{
c++;
j+=3;
}
}
d1(c);
}
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define w(x) int x; cin>>x; while(x--)
#define endl ("\n")
#define f(i, a, n) for(int i=a; i<n; i++)
#define cc(r) cout<<r<<" "
#define ce(r) cout<<r<<endl
void inout()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
int nCrModpDP(int n, int r, int p)
{
int C[r + 1];
memset(C, 0, sizeof(C));
C[0] = 1;
for (int i = 1; i <= n; i++)
{
for (int j = min(i, r); j > 0; j--)
C[j] = (C[j] + C[j - 1]) % p;
}
return C[r];
}
int nCrModpLucas(int n, int r, int p)
{
if (r == 0)
return 1;
int ni = n % p, ri = r % p;
return (nCrModpLucas(n / p, r / p, p) * nCrModpDP(ni, ri, p)) % p;
}
int32_t main()
{
inout();
int n;
cin >> n;
int r[n], a[n], ans = 0;
f(i, 0, n) {
r[i] = nCrModpLucas(n - 1, i, 3);
}
char k;
f(i, 0, n) {
cin >> k;
if (k == 'B')
a[i] = 0;
else if (k == 'W')
a[i] = 1;
else
a[i] = 2;
}
f(i, 0, n) {
ans = (ans + (a[i] * r[i]) % 3) % 3;
}
if ((n & 1) == 0) {
ans = (-ans + 3) % 3;
}
if (ans == 0)
ce('B');
else if (ans == 1)
ce('W');
else
ce('R');
}
| #include <bits/stdc++.h>
using namespace std;
using namespace chrono;
using ll = long long;
constexpr double TIME_LIMIT = 2.95;
system_clock::time_point start;
double elapsed = 0;
int loops = 1;
int steps = 10;
int N;
int M;
vector<string> S;
vector<string> output;
int base_num = 9;
char bases[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', '.'};
static uint32_t randXor() {
static uint32_t x = 123456789;
static uint32_t y = 362436069;
static uint32_t z = 521288629;
static uint32_t w = 88675123;
uint32_t t;
t = x ^ (x << 11);
x = y;
y = z;
z = w;
return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
}
static double rand01() { return (randXor() + 0.5) * (1.0 / UINT_MAX); }
int get_score(vector<string> &output) {
int score;
int c = 0, d = 0;
bool match = false;
for (int i = 0; i < M; i++) {
match = false;
// horizontal
for (int h = 0; h < N; h++) {
for (int w = 0; w < N; w++) {
bool check = true;
for (int j = 0; j < S[i].length(); j++) {
if (S[i][j] != output[h][(w + j) % N]) {
check = false;
break;
}
}
if (check) {
match = true;
goto matched;
}
}
}
// vertical
for (int h = 0; h < N; h++) {
for (int w = 0; w < N; w++) {
bool check = true;
for (int j = 0; j < S[i].length(); j++) {
if (S[i][j] != output[(h + j) % N][w]) {
check = false;
break;
}
}
if (check) {
match = true;
goto matched;
}
}
}
matched:
if (match) c++;
}
for (int h = 0; h < N; h++) {
for (int w = 0; w < N; w++) {
if (output[h][w] == '.') d++;
}
}
if (c == M) {
score =
round(1e8 * 2 * (double)pow(N, 2) / (double)(2 * pow(N, 2) - d));
} else {
score = round(1e8 * (double)c / (double)M);
}
return score;
}
void init() {
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
output[i][j] = bases[randXor() % base_num];
}
}
}
vector<string> mutate(vector<string> output) {
int H = randXor() % N;
int W = randXor() % N;
string T = S[randXor() % M];
int st = randXor() % N;
if (randXor() % 2 == 1) {
for (int i = 0; i < T.length(); i++) {
output[H][(st + i) % N] = bases[randXor() % base_num];
}
} else {
for (int i = 0; i < T.length(); i++) {
output[(st + i) % N][W] = bases[randXor() % base_num];
}
}
return output;
}
int main() {
start = system_clock::now();
// srand(time(NULL));
cin >> N >> M;
S.resize(M);
for (auto &s : S) cin >> s;
output.resize(N);
for (auto &o : output) o.resize(N);
init();
int score = get_score(output);
while (elapsed < TIME_LIMIT * 1e6) {
if (loops % steps == 0) {
elapsed = duration_cast<microseconds>(system_clock::now() - start)
.count();
}
vector<string> output_new = mutate(output);
int score_new = get_score(output_new);
if (score_new > score) {
output = output_new;
score = score_new;
}
loops++;
}
for (auto o : output) cout << o << endl;
// int score = get_score();
// cout << score << endl;
// cout << loops << endl;
return 0;
}
|
#include<bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i, 0, n)
#define all(x) (x).begin(),(x).end()
const int INF = 1e9+1;
using namespace std;
using ll = long long;
using p = pair<int, int>;
using v = vector<int>;
int main(){
int N, M;
cin >> N >> M;
vector<bool> A(N+1, false);
REP(i, M) {
int B;
cin >> B;
A[B-1] = true;
}
A[N] = true;
v C;
int c = 0;
int k = N;
REP(i, N+1) {
if (A[i]) {
if (c > 0) {
k = min(k, c);
C.push_back(c);
}
c = 0;
// cout << "o";
} else {
// cout << "x";
c++;
}
}
// cout << endl;
// cout << "k:" << k << endl;
int n = C.size();
int ans = 0;
REP(i, n) {
ans += ceil((double)C[i]/k);
// cout << C[i] << " ";
}
// cout << endl;
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#define ll long long
#define V vector<long long>
#define VV vector<vector<long long>>
#define VVV vector<vector<vector<long long>>>
#define P pair<ll,ll>
#define rep(i,n) for(ll (i)=0;(i)<(n);++(i))
using namespace std;
int main() {
ll n,m;
cin>>n>>m;
V a(m);
rep(i,m)cin>>a[i];
if(m==0){
cout<<1<<endl;
return 0;
}
sort(a.begin(),a.end());
V res;
if(a[0]-1>0)res.push_back(a[0]-1);
rep(i,m-1)if(a[i+1]-a[i]>1)res.push_back(a[i+1]-a[i]-1);
if(n-a[m-1]>0)res.push_back(n-a[m-1]);
if(res.size()==0){
cout<<0<<endl;
return 0;
}
ll k=*min_element(res.begin(), res.end());
ll ans=0;
for(ll r:res)ans+=(r+k-1)/k;
cout<<ans<<endl;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=200005,INF=1<<30;
//const ll INF=1LL<<60;
#define ld long double
ll f(string x){
bool ok=true;
for(char c:x) if(c=='.') ok=false;
if(ok){
return stoll(x)*10000;
}
int wh=-1;
for(int i=0;i<si(x);i++){
if(x[si(x)-1-i]=='.'){
wh=i;
break;
}
}
for(int t=0;t<4-wh;t++) x+='0';
ll res=0;
for(int i=0;i<si(x);i++){
if(x[i]=='.') continue;
res*=10;
res+=ll(x[i]-'0');
}
return res;
}
int main(){
std::ifstream in("text.txt");
std::cin.rdbuf(in.rdbuf());
cin.tie(0);
ios::sync_with_stdio(false);
string XX,YY,RR;cin>>XX>>YY>>RR;
ll sx=f(XX),sy=f(YY),sr=f(RR);
ld X,Y,R;
X=(ld)sx/10000;
Y=(ld)sy/10000;
R=(ld)sr/10000;
ll ans=0;
//cout<<sx<<" "<<sy<<" "<<sr<<" "<<X<<" "<<Y<<" "<<R<<endl;
for(ll x=X-R-3;x<=X+R+3;x++){
if(abs(sx-x*10000)>sr) continue;
ld rem=R*R-(X-x)*(X-x);
ll y1=Y-sqrt(rem)-3,y2=Y+sqrt(rem)+3;
while(1){
if((sy-y1*10000)*(sy-y1*10000)+(sx-x*10000)*(sx-x*10000)>sr*sr) y1++;
else break;
if(y1>y2) break;
}
if(y1>y2) continue;
while(1){
if((sy-y2*10000)*(sy-y2*10000)+(sx-x*10000)*(sx-x*10000)>sr*sr) y2--;
else break;
if(y1>y2) break;
}
if(y1<=y2) ans+=(y2-y1+1);
}
cout<<ans<<endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define fill0(a) memset(a,0,sizeof(a))
#define fill1(a) memset(a,-1,sizeof(a))
#define fillbig(a) memset(a,63,sizeof(a))
#define pb push_back
#define ppb pop_back
#define mp make_pair
template<typename T1,typename T2> void chkmin(T1 &x,T2 y){if(x>y) x=y;}
template<typename T1,typename T2> void chkmax(T1 &x,T2 y){if(x<y) x=y;}
typedef pair<int,int> pii;
typedef long long ll;
typedef unsigned int u32;
typedef unsigned long long u64;
namespace fastio{
#define FILE_SIZE 1<<23
char rbuf[FILE_SIZE],*p1=rbuf,*p2=rbuf,wbuf[FILE_SIZE],*p3=wbuf;
inline char getc(){return p1==p2&&(p2=(p1=rbuf)+fread(rbuf,1,FILE_SIZE,stdin),p1==p2)?-1:*p1++;}
inline void putc(char x){(*p3++=x);}
template<typename T> void read(T &x){
x=0;char c=getchar();T neg=0;
while(!isdigit(c)) neg|=!(c^'-'),c=getchar();
while(isdigit(c)) x=(x<<3)+(x<<1)+(c^48),c=getchar();
if(neg) x=(~x)+1;
}
template<typename T> void recursive_print(T x){if(!x) return;recursive_print(x/10);putc(x%10^48);}
template<typename T> void print(T x){if(!x) putc('0');if(x<0) putc('-'),x=~x+1;recursive_print(x);}
void print_final(){fwrite(wbuf,1,p3-wbuf,stdout);}
}
const int MAXN=1e5;
int n,s1,s2,a[MAXN+5],b[MAXN+5];
priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > ls,mr;
int main(){
scanf("%d%d%d",&n,&s1,&s2);int sum=0;
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
for(int i=1;i<=n;i++){
int lw=1ll*a[i]*s2/s1,up=lw+1;
if(abs(1ll*lw*s1-1ll*a[i]*s2)<abs(1ll*up*s1-1ll*a[i]*s2))
b[i]=lw,ls.push(mp(abs(1ll*up*s1-1ll*a[i]*s2),i));
else b[i]=up,mr.push(mp(abs(1ll*lw*s1-1ll*a[i]*s2),i));
sum+=b[i];//printf("%d\n",b[i]);
}
// printf("%d\n",sum);
if(sum>s2){
for(int i=1;i<=sum-s2;i++){
pair<int,int> p=mr.top();mr.pop();
b[p.se]--;
}
} else {
for(int i=1;i<=s2-sum;i++){
pair<int,int> p=ls.top();ls.pop();
b[p.se]++;
}
}
for(int i=1;i<=n;i++) printf("%d ",b[i]);printf("\n");
return 0;
}
/*
3 1000 999
333 333 334
*/ |
#pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
#define DEBUG
#ifdef DEBUG
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 << '{';
for(int i = 0; i < (int)v.size(); i++) {
if(i) { os << ','; }
os << v[i];
}
os << '}';
return os;
}
void debugg() { cerr << endl; }
template <class T, class... Args>
void debugg(const T &x, const Args &... args) {
cerr << " " << x;
debugg(args...);
}
#define debug(...) \
cerr << __LINE__ << " [" << #__VA_ARGS__ << "]: ", debugg(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = (1<<30)-1;
const ll linf = 1LL<<61;
const int MAX = 510000;
int dy[8] = {0,1,0,-1,1,-1,-1,1};
int dx[8] = {-1,0,1,0,1,-1,1,-1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
if(a>b){
a = b; return true;
}
else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
if(a<b){
a = b; return true;
}
else return false;
}
template<typename T> inline void print(T &a){
int sz = a.size();
for(auto itr = a.begin(); itr != a.end(); itr++){
cout << *itr;
sz--;
if(sz) cout << " ";
}
cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){
cout << a << " " << b << "\n";
}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
cout << a << " " << b << " " << c << "\n";
}
void mark() {cout << "#" << "\n";}
ll pcount(ll x) {return __builtin_popcountll(x);}
const int mod = 1e9 + 7;
//const int mod = 998244353;
ll GCD(ll a, ll b){
if(b==0) return a;
else return GCD(b,a%b);
}
int main(){
int n; cin >> n;
cout << "6 10 15";
n -= 3;
int now = 2;
while(n > 0){
if(now * 6 > 10000) break;
cout << " " << now*6;
n--;
now++;
}
now = 2;
while(n > 0){
if(now*10 > 10000) break;
if((now*10) % 6 == 0){
now++; continue;
}
cout << " " << now*10;
n--;
now++;
}
now = 2;
while(n > 0){
int t = now*15;
if(t % 6 == 0 || t % 10 == 0){
now++; continue;
}
cout << " " << t;
n--;
now++;
}
cout << endl;
} | #include<bits/stdc++.h>
using namespace std;
const int N = 4e5 + 213;
int a[N];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
a[1] = 2 * 5;
a[n] = 5 * 3;
int x = 1;
int len = 2;
for(int i = 1; i <= 10000; i++) {
if(i != a[1] && i != a[n] && ((i % 2 == 0 && (i % 3 == 0 or i % 5 == 0)) or (i % 3 == 0 and i % 5 == 0))) {
if(len == n) break;
a[len] = i;
len++;
}
}
int g = 0;
for(int i = 1; i <= n; i++)
cout << a[i] << ' ',g = __gcd(g, a[i]);
// cout << endl;
// cout << g << ' ';
bool ok = 1;
for(int i = 1; i <= n; i++)
for(int j = i + 1; j <= n; j++)
ok &= (__gcd(a[i], a[j]) > 1);
// cout << ok;
return 0;
}
|
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
#include <functional>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<PII> VPI;
typedef vector<PLL> VPL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<(n);i++)
#define rep2(i,n,m) for(ll i=n;i<(m);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound
#define fi first
#define se second
void YES(int a){
if(a) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
void Yes(int a){
if(a) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
//#include <atcoder/all>
//using namespace atcoder;
//typedef modint998244353 mint;
ll inf=1001001001001001001;
ll gcd(ll a,ll b){
if(b==0) return a;
return gcd(b,a%b);
}
int main(){
string S;
cin>>S;
string T;
rep(i,S.size()){
if(S[i]=='6') T+='9';
else if(S[i]=='9') T+='6';
else T+=S[i];
}
reverse(all(T));
cout<<T<<endl;
}
| #include<bits/stdc++.h>
using namespace std;
string s;
int main()
{
cin>>s;
reverse(s.begin(),s.end());
for(int i=0;i<s.size();i++){
if(s[i]=='6')s[i]='9';
else if(s[i]=='9')s[i]='6';
}
cout<<s<<endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define fastio ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define t_times int t; cin >> t; while(t--)
#define fr(i, st, n) for(int i = (int )st; i < (int )n; i++)
#define rfr(i, en, st) for(int i = (int )en; i >= (int )st; i--)
#define all(c) (c).begin(), (c).end()
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)((a).size())
typedef long long int LL;
typedef pair< int, int> ii;
typedef vector< int> vi;
typedef vector< ii> vii;
typedef vector< vi> vvi;
const int mod = 1e9 + 7;
const LL INF = 9e18 + 2e17;
const int inf = 2e9;
const double eps = 1e-10;
void solve() {
int x;
cin>>x;
cout<<(x>0?x:0)<<endl;
}
int main(int argc, char const *argv[])
{
fastio;
// t_times{
solve();
// }
return 0;
}
| #include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
inline int read(){
int x=0,f=1;
char ch=getchar();
while(ch>'9'||ch<'0'){
if(ch=='-') f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9'){
x=(x<<1)+(x<<3)+(ch^48);
ch=getchar();
}
return x*f;
}
int n;
int main(){
n=read();
if(n<0)printf("0");
else printf("%d",n);
return 0;
} |
#ifdef Rahul
#include "RAHUL.h"
#else
#include <bits/stdc++.h>
using namespace std;
#define error(...) 42;
#endif
#define SZ(v) int((v).size())
#define ALL(vec) begin(vec), end(vec)
typedef long long i64;
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
#define Luv(...) [&] (auto &&u, auto &&v) { return __VA_ARGS__; }
const int MOD = (int) 1e9 + 7;
const i64 INF = (i64) 1e18 + 42;
const int N = 52;
int n;
i64 a[N];
i64 b[N];
i64 d[N];
i64 dp[N][2];
i64 Solve(int i, int carry) {
if (i == n) return 1;
i64 &res = dp[i][carry];
if (~res) return res;
if (carry && d[i] == b[i] - 1) return res = Solve(i + 1, 1);
if (!carry && d[i] == 0) return res = Solve(i + 1, 0);
return res = Solve(i + 1, 0) + Solve(i + 1, 1);
}
int main() {
cin.tie(nullptr) -> sync_with_stdio(false);
memset(dp, -1, sizeof dp);
i64 x; cin >> n >> x;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
if (i > 1) b[i - 1] = a[i] / a[i - 1];
}
for (int i = n; i > 0; --i) {
d[i] = x / a[i];
x %= a[i];
}
kek(Solve(0, 0));
} | #include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using ld = long double;
using vld = vector<ld>;
using vb = vector<bool>;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define dbg(x) true
#endif
template <class T> bool chmin(T& a, T b) {
if(a > b) { a = b; return true; }
else return false;
}
template <class T> bool chmax(T& a, T b) {
if(a < b) { a = b; return true; }
else return false;
}
template <class T> ostream& operator<<(ostream& s, const vector<T>& a) {
for(auto i : a) s << i << ' ';
return s;
}
constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 62;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);
void solve() {
ll n, x;
cin >> n >> x;
vll a(n);
rep(i, n) cin >> a[i];
vll div(n-1);
rep(i, n-1) div[i] = a[i+1]/a[i];
div.push_back(INFL);
vll cnt(n); // お釣りのない場合の各コインの枚数
for(int i = n-1; i >= 0; --i) {
cnt[i] = x / a[i];
x -= cnt[i] * a[i];
}
vvll dp(n+1, vll(2)); // dp[i][j] : i枚目のコイン,jは桁上がりの有無
dp[0][0] = 1;
rep(i, n) {
dp[i+1][0] += dp[i][0]; // 桁上がり無しの支払い
dp[i+1][1] += dp[i][1]; // 桁上がり有りの遷移
if(cnt[i] > 0) { // 支払いに1枚以上必要な時は桁上がりへの遷移がある
dp[i+1][1] += dp[i][0];
}
if(cnt[i]+1 < div[i]) { // 桁上がり後に桁上がり無しに遷移できる
dp[i+1][0] += dp[i][1];
}
}
cout << dp[n][0] << endl;
return;
}
int main() {
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
cout << fixed << setprecision(15);
solve();
} |
#include<bits/stdc++.h>
using namespace std;
#define speed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define vec vector<int>
#define mii map<int,int>
#define pqb priority_queue<int>
#define pqs priority_queue<int,vi,greater<int> >
#define inf 1e18
#define no_of_test(x) int x; cin>>x; while(x--)
//Actual Code Is At The Top
int32_t main()
{
speed;
// no_of_test(x)
{
int n;
cin>>n;
int a=1,b=1;
for(int i=1;i<=39;i++)
{
a=a*3;
b=1;
for(int j=1;j<=30;j++)
{
b=b*5;
if(a+b==n)
{
cout<<i<<" "<<j<<'\n';
return 0;
}
if(b>=2*b)
break;
}
if(a>=2*a)
break;
}
cout<<-1<<'\n';
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(), x.end()
#define MP make_pair
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
int main(int argc, char *argv[]) {
#ifndef LOCAL
ios::sync_with_stdio(false);
cin.tie(nullptr);
#endif
vector<int> prime{3, 5, 7, 11};
vector<int> v;
for (int i = 1; i <= 5000; i++) {
for (int &x : prime) {
if (i % x == 0) {
v.push_back(i * 2);
break;
}
}
}
int n = 0;
cin >> n;
int g = 3 * 5 * 7 * 11;
for (int i = 0; i < n - 1; i++) {
cout << v[i] << ' ';
g = __gcd(g, v[i]);
}
assert(g == 1);
cout << 3 * 5 * 7 * 11 << '\n';
return 0;
}
/**
* created: 2021/05/09 22:30:40
* compile: g++ sol.cpp -o sol.out -g -std=c++17 -Wall -Wextra -Wshadow -fsanitize=undefined -fsanitize=address -D_GLIBCXX_DEBUG -DLOCAL
**/ |
/*
python3 ../../CompetitionHelpers/run_codeforces.py --problem E --test 0
g++ -ggdb -fsanitize=address -std=c++14 E.cpp && ./a.out <<< "5
1 2
2 3
2 4
4 5
4
1 1 1
1 4 10
2 1 100
2 2 1000"
g++ -ggdb -fsanitize=address -std=c++14 E.cpp && ./a.out <<< "7
2 1
2 3
4 2
4 5
6 1
3 7
7
2 2 1
1 3 2
2 2 4
1 6 8
1 3 16
2 4 32
2 1 64"
*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define trav(a, x) for (auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template <typename A>
string to_string(A v) { int cnt = 0; string res; for (const auto &x : v) { if (cnt++) res += " "; res += to_string(x); } return "[" + res + "]"; }
string to_string(const string& s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); }
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
template<typename T>
void output_vector(const vector<T> &v, int start = 0, int end = -1) {
if (end < 0) end = int(v.size());
for (int i = start; i < end; i++)
cout << v[i] << (i < end - 1 ? ' ' : '\n');
}
int main() {
cin.sync_with_stdio(0); cin.tie(0);
cin.exceptions(cin.failbit);
int N; cin >> N;
vector<vi> Edges(N - 1, vi(2)); rep(i, 0, N - 1) rep(j, 0, 2) cin >> Edges[i][j];
vector<vi> Adj(N + 1);
{
trav(ab, Edges) {
int a = ab[0]; int b = ab[1];
Adj[a].push_back(b);
Adj[b].push_back(a);
}
}
int root = 1;
vector<vi> Kids(N + 1);
vi Parents(N + 1, -1);
{
auto dfsHangTree = [&](auto& self, int node, int par)->void {
Parents[node] = par;
trav(sib, Adj[node]) {
if (sib != par) {
Kids[node].push_back(sib);
self(self, sib, node);
}
}
};
dfsHangTree(dfsHangTree, root, -1);
}
vector<ll> Values(N + 1, 0);
int Q; cin >> Q;
rep(qi, 0, Q) {
int ti, ei; cin >> ti >> ei;
ll xi; cin >> xi;
int ai = Edges[ei - 1][0];
int bi = Edges[ei - 1][1];
if (Parents[ai] == bi) {
if (ti == 1)
Values[ai] += xi;
else {
Values[ai] -= xi;
Values[root] += xi;
}
}
else {
if (ti == 2)
Values[bi] += xi;
else {
Values[bi] -= xi;
Values[root] += xi;
}
}
}
vector<ll> Ans(N, 0);
auto dfsAns = [&](auto& self, int node, ll cursum)->void {
Ans[node - 1] = cursum;
trav(kid, Kids[node]) {
self(self, kid, cursum + Values[kid]);
}
};
dfsAns(dfsAns, root, Values[root]);
trav(x, Ans)
cout << x << "\n";
} | #include <stdio.h>
#include <vector>
#define N 200005
using namespace std;
long long sum[N];
long long ans[N];
int dis[N], dis_cnt;
int n;
struct EDGE
{
int x, y;
}edge[N];
vector<int> e[N];
void dfs(int x, int pa)
{
dis[x] = ++dis_cnt;
for (int i = 0; i < e[x].size(); i++) {
int y = e[x][i];
if (y != pa) dfs(y, x);
}
}
void dfs2(int x, int pa, long long total)
{
ans[x] = total + sum[x];
for (int i = 0; i < e[x].size(); i++) {
int y = e[x][i];
if (y != pa) dfs2(y, x, total+sum[x]);
}
}
int main()
{
scanf("%d", &n);
for (int i = 1; i < n; i++) {
scanf("%d %d", &edge[i].x, &edge[i].y);
e[edge[i].x].push_back(edge[i].y);
e[edge[i].y].push_back(edge[i].x);
}
dfs(1, 0);
int q;
scanf("%d", &q);
for (int i = 1; i <= q; i++) {
int t, a, b;
scanf("%d %d %d", &t, &a, &b);
if (t == 1) {
if (dis[edge[a].x] > dis[edge[a].y]) sum[edge[a].x] += b;
else {
sum[1] += b;
sum[edge[a].y] -= b;
}
}
else {
if (dis[edge[a].y] > dis[edge[a].x]) sum[edge[a].y] += b;
else {
sum[1] += b;
sum[edge[a].x] -= b;
}
}
}
dfs2(1, 0, 0LL);
for (int i = 1; i <= n; i++) printf("%lld\n", ans[i]);
return 0;
} |
#include <bits/stdc++.h>
#define ll long long
#define INF 1e9
#define pb push_back
#define mp make_pair
#define loop(a,n) for(long long i=a;i<n;i++)
#define vil vector<long long int>
#define vi vector<int>
#define sz(v) v.size()
#define setbits(x) __builtin_popcountll(x)
#define ff first
#define ss second
#define endl '\n'
using namespace std;
///order_of_key (k) : Number of items strictly smaller than k .
///find_by_order(k) : K-th element in a set (counting from zero).
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
// http://xorshift.di.unimi.it/splitmix64.c
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
int nCrevenoroddfinder(int n,int r)
{
int a=r;
int b=n-r;
for(int i=0;i<30;i++)
{
int x=1<<i;
if((x&a)&&(x&b))
{
return 0;//even
}
}
return 1;//odd
}
ll gcd(ll a, ll b) {
if (b == 0)return a;
return gcd(b, a%b);
}
ll extendeddgcd(ll a,ll b, ll &x,ll &y){
if(b==0){
x=1,y=0;
return a;
}
ll x1,y1;
ll d=extendeddgcd(b,a%b,x1,y1);
x=y1;
y=x1-(a/b)*y1;
return d;
}
bool isperfect(ll n) {
ll y = sqrt(n);
if (n % y == 0 && y * y == n)return true;
return false;
}
bool comp(pair<int,int> a, pair<int,int> b) {
if(a.first == b.first) return a.second>b.second;
return a.first < b.first;
}
ll powi(ll a, ll b) {
ll ans = 1;
while (b > 0) {
if (b & 1)ans = (ans * a);
b = b >> 1;
a = (a * a);
}
return ans;
}
bool isprime(ll n) {
for (int i = 2; i * i <= n; i++) {
if (n % i == 0)return false;
}
return true;
}
bool prime[10000000];
void seive() {
prime[1] = true;
for (int i = 2; i * i < 10000000; i++) {
if (prime[i])continue;
for (int j = i * i; j < 10000000; j += i) {
prime[j] = true;
}
}
}
int main()
{
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int t;
t=1;
while(t--){
ll n;
cin>>n;
string s;
cin>>s;
ll cnt=0;
ll q;cin>>q;
while(q--){
ll x;
ll a,b;
cin>>x>>a>>b;
if(x==1){
ll p,r;
if(a<=n) p=n+a;
else p=a-n;
if(b<=n) r=n+b;
else r=b-n;
if(cnt%2){
swap(s[p-1],s[r-1]);
}else swap(s[a-1],s[b-1]);
}else cnt++;
}
if(cnt%2){
for(int i=n;i<2*n;i++) cout<<s[i];
for(int i=0;i<n;i++) cout<<s[i];
}else
cout<<s;
cout<<endl;
}
}
| #pragma GCC optimize("Ofast")
#pragma GCC optimization("unroll-loops")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define deb(x) cout << #x << " " << x << endl;
#define mod 1000000007
#define fast std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define rall(v) v.rbegin(), v.rend()
const ll INF = 1e18;
//const ll NEGINF = -1 * INF;
const ll N = 1e6 + 1;
ll gcd(ll a, ll b)
{
if (b == 0)
{
return a;
}
return gcd(b, a % b);
}
ll my_pow(ll a, ll n, ll m = INF)
{
ll res = 1;
while (n)
{
if (n % 2)
{
res = (res * a) % m;
n--;
}
a = (a * a) % m;
n /= 2;
}
return res;
}
map<int, ll> mTrue, mFalse;
ll buildTrue(vector<bool> &a, int curr);
ll buildFalse(vector<bool> &a, int curr)
{
int n = a.size();
if (curr == 0)
{
if (a[curr])
{
return 1;
}
else
{
return 3;
}
}
if (mFalse.find(curr) != mFalse.end())
{
return mFalse[curr];
}
ll cnt = 0;
if (a[curr])
{
cnt += buildFalse(a, curr - 1);
}
else
{
cnt += 2 * buildFalse(a, curr - 1);
cnt += buildTrue(a, curr - 1);
}
mFalse[curr] = cnt;
return cnt;
}
ll buildTrue(vector<bool> &a, int curr)
{
int n = a.size();
if (curr == 0)
{
if (a[curr])
{
return 3;
}
else
{
return 1;
}
}
if (mTrue.find(curr) != mTrue.end())
{
return mTrue[curr];
}
ll cnt = 0;
if (a[curr])
{
cnt += buildFalse(a, curr - 1);
cnt += 2 * buildTrue(a, curr - 1);
}
else
{
cnt += buildTrue(a, curr - 1);
}
mTrue[curr] = cnt;
return cnt;
}
void solve()
{
ll n;
cin >> n;
vector<bool> a(n);
string t;
for (int i = 0; i < n; i++)
{
cin >> t;
if (t == "AND")
{
a[i] = false;
}
else
{
a[i] = true;
}
}
ll cnt = buildTrue(a, n - 1);
cout << cnt << endl;
}
int main()
{
fast;
#ifndef ONLINE_JUDGE
freopen("/home/kalit/Desktop/Data Structures-Algo-Competitive/src/codeforces/input.txt", "r", stdin);
freopen("/home/kalit/Desktop/Data Structures-Algo-Competitive/src/codeforces/output.txt", "w", stdout);
#endif
int T = 1;
while (T--)
{
solve();
}
//cout<< "Done in " << clock() / CLOCKS_PER_SEC <<"sec"<< endl;
return 0;
} |
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000007
using namespace std;
vector<ll> A(2001);
map<ll,ll> mapp;
ll bgcd(ll a, ll b)
{
if (b == 0)
return a;
return bgcd(b, a % b);
}
int main()
{
int N;
cin>>N;
A.resize(N+1);
ll minn=-1;
for(int i=1; i<=N; i++)
{
cin>>A[i];
if(A[i]<minn || minn==-1)
{
minn=A[i];
}
for(ll j=1; j*j<=A[i]; j++)
{
if(A[i]%j==0)
{
mapp[j]=bgcd(mapp[j],A[i]);
mapp[A[i]/j]=bgcd(mapp[A[i]/j], A[i]);
}
}
}
ll cnt=0;
for(auto u: mapp)
{
if(u.second==u.first && u.second<=minn)
{
cnt++;
}
}
cout<<cnt<<endl;
return 0;
} | #include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
typedef long long ll;
using namespace std;
ll gcd(ll a, ll b) {
if (a % b == 0ll) return b;
return gcd(b, a%b);
}
ll gcd_multi(vector<ll> A) {
ll n = A.size();
ll G = A[0];
for (ll i = 1; i < n; ++i) G = gcd(G, A[i]);
return G;
}
int main(int argc, char const *argv[]) {
ll n; cin>>n;
vector<ll> a(n);
rep(i,n) cin>>a[i];
map<ll, vector<ll>> mp;
auto div_cnt = [&](const ll m) {
for (ll i = 1; i*i <= m; ++i) {
if (m % i == 0ll) {
mp[i].push_back(m);
if (i != m/i) mp[m/i].push_back(m);
}
}
return;
};
unordered_set<ll> st;
ll mini = *min_element(a.begin(), a.end());
st.insert(mini);
for (auto &&e: a) div_cnt(e);
for (const auto [div, arr]: mp) {
if (gcd_multi(arr) == div) {
if (div <= mini) st.insert(div);
}
}
cout << st.size() << '\n';
return 0;
} |
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define mydeb(fmt, ...) fprintf(stderr, fmt, __VA_ARGS__)
//#define mydeb(fmt, ...)
int main()
{
uint64_t n;
int k;
cin >> n >> k;
rep(i,k)
{
if ((n%200)==0)
{
n/=200;
}
else
{
n*=1000;
n+=200;
}
}
cout << n << endl;
}
| #include "stdio.h"
long long f[1000010];
int l, r;
long long sol(int m, int n) {
long long ans = 0, num = 0;
for (int i = m; i > 1; -- i) {
f[i] = 1ll * (n / i) * (m / i);
for (int j = i << 1; j <= m; j += i)
f[i] -= f[j];
ans += f[i];
}
return ans;
}
main() {
scanf("%d%d", &l, &r);
(l == 1) && ++ l;
long long num = 0;
for (int i = l; i <= r; ++ i)
num += r / i;
printf("%lld", sol(r, r) - sol(l - 1, r) * 2 + sol(l - 1, l - 1) - 2 * num + r - l + 1);
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll = long long;
using P = pair<int,int>;
int main() {
int H, W, min, ans = 0;
cin >> H >> W;
vector <int> vec(H * W);
rep(i, H * W) cin >> vec.at(i);
sort(vec.begin(), vec.end());
min = vec.at(0);
rep(i, H * W) ans += (vec.at(i) - min);
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define FOR(i,l,r,d) for(int i=(l);i<=(r);i+=(d))
#define vi vector<int>
#define pii pair<int,int>
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define mkp make_pair
const int INF=2147483647;
const int MOD=1000000007;
const int mod=998244353;
int n;
int lim;
int v[1001],p[1001];
int sum;
int ptr;
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n>>lim;
lim*=100;
FOR(i,0,n-1,1){
cin>>v[i]>>p[i];
}
v[n] = INF;
p[n] = INF;
ptr=0;
while(sum<=lim){
sum += v[ptr]*p[ptr];
ptr++;
}
if(ptr==n+1) cout<<-1<<endl;
else cout<<ptr<<endl;
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); i++)
int main() {
int n; std::cin >> n;
std::vector<std::vector<int64_t> > a(3);
std::string rgb = "RGB";
REP(i, 2*n) {
int64_t x; std::cin >> x;
char c; std::cin >> c;
a[rgb.find(c)].push_back(x);
}
std::vector<int> res;
REP(i, 3) {
std::sort(a[i].begin(), a[i].end());
if (a[i].size() % 2)
res.push_back(i);
}
if (res.empty()) {
std::cout << 0 << '\n';
return 0;
}
int u = res[0];
int v = res[1];
auto cal = [&](int u, int v) {
int64_t ans = 1e18;
if (a[v].empty())
return ans;
for (int i = 0, j = 0; i < static_cast<int>(a[u].size()); i++) {
while (j+1 < static_cast<int>(a[v].size()) && a[v][j+1] <= a[u][i])
j++;
ans = std::min(ans, std::abs(a[u][i] - a[v][j]));
if (j+1 < static_cast<int>(a[v].size()))
ans = std::min(ans, std::abs(a[u][i] - a[v][j+1]));
}
return ans;
};
int w = 3 - u - v;
std::cout << std::min(cal(u, v), cal(u, w) + cal(v, w)) << '\n';
return 0;
} | #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
const int BUF = 200005;
const long long INF = 1LL << 60;
int N;
pair<long long, char> vCh[BUF];
void read() {
cin >> N;
N *= 2;
for (int i = 0; i < N; ++i) {
cin >> vCh[i].first >> vCh[i].second;
}
}
void work() {
vector<long long> v[3];
for (int i = 0; i < N; ++i) {
static string s = "RGB";
v[s.find(vCh[i].second)].push_back(vCh[i].first);
}
for (int i = 0; i < 3; ++i) {
sort(v[i].begin(), v[i].end());
}
vector<int> colors;
for (int i = 0; i < 3; ++i) {
if (v[i].size() % 2 != 0) {
colors.push_back(i);
}
}
if (colors.empty()) {
cout << 0 << endl;
return;
}
for (int i = 0; i < 3; ++i) {
if (v[i].size() % 2 == 0) {
colors.push_back(i);
}
}
long long minV = INF;
for (int i = 0; i < v[colors[0]].size(); ++i) {
vector<long long> &vList = v[colors[1]];
int idx = upper_bound(vList.begin(), vList.end(), v[colors[0]][i]) - vList.begin();
if (idx < vList.size()) {
minV = min(minV, llabs(vList[idx] - v[colors[0]][i]));
}
if (0 <= idx - 1) {
minV = min(minV, llabs(vList[idx - 1] - v[colors[0]][i]));
}
}
vector<pair<long long, int> > costId[2];
for (int i = 0; i < v[colors[2]].size(); ++i) {
for (int j = 0; j < 2; ++j) {
vector<long long> &vList = v[colors[j]];
int idx = upper_bound(vList.begin(), vList.end(), v[colors[2]][i]) - vList.begin();
long long toPush = INF;
if (idx < vList.size()) {
toPush = min(toPush, llabs(vList[idx] - v[colors[2]][i]));
}
if (0 <= idx - 1) {
toPush = min(toPush, llabs(vList[idx - 1] - v[colors[2]][i]));
}
costId[j].push_back(make_pair(toPush, i));
}
}
for (int i = 0; i < 2; ++i) {
sort(costId[i].begin(), costId[i].end());
}
for (int i = 0; i < min((int)costId[0].size(), 2); ++i) {
for (int j = 0; j < min((int)costId[1].size(), 2); ++j) {
if (costId[0][i].second != costId[1][j].second) {
minV = min(minV, costId[0][i].first + costId[1][j].first);
}
}
}
cout << minV << endl;
}
int main() {
read();
work();
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
bool flag=false;
string ans;
map<string , bool > mp;
for(int i=0;i<n;i++)
{
string s;
cin>>s;
if(s[0]=='!')
{
string r=s;
mp[s]=true;
int n=s.size();
r=r.substr(1,n-1);
if(mp.find(r)!=mp.end())
{
flag=true;
ans=r;
}
}
else
{
string r=s;
mp[s]=true;
reverse(r.begin(),r.end());
r.push_back('!');
reverse(r.begin(),r.end());
if(mp.find(r)!=mp.end()) {
flag=true;
ans=s;
}
}
}
if(flag) cout<<ans<<endl;
else cout<<"satisfiable"<<endl;
}
| #include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <complex>
#include <vector>
#include <limits>
#include <iomanip>
#include <cassert>
#include <numeric>
#include <chrono>
#include <random>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define debug(x) cerr << #x << " = " << (x) << endl;
#define debug_pii(x) cerr << "(" << x.first << "," << x.second << ")";
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n-1;i >= 0;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
const long double pi = 3.141592653589793;
const int mod = 1e9 + 7;
void solve() {
unordered_set<string> us1, us2;
int n;string s;cin>>n;
rep(i,n) {
cin>>s;
if(s[0] == '!') {
s.erase(s.begin());
us2.insert(s);
} else {
us1.insert(s);
}
}
for(auto x : us1) {
if(us2.count(x) == 1) {
cout << x << endl;
return;
}
}
cout << "satisfiable\n";
}
int main() {
// freopen("input.in","r",stdin);
// freopen("output.out","w",stdout);
// cout << fixed << setprecision(15);
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
// #include <atcoder/all>
// #include "icld.cpp"
using namespace std;
using ll = long long int;
using vi = vector<int>;
using si = set<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using ss = string;
using db = double;
template<typename T> using minpq = priority_queue <T,vector<T>,greater<T>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
#define V vector
#define P pair<int,int>
#define rep(i,s,n) for(int i=(s);i<(int)(n);i++)
#define rev(i,s,n) for(int i=(s);i>=(int)(n);i--)
#define reciv(v,n) vi (v)((n)); rep(i,0,(n))cin>>v[i]
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define ci(x) cin >> x
#define cii(x) ll x;cin >> x
#define cci(x,y) ll x,y;cin >> x >> y
#define co(x) cout << x << endl
#define pb push_back
#define eb emplace_back
#define rz resize
#define sz(x) int(x.size())
#define yn cout<<"Yes"<<endl;else cout<<"No"<<endl
#define YN cout<<"YES"<<endl;else cout<<"NO"<<endl
template<class T>void chmax(T &x,T y){x=max(x,y);}
template<class T>void chmin(T &x,T y){x=min(x,y);}
int main(){
cii(n);
vi va(n+1,0);
rep(i,0,n){
cii(a);
va[a]++;
}
reciv(vb,n);
reciv(vc,n),vc[i]--;
ll ans=0;
rep(j,0,n){
int now=vc[j];
int val=vb[now];
ans+=va[val];
}
co(ans);
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a(100001, 0), b(n), c(n);
int tmp;
for(int i = 0; i < n; i++) {
cin >> tmp;
a[tmp - 1]++;
}
for(int i = 0; i < n; i++) cin >> b[i];
for(int i = 0; i < n; i++) cin >> c[i];
long long ans = 0;
for(int i = 0; i < n; i++) {
ans += a[b[c[i] - 1] - 1];
}
cout << ans << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
pair<long long, long long> range(long long b, long long c) {
long long n = c / 2;
if (c % 2 == 0) {
if (c == 0) return {b, b};
else return {b - n, b + n - 1};
} else {
return {-b - n, -b + n};
}
}
int main() {
long long b, c;
cin >> b >> c;
auto [l1, r1] = range(b, c);
auto [l2, r2] = range(b, c - 1);
long long ans = (r1 - l1 + 1) + (r2 - l2 + 1) - max(0LL, min(r1, r2) - max(l1, l2) + 1);
cout << ans << '\n';
} | #include <bits/stdc++.h>
using namespace std;
//using namespace atcoder;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#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(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#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 chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define pb push_back
#define fi first
#define se second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void chOut(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }
using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using v_bool = vector<bool>;
using v_Pii = vector<Pii>;
//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};
const int mod = 1000000007;
//const int mod = 998244353;
signed main(){
int B, C; cin >> B >> C;
int ans = 0;
if(B > 0){
//[-B,B]
if(C >= 2 * B) ans++;
ans += min(B, C / 2 + 1);
ans += min(B, (C - 1) / 2 + 1);
//(-INF,-B)
ans += (C - 1) / 2;
//(B,INF)
if(C >= 4) ans += (C - 4) / 2 + 1;
}else if(B < 0){
//(-INF,B]
ans += C / 2 + 1;
//[-B,INF)
ans += (C - 1) / 2 + 1;
//(B,-B)
if(C >= 2 * (-B) + 1) ans++;
ans += min(-B - 1, (C - 1) / 2);
if(C >= 2) ans += min(-B - 1, (C - 2) / 2);
}else if(B == 0){
ans += C / 2 + 1;
ans += (C - 1) / 2;
}
Out(ans);
return 0;
}
|
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define setbits(x) __builtin_popcountll(x)
#define lp(a,n) for(ll i=a; i<n; i++)
#define lpi(a,n) for(int i=a; i<n; i++)
#define w(t) int t; cin>>t; while(t--)
#define vi vector<int>
#define vll vector<ll>
#define pll pair<ll, ll>
#define pii pair<int, int>
#define inf 1e9
#define LB lower_bound
#define UB upper_bound
const int mod = 1000000007;
using namespace std;
ll gcd(ll a,ll b){
if(a==0)return b;
return gcd(b%a,a);
}
ll lcm(ll a, ll b){
return (a*b)/gcd(a,b);
}
int prime[100007];
void SieveOfEratosthenes(int n)
{
memset(prime, -1, sizeof(prime));
for (int p=2; p*p<=n; p++)
{
if (prime[p] == -1)
{
for (int i=p*p; i<=n; i += p)
prime[i] = p;
}
}
}
int lps(string s){
int len = 0;
int n = s.length();
int dp[n];
dp[0] = 0;
for(int i=1; i<n; i++){
if(s[i] == s[len]){
len++;
dp[i] = len;
continue;
}
if(len!=0){
len = dp[len-1];
i--;
continue;
}
dp[i]=0;
}
return dp[n-1];
}
ll power(unsigned ll x,unsigned ll y)
{
ll res = 1;
while (y > 0)
{
if (y & 1)
res = res*x;
y = y>>1;
x = x*x;
}
return res;
}
//to calculate p1^x * p2^x2 *p3^x3 ----------
//i.e. prime factorization and store pi and xi in vector
vector<pair<ll, ll>> pFactor;
void factorize(long long n)
{
int count = 0;
// count the number of times 2 divides
while (!(n % 2)) {
n >>= 1; // equivalent to n=n/2;
count++;
}
// if 2 divides it
if (count)
pFactor.pb({2,count});
// check for all the possible numbers that can
// divide it
for (long long i = 3; i <= sqrt(n); i += 2) {
count = 0;
while (n % i == 0) {
count++;
n = n / i;
}
if (count)
pFactor.pb({i,count});
}
// if n at the end is a prime number.
if (n > 2)
pFactor.pb({n,1});
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n;
cin>>n;
vector<string> v(n+1);
int mx = -1;
lp(1,n+1){
cin>>v[i];
if(v[i]=="OR"){
mx = i;
}
}
ll ans = 0;
for(int i=n; i>=1; i--){
if(v[i]=="AND"){
continue;
}
ans += (1ll<<i);
}
ans++;
cout<<ans<<endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(),v.end()
#define MP make_pair
#define MT make_tuple
typedef int64_t ll;
#define PA pair<ll,ll>
#define TU tuple<ll,ll,ll>
#define vi vector<ll>
#define vii vector<vector<ll> >
#define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++)
#define rep2(i,m,n) for(ll (i)=(m); (i)<(ll)(n); (i)++)
const ll INF = 1ll<<30;
const ll INF2 = 1ll<<32;
int main() {
ll n;
cin >> n ;
vector<bool> b(n,true);
//ANDならfalse、ORならtrue
rep(i,n) {
string s;
cin >>s;
if(s=="AND") b.at(i) =false;
}
ll ans =0;
for(ll i=n-1; i>=0; i--) {
if(b.at(i)) ans += 1ll<<i+1;
}
cout << ans+1 << endl;
} |
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define lli long long int
#define tc int t;cin>>t;while(t--)
#define all(x) x.begin(),x.end()
#define f first
#define s second
#define pb push_back
#define vi vector<int>
#define vll vector<lli>
#define vpi vector<pair<int,int> >
#define vpll vector<pair<lli,lli> >
#define vvi vector<vector<int> >
#define vvll vector<vector<lli> >
#define maxn 100005
int main(){
fastio;
int n;
string s;
cin>>n>>s;
int ans=0;
for(int i=0;i<n;i++)
{
int fra=0,frt=0,frc=0,frg=0;
for(int j=i;j<n;j++){
if(s[j]=='A') fra++;
if(s[j]=='T') frt++;
if(s[j]=='C') frc++;
if(s[j]=='G') frg++;
if(fra==frt and frc==frg)
ans++;
}
}
cout<<ans<<"\n";
return 0;
}
| #include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <map>
using namespace std;
int main() {
ios::sync_with_stdio(false);
int n;
string s;
cin >> n >> s;
pair<int, int> cnt = {0, 0};
map< pair<int, int>, int > m;
m[cnt] = 1;
for (int i = 0; i < n; ++i) {
switch (s.at(i)) {
case 'A': ++cnt.first; break;
case 'T': --cnt.first; break;
case 'C': ++cnt.second; break;
case 'G': --cnt.second; break;
}
++m[cnt];
}
cout << accumulate(m.begin(), m.end(), 0, [](int init, pair< pair<int, int>, int> i) {
return init += i.second * (i.second - 1) / 2;
}) << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int maxn = 1e6 + 10;
int main() {
string s;
cin >> s;
int n = s.length();
vector<int> cnt(26);
ll ans = 0;
for (int i = n - 1; ~i; i--) {
int m = n - i;
int c = s[i] - 'a';
cnt[c]++;
if (i > n - 3) continue;
if (s[i] == s[i + 1] && s[i] != s[i + 2]) {
ans += m - cnt[c];
for (int i = 0; i < 26; i++) cnt[i] = 0;
cnt[c] = m;
}
}
cout << ans;
} | #include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define REPO(i,x) for(int i=x-1;i>=0;i--)
#define T int tc; cin>>tc;while(tc--)
#define READ freopen("input.txt","r", stdin)
#define mem(a,b) memset(a, b, sizeof(a))
#define lcm(a, b) ((a / __gcd(a, b) ) * b)
#define PI 2*acos(0.0)
#define pb push_back
#define eb emplace_back
#define ll long long
#define MAX 1e9
#define inf 1e18
#define MOD 1000000007
#define n0 cout<<"\n"
#define N 200001
int main()
{
int n; string s;cin>>s; n=s.size(); int cnt[26]={0}; ll an=0;
for(int i=n-1;i>=0;i--)
{ cnt[s[i]-'a']++;
if(i<n-1)
{
if(s[i]==s[i+1])
{
an+=n-i-cnt[s[i]-'a'];
memset(cnt,0,sizeof(cnt)); cnt[s[i]-'a']=n-i;
}
}
} cout<<an<<endl;
}
|
#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)
#define bit(n,k) ((n>>k)&1) //nのk bit目
#define vec(T) vector<T>
#define vvec(T) vector<vector<T>>
using ll = long long;
using P = pair<int,int>;
using Pll = pair<ll,ll>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll llINF = 1LL << 60;
const int iINF = 1e9;
//------------------------------------------------
struct Solver{
void solve(){
ll K;
cin >>K;
ll ans=0;
rep1(a,K){
rep1(d,K){
if(a*d>K) break;
for(ll b=1; b*b<=d; b++){
if(d%b!=0) continue;
if(d/b==b) ans++;
else ans+=2;
}
}
}
cout << ans << endl;
/*
ll ans = 0;
rep1(kk,K){
//cout << kk << endl;
rep1(a,kk){
if(kk%a!=0) continue;
ll l=kk/a;
for(ll b=1; b*b<=l; b++){
if(l%b!=0) continue;
if(l/b==b) ans++;
else ans+=2;
//cout << a << ","<<b <<"," << l/b<<" : " << ans << endl;
}
}
}
cout << ans << endl;
*/
}
};
int main(){
int testcasenum=1;
//cin >> testcasenum;
rep1(ti,testcasenum){
Solver solver;
solver.solve();
}
return 0;
}
| #include <bits/stdc++.h>
#include <chrono>
using namespace std;
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;
//container util
//------------------------------------------
#define PB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define ALL(a) (a).begin(),(a).end()
#define CLR(a) memset((a), 0 ,sizeof(a))
//constant
//--------------------------------------------
//clear memory
struct edge{LL to,cost,k;};
typedef pair<LL,LL> P;//firstは最短距離,secondは頂点番号
const int MAX_V=1e5+3;
const LL INF=LONG_MAX;
int main(){
int K;
cin>>K;
LL res=0;
for(LL A=1;A<=K;A++){
for(LL B=1;A*B<=K;B++){
for(LL C=1;A*B*C<=K;C++){
if(A*B*C<=K)res++;
}
}
}
cout<<res<<endl;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
int main(){
int v,t,s,d;
cin>>v>>t>>s>>d;
int st=v*t;
int en=v*s;
if(d<st||d>en)
cout<<"Yes";
else
cout<<"No";
return 0;
} | #include<iostream>
using namespace std;
int main()
{
long long n,m,t;
cin>>n>>m>>t;
long long answer = n;
int start,end;
cin>>start>>end;
answer -= (start);
if(answer<1){
cout<<"No"<<endl;
return 0;
}
answer+= (end-start);
if(answer>n){
answer=n;
}
for(int i = 1 ; i < m ; i++){
long long l = end;
cin>>start>>end;
answer-=(start-l);
if(answer<1){
cout<<"No"<<endl;
return 0;
}
answer+= (end-start);
if(answer>n){
answer=n;
}
}
answer-=(t-end);
answer<=0 ? cout<<"No":cout<<"Yes"<<endl;
return 0;
}
|
#include<bits/stdc++.h>
#define N 60
#define A(i,m,n) for(int i=m;i<=n;++i)
using namespace std;
typedef long long LL;
const LL mod=998244353;
int a[N][N],n,k;
inline bool check1(int x,int y){
A(i,1,n)if(a[x][i]+a[y][i]>k)return 0;
return 1;
}
inline bool check2(int x,int y){
A(i,1,n)if(a[i][x]+a[i][y]>k)return 0;
return 1;
}
LL fc[N];
int fa[N],siz[N];
int findfa(int x){
if(fa[x]!=x)fa[x]=findfa(fa[x]);
return fa[x];
}
inline void mer(int x,int y){
int tx=findfa(x),ty=findfa(y);
if(tx!=ty){
fa[tx]=ty;
siz[ty]+=siz[tx];
}
}
int main(){
cin>>n>>k;
fc[1]=1;
A(i,2,n)fc[i]=(fc[i-1]*i)%mod;
A(i,1,n){
A(j,1,n)cin>>a[i][j];
fa[i]=i;
siz[i]=1;
}
A(i,1,n)
A(j,i+1,n)
if(findfa(i)!=findfa(j)&&check1(i,j)==1)mer(i,j);
LL ans=1;
A(i,1,n)
if(findfa(i)==i)ans=ans*fc[siz[i]]%mod;
A(i,1,n)fa[i]=i,siz[i]=1;
A(i,1,n)
A(j,i+1,n)
if(findfa(i)!=findfa(j)&&check2(i,j)==1)mer(i,j);
A(i,1,n)
if(findfa(i)==i)ans=ans*fc[siz[i]]%mod;
printf("%lld\n",ans);
return 0;
} | #include<bits/stdc++.h>
#include<iostream>
#include<map>
#include<math.h>
#include<string>
#include<string.h>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
#define _GLIBCXX_DEBUG
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
using namespace std;
using ll=long long;
const ll INF=5000000000000;
const ll dx[8]={1,0,-1,0,1,1,-1,-1};
const ll dy[8]={0,1,0,-1,1,-1,1,-1};
ll mod(ll x,ll m){return x & m;}
ll modinv(ll a,ll m){ll b=m,u=1,v=0;while(b){ll t=a/b;a-=t*b;swap(a,b);u-=t*v;swap(u,v);}u%=m;if(u<0){u+=m;}return u;}
ll modpow(ll a,ll n,ll m){ll res=1;while(n>0){if(n&1){res=res*a%m;}a=a*a%m;n>>=1;}return res;}
ll npow(ll a,ll n){ll res=1;while(n>0){if(n&1){res=res*a;}a=a*a;n>>=1;}return res;}
ll yaku(ll x){ll cnt=0;for(int i=1;i*i<=x;i++){if(x%i==0){if(i==x/i){cnt++;}else{cnt+=2;}}}return cnt;}
ll modwaru(ll a, ll b, ll m){a%=m;return a*modinv(b,m)%m;}
ll gcd(ll x, ll y){if(x%y==0){return y;}else{return gcd(y, x % y);}}
ll lcm(ll a, ll b){return a/gcd(a, b)*b;}
struct UnionFind{vector<ll>par;UnionFind(ll N):par(N){for(ll i=0;i<N;i++)par[i]=i;}ll root(ll x){if(par[x]==x){return x;}return par[x]=root(par[x]);}void unite(ll x,ll y){ ll rx=root(x);ll ry=root(y);if(rx==ry){return;}par[rx]=ry;}bool same(ll x,ll y){ll rx=root(x);ll ry=root(y);return rx==ry;}};
int main(){
ll N, K;
cin >> N >> K;
vector<vector<ll>> A(N, vector<ll>(N));
UnionFind iti(N), ni(N);
for(int i = 0; i < N; i++){
for(int j = 0; j < N; j++) cin >> A[i][j];
}
for(int i = 0; i < N; i++){
for(int j = 0; j < N; j++){
if(i == j) continue;
bool b = true;
for(int k = 0; k < N; k++){
if(A[i][k] + A[j][k] > K) b = false;
}
if(b){iti.unite(i, j);}
}
}
for(int i = 0; i < N; i++){
for(int j = 0; j < N; j++){
if(i == j) continue;
bool b = true;
for(int k = 0; k < N; k++){
if(A[k][i] + A[k][j] > K) b = false;
}
if(b){ni.unite(i, j);}
}
}
ll ans1 = 1, ans2 = 1, mo = 998244353;
map<ll,ll> cnt1, cnt2;
for(int i = 0; i < N; i++){
cnt1[iti.root(i)]++;
cnt2[ni.root(i)]++;
}
for(pair<ll,ll> a : cnt1){
for(int i = 1; i <= a.second; i++){
ans1 *= i;
ans1 %= mo;
}
}
for(pair<ll,ll> a : cnt2){
for(int i = 1; i <= a.second; i++){
ans2 *= i;
ans2 %= mo;
}
}
cout << ans1 * ans2 % mo << endl;
} |
#include <bits/stdc++.h>
int ri() {
int n;
scanf("%d", &n);
return n;
}
int main() {
int n = ri();
int a[n];
for (auto &i : a) i = ri();
int res = 2000000000;
for (int i = 0; i < 1 << (n - 1); i++) {
int xored = 0;
int ored = 0;
for (int j = 0; j <= n; j++) {
if (j < n) ored |= a[j];
if (j == n || (i >> j & 1)) xored ^= ored, ored = 0;
}
res = std::min(res, xored);
}
printf("%d\n", res);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
int main(){
int n;
cin >> n;
vector<int> x(n), y(n);
rep(i, n) cin >> x[i] >> y[i];
REP(i, 0, n-3){
REP(j, i+1, n-2){
REP(k, j+1, n-1){
if((y[j]-y[i])*(x[k]-x[j]) == (x[j]-x[i])*(y[k]-y[j])){
cout << "Yes" << endl;
return 0;
}
}
}
}
cout << "No" << endl;
return 0;
}
|
#include <bits/stdc++.h>
// #include <atcoder/all>
// using namespace atcoder;
using namespace std;
#define rep2(i, m, n) for (int i = (m); i < (n); ++i)
#define rep(i, n) rep2(i, 0, n)
#define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i)
#define drep(i, n) drep2(i, n, 0)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#ifdef LOCAL
void debug_out() { cerr << endl; }
template <class Head, class... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...); }
#define debug(...) cerr << 'L' << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << 'L' << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif
template<class T> using V = vector<T>;
template<class T> using P = pair<T, T>;
using ll = long long;
using ld = long double;
using Vi = V<int>; using VVi = V<Vi>;
using Vl = V<ll>; using VVl = V<Vl>;
using Vd = V<ld>; using VVd = V<Vd>;
using Vb = V<bool>; using VVb = V<Vb>;
using Pi = P<int>;
using Pl = P<ll>;
using Pd = P<ld>;
template<class T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
template<class T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<class... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<class T> inline int sz(const T &x) { return x.size(); }
template<class T> inline bool chmin(T &a, const T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T &a, const T b) { if (a < b) { a = b; return true; } return false; }
template<class T1, class T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; }
template<class T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<class T> inline void deduplicate(vector<T> &a) { sort(all(a)); a.erase(unique(all(a)), a.end()); }
template<class T> inline int count_between(const vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline ll cDiv(const ll x, const ll y) { return (x+y-1) / y; } // ceil(x/y)
inline int fLog2(const ll x) { assert(x > 0); return 63-__builtin_clzll(x); } // floor(log2(x))
inline int cLog2(const ll x) { assert(x > 0); return (x == 1) ? 0 : 64-__builtin_clzll(x-1); } // ceil(log2(x))
inline int popcount(const ll x) { return __builtin_popcountll(x); }
inline void fail() { cout << -1 << '\n'; exit(0); }
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
// const int INF = (1<<30) - 1;
// const ll INFll = (1ll<<60) - 1;
// const ld EPS = 1e-10;
// const ld PI = acos(-1.0);
int main() {
char s, t; cin >> s >> t;
if (s == 'Y') t += 'A' - 'a';
cout << t << '\n';
}
| //#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define mod 1000000007
#define maxn 100011
#define el "\n"
#define pi acos(-1.0)
using namespace std;
#define lcm(a,b) (a/__gcd(a,b))*b
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL)
int main()
{
ios;
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
//cout<<fixed<<showpoint<<setprecision(7);
char s,t,a;
cin>>s>>t;
if(s=='Y'){
if(t=='a') a='A';
else if(t=='b') a='B';
else a='C';
}
else a=t;
cout<<a<<el;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD = 1e9 + 7;
ll modpow(ll a, ll b){
ll ans = 1;
while (b > 0){
if (b % 2 == 1){
ans *= a;
ans %= MOD;
}
a *= a;
a %= MOD;
b /= 2;
}
return ans;
}
ll modinv(ll a){
return modpow(a, MOD - 2);
}
vector<ll> mf = {1};
vector<ll> mfi = {1};
ll modfact(ll n){
if (mf.size() > n){
return mf[n];
} else {
for (ll i = mf.size(); i <= n; i++){
ll next = mf.back() * i % MOD;
mf.push_back(next);
mfi.push_back(modinv(next));
}
return mf[n];
}
}
ll modfactinv(ll n){
if (mfi.size() > n){
return mfi[n];
} else {
return modinv(modfact(n));
}
}
ll modbinom(ll n, ll k){
if (n < 0 || k < 0 || k > n){
return 0;
} else {
return modfact(n) * modfactinv(k) % MOD * modfactinv(n - k) % MOD;
}
}
int main(){
ll N, M, K;
cin >> N >> M >> K;
if (N > M + K){
cout << 0 << endl;
} else {
ll ans = modbinom(N + M, N);
ll a = N - K - 1, b = K + M + 1;
ans -= modbinom(a + b, a);
if (ans < 0){
ans += MOD;
}
cout << ans << endl;
}
}
| #include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define pii pair<ll,ll>
#define inf 1000000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define autoitr(x,it) for(auto it = x.rbegin(); it != x.rend(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
int main()
{
FAST/**/
ll n = 4;
ll arr[n];
rep(n)
cin>>arr[i];
ll lim = (1ll<<(n));
bool pos = 0;
repi(mask,lim)
{
ll sum = 0;
ll sum1 = 0;
repi(j,n)
{
sum1+=arr[j];
if((1ll<<j)&mask)
sum+=arr[j];
}
//cout<<sum<<" "<<sum1<<"\n";
if(sum == sum1/2 && sum1%2 == 0)
pos = 1;
}
if(pos)
cout<<"Yes\n";
else cout<<"No\n";
return 0;
}
|
/*
Code written by Talant I.D.
*/
#include <bits/stdc++.h>
//~ #include <ext/pb_ds/assoc_container.hpp>
//~ using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
//~ typedef tree <ll, null_type, less_equal <ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define precision(n) fixed << setprecision(n)
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define eps (double)1e-9
#define PI 2*acos(0.0)
#define endl "\n"
#define sz(v) int((v).size())
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define OK cout << "OK" << endl;
const int mod = 998244353;
ll mode(ll a) {
while (a < 0) {
a += mod;
}
return a % mod;
}
ll subt(ll a, ll b) {
return mode(mode(a)-mode(b));
}
ll add(ll a, ll b) {
return mode(mode(a)+mode(b));
}
ll mult(ll a, ll b) {
return mode(mode(a)*mode(b));
}
ll binpow(ll a, ll b) {
ll res = 1;
while (b) {
if (b&1) res = mult(res, a);
a = mult(a, a);
b >>= 1;
}
return res;
}
ll dp[10003][103];
ll fact[10003];
int main() {
do_not_disturb
fact[0] = fact[1] = 1;
for (ll i = 2; i < 10003; i++) {
fact[i] = mult(fact[i-1], i);
}
dp[0][0] = 1;
int n;
cin >> n;
vector <int> a(n);
for (auto &to : a) cin >> to;
for (auto to : a) {
for (int i = 5000; i >= to; i--) {
for (int j = 0; j < 100; j++) {
dp[i][j+1] = add(dp[i][j+1], dp[i-to][j]);
}
}
}
ll ans = 0;
ll sum = 0;
for (auto to : a) sum += to;
if (sum&1) {
cout << 0;
return 0;
}
sum /= 2;
for (int i = 0; i <= 100; i++) {
ans = add(ans, mult(dp[sum][i], mult(fact[i], fact[n-i])));
}
cout << ans;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define endl '\n'
#define INF 0x3f3f3f3f
#define LINF 1LL<<62
#define MSET(a) memset(a, 0, sizeof(a))
#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define key first
#define val second
#define pb push_back
template <typename T> bool ckmax(T &x, T y) {return x < y? (x = y, 1): 0;}
template <typename T> bool ckmin(T &x, T y) {return x > y? (x = y, 1): 0;}
inline int lc(int x) { return (x << 1);}
inline int rc(int x) { return (x << 1) + 1;}
inline int lowbit(int x) { return x&(-x);}
void extend_gcd(int64 a, int64 b, int64& d, int64& x, int64& y) {
if (b) {
extend_gcd(b, a%b, d, y, x);
y -= a/b*x;
} else d = a, x = 1, y = 0;
}
auto power(int64 a, int64 b, int64 mod) {
int64 res = a % mod;
while(b) {
if (b&1) res = res * a % mod;
a = a*a % mod;
b >>= 1;
}
return res;
}
void SetupIo() {
ios::sync_with_stdio(false);
cin.tie(0);
}
void Main();
int main() {
SetupIo();
Main();
return 0;
}
//----------------------
const int N = 2e4 + 10;
const int64 MOD = 998244353;
int n, m;
int a[N];
int64 dp[110][N];
int64 fac[N];
void pre() {
fac[0] = 1;
for(int i = 1; i < N; ++i) {
fac[i] = fac[i-1]*i % MOD;
}
//for(int i = 0; i < 20; ++i) cout << fac[i] << endl;
}
int64 Ans() {
int sum = 0;
for(int i = 0; i < n; ++i) sum += a[i];
if(sum % 2 == 1) return 0;
int s = sum / 2;
memset(dp, 0, sizeof(dp));
dp[0][0] = 1;
for(int i = 1; i <= n; ++i) {
int v = a[i-1];
for (int k = i; k >= 1; --k) {
for(int j = s; j - v >= 0; --j) {
dp[k][j] += dp[k-1][j-v];
if (dp[k][j] >= MOD) dp[k][j] -= MOD;
}
}
}
int64 ans = 0;
for(int i = 0; i <= n; ++i) {
if (dp[i][s] != 0) {
//cout << i << " " << s << ": " << dp[i][s] << endl;
int64 x = fac[i]*fac[n-i] % MOD;
ans += x*dp[i][s]%MOD;
ans %= MOD;
}
}
return ans;
}
void Main() {
pre();
cin >> n;
for(int i = 0; i < n; ++i) {
cin >> a[i];
}
cout << Ans() << endl;
}
|
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int H, W, X, Y;
cin >> H >> W >> X >> Y;
string S[100];
rep(i, H) cin >> S[i];
X--;
Y--;
int kotae = 1;
for (int i = X + 1; i < H; i++) {
if (S[i][Y] == '#') break;
else kotae++;
}
for (int i = X - 1; i >= 0; i--) {
if (S[i][Y] == '#') break;
else kotae++;
}
for (int i = Y + 1; i < W; i++) {
if (S[X][i] == '#') break;
else kotae++;
}
for (int i = Y - 1; i >= 0; i--) {
if (S[X][i] == '#') break;
else kotae++;
}
co(kotae);
Would you please return 0;
} | #include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main(){
int a, b, c, d;
cin >> a >> b >> c >> d;
int ans;
ans = min(a, b);
ans = min(ans, c);
ans = min(ans, d);
cout << ans << endl;
}
|
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
typedef long long ll;
typedef unsigned long long ull;
typedef short int si;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int nMax = 1e6+5;
const ll mod = 1e9+7;
string s,x;
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> s;
for (int i=0;i<s.size();i++) {
if (s[i] == '.')
break;
x += s[i];
}
cout << x << "\n";
return 0;
} | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
string s;
cin>>s;
if(s.find('.') != s.npos) {
s=s.substr(0,s.find('.'));
}
cout<<s<<endl;
} |
#include <bits/stdc++.h>
#define for0(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define forc(i, l, r) for (int i = (int)(l); i <= (int)(r); ++i)
#define forr0(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define forr1(i, n) for (int i = (int)(n); i >= 1; --i)
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin, (x).rend()
#define tr(c,i) for(__typeof__((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define sz(a) int((a).size())
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef double ld;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int a,b;
cin>>a>>b;
double c = (double)(a-b)/a * 100;
cout<<setprecision(24)<<c<<endl;
return 0;
} | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long int
#define pb push_back
#define pi pair<int, int>
#define pii pair<int, pi>
#define fir first
#define sec second
#define MAXN 2002
#define mod 1000000007
int modpow(int x, int y)
{
int z = 1;
while (y)
{
if (y & 1)
z = (z * x) % mod;
x = (x * x) % mod;
y >>= 1;
}
return z;
}
int subtract(int a, int b)
{
return (a - b < 0) ? a - b + mod : a - b;
}
int multiply(int x, int y)
{
return (x * y) % mod;
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, p;
cin >> n >> p;
int ans = multiply(subtract(p, 1), modpow(subtract(p, 2), subtract(n, 1)));
cout << ans << endl;
return 0;
}
// prefix sum nunca pode dar 0
// primeiro cara = (p - 1) possibilidades
// segundo cara = (p - 2) possibilidades
// terceiro cara = (p - 2) possibilidades
// ...
// (p - 1) * (p - 2)^n - 1 |
#include<bits/stdc++.h>
#include <string>
#include<vector>
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
int main()
{
int n;
cin>>n;
int a[n],i;
for(i=0;i<n;i++)
cin>>a[i];
set<int> s(a,a+n);
if(s.size()==n)
cout<<"Yes";
else
cout<<"No";
return 0;
} | // ConsoleApplication1.cpp : Defines the entry point for the console application.
//
#include <stack>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <queue>
#include <climits>
#define MAXCHAR 255
#define ll long long
using namespace std;
const ll dividend = 1000000007;
const ll limit = pow(10, 18);
const ll bigNum = pow(10, 9);
const int intMax = 2147483647;
ll funcComb(int n, int k)
{
ll output = 1;
int sum = n + k;
vector<int> dividends;
for (int i = 0; i < k; i++)
{
dividends.push_back(k - i);
}
for (int i = 0; i < k; i++)
{
output *= sum - i;
for (auto it = dividends.begin(); it != dividends.end(); it++)
{
if (*it == 0)
continue;
if (output % *it == 0)
{
output /= *it;
*it = 0;
}
}
if (output > dividend)
{
output %= dividend;
}
}
return output;
}
ll funcPow(int n, int r)
{
ll ret = 1;
for (int i = 1; i <= r; i++)
{
ret *= n;
if (ret > dividend)
ret %= dividend;
}
return ret;
}
vector<int> A;
vector<int> Ns;
int main()
{
int N;
cin >> N;
for (int i = 0; i < N; ++i)
{
int a;
cin >> a;
A.push_back(a);
Ns.push_back(i + 1);
}
sort(A.begin(), A.end());
if (A == Ns)
cout << "Yes" << endl;
else
cout << "No" << endl;
return 0;
} |
//* Jai shree Ram
#include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define lli long long int
#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define vi vector<int>
#define vll vector<ll>
#define all(a) a.begin(),a.end()
#define sz(a) (int)a.size()
#define pb push_back
#define ppb pop_back
#define pf push_front
#define fr first
#define sc second
#define uniq(v) (v).erase(unique(all(v)),(v).end())
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
template<typename T,typename T1>T amax(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T amin(T &a,T1 b){if(b<a)a=b;return a;}
// __builtin_popcountll(x);
// __builtin_clz(x) // Count Leading zeros
// __builtin_ctz(x) // Trailing zeros
const int MM = 998244353;
const int mod = 1e9 + 7;
const int INF = 1e9 + 5;
const int N = 1e5 + 5;
void solve()
{
int n;
cin >> n;
vll a(n);
map<ll,ll> mpp;
for(ll &x : a) {
cin >> x;
mpp[x%200]++;
}
ll ans = 0;
for(auto x : mpp) {
ans += x.sc*(x.sc-1)/2;
}
cout << ans << "\n";
}
signed main()
{
ios;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
#ifdef SIEVE
sieve();
#endif
#ifdef NCR
init();
#endif
int t;
t=1;
// cin>>t;
while(t--)
{
solve();
}
}
/* stuff you should look for
* int overflow, array bounds
* special cases (n=1?)
* remember out of bounds case mainly in if else
* do smth instead of nothing and stay organized
* WRITE STUFF DOWN
*/ | #include <vector>
#include <stdio.h>
using namespace std;
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll = long long;
using P = pair<int,int>;
#define pcnt __builtin_popcount//1ビットがたっている数を数える
int main() {
int n;
cin >> n;
int a[n];
ll b[200] = {0};
rep(i,n)
{
cin >> a[i];
b[a[i]%200]++;
}
ll ans = 0;
rep(i,200)
{
ans += (b[i]*(b[i]-1))/2;
}
cout << ans << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<n; i++)
int main() {
int n;
string s,t;
cin >> n >> s >> t;
vector<int> sz,tz;
rep(i,n){
if(s[i] == '0') sz.push_back(i);
if(t[i] == '0') tz.push_back(i);
}
int ans = 0;
if(sz.size() != tz.size()) cout << -1 << endl;
else{
rep(i,sz.size()){
if(sz[i] != tz[i]) ans++;
}
cout << ans << endl;
}
} | #include <iostream>
#include <string>
#include <vector>
int main()
{
int N;
std::string S, T;
std::cin >> N >> S >> T;
int SS = 0, TT = 0;
for (int i = N - 1; i >= 0; i--)
{
if (S[i] == '1')
{
SS++;
}
}
for (int i = N - 1; i >= 0; i--)
{
if (T[i] == '1')
{
TT++;
}
}
if (SS != TT)
{
std::cout << "-1" << std::endl;
return 0;
}
int AT = 0, COUNT = 0, tmp;
while (AT < N)
{
if (S[AT] == T[AT])
{
AT++;
continue;
}
else
{
if (S[AT] == '1')
{
tmp = AT + 1;
while (S[tmp] == '1')
{
tmp++;
}
S[AT] = '0';
S[tmp] = '1';
COUNT++;
AT++;
}
else
{
tmp = AT + 1;
while (T[tmp] == '1')
{
tmp++;
}
T[AT] = '0';
T[tmp] = '1';
COUNT++;
AT++;
}
}
}
std::cout << COUNT << std::endl;
return 0;
} |
#include<iostream>
#include<vector>
using namespace std;
using ll = long long;
const int mod = 1e9+7;
struct mint {
ll x; // typedef long long ll;
mint(ll x=0):x((x%mod+mod)%mod){}
mint operator-() const { return mint(-x);}
mint& operator+=(const mint a) {
if ((x += a.x) >= mod) x -= mod;
return *this;
}
mint& operator-=(const mint a) {
if ((x += mod-a.x) >= mod) x -= mod;
return *this;
}
mint& operator*=(const mint a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const {
mint res(*this);
return res+=a;
}
mint operator-(const mint a) const {
mint res(*this);
return res-=a;
}
mint operator*(const mint a) const {
mint res(*this);
return res*=a;
}
mint pow(ll t) const {
if (!t) return 1;
mint a = pow(t>>1);
a *= a;
if (t&1) a *= *this;
return a;
}
// for prime mod
mint inv() const {
return pow(mod-2);
}
mint& operator/=(const mint a) {
return (*this) *= a.inv();
}
mint operator/(const mint a) const {
mint res(*this);
return res/=a;
}
friend ostream& operator<<(ostream& os, const mint& m){
os << m.x;
return os;
}
};
int main(){
int N;
cin >> N;
vector<int> A(N);
for(int i=0;i<N;i++)cin >> A[i];
vector<vector<mint>> dp1(N+1,vector<mint>(2)),dp2(N+1,vector<mint>(2));
dp1[1][0] = 1;
dp2[1][0] = A[0];
for(int i=2; i<=N; i++){
dp1[i][0] += dp1[i-1][0] + dp1[i-1][1];
dp1[i][1] += dp1[i-1][0];
dp2[i][0] += dp2[i-1][0] + dp2[i-1][1] + dp1[i][0]*A[i-1];
dp2[i][1] += dp2[i-1][0] - dp1[i][1]*A[i-1];
}
cout << dp2[N][0] + dp2[N][1] << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ll long long
int main(){
ll n;
cin >> n;
vector<ll> a(n);
ll sigma = 0;
ll p = 0;
ll maxd = 0;
ll ans = 0;
for(ll i=0;i<n;i++){
cin >> a.at(i);
sigma += a.at(i);
maxd = max(maxd,sigma);
ans = max(ans,p+maxd);
p += sigma;
ans = max(ans,p);
}
cout << ans << endl;
return 0;
} |
#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
#define vv(type, name, h, ...) vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...) vector<vector<vector<type>>> name(h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
using namespace std;
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
typedef long long lli;
typedef pair<int,int> ii;
typedef vector<int> vi;
#define deb(x) cout << #x": " << (x) << endl;
lli gcd(lli a, lli b){return (b?gcd(b,a%b):a);}
lli lcm(lli a, lli b){ if(!a || !b) return 0; return a * b / gcd(a, b); }
int popcount(lli x) { return __builtin_popcountll(x); }
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// int rnd(int n){return uniform_int_distribution<int>(0, n-1)(rng);}
lli poww(lli a, lli b){
lli res =1;
while(b){ if(b&1) res = res * a; a = a*a; b/=2; }
return res;
}
vvc<int> graph(int n, int m, bool dir=1){
vv(int,v,n+1,0);
fore(i,0,m){
int a,b; cin>>a>>b;
v[a].pb(b);
if(dir)v[b].pb(a);
}
return v;
}
template <typename T> static constexpr T inf = numeric_limits<T>::max() / 2;
// ---- コーディングはここから! ('-')7
void solve(){
int n,m; cin>>n>>m;
vv(int,v,n,n,inf<int>);
fore(i,0,m){
int a,b,c; cin>>a>>b>>c;a--,b--;
v[a][b]=min(v[a][b],c);
}
vv(ii,g,n+1);
fore(i,0,n)fore(j,0,n)if(v[i][j]!=inf<int>)g[i].pb({j,v[i][j]});
auto dij=[&](int a){
using pp = pair<int,lli>;
priority_queue<pp>q;
q.push({0,n});
g[n]=g[a];
vc<lli>dp(n+1,inf<lli>);
dp[n]=0;
while(!q.empty()){
auto p=q.top(); q.pop();
auto [y,x]=p;
y*=-1;
if(y!=dp[x])continue;
if(x==a)return y;
for(auto [i,j]:g[x])if(dp[i]>y+j){
dp[i]=y+j;
q.push({-dp[i],i});
}
}
return -1;
};
fore(i,0,n)cout<<dij(i)<<ENDL;
}
int main(){_
//int t; cin>>t; while(t--)
solve();
}
| //BISMILLAHIR RAHMANIR RAHIM
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define mem(a, b) (memset(a, b, sizeof(a)))
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
#define PI acos(-1)
#define INF 2147483647
#define MOD 1000000007
#define MAX 2005
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ii, int> pii;
typedef vector<ii> vii;
typedef priority_queue<int,vector<int>,greater<int> > PQ;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
int setBit(int mask, int pos){return mask = mask | (1<<pos);}
bool checkBit(int mask, int pos){return (bool)(mask & (1<<pos));}
vector<pair<int, int> > adj[MAX];
ll dist[MAX][MAX];
int n;
void dijkstra(int src) {
priority_queue<ii> q;
q.push(mk(-0, src));
dist[src][src] = 0;
while (!q.empty()) {
ii x = q.top();
q.pop();
int cur = x.ss;
int sz = adj[cur].size();
for (int i = 0; i < sz; i++) {
if (dist[src][adj[cur][i].ff] > dist[src][cur] + adj[cur][i].ss) {
dist[src][adj[cur][i].ff] = dist[src][cur] + adj[cur][i].ss;
q.push(mk(-dist[src][adj[cur][i].ff], adj[cur][i].ff));
}
}
}
}
int main() {
int m;
scanf("%d %d", &n, &m);
vector<ll> ans(n + 1, INF);
for(int i = 0; i <= n; i++) {
for(int j = 0; j <= n; j++) {
dist[i][j] = 1e12;
}
}
map<ii, int> mp;
for (int i = 0; i < m; i++) {
int x, y, w;
scanf("%d %d %d", &x, &y, &w);
if(x == y) {
ans[x] = min(ans[x], (ll) w);
}
else {
if(mp.count(mk(x, y))) {
mp[mk(x, y)] = min(mp[mk(x, y)], w);
}
else{
mp[mk(x,y)] = w;
}
}
}
for(map<ii, int> :: iterator it = mp.begin(); it != mp.end(); it++) {
adj[it->ff.ff].pb(mk(it->ff.ss, it->ss));
}
for(int i = 1; i <= n; i++) {
dijkstra(i);
}
for(int j = 1; j <= n; j++) {
for(int i = 1; i <= n; i++) {
if(i != j) {
ans[i] = min(ans[i], dist[i][j] + dist[j][i]);
}
}
}
for(int i = 1; i <= n; i++) {
if(ans[i] == INF)
printf("-1\n");
else
printf("%d\n", ans[i]);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main()
{
string s;
set<char> ele;
cin >> s;
for (auto i: s)
{
ele.insert(i);
}
if (ele.size() == 1)
cout << "Won";
else
cout << "Lost";
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main(){
string str;
cin>>str;
if(str[0]==str[1]&&str[1]==str[2]) cout<<"Won";
else cout<<"Lost";
return 0;
} |
/*
* @Author: Luisvacson
* @LastEditors: Luisvacson
* @Descriptions: None
* @Date: 2021-06-12 19:05:10
* @LastEditTime: 2021-06-12 19:38:21
* @FilePath: \C++\Public\ABC203D - Pond.cpp
*/
#include <bits/stdc++.h>
using namespace std;
int n, k, t;
int a[805][805], b[805][805];
int sum[805][805];
inline bool check(int mid) {
register int i, j;
memset(b, 0, sizeof(b));
memset(sum, 0, sizeof(sum));
for (i = 1; i <= n; ++i) {
for (j = 1; j <= n; ++j) {
if (a[i][j] > mid) b[i][j] = 1;
}
}
for (i = 1; i <= n; ++i) {
for (j = 1; j <= n; ++j) {
sum[i][j] =
sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + b[i][j];
}
}
for (i = 0; i <= n - k; ++i) {
for (j = 0; j <= n - k; ++j) {
if ((sum[i + k][j + k] + sum[i][j] - sum[i][j + k] -
sum[i + k][j]) < t)
return true;
}
}
return false;
}
signed main() {
scanf("%d%d", &n, &k);
t = ((k * k) >> 1) + 1;
register int i, j;
int l = 0, r = 0, mid, ans = 0;
for (i = 1; i <= n; ++i) {
for (j = 1; j <= n; ++j) {
scanf("%d", &a[i][j]);
r = max(r, a[i][j]);
}
}
while (l <= r) {
mid = l + r >> 1;
if (check(mid)) {
r = mid - 1;
ans = mid;
} else
l = mid + 1;
}
printf("%d\n", ans);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define mp make_pair
#define fr first
#define sc second
template<class T> T T_INF(){ return 1000000000000000000; }
template<> int T_INF<int>(){ return 1000000000; }
template<int MOD> struct modint{
ull val;
modint(ull x){ val=x%MOD; }
modint(){}
friend modint modpow(modint x,ull k){
modint ret(1ULL);
while(k>0){
if(k&1ULL)ret*=x;
x*=x;
k>>=1;
}
return ret;
}
modint& operator +=(const modint& rhs){
this->val+=rhs.val;
if(this->val>=MOD)this->val-=MOD;
return *this;
}
friend modint operator+(modint lhs, const modint& rhs){
lhs+=rhs;
return lhs;
}
modint& operator -=(const modint& rhs){
this->val+=MOD-rhs.val;
if(this->val>=MOD)this->val-=MOD;
return *this;
}
friend modint operator-(modint lhs, const modint& rhs){
lhs-=rhs;
return lhs;
}
modint& operator *=(const modint& rhs){
this->val*=rhs.val;
this->val%=MOD;
return *this;
}
friend modint operator*(modint lhs, const modint& rhs){
lhs*=rhs;
return lhs;
}
static vector<modint> inv_;
static void precalc_inv_(int k){
int t=inv_.size();
inv_.resize(k);
for(int i=t;i<k;i++){
inv_[i]=modpow(modint(i),MOD-2);
}
}
modint& operator /=(const modint& rhs){
//if(rhs.val<inv_.size()){
// (*this)*=inv_[rhs.val];
//}
//else {
(*this)*=modpow(rhs,MOD-2);
//}
return *this;
}
friend modint operator/(modint lhs, const modint& rhs){
lhs/=rhs;
return lhs;
}
static vector<vector<modint>> C_;
static vector<modint> fac,inv_fac;
static void precalc_C_(int k){
C_.resize(k,vector<modint>(k));
for(int i=0;i<k;i++){
C_[i][0]=C_[i][i]=1;
for(int j=1;j<=i-1;j++){
C_[i][j]=C_[i-1][j-1]+C_[i-1][j];
}
}
}
static void precalc_fac(int k){
fac.resize(k);
inv_fac.resize(k);
fac[0]=inv_fac[0]=1;
for(int i=1;i<k;i++){
fac[i]=fac[i-1]*i;
inv_fac[i]=modpow(fac[i],MOD-2);
}
}
static modint C(ll n,ll k,int type=0){
if(k<0||k>n)return 0;
if(type==0){
return C_[n][k];
}
else {
return fac[n]*inv_fac[k]*inv_fac[n-k];
}
}
};
template<int MOD> vector<modint<MOD>> modint<MOD>::inv_;
template<int MOD> vector<vector<modint<MOD>>> modint<MOD>:: C_;
template<int MOD> vector<modint<MOD>> modint<MOD>::fac;
template<int MOD> vector<modint<MOD>> modint<MOD>::inv_fac;
const int MOD=1000000007;
typedef modint<MOD> mi;
int n;
int a[100010];
mi dp[100010][2];
mi f(int i){
if(i==-2)return 0;
if(i<=0)return 1;
return dp[i][0]+dp[i][1];
}
int main(){
scanf("%d",&n);
for(int i=0;i<n;i++)scanf("%d",&a[i]);
dp[1][0]=dp[1][1]=1;
for(int i=2;i<100010;i++){
dp[i][0]=dp[i-1][0]+dp[i-1][1];
dp[i][1]=dp[i-1][0];
}
mi ret=0;
for(int i=0;i<n;i++){
ret+=f(i-1)*f(n-1-i)*a[i];
ret-=f(i-2)*f(n-2-i)*a[i];
}
cout<<ret.val<<endl;
} |
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 1000000007;
// constexpr int MOD = 998244353;
constexpr int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
constexpr int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
IOSetup() {
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
std::cout << fixed << setprecision(20);
}
} iosetup;
int main() {
constexpr int N = 2;
int candy[N]; REP(i, N) cin >> candy[i];
int c; cin >> c;
while (true) {
if (candy[c] == 0) {
cout << (c == 0 ? "Aoki\n" : "Takahashi\n");
return 0;
}
--candy[c];
c ^= 1;
}
}
| #define as(array) (sizeof(array)/sizeof(array[0]))
#define ll long long
#define dd double
#define mp make_pair
#define pb push_back
#define se second
#define fi first
#define mod 10000007
#define sob(v) v.begin(),v.end()
#define sobr(v) v.rbegin(),v.rend()
#define fr(i,a,b) for(int i=a;i<=b;++i)
#define frr(i,a,b) for(int i=a;i>=b;--i)
#define pi acos(-1.00)
#define check cout<<"*"<<endl
#define ffix(x) cout<<fixed<<setprecision(x)
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
// Ascending sort: sort(arra, arra+n)
// Descending sort: sort(arra, arra+n, greater<int>())
#include <bits/stdc++.h>
using namespace std;
bool binarySearch(int arra[],int arraySize, int key){
int startPoint, endPoint;
int location;
startPoint = 0;
endPoint = arraySize - 1;
while(startPoint <= endPoint){
int midPoint = (startPoint + endPoint) / 2;
if(arra[midPoint] == key){
return true;
break;
}
else if(arra[midPoint] < key){
startPoint = midPoint + 1;
}
else
{
endPoint = midPoint - 1;
}
}
return false;
}
void insert(int arra[], int arraySize, int position, int item){
for(int i = arraySize - 1; i >= position-1; i--){
arra[i+1] = arra[i];
}
arra[position-1] = item;
}
int count = 0;
int main() {
int A, B, W;
cin >> A >> B >> W;
int hi, lo;
W *= 1000;
hi = (W / A);
if(W % A > hi * (B - A)){
cout << "UNSATISFIABLE";
return 0;
}else if(W % B == 0){
lo = W / B;
}else{
lo = (W / B) + 1;
}
cout << lo << " " << hi;
} |
#include <iostream>
using namespace std;
int main()
{
int a, b, c;
cin >> a >> b >> c;
int sum;
sum = 21 - a - b - c;
cout << sum << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main () {
int a, b, c, d;
cin >> a >> b >> c >> d;
cout << a*d - b*c << endl;
} |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
ll ans=0,n,k;cin>>n>>k;
map<ll,ll>a;
while(n--)
{
ll x,y;cin>>x>>y;
a[x]+=y;
}
ll pre=0,j=0;
for(auto i=a.begin();i!=a.end();i++)
{
if(k>=(i->first)-pre)
{
k=k-(i->first)+pre;
/*
3 2
2 3
5 5
*/
pre=(i->first);
k=k+i->second;
}
else
{
cout<<k+pre;
j=1;
break;
}
}
if(j==0)
cout<<k+pre;
}
| #include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int long long
#define w(x) int x; cin>>x; while(x--)
#define mii map<int,int>
#define endl ("\n")
#define vi vector<int>
#define pqb priority_queue<int>
#define pqs priority_queue<int,vi,greater<int> >
#define pii pair<int,int>
#define f(i, a, n) for(int i=a; i<n; i++)
#define fd(i, a, n, d) for(int i=a; i<n; i+=d)
#define in(a,n) f(i,0,n){cin>>a[i];}
#define pb push_back
#define yy cout<<"YES\n"
#define nn cout<<"NO\n"
#define kk cout<<"-1\n"
#define inf (long long)1e18
#define mod 1000000007LL
#define cc(r) cout<<r<<" "
#define ce(r) cout<<r<<endl
#define out(a,n) f(i,0,n){cc(a[i]);}
//No use
void inout()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
//No use
void ovector_n() {
ce(1);
}
int32_t main()
{
inout();
int T = clock();
int n, k, a, b;
cin >> n >> k;
mii m;
int tb = k;
f(i, 0, n) {
cin >> a >> b;
m[a] += b;
}
for (auto it : m) {
//cc(a);
//ce(b);
a = it.ff;
b = it.ss;
if (tb < a)
break;
tb += b;
}
ce(tb);
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=100005;
ll a[N],n,m,k;
int check(ll x)
{
int now=upper_bound(a+1,a+1+n,x)-a-1;
return x-now>=k;
}
void solve()
{
cin>>k;
ll l=1,r=2e18+10LL;
while(r-l>1)
{
ll mid=(l+r)>>1;
if(check(mid)) r=mid;
else l=mid;
}
if(check(l)) printf("%lld\n",l);
else printf("%lld\n",r);
}
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++) cin>>a[i];
while(m--) solve();
} | #include <bits/stdc++.h>
using namespace std;
#define int ll
#define FOR(i,s,e) for(ll i = s; i <= (ll)e; ++i)
#define DEC(i,s,e) for(ll i = s; i >= (ll)e; --i)
#define IAMSPEED ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef LOCAL
#define db(x) cerr << #x << "=" << x << "\n"
#define db2(x, y) cerr << #x << "=" << x << " , " << #y << "=" << y << "\n"
#define db3(a,b,c) cerr<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<"\n"
#define dbv(v) cerr << #v << ":"; for (auto ite : v) cerr << ite << ' '; cerr <<"\n"
#define dbvp(v) cerr << #v << ":"; for (auto ite : v) cerr << "{" << ite.f << ',' << ite.s << "} "; cerr << "\n"
#define dba(a,ss,ee) cerr << #a << ":"; FOR(ite,ss,ee) cerr << a[ite] << ' '; cerr << "\n"
#define reach cerr << "LINE: " << __LINE__ << "\n";
#else
#define db(x)
#define db2(x,y)
#define db3(a,b,c)
#define dbv(v)
#define dbvp(v)
#define dba(a,ss,ee)
#define reach
#endif
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define g0(x) get<0>(x)
#define g1(x) get<1>(x)
#define g2(x) get<2>(x)
#define g3(x) get<3>(x)
typedef pair <ll, ll> pi;
typedef tuple<ll,ll,ll> ti3;
typedef tuple<ll,ll,ll,ll> ti4;
ll rand(ll a, ll b) { return a + rng() % (b-a+1); }
const int MOD = 1e9 + 7;
const int inf = (int)1e9 + 500;
const long long oo = (ll)1e18 + 500;
template <typename T> bool chmax(T& a, const T b) { return a<b ? a = b, 1 : 0; }
template <typename T> bool chmin(T& a, const T b) { return a>b ? a = b, 1 : 0; }
const int MAXN = -1;
vector<int> v;
int n,Q;
int k;
bool check(int x) {
int smaller = upper_bound(all(v), x) - v.begin();
if(x-smaller<k)return 1;
else return 0;
}
int32_t main()
{
IAMSPEED
cin >> n >> Q;
FOR(i,1,n) {
int x; cin >> x;
v.pb(x);
}
sort(all(v));
while(Q--) {
cin >> k;
int lo = 0, hi = (ll)2e18;
while(lo < hi-1) {
int mid=(lo+hi)/2;
if(check(mid))lo=mid;
else hi=mid;
}
cout << lo+1 << '\n';
}
}
|
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------
int T;
int N;
int P[555];
vector<int> R;
void go(int x) {
swap(P[x],P[x+1]);
R.push_back(x);
}
void solve() {
int i,j,k,l,r,x,y; string s;
cin>>T;
while(T--) {
cin>>N;
FOR(i,N) {
cin>>P[i];
P[i]--;
}
R.clear();
int step=0;
for(i=N-1;i>=3;i--) {
FOR(j,N) if(P[j]==i) break;
if(j==i) continue;
if(i==3&&j==2&&step==1) {
go(1);
go(2);
j=1;
}
while(j<i) {
if(step==j%2) {
go(j);
j++;
}
else if(step==0) {
if(j==1) go(2);
else go(0);
}
else {
if(j==2) go(3);
else go(1);
}
step^=1;
}
}
while(1) {
for(j=N-1;j>=0;j--) if(P[j]!=j) break;
if(j<0) break;
assert(j<3);
swap(P[step],P[step+1]);
R.push_back(step);
step^=1;
}
cout<<R.size()<<endl;
FOR(i,R.size()) {
assert(R[i]%2==i%2);
cout<<(R[i]+1)<<" ";
}
cout<<endl;
FOR(i,N) assert(P[i]==i);
}
}
int main(int argc,char** argv){
string s;int i;
if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
cout.tie(0); solve(); return 0;
}
| #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, b) for(ll i = (a); i < (b); i++)
#define REP(i, a) FOR(i, 0, a)
ll T, X, Y, P, Q;
ll extgcd(ll a, ll b, ll& x, ll &y){
ll d = a;
if(b != 0){
d = extgcd(b, a % b, y, x);
y -= (a / b) * x;
}else{
x = 1; y = 0;
}
return d;
}
ll gcd(ll a, ll b){
ll x, y;
return extgcd(a, b, x, y);
}
ll mod_inverse(ll a, ll m){
ll x, y;
extgcd(a, m, x, y);
return (m + x % m) % m;
}
int main(){
cin >> T;
REP(cs, T){
cin >> X >> Y >> P >> Q;
ll ans = -1;
REP(y, Y){
REP(q, Q){
ll x = X + y, m = 2 * (X + Y), b1 = P + q, m1 = P + Q;
ll b = b1 - x, d = gcd(m1, m);
if(b % d != 0) continue;
ll t = b / d * mod_inverse(m / d, m1 / d) % (m1 / d);
x = x + m * t;
m *= m1 / d;
x = (m + x % m) % m;
if(ans == -1){
ans = x;
}else{
ans = min(ans, x);
}
}
}
if(ans == -1){
cout << "infinity" << endl;
}else{
assert(ans >= 0);
cout << ans << endl;
}
}
}
|
#include <bits/stdc++.h>
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
const i64 P = 998244353;
const int maxn = 3100;
i64 dp[maxn][maxn];
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.precision(10);
cout << fixed;
#ifdef LOCAL_DEFINE
freopen("input.txt", "rt", stdin);
#endif
dp[0][0] = 1;
for1(i, maxn - 1) ford(j, maxn) {
if (j) dp[i][j] = dp[i - 1][j - 1];
if (2 * j < maxn) (dp[i][j] += dp[i][2 * j]) %= P;
}
int n, k;
cin >> n >> k;
cout << dp[n][k] << '\n';
#ifdef LOCAL_DEFINE
cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
return 0;
}
| #include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <algorithm>
#include <cstring>
#include <queue>
#include <set>
#include <cmath>
//========================[define]=======================
#define ll long long
//#define File
#define ull unsigned long long
#define loop(i,a,b,k) for(register int i = a;i<=b;i+=k)
#define ii(a) scanf("%d",&a);
#define oi(a) printf("%d",a);
#define ic(a) scanf("%c",&a);
#define oc(a) printf("%c",a);
#define ill(a) scanf("%lld",&a);
#define oll(a) printf("%lld",a);
#define pl() printf("\n");
#define pk() printf(" ");
#define it (int)
#define db (double)
#define lng (long long)
#define debug(x) cerr<<#x<<" = "<<x<<'\n';
//=========================[const]=======================
using namespace std;
const int N=1000+10;
const int M=100000+10;
const int MOD=1e9+7;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
//================================[begin]=====================
int add,Minus;
//=================================[end]======================
int
main()
{
#ifdef File
freopen("in.in","r", stdin);
freopen("out.out","w", stdout);
#endif
scanf("%d%d",&add,&Minus);
printf("%d %d",(add + Minus)/2,(add - Minus)/2);
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
struct Edge {
int to, cost;
Edge(){};
Edge(int to, int cost): to(to), cost(cost){};
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;
int main() {
cin.tie(0);
cin.sync_with_stdio(0);
ll n;
cin >> n;
int i = 1, j;
for(ll a = 5; a < n; a *= 5) {
j = 0;
ll t = n - a;
while (t % 3 == 0) {
j++;
t /= 3;
}
if (t == 1 && j != 0) {
cout << j << ' ' << i << endl;
return 0;
}
i++;
}
cout << -1 << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll qpow(ll a,ll b)
{
ll ans=1;
while(b>0)
{
if(b&1)
{
ans=ans*a;
}
a=a*a;
b>>=1;
}
return ans;
}
int main()
{
ll n;
scanf("%lld",&n);
for(ll i = 1;i<=38;i++){
for(ll j = 1;j<=26;j++){
if(qpow(3,i) + qpow(5,j) == n && qpow(3,i)>0 && qpow(5,j)>0){
printf("%lld %lld",i,j);
return 0;
}
}
}
printf("-1\n");
//printf("%lld\n",qpow(3,35));
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define ll long long int
#define sz(x) (int)(x.size())
#define FOR(i,x,y) for(int i=x;i<=y;++i)
#define FORN(i,x,y) for(int i=x;i>=y;--i)
#define debug(x )cout<<'['<<#x<<" is "<<x<<"]"<<endl;
#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
#define endl '\n';
void solve() {
ll arr[3];
ll mod=998244353;
cin>>arr[0]>>arr[1]>>arr[2];
arr[0]%=mod;
arr[1]%=mod;
arr[2]%=mod;
sort(arr,arr+3);
ll ans=0;
ans+=(arr[2]*(arr[2]+1)/2)%mod;
ans%=mod;
ans*=(arr[1]*(arr[1]+1)/2)%mod;
ans%=mod;
ans*=(arr[0]*(arr[0]+1)/2)%mod;
cout<<ans%mod<<endl;
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#ifdef CLION
freopen("input.in", "r", stdin);
#endif
// seive();
// ll t;cin>>t;while(t--) {
solve();
//}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repp(i, st, en) for (ll i = (ll)st; i < (ll)(en); i++)
#define repm(i, st, en) for (ll i = (ll)st; i >= (ll)(en); i--)
#define all(v) v.begin(), v.end()
void chmax(ll &x, ll y) {x = max(x,y);}
void chmin(ll &x, ll y) {x = min(x,y);}
void Yes() {cout << "Yes" << endl; exit(0);}
void No() {cout << "No" << endl; exit(0);}
template<class in_Cout> void Cout(in_Cout x) {cout << x << endl; exit(0);}
template<class in_vec_cout>
void vec_cout(vector<in_vec_cout> vec) {
for (in_vec_cout res : vec) {cout << res << " ";}
cout << endl;
}
const ll inf = 1e18;
const ll mod = 1e9 + 7;
int main() {
ll a, b, c; cin >> a >> b >> c;
if (a==b) Cout(c);
if (b==c) Cout(a);
if (c==a) Cout(b);
Cout(0);
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template<class T> bool chmin(T& a,T b){if(a>b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b){if(a<b) {a = b; return true;} return false;}
#define rep(i,n) for(int i=0;i<(n);i++)
#define drep(i,n) for(int i=(n)-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << " = " << (x) << endl;
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
vec<ll> A(N),B(N);
rep(i,N) cin >> A[i];
rep(i,N) cin >> B[i];
vec<ll> ans(N+1);
vec<ll> ma(N+1);
rep(i,N) ma[i+1] = max(ma[i],A[i]);
rep(i,N){
ans[i+1] = max(ans[i],B[i]*ma[i+1]);
}
rep(i,N+1) if(i) cout << ans[i] << "\n";
} | #include<bits/stdc++.h>
using namespace std;
using P=pair<int,int>;
constexpr int mod=1000000007;
constexpr int inf=1e9;
int in(){
int x;
scanf("%d",&x);
return x;
}
int main(){
int n=in();
long long a[n],b[n];
for(int i=0;i<n;i++)cin>>a[i];
for(int i=0;i<n;i++)cin>>b[i];
long long amax=0,ans=0;
for(int i=0;i<n;i++){
amax=max(amax,a[i]);
ans=max(ans,amax*b[i]);
cout<<ans<<endl;
}
return 0;
} |
/*
/> フ
| _ _|
/`ミ _x 彡
/ |
/ ヽ ?
/ ̄| | | |
| ( ̄ヽ__ヽ_)_)
\二つ
*/
#pragma GCC optimize("Ofast","inline","-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define pf push_front
#define F first
#define S second
#define SS stringstream
#define sqr(x) ((x)*(x))
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define CC(x) cout << (x) << endl
#define AL(x) x.begin(),x.end()
#define pw(x) (1ull<<(x))
#define NMSL cout << "NMSL" << endl;
#define debug(x) cout << #x << ": " << x << endl;
#define debug2(x, y) cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl;
#define debug3(x, y, z) cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define debug4(a, b, c, d) cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define fio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define in128 __int128_t
using namespace std;
const int N = 2e5+10;
const int INF = 0x7f7f7f7f;
const double EPS = 1e-3;
const long double PI = 3.14159265358979323846;
int n,p,ans=0;
int a[55];
map<pair<signed,int>,int>mp;
int DFS(signed x,int rest)
{
if(mp[{x,rest}])
return mp[{x,rest}];
if(x<=0)
return 1;
int fake=rest;
int ck=abs(rest);
fake%=a[x];
ck=ck-abs(fake)+a[x];
mp[{x,rest}]+=DFS(x-1,fake);
if(ck<a[x+1])
{
if(fake>0)
mp[{x,rest}]+=DFS(x-1,fake-a[x]);
else if(fake<0)
mp[{x,rest}]+=DFS(x-1,fake+a[x]);
}
return mp[{x,rest}];
}
signed main()
{
fio
cin>>n>>p;
for(int i=0; i<n; ++i)
cin>>a[i];
p%=a[n-1];
ans+=DFS(n-2,p);
if(p)
ans+=DFS(n-2,p-a[n-1]);
cout<<ans;
return 0;
}
| #include <bits/stdc++.h>
#define int long long
using namespace std;
int n, x, a[100], b[100], c[100], dp[100][2][2];
signed main() {
scanf("%lld%lld", &n, &x);
for (int i = 1; i <= n; ++i)
scanf("%lld", &a[i]);
for (int i = n, y = x; i >= 1; --i)
b[i] += y/a[i], y %= a[i];
for (int i = 1; i < n; ++i)
c[i] = a[i+1]/a[i];
c[n] = 1e15;
dp[0][0][0] = 1;
for (int i = 1; i <= n; ++i)
if (c[i]-1 == b[i]) {
dp[i][0][0] = dp[i-1][0][0]+dp[i-1][1][0];
dp[i][0][1] = dp[i-1][0][1]+dp[i-1][1][1];
dp[i][1][1] = dp[i-1][0][0]+dp[i-1][1][0];
} else {
dp[i][0][0] = dp[i-1][0][0]+dp[i-1][1][0]+dp[i-1][0][1]+dp[i-1][1][1];
dp[i][1][1] = dp[i-1][0][1]+dp[i-1][1][1];
if (b[i]) dp[i][1][1] += dp[i-1][0][0]+dp[i-1][1][0];
}
printf("%lld\n", dp[n][0][0]);
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a[]={15,10,3,0};
int b[]={8,3,0,0};
int p,q;
cin>>p>>q;
p+=q;
int i,j;
for(i=0;i<4;i++)
{
if(p>=a[i])
break;
}
for(j=0;j<4;j++)
{
if(q>=b[j])
break;
}
int ps=max(i,j);
cout<<ps+1<<"\n";
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main()
{
int A, B;
cin >> A >> B;
int C = A + B;
if (C >= 15 && B >= 8)
cout << 1 << endl;
else if (C >= 10 && B >= 3)
cout << 2 << endl;
else if (C >= 3)
cout << 3 << endl;
else
cout << 4 << endl;
}
|
#include "bits/stdc++.h"
using namespace std;
int n,x,y,ans;
string a;
map <pair <int,int>,int> m;
int main()
{
cin>>n>>a;
m[{x,y}]++;
for(auto c:a)
{
if(c=='A') x++;
else if(c=='T') x--;
else if(c=='C') y++;
else y--;
ans+=m[{x,y}];
m[{x,y}]++;
}
cout<<ans;
} | #include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <set>
#include <utility>
#include <queue>
#include <map>
#include <assert.h>
#include <stack>
#include <string>
#include <stdlib.h>
#include <stdio.h>
#include <cstring>
#include <cmath>
#include<iomanip>
#define int long long int
using namespace std;
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
int mod(int x)
{
return (((x)%1000000007)+1000000007)%1000000007;
}
int solve()
{
int n;
string s;
cin>>n>>s;
int a[n+1],g[n+1],c[n+1],t[n+1];
for(int i=0;i<n+1;i++)
{
a[i]=0;
c[i]=0;
g[i]=0;t[i]=0;
}
if(s[0]=='A')
a[1]=1;
else
a[1]=0;
if(s[0]=='G')
g[1]=1;
else
g[1]=0;
if(s[0]=='C')
c[1]=1;
else
c[1]=0;
if(s[0]=='T')
t[1]=1;
else
t[1]=0;
for(int i=2;i<=n;i++)
{
if(s[i-1]=='A')
a[i]=a[i-1]+1;
else
a[i]=a[i-1];
}
for(int i=2;i<=n;i++)
{
if(s[i-1]=='C')
c[i]=c[i-1]+1;
else
c[i]=c[i-1];
}
for(int i=2;i<=n;i++)
{
if(s[i-1]=='T')
t[i]=t[i-1]+1;
else
t[i]=t[i-1];
}
for(int i=2;i<=n;i++)
{
if(s[i-1]=='G')
g[i]=g[i-1]+1;
else
g[i]=g[i-1];
}
int count=0;
for(int i=0;i<n;i++)
{
for(int j=i;j<n;j++)
{
if(a[j+1]-a[i]==t[j+1]-t[i] && c[j+1]-c[i]==g[j+1]-g[i])
count++;
}
}
cout<<count;
return 0;
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(NULL); cout.tie(NULL);
int t;
//cin >> t;
t=1;
while (t--)
{
solve();
}
return 0;
} |
/*
after dusk passed,
there is a starry sky.
*/
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define m_k make_pair
using namespace std;
int n,m;
inline int read()
{
int f=1,x=0;char s=getchar();
while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
while(s>='0'&&s<='9'){x=x*10+s-'0';s=getchar();}
return x*f;
}
signed main()
{
n=read();m=read();
if (n==1&&m==0)
{
printf("1 2\n");
return 0;
}
if (m>=n-1||m<0)
{
printf("-1\n");
return 0;
}
printf("1 100000000\n");m++;
for (int i=1;i<m;i++) printf("%d %d\n",2*i,2*i+1);
printf("%d %d\n",2*m,m+n);
for (int i=m+1;i<n;i++) printf("%d %d\n",m+i,n+i);
} | #include <bits/stdc++.h>
using namespace std;
void setup() {
#ifdef LOCAL
freopen("input", "r", stdin);
#else
ios::sync_with_stdio(0);
cin.tie(NULL);
#endif
}
#define int long long
vector<int> getTimes(vector<int> &a, int start, int end) {
const int n = end - start;
const int total = 1 << n;
vector<int> times;
for (int i = 0; i < total; i++) {
int timeTook = 0;
for (int j = 0; j < n; j++) {
if (i & (1 << j)) {
timeTook += a[start + j];
}
}
times.push_back(timeTook);
}
return times;
}
signed main() {
setup();
int n, t;
cin >> n >> t;
vector<int> a(n);
for (int &it : a) cin >> it;
vector<int> times1 = getTimes(a, 0, n / 2), times2 = getTimes(a, n / 2, n);
sort(times1.begin(), times1.end());
sort(times2.begin(), times2.end());
int r = times2.size() - 1;
int best = 0;
for (int i = 0; i < (int)times1.size(); i++) {
while (r >= 0 && times1[i] + times2[r] > t) {
r--;
}
if (r >= 0) {
best = max(best, times1[i] + times2[r]);
} else {
break;
}
}
cout << best << endl;
} |
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef pair<LL, LL> ii;
LL N, L, R;
bool isPrime[1000100];
LL leastFac[1000100];
LL numFac[1000100];
bool freeSquareFaq[1000100];
void main1() {
cin >> L >> R;
LL ans = 0;
for (LL i = 0; i < 1000100; i++) {
isPrime[i] = true;
}
isPrime[0] = false;
isPrime[1] = false;
memset(leastFac, -1, sizeof leastFac);
leastFac[0] = 0;
leastFac[1] = 1;
for (LL i = 2; i < 1000100; i++) {
if (leastFac[i] == -1) {
leastFac[i] = i;
for (LL j = i * i; j < 1000100; j += i) {
if (leastFac[j] == -1) {
leastFac[j] = i;
}
isPrime[j] = false;
}
}
}
for (LL i = 2; i < 1000100; i++) {
LL u = i;
freeSquareFaq[i] = true;
while (u > 1) {
numFac[i]++;
if (leastFac[u] == leastFac[u / leastFac[u]]) {
freeSquareFaq[i] = false;
}
u /= leastFac[u];
}
}
for (LL i = 2; i <= 1000000; i++) {
if (!freeSquareFaq[i]) {
continue;
}
LL l = ((L + i - 1) / i) * i;
while (l <= R) {
LL bawahl = l / l;
LL atasl = R / l;
LL numKelipatanl = atasl - bawahl + 1;
LL bawahi = l / i;
LL atasi = R / i;
LL numTotalGCDi = atasi - bawahi + 1;
if (numFac[i] % 2 == 1) {
ans += numTotalGCDi - numKelipatanl;
} else {
ans -= numTotalGCDi - numKelipatanl;
}
// if (numTotalGCDi - numKelipatanl > 0) {
// cout << i << ' ' << l << ' ' << numKelipatanl << ' ' << numTotalGCDi << endl;
// }
l += i;
}
}
cout << 2 * ans << endl;
}
LL T2;
int main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// cin >> T2;
T2 = 1;
while (T2--) {
main1();
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main () {
int N;
ll K;
cin >> N >> K;
ll pk = N;
pk *= N;
pk *= N;
if (K == pk) {
cout << N << ' ' << N << ' ' << N << endl;
return 0;
}
ll dp[4][3000030];
ll sum[4][3000030];
dp[0][0] = 1;
sum[0][0] = 1;
for (int i = 1; i <= N * 3; i ++) {
dp[0][i] = 0;
sum[0][i] = 1;
}
for (int i = 1; i <= 3; i ++) {
sum[i][0] = 0;
for (int j = 1; j <= N * 3; j ++) {
dp[i][j] = sum[i - 1][j - 1];
if (j >= N + 1) {
dp[i][j] -= sum[i - 1][j - N - 1];
}
sum[i][j] = sum[i][j - 1] + dp[i][j];
}
}
/*for (int i = 1; i <= 3; i ++) {
for (int j = 1; j <= N * 3; j ++) {
cout << dp[i][j] << ' ';
}
cout << endl;
}*/
ll ss = 0;
int fl = 0;
while (K > ss) {
fl ++;
ss += dp[3][fl];
}
ss -= dp[3][fl];
K -= ss;
int fr = 0;
while (K > 0) {
fr ++;
K -= dp[2][fl - fr];
}
K += dp[2][fl - fr];
int fq = max(0, (fl - fr) - N - 1) + K;
cout << fr << ' ' << fq << ' ' << fl - fr - fq << endl;
} |
#include<iostream>
#include<math.h>
using namespace std;
int main(void){
int a[100]={};
int min=INFINITY;
for(int i=0;i<4;i++){
cin >> a[i];
}
for(int i=0;i<4;i++){
if(min>a[i]){
min=a[i];
}
}
cout << min;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define p pair<long long,long long>
#define endl '\n'
#define iof freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define pi acos(-1)
int fx[]={0,0,1,-1,1,1,-1,-1};
int fy[]={1,-1,0,0,-1,1,-1,1};
const int mxn=1e9+7;
int main(int argc, char const *argv[])
{
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
int a,b,c,d;
cin>>a>>b>>c>>d;
int mn=min({a,b,c,d});
cout<<mn<<endl;
}
|
#include <iostream>
using namespace std;
int main(void)
{
char S[12];
cin >> S;
int number = 0;
for (int i = 0; i < 12; i++)
{
if (S[i] == 'Z' && S[i + 1] == 'O' && S[i + 2] == 'N' && S[i + 3] == 'e')
{
number ++;
}
}
cout << number << endl;
return 0;
} | // template for atcoder beginners
// when you create a *.cpp file, this template is loaded
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string n_str(to_string(n));
int zero_count = 0;
// お尻が0の場合その数分付け足す。
if (n_str[n_str.size() - 1] == '0') {
string n_str_temp(n_str);
do {
n_str_temp.erase(n_str_temp.size() - 1,1);
zero_count++;
} while (n_str_temp.size() != 0 && n_str_temp[n_str_temp.size() - 1] == '0');
// cout << zero_count << endl;
n_str = n_str.substr(n_str.size() - zero_count).append(n_str);
}
string n_str_reverse(n_str);
reverse(n_str_reverse.begin(),n_str_reverse.end());
// cout << n_str << endl;
// cout << n_str_reverse << endl;
if (n_str == n_str_reverse) {
cout << "Yes" << endl;
return (0);
}
cout << "No" << endl;
return (0);
}
|
// E - 潜入
#include <bits/stdc++.h>
using namespace std;
#define vec vector
using vi = vec<int>;
using PR = pair<int,int>;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
int V; // 頂点数
vec<vec<PR>> G; // [from]<to, cost> 隣接リスト
int INF = 1e9;
vi dijkstra(int s){
vi dist(V, INF);
dist[s] = 0;
priority_queue<PR, vec<PR>, greater<PR>> pq;
pq.push({0, s});
while(pq.size()){
auto[from_d, from_v] = pq.top(); pq.pop();
if(dist[from_v] < from_d) continue;
for(auto[to_u, to_d]:G[from_v]){
to_d += dist[from_v];
if(dist[to_u] <= to_d) continue;
dist[to_u] = to_d;
pq.push({to_d, to_u});
}
}
return dist;
}
int main(){
int R, C; cin>>R>>C;
vec<vi> A(R, vi(C-1)); for(vi&v:A) for(int&x:v) cin>>x;
vec<vi> B(R-1, vi(C)); for(vi&v:B) for(int&x:v) cin>>x;
auto rc2id = [&](int r, int c){ return r*C + c; };
V = R*C*2;
G.resize(V);
rep(r, R) rep(c, C){
int a = rc2id(r, c), b = rc2id(r, c+R*C);
G[a].emplace_back(b, 1), G[b].emplace_back(a, 0);
if(r != R-1){
G[rc2id(r+1, c+R*C)].emplace_back(rc2id(r, c+R*C), 1);
G[rc2id(r, c)].emplace_back(rc2id(r+1, c), B[r][c]);
}
if(c != C-1){
a = rc2id(r, c), b = rc2id(r, c+1);
G[a].emplace_back(b, A[r][c]), G[b].emplace_back(a, A[r][c]);
}
}
cout<< dijkstra(0)[rc2id(R-1,C-1)] <<endl;
}
| #include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define MP make_pair
#define mt make_tuple
#define eb emplace_back
#define ar array
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define mem(arr,x) memset(arr, x, sizeof arr)
#define db(arr) for(auto x : arr) cout << x << " "; cout << "\n";
#define db2d(arr) for(auto x : arr){ for(auto y : x) cout << y << " "; cout << "\n";}
#define read(arr) for(auto &x : arr) cin >> x;
#define sz(x) (int)x.size()
#define MOD 1000000007
#define MOD2 998244353
#define nl '\n'
using namespace std;
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// order_of_key (k) : Number of items strictly smaller than k
// find_by_order(k) : K-th element in a set (counting from zero)
string to_string(char c) {
return string(1, c);
}
string to_string(bool b) {
return b ? "true" : "false";
}
string to_string(const char* s) {
return string(s);
}
string to_string(string s) {
return s;
}
string to_string(vector < bool > v) {
string res;
for(int i = 0; i < sz(v); i++)
res += char('0'+v[i]);
return res;
}
template < size_t S > string to_string(bitset < S > b) {
string res;
for(int i = 0; i < S; i++)
res += char('0' + b[i]);
return res;
}
template < class T > string to_string(T v) {
bool f = 1;
string res;
for(auto x : v) {
if(!f)
res+=' ';
f=0;
res += to_string(x);
}
return res;
}
void dbvar() { cerr << "]" << endl; }
template<class H, class... T> void dbvar(H h, T... t){
cerr << to_string(h);
if(sizeof...(t))
cerr << ", ";
dbvar(t...);
}
template<class A> void write(A x) {
cout << to_string(x);
}
template<class H, class... T> void write(const H& h, const T&... t) {
write(h);
write(t...);
}
void print() {
write("\n");
}
template<class H, class... T> void print(const H& h, const T&... t) {
write(h);
if(sizeof...(t))
write(' ');
print(t...);
}
template <typename T1, typename T2>
constexpr typename std::common_type<T1, T2>::type floor_div(T1 x, T2 y) {
assert(y != 0);
if (y < 0) x = -x, y = -y;
return x < 0 ? (x - y + 1) / y : x / y;
}
const ll INFL = (ll)1e18;
const int INF = (int)1e9;
const ld eps = (ld)1e-9;
const ld pi = acos(-1.0);
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, 1, 0, -1};
ll power(ll n, ll m){
if(m == 0) return 1;
ll val = power(n, m/2);
if(m % 2 == 0) return (val * val); else return ((val * val) * n);
}
ll powermod(ll n, ll m, ll _MOD){
if(m == 0) return 1;
ll val = powermod(n,m/2,_MOD);
val %= _MOD;
if(m % 2 == 0) return (val * val) % _MOD; else return (((val * val) % _MOD) * n) % _MOD;
}
const int mxN = 3000;
vector < pair < ll, ll > > graph[mxN];
ll dis[mxN];
void solve(){
ll n, m; cin >> n >> m;
for(ll i = 0; i < m; i++){
ll a, b, c; cin >> a >> b >> c; a--; b--;
graph[a].pb(MP(b, c));
}
priority_queue < pair < ll, ll >, vector < pair < ll, ll > >, greater < pair < ll, ll > > > q;
for(ll i = 0; i < n; i++){
for(ll j = 0; j < mxN; j++) dis[j] = INF;
dis[i] = 0;
ll ans = INF;
q.push(MP(0, i));
while(!q.empty()){
auto cur = q.top(); q.pop();
if(cur.first > dis[cur.second]) continue;
for(auto x : graph[cur.second]){
if(dis[x.first] > cur.first + x.second){
dis[x.first] = cur.first + x.second;
q.push(MP(dis[x.first], x.first));
}
if(x.first == i){
ans = min(ans, cur.first + x.second);
}
}
}
if(ans == INF) ans = -1;
print(ans);
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
// cout << setprecision(10) << fixed;
int t = 1;
// cin >> t;
for(int i = 1; i <= t; i++){
// cout << "Case #" << i << ": ";
solve();
}
return 0;
} |
#include <bits/stdc++.h>
#include <unordered_set>
#include <vector>
// #include <atcoder/all>
// using namespace atcoder;
using namespace std;
using ll = long long;
// using Graph = vector<vector<int>>;
vector<bool> visited;
vector<bool> good;
vector<int> C;
vector<int> G[100009];
void dfs(int v, vector<int> &color) {
if (0 == color[C[v]]) good[v] = true;
color[C[v]]++;
visited[v] = true;
for (int next_v : G[v]) {
if (visited[next_v]) continue;
dfs(next_v, color);
}
color[C[v]]--;
}
int main() {
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int N;
cin >> N;
vector<int> color(100009, 0);
// Graph G(N);
C.resize(N);
for (int i = 0; i < N; i++) {
cin >> C[i], C[i]--;
}
for (int i = 0; i < N - 1; i++) {
int a, b;
cin >> a >> b;
a--;
b--;
G[a].push_back(b);
G[b].push_back(a);
}
visited.assign(N, false);
good.assign(N, false);
dfs(0, color);
for (int i = 0; i < N; i++) {
if (good[i]) {
cout << i + 1 << endl;
}
}
return 0;
}
| /* code of Ayush Tiwari
codeforces- servermonk
codechef- ayush572000
*/
#include <bits/stdc++.h>
#define ll long long
//STL
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define all(v) v.begin(), v.end()
//loops
#define forn(i,a,b) for(int i=a; i<b; i++)
#define rforn(i,a,b) for(int i=a; i>=b; i--)
// defined values
#define maxn 200004
#define Mod 1000000007
// fast io
#define FIO() ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
vector<int> graph[maxn];
map<int,int> m;
int a[maxn];
int vis[maxn];
void dfs(int node,int flag){
vis[node]=flag;
m[a[node-1]]+=1;
for(auto child: graph[node]){
if(vis[child]) continue;
if(!m[a[child-1]])
dfs(child,1);
else dfs(child,2);
}
m[a[node-1]]-=1;
}
void solution(){
// This is the main code
int n;
cin>>n;
forn(i,0,n) cin>>a[i];
forn(i,0,n-1){
int u,v;
cin>>u>>v;
graph[u].pb(v);
graph[v].pb(u);
}
dfs(1,1);
forn(i,1,n+1){
if(vis[i]==1) cout<<i<<endl;;
}
}
int main(){
#ifndef ONLINE_JUDGE
freopen("D:/competitive-programming/input.txt","r",stdin);
freopen("D:/competitive-programming/output.txt","w",stdout);
#endif
FIO()
ll t=1;
// cin>>t;
while (t--)
{
solution();
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
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; }
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
ll n;
cin >> n;
ll a, p, x, t = 0, res = INF;
REP(i, n) {
cin >> a >> p >> x;
if (x - a > 0) chmin(res, p);
}
if (res == INF) cout << -1 << endl;
else cout << res << endl;
return 0;
} | #include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"
using namespace std;
constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-5;
//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> N;
long long int ans = MOD * MOD;
while (N--) {
cin >> L >> R >> K;
if (L < K) {
ans = min(ans, R);
}
}
if (ans == MOD * MOD)ans = -1;
cout << ans << endl;
} |
#include<bits/stdc++.h>
using namespace std;
namespace IO
{
const int buffer_size=1e5+5;
char buf[buffer_size],*S,*T;
bool flag_EOF;
inline char read_char()
{
if(S==T)
T=(S=buf)+fread(buf,1,buffer_size,stdin);
return S!=T?*(S++):EOF;
}
inline int read_int()
{
int flag=1;
char c=read_char();
while(c<'0'||c>'9')
{
if(c==EOF)
{
flag_EOF=true;
return 0;
}
flag=(c=='-'?-1:1);
c=read_char();
}
int x=0;
while(c>='0'&&c<='9')
{
x=x*10+(c^48);
c=read_char();
}
return x*flag;
}
char st[13];
int _top;
void Write(int x)
{
if(!x)
{
putchar('0');
return;
}
if(x<0)
{
putchar('-');
x=-x;
}
while(x)
{
st[++_top]=x%10+'0';
x/=10;
}
while(_top>0)
putchar(st[_top--]);
}
}
int main()
{
long long x,y;
cin>>x>>y;
long long ans=1e18;
for(int k=0;;++k)
{
if(k!=0)
x<<=1;
long long res=k;
long long val=x>y?x-y:y-x;
int now=k;
while(1)
{
while(!(val&1)&&now>0)
val>>=1,--now;
if(now==0)
{
res+=val;
break;
}
int i=0;
while(val&(1ll<<i))
++i;
i=min(i,now);
if(i==1)
++res,val^=1;
else
{
res+=2;
val^=(1ll<<i)-1;
}
}
ans=min(ans,res);
if(x>=y)
break;
}
printf("%lld\n",ans);
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
long long int mod = 1e9+7;
int main(){
int a,b;
cin>>a>>b;
cout<<2*a+100-b<<endl;
return 0;
} |
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rel register ll
#define rec register char
#define gc getchar
//#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<23,stdin),p1==p2)?-1:*p1++)
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
char buf[1<<23],*p1=buf,*p2=buf;
inline int read(){
int x=0,f=1;char c=gc();
for (;!isdigit(c);c=gc()) f^=c=='-';
for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
return f?x:-x;
}
template <typename mitsuha>
inline bool read(mitsuha &x){
x=0;int f=1;char c=gc();
for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';
if (!~c) return 0;
for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
return x=f?x:-x,1;
}
template <typename mitsuha>
inline int write(mitsuha x){
if (!x) return 0&pc(48);
if (x<0) pc('-'),x=-x;
int bit[20],i,p=0;
for (;x;x/=10) bit[++p]=x%10;
for (i=p;i;--i) pc(bit[i]+48);
return 0;
}
inline char fuhao(){
char c=gc();
for (;isspace(c);c=gc());
return c;
}
}using namespace chtholly;
using namespace std;
const int yuzu=4e5;
typedef int fuko[yuzu|10];
fuko fa,sz;
struct dsu {
int find(int x) {
return fa[x]?fa[x]=find(fa[x]):x;
}
int mg(int u,int v) {
u=find(u),v=find(v);
if (sz[u]&&sz[v]) return 0;
u^v?fa[u]=v,sz[v]|=sz[u]:sz[u]=1;
return 1;
}
}zw;
int main() {
int n,i,a,b,lxy=0;
read(n);
for (i=1;i<=n;++i) lxy+=zw.mg(read(),read());
printf("%d\n",lxy);
} | //#pragma once
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cctype>
#include <cstdlib> // srand,rand
#include <random>
#include <functional>
#include <list>
#include <stack>
#include <time.h>
#define height 50
#define width 50
#define tile_sum 2500
using namespace std;
#define ll long long
#define ll128 long long
#define lp(i,n) for(ll i=0;i<n;i++)
clock_t start_clock = clock();
clock_t end_clock = clock();
int start_x;
int start_y;
int tile[height][width];
int point[height][width];
int ans_score=0;
string direction_str;
string ans_string;
int GetTileKind(int y,int x){
return tile[y][x];
}
void Input(){
cin>>start_y;
cin>>start_x;
for(int h=0;h<height;h++){
for(int w=0;w<width;w++){
cin>>tile[h][w];
}
}
for(int h=0;h<height;h++){
for(int w=0;w<width;w++){
cin>>point[h][w];
}
}
}
int CheckScore(string direction_str){
int now_x=start_x;
int now_y=start_y;
int score=point[now_y][now_x];
for(int i=0;i<direction_str.size();i++){
if(direction_str[i]=='U')now_y--;
if(direction_str[i]=='D')now_y++;
if(direction_str[i]=='L')now_x--;
if(direction_str[i]=='R')now_x++;
score+=point[now_y][now_x];
}
return score;
}
bool CheckCanGo(int y,int x,bool gone[tile_sum]){
if(y<0 || height<=y || x<0 || width<=x)return false;
if(gone[GetTileKind(y,x)]==true)return false;
return true;
}
string DicidePath(string direction_str){
bool gone[tile_sum]={};
int now_x=start_x;
int now_y=start_y;
gone[GetTileKind(now_y ,now_x )]=true;
for(int i=0;i<direction_str.size();i++){//元々決められていたパスの処理
if(direction_str[i]=='U')now_y--;
if(direction_str[i]=='D')now_y++;
if(direction_str[i]=='L')now_x--;
if(direction_str[i]=='R')now_x++;
gone[GetTileKind(now_y ,now_x )]=true;
}
char pre_direct_x='a';
char pre_direct_y='a';
while(true){//追加のパスを決める処理
string CanGoDirection="";
if(CheckCanGo(now_y - 1 ,now_x ,gone )==true){
for(int i=0;i<now_y;i++)CanGoDirection+="U";
}
if(CheckCanGo(now_y + 1 ,now_x ,gone )==true){
for(int i=0;i<49-now_y;i++)CanGoDirection+="D";
}
if(CheckCanGo(now_y ,now_x - 1 ,gone )==true){
for(int i=0;i<now_x;i++)CanGoDirection+="L";
}
if(CheckCanGo(now_y ,now_x + 1 ,gone )==true){
for(int i=0;i<49-now_x;i++)CanGoDirection+="R";
}
if(CanGoDirection.empty())break;
direction_str+=CanGoDirection[rand()%CanGoDirection.size()];
if(direction_str.back()=='U')now_y--;
if(direction_str.back()=='D')now_y++;
if(direction_str.back()=='L')now_x--;
if(direction_str.back()=='R')now_x++;
gone[GetTileKind(now_y ,now_x )]=true;
}
return direction_str;
}
int main(){
srand((unsigned int)time(NULL));
Input();
direction_str.clear();
ans_string=DicidePath(direction_str);
ans_score=CheckScore(ans_string);
while(true){
end_clock = clock();
double tt = (double)((end_clock - start_clock));
if (tt >= (double)1800.000)break;
int used_c_num=rand()%ans_string.size();
direction_str.clear();
for(int j=0;j<used_c_num;j++)direction_str+=ans_string[j];
string now_direct_str=DicidePath(direction_str);
int score=CheckScore(now_direct_str);
if(ans_score<=score){
ans_string=now_direct_str;
ans_score=score;
}
}
cout<<ans_string<<endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int M;
cin >> M >> M;
vector<string> s(M);
map<string, int> m;
set<string> S;
vector<vector<char>> a(20, vector<char>(20, 'A'));
deque<tuple<int, int, string>> t;
for (int i = 0; i < M; i++) {
cin >> s.at(i);
if (m.count(s.at(i))) {
m.at(s.at(i))++;
}
else {
m[s.at(i)] = 1;
}
}
for (int i = 0; i < M; i++) {
if (!(S.count(s.at(i)))) {
S.insert(s.at(i));
t.push_back(make_tuple(m.at(s.at(i)), (int)s.at(i).size(), s.at(i)));
}
}
sort(t.begin(), t.end());
for (int i = 0; i < 20; i++) {
M = 0;
for (int j = 0; j < 10; j++) {
if (M + get<1>(t.front()) > 19) {
break;
}
for (int k = 0; k < get<1>(t.front()); k++) {
a.at(i).at(M + k) = get<2>(t.front()).at(k);
}
M += get<1>(t.front());
t.pop_front();
}
}
for (int i = 0; i < 20; i++) {
for (int j = 0; j < 20; j++) {
cout << a.at(i).at(j);
if (j > 18) {
cout << endl;
}
}
}
}
| #pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<string.h>
#include<random>
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>
using namespace std;
typedef long long LL;
typedef vector<int> VI;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
#define rprintf(fmt, begin, end) do { const auto end_rp = (end); auto it_rp = (begin); for (bool sp_rp=0; it_rp!=end_rp; ++it_rp) { if (sp_rp) putchar(' '); else sp_rp = true; printf(fmt, *it_rp); } putchar('\n'); } while(0)
VI ans;
void rec(LL x, LL y, int dep) {
if (ans.size() > 130u) return;
if (x == y) {
ans.push_back(4);
REP (i, x) {
ans.push_back(1);
if (ans.size() > 130u) return;
}
// printf("%lld %lld %d\n", x, y, dep);
return;
}
if (x > y) {
ans.push_back(3);
rec(x - y, y, dep+1);
} else {
ans.push_back(4);
rec(x, y - x, dep+1);
}
}
// const long double GR = 2L / (1L + sqrt(5L));
const long double GR = 0.6180339887498948482045868343656381177203091798057628621354486227L;
bool solve(LL N) {
ans.clear();
if (N == 1) {
ans.push_back(1);
return true;
}
REP (i, 100) {
LL tmpN = N-i;
LL y = (long double)tmpN * GR;
for (LL tmpy = y-30; tmpy <= y+30; tmpy++) {
if (tmpy > 0 && tmpy < tmpN && __gcd(tmpN, tmpy) == 1) {
while ((int)ans.size() != i) ans.pop_back();
rec(tmpN, tmpy, 0);
if (ans.size() <= 130) {
return true;
}
}
}
ans.push_back(1);
}
return false;
}
mt19937_64 engine;
void MAIN() {
assert(solve(1));
assert(solve(2));
LL N;
#ifdef LOCALx
REP (t, 100000) {
N = engine() % 1000000000000000000LL + 1;
printf("%lld\n", N);
assert(solve(N));
}
#endif
scanf("%lld", &N);
bool b = solve(N);
assert(b);
reverse(ans.begin(), ans.end());
printf("%d\n", (int)ans.size());
REP (i, ans.size()) printf("%d\n", ans[i]);
}
int main() {
int TC = 1;
// scanf("%d", &TC);
REP (tc, TC) MAIN();
return 0;
}
|
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<bitset>
#include<deque>
#include<cstdlib>
#include<set>
#include<ctime>
#define ll long long
#define mp make_pair
#define mod 1000000007
using namespace std;
ll read()
{
ll x=0,f=1;
char c=getchar();
while(c>'9'||c<'0')
{
if(c=='-') f=-1;
c=getchar();
}
while(c>='0'&&c<='9')
{
x=x*10+c-'0';
c=getchar();
}
return f*x;
}
int n;
ll a[100003],ans=1;
int main()
{
n=read();
for(int i=1;i<=n;++i) a[i]=read();
sort(a+1,a+1+n);
for(int i=1;i<=n;++i)
{
ans=ans*(a[i]-a[i-1]+1)%mod;
while(a[i]==a[i+1]) ++i;
}
cout<<ans<<'\n';
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 400010, mod = 1e9 + 7;
set<LL> s;
int n;
int main(){
cin >> n;
s.insert(0);
for (int i = 0; i < n; i ++) {
int x;
cin >> x;
s.insert(x);
}
LL ans = 1;
for (auto it = next(s.begin()), i = s.begin(); it != s.end(); it ++, i ++) {
ans = ans * (*it - *i + 1) % mod;
}
cout << ans;
return 0;
}
|
//
// Created by yamunaku on 2021/03/07.
//
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)
using ll = long long;
using ld = long double;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
template<typename T>
using heap = priority_queue<T, vector<T>, function<bool(const T, const T)>>;
void solve() {
int n;
cin >> n;
vector<string> s(3);
rep(i, 3) cin >> s[i];
cout << "1" + string(n, '0') + string(n, '1') << endl;
}
int main() {
//CFS;
int t;
cin >> t;
rep(_, t) solve();
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pp pop_back
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define f0(i,a,n) for(i=a;i<n;i++)
#define f1(i,a,b) for(i=a;i<=b;i++)
#define all(v) sort(v.begin(),v.end());
#define stp setprecision
#define nl endl
#define I insert
#define ipt(a,n) for(i=0;i<n;i++)cin>>a[i];
#define pll pair<ll,ll>
#define pii pair<int,int>
#define vl vector<ll>
#define mp map<ll,ll>
#define sr(a,n) sort(a,a+n);
#define cx(x) cout<<x<<"\n";
#define cy(x) cout<<x<<" ";
#define cn cout<<"No\n";
#define cw cout<<"Yes\n";
#define bs binary_search
#define S second
#define F first
#define pi 3.141592653589793238
#define ct cout<<
ll sieve[1000001];
void prime()
{
ll i,j;
sieve[0]=0,sieve[1]=0;
for(i=2;i<=1e6;i++)
sieve[i]=1;
for(i=2;i<=1e6;i++)
{
if(sieve[i]==1)
{
for(j=2*i;j<=1e6;j+=i)
sieve[j]=0;
}
}
}
ll be(ll a,ll b,ll m)
{
ll r=1;
while(b!=0)
{
if(b&1)
r=(r*a)%m;
a=(a*a)%m;
b=b/2;
}
return r;
}
int main()
{
fast;
prime();
ll t=1;
//cin>>t;
while(t--)
{
ll n,s,d,i;
cin>>n>>s>>d;
ll x[n],y[n],ans=0,k=0;
f0(i,0,n)
{
cin>>x[i]>>y[i];
k=0;
if(x[i]<s&&y[i]>d)
{
ans=1,k=1;
}
//cx(k)
}
if(ans)
cw
else
cn
}
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.