akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define ARC(i, a, b) for(ull i = (a); i < (b); ++i)
#define RC(i, n) ARC(i, 0, n)
#define ARCH(i, a, b) for(ull i = (a) - 1; i >= (b); --i)
#define RCH(i, n) ARCH(i, n, 0)

template<class T> T ant(const T &a, const T &b){ return a > b ? a : b; }
template<class T> T ont(const T &a, const T &b){ return a < b ? a : b; }
template<class T> T &anth(T &a, const T &b){ return a = ant(a, b); }
template<class T> T &onth(T &a, const T &b){ return a = ont(a, b); }

using ull = unsigned long long;

ull pow(ull a, ull n){
	ull rtn = 1;
	while(n){
		if(n & 1) rtn *= a;
		a *= a;
		n >>= 1;
	}
	return rtn;
}

int main(){
	ull n;
	std::cin >> n;

	ull num = 1, sum = 1, rm = 0;
	ull tmp = n;

	for(ull i = 2; i * i <= n; ++i){
		if(tmp % i == 0){
			ull count = 0;
			while(tmp % i == 0){
				tmp /= i;
				++count;
			}
			num *= count + 1;
			sum *= (pow(i, count + 1) - 1) / (i - 1);
		}
	}
	if(tmp > 1){
		num *= 2;
		sum *= tmp + 1;
	}

	for(ull i = 1; i * (i - 1) <= n; ++i) if(n % i == 0) rm += i - 1;

	// std::cout << sum << ' ' << num << ' ' << rm << std::endl;

	std::cout << sum - num - rm << std::endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pi 3.14159265359
#define int long long
#define pii pair<int,int>
const int mod=1e9+7;

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


int lis(vector<int> const& a) {
    int n = a.size();
    const int INF = 1e9;
    vector<int> d(n+1, INF);
    d[0] = -INF;

    for (int i = 0; i < n; i++) {
        int j = upper_bound(d.begin(), d.end(), a[i]) - d.begin();
        if (d[j-1] <= a[i] && a[i] <= d[j])
            d[j] = a[i];
    }

    int ans = 0;
    for (int i = 0; i <= n; i++) {
        if (d[i] < INF)
            ans = i;
    }
    return ans;
}

int32_t  main()
{ 
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
 
  #ifndef ONLINE_JUDGE
  freopen("input.txt","rt",stdin);
  freopen("output.txt","wt",stdout);
  #endif

  int n;
  cin>>n;
  vector<int>v;
  string s;
  cin>>s;
  int cnt=0;
  for(auto i : s)
  {
    if(i=='R')cnt++;
  }
  
  int ans=0;
  for(int i=0;i<cnt;i++)
  {
    if(s[i]!='R')ans++;
  }

  cout<<ans<<"\n";

}

Measured memory_bytes: 3720
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<queue>
#include <climits>
#include <map>
#include <set>
const int mod = 1e9 + 7;
const int INF = 1 << 20;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
 
int main()
{
    while(true){
        int m,f,r; cin >> m >> f >> r;
        if(m==-1&&f==-1&&r==-1) break;
        int sum = m+f;
        if(m==-1 || f==-1){
            cout << 'F' << endl;
        }else if(sum >= 80){
            cout << 'A' << endl;
        }else if(sum >= 65){
            cout << 'B' << endl;
        }else if(sum >= 50 || r >= 50){
            cout << 'C' << endl;
        }else if(sum >= 30){
            cout << 'D' << endl;
        }else{
            cout << 'F' << endl;
        }
    }
}


Measured memory_bytes: 3096
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <list>
#include <cstdlib>
#include <memory>
#include <cstring>
#include <sstream>
#include <list>
#include <deque>
#include <bitset>
#include <vector>

using namespace std;

#define INF 0x3f3f3f3f
#define PI 3.141592653579
#define FRER() freopen("input.txt" , "r" , stdin);
#define FREW()  freopen("output.txt" , "w" , stdout);
#define  QIO std::ios::sync_with_stdio(false)
#define mem(a, b) memset(a , b , sizeof(a))
const double eps = 1e-8;
typedef long long ll;
const int maxn = 30;
int cnt, n;
ll ans;
int x[maxn], y[maxn];
bool vis[maxn];
struct Vec
{
    int x, y;
} vec[maxn * maxn];
int res, cntl;

bool isping(Vec a, Vec b)
{
    if (a.x * b.y - b.x * a.y == 0) return true;
    return false;
}

void dfs(int cur)
{
//    while(cur < n && vis[cur]) cur++;
    if (cur == n)
    {
        int cntp = 0;
        for (int i = 0; i < cntl; i++)
        {
            for (int j = i + 1; j < cntl; j++)
            {
//                cout << /"===" << endl;
                if (isping(vec[i], vec[j]))
                {
//                    cout << "yes" << endl;
                    cntp++;
                }
            }
        }
        res = max(res, cntp);
        return;
    }
    if (vis[cur]) dfs(cur + 1);
    else
    {
        vis[cur] = true;
        for (int i = cur + 1; i < n; i++)
        {
            if (vis[i] || i == cur) continue;
            vis[i] = true;
            vec[cntl].x = x[i] - x[cur];
            vec[cntl++].y = y[i] - y[cur];
            dfs(cur + 1);
            vis[i] = false;
            cntl--;
        }
        vis[cur] = false;
    }

}


int main()
{
//    FRER();
    mem(vis, false);
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        scanf("%d%d", &x[i], &y[i]);
    res = 0;
    cntl = 0;
    dfs(0);
    printf("%d\n", res);
    return 0;
}


Measured memory_bytes: 3220
#include <iostream>

using namespace std;

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

    double sum = 0.0;
    double k;

    for (int  i = 0; i < N; i++)
    {
        cin >> k;
        sum += 1.0 / k;
    }
    
    cout << 1.0 / sum << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
const ll inf  = 1e6+5;
vector<int> freq (5);
int main() {
  ll a,b,c; cin >> a >> b >> c;
  ll total = b * (a / (b+c));
  ll left = a%(b+c);
  total += min(left, b);
  cout << total;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <set>
#include <unordered_map>
#include <list>
#include <unordered_set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#define INFI 987654321
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
struct Node{
    int idx, x, y;
    Node(){};
    Node(int a, int b, int c)
    {
        idx = a;
        x= b;
        y = c;
    }
};
Node points[100001];
vector<pi> G[100001];
priority_queue<pi, vector<pi>, greater<pi>> pq;
bool visit[100001];
int N;
int main() {
    ios_base::sync_with_stdio(false);
    cin >> N;
    for(int i = 1; i <= N; ++i) {
        cin >> points[i].x >> points[i].y;
        points[i].idx = i;
    }
    sort(points + 1, points + N + 1, [](Node a, Node b) {
        return a.x < b.x;
    });
    for(int i = 2; i <= N; ++i)
    {
        int dist = points[i].x - points[i - 1].x;
        G[points[i].idx].push_back(pi(dist, points[i - 1].idx));
        G[points[i - 1].idx].push_back(pi(dist, points[i].idx));
    }
    sort(points + 1, points + N + 1, [](Node a, Node b) {
       return a.y < b.y;
    });
    for(int i = 2; i <= N; ++i)
    {
        int dist = points[i].y - points[i - 1].y;
        G[points[i].idx].push_back(pi(dist, points[i - 1].idx));
        G[points[i - 1].idx].push_back(pi(dist, points[i].idx));
    }
    pq.push(pi(0, 1));
    int ans = 0;
    while(pq.empty() == false)
    {
        pi ege = pq.top();
        pq.pop();
        int here = ege.second;
        int cost = ege.first;
        if(visit[here])
            continue;
        ans += cost;
        visit[here] = 1;
        for(pi there : G[here]) {
            if(!visit[there.second])
                pq.push(there);
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 12028
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(){
    int N;
    double M;
    cin >> N >> M;
    double A[N], sum = 0;
    for(int i=0;i<N;i++){
        cin >> A[i];
        sum += A[i];
    }
        
    int count = 0;
    for(int i=0;i<N;i++){
        if(A[i] >= sum/(4*M))
            count++;
    }
    
    if(count >= M){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    

}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#define REP(i, n) for (ull i = 0; i < (n); i++)
using ll = long long int;
using ull = unsigned long long int;
using namespace std;

int main() {
  ull N;
  cin >> N;
  vector<int> a(N);
  REP(i, N) {
    cin >> a[i];
  }
  ll sum = 0;
  for (auto i : a) {
    sum += i;
  }
  double avg = sum / (double)a.size();
  ull ans_f = 0;
  for (auto i : a) {
    ans_f += pow(i - floor(avg), 2);
  }
  ull ans_c = 0;
  for (auto i : a) {
    ans_c += pow(i - ceil(avg), 2);
  }
  cout << min(ans_f, ans_c) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<queue>
#include<stack>
#include<list>

#define endl "\n"
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;

int main(){
    ll h,w;
    cin>>h>>w;
    ll ans;
    if(w % 2 == 0){
        ans = h * (w/2);
    }
    else{
        ans = h * ((w+1)/2 -1) + (h+1)/2;
    }

    if(h==1 || w==1) ans = 1;
    
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;

int main(){
  string s;cin >> s;
  string t = s;
  sort(t.begin(),t.end());
  t.erase(unique(t.begin(),t.end()),t.end());
  cout << (s.size()==t.size()?"yes":"no") << endl;
  return 0;
}


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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};

typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x)
{
  while( x->left != NIL )
    {
      x = x->left;
    }
  return x;
}

Node treeMaximum(Node x)
{
  while( x->right != NIL )
    {
      x = x->right;
    }
  return x;  
}

Node treeSearch(Node u, int k)
{
  if( u == NIL || k == u->key )
    {
      return u;
    }
  if( k < u->key )
    {
      return treeSearch(u->left,k);
    }
  else return treeSearch(u->right,k);
  
}

Node treeSuccessor(Node x)
{
  Node y;
  if( x->right != NIL )
    {
      return treeMinimum(x->right);
    }

  y = x->parent;
  while( y != NIL && x == y->right )
    {
      x = y;
      y = y->parent;
    }

  return y;
}

void treeDelete(Node z)
{
  Node y; // node to be deleted
  Node x; // child of y

  if( z->left == NIL || z->right == NIL ) y = z;
  else y = treeSuccessor(z);
    
  if( y->left != NIL ) x = y->left;
  else x = y->right;
    
  if( x != NIL ) x->parent = y->parent;

  if( y->parent == NIL ) root = x;
  else if( y == y->parent->left ) y->parent->left = x;
  else y->parent->right = x;

  if( y != z ) z->key = y->key;
 
}

void insert(int k)
{
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while( x != NIL )
    {
      y = x;
      if( z->key < x->key )
	{
	  x = x->left;
	}
      else
	{
	  x = x->right;
	}
    }
      z->parent = y;

      if( y == NIL ) root = z;
      else if( z->key < y->key ) y->left = z;
      else y->right = z;
}

void inorder(Node u)
{ 
  if( u == NIL ) return;

  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
}
 
void preorder(Node u)
{ 
  if( u == NIL ) return;

  printf(" %d", u->key);
  preorder(u->left);
  preorder(u->right);
}


int main()
{
  int n, i, x;
  char com[20];
  
  scanf("%d", &n);
  
  for ( i = 0; i < n; i++ )
    {
      scanf("%s", com);
      if ( com[0] == 'f' )
	{
	  scanf("%d", &x);
	  Node t = treeSearch(root, x);
      
	  if ( t != NIL ) printf("yes\n");
	  else printf("no\n");
	}
      else if ( com[0] == 'i' )
	{
	  scanf("%d", &x);
	  insert(x);
	}
      else if ( com[0] == 'p' )
	{
	  inorder(root);
	  printf("\n");
	  preorder(root);
	  printf("\n");
	}
      else if ( com[0] == 'd' )
	{
	  scanf("%d", &x);
	  treeDelete(treeSearch(root, x));
	}
    }
  
  return 0;
}
 



Measured memory_bytes: 20456
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<pair<ll,ll>,int> P;
typedef pair<int,ll> Q;
#define mp make_pair
#define pb push_back
int n,m;
ll x,h[100005],d[100005];
vector<Q>edge[100005];
priority_queue<P,vector<P>,greater<P> >que;
int main(){
	scanf("%d%d%lld",&n,&m,&x);
	for(int i=1;i<=n;i++){
		scanf("%lld",&h[i]);
	}
	for(int i=0;i<m;i++){
		int u,v; long long l;
		scanf("%d%d%lld",&u,&v,&l);
		edge[u].pb(mp(v,l));
		edge[v].pb(mp(u,l));
	}
	fill(d,d+100005,1e15);
	d[1] = 0;
	que.push(mp(mp(0,x),1));
	while(!que.empty()){
		P p = que.top(); que.pop();
		if(d[p.second] < p.first.first) continue;
		
		if(p.second == n){
			printf("%lld\n",d[n]*2LL + h[n] - x);
			return 0;
		}
		for(int i=0;i<edge[p.second].size();i++){
			ll cur = p.first.second;
			if(cur-edge[p.second][i].second > h[edge[p.second][i].first]){
				ll nw = p.first.first+cur-h[edge[p.second][i].first];
				ll nw2 = h[edge[p.second][i].first];
				if(nw < d[edge[p.second][i].first]){
					d[edge[p.second][i].first] = nw;
					que.push(mp(mp(nw,nw2),edge[p.second][i].first));
				}
			}
			else if(cur-edge[p.second][i].second < 0){
				if(edge[p.second][i].second > h[p.second]) continue;
				ll nw = p.first.first+edge[p.second][i].second;
				ll nw2 = 0;
				if(nw < d[edge[p.second][i].first]){
					d[edge[p.second][i].first] = nw;
					que.push(mp(mp(nw,nw2),edge[p.second][i].first));
				}
			}
			else{
				ll nw = p.first.first+edge[p.second][i].second;
				ll nw2 = cur-edge[p.second][i].second;
				if(nw < d[edge[p.second][i].first]){
					d[edge[p.second][i].first] = nw;
					que.push(mp(mp(nw,nw2),edge[p.second][i].first));
				}
			}
		}
	}cout << -1 << endl;
}

Measured memory_bytes: 23712
// ABC 155-C
// 2020.2.16 bal4u

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

typedef long long ll;

#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)

int in() {   // 非負整数の入力
	int n = 0;
	int c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

ll ins() { // 文字列の入力　スペース以下の文字で入力終了
    ll n = 0;
	int c = gc();
    int w = 10;
	do n = (n << 5) + (c - 'a'+1), --w;
    while ((c = gc()) > ' ');
    return n << 5*w;
}

void outs(ll s) {
    int c, i = 5*9;
    while (c = (s >> i) & 31) pc(c+'a'-1), i -= 5;
    pc('\n');
}

void Usort(ll *a, int n) {
	int i, k;
#define B 8
#define BMSK 255 // (1<<8)-1
	int t1[1 << B], t2[1 << B];

	ll *tmp = malloc(n * sizeof(ll));
	for (k = 0; k < 8; ++k) {  // for 64ビット
		memset(t1, 0, sizeof(t1)), memset(t2, 0, sizeof(t2));
		for (i = 0; i < n; ++i)	t1[(a[i] >> k*B) & BMSK]++;
		for (i = 0; i < BMSK; ++i) t1[i+1] += t1[i];
		i = n; while (i--) tmp[--t1[(a[i] >> k*B) & BMSK]] = a[i];
		k++;
		for (i = 0; i < n; ++i) t2[(tmp[i] >> k*B) & BMSK]++;
		for (i = 0; i < BMSK; ++i) t2[i+1] += t2[i];
		i = n; while (i--) a[--t2[(tmp[i] >> k*B) & BMSK]] = tmp[i];
	}
	free(tmp);
#undef B
}

#define MAX 200005
ll s[MAX]; int n[MAX];

int main()
{
	int i, j, k, N, ma;

    N = in();
	for (i = 0; i < N; ++i) s[i] = ins();
	Usort(s, N);

	j = 0, k = 1, ma = 1;
	for (i = 1; i <= N; ++i) {
		if (s[i] == s[j]) ++k;
		else {
			n[j] = k;
			if (k > ma) ma = k;
			j = i, k = 1;
		}
	}

	for (i = 0; i < N; ++i) {
		if (n[i] == ma) outs(s[i]);
	}
	return 0;
}


Measured memory_bytes: 4196
N, M = map(int, input().split())
A = [0]*N
B = [0]*M

for i in range(N):
	A[i] = input()
for i in range(M):
	B[i] = input()

ans = False
for sy in range(N-M+1):
	for sx in range(N-M+1):
		flag = True
		for iy in range(M):
			if B[iy] != A[sy+iy][sx:sx+M]:
				flag = False
				break
		if flag:
			ans = True
			break

if ans:
	print("Yes")
else:
	print("No")


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

int main() {
    int N;
    int t[110000], x[110000], y[110000];
    cin >> N;
    t[0] = x[0] = y[0] = 0;  // 初期状態
    for (int i = 0; i < N; ++i) cin >> t[i+1] >> x[i+1] >> y[i+1];  // 1-index にしておく

    bool can = true;
    for (int i = 0; i < N; ++i) {
        int dt = t[i+1] - t[i];
        int dist = abs(x[i+1] - x[i]) + abs(y[i+1] - y[i]);
        if (dt < dist) can = false;
        if (dist % 2 != dt % 2) can = false;  // dist と dt の偶奇は一致する必要あり！
    }

    if (can) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int n, k;
int snack[105];

int main()
{
	cin >> n >> k;
	int t;
	for (int i = 1; i <= k; i++)
	{
		cin >> t;
		for (int j = 1; j <= t; j++)
		{
			int q;
			cin >> q;
			snack[q]++;
		}
	}
	int cnt = 0;
	for (int i = 1; i <= n; i++)
		if (snack[i] == 0) cnt++;
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 3636
import sys

K,X=map(int, raw_input().split())

start_pos = X -K +1
end_pos = X +K -1

if start_pos < -1000000:
    start_pos = -1000000

if end_pos > 1000000:
    end_pos = 1000000

for i in range(start_pos, end_pos):
    sys.stdout.write("%d "%i)

print end_pos


Measured memory_bytes: 2568
#include <iostream>
#include <cstdio>
#define N_MAX 102
using namespace std;
int main(){
  int N,T,L,B,in,data[N_MAX];
  bool visited[N_MAX][N_MAX];
  double dp[N_MAX][N_MAX];
  while(1){
    cin>>N>>T>>L>>B;
    if(!N&&!T&&!L&&!B) break;
    for(int i=0;i<=T;i++)
      for(int j=0;j<=N;j++) dp[i][j]=0,data[j]=0;
    for(int i=0;i<L;i++) cin>>in,data[in]=1;
    for(int i=0;i<B;i++) cin>>in,data[in]=2;
    dp[0][0]=1;
    for(int i=0;i<T;i++)
      for(int j=0;j<N;j++){
	for(int k=1;k<=6;k++){
	  int nx=j+k;
	  if(nx>N) nx=N-nx%N;
	  if(data[nx]==0) dp[i+1][nx]+=dp[i][j]/6;
	  else if(i+2<=T&&data[nx]==1) dp[i+2][nx]+=dp[i][j]/6;
	  else if(data[nx]==2) dp[i+1][0]+=dp[i][j]/6;
	}
      }
    double sum=0;
    for(int i=1;i<=T;i++) sum+=dp[i][N];
    printf("%.6f\n",sum);
  }
  return 0;
}

Measured memory_bytes: 1268
/*
 _     _                             
| |__ | |__   __ _  __ _ _   _  __ _ 
| '_ \| '_ \ / _` |/ _` | | | |/ _` |
| |_) | | | | (_| | (_| | |_| | (_| |
|_.__/|_| |_|\__,_|\__, |\__, |\__,_|
                   |___/ |___/       
*/
#include<bits/stdc++.h>

#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<ll int,ll int>
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
using namespace std;

#define N  100005

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
	// cin>>TESTS;
	while(TESTS--)
	{
		ll int n,p;
		string s;
		cin>>n>>p>>s;
		if(p==2||p==5)
		{
			ll int ans=0;
			for(ll int i=0;i<n;i++)
			{
				if((s[i]-'0')%p==0) ans+=i+1;
			}
			cout<<ans<<endl;
		}		
		else
		{
			mii ma;
			ll int val=0;
			ll int tmp=1;
			ma[val]++;
			ll int ans=0;
			for(ll int i=n-1;i>=0;i--)
			{
				val=(val+tmp*(s[i]-'0'))%p;
				tmp=(tmp*10)%p;
				ans+=ma[val];
				ma[val]++;
			}
			cout<<ans<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1044
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MX=100010, inf=2e9;

int n;
vector<pii> G[MX];
int sub[MX];
ll ans;

void dfs(int v, int p){
    sub[v]=1;
    for(pii &e:G[v]){
        int x,c; tie(x,c)=e;
        if(x==p) continue;
        dfs(x,v);
        sub[v]+=sub[x];
        ans+=2LL*min(sub[x], n-sub[x])*c;
    }
}

int findcen(int v=1, int p=-1){
    for(pii &e:G[v]){
        int x=e.first;
        if(x==p) continue;
        if(sub[x]*2>n) return findcen(x,v);
    }
    return v;
}

void solve0(int v){
    int mn=inf;
    for(pii &e:G[v]){
        int x=e.first;
        if(sub[x]*2==n) { ans-=e.second; return; }
        mn=min(mn, e.second);
    }
    ans-=mn;
}

void solve1(int v){
    int mn=inf;
    for(pii &e:G[v]){
        mn=min(mn, e.second);
    }
    ans-=mn;
}

int main(){
    ios::sync_with_stdio(0); cin.tie(0);
    cin>>n;
    for(int i=1; i<n; i++){
        int u, v, c; cin>>u>>v>>c;
        G[u].push_back({v,c});
        G[v].push_back({u,c});
    }
    dfs(1,-1);

    int cen=findcen();

    if(n%2==0) solve0(cen);
    else solve1(cen);

    cout<<ans;
    return 0;
}

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

using namespace std;

int a[505][505];

int main() {
  int k;
  scanf("%d", &k);
  if (k == 1) {
    puts("1\n1");
    return 0;
  }
  int n = (k+3)/4 * 2;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      a[i][j] = (i+j) % n;
      if ((i & 1) && a[i][j]+n < k)
        a[i][j] += n;
    }
  }
  assert(n <= 500);
  printf("%d\n", n);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      ++a[i][j];
      printf("%d%c", a[i][j], j == n-1 ? '\n' : ' ' );
    }
  }

  return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N;
  cin >> N;
  int a = 0, flag = 1;
  for(int i = 0; i < N; i++){
    cin >> a;
    if(a % 2 == 0){
      if(a % 3 != 0 && a % 5 != 0)flag = 0;
    }
  }
  cout << (flag?"APPROVED":"DENIED") << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int X,K,Q,r[N],t[N],x[N],la,lb,a,b,c,t1,t2,add,tmp,diff,f;
int main() {
  //  freopen("input.txt", "r", stdin);
    cin>>X;
    cin>>K;
    for(int i=1;i<=K;i++)
        cin>>r[i];
    cin>>Q;
    for(int i=1;i<=Q;i++)
        cin>>t[i]>>x[i];
    t1=0,t2=1;
    a=0,b=X,f=-1;
    while(t2<=Q) {
        if(t[t2]>r[t1+1]&&t1<K) {
            t1++;
            add=f*(r[t1]-r[t1-1]);
            b+=add,a+=add;
            b=max(0,min(X,b)),a=max(0,min(X,a));
            c+=add;
            f*=-1;
        }
        else {
            diff=t[t2]-r[t1];
            tmp=max(a,min(b,x[t2]+c));
            tmp+=diff*f;
            tmp=max(0,min(X,tmp));
            cout<<tmp<<endl;
            t2++;
        }
    }
    return 0;
}

Measured memory_bytes: 2432
def resolve():
    N, Cnum = list(map(int, input().split()))
    D = [list(map(int, input().split())) for _ in range(Cnum)]
    C = [list(map(int, input().split())) for _ in range(N)]
    color_count = [{}, {}, {}]
    for i in range(N):
        for j in range(N):
            group = (i+j)%3
            d = color_count[group]
            if C[i][j]-1 in d:
                d[C[i][j]-1] += 1
            else:
                d[C[i][j]-1] = 1
    
    ans = float("inf")
    import itertools
    for pattern in itertools.permutations(list(range(0, Cnum)), 3):
        total = 0
        for i, after in enumerate(pattern):
            for color, count in color_count[i].items():
                total += count*D[color][after]
        ans = min(ans, total)
    print(ans)

if '__main__' == __name__:
    resolve()

Measured memory_bytes: 43996
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

int main(void) {
	int N, X, T;
	cin >> N >> X >> T;
	int res = ((N / X) + (N % X ? 1 : 0)) * T;
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const int INF = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS = 1e-10;
const int MOD = int(1e9)+7;
template<typename T> inline bool chmin(T& a, T b) {if(a>b) {a=b; return true;} return false;}
template<typename T> inline bool chmax(T& a, T b) {if(a<b) {a=b; return true;} return false;}


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

  VV G(N);
  V indeg(N);
  for (int i = 0; i < M; ++i) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    G[a].push_back(b);
    indeg[b]++;
  }

  queue<int> que;
  V dist(N);
  rep(i, N) if (indeg[i] == 0) que.push(i);

  while (!que.empty()) {
    int u = que.front(); que.pop();
    for (auto v : G[u]) {
      chmax(dist[v], dist[u] + 1);
      indeg[v]--;
      if (indeg[v] == 0) que.push(v);
    }
  }

  int ans = 0;
  rep(i, N) chmax(ans, dist[i]);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 6528
/* Author: Dhruv Rastogi */
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define all(sdk) sdk.begin(),sdk.end()
#define mll map<int, int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;++i)
#define repd(i,a,b) for(int i=a;i>=b;--i)
#define mp make_pair
#define hell 1000000007
#define endl '\n'
#define vvll vector<vector<int> >
#define vll vector<int>
#define mint map<int,int> 
#define sz(x) (int)x.size()
#define sll set<int>
#define pll pair<int,int>
#define F first
#define S second
const long double PI = acos(-1.0);

int a[2005];

void solve(){  
	int n;
	cin>>n;
	rep(i,0,n) cin>>a[i];
	sort(a,a+n);
	int ans=0;
	rep(i,0,n){
		rep(j,i+1,n){
			int idx=lower_bound(a,a+n,a[i]+a[j])-a-1;
			ans+=idx-j;
		}
	}
	cout<<ans<<endl;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

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

int64_t gcd(int64_t A, int64_t B)
{
   if (A%B == 0)
   {
       return(B);
   }
   else
   {
       return(gcd(B, A%B));
   }
}

int64_t lcm(int64_t A, int64_t B)
{
   return A * B / gcd(A, B);
}

int main() {
    int64_t A,B;
    cin >> A >> B;
    cout << lcm(A,B) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
double pi=acos(-1);




int main()
{

    int sum;cin>>sum;
    int n;cin>>n;
    int lol=0;
    for(int i=0;i<n;i++){int  a;cin>>a;lol+=a;}
    if(lol>sum)cout<<-1<<endl;
    else cout<<sum-lol<<endl;


	return 0;
}


Measured memory_bytes: 3636
import collections
import sys
import numpy as np
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
MOD = 10**9+7
import itertools
import math

s = input()
for i in range(len(s)):
    if s[i] == "A":
        a_p = i
        break
for i in range(len(s)-1,-1,-1):
    if s[i] == "Z":
        z_p = i
        break
print(z_p-a_p+1)

Measured memory_bytes: 13048
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s, t;
  cin >> s >> t;
  int cnts = 0, cntt = 0, i = 0;
  string ans;
  while (true)
  {
	if (i % 2 == 0) {
	  ans += s[cnts];
	  cnts++;
	}
	else {
	  ans += t[cntt];
	  cntt++;
	}
	if (ans.size() == s.size() + t.size()) {
	  cout << ans << endl;
	  return 0;
	}
	i++;
  }
  
  return 0;
}



Measured memory_bytes: 256
s = list(str(input()))
t = list(str(input()))
alp = 'abcdefghijklmnopqrstuvwxyz'
slst = []
tlst = []

for i in range(len(s)):
    slst.append(alp.find(s[i]))
for i in range(len(t)):
    tlst.append(alp.find(t[i]))

if min(slst)>max(tlst):
    print('No')
elif min(slst)==max(tlst):
    if max(slst)>min(tlst):
        print('No')
    else:
        if len(slst)>=len(tlst):
            print('No')
        else:
            print('Yes')
else:
    print('Yes')

Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
static const int dw[6] = {2,5,10,15,20,25};
static const int dl[6] = {60,80,100,120,140,160};
static const int dm[6] = {600,800,1000,1200,1400,1600};
int main(void){
  int n;
  while(cin>>n){
    if(n==0) break;
    int ans=0;
    REP(i,n){
      int x,y,h,w,l;
      cin>>x>>y>>h>>w;
      l = x+y+h;
      REP(i,6){
        if(l<=dl[i]&&w<=dw[i]){
          ans+=dm[i];
          break;
        }
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <algorithm>
using namespace std;
#define ll long long
const double EPS = 1e-10;
const ll MOD = 7+(1e+9);

int main (){
  ll a,b,c;
  cin>>a>>b>>c;
  if(a==b&&b==c)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int N, K;

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

    std::cin >> N >> K;

    int res;

    if(N % K == 0){
        res = 0;
    }else{
        res = 1;
    }

    std::cout << res << std::endl;
}


Measured memory_bytes: 256
fun main(args : Array<String>) {
    val (h, w) = readLine()!!.split(" ").map{ it.toInt() }
    val ss = Array(h){ readLine()!!.toList() }

    for (i in 0 until h) {
        for (j in 0 until w) {
            var c = ss[i][j]
            if (c == '#') {
                if (i != 0 && ss[i-1][j] == '#') {
                    continue
                }
                if (i != h-1 && ss[i+1][j] == '#') {
                    continue
                }
                if (j != 0 && ss[i][j-1] == '#') {
                    continue
                }
                if (j != w-1 && ss[i][j+1] == '#') {
                    continue
                }

                println("No")
                return
            }
        }
    }

    println("Yes")
}

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

int main(){
int x;
cin>>x;
if(x>=400&&x<=599){
    cout<<'8'<<endl;
}
else if(x>=600&&x<=799){
    cout<<'7'<<endl;
}
else if(x>=800&&x<=999){
    cout<<'6'<<endl;
}
else if(x>=1000&&x<=1199){
    cout<<'5'<<endl;
}
else if(x>=1200&&x<=1399){
    cout<<'4'<<endl;
}
else if(x>=1400&&x<=1599){
    cout<<'3'<<endl;
} else if(x>=1600&&x<=1799){
    cout<<'2'<<endl;
}
else {
    cout<<'1'<<endl;
}

return 0;
}


Measured memory_bytes: 3628
/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

void solve() {
	string s; cin >> s;
    ll sum = 0;
    rep(i, s.size()) {
        sum += s[i] - '0';
        sum %= 9;
    }
    cout << (sum % 9 == 0 ? "Yes" : "No") << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 3740
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstring>
#include <map>
#include <set>
#include <algorithm>

using namespace std;

int main()
{
  int a, b;
  cin >> a >> b;
  int ans = b % a == 0 ? b+a : b-a;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>
#include<limits>
#include<bitset>
#include<functional>
#include<type_traits>
#include<queue>
#include<stack>
#include<array>
#include<random>
#include<utility>
#include<cstdlib>
#include<ctime>

using namespace std;

typedef  long long ll;
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;}

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep2(i, begin_i, end_i) for (int i = (int)begin_i; i < (int)end_i; i++)

long long INF = 1LL<<60;
long long dp[100010];
int h[100010];
int n;
int main(){
    cin>>n;
    int a[n+1];
    for(int i=1;i<=n;i++){
        int temp;
        cin>>temp;
        a[temp]=i;
    }
    for(int i=1;i<=n;i++)cout<<a[i]<<" ";cout<<endl;
    return 0;
}




Measured memory_bytes: 1280
q = int(input())
ary = []
for i in range(q):
    ary.append(int(input()))

minv = ary[0]
maxv = ary[-1]-ary[0]

for j in ary[1:]:
    maxv= max(maxv,j-minv)
    minv= min(minv,j)

print(maxv)

Measured memory_bytes: 17132
import sys
x, n = map(int, input().split())
p = []
if n != 0:
    p = sorted(map(int, input().split()))
q = []
t = 0
for t in range(102):
    if t not in p:
        q.append(t)
m = 100000000
ans = 0
for i in q:
    if abs(x - i) < m:
        m = abs(x - i)
        ans = i
print(ans)


Measured memory_bytes: 9192
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) {
    
    new Main().run();
  }

  public void run() {

    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(br.readLine());
      String op;
      String[] words;
      Tree tree = new Tree();

      for(int i=0,k=0; i<n; i++,k=0){
        words = br.readLine().split(" ");
        op  = words[k++];
        if ( op.equals("insert") ) { 
          tree.insert(Integer.parseInt(words[k++]));
        }
        else {
          tree.dispRoundPath();
        }
      }

    }
    catch(IOException e) {
      System.out.println("IOException!");
    }
  }
}

class Tree {

  static final BTreeNode NIL = new BTreeNode(-1);
  BTreeNode root;
  StringBuilder buf;

  public Tree() {
    root = NIL;
    buf = new StringBuilder();
  }

  public void insert(int val) {
    BTreeNode y = NIL;
    BTreeNode x = root;
    BTreeNode z = new BTreeNode(val);

    while( !x.equals(NIL) ) {
      y = x;
      if( z.key < x.key )
        x = x.left;
      else
        x = x.right;
    }
    z.parent = y;

    if( y.equals(NIL) ){
      root = z;
    }
    else if( z.key < y.key )
      y.left = z;
    else
      y.right = z;
  } 
  void preParse(BTreeNode u) {
    if( !u.equals(NIL) ) {
      buf.append(" ").append(u.key);
      preParse(u.left);
      preParse(u.right);
    }
  }
  void inParse(BTreeNode u) {
    if( !u.equals(NIL) ) {
      inParse(u.left);
      buf.append(" ").append(u.key);
      inParse(u.right);
    }
  }

  void dispRoundPath() {

    inParse(root);
    buf.append("\n");
    preParse(root);
    buf.append("\n");

    System.out.print(buf);
    buf.setLength(0);
  }
}

class BTreeNode {
  int key;
  BTreeNode parent,left,right;

  public BTreeNode(int key) {
    this.key = key;
    this.parent =
    this.left =
    this.right = Tree.NIL;
  }

  @Override
  public boolean equals(Object o) {
    if(o == this) return true;
    if(o == null) return false;
    if(!(o instanceof BTreeNode)) return false;

    BTreeNode node = (BTreeNode)o;
    if(!(this.key == node.key)) return false;

    return true;
  }
}


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

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

    while (1) {
        int H, W;
        cin >> H >> W;
        if (!H & !W) break;
        int ansH = H, ansW = W, Diagonal = H * H + W * W, miD = INF;
        for (int h = 1; h <= 150; h++) {
            for (int w = h + 1; w <= 150; w++) {
                if (h == H && w == W) continue;
                if (h * h + w * w >= Diagonal && h * h + w * w < miD) {
                    if (h * h + w * w == Diagonal && h < H) continue;
                    // cout << h << " " << w << endl;
                    miD = h * h + w * w;
                    ansH = h;
                    ansW = w;
                }
            }
        }
        cout << ansH << " " << ansW << endl;
    }
}


Measured memory_bytes: 3080
// ------------------------------------
// Date:2018/ 4/28
// Problem:/ / / a.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

int N;


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

  cin >> N;
  vector< ll > sum(N + 1, 0ll);
  REP(i, N) {
    LCIN(a);
    if (i > 0) sum[i + 1] = sum[i] + a;
    else sum[i + 1] = a;
  }

  sort(ALL(sum));

  ll ans = 0ll;
  ll last = sum[0];
  ll tmp = 1ll;

  
  FOR(i, 1, N + 1) {
    // debug(sum[i]);
    if (sum[i] != last) {
      // OK(true);
      // debug(tmp);
      ans += tmp * (tmp - 1) / 2;
      last = sum[i];
      tmp = 0ll;
    }
    tmp++;
  }
  if (tmp > 1) ans += tmp * (tmp - 1) / 2;

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



Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    string s;
    while(cin >> s, s != "#"){
        ll a = 0, b = 1;
        int k = 1, cur = 0;
        reverse(s.begin(),s.end());
        if(s[cur] == 'h'){
            a = 0;
            cur += 5;
        }else {
            a = 90;
            cur += 4;
        }

        while(cur < s.size()){
            if(s[cur] == 'h'){
                a = ((1<<k)*a-90*b), b = (1<<k)*b;
                ll g = __gcd(a, b);
                a /= g, b /= g;
                cur += 5;
            }else {
                a = ((1<<k)*a+90*b), b = (1<<k)*b;
                ll g = __gcd(a, b);
                a /= g, b /= g;
                cur += 4;
            }
            k++;
        }
        printf("%lli", a);
        if(b != 1) printf("/%lli", b);
        puts("");
    }
    return 0;
}


Measured memory_bytes: 3256
import collections
n=int(input())
a=list(map(int, input().split(' ')))
c = collections.Counter(a)

def n_c_2(val):
  ret = 0
  if val > 1:
    ret = (val)*(val-1)//2
  return ret

org_nc2 = {}
org_minus1_nc2 = {}
sumall = 0
for k in list(c.keys()):
  org_nc2[k] = n_c_2(c[k])
  org_minus1_nc2[k] = n_c_2(c[k] - 1)
  sumall += org_nc2[k]
for d in a:
  ans = sumall - org_nc2[d] + org_minus1_nc2[d]
  print (ans)


Measured memory_bytes: 40604
#include <bits/stdc++.h>
using namespace std;
int main() {
    string s,t;
    cin >> s >> t;
    int ans = 0;
    if(s[0] == t[0]) ans++;
    if(s[1] == t[1]) ans++;
    if(s[2] == t[2]) ans++;
  	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

#define abs(a) (a < 0 ? -(a) : a)

int main()
{
  int w, a, b;
  scanf("%d %d %d", &w, &a, &b);
  printf("%d\n", abs(a - b) <= w ? 0 : abs(a - b) - w);
  return 0;
}


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

long long int dp[100005][3],ar[100005][3];
long long int solve(long long int i, long long int j,long long int n)
{
    if(i==(n-1))
        return dp[i][j]=ar[i][j];
    if(dp[i][j]!=-1)
       return dp[i][j];
    if(j==0)
        return dp[i][j]=ar[i][j]+max(solve(i+1,1,n),solve(i+1,2,n));
    if(j==1)
        return dp[i][j]=ar[i][j]+max(solve(i+1,0,n),solve(i+1,2,n));
    if(j==2)
        return dp[i][j]=ar[i][j]+max(solve(i+1,0,n),solve(i+1,1,n));
}

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

    long long int a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z;

    cin>>n;
    for(i=0;i<n;i++)
    {
        for(j=0;j<3;j++){
        cin>>ar[i][j];
        dp[i][j]=-1;
        }
    }
    m=solve(0,0,n);
    m=max(m,solve(0,1,n));
    m=max(m,solve(0,2,n));
    cout<<m<<"\n";

    return 0;


}


Measured memory_bytes: 9600
halfAndHalf :: [Int] -> Int
halfAndHalf [a,b,c,x,y]
    | x > y     = minValue y + remValue (x - y) a
    | otherwise = minValue x + remValue (y - x) b
    where
        minValue n = if a + b < 2 * c then (a + b) * n else 2 * c * n
        remValue n v = if v < 2 * c then v * n else 2 * c * n

main :: IO ()
main = do
    input <- map read . words <$> getLine
    putStrLn . show $ halfAndHalf input

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

long long progi[50] = {1, 10, 50, 250, 1250, 6250, 31250, 156250, 781250, 3906250, 19531250, 97656250, 488281250, 2441406250, 12207031250, 61035156250, 305175781250, 1525878906250, 7629394531250, 38146972656250, 190734863281250, 953674316406250, 4768371582031250, 23841857910156250, 119209289550781250, 596046447753906250, 2980232238769531250};
long long wart[50] = {0, 1, 6, 31, 156, 781, 3906, 19531, 97656, 488281, 2441406, 12207031, 61035156, 305175781, 1525878906, 7629394531, 38146972656, 190734863281, 953674316406, 4768371582031, 23841857910156, 119209289550781, 596046447753906, 2980232238769531, 14901161193847656, 74505805969238281, 372529029846191406};

long long ile5(long long k){
	int licznik = 0;
	while (k % 5 == 0 && k){
		licznik++;
		k /= 5;
	}
	return licznik;
}

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

	long long n;
	cin >> n;

	if (n % 2 == 1){
		cout << "0\n";
		return 0;
	}
	int idx = 26;
	long long wynik = 0;

	while (n){
		while (n >= progi[idx]){
			wynik += wart[idx];
			n -= progi[idx];
		}
		idx--;
	}
	cout << wynik << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, k, n) for(int i = (k); i < (n); i++)
#define FORr(i, k, n) for(int i = (k); i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORr(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using ll = long long;

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

  vector<priority_queue<int>> a(m+1);
  REP(i, n){
    int x, y;
    cin >> x >> y;
    if(x <= m) a[x].push(y);
  }

  ll ans = 0;
  priority_queue<int> t;
  FOR(i, 1, m+1){
    if(a[i].empty() && t.empty()) continue;
    if(!a[i].empty() && !t.empty()){
      if(a[i].top() > t.top()){
        ans += a[i].top();
        a[i].pop();
      }else{
        ans += t.top();
        t.pop();
      }
    }else if(t.empty()){
      ans += a[i].top();
      a[i].pop();
    }else{
      ans += t.top();
      t.pop();
    }

    while(!a[i].empty()){
      t.push(a[i].top());
      a[i].pop();
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6272
import sys
import numpy as np
from collections import Counter
input = sys.stdin.buffer.readline
N = int(input())
A = np.array(list(map(int, input().split())))


def f(n):
    return n * (n - 1) // 2


cumsum = A.cumsum()
ans = 0
for key, value in Counter(cumsum).items():
    if key == 0:
        ans += value
    if value >= 2:
        ans += f(value)
print(ans)


Measured memory_bytes: 53300
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#include <cstdio>
using namespace std;

#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
/* ここからが本編 */
/* */
/* 入力開始！ */
/* 入力終了！ */

/* prime_judge(a,n)はaが全て0で初期化されてることを前提
としてます */
void prime_hantei(bool prime_judge[],int n)
{
   int i,j,k;
   prime_judge[2] = 1;

	for(i=3;i<=n;i+=2)
	{
		k=0;
		for(j=3;j*j<=i;j+=2)
		{
			if(i%j==0)
			{
				k=1;
				break;
			}
		}

		if(k==0) prime_judge[i] = 1;
	}
}
int main()
{
   bool a[10050] = {0};
   int n;
   int p;
   int i,j;
   prime_hantei(a,10030);
   while(1) {
      int cnt=0;
      if(scanf("%d",&n) == EOF) break;
      for(i=1;i<= n/2 ;i++) {
         if(a[i] && a[n+1-i])
            cnt++;
      }
      cnt *= 2;
      if(n%2) { 
         if(a[n/2 +1]) cnt++;
      }
      printf("%d\n",cnt);
   }
   return 0;
}

Measured memory_bytes: 1204
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=1e5+5;
int a[N],n;
int cnt1[N],cnt2[N];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        if(i&1)
            cnt1[a[i]]++;
        else
            cnt2[a[i]]++;
    }
    int ans=0;
    int mx=0,mx2=0,mi;
    int fx=0,fx2=0,fi;
    for(int i=1;i<N;i++){
        if(cnt1[i]>mx){
            mx2=mx;
            mx=cnt1[i];
            mi=i;
        }
        else if(cnt1[i]>mx2){
            mx2=cnt1[i];
        }
    }
    for(int i=1;i<N;i++){
        if(cnt2[i]>fx){
            fx2=fx;
            fx=cnt2[i];
            fi=i;
        }
        else if(cnt2[i]>fx2){
            fx2=cnt2[i];
        }
    }
    if(mi!=fi){
        ans=n-mx-fx;
    }
    else{
        ans=min(n-mx-fx2,n-fx-mx2);
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
const int INF = 0x3f3f3f3f, N = 2e5 + 5;
const ll LINF = 1e18 + 5;
int n;
unordered_map <string, int> cnt;
string s;
int main()
{
 	ios::sync_with_stdio(false);
 	cin.tie(0);
 	cin >> n;
 	int ans = 0;
 	for(int i=1; i<=n; i++) 
 	{
 		cin >> s;
 		cnt[s]++;
 		ans = max(ans, cnt[s]);
 	}
 	vector <string> res;
 	for(auto x : cnt) if(x.second==ans) res.pb(x.first);
 	sort(all(res));
 	for(auto x : res) cout << x << '\n';
	return 0;
}


Measured memory_bytes: 25284