akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
 
using namespace std;
 
#define int long long
#define ALL(x) (x).begin(),(x).end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
 
typedef pair<int,int> PI;
typedef pair<int,pair<int,int>> PII;
static const int INF=1010000000000000017LL;
static const double eps=1e-12;
static const double pi=3.14159265358979323846;
static const int dx[4]={1,-1,0,0};
static const int dy[4]={0,0,1,-1};
static const int ddx[8]={1,-1,0,0,1,1,-1,-1};
static const int ddy[8]={0,0,1,-1,1,-1,1,-1};
 
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}

const int mod=1000000007;

string L;
int N;

PI ab[4]={PI(0,0),PI(0,1),PI(1,0),PI(1,1)};
int mem[100005][2][3];

void init(){
    for(int i=0;i<100005;++i)for(int j=0;j<2;++j)for(int k=0;k<3;++k)mem[i][j][k]=-1;
}

int check(int a, int b, int c, int dig){
    if(a+b+c>L[dig]-'0')return 2;
    if(a+b+c==L[dig]-'0')return 1;
    else return 0;
}

// isequal : 0=small, 1=equal, 2=bigger 
int calc(int n, int pre_c, int isequal,PI res){
    if(mem[n][pre_c][isequal]!=-1)return mem[n][pre_c][isequal];
    int ret=0;
    int a,b,c;
    int isequal_;
    if(n==N)return 0;
    for(int i=0;i<4;++i){
        a=ab[i].first,b=ab[i].second;
        PI next=PI(res.first+(a<<n),res.second+(b<<n));
        if(a+b+pre_c>=2)c=1;
        else c=0;
        int same=check(a,b,pre_c,n);
        if(isequal==0||isequal==2){
            if(same==1)isequal_=isequal;
            else isequal_=same;
        }
        else isequal_=check(a,b,pre_c,n);
        if((a+b+pre_c)%2==a^b){
            if(!(n==N-1&&isequal_==2)){
                if((a==0&&b==0)||c!=0)ret+=calc(n+1,c,isequal_,next);
                else ret+=calc(n+1,c,isequal_,next)+1;
            }
            ret%=mod;
        }
    }
    return mem[n][pre_c][isequal]=ret%mod;
}

signed main(){
    init();
    cin>>L;
    N=L.size();
    reverse(L.begin(),L.end());
    cout<<(calc(0,0,1,PI(0,0))+1)%mod<<endl;
    return 0;
}


Measured memory_bytes: 16224
//競技プログラミング　テンプレ
//
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)

const int max_v = 300;
const int INF = 1000000;



int main() {
	int n,a,b, ans;
	cin >> n >> a >> b;
	//vector <int> A(n);

    if(n*a >= b){cout << b << endl;}
    else  cout << a*n << endl;


	return 0;
}


Measured memory_bytes: 256
(N,W),*vw = [list(map(int, s.split())) for s in open(0)]
vw.sort(key=lambda x:x[1],reverse=True)
from collections import defaultdict
dp = defaultdict(int)
dp[0] = 0

for v,w in vw:
    items = list(dp.items())
    for key, val in items:
        new_key = key+w
        if new_key <= W:
            new_val = val+v
            if (new_key in dp and dp[new_key] < new_val) or new_key not in dp:
                dp[new_key] = max(dp[new_key], new_val)

print(max(dp.values()))


Measured memory_bytes: 8632
#include <bits/stdc++.h>
using namespace std;

int main(){
    int n,m;
    cin >> n >> m;

    vector<vector<int>> jobs(m);
    for(int i=0;i<n;i++){
        int a,b;
        cin>> a >> b;
        // m日以降しか取得できない場合は除く
        if(m >= a){
            jobs.at(a-1).push_back(b);
        }
    }
    
    long long ans=0;
    // i日後得られる最大値を求める
    priority_queue<int> cand;
    for(int i=0;i<m;i++){
        for(int b : jobs.at(i)){
            cand.push(b);
        }
        if(!cand.empty()){
            ans+= cand.top();
            cand.pop();
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 5632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;



int main() {
#ifdef HOME
    freopen("in", "r", stdin);
#endif

    int n, h;
    while (scanf("%d%d", &n, &h) == 2) {
        vector<int> a(n), b(n), c(n), d(n);
        for (int i = 0; i < n; i++) {
            scanf("%d%d%d%d", &a[i], &b[i], &c[i], &d[i]);
        }

        vector<int> p(2 * h);
        iota(p.begin(), p.end(), 0);
        function<int(int)> get = [&](int x) {
            return x == p[x] ? x : p[x] = get(p[x]);
        };
        auto uni = [&](int u, int v) {
            p[get(v)] = get(u);
        };
        vector<int> deg(2 * h);
        vector<char> ok(2 * h, 1);
        for (int i = 0; i < n; i++) {
            int u = c[i] == 0 ? a[i]-1 : h + c[i]-1;
            int v = d[i] == 0 ? h+b[i]-1 : d[i]-1;
            ok[u] = ok[v] = 0;
            uni(u, v);
            deg[u]++;
            deg[v]--;
        }
        bool f = 1;
        for (int i = 0; i < h; i++) {
            f &= deg[i] >= 0;
            f &= deg[i + h] <= 0;
        }
        for (int i = 0; i < 2 * h; i++) if (deg[i] != 0) ok[get(i)] = 1;
        for (int i = 0; i < 2 * h; i++) if (p[i] == i && !ok[i]) f = 0;
        string ans = f ? "YES" : "NO";
        cout << ans << endl;
    }

#ifdef HOME
    cerr << clock() / (double)CLOCKS_PER_SEC << endl;
#endif
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <bitset>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;

int main(){
    ll n; cin >> n;
    map<pair<string, ll>,ll> mp;
    rep(i,n){
        string s; ll x;
        cin >> s >> x;
        auto p = make_pair(s,-x);
        mp[p] = i+1;
    }
    for(auto i : mp){
        cout << i.second << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>

using namespace std;
#define sint(a) scanf("%d",&a)
#define sint2(a,b) scanf("%d %d",&a,&b)
#define sll(a) scanf("%lld",&a)
#define sll2(a,b) scanf("%lld %lld",&a,&b)
#define mem(a,i) memset(a,i,sizeof(a))
#define pb push_back
#define ll long long
#define lson node<<1
#define rson (node<<1)+1

const int maxn=1e6+10;
const ll mod=1e9+7;
const double pi=acos(-1);

ll a[maxn];
int main()
{
    int n;
    sint(n);
    ll x=0;
    for(int i=0; i<n; i++)
    {
        sint(a[i]);
        x^=a[i];
    }
    for(int i=0;i<n;i++)
        printf("%lld ",x^a[i]);
    return 0;
}



Measured memory_bytes: 5372
#include<bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
using pqueg = priority_queue<int, vector<int>, greater<int>>;
using pquel = priority_queue<int, vector<int>, less<int>>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
int lcm(int a, int b){
  return a / __gcd(a, b) * b;
}
int r_int(int a, int b){
  return rand() % b + a;
}
const lint mod=1e9+7;


int main()
{
  lint x;
  cin >> x;

  int range = 200;
  map<int, lint> sqrt5;
  for(int i = -1*range;i<=range;i++) sqrt5[i] = pow(i,5);

  for(int i = -1*range;i<range;i++){
    for(int j = i+1;j<=range;j++){
      if(sqrt5[j]-sqrt5[i] == x){
        cout << j << " " << i << "\n";
        return 0;
      }
    }
  }

  return 0;
}


Measured memory_bytes: 4136
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

#include <vector>
#include <queue>

using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

	int N, M;
	cin >> N >> M;

	vector<int> H(N, 0);
	for (int i = 0; i < N; i++)
	{
		cin >> H[i];
	}

	vector<int> max_height(N, 0);

	for (int i = 0; i < M; i++)
	{
		int a, b;
		cin >> a >> b;

		a--;
		b--;

		max_height[a] = max(max_height[a], H[b]);
		max_height[b] = max(max_height[b], H[a]);
	}

	int result = 0;
	for (int i = 0; i < N; i++)
	{
		if (max_height[i] == 0 || max_height[i] < H[i])
		{
			result++;
		}
	}

	cout << result;

	return 0;
}

Measured memory_bytes: 3988
#include <bits/stdc++.h>
using namespace std;
#define all(n) begin(n), end(n)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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;
}
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);
}
int main()
{
    char a;
    cin>>a;
    if('a'<= a and a <= 'z')
    {
        cout<<'a';
    }
    else
    cout<<'A';
    return 0;
}

Measured memory_bytes: 3668
#pragma GCC optimize ("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n, a, i;
	cin >> n;

	int persons[n];
	for (i = 0; i < n; ++i) {
		cin >> a;
		persons[a - 1] = i + 1;
	}

	for (i = 0; i < n - 1; ++i) {
		cout << persons[i] << " ";
	}
	cout << persons[n - 1] << endl;
	return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPP(i, n) for(int i = 1; i <= n; ++i)
#define REPR(i, n) for(int i = n-1; i >= 0; --i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1000000007;
const ll INF = 1000000000;

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;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    vector<ll> a(3*n);
    REP(i,3*n) cin >> a[i];
    sort(a.rbegin(),a.rend());
    ll ans = 0;
    for(int i = 1; i < 3*n - (n-1); i += 2) ans += a[i];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
#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 rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
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;
  int tmp;
  int ans = 0;
  for(int i=0;i<N;++i) {
    cin>>tmp;
    if(i%2==0 && tmp%2==1) ans++;
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 3580
#include <iostream>
#include <algorithm>
#include <map>
#include <utility>
#include <vector>
#include <cstdio>
#include <iomanip>
#include <cmath>  
#include <cstdlib>
#include <limits>
#include <numeric>
#include <type_traits>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i <= n; i++) 

int gcd(int x, int y) {return (x%y)? gcd(y, x%y): y;}

int trigcd(int a, int b, int c) {
    a = gcd(a, b);
    a = gcd(a, c);
    return a;

}

int main() {
    int k;
    cin >> k;
    int ans = 0;
    rep1(a,k) {
        rep1(b,k) {
            rep1(c,k){
                ans += trigcd(a, b, c);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;

int main(){
    int N;
    cin>>N;
    int ans=0;
    for(int i=1;i<=N;i+=2){
        int cnt=0;
        for(int j=1;j<=N;j++){
            if(i%j==0){
                cnt++;
            }
        }
        if(cnt==8){
            ans++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
n = int(input())
x = list(map(int, input().split()))
x_ = sorted(x)
a = x_[int(len(x)/2)-1]
b = x_[int(len(x)/2)]

for i in range(n):
    if x[i]>=b:
        print(a)
    else:
        print(b)

Measured memory_bytes: 25224
#include <iostream>
using namespace std;
int main(){
		int x,y,d;
		cin >> x >> y;
		if( y >= x) swap(x,y);
		while(y > 0){
				d = x % y;
				x = y;
				y = d;
		}
		cout << x << endl;
		return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
typedef long long i64;
int main() {
    int n,k;
    cin>>n>>k;
    i64 a[n],dp[n+1];
    for(int i = 0; i <= n; i++)
        dp[i] = INT_MAX;
    for(int i = 0; i < n; i++)
        cin>>a[i];
    dp[0] = 0;
    dp[1] = abs(a[1] - a[0]);
    for(int i = 2; i < n; i++) {
        for(int j = 1; j <= k; j++) {
            if(i >= j) {
                dp[i] = min(dp[i],dp[i-j] + abs(a[i] - a[i-j]));
            }
        }
    }
    cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define maxn 200000
#define LL long long
int a[maxn+5],f[maxn+5],n; LL k;
bool check(LL x){
	LL ans=0;
	for(int i=0;i<n;i++){
		ans+=max(0ll,a[i]-x/f[i]);
	}
	return ans<=k;
}
int main(){
	scanf("%d%lld",&n,&k);
	for(int i=0;i<n;i++)scanf("%d",a+i);
	for(int i=0;i<n;i++)scanf("%d",f+i);
	sort(f,f+n);sort(a,a+n,greater<int>());
	LL l=0,r=1e12,mid;
	while(l<=r){
		mid=(l+r)>>1;
		if(check(mid))r=mid-1;
		else l=mid+1;
	}
	printf("%lld\n",l);
	return 0;
}

Measured memory_bytes: 1792
/*{{{*/
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll n,k;
  cin >> n >> k;
  vl a(n);
  ll sum = 0;
  REP(i,n){
    cin >> a[i];
    sum += a[i];
  }
  vl cand;
  REP(i,sqrt(sum)+1){
    if(i==0) continue;
    if(sum%i==0){
      cand.push_back(i);
      cand.push_back(sum/i);
    }
  }
  sort(cand.begin(),cand.end());
  reverse(cand.begin(),cand.end());
  REP(i,cand.size()){
    ll x = cand[i];
    vl b(n);
    REP(i,n) b[i] = a[i]%x;
    sort(b.begin(),b.end());
    deque<ll> que;
    REP(i,n) if(b[i]>0) que.push_back(b[i]);
    ll cur = 0;
    ll cnt = 0;
    while(que.size()>0){
      if(cur<=0){
        cur += que.front();
        cnt += que.front();
        que.pop_front();
      }else{
        cur += que.back()-x;
        que.pop_back();
      }
    }
    if(cnt<=k){
      cout << x << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
#define loop(i,N) for(ll (i)=0; (i)<(N);++(i))
struct _OMAZINAI_ { _OMAZINAI_() { std::ios::sync_with_stdio(false); std::cin.tie(0); } } __omazinai_instance__;
#define INF ((1LL<<61) + (1<<29))
#define YesNo(x) {std::cout << ((x)?"Yes":"No") << std::endl;}
#define YESNO(x) {std::cout << ((x)?"YES":"NO") << std::endl;}
#define OddEven(x) {std::cout << ((x)%2?"Odd":"Even") << std::endl;}
#define ODDEVEN(x) {std::cout << ((x)%2?"ODD":"EVEN") << std::endl;}
typedef long long int ll;
void _INPUT_IMPL_() {};
template <class T, class... Args> void _INPUT_IMPL_(T& dest, Args&... args) { cin >> dest; _INPUT_IMPL_(args...); }
void _OUTPUT_IMPL_() {};
template <class T, class... Args> void _OUTPUT_IMPL_(T dest, Args... args) { cout<< dest << (sizeof...(Args)?" ":""); _OUTPUT_IMPL_(args...); }
#define in(type, ...) type __VA_ARGS__; _INPUT_IMPL_(__VA_ARGS__)
#define in_v(type, name, cnt) vector<type> name(cnt); loop(i, cnt) cin >> name[i];
#define sort_v(v) std::sort(v.begin(), v.end())
#define set_fix(x) ((std::cerr<<std::fixed<<std::setprecision(x)),(std::cout<<std::fixed<<std::setprecision(x)))
#define out(...) (_OUTPUT_IMPL_(__VA_ARGS__), std::cout<<std::endl)
//小さい方に寄る
#define space_op(x, y, a, b, c) ([](auto x_, auto y_, auto a_, auto b_, auto c_){if(x_<y_)return a_;if(x_>y_)return c_;return b_;}(x,y,a,b,c))
#define space_out(x, y, a, b, c) out(space_op(x, y, a, b, c))

int flag[26] = {};
int main() {
	in(string, S);
	for(char c : S) flag[c-'a'] = 1;
	if(S.size()<26){
		cout << S;
		loop(i, 26) if(!flag[i]){
			cout << (char)(i+'a') << endl;
			return 0;
		}
	}else if(S=="zyxwvutsrqponmlkjihgfedcba"){
		out(-1);
	}else{
		vector<char> tmp;
		loop(i, 26){
			tmp.push_back(S.back());
			sort_v(tmp);
			S.pop_back();
			for(auto x : tmp)
				if(S.back() < x){
					S.pop_back();
					cout << S << x << endl;
					return 0;
				}
		}
	}
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using vll = vector<ll>;
using vc = vector<char>;
using vs = vector<string>;
using vpll = vector<pll>;

#define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
#define RREP(i, n) for(ll i = n-1; i >= 0; i--)
#define FOR(i, a, b) for(ll i = a; i <= (ll)(b); i++)
#define RFOR(i, a, b) for(ll i = a; i >= (ll)(b); i--)

#define SIZE(x) ((ll)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));

#define PB push_back
#define MP make_pair
#define F first
#define S second

#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

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; }

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string S; cin >> S;
    cout << ((S == "ABC") ? "ARC" : "ABC") << endl; 
}

Measured memory_bytes: 3600
public class Main {

	/**
	 * AOJ:QQ
	 * @param args
	 */

	static final String MULTIPLE = "x";
	static final String EQUAL = "=";

	public static void main(String[] args) {
		for (int i = 1; i <= 9; i++) {
			for (int j = 1; j <= 9; j++) {
				System.out.println(i + MULTIPLE + j + EQUAL + i * j);
			}
		}
	}

}

Measured memory_bytes: 16872
using System;

	public class Class1
	{
		public static void Main()
		{   
			
			int n =int.Parse(Console.ReadLine());
			string dataSet=Console.ReadLine();
			string[] data=dataSet.Split();
			
			for(int i=0;i<n;i++)
			{
				
				Console.Write(data[n-1-i]);
				if(i!=n-1)
				{
					Console.Write(" ");
				}
			}
			Console.WriteLine();
		
		
		}
	}

Measured memory_bytes: 8796
#include <bits/stdc++.h>

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};

ll N;
const ll MOD = 1000000000 + 7;
std::map<std::tuple<ll, int, bool, bool>, ll> dp;

// 1: accept, 0: reject
bool _next(bool state, int x, int y){
    if(x > y){
        return false;
    }else if(x < y){
        return true;
    }
    return state;
}

ll rec(ll n, int carry, bool stateXor, bool stateSum){
    if(n == 0){
        return carry == 0 && stateXor && stateSum ? 1 : 0;
    }

    auto key = std::make_tuple(n, carry, stateXor, stateSum);
    if(dp.find(key) != dp.end()){
        return dp[key];
    }

    ll res = 0;
    // 00
    res = rec(n / 2, 0, _next(stateXor, 0, n % 2), _next(stateSum, carry, n % 2));

    // 01 (10)
    res = (res + rec(n / 2, carry & 1, _next(stateXor, 1, n % 2), _next(stateSum, carry ^ 1, n % 2))) % MOD;

    // 11
    res = (res + rec(n / 2, 1, _next(stateXor, 0, n % 2), _next(stateSum, carry, n % 2))) % MOD;

    return dp[key] = res;
}

int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    std::cin >> N;

    ll res = rec(N, 0, true, true);
    std::cout << res << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int N;
  cin >> N;
  int p=0, w=0, g=0, y=0;
  for(int i = 0; i < N; i++) {
    string s;
    cin >>s;
    if(s=="P")
      p++;
    if(s=="W")
      w++;
    if(s=="G")
      g++;
    if(s=="Y")
      y++;
  }
  int sum = 0;
  if(p != 0)
    sum++;
  if(w != 0)
    sum++;
  if(g != 0)
    sum++;
  if(y != 0)
    sum++;
  if(sum == 3)
    cout << "Three" <<endl;
  if(sum == 4)
    cout << "Four" <<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1000000007 // 1e9+7
#define PI acos(-1.0)
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1

int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
//---------------------------

int main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  ll n,m;cin>>n>>m;
  ll ans=0;
  if(m-2*n>=0){
    ans=n+(m-2*n)/4;
  }else{
    ans=m/2;
  }
  P(ans);
  return 0;
}


Measured memory_bytes: 256
n,h=map(int,input().split())
AB=list(tuple(map(int,input().split())) for i in range(n))
A,B=zip(*AB)
a=max(A)
count=0
for i in sorted(B)[::-1]:
    if i>=a:
        h -=i
        count +=1
    if h<=0:print(count);exit()

print(count+(h//a) if h%a==0 else 1+count+(h//a))

Measured memory_bytes: 25304
def dfs(a,n):
    if int(a)>n:
        return 0
    if a.count('7')>0 and a.count('5')>0 and a.count('3')>0:
        ans=1
    else:
        ans=0
    for i in '753':
        ans+=dfs(a+i,n)
    return ans

n=int(input())
print(dfs('0',n))

Measured memory_bytes: 3060
// Problem : F - LCS
        // Contest : AtCoder - Educational DP Contest
        // URL : https://atcoder.jp/contests/dp/tasks/dp_f
        // Memory Limit : 1024 MB
        // Time Limit : 2000 ms
        // Powered by CP Editor (https://github.com/cpeditor/cpeditor)
         
        #include <bits/stdc++.h>
        #include <ext/pb_ds/assoc_container.hpp>
        #include <ext/pb_ds/tree_policy.hpp>
        using namespace std;
        using namespace __gnu_pbds;
         
        #define int long long
        #define db double
        #define mod 1000000007
        #define pb push_back
        #define pp pair<int,int>
        #define rep(i,a,b) for(int i=a;i<b;i++)
        #define repe(i,a,b) for(int i=a;i<=b;i++)
        #define repr(i,a,b) for(int i=b;i>=a;i--)
        #define maxn 200005
        #define ss second
        #define ff first
        #define all(a) a.begin(),a.end()
        #define lb lower_bound
        #define ub upper_bound
        #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
        int inv(int a, int b){
         return 1<a ? b - inv(b%a,a)*b/a : 1;
        }
        void solve()
        {
        	string s,t;
        	cin >> s >> t;
        	int n=s.size(),m=t.size();
        	int dp[n+1][m+1];
        	memset(dp,0,sizeof(dp));
        	rep(i,1,n+1)
        		rep(j,1,m+1)
        		{
        			dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        			if(s[i-1] == t[j-1])
        				dp[i][j]=max(dp[i][j],1+dp[i-1][j-1]);
        		}		
        	string ans;
        	int i=n,j=m;
        	while(i>0 and j>0)
        	{
        		if(s[i-1] == t[j-1]) ans.pb(s[i-1]), i--, j--;
                else if(dp[i][j-1] > dp[i-1][j]) j--;
                else i--;
        	}
        	reverse(all(ans));
        	cout <<ans ;
        }
        signed main()
        {
        	ios_base::sync_with_stdio(false);
            cin.tie(NULL);
            int t=1;
            //cin >> t;
            while(t--)
            solve();
            return 0;
        }

Measured memory_bytes: 74004
n=int(input())
A=[int(input()) for _ in range(n)]
cnt=0
for i in range(n):
    cnt+=A[i]//2
    if A[i]%2==1 and i!=n-1:
        if A[i+1]>0:
            cnt+=1
            A[i+1]-=1

print(cnt)

Measured memory_bytes: 7072
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007

const int mx=2e6;

int main(){
	int n,f=0,i,j,num,div;
	cin>>n;
	//cout<<n<<endl;
	vector<int> arr(n);
	for(i=0;i<n;i++)
		cin>>arr[i];

	int fact[mx];

	for(i=0;i<mx;i++)
		fact[i]=i;
	fact[0]=1;
	for(i=2;i*i<mx;i++){
		if(fact[i]==i){
			for(j=2*i;j<mx;j+=i){
				if(fact[j]==j)
					fact[j]=i;
			}
		}
	}

	unordered_map<int,int> mp;
	for(i=0;i<n;i++){
		num=arr[i];
		while(num>1){
			if(mp.find(fact[num])!=mp.end()){
			f=1;
			}
			mp[fact[num]]++;
			div=fact[num];
			while(num%div==0){
				num/=div;
			}
		}
	}

	if(f==0){
		cout<<"pairwise coprime"<<endl;
		return 0;
	}

	f=0;
	for(auto k:mp){
		//cout<<k.first<<" "<<k.second<<endl;
		if(k.second == n){
			f=1;
		}
	}
    if(f==0){
		cout<<"setwise coprime"<<endl;
		return 0;
	}
	cout<<"not coprime"<<endl;
}

Measured memory_bytes: 18352
n,k,*l=map(int,open(0).read().split())
s=sum(l);L=[]
for i in range(1,int(s**0.5)+1):
	if s%i==0:L+=[i,s//i]
L.sort()
for d in L[::-1]:
	a=sorted([m%d for m in l])
	if sum(a[:n-sum(a)//d])<=k:print(d);exit()

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<string>


using ui = unsigned int;

int main() {

	std::string s, t;

	std::cin >> s >> t;

	bool yn = false;

	for (ui i{}; i < s.size(); ++i) {

		auto it = std::find(std::begin(t), std::end(t), s[i]);

		//std::cout << s[i] << " ";
		if (it != std::end(t)) {
			auto ad = std::distance(std::begin(t), it);
			bool eval = true;
			//std::cout << ad << "\n";
			for (ui j{}; j < s.size(); ++j) {
			//	std::cout << j << " " << (j + ad)%s.size() << "\n";

				eval &= s[(i+j)%s.size()] == t[(j + ad) % s.size()];
				if (!eval)
					break;
			}

			if (eval) {
				yn = true;
				break;
			}
		}
	}

	std::cout << (yn ? "Yes" : "No") << "\n";


	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <b; i++)
typedef long long ll;
#define int ll
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int,int> pi;
#define trace(x) cout<<#x<<"="<<x<<"\n";
#define sz(x) (int)(x.size())
#define mod 1000000007

template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
    return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "{";
    typename vector< T > :: const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
    os << "[";
    typename set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
    os << "[";
    typename map< F , S >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << " = " << it -> second ;
    }
    return os << "]";
}

#define deb(x) cerr << #x << " = " << x << endl;

int dp[100005];
set<int> a;
int n;
int fun(int x){
    if(x==0){
        return dp[x]=1;
    }
    if(dp[x]!=-1){
        return dp[x];
    }
    else{
        int ans=0;
        if(a.find(x-1)==a.end()){
            if((x-1)>=0)
            ans=(ans+fun(x-1))%mod;
        }
        if(a.find(x-2)==a.end()){
            if((x-2)>=0)
            ans=(ans+fun(x-2))%mod;
        }
        return dp[x]=ans;
    }
}
int32_t main(){
    ios::sync_with_stdio(false);
    memset(dp,-1,sizeof(dp));
    int m;
    cin>>n;
    cin>>m;
    REP(i,0,m){
        // cin>>a[i];
        int A;
        cin>>A;
        a.insert(A);
    }
    cout<<fun(n)<<"\n";



    return 0;
}

Measured memory_bytes: 5760
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

long compare(const void *a, const void *b)
{
	return *(long*)a - *(long*)b;
}


int main(void)
{
	long nums[200000];
	int n, flg = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%ld", &nums[i]);
	}
	qsort(nums, n, sizeof(long), compare);
	for (int i = 0; i < n - 1 ; i++) {
		if (nums[i] == nums[i + 1]) {
			flg++;
			break;
		}
	}
	if (flg) {
		printf("NO\n");
	}
	else {
		printf("YES\n");
	}
	return 0;
}


Measured memory_bytes: 3324
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N=0;
    cin >>N;
    vector<vector<int>> c(9, vector<int>(9));
    for(int i = 1;i<=N;i++){
        int keta = to_string(i).length();
        //cout << keta << endl;
        int last_num = i%10;
        if(last_num == 0) continue;
        int first_num = 0;
        if(keta == 1){
            first_num = i;
        }else{
            first_num = i/pow(10,(keta-1));
        }
        if(last_num > 9 || first_num >9){
            cout << i << endl;
            cout << pow(10,(keta-1)) << endl;
            cout << first_num << endl;
            cout << last_num << endl;
            exit(1);
        }
        //cout << first_num << endl;
        //cout << last_num << endl;
        
        c.at(last_num-1).at(first_num-1) +=1;
    }
    int cnt = 0;
    for(int i=0;i<9; i++){
        for(int j=0;j<9;j++){
            cnt += c.at(i).at(j)* c.at(j).at(i);
        }
    }
    cout << cnt;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;


int main(){
  int a,b,i;
  cin >> a >> b;
  if(a>=b){
    for(i=0;i<a;++i){
      cout << b;
    }
  }else{
    for(i=0;i<b;++i){
      cout << a;
    }
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Map<Long,Long> map = new HashMap<>();

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        for(int i = 0; i < n; i++){
            Long A_i = sc.nextLong();
            if(map.containsKey(A_i)){
                map.replace(A_i, map.get(A_i) + 1);
            }else {
                map.put(A_i,(long)1);
            }
        }

        int q = sc.nextInt();
        long ans = 0;

        for(int j = 0; j < q; j++){

            if(j == 0) {//一回目だけ
                for (Map.Entry<Long, Long> entry : map.entrySet()) {
                    ans += entry.getKey() * entry.getValue();
                }
            }

            long b = sc.nextInt();
            long c = sc.nextInt();

            if(map.containsKey(b)){

                ans -= b * map.get(b);

                if(map.containsKey(c)){
                    //cの方にbの個数をたす
                    map.replace(c,map.get(c) + map.get(b));
                    ans += c * map.get(b);
                    map.remove(b);

                }else {
                    //新しくcを生成してbの方に移す
                    map.put(c,map.get(b));
                    ans += c * map.get(b);
                    map.remove(b);
                }
            }

            System.out.println(ans);
        }

    }
}


Measured memory_bytes: 77784
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Main {

    private static Scanner sc;

    public static void main(String[] args) {
        Main instance = new Main();
        sc = instance.new Scanner();
        instance.solve();
    }

    private void solve() {
        try {
          int a = sc.nextInt();
          int b = sc.nextInt();
          int c = sc.nextInt();
          if (a == b && a == c) {
            System.out.println(1);
          } else if (a != b && a != c && b != c) {
            System.out.println(3);
          } else {
            System.out.println(2);
          }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private class Scanner {
        String[] s;
        int i;
        BufferedReader br;
        String regex = " ";

        public Scanner() {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        @Override
        protected void finalize() throws Throwable {
            try {
                super.finalize();
            } finally {
                destruction();
            }
        }

        private void destruction() throws IOException {
            if (br != null) br.close();
        }

        public String next() throws IOException {
            if (i < s.length) return s[i++];
            String st = br.readLine();
            while (st == "") st = br.readLine();
            s = st.split(regex, 0);
            i = 0;
            return s[i++];
        }

        public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        }

        public Long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(next());
        }

        public Double nextDouble() throws NumberFormatException, IOException {
            return Double.parseDouble(next());
        }
    }
}



Measured memory_bytes: 8148
#include <iostream>
#include <vector>
#include <algorithm>

int main() {
    long long d, g, ret = 100000000000;
    std::cin >> d >> g;
    std::vector<long long> p(d), c(d);
    for (auto i = 0; i < d; i++) {
        std::cin >> p[i] >> c[i];
    }

    std::vector<int> v(d);
    for (auto i = 0; i < d; i++) v[i] = i;

    do {
        auto h = g, l = 0ll;
        for (auto i = 0; i < d; i++) {
            if (p[v[i]] * 100 * (v[i] + 1) >= h) {
                l += (h / (100 * v[i] + 100) + (h % (100 * v[i] + 100)));
                break;
            } else if (p[v[i]] * 100 * (v[i] + 1) + c[v[i]] >= h) {
                l += p[v[i]];
                break;
            } else {
                h -= (p[v[i]] * 100 * (v[i] + 1) + c[v[i]]);
                l += p[v[i]];
            }
        }
        if (ret > l) {
            ret = l;
        }
    } while (std::next_permutation(v.begin(), v.end()));

    std::cout << ret << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

const long double PI = (acos(-1));

int main(void){
    long double a, b, x;
    cin >> a >> b >> x;

    long double ans;
    long double mid = (a * a * b) / 2.0;

    if(x <= mid)
        ans = PI / 2.0 - atan((2.0 * x) / (a * b * b));
    else
        ans = atan(2.0 * (a * a * b - x) / (a * a * a));

    cout << setprecision(10) << ans * 180.0 / PI << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <queue>
#include <vector>
#include <functional>
#include <algorithm>
#include <map>

using namespace std;

#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)

typedef long long ll;	
typedef pair<int,int> pii;
typedef pair<ll,int> plli;
#define MP make_pair
	
int main(){
	int m,n,k;
	scanf("%d%d%d",&m,&n,&k);
	map<int,vector<pii>> xi;
	map<int,vector<pii>> yi;
	int si=k*2,gi=k*2+1;
	REP(i,k){
		int x,y;
		scanf("%d%d",&x,&y);
		xi[x].push_back(MP(y,i*2));
		yi[y].push_back(MP(x,i*2+1));
		if(x==1&&y==1)
			si=i*2;
		if(x==m&&y==n)
			gi=i*2;
	}
	if(si==k*2)
		xi[1].push_back(MP(1,si));
	if(gi==k*2+1){
		xi[m].push_back(MP(n,gi));
		yi[n].push_back(MP(m,gi+1));
	}
	static vector<pii> graph[500000];
	for(auto& _xs:xi){
		auto& xs = _xs.second;
		sort(xs.begin(),xs.end());
		REP(i,xs.size()-1){
			graph[xs[i].second].push_back(MP(xs[i+1].first-xs[i].first,xs[i+1].second));
			graph[xs[i+1].second].push_back(MP(xs[i+1].first-xs[i].first,xs[i].second));
		}
	}
	for(auto& _ys:yi){
		auto& ys=_ys.second;
		sort(ys.begin(),ys.end());
		REP(i,ys.size()-1){
			graph[ys[i].second].push_back(MP(ys[i+1].first-ys[i].first,ys[i+1].second));
			graph[ys[i+1].second].push_back(MP(ys[i+1].first-ys[i].first,ys[i].second));
		}
	}
	REP(i,k){
		graph[i*2].push_back(MP(1,i*2+1));
		graph[i*2+1].push_back(MP(1,i*2));
	}
	priority_queue<plli,vector<plli>,greater<plli>> pq;
	pq.push(MP(0,si));
	ll ans=-1;
	static ll nc[500000];
	REP(i,k*2+3)
		nc[i]=1145141919810893LL;
	while(!pq.empty()){
		plli t=pq.top();
		pq.pop();
		if(t.first>nc[t.second])
			continue;
		if(t.second==gi||t.second==gi+1){
			ans=t.first;
			break;
		}
		for(auto c:graph[t.second])
			if(t.first+c.first<nc[c.second]){
				nc[c.second]=t.first+c.first;
				pq.push(MP(t.first+c.first,c.second));
			}
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 53736
def main():
    N = int(input())
    Up = list(map(int,input().split()))
    Down = list(map(int,input().split()))
    ans = 0
    for i in range(N):
        tmp = sum(Up[:i+1]) + sum(Down[i:])
        ans = max(ans,tmp)
    
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3188
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int n,m,f;
string u[333];
int main(void){
  cin >> n;
  for(int i = 0; i < n; i++) cin >> u[i];
  cin >> m;
  for(int i = 0; i < m; i++){
    string k;
    cin >> k;
    int j;
    for(j = 0; j < n; j++) if(k == u[j]) break;
    if(n-j){
      cout <<(f?"Closed":"Opened") << " by " << k << endl;
      f^=1;
    }else{
      cout << "Unknown " << k << endl;
    }
  }
}

Measured memory_bytes: 1216
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i,j,k;
  int n;
  while(cin>>n&&n){
    int a[50][30];
    memset(a,0,sizeof(a));
    for(i=0;i<n;i++){
      int p;
      cin>>p;
      for(j=0;j<p;j++){
	int q;
	cin>>q;
	q--;
	a[i][q]=1;
      }
    }
    int b[50][50];
    memset(b,0,sizeof(b));
    for(i=0;i<n;i++)
      b[i][i]=1;
    for(i=0;i<30;i++){
      int c[50];
      memset(c,0,sizeof(c));
      for(j=0;j<n;j++){
	if(a[j][i]){
	  for(k=0;k<n;k++)
	    c[k]|=b[j][k];
	}
      }
      for(j=0;j<n;j++){
	if(c[j]==0)
	  break;
      }
      if(j==n)
	break;
      for(j=0;j<n;j++){
	if(a[j][i]){
	  for(k=0;k<n;k++)
	    b[j][k]=c[k];
	}
      }
    }
    if(i==30)
      cout<<-1<<endl;
    else
      cout<<i+1<<endl;
  }
  return 0;
}

Measured memory_bytes: 884
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) { a = b; return 1; }
  return 0; }
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) { a = b; return 1; }
  return 0; }

ll MOD = 1000000007;

int main(void){
  int mx = 100;
  int n; cin >> n;
  vector<int> f;
  rep(i,10005){
    f.push_back(0);
  }
  for(int i = 1; i <= 100; i++){
    for(int j = 1; j <= 100; j++){
      for(int k = 1; k <= 100; k++){
        if(i*i+j*j+k*k+i*j+j*k+k*i > 10000) continue;
        f[i*i+j*j+k*k+i*j+j*k+k*i]++;
      }
    }
  }
  for(int i = 1; i <= n; i++){
    cout << f.at(i) << endl;
  }
  return 0;
}


Measured memory_bytes: 3696
#include <bits/stdc++.h>
using namespace std;
 
int main() {

    int  s,s1,s2,s3,ans;
    
        cin >> s;
        s1 = s / 100;
        s2 = (s - s1*100) / 10;
        s3 = (s - s1*100 - s2*10);

    //cout << s1 << "," << s2 << "," << s3 << endl;

        ans = s1 + s2 + s3;
        cout << ans << endl;
   
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
int main(){
	string str;
	while(1){
		int flg=0;
		char NOW='A';
		cin >> str;
		if(str=="#")break;
		for(int i=0; i<str.size() && flg==0 ; i++){
			if(str[i]=='0'){
				if(NOW=='A') NOW='X';
				else if(NOW=='X') flg=1;
				else if(NOW=='Z') NOW='W';
				else if(NOW=='B') NOW='Y';
				else if(NOW=='W') NOW='B';
				else NOW='X';
			}else{
				if(NOW=='A') NOW='Y';
				else if(NOW=='X') NOW='Z';
				else if(NOW=='Z') NOW='B';
				else if(NOW=='B') NOW='X';
				else if(NOW=='W') NOW='Y';
				else flg=1;
			}
		}
		if(flg==1 || NOW!='B') cout << "No" << endl;
		else cout << "Yes" << endl;
	}
}

Measured memory_bytes: 1180
#define watch5(a,b,c,d,e) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d << " | "<<#e<<": "<<e<<endl;
#define watch4(a,b,c,d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define watch3(a,b,c) cerr <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<endl;
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define sharingan cerr << "\n-------------------------------------------\n\n";
#define watch2(a,b) cerr <<#a<<": "<<a<<" | "<<#b<<": "<<b<< endl;
#define slow ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define watch(a) cerr <<#a<<": "<<a<<endl;
#define set_bits(x) __builtin_popcount(x)
#define __gcd(a, b) __algo_gcd(a, b)
#define PI 3.14159265358979323846
#define mod 1000000007

#include"bits/stdc++.h"
using namespace std;

#define int long long

int n, m;
int sx, sy;
int fx, fy;
int vis[1001][1001];
int ans[1001][1001];
string ar[1001];

int dx[4] = {0, 1, -1, 0};
int dy[4] = {-1, 0, 0, 1};

int can( int x, int y ){
    if( x < n && y < m && x >= 0 && y >= 0 )return 1;
    return 0;
}

int go(){
    priority_queue< pair<int, pair<int,int> >, vector< pair<int, pair<int,int> > > , greater< pair<int, pair<int,int> > > > q;
    q.push(make_pair(0, make_pair(sx, sy)));
    ans[sx][sy] = 0;
    while( !q.empty() ){
        pair<int, pair<int,int> > temp = q.top();
        q.pop();
        int val = temp.first;
        int X = temp.second.first;
        int Y = temp.second.second;
        for( int i = 0; i < 4; i++ ){
            int XX = X + dx[i];
            int YY = Y + dy[i];
            if( can(XX, YY) && ar[XX][YY] == '.' && ans[XX][YY] > ans[X][Y] ){
                q.push(make_pair(ans[X][Y], make_pair(XX, YY)));
                ans[XX][YY] = ans[X][Y];
                //watch3(XX, YY, ans[XX][YY]);
            }
        }
        for( int i = X - 2; i <= X + 2; i++ ){
            for( int j = Y-2; j <= Y+2; j++ ){
                int XX = i;
                int YY = j;
                if( can(XX, YY) && ar[XX][YY] == '.' && ans[XX][YY] > ans[X][Y]+1 ){
                    q.push(make_pair(ans[X][Y]+1, make_pair(XX, YY)));
                    ans[XX][YY] = ans[X][Y]+1;
                    //watch3(XX, YY, ans[XX][YY]);
                }
            }
        }
    }
    //watch3(fx, fy, ans[fx][fy]);
    if( ans[fx][fy] == INT_MAX )return -1;
    return ans[fx][fy];
}

int32_t main(){
    cin >> n >> m;
    for( int i = 0; i <= n; i++ ){
        for( int j = 0; j <= m; j++ ){
            ans[i][j] = INT_MAX;
        }
    }
    cin >> sx >> sy;
    cin >> fx >> fy;
    sx--; sy--;
    fx--;
    fy--;
    for( int i = 0; i < n; i++ ){
        cin >> ar[i];
    }
    cout << go();
}

Measured memory_bytes: 13564
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

int main(){
  ll n;
  
  cin>>n;
  
  ll a[n];
  ll sum=0;
  for(int i=0;i<n;i++){
    cin>>a[i];
    sum+=a[i];
  }
  
  ll m;
  cin>>m;
  
  for(int i=0;i<m;i++){
    ll p,t;
    cin>>p>>t;
    cout<<sum-a[p-1]+t<<endl;
  }
  
  return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
const int INF = 1e9;
const int EPS = 1e-9; 

int main() {
  int N;
  cin >> N;
  vector<int> H(N);
  for(int i = 0; i < N; ++i) cin >> H.at(i);
  
  int ans = 0, subcum = 0;
  for (int i = 1; i < N; ++i) {
    if (H.at(i) <= H.at(i-1)) subcum++;
    else subcum = 0;
    ans = max(ans, subcum);
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using P	  = pair<ll, ll>;
using mat = vector<vector<ll>>;
typedef string::const_iterator State;
class ParseError {};

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

constexpr ll INF = 1e16;
constexpr ll INM = 114514;
constexpr ll MOD = 1e9 + 7;
constexpr ld EPS = 1e-12;

template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}
ll powm(ll a, ll b, ll c) {
	if (b == 0)
		return 1;
	else if (b % 2 == 0) {
		ll d = powm(a, b / 2, c);
		return (d * d) % c;
	} else
		return (a * powm(a, b - 1, c)) % c;
}
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 dx[4] = {1, 0, -1, 0};
ll dy[4] = {0, 1, 0, -1};

ll dp[1002][5000];

int main() {
	IOS();
	ll n, m;
	cin >> n >> m;
	Fill(dp, INF);
	vector<ll> a(m);
	vector<ll> b(m);
	for (int i = 0; i < m; i++) {
		int size;
		cin >> a[i] >> size;
		int cx = 0;
		for (int j = 0; j < size; j++) {
			int c;
			cin >> c;
			cx += 1 << (c - 1);
		}
		b[i] = cx;
	}
	dp[0][0] = 0;
	for (int i = 0; i < m; i++) {
		for (int j = 0; j < (1 << n); j++) {
			dp[i + 1][j] = min(dp[i+ 1][j], dp[i][j]);
			dp[i + 1][j | b[i]] = min(dp[i][j] + a[i], dp[i + 1][j | b[i]]);
		}
	}
	dump(dp[m][(1 << n) - 1] < INF ? dp[m][(1 << n) - 1] : -1);
	return 0;
}

Measured memory_bytes: 39424
#include<stdio.h>
int N, M, D;
char S[110][110];
int main()
{
	int i, j, k, flg, ans;
	scanf("%d%d%d", &N, &M, &D);
	for (i = 0; i < N; ++i) {
		scanf("%s", S[i]);
	}
	ans = 0;
	for (i = 0; i < N; ++i) {
		for (j = 0; j <= M - D; ++j) {
			flg = 1; for (k = 0; k < D; ++k) {
				if (S[i][j + k] == '#') flg = 0;
			}
			if (flg == 1) ++ans;
		}
	}
	for (i = 0; i <= N - D; ++i) {
		for (j = 0; j < M; ++j) {
			flg = 1;
			for (k = 0; k < D; ++k) {
				if (S[i + k][j] == '#')
					flg = 0;
			}
			if (flg == 1) ++ans;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 2740
#include <bits/stdc++.h>
using namespace std;

int N;
vector<vector<int>> graph(222222);
vector<int> a;

vector<bool> visited(222222,false);
vector<int> dp(222222);
vector<vector<int>> hist(222222);
vector<int> ans(222222);

void DFS(int x){
	auto it=lower_bound(dp.begin(),dp.begin()+N,a[x]);
	int p=it-dp.begin();
	hist[p].push_back(a[x]);
	dp[p]=a[x];
	ans[x]=(int)(lower_bound(dp.begin(),dp.begin()+N,999999999)-dp.begin());
	for(auto t:graph[x]){
		if(!visited[t]){
			visited[t]=true;
			DFS(t);
		}
	}
	hist[p].erase(hist[p].begin()+hist[p].size()-1);
	dp[p]=hist[p][hist[p].size()-1];
}

int main(){
	cin >> N;
	for(int i=0;i<N;i++){
		int tmp;
		cin >> tmp;
		a.push_back(tmp);
	}
	for(int i=0;i<N-1;i++){
		int u,v;
		cin >> u >> v;
		u--;
		v--;
		graph[u].push_back(v);
		graph[v].push_back(u);
	}
	
	for(int i=0;i<222222;i++)dp[i]=ans[i]=999999999;
	for(int i=0;i<222222;i++)hist[i].push_back(999999999);
	
	visited[0]=true;
	DFS(0);
	
	for(int i=0;i<N;i++)cout << ans[i] << endl;
	
	return 0;
}

Measured memory_bytes: 41940
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
const int m=1e9;

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

    int t;
    //cin>>t;
    t=1;
    while(t--)
    {
        string w;
        cin>>w;
        int c[26]={0};
        for(int i=0;i<w.size();i++)
        {
            c[w[i]-97]++;
        }
        bool flag=1;
        for(int i=0;i<26;i++)
        {
            if(c[i]%2==1)
            {
                flag=0;
                break;
            }
        }
        if(flag==1)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256