akhauriyash/Code-Regression huggingface dataset:
// package div2658.dpatcoder;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    static class FastReader {

        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        }

        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        }

        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 

    }

    public static void main(String[] args) {
        FastReader fs = new FastReader();
        int n = fs.nextInt();
        int k = fs.nextInt();
        int[] h = new int[n];
        
        for (int i = 0; i < n; i++) {
            h[i] = fs.nextInt();
        }

        int[] dp = new int[n];

        dp[n-1] = 0;

        for (int i = n-2; i >= 0; i--) {
            int curr = Integer.MAX_VALUE;
            for (int l = 1; l <= k; l++) {
                if (i+l < dp.length) {
                    curr = Math.min(curr, Math.abs(h[i] - h[i+l]) + dp[i+l]);
                }
            }
            dp[i] = curr;
        }

        System.out.println(dp[0]);

    }




}


Measured memory_bytes: 43940
#include <bits/stdc++.h>
#define rep(i, l, r) for (register int i = l; i <= r; i++)
#define per(i, r, l) for (register int i = r; i >= l; i--)
#define srep(i, l, r) for (register int i = l; i < r; i++)
#define sper(i, r, l) for (register int i = r; i > l; i--)
#define ll long long int 
#define pii pair<int, int>
#define fi first
#define se second
using namespace std;

int main(){ 
	int a, v, b, w, t;
	scanf("%d%d%d%d%d", &a, &v, &b, &w, &t);
	if (v <= w) printf("NO");
	else {
		if ((ll)t * (v - w) >= abs(a - b)) printf("YES");
		else printf("NO");
	}
	return 0;
}



Measured memory_bytes: 3828
#include<iostream>
#include <iomanip>

#define PI 3.14159265359	

using namespace std;

int main(){
	int n, x;
	cin >> n;
	for (int i = 1; i <= n; i++){
		if (i % 3 == 0) cout << " " << i;
		else {
			x = i;
			while (x){
				if (x % 10 == 3){
					cout << " " << i;
					break;
				}
				else x /= 10;
			}
		}
	}
	cout << endl;
}

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

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

  vector<pair<int, int>> p(M);
  for (int i = 0; i < M; i++) {
    int P, Y;
    cin >> P >> Y;
    P--;
    p.at(i) = make_pair(Y, P);
  }

  vector<vector<int>> vals(N);
  for (int i = 0; i < M; i++) vals.at(p.at(i).second).push_back(p.at(i).first);

  for (int v = 0; v < N; v++) {
    sort(vals.at(v).begin(), vals.at(v).end());
  }

  for (int i = 0; i < M; ++i) {
    int v = p.at(i).second;
    printf("%06d", v + 1);
    int id = lower_bound(vals.at(v).begin(), vals.at(v).end(), p.at(i).first) -
             vals.at(v).begin();
    printf("%06d\n", id + 1);
  }
}

Measured memory_bytes: 9420
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define mp make_pair
#define fir first 
#define sec second
#define int long long
#define endl "\n"
# define M_PI 3.14159265358979323846
using namespace std;
const int nax=1e5+5;
vector<int>adj[nax];
const int mod=1e9+7;
const int inf=1e18+7;

signed main(){
	int n;
	cin>>n;
	std::cout << std::setprecision(15) << 2*M_PI*n << endl;
	return 0;
}



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

using namespace std;

#define LL long long
#define pb push_back
#define pLL pair<LL,LL>
#define ff first
#define ss second
#define rep(i,a,b) for(LL i=a;i<=b;++i)
#define ld double
#define mp make_pair
#define vLL vector<LL>
#define vpLL vector<pLL>
#define vld vector<ld>
#define pld pair<ld,ld>
#define vpld vector<pld>
#define SLL set<LL>
#define SpLL set<pLL>
#define FIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)

LL n,p[20005],a[20005],b[20005];

int main()
{
    cin>>n;
    rep(i,1,n) cin>>p[i];
    rep(i,1,n) a[i]=30000*i;
    rep(i,1,n) b[p[i]]=30000*(n-p[i])+i;
    rep(i,1,n) cout<<a[i]<<" ";
    cout<<endl;
    rep(i,1,n) cout<<b[i]<<" ";
    cout<<endl;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
//#include<bits/extc++.h>
//using namespace __gnu_pbds;
using namespace std;
#define F(i,L,R) for (int i = L; i < R; i++)
#define FE(i,L,R) for (int i = L; i <= R; i++)
#define getI(a) scanf("%d", &a)
#define getII(a,b) scanf("%d%d", &a, &b)
#define getIII(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define VgetI(n) int (n); scanf("%d",&(n))
#define VgetII(n,m) int (n),(m); scanf("%d %d",&(n),&(m))
#define VgetIII(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k))
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define INF 2000000000
#define PI 3.1415926535897932384626
const ll MOD=1e9+7;
int main(){
        int a,b,c;
        while(~getIII(a,b,c)) printf("%d\n",max(0,b+c-a));
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main () {
  int N;
  cin >> N;
  int cl[100003];
  for (int i = 0; i < N; i ++) {
    int k;
    cin >> k;
    cl[k - 1] = i + 1;
  }
  for (int i = 0; i < N - 1; i ++){
    cout << cl[i] << ' ';
  }
  cout << cl[N - 1] << endl;
}


Measured memory_bytes: 1152
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<ctype.h>

int main()

{
    long long int n,a,b;
    scanf("%lld",&n);
    a=(n/500)*1000;
    b=((n-(n/500)*500)/5)*5;
    printf("%lld\n",a+b);

    return 0;
}


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

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int num = 1, cnt = 0;
		while(num < b) {
			num += (a - 1);
			cnt++;
		}
		out.println(cnt);
		
		out.close();
	}

static class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}
}




Measured memory_bytes: 22356
#include <map>
#include <set>
#include <ctime>
#include <queue>
#include <stack>
#include <cmath>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cctype>
#include <string>
#include <numeric>
#include <cstring>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std ;
#define rep(i, a, b) for (register int i = (a); i <= (b); ++i)
#define per(i, a, b) for (register int i = (a); i >= (b); --i)
#define loop(it, v) for (auto it = v.begin(); it != v.end(); it++)
#define cont(i, x) for (register int i = head[x]; i; i = edge[i].nex)
#define clr(a) memset(a, 0, sizeof(a))
#define ass(a, cnt) memset(a, cnt, sizeof(a))
#define cop(a, b) memcpy(a, b, sizeof(a))
#define lowbit(x) ((x) & (-(x)))
#define all(x) x.begin(), x.end()
#define SC(t, x) static_cast <t> (x)
#define ub upper_bound
#define lb lower_bound
#define pqueue priority_queue
#define mp make_pair
#define pb push_back
#define pof pop_front
#define pob pop_back
#define fi first
#define se second
#define y1 y1_
#define Pi acos(-1.0)
#define iv inline void
#define enter putchar('\n')
#define sum(x) ((int)x.sume())
#define file(x) freopen(x".in", "r", stdin),freopen(x".out", "w", stdout)
typedef double db ;
typedef long long ll ;
typedef unsigned long long ull ;
typedef pair <int, int> pii ;
typedef vector <int> vi ;
typedef vector <pii> vii ;
typedef queue <int> qi ;
typedef queue <pii> qii ;
typedef set <int> si ;
typedef map <int, int> mii ;
typedef map <string, int> msi ;
const int maxn = 5e2 + 100 ;
const int inf = 0x3f3f3f3f ;
const int iinf = 1 << 30 ;
const ll linf = 2e18 ;
const ll mod = 1e9 + 7 ;
const double eps = 1e-7 ;
template <class T = int> T read()
{
	T f = 1, a = 0;
	char ch = getchar() ;
	while (!isdigit(ch)) { if (ch == '-') f = -1 ; ch = getchar() ; }
	while (isdigit(ch)) { a =  (a << 3) + (a << 1) + ch - '0' ; ch = getchar() ; }
	return a * f ;
}

int k, n;

int ans[maxn][maxn];

signed main()
{
	scanf("%d", &k);
	n = min(k, 500);
	rep(i, 1, n) rep(j, 1, n) ans[j][(i + j - 2) % n + 1] = ((j & 1) && (i + n <= k)) ? i + n : i;
	printf("%d\n", n);
	rep(i, 1, n) rep(j, 1, n) printf("%d%c", ans[i][j], " \n"[j == n]);
	return 0;
}

Measured memory_bytes: 2432
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#include<queue>
#define ll long long
#define itn int
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
using namespace std;

int N,M,K,A,B,C,ans=0,cnt=0;
string S,T;
vector<int> P,Q;
vector<pair<int,int>> PP;
bool CAN=true;


int main(){
  cin>>S;
  int A[5];
  REP(i,5) A[i]=0;
  REP(i,S.size()){
    if(S.at(i)=='N') A[1]++;
    else if(S.at(i)=='S') A[2]++;
    else if(S.at(i)=='W') A[3]++;
    else if(S.at(i)=='E') A[4]++;
  }
  
  if(A[1]*A[2]==0 && A[1]+A[2]>0) CAN=false;
  if(A[3]*A[4]==0 && A[3]+A[4]>0) CAN=false;
  
  if(CAN) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
const double pi=acos(-1);

int main(){
  int n;
  cin >> n;
  int gapt=0,gapx=0,gapy=0;
  rep(i,n){
    int t,x,y;
    cin >> t >> x >> y;
    if(abs(x-gapx)+abs(y-gapy)<=t-gapt && (abs(x-gapx)+abs(y-gapy))%2==(t-gapt)%2){
      gapt=t;
      gapx=x;
      gapy=y;
    }
    else{
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n, m;
string s, t;

int32_t main(){_
   
   cin >> n;

   vector<int> f(n+1,0);
   
   for (int i = 2; i <= n; ++i)
   {
      int x;
      cin >> x;
      f[x]++;
   }

   for (int i = 1; i <= n; ++i)
   {
      cout<<f[i]<<"\n";
   }

   return 0;
}

Measured memory_bytes: 4780
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define F first
#define S second
#define db double
#define pb push_back
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define all(a) a.begin(),a.end()
using namespace std;

 ll mod=1e9 +7;

ll expo(ll base,ll exponent,ll mod){
    ll ans=1;
    while(exponent!=0){
        if(exponent&1) ans=(1LL*ans*base)%mod;
        base=(1LL*base*base)%mod;
        exponent>>=1;
    }
    return ans%mod;
}
 
vector<bool>  prime(90000002,true);
void Sieve() 
{ 
   
    for (int p=2; p*p<=90000001; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=90000001; i += p) 
                prime[i] = false; 
        } 
    } 
}

ll get_val(vector<ll>&ft,ll index)
{
  ll res=0;
  for(;index>=0;index=(index & (index+1))-1)
    res+=ft[index];
  return res;
}

void update(vector<ll>&ft,ll index,ll val)
{
  for(;index<(ll)ft.size();index|=index+1)
    ft[index]+=val;
}

ll mex(vector<ll>&a, ll n)
{
  ll res=0;
  // set<ll>st;
  vector<ll>b(n+1,0);
  for(auto x:a) b[x]++;
    while(res<n && b[res]>0) res++;
  return res;
}



int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //   #ifndef ONLINE_JUDGE
    // // for getting input from input.txt
    // freopen("input.txt", "r", stdin);
    // // for writing output to output.txt
    // freopen("output.txt", "w", stdout);
    // #endif
    
    // Sieve();
   ll tests=1;
 // cin>>tests;
  // ll t=1;
    while(tests--)
    {
      ll a=0,w=0,t=0,r=0,n;
      cin>>n;
      string s;
      while(n--)
      {
        cin>>s;
        if(s=="TLE") t++;
        else if(s=="RE") r++;
        else if(s=="AC") a++;
        else w++;
      }
      cout<<"AC x "<<a<<"\n";
      cout<<"WA x "<<w<<"\n";
      cout<<"TLE x "<<t<<"\n";
      cout<<"RE x "<<r<<"\n";

    }

    return 0;
   }

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

int main()
{
	int N,K,sum=0;
	int fruit[1050];
	scanf("%d%d",&N,&K);
	for(int i=0;i<N;++i)
		scanf("%d",&fruit[i]);
	sort(fruit,fruit+N);
	for(int i=0;i<K;++i)
		sum+=fruit[i];
	printf("%d\n",sum);
return 0;
}

Measured memory_bytes: 3212
#include<bits/stdc++.h>
using namespace std;
#define _ ios::sync_with_stdio(false);cin.tie(0);
#define __ cout<<fixed;cout<<setprecision(10);
#define int long long

int32_t main() {
	_ __

#ifdef LOCAL_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n;
	cin >> n;
	int arr[n];
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
	}
	int count = 0;
	int x = 0;
	int untilmax = arr[0];
	for (int i = 1; i < n; i++) {
		if (arr[i] < untilmax) {
			count += untilmax - arr[i];
		}
		else {
			untilmax = arr[i];
		}
	}
	cout << count << "\n";


#ifdef LOCAL_JUDGE
	cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
#endif

	return 0;
}

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

using namespace std;
typedef pair<int,int> pii;
typedef long long int ll;

#define INF 1 << 30
#define REP(i,n) for(ll i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(ll i=(k);i<(int)(n);i++)



vector<bool> gen_sosuu(vector<bool> sosuu){
  int size = sosuu.size();
  REP(i,size){
    sosuu[i] = true;
  }
  sosuu[0] = false;
  sosuu[1] = false;
  sosuu[2] = true;
  FOR(i,2,sqrt(size)+1){
    if(sosuu[i] == false) continue;
    for(int j = 2; i*j<size;j++){
      sosuu[i*j] =false;
    }
  }
  return sosuu;
}

int n;
vector<ll> a;
ll rui[1000001];

bool check(int m){
  ll now = rui[m+1];
  FOR(i,m+1,n){
    if(now*2<a[i]) return false;
    now += a[i];
  }
  return true;
}


int main(){
  cin >> n;
  REP(i,n){
    ll x;
    cin >> x;
    a.push_back(x);
  }
  sort(a.begin(),a.end());
  rui[0] = 0;
  REP(i,n){
    rui[i+1] = rui[i] + a[i];
  }
  int ok = n-1;
  int ng = -1;
  int m;
  while(abs(ok-ng)>1){
    m = (ok+ng)/2;
    if(check(m)){
      ok = m;
    }else{
      ng = m;
    }
  }
  cout << n-ok<< endl;
}


Measured memory_bytes: 1908
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
const ll mod = 1e9 + 7;

int main() {
  int x;
  cin >> x;
  for (int i = 0; i * 100 <= x; i++) {
    for (int j = 0; i * 100 + j * 101 <= x; j++) {
      for (int k = 0; i * 100 + j * 101 + k * 102 <= x; k++) {
        for (int l = 0; i * 100 + j * 101 + k * 102 + l * 103 <= x; l++) {
          for (int m = 0; i * 100 + j * 101 + k * 102 + l * 103 + m * 104 <= x;
               m++) {
            if ((x - (i * 100 + j * 101 + k * 102 + l * 103 + m * 104)) % 105 ==
                0) {
              cout << 1 << endl;
              return 0;
            }
          }
        }
      }
    }
  }
  cout << 0 << endl;
  return 0;
}

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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

typedef pair<ll,ll> P_ll;
struct edge {int to , cost;};
typedef vector<vector<edge>> wgraph; // cost, to

// 比較の動きを定義した構造体を使えばよい
struct state {
    int node;
    ll cnt;
    ll nokori;
    bool operator<(const state& r) const{
        if(cnt != r.cnt) return cnt > r.cnt;
        else return nokori < r.nokori;
    }
};

P_ll ans[300][300];

int main(void) {
  int N, M;
  std::cin >> N >> M;

  ll L;
  std::cin >> L;

  wgraph g(N);
  REP(i, M){
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    a--, b--;
    if(L >= c){
      g[a].push_back({b, c});
      g[b].push_back({a, c});
    }
  }

  priority_queue<state> que;
  REP(i, N) REP(j, N) {
    if(i == j) ans[i][j] = {0, L};
    else ans[i][j] = {longinf, -1};
  }

  REP(st, N){
    que.push({st, 0, L});

    while(que.size()){
      auto q = que.top();
      que.pop();

      ll s = q.node;
      ll c1 = q.cnt;
      ll zan = q.nokori;

      if(ans[st][s].first < c1) continue;
      if(ans[st][s].second > zan) continue;

      for(auto&& v : g[s]){
        ll z = zan;
        ll c = c1;
        if(z < v.cost) {
          z = L;
          c++;
        }
        z -= v.cost;
        if(ans[st][v.to].first > c || (ans[st][v.to].first == c && z > ans[st][v.to].second)){
          ans[st][v.to] = {c, z};
          que.push({v.to, c, z});
        }
      }
    }
  }

  int Q;
  cin >> Q;

  REP(i, Q){
    int s, t;
    scanf("%d %d", &s, &t);
    t--;s--;

    if(ans[s][t].first == longinf){
      cout << -1 << endl;
    } else {
      cout << ans[s][t].first << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 3844
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    S=ST()
    d = defaultdict(int)
    for s in S:
        d[s]+=1
    for v in d.values():
        if v&1:
            print("No")
            exit()
    print("Yes")
if __name__ == '__main__':
    main()

Measured memory_bytes: 3572
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#include <bitset>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < (n); i++)

using namespace std;

void solve() {
  string S;
  cin >> S;
  long N = S.size() + 1;
  // long bottom = 0;
  long current = 0;
  long top = 0;
  long dec_len = 0;
  long sum = 0;
  for (char c: S) {
    if (c == '<') {
      current++;
      sum += current;
      top = current;
      dec_len = 0;
    } else {
      current = min(0l, current - 1);
      dec_len++;
      if (current < 0) {
        current = 0;
        sum += dec_len - 1;
        if (dec_len > top) sum += 1;
      }
    }
  }
  cout << sum << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 1172
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define pb push_back
#define fr(i,n) for(int i=0;i<n;i++)
#define Fr(i,n) for(int i=0;i++<n;)
#define ifr(i,n) for(int i=n-1;i>=0;i--)
#define iFr(i,n) for(int i=n;i>0;i--)

int gcd(int n,int m){
  if(n>m) return gcd(m,n);
  else if(n==0) return m;
  else return gcd(m-n*(m/n),n);
}

int main(){
  int n,x,y[100010],z,ans=0;
  cin>>n>>x;
  fr(i,n){cin>>z;ans=gcd(abs(z-x),ans);}
  cout<<ans<<endl;
}

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

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

const int mod =  1000000007;  //出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;


int main()
{
    int n; cin >> n;
    ll zmax = -INF,zmin = INF;
    ll wmax = -INF,wmin = INF;
    rep(i,n){
        ll x,y; cin >> x >> y;
        zmin = min(zmin,x+y);
        zmax = max(zmax,x+y);
        wmin = min(wmin,x-y);
        wmax = max(wmax,x-y);
    }
    cout << max(abs(zmax-zmin),abs(wmax-wmin)) << endl;

}

Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <math.h>
#include <set>
#include <bitset>
#include <stack>
#include <cmath>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
#define mp make_pair;

const ll prime = 1000000000 + 7;
const ld PI = 2 * acos(0.0);

/*
cout << fixed << setprecision(10);
*/

int main() {

	ll m;
	cin >> m;
	vector<ll> d(m), c(m);
	vector<ll> num(10, 0);

	for (ll i = 0; i < m; i++)
	{
		cin >> d[i] >> c[i];
		num[d[i]] += c[i];
	}


	ll a1, n1, a2, a3;
	ll cnt = 0;
	bool flag = true;
	while (flag) {
		flag = false;
		for (ll i = 0; i < 10; i++)
		{
			a1 = i;
			n1 = num[i] / 2;
			if (n1 > 0) {
				flag = true;
			}
			num[i] -= n1 * 2;

			a2 = (a1 * 2) / 10;
			a3 = (a1 * 2) % 10;
			if (a2 != 0) {
				num[a2] += n1;
			}
			num[a3] += n1;
			cnt += n1;
		}
	}

	vector<ll> number;
	for (ll i = 9; i >= 0; i--)
	{
		if (num[i] != 0) {
			number.push_back(i);
		}
	}

	ll n = number.size();
	ll i = 0;
	while (i < n - 1) {
		a1 = number[i] + number[i + 1];
		number[i] = a1 / 10;
		number[i + 1] = a1 % 10;
		cnt++;
		if (number[i] == 0) {
			i++;
		}
	}

	cout << cnt << endl;

	return 0;
}


Measured memory_bytes: 3328
#設定
import sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict

con = 10 ** 9 + 7
#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N = int(input())
	ans = 0
	for i in range(1, N + 1):
		if i % 3 != 0 and i % 5 != 0:
			ans += i

	print(ans)
	


if __name__ == '__main__':
	main()

Measured memory_bytes: 67700
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pii pair<int, int>
#define p3i pair<pii, int>
#define pll pair<ll, ll>
#define p3l pair<pll, ll>
#define vi vector<int>
#define vpii vector<pii>
#define vp3i vector<p3i>
#define vpll vector<pll>
#define vp3l vector<p3l>
#define lseg L, (L+R)/2, N*2+1
#define rseg (L+R)/2+1, R, N*2+2
#define ub upper_bound
#define lb lower_bound
#define pq priority_queue
#define MN 1000000007
#define fox(k, x) for (int k=0; k<x; ++k)
#define fox1(k, x) for (int k=1; k<=x; ++k)
#define foxr(k, x) for (int k=x-1; k>=0; --k)
#define fox1r(k, x) for (int k=x; k>0; --k)
#define ms multiset
#define flood(x) memset(x, 0x3f3f3f3f, sizeof x)
#define drain(x) memset(x, 0, sizeof x)
#define rng() ((rand() << 14)+rand())
#define scan(X) do{while((X=getchar())<'0'); for(X-='0'; '0'<=(_=getchar()); X=(X<<3)+(X<<1)+_-'0');}while(0)
char _;
#define pi 3.14159265358979323846

int n, a, b, P;
ll ans, c;
multiset<pii> s, t, u, v;
bool f;
pii p;
int main() {
	cin >> n;
	fox(l, n){
		scanf("%i%i", &a, &b);
		u.insert(mp(b, a));
		v.insert(mp(-a, -b));
	}
	s=u;
	t=v;
	f=0;
	while(s.size()){
		if (f){
			p=*t.begin();
			a=-p.x; b=-p.y;
			if (a<P) break;
			s.erase(s.lb(mp(b, a)));
			t.erase(t.begin());
			c+=a-P;
			P=a;
		} else {
			p=*s.begin();
			a=p.y; b=p.x;
			if (b>P) break;
			t.erase(t.lb(mp(-a, -b)));
			s.erase(s.begin());
			c+=P-b;
			P=b;
		}
		f=!f;
		//cout << P << ' ' << c << endl;
	}
	c+=abs(P);
	ans=c;
	s=u;
	t=v;
	f=1;
	c=0;
	P=0;
	while(s.size()){
		if (f){
			p=*t.begin();
			a=-p.x; b=-p.y;
			if (a<P) break;
			s.erase(s.lb(mp(b, a)));
			t.erase(t.begin());
			c+=a-P;
			P=a;
		} else {
			p=*s.begin();
			a=p.y; b=p.x;
			if (b>P) break;
			t.erase(t.lb(mp(-a, -b)));
			s.erase(s.begin());
			c+=P-b;
			P=b;
		}
		f=!f;
	}
	c+=abs(P);
	//cout << ans << ' ' << c << endl;
	printf("%lli\n", max(ans, c));
	return 0;
}

Measured memory_bytes: 18944
#pragma target("avx")
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using V = std::vector<ll>;
template<typename T> using pq = std::priority_queue<T>;
template<typename T> using rpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

#define rep(i,b,e) for(ll i=b; i<e; i++)
#define be(vec) vec.begin(),vec.end()
#define print(vec) printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");
#define scan(vec) for(auto &i:vec)scanf("%ld",&i)
#define fi first
#define se second

const int MOD = 1e9+7;
const ll INF = 1e18;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

template<typename T>
struct Segtree{
        using F = std::function<T(T,T)>;
        std::vector<T> seg;
        int size=1;
        T unit;
        F func;

        Segtree(int n, const T &u, const F f): unit(u), func(f) {
                while(size<n) size <<= 1;
                seg.assign(2*size-1, unit);
        }

        void update(int idx, const T &x){
                idx += size-1;
                seg[idx] = x;
                while(idx>0){
                        idx = (idx-1) / 2;
                        seg[idx] = func(seg[2*idx+1], seg[2*idx+2]);
                }
        }

        T query(int a, int b, int k=0, int l=0, int r=-1){
                if(r<0) r = size;
                if(b<=l or r<=a) return unit;
                if(a<=l and r<=b) return seg[k];
                return func(query(a,b, 2*k+1, l,(l+r)/2), query(a,b, 2*k+2, (l+r)/2,r));
        }

        T operator[](const int &i) const {return seg[size-1+i];}
};

int main(){
	int n, q;
	scanf("%d", &n);
	std::vector<Segtree<ll>> seg(26, Segtree<ll>(n, 0, [](ll a, ll b){return a+b;}));
	char s[n];
	getchar();
	rep(i, 0, n){
		s[i] = getchar();
		seg[s[i]-'a'].update(i, 1);
	}
	getchar();
	scanf("%d", &q);
	while(q--){
		int t;
		scanf("%d", &t);
		if(t==1){
			int i;
			char c;
			scanf("%d %c", &i, &c);
			seg[s[i-1]-'a'].update(i-1, 0);
			seg[c-'a'].update(i-1, 1);
			s[i-1] = c;
		}else{
			int l, r;
			scanf("%d %d", &l, &r);
			ll ans = 0;
			rep(i, 0, 26) ans += (seg[i].query(l-1, r) > 0);
			printf("%ld\n", ans);
		}
	}
	return 0;
}


Measured memory_bytes: 221568
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#define LEN 100005
#define MAX 100000    //?

typedef struct pp{
    char name[100];
    int t;
}P;

P Q[LEN+1];

int head, tail, n;
//int MAX;

void initialize(){
    head = tail = 0;
}

int isEmpty(){
    if(head == tail) return 1;
    else return 0;
}

int isFull(){
    if(head == (tail + 1) % MAX) return 1;
    else return 0;
}

void enqueue(P x){
    if(isFull()) printf("エラー（オーバーフロー）");
    Q[tail] = x;
    if(tail + 1 == MAX){
        tail = 0;
    }else{
        tail++;
    }
}

P dequeue(){
    P x;
    if(isEmpty()) printf("エラー（アンダーフロー）");
    x = Q[head];
    if(head + 1 == MAX){
        head = 0;
    }else{
        head++;
    }
    return x;
}


int main(){
    initialize();
    int elaps = 0, c; //elaps:時の経過
    int i, q;
    P u;
    
    scanf("%d %d", &n, &q);
    for (i=1; i<=n; i++){
        scanf("%s", Q[i].name);
        scanf("%d", &Q[i].t);
        enqueue(Q[i]);
    }
    //MAX=n;
    
    while(1){
        u = dequeue();
        if(q < u.t){
            elaps += q;
            u.t -= q; 
            enqueue(u);
        }else if(q >= u.t){// >=でないとダメ
            elaps += u.t;
            printf("%s %d\n", u.name, elaps);
        }
       // printf("%s %d\n", u.name, elaps);
        //if(Q[i].t == 0) printf("%s %d\n", u.name, elaps);
        if(isEmpty()) break;
    }
    return 0;
}


Measured memory_bytes: 11828
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
#define ci(n,a)   vi a(n); rep(i,(n)) cin>>a[i];
#define rep(i,n)  for(ll i = 0; i < (n); ++i)
#define red(i,n)  for(ll i = (n)-1; i >= 0; --i)
#define all(a)    begin(a),end(a)
#define pb(a)     push_back(a)
#define mp(a,b)   make_pair(a,b)
#define yn(a)     cout << ( (a)?"Yes\n":"No\n" )
inline ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }
ll INF = 1e9+7, LINF = 1e18;


int main(int argc,char* argv[])
{
    string s,a;
    cin>>s;
    vi q;
    q.pb(0);
    rep(i,s.size()){
        if(s[i]=='A'||s[i]=='T'||s[i]=='C'||s[i]=='G') a+=s[i];
        else q.pb(a.size()),a="";
        if(i==s.size()-1)q.pb(a.size()),a="";
    }
    sort(all(q));
    reverse(all(q));
    cout<<q[0]<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

VVI C;
vector<vector<bool>> used;
int MH, MW;
int dh[] = {0, 0, -1, 1, -1, -1, 1, 1};
int dw[] = {-1, 1, 0, 0, -1, 1, -1, 1};
bool inside(int h, int w) {
    return 0 <= h && h < MH && 0 <= w && w < MW;
}
bool dfs(int h, int w) {
    if (used[h][w]) return false;
    used[h][w] = true;
    REP(i, 8) {
        int nh = h + dh[i], nw = w + dw[i];
        if (!inside(nh, nw)) continue;
        if (C[nh][nw] == 1) dfs(nh, nw);
    }
    return true;
}
void solve(int w, int h) {
    MH = h; MW = w;
    C.resize(h, VI(w));
    used.resize(h, vector<bool>(w, false));
    REP(i, h)REP(j, w) cin >> C[i][j];
    int cnt = 0;
    REP(i, h)REP(j, w) {
        if (C[i][j] == 1) cnt += dfs(i, j);
    }
    cout << cnt << endl;
    used.clear();
    C.clear();
    return;
}

int main(void) {
    int n, p, m, w, h;
    string s;
    int a, b, c;
    while (cin >> w >> h) {
        if (w == 0 && h == 0) return 0;
        solve(w, h);
        //return 0;
    }
}

Measured memory_bytes: 3128
a,b,c=map(int,input().split())
d,e,f=map(int,input().split())
g,h,i=map(int,input().split())

z1=[]
z2=[]
z3=[]
z4=[]
z5=[]
z6=[]
z7=[]
z8=[]
z1.append(a)
z1.append(b)
z1.append(c)

z2.append(d)
z2.append(e)
z2.append(f)

z3.append(g)
z3.append(h)
z3.append(i)

z4.append(a)
z4.append(d)
z4.append(g)

z5.append(b)
z5.append(e)
z5.append(h)

z6.append(c)
z6.append(f)
z6.append(i)

z7.append(a)
z7.append(e)
z7.append(i)

z8.append(c)
z8.append(e)
z8.append(g)

n=int(input())
for i in range(n):
    x=int(input())
    if x in z1:z1.remove(x)
    if x in z2:z2.remove(x)
    if x in z3:z3.remove(x)
    if x in z4:z4.remove(x)
    if x in z5:z5.remove(x)
    if x in z6:z6.remove(x)
    if x in z7:z7.remove(x)
    if x in z8:z8.remove(x)

if len(z1)==0 or len(z2)==0 or len(z3)==0 or len(z4)==0 or len(z5)==0 or len(z6)==0 or len(z7)==0 or len(z8)==0:
    print("Yes")
else:
    print("No")
       

Measured memory_bytes: 38256
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>

#ifndef ULLONG
typedef unsigned long long ULLONG;
#endif
#ifndef LLONG
typedef long long LLONG;
#endif
static const ULLONG UL_HUGE_DIVIDER = 1000000007LLU;
static const LLONG LL_HUGE_DIVIDER = 1000000007LL;

//static void ABC111D_RobotArms();
static void ABC110D_Factorization();

#if 1
int main()
{
	//ABC111D_RobotArms();
	ABC110D_Factorization();

	fflush(stdout);
	return 0;
}
#endif


//	素因数分解した結果を map で返す
template <class _Ty> void tp_getPrimes(_Ty targ, std::map<_Ty, _Ty>& primes)
{
	_Ty target = targ;
	_Ty i = 2;
	while ((i * i) <= target) {
		if ((target % i) == 0) {
			target /= i;

			if (primes.find(i) == primes.end()) {
				primes[i] = 1;
			}
			else {
				primes[i] = primes[i] + 1;
			}
		}
		else {
			i++;
		}
	}
	if (target == 1) {
		//	なにもしない
	}
	else if (primes.find(target) == primes.end()) {
		primes[target] = 1;
	}
	else {
		primes[target] = primes[target] + 1;
	}


#if 0
	printf("Target: %d equals\n", targ);
	for (auto it = primes.begin(); it != primes.end(); it++) {
		printf("%d ^ %d\n", it->first, it->second);
	}
#endif
}

template <class _Ty> class PermComb
{
protected:

	_Ty _maxNum = 0;
	_Ty _use_mod = 0;
	_Ty* _fact = 0;
	_Ty* _inv = 0;
	_Ty* _finv = 0;

	PermComb(){}

public:
	PermComb(_Ty maxNum, _Ty use_mod = 0) {
		_maxNum = maxNum;
		_use_mod = use_mod;
		_fact = new _Ty[(unsigned int)maxNum + 1];
		_fact[0] = _fact[1] = 1;

		if (_use_mod) {
			_inv = new _Ty[(unsigned int)maxNum + 1];
			_finv = new _Ty[(unsigned int)maxNum + 1];
			_inv[0] = _inv[1] = 1;
			_finv[0] = _finv[1] = 1;
		}

		for (_Ty i = 2; i <= maxNum; i++) {
			_fact[i] = _fact[i - 1] * i;
			if (_use_mod) {
				_fact[i] %= _use_mod;
				_inv[i] = _use_mod - _inv[_use_mod % i] * (_use_mod / i) % _use_mod;
				_finv[i] = _finv[i - 1] * _inv[i] % _use_mod;
			}
		}
	}

	//	get permutation value
	virtual _Ty GetPermAns(int n, int k) {
		if ((k > _maxNum) || (n > _maxNum) || (k > n) || (k < 0) || (n < 0)) {
			return 0;
		}
		return(_fact[n] / _fact[n - k]);
	}

	//	get combination value
	virtual _Ty GetCombAns(int n, int k) {
		_Ty ans = 0;
		if ((k > _maxNum) || (n > _maxNum) || (k > n) || (k < 0) || (n < 0)) {
			ans = 0;
		}
		else if (_use_mod == 0) {
			ans = GetPermAns(n, k);
			ans /= _fact[k];
		}
		else {
			ans = _fact[n] * (_finv[k] * _finv[n - k] % _use_mod) % _use_mod;
		}
		return ans;
	}

	//	destructor
	~PermComb() {
		delete[] _fact; 
		delete[] _inv;
		delete[] _finv;
	}
};

static void ABC110D_Factorization() 
{
	int N, M;
	scanf(" %d %d", &N, &M);

	std::map<int, int> primes;
	tp_getPrimes<int>(M, primes);

	LLONG expSum = 0;
	for (auto prIt = primes.begin(); prIt != primes.end(); prIt++) {
		expSum += prIt->second;
	}
	
	PermComb<LLONG> calc(((LLONG)expSum + N), LL_HUGE_DIVIDER);

	//	N - 1個の仕切りとexpSum 個の次数から N - 1 個選ぶ
	LLONG ans = 1;
	for (auto prIt = primes.begin(); prIt != primes.end(); prIt++) {
		LLONG tmp = calc.GetCombAns(prIt->second + (N - 1), (N - 1));
		ans = ans * tmp % LL_HUGE_DIVIDER;
	}

	printf("%lld\n", ans);
}


Measured memory_bytes: 2560
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    void input() {

    }

    void solve() {
        input();
        while (true) {
            int n, x;
            cin >> n >> x;
            if(n == 0 && x == 0) break;
            int ans = 0;
            for(int i = 1; i <= n; ++i){
                for(int j = i + 1; j <= n; ++j){
                    for(int k = j + 1; k <= n; ++k){
                        if(i + j + k == x) ans++;
                    }
                }
            }
            cout << ans << endl;
        }

    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}



Measured memory_bytes: 3116
//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60) 
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

signed main(void)
{
    while(true) {
        int n, w, d;
        cin >> n >> w >> d;
        if(!n && !w && !d) break;

        int cnt = 1;
        PII a[105];
        a[1] = {w, d};
        REP(i, n) {
            int p, s;
            cin >> p >> s;
            
            //cout << a[p].first << " " << a[p].second << endl;
            s %= 2*(a[p].first+a[p].second);
            PII t1, t2;
            if(s < a[p].first) {
                t1 = {s, a[p].second};
                t2 = {a[p].first-s, a[p].second};
                //cout << "a" << endl;
            } else if(s < a[p].first+a[p].second) {
                s -= a[p].first;
                t1 = {a[p].first, s};
                t2 = {a[p].first, a[p].second-s};
               // cout << "b" << endl;
            } else if(s < 2*a[p].first+a[p].second) {
                s -= a[p].first+a[p].second;
                t1 = {s, a[p].second};
                t2 = {a[p].first-s, a[p].second};
                //cout << "c" << endl;
            } else {
                s -= 2*a[p].first+a[p].second;
                t1 = {a[p].first, s};
                t2 = {a[p].first, a[p].second-s};
                //cout << "d" << endl;
            }
            FOR(j, p, cnt) {
                a[j] = a[j+1];
            }
            if(t1.first*t1.second < t2.first*t2.second) {
                a[cnt] = t1;
                a[cnt+1] = t2;
            } else {
                a[cnt] = t2;
                a[cnt+1] = t1;
            }
            //FOR(j, 1, cnt+2) cout << "(" << a[j].first << ", " << a[j].second << ")"; cout << endl;
            cnt++;
        }
        VI b;
        FOR(i, 1, cnt+1) {
            b.PB(a[i].first*a[i].second);
        }
        sort(ALL(b));
        REP(i, b.size()) {
            cout << b[i];
            if(i != b.size()-1) cout << " ";
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 3032
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(a+b==c||b+c==a||a+c==b){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f(i,n) for(int i=0;i<(n);i++)
#define P pair<int,int>
#define LONG LLONG_MAX/3;
#define INT INT_MAX/3;
#define mod 1000000007
#define S second
#define F first
#define int long long
typedef long long ll;
using namespace std;
int gcd(int c,int b){
	if(b==0) return c;
	return gcd(b,c%b);
}
int a[100010];
signed main(){
	int n,ans;
	cin>>n;
	f(i,n+1){
		cin>>a[i];
	}
	sort(a,a+n+1);
	f(i,n){
		a[i+1]-=a[0];
	}
	f(i,n-1){
		if(i) ans=gcd(ans,a[i+2]);
		else ans=gcd(a[i+1],a[i+2]);
	}
	if(n==1) cout<<a[1]<<endl;
	else cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1024
void main() {
  import std.stdio, std.string, std.conv, std.algorithm;

  int n, m;
  rd(n, m);

  int[] a;
  for (int i = 2; i * i <= m; i++) {
    if (m % i == 0) {
      int cnt = 0;
      while (m % i == 0) {
        cnt++;
        m /= i;
      }
      a ~= cnt;
    }
  }
  if (m > 1) {
    a ~= 1;
  }

  const long mod = 10 ^^ 9 + 7;
  const size_t M = 10 ^^ 5 * 2;
  static long[M] fac, inv;
  { // init
    fac[0] = fac[1] = 1;
    foreach (i; 2 .. M)
      fac[i] = i * fac[i - 1] % mod;
    long _pow(long a, long x) {
      if (x == 0)
        return 1;
      else if (x == 1)
        return a;
      else if (x & 1)
        return a * _pow(a, x - 1) % mod;
      else
        return _pow(a * a % mod, x / 2);
    }

    foreach (i; 0 .. M)
      inv[i] = _pow(fac[i], mod - 2);
  }
  long cmb(long nn, long rr) {
    if (nn < rr)
      return 0;
    return fac[nn] * inv[rr] % mod * inv[nn - rr] % mod;
  }

  long tot = 1;
  foreach (e; a) {
    (tot *= cmb(e + n - 1, e)) %= mod;
  }
  writeln(tot);
}

void rd(T...)(ref T x) {
  import std.stdio, std.string, std.conv;

  auto l = readln.split;
  assert(l.length == x.length);
  foreach (i, ref e; x)
    e = l[i].to!(typeof(e));
}


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

int main () {
	int n, m;
	int sum = 0;
	int p[100000];

	cin >> n >> m;
	for (int i=0; i<n; i++)
		p[i] = -1;

	for (int i=0; i<m; i++) {
		int pi;
		string s;
		cin >> pi >> s;
		pi --;
		if (s=="WA" && p[pi]<0)
			p[pi] --;
		if (s=="AC" && p[pi]<0) {
			p[pi] = -p[pi] - 1;
			sum ++;
		}
	}

	int w = 0;
	for (int i=0; i<n; i++)
		if (p[i] > 0)
			w += p[i];

	cout << sum << " " << w << endl;
	return 0;
}

Measured memory_bytes: 640
import sys
from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """1 3"""
        output = """3"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """0 1"""
        output = """0"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """32 21"""
        output = """58"""
        self.assertIO(input, output)
def resolve():
    (A,P)=(int(i) for i in input().split())
    print(int((A*3+P)/2))
if __name__ == "__main__":
    resolve()



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

n = int(input())
a = list(map(int, input().split()))

def gcd(x,y):
  while y:
    x, y = y, x%y
  return x

ll, lr = [0]*n, [0]*n
ll[0], lr[n-1] = a[0], a[n-1]
for i in range(1,n):
  ll[i] = gcd(ll[i-1], a[i])
  lr[n-i-1] = gcd(lr[n-i], a[n-i-1])

print(max(ll[n-2], lr[1], *[gcd(l,r) for l,r in zip(ll[:n-2], lr[2:])]))

Measured memory_bytes: 14488
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define ll long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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; }

signed main() {
	int N, Y;
	cin >> N >> Y;
	for (int i = 0; i <= N; i++) {
		for (int j = 0; j <= N - i; j++) {
			int k = N - i - j;
			int sum = 10000 * i + 5000 * j + 1000 * k;
			if (sum == Y) {
				cout << i << " " << j << " " << k;
				return 0;
			}
		}
	}
	cout << -1 << " " << -1 << " " << -1;
}

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

int main(){
    int cnt = 0, N, M, A;
    cin >> N >> M;
    for (int i = 0; i < M; i++){
        cin >> A;
        cnt += A;
    }
    if(N < cnt) cout << "-1" << endl;
    else cout << N - cnt << endl;
    return 0;
}

Measured memory_bytes: 3600