akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n, m;
	cin >> n >> m;
	int a, sum = 0;
	while (m-- > 0) {
		cin >> a;
		sum += a;
	}
	cout << (sum <= n ? n - sum : -1);
	return 0;
}

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

int main() {
	string s;
	cin >> s;
	vector<string> vec((s.size() + 1 ) / 2);
	for (int i = 0; i < s.size(); i += 2) {
		vec.at(i / 2) = s.at(i);
	}
	for (int j = 0; j < (s.size() + 1) / 2; j++) {
		cout << vec.at(j);
	}
}

Measured memory_bytes: 5056
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <map>
#define ll long long

using namespace std;

ll comb(ll n, ll r){
    ll child = 1, mother = 1;
    for(ll i = 1; i <= r; i++){
        child = child * (n-i+1);
        child /= i;
    }
    ll ans = child;
    return ans;
}

int main(void){
    ll n, p;
    cin >> n >> p;
    ll a[n];
    ll odd = 0, even = 0;
    for(ll i = 0; i < n; i++){
        cin >> a[i];
        if(a[i]%2!=0) odd++;
        else even++;
    }
    //cout << even << " " << odd << endl;
    ll ans = 0;
    if(p==1){
        for(ll i = 0; i <= even; i++){
            for(ll j = 1; j <= odd; j+=2){
                ans+=comb(even, i)*comb(odd, j);
            }
        }
    }
    else if(p==0){
        for(ll i = 0; i <= even; i++){
            for(ll j = 0; j <= odd; j+=2){
                ans+=comb(even, i)*comb(odd, j);
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<vector>
#include<deque>
#include<stack>
#include<queue>
#include<string>
#include<iostream>
#include<tuple>
#include<utility>
#include<set>
#include<queue>
#include<iomanip>
#include<iterator>
//#include<chrono>
#include<random>
using namespace std;
typedef long long int llint;
const int big=1e9+100000;
const int mod=1e9+7;
const long double pai=3.141592653589793238462643;
#define mt make_tuple
#define mp make_pair
#define fir first
#define sec second
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define res resize
#define ins insert
#define era erase
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
class seg{
public:
	vector<vector<int>> val;
	seg(void){
		val.res(19);
		for(int bi=0;bi<19;bi++){val[bi].res(1<<(18-bi));}
	}
	void ran_plus(int bas,int su){
		int pot=0;
		for(int bi=18;bi>=0;bi--){
			if((1<<bi)<=bas){
				bas-=(1<<bi);
				val[bi][pot]+=su;
				pot*=2;
				pot++;
			}else{pot*=2;}
		}
	}
	int ask(int bas){
		int ans=0;
		for(int bi=0;bi<19;bi++){
			if(bas%2==0){ans+=val[bi][bas/2];}
			bas/=2;
		}
		return ans;
	}
};
int main(void){
	int n,m,i;cin>>n>>m;
	deque<pair<int,int>> miya(n);//1+r-l,l
	seg eki;
	
	for(i=0;i<n;i++){
		int l,r;cin>>l>>r;miya[i]=mp(1+r-l,l);
	}
	int kae=n;
	sort(miya.begin(),miya.end());
	for(int d=1;d<=m;d++){
		while((!miya.empty())&&miya[0].fir<d){
			int l=miya[0].sec,r=miya[0].fir+miya[0].sec;
			eki.ran_plus(r,1);
			eki.ran_plus(l,-1);
			miya.pof();kae--;
		}
		//cout<<"de"<<miya.size()<<" "<<kae<<endl;
		int ans=kae;
		//cout<<"de";
		for(i=0;i<=m;i+=d){
			ans+=eki.ask(i);
			//cout<<eki.ask(i)<<" ";
		}
		//cout<<endl;
		cout<<ans<<endl;
	}
	return 0;
}

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

int main() {
  string s;
  char t;
  long long int k;
  int count=0;
  cin >> s >> k;
  for (auto i : s) {
    if (i!='1') {
      t = i;
      break;
    }
    else count++;
  }
  if (k>count) cout << t;
  else cout << 1;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<utility>
#include<functional>
#include<algorithm>
#include<bitset>
#include<ctime>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#define int long long
using namespace std;
int n,m,x[1005][3],mx;
signed main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		for(int j=0;j<3;j++)
			cin>>x[i][j];
	for(int mask=0;mask<8;mask++)
	{
		vector<int>all;
		for(int i=1;i<=n;i++)
		{
			int t=mask;
			int val=0;
			for(int j=0;j<3;j++)
			{
				if(t&1)
					val+=x[i][j];
				else
					val-=x[i][j];
				t>>=1;
			}
			all.push_back(val);
		}
		sort(all.begin(),all.end());
		reverse(all.begin(),all.end());
		int cur=0;
		for(int i=0;i<m;i++)
			cur+=all[i];
		mx=max(mx,cur);
	}
	cout<<mx;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int n,a[5000];
int main(){
	int i,j,t,tmp;
	while(cin >> n && n){
		tmp = 0;
		t = -1000000;
		for(i=0;i<n;i++){
			cin >> a[i];
		}
		for(i=0;i<n;i++){
			tmp += a[i];
			if(t < tmp) t = tmp;
				for(j=i+1;j<n;j++){
					tmp += a[j];
					if(t < tmp) t = tmp;
				}
			tmp = 0;
		}
		cout << t << endl;
	}
	return 0;
}

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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n, ans = 0;
	string s;
	cin>>n>>s;
	int r = 0, w = 0;
	for(int i = 0;i < n;i++){
		if(s[i] == 'R') r++;
		else w++;
	}
	if(w < r){
		for(int i = 0;i < n - w;i++){
			if(s[i] == 'W') ans++;
		}
	}
	else{
		for(int i = r;i < n;i++){
			if(s[i] == 'R') ans++;
		}
	}
	cout<<ans<<'\n';
	return 0;
}
//ios_base::sync_with_stdio(false);
//cin.tie(0);
//tod-ngen


Measured memory_bytes: 3772
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#define tonum(c) ((c) - '0')
using namespace std;
int main()
{
    string s;
    cin >> s;
    int ans = 10000;
    for(int i = 0; i < s.size() - 2; i++){
        int k = tonum(s[i]) * 100 + tonum(s[i+1]) * 10 + tonum(s[i+2]);
        ans = min(ans, abs(k - 753));
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
  int N, K, sum;
  cin >> N >> K;
  
  sum = 1;
  for(int i = 0; i < N; i++){
    if(sum <= K)
      sum *= 2;
    else
      sum += K;
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=200000;
const int MOD=998244353;
void inc(int &a,int b) { if((a+=b)>=MOD) a-=MOD; }

int n;
char lim[MAXN+1];

int p2[MAXN+1];
int mlt[MAXN+1];

int calccnt(int x) {
	int ret=0;
	REP(i,x) if(lim[i]=='1') inc(ret,p2[x-i-1]);
	bool ok=true; int times=n/x; REP(k,n) { int i=k/x,j=k%x; char a=lim[j],b=lim[i*x+j]; if(i%2==1) a='0'+1-(a-'0'); if(a==b) continue; if(b<a) ok=false; break; } if(ok) ++ret;
	return ret;
}

int solve() {
	int ret=0;
	p2[0]=1; FORE(i,1,n) p2[i]=(ll)p2[i-1]*2%MOD;
	for(int x=n;x>=1;--x) if(n%x==0&&n/x%2==1) {
		int cur=calccnt(x);
		int have=0,want=2*x;
		for(int y=2*x;y<=n;y+=x) if(n%y==0&&n/y%2==1) inc(have,mlt[y]);
		mlt[x]=(want+MOD-have)%MOD;
		//printf("x=%d -> cur=%d have=%d want=%d mlt=%d\n",x,cur,have,want,mlt[x]);
		ret=(ret+(ll)mlt[x]*cur)%MOD;
	}
	return ret;
}

void run() {
	scanf("%d",&n);
	scanf("%s",lim); assert(strlen(lim)==n);
	printf("%d\n",solve());
}

void printbin(int x,int len) { REP(i,len) printf("%d",(x>>(len-i-1))&1); }
void research() {
	FORE(len,1,20) {
		printf("len=%d\n",len);
		vector<bool> seen(1<<len,false);
		REP(s,1<<len) if(!seen[s]) {
			vector<int> cur;
			int at=s; while(!seen[at]) { cur.PB(at); seen[at]=true; if(at%2==0) at=(at>>1)|(1<<(len-1)); else at=(at>>1); }
			if(SZ(cur)!=2*len) { printf("\tcur (%d):",SZ(cur)); REPSZ(i,cur) { printf(" "); printbin(cur[i],len); } puts(""); }
		}

	}
}

int main() {
	//research();
	run();
	return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
int dx[2] = {1,0};
int dy[2] = {0,1};
double p[3000];
double dp[3000][3000] = {};

int main() {
    int N;
    cin >> N;
    for(int i=0; i<N; ++i) {
        cin >> p[i];
    }

    dp[0][0] = 1;
    for(int i=0; i<N; ++i) {
        for(int j=0; i+j<N; ++j) {
            dp[i][j+1] += dp[i][j] * p[i+j];
            dp[i+1][j] += dp[i][j] * (1 - p[i+j]);
        }
    }

    double res = 0;
    for(int i= N; i > N / 2; --i) res += dp[N-i][i];
    printf("%.10f\n", res);
    return 0;
}

Measured memory_bytes: 70016
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

int main()
{
    int h, w, k;
    cin >> h >> w >> k;

    vector<string> g(h);
    rep(y, h)
    {
        cin >> g[y];
    }

    ll ans = INT32_MAX;
    rep(j, (1 << h - 1))
    {
        int loc = __builtin_popcount(j);

        ll now = loc;
        vector<vector<int>> lines(loc + 1, vector<int>(w + 1));
        int i = 0;
        rep(y, h)
        {
            rep(x, w)
            {
                lines[i][x + 1] += (g[y].at(x) == '1');
            }
            if (j & (1 << y))
            {
                i++;
            }
        }
        rep(y, loc + 1) rep(x, w) lines[y][x + 1] += lines[y][x];

        bool ok = true;
        int cutx = 0;
        rep(x, w)
        {
            rep(y, loc + 1)
            {
                if (lines[y][x + 1] - lines[y][cutx] > k)
                {
                    if (lines[y][x] - lines[y][cutx] > k)
                    {
                        ok = false;
                    }
                    cutx = x;
                    now++;
                }
            }
        }
        if (!ok)
            continue;

        // bitset<5> b = j;
        // cout << b << " " << now << endl;
        // view(lines);

        ans = min(now, ans);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int a[]={0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0};
char ch;
int main()
{
	ch=getchar();
	if(a[ch-'a'+1]) cout<<"vowel";
	else cout<<"consonant";
	return 0;
}

Measured memory_bytes: 256
s = input()

l = len(s)

ans = 0

if l%2 == 0:
	a = s[:int(l/2)]
	b = s[int(l/2):]
	
	for i in range(len(a)):
		if a[i]==b[-1*(i+1)]:
			pass
		else:
			ans = ans + 1

else:
	a = s[:int(l//2)]
	b = s[int(l//2)+1:]
	
	for i in range(len(a)):
		if a[i]==b[-1*(i+1)]:
			pass
		else:
			ans = ans + 1

print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
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; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll x;
  cin >> x;
  cout << x/500*1000+x%500/5*5 << endl;
  return 0;
}

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

ll a[100000];

template <typename T>
T Gcd(T a, T b) {
  if (b == 0) {
    return a;
  }
  return Gcd(b, a % b);
}

int main() {
  in(ll,n,m);
  rep(i,n)cin>>a[i];

  rep(i,n){
    a[i]/=2;
  }
  ll l=1;
  rep(i,n){
    l=l*a[i]/Gcd(l,a[i]);
    if(l>m){
      out(0);
      return 0;
    }
  }
  dbg(l,m);
  rep(i,n)if(l/a[i]%2==0){
    out(0);
    return 0;
  }
  ll ans=0;
  if (m >= l) {
    ++ans;
    m -= l;
  }
  ans+=m/(2*l);
  out(ans);
}


Measured memory_bytes: 1024
N, W = map(int,input().split())
dp = [[0 for i in range(100001)] for i in range(N+1)]

for i in range(N):
    w, v = map(int, input().split())
    for sum_w in range(W+1):
        if sum_w - w >= 0:
            dp[i+1][sum_w] = max(dp[i][sum_w - w] + v, dp[i+1][sum_w])

        dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w])

print(max(dp[-1]))

Measured memory_bytes: 171528
s = input()
n = len(s)
s1 = s[::-1]
if s == s1:
    s2 = s[: (n - 1) // 2]
    s3 = s2[::-1]
    if s3 == s2:
        s4 = s[(n + 3) // 2 - 1: ]
        s5 = s4[::-1]
        if s4 == s5:
            print("Yes")
        else:
            print("No")
    else:
        print("No")
else:
    print("No")

Measured memory_bytes: 38384
import math
n, m = map(int, input().split())
div = 10**9 + 7

if abs(n-m)>1:
    print(0)
    exit()
elif n == m:
    ans1 = math.factorial(n)
    ans2 = math.factorial(m)
    ans = 2 * ans1 * ans2 
else:
    ans1 = math.factorial(n)
    ans2 = math.factorial(m)
    ans = ans2*ans1

print(ans % div)

Measured memory_bytes: 86040
#include<bits/stdc++.h>
using namespace std;
int a[10001],num,tot;
int main()
{
	double n,m,temp;
	cin>>n>>m;
	
	for(int i=1;i<=n;++i)
	{
		cin>>a[i];
		num+=a[i];
	}
	temp=num/(4.0*m);
	for(int i=1;i<=n;++i)
	{
		if(a[i]>=temp) tot++;
	}
	if(tot>=m) cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define N 1000000007
#define pll pair<ll,ll>

void dfs(int x, vector<vector<ll> > &adj, vector<ll> &pars, vector<ll> &visited) {

	visited[x] = 1;

	for(auto i:adj[x]) {
		if(!visited[i])
			dfs(i,adj,pars,visited);
	}

	pars.pb(x);
}

int main() {

	ll n,m;
	cin>>n>>m;

	vector<ll> dp(m,0);
	dp[0]=1;

	for(ll i=0;i<n;i++) {
		string s;
		cin>>s;
		for(ll j=0;j<m;j++) {
			if(s[j]=='.') dp[j] = (dp[j] + (j-1>=0 ? dp[j-1] : 0))%N;
			else dp[j] = 0;
		}
	}

	cout<<dp[m-1]<<endl;
	return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc160/tasks/abc160_e

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

const ll INF = 1e18;

void solve() {
  ll X, Y, A, B, C;
  cin >> X >> Y >> A >> B >> C;

  VL ps(A);
  rep(i, A) cin >> ps[i];
  sort(all(ps), [](ll a, ll b) { return a > b; });

  VL qs(B);
  rep(i, B) cin >> qs[i];
  sort(all(qs), [](ll a, ll b) { return a > b; });

  VL rs(C);
  rep(i, C) cin >> rs[i];
  sort(all(rs), [](ll a, ll b) { return a > b; });

  ll sum = 0;
  priority_queue<ll, VL, greater<ll>> pq;

  rep(i, X) {
    sum += ps[i];
    pq.push(ps[i]);
  }

  rep(i, Y) {
    sum += qs[i];
    pq.push(qs[i]);
  }

  ll r_i = 0;
  while (r_i < C && rs[r_i] > pq.top()) {
    sum -= pq.top();
    pq.pop();
    sum += rs[r_i];
    r_i++;
  }

  cout << sum << endl;
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


Measured memory_bytes: 4852
#include<bits/stdc++.h>
using namespace std;
int main(){
  int A,B;
  cin>>A>>B;
  if(A%3==0||B%3==0||(A+B)%3==0){
    cout<<"Possible"<<endl;
  }
  else{
    cout<<"Impossible"<<endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef pair<int,int> pa;
#define w1 first
#define w2 second
#define ls (x<<1)
#define rs (x<<1|1)
#define pb push_back
#define mp make_pair
#define mid ((l+r)>>1)
#define SZ(x) ((x).size())
#define All(x) (x).begin(),(x).end()
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define rep2(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define per(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)
#define Rep(p,x) for(int (p)=head[(x)];(p);(p)=nxt[(p)])
template<class T>void read(T&num){
	num=0;T f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')num=num*10+ch-'0',ch=getchar();
	num*=f;
}
int power(int x,int k,int p){int res=1;for(;k;k>>=1,x=1ll*x*x%p)if(k&1)res=1ll*res*x%p;return res;}
int getgcd(int x,int y){return !x?y:getgcd(y%x,x);}
const int maxn=2e5,mod=1e9+7;
int H,W,A,B;
int fac[maxn+5],ifac[maxn+5];
int C(int n,int m){
	return 1ll*fac[n]*ifac[m]%mod*ifac[n-m]%mod;
}
int calc(int x,int y){
	return C(x+y,x);
}
int main(){
	fac[0]=1;rep(i,1,maxn)fac[i]=1ll*fac[i-1]*i%mod;
	ifac[maxn]=power(fac[maxn],mod-2,mod);per(i,maxn-1,0)ifac[i]=1ll*ifac[i+1]*(i+1)%mod;
	read(H);read(W);read(A);read(B);
	int x=H-A,y=B+1,ans=0;
	while(x!=0&&y!=W+1){
		ans=(ans+1ll*calc(x-1,y-1)*calc(H-x,W-y))%mod;
		x--;y++;
	}
	cout<<ans<<endl;
	return 0;
}

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

typedef long double ld;
//#define int long long   
#define PB push_back 
#define endl '\n'
#define all(x) (x).begin(),(x).end()
#define ii pair <int,int>
#define mii map <int,int>
#define vi vector<int> 
#define vii vector< ii >
#define F first
#define S second 
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define repd(i,a,b) for(int i=a; i>=b; --i)
#define sz(x) (int)((x).size())
ld pi= 3.14159265358979;
const int mod = 1e9+7;
const int N = 1e6+7;

void solve()
{  
	int x, y; cin>>x>>y;
	int z = x*4;
	rep(i, 0, x+1){
		if(z-2*i == y){
			cout<<"Yes"; return;
		}
	}cout<<"No";
}
signed main() 
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    //cout<<setprecision(20);
    int tc=1; //cin>>tc;
    while(tc--){
        solve();cout<<'\n';
    }
    return 0;
}

Measured memory_bytes: 3644
K=int(input())


if K%2==0 or K%5==0:
    print(-1)
    exit()
elif K==7 or K==1:
    print(1)
else:
    M=7%K
    B=7%K
    for i in range(10**7):
        A=((B*10)%K)
        M+=A
        M%=K
        if M==0:
            print(i+2)
            exit()
        B=A+0
        #print(M,B,i)
        

Measured memory_bytes: 63508
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
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;}
typedef long long int ll;


int main() {
	int a, b, c;
	cin >> a >> b >> c;
	YesNo(a + b >= c);
}

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

int main() {
  int N;
  string S;
  cin >> N >> S;
  for (int i = 0; i < S.size(); ++i)
    S[i] = 'A' + (S[i] - 'A' + N) % 26;
  cout << S << endl;
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>


using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define loop(n) FOR(i,0,n)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {
	int n;
	
	while (true) {

		cin >> n;
		if (n == 0)return 0;

		int l = -1;
		int r = -1;
		int cnt = 0;
		int target = 2;
		for (int i = 0; i < n; i++) {
			string order; cin >> order;

			if (order == "lu") {
				l = 1;
			}

			if (order == "ld") {
				l = -1;
			}

			if (order == "ru") {
				r = 1;
			}

			if (order == "rd") {
				r = -1;
			}

			if (l == r && l+r==target) {
				cnt++;

				if (target == 2) {
					target = -2;
				}
				else {
					if (target == -2) {
						target = 2;
					}
				}

				
			}
		}
		cout << cnt << endl;
	}

	
	return 0;
}


Measured memory_bytes: 3152
#include <iostream>

int main() {
  char c = 0;
  int ans = 0;
  std::cin >> c;
  if (c == '1') ans++;
  std::cin >> c;
  if (c == '1') ans++;
  std::cin >> c;
  if (c == '1') ans++;
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 256
lines = STDIN.read.split("\n")
loop do
  cards = lines.shift
  break if cards == "-"
  n = lines.shift.to_i
  n.times do |i|
    h = lines.shift.to_i
    cards = cards[h..cards.size] + cards[0..(h - 1)]
  end
  puts cards
end

Measured memory_bytes: 8656
#include <stdio.h>
#include <math.h>
 
#define rep(i, n) for(int i = 0; i < n; i++)
#define in_arr(type, a, n) for(int i = 0; i < n; i++) scanf(type, &((a)[i]));
#define ll long long int
 
int main(){
    ll a;
    scanf("%lld", &a);
    printf("%lld\n", a % 2 == 0 ? a : a * 2);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//#define ll long long
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll t1,t2,t3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;
void swap(ll *x,ll *y){
  ll tmp;
  tmp = *x;
  *x = *y;
  *y = tmp;
}

int main(){
  ll n;
  cin >> n;
  vector<ll> vec(n);
  rep(i,n){
    cin >> vec[i];
  }
  ll ans = INFLONG;
  rep(i,101){
    t1 = 0;
    rep(j,n){
      t1 += (vec[j] - i) * (vec[j] - i);
    }
    chmin(ans,t1);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<cstdio>
using namespace std;
const int maxn=200+2;
const int mod=998244353;
int n;
struct Point{
	int x,y;
};
Point p[maxn];
int _2[maxn];
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d%d",&p[i].x,&p[i].y);
	_2[0]=1;
	for (int i=1;i<maxn;i++) _2[i]=(1LL*_2[i-1]*2)%mod;
	int ans=(_2[n]-n-1+mod)%mod;
	for (int i=1;i<n;i++)
		for (int j=i+1;j<=n;j++){
			int tmp=1;
			for (int k=j+1;k<=n;k++)
				if ((p[j].x-p[i].x)*(p[k].y-p[i].y)==(p[k].x-p[i].x)*(p[j].y-p[i].y)) tmp=(tmp<<1)%mod;
			ans=(ans-tmp+mod)%mod;
		}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 128
<?php
list($N, $M) = explode(" ", trim(fgets(STDIN)));
for($k = 0; $k < $M; $k++){
    $map[$k] = explode(" ", trim(fgets(STDIN)));
    array_shift($map[$k]);
}
$odd = explode(" ", trim(fgets(STDIN)));

$count = 0;
for($i = 0; $i < 2**$N; $i++){
    $flags = sprintf("%0".$N."d", decbin($i));
    for($k = 0; $k < $M; $k++){
        $on = $odd[$k];
        foreach($map[$k] as $switch){
            $on += $flags[$switch - 1];
        }
        if($on % 2 == 1)break;
        if($k == $M-1){
            $count++;
        }
    }
}
echo $count;


Measured memory_bytes: 4728
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>

using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ll> pdl;
typedef pair<ld, ld> pdd;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
//typedef boost::multiprecision::cpp_int bigint;

//si:頂点数
//root:根
//ch:子供の集合
//pa:親(根の親=-1)
//no:前提情報
void treeconstruct(ll si, ll root, vector<vector<ll>>& ch, vector<ll>& pa, vector<vector<ll>>& no) {
	ch.resize(si, vector<ll>(0));
	pa.resize(si, -2);
	queue<pll> q;
	q.push(pll(root, -1));
	while (!q.empty()) {
		ll cur = q.front().first;
		ll p = q.front().second;
		q.pop();
		pa[cur] = p;
		for (ll next : no[cur]) {
			if (next == p)continue;
			ch[cur].push_back(next);
			q.push(pll(next, cur));
		}
	}
	return;
}

vector < vector <pll>> edges;
VLL ans;
ll N;

void calc(ll n) {
	ll des = -1;
	for (ll c = 0; c < edges[n].size(); c++) {
		if (ans[edges[n][c].second] != -1) {
			des = ans[edges[n][c].second];
			break;
		}
	}
	ll c = 0;
	for (ll child = 0; child < edges[n].size(); child++) {
		if (c == des)c++;
		if (ans[edges[n][child].second] == -1) {
			ans[edges[n][child].second] = c;
			calc(edges[n][child].first);
		c++;
		}
	}
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	cin >> N;
	edges.resize(N);
	for (ll n = 0; n < N - 1; n++) {
		ll a, b;
		cin >> a >> b;
		a--; b--;
		edges[a].push_back(pll(b,n));
		edges[b].push_back(pll(a,n));
	}
	for (ll n = 0; n < N; n++) {
		sort(edges[n].begin(), edges[n].end());
	}
	ans.resize(N-1,-1);
	calc(0);
	ll K = 0;
	for (ll n = 0; n < N; n++)K = max(K, (ll)edges[n].size());
	cout << K << "\n";
	vector<ll> anse(N);
	for (ll n = 0; n < N - 1; n++)cout << ans[n]+1 << "\n";
	return 0;
}

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

int main(void) {
    int N,K;
    cin >> N >> K;

    int ans[N+1];

    for(int i=0; i<N+1; i++){
      ans[i] = 0;
    }

    for(int i=0; i<K; i++){
      int d;
      cin >> d;
      int A[d];
      for(int j=0; j<d; j++){
        cin >> A[j];
        ans[A[j]]++;
      }
    }
    int cnt =0;

    for(int i=1; i<N+1; i++){
      if(ans[i]==0)
        cnt++;
     }

     cout << cnt << endl;

    return 0;
}


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

int main(){
  int N, K, Q;
  cin >> N >> K >> Q;

  int a[Q];
  int b[N];
  for(int i=0; i<Q; i++){
    cin >> a[i];
  }
  for(int i=0; i<N; i++){
    b[i] = K;
  }

  for(int n=0; n<N; n++){
      b[n] -= Q;
    }

  for(int q=0;q<Q; q++){
    ++b[a[q]-1];
  }

  for(int n=0; n<N; n++){
    if(b[n] <= 0){
      cout << "No" << endl;
    }else{
      cout << "Yes" << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 1408
#include<iostream>
using namespace std;

int judge(int a, int b, int x) {
	if ((x < a) || (a + b) < x)	return 0;
	else if (a <= x && x <= (a + b))	return 1;

}

int main() {
	int A, B, X;
	cin >> A >> B >> X;

	int ans = judge(A, B, X);
	if (ans == 0)	cout << "NO";
	else cout << "YES";

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b,c,d,e;
    cin>>a>>b>>c>>d>>e;
    if(a==0){
        cout<<"1"<<endl;
    }
    else if(b==0){
        cout<<"2"<<endl;
    }
    else if(c==0){
        cout<<"3"<<endl;
    }
    else if(d==0){
        cout<<"4"<<endl;
    }
    else{
        cout<<"5"<<endl;
    }
}

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

int main() {
	ll n;
	map<string,ll>mp;
	cin>>n;
	for(int i=0;i<n;i++){
		string s;
		cin>>s;
		mp[s]++;	
	}
	cout<<mp.size();
	return 0;
}


Measured memory_bytes: 19196
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		solve();
	}

	private static void solve() {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();

		int[][] magic = new int[10][10];
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				magic[i][j] = sc.nextInt();
			}
		}

		for (int k = 0; k < 10; k++) {
			for (int i = 0; i < 10; i++) {
				for (int j = 0; j < 10; j++) {
					if (magic[i][j] > magic[i][k] + magic[k][j]) {
						magic[i][j] = magic[i][k] + magic[k][j];
					}
				}
			}
		}

		int[][] targets = new int[h][w];
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				targets[i][j] = sc.nextInt();
			}
		}

		int cost = 0;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (targets[i][j] == -1 || targets[i][j] == 1) {
					continue;
				} else {
					cost += magic[targets[i][j]][1];
				}
			}
		}
		System.out.println(cost);
	}
}

Measured memory_bytes: 47836
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
  ll a, b, x;
  cin >> a >> b >> x;
  ll p = a - 1 < 0 ? 0 : (a - 1) / x + 1;
  ll q = b / x + 1;
  cout << q - p << endl;
  return 0;
}

Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main()
{
	int N, M;
	cin >> N >> M;
	int *A = new int[M];
	for (int i = 0; i < M; i++)
		cin >> A[i];

	int sum = 0;
	for (int i = 0; i < M; i++)
		sum += A[i];
	
	if (N - sum < 0)
		cout << -1 << endl;
	else
		cout << N - sum << endl;

	return 0;
}

Measured memory_bytes: 3664
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>

using namespace std;


void solve() {
    int N, M; cin >> N >> M;
    if (N == M) cout << "Yes" << endl;
    else cout << "No" << endl;
}


int main() {
    solve();
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
 
int main(void){
  int i;
  int n;
  int m;
  int a[10010];
  scanf("%d%d",&n, &m);
  for(i = 0; i < m; i++){
    scanf("%d", &a[i]);
    n -= a[i];
  }
  if (n < -1)
    n=-1;
  printf("%d",n);
}

Measured memory_bytes: 1768
#include"stdio.h"
#include"stdlib.h"
#include"string.h"
int main(void){
  char* wt = (char*) calloc(10,sizeof(char));
  scanf("%s",wt);
  if(strcmp(wt,"Sunny")==0){
    printf("Cloudy\n");
  }
  else if(strcmp(wt,"Rainy")==0){
    printf("Sunny\n");
  }
  else{
    printf("Rainy\n");
  }
  return 0;
}


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

using namespace std;

int h[100005];

int main() {

	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);

	int n, k;
	cin >> n >> k;
	int ans = 0;
	for (int i = 1; i <= n; ++i) {
		cin >> h[i];
		if (h[i] >= k) ans++;
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            int[] p = new int[N];
            for (int i = 0; i < N; i++) {
                p[i] = in.nextInt() - 1;
            }

            int count = 0;
            for (int i = 0; i < N; i++) {
                if (p[i] != i) {
                    count++;
                }
            }

            System.out.println(count == 0 || count == 2 ? "YES" : "NO");
        }
    }
}


Measured memory_bytes: 21844
import java.util.*;

class Main {
	public static void main (String[] args) {
    	Scanner sc = new Scanner(System.in);
      	int A = sc.nextInt();
      	int B = sc.nextInt();
      	int C = sc.nextInt();
      	int K = sc.nextInt();
      	int judge = 0;
      	int alpha = 0, beta = 0, gamma = 0;
      	for (int c = 0; c < K + 1; c++) {
        	for (int b = (int)Math.max(0, 1-c); b < K + 1 - c; b++) {
            	for (int a = (int)Math.max(0, 1-c-b); a < K + 1 - c - b; a++) {
                	alpha = A * (int) Math.pow(2, a);
                  	beta = B * (int) Math.pow(2, b);
                  	gamma = C * (int) Math.pow(2, c);
                  	if ((gamma > beta)&&(beta > alpha)) {
                    	judge = 1;
                      	break;
                    }
                }
            }
        }
      	if (judge == 1) {
          	System.out.println("Yes");
        } else {System.out.println("No");}
      	
	}
}

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

int main(int argc, char const *argv[])
{
	int n,m;
	cin>>n>>m;
	int k[m],s[m][n]={},a;
	for (int i = 0; i < m; ++i)
	{
		cin>>k[i];
		for (int j = 0; j < k[i]; ++j)
		{
			cin>>a;--a;
			++s[i][a];
		}
	}
	int p[m];
	for (int i = 0; i < m; ++i)
	{
		cin>>p[i];
	}
	int b[n+5]={},ans=0;
	while (b[n]==0)
	{
		int c[m]={};
		for (int i = 0; i < n; ++i)
		{
			if (b[i]==1)
			{
				for (int j = 0; j < m; ++j)
				{
					if (s[j][i]==1)
					{
						++c[j];
					}
				}
			}
		}
		int f=1;
		for (int i = 0; i < m; ++i)
		{
			if (c[i]%2!=p[i])
			{
				f=0;
			}
		}
		if (f==1)
		{
			++ans;
		}
		for (int i = 0; i <= n; ++i)
		{
			if (b[i]==0)
			{
				b[i]=1;
				break;
			}
			b[i]=0;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define itn int
#define int long long
#define mod 1000000007
#define fi first
#define se second
#define be begin()
#define en end()
#define re reverse
#define Set setprecision
#define NO cout<<"NO\n"
#define YES cout<<"YES\n"
#define No cout<<"No\n"
#define Yes cout<<"Yes\n"
const int INFi=2147483647;
const long long INFl=9223372036854775807LL;
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string a;
    cin>>a;
    if(a[0]!=a[1]||a[0]!=a[2]||a[1]!=a[2]) Yes;
    else No;
}


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

int main(){
  int n;
  int ans;
  int kenzan;
  
  cin >> n;
  ans = ceil(n/1.08);
  kenzan = ans * 1.08;
  
  //cout << "ans" << ans << "kenzan" << kenzan;
  if(n == kenzan)cout << ans;
  else cout << ":(";
  
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<algorithm>
#include<functional>

#define fir first
#define sec second
#define mp make_pair
#define mt make_tuple
#define pub push_back
using namespace std;
typedef long long int llint;
const llint one = 1;
const llint big = (one<<33);
const llint ban = (big<<20);

int main(void){
	static int J[1001][1001]={0};
	static int O[1001][1001]={0};
	static int I[1001][1001]={0};
	int M,N,K,i,j,q,w,e,r;
	char c;
	scanf("%d %d",&M,&N);
	scanf("%d",&K);
	for(j=1;j<=M;j++){
		for(i=1;i<=N;i++){ 
			scanf(" %c",&c);
			if(c=='J'){J[j][i]++;}
			if(c=='O'){ O[j][i]++; }
			if(c=='I'){ I[j][i]++; }
		}
	}
	for(j=1;j<=M;j++){
		for(i=1;i<=N;i++){
			J[j][i]+=J[j][i-1];
			O[j][i]+=O[j][i-1];
			I[j][i]+=I[j][i-1];
		}
	}
	for(j=1;j<=M;j++){
		for(i=1;i<=N;i++){
			J[j][i]+=J[j-1][i];
			O[j][i]+=O[j-1][i];
			I[j][i]+=I[j-1][i];
		}
	}
	for(;K>0;K--){
		scanf("%d %d %d %d",&q,&w,&e,&r);
		q--;w--;
		printf("%d ",J[q][w]+J[e][r]-J[q][r]-J[e][w]);
		printf("%d ",O[q][w]+O[e][r]-O[q][r]-O[e][w]);
		printf("%d\n",I[q][w]+I[e][r]-I[q][r]-I[e][w]);
	}
	return 0;
}

Measured memory_bytes: 14340
I = 0
L = 1
R = 2
P = 3
B = 4
D = 5
H = 6

def getidx(Tree,value):
    idx = -1
    for i in range(len(Tree)):
        if Tree[i][I] == value:
            idx = i
            break
    return idx

def search(Tree, A, B, num):
    root = A[0]
    rootidx = getidx(Tree,root)
    ld = num
    for i in range(num):
        if B[i] == root:
            ld = i
            break
    if ld > 0:
        left,lidx = search(Tree,A[1:ld+1],B[:ld],ld)
        Tree[rootidx][L] = lidx
    rt = ld + 1
    if rt < num:
        right,ridx = search(Tree,A[rt:],B[rt:],num - rt)
        Tree[rootidx][R] = ridx
    return (root,rootidx)

def postorder(Tree, nidx, A):
    if nidx < 0:
        return
    postorder(Tree,Tree[nidx][L],A)
    postorder(Tree,Tree[nidx][R],A)
    A.append(Tree[nidx][I])


def main():

    """ ????????? """
    num = int(input().strip())
    plist = list(map(int,input().split()))
    ilist = list(map(int,input().split()))
    tree = []
    for i in plist:
        tree.append([i, -1, -1, -1, -1, 0, 0])

    root,ridx = search(tree, plist, ilist, num)

    pos = []

    postorder(tree, ridx, pos)
    print(" ".join(map(str,pos)))

if __name__ == '__main__':
    main()

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

int main()
{
    int n, k, x;
    vector<int> v;
    cin>>n>>k;

    while(n>=k){
        x = n%k;
        v.push_back(x);
        n = n/k;
    }
    cout<<v.size()+1;

}


Measured memory_bytes: 256
#include <string>
#include <stack>
#include <stdlib.h>
#include <iostream>
using namespace std;
int a, b,c;

int main()
{
	string word;
	stack <int> S;
	while (cin >> word)
	{
		if (word == "+")
		{
			a = S.top(); S.pop();
			b = S.top(); S.pop();
			S.push(a + b);
		}
		else if (word == "-")
		{
			a = S.top(); S.pop();
			b = S.top(); S.pop();
			S.push(b - a);
		}
		else if (word == "*")
		{
			a = S.top(); S.pop();
			b = S.top(); S.pop();
			S.push(a * b);
		}
		else
		{
			c = atoi(word.c_str());
			S.push(c);
		}
	}
	cout << S.top() << endl;
	return 0;
}


Measured memory_bytes: 3212
#include <bits/stdc++.h>
#ifdef __DEBUG__
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int N;
vector<ll> A;
void input(){
    fast_io();
    cin >> N;
    A = fetch_vec<ll>(N);
}

int solve(){
    deque<ll> X;
    for (size_t i = 0; i < N; i++)
    {
        if(i%2) X.push_back(A[i]);
        else X.push_front(A[i]);
    }
    if(N%2==0) reverse(X.begin(),X.end());
    cout << X << endl;
    
    return 0;
}   

int main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
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 <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    int h, w, n;
    cin >> h >> w >> n;
    chmax(h, w);
    cout << (n + h - 1) / h << endl;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
S = []
s = 0

#累積和のリストを作りますが最後の要素は使いません
for i in range(N-1):
  s += A[i]
  S.append(s)
#print(S)

s = sum(A) #再利用（よくない）
#print(s)

h = s/2
m = 10000000000
index = 0

for i in range(N-1):
  if abs(S[i] - h) < m:
    m = abs(S[i] - h)
    index = i
    #print(m, i)
print(abs(s-S[index]*2))

Measured memory_bytes: 23792
n,m=map(int,input().split())
a=[input() for i in range(n)]
b=[input() for i in range(m)]
for i in range(n-m+1):
  for l in range(n-m+1):
    ok=True
    for j in range(m):
      for k in range(m):
        if b[j][k]!=a[i+j][l+k]:
          ok=False
    if ok:
      print('Yes')
      exit()
print('No')

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
#include<time.h>
#include<cassert>

using namespace std;
#define ll long long
#define ld long double
#define int long long
#define all(a) (a).begin(),(a).end()
#define EPS (1e-13)
#define fs first
#define sc second
#define xx first
#define yy second.first
#define zz second.second
#define P pair<int, int>
#define Q pair<int, pair<int, int>>
#define rep(i,n) for(int (i) = 0 ; (i) < (n) ; (i)++)
#define mkp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define crdcomp(b) sort(all((b)));(b).erase(unique(all((b))),(b).end())
const int Mod = 1e9 + 7;
const int mod = 998244353;
const ll Inf = 3 * 1e18;
const int inf = 15 * 1e8;
ll read() {
	ll u, k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}
ll bcount(ll x) {
	int sum = 0;
	for (int i = 0; i < 20; i++)
		if ((1ll << i) & x) sum++;
	return sum;
}
/*const int fn_ = 2000000;
ll fact_[fn_], comp_[fn_];
ll comb(ll x, ll y, ll mod = Mod) {
	if (!fact_[0]) {
		fact_[0] = 1; comp_[0] = 1;
		for (int i = 1; i < fn_; i++) {
			fact_[i] = fact_[i - 1] * i % mod;
			comp_[i] = mod_pow(fact_[i], mod - 2, mod);
		}
	}
	if (x < y) return 0;
	return fact_[x] * comp_[x - y] % mod * comp_[y] % mod;
}*/
//---------------------------------------------------
signed main() {
	int a, b;
	cin >> a >> b;
	cout << max(0ll, a - 2 * b) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
using ll = long long;

int main() {
	ll n;
	cin >> n;
	string s = "";
	while (n != 0) {
		if (abs(n) % 2 == 0) {
			s = "0" + s;
		}
		else {
			n -= 1;
			s = "1" + s;
		}
		n /= -2;
	}
	if (s == "") {
		cout << 0 << endl;
		return 0;
	}
	cout << s << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N;
    cin >> N;
    
    bool flag = false;
    
    for(int i = 0; i < N; i++) {
        string S;
        cin >> S;
        if(S == "Y") {
            flag = true;
        }
    }
    
    if(flag) {
        cout << "Four" << endl;    
    }else {
        cout << "Three" << endl;
    }
    
}

Measured memory_bytes: 256
import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;
import java.util.regex.*;

public class Main {

    public static int frog1(int[] arr) {
        if(arr == null || arr.length == 0) {
            return 0;
        }
        int[] dp = new int[arr.length];

        for(int i = 1; i < arr.length; i++) {
            if(i == 1) {
                dp[i] = dp[i - 1] + Math.abs(arr[i] - arr[i-1]);
            } else {
                dp[i] = Math.min(dp[i - 1] + Math.abs(arr[i] - arr[i-1]), 
                                dp[i-2] + Math.abs(arr[i] - arr[i-2]));   
            }
        }
        return dp[arr.length - 1];
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        
        int[] arr = new int[n];
        int i = 0;
        while(sc.hasNextInt()) {
            arr[i] = sc.nextInt();
            i++;
        }
        
        System.out.println(frog1(arr));
  }
}


Measured memory_bytes: 54268
import sys, math
from functools import lru_cache
sys.setrecursionlimit(10**9)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    N = ii()
    ans = pow(10, N, MOD)
    ans -= pow(9, N, MOD)
    ans -= pow(9, N, MOD)
    ans += pow(8, N, MOD)
    print(ans%MOD)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9568
s=gets.chomp
c=0
f=0
s.reverse.each_char do |t|
  if f==2
    if t=~ /[5-9]/
      f=1
    else
      f=0
    end
  end
  if f==1
    if t=~ /[5-9]/
      c+=9-t.to_i
    elsif t=~ /[0-3]/
      c+=1+t.to_i
      f=0
    elsif t=~ /4/
      c+=5
      f=2
    end
  else
    if t=~ /[0-4]/
      c+=t.to_i
    elsif t=~ /5/
      c+=5
      f=2
    elsif t=~ /[6-9]/
      c+=10-t.to_i
      f=1
    end
  end
end
if f==1
  c+=1
end
puts c


Measured memory_bytes: 5644