akhauriyash/Code-Regression huggingface dataset:
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let a: usize = read();
    let b: usize = read();
    if a == b {
        println!("Draw");
        return;
    }

    if a == 1 {
        println!("Alice");
        return;
    }

    if b == 1 {
        println!("Bob");
        return;
    }

    if a > b {
        println!("Alice")
    } else {
        println!("Bob")
    }
}


Measured memory_bytes: 4352
#include<iostream>
#include<string>

using namespace std;


void pln()
{
	cout << endl;
	return;
}

void print(int x)
{
	cout << x << endl;
	return;
}

void print(string str) {
	cout << str << endl;
	return;
}

int ri() {
	int x;
	cin >> x;
	return x;
}

string rs() {
	string str;
	cin >> str;
	return str;
}

int main(void)
{
	int a = ri();
	int b = ri();
	int c = ri();
	int d = ri();

	int l = a + b;
	int r = c + d;

	if (l>r)
	{
		print("Left");
	}
	else if (l < r) {
		print("Right");
	}
	else {
		print("Balanced");
	}

}



Measured memory_bytes: 256
// B.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

int main(int argc, char *argv[]) {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	int ans = 0;
	sort(a.begin(), a.end());
	for (int i = 0; i < n; ++i) {
		for (int j = i + 1; j < n; ++j) {
			if (a[i] == a[j]) continue;
			for (int k = j + 1; k < n; ++k) {
				if (a[j] == a[k]) continue;
				ans += a[i] + a[j] > a[k];
			}
		}
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;

int main(){
    int k;
    int n;
    cin >> k >> n;
    //int maxlen = 0;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    int len = k - (a[n - 1] - a[0]);
    for(int i = 0; i < n - 1; i++){
        len = max(len, a[i + 1] - a[i]);
    }
    int result = k - len;
    cout << result << endl;
}

Measured memory_bytes: 1024
#!/usr/bin/env python
"""<https://github.com/cheran-senthil/PyRival>"""
from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip
else:
    _str = str
    str = lambda x=b"": x if type(x) is bytes else _str(x).encode()


def main():
    N = read_int()
    print((N-2) * 180)


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        if self.buffer.tell():
            return self.buffer.read()
        return os.read(self._fd, os.fstat(self._fd).st_size)

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", b" "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", b"\n"))
    if kwargs.pop("flush", False):
        file.flush()


sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip(b"\r\n")


def read():
    return input()


def read_array(sep=None, maxsplit=-1):
    return read().split(sep, maxsplit)


def read_int():
    return int(read())


def read_int_array(sep=None, maxsplit=-1):
    return [int(a) for a in read_array(sep, maxsplit)]

# endregion

if __name__ == "__main__":
    main()


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

int main() {
  int n;
  cin>>n;
  
  bool empty=0;

  rep(i,0,n){
    int a;
    cin>>a;
    if(a%2==0){
      if(a%3==0){continue;}
      if(a%5==0){continue;}
      empty=1;break;
    }
  }
    
  if(empty==0){cout<<"APPROVED"<<endl;}
  else{cout<<"DENIED"<<endl;}
    
  return 0;

}

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

int n, l, r, ans, a[MaxN], s[MaxN * 10];
ll tr[MaxN * 10];

int read() {
	int res = 0, flag = 1; char ch;
	ch = getchar();
	while (!isdigit(ch)) {
		if (ch == '-') flag = -1;
		ch = getchar();
	}
	while (isdigit(ch)) {
		res = res * 10 + ch - '0';
		ch = getchar();
	}
	return res * flag;
}

void add(int x) {
	for (; x <= MaxN * 2; x += x & -x)
		tr[x]++;
}

ll ask(int x) {
	ll res = 0;
	for (; x; x -= x & -x)
		res += tr[x];
	return res;
}

bool check(int val) {
	ll res = 0;
	memset(tr, 0, sizeof(tr));
	for (int i = 1; i <= n; i++)
		if (a[i] < val) s[i] = s[i - 1] - 1;
		else s[i] = s[i - 1] + 1;
	for (int i = 0; i <= n; i++) {
		res += ask(s[i] + MaxN);
		add(s[i] + MaxN);
	}
	return res >= (ll) n * (n + 1) / 4;
}

int main() {
	n = read();
	for (int i = 1; i <= n; i++)
		a[i] = read(), r = max(a[i], r);
	while (l <= r) {
		int mid = l + r >> 1;
		if (check(mid)) ans = mid, l = mid + 1;
		else r = mid - 1;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 12280
N=int(input())
A=list(map(int,input().strip().split()))
Q=int(input())

dp=[0 for n in range(100000+1)]
for n in range(len(A)):
    dp[A[n]-1]+=1

init=0
for n in range(1,len(dp)):
    init+=n*dp[n-1]

ans=init
for n in range(Q):
    B,C=map(int,input().strip().split())
    ans=ans-dp[B-1]*B+dp[B-1]*C
    dp[C-1]+=dp[B-1]
    dp[B-1]=0
    print(ans)

Measured memory_bytes: 20744
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = LLONG_MAX;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(16);

	//cout << setprecision(10) << scientific << ans << endl;
}

signed main() {
	ll n;
	string s;

	cin >> n;

	vector<string> v;

	REP(i, n) {
		cin >> s;
		sort(s.begin(), s.end());
		v.push_back(s);
	}

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

	v.push_back("a");

	ll ans = 0;
	ll cnt = 1;
	
	REP(i, n) {
		if (v[i] != v[i + 1]) {
			ans += cnt * (cnt - 1) / 2;
			cnt = 1;
		}
		else {
			cnt++;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 5748
import java.io.BufferedReader;
import java.io.InputStreamReader;
 
public class Main {
 
    public static void main(String[] args) throws Exception {
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
        int n = readInt(r);
        int[] price = new int[n];
        for(int i = 0 ; i < n ; i++) price[i] = readInt(r);
 
        int max = -2000000000;
        int min = price[0];
        for(int x = 1 ; x < n ; x++){
            max = Math.max(max,price[x] - min);
            min = Math.min(min,price[x]);
        }
 
        System.out.println(max);
    }
 
    public static int readInt(BufferedReader r) throws Exception{
        return Integer.parseInt(r.readLine());
    }
 
}

Measured memory_bytes: 43132
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cstdio>
#include<cmath>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
int MOD=1000000007;
int inf=1e18;
bool judge(string const& s,char x){
    int n=s.length();
    rep(i,n){
        if(s[i]!=x){
            return false;
        }
    }
    return true;
}
string pro(string const& s,char x){
    int n=s.length();
    string res;
    rep(i,n-1){
        if(s[i+1]==x){
            res+=x;
        }
        else{
            res+=s[i];
        }
    }
    return res;
}
signed main(){
    string s;cin>>s;
    int res=inf;
    rep(i,26){
        string buf=s;
        int cnt=0;
        while(!judge(buf,'a'+i)){
            buf=pro(buf,'a'+i);
            cnt++;
            if(cnt>105)break;
        }
        res=min(res,cnt);
    }
    cout<<res<<"\n";
    return 0;
}

Measured memory_bytes: 256
// AOJ 585 Nearest Two Points
// 2017.9.24 bal4u
// 2018.3.17
// 2018.5.3

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct { int x, y; } PP;

#define INF  0x10101010

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
int in()
{
	int n = 0, c = gc();
	if (c == '-') {	c = gc();
		do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
		return -n;
	}
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

PP L[500005], R[500005];

int cmp(const void *a, const void *b)
{
	return ((PP *)a)->x - ((PP *)b)->x;
}

void merge(PP *p, int low, int mid, int high)
{
	int n1, n2, i, j, k;

	n1 = mid-low, n2 = high-mid;
	memcpy(L, p+low, sizeof(PP)*n1);
	memcpy(R, p+mid, sizeof(PP)*n2);
	L[n1].y = R[n2].y = INF;

	i = 0, j = 0;
	for (k = low; k < high; k++) {
		if (L[i].y <= R[j].y) p[k] = L[i++];
		else                  p[k] = R[j++];
	}
}

int closest_pair(int n, PP *p)
{
	int m, i, j, t;
	int ans, d, x;

	if(n <= 1) return INF;
	m = n >> 1;
	x = p[m].x;
	ans = closest_pair(m, p);
	d   = closest_pair(n-m, p+m);
	if (d < ans) ans = d;
	merge(p, 0, m, n);

	t = 0;
	for (i = 0; i < n; i++) {
		d = p[i].x-x;
		if (d*d >= ans) continue;

		for (j = 0; j < t; j++) {
			int dx = p[i].x - L[t-1-j].x;
			int dy = p[i].y - L[t-1-j].y;
			int dy2 = dy*dy;
			if (dy2 >= ans) break;
			d = dx*dx + dy2;
			if (d < ans) ans = d;
		}
		L[t++] = p[i];
	}
	return ans;
}

PP p[500005];

int main()
{
	int n, i;

	n = in();
	for (i = 0; i < n; i++) p[i].x = in(), p[i].y = in();
	qsort(p, n, sizeof(PP), cmp);
	printf("%d\n", closest_pair(n, p));
	return 0;
}


Measured memory_bytes: 9556
#include<stdio.h>

int main(){
int i,sum=0;
char gyo[1001];

while(scanf("%s",&gyo) && gyo[0] != '0'){
sum=0;
for(i=0;gyo[i]!='\0';i++){
sum+=gyo[i] - '0';
}
printf("%d\n",sum);

}

return 0;

}



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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
const ll INF = 1LL<<55;

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, m, l, q;
	cin >>n >>m >>l;
	vector<VL> a(n, VL(n, INF));
	rep(i, n) a[i][i] = 0;
	auto b = a;
	rep(i, m){
		int x, y, z;
		cin >>x >>y >>z;
		if(a[x-1][y-1] > z) a[x-1][y-1] = a[y-1][x-1] = z;
	}
	rep(k,n) rep(i,n) rep(j,n) a[i][j] =min(a[i][j], a[i][k] + a[k][j]);
	
	rep(i, n) rep(j, n) if(a[i][j] > 0 && a[i][j] <= l) b[i][j] = 1;
	rep(k,n) rep(i,n) rep(j,n) b[i][j] =min(b[i][j], b[i][k] + b[k][j]);
	
	cin >>q;
	while(q--){
		int s, t; cin >>s >>t;
		ll ans = b[s-1][t-1];
		cout <<(ans<INF? ans -1: -1) <<"\n";
		
	}

	return 0;
}


Measured memory_bytes: 2048
use proconio::input;
use std::collections::HashMap;

fn main() {
  input! {
    N: i128,
    K: i128,
  }
  
  let quotient = N / K;
  let mut n = if 0 < quotient {
    N - (K * quotient)
  } else {
    N
  };
    
  let mut map: HashMap<i128, bool> = HashMap::new();
  let mut result = i128::max_value();
  while map.get(&n).is_none() {
    map.insert(n, true);
    result = std::cmp::min(n, result);
    n = (n - K).abs();
  }
  println!("{}", result);
}

Measured memory_bytes: 2144
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define sqr(x)  ((x) * (x)) 
#define cub(x)  ((x) * (x) * (x))
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// int gcd(int a,int b){return b?gcd(b,a%b):a;}

ll gcd(ll x, ll y)
{
    ll temp;
    while (y != 0) {
        temp = y;
        y = x % y;
        x = temp;
    }
    return (x);
}

ll lcm( ll m, ll n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}//lcm

int main(){
  ll a,b; cin >> a >> b;
    cout << lcm(a,b) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5+2;
typedef long long ll;
int a[maxn];

int main()
{
	int n; scanf("%d",&n);
	for(int i=0;i<n;++i)
	{
		scanf("%d",&a[i]);
	}
	ll ans = 0;
	int tot = 0;
	int l=0,r=0;
	
	while(1)
	{

		while(r<n && !(tot&a[r]))
		{
			tot+=a[r++];
			
		}
		//if(r>=n) break;
		ans+=r-l;
		//cout<<l<<" "<<r<<"\n";
		tot-=a[l++];
		if(l>=n) break;
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;
typedef long double ld;

int main(){
  ld N,M;
  cin >> N >> M ;
  ld sum=0;
  ll count=0;
  vector<ll> v(N);
  for(ll i=0 ; i<N ;i++){
    cin >> v[i];
  }
  for(ll i=0 ; i<N ;i++){
    sum+=v[i];
  }
  for(ll i=0 ; i<N ;i++){
    if((sum/(4*M))<=v[i]){
      count+=1;
    }
  }
  if(count>=M){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3732
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define erep(i,a,n) for(int i = a;i<=n;i++)
typedef long long ll;
#define int long long
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define P = pair<int,int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

struct UnionFind{
  // 小さい方を大きいほうにくっつける
  // これのおかげでO(logN)になる
  // 親をたどる際に途中経路に結果を残しておくことで根に直接葉をつなげる
  vector<int> d;
  UnionFind(int n=0):d(n,-1){}
  int find(int x){
    // 根を返すfind関数
    // d[x] < 0 -> xは根
    if(d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x,int y){
    x = find(x); y = find(y);
    if(x == y) return false;
    if(d[x] > d[y]) swap(x,y);
    // 根には自分を含めた項の数が負の数で入っている
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x,int y){return find(x) == find(y);}
  int size(int x){return -d[find(x)];}
};

signed main(){
  int n,m;
  cin >> n >> m;
  UnionFind tree(n);
  int sum = n*(n-1)/2;
  vint A(m),B(m);
  rep(i,0,m){
    cin >> A[i] >> B[i];
    A[i]--;B[i]--;
  }
  vint ans(m);
  ans[m-1] = sum;
  rrep(i,m-1,1){
    if(!tree.same(A[i],B[i])){
      sum -= tree.size(A[i]) * tree.size(B[i]);
      tree.unite(A[i],B[i]); 
    }
    ans[i-1] = sum;
  } 
  rep(i,0,m){
    cout << ans[i] << endl;
  }
}

Measured memory_bytes: 4480
#include <iostream>
#include<stdio.h>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<math.h>

using namespace std;

int main()
{
	int N,M;
	cin >> N >> M;
	vector<int> A(N);
	for (int i = 0; i < N; i++)
	{
		cin >> A[i];	//カード
	}

	vector<pair<int, int>> v(M);
	long long int ans=0;

	for (int i = 0; i < M; i++)
	{
		cin >> v[i].second >> v[i].first;	//書かれてる整数を最初の要素とする
	}

	sort(A.begin(), A.end());	//カードを昇順に並べる
	sort(v.begin(), v.end());
	int j = 0;	//昇順に並べたカードのそえじ
	for (int i = M - 1; i >= 0; i--)	//数が大きい操作から順に
	{
		while (A[j] < v[i].first && v[i].second>0)	//数が大きいかつ回数が残ってるなら
		{
			A[j] = v[i].first;
			v[i].second--;
			j++;

		}

	}

	for (int i = 0; i < N; i++)
	{
		ans += A[i];
		//cout << A[i] << endl;
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 1408
S = list(input())
T = list(input())
new_S = S
judge = 0

if(S == T):
  print('Yes')
else:
 for i in range(len(S)):
  tmp = S.pop(-1)
  S.insert(0,tmp)
  new_S = S
  if(new_S == T):
    judge = 1
    break
 if(judge == 1):
  print('Yes')
 else:
  print('No')
    


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ld long double
#define int long long
using namespace std;
const int N = 2e5 + 50;
const int mod = 1e9 + 7;
const int inf = 1e17;
int dx[] = {0, 1, -1, 0, -1, 1, 1, -1};
int dy[] = {1, 0, 0, -1, -1, 1, -1, 1};
int gcd(int a, int b){
	if(a == 0){
		return b;
	}return gcd(b % a, a);
}
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);	
	int n;
	cin >> n;
	int gc = 0;
	for(int i = 0; i < n; i++){
		int num;
		cin >> num;
		gc = gcd(gc, num);
	}
	cout << gc;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int a,b,c,d;

       cin>>a>>b>>c>>d;

       int even=0;

        while(a!=0 && c!=0){
              even++;

             if(even % 2!=0){
             if(c > b)
             c=c-b;

             else
             c=0;
             }

            else{
             if(a > d)
             a=a-d;

             else
             a=0;
           }
        }

         if(a==0)
         cout<<"No";

         else
         cout<<"Yes";
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define rep(i,n) for(long long int i = 0; i < n; i++)
#define _rep(i,m,n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;
const ll mod = 1000000007;

int main(){
   ll n; cin >> n;
   vector<ll> a(n + 10);
   fill(a.begin() + n,a.end(), 0);
   rep(i,n) cin >> a[i];
   ll nagai = 0;

   sort(a.begin(),a.end(),greater<>());
   for (int i = 0; i < n; i++){
       if(a[i] == a[i + 1]){
           if(a[i + 1] == a[i + 3] && nagai == 0){
               print(a[i] * a[i]);
               return 0;
            }else if(a[i + 1] == a[i + 3] && nagai != 0){
               print(nagai * a[i]);
               return 0;
            }else if(nagai == 0){
               nagai = a[i];
               i++;
            }else if(nagai != 0){
               print(nagai * a[i]);
               return 0;
           }
       }
   }
   print(0);
   return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<string.h>
#include <iomanip>
#include <sstream>
using namespace std;

int main() {
  int N, M;
  long long a;
  int ans = 0;
  string s;

  cin >> N >> M;

  ans += N * (N-1)/2;
  ans += M*(M-1)/2;

  cout << ans << endl;
}


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

int main() {
  long n,m,a,b,ans=0;
  cin >> n >> m;
  vector<long> h(n);
  vector<vector<long>> aaa(n);
  for(long i=0;i<n;i++) cin >> h[i];
  for(long i=0;i<m;i++) {
    cin >> a >> b;
    aaa[a-1].push_back(b-1);
    aaa[b-1].push_back(a-1);
  }
  for(long i=0;i<n;i++) {
    bool good=true;
    for(long j=0;j<aaa[i].size();j++) {
      if(h[i]<=h[aaa[i][j]]) good=false;
    }
    if(good) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 9808
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(obj)   (obj).begin(),(obj).end()

#define debug(var)  do{std::cout << __LINE__ << "> " << #var << ": ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

struct CumulativeSum {
    int n;
    vector<long long> nums;
    vector<long long> s;
    CumulativeSum(int n) : n(n), s(n + 1, 0) { }
    void add(long long num) {
        nums.push_back(num);
    }
    void build() {
        for (int i = 0; i < n; ++i) s[i+1] = s[i] + nums[i];
    }
    // [l, r), l and r is 0-indexed.
    long long sum(int l, int r) {
        return s[r] - s[l];
    }
};

void Main() {
	int N, K; cin >> N >> K;
	vl x(N + 1);
	REP(i, N) cin >> x[i];
	x[N] = 0;
	sort(ALL(x));
	vl positive_v;
	vl negative_v;
	for (auto v : x) {
		if (v > 0) {
			positive_v.push_back(2 * v);
			negative_v.push_back(v);
		} else if (v < 0) {
			positive_v.push_back(-v);
			negative_v.push_back(-2 * v);
		} else {
			positive_v.push_back(v);
			negative_v.push_back(v);
		}
	}
	ll res = numeric_limits<ll>::max();;
	// debug(positive_v);
	// debug(negative_v);
	REP(i, N - K + 1) {
		// debug(i);
		// debug(positive_v[i] + positive_v[i + K]);
		// debug(negative_v[i] + negative_v[i + K]);
		chmin(res, positive_v[i] + positive_v[i + K]);
		chmin(res, negative_v[i] + negative_v[i + K]);
	}
	cout << res << endl;
}

int main() {
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}


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

typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

#define REP(i, x) for (ll i = 0; i < (ll)(x); i++)
#define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++)
#define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;
const int INF = pow(2, 30) - 1;

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

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

    ll N,M;
    string S;
    cin >> N>>M;

    vector<ll> A(N),B(N);

    REP(i,N){
        cin >> A.at(i) >> B.at(i);
    }

    vec_p p(N);
    REP(i,N){
        p.at(i) = make_pair(A.at(i), B.at(i));
    }

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

    ll count = M;
    ll ans = 0;
    REP(i, N)
    {
        ll tmp1 = p.at(i).first;
        ll tmp2 = p.at(i).second;
        if (M > tmp2){
            ans += tmp1 * tmp2;
            M -= tmp2;

        }
        else if(M==tmp2){
            ans += tmp1 * tmp2;
            break;
        }
        else{
            ans += tmp1 * M;
            break;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 6364
#include <bits/stdc++.h>
using namespace std;
int main () {
  int A, B;
  cin >> A >> B;
  int ans = B;
  if(6 <= A && A <= 12){
    ans /= 2;
  } else if(A <= 5){
    ans = 0;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			int m = scanner.nextInt();
			// パスの一覧
			@SuppressWarnings("unchecked")
			Set<Integer>[] paths = new Set[n];
			IntStream.range(0, n).forEach(i -> paths[i] = new HashSet<>());
			IntStream.range(0, m).forEach(i -> {
				int a = scanner.nextInt() - 1;
				int b = scanner.nextInt() - 1;
				paths[a].add(b);
				paths[b].add(a);
			});
			System.out.println(getResult(0, paths, ~(0xFFFF_FFFF << n), new HashMap<>()));
		}
	}

	/**
	 * @param startNode アクセス始点
	 * @param paths
	 * @param status    グラフのアクセス済ステータス（nビット目が1＝まだアクセスしていない）
	 * @param map
	 * @return アクセスのパスの数
	 */
	private static int getResult(int startNode, Set<Integer>[] paths, int status, Map<List<Integer>, Integer> map) {
		// 現在のノードが最後のノードの場合
		if (0 == (status & (~(1 << startNode)))) {
			return 1;
		}
		List<Integer> key = Arrays.asList(startNode, status);
		Integer result = map.get(key);
		if (null == result) {
			result = 0;
			// 現在のノードをアクセス済にする
			status &= ~(1 << startNode);
			for (Integer nextNode : paths[startNode]) {
				if ((status & (1 << nextNode)) > 0) {
					result += getResult(nextNode, paths, status, map);
				}
			}
			map.put(key, result);
		}
		return result;
	}
}


Measured memory_bytes: 26700
/**
	Language: C++ 11
	Author  : ebby21
**/

#include <bits/stdc++.h>

using namespace std;

#define FASTIO() ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
#define DEBUG(var) cerr << '\n' << #var << "\t:\t" << var << '\n'
#define FORF(i, L, U) for (ll i = (L); i <= (U); ++i)
#define FORR(i, U, L) for (ll i = (U); i >= (L); --i)
#define FORE(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef unsigned int ui;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< ii > vii;

int main() {
	FASTIO();
	int n, m;
	cin >> n >> m;
	ll ans = 0;
	if (m >= 2) {
		ans += (m*(m - 1LL))/2;
	}
	if (n >= 2) {
		ans += (n*(n - 1LL))/2;
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    char a[4];

    scanf("%s",a);

    int i,j,c=0;

    for(i=0;i<4;i++)
        for(j=i+1;j<4;j++)
    {
        if(a[i]==a[j])
            c++;
    }

    if(c==2)
        printf("Yes");
    else
        printf("No");
    
}

Measured memory_bytes: 128
// C++ 14
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)

template <class T, class T2>
void group(T &xs, vector<pair<T2, int> > &result) {
  int i=0, j;
  while (i<xs.size()) {
    j=i;
    while (j < xs.size() and xs[j] == xs[i]) j++;
    result.push_back({ xs[i], j-i });
    if (j==i) i++;
    i=j;
  }
}
  
int main() {
  int n; cin >> n;
  vector<int> A(n);
  loop(i,0,n) cin >> A[i];
  sort(A.begin(), A.end());
  vector<pair<int, int> > G;
  group(A, G);
  int ans = 0;
  for (auto &&g: G) {
    if (g.first == g.second) continue;
    if (g.first > g.second) ans += g.second;
    else ans += g.second - g.first;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4512
let inv a =
    let rec loop = function
        0 -> raise Not_found
        | i -> if (a*i) mod 26 = 1 then i else loop (i-1)
    in loop 26 ;;

let decode ainv b r = (ainv*(r-b+26)) mod 26;;
let rec gcd a b = if b = 0 then a else gcd b (a mod b);;

let dup a b =
    let rec loop l i =
        if i = -1 then false
        else
            let decoded = decode a b i in
            if List.mem decoded l then true
            else loop (decoded::l) (i-1)
in loop [] 25;;

let invs =
    let rec loop l = function
        0 -> l
        | i ->
            if gcd i 26 = 1 then loop ((inv i)::l) (i-1)
            else loop l (i-1)
    in loop [] 26
;;

let decrypt s =
    let f a b = String.map (fun c ->
        let cc = (Char.code c) in
        if cc >= 97 && cc <= 122 then decode a b (cc-97) |> (+) 97 |> Char.chr
        else c) in
    let rec loop = function
    [] -> ()
    | h::tl ->
            for i = 0 to 25 do
                let decrypted = (f h i s) in
                if Str.string_match (Str.regexp ".*\\(this\\|that\\).*")  decrypted 0 then
                    if not (dup h i) then
                        print_endline decrypted;
            done;
            loop tl
    in loop invs
;;

let () =
    let n = read_int () in
    let rec read = function
        0 -> ()
        | i ->
            let line = read_line () in
            decrypt line;read (i-1)
    in read n
;;

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

int main(){
  int A,B,K;
  cin >> A >> B >> K;
  vector<int> C;
  for(int i=A;i<B+1;i++){
    if(i<A+K){
      C.push_back(i);
    }
    else if(B-K<i){
      C.push_back(i);
    }
  }
  int D=C.size();
  for(int i=0;i<D;i++){
    cout << C.at(i) << endl;
  }
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <map>
#define REP(i,n) for(long (i)=0;(i)<(n);(i)++)
#define REPI(i,a,b) for(long (i)=(a);(i)<(b);(i)++)
#define INF numeric_limits<double>::infinity()
constexpr long MOD = 1e9 + 7;
using namespace std;
using P = pair<long, long>;
using VI = vector<long>;

int main() {
    int n;
    cin >> n;
    map<long, long> r;
    REP(i,n) {
        long p;
        cin >> p;
        r[p] = i + 1;
    }
    REP(i,n-1) {
        cout << 30000l * (i + 1) << " ";
    }
    cout << 30000l * n << endl;
    REP(i,n-1) {
        cout << 30000l * (n - i - 1) + r[i + 1] << " ";
    }
    cout << r[n] << endl;
}


Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 998244353;

inline ll qpow(ll a,ll b){
	ll res = 1;
	while(b){
		if(b & 1) res = (res*a) % MOD;
		a = (a*a) % MOD;
		b >>= 1;
	}
	return res % MOD;
}

ll s[100005],a[100005];

int main(){
	ll x = -2e18,n;
	scanf("%lld",&n);
	memset(s,0,sizeof(s));
	for(ll i = 0;i < n;i++){
		scanf("%lld",&a[i]);
		s[a[i]]++;
		x = max(x,a[i]);
	}

	ll ans = 1;
	for(int i = 0;i < x;++i){
		if(!s[i]){
			ans = 0;
			break;
		}
		ll t = qpow(s[i],s[i+1]) % MOD;
		ans = (ans*t) % MOD;
	}
	
	if(s[0] != 1 || a[0] != 0) ans = 0;
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 1792
str = input()
if str == 'SUN':
  print(7)
elif str == 'MON':
  print(6)
elif str == 'TUE':
  print(5)
elif str == 'WED':
  print(4)
elif str == 'THU':
  print(3)
elif str == 'FRI' :
  print(2)
elif str == 'SAT':
  print(1)

Measured memory_bytes: 3060
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE UnboxedTuples #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE MultiWayIf #-}

import Control.Monad
import Control.Monad.ST
import Control.Monad.State
import Control.Applicative
import Control.Arrow
import Data.List
import Data.Array
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
import Data.Maybe
import Data.Bits
import Data.Ord
import Data.Ratio
import Data.Int
import Data.Char
import qualified Data.IntMap as IM
import qualified Data.Map as Map
import qualified Data.ByteString.Char8 as BS
import qualified Data.Set as Set
import qualified Data.Sequence as Sq
import Data.Tuple
import Data.Function
import Text.Printf
import Debug.Trace
import Numeric

modifyArray arr i f = readArray arr i >>= \x -> writeArray arr i (f x)

listToTuple2 [a,b] = (a,b)
listToTuple3 [a,b,c] = (a,b,c)
listToTuple4 [a,b,c,d] = (a,b,c,d)
listToTuple5 [a,b,c,d,e] = (a,b,c,d,e)

readIntBS = fst . fromJust . BS.readInt
  
for = flip map

infixr 1 ?
(?) :: Bool -> (a,a) -> a
(?) b t = (if b then fst else snd) t


main :: IO ()
main = do
  s <- getLine
  t <- getLine

  let
    m1 = map (map head . group . sort . snd) $ Map.toList $ (f s t) `execState` (Map.empty)
    m2 = map (map head . group . sort . snd) $ Map.toList $ (f t s) `execState` (Map.empty)

  putStrLn $ if all ((==1) . length) m1 && all ((==1) . length) m2 then "Yes" else "No"

f [] [] = return ()
f (x:xs) (y:ys) = do
  mp <- get
  if x `Map.member` mp then
    put $ Map.insert x (y : (mp Map.! x)) mp
    else
    put $ Map.insert x [y] mp
  f xs ys


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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef tuple<int, int> duo;

#define TT template<typename T>
#define ET(T) typename T::value_type
TT inline T sq(T x){return x*x;}
TT inline T In(){T x;cin>>x;return x;}
TT inline int ubnd(T&v,ET(T) x){return upper_bound(begin(v),end(v),x)-begin(v);}
TT inline int lbnd(T&v,ET(T) x){return lower_bound(begin(v),end(v),x)-begin(v);}
TT inline void sort(T&v){sort(begin(v),end(v));}
TT inline void revs(T&v){reverse(begin(v),end(v));}
TT inline void uniq(T&v){sort(v);v.erase(unique(begin(v),end(v)),end(v));}
TT inline void inpt(T&v,int n,function<ET(T)()>f=In<ET(T)>){for(v.reserve(n);n--;v.emplace_back(f()));}
TT inline void show(T&v,string d=" ",string e="\n"){int i=0;for(auto&x:v)i++&&(cout<<d),cout<<x;cout<<e;}
#undef TT
#undef ET

inline void fast_io(){ios::sync_with_stdio(0); cin.tie(0);}
inline int in(){int x;scanf("%d",&x);return x;}
inline string instr(){string x;cin>>x;return x;}
inline ll pow_mod(ll a, ll k, ll m){ll r=1;for(;k>0;a=a*a%m,k>>=1)if(k&1)r=r*a%m;return r;}
inline ll mod_inv(ll a, ll p){return pow_mod(a,p-2,p);}

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

int main()
{
  string s;
  cin >> s;
  bool cup, clow, cnum, len;
  cup = clow = cnum = false;
  len = s.size() > 5u;
  for (char c : s){
    if (isupper(c)) cup = true;
    if (islower(c)) clow = true;
    if (isdigit(c)) cnum = true;
  }
  if (cup && clow && cnum && len) cout << "VALID\n";
  else cout << "INVALID\n";

  return (0);
}

// priority_queue queue deque front top push pop map set stringstream max_element min_element insert count find get tie make_tuple

Measured memory_bytes: 1160
n = int(input())
a = [int(x) for x in input().split()]

count = []

flg = 1
for i in range(1,n):
    if a[i] == a[i-1]:
        flg += 1
        
        if i == n-1:
            count.append(flg)
            
    else:
        count.append(flg)
        flg = 1
        i +=1
cnt = 0

for j in count:
    cnt += j//2
print(cnt)
        

Measured memory_bytes: 38384
"""
# 標準入力取得
## 文字列
 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())

## 数値
 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

import math
import sys
import itertools
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

if __name__ == "__main__":
    n = int(sys.stdin.readline())
    l = [list(list(sys.stdin.readline().split())) for i in range(n)]

    c = 0
    for i in range(n):
        if l[i][1] == "JPY":
                c += float(l[i][0])
        else:
            c += float(l[i][0]) * 380000
    print(c)

Measured memory_bytes: 5200
import sys
from itertools import combinations
def I(): return int(sys.stdin.readline().rstrip())


N = I()
A = [(i*(i-1))//2 for i in range(448)]

index = 0
for i in range(2,448):
    if A[i] == N:
        print('Yes')
        print(i)
        index = i
        break
else:
    print('No')
    exit()

ANS = [[index-1] for _ in range(index)]
for i,a in enumerate(list(combinations([i for i in range(index)],2))):
    b,c = a
    ANS[b].append(i+1)
    ANS[c].append(i+1)

for ans in ANS:
    print(*ans)



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

int main()
{
  static char s[500010];
  scanf("%s",s);
  int n=strlen(s);
  static int a[500000];
  for(int i=0;i<n;i++){
    a[i]=s[n-i-1]-'0';
  }
  int L=-1,R=10000000;
  while(L+1<R){
    int D=(L+R)/2;
    int d=D;
    int q=0;
    bool F=0;
    for(int i=0;i<n;i++){
      int g=a[i]-q;
      if(g>d){
	F=1;
	break;
      }
      int d2=g+(d-g)/10*10;
      q=(d2-g)/10;
      d=d2;
    }
    if(F){
      L=D;
    }
    else{
      R=D;
    }
  }
  printf("%d\n",(R+8)/9);
  return 0;
}


Measured memory_bytes: 2688
#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;
int main(){
  double a,b,c,n;
  cin>>n;
  c=fmod (n,2);
  if(c==1){a=n/2+0.5;}
  else{a=n/2;}
 b=a/n;
  printf("%11.10lf",b);
}

Measured memory_bytes: 384
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		double C  =  Math.toRadians(sc.nextInt());
		double S = a * b * Math.sin(C) / 2;
		double L = a + b + Math.sqrt(a * a + b * b - 2 * a * b * Math.cos(C));
		double h = S * 2 / a;
		System.out.printf("%.8f\n%.8f\n%.8f\n",S, L, h);
	}

}

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

using namespace std;

#define ll long long

const ll mod  = 1e9 + 7;
const ll INF = 1e14;


void solve(){

    ll n; cin >> n;
    ll st = 100, ans = 0;
    while(st < n){
        st += st/100;
        ++ans;
    }
    cout << ans;
}

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

    //int test; cin >> test;
    //for(int t = 1; t <= test; ++t){
        solve();
    //}

	return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0; i<(int)(n); i++)
int main(){
long A, V, B, W, T; cin >> A >> V >> B >> W >> T;
long sa=abs(A-B), oi=V-W;
if(oi<=0||oi*T<sa){ cout << "NO\n"; return 0; }
cout << "YES\n";
}


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

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, n)	 for(int i = 0; i < (n); i++)
#define all(a)		 begin(a), end(a)

typedef long long int		   ll;
typedef long long unsigned int llu;

void solve(ll N) {
	printf("ABC%d", N);
}

int main() {
	ll N;
	scanf("%lld", &N);
	solve(N);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define ALL(a) (a).begin(),(a).end()
 
using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;
 
const ll MOD  = 1e9+7;
const ll LINF = 1LL << 60;
const int INF = 1e9 + 7;

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

    ll cntr[200010] = {};
    ll a[n];
    rep(i, n){
        cin >> a[i];
        cntr[a[i]]++;
    }

    ll num_pair[200010] = {};
    ll sum_pair = 0;

    rep(i, 200010){
        if(cntr[i] < 2)continue;
        num_pair[i] = cntr[i]*(cntr[i]-1) / 2;
        sum_pair += num_pair[i];
    }

    rep(i, n){
        ll ans = sum_pair - num_pair[a[i]];
        if(cntr[a[i]] > 2)ans += (cntr[a[i]]-1)*(cntr[a[i]]-2) / 2;
        cout << ans << endl;
    }

}

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

using namespace std;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define MP make_pair
#define PB push_back
#define ff first
#define ss second
#define TR(it,c) for( typeof(c.begin()) it = c.begin(); it != c.end(); ++it )
#define TRR(it,c) for( typeof(c.rbegin()) it = c.rbegin(); it != c.rend(); ++it
#define REP(i,a) for (int i = 0; i < (a); i++)
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORD(i,a,b) for (int i = (a); i >= (b); i--)

#define DRI(a) int a; scanf("%d", &a);
#define DRII(a, b) int a, b; scanf("%d %d", &a, &b);
#define DRIII(a, b, c) int a, b, c; scanf("%d %d %d", &a, &b, &c);
#define RI(a) scanf("%d", &a);
#define RII(a, b) scanf("%d %d", &a, &b);
#define RIII(a, b, c) scanf("%d %d %d", &a, &b, &c);
#define MM(arr, num) memset((arr), (num), sizeof((arr)))
#define DEB(x) cerr << ">>> " << (#x) << " -> " << (x) << endl;
#define DEBA(x,n) cerr << (#x) << " "; deba((x),(n));
void deba(int * a, int n){ cerr << "| "; REP(i,n) cerr << a[i] << " "; cerr << "|" << endl;}


inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }

const int INF = 1<<30;
typedef long long ll;
typedef unsigned long long ull;
/*******************************************************/
int a[223456];
int l[223456];
int r[223456];

int ia[223456];

int main() {

  DRI(n);
  a[0] = 0;
  REP(i,n)RI(a[i+1]);
  a[n+1]= 0;

  FOR(i,1,n) ia[ a[i] ] = i;

  FORD(i,n,1){
    int p = ia[i]-1;
    while(1){
        if( a[p] < i ){ l[ia[i]] = p; break;}
        else p = l[p];
    }
  }

  FORD(i,n,1){
    int p = ia[i]+1;
    while(1){

        if( a[p] < i ){ r[ia[i]] = p; break;}
        else p = r[p];
    }
  }
  ll res = 0;
  FOR(i,1,n){

    res+= (ll)( i - l[i]) * (ll)( r[i] - i )* (ll)a[i];
  }

  cout << res << endl;


  return 0;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

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


	int N;
	cin >> N;
	string S;
	cin >> S;

	ll P[100001];
	P[0] = 1;
	ll mod = 998244353;
	rep1(i, N) P[i] = P[i - 1] * i % mod;
	ll kotae = P[N];

	int flag = 0;
	int a = 0, b = 0;
	char ca, cb;
	rep(i, 3 * N) {

		switch (flag) {
		case 0:
			flag = 1;
			ca = S[i];
			a++;
			break;
		case 1:
			if (S[i] == ca) a++;
			else {
				cb = S[i];
				kotae = kotae * a % mod;
				a--;
				b++;
				if (a) flag = 2;
				else flag = 3;
			}
			break;
		case 2:
			if (S[i] == ca) a++;
			else if (S[i] == cb) {
				kotae = kotae * a % mod;
				a--;
				b++;
				if (a == 0) flag = 3;
			}
			else {
				kotae = kotae * b % mod;
				b--;
				if (b == 0) flag = 1;
			}
			break;
		case 3:
			if (S[i] == ca) {
				a++;
				flag = 2;
			}
			else if (S[i] == cb) {
				a++;
				cb = ca;
				ca = S[i];
				flag = 2;
			}
			else {
				kotae = kotae * b % mod;
				b--;
				if (b == 0) flag = 0;
			}
			break;
		}
		//cesp(S[i]);
		//ce(flag);
		//cesp(a);
		//ce(b);
		//cesp(ca);
		//ce(cb); ce("");

	}

	co(kotae);


	Would you please return 0;
}

Measured memory_bytes: 1428
mod=10**9+7
H,W,A,B=map(int,input().split())

Factorial=[1]*(H+W+1)
for i in range(1,H+W+1):
  Factorial[i]=Factorial[i-1]*(i)%mod
def power(x,y):
  if y==0:
    return 1
  elif y==1:
    return x%mod
  elif y%2==0:
    return power(x,y//2)**2%mod
  else:
    return (power(x,y//2)**2)*x%mod

inverseFactorial=[1]*(H+W+1)
inverseFactorial[H+W]=power(Factorial[H+W],mod-2)
for i in range(0,H+W)[::-1]:
  inverseFactorial[i]=(inverseFactorial[i+1]*(i+1))%mod
  
def comb(x,y):
  if x<y or y<0:
    return 0
  else:
    return (Factorial[x]*inverseFactorial[y]*inverseFactorial[x-y])%mod
ans=0
for a in range(0,H-A):
  ans=(ans+comb(B+a-1,a)*comb(W-B+H-a-2,H-a-1))%mod
print(ans)
  

Measured memory_bytes: 18804
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int n,m;
  cin >> n >> m;
  int a[n];
  rep(i,n) R a[i];
  if(n==m) pr(1);
  else pr((int)ceil((double)(n-1)/(m-1)));
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


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

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fo(i,l,r) for(int i=l;i<=r;i++)
#define of(i,l,r) for(int i=l;i>=r;i--)
#define fe(i,u) for(int i=head[u];i;i=e[i].next)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
inline void open(const char *s)
{
	#ifndef ONLINE_JUDGE
	char str[20];
	sprintf(str,"%s.in",s);
	freopen(str,"r",stdin);
//	sprintf(str,"%s.out",s);
//	freopen(str,"w",stdout);
	#endif
}
inline int rd()
{
	static int x,f;
	x=0;f=1;
	char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;
	for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+ch-'0';
	return f>0?x:-x;
}
const int N=510;
int n,K,a[N][N];

int main()
{
	K=rd();
	int B=500;
	if(K<=B){
		n=K;
		cout<<n<<'\n';
		fo(i,1,n){
			fo(j,1,n)cout<<i<<' ';cout<<'\n';
		}return 0;
	}n=B;
	cout<<n<<'\n';
	fo(i,1,n){
		for(int x=i,y=1;!a[x][y];x=x%n+1,y=y%n+1)a[x][y]=i;
	}
	fo(i,B,K){
		for(int x=i-B,y=1;a[x][y]^i;x=(x+1)%n+1,y=(y+1)%n+1)a[x][y]=i;
	}
	fo(i,1,n){
		fo(j,1,n)cout<<a[i][j]<<' ';cout<<'\n';
	}
	return 0;
}


Measured memory_bytes: 2176
#!/usr/bin/env python3
import sys

def main():
    N = int(input())
    red = [list(map(int,input().split())) for _ in range(N)]
    blue = [list(map(int,input().split())) for _ in range(N)]

    red.sort(key=lambda x: -x[1]) #y座標が大きい順
    blue.sort(key=lambda x: x[0]) #x座標が小さい順
    j_list = []
    for i in range(N):
        c,d =blue[i]

        for j in range(N):
            a,b = red[j]
            if j in j_list:
                continue

            if a<c and b<d:
                # d以下の最大のy座標はbである
                j_list.append(j)
                break
    print(len(j_list))

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
N = int(input())
A = [[int(i) for i in input().split()] for i in range(2)] 

tmp = 0

for i in range(N):
    list1 = A[0][:N-i]
    list2 = A[1][N-1-i:]
    if tmp < sum(list1) + sum(list2):
        tmp = sum(list1) + sum(list2)

print(tmp)

Measured memory_bytes: 3060