akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <iterator>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef vector<PII> VPII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define FOR( v, c ) for ( auto &v : c )
#define EACH( it, c ) for ( auto it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()
#define DRANGE( c, p ) (c).begin(), (c).begin() + p, (c).end()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

const LL INF = LLONG_MAX / 4;

// セグメント木のユーティリティ
inline const int chl( const int k )
{
	return k * 2 + 1;
}

inline const int chr( const int k )
{
	return k * 2 + 2;
}

inline const int mid( const int l, const int r )
{
	return ( l + r ) / 2;
}

// セグメント木による Range Maximum Query
template < typename T >
class RangeMaximumQuery
{
private:
	const int N;
	vector<T> data;

public:
	RangeMaximumQuery( const vector<T> &src ) : N( src.size() ), data( N * 4 )
	{
		REP( i, 0, N )
		{
			update( i, src[i] );
		}
		return;
	}

	void update( const int p, const T x )
	{
		return update( p, x, 0, 0, N );
	}

	T maximum( const int a, const int b ) const
	{
		return maximum( a, b, 0, 0, N );
	}
private:
	void update( const int p, const T x, const int k, const int l, const int r )
	{
		if ( p < l || r <= p )
		{
			return;
		}
		if ( l + 1 == r && p == l )
		{
			data[k] = x;
			return;
		}

		update( p, x, chl( k ), l, mid( l, r ) );
		update( p, x, chr( k ), mid( l, r ), r );
		data[k] = max( data[ chl( k ) ], data[ chr( k ) ] );
	
		return;
	}

	T maximum( const int a, const int b, const int k, const int l, const int r ) const
	{
		if ( b <= l || r <= a )
		{
			return LLONG_MIN;
		}
		else if ( a <= l && r <= b )
		{
			return data[k];
		}
		else
		{
			return max( maximum( a, b, chl( k ), l, mid( l, r ) ), maximum( a, b, chr( k ), mid( l, r ), r ) );
		}
	}
};
// RangeMaximumQuery( VI src )
// update( pos, x )
// maximum( [ a, b ) )

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

	LL n;
	cin >> n;

	VI xs( n );
	REP( i, 0, n )
	{
		cin >> xs[i];
	}

	RangeMaximumQuery<LL> rmq( vector<LL>( n + 1, -INF ) );
	rmq.update( 0, 0 );

	REP( i, 0, n )
	{
		rmq.update( xs[i], rmq.maximum( 0, xs[i] ) + xs[i] );
	}

	cout << n * ( n + 1 ) / 2 - rmq.maximum( 0, n + 1 ) << endl;

	return 0;
}

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

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

    if(N == "abc") cout<<"Yes\n";
    else if(N == "acb") cout<<"Yes\n";
    else if(N == "bac") cout<<"Yes\n";
    else if(N == "bca") cout<<"Yes\n";
    else if(N == "cab") cout<<"Yes\n";
    else if(N == "cba") cout<<"Yes\n";
    else cout<<"No\n";


}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int n;
  cin >> n;
  bool flag = false;
  for (int i = 0; i <= 50000; ++i) {
    if (int(i * 1.08) != n)
      continue;
    cout << i << endl;
    flag = true;
    break;
  }
  if (flag == false)
    cout << ":(" << endl;
}


Measured memory_bytes: 3600
#include <stdio.h>

int main(int argc, char *argv[])
{
    int A, B;
    scanf("%d %d", &A, &B);
    if ( A%3 == 0 || B%3==0 || (A+B)%3 == 0 ){
        printf("Possible\n");
    } else {
        printf("Impossible\n");
    }
    return 0;
}

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

int main(void){
    int n,i,a[10001]={0};
    long min,max,sum=0;
    cin >> n;
    
    for(i=1;i<=n;i++){
        cin >> a[i];
    }
    
    min = 1000000;
    for(i=1;i<=n;i++){
        if(min >= a[i]){
            min = a[i];
        }
    }
    
    max = -1000000;
    for(i=1;i<=n;i++){
        if(max <= a[i]){
            max = a[i];
        }
    }
    
    for(i=1;i<=n;i++){
        sum = sum + a[i];
    }
    cout << min << " " << max << " " << sum << endl;
}


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

int main() {
  int N;
  cin >> N;
  vector<string> S(N);
  for (int i = 0; i < N; i++) cin >> S.at(i);

  sort(S.begin(), S.end());
  S.push_back("");

  vector<pair<int, string>> V;
  for (int i = 1, cnt = 1; i <= N; i++) {
    if (S.at(i - 1) == S.at(i)) {
      cnt++;
    } else {
      V.push_back({-cnt, S.at(i - 1)});
      cnt = 1;
    }
  }

  sort(V.begin(), V.end());

  for (int i = 0; i < V.size(); i++) {
    if (V.at(i).first == V.at(0).first) cout << V.at(i).second << "\n";
    else return 0;
  }
}

Measured memory_bytes: 20448
fun main(args: Array<String>) {
    var (A, B, C, D) = listOfLong()
    A -= 1
    val e = lcm(C, D)
    val ac = A / C
    val ad = A / D
    val acd = A / e
    val a = ac + ad - acd
    val bc = B / C
    val bd = B / D
    val bcd = B / e
    val b = bc + bd - bcd
    val ab = b - a
    val ans = (B - A) - ab
    println(ans)
}
fun gcd(a: Long, b: Long): Long = if (a % b == 0L) b else gcd(b, a % b)
fun lcm(a: Long, b: Long): Long = a * b / gcd(a, b)
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfLong() = listOfString().map { java.lang.Long.parseLong(it) }

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

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int INF = int (1e9) + int (1e5);
const ll INFL = ll(2e18) + ll(1e10);
const ui MOD = 1E9 + 7;
const double EPS = 1e-9;
#define FOR(i,n) for (int i=0;i<(n);++i)
#define ROF(i,x) for(int i = (x) ; i >= 0 ; --i)
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define ODD(x) (((x)&1)==0?(0):(1))
#define sign(x) ((x > 0) - (x < 0))
std::mt19937_64  generator(std::chrono::system_clock::now().time_since_epoch().count());

inline ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a, ll b) { return a ? gcd(b%a, a): b; }
ll lcm(ll a, ll b) { return a / gcd(a,b) * b; }


void READ(bool _local){
    ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef _DEBUG
    if (_local)
        freopen ("in.txt", "r", stdin);
#endif
}

const int N=2E5+1;
ll val[N];
vi g[N];

void add_edge(int u,int v){
    g[u].push_back(v);
    g[v].push_back(u);
}
void dfs(int node,int p=-1){
    for(int c:g[node]){
        if (c!=p){
            val[c] += val[node];
            dfs(c,node);
        }
    }    
    
}

int main() {
    READ(0);
    memset(val,0,sizeof(val));
    int n,q;cin>>n>>q;
    FOR(i,n-1){
        int x,y;cin>>x>>y;
        add_edge(x-1,y-1);
    }
    while(q--){
        int x,v;cin>>x>>v;
        val[x-1]+=v;
    }
    dfs(0);
    FOR(i,n) cout << val[i] << " ";
    return 0;
}



Measured memory_bytes: 24320
#include<iostream>
#include<vector>

int main(){
    int N;
    std::cin >> N;
    std::vector<int> T(N);
    int notDrink = 0;
    for(int i = 0; i < N; i++){
        std::cin >> T[i];
        notDrink += T[i];
    }
    int M;
    std::cin >> M;
    for(int i = 0; i < M; i++){
        int x, p;
        std::cin >> p >> x;
        p--; // to 0 origin
        std::cout << notDrink - T[p] + x << std::endl;
    }

    return 0;
}


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


Measured memory_bytes: 256
IDENTIFICATION DIVISION.
      PROGRAM-ID. 122A.
      DATA DIVISION.
      WORKING-STORAGE SECTION.
      01 B PIC X(1).
      
      PROCEDURE DIVISION.
      
      ACCEPT B.
      
      EVALUATE B
      	WHEN "A"
      		DISPLAY  "T"
      	WHEN "C"
      		DISPLAY  "G"
      	WHEN "G"
      		DISPLAY  "C"
      	WHEN "T"
      		DISPLAY  "A"
      WHEN OTHER
      	CONTINUE
      END-EVALUATE.
      
      STOP RUN.

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
#define FOR(i,a,b) for(long long int i=a;i<b;i++)
#define sz(s) (long long int)(s).size()
#define pb push_back
#define mp make_pair
const ll inf = 1000000000;
const ll MOD = 1000000007;
ll n, m, q;
vector<ll> a, b, c, d;
ll dfs(vector<ll> &A){
    ll ans = 0;
    if(A.size() == n){
        for(ll i=0;i<q;i++){
            if(A[b[i]] - A[a[i]] == c[i]){
                ans += d[i];
            }
        }
        return ans;
    }
    ll last = 1;
    if(!A.empty()){
        last = A.back();
    }
    for(ll i=last;i<=m;i++){
        A.pb(i);
        ans = max(ans, dfs(A));
        A.pop_back();
    }
    return ans;
}
int main(void){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);   
    cout.tie(NULL);    
    cin>>n>>m>>q;    
    a.resize(q), b.resize(q), c.resize(q), d.resize(q);
    for(ll i=0;i<q;i++){
        cin>>a[i]>>b[i]>>c[i]>>d[i];      
        a[i]--;
        b[i]--;  
    }        
    vector<ll> A;
    cout<<dfs(A)<<"\n";
}    
    

Measured memory_bytes: 3648
#!/usr/bin python3
# -*- coding: utf-8 -*-

import sys
#input = sys.stdin.readline

def main():
    N = int(input())
    mp = {}
    mx = 0
    for i in range(N):
        s = input()
        if s in mp:
            mp[s] += 1
            mx = max(mx, mp[s])
        else:
            mp[s] = 0
    ret = []
    for s, c in mp.items():
        if c == mx:
            ret.append(s)
    ret.sort()
    print('\n'.join(ret))

if __name__ == '__main__':
    main()

Measured memory_bytes: 34140
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;

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

	int n;
	cin >> n;

	// Divide into two piles, maximize sum of lengths of intersections of the piles
	// If there are three pairwise disjoint intervals, it is optimal to pick the longest interval for the other pile.
	// Otherwise, now every interval overlaps with either the interval that ends the earliest or starts the latest
	// The overlap of those two intervals will overlap with all other intervals, so if they are in the same pile,
	// it is optimal to pick the longest remaining interval alone in the other pile. If they are not in the same pile,
	// the result will be the minimum end over intervals in the left pile, plus the maximum start over intervals in the right pile.
	// Sort intervals by their start, and put some prefix into the right pile. Take answer as the maximum offer.

	vector<pair<int, int>> itvs(n);
	for (int i = 0; i < n; ++i) cin >> itvs[i].first >> itvs[i].second;

	// The interval that starts the latest
	for (int i = n-1; i >= 0; --i) {
		if (itvs[i].first > itvs.back().first) swap(itvs[i], itvs.back());
	}
	pair<int, int> x = itvs.back();
	itvs.pop_back();
	
	// The interval that ends the earliest
	for (int i = n-2; i >= 0; --i) {
		if (itvs[i].second < itvs.back().second) swap(itvs[i], itvs.back());
	}
	pair<int, int> y = itvs.back();

	if (y.second > x.second) {
		// x and y essentially are always in the same pile Put both x and y in the same pile
		ll res = 0;
		for (auto pr : itvs) res = max(res, (ll)pr.second - pr.first + 1);
		res += x.second - x.first + 1;
		cout << res << '\n';
	} else {
		itvs.pop_back();

		// Case 1: Put both x and y in the same pile
		ll res = 0;
		for (auto pr : itvs) res = max(res, (ll)pr.second - pr.first + 1);
		res += max(0, y.second - x.first + 1);

		// Case 2: x and y in different piles
		sort(itvs.begin(), itvs.end());

		int min_end = x.second;
		for (int i = n-3; i >= -1; --i) {
			int max_start = (i >= 0 ? max(y.first, itvs[i].first) : y.first);
			ll offer = max(0, min_end - x.first + 1) + max(0, y.second - max_start + 1);
			res = max(res, offer);

			cerr << x.first << ' ' << min_end << ", " << max_start << ' ' << y.second << ": " << offer << '\n';

			if (i >= 0) min_end = min(min_end, itvs[i].second);
		}

		cout << res << '\n';
	}

}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define reprr(i, m, n) for (ll i = m; i < n; i++)
#define inf 2e9
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
using Graph = vector<vector<pair<ll, ll>>>;


int main()
{
    ll N, C; cin >> N >> C;
    vvll D(C, vll(C));
    // cost to make i -> j
    rep(i, C) rep(j, C) {
        cin >> D[i][j];
    }
    vvll c(N, vll(N));
    rep(i, N) rep(j, N) {
        cin >> c[i][j]; c[i][j]--;
    }

    vvll counter(3, vll(C));

    rep(color, C) {
        // すべての色をcolorにするときにかかるコストを(i + j) % 3で分類して格納する
        rep(i, N) rep(j, N) {
            counter[(i + j + 2) % 3][color] += D[c[i][j]][color];
        }
    }

    ll minn = inf;
    rep(i, C) {
        rep(j, C) {
            if (i == j) continue;
            rep(k, C) {
                if (k == i || k == j) continue;
                minn = min(minn, counter[0][i] + counter[1][j] + counter[2][k]);
            }
        }
    }
    cout << minn << endl;
    return 0;
}

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

int main(){
    double sum = 0;
    int n;
    cin >> n;
    double value[15];
    string unit[15];

    for(int i = 0;i < n;i++){
        cin >> value[i] >> unit[i];
        if(unit[i] == "JPY")sum += value[i];
        else sum += (value[i] * 380000);
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
{-# OPTIONS_GHC -Wall #-}

import Data.Array

readInt :: String -> Int
readInt = read

fibs :: Array Int Int
fibs = listArray (0,50) $ 1 : 1 : [f i | i <- [2..50]]
    where
        f i = fibs!(i-1) + fibs!(i-2)

main :: IO ()
main = do
    n <- fmap readInt getLine

    let ans = fibs ! n

    print ans



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

using namespace std;

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

    int n,k;

    cin >> n >> k;

    if(k==1)
    {
    	cout << 0 << '\n';
    }
    else
    {
    	cout << n-k << '\n';
    }
    
    return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
p = list(map(int, input().split()))
for i in range(n):
    p[i] = (p[i] + 1) / 2
ans = sum(p[:k])
pre = sum(p[:k])
for j in range(k, n):
    pre = pre + p[j]- p[j - k]
    ans = max(ans, pre)
print(ans)

Measured memory_bytes: 92092
#include <iostream>

using namespace std;

int main()
{
    long int sum;
    int N;
    cin >> N;
    sum = 0;
    for(int i = 0 ; i < N ; i++ )
        if( (i+1)%5 != 0 && (i+1)% 3 !=0 )
            sum = sum+i+1;

    cout << sum;
    

    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	int N;
	cin >> N;
	vector<int> A(N);
	for (auto &x : A) {
		cin >> x;
	}
	auto B = A;
	sort(B.begin(), B.end());

	int odd = 0;
	for (int i = 0; i < N; ++i) {
		auto j = distance(B.begin(), lower_bound(B.begin(), B.end(), A[i]));
		odd += abs(i - j) % 2;
	}
	int ans = odd / 2;
	cout << ans << endl;
}


Measured memory_bytes: 1024
N,M=map(int,input().split())
L=[]
for i in range(M):
    a,b=map(int,input().split())
    L.append([b,a])
L.sort(reverse=True)
    
ans=1
P=L[0][1]
for i in range(M-1):
    if L[1+i][0]>P:
        P=max(P,L[1+i][1])
    else:
        ans+=1
        P=L[1+i][1]
print(ans)

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

ll h, w, h1, h2, h3, w1, w2, w3, mx, mn, ans = INF, m1, m2, m3;

int main() {
  cin >> h >> w;
  for (ll h1 = 1; h1 < h; ++h1) {
    m1 = h1 * w;

    h2 = ceil((h - h1) / 2.0);

    m2 = h2 * w;
    h3 = (h - h1 - h2);
    m3 = h * w - m1 - m2;
    mx = max({m1, m2, m3});
    mn = min({m1, m2, m3});
    ans = min(ans, mx - mn);

    h2 = h - h1;
    w2 = ceil(w / 2.0);
    m2 = h2 * w2;
    w3 = w - w2;
    m3 = h * w - m1 - m2;
    mx = max({m1, m2, m3});
    mn = min({m1, m2, m3});
    ans = min(ans, mx - mn);
  }

  swap(h, w);
  for (ll h1 = 1; h1 < h; ++h1) {
    m1 = h1 * w;

    h2 = ceil((h - h1) / 2.0);

    m2 = h2 * w;
    h3 = (h - h1 - h2);
    m3 = h * w - m1 - m2;
    mx = max({m1, m2, m3});
    mn = min({m1, m2, m3});
    ans = min(ans, mx - mn);

    h2 = h - h1;
    w2 = ceil(w / 2.0);
    m2 = h2 * w2;
    w3 = w - w2;
    m3 = h * w - m1 - m2;
    mx = max({m1, m2, m3});
    mn = min({m1, m2, m3});
    ans = min(ans, mx - mn);
  }

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


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

int main() {
  int H, N;
  cin >> H >> N;
  
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  
  int sum = 0;
  for (int i = 0; i < N; i++) sum += A.at(i);
  
  if (sum < H) cout << "No" << endl;
  else cout << "Yes" << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#define mod 1000000007
#define ten5 100005
#define PI 3.1415926
using namespace std;

int num[26];

int main()
{
    //int m,n,o=0,i,j,k;
    long long int sum=0,sum2=0,n1=0,n2=0,n3;
    double ans=0.0,half;
    long long int m,n,o,i,j,k=1,now=1;
    long long int a,a1,a2,a3,a4;
    //float f,g,h;
    //char now,pre;
    string s,s1;
    cin>>n>>k;
    char _map[n][k];
    vector<int> vi,vj;
    for(i=0;i<n;i++)
    {
        for(j=0;j<k;j++)
        {
            cin>>_map[i][j];
        }
    }
    for(i=0;i<n;i++)
    {
        for(j=0;j<k;j++)
        {
            if(_map[i][j]=='#') cout<<'#';
            else
            {
                sum=0;
                for(a1=-1;a1<=1;a1++)
                    for(a2=-1;a2<=1;a2++)
                    {
                        if(i==0 && a1==-1) break;
                        else if(i==n-1 && a1==1) break;
                        else if(j==0 && a2==-1) continue;
                        else if(j==k-1 && a2==1) break;
                        if(_map[i+a1][j+a2]=='#')
                            sum++;
                    }

                cout<<sum;
            }
        }
        cout<<endl;
    }
    return 0;
}



Measured memory_bytes: 256
//$g++ -std=c++11 Template.cpp 

//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

priority_queue<int> q_descending;
priority_queue<int, vector<int>, greater<int> > q_ascending;

#define MAX_N 10000001

int n;

struct edge {
  int from, to;
  ll cost;
    edge(int to, ll cost): to(to), cost(cost) {}
};
vector<edge> graph[MAX_N];
ll d[MAX_N];

void bfs(int k){
  queue<int> q;
  q.push(k);
  while(!q.empty()){
    int from = q.front(); q.pop();
    REP(i, graph[from].size()){
      edge e = graph[from][i];
      int to = graph[from][i].to;
      ll cost = graph[from][i].cost;
      if(d[to]!=0) continue;
      d[to] = d[from] + cost;
      q.push(to);
    }
  }
}

int
main(void){  
  ios_base::sync_with_stdio(false);
  
  cin >> n;
  REP(i, n-1) {
    ll a, b, c;
    cin >> a >> b >> c;
    a--; b--;
    edge e1 = {(int)b, c};
    edge e2 = {(int)a, c};
    graph[a].emplace_back(e1);
    graph[b].emplace_back(e2);
  }

  //wf まにあわない
  int q, k;
  cin >> q >> k;
  k--;

  //kから各頂点へのの最短距離を求める
  bfs(k);
  
  REP(i, q){    
    int x, y;
    cin >> x >> y;
    x--; y--;
    cout << d[x] + d[y] << endl;
  }
  
  return 0;
}


Measured memory_bytes: 242304
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
	int a,b,k;
	cin>>k>>a>>b;
	for(int i=a;i<=b;++i)
	{
		if(i%k==0)
		{
			cout<<"OK";
			return 0;
		}
	}	
	cout<<"NG";
} 

Measured memory_bytes: 3632
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e18;
template<typename T> void cmax(T &a, T b) { a = max(a, b); }
template<typename T> void cmin(T &a, T b) { a = min(a, b); }

signed main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n), b(m);
  map<int, int> t;
  set<int> s;
  rep(i, n) {
    cin >> a[i];
    s.insert(a[i]);
    t[a[i]]++;
  }
  rep(i, m) {
    cin >> b[i];
    s.insert(b[i]);
    t[b[i]]++;
  }
  int cnt = 0;
  vector<int> ans;
  for (auto x : t) {
    if (x.second == 2) cnt++, ans.push_back(x.first);
  }
  cout << cnt << ' ' << s.size() << endl;
  for (auto x : ans) cout << x << endl;
  for (auto x : s) cout << x << endl;

  return 0;
}



Measured memory_bytes: 28844
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        w: [i64; n],
    }
    let w_sum: i64 = w.iter().sum();
    let mut acc = 0i64;
    let mut ans = std::i64::MAX;
    for i in 0..n {
        acc += w[i];
        ans = min(ans, (w_sum - 2*acc).abs());
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
import math 
import sys 
"""
def p(n,r):
    if n<r:
        return 1
    return math.factorial(n)//math.factorial(n-r)
"""
def main():
    input=sys.stdin.readline 
    N,K=map(int,input().split())
    E=[[] for _ in range(N)]
    MOD = 10**9+7
    for _ in range(N-1):
        u,v=map(int,input().split())
        u-=1
        v-=1
        E[u].append(v)
        E[v].append(u)

    if N==1:
        print(K)
        sys.exit()

    color = [-1 for _ in range(N)]
    dp = [-1 for _ in range(N)]
    stack = []
    color[u]=1
    ans=K
    for i,v in enumerate(E[u]):
        stack.append(v)
        ans*=(K-i-1)
        ans%=MOD


    while stack:
        u=stack.pop()
        color[u]=1
        length=0
        for v in E[u]:
            if color[v]==-1:
                stack.append(v)
                length+=1
        if dp[length]==-1:
            tmp=1
            for i in range(K-1-length,K-1):
                tmp*= i 
                tmp%=MOD 
            ans*=tmp 
        else:
            ans*=dp[length]
        ans%=MOD

    print(ans%MOD)

if __name__ == '__main__':
    main()
    



Measured memory_bytes: 24428
import sys
sys.setrecursionlimit(10**6)

def main(n):
	b = list(map(int, input().split()))
	ans = []
	for i in range(n):
		if i+1 < b[i]:
			print(-1)
			return
		if i == 0:
			ans = [1]
			continue
		ans = ans[:b[i]-1] + [b[i]] + ans[b[i]-1:]
	print("\n".join(map(str,ans)))

main(int(input()))

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

int main(){
    int n;
    cin>>n;
    for (int i=1;i<=n;i++){
        int x=i;
        if(x%3==0||x%10==3){
            cout<<" "<<i;
        }
        else{
            while(x/=10){
                if(x%10==3){
                    cout<<" "<<i;
                    break;
                }
            }
        }
    }
    cout<<endl;
}


Measured memory_bytes: 3104
#include <stdio.h>
int main(void)
{
	int a,b;
	int d,r;
	double f;
	

	scanf("%d",&a);
	
	scanf("%d",&b);
	
	d = a/b;
	r = a%b;
	f = (double)a/b;
	
	printf("%d %d %lf",d,r,f);
	
	return 0;
	
}

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

int main() {
	int n, a, b;
	cin >> n >> a >> b;
	if (n == 2) {
		cout << "Borys" << endl;
	}
	else if ((b - a - 1) % 2 == 1) {
		cout << "Alice" << endl;
	}
	else {
		cout << "Borys" << endl;
	}
}

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

using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define SORT(v) sort(ALL(v))
//#define scanf scanf_s
typedef pair<int, int> P;

int main()
{
	int n;
	while (cin >> n, n)
	{
		bool hidari = false; bool migi = false;
		string f[500];
		int cnt = 0;
		f[0] = "";
		FOR(i,1 ,n+1)
		{
			cin >> f[i];
			if (f[i] == "lu")
			{
				if (f[i - 1] == "ru") cnt++;
			}
			if (f[i] == "ru")
			{
				if (f[i - 1] == "lu") cnt++;
			}
			if (f[i] == "ld")
			{
				if (f[i - 1] == "rd") cnt++;
			}
			if (f[i] == "rd")
			{
				if (f[i - 1] == "ld") cnt++;
			}
		}
		cout << cnt << endl;

	}
	return 0;
}

Measured memory_bytes: 1216
N=int(input())
L=list(map(int,input().split()))
L=sorted(L,reverse=True)
count=0
for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            if L[i]<L[j]+L[k] and L[i]>L[j] and L[j]>L[k]:
                count+=1
print(count)

Measured memory_bytes: 68096
// reference https://www.ipsj.or.jp/07editj/promenade/4506.pdf

import java.util.Arrays;
import java.util.Scanner;

class Node implements Comparable<Node> {
    int value;
    int place;

    Node(int value, int place) {
        this.value = value;
        this.place = place;
    }

    public int compareTo(Node n) {
        return value - n.value;
    }
}

public class Main {
    private static int sillysort(int m, int[] seq) {
        // initialize
        Node[] nodes = new Node[m];
        Node[] temp = new Node[m];
        for(int i = 0; i < m; i++) {
            temp[i] = new Node(seq[i], i);
        }
        Arrays.sort(temp);
        for(int i = 0; i < m; i++) {
            nodes[i] = new Node(-1, -1);
        }
        for(int i = 0; i < m; i++) {
            nodes[i].value = seq[i];
            nodes[temp[i].place].place = i;
        }
        int s = temp[0].value;

        // compute
        int cost = 0;
        for(int i = 0; i < m; i++) {
            int j = nodes[i].place;
            if(j >= 0 && j != i) {
                int n = 1;
                int amin = nodes[i].value;
                int sum = nodes[i].value;
                while(j != i) {
                    int next = nodes[j].place;
                    amin = Math.min(amin, nodes[j].value);
                    sum += nodes[j].value;
                    n++;
                    nodes[j].place = -1;
                    j = next;
                }
                cost += Math.min(sum + (n - 2) * amin, sum + amin + (n + 1) * s);
            }
        }
        return cost;
    }

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

        System.out.println(sillysort(n, a));

        sc.close();
    }
}



Measured memory_bytes: 30436
N = input()
A = map(int, raw_input().split())
 
MOD = 10 ** 9 + 7

def gcd(x, y):
    while y != 0:
        x, y = y, x % y
    return x

def lcm(x, y):
    return x/gcd(x, y)*y
 
l = A[0]
for a in A:
    l = lcm(l, a)
 
res = 0
for a in A:
    res = (res + (l * pow(a, MOD - 2, MOD)) % MOD) % MOD
 
print(res)



Measured memory_bytes: 3460
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ul;
typedef signed long long ll;
ul over = 1000000007;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  string s;
  int k;
  cin >> s >> k;
  vector< string > v;
  unordered_map< string, bool > m;
  for (int i=0; i<s.size(); ++i) {
    for (int j=1; i+j<=s.size() && j<=k; ++j) {
      string tgt = s.substr(i, j);
      if (m.count(tgt) > 0) continue;
      m[tgt] = true;
      v.push_back(tgt);
    }
  }
  sort(v.begin(), v.end());
  cout << v[k-1] << endl;
  return 0;
}


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

class Program
{
    static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var monsters = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).OrderBy(i => i).ToList();
        
        while (true)
        {
            var buf = monsters.First();
            monsters = monsters.Select(x => x % buf).Where(x => x != 0).ToList();
            monsters.Add(buf);
            monsters = monsters.OrderBy(i => i).ToList();
            if (monsters.Count() == 1)
            {
                Console.WriteLine(monsters.First());
                return;
            }
        }
    }
}

Measured memory_bytes: 26720
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m,max_x,min_y;
    int x,y;
    cin >> n>>m>>max_x>>min_y;
    for (int i;i<n;i++){
        cin >> x;
        max_x = max(max_x,x);
    }
    for (int i;i<m;i++){
        cin >> y;
        min_y = min(min_y,y);
    }
    if (max_x < min_y){
        cout << "No ";
    }
    cout << "War" << endl;
}

Measured memory_bytes: 256
// SeeAlso: 

#include <bits/stdc++.h>

#define MAX 4
#define rep(i,n) for(int i = 0; i < n; i++)

using namespace std;
double W, H;
double x, y;

int main() {

    cin >> W >> H >> x >> y;


    double ans = W * H / 2.0;
    int d;
    if ((x == (W / 2)) && (y == (H/2))) {
        d = 1;
    } else {
        d= 0;
    }
    cout << ans << " "  << d << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int distance (int num1, int num2);
  
int main(void){
  int x, a, b;
  scanf( "%d %d %d", &x, &a, &b);
  int d1 = distance (x,a);
  int d2 = distance (x,b);
  if (d1>=d2){
    printf("B");
  }else {
    printf("A");
  }
return 0;
}

  int distance (int num1, int num2){
    int dis;
    if (num1 > num2){
      dis = num1 - num2;
    } else {
      dis = num2 - num1;
    }
    return dis;
  }


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

int main()
{
        ll a[6],i;
        rep(i,5)
            cin >> a[i];
        rep(i,5)
        {
            if(a[i]==0)
                cout << i+1 << endl;
        }
    
    return 0; 
}

Measured memory_bytes: 3552
#define rep(i, a, b) for(int i = a; i < (int)(b); i++)
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
template<class T> inline void chmax(T &a, const T &b) {if(a < b) a = b;}
template<class T> inline void chmin(T &a, const T &b) {if(a > b) a = b;}
const long long INF = 1LL<<60;

// const ll DIV = (ll)8e3+7;
const ll MAXN = (ll)8e3+7;


int main(void) {
   ll N;
   cin>>N;
   string S;
   cin>>S;
   if (N%2 == 1) {
      cout<<"No"<<endl;
      return 0;
   }
   bool flag = true;
   rep(i,0,N/2) {
      if (S[i] != S[i+N/2]) flag = false;
   }
   if (flag) cout<<"Yes"<<endl;
   else cout<<"No"<<endl;

   return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll  long long
#define pp pair<int,int>
#define ppn pair<pp,int>
#define F first
#define S second
#define N 205
#define mod 1000000007
#define pi 3.14159265358979323846

using namespace std;



int main()
{


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



    string n;
    cin>>n;
    int k = n.length();
    if(n[k-1]!='s')n+='s';
    else n+="es";
    cout<<n<<endl;
}


Measured memory_bytes: 3652
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

struct RangeMinimumQuery {
	int n;
	vector<int>d;
	RangeMinimumQuery(int m) {
		for (n = 1; n < m; n <<= 1);
		d.assign(2 * n, INF);
	}
	void update(int i, int x) {
		d[n + i] = x;
		for (int j = (n + i) / 2; j > 0; j >>= 1)
			d[j] = min(d[2 * j], d[2 * j + 1]);
	}
	int query(int a, int b) {
		return query(a, b, 1, 0, n);
	}
	int query(int a, int b, int k, int l, int r) {
		// [a,b) [l,r)
		if (r <= a || b <= l)return INF;
		else if (a <= l&&r <= b)return d[k];
		else {
			int vl, vr;
			vl = query(a, b, 2 * k, l, (l + r) / 2);
			vr = query(a, b, 2 * k + 1, (l + r) / 2, r);
			return min(vl, vr);
		}
	}

};

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, q; cin >> n >> q;
	RangeMinimumQuery rmq(n);
	rep(i, 0, q) {
		int com, a, b; cin >> com >> a >> b;
		if (com)cout << (rmq.query(a, b + 1)==INF?(1ll<<31)-1:rmq.query(a,b+1)) << endl;
		else rmq.update(a, b);
	}
	return 0;
}

Measured memory_bytes: 3856
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD 1000000007
#define PI 3.1415926535897932384

std::ostream &operator<<(std::ostream &out, const vector<int> &tgt)
{
	string s;
	for (int i = 0; i<tgt.size(); i++) {
		s += (to_string(tgt[i]) + ((i != tgt.size() - 1) ? " " : ""));
	}
	out << s;
	return out;
}

int main() {
	int n, m, ans;
	char c;
	cin >> n >> m;
	rep(i, n*m) {
		cin >> c;
		if (c == '#')ans++;
	}
	cout << (ans == n + m - 1 ? "Possible" : "Impossible") << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
long long  gcd(long long  a,long long  b){
	if(a<b) swap(a,b);
	if(b==0) return a;
	else return gcd(b,a%b);
}
int main(){
	long long  a,b;
	scanf("%lld%lld",&a,&b);
	printf("%lld\n",gcd(a,b));
	return 0;
}


Measured memory_bytes: 2728
#include<cstdio>
#include<algorithm>
long long w[105],v[105];
long long a[4][105];
long long sum[4][105];

int main(){
    int n; long long m;
    scanf("%d%lld",&n,&m);
    for(int i = 1; i <= n; i++){
        scanf("%lld%lld",&w[i],&v[i]);
    }
    int size[4] = {0,0,0,0};
    long long fst = w[1];
    for(int i = 1; i <= n; i++){
        long long p = w[i]-fst;
        a[p][++size[p]] = v[i];
    }
    for(int i = 0; i < 4; i++){ 
        std::sort(a[i]+1,a[i]+1+size[i],[&](long long u,long long v){
            return u>v;
        });
        sum[i][0] = 0;
        for(int j = 1; j <= size[i]; j++) sum[i][j] = sum[i][j-1]+a[i][j];
    }
    long long ans = 0;
    for(int i = 0; i <= size[0]; i++){
        for(int j = 0; j <= size[1]; j++){
            for(int k = 0; k <= size[2]; k++){
                for(int l = 0; l <= size[3]; l++){
                    long long offer = sum[0][i]+sum[1][j]+sum[2][k]+sum[3][l];
                    long long weight = i*1ll*fst+j*1ll*(fst+1ll)+k*1ll*(fst+2ll)+l*1ll*(fst+3ll);
                    if(weight<=m && ans<offer) ans = offer;
                }
            }
        }
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 1712
s = input().strip()
x = ""
cur = 0
for i in range(len(s)):
    if s[i]=="0":
        x += "0"
        cur += 1
    elif s[i]=="1":
        x += "1"
        cur += 1
    else:
        if cur>0:
            x = x[:-1]
            cur -= 1
print(x)

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

int main() {
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 1; i <= n; i += 2) {
    int cnt = 0;
    REP(j, 1, i + 1) if (i % j == 0) cnt++;
    if (cnt == 8) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
//header{{{
//#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/math/common_factor_rt.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
  
using namespace std;
//using namespace boost;
//using namespace multiprecision;  

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define Fixed fixed << setprecision(12)
#define int int64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9+7; 
constexpr int mod2 = 998244353;

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A, class B> using umap = unordered_map<A,B>;
  
inline int square(int a){ return a * a;}
inline int updiv(int a,int b){ return (a + b - 1) / b; }

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

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

    int n;
    cin >> n;
    vector<int> a(n),cnt(n+1);

    rep(i,n){
        cin >> a[i];
        ++cnt[a[i]];
    }

    int sum = 0;
    reps(i,n){
        sum += cnt[i] * (cnt[i]-1) / 2;
    }

    rep(i,n){
        if(cnt[a[i]] >= 2){
            cout << sum - (cnt[a[i]] * (cnt[a[i]]-1) / 2 - (cnt[a[i]]-1) * (cnt[a[i]]-2) / 2) << '\n';
        }else{
            cout << sum << '\n';
        }
    }

    return 0;
}


Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
#define N 15

int n,m,sum,d[N][1<<N],e[1<<N],f[1<<N][N];

void upd(int &x,int y){x=max(x,y);}

int read(){
	int x=0,f=1;char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-')  f=-f;
	for (;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return x*f;
}

int main(){
	n=read();m=read();
	for (int i=1;i<=m;i++){
		int x=read()-1,y=read()-1;
		d[x][1<<y]=d[y][1<<x]=read();
		sum+=d[x][1<<y];
	}
	for (int i=0;i<n;i++)
		for (int j=1;j<(1<<n);j++)
			d[i][j]=d[i][j&-j]+d[i][j-(j&-j)];
	for (int i=0;i<(1<<n);i++)
		for (int j=0;j<n;j++)
			if (i&(1<<j))
			e[i]=e[i-(1<<j)]+d[j][i-(1<<j)];
	memset(f,0x80,sizeof(f));f[1][0]=0;
	for (int i=1;i<(1<<n);i++)
		for (int j=0;j<n;j++)
			if (f[i][j]!=-1){
				for (int k=0;k<n;k++)
					if ((i&(1<<k))==0&&d[j][1<<k])
					upd(f[i+(1<<k)][k],f[i][j]+d[j][1<<k]);
				for (int s=(1<<n)-1-i,k=s;k;k=(k-1)&s)
					upd(f[i+k][j],f[i][j]+e[k+(1<<j)]);
			}
	printf("%d\n",sum-f[(1<<n)-1][n-1]);
	return 0;
}

Measured memory_bytes: 4224
{-# LANGUAGE Strict #-}

main :: IO ()
main = do
  [n, k] <- map read . words <$> getLine
  print $ solve n k

solve :: Integer -> Integer -> Integer
solve n k = ((12 + 2 * k ^ 3 + 8 * n + 3 * n ^ 2 + n ^ 3 - 3 * k ^ 2 * (2 + n) + k * (-2 + 3 * n)) `div` 6) `mod` m

m :: Num a => a
m = 10 ^ (9 :: Int) + 7


Measured memory_bytes: 3944
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7;
constexpr long long INF = std::numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Mfor(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, k, t, s, q, last, cnt, sum[2000000], ans, dp[10000000],a[2000000], b[2000000];
string str;
bool f;
double Ans;
char c;
int di[4][2] = { { 0,1 },{ 1,0 },{ -1,0 } ,{ 0,-1 } };
struct Edge { LL to, cost; };
vector<Edge>vec[10000];
vector<Pll>v;
map<string, LL>ma;
set<LL>st;
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

int main() {
	cin >> n >> m >> k;
	if (n- k > 0) {
		Ans += ( double)((n - k)*(m-1)*2)/(double)(n*n);
   }
	if (k == 0)
		Ans /= 2;
	printf("%.30f", Ans);
	return 0;
}

Measured memory_bytes: 1020
while 1:
    a, b = [int(i) for i in input().split()]
    if a == 0 and b == 0:
        break
    n = b - a
    t = n // 1000
    n = n % 1000
    f = n // 500
    n = n % 500
    h = n // 100
    print(h, f, t)



Measured memory_bytes: 5616
#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
using namespace std;
typedef long double ld;
typedef long long lli;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<bool> vb;
#define deb(x) cout << #x": " << (x) << endl;

const int N = 1e3+5;
const lli INF = 1e18;
const lli MOD = 1e9+7;

bool mm[N];
vi primes(1,2);
ld nk[N][N];
void sieve(){
	for(int i = 4; i<N; i+=2)mm[i]=1;
	for(int i = 3; i*i<=N; i+=2)if(!mm[i])for(int j = i*i; j<N; j+=i)mm[j]=1;
	for(int i = 3; i<N; i+=2)if(!mm[i])primes.pb(i);
}

void pascal(){
	fore(i,0,N)nk[i][0]=nk[i][i]=1.0;
	fore(i,1,N)fore(j,1,i)nk[i][j]=nk[i-1][j-1]+nk[i-1][j];
}

lli gcd(lli a, lli b){return (b?gcd(b,a%b):a);}

lli lcm(lli a, lli b){
	if(a<b)swap(a,b);
	lli c = gcd(a,b);
	a/=c;
	return a*b;
}

int popcount(lli x) { return __builtin_popcountll(x); }

lli poww(lli a, lli b){
	lli res =1;
	while(b){
		if(b&1) res = res * a;
		a = a*a;
		b/=2;
	}
	return res;
}

lli powm(lli a, lli b){
	lli res =1;
	while(b){
		if(b&1) res = (res * a)%MOD;
		a = (a*a)%MOD;
		b/=2;
	}
	return res;
}

bool isPrime(lli x){
	if(x==1)return 0;
	for(auto i:primes){
		if(i*i>x)return 1;
		if(x%i==0)return 0;
	}
	return 1;
}

// ---- コーディングはここから！ ('-')7

int main(){_
	int n,m; cin>>n>>m;
	if(m&1){
		cout<<"No"<<ENDL;return 0;
	}
	fore(i,0,n+1){
		lli sum = 4*i+2*(n-i);
		if(sum==m){cout<<"Yes"<<ENDL;return 0;}

	}
	cout<<"No"<<ENDL;
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
int nCkModp(int n, int k, int p)
{
    vector <int> res(n+1);
    if(2*k > n)
        k = n-k;
    for (int i = 0; i <=n; i++) res[i] = 1;
    for (int i = 2; i <= n;i++)
        for (int j = min(i-1,k); j > 0; j--)
            res[j] = (res[j]+res[j-1]) ;

    return res[k];
}

int main()
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);
    //freopen("Inp.txt","r", stdin);
    //freopen("Out.txt","w", stdout);

    int n; cin >> n;
    vector <int> a(n), b(n), c(n);
    for (int i = 0; i < n; i++)
        cin >> a[i] >> b[i] >> c[i];
    vector <int> a1(n), b1(n), c1(n);
    a1[0] = a[0]; b1[0] = b[0]; c1[0] = c[0];
    for (int i = 1; i < n; i++)
    {
        b1[i] = max(a1[i-1]+b[i],c1[i-1]+b[i]);
        a1[i] = max(b1[i-1]+a[i],c1[i-1]+a[i]);
        c1[i] = max(a1[i-1]+c[i],b1[i-1]+c[i]);
    }
    cout << max (a1[n-1],max(b1[n-1],c1[n-1]));
    return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <cstdio>
#include <set>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <string>
#include <sstream>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <fstream>
#include <iomanip>
//#include <unordered_map>
using namespace std;
#define dbg(x) cerr << #x " = " << x << endl;
typedef pair<int, int> P;
typedef long long ll;

int main()
{
    //freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string op;
    cin >> op;
    string n;
    for(int i = 0; i < op.size(); i++)
    {
        if(i == 0)
        {
            n += op[i];
        }
        else
        {
            if(op[i] != n[n.size() - 1])
            {
                n += op[i];
            }
        }
        
    }
    cout << n.size() - 1 << endl;
}

Measured memory_bytes: 592