akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
const int N=1000100;
const int mod=924844033;
const int g[2]={5,554906420};
int n,lim=1,pos[N],cnt[N],siz[N],f[N],r[N],T[N];
vector<int>V[N];
int qpw(int x,int n){
	int ret=1; for(;n;n>>=1,x=1ll*x*x%mod)
	if(n&1) ret=1ll*ret*x%mod; return ret;
}
void ini(int x){
	int l=0; while(lim<x) lim<<=1,++l;
	for(int i=0;i<lim;i++) pos[i]=pos[i>>1]>>1|(i&1)<<l-1;
}
void ntt(int A[],int op){
	for(int i=0;i<lim;i++) if(i<pos[i]) swap(A[i],A[pos[i]]);
	for(int d=1;d<lim;d<<=1) for(int l=d<<1,wn=qpw(g[op],(mod-1)/l),i=0;i<lim;i+=l)
		for(int j=0,w=1;j<d;j++,w=1ll*w*wn%mod){
			int a=A[i+j],b=1ll*w*A[i+j+d]%mod;
			A[i+j]=(a+b)%mod,A[i+j+d]=(a-b)%mod;
		}
	if(op) for(int i=0,k=qpw(lim,mod-2);i<lim;i++) A[i]=1ll*A[i]*k%mod;
}
void dfs(int x,int f){
	siz[x]=1;
	for(int i=0;i<V[x].size();i++){
		int t=V[x][i]; if(t==f) continue; dfs(t,x);
		++cnt[siz[t]], ++cnt[n-siz[t]], siz[x]+=siz[t];
	}
}
int C(int n,int m){return 1ll*f[n]*r[n-m]%mod*r[m]%mod;}
int main(){
	scanf("%d",&n),f[0]=1;
	for(int i=1;i<=n;i++) f[i]=1ll*f[i-1]*i%mod;
	r[n]=qpw(f[n],mod-2); for(int i=n;i>=1;i--) r[i-1]=1ll*r[i]*i%mod;
	for(int i=1,x,y;i<n;i++)scanf("%d%d",&x,&y),V[x].pb(y),V[y].pb(x);
	dfs(1,0); for(int i=0;i<=n;i++) cnt[i]=1ll*cnt[i]*f[i]%mod, T[i]=r[i]; reverse(cnt,cnt+n+1);
	ini(n<<1), ntt(cnt,0), ntt(T,0); for(int i=0;i<lim;i++) cnt[i]=1ll*cnt[i]*T[i]%mod; ntt(cnt,1);
	for(int i=1;i<=n;i++) printf("%lld\n",(mod+(1ll*n*C(n,i)-1ll*r[i]*cnt[n-i])%mod)%mod);
}


Measured memory_bytes: 55244
#include<bits/stdc++.h>
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

int main(){
  fastIO
 int l,r,d;
  cin>>l>>r>>d;
  int count=0;
  for(int i=l;i<=r;i++){
    if(i%d==0){
      count++;
    }
  }
  cout<<count<<endl;
  return 0;
}

Measured memory_bytes: 3548
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <iterator>
#include <algorithm>

typedef long long lint;

using namespace std;

void showIntArray(lint a[], lint n);

int main() {
  int A, P;
  cin >> A >> P;
  cout << (A * 3 + P) / 2 << endl;
  return 0;
}

void showIntArray(lint a[], lint n) {
  for (int i=0; i<n; i++) {
    cout << a[i] << ' ';
  } cout << endl;
}


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

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

	int S = 1; for (int i = 0; i < D; i++) S *= 100;
	if (N < 100) {
		cout << S * N << endl;
	}
	else {
		cout << S * 101 << endl;
	}
	return 0;
}


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

int main(void){
    long Num, Value, Min, Max, Sum;
    
    std::cin >> Num;
    
    Sum = 0;
    for(long i = 0; i < Num; i++){
        std::cin >> Value;
        if(i == 0){
            Min = Value;
            Max = Value;
        } else{
            if(Value < Min) Min = Value;
            if(Value > Max) Max = Value;
        }
        Sum += Value;
    }
    
    std::cout << Min << " " << Max << " " << Sum << std::endl;
}

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

#define ll long long

int main(void){
    int n;
    cin >> n;
    vector<int>p(n);
    for(int i=0;i<n;i++){
        cin >>p[i];
    }
    bool flag = true;
    for(int i=0;i<n;i++){
        for(int j=i;j<n;j++){
            vector<int>tmp(n);
            for(int k=0;k<n;k++){
                tmp[k] = p[k];
            }
            int t;
            t = tmp[i];
            tmp[i] = tmp[j];
            tmp[j] = t;
            // cout << tmp[2];
            flag = true;
            for(int k=1;k<n;k++){
                // cout << tmp[k] << tmp[k-1] << endl;
                if(tmp[k] < tmp[k-1]){
                    flag = false;
                }
            }
            if(flag == true){
                cout << "YES" << endl;
                break;
            }
        }
        if(flag == true){
            break;
        }
    }
    if(flag == false){
        cout << "NO"<<endl;
    }
    return 0;
}

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

using ll = long long;

// 組合せを素数で割った値を求める
const int MAX = 510000;
const int MOD = 1e9 + 7;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll n, m, k;
  cin >> n >> m >> k;
  
  COMinit();
  
  ll ans = 0;
  for(int i = 1; i <= m - 1; i++){
    ll keep = (((i * n * n) % MOD) * (m - i)) % MOD;
    keep *= COM(n * m - 2, k - 2);
    keep %= MOD;
    ans += keep;
    ans %= MOD;
  }
  for(int i = 1; i <= n - 1; i++){
    ll keep = (((i * m * m) % MOD) * (n - i)) % MOD;
    keep *= COM(n * m - 2, k - 2);
    keep %= MOD;
    ans += keep;
    ans %= MOD;
  }
  
  cout << ans << '\n';
}

Measured memory_bytes: 12160
#include<stdio.h>
int main(){
int a=0,b=0,d;
for(int i=0;i<4;i++){
 scanf("%d",&d);
 a=a+d;
}

for(int i=0;i<4;i++){
 scanf("%d",&d);
 b=b+d;
}
if(a<=b) printf("%d\n",b);
else printf("%d\n",a);
return 0;
}

Measured memory_bytes: 0
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
using namespace std;
int main(){

int a,b,c,d;

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

int f = 1;

if((a-1)*(b-1)*(c-1)*(d-1)!=0){
f=0;
}
if((a-9)*(b-9)*(c-9)*(d-9)!=0){
f=0;
}
if((a-7)*(b-7)*(c-7)*(d-7)!=0){
f=0;
}
if((a-4)*(b-4)*(c-4)*(d-4)!=0){
f=0;
}

if(f==1){
cout << "YES";
}else{
cout << "NO";
}
return 0;

}

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

void step(vector<vector<int> >& edges, vector<int>& node_class, int node, int cls)
{
    if(node_class[node] != -1) return;
    node_class[node] = cls;
    for(int e : edges[node])
    {
        if(node_class[e] == -1) step(edges, node_class, e, cls);
    }
}

void cls_init(vector<int>& node_class)
{
    for(vector<int>::size_type i=0;i<node_class.size();++i)
        node_class[i] = -1;
}

void dfs(vector<vector<int> >& edges, vector<int>& node_class)
{
    int cls = 0;
    cls_init(node_class);
    for(vector<int>::size_type i=0;i<edges.size();++i)
    {
        if(node_class[i] == -1) step(edges, node_class, i, cls++);
    }
}

int main()
{
    int n, m, s, t;
    cin >> n >> m;
    vector< vector<int> > edges(n);
    vector<int> node_class(n);
    for(int i=0;i<m;++i)
    {
        cin >> s >> t;
        edges[s].push_back(t);
        edges[t].push_back(s);
    }
    dfs(edges, node_class);
    int q;
    cin >> q;
    for(int i=0;i<q;++i)
    {
        cin >> s >> t;
        if(
            node_class[s] == node_class[t]
            && node_class[s] != -1
            && node_class[t] != -1
        ){ 
            cout << "yes";
        }
        else cout << "no";
        cout << endl;
    }
}



Measured memory_bytes: 13380
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
 
int main() {
	int n;
	cin >> n;
	int a[100];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int mi = 0;
	int ma = 0;
	int co[8] = {};
	for (int i = 0; i < n; i++) {
		if (a[i] <= 399) {
			co[0] = 1;
		}
		else if ((a[i] >= 400) && (a[i] <= 799)) {
			co[1] = 1;
		}
		else if ((a[i] >= 800) && (a[i] <= 1199)) {
			co[2] = 1;
		}
		else if ((a[i] >= 1200) && (a[i] <= 1599)) {
			co[3] = 1;
		}
		else if ((a[i] >= 1600) && (a[i] <= 1999)) {
			co[4] = 1;
		}
		else if ((a[i] >= 2000) && (a[i] <=2399)) {
			co[5] = 1;
		}
		else if ((a[i] >= 2400) && (a[i] <= 2799)) {
			co[6] = 1;
		}
		else if ((a[i] >= 2800) && (a[i] <= 3199)) {
			co[7] = 1;
		}
		else if (a[i] >= 3200) {
			ma++;
		}
	}
	for (int i = 0; i < 8; i++) {
		if (co[i] == 1) {
			mi++;
		}
	}
	cout << max(mi,1)<< " "<<ma+mi<<endl;
	getchar();
	getchar();
	return 0;
}


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

int main(void){
    char b;
    scanf("%c",&b);
    
    char test[4] = "ATCG";
    char ans[4] = "TAGC";

    for (int i = 0;i < 4;i++){
        if(test[i] == b){
            printf("%c",ans[i]);
            return 0;
        }
    }
    return 0;
}

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

#define ll long long
#define llong long long
#define REP(i,n) for(auto i=0;i<n;++i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define FOR(i,a,b) for(auto i=a;i<b;++i)
#define ALL(v) v.begin(),v.end()
#define pb push_back

#define INF (int)1e6

using namespace std;

int main(){
  int n; cin >> n;
  vector<string> s(n);
  for(int i = 0; i < n; i++){
    string temp;
    cin >> temp;
    if(temp == "goto"){
      cin >> s[i];
    }
    else{
      s[i] = temp;
    }
  }
  //for(auto e : s)cerr << e << endl;
  map<string, int> l;
  for(int i = 0; i < n; i++){
    if(s[i].back() == ':'){
      auto temp = s[i];
      temp.pop_back();
      l[temp] = i;
    }
  }
  vector<vector<int> > e(n+1, vector<int>(n+1,INF));
  //for(auto e : l)cerr << e.first << " : " << e.second << endl;
  for(int i = 0; i < n; i++){
    if(s[i].back() == ';'){
      auto temp = s[i];
      temp.pop_back();
      e[i][i+1] = 1;
      e[i][l[temp]] = min(0,e[i][l[temp]]);
    }
    else{
      e[i][i+1] = 0;
    }
    e[i][i] = 0;
  }
  /*
  for(int i = 0; i <= n; i++){
    for(int j = 0; j <= n; j++){
      fprintf(stderr,"%2d ",e[i][j] == INF ? -1 : e[i][j]);
    }
    cerr << endl;
  }
  */
  //for(auto v : e){for(auto ee : v)fprintf(stderr,"%2d ",ee == INF ? -2 : ee);cerr<<endl;}

  for(int k = 0; k <= n; k++){
    for(int i = 0; i <= n; i++){
      for(int j = 0; j <= n; j++){
        e[i][j] = min(e[i][j], e[i][k] + e[k][j]);
      }
    }
  }

  cout << e[0][n] << endl;

  return 0;
}




Measured memory_bytes: 3232
#include <bits/stdc++.h>
#define FOR(i,a,b) for(register int i=(a);i<(b);++i)
#define ROF(i,a,b) for(register int i=(a);i>=(b);--i)
#define pi pair<int,int>
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef double db;
const int maxn = 200005;
const int maxm = 100;
const int inf = 2147483647;
typedef long long ll;
const double eps = 1e-9;
const long long INF = 9223372036854775807ll;
ll qpow(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=ans*a%c;a=a*a%c;b>>=1;}return ans;}
struct Node{
	int l,r,d;
	bool operator <(const Node a)const{
		return abs(r-l)>abs(a.r-a.l);
	}
}s[maxn];
vector<int>a,b;
bool cmp1(int a,int b){
	return s[a].d<s[b].d;
}
bool cmp2(int a,int b){
	return s[a].d>s[b].d;
}
priority_queue<Node>aa,bb;
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		int n;
		scanf("%d",&n);
		a.clear(),b.clear();
		ll ans=0;
		FOR(i,0,n){
			scanf("%d%d%d",&s[i].d,&s[i].l,&s[i].r);
			if(s[i].l>s[i].r)a.push_back(i);else if(s[i].l<s[i].r)b.push_back(i);
			else ans+=s[i].l;
		}
		sort(a.begin(),a.end(),cmp1);
		sort(b.begin(),b.end(),cmp2);
		FOR(i,0,a.size()){
			if((int)aa.size()==s[a[i]].d){
				if(abs(aa.top().r-aa.top().l)<abs(s[a[i]].r-s[a[i]].l)){
					ans+=aa.top().r-aa.top().l;
					aa.pop();
					aa.push(s[a[i]]);
					ans+=s[a[i]].l;
				}else{
					ans+=s[a[i]].r;
				}
			}else if(aa.size()<s[a[i]].d){
				aa.push(s[a[i]]);
				ans+=s[a[i]].l;
			}
		}
		FOR(i,0,b.size()){
			if((int)bb.size()==n-s[b[i]].d && n-s[b[i]].d){
				if(abs(bb.top().l-bb.top().r)<abs(s[b[i]].r-s[b[i]].l)){
					ans+=bb.top().l-bb.top().r;
					bb.pop();
					ans+=s[b[i]].r;
					bb.push(s[b[i]]);
				}else {
					ans+=s[b[i]].l;
				}
			}else if((int)bb.size()<n-s[b[i]].d){
				bb.push(s[b[i]]);
				ans+=s[b[i]].r;
			}else {
				ans+=s[b[i]].l;
			}
		}
		while(!aa.empty())aa.pop();
		while(!bb.empty())bb.pop();
		printf("%lld\n",ans);
	} 
}


Measured memory_bytes: 9708
import numpy as np
N = int(input())
h = np.array([int(i) for i in input().split()])
count=0
 
while(np.max(h)>0):
    start=0
    i=0
    while(h[i]==0):
        i+=1
    start=i
    while(h[i]!=0 and i<N-1):
        i+=1
    if h[i]==0:
        h[start:i]=h[start:i]-1
    else:
        h[start:]=h[start:]-1
    count+=1
 
print(count)

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

using namespace std;

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

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#ifdef Debug
#define dump(x)  cerr << #x << " = " << (x) << endl
#else
#define dump(x)
#endif

int main(){
	int n;
	cin>>n;
	int c=0;
	while(1){
		n=ceil(n/3.0);
		c++;
		if(n==1)break;
	}

	cout<<c<<endl;

	return 0;
}

Measured memory_bytes: 1168
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;
const ll LINF=1e18;

int main(){
    int x;
    cin>>x;
    int dp[x+1000]={};
    dp[0]=1;
    int a[]={100,101,102,103,104,105};
    for(int i=0;i<x;i++){
        for(int j=0;j<6;j++){
            dp[i+a[j]]|=dp[i];
        }
    }
    if(dp[x])cout<<1<<endl;
    else cout<<0<<endl;
}

Measured memory_bytes: 640
a, b, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
aa = min(a)
bb = min(b)
aabb = aa+bb
ab = [a+b for a, b in zip(a, b)]
ans = []
for i in ab:
    ans.append(i)

for i in range(m):
    x, y, c = map(int, input().split())
    ans.append(a[x-1]+b[y-1]-c)

ans.append(aabb)
print(min(ans))

Measured memory_bytes: 76504
# coding: utf-8
# Your code here!
n = int(input())
a = list(map(int,input().split()))
money = 1000
have = 0
buy = 0
c = []
check = a[0]
start = False
check2 = -1
for i in range(1,n):
    if check2 > a[i] and start:
        c.append((check,check2))
        check = a[i]
        check2 = -1
        #print(i)
    elif check >= a[i] and start:
        check = a[i]
    elif check2 <= a[i] and start:
        check2 = a[i]
    elif check < a[i] and not start:
        check2 = a[i]
        start = True
    elif check >= a[i] and not start:
        check = a[i]
    #print(check,check2)
if check2 != -1 and check != check2:
    c.append((check,check2))
#print(c)
for i in c:
    have = money//i[0]
    money -= i[0]*have
    money += have * i[1]
print(money)
    

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

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

  if(n%2 == 0)
    cout << n / 2;
  else
  {
    cout << n / 2 + 1;
  }

}


Measured memory_bytes: 3624
#include<iostream>
#include<queue>
#include<algorithm>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
const int N = 20*20+2;
const int inf = (1<<25);
int cap[N][N];
bool vis[N];
int parent[N];
int flow[N][N];
int layer[N];

void make_layer(int n,int s,int t){
  queue<int >Q;
  Q.push(s);
  layer[s]=0;
  while(!Q.empty()){
    int now = Q.front();Q.pop();
    rep(i,n){
      if (cap[now][i]-flow[now][i]  > 0 && layer[i] == -1){
	layer[i]=layer[now]+1;
	Q.push(i);
      }
    }
  }
}

int augment(int now,int t,int n,int f){
  if (now == t || f == 0)return f;
  if (vis[now])return 0;
  vis[now]=true;
  rep(i,n){
    if (layer[now] < layer[i]){
      int tmp = augment(i,t,n,min(f,cap[now][i]-flow[now][i]));
      if (tmp > 0){
	flow[now][i]+=tmp;
	flow[i][now]=-flow[now][i];
	vis[now]=false;
	return tmp;
      }
    }
  }
  return 0;
}

int dinic(int n,int s,int t){
  int ansflow=0;
  bool flag=true;
  rep(i,n)rep(j,n)flow[i][j]=0;
  while(flag){
    fill(layer,layer+n,-1);
    fill(vis,vis+n,false);
    flag=false;
    make_layer(n,s,t);
    if (layer[t] == -1)break;
    for(int f=1;f;flag=true){
      f=augment(s,t,n,inf);
      if (f==0)break;
      ansflow+=f;
    }
  }
  return ansflow;
}

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

main(){
  int r,c;
  int te,tc=1;
  cin>>te;
  while(te--){
    cin>>c>>r;
    int n = r*c+2,src=r*c,dst=r*c+1;
    int sum = 0;
    rep(i,n)rep(j,n)cap[i][j]=0;
    rep(i,r){
      rep(j,c){
	int tmp;
	cin>>tmp;
	int now = i*c+j;
	sum+=tmp;
	//cout << i <<" " << j <<" " << (i+j)%2  << endl;
	if ((i+j)%2 == 0)cap[src][now]=tmp;
	else cap[now][dst]=tmp;
	rep(k,4){
	  int ney=i+dy[k],nex=j+dx[k];
	  if (nex ==-1 || ney ==-1 ||
	      nex == c || ney == r)continue;
	  int next=ney*c+nex;
	  if ((i+j)%2 == 0)cap[now][next]=inf;
	}
      }
    }
    /*
    rep(i,n){
      rep(j,n){
	cout << cap[i][j] <<" " ;
      }
      cout << endl;
    }
    */
    int ans=sum-dinic(n,src,dst);
    //cout << sum << " " << dinic(n,src,dst) << endl;
    cout <<"Case " << tc++ <<": " <<  ans << endl;
    /*
    REP(i,r*c,n){
      rep(j,r*c){
	if (flow[i][j] > 0)cout <<i <<" " << j <<" " <<  flow[i][j] << endl;
      }
      cout << endl;
    }
    */
  }
}

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

int main() {
  string A, B, a, b, c, d;
  cin >> A;
  B = "No";
  a = A.at(0);
  b = A.at(1);
  c = A.at(2);
  d = A.at(3);
  
  if (a == b && c == d && a != c)
        B = "Yes";
  if (a == c && b == d && a != b)
        B = "Yes";
  if (a == d && b == c && a != b)
        B = "Yes";
  cout << B << endl;
}

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

using T=tuple<string,int,int>;
int main(){
    int N;
    cin>>N;
    vector<T> V;
    for(int i=0;i<N;i++){
        string S;
        int p;
        cin>>S>>p;
        V.emplace_back(S,-p,i+1);
    }
    sort(V.begin(), V.end());
    for(auto t:V){
        int id;
        tie(ignore,ignore,id)=t;
        cout<<id<<endl;
    }
    return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
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 (b<a) { a=b; return 1; } return 0; }

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

int main() {
  string S;
  cin>>S;
  int ans = 0;
  int N = S.size();
  for(int i = 0; i < N; i++){
    for(int j = i+1; j < N+1; j++){
      bool t = true;
      for(int k = i; k < j; k++){
        if(S[k]!='A'&&S[k]!='T'&&S[k]!='G'&&S[k]!='C') t=false;
      }
      if(t) chmax(ans,j-i);
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define POWER9 1000000000
#define MOD POWER9+7
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483647
#define INT_MAX 2147483647
#define LL_MIN (LL)-9223372036854775807
#define LL_MAX (LL)9223372036854775807
#define PI 3.14159265359

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << setprecision(9);

	int N;
	LL a[100000];
	cin >> N;
	for(int i=0; i<N; i++) cin >> a[i];
	
	LL sum = 1;
	LL ans = abs(sum-a[0]);
	for(int i=1; i<N; i++){
		if(sum > 0){
			sum += a[i];
			if(sum >= 0){
				ans += sum+1;
				sum = -1;
			}
		}
		else{
			sum += a[i];
			if(sum <= 0){
				ans += -sum+1;
				sum = 1;
			}
		}
		//cout << sum << endl;
	}
	LL memo = ans;

	sum = -1;
	ans = abs(sum-a[0]);
	for(int i=1; i<N; i++){
		if(sum > 0){
			sum += a[i];
			if(sum >= 0){
				ans += sum+1;
				sum = -1;
			}
		}
		else{
			sum += a[i];
			if(sum <= 0){
				ans += -sum+1;
				sum = 1;
			}
		}
		//cout << sum << endl;
	}
	memo = min(ans, memo);

	if(a[0] != 0){

	sum = a[0];
	ans = 0;
	for(int i=1; i<N; i++){
		if(sum > 0){
			sum += a[i];
			if(sum >= 0){
				ans += sum+1;
				sum = -1;
			}
		}
		else{
			sum += a[i];
			if(sum <= 0){
				ans += -sum+1;
				sum = 1;
			}
		}
		//cout << sum << endl;
	}
	memo = min(ans, memo);

	}
	

	cout << memo << endl;

	return 0;
}


Measured memory_bytes: 1024
import sys
from collections import defaultdict, deque
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N = int(readline())

g = [[] for _ in range(N)]
deg = [0] * N
ab = defaultdict(int)

for _ in range(N - 1):
    a, b = map(int1, readline().split())
    g[a].append(b)
    g[b].append(a)
    deg[a] += 1
    deg[b] += 1
    ab[(a, b)] = -1

color = [-1] * N

print(max(deg))

C = [0] * N
C[0] = -1

que = deque([0])

while len(que) != 0:
    idx = que.popleft()
    tmp = 1
    for i in g[idx]:
        if C[i] != 0:
            continue
        a, b = idx, i
        if tmp == C[idx]:
            tmp += 1
        ab[(a, b)] = tmp
        C[i] = tmp
        que.append(i)
        tmp += 1

for v in ab.values():
    print(v)


Measured memory_bytes: 40172
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect# lower_bound etc
#import numpy as np
#from copy import deepcopy
#from collections import deque

import math
class segtree:
    def __init__(self, n, init_val = None, init = 0):
        self.n = n
        self.init_val = init_val
        self.init = init
        self.k = math.ceil(math.log2(n))

        try:init_val[0]
        except:raise ValueError('init_val should be list')

        self.bins = [self.init] * (1<<(self.k+1))
        for idx, i in enumerate(range(1<<self.k, 1<<(self.k+1))):
            if len(self.init_val)>idx:
                self.bins[i] = init_val[idx]

        self.caliculate()

    def compare(self, l, r):
        # modify!!
        #print(l, r)
        return max(l, r, key = lambda x:x[0])

    def caliculate(self):
        k = self.k
        while k:
            for i in range(1<<k, 1<<(k+1)):
                if not i%2:
                    self.bins[i//2] = self.compare(self.bins[i], self.bins[i+1])
                else:continue
            k -= 1

    def update(self, idx, val):
        '''idx : 0-started index'''
        k = (1<<self.k) + idx
        self.bins[k] = val
        while k>1:
            self.bins[k // 2] = self.compare(self.bins[k // 2 * 2], self.bins[k // 2 * 2 + 1])
            k = k//2


    def eval(self, l, r):
        ret = self.init
        l = (1 << self.k) + l
        r = (1 << self.k) + r
        #print(l, r)
        while True:
            #print(l, r)
            if r - l == 1:
                ret = self.compare(ret, self.bins[l])
                ret = self.compare(ret, self.bins[r])
                break
            elif l == r:
                ret = self.compare(ret, self.bins[l])
                break
            else:
                done = False
                if l % 2:
                    ret = self.compare(ret, self.bins[l])
                    l += 1
                    done = True
                if not r % 2:
                    ret = self.compare(ret, self.bins[r])
                    r -= 1
                    done = True
                if not done:
                    l = l // 2
                    r = r // 2
        #print(ret)
        return ret

    def value(self, ind):
        return self.bins[(1<<self.k) + ind]


def run():
    N,M = map(int, sysread().split())
    A = list(map(int, sysread().split()))
    A_with_idx = [(a, i) for i, a in enumerate(A)]
    st = segtree(len(A_with_idx), init_val = A_with_idx, init = (0, -1))
    for i in range(M):
        a, idx = st.bins[1]
        st.update(idx, (a // 2, idx))

    ret = 0
    for i in range(N):
        ret += st.value(i)[0]
    print(ret)



if __name__ == "__main__":
    run()


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

int main() {
  
  int X;
  cin >> X;
  
  int base=2;
  int max=1;
  while(base*base<=X){
    int expo=2;
    while( pow(base, expo+1)<=X ){
      expo++;
    }
    if( max<pow(base, expo) ){ max=pow(base, expo); }
    base++;
  }
  
  cout << max << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,j,m,n,a,b,l,count=0;
    string s;
    cin>>s;


        if(s[0]=='R'&&s[1]=='R'&&s[2]=='R')
        {
            cout<<3<<endl;
        }
        else if(s[0]=='R'&&s[1]=='R'||s[1]=='R'&&s[2]=='R')
        {
            cout<<2<<endl;
        }
        else if(s[0]=='S' &&s[1]=='S'&&s[2]=='S') cout<<0<<endl;
        else cout<<1<<endl;



}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef long long ll;
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 int INF = 100000; 

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

    if(n % 10 == 9 || (n / 10) % 10 == 9){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
e = list(map(lambda x: (int(x)+1)/2, input().split()))

s = [e[0]]
for i in range(1, n):
    s.append(s[i-1]+e[i])

a = 0
for i in range(n-k+1):
    if i == 0:
        a = max(a, s[i+k-1])
    else:
        a = max(a, s[i+k-1] - s[i-1])
print(a)

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

int main() {
   string s[2];
   rep(i, 2) {
       cin >> s[i];
   }

   if (s[0][0] == s[1][2] && s[0][1] == s[1][1] && s[0][2] == s[1][0]) {
       cout << "YES" << endl;
   } else {
       cout << "NO" << endl;
   }
}

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

#define M 1000003
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key) {return key % M;}
int h2(int key) {return 1 + key % (M - 1);}

int find(char str[]){

  int i;
  long long a1,a2;
  a1 = getKey(str);
  for(i = 0; i < M; i++){
    a2 = (h1(a1) + i * h2(a1)) % M;
    if(H[a2][0] == '\0'){ return 0;}
    if(strcmp(H[a2],str) == 0){ return 1;}

  }
  return 0;
}

int insert(char str[]){
  
  int i;
  long long a1,a2;
  a1 = getKey(str);
  for(i = 0; i < M; i++){
    
    a2 = (h1(a1) + i * h2(a1)) % M;
    
    if(H[a2][0] == '\0'){
      strcpy(H[a2],str);
      return 0;
    }
  }
}
int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);
	
	if ( com[0] == 'i' ){
	    insert(str);
	} else {
	    if (find(str)){
		printf("yes\n");
	    } else {
		printf("no\n");
	    }
	}
    }

    return 0;
}

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

int main() {
  int k, n;
  cin >> k >> n;
  vector<int> A(n, 0);
  vector<int> d(n, 0);
  rep(i, n) {
    cin >> A[i];
  }
  
  int l = 0;
  rep(i, n) {
    int d;
    if (i+1 == n) d = k + A[0] - A[i];
    else d = A[i+1] - A[i];
    l = max(d, l);
  }
  int ans = k - l;
  cout << ans << endl;
}


Measured memory_bytes: 1920
#include <utility> // pair make_pair
using std::swap; // c++11
using std::pair;
using std::make_pair;
#include <tuple> // tuple(c++11) make_tuple(c++11)
using std::tuple; // get<address>(variable)
using std::make_tuple;
#include <string> // string stoi(c++11) stoll(c++11) to_string(c++11)
using std::string;
using std::stoi;
using std::stoll;
using std::to_string;
#include <queue> // queue priority_queue
using std::queue;
using std::priority_queue;
#include <stack> // stack
using std::stack;
#include <vector> // vector
using std::vector;
#include <map> // map
using std::map;
#include <set> // set
using std::set; // insert erase find count
#include <algorithm> // min max
using std::sort;
using std::lower_bound; // iterator,  >=
using std::upper_bound; // iterator,  >
using std::min;
using std::max;
using std::min_element; // iterator
using std::max_element; // iterator
#include <complex> // complex
using std::complex; // real imag
#include <iostream> // cin cout
using std::cin;
using std::cout;
using std::endl;
#include <iomanip> // setprecision fixed(manipulator)
using std::setprecision;
using std::fixed;
#include <cmath>
#include <cstdio>

#define lli long long int
#define INF (int)1e09
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define EFOR(i, m, n) for (int i = m; i <= n; i++)
#define RFOR(i, m, n) for (int i = m; i > n; i--)
#define REFOR(i, m, n) for (int i = m; i >= n; i--)
#define VSORT(v) sort((v).begin(), (v).end()) // sort vector
typedef pair<int, int> PI;
typedef tuple<int, int, int> TI;
template <typename T> using Vec = vector<T>; // c++11

int sum_or_dif(int a, int b, char op) {
    if (op == '+') {
        return a + b;
    } else if (op == '-') {
        return a - b;
    } else {
        return 0;
    }
}

bool calc(string num, string op) {
    int array[4];
    FOR (i, 0, 4) {
        array[i] = (int)(num[i] - '0');
    }
    if (sum_or_dif(sum_or_dif(sum_or_dif(array[0], array[1], op[0]), array[2], op[1]), array[3], op[2]) == 7) {
        return true;
    } else {
        return false;
    }
}

int main(void) {
    string num;
    cin >> num;
    Vec<string> op = {"+++","++-","+-+","+--","-++","-+-","--+","---"};

    FOR (i, 0, 8) {
        if (calc(num, op[i]) == true) {
            FOR (k, 0, 3) {
                cout << num[k] << op[i][k];
            }
            cout << num[3] << "=7" << endl;
            break;
        }
    }
    return 0;
}


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

int main(){
    int n,d,a;
    cin>>n>>d>>a;
    vector <pii> x;
    vector <int> limit(n,0);
    const int inf = 1e9+7;
    rep(i,n){
        int a,b;cin>>a>>b;
        x.emplace_back(make_pair(a,b));
    }
    sort(x.begin(),x.end());
    rep(i,n){
        limit[i]=upper_bound(x.begin(),x.end(),make_pair(x[i].first+2*d,inf))-x.begin();
    }
    ll ans=0;
    ll cnt=0;
    vector <int> s(n+1,0);
    rep(i,n){
        x[i].second-=s[i];
        int cnt = (x[i].second+a-1)/a;
        if(x[i].second>0){
            ans +=cnt;
            s[i]+=cnt*a;
            s[limit[i]]-=cnt*a;
        }
        s[i+1]+=s[i];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3440
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

#define MIN_INT -2147483648
#define MAX_INT 2147483647
#define MIN_LONG -9223372036854775808L
#define MAX_LONG 9223372036854775807L
#define PI 3.141592653589793238462643383279502884L

#define long long long int

using std::vector;
using std::map;
using std::set;
using std::string;
using std::pair;
using std::cin;
using std::cout;
using std::cerr;

// @author: pashka

struct edge {
    int dst;
    int s;
};

int n;
vector<vector<edge>> g;
vector<int> z;
vector<long> d;

bool ok = true;
long X = -1;

void dfs(int x, int zz, long dd) {
    if (z[x] != 0) {
        if (z[x] == zz) {
            if (d[x] != dd) {
                ok = false;
            }
        } else {
            if ((dd - d[x]) % (z[x] - zz) != 0) {
                ok = false;
            } else {
                int XX = (dd - d[x]) / (z[x] - zz);
                if (XX < 0) {
                    ok = false;
                } else {
                    if (X != -1 && X != XX) {
                        ok = false;
                    } else {
                        X = XX;
                    }
                }
            }
        }
    } else {
        z[x] = zz;
        d[x] = dd;
        for (auto &e : g[x]) {
            dfs(e.dst, -z[x], e.s - d[x]);
        }
    }
}

//long max(long a, long b) {
//    return a > b ? a : b;
//}

int main() {
    std::ios::sync_with_stdio(false);

    int m;
    cin >> n >> m;
    g.resize(n);
    for (int i = 0; i < m; i++) {
        int u, v, s;
        cin >> u >> v >> s;
        u--;
        v--;
        g[u].push_back({v, s});
        g[v].push_back({u, s});
    }

    z.resize(n);
    d.resize(n);
    dfs(0, 1, 0);

    if (!ok) {
        cout << 0;
    } else if (X != -1) {
        for (int i = 0; i < n; i++) {
            if (z[i] * X + d[i] < 0) ok = false;
        }
        if (!ok) {
            cout << 0;
        } else {
            cout << 1;
        }
    } else {
        long l = 1;
        long r = MAX_LONG;
        for (int i = 0; i < n; i++) {
            if (z[i] > 0) {
                l = std::max(l, -d[i] / z[i] + 1);
            } else {
                r = std::min(r, -d[i] / z[i] - 1);
            }
        }
        int d = std::max(r - l + 1, 0ll);
        cout << d;
    }

    return 0;
}

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

using Segment = pair<int, int>; // (右端, 左端)

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

    vector<Segment> segments;
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;

        segments.emplace_back(b, a);
    }

    sort(segments.begin(), segments.end());
    int last = -1,
        ans  = 0;
    for (auto seg : segments) {
        if (seg.first <= last or seg.second < last) continue;
        last = seg.first;
        ans++;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define endl "\n"
#define ii pair<int, int>
#define fi first
#define se second
#define vi vector<int>
#define pb push_back
#define make_pair mp
#define MAX (int)1e5+5
#define INF (int)1e9
#define K 26
#define rep(i,a,b) for(int i = a; i<b; i++)
#define vi vector<int>



int32_t main() {
	int a,b,c,d;
	cin >> a >> b >> c >>d;
	int r1 = 0, r2 = 0;
	r1 = a/d;
	r2 = c/b;
	if(a%d != 0){
		r1++;
	}
	
	if(c%b != 0){
		r2++;
	}
	
	if(r1 >= r2){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	return 0;
}

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

int main() {
	int x,y,a,b;
	
	cin>>x>>y;
	if(x*2>y){
		cout<<"No"<<endl;
	}else{
		if(y%2==0){
			if(x*4>=y){
				cout<<"Yes"<<endl;
			}else{
				cout<<"No"<<endl;
			}
		}else{
			cout<<"No"<<endl;
		}
	}
	
	// your code goes here
	return 0;
}

Measured memory_bytes: 3636
n, T = [int(i) for i in input().split()]
t = [int(i) for i in input().split()]

# print(n, T, t)

sum = 0

for i in range(1,n):
    interval = t[i] - t[i-1]
    if interval < T:
        sum += interval
    else:
        sum += T

sum += T

print(sum)


Measured memory_bytes: 25200
#!/usr/bin/perl

use strict;
use warnings;

my ($a, $b);
{
    my $in = <STDIN>;
    ($a, $b) = split(" ", $in);
}
my $ans = $a * $b;

print "$ans\n" if $a<10 && $b<10;
print "-1\n" unless $a<10 && $b<10;

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

int main(){
	int A,B,x;
  cin>>A>>B;
  for(A;A<B+1;A++){
  	 if(A/10000==A%10&&A/1000%10==A%100/10) x++;
     }
  	  cout<<x;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int num[7], tp;

void roll(char ch){
    switch(ch){
        case 'E': tp = num[1]; num[1] = num[4]; num[4] = num[6]; num[6] = num[3]; num[3] = tp; break;
        case 'N': tp = num[1]; num[1] = num[2]; num[2] = num[6]; num[6] = num[5]; num[5] = tp; break;
        case 'S': tp = num[1]; num[1] = num[5]; num[5] = num[6]; num[6] = num[2]; num[2] = tp; break;
        case 'W': tp = num[1]; num[1] = num[3]; num[3] = num[6]; num[6] = num[4]; num[4] = tp; break;
        case 'R': tp = num[2]; num[2] = num[4]; num[4] = num[5]; num[5] = num[3]; num[3] = tp; break;
    }
}

int main(){
    for(int i = 1; i <= 6; ++i) cin >> num[i];
    int n;
    cin >> n;
    while(n--){
        int top,front;
        cin >> top >> front;
        if(num[4] == top) roll('E');
        if(num[3] == top) roll('W');
        while(num[1] != top) roll('S');
        while(num[2] != front) roll('R');
        cout << num[3] << endl;
    }
    return 0;
}



Measured memory_bytes: 3108
#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (ll i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define Rev(a) reverse(a.begin(), a.end())
#define MATHPI acos(-1)
#define itn int
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;
}
struct io
{
    io()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-19;






signed main() {
    int n;
    cin >> n;
    vll a(200005), b(200005);
    
    
    rrep(i, n) cin >> a[i];
    rep(i, n) cin >> b[n-i];

    bool success = true;

    
    for (int i = 1; i <= n && success; i++) {
        if (a[i] == b[i]) {
            for (int k = 1; k <= n && a[i] == b[i]; k++)
                if (b[k] != b[i] && a[k] != b[i]) {
                    swap(b[i], b[k]);
                    i++;
                }
            
            if (a[i] == b[i]) success = false;
        }
    }

    if (success) {
        mes("Yes");
        for (int i = 1; i <= n; i ++ ) cout << b[i] << " "; 
    } else mes("No");

}
    
    
    
    
    


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

using namespace std;

const int N = 2e5 + 5;

int main() {
  map<long long, int> mp;
  mp[0] = 1;
  int n;
  scanf("%d", &n);
  long long sum = 0;
  for (int i = 0; i < n; ++i) {
    int x;
    scanf("%d", &x);
    sum += x;
    ++mp[sum];
  }
  long long ans = 0;
  for (auto it : mp) {
    long long x = it.second;
    ans += x * (x - 1) / 2;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 12800
#include <iostream>
#include <string>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  int a[n];
  for(int i=0; i<n; i++) cin >> a[i];
  
  int res = 0;
  for(int i=0; i<n; i++){
    res += a[i] - 1;
  }
 
  cout << res << endl;
 
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
     
    using namespace std;
     
    #define DEBUG(x) cerr<<#x<<": "<<x<<endl;
    #define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
     
    typedef long long ll;
    #define vi vector<int>
    #define vl vector<ll>
    #define vii vector< vector<int> >
    #define vll vector< vector<ll> >
    #define vs vector<string>
    #define pii pair<int,int>
    #define pis pair<int,string>
    #define psi pair<string,int>
    #define pll pair<ll,ll>
    template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
    template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
    template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
    #define X first
    #define Y second
    #define rep(i,n) for(ll i=0;i<(ll)(n);i++)
    #define rep1(i,n) for(ll i=1;i<=(ll)(n);i++)
    #define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
    #define rrep1(i,n) for(ll i=(ll)(n);i>0;i--)
    #define REP(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
    #define in(x, a, b) (a <= x && x < b)
    #define all(c) c.begin(),c.end()
    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; }
    #define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
    const ll inf = 1000000001;
    const ll INF = 1e18;
    const ll MOD = 1000000007;
    const double pi = 3.14159265358979323846;
    #define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
    int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
    int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
    #define fio() cin.tie(0); ios::sync_with_stdio(false);
    #define mp make_pair
     
    int main() {
      ll n, k;
      cin >> n >> k;
      if (k % 2 == 1) {
        cout << (n / k) * (n / k) * (n / k) << endl;
      }
      else {
        ll ans = (n / k) * (n / k) * (n / k);
        ll num = (n / (k / 2)) - (n / k);
        ans += num*num*num;
        cout << ans << endl;
      }
    }

Measured memory_bytes: 256
from collections import Counter

def main():
	n = int(input())
	w = input().split()
	a = Counter(w[::2]).most_common(2)
	b = Counter(w[1::2]).most_common(2)
	if a[0][0]!=b[0][0]:
		stay = a[0][1] + b[0][1]
	elif a[0][1]==b[0][1]==n // 2:
		stay = n // 2
	else:
		stay = max(a[0][1] + b[1][1], a[1][1] + b[0][1])
	print(n - stay)

if __name__=="__main__":
	main()

Measured memory_bytes: 16232
char s[4005],t[4005];
u[4005],m,i,j,c;
main(n){
	for(;~scanf("%s%s",s,t+1);i=m=!printf("%d\n",m)){
		for(n=strlen(s);!i|t[i];i++)
			for(j=n;j--;m<c?m=c:0)
				u[j+1]=c=s[j]-t[i]?0:u[j]+1;
	}
}

Measured memory_bytes: 432
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 10e16
#define MOD 1000000007
#define mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//--------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????        memset()!!!!!!!!!!!!       ペナを減らせ!!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    ll n;cin>>n;
    vector<ll>a(n);
    for(ll i=0;i<n;i++)cin>>a[i];
    sort(all(a));
    ll b=a[n-1];
    ll t=INF;
    ll ci=0;
    for(ll i=0;i<n;i++){
        ll tmp=abs(a[i]-(b+1)/2);
        if(tmp<t){
            t=tmp;
            ci=i;
        }
    }
    ll c=a[ci];
    cout<<b<<" "<<c<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------




Measured memory_bytes: 1024
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define pb            push_back
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())

// code
// ------------------------------------------------
int main() {

  int a,b,c,d;cin >> a >> b >> c >> d;
  
  int s,t;
  s = a > b ? b : a;
  t = c > d ? d : c;
  
  cout << s + t << endl;
  
  return 0;
}

// funcの実体
// ------------------------------------------------
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1000000010
#define N 1010
char getc(){char c=getchar();while (c!='#'&&c!='.') c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
	int x=0,f=1;char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x*f;
}
int n,m,a[N][N],f[4][N][N],ans;
signed main()
{
	n=read(),m=read();
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++)
		{
			char c=getc();
			if (c=='.') a[i][j]=0;
			else a[i][j]=1;
		}
	memset(f,200,sizeof(f));
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++)
		if (a[i][j]) f[0][i][j]=i+j;
		else f[0][i][j]=max(f[0][i-1][j],f[0][i][j-1]);
	for (int i=n;i>=1;i--)
		for (int j=1;j<=m;j++)
		if (a[i][j]) f[1][i][j]=j-i;
		else f[1][i][j]=max(f[1][i+1][j],f[1][i][j-1]);
	for (int i=1;i<=n;i++)
		for (int j=m;j>=1;j--)
		if (a[i][j]) f[2][i][j]=i-j;
		else f[2][i][j]=max(f[2][i-1][j],f[2][i][j+1]);
	for (int i=n;i>=1;i--)
		for (int j=m;j>=1;j--)
		if (a[i][j]) f[3][i][j]=-i-j;
		else f[3][i][j]=max(f[3][i+1][j],f[3][i][j+1]);
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++)
		ans=max(ans,min(min(i+j-f[0][i][j],j-i-f[1][i][j]),min(i-j-f[2][i][j],(-i-j)-f[3][i][j])));
	cout<<ans;
	return 0;
	//NOTICE LONG LONG!!!!!
} 


Measured memory_bytes: 20096
X,Y=map(int, input().split())
flag=0

if Y>=4:
	for i in range(0,Y//4+1):
		if (X-i)*2+4*i==Y:
			flag=1
			break

else:
	if X==1 and Y==2:
		flag=1


print("Yes" if flag==1 else "No")

Measured memory_bytes: 9128