akhauriyash/Code-Regression huggingface dataset:
#この方法だとTLEになるためNG

from pprint import pprint
from copy import deepcopy

#N <= 10**5なので、全探索はNG
#Greedyでいける？


n,m = map(int,input().split())

requests = [list(map(int,input().split())) for _ in range(m)]

#区間スケジュール問題と考え、終端が小さい順で並べる。その後Greedyで計算。
requests = sorted(requests, key=lambda x:x[1])

counter = 0
before_point = -float('inf')

#pprint(requests)

for i in range(m):
    if requests[i][0] >= before_point:
        counter += 1
        before_point = requests[i][1]
        #print("requests[{}]={} YES".format(i,requests[i]))
    else:
        #print("requests[{}]={} NO".format(i,requests[i]))
        pass

print(counter)


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

using namespace std;

int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b&&b!=c)
        cout<<"Yes\n";
    else if(a==c&&b!=c)
        cout<<"Yes\n";
    else if(c==b&&b!=a)
        cout<<"Yes\n";
    else
        cout<<"No\n";
    return 0;

}


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

#define vec vector
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define Str(x) to_string(x)
#define len(s) (int)s.size()

typedef long long ll;
typedef double d;
typedef long double lld;
typedef string str;
typedef unsigned long long ull;
typedef unsigned int ui;


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n;
    cin >> n;
    vector <int> a(n+1, 0), b(n+1, 0), v(n);
    for (auto &it : v)
        cin >> it;
    a[0] = v[0];
    b[n-1] = v.back();
    for (int i = 1; i < n; i++)
    {
        a[i] = __gcd(v[i], a[i-1]);
    }
    for (int i = n - 2; i >= 0; i--)
    {
        b[i] = __gcd(v[i], b[i+1]);
    }
    int x = 1;
    for (int i = 0; i < n; i++)
    {
        x = max(x, __gcd((i ? a[i-1] : 0), b[i+1]));
    }

    cout << x;
    return 0;
}

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

int main()
{
    int x,a,b,c;
    cin>>x;
    a=x/100;
    b=(x/10)%10;
    c=x%10;
    if(a==7||b==7||c==7) cout<<"Yes";
    else cout<<"No";
    return 0;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0; i<(int)(n); ++i)
#define REP(i,m,n) for(ll i=(ll)(m); i<(ll)(n); ++i)
#define F first
#define S second
const double PI=acos(-1);
//fixed<<setprecision(11)<<

char in[120];
pair<pair<string,int>,int> p[110];
int main(){
  int a;
  cin>>a;
  rep(i,a){
  int t;
  cin>>in>>t;
  //string tmp=in;
  p[i]=make_pair(make_pair(in,-t),i);
  }
  sort(p,p+a);
  rep(i,a) cout<<p[i].second+1<<endl;
}

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

#define EACH(i, a) for (auto &&i : a)
#define FOR(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RFOR(i, a, b) for (int i = (int)b - 1; i >= (int)a; --i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREPS(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(x) (x).begin(), (x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define debug(x) cout << #x << ": " << x << endl

#define pb push_back
#define mp make_pair
#define F first
#define S second

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define INF (1L << 30)
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

template <class T>
void pv(T a, T b) {
  for (T i = a; i != b; ++i) cout << *i << " ";
  cout << endl;
}
template <class T>
void pvp(T a, T b) {
  for (T i = a; i != b; ++i)
    cout << "(" << i->first << ", " << i->second << ") ";
  cout << endl;
}
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int in() {
  int x;
  scanf("%d", &x);
  return x;
}

using ll = long long;
#define int ll

//**********

bool test(long double a, long double b, long double c) {
  if (c - a - b == 2 * sqrt(a * b)) {
    return false;
  } else if (sqrt(a) + sqrt(b) < sqrt(c)) {
    return true;
  } else {
    return false;
  }
}

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

  long double a, b, c;
  cin >> a >> b >> c;

  // debug(test(4, 5, 17));

  if (test(a, b, c)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
};


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int compare(const void *a,const void *b){
  return *(int*)a-*(int*)b;
}
int main(){
  int n,i,r = 1,t;
  int arr[999];
  scanf("%d",&n);
  for(i = 0;i<n;i++)scanf("%d",&arr[i]);
  qsort(arr,n,sizeof(int),compare);
  t = arr[0];
  for(i = 1;i<n;i++){
    if(t != arr[i]){
      t=arr[i];
      r++;
    }
  }
  printf("%d\n",r);
  return 0;
}


Measured memory_bytes: 128
void solve();

int main() {
	solve();
	return 0;
}

//////////////////////////////////////////////////
//////////////////////////////////////////////////
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <limits.h>
#include <math.h>
#include <iomanip>
using namespace std;
typedef pair<int, int> pii;
typedef long double ld;
typedef long long ll;

void solve() {
	int A, B, C, D;
	cin >> A >> B;
	if ((A - B) % 2 == 0)cout << (A + B) / 2 << endl;
	else cout << "IMPOSSIBLE" << endl;
	return;
}

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

#define ll unsigned long long
#define INF 1234567890
#define N (int)(1e5 + 5)
#define pi acos(-1)

int t[N], cost[N];

void solve()
{
    int n, k;
    cin >> n >> k;
    for(int i = 1; i <= n; ++i) cin >> t[i];
    for(int i = 1; i <= n; ++i) cost[i] = INF;
    cost[1] = 0;
    for(int i = 2; i <= n; ++i)
        for(int j = i - 1; j >= i - k && j >= 1; --j)
        cost[i] = min(cost[i], cost[j] + abs(t[i] - t[j]));
    cout << cost[n];
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    solve();
    return 0;
}


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

using namespace std;

#define ll long long
#define ull unsigned long long
#define vll vector<ll>
#define pii pair<int, int>
#define vii vector<pii>
#define vs vector<string>
#define vb vector<bool>
#define vi vector<int>
#define vd vector<double>
#define vvi vector< vector<int> >
#define vvii vector< vector< pii > >
#define ld long double
#define mapii map<int, int>
#define mapsi map<string, int>
#define erep(i, x, n) for (auto i = x; i<=(ll)(n); i++)
#define rep(i, x, n) for(auto i = x; i<(ll)(n); i++)
#define INF  LLONG_MAX
#define all(v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
#define pie  acos(-1)
#define mod(n,m) ((n % m + m) % m)
#define eps (1e-8)
#define reset(n, m) memset(n, m, sizeof n)
#define endl '\n'
#define output freopen("output.txt", "w", stdout)
#define mp(x, y, z) {x, {y, z}}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    int mx = 0, mn = INT_MAX;
    int x;
    rep(i, 0, n)
    {
        cin >> x;
        mx = max(x, mx);
        mn = min(mn, x);
    }
    cout << mx - mn;


    return 0;
}


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

int main()
{
    int N;
    cin >> N;
    string S;
    for (int i = 0; i < N; i++)
    {
        char temp;
        cin >> temp;
        S.push_back(temp);
    }

    if (S.find("Y") != -1)
    {
        cout << "Four";
    }
    else
    {
        cout << "Three";
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
using namespace __gnu_pbds; 
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
int fc[100001], in[100001];

int pwmd(int a, int n = mod - 2)
{
	if (!n)
		return 1;
	int pt = pwmd(a, n / 2);
	pt *= pt, pt %= mod;
	if (n & 1)
		pt *= a, pt %= mod;
	return pt;
}
int nCr(int n, int r)
{
     fc[0] = in[0] = 1;

	for (int i = 1; i <= 100000; ++i)
	{
		fc[i] = (i * fc[i - 1]) % mod;
		in[i] = pwmd(fc[i]);
	}

	int ans = fc[n];
	ans = (ans * in[r]) % mod;
	ans = (ans * in[n - r]) % mod;

	return ans;
}
double pow(double a,int b)
{
	double ans=1;
	while(b>0)
	{
		if(b&1)
			ans*=a;
		a*=a;
		b=b>>1;
	}
	return ans;
}
vector<pair<int,int>> vec;
bool compare(pair<int,int> v1,pair<int,int> v2)
{
	return v1.ss<v2.ss;
}

vector<int> adj[200005];
int dis[200005];
void dfs1(int par, int u)
{
	for(int x:adj[u])
	{
		if(x==par)
			continue;
		dis[x]=dis[u]+1;
		dfs1(u,x);
	}
}

void dfs(int par, int u,bool *vis)
{
	vis[u]=true;
	for(int x:adj[u])
	{
		if(x==par)
			continue;
		dfs(u,x,vis);
		vis[x]=true;
	}
}

int32_t main()
{       
    FIO;
    string s;
    cin>>s;

    if(s[1]=='R')
    	cout<<"ABC"<<endl;
    else
    	cout<<"ARC"<<endl;
    


}

Measured memory_bytes: 8312
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};

fn main() {
    input! {
        n:usize,m:usize,
        xy:[(Usize1,Usize1);m],
    }
    let mut w = vec![1; n];
    let mut r = vec![false; n];
    r[0] = true;
    for &(x, y) in xy.iter() {
        if r[x] {
            r[y] = true;
        }
        w[x] -= 1;
        w[y] += 1;
        if w[x] == 0 {
            r[x] = false;
        }
    }
    println!("{}", r.iter().filter(|&&x| x).count());
}


Measured memory_bytes: 5124
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define ull unsigned long long
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
using namespace std;

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

    int N;
    cin >> N;
    REP(i, N) {
        int r, t;
        cin >> r >> t;
        bool b1 = (r % 100 != 0);
        bool b2 = (t % 30 != 0);
    
        int tmp = t / 30;
        int tmp2 = r / 100; 
        if(b1 && b2) {
            cout << 5*tmp + tmp2 << " " << 5*tmp + tmp2 + 1 << " " << 5*(tmp+1) + tmp2 << " " << 5*(tmp+1) + tmp2 + 1 << endl;
        } else if(b2) {
            cout << 5*tmp + tmp2 << " " << 5*(tmp+1) + tmp2 << endl;
        } else if(b1) {
            cout << 5*tmp + tmp2 << " " << 5*tmp + 1 + tmp2 << endl;
        } else {
            cout << 5*tmp + tmp2 << endl;
        }
    }
    return 0;
}


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

int main(){
	while(1){
		int n, av, max, min, sum = 0,s;
		cin>>n;
		if(n == 0) break;
			cin>>s;
			sum = s;
			max = s;
			min = s;
		for(int i = 1; i < n; i++){
			cin>>s;
			sum += s;
			if(s > max) max = s;
			if(s < min) min = s;
		}
		av = (sum - max - min)/ (n - 2);
		cout<<av<<endl;
	}
	
	return 0;
}




Measured memory_bytes: 3076
N = int(input())

abc = "abcdefghijklmnopqrstuvwxyz"
S = {}
for c in abc: S[c] = [0 for i in range(N)]

for i in range(N):
    for c in input(): S[c][i] +=1
        
ANS = ""
for k in sorted(S):
    ANS += k*min(S[k])
    
print(ANS)

Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <cstring>
#include <map>
using namespace std;

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

const ll MAX_N = 2e5 + 5;
ll n, x, y, ans, ANS;

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    cin >> n >> x >> y;
    if (abs(x - y) % 2 == 0)
        cout << abs(x - y) / 2 << "\n";
    else {
        if (y < x)
            swap(x, y);
        ll X = x, Y = y;
        ans = X;
        Y -= X;
        X = 1;
        ans += (Y - 1) / 2;

        ANS = (n - y + 1);
        x += n - y + 1;
        y = n;

        ANS += abs(x - y) / 2;
        cout << min(ans, ANS);
    }
    return 0;
}

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

public class Main {
    static IO io = new IO();
    public static void main(String[] args) {
        while (io.hasNext()) {
            long a = io.nextInt();
            long b = io.nextInt();
            long g = gcd(a,b);
            long l = a*b/g;
            System.out.println(g + " " + l);
        }
    }

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

    static class IO extends PrintWriter {
        private final InputStream in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;

        IO() {
            this(System.in);
        }

        IO(InputStream source) {
            super(System.out);
            this.in = source;
        }

        boolean hasNextByte() {
            if (ptr < buflen) return true;
            else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) return false;
            }
            return true;
        }

        int readByte() {
            if (hasNextByte()) return buffer[ptr++];
            else return -1;
        }

        boolean isPrintableChar(int c) {
            return 33 <= c && c <= 126;
        }

        void skipUnprintable() {
            while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
        }

        boolean hasNext() {
            skipUnprintable();
            return hasNextByte();
        }

        long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) throw new NumberFormatException();
            while (true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if (b == -1 || !isPrintableChar(b)) return minus ? -n : n;
                else throw new NumberFormatException();
                b = readByte();
            }
        }

        int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
            return (int) nl;
        }

        public void close() {
            super.close();
            try {
                in.close();
            } catch (IOException ignored) {
            }
        }
    }
}

Measured memory_bytes: 24180
#include <bits/stdc++.h>
#define len(x) ((int)(x).size())

using namespace std;

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

  int X;
  cin >> X;
  if (X >= 30) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


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

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<bool> VB;
typedef vector<double> VD;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define LB lower_bound
#define UB upper_bound

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a);i>(b);--i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL INF = 1000000000;
const LL MOD = 1000000007;

//other
//-------------------------------------------
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define FI first
#define SE second

int main() {
  int ans=0;
  VI A(5), B(5);
  
  REP(i,5) {
    int T;
    cin >> T;
    B.at(i) = T%10;
    A.at(i) = T -B.at(i);
    if(B.at(i) == 0) B.at(i) = 10;
    ans += A.at(i);
  }
  SORT(B);
  REP(i,5) {
    if(B.at(i) != 10) {
      ans += 10;
    }
  }
  ans += B.at(0)-10;
  cout << ans << endl;
  return 0;
}

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

#define MOD 1000000007

int nsum;

int rest(int x, int i, int k){
	if( k == 3 ){
		return nsum - (x & 077) - (x >> 6 & 077) - (x >> 12 & 077) - i;
	}
	return (x >> (k * 6)) & 077;
}

int main(){
	int na, nt, ng, nc, m;
	cin >> na >> nt >> ng >> nc >> m;
	nsum = na + nt + ng + nc;

	cin.ignore();

	vector<string> vs(m);
	for(int i = 0; i < m; ++i){
		getline(cin, vs[i]);
	}
	
	map<string,int> nametbl;
	char buf[32];
	vector<vector<char> > seq(m);
	int d = 0;
	
	char chtbl['T' + 1] = {};
	chtbl['A'] = 1;
	chtbl['T'] = 2;
	chtbl['G'] = 4;
	chtbl['C'] = 8;

	for(int i = m - 1; i >= 0; --i){
		const char *ptr = vs[i].c_str();
		
		sscanf(ptr, "%[^:]:%n", buf, &d);
		ptr += d;
		nametbl.insert( make_pair(buf, i) );
		
		while( *ptr != '\0' ){
			if( sscanf(ptr, " %s%n", buf, &d) < 1 ) break;
			ptr += d;

			if( *buf == '[' ){
				char t = 0;

				for(int j = 1; buf[j] != ']'; ++j){
					t |= chtbl[ buf[j] ];
				}
				seq[i].push_back(t);
			}
			else{
				int j = nametbl[buf];
				seq[i].insert( seq[i].end(), seq[j].begin(), seq[j].end() );
			}
			
			if( seq[i].size() > nsum ) break;
		}
	}

	if( seq[0].size() != nsum ){
		puts("0");
		return 0;
	}
	
	int last = 1 << 18;
	vector<vector<int> > dp(seq[0].size() + 1, vector<int>(last) );
	dp[0][na | nt << 6 | ng << 12] = 1;
	
	for(int i = 0; i < seq[0].size(); ++i){
		for(int S = 0; S < last; ++S){
			if( dp[i][S] == 0 ) continue;

			for(int j = 0; j < 4; ++j){
				if( !(seq[0][i] & 1 << j) ) continue;

				int c = rest(S, i, j);
				if( c > 0 ){
					int t = S - ((1 << (j * 6)) & 0777777);
					dp[i + 1][t] = (dp[i + 1][t] + dp[i][S]) % MOD;
				}
			}
		}
	}
	
	int ans = 0;
	for(int S = 0; S < last; ++S){
		ans = (ans + dp.back()[S]) % MOD;
	}
	
	printf("%d\n", ans);
}

Measured memory_bytes: 201644
#include<bits/stdc++.h>
using namespace std;
string s[105];
int a[105],b[105];
int main()
{
	int i,j,n;
	cin>>n;
	for (i=1;i<=n;i++)
	{
		cin>>s[i]>>a[i];
		b[i]=i;
	}
	for (i=1;i<n;i++)
	{
		for (j=i+1;j<=n;j++)
		{
			if (s[i]>s[j])
			{
				swap(s[i],s[j]);
				swap(a[i],a[j]);
				swap(b[i],b[j]);
			}
			else if (s[i]==s[j]&&a[i]<a[j])
			{
				swap(s[i],s[j]);
				swap(a[i],a[j]);
				swap(b[i],b[j]);
			}
		}
	}
	for (i=1;i<=n;i++)
	{
		cout<<b[i]<<endl;
	}
}

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 a, b;
  cin >> a >> b;
  if (a * b * (a + b) % 3 == 0) cout << "Possible" << endl;
  else cout << "Impossible" << endl;
  return 0;
}

Measured memory_bytes: 3640
// AUTHOR : Kishan Srivastav
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define in freopen("input.txt", "r", stdin)
#define out freopen("output.txt", "w", stdout)
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);


int main() {
	ios
#ifndef ONLINE_JUDGE
	in;
	out;
#endif
	int a,b;
	cin>>a>>b;
	if(a <= 9 && b <= 9){
		cout<<( a * b )<<endl;
	}else{
		cout<<"-1"<<endl;
	}
}

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

using ll = long long;
using ull = unsigned long long;

const double PI = acos(-1);
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;

#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i<n; i++)
#define ALL(a) begin(a), end(a)

int main (void) {
    int N;
    cin>>N;
    vector<ll> A(N);
    REP(i,N) cin>>A[i];

    vector<ll> res1(N);
    vector<int> p(N,0);
    sort(ALL(A),greater<ll>());
    REP(i,N-1) {
        if (i % 2 == 0) {
            p[i + 1] ++;
            p[i] --;
        }
        else {
            p[i + 1] --;
            p[i] ++;
        }
    }
    int n = 0;
    for (int i=2;i>=-2;i--) {
        REP(j,N) {
            if (p[j] == i) {
                res1[j] = A[n++];
            }
        }
    }
    ll sum1 = 0;
    REP(i,N-1) {
        sum1 += abs(res1[i] - res1[i+1]);
    }

    vector<ll> res2(N);
    REP(i,N) p[i] = 0;
    REP(i,N-1) {
        if (i % 2 == 1) {
            p[i + 1] ++;
            p[i] --;
        }
        else {
            p[i + 1] --;
            p[i] ++;
        }
    }
    n = 0;
    for (int i=2;i>=-2;i--) {
        REP(j,N) {
            if (p[j] == i) {
                res2[j] = A[n++];
            }
        }
    }
    ll sum2 = 0;
    REP(i,N-1) {
        sum2 += abs(res2[i] - res2[i+1]);
    }

    cout<<max(sum1,sum2)<<endl;
    return 0;
}


Measured memory_bytes: 2944
import java.util.*;
import static java.lang.Math.*;
public class Main {
	final Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		new Main().init();
	}
	void init(){
		new AOJ1153();
	}
	
	class AOJ1153{
		AOJ1153(){
			while(true){
				int n=sc.nextInt(),m=sc.nextInt();
				if((n|m)==0)	break;
				solve(n,m);
			}
		}
		void solve(int n,int m){
			int[] nn=new int[n],
					mm=new int[m];
			int ns=0, ms=0;
			for(int i=0; i<n; ++i){
				nn[i]=sc.nextInt();
				ns+=nn[i];
			}
			for(int i=0; i<m; ++i){
				mm[i]=sc.nextInt();
				ms+=mm[i];
			}
			Arrays.sort(nn);
			Arrays.sort(mm);
			int cand1=-1,cand2=-1,sum=Integer.MAX_VALUE/4;
			for(int i=0; i<n; ++i){
				for(int j=0; j<m; ++j){
					if(ns-nn[i]+mm[j] == ms-mm[j]+nn[i] && sum>nn[i]+mm[j]){
						cand1=i;
						cand2=j;
						sum=nn[i]+mm[j];
					}
				}
			}
			System.out.println(cand1<0? "-1" : nn[cand1]+" "+mm[cand2]);
		}
	}
	
	

}

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

int main(){
    int N,M; cin >> N >> M;
    priority_queue<long long> que;
    long long A;
    for(int i = 0; i < N; i++){
        cin >> A; que.push(A);
    }
    
    for(int i = 0; i < M; i++){
        long long p = que.top(); que.pop();
        p /=2;
        que.push(p);
    }
    int Size = que.size();
    long long ans = 0;
    for(int i = 0; i < Size; i++){
        long long q = que.top(); que.pop();
        ans += q;
    }
    
    cout << ans << endl;
    return 0;
}


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

static const int MAX=200000;

int main(){
    
    int R[MAX],n;
    cin>>n;
    for(int i=0;i<n;i++) cin>>R[i];

    int maxv=-2000000000;
    int minv=R[0];

    for(int i=1;i<n;i++){
        maxv=max(maxv,R[i]-minv);
        minv=min(minv,R[i]);
    }

    cout<<maxv<<endl;
    
    return 0;
}



Measured memory_bytes: 3792
// C++ code to find number of distinct numbers 
// in a subarray 
#include<bits/stdc++.h> 
using namespace std; 

const int MAX = 500005; 

// structure to store queries 
struct Query 
{ 
	int l, r, idx; 
}; 

// cmp function to sort queries according to r 
bool cmp(Query x, Query y) 
{ 
	return x.r < y.r; 
} 

// updating the bit array 
void update(int idx, int val, int bit[], int n) 
{ 
	for (; idx <= n; idx += idx&-idx) 
		bit[idx] += val; 
} 

// querying the bit array 
int query(int idx, int bit[], int n) 
{ 
	int sum = 0; 
	for (; idx>0; idx-=idx&-idx) 
		sum += bit[idx]; 
	return sum; 
} 

void answeringQueries(int arr[], int n, Query queries[], int q) 
{ 
	// initialising bit array 
	int bit[n+1]; 
	memset(bit, 0, sizeof(bit)); 

	// holds the rightmost index of any number 
	// as numbers of a[i] are less than or equal to 10^6 
	int last_visit[MAX]; 
	memset(last_visit, -1, sizeof(last_visit)); 

	// answer for each query 
	int ans[q]; 
	int query_counter = 0; 
	for (int i=0; i<n; i++) 
	{ 
		// If last visit is not -1 update -1 at the 
		// idx equal to last_visit[arr[i]] 
		if (last_visit[arr[i]] !=-1) 
			update (last_visit[arr[i]] + 1, -1, bit, n); 

		// Setting last_visit[arr[i]] as i and updating 
		// the bit array accordingly 
		last_visit[arr[i]] = i; 
		update(i + 1, 1, bit, n); 

		// If i is equal to r of any query store answer 
		// for that query in ans[] 
		while (query_counter < q && queries[query_counter].r == i) 
		{ 
			ans[queries[query_counter].idx] = 
					query(queries[query_counter].r + 1, bit, n)- 
					query(queries[query_counter].l, bit, n); 
			query_counter++; 
		} 
	} 

	// print answer for each query 
	for (int i=0; i<q; i++) 
		cout << ans[i] << endl; 
} 

// driver code 
int main() 
{ 
	int n,q;
	cin>>n>>q;
	int a[n];
	for(int i=0;i<n;i++)cin>>a[i];
	int ll,rr;
	Query queries[q]; 
	for(int i=0;i<q;i++)
	{
		cin>>ll>>rr;
		ll--;rr--;
	
		queries[i].l = ll; 
		queries[i].r = rr; 
		queries[i].idx = i; 
	}
	
	
	sort(queries, queries+q, cmp); 
	answeringQueries(a, n, queries, q); 
	return 0; 
} 


Measured memory_bytes: 17384
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
#include <random>
#include <fstream>
using namespace std;

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<int, ll> i_ll;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int v; ll w; };

const int MOD = 1000000007;
const int _MOD = 1000000009;
double EPS = 1e-10;
const int INF = INT_MAX / 2;

int main() {
	int N, K; cin >> N >> K;
	string s; cin >> s;
	rep(i, N) if ((N - 1 - i) % 2) s[i] = 'A' + 'B' - s[i];
	int l = 0, k = 0;
	while (k < K) {
		char c = s[l];
		if ((N - 1) % 2) c = 'A' + 'B' - c;
		if (c == 'A') s[l] = 'A' + 'B' - s[l];
		else l++;
		k++;
		if (l == N) break;
	}
	string t = s.substr(l) + string(l, 'A');
	if (N % 2 && (K - k) % 2) t[0] = 'A' + 'B' - t[0];
	rep(i, N) if ((N - 1 - i) % 2) t[i] = 'A' + 'B' - t[i];
	cout << t << endl;
}


Measured memory_bytes: 1088
# coding: utf-8

import sys
import math
import collections
import itertools
from inspect import currentframe
INF = 10 ** 10
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def MI() : return map(int, input().split())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def chkprint(*args) : names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}; print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

A = LRI(3)
N = I()
B = [b[0] for b in LRI(N)]

for i in range(3):
    for j in range(3):
        for b in B:
            if b == A[i][j]:
                A[i][j] = -1

flag = False
for i in range(3):
    if A[0][i] == -1 and A[1][i] == -1 and A[2][i] == -1:
        flag = True
    if A[i][0] == -1 and A[i][1] == -1 and A[i][2] == -1:
        flag = True

if A[0][0] == -1 and A[1][1] == -1 and A[2][2] == -1:
        flag = True
if A[0][2] == -1 and A[1][1] == -1 and A[2][0] == -1:
        flag = True

print("Yes" if flag else "No")

Measured memory_bytes: 43376
import sys
import time
import math
st = time.perf_counter()
def inpl():
    return list(map(int, input().split()))
# ------------------------------

N = int(input())
nl = [0] * 100100
ls = inpl()
ans = 0
for i in ls:
	nl[i] += 1
	ans += i
M = int(input())
for _ in range(M):
	a, b = map(int, input().split())
	ans = ans - (nl[a] * a) + (nl[a] * b)
	nl[b] += nl[a]
	nl[a] = 0
	print(ans)

# ------------------------------
ed = time.perf_counter()
print('time:', ed-st, file=sys.stderr)


Measured memory_bytes: 21760
<?php

list($v, $e) = explode(" ", trim(fgets(STDIN)));
$edges = [];
for ($i = 0; $i < $e; $i++) {
    list($s, $t, $w) = explode(" ", trim(fgets(STDIN)));
    $edges[] = [$w, $s, $t];
}
sort($edges);

$parList = [];
for ($i = 0; $i < $v; $i++) {
    $parList[$i] = $i;
}

function find($x) {
    global $parList;
    if ($x === $parList[$x]) {
        return $x;
    }
    $parList[$x] = find($parList[$x]);
    return $parList[$x];
}

$ans = 0;
foreach ($edges as $edge) {
    list($w, $s, $t) = $edge;
    $ps = find($s);
    $pt = find($t);
    if ($ps != $pt) {
        $ans += $w;
        $parList[$ps] = $pt;
    }
}

echo $ans . "\n";



Measured memory_bytes: 92308
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)








int main(){
    ll n;
    cin >> n;
    vector<ll> cnt(n + 10);
    for(ll i = 2; i <= n; i++){
        ll t = i;
        for(ll j = 2; j <= sqrt(t); j++){
            while(t % j == 0){
                t /= j;
                cnt[j]++;
            }
        }
        if(t != 1)cnt[t]++;
    }
    ll ans = 1;
    REP(i, n + 5){
        ans *= cnt[i] + 1;
        ans %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int a,b;
    cin>>a>>b;
    if(a<=b){
        for(int i=0; i<b; i++){
            cout<<a;
        }
        cout<<endl;
    }else{
        for(int i=0; i<a; i++){
            cout<<b;
        }
        cout<<endl;
    }
    return 0;
}

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    ll n,ans=0;
    cin>>n;
    vector<string> s(n);
    unordered_map<string, ll> mp;
    for (int i = 0; i < n; i++)
    {
        cin>>s[i];
        sort(all(s[i]));
        mp[s[i]]++;
    }
    for (auto i = mp.begin(); i != mp.end(); i++)
    {
        ll val = i->second;
        ans+=val*(val-1)/2;
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 17700
#include<bits/stdc++.h>
using namespace std;
int a[51],t;
int main() {
	int n,k;
	cin>>n>>k;
	for(int i=1;i<=n;i++) {
		cin>>a[i];
	}
	sort(a+1,a+n+1);
	for(int i=n;i>n-k;i--){
		t+=a[i];
	}
	cout<<t<<"\n";
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int m,f,b,sum;
	scanf("%d %d %d", &m, &f, &b);
	if(m>=b){
		sum = 0;
		printf("%d\n", sum);
	}
	else if(m+f>=b){
		sum = b-m;
		printf("%d\n", sum);
        }
	else printf("NA\n");

	return 0;
}


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

long sum_digits(long n) {
  long ret = 0;
  while (n > 0) {
    ret += n % 10;
    n /= 10;
  }
  return ret;
}

int main(int argc, char *argv[]) {
  // read inputs
  long K;
  scanf("%ld", &K);

  // solve
  long n = 1, s_n = 1, d = 1;
  for (long k = 0; k < K; k++) {
    for (;; d *= 10) {
      n = (n / d) * d + (d - 1);
      s_n = sum_digits(n);
      long m = n + d, s_m = sum_digits(m);
      // printf("m = %ld, s_m = %ld, n = %ld, s_n = %ld, d = %ld\n", m, s_m, n,
      //        s_n, d);
      if (n * s_m <= m * s_n) {
        break;
      }
    }
    printf("%ld\n", n);
    n++;
    s_n = sum_digits(n);
  }

  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ll a,b,c,k;cin>>a>>b>>c>>k;
    ll ans=0;

    if(a>=k)
        ans=k;
    else if(b+a>=k)
    {
        ans=a;
    }
    else
    {
        ans=a;
        k-=(a+b);
        ans-=k;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3588
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

long long X, Y;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> X >> Y;
  int ctr = 0;
  while (X <= Y) {
    ctr++;
    X *= 2LL;
  }
  cout << ctr << "\n";
  return 0;
}


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

using namespace std;

typedef long long int ll;
#define inf 0x3f3f3f3f
#define endl '\n'
#define case(i) "Case #" << i << ": "

template <typename S, typename T>
ostream& operator<<(ostream& out, pair<S, T> const& p) {
    out << '(' << p.first << ", " << p.second << ')';
    return out;
}
template <typename T>
ostream& operator<<(ostream& out, vector<T> const& v) {
    ll l = v.size();
    for (ll i = 0; i < l - 1; i++) out << v[i] << ' ';
    if (l > 0) out << v[l - 1];
    return out;
}

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

    int a, b;
    cin >> a >> b;
    if(a >= 1 && a <= 9 && b <= 9 && b >= 1) {
        cout << a * b << endl;
    }
    else cout << -1 << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MAXN=100010;
int n,m,p,ans1,ans2,pen[MAXN],cor[MAXN];
char c[4];
int main () {
	scanf("%d%d",&n,&m);
	for (int i=1;i<=m;i++) {
		scanf("%d%s",&p,c+1);
		if (c[1]=='A') {
			if (++cor[p]==1) {ans1++,ans2+=pen[p];}
		} else {
			pen[p]++;
		}
	}
	printf("%d %d\n",ans1,ans2);
	return 0;
}

Measured memory_bytes: 1024
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

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

ll fac[MAX], finv[MAX], inv[MAX];

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

ll nCrcheep(ll n,ll r){
  if(r == 0) return 1;
  else if(r == 1) return n;
  else return nCrcheep(n-1,r-1)*n/r;
}

vector<pair<ll,ll>> prime_factorize(ll n){
  vector<pair<ll,ll>> res;
  
  for(ll i=2; i*i <= n; i++){
    if(n % i != 0) continue;
    
    ll ex = 0;
    while(n % i == 0){
      ex++;
      n /= i;
    }
    
    res.push_back({i,ex});
  }
  
  if(n != 1) res.push_back({n,1});
  
  return res;
  
}




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

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

const ull B1=1000000007,B2=9973;

int h,w;
char field[1111][1111];
int r,c;
char pat[1111][1111];

ull allhash[1111][1111],rowhash[1111][1111],pathash;
ull t1=1,t2=1;

int main(){
	cin.sync_with_stdio(false);
	cin>>h>>w;
	rep(i,h)cin>>field[i];
	cin>>r>>c;
	rep(i,r)cin>>pat[i];

	if(h<r||w<c)return 0;

	pathash=0;
	rep(i,r){
		ull sum=0;
		rep(j,c)sum=B1*sum+pat[i][j];
		pathash=B2*pathash+sum;
	}

	rep(i,c)t1*=B1;
	rep(i,r)t2*=B2;

	rep(i,h){
		rep(j,c)rowhash[i][0]=B1*rowhash[i][0]+field[i][j];
		repl(j,1,w-c+1){
			rowhash[i][j]=rowhash[i][j-1]*B1-t1*field[i][j-1]+field[i][j+c-1];
		}
	}

	rep(j,w){
		rep(i,r)allhash[0][j]=B2*allhash[0][j]+rowhash[i][j];
		repl(i,1,h-r+1){
			allhash[i][j]=allhash[i-1][j]*B2-t2*rowhash[i-1][j]+rowhash[i+r-1][j];
		}
	}

	rep(i,h-r+1)rep(j,w-c+1){
		if(allhash[i][j]==pathash){
			printf("%d %d\n", i,j);
		}
	}

	return 0;
}

Measured memory_bytes: 21528
//in the name of allah the most gracious the most merciful
#include<bits/stdc++.h>
#pragma GCC optimize ("Ofast","unroll-loops")
#define int long long
#define pb push_back
#define fi  first
#define rep(i,n)  for(int i=0;i<n;i++)//looping 
#define rep1(i,n) for(int i=1;i<=n;i++)  
#define se  second
#define endl '\n'
#define PB pop_back
#define PF pop_front
#define pf push_front
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define ld long double 
const double PI = acos(-1);
const double e = exp(1);
const int MAXN = 2e5+100;
using namespace std;
bool check(string s ){
    int n = s.size(); 
    for(int i=0;i<n/2;i++){
        if(s[i] != s[n-1-i]) return 0 ; 
    }
    return 1 ;
}
void solve(){
    int n ; 
    cin>>n ; 
    vector<int> a(n); 
    for(int i=0;i<n;i++)cin>>a[i]; 
    int occ[n+2];
    rep(i,n+2)occ[i] = 0; 
    for(int i =0;i<n;i++){
        occ[a[i]]++;
        }
    int ans = 0 ;
    rep(i,n+1){
        ans += occ[i]*(occ[i]-1)/2;
    }
    rep(i,n){
        if(occ[a[i]]>1){
            cout << ans-occ[a[i]]+1;
        }
        else cout << ans; 
        cout << endl ; 
    }
        return ;
}
signed main ()
{
    int t=1; 
    
    while(t--){
        solve(); 
        cout << endl;
    }
    return 0 ; 
}   

Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }

int is_exist(int i, int j, vector<Pii> &ab){
    int n = Lower_bound(ab, Pii(i, j));
    if(n != ab.size() && ab[n] == Pii(i, j)) return 1;
    else return 0;
}

int count(int i, int j, int H, int W, vector<Pii> &ab){
    if(i < 0 || j < 0 || i >= H - 2 || j >= W - 2) return -1;
    int n = 0;
    REP(x, 3) REP(y, 3) n += is_exist(i + x, j + y, ab);
    return n;
}

signed main(){

    int H, W, N; cin >> H >> W >> N;
    int a, b; vector<Pii> ab(N);
    REP(i, N){
        cin >> a >> b;
        ab[i] = Pii(a - 1, b - 1);
    }
    SORT(ab);

    vec ans(10, 0);
    set<Pii> s;
    REP(i, N){
        int i0 = ab[i].first, j0 = ab[i].second;
        FOR(x, -2, 3) FOR(y, -2, 3){
            if(s.count(Pii(i0 + x, j0 + y)) > 0) continue;
            int n = count(i0 + x, j0 + y, H, W, ab);
            if(n > 0){
                ans[n]++;
                s.insert(Pii(i0 + x, j0 + y));
            }
        }
    }
    ans[0] = (H - 2) * (W - 2);
    FOR(i, 1, 10) ans[0] -= ans[i];
    REP(i, 10) cout << ans[i] << endl;

    return 0;
}

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

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef long double ld;


const ll mod = (ll)1e9 + 7;
const ll mxN = 10100;

ll n,x;
vll Adj[mxN];
ll depth[mxN];

void dfs(ll s = x, ll d = 0, ll par = -1) {
	depth[d]++;
	for(auto i: Adj[s])
		if(i != par) 
			dfs(i,d+1,s);
}

void pre() {
	for(int i=0;i<mxN;i++)
		Adj[i].clear();
}

void solve() {
	ll n;cin>>n;
	vll A(n), B(n);for(int i=0;i<n;i++) cin>>A[i]>>B[i];
	sort(all(A));sort(all(B));
	if(n&1) cout<<B[n/2]-A[n/2]+1<<"\n";
	else cout<<B[n/2]+B[n/2-1] - A[n/2] - A[n/2-1]+1<<"\n";


}


int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(20);
	cout << fixed;

//	pre();
//	ll t;cin>>t;while (t--)
		solve();

}


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

void trace(int arr[], int N)
{
    for(int i=0; i<N; i++){
        if(i>0) cout<<' '<<flush;
        cout<<arr[i]<<flush;
    }
    cout<<endl;
}

int main()
{
    int N;
    cin>>N;
    int* arr=new int[N];
    int comp;
    int j;
    for(int i=0; i<N; i++){
        cin>>arr[i];
    }
    trace(arr,N);



    for(int i=1; i<N; i++){
        comp=arr[i];
        j=i-1;
        while( arr[j] > comp && j>=0 ){
            arr[j+1]=arr[j];
            j--;
        }
        arr[j+1]=comp;
        trace(arr,N);

    }
}

Measured memory_bytes: 1188
k = int(input())
num = 7

if k == 1 or k == 7:
  print(1)
  exit()

if k%2==0:
  print(-1)
  exit()
for i in range(1, k + 1):
    num = num * 10 + 7
    if num % k == 0:
        print(i + 1)
        exit()
    else:
        num %= k
        
print(-1)
exit()

Measured memory_bytes: 9124
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  int n, m, d; readV(n, m, d);

  if (d == 0)
    writefln("%.7f", 1.0L/n*(m-1));
  else
    writefln("%.7f", 2.0L*(n-d)/n/n*(m-1));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
const ll INF = 99999999999999;
const ll MOD = 1000000007;
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
ll lcm(ll number1, ll number2)
{
    return number1 * number2 / gcd(number1, number2);
}
template <class T>
bool contain(const std::string &s, const T &v)
{
    // contain(to_string(N), '3')
    return s.find(v) != std::string::npos;
}
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> v(n);
    rep(i, n)
    {
        cin >> v[i];
    }

    sort(all(v));

    double tmp = v[0];
    for (int i = 1; i <= n - 1; i++)
    {
        tmp = (tmp + v[i]) / 2;
    }

    cout << tmp << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
    string S; cin >> S;
    int cnt = 0;
    for (int i = 1; i < S.size()/2; i++) {
        if (S.substr(0, i) == S.substr(i, i)) {
            cnt = i*2;
        }
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(){
  string S;
  cin >> S;
  sort(S.begin(), S.end());
  if (S[0] == S[1] && S[2] == S[3] && S[0] != S[2]){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}
    

Measured memory_bytes: 256
n=int(input())
l=map(int,input().split())
flag=1

for i in l:
  if i%2==0:
    if i%3==0 or i%5==0:
      flag*=1
    else:
      flag*=0

if flag==1:
  print('APPROVED')
else:
  print('DENIED')

Measured memory_bytes: 38384
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
using namespace std;
int main(){
  string S, T;
  cin >> S >> T;
  int count = 0;
  string ans[6000];
  int lens = S.size(), lent = T.size();
  for(int i = 0; i <= lens - lent; i++ ){
    string G ="";
    bool match = true;
    for(int k = i; k < i + lent; k++ ){
      G += S[k];
    }
    //cout << G << endl;
    for(int k = 0; k < lent; k++){
      if(T[k] != G[k] && G[k]!= '?'){
        match = false;
      }
    }
    if(match){
      string gen = "";
      for(int k = 0; k < lens; k++){
        if(k == i){
          gen += T;
          k+=(lent - 1);
        }else{
          if(S[k] == '?'){
            gen += "a";
          }else{
            gen += S[k];
          }
        }
        //cout << gen << " " << i << endl;
      }
      ans[count] = gen;
      count ++;
      //cout << gen <<endl;
    }
  }
  //cout << ans[0] << endl;
  sort(ans, ans + count);
  if(count == 0 || lens < lent){
    ans[0] = "UNRESTORABLE";
  }
  cout << ans[0] << endl;
  return 0;
}


Measured memory_bytes: 256
use proconio::input;

fn main() {
  input! {
    s: String,
  }
  let mut count = vec![0; 2019];
  count[0] += 1;
  let mut x = 0;
  let mut r = 1;
  for a in s.chars().map(|c| c.to_digit(10).unwrap() as usize).rev() {
    x = (x + r * a) % 2019;
    r = (10 * r) % 2019;
    count[x] += 1;
  }
  let mut total = 0;
  for x in 0..2019 {
    total += count[x] * (count[x] - 1) / 2;
  }
  println!("{}", total);
}


Measured memory_bytes: 2420
#include <stdio.h>

int main(void)
{
    int x[5];
    int i;
    for (i = 0; i < 5; i++) {
        scanf("%d", &(x[i]));
        if (x[i] == 0) {
            printf("%d\n", i + 1);
        }
    }
    return 0;
}

Measured memory_bytes: 1736