akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main() {
  int n,i,j,e,t,mi,fl,sta=0;
  int a[50],b[50];
  char c[101],kara,m,d[101],f[4],str[3];
  
  scanf("%d", &n);
  
  for(i=0; i<n; i++) {
    
    scanf("%s",str);
    c[i] = str[0];
    a[i]  = str[1] - '0';
    b[i] = a[i];
    d[i] = c[i];
  }
  
  for(i = 0; i<=n-1;i++) {
    for(j = 0; j<=n-1;j++) {
      if(a[j] < a[j-1]) {
	t = a[j];
	a[j] = a[j-1];
	a[j-1] = t;
	m = c[j];
	c[j] = c[j-1];
	c[j-1] = m;
      }
    }
  }
  
  for(i = 0;i<n;i++) {  
    printf("%c%d",c[i],a[i]);
    if(i != n-1) printf(" ");
  }
  
  printf("\nStable\n");
  
  for(i = 0; i<=n-1; i++) {
    mi = i;
    fl = 0;
    for(j = i; j<=n-1;j++) {
      if(b[j] < b[mi]) {
	mi = j;
	fl = 1;
      }
    }
    if(fl == 1) { 
      t = b[i];
      b[i] = b[mi];
      b[mi] = t;
      m = d[i];
      d[i] = d[mi];
      d[mi] = m;
    }
  }
  for(i=0;i<n;i++) {
    printf("%c%d",d[i],b[i]);
    if(i != n-1) {
      printf(" ");
    }   
  }
  printf("\n");
  fl = 0;
  for(j=0;j<n;j++){
    if(c[j] != d[j]) {
      fl = 1;
    }
  } 
  if(fl == 1) printf("Not stable\n");
  else printf("Stable\n");
  
  return 0;
  
}



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

typedef long long ll;

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

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

    int x,y;
    cin >> x >> y;
    if((2*y-x)%3!=0 || (2*x-y)%3!=0){
        cout << 0 << endl;
        return 0;
    }
    int a = (2*y-x)/3;
    int b = (2*x-y)/3;
    combination c(x+y);
    mint ans = c(a+b,a);
    cout << ans.x << endl;
    return 0;
}

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

int main() {
  int n, x, a = 1, lsum = 0;
  cin >> n >> x;
  vector<int> l(n);
  for(int i = 0;i < n;i++){
    cin >> l.at(i);
    lsum = lsum + l.at(i);
    if(lsum <= x)
      a++;
  }
  cout << a << endl;
}

Measured memory_bytes: 256
//
//  main.cpp
//  ProgrammingContestChallengeBook2
//
//  Created by Hisaki Kobayashi on 2020/04/04.
//  Copyright © 2020 Hisaki Kobayashi. All rights reserved.
//

#include <iostream>
#include <stdio.h>
#include <string>
#include <bits/stdc++.h>
using namespace std;

int main(int argc, const char * argv[]) {
    
    int N,M,i;
    cin >> N >> M;
    double A[N],sum=0;
    for(i=0;i<N;i++){
        cin >> A[i];
        sum+=A[i];
    }
    
    double condition = sum / (4*(double)M);
    
    int cnt=0;
    for(i=0;i<N;i++){
        if(A[i]>=condition)
            cnt++;
        
    }
    if(cnt>=M)
        cout << "Yes" << endl;
    else{
        cout << "No" << endl;
    }
    
    return 0;
}




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

struct segtree{
    int size;
    vector<ll> dat;
    ll init = 0;

    segtree (int N) {
        size = 1;
        while (size < N) size *= 2;
        dat = vector<ll>(2*size-1, init);
    }

    ll op(ll a, ll b) {
        return a+b;
    }

    void update(int i, ll x) { 
        i += size-1;
        dat[i] = x;
        while (i > 0) {
            i = (i-1)/2;
            dat[i] = op(dat[2*i+1], dat[2*i+2]);
        }
        return;
    }
    
    void add(int i, ll x) { 
        i += size-1;
        dat[i] += x;
        while (i > 0) {
            i = (i-1)/2;
            dat[i] = op(dat[2*i+1], dat[2*i+2]);
        }
        return;
    }

    ll query(int a, int b) {
        return query(a, b, 0, 0, size);
    }
    

    ll query(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l) return init;
        if (a <= l && r <= b) return dat[k];
        ll lv, rv;
        lv = query(a, b, 2*k+1, l, (l+r)/2);
        rv = query(a, b, 2*k+2, (l+r)/2, r);
        return op(lv, rv);
    }
};

int main() {
    int N, M;
    cin >> N >> M;
    vector<pair<int, pair<int, int>>> omiya(N);
    for (int i = 0; i < N; i++) {
        int l, r;
        cin >> l >> r;
        omiya[i] = {r-l+1, {l, r}};
    }
    sort(omiya.begin(), omiya.end());
    segtree st(M+3);
    int pos = 0;
    for (int i = 1; i <= M; i++) {
        while (pos < N && omiya[pos].first < i) {
            auto p = omiya[pos].second;
            st.add(p.first, 1);
            st.add(p.second+1, -1);
            pos++;
        }
        int ans = N-pos;
        for (int j = i; j <= M; j += i) {
            ans += st.query(0, j+1);
        }
        cout << ans << "\n";
    }
    return 0;
}


Measured memory_bytes: 6528
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <forward_list>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;

const ll MOD = 1E+09 + 7;
const ll INF = 1E18;
const int MAX_N = 3000;

int N;

double dp[MAX_N + 1][MAX_N + 1], P[MAX_N + 1];

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

    cin >> N;

    for (int i = 1; i <= N; i++) {
        cin >> P[i];
    }

    dp[0][0] = 1.0;

    for (int i = 1; i <= N; i++) {
        for (int j = 0; j <= i; j++) {
            if (j >= 1) {
                dp[i][j] += dp[i - 1][j - 1] * P[i];
            }
            dp[i][j] += dp[i - 1][j] * (1 - P[i]);
        }
    }

    double ans = 0.0;

    for (int j = ceil(double(N) / 2); j <= N; j++) {
        ans += dp[N][j];
    }

    cout << fixed << setprecision(10) << ans << "\n";

    return 0;
}

Measured memory_bytes: 49940
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int main () {
  int H, W;
  cin >> H >> W;
  string a[110];
  for (auto i = 0; i < H; ++i) {
    cin >> a[i];
  }
  cout << "#";
  for (auto i = 0; i < W; ++i) {
    cout << "#";
  }
  cout << "#" << endl;
  for (auto i = 0; i < H; ++i) {
    cout << "#" << a[i] << "#" << endl;
  }
  cout << "#";
  for (auto i = 0; i < W; ++i) {
    cout << "#";
  }
  cout << "#" << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>

using namespace std;

using Weight=long long;
static const Weight INF=1LL<<57;

struct Edge {
    size_t src, dst;
    Weight weight;
    Edge() {}
    Edge(size_t src, size_t dst, Weight weight=1):
        src(src), dst(dst), weight(weight)
    {}
};

bool operator<(const Edge &e, const Edge &f) {
    if (e.weight != f.weight) {
        return e.weight > f.weight;
    } else {
        return e.src!=f.src? e.src<f.src : e.dst<f.dst;
    }
}

using Edges=vector<Edge>;
using Vertex=vector<Edge>;
using Graph=vector<Vertex>;

void join(Graph &g, size_t s, size_t d, Weight w=1) {
    // non-directed
    g[s].push_back(Edge(s, d, w));
    g[d].push_back(Edge(d, s, w));
}

void connect(Graph &g, size_t s, size_t d, Weight w=1) {
    // directed
    g[s].push_back(Edge(s, d, w));
}

struct UndirComp {
    bool operator()(const Edge &e, const Edge &f) const {
        if (min(e.src, e.dst) != min(f.src, f.dst)) {
            return min(e.src, e.dst) < min(f.src, f.dst);
        } else {
            return max(e.src, e.dst) < max(f.src, f.dst);
        }
    }
} undircomp;

void visit(
    const Graph &g, size_t v, vector<vector<size_t>> &sccomp,
    stack<size_t> &s, vector<bool> &stacked, vector<size_t> &low,
    vector<size_t> &num, int &time
) {
    low[v] = num[v] = ++time;
    s.push(v), stacked[v] = true;
    for (const Edge &e: g[v]) {
        size_t w=e.dst;
        if (!num[w]) {
            visit(g, w, sccomp, s, stacked, low, num, time);
            low[v] = min(low[v], low[w]);
        } else if (stacked[w]) {
            low[v] = min(low[v], num[w]);
        }
    }

    if (low[v] == num[v]) {
        sccomp.push_back(vector<size_t>());
        while (true) {
            size_t w=s.top(); s.pop(), stacked[w]=false;
            sccomp.back().push_back(w);
            if (v == w) break;
        }
    }
}

vector<vector<size_t>> get_sccomp(const Graph &g) {
    size_t V=g.size();
    vector<size_t> num(V), low(V);
    stack<size_t> s;
    vector<bool> stacked(V);
    int time=0;

    vector<vector<size_t>> sccomp;
    for (size_t u=0; u<V; ++u) if (!num[u])
        visit(g, u, sccomp, s, stacked, low, num, time);

    return sccomp;
}

int main() {
    size_t V, E;
    scanf("%zu %zu", &V, &E);

    Graph g(V);
    for (size_t i=0; i<E; ++i) {
        size_t s, t;
        scanf("%zu %zu", &s, &t);

        connect(g, s, t);
    }

    vector<vector<size_t>> sccomp=get_sccomp(g);

    vector<size_t> comp_idx(V);
    for (size_t i=0; i<sccomp.size(); ++i)
        for (size_t j: sccomp[i])
            comp_idx[j] = i;

    size_t Q;
    scanf("%zu", &Q);

    for (size_t i=0; i<Q; ++i) {
        size_t u, v;
        scanf("%zu %zu", &u, &v);

        printf("%d\n", comp_idx[u]==comp_idx[v]);
    }

    return 0;
}

Measured memory_bytes: 5292
# coding: utf-8
# Your code here!

n = int(input());
#n = [int(i) for i in input().split()];
#S = [str(s) for s in in_S]

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            divisors.append(n//i)

    # divisors.sort()
    return divisors
    
m = make_divisors(n)
#print(m);

count = 0;
for i in range(0,len(m),2):
    #print(i);
    #if i==len(m)-1:
        #break;
    tmp =  (m[i]-1) + (m[i+1]-1);
    #print(tmp);
    if tmp < count or count == 0:
        count = tmp;
    #if n%i == 0 and n/i <= 9:
        #jud ='Yes';
print(count);


Measured memory_bytes: 3268
from collections import defaultdict
(h,n),*ab = [list(map(int, s.split())) for s in open(0)]

mxa = max(a for a,b in ab)

dp = defaultdict(lambda: float('inf'))
dp[0] = 0

for i in range(1, h+mxa):
    dp[i] = min(dp[i-a] + b for a,b in ab)

print(min(v for k,v in dp.items() if k>=h))

Measured memory_bytes: 78296
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long x,k,d;
	cin>>x>>k>>d;
	x=abs(x);
	if (x/k>=d)
	{
		cout<<abs(x-k*d)<<endl;
	}
	else
	{
		long long y=x%d;
		long long i=(x-y)/d;
		if ((k-i)%2==1) y=abs(y-d);
		cout<<y<<endl; 
	}
	return 0;
}

Measured memory_bytes: 3556
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define maxn	500005
#define mod		int(1e9+7)
#define db		double
#define ll		long long
#define si 		stack<int>
#define qi 		queue<int>
#define vi 		vector<int>
#define pi 		pair<int, int>
ll powmod(ll a, ll b) {
	ll res = 1; a %= mod;
	for (; b; b >>= 1)
		res = (res * ((b & 1) ? a : 1)) % mod,
		a = a * a % mod;
	return res;
}
ll gcd(ll a, ll b) {
	return b ? gcd(a, b) : a;
}
/** GRAPH
int edgenum, head[maxn], vet[2 * maxn], nxt[2 * maxn], wt[2 * maxn];
void addedge(int u, int v) {
	edgenum ++;
	vet[edgenum] = v;
	nxt[edgenum] = head[u];
	head[u] = edgenum;
}
void addedge(int u, int v, int w) {
	edgenum ++;
	vet[edgenum] = v;
	nxt[edgenum] = head[u];
	head[u] = edgenum;
	wt[edgenum] = w;

}
GRAPH **/

using namespace std;
int main() {
	ll a, b, n;
	cin >> a >> b >> n;
	if(n > b - 1) {
		cout << floor((a * (b - 1)) / b);
	}
	else cout << floor((a * n) / b);
	cout << endl;
	return 0;
}

Measured memory_bytes: 3776
import java.util.Scanner;
import java.util.HashMap;

public class Main{
    public static void main(String[] args){
	Scanner scan = new Scanner(System.in);

	HashMap<String, Integer> hash = new HashMap<String, Integer>();
	int N = scan.nextInt();

	for(int i = 0; i < N; i++){
	    String s = scan.next();
	    if(hash.containsKey(s)){
		hash.put(s, hash.get(s)+1);
	    }else{
		hash.put(s, 1);
	    }
	}

	int M = scan.nextInt();

	for(int i = 0; i < M; i++){
	    String s = scan.next();
	    if(hash.containsKey(s)){
		hash.put(s, hash.get(s)-1);
	    }else{
		hash.put(s, -1);
	    }
	}

	int max = 0;
	for(String s : hash.keySet()){
	    int num = hash.get(s);
	    if(max < num){
		max = num;
	    }
	}

	System.out.println(max);
    }
}


Measured memory_bytes: 21844
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;
typedef long long ll;
vector<ll> g[100005];
ll dp[1100][1100] = { 0 };
ll d[100005];
ll mod = 1000000007;
vector<string> a;
void add(ll &a, ll b) {
	a += b;
	a = a % mod;
}

int main() {
	ll h, w;
	cin >> h >> w;
	vector<string> a;
	a.resize(h);
	for (int i = 0; i < h; i++) {
		cin >> a[i];
	}

	dp[0][0] = 1;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (i + 1 < h && a[i + 1][j] == '.') {
				add(dp[i + 1][j], dp[i][j]);
			}
			if (j + 1 < w && a[i][j + 1] == '.') {
				add(dp[i][j + 1], dp[i][j]);
			}
		}
	}
	cout << dp[h - 1][w - 1] << endl;
	return 0;
}

Measured memory_bytes: 13056
import java.util.ArrayDeque;
import java.util.Scanner;

public class Main {

	static char	s[];
	static char	t[];

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		s = in.next().toCharArray();
		t = in.next().toCharArray();
		in.close();

		int row = t.length;
		int col = s.length;
		int tb[][] = new int[row + 1][col + 1];
		for(int i = 0; i<=row; i++)tb[i][0] = 0;
		for(int i = 0; i<=col; i++)tb[0][i] = 0;

		for ( int r = 0; r < row; r++ ) {
			for ( int c = 0; c < col; c++ ) {
				if ( t[r] == s[c] ) {
					tb[r + 1][c + 1] = tb[r][c] + 1;
				} else {
					tb[r + 1][c + 1] = Math.max(tb[r + 1][c], tb[r][c + 1]);
				}
			}
		}

		//		for ( int[] is : tb ) {
		//			for ( int i : is ) {
		//				System.out.print(i + " ");
		//			}
		//			System.out.println();
		//		}

		int r = row;
		int c = col;
		ArrayDeque<Character> stack = new ArrayDeque<Character>();
		while ( tb[r][c] != 0 ) {

			// 左上に行けるとき
			if ( tb[r - 1][c - 1] == tb[r][c]) {
				r -= 1;
				c -= 1;
			} else
			// 上にだけ行けるとき
			if ( tb[r - 1][c] ==  tb[r][c]) {
				r -= 1;
			} else
			// 左にだけ行けるとき
			if ( tb[r][c - 1] == tb[r][c]) {
				c -= 1;
			} else
			// 行き止まり
			{
				stack.add((Character) s[c - 1]);
				r -= 1;
				c -= 1;
			}
		}
		if ( stack.size() == 0 ) {
			System.out.print("");
			return;
		}

		while ( stack.size() > 0 ) {
			System.out.print(stack.pollLast());
		}
	}
}


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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    int x = 0;
    for (int i=0;i<n;i++) {
        cin >> a.at(i);
        x = (x^a.at(i));
    }
    for (int i=0;i<n;i++) {
        cout << (x^a.at(i));
        if (i==n-1) cout << endl;
        else cout << " ";
    }
}

Measured memory_bytes: 4056
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long int n;
  cin>>n;
  vector<int>h(n);
vector<int>b(n);
map<int,long long>m;

    for(int i=0;i<n;i++){
        cin>>h[i];
    }
    for(int i=0;i<n;i++){
        cin>>b[i];
    }
    for(int i=0;i<n;i++){
 
        int x = h[i];
        long long val = b[i];
        auto itr = m.upper_bound(x);
        if(itr!=m.begin()){
            itr--;
            val += itr->second;
        }
        m[x] = val;
        itr = m.upper_bound(x);
        while(itr != m.end() && itr->second <=val){
            auto temp = itr;
            temp++;
            m.erase(itr);
            itr = temp;
        }
    }
    auto it = m.end();
    it--;
    long long ans  = it->second;
    cout << ans <<"\n";
}

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

// macros
#define M 1000000007
#define addmod(a,b,m) (a%m + b%m)%m
#define submod(a,b,m) (a%m - b%m)%m
#define mulmod(a,b,m) ((a%m)*(b%m))%m
#define F first
#define S second
#define APSUM(a,b,n) n*((a*.5)+(b*.5))
#define GPSUM(a,b,k) (b*k-a)/(k-1)
#define INFGP(a,k) a/(1-r)
#define CEIL(a,b) ceil(double(a)/double(b))
#define FLOOR(a,b) floor(double(a)/double(b))
#define T(t) while(t--)
#define F first
#define S second
#define PB push_back
#define MP make_pair

using namespace std;

//typedefs
typedef long long int ll ;
typedef vector<ll> vi ;
typedef pair<ll,ll> pi ;
typedef map<ll,ll> mps;

ll power(ll base,ll val)
{
    ll res=1;
    while(val)
    {
        if(val&1)
    {
        res = (res*base)%M;
    }
     base = (base*base)%M;
     val/=2;
    }
    return res;
}
ll digit(ll n)
{
    double phi = (1 + sqrt(5))/2;
    ll value = round(pow(phi,n)/(sqrt(5)));
    ll count=0;
    while(value)
    {
        count++;
        value/=10;
    }
    return count;
}
set<tuple<int,int,int> > ss;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
/*
when files are giving the inputs and outputs
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);

*/
    ll n;
    cin>>n;
    ll sum=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            for(int k=1;k<=n;k++)
            {
                sum = sum + __gcd(i,__gcd(j,k));
            }
        }
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 3700
#include <stdio.h>
int main()
{
  int mj,cou=0,next=0,h=0;;
  char m[33];
  while(1){
    mj=0;
    h=0;
    scanf("%s",m);
    if(m[0]=='#')break;
    if(('a'<=m[mj]&&m[mj]<='g')||('q'<=m[mj]&&m[mj]<='t')||('v'<=m[mj]&&m[mj]<='x')||m[mj]=='z')h=1;
    next=0;
    cou=0;
    for(mj=1;m[mj]!='\0';mj++){
      if(h==0){
	if(('a'<=m[mj]&&m[mj]<='g')||('q'<=m[mj]&&m[mj]<='t')||('v'<=m[mj]&&m[mj]<='x')||m[mj]=='z'){
	  cou++;
	  h=2;
	}
      }
      if(h==1){
	if(('h'<=m[mj]&&m[mj]<='p')||m[mj]=='u'||m[mj]=='y'){
	cou++;
        h=3;
	}
      }
      if(h==2)h=1;
      if(h==3)h=0;
    }
    printf("%d\n",cou);
  }
  return 0;
}

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

int main(){
	int n, x;

	while(1){
		cin >> n >> x;
		if(n == 0 && x == 0) break;
		int count = 0;

		for(int i = 1; i <= n-2; i++){
			for(int j = i+1; j <= n-1; j++){
				for(int k = j+1; k <= n; k++){
					if(i+j+k == x) count++;
				}
			}
		}
		cout << count << endl;
	}
	return 0;
}


Measured memory_bytes: 3076
#include<iostream>
#include<string.h>
#include<ctype.h>
#include<string>
#include<math.h>
#define pi 3.141592653589
#include<iomanip>
using namespace std;
#include<algorithm>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 1e9
#define LINF 1e17
#define ll long long
#define MOD (int)(1e9+7)

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



int main() {

	int n, a;

	cin >> n >> a;
	cout << n*n - a << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<vector>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
int main() {
  long long int a,b,c=0,d=1000000007;cin>>a>>b;
  rep(i,b){
    cin>>d;
    c+=d;
  }
  if(a-c<0)cout<<-1;
  else cout<<a-c;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct node{
	int b,c;
}a[100005];
int cmp(node x,node y){
	return x.c>y.c;
}
int d[100005];
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++)
		scanf("%d",&d[i]);
	sort(d,d+n);
	for(int i=0;i<m;i++)
		scanf("%d%d",&a[i].b,&a[i].c);
	sort(a,a+m,cmp);
	int id=0;
	ll ans=0;
	for(int i=0;i<n;i++){
		if(d[i]<a[id].c&&a[id].b){
			ans+=a[id].c;
			a[id].b--;
		}
		else ans+=d[i];
		if(a[id].b==0){
			if(id+1<m)
				id++;
		}
	}
	printf("%lld\n",ans);
}

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

using namespace std;
#define int long long int
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define vi vector <int>
#define sz(s) (int)s.size()
#define pii pair<int,int>
#define piii pair< int,pair<int,int> >
#define tiii tuple <int,int,int>
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define rall(v) v.rbegin(),v.rend()
#define endl '\n'
#define matrix vector <vector <int> >
#define boost ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define NAYAN freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define N 406
#define mod 1000000007
#define mod2 998244353
#define inf 1e18

int a[N];
int dp[N][N];
int n;
int pref[N];

int sum(int i,int j)
{
    int ans=pref[j]-pref[i-1];
    return ans;
}

int solve(int i,int j)
{
    if(i>=j)
        return 0;
    if(i+1==j)
        return (a[i]+a[j]);


    int &ans=dp[i][j];
    if(ans!=-1)
        return ans;

    ans=inf;

    for(int k=i;k<j;k++)
    {
        ans=min(ans,solve(i,k)+solve(k+1,j)+sum(i,j));
    }

    return ans;
}







int32_t main()
{
    boost
    // #ifndef ONLINE_JUDGE 
    // NAYAN
    // #endif

    memset(dp,-1,sizeof dp);
    cin >> n;
    int i;
    for(i=1;i<=n;i++)
    {
        cin >> a[i];
    }

    pref[0]=0;
    pref[1]=a[1];

    for(i=2;i<=n;i++)
    {
        pref[i]=pref[i-1]+a[i];
    }



    int ans=solve(1,n);

    cout << ans;

    
    
    
}

Measured memory_bytes: 1536
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repq(i,a,n) for(int i=a; i<=n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 999999999

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))
#define int long long

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int const MOD = 1000000007;

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int dp[60][60][2600];
signed main() {
    int n, a; cin >> n >> a;
    memset(dp, 0, sizeof(dp));
    repq(i,0,n) dp[i][0][0] = 1;
    int x[60]; rep(i,0,n) cin >> x[i];

    rep(i,0,n) {
        repq(j,0,i) {
            rep(k,0,2600) {
                dp[i+1][j+1][k] += dp[i][j+1][k];
                if(k-x[i] < 0) continue;
                dp[i+1][j+1][k] += dp[i][j][k-x[i]];
            }
        }
    }
    int ans = 0;
    repq(i,1,n) rep(j,0,2600) {
        if(a * i == j) ans += dp[n][i][j]; 
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 73344
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
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;}


template<typename T,T MOD = 1000000007>
struct Mint{
  static constexpr T mod = MOD;
  T v;
  Mint():v(0){}
  Mint(signed v):v(v){}
  Mint(long long t){v=t%MOD;if(v<0) v+=MOD;}

  Mint pow(long long k){
    Mint res(1),tmp(v);
    while(k){
      if(k&1) res*=tmp;
      tmp*=tmp;
      k>>=1;
    }
    return res;
  }

  static Mint add_identity(){return Mint(0);}
  static Mint mul_identity(){return Mint(1);}

  Mint inv(){return pow(MOD-2);}

  Mint& operator+=(Mint a){v+=a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator-=(Mint a){v+=MOD-a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator*=(Mint a){v=1LL*v*a.v%MOD;return *this;}
  Mint& operator/=(Mint a){return (*this)*=a.inv();}

  Mint operator+(Mint a) const{return Mint(v)+=a;}
  Mint operator-(Mint a) const{return Mint(v)-=a;}
  Mint operator*(Mint a) const{return Mint(v)*=a;}
  Mint operator/(Mint a) const{return Mint(v)/=a;}

  Mint operator-() const{return v?Mint(MOD-v):Mint(v);}

  bool operator==(const Mint a)const{return v==a.v;}
  bool operator!=(const Mint a)const{return v!=a.v;}
  bool operator <(const Mint a)const{return v <a.v;}

  static Mint comb(long long n,int k){
    Mint num(1),dom(1);
    for(int i=0;i<k;i++){
      num*=Mint(n-i);
      dom*=Mint(i+1);
    }
    return num/dom;
  }
};
template<typename T,T MOD> constexpr T Mint<T, MOD>::mod;
template<typename T,T MOD>
ostream& operator<<(ostream &os,Mint<T, MOD> m){os<<m.v;return os;}


template<typename T>
map<T, int> factorize(T x){
  map<T, int> res;
  for(int i=2;i*i<=x;i++){
    while(x%i==0){
      x/=i;
      res[i]++;
    }
  }
  if(x!=1) res[x]++;
  return res;
}

//INSERT ABOVE HERE
signed main(){
  int n;
  cin>>n;
  vector<int> as(n);
  for(int i=0;i<n;i++) cin>>as[i];

  map<int, int> ps;
  for(auto a:as)
    for(auto p:factorize(a))
      ps[p.first],chmax(ps[p.first],p.second);

  using M = Mint<int>;
  M lcm{1};
  for(auto p:ps)
    lcm*=M(p.first).pow(p.second);

  M ans{0};
  for(auto a:as)
    ans+=lcm/M(a);

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


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
const int MOD = 1000000007;



int main(){

    int MAX = 100000;
    vector<int> is_prime(MAX,1);
    is_prime[0] = 0;
    is_prime[1] = 0;
    for(int i=2;i<MAX;i++){
        if(!is_prime[i]) continue;
        for(int j = i*2 ;j<MAX;j+=i){
            //iの倍数
            is_prime[j] = 0;
        }
    }
    //累積和の求める
    vector<int> A(MAX+1,0);
    REP(i,MAX){
        if(i%2 ==1 and is_prime[i] and is_prime[(i+1)/2]){
            A[i+1] = A[i] + 1;
        }else{
            A[i+1] = A[i];
        }
    }
    int Q;cin>>Q;
    REP(i,Q){
        int left, right;
        cin>>left>>right;
        right++;
        cout<<A[right]-A[left]<<endl;
    }
}

Measured memory_bytes: 1408
#define _DEBUG
#include "bits/stdc++.h"
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif
#define rep(index,num) for(int index=0;index<(int)num;index++)
#define rep1(index,num) for(int index=1;index<=(int)num;index++)
#define brep(index,num) for(int index=(int)num-1;index>=0;index--)
#define brep1(index,num) for(int index=(int)num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
struct UnionFind{
  vector<int> par;
  vector<int> sizes;
  UnionFind(int n) : par(n), sizes(n, 1) {
    rep(i,n) par[i] = i;
  }
  int root(int x) {
    if (x == par[x]) return x;
    return par[x] = root(par[x]);
  }
  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return;
    if (sizes[x] < sizes[y]) swap(x, y);
    par[y] = x;
    sizes[x] += sizes[y];
  }
  bool same(int x, int y) {
    return root(x) == root(y);
  }
  int size(int x) {
    return sizes[root(x)];
  }
};
int main(){
	int N,M,K;
	scan(N>>M>>K);
	UnionFind uf(N);
	int en[100001]={};
	rep(i,M){
		int a,b;
		scan(a>>b);
		a--; b--;
		uf.unite(a,b);
		en[a]++; en[b]++;
	}
	int ans[100001];
	rep(i,N){
		ans[i]=uf.size(i)-1-en[i];
	}
	rep(i,K){
		int c,d;
		scan(c>>d);
		c--; d--;
		if(uf.same(c,d)){
			ans[c]--;
			ans[d]--;
		}
	}
	rep(i,N){
		printf("%d ",ans[i]);
	}kaigyo;
	return 0;
}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
//#define DBG

using namespace std;

using ll = long long;

int main(){
  ll n, a, b;
  cin >> n >> a >> b;
  cin.ignore();

  ll tmp;
  if(b < a){
    tmp = b;
    b = a;
    a = tmp;
  }

  //以下、a<b

  ll d = b - a;

  // 距離が偶数ならその半分が最小の回数

  ll ans;
  if(d % 2 == 0){
    ans = d / 2;
    cout << ans << endl;
    return 0;
  }

  // 1に寄った場合
  ll a_tmp, b_tmp;
  ll cnt1 = a - 1; // まずaが1に行く
  a_tmp = 1;
  b_tmp = b - (a - 1);

  // aが1に留まる
  --b_tmp;
  ++cnt1;
#ifdef DBG
  cout << "1" << endl;
  cout << "a_tmp = " << a_tmp << " " << flush;
  cout << "b_tmp = " << b_tmp << " " << endl;
#endif
  // b_tmpがすでに1であれば？
  if(b_tmp == 1){
  } else {
    cnt1 += (b_tmp - a_tmp) / 2;
  }
    
  // Nに寄った場合
  //ll a_tmp, b_tmp;
  ll cnt2 = n - b; // まずbがnに行く
  b_tmp = n;
  a_tmp = a + (n - b);

  // bがnに留まる
  ++a_tmp;
  ++cnt2;
#ifdef DBG
  cout << "N" << endl;
  cout << "a_tmp = " << a_tmp << " " << flush;
  cout << "b_tmp = " << b_tmp << " " << endl;
#endif
  // b_tmpがすでに1であれば？
  if(b_tmp == 1){
  } else {
    cnt2 += (b_tmp - a_tmp) / 2;
  }

  if(cnt1 < cnt2){
    ans = cnt1;
  } else {
    ans = cnt2;
  }

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

  


Measured memory_bytes: 256
#pragma warning disable

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics;
using System.Numerics;
using System.Collections;

static class MainClass
{
    public static void Main(string[] args)
    {
        var NY = Console.ReadLine().SplittedStringToInt32List();
        var N = NY[0];
        var Y = NY[1];

        var isok = false;
        for (int i = 0; i <= N; i++)
        {
            for (int j = 0; j <= N - i; j++)
            {
                var sum = i * 10000l + j * 5000l;
                if (Y - sum >= 0 && (Y - sum)/1000 == N - i - j)
                {
                    Console.WriteLine($"{i} {j} {N - i - j}");
                    isok = true;
                    break;
                }
            }
            if (isok)
                break;
        }
        if (!isok)
            Console.WriteLine("-1 -1 -1");
        Console.ReadLine();
    }
    

    #region ライブラリ
    public static long ToInt64(this string str) => long.Parse(str);
    public static int ToInt32(this string str) => int.Parse(str);
    public static BigInteger ToBigInteger(this string str) => BigInteger.Parse(str);
    public static List<string> SplittedStringToList(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
    public static List<int> SplittedStringToInt32List(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x)).ToList();
    public static List<long> SplittedStringToInt64List(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => long.Parse(x)).ToList();
    public static List<BigInteger> SplittedStringToBigInteger(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => BigInteger.Parse(x)).ToList();
    public const int INF = int.MaxValue / 2;
    public const long LONGINF = long.MaxValue / 2;
    
  
  

    public static void PrintArray(int[,] array)
    {
        for (int i = 0; i < array.GetLength(0); i++)
        {
            var sb = new StringBuilder();
            for (int j = 0; j < array.GetLength(1); j++)
            {
                sb.Append(array[i, j]).Append(" ");
            }
            Console.WriteLine(sb.ToString());
        }
    }

    #endregion
}



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

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
//typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define NP(X,Y) next_permutation(X,Y)
#define setdouble(X,Y) cout<<fixed<<setprecision(X)<<Y
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int H,W,K;
int A[15][1010];


signed main(){
	cin>>H>>W>>K;
	REP(i,H){
		string s;
		cin>>s;
		REP(j,s.size()){
			A[i][j]=s[j]-'0';
		}
	}
	int L=pow2(2,H-1);
	int ans=INF;
	REP(Bit,L){
		bool B[12]={};
		bool C[1010]={};
		int cnt=0;
		REP(i,H-1){
			if(Bit&(1LL<<i)){
				B[i]=1;
				cnt++;
			}
		}
		B[H-1]=1;
		cnt++;
		vector<int> v(cnt,0);
		int M=0;
		REP(i,W){
			int cnt2=0;
			REP(j,H){
				if(A[j][i]==1){
					cnt2++;
				}
				if(B[j]==1){
					M=max(cnt2,M);
					cnt2=0;
				}
			}
		}
		if(M>K){
			continue;
		}
		REP(i,W-1){
			int cnt2=0;
			bool flag=false;
			int k=0;
			REP(j,H){
				if(A[j][i]==1){
					cnt2++;
				}
				if(B[j]==1){
					v[k]+=cnt2;
					cnt2=0;
					k++;
				}
			}
			k=0;
			cnt2=0;
			REP(j,H){
				if(A[j][i+1]==1){
					cnt2++;
				}
				if(B[j]==1){
					if(cnt2+v[k]>K){
						flag=true;
					}
					k++;
					cnt2=0;
				}
			}
			if(flag==true){
				C[i]=true;
				REP(i,v.size()){
					v[i]=0;
				}
			}
		}
		int sum=cnt-1;
		REP(i,W-1){
			if(C[i]==true){
				sum++;
				if(Bit==1){
					DEB(i)END
				}
			}
		}
		ans=min(ans,sum);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstdlib>
#define INF 100000000
#define _INF -100000000
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> P;

char field[100][101];
int h, w;
queue<P> que;
int dx[4] = { 0,0,-1,1 }, dy[4] = { -1,1,0,0 };
int ret;

void solve() {
	Loop(i, h) {
		Loop(j, w) {
			if (field[i][j] != '.') {
				que.push(P(i, j));
				char c = field[i][j];
				field[i][j] = '.';
				while (que.size() > 0) {
					P p = que.front(); que.pop();
					Loop(k, 4) {
						int a = p.first + dx[k], b = p.second + dy[k];
						if (a >= 0 && a <= h - 1 && b >= 0 && b <= w - 1 && field[a][b] == c) {
							field[a][b] = '.';
							que.push(P(a, b));
						}
					}
				}
				ret++;
			}
		}
	}
}

int main() {
	while (cin >> h >> w, h || w) {
		Loop(i, h) {
			Loop(j, w) {
				cin >> field[i][j];
			}
		}
		ret = 0;
		solve();
		cout << ret << endl;
	}
	return 0;
}

Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
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 (a>b) { a=b; return true; } return false; }

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


bool f(pair<string, int> a, pair<string, int> b){
    if (a.first == b.first){
        return a.second > b.second;
    }else{
        return a.first < b.first;
    }
}

int main(){
    int n;
    cin >> n;
    vector<pair<string, int>> sp(n);
    map<pair<string, int>, int> m;
    rep(i,n){
        string s;
        int p;
        cin >> s >> p;
        sp[i] = make_pair(s, p);
        m[sp[i]] = i;
    }
    sort(all(sp), f);
    rep(i,n) cout << m[sp[i]]+1 << endl;
    return 0;
}

Measured memory_bytes: 3552
//設定言語check
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <limits.h>
#include <algorithm>
#include <iomanip>
#include <math.h>
using namespace std;

int main(){
  int N, ans = 0, check = 0 ;
  cin >> N ;
  ans = N + N * N + N * N * N ;
  cout << ans << endl ;
  return 0 ;
}  

Measured memory_bytes: 3632
N = int(input())
L = list(map(int, [input() for i in range(5)]))
minn = min(L)
sum1 = 0
sum2 = 0
if minn < N:
    sum1 = N // minn
    sum2 = N % minn
    if sum2 == 0:
        print(sum1+5-1)
    else:
        print(sum1+5)
else:
    print(5)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define strall(v) (v).cbegin(),(v).cend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
//const long long INF = 1LL << 60;
 int INF = 500000;
 int MAX = 2050;
 ll mod = 1e9+7;


int main(){
  int a,b;
  cin >> a >> b;
  int ans = max(a+b,a*b);
  ans = max(a-b,ans);
  cout << ans << endl;

}


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


void solve(long long T, long long X){
    cout << (double)T / X << endl;

}

int main(){
    long long T;
    scanf("%lld",&T);
    long long X;
    scanf("%lld",&X);
    solve(T, X);
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

class A{
  static void Main(){
    var s = Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
    var c = 0;
    for(int i = 0;i < s[0];i++){
      var e = Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
      if(e[0] >= s[1] && e[1] >= s[2]) c++;
    }
    Console.WriteLine(c);
  }
}


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

int main(){
  int n;
  cin >> n;
  vector<int>kazu(n);
  vector<int>kasu(n);
  for(int i=0;i<n;i++){
    cin >> kazu.at(i);
    kasu.at(i)=kazu.at(i);
  }
  sort(kasu.begin(),kasu.end());
  double ty=(kasu.at(n/2)+kasu.at(n/2-1))/double(2);
  for(int i=0;i<n;i++){
    if(kazu.at(i)<ty)
      cout << kasu.at(n/2);
    else
      cout << kasu.at(n/2-1);
    cout << endl;
  }
  return 0;
}

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

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

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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  if (A <= C && C <= B)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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

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

class Prime{
public:
	vector<int> prime;
	vector<bool> is_prime;
	Prime(int n){
		prime = vector<int>(n);
		is_prime = vector<bool>(n+1,true);
		is_prime[0] = is_prime[1] = false;
		int p = 0;
		for (int i = 2;i <= n;i++){
			if(is_prime[i]){
				prime[p++] = i;
				for (int j = 2*i;j <= n;j += i)is_prime[j] = false;
			}
		}
	}
};

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

	int Q; cin >> Q;
	Prime p(100005);

	int sum[100005];
	sum[0] = 0;

	for (int i = 1;i < 100005;i++){
		sum[i] = sum[i-1];
		if(i%2 == 0) continue;
		if(p.is_prime[i] && p.is_prime[(i+1)/2]) sum[i]++;
	}

	for (int i = 0;i < Q;i++){
		int l,r; cin >> l >> r;
		cout << sum[r]-sum[l-1] << endl;
	}

	return 0;

}


Measured memory_bytes: 1408
#include<stdio.h>
 
int main()
{
  int n=0,i;
  scanf("%d",&n);
  
  int a[n],b[n],c[n],sum=0;
  
  for(i=0;i<n;i++)
  scanf("%d",&a[i]); 
  
  for(i=0;i<n;i++)
   scanf("%d",&b[i]);

  for(i=0;i<n-1;i++)
   scanf("%d",&c[i]); 
  
   sum+=b[n-1];
  for(i=0;i<n-1;i++)
  {
    sum+=b[i];
    if(a[i]+1==a[i+1])
    sum+=c[a[i]-1];
  }
  printf("%d\n",sum);
  
 return 0; 
}


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

bool chk(int bit, vector<vector<P>> &p)
{
    bool result = true;

    for (int i = 0; i < (int)p.size(); i++)
    {
        if (!(bit & (1 << i)))
        {
            continue;
        }

        for (int j = 0; j < (int)p[i].size(); j++)
        {
            int tx = p[i][j].first;
            int ty = p[i][j].second;

            if ((ty == 1 && (bit & (1 << tx))) ||
                (ty == 0 && (~bit & (1 << tx))))
            {
                continue;
            }
            else
            {
                result = false;
            }
        }
    }

    return result;
}

int main()
{
    int n;
    int a;
    vector<vector<P>> p;
    int cnt = 0, ans = 0;

    // 入力
    cin >> n;
    p.resize(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a;
        p[i].resize(a);
        for (int j = 0; j < a; j++)
        {
            cin >> p[i][j].first >> p[i][j].second;
            --p[i][j].first;
        }
    }

    // 処理
    for (int bit = 0; bit < (1 << n); bit++)
    {
        if (chk(bit, p))
        {
            cnt = 0;
            for (int i = 0; i < n; i++)
            {
                if (bit & (1 << i))
                    cnt++;
            }
            ans = max(ans, cnt);
        }
    }

    // 出力
    cout << ans << endl;

    return 0;
}


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

int main() {
	ll n,d,ans;
	cin>>n>>d;
	if(n%(2*d+1)==0)
	ans=n/(2*d+1);
	else
	ans=(n/(2*d+1))+1;
	cout<<ans;
	 
	return 0;
}

Measured memory_bytes: 256
#define DIN freopen("input.txt","r",stdin);
#define DOUT freopen("output.txt","w",stdout);
#include <bits/stdc++.h>
#include <cstdio>
#define mem(a,b) memset(a,b,sizeof(a))
#define REP(i,a,b) for(int i=(a);i<=(int)(b);i++)
#define REP_(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
using namespace std;
typedef long long LL;
typedef std::vector<int> VI;
typedef std::pair<int,int> P;
int read()
{
    int x=0,flag=1; char c=getchar();
    while((c>'9' || c<'0') && c!='-') c=getchar();
    if(c=='-') flag=0,c=getchar();
    while(c<='9' && c>='0') {x=(x<<3)+(x<<1)+c-'0';c=getchar();}
    return flag?x:-x;
}

const int maxn=5005;
int n,k,p[maxn],c[maxn];
LL ans=1e-15;

int main()
{
    n=read(),k=read();
    REP(i,1,n) p[i]=read();
    REP(i,1,n) c[i]=read();
    REP(i,1,n)
    {
        int cur=i,be=i;
        VI s;
        s.pb(cur);
        LL y=c[cur];
        cur=p[cur];
        while(cur!=be)
        {
            s.pb(cur);
            y+=c[cur];
            cur=p[cur];
        }
        LL t=0;
        for(int i=0;i<s.size();i++)
        {
            t+=c[s[i]];
            if(i>=k) break;
            LL temp=t;
            if(y>0) temp+=(k-i-1)/s.size()*y;
            ans=max(ans,temp);
        }
    }
    if(ans==0) cout<<*max_element(c+1,c+n+1);
    else cout<<ans;
    //cout<<ans;

    return 0;
}


Measured memory_bytes: 3704
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
bool prime[1000001];
bool isReach[1000001];
int main() {
	// your code goes here
	
	vector<int> p;
	p.push_back(2);
	prime[2]=true;
	for(int i=3;i<=1000000;i++){
		for(int j=0;j<p.size();j++){
			if(i%p[j]==0)
			break;
			if(p[j]*p[j]>i ||p.size()-1==j){
			p.push_back(i);
			prime[i]=true;
			break;
			}
		}
	}
	int n,budget,tmp;
	while(cin >> n >> budget && n){
		for(int i=0;i<=1000000;i++)
		isReach[i]=false;
		vector<int> cooks;
		queue<int> qu;
		for(int i=0;i<n;i++){
			cin >> tmp;
			cooks.push_back(tmp);
		}
		qu.push(0);
		int maxim=0;
		while(!qu.empty()){
			int f=qu.front();
			qu.pop();
			if(prime[f])
			maxim=max(maxim,f);
			for(int i=0;i<cooks.size();i++)
				if(f+cooks[i]<=budget && (!isReach[f+cooks[i]])){

					qu.push(f+cooks[i]);
					isReach[f+cooks[i]]=true;
				}
		}
		if(maxim)
		cout << maxim << endl;
		else
		cout << "NA" << endl;
	}
	return 0;
}

Measured memory_bytes: 3584
#include<stdio.h>
#include<string.h>
int main(){
  int i,n,j;
  char s[3];
  char t[3];
  scanf("%s",s);
  scanf("%s",t); 
  j=0;
  for(i=0;i<3;++i){
    if(s[i]==t[i])
      	j++;
  }
  printf("%d",j);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n,flag;
  int *h;
  
  cin >> n;
  
  h = new int[n];
  
  for(int i=0;i<n;i++){
    cin >> h[i];
  }
  
  if(n==1){
     cout << "Yes"<<endl;
  } 
  else{ 
    flag = 0;
 	 for(int i=(n-1);i>0&&flag!=1;i--){
       if(h[i-1]>h[i]){
         h[i-1]-=1;
         if(h[i-1]>h[i]){
           flag=1;
         }
       }
     }
    if(flag==1){
       cout << "No" << endl;
    }
    else{
       cout << "Yes"<<endl;
    }
  }  
  
  delete h;
 
}

Measured memory_bytes: 640