akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; //1e18
const double EPS = 1e-10;

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

    vector<int> a(N);
    ll sum = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> a[i];
        sum += a[i];
    }

    ll average = sum / N;
    ll x1 = average - 1;
    ll x2 = average;
    ll x3 = average + 1;
    ll ans1 = 0; // average - 1
    ll ans2 = 0; // average
    ll ans3 = 0; // average + 1
    for (int i = 0; i < N; i++)
    {
        ans1 += pow((a[i] - x1), 2);
        ans2 += pow((a[i] - x2), 2);
        ans3 += pow((a[i] - x3), 2);
    }

    ll mn = min({ans1, ans2, ans3});
    cout << mn << endl;
    return (0);
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
ll n,ans,x=1e9;
int main(){
	cin >> n;
	for(ll i=1;i<n;){
		if(x<=1)break;
		x=(n-i)/i;
		if((n-i)/i!=0 and n/((n-i)/i)==n%((n-i)/i))ans+=(n-i)/i,i++;
		else if(x>1)i=max(i+1,n/(x-1)-1);
	}
	cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<sstream>
 
using namespace std;
 
string s;
string han;
 
string hantei(string* a) {
 
	if (*a == "AAA") {
      
		han = "No";
      
	}
	else {
		*a == "BBB" ? han = "No" : han = "Yes";
	}
 
	return han;
}
 
 
int main() {
 
	cin >> s;
 
	cout << hantei(&s) << endl;
 
	return 0;
 
}

Measured memory_bytes: 256
//QWsin
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,x,y) for(int i=x;i<=y;++i)
#define out(i,u) for(int i=first[u];i!=-1;i=next[i])
#define repvc(i,vc) for(int i=0,Sz=vc.size();i<Sz;++i)

using namespace std;

const int INF=1<<30;

int main()
{
	int a,b;cin>>a>>b;
	if(!(a&1) || !(b&1)) puts("No");
	else puts("Yes");
	return 0;
}


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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 11451419194545;

int main(){

    ll N; string S;
    cin >> N >> S;

    ll ans = 0;

    for(ll i = 0; i <= 999; i++){
        ostringstream ss;
        ss << setw(3) << setfill('0') << i << "\n";
        string s(ss.str());

        ll cn = 0;
        for(ll i = 0; i < N; i++){
            if(s[cn] == S[i]){
                cn++;
            }
            if(cn > 2){
                ans++;
                break;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS // #pragma warning(disable:4996)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <functional>
#include <sstream>
#include <cmath>
#include <set>
#include <map>
#include <stack>
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 pb push_back
#define mp(a,b) make_pair(a,b)
#define all(a) a.begin(),a.end()
#define len(x) ((int)(x).size())
#define tmax(a,b,c) max((a),max((b),(c)))
#define tmin(a,b,c) min((a),min((b),(c)))
#define debug(x) cerr << #x << " is " << x << endl;
#define debug2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl;
#define debugg(g,h,w) rep(i,0,h) { rep(j,0,w) cout << g[i][j] << " "; cout << endl;}
#define debugv(v) for(auto&& x : v){cout << x << " ";} cout << endl;

typedef pair<int, int> Pii;
typedef map<int, int> Mii;
typedef vector<int> Vi;
typedef vector<vector<int> > VVi;
typedef long long ll;
const int inf = 2e9;
const ll ll_inf = 1e17;
const int mod = 1e9 + 7;
const long double eps = 1e-10;
typedef pair<ll, ll> Pll;

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

int main()
{
	int t, n;
	Vi vans;
	while (cin >> t >> n) {
		if (!t && !n) break;
		memset(g, 0, sizeof(g));
		int a, b;
		rep(i, 0, n) {
			cin >> a >> b;
			a += 100, b += 100;
			g[b][a] = 3;
		}
		cin >> a >> b;
		a += 100, b += 100;
		g[b][a]++;
		int ans = 1;
		set<Pii> s;

		rep(k, 0, t) {
			s.clear();
			rep(x, 1, 199) rep(y, 1, 199) {
				if (g[y][x] == 1) {
					g[y][x]++;
					rep(l, 0, 6) {
						int nx = x + dx[l];
						int ny = y + dy[l];
						if (g[ny][nx] == 0) {
							s.insert(Pii(ny,nx));
						}
					}
				}
			}
			ans += (int)s.size();
			for (auto p: s) g[p.first][p.second]++;
		}
		//cout << ans << endl;
		vans.pb(ans);
	}
	for (auto a: vans) cout << a << endl;
	return 0;
}

Measured memory_bytes: 3304
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const ll MAX = 1000000000000000;
static const int NIL = -1;
using namespace std;

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")


int main() {
    ll n; cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    vector<ll> g(n,0);
    bool buy = false;
    ll price;

    ll Min = 10000000;

    ll v = 1000;
    ll num = 0;


    if(a[1] > a[0]) {
        buy = true;
        price = a[0];
        num  = v/price;
        v -= price*num;
    }else{
        Min = a[1];
    }


    for(int i = 1; i < n; i ++){
        if(buy && a[i] < a[i-1]){
            //sell on previous day
            //cout << "sell when : "<< a[i-1] << endl;
            v += a[i-1]*num;
            buy = false;
            Min = a[i];
        }else if(!buy && a[i] > a[i-1]){
            //buy on previous day
            //cout << "buy when :" << a[i-1] << endl;
            buy = true;
            Min = min(Min,a[i-1]);
            price = Min;
            num  = v/price;
            v -= price*num;
            Min = 100000;
        }else if(!buy && a[i] < a[i-1]){
            //memorize the lowest date to buy
            Min = min(Min,a[i]);
        }
    }

    if(buy) v += max(price*num,a[n-1]*num);

    if(v < 1000) cout << 1000;
    else cout << v;



    return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int ans[200005];int n;
int a[200005];int cnt;
vector<int>red,bl;
void dfs(int node,vector<int>adj[],int par,int val)
{
  a[node]=val;
  if(val==0)
    red.push_back(node);
  else
    bl.push_back(node);
  for(int j:adj[node])
  {
    if(j!=par)
      dfs(j,adj,node,val^1);
  }
}
int main()
{
//int n;
  cin>>n;
  vector<int>adj[n+1];
  int u,v;
  for(int i=0;i<n-1;i++)
  {
    cin>>u>>v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  dfs(1,adj,-1,0);
  if(red.size()>bl.size())
  {
    red.clear();
    bl.clear();
    dfs(1,adj,-1,1);
  }
  int p=n/3;
  int x=1,y=2,z=3;
  if(red.size()<=p)
  {
    for(int j:red)
      ans[j]=z,z+=3;
    for(int j:bl)
    {
      if(x<=n)
        ans[j]=x,x+=3;
      else if(y<=n)
        ans[j]=y,y+=3;
      else
        ans[j]=z,z+=3;
    }
  }
  else
  {
    for(int j:red)
    {
      if(x<=n)
        ans[j]=x,x+=3;
      else
        ans[j]=z,z+=3;
    }
    for(int j:bl)
    {
      if(y<=n)
        ans[j]=y,y+=3;
      else if(z<=n)
        ans[j]=z,z+=3;
      else
        ans[j]=x,x+=3;
    }
  }
  for(int i=1;i<=n;i++)
    cout<<ans[i]<<" ";
  cout<<"\n";
  return 0;
}


Measured memory_bytes: 21108
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll MOD=1e9+7;
ll INF=1e17;
int main(){
  ll i,j,k,n;
  cin >> n >> k;
  vector<ll> d(n+1),dp(n+1,INF);
  for(i=0;i<n;i++){
    cin >> d[i];
  }
  dp[0]=0;
  for(i=1;i<n;i++){
    for(j=max(0LL,i-k);j<i;j++){
      dp[i]=min(dp[i],dp[j]+abs(d[i]-d[j]));
    }
  }
  cout << dp[n-1] << endl;
  return 0;
}

Measured memory_bytes: 1792
/**
 * Created by hiramekun at 20:10 on 2019-11-16.
 */
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}

template<class T>
istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template<class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

void solve() {
    ll n;
    cin >> n;
    vector<P> xy(n);
    rep(i, n) {
        cin >> xy[i].F >> xy[i].S;
    }
    sort(all(xy));

    double ans = 0;
    ll div = 0;
    do {
        double tmp = 0;
        P pre = {0, 0};
        rep(i, n) {
            double x = (xy[i].F - pre.F);
            double y = (xy[i].S - pre.S);
            if (i != 0) tmp += sqrt(x * x + y * y);
            pre = xy[i];
        }
        ans += tmp;
        div++;
    } while (next_permutation(all(xy)));
    cout << fixed << setprecision(10) << ans / div << endl;
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 256
def arr(row, column, value): return [[value for _ in range(column)] for _ in range(row)]

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

sum_range = arr(n + 1, n + 1, 0)
#sum_range[0][0] - sum_range[n][n]まで
#初期値0
#行列値は1からnを取るが、累積和を加算する過程で行列を1引いたものを参照するので、[0][0]がエラーにならないと便利？

for _ in range(m):
    L, R = map(int, input().split())
    sum_range[L][R] += 1#(L, R)間を運行す列車の数を代入
    
for L in range(1, n + 1):
    for R in range(1, n + 1):
        #累積和を取る（53:44あたり）
        #https://www.youtube.com/watch?v=OdJH-io-sVw
        sum_range[L][R] += sum_range[L - 1][R]
        sum_range[L][R] += sum_range[L][R - 1]
        sum_range[L][R] -= sum_range[L - 1][R - 1]

#print(sum_range)
for _ in range(q):
    p, q = map(int, input().split())
    ans = sum_range[q][q] - sum_range[p - 1][q] - sum_range[q][p - 1] + sum_range[p - 1][p - 1]
    print(ans)

Measured memory_bytes: 15140
while 1:
    s = input()
    if s=='.':
        break
    s=list(s.split('"'))
    t=list(input().split('"'))
    if s==t:
        print("IDENTICAL")
    elif len(s)!=len(t):
        print("DIFFERENT")
        continue
    else:
        flag = 0
        for i in range(0,len(s),2):
            if s[i] != t[i]:
                print("DIFFERENT")
                flag = 1
                break
        if flag == 1:
            continue
        for i in range(1,len(s),2):
            if s[i] != t[i]:
                flag+=1
                if flag == 2:
                    print("DIFFERENT")
                    break
        if flag == 1:
            print("CLOSE")
        



Measured memory_bytes: 5580
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include<complex>
#include <cassert>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repd(i, n) for (int i = n; i > 0; i--)
#define mod 1000000007
#define MOD 998244353
#define inf 1e20
typedef long long int ll;
typedef pair<ll, ll> pr;
typedef complex<double> com;


int main(){
	string s,ans="";
	cin >> s;
	rep(i, s.size()){
		if (s[i] == 'B'&&ans.size()!=0) {
			ans.pop_back();
		}
		else {
			if (s[i] == '1') {
				ans += '1';
			}
			if(s[i]=='0') {
				ans += '0';
			}
		}
	}
	cout << ans <<endl;
	return 0;
}
//Ctrl+Aを使わない

Measured memory_bytes: 256
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include<cassert>
    #include<cmath>
    #include<cstdint>
     
    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
    #define ALL(a)  (a).begin(),(a).end()
     
    using namespace std;
    using ll = long long;
    using Graph = vector<vector<int>>;
    using P = pair<ll, ll>;
     
//const ll MOD = INF + 7;
//Combination MOD
const int MOD = 1e9 + 7;

//bit全探索
vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    S.push_back(1e9);
    return S;
}

int main(){
   int n;
   cin >> n;
   ll res = 0;
   vector<ll> a(n);
   rep(i, n)cin >> a[i];
   sort(ALL(a), greater<ll>());
   int cnt = 1;
   rep(i, n - 1){
      if(i == 0)res += a[i];
      else {
         int now = (i + 1) / 2;
         res += a[now];
        //cout << a[now] << endl;
      }
   }
   cout << res << endl;
}


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

int main(){
  int N,Q;
  cin >> N;
  long long sum=0;
  vector<long long> num(1000000,0);
  for(int i=0;i<N;i++){
    int A;
    cin >> A;
    sum+=A;
    num.at(A)++;
  }
  cin >> Q;
  for(int i=0;i<Q;i++){
    int B,C;
    cin >> B >> C;
    sum+=(C-B)*num.at(B);
    num.at(C)+=num.at(B);
    num.at(B)=0;
    cout << sum << endl;
  }
}

Measured memory_bytes: 11188
#include<string.h>
#include<cstdio>
#include<string>
#include<iostream>

using namespace std;

int main() {
	string s;
	int ans = 0;
	while (1) {
		cin >> s;
		ans = 0;
		if (s[0] == '0') {
			break;
		}
		for (int i = 0; i<s.size();i++) {
			ans += s[i]-'0';
		}
		cout << ans << endl;
	}
	return 0;
}


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

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

    multimap<int, int> data;
    for (int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        data.insert(make_pair(a, b));
    }

    bool ret = false;
    for (auto it = data.equal_range(1).first; it != data.equal_range(1).second; it++){
        for (auto it2 = data.equal_range(it->second).first; it2 != data.equal_range(it->second).second; it2++){
            if (it2->second == n){
                ret = true;
                break;
            }
        }
    }

    cout << (ret ? "POSSIBLE" : "IMPOSSIBLE") << endl;
}

Measured memory_bytes: 9600
import sys
input = sys.stdin.readline

N = int(input())
LIMIT = min(N,4195)

V = [0] * N
W = [0] * N
for i in range(N):
    nV, nW = map(int, input().split())
    V[i] = nV
    W[i] = nW

pre = [[] for i in range(LIMIT)]

for i in range(LIMIT):
    if i == 0:
        pre[i] = [(0,0), (W[i], V[i])]
        continue

    curr = pre[i]
    prev = pre[(i - 1)//2]
    nV, nW = V[i], W[i]
    
    size = len(prev)

    left = 0
    right = 0
    while left < size or right < size:
        if left == size or prev[left][0] > prev[right][0] + nW or (prev[left][0] == prev[right][0] + nW and prev[left][1] < prev[right][1] + nV):
            if len(curr) == 0 or prev[right][1] + nV > curr[-1][1]:
                curr.append((prev[right][0] + nW, prev[right][1] + nV))
            right += 1
        else:
            if len(curr) == 0 or prev[left][1] > curr[-1][1]:
                curr.append(prev[left])
            left += 1
            
Q = int(input())
out = [0] * Q
for t in range(Q):
    vert, L = map(int, input().split())
    vert -= 1

    stack = []
    while vert >= LIMIT:
        stack.append((V[vert], W[vert]))
        vert = (vert - 1) // 2
        
    prev = pre[vert]
    best = 0
    
    for i in range(1 << len(stack)):
        sV = 0
        sW = 0
        red = i
        for nV, nW in stack:
            if red & 1:
                sV += nV
                sW += nW
            red >>= 1

        limit = L - sW
        if limit < 0:
            continue
        
        lo = -1
        hi = len(prev)
        while hi - lo > 1:
            test = (hi + lo) // 2
            if prev[test][0] <= limit:
                lo = test
            else:
                hi = test
                
        if lo >= 0:
            new = prev[lo][1] + sV
            best = max(best, new)
        
    out[t] = best

print('\n'.join(map(str,out)))


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

int main() {
  int a[5];
  for (int i = 0; i < 5; i++)
  cin >> a[i];
  int k;
  cin >> k;

  if (a[4]-a[0] <= k)
  cout << "Yay!" << endl;
  else
  cout << ":(" << endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1e17;
#define int long long
int dist[310][310];
int dist2[310][310];
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	VE c(n);
	VE d(n + 1);
	rep(i, n) {
		int a; cin >> a; a--;
		c[a]++; d[c[a]]++;
	}
	VE s(n + 1);
	FOR(i, 1, n + 1)s[i] = s[i - 1] + d[i];
	FORR(k, 1, n) {
		int low = 0, high = n + 1;
		while (high - low > 1) {
			int x = (low + high) / 2;
			if (s[x] >= k * x) {
				low = x;
			}
			else high = x;
		}
		cout << low << endl;
	}
	return 0;
}


Measured memory_bytes: 7936
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

func main() {
	var d, s, ans int
	n := readi()
	k := readi()
	snk := make(map[int]int, n)
	for i := 0; i < k; i++ {
		d = readi()
		for j := 0; j < d; j++ {
			fmt.Scan(&s)
			snk[s]++
		}
	}
	for i := 1; i <= n; i++ {
		if snk[i] == 0 {
			ans++
		}
	}
	fmt.Println(ans)
}

// IO---------------------------------------------------

func readi() (n int) {
	fmt.Scan(&n)
	return
}

func readf() (n float64) {
	fmt.Scan(&n)
	return
}

func reads() (n string) {
	fmt.Scan(&n)
	return
}

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readLine() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func readSlice() []string {
	return strings.Split(readLine(), " ")
}

func atoi(a []string) (b []int) {
	b = make([]int, len(a))
	for i := range a {
		b[i], _ = strconv.Atoi(a[i])
	}
	return
}

func atof(a []string) (b []float64) {
	b = make([]float64, len(a))
	for i := range a {
		b[i], _ = strconv.ParseFloat(a[i], 64)
	}
	return
}

func readSlice2(n int) (a []int, b []int) {
	a = make([]int, n)
	b = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i], &b[i])
	}
	return
}

func readFloatSlice2(n int) (a []float64, b []float64) {
	a = make([]float64, n)
	b = make([]float64, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i], &b[i])
	}
	return
}

func yesOrNo(b bool) {
	if b {
		fmt.Println("Yes")
		return
	}
	fmt.Println("No")
}

func yesorNO(b bool) {
	if b {
		fmt.Println("YES")
		return
	}
	fmt.Println("NO")
}

func yesorno(b bool) {
	if b {
		fmt.Println("yes")
		return
	}
	fmt.Println("no")
}

// calc---------------------------------------------------

func abs(a int) int {
	if a > 0 {
		return a
	}
	return -a
}

func ave(a []int) (ave int) {
	for i := 0; i < len(a); i++ {
		ave += a[i]
	}
	ave /= len(a)
	return
}

func eq(a []string, b []string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] != b[i] {
			return false
		}
	}
	return true
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func max(a ...int) int {
	max := a[0]
	for i := 1; i < len(a); i++ {
		if max < a[i] {
			max = a[i]
		}
	}
	return max
}

func min(a ...int) int {
	min := a[0]
	for i := 1; i < len(a); i++ {
		if min > a[i] {
			min = a[i]
		}
	}
	return min
}

func mid(a []int) int {
	sort.Ints(a)
	return a[len(a)/2]
}

func sum(a []int) (ans int) {
	for i := range a {
		ans += a[i]
	}
	return
}

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

#define INF 1000000007
#define LINF 1000000000000000007

using namespace std;

typedef long long Int;
typedef pair<Int, Int> P;

Int gcd(Int x, Int y){
	if(y == 0)
		return x;
	return gcd(y, x % y);
}

Int lcm(Int x, Int y){
	return x * y / gcd(x, y);
}

bool sosuu(int x){
	bool b = 1;
	if(x == 1) b = 0;
	for(int i = 2; i * i <= x; i++){
		if(x % i == 0) {
			b = 0;
			break;
		}
	}
	return b;
}

int n, x[200000], a[200000];

int main(){
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> x[i];
		a[i] = x[i];
	}
	sort(x, x+ n);
	int l = x[n/2-1], r = x[n/2];
	
	for(int i = 0; i < n; i++){
		if(a[i] <= l) cout << r << endl;
		else cout << l << endl;
	}
	
	return 0;
}

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

typedef long long ll;
using namespace std;

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

	while(true){
		int a,b,c; cin >> a >> b >> c;
		if(a == 0) break;
		int n; cin >> n;

		int t[2000][4];
		for (int i = 0;i < n;i++){
			for (int j = 0;j < 4;j++){
				cin >> t[i][j];
				if(j < 3) t[i][j]--;
			}
		}

		bool f = true;
		int s[2000];
		memset(s,0,sizeof(s));
		while(f){
			f = false;
			for (int i = 0;i < n;i++){
				if(t[i][3] == 1){
					for (int j = 0;j < 3;j++){
						if(s[t[i][j]] == 0){
							f = true; s[t[i][j]] = 1;
						}
					}
				}else{
					for (int j = 0;j < 3;j++){
						if(s[t[i][j]] == 0 && s[t[i][(j+1)%3]] == 1 && s[t[i][(j+2)%3]] == 1){
							f = true; s[t[i][j]] = 2;
						}/*else if(s[t[i][j]] == 2){
							if( s[t[i][(j+1)&3]] == 1 && s[t[i][(j+2)%3]] == 1)continue;
							f = true;  s[t[i][(j+1)&3]] = 1;  s[t[i][(j+2)%3]] = 1;
						}*/
					}
				}
			}
		}
		for (int i = 0;i < a+b+c;i++){
			if(s[i] == 0) cout << 2 << endl;
			else if(s[i] == 1) cout << 1 << endl;
			else cout << 0 << endl;

		}
	}

	return 0;

}



Measured memory_bytes: 3112
import java.util.Scanner;

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

            int sum = 0;
            for(int i=a;i<=b;i++) {
                if (c % i == 0) sum++;
            }
            System.out.println(sum);
    }
}



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

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

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

#define INF INT_MAX/3

int main(){
    cin.sync_with_stdio(false);
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(a * n, b) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 
double mpow(double x, int n);
int ch2dec(char hex);
void bit_conv(char *bit, int num);
 
int main(void)
{
	char bit[64];
	char format[16];
	double frac;
	int dec;
	int n;
	int i;
	int max;
	
	scanf("%d", &n);
	while (n--){
		getchar();
		for (i = 0; i < 8; i++){
			bit_conv(bit + (i * 4), ch2dec(getchar()));
		}
		
		if (*bit) printf("-");
		
		dec = 0;
		for (i = 0; i < 24; i++){
			dec = (dec << 1) + bit[1 + i];
		}
		
		frac = max = 0;
		for (i = 0; i < 7; i++){
			if (bit[25 + i]){
				frac += mpow(0.5, i + 1);
				max = i;
			}
		}
		
		sprintf(format, "%s.%d%s\n", "%", max + 1, "lf");
		
		printf(format, frac + dec);
	}
	
	return (0);
}
 
void bit_conv(char *bit, int num)
{
	int i;
	int index;
	
	for (index = 0, i = 3; i >= 0; i--, index++){
		bit[index] = (num >> i) & 1;
	}
	return;
}
 
int ch2dec(char hex){
	if ('0' <= hex && hex <= '9') return (hex - '0');
	return ((hex - 'a') + 10);
}
 
double mpow(double x, int n)
{
	int i;
	double ret;
	
	ret = 1;
	for (i = 0; i < n; i++){
		ret *= x;
	}
	
	return (ret);
}

Measured memory_bytes: 656
def main():
  import sys
  b=sys.stdin.buffer
  input=b.readline
  n=int(input())
  d=[0]*n+[1<<c-97for c in input()[:n]]
  for i in range(n-1,0,-1):d[i]=d[i+i]|d[i-~i]
  r=[]
  input()
  for q,a,b in zip(*[iter(b.read().split())]*3):
    i,s=int(a)+n-1,0
    if q<b'2':
      d[i]=1<<b[0]-97
      while i:
        i//=2
        d[i]=d[i+i]|d[i-~i]
      continue
    j=int(b)+n
    while i<j:
      if i&1:
        s|=d[i]
        i+=1
      if j&1:
        j-=1
        s|=d[j]
      i//=2
      j//=2
    r+=bin(s).count('1'),
  print(' '.join(map(str,r)))
main()

Measured memory_bytes: 44720
n=int(input())
a=list(map(int,input().split()))
count=0
for i in range(n):
    if a[i]<0:
        count+=1
if count%2==0:
    for j in range(n):
        a[j]=abs(a[j])
    print(sum(a))
else:
    for j in range(n):
        a[j]=abs(a[j])
    print(sum(a)-2*min(a))
    


Measured memory_bytes: 20084
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define IOS ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define pf push_front
#define PI acos(-1)
#define EPS 1e-5
#define sz(v) ((int)(v).size())
#define all(v) v.begin(),v.end()
#define forn(i, n) for(ll i=0;i<(ll)n;i++)
#define fi first
#define se second
 

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> a(n, -1);
	forn(i, m) {
		int s, c;
		cin >> s >> c;
		if(a[s-1] != -1 && a[s-1] != c) {
			cout << -1 << endl;
			return 0;
		}
		a[s-1] = c;
	}
	if((a[0] == 0 && n == 1 && a.size() == 1)|| a[0] == -1 && n==1 &&a.size() == 1){
		cout << 0 << endl;
		return 0;
	}

	if(a[0] == 0) {
		cout << -1 << endl;
		return 0;
	}
	vector<int> res(n);
	if(a[0] == -1)
		res[0] = 1;
	else res[0] = a[0];
	for(int i = 1; i < n; i++) {
		if(a[i] == -1)
			res[i] = 0;
		else res[i] = a[i];
	}
	forn(i, n) cout << res[i];
	cout << endl;
		
	return 0;
}



Measured memory_bytes: 3572
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <cmath>
#include <bitset>
#include <string>
#define REP(i,n) for(int i=0;i<n;i++)
using Int = long long;
using namespace std;
int main()
{
    Int N, A, B; cin >> N >> A >> B;
    vector<Int> X(N);
    REP(i, N) cin >> X[i];
    Int cost = 0;
    for (int i = 1; i < N; i++) {
        Int d = X[i] - X[i-1];
        cost += min(d*A, B);
    }
    cout << cost << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <sstream>

using namespace std;


int main()
{
      int a, b;
      cin>> a >> b;
      if(a > b && b != 1)
            cout << "Alice";
      else if(b > a && a != 1)
            cout << "Bob";
      else if(a == 1 && b != 1)
            cout << "Alice";
      else if(b == 1 && a != 1)
            cout << "Bob";
      else
            cout << "Draw";

      return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

typedef long long ll;

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

    ll ans = 0;
    for (ll k = 1; k * k + k < N; k++) {
        if (N % k == 0) {
            ans += N / k - 1;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#define N 400000
#define mod 1000000007
int main(int argc, char *argv[])
{
	long long a[N]={0},n,i,sum=0;
	scanf("%lld",&n);
	for(i=0;i<n;i++){
		scanf("%lld",&a[i]);
		sum+=a[i];
	}
	long long s=0;
	for(i=0;i<=n-2;i++){
		sum-=a[i];
		s+=((sum%mod)*a[i])%mod;
	}
	printf("%lld\n",(s+mod)%mod);
}

Measured memory_bytes: 4852
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
#define REP0(i,n) for(int i=0;i<n;++i)
#define REP1(i,n) for(int i=1;i<=n;++i)
#define ALL(c) (c).begin(),(c).end()
int main(){
	string s;
	cin >> s;
	reverse(ALL(s));
	cout << s << endl;
	return 0;
}

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

#define int long long
#define endl '\n'

signed main() {
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    string s; cin >> s;
    vector<int> c(2019, 0);
    c[0] = 1;
    int sum = 0, base = 1, ans = 0;
    reverse(s.begin(), s.end());
    for (auto i: s) {
        sum += base * (i - '0'); sum %= 2019;
        base *= 10; base %= 2019;
        ans += c[sum];
        c[sum]++;
    }
    cout << ans;
}

Measured memory_bytes: 3696
use proconio::input;
fn main() {
    input! {
        n:usize,
        m:usize,
        h:[usize;n],
    }

    let mut ma = vec![0; n];

    for _ in 0..m {
        input! {
            a:usize,
            b:usize,
        }
        ma[a - 1] = ma[a - 1].max(h[b - 1]);
        ma[b - 1] = ma[b - 1].max(h[a - 1]);
    }
    let mut ans = 0;
    for i in 0..n {
        if h[i] > ma[i] {
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 5800
#include<bits/stdc++.h>
using namespace std;
int n;
bitset<2000*2000+9> b;
int main(){
    scanf("%d",&n);
    b[0]=1;int sum=0;
    for (int i=1;i<=n;i++){
        int a;
        scanf("%d",&a);
        b|=b<<a;
        sum+=a;
    }
    for (int i=(sum+1)/2;;i++)if (b[i]){printf("%d",i);break;}
    return 0;
}

Measured memory_bytes: 1664
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        for (;;) {
            char[] n = sc.next().toCharArray(), m = sc.next().toCharArray();
            if (n.length == 1 && m.length == 1 && (n[0] | m[0]) == '0') {
                break;
            }
            int hit = 0;
            int blow = 0;
            for (int i = 0; i < 4; i++) {
                for (int j = 0; j < 4; j++) {
                    if (i == j) {
                        if (n[i] == m[j]) {
                            hit++;
                        }
                    } else {
                        if (n[i] == m[j]) {
                            blow++;
                        }
                    }
                }
            }
            System.out.println(hit + " " + blow);
        }
    }
}


Measured memory_bytes: 46672
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;

long long factorial(int n) {
	long long ans = 1;
	for (int i = 1; i <= n;i++) {
		ans = ans * i % 1000000007;
	}
	return ans;
}

int main() {
	int N, M;
	long long ans;
	cin >> N >> M;
	
	if (abs(N - M) >= 2) ans = 0;
	else if (N != M) ans = factorial(N)*factorial(M);
	else if (N == M) {
		ans = factorial(N);
		ans = 2 * ans * ans;
	}

	ans = ans % 1000000007;

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

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

int main(){
  int N,X,Y;
  cin>>N>>X>>Y;
  map<int,int>mp;
  for(int i=1;i<N+1;i++){
    for(int j=i+1;j<N+1;j++){
      mp[min(j-i,abs(X-i)+1+abs(Y-j))]++;
    }
  }
  for(int i=1;i<N;i++){
    cout<<mp[i]<<endl;
  }
  return 0;
}



Measured memory_bytes: 384
from math import floor

x, k, d = map(int, input().split())

x = abs(x)

decim = x/d

if (decim > k):
    print(abs(x - k*d))
    exit(0)
else:
    if decim <= 1:
        if (k % 2 == 1):
            print(abs(x - d))
        else:
            print(abs(x))
    else:
        if k % 2 == 0:
            lower = int(decim) if ((int(decim) % 2) == 0) else int(decim) - 1
        else:
            lower = 2*floor(decim/2)-1
        upper = lower + 2
        print(min(abs(x - lower*d), abs(x - upper*d)))


Measured memory_bytes: 9216
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
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(a > b){ a = b; return 1; } return 0; }
int main()
{
  int n; cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];

  int sum = 0;
  rep(i,n) sum += a[i];
  int mini = 1e+9;
  int res;
  rep(i,n) {
    int d = abs(sum - a[i]*n);
    if(chmin(mini, d)) res = i;
  }
  cout << res << "\n";

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    map<string,int> m;
    int n;
    cin>>n;
    string x;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        m[x]++;
    }
    cout<<"AC"<<" x "<<m["AC"]<<endl;
    cout<<"WA"<<" x "<<m["WA"]<<endl;
    cout<<"TLE"<<" x "<<m["TLE"]<<endl;
    cout<<"RE"<<" x "<<m["RE"]<<endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<vector<ll> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
//const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}




// combination mod prime
// mintが必要
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main(){
    ll n,k;
    cin >> n >> k;
    combination c(n);
    for(int i=1;i<=k;i++){
        mint a = c(n-k+1,i);
        mint b = c(k-1,i-1);
        mint ans = a*b;
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3652
#include <stdio.h>
#define int long long

signed main(){
	int X, i, N;
	scanf("%lld", &X);
	for(i = 0, N = 2; i < X; i++){
		N = N + (N + 1) + 1;
	}
	printf("%lld\n", N);
	return 0;
}

Measured memory_bytes: 128
import sys

sys.setrecursionlimit(10 ** 6)


def rolling_hash(s, w, MOD):
    ret = []
    tmp = 0
    p = pow(26, w, MOD)
    ords = [ord(c) - 97 for c in s]
    for i, o in enumerate(ords):
        tmp = tmp * 26 + o
        if i >= w:
            tmp = (tmp - ords[i - w] * p)
        tmp %= MOD
        ret.append(tmp)
    return ret


def solve(s, t):
    MOD = 10 ** 9 + 7
    ls, lt = len(s), len(t)
    k = (lt - 1) // ls + 1
    s *= k * 2
    ls *= k
    rs, rt = rolling_hash(s, lt, MOD), rolling_hash(t, lt, MOD)
    rs = rs[ls:]
    ht = rt[-1]

    checked = [-1] * ls

    def series(i, st):
        if st <= i < st + lt:
            return float('-inf')
        if checked[i] == -1:
            checked[i] = series((i + lt) % ls, st) + 1 if rs[i] == ht else 0
        return checked[i]

    for i, hs in enumerate(rs):
        if hs != ht:
            continue
        ret = series((i + lt) % ls, i)
        if ret == float('-inf'):
            return -1
        checked[i] = ret + 1

    return max(0, max(checked))


s = input()
t = input()
print(solve(s, t))


Measured memory_bytes: 535948
#include<bits/stdc++.h>
using namespace std;
char a[102][102], usedh[102], usedw[102];
int main(){
    int h, w;
    scanf("%d %d", &h, &w);
    for(int i = 1; i <= h; i++){
        scanf("%s", a[i] + 1);
    }
    for(int i = 1; i <= h; i++){
        bool flag = 0;
        for(int j = 1; j <= w; j++){
            if(a[i][j] == '#') flag = 1;
        }
        if(flag == 0){
            usedh[i] = 1;
        }
    }
    for(int j = 1; j <= w; j++){
        bool flag = 0;
        for(int i = 1; i <= h; i++){
            if(a[i][j] == '#') flag = 1;
        }
        if(flag == 0){
            usedw[j] = 1;
        }
    }
    for(int i = 1; i <= h; i++){
        if(usedh[i]) continue;
        for(int j = 1; j <= w; j++){
            if(usedw[j]) continue;
            printf("%c", a[i][j]);
        }
        printf("\n");
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <cmath>
#include <set>
#include <bitset>
#include <limits>

using namespace std;

#define ll long long

int main(void){
    string s;
    cin >> s;

    int flag = 1;
    for(int i = 0;i < 3;++i){
        if(s[i] == '7'){
            flag = 0;
        }
    }

    if(flag == 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int main () {
  double n, m, d;
  cin >> n >> m >> d;
  double ans = (n - d) * (m - 1) / (n * n);
  if(d != 0)ans *= 2;
  cout << setprecision(100) << ans << endl;
  return 0;
}

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

int main() {
  map <string,long long> M;
  long long N,p=1,ans=0;
  cin>>N;
  vector<long long> a(N);
  vector<long long> A;
  for(int i=0;i<N;i++){
    cin>>a.at(i);
  }
  A=a;
  sort(a.begin(),a.end());
  for(int i=0;i<N;i++){
    if(i==N-1||a.at(i)!=a.at(i+1)){
      M[to_string(a.at(i))]=p;
      ans+=p*(p-1)/2;
      p=1;
    }
    else{
      p++;
    }
  }
  for(int i=0;i<N;i++){
    
  cout<<ans-M.at(to_string(A.at(i)))+1<<endl;
  }
  
}


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

struct data{
	int num;
	char c;
};

bool compare(const data& left, const data& right){
	if(left.num == right.num){
		return left.c < right.c;
	}
	else return left.num > right.num;
}

int main(){
	int n;
	char c[101];
	vector<data> vec;
	data d;
	while(1){
		cin >> n;
		if(n == 0)break;
		for(int i = 0;i < n;i++){
			cin >> c[i];
		}
		vec.clear();
		bool tie = true;
		for(int i = 0;i < n;i++){
			bool flag = true;
			for(int j = 0;j < vec.size();j++){
				if(c[i] == vec[j].c){
					vec[j].num++;
					flag = false;
					break;
				}
			}
			if(flag){
				d.c = c[i];
				d.num = 1;
				vec.push_back(d);
			}
			sort(vec.begin(),vec.end(),compare);
			if(vec.size() == 1){
				if(vec[0].num > n/2){
					tie = false;
					cout << vec[0].c << " " << i+1 << endl;
					break;
				}
			}
			else if(vec.size() > 1){
				if(vec[0].num > vec[1].num + (n - (i+1))){
					tie = false;
					cout << vec[0].c << " " << i+1 << endl;
					break;
				}
			}
		}
		if(tie)cout << "TIE" <<endl;
	}
	return 0;
}

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

using namespace std;

int main() {
  int n;
  cin >> n;
  int a = n/1000; n%= 1000;
  int b = n/100; n%= 100;
  int c = n/10; n%= 10;
  int d= n;
  if(a+b+c+d==7){cout << a << "+" << b << "+" << c << "+" << d << "=7" << endl; return 0;}
  if(a-b+c+d==7){cout << a << "-" << b << "+" << c << "+" << d << "=7" << endl; return 0;}
  if(a+b-c+d==7){cout << a << "+" << b << "-" << c << "+" << d << "=7" << endl; return 0;}
  if(a-b-c+d==7){cout << a << "-" << b << "-" << c << "+" << d << "=7" << endl; return 0;}
  if(a+b+c-d==7){cout << a << "+" << b << "+" << c << "-" << d << "=7" << endl; return 0;}
  if(a-b+c-d==7){cout << a << "-" << b << "+" << c << "-" << d << "=7" << endl; return 0;}
  if(a+b-c-d==7){cout << a << "+" << b << "-" << c << "-" << d << "=7" << endl; return 0;}
  if(a-b-c-d==7){cout << a << "-" << b << "-" << c << "-" << d << "=7" << endl; return 0;}
}


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

int main() {  
  int n;
  cin >> n;
  vector<int> vec(n);
  
  for (int i = 0; i<n; i++) {
    cin >> vec.at(i);
  }
  
  sort(vec.begin(), vec.end());
  double sum = vec.at(0);
  
  for (int i = 1; i<n; i++) {
    sum = (sum+vec.at(i))/2;
  }
  
  cout << sum << endl;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
a = list(map(int, input().split()))
MOD = 10**9+7
a.sort()

def prepare(n, MOD):
    """
    nCr mod MOD
    :param n:
    :param MOD:
    :return:
    """
    facts = [1]*(n+1)
    for i in range(1, n+1):
        facts[i] = facts[i-1]*i%MOD
    invs = [1]*(n+1)
    _invs = [1]*(n+1)
    invs[n] = pow(facts[n], MOD-2, MOD)
    for i in range(0, n)[::-1]:
        invs[i] = invs[i+1] * (i+1) % MOD
    return facts, invs
facts, invs = prepare(n, MOD)
max_sum = 0
min_sum = 0
for i, v in enumerate(a):
    under = i
    upper = n-1-i
    if i >= k-1:
        max_sum += v*facts[i]*invs[k-1]*invs[i-k+1]
        max_sum %= MOD
    if n-1-i >= k-1:
        min_sum += v*facts[n-1-i]*invs[k-1]*invs[n-i-k]
        min_sum %= MOD

print((max_sum-min_sum)%MOD)

Measured memory_bytes: 21696
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

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

#define t_max 100000+5

int v[30][t_max]={};

int main(void) {
  int i,j;
  int n,c;
  cin>>n>>c;
  rep(i,n){
    int a,b,c;
    cin>>a>>b>>c;
    c--;
    v[c][a]++;
    v[c][b]--;
  }
  rep(i,c)rep(j,t_max-1)v[i][j+1]+=v[i][j];
  rep(i,c)rep(j,t_max-1)
    if(v[i][j]==0 && v[i][j+1]==1)v[i][j]++;
  int ans=0;
  rep(j,t_max){
    int cnt=0;
    rep(i,c)if(v[i][j])cnt++;
    ans=max(ans,cnt);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 11904
// parameter "input" gets all data
function Main(input) {
	// the first line is assigned to input[0], the second line is assigned to input[1] similarly.
	var ab = input.split(' ');
	a = parseInt(ab[0]);
	b = parseInt(ab[1]);

	console.log((a*b)%2==0?'No':'Yes');
}
// Don't edit this line!
//Main(require("fs").readFileSync(__dirname+'/in.txt', "utf8"));
Main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 21956
A,B,K = map(int,input().split())
for i in range(K):
    if A%2 == 1:
        A-=1
    B = A//2+B
    A = A//2
    A,B = B,A
if K%2==0 :
    print(A,B)
else :
    print(B,A)


Measured memory_bytes: 2940
#include <bits/stdc++.h> 
using namespace std;
///////////////////////////////////////////
const long long int INF = 100000000000;
const long long int Mod = 1000000007;
using ll = long long int; //long long int は64bit
using ci = const int; using vi = vector<int>; using Vi = vector<long long int>; using pii = pair<int,int>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(int i=0;i<N;i++)
#define np nullptr
template<class T>bool chmax(T &former, const T &b) { if (former<=b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define fill(x,num) memset(x,num,sizeof(x));
typedef vector<vector<ll> > matrix;
//       cin.tie(0);ios::sync_with_stdio(false);
void cinit(){cin.tie(0);ios::sync_with_stdio(false);}
//////////////////////////^^ *Emile ^^^//////////////////////////////////////////////////////

ll a,b,q;
Vi s,t,x;


int main(){
	cin>>a>>b>>q;ll aa;
	rep(i,a){
		cin>>aa;
		s.pb(aa);
	}
	rep(i,b){
		cin>>aa;
		t.pb(aa);
	}
	rep(i,q){
		cin>>aa;
		x.pb(aa);
	}//input
	
	decltype(x)::iterator si,ti;
	ll tmp = 0,ans = 0;
	ll sl,sr,tl,tr;
	rep(i,q){
		si = upper_bound(all(s),x[i]);sr = si[0];
		ti = upper_bound(all(t),x[i]);tr = ti[0];
		if(si[0]==0)sr = INF;
		if(ti[0]==0)tr = INF;
		if(si[0]==s[0]){sl = -1*INF;}
		else{sl = si[-1];}
		if(ti[0]==t[0]){tl = -1*INF;}
		else{tl = ti[-1];}
		ans = x[i]-sl + tr - sl;
		chmin(ans,x[i]+sr-2*tl);
		chmin(ans,2*tr-x[i]-sl);
		chmin(ans,2*sr-x[i]-tl);
		chmin(ans,x[i]-min(sl,tl));
		chmin(ans,max(tr,sr)-x[i]);
		cout<<ans<<endl;
	}

	return 0;
}

Measured memory_bytes: 3828
#!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

K = int(input())
amari = []
s = 0
before = 0
for i in range(10 ** 6 + 1):
    if i == 0:
        s += 7 % K
        before = 7 % K
    else:
        before = before * 10 % K
        s += before
    s = s % K
    if s == 0:
        break
else:
    print("-1")
    sys.exit()

print(i + 1)






"""
7
77
777
7777

7
70 == 7 * 10 =
700 ==  



1
11
111
1111

k = 3
1 == 1
10 == 1
100 == 1

k = 4
1 == 1
10 == 2
100 == 0
100 == 10 * 10 == 2 * 10
"""


Measured memory_bytes: 10884