akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long ll ;
#define rep(i, a, b) for (int i = a; i <= b; ++ i) 
using namespace std ;
 
string trans(string x, string a, string b, string c) {
	string ret ;
	rep(i, 0, (int) x.length() - 1) {
		if (x[i] == 'a') ret += a ;
		if (x[i] == 'b') ret += b ;
		if (x[i] == 'c') ret += c ;
	}
	return ret ;
}
 
void dfs(string a, string b, string c, int x, int y, int z) {
	if (!y && !z) {
		rep(i, 1, x) cout << a ;
		return ;
	}
	string s[55] ;
	rep(i, 1, x) s[i] = 'a' ;
	for ( ; z; ) {
		for (int i = x; i; -- i) if (z) {
			s[i] = s[i] + 'c' ;
			-- z ;
		}
	}
	int k = x ;
	rep(i, 1, x - 1) if (s[i].length() != s[i + 1].length()) {
		k = i ; 
		break ;
	}
	for ( ; y; ) {
		for (int i = k; i; -- i) if (y) {
			s[i] = s[i] + 'b' ;
			-- y ;
		}
	}
	int X = 0, Y = 0, Z = 0, d[5] = {0} ;
	rep(i, 1, x - 1) if (s[i] != s[i + 1]) {
		d[++ d[0]] = i ;
	} 
	d[++ d[0]] = x ;
	if (d[0]) X = d[1] ;
	if (d[0] > 1) Y = d[2] - d[1] ;
	if (d[0] > 2) Z = d[3] - d[2] ;
	dfs(trans(s[d[1]], a, b, c), trans(s[d[2]], a, b, c), trans(s[d[3]], a, b, c), X, Y, Z) ;
}
 
int main() {
	int x, y, z ;
	string s[55] ;
	scanf("%d%d%d", &x, &y, &z) ;
	if (!x && !y) {
		rep(i, 1, z) printf("%c", 'c') ;
	} else
	if (!x) {
		dfs("b", "c", "a", y, z, x) ;
	} else {
		dfs("a", "b", "c", x, y, z) ;
	}
	return 0 ; 
}

Measured memory_bytes: 256
n=int(input())
b0=input().split()
b=[int(x) for x in b0]

ret=0

if b[-1]==0:
  ret=-1
else:
  maxl=[]
  v=1
  for i in range(n+1):
    maxl.append(v)
    v=(v-b[i])*2
    if v<0:
      ret=-1
      break

v=0
vsum=0
if ret!=-1:
  for i in range(n,-1,-1):
    v=min(v+b[i],maxl[i])
    vsum+=v

if ret==-1:
  print(-1)
else:
  print(vsum)

Measured memory_bytes: 681720
#include <bits/stdc++.h>
#ifdef DBP
#define deb(...) fprintf(stderr,__VA_ARGS__)
#else
#define deb(...) 0
#endif
#define fst first
#define snd second
#define fore(x,a,b) for(int x=(a), qwerty=(b); x<qwerty; x++)
#define pb push_back
#define mset(a,v) memset((a),(v),sizeof(a))
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) int((a).size())
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;

const int N=405;
ll A[N],sum[N][N],dp[N][N];
int n;

ll f(int s, int e){
	if(s+1==e)return 0;
	ll &r=dp[s][e];
	if(r!=-1)return r;
	r=1e18;
	fore(m,s+1,e){r=min(r,f(s,m)+f(m,e)+sum[s][m]+sum[m][e]);}
	assert(r>=0);
	return r;
}

int main(){FIN;mset(dp,-1);
	cin >>n;
	fore(x,0,n)cin>>A[x];
	fore(x,0,n){
		fore(y,x,n)sum[x][y+1]=sum[x][y]+A[y];
	}
	cout << f(0,n) << "\n";
}


Measured memory_bytes: 2816
from sys import stdin, stdout

int_in = lambda: int(stdin.readline())
arr_in = lambda: [int(x) for x in stdin.readline().split()]
mat_in = lambda rows: [arr_in() for _ in range(rows)]
str_in = lambda: stdin.readline().strip()
out = lambda o: stdout.write("{}\n".format(o))
arr_out = lambda o: out(" ".join(map(str, o)))
bool_out = lambda o: out("YES" if o else "NO")
tests = lambda: range(1, int_in() + 1)
case_out = lambda i, o: out("Case #{}: {}".format(i, o))


# https://atcoder.jp/contests/abc171/tasks/abc171_c
def solve(n):
    alphabet = "abcdefghijklmnopqrstuvwxyz"
    reversed_result = ""
    while n > 0:
        curr = n % 26
        curr = 25 if curr == 0 else curr - 1
        reversed_result += alphabet[curr]
        n -= curr
        n //= 26
    return reversed_result[::-1]



if __name__ == "__main__":
    n = int_in()
    out(solve(n))

Measured memory_bytes: 70208
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define INF (1 << 30) - 1
#define LLINF (1LL << 61) - 1
// #define int ll
using namespace std;
const int MOD = 1000000007;
const int MAX = 510000;
 
 
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,place[200010],ans=0;
    cin>>n;
    set<ll> used={0,n+1};
    rep2(i,1,n+1){
        ll a;
        cin>>a;
        place[a]=i;
    }
    rep2(i,1,n+1){
        ll r,l;
        auto itr =used.lower_bound(place[i]);
        r=*itr;
        l=*(--itr);
        ans+=i*(place[i]-l)*(r-place[i]);
        used.insert(place[i]);
}
    cout<<ans<<endl;
    return 0;
}

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

int main()
{
    int X;
    cin >> X;
    long ans = (X / 500) * 1000 + ((X % 500) / 5) * 5;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
    string command,q,str,str1,p;
    int n,a,b,c,d;
    cin >> str >> n;
    for(int i = 0;i<n;i++){
        cin >> command >>a >> b;
        if(command=="print"){
            q = str.substr(a,b-a+1);
            cout << q << endl;
        }
        if(command=="reverse"){
            str1=str.substr(a,b-a+1);
            c = str1.size();
            for(int i =0;i<c;i++){
                str[i+a]=str1[c-i-1];
                
            }
        }
        if(command=="replace"){
            cin >> p;
            str = str.replace(a,b-a+1,p);
        }
    }return 0;
}


Measured memory_bytes: 3216
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double EPS=1e-10;
const double PI=acos(-1);

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<ll> a(n),sum(n+1,0);
    rep(i,n){
        cin>>a[i];
        sum[i+1]=sum[i]+a[i];
    }
    ll ans=inf;
    FOR(i,1,n){
        chmin(ans,abs(sum[i]-(sum[n]-sum[i])));
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define in freopen("input.txt", "r" ,stdin)
#define out freopen("output.txt", "w" , stdout)
#define ll long long
#define inf 200005
#define fr first
#define  sc second
#define pb push_back
#define p_b pop_back
#define p_f pop_front
#define mp make_pair
#define N 100100
#define mod 1000000007
#define pi 3.1415926535
using namespace std;
int n,k;
int a[105];
int dp[105][100005];
int f[100005];
int main (){
//in;out;
ios_base::sync_with_stdio(0);
cin >> n >> k;
for (int i = 1; i <=n; i++){
    cin >> a[i];
}
for (int i = 1; i <=a[1]; i++){
    dp[1][i] = 1;
}
for (int i = 1; i <=n; i++){
    dp[i][0] = 1;
}
int sum = 0;

for (int i = 2; i <=n; i++){
    for (int j = 0; j <= k; j++){
        sum += dp[i-1][j];
        sum%=mod;
        f[j] = sum;
        if (j > a[i]) dp[i][j] = sum + mod  - f[j - a[i]- 1];
        else dp[i][j] = sum;
        dp[i][j]%=mod;
    }
    sum= 0;
}

cout << dp[n][k];
}


Measured memory_bytes: 40832
#include<stdio.h>
#include<stdlib.h>

int main(void){
	int sx,sy,tx,ty;
	int i;
	int dx,dy;
	

	scanf("%d %d %d %d",&sx,&sy,&tx,&ty);
	
	dx = labs(tx-sx);
	dy = labs(ty-sy);

	for(i=0;i<dy;i++){
		printf("U");
	}

	for(i=0;i<dx;i++){
		printf("R");
	}

	for(i=0;i<dy;i++){
		printf("D");
	}

	for(i=0;i<dx;i++){
		printf("L");
	}
	
	printf("L");
	for(i=0;i<dy+1;i++){
		printf("U");
	}

	for(i=0;i<dx+1;i++){
		printf("R");
	}
	printf("D");

	printf("R");
	for(i=0;i<dy+1;i++){
		printf("D");
	}

	for(i=0;i<dx+1;i++){
		printf("L");
	}
	printf("U");

	printf("\n");
return 0;


}

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

int main(){
    int H,W;
    cin >> H >> W;
    vector<vector<int> > A(H, vector<int> (W)), B(H, vector<int> (W));
    rep(i,H){
        rep(j,W){
            cin >> A[i][j];
        }
    }
    rep(i,H){
        rep(j,W){
            cin >> B[i][j];
        }
    }
    
    vector<vector<vector<int> > > dp(H, vector<vector<int> >(W, vector<int> (6480)));
    rep(i,H){
        rep(j,W){
            rep(k,6480){
                dp[i][j][k] = 0;
            }
        }
    }
    vector<vector<int> > C(H, vector<int> (W));
    for (int i = 0; i < H; i++){
        for (int j = 0; j < W; j++){
            C[i][j] = abs(A[i][j] - B[i][j]);
        }
    }
    dp[0][0][C[0][0]] = 1;
    for (int i = 0; i < H - 1; i++){
        for (int j = 0; j < W - 1; j++){
            for (int k = 0; k < 6400; k++){
                if (dp[i][j][k] > 0){
                    dp[i][j + 1][abs(k - C[i][j + 1])]++;
                    dp[i][j + 1][abs(k + C[i][j + 1])]++;
                }
            }
        }
        for (int j = 0; j < W; j++){
            for (int k = 0; k < 6400; k++){
                if (dp[i][j][k] > 0){
                    dp[i + 1][j][abs(k - C[i + 1][j])]++;
                    dp[i + 1][j][abs(k + C[i + 1][j])]++;
                }
            }
        }
    }
    for (int j = 0; j < W - 1; j++){
        for (int k = 0; k < 6400; k++){
            if (dp[H - 1][j][k] > 0){
                dp[H - 1][j + 1][abs(k - C[H - 1][j + 1])]++;
                dp[H - 1][j + 1][abs(k + C[H - 1][j + 1])]++;
            }
        }
    }
    int ans = 6479;
    for (int k = 6479; k >= 0; k--){
        if (dp[H - 1][W - 1][k] > 0) ans = k;
    }
    cout << ans << endl;
}


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

int main(){
	int n;
	cin>>n;
	for(int x=0;x<n;x++){
		int r,t;
		cin>>r>>t;
		
		if(t%30==0){
			if(r%100==0){
				int a=t/30;
				a*=5;
				a+=(r/100);
				cout<<a<<endl;
				}
			else{
				int a,b;
				a=t/30;
				b=t/30;
				a*=5;
				b*=5;
				a+=(r/100);
				b+=((r+99)/100);
				cout<<a<<' '<<b<<endl;
				}	
			}
		else if(r%100==0){
			int a,b;
			a=t/30;
			a*=5;
			a+=(r/100);
			b=a+5;
			cout<<a<<' '<<b<<endl;
			}	
			
		else{
			int a,b,c,d;
			a=t/30;
			b=t/30;
			c=(t+29)/30;
			d=(t+29)/30;
			a*=5;
			b*=5;
			c*=5;
			d*=5;
			a+=(r/100);
			c+=(r/100);
			b+=((r+99)/100);
			d+=((r+99)/100);
			cout<<a<<' '<<b<<' '<<c<<' '<<d<<endl;
			}	
		}
		return 0;
	}

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

int main(void){
   int a[8], min, max;
   for(int i = 0; i<3; i++){
      scanf("%d", &a[i]);
   }

   min = max = a[0];

  for(int i = 1 ; i < 3; i++){
      if(min>a[i]){
        min = a[i];
      }else if(max<a[i]){
         max = a[i];
      }
   }

   printf("%d\n",max-min);
   return 0;


}



Measured memory_bytes: 128
using System;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] vs = {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 };
            Console.WriteLine(vs[int.Parse(Console.ReadLine()) - 1]);
        }
    }
}


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

int z;

int leap(int year){
	if(year % 400 == 0){
		cout << year << endl;
		z++;
	}
	else if (year % 4 == 0){
		if(year % 100 != 0){
			cout << year << endl;
			z++;
		}
	}
	return 0;
}

int main(){
	int a, b;
	z = -1;
	cin >> a >> b;
	if (a == 0 && b == 0) { return 0; }
	for (int i = a; i <= b; i++) {
		leap(i);
	}
	if (z == -1) {
		cout << "NA" << endl;
	}
	while(cin >> a >> b){
		z = -1;
		if (a == 0 && b == 0) { break; }
		cout << endl;
		for ( int i = a;i<=b;i++){
			leap(i);
		}
		if (z == -1){
			cout << "NA" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3056
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int n,x,a[100100],i;
    long long int sum=0,s;
    scanf("%d%d",&n,&x);
    for(i=0;i<n;i++)
        scanf("%d",&a[i]);
    for(i=1;i<n;i++)
    {
        if((a[i]+a[i-1])>x)
        {
                s=(a[i]+a[i-1])-x;
                sum+=s;
                if(a[i]>=s)
                    a[i]-=s;
                else if(a[i]<s)
                    {
                        a[i-1]-=s-a[i];
                        a[i]=0;
                    }
        }
    }
    printf("%lld",sum);
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
using namespace std;
int main (int argc, char const* argv[]) {
  string right = "Hoshino";
  int N;
  cin >> N;
  cin.ignore();
  for (int z = 1; z <= N; z += 1) {
    string line;
    getline(cin, line);
    for (int i = 0; i < line.size(); i += 1) {
      if (line[i] == 'H') {
        if (line.size() >= i + right.size()) {
          bool flag = true;
          for (int j = 0; j < right.size(); j += 1) {
            if (right[j] != line[i+j]) {
              flag = false;
              break;
            }
          }
          if (flag) {
            line[i+right.size()-1] = 'a';    
          }
        }
      }
    }
    cout << line << endl;
    //
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
struct node
{
    int c,t,i;
};
bool cm(node&a,node&b)
{
    return a.c<b.c;
}
int main()
{
  int n,t;
  cin>>n>>t;
  vector<node>v(n);
  for(int i=0;i<n;i++){cin>>v[i].c>>v[i].t;v[i].i=i+1;}

  sort(v.begin(),v.end(),cm);
  for(int i=0;i<n;i++)
  {
    if(v[i].t<=t)
    {
        cout<<v[i].c;
        return 0;
    }
  }
  cout<<"TLE";
}


Measured memory_bytes: 256
// Ambition without ammunition is dangerous
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long int ll;
typedef long double dl;
#define PI  3.14159265358979323846
#define M   1000000007
ll fast(ll n,ll a,ll m)
{
    if(n==0)
        return 1;
    else if(n==1)
        return a;
    else
    {
        ll r=fast(n/2,a,m);
        if(n%2==0)
        {
            return (((r%m)*(r%m))%m);
        }
        else
        {
            return (((((r%m)*a)%m)*r)%m);
        }
    }
}
ll Sum(ll n)
{
    ll d=n*(n+1);
    d/=2;
    return d;
}
int main()
{
    ll n,m,i;
    cin>>n>>m;
    ll A[m];
    ll S=0;
    for(i=0;i<m;i++)
    {
        cin>>A[i];
        S+=A[i];
    }
    if(S>n)
        cout<<-1;
    else
        cout<<n-S;

}


Measured memory_bytes: 3600
#include <stdio.h>
 int main (void){
int a[10000],N;
int b = 0;
scanf("%d",&N);
for(int i=0;i<N;i++){
scanf("%d",&a[i]);
 }
 for(int k=0;k<N;k++){
     if(a[k]%2==0){
         if(a[k]%3!=0&&a[k]%5!=0){
         printf("DENIED");
         b=1;
         break;
         }
     }
 }
 if(b==0){
     printf("APPROVED");
 }
 }

Measured memory_bytes: 128
#利益を最大

N = int(input())
a = [int(input()) for i in range(N)]

d_MAX = -2*10**9
v_min = a[0]

for i in range(1, N):
    d_MAX = max(d_MAX, a[i]-v_min)
    v_min = min(v_min, a[i])

print(d_MAX)



Measured memory_bytes: 13592
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> h(n);
    rep(i,n) cin >> h[i];
    for(int i = n-2; i >= 0; --i){
        if(h[i] > h[i+1]+1){
            cout << "No" << endl;
            return 0;
        }
        chmin(h[i], h[i+1]);
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3716
import sys
h, w, a, b = [int(i) for i in sys.stdin.readline().split()]
res = []
res.append(("0" * a + "1" * (w - a) + "\n") * b)
res.append(("1" * a + "0" * (w - a) + "\n") * (h-b))
print("".join(res))

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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 10000000000
#define MOD 998244353
using ll = long long;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
using Graph = vector<vector<int>>;

int main(){
    int N,W; cin>>N>>W;
    vector<ll> w(N),v(N);
    rep(i,N)cin>>w.at(i)>>v.at(i);
    vector<vector<ll>> dp(N+1,vector<ll> (W+1,0));//dp[n][w] 0ton-1の荷物で重さwとしたときの価値の最大値
    rep(i,N){
        rep(j,W+1){
            dp[i+1][j] = dp[i][j];
            if(j>=w.at(i))dp[i+1][j] = max(dp[i][j-w.at(i)]+v.at(i),dp[i+1][j]);
        }
    }
    ll res = 0;
    rep(j,W+1)res = max(res,dp[N][j]);
    cout<<res<<endl;
}

Measured memory_bytes: 83104
S = str(input())

if S == 'SAT':
    print(1)
elif S== 'FRI':
    print(2)
elif S== 'THU':
    print(3)
elif S== 'WED':
    print(4)
elif S== 'TUE':
    print(5)
elif S== 'MON':
    print(6)
elif S== 'SUN':
    print(7)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef map<int,int> mii;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<long long> vl;
typedef vector<vector<ll>> vll;
typedef vector<bool> vb;
typedef set<int> si; 
typedef queue<int> qi;
typedef stack<int> sti;
typedef priority_queue<int> pqi;
#define fori(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i,b,a) for(int i = (b); i >= (a); --i)
#define all(a) (a).begin(), (a).end()
//#define __builtin_popcountll bitCountLL
//#define __builtin_popcount bitCount
//__builtin_ctz 末尾0的个数, __builtin_clz 前导0的个数
//__builtin_ffs 最后一个1的位置
mt19937 mt_rand(chrono::high_resolution_clock::now().time_since_epoch().count());
//std::uniform_int_distribution<long long> rg(1,1e18);
#define maxn 100005
#define Mod 1000000007
const int INF = 2e9;
const ll ML = 4e18;
    
void solve() {
    int n;
    cin >> n;
    vi a(n);
    fori(i,0,n) cin >> a[i];
    int pre = a[0];
    ll ans = 0;
    fori(i,1,n) {
        ans += max(0, pre - a[i]);
        pre = max(pre, a[i]);
    }
    cout << ans << endl;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
	//cout.precision(30); cout << fixed;
//	freopen("D:\\data_in.txt", "r", stdin);
   
    solve();
   
    /*
    clock_t start,finish;
    start = clock();
    
    finish = clock();
    cout << "\n" << (double)(finish - start) / (double)(CLOCKS_PER_SEC) * 1000 << "ms" << endl;
    */
    return 0;
}

/***************************************************************
 question:
 idea:
 tag:
 record:
 ***************************************************************/


Measured memory_bytes: 3984
#include <iostream>
using namespace std;
#define NIL -1
const int maxn=1e5+7;

struct node{int p,l,r;};

node t[maxn];
int n,d[maxn];

void print(int u)
{
	int i,c;
	cout << "node " << u <<": ";
	cout << "parent = "<< t[u].p<<", ";
	cout << "depth = "<< d[u]<<", ";
	
	if(t[u].p==NIL) cout<<"root, ";
	else if(t[u].l==NIL) cout<<"leaf, ";
	else cout<<"internal node, ";
	
	cout<< "[";
	for(i=0,c=t[u].l;c!=NIL;i++,c=t[c].r)
	{
		if(i) cout<<", ";
		cout<<c;
	}
	cout <<"]"<<endl;
} 

int rec(int u,int p)
{
	d[u]=p;
	if(t[u].r!=NIL)
	rec(t[u].r,p);
	if(t[u].l!=NIL)
	rec(t[u].l,p+1);
}

int main()
{
	int i,j,d,v,c,l,r;
	cin>>n;
	for(i=0;i<n;i++)
	t[i].p=t[i].l=t[i].r=NIL;
	
	for(i=0;i<n;i++)
	{
		cin>>v>>d;
		for(j=0;j<d;j++)
		{
			cin>>c;
			if(j==0) t[v].l=c;
			else t[l].r=c;
			l=c;
			t[c].p=v;
		}
	}
	
	for(i=0;i<n;i++)
	{
		if(t[i].p==NIL)
		r=i;
	}
	rec(r,0);
	for(i=0;i<n;i++)
	print(i);
	
	
	return 0;
}


Measured memory_bytes: 7640
N, M = gets.split.map(&:to_i)
as = Array.new(M) { gets.to_i }
dp = [1] * (N+1)
as.each{|x|
    dp[x] = -1
}
dp[1] = 0 if dp[1] == -1
mod = 1000000007
for i in 0..(N-1) do
    if dp[i+2] != -1
        dp[i+2] = (dp[i+1] + dp[i]) % mod 
    else
        dp[i+2] = 0
    end
end

puts dp[N]


Measured memory_bytes: 3580
package main

import (
	"fmt"
)

func main() {
	var n, a int
	fmt.Scan(&n)

	arr := []int{}
	for i := 0; i < n; i++ {
		fmt.Scan(&a)
		arr = append(arr, a)
	}

	c := 0
	flag := 1
	for flag > 0 {
		flag = 0
		for j := n-1; j > 0; j-- {
			if arr[j-1] > arr[j] {
				arr[j-1], arr[j] = arr[j], arr[j-1]
				c++
				flag = 1
			}
		}
	}
	fmt.Print(arr[0])
	for i := 1; i < n; i++ {
		fmt.Print(" ")
		fmt.Print(arr[i])
	}
	fmt.Println()
	fmt.Println(c)
}



Measured memory_bytes: 1136
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF (1<<28)-1
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int n;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> n;
    rep(i, 0, 100) {
        rep(j, 0, 100) {
            if (n == 4 * i + 7 * j) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}


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

int main()
{
    int n;
    cin >> n;
    int a[n + 1];
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    int j = 0, p = 0;
    bool f = false;
    for (int i = 1; i <= n; i++)
    {
        if (j == 2)
        {
            f = true;
            break;
        }
        if (j == 0)
        {
            j = a[i];
            p++;
        }
        else
        {
            j = a[j];
            p++;
        }
    }
    if (f)
        cout << p << endl;
    else
        cout << -1 << endl;
}


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

using namespace std;

int main() {
    unsigned long long a, b, x;
    unsigned long long ans;

    cin >> a >> b >> x;

    if (b == 0) {
        ans = 1;
    } else if (a == 0) {
        ans = b/x + 1;
    } else {
        ans = b/x - (a-1)/x;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){

    int i,n[10000],m=10000;
    
    for(i = 0;i < 10000;i++){
        cin >> n[i];
        if(n[i] == 0){
            m = i;
            i = 10000;
        }
    }
    
    for(i = 0;i < m;i++){
        cout <<"Case "<<i+1<<": "<<n[i]<<"\n";
        
    }
    
    return 0;

}



Measured memory_bytes: 3016
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N, ans = 0;
    cin >> N;
    vector<vector<int>> g(N);
    
    rep(i, N) {
        int a;
        cin >> a;
        a--;
        g[i].push_back(a);
        
        rep(ii, sz(g[a])) {
            if (g[a][ii] == i) {
                ans++;
            }
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5760
#include <stdio.h>
#include <string.h>
int main(){
    int n,i,j,k,i_len,j_len,dp[1001][1001];;
    char a[1002],b[1002];
    scanf("%d",&n);
    for(k=0;k<n;k++){
        scanf("%s",&a[1]);
        scanf("%s",&b[1]);
        j_len=strlen(&a[1]);
        i_len=strlen(&b[1]);
        for(i=0;i<=i_len;i++){
            for(j=0;j<=j_len;j++){
                if(i==0 || j==0){
                    dp[i][j]=0;
                }
                else if(a[j]==b[i]){
                    dp[i][j]=dp[i-1][j-1]+1;
                }
                else{
                    if(dp[i][j-1]>dp[i-1][j]){
                        dp[i][j]=dp[i][j-1];
                    }
                    else{
                        dp[i][j]=dp[i-1][j];
                    }
                }
            }
        }
        printf("%d\n",dp[i_len][j_len]);
    }
    return 0;
}


Measured memory_bytes: 5664
N, K = map(int, input().split())
h = [int(input()) for i in range(N)]
h.sort()
INF = 10**9
min_dst = INF
for i in range(N-K+1):
    dst = h[i+K-1] - h[i]
    min_dst = min(dst, min_dst)
print(min_dst)

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

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

    int a,b,c;
    cin>>a>>b>>c;
    int cost1 = abs(a-b)+abs(c-b);
    int cost2 = abs(b-a)+abs(c-a);
    int cost3 = abs(a-c)+abs(b-c);
    cout<<min(cost1,min(cost2,cost3))<<'\n';
    return 0;
}   


Measured memory_bytes: 256
n = int(input())
t_lst = list(map(int, input().split()))
m = int(input())
px_lst = [list(map(int, input().split())) for _ in range(m)]

time_lst = []
for i in range(m):
    problem = px_lst[i][0] - 1
    time = px_lst[i][1]
    before = t_lst[problem]
    t_lst[problem] = time
    time_lst.append(sum(t_lst))
    t_lst[problem] = before

for i in range(m):
    print(time_lst[i])

Measured memory_bytes: 9080
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
using namespace std;
int n;
int a[100005],b[100005],c[100005];
long long sum[100005];
int tmp;
long long ans;
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
    	scanf("%d",&a[i]);
	}
	for(int i=1;i<=n;i++){
    	scanf("%d",&b[i]);
	}
	for(int i=1;i<=n;i++){
    	scanf("%d",&c[i]);
	}
	sort(a+1,a+n+1);
	sort(b+1,b+n+1);
	sort(c+1,c+n+1); 
	for(int i=1;i<=n;i++){
		sum[i]=sum[i-1]+(n-(upper_bound(c+1,c+n+1,b[i])-(c+1)));
	}
	b[n+1]=a[n]+3;
	for(int i=1;i<=n;i++){
		tmp=(upper_bound(b+1,b+n+2,a[i])-b);
		if(tmp>n)break;
		else ans+=(sum[n]-sum[tmp-1]);
	}
	cout<<ans;
    return 0;
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long ll;
 
int main(){
    int h,w;cin>>h>>w;
    vector<string> s(h);
    rep(i,h) cin>>s[i];
    /////////
    rep(i,h){
        rep(j,w){
            if(s[i][j]=='#')continue;
            else{
                int count=0;
                for(int k=i-1;k<=i+1;++k){
                    for(int l=j-1;l<=j+1;++l){
                        if(k<0 || k>=h)continue;
                        if(l<0 || l>=w)continue;
                        
                        if(s[k][l]=='#')count+=1;          
                    }
                }
            s[i][j]=char(count+'0');
            }
            }
        }
rep(i,h) cout<<s[i]<<endl;
return 0;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>


using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

class ACalc {
public:
void solve(std::istream& cin, std::ostream& cout) {
    int a,b;
    int ans = 0;
    cin >> a;
    ans = a+a*a+a*a*a;

    cout << ans << endl;
}
};


int main() {
	ACalc solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3632
def main():
    k, n = map(int, input().split())
    a_lst = list(map(int, input().split()))

    d_lst = [0 for _ in range(n)]

    for i in range(n - 1):
        d_lst[i] = a_lst[i + 1] - a_lst[i]

    d_lst.append(a_lst[0] + k - a_lst[n - 1])

    ans = k - max(d_lst)

    print(ans)


if __name__ == "__main__":
    main()


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

int main () {
  int N ;
  cin >> N ;
  
  int board[2][N] ;
  
  for( int i = 0 ; i < 2 ; i++ ) {
    for( int j = 0 ; j < N ; j++ ) {
      cin >> board[i][j] ;
    }
  }
  
  for( int i = 0 ; i < N ; i++ ) {
    board[0][i] += board[0][i-1] ;
  }
  board[1][0] += board[0][0] ;
  for( int i = 1 ; i < N ; i++ ) {
    board[1][i] += max(board[0][i],board[1][i-1]) ;
  }
  cout << board[1][N-1] << endl ;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
 int N;
 double n;
 scanf("%d",&N);
  if(N%2==0){
   n=((double)N/2)/N;
   printf("%lf",n);
  }
  else{
   n=((double)(N+1)/2)/N;
   printf("%lf",n);
  }
 }


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp make_pair
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

class UnionFind {
public:
  vector<int> par, rank;
  UnionFind(int sz) : par(sz, -1), rank(sz, 0){}
  int find(int x){
    if(par[x]<0) 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]) swap(x,y);
    par[x] += par[y];
    par[y] = x;
    if(rank[x]==rank[y]) rank[x]++;
  }
  inline bool same(int x, int y){ return find(x) == find(y); }
  inline int size(int x){ return -par[find(x)]; }
};

long solve(){
  int n,m;
  cin>>n>>m;
  vector<int> a(n);
  rep(i,n) cin>>a[i];
  UnionFind uf(n);
  rep(i,m){
    int s,t;
    cin>>s>>t;
    uf.unite(s,t);
  }
  vector<bool> used(n,false);
  vector<vector<int>> g(n);
  rep(i,n) g[uf.find(i)].pb(i);

  vector<int> amari;
  long ans = 0;
  int gs = 0;
  rep(i,n) if(g[i].size()>0){
    gs++;
    sort(all(g[i]), [&](const int l, const int r){
      return a[l] < a[r];
    });
    ans += a[g[i][0]];
    rep(j,1,g[i].size()) amari.pb(a[g[i][j]]);
  }

  if(gs==1) return 0;
  int req = 2*(gs-1) - gs;
  if(amari.size() < req) return -1;

  sort(all(amari));
  rep(i,req) ans += amari[i];

  return ans;
}

int main(){
  long r = solve();
  if(r==-1) cout << "Impossible" << endl;
  else cout << r << endl;

  return 0;
}


Measured memory_bytes: 6912
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n; scanf("%d",&n);
    vector<int> a(n+1,0);
    for(int i=1;i<n;i++){
    	int x; scanf("%d",&x);
        a[x]++;
    }
    for(int i=1;i<=n;i++) printf("%d\n",a[i]);
}


Measured memory_bytes: 4080
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
//ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll c(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }

int main(void) {
	int n;
	cin >> n;
	int t = n % 10;
	switch (t) {
	case 2:
	case 4:
	case 5:
	case 7:
	case 9:
		puts("hon");
		break;
	case 3:
		puts("bon");
		break;
	default:
		puts("pon");
	}
	return 0;
}


Measured memory_bytes: 3620
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            long sum = 0;
            int N = int.Parse(Console.ReadLine());
            String[] str = Console.ReadLine().Split(' ');
            var T= new int[101];

            for(int i = 0; i < N; i++)
            {
                T[i] = int.Parse(str[i]);
                sum += T[i];
            }
            int M = int.Parse(Console.ReadLine());
            var P = new int[101];
            var X = new int[101];
            for (int i = 0; i < M; i++)
            {
                String[] tmpstr = Console.ReadLine().Split(' ');
                P[i] = int.Parse(tmpstr[0])-1;
                X[i] = int.Parse(tmpstr[1]);
            }
            for (int i = 0; i < M; i++)
            {
                Console.WriteLine(sum + (X[i] - T[P[i]]));

            }


        }
    }
}


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

int main() {
	int a, b, c;
	string ans;
	cin >> a >> b >> c;
	if(a==b && b!=c){
		ans = "Yes";
	}else if(b==c && c!=a){
		ans = "Yes";
	}else if(a==c && a!=b){
		ans = "Yes";
	}else{
		ans = "No";
	}

	cout << ans << endl;
	return 0;

}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
  public static void main(String args[]){
    Scanner scan=new Scanner(System.in);
    int num=scan.nextInt();
    int mem[]=new int[num];
    int come[]=new int[num];
    for(int a=0;a<num;a++){
      mem[a]=scan.nextInt();
    }
    for(int a=1;a<num+1;a++){
          come[mem[a-1]-1]=a;
    }
    for(int a=0;a<num;a++){
      System.out.print(come[a]+" ");
    }
  }
}

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

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

    int res = 0;
    int mn = 0;
    int now;
    for (int i = 0; i < N; i++) {
        cin >> now;
        if (i == 0 || mn >= now) {
            res++;
            mn = now;
        }
    }
    cout << res;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		for (int i = 0; i < n; i++) {
			int[] nums = {sc.nextInt(), sc.nextInt(), sc.nextInt()};
			Arrays.sort(nums);
			System.out.println(nums[0] * nums[0] + nums[1] * nums[1] == nums[2] * nums[2] ?
							   "YES" : "NO");
		}

	}

}

Measured memory_bytes: 23400
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, a, b) for(int i = (a); i <= (b); i++)
#define PER(i, a, b) for(int i = (a); i >= (b); i--)
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define all(S) (S).begin(), (S).end()
#define pf push_front
#define pb push_back
#define mk make_pair
#define S second
#define F first
typedef long long ll;
typedef long double lf;
typedef pair<int, int> ii;
const int MAX = 55;
ll pd[MAX][MAX][MAX*MAX];
int N, K, a[MAX];

int main(int argc, char ** argv) {
	ll ans = 0;
	scanf("%d%d", &N, &K);
	rep(i, 0, N) scanf("%d", &a[i]);
	pd[0][0][0] = 1;
	rep(i, 0, N) rep(j, 0, N) REP(k, 0, 2500) {
		if(!pd[i][j][k]) continue;
		pd[i+1][j][k] += pd[i][j][k];
		pd[i+1][j+1][k+a[i]] += pd[i][j][k];
	}
	REP(j, 1, N) ans += pd[N][j][j*K];
	printf("%lld\n", ans);
	return 0;
}



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

int main() {
  ll Q, H, S, D;
  long double N;
  cin >> Q >> H >> S >> D >> N;
  ll a = min(2*Q,H);//0.5l最安
  ll b = min(S,2*a);//1l最安
  ll c = min(D,2*b);//2l最安
  ll x = N/2;
  ll y = (ll)N%2;
  ll z = (ll)(N*100)%100/50;
  ll xx = (ll)(N*100)%50/25;

  cout << c*x+b*y+a*z+Q*xx << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define endl '\n'
void trace(int n, int arr[]){for(int i = 0; i < n; i++){cout << arr[i] << " ";} cout << endl << endl;}
int main()
{
    Hello
    ll a, b, c;
    char dot;
    cin >> a >> b >> dot >> c;
    b *= 100;
    b += c;
    cout << (a * b)/100;
    return 0;
}

Measured memory_bytes: 3660
import java.util.Scanner;
class Main
 {
   public static void main(String[] args)
      {
      Scanner sc = new Scanner(System.in);
      int n, x, i, j, k, c;
      while(true){
             c = 0;
        n = sc.nextInt();
        x = sc.nextInt();
        if(n==0&&x==0)break;
               
          for (i = 1; i<=n; i++){
            for( j = i+1; j<=n; j++){
              for( k = j+1; k<=n; k++){
                 if (i+j+k==x)c++;
                                   }
                                  }
                                 }
         System.out.println(c);
                  }
       }
 }



Measured memory_bytes: 26444
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

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

__attribute__((constructor))
void initial() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int main() {
    int N, M;
    cin >> N >> M;
    int sumA = 0;
    vector<int> A;
    rep(i, N) {
        int Ai;
        cin >> Ai;
        sumA += Ai;
        A.pb(Ai);
    }
    int cntOK = 0;
    rep(i, N) {
        if ((A[i] * 4 * M) >= sumA) {
            cntOK++;
        }
    }

    if (cntOK >= M) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    
}


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

int main(){
    int N;cin>>N;
    ll nt=1,na=1;
    ll t,a;
    for(int i=0;i<N;i++){
        cin>>t>>a;    
        if(nt<=t&&na<=a){
            nt=t;
            na=a;
        }
        else{
            ll s=max((nt+t-1)/t,(na+a-1)/a);
            nt=t*s;
            na=a*s;
        }
    }
    cout<<nt+na<<endl;
    return 0;
}

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

int main() {
  int A1, A2, A3;
  cin >> A1 >> A2 >> A3;
  if (A1 + A2 + A3 >= 22) {
    cout << "bust" << endl;
  } else {
    cout << "win" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>
#include<map>
 
 
using namespace std;
#define int long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back
#define mod 1000000007
//#define mod 998244353

char S[100005];
int dp[100005][15];
signed main(){
    scanf("%s",S);
    int N=strlen(S);
    for(int i=N-1;i>=0;i--){
        rep(j,13){
            int num=S[i]-'0';
            int keta=N-1-i;
            int mod10keta=1;
            rep(k,keta%12)mod10keta=mod10keta*10%13;
            mod10keta%=13;
            if(i==N-1){
                if(S[i]=='?'){
                    if(j<10)dp[i][j]=1;
                }else{
                    if(num==j)dp[i][j]=1;
                }
            }else{
                if(S[i]=='?'){
                    rep(k,10)dp[i][j]+=dp[i+1][((j-k*mod10keta)%13+13)%13];
                }else{
                    dp[i][j]+=dp[i+1][((j-num*mod10keta)%13+13)%13];
                }
            }
            dp[i][j]%=mod;
        }
    }
    printf("%lld\n",dp[0][5]);
    return 0;
}

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

#define REP(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define REPE(i, n) for (int i = (int)(0); i <= (int)(n); ++i)
#define REPR(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define REPRE(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using ll = long long;

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

	int p,q,r;cin >> p >> q >> r;
	int ans = p+q;
	if(ans>q+r) ans=q+r;
	if(ans>r+p) ans=r+p;

    cout << ans << endl;

    return 0;
}

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


n, q = map(int, input().split())
s = input()

AC = [0]
count = 0
for i in range(n - 1):
    if s[i] + s[i + 1] == "AC":
        count += 1
        AC.append(count)
    else:
        AC.append(count)

for _ in range(q):
    l, r = map(int, input().split())
    print(AC[r - 1] - AC[l - 1])


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

ll n, q, b, c;

int main() {
	cin>>n;
	ll a[n], freq[100010], total=0;
	memset(freq, 0, sizeof(freq));
	for (int i=0; i<n; i++) {
		cin>>a[i];
		freq[a[i]]++;
		total+=a[i];
	}
	cin>>q;
	for (int i=0; i<q; i++) {
		cin>>b>>c;
		ll diff=c-b;
		diff*=freq[b];
		total+=diff;
		freq[c]+=freq[b];
		freq[b]=0;
		cout<<total<<endl;
	}
}



Measured memory_bytes: 5148
#include<bits/stdc++.h>
using namespace std;
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vec             vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define inf             1e18
#define no_of_test(x)        int x; cin>>x; while(x--)
const int mod = 1e9 + 7;
//actual code is at the top 
int32_t main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//	no_of_test(x)
	{
      int n,r;
	  cin>>n>>r;
	  if(n>=10)
	  {
		  cout<<r<<'\n';
	  }	 
	  else
	  {
		  cout<<r+100*(10-n)<<'\n';
	  }
	  
	}
	return 0;
}
 

Measured memory_bytes: 3644
#include<stdio.h>
#include<algorithm>
using namespace std;
long long t[11000];
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++)scanf("%lld",t+i);
	std::sort(t,t+a);
	if(t[0]!=1){
		printf("1\n");return 0;
	}
	long long now=0;
	for(int i=0;i<a;i++){
		now+=t[i];
		if(i==a-1||now+1<t[i+1]){
			printf("%lld\n",now+1);
			break;
		}
	}
}

Measured memory_bytes: 1116
#include <iostream>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
 
using namespace std;
typedef long long int ll;
typedef pair <int,int> pii;
typedef pair<ll,ll> pll;
 
 
/*bool compare_function(const pair<int, int> a, const pair<int, int> b)
{
    return a.first < b.first;
}*/
// use case
//sort(V.begin(), V.end(), compare_function);
 
/*struct compare
{
    bool operator ()(const pair<int, int> &a, const pair<int, int> &b) {
    if (a.second-a.first==b.second-b.first)
    {
        return a.first>b.first;
    }
    return a.second-a.first < b.second-b.first;}
};
priority_queue <pair<int,int>, vector <pair<int,int>>, compare> Q;*/
 
/*void print1(vector <int> X)
{
    for (int i=0; i<X.size(); i++)
    {
        cout<<X[i]<<" ";
    }
    cout<<endl;
    return;
}
 
void print2(vector <vector <int>> X)
{
    for (int i=0; i<X.size(); i++)
    {
    for (int j=0;j<X[i].size();j++) {
        cout<<X[i][j]<<" ";}
    cout<<endl;}
    return;
}*/

 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    int x=1000-n%1000;
    cout<<x%1000<<endl;
    return 0;
}


Measured memory_bytes: 3640
n = int(input())
a = [int(x) for x in input().split()]

a.sort()

results = []
x_min = a[0]
x_max = a[-1]
if x_min < 0 and x_max >= 0:
    # -と+にまたがる
    for i in range(1, n-1):
        if a[i] < 0:
            results.append((x_max, a[i]))
            x_max -= a[i]
        else:
            results.append((x_min, a[i]))
            x_min -= a[i]
elif a[0] >= 0:
    # +側only
    for i in range(1, n-1):
        results.append((x_min, a[i]))
        x_min -= a[i]
else:
    # -側only
    for i in range(1, n-1):
        results.append((x_max, a[i]))
        x_max -= a[i]

results.append((x_max, x_min))
print(x_max - x_min)
for x in results:
    print(str(x[0]) + " " + str(x[1]))

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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long  ll; typedef vector<int> VI; typedef pair<ll,int> pii;
typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){cerr<<"\n";} template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n; cin >>n;
	VI a(n);
	rep(i, n) cin >>a[i];
	map<int, int> mp;
	rep(i, n) mp[a[i]]++;
	ll sm = 0;
	for(auto x: mp) sm += (ll)x.second *(x.second -1) /2;
	
	rep(i, n){
		ll cr = mp[a[i]];
		ll se = (cr-2)* (cr-1)/2  -  cr * (cr-1) /2;
		cout << sm + se<<"\n";
	}
	return 0;
}


Measured memory_bytes: 8320
R, G, B, N = map(int,input().split())
count = 0

for r in range(N // R + 1):
    for g in range(N // G + 1):
        b = (N - R*r - G*g) / B
        if b >= 0 and b.is_integer():
            count += 1

print(count)


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

#define ARRSIZE 100001
void solve(long long N, std::vector<long long> a){
  vector<long long> dp(ARRSIZE);

  for(long long i = 0; i < N; i++){
    for(long long j = -1; j <= 1; j++) {
      if(a[i]+j >= 0 && a[i]+j < ARRSIZE) dp[a[i]+j]++;
    }
  }


  cout << *max_element(dp.begin(), dp.end()) << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
  scanf("%lld",&N);
  std::vector<long long> a(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&a[i]);
  }
    solve(N, std::move(a));
    return 0;
}


Measured memory_bytes: 1792