akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e6+100;
const int maxc=26;
const int mod=998244353;
ll dp[3500];
ll a[3500];
int main()
{
    int n,s;
    scanf("%d%d",&n,&s);
    for(int i=1;i<=n;i++)
        scanf("%lld",&a[i]);
    ll ans=0;
    for(int i=1;i<=n;i++){
        dp[0]++;
        for(int j=s;j>=1;j--){
            int u=j-a[i];
            if(u>=0&&u<=s){
                if(j==s)
                    {
                        ans=(ans+dp[u]*(n-i+1))%mod;
                        //cout<<i<<"  "<<dp[u]<<"  "<<u<<endl;
                    }
                else if(u)
                    dp[j]=(dp[j]+dp[u])%mod;
            }
            else
                break;
            //cout<<i<<"   "<<j<<"  "<<dp[2]<<endl;
        }
        //cout<<dp[2]<<endl;
        if(a[i]<=s)
            dp[a[i]]=(dp[a[i]]+i)%mod;
        //cout<<ans<<endl;
    }
    printf("%lld\n",ans);
    return 0;
}
/*

*/


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;
const int MOD = 1e9+7;


#define REP(i, N) for (int i = 0; i < (N); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((int)(x).size())
//vvintを作る　マクロで　 #define vvint(N,M) vector<vector<int>>

using namespace std;


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

    ll N;
    cin >> N;
    vector<ll>  fl(1000,0);
    vector<pair<ll,ll> > robo(N),rl(N);
    ll x,l;

    ll cnt = 0;
    
    for(int i = 0; i < N;i++){
        cin >> x >> l;
        rl[i] = make_pair(x+l,x-l);
        robo[i] = make_pair(l,x);
    }

    sort(rl.begin(),rl.end());
    ll now = -1*MOD;

    for(int i = 0; i < N;i++){
        if(now <= rl[i].second){
            now = rl[i].first;
            cnt++;
        }
    }

    
    cout << cnt << endl;




    return 0;
}

Measured memory_bytes: 3456
#include<stdlib.h>
#include<iostream>
#include<stdio.h>
#include<algorithm>

using namespace std;
int main()
{
	int A = 0, B = 0;
	cin >> A >> B;
	int sum1 = 0, sum2 = 0, sum3=0;
	sum1 = A + A - 1;
	sum2 = B + B - 1;
	sum3 = A + B;
	int a[3];
	a[0] = sum1;
	a[1] = sum2;
	a[2] = sum3;
	sort(a, a + 3);
	cout << a[2];


	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <unistd.h>
using namespace std;
#define nl cout<<"\n"
#define endl '\n'
#define pb push_back
#define se second
#define fi first
#define int long long 
#define pi pair<int,int>
#define vpi vector<pi>
#define vvpi vector<vpi>
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define For(i,n) for(int i=0;i<n;i++)
#define Forn(i,a,n) for(int i=a;i<n;i++)
#define pie =3.14159265358979323846264338327950;
const int mod= 998244353;


void solve(){
	fio;
	int d,t,s;
	cin>>d>>t>>s;
	if(d<=t*s){
		cout<<"Yes"<<endl;
	}
	else cout<<"No"<<endl;
}

int32_t main(){
	fio;
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int t=1;
	//cin>>t;
	for(int i=1;i<=t;i++){ 
		//cout<<"Case #"<<i<<": ";
		solve();
	}
	return 0;
}


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

typedef long long ll;
typedef pair<ll, ll> P;


#define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++)
#define frep(i,m,n) for(ll (i)=(m); (i)<=(ll)(n); (i)++)
#define rrep(i,n) for(ll (i)=(n)-1; (i)>-1; (i)--)
#define frrep(i,m,n) for(ll (i)=(n); (i)>(ll)(m); (i)--)
#define ALL(x) (x).begin(), (x).end()

const ll INF = 100100100100100100;
const ll MOD = 1000000007;

// get abs
ll my_abs(ll a);
// a^n
ll a_n(ll a, ll n);
// get gcd
ll my_gcd(ll a, ll b);
// a^(-1) % MOD 
ll inv(ll a);
// (a+b+c)%MOD
ll madd(ll a, ll b, ll c);
// (a-b)%MOD
ll msub(ll a, ll b);
// (a*b*c)%MOD
ll mtime(ll a, ll b, ll c);


int main() {
    ll n; cin >> n;
    cout << (10000-n)%1000 << endl;
    return 0;
}

ll my_abs(ll a) {
    if(a >= 0) return a;
    else return -1 *a;
}

ll a_n(ll a, ll n) { 
    if(n == 0) return 1;
    
    ll ret = a, count = 1;
    while(count * 2 < n) {
        ret *= ret;
        count *= 2;
    }
    if(count == n) return ret;
    else return (ret * a_n(a, n-count));
}

ll my_gcd(ll a, ll b) {
    if(b == 0) return a;
    return my_gcd(b, a%b);
}

ll inv(ll a) {
    return a_n(a, MOD-2);
}

ll madd(ll a, ll b, ll c) {
    ll ret = (a+b) % MOD;
    return (ret+c) % MOD;
}

ll msub(ll a, ll b) {
    if(a < b) return (a-b+MOD) % MOD;
    else return (a-b) % MOD;
}

ll mtime(ll a, ll b, ll c) {
    ll ret = (a*b) % MOD;
    return (ret*c) % MOD;
}


Measured memory_bytes: 3632
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define bit(n,k) (((ll)n>>(ll)k)&1) /*nのk bit目*/
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
vl dx={-1,-1,-1,0,0,1,1,1};
vl dy={1,-1,0,1,-1,1,0,-1};
//約数の列挙O(√n)
vector<ll>divisor(ll n){
  vector<ll>res;
  for(ll i=1;i*i<=n;i++){
    if(n%i==0){
      res.push_back(i);
      if(i != n/i) res.push_back(n/i);
    }
  }
  return res;
}
int main(){
    ll x;cin>>x;
    vl vec=divisor(x);
    for(auto d:vec) {
        for(ll b=-d/2+1;abs((b+d)*(b+d)*(b+d)*(b+d)*(b+d)-b*b*b*b*b)<=x;b++){
          if((b+d)*(b+d)*(b+d)*(b+d)*(b+d)-b*b*b*b*b==x){
              cout<<b+d<<" "<<b<<endl;
              return 0;
          }
        }
        for(ll b=-d/2;abs((b+d)*(b+d)*(b+d)*(b+d)*(b+d)-b*b*b*b*b)<=x;b--){
          if((b+d)*(b+d)*(b+d)*(b+d)*(b+d)-b*b*b*b*b==x){
              cout<<b+d<<" "<<b<<endl;
              return 0;
          }
        }
    }
}
    
    

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n,l;
    cin>>n>>l;

    vector<string> V;
    string s;
    for(int i = 0; i < n; i++)
    {
        cin>>s;
        V.push_back(s);
    }

    sort(V.begin(),V.end());

    for(auto v:V)
        cout<<v;

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


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

int S[110][110] = { 0 }, a[110][110];


int main(){
	int n,max=-50000,t;
	cin >> n;
	for (int i = 0; i <= n; i++){
		S[0][i] = 0; S[i][0] = 0;
	}
	for (int i = 0; i < n; i++){
		for (int j = 0; j < n; j++){
			cin >> a[i][j];
			S[i + 1][j + 1] = S[i][j + 1] + S[i + 1][j]-S[i][j]+a[i][j];
		}
	}
	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= n; j++){
			for (int k = 0; k < i; k++){
				for (int h = 0; h < j; h++){
					t = S[i][j] - S[k][j] - S[i][h] + S[k][h];
					if (max < t)max = t;
				}
			}
		}
	}
	cout << max << endl;
}

Measured memory_bytes: 1248
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <climits>
using namespace std;

#define MOD1097 1000000007

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mpair make_pair
#define pm(first, second) pb(mpair(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()
#define reall(X) (X).rbegin(), (X).rend()
#define divcel(a, b) (((a) + ((b) - 1)) / (b))

int main(){

	int k, N;
	cin >> N >> k;
	vector<int> A(N);
	for(int i = 0; i < N; i++){
		cin >> A[i];
	}
	sort(all(A));
	int ans = 0;
	for(int i = 0; i < k; i++){
		ans += A[i];
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
using namespace std;

long long int cnt[114514] = {};

int main() {


  long long int n, m;
  cin >> n >> m;

  vector< vector< long long int > > v;
  for ( long long int i = 0; i < n; i++ ) {
    vector< long long int > vv;
    v.push_back( vv );
  }


  for ( long long int i = 0; i < m; i++ ) {

    long long int x, y, z;
    cin >> x >> y >> z;
    x--;
    y--;
    v[x].push_back( y );
    v[y].push_back( x );

  }

  long long int ans = 0;

  for ( long long int i = 0; i < n; i++ ) {

    if ( cnt[i] > 0 ) continue;
    ans++;
    queue< long long int > q;
    q.push( i );

    while( q.size() ) {

      long long int k = q.front();
      q.pop();
      if ( cnt[k] > 0 ) continue;
      cnt[k]++;
      for ( long long int j = 0; j < v[k].size(); j++ ) {
	long long int l = v[k][j];
	if ( cnt[l] > 0 ) continue;
	q.push( l );
      }

    }

  }

  cout << ans << endl;

  return 0;

}


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

    const ll INF = 1000000007;

ll powmod(ll x,ll y) {
    ll a = 1;
    for(int i=0; i<y; i++) {
        a=a*x%INF;
    }
    return a;
}

int main(void) {
    int N; cin >> N;
    if(N==1) {
        cout << 0 << endl;
        return 0;
    }

    ll ans = powmod(10,N)-powmod(9,N)-powmod(9,N)+powmod(8,N);

    ans %= INF;
    if(ans<0) ans+=INF;
    cout << ans << endl;
}

Measured memory_bytes: 3620
txt = list(input())
a = txt[0]
count = 1
i = 1
while(i < len(txt)):
  #print(temp)
  if a != txt[i]:
    a = txt[i]
    i += 1
    count += 1
  else:
    if (len(txt)-i) >= 2:
      a = txt[i:i+1]
      i += 2
      count += 1
    else:
      break
print(count)

Measured memory_bytes: 77132
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
    for(auto i=begin(v); i != end(v); ++i){
        if(i !=begin(v)) os << ' ';
        os << *i;
    }
    return os;
}

int main() {
    ll X,Y;
    cin >> X  >> Y;
    cout << ( (X%Y==0) ? -1 : X) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std; 
typedef long long ll;
#define fi first
#define se second 
#define pb push_back

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int h,n; 
	cin>>h>>n;
	ll sum = 0; 
	for(int i=0;i<n;i++){
		int x; 
		cin>>x; 
		sum+=x;
	}
	if(sum>=h)cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}


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

const int MAX = 210000;
const int MOD = 1000000007;

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()
{
	ll N,M,K;
	cin >> N >> M >> K;
	COMinit();
	ll ans = 0;
	ll temp = 0;
	for (int i = 1; i <= N-1; ++i)
	{
		temp = (N-i) * M * M % MOD * i % MOD;
		ans = (ans + COM(N*M-2,K-2) * temp % MOD) % MOD;
	}
	for (int i = 1; i <= M-1; ++i)
	{
		temp = (M-i) * N * N % MOD * i % MOD;
		ans = (ans + COM(N*M-2,K-2) * temp % MOD) % MOD;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 8528
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import math


A, B = list(map(int, input().split()))
# A, B = [12, 18]
# A, B = [420, 660]
# A, B = [1, 2019]


# 1. A,B の gcd を取得して C とする
# 2. C を素因数分解する
# 3. 「素因数分解の数 + 1」を返す

def gcd(a, b):
    # a の方が大きいと仮定
    def _gcd(a, b):
        # print(a, b)
        if a % b == 0:
            return b
        else:
            return gcd(b, a % b)

    if a < b:
        return _gcd(b, a)
    else:
        return _gcd(a, b)


def factorize(x):
    res = {}
    for i in range(2, int(math.sqrt(x) + 1)):  # x まで行かずともよさそう
        if x % i == 0:
            while x % i == 0:
                x //= i
                res[i] = res.get(i, 0) + 1

    if x != 1:
        res[x] = 1

    return res

C = gcd(A, B)
factors = factorize(C)
print(len(factors) + 1)


Measured memory_bytes: 3064
#include<iostream>
#include<queue>

using namespace std;

static const int N = 100;

int n,d[N],M[N][N];//d[]...?§??????????????????¢(-1?????°?????????)???M[][]?????£??\???????????§????????????

void dfs(int r) {
	queue<int> q;//queue??§?????????
	q.push(r);//?§?????????£??\
	for (int i = 0; i < n; i++) d[i] = -1;//??????????????????
	d[r] = 0;//?§????????????¢???0

	int u;
	while (!q.empty()) {//??¢?´¢???????????§??°?????????
		u = q.front();//u????????\?????????????????¢?´¢???????????£?????????????????£??\
		q.pop();//?????\???????????????????´????????????????

		for (int v = 0; v < n; v++) {//??£??\????????????????????????
			if (M[u][v] == 0) continue;//?§??????¨??????????????§?????°?????????????????´???????????????
			if (d[v] != -1) continue;//?§??????¨????????¢???????????£??????????????¢?´¢???????????£??????????????´??????????????????
			d[v] = d[u] + 1;//??????u????§??????¨??£??\?????????????????????????????¢1???1?????????????????????????????????+1???
			q.push(v);//?????\??????v?????????
		}
	}
	for (int i = 0; i < n; i++) {
		cout<<i+1<<" "<<d[i]<<endl;//??????
	}
}

int main() {
	int u, p, v;
	cin >> n;
	for (int i = 0; i < n; i++) {//?????????(d[]?????¢????????????dfs??§?±??????????????????§????????????????????????)
		for (int j = 0; j < n; j++) {
			M[i][j] = 0;
		}
	}

	for (int i = 0; i < n; i++) {//??????????????????
		cin >> u >> p;
		u--;//0?????????????????????
		for (int j = 0; j < p; j++) {
			cin >> v;
			v--;//0?????????????????????
			M[u][v] = 1;
		}
	}

	dfs(0);//??????0????§??????¨??????

	return 0;
}

Measured memory_bytes: 3120
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time
from fractions import gcd
#import random


def I(): return int(input())


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


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['No', 'Yes']
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']


# show_flg = False
show_flg = True

p = None
XY = None
N = None


def lcm(a, b):
    return a * b // gcd(a, b)


def main():
    A, B = MI()
    print(lcm(A, B))


if __name__ == '__main__':
    main()


Measured memory_bytes: 66028
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main(){
  char w[100];
  int A[100];
  int j=0;
  while( scanf("%s", w) != EOF ){
    if ( w[0] == '+' ){
      A[j-2]=A[j-2]+A[j-1];
      j--;
    } else if ( w[0] == '-' ){
      A[j-2]=A[j-2]-A[j-1];
      j--;
    } else if ( w[0] == '*' ){
      A[j-2]=A[j-2]*A[j-1];
      j--;
      } else {
      A[j] = atoi(w);
      j++;
    }
  }
  printf("%d\n",A[0]);
  return 0;
}


Measured memory_bytes: 2076
#include<bits/stdc++.h>
using namespace std;
 
int main(){
    int n, a, b;
    string  s;
    int sum_b=0;
    int sum=0;
    cin >> n >> a >> b;
    cin >> s;
 
    int len = s.length();
    for(int i=0; i<len; i++){
        if(s.at(i) == 'a'){
            if(sum < (a+b)){
                sum++;
                printf("Yes\n");
            }else{
                printf("No\n");
            }
        }else if(s.at(i) == 'b'){
            if(sum < (a+b) && sum_b < b){
                sum++;
                sum_b++;
                printf("Yes\n");
            }else{
                printf("No\n");
            }
        }else{
            printf("No\n");
        }
    }
}

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

#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define reset(a, v) memset((a), v, sizeof(a))

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;

const int N = 200005;

int n;
int inp[N];
int ans[N];

int main() {
	scanf("%d", &n);
	int xors = 0;
	for (int i = 0; i < n; i++) {
		scanf("%d", &inp[i]);
		xors ^= inp[i];
	}
	for (int i = 0; i < n; i++) {
		ans[i] = xors ^ inp[i];
	}
	for (int i = 0; i < n; i++) {
		printf("%d", ans[i]);
		if (i == n-1) printf("\n");
		else printf(" ");
	}
	return 0;
}


Measured memory_bytes: 5284
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_MASS_MAX		100										// 最大マス数
#define D_RES_INI		-1										// 結果 - 初期値
#define D_RES_WIN		0										// 結果 - 勝ち
#define D_RES_LOSE		1										// 結果 - 負け

// 内部変数
static FILE *szpFpI;											// 入力
static char sc3Res[D_MASS_MAX][D_MASS_MAX][2];					// 結果[先手位置][後手位置][ターン]
static int siMCnt;												// マス数

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
	static int siTNo;
#endif

// １行出力
int
fOutLine(
	char *pcpLine				// <I> １行
)
{
	char lc1Buf[1024];

#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, pcpLine)) {
		siRes = -1;
	}
#else
	printf("%s", pcpLine);
#endif

	return 0;
}

// 結果 - セット
int
fSetRes(
	int piNo1					// <I> 先手位置
	, int piNo2					// <I> 後手位置
	, int piTurn				// <I> ターン
	, int piRes					// <I> 勝敗
)
{
	// セット済
	if (sc3Res[piNo1][piNo2][piTurn] != D_RES_INI) {
		return 0;
	}

	// 結果 - セット
	sc3Res[piNo1][piNo2][piTurn] = piRes;

	// １手前へ
	if (piTurn == 0) {										// 先手
		if (piNo2 > 0 && piNo1 != piNo2 - 1) {
			fSetRes(piNo1, piNo2 - 1, !piTurn, piRes);
		}
		if (piNo2 < siMCnt - 1 && piNo1 != piNo2 + 1) {
			fSetRes(piNo1, piNo2 + 1, !piTurn, piRes);
		}
	}
	else {													// 後手
		if (piNo1 > 0 && piNo1 - 1 != piNo2) {
			fSetRes(piNo1 - 1, piNo2, !piTurn, piRes);
		}
		if (piNo1 < siMCnt - 1 && piNo1 + 1 != piNo2) {
			fSetRes(piNo1 + 1, piNo2, !piTurn, piRes);
		}
	}

	return 0;
}

// 実行メイン
int
fMain(
)
{
	char lc1Buf[1024];

	// マス数・位置 - 取得
	int li1No[2];
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%d%d%d", &siMCnt, &li1No[0], &li1No[1]);
	li1No[0]--;
	li1No[1]--;

	// 結果 - セット
	fSetRes(0, 1, 0, D_RES_LOSE);
	fSetRes(siMCnt - 2, siMCnt - 1, 1, D_RES_WIN);

	// 結果 - 取得
	return sc3Res[li1No[0]][li1No[1]][0];
}

// １回実行
int
fOne(
)
{
	int liRet;
	char lc1Buf[1024];

	// データ - 初期化
	memset(sc3Res, D_RES_INI, sizeof(sc3Res));					// 結果

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", siTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", siTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 実行メイン
	liRet = fMain();

	// １行出力
	switch (liRet) {
	case D_RES_WIN:
		sprintf(lc1Buf, "Alice\n");
		break;
	case D_RES_LOSE:
		sprintf(lc1Buf, "Borys\n");
		break;
	default:
		sprintf(lc1Buf, "Draw\n");
		break;
	}
	fOutLine(lc1Buf);

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", siTNo);
	}
	else {
		printf("NG %d\n", siTNo);
	}
#endif

	return 0;
}

// プログラム開始
int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		siTNo = i;
		fOne();
	}
#else
	fOne();
#endif

	return 0;
}



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

// vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << "\t";
  }
  return s;
}

int main() {
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  int cnt = 1;
  int ans = 0;
  for (int i = 0; i < n-1; ++i) {
    if (s[i] == s[i+1]) ++ans;
  }
  char c = s[0];
  int rev = 0;
  for (int i = 1; i < n-1; ++i) {
    if (s[i] != c) {
      c = s[i];
      ++rev;
    }
  }
  cout << min(n-1, ans+min(rev,k)*2) << endl;
}



Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.close();
		boolean b = n % 2 == 0;
		System.out.println(b?n/2:n/2+1);
	}
}


Measured memory_bytes: 21844
package main
import (
  "fmt"
  "os"
)
func main() {
  var s string
  var n int
  fmt.Scan(&s)
  n = len(s)
  var c []int = make([]int,26)
  var t []rune = []rune(s)
  if n < 26 {
    for i:=0;i<n;i++ {
      c[int(t[i])-97] = 1
    }
    for i:=0;i<26;i++ {
      if c[i] == 0 {
        fmt.Println(s+string(rune(i+97)))
        os.Exit(0)
      }
    }
  }
  c[int(t[n-1])-97] = 1
  for i:=n-2;i>=0;i-- {
    for j:=int(t[i])-96;j<26;j++ {
      if c[j] == 1 {
        fmt.Println(s[:i]+string(rune(j+97)))
        os.Exit(0)
      }
    }
    c[int(t[i])-97] = 1
  }
  fmt.Println(-1)
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false); //cin.tie(NULL); cout.tie(NULL)
#define mp make_pair
#define pb push_back
#define fs first
#define sc second

using namespace std;
typedef long long ll;
typedef long double ld;

void bug();

/* BIEN CUC BO BEGIN*/
	int h, w, a, b;
/* BIEN CUC BO END*/


void solve(){	
	cin >> h >> w >> a >> b;
	cout << h*w - a*w - h*b + a*b;
}

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

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

long long K;

int main() {
	cin >> K;
	if (K == 1) {
		cout << "1" << endl;
		cout << "1" << endl;
		return 0;
	}

	long long A = (K + 3) / 4; A *= 2;

	cout << A << endl;
	for (int i = 0; i < A; i++) {
		for (int j = 0; j < A; j++) {
			if (j) cout << " ";

			long long E = (i + j) % A + 1;

			if (i % 2 == 0 || E + A > K) cout << E;
			else cout << E + A;
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1152
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<math.h>

#define rep(i,a,b) for (int i = a;i < b;i++)

using namespace std;

int main() {
	int N, K;
	cin >> N >> K;
	int amari = N % K;
	
	if (amari == 0) {
		cout << 0 << endl;
	}
	else {
		cout << 1 << endl;
	}

	return 0;
}


Measured memory_bytes: 256
$N=<>;
sub f{
	$ret=0;
	@P=();
	for$i(0..$N-1)
	{
		$ret+=grep(!$_,@P[1..$_[$i]-1])*(1,1,2,6,24,120,720,5040)[$N-$i-1];
		$P[$_[$i]]=1;
	}
	$ret
}
print abs f(glob<>)- f(glob<>)


Measured memory_bytes: 768
#include<stdio.h>
#include<iostream>
#include<vector>
#include<string.h>
using namespace std;
typedef long long ll;
int main()
{
	string s;
	cin>>s;
	ll i;
	ll count=0;
	char at[17]="CODEFESTIVAL2016";
	for(i=0;i<s.size();i++)
	{
		if(at[i]!=s[i])
		count++;
	}
	cout<<count;
	return 0;
}

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

//#define DEBUG 1

//#define int long long
#define for0(i,n) for (int i=0; i<n; i++)
#define iter(c) for(auto it=c.begin(); it!=c.end(); it++)
#define iter2(c) for(auto it2=c.begin(); it2!=c.end(); it2++)
#define pb push_back
#define ms(a,z) memset(a,z,sizeof(a));
#define mp make_pair
#define X first
#define Y second
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define all(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define pmod(x,m) (((x)%(m)+m)%m)
#ifdef int
#define read(x) scanf("%lld",&x);
#else
#define read(x) scanf("%d",&x);
#endif

#ifdef DEBUG
#define nl cout<<"\n";
#define pr(x) cout<<(x)<<" ";
#define prl(x) cout<<#x " = "<<x<<endl;
#define prp(x) cout<<"("<<(x).first<<" "<<(x).second<<") ";
#define printv(v) {for(int _=0; _<sz(v); _++) cout<<v[_]<<" "; cout<<"\n";}
#define printa(a,s) {for (int _=0; _<s; _++) cout<<a[_]<<" "; cout<<"\n";}
#define print2D(a,m,n) {for (int _=0; _<m; _++) {for (int __=0; __<n; __++) cout<<a[_][__]<<" "; cout<<"\n";} cout<<"\n";}
#define priter(v) iter(v) {pr(*it)} nl
#define debug cout<<"ok at line "<<__LINE__<<endl;
#else
#define nl
#define pr(x)
#define prl(x)
#define prp(x)
#define printv(v)
#define printa(a,s)
#define print2D(a,m,n)
#define priter(v)
#define debug
#endif
#define MAXN 100

using namespace std;

typedef long long ll;

const int INF = 2147483647;
const long long INFL = 9223372036854775807LL;
const double EPSILON = 0.00000001;
const long long MOD = 1000000007;

ll dp[3][MAXN+5];
int a[3][MAXN+5];

int32_t main()
{
    #ifdef DEBUG
    //freopen("A.txt","r",stdin);
    //freopen("","w",stdout);
    #endif

    int n;
    cin >> n;
    for0(i,n) {
        cin >> a[0][i];
    }
    for0(i,n)
        cin>>a[1][i];
        
    ms(dp,0);
    for (int i=1; i>=0; i--) {
        for (int j=n-1; j>=0; j--) {
            dp[i][j] = max(dp[i+1][j],dp[i][j+1]) + a[i][j];
        }
    }
    cout<<dp[0][0]<<endl;
    return 0;
}


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

int main() {

	string S;
	cin >> S;

	int intT = 0;
	if (S[0] == '+') {
		intT++;
	}else{ intT--; }

	if (S[1] == '+') {
		intT++;
	}else{ intT--; }

	if (S[2] == '+') {
		intT++;
	}else{ intT--; }

	if (S[3] == '+') {
		intT++;
	}else{ intT--; }

	cout << intT << endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define lli long long int
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(lli i=0, i##_len=(lli)(n); i<i##_len; i++)
#define repf(i, n) for(lli i=1, i##_len=(lli)(n+1); i<i##_len; i++)
#define per(i, n) for(lli i=((lli)(n))-1; i>=0; i--)
#define perf(i, n) for(lli i=((lli)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<lli>
#define vvi vector<vector<lli>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    lli n, d, cnt = 0;
    cin >> n >> d;
    vvi x(n, vi(d, 0));
    rep(i, n){
        rep(j, d){
            cin >> x[i][j];
        }
    }
    
    rep(i, n-1){
        for(lli k=i+1; k<n; k++){
            lli sum = 0;
            rep(j, d) sum += pow((x[i][j]-x[k][j]), 2);
            double dist = sqrt(sum);
            if(dist == floor(dist)) cnt++;
        }
    }

    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

vector<int> fact;
vector<int> ifact;
vector<int> inv;
vector<int> pow2;
const int MOD = (1e9 + 7);
int add(int a, int b)
{
	a+=b;
	while(a>=MOD) a-=MOD;
	return a;
}
void radd(int &a, int b)
{
	a=add(a,b); 
}
int mult(int a, int b)
{
	return (a*1LL*b)%MOD;
}
void rmult(int &a, int b)
{
	a=mult(a,b);
}
int modpow(int a, int b)
{
	int r=1;
	while(b)
	{
		if(b&1) r=mult(r,a);
		a=mult(a,a);
		b>>=1;
	}
	return r;
}
int choose(int a, int b)
{
	if(a<b) return 0;
	if(b==0) return 1;
	if(a==b) return 1;
	return mult(fact[a],mult(ifact[b],ifact[a-b]));
}
int inverse(int a)
{
	return modpow(a,MOD-2);
}
void init(int _n)
{
	fact.clear(); ifact.clear(); inv.clear(); pow2.clear();
	fact.resize(_n+1);
	ifact.resize(_n+1);
	inv.resize(_n+1);
	pow2.resize(_n+1);
	pow2[0]=1;
	ifact[0]=1;
	fact[0]=1;
	for(int i=1;i<=_n;i++)
	{
		pow2[i]=add(pow2[i-1],pow2[i-1]);
		fact[i]=mult(fact[i-1],i);
		//ifact[i]=mult(ifact[i-1],inv[i]);
	}
	ifact[_n] = inverse(fact[_n]);
	for(int i=_n-1;i>=1;i--)
	{
		ifact[i] = mult(ifact[i + 1], i + 1);
	}
	for(int i=1;i<=_n;i++)
	{
		inv[i] = mult(fact[i-1],ifact[i]);
	}
}
	
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	ll a,b; cin>>a>>b; cout<<a*b<<'\n';
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
#define ran 200020
int n;
pair<int,int> a[ran];
int b[ran];
int main(){
	scanf("%d",&n);
	for(int i=0; i<n; i++){
		scanf("%d",&a[i].first);
		a[i].second = i;
	}
	sort(a,a+n);
	for(int i=0; i<n; i++){
		b[a[i].second] = i<n/2 ? a[n/2].first : a[n/2-1].first;
	}
	for(int i=0; i<n; i++)
		printf("%d\n",b[i]);
	return 0;
}


Measured memory_bytes: 4480
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long 

int dp[100010][13];

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin >> S;
    int len = S.length();
    int d = 0;
    int s = 0;
    dp[0][0] = 1;
    int times = 1;
    for(int i = len - 1; i >= 0; i--) {
        if (S[i] != '?') {
            int add = (S[i] - '0') * times % 13;
            for (int j = 0; j < 13; ++j) {
                (dp[d+1][j] += dp[d][(j-add + 13) % 13]) %= mod;
            }
        } else {
            REP(k, 0, 9) {
                int add = k * times % 13;
                for (int j = 0; j < 13; j++) {
                    (dp[d+1][j] += dp[d][(j-add + 13) % 13]) %= mod;
                }
            }
        }
        //rep(n, 13) cout << n <<":" << dp[d][n] << endl;
        d++;
        times = times * 10 % 13;
    }
    // rep(i, 13) {
    //     cout << i <<": ";
    //     rep(j, len) cout << dp[len][i] << " ";
    //     cout << endl;
    // }
    cout << dp[len][5] << endl;


    return 0;
}


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

#define mp make_pair

using namespace std;

typedef int32_t i32;
typedef uint32_t u32;
typedef int64_t i64;
typedef uint64_t u64;
typedef pair<int,int> pii;
typedef pair<i64,int> pli;
typedef pair<int,i64> pil;
typedef pair<i64,i64> pll;
typedef vector<int> vi;
typedef vector<i64> vl;

template <typename T>
T id(T b) {return b;};
template <class It>
bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It>
bool any(It f,It l){return std::any_of(f,l,id<bool>);}

template <int N> class rmq {
  int n; i64 dat[4*N-1];
  i64 query(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l) return INF;
    if (a <= l && r <= b) return dat[k];
    else {
      return min(query(a,b,2*k+1,l,(l+r)/2),query(a,b,2*k+2,(l+r)/2,r));
    }
  }

public:
  const i64 INF = INT64_MAX;
  rmq() {
    n = 1;
    while (n < N) n *= 2;
    for (int i = 0; i < 2*n-1; i++) dat[i] = INF;
  }

  void update(int k, i64 a) {
    k += n-1; dat[k] = a;
    while (k > 0) {
      k = (k-1) / 2;
      dat[k] = min(dat[2*k+1],dat[2*k+2]);
    }
  }

  i64 query(int a, int b) { return query(a, b, 0, 0, n); }
};

struct union_find {
  typedef vector<int> vi;
  vi parent,rank,cnt;
  int n;

  union_find(int n) : n(n) {
    parent = vi(n); rank = vi(n,0); cnt = vi(n,1);
    for (int i = 0; i < n; i++) parent[i] = i;
  }

  int find(int a) {
    if (parent[a] == a) return a;
    return parent[a] = find(parent[a]);
  }

  void unite(int a, int b) {
    a = find(a); b = find(b);

    if (a == b) return;
    if (rank[a] < rank[b]) {
      parent[a] = b; cnt[b] += cnt[a];
    } else {
      parent[b] = a; cnt[a] = cnt[b];
      if (rank[a] == rank[b])
        rank[a]++;
    }
  }

  int count(int a) { return cnt[find(a)]; }

  bool same(int a, int b) { return find(a) == find(b); }
};

typedef tuple<i64,int,int> edge;

const int MAX_N = 200000;
int n;
i64 d, a[MAX_N];
pii b[MAX_N];
int tab[MAX_N];
rmq<MAX_N> r1, r2;
map<i64,int> m;

int main()
{
  cin >> n >> d;
  for (int i = 0; i < n; i++) cin >> a[i], b[i] = mp(a[i],i);
  sort(b,b+n);

  for (int i = 0; i < n; i++) tab[b[i].second] = i;

  vector<edge> es;

  r1.update(tab[0], a[0]-d);
  m[a[0]-d] = 0;
  for (int i = 1; i < n; i++) {
    i64 v = r1.query(0,tab[i]);
    if (v < r1.INF) {
      int j = m[v];
      es.push_back(make_tuple(v+a[i]+(i+1)*d,i,j));
    }
    v = a[i]-(i+1)*d;
    r1.update(tab[i], v);
    m[v] = i;
  }

  m.clear();
  r2.update(tab[n-1], a[n-1]+n*d);
  m[a[n-1]+n*d] = n-1;
  for (int i = n-2; i >= 0; i--) {
    i64 v = r2.query(0,tab[i]);
    if (v < r2.INF) {
      int j = m[v];
      es.push_back(make_tuple(v+a[i]-(i+1)*d,i,j));
    }
    v = a[i]+(i+1)*d;
    r2.update(tab[i], v);
    m[v] = i;
  }

  sort(es.begin(),es.end());

  union_find uf(n);
  i64 res = 0;
  for (auto e : es) {
    i64 cost; int u,v;
    tie(cost,u,v) = e;
    if (uf.same(u,v)) continue;
    res += cost;
    uf.unite(u,v);
  }

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 39656
n,ms = map(int, input().split())
a = [list(map(str, input().split())) for _ in range(n)]
total = 0
for i in a:
    tmp = int(i[1]) - ms
    if tmp <= 0:
        total += ms + tmp
        print("{} {}".format(i[0], total))
    else:
        total += ms
        a.append([i[0], tmp])


Measured memory_bytes: 29636
#include <stdio.h>

int main(void){
    int n,a,ans=0;
    scanf("%d",&n);
    for (int i=0; i<n; i++){
        scanf("%d",&a);
        if (a%2==1){
            ans=1;
        }
    }
    if (ans==1){
        printf("first\n");
    } else {
        printf("second\n");
    }
	return 0 ;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<algorithm>
const int INF = 1001;
const int V = 20;
int dis[V][V];
int n, m;

void warshall_floyd(){
	for (int k = 0; k < n; ++k)
		for (int i = 0; i < n; ++i)
			for (int j = 0; j < n; ++j)dis[i][j] = std::min(dis[i][j], dis[i][k] + dis[k][j]);
}

int main(){
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) dis[i][j] = i == j ? 0 : INF;
	for (int i = 0; i < m; ++i){
		int a, b, c, d;
		scanf("%d,%d,%d,%d", &a, &b, &c, &d);
		--a; --b;
		dis[a][b] = c;
		dis[b][a] = d;
	}
	int x1, x2, y1, y2;
	scanf("%d,%d,%d,%d", &x1, &x2, &y1, &y2);
	--x1; --x2;
	warshall_floyd();
	y1 -= dis[x1][x2];
	y1 -= dis[x2][x1];
	y1 -= y2;
	printf("%d\n", y1);

	return 0;
}

Measured memory_bytes: 1012
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define llu long long unsigned
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
 
int n;
llu x;

llu int f(int lv){
  llu int res = 1;
  REP(i, lv+2) res *= 2;
  return res - 3;
}

llu int g(int lv){
  llu int res = 1;
  REP(i, lv+1) res *= 2;
  return res - 1;
}
llu int rec(llu int nokori, int now){
  llu int ans = 0;
  if(now == 0){
    return 1;
  }else{
    if(nokori == 1) return 0;
    else if(nokori <= 1 + f(now-1)) return rec(nokori-1, now-1);
    else if(nokori == 2 + f(now-1)) return (1 + rec(nokori-2, now-1));
    else if (nokori <= 2 + 2 *f(now-1)) return (1 + g(now-1) + rec(nokori - 2 - f(now-1), now-1));
    else return (1 + g(now-1) + rec(nokori - 3 - f(now-1), now-1));
  }
}
int main(){
  cin >> n >> x;
  cout << rec(x, n) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<map>
#include<set>
using lint=int64_t;
using namespace std;

int main()
{
	lint N;
	lint P[100010]={};
	cin >> N;
	for(int i=1;i<=N;i++)
		cin >> P[i];

	map<lint,lint> indexof;
	map<lint,lint> valueof;
	for(lint i=1;i<=N;i++)
	{
		indexof[P[i]]=i;
		valueof[i]=P[i];
	}
	valueof[0]=valueof[1];
	valueof[N+1]=valueof[N];

	multiset<lint> ipool;
	ipool.insert(0);
	ipool.insert(0);
	ipool.insert(N+1);
	ipool.insert(N+1);
	
	lint ans=0;
	for(lint i=N;i>=1;i--)
	{
		lint l2,l1,r1,r2;
		auto itr=ipool.lower_bound(indexof[i]);
		r1=*itr;
		++itr;
		r2=*itr;
		--itr;--itr;
		l1=*itr;
		--itr;
		l2=*itr;

		ans+=(indexof[i]-l1)*(r2-r1)*i;
		ans+=(l1-l2)*(r1-indexof[i])*i;

		ipool.insert(indexof[i]);
	}

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



Measured memory_bytes: 18176
def palindrome(s):
  for i in range(len(s) // 2):
    if s[i] != s[-i -1]:
      return False
  return True

def main():
  s = input()
  t = ''
  for ch in s:
    if ch != 'x':
      t += ch

  if len(t) == 0:
    print(0)
    return

  if (palindrome(t) == False):
    print(-1)
    return

  cnt = 0
  odd = len(t) & 1
  mid = len(t) // 2

  if odd == 1:  # ax[b]a

    for i in range(len(s)):
      if s[i] != 'x':
        cnt += 1
        if cnt == mid + 1:
          s1 = s[      : i]
          s2 = s[i + 1 :  ]
          break    

  else: # a[x]a

    for i in range(len(s)):
      if s[i] != 'x':
        cnt += 1
        if cnt == mid:
          s1 = s[  : i + 1]
        if cnt == mid + 1:
          s2 = s[i :  ]
          break

  # print(s1, s2)
  ans = 0
  i = 0
  j = 0
  while (i < len(s1) and j < len(s2)):
    c1 = s1[i]
    c2 = s2[-j-1]
    if c1 == c2:
      i += 1
      j += 1
      continue

    ans += 1
    if c1 == 'x':
      i += 1
    else:
      j += 1

  ans += (len(s1) - i) + (len(s2) - j)
  print(ans)






if __name__ == '__main__':
  main()

Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
const int MAX = 2020;
bool a[MAX][MAX]={};
using BS = bitset<MAX>;
BS st[MAX],dpL[MAX],dpR[MAX];
signed main(){
  int n;
  cin>>n;
  for(int i=1;i<n;i++){
    string s;
    cin>>s;
    for(int j=0;j<i;j++){
      a[i][j]=s[j]-'0';      
      a[j][i]=!a[i][j];
    }
  }
  
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
      if(a[i][j]) st[i].set(j);
      
  for(int i=0;i<n;i++){
    dpL[i].set(i);
    dpR[i].set(i);
  }

  for(int w=2;w<=n;w++){
    for(int i=0;i+w<=n;i++){
      int l=i,r=i+w-1;
      {
        BS x=dpR[l+1]&dpL[r]&st[l];      
        if((((x>>(r+1))<<(r+1))^((x>>(l+1))<<(l+1))).any()) dpL[r].set(l);
      }
      { 
        BS x=dpR[l]&dpL[r-1]&st[r];
        if((((x>>r)<<r)^((x>>l)<<l)).any()) dpR[l].set(r);        
      }
    }
  }
  
  cout<<(dpR[0]&dpL[n-1]).count()<<endl;  
  return 0;
}


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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);  
	int n, p;
	cin >> n >> p;
	vector<vector<long long>> dp(n + 1, vector<long long>(2));
	dp[0][0] = 1;
	for(int i = 0; i < n; i++) {
		int a;
		cin >> a;
		if(a % 2 == 0) {
			dp[i + 1][0] = dp[i][0] * 2LL;
			dp[i + 1][1] = dp[i][1] * 2LL;
		} else {
			dp[i + 1][0] = dp[i + 1][1] = dp[i][0] + dp[i][1];
		}
	}
	cout << dp[n][p] << endl;
	return 0;	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define what_is(x) cerr << #x << " is " << x << endl;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
typedef long long ll;
const int N = 3e3+5;
const int INF = 1e9;
const int MOD = 1e9+7;

int n;
long double p[N];
long double dp[N][2][N];
int main()
{
	IOS
	// freopen("input.txt", "r", stdin);
	cin >> n;
	for(int i=1; i<=n; i++){
		cin >> p[i];
	}
	dp[1][0][0] = 1 - p[1];
	dp[1][1][1] = p[1];
	for(int i=2; i<=n; i++){
		for(int j=0; j<=i; j++){
			dp[i][0][j] = (dp[i-1][0][j] + dp[i-1][1][j])*(1-p[i]);
			dp[i][1][j] = (dp[i-1][0][j-1] + dp[i-1][1][j-1])*p[i];
		}
	}
	long double ans = 0;
	for(int j=n/2+1; j<=n; j++){
		ans += dp[n][0][j] + dp[n][1][j];
	}
	cout << fixed << setprecision(10);
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 280192
#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>
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 ;

struct UnionFind{
   vector<int> par;
   UnionFind(int n):par(n,-1){}
   int find(int x){
       if(par[x]<0)return x;
       return par[x]=find(par[x]);
   }
   bool unite(int x,int y){
       x=find(x);
       y=find(y);
       if(x==y)return false;
       if(par[x]>par[y]){
           par[y]+=par[x];
           par[x]=y;
       }
       else{
           par[x]+=par[y];
           par[y]=x;
       }
       return true;
   }
 
   bool same(int x,int y){
       return find(x)==find(y);
   }
   int size(int x){
       return -par[find(x)];
   }
};

struct edge{int u,v,cost;};
bool comp(const edge& e1, const edge& e2){
  return e1.cost<e2.cost;
}
edge es[200010];
int V,E;

int kruskal(){
  sort(es, es+E, comp);
  UnionFind uf(V);
  int res=0;
  for(int i=0;i<E;i++){
    edge e=es[i];
    if(!uf.same(e.u, e.v)){
      uf.unite(e.u, e.v);
      res+=e.cost;
    }
  }
  return res;
}

int main(){
  cin >> V;
  E=2*(V-1);
  pint x[V],y[V];
  rep(i,V){
    cin >> x[i].first >> y[i].first;
    x[i].second=i;
    y[i].second=i;
  }
  sort(x,x+V);
  sort(y,y+V);
  rep(i,V-1){
    es[2*i]={x[i].second,x[i+1].second,x[i+1].first-x[i].first};
    es[2*i+1]={y[i].second,y[i+1].second,y[i+1].first-y[i].first};
  }
  int ans=kruskal();
  cout << ans << endl;
return 0;}

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

#define REP(i, start, count) for(int i=(start); i<(int)(count); ++i)
#define rep(i, count) REP(i, 0, count)
#define ALLOF(c) (c).begin(), (c).end()

typedef long long ll;
typedef unsigned long long ull;

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

    int num = N / 2;
    if (N % 2 == 1) num++;
    cout << num << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define INF 1e9

int N,M,R;
int edge[200][200]={};
int d[8][8];

int dfs(int mask,int v,int cost){
    if((1<<R)-1 == mask) return cost;
    int res = INF;
    rep(i,R){
        if((1<<i)&mask) continue;
        res = min(res,dfs(mask|(1<<i),i,cost+d[v][i]));
    }
    return res;
}

int main(void){
    cin>>N>>M>>R;
    vector<int> r(R);
    rep(i,R) cin>>r[i],r[i]--;
    rep(i,200) rep(j,200) edge[i][j]=(i==j ? 0 : INF);
    rep(i,M){
        int a,b,c;
        cin>>a>>b>>c;
        a--,b--;
        edge[a][b]=c;
        edge[b][a]=c;
    }

    rep(i,N)rep(j,N)rep(k,N) edge[j][k] = min(edge[j][k], edge[j][i] + edge[i][k]);
    int res=INF;
    rep(i,R)rep(j,R) d[i][j] = edge[r[i]][r[j]];
    rep(start,R){
        res=min(res,dfs(1<<start,start,0));
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 384
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long LL;
const int maxn = 1e5+5;

int a[maxn],b[maxn],c[maxn],dp[maxn][3];

int main(){
	int n;
	scanf("%d",&n);
	int m;
	for(int i = 1; i <= n; i++) scanf("%d %d %d", &a[i],&b[i],&c[i]);
	dp[1][0] = a[1]; dp[1][1] = b[1]; dp[1][2] = c[1];
	for(int i = 2; i <= n; i++){
		for(int j = 0; j < 3; j++){
			if(j == 0) dp[i][j] = max(dp[i-1][1] + a[i], dp[i-1][2] + a[i]);
			if(j == 1) dp[i][j] = max(dp[i-1][0] + b[i], dp[i-1][2] + b[i]);
			if(j == 2) dp[i][j] = max(dp[i-1][0] + c[i], dp[i-1][1] + c[i]);
		}
	}
	m = max(dp[n][0], dp[n][1]);
	m = max(m, dp[n][2]);
	printf("%d",m);
}

Measured memory_bytes: 2560
def moveRobot(d,l,robotPosition,square):
    get_gems = 0
    for i in range(0,l):
        if d == "N":
            robotPosition["y"] = min(20, robotPosition["y"]+1) 
        elif d == "S":
            robotPosition["y"] = max(0, robotPosition["y"]-1) 
        elif d == "E":
            robotPosition["x"] = min(20, robotPosition["x"]+1) 
        elif d == "W":
            robotPosition["x"] = max(0, robotPosition["x"]-1)
        if square[robotPosition["x"]][robotPosition["y"]] == 1:
            square[robotPosition["x"]][robotPosition["y"]] = 0
            get_gems += 1
    return robotPosition,square,get_gems

while True:
    N = int(input())
    if N == 0: break
    square = [[0] * 21 for i in range(21)]

    #Set gems
    total_gems = 0
    for i in range(0,N):
        position = input().split()
        square[int(position[0])][int(position[1])] = 1
        total_gems += 1

    M = int(input())
    robotPosition = {"x":10, "y":10}
    sum_gems = 0
    for i in range(0,M):
        operation = input().split()
        d,l = operation[0],int(operation[1])
        robotPosition,square,get_gems = moveRobot(d,l,robotPosition,square)
        sum_gems += get_gems
    if total_gems == sum_gems:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 5628