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

#define ll             long long
#define LL             long long
#define pii            pair<int, int>
#define pll            pair<ll, ll>
#define pil            pair<int, ll>
#define pli            pair<ll, int>
#define vi             vector<int>
#define vl             vector<ll>
#define vii            vector<pii>
#define vll            vector<pll>
#define vil            vector<pil>
#define vli            vector<pli>
#define pb             push_back
#define ppb            pop_back
#define mp             make_pair
#define ff             first
#define ss             second
#define sz(x)          (int)x.size()
#define TN             typename
#define all(v)         v.begin(), v.end()
#define fill(a, b)     memset(a, b, sizeof(a))
#define endl           '\n'

template <TN T> T gcd(T a, T b) {return !b ? a : gcd(b, a % b);}
template <TN T> T lcm(T a, T b) {return a * (b / gcd(a, b));}
template <TN T> T sqr(T a) {return a * a;}
template <TN T> T cube(T a) {return a * a * a;}
template <TN T> inline void smin(T &a, T b) {a = a < b ? a : b;}
template <TN T> inline void smax(T &a, T b) {a = a > b ? a : b;}

template <TN T> inline void Int(T &n) {
	n = 0; int f = 1; register int ch = getchar();
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
	for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';
	n = n * f;
}

#define error(args...) {vector <string> _v = split(#args, ','); err(_v.begin(), args); cout << endl;}
vector <string> split(const string &s, char c) {
	vector <string> v;
	stringstream ss(s); string x;
	while (getline(ss, x, c)) v.emplace_back(x);
	return move(v);
}
void err(vector <string> :: iterator it) {}
template <typename T, typename... Args>
void err(vector <string> :: iterator it, T a, Args... args) {
	cout << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << ", ";
	err(++it, args...);
}

inline int in() {int n; scanf("%d", &n); return n;}
inline ll Lin() {ll n; scanf("%lld", &n); return n;}
inline double Din() {double n; scanf("%lf", &n); return n;}

inline int add(int a, int b, int mod) {a += b; return a >= mod ? a - mod : a;}
inline int sub(int a, int b, int mod) {a -= b; return a < 0 ? a + mod : a;}
inline int mul(int a, int b, int mod) {return (ll)a * b % mod;}

const int N          = 2e5 + 5;
const ll  Mod        = (ll)1e9 + 7;
const int inf        = (int)2e9;
const ll  Inf        = (ll)1e18;
const int mod        = (int)1e9 + 7;



int solve() {
	int n = in();
	vi h(n + 1);
    for (int i = 1; i <= n; i++) {
        h[i] = in();	
    }
    vi dp(n + 1, inf);
    dp[1] = 0;
    for (int i = 1; i <= n; i++) {
        for(int j = i + 1; j <= i + 2; j++) {
        	if(j <= n) smin(dp[j], dp[i] + abs(h[i] - h[j]));
        }
    }
    printf("%d\n", dp[n]);
	return 0;
}

int main() {
	int test = 1, tc = 0;
	//scanf("%d", &test);
	while (test--) {
		//printf("Case %d: ", ++tc);
		solve();
	}
	return 0;
}





Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
// -----------------<fast IO>------------------
#define IOS             ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FLSH             fflush(stdout)
#define fileIO(name) \
    freopen(name".in", "r", stdin); \
    freopen(name".out", "w", stdout);
#define PRECISION(x)     cout << fixed << setprecision(x);
// -----------------<TypeDef Start>------------------
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
// -----------------<Constants>------------------
const int MAXN = 1000005;
const int SQRTN = 1003;
const int LOGN = 22;
const double PI=acos(-1);

const int INF=1e9;

int MOD = 1000000007;
const int FMOD = 998244353;
const double eps = 1e-9;
/*ll gcd(ll a,ll b)
{
    if(a==0)
    return(b);
    return(gcd(b%a,a));
}*/
// --------------------------------------------------</TEMPLATE>--------------------------------------------------
ll arr[505][505];
ll brr[505][505];
void solve()
{
    ll n,w;
    cin>>n>>w;
    vector<pair<ll,ll> > v(n);
    ll s=0;
    for(ll i=0;i<n;i++)
    {
        cin>>v[i].first>>v[i].second;
        s+=v[i].second;
    }
    ll dp[s+1];
    for(ll i=0;i<s+1;i++)
        dp[i]=INT_MAX;
    dp[0]=0;
    for(ll i=0;i<n;i++)
    {
        for(ll j=s-v[i].second;j>=0;j--)
            dp[j+v[i].second]=min(dp[j+v[i].second],v[i].first+dp[j]);
    }
    ll ans=0;
    for(ll i=0;i<=s;i++)
    {
        if(dp[i]<=w)
            ans=max(ans,i);
    }
    cout<<ans<<endl;
}

int main()
{
    IOS
    ll t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return(0);
}


Measured memory_bytes: 4392
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

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; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

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

int dist[101010][3];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<vector<int>> to(n);
    REP(i,m){
        int a, b;
        cin >> a >> b;
        --a, --b;
        to[a].push_back(b);
    }
    int sv, tv;
    cin >> sv >> tv;
    --sv, --tv;
    REP(i,n) REP(j,3) dist[i][j] = INF;
    queue<P> q;
    q.push(P(sv,0));
    dist[sv][0] = 0;
    while(!q.empty()){
        int v = q.front().first;
        int l = q.front().second;
        q.pop();
        for(int u : to[v]){
            int nl = (l+1) % 3;
            if(dist[u][nl] != INF) continue;
            dist[u][nl] = dist[v][l] + 1;
            q.push(P(u,nl));
        }
    }
    int ans = dist[tv][0];
    if(ans == INF) ans = -1;
    else ans /= 3;
    cout << ans << endl;
}

Measured memory_bytes: 6912
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(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 INF 2e9
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> pint;
typedef vector<int> vint;
#define MSG(a) cout << #a << " " << a << "\n";
 
 
int main(){
  int n; cin >> n;
  int m; cin >> m;
  int c; cin >> c;
  vint b(m); REP(i,m) cin >> b.at(i); 
  vector<vector<int>> a(n,vector<int>(m));
  
  REP(i,n){
    REP(j,m){
      cin >> a.at(i).at(j);
    }
  }
  int count = 0;
  int sum = 0;
  REP(i,n){
    sum = 0;
    REP(j,m){
      sum += a.at(i).at(j)*b.at(j);
    }
    if(sum + c > 0) count++;
  }  
  
  cout << count <<"\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#define REP(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long LL;

const LL MOD = 1000000007;
vector<LL> fac(100101), ifac(100101);

LL modpow(LL x, LL n) {
  LL ret = 1;
  while(n!=0) {
    if(n&1) {
      ret = ret * x % MOD;
    }
    x = x * x % MOD;
    n >>= 1;
  }
  return ret;
}

void prepare() {
  fac[0] = 1; ifac[0] = 1;
  REP(i, 100100) {
    fac[i+1] = fac[i] * (i+1) % MOD;
    ifac[i+1] = ifac[i] * modpow(i+1, MOD-2) % MOD;
  }
}

LL comb(int a, int b) {
  return fac[a] * (ifac[b] * ifac[a-b] % MOD) % MOD; 
}

map<int,int> factorize(int n) {
  map<int,int> m;
  for(int i = 2; i*i <= n; ++i) {
    int c = 0;
    while(n%i == 0) {
      n /= i;
      ++c;
    }
    if(c != 0) {
      m[i] = c;
    }
  }
  if(n != 1) {
    m[n] = 1;
  }
  return m;
}

int main(){
  prepare();
  int N, M;
  cin >> N >> M;
  LL ret = 1;
  for(const auto& p : factorize(M)) {
    int n = p.second;
    ret = ret * comb(N-1+n, n) % MOD;
  }
  cout << ret << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long
using namespace std;
void read(int &x){
	char c;x=0;int b=1;do{c=getchar();if(c==45)b=-1;}while(c>57||c<48);
	do x=x*10+c-48,c=getchar();while(c<=57&&c>=48);x*=b;
}
void read(ll &x){
	char c;x=0;int b=1;do{c=getchar();if(c==45)b=-1;}while(c>57||c<48);
	do x=x*10+c-48,c=getchar();while(c<=57&&c>=48);x*=b;
}
ll a[200010],f[200010];
ll i,j,k,n,m;
bool cmp(ll a,ll b){return a>b;}
bool check(ll x){
	ll K=k;
	for(i=1;i<=n;i++){
		ll NEED=x/f[i];
		K-=max(0ll,a[i]-NEED);
		if(K<0)return false;
	}
	return true;
}
int main() {
	cin>>n>>k;
	for(i=1;i<=n;i++)
		read(a[i]);
	for(i=1;i<=n;i++)
		read(f[i]);
	sort(a+1,a+1+n);
	sort(f+1,f+1+n,cmp);
	ll L=0,R=1e12;
	while(R>=L){
		ll mid=L+R>>1;
		if(check(mid))R=mid-1;
		else L=mid+1;
	}cout<<R+1<<endl;
	//cerr << 1.0*clock()/CLOCKS_PER_SEC << endl;
	return 0;
}


Measured memory_bytes: 3328
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();

        if(a == b){
            System.out.println("a == b");
        }
        else if(a < b){
            System.out.println("a < b");
        }
        else if(a > b){
            System.out.println("a > b");
        }
    }
}


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

int main(){
    int N;
    cin >> N ;
    int a[N];
    int c=0;
    for(int i=1;i<=N;i++){
    cin >> a[i];
    }
    for(int i=1;i<=N;i++){
    if(i%2!=0){
        if(a[i]%2!=0){
            c++;
        }
    }
    }
    cout << c << endl;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; using ll = long long; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    string s;
    cin >> s;
    if (s == "ABC") write("ARC");
    else write("ABC");
}

Measured memory_bytes: 3568
/************************Code by Hardik Aggarwal!!!!***********************************/

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

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define endl '\n'
#define debug cout << "Hold right there sparky.....\n";
#define forn(low,high,i) for(i=low;i<high;i++)
#define forrev(high,low,i) for(i = high; i>= low;i--)
#define trace(x) cerr << #x << ": " << x << " " << endl;

typedef long long int ll;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod =998244353;
int main()
{
      

    IOS
    ll n;
    cin>>n;
    ll a[n];
    ll neg=0,sum=0,mini=1e9+5;
    for(ll i=0;i<n;i++)
        {
            cin>>a[i];
            if(a[i]<0)
            {
                neg++;

            }
            mini=min(mini,abs(a[i]));
            sum+=(abs(a[i]));
        }

    if(neg%2)
    {
        sum-=2*(mini);
    }
    cout<<sum<<endl;
    



    

    
}
    
 
    
    



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const double PI = 3.14159265358979323846;

int main() {
  int a, b;
  cin >> a >> b;
  int ans = (a-1)*(b-1);
  cout << ans << endl;
}

Measured memory_bytes: 3588
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;

#define FOR(i,n) for(ll i=0;i<n;i++) 
#define RFOR(i,n) for(ll i=n-1;i>=0;--i)
#define COUT(str) cout << str << endl

//入力
char x,y ;


int main() {

	cin >> x >> y;

	if (x > y)COUT('>');

	else if (x < y)COUT('<');

	else COUT('=');

	return 0;
}


Measured memory_bytes: 256
N = input()
A = [input() for _ in range(N)]
ans = 0
for i in range(N-1):
	ans += A[i]/2
	A[i] %= 2
	if A[i]>0 and A[i+1]>0:
		ans += 1
		A[i] -= 1
		A[i+1] -= 1
ans += A[-1]/2
print ans


Measured memory_bytes: 8964
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<complex>

using namespace std;

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

ll N, M;
ll ary[200000];
ll solve() {
    scanf("%lld%lld", &N, &M);
    REP(i, N) ary[i]=0;
    ll p1, p2;
    REP(i, M) {
        p1 = p2;
        scanf("%lld", &p2);
        if (i==0) continue;
        ary[min(p1, p2)-1]++;
        ary[max(p1, p2)-1]--;
    }
    REP(i, N) {
        if (i==0) continue;
        ary[i] += ary[i-1];
    }

    ll ans = 0;
    REP(i, N-1) {
        ll a, b, c;
        scanf("%lld%lld%lld", &a, &b, &c);
        ans += min(a*ary[i], b*ary[i]+c);
    }
    return ans;
}

int main() {
    printf("%lld\n", solve());
    return 0;
}

Measured memory_bytes: 3984
#include<bits/stdc++.h>
using namespace std;
int s[5][120000],a[5][120000],n;
int main(){
	int ans=0;
	cin>>n;
	for(int i=1;i<=2;i++)
		for(int j=1;j<=n;j++){
			cin>>a[i][j];
			s[i][j]=s[i][j-1]+a[i][j];
		}
	for(int i=1;i<=n;i++)
		if(s[1][i]+s[2][n]-s[2][i-1]>ans)
			ans=s[1][i]+s[2][n]-s[2][i-1];
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2304
H,W = map(int,input().split())

INF = 10000000000

grid = [["." for _ in range(W+1)]]

for _ in range(H):
    in_list = list("." + input())
    grid.append(in_list)

# dp[i][j] = x x: これまでに何ブロックあったか
dp = [[INF for _ in range(W+1)] for _ in range(H+1)]
dp[1][0] = 0
dp[0][1] = 0


# if grid[0][0] = "#":
#     dp[0][0] = 1
# else:
#     dp[0][0] = 0

for j in range(1,W+1):
    for i in range(1,H+1):
        if grid[i][j] == ".": # 白の場合
            dp[i][j] = min(dp[i-1][j],dp[i][j-1])
        else: # 黒の場合
            # route_top
            if grid[i-1][j] == "#": # 上も黒ならそのまあ
                route_top = dp[i-1][j]
            else:
                route_top = dp[i-1][j] + 1

            # route_left
            if grid[i][j-1] == "#": # 上も黒ならそのまあ
                route_left = dp[i][j-1]
            else:
                route_left = dp[i][j-1] + 1
            
            dp[i][j] = min(route_top,route_left)
print(dp[-1][-1])

Measured memory_bytes: 3188
#include <algorithm>
#include <iostream>
#include <map>
#include <string>

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

using namespace std;

int main(){
	int n;
	string s[100000];
	cin>>n;
	rep(i,n) cin>>s[i], sort(s[i].begin(),s[i].end());

	map<string,int> f;
	rep(i,n) ++f[s[i]];

	long long ans=0;
	for(auto a:f) ans+=a.second*(a.second-1LL)/2;
	cout<<ans<<endl;

	return 0;
}


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

int main(){
	while(1){
		int n;
		int k[10000];
		
		scanf(" %d", &n);
		if(n==0) break;
		for(int i=0; i<n; ++i) scanf(" %d", &k[i]);
		
		sort(k, k+n, greater<int>());
		if(k[0]<2){
			printf("NA\n");
			continue;
		}
		
		int ans=n;
		for(int i=0; i<n; ++i){
			if(k[i]==0) --ans;
		}
		++ans;
		
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 1244
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

n, a, b = map(int, read().split())
MOD = 10**9 + 7


def countComb(n, r, MOD=1e9 + 7):
    res = 1
    fac = 1
    for i in range(r):
        res *= n - i
        res %= MOD
        fac *= i + 1
        fac %= MOD
    return res * pow(fac, MOD - 2, MOD) % MOD


ans = pow(2, n, MOD) - 1

for k in [a, b]:
    ans -= countComb(n, k, MOD)

ans %= MOD

print(ans)


Measured memory_bytes: 3064
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	ll n,d,a ;
	cin >> n >> d >> a ;
	vector<pll> enemy(n) ;
	for(int i=0;i<n;i++) cin >> enemy.at(i).first >> enemy.at(i).second ;
	sort(all(enemy)) ;
	vll sum(n,0) ;
	ll ans = 0 ;
	for(int i=0;i<n;i++){
		if(i!=0) sum.at(i) = sum.at(i-1)+sum.at(i) ;
		if(sum.at(i)>=enemy.at(i).second) continue ;
		enemy.at(i).second -= sum.at(i) ;
		ll cnt = (enemy.at(i).second+a-1)/a ;
		ans += cnt ;
		sum.at(i) += cnt*a ;
		ll l,r,m ;
		l = i ;
		r = n ;
		while(l+1<r){
			m = (l+r)/2 ;
			if(enemy.at(m).first>enemy.at(i).first+2*d) r = m ;
			else l = m ;
		}
		if(r!=n) sum.at(r) -= cnt*a ;
	}
	cout << ans << endl ;
}


Measured memory_bytes: 4992
_ = input()
a = [int(e) for e in input().split(" ")]
b = [int(e) for e in input().split(" ")]
c = [int(e) for e in input().split(" ")]
res = 0
for i,j in enumerate(a):
  res += b[j-1]
  if i != 0 and j - a[i-1] == 1:
    res += c[j-2]
print(res) 

Measured memory_bytes: 9208
fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let s = read(&mut stdin_lock, &mut buf, b'\n');
    println!("{}", solve(s));
}

fn solve(s: String) -> String {
    s.chars()
        .map(|c| match c {
            '1' => '9',
            '9' => '1',
            _ => unreachable!(),
        })
        .collect()
}

#[test]
fn example1() {
    assert_eq!("991", solve("119".to_owned()))
}

#[test]
fn example2() {
    assert_eq!("111", solve("999".to_owned()))
}


Measured memory_bytes: 4352
s = input()

n = len(s)
s_inv = [s[n-1-i] for i in range(n)]
s_inv = "".join(s_inv)

pre = s[:int((n-1)/2)]
pst = s[int((n+3)/2)-1:]

pre_inv = [pre[len(pre)-1-i] for i in range(len(pre))]
pre_inv = "".join(pre_inv)

pst_inv = [pst[len(pst)-1-i] for i in range(len(pst))]
pst_inv = "".join(pst_inv)

if (s == s_inv) * (pre == pre_inv) * (pst == pst_inv) == 1:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
//前置き
#pragma region

#include<stdio.h>
#include<iostream>
#include<cstdio>
#include <cstring>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<queue>

using namespace std;

typedef  long long ll;

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

#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(all(a))
#define REVERSE(a) reverse(all(a))

#define PRINT(str) printf(#str "\n")
#define yOUT PRINT(Yes)
#define nOUT PRINT(No)
#define YOUT PRINT(YES)
#define NOUT PRINT(NO)

#pragma endregion

//関数定義
#pragma region 
//偶数 ->　true :: 奇数　-> false
bool EVEN(ll a){
    return a%2-1;
}

//最大公約数
ll gcd(ll a, ll b) {  
    if (!b)  
        return a;  
    return gcd(b, a%b);  
}  

//最小公倍数
ll lcm(ll a, ll b) {  
    return a*b/gcd(a,b);  
} 

#pragma endregion

int dore(int a,int b,int c){
    
    if(a == max(a,max(b,c))) return 1;
    if(b == max(a,max(b,c))) return 2;
    if(c == max(a,max(b,c))) return 3;
}
int main(){
    string s;
    cin >> s;

    ll size = s.size(),ans=0;

    REP(i,(1 << size-1)){
        string ss;
        ss = "";
        REP(j,size-1){
            ss.push_back(s[j]);
            if(i & (1 << j)){
                if(ss.size() >= 8){
                    string l = ss.substr(0,7), r = ss.substr(7);
                    ans += stoi(r);
                    ll k = stoi(l);
                    REP(i,ss.size()-7) k *= 10;
                    ans += k;
                    ss = "";
                }else{
                    ans += stoi(ss);
                    ss = "";
                }
            }
        }
        ss.push_back(s[size-1]);
        if(ss.size() >= 9){
                    string l = ss.substr(0,7), r = ss.substr(7);
                    ans += stoi(r);
                    ll k = stoi(l);
                    REP(i,ss.size()-7) k *= 10;
                    ans += k;
                    ss = "";
        }else{
                    ans += stoi(ss);
                    ss = "";
        }
    }
    
    cout << ans <<endl;
}




Measured memory_bytes: 256
input_string = input()
length = len(input_string)
n = int(input_string)

ans = 0

def func(i):
    a = '9'*i
    b = '1' + '0'*(i-1)
    A = int(a)
    B = int(b)

    if A > n:
        A = n

    return A - B + 1

ans = n
for i in range(0, length+1, 2):
    if i == 0:
        continue
    ans -= func(i)
print(ans)


Measured memory_bytes: 3060
#include<stdio.h>

int main(){

    int N, X;
    scanf("%d%d", &N, &X);

    int L[N];
    for (int i = 0; i < N; i++){
        scanf("%d", &L[i]);
    }

    int D = 0;
    int count = 1;

    for (int i = 0; i < N; i++){

        D += L[i];

        if(D > X){
            count += i;
            break;
        }

        if((i == N-1)&&(D <= X)){
            count = N + 1;
        }
    }

    printf("%d", count);

    return 0;
}

Measured memory_bytes: 128
"""

貪欲か？
今いる地点から左のRと右のLの数を比較
多い方の最遠点に行く→そのような点が無くなったら終了

証明は…
まず右のR,左のLは無意味→区間を無駄にするだけ
少ない方に行く→多い方の区間が無駄になる
近い点に行く→　ここがむずい
遠い区間が無駄になるのを防ぐため？

実装は？
多い方の処理→BITで左にあるRの数と右にあるLの数をlogNで
優先度付きキューで最小のRと最大のLを検出
10^5+1 を足して1 ～ 2*10^5 + 1の区間として扱う
初期・終了地点は　10^5+1

"""
import heapq

def bitadd(a,w,bit): #aにwを加える(1-origin)
 
    x = a
    while x <= (len(bit)-1):
        bit[x] += w
        x += x & (-1 * x)
 
def bitsum(a,bit): #ind 1～aまでの和を求める
 
    ret = 0
    x = a
    while x > 0:
        ret += bit[x]
        x -= x & (-1 * x)
    return ret

N = int(input())

used = [False] * N
lq = []
rq = []
LR = []

LBIT = [0] * (2 * (10**5) + 10)
RBIT = [0] * (2 * (10**5) + 10)

for i in range(N):

    L,R = map(int,input().split())

    L += 10**5+1
    R += 10**5+1

    LR.append([L,R])
    
    heapq.heappush(lq,[-1 * L,i])
    heapq.heappush(rq,[R,i])

    bitadd(L,1,LBIT)
    bitadd(R,1,RBIT)


ans = 0
now = 10**5+1

for i in range(N):

    R_in_left  = bitsum(now-1,RBIT)
    L_in_right = N - i - bitsum(now,LBIT)
    

    if R_in_left >= L_in_right: #左にあるRに移動

        while len(rq) > 0 and used[ rq[0][1] ]:
            heapq.heappop(rq)

        if len(rq) == 0:
            break

        nexp,nexind = heapq.heappop(rq)
        pair = LR[nexind][0]

        bitadd(nexp,-1,RBIT)
        bitadd(pair,-1,LBIT)
        used[nexind] = True

        if nexp >= now:
            break

        ans += now - nexp
        now = nexp

    else:

        while len(lq) > 0 and used[ lq[0][1] ]:
            heapq.heappop(lq)

        if len(lq) == 0:
            break

        nexp,nexind = heapq.heappop(lq)
        nexp *= -1
        pair = LR[nexind][1]

        bitadd(nexp,-1,LBIT)
        bitadd(pair,-1,RBIT)
        used[nexind] = True

        if nexp <= now:
            break

        ans += nexp - now
        now = nexp

ans += abs(10**5+1 - now)

print (ans)

        



Measured memory_bytes: 109016
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=3005,INF=1<<30;
ll dp[MAX][MAX],last[MAX][MAX];
ll rui[MAX];

void make(){
    rui[0]=1;
    for(int i=1;i<MAX;i++){
        rui[i]=rui[i-1]*2%mod;
    }
}

void update(int i,int j,int t){
    dp[i][j]*=rui[(t-last[i][j])];
    dp[i][j]%=mod;
    
    last[i][j]=t+1;
    
    return;
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    make();
    
    int N,Q;cin>>N>>Q;
    vector<int> A(N);
    for(int i=0;i<N;i++) cin>>A[i];
    
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            if(A[i]>A[j]) dp[i][j]=1;
        }
    }
    
    for(int q=0;q<Q;q++){
        int a,b;cin>>a>>b;
        a--;b--;
        if(a>b) swap(a,b);
        
        for(int i=0;i<N;i++){
            if(i==a||i==b) continue;
            update(i,a,q);
            update(i,b,q);
            ll s=dp[i][a]+dp[i][b];
            
            dp[i][a]=s;
            dp[i][b]=s;
        }
        
        for(int j=0;j<N;j++){
            if(j==a||j==b) continue;
            update(a,j,q);
            update(b,j,q);
            ll s=dp[a][j]+dp[b][j];
            
            dp[a][j]=s;
            dp[b][j]=s;
        }
        
        update(a,b,q);
        update(b,a,q);
        
        ll s=dp[a][b]+dp[b][a];
        
        dp[a][b]=s;
        dp[b][a]=s;
        
    }
    
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            update(i,j,Q);
        }
    }
    
    ll ans=0;
    
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            ans+=dp[i][j];
            ans%=mod;
        }
    }
    
    cout<<ans<<endl;
}


Measured memory_bytes: 141312
# 044_a
# A - 高橋君とホテルイージー

N = int(input())  # 連泊数
K = int(input())  # 料金変動泊数
X = int(input())  # 通常価格
Y = int(input())  # 変動価格

if ((1 <= N & N <= 10000) & (1 <= K & K <= 10000)) \
        & (1 <= X & X <= 10000) & (1 <= Y & Y <= 10000):
    if (X > Y):
        price = 0
        if (N < K):
            for i in range(1, N + 1):
                price += X
        if (N >= K):
            for i in range(1, K + 1):
                price += X
            for j in range(K + 1, N + 1):
                price += Y
        print(price)

Measured memory_bytes: 9164
import java.util.*;
import java.io.*;



public class Main{
    static int INFTY=Integer.MAX_VALUE;
    public static void main (String args[]){
        //初期処理
        Scanner sc=new Scanner(System.in);
        // BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        // try{
            // int n = Integer.parseInt(br.readLine());
            int L=sc.nextInt();
            int R=sc.nextInt();
            int lShou= L/2019;
            int rShou= R/2019;
            int lJouyo=L%2019;
            int rJouyo=R%2019;
            int ans=INFTY;
            if(lShou!=rShou){
                ans=0;
            }else{
                for(int i=lJouyo;i<rJouyo;i++){
                    for(int j=i+1;j<=rJouyo;j++){
                        ans=Math.min(ans,(i*j)%2019);
                    }
                }
            }
            System.out.println(ans);
    }
}

Measured memory_bytes: 23888
#include <bits/stdc++.h>
#define pf push_front
#define pb push_back
#define ppf pop_front
#define INF 1000000009
using namespace std;

int k,d[100005];
deque<int> q;

int main()
{
    for(int i=0;i<=100005;i++) d[i]=INF;
    cin>>k;
	q.pb(1);
	d[1]=0;
	while(!q.empty())
	{
		int t=q.front();q.ppf();
		if(d[t]<d[(t*10)%k])
		{
		    q.pf((t*10)%k);
		    d[(t*10)%k]=d[t];
	    }
	    if(d[t]+1<d[(t+1)%k])
	    {
		    q.pb((t+1)%k);
		    d[(t+1)%k]=d[t]+1;
	    }
	}
	
	cout<<d[0]+1<<endl;
	return 0;
}

Measured memory_bytes: 896
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
const int MAXN = (int)1e2 + 10;

int n;
vector<int> g[MAXN];
int vis[MAXN];
int st[MAXN],en[MAXN];
int clk;

void DFS(int u){
    vis[u]=1;
    st[u]=++clk;
    for(int i=0;i<g[u].size();i++){
        int v=g[u][i];
        if(vis[v]) continue;
        DFS(v);
    }
    en[u]=++clk;
}

void work(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        int u,k; scanf("%d%d",&u,&k);
        while(k--){
            int v; scanf("%d",&v);
            g[u].push_back(v);
        }
        sort(g[u].begin(),g[u].end());
    }
    for(int i=1;i<=n;i++)if(!vis[i]) DFS(i);
    for(int i=1;i<=n;i++) printf("%d %d %d\n",i,st[i],en[i]);
}

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




Measured memory_bytes: 2784
import java.io.PrintWriter
import kotlin.math.min

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun <T> Iterable<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)
fun <T> Array<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val (N, K) = nextIntList()
    val S = next()
    var ans = 0L
    var ch = 0
    for (i in 1 until N) {
        if (S[i - 1] == S[i]) ans++
        else ch++
    }
    val m = (ch + 1) / 2
    val n = min(m, K)
    val a = if (n == m) ch % 2 else 0
    println(ans + 2L * n - a)
}

Measured memory_bytes: 39068
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A - Rounding
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  int x, a;
  scanf("%d%d", &x, &a);

  printf("%d\n", (x < a) ? 0 : 10);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1001001001;
const int MOD = 1000000007;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...)
#define print(...)
#endif

int main() {
    ll n; cin >> n;
    ll x, m; cin >> x >> m;
    vector<int> a;
    set<int> st;
    int loopNum = -1;
    rep(i, n) {
        if (i>0) {
            x *= x;
            x %= m;
        }
        if (st.count(x)) {
            loopNum = x;
            break;
        }
        a.push_back(x);
        st.insert(x);
    }
    if (loopNum == -1) {
        cout << accumulate(all(a), 0ll) << endl;
    } else {
        int start = find(a.begin(), a.end(), loopNum) - a.begin();
        int end = sz(a)-1;
        // debug(start, end);
        int loopLength = end - start + 1;
        ll beforeLoop = accumulate(a.begin(), a.begin()+start, 0ll);
        ll loopTotal = accumulate(a.begin()+start, a.end(), 0ll);
        ll loopCount = (n-start) / loopLength;
        ll restCount = n - start - (ll)loopLength*loopCount;
        ll loopRemain = accumulate(a.begin()+start, a.begin()+start+restCount, 0ll);
        ll ans = beforeLoop + loopTotal*loopCount + loopRemain;
        // debug(a);
        // debug(*(a.begin()+start));
        // debug(start, loopLength, loopCount, restCount);
        // debug(beforeLoop, loopTotal, loopCount, restCount, loopTotal*loopCount, loopRemain);
        // debug(accumulate(all(a), 0ll));
        cout << ans << endl;
    }
}

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

#define int long long
#define double long double
#define ff first
#define ss second
#define endl '\n'
#define ii pair<int, int>
#define mp make_pair
#define mt make_tuple
#define DESYNC ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define pb push_back
#define vi vector<int>
#define vii vector< ii >
#define EPS 1e-9
#define INF 1e18
#define ROOT 1
#define M 1000000007
const double PI = acos(-1);

using namespace std;

inline int mod(int n, int m){ int ret = n%m; if(ret < 0) ret += m; return ret; }

int gcd(int a, int b){
  if(a == 0) return b;
  else return gcd(b%a, a);
}

int dp[112345][13];
string s;

int solve(int i, int r){
  if(i == s.size()) return r == 5;
  if(dp[i][r] != -1) return dp[i][r];
  dp[i][r] = 0;
  if(s[i] != '?'){
    dp[i][r] = solve(i+1, (r*10+(s[i]-'0'))%13);
    //cout << "dp[" << i+1 << "][" << (r*10+(s[i]-'0'))%13 << "] = " << dp[i+1][(r*10+(s[i]-'0'))%13] << endl;
    dp[i][r] = mod(dp[i][r], M);
  }
  else {
    for(int d = 0; d <= 9; d++){
      dp[i][r] += solve(i+1, (r*10+d)%13);
      //cout << "dp[" << i+1 << "][" << (r*10+d)%13 << "] = " << dp[i+1][(r*10+d)%13] << endl;
      //cout << dp[i][r] << endl;
      dp[i][r] = mod(dp[i][r], M);
    }
  }
  return dp[i][r];
}
int32_t main(){
  DESYNC;
  cin >> s;
  memset(dp, -1, sizeof dp);
  cout << solve(0, 0) << endl;
}



Measured memory_bytes: 18156
n, m = map(int, input().split())
h = [int(x) for x in input().split()]
ans = [True] * n
for i in range(m):
    a, b = map(int, input().split())
    if h[a-1] < h[b-1]:
        ans[a-1] = False
    elif h[a-1] > h[b-1]:
        ans[b-1] = False
    else:
        ans[a-1] = False
        ans[b-1] = False
print(ans.count(True))


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

struct node
{
	int key;
	node* lc, * rc, * p;
};

node* root = 0;

void insert(int x)
{
	node* pre = root;        //设当前节点为根，以根为起点
	node* temp = pre;        //用来保存当前节点的临时指针

	node* in = (node*)malloc(sizeof(node));
	in->key = x;
	in->lc = 0;     
	in->rc = 0;     

	while (pre != 0)
	{
		temp = pre;
		if (in->key < pre->key)
			pre = pre->lc;
		else
			pre = pre->rc;
	}
	pre = temp;

	in->p = pre;
	if (pre == 0)
		root = in;
	else
	{
		if (in->key < pre->key)
			pre->lc = in;
		else
			pre->rc = in;
	}
}

void Inorder(node* r)
{
	if (r->lc != 0)
		Inorder(r->lc);

	cout << " " << r->key;

	if (r->rc != 0)
		Inorder(r->rc);
}

void Preorder(node* r)
{
	cout << " " << r->key;

	if (r->lc != 0)
		Preorder(r->lc);
	if (r->rc != 0)
		Preorder(r->rc);
}

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

	int n, x;
	string p;

	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> p;

		if (p == "insert")
		{
			cin >> x;
			insert(x);
		}
		else
		{
			Inorder(root);
			cout << endl;
			Preorder(root);
			cout << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 26660
s = input()
odd = ['R', 'U', 'D']
even = ['L', 'U', 'D']

for i in range(len(s)):
    if (i+1) % 2 == 1:
        if s[i] not in odd:
            print('No')
            exit(0)
    else:
        if s[i] not in even:
            print('No')
            exit(0)

print('Yes')


Measured memory_bytes: 38512
package main

import (
	"fmt"
	//	"math"

	"sort"
	"strconv"
)

func stringToint(s string) int {
	i, _ := strconv.ParseInt(s, 10, 64)
	return int(i)
}

func noResult() {
	fmt.Println(0)
}

func main() {
	var n int
	var tmp string
	//	data := make([]int, 0, 0)
	fmt.Scan(&n)

	data := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&tmp)
		data[i] = stringToint(tmp)
	}
	/*
			scanner := bufio.NewScanner(os.Stdin)
			line := make([]string, 0, 0)
			data := make([]int, 0, 0)

			for scanner.Scan() && scanner.Text() != "" {
				if scanner.Err() != nil && scanner.Err() == io.EOF {
					break
				}
				line = append(line, scanner.Text())
			}
			if len(line) < 2 {
				noResult()
				return
			}

			input := strings.Split(line[1], " ")

			for _, s := range input {
				data = append(data, stringToint(s))
			}

		if len(data) != stringToint(line[0]) {
			noResult()
			return
		}
	*/

	sort.Ints(data)
	totalNum := 0

	if len(data)%2 != 0 {
		if data[0] != 0 {
			noResult()
			return
		} else {
			for i := 0; i < (len(data)-1)/2; i++ {
				if !(data[i*2+1] == (i+1)*2 && data[i*2+2] == (i+1)*2) {
					noResult()
					return
				}
			}
			totalNum = (len(data) - 1) / 2
		}
	} else {
		for i := 0; i < len(data)/2; i++ {
			if !(data[i*2] == (i+1)*2-1 && data[i*2+1] == (i+1)*2-1) {
				noResult()
				return
			}
		}
		totalNum = len(data) / 2
	}

	remain := 1
	for i := 0; i < totalNum; i++ {
		remain = (remain * 2) % 1000000007
	}
	fmt.Println(remain)
}

Measured memory_bytes: 5504
#include <iostream>
#include <math.h>
using namespace std;


int main()
{
  string s;
  cin >> s;
  int digits = s.size();
  int count = digits / 2 * 2 - 1,
      ret = 0, digitCount = 9;
  for (int i = 1; i <= count; i = i + 2)
  {
    ret = ret + digitCount;
    digitCount *= 100;
  }
  if (digits % 2 == 1)
  {
    ret = ret + (stoi(s) - pow(10, digits - 1) + 1);
  }
  cout << ret << endl;
  return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = 3;
int a[maxn][maxn];
bool legal(int a2,int a3, int b2, int b3)
{
    if(a2>=0&&a3>=0&&b2>=0&&b3>=0) return true;
    return false;
}
bool check(int a1,int b1)
{
    int a2,a3,b2,b3;
    if((a1+b1)!=a[0][0]) return false;
    else
    {
        a2 = a[1][0] - b1;
        a3 = a[2][0] - b1;
        b2 = a[0][1] - a1;
        b3 = a[0][2] - a1;

        if(!legal(a2,a3,b2,b3)) return false;
        if((a2+b2)!=a[1][1]||(a3+b2)!=a[2][1]||(a2+b3)!=a[1][2]||(a3+b3)!=a[2][2]) return false;
        return true;
    }
}
int main()
{
    int a1,b1;
    for(int i=0;i<3;i++)
    {
        for(int j=0;j<3;j++)
        {
            cin>>a[i][j];
        }
    }

    for(a1 = 0;a1<=100;a1++)
    {
        for(b1 = 0;b1<=100;b1++)
        {
            if(check(a1,b1))
            {
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
import std.algorithm;
import std.range;
import std.stdio;
import std.math;
import std.array;
import std.string;
import std.conv;

/// 数列の読み込み
auto readNums() {
	return readln().chomp.split.map!(to!int).array;
}

/// 数の読み込み
auto readNum() {
	return readNums.front;
}

/// 指定行数読み込み
auto readRows(size_t rows) {
	return generate(() => readln().chomp).take(rows).array;
}

void main() {
	const nums = readNums();
	writefln("%s", nums[1] * ((nums[1] - 1) ^^ (nums[0] - 1)));
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int n,x,cnt,i,j,k;
	while(1){
		scanf("%d%d",&n,&x);
		if(n==0 && x==0) break;
		cnt=0;
		for(i=1;i<=n;i++){
			for(j=i+1;j<=n;j++){
				for(k=j+1;k<=n;k++){
					if(i+j+k==x)cnt++;
				}
			}
		}
		printf("%d\n",cnt);
	}
	return 0;
}



Measured memory_bytes: 2120
#include <cstdio>
#include <cstdint>
#include <vector>
#include <set>
#include <algorithm>

int main()
{
    int64_t n;
    scanf("%ld", &n);

    std::vector<int64_t> flowerHeights;
    std::set<int64_t> sortedFlowerHeights;
    for (int64_t i = 0; i < n; i++)
    {
        int64_t h;
        scanf("%ld", &h);
        flowerHeights.push_back(h);
        sortedFlowerHeights.insert(h);
    }
    
    int64_t count = 0, prevBaseline = 0;
    for (auto baseline : sortedFlowerHeights)
    {
        auto delta = baseline - prevBaseline;
        // printf("baseline %3ld:", baseline);

        int64_t beginCont = -1;
        int64_t endCont = -1;
        for (int64_t i = 0; i < n; i++)
        {
            auto h = flowerHeights[i];
            if (h >= baseline)
            {
                // printf("* ");
                endCont = i;
                continue;
            }

            if (beginCont < endCont)
            {
                count += delta;
                // printf("= ");
            }
            else
            {
                // printf("- ");
            }

            beginCont = endCont = i;
        }
        if (beginCont < endCont)
        {
            count += delta;
        }
        // printf("\n");

        prevBaseline = baseline;
    }

    printf("%ld\n", count);
    return 0;
}


Measured memory_bytes: 888
#include <iostream>
using namespace std;
int main () { 
	int r, x, y, H, W ;
	cin >> W >> H >> x >> y >> r ;
	
	if (( r < H )&&( x < W )&&( x > 0 )&&( y < H )&&
	( y > 0 )&&( r <= W-x )&&( r <= H-y )){
		cout << "Yes" << endl ;
	} else {
		cout << "No" << endl ;
	}
}
	


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

typedef long long ll;

int main(){
	ll n,a,b;
	cin >> n >> a >> b;
	ll c = (a+b);
	ll mult = n/c;
	ll sisa = n%c;
	sisa = min(sisa,a);
	cout << mult*a + sisa << endl;
	return 0;
}


Measured memory_bytes: 256
unittest
{
	assert( [ "5", "11 1 2 4 8", "11 1 2 2 8", "32 10 8 5 4", "29384293847243 454353412 332423423 934923490 1", "900000000000000000 332423423 454353412 934923490 987654321" ].parse.expand.solve == "20\n19\n26\n3821859835\n23441258666" );
}



import std.algorithm;
import std.conv;
import std.functional;
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 t = input.front.to!( long );
	auto nabcds = new long[ 5 ][ t ];
	foreach( ref nabcd; nabcds )
	{
		input.popFront;
		nabcd = input.front.split.to!( long[] );
	}
	return tuple( nabcds );
}

auto solve( long[ 5 ][] nabcds )
{
	auto anss = new long[ nabcds.length ];
	foreach( ref ans, nabcd; lockstep( anss, nabcds ) )
	{
		ans = memoize!solve2( nabcd[ 0 ], nabcd[ 1 .. $ - 1 ], nabcd[ $ - 1 ] );
	}
	return anss.to!( string[] ).join( "\n" );
}

long solve2( ulong n, long[] abc, long d )
{
	auto m = n * d;
	
	// 1を引く しかできない
	if( n <= 1 ) return m;
	
	// 1を引く or 1を足す or 2,3,5で割る 操作の組み合わせでnを0にするときのコストを計算
	foreach( x, M; lockstep( abc, [ 2L, 3L, 5L ] ) )
	{
		if( n % M == 0 )
		{
			// Mで割る
			m = min( m, memoize!solve2( n / M, abc, d ) + x );
		}
		else
		{
			// 1を引くの繰り返しでMの倍数にした後にMで割る
			auto nf = n / M * M;
			m = min( m, memoize!solve2( nf / M, abc, d ) + x + d * ( n - nf ) );
			
			// 1を足すの繰り返しでMの倍数にした後にMで割る
			auto nc = ( n + M - 1 ) / M * M;
			m = min( m, memoize!solve2( nc / M, abc, d ) + x + d * ( nc - n ) );
		}
	}
	return m;
}


Measured memory_bytes: 21764
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define Max 100001
#define inf 1000000000000000
using namespace std;
struct problem {
    int p,c,score;
}s[11];
int d,g,ans = 1000;

int main() {
    scanf("%d%d",&d,&g);
    g /= 100;
    for(int i = 1;i <= d;i ++) {
        scanf("%d%d",&s[i].p,&s[i].c);
        s[i].c /= 100;
        s[i].score = s[i].p * i + s[i].c;
    }
    for(int i = 1;i < 1 << (d + 1);i ++) {
        int sum = 0,k = 0,maxn;
        for(int j = 1;j <= d;j ++) {
            if(i & (1 << j)) {
                sum += s[j].score;
                k += s[j].p;
            }
            else maxn = j;
        }
        if(sum < g) {
            int need = (g - sum + maxn - 1) / maxn;
            if(need > s[maxn].p)continue;
            k += need;
        }
        ans = min(ans,k);
    }
    printf("%d",ans);
}


Measured memory_bytes: 256
from collections import Counter

N,M = map(int,input().split())
A = sorted(list(map(int,input().split())),reverse=True)
B = sorted(list(map(int,input().split())),reverse=True)
mod = pow(10,9)+7

n,m = 0,0
ans = 1

def istwo(L):
    if len(list(filter(lambda x:x>1,Counter(L).values())))>0:
        return True
    else:
        return False

if istwo(A) or istwo(B):
    print(0)
else:
    for i in range(1,(N*M)+1)[::-1]:
        if n<N and i<=A[n]:n+=1
        if m<M and i<=B[m]:m+=1
        if n>0 and m>0 and i == A[n-1] and i == B[m-1]:
            ans = ans%mod
        elif n>0 and i == A[n-1]:
            ans = (ans*(m))%mod
        elif m>0 and i == B[m-1]:
            ans = (ans*(n))%mod
        else:
            ans = (ans*(n*m-(N*M-i)))%mod
        #print(i,n,A[n-1],m,B[m-1],ans)
    print(ans)

Measured memory_bytes: 3572
#include <stdio.h>

static int table[6][6]={{'\0', 3, 5, 2, 4, '\0'},
                        {4, '\0', 1, 6, '\0', 3},
                        {2, 6, '\0', '\0', 1, 5},
                        {5, 1, '\0', '\0', 6, 2},
                        {3, '\0', 6, 1, '\0', 4},
                        {'\0', 4, 2, 5, 3, '\0'}
                        };

int main(void) {
    int n, a, b, d[6], i, j, k;

    scanf("%d %d %d %d %d %d", &d[0], &d[1], &d[2], &d[3], &d[4], &d[5]);
    scanf("%d", &n);
    for (i=0; i<n; i++) {
        scanf("%d %d", &a, &b);
        for (j=0;j<6;j++) {
            for (k=0;k<6;k++) {
                if (a==d[j] && b==d[k]) {
                    printf("%d\n", d[table[j][k]-1]);
                }
            }
        }
    }

    return 0;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    rep(ki, k) {// k回の操作
        vector<int> b(n+1);
        rep(i, n) {
            int l = max(0, i-a[i]); //区間の左端
            int r = min(i+a[i]+1, n); //区間の右端 
            b[l]++; b[r]--;
        }
        rep(i, n) b[i+1] += b[i]; //累積和をとる
        b.pop_back(); // 末尾を削除する
        if (a == b) break; //もし一致したら操作をストップする
        a = b;
    }
    rep(i, n) cout << a[i] << endl;
    return 0;
}

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

int N,L;
const int MAX_N = 100000;
int a[MAX_N];

const string TRUE = "Possible";
const string FALSE = "Impossible";

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

int check(){
  for(int i = 0 ; i < N-1 ; i++){
    if(a[i] + a[i+1] >= L)return i;
  }
  return -1;
}

int main(){
  input();
  int pos = check();
  cout << (pos != -1?TRUE:FALSE) << endl;
  if(pos != -1){
    for(int i = 0 ; i < pos ; i++){
      cout << i+1 << endl;
    }

    for(int i = N-2 ; i >= pos ; i--){
      cout << i+1 << endl;
    }
  }
  return 0;
}


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

int main()
{
	int R, G, B, N;
	int ans = 0;
	cin >> R >> G >> B >> N;
	for (int i = 0; i <= N / R; i++)
		for (int j = 0; j <= (N - R * i) / G; j++)
			if ((N - (R * i + G * j)) % B == 0)
				ans++;
	cout << ans << endl;
}


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

typedef long long ll;
typedef unsigned long long ull;

int main()
{
    ll A;
    string Bstr;
    cin >> A >> Bstr;
    ll B = 0;
    B += 100 * (Bstr[0]-'0');
    B += 10  * (Bstr[2]-'0');
    B += 1   * (Bstr[3]-'0');

    A *= B;

    cout << A/100 << endl;

    return 0;
}

Measured memory_bytes: 3628