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

int main(void) {
	int a, b, c, d, e, x, y;
	
	scanf("%d", &a);
	scanf("%d", &b);
	scanf("%d", &c);
	scanf("%d", &d);
	scanf("%d", &e);
	
	x=a*e;
	
	if(e<=c)
	y=b;
	
	if(e>c)
	y=b+(e-c)*d;
	
	if(x<=y)
	printf("%d\n", x);
	
	if(x>y)
	printf("%d\n", y);
	return 0;
}

Measured memory_bytes: 596
#include<stdio.h>

int  a[1000][200000], count[1000] = {0}, data[100000];
int main(){
	int i, j = 0, type, t, x, n, q;
	char s[6];
	scanf("%d %d", &n, &q);

	for(i = 0; i < q; i++){
	    scanf("%d %d", &type, &t);
	    if(type == 0){
	    	scanf("%d", &x);
	    	a[t][count[t]] = x;
	    	count[t]++;
	    } else if(type == 1){
	    	if(count[t] > 0){
	    	    data[j++] = a[t][count[t] - 1];
	    	}
	    } else {
	        if(count[t] > 0){
	    	    count[t]--;
	        }
	    }
	}

	for(i = 0; i < j; i++){
		printf("%d\n", data[i]);
	}

	return 0;
}


Measured memory_bytes: 6436
#include<stdio.h>
int main(){
int m=0,n,a[2000],i,j,k,ans=0,b[1010];
  scanf("%d\n",&n);
  for(i=0;i<n;i++){
    scanf("%d\n",&a[i]);
  }
  for(i=0;i<1001;i++){
    b[i]=0;
  }
  for(i=0;i<n;i++){
    b[a[i]]++;
  }
  for(i=0;i<1001;i++){
    for(j=0;j<b[i];j++){
      a[m]=i;
      m++;
    }
  }
  for(i=0;i<n;i++){
    for(j=i+1;j<n;j++){
      for(k=j+1;k<n;k++){
        if(a[k]<a[i]+a[j] && a[i]<a[k]+a[j] && a[j]<a[i]+a[k]){
          ans++;
        }
      }
    }
  }
  printf("%d\n",ans);
return 0;
}

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

int main() {
    int n;
    long int sum = 0;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        if (i % 3 == 0 || i % 5 == 0) ;
        else sum += i;
    }
    cout << sum << endl;
    
    return 0; 
}

Measured memory_bytes: 3180
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int n;
    cin >> n;
    vector<int> l(n);
    for(int i = 0; i < n; i++){
        cin >> l[i];
    }
    sort(l.begin(),l.end());
    int ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++ ){
            for(int k = j+1; k < n; k++ ){
                if(l[i] == l[j] || l[j] == l[k]){
                    continue;
                }

                if(l[j]-l[i] < l[k] && l[k] < l[i] + l[j]){
                    ans++;
                }
            }
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3632
x1, y1, x2, y2 = map(int, input().split())
a = x2 - x1
b = y2 -y1

x3 = x2 - b
y3 = y2 + a
x4 = x1 - b
y4 = y1 + a
print("{} {} {} {}".format(x3, y3, x4, y4))

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <limits>
#include <stack>
#include <queue>
#include <map>
#include <set>

using namespace std;

using ll = long long;
using ui = unsigned int;
const ll MOD = 1000000007;
const ll INF = 9223372036854775807;

//C

//B
int main() {
	ll N;
	scanf("%lld", &N);

	bool result = false;

	for (ll i = 1; i <= 9; i++) {
		if (N % i == 0 && N / i <= 9) {
			result = true;
			break;
		}
	}

	if (result == true) {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}
}


//A
/*
int main() {
	ll A;
	scanf("%lld", &A);
	ll B;
	scanf("%lld", &B);

	ll result = 0;

	if (A <= 9 && B <= 9) {
		result = A * B;
	}
	else {
		result = -1;
	}

	printf("%lld\n", result);
}
*/


Measured memory_bytes: 256
#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 K, N;
    cin >> K >> N;
    vector<int> A(N);
    rep(i,N) cin >> A.at(i);
    int dis_max = 0;

    sort(A.begin(), A.end());
    A.push_back(K + A.at(0));
    rep(i,N) {
        dis_max = max(dis_max, abs(A.at(i) - A.at(i + 1)));
    }
    cout << K - dis_max << endl;
}


Measured memory_bytes: 4764
n,k=map(int,input().split())
A=list(map(int,input().split()))

ans=float("inf")
for i in range(n-k+1):
    l,r=i,i+k-1
    ans=min(ans,abs(A[r]-A[l])+abs(A[r]),abs(A[l])+abs(A[l]-A[r]))
print(ans)

Measured memory_bytes: 15020
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <cassert>
#include <queue>
#include <ctime>
#include <string>
#include <cstring>
#define mp make_pair
#define pb push_back
#define NAME ""
#define y1 y1_423
#define list lista

using namespace std;

typedef long long ll;
typedef long double ld;

template<typename T>
ostream& operator << (ostream& cout, const vector<T> &a) {
	if ((int)a.size() == 0) {
		return (cout << "()");
	}
	cout << "(" << a[0];
	for (int i = 1; i < (int)a.size(); i++) {
		cout << "; " << a[i];
	}
	return (cout << ")");
}

template<typename T>
ostream& operator << (ostream& cout, const set<T> &a) {
	if ((int)a.size() == 0) {
		return (cout << "{}");
	}
	auto it = a.begin();
	cout << "{" << *it;
	++it;
	for (; it != a.end(); ++it) {
		cout << "; " << *it;
	}
	return (cout << "}");
}

template<typename T>
ostream& operator << (ostream& cout, const multiset<T> &a) {
	if ((int)a.size() == 0) {
		return (cout << "{}");
	}
	auto it = a.begin();
	cout << "{" << *it;
	++it;
	for (; it != a.end(); ++it) {
		cout << "; " << *it;
	}
	return (cout << "}");
}

template<typename T1, typename T2>
ostream& operator << (ostream& cout, const pair<T1, T2> &a) {
	return cout << "(" << a.first << "; " << a.second << ")";
}

const int nmax = 2000 * 1000;
const int inf = 2000 * 1000 * 1000;
const ll infl = 1000ll * 1000ll * 1000ll * 1000ll * 1000ll * 1000ll;
const int mod = 1000 * 1000 * 1000 + 7;
const ld pi = acos(-1.0);

string s, s1;

int main() {
	//freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
	//freopen(NAME".in", "r", stdin);freopen(NAME".out", "w", stdout);
	getline(cin, s);
	reverse(s.begin(), s.end());
	int ind = 0;
	while (ind < (int)s.length()) {
		s1 = "";
		if (s[ind] == 'r') {
			for (int i = ind; i < min((int)s.length(), ind + 6); i++) {
				s1 += s[i];
			}
			reverse(s1.begin(), s1.end());
			if (s1 == "eraser" || (s1 == "reamer" && (ind + 6 < (int)s.length() && s[ind + 6] == 'd'))) {
				ind += (s1 == "eraser" ? 6 : 7);
			} else {
				cout << "NO\n";
				return 0;
			}
		} else {
			for (int i = ind; i < min((int)s.length(), ind + 5); i++) {
				s1 += s[i];
			}
			reverse(s1.begin(), s1.end());
			if (s1 == "dream" || s1 == "erase") {
				ind += 5;
			} else {
				cout << "NO\n";
				return 0;
			}
		}
	}
	cout << "YES\n";
	return 0;
}


Measured memory_bytes: 640
<?php
$n = trim(fgets(STDIN));
$a = 0;

for ($i = 1; $i <= strlen($n); $i++) {
    if ($i === strlen($n)) {
        $a = $a + (int)substr($n, -$i, 1);
        break;
    }

    if ((int)substr($n, -$i, 1) === 9) {
        $a = $a + 9;
    } else {
        $a = $a + 9;
        $n = $n - pow(10, $i);
    }
}

echo $a . "\n";

Measured memory_bytes: 3828
import os, sys
import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")
 
sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10**18
MOD = 10**9 + 7

def N(): return int(sys.stdin.readline())
def li(): return list(map(int, sys.stdin.readline().split()))
def bulk_li(): return list(map(lambda s: list(map(int, s.split())), sys.stdin.readlines()))

n = N()
hs = np.array(li())

hs_diff = hs[1:] - hs[:-1]
# print(hs_diff)

result = 'Yes'
flg = 0
for diff in hs_diff:
  if diff < -1:
    result = 'No'
  elif diff == -1 and flg == 1:
    result = 'No'
  elif diff == -1:
    flg = 1
  elif diff == 0 and flg == 1:
    flg = 1
  else:
    flg = 0

print(result)


Measured memory_bytes: 23120
#include <iostream>

using namespace std;

int main() {
  int n, h, w;
  int count = 0;
  cin >> n >> h >> w;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    if (a >= h && b >= w) count++;
  }
  cout << count << endl;
}


Measured memory_bytes: 256
import itertools
import math
n = int(input())
lis = [x for x in range(n)] 
permutations_lis = itertools.permutations(lis)
adjacent = []
for i in range(n):
  x, y = map(int, input().split())
  adjacent.append([x, y])
length = 0
for j in permutations_lis:
    lengthX = 0
    for i in range(n-1):
        a = j[i]
        b = j[i+1]
        ax, ay = adjacent[a]
        bx, by = adjacent[b]
        lengthX += math.sqrt((ax-bx)**2+(ay-by)**2)
    length += lengthX
print(length/math.factorial(n))

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string s[n];
  int p[n];
  for(int i = 0; i < n; i++) {
    cin >> s[i] >> p[i];
  }
  int ans[n];
  for(int i = 0; i < n; i++) {
    ans[i] = i + 1;
  }
  bool f = 0;
  while(1) {
    if(f) break;
    f = 1;
    for(int i = 0; i < n - 1; i++) {
      if(s[i] > s[i + 1]) {
        swap(ans[i], ans[i + 1]);
        swap(s[i], s[i + 1]);
        swap(p[i], p[i + 1]);
        f = 0;
      } else if(s[i] == s[i + 1]) {
        if(p[i] < p[i + 1]) {
          swap(ans[i], ans[i + 1]);
          swap(p[i], p[i + 1]);
          f = 0;
        }
      }
    }
  }
  for(int i = 0; i < n; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}


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

int main() {
  int N, Alice = 0, Bob = 0, points;

  cin >> N;
  vector<int> cards(N);
  
  for(int i = 0; i < N; i++){
    cin >> cards.at(i);
  }
  
  sort(cards.begin(), cards.end());
  reverse(cards.begin(), cards.end());
  
  for(int i = 0; i < N; i++){
    if (!(i % 2)) Alice += cards.at(i);
    else Bob += cards.at(i);
  }
  
  points = Alice - Bob;
  
  cout << points << endl;
}


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

int main(){
	int a , b;
	cin >> a >> b;
  
  	if((a+b)%2 == 0){
    	cout << (a + b) / 2 << endl;
    }
  	else{
    	cout << (a + b) / 2 + 1  << endl;
    }
  	
}

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

int main()
{
  string s;
  cin >> s;
  
  bool flag = true;
  int n = s.size();
  int ok = 0;
  if(s[0] != 'A'){
    cout << "WA" << endl;
    return 0;
  }
  
  for(int i = 2; i <= n-2; i++){
    if(s[i] == 'C'){
      ok++;
    }
  }
  if(ok != 1){
    cout << "WA" << endl;
    return 0;
  }
  
  for(int i = 0; i < n; i++){
    if(s[i] != 'A' && s[i] != 'C' && isupper(s[i])){
      cout << "WA" << endl;
      return 0;
    }
  }
  
  cout << "AC" << endl;
}

Measured memory_bytes: 3572
import java.util.*;

public class Main {
    static final int MOD = 10007;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        char[] arr = sc.next().toCharArray();
        int[][] dp = new int[n + 1][8];
        dp[0][4] = 1;
        for (int i = 1; i <= n; i++) {
            int must;
            if (arr[i - 1] == 'J') {
                must = 4;
            } else if (arr[i - 1] == 'O') {
                must = 2;
            } else {
                must = 1;
            }
            for (int j = 1; j < 8; j++) {
                for (int k = 1; k < 8; k++) {
                    if ((k & must) == 0) {
                        continue;
                    }
                    if ((j & k) == 0) {
                        continue;
                    }
                    dp[i][k] += dp[i - 1][j];
                    dp[i][k] %= MOD;
                }
            }
        }
        int total = 0;
        for (int i = 1; i < 8; i++) {
            total += dp[n][i];
            total %= MOD;
        }
        System.out.println(total);
    }
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define sd(mark) scanf("%d",&mark)
#define ss(mark) scanf("%s",&mark)
#define slld(mark) scanf("%lld",&mark)
#define clr(mark) memset(mark,0,sizeof(mark))
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define sz(x) (int((x).size()))
#define PII pair<int,int>
#define PIL pair<int,long long>
#define PLL pair<long long,long long>
#define PIS pair<int,string>
#define MII map<int,int>
#define LL long long
#define FILEIO(name) \
    freopen(name".in", "r", stdin); \
    freopen(name".out", "w", stdout);
#define INF 2000000000 // 2 * 10^9
#define INFLL 1000000000000000000LL  // 10^18
#define mod 1000000007

#define N 1015

void solve()
{
    int i,n,a[N];
    sd(n);
    n<<=1;
    for(i=0;i<n;++i)
    {
        sd(a[i]);
    }
    sort(a,a+n);
    int rs = 0;
    for(i=n-2;i>=0;i-=2)
    {
        rs += a[i];
    }
    printf("%d\n",rs);
}



int main()
{
    int t = 1;
    //scanf("%d",&t);
    while(t--)
    {
        solve();
    }
}



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

using namespace std;

int n;
vector<int> a(16);
vector<int> gd[16];
vector<int> bd[16];

bool fine(int x) {
	vector<int> ach, bure;
	for(int i = 0; i < n; i++) {
		if(! (x & (1 << i))) {
			bure.push_back(i+1);
			continue;
		}
		ach.push_back(i+1);
		for(auto j : gd[i+1]) {
			ach.push_back(j);
		}
		for(auto j : bd[i+1]) {
			bure.push_back(j);
		}
	}
	vector<int> quality(n+1);
	for(auto i : ach) quality[i] = 1;
	for(auto j : bure) if(quality[j]) return false;
	return true;
}

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

	cin >> n;

	for(int i = 1; i <= n; i++) {
		cin >> a[i];
		int u, v;
		for(int j = 0; j < a[i]; j++) {
			cin >> u >> v;
			if(v == 1) gd[i].push_back(u);
			else bd[i].push_back(u);
		}
	}

	int ans = 0;

	for(int i = 0; i < (1 << n); i++) {
		if(fine(i)) {
			ans = max(ans, __builtin_popcount(i));
		}
	}

	cout << ans << '\n';


	return 0;
}

Measured memory_bytes: 256
import heapq


change = []
n, m = map(int, input().split())
a = [-1 * int(i) for i in input().split()]
for i in range(m):
    b, c = map(int, input().split())
    change.append([-c, b])

total = 0
heapq.heapify(change)
heapq.heapify(a)
flg = False
cnt = 0
while cnt < n:
    if change:
        atmp = -1 * a[0]
        btmp = -1 * change[0][0]
        if atmp <= btmp:
            b, c = heapq.heappop(change)
            while c > 0 and cnt < n:
                total -= b
                c -= 1
                cnt += 1
        else:
            aa = heapq.heappop(a)
            total -= aa
            cnt += 1
    else:
        aa = heapq.heappop(a)
        total -= aa
        cnt += 1
        
print(total)

Measured memory_bytes: 28252
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

int main() {
	ll r,d,x;
	cin>>r>>d>>x;
	for(ll i=0;i<10;i++){
		x=r*x-d;
		cout <<x<<endl;
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 3604
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {
	
	public static void main(String[] args) throws IOException {	
		try(final Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			
			for(int i = 1; i <= N; i++) {
				final int cost = i * 108 / 100;
				
				if(cost == N) {
					System.out.println(i);
					return;
				}
			}
			
			System.out.println(":(");
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
		

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}

Measured memory_bytes: 21204
num = int(input())
work = []
for i in range(num):
    work.append(list(map(int,input().split(' '))))
work.sort(key = lambda a: a[1])
time = 0
limit  = 0
cant_flg = 0
for w in work:
    limit = w[1]
    time += w[0]
    if(limit<time):
        print('No')
        cant_flg = 1
        break
if(cant_flg==0):
    print('Yes')


Measured memory_bytes: 53728
#include<bits/stdc++.h>
#define fo(i,a,b)for(int i=a,_e=b;i<=_e;++i)
#define fd(i,a,b)for(int i=b,_e=a;i>=_e;--i)
#define put putchar
#define ll long long
using namespace std;
const int N=2e5+5,M=1e6+7;
const ll mo=23333333333333333LL;
int n,k;
int p[N],ans;
ll v[N],pre[N],suf[N];
struct nod{
	int sz;
	ll ha;
}t[N*4];
map<ll,bool>A;
ll z;
inline ll mult(ll x,ll y){
	z=x*y-(ll)((long double)x*y/mo)*mo;
	return z<0?z+mo:(z>=mo?z-mo:z);
}
void hb(nod &z,nod x,nod y){
	z.sz=x.sz+y.sz;
	z.ha=(mult(x.ha,v[y.sz])+y.ha)%mo;
}
void add(int v,int l,int r,int x){
	if(l==r){
		if(t[v].sz)t[v].sz=0,t[v].ha=0;
		else t[v].sz=1,t[v].ha=x+1;
		return;
	}
	int m=l+r>>1;
	if(x<=m)add(v*2,l,m,x);else add(v*2+1,m+1,r,x);
	hb(t[v],t[v*2],t[v*2+1]);
}
ll get(int x){
	ll a=pre[x-1];
	a=(mult(a,v[k])+t[1].ha)%mo;
	a=(mult(a,v[n-(x-1+k)])+suf[x+k])%mo;
	return a;
}
int main(){
	cin>>n>>k;
	fo(i,1,n)scanf("%d",&p[i]);
	v[0]=1;
	fo(i,1,n)v[i]=mult(v[i-1],M);
	fo(i,1,n)pre[i]=(mult(pre[i-1],M)+p[i]+1)%mo;
	fo(i,1,n)suf[i]=(pre[n]-mult(pre[i-1],v[n-i+1])+mo)%mo;
	fo(i,1,k)add(1,0,n-1,p[i]);
	A.clear();
	A[get(1)]=1;
	fo(i,k+1,n){
		add(1,0,n-1,p[i-k]);
		add(1,0,n-1,p[i]);
		A[get(i-k+1)]=1;
	}
	ans=A.size();
	cout<<ans;
}

Measured memory_bytes: 28672
def find(scores):
    for score in scores:
        if score % 10 != 0: return score
    return -1

def solve(scores):
    x = find(scores)
    if x == -1: return 0

    total = sum(scores)
    return total if total % 10 != 0 else total - x

if __name__ == '__main__':
    n = int(input())
    scores = list(sorted(int(input()) for _ in range(n)))
    print(solve(scores))


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

int main() {
  int N,Y;
  cin>>N>>Y;
  int res10000=-1,res5000=-1,res1000=-1;
  bool find=false;
  for (int i=0;i<=N;++i){
    for (int j=0;j<=(N-i);++j){
      int sum=10000*i+5000*j+1000*(N-i-j);
      if (Y==sum) {
        res10000=i;
        res5000=j;
        res1000=N-i-j;
        find=true;
      }
      if (find) break;
    }
    if (find) break;
  }
  cout<<res10000<<" "<<res5000<<" "<<res1000<<endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;

int main(){
	
	string str;
	cin >> str;
	
	str[3] = '8';
	
	cout << str << endl;
	
	return 0;
}

Measured memory_bytes: 256
<?php
class Line {
    protected $lineData;
    protected $pointer;
    public function __construct(array $line)
    {
        $this->lineData = $line;
        $this->pointer = 0;
        $this->count = count($line);
    }

    public function next()
    {
        if ($this->count > $this->pointer) {
            return $this->lineData[$this->pointer++];
        }
        return false;
    }

    public function getData()
    {
        return $this->lineData;
    }
}

class IOW {
    /**
     * @return Line
     */
    public static function nl()
    {
        $str = trim(fgets(STDIN));
        return new Line(explode(' ', $str));
    }

    public static function out($data)
    {
        print_r ($data . PHP_EOL);
    }
}

$shopCount = IOW::nl()->next();

$result = [];
for ($i = 0;$i < $shopCount; $i++) {
    $line = IOW::nl();
    $city = $line->next();
    $point = $line->next();
    $result[$city][$point] = $i;
}

foreach ($result as $city => $pointList) {
    krsort($result[$city]);
}
ksort($result);

foreach ($result as $city => $pointList) {
    foreach ($pointList as $shopNum) {
        IOW::out($shopNum + 1);
    }
} 

Measured memory_bytes: 4728
import bisect

n=int(input())
a=[int(i) for i in input().split(" ")]
b=[int(i) for i in input().split(" ")]
c=[int(i) for i in input().split(" ")]

a.sort()
c.sort()
lc=len(c)
print(sum([(lc-bisect.bisect_right(c,j))*(bisect.bisect_left(a,j)) for j in b]))

Measured memory_bytes: 22592
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long mod = 1e9+7;
map<ll,ll> dp;

long long f(long long n) {
        if(dp[n])       return dp[n];
        return dp[n] =  (f(n/2)+f((n-1)/2)+f((n-2)/2))%mod;
}

long long solution(long long n) {
        return f(n)%mod;
}

int main() {
        long long n;
        cin>>n;
        dp[0] = 1;
        dp[1] = 2;
        cout<<solution(n)<<endl;
        return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const LL LLINF = 1e16;

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

int main(){
    LL L, R;
    cin >> L >> R;
    LL ans = INF;
    for(LL i=L; i<=min(R, L+2019); i++){
        for(LL j=i+1; j<=min(R, L+2019); j++){
            ans = min(ans, ((i%2019)*(j%2019))%2019);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

s64 mypow(s64 x, s64 n)
{
    s64 ret = 1;
    while (n > 0)
    {
        if (n & 1) ret = (ret * x) % MOD;
        x = (x * x) % MOD;
        n >>= 1;
    }
    return ret;
}

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

    s64 N;
    cin >> N;
    vs64 c(N);
    rep (i, N)
    {
        cin >> c[i];
    }
    sort(c.begin(), c.end());

    s64 ans = 0;
    s64 z = mypow(2, N - 2);
    s64 y = mypow(2, N - 1);
    s64 x = mypow(2, N);
    for (s64 i = 1; i <= N; ++i)
    {
        ans += c[i - 1] * ((y + (N - i) * z % MOD) % MOD) % MOD;
        ans %= MOD;
    }

    cout << x * ans % MOD << "\n";
    return 0;
}



Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define N 100002
using namespace std;
int n,a,b,d[N],ans;

int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a>>b;
    for(int j=a;j<=b;j++)d[j]++;
  }
  ans=1;
  for(int i=n+1;i>=2;i--)
    if(d[i]>=i-1)ans=max(ans,i);
  cout<<ans-1<<endl;
  return 0;
}

Measured memory_bytes: 1548
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        int H = in.nextInt();
        int[] a = new int[N];
        int[] b = new int[N];
        for(int i = 0; i < N; i++){
            a[i] = in.nextInt();
            b[i] = in.nextInt();
        }
        Arrays.sort(a);
        Arrays.sort(b);
        int count = 0;
        for (int i = N-1; i >= 0; i--){
            if(a[N-1] < b[i]){
                H -= b[i];
                count++;
                if (H <= 0){
                    break;
                }
            }
        }
        while(H > 0){
            H -=a[N-1];
            count++;
        }


        System.out.println(count);

        in.close();
    }
}


Measured memory_bytes: 79248
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

typedef pair<int, int> pii;

int main(){
  int N;

  cin >> N;

  vector<pii>A(N);

  for(int i=0;i<N;i++){
    int t;
    cin >> t;
    A.at(i) = make_pair(t, i);
  }
  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());


  for(int i=0;i<N;i++){
    if(i != A.at(0).second)  cout << A.at(0).first << endl;
    else cout << A.at(1).first << endl;
  }
}



Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, k;
    cin >> n >> k;
    int ans = 0;
    int x;
    for (int i=0; i<n; i++) {
        cin >> x;
        if (x * 2 <= (k-x) * 2) {
            ans += x * 2;
        } else {
            ans += (k-x) * 2;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
 
class TEST{
	static void Main(){
		while(true){
			var d=Array.ConvertAll(Console.ReadLine().Split(' '),e=>int.Parse(e));
			if(d[0]==0)break;
			Sol mySol =new Sol(d);
			mySol.Solve();
		}
	}
}

class Sol{
	public void Solve(){
		int mod=100000;
		int[][] dp=new int[N*N+1][];
		for(int i=0;i<=N*N;i++){
			dp[i]=new int[S+1];
		}
		
		dp[0][0]=1;
		for(int j=1;j<=M;j++){
			for(int i=N*N-1;i>=0;i--){
				for(int s=0;s+j<=S;s++){
					dp[i+1][j+s]+=dp[i][s];
					if(dp[i+1][j+s]>=mod)dp[i+1][j+s]-=mod;
				}
			}
		}
		Console.WriteLine(dp[N*N][S]);
		
		
		
	}

	int N;
	int M;
	int S;

	public Sol(int[] d_){
		N=d_[0];M=d_[1];S=d_[2];
	}




	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(){return Console.ReadLine().Split(' ');}
	static int[] ria(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>int.Parse(e));}
	static long[] rla(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>long.Parse(e));}
	static double[] rda(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>double.Parse(e));}
}

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

int main() {
  ll N, K;
  cin >> N >> K;

  ll ans = 0;
  for (ll i = 0; i < N; i++) {
    ll tmp;
    cin >> tmp;
    if (tmp >= K) ans++;
  }

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


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);
#define FO cout.tie(NULL);
#define FI cin.tie(NULL);
#define IN cin>>
#define OUT cout<<
#define loop(i,a,n) for(int i=a; i<n; i++)
#define rloop(i,a,n) for(int i=a; i>=n; i--)
#define endl "\n";
#define pb push_back
#define mp make_pair
#define set_bits(a) __builtin_popcount(a)
#define ll long long int
#define ld long double
#define vll vector<long long int>
#define pll pair<long long int, long long int>
#define mod 1000000007
#define M 998244353
ll gcd(ll a, ll b)
{
    return (b?gcd(b,a%b):a);
}
ll P(ll B, ll power, ll modulo)
{
    ll ans=1LL;
    while(power>0LL)
    {
        if(power%2LL==1LL)
        {
            ans=(ans*B)%modulo;
        }
        B=(B*B)%modulo;
        power/=2LL;
    }
    return ans;
}
bool isPrime(ll n)
{
    if(n<=1LL)
    {
        return false;
    }
    if(n<=3LL)
    {
        return true;
    }
    if(n%2==0LL || n%3==0LL)
    {
        return false;
    }
    for(ll i=5LL; (i*i)<=n; i+=6LL)
    {
        if(n%i==0LL || n%(i+2LL)==0LL)
        {
            return false;
        }
    }
    return true;
}
using namespace std;
bool sortbysec(const pair<int,int> &a, const pair<int,int> &b)
{
    return (a.second<b.second);
}
bool sortbysecll(const pll &a, const pll &b)
{
    return (a.second<b.second);
}
ll modinv(ll x, ll y, ll modulo)
{
    return ((x%modulo)*(P(y,modulo-2LL,modulo)%modulo))%modulo;
}
int main()
{
    FAST
    FO
    FI
    int n,m;
    IN n>>m;
    int ans;
    if(n!=0)
    {
        ans= n*(n-1);
        ans/=2;
    }
    if(m!=0)
    {
        int temp=m;
        temp*=(m-1);
        temp/=2;
        ans+=temp;
    }
    OUT ans;
    return 0;
}


Measured memory_bytes: 256
//author : raghav_0901
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
//#define int long long int
#define f(i,s,e) for(i=s;i<e;++i)
#define fr(i,s,e) for(i=s;i>=e;i--)
#define all(x) (x).begin(),(x).end()
#define all_r(x) (x).rbegin(),(x).rend()
#define _in(v) for(auto &x:v) cin>>x;
#define ffr(i,s,e,f) for(i=s;i>=e && f;i--)
#define ff(i,s,e,f) for(i=s;i<e && f;++i)
#define mem(arr,val) memset(arr, val, sizeof(arr));
#define _out(v) for(auto x:v) cout<<x<<' '; cout<<'\n';
#define ARENA ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
 
const int lim = 1000000;
const int mod = 1e9;

typedef vector<double> vec;
typedef pair<int,int> pr;

//-----------------------------------------functions---------------------------------------------------------------------------------
int gcd(int a,int b) { return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b/gcd(a,b);}
inline int n_sum(int n){return (n*(n+1))/2;}
int power(int a,int b){int res=1;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a;a=a*a;}return res;}
int powmod(int a,int b){int res=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int gcdExtended(int a,int b,int &x,int &y){if(a==0){x=0;y=1;return b;}int x1,y1,gcd=gcdExtended(b%a,a,x1,y1);x=y1-((b/a)*x1);y=x1;return gcd;}
int modInv(int a,int m){int x,y;gcdExtended(a,m,x,y);return (x%m + m)%m;}
int divM(int a,int b){return (modInv(b,mod)*(a%mod))%mod;}
//------------------------------------------------------------------------------------------------------------------------------------


void _main(void)
{
    int i,num,n,m;cin>>n;
    map<int,int> mp;
    f(i,1,n)
    {
        cin>>num;mp[num]++;
    }
    f(i,1,n+1)
        cout<<mp[i]<<endl;
    return;
} 

signed main(void)
{
    ARENA
    int t=1,i;//cin>>t;
    f(i,1,t+1)
    {
        //cout<<"Case #"<<i<<": ";
        _main();
    }
    return 0;
}


Measured memory_bytes: 13024
#include<bits/stdc++.h>
using namespace std;
int arr[12005],as[105][105];
main()
{
	int m,n,a;
    scanf("%d%d%d",&m,&n,&a);
    for(int i = 1;i <= a;i++)
    {
        scanf("%d",&arr[i]);
    }
    int po=1;
    for(int i = 1;i <= m;i++)
    {
        if(i%2==0)
        {
            for(int j = 1;j <= n;j++)
            {
                if(arr[po]==0)
                po++;
                as[i][j]=po;
                arr[po]--;
            }
        }
        else
        {
            for(int j = n;j >= 1;j--)
            {
                if(arr[po]==0)
                po++;
                as[i][j]=po;
                arr[po]--;
            }
        }
    }
    for(int i = 1;i <= m;i++)
    {
        for(int j = 1;j <= n;j++)
        {
            printf("%d ",as[i][j]);
        }
        printf("\n");
    }
}


Measured memory_bytes: 384
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cstring>
#include <cmath>
#include <climits>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <array>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define io() ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define fi first
#define se second
#define IN(i,l,r) (l<i&&i<r)
#define LINR(i,l,r) (l<=i&&i<=r)
#define LIN(i,l,r) (l<=i&&i<r)
#define INR(i,l,r) (l<i&&i<=r)
#define v(T) vector<T>
#define p(T, N) pair<T, N>
#define tp(A, B, C) tuple<A, B, C>
#define ii p(int, int)
#define vi v(int)
#define vii v(p(int, int))
#define vvi v(v(int))
#define vl v(long long)
#define vll v(p(long long, long long))
#define si set<int>
#define msi map<string, int>
#define rsz(a) resize(a)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define qsort(a) sort(all(a))
#define qsortd(a) sort(all(a), greater<>())
#define qsortf(a, f) sort(all(a), f)
#define qsortsi(v) sort(v.begin(), v.end(), [](pair<int, int> a, pair<int, int> b){return a.se < b.se;})
#define pb(n) push_back(n)
#define eb(n) emplace_back(n)
#define pp(a, b) emplace_back(make_pair(a, b))
#define pt(a, b, c) emplace_back(make_tuple(a, b, c))
#define elif else if
#define fori(i, n) for(ll i = 0; i < n; ++i)
#define foris(i, a, b) for(ll i = a; i < b; ++i)
#define forise(i, a, b) for(ll i = a; i <= b; ++i)
#define ford(i, n) for(ll i = n; i >= 0; --i)
#define fords(i, a, b) for(ll i = a; i >= b; --i)
#define fordse(i, a, b) for(ll i = a; i > b; --i)
#define fora(i, a) for (auto &i: a)
#define rev(a) reverse(a.begin(), a.end())
#define revf(a, b, c) (reverse(a.begin() + b, a.begin() + c))
#define umap unordered_map
#define uset unordered_set
#define pq(T) priority_queue<T>
#define rpq(T) priority_queue<T, vector<T>, greater<T> >
#define nl '\n'
#define fileio(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout)
const int mod = 1000000007;
int digits(int n) {
  n = abs(n);
  if(n < 10) return 1;
  elif(n < 100) return 2;
  elif(n < 1000) return 3;
  elif(n < 10000) return 4;
  elif(n < 100000) return 5;
  elif(n < 1000000) return 6;
  elif(n < 10000000) return 7;
  elif(n < 100000000) return 8;
  elif(n < 1000000000) return 9;
  else return 10;
}

bool palin(string str) {
  for(int i = 0, k = str.size() - 1; i <= k; ++i, --k) {
    if(str[i] != str[k]) {
      return false;
    }
  }
  return true;
}

int main() {
  io();
  
  string s;
  cin >> s;
  bool a = palin(s);
  int n1 = (s.size() - 1)/2;
  int n2 = (s.size() + 2)/2;
  bool b = palin(s.substr(0, n1));
  bool c = palin(s.substr(n2));
  if(a && b && c) cout << "Yes";
  else cout << "No";
  
  return 0;
}

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


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n, t;
    cin >> n >> t;
    if(n-t>=0) cout << n-t;
    else cout << 0;
    return 0;
}

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

#define M 1046527
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key % M; }
int h2(int key){ return 1 + (key % (M - 1)); }

int find(char str[]){
  long long key,i,h;
  key = getKey(str);
  for(i=0;;i++){
    h = (h1(key) + i*h2(key)) %M;
    if(strcmp(H[h],str) == 0)return 1;
    else if (strlen(H[h]) == 0)return 0;
  }
  return 0;
}

int insert(char str[]){
  long long key,i,h;
  key = getKey(str);
  for(i=0;;i++){
    h = (h1(key) + i*h2(key)) %M;
    if(strcmp(H[h],str) == 0)return 1;
    else if (strlen(H[h]) == 0){
      strcpy(H[h],str);
      return 0;
    }
  }
  return 0;
}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);
	
	if ( com[0] == 'i' ){
	    insert(str);
	} else {
	    if (find(str)){
		printf("yes\n");
	    } else {
		printf("no\n");
	    }
	}
    }

    return 0;
}



Measured memory_bytes: 16048
n=int(input())
ans=n
for i in range(0,n+1,6):
    cnt=0
    j=n-i
    while i>0:
        cnt+=i%6
        i//=6
    while j>0:
        cnt+=j%9
        j//=9
    ans=min(ans,cnt)
print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<iomanip>

using namespace std;
using ll = long long;

const int MOD = 1e9 + 7;
const int INF = numeric_limits<int>::max();
const ll LLINF = numeric_limits<ll>::max();
const double PI = acos(-1.0);

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, a, n) for (int i = a; i <= (n); ++i)

int main() {
    int N, A, B; cin >> N >> A >> B;
    int D = B - A;    

    if (D & 1) cout << "Borys" << endl;
    else cout << "Alice" << endl;
    return 0;
}


Measured memory_bytes: 256
N = gets.to_i
as = gets.split.map(&:to_i)

as << 0 if as.size.odd?

a, b = (
  as
    .sort
    .reverse
    .each_slice(2)
    .to_a
    .transpose
    .map { |row| row.reduce(&:+) }
)

puts a - b


Measured memory_bytes: 1788
from collections import deque
n, q = map(int, input().split())
g = [[] for _ in range(n)]
for _ in range(n-1):
    a, b = map(int, input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)
c = [0]*n
for _ in range(q):
    p, x = map(int, input().split())
    c[p-1] += x
used = [0]*n
used[0] = 1
next = deque([0])
while next:
    v = next.popleft()
    cost = c[v]
    for nv in g[v]:
        if used[nv]:
            continue
        used[nv] = 1
        c[nv] += cost
        next.append(nv)

print(*c)

Measured memory_bytes: 56180
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
const ll mo = 1000000007;
const ll INF = 1 << 30;
ll ans = 0;

int main()
{
ll n,r,g,b;
cin >> r>>g>>b>>n;
rep(i,n/r+1)rep(j,n/g+1){
    if((n-r*i-g*j)%b==0&&n-r*i-g*j>=0)ans++;
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifndef LOCAL
#pragma GCC optimize(3)
#endif
#define ls (rt<<1)
#define rs (rt<<1)|1
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
const int maxn=1e6+100;
const int mod=1e9+7;
ll loc[100][30];
int main() {
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    ll l, r;
    cin >> l >> r;
    if (r-l>3000) {
        cout << 0 << endl;
    } else {
        ll ans = inf;
        for (int i=l; i<=r; i++) {
            for (int j=i+1; j<=r; j++) {
                ans=min(ans, 1LL*i%2019*(j%2019)%2019);
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		java.util.Scanner sc = new java.util.Scanner(System.in);

		int[][][] house = new int[4][3][10];

		int n = sc.nextInt();
		sc.nextLine();

		for (int i = 0; i < n; i++) {
			int b = sc.nextInt();
			int f = sc.nextInt();
			int r = sc.nextInt();
			int v = sc.nextInt();

			house[b-1][f-1][r-1] += v;
		}

		StringBuilder sb = new StringBuilder();

		for (int i=0; i<4; i++) {

			for (int j=0; j<3; j++) {

				for (int k=0; k<10; k++) {
					sb.append(" " + house[i][j][k]);
				}
				sb.append("\n");

			}
			if (i==3) break;
			sb.append("####################\n");

		}

		System.out.print(sb);
	}

}

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

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



int main()
{
	int n, x;

	while (true) {
		int ans = 0;
		cin >> n >> x;
		if (n == 0 && x == 0) break;
		repc(i, 1, n - 2) repc(j, i + 1, n - 1) repc(k, j + 1, n) {
			if (i + j + k == x) ans++;
		}
		cout << ans << endl;
	}





	return 0;
}



Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 2e5+23;

int n,m,k;
int a[maxn];
int vis[maxn];
int num[maxn];
char s[5];

int main()
{
    cin>>n>>m;int ans=0,cnt=0;
    while(m--){
        int t;
        scanf("%d",&t);scanf("%s",s);
        if(vis[t]) continue;
        else if(s[0]=='A') vis[t]=1,cnt++,ans+=num[t];
        else num[t]++;
    }
    cout<<cnt<<" "<<ans;
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
#define LF '\n'
#define ALL(x) x.begin(), x.end()
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;
template<class Itr> void dump(Itr begin, Itr end) { for (;begin != end; ++begin) clog << *begin << LF; }

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

  string a,b,c;
  cin>>a>>b>>c;

  cout << (a.back() == b.front() && b.back() == c.front() ? "YES" : "NO") << LF;

  return 0;
}



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

#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#define int long long

using namespace std;

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

const int N = 200000 + 10;
const int MOD = 1000000007;
const int LOG = 20;
const ll INF = 1e18;

int n, q, seg[2][N << 2], lazy, A, B, a[N];

void Set(int ind, int id, int lq, int rq, int x, int l, int r){
	if (rq <= l || r <= lq) return;
	if (lq <= l && r <= rq){
		seg[ind][id] = x;
		return;
	}
	int md = (l + r) >> 1;
	Set(ind, id << 1, lq, rq, x, l, md);
	Set(ind, id << 1 | 1, lq, rq, x, md, r);
	seg[ind][id] = min(seg[ind][id << 1], seg[ind][id << 1 | 1]);
}

int get(int ind, int id, int lq, int rq, int l, int r){
	if (rq <= l || r <= lq) return INF;
	if (lq <= l && r <= rq){
		return seg[ind][id];
	}
	int md = (l + r) >> 1;
	return min(get(ind, id << 1, lq, rq, l, md), get(ind, id << 1 | 1, lq, rq, md, r));
}

int32_t main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> q;
	cin >> A >> B;
	memset(seg, 63, sizeof seg);
	a[0] = B;
	for (int i = 1; i <= q; i++){
		cin >> a[i];
	}
	Set(0, 1, A, A + 1, -A, 1, n + 1);
	Set(1, 1, A, A + 1, +A, 1, n + 1);
	for (int i = 1; i <= q; i++){
		int x = min(get(1, 1, a[i], n + 1, 1, n + 1) - a[i], get(0, 1, 1, a[i], 1, n + 1) + a[i]) + lazy;
		lazy += abs(a[i] - a[i - 1]);
		//cout << x << '\n';
		if (x < get(0, 1, a[i - 1], a[i - 1] + 1, 1, n + 1) + a[i - 1] + lazy){
			Set(0, 1, a[i - 1], a[i - 1] + 1, x - a[i - 1] - lazy, 1, n + 1);
			Set(1, 1, a[i - 1], a[i - 1] + 1, x + a[i - 1] - lazy, 1, n + 1);
		}
		
	}
	ll ans = INF;
	for (int i = 1; i <= n; i++){
		ans = min(ans, get(0, 1, i, i + 1, 1, n + 1) + lazy + i);
	}
	cout << ans;

	return 0;
}

Measured memory_bytes: 14464
#include<stdio.h>

int main()
{
	int w,n,r=1,s;
	int a,b,x[64];
	scanf("%d%d",&w,&n);
	for(int i=0;i<w;i++){
		x[i]=r;
		r++;
	}
	for(int i=0;i<n;i++){
		scanf("%d,%d",&a,&b);
		s=x[a-1];
		x[a-1]=x[b-1];
		x[b-1]=s;
	}
	for(int i=0;i<w;i++){
		printf("%d\n",x[i]);
	}
	return 0;
}

Measured memory_bytes: 2560
#include <cstdio>
#include <algorithm>
using namespace std;

int n,m,a,s=0;

inline int read(){
	int s=0,t=1;
	char c=getchar();
	while((c<'0'||c>'9')&&c!='-')c=getchar();
	if(c=='-')c=getchar(),t=-1;
	while(c>='0'&&c<='9')s=(s<<1)+(s<<3)+(c^48),c=getchar();
	return s*t;
}

int main(void){
	n=read();
	m=read();
	for(int i=1;i<=m;i++){
		a=read();
		s+=a;
	}
	if(s>=n)
	printf("Yes\n");
	else
	printf("No\n");
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
//define
typedef pair<int,int>pi;
#define int long long
#define elif else if
#define rep(x,y) for(int i=x;i<y;i++)
#define REP(x,y) for(int j=x;j<y;j++)
#define Rep(x,y) for(int k=x;k<y;k++)
#define all(x) x.begin(),x.end()
#define pb push_back
#define vint vector<int>
#define vvint vector<vector<int>>
#define vtr vector<string>
#define vvtr vector<vector<string>>
#define vhar vector<char>
#define vvhar vector<vector<char>>
#define mod 100000007
#define elif else if
#define str string
int sum(int a){
  int b=0;
  while(true){
    if(a>=1){
      a%=10;
      b+=a%=10;
    }
    else break;
  }
  return b;
}
signed main(){
  int N,M,O,P=0,c=0,c2=0,crash=0,nowtab=0;
  double D,D2;
  char C;
  str S,T,U;
  cin>>N>>M;
  vint p(M);
  vtr s(M);
  vint B(N);rep(0,N)B[i]=0;
  rep(0,M){
    cin>>p[i]>>s[i];
  }
  rep(0,M){
    if(B[p[i]-1]==0&&s[i]=="AC"){
      B[p[i]-1]=1;
      c++;
    }
    else if(B[p[i]-1]==0&&s[i]=="WA"){
      c2++;
    }
  }
  rep(0,M){
    if(B[p[i]-1]==0&&s[i]=="WA")crash++;
  }
  cout<<c<<" "<<c2-crash<<endl;
}


Measured memory_bytes: 7296
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <list>
#include <stack>

using namespace std;

/* constant */

const int INF = 1 << 30;
const int mod = 1000000007;
const double pi = 3.141592653589;

/* typedef */

typedef long long ll;

/* global variables */

/* function */

/* main */
int main() {

    int n; cin >> n;
    map<char, int> m;
    m['S'] = 1;
    m['H'] = 2;
    m['C'] = 3;
    m['D'] = 4;
    map<int, char> m2;
    m2[1] = 'S';
    m2[2] = 'H';
    m2[3] = 'C';
    m2[4] = 'D';


    vector< vector<int> > T(5, vector<int>(14, 0));

    for (int i = 0; i < n; i++) {
        char mark; int num;
        cin >> mark >> num;
        int mark_num = m[mark];
        T[mark_num][num] = 1;
    }
    for (int i = 1; i < 5; i++) {
        for (int j = 1; j < 14; j++) {
            if (T[i][j] == 0) {
                cout << m2[i] << ' ' << j << '\n';
            }
        }
    }

}



Measured memory_bytes: 3160