akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <map>
using namespace std;


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

    vector<int> P(N);
    for (int i = 0; i < N; ++i){
        cin >> P.at(i);
    }

    int ans = 0;
    int currentMin = 1e9;
    for (int i = 0; i < N; ++i){
        currentMin = min(currentMin, P.at(i));
        if(currentMin == P.at(i)){
            ans++;
        }
    }

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

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

int main(){
  string s; cin>>s;
  if(s.at(0)=='0'&&s.at(1)!='0'
    ||s.at(0)=='1'&&s.at(1)=='0'
    ||s.at(0)=='1'&&s.at(1)=='1'
    ||s.at(0)=='1'&&s.at(1)=='2'){
    
    if(s.at(2)=='0'&&s.at(3)!='0'
    ||s.at(2)=='1'&&s.at(3)=='0'
    ||s.at(2)=='1'&&s.at(3)=='1'
    ||s.at(2)=='1'&&s.at(3)=='2'){
      cout<<"AMBIGUOUS";}
    else{cout<<"MMYY";}
  }
  else if(s.at(2)=='0'&&s.at(3)!='0'
    ||s.at(2)=='1'&&s.at(3)=='0'
    ||s.at(2)=='1'&&s.at(3)=='1'
    ||s.at(2)=='1'&&s.at(3)=='2'){
    cout<<"YYMM";}
  else{cout<<"NA";}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int const nax = 4e5 + 10;
int n, k , c;
char s[nax];

bool work[nax];

int dp[nax];
int dp2[nax];

int pref[nax];
int suf[nax];
int ex[nax];

int w[nax];

int main () {
    scanf("%d %d %d", &n, &k, &c);
    scanf("%s", s + 1);

    for (int i = 1 ;  i <= n ; ++ i)
        work[i] = s[i] == 'o';


    for (int i = 1 ; i <= n ; ++ i) {
        if (s[i] == 'o') {
            int last = i - c - 1;
            int toAdd = 0;
            if (last > 0) toAdd = max(toAdd, pref[last]);
            dp[i] = toAdd + 1;
        }

        pref[i] = max(pref[i - 1], dp[i]);
    }

    for (int i = n ; i >= 1 ; -- i) {
        if (s[i] == 'o') {
            int nxt = i + c + 1;
            dp2[i] = 1 + suf[nxt];
        }

        suf[i] = max(suf[i + 1], dp2[i]);
    }

    deque<pair<int, int>> d;

  /*  for (int i = 1 ; i <= n ; ++ i)
        fprintf(stderr, "%d ", pref[i]);

    fprintf(stderr, "\n");

    for (int i = 1 ; i <= n ; ++ i)
        fprintf(stderr, "%d ", suf[i]);
    fprintf(stderr, "\n");*/


    for (int i = 1 ; i <= n ; ++ i) {

        while (!d.empty() && c + d.front().first + 1  <= i) d.pop_front();
        int h = d.empty() ? 0 : d.front().second;

       // if (i == 5) fprintf(stderr, "huh %d %d\n", d.front().first, d.front().second);

        h = max(h, suf[i + 1] + pref[max(0, i - c - 1)]);



        if (s[i] == 'o') {
            while (!d.empty() && d.front().second <= dp[i] + suf[i + c + 1]) d.pop_back();
            d.emplace_back(i, dp[i] + suf[i + c + 1]);
        }

       // fprintf(stderr, "%d ", h);
        if (s[i] == 'o' && h < k) printf("%d\n", i);


    }

    fprintf(stderr, "\n");

}
/*
    Good Luck
        -Lucina
*/


Measured memory_bytes: 8448
// Problem : D - Floor Function
// Contest : AtCoder - AtCoder Beginner Contest 165
// URL : https://atcoder.jp/contests/abc165/tasks/abc165_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
ordered_set;	

#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, int> para;
const ll inf = 1e18 + 7;
const ll maxN = 1e6 + 5;
const ll MOD = 1e9 + 7;

// sprawdz MODULO!
int main() {
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	ll a, b, n;
	cin >> a >> b >> n;
	if (n < b) {
		cout << (n * a) / b << endl;
	} else {
		cout << ((b - 1) * a) / b << endl;
	}
	return 0;
}
 


Measured memory_bytes: 3584
#include "bits/stdc++.h"

//region Template
#include "ext/pb_ds/assoc_container.hpp"

using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const int MOD = 1000000007;
using namespace std;
#define finish(x) cout << x; exit(0);
#define fastIO cin.tie(0); cin.sync_with_stdio(false);

void setIn(string s) { freopen(s.c_str(), "r", stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }

//const string USCAO_TAG = "mountains";
void usaco(const string& USACO_TAG) { setIn(USACO_TAG + ".in"); setOut(USACO_TAG + ".out"); }
/*
template<typename... Args>
void print(Args... args) {
	#ifdef LOCAL
	((std::cout << args << " "), ...);
	cout << endl;
	#endif
}
 */
//endregion

/* Notes:
 * Farah </3
 */

const int MAXN = 1e5 + 5;
const int INF = 2e9;


int main() {
	//usaco("milkvisits");

#ifdef LOCAL
	setIn("in.txt");
	setOut("out.txt");
#endif

	int n;
	cin >> n;

	int exp = 1;
	ll ans = 0;
	for(int i = 0; i < n; i++){
		int t;
		cin >> t;

		if(t != exp){
			ans++;
		}
		else{
			exp++;
		}
	}

	if(ans == n) cout << -1;
	else
		cout << ans;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>

int main(){
    string A,B;
    cin>>A>>B;
    int numA = stoi(A);
    int numB = stoi(B);
    ll ans=0;
    rep(i,numA,numB+1){
        A = to_string(i);
        if(A[0]==A[4]&&A[1]==A[3])ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
A = list(input().split())
for i in range(n):
    A[i] = int(A[i])
m = int(input())
B = list(input().split())
for i in range(m):
    B[i] = int(B[i])

def solve(x,y):
    if x==n:
        S[y] = 1
    else:
        solve(x+1,y)
        if y+A[x] < 2001:
            solve(x+1,y+A[x])
            
S = [0 for i in range(2001)]

solve(0,0)
    
for i in range(m):
    if S[B[i]] == 1:
        print("yes")
    else:
        print("no")




Measured memory_bytes: 5636
#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() {
    int n, r;
    cin >> n >> r;
    int ans;
    if (n >= 10) ans = r;
    else ans = r + 1000 - 100*n;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cassert>
#include <queue>


using namespace std;

using ll = long long;

ll NAX = 2e5;

struct ST {
  vector<ll> t;
  ST() {
    t.assign(NAX*4+10, 0);
  }


  void build(ll root, ll l, ll r, vector<pair<ll,ll>> & ACid) {
    if (l > r) return ;

    if (l==r) {
      // cout << l << endl;
      if (ACid[l].second < 0) t[root] = 1;
      else t[root] = 0;
      return ;
    }

    ll m = (l + r) / 2;

    build(root*2, l, m, ACid);
    build(root*2+1, m+1, r, ACid);

    t[root] = t[root*2] + t[root*2+1];
  }

  ll sum(ll root, ll l, ll r, vector<pair<ll,ll>> &ACid) {
    if (t[root] == 0) return 0;
    if (l > r) return 0;

    if (l==r) {
      return t[root] * ACid[l].first;
    }

    ll m = (l + r) / 2;

    return sum(root*2, l, m, ACid) +  sum(root*2+1, m+1, r, ACid);
  }
  void add(ll root, ll pos, ll count, ll l, ll r) {
    if (l > r) return ;
    if (l == r && l == pos) {
      t[root] += count;
      return ;
    }


    if (t[root] == 0) {
      t[root*2] = 0;
      t[root*2+1] = 0;
    }

    ll m = (l + r) / 2;
    if (pos <= m) 
    add(root*2, pos, count, l, m);
    else
    add(root*2+1, pos, count, 1+ m, r);

    t[root] = t[root*2] + t[root*2+1];

  }

  void update(ll root, ll pos, ll maxc, ll l, ll r) {
    if (t[root] == 0) return ;
    if (maxc == 0 ) return ;
    if (l > r) return ;

    if (l == r) {
      t[root] = max(0LL, t[root] - maxc);
      return ;
    }

    ll m = (l+ r) / 2;

    if (pos  <= m) {
        update(2*root, pos, maxc, l, m);
    } else {
      if (t[root*2] <= maxc) {
        update(2*root+1, pos, maxc-t[root*2], m+1, r);
        t[root*2] = 0;
      } else {
        update(2*root, pos, maxc, l, m);
      }
    }
    t[root] = t[root*2] + t[root*2+1];
  }

  ll query();
};

int main() {
  ll N, M;

  cin >> N >> M;
  vector<ll> A(N);
  vector<pair<ll,ll>> ACid(N+M);
  for(auto i=0;i<N;i++) {
    cin >> A[i];
    ACid[i].first = A[i];
    ACid[i].second = -i-1;
  }

  vector<ll> B(M);
  vector<ll> C(M);
  for(auto i=0;i<M;i++) {
    cin >> B[i] >> C[i];
    ACid[N+i].first = C[i];
    ACid[N+i].second = i+1;
  }

  sort(ACid.begin(), ACid.end());
  vector<ll> Cmap(M);
  for(auto i = 0; i<M+N; i++) {
    if (ACid[i].second > 0) //
    Cmap[ACid[i].second - 1] = i;
  }

  ST tree;
  tree.build(1, 0, N+M-1, ACid);
  // cout << tree.t[1] << endl;
  for (auto i=0; i<M;i++) {
    tree.update(1,  Cmap[i], B[i], 0, M+N-1);
    // cout << tree.t[1] << endl;
    tree.add(1,  Cmap[i], N-tree.t[1], 0, M+N-1);
    // cout << tree.t[1] << endl;
  }


  cout << tree.sum(1, 0, N+M-1, ACid) << endl;


  return 0;
}


Measured memory_bytes: 12800
#include<iostream>
#include<algorithm>

using namespace std;

int main()
{
	int size = 0;
	int K;
	int tile[1000];
	pair<int, int> Tplace[1000];

	cin >> size;
	cin >> K;

	for (int a = 0; a < K; a++)
	{
		cin >> Tplace[a].first >> Tplace[a].second;
	}

	for (int a = 0; a < K; a++)
	{
		tile[a] = min(min(Tplace[a].first, Tplace[a].second), min(1 + size - Tplace[a].first, 1 + size - Tplace[a].second)) % 3;
		if (tile[a] == 0)
		{
			tile[a] = 3;
		}
	}

	for (int a = 0; a < K; a++)
	{
		cout << tile[a] << endl;
	}

	return 0;
}

Measured memory_bytes: 1172
(defun splitat (c line)
  (labels ((rec (line acc)
				(let ((pos (position-if (lambda(cc) (char= c cc)) line)))
				  (if pos
					  (rec (subseq line (1+ pos)) (cons (subseq line 0 pos) acc))
					(nreverse (cons line acc))))))
	(rec line nil)))

(defun f(lst)
  (if (every (lambda(a) (or (zerop (mod a 3)) (zerop (mod a 5)))) (remove-if-not #'evenp lst)) "APPROVED" "DENIED")) 

(let* ((line0 (read-line nil nil))
       (line (mapcar #'parse-integer (splitat #\space (read-line nil nil)))))
  (format t "~A~%" (f line)))


Measured memory_bytes: 16100
N, *A = map(int, open(0).read().split())
ans = 10**30
for i in range(N):
  l = -1
  r = 10**30
  while l+1<r:
    s = (l+r)//2
    x = s*N+i
    m = sum((c+x-N+1+N)//(N+1) for c in A)
    if m>x:
      l = s
    else:
      r = s
  x = r*N+i
  m = sum((c+x-N+1+N)//(N+1) for c in A)
  if m==x:
    ans = min(ans,x)
print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

static const ll MAX = 100001;
vector <ll> out;
vector <ll> G[MAX];
vector <ll> inputG[MAX];
bool V[MAX] = {};
ll n;
ll indeg[MAX] = {};

void bfs(ll s){
    queue<ll> q;
    q.push(s);
    V[s] = true;
    while(!q.empty()){
        ll u = q.front();
        q.pop();
        out.push_back(u);
        for (ll i=0;i<G[u].size();i++){
            ll v = G[u][i];
            indeg[v]--;
            if(indeg[v] == 0  and !V[v]){
                V[v] = true;
                q.push(v);
            }
        }
    }
}
vector <ll> tsort(){
    for (ll u=1;u<=n;u++){
        for (ll i=0;i<G[u].size();i++){
            ll v = G[u][i];
            indeg[v]++;
        }
    }
    for (ll u=1;u<=n;u++){
        if(indeg[u] == 0 and !V[u]){
            bfs(u);
        }
    }
    return out;
}

int main(){
    

    ll m;
    cin >> n >> m;
    for (ll i=0;i<n+m-1;i++){
        ll a,b;
        cin >> a >> b;
        G[a].push_back(b);
        inputG[b].push_back(a);
    }

    vector <ll> v;
    v = tsort();

    ll pos[MAX] = {};
    ll parent = 0;
    ll par[MAX] = {};
//    for (ll i=0;i<n;i++){
//        cout << v[i] << endl;
//    }
    for (ll i=0;i<n;i++){
        pos[v[i]] = i;
    }
    for (ll i=0;i<n;i++){
        ll maxv,maxidx;
        for (ll k=0;k<inputG[v[i]].size();k++) {
            if(k==0){
                maxv = pos[inputG[v[i]][k]];
                maxidx = inputG[v[i]][k];
            }else{
                if(maxv < pos[inputG[v[i]][k]]){
                    maxv = pos[inputG[v[i]][k]];
                    maxidx = inputG[v[i]][k];
                }
            }
        }
        if(i==0){
            par[v[i]] = 0;
        }else {
            par[v[i]] = maxidx;
        }
    }
    for (ll i=1;i<=n;i++){
        cout << par[i] << endl;
    }
}


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

int main(void)
{
    long long a, b, c, k;
    cin >> a >> b >> c >> k;
    long long ans = a;
    if (k > a)
    {
        k -= a;
        if (k > b)
        {
            k -= b;
            ans -= k;
        }
    }
    else{
        ans = k;
    }
    cout << ans << endl;

    return 0;
}

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

#define froop1(a,n) for(int i = a;i < n;i++)
#define froop2(a,n) for(int i = a;i > n;i--)

#define ll long long

#define pq(name,type) priority_queue<type> name
#define vec(name,type,length,value) vector<type> name(length,value)
#define vec2(name,type,length,width,value) vector<vector<type>> name(length,vector<type>(width,value));

int main(){
	vector<ll> a(4);
  cin >> a.at(0) >> a.at(1) >> a.at(2) >> a.at(3);
  ll m;
  ll e,b,c,d;
  e = a.at(0)*a.at(2);
  b = a.at(1)*a.at(2);
  c = a.at(0)*a.at(3);
  d = a.at(1)*a.at(3);
  m = max(e,max(b,max(c,d)));
  cout << m << endl;
return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

int main() {
    int n;
    cin >> n;
    const int LIM = 100010;
    vector<int> left(LIM), right(LIM), ims(LIM);
    vector<P> v(n);
    for (int i = 0; i < n; ++i) {
        int a, b;
        cin >> a >> b;
        ++ims[a];
        --ims[b];
        ++left[a];
        ++right[b];
        v[i] = P(a, b);
    }
    int ans1 = 0, ans2 = 0;
    for (int i = 1; i < LIM; ++i) {
        ims[i] += ims[i - 1];
        left[i] += left[i - 1];
        right[i] += right[i - 1];
        ans2 = max(ans2, ims[i]);
    }
    for (P& i : v) ans1 = max(ans1, left[i.second - 1] - right[i.first]);
    cout << ans1 << " " << ans2 << "\n";
    return 0;
}



Measured memory_bytes: 5472
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e11;

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

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

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

bool isOK(map<char, ll> cnter, ll cnt, ll K, char c)
{
    if (cnt == K)
    {
        if (cnter[c] >= 1)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    else if (cnt == K - 1)
    {
        if (cnter[c] == 0)
        {
            return true;
        }
    }
    return false;
}
int main()
{
    ll N, K;
    cin >> N >> K;
    vector<ll> a(N);
    for (int i = 0; i < N; i++)
    {
        cin >> a[i];
    }
    ll ans = INF;
    for (int bit = 0; bit < (1 << N); bit++)
    {
        ll prev = -1;
        ll cost = 0;
        vector<ll> copy(N);
        copy = a;
        for (int i = 0; i < N; i++)
        {
            if (bit & (1 << i))
            {
                // i番目の建物を増築する
                if (copy[i] <= prev)
                {
                    cost += prev + 1 - copy[i];
                    copy[i] = prev + 1;
                    prev = copy[i];
                }
                else
                {
                    prev = copy[i];
                }
            }
            else
            {
                prev = max(prev, copy[i]);
            }
        }

        prev = -1;
        ll cnt = 0;
        for (int i = 0; i < N; i++)
        {
            if (prev < copy[i])
            {
                cnt++;
                prev = copy[i];
            }
        }
        if (K <= cnt)
        {
            ans = min(ans, cost);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=5005,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N,M,X;cin>>N>>M>>X;
    vector<int> cost(N);
    vector<vector<int>> skill(N,vector<int>(M));
    
    for(int i=0;i<N;i++){
        cin>>cost[i];
        for(int j=0;j<M;j++) cin>>skill[i][j];
    }
    
    int ans=INF;
    
    for(int bit=0;bit<(1<<N);bit++){
        vector<int> get(M);
        int s=0;
        for(int i=0;i<N;i++){
            if(bit&(1<<i)){
                for(int j=0;j<M;j++){
                    get[j]+=skill[i][j];
                }
                s+=cost[i];
            }
        }
        sort(all(get));
        if(get[0]>=X) chmin(ans,s);
    }
    
    if(ans==INF) ans=-1;
    cout<<ans<<endl;
}



Measured memory_bytes: 3676
use proconio::fastout;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
use std::cmp::min;

#[fastout]
fn main() {
    input! {
        n: usize,
        m: usize,
        x: usize,
    }

    let mut c = vec![];
    let mut a = vec![];

    for _ in 0..n {
        input! {
            ci: isize,
            ai: [usize; m],
        }
        c.push(ci);
        a.push(ai);
    }

    let mut cost = isize::max_value();
    for bits in 1..1 << n {
        let mut t_cost = 0;
        let mut skill = vec![0; m];
        for i in 0..n {
            if bits >> i & 1 == 1 {
                t_cost += c[i];
                for (s, ai) in skill.iter_mut().zip(a[i].iter()) {
                    *s += ai;
                }
            }
        }
        if skill.into_iter().all(|s| s >= x) {
            cost = min(cost, t_cost);
        }
    }
    println!("{}", if cost == isize::max_value() { -1 } else { cost })
}


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

int wa(int n){
    int res=0;
    while(n){
        res+=n%10;
        n/=10;
    }
    return res;
}
int main(){
    int n,a,b;
    cin >> n >> a >> b;
    int ans=0;
    rep(i,n+1){
        if(a>wa(i) or b<wa(i))continue;
        ans+=i;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
package main 
 
import (
  "bufio"
  "fmt"
  "os"
  "strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
    sc.Scan()
    i, e := strconv.Atoi(sc.Text())
    if e != nil {
        panic(e)
    }
    return i
}

func main() {
    sc.Split(bufio.ScanWords)
    s := nextInt()
    w := nextInt()
    
    if s > w {
	   fmt.Println("safe")
    } else { 
       fmt.Println("unsafe")
	}
}


Measured memory_bytes: 1760
#include<bits/stdc++.h>
using namespace std;
     
#define ll long long
#define loop(i,a,n) for(ll i=a;i<n;++i)
#define revloop(i,a,b) for(ll i=a;i>=b;--i)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define INF 99999999999999999
#define MOD 1000000000

void func()
{
    ll n;
    cin>>n;
    ll d=n%10;
    if(d==3){
        cout<<"bon"<<"\n";
    }
    else if(d==2||d==4||d==5||d==7||d==9){
        cout<<"hon"<<"\n";
    }
    else{
        cout<<"pon"<<"\n";
    }
}

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

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w" , stdout);
    #endif

    ll t=1;
    //cin>>t;
    while(t--)
    {
        func();
    }
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll dp[100005];
ll nums[100005];

int main(){
    int n;
    scanf(" %d",&n);
    for(int i = 0; i < n;++i) scanf(" %lld",&nums[i]);
    for(int i = 1; i < n;++i){
        dp[i] = abs(nums[i]-nums[i-1]) + dp[i-1];
        if(i > 1) dp[i] = min(dp[i],abs(nums[i]-nums[i-2])+ dp[i-2]);
    }
    printf("%lld\n",dp[n-1]);
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

int main() {
    string s;
    cin >> s;
    char pre = 'u';
    for(int i = 0; i < s.size(); i++) {
        if (s[i] == pre) {
            cout << "Bad" << endl;
            return 0;
        }
        pre = s[i];
    }
    cout << "Good" << endl;
    return 0;
}



Measured memory_bytes: 256
import java.util.*;
import java.io.*;
 
public class Main implements Runnable{
    static Scanner sc = new Scanner(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) throws IOException{
        new Thread(null, new Main(), "", 32 * 1024 * 1024).start();
        Thread.setDefaultUncaughtExceptionHandler((t,e)->System.exit(1));
        out.flush();
    }
    public void run() {
        int S = Integer.parseInt(sc.next());
        int W = Integer.parseInt(sc.next());
        if(S <= W){
            System.out.println("unsafe");
        }else{
            System.out.println("safe");
        }
    }
} 

Measured memory_bytes: 35872
#include<bits/stdc++.h>
using namespace std;
int main(){
  string str;
  cin >> str;
  string t = "keyence";
  if(str == t){
    cout << "YES" << endl;
    return 0;
  }
  int n = str.size();
  for(int i = 0; i < n; i++){
    for(int j = i; j < n; j++){
      string S = "";
      for(int k = 0; k < n; k++){
        if(i <= k && k <= j) continue;
        else S.push_back(str[k]);
      }
      if(S == t){
        cout << "YES" << endl;
        return 0;
      }
    }
  }
  cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 256
using System;

namespace v0_0005
{
    class Program
    {
        static void Main(string[] args)
        {
            string line;
            while (!string.IsNullOrEmpty(line = Console.ReadLine()))
            {
                var ab = line.Split(' ');
                var a = int.Parse(ab[0]);
                var b = int.Parse(ab[1]);
                int LCM = 1;
                int GCD = 1;

                int divVal;
                while ((divVal = GetDivisor(a, b)) != -1)
                {
                    a /= divVal;
                    b /= divVal;
                    GCD *= divVal;
                }
                LCM = GCD * a * b;

                Console.WriteLine("{0} {1}", GCD, LCM);
            }
        }

        static int GetDivisor(int a, int b)
        {
            if ((a % 2 == 0) && (b % 2 == 0)) { return 2; }
            for (int i = 3; i <= Math.Min(a, b); i += 2)
            {
                if ((a % i == 0) && (b % i == 0))
                {
                    return i;
                }
            }
            return -1;
        }
    }
}

Measured memory_bytes: 8952
fn read<T: std::str::FromStr>() -> T
{
    std::io::Read::bytes(std::io::stdin())
                    .map(|c| c.unwrap() as char)
                    .skip_while(|c| c.is_whitespace())
                    .take_while(|c| !c.is_whitespace())
                    .collect::<String>()
                    .parse().ok().unwrap()
}

fn main() {
    let n: usize = read();

    let mut prev: i64 = read();
    if prev != 0 {
        println!("-1");
        return;
    }

    let mut ans: i64 = 0;
    for _ in 1..n {
        let num: i64 = read();
        let d = num - prev;
        if d > 1 {
            println!("-1");
            return;
        } else if d == 1 {
            ans += 1;
        } else {
            ans += num;
        }

        prev = num;
    }

    println!("{}", ans);
}


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

using namespace std;

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

	int w,a,b;

	cin >> w >> a >> b;

	if((a<=b && b<=a+w) || (b<=a && a<=b+w))
	{
		cout << 0 << '\n';
	}
	else
	{
		if(a > b)
		{
			cout << abs(b+w - a) << '\n';
		}
		else
		{
			cout << abs(a+w - b) << '\n';
		}
	}
	return 0;
}


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

using namespace std;

const int N = 1e5 + 8;
int a , b , n , m;
vector <int> nei[N] , ans;
bool mark[N];

void dfs(int v)
{
	mark[v] = 1;
	ans.push_back(v);
	for(int u : nei[v])
		if(!mark[u])
			return dfs(u);
}

int main()
{
	ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
	cin >> n >> m;
	for(int i = 0 ; i < m ; i++)
	{
		cin >> a >> b;
		a-- , b--;
		nei[a].push_back(b);
		nei[b].push_back(a);
	}
	dfs(0);
	reverse(ans.begin() , ans.end());
	ans.pop_back();
	dfs(0);
	cout << ans.size() << endl;
	for(int j : ans)
		cout << j + 1 << " ";
}

Measured memory_bytes: 9720
n = int(input())
count = [0]
cur = 0
data = list(map(int, input().split()))
for i,v in enumerate(data):
  count[-1] += 1
  if v < 2*(i-cur)+1:
    cur += 1
    count.append(0)
res = 1
cur = 1
for i in range(n):
  cur -= 1
  if count: cur += count.pop(0)
  res *= cur
  res %= 1000000007
print(res)


Measured memory_bytes: 14364
#include<bits/stdc++.h>
using namespace std;
#define ld long double
#define lli long long int
#define vi vector<int>
#define vlli vector<lli>
#define vvi vector<vi >
#define str string
#define vs vector<str>
#define vb vector<bool>
#define slli set<lli>
#define mii map<int, int>
#define mlli map<int, lli>
#define msi map<str, int>
#define mp make_pair
#define pii pair<int, int>
#define pll pair<lli, lli>
#define vpii vector<pii >
#define vpll vector<pll >
#define pb push_back
#define loop(i, s, l, j) for(int i = s; i < l; i += j)
#define rloop(i, s, l, j) for(int i = s; i >= l; i -= j)
#define rep(i, n) loop(i,0,n,1)
#define rrep(i, n) rloop(i,n-1,0,1) 
#define fastio() ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ft first
#define sd second   
#define mit mii::iterator
#define vit vi::iterator
#define all(a) a.begin(),a.end()
#define min3(a, b, c) min(a, min(b, c))
#define mod 1000000007
#define inf 10000000000000000
#define limit 200005
/**********************************************************************************************************************************************/
int dx4[4] = {0, -1, 0, 1};
int dy4[4] = {1, 0, -1, 0};
int dx8[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
int dy8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int Power(int base,int exp){int ans=1;  while(exp > 0){if(exp&1)ans=(1LL*ans*base)%mod; exp=exp>>1; base=(1LL*base*base)%mod;}  return ans;}
/**********************************************************************************************************************************************/ 
void input()
{
	int n;
	cin >> n;
	
	vlli a(n);
	rep(i,n)
	{
		str s;
		cin >> s;

		int j = -1;

		str s1 = "", s2 = "";
		rep(ii,(int)s.length())
		{
			if(s[ii] == '.')
			{
				j = ii;
				continue;
			}

			if(j != -1)
				s2 += s[ii];
			else
				s1 += s[ii];
		}

		while((int)s2.length() < 9)
			s2 += '0';

		s = s1 + s2;
		lli x = 0;
		rep(ii,(int)s.length())
			x = 1LL * 10 * x + (s[ii]-'0');
		
		a[i] = x;
	}

	vvi g(30);
	rep(i,n)
	{
		int p5 = 0, p2 = 0;
		lli x = a[i];
		while(x%5==0)
			p5++, x=x/5;
		x = a[i];
		while(x%2==0)
			p2++, x=x/2;
		g[p5].pb(p2);
	}

	lli ans = 0;
	rep(i,30)
		loop(j,i+1,30,1)
		{
			if((int)g[i].size()==0 || (int)g[j].size()==0 || i + j < 18)
				continue;
			vlli f1(65, 0), f2(65, 0);
			rep(ii,(int)g[i].size())
				f1[g[i][ii]]++;
			rep(ii,(int)g[j].size())
				f2[g[j][ii]]++;	
		
			rep(i_,65)
				rep(j_,65)
					if(i_ + j_ >= 18)
						ans += f1[i_] * f2[j_];		
		}
	
	lli ans_ = 0;
	rep(i,30)
	{
		if((int)g[i].size() < 2 || i + i < 18)
			continue;
		vlli f(65, 0);
		rep(ii,(int)g[i].size())
			f[g[i][ii]]++;
		rep(i_,65)
			loop(j_,i_,65,1)
				if(i_+j_ >= 18)
				{
					if(i_ != j_)
						ans_ += f[i_] * f[j_];
					else
						ans_ += f[i_] * (f[i_] - 1)/2;
				}
	}
	cout << ans_ + ans	<< '\n';
}


int main()
{
	
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
 
    fastio();
    int q = 1;
    //cin >> q;
    while(q--)
        input();
}

Measured memory_bytes: 6084
#include <iostream>
#include <vector>
#include <iomanip>
#include <algorithm>
using namespace std;
using ll = long long;
using ld = long double;
int main()
{
    int N;
    cin >> N;
    vector<ll> a(N);
    for (int i = 0; i < N; i++) { cin >> a[i]; }
    constexpr int MAX = 200000;
    constexpr ld INF = 1e100;
    vector<ld> dp(MAX, INF);
    dp[1] = 0;
    for (int i = 0; i < N; i++) {
        vector<ld> tmp(MAX, INF);
        for (int j = 1; j < MAX; j++) {
            if (dp[j] == INF) { continue; }
            for (int k = j; k < MAX; k += j) { tmp[k] = min(tmp[k], max(dp[j], (ld)abs(k - a[i]) / a[i])); }
        }
        dp = tmp;
    }
    const ld ans = *min_element(dp.begin(), dp.end());
    cout << fixed << setprecision(15) << ans << endl;
    return 0;
}



Measured memory_bytes: 9176
#include<stdio.h>
#define N 10000
int keee(int *,int);
int n;
  int main(){
  int Sarray[N],key;
  int i,j,count = 0,q;
  
  scanf("%d",&n);

  for(i = 0;i < n;i++){
    scanf("%d",&Sarray[i]);
  }
  
  scanf("%d",&q);


  for(j = 0;j < q;j++){
    scanf("%d",&key);
    if(keee(Sarray,key)==1) count++;  
  }

   printf("%d\n",count);
  return 0;
}

int keee(int *s,int arraykey){
  int i=0;
  s[n] = arraykey;
  while(s[i] != arraykey){
    i++;
  }
  if(i == n){
    return 0;
  
  }
  return 1;
}

Measured memory_bytes: 636
#include<bits/stdc++.h>
using namespace std;
////////////////////////////////////////////////*kedar1514*////////////////////////////////////////////////(Template Start)*****
#define endl "\n"
#define ll long long
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,n) for(i=1;i<=n;i++)
#define si(x)   scanf("%d",&x)
#define sl(x)   scanf("%lld",&x)
#define ss(s)   scanf("%s",s)
#define pi(x)   printf("%d\n",x)
#define pl(x)   printf("%lld\n",x)
#define ps(s)   printf("%s\n",s)
#define all(x)  (x.begin(),x.end())
#define sortAll(x) sort(all(x))   
#define clearAll(arr) memset(arr,0,sizeof(arr))
#define deb(sum) cout<<"deb = "<<sum<<endl;
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define PI 3.1415926535897932384626
typedef pair<int, int>              pii;
typedef pair<long long, long long>  pll;
typedef vector<int>                 vi;
typedef vector<long long>           vl;
typedef vector<pii>                 vpii;
typedef vector<pll>                  vpll;
#define kedar ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

ll powerMod(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  while (n) {
	if (n & 1)
	  res = (res * x) % mod;
	x = (x * x) % mod;
	n >>= 1;
  }
  return res;
}

ll power(ll x, ll n) {
  ll res = 1;
  while (n) {
	if (n & 1)
	  res = (res * x);
	x = (x * x);
	n >>= 1;
  }
  return res;
}

int gcd(int A, int B) {
    if(B==0)
        return A;
    else
        return gcd(B, A % B);
}
////////////////////////////////////////////////*kedar1514*////////////////////////////////////////////////(Template ends)*****
// <<
//  <<,
//  , cout<<<<endl;
ll arr[100005];
ll dp[100005];
ll n;

int totalCost(int ind)
{
  if(dp[ind]!=-1) 
    return dp[ind];

  if(ind==(n-1))
  {
    return 0;
  }
  if(ind>=n)
  {
    return INT_MAX;
  }

  int left = abs(arr[ind]-arr[ind+1]) + totalCost(ind+1);
  int right = INT_MAX;
  
  if(ind+2<n)
  {
    right = abs(arr[ind]-arr[ind+2]) + totalCost(ind+2);
  }
  dp[ind] = min(right,left);

  return dp[ind];
}

void solve()
{
  cin>>n;
  for (ll i = 0; i < n; i++)
  {
    cin>>arr[i];
  }
  memset(dp,-1,sizeof(dp));
  cout<<totalCost(0);
  
}

int main(){
    kedar;
// <<
//  <<,
//  ,

    ll t=1;
    //cin>>t;
    while(t--)
    {       
        solve();
    }
    return 0;
}// <<
//  <<,
//  ,


Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
int a[20],x[20][20],y[20][20],ans=0,n;
void cal(int b){
    int num=0;
    for(int i=1;i<=n;i++){
        if((b>>(i-1))&1){
            num++;
            for(int j=1;j<=a[i];j++){
                if(((b>>(x[i][j]-1))&1)!=y[i][j]) return ;
            }
        }
    }
    ans=max(num,ans);
}
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        for(int j=1;j<=a[i];j++){
            cin>>x[i][j]>>y[i][j];
        }
    }
    for(int i=1;i<(1<<n);i++){
        cal(i);
    }
    cout<<ans<<endl;
}

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

int main()
{
  LL n,m,j=0,ans=0;
  pair<LL,LL> pii[100005];

  cin>>n>>m;

  for(int i=0; i<n; i++){
    cin>>pii[i].first>>pii[i].second;
  }

  sort(pii,pii+n);

  while(m>0){
    if(m>=pii[j].second){
      ans+=pii[j].second*pii[j].first;
      m-=pii[j].second;
      j++;
    }else{
      ans+=pii[j].first*m;
      m=0;
    }
  }
  cout<<ans<<'\n';
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define e1 first
#define e2 second
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false)
#define eb emplace_back
#define OUT(x) {cout << x; exit(0); }
#define REYNA(i,a,b) for(int i=(a);i<(b);++i)
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define scanf(...) scanf(__VA_ARGS__)?:0
typedef long long int ll;
typedef unsigned long long ull;
typedef pair <int, int> PII;
typedef pair <ll, ll> PLL;
typedef pair <PLL, int> PLLI;
typedef pair <PLL, pair <int, ll> > PP;
typedef pair <PII, int> PPI;
typedef pair <int, PII> PIP;
typedef pair <ll, int> PLI;
typedef unsigned int ui;
const int mod = 1e9+7;
const int inf = 1e9+9;
const ll MOD = 1e9+696969;
const long long INF = 1e18+3;
const int maxn = 1e6 + 5;
int tab[maxn], n;

int main()
{
	cin >> n;
	FOR(i, 1, n) cin >> tab[i];
	int res = 0;
	FOR(i, 1, n)
	{
		if (tab[i] == tab[i - 1])
		{
			++res;
			tab[i] = -1;
		}
	}
	
	cout << res;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    static final int MOD = 1_000_000_007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] a = new int[m];
        for (int i = 0; i < m; i++) {
            a[i] = sc.nextInt();
        }
        sc.close();

        int ans[] = new int[n + 1];
        ans[0] = 1;
        ans[1] = 1;
        int index = 0;
        for (int i = 2; i < n + 1; i++) {
            // 壊れている床を考慮
            if (index < m) {
                if (i - 1 == a[index]) {
                    ans[i - 1] = 0;
                    index++;
                }
            }
            // dpで算出
            ans[i] = (ans[i - 2] + ans[i - 1]) % MOD;
        }
        System.out.println(ans[n]);
    }

}


Measured memory_bytes: 51184
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#if __cplusplus >= 201103L
#include <chrono>
using namespace std::chrono;
#endif
using namespace std;
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pb push_back
#define fi first
#define se second
#ifdef LOCAL
#define prln(x) (cout << #x << ' ' << x << endl)
#define pr(x) (cout << #x << ' ' << x << ' ' )
#define prv(x) (cout << x << ' ')
#else
#define prln(x) 
#define pr(x)
#define prv(x)
#endif
#define clr(x) memset((x), 0, sizeof((x)))
#define clr1(x) memset((x), -1, sizeof((x)))
#define endl "\n"
#define pi acos(-1)
#define rep(i, st, ed) for (int i = (st); i <= (ed); ++i)
#define rep0(i, st, ed) for (int i = (st); i < (ed); ++i)
#define per0(i, st, ed) for (int i = (st); i > ed; --i)
#define per(i, st, ed) for (int i = (st); i >= ed; --i)
#define chmin(a, b) (a = a > b ? b : a)
#define chmax(a, b) (a = a < b ? b : a)
template<class T> void _sf(T &x) {cin >> x;}
void _sf(int &x) {scanf("%d", &x);}
void _sf(ll &x) {scanf("%lld", &x);}
void _sf(double &x) {scanf("%lf", &x);}
void _sf(char &x) {scanf(" %c", &x);}
void _sf(char *x) {scanf("%s", x);}
void sf() {}
template <class T, class...U> void sf(T & head, U&... tail) { _sf(head); sf(tail...);}
template<class T> void _out(const T &x) { cout << x; }
void _out(const int &x) { printf("%d", x); }
void _out(const ll &x) { printf("%lld", x); }
void _out(const double &x) { printf("%.16f", x); }
void _out(const char &x) { putchar(x); }
void _out(const char *x) { printf("%s", x); }
template<class T,class U> void _out(const pair<T,U> &x) {_out(x.F); putchar(' '); _out(x.S);}
template<class T> void _out(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _out(*i++)) if (i != x.cbegin()) putchar(' '); }
void out() {}
template<class T, class... U> void out(const T &head, const U &... tail) { _out(head); putchar(sizeof...(tail) ? ' ' : '\n'); out(tail...); }
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;

int read() {
    int x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}


int main(){
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    ll n, a, b;
    sf(n, a, b);
    ll ans = 0;
    if ((b - a) % 2 == 0) {
        ans = (b - a) / 2;
    }else {
        ll tl = a - 1;
        ll dif = b - a;
        ans = tl + dif / 2 + 1;

        ll tr = n - b;
        ll temp = tr + dif / 2 + 1;
        ans = min(ans, temp);
    }
    out(ans);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if(a-b==b-c)
	{
    	cout<<"YES"<<endl;
    	return 0;
    }
    cout<<"NO"<<endl;
    return 0;
}

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

int main(){
    long long cases, num[10000], total = 0, largest, smallest;
    cin >> cases;
    for(int i = 0; i < cases; ++i){
        cin >> num[i];
    }
    largest = num[0];
    smallest = num[0];
    for(int i = 0; i < cases; ++i){
        total += num[i];
        if(num[i] > largest){
            largest = num[i];
        }
        if(num[i] < smallest){
            smallest = num[i];
        }
    }
    cout << smallest << " " << largest << " " << total << endl;
}

Measured memory_bytes: 1236
import sys
S = input()
idx = 1
for s in S:
  if idx%2==1:
    if not(s=='R' or s=='U' or s=='D'):
      print('No')
      sys.exit()
    else:
      idx+=1
  else:
    if not(s=='L' or s=='U' or s=='D'):
      print('No')
      sys.exit()
    else:
      idx+=1
print('Yes')


Measured memory_bytes: 2940
#include<stdio.h>

int main(void){
    int n=1,x=1;
    int i,j,k;
    int sum = 0;

    while(1){
        scanf("%d %d",&n, &x);
           if(n == 0 && x == 0){break;}

            for(i = 1; i <= n -2;  i++){
                for(j =  i+1; j <= n -1; j++){
                    for(k = j + 1 ; k <= n; k++){
                        if(((i + j + k) == x) && i != j && j!=k  && i != k){
                            sum++;
                        }
                    }
                }
            }

        printf("%d\n",sum);
        sum = 0;
    }
    return 0;
}

Measured memory_bytes: 600
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        var inputs = Console.ReadLine().Split(' ');
        var H = int.Parse(inputs[0]);
        var W = int.Parse(inputs[1]);
        var mat = new int[H, W];
        for (int i = 0; i < H; i++)
        {
            var str = Console.ReadLine();
            for (int j = 0; j < W; j++)
            {
                if (str[j] == '.')
                {
                    mat[i, j] = 0;
                }
                else
                {
                    mat[i, j] = 1;
                }
            }
        }

        var ignoreRow = new bool[H];
        var ignoreCol = new bool[W];

        for (int i = 0; i < H; i++)
        {
            ignoreRow[i] = true;
            for (int j = 0; j < W; j++)
            {
                if (mat[i, j] == 1)
                {
                    ignoreRow[i] = false;
                    break;
                }
            }
        }

        for (int j = 0; j < W; j++)
        {
            ignoreCol[j] = true;
            for (int i = 0; i < H; i++)
            {
                if (mat[i, j] == 1)
                {
                    ignoreCol[j] = false;
                    break;
                }
            }
        }

        for (int i = 0; i < H; i++)
        {
            var sb = new System.Text.StringBuilder();
            for (int j = 0; j < W; j++)
            {
                if (!ignoreRow[i] && !ignoreCol[j])
                {
                    var str = mat[i, j] == 1 ? "#" : ".";
                    sb.Append(str);
                }
            }

            if (sb.Length > 0)
            {
                Console.WriteLine(sb);
            }
        }
    }
}



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

#define PI 3.141592653
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descSort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;
ll gcd(ll x,ll y){
    if(x%y==0)return y;
    return gcd(y,x%y);
}

int main(void){
    int a,b,c;
    cin>>a>>b>>c;
    int ma=max({a,b,c});
    int sum=a+b+c;
    if((3*ma-sum)%2==0) cout<<(3*ma-sum)/2<<endl;
    else cout<<(3*(ma+1)-sum)/2<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
int gcd(int a, int b) { return !b ? a : gcd(b, a%b); }
char s[100010], t[100010];
int main() {
	int n, m;
	scanf("%d%d%s%s",&n,&m,s,t);
	int g = gcd(n,m);
	for(int i=0; n/g*i<n && m/g*i<m; i++) {
		if(s[n/g*i] != t[m/g*i]) {
			puts("-1");
			return 0;
		}
	}
	printf("%lld", 1ll * n * m / g);
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(false), cout << fixed << setprecision(20);
#define int long long
#define gcd __gcd
#define all(x) (x).begin(), (x).end()
template<class T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<class T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}
#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(...) _overload(__VA_ARGS__, repi, _rep)(__VA_ARGS__)
#define _rev(i, n) revi(i, n, 0)
#define revi(i, a, b) for(int i = (int)(a - 1); i >= (int)(b); i--)
#define rev(...) _overload(__VA_ARGS__, revi, _rev)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
int INF = 1e18, MOD = 1e9 + 7;
signed main() {
    INCANT;
    int a,b,c,d, res = 0;
    cin>>a>>b>>c>>d;
    rep(i, a){
        rep(j, b){
            if(j < c && i < d || j >= c && i >= d){
                cout<<'0';
            }else{
                cout<<'1';
            }
        }
        cout<<endl;
    }
}


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

#define MAX 1000000000

void merge(int *, int, int, int);
void mergeSort(int *, int, int);

int count = 0;

int main() {
  int i, n;
  int data[500000];

  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &data[i]);
  }

  mergeSort(data, 0, n);

  for (i = 0; i < n; i++) {
    printf("%d" ,data[i]);
    if (i != n-1) {
      printf(" ");
    }
    else {
      printf("\n");
    }
  }

  printf("%d\n", count);

  return 0;
}


void merge(int *data, int left, int mid, int right) {
  int n1, n2, i, j, k;
  int *l, *r;

  n1 = mid - left;
  n2 = right - mid;
  
  l = malloc((n1+1) * sizeof(int));
  r = malloc((n2+1) * sizeof(int));

  for (i = 0; i < n1; i++) {
    l[i] = data[left+i]; 
  }
  for (i = 0; i < n2; i++) {
    r[i] = data[mid+i];
  }
  l[n1] = MAX;
  r[n2] = MAX;
  
  i = 0;
  j = 0;

  for (k = left; k < right; k++) {
    if (l[i] <= r[j]) {
      data[k] = l[i];
      i++;
      count++;
    }
    else {
      data[k] = r[j];
      j++;
      count++;
    }
  }
}

void mergeSort(int *data, int left, int right) {
  int mid;
  if (left+1 < right) {
    mid = (left + right) / 2;
    mergeSort(data, left, mid);
    mergeSort(data, mid, right);
    merge(data, left, mid, right);
  }
}



Measured memory_bytes: 64440
N = int(input())
s = N*(N+1)*0.5
t = N // 3
ts = t*(t+1)*0.5*3
f = N // 5
fs = f *(f+1)*0.5*5
ff = N // 15
ffs = ff*(ff+1)*0.5*15

print(int(s-ts-fs+ffs))


Measured memory_bytes: 9176
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mxn= 5e5+5;
#define mod 1000000007
#define endl '\n'
void rishabh(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}
int main(){
    rishabh();
    int n;
    cin>>n;
    string s;
    cin>>s;
    int x=0,ans=0;
    for(auto k: s){
        if(k=='I')x++;
        else x--;
        ans=max(ans,x);
    }
    cout<<ans;
}



Measured memory_bytes: 3628