akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
const int MOD = 1e9 + 7;

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

    string N;
    int K, Nlen;
    cin >> N >> K;
    Nlen = N.length();

    static ll dp[103][6][2];
    dp[0][0][0] = 1;

    for (int i = 0; i < Nlen; ++i) {
        int num = N[i] - '0';
        for (int j = 0; j <= K; ++j) {
            dp[i + 1][j + (num != 0)][0] += dp[i][j][0];
            for (int k = 0; k < 10; ++k) {
                if (k < num)
                    dp[i + 1][j + (k != 0)][1] += dp[i][j][0];
                dp[i + 1][j + (k != 0)][1] += dp[i][j][1];
            }
        }
    }

    cout << dp[Nlen][K][0] + dp[Nlen][K][1] << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define idfc ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
//:/
#define pb emplace_back
#define mp make_pair
#define nt _ll128
#define ld long double
long double PI =3.14159265358979323846;
using ll = long long;



const ll modo=998244353;
const ll inf=1e17;
const ll ms=(2e5)+5;

vector<ll> a;
vector<ll> b;

ll sa[ms]={0};
ll sb[ms]={0};

int main()
{
    idfc;
    int n,k;
    cin>>n>>k;
    int i;
    int e;

    for(i=1;i<=n;i++)
    {
        cin>>e;
        if(e>=0)b.pb(e);
        else a.pb(-e);
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());

    int aa=a.size();
    int bb=b.size();

    for(i=1;i<=aa;i++)
    {
        sa[i]=a[i-1];
    }

    for(i=1;i<=bb;i++)
    {
        sb[i]=b[i-1];
    }
    int r;
    ll ans=LONG_LONG_MAX;
    ll x,y;
    for(i=0;i<=bb;i++)
    {
        if(i>k)break;
        r=k-i;
        if(r>aa)continue;
        x=sa[r];
        y=sb[i];
        //cout<<x<<" "<<y<<" "<<i<<"\n";
        ans=min(ans,2*x+y);
        ans=min(ans,2*y+x);
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 5224
char=input()
cnt=int(input())
for _ in range(0,cnt):
    ops = input().split()
    a,b=map(int,ops[1:3])
    if ops[0] == 'print':
        print(char[a:b+1])
    if ops[0] == 'reverse':
        char = char[0:a] + char[a:b+1][::-1] + char[b+1:]
    if ops[0] == 'replace':
        char = char[0:a] + ops[3] + char[b+1:]



Measured memory_bytes: 5612
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <deque>
#include <list>
#include <sys/timeb.h>
#include <fstream>
#include <set>

using namespace std;

#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFL 1100000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<Pi> > vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
template <class T>
using vec = vector<T>;
template<class T>
using pql = priority_queue<T, vector<T>, greater<T>>;
string debug_show(Pi a) {
	return "(" + to_string(a.first) + "," + to_string(a.second) + ")";
}

template<class T>
struct augEdge {
	T from, to;
	int cost;
	bool operator<(augEdge e) { return cost < e.cost; }
	bool operator>(augEdge e) { return cost > e.cost; }
};
template<class T>
using augGraph = vector<augEdge<T>>;


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

	string s, t;
	cin >> s >> t;
	if (s == t) {
		cout << "Yes" << endl;
		return 0;
	}

	rep(i, s.size()) {
		string a = s.substr(0,i);
		string b = s.substr(i);

		string tmp = b + a;

		if (tmp == t) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;

	return 0;
}



Measured memory_bytes: 256
module Main where

import           Control.Monad
import           Debug.Trace
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as VM
import qualified Data.Vector.Unboxed           as VU
import qualified Data.Vector.Unboxed.Mutable   as VUM
import           Data.List
import qualified Data.ByteString               as BS
import qualified Data.ByteString.Char8         as BSC8
import           Data.Char
import           Data.Maybe
import           Data.Ord
import           Data.Vector.Algorithms.Search
import qualified Data.Array                    as A
import qualified Data.Array.Unboxed            as AU
import qualified Data.Array.IO                 as AIO



getvuil :: IO (VU.Vector Int)
getvuil = VU.unfoldr (BSC8.readInt . BSC8.dropWhile isSpace) <$> BSC8.getLine
readi :: BSC8.ByteString -> Int
readi = fst . fromJust . BSC8.readInt
readil :: BSC8.ByteString -> [Int]
readil = map readi . BSC8.words
geti :: IO Int
geti = readi <$> BSC8.getLine
getil :: IO [Int]
getil = readil <$> BSC8.getLine

getNis :: Int -> IO [(Int, BSC8.ByteString)]
getNis 0 = return []
getisl n = do
    [aFst, aSnd] <- BSC8.words <$> BSC8.getLine
    next         <- (getisl (n - 1))
    return ((readi aFst, aSnd) : next)

il2ss :: [Int] -> String
il2ss = unwords . map show

il2sn :: [Int] -> String
il2sn = unlines . map show

main :: IO ()
main = do
    aK <- geti

    let
        ret = foldl
            (\acc1 x ->
                acc1
                    + (foldl
                          (\acc2 y ->
                              let
                                  (retAcc, _) =
                                      (foldl
                                          (\acc3@(acc4, xy) z ->
                                              (gcd xy z + acc4, xy)
                                          )
                                          (0, gcd x y)
                                          [1 .. aK]
                                      )
                              in  retAcc + acc2
                          )
                          0
                          [1 .. aK]
                      )
            )
            0
            [1 .. aK]

    print ret


Measured memory_bytes: 5288
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

def lcm(x, y):
    return (x * y) // gcd(x, y)


n = int(input())
temp = 1
ans = 0
a = list(map(int, input().split()))
for i in a:
    temp = lcm(temp, i)

for i in a:
    ans +=  int(temp/i)

print(temp/ans)

Measured memory_bytes: 38256
#include <stdio.h>
 
int main(void) {
 
	// ??°????????\???????????°
	int W;
	int H;
	int x;
	int y;
	int r;
	
	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
	
	if((0 <= x-r) && (0 <= y-r) && (x+r <= W) && (y+r <= H)) {
		
		printf("Yes\n");

	} else {

		printf("No\n");
		
	}
	return 0;
}

Measured memory_bytes: 1788
N=int(input())
S=[input() for _ in range(N)]

F = [[0]*N for _ in range(26)]

f1=lambda c: ord(c) - ord('a')
f2=lambda c: chr(c+97)


for i in range(N):
    for s in S[i]:
        F[f1(s)][i]+=1
        
ans=''
for i in range(26):
    t=min(F[i])
    if t!=0:
        ans+=t*f2(i)
print(ans)

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

public class Main{

	public static void main(String[] args) {
		Main ans = new Main();
		System.out.printf("%.10f",ans.solve());
	}

	private double solve() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		double [] array = new double[N+1];
		for(int i=1;i<=N;i++){
			array[i] = sc.nextDouble();
		}

		double ans = 0.0;
		double [][] dp = new double[3000][3000];
		for(int i=0;i<3000;i++) {
			Arrays.fill(dp[i], -1);
		}


		return solve(dp, array, N, (N+1)/2);

	}

	private double solve(double [][] dp, double []array, int i, int x) {

		if (x==0) return 1;
		if (i==0) return 0;
		if (dp[i][x]>-0.9) return dp[i][x];
		dp[i][x] = array[i]* solve(dp, array, i-1, x-1) + (1-array[i]) * solve(dp, array, i-1, x);
		return dp[i][x];

	}

}

Measured memory_bytes: 119124
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
   
    int a = sc.nextInt();
    int b = sc.nextInt();

    if (a>b){
      System.out.println("a > b");
    } else {
      if (a<b){
        System.out.println("a < b");
      } else {
        System.out.println("a == b");
      }
    }
  }
}


Measured memory_bytes: 26192
#include <iostream>

bool IsPrimeNumber(int num)
{
    // (2 <= num <= 10の8乗) なので、1の判定は略
    if ((num & 1) == 0) {
        return (num == 2);
    } else {
        int d = 3;
        while (d * d <= num) {
            if ((num % d) == 0) {
                return false;
            }
            d += 2;
        }
    }
    return true;
}

int main()
{
    int n;
    std::cin >> n;
    int count = 0;
    for (int i = 0; i < n; ++i) {
        int val;
        std::cin >> val;
        if (IsPrimeNumber(val)) {
            ++count;
        }
    }
    std::cout << count << std::endl;
    return 0;
}

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

// 深さ優先探索
int dfs(string &S) {
    ll ret = 0;
    vector<char> lis = {'3', '5', '7'};
    if ((int)S.size() > 0) {  // 最初はSは空なので注意
        if (stoll(S) > N) {   // Nを超えてたら探索しない
            return ret;
        } else {  // N 以下の時 3,5,7 がそれぞれ1回以上登場するか確かめる
            bool ok = true;
            for (auto c : lis) {
                if (S.find(c) == string::npos) ok = false;
            }
            if (ok) ret++;
        }
    }
    for (auto c : lis) {  // 3つに分岐する
        S.push_back(c);
        ret += dfs(S);
        S.pop_back();
    }
    return ret;
}

int main() {
    cin >> N;
    string S = "";
    cout << dfs(S) << endl;
}

Measured memory_bytes: 3616
#include<iostream>
#include<cstdio>
#include<cstring>

using namespace std;
const int maxn=2e5+5;
char s[maxn];
int main(){
    scanf("%s",s);
    int sum=0;
    for(int i=0;i<strlen(s);++i){
        sum+=(s[i]-'0');
    }
    if(sum%9==0)puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 3328
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>
#include <stack>
using namespace std;
 
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define ktya(x) sort(all(x))
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 1e18
#define INFLL 1000000000000000007LL
#define SIZE 200105
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define PI (acos(-1))
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
ll MOD = 1000000007;
// ll MOD=998244353;
typedef ll Weight;
struct Edge {
	int src, dst;
	ll weight;
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
ll powMod(ll x, ll k, ll m) {//x^k (mod n)
	if (k == 0)     return 1;
	if (k % 2 == 0) return powMod(x*x % m, k/2, m);
	else            return x*powMod(x, k-1, m) % m;
}
int N,M;
ll Po;
vi PP;

vector<Edge> graph;
ll dist[3000];
void minpath(int s){
	for(int i=0;i<N;i++) dist[i] = INF;
	dist[s] = 0;
	for(int j=0;j<N-1;j++){
		for(int i=0;i<graph.size();i++){
			Edge e = graph[i];
			if(dist[e.src] != INF && dist[e.dst] > dist[e.src] + e.weight){
				dist[e.dst] = dist[e.src] + e.weight;
			}
		}
	}
}
 
void negloop(){// 最短経路求めたのちにもう一回更新できてしまうときに-INFでメモ　これをN回やると負の情報が伝搬する
	for(int i=0;i<N;i++){
		for(int j=0;j<graph.size();j++){
			Edge e = graph[j];
			if(dist[e.dst]!=INF && dist[e.dst] > dist[e.src] + e.weight){
				dist[e.dst] = -INF;
			}
		}
	}
}
 
int main(){
	cin >> N >> M >> Po;
	for(int i=0;i<M;i++){
		int a,b;
		ll c;
		cin >> a >> b >> c;a--;b--;
		c-=Po;
		Edge hen={a,b,-c};
		graph.push_back(hen);
	}
	minpath(0);
	//rep(i,N)cout<<dist[i]<<endl;
	ll ans = max(-dist[N-1],0LL);
	//cout<<ans<<endl;
	negloop();
    cout << (dist[N-1]==-INF? -1:ans) << endl;
}



Measured memory_bytes: 640
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
int dx[4]={0,1,-1,0};
int dy[4]={1,0,0,-1};

vector<vector<int>> v(100010);

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

    ll n,k;
    cin>>n>>k;
    ll p[n],a[n];
    ll ans = -1e17;
    for(int i=0;i<n;i++){
        cin>>p[i];
        p[i]--;
    }
    for(int i=0;i<n;i++){
        cin>>a[i];
        chmax(ans,a[i]);
    }
    bool used[n]={};
    for(int i=0;i<n;i++){
        if(used[i])continue;
        vector<int> ret;
        ll now = 0;
        int x = i;
        while(!used[x]){
            now += a[x];
            ret.push_back(x);
            used[x] = 1;
            x = p[x];
        }
        ll m = ret.size();
        ll cost[m+m+1]={};
        for(int i=0;i<m+m;i++){
            cost[i+1] = cost[i] + a[ret[i%m]];
        }
        if(k/m != 0)chmax(ans, k/m * now);
        for(int x=0;x<=m;x++){
            for(ll l=1;l<=min(k,m);l++){
                ll sum = cost[x+l] - cost[x];
                sum += max(0LL, (k-l)/m * now);
                chmax(ans,sum);
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 5836
macro_rules! get {
    (Vec<$t:ty>) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
}

use std::cmp;

fn main() {
    let (N, A, B) = get!(i64, i64, i64);

    let ans = cmp::min(N * A, B);

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

Measured memory_bytes: 4352
package main

import "fmt"

func main() {
	var h, w int
	fmt.Scan(&h, &w)

	if h == 1 || w == 1 {
		fmt.Println(1)
		return
	}

	a := (h + 1) / 2
	b := h - a
	c := (w + 1) / 2
	d := w - c
	fmt.Println(a*c + b*d)
}


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

typedef long long ll;
#define PB push_back

const ll MOD = 1e9+7;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	ll n, k; cin >> n >> k;
	if (k > n) cout << 1;
	else {
		ll ans = 0;
		for (ll i = k; i <= n + 1; ++i) {
			ll low = i * (i - 1) / 2;
			ll high = i * (2 * n - i + 1) / 2;
			ans += high - low + 1;
			ans %= MOD;
		}
		cout << ans;
	}
}

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

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

#define INF 100000000
#define MOD 1000000007
#define writeln(n) cout<<n<<endl
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
//vector<tuple<long long, long long, long long>>vec;

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

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

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

const int inf=100000000;



int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int n,m;
    cin>>n>>m;
    vector<int> L(m,0);
    vector<int> R(m,0);
    int cntl=0;
    int cntr=INF;
    int ans=0;
    REP(i,m)
    {
        cin>>L[i]>>R[i];
        cntl=max(cntl,L[i]);
        cntr=min(cntr,R[i]);
    }
    if(cntl<=cntr) ans=cntr-cntl+1;
    else ans=0;
    cout<<ans<<endl;
    return 0;

}

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

long div2count(long n){
  long count = 0;
  while(n % 2 == 0){
    count++;
    n = n / 2;
  }
  return count;
}

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

  long ans = 100000000000000;
  for(int i = 0; i < N; i++){
    long tmp;
    cin >> tmp;
    long count = div2count(tmp);
    cerr << count << endl;
    if(count < ans){
      ans = count;
    }

    if(ans == 0) { 
      break;
    }
  }

  cout << ans << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1001001001;
const int MOD = 1000000007;
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 (b<a) {a=b; return 1;} return 0;}

#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...)
#define print(...)
#endif

struct UnionFind {
	vector<int> data;

	UnionFind(int sz) {
		data.assign(sz, -1);
	}

	void unite(int x, int y) {
		x = find(x), y = find(y);
		if (x == y) return;
		if (data[x] > data[y]) swap(x, y);
		data[x] += data[y];
		data[y] = x;
	}

	int find(int k) {
		if(data[k] < 0) return(k);
		return data[k] = find(data[k]);
	}

	bool same(int x, int y)	{
		return find(x) == find(y);
	}

	int size(int k)	{
		return -data[find(k)];
	}
};


int main() {
    int n, m; cin >> n >> m;
    UnionFind uf(n);
    rep(i, m) {
        int a, b; cin >> a >> b;
        a--; b--;
        uf.unite(a, b);
    }
    int ans = 0;
    rep(i, n) {
        chmax(ans, uf.size(i));
    }
    cout << ans << endl;
}

Measured memory_bytes: 4044
#include <stdio.h>

int main()
{
	int N, a[1000];
	int i, j,chan;

	scanf("%d", &N);
	for (i = 0; i < N; ++i){
	scanf("%d", &a[i]);
  }
	for (i = 0; i<N; ++i) {
		for (j = i + 1; j<N; ++j) {
			if (a[i]>a[j]) {
				chan = a[i];
				a[i] = a[j];
				a[j] = chan;
			}
		}
	}

	printf("%d", a[N-1] - a[0]);

    return 0;
}

Measured memory_bytes: 128
/* it was worth becoming a chemist */
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;
typedef long double ld;
typedef unsigned int uni;
typedef unsigned long long unll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long long, int> pli;
typedef pair<int, long long> pil;
typedef vector<int> vi;
typedef vector<long long> vll;

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
#define NAME "puts"
#define F first
#define S second

const ll INF = 1e18;
const int inf = 1e9;
const int mod = 1e9 + 7;
const db EPS = (db) 1e-9;
const db pi = acos(-1.0);
const int MAXN = 2e5 + 5;

int n;

int main() {	
    cout << setprecision(9) << fixed;

	cin >> n;
	cout << double(double(n - n / 2) / double(n));
	return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
	int a,b,c;
	cin >> a >> b >> c;
	if(c-b<1){
	 cout << "delicious" << endl;
	}
	else if(c-b<=a){
	 cout << "safe" << endl;
	}
	else{
	 cout << "dangerous" << endl;
	}
}

Measured memory_bytes: 256
n, k = (int(x) for x in input().split())

a = [int(x) for x in input().split()]

if n == k:
    print(1)
elif k == 2:
    print(n-1)
else:
    rem = n % (k-1)
    m = (n - rem) / (k-1)
    if rem <= 1:
        print(int(m))
    else:
        print(int(m+1))



Measured memory_bytes: 13880
K,A,B = map(int,input().split())
ans = 0
if B-A <= 2:
    # 1円に交換せず割り続けたほうが良い
    ans = 1+K
else:
    # x 回 ビスケット→円→ビスケットが行われると
    # ビスケットの儲けは(B-A)*2,消費する手数はx*2
    # k-x*2 分は交換せず叩いて増やす
    x = max(0,(K-(A-1))//2)
    ans = 1 + (B-A)*x + (K-(x*2))
print (ans)

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

#define ll long long
#define ull unsigned long long
#define pb push_back
#define pf push_front
#define pof pop_front
#define pob pop_back
#define mp make_pair
#define pll pair<ll,ll>
#define pii pair<int,int>
#define all(s) s.begin(),s.end()
#define vll vector<ll>
#define vi vector<int>
#define vpii vector<pii>
#define vpll vector<pll>
#define vd vector<double>
#define vull vector<ull>
#define vc vector<char>
#define vs vector<string>
#define fi first
#define se second
#define sz(x) x.size()
#define cinarr(n,a) for(int i = 0; i < n; i++) cin >> a[i];
#define coutarr(n,a) for(int i = 0; i < n; i++) cout << a[i] << (i+1==n?'\n':' ');
#define fori(i,a,b,x) for(int i = a; i <= b; i+=x)
#define ford(i,a,b,x) for(int i = a; i >= b; i-=x)
#define tc int t; cin >> t; for(int cs = 1; cs <= t; cs++)
#define IOS ios_base::sync_with_stdio(0); cin.tie(NULL);
#define ld long double
#define reset(x,y) memset(x,y,sizeof x);
#define sqr(x) 1LL*(x)*(x)
#define cube(x) 1LL*(x)*(x)*(x)
#define ub(v, a) upper_bound(all(v), a)
#define lb(v, a) lower_bound(all(v), a)
#define EPS 1e-10
#define INF 2000000000
#define mod 1000000007
#define minof(a) min_element(all(a))
#define maxof(a) max_element(all(a))
#define debug(val) cerr << "The value of " << #val << " is = " << val << endl;
#define testing cerr << "--------------------------\n";

//input space ---> scanf("%[^\n]%*c",s);

int main() {
	IOS
	ll n,ans=LLONG_MAX;
	cin >> n;
	for(ll i = 1; i*i <= n; i++) {
		if(n % i == 0) {
			ans = min(ans,i + n/i - 2);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include<iostream>
#include<cmath>
#define MAXN 100003
using namespace std;
int f[MAXN][3];
int dp[MAXN][3];

int main(void){

    int N;
    cin >> N;


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

    for(int j=0; j<3; j++){
        dp[N][j] = f[N][j];
    }

    for(int i = N- 1; i>=1; i--){
        for(int j=0; j<3; j++){
            dp[i][j] = max(dp[i+1][(j+1)%3], dp[i+1][(j+2)%3]) + f[i][j];
        }
    }
    cout << max(dp[1][0], max(dp[1][1], dp[1][2]));
    return 0;


}


Measured memory_bytes: 2560
#include <bits/stdc++.h> 
#define pb push_back
#define mp make_pair 
#define fr first
#define sc second
#define MOD 1000000007
#define len(x) x.size()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define all(v) v.begin(), v.end()
#define alla(a,n) a, a + n
  
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef vector<string> vs;

int32_t main() {

    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin) ;
    // freopen("output.txt", "w", stdout) ;
    // #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL) ; cout.tie(NULL) ;

    int x,y,z;
    cin>>x>>y>>z;
    swap(x,y);
    swap(x,z);
    cout<<x<<" "<<y<<" "<<z<<endl;
 

}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <sstream>
#include <string>

using namespace std;

int main() {
    string S;
    cin >> S;
    int min = 99999;
    for (int i=0; i<S.length()-2; i++) {
        string tempstring = S.substr(i, 3);
        int temp = stoi(tempstring);
        int absolute = abs(temp-753);
        if (absolute<min) {
            min = absolute;
        }
    }
    cout << min << endl;
}

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

int f[10000][2],n,tt[2],a[100069],b[100];

int onbit(int x,int k){
    return x+(1<<(k-1));
}
int getbit(int x,int k){
     if (k==0 || k==14) return 1;
     return (x>>(k-1))&1;
}
int cal(int ttt,int turn){
    if (f[ttt][turn]!=-1) return f[ttt][turn];
    for (int i=1;i<=13;i++){
        if (getbit(tt[1-turn],i)==1 && getbit(ttt,i)==1) break;
        if (i==13) return f[ttt][turn]=0;
    }
    //cout<<turn<<" "<<ttt<<endl;
    int check=1;
    for (int i=1;i<=13;i++){
        if (getbit(tt[turn],i) && getbit(ttt,i) && (!(getbit(ttt,i+1) && getbit(ttt,i+1)) || (!(getbit(ttt,i-1) && getbit(ttt,i-1))))){
            check=0;
         //   if (ttt==8095) cout<<ttt-(1<<(i-1))<<endl;
            if (cal(ttt-(1<<(i-1)),1-turn)==0) return f[ttt][turn]=1;
        }
    }
    if (check && cal(ttt,1-turn)==0) return f[ttt][turn]=1;
    return f[ttt][turn]=0;
}
int main(){
    scanf("%d",&n);
    int tmp;
    for (int te=1;te<=n;te++){;
        memset(f,-1,sizeof(f));
        tt[1]=tt[0]=0;
        tmp=0;
        int check=0;
        for (int i=1;i<=6;i++) scanf("%d",&a[i]),tt[0]=onbit(tt[0],a[i]);
        for (int i=1;i<=13;i++){
            if (i==7) continue;
            check=1;
            for (int j=1;j<=6;j++) if (a[j]==i) {check=0;break;}
            if (check) tt[1]=onbit(tt[1],i);
        }
     //  cout<<tt[0]<<" "<<tt[1]<<endl;
       // cout<<tt[1]<<" "<<tt[2]<<endl;
       // cout<<te<<endl;
       // for (int i=1;i<=6;i++) cout<<a[i]<<" "<<b[i]<<endl;
        if (cal(8127,0)) cout<<"yes"<<endl;
        else cout<<"no"<<endl;
        //cout<<cal(63,63,8127,0)<<endl;
    }
}



Measured memory_bytes: 3324
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int n, a[55], dp[50009], greed[50009];
int main() {
	int cnt = 0;
	while (cin >> n, n) {
		for (int i = 0; i < n; i++) cin >> a[i];
		fill(dp + 1, dp + 50001, 999999999);
		fill(greed + 1, greed + 50001, 999999999);
		for (int i = 1; i <= 50000; i++) {
			int ptr = -1;
			for (int j = 0; j < n && i >= a[j]; j++) {
				dp[i] = min(dp[i], dp[i - a[j]] + 1);
				ptr = j;
			}
			if (ptr != -1) greed[i] = greed[i - a[ptr]] + 1;
		}
		bool ret1 = true, ret2 = true;
		for (int i = 1; i <= 50000; i++) {
			if (dp[i] == 999999999) ret1 = false;
			if (dp[i] < greed[i]) ret2 = false;
		}
		cout << "Case #" << ++cnt << ": ";
		if (!ret1) cout << "Cannot pay some amount" << endl;
		else if (!ret2) cout << "Cannot use greedy algorithm" << endl;
		else cout << "OK" << endl;
	}
	return 0;
}

Measured memory_bytes: 3436
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
// #define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
// #define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
using namespace std;
// using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
int BinarySearch(int key,int n,int S[]){
	int l=0,r=n;
	while(r-l>1){
		int mid=(l+r)/2;
		if(S[mid]>key)r=mid;
		else l=mid;
	}
	return (S[l]==key?1:0);
}
#define MOD 1000000007
#define EPS 10e-8

int partition(int A[],int p, int r){
    int x=A[r];
    int i=p-1;
    for(int j=p;j<r;j++){
        if(A[j]<=x){
            i++;
            swap(A[i],A[j]);
        }
    }
    swap(A[i+1],A[r]);
    return i+1;
}

int main(){
    int A[100007],n;cin >> n;
    rep(i,n){
        cin >> A[i];
    }
    int q=partition(A,0,n-1);
    rep(i,n){
        if(i>0){
            cout << " " ;
        }
        if(i==q){
            cout <<"[";
        }       
        printf("%d",A[i]);
        if(i==q){
            cout <<"]";
        }
    }
    cout << endl;
}


Measured memory_bytes: 3620
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn mat_chars(&mut self, row: usize) -> Vec<Vec<char>> {
        (0..row).map(|_| self.chars()).collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let N: usize = sc.get();
    let mut L: Vec<usize> = sc.vec(N);
    L.sort();
    let mut ans = 0;
    if N < 3 {
        println!("0");
        return;
    }
    for i in 0..N-2 {
        for j in i+1..N-1 {
            for k in j+1..N {
                if L[i] != L[j] && L[j] != L[k] && L[i] + L[j] > L[k] {
                    ans += 1;
                }
            }
        }
    }
    println!("{}", ans);
}


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

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;
typedef long double ld;

static const long long MOD = 1000000007;
static const long long LINF = (ll)(1e18+99);
static const int INF = 1e9+99;
const int MAX = 100005;

vector<int> G[MAX];
int ans[MAX];

void bfs(int s) {
    rep(i, 0, MAX) ans[i] = -1;
    queue<int> q;
    ans[s] = 0;
    q.push(s);
    while (!q.empty()) {
        int u = q.front(); q.pop();
        for (int v : G[u]) {
            if (ans[v]==-1) {
                ans[v] = u;
                q.push(v);
            }
        }
    }



}

int main(void) {
    int n, m;
    cin >> n >> m;

    rep(i, 0, m) {
        int a, b;
        cin >> a >> b;
        G[a].pb(b);
        G[b].pb(a);
    }

    bfs(1);

    puts("Yes");
    rep(i, 2, n+1) {
        printf("%d\n", ans[i]);

    }

	return 0;
}


Measured memory_bytes: 10536
import collections
import math
n,k = map(int, raw_input().split(' '))
ais = map(int, raw_input().split(' '))
r = 0
m = 42
x = 0
for ii in range(m, -1, -1):
	cc = collections.Counter([(ai >> ii) & 1 for ai in ais])
	if (x + (1 << ii) <= k):
		if cc[0] > cc[1]: x += (1 << ii)
		
	  
for ai in ais:
	r += ai ^ x
print r

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

using namespace std;

typedef unsigned long long ull;
#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF ((1 << 16)-1)
#define all(x) x.begin(), x.end()
struct PreMain {PreMain(){std::cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    std::ifstream in("../arg.txt");
    std::cin.rdbuf(in.rdbuf());
#endif

    int N, x, y;
    cin >> N;

    int s = 0;
    int t = 2 * N + 1;

    vector<pair<int, int>> reds;
    vector<pair<int, int>> blues;

    REP(i, N) {
        cin >> x >> y;
        reds.emplace_back(make_pair(x, y));
    }
    REP(i, N) {
        cin >> x >> y;
        blues.emplace_back(make_pair(x, y));
    }

    sort(all(reds));
    sort(all(blues));

    multiset<int> tmp;
    int ans = 0;
    int idx = 0;
    for (auto q: blues) {
        while(idx < N) {
            auto p = reds[idx];
            if (p.first >= q.first) break;

            tmp.insert(p.second);
            idx++;
        }

        auto lb = tmp.lower_bound(q.second);
        if (lb != tmp.begin()) {
            ans++;
            tmp.erase(prev(lb));
        }
    }

    cout << ans << endl;

    return 0;
}




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

int main(void){
    ll n;
    cin >> n;

    map<ll, ll> a;
    rep(i, n){
        ll tmp;
        cin >> tmp;

        a[tmp]++;
    }

    ll count = 0;
    for(auto m: a){
        if(m.first < m.second){
            count += m.second - m.first;
        }else if(m.first > m.second){
            count += m.second;
        }
    }

    cout << count << endl;
    return 0;


}


Measured memory_bytes: 6272
#include<iostream>
using namespace std;
typedef long long li;
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }

li pow5(li a){
  li s=a*a;
  return a*s*s; 
}

int main(){
  li x; cin >>x;
  rep(a,140){
    repa(b,-140,140){
      if(pow5(a)-pow5(b)==x){
        print(a,b);
        return 0;
      }
    }
  }
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=2e5+10;
map<int,int>mp;
int n,a[N];
LL ans;

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]),mp[i-a[i]]++;
	for(int i=1;i<=n;i++){
		mp[i-a[i]]--;
		ans+=1ll*mp[i+a[i]];
	}
	cout<<ans<<endl;
} 

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

int main(void)
{
	char str[100];

	cin >> str;

	if (str[0] == 'a'|| str[0] == 'i'|| str[0] == 'u'|| str[0] == 'e'||str[0] == 'o') {
		cout << "vowel" << endl;
	}
	else {
		cout << "consonant" << endl;
	}
}

Measured memory_bytes: 256
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0].split(" ")[0]);
    const M = parseInt(arg[0].split(" ")[1]);
    let AB = arg.slice(1, N + 1).map(n=>n.split(" ").map(l=>parseInt(l)));
    
    // 安い順集めれば良い
    AB = AB.sort((a,b)=>a[0] - b[0]);
    
    let now = 0;
    let nowAmount = 0;
    
    for(let i=0; i<N; i++) {
        const cost = AB[i][0];
        const amount   = AB[i][1];
        
        // console.log(amount);
        // console.log(cost);
        
        if(nowAmount + amount <= M) {
            now += amount * cost;
            nowAmount += amount;
        } else {
            const rest = M - nowAmount;
            now += rest * cost;
            nowAmount += rest;
            break;
        }
    }
    
    console.log(now)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

using namespace std;

typedef long long int ll;
const ll mod = 1e9 + 7;

ll square(ll x)
{
    return x * x;
}

ll power(ll b, ll p, ll m)
{
    if (p == 0)
        return 1;

    if (p % 2 == 0)
        return square(power(b, p/2, m)) % m;

    return (b * power(b, p-1, m)) % mod;
}

int main()
{
    ll n, a, b;

    cin >> n >> a >> b;

    ll ans = power(2, n, mod) - 1;

    ll c[b+1];

    c[0] = 1;
    c[1] = n;

    for (int i = 2; i <= b; i++)
    {
        c[i] = ((n+1-i) * c[i-1]) % mod;
        c[i] = c[i] * power(i, mod-2, mod);
        c[i] = c[i] % mod;
    }

    ans = ans - c[a];
    if (ans <= 0)
        ans = ans + mod;

    ans = ans - c[b];
    if (ans <= 0)
        ans = ans + mod;

    cout << ans % mod<< "\n";

    return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
#define N 2000002
#define MAX 10000


int A[N],B[N];
int main(){
  
  int C[MAX+1];
  int n, i, j;
  

 
  /*配列cの初期化*/
  for ( i = 0; i <= MAX; i++ ) C[i] = 0;


  /*データの読取*/
 scanf("%d", &n);

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


  /* C[i] に i 以下の数の出現数を記録する*/
  for ( i = 1; i <= MAX; i++ ) C[i] = C[i] + C[i - 1];




  for ( j = 1; j <= n; j++ ){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }



  /*表示*/
  for ( i = 1; i <n; i++ ){ 
    printf("%d ", B[i]);
  }
  printf("%d\n",B[i]);

  return 0;
}

Measured memory_bytes: 16260
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");

		int n = Integer.parseInt(str[0]);
		long m = Long.parseLong(str[1]);

		ArrayList<Long> list = divisor(m);

		long max = 0;
		for (long l : list) {
			if (n * l <= m) {
				if (max < l) {
					max = l;
				}
			}
		}

		System.out.println(max);
	}

	public static final ArrayList<Long> divisor(final long n) {
		final ArrayList<Long> list = new ArrayList<>();

		for (long i = 1; i * i <= n; i++) { // √n
			if (n % i == 0) {
				list.add(i); // a x b
				if (i != n / i) {
					list.add(n / i); // b x a (逆向き)
				}
			}
		}
		return list;
	}
}


Measured memory_bytes: 32732
import java.util.*;
import java.lang.Math;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);  
   	int n = sc.nextInt();
    int as[] = new int[n+1];
    int as2[] = new int[n+1];
    Map nMap = new HashMap<Integer,Integer>();
    List nList = new ArrayList<Integer>();
    int count = 0;
    long ap = 0;
    int istack;
    int cnt;
    
    for(int i = 0;i < n;i++) {
      as[i] = sc.nextInt();
      as2[i] = as[i];
    }
    as2[n] = n + 1;
    Arrays.sort(as2);
    istack = as2[0];
    cnt = 1;
    for(int i = 1;i <= n;i++){
      if(istack == as2[i]) cnt++;
      else{
        ap += (long)cnt*(cnt-1);
        nMap.put(istack,cnt-1);
        istack = as2[i];
        cnt = 1;
      }
    }
    ap /= (long)2;
    
    for(int i = 0;i < n;i++){
      System.out.println(ap - (int)nMap.get(as[i]));
    }
    
    

  }
}


Measured memory_bytes: 72004
#include "bits/stdc++.h"
#define rep(i,a,n) for(int i = (a);i < (n);i++)
typedef unsigned long long ull;
typedef long long ll;
using namespace std;

int main(){
	int n;
	cin >> n;
	
	string s;
	int l_cnt[26] = {0},cnt_memo[26] = {0};
	
	rep(i,0,n){
		cin >> s;
		rep(j,0,26){
			cnt_memo[j] = 0;
		}
		rep(j,0,s.size()){
			cnt_memo[(int)s[j]-97]++;
		}
		
		rep(j,0,26){
			if(i == 0){
				l_cnt[j] = cnt_memo[j];
			}
			l_cnt[j] = min(l_cnt[j],cnt_memo[j]);
		}
	}
	
	rep(i,0,26){
		rep(j,0,l_cnt[i]){
			cout << (char)(i+97);
		}
	}
	cout << endl;
	
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  map<int,int>mp;
  vector<int>a(n);
  rep(i,n) cin >> a[i];
  sort(a.begin(),a.end());
  rep(i,2){
    for(int j=1;j*j<=a[i];j++){
      if(a[i]%j==0){
        mp[j]++;
        mp[a[i]/j]++;
      }
    }
  }
  for(int i=2;i<n;i++){
    for(auto j:mp){
      if(a[i]%j.first==0){
        mp[j.first]++;
      }
    }
  }
  int ans=1;
  for(auto p:mp){  
    if(p.second==n || p.second==n-1){
      if(ans<p.first)ans=p.first;
    }
  }
  
  cout << ans << endl;
  
}


Measured memory_bytes: 640
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#include <stdio.h>
#include <bits/stdc++.h>

using namespace std;

#include <x86intrin.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define all(x) x.begin(), x.end()

#define mp make_pair
#define in insert
#define er erase
#define con continue
#define pb push_back
#define sc scanf
#define pr printf
#define ub upper_bound
#define lb lower_bound
#define s second
#define f first
#define int long long

const long long infl = 1e18; 
const int N = 3e5 + 300, N2 = 2e3, inf = 1e9 + 200;

set <int> S;
vector <int> g;
int n, m, k;
int a[N];
string ss;

main (){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++){
		int x;
		cin >> x;
		a[x]++;
		S.in(x);
	}
	if (S.size() == 1){
		int x = *S.begin();
		if (x == n - 1 || 2 * x <= n) cout << "Yes";
		else cout << "No";
	}
	else{
		int mn = *S.begin();
		S.er(S.begin());
		int mx = *S.begin();
		if (mx - mn == 1 && a[mn] + 1 <= mx && mx <= a[mn] + a[mx] / 2) cout << "Yes";
		else cout << "No";
	}
	return 0;
}












Measured memory_bytes: 5760
#define _GLIBCXX_DEBUG
#pragma GCC diagnostic ignored "-Wsign-compare"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < int(n); ++i)

void solve() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> S(m, vector<int>(0));
    int k, s;
    rep(i, m) {
        cin >> k;
        rep(j, k) {
            cin >> s;
            S[i].push_back(s - 1);
        }
        sort(S[i].begin(), S[i].end());
    }
    vector<int> P(m);
    for (auto &e : P) {
        cin >> e;
    }
    int ans = 0;
    for (int bit = 0; bit < (1 << n); bit++) {
        vector<bool> light(m, false);
        rep(j, m) {
            k = 0;
            rep(i, n) {
                if (bit & (1 << i)) {
                    // スイッチiが押された
                    for (auto &e : S[j]) {
                        if (e == i) k++;
                    }
                }
            }
            if (P[j] == k % 2) {
                light[j] = true;
            }
        }
        if (all_of(light.begin(), light.end(), [](bool x) { return x; })) {
            ans++;
        }
    }
    cout << ans << "\n";
}
int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}

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

int main(){
    ll H, W, M; cin >> H >> W >> M;
    map<ll, ll> MH, MW;
    vector<pair<ll, ll>> V(M);
    for(int i = 0; i < M; i++){
        ll h, w; cin >> h >> w;
        MH[h]++;
        MW[w]++;
        V[i] = {h, w};
    }
    ll ans = 0;
    ll MAX1 = 0, MAX2 = 0;
    set<ll> VH, VW;
    for(auto p : MH) MAX1 = max(MAX1, p.second);
    for(auto p : MH) if(p.second == MAX1) VH.insert(p.first);

    for(auto p : MW) MAX2 = max(MAX2, p.second);
    for(auto p : MW) if(p.second == MAX2) VW.insert(p.first);

    ll cnt = 0, SIZE = VH.size()*VW.size();
    for(auto p : V){
        ll h = p.first, w = p.second;
        if(VH.find(h) != VH.end() && VW.find(w) != VW.end()) cnt++;
    }


    if(cnt == SIZE) cout << MAX1 + MAX2 -1 << endl;
    else cout << MAX1 + MAX2 << endl;
}

Measured memory_bytes: 73400
function area(x1, y1, x2, y2, x3, y3) {
    var
    ab = Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)),
    bc = Math.sqrt((x2-x3)*(x2-x3)+(y2-y3)*(y2-y3)),
    ca = Math.sqrt((x3-x1)*(x3-x1)+(y3-y1)*(y3-y1)),
    s = 0.5*(ab+bc+ca),
    S= Math.sqrt(s*(s-ab)*(s-bc)*(s-ca));
    return S;
}

function inTriangle(x1, y1, x2, y2, x3, y3, xp, yp) {
  var
  abc = area(x1, y1, x2, y2, x3, y3),
  abp = area(x1, y1, x2, y2, xp, yp),
  bcp = area(x2, y2, x3, y3, xp, yp),
  cap = area(x3, y3, x1, y1, xp, yp),
  sub = abc-(abp+bcp+cap);
  return Math.abs(sub) <= 0.01;
}

function main() {
  input.forEach(function(line) {
    if(line.trim() === '') return;
    console.log(inTriangle.apply(null, line.split(' ').map(parseFloat)) ? 'YES' : 'NO');
  });
}

var
input = '';

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
  input += chunk;
});
process.stdin.on('end', function() {
  input = input.split('\n');
  main();
});

Measured memory_bytes: 7916
import java.util.Scanner;

public class Main
{
    String s;

    public static void main(String args[])
    {
	new Main().run();
    }
    
    void run()
    {
	in();
	
	for(int i = 0; i < s.length(); i += 2) {
	    System.out.print(s.substring(i, i + 1));
	}
	System.out.println();
    }

    void in()
    {
	Scanner sc = new Scanner(System.in);

	s = sc.next();
    }
}


Measured memory_bytes: 29108