akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[4] = {-1, 0, 1, 0};
ll dy[4] = {0, 1, 0, -1};

int main(){
    ll k, n;
    cin >> k >> n;
    ll a[n+1];
    for(ll i = 0; i < n; i++)
        cin >> a[i];
    a[n] = k+a[0];
    ll dis = 0;
    for(ll i = 0; i < n; i++){
        ll check = abs(a[i]-a[i+1]);
        dis = max(dis, check);
    }
    cout << k -dis << endl;
    return 0;
}


Measured memory_bytes: 1792
#!/usr/bin python3
# -*- coding: utf-8 -*-

from collections import Counter
from itertools import permutations

n, c = map(int, input().split())
d = [list(map(int,input().split())) for _ in range(c)]
ci = [[] for _ in range(3)]
for i in range(n):
    cl = list(map(int, input().split()))
    for j in range(3):
        ci[(i+j)%3].extend(cl[j::3])
for i in range(3):
    ci[i] = Counter(ci[i])

def iwa(cols):
    ret = 0
    for i in range(3):
        for x, v in ci[i].items():
            ret += v * d[x-1][cols[i]]
    return ret

L = list(permutations(range(c), 3))
ret = 500*500*1000
for cols in L:
    ret = min(ret, iwa(cols))
print(ret)


Measured memory_bytes: 11472
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=998244353;
ll dp[2000][2010];
int sum[2000];
const int MAX_P=2010;
ll extgcd(ll a, ll b, ll& x, ll&y){
    ll d=a;
    if(b!=0){
        d=extgcd(b, a%b, y, x);
        y-=(a/b)*x;
    }
    else {
        x=1; y=0;
    }
    return d;
}

ll mod_inverse(ll a, ll m){
    ll x,y;
    extgcd(a,m,x,y);
    return (m+x%m)%m;
}

//n!modp
ll fact[MAX_P];

//n!=a p＾eとした時のa modpを求める。O(log_p n)
ll mod_fact(ll n, ll p, ll& e){
    e=0;
    if(n==0) return 1;
    
    //pの倍数の部分を計算
    ll res=mod_fact(n/p,p,e);
    e+=n/p;
    
    //(p-1)!≡-1なので(p-1)!^(n/p)はn/pの偶奇だけで計算できる
    if(n/p%2!=0) return res*(p-fact[n%p])%p;
    return res*fact[n%p]%p;
}

//nCk modpを求める。O(log_p n)
ll mod_comb(ll n, ll k, ll p){
    if(n<0||k<0||n<k) return 0;
    ll e1, e2, e3;
    ll a1=mod_fact(n,p,e1), a2=mod_fact(k,p,e2), a3=mod_fact(n-k,p,e3);
    if(e1>e2+e3) return 0;
    return a1*mod_inverse(a2*a3%p,p)%p;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string S;
    cin>>S;
    int N=S.length();
    sum[0]=2-(S[0]-'0');
    rep(i,1,N){
        sum[i]=sum[i-1]+2-(S[i]-'0');
    }
    if(S[0]=='0'){
        dp[0][0]=0;
        dp[0][1]=1;
    }
    if(S[0]=='1'){
        dp[0][0]=1;
        dp[0][1]=1;
    }
    if(S[0]=='2'){
        dp[0][0]=1;
        dp[0][1]=0;
    }
    rep(i,1,N){
        rep(j,0,i+2){
            if(j==0){
                dp[i][j]=(dp[i-1][0]&&sum[i]<=i+1?1:0);
            }
            else{
                dp[i][j]=(sum[i]>j-1?dp[i-1][j-1]:0)+(sum[i]-j<=i+1?dp[i-1][j]:0);
                dp[i][j]%=MOD;
            }
        }
    }
    fact[1]=1;
    rep(i,2,MAX_P){
        fact[i]=fact[i-1]*i;
        fact[i]%=MOD;
    }
    ll ans=0;
    rep(i,0,min(sum[N-1]+1, N+1)){
        ans+=mod_comb(N, sum[N-1]-i, MOD)*dp[N-1][i]%MOD;
        ans%=MOD;
    }
    cout << ans<<"\n";
}

Measured memory_bytes: 30208
#include<bits/stdc++.h>
#define For(i,a,b) for(i=(a);i<=(b);++i)
#define Forward(i,a,b) for(i=(a);i>=(b);--i)
#define Rep(i,a,b) for(register int i=(a);i<=(b);++i)
#define Repe(i,a,b) for(register int i=(a);i>=(b);--i)
#define Chkmax(a,b) a=a>b?a:b
#define Chkmin(a,b) a=a<b?a:b
using namespace std;
template<typename T>inline void read(T &x)
{
	T s=0,f=1;static char c;
	for(c=getchar();!isdigit(c);c=getchar())if(c=='-')f=-1;
	for(;isdigit(c);c=getchar())s=s*10+(c^48);
	x=s*f;
}
const int MAXN=1e4+7;
static int n;
inline void init()
{
	read(n);
}
inline void solve()
{
	if(n==3)printf("2 5 63\n"),exit(0);
	if(n==4)printf("2 4 3 9\n"),exit(0);
	if(n&1)printf("30000 "),--n;
	printf("2 4 3 9 ");n-=4;
	static int x=4;
	n/=2;
	while(n)
	{
		printf("%d ",x<<1);
		++x;if(x%3==0)++x;
		printf("%d ",x<<1);
		++x;if(x%3==0)++x;
		--n;
		if(x>=14999)break;
	}
	x=5;
	while(n)
	{
		printf("%d ",x*3);
		x+=2;
		printf("%d ",x*3);
		x+=2;
		--n;
		if(x>=9998)break;
	}
	x=6;n*=2;
	while(n)printf("%d ",x),x+=6,--n;
		puts("");
}
int main()
{
	init();
	solve();
	return 0;
}


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

int main()
{
	const long long DEF = 1000000007;
	long long N, fac = 1;
	cin >> N;

	vector<int> primes;
	vector<int> cnts;
	for (int i = 2; i <= N; i++) {
		int val = i;
		for (int k = 0; k < primes.size(); k++) {
			int pri = primes[k];
			while (val % pri == 0) {
				cnts[k]++;
				val /= pri;
			}
		}
		if (val == i) {
			primes.push_back(val);
			cnts.push_back(1);
		}
	}

	long long  cnt = 1;
	for (int i : cnts) {
		cnt = (cnt * (i + 1)) % DEF;
	}

	cout << cnt << endl;

	return 0;
}



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

typedef long long ll;

using namespace std;

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

template<class T>
using vt = vector<T>;
template<class T>
using vvt = vector<vector<T>>;


int main(){
    int N,sum=0,min_n=10000000;
    cin >> N;
    int seiseki[N];
    rep(i,N){
        cin >> seiseki[i];
        if((seiseki[i]%10)!=0 && seiseki[i] < min_n) min_n = seiseki[i];
        sum += seiseki[i];
    } 
    if((sum%10)!=0) cout << sum << endl;
    else if((sum-min_n) > 0) cout << sum-min_n << endl;
    else cout << 0 << endl;
    return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(i=0;i<n;i++)
#define rep(i,a,n) for(i=a;i<=n;i++)
#define test(a) cout << "*" << a << endl
#define ll long long
int main(){
  ll x;
  int i,j;
  bool existBreak = false;
   
  cin >> x;
  
  for(i=1000;i>-1000;i--){
    if(existBreak)
      break;
    for(j=1000;j>-1000;j--){
      if(pow(i,5) - pow(j,5) ==x){
        cout << i << " " << j << endl;
        existBreak = true;
        break;
      }
    }
  }
  
  
 
  
}

Measured memory_bytes: 3972
// #include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>

using namespace std;
const int N = 100010;

char s[N];
int a[N];
int vis[N];


int main()
{
    while(scanf("%s", s) != EOF)
    {
        // scanf("%s", s);
        // printf("%s\n", s);
        int n = strlen(s);
        // printf("%d\n", n);
        for(int i=0; i < n; i++)
            a[i] = 1, vis[i] = 0;
        
        int maxcnt = 0;
        int lcnt = 0;
        int rcnt = 0;
        for(int i=0, j = 0; i<n; i++)
        {
            
            bool flag = false;
            if(s[i] == 'R') 
            {
                rcnt ++;
                a[i] = 0;
            }
            else if(s[i] == 'L')
            {
                flag = true;
                for(j=i; j<n; j++)
                {
                    // printf("i = %d, j = %d\n", i, j);
                    if(s[j] == 'L')
                    {
                        lcnt++;
                        a[j] = 0;
                    }
                    else if(s[j] == 'R')
                        break;
                    
                }
            }

            
            if(flag)
            {
                maxcnt = max(maxcnt, max(lcnt, rcnt));
                if((lcnt + rcnt) % 2 == 0)
                    a[i] = a[i-1] = (lcnt + rcnt) / 2;
                else if(lcnt > rcnt)
                {
                    a[i-1] = (lcnt + rcnt) / 2;
                    a[i] = (lcnt + rcnt) / 2 + 1;
                }
                else if(lcnt < rcnt)
                {
                    a[i-1] = (lcnt + rcnt) / 2 + 1;
                    a[i] = (lcnt + rcnt) / 2;
                }
                vis[i] = max(lcnt, rcnt);
                i = j - 1;
                lcnt = 0;
                rcnt = 0;
            }
               
            
        }

        for(int i=0; i<n; i++)
        {
            if(vis[i] != 0)
            {
                int t = maxcnt - vis[i];
                for(int j=0; j<t; j++)
                {
                    int temp = a[i];
                    a[i] = a[i-1];
                    a[i-1] = temp;
                }
            }
        }


        if(maxcnt % 2 == 1)
        {
            printf("%d", a[0]);
            for(int i=1; i<n; i++)
                printf(" %d", a[i]);
            printf("\n");
        }
        else
        {
            for(int i=0; i<n; i++)
            {
                if(a[i] != 0)
                {
                    int temp = a[i];
                    a[i] = a[i+1];
                    a[i+1] = temp;
                    i++;
                }
            }
            printf("%d", a[0]);
            for(int i=1; i<n; i++)
                printf(" %d", a[i]);
            printf("\n");
        }
        
    }


    return 0;
}

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

#define range 524289
#define mod 1000000007
#define eps 1e-9
#define PI 3.14159265358979323846
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define ALL(V) V.begin(), V.end()
#define _ <<" "<<

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector<vi> vvi;
typedef pair <int, int> ii;
typedef pair<int, pair<int,int> > iii;
typedef vector<ii> vii;
typedef vector<iii> viii;


int main(int argc, char const *argv[])
{
	// #ifndef ONLINE_JUDGE
 //    	freopen("input.txt", "r", stdin);
 //    	freopen("output.txt", "w", stdout);
	// #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,m,l;
    string a;
    cin>>a;
    n = a.size();
    int rl = 0;

    int rc = 1;
    int lc  = 0;
    int turns  = 0;
    char curr = 'R';
    int count =0;
    vi res(n, 0);
    int i = 1;
    int rstart = 0;
    int lstart = 0;
    while(i<n){
    	if(a[i]==curr){
    		if(curr=='R'){
    			rc++;
    		}
    		else{
    			lc++;
    		}
    	}
    	else{
    		if(a[i]=='L'){
    			lstart = i;
    			curr = 'L';
    			lc++;
    		}
    		else{
    			int lolr =  rc + rstart -1;
    			int loll = lstart;
    			int trns = max(lc, rc)-1;
    			turns = max(trns, turns);
    			int sum = lc+rc;
    			if(sum%2){
    				if(lc>rc){
    					res[loll] = sum/2 + sum%2;
    					res[lolr] = sum/2;
    				}
    				else{
    					res[lolr] = sum/2 + sum%2;
    					res[loll] = sum/2;
    				}
    			}
    			else{
    				res[loll] = sum/2;
    				res[lolr] = sum/2;
    			}

    			if(trns==0||trns%2==1){
    				swap(res[loll], res[lolr]);
    			}
    			rstart  = i;
    			lc = 0;
    			rc = 1;
    			curr = 'R';
    		}

    	}
    	i++;

    }

    int lollr =  rc + rstart -1;
    			int lolll = lstart;
    			int trnss = max(lc, rc)-1;
    			turns = max(trnss, turns);
    			int sums = lc+rc;
    			if(sums%2){
    				if(lc>rc){
    					res[lolll] = sums/2 + sums%2;
    					res[lollr] = sums/2;
    				}
    				else{
    					res[lollr] = sums/2 + sums%2;
    					res[lolll] = sums/2;
    				}
    			}
    			else{
    				res[lolll] = sums/2;
    				res[lollr] = sums/2;
    			}
    			if(trnss==0||trnss%2==1){
    				swap(res[lolll], res[lollr]);
    			}


    for (i = 0; i < n; ++i)
    {
    	cout<<res[i]<<" ";
    }
    return 0;
}


Measured memory_bytes: 1104
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(itr,v) for(auto &(itr):(v))
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a*b/gcd(a,b);}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;



// 操作を逆から見ると、最終状態の1は「もともと1だった」か「101に操作をして出来た」かどっちかである
// すると最終状態での1個の1に対応するのは初期状態における
// a) 1
// b) 111...11101 (左側で1がk個連続するならk回操作ができる)
// c) 10111...111 (同様)
// bとcをうまく選んでsを分割することで和を最大化したい

int n, l[500500], r[500500], dp[500500];
string s;

signed main() {
	cin >> n >> s;
	int t = -1;
	rep(i,n) {
		l[i] = t;
		if (s[i]=='0') t = i;
	}
	t = n;
	for (int i=n-1; i>=0; i--) {
		r[i] = t;
		if (s[i]=='0') t = i;
	}
	rep(i,n) {
		chmax(dp[i+1], dp[i]);
		if (s[i]=='0') continue;
		// 10111
		if (1<=l[i] && s[l[i]-1]=='1') chmax(dp[i+1], dp[l[i]-1] + i-l[i]);
		// 11101
		if (r[i]<n-1 && s[r[i]+1]=='1') chmax(dp[r[i]+2], dp[i] + r[i]-i);
	}
	cout << dp[n] << endl;
}

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

typedef long int lint;
typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<int, string> pis;
typedef pair<long, long> pll;

#define EACH(i, c) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i, s, e) for (int i = (s); i < (int)(e); ++i)
#define REP(i, n) FOR(i, 0, n)
#define endl "\n"

const int INF = 1000000;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

template<typename T>
void print(const std::vector<T>& v, char sep=' ') {
  for (int i = 0; i < (int)v.size(); i++) {
    if (i != 0) cout << sep;
    cout << v[i];
  }
  cout << endl;
}

int prime[INF];

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

  int n;

  REP(i, INF) prime[i] = 1;

  prime[0] = prime[1] = 0;

  for (int i =  2; i * i <= INF; i++){
    if (prime[i]){
      for (int j = 2; i * j <= INF; j++){
        prime[i * j] = 0;
      }
    }
  }

  while (cin >> n){
    int ct = 0;
    for (int i = 2; i <= n; i++){
      if (prime[i]) ct++;
    }
    cout << ct << endl;
  }
}

Measured memory_bytes: 5100
/**

つのデータがどれだけ似ているかを、それらの距離で測る手法は、クラスタリングや分類など、様々なところで使われています。
ここでは、２つの n  次元ベクトル x={x 1 ,x 2 ,...,x n }  と y={y 1 ,y 2 ,...,y n }  の距離を計算してみましょう。

このようなデータの距離を測る指標のひとつとして、次のミンコフスキー距離が知られています。

D xy =(? i=1 n |x i −y i | p ) 1p

p=1  のとき

D xy =|x 1 −y 1 |+|x 2 −y 2 |+...+|x n −y n |

となり、これはマンハッタン距離とよばれます。

p=2  のとき

D xy =  √(|x 1 −y 1 |) 2 +(|x 2 −y 2 |) 2 +...+(|x n −y n |) 2

となり、これは一般的に使われるユークリッド距離になります。

p=∞  のとき


D xy =max n i=1 (|x i −y i |)


となり、これはチェビシェフ距離と呼ばれます。

２つの n  次元ベクトルが与えられるので、p  がそれぞれ 1、2、3、∞  のミンコフスキー距離を求めるプログラムを作成してください。


 */

//スキャナつかうため

import java.util.Scanner;

public class Main {
	// プログラムのエントリポイント
	public static void main(String[] args) {
		// 入力ストリームの生成

		Scanner sc = new Scanner(System.in);
		// 6桁の数字を受け取る配列diceを作る
		int[] dice = new int[6];
		// 6個入力された数字を受け取る
		for (int i = 0; i < 6; i++) {
			dice[i] = sc.nextInt();
		}
		// 命令の文字列を受け取る
		String mei = sc.next();
		// 受け取った文字列をcharの配列に入れていく
		char[] Roll = mei.toCharArray();
		for (int i = 0; i < mei.length(); i++) {
			int irekae = 0;
			if (Roll[i] == 'S') {
				irekae = dice[0];
				dice[0] = dice[4];
				dice[4] = dice[5];
				dice[5] = dice[1];
				dice[1] = irekae;

			} else if (Roll[i] == 'N') {
				irekae = dice[0];
				dice[0] = dice[1];
				dice[1] = dice[5];
				dice[5] = dice[4];
				dice[4] = irekae;

			} else if (Roll[i] == 'W') {
				irekae = dice[0];
				dice[0] = dice[2];
				dice[2] = dice[5];
				dice[5] = dice[3];
				dice[3] = irekae;

			} else if (Roll[i] == 'E') {
				irekae = dice[0];
				dice[0] = dice[3];
				dice[3] = dice[5];
				dice[5] = dice[2];
				dice[2] = irekae;

			}

		}
		System.out.println(dice[0]);
	}
}

Measured memory_bytes: 18912
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int A =sc.nextInt();
    int B =A+sc.nextInt();
    if(B%2==1){System.out.println("IMPOSSIBLE");}
    else{System.out.println(B/2);}
  }
}

Measured memory_bytes: 23636
#include <iostream>

using namespace std;
int W,H;
int N;

int main(){
  cin >> W >> H;
  cin >> N;
  int Y1,X1;//outer
  int Y2,X2;//inner
  Y1 = H - 1;
  X1 = W - 1;
  
  Y2 = H - 2;
  X2 = W - 1;

  int res = 0;
  for (int i = 0; i < N; i++){
    int tmp;
    cin >> tmp;
    if (tmp){//inner
      if (Y2 == H - 2 and X2 >= 2){//upper
	X2--;
	if (X1 == X2 and abs(Y2 - Y1) == 1){
	  res++;
	}
	if (abs(X1 - X2) == 1 and Y2 == Y1){
	  res++;
	}
	
      }else if(Y2 >= 2 and X2 == 1){//right
	Y2--;
	if (abs(X1 - X2) == 1 and Y2 == Y1){
	  res++;
	}
	if (X1 == X2 and abs(Y2 - Y1) == 1){
	  res++;
	}

      }else if(Y2 == 1 and X2 >= 1){//lower
	X2++;
	if (X1 == X2 and abs(Y2 - Y1) == 1){
	  res++;
	}

	  
      }
    }else{//outer
      
      if (Y1 == H - 1 and X1 >= 1){//upper
	X1--;

	if (X1 == X2 and abs(Y2 - Y1) == 1){
	  res++;
	}
	if (abs(X1 - X2) == 1 and Y2 == Y1){
	  res++;
	}
	
      }else if(Y1 >= 1 and X1 == 0){//right
	Y1--;
	if (abs(X1 - X2) == 1 and Y2 == Y1){
	  res++;
	}
	if (X1 == X2 and abs(Y2 - Y1) == 1){
	  res++;
	}
      }else if(Y1 == 0 and X1 >= 0){
	X1++;
	if (X1 == X2 and abs(Y2 - Y1) == 1){
	  res++;
	}	
      }
      
      
    }
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3116
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

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

  SORT(a); reverse(a.begin() , a.end());
  vector<ll> b; b.pb(a[0]);
  repn(i,N - 1){
    b.pb(a[i]); b.pb(a[i]);
  }

  ll ans = 0;
  rep(i,N - 1){
    ans += b[i];
  }

  cout << ans << endl;
}


Measured memory_bytes: 9024
N = gets.to_i
Ss, Ts, Us, Vs = readlines.map{_1.split.map(&:to_i)}

xs = N.times.map do |i|
  N.times.map do |j|
    case [Ss[i], Ts[j]]
    when [1, 1]; Us[i] & Vs[j]
    when [0, 1]; Us[i]
    when [1, 0]; Vs[j]
    when [0, 0]; Us[i] | Vs[j]
    end
  end
end

def go(x, s, t, u, v)
  a1 = Array.new(N, -1)
  a2 = Array.new(N){Array.new(N, -1)}
  (N - 2).downto(0).each do |i|
    N.times{|j| a2[i][j] = a2[i + 1][j] & x[i + 1][j]}
  end
  N.times do |i|
    a = x[i].inject(~u[i]){|r, v| r | v}
    N.times do |j|
      if s[i] == 1 && t[j] == 0
        x[i][j] |= ~(a1[j] & a2[i][j] | a)
        a |= x[i][j]
      end
      a1[j] &= x[i][j]
    end
  end
  (puts -1; exit) unless N.times.map{|i| x[i].inject(s[i] == 1 ? :| : :&)} == u
  x
end

xs = go(xs, Ss, Ts, Us, Vs)
xs = go(xs.transpose, Ts, Ss, Vs, Us).transpose
xs.each{puts _1.join(' ')}

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

int main(){
  int a,b,c,max,d,e;
  cin >> a >> b >> c;
  max = a;
  if(max < b){
    max = b;
  }
  if(max < c){
    max = c;
  }
  
  if(max == a){
    d = b;
    e = c;
  }
  if(max == b){
    d = a;
    e = c;
  }
  if(max == c){
    d = a;
    e = b;
  }
  cout << max*10+d+e << endl;
}
  

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
struct Dice{
  int s[6];
  void roll(char c){
    int b;
    if(c=='E'){
      b=s[0];
      s[0]=s[3];
      s[3]=s[5];
      s[5]=s[2];
      s[2]=b;
    }
    if(c=='W'){
      b=s[0];
      s[0]=s[2];
      s[2]=s[5];
      s[5]=s[3];
      s[3]=b;
    }
    if(c=='N'){
      b=s[0];
      s[0]=s[1];
      s[1]=s[5];
      s[5]=s[4];
      s[4]=b;
    }
    if(c=='S'){
      b=s[0];
      s[0]=s[4];
      s[4]=s[5];
      s[5]=s[1];
      s[1]=b;
    }
    if(c=='R'){
      b=s[1];
      s[1]=s[2];
      s[2]=s[4];
      s[4]=s[3];
      s[3]=b;
    }    
  }
  int top() {
    return s[0];
  }
  int right(){
    return s[2];
  }
  int left(){
    return s[3];
  }
  int front(){
    return s[1];
  }
};
bool same(Dice a,Dice b){
  for(int i=0;i<6;i++) if(a.s[i]!=b.s[i]) return false;
  return true;
}
int main(){
  Dice d[2];
  for(int j=0;j<2;j++) 
    for(int i=0;i<6;i++)
      cin >> d[j].s[i];
  bool f=false;
  
  
  for(int i=0;i<4;i++){
    d[1].roll('R');
    for(int j=0;j<4;j++){
      d[1].roll('N');
      if(same(d[0],d[1])) f=true;
    }
  }
  d[1].roll('E');
  for(int j=0;j<4;j++){
    d[1].roll('N');
    if(same(d[0],d[1])) f=true;
  }

  d[1].roll('W');
  d[1].roll('W');
  for(int j=0;j<4;j++){
    d[1].roll('N');
    if(same(d[0],d[1])) f=true;
  }
  
  cout << (f?"Yes":"No") << endl;
  return 0;
}

Measured memory_bytes: 1156
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdio>
using namespace std;
bool deb = 0 , deb2 = 1;
char str[14],sor[14];
int bod[10];
int head_check(void);
int body_check(int x);
int main(){
    while(cin>>str){
        bool zero=0;
        int flg[14]={0};

        for(int i=0;i<13;i++){
            flg[str[i]-'0']++;
        }
        for(int i=1;i<=9;i++){
            if(flg[i]<4){
                str[13]=i+'0';
                for(int j=0;j<14;j++){
                    sor[j]=str[j];
                }
                sort(sor,sor+14);
                if(deb)cout<<sor<<endl;
                if(head_check()){
                    zero ? cout<<" "<<i : cout<<i;
                    zero=1;
                }
            }
        }
        if(!zero)cout<<0;
        cout<<endl;

        for(int q=0;q<14;q++){
            str[q]=0,sor[q]=0;
        }
        for(int q=0;q<10;q++){
            bod[q]=0;
        }
    }
}
int head_check(void){
    for(int i=0;i<13;i++){
        if(sor[i]==sor[i+1]){
            for(int j=0,k=0;j<14;j++){
                if(j!=i&&j!=i+1){
                    bod[sor[j]-'0']++;
                }

            }
            if(body_check(1))return 1;
        }
        for(int j=1;j<10;j++){
            bod[j]=0;
        }
    }
    return 0;
}
int body_check(int x){
    if(deb){
        cout<<"x="<<x<<" ";
        for(int q=1;q<10;q++)cout<<bod[q];
        cout<<endl;
    }
    if(x==5)return 1;
    for(int i=1;i<10;i++){

        if(bod[i]>=3){
            bod[i]-=3;
            if(body_check(x+1))return 1;
            bod[i]+=3;
        }
        if(i<=7&&bod[i]>0&&bod[i+1]>0&&bod[i+2]>0){
            bod[i]--,bod[i+1]--,bod[i+2]--;
            if(body_check(x+1))return 1;
            bod[i]++,bod[i+1]++,bod[i+2]++;
        }
    }
    return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define EPS (1e-15)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define bet(x, a, b) (a) <= (x) && (x) < (b)
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	int N, A;
	bool ans = true;

	cin >> N;
	rep(i, N) {
		cin >> A;
		if (A % 2 == 0) {
			if (A % 3 != 0 && A % 5 != 0) ans = false;
		}
	}

	cout << (ans ? "APPROVED" : "DENIED") << endl;

	return 0;
}


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

#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
ll n;
cin>>n;
vector<ll>a(n);
rep(i,n)cin>>a[i];
sort(a.begin(),a.end());

int res=0;
vector<int> used(3*(int)1e6,false);
map<int,int> same;
vector<int> valid;
rep(i,n){
    same[a[i]]++;
    if(used[a[i]])continue;
    valid.pb(a[i]);
    int num=a[n-1]/a[i];
    reps(j,num+2,1){
        used[a[i]*j]=true;
    }
    res++;
}
for(auto v:valid){
    if(same[v]>=2)res--;
}
cout<<res<<endl;
return 0;
}

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

#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define REPR(i, a, b) for (int i = (a); i >= (b); i--)
#define ALL(container) (container).begin(), (container).end()

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;

const int INF = 1e9;
const int MOD = 1000000007;

int main()
{
  int a;
  string s;

  cin >> a >> s;

  if (a >= 3200)
    cout << s << endl;
  else
    cout << "red" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(){
    int N;
    cin >> N;
    ll a[200000], sum = 0;
    for(int i=0;i<N;i++){
        cin >> a[i];
        sum += a[i];
    }
    
    ll snuke = 0, arai, min = LLONG_MAX;
    for(int i=0;i<N-1;i++){
        snuke += a[i];
        arai = sum - snuke;
        if(abs(snuke - arai) < min)
            min = abs(snuke - arai);
    }

    cout << min << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+5;
ll dp[N];
int n;
string s;

bool check(int i){
	if( i > n ){ return 0; }
	if( i == n ){ return 1; }
	if( dp[i] != -1 ){ return dp[i]; }
	dp[i] = 0;
	if( i + 5 <= n and (s.substr(i,5) == "dream" or s.substr(i,5) == "erase") ){
		dp[i] |= check(i+5);
	}
	if( i + 6 <= n and s.substr(i,6) == "eraser" ){
		dp[i] |= check(i+6);
	}
	if( i + 7 <= n and s.substr(i,7) == "dreamer" ){
		dp[i] |= check(i+7);
	}
	return dp[i];
}

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

	cin>>s;
	n = s.size();
	memset(dp,-1,sizeof(dp));
	check(0) ? cout<<"YES\n" : cout<<"NO\n";

	return 0;
}


Measured memory_bytes: 2896
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define MIN(a,b) ((a) <= (b) ? (a) : (b))
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort( ALL(v) )

using namespace std;
using ll = long long;
using P = pair<int,int>;

int main()
{

   string s;  cin>>s;
   if(s[0]=='A' && s[1] == 'A' && s[2]== 'A')
    cout<<"No"<<endl;
   else if(s[0]=='B' && s[1] == 'B' && s[2]== 'B')
    cout<<"No"<<endl;
    else
    cout<<"Yes"<<endl;

    return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var K int
	fmt.Scan(&K)

	qs := make([]int, 0)
	qs = append(qs, []int{1, 2, 3, 4, 5, 6, 7, 8, 9}...)
	count := 0
	for len(qs) > 0 {
		q := qs[0]
		qs = qs[1:]
		count++
		if count == K {
			fmt.Println(q)
			return
		}
		last := q % 10
		if last != 0 {
			qs = append(qs, 10*q+last-1)
		}
		qs = append(qs, 10*q+last)
		if last != 9 {
			qs = append(qs, 10*q+last+1)
		}
	}
}


Measured memory_bytes: 7420
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  string L="";
  string R="";
  int Q;
  int T;
  int F;
  char C;
  int n=1;
  cin >> S >> Q;
  for(int i=0;i<Q;i++){
    cin >> T;
    if(T==1){
      n*=-1;
    }
    if(T==2){
      cin >> F >>C;
      if((F==1 and n==1) or (F==2 and n==-1)){
        L.push_back(C);
      }
      else{
        R.push_back(C);
      }
    }
  }
  reverse(L.begin(),L.end());
  S=L+S+R;
  if(n==-1){
    reverse(S.begin(),S.end());
  }
  cout << S <<endl;
}

Measured memory_bytes: 1348
#include<stdio.h>
using namespace std;

double r = 0.0;
double a = 0.0, b = 0.0;


int main() {

	scanf("%lf", &r);
	//面積
	a = r * r * 3.141592653589;
	//円周
	b = r * 2 * 3.141592653589;

	printf("%f %f\n",a,b);

		return 0;
}




Measured memory_bytes: 2628
#include<bits/stdc++.h>
using namespace std;
#define int long long

#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif

signed main(){

  int n; cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  reverse(a.begin(),a.end());

  vector<int> dp(n,1 << 30); //長さをiとしたときの末尾の最小値
  for(int i = 0; i < n; i++){
    int j = lower_bound(dp.begin(),dp.end(),a[i]+1) - dp.begin();
    dp[j] = a[i];
  }
  cout << lower_bound(dp.begin(),dp.end(),1 << 30) - dp.begin() << endl;

  return 0;
}


Measured memory_bytes: 1792
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	x := make([]int, m)
	for i := range x {
		sc.Scan()
		x[i], _ = strconv.Atoi(sc.Text())
	}

	sort.Ints(x)
	d := make([]int, m-1)
	for i := range d {
		d[i] = x[i+1] - x[i]
	}
	sort.Ints(d)
	sum := 0
	for i := 0; i < n-1; i++ {
		if v := m - 2 - i; v < 0 {
			break
		} else {
			sum += d[v]
		}
	}
	fmt.Println(x[m-1] - x[0] - sum)
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define EB emplace_back

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;

const int INF = 1e9 + 7;

int main()
{
	IO_OP;
	
	int n, l, s = 0,mn = INF, d;
	cin >> n >> l;
	for(int i=0;i<n;i++) {
		int t = l + i;
		if(abs(t) < mn) {
			mn = abs(t);
			d = t;
		}
		s += t;
	}
	cout << s - d << endl;
	
}



Measured memory_bytes: 256
using System;
class AOJ0507
{
    static void Main()
    {
        while (true)
        {
            int input = int.Parse(Console.ReadLine());
            if (input == 0) break;
            for (int i = input; i > 0; i--)
            {
                sub(i.ToString(), input - i, i);
            }
        }
    }
    static void sub(string front, int rest, int max){
        if(rest==0){
            Console.WriteLine(front);
        }
        for(int i=max>rest?rest:max;i>0;i--){
            sub(front + " " + i.ToString(), rest - i, i);
        }
    }
}

Measured memory_bytes: 5784
#include<iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <bitset>
#include <stack>
#include <queue>
#include <fstream>
#include <functional>

using namespace std;
using ll = long long;

#define all(x) (x).begin(),(x).end()
#define PRI(n) cout << n << " "<<endl;
#define PRI2(n, m) cout << n << " " << m << " "<<endl;

#define REP(i, n)  for(int i = 0; i < (int)n; ++i)
#define FOR(i, t, n)  for(int i = t; i <= (int)n; ++i)

const char alphabet[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
                           's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
const ll MOD = 1e9 + 7;

struct edge;
struct UnionFind;

bool isPrime(ll x);

ll GCD(ll a, ll b);

ll LCM(ll a, ll b);

ll nCr(int n, int r);


struct UnionFind {
    vector<int> par;
    vector<int> rank;

    UnionFind(int N) {
        for (int i = 0; i < N; ++i) {
            par.push_back(i);
            rank.push_back(0);
        }
    }

    int find(int x) {
        if (par[x] == x)return x;
        else return par[x] = find(par[x]);
    }

    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y)return;
        if (rank[x] < rank[y])par[x] = y;
        else {
            par[y] = x;
            if (rank[x] == rank[y])rank[x]++;
        }
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }
};

int M, N;
bool W[3010];
bool S[3010];

int main() {
    cin >> N;
    vector<ll> A(N);
    vector<ll> B(N);
    vector<ll> C(N);
    REP(i, N)cin >> A[i];
    REP(i, N)cin >> B[i];
    REP(i, N)cin >> C[i];
    sort(all(A));
    sort(all(B));
    sort(all(C));
    ll ans = 0;
    REP(i, N) {
        ll a = lower_bound(all(A), B[i]) - A.begin();
        ll c = C.end() - upper_bound(all(C), B[i]);
        ans += a * c;
    }
    PRI(ans)
    return 0;
}

struct edge {
    int to, cost;
    bool flag = false;
};

bool isPrime(ll x) {
    if (x == 0)return 0;
    if (x == 1)return 0;
    if (x == 2)return 1;
    if (x % 2 == 0)return 0;
    FOR(i, 3, x - 1) {
        if (x % i == 0)return 0;
    }
    return 1;
}

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

ll LCM(ll a, ll b) {
    ll gcd = GCD(a, b);
    return a / gcd * b;
}

ll nCr(int n, int r) {
    vector<ll> C(r + 1);
    C[0] = 1;
    FOR(i, 1, n) for (int j = min(i, r); j < 1; --j)C[j] = (C[j] + C[j - 1]) % MOD;
    return C[r];
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
#include<vector>
#include<string>
#define rep(i,a,b) for(long long int i=(a);i<(b);i++)
#define se(a) a.begin(),a.end()
#define ll unsigned long long int
#define mll map<ll,ll>
#define pll pair<ll, ll>
#define pii pair<int,int>
#define pb push_back
#define mk make_pair
#define F first
#define S second
#define mod 1000000007
#define maxn 100005
#define inf 1e18
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
int main()
{
	boost;
	ll n;
	cin>>n;
	long double a[n];
	rep(i,0,n)
	cin>>a[i];
	long double dp[n+1][n+1];
	memset(dp,0.0,sizeof(dp));
	dp[0][0]=1.0;
	rep(i,1,n+1)
	{
		rep(j,0,i+1)
		{
			if(j==0)
			dp[i][j]=dp[i-1][j]*(1.0-a[i-1]);
			else
			dp[i][j]=dp[i-1][j]*(1.0-a[i-1])+dp[i-1][j-1]*a[i-1];
		}
	}
	long double ans=0.0;
	for(int i=(n+1)/2;i<=n;i++)
	ans+=dp[n][i];
	cout<<fixed<<setprecision(12)<<ans<<endl;
}

Measured memory_bytes: 140928
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        double n = sc.nextDouble();
        double ans;
        if (n % 2 == 0) {
            ans = 0.5;
        } else {
            ans = (n - ((n - 1) / 2)) / n;
        }
        System.out.println(ans);
        sc.close();
    }
}

Measured memory_bytes: 25172
n,m = map(int,input().split())
coins = sorted(list(map(int,input().split())),reverse=True)

dp = [float("inf")]*50001

dp[0] = 0

for  i in range(50001):
    for coin in coins:
        if i+coin > 50000:
            continue
        
        else:
            dp[i+coin] = min(dp[i+coin], dp[i]+1)

print(dp[n])


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

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<vector<vector<bool>>> dp(n+1,vector<vector<bool>>(4,vector<bool>(1000)));
  dp[0][0][0] = 1;
  rep(i,n){
    rep(j,4){
      rep(k,1000){
        if(dp[i][j][k]){
          dp[i+1][j][k] = 1;
          if(j < 3){
          	dp[i+1][j+1][10*k+s[i]-'0'] = 1;
          }
        }
      }
    }
  }
  int ans = 0;
  rep(i,1000) if(dp[n][3][i]) ans ++;
  cout << ans << endl;
}


Measured memory_bytes: 25968
#include <iostream>
#include <vector>
#include <cmath>


using namespace std;






int main() {
  // 入力
  long long n;
  vector<long long> C(5, 0);

  cin >> n;
  for (int i = 0; i < 5; ++i) {
    cin >> C[i];
  }

  long long min_c = C[0];
  for (int i = 1; i < 5; ++i) {
    min_c = min(min_c, C[i]);
  }

  //
  long long ans = n / min_c;
  if(n % min_c > 0) ans ++;
  cout << ans+4 << endl;

  return 0;
}

Measured memory_bytes: 256
N = int(input())
string = input()
 
result = string.count('R')*string.count('G')*string.count('B')
 
for i in range(N-2):
  for j in range(i+1, N-1):
    k = 2*j-i
    if k>=N:
      break
    if string[i] != string[j] and string[j] != string[k] and string[i] != string[k]:
      result -= 1
print(result)

Measured memory_bytes: 9172
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <utility>
using namespace std;

long long X, Y;

int main(){
	cin >> X >> Y;
	if(X % Y == 0){
		cout << "-1" << endl;
		return 0;
	} else {
		cout << X * (Y-1) << endl;
		return 0;
	}
}




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

using namespace std;

typedef long long ll;
int main()
{
	ll n,m,k;
	cin >> n >> m >> k;
	ll a[n],b[m], pref[n+1] = {0}, ano[m+1] = {0};
	for(ll &i : a) cin >> i;
	for(ll &i : b) cin >> i;
	for(ll i = 0; i < n; i++) pref[i+1] = pref[i]+a[i];
	for(ll i = 0; i < m; i++) ano[i+1] = ano[i]+b[i];
	ll ans = 0;
	for(ll i = 0; i <= n; i++){
		if(k < pref[i]) continue;
		ll left = k-pref[i];
		ll l = 1, r = m;
		ll cnt = 0;
		while(l <= r){
			ll mid = l+(r-l)/2;
			if(left >= ano[mid]){
				cnt = mid;
				l = mid+1;
			}
			else r = mid-1;
		}
		ans = max(ans, cnt+i);
	}
	cout << ans;
}


Measured memory_bytes: 9848
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include<iomanip>

using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
const int inf = 1000000;

int main(int argc, const char * argv[]) {
  ll N, K;
  cin >> N >> K;
  vector<ll> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  
  ll len = 0;
  for (ll b = 1; b <= K; b*=2) {
    len++;
  }
  
  ll X = 0;
  for (ll b = len - 1; b >= 0; b--) {
    ll nzero = 0, none = 0;
    for (int i = 0; i < N; i++) {
      if (((A[i]>>b)&1) == 1){
        none++;
      } else {
        nzero++;
      }
    }
    if (nzero > none && (X | (1LL << b)) <= K) {
      X |= 1LL << b;
    }
  }
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    ans += A[i] ^ X;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<cmath>
#include<set>
#include<queue>
#include <iomanip>
using namespace std;

int main()
{
	int n;
	long long int ans=0;
	cin>>n;
	vector<string> s(n);
	for (int i = 0; i < n; i++) {
		cin>>s[i];
		sort(s[i].begin(),s[i].end());
	}
	sort(s.begin(),s.end());
	long long int temp=1;
	for (int i = 0; i < n-1; i++) {
		if(s[i]==s[i+1]){
			temp++;
			if (i==n-2) {
				ans+=temp*(temp-1)/2;
			}
		}else{
			ans+=temp*(temp-1)/2;
			temp=1;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 7296
#include<stdio.h>

int main(void){
    int h1,h2,m1,m2,k;
    scanf("%d%d%d%d%d",&h1,&m1,&h2,&m2,&k);
    printf("%d",(60 * (h2-h1) - m1 + m2) - k);
}

Measured memory_bytes: 1724
#include<bits/stdc++.h>
using namespace std;
const int maxn = 5e5+5;
int n, m;
struct Tree {
    int ls, rs, val; 
}tre[maxn*80];
int idx = 0, root[maxn];
int build(int l, int r) {
    int nod = ++idx;
    tre[nod].val = 0;
    if (l == r) return nod;
    int mid = (l + r) >> 1;
    tre[nod].ls = build(l, mid);
    tre[nod].rs = build(mid+1, r);
    return nod;
}

int update(int pre, int l, int r, int pos, int v) {
    int nod = ++idx;
    tre[nod] = tre[pre]; tre[nod].val += v;
    if (l == r) return nod;
    int mid = (l + r) >> 1;
    if (pos <= mid) tre[nod].ls = update(tre[pre].ls, l, mid, pos, v);
    else tre[nod].rs = update(tre[pre].rs, mid+1, r, pos, v);
    return nod;
}

int query(int id, int l, int r, int pos) {
    if (l == r) return tre[id].val;
    int mid = (l + r) >> 1;
    if (pos <= mid) {
        return tre[tre[id].rs].val + query(tre[id].ls, l, mid, pos);
    }
    else return query(tre[id].rs, mid+1, r, pos);
}

int a[maxn], vis[maxn];
void solve() {
    scanf("%d%d", &n,&m);
    for (int i = 1 ; i <= n ; i ++) {
        scanf("%d", a+i);
    }
    root[0] = build(1, n);    
    for (int i = 1 ; i <= n ; i ++) {
        if (!vis[a[i]])
            root[i] = update(root[i-1], 1, n, i, 1);
        else {
            int t = update(root[i-1], 1, n, vis[a[i]], -1);
            root[i] = update(t, 1, n, i, 1);
        }
        vis[a[i]] = i;
    }
    while (m--) {
        int l, r; scanf("%d%d", &l, &r);
        int tmp = query(root[r], 1, n, l);
        printf("%d\n", tmp);
    }
}

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


Measured memory_bytes: 252764
#include <cstdio>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main(){
  int n, h[20];
  scanf("%d", &n);
  for(int i=0; i<n; i++) scanf("%d", &h[i]);
  
  int result = 1;
  for(int i=1; i<n; i++){
    int flag = 1;
    for(int j=0; j<i; j++){
    	if(h[j] > h[i]) {
          flag = 0;
          break;
        }
    }
    result += flag;
  }
  
  printf("%d\n", result);
  return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
b=[]
c=0

for i in range(n):
	a=list(map(int,input().split()))
	del a[0]
	b+=a

for j in range(1,31):
	d=b.count(j)
	if d==n:
		c+=1
print(c)

Measured memory_bytes: 2940
#include<stdio.h>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iterator>
#include <list>
#include <map>     
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <iomanip>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define loop(a,t) for(int a=0;a<t;a++) 
#define forever while(true)
#define Sort(a) sort(a.begin(),a.end())
#define Reverse(a) reverse(a.begin(),a.end())

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

	forever{
		int a, b;
	
		int n;
		cin >> a >> b;
		if (a == 0 && b == 0) { break; }
		bool out[16][16];
		int dp[16][16];
		loop(i, 16) {
			loop(j, 16) {
				out[i][j] = false;
				dp[i][j] = 0;
			}
		}
		cin >> n;
		loop(i, n) {
			int p, q;
			cin >> p >> q;
			out[p - 1][q - 1] = true;
		}

		dp[0][0] = 1;
		loop(i, a) {
			loop(j, b) {
				if (!out[i][j])
				{
					if (i != 0) { dp[i][j] += dp[i - 1][j]; }
					if (j != 0) { dp[i][j] += dp[i][j - 1]; }
				}
			}
		}
		cout << dp[a - 1][b - 1] << endl;
	}
	return 0;
}


Measured memory_bytes: 3016
#include <iostream>
#include <string>
#include <queue>
#include <utility>
#include <algorithm>
#include <numeric>
#include <set>
#include <climits>
#include <map>

using namespace std;

int c[3][3];
int a[3];
int b[3];
int main(){
  for(int i = 0; i < 3; i++){
    for(int j = 0; j < 3; j++){
      cin >> c[i][j];
    }
  }
  for(a[0] = 0; a[0] <= 100; a[0]++){
    for(a[1] = 0; a[1] <= 100; a[1] ++){
      for(a[2] = 0; a[2] <= 100; a[2] ++){
        b[0] = c[0][0] - a[0];
        b[1] = c[0][1] - a[0];
        b[2] = c[0][2] - a[0];
        bool valid = true;
        for(int i = 0; i < 3; i++){
          for(int j = 0; j < 3; j++){
            if(c[i][j] != a[i] + b[j]){
              valid = false;
              break;
            }
          }
        }
        if(valid){
          cout << "Yes" << endl;
          return 0;
        }
      }
    }
  }

  cout << "No" << endl;
  return 0;
}

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

using namespace std;

#define int long long
#define ar array
#define vt vector
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()

#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)

template<class T>
bool umin(T &a, const T &b) {
    return b < a ? a = b, 1 : 0;
}

template<class T>
bool umax(T &a, const T &b) {
    return a < b ? a = b, 1 : 0;
}

template<class A>
void read(vt<A> &v);

template<class A, size_t S>
void read(ar<A, S> &a);

template<class T>
void read(T &x) {
    cin >> x;
}

void read(double &d) {
    string t;
    read(t);
    d = stod(t);
}

void read(long double &d) {
    string t;
    read(t);
    d = stold(t);
}

template<class H, class... T>
void read(H &h, T &... t) {
    read(h);
    read(t...);
}

template<class A>
void read(vt<A> &x) {
    EACH(a, x)read(a);
}

template<class A, size_t S>
void read(array<A, S> &x) {
    EACH(a, x)read(a);
}

string to_string(char c) {
    return string(1, c);
}

string to_string(bool b) {
    return b ? "true" : "false";
}

string to_string(const char *s) {
    return string(s);
}

string to_string(string s) {
    return s;
}

string to_string(vt<bool> v) {
    string res;
    FOR(sz(v))res += char('0' + v[i]);
    return res;
}

template<size_t S>
string to_string(bitset<S> b) {
    string res;
    FOR(S)res += char('0' + b[i]);
    return res;
}

template<class T>
string to_string(T v) {
    bool f = 1;
    string res;
    EACH(x, v) {
        if (!f)
            res += ' ';
        f = 0;
        res += to_string(x);
    }
    return res;
}

template<class A>
void write(A x) {
    cout << to_string(x);
}

template<class H, class... T>
void write(const H &h, const T &... t) {
    write(h);
    write(t...);
}

void print() {
    write("\n");
}

template<class H, class... T>
void print(const H &h, const T &... t) {
    write(h);
    if (sizeof...(t))
        write(' ');
    print(t...);
}

template<class T, class U>
void vti(vt<T> &v, U x, size_t n) {
    v = vt<T>(n, x);
}

template<class T, class U>
void vti(vt<T> &v, U x, size_t n, size_t m...) {
    v = vt<T>(n);
    EACH(a, v)vti(a, x, m);
}

void solve() {
    int s, c;
    read(s, c);

    int ans = min(c / 2, s);
    s -= ans;
    c -= 2 * ans;

    ans += c / 4;
    print(ans);
}

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

    int tt = 1;
//    read(tt);
    FOR(tt) {
//        write("Case #", i + 1, ": ");
        solve();
    }

}



Measured memory_bytes: 3692
#include<iostream>

using namespace std;

int main(){
	int n, cnt = 0;
	cin >> n;
	for(int i = 0; i < n; i++){
		int a;
		cin >> a;
		if(a % 2 == 1) cnt++;
	}
	cout << ((cnt % 2 == 0)? "YES":"NO") << endl;
	return 0;
}

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

int main() {
  int n;
  cin >> n;
//  vector<int> p(n);
  int p;
  int min_value = 2e5;
  int count = 0;
  rep(i,n) {
//	cin >> p.at(i);
    cin >> p;
    if (p <= min_value) {
      min_value = p;
      count++;
    }
  }
  
  cout << count << endl;
  
  return 0;
}


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

int main(){
    int N, K, Q;
    cin >> N >> K >> Q;
    int bucket[N] = {0};
    for(int i =0; i < Q; i++){
        int A;
        cin >> A;
        A--;
        bucket[A] ++;
    }
    for(int i =0; i < N; i++){
        if(K + bucket[i] -Q >0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}

Measured memory_bytes: 1024