akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#define REP(i, n) for(ll 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 INF 1<<30
#define LINF 1LL<<62
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
const ll MOD = 998244353;
 
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  COMinit();
   ll n,a,b,k; cin >> n >> a >> b >> k;
   ll ans = 0;
   REP(i,n+1){
       if(k<b*i)break;
       if((k-b*i) %a == 0 && (k-b*i) / a <= n){
           ll cnta = (k-b*i) / a;
           ll cntb = i;
           ans += COM(n,cnta) %MOD * COM(n,cntb);
           ans %= MOD;
       }
   }
   cout << ans << endl;


}

Measured memory_bytes: 12160
// includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>
#include <list>
#include <random>

// macros
#define ll long long int
#define pb emplace_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#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 UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1e9 + 7;

// solve
template <class T>bool chmax(T &a, const T &b){if(a < b){a = b; return 1;} return 0;}
template <class T>bool chmin(T &a, const T &b){if(a > b){a = b; return 1;} return 0;}


int main(int argc, char const* argv[])
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  set<ll> st;
  rep(i, n){
    ll x;
    cin >> x;
    st.insert(x);
  }
  int q;
  cin >> q;
  int res = 0;
  rep(i, q){
    ll x;
    cin >> x;
    if(st.find(x) != st.end())res++;
  }
  cout << res << endl;
	return 0;
}



Measured memory_bytes: 7656
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
#ifdef DEBUG
#define debug(...) pr(any{__VA_ARGS__})
#define debugv(x) pr((x))
#else
#define debug(...)
#define debugv(x)
#endif

int main(){
	ll N;
	cin >> N;
	ll Ga, Gb, Sa, Sb, Ba, Bb;
	cin >> Ga >> Sa >> Ba;
	cin >> Gb >> Sb >> Bb;

	ll ans = 0;
	if(Ga<Gb && Sa<Sb && Ba<Bb){
		for(int i=0; Ga*i<=N; i++){
			for(int j=0; Ga*i+Sa*j<=N; j++){
				int k = (N - Ga*i - Sa*j) / Ba;
				ans = max(ans, N + i*(Gb-Ga) + j*(Sb-Sa) + k*(Bb-Ba));
			}
		}
	} else if(Gb<Ga && Sb<Sa && Bb<Ba){
		for(int i=0; Gb*i<=N; i++){
			for(int j=0; Gb*i+Sb*j<=N; j++){
				int k = (N - Gb*i - Sb*j) / Bb;
				ans = max(ans, N + i*(Ga-Gb) + j*(Sa-Sb) + k*(Ba-Bb));
			}
		}
	} else {
		ll xa, xb, ya, yb;
		if(Ga<Gb){
			xa = Ga;
			xb = Gb;
			if(Sa<Sb){
				ya = Sa;
				yb = Sb;
			} else if(Ba<Bb){
				ya = Ba;
				yb = Bb;
			} else {
				ya = yb = 1;
			}
		} else if(Sa<Sb){
			xa = Sa;
			xb = Sb;
			if(Ba<Bb){
				ya = Ba;
				yb = Bb;
			} else {
				ya = yb = 1;
			}
		} else if(Ba<Bb){
			xa = Ba;
			xb = Bb;
			ya = yb = 1;
		} else {
			xa = xb = 1;
			ya = yb = 1;
		}

		ll m = 0;
		for(int i=0; xa*i<=N; i++){
			int j = (N-xa*i)/ya;
			m = max(m, N + i*(xb-xa) + j*(yb-ya));
		}

		if(Gb<Ga){
			xa = Ga;
			xb = Gb;
			if(Sb<Sa){
				ya = Sa;
				yb = Sb;
			} else if(Bb<Ba){
				ya = Ba;
				yb = Bb;
			} else {
				ya = yb = 1;
			}
		} else if(Sb<Sa){
			xa = Sa;
			xb = Sb;
			ya = yb = 1;
			if(Bb<Ba){
				ya = Ba;
				yb = Bb;
			} else {
				ya = yb = 1;
			}
		} else if(Bb<Ba){
			xa = Ba;
			xb = Bb;
			ya = yb = 1;
		} else {
			xa = xb = 1;
			ya = yb = 1;
		}

		for(int i=0; xb*i<=m; i++){
			int j = (m-xb*i)/yb;
			ans = max(ans, m + i*(xa-xb) + j*(ya-yb));
		}

	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <list>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <chrono>
#include <math.h>
using namespace std;

using lli = long long int;
using Vint = std::vector<int>;
using Vlli = std::vector<lli>;
using Wint = std::vector<Vint>;
using Wlli = std::vector<Vlli>;
using Vbool = std::vector<bool>;
using Wbool = std::vector<Vbool>;
using pii = std::pair<int, int>;
using pll = std::pair<lli, lli>;
template <class T>
using Vec = std::vector<T>;

constexpr int MOD = 1e9 + 7;
constexpr int INFi = 2e9 + 1;
constexpr lli INFl = (lli)(9e18) + 1;
const std::vector<std::pair<int, int>> DXDY = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
constexpr char BR = '\n';

#define DEBUG(x) std::cerr << #x << " = " << x << '\n';
#define FOR(i, a, b) for(int (i) = (a); (i) < (b); ++(i))
#define FOReq(i, a, b) for(int (i) = (a); (i) <= (b); ++(i))
#define rFOR(i, a, b) for(int (i) = (b); (i) >= (a); --(i))
#define FORstep(i, a, b, step) for(int (i) = (a); i < (b); i += (step))
#define REP(i, n) FOR(i, 0, n)
#define rREP(i, n) rFOR(i, 0, (n-1))
#define vREP(ele, vec) for(auto &(ele) : (vec))
#define vREPcopy(ele, vec) for(auto (ele) : (vec))
#define SORT(A) std::sort((A).begin(), (A).end())
#define RSORT(A) std::sort((A).rbegin(), (A).rend())
#define ALL(A) (A).begin(), (A).end()
// 座標圧縮 (for vector) : ソートしてから使うのが一般的 ; SORT(A) => COORDINATE_COMPRESSION(A)
#define COORDINATE_COMPRESSION(A) (A).erase(unique((A).begin(),(A).end()),(A).end())



template <class T> inline int argmin(std::vector<T> vec){return min_element(vec.begin(), vec.end()) - vec.begin();}
template <class T> inline int argmax(std::vector<T> vec){return max_element(vec.begin(), vec.end()) - vec.begin();}
template <class S, class T> inline void chmax(S &a, T b){if(a < b) a = b;}
template <class S, class T> inline void chmin(S &a, T b){if(a > b) a = b;}
template <class T> inline void reverseSORT(Vec<T> &Array){
  std::sort(Array.begin(), Array.end(), std::greater<T>());
}
inline int BitI(int k){return 1 << k;}
inline lli BitL(int k){return 1LL << k;}
inline void putsDouble(double d){printf("%.16lf\n", d);}
inline int toInt(const string &s){int res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
inline long long int toLong(const string &s){lli res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
template <class T> inline std::string toString(T n){
  if(n == 0) return "0";
  std::string res;
  if(n < 0){n = -n;while(n != 0){res += (char)(n % 10 + '0'); n /= 10;}
  std::reverse(res.begin(), res.end()); return '-' + res;}
  while(n != 0){res += (char)(n % 10 + '0'); n /= 10;} std::reverse(res.begin(), res.end()); return res;
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~






int main(void){
    string s; cin >> s;
    int cnt = 0;
    vREP(ele, s) if(ele == 'x') cnt++;
    puts((cnt <= 7) ? "YES" : "NO");
    return 0;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
         
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define mod 1000000007  
const int N = 100001; 

int fexp(int a, int b,int m){int ans = 1;while(b){if(b&1)ans=ans*a%m; b/=2;a=a*a%m;}return ans;}
int inverse(int a, int p){return fexp(a, p-2,mod);} 

// int fac[2000001];

// int nCrModPFermat(int n, int r,int p) { 
//     if (r==0) return 1; 
//     return (fac[n]*inverse(fac[r],p)%p*inverse(fac[n-r],p)%p)%p; 
// }
 

void solve(){
    int n;cin>>n;
    int ans=fexp(10,n,mod)-fexp(9,n,mod)*2+fexp(8,n,mod);
    cout<<(ans+mod+mod)%mod;
    return;
}
         
signed main(){
        IOS;    
       

        int t=1;
        // // cin>>t;
        // fac[0] = 1; 
        // for (int i=1 ; i<=2000001; i++) fac[i] = fac[i-1]*i%mod; 
        rep(i,0,t){
            // cout<<"Case #"<<i+1<<": ";
            solve();
            cout<<"\n";
        }
    //    return 0;
}

Measured memory_bytes: 3688
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
using namespace std;
int main(){
    //Seiranchan!
    string S;
    cin >>S;

    SORT(S);
    string T;
    cin >> T;

    SORT(T);
    reverse(T.begin (),T.end());

    if(S<T) cout << "Yes" <<endl;
    else cout << "No" <<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

template<int Modulo = MOD> struct Mint {
	Int val;
	constexpr Mint(Int v = 0) noexcept : val(v% Modulo) {
		if (val < 0) v += Modulo;
	}
	constexpr int getmod() { return Modulo; }
	constexpr Mint operator - () const noexcept { return val ? Modulo - val : 0; }
	constexpr Mint operator + (const Mint& r) const noexcept { return Mint(*this) += r; }
	constexpr Mint operator - (const Mint& r) const noexcept { return Mint(*this) -= r; }
	constexpr Mint operator * (const Mint& r) const noexcept { return Mint(*this) *= r; }
	constexpr Mint operator / (const Mint& r) const noexcept { return Mint(*this) /= r; }
	constexpr Mint& operator += (const Mint& r) noexcept {
		val += r.val;
		if (val >= Modulo) val -= Modulo;
		return *this;
	}
	constexpr Mint& operator -= (const Mint& r) noexcept {
		val -= r.val;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr Mint& operator *= (const Mint& r) noexcept {
		val = val * r.val % Modulo;
		return *this;
	}
	constexpr Mint& operator /= (const Mint& r) noexcept {
		Int a = r.val, b = Modulo, u = 1, v = 0;
		while (b) {
			Int t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		val = val * u % Modulo;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr bool operator == (const Mint& r) const noexcept {
		return this->val == r.val;
	}
	constexpr bool operator != (const Mint& r) const noexcept {
		return this->val != r.val;
	}
	friend ostream& operator << (ostream& os, const Mint<Modulo>& x) noexcept {
		return os << x.val;
	}
	friend istream& operator >> (istream& is, Mint<Modulo>& x) noexcept {
		Int tmp; is >> tmp;
		x = Mint<Modulo>(tmp);
		return is;
	}
	friend constexpr Mint<Modulo> modpow(const Mint<Modulo>& a, Int n) noexcept {
		Mint res(1), tmp = a;
		while (n > 0) {
			if (n & 1) res *= tmp;
			tmp *= tmp;
			n >>= 1;
		}
		return res;
	}
};

using mint = Mint<>;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	string S;
	cin >> S;

	Int len = S.size();

	Int ans = 1;
	string temp1 = "";
	temp1 += S[0];

	string temp2;
	for (Int i = 1; i < len; i++) {
		temp2 += S[i];
		if (temp1 == temp2)continue;
		else {
			temp1 = temp2;
			temp2 = "";
			ans++;
		}
	}


	cout << ans << "\n";

}

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

typedef long long ll;

int main(){
	ll n, p;
	cin >> n >> p;
	if(n==1){
		cout << p << endl;
		return 0;
	}
	ll ans = 1;
	for(ll i = 2; i <= 1e6; i++){
		int cnt = 0;
		while(p%i==0){
			p/=i;
			cnt++;
		}
		cnt/=n;
		while(cnt){
			ans*=i;
			cnt--;
		}
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int n,m,q,a[50],b[50],c[50],d[50],A[11],ans=0;

void dfs(int x, int y){
  if (x == n+1){
    int tmp = 0;
    rep(i,q){
      if (A[b[i]] - A[a[i]] == c[i]) tmp += d[i];
    }
    ans = max(ans,tmp);
  }
  else {
    for(int i=y;i<=m;i++){
      A[x] = i;
      dfs(x+1,i);
    }
  }
}

int main() {
  cin >> n >> m >> q;
  rep(i,q) cin >> a[i] >> b[i] >> c[i] >> d[i];
  A[1]=1;
  dfs(2,1);
  cout << ans << endl;
}


Measured memory_bytes: 3620
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;



int main()
{
	int n;
	cin >> n;
	vector<pair<int,int>> red(n);
	vector<pair<int,int>> blue(n);
	for (int i = 0; i < n; i++) {
		cin >> red[i].first >> red[i].second;
	}
	for (int i = 0; i < n; i++) {
		cin >> blue[i].first >> blue[i].second;
	}
	sort(red.begin(), red.end());
	sort(blue.begin(), blue.end());

	int x = 0;
	int r = 0, b = 0;
	vector<int> remained;
	while (x < 2 * n) {
		while (b < n && blue[b].first <= x) {
			
			if (blue[b].first == x) {
				
				while (b < n &&blue[b].first == x) {
					int maxy = -1;
					int index;

					for (int i = 0; i < remained.size(); i++) {
						if (remained[i] > maxy && remained[i] < blue[b].second) {
							index = i;
							maxy = remained[i];
						}
					}
						
					if (maxy != -1) {
						remained.erase(remained.begin() + index);
					}
					b++;
					
				}
				break;
			}
			b++;
			
		}
		while ( r < n &&red[r].first <= x) {
			
			if (red[r].first == x) {
				
				while (r < n &&red[r].first == x) {
					remained.push_back(red[r].second);
					r++;
				}
				break;
			}
			r++;
		}
		x++;
	}
	cout << n - remained.size() << endl;
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  char hina[n];
  
  int i;
  for(i=0; i<n; i++) cin >> hina[i];
  
  int flag = 0;
  for(i=0; i<n; i++){
    if(hina[i] == 'Y'){
      flag = 1;
      break;
    }
  }
  
  if(flag == 1) cout << "Four" << endl;
  else cout << "Three" << endl;
  
  return 0;
  
}


Measured memory_bytes: 256
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
#define dumpR(x) cerr<<"\x1b[31m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpY(x) cerr<<"\x1b[33m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpG(x) cerr<<"\x1b[32m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

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

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

const lint INF=1e18;
int X,Y,Z;
pi ps[100005];

lint Ymax[100005],Zmax[100005];
int main(){
#ifdef LOCAL_REDIR
  freopen("/home/hog/Dropbox/pg/working/in.txt","r",stdin);
#endif

  lint res=0;
  cin>>X>>Y>>Z;
  int n=X+Y+Z;
  REP(i,n){
    int a,b,c;scanf("%d%d%d",&a,&b,&c);
    res+=a;
    ps[i]={b-a,c-a};
  }
  sort(ps,ps+n,[&](pi a,pi b){
    return a.fr-a.sc>b.fr-b.sc;
  });

  priority_queue<int,vector<int>, greater<int> > pq;
  lint tot=0;
  REP(i,n){
    pq.push(ps[i].fr);
    tot+=ps[i].fr;
    if(pq.size()>Y){
      tot-=pq.top();pq.pop();
    }
    Ymax[i]=(pq.size()==Y?tot:-INF);
  }

  tot=0;
  while(!pq.empty()) pq.pop();
  for(int i=n-1;i>=0;--i){
    pq.push(ps[i].sc);
    tot+=ps[i].sc;
    if(pq.size()>Z){
      tot-=pq.top();pq.pop();
    }
    Zmax[i]=(pq.size()==Z?tot:-INF);
  }

  lint tmp=-INF;
  REP(i,n-1){
    chmax(tmp,Ymax[i]+Zmax[i+1]);
  }

  res+=tmp;
  cout<<res<<endl;

  return 0;
}






Measured memory_bytes: 3064
unittest
{
	assert( [ "5 2" ].parse.expand.solve == 18 );
	assert( [ "3 -1" ].parse.expand.solve == 0 );
	assert( [ "30 -50" ].parse.expand.solve == -1044 );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nl = input.front.split.to!( long[] );
	return tuple( nl[ 0 ], nl[ 1 ] );
}

auto solve( long n, long l )
{
	auto t = n * l + ( ( n - 1 ) * n ) / 2;
	auto mi = l;
	auto ma = l + n - 1;
	if( ma < 0 ) return t - ma;
	if( 0 < mi ) return t - mi;
	return t;
}


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

using namespace std;

int main(){
    int n, m;
    cin >> n >> m;
    int arr[n + 1] = {0}, arrw[n + 1] = {0}, cr = 0;
    for(int i = 0; i < m; ++i){
        int tmp;
        string s;
        cin >> tmp >> s;
        if(s[0] == 'W' && arr[tmp] == 0){
            arrw[tmp]++;
        }else if(s[0] == 'A'){
            if(arr[tmp] != 1)
                cr++;
            arr[tmp] = 1;
        }
    }
    int wr = 0;
    for(int i = 0; i < n + 1; ++i){
        if(arr[i] == 1){
            wr += arrw[i];
        }
    }
    cout << cr << " " << wr;
	return 0;
}


Measured memory_bytes: 1024
import sys
readline = sys.stdin.readline

N = int(readline())
X = readline().rstrip()

X0 = int(X, 2)
count1 = X.count("1")

X0mod0to1 = X0 % (count1 + 1) # 0->1に変化した際の、X0を割った余り
if count1 > 1:
  X0mod1to0 = X0 % (count1 - 1) # 1->0に変化した際の、X0を割った余り
else:
  X0mod1to0 = 0

from collections import defaultdict
dp = defaultdict(int)
dp[0] = 0
def f(x): # 愚直にf(x)を求める式
  if x in dp:
    return dp[x]
  pc = bin(x).count("1")
  val = f(x % pc) + 1
  dp[x] = val
  return val
  
val0to1 = 1
val1to0 = 1
ans = [-1] * N

for i in range(N - 1, -1, -1): # 下の桁から順に、f(Xi)の値を求める
  if X[i] == "0": # 0を1に変える場合
    pat = (X0mod0to1 + val0to1 % (count1 + 1)) % (count1 + 1)
    ans[i] = f(pat) + 1
  elif X[i] == "1": # 1を0に変える場合
    if count1 > 1:
      pat = (X0mod1to0 - val1to0 % (count1 - 1)) % (count1 - 1)
      ans[i] = f(pat) + 1
    else:
      ans[i] = 0
  val0to1 = val0to1 * 2 % (count1 + 1)
  if count1 != 1:
    val1to0 = val1to0 * 2 % (count1 - 1)

print(*ans, sep = "\n")

Measured memory_bytes: 88000
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int n,q;
    cin>>n>>q;
    ll p2=1;
    rep(i,q)p2=p2*2%mod;
    ll inv2=(mod+1)/2;
    int a[n];
    rep(i,n)cin>>a[i];
    ll dp[n][n];
    rep(i,n)rep(j,n)dp[i][j]=(a[i]>a[j] ? p2 : 0 );
    rep(i,q){
        int x,y;
        cin>>x>>y;
        --x;--y;
        dp[x][y]=dp[y][x]=(dp[x][y]+dp[y][x])*inv2%mod;
        rep(j,n){
            if(j==x||j==y)continue;
            dp[x][j]=dp[y][j]=(dp[x][j]+dp[y][j])*inv2%mod;
        }
        rep(j,n){
            if(j==x||j==y)continue;
            dp[j][x]=dp[j][y]=(dp[j][x]+dp[j][y])*inv2%mod;
        }
    }
    ll ans=0;
    rep(i,n)rep(j,i)ans+=dp[j][i];
    cout<<ans%mod<<endl;
    return 0;
}

Measured memory_bytes: 70528
#include <string.h>
#include<stdio.h>
int main(void)
{
	int i,sum=0;
	int flag=0;
	char x[1002];
	scanf("%s",x);
	do{
		
		for(i=0;i<1002;i++){
			if(x[i]==0){
				printf("%d\n",sum);
				break;
			}else{
				sum+=x[i]-0x30;
			}
		}
		sum=0;
		scanf("%s",x);
	}while(x[0]!=0x30);

	return 0 ;
}

Measured memory_bytes: 536
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    string s;
    cin>>s;
    if(s.length()%2)reverse(all(s));
    cout<<s<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
 
int main() {
    string s, t;
    cin >> s >> t;
    sort(s.begin(),s.end());
    sort(t.begin(),t.end(),greater<char>());
    if(s<t) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#axino's copy

def move(up, bottom, right, left, front, back, direction):
    if direction == 'N':
        return(front, back, right, left, bottom, up)
    elif direction == 'S':
        return(back, front, right, left, up, bottom)
    elif direction == 'E':
        return(left, right, up, bottom, front, back)
    elif direction == 'W':
        return(right, left, bottom, up, front, back)

def check(up, bottom, right, left, front, back, up_current, front_current):
    if front_current == front and up_current == up:
        print(right)
    elif front_current == front:
        if left == up_current:
            print(up)
        elif bottom == up_current:
            print(left)
        elif right == up_current:
            print(bottom)
    elif up_current == up:
        if right == front_current:
            print(back)
        elif back == front_current:
            print(left)
        elif left == front_current:
            print(front)
    else:
        up, bottom, right, left, front, back = move(up, bottom, right, left, front, back, 'S')
        check(up, bottom, right, left, front, back, up_current, front_current)
up, front, right, left, back, bottom = input().split()
times = int(input())

for i in range(times):
    up_current, front_current = input().split()
    check(up, bottom, right, left, front, back, up_current, front_current)

Measured memory_bytes: 7684
#include<stdio.h>
int main(void){
	int i,j,n,rank,Cards[4][13]={0};
	char mark;
	scanf("%d",&n);
	n *= 2;
	for(i = 0;i < n;i++){
		scanf("%c %d",&mark,&rank);
		switch(mark){
		case 'S':
			Cards[0][rank-1]++;
			break;
		case 'H':
			Cards[1][rank-1]++;
			break;
		case 'C':
			Cards[2][rank-1]++;
			break;
		case 'D':
			Cards[3][rank-1]++;
			break;
		}
	}
	for(i = 0;i < 4;i++){
		for(j = 0;j < 13;j++){
			if(Cards[i][j] == 0){
				switch(i){
				case 0:
					printf("S %d\n",j+1);
					break;
				case 1:
					printf("H %d\n",j+1);
					break;
				case 2:
					printf("C %d\n",j+1);
					break;
				case 3:
					printf("D %d\n",j+1);
					break;
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 596
#include <iostream>

using namespace std;

int main()
{
    char a;
    cin >> a;

    if (a >= 'A' && a <= 'Z')
    {
        cout << "A" << endl;
    }
    else if (a >= 'a' && a <= 'z')
    {
        cout << "a" << endl;
    }

    return 0;
}

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

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

  double sum = 0;
  for(int i=0; i<n; i++) sum += 1.0/a[i];

  cout<<fixed<<setprecision(10)<<1.0/sum<<endl;

  return 0;
}

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

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

    int h, w;
    cin >> h >> w;

    vector< string >v(h);
    for (string &x : v) cin >> x;

    string mid(w-2, '#');
    for (int i = 0; i < h; i++) {
        string t = "#";
        if (i%2) t += v[i].substr(1, w-2);
        else t += mid;
        t += '.';
        cout << t << "\n";
    }
    cout << "\n";

    for (int i = 0; i < h; i++) {
        string t = ".";
        if (i%2==0) t += v[i].substr(1, w-2);
        else t += mid;
        t += '#';
        cout << t << "\n";
    }

    return 0;
}


Measured memory_bytes: 1024
H,W=gets.split.map(&:to_i)
c=H.times.map { gets.chomp.chars }

dx=[-1, 0, 1, -1, 1, -1,  0,  1]
dy=[ 1, 1, 1,  0, 0, -1, -1, -1]

H.times do |i|
  W.times do |j|
    if c[i][j]=='#'
      print '#'
    else
      s=0
      8.times do |k|
        y=i+dx[k]
        x=j+dy[k]
        next if x<0 || x>=W
        next if y<0 || y>=H
        s+=1 if c[y][x]=='#'
      end
      print s
    end
  end
  puts
end

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


int main(){
    int a=1, b=1, c=1;
    string x;
    cin >> x;

    for (int i = 0; i < 3; i++){
        if(x[i]=='a') a--;
        if (x[i] == 'b') b--;
        if (x[i] == 'c') c--;
    }

    if(a==b && b==c) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    long N;
    cin>>N;
    set<long> paper;
    for(int i=0,A;i<N;i++){
        cin>>A;
        if(paper.count(A)) paper.erase(A);
        else paper.insert(A);
    }
    cout<<paper.size()<<endl;
}

Measured memory_bytes: 4864
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    ll n,k;cin >> n >>k;
    vl a(n),f(n);
    rep(i,n)cin >> a[i];
    rep(i,n)cin >> f[i];
    sort(all(f));sort(all(a));
    rev(all(f));
    vl pro(n);rep(i,n)pro[i]=f[i]*a[i];
    ll ok=0;rep(i,n)chmax(ok,pro[i]);
    ll ng=-1;
    while(abs(ok-ng)>1){
        ll mid=(ok+ng)/2;
        ll tmp=0;
        rep(i,n){
            if(mid<pro[i]){
                tmp+=(pro[i]-mid+f[i]-1)/f[i];
            }
        }
        if(tmp<=k)ok=mid;
        else ng=mid;
    }
    cout << ok <<endl;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
namespace FAST_IO
{
	template<typename T> void read(T &a)
	{
		a=0;
		int f=1;
		char c=getchar();
		while(!isdigit(c))
		{
			if(c=='-')
			{
				f=-1;
			}
			c=getchar();
		}
		while(isdigit(c))
		{
			a=a*10+c-'0';
			c=getchar();
		}
		a=a*f;
	}
	template <typename T> void write(T a)
	{
		if(a<0)
		{
			a=-a;
			putchar('-');
		}
		if(a>9)
		{
			write(a/10);
		}
		putchar(a%10+'0');
	}
	template <typename T> void writeln(T a)
	{
		write(a);
		puts("");
	}
}
int n,k;
int main()
{
	cin>>n>>k;
	cout<<n-k+1;
}


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

int main(){
	int n, a[] = {1,2,4,8,16,32,64,128,256,512};
	bool r[10];
	while(cin >> n){
		fill(r, r+10, false);
		for(int s = 9;0 < n && 0 <= s;s--){
			if(n >= a[s]){r[s] = true;n -= a[s];}
		}
		bool f = false;
		for(int i = 0;i < 10;i++){
			if(r[i] == true){
				if(f == true)cout << " ";
				cout << a[i];f = true;
			}
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3068
#include<stdio.h>
#define N 100000
int binary(int );
int A[N+1],n;

int main ()  {
  int q,key,sum = 0,i;

  scanf("%d",&n);
for(i=0;i<n;i++)  scanf("%d", &A[i]);
  scanf("%d", &q);

for(i=0;i<q;i++) {
    scanf("%d", &key);
    if(binary(key)) sum++;
}
  printf("%d\n",sum);

  return 0;
}

int  binary(int key) {
   int left=0,right=n,mid;
   while(left < right) {
     mid = (left + right)/2;
      if(A[mid] == key)
         return 1;
         else if(key < A[mid])
         right = mid;
         else left = mid +1;
   }
   return 0;
}

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

#define FOR(i,l,r) for(int i = (l);i < (r);i++)
#define ALL(x) (x).begin(),(x).end()
template<typename T> bool chmax(T& a,const T& b){return a < b ? (a = b,true) : false;}
template<typename T> bool chmin(T& a,const T& b){return b < a ? (a = b,true) : false;}
typedef long long ll;

ll N,X;
ll mn [2000] [2000];
const ll INF = 1e17;

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

	cin >> N >> X;
	vector<ll> A(N);
	FOR(i,0,N){
		cin >> A [i];
	}
	FOR(i,0,N){
		mn [i] [0] = A [i];
		for(int j = 1;j < N;j++){
			mn [i] [j] = min(mn [i] [(j - 1 + N) % N],A [(i - j + N) % N]);
		}
	}

	ll ans = INF;
	for(int i = 0;i < N;i++){
		ll sum = X * i;
		for(int j = 0;j < N;j++){
			sum += mn [j] [i];
		}
		chmin(ans,sum);
	}

	cout << ans << endl;

	return 0;
}


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

int main() {
  int N;
  cin >> N;
  
  vector<int> list(N-1);
  vector<int> ans(N);
  for(int i=0;i<N-1;i++){
    cin >> list[i];
  }
  
  for(int i=0;i<N;i++){
    ans[i] = 0;
  }
  
  for(int i=0;i<N-1;i++){
    ans[list[i]-1] += 1;
  }
  
  for(int i=0;i<N;i++){
    cout << ans[i] << endl;
  }
}


Measured memory_bytes: 4788
memo = [-1]*100
mepp = [-1]*100
def getPB(N,k):
    if (N==0):
        return 1,1 if k>0 else 0
    if (memo[N] != -1 and k >= memo[N] and mepp[N]!=-1 ):
        return memo[N] , mepp[N]
    if (memo[N] != -1 and k <= 0):
        return memo[N] , 0
    #c =  1+getPB(N-1)+1+getPB(N-1)+1 # BxPxB
    c,p = 1,0
    _c,_p=getPB(N-1,k-c)
    c,p=c+_c,p+_p
    c,p=c+1,(p+1 if (k-c>0) else p)
    _c,_p=getPB(N-1,k-c)
    c,p=c+_c,p+_p
    c += 1
    memo[N] = c
    if (k-c>=0):
        mepp[N] = p
    return c,p
N,X = [ int(it) for it in input().split() ]
print ( getPB(N,X)[1] )

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    string s,t;
    cin>>s;
    cin>>t;
    if(s.length()!=t.length()-1){
        cout<<"No"<<endl;
        return 0;
    }
    for(int i=0;i<s.length();i++){
        if(s[i]!=t[i]){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 3640
A,B,C,D,E,F = map(int, input().split(' '))
water = []
for i in range(int(F/(A*100))+1):
    for j in range(int(F/(B*100))+1):
        water.append(100*A*i+100*B*j)
water = list(set(water))
water = sorted(water)
water = [i for i in water if i <= F]
water = water[::-1]
water.remove(0)

suger = []
for i in range(int(F/C)+1):
    for j in range(int(F/D)+1):
        suger.append(C*i+D*j)
suger = list(set(suger))
suger = sorted(suger)
suger = [i for i in suger if i <= F]
suger = suger[::-1]

limit = E / (100.0+E)
maxAns = 0.0
for w in water:
    for s in suger:
        if s + w > F:
            continue
        tmp = s / float(s+w)
        if tmp <= limit and tmp >= maxAns:
            maxAns = tmp
            maxWS = w+s
            maxS = s
print(str(maxWS) + ' ' + str(maxS))


Measured memory_bytes: 22552
#include<stdio.h>
int main(void)
{
    int n,i,j,a[100],min=0,max=0,sum=0,temp=0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
        if(a[i]<a[min])
            min=i;
        if(a[i]>a[max])
            max=i;
    }
    for(j=a[min];j<=a[max];j++){
        temp=0;
        for(i=0;i<n;i++){
            if(j==a[min]){
                sum+=(a[i]-j)*(a[i]-j);
            }
            else{
                temp+=(a[i]-j)*(a[i]-j);
            }
        }
        if(j>a[min]&&temp<sum)
            sum=temp;
    }
    printf("%d",sum);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main() {
	ll n, d;
	cin >> n >> d;
	vector<double> x(n), y(n);
	rep(i, n) cin >> x[i] >> y[i];
	int ans = 0;
	rep(i, n) {
		if(x[i]*x[i]+y[i]*y[i]<=d*d) ans++;
	}
	
	cout << ans << endl;
	return 0;
}

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

using namespace std;

main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int a, b;
    cin >> a >> b;
    for (int ans = 0; ans <= 100; ++ans) {
        if (ans * a - ans + 1 >= b) {
            cout << ans << '\n';
            return 0;
        }
    }
    return 0;
}



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

int main()
{
int N;
cin >> N;
int t[N+1],x[N+1],y[N+1];
bool j = true;
for(int i = 1; i <= N; i++) cin >> t[i] >> x[i] >> y[i];
t[0] = 0;
x[0] = 0;
y[0] = 0;

for(int i = 1; i <= N; i++){
    int dt = t[i] - t[i-1];
    int dx = abs(x[i] - x[i-1]);
    int dy = abs(y[i] - y[i-1]);
    if (dt < dx + dy || (t[i]%2 == 1 && (x[i]+y[i])%2 == 0) || (t[i]%2 == 0 && (x[i]+y[i])%2 == 1)) j=false;
}
if(j) cout << "Yes" << endl;
else cout << "No" << endl;
}

Measured memory_bytes: 1536
N=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

kill=0
a1=a[0]
for i in range(N):
    if a1 >= b[i]:
        kill += b[i]
        a1 = a[i+1]
    elif a1+a[i+1] >= b[i]:
        kill += b[i]
        a1 = a[i+1]+a1-b[i]
    else:
        kill += a1 +a[i+1]
        a1 = 0
print(kill)

Measured memory_bytes: 19156
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
#define N 100001
#define INF 10000000000
using namespace std;

typedef long long ll;
int main()
{
    int n;
    ll a[N] = {};
    cin >> n;
    int p = 0, z = 0, m = 0;
    FOR(i, 0, n)
    {
        cin >> a[i];
        if (a[i] > 0)
            p++;
        else if (a[i] == 0)
            z++;
        else
            m++;

        a[i] = abs(a[i]);
    }
    sort(a, a + n);

    int x = m % 2;
    if (z > 0)
        x = 0;
    ll r = 0;
    FOR(i, x, n)
    r += a[i];

    if(x == 1)
        r -= a[0];

    cout << r << "\n";
    return 0;
}

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


"""
愚直解
Nを2~50までは試せるけど、各要素の値は何にすればいいかよくわからない。
なので、全探索的な解き方は期待できない。

一つからN引いて、残りに＋１するので、一回の操作で全体の合計から１減っていることになる
なので、開始時点で全体の合計は、(N-1)*N + K ~ N*N+K になるのか?

ある操作を繰り返して最後に～系の問題は、最後から操作を逆におこなって最初の状態に戻るようにすると解けることがおおい
今回はK回の操作の後に数列の最大値が N-1 以下になるので、N-1から開始して、ある要素にN足して全体から１引く、をK回やればよい。
Nは50までなので、とりあえず５０とする（小さすぎなければよいと判断）

操作が配列の要素すべてに一回ずつ行われたとき、NふえてN-1減るので、1増えただけになる
"""
N = 50
ans = [49] * 50

cnt_all = K // N # 全体に1足される回数
rem = K % N # 初めのrem個の要素は N - (rem-1)され、残りの要素は普通にrem減る

for i in range(N):
    if i < rem:
        ans[i] += cnt_all + N - (rem-1)
    else:
        ans[i] += cnt_all - rem


print(50)
print(*ans)

Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>

void utol(char *s) {
    int i;
    for (i=0; i<sizeof(s); i++) if (s[i]>=65 && s[i]<=90) s[i]+=32;
}

int main(void) {
    char w[11]={'\0'}, t[1001]={'\0'}, *word;
    int i, n;

    scanf("%s", w);
    utol(w);
    n=0;
    while (1) {
        scanf("%s", t);
        if (strcmp(t, "END_OF_TEXT") == 0) break;
        utol(t);
        i=0;
	    do {
            if (i==0) (word = strtok(t, " ")), i++;
            if (strcmp(w, word) == 0) n++;
        } while ((word = strtok(NULL, " "))!=NULL);
        for (i=0; i<sizeof(t); i++) t[i]='\0';
    }
    printf("%d\n", n);
    return 0;
}



Measured memory_bytes: 2104
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    long long int res = k;
    for (int i = 1; i < n; i++) {
        res *= (k - 1);
    }
    cout << res << endl;
}


Measured memory_bytes: 3564
x,k,d = map(int,input().split())

min_p = abs(x)//d
min_n = min_p + 1
rest_p = abs(x)- d*min_p
rest_n = rest_p - d

if k < min_p:
  print(abs(x) - k*d)
elif (k-min_p) % 2 == 0:
  print(rest_p)
else:
  print(abs(rest_n))
    



Measured memory_bytes: 9116
from collections import Counter
s = input()
N = len(s)
a = -1
b = -1
for i in range(N):
    for j in range(i+2,i+4):
        if max(Counter(s[i:j]).values()) > (j-i)/2:           
            a = i+1
            b = j
            break
    else:
        continue
    break
    
print(a,b)

Measured memory_bytes: 75004
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;

const int N = 60;
int n, m, q, A[N], a[N], b[N], c[N], d[N], ans;
int culc();

void f(int i, int pi){
    if (i == n+1) {
        ans = max(ans, culc());
        return;
    }
    FOR(j, pi, m+1){
        A[i] = j;
        f(i + 1, j);
    };
}

int culc(){
    int cnt = 0;
    rep(i, q) {
        if (A[b[i]] - A[a[i]] == c[i]) {
            cnt += d[i];
        }
    };
    return cnt;
}

int main()
{
    cin >> n >> m >> q;
    
    rep(i, q) cin >> a[i] >> b[i] >> c[i] >> d[i];

    f(1, 1);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3636
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    c = list(map(int, input().split()))
    mod = pow(10, 9) + 7
    
    c.sort(reverse=True)
    
    ans = 0
    
    for i in range(n):
        ans += (i+2) * c[i]
        ans %= mod
    
    ans *= pow(2, n*2-2, mod)
    ans %= mod
    
    print(ans)
    
    
if __name__ == "__main__":
    main()


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

// #define int long long

/* cpp template {{{ */

/* short */
#define pb push_back
#define print(x) cout << x << '\n'
#define Fi first
#define Se second

/* REPmacro */
#define REPS(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = 1; i <= (n); i++)
#define DEPS(i, a, n) for (int i = (a); i >= n; i--)
#define DEP(i, n) for (int i = (n); i >= 0; i--)

/* typedef */
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;

/* const */
const int INF = INT_MAX;
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

/* func */
inline bool is_uruu(int y) {return (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0));}
inline bool is_inside(int y, int x, int H, int W) {return (y >= 0 && x >= 0 && y < H && x < W);}

/* }}} */

const double BEST = 22.0;

signed main()
{
  ios::sync_with_stdio(false);
  int n;
  
  for (; cin >> n, n;){
    // Fi->number Se->bmi_diff
    vector<pair<int, double> > body(n);

    REP(i, n){
      double h, w;
      cin >> body[i].Fi >> h >> w;
      h /= 100;
      body[i].Se = fabs(BEST - w / (h * h));
    }

    pair<int, double> ans(body[0].Fi, body[0].Se);
    RREP(i, n - 1){
      if (body[i].Se <= ans.Se){
        if (body[i].Se == ans.Se){
          if (body[i].Fi < ans.Fi){
            ans = body[i];
          }
        } else {
          ans = body[i];
        }
      }
    }

    print(ans.Fi);
  }
  return (0);
}

Measured memory_bytes: 1248
//-----------------------
// author : xyqkoala
// time : 2020-09-14
//-----------------------

#include<iostream>
#include<vector>
#include<string>
#include<deque>
#include<unordered_map>
#include<unordered_set>
#include<queue>
#include<algorithm>
#include<cmath>
#include<numeric>
using namespace std;

typedef long long LL;
const int MOD = 1e9+7;

void solve();


int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int T = 1;
	// cin>>T;
	while(T--){
		solve();
	}
	return 0;
}


int dfs(vector<int> &dp,int x){
	if(x<0) return 0;
	if(dp[x] != -1) return dp[x];
	if(x==0) return dp[x];
	if(x<3) return 0;
	dp[x] = 0;
	for(int i=3;i<=x;i++){
		dp[x] = (dp[x]+dfs(dp,x-i))%MOD;
	}
	return dp[x];
}
void solve(){
	int n;
	cin>>n;
	vector<int> dp(n+1,-1);
	dp[0] = 1;
	cout<<dfs(dp,n)<<endl;
}


void solve1(){
	int n;
	cin>>n;
	vector<int> dp(n+1,0);
	dp[0] = 1;
	LL s = 1;
	for(int i=3;i<=n;i++){
		dp[i] = s;
		s = (s+dp[i-2])%MOD;
	}
	cout<<dp[n]<<endl;
}

Measured memory_bytes: 3636
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int w = sc.nextInt(), h = sc.nextInt(), n = sc.nextInt();
		int xmax = w, ymax = h, xmin = 0, ymin = 0;
		for(int i = 0; i < n; i++){
			int x = sc.nextInt(), y = sc.nextInt(), a = sc.nextInt();
			if(a == 1) xmin = Math.max(xmin, x);
			if(a == 2) xmax = Math.min(xmax, x);
			if(a == 3) ymin = Math.max(ymin, y);
			if(a == 4) ymax = Math.min(ymax, y);
		}
		if(xmax-xmin < 0 || ymax-ymin < 0){
			System.out.println(0);
		}else{
			System.out.println((xmax-xmin) * (ymax-ymin));
		}
	}
}

Measured memory_bytes: 22100
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <stack>
#include <string>
using namespace std;

int main(){
    int a,b;
    cin>>a>>b;
    char ca=a+'0';
    char cb=b+'0';
    string sa;
    string sb;
    while(b--){
        sa.push_back(ca);
    }
    while(a--){
        sb.push_back(cb);
    }
    cout<<min(sa,sb)<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e6+5;
int n,sum,a[N];
signed main()
{
	cin>>n;
	for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
	for(int i=1;i<=n;i++)
	{
		sum^=a[i];
	}
	if(sum==0)puts("Yes");
	else puts("No");
}

Measured memory_bytes: 1024
#include<stdio.h>

int binarySearch(int *A,int key);

int cnt;
int n,q;

int main(){
  int s[100000],t[50000];
  int i,j;
  //in
  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&s[i]);

  scanf("%d",&q);
  for(i=0;i<q;i++)
    scanf("%d",&t[i]);

  //roop
  for(j=0;j<q;j++){
    if(binarySearch(s,t[j])!=0)cnt++;
  }
  //out
  printf("%d\n",cnt);
  return 0;
}
//func
int binarySearch(int *A,int key){
  int left,right,mid;
  int hit;
  
  left = 0;
  right = n;
  while (left < right){
    hit=0;
    mid = (left + right)/2;
    if (key == A[mid]){
      hit=1;
      return 1;
    }
    if (key > A[mid])
      left = mid + 1;
    else if (key < A[mid])
      right = mid;
  }
  return 0;
}




Measured memory_bytes: 2292
#include<stdio.h>
int main(void){
	int n,m;
	
	char str[1000];
	int i, j;
    int ans = 0;

	scanf("%s", str);

	int count = 0;
	int maru = 0;

	for (i = 0; str[i] != '\0'; i++) {
		if (str[i] == 'o') {
			maru++;
		}
		count++;
	}
	
	int nokori = 0;
	nokori = 15 - count;

	if (maru >= 8) {
		printf("YES\n");
	}
	else if (maru <= 7) {
		if (nokori + maru >= 8) {
			printf("YES\n");
		}
		else {
			printf("NO\n");
		}
	}
	

	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
using namespace std;

int main(){
    int N;
    cin >> N;
    map<string, int> mp;
    int max = 0;
    vector<string> S(N);
    for (int i = 0; i < N;i++){
        cin >> S[i];
        mp[S[i]]++;
        if(max < mp[S[i]])
            max = mp[S[i]];
    }

    vector<string> ans(0);
    for (int i = 0; i < N;i++){
        if(mp[S[i]] == max)
            ans.push_back(S[i]);
    }
    sort(ans.begin(), ans.end());
    ans.erase(unique(ans.begin(), ans.end()), ans.end());
    
    for (int i = 0;i < (int)ans.size();i++){
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 28404
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include<iomanip>

using namespace std;
typedef long long ll;

int main() {
	int N;
	cin >> N;
	vector<int> s(N);
	for (int i = 0; i < N; i++) cin >> s[i];
	int ans = 0;
	for (int i = 0; i < N; i++) ans += s[i];
	if (ans % 10 != 0) {
		cout << ans << endl;
	}
	else {
		sort(s.begin(), s.end());
		for (int i = 0; i < N; i++) {
			if (s[i] % 10 != 0) {
				ans -= s[i];
				cout << ans << endl;
				return 0;
			}
		}
		cout << 0 << endl;
	}
	
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define ll long long
#define maxn 300005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define pii pair<int,int>
const int mod = 1e9 + 7;
int a[55],b[55],c[55],d[55];
int n,m,q;
int v[12];
int mx = 0;
void dfs(int cur) {
    if (cur == n + 1) {
        int sum = 0;
        for (int i = 0 ; i < q; i++) {
            if (v[b[i]] - v[a[i]] == c[i]) {
                sum += d[i];
            }
        }
        mx = max(mx, sum);
        return;
    }
    for (int i = max(1,v[cur-1]);i<=m;i++) {
        v[cur] = i;
        dfs(cur+1); 
    }
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //int n, m;
    cin >> n >> m >> q;
    for (int i = 0 ; i < q ; i++) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    dfs(1);
    cout << mx << '\n';
}

Measured memory_bytes: 3656
#[allow(unused_imports)]
use proconio::{fastout, input, marker::*};

use std::cmp::Reverse;
const INF: i32 = std::i32::MAX;

#[fastout]
fn main() {
   input! {
      h: usize,
      w: usize,
      k: i32,
      mut s: (i32, i32),
      mut g: (i32, i32),
      c: [Bytes; h]
   }
   s.0 -= 1;
   s.1 -= 1;
   g.0 -= 1;
   g.1 -= 1;
   let mut d = vec![vec![INF; w]; h];
   let ps = [[1, 0], [-1, 0], [0, 1], [0, -1]];
   d[s.0 as usize][s.1 as usize] = 0;
   let mut q = std::collections::BinaryHeap::new();
   q.push((Reverse(0), 0, s.0, s.1));
   q.push((Reverse(0), 1, s.0, s.1));
   q.push((Reverse(0), 2, s.0, s.1));
   q.push((Reverse(0), 3, s.0, s.1));
   while let Some((Reverse(dd), p, x, y)) = q.pop() {
      let p1 = (1 - (p / 2)) * 2;
      let p2 = p1 + 1;
      let mut i = 0;
      loop {
         let xn = x + ps[p][0] * (i + 1);
         let yn = y + ps[p][1] * (i + 1);
         if xn < 0
            || xn >= h as i32
            || yn < 0
            || yn >= w as i32
            || c[xn as usize][yn as usize] == b'@'
         {
            break;
         }
         let dn = dd + i / k + 1;
         if d[xn as usize][yn as usize] > dn {
            d[xn as usize][yn as usize] = dn;
            q.push((Reverse(dn), p1, xn, yn));
            q.push((Reverse(dn), p2, xn, yn));
         }
         i += 1;
      }
   }
   if d[g.0 as usize][g.1 as usize] == INF {
      println!("{}", -1);
   } else {
      println!("{}", d[g.0 as usize][g.1 as usize]);
   }
}


Measured memory_bytes: 36068