code1
stringlengths 54
12k
| code2
stringlengths 71
12k
| similar
int64 0
1
| __index_level_0__
int64 0
101M
|
---|---|---|---|
#include<iostream>
#include<vector>
using namespace std;
const int MAX = 2000001;
const int VMAX = 10001;
int main(){
int N;
cin >> N;
vector <int> A(N + 1), B(N + 1), C(VMAX + 1, 0);
for(int i = 1; i <= N; i++) {
cin >> A[i];
}
for(int j = 1; j <= N ; j++){
C[A[j]] = C[A[j]] + 1;
}
for(int i = 1; i <= VMAX; i++){
C[i] = C[i] + C[i-1];
}
for(int j = N; j >= 1; j--){
B[C[A[j]]] = A[j];
C[A[j]] = C[A[j]] - 1;
}
for(int i = 1 ; i <= N; i++){
if (i > 1) {
cout << " ";
}
cout << B[i];
}
cout << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int a[3][3],n;
for ( int i=0; i<3 ; i++){
for (int j=0 ; j<3 ; j++){
cin >> a[i][j];
}
}
cin >> n;
int b[n] ;
for ( int i= 0 ; i<n ; i++) {
cin >> b[i] ;
}
bool c[3][3];
for ( int i=0; i<3 ; i++){
for (int j=0 ; j<3 ; j++){
c[i][j]=false ;
for ( int k = 0 ; k<n ; k++){
if ( a[i][j]==b[k]){
c[i][j]=true ;
}
}
}
}
string ans="No" ;
for ( int i=0 ; i<3 ; i++){
if ( c[i][1] && c[i][2]&&c[i][0]){
ans= "Yes" ;
}
if ( c[0][i] && c[1][i]&&c[2][i]){
ans= "Yes" ;
}
}
if ( c[0][0] && c[1][1]&&c[2][2]){
ans= "Yes" ;
}
if ( c[0][2] && c[1][1]&&c[2][0]){
ans= "Yes" ;
}
cout << ans << endl;
} | 0 | 15,592,844 |
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
#if defined(ENABLE_PRINT)
#define Print(v) \
do {\
cout << #v << ": " << v << endl; \
}while(0)
#define PrintVec(v) \
do {\
for(int __i = 0; __i < v.size(); ++__i) \
{ \
cout << #v << "[" << __i << "]: " << v[__i] << endl; \
}\
}while(0)
#else
#define Print(v) ((void)0)
#define PrintVec(v) ((void)0)
#endif
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
void f(string s, vector<string>& ans, int maxLen)
{
if(s.size() == 0)
{
abort();
}
ans.push_back(s);
if((int)s.size() == maxLen)
{
return;
}
auto t = (*s.rbegin());
if(t > '0')
{
auto na = s + (char)(t - 1);
f(na, ans, maxLen);
}
f(s + t, ans, maxLen);
if(t < '9')
{
auto na = s + (char)(t + 1);
f(na, ans, maxLen);
}
}
int main(int, const char**)
{
int k;
cin >> k;
vector<string> ans;
rep(i, 9)
{
auto a = string(1, '0' + i + 1);
f(a, ans, 10);
}
sort(ans.begin(), ans.end(), [](const auto& a, const auto& b){
if(a.size() == b.size())
{
return a < b;
}
return a.size() < b.size();
});
if(k <= (int)ans.size())
{
cout << ans[k - 1] << endl;
}
else
{
printf("over, ans.size = %zu, k = %d\n", ans.size(), k);
}
return 0;
} | #define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;
ll gcd(ll a,ll b){
if(b == 0) return a;
return gcd(b , a % b);
}
const ll MOD = 1000000007;
const ll MAX = 2000001;
ll mod(ll a){
return a % MOD;
}
ll lcm(ll a,ll b){
return (a*b)/gcd(a,b);
}
ll fac[MAX], finv[MAX], inv[MAX];
void nCrprep() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (ll 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 nCr(ll n, ll r){
if (n < r) return 0;
if (n < 0 || r < 0) return 0;
return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}
ll nCrcheep(ll n,ll r){
if(r == 0) return 1;
else if(r == 1) return n;
else return nCrcheep(n-1,r-1)*n/r;
}
vector<pair<ll,ll>> prime_factorize(ll n){
vector<pair<ll,ll>> res;
for(ll i=2; i*i <= n; i++){
if(n % i != 0) continue;
ll ex = 0;
while(n % i == 0){
ex++;
n /= i;
}
res.push_back({i,ex});
}
if(n != 1) res.push_back({n,1});
return res;
}
int main(){
ll a,b; cin >> a >> b;
if(a+b == 15) cout << '+' << endl;
else if(a*b == 15) cout << '*' << endl;
else cout << "x" << endl;
} | 0 | 1,787,688 |
#include <bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define MAX 2000005
#define MOD 1000000007
#define MOD2 998244353
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define vi vector<ll>
#define vp vector<pii>
#define all(v) v.begin(),v.end()
#define sz(x) (ll)x.size()
#define F first
#define S second
#define FOR(i,a,b) for(ll i=a;i<b;++i)
#define ROF(i,a,b) for(ll i=a;i>=b;--i)
#define trace(x) cerr<<#x<<": "<<x<<'\n';
typedef long long ll;
using namespace std;
ll mexp(ll a, ll b){
ll ans=1;
a%=MOD;
while(b){
if(b&1) ans=ans*a%MOD;
b>>=1;
a=a*a%MOD;
}
return ans;
}
ll h,w,n;
map<pair<ll,ll>,bool> f;
vector<pair<ll,ll> >v;
set<pair<ll,ll> >s;
int calc(int x,int y){
int c=0;
FOR(i,-1,2){
FOR(j,-1,2){
if(x+i<1 || x+i>h || y+j<1 || y+j>w){
return 0;
}
if(f[mp(x+i,y+j)]){
c++;
}
}
}
s.insert(mp(x,y));
return c;
}
int main(){
IOS
cin>>h>>w>>n;
FOR(i,0,n){
int x,y;
cin>>x>>y;
f[mp(x,y)]=1;
v.pb(mp(x,y));
}
ll ans[10];
FOR(i,0,10){
ans[i]=0;
}
FOR(p,0,n){
FOR(i,-1,2){
FOR(j,-1,2){
int x=v[p].F,y=v[p].S;
if(s.find(mp(x+i,y+j))!=s.end()){
continue;
}
ans[calc(x+i,y+j)]++;
}
}
}
ll sum=0;
FOR(i,1,10){
sum+=ans[i];
}
ans[0]=(h-2)*(w-2)-sum;
FOR(i,0,10){
cout<<ans[i]<<endl;
}
cerr<<"Time: "<<1.0/CLOCKS_PER_SEC<<" ms"<<endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
typedef vector<int> vec;
ll mod_pow(ll a, ll n, ll m) {
ll res = 1;
while (n) {
if (n & 1)res = res * a%m;
a = a * a%m; n >>= 1;
}
return res;
}
struct modint {
ll n;
modint() :n(0) { ; }
modint(ll m) :n(m) {
if (n >= mod)n %= mod;
else if (n < 0)n = (n%mod + mod) % mod;
}
operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
if (n == 0)return modint(1);
modint res = (a*a) ^ (n / 2);
if (n % 2)res = res * a;
return res;
}
ll inv(ll a, ll p) {
return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }
const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
fact[0] = modint(1);
for (int i = 0; i < max_n - 1; i++) {
fact[i + 1] = fact[i] * modint(i + 1);
}
factinv[max_n - 1] = modint(1) / fact[max_n - 1];
for (int i = max_n - 2; i >= 0; i--) {
factinv[i] = factinv[i + 1] * modint(i + 1);
}
}
modint comb(int a, int b) {
if (a < 0 || b < 0 || a < b)return 0;
return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
void solve() {
int N, M; cin >> N >> M;
vector<ll> x(N), y(N), z(N);
rep(i, N) cin >> x[i] >> y[i] >> z[i];
ll ans = 0;
rep(i, 1 << 3){
vector<ll> tmpv(N);
rep(j, N){
ll tmp = 0;
if(1 & (i >> 2)) tmp += x[j];
else tmp -= x[j];
if(1 & (i >> 1)) tmp += y[j];
else tmp -= y[j];
if(1 & (i >> 0)) tmp += z[j];
else tmp -= z[j];
tmpv[j] = tmp;
}
sort(all(tmpv));
reverse(all(tmpv));
ll res = 0;
rep(i, M){
res += tmpv[i];
}
ans = max(ans, res);
}
cout << ans << endl;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
solve();
return 0;
} | 0 | 20,883,626 |
#include<bits/stdc++.h>
#define int long long
using namespace std;
int num , k , a[100005];
int dp[100005];
const int oo=1e9+7;
int Min(int a , int b)
{
if(a>b)return b;
else return a;
}
main()
{
cin >> num >> k;
for( int i=1 ; i <= num ; ++i )
{
cin >> a[i];
dp[i]=oo;
}
dp[1]=a[1];
dp[2]=abs(a[1]-a[2]);
for(int i=3 ; i<=num ; i++)
{
for(int j=1 ; j<=k ; j++)
{
if(i<=j)continue;
if(i-j==1)dp[i]=Min(dp[i] , abs(a[i]-a[i-j]));
else dp[i]=Min(dp[i] , abs(a[i]-a[i-j])+dp[i-j]);
}
}
cout << dp[num]<<endl;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
using namespace std;
int main() {
int n;
cin >> n;
ll a[n + 1], max[n + 1], min[n + 1];
rep(i, n + 1) cin >> a[i];
max[n] = min[n] = a[n];
for (int i = n - 1; i >= 0; i--) {
max[i] = max[i + 1] + a[i];
min[i] = (min[i + 1] + 1) / 2 + a[i];
}
if (min[0] > 1) {
cout << -1 << endl;
return 0;
}
ll ans = 0, p = 1;
rep(i, n + 1) {
ans += p;
p = (p - a[i]) * 2;
if (p > max[i + 1]) p = max[i + 1];
}
cout << ans << endl;
return 0;
} | 0 | 44,610,875 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
string s;
int n;
int main() {
cin >> n;
cin >> s;
int cnt = 0;
long long ans = 1;
for (int i = 1; i <= n; i++) {
ans = ans * i % mod;
}
for (int i = 0; i < n * 2; i++) {
if (i % 2 == 0) {
if (s[i] == 'W') {
s[i] = 'B';
} else {
s[i] = 'W';
}
}
if (s[i] == 'B') {
ans = ans * cnt % mod;
cnt--;
} else {
cnt++;
}
}
if (cnt != 0) {
cout << 0;
return 0;
}
cout << ans;
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<long long,int> P;
int main(){
ll a, b, k;
cin >> a >> b >> k;
rep(i, k){
if (i % 2 == 0){
if (a % 2 != 0) a--;
b += a / 2;
a /= 2;
}
else if (i % 2 != 0){
if (b % 2 != 0) b--;
a += b / 2;
b /= 2;
}
}
cout << a << " " << b << endl;
return 0;
} | 0 | 11,759,603 |
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
int main()
{
string s, t;
cin >> s >> t;
sort(all(s));
sort(all(t));
reverse(all(t));
yorn(s < t);
return 0;
} | #pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i32 = int32_t;
using i64 = int64_t;
constexpr char newl = '\n';
template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define debug(x) cout << #x << ": " << x << '\n';
template<class T> void Print(vector<T> v) {
F0R(i, v.size()) {
cout << v[i] << ' ';
}
cout << newl;
}
#if 1
signed main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
int N, P;
string S;
cin >> N >> P >> S;
i64 result = 0;
if (P != 2 && P != 5) {
vector<int> rs(P, 0);
rs[0]++;
i64 tr = 1;
i64 r = 0;
RF0(i, N) {
r = (r + tr * (S[i] - '0')) % P;
rs[r]++;
tr = (tr * 10) % P;
}
F0R(i, P) {
result += (i64)rs[i] * (rs[i] - 1) / 2;
}
}
else {
F0R(i, N) {
if ((S[i] - '0') % P == 0) {
result += i + 1;
}
}
}
cout << result;
}
#endif | 0 | 24,904,292 |
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;
#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x))
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf
#define lcm hddalkwjeidjjhasda
#define random_shuffle asdasdd
const int MAXN = 105;
int n = 100, m = 40;
int w, b;
char c[MAXN][MAXN];
bool used[MAXN][MAXN];
void dfs(int i, int j, char col) {
if (i < 0 || i >= n || j < 0 || j >= m || used[i][j] || c[i][j] != col) {
return;
}
const int di[] = {-1, 1, 0, 0};
const int dj[] = {0, 0, -1, 1};
used[i][j] = true;
for (int k = 0; k < 4; k++) {
dfs(i + di[k], j + dj[k], col);
}
}
void comps() {
int wc = 0, bc = 0;
memset(used, 0, sizeof(used));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (!used[i][j]) {
if (c[i][j] == '#') {
bc++;
} else {
wc++;
}
dfs(i, j, c[i][j]);
}
}
}
cerr << "White: " << wc << " black: " << bc << endl;
}
int main() {
cin >> w >> b;
for (int i = 0; i < 100; i++) {
for (int j = 0; j < 20; j++) {
c[i][j] = '#';
}
}
for (int i = 1; i < 100; i += 2) {
for (int j = 0; j < 20; j += 2) {
c[i][j] = '.';
}
}
c[99][19] = '.';
for (int i = 0; i < 100; i++) {
for (int j = 0; j < 20; j++) {
c[i][20 + j] = '.';
}
}
for (int i = 0; i < 100; i += 2) {
for (int j = 1; j < 20; j += 2) {
c[i][20 + j] = '#';
}
}
c[0][20] = '#';
comps();
int wc = 500, bc = 500;
for (int j = 18; j >= 0; j -= 2) {
for (int i = 98; i >= 2; i -= 2) {
if (wc == w) {
break;
}
c[i][j] = '.';
wc--;
}
if (wc == w) {
break;
}
c[99][j - 1] = '.';
wc--;
}
for (int j = 21; j < 40; j += 2) {
for (int i = 1; i <= 97; i += 2) {
if (bc == b) {
break;
}
c[i][j] = '#';
bc--;
}
if (bc == b) {
break;
}
c[0][j + 1] = '#';
bc--;
}
cout << n << " " << m << endl;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
printf("%c", c[i][j]);
}
printf("\n");
}
comps();
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<" "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;
int main() {
int h1, m1, h2, m2, k;
cin >> h1 >> m1 >> h2 >> m2 >> k;
int ans = (h2-h1)*60 + (m2-m1) - k;
cout << ans << endl;
return 0;
} | 0 | 43,826,757 |
#include<iostream>
using namespace std;
int main(void){
double xa,ya,xb,yb,xc,yc,xd,yd;
int n;
cin >> n;
while( --n >=0){
cin >> xa >> ya >> xb >> yb >> xc >> yc >> xd >> yd;
if( (yb - ya)/(xb - xa) == (yd - yc)/(xd - xc))
cout << "YES" << endl;
else
cout << "NO" << endl;
}
return 0;
} | #include<bits/stdc++.h>
using namespace std;
int table[1010][1010];
int table2[1010][1010];
typedef long long LL;
int main() {
int N = 1010;
int H,W,D;
cin >> H >> W >> D;
char c[4] = {'R', 'G', 'B', 'Y'};
if(D%2 == 1) {
for(int i=0 ;i<H; i++, cout << endl)
for(int j=0; j<W; j++)
cout << c[(i+j)%2];
}
else {
for(int i=0; i<1010; i++) {
for(int j=0; j<1010; j++) {
table[i][j] = (2*(i/D)+j/D) % 4 ;
}
}
for(int i=0; i<H; i++, cout << endl)
for(int j=0; j<W; j++)
cout << c[table[500 + i - j][0 + i + j]];
}
return 0;
} | 0 | 64,806,241 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<=n;i++)
const ll MOD = 1000000007;
long long modinv(long long a, long long m=MOD) {
long long b = m, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b; swap(a, b);
u -= t * v; swap(u, v);
}
u %= m;
if (u < 0) u += m;
return u;
}
int H,W;
const int MAXW = 2001;
const int MAXH = 2001;
string S[MAXH];
int tate[MAXH][MAXW];
int yoko[MAXH][MAXW];
void showtate(){
rep(i,H){
rep(j,W)cout << tate[i][j];
cout << endl;
}
cout << endl;
}
void showyoko(){
rep(i,H){
rep(j,W)cout << yoko[i][j];
cout << endl;
}
cout << endl;
}
int main(){
cin >> H >> W;
rep(i,H){
rep(j,W){
tate[i][j] = 0;
yoko[i][j] = 0;
}
cin >> S[i];
}
rep(i,H){
int counter = 0;
rep(j,W){
if(S[i][j]=='.'){
counter++;
yoko[i][j]=counter;
}else {
counter = 0;
}
}
}
for(int i=H-1;i>=0;i--){
for(int j=W-1;j>=1;j--){
if(yoko[i][j]>=yoko[i][j-1] && S[i][j-1]!='#'){
yoko[i][j-1] = yoko[i][j];
}
}
}
rep(j,W){
int counter = 0;
rep(i,H){
if(S[i][j]=='.') {
counter++;
tate[i][j] = counter;
}else{
counter = 0;
}
}
}
for(int i=W-1;i>=0;i--){
for(int j=H-1;j>0;j--){
if(tate[j][i]>=tate[j-1][i] && S[j-1][i] != '#'){
tate[j-1][i] = tate[j][i];
}
}
}
int ans = 0;
rep(i,H)rep(j,W){
int tmp = tate[i][j] + yoko[i][j];
ans = max(ans, tmp);
}
cout << ans-1 << endl;
return 0;
} | #ifndef _WIN32
#include<iostream>
#endif
#include<string>
#include<iomanip>
#include<vector>
#include<string>
using namespace std;
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
int main() {
int n;
while (cin >> n, n) {
int prv = 0;
int l = 0;
int r = 0;
int res=0;
REP(i, n) {
string s;
cin >> s;
if (s == "lu")l = 1;
if (s == "ru")r = 1;
if (s == "ld")l = 0;
if (s == "rd")r = 0;
if (l == r&&r != prv) {
prv = r;
res++;
}
}
cout << res << endl;
}
return 0;
} | 0 | 62,169,760 |
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin>>n;
vector<int>a(n);
map<int,int>num;
rep(i,n){
cin>>a[i];
num[a[i]]++;
}
int res=0;
for(auto v:num){
if(v.first<v.second){
res+=v.second-v.first;
}
else if(v.first>v.second){
res+=v.second;
}
}
cout<<res<<endl;
return 0;
} | #include<iostream>
using namespace std;
int main() {
for (int i = 1; i <= 9; i++){
cout << i << "x1=" << i*1 << endl;
cout << i << "x2=" << i*2 << endl;
cout << i << "x3=" << i*3 << endl;
cout << i << "x4=" << i*4 << endl;
cout << i << "x5=" << i*5 << endl;
cout << i << "x6=" << i*6 << endl;
cout << i << "x7=" << i*7 << endl;
cout << i << "x8=" << i*8 << endl;
cout << i << "x9=" << i*9 << endl;
}
return 0;
} | 0 | 83,174,797 |
#include<iostream>
using namespace std;
int main(){
int count[100];
int b;
int ans[100];
int ans2[100];
int ans3;
ans3 = 0;
for(int i=0;i<100;i++){
ans[i] = 0;
ans2[i] = 0;
count[i] = 0;
}
while(cin>>b) count[b-1]++;
for(int i=0;i<100;i++){
if(ans[ans3]<count[i]){
ans[i] = count[i];
ans2[i] = i + 1;
ans3 = i;
for(int k=0;k<100;k++) if(k!=i) ans2[k] = 0;
}
else if(ans[ans3]==count[i]&&ans3!=0) ans2[i] = i + 1;
}
for(int i=0;i<100;i++) if(ans2[i]!=0) cout << ans2[i] << endl;
return 0;
} | #include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
int main(){
int n;
cin >> n;
vector<ll>a(n);
ll p = 0;
rep(i,n){
cin >> a[i];
p ^=a[i];
}
rep(j,60){
if((p>>j)&1){
rep(i,n){
if((a[i]>>j)&1){
a[i] ^= (1LL<<j);
}
}
}
}
rep(i,min(60,n)){
sort(a.begin(),a.end(),greater<ll>());
ll c = -1;
rep(j,60){
if((a[i]>>j)&1){
c = j;
}
}
if(c==-1)break;
rep(j,n){
if(i!=j){
if((a[j]>>c)&1){
a[j]^=a[i];
}
}
}
}
sort(a.begin(),a.end(),greater<ll>());
int m = min(n,60);
cerr << bitset<60>(p) << endl;
rep(i,n){
cerr << bitset<60>(a[i]) << endl;
}
ll q = 0;
rep(i,m){
q ^=a[i];
}
cout << q + (p^q) << endl;
return 0;
} | 0 | 85,232,568 |
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);
struct fastio {
fastio() {
ios::sync_with_stdio(false);
cout << setprecision(10) << fixed;
cin.tie(0);
}
};
fastio _fast_io;
const int N = 8;
vector<int> e[N];
int n, m, f, t, ans;
int dp[1 << N][N];
int main() {
cin >> n >> m;
for (int i = 0; i < m; ++i) {
cin >> f >> t;
e[f - 1].push_back(t - 1);
e[t - 1].push_back(f - 1);
}
dp[1][0] = 1;
for (int i = 0; i < (1 << n); ++i) {
for (int j = 0; j < n; ++j) {
if (dp[i][j] != 0) {
for (int k : e[j]) {
if (!(i & (1 << k))) {
dp[i ^ (1 << k)][k] += dp[i][j];
}
}
}
}
}
for (int i = 0; i < n; ++i) {
ans += dp[(1 << n) - 1][i];
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define ALL(v) (v).begin(), (v).end()
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
#if 1
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
for (T& x : vec) is >> x;
return is;
}
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
os << "(" << pair_var.first << ", " << pair_var.second << ")";
return os;
}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
os << "{";
for (int i = 0; i < vec.size(); i++) {
os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
}
os << "}";
return os;
}
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
os << "{";
repi(itr, map_var) {
os << *itr;
itr++;
if (itr != map_var.end()) os << ", ";
itr--;
}
os << "}";
return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
os << "{";
repi(itr, set_var) {
os << *itr;
itr++;
if (itr != set_var.end()) os << ", ";
itr--;
}
os << "}";
return os;
}
#define DUMPOUT cerr
void dump_func() {
DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&& ... tail) {
DUMPOUT << head;
if (sizeof...(Tail) > 0) {
DUMPOUT << ", ";
}
dump_func(std::move(tail)...);
}
#ifdef DEBUG
#define DEB
#define dump(...) \
DUMPOUT << " " << string(#__VA_ARGS__) << ": " \
<< "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" \
<< endl \
<< " ", \
dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}
template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
for(auto &e:t) fill_v(e,v);
}
#endif
#define mod 1000000007
typedef pair<int, int> P;
#define INF (1LL<<60)
void solve(){
int N;
cin >> N;
vector<int> P(N);
vector<int> idx(N);
rep(i,N){
cin >> P[i];
P[i]--;
idx[P[i]] = i;
}
dump(idx);
int ans = 0;
set<int> s;
for(int k=N-1; k>=0; k--){
int p = idx[k];
if(k<N-1){
auto ridx = s.lower_bound(p);
int r=N, r2=N;
if(ridx==s.end()){
r = N; r2 = N;
}else{
r = *ridx;
ridx++;
if(ridx==s.end()) r2 = N;
else r2 = *ridx;
}
auto lidx = s.lower_bound(p);
int l=-1, l2=-1;
if(lidx==s.begin()){
l = -1;
l2 = -1;
}else{
lidx--;
l = *lidx;
if(lidx==s.begin()){
l2 = -1;
}else{
lidx--;
l2 = *lidx;
}
}
int tmp = (l-l2)*(r-p) + (r2-r)*(p-l);
ans += ((l-l2)*(r-p) + (r2-r)*(p-l)) * (k+1);
dump(p, s, l2, l, r, r2, tmp);
}
s.insert(p);
}
cout << ans << endl;
}
signed main(){
cout << fixed << setprecision(18);
cerr << fixed << setprecision(18);
solve();
} | 0 | 83,093,860 |
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;
ll a,b,c,d;
int main(){
scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
ll x1,x2,x3,x4;
x1=a*c;
x2=a*d;
x3=b*c;
x4=b*d;
ll ans;
ans=max(max(x1,x2),max(x3,x4));
printf("%lld",ans);
return 0;
} | #include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reg(i,a,b) for(int i=(a);i<=(b);i++)
typedef long long int lli;
typedef pair<int,int> mp;
#define fir first
#define sec second
bool warshell(int n,vector<mp>* vs,vector<int>* dist,vector<int> *gone){
rep(i,n){
gone[i].clear();
dist[i].clear();
gone[i].resize(n,-1);
dist[i].resize(n,-1);
gone[i][i]=1;
dist[i][i]=0;
rep(j,vs[i].size()){
int to=vs[i][j].fir,
co=vs[i][j].sec;
gone[i][to]=1;
dist[i][to]=co;
}
}
rep(k,n){
rep(i,n){
rep(j,n){
if(gone[i][k]==-1 || gone[k][j]==-1)continue;
int cd=dist[i][k]+dist[k][j];
if(gone[i][j]==-1 || dist[i][j]>cd){
gone[i][j]=1;
dist[i][j]=cd;
}
}
}
}
rep(i,n)if(dist[i][i]!=0)return false;
return true;
}
int n,m;
vector<mp> vs[105];
vector<int> dist[105];
vector<int> gone[105];
int main(void){
int n,m;
scanf("%d%d",&n,&m);
rep(i,m){
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
vs[a].push_back(mp(b,c));
}
if(warshell(n,vs,dist,gone)){
rep(i,n){
rep(j,n){
if(gone[i][j]!=-1)printf("%d",dist[i][j]);
else printf("INF");
printf("%s",j==n-1?"\n":" ");
}
}
}
else printf("NEGATIVE CYCLE\n");
return 0;
} | 0 | 59,164,579 |
#include <bits/stdc++.h>
using namespace std;
using edge = struct {
int next;
long d;
};
vector<edge> tree[100000];
long depth[100000] = {};
void dfs(int n, int p, long d) {
depth[n] = d;
for (auto &e : tree[n]) {
if (e.next == p)
continue;
dfs(e.next, n, d+e.d);
}
}
int main() {
int n;
cin >> n;
int a, b;
long c;
for (int i=0; i<n-1; i++) {
cin >> a >> b >> c;
a--;
b--;
tree[a].push_back({b, c});
tree[b].push_back({a, c});
}
int q, k, x, y;
cin >> q >> k;
k--;
dfs(k, -1, 0);
for (int i=0; i<q; i++) {
cin >> x >> y;
cout << depth[x-1]+depth[y-1] << '\n';
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
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 dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int N; cin >> N;
ves s(N); vi t(N); int ans = 0;
string X;
rep(i,N) cin >> s[i] >> t[i];
cin >> X;
int i = 0;
while(X!=s[i]) {
i++;
}
i++;
while(i < N) {
ans += t[i];
i++;
}
cout << ans << endl;
} | 0 | 87,234,530 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
int main(){
int n;
cin >> n;
vector<pair<int,int>> rp(n);
vector<pair<int,int>> bp(n);
rep(i,n){
int a,b;
cin >> a >> b;
rp[i]=make_pair(b,a);
}
rep(i,n){
int c,d;
cin >> c >> d;
bp[i]=make_pair(c,d);
}
sort(bp.begin(),bp.end());
sort(rp.begin(),rp.end(),greater<pair<int,int>>());
int ans=0;
int i=0;
while(i<rp.size()){
bool z=false;
int j=0;
while(j<bp.size()){
if(rp[i].second-bp[j].first<0 && rp[i].first-bp[j].second<0){
ans++;
rp.erase(rp.begin()+i);
bp.erase(bp.begin()+j);
z=true;
break;
}
j++;
}
if(!z) i++;
}
cout << ans << "\n";
} | #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;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;
int main()
{
ll A, B;
cin >> A >> B;
if (A == 1 || B == 1)
{
if (A == B)
{
cout << "Draw" << endl;
}
else if (A == 1)
{
cout << "Alice" << endl;
}
else
{
cout << "Bob" << endl;
}
}
else
{
if (A == B)
{
cout << "Draw" << endl;
}
else if (A > B)
{
cout << "Alice" << endl;
}
else
{
cout << "Bob" << endl;
}
}
} | 0 | 78,961,977 |
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
int w,h,x,y,r;
cin >> w >> h >> x >> y >> r;
cout << (x-r<0 || y-r<0 || x+r>w || y+r>h ? "No":"Yes") << endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"
template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}
const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;
int main(){
cin.tie(0);ios::sync_with_stdio(false);
ll n,m;
cin>>n>>m;
vector<P> g(n);
rep(i,n){
cin>>g[i].fi>>g[i].se;
}
sort(begin(g),end(g));
ll ans=0;
rep(i,n){
if(m>=g[i].se){
ans+=g[i].fi*g[i].se;
m-=g[i].se;
}else{
ans+=g[i].fi*m;
break;
}
}
cout<<ans<<endl;
} | 0 | 82,396,053 |
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i < (n);i++)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pil = pair<pii,int>;
int main(){
int n;
cin >> n;
cout << n/3 << endl;
} | #include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
template<typename T> auto compare = [](T x, T y) -> bool{return (x < y);};
const int MOD = 1000000007;
int N;
ll A[100010];
ll acc[100010], num[100010];
signed main(){
cin >> N;
REP(i, N + 1) cin >> A[i];
REP(i, N + 1){
acc[i] += A[i];
acc[i + 1] += acc[i];
}
if(A[0] > 1){
PRINT("-1");
return 0;
}
num[0] = 1;
ll ans = 1;
FOR(i, 1, N + 1){
num[i] = min((num[i - 1] - A[i - 1]) * 2, acc[N] - acc[i - 1]);
if(num[i] <= 0){
PRINT("-1");
return 0;
}
ans += num[i];
}
if(num[N] != A[N]){
PRINT("-1");
return 0;
}
PRINT(ans);
return 0;
} | 0 | 58,490,693 |
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define MOD 1000000007
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define ALL(v) v.begin(), v.end()
typedef long long ll;
int main(){
int a,b,c;
cin >> a >> b >> c;
if(c-a+b>=0)cout << c-a+b <<endl;
else cout << 0 << endl;
return 0;
} | #include<iostream>
#include<algorithm>
int main () {
int k, s;
std::cin >> k >> s;
long long ans = 0;
for (int x = 0; x <= k; x++)
{
for (int y = 0; y <= k; y++) {
int z = s - x - y;
if(z >= 0 && z <= k) {
ans++;
}
}
}
std::cout << ans << "\n";
} | 0 | 41,458,962 |
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
int main() {
string S;
cin>>S;
for(ll i=0;i<19;i++) {
if(i==5||i==13) {
cout<<" ";
}
else {
cout<<S[i];
}
}
cout<<endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define rep(i, n) for(int i = 0; i < (n); i++)
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define dump(x) cout << #x << " = " << (x) << endl
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define MINS(m, s) m.insert(make_pair(s, 1));
#define MFIN(m, s) m.find(s) != m.end()
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9 + 7;
int main() {
ll n, m, a;
cin >> n >> m;
priority_queue<ll> p_que;
for(ll i = 0; i < n; i++) {
cin >> a;
p_que.push(a);
}
for(ll i = 0; i < m; i++) {
ll t = p_que.top();
p_que.pop();
p_que.push(t / 2);
}
ll sum = 0;
for(ll i = 0; i < n; i++) {
sum += p_que.top();
p_que.pop();
}
cout << sum << endl;
return 0;
} | 0 | 42,433,359 |
#include <iostream>
using namespace std;
int main(){
int m;
while(cin >> m,m){
int c=0;
m=1000-m;
while(m-500>=0){
m=m-500;
c++;
}
while(m-100>=0){
m=m-100;
c++;
}
while(m-50>=0){
m=m-50;
c++;
}
while(m-10>=0){
m=m-10;
c++;
}
while(m-5>=0){
m=m-5;
c++;
}
while(m-1>=0){
m=m-1;
c++;
}
cout << c << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int C[5];
int main(void){
int a,b,c,d,e,f;
cin>>a>>b>>c>>d>>e>>f;
C[a]++; C[b]++; C[c]++; C[d]++; C[e]++; C[f]++;
for(int i=1;i<=4;i++){
if(C[i]>=3){
cout<<"NO"<<endl;
return 0;
}
}
cout<<"YES"<<endl;
} | 0 | 91,268,122 |
#include <bits/stdc++.h>
#include <numeric>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep1(i,n) for (int i = 1; i <= n; ++i)
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline T intceil(T a, T b) { return (a + (b - 1)) / b; }
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
const long long MOD = 1e9+7;
#define precout() cout << std::fixed << std::setprecision(20);
const string alphabet = "abcdefghijklmnopqrstuvwxyz";
const int dy[4] = { 0, 1, 0, -1 };
const int dx[4] = { 1, 0, -1, 0 };
typedef complex<double> cd;
static const double pi = 3.141592653589793;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
string s; cin >> s;
int n = s.size();
ll k; cin >> k;
int need = 0;
for(int i = 1; i < n; ++i) {
if(s[i] == s[i - 1]) {
++need;
++i;
}
}
if(k == 1) {
cout << need << endl;
return 0;
}
bool only = 1;
for(int i = 1; i < n; ++i) {
if(s[i] != s[i - 1]) {
only = 0;
break;
}
}
if(only) {
ll cnt = n * k;
ll ans = cnt / 2;
cout << ans << endl;
return 0;
}
s += s;
n = s.size();
int needTwice = 0;
for(int i = 1; i < n; ++i) {
if(s[i] == s[i - 1]) {
++needTwice;
++i;
}
}
ll diff = needTwice - need;
ll ans = need + (k - 1) * diff;
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))
#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long
#define Ceil(x, n) (((((x))+((n)-1))/n))
#define CeilN(x, n) (((((x))+((n)-1))/n)*n)
#define FloorN(x, n) ((x)-(x)%(n))
#define ALL(x) (x).begin(),(x).end()
typedef pair<ll, ll> P;
int main() {
string s;
cin >> s;
int n = s.size();
vector<bool> used(26, false);
REP(i, n) {
used[s[i] - 'a'] = true;
}
if(s == "zyxwvutsrqponmlkjihgfedcba") {
cout << "-1" << endl;
return 0;
}
if(n < 26) {
REP(i, 26) {
if(!used[i]) {
cout << s << (char)('a' + i) << endl;
return 0;
}
}
}
int nozoku = 0;
bool find = false;
REP_REV(i, n) {
int idx = s[i] - 'a';
REPN(j, idx+1, 26) {
if(!used[j]) {
s[i] = 'a' + j;
find = true;
break;
}
}
if(find) break;
used[idx] = false;
nozoku++;
}
cout << s.substr(0, n-nozoku) << endl;
return 0;
} | 0 | 9,188,464 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
ll l, r;
cin >> l >> r;
ll mi = 2000000000;
if (r - l > 2019) cout << 0;
else {
for (ll i = l; i < r; i++) {
for (ll j = i + 1; j < r + 1; j++) {
ll rem = (i * j) % 2019;
mi = min(rem, mi);
}
}
cout << mi;
}
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
const int MOD=1e9+7;
const long double Pi=acos(-1);
using P=pair<ll,ll>;
ll gcd(ll a,ll b){
if(a%b==0){return b;}
else{return gcd(b,a%b);}
}
ll lcm(ll a,ll b){
return a*b/gcd(a,b);
}
ll pow(ll x,ll y){
ll tmp=x,res=1;
while(y){
if(y%2){res=res*tmp%MOD;}
y>>=1;
tmp=tmp*tmp%MOD;
}
return res;
}
ll nature(ll a){
if(a>=0){return(a);}
else{return(-1*a);}
}
ll prime(ll a){
if(a==2){return 1;}
else if(a%2==0 || a==1){return 0;}
for(ll i=3;i*i<=a;i+=2){if(a%i==0){return 0;}}
return 1;
}
vector<int> Z;
void z_algorithm(string str){
Z.resize(str.size());
Z.at(0)=str.size();
int m=1,n=0;
while(m<(int)str.size()){
while(m+n<(int)str.size()&&str.at(n)==str.at(m+n)){n++;}
Z.at(m)=n;
if(n==0){
m++;
continue;
}
int k=1;
while(k+Z.at(k)<n){
Z.at(m+k)=Z.at(k);
k++;
}
m+=k;
n-=k;
}
}
template <typename T>
struct BIT{
int n;
vector<T> bit[2];
void init(int n_){
n=n_+1;
for(int j=0;j<2;j++){
bit[j].assign(n,0);
}
}
void add_sub(int p,int i,T x){
for(int j=i;j<n;j+=j&-j){
bit[p][j]+=x;
}
}
void add(int l,int r,T x){
add_sub(0,l,-x*(l-1));
add_sub(0,r+1,x*r);
add_sub(1,l,x);
add_sub(1,r+1,-x);
}
T sum_sub(int p,int i){
T s(0);
for (int j=i;j>0;j-=j&-j){
s+=bit[p][j];
}
return s;
}
T sum(int i,int j){
return sum_sub(0,j)+sum_sub(1,j)*j-sum_sub(0,i-1)-sum_sub(1,i-1)*(i-1);
}
T binary_search_sum1(int key){
if(key<=0){
return 0;
}
else{
int x=0,r=1;
while(r<n){
r=r<<1;
}
for(int length=r;length>0;length=length>>1){
if(x+length<n&&sum(x+1,x+length)<key){
key-=sum(x+1,x+length);
x+=length;
}
}
return x+1;
}
}
T binary_search_sum2(int key){
key++;
if(key<=0){
return 0;
}
else{
int x=0,r=1;
while(r<n){
r=r<<1;
}
for(int length=r;length>0;length=length>>1){
if(x+length<n&&sum(x+1,x+length)<key){
key-=sum(x+1,x+length);
x+=length;
}
}
return x;
}
}
};
template<typename T>
struct BIT2D{
int H,W;
vector<vector<T>> bit;
void init(int H_,int W_){
H=H_+1;
W=W_+1;
bit.assign(H,vector<T>(W,0));
}
void add(int h,int w,T x){
for(int i=h;i<H;i+=i&-i){
for(int j=w;j<W;j+=j&-j){
bit[i][j]+=x;
}
}
}
T sum(int h,int w){
T s=0;
for(int i=h;i>0;i-=i&-i){
for(int j=w;j>0;j-=j&-j){
s+=bit[i][j];
}
}
return s;
}
T partsum(int h,int w,int hh,int ww){
return sum(hh,ww)+sum(h-1,w-1)-sum(hh,w-1)-sum(h-1,ww);
}
};
int main(){
int N,K;
cin>>N>>K;
vector<int> A(N);
for(int i=0;i<N;i++){
cin>>A.at(i);
}
BIT<int> rock;
rock.init(N);
for(int i=1;i<=N;i++){
rock.add(i,i,A.at(i-1));
}
vector<int> copy(N);
for(int i=0;i<K;i++){
for(int i=1;i<=N;i++){
copy.at(i-1)=rock.sum(i,i);
}
for(int i=1;i<=N;i++){
rock.add(i,i,-1*rock.sum(i,i));
}
for(int i=1;i<=N;i++){
int left=max(1,i-copy.at(i-1)),right=min(N,i+copy.at(i-1));
rock.add(left,right,1);
}
int check=0;
for(int i=1;i<=N;i++){
if(rock.sum(i,i)==N){check++;}
}
if(check==N){break;}
}
for(int i=1;i<=N;i++){
cout<<rock.sum(i,i)<<" ";
}
} | 0 | 58,002,603 |
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vi p(n);
rep(i, n) cin >> p[i];
vi a(n, 1), b(n, 1);
int h = n-1;
rep(i, n) {
int now = p[i];
now--;
if(now != n-1) a[now+1] += h;
if(now) b[now-1] += h;
h--;
}
rep(i, n-1) {
a[i+1] += a[i];
b[n-i-2] += b[n-i-1];
}
rep(i, n) {
cout << a[i] << (i == n-1?'\n':' ');
}
rep(i, n) {
cout << b[i] << (i == n-1?'\n':' ');
}
} | #include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);
int main() {
int N;
cin>>N;
string tmp;
int ans = 0;
int anum=0, bnum=0, banum=0;
bool notba = false;
for(int i=0;i<N;++i) {
cin>>tmp;
for(int i=0;i<tmp.size()-1;++i) {
if(tmp[i]=='A' && tmp[i+1]=='B') ans++;
}
if(tmp[0]=='B' && tmp[tmp.size()-1]=='A') {
anum++;
bnum++;
}
else if(tmp[0]=='B') {
bnum++;
notba = true;
}
else if(tmp[tmp.size()-1]=='A') {
anum++;
notba = true;
}
}
if(notba) cout<<ans+min(anum, bnum)<<endl;
else if(min(anum, bnum)>0) cout<<ans+min(anum, bnum)-1<<endl;
else cout<<ans<<endl;
} | 0 | 74,578,522 |
#include <iostream>
using namespace std;
long long dist(long long a, long long b, long long c, long long d){
return abs(a-c)+abs(b-d);
}
int main() {
int N, M;
cin >> N >> M;
long long s[N][2];
long long p[M][2];
for (int i=0; i<N; i++){
cin >> s[i][0] >> s[i][1];
}
for (int i=0; i<M; i++){
cin >> p[i][0] >> p[i][1];
}
for (int i=0; i<N; i++){
long long x = dist(s[i][0],s[i][1],p[0][0],p[0][1]);
int order = 1;
for (int j=1; j<M; j++){
long long y = dist(s[i][0],s[i][1],p[j][0],p[j][1]);
if (y<x){
x = y;
order = j+1;
}
}
cout << order << '\n';
}
} | #include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
struct UnionF {
vector<ll> S;
UnionF(ll a){
S=vector<ll>(a);
for(ll i=0;i<a;i++)S[i]=i;
}
ll FFi(ll i){
if(S[i]==i)return i;
S[i]=FFi(S[i]);
return S[i];
}
void marge(ll a,ll b){
ll aa=FFi(a),bb=FFi(b);
if(aa==bb)return;
ll mms = (aa<bb)?aa:bb;
S[aa]=mms;S[bb]=mms;
}
bool equalU(ll a,ll b){return (FFi(S[a])==FFi(S[b]));}
};
int main() {
ll N,Q;
cin >> N >> Q;
UnionF U(N);
while(Q){
ll sub1,sub2,sub3;
cin >> sub1 >> sub2 >> sub3;
if(sub1==0)U.marge(sub2, sub3);
else {
if(U.equalU(sub2, sub3))cout << 1 << endl;
else cout << 0 << endl;
}
Q--;
}
} | 0 | 46,013,118 |
#include<iostream>
#include<string>
#include<set>
using namespace std;
int main() {
int n;
cin >> n;
set<string> Dic;
string com, word;
while( n-- ) {
cin>>com>>word;
if(com[0] == 'i' ) Dic.insert(word);
else {
if( Dic.find(word) != Dic.end() ) cout << "yes" << endl;
else cout << "no" <<endl;
}
}
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int>>
#define vvb vector<vector<bool>>
#define vb vector<bool>
#define pii pair<int, int>
#define vpli vector<pair<long long, int>>
#define deb(x) cout << "deb " << #x << " " << x << endl;
#define all(x) x.begin(), x.end()
#define endl "\n"
const ll BIG = 1e18;
void swap(ll &a, ll &b)
{
ll t = a;
a = b;
b = t;
}
ll Min(ll a, ll b, ll c)
{
return min(a, min(b, c));
}
void printvec(vi &vec)
{
for (int x : vec)
{
cout << x << " ";
}
cout << endl;
}
int sum(int a)
{
int ans = 0;
while (a)
{
ans += (a % 10);
a = a / 10;
}
return ans;
}
void print(vi &mp)
{
for (auto x : mp)
{
cout << x;
}
cout << endl;
}
void solve()
{
ll n;
cin >> n;
ll ans = 0;
for(ll i=2;i*i<=n;i++)
{
int power = 0;
while(n%i == 0)
{
power++;
n = n/i;
}
int reqd = 1;
while(power>=reqd)
{
ans ++;
power -= reqd;
reqd++;
}
}
if(n!=1) ans++;
cout<<ans<<endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t = 1;
while (t--)
solve();
return 0;
} | 0 | 8,149,017 |
#include <iostream>
#include <queue>
using namespace std;
int main ()
{
priority_queue <int> gquiz;
string s;
int x;
while (cin>>s,s!="end"){
if (s=="insert"){
cin>>x;
gquiz.push(x);
}
if (s=="extract"){
cout<<gquiz.top()<<'\n';
gquiz.pop();
}
}
return 0;
} | #include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define orz 1000000007
using namespace std;
int n,a[100005];
vector<int> v[100005];
void dfs(int x,int y){
for(int i=0;i<v[x].size();++i){
int z=v[x][i];
if(y==z) continue;
dfs(z,x);
a[x]^=(a[z]+1);
}
}
int main(){
scanf("%d",&n);
for(int i=1;i<n;++i){
int x,y;
scanf("%d%d",&x,&y);
v[x].pb(y),v[y].pb(x);
}
dfs(1,0);
if(a[1])puts("Alice");
else puts("Bob");
return 0;
} | 0 | 33,760,956 |
#include<cstdio>
#include<algorithm>
using namespace std;
int n,a[100010];
double Abs(double x) { return (x>0)?x:-x;}
int main()
{
scanf("%d",&n);
int Max=-1<<29,x=-1<<29;
for (int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
Max=max(Max,a[i]);
}
for (int i=1;i<=n;i++)
if (a[i]!=Max&&Abs((double)Max/2-a[i])<=Abs((double)Max/2-x)) x=a[i];
printf("%d %d\n",Max,x);
return 0;
} | #include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
int main()
{
int n, k;
cin >> n >> k;
set<int> S;
vector<pair<int,int>> V0;
rep(i,n) {
int t, d;
cin >> t >> d;
V0.emplace_back(t,d);
}
sort(V0.rbegin(), V0.rend());
vector<pair<int,int>> V;
for (auto v : V0) {
if (S.find(v.first) == S.end()) {
S.insert(v.first);
V.emplace_back(v.second, 1);
} else {
V.emplace_back(v.second, 0);
}
}
sort(V.rbegin(), V.rend());
ll x = 0;
ll y = 0;
auto f = [&](){return x + y*y;};
rep(i,k) {
x += V[i].first;
if(V[i].second == 1) y++;
}
ll ans = f();
vector<int> T;
for(int i= k; i<n; i++) {
if(V[i].second == 1) T.push_back(V[i].first);
}
sort(T.rbegin(), T.rend());
vector<int> W;
rep(i,k) {
if (V[i].second == 0) W.push_back(V[i].first);
}
sort(W.begin(), W.end());
rep(i, T.size()) {
if (i == W.size()) break;
y++;
x += T[i];
x -= W[i];
ans = max(f(), ans);
}
cout << ans << endl;
return 0;
} | 0 | 42,241,223 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
int main() {
int n;
cin >> n;
string alphabet = "abcdefghijklmnopqrstuvwxyz";
map<char, int>mp;
string s;
for (int i = 0; i < n; i++) {
cin >> s;
map<char, int> m;
for (int j = 0; j < s.size(); j++) {
m[s[j]]++;
}
for (int j = 0; j < alphabet.size(); j++) {
if (i == 0) {
mp[alphabet[j]] = m[alphabet[j]];
} else {
mp[alphabet[j]] = min(mp[alphabet[j]], m[alphabet[j]]);
}
}
}
string ans = "";
for (int i = 0; i < alphabet.size(); i++) {
if (mp[alphabet[i]] > 0) {
for (int j = 0; j < mp[alphabet[i]]; j++) {
ans += alphabet[i];
}
}
}
cout << ans << endl;
} | #include<bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
const int mod = 1e9+7;
const int mx = INT_MAX;
const long double pi = 4*atan((long double)1);
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
#define file "orz"
const int mxN=1e5+5;
int n, arr[mxN], cnt[mxN], occ[mxN];
signed main()
{
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin>>n;
priority_queue<pii> pq;
for(int i=1;i<=n;i++)
{
cnt[i]=1;
cin>>arr[i];
pq.push(mp(arr[i],i));
}
while(pq.size()>=2)
{
auto temp=pq.top();
pq.pop();
auto temp2=pq.top();
pq.pop();
occ[temp.se] += cnt[temp.se]*(temp.fi-temp2.fi);
cnt[min(temp.se,temp2.se)]+=cnt[max(temp.se,temp2.se)];
pq.push(mp(temp2.fi,min(temp.se,temp2.se)));
}
cout<<occ[1]+n*pq.top().fi<<"\n";
for(int i=2;i<=n;i++)
cout<<occ[i]<<"\n";
} | 0 | 35,951,865 |
#include <bits/stdc++.h>
using namespace std;
int main(void){
int R;
int G;
cin >> R >> G;
cout<<G-R+G;
} | #include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)
#define inf (1<<29)
int main(int argc,char* argv[]){
int n;
cin >> n;
vector<int> a(n);
for(auto &x:a)cin >> x;
int count=0;
for(int i=0;i<a.size();i++){
if(a[i]!=i+1){
a.erase(a.begin()+i);
count++;
i--;
}
}
if(a.size())cout << count << endl;
else cout << -1 << endl;
return 0;
} | 0 | 29,909,404 |
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
typedef long long lint;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
const lint MOD =1000000007;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
typedef map<lint,lint> M;
lint fac[MAX], finv[MAX], inv[MAX];
void COMinit()
{
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (lint i = 2; i < MAX; i++)
{
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
long long COM(lint n, lint k)
{
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
lint primary(lint num)
{
if (num < 2) return 0;
else if (num == 2) return 1;
else if (num % 2 == 0) return 0;
double sqrtNum = sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2)
{
if (num % i == 0)
{
return 0;
}
}
return 1;
}
long long modpow(long long a, long long n, long long mod) {
long long res = 1;
while (n > 0) {
if (n & 1) res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
lint lcm(lint a,lint b){
return a/__gcd(a,b)*b;
}
lint gcd(lint a,lint b){
return __gcd(a,b);
}
int main(){
lint n;
cin >>n;
map<lint,lint> mp;
map<lint,lint> mp2;
rep(i,n){
lint a;
cin>>a;
if(i%2==0)mp[a]++;
else mp2[a]++;
}
vector<P> p;
vector<P> p2;
for(auto x:mp){
p.push_back(make_pair(x.second,x.first));
}
for(auto x:mp2){
p2.push_back({x.second,x.first});
}
p.push_back({0,0});
p2.push_back({0,0});
sort(all(p),greater<P>());
sort(all(p2),greater<P>());
if(p[0].second!=p2[0].second){
cout<<n-p[0].first-p2[0].first<<endl;
}else{
lint x=max(p[0].first+p2[1].first,p[1].first+p2[0].first);
cout<<n-x<<endl;
}
} | #include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define Rep(i,n) for(int i = 1; i <= n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
template<class T> using V = vector<T>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main(){
int h, w, m;
cin >> h >> w >> m;
V<int> cnt_h(h), cnt_w(w);
set<P> points;
rep(i,m) {
int y, x;
cin >> y >> x;
y--; x--;
cnt_h[y]++;
cnt_w[x]++;
points.emplace(y,x);
}
int mx_h = 0, mx_w = 0;
rep(i,h) chmax(mx_h, cnt_h[i]);
rep(i,w) chmax(mx_w, cnt_w[i]);
V<int> hs, ws;
rep(i,h) if(cnt_h[i] == mx_h) hs.push_back(i);
rep(i,w) if(cnt_w[i] == mx_w) ws.push_back(i);
int ans = mx_w + mx_h;
for(int i : hs) for(int j : ws) {
if(points.count(make_pair(i,j))) continue;
cout << ans << endl;
return 0;
}
ans--;
cout << ans << endl;
} | 0 | 48,887,868 |
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
vector<ll> a, b, c;
int main(){
ll x, y, z, k;
cin >> x >> y >> z >> k;
rep(i, x){
ll A;
cin >> A;
a.push_back(A);
}
rep(i, y){
ll B;
cin >> B;
b.push_back(B);
}
rep(i, z){
ll C;
cin >> C;
c.push_back(C);
}
sort(c.begin(), c.end(), greater<ll>());
vector<ll> ab;
rep(i, x){
rep(j, y) ab.push_back(a[i] + b[j]);
}
sort(ab.begin(), ab.end(), greater<ll>());
vector<ll> ans;
ll idx_ab = min(k, x * y);
ll idx_c = min(k, z);
rep(i, idx_ab) rep(j, idx_c) ans.push_back(ab[i] + c[j]);
sort(ans.begin(), ans.end(), greater<ll>());
rep(i, k) cout << ans[i] << endl;
return 0;
} | #include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;
int main(){
Init();
ll n, k; cin >> n >> k;
vi a(n);
bool possible = false;
ll gcdNum = -1;
rep(i, n){
cin >> a[i];
if(a[i] == k) possible = true;
if(i == 0) gcdNum = a[i];
else gcdNum = __gcd(gcdNum, a[i]);
}
sort(all(a));
if(a[n-1] >= k && !possible){
ll sub = k-a[n-1];
if(sub%gcdNum == 0) possible = true;
}
cout << (possible ? "POSSIBLE" : "IMPOSSIBLE") << endl;
} | 0 | 91,110,138 |
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define INF INT_MAX;
typedef long long ll;
using namespace std;
int main(){
int x;cin >> x;
(x<1200) ? puts("ABC") : puts("ARC");
} | #include <bits/stdc++.h>
using namespace std;
#define INF INT_MAX/3
#define LLINF LLONG_MAX/3
#define MOD (1000000007LL)
#define MODA(a, b) a=((a)+(b))%MOD
#define MODP(a, b) a=((a)*(b))%MOD
#define inc(i, l, r) for(long long i=(l);i<(r);i++)
#define dec(i, l, r) for(long long i=(r)-1;i>=(l);i--)
#define pb push_back
#define se second
#define fi first
#define mset(a, b) memset(a, b, sizeof(a))
using LL = long long;
using G = vector<vector<int>>;
int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
int main() {
std::ios::sync_with_stdio(false);
LL x, y;cin >> x >> y;
if(abs(x-y) <= 1){
cout << "Brown" << endl;
}else{
cout << "Alice" << endl;
}
return 0;
} | 0 | 13,363,091 |
#include<iostream>
#include<string>
using namespace std;
int main() {
string str, cmd;
int a, b, q;
cin >> str >> q;
for (int i = 0; i < q; i++) {
cin >> cmd >> a >> b;
if (cmd == "print") {
for (int j = a; j <= b; j++)
cout << str[j]; cout << endl;
}
else if (cmd == "reverse") {
int fend = (b - a + 1) / 2;
for (int j = 0; j < fend; j++)
swap(str[a++], str[b--]);
}
else if (cmd == "replace") {
string p; int n = 0;
cin >> p;
for (int k = a; k <= b; k++) {
str[k] = p[n++];
}
}
}
return 0;
} | #include<iostream>
#include<algorithm>
#define ios ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
typedef long long ll;
ll a,b,c,d;
int main()
{
ios;
cin>>a>>b>>c>>d;
ll m1,m2,m3,m4,maxn;
m1=a*c,m2=a*d;
m3=b*c,m4=b*d;
maxn=max(max(max(m1,m2),m3),m4);
cout<<maxn<<"\n";
return 0;
} | 0 | 13,573,552 |
#include<bits/stdc++.h>
using namespace std;
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout<<fixed; cout<<setprecision(12);
#define randomINT mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define newl cout<<"\n"
#define DISP(as) for(auto it : as) cout<<it<<" ";newl;
#define all(x) (x).begin(),(x).end()
#define mset(x,val) memset(x,val,sizeof(x))
#define newl cout<<"\n"
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define dline cerr<<"
#define deb1(x) cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y) cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z) cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';
typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll , ll> pll;
typedef pair<ld, ld> pld;
typedef unordered_map<ll, ll> um;
typedef vector<pll> vpll;
const ll MAX5 = 1e+5 + 7;
const ll MAX7 = 1e+7 + 7;
const ll MAXN = MAX7;
const ll INF = 0x7f7f7f7f7f7f7f7f;
const int INFi = 0x7f7f7f7f;
const ll MOD = 1e+9 + 7;
const ll N = 3*MAX5;
ll T = 1;
ll n, x, m, y, k, z, l;
string s, t, d, c;
void MAIN() {
ld n,k;
cin >> n >> k;
ld ans = 0;
for(ll i=1;i<=n;i++) {
ld score = i;
ld val = 1;
ll cou = 0;
while(score < k) cou++,score*=2;
val /= (n);
val /= pow(2,cou);
ans += val;
}
cout<<ans;
}
int main() {
fastio; randomINT;
while (T--) {
MAIN();
}
return 0;
} | #include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <sstream>
#include <fstream>
#include <iostream>
#include <algorithm>
using namespace std;
int m[128], costs[128][128];
int calc(int s, int e){
if(s==e) return 0;
if(costs[s][e] == INT_MAX){
if(e-s==1) return costs[s][e] = m[s-1] * m[s] * m[e];
for(int i = s; i < e; i++){
costs[s][e] = min(costs[s][e], calc(s, i) + calc(i+1, e) + m[s-1] * m[i] * m[e]);
}
}
return costs[s][e];
}
int main() {
int n;
scanf("%d", &n);
for(int i = 0; i < n; i++){
scanf("%d %d", &m[i], &m[i+1]);
}
for(int i = 0; i <= n; i++){
for(int j = 0; j <= n; j++){
costs[i][j] = INT_MAX;
}
}
printf("%d\n", calc(1, n));
return 0;
} | 0 | 31,162,535 |
#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int MOD = 1000000007;
const int INF = 1e11;
using Graph = vector<vector<int>>;
signed main(){
vector<int> prime;
for( int i = 2; i <= 100; i++ ){
bool fg = 1;
for( int j = 2; j < i; j++ ){
if( i%j == 0 ) fg = 0;
}
if( fg ) prime.push_back(i);
}
int N;
cin >> N;
int p = (int)prime.size();
vector<int> fac(p+10);
for( int i = 1; i <= N; i++ ){
int n = i;
for( int j = 0; j < p; j++ ){
while( n%prime[j] == 0 ){
n /= prime[j];
fac[j]++;
}
}
}
int ans = 0;
for( int i = 0; i < p; i++ ){
if( fac[i] >= 74 ) ans++;
}
for( int i = 0; i < p; i++ ){
for( int j = 0; j < p; j++ ){
if( i == j ) continue;
int a = fac[i];
int b = fac[j];
if( a>=2 && b>=24 ) ans++;
if( a >= 4 && b >= 14 ) ans++;
}
}
for( int i = 0; i < p; i++ ){
for( int j = 0; j < p; j++ ){
for( int k = j+1; k < p; k++ ){
if( i == j || i == k ) continue;
if( fac[i] >= 2 && fac[j] >= 4 && fac[k] >= 4 ) ans++;
}
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin>>n;
string s;
cin>>s;
int k;
cin>>k;
char cwk=s.at(k-1);
for(int i=0;i<n;i++){
if(s.at(i)!=cwk)
s.at(i)='*';
}
cout<<s<<endl;
return 0;
} | 0 | 63,149,300 |
#include "bits/stdc++.h"
using namespace std;
void Main() {
int N;
cin >> N;
vector<int> a(N, 0);
for (int i = 0; i < N; ++i) {
cin >> a[i];
a[i] -= 1;
}
set<int> lighten;
int ans = -1;
int l = 0;
for (int i = 0; i < N; ++i) {
l = a[l];
if (l == 1) {
ans = i + 1;
break;
}
}
cout << ans << endl;
}
int main() {
std::cout << std::fixed << std::setprecision(15);
Main();
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
constexpr double eps=1e-8;
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int Random(int mi,int ma){
random_device rnd;
mt19937 mt(rnd());
uniform_int_distribution<int>engine(mi,ma);
return engine(mt);
}
int gcd(int a,int b){
if(b==0)return a;
return gcd(b,a%b);
}
int lcm(int a,int b){
return a/gcd(a,b)*b;
}
bool prime(int a){
if(a==1)return false;
for(int i=2;i*i<=a;i++){
if(a%i==0)return false;
}
return true;
}
int modpow(int a,int b){
if(b==0)return 1;
if(b%2)return modpow(a,b-1)*a%mod;
int memo=modpow(a,b/2);
return memo*memo%mod;
}
vector<int>kaijo,invkaijo;
void init_fact(int n){
kaijo.resize(n+1);
invkaijo.resize(n+1);
kaijo[0]=1;
for(int i=1;i<=n;i++){
kaijo[i]=kaijo[i-1]*i;
kaijo[i]%=mod;
}
rep(i,n+1)invkaijo[i]=modpow(kaijo[i],mod-2);
}
int comb(int a,int b){
if(a<b)return 0;
if(a<0||b<0)return 0;
return kaijo[a]*invkaijo[a-b]%mod*invkaijo[b]%mod;
}
int inv(int x){
x=modpow(x,mod-2);
return x;
}
int n,a[300010];
vector<int>v,sum={0};
map<int,int>mp;
bool check(int k,int m){
int x=lower_bound(all(v),m)-v.begin();
int res=sum[x]+(v.size()-x)*m;
return res>=m*k;
}
signed main(){
cin.tie(0);ios::sync_with_stdio(false);
cin>>n;
rep(i,n){
cin>>a[i];
mp[a[i]]++;
}
for(P p:mp)v.pb(p.se);
sort(all(v));
for(int i:v)sum.pb(sum.back()+i);
for(int k=1;k<=n;k++){
int ok=0,ng=n+1;
while(ng-ok>1){
int m=(ok+ng)/2;
if(check(k,m))ok=m;
else ng=m;
}
cout<<ok<<endl;
}
return 0;
} | 0 | 96,900,556 |
#include <bits/stdc++.h>
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,n) for(ll i=0;i<(n);++i)
#define repA(i,a,n) for(ll i=a;i<=(n);++i)
#define repD(i,a,n) for(ll i=a;i>=(n);--i)
using namespace std;
using ll = long long;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n,l;
cin>>n>>l;
vector<string> v(n);
rep(i,n) cin>>v[i];
sort(v.begin(), v.end());
rep(i,n) cout<<v[i];
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PB(x, v) x.push_back(v);
#define pll pair<ll, ll>
#define ll long long
#define mll map<ll, ll>
#define vl vector<ll>
#define fa(x, v) for(auto x: v)
#define fr(i, a, b) for(int i= a;i <=b; i++)
#define B_ begin()
#define E_ end()
#define all(a) a.begin(), a.end()
#define NL_ "\n"
#define MAX 2000000000
#define F first
#define S second
#define FF first.first
#define FS first.second
#define SF second.first
#define SS second.second
#define mod(a) a%1000000007
int main()
{
FAST;
ll n;
cin >> n;
ll arr[n];
for(ll i=0; i< n; i++)
{
cin >> arr[i];
}
ll mn = LLONG_MAX;
ll cnt= 0;
for(int i = 0; i< n; i++)
{
mn = min(arr[i], mn);
if(mn>=arr[i]) cnt++;
}
cout << cnt<<NL_;
return 0;
} | 0 | 32,648,986 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for (int (i)=0; (i) < (n); (i)++)
int main()
{
ll N, M; cin >> N >> M;
vector<ll> a(N, 0);
vector<ll> b(N, 0);
rep(i,M) {
ll A, B; cin >> A >> B;
if (A == 1) {
a[B-1] = 1;
}
else if (B == 1) {
a[A-1] = 1;
}
if (A == N) {
b[B-1] = 1;
}
else if (B == N) {
b[A-1] = 1;
}
}
rep(i,N) {
if (a[i] == 1 && b[i] == 1) {
cout << "POSSIBLE" << endl;
exit(0);
}
}
cout << "IMPOSSIBLE" << endl;
} | #include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define DUMP(v) for(auto& x : v) cerr << x << " "; cerr << endl;
using namespace std;
using ll = long long;
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; }
constexpr int INF = 1e9+5;
constexpr long long INFLL = 1LL<<60;
constexpr double eps = (1e-9);
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int x, y, z, k;
cin >> x >> y >> z >> k;
vector<ll> a(x), b(y), c(z);
rep(i, x) cin >> a[i];
rep(i, y) cin >> b[i];
rep(i, z) cin >> c[i];
vector<ll> bc(y * z);
rep(i, y) {
rep(j, z) {
bc.push_back(b[i] + c[j]);
}
}
sort(bc.rbegin(), bc.rend());
bc.resize(min(3000, int(bc.size())));
vector<ll> abc;
rep(i, x) {
rep(j, bc.size()) {
abc.push_back(a[i] + bc[j]);
}
}
sort(abc.rbegin(), abc.rend());
rep(i, k) {
cout << abc[i] << endl;
}
return 0;
} | 0 | 18,627,009 |
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main() {
string s, t;
cin >> t;
ll k;
cin >> k;
s=t;
if(s==string(s.size(),s[0])) {
cout << s.size()*k/2 << endl;
return 0;
}
ll ans=0;
for(int i=1; s[i]!='\0'; i++) {
if(s[i]==s[i-1]) {
ans++;
s[i]='*';
}
}
ans*=k;
int n1=1, n2=1;
for(int i=1; i<t.size(); i++) {
if(t[0]==t[i]) n1++;
else break;
}
for(int i=t.size()-2; i>=0; i--) {
if(t.back()==t[i]) n2++;
else break;
}
if(n1%2==1&&n2%2==1&&t[0]==t.back()) ans += k-1;
cout << ans << endl;
} | #include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i = 0; i < N; i++)
#define all(x) x.begin(), x.end()
#define sort(x) sort(all(x))
#define cou(x) cout << x << endl
#define y() cout << "Yes" << endl
#define n() cout << "No" << endl
#define Y() cout << "YES" << endl
#define N() cout << "NO" << endl
#define x2(x) x * x
using lint = long long;
using vi = vector<int>;
using vli = vector<lint>;
using vc = vector<char>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using msi = map<string, int>;
int gcd(int a, int b) {
int t;
while (b != 0) {
t = a % b;
a = b;
b = t;
}
return a;
}
int lcm(int a, int b) {
return a * b / gcd(a, b);
}
double distance(pii a, pii b) {
double dist;
dist = sqrt(x2(a.first - b.first) + x2(a.second - b.second));
return dist;
}
int main() {
int N;
cin >> N;
cou((N - 1) / 2);
} | 0 | 43,420,795 |
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 10000
using namespace std;
typedef long long ll;
int mod = 1000000007;
ll dp[100005];;
ll gcd(long long a,long long b){
if(b == 0)
return a;
else return gcd(b,a%b);
}
bool compare(pair<int,int>p1, pair<int,int>p2){
return p1.second > p2.second;
}
int main(){
int a[3];
for(int i=0;i<3;i++){
cin>>a[i];
}
sort(a,a+3);
long long sum =0;
for(int i=0;i<2;i++){
sum += a[i+1]-a[i];
}
cout<<sum<<endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) ll((a).size())
#define out(a) cout<<(a)<<endl;
const ll inf=1e9;
const int MAX = 510000;
const ll MOD = 998244353;
inline ll mod(ll a, ll m) {
return (a % m + m) % m;
}
int main(){
ll n;cin>>n;
vll a(n),b(n);
ll aa=0,bb=0;
rep(i,0,n)cin>>a[i];
rep(i,0,n)cin>>b[i];
rep(i,0,n){
if(a[i]<b[i]){
aa+=(b[i]-a[i])/2;
}
else{
bb+=a[i]-b[i];
}
}
if(aa>=bb){
cout<<"Yes"<<endl;
}
else{
cout<<"No"<<endl;
}
} | 0 | 93,218,699 |
#include <bits/stdc++.h>
#define rep_n(_1, _2, _3, NAME, ...) NAME
#define rep_2(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep_3(i, initial, n) for (int i = (int)(initial); i < (int)(n); ++i)
#define repeat(...) rep_n(__VA_ARGS__, rep_3, rep_2, rep_1)(__VA_ARGS__)
#define rep_r_n(_1, _2, _3, NAME, ...) NAME
#define rep_r_2(i, n) for (int i = (int)(n); i > 0; i--)
#define rep_r_3(i, initial, n) for (int i = (int)(initial); i > (int)(n); i--)
#define repeat_r(...) rep_r_n(__VA_ARGS__, rep_r_3, rep_r_2)(__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const double EPS = numeric_limits<double>::epsilon();
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main() {
int K;
cin >> K;
vector<int> list{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
cout << list[K-1] << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)
int main() {
int N, C, K; cin >> N >> C >> K;
vector<int> T(N);
rep(i,N) cin >> T.at(i);
sort(T.begin(), T.end());
int i = 0, p = 0, ws = 0;
ll res = 0;
while(i < N) {
if (p == 0) ws = T[i];
p++;
if (i == N-1 || p == C || T[i+1] - ws > K) {
res++;
p = 0;
}
i++;
}
cout << res << endl;
} | 0 | 23,400,262 |
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };
int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };
const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);
ll cnt[1000006];
int main(void){
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
int n;
cin >> n;
vector<ll> a(n);
rep(i,n) cin >> a[i];
ll allgcd = a[0];
rep(i,n)allgcd = __gcd(allgcd,a[i]);
if(allgcd > 1){
cout << "not coprime" << endl;
}else{
rep(i,n){
ll now = a[i];
for(ll j=2;j*j<=now;j++){
if(now%j==0){
while(now%j==0)now/=j;
cnt[j]++;
}
}
if(now>1)cnt[now]++;
}
for(int i=2;i<=1e6;i++){
if(cnt[i]>1){
cout << "setwise coprime" << endl;
return 0;
}
}
cout << "pairwise coprime" << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#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()
#define fi first
#define se second
#define debug(...) cerr<<__LINE__<<" ["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec)
{ for (auto v : vec) os << v << ' '; os << '\n'; return os; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa)
{ os << '(' << pa.first << ',' << pa.second << ')'; return os; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T)
{ cerr << " " << H; debug_out(T...); }
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 int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;
void solve() {
ll n, k;
cin >> n >> k;
vector<ll> A(n);
rep(i, n) cin >> A[i];
vector<ll> S(n + 1, 0);
REP(i, 1, n) S[i] = S[i - 1] + A[i - 1];
map<ll, int> mp;
REP(i, 0, min(n, k - 1)) {
mp[(S[i] - i) % k]++;
}
ll ans = 0;
REP(i, 0, n) {
mp[(S[i] - i) % k]--;
ans += mp[(S[i] - i) % k];
if (i + k > n) continue;
mp[(S[i + k] - i - k) % k]++;
}
cout << ans << endl;
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
solve();
return 0;
} | 0 | 47,583,016 |
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <list>
#include <string>
typedef char SINT8;
typedef short SINT16;
typedef int SINT32;
typedef long long SINT64;
typedef double DOUBLE;
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define rep(i,a,b) for(SINT64 (i)=SINT64(a);(i)<SINT64(b);(i)++)
#define rrep(i,a,b) for(SINT64 (i)=SINT64(a);(i)>=SINT64(b);(i)--)
#define put(a) cout << (a) << endl
#define puts(a) cout << (a) << " "
#define putr(a) rep(testIncrement,0,a.size()) {puts(a[testIncrement]);} cout << endl
#define putrr(a) rep(Incr1,0,a.size()) {rep(Incr2,0,a[Incr1].size()) {puts(a[Incr1][Incr2]);} cout<<endl;} cout<<endl;
#define INF 1000000001
#define MOD 1000000007
#define INF64 1000000000000000001
#define PI (acos(-1))
#define F first
#define S second
#define Pii pair<SINT32,SINT32>
#define Pll pair<SINT64,SINT64>
#define Piii pair<SINT32,pair<SINT32,SINT32>>
#define Plll pair<SINT64,pair<SINT64,SINT64>>
#define Vll(a,b,c) vector<vector<SINT64>> (a)((b),vector<SINT64>((c))
#define Vlll(a,b,c,d) vector<vector<vector<SINT64>>> (a)((b),vector<vector<SINT64>>((c),vector<SINT64>((d)))
using namespace std;
int main() {
SINT64 N; cin >> N;
SINT64 K; cin >> K;
deque<SINT64> dq;
SINT64 ans = 0;
rep(i,0,N) {
SINT64 a;
cin >> a;
dq.emplace_back(a);
}
rep(i,0,K+1) {
vector<SINT64> data;
deque<SINT64> now = dq;
rep(c,0,i) {
if (now.size() != 0) {
SINT64 a = now[0];
now.pop_front();
data.emplace_back(a);
} else {
break;
}
}
rep(j,0,K+1) {
if (j+i > K) break;
if (j != 0) {
if (now.size() != 0) {
SINT64 a = now[now.size()-1];
now.pop_back();
data.emplace_back(a);
} else {
break;
}
}
vector<SINT64> data2 = data;
sort(data2.begin(),data2.end());
SINT64 buf = 0;
rep(bbb,0,data2.size()) {
if ((bbb < (K-i-j)) && (data2[bbb] < 0)) {
} else {
buf += data2[bbb];
}
}
ans = MAX(ans,buf);
}
}
put(ans);
return 0;
} | #include <iostream>
#include <vector>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<map>
#include<math.h>
#include<queue>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int MOD = 1000000007;
const int mod = 1000000007;
const int INF = 1000000000;
const long long LINF = 1e18;
const int MAX = 510000;
int main() {
int k;
cin >> k;
vector<long long int> a(k + 10);
a.at(0) = 2;
a.at(1) = 1;
for (int i = 2; i <= k; i++) {
a.at(i) = a.at(i - 1) + a.at(i - 2);
}
cout << a.at(k ) << endl;
return 0;
} | 0 | 66,942,802 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
int x, y;
cin >> x >> y;
if (x % y == 0) {
cout << -1 << endl;
}
else {
cout << x << endl;
}
return 0;
} | #include<iostream>
#include<math.h>
using namespace std;
int main(){
int n;
bool p[1000000];
while(cin>>n){
int n_sq = (int)sqrt(n);
for(int i=0; i<n; i++){
p[i] = true;
}
p[0] = false;
for(int i=1; i<n_sq; i++){
if(p[i]){
for(int j=i*2+1; j<n; j=j+(i+1)){
p[j] = false;
}
}
}
int cnt=0;
for(int i=0; i<n; i++){
if(p[i]){
cnt++;
}
}
cout<<cnt <<endl;
}
return 0;
} | 0 | 66,500,040 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll gcd(ll x, ll y) {
if(x < y) swap(x, y);
ll r;
while(y > 0) {
r = x % y;
x = y;
y = r;
}
return x;
}
ll lcm(ll x, ll y) {
return ll(x / gcd(x, y)) * y;
}
int main() {
ll A, B;
cin >> A >> B;
cout << (ll)lcm(A, B) << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;
int main()
{
ll i,j;
ll n,m,v,p;
cin >> n >> m >> v >> p;
vector<ll> a(n);
for(i = 0;i < n;++i){
cin >> a.at(i);
}
sort(all(a), greater<ll>());
ll sup = n;
ll inf = 0;
ll meyasu = a.at(p-1);
while(sup - inf > 1){
ll mid = (sup + inf)/2;
if(meyasu - a.at(mid) > m){
sup = mid;
continue;
}
ll tmp = m*(p-1) + m*(n - mid);
for(i = p-1;i < mid;++i){
tmp += a.at(mid) + m - a.at(i);
}
if(tmp < m*v) sup = mid;
else inf = mid;
}
cout << sup << endl;
return 0;
} | 0 | 19,487,618 |
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0; i<(n); ++i)
#define REPR(i,n,m) for (int i=(n); i>=(m); --i)
using namespace std;
using LL = long long;
using LD = long double;
using PLL = pair<long long, long long>;
using PLD = pair<long double, long double>;
using VLL = vector<long long>;
using VLD = vector<long double>;
using VPLL = vector<PLL>;
using VPLD = vector<PLD>;
const int INF = numeric_limits<int>::max();
const unsigned long long int ULLINF = numeric_limits<unsigned long long int>::max();
const long long mod = 1000000007;
int main() {
LL s;
cin >> s;
VLL v(2001,0);
v[0] = 1;
v[1] = 0;
v[2] = 0;
v[3] = 1;
for (LL i=4; i<=2000; i++) {
v[i] = (v[i-1] + v[i-3])%mod;
}
cout << v[s] << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
int a[n];
map<int, int> mp;
for(int i=0;i<n;i++){
cin >> a[i];
mp[a[i]]++;
}
sort(a,a+n);
int dia=a[n-1]+1,tmp=a[n-1];
while(dia>0){
if(dia>2){
if(mp[tmp]<2){
cout << "Impossible\n";
return 0;
}else{
dia-=2;
}
}else if(dia==2){
if(mp[tmp]==2){
dia-=2;
}else{
cout << "Impossible\n";
return 0;
}
}else{
if(mp[tmp]==1){
dia--;
}else{
cout << "Impossible\n";
return 0;
}
}
tmp--;
}
cout << "Possible\n";
return 0;
} | 0 | 65,967,287 |
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
double x1, x2, x3, y1, y2, y3, px, py;
while (cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> px >> py) {
double j1 = (x1 - x2)*(py - y2) - (px - x2)*(y1 - y2),
j2 = (x3 - x1)*(py - y1) - (px - x1)*(y3 - y1),
j3 = (x2 - x3)*(py - y3) - (px - x3)*(y2 - y3);
if ((j1 < 0 && j2 < 0 && j3 < 0) || (j1 > 0 && j2 > 0 && j3 > 0))
cout << "YES" << endl;
else
cout << "NO" << endl;
}
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
int main(){
long long X,y,a,b,c;
cin>>X>>y>>a>>b>>c;
vector<int>R,B,T;
long long x;
for(int i=0;i<a;i++){
cin>>x;
R.push_back(x); }
for(int i=0;i<b;i++){
cin>>x;
B.push_back(x); }
for(int i=0;i<c;i++){
cin>>x;
T.push_back(x); }
sort(R.begin(),R.end(),greater<int>());
sort(B.begin(),B.end(),greater<int>());
for(int i=0;i<X;i++)
T.push_back(R[i]);
for(int i=0;i<y;i++)
T.push_back(B[i]);
sort(T.begin(),T.end(),greater<int>());
long long sum=0;
for(int i=0;i<X+y;i++){
sum += T[i];
}
cout<<sum<<endl;
return 0;
} | 0 | 87,972,799 |
#include <iostream>
#include <cstdio>
#include <set>
using namespace std;
int main()
{
for(;;){
int n;
cin >> n;
if(n == 0) break;
multiset<int> slist,elist;
for(int i=0; i<n; i++){
int h1,h2,m1,m2,s1,s2;
scanf("%d:%d:%d %d:%d:%d",&h1,&m1,&s1,&h2,&m2,&s2);
int s = h1 * 3600 + m1 * 60 + s1;
slist.insert(s);
int e = h2 * 3600 + m2 * 60 + s2;
elist.insert(e);
}
int ret = 0, count = 0;
multiset<int>::iterator its = slist.begin(), ite = elist.begin();
while(its != slist.end()){
if((*its) < (*ite)){
count++;
its++;
if(count > ret) ret = count;
}else{
count--;
ite++;
}
}
cout << ret << endl;
}
return 0;
} | #include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(x) ll((x).size())
#define all(v) (v).begin(),(v).end()
#define trace(x) cerr << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define For(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
#define roF(i,a,b) for(ll i = ll(a); i >= ll(b); i--)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
const ll N=1<<19;
int n;
ll a[N];
ll dp[N];
ll may, may2;
int V[N];
int tam;
void getsubmasks(int mask, int i = 0, int sub=0){
if(i==tam){
if(a[sub]>may){
may2=may;
may=a[sub];
}else if(a[sub]>may2) may2=a[sub];
return;
}
getsubmasks(mask, i+1, sub);
getsubmasks(mask, i+1, sub | (1<<V[i]));
}
int main(){
scanf("%d",&n);
int tot= 1<<n;
For(i,0,tot) scanf("%lld",&a[i]);
For(msk,1,tot){
tam=0;
For(j,0,n)
if((msk>>j)&1) V[tam++]=j;
may = -1;
may2=-1;
getsubmasks(msk);
dp[msk] = may+may2;
}
For(i,1,tot){
dp[i]=max(dp[i],dp[i-1]);
printf("%lld\n",dp[i]);
}
return 0;
} | 0 | 11,113,610 |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(long long i=0; i<(int)n; i++)
#define rep2(i,a,n) for(long long i=(a); i<(int)(n); i++)
#define all(vec) vec.begin(),vec.end()
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using psi = pair<string, int>;
const int dx[4] = {1, 0,-1, 0};
const int dy[4] = {0, 1, 0,-1};
const int mod = 1e9+7;
int gcd(int a, int b){if(a%b == 0){return(b);}else{return(gcd(b, a%b));}}
int lcm(int a, int b){return a * b / gcd(a, b);}
int N, M, K, H, W, L, R, T, X;
string S;
signed main(){
cin >> N >> X;
vi a(N);
rep(i,N) {cin >> a[i]; a[i] = abs(a[i]-X);}
int ans = a[0];
rep2(i,1,N) ans = gcd(ans,a[i]);
cout << ans << endl;
return 0;
} | #include <iostream>
void show_ret(int home[][10], bool use_partition) {
for(int i= 0; i < 3; i++) {
for(int j = 0; j < 10; j++) {
std::cout << " " << home[i][j];
}
std::cout << std::endl;
}
if(use_partition) std::cout << "####################" << std::endl;
}
int main(int argc, char *argv[]) {
int home1[3][10] = {{0}};
int home2[3][10] = {{0}};
int home3[3][10] = {{0}};
int home4[3][10] = {{0}};
int n, b, f, r, v = 0;
std::cin >> n;
for(int i = 0; i < n; i++) {
std::cin >> b >> f >> r >> v;
switch(b) {
case 1:
home1[f-1][r-1] += v;
break;
case 2:
home2[f-1][r-1] += v;
break;
case 3:
home3[f-1][r-1] += v;
break;
case 4:
home4[f-1][r-1] += v;
break;
}
}
show_ret(home1, true);
show_ret(home2, true);
show_ret(home3, true);
show_ret(home4, false);
return 0;
} | 0 | 42,888,753 |
#include <cmath>
#include <iostream>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
struct Point {
double x;
double y;
};
void koch(Point p1, Point p2, int n, int cnt) {
if (cnt >= n) {
std::cout << p1.x << ' ' << p1.y << '\n';
return;
}
cnt++;
Point s{p1.x + (p2.x - p1.x) / 3.0, p1.y + (p2.y - p1.y) / 3.0};
Point t{p2.x - (p2.x - p1.x) / 3.0, p2.y - (p2.y - p1.y) / 3.0};
Point v{t.x - s.x, t.y - s.y};
Point u{s.x + (v.x - sqrt(3) * v.y) / 2.0, s.y + (sqrt(3) * v.x + v.y) / 2.0};
koch(p1, s, n, cnt);
koch(s, u, n, cnt);
koch(u, t, n, cnt);
koch(t, p2, n, cnt);
}
void koch2(Point p1, Point p2, int n) {
if (n < 1) {
return;
}
Point s{p1.x + (p2.x - p1.x) / 3.0, p1.y + (p2.y - p1.y) / 3.0};
Point t{p2.x - (p2.x - p1.x) / 3.0, p2.y - (p2.y - p1.y) / 3.0};
Point v{t.x - s.x, t.y - s.y};
Point u{s.x + (v.x - sqrt(3) * v.y) / 2.0, s.y + (sqrt(3) * v.x + v.y) / 2.0};
koch2(p1, s, n - 1);
std::cout << s.x << ' ' << s.y << '\n';
koch2(s, u, n - 1);
std::cout << u.x << ' ' << u.y << '\n';
koch2(u, t, n - 1);
std::cout << t.x << ' ' << t.y << '\n';
koch2(t, p2, n - 1);
}
int main() {
int n;
std::cin >> n;
Point p1{0.0, 0.0}, p2{100.0, 0.0};
std::cout << p1.x << ' ' << p1.y << '\n';
koch2(p1, p2, n);
std::cout << p2.x << ' ' << p2.y << '\n';
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;
typedef pair<int,int> P;
vector<int> num = {0,2,5,5,4,5,6,3,7,6};
int main(){
int N, M; vector<int> A(9);
cin >> N >> M;
rep(i,M) cin >> A[i];
sort(A.begin(), A.begin()+M, greater<int>());
vector<int> dp(10010, -1);
dp[0] = 0;
rep(i,N) rep(j,M){
if(i+num[A[j]] <= N){
dp[i+num[A[j]]] = max(dp[i+num[A[j]]], dp[i]+1);
}
}
string ans;
while(N > 0){
rep(i,M){
if(N-num[A[i]] >= 0 && dp[N-num[A[i]]] == dp[N]-1){
ans.push_back(A[i] + '0');
N -= num[A[i]];
break;
}
}
}
cout << ans << endl;
} | 0 | 15,566,818 |
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
long long N, K;
cin >> N >> K;
vector<long long> H(N);
for (long long i = 0; i < N; i++)
cin >> H[i];
sort(H.begin(), H.end(), greater<>());
long long ans = 0;
for (long long i = 0; i < N; i++, K--) {
if (K <= 0) {
ans += H[i];
}
}
cout << ans << endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
int main(){
string s,t;
cin>>s>>t;
int m,n,i,j,k;
m=s.length();
n=t.length();
if(m<n){
cout<<"UNRESTORABLE"<<endl;
return 0;
}
for(i=0;i<=m-n;i++){
for(j=0;j<n;j++){
if(s.at(m-n-i+j)!='?'&&s.at(m-n-i+j)!=t.at(j)) break;
}
if(j==n){
for(k=0;k<m-n-i;k++){
if(s.at(k)=='?') cout<<'a';
else cout<<s.at(k);
}
cout<<t;
for(k=0;k<i;k++){
if(s.at(m-i+k)=='?') cout<<'a';
else cout<<s.at(m-i+k);
}
cout<<endl;
return 0;
}
}
cout<<"UNRESTORABLE"<<endl;
} | 0 | 49,618,899 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
vector<int> b = {0,2,5,5,4,5,6,3,7,6};
int n,m; cin>>n>>m;
vector<int> a(m);rep(i,m)cin>>a[i];
sort(a.rbegin(),a.rend());
vector<ll> dp(n+1,-INF);
dp[0]=0;
for(int i=1; i<=n; i++){
ll M = -INF;
for(int j:a){
if(b[j]<=i)M=max(M,dp[i-b[j]]+1);
}
dp[i]=M;
}
for(int j:a){
while(n>=b[j]&&dp[n]==dp[n-b[j]]+1){cout<<j;n-=b[j];}
}
return 0;
} | #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(intl i=0;i<(intl)(n);i++)
#define Rep1(i,n) for(intl i=1;i<(intl)(n)+1;i++)
#define vec vector
#define fi first
#define se second
#define pub push_back
#define pob pop_back
#define SortA(v) sort(v.begin(), v.end())
#define SortD(v) sort(v.rbegin(), v.rend())
#define All(a) (a).begin(),(a).end()
using intl = int64_t;
using vi = vec<intl>;
using vvi = vec<vi>;
using pi = pair<intl,intl>;
using vpi = vec<pi>;
vec<intl> dx = {0, 1, 0, -1, 1, 1, -1, -1};
vec<intl> dy = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr intl INF = 9223372036854775807;
int main(){
intl A,B,M;
cin >>A>>B>>M;
vi a(A),b(B);
vi x(M),y(M),c(M);
intl amin = INF, bmin = INF;
Rep(i,A){
cin >> a[i];
amin = min(amin ,a[i]);
}
Rep(i,B){
cin >>b[i];
bmin = min(bmin , b[i]);
}
Rep(i,M){
cin >> x[i]>>y[i]>>c[i];
}
intl mincost = INF;
mincost = min(mincost, amin +bmin);
Rep(i,M){
mincost = min(mincost, a[x[i]-1]+b[y[i]-1]-c[i]);
}
cout <<mincost;
} | 0 | 49,418,997 |
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <sstream>
using namespace std;
struct Node{
int key;
Node *prev, *next;
};
Node *nil;
void init(){
nil = new Node;
nil->next = nil;
nil->prev = nil;
}
void insert(int key){
Node *x = new Node;
x->key = key;
x->next = nil->next;
nil->next->prev = x;
nil->next = x;
x->prev = nil;
}
Node* listSearch(int key){
Node *cur = nil->next;
while(cur != nil && cur->key != key){
cur = cur->next;
}
return cur;
}
void deleteNode(Node *t){
if(t == nil) return;
t->prev->next = t->next;
t->next->prev = t->prev;
delete t;
}
void deleteFirst(){
deleteNode(nil->next);
}
void deleteLast(){
deleteNode(nil->prev);
}
void deletekey(int key){
deleteNode(listSearch(key));
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
init();
for(int i = 0; i < n; ++i){
string s;
int a;
cin >> s;
if(s == "insert" || s == "delete"){
cin >> a;
if(s == "insert"){
insert(a);
}
if(s == "delete"){
deletekey(a);
}
}
else {
if(s == "deleteFirst"){
deleteFirst();
}
if(s == "deleteLast"){
deleteLast();
}
}
}
Node *cur = nil->next;
int i0 = 0;
while(1){
if(cur == nil) break;
if(i0 > 0) cout << " ";
cout << cur->key;
cur = cur->next;
++i0;
}
cout << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<string> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
vector<bool> can(n, true);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
for (int k = 0; k < n; k++) {
int si = (i + k) % n;
int sj = (j - k + n) % n;
if (a[i][j] != a[si][sj]) {
can[(i - sj + n) % n] = 0;
}
}
}
}
cout << n * accumulate(can.begin(), can.end(), 0) << '\n';
return 0;
} | 0 | 50,054,210 |
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main() {
int X, N;
cin >> X >> N;
vector<int> ng(N);
rep (i, N) {
cin >> ng.at(i);
}
vector<int> ok(100 - N + 2);
int tmpIndex = 1;
ok.at(0) = 0;
rep (i, 100) {
bool ngMatchFlag = false;
rep (j, N) {
if (ng.at(j) == i + 1) {
ngMatchFlag = true;
break;
}
}
if(!ngMatchFlag) {
ok.at(tmpIndex) = i + 1;
tmpIndex++;
}
}
ok.at(tmpIndex) = 101;
int preDiff = 100;
int nowDiff = 100;
int preI = 0;
rep (nowI, 100 - N + 2) {
nowDiff = abs(ok.at(nowI) - X);
if ( (nowDiff < preDiff) || (nowDiff == preDiff && ok.at(nowI) < ok.at(preI)) ) {
preDiff = nowDiff;
preI = nowI;
}
}
cout << ok.at(preI) << 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() {
string s;
int flg,cnt1, cnt2, ans;
cin >> s;
cnt1 = 0;
flg = 0;
rep(i, s.size()) {
if (flg != s[i]-'0')
++cnt1;
if (++flg == 2)
flg = 0;
}
cnt2 = 0;
flg = 1;
rep(i, s.size()) {
if (flg != s[i]-'0')
++cnt2;
if (++flg == 2)
flg = 0;
}
ans = min(cnt1, cnt2);
cout << ans << endl;
return 0;
} | 0 | 48,634,181 |
#include<bits/stdc++.h>
using namespace std;
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout<<fixed; cout<<setprecision(12);
#define randomINT mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define newl cout<<"\n"
#define DISP(as) for(auto it : as) cout<<it<<" ";newl;
#define all(x) (x).begin(),(x).end()
#define mset(x,val) memset(x,val,sizeof(x))
#define newl cout<<"\n"
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define dline cerr<<"
#define deb1(x) cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y) cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z) cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';
typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll , ll> pll;
typedef pair<ld, ld> pld;
typedef unordered_map<ll, ll> um;
typedef vector<pll> vpll;
const ll MAX5 = 1e+5 + 7;
const ll MAX7 = 1e+7 + 7;
const ll MAXN = MAX7;
const ll INF = 0x7f7f7f7f7f7f7f7f;
const int INFi = 0x7f7f7f7f;
const ll MOD = 1e+9 + 7;
ll T = 1;
ll n, x, m, y, k, z, N;
string s, t, d, c;
void MAIN() {
cin>>n;
cout<<(ll)(n*(n+1)/2);
}
int main() {
fastio; randomINT;
while (T--) {
MAIN();
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int64_t L, R;
cin >> L >> R;
if(L == 0) {
cout << 0 << endl;
return 0;
}
else if(R - L == 1) {
cout << R * L % 2019 << endl;
return 0;
}
else if(R / 673 != L / 673) {
cout << 0 << endl;
return 0;
}
else {
int64_t ans = L * (L + 1) % 2019;
for(int64_t i = L; i < R; i++) {
for(int64_t j = i + 1; j <= R; j++) {
int64_t keep = i * j % 2019;
if(keep < ans) {
ans = keep;
}
}
}
cout << ans << endl;
}
} | 0 | 63,686,734 |
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
int main() {
char a[25], i;
scanf("%s", &a);
for(i=strlen(a)-1;i>=0;i--){
printf("%c", a[i]);
}
printf("\n");
return 0;
} | #include <bits/stdc++.h>
using namespace std ;
typedef long long ll;
int main(){
int N;cin>>N;
int a[N+1],b[N];
for(int i=0;i<=N;i++)cin>>a[i];
for(int i=0;i<N;i++)cin>>b[i];
ll monster=0;
for(int i=0;i<N;i++){
int ans1=min(a[i],b[i]);
int ans2=min(a[i+1],b[i]-ans1);
monster+=ans1;
monster+=ans2;
a[i]-=ans1;
a[i+1]-=ans2;
}
cout <<monster;
} | 0 | 28,643,085 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string ABCD;
cin >> ABCD;
int a, b, c, d;
a = (int)ABCD.at(0) - 48;
b = (int)ABCD.at(1) - 48;
c = (int)ABCD.at(2) - 48;
d = (int)ABCD.at(3) - 48;
int n = 3;
vector<int> answerCal(3);
for (int bit = 0; bit < (1 << n); bit++) {
int total = 0;
vector<int> cal(3);
if (bit & 1) {
cal.at(0) = 1;
total += a + b;
} else {
total += a - b;
}
if (bit & 2) {
cal.at(1) = 1;
total += c;
} else {
total -= c;
}
if (bit & 4) {
cal.at(2) = 1;
total += d;
} else {
total -= d;
}
if (total == 7) {
answerCal = cal;
break;
}
}
string answer = "";
answer += to_string(a);
answerCal.at(0) == 1 ? answer += "+" : answer += "-";
answer += to_string(b);
answerCal.at(1) == 1 ? answer += "+" : answer += "-";
answer += to_string(c);
answerCal.at(2) == 1 ? answer += "+" : answer += "-";
answer += to_string(d);
answer += "=7";
cout << answer << endl;
return 0;
} | #pragma GCC diagnostic ignored "-Wunused-variable"
#include <bits/stdc++.h>
using namespace std;
#define BOOST
#ifdef BOOST
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/range/adaptor/reversed.hpp>
using namespace boost;
using ml = boost::multiprecision::cpp_int;
using md = boost::multiprecision::cpp_dec_float_100;
#define forir(i, ...) if(ll i=(ll)v.size())for(__VA_ARGS__)if(i--,1)
#define eachr(i, e, c) forir(i, auto &&e: adaptors::reverse(c))
#endif
using ll = long long;
using ld = long double;
using pll = pair<long long, long long>;
template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;
template <class T> using vvvt = vector<vector<vector<T>>>;
#define all(c) (c).begin(), (c).end()
#define coutd cout << fixed << setprecision(10)
#define output(x) do{cout<<x<<endl;exit(0);}while(0)
#define rep(i, b, e) for (ll i = b; i < e; i++)
#define repr(i, b, e) for (ll i = b; e < i; i--)
#define fori(i, ...) if (ll i = -1) for(__VA_ARGS__) if (i++, 1)
#define each(i, e, c) fori (i, auto&& e: c)
#define llong_max 9223372036854775807
#define ldbl_max 1.79769e+308
#define pi 3.1415926535897932
auto Ceil = []
(auto x) { return (ll)ceil(x); };
auto Count = []
(auto b, auto e, auto x) { return (ll)count(b, e, x); };
auto CtoL = []
(auto c) { return (ll)c - (ll)'0'; };
auto LtoC = []
(auto n) { return (char)('0' + n); };
auto Pow = []
(auto a, auto b) { return (ll)pow(a, b); };
auto Pow2 = []
(auto n) { return (1LL << n); };
auto Pow10 = []
(auto n) { return (ll)pow(10, n); };
auto Size = []
(auto& c) { return (ll)(c).size(); };
auto Sum = []
(auto b, auto e) { return accumulate(b, e, 0LL); };
template <class T> void MakeVVT
(ll ys, ll xs, vvt<T>& v, T fill = T())
{
v.resize(ys); rep(y, 0, ys) v[y].resize(xs, fill);
}
template <class T> void MakeVVVT
(ll zs, ll ys, ll xs, vvvt<T>& v, T fill = T())
{
v.resize(zs); rep(z, 0, zs) MakeVVT(ys, xs, v[z], fill);
}
template <class T> void InputVT
(ll xs, vt<T>& v, T fix = T())
{
v.resize(xs); rep(i, 0, xs) { cin >> v[i]; v[i] += fix; }
}
template <class T> void InputVVT
(ll ys, ll xs, vvt<T>& v, T fix = T())
{
MakeVVT(ys, xs, v, fix);
rep(y, 0, ys) rep(x, 0, xs) { cin >> v[y][x]; v[y][x] += fix; }
}
template <class T> void InputVVVT
(ll zs, ll ys, ll xs, vvvt<T>& v, T fix = T())
{
v.resize(zs); rep(z, 0, zs) InputVVT(ys, xs, v[z], fix);
}
namespace NyaGadget {}
namespace NyaGadget
{
struct NT_NyaaBit
{
static long long Count(long long x, bool flip = false)
{
long long sum = 0;
for (auto i = 0LL; i < Size(x); ++i) sum += Test(x, i, flip);
return sum;
}
static long long ToLL(std::string bit)
{
long long res = 0;
long long maxSize = (long long)bit.size();
for (auto i = 0LL; i < maxSize; ++i) if (bit[i] == '1') res += (1LL << (maxSize - i - 1));
return res;
}
static std::string ToString(long long x, bool flip = false)
{
std::string res;
if (!flip) for (auto i = Size(x) - 1; -1 < i; --i) res += (char)('0' + Test(x, i));
else for (auto i = 0LL; i < Size(x); ++i) res += (char)('0' + Test(x, i));
return res;
}
static std::string ToString(long long maxSize, long long x, bool flip = false)
{
std::string res;
for (auto i = 0LL; i < (maxSize - Size(x)); i++) res += '0';
if (!flip) for (auto i = Size(x) - 1; -1 < i; --i) res += (char)('0' + Test(x, i));
else for (auto i = 0LL; i < Size(x); ++i) res += (char)('0' + Test(x, i));
return res;
}
static long long RangeCount(long long x, long long b, long long e, bool flip = false)
{
long long sum = 0;
for (auto i = b; i < e; i++) sum += Test(x, i, flip);
return sum;
}
static long long Shift(long long x, long long n)
{
return (x << n);
}
static long long Size(long long x)
{
long long size = 0;
while ((long long)(1LL << size) <= x) size++;
return size;
}
static long long Test(long long x, long long i, bool flip = false)
{
if (flip) return ((x & Shift(1, i)) != 0) ? 0 : 1;
else return ((x & Shift(1, i)) != 0) ? 1 : 0;
}
static long long To10(long long x, long long i)
{
return Test(x, i) * (long long)pow(2, i);
}
static void CombinationTable(long long N, long long m, std::vector<std::string>& res)
{
if (N <= 0 || m < 0) return;
long long c = (1LL << m) - 1;
while (c < 1LL << N)
{
res.push_back(ToString(N, c));
long long x = c & -c, y = c + x;
c = ((c) & ~y) / x >> 1LL | y;
}
}
static void CombinationTable(long long N, long long m, std::vector<long long>& res)
{
if (N <= 0 || m < 0) return;
long long c = (1LL << m) - 1;
while (c < 1LL << N)
{
res.push_back(c);
long long x = c & -c, y = c + x;
c = ((c) & ~y) / x >> 1LL | y;
}
}
};
}
using namespace NyaGadget;
int main(void)
{
ll N, M; cin >> N >> M;
vvt<bool> s; MakeVVT(M, N, s);
rep(i, 0, M)
{
ll k; cin >> k;
rep(j, 0, k)
{
ll nyaa; cin >> nyaa; --nyaa;
s[i][nyaa] = true;
}
}
vt<ll> p(M); each(i, e, p) cin >> e;
ll ans = 0;
rep(i, 0, Pow2(N))
{
each(j, e, s)
{
ll count = 0;
rep(k, 0, N)
{
if (NT_NyaaBit::Test(i, k) == 1 && e[k]) ++count;
}
if (count % 2 != p[j]) break;
if (j == Size(s) - 1) ++ans;
}
}
cout << ans;
return 0;
} | 0 | 39,215,858 |
#include <iostream>
using namespace std;
int main(){
int b,f,r,v,i,j,n;
int a[12][10];
for (j=0;j<12;j++){
for (i=0;i<10;i++)a[j][i]=0;
}
cin>>n;
for (i=0;i<n;i++){
cin>>b>>f>>r>>v;
a[b*3+f-4][r-1]+=v;
}
for (j=0;j<12;j++){
if (j&&!(j%3))cout<<"####################"<<endl;
for (i=0;i<10;i++){
cout<<' '<<a[j][i];
}
cout<<endl;
}
} | #include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll=long long;
using P =pair<int,int>;
int main(){
int a,b,k;
int count=0;
cin>>a>>b>>k;
for(int i=min(a,b);i>0;i--){
if(a%i==0&&b%i==0){
count++;
if(count==k){
cout<<i<<endl;
return 0;
}
}
}
} | 0 | 85,231,855 |
#include<iostream>
using namespace std;
int main() {
int N, M, A;
cin >> N >> M;
int sum = 0;
for(int i = 0; i < M; i++) {
cin >> A;
sum += A;
}
if (sum > N) cout << -1 << endl;
else cout << N - sum << endl;
} | #include<bits/stdc++.h>
#define rep(i, n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int INF = 1e9;
int main(void){
int h, w;
cin>>h>>w;
vector<string> v(h);
rep(i, h) cin>>v[i];
queue<pair<int, int> > que;
queue<pair<int, int> > nextque;
rep(i, h)rep(j, w)if(v[i][j] == '#') que.push(make_pair(i, j));
int ans = 0;
bool ok = true;
vector<int>dx = {0, -1, 0, 1};
vector<int>dy = {-1, 0, 1, 0};
while(ok){
nextque = queue<pair<int, int> >();
while(!que.empty()){
auto p = que.front();que.pop();
rep(i, 4){
if(p.first+dx[i]>=0 && p.first+dx[i]<=h-1 && p.second+dy[i]>=0 && p.second+dy[i]<=w-1 && v[p.first+dx[i]][p.second+dy[i]] == '.'){
v[p.first+dx[i]][p.second+dy[i]] = '#';
nextque.push(make_pair(p.first+dx[i], p.second+dy[i]));
}
}
}
ok = !nextque.empty();
que = nextque;
if(ok) ans++;
}
cout<<ans<<endl;
return 0;
} | 0 | 49,160,323 |
#include<iostream>
using namespace std;
int main(){
int x[11];
int r, d;
cin >> r >> d >> x[0];
for (int i = 1; i < 11; i++)
{
x[i] = r * x[i - 1] - d;
}
for (int i = 1; i < 11; i++)
{
cout << x[i] << endl;
}
return 0;
} | #include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define mp make_pair
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
string s,t;
getline(cin,s);
stringstream ss(s);
while(ss>>t)
{
cout<<char(t[0]-32);
}
return 0;
} | 0 | 77,674,672 |
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>
using namespace std;
int main(int argc, char** argv) {
ios::sync_with_stdio(false);
cin.tie(0);
int m;
cin >> m;
vector<int> D(m);
vector<long long> C(m);
for (int i = 0; i < m; ++i) {
cin >> D[i] >> C[i];
}
long long res = 0;
long long sum = 0;
for (auto x : C) {
res += x;
}
--res;
for (int i = 0; i < m; ++i) {
sum += D[i] * C[i];
}
res += (sum - 9 + 8) / 9;
cout << res << '\n';
return 0;
} | #include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <cmath>
#include <iostream>
#include <stack>
#include <queue>
#define ll long long int
#define all(x) x.begin(), x.end()
#define MOD 998244353
using namespace std;
void solve()
{
int N, M;
cin >> N >> M;
int even_count = (M + 1) / 2;
int odd_count = M / 2;
int a = even_count;
int b = a + 1;
for (int i = 0; i < even_count; i++)
{
cout << a << " " << b << endl;
a--;
b++;
}
a =2 * even_count + odd_count;
b = a + 2;
for (int i = 0; i < odd_count; i++)
{
cout << a << " " << b << endl;
a--;
b++;
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int T = 1;
while (T--)
{
solve();
}
return 0;
} | 0 | 82,381,101 |
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <iomanip>
#include <functional>
#include <cmath>
#include <cassert>
#include <bitset>
#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif
#define int long long
#define EL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
signed main() {
int n;
std::cin >> n;
bool equal=true;
int sum=0;
int min=1e10;
rep(i,n) {
int a,b;
std::cin >> a >> b;
sum+=b;
if(a!=b) equal=false;
if(a>b) min=std::min(min,b);
}
if(equal) print(0);
else print(sum-min);
return 0;
} | #include <iostream>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>
using namespace std;
using ll = long long;
constexpr ll INF = 1010000000000000017LL;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
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/GCD(a,b)*b; }
class CSubarraySum {
public:
void solve(std::istream& in, std::ostream& out) {
ll n,k,s;in>>n>>k>>s;
rep(i,k) out<<s<<' ';
if(s==pow(10,9)) rep(i,n-k) out<<1<<' ';
else rep(i, n-k) out<<s+1<<' ';
}
};
int main() {
CSubarraySum solver;
std::istream& in(std::cin);
std::ostream& out(std::cout);
solver.solve(in, out);
return 0;
} | 0 | 93,045,559 |
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <iomanip>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
int main() {
string s;
cin >> s;
int len = (int)(s.size());
long long int ans = 0,x = 0;
rep(i,len){
if(s[i] == 'W'){
ans += x;
}
else if(s[i] == 'B'){
x++;
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e5+100;
int n,l,t,ans[N],wa,wb;
struct node
{
int x,w,id;
}a[N];
node b[N],sh[N];
deque <int> s;
signed main()
{
scanf("%lld%lld%lld",&n,&l,&t);
for (int i=1;i<=n;i++)
{
int x,w;
scanf("%lld%lld",&x,&w);
sh[i].x=x,sh[i].w=w;
if (w==1) a[++wa].x=x,a[wa].w=w,a[wa].id=i;
else b[++wb].x=x,b[wb].w=w,b[wb].id=i;
}
if (wa==0 || wb==0)
{
for (int i=1;i<=n;i++)
{
if (sh[i].w==2) printf("%lld\n",(sh[i].x-t+l)%l);
else printf("%lld\n",(sh[i].x+t)%l);
}
return 0;
}
for (int i=1;i<=wb;i++) s.push_back(b[i].x);
for (int i=1;i<=wa;i++)
{
while (s.front()<a[i].x)
{
int x=s.front();
s.pop_front();
s.push_back(x+l);
}
int now=2ll*t,cnt=0;
cnt=(now/l)*wb,now%=l;
cnt+=upper_bound(s.begin(),s.end(),a[i].x+now)-s.begin();
cnt%=n;
if (a[i].id+cnt>n) sh[a[i].id].id=a[i].id+cnt-n;
else sh[a[i].id].id=a[i].id+cnt;
}
s.clear();
for (int i=1;i<=wa;i++) s.push_back(a[i].x);
for (int i=wb;i>=1;i--)
{
while (s.back()>b[i].x)
{
int x=s.back();
s.pop_back();
s.push_front(x-l);
}
int now=2ll*t,cnt=0;
cnt=(now/l)*wa,now%=l;
cnt+=wa-(lower_bound(s.begin(),s.end(),b[i].x-now)-s.begin());
cnt%=n;
if (b[i].id-cnt<1) sh[b[i].id].id=n+b[i].id-cnt;
else sh[b[i].id].id=b[i].id-cnt;
}
t%=l;
for (int i=1;i<=n;i++)
{
if (sh[i].w==2) ans[sh[i].id]=(sh[i].x-t+l)%l;
else ans[sh[i].id]=(sh[i].x+t)%l;
}
for (int i=1;i<=n;i++) printf("%lld\n",ans[i]);
} | 0 | 59,597,894 |
#include<iostream>
#include<queue>
using namespace std;
int G[1005][1005], dist[1005][1005], H, W, K, sx[11], sy[11];
int solve(int ax, int ay, int bx, int by) {
for (int i = 0; i < 1005 * 1005; i++)dist[i / 1005][i % 1005] = 1000000000;
queue<pair<int, int>>Q; Q.push(make_pair(ax, ay)); dist[ax][ay] = 0;
while (!Q.empty()) {
int a1 = Q.front().first, a2 = Q.front().second; Q.pop();
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
for (int i = 0; i < 4; i++) {
if (G[a1 + dx[i]][a2 + dy[i]] == 0 && dist[a1 + dx[i]][a2 + dy[i]] > dist[a1][a2] + 1) {
dist[a1 + dx[i]][a2 + dy[i]] = dist[a1][a2] + 1;
Q.push(make_pair(a1 + dx[i], a2 + dy[i]));
}
}
}
return dist[bx][by];
}
int main() {
cin >> H >> W >> K;
for (int i = 0; i <= H + 1; i++) {
for (int j = 0; j <= W + 1; j++) {
if (i == 0 || i == H + 1 || j == 0 || j == W + 1)G[i][j] = 1;
}
}
for (int i = 1; i <= H; i++) {
for (int j = 1; j <= W; j++) {
char p; cin >> p;
if (p == 'S') { sx[0] = i; sy[0] = j; }
if (p >= '0' && p <= '9') { sx[p - '0'] = i; sy[p - '0'] = j; }
if (p == 'X')G[i][j] = 1;
}
}
int cnt = 0;
for (int i = 0; i < K; i++) {
cnt += solve(sx[i], sy[i], sx[i + 1], sy[i + 1]);
}
cout << cnt << endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
int n;
cin >> n;
vector<ll> v(n);
for(int i = 0; i < n; i++)
cin >> v[i];
sort(v.begin(), v.end());
ll p = 2;
for(int i = 2; i < n; i++){
v[i] *= p;
p *= 2;
}
ll s = 0;
for(int i = 0; i < n; i++)
s += v[i];
double ans = (double)s / p;
printf("%.8f\n",ans);
return 0;
} | 0 | 52,382,925 |
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
#define ll (long long)
#define REP(i,n) for(int i = 0;i<(int)n;i++)
#define FOR(i,a,b) for(int i = (a);i < (b);i++)
#define RFOR(i,a,b) for(int i = (a);i>(b);i--)
#define risi (0.05)
using namespace std;
int main(void)
{
int a,b,c,d;
int i,j,k,l;
int number;
int answercounter = 0;
int answerarray[1000] = {0};
int temp = 0;
while(cin >> number)
{
for(i = 0;i <= 9;i++)
if(i <= number)
for(j = 0;j<=9;j++)
if(i+j<= number)
for(k = 0;k<=9;k++)
if(i+j+k <= number)
for(l = 0;l<=9;l++)
if((i+j+k+l) == number)
temp++;
answerarray[answercounter] = temp;
temp = 0;
answercounter++;
}
REP(i,answercounter)
cout << answerarray[i] << endl;
return 0;
} | #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60
int main(void) {
cin.tie(0); ios::sync_with_stdio(false);
ll N; cin >> N;
vector<ll> a(N);
for(auto& in:a) cin >> in;
ll res = LINF;
vector<ll> cusum(N,0);
cusum[0] = a[0];
for(int i = 1; i < N;i++){
cusum[i] = cusum[i-1] + a[i];
}
for(int i = 0; i < N-1;i++){
res = min(res,abs(cusum[i] - (cusum[N-1] - cusum[i])));
}
cout << res << endl;
return 0;
} | 0 | 25,506,239 |
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
long long A, B;
cin >> A >> B;
long long D = 1, ans = 0;
while (D <= B) {
long long Anum = (A-1) / (D * 2) * D + max(0ll, (A-1) % (D * 2) - (D - 1));
long long Bnum = B / (D * 2) * D + max(0ll, B % (D * 2) - (D - 1));
ans += D * ((Bnum - Anum) % 2);
D *= 2;
}
cout << ans << endl;
} | #include <iostream>
int main() {
int n, T; std::cin >> n >> T;
unsigned long long X = 0;
int head = 0, tail = 0;
for (int i = 0; i < n; i++) {
int t; std::cin >> t;
if (t <= tail) {
tail = t + T;
} else {
X += tail - head;
head = t;
tail = t + T;
}
}
X += tail - head;
std::cout << X << std::endl;
return 0;
} | 0 | 85,052,637 |
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x) cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
int main(void)
{
cin.tie(0);
ios::sync_with_stdio(false);
string S; cin >> S;
if(S[2] == S[3] && S[4] == S[5]) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
} | #pragma GCC optimize("Ofast")
#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 cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
#define FS fixed<<setprecision(15)
typedef long long ll;
const double pi=3.141592653589793;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
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; }
template<class T> inline void out(T a){ cout << a << '\n'; }
void YN(bool ok){if(ok) cout << "Yes" << endl; else cout << "No" << endl;}
const ll INF=1e18;
const int mx=200005;
int main(){
cin.tie(0);ios::sync_with_stdio(false);
int n, q;
scanf("%d %d", &n, &q);
dsu d(n);
for (int i = 0; i < q; i++) {
int t, u, v;
scanf("%d %d %d", &t, &u, &v);
if (t == 0) {
d.merge(u, v);
} else {
if (d.same(u, v)) {
printf("1\n");
} else {
printf("0\n");
}
}
}
return 0;
} | 0 | 39,298,161 |
#include <iostream>
#include <string>
using namespace std;
int main()
{
int w;
int h;
int x;
int y;
int r;
string answer;
cin >> w >> h >> x >> y >> r;
if ( ( x + r ) > w) {
answer = "No";
} else if ( ( y + r ) > h ) {
answer = "No";
} else if ( x < r ) {
answer = "No";
} else if ( y < r ) {
answer = "No";
} else {
answer = "Yes";
}
cout << answer << endl;
} | #include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<map>
#include<unordered_map>
#include<stack>
#include<string>
#include<iomanip>
#include<algorithm>
#include<functional>
#include<cstring>
#include<utility>
#include<math.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> Q;
const ll INF = 1LL << 60;
const ll mod = 1000000007;
const ll dx[4] = {1, 0, -1, 0};
const ll dy[4] = {0, -1, 0, 1};
const ll NCK_MAX = 510000;
ll ketawa(ll n){
ll a=0;
while(n!=0){
a+=n%10;
n/=10;
}
return a;
}
ll RepeatSquaring(ll N, ll P, ll M){
if(P==0) return 1;
if(P%2==0){
ll t = RepeatSquaring(N, P/2, M);
return ((t% M)*(t % M))%M;
}
return (N * RepeatSquaring(N, P-1, M))%M;
}
ll RS(ll N, ll P){
if(P==0) return 1;
if(P%2==0){
ll t = RS(N, P/2);
return t*t;
}
return (N * RS(N, P-1));
}
map< ll, int > prime_factor(ll n) {
map< ll, int > ret;
for(ll i = 2; i * i <= n; i++) {
while(n % i == 0) {
ret[i]++;
n /= i;
}
}
if(n != 1) ret[n] = 1;
return ret;
}
bool IsPrime(ll a){
if(a==1)return false;
for(int i=2;i*i<=a;i++){
if(a%i==0&&a!=i){
return false;
}
}
return true;
}
ll gcd(ll a, ll b) {
if (b == 0) return a;
return gcd(b, a % b);
}
ll lcm(ll a, ll b){
return a / gcd(a, b)*b;
}
ll extgcd(ll a, ll b, ll& x, ll& y) {
if (b == 0) {
x = 1, y = 0; return a;
}
ll q = a/b, g = extgcd(b, a - q*b, x, y);
ll z = x - q * y;
x = y;
y = z;
return g;
}
ll invmod (ll a, ll m) {
ll x, y;
extgcd(a, m, x, y);
x %= m;
if (x < 0) x += m;
return x;
}
ll *fac, *finv, *inv;
void nCk_init(ll mod) {
fac = new ll[NCK_MAX];
finv = new ll[NCK_MAX];
inv = new ll[NCK_MAX];
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (ll i = 2; i < NCK_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 nCk(ll n, ll k, ll mod) {
if (fac == NULL) nCk_init(mod);
if (n < k) return 0;
if (n < 0 || k < 0) return 0;
return fac[n] * (finv[k] * finv[n-k] % mod) % mod;
}
ll lmin(ll a, ll b) { return a > b ? b : a; };
ll lmax(ll a, ll b) { return a > b ? a : b; };
ll lsum(ll a, ll b) { return a + b; };
void warshall_floyd(int n) {
for (int k = 0; k < n; k++){
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
}
}
}
}
template <typename T>
class Zip {
vector<T> d;
bool flag;
public:
Zip() {
flag = false;
}
void add(T x) {
d.push_back(x);
flag = true;
}
ll getNum(T x) {
if (flag) {
sort(d.begin(), d.end());
d.erase(unique(d.begin(), d.end()), d.end());
flag = false;
}
return lower_bound(d.begin(), d.end(), x) - d.begin();
}
ll size() {
if (flag) {
sort(d.begin(), d.end());
d.erase(unique(d.begin(), d.end()), d.end());
flag = false;
}
return (ll)d.size();
}
};
class UnionFind {
vector<ll> par, rank;
public:
void init(ll n) {
par.resize(n, 1); rank.resize(n, 0);
}
ll getSize(ll x) {
return par[find(x)];
}
ll find(ll x) {
if (par[x] > 0) return x;
return -(par[x] = -find(-par[x]));
}
void merge(ll x, ll y) {
x = find(x);
y = find(y);
if (x == y) return;
if (rank[x] < rank[y]) {
par[y] += par[x];
par[x] = -y;
} else {
par[x] += par[y];
par[y] = -x;
if (rank[x] == rank[y]) rank[x]++;
}
}
bool isSame(ll x, ll y) {
return find(x) == find(y);
}
};
class SegmentTree {
public:
vector<pair<double, double>> node;
ll n;
pair<double, double> initial_value;
public:
void Init(ll n_,pair<double, double> initial_value_){
n=1;
while(n<n_)n*=2;
node.resize(2*n);
for(ll i=0;i<2*n;i++){
node[i]=initial_value_;
}
initial_value=initial_value_;
}
void Update(ll k,pair<double, double> a){
k+=n;
node[k]=a;
while(k>1){
k=k/2;
node[k]=pair<double, double>(node[k*2].first*node[k*2+1].first,node[k*2].second*node[k*2+1].first+node[k*2+1].second);
}
}
double Query(){
return node[1].first+node[1].second;
}
};
ll lis(ll* a, ll n, ll* dp) {
fill(dp, dp + n, INF);
for (ll i = 0; i < n; i++) *lower_bound(dp, dp + n, a[i]) = a[i];
return (ll)(lower_bound(dp, dp + n, INF) - dp);
}
ll n,m,kk;
ll ans;
string s;
vector<ll> t,a;
ll kakutei[100001];
map<P,ll> mp;
int main(){
cin>>n>>kk;
for(ll i=0;i<n;i++){
ll aa;
cin>>aa;
a.push_back(aa);
}
for(ll i=0;i<=n;i++){
for(ll j=0;j<=n;j++){
if(i+j>kk||i+j>n)continue;
vector<ll> totta;
ll hidari=0,migi=0;
for(ll k=0;k<i;k++){
totta.push_back(a[k]);
hidari+=a[k];
}
for(ll k=0;k<j;k++){
totta.push_back(a[n-1-k]);
migi+=a[n-1-k];
}
sort(totta.begin(),totta.end());
ll modosu=kk-(i+j);
ll kati=hidari+migi;
for(ll k=0;k<modosu&&k<totta.size();k++){
if(totta[k]<0){
kati-=totta[k];
}else{
break;
}
}
ans=lmax(ans,kati);
}
}
cout<<ans<<endl;
} | 0 | 60,574,608 |
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll MOD = 1e9+7;
#define vec vector<int>
#define vecll vector<ll>
#define vec2 vector<vector<int>>
#define vec2ll vector<vector<ll>>
#define vpair vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>
#define rep(i,n) for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n) for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n) vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n) vecll var(n); rep(i,n){cin >> var[i];}
#define all(var) (var).begin(), (var).end()
#define sortall(var) sort(all(var))
#define mpair(v1, v2) make_pair(v1, v2)
#define pb(var) push_back(var)
#define prt(var) cout << var << "\n"
#define scn(var) cin >> var;
#define pYes() prt("Yes")
#define pNo() prt("No")
#define prtd(n, var) cout << fixed << setprecision(n) << var << "\n"
#define prt2(v1, v2) cout << v1 << " " << v2 << "\n"
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << "\n"
#define prtall(var) rep(i,var.size()){cout << var[i] << " ";} cout << "\n"
ll gcd(ll a, ll b){ return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){ return a/gcd(a,b)*b;}
ll div2(ll x){
ll num=0;
while(x%2==0){
x /= 2;
num++;
}
return num;
}
int main(void) {
ll n, m;
cin >> n >> m;
arrll(a,n);
rep(i,n){
a[i] /= 2;
}
ll k=div2(a[0]);
rep(i,n){
if(k!=div2(a[i])){
prt(0); return 0;
}
a[i] >>= k;
}
m >>= k;
ll l=1;
rep(i,n){
l = lcm(a[i], l);
if(l > m){
prt(0); return 0;
}
}
prt(1+(m-l)/(2*l));
} | #include <bits/stdc++.h>
#define optimize ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0) ;
#define ll long long
#define ld long double
#define lint __int128
#define vi vector<int>
#define pb push_back
#define lp(i,a,b) for(int i = a ; i <= b ; i ++)
#define rlp(i,a,b) for(int i = b ; i >= a ; i --)
#define a_sort(v) sort(v.begin(), v.end())
#define d_sort(v) sort(v.rbegin(), v.rend())
#define pii pair<int,int>
#define pi 3.14159265358979323846264338327950
using namespace std ;
const int MOD = 1E9 + 7 ;
const int N = 1E5 ;
int main() {
#ifdef debug
freopen("input.txt", "r", stdin) ;
freopen("output.txt", "w", stdout) ;
#endif
optimize
string a , b ; cin >> a >> b ;
if(a.size() > b.size()) cout << "GREATER\n" ;
else if(a.size() < b.size()) cout << "LESS\n" ;
else {
if(a > b) cout << "GREATER\n" ;
else if(a < b) cout << "LESS\n" ;
else cout << "EQUAL\n" ;
}
} | 0 | 88,846,887 |
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln = '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define fo(i,j,n) for (int i=(j); i < (n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int main() {
int n; cin >> n;
vector<ll> A(n+1); rep(i, n+1) cin >> A[i];
ll min_max[100100][2];
min_max[n][0] = min_max[n][1] = A[n];
for(int i=n-1; i>=0; i--){
min_max[i][0] = min_max[i+1][0]/2 + min_max[i+1][0]%2 + A[i];
min_max[i][1] = min_max[i+1][1] + A[i];
}
if(min_max[0][0] > 1 || min_max[0][1] < 1) cout << -1 << ln;
else{
ll cnt[100100];cnt[0] = 1;
for(int i=1; i<=n; i++){
cnt[i] = min((cnt[i-1]-A[i-1])*2, min_max[i][1]);
}
ll sum = 0;
rep(i, n+1) sum += cnt[i];
cout << sum << ln;
}
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,a,b) for(int i=(a);i<(b);++i)
template<class T> inline void chmin(T& a, T b) {if (a > b) a = b;}
template<class T> inline void chmax(T& a, T b) {if (a < b) a = b;}
int main() {
int N,K;
cin >> N >> K;
int tmp=N*(N-1)/2;
if (K>(N-1)*(N-2)/2) {
cout << -1 << endl;
return 0;
}
cout << tmp-K << endl;
rep(i,N-1) {
rep2(j,i+1,N) {
if (tmp>=K) {
cout << i+1 << ' ' << j+1 << endl;
tmp--;
}
if (tmp==K) return 0;
}
}
} | 0 | 11,454,499 |
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
vector<int> menu(5);
int main() {
rep(i, 5) cin >> menu.at(i);
int r = 1e9;
int ans = 0;
rep(i, 5) {
if(menu.at(i) % 10 != 0) r = min(r, menu.at(i) % 10);
ans += ((menu.at(i) + 9)/10) * 10;
}
if(r != 1e9) ans += r - 10;
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct ki {
ll num, kyori;
};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll n;
cin >> n;
vector<vector<ki>> node(n);
for (ll i = 0; i < n - 1; i++) {
ki temp;
ll a, b, c;
cin >> a >> b >> c;
a--;
b--;
temp.num = b;
temp.kyori = c;
node[a].push_back(temp);
temp.num = a;
temp.kyori = c;
node[b].push_back(temp);
}
ll q, k;
cin >> q >> k;
k--;
queue<ll> que;
vector<ll> dist(n, 0);
que.push(k);
while (!que.empty()) {
ll temp = que.front();
que.pop();
for (ll i = 0; i < node[temp].size(); i++) {
if (dist[node[temp][i].num] == 0) {
que.push(node[temp][i].num);
dist[node[temp][i].num] = dist[temp] + node[temp][i].kyori;
}
}
}
for (ll i = 0; i < q; i++) {
ll x, y;
cin>>x>>y;
x--;
y--;
cout << dist[x] + dist[y] << endl;
}
return 0;
} | 0 | 80,177,325 |
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int nax = 1e6+1;
int main(){
ll n;
cin>>n;
ll mi = 2*n;
for(ll i=1;i*i<=n;i++){
if(n%i==0){
ll k = n/i;
ll sum = i+k;
mi = min(mi,sum);
}
}
cout<<mi-2;
return 0;
} | #include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <cstdlib>
#include <cmath>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
int main(){
int a,b,m;
cin >> a >> b >> m;
vector<int> A(a);
vector<int> B(b);
rep(i,a) cin >> A[i];
rep(i,b) cin >> B[i];
int mina=100100100,minb=100100100;
rep(i,a) mina=min(mina,A[i]);
rep(i,b) minb=min(minb,B[i]);
int ans=mina+minb;
for(int i=0;i<m;i++){
int x,y,c;
cin >> x >> y >> c;
ans=min(ans,A[x-1]+B[y-1]-c);
}
cout << ans << endl;
} | 0 | 10,317,543 |
#include <iostream>
#include <complex>
#include <cmath>
using namespace std;
typedef complex<double> P;
#define PI 3.1415926535898
#define EPS (1e-10)
#define X real()
#define Y imag()
bool equal(double a, double b){
return ( abs( a-b ) < EPS )? true : false ;
}
class Triangle{
private:
P a, b, c;
double edgeA,edgeB,edgeC;
double angleA,angleB,angleC;
double LawOfCosines(double a,double b, double c){
return acos( (b*b+c*c-a*a) / (2.0*b*c) );
}
public:
Triangle(P p1, P p2, P p3){
a = p1;
b = p2;
c = p3;
edgeB = abs(c-a);
edgeA = abs(b-c);
edgeC = abs(a-b);
angleA = LawOfCosines(edgeA,edgeB,edgeC);
angleB = LawOfCosines(edgeB,edgeC,edgeA);
angleC = LawOfCosines(edgeC,edgeA,edgeB);
}
double getAngleC(){
return angleC;
}
};
int main(){
double x1, x2, x3, y1, y2, y3, xp, yp, angle;
while( cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> xp >> yp ){
P a( x1 , y1 );
P b( x2 , y2 );
P c( x3 , y3 );
P p( xp , yp );
Triangle Tr1(a,b,p);
Triangle Tr2(b,c,p);
Triangle Tr3(c,a,p);
angle = Tr1.getAngleC() + Tr2.getAngleC() + Tr3.getAngleC();
( equal( 2.0*PI , angle) )? cout << "YES" : cout << "NO" ;
cout << endl;
}
} | #include <bits/stdc++.h>
#define ALL(a) (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename 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(){
ll N, K;
cin >> N >> K;
vll a(N), aa(N);
vll highest(N), highestt(N);
for(int i = 0; i < N; i++){
cin >> a.at(i);
if(i == 0) highest.at(0) = a.at(0);
else if(a.at(i) > highest.at(i-1)) highest.at(i) = a.at(i);
else highest.at(i) = highest.at(i-1);
}
aa = a; highestt = highest;
ll result = INF;
for(int tmp = 0; tmp < (1 << (N-1)); tmp++){
bitset<14> bit(tmp);
if(bit.count() != K-1) continue;
a = aa; highest = highestt;
ll sum = 0;
for(int i = 0; i < N-1; i++){
if(bit.test(i)){
if(a.at(i+1) <= highest.at(i)){
sum += (highest.at(i) + 1LL - a.at(i+1));
a.at(i+1) = highest.at(i) + 1LL;
}
}
highest.at(i+1) = max(a.at(i+1), highest.at(i));
}
chmin(result, sum);
}
cout << result << endl;
} | 0 | 28,130,093 |
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
signed main(){
Int n;
cin>>n;
vector<Int> a(n);
for(Int i=0;i<n;i++) cin>>a[i];
Int ans=a[0];
for(Int i=0;i<n;i++) ans=__gcd(ans,a[i]);
cout<<ans<<endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define input_output freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define ll long long
#define read1(x) cin>>x
#define read2(x,y) cin>>x>>y
#define print(x) cout<<x<<endl
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vb vector<bool>
#define vd vector<double>
#define vs vector<string>
#define ff first
#define ss second
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define vpii vector<pii>
#define umap unordered_map
#define uset unordered_set
#define clr(a,b) memset(a,b,sizeof a)
#define all(ds) ds.begin(), ds.end()
#define rev(ds) ds.rbegin(), ds.rend()
#define asc(A) sort(A.begin(), A.end())
#define dsc(A) sort(A.begin(), A.end(), greater<int>())
#define gcd(x,y) __gcd(x,y)
#define clr(a,b) memset(a,b,sizeof a)
#define fr(i, n) for(int i=0; i<n;++i)
#define fr1(i, n) for(int i=1; i<=n; ++i)
#define rfr(i, n) for(int i=n-1; i>=0; --i)
#define printVector(v) for(int i= 0;i<v.size();i++) {cout<<v[i]<<" ";} cout<<endl;
#define precise(x) cout<<fixed<<setprecision(x)
#define inf 10000000000000
ll lcm(ll a, ll b) {return (a*b)/__gcd(a, b); }
ll power(ll x, ll y, ll m) { if(!y) return 1; ll p=power(x, y>>1, m)%m; p=p*p%m; return (y&1)?(x*p)%m:p;}
ll modInverse(ll a, ll m){ return power(a, m-2, m); }
bool isPrime(ll num){bool flag=true;for(ll i =2;i<=num/2;i++){if(num%i==0) {flag=false; break;} }return flag;}
ll sumofdigits(ll n){ll c=0;while(n>0){c++;n/=10;}return c;}
bool sortinrev(const pair<int,int>&a,const pair<int,int>&b) {return a.first > b.first; }
bool sortbysec(const pair<int,int> &a, const pair<int,int> &b) {return a.second < b.second; }
const long long MOD= 1000000007;
void solve(){
int n; cin>>n;
vi v(n);
fr(i,n){
cin>>v[i];
}
ll ans = 0;
for(int i = 1; i < n; ++i){
if(v[i-1] > v[i]){
int diff = v[i-1]-v[i];
v[i] = v[i] + diff;
ans += diff;
}
}
cout<<ans<<endl;
}
int main()
{
#ifndef ONLINE_JUDGE
input_output
#else
fastio
#endif
int t =1 ;
while(t--){
solve();
}
return 0;
} | 0 | 46,881,496 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
cin >> N;
vector<int> vec(N);
for(int i=0; i<N; i++){
cin >> vec.at(i);
}
vector<int> copy(N);
for(int i=0; i<N; i++){
copy.at(i) = vec.at(i);
}
sort(copy.begin(),copy.end());
map<int,int> mp;
for(int i=0; i<N; i++){
mp[copy.at(i)] = i;
}
vector<bool> change(N);
for(int i=0; i<N; i++){
if(i %2 == mp[vec.at(i)] %2){
change.at(i) = true;
}
else{
change.at(i) = false;
}
}
int ans = 0;
for(int i=0; i<N-1; i++){
if(!change.at(i)){
if(!change.at(i+1)){
change.at(i) = true;
change.at(i+1) = true;
ans++;
}
else{
swap(change.at(i),change.at(i+1));
}
}
}
cout << ans << endl;
} | #include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using lint = long long;
int main() {
lint N, M; std::cin >> N >> M;
std::vector<std::string> A(N);
std::vector<std::string> B(M);
for (auto& r : A)std::cin >> r;
for (auto& r : B)std::cin >> r;
if (N == M) {
bool flag = true;
for (int i = 0; i < N; ++i) {
if (A[i] != B[i])
flag = false;
}
if (flag == true) {
std::cout << "Yes" << std::endl;
return 0;
}
else {
std::cout << "No" << std::endl;
return 0;
}
}
for (int h = 0; h < N - M; ++h) {
for (int w = 0; w < N - M; ++w) {
bool flag = true;
for (int j = 0; j < M; ++j) {
if (A[h + j].substr(w, M) != B[j]) {
flag = false;
break;
}
}
if (flag == true) {
std::cout << "Yes" << std::endl;
return 0;
}
}
}
std::cout << "No" << std::endl;
} | 0 | 79,706,712 |
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
os << '(' << a.first << ',' << a.second << ')';
return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
for (auto x : v) os << x << ' ';
return os;
}
void debug() {
cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
cerr << a;
if (sizeof...(b)) cerr << ", ";
debug(b...);
}
vector<vector<int>> g;
int main(){
int n, m;
cin >> n >> m;
g.resize(n);
rep(i,m){
int a, b;
cin >> a >> b;
a--;b--;
g[a].push_back(b);
g[b].push_back(a);
}
vector<int>dist(n,INT_MAX);
dist[0] = 0;
queue<int>q;
q.push(0);
while(q.size()){
int x = q.front();
q.pop();
for(auto v: g[x]){
if(dist[v]!=INT_MAX)continue;
dist[v] = dist[x] + 1;
q.push(v);
}
}
cout << "Yes" << endl;
for(int i = 1; i < n; i++){
for(auto x : g[i]){
if(dist[i] == dist[x] + 1){
cout << x + 1 << "\n";
break;
}
}
}
} | #include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef vector<int> vi;;
typedef vector<ll> vll;
#define l() length()
#define sz() size()
#define b() begin()
#define e() end()
#define all(x) x.begin(), x.end()
#define pb(i) push_back(i)
#define PB() pop_back()
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
#define mp make_pair
#define Fi first
#define Se second
const int maxx=1e6+9;
ll _find(string &str){
for(ll i=0;i<(ll)str.length();i++){
if(str[i]!='1'){return i;}
}
return -1;
}
void solve(){
string str;
ll k;
cin>>str;
cin>>k;
ll p=_find(str);
if(p==-1){
cout<<1<<endl;
return ;
}
else{
k--;
if(k>=p){
cout<<str[p];
}
else{
cout<<1;
}
}
}
int main() {
faster;
int t=1;
while(t-->0){
solve();
}
return 0;
} | 0 | 94,784,813 |
#include <iostream>
using namespace std;
int main()
{
int x,y,c;
cin >> x >> y >> c;
int i, count = 0;
for(i = x; i <= y && i <= c;i++)
if(c%i == 0) count++;
cout << count << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX = 2e5 + 5;
const int K = 21;
ll ar[MAX];
int n;
ll dp[MAX];
ll sum[MAX];
int cnt[K];
int main()
{
cin >> n;
for (int i = 0; i < n; i++)
cin >> ar[i];
int start = 0;
int end = 0;
bool ok = true;
ll sum = 0;
ll xor_sum = 0;
ll ans = 0;
while (end < n){
sum += ar[end];
xor_sum ^= ar[end];
if (sum == xor_sum){
ans += (end - start + 1);
} else{
while (sum != xor_sum){
sum -= ar[start];
xor_sum ^= ar[start];
start += 1;
}
ans += (end - start + 1);
}
end += 1;
}
cout << ans << "\n";
return 0;
} | 0 | 72,200,311 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
int a[MAXN];
int dp_old[MAXN], dp[MAXN], sums[MAXN];
int n, k;
const int MOD = 1e9 + 7;
inline int get_sum(int start, int end){
if(start == 0)
return sums[end];
int ans = sums[end] - sums[start - 1];
if(ans < 0){
ans += MOD;
}
return ans;
}
inline long long int mod_ans(long long int a, int val){
if(a >= val)
return a % val;
return a;
}
int main(){
cin >> n >> k;
for(int j = 0; j <= k; ++j){
dp[j] = 0;
dp_old[j] = 0;
}
dp_old[0] = 1;
for(int x = 0; x < n; ++x){
cin >> a[x];
int sum = 0;
for(int i = 0; i <= k; ++i){
sum = mod_ans(dp_old[i] + sum, MOD);
sums[i] = sum;
}
for(int val = 0; val <= k; val++){
dp[val] = get_sum(max(val - a[x], 0), val);
}
for(int i = 0; i <= k; ++i){
dp_old[i] = dp[i];
sums[i] = 0;
dp[i] = 0;
}
}
cout << dp_old[k] << "\n";
return 0;
} | #include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef long double ld;
const int MAXN = 302;
const lli INF = (lli)(1e16);
lli H[MAXN];
lli memo[MAXN][MAXN];
int main() {
int N, K;
cin >> N >> K;
for (int i = 1 ; i <= N ; i++) {
cin >> H[i];
}
for (int i = 1 ; i <= N ; i++) {
memo[i][1] = H[i];
for (int k = 2 ; k <= N ; k++) {
memo[i][k] = INF;
}
}
for (int k = 2 ; k <= N-K ; k++) {
for (int i = 1 ; i <= N ; i++) {
for (int j = i-1 ; j >= 1 ; j--) {
memo[i][k] = min(memo[i][k], memo[j][k-1] + max((lli)0, H[i]-H[j]));
}
}
}
lli ans = INF;
for (int i = 1 ; i <= N ; i++) {
ans = min(ans, memo[i][N-K]);
}
cout << ans;
return 0;
} | 0 | 38,205,078 |
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>
using namespace std;
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());
typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<bool> vb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 29);
const ll LINF = 1e18;
const double PI = acos(-1);
template<typename T>vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value != 0>::type
fill_v(U& u, const V... v) { u = U(v...); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value == 0>::type
fill_v(U& u, const V... v) { for (auto& e : u) fill_v<T>(e, v...); }
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 main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
vi A(N);
REP(i, N)cin >> A[i];
double sum = 0;
REP(i, N) {
sum += 1.0/A[i];
}
double ans = 1.0 / sum;
printf("%.7f\n", ans);
return 0;
} | #pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
using ll = long long;
using namespace std;
const long long MOD = 1000000007;
const ll LINF = 1LL << 50;
int main() {
int N;
cin >> N;
vector<int> C(N-1);
vector<int> S(N-1);
vector<int> F(N-1);
REP(n,N-1){
cin >> C[n] >> S[n] >> F[n];
}
REP(n,N-1){
int time = 0;
for(int m = n;m < N-1;m++){
if (time < S[m]) {
time = S[m];
} else if(time % F[m] == 0) {
time = time;
} else{
time = time + F[m] - time%F[m];
}
time += C[m];
}
cout << time << endl;
}
cout << 0 << endl;
} | 0 | 86,164,163 |
#include<iostream>
using namespace std;
int main()
{
int a,b,c,d,e;
cin>>a>>b;
if(a==1&&b==2)
cout<<3<<endl;
else if(a==3&&b==1)
cout<<2<<endl;
else if(a==1&&b==3)
cout<<2<<endl;
else if(a==2&&b==3)
cout<<1<<endl;
else if(a==3&&b==2)
cout<<1<<endl;
else if(a==2&&b==1)
cout<<3<<endl;
} | #include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
#ifdef TEST
chrono::system_clock::time_point start, end;
start = chrono::system_clock::now();
#endif
string S, T;
cin >> S;
cin >> T;
map<char, ll> S_map;
map<char, ll> T_map;
for(size_t i=0;i<S.size(); i++)
{
S_map[S[i]]++;
T_map[T[i]]++;
}
map<ll, vector<char>> diff_S;
map<ll, vector<char>> diff_T;
for(auto m : S_map)
{
if(m.second != T_map[m.first]) diff_S[m.second].push_back(m.first);
}
for(auto m : T_map)
{
if(m.second != S_map[m.first]) diff_T[m.second].push_back(m.first);
}
bool ok = true;
for(auto m: diff_S)
{
if(m.second.size() != diff_T[m.first].size()) ok = false;
}
if(ok) cout << "Yes" << endl;
else cout << "No" << endl;
#ifdef TEST
end = chrono::system_clock::now();
cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
return 0;
} | 0 | 79,005,998 |
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
int main() {
int N;
cin >> N;
map<int, int> map;
int a;
rep(i,N) {
cin >> a;
map[a] += 1;
}
int ans, curr;
ans = 0;
rep(i, 100001) {
curr=map[i-1]+map[i]+map[i+1];
ans = curr > ans ? curr : ans;
}
cout << ans << endl;
} | #include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int MOD = 1000000007;
typedef long long ll;
int main(){
ll S;
cin >> S;
if(S == 1000000000000000000) {
cout << 0 << " " << 0 << " " << 1000000000 << " " << 0 << " " << 0 << " " << 1000000000
<< endl;
return 0;
}
ll x0 = 0, y0 = 0, x1 = 1000000000, x2 = 1;
ll y2 = (S / 1000000000) + 1;
ll y1 = 1000000000 - (S % 1000000000);
cout << x0 << " " << y0 << " " << x1 << " " << y1 << " " << x2 << " " << y2 << endl;
return 0;
} | 0 | 40,224,495 |
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
int main(){
long long n;
cin >> n;
vector<int> a(n);
rep(i,n) cin >> a[i];
long long ans = 0;
int maxi = 0;
rep(i,n){
maxi = max(maxi,a[i]);
int Bi = maxi;
ans += Bi - a[i];
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define MIN(a,b) ((a)>(b)? (b): (a))
#define MAX(a,b) ((a)<(b)? (b): (a))
const long long INF = 1LL << 60;
typedef unsigned long long ll;
const long long MOD = 1000000000 + 7;
int main(){
int a, b, c;
cin >> a >> b >> c;
rep(i,100){
if(a*(i+1)%b == c){
cout << "YES" << endl;
return 0;
}
}
cout << "NO" << endl;
return 0;
} | 0 | 84,076,114 |
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;
ll H, W;
vector<vector<ll>> h_sum, w_sum;
void init(vector<vector<char>>& maze)
{
for (ll i = 1; i <= H + 1; ++i) {
ll l = 1, cnt = 0;
for (ll j = 1; j <= W + 1; ++j) {
if (maze.at(i).at(j) == '#') {
for (ll k = l; k < j; ++k) {
w_sum.at(i).at(k) = cnt;
}
cnt = 0;
l = j + 1;
}
else {
cnt += 1;
}
}
}
for (ll i = 1; i <= W + 1; ++i) {
ll l = 1, cnt = 0;
for (ll j = 1; j <= H + 1; ++j) {
if (maze.at(j).at(i) == '#') {
for (ll k = l; k < j; ++k) {
h_sum.at(k).at(i) = cnt;
}
cnt = 0;
l = j + 1;
}
else {
cnt += 1;
}
}
}
}
int main()
{
cin >> H >> W;
h_sum = vector<vector<ll>>(H + 2, vector<ll>(W + 2));
w_sum = vector<vector<ll>>(H + 2, vector<ll>(W + 2));
vector<vector<char>> maze(H + 2, vector<char>(W + 2, '#'));
for (ll i = 0; i < H; ++i) {
for (ll j = 0; j < W; ++j) {
cin >> maze.at(i + 1).at(j + 1);
}
}
init(maze);
ll ans = 0;
for (ll i = 1; i <= H; ++i) {
for (ll j = 1; j <= W; ++j) {
ans = max(ans, h_sum.at(i).at(j) + w_sum.at(i).at(j) - 1);
}
}
cout << ans << "\n";
} | #pragma region header
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr ll inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
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;
}
ll fact(int i) {
if (i == 0) return 1;
return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {
if(b == 0) return a;
return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
return a * b / gcd(a, b);
}
int keta(ll n) {
if(n == 0) return 1;
int count = 0;
while(n != 0) {
n /= 10;
count++;
}
return count;
}
ll ketasum(ll n) {
ll sum = 0;
while(n != 0) {
sum += n % 10;
n /= 10;
}
return sum;
}
#pragma endregion
signed main() {
int n;cin >> n;
vi div;
int k = sqrt(n);
for(int i = 1;i<=k;i++) if(n%i==0)div.pb(i);
cout << keta(n/div[div.size()-1]) << endl;
return 0;
} | 0 | 28,095,416 |
#include<iostream>
using namespace std;
int main(){
long long int a,b,c;
long long int k;
cin>>a>>b>>c>>k;
while(k--){
if(a>=b){
b*=2;
}
else if(b>=c){
c*=2;
}
}
if(a<b&&b<c){
cout<<"Yes"<<endl;
return 0;
}
cout<<"No"<<endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int64_t powermod(int64_t x, int64_t y, int64_t p){
if(y < 0 || x <= 0)
return 0;
else{
int64_t n = 1;
x %= p;
for(int64_t i = 0; i < y; i++){
n = n*x%p;
}
return n;
}
}
int main() {
int64_t mod = 998244353;
int64_t n;
cin >> n;
vector<int>d(n);
rep(i,n) cin >> d[i];
if(d[0] != 0) cout << 0 << endl;
else{
sort(d.begin(),d.end());
int dmax = d[d.size()-1];
vector<int>cnt(dmax+1,0);
rep(i,n) cnt[d[i]]++;
int64_t ans = 1;
if(cnt[0] != 1) cout << 0 << endl;
else{
rep(i,dmax) ans = ans*powermod(cnt[i],cnt[i+1],mod)%mod;
cout << ans << endl;
}
}
} | 0 | 74,603,997 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
int N;
cin >> N;
vector<int> a(N+1,0);
rep(i,N) cin >> a[i];
ll ans = 0;
rep(i,N){
ans += a[i]/2;
a[i] %= 2;
if(a[i] & (a[i + 1]>0)){
ans++;
a[i+1]--;
}
}
cout << ans << endl;
} | #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
int main()
{
int N, cnt = 0;
cin >> N;
bool flag = false;
for (int i = 0; i <= N / 4; i++)
{
for (int j = 0; j <= N / 7; j++)
if (4 * i + 7 * j == N)
{
flag = true;
break;
}
}
if (flag)
{
cout << "Yes";
}
else
{
cout << "No";
}
} | 0 | 10,166,214 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()
const int N = 1e5 + 5;
int a[N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
int ans = a[n - 1] - a[0];
for (int i = 1; i + 1 < n; i++) {
ans += abs(a[i]);
}
cout << ans << "\n";
int anime = a[0];
for (int i = 1; i + 1 < n; i++) {
if (a[i] > 0) {
cout << anime << " " << a[i] << "\n";
anime -= a[i];
}
}
cout << a[n - 1] << " " << anime << "\n";
anime = a[n - 1] - anime;
for (int i = 1; i + 1 < n; i++) {
if (a[i] <= 0) {
cout << anime << " " << a[i] << "\n";
anime -= a[i];
}
}
return 0;
} | #include <iostream>
using namespace std;
int main() {
while(true) {
int n, x;
cin >> n >> x;
if(n == 0 && x == 0) {
break;
}
int count = 0;
int i, ii, iii = 0;
for(i=1; i <= n; i++) {
for(ii = i + 1; (ii > i && ii <= n); ii++) {
for(iii = ii + 1; (iii > ii && iii <= n); iii++) {
if( i + ii + iii == x ) {
count += 1;
}
}
}
}
cout << count << endl;
}
} | 0 | 18,870,945 |
#include <bits/stdc++.h>
const int INF =1e9;
const int MOD =1e9+7;
using namespace std;
typedef long long ll;
#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REPD(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < int(b); i++)
#define FORD(i, a, b) for (int i = b - 1; i >= int(a); i--)
#define WRAP(y, x, h, w) (0 <= y && y < h && 0 <= x && x < w)
#define ALL(x) (x).begin(), (x).end()
int dx[4] ={ 1, 0, -1, 0 };
int dy[4] ={ 0, 1, 0, -1 };
int main()
{
int s,w;
cin>>s>>w;
if(s>w)
cout<<"safe"<<endl;
else
cout<<"unsafe"<<endl;
} | #include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;
#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x) cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
void solve() {
int n, k; cin >> n >> k;
vector<int> a(n), sum(n + 1, 0), psum(n + 1, 0);
rep(i, n) {
cin >> a[i];
sum[i + 1] = sum[i] + a[i];
psum[i + 1] = psum[i] + (a[i] > 0 ? a[i] : 0);
}
int ans = 0;
for(int r = k; r <= n; ++ r) {
int l = r - k;
int res = max(0LL, sum[r] - sum[l]);
res += psum[n] - (psum[r] - psum[l]);
chmax(ans, res);
}
cout << ans << endl;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
solve();
return 0;
} | 0 | 53,623,321 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
int main(){
int n;
cin >> n;
vi a(n);
rep(i,n) cin >> a[i];
sort(a.rbegin(),a.rend());
int len = a[0]+1;
vi cnt(len);
for(int x : a) for(int i=x; i<=len; i+=x) cnt[i]++;
int ans=0;
for(int x : a){
if(cnt[x] == 1) ans++;
}
cout << ans << endl;
} | #define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>
#include <queue>
using namespace std;
int main() {
priority_queue<int> PQ;
string com;
int k;
cin >> com;
while (com != "end") {
if (com == "insert") {
cin >> k;
PQ.push(k);
}
if (com == "extract") {
cout << PQ.top() << endl;
PQ.pop();
}
cin >> com;
}
return 0;
} | 0 | 48,011,910 |
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
int main(){
int N;
cin>>N;
VI A(N);
rep(i,N) cin>>A[i];
sort(all(A));
VL X(N);
X[0]=A[0];
rep(i,N-1) X[i+1]=X[i]+A[i+1];
int ans=1;
rep(i,N-1){
if(A[N-1-i]>X[N-2-i]*2) break;
ans++;
}
cout<<ans<<endl;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int Max = 0;
int Min = 110;
int water(vector<int> h) {
rep(i, h.size()) h[i] -= Min;
int count = Min;
for(int i = 0; i <= Max; i++) {
rep(j, h.size()) {
if(h[j] != 0) {
h[j]--;
while(h[j + 1] != 0) {
h[j + 1]--;
j++;
}
count++;
}
}
}
return count;
}
int main () {
int n;
cin >> n;
vector<int> h(n);
rep(i, n) {
cin >> h[i];
Max = max(h[i], Max);
Min = min(h[i], Min);
}
cout << water(h) << endl;
} | 0 | 299,120 |
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
typedef pair<int, int>P;
P h[100000];
int main() {
int n, m;
while (scanf("%d%d", &n, &m), n) {
int ans = 0;
rep(i, n) {
int d, p; scanf("%d%d", &d, &p);
ans += d*p;
h[i] = P(p, d);
}
sort(h, h + n, greater<>());
int sum = m;
int i;
for (i = 0; i < n&& sum - h[i].second >= 0; i++) {
sum -= h[i].second;
ans -= h[i].first*h[i].second;
}
ans -= h[i].first*sum;
printf("%d\n", max(0, ans));
}
} | #include <stdio.h>
int main()
{
int w,h,n,x,y;
while(1)
{
scanf("%d%d",&w,&h);
if(w == 0&&h == 0)break;
int mem[20][20] = {0};
scanf("%d",&n);
for(int i = 0; i < n; i++)
{
scanf("%d%d",&y,&x);
mem[x - 1][y - 1] = 1;
}
int dp[20][20] = {1};
for(int i = 0; i < h; i++)
{
for(int j = 0; j < w; j++)
{
if(mem[i][j] == 1)dp[i][j] = 0;
else if(i != 0||j != 0)dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
}
}
printf("%d\n",dp[h - 1][w - 1]);
}
return 0;
} | 0 | 14,350,497 |
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
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 modInverse(ll n, ll p)
{
return power(n, p-2, p);
}
ll nCrModPFermat(ll n, ll r, ll p)
{
if (r==0)
return 1;
ll fac[n+1];
fac[0] = 1;
for (ll i=1 ; i<=n; i++)
fac[i] = fac[i-1]*i%p;
return (fac[n]* modInverse(fac[r], p) % p *
modInverse(fac[n-r], p) % p) % p;
}
void solve()
{
ll mod = 1e9 + 7;
ll n,k;
cin>>n>>k;
ll ans = 0;
ll c = n+1-k;
for (ll i = k; i < n+2; ++i)
{
ll l = i*(i-1)/2;
ll r = (n+1)*(n)/2 - (n+1-i)*(n-i)/2;
ans = (ans + r-l+1)%mod;
}
cout<<ans<<endl;
}
int main()
{
ll t = 1;
while(t--)
{
solve();
}
} | #include <bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
int main() {
string s;
cin >> s;
for (int i = 0; i < s.size(); i += 2) {
cout << s[i];
}
cout << endl;
return 0;
} | 0 | 93,613,711 |
#include <iomanip>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int main(void) {
ios::sync_with_stdio(false);
int N, K;
cin >> N >> K;
vector<int64_t> A(N);
rep(i, N) cin >> A[i];
int maxK = N * (N + 1) / 2;
vector<int64_t> B;
rep(i, N) {
int64_t sum = 0;
for (int j = i; j < N; ++j) {
sum += A[j];
B.emplace_back(sum);
}
}
int64_t answer = 0;
for (int i = 39; i >= 0; --i) {
int count = 0;
rep(j, maxK) {
if ((B[j] & answer) == answer && (B[j] & (1LL << i))) ++count;
}
if (K <= count) answer |= (1LL << i);
}
cout << answer << endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define MAX_N 100000
typedef long long ll;
typedef pair<int,int> P;
const long long MOD = 1e9 + 7;
const long long INF = 1e15;
const int INF_INT = 1e9;
template<class TYPE>
struct edge{
TYPE to,cost;
edge(TYPE t,TYPE c){
to = t;
cost = c;
}
};
int main(){
int N,M;
cin >> N >> M;
int ans = 1;
for(int i = 1; i <= M; i++) ans *= 2;
int temp = ans;
ans *= 1900 * M;
for(int i = 1; i <= temp; i++) ans += (N-M)*100;
cout << ans << endl;
return 0;
} | 0 | 25,266,287 |
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
int main() {
int N;
ll ans = 0;
cin >> N;
vector<ll> A(N);
vector< vector<ll> > B(60, vector<ll>(N+1));
ll all_a = 0;
REP(i, N) {
ll ain;
cin >> A[i];
all_a ^= A[i];
}
REP(i,N) A[i] &= ~all_a;
ans = all_a;
REP(i,60) {
REP(j,N) {
B[59-i][j] = (A[j] >> i) & 1;
}
B[59-i][N] = 1;
}
vector<bool> use(60,false);
REP(col,N) {
int pivot = -1;
REP(row,60) {
if (use[row]) continue;
if (B[row][col] == 1) {
pivot = row;
break;
}
}
if (pivot == -1) continue;
REP(row,60) {
if ((row != pivot) && (B[row][col] == 1)) {
REP(i,N+1) {
B[row][i] ^= B[pivot][i];
}
}
}
use[pivot] = true;
}
REP(row,60) {
bool ok = false;
if ( (B[row][N] == 0) ) ok = true;
REP(col,N)
if ( B[row][col] == 1 ) ok = true;
if (ok)
ans += (2LL << (59-row));
}
cout << ans << endl;
} | #include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod =1e+9+7;
const int dy[4]={0,1,0,-1};
const int dx[4]={1,0,-1,0};
const ll INF=1e10;
int main(){
ll n; cin>>n;
vector<ll>a(n);
rep(i,n){
cin>>a[i];
a[i]-=i+1;
}
sort(all(a));
ll mid;
ll ans=0;
vector<ll>b=a;
vector<ll>c=a;
if(n%2==1){
mid=-1*b[n/2];
rep(i,n){
b[i]+=mid;
ans+=abs(b[i]);
}
cout<<ans<<endl;
return 0;
}
else{
ll mid1=-1*c[n/2-1],mid2=-1*c[n/2];
ll ans1=0,ans2=0;
rep(i,n){
c[i]+=mid1;
ans1+=abs(c[i]);
}
c=a;
rep(i,n){
c[i]+=mid2;
ans2+=abs(c[i]);
}
ans=min(ans1,ans2);
cout<<ans<<endl;
}
} | 0 | 36,709,818 |
End of preview. Expand
in Dataset Viewer.
- Downloads last month
- 104