akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

class Solution {
public:
    void init(int n, long long L, vector<vector<int>>& edges) {
        N = n;
        graph.clear();
        graph.resize(n);
        
        for (auto& e : edges) {
            int u = e[0], v = e[1], c = e[2];
            graph[u].emplace_back(v, c);
            graph[v].emplace_back(u, c);
        }

        const long long INF = 1LL << 50;
        vector<vector<long long>> D(n, vector<long long>(n, INF));
        for (int i = 0; i < n; ++i) {
            D[i][i] = 0;
            for (auto& e : graph[i]) {
                int j = e.first;
                int c = e.second;
                D[i][j] = c;
            }
        }

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

        dis.clear();
        dis.resize(n, vector<int>(n, 1 << 24));
        for (int i = 0; i < n; ++i) {
            dis[i][i] = 0;
            for (int j = 0; j < n; ++j) {
                if (j != i) {
                    if (D[i][j] <= L) {
                        dis[i][j] = 1;
                    }
                }
            }
        }

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

    int query(int s, int t) {
        int res = dis[s][t];
        --res;
        if (res > N) {
            return -1;
        }
        return res;
    }

private:
    int N;
    vector<vector<pair<int,int>>> graph;
    vector<vector<int>> dis;
};

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    int m;
    long long L;
    cin >> n >> m >> L;
    vector<vector<int>> edges;
    for (int i = 0; i < m; ++i) {
        int u, v, c;
        cin >> u >> v >> c;
        --u, --v;
        edges.emplace_back(vector<int>{u, v, c});
    }

    Solution sol;
    sol.init(n, L, edges);

    int q;
    cin >> q;
    while (q-- > 0) {
        int s, t;
        cin >> s >> t;
        --s, --t;
        cout << sol.query(s, t) << "\n";
    }

    return 0;
}

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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  string S; cin >> S;
  int N = SZ(S);
  int i, f = 0;
  for(i=0;i<N;){
	if(i+6 <= N && S.substr(i,6) == "eraser")
	  i += 6, f = 0;
	else if(i+5 <= N && S.substr(i,5) == "erase")
	  i += 5, f = 0;
	else if(i+5 <= N && S.substr(i,5) == "dream")
	  i += 5, f = 1;
	else if(f && i+2 <= N && S.substr(i,2) == "er")
	  i += 2, f = 0;
	else
	  break;
  }

  cout << (i==N? "YES": "NO") << endl;

  return 0;
}


Measured memory_bytes: 512
S = list(input())
N = len(S)
S_mae = S[:int((N-1)/2)]
S_usi = S[int((N+1)/2):]

if (S_mae[:len(S_mae)] == S_mae[::-1]) and (S_usi[:len(S_usi)] == S_usi[::-1]) and (S == S[::-1]):
    print("Yes")
else:
    print("No")
    
#print(S_mae)
#print(S_usi)



Measured memory_bytes: 3060
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

int main() {
    int N;
    cin >> N;
    string P = "", Q = "";
    REP(i, N) {
        string s;
        cin >> s;
        P = P + s;
    }
    REP(i, N) {
        string s;
        cin >> s;
        Q = Q + s;
    }
    set<string> order;
    vector<int> nums(N);
    REP(i, N) nums[i] = i+1;
    do {
        string tmp = "";
        for(int i: nums)
            tmp = tmp + to_string(i);
        order.insert(tmp);
    } while (next_permutation(nums.begin(), nums.end()));

    int a = -1, b = -1, idx = 0;
    for(string s: order) {
        if(s == P) a = idx;
        if(s == Q) b = idx;
        idx++;
    }
    cout << abs(a - b) << endl;
    return 0;
}

Measured memory_bytes: 3968
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    const ll mod=1e9+7;
    int n,k;
    cin>>n>>k;
    ll ans=0;
    vector<ll>a;
    a.push_back(0);
    for(int i=1; i<=n; ++i){
        a.push_back(a[i-1]+i);
    }
    for(int i=k; i<=n; ++i){
        ll mx=a[n]-a[n-i];
        ll mn=a[i-1];
        ans+=(mx-mn+1)%mod;
        ans%=mod;
    }
    ans++;
    cout<<ans<<endl;
}


Measured memory_bytes: 5364
#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>

using namespace std;

typedef long long ll;
const int maxn = 105;

char str[maxn][maxn];
int cnt[maxn];

int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++){
		scanf("%s",str[i]);
	}
	memset(cnt,0,sizeof(cnt));
	for(int i=0;i<n;i++)
		for(int j=0;j<m;j++){
			cnt[str[i][j]-'a']++;
	}
	bool flag=true;
	if(n==1||m==1){
		if(n==1&&m==1){
			flag=true;		
		}
		else{
		 if(n>m) swap(n,m);
		 	int left=(m&1)?1:0;
		 	for(int i=0;i<26;i++){
		 		if(cnt[i]&1) left--; 
			 }
			 if(left>=0) flag=true;
			 else flag=false;
		}
	}else{
		if(n%2==0&&m%2==0){
			for(int i=0;i<26;i++){
				if(cnt[i]%4) flag=false;
			}
		}else if(n%2==0||m%2==0){
			if(m&1) swap(n,m);
			int left=m;
			for(int i=0;i<26;i++){
				if(cnt[i]%4==1||cnt[i]%4==3){
					flag=false;
				}else if(cnt[i]%4==2){
					left-=2;
				}
			}
			if(left<0) flag=false;
		}else {
			int left1 = 1;
			int left2 = n+m-1;
			for(int i=0;i<26;i++){
				if(cnt[i]%4==1||cnt[i]%4==3) {
					left1--;
					if(cnt[i]%4==3) left2-=2;
				}else if(cnt[i]%4==2){
					left2-=2;
				}
			}
			if(left1<0) flag=false;
			if(left2<0) flag=false;
		}
	}
	if(flag) printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int Maxn=3e5+10;
int N;
int A[Maxn];
int Pre[Maxn],Suf[Maxn];
multiset<int> M,V;
int Ans=-1e18;
signed main()
{
	scanf("%d",&N);
	int X=3*N; 
	for(int i=1;i<=X;i++) scanf("%d",A+i);
	for(int i=1;i<=N;i++) M.insert(A[i]),Pre[N]+=A[i];
	for(int i=N+1;i<=X;i++)
		if(A[i]>*M.begin())
		{
			int tmp=A[i]-*M.begin();
			M.erase(M.begin());
			M.insert(A[i]);
			Pre[i]=Pre[i-1]+tmp; 
		}
		else Pre[i]=Pre[i-1];
	int X2=2*N+1;
	for(int i=X2;i<=X;i++) V.insert(A[i]),Suf[X2]+=A[i];
	for(int i=X2-1;i>=1;i--)
	{
		if(A[i]<*V.rbegin())
		{
			int tmp=*V.rbegin()-A[i];
			multiset<int>::iterator it=V.end();
			--it;
			V.erase(it);
			V.insert(A[i]);
			Suf[i]=Suf[i+1]-tmp;
		}
		else Suf[i]=Suf[i+1];
	}
	int X3=2*N;
	for(int i=N;i<=X3;i++) Ans=max(Ans,Pre[i]-Suf[i+1]);
	cout<<Ans<<endl;
	return 0;
}

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

int main(void) {
    int n;
    cin >> n;
    vector<int> member(n-1);
    vector<int> supervise(n, 0);
    for (int i=0; i<n-1; i++) {
        cin >> member.at(i);
        supervise.at(member.at(i)-1)++;
    }
    for (int i=0; i<n; i++) {
        cout << supervise.at(i) << endl;
    }
}

Measured memory_bytes: 4780
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


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

    vbool d(4, false);
    rep(i, s.length()) {
        if (s[i] == 'N') d[0] = true;
        if (s[i] == 'W') d[1] = true;
        if (s[i] == 'S') d[2] = true;
        if (s[i] == 'E') d[3] = true;
    }

    int e = 0;
    rep(i, 4) e += d[i] << i;

    yns(e%5 == 0);
    return 0;
}

Measured memory_bytes: 256
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline



def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [int(input_raw[0])]
    input_raw = read_func().strip().split()
    A = [int(input_raw[i]) for i in range(N)]
    sortA = sorted(A)

    inv = 0
    for i in range(N):
        if sortA[i] != A[i]:
            inv += 1
    if inv <= 2:
        print "YES"
    else:
        print "NO"

if __name__ == '__main__':
    main()


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

    using namespace std;
    int main(){
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        string s;
        cin>>s;
        for(int i=0;i<3;i++){
            if(s[i]=='7'){
                cout<<"Yes";
                return 0;
            }
        }
        cout<<"No";
        return 0;
    }


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;

int main()
{
    double w=0.0, h=0.0, x=0.0, y=0.0;
    cin >> w >> h >> x >> y;

    cout << fixed << setprecision(6) << (w*h)/2 << " ";
    if(x==w/2&&y==h/2){
        cout << 1 << endl;
    }else{
        cout << 0 << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n;
struct ii{
    int x,y;
};
ii p[1000005];
bool ss(ii p1,ii p2)
{
    return (p1.y<p2.y||(p1.y==p2.y&&p1.x<p2.x));
}
bool ccw(ii p1,ii p2,ii p3)
{
    int x1=p1.x-p2.x,y1=p1.y-p2.y;
    int x2=p3.x-p2.x,y2=p3.y-p2.y;
    int kq=x1*y2-x2*y1;
    if (kq>=0) return true;
    return false;
}
void nhap()
{
    scanf("%d",&n);
    for (int i=1;i<=n;i++){
        scanf("%d %d",&p[i].x,&p[i].y);
    }
}
void baoloi()
{
    vector <ii> up,down;
    sort (p+1,p+1+n,ss);
    up.push_back(p[1]);up.push_back(p[2]);
    down.push_back(p[n]);down.push_back(p[n-1]);
    for (int i=3;i<=n;i++){
        while (up.size()>1&&ccw(up[up.size()-2],up[up.size()-1],p[i])==false) up.pop_back();
        up.push_back(p[i]);
    }
    for (int i=n-2;i>=1;i--){
        while (down.size()>1&&ccw(down[down.size()-2],down[down.size()-1],p[i])==false) down.pop_back();
        down.push_back(p[i]);
    }
    printf("%d\n",down.size()+up.size()-2);
    for (int i=down.size()-1;i>=0;i--) printf("%d %d\n",down[i].x,down[i].y);
    for (int i=up.size()-2;i>=1;i--) printf("%d %d\n",up[i].x,up[i].y);

}
int main()
{
    nhap();
    baoloi();
}



Measured memory_bytes: 4492
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 100100;
int par[N];
ll ans;
multiset<ll>s[N];
set<pair<ll,int>>all;
set<pair<int,int>>sz;
int n , m ;

int get(int i){
if( par[i]==i )return par[i];
par[i]=get(par[i]);
return par[i];
}
bool same(int i,int j){ return get(i)==get(j); }
void join(int i,int j){
i=get(i);
j=get(j);
if( i == j )return;
if( s[i].size() < s[j].size() )swap(i,j);
    par[j]=par[i];
    for(auto x:s[j])s[i].insert(x);
    s[j].clear();
}

int main(){

scanf("%d %d",&n,&m);

for(int i=0;i<n;i++)par[i]=i;

for(int i=0;i<n;i++){
    ll x;
    scanf("%lld",&x);
    s[i].insert(x);
    all.insert( {x,i} );
}

while( m-- ){
    int u , v ;
    scanf("%d %d",&u,&v);

    u=get(u);
    all.erase( { *s[u].begin(),u } );

    v=get(v);
    all.erase( { *s[v].begin(),v } );

    join(u,v);

    u=get(u);
    all.insert({ *s[u].begin(),u } );
}

for(int i=0;i<n;i++)sz.insert( { s[get(i)].size(),get(i) } );

while( all.size()>1 ){

    int u = (--sz.end())->second;
            all.erase({*s[u].begin(),u});

    int v = all.begin()->second;
            all.erase(all.begin());
    v=get(v);

    ans+=*s[u].begin();
    sz.erase({s[u].size(),u});
    s[u].erase(s[u].begin());

    ans+=*s[v].begin();
    sz.erase({s[v].size(),v});
    s[v].erase(s[v].begin());

    join(u,v);
    u = get(u);

    if( s[u].size() )
    all.insert({*s[u].begin(),u}),sz.insert({s[u].size(),u});
}


for(int i=1;i<n;i++)
if( !same(0,i) ){
    printf("Impossible\n");
    return 0;
}

printf("%lld\n",ans);
return 0;
}


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

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;
}
const long long INF=1LL<<60;

int N; 
long long W;
long long weight[110];
long long value[110];
long long dp[110][100010]={0};

int main(){
  cin >> N >> W;
  for(int i=0;i<N;i++) cin >> weight[i] >> value[i];

  for(int i=0;i<N;i++){
    for(int sum_w=0;sum_w<=W;++sum_w){
      if(sum_w-weight[i]>=0){
        chmax(dp[i+1][sum_w],dp[i][sum_w-weight[i]]+value[i]);
      }
      chmax(dp[i+1][sum_w],dp[i][sum_w]);
    }
  }
  cout << dp[N][W] <<endl;
}


Measured memory_bytes: 79360
#include<bits/stdc++.h>
#define maxn 0x3f3f3f3f
using namespace std;
typedef long long ll;
int main()
{
	std::ios::sync_with_stdio(false);
	int a;
	int b;
	cin>>a>>b;
	int s1=2*a;
	int s2=4*a;
	if(b<s1||b>s2)
	{
		cout<<"No";
		return 0;
	}
	if(b%2!=0)
	{
		cout<<"No";
		return 0; 
	} 
	int c=b/2;
	if(c<a) 
	{
		cout<<"No";
		return 0;
	}
	int y=c-a;
	int x=2*a-c;
	if(x+y==a&&2*x+4*y==b) cout<<"Yes";
	else cout<<"No";
	return 0; 
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)



int main(){
	int q,c,x;
	string key,L,R;
	cin >> q;
	map<string,int> ma;
	while(q--){
		cin >> c >> key;
		if(c==1){
			cout << ma[key] << "\n";
		}else if(c==0){
			cin >> x;
			ma[key] = x;
		}else if(c==2){
			//ma[key] = 0;
			ma.erase(key);
		}else if(c==3){
			L = key;
			cin >> R;
			auto it = ma.lower_bound(L);
			auto end = ma.upper_bound(R);
			for(;it!=end;it++){
				if((*it).second)cout << (*it).first << " " << (*it).second << "\n";
			}
		}
	}
}


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

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

	map<int, int> ball;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		ball[a]++;
	}

	vector<int> ball_num(ball.size());
	int i = 0;
	for(auto x : ball) {
		ball_num[i] = x.second;
		i++;
	}
	sort(ball_num.begin(), ball_num.end());

	int sum = 0;
	for (int i = 0; i < (int)ball_num.size() - k; i++) {
		sum += ball_num[i];
	}

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


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using ll = long long;
int mod = 1000000000+7;

int main(){

	int n;
	cin>>n;
	int a[n];
	int z[1000*1000+1]={};
	rep(i,n){
		cin>>a[i];
		z[a[i]]++;
	}

	if(z[1]==1){
		cout<<1<<endl;
		return 0;
	}
	else if(z[1]>1){
		cout<<0<<endl;
		return 0;
	}

	for(int i=2;i<=1000*1000;i++){
		if(z[i]==0)continue;
		else if(z[i]>=1){
			if(z[i]!=1)z[i]=0;
			int k=2;
			while(k*i<=1000*1000){
				z[i*k]=0;
				k++;
			}
		}
	}
	
	int ans=0;
	for(int i=0;i<=1000*1000;i++)ans+=z[i];
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 8320
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		
		int X = scan.nextInt();
		int A = scan.nextInt();
		
		if (X < A) {
			System.out.println(0);
		} else {
			System.out.println(10);
		}
		
		scan.close();
	}

}


Measured memory_bytes: 21204
N,M = map(int,input().split())
if N >= 2 and M >= 2:
    print(int((N*(N-1)/2)+M*(M-1)/2))
elif N < 2 and M >= 2:
    print(int(M*(M-1)/2))
elif N >= 2 and M < 2:
    print(int(N*(N-1)/2))
else:
    print(0)           

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vi;
typedef vector<bool> vb;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define sq(x) ((x)*(x))
#define fo(i,n) for(int i=0;i<n;i++)
#define fp(i,k,n) for(int i=k;i<n;i++)
#define Fo(i,n) for(int i=1;i<=n;i++)
#define all(x) x.begin(),x.end()
#define deb(x) cout<<#x<<"="<<x<<"\n"
#define deb2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<"\n"
#define fi first
#define se second
const double pi = 3.14159265358979323846;
#define uni(c) (c).resize(unique(all(c))-(c).begin())
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL)
//pair <int, int> w[4] = {mp(-1, 0), mp(0, -1), mp(1, 0), mp(0, 1)};   // for matrix movement:
void cp()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE
}
void solve()
{

	ll n, k; cin >> n;
	ll a[n];
	map<ll, ll> have;
	ll sum = 0;
	fo(i, n)
	{
		cin >> a[i];
		sum += a[i];
		have[a[i]]++;
	}
	ll q; cin >> q;
	while (q--)
	{
		ll x, y; cin >> x >> y;
		if (have.count(x))
		{
			sum -= x * have[x];
			sum += y * have[x];
			have[y] += have[x];
			have.erase(x);
		}
		cout << sum << "\n";
	}


}
int main()
{
	fast;
	//cp();
	ll t = 1;
	//cin >> t;
	while (t--)
		solve();


	return 0;
}

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

using namespace std;

vector<int> dp(100005, 0);
vector<bool> vis(100005, false);
vector<vector<int>> g(100005);
int mx = 0;
int n, m;
void dfs(int node) {
    vis[node] = true;
    for(int i=0;i<g[node].size();i++){
        if(!vis[g[node][i]]){
            dfs(g[node][i]);
        }
        dp[node] = max(dp[node], 1 + dp[g[node][i]]);
    }
}

int main() {
    cin>>n>>m;
    int x, y;
    for(int i=0;i<m;i++) {
        cin>>x>>y;
        g[x-1].push_back(y-1);
    }
    for(int i=0;i<n;i++){
        if(!vis[i]) {
            dfs(i);
        }
    }
    cout<<*max_element(dp.begin(), dp.begin()+n+1)<<endl;
}


Measured memory_bytes: 8192
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main () {
    long long A, B, X ;
    X = -1 ;
    scanf ( "%lld %lld", &A, &B ) ;
    if ( A != 0 && B != 0 && A % B != 0 ) {
        X = A ;
    }
    printf ( "%lld\n", X ) ;
    return 0 ;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;
#define ll long long
#define pb push_back

int main()
{
    int n;
    vector<int> x;
    while (1)
    {
        cin >> n;
        if (n == 0)
        {
            break;
        }
        int min = 1000000;
        vector<int> a(n);
        for(int i=0; i<n;i++){
            cin >> a[i];
        }
        sort(a.begin(),a.end());
        for(int i=0; i<n-1;i++){
            int diff = abs(a[i] - a[i+1]);
            if(diff < min){
                min = diff;
            }
        }
        x.push_back(min);
    }
    for (int i = 0; i < x.size(); i++)
    {
        cout << x[i] << endl;
    }
}



Measured memory_bytes: 3120
N = int(input())
data = [int(i) for i in input().split()]
Q = int(input())

array = dict()
for i in data:
  if i in array:
    array[i] += 1
  else:
    array[i] = 1
    
total = 0
for i, j in array.items():
  total += i*j
  
for i in range(Q):
  dt = 0
  quary = [int(i) for i in input().split()]
  if quary[0] not in array:
    pass
  elif quary[1] in array:
    dt = (quary[1]-quary[0])*array[quary[0]]
    array[quary[1]] += array[quary[0]]
    del array[quary[0]]
  else:
    dt = (quary[1]-quary[0])*array[quary[0]]
    array[quary[1]] = array[quary[0]]
    del array[quary[0]]
  
  total += dt
  print(total)

Measured memory_bytes: 21280
#include<bits/stdc++.h>
#define gc getchar()
#define ll long long
#define pb push_back
#define mk make_pair
#define rint register int
#define debug(x) cerr<<#x<<"="<<x<<"\n"
#define pa pair<int,int>
#define fir first
#define sec second
using namespace std;
const int mod = 1e9+7;
inline int read(){int w=1,s=0;char ch=getchar();while(!isdigit(ch)){if(ch=='-')w=-1;ch=getchar();}while(isdigit(ch)){s=s*10+ch-'0';ch=getchar();}return  w*s;}
int n,H,D;
int Sum[1101000],f[1010100];
inline ll ksm(ll x,ll y){ll res=1;while(y){if(y&1) res=res*x%mod;x=x*x%mod;y>>=1;} return res;}
inline int pls(int a,int b){a+=b;return a>=mod?a-mod:a;}
inline int mns(int a,int b){a-=b;return a<0?a+mod:a;}
inline int get(int x,int y){
	if(x==0) return Sum[y];
	else return mns(Sum[y],Sum[x-1]);
}
int main()
{	
	n=read(),H=read(),D=read();
	int S,cur;
	S=cur=1;
	for(rint i=2;i<=n;++i) {
		cur=1ll*cur*i%mod;
		S=pls(S,cur);
	}
	Sum[0]=1;
	for(rint i=1;i<=H;++i) {
		Sum[i]=Sum[i-1];
		f[i]=get(max(i-D,0),i);
		Sum[i]=pls(Sum[i],1ll*f[i]*S%mod);
	}
	for(rint i=1;i<=n;++i) f[H]=1ll*f[H]*i%mod;
	cout<<f[H]<<"\n";
	return 0;
}	

Measured memory_bytes: 8448
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    for(int i = 1; i<= 9; ++i)
    {
        if(n%i == 0)
        {
            if(n / i <= 9)
            {
                cout << "Yes";
                return 0;
            }
        }
    }
    cout <<"No";
    


    return 0;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<char> c(m);
  rep(i,m) {
    cin >> s[i] >> c[i];
  }
  rep(i,1005) {
    string a = to_string(i);
    if(a.size() != n) continue;
    int j = 0;
    while(j < m) {
      if(a[s[j]-1] != c[j]) break;
      j++;
    }
    if(j != m) continue;
    cout << a << endl;
    return 0;
  }
  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 3684
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <cmath>
#include <utility> // pair make_pair
#include <algorithm>
#include <functional>
#include <iomanip>
#include <climits> // LLONG_MAX, LLONG_MIN, INT_MIN, INT_MAX
#include <assert.h>

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define ll long long
//#define int ll
#define INF INT_MAX/10
#define MOD 1000000007

using namespace std;
using Pi = pair<int, int>;
using Graph = vector<vector<int> >;
using WeightGraph = vector<vector<Pi> >;

int Input[100100];

int main() {
  memset(Input, 0, sizeof(Input));
  
  int N, K, Q; cin >> N >> K >> Q;
  for (int i = 0; i < Q; i++) {
    int a; cin >> a; a--;
    Input[a]++;
  }

  for (int i = 0; i < N; i++) {
    if (K <= Q - Input[i]) {
      cout << "No" << endl;
    } else {
      cout << "Yes" << endl;
    }
  }
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int N,K,S; cin>>N>>K>>S;
	int x=S, y=x-1;
	if(y==0) y=x+1;
	for (int i=0; i<N; i++) {
		if(i) cout<<" ";
		if(K>0) K--, cout<<x;
		else cout<<y;
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 1280
#include <cstdio>
#include <vector>
#include <stack>
#include <iostream>
#include <string>
#include <tuple>
#include <random>
#include <map>
#include <queue>
#include <set>
#include <complex>
#include <algorithm>
#include <cassert>
#include <iterator>
#include <numeric>
#include <cmath>
#include <stdio.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

const double eps = 1e-8;

const ll INF = 1e15;
const ll MOD = 1e9 + 7;

int main() {
	ll N;
	cin >> N;
	vector<ll> A(N);
	map<ll, ll> num;
	for (int i = 0;i < N;i++) {
		cin >> A[i];
		if (num.find(A[i]) == num.end())
			num[A[i]] = 1;
		else
			num[A[i]]++;
	}
	sort(A.begin(), A.end());
	ll answer = 0;
	for (int i = N - 1;i >= 0;i--) {
		if (num.find(A[i]) == num.end())
			continue;
		if (num[A[i]] == 0)
			continue;
		num[A[i]]--;
		ll target = 1;
		while (target <= A[i])
			target *= 2;
		ll to = target - A[i];
		if (num.find(to) == num.end())
			continue;
		if (num[to] > 0) {
			answer++;
			num[to]--;
		}
	}
	cout << answer << endl;
	return 0;
}


Measured memory_bytes: 14968
#include <iostream>

using namespace std;

int main(){

    int d;
    cin >> d;

    int h, m, s;

    h = d / 3600;
    m = (d % 3600) / 60;
    s = (d % 3600) % 60;
    cout << h << ":" << m << ":" <<  s << endl;

    return 0;
}



Measured memory_bytes: 3116
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define FOR(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v),end(v)
#define debug(x) std::cerr<<#x<<": "<<x<<"\n"
#define debug2(x,y) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<"\n"
#define debug3(x,y,z) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<", "<<#z<<": "<<z<<"\n"

typedef long long ll;
typedef std::vector<int> vi;
typedef std::vector<vi> vvi;
typedef std::vector<ll> vll;
typedef std::vector<vll> vvll;
template<typename T> using vvec=std::vector<std::vector<T>>;
template<typename T>
auto make_v(size_t sz){return std::vector<T>(sz);}
template<typename T,typename... Ts>
auto make_v(size_t sz,Ts...ts){return std::vector<decltype(make_v<T>(ts...))>(sz,make_v<T>(ts...));}
template<typename T>
void fill_v(T&var,const T&x){var=x;}
template<typename V,typename T>
void fill_v(V&v,const T&x){for(auto&& w:v){fill_v(w,x);}}

template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<std::vector<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<std::deque<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s, const std::set<T>&v){
  s<<"\n";for(auto&& elm:v){s<<elm<<"\t";}s<<"\n";return s;}

inline void scan(int&a){scanf("%d",&a);}
inline void scan(ll&a){scanf("%lld",&a);}
inline void scan(char&a){scanf(" %c",&a);}
inline void scan(double&a){scanf("%lf",&a);}
template<typename T>
inline void scan(std::vector<T>&v){for(auto&& sv:v){scan(sv);}}
template<typename First,typename...Args>
inline void scan(First&f,Args&...args){scan(f);scan(args...);}
inline void scan(std::string&s){char BUF[3000000];scanf(" %s",BUF);s=std::string(BUF);}
inline void print(int a){printf("%d\n",a);}
inline void print(ll a){printf("%lld\n",a);}
inline void print(double a){printf("%.12f\n",a);}
inline void print(std::string s){std::cout<<s<<"\n";}

using namespace std;

int main() {
  int n;
  scan(n);
  string a, b, c;
  scan(a);
  scan(b);
  scan(c);
  int ans = 0;
  rep (i, n) {
    if (a[i] == b[i] && b[i] == c[i]) {
    } else if (a[i] == b[i] || b[i] == c[i] || c[i] == a[i]) {
      ans += 1;
    } else {
      ans += 2;
    }
  }
  print(ans);

  return 0;
}


Measured memory_bytes: 760
#include <algorithm>

namespace rika
{
  template <typename T>
  class edge
  {
  public:
    int to;
    T cost;
    
    edge() = default;
    edge(const edge<T>&) = default;
    edge(edge<T>&&) = default;
    edge& operator =(const edge<T>&) = default;
    edge& operator =(edge<T>&&) = default;

    ~edge() = default;

    edge(int _to, T _cost) : to(_to), cost(_cost) {}
  };
}

#include<bits/stdc++.h>

using namespace std;
using namespace rika;
namespace rika
{
  namespace internal
  {
    template <typename TValue, typename TGraph>
    std::pair<TValue, int> visit(int from, int v, const TGraph &g)
    {
      auto r = std::make_pair(TValue(), v);
try{
      for(auto it = g[v].begin(); it != g[v].end(); ++it)
      {
        if(it->to == from)
          continue;
        auto r2 = visit<TValue>(v, it->to, g);
        if(r2.first + it->cost >= r.first)
          r = std::make_pair(r2.first + it->cost, r2.second);
      }
}catch(const std::out_of_range &e){}
      return r;
    }
  }

  template <typename TValue, typename TGraph>
  TValue tree_diameter(const TGraph &g)
  {
    using namespace internal;
    auto r1 = visit<TValue>(-1, 0, g);
    auto r2 = visit<TValue>(-1, r1.second, g);
    return r2.first;
  }
}

int main()
{
  int N;
  cin >> N;
  vector<vector<edge<int>>> g(N * 10);
  for(int i = 0; i < N - 1; i++)
  {
    int s, t, w;
    cin >> s >> t >> w;
    g[s].push_back(edge<int>(t, w));
    g[t].push_back(edge<int>(s, w));
  }
  cout << tree_diameter<int>(g) << endl;
}

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

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	long long n;
	cin>>n;
	long long sum=0;
	sum+=((n/500)*1000);
	n%=500;
	sum+=((n/5)*5);
	cout<<sum;
	return 0;
 } 


Measured memory_bytes: 256
#include<iostream>
using namespace std;
#include<vector>
int W,H;
int nb,nw;
int n,flag=1,flag2;
char field[50][50];
#define W_MAX 50
#define H_MAX 50
#define Black true
#define White false
/*-------------------------
const int dx[]={-1,0,1,0};
const int dy[]={0,-1,0,1};
--------------------------*/
int umerub(int x,int y){
	n++;
	field[y][x]='X';

	if(y!=0&&field[y-1][x]=='.')umerub(x,y-1);
	if(x!=0&&field[y][x-1]=='.')umerub(x-1,y);
	if(y!=H-1&&field[y+1][x]=='.')umerub(x,y+1);
	if(x!=W-1&&field[y][x+1]=='.')umerub(x+1,y);
	if(y!=0&&field[y-1][x]=='W')flag=0;
	if(x!=0&&field[y][x-1]=='W')flag=0;
	if(y!=H-1&&field[y+1][x]=='W')flag=0;
	if(x!=W-1&&field[y][x+1]=='W')flag=0;
	if(y!=0&&field[y-1][x]=='B')flag2=1;
	if(x!=0&&field[y][x-1]=='B')flag2=1;
	if(y!=H-1&&field[y+1][x]=='B')flag2=1;
	if(x!=W-1&&field[y][x+1]=='B')flag2=1;
	return n;
}

int umeruw(int x,int y){
	n++;
	field[y][x]='F';
	if(y!=0&&field[y-1][x]=='X')umeruw(x,y-1);
	if(x!=0&&field[y][x-1]=='X')umeruw(x-1,y);
	if(y!=H-1&&field[y+1][x]=='X')umeruw(x,y+1);
	if(x!=W-1&&field[y][x+1]=='X')umeruw(x+1,y);
	if(y!=0&&field[y-1][x]=='B')flag=0;
	if(x!=0&&field[y][x-1]=='B')flag=0;
	if(y!=H-1&&field[y+1][x]=='B')flag=0;
	if(x!=W-1&&field[y][x+1]=='B')flag=0;
	if(y!=0&&field[y-1][x]=='W')flag2=1;
	if(x!=0&&field[y][x-1]=='W')flag2=1;
	if(y!=H-1&&field[y+1][x]=='W')flag2=1;
	if(x!=W-1&&field[y][x+1]=='W')flag2=1;
	return n;
}

int main(){
	while(cin>>W>>H,W|H){
		nb=0;
		nw=0;
		n=0;
		flag=1;
		flag2=0;
		for(int i=0;i<50;i++){
			for(int j=0;j<50;j++){
				field[i][j]=0;
			}
		}
		for(int i=0;i<H;i++){
			cin>>field[i];
		}
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				if(field[i][j]=='.'){
					nb+=umerub(j,i)*flag*flag2;
					flag=1;
					flag2=0;
					n=0;
					nw+=umeruw(j,i)*flag*flag2;
					flag=1;
					flag2=0;
					n=0;
					/*cout<<endl;
					for(int k=0;k<H;k++){
			cout<<field[k]<<endl;
					}
					cout<<nb<<" "<<nw<<endl;*/
				}
			}
		}
		cout<<nb<<" "<<nw<<endl;
	}
	return 0;
}

Measured memory_bytes: 1284
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    int x[n],y[n],z[n],h;
    bool ans;
    for(int i=0;i<n;i++){
        cin>>x[i]>>y[i]>>z[i];
    }

    for(int i=0;i<=100;i++){
        for(int j=0;j<=100;j++){
            for(int k=0;k<n;k++){
                if(z[k]){
                    h=abs(x[k]-j)+abs(y[k]-i)+z[k];
                }
            }
            for(int k=0;k<n;k++){
                if(z[k]==max(h-abs(x[k]-j)-abs(y[k]-i),0)){
                    ans=true;
                }
                else{
                    ans=false;
                    k=n;
                }
            }
            if(ans==true){
                cout << j<<" "<<i<<" "<<h<<endl;
                return 0;
            }
        }
    }

    bool num[101][101];
    for(int i=0;i<=100;i++){
        for(int j=0;j<=100;j++){
            num[i][j]=false;
        }
    }

    for(int i=0;i<n;i++){
        num[y[i]][x[i]]=true;
    }
    for(int i=0;i<=100;i++){
        for(int j=0;j<=100;j++){
            if(num[i][j]==false){
                cout << j<<" "<<i<<" "<<1<<endl;
                return 0;
            }
        }
    }
    return 0;
}




Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
        new Main().run();
    }
	public void run(){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			int q1 = scan.nextInt();
			if(q1 == 0){
				break;
			}
			int b = scan.nextInt();
			int c1 = scan.nextInt();
			int c2 = scan.nextInt();
			int q2 = scan.nextInt();
			if(b < c1){
				System.out.println("NA");
				continue;
			}
			int x = b / c1;
			int y = 0;
			boolean fl = true;
			x = (x > q2)?q2:x;
			for(int i = x;i > 0;i--){
				if(i*c1 > b){
					continue;
				}
				y = (b-i*c1)/c2;
				if(i+y >= q1){
					System.out.println(i + " " + y);
					fl = false;
					break;
				}
			}
			if(fl){
				System.out.println("NA");
			}
		}
	}
}

Measured memory_bytes: 18400
#include<iostream>
using namespace std;
#include<math.h>

int main(){
	double n,sqr;
	long long int i,j;
	cin >> n;
	sqr = sqrt(n);
	for(i = sqr; i >= 1; i--){
		if((long long int)n%i == 0){
			j = (long long int)n/i;
			break;
		}
	}

	cout << i+j-2;
	return 0;
}


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

namespace ABC113B
{
    static class MainClass
    {
        public static void Main(string[] args)
        {
        
            int N = int.Parse(Console.ReadLine());

            int hyaku = N / 100;
            int juu = (N - (hyaku * 100)) / 10;
            int ichi = N % 10;
            int zoromein = (100 * hyaku) + (10 * hyaku) + hyaku;
            if ( zoromein >= N ){
                Console.WriteLine(zoromein);
                return;
            }

            hyaku = hyaku + 1;
            int zoromein2 = (100 * hyaku) + (10 * hyaku) + hyaku;

            Console.WriteLine(zoromein2);

            return;


        }


        public static int Gcd(int a, int b)
        {
            int tmp;
            // a<bにする
            if (a >= b)
            {
                tmp = a;
                a = b;
                b = tmp;
            }

            if (a == 0)
            {
                return b;
            }

            tmp = a;
            a = b % a;
            b = tmp;
            return Gcd(a, b);

        }


    }

}






Measured memory_bytes: 11092
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
using namespace std;

#define rep(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define SZ(x) ((int) (x).size())
typedef long long ll;

int main(){
	int n;
	while(cin >> n) {
		int a = n % 10;
		int b = n / 10;
		if(a == 9 || b == 9) puts("Yes");
		else puts("No");
	}

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
 
class Main {
    public static void main(String[] args) {
      
        Scanner sc = new Scanner(System.in);
        String ss = sc.next();
        int nam = ss.length();
        
        int one = 0;int zero = 0;
        for(int i = 0; i < nam;i++){
            if(ss.charAt(i) == '0'){
                zero++;
            }else if(ss.charAt(i) == '1'){
                one++;
            }
        }
        System.out.println(Math.min(zero,one)*2);
    }
}

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

template <class T> using V = vector<T>;
template <class S, class T> using P = pair<S, T>;
template <class... T> using TP = tuple<T...>;

using ll = long long;
using db = double;
using ldb = long db;
using str = string;
using vll = V<ll>;
using vvll = V<V<ll>>;
using pll = P<ll,ll>;
using tpll = TP<ll,ll,ll>;
using vpll =V<pll>;
using vst = V<str>;
using vch = V<char>;

#define FOR(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFOR(i,a,b) for(ll i=(b);i>(ll)(a);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(ll)(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) __lcm(a,b)
#define co(a) cout<<a<<endl
#define ci(a) cin>>a
#define pb(a) push_back(a)
#define pob pop_back()
#define mp make_pair
#define mt make_tuple
#define pbmp(a,b) push_back(mp(a,b))
#define subs(a,b) substr(a,b)
#define cfs(a) cout<<fixed<<setprecision(a)
#define INF 1e16
#define mod 1e9+7

const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void Comuse() {
    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;
    }
}
#define comuse Comuse()
ll combi(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() {
  ll n,d;
  cin>>n>>d;
  vvll v(n,vll(d));
  FOR(i,0,n){
    FOR(j,0,d){
      cin>>v[i][j];
    }
  }
  ll count=0;
  ll bns=0;
  vll ve(200);
  FOR(i,0,200){
    ve[i]=i*i;
  }
  FOR(i,0,n-1){
    FOR(k,i+1,n){
      FOR(j,0,d){
        bns+=(v[i][j]-v[k][j])*(v[i][j]-v[k][j]);
      }
      FOR(k,0,200){
        if(bns==ve[k]){
          count++;
          break;
        }
      }
      bns=0;
    }
  }
  co(count);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
/*	#include <boost/math/common_factor.hpp>  boost::math::lcm(10,20) ---> use it to find lcm.*/
using namespace std;
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long ll;
// #define int long long 
#define PI pair<int , int >
#define mpr make_pair
#define ff first
#define ss second
#define endl "\n"
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define FO(i,a,b) for(int i = (int)a;i < (int)b;++i)
#define FE(i,a,b) for(int i = (int)a;i <= (int)b;++i)
const int MOD = 1e9+7;
const int MAXN = 1e5+3;
const int inf = 2e9;
int max(int a,int b){	if(a > b)return a; else return b; }
int min(int a, int b){	if(a < b)return a; else return b; }
int dx[] = {1,-1,0,0};
int dy[] = {0,0,-1,1};
bool cmp(PI p1,PI p2){
	if(p1.ff < p2.ff)return true;	// You should not be writing p1.ss <= p2.ss !!!
	else if(p1.ff == p2.ff){ if(p1.ss < p2.ss)return true; return false; }
	return false;
}
/*		1. Take all the inputs
		4. Whenever you do multiplication and division in the same line, beware.
*/
void solve(){
	// int main  or  int32_t main ...
	int n;
	cin >> n;
	int ans[n];
	memset(ans,0,sizeof ans);
	int a;
	FO(i,1,n){
		cin >> a;
		a--;
		ans[a]++;
	}
	FO(i,0,n)cout << ans[i] << endl;
}
/*	memset() can be used to set all values as 0 or -1 for integer data types.*/

int main(){
	IO;
	#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r", stdin);
	#endif // ONLINE_JUDGE
	// std::cout << std::setprecision(15); std::cout << std::fixed;
	int t; t = 1;
	// cin >> t;
	while(t--){ solve(); }
	return 0;
}


Measured memory_bytes: 4432
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t,a=0,w=0,tl=0,r=0;

    cin>>t;
    while(t--)
    {
        string s;
        cin>>s;
        if(s[0]=='A')
            a++;
        else if(s[0]=='W')
            w++;
        else if(s[0]=='T')
            tl++;
        else
            r++;
    }

    cout<<"AC x "<<a<<endl;
    cout<<"WA x "<<w<<endl;
    cout<<"TLE x "<<tl<<endl;
    cout<<"RE x "<<r<<endl;

    return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define ll unsigned long long int
ll ar[500009],br[500009],fr[500009];
string s1,s2,s3[200005];
map<string,int>mp;
int main()
{
    ll i,j,k,e,r,n,s,d,f,g,h,u,ck=0,ck1=0,t;
    cin >> n;
    g=0;
    for(i=1; i<=n; i++)
    {
        cin >> s3[i];
    sort(s3[i].begin(),s3[i].end());
    mp[s3[i]]++;
    if(mp[s3[i]]>1)
    {

        g+=mp[s3[i]]-1;
    }
    }
//    for(i=1;i<n;i++)
//    {
//        for(j=i+1;j<=n;j++)
//        {
//            if(s3[i]==s3[j])
//            {
//                g++;
//            }
//        }
//    }
    cout << g << endl;
    return 0;
}
/*
2
greenbin
beginner
*/


Measured memory_bytes: 18944
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define LL long long
#define M 200020
using namespace std;
LL read(){
	LL nm=0,fh=1;char cw=getchar();
	for(;!isdigit(cw);cw=getchar()) if(cw=='-') fh=-fh;
	for(;isdigit(cw);cw=getchar()) nm=nm*10+(cw-'0');
	return nm*fh;
}
LL n,m,k,t1,t2,len,RS;
char s1[M],s2[M]; 
LL gcd(LL x,LL y){return y?gcd(y,x%y):x;}
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	n=read(),m=read(),k=gcd(n,m);
	len=n*m/k,t1=n/k,t2=m/k;
	scanf("%s%s",s1,s2);
	for(LL i=0;i<n;i++){
		while(RS<m&&RS*n<i*m) RS++;
		if(RS<m&&RS*n==i*m&&s2[RS]!=s1[i]){	puts("-1");return 0;}
	}
	printf("%lld\n",len);
	return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <unordered_set>
#include <utility>
using namespace std;
using ll = long long;

struct phash {
	inline size_t operator()(const pair<int, int> &p) const {
		const auto h1 = hash<int>()(p.first);
		const auto h2 = hash<int>()(p.second);
		return h1 ^ (h2 << 1);
	}
};

int main() {
	int H, W, M;
	scanf("%d%d%d", &H, &W, &M);
	unordered_set<pair<int, int>, phash> tg;
	int *sumr, *sumc;
	sumr = new int[H]();
	sumc = new int[W]();
	for (int i = 0; i < M; i++) {
		int h, w;
		scanf("%d%d", &h, &w);
		h--, w--;
		tg.insert(make_pair(h, w));
		sumr[h]++;
		sumc[w]++;
	}

	unordered_set<int> maxi, maxj;
	int maxsumr = 0, maxsumc = 0;
	for (int i = 0; i < H; i++) {
		if (sumr[i] > maxsumr) {
			maxi.clear();
			maxsumr = sumr[i];
			maxi.insert(i);
		} else if (sumr[i] == maxsumr) {
			maxi.insert(i);
		}
	}
	for (int j = 0; j < W; j++) {
		if (sumc[j] > maxsumc) {
			maxj.clear();
			maxsumc = sumc[j];
			maxj.insert(j);
		} else if (sumc[j] == maxsumc) {
			maxj.insert(j);
		}
	}
	ll n = maxi.size() * maxj.size();
	for (auto p : tg) {
		if (maxi.count(p.first) && maxj.count(p.second)) {
			n--;
		}
		if (n == 0) {
			break;
		}
	}
	printf("%d\n", maxsumr + maxsumc - (n == 0));
	return 0;
}


Measured memory_bytes: 46076
#include<stdio.h>

#define MAXN 300
#define MAXM 300

int main(void){
	int n,m,i,j,k;
	int sp[MAXN][MAXM];
	int manage_rank[MAXM+1],join_num[MAXM+1],subflg[MAXM+1];
	int maxnum=301,tmpmax,tmpsub;
	
	for(i=0;i<MAXN;i++){
		for(j=0;j<MAXM;j++) sp[i][j]=0;
	}
	for(i=0;i<=MAXM;i++){
		manage_rank[i]=0;
		join_num[i]=0;
		subflg[i]=1;
	}
	
	scanf("%d %d",&n,&m);
	for(i=0;i<n;i++) for(j=0;j<m;j++) scanf("%d",&sp[i][j]);
	
	for(i=0;i<m;i++){
		tmpmax=-1;
		for(j=0;j<n;j++){
			join_num[sp[j][manage_rank[j]]]++;
		}
		for(j=1;j<=m;j++){
			if(tmpmax<join_num[j]){
				tmpsub=j;
				tmpmax=join_num[j];
			}
		}
		if(tmpmax<maxnum) maxnum=tmpmax;
		//fprintf(stdout,"%d\t maxnum:%d @ %d\n",i,maxnum,tmpsub);
		subflg[tmpsub]=0;
		for(j=1;j<=m;j++) join_num[j]=0;
		for(j=0;j<n;j++){
			while(manage_rank[j]<m && subflg[sp[j][manage_rank[j]]]==0) manage_rank[j]++;
		}
		//for(j=0;j<n;j++) fprintf(stderr,"%d%c",manage_rank[j],(j==n-1)?'\n':' ');
	}
	printf("%d\n",maxnum);
	return 0;
}

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ar array

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;

signed main(void) {
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #ifdef LOCAL
    freopen("A.INP", "r", stdin);
    freopen("A.OUT", "w", stdout);
  #endif // LOCAL

  int n, k; cin >> n >> k;
  int g = 0, mx = 0;
  for (int i = 0; i < n; ++i) {
    int a; cin >> a;
    g = __gcd(g, a);
    mx = max(mx, a);
  }
  if (k <= mx && k % g == 0) cout << "POSSIBLE";
  else cout << "IMPOSSIBLE";
}


Measured memory_bytes: 3584