akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

template<class T>
void chmin(T &a, T b)
{
	if (a > b) a = b;
}

constexpr ll INF = 1ll<<60;
ll N, W;
constexpr ll MAX_V{100010}, MAX_N{110};
ll dp[MAX_N][MAX_V];
vector<ll> w, v;

int main(int argc, char **argv)
{
	cin >> N >> W;
	w.resize(N), v.resize(N);
	for (ll i = 0; i < N; ++i) cin >> w[i] >> v[i];

	for (ll ni = 0; ni < MAX_N; ++ni) for (ll vi = 0; vi < MAX_V; ++vi) dp[ni][vi] = INF;
	dp[0][0] = 0;
	
	for (ll ni = 0; ni < N; ++ni)
	{
		for (ll vi = 0; vi < MAX_V; ++vi)
		{
			if (vi - v[ni] >= 0) chmin(dp[ni+1][vi], dp[ni][vi-v[ni]]+w[ni]);
			chmin(dp[ni+1][vi], dp[ni][vi]);
		}
	}

	ll res{0};
	for (ll v = 0; v < MAX_V; ++v)
	{
		if (dp[N][v] <= W) res = v;
	}

	std::cout << res << std::endl;
}


Measured memory_bytes: 86144
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <map>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define x first
#define y second

using namespace std;

typedef long long ll;
typedef double db;

const int N = 1e5+10,M=1e4+10,MOD = 1e9+7;

char s[N],p[N];

int main()
{
#ifdef local
    freopen("data","r",stdin);
#endif

    while(cin>>s){
        int top=0;
        p[top++]=s[0];
        p[top++]=s[1];
        int n=strlen(s);
        int cnt=0;
        for(int i=2;i<n;i++){
            if(p[top-2]==s[i])
                p[top++]=s[i];
            else{
                while(p[top-2]!=s[i]&&top>1){
                    top--;
                    cnt++;
                }
                p[top++]=s[i];
            }
        }
        if(cnt%2)puts("First");
        else puts("Second");
    }


}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()

int main(){
    int d;cin>>d;
    if(d==25)cout<<"Christmas"<<endl;
    else if(d==24)cout<<"Christmas Eve"<<endl;
    else if(d==23)cout<<"Christmas Eve Eve"<<endl;
    else if(d==22)cout<<"Christmas Eve Eve Eve"<<endl;
}

Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define _h cout<<"here"<<endl;
#define fill(a,v) memset(a,v,sizeof(a));
#define all(v) v.begin(),v.end()
#define rep(i,n) for(int i=0;i<n;i+=1)
#define prarr(a,n) rep(i,n) cout<<a[i]<<" \n"[i==n-1];// printf("%s\n"," " );
#define ff first
#define ss second
#define pu push_back
#define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)
template<typename S, typename T> 
ostream& operator<<(ostream& out,pair<S,T> const& p){out<<'('<<p.ff<<", "<<p.s<<')';return out;}
template<typename T>
ostream& operator<<(ostream& out,vector<T> const& v){
int l=v.size();for(int i=0;i<l-1;i++)out<<v[i]<<' ';if(l>0)out<<v[l-1];return out;}
template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}
template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}
const int inf = 1e9+10;
const ll INF = 1e18+10;
const int MOD = 1e9+7;
const int MAXN = 2e5+10;

void solve()
{
	int n;
	int a,b;
	cin>>a>>b;
	cout<<max({0,a-2*b})<<endl;
}
int main()
{
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// #endif
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
	// cin>>t;
	while(t--){
		solve();
	}
	return 0;

}
    

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

using namespace std;

constexpr int MOD = 1'000'000'007;

int main() {
    std::ios::sync_with_stdio(false); 
    cin.tie(nullptr);
    
    int N;
    cin >> N;
    vector<vector<int>> a(N, vector<int>(N));
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < N; ++j) {
            cin >> a[i][j];
        }
    }
    const int m = (1 << N);
    vector<int> dp(m, 0);
    dp[0] = 1;
    for (int i = 0; i < N; ++i) {
        for (int mask = m - 1; mask >= 0; --mask) {
            if (dp[mask]) {
                for (int j = 0; j < N; ++j) {
                    if (mask & (1 << j)) {
                        continue;
                    }
                    if (a[i][j]) {
                        int new_mask = mask | (1 << j);
                        dp[new_mask] = (dp[new_mask] + dp[mask]);
                        if (dp[new_mask] >= MOD) {
                            dp[new_mask] -= MOD;
                        }
                    }
                }
                dp[mask] = 0;
            }
        }
    }
    cout << dp[m - 1] << "\n";


    return 0;
}

Measured memory_bytes: 8448
#include <bits/stdc++.h>
const char nl = '\n';
using namespace std;
typedef long long ll;
typedef long double ld;
typedef complex<ld> pt;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int N = 1e4+10, D = 101;

string s;
int d;
int dp[2][D][2];

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> s >> d;
  int n = s.size();
  dp[1][0][0] = dp[1][0][1] = 1;
  for (int i = n-1; i >= 0; i--) {
    for (int r = 0; r < d; r++) {
      dp[0][r][0] = dp[0][r][1] = 0;
      for (int j = 0; j < 10; j++) {
        int nr = (r + j) % d;
        dp[0][r][1] = (dp[0][r][1] + dp[1][nr][1]) % MOD;
      }
      for (int j = 0; j < s[i]-'0'; j++) {
        int nr = (r + j) % d;
        dp[0][r][0] = (dp[0][r][0] + dp[1][nr][1]) % MOD;
      }
      int nr = (r + s[i]-'0') % d;
      dp[0][r][0] = (dp[0][r][0] + dp[1][nr][0]) % MOD;
      //cerr << i << " " << r << " -> " << dp[0][r][0] << " " << dp[0][r][1] << nl;
    }
    swap(dp[0], dp[1]);
  }
  cout << (dp[1][0][0]+MOD-1)%MOD << nl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
using namespace std;
 
#define B 317
 
typedef long long int LLI;
#define int long long int
 
typedef pair<string, int> Pair;
typedef pair<int, int> Seg;
typedef pair<Seg, pair<int,int> > Data;
 
int size;
int T;
int n;
int m;
LLI cur;
LLI ans[200005];
LLI BIT2[100005];
vector<int> list_str;
vector<int> sorted_str;
int myrank[100010];
vector<Data> queries;
 
bool cmp_query(const Data &d1, const Data &d2) {
    int l1 = d1.first.first;
    int r1 = d1.first.second;
    int l2 = d2.first.first;
    int r2 = d2.first.second;
    
    if (l1/B != l2/B) return l1/B < l2/B;
    return r1 < r2;
}
 
void update(LLI *BIT, int k, LLI x) {
  k++;
    while (k <= n) {
        BIT[k] += x;
        k += k&-k;
    }
}
 
LLI getsum(LLI *BIT, int k) {
  k++;
    LLI ret = 0;
    while (k > 0) {
        ret += BIT[k];
        k -= k&-k;
    }
    return ret;
}
 
void append_end(int x) {
    int &ss = list_str[x];
    int idx = myrank[ss];
    cur += getsum(BIT2, n-1) - getsum(BIT2, idx); // (idx,n-1]
    update(BIT2, idx, 1);
}
void append_front(int x) {
    int &ss = list_str[x];
    int idx = myrank[ss];
    cur += getsum(BIT2, idx-1);
    update(BIT2, idx, 1);
}
void remove_end(int x) {
    int &ss = list_str[x];
    int idx = myrank[ss];
    cur -= getsum(BIT2, n-1) - getsum(BIT2, idx); // (idx,n-1]
    update(BIT2, idx, -1);
}
void remove_front(int x) {
    int &ss = list_str[x];
    int idx = myrank[ss];
    cur -= getsum(BIT2,idx-1);
    update(BIT2, idx, -1);
}
 
signed main() {
    ios_base::sync_with_stdio(false);
 
    //cin >> T;
    while (1) {
        cin >> n;
        size = 1;
        fill(BIT2, BIT2+n+1, 0ll);
 
        list_str.clear();
        sorted_str.clear();
        for (int i=0; i<n; i++) {
          int s;
          cin >> s;
          list_str.push_back(s);
          sorted_str.push_back(s);
        }
        sort(sorted_str.begin(), sorted_str.end());
        for (int i=0; i<n; i++) {
            myrank[sorted_str[i]] = i;
        }
 
        queries.clear();
        cin >> m;
        for(int j = 0 ; j < m ; j++){
            int l, r,k;
            cin >> l >> r;
            --l;
            --r;
            queries.push_back(Data(Seg(l, r), {j,j}));
      }
      
        sort(queries.begin(), queries.end(), cmp_query);
        cur = 0;
        int a = 0;
        int b = -1;
        for (int i=0; i<queries.size(); i++) {
            int l = queries[i].first.first;
            int r = queries[i].first.second;
            int idx = queries[i].second.second;
            int k = queries[i].second.first;
            while (b < r) append_end(++b);
            while (l < a) append_front(--a);
            while (a < l) remove_front(a++);
            while (r < b) remove_end(b--);
            ans[idx] = cur;
        }
 
        for (int i=0; i<m; i++) {
            cout << ans[i] << endl;
        }
        break;
    }
}  

Measured memory_bytes: 14412
#pragma GCC optimize("Ofast","unroll-loops")
#pragma GCC target("avx2,fma")
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (__typeof(a) i=(a); i<(b); ++i)
#define iter(it,c) for (__typeof((c).begin()) \
  it = (c).begin(); it != (c).end(); ++it)
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long ll;
const int INF = ~(1<<31);

const double EPS = 1e-9;
const double pi = acos(-1);
typedef unsigned long long ull;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
template <class T> T smod(T a, T b) {
  return (a % b + b) % b; }

vi A[3];
int n;
int memo[4][100050];

int dp(int at, int l) {
  if(at > n-1) return 0;
  if(memo[l][at] != -1) return memo[l][at];
  int bst = 0;
  if(l != 0) bst = max(bst, dp(at+1,0)+A[0][at]);
  if(l != 1) bst = max(bst, dp(at+1,1)+A[1][at]);
  if(l != 2) bst = max(bst, dp(at+1,2)+A[2][at]);
  return memo[l][at] = bst; 
}

int main() {
  cin >> n;
  memset(memo, -1, sizeof(memo));
  A[0] = vi(n);
  A[1] = vi(n);
  A[2] = vi(n);
  rep(i,0,n){
    rep(j,0,3){
      cin >> A[j][i];
    }
  }
  cout << dp(0, 3) << endl;
  return 0;
}

Measured memory_bytes: 9216
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, j, n) for(int i=j;i<n;++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
#define LINF 1e18
const int mod = 1e9 + 7;
 
typedef long long i64;
typedef pair<int, int> pi;
 
template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;
 
i64 gcd(i64 n, i64 m) {return (m == 0? n : gcd(m, n % m));}
i64 lcm(i64 n, i64 m) {return (n / gcd(n, m) * m);}
int dx[] = {0, -1, 0, 1, 1, 1, -1, -1};
int dy[] = {-1, 0, 1, 0, 1, -1, 1, -1};

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

  int n, m, k;
  cin >> n >> m >> k;
  rep(i, 0, n + 1) {
    rep(j, 0, m + 1) {
      if(i * (m - j) + j * (n - i) == k) return cout << "Yes\n", 0;
    }
  }
  cout << "No\n";
}


Measured memory_bytes: 256
N, W = map(int, input().split())
L = [list(map(int, input().split())) for i in range(N)]
V = 0
for i in range(N):
  V += L[i][1]

dp = [[10**9+1] * (V + 1) for i in range(N+1)]
dp[0][0] = 0
for i in range(N):
    for j in range(V+1):
        if j - L[i][1] >= 0:
          dp[i+1][j] = min(dp[i][j], dp[i][j-L[i][1]] + L[i][0])
        else:
          dp[i+1][j] = dp[i][j]
ans = 0
for j in range(V+1):
    if  W >= dp[-1][j]:
        ans = max(ans, j)
print(ans)

Measured memory_bytes: 119916
#include<stdio.h>
int main(){
	long long A,B,C,X,Y;
	scanf("%ld%ld%ld%ld%ld",&A,&B,&C,&X,&Y);
	long long cc=0;
	while(cc<X||cc<Y)cc++;
    long long money=cc*C*2;
	for(;cc>=0;cc--){
		long long sub=0;
		if(X>cc)sub+=(X-cc)*A;
		if(Y>cc)sub+=(Y-cc)*B;
		if(money<sub+cc*C*2)break;
		money=sub+cc*C*2;
	}
	printf("%ld\n",money);
}


Measured memory_bytes: 1732
#include "bits/stdc++.h"
using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
ld EPS = 1e-12;
int INF = numeric_limits<int>::max() / 2;
ll LINF = numeric_limits<ll>::max() / 2;
int MOD = 1e9 + 7;
#define rep(i,n) for(int i = 0; i < n; i++)
#define all(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ": " << x << '\n'

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    bool a = false;
    bool b = false;
    bool c = false;
    rep(i,3){
        char l;
        cin >> l;
        if(l == 'a') a = true;
        else if(l == 'b') b = true;
        else if(l == 'c') c = true;
    }
    cout << (a&&b&&c ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stack>
#include <algorithm>
#include <numeric>
#include <unordered_map>
#include <cmath>
#include <iomanip>

using namespace std;


int main() {
    int H, N;
    cin >> H >> N;

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

    vector<int> dp(H+10, std::numeric_limits<int>::max());
    dp[0]=0;
    for(int hp=1; hp<=H; hp++){
        for(int i=0; i<N; i++){
            int tmp = hp-A[i]>=0 ? hp-A[i] : 0;
            dp[hp] = min(dp[hp], dp[tmp]+B[i]);
        }
    }

    cout << dp[H] << endl;


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end())
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 25000001;
ll n, a[2][3], DP[N];
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  FOR(i, 0, 2)FOR(j, 0, 3) cin >> a[i][j];
  FOR(i, 0, 2){
    FOR(j, 0, 3){
      ll c = a[0][j], d = a[1][j]-a[0][j];
      if(d<=0) continue;
      FOR(k, 0, n-c+1) maxs(DP[k+c], DP[k]+d);
    }
    ll ma = DP[n];
    fill(DP, DP+n+1, 0);
    n += ma;
    swap(a[0], a[1]);
  }
  cout << n << endl;
}

Measured memory_bytes: 195584
#include<iostream>
#include <climits>
#include<vector>
#include<list>
#include<numeric>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>
#include<map>
#include<stack>
#include<queue>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;

int partition(vector<int> &A, int p, int r) {
	int x = A[r];
	int i = p - 1;
	for (int j = p;j < r;j++) {
		if (A[j] <= x) {
			i++;
			int tmp = A[i];
			A[i] = A[j];
			A[j] = tmp;
		}
	}
	int tmp = A[i + 1];
	A[i + 1] = A[r];
	A[r] = tmp;
	return i + 1;
}

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

	int n;
	cin >> n;
	vector<int> A(n);
	REP(i, n) cin >> A[i];
	int q = partition(A, 0, n - 1);
	REP(i, n) {
		if (i < n - 1) {
			if (i == q) cout << "[" << A[i] << "]" << " ";
			else cout << A[i] << " ";
		}
		else cout << A[i] << "\n";
	}

	return 0;
}


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

#define REPI(i, n) for(int i = 0; i < n; i++)
#define REPJ(j, n) for(int j = 0; j < n; j++)

using ll = long long;
using namespace std;

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

    ll n; cin >> n;
    ll ans = 0, large = 0;

    for(ll i = 2; i * i <= n; i++)
        if(n % i == 0) ans = max(i, large);
    cout << (ans != 0 ? ((ans - 1) + (n / ans - 1)) : n - 1);
}


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

int main() {
    long long N;
    cin >> N;

    long long ans = 1001001001001;
    for (long long i = 1; i * i <= N; i++) {
        if (N % i != 0) continue;
        long long j = N / i;
        ans = min(ans, i + j - 2);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    int N,T;
    cin >> N >> T;
    vector<int> t(N+1);
    rep(i,N){
        cin >> t[i];
    }
    int remain_t;
    int j = 0;
    ll ans = 0;
    rep(i,t[N-1]+T+1){
        if(i==t[j]){
            remain_t = T;
            j++;
        }
        if(remain_t>0){
            if(t[j]==0){
                ans+=remain_t;
                break;
            }
            if(i+remain_t>=t[j]){
                ans+=t[j]-i;
            }else{
                ans+=remain_t;
            }
            i=t[j]-1;
            remain_t = 0;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<cmath>
#include<queue>
#include<limits>
#include<cassert>
#include<set>
#include<tuple>
#include<map>

#define PB push_back
#define ALL(a)  (a).begin(),(a).end()
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

using namespace std;
typedef long long ll;

int main()
{
	ll n;
	cin >> n;
	vector<ll> a(n);
	ll X = 0, x = 0, ans = 100000000000LL;
	REP(i, n) {
		cin >> a[i];
		X += a[i]; //カードの総数
	}
	REP(i, n) {
		x += a[i]; //取るカードの総数
		if(i + 1 < n) ans = min(ans, abs(X - 2 * x)); //最低一つは残す
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <string>
#include <cmath>
#include <queue>
typedef long long ll;

using namespace std;

int main(){

    string s;

    cin >> s;

    queue<ll> que;

    vector<bool > t;

    int one = 0;
    int zero = 0;

    for(int i = 0; i < s.length(); i++){
        //que.push(atoi(s.substr(i,1).c_str()));
        if(s.substr(i,1) == "0"){
            zero++;
        }else{
            one++;
        }
    }   
    int total = 0;

    if((zero == 0 && one == 1) || (zero == 1 && one == 1)){
        cout << "0" << endl;
        return 0;
    }

    if(zero == 1 && one == 1){
        cout << "2" << endl;
        return 0;
    }

    if(zero > one){
        total = one * 2;
    }else{
        total = zero * 2;
    }

    cout << total << endl;

}

Measured memory_bytes: 512
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
ans = 0
for i in range(n):
  a = list(map(int, input().split()))
  delta = 0
  for j in range(m):
    delta += a[j]*b[j]
  delta += c
  if delta > 0:
    ans += 1
  else:
    continue
print(ans)

Measured memory_bytes: 9160
#include <algorithm>
#include <iostream>
using namespace std;
static const int MAX = 41;
int measure[MAX];
struct node {
  node *left;
  node *right;
  int key;
};

node *root = NULL;

void insert(int key) {
  node *nd = (node *)malloc(sizeof(node));
  nd->key = key;
  nd->left = NULL;
  nd->right = NULL;

  if (root == NULL) {
    root = nd;
    return;
  }

  node *x = root;
  while (1) {
    if (measure[x->key] < measure[nd->key]) {
      if (x->right == NULL) {
        x->right = nd;
        break;
      } else {
        x = x->right;
      }
    } else {
      if (x->left == NULL) {
        x->left = nd;
        break;
      } else {
        x = x->left;
      }
    }
  }
}

int buf[MAX];
int bufp =0;
void walk(node *n) {
  if (!n)
    return;
  walk(n->left);
  walk(n->right);
  buf[bufp++] = n->key;
}

int main() {
  int keys[MAX];
  int n, idx;
  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> keys[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> idx;
    measure[idx] = i;
  }

  for (int i = 0; i < n; i++) {
    insert(keys[i]);
  }

  walk(root);
  cout << buf[0];
  for (int i=1; i<n; i++) {
    cout << " " << buf[i];
  }
  cout << endl;
}

Measured memory_bytes: 3100
/**
 *   @FileName	c.cpp
 *   @Author	kanpurin
 *   @Created	2020.05.17 21:32:37
**/

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

int main() {
    const double PI = 3.14159265358979;
    int a,b,h,m;cin >> a >> b >> h >> m;
    double kaku1 = double(h*60+m)/1440*4*PI;
    double kaku2 = double(m)/60*2*PI;
    //cout << kaku1 << " " << cos(kaku1) << " " << sin(kaku1) << endl;
    double p = (a*cos(kaku1)-b*cos(kaku2));
    double q = (a*sin(kaku1)-b*sin(kaku2));
    //cout << p << " " << q << endl;
    //cout << p*p+q*q << endl;
    printf("%.10f\n",sqrt(p*p+q*q));
    return 0;
}

Measured memory_bytes: 4064
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;

int main() {
  string s; cin >> s;
  bool y = false, yy = false;
  if (1 <= stoi(s.substr(0, 2)) && stoi(s.substr(0, 2)) <= 12)
    y = true;
  if (1 <= stoi(s.substr(2, 4)) && stoi(s.substr(2, 4)) <= 12)
    yy = true;
  if (y && yy) cout << "AMBIGUOUS" << endl;
  else if (y) cout << "MMYY" << endl;
  else if (yy) cout << "YYMM" << endl;
  else cout << "NA" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdio.h>
int compare(const void *a,const void *b){
    if(*(long long*)a>*(long long*)b)return 1;
    return -1;
}
int main()
{   int um=0,dm=0;
    char s[5];
    scanf("%s",s);
    if((s[0]=='1'&&(s[1]=='0'||s[1]=='1'||s[1]=='2'))||(s[0]=='0'&&s[1]!='0'))um=1;
if((s[2]=='1'&&(s[3]=='0'||s[3]=='1'||s[3]=='2'))||(s[2]=='0'&&s[3]!='0'))dm=1;
if(um==1&&dm==1)printf("AMBIGUOUS");else if(um==1)printf("MMYY");
else if(dm==1)printf("YYMM");else printf("NA");
    
    return 0;
}


Measured memory_bytes: 128
K, N = map(int, input().split())
A = list(map(int, input().split()))
ans = 10 ** 9
mx = max(A)
mi = min(A)
tmp = mx - mi
ans = tmp
for i in range(N):
    A.append(A[i]+K)

# ここから連続するNの部分の最小幅を出す

for i in range(N):
    tmp += A[i+N] - A[i+N-1]
    tmp -= A[i+1] - A[i]
    ans = min(ans, tmp)

print(ans)


Measured memory_bytes: 92748
#include <bits/stdc++.h>
using namespace std;
typedef __int128_t i128;
typedef long long i64;
#ifdef DEBUG
#define FPEN freopen("in.txt", "r", stdin);
#define FPEN2 freopen("out.txt", "w", stdout);
#else
#define FPEN
#define FPEN2
#endif
#define Sz(a) ((int)(a).size())
const int maxn = 200009;
const int MOD = 1e9 + 7;
int main(){
  FPEN;
  ios_base::sync_with_stdio(false);cout.tie(0);cin.tie(0);
  int n;cin>>n;
  vector<int> a(n),b(n);
  for(int i=0;i<n;++i)cin>>a[i]>>b[i];
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  if(n&1){
    cout<<b[n/2]-a[n/2]+1<<'\n';
  }else{
    cout<<(b[n/2]+b[n/2-1])-(a[n/2]+a[n/2-1])+1<<'\n';
  }
  
  return 0;
}
//2020.05.31 20:23:15


Measured memory_bytes: 4784
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
// const long double PI = acos(-1);
constexpr int inf = 1e9;
constexpr ll INF = 2e18;
// constexpr ll MOD = 1e9+7;
constexpr ll MOD = 998244353;

ll n,k;
ll a[1<<19];
bool inque[1<<19];
ll table[1<<19][100];
ll pre[1<<19];

void input() {
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
}

void make_table() {

    for (int i = n * 2 - 1; i >= 0; i--) {
        table[i%n][0] = pre[a[i%n]] - i + 1;
        pre[a[i%n]] = i;
    }

    for (int i = 1; i < 66; i++) {
        for (int j = 0; j < n; j++) {
            table[j][i] = table[j][i-1] + table[(table[j][i-1] + j) % n][i-1];
            table[j][i] = min(table[j][i], (1LL << 61));
        }
    }

}

void solve() {
    make_table();
    ll pos = 0;
    ll left = n * k;
    // for (int i = 0; i < 64; i++) {
    //     for (int j = 0; j < n; j++) {
    //         cout << table[j][i] << " ";
    //     }
    //     cout << endl;
    // }
    for (int i = 65; i >= 0; i--) {
        if (left >= table[pos][i]) {
            left -= table[pos][i];
            pos += table[pos][i];
            pos %= n;
        }
    }

    vector<int> v;
    while (left--) {
        if (!inque[a[pos]]) {
            v.push_back(a[pos]);
            inque[a[pos]] = 1;
        } else {
            while (inque[a[pos]]) {
                inque[v[v.size() - 1]] = 0;
                v.pop_back();
            }
        }
        pos++;
        pos %= n;
    }

    for (int i = 0; i < v.size(); i++) {
        cout << v[i] << " \n"[i == v.size() - 1];
    }
}

int main(int argc, char *argv[]) {
    input();
    solve();
    return 0;
}


Measured memory_bytes: 165748
#include <iostream>
#include <vector>
#include <algorithm>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <functional>
#include <map>
#include <set>
#include <cmath>
using namespace std;

#define INT_MAX 2147483647
#define ll long long

#define MOD 1000000007

ll max(ll a, ll b) { return (a < b) ? b : a; }


// DP !!
int main() {
    int n;
    cin >> n;

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

    vector<vector<ll>> dp(n);
    for (int i = 0; i < n; i++) {
        dp[i].resize(n);
    }

    for (int i = 0; i < n; i++) {
        dp[i][i] = a[i];
    }

    for (int i = 0; i < n - 1; i++) {
        for (int j = 0; j < n - i - 1; j++) {
            int f = j, l = j + i + 1;
            dp[f][l] = max(a[f] - dp[f + 1][l], a[l] - dp[f][l - 1]);
        }
    }

    cout << dp[0][n - 1] << endl;

    return 0;
}

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define ALL(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1e15;

int main() {
  ll n, p;
  cin >> n >> p;
  string s;
  cin >> s;

  ll ans = 0;
  map<ll, ll> mp;
  if (p == 2 || p == 5) {
    REPR(i, n - 1) {
      ll now = s[i] - '0';
      if (now % p == 0) {
        ans += i + 1;
      }
    }
  } else {
    ll prev, next;
    prev = 0;
    mp[0]++;
    ll d = 1;
    REPR(i, n - 1) {
      next = prev + (s[i] - '0') * d;
      ans += mp[next % p];
      mp[next % p]++;
      prev = next;
      d *= 10;
      d %= p;
    }
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1028
// -*- coding:utf-8-unix -*-

use proconio::input;
use rand::Rng;

pub fn get_time() -> f64 {
    static mut STIME: f64 = -1.0;
    let t = std::time::SystemTime::now()
        .duration_since(std::time::UNIX_EPOCH)
        .unwrap();
    let ms = t.as_secs() as f64 + t.subsec_nanos() as f64 * 1e-9;
    unsafe {
        if STIME < 0.0 {
            STIME = ms;
        }
        ms - STIME
    }
}

fn calclate_score(D: usize, s: &Vec<Vec<isize>>, c: &Vec<isize>, out: &Vec<usize>) -> isize {
    let mut sat = 0;
    let mut last = vec![0; 26];
    for d in 0..D {
        assert!(0 <= out[d] && out[d] <= 25);
        let j = out[d as usize] as usize;
        last[j] = d + 1;
        for i in 0..26 as usize {
            sat -= (d + 1 - last[i]) as isize * c[i];
        }
        sat += s[d][j];
    }
    sat
}

fn main() {
    input! {
        D: usize,
        c: [isize; 26],
        s: [[isize; 26]; D],
    }
    let mut out = vec![0 as usize; D];
    for i in 0..D {
        let mut max = 0;
        for j in 0..26 {
            max = if s[i][max] < s[i][j] { j } else { max };
        }
        out[i] = max;
    }
    let mut rng = rand::thread_rng();
    let mut max_score = -1000000000;
    while get_time() < 1.9 {
        let d: usize = rng.gen_range(0, D);
        let q: usize = rng.gen_range(0, 26);
        let old = out[d];
        out[d] = q;
        if max_score < calclate_score(D, &s, &c, &out) {
            max_score = calclate_score(D, &s, &c, &out);
        } else {
            out[d] = old;
        }
    }
    for x in out {
        println!("{}", x + 1);
    }
    eprintln!("{}", max_score);
}


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

using namespace std;

using Int = long long;
using P = pair<int, int>;

const long long MOD = 1e9 + 7;
const int INF = 1e9;
const double EPS = 1e-9;

int main() {
  string S;
  cin >> S;
  string ans = "NO";
  if (S.front() != 'k') {
    if (S.substr(S.size() - 7, 7) == "keyence") ans = "YES";
  }
  else if (S.back() != 'e') {
    if (S.substr(0, 7) == "keyence") ans = "YES";
  }
  else {
    for (int i = 1; i <= 7; ++i) {
      if (S.substr(0, i) + S.substr(S.size() - (7 - i), 7 - i) == "keyence") ans = "YES";
    }
  }
  cout << ans << endl;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, m, c;
  cin >> n >> m >> c;
  vll b(m);
  for (int i = 0; i < m; i++)
    cin >> b[i];
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    vll a(m);
    for (int j = 0; j < m; j++)
      cin >> a[j];
    ll sum = c;
    for (int j = 0; j < m; j++)
      sum += a[j] * b[j];
    if (sum > 0)
      ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;
const int mod = 1e9+7;

ll solve(int h, int w) {
    ll mn;
    if (h % 3 == 0) return 0;
    else mn = w;
    if (w % 2 == 0) {
        for (ll x = 1; x <= h-1; x++) {
            mn = min(mn,abs(w*x-(h-x)*(w/2)));
        }
    }
    else {
        for (ll x = 1; x <= h-1; x++) {
            ll s1 = w*x;
            ll s2 = (w/2)*(h-x);
            ll s3 = ((w+1)/2)*(h-x);
            mn = min(mn,max({s1,s2,s3})-min({s1,s2,s3}));
        }
    }
    return mn;
}

int main() {
    int h, w; cin >> h >> w;
    ll mn = inf_l;
    mn = min(mn,solve(h,w));
    swap(h,w);
    mn = min(mn,solve(h,w));
    cout << mn << endl;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(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; }

const long long INF = 1LL << 60;

int n;
long long h[100010];

long long dp[100010];

int main() {
  cin >> n;
  rep(i,n) cin >> h[i];
  rep(i,100010) dp[i] = INF;
  dp[0] = 0;
  for(int i = 0;i < n;i++) {
    chmin(dp[i+1],dp[i] + abs(h[i+1] - h[i]));
    chmin(dp[i+2],dp[i] + abs(h[i+2] - h[i]));
  }
  cout << dp[n-1] << endl;
}


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

const int64 mod = 1e9+7;

int main(void){
	int64 N;
	int64 A, B, C, D;
	cin >> N >> A >> B >> C >> D;
	REP(i, N){
		if(-D*(N-i-1)+C*i <= B-A && B-A <= -C*(N-i-1)+D*i){
			cout << "YES" << endl;
			return 0;
		}
	}
	cout << "NO" << endl;

}

Measured memory_bytes: 256
#include <iostream>
const int MAX = 50001;
using namespace std;

bool p[MAX];

void f(){
    for(int i=0 ; i<MAX ; i++){
        p[i] = (i<=1)? false : true ;
    }
    for(int i=2 ; i<=MAX ; i++){
        if( p[i] ){
            for(int j=i*2 ; j<MAX ; j+=i){
                p[j] = false;
            }
        }
    }
}

int main(){
    int n;

    f();
    while( cin >> n , n ){
		int ans = 0;
		//if( n > 3 && n%2 == 0){
			for(int i=2 ; i <= n/2 ; ++i ){
				if( p[i] && p[n - i]){
					//cout << n << " = " << p_[i] << " + " << n - p_[i] << endl;
					ans++;
				}
			}
		//}
		cout << ans << endl;
    }
}

Measured memory_bytes: 916
/***** author :  C0d1ngPhenomena *****/

    #include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define endl "\n"
    #define ll long long int
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define f first
    #define s second
    #define pb push_back
    
    using namespace std;
    int main()
    {
        std::ios::sync_with_stdio(false);
        cin.tie(NULL);
  		char arr1[1000000];
  		char arr2[1000000];
  		cin >>arr1>>arr2;
  		ll sum = 0;
  		for (int i = 0; i < strlen(arr1); ++i)
  		{
  			if(arr1[i] != arr2[i])
  				sum++;
  		}

  		cout << sum;
        return 0;
    }


Measured memory_bytes: 4044
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<string,int>;
const double PI = acos(-1);

int main() {
int n,k;
cin >> n >> k;
vector<int> a(n); 
rep(i,n) cin>> a.at(i);
sort(a.begin(),a.end());

int ans = 1000000000;
rep(i,a.size()-k+1){
  ans = min(a.at(i+k-1)-a.at(i),ans); 
}
cout << ans <<  endl;
}


Measured memory_bytes: 3768
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    s = int(readline())
    d = dict()
    d[s] = 1

    def solve():
        cur = s
        i = 1

        while True:
            i += 1
            if cur % 2 == 0:
                cur //= 2
            else:
                cur = 3 * cur + 1
            if d.get(cur):
                return i
            else:
                d[cur] = i

    print(solve())

if __name__ == '__main__':
    main()


Measured memory_bytes: 61852
require 'pp'
x,y = gets.split.map(&:to_i)
sum = 0
sum += 300000 if x == 1
sum += 300000 if y == 1
sum += 200000 if x == 2
sum += 200000 if y == 2
sum += 100000 if x == 3
sum += 100000 if y == 3
sum += 400000 if x == 1 && y == 1
p sum


Measured memory_bytes: 4092
// 見せてやるぜ、奇跡ってやつをよぉ……
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m; cin >> n >> m;
    string s; cin >> s;
    vvll edges(n);
    REP(i, m) {
        ll a, b; cin >> a >> b;
        edges[a - 1].push_back(b - 1);
        edges[b - 1].push_back(a - 1);
    }

    vll stack;
    V< map<char, ll> > topo(n);
    REP(i, n) {
        map<char, ll> sc = {{'A', 0}, {'B', 0}};
        for (ll e: edges[i]) {
            if (s[e] == 'A') sc['A']++;
            else sc['B']++;
        }
        if (sc['A'] == 0 || sc['B'] == 0) stack.emplace_back(i);
        topo[i] = sc;
    }

    vll poped(n, 0);
    while (!stack.empty()) {
        ll i = *(--stack.end());
        stack.pop_back();
        if (poped[i] == 1) continue;
        poped[i] = 1;
        for (ll e: edges[i]) {
            topo[e][s[i]]--;
            if (topo[e][s[i]] == 0) stack.emplace_back(e);
        }
    }

    REP(i, n) {
        if (poped[i] == 0) {
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";
    return 0;
}


Measured memory_bytes: 46660
#include "bits/stdc++.h"
#include<unordered_map>
#pragma warning(disable:4996)
using namespace std;

int walls[55][55][4];

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

struct aa {
	int x;
	int y;
	int time;
	vector<int>xs;
	vector<int>ys;
};
class Compare {
public:
	//aaが昇順に並ぶ
	bool operator()(const aa&l, const aa&r) {
		return l.time> r.time;
	}
};
aa getway(const int fx, const int fy, const int tx, const int ty) {
	priority_queue<aa, vector<aa>, Compare>que;
	que.push(aa{ fx,fy,0,{},{} });
	int memo[100][100];
	for (int i = 0; i < 100; ++i) {
		for (int j = 0; j < 100; ++j) {
			memo[i][j] = 99999999;
		}
	}
	memo[fy][fx] = 0;
	while (!que.empty()) {
		aa atop(que.top());
		que.pop();
		if (atop.x == tx&&atop.y == ty) {
			return atop;
		}
		else {
			atop.xs.push_back(atop.x);
			atop.ys.push_back(atop.y);
		}
		vector<int> axs(atop.xs);
		vector<int> ays(atop.ys);
		for (int i = 0; i < 4; ++i) {
			int newx = atop.x + dx[i];
			int newy = atop.y + dy[i];
			if (!walls[atop.y][atop.x][i]) {
				if (memo[newy][newx]>atop.time + 1) {
					memo[newy][newx] = atop.time + 1;
					que.push(aa{ newx,newy,atop.time + 1,atop.xs,atop.ys });
				}
			}
		}
	}
	return aa{ -10000,0,0,{},{} };
}

int main() {
	int W, H,N; cin >> W >> H >> N;
	for (int i = 0; i < N; ++i) {
		int sx, sy, dx, dy; cin >> sx >> sy >> dx >> dy;
		sy = H - sy;
		dy = H - dy;
		if (sx == dx) {
			if (sy > dy)swap(sy, dy);
			for (int y = sy; y < dy; ++y) {
				if(sx-1>=0)walls[y][sx - 1][2] = true;
				if (sx < W)walls[y][sx][0] = true;
			}
		}
		else {
			if (sx > dx)swap(sx, dx);
			for (int x = sx; x < dx; ++x) {
				if(sy-1>=0)walls[sy-1][x][1] = true;
				if(sy<H)walls[sy][x][3] = true;
			}
		}
	}
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			for (int k = 0; k < 4; ++k) {
				if (i + dy[k] < 0 || i + dy[k] >= H) {
					walls[i][j][k] = true;
				}
				if (j + dx[k] < 0 || j + dx[k] >= W) {
					walls[i][j][k] = true;

				}
			}
		}
	}
	int startx, starty, goalx, goaly; cin >> startx >> starty >> goalx >> goaly;
	starty = H - starty - 1;
	goaly = H - goaly - 1;

	aa fstway =getway(startx, starty, goalx, goaly);
	fstway.xs.push_back(goalx);
	fstway.ys.push_back(goaly);
	int fsttime = fstway.time;
	int ans = 0;
	if (!fstway.xs.empty()) {
		for (int i = 0; i < fstway.xs.size() - 1; ++i) {
			for (int j = 0; j < 4; ++j) {
				if (fstway.xs[i] + dx[j] == fstway.xs[i + 1] && fstway.ys[i] + dy[j] == fstway.ys[i + 1]) {
					walls[fstway.ys[i]][fstway.xs[i]][j] = true;
					walls[fstway.ys[i + 1]][fstway.xs[i + 1]][(2 + j) % 4] = true;
					aa nowway(getway(startx, starty, goalx, goaly));
					if (nowway.time) {
						ans = max(ans, nowway.time - fsttime);
					}
					walls[fstway.ys[i]][fstway.xs[i]][j] = false;
					walls[fstway.ys[i + 1]][fstway.xs[i + 1]][(2 + j) % 4] = false;
				}
			}
		}
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3244
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <stdlib.h>
#include <math.h>

int main(void)
{
	long int i, j, k, l;
	long int n, a, b, sum;
	
	scanf("%ld%ld%ld", &n, &a, &b);
	
	sum = b - a;
	
	if(sum % 2 == 1) {
		if( (a - 1 + b - 1 + 1) < (n - a + n - b + 1) ) {
			sum = a - 1 + b - 1 + 1;
			printf("%ld\n", sum / 2);
		} else {
			sum = n - a + n - b + 1;
			printf("%ld\n", sum / 2);
		}
	} else {
		printf("%ld\n", sum / 2);
	}
	
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
using namespace std;
int main (){
    int n;
    cin >>n;
    for(int i=1;i<10;i++){
        for(int j=1;j<10;j++){
            if(n==i*j){
                cout << "Yes"<< endl;
                return 0;
            }
        }
    }
    cout << "No"<< endl;
    return 0;
}

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

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


Measured memory_bytes: 640
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <memory.h>
#include <queue>

using namespace std;
typedef long long LL;
const int maxn = 600005;

priority_queue<int> P,Q;
int X,Y,Z,n,a[maxn],b[maxn],c[maxn],ord[maxn];
LL sum,ans,f[maxn],g[maxn],cur;
bool comp(int u,int v) {
	return b[u]-c[u]>b[v]-c[v];
}
int main()
{
	#ifdef Amberframe
		freopen("agc018c.in","r",stdin);
		freopen("agc018c.out","w",stdout);
	#endif
	scanf("%d %d %d",&X,&Y,&Z);n=X+Y+Z;
	for (int i=1;i<=n;i++)
		scanf("%d %d %d",&a[i],&b[i],&c[i]),ord[i]=i,sum+=a[i];
	sort(ord+1,ord+n+1,comp);
	
	cur=0;
	for (int i=1;i<=n;i++) {
		int w=b[ord[i]]-a[ord[i]];cur+=w;P.push(-w);
		if (P.size()>Y) cur+=P.top(),P.pop();
		f[i]=cur;
	}
	
	cur=0;
	for (int i=n;i>=1;i--) {
		int w=c[ord[i]]-a[ord[i]];cur+=w;Q.push(-w);
		if (Q.size()>Z) cur+=Q.top(),Q.pop();
		g[i]=cur;
	}
	
	for (int i=Y;i<=n-Z;i++)
		ans=max(ans,sum+f[i]+g[i+1]);
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 13820
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n, k;
    cin >> n >> k;
  
    out(min(n%k, k - n%k));
    re0;
}

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

int main() {
  int n;
  vector<int> vec(51, 0);
  
  for(int i = 0; i < 10; i++){
    for(int j = 0; j < 10; j++){
      for(int k = 0; k < 10; k++){
        for(int l = 0; l < 10; l++){
          vec.at(i + j + k + l)++;
        }
      }
    }
  }
  
  while(cin >> n){
    cout << vec.at(n) << endl;
  }
  
}


Measured memory_bytes: 3080
import sys

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

def solve():
    n = ni()
    s = 'UDLR'
    g = [list() for _ in range(4)]
    for _ in range(n):
        x, y, u = input().split()
        g[s.index(u)].append((int(x), int(y)))


    def calc(a, b):
        a.sort()
        b.sort()
        idx = 0
        m = len(b)
        res = 10 ** 9
        for x, y in a:
            while idx < m and (b[idx][0] < x or b[idx][0] == x and b[idx][1] < y):
                idx += 1
            if idx >= m:
                break
            if b[idx][0] == x and b[idx][1] >= y:
                res = min(res, b[idx][1] - y)
        return res * 5

    res1 = calc(g[0], g[1])
    res2 = calc([(y, x) for x, y in g[3]], [(y, x) for x, y in g[2]])
    res3 = calc([(x+y, x-y) for x, y in g[3]], [(x+y, x-y) for x, y in g[0]])
    res4 = calc([(x+y, x-y) for x, y in g[1]], [(x+y, x-y) for x, y in g[2]])
    res5 = calc([(x-y, x+y) for x, y in g[0]], [(x-y, x+y) for x, y in g[2]])
    res6 = calc([(x-y, x+y) for x, y in g[3]], [(x-y, x+y) for x, y in g[1]])
    ans = min(res1, res2, res3, res4, res5, res6)
    if ans > 10**9:
        print('SAFE')
    else:
        print(ans)
    return

solve()


Measured memory_bytes: 62452
#include <stdio.h>
int main(void)
{
    int n, count = 0, flug = 0, min;
    scanf("%d", &n);
    int p[n];
    for (int i = 0; i < n; i++)
        scanf("%d", &p[i]);
    min = p[0];
    for (int i = 0; i < n; i++)
    {
        if (min >= p[i]){
            min=p[i];
            count++;
        }
    }
    printf("%d\n", count);
    return 0;
}

Measured memory_bytes: 896
def main():
    s=input()
    string=('dream','erase')

    i=0
    n=len(s)
    while i<n:
        st=s[i:i+5]
        if st==string[0]:
            i+=5
            st=s[i:i+2]
            if st=='er':
                if i+2==n:
                    break
                if s[i+2]!='a':
                    i+=2
        
        elif st==string[1]:
            i+=5
            if i==n:
                break
            if s[i]=='r':
                i+=1
        
        else:
            print('NO')
            exit()
    print('YES')
if  __name__=='__main__':
    main()

Measured memory_bytes: 3188