akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;

int main(){
	int counter = 0;

	for (int i = 0; i < 3; i++){
		int c;
		cin >> c;

		if(c == 5) {
			counter++;
		} else if(c == 7) {
			counter--;
		} else {
			cout << "NO" << endl;
			return 0;
		}
	}

	cout << ((counter == 1) ? "YES" : "NO") << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()
#define INF 3000000
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
int a[55][55];
int b[55][55];
int c[55][55];
int main()
{
	memset (a, 0, sizeof (a ) );
	memset (b, 0, sizeof (b ) );
	memset (c, 0, sizeof (c ) );
	ios_base::sync_with_stdio(0);
	int H, W; cin >> H >> W;
	rep (i, H ) rep (j, W ) cin >> a[i][j];
	rep (i, H ) rep (j, W ) cin >> b[i][j];
	int h, w; cin >> h >> w;
	rep (i, h ) rep (j, w ) cin >> c[i][j];

	int res = -INF;
	bool found = false;
	rep (i, H-h+1 ) rep (j, W-w+1 ){
		bool match = true;
		int cur = 0;
		rep (row, h ){
			rep (col, w ){
			 	if (b[i+row][j+col] != c[row][col] ){
					match = false; 
					break;
				}else{
					cur += a[i+row][j+col];
				} // end if
			} // end rep
			if (!match ) break;
		} // end rep
		if (match ){
			res = max (res, cur );
			found |= true;
		} // end if
	} // end rep
	if (!found ){
		cout << "NA" << endl;
	}else{
		cout << res << endl;
	} // end if
	return 0;
}


Measured memory_bytes: 1240
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int maxt = sc.nextInt();
		int[] c = new int[n];
		int[] t = new int[n];
		int minc = 0;
		int minct = 0;
		for (int i = 0; i < n; i++) {
			c[i] = sc.nextInt();
			t[i] = sc.nextInt();
			if (i == 0) {
				minc = c[i];
				minct = t[i];
			} else {
				if (t[i] <= maxt) {
					if (c[i] < minc) {
						minc = c[i];
						minct = t[i];
					}
				}
			}
		}
		if (minct > maxt) {
			System.out.println("TLE");
		} else {
			System.out.println(minc);
		}
 	}
}


Measured memory_bytes: 23636
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main(){
  int A, B, C;

  cin >> A >> B >> C;

  int ans = 0;

  while(!(A == B && B == C)) {
    if (B < C) swap(B, C);
    if (A < B) swap(A, B);
    if (B < C) swap(B, C);

    if (A != B) {
      B += 1;
      C += 1;
      ans++;
    } else {
      C += 2;
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
const int mx = 2e5;
 
 
int main(void){
  ll N,M;
  cin >> N >> M;
  
  ll mar[N], vote=0;
  for(int i=0; i<N; i++){
    cin >> mar[i];
    vote += mar[i];
  }
  
  double lim = (double)vote / 4.0 / (double)M;
  ll mars = 0;
  for(int i=0; i<N; i++){
    if(mar[i]>=lim){
      mars++;
    }
  }
  if(mars<M){
    cout << "No";
  }else{
    cout << "Yes";
  }
  //cout << "\n" << vote << " " <<lim << " " <<M;
 
  return 0;
}

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

int main() {

    vector<bool> primes (1000000);
    for (int n = 0; n < 1000000; n++) {
        primes[n] = true;
    }
    primes[0] = false;
    primes[1] = false;

    for (int n = 2; n < 1000000; n++) {
        if (primes[n]) {
            for (int k = 2*n; k < 1000000; k = k+n) {
                primes[k] = false;
            }
        }
    }

    int n;
    while (cin >> n) {
        int result = 0;
        for(int i = 0; i <= n; i++) {
            if ( primes[i] ) {
                result += 1;
            }
        }
        cout << result << endl;
    }
     
    return 0;
}

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

int main() {
    string s, a="", b="";
    cin >> s;
    if (s.length() == 0) {
        puts("0");
        return 0;
    }

    int zero_one_diff = 0, one_zero_diff = 0;
    for (int i = 0; i < s.length(); i++) {
        if (i % 2 == 0) {
            s[i] == '0' ? zero_one_diff++ : one_zero_diff++;
        } else {
            s[i] == '1' ? zero_one_diff++ : one_zero_diff++;
        }
    }
    printf("%d", min(zero_one_diff, one_zero_diff));

    return 0;
}

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

// const int MAXN = 1e5 + 7;
// const long long INF = 1e18;

// long long height = 0;
// long long dp[MAXN];
// long long h[MAXN];
// int n, k;

// long long rec(int idx)
// {
//     if (dp[idx] != -1)
//         return dp[idx];
//     if (idx == n - 1)
//     {
//         dp[idx] = 0;
//         return dp[idx];
//     }
//     dp[idx] = INF;
//     for (int i = 1; i <= k; i++)
//     {
//         if (idx + i <= (n - 1))
//         {
//             dp[idx] = min(dp[idx], rec(idx + i) + abs(h[idx + i] - h[idx]));
//         }
//     }
//     return dp[idx];
// }

// int main()
// {
//     cin >> n >> k;
//     for (int i = 0; i < n; i++)
//         cin >> h[i];
//     for (int i = 0; i < n; i++)
//         dp[i] = -1;
//     cout << rec(0) << endl;
//     return 0;
// }

int n, k;
int h[100005], dp[100005];

// dp[i] = min cost to go from 0 to i

int rec(int idx)
{
    if (dp[idx] != -1)
        return dp[idx];

    if (idx == 0)
        dp[idx] = 0;
    else if (idx == 1)
        dp[idx] = abs(h[idx] - h[idx - 1]);
    else
    {
        dp[idx] = INT_MAX;
        for (int i = 1; i <= k; i++)
        {
            if (idx - i >= 0)
            {
                int curr = rec(idx - i) + abs(h[idx] - h[idx - i]);
                dp[idx] = min(dp[idx], curr);
            }
        }
    }
    return dp[idx];
}

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

    for (int i = 0; i < n; i++)
        dp[i] = -1;

    int ans = rec(n - 1);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4096
import java.util.*;

class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int t[] = new int[n];

        for(int i = 0; i < n; i++){
          t[i] = sc.nextInt();
        }

        int m = sc.nextInt();
        int sum[] = new int[m];
        int p=0; //ドリンクの効果が表れる番目
        int x=0; //ドリンクを飲んだ時何秒になるか
        for(int j = 0; j < m; j++){
          p = sc.nextInt();
          x = sc.nextInt();
           int temp = t[p-1];
           t[p-1] = x;
           for(int k = 0; k < n; k++){
             sum[j] += t[k];
           }
           t[p-1] = temp;
        }
        for(int l = 0; l < m; l++){
          System.out.println(sum[l]);
        }
    }
}


Measured memory_bytes: 22868
#include<iostream>
#include<cstdio>
#include<cstring>
using  namespace  std;
int main()
{
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	if (a==b) cout<<c;
	else if (a==c) cout<<b;
	else if (c==b) cout<<a;
 } 

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

const ll MOD = 1000000007;

int main(void) {
  ll N, M;
  cin >> N >> M;
  vector<ll> A(N), B(M);
  REP(i, 0, N) cin >> A[i];
  REP(i, 0, M) cin >> B[i];

  vector<ll> row(N * M + 1, -1), col(N * M + 1, -1);
  REP(i, 0, N) {
    if (row[A[i]] != -1) {
      cout << 0 << endl;
      return 0;
    }
    row[A[i]] = i;
  }
  REP(i, 0, M) {
    if (col[B[i]] != -1) {
      cout << 0 << endl;
      return 0;
    }
    col[B[i]] = i;
  }

  ll ans = 1;
  ll cr = 0, cc = 0;
  for (ll k = N * M; k >= 1; k--) {
    ll r = row[k], c = col[k];
    if (r != -1 && c != -1) {
      cerr << "  " << 1 << endl;
      cr++;
      cc++;
    } else if (r != -1 && c == -1) {
      cerr << "  " << cc << endl;
      ans *= cc;
      ans %= MOD;
      cr++;
    } else if (r == -1 && c != -1) {
      cerr << "  " << cr << endl;
      ans *= cr;
      ans %= MOD;
      cc++;
    } else {
      ans *= (cr * cc) - (N * M - k);
      ans %= MOD;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 15872
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdlib.h>
#include<utility>
#include<functional>
#include<cfenv>
#include<cmath>
#include<string>
#include<queue>
#include<map>
#include<set>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define vint vector<ll>
#define vvint vector<vint>
#define P pair<int,int>
#define INT_MAX 2147483647
using namespace std;
typedef long long ll;


int main(void) {
	string s; cin >> s;
	rep(i, s.size()) {
		cout << 'x';
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#ifndef ONLINE_JUDGE
#define _GLIBCXX_DEBUG
#endif
#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目*/
#define pb push_back
#define eb emplace_back
#define SZ(x) ((ll)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
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;
//ll MOD=1000000007LL;
//const ll MOD=998244353LL;
//const ll MOD=1777777777LL;
//const ll MAX_V=114514LL;
//const ll MAX = 500010LL;
const ll mod=MOD;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
vl dx={0,0,1,-1};
vl dy={1,-1,0,0};

//素因数分解O(√n)
map<ll,ll>prime_factor(ll n){
  map<ll,ll>res;
  for(ll i=2;i*i<=n;i++){
    while(n%i==0){
      res[i]++;
      n/=i;
    }
  }
  if(n!=1)res[n]=1;
  return res;
}

const ll MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
//finvが階乗の逆元

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll 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(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll modpow(ll a, ll n, ll mod) {
  
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}



int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  cout << fixed << setprecision(10);
  /*--------------------------------*/
  ll n;cin>>n;
  vl x(n),y(n),p(n);
  rep(i,n)cin>>x[i]>>y[i]>>p[i];
  vvl bitx((1<<n),vl(n)),bity((1<<n),vl(n));
  rep(bit,1<<n){
    rep(i,n){
      bitx[bit][i]=min(abs(x[i]),abs(y[i]));
      bity[bit][i]=min(abs(x[i]),abs(y[i]));
    }
  }
  vl ans(n+1,INF);
  vl pow(16);
  vl three(16);
  pow[0]=1;
  three[0]=1;
  rep(i,15)pow[i+1]=pow[i]*2;
  rep(i,15)three[i+1]=three[i]*3;
  rep(bit,(1<<n)){
    rep(i,n){
      rep(j,n){
        if(bit(bit,j))bitx[bit][i]=min(bitx[bit][i],abs(x[i]-x[j]));
      }
    }
  }
  rep(bit,(1<<n)){
    rep(i,n){
      rep(j,n){
        if(bit(bit,j))bity[bit][i]=min(bity[bit][i],abs(y[i]-y[j]));
      }
    }
  }
  // rep(bit,1<<n){
  //   rep(i,n)cout<<bitx[bit][i]<<" ";
  //   cout<<endl;
  // }
  
  rep(bit,three[n]){
    
    ll sumx=0,sumy=0;
    ll cnt=0;
    ll tmp=bit;
    
    rep(i,n){
      cnt++;
      if(tmp%3==1)sumx+=pow[i];
      else if(tmp%3==2)sumy+=pow[i];
      else cnt--;
      tmp/=3;
      if(tmp==0)break;
    }
    
    // cout<<bit<<" "<<sumx<<" "<<sumy<<endl;
    ll part=0;
    
    rep(i,n){
      part+=p[i]*min(bitx[sumx][i],bity[sumy][i]);
    }
    ans[cnt]=min(ans[cnt],part);
    // cout<<bit<<" "<<part<<" "<<cnt<<endl;
    
  }
  rep(i,n+1)cout<<ans[i]<<'\n';
  
}
  


Measured memory_bytes: 12940
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
    int a, b;
    string c;
    
    cin >> a >> b;
    
    if (a * b % 2 == 0) c = "Even";
    else c = "Odd";
    
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<unordered_map>
#include<algorithm>
#include<functional>


using namespace std;

class Main{
public:
  void input();
  void run();

private:
  int R;
  int G;
  int B;
  int N;
  vector<int> v;
};


void Main::input(){
  cin >> R >> G >> B >> N;
  v.emplace_back(R);
  v.emplace_back(G);
  v.emplace_back(B);
  sort(v.begin(), v.end(), greater<int>());
  return;
}


void Main::run(){
  int sum = 0;
  for( int i = 0; i <= N; i+=v[0] ){
    for( int j = 0; i+j <= N; j+=v[1] ){
      int c = (N-i-j) % v[2];
      if( c == 0 ){ ++sum; }
      // cout << i << "," << j << "," << c << endl;
    }
  }
  cout << sum << endl;
  return;
}






int main(){
  Main m;
  m.input();
  m.run();
  return 0;
}



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

int N;
vector<vector<pair<int,lint>>> edge;
int col[100010];
bool ok;

void dfs(int cur,int prev,int ccol)
{
	if(!ok)return;
	
	col[cur]=ccol;

	for(auto&& i:edge[cur])
	{
		int to=i.first;
		lint dist=i.second;
		if(to==prev)continue;

		if(col[to]==-1)
		{
			if(dist%2==0)
				dfs(to,cur,ccol);
			else
				dfs(to,cur,1-ccol);
		}
		else if(col[cur]==col[to])
		{
			if(dist%2==1)
			{
				ok=false;
				return;
			}
		}
	}
	return;
}
int main()
{
	cin >> N;

	edge.resize(N);
	for(int i=0;i<N-1;i++)
	{
		int u,v;
		lint w;
		cin >> u >> v >> w;
		u--;
		v--;
		edge[u].push_back(make_pair(v,w));
		edge[v].push_back(make_pair(u,w));
	}

	for(int i=0;i<N;i++)
		col[i]=-1;
	ok=true;
	dfs(0,-1,0);
	
	if(!ok)
	{
		for(int i=0;i<N;i++)
			cout << col[i] << endl;
		return 0;
	}
	
	for(int i=0;i<N;i++)
		col[i]=-1;
	ok=true;
	dfs(0,-1,1);
	for(int i=0;i<N;i++)
		cout << col[i] << endl;
	return 0;
}



Measured memory_bytes: 11264
import sys
from itertools import combinations as combi
input = sys.stdin.readline
H, W, K = map(int, input().split())
S = [list(input())[: -1] for _ in range(H)]
cs = [[0] * (W + 1) for _ in range(H)]
for i in range(H):
  for j in range(W): cs[i][j + 1] = cs[i][j] + int(S[i][j] == "1")
res = H * W
#print(cs)
for t in range(H):
  for c in combi([x for x in range(H - 1)], t):
    l = 0
    tres = 0
    while l < W:
      ok = l
      ng = W + 1
      while ng - ok > 1:
        m = (ok + ng) // 2
        tt = 0
        i = 0
        ttt = 0
        while i < H:
          ttt += cs[i][m] - cs[i][l]
          if i in c:
            tt = max(tt, ttt)
            ttt = 0
          i += 1
        tt = max(tt, ttt)
        if tt <= K: ok = m
        else: ng = m
      if l == ok:
        tres = H * W
        break
      l = ok
      tres += int(l < W)

    #print(c, tres)
    res = min(res, tres + len(c))
print(res)

Measured memory_bytes: 46812
#!/usr/bin/env python
# _*_ coding: utf-8 _*_
a = input()
a.split()
a.split()[1]

A = int(a.split()[0])
B = int(a.split()[1])

sum = A + B

if sum < 10:
    print(sum)

elif sum >= 10:
    print("error")


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#include <variant>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

constexpr int C = 200000;

int solve(vector<tuple<int,int,char>>& vt) {
  vecint xpy(400001, -1e8);
  vecint xmy(400001, -1e8);
  sort(ALL(vt));
  int mn = 1e8;
  int last_u_x = -1;
  int last_u = -1e8;
  for (auto&&[x,y,u] : vt) {
    switch (u) {
      case 'R':
        xpy[x+y] = max(xpy[x+y], x);
        xmy[x-y+C] = max(xmy[x-y+C], x);
        break;
      case 'U':
        mn = min(mn, (x - xpy[x+y]) * 10);
        last_u_x = x;
        last_u = y;
        break;
      case 'D':
        mn = min(mn, (x - xmy[x-y+C]) * 10);
        if (x == last_u_x) {
          mn = min(mn, (y - last_u) * 5);
        }
        break;
    }
  }
  return mn;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin>>n;
  vector<tuple<int,int,char>> vt;
  REP(i,n) {
    int x,y;
    string u;
    cin>>x>>y>>u;
    vt.emplace_back(x,y,u[0]);
  }
  int mn = 1e8;
  REP(i,2) {
    mn = min(mn, solve(vt));
    for (auto&&[x,y,u] : vt) {
      x = C - x;
      if (u == 'R') {
        u = 'L';
      } else if (u == 'L') {
        u = 'R';
      }
    }
    mn = min(mn, solve(vt));
    for (auto&&[x,y,u] : vt) {
      int tmp = x;
      x = y;
      y = tmp;
      switch (u) {
        case 'L': u = 'D'; break;
        case 'R': u = 'U'; break;
        case 'U': u = 'R'; break;
        case 'D': u = 'L'; break;
      }
    }
  }
  if (mn >= 1e8) {
    cout<<"SAFE\n";
  } else {
    cout<<mn<<"\n";
  }
  return 0;
}


Measured memory_bytes: 8732
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1000000;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}

/*------------------------------------------------------------------*/


int main(){
    int n; cin >> n;
    vector<int> p(n);
    rep(i, n) cin >> p[i];
    int ans = 0;
    _rep(i, 1, n - 1){
        if((p[i - 1] < p[i] and p[i] < p[i + 1]) 
        or (p[i - 1] > p[i] and p[i] > p[i + 1])) ans++; 
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <sstream>
 
#define INPUT_FROM_FILE (0) 
#if INPUT_FROM_FILE
#include <fstream>
#endif

bool is_leap_year(int year){
	if(year % 4 == 0){
		if(year % 400 == 0){
			return true;
		}
		else if(year % 100 == 0){
			return false;
		}
		else{
			return true;
		}
	}

	return false;
}


int main(int argc, char **argv){
	int a, b;
	bool is_first = true;

#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
	//FILE *fp = fopen("test.txt", "r");
#endif

#if INPUT_FROM_FILE
	while(ifs >> a >> b){
#else
	while(std::cin >> a >> b){
#endif
		if(a == 0 && b == 0){ break; }
		if(is_first){
			is_first = false;
		}
		else{
			std::cout << std::endl;
		}
		std::vector<int> leap_years;

		for(int i = a; i <= b; i++){
			if(is_leap_year(i)){
				leap_years.push_back(i);
			}
		}

		if(leap_years.empty()){
			std::cout << "NA" << std::endl;
		}
		else{
			for(int i = 0; i < leap_years.size(); i++){
				std::cout << leap_years[i] << std::endl;
			}
		}
	}

 
#if INPUT_FROM_FILE
	//fclose(fp);
#endif
    return 0;
}


Measured memory_bytes: 3020
import math

def intinput():
    return int(input())

def listintinput():
    return list(map(int,input().split()))

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

A,B,C,D = splitintinput()
if B <= C or A >= D:
    print(0)
else:
    print(min(B,D) - max(A,C))

Measured memory_bytes: 3060
n,m,q = gets.to_s.split.map{|t|t.to_i}

abcd = Array.new(q) do
  a, b, c, d = gets.to_s.split
  a, b, c, d = a.to_i-1, b.to_i-1, c.to_i, d.to_i
end.sort

ans = 0
(1..m).to_a.repeated_combination(n) do |cmb|
  
  cnt = 0
  abcd.each do |a,b,c,d|
    
    if cmb[b] - cmb[a] == c
      cnt += d
    end
  end
  
  ans = cnt if ans < cnt
end

puts ans

Measured memory_bytes: 14752
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) {

		 BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		 try{

			 int x = Integer.parseInt(br.readLine());

			 System.out.printf("%d\n", x*x*x);

		 }catch(IOException e){
			 e.printStackTrace();
		 }
	}
}





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

int main() {
  int N;
  cin >> N;
  vector<vector<int>> a(2,vector<int>(N));
  for(int i=0; i<2; i++){
    for(int j=0; j<N; j++){
    cin >> a.at(i).at(j);
  }}
  
 	int max_T=0;
    int sum1_0 = 0;	
  for(int j=0; j<N; j++){
    sum1_0 += a.at(1).at(j); //2列目の和
  }

  for(int k=0; k<N; k++){
    int sum_0 = 0;
    int sum_1 = sum1_0;
    for(int j=0; j<=k; j++){
     sum_0 += a.at(0).at(j);
     if(j!=0){
       sum_1 -= a.at(1).at(j-1);
     }
  }
    int T= sum_0 +sum_1;
    max_T = max(max_T, T);
  }

  cout << max_T <<endl;
  return 0;
} 
    
    

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    double n = sc.nextDouble();
    double answer =0;
    if(n%2==0){
      answer = 0.5;
    }else{
      answer = (n+1)/(2*n);
    }
    
    System.out.println(answer);
  }
  

  
}

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);  
	int h, w, d;
	cin >> h >> w >> d;
	vector<int> x(h * w + 1), y (h * w + 1);
	for(int i = 1; i <= h; i++) {
		for(int j = 1; j <= w; j++) {
			int a;
			cin >> a;
			x[a] = i;
			y[a] = j;
		}
	}
	vector<int> a(h * w + 1);
	for(int i = d; i < h * w + 1; i++) {
		a[i] = a[i - d] + abs(x[i] - x[i - d]) + abs(y[i] - y[i - d]);
	}
	int q;
	cin >> q;
	for(int i = 0; i < q; i++) {
		int l, r;
		cin >> l >> r;
		cout << a[r] - a[l] << endl;
	}
	return 0;	
}


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

int main(){
      int n,m,x;cin >> n >> m >> x;
      int l = 0;
      int r = 0;
      for(int i = 0;i < m;i++){
            int t;cin >> t;
            if(t < x)l++;
            else r++;
      }
      cout << min(l, r);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 55555, mz = 1e9+7;
bool vis[N];
int n;
void init(){
    for(int i = 2 ; i < N ; i++){
        if( vis[i] )    continue;
        for(long long j = 1LL*i*i ; j < N ; j+=i)
            vis[j] = 1;
    }
}

int main(){
    init();
    cin>>n;
    for(int i = 2 ; i < N && n; i++){
        if( vis[i] )    continue;
        if( i%5==1 )
            printf("%d%c",i,n--==1?'\n':' ');
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

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

    if((a < c && c < b) || (a == c && b > a)){
        printf("%d %d %d\n", a, c, b);
    }
    else if((b < a && a < c) || (a == c && b < a)){
        printf("%d %d %d\n", b, a, c);
    }
    else if(c < a && a < b){
        printf("%d %d %d\n", c, a, b);
    }
    else if(b < c && c < a){
        printf("%d %d %d\n", b, c, a);
    }
    else if((c < b && b < a) || (a == b && c < a) || (b == c && c < a)){
        printf("%d %d %d\n", c, b, a);
    }
    else printf("%d %d %d\n", a, b, c);
   
    return 0;
}


Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
typedef pair<int, int> P_i;
typedef pair<double,double> P_d;
#define rep(i,n) for(int i=0;i<(n);++i)
#define alrep(i,j,n) for(int i=0;i<(n);++i)for(int j=i+1;j<(n);++j)
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;int ans=0;
#define answer cout << ans << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int MOD=1e9+7;
const long long INF = 1LL << 60;

signed main(){
  // 頂点数と辺数
  int N, M; cin >> N >> M;

  int dp[N][N];
  rep(i,N)rep(j,N){
    if(i!=j) dp[i][j]=INF;
    else dp[i][j]=0;
  }
  for (int i = 0; i < M; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    dp[a][b]=c;
  }
  for(int k=0;k<N;k++){
    for(int i=0;i<N;i++){
      for(int j=0;j<N;j++){
        dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
      }
    }
  }
  rep(i,N){
    if(dp[i][i]<0){
      cout << "NEGATIVE CYCLE" << endl;
      return 0;
    }
  }
  rep(i,N){
    rep(j,N-1){
      if(dp[i][j]>=INF/2) cout << "INF" << " ";
      else cout << dp[i][j] << " ";
    }
    if(dp[i][N-1]>=INF/2) cout << "INF" << endl;
    else cout << dp[i][N-1] << endl;
  }
  return 0;
}



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

int main() {
	ll a, b;
	cin >> a >> b;
	if (a <= b) {
		cout << min(b - a, 1 + abs(abs(b) - abs(a)));
	} else if (a > b) {
		if (abs(a) == abs(b)) {
			cout << 1 << endl;
		} else if (a <= 0 && b <= 0) {
			if (a == 0) {
				cout << abs(b) + 1 << endl;
			} else {
				cout << 1 + abs(abs(b) - abs(a)) + 1 << endl;
			}
		} else if (a <= 0 && b >= 0) {

		} else if (a >= 0 && b <= 0) {
			cout << 1 + abs(abs(b) - abs(a)) << endl;
		} else if (a >= 0 && b >= 0) {
			cout << 1 + abs(abs(b) - abs(a)) + 1 << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3620
#include<iostream>
#include<algorithm>
#include<vector>
#define MOD ((int)1e9 + 7)
using namespace std;
int N;
vector<vector<int> > dp(100, vector<int>(256, -1));

bool check(int num) {
	vector<int> line(4);
	for (int i = 0; i < 4; ++i) {
		line[i] = num & 3;
		num /= 4;
	}
	bool flag = true;
	for (int i = 0; i < 3; ++i) {
		if (line[i] != i + 1) {
			flag = false;
			break;
		}
	}
	if (flag) {
		return true;
	}
	flag = true;
	for(int i= 1;i<4;++i){
		if (line[i] != i) {
			flag = false;
			break;
		}
	}
	if (flag) {
		return true;
	}
	for (int i = 0; i < 3; ++i) {
		swap(line[i], line[i + 1]);
		flag = true;
		for (int j = 0; j < 3; ++j) {
			if (line[j] != j + 1) {
				flag = false;
				break;
			}
		}
		if (flag) {
			return true;
		}
		flag = true;
		for (int j = 1; j < 4; ++j) {
			if (line[j] != j) {
				flag = false;
				break;
			}
		}
		if (flag) {
			return true;
		}
		swap(line[i], line[i + 1]);
	}
	return false;
}

int addn(int x, int a) {
	return (x * 4 + a) % 256;
}
int func(int place, int num) {
	if (place == N) {
		return 1;
	}
	if (dp[place][num] >= 0) {
		return dp[place][num];
	}
	int res = 0;
	for (int i = 0; i < 4; ++i) {
		int nn = addn(num, i);
		if (check(nn))continue;
		res = (res + func(place + 1, nn)) % MOD;
	}
	dp[place][num] = res;
	return res;
}
int main() {
	cin >> N;
	cout << func(0, 0) << endl;
	return 0;
}

Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main{
	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader bfr=new BufferedReader(new InputStreamReader(System.in));
		String str="";
		str=bfr.readLine();
		String[] wake=str.split(" ");
		int kazu1=Integer.parseInt(wake[0]);
		int kazu2=Integer.parseInt(wake[1]);
		if((kazu1+kazu2)%2==0) {
			System.out.println((kazu1+kazu2)/2);
		}
		else {
			System.out.println((kazu1+kazu2)/2+1);
		}
	}
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
int main (){
    int K;
    cin>>K;
    vector<int> a{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    
    cout<<a.at(K-1)<<endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		char[][] c = new char[H][W];
		int[][][] ans=new int[H][W][2];
		for (int i=0;i<H;i++) {
			String S=sc.next();
			for (int j=0;j<W;j++) {
				c[i][j]=S.charAt(j);
			}
		}
		for (int i=0;i<H;i++) {
			int left=0;
			int right=0;
			Queue<int[]> queue = new ArrayDeque<int[]>();
			for (int j=0;j<W;j++) {
				if (c[i][j]=='#') {
					ans[i][j][0]=-5000000;
					int[] tmp = {i,left,right};
					queue.add(tmp);
					right++;
					left=right;
				} else {
					if (j==W-1) {
						right++;
						int[] tmp = {i,left,right};
						queue.add(tmp);
					} else {
						right++;
					}
				}
				while (!queue.isEmpty()) {
					int[] rem=queue.remove();
					int I = rem[0];
					int Left = rem[1];
					int Right = rem[2];
					for (int k=Left;k<Right;k++) {
						ans[I][k][0]=Right-Left;
					}
				}
			}
		}
		for (int j=0;j<W;j++) {
			int left=0;
			int right=0;
			Queue<int[]> queue = new ArrayDeque<int[]>();
			for (int i=0;i<H;i++) {
				if (c[i][j]=='#') {
					ans[i][j][1]=-5000000;
					int[] tmp = {j,left,right};
					queue.add(tmp);
					right++;
					left=right;
				} else {
					if (i==H-1) {
						right++;
						int[] tmp = {j,left,right};
						queue.add(tmp);
					} else {
						right++;
					}
				}
				while (!queue.isEmpty()) {
					int[] rem=queue.remove();
					int J = rem[0];
					int Left = rem[1];
					int Right = rem[2];
					for (int k=Left;k<Right;k++) {
						ans[k][J][1]=Right-Left;
					}
				}
			}
		}

		int[][] ans_2 = new int[H][W];
		int Ans=0;
		for (int i=0;i<H;i++) {
			for (int j=0;j<W;j++) {
				ans_2[i][j]=ans[i][j][0]+ans[i][j][1];
				Ans=Math.max(Ans,ans_2[i][j]);
			}
		}
		System.out.println(Ans-1);
	}
}

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





int main() {
  int N,Y;
  cin >> N>>Y;
  string str = "No";
  for(int i =0;i<=N;i++){
    if(Y == i*2+(N-i)*4) {
      str = "Yes";
      break;
    }
  }
  
  cout << str <<endl;

}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#pragma GCC optimize ("O2")
#pragma GCC optimize ("unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const ld eps=1e-7;
const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 310, LOG=20;

int n, m, k, u, v, x, y, t, a, b, ans;
int H[MAXN];
ll dp[MAXN][MAXN][MAXN];
vector<int> comp;

inline void upd(ll &x, ll y){
	x=min(x, y);
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin>>n>>k;
	for (int i=1; i<=n; i++) cin>>H[i], comp.pb(H[i]);
	comp.pb(0);
	sort(all(comp));
	comp.resize(unique(all(comp))-comp.begin());
	for (int i=1; i<=n; i++) H[i]=lower_bound(all(comp), H[i])-comp.begin();
	
	memset(dp, 63, sizeof(dp));
	for (int j=0; j<=k; j++) for (int x=0; x<comp.size(); x++) dp[0][j][x]=0;
	
	for (int i=1; i<=n; i++) for (int j=0; j<=k; j++) for (int x=comp.size()-1; x>=0; x--){
		upd(dp[i][j][x], dp[i-1][j][H[i]] + max(0, comp[H[i]]-comp[x]));
		if (x+1<comp.size()) upd(dp[i][j][x], dp[i][j][x+1] + comp[x+1]-comp[x]);
		if (j) upd(dp[i][j][x], dp[i-1][j-1][x]);
	}
	cout<<dp[n][k][0]<<'\n';
	
	return 0;
}

Measured memory_bytes: 232960
#include <bits/stdc++.h>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long int ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
const int MOD=1000000007;

bool isPowerOfTwo (ll x)  
{  
    return x && (!(x&(x-1)));  
}
bool isPrime(int n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}
int highestPowerof2(unsigned int n) 
{ 
    // Invalid input 
    if (n < 1) 
        return 0; 
  
    int res = 1;
    for (int i=0; i<8*sizeof(unsigned int); i++) 
    { 
        int curr = 1 << i; 
        if (curr > n) 
           break; 
  
        res = curr; 
    } 
  
    return res; 
} 
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
/*lcm(gcd(N1, M), gcd(N2, M), ..., gcd(Nk, M)) = gcd(lcm(N1, ..., Nk), M)
gcd(lcm(N1, M), lcm(N2, M), ..., lcm(Nk, M)) = lcm(gcd(N1, ..., Nk), M).

If gcd(N1, N2) = 1, then
gcd(N1·N2, M) = gcd(N1, M)·gcd(N2, M)
lcm(N1·N2, M) = lcm(N1, M)·lcm(N2, M)/M.

lcm(M, N, P) · gcd(M, N) · gcd(N, P) · gcd(P, M) = NMP · gcd(N, M, P).
*/
////////////////////////////////////////////////////////////////////

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);  
  cout.tie(NULL);
  ll t=1;
  while(t--)
  {
    int n;
    cin>>n;
    int a[n],b[n];
    REP(i,n)
    {
        cin>>a[i]>>b[i];
    }
    ll ans=0;
    for(int i=n-1;i>=0;i--)
    {
        if((a[i]+ans)%b[i] == 0)continue;
        ll x=b[i]-((a[i]+ans)%b[i]);
        ans+=x;
    }
    cout<<ans;
  }  
  return 0;
}
/* Look for:
* the exact constraints (multiple sets are too slow for n=10^6 :( )
* special cases (n=1?)
* 1LL<<i and not 1<<i
* overflow (int vs ll?)
* array bounds
* if you have no idea just guess the appropriate well-known algo instead of doing nothing :/
*/

Measured memory_bytes: 4424
#!/usr/bin/env python3
import sys


def solve(H: int, W: int, S: "List[str]"):
    ret = []
    for x, R in enumerate(S):
        r = ''
        for y, c in enumerate(R):
            if c == '.':
                tmp = 0
                for i in range(-1, 2):
                    for j in range(-1, 2):
                        if 0 <= x + i < H and 0 <= y + j < W and S[x + i][y + j] == '#':
                            tmp += 1
                r += str(tmp)
            else:
                r += c
        ret.append(r)

    for r in ret:
        print(r)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    S = [ next(tokens) for _ in range(H) ]  # type: "List[str]"
    solve(H, W, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3192
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int pnum = 0;
		int a[] = new int[n];
		int b[] = new int[n];
		int c[] = new int[n-1];
		int sum = 0;
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		for(int i = 0; i < n; i++) {
			b[i] = sc.nextInt();
		}
		for(int i = 0; i < n-1; i++) {
			c[i] = sc.nextInt();
		}

		for(int i = 0; i < n; i++) {
			if(pnum != 0) {
				if((pnum+1) == a[i])
					sum += c[pnum-1];
			}
			int num = a[i];
			sum += b[num-1];
			pnum = num;
			//System.out.println(sum);
		}
		System.out.println(sum);
	}


}


Measured memory_bytes: 22996
#include<stdio.h>
#include<string.h>
int set(int[][8],int,int,int);
int check(int[][8],int*,int);
int main(){
  int n,i,j,q[8],tate,yoko;
  
int kinsi[8][8];
  for(i=0;i<8;i++)
    for(j=0;j<8;j++){
      kinsi[j][i]=0;
      q[i]=-1;
    }
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d %d",&tate,&yoko);
    set(kinsi,tate,yoko,1);
    q[tate]=yoko;
  }
  check(kinsi,q,0);


  
  
}
int check(int kinsi[][8],int *q,int now){
  int i,j;
  
  if(now==8) {
    for(i=0;i<8;i++){
      for(j=0;j<8;j++){
	if(q[i] == j)
	  printf("Q");
	else
	  printf(".");
      }
      printf("\n");
    }
    return 1;
  }
  if(q[now]!=-1){
    check(kinsi,q,now+1);
  }
  for(i=0;i<8;i++){
    if(kinsi[now][i]==0){
      set(kinsi,now,i,1);
      q[now]=i;
      check(kinsi,q,now+1);
      q[now]=-1;
      set(kinsi,now,i,-1);
      
      
    }

  }

  
  return 0;

}
int set(int bord[][8],int tate,int yoko,int dotti){
  int i,j,k,seihu[5]={1,1,-1,-1,1};
  for(i=0;i<8;i++)
    bord[tate][i]+=dotti;
  for(i=0;i<8;i++)
    bord[i][yoko]+=dotti;
  for(k=0;k<4;k++){
    i=tate;
    j=yoko;
    while(i>=0 &&i<8 && j>=0&&j<8){
      bord[i][j]+=dotti;
      i+=seihu[k];
      j+=seihu[k+1];
    }
  }
  return 1;

}



Measured memory_bytes: 2112
#include<iostream>

int n;

unsigned long long result=0;

long long a[200000],b[200000];

int main(){

    std::cin>>n;

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

    for(int i=0;i<n;i++){
        if(a[i]<=b[i]){
            result+=a[i];
            if(a[i+1]<=b[i]-a[i]){
                result+=a[i+1];
                a[i+1]=0;
            }
            else{
                a[i+1]-=(b[i]-a[i]);
                result+=(b[i]-a[i]);
            }
        }
        else result+=b[i];
    }

    std::cout<<result<<std::endl;

    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
int main(){
	int n;
	cin>>n;
	string s;
	cin>>s;
	vi co(26),cnt(10);
	rep(i,n)if(i%2==0)co[s[i]-'a']++;
	rep(i,26)cnt[co[i]]++;
	int out=0;
	bool h=false;
	loop(i,1,10)if(cnt[i]){
		out+=h;
		h=true;
		if(cnt[i]==1){
			out++;
			if(i!=1)out+=2;
		}else{
			out+=cnt[i]*2-1;
			if(i!=1)out+=4;
		}
	}
	cout<<out<<endl;
}

Measured memory_bytes: 3212
#!/usr/bin/env fsharpi

open System;

let ParseInt64N ( str : string ) =
    str.Split(' ')
    |> Array.map System.Int64.Parse

let ParseInt643 ( str : string ) =
    ParseInt64N str |> fun arr -> (arr.[0],arr.[1],arr.[2])

let ReadLinesN ( n : int ) =
    fun _ -> Console.ReadLine()
    |> Seq.initInfinite
    |> Seq.take n

let ReadLines =
    fun _ -> Console.ReadLine()
    |> Seq.initInfinite
    |> Seq.takeWhile ((<>) null)

let (a,b,x) = ParseInt643 <| Console.ReadLine()
let res = (b / x) - (a / x) + if (a % x) = 0L then 1L else 0L
Console.WriteLine res


Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
#define N 100009
#define ll long long

int dp[N], n, m;
vector<int>v[N];

void solve(int i)
{
    if(dp[i] != -1) return;
    int ans = 0;
    for(int x: v[i])
    {
        solve(x);
        ans = max(ans, dp[x] + 1);
    }
    dp[i] = ans;
}

int main()
{
    memset(dp, -1, sizeof(dp));
    cin >> n >> m;
    for(int i = 1; i <= m; i++)
    {
        int x, y;
        cin >> x >> y;
        v[x].push_back(y);
        //v[y].push_back(x);
    }
    for(int i = 1; i <= n; i++)
    {
        solve(i);
    }
    int ans = 0;
    for(int i = 1; i <= n; i++) ans = max(ans, dp[i]);
    cout << ans << endl;
}




Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  int N;
  cin >> N;
  vector<int> p(N);
  vector<bool> match(N, false);
  rep(i, N) {
    cin >> p[i];
    p[i]--;
    if (i == p[i]) {
      match[i] = true;
    }
  }

  int ans = 0;
  rep(i, N) {
    if (!match[i])
      continue;
    ans++;
    if ((i < N - 1) && match[i + 1]) {
      i++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
#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 ll long long
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define vul vector<ull>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi2d vector<vi >
#define vl2d vector<vl >
#define vpll vector<pll >

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rz resize
#define fr(i,n) for(i=0;i<(n);i++)
#define frr(i,n) for(i=(n-1);i>=0;i--)
#define fre(i,n) for(i=0;i<=(n);i++)
#define frre(i,n) for (i=(n);i>=0;i--)
#define frab(i,a,b) for(i=(a);i<(b);i++)
#define freab(i,a,b) for(i=(a);i<=(b);i++)
#define frrab(i,a,b) for(i=(b-1);i>=a;i--)
#define frreab(i,b,a) for(i=(b);i>=a;i--)

#define sz(a) int((a).size())
#define mset(a,b) (memset(a,b,sizeof(a)))
#define max3(a,b,c) (max((a),max((b),(c))))
#define min3(a,b,c) (min((c),min((a),(b))))
#define sumv(v) accumulate(all(v),ll(0))
#define productv(v) accumulate(all(v), ll(1), multiplies< ll >())
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
vector <ll> sprime;
vector<char> prime (1000000, true);
void sieve(ll n)
{
  //O(nloglogn) time
  sprime.pb(0);
  prime[0] = prime[1] = false;
  ll cnt = 0;
  for (ll i = 2; i <= n; ++i)
  {
    if (prime[i])
    {
      cnt++;
      sprime.pb(i);
      for (ll j = 2 * i; j <= n; j += i)
        prime[j] = false;
    }
  }
}
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll fastpowMOD(ll a, ll p, ll MOD) { if (p == 0) return 1; ll z = fastpowMOD(a, p / 2, MOD); z = (z * z) % MOD; if (p % 2) z = (z * a) % MOD; return z; }
ll fastpow(ll a, ll p) { if (p == 0) return 1; ll z = fastpow(a, p / 2); z = (z * z); if (p % 2) z = (z * a); return z; }
#define inf LLONG_MAX
#define minf LLONG_MIN
#define pi 3.14
#define ex 2.71
const int mod= 1e9+7;
//*********************************************///
const int N = 5e5+5;
ll i,j,k,p;

int m;
string s;

int count()
{
  int n=sz(s);
  int dp[n+1][m][2];
  mset(dp,0);
  dp[0][0][1]=1;
  fr(i,n)
    fr(j,m)
      fr(k,2)
      {
        fr(p,(k?int(s[i]-'0')+1:10))
        {
          int k1= (k && (p==int(s[i]-'0')));
          dp[i+1][(j+p)%m][k1]+=dp[i][j][k];
          dp[i+1][(j+p)%m][k1]%=mod;
        }
      }
  return ((dp[n][0][0]+dp[n][0][1])%mod);
}





void solve()
{
  cin>>s>>m;
  cout<<(count()-1+mod)%mod<<endl;
}

int main()
{
  fast;
  int z;
  z=1;
  //cin>>z;
  while(z--)
  {
    solve();
  }
  return 0;
}


Measured memory_bytes: 9088
#include<iostream>
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

int main(){
    ll A,B,K;
    cin>>A>>B>>K;
    if(A>=K){
        cout<<A-K<<" "<<B<<endl;
        return 0;
    }
    else{
        if(A+B>=K){
            cout<<0<<" "<<B+A-K<<endl;
            return 0;
        }
        else{
            cout<<0<<" "<<0<<endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
int main() {
  int l, i=0, a[2];
  while(cin>>l){
    a[i] = l;
    i++;
  }
  int X = a[0];
  int A = a[1];
  int ans;
  if (X < A) {
    ans = 0;
  } else {
    ans = 10;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int p, q, r, s, ans;
  scanf("%d %d %d", &p, &q, &r);
  s = (p>q) ? p : q;
  s = (s>r) ? s : r;
  ans = p+q+r-s;
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
const Int MOD = 1000000007;
Int dp[301][301][301];
int main() {
    int N, M; cin >> N >> M;
    dp[0][1][1] = 1;
    for (int i = 0; i < M; i++) {
        for (int j = 0; j <= N; j++) {
            for (int k = 0; k <= j; k++) {
                if (j + 1 <= N) dp[i+1][j+1][k] += dp[i][j][k] * (N - j);
                dp[i+1][j][k] += dp[i][j][k] * (j - k);
                dp[i+1][j][j] += dp[i][j][k] * k;
            }
        }
        for (int j = 0; j <= N; j++) {
            for (int k = 0; k <= j; k++) {
                dp[i+1][j][k] %= MOD;
            }
        }
    }
    cout << dp[M][N][N] << '\n';
    return 0;
}


Measured memory_bytes: 212608
#include<bits/stdc++.h>
using namespace std;
typedef		vector<int>				 vi;
typedef 	vector<vi>				vii;
typedef		pair<int,int>			pii;
typedef		unsigned long long		ull;
typedef		long long				ll ;
#define MOD (int)(1e9+7)
#define INF (int)(1<<29) 
#define fori(i,a,b)		for(int i=a ; i <= b ; i++) 			
#define ford(i,a,b)  	for(int i=a ; i >= b ; i-- ) 
#define rep(i,n)   		for(int i=0; i < n ; i++ ) 
#define DEBUG(x)		cout << '>' << #x << ':' << x << endl;


int main()
{
	ios_base::sync_with_stdio(0);	
	string a ;
	cin >> a ;
	cout << a[0] << a.length()-2 << a[a.length() - 1 ] << endl ; 

	return 0 ;
}



Measured memory_bytes: 256