akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
import java.util.TreeMap;

class UnionFind{
	int[] par;
	int[] cnt;
	int N;
	public UnionFind(int n){
		N = n;
		par = new int[N];
		for(int i = 0; i < N; i++){
			par[i] = i;
		}
	}
	public int find(int x){
		if(par[x] == x) return x;
		int parent = find(par[x]);
		return par[x] = parent;
	}
	public Boolean same(int x, int y){
		return find(x) == find(y);
	}
	public void unite(int x, int y){
		if(find(x) == find(y)) return;
		par[find(y)] = find(x);
	}
}
class Edge{
	int s, t;
	public Edge(int _s, int _t) {
		s = _s; t = _t;
	}
}
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), M = sc.nextInt();
		Edge[] edges = new Edge[M];
		UnionFind uf = new UnionFind(N);
		for(int i = 0; i < M; i++) {
			edges[i] = new Edge(sc.nextInt(), sc.nextInt());
		}
		TreeMap<Integer, Long> map = new TreeMap<Integer, Long>();
		long[] ans = new long[M];
		ans[M - 1] = (long)(N - 1) * (long)N / (long)2; // 全て崩壊したとき
		for(int i = M - 2; i >= 0; i--) {
			// edges[i + 1]の橋が復活した時
			int source = uf.find(edges[i + 1].s - 1), sink = uf.find(edges[i + 1].t - 1);
			if(source == sink) {
				ans[i] = ans[i + 1];
				continue;
			}
			long first = (map.containsKey(source)) ? map.get(source) : 1;
			long second = (map.containsKey(sink)) ? map.get(sink) : 1;
			ans[i] = Math.max(0, ans[i + 1] - (first * second));
			uf.unite(edges[i + 1].s - 1, edges[i + 1].t - 1);
			uf.find(edges[i + 1].s - 1); uf.find(edges[i + 1].t - 1);
			map.put(uf.find(edges[i + 1].s - 1), first + second);
		}
		for(long a : ans) System.out.println(a);
	}
}

Measured memory_bytes: 99124
#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <string>
#include <set>
#include <map>
#include <tuple>
#include <queue>
#include <stack>
#include <deque>
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int (i) = (int)(a);(x);++(i))
#define repr(i, a, n) for(int (i) = (int)(a);(i) > (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, n) &((x)[0]), &((x)[n])
#define ADD(a, b) ((((a)%MOD)+((b)%MOD))%MOD)
#define MUL(a, b) ((((a)%MOD)*((b)%MOD))%MOD)
#define FLOOR(x) ((int)floor(((double)x)))
#define CEIL(x) ((int)ceil(((double)x)))
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define pf push_front
#define mt make_tuple
#define fi first
#define se second
#define EPS (1e-20)
#define INF 2147483647
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using VLL = std::vector<llint>;
using MCI = std::map<char, int>;
using namespace std;


int N;


bool isPrime(int n){
	repif(i, 2, i*i <= n)
		if(n%i == 0) return false;
	return true;
}


void solve(){
	VI ans;
	rep(i, 11, 55555){
		if(isPrime(i) && i%5 == 1) ans.pb(i);
		if(SIZE(ans) == N) break;
	}
	rep(i, 0, N){
		cout << ans[i];
		if(i != N-1) cout << ' ';
	}
	cout << endl;
}


signed main(){
	cin >> N;

	solve();

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <functional>
#include <algorithm>


using namespace std;

int main(){
	array<int,10> list;
	for (int i = 0; i < 10; i++){
		cin >> list[i];
	}
	sort(list.begin(), list.end(),greater<int>());
	for (int i = 0; i < 3; i++){
		cout << list[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 1172
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
template <class T>
bool maxi(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool mini(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
#define INF2 1000000000000000037
#define INF 1000000007
#define MOD 1000000007
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
//--GLOBAL---------------------------------


//--MAIN-----------------------------------
void Main() {

    ll N; cin>>N;

    vector<ll> A(N);
    rep(i,N) cin>>A[i];

    ll ans[N+1]={};

    ll mai[N+1]={};
    ll sum[N+1]={};

    map<ll,ll> mp;

    rep(i,N){
        ++mp[A[i]];
    }
    for(auto x: mp){
        ++mai[x.second];
    }
    ll syurui=mp.size();
    ll ct=0;
    reps(i,1,N+1){
        sum[i]=sum[i-1]+syurui;
        syurui-=mai[i];
    }

    rep(i,N){
        ll K=i+1;
        /*bis*/ ll low= -1 , high= N+1 ; // min-1, max+1
        while( abs(high-low)>1 ){ ll mid=(high+low)/2;
            ( sum[mid]>=mid*K ? low : high ) = mid;
        }// if ok, okdir = mid
        ans[i]=low;
    }

    rep(i,N){
        cout<< ans[i] <<"\n";
    }

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


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

int main()
{
  int N;
  cin >> N;
  vector<int> A(N-1);
  vector<int> ans(N, 0);
  for (int i = 0; i < N-1; i++)
  {
    cin >> A.at(i);
    ans.at(A.at(i)-1)++;
  }
  for (int i = 0; i < N; i++) cout << ans.at(i) << endl;
}


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

int N;
int a[305],b[305];
int dp[305][305];
int sum[305][305];

int calc(int x,int y){
  int res=0,c=0;

  while(x>0||y>0){
    int px=x%10,py=y%10;
    res+=( px*py + c );
    if(px+py+c<10)c=0;
    else c=1;
    x/=10;
    y/=10;
  }

  return res+c;
}

int solve(int l,int r){
  if(dp[l][r]!=-1)return dp[l][r];
  if(l==r)return 0;
  
  int res=1e8;
  for(int i=l;i<r;i++){
    res=min(res,solve(l,i)+solve(i+1,r)+calc(b[i]-b[l-1],b[r]-b[i]));
  }
  
  return dp[l][r]=res;
}

int main(){
  memset(dp,-1,sizeof(dp));
  cin>>N;
  for(int i=1;i<=N;i++){
    cin>>a[i];
    b[i]=a[i]+b[i-1];
  }


  cout<<solve(1,N)<<endl;
  return 0;
}

Measured memory_bytes: 1564
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		boolean[][] connected=new boolean[200][200];
		boolean[] visied=new boolean[200];

		for(int i=0; i<n; i++) {
			//polygon information
			int u=0,k=0,v=0;
			u=sc.nextInt();
			u--;

			k=sc.nextInt();

			for(int j=0; j<k; j++) {
				v=sc.nextInt();	//input polygon data
				v--;
				connected[u][v]=true;		//graph no renketu
			}
		}
		Queue<Integer> q1,q2;
		q1=new LinkedList<Integer>();
		q2=new LinkedList<Integer>();
		boolean[] visited=new boolean[200];
		int[] ans=new int[200];
		for(int i=0; i<n; i++) {
			ans[i]=-1;
		}
		q1.add(0);

		for(int i=0; i<n; i++) {
			while(q1.size()>0) {
				int p=q1.peek();
				q1.remove();
				if(visited[p]==true) {continue;}
				else {
					visited[p]=true;
					ans[p]=i;
				}

				for(int j=0; j<n; j++) {
					if(connected[p][j]==true) {
						q2.add(j);
					}
				}
			}
			q1=q2;
			q2=new LinkedList<Integer>();
		}

		for(int i=0; i<n; i++) {
			System.out.println(i+1+" "+ans[i]);
		}

	}
}


Measured memory_bytes: 28256
#include <bits/stdc++.h>
using namespace std;
const int N = 500010;
typedef long long ll;
typedef long double ld;

ll min(ll a, ll b, ll c, ll d) {
	return min(a, min(b, min(c, d)));
}

ll n, a, b;

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n >> a >> b;
	if ((b - a) % 2 == 0) {
		cout << (b - a) / 2;
	}
	else {
		cout << min(b - 1, n - a, a+(b-a-1)/2, n-b+1+(n-(a+(n-b+1)))/2) << endl;
	}
}

Measured memory_bytes: 256
import itertools
N = int(input())
A = list(map(int, input().split()))

mini = float('inf')

cumsum = list(itertools.accumulate(A))
A.reverse()
rev = list(itertools.accumulate(A))
rev.reverse()
cumsum.pop()
rev.pop(0)

for i, j in zip(cumsum,rev):
    if abs(i-j) < mini:
        mini = abs(i-j)

print(mini)

Measured memory_bytes: 39396
//38
#include<iostream>
#include<algorithm>
#include<string>

using namespace std;

int main(){
  for(string s;cin>>s;){
    static int dp[2001][2001];
    fill(dp[0],dp[2001],0);
    for(int i=1;i<=s.size();i++){
      for(int j=1;j<=s.size();j++){
	dp[i][j]=max(dp[i-1][j],max(dp[i][j-1],dp[i-1][j-1]+(s[i-1]==s.rbegin()[j-1])));

      }
    }
    string t;
    int x=s.size(),y=s.size();
    while(x&&y){
      if(s[x-1]==s.rbegin()[y-1]){
	t+=s[x-1];
	x--;
	y--;
      }else if(dp[x-1][y]>dp[x][y-1]){
	x--;
      }else{
	y--;
      }
    }
    cout<<t<<endl;
  }
  return 0;
}
	  

Measured memory_bytes: 16832
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
int dx[4]={-1,0,1,0};
int dy[4]={0,1,0,-1};
#define INF 99999999
typedef std::pair<int,int> pii;
const int nmax = 8;
bool graph[nmax][nmax];
int dfs(int v, int N, bool g[nmax]) {
    bool all = true;
    for (int i = 0; i < N; i++) {
        if (!g[i]) {
            all = false;
        }
    }
    if (all) {
        return 1;
    }
    int res = 0;
    for (int i = 0; i < N; i++) {
        if (!graph[v][i]) continue;
        if (g[i]) continue;
        g[i] = true;
        res += dfs(i, N, g);
        g[i] = false;
    }
    return res;
}
int main(){
    int N,M;
    std::cin >> N >> M;

    for (int i = 0; i < M; i++) {
        int a, b;
        std::cin >> a >> b;
        graph[a - 1][b - 1] = graph[b - 1][a - 1] = true;
    }
    bool visited[nmax];
    for (int i = 0; i < N; i++) {
        visited[i] = false;
    }
    visited[0] = true;
    std::cout << dfs(0, N, visited) << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}

typedef struct _cake{
	ll x;
	ll y;
	ll z;
}cake;

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

	ll N, M ;
	cin >> N >> M;

	vector<cake> A;

	rep(i,N){
		cake inp;
		cin >> inp.x >> inp.y >> inp.z;
		A.pb(inp);
	}

ll ans = 0 ;
	for(ll i=-1; i<=1 ; i+=2){
		for(ll j=-1; j<=1 ; j+=2){
			for(ll k=-1; k<=1 ; k+=2){
				vector<ll> a;
				rep(idx, N){
					a.pb(A[idx].x*i + A[idx].y*j+A[idx].z*k);
				}
				sort(rall(a));
				ll ret = 0;
				rep(idx, M){
					ret += a[idx];
				}
				ans = max(ans, ret);
			}
		}
	}
cout << ans << endl;

	//cout << fixed << setprecision(16) << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n, d, x, cnt=0;
    int a[110];
    cin >> n >> d >> x;
    for(int i=0; i<n;i++){
        cin >> a[i];
    }
    for(int i=0; i<n;i++){
        for(int j=0; j<d;j++){
            if(a[i]*j +1 <= d){
                cnt++;
            }else{
                break;
            }
        }
    }
    cout << (cnt + x) << endl;
    return 0;
}

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

int main()
{
	ll n,m;
	cin >> n >> m;
	vector<ll> A(n);
	for(int i = 0;i<n;++i)cin >> A[i];

	vector<ll> sum(n+1);
	for(int i =0;i<n;i++)
	{
		A[i]%=m;
		sum[i+1] +=sum[i]+ A[i];
		sum[i+1]%=m;
	}
	sort(sum.begin(),sum.end());
	//for(auto i:sum)cout<<i<<' ';cout<<endl;
	ll ans = 0;
	ll l = 1;
	sum.push_back(-1);
	for(int i = 0;i<n+1;i++)
	{
		if(sum[i]==sum[i+1])
		{
			l++;
		}
		else
		{
			ans += l*(l-1)/2;
			l=1;
			//cout<<ans<<endl;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 2560
#include <iostream>

int maxSubSum(int* B, int n)
{
	int* dp = new int[n];
	dp[0] = B[0];
	int res = B[0];
	for (int i=1; i<n; i++) {
		dp[i] = std::max(dp[i-1] + B[i], B[i]);
		res = std::max(res, dp[i]);
	}
	delete[] dp;
	return res;
}

int main()
{
	int n; std::cin >> n;
	int** A = new int*[n];
	for (int i=0; i<n; i++) A[i] = new int[n];
	
	for (int i=0; i<n; i++) {
		for (int j=0; j<n; j++) std::cin >> A[i][j];
	}
	
	int** vert_sum = new int*[n];
	for (int i=0; i<n; i++) vert_sum[i] = new int[n];
	for (int j=0; j<n; j++) {
		vert_sum[0][j] = A[0][j];
		for (int i=1; i<n; i++) vert_sum[i][j] = vert_sum[i-1][j] + A[i][j];
	}
	
	//int** hori_dp = new int*[n];
	//for (int i=0; i<n; i++) hori_dp[i] = new int[n];
	int* B = new int[n];
	int res = A[0][0];
	
	for (int i=0; i<n; i++) {
		for (int j=i; j<n; j++) {
			for (int k=0; k<n; k++) {
				if (i==0) B[k] = vert_sum[j][k];
				else B[k] = vert_sum[j][k] - vert_sum[i-1][k];
			}
			res = std::max(res, maxSubSum(B, n));
		}
	}
	
	std::cout << res << std::endl;				
	
	for (int i=0; i<n; i++) delete[] A[i];
	delete[] A;
	for (int i=0; i<n; i++) delete[] vert_sum[i];
	delete[] vert_sum;
	//for (int i=0; i<n; i++) delete[] hori_dp[i];
	//delete[] hori_dp;
	delete[] B;
	
	return 0;
}



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

using namespace std;

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

int main() {
  
  int H;
  while(cin >> H && H) {
    int b[10][10];
    rep(i, H) rep(j, 5) {
      cin >> b[i][j];
    }

    int score = 0;
    while(1) {
      bool update = 0;
      rep(i, H) rep(j, 5)
        for(int k=5; k>0; k--) {
          if(k-j < 3) continue;
          bool ok = 1;
          REP(l, j+1, k) {
            if(b[i][l] == -1) ok = 0;
            if(b[i][l] != b[i][j]) ok = 0;
          }
          if(!ok) continue;
          update = 1;
          REP(l, j, k) {
            score += b[i][l]; b[i][l] = -1;
          }
        }
    
      if(!update) break;
    
      rep(j, 5) {
        queue<int> q;
        for(int i=H-1; i>=0; i--) { if(b[i][j]!=-1) q.push(b[i][j]); }
        for(int i=H-1; i>=0; i--) {
          if(q.empty()) { b[i][j] = -1; }
          else { b[i][j] = q.front(); q.pop(); }
        }
      }
    }
    cout << score << endl;
  }
  return 0;
}

Measured memory_bytes: 1200
#include <stdio.h>

int A[1000000], n;

int binarySearch(int key) {
  int left = 0;
  int right = n;
  int mid;
  while(left < right) {
    mid = (left + right) / 2;
    if(key == A[mid]) return 1; 
    if(key > A[mid]) left = mid + 1; 
    else if(key < A[mid]) right = mid;
  }
  return 0;
}

int main(void) {
  int i, q, k, sum = 0;
  scanf("%d",&n);
  for(i=0; i<n; i++) {
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++) {
    scanf("%d",&k);
    if(binarySearch(k))
      sum++;
  }
  printf("%d\n",sum);
  return 0;
}


Measured memory_bytes: 2104
import java.util.Scanner;

//Cubic Eight-Puzzle
public class Main{

	int[] top = {0, 0, 1, 1, 2, 2, 3};
	int[][] d = {{-1,0},{0,1},{1,0},{0,-1}};
	int[][] adj = {
			{2, 5, 2, 5},
			{4, 3, 4, 3},
			{0, 4, 0, 4},
			{5, 1, 5, 1},
			{1, 2, 1, 2},
			{3, 0, 3, 0}
	};

	int[][] goal, state;
	boolean dfs(int ei, int ej, int depth, int limit, int pre){
		int dif = 0;
		for(int i=0;i<3;i++)for(int j=0;j<3;j++)dif+=top[state[i][j]]!=goal[i][j]?1:0;
		if(dif==0)return true;
		if(limit<depth)return false;
		if(limit<depth+dif-1)return false;
		for(int k=0;k<4;k++){
			if(pre==(k+2)%4)continue;
			int ni = ei+d[k][0], nj = ej+d[k][1];
			if(0<=ni&&ni<3&&0<=nj&&nj<3){
				state[ei][ej] = adj[state[ni][nj]][k]; state[ni][nj] = 6;
				if(dfs(ni, nj, depth+1, limit, k))return true;
				state[ni][nj] = adj[state[ei][ej]][k]; state[ei][ej] = 6;
			}
		}
		return false;
	}

	void run(){
		Scanner sc = new Scanner(System.in);
		for(;;){
			int x = sc.nextInt(), y = sc.nextInt();
			if((x|y)==0)break;
			goal = new int[3][3];
			for(int i=0;i<3;i++)for(int j=0;j<3;j++){
				char c = sc.next().charAt(0);
				goal[i][j] = c=='W'?0:c=='R'?1:c=='B'?2:3;
			}
			state = new int[3][3];
			for(int i=0;i<3;i++)for(int j=0;j<3;j++){
				state[i][j] = i+1==y&&j+1==x?6:0;
			}
			int res = -1;
			for(int L=0;L<=30;L++){
				if(dfs(y-1, x-1, 0, L, -1)){
					res = L; break;
				}
			}
			System.out.println(res);
		}
	}

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

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

int main(){
    double l;
    cin >>l;

    l = l * l * l / 27;

    printf("%.7lf\n", l);


    return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

class Main {
	public static void main(String[] $) {
		Scanner sc = new Scanner(System.in);
		long a=sc.nextLong(),b=sc.nextLong();
		if(a==0||b==0) {
			System.out.println("Zero");//Positive を、負ならば Negative を、Zero を出力せよ。
		}else if(a<0 && b>0){
			System.out.println("Zero");
		}else if(a>0&&b>0) {
			System.out.println("Positive");
		}else if((b-a)%2==0) {
			System.out.println("Negative");
		}else {
			System.out.println("Positive");
		}
	}
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
int main() {
  int data[3];
  cin >> data[0] >> data[1] >> data[2];

  int max_d = max({data[0],data[1],data[2]});
  int max_id;
  if(max_d==data[0]){
    max_id=0;
  }else if(max_d==data[1]){
    max_id=1;
  }else{
    max_id=2;
  }

  if (data[max_id] == (data[0] + data[1] + data[2] - data[max_id])){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n,x,i,j,k,a;
  int d=0;
  for(a=0;a<10000;a++){
    d=0;
  scanf("%d %d",&n,&x);
  if(n == 0 && x == 0)
    break;
  for(i=1;i<=n-2;i++){
    for(j=1;j<=n-1;j++){
      for(k=1;k<=n;k++){
	if(i == j || j == k || i == k){
	}else if(i > j || j > k || i > k){
	}else if(i+j+k == x){
	  d++;
	}
      }
    }
  }
  printf("%d\n",d);
  }
  return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>

using namespace std;

using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define Rep(i, n) for (long long i = 0; i< (long long)(n); i++)
#define RRep(i,n) for (long long i = ((long long)(n)-1); i>=0; i--)

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;

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;
}

template <class T>
T gcd(T a, T b){
    if( b==0 ) return a;
    else return gcd(b, a%b);
}

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

int INF = 1e9+7;

vector<int> dx = {-1,0,1,0};
vector<int> dy = {0,-1,0,1};

int main(){
    int h,w;
    cin >> h >>w;
    vector<string> s(h);
    rep(i,h) cin >> s[i];
    vector<vector<bool>> visited(h,vector<bool>(w,false));
    ll ans = 0;
    rep(i,h) rep(j,w){
        if(visited[i][j])continue;
        visited[i][j] = true;
        queue<pair<int,int>> que;
        que.push({i,j});
        vector<ll> num(2,0LL);
        while(!que.empty()){
            int y = que.front().first;
            int x = que.front().second;
            que.pop();
            num[s[y][x]=='#']++;
            rep(k,4){
                int ny = y+dy[k];
                int nx = x+dx[k];
                if(0<=ny && ny<h && 0<= nx && nx < w && !visited[ny][nx] && s[y][x]!=s[ny][nx]){
                    que.push({ny,nx});
                    visited[ny][nx] = true;
                }
            }
        }
        ans += num[0]*num[1];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<cmath>
int main()
{
  int n;
  std::cin>>n;

  int R[n]={0};
  int i,j;
  for(i=0; i<n; i++){
    std::cin>>R[i];
  }

  int cnt;
  int so=0;
  for(i=0; i<n; i++){
    cnt=0;
    for(j=2; j<sqrt(R[i])+1; j++){
      if(R[i]%j==0){
	cnt++;
      }
    }
    if(cnt<1 || R[i]==2){
      so++;
    }
  }

  std::cout<<so<<"\n";
  return 0;
}


Measured memory_bytes: 3104
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
#define FOR(a, b, c) for (int (a) = (b); (a) < (c); ++(a))
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))

int main() {
    ll n;
    cin >> n;
    vl a(n);
    for (ll i = 0; i < n; i++) {
        cin >> a[i];
    }
    ll ans = 0;
    ll m = pow(10, 9) + 7;

    /*REP (i, n) {
        for (int j = i + 1; j < n; j++) {
            ans += a[i] * a[j];
            //cout << ans << endl;
        }
    }*/
    
    // Using math formula
    /*ll ts = 0, is = 0;
    for (ll i = 0; i < n; i++) {
        ts += a[i];
        is += a[i] * a[i];
    }
    ll tss = ts * ts;
    ans = (tss - is) / 2;
    cout << ans % m << endl;*/

    ll x = 0;
    REP (i, n) {
        ans = (ans + (ll)a[i] * x) % m;
        x = (x + a[i]) % m;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4780
#include "bits/stdc++.h"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/pb_ds/assoc_container.hpp"
#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(ll x = l;x<u;x++)
#define RREP(x,l,u) for(ll x = l;x>=u;x--)
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define mst(x,a) memset(x,a,sizeof(x))
#define all(a) a.begin(),a.end()
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define sqr(x) ((x)*(x))
#define lowbit(x) (x&(-x))
#define lson (ind<<1)
#define rson (ind<<1|1)
#define se second
#define fi first
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
#define sz(x) ((int)x.size())
typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;
const int block_size = 320;
typedef complex<ll> point;
const ll mod = 1e9+7;
const ld eps = 1e-9;
const int inf = mod;
const db PI = atan(1)*4;
template<typename T>
inline int sign(const T&a){if(a<0)return -1;if(a>0)return 1;return 0;}


template<typename T> inline void in(T &x){
    x = 0; T f = 1; char ch = getchar();
    while (!isdigit(ch)) {if (ch == '-') f = -1; ch = getchar();}
    while (isdigit(ch))  {x = x * 10 + ch - '0'; ch = getchar();}
    x *= f;
}

int main(){
	string s;cin>>s;
	int ans = 0;
	int res = 0;
	for(auto i:s){
		if(i == 'g'){
			if(res){
				res--;ans++;
			}else{
				res++;
			}
		}else{
			if(res){
				res--;
			}else{
				res++;ans--;
			}
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 540
// ABC061_A
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <iterator>  // std::back_inserter()
#include <tuple>  // std::tuple std::get
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>  // std::copy()
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;

#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
#define REPN(i, n) for (ll i=1; i <= n; i++)  // 1 ~ n
#define MIN(vec) min_element(ALL((vec)))  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(ALL((vec)))
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(ALL((vec)), 0LL)  // 0 は初期値
#define COPY(vec1, vec2) copy(ALL(vec1), back_inserter(vec2))  // vec1をvec2にコピーする vec2は空にしておく必要あり
#define zero_pad(num) setfill('0') << std::right << setw(num)
#define space_pad(num) setfill(' ') << std::right << setw(num)

typedef long long ll;

const ll MOD7 = 1000000007;  // 1 000 000 007
const ll MOD9 = 1000000009;  // 1 000 000 009

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

    // input
    ll N, M, L;
    cin >> N >> M >> L;
    // vector<ll> vec(N);
    // REP(i, N) cin >> vec[i];
    
    // calculation
    if (N <= L && L <= M) {
        cout << "Yes" << "\n";
    } else {
        cout << "No" << "\n";
    }
    
    return 0;
}


Measured memory_bytes: 256
import heapq

x, y, a, b, c = map(int, input().split())

def max_listup(limit):
  l = sorted(list(map(int, input().split())))
  cnt = 1
  res = []
  while l:
    if cnt > limit:
      break
    m = l.pop()
    res.append(m)
    cnt += 1
  return res

if __name__ == "__main__":
  all = sorted(max_listup(x) + max_listup(y) + list(map(int, input().split())))
  ans = 0
  for _ in range(x+y):
    ans += all.pop()

  print(ans)


Measured memory_bytes: 22520
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <unordered_map>
#include <random>
#include <cstdio>
#include <cstring>
#include <cmath>

using namespace std;
using ll = long long;

ll N;
vector<ll> V;

void input() {
    cin >> N;
    V.resize(N);
    for (auto& v : V)
        cin >> v;
}

ll solve() {
    vector<ll> counts[2] = {vector<ll>(100001), vector<ll>(100001)};
    for (ll i = 0; i < N; i++) {
        counts[i % 2][V[i]]++;
    }
    ll maxif = max_element(counts[0].begin(), counts[0].end()) - counts[0].begin();
    ll maxis = max_element(counts[1].begin(), counts[1].end()) - counts[1].begin();
    if (maxif == maxis) {
        if (counts[0][maxif] > counts[1][maxis]) {
            counts[1][maxis] = 0;
            maxis = max_element(counts[1].begin(), counts[1].end()) - counts[1].begin();
        } else if (counts[0][maxif] < counts[1][maxis]) {
            counts[0][maxif] = 0;
            maxif = max_element(counts[0].begin(), counts[0].end()) - counts[0].begin();
        } else {
            ll pmaxif = maxif, pmaxis = maxis, pmaxcf = counts[0][maxif], pmaxcs = counts[1][maxis];
            counts[0][maxif] = 0;
            maxif = max_element(counts[0].begin(), counts[0].end()) - counts[0].begin();
            counts[1][maxis] = 0;
            maxis = max_element(counts[1].begin(), counts[1].end()) - counts[1].begin();
            if (counts[0][maxif] > counts[1][maxis]) {
                maxis = pmaxis;
                counts[1][pmaxis] = pmaxcs;
            } else {
                maxif = pmaxif;
                counts[0][pmaxif] = pmaxcf;
            }
        }
    }
    
    return N - counts[0][maxif] - counts[1][maxis];
}


int main() {
    input();
    cout << solve() << endl;
//    solve();
    
    return 0;
}



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

int main() {
	int r, a;
	
	while(1){
		cin >> r >> a;
		if(r == 0 && a == 0)
			break;
		
		int right[4], ans[4], hit = 0, blow = 0;
		for(int i = 0; i < 4; ++i){
			right[i] = r % 10;
			r /= 10;
			ans[i] = a % 10;
			a /= 10;
		}
		for(int i = 0; i < 4; ++i){
			for(int j = 0; j < 4; ++j){
				if(right[i] == ans[j]){
					if(i == j)
						hit++;
					else
						blow++;
				}
			}
		}
		cout << hit << " " << blow << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
import java.util.*

fun main(args: Array<String>) {
    val (X, Y, Z, K) = readLine()!!.split(" ").map {it.toInt()}
    val A = Array(3) {readLine()!!.split(" ").map{it.toLong()}}

    val Qs = Array(4) { PriorityQueue<Long>()}

    Qs[0].add(0)

    for (i in A.indices) {
        while (Qs[i].isNotEmpty()) {
            val q = Qs[i].poll()
            for (a in A[i]) {
                Qs[i + 1].add(q + a)

                if (Qs[i + 1].size > K) {
                    Qs[i + 1].poll()
                }
            }
        }
    }

    val a = Qs[3].toLongArray()
    Arrays.sort(a)
    a.reverse()

    a.forEach { println(it) }
}


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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define per(i, a, b) for(int i = (b)-1; i >= (a); --i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pii> vii;

int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);

  int n;
  cin >> n;
  ++n;

  vl a(n);
  rep(i,0,n) cin >> a[i];

  if (n==1) {
    if (a[0] == 1) cout << 1 << '\n';
    else cout << -1 << '\n';
    return 0;
  }

  vl pars(n);
  per(i,1,n) {
    pars[i-1] = (pars[i]+a[i]);
  }
  rep(i,0,n) {
    if (i < 60) ckmin(pars[i], (1ll<<i)-a[i]);
    else ckmin(pars[i], 10000000000000ll-a[i]);
    ckmax(pars[i], 0ll);
    if (i<n-1) {
      ckmin(pars[i+1], pars[i]*2-a[i+1]);
      ckmax(pars[i+1], 0ll);
    }
  }

  per(i,1,n) {
    ckmin(pars[i-1], pars[i]+a[i]);
  }

  bool ok = true;
  ll ans = 0;
  rep(i,0,n) {
    if (i<n-1) ok &= pars[i]*2 >= (pars[i+1] + a[i+1]);
    ans += pars[i] + a[i];
  }

  if (not ok) ans = -1;
  cout << ans << '\n';
}

Measured memory_bytes: 4784
N,M,K = list(map(int,input().split(' ')))

friend_list = [0]*(N+1)
bad_list = [0]*(N+1)
group = {}

parent = [i for i in range(N+1)]

def find(i):
    rireki = []
    while parent[i] != i:
        rireki.append(i)
        i = parent[i]
    for r in rireki:
        parent[r]=i
    return i

def union(i, j):
    i = find(i)
    j = find(j)
    parent[j] = i



for i in range(M):
    A,B = list(map(int,input().split(' ')))
    friend_list[A]+=1
    friend_list[B]+=1
    
    union(A,B)

for i in range(1,N+1):
    oya = find(i)
    parent[i] = oya
    #print(oya)
    if oya in group:
        group[oya] = group[oya]+1
    else:
        group[oya]=1

for i in range(K):
    A,B = list(map(int,input().split(' ')))
    if find(A)==find(B):
        bad_list[A]+=1
        bad_list[B]+=1
    
    #union(A,B)



#print(parent)
#print('parent')

#print('friend')
#print(friend_list)
#print('bad')
#print(bad_list) 
#print(group)

kouho = [0]*N

for i in range(1,N+1):
    oya = find(i)
    abc = group[oya]-friend_list[i]-bad_list[i]-1
    kouho[i-1] = abc

for k in kouho:
    print(k,end=" ")
print()

#print(parent)

Measured memory_bytes: 78112
#include <iostream>
#include <cmath>

using namespace std;

bool isprime(unsigned int x)
{
	if (x == 2) return true;

	if (x < 2 || x % 2 == 0)
		return false;

	unsigned int i = 3;
	while (i <= floor(sqrt(x))) {
		if (x % i == 0) {
		  return false;
		}
		i = i + 2;
	}

	return true;
}

int main()
{
	unsigned int n;
	unsigned int ans = 0;
	cin >> n;
	for (unsigned int i = 0; i < n; ++i) {
		unsigned int x;
		cin >> x;
		if (isprime(x)) ++ans;
	}
	cout << ans << endl;
	return 0;
}
 


Measured memory_bytes: 3124
#include <iostream>
#include <vector>
#include <iostream>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <list>
#include <stack>
#include <climits>
#include <unordered_set>
#include <unordered_map>
#define m7 1000000007
#define m9 1000000009
#define ll long long
#define pii pair<int,int>
#define F first
#define S second

using namespace std;
int maxlen;
int dfs(vector<vector<int> >& gr, vector<int>& dp, int pos) {
	if (dp[pos] != -1) return dp[pos];
	dp[pos] = 0;
	for (int i = 0; i < gr[pos].size(); i++) {
		dp[pos] = max(dp[pos], dfs(gr,dp,gr[pos][i]) + 1);
	}
	maxlen = max(maxlen, dp[pos]);
	return dp[pos];
}
int main()
{
	int n, m,t1,t2;
	cin >> n >> m;
	vector < vector<int> >gr(n+1);
	vector<int> dp(n+1,-1);
	for (int i = 0; i < m; i++) {
		cin >> t1 >> t2;
		gr[t1].push_back(t2);
	}
	maxlen = 0;
	for (int i = 1; i <= n; i++) {
		if (dp[i] < 0) {
			dfs(gr, dp, i);
		}
	}
	cout << maxlen;
	return 0;
}

Measured memory_bytes: 8832
#include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(ll i=0;i<N;++i)
typedef long long int ll;
ll INF = 1LL<<60;

ll n,m;

struct UnionFind {
  vector< int > data;
 
  UnionFind(int sz) {
    data.assign(sz, -1);
  }
 
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
 
  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }
 
  int size(int k) {
    return (-data[find(k)]);
  }
};

int main(){
    cin >> n >> m;
    UnionFind tree(n);
    rep(i,m){
        int x,y; cin >> x >> y;
        tree.unite(x,y);
    }
    int q; cin >> q;
    rep(i,q){
        int x,y; cin >> x >> y;
        if(tree.find(x) != -1 && tree.find(y) != -1){
            if(tree.find(x) == tree.find(y)) cout << "yes" << endl;
            else cout << "no" << endl;
        }else cout << "no" << endl;
    }
}


Measured memory_bytes: 3144
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s; cin >> s;
    int ans = 0;
    rep(i,s.size()) {
        if(s[i] == 'g') {
            if(i%2==1) {
                ans++;
            }
        }else {
            if(i%2==0) {
                ans--;
            }
        }
    }
    cout << ans << endl;

    return 0;
}

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_N = (int)(1e2 + 5);

int h, w;
char a[MAX_N][MAX_N];

map<int, int> count_parity() {
  map<char, int> cnt;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      cnt[a[i][j]] += 1;
    }
  }

  map<int, int> ret;
  for (auto &e : cnt) {
    ret[e.second % 4] += 1;
  }

  return ret;
}

int main(void) {
  // Here your code !
  scanf("%d %d", &h, &w);

  for (int i = 0; i < h; ++i) {
    scanf("%s", a[i]);
  }

  // for (int i = 0; i < h; ++i) {
  //   for (int j = 0; j < w; ++j) {
  //     printf("%c", a[i][j]);
  //   }
  //   printf("\n");
  // }

  auto pc = count_parity();

  string ans = "No";

  if ((h % 2 == 0) && (w % 2 == 0)) {
    if (pc[1] == 0 && pc[2] == 0 && pc[3] == 0) {
      ans = "Yes";
    }
  } else if ((h % 2 == 1) && (w % 2 == 1)) {
    if (pc[1] == 1 && (pc[2] * 2 <= (h + w - 2)) && pc[3] == 0) {
      ans = "Yes";
    }
  } else {
    int even = (h % 2 == 0) ? h : w;

    if (pc[1] == 0 && (pc[2] * 2 <= even) && pc[3] == 0) {
      ans = "Yes";
    }
  }

  cout << ans << endl;

  return 0;
}


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

int main() {
    int N, M;
    int c[110] = {};
    cin >> N >> M;
    for(int i = 0; i < M * 2; i++) {
        int tmp;
        cin >> tmp;
        c[tmp]++;
    }

    for(int i = 1; i <= N; i++) {
        cout << c[i] << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
using Graph = vector<vector<int>>;

int main()
{
    // 頂点数と辺数
    int N, M;
    cin >> N >> M;

    // グラフ入力受取 (ここでは無向グラフを想定)
    Graph G(N);
    for (int i = 0; i < M; ++i)
    {
        int a, b;
        cin >> a >> b;
        G[a - 1].push_back(b - 1);
        G[b - 1].push_back(a - 1);
    }

    // BFS のためのデータ構造
    vector<int> dist(N, -1); // 全頂点を「未訪問」に初期化
    queue<int> que;

    // 初期条件 (頂点 0 を初期ノードとする)
    dist[0] = 0;
    que.push(0); // 0 を橙色頂点にする

    int num = 0;
    // BFS 開始 (キューが空になるまで探索を行う)
    while (!que.empty())
    {
        int v = que.front(); // キューから先頭頂点を取り出す
        que.pop();

        // v から辿れる頂点をすべて調べる
        for (int nv : G[v])
        {
            if (dist[nv] != -1)
                continue; // すでに発見済みの頂点は探索しない

            // 新たな白色頂点 nv について距離情報を更新してキューに追加する
            dist[nv] = v + 1;
            que.push(nv);
            num++;
        }
    }

    if (num >= N - 1)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
        return 0;
    }
    // 結果出力 (各頂点の頂点 0 からの距離を見る)
    for (int v = 1; v < N; ++v)
        cout << dist[v] << endl;
}

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

vector<int> parents;
vector<int> scores;
vector<int> counters;

// 親をたどって自分のカウンターを返す
int counter(int v) {
  if (counters[v] > -1) {
    return counters[v];
  }

  int parent_score = 0;

  if (parents[v] > -1) {
    parent_score = counter(parents[v]);
  }

  int score = scores[v] + parent_score;
  counters[v] = score;
  return score;
}

// 根から自分までの各ノードのカウンターを足すとそのノードの値が計算できる
// 各ノードは親を把握しておけばよさそう
int main() {
  int N, Q;
  cin >> N >> Q;

  parents.assign(N, -1);
  scores.assign(N, 0);
  counters.assign(N, -1);

  for (int i = 0; i < N - 1; i++) {
    int a, b;
    cin >> a >> b;

    parents[b - 1] = a - 1;
  }

  for (int i = 0; i < Q; i++) {
    int p, x;
    cin >> p >> x;

    scores[p - 1] += x;
  }

  for (int i = 0; i < N; i++) {
    printf(i == 0 ? "%d" : " %d", counter(i));
  }
  printf("\n");
}

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

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

#define fst first
#define snd second
#define pb push_back

const int maxn=300005,maxm=106;
const double pi=acos(-1.0);
const ll mod=1000000007;
const double eps=1e-6;

int n,m;

bool v[maxn]={0};



int main()
{
	int i,j,k,l;
	scanf("%d %d",&n,&m);
	for(i=0;i<m;i++)
    {
        int x;scanf("%d",&x);
        for(j=0;j<x;j++)
        {
            int y;scanf("%d",&y);
            v[y-1]=1;
        }
    }
    int ans=0;
    for(i=0;i<n;i++) ans+=(!v[i]);
    printf("%d\n",ans);
    return 0;
}


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

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORTASC(c) sort((c).begin(),(c).end())
#define SORTDESC(c,t) sort((c).begin(),(c).end(), std::greater<t>());
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define VMAX(a) *max_element(ALL(a))
#define VMIN(a) *min_element(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double PI  = acos(-1.0);

using ll = long long;
using namespace std;

int main() {
    ll n;
    double total = 0;
    ll x[10], y[10];

    cin >> n;

    ll array[n];
    REP(i, n){
        cin >> x[i] >> y[i];
        array[i] = i+1;
    }

  	ll ct = 0;
    do{
        REP(i, n-1){
            total += sqrt((x[array[i]-1] - x[array[i+1]-1])*(x[array[i]-1] - x[array[i+1]-1]) + (y[array[i]-1] - y[array[i+1]-1])*(y[array[i]-1] - y[array[i+1]-1]));
        }
        ct++;
    }while(next_permutation(array, array+n));

    cout << setprecision(20) << total / double(ct) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64

signed main() {
  int n,k; cin>>n>>k;
  vector<int> l(n);
  for(int i=0;i<n;++i) cin>>l[i];

  sort(l.begin(), l.end(), greater<int>());

  int ans = 0;
  for(int i=0;i<k;++i) {
    ans += l[i];
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll INF = 1e15;
int main()
{
    int n, k;
    cin >> n >> k;
    vector<ll> h(n+1);
    for(int i = 1; i <= n; i++) cin >> h[i];
    vector<vector<ll>> dp(n+1, vector<ll>(n+1));
    for(int i = 0; i <= n; i++)
    {
        for(int j = 0; j <= n; j++)
        {
            dp[i][j] = INF;
        }
    }
    dp[0][0] = 0;
    if(n == k)
    {
      cout << 0 << endl;
      return 0;
    }

    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= n-k; j++)
        {
            if(i < j) break;
            for(int x = 0; x <= i-1; x++)
            {
                dp[i][j] = min(dp[i][j], dp[x][j-1] + max(0LL, h[i]-h[x]));
            }
        }
    }
    ll ans = INF;
    for(int i = 1; i <= n; i++)
    {
        ans = min(ans, dp[i][n-k]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1152
h,w=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(h)]
m=[]

for y in range(h):
  for x in range(w):
    if x<w-1 and l[y][x]%2:
      l[y][x]-=1
      l[y][x+1]+=1
      m.extend([[y+1,x+1,y+1,x+2]])

for x in range(w):
  for y in range(h):
    if y<h-1 and l[y][x]%2:
      l[y][x]-=1
      l[y+1][x]+=1
      m.extend([[y+1,x+1,y+2,x+1]])

print(len(m))
for i in m:
  print(*i,sep=" ")


Measured memory_bytes: 30404
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
using namespace std;
int gcd2(int x, int y) { return (x % y)? gcd2(y, x % y): y; }

int gcd(int a, int b, int c) {
    a = gcd2(a, b);
    a = gcd2(a, c);
  return a;
}

int main(){
  int s;
  cin >> s;
  int i,j,k;
  int sum = 0;
  for(i=1;i<=s;i++){
    for(j=1;j<=s;j++){
      for(k=1;k<=s;k++){
        sum += gcd(i,j,k);
      }
    }
  }
  cout << sum << "\n";
  return 0;
}

Measured memory_bytes: 3632
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
input = sys.stdin.readline

# bisect_left(lists, 3)
# bisect_right(lists, 3)

def main():
	N = int(input())
	H = input().split(" ")
	H = [int(s) for s in H]
	

		



 
	ans = 0
	max = 0
	for i, val in enumerate(H):
		if i == 0:
			ans += 1
			max = val
			continue
		if max <= val:
			max = val
			ans += 1
			
 
	print(ans)

	
	
if __name__ == "__main__":
	main()
	

Measured memory_bytes: 3316
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<cmath>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<algorithm>
#include<bitset>
#include<complex>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
using namespace std;
int x,y;
int main()
{
	scanf("%d%d",&x,&y);
	if (x*4<y || x*2>y || y&1)
		printf("No");
	else printf("Yes");
	return 0;
}

Measured memory_bytes: 3788
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class _C
{
	void _()
	{

		var n = _Ns();
		var a = _Ns();

		int min = int.MaxValue;

		for (int i=-100;i<=100 ;i++) {

			int sum = 0;
			for (int j = 0; j< n[0]; j++)
			{
				sum += (i-a[j])* (i - a[j]);
			}
			min=Math.Min(sum,min);
		}

		Console.WriteLine(min);
		
	}

	static void Main(string[] args)
  {
    new _C()._();
  }

  #region

  string _S()
  {
    return Console.ReadLine();
  }

  string[] _Ss()
  {
    return Console.ReadLine().Split();
  }

  int[] _N(int n)
  {
    var x = new int[n];
    for (var i = 0; i < n; i++)
    {
      x[i] = int.Parse(Console.ReadLine());
    }
    return x;
  }

  int[] _Ns()
  {
    var ss = Console.ReadLine().Split();

    var x = new int[ss.Length];
    for (var i = 0; i < ss.Length; i++)
      x[i] = int.Parse(ss[i]);

    return x;
  }
  #endregion
}


Measured memory_bytes: 2648
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; ++i)
        cin >> a[i];
    sort(a.rbegin(), a.rend());

    int ans = a[1];
    for(int i=2; i<n; ++i){
        if(abs(a[i] - a[0] / 2) < abs(ans - a[0] / 2))
            ans = a[i];
    }
    cout << a[0] << ' ' << ans << endl;

    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>

int main(void)
{
	char c;
	
	scanf("%c", &c);
	if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
		printf("vowel");
	}
	else {
		printf("consonant");
	}
	return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <array>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define int long long

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

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

    for (int i = 0; i < 5; i++) {
        if (a[i] == 0) {
            cout << i + 1 << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 3632
#include <stdio.h>
#define SIZE 2001
 
char resultTable[SIZE];
int n,q,elems[20];
 
void calc(int sum,int index){
    if(index == n){
        if(sum >= 1 && sum <= 2000){
            resultTable[sum] = 'y';
        }
    }else{
        calc(sum+elems[index],index+1);
        calc(sum,index+1);
    }
}
 
int main(){
 
    for(int i = 0;i < SIZE; i++) resultTable[i] = 'n';
 
    scanf("%d",&n);
    for(int i = 0; i < n; i++) scanf("%d",&elems[i]);
    calc(0,0);
 
    scanf("%d",&q);
 
    int tmp;
    for(int i = 0; i < q; i++){
        scanf("%d",&tmp);
        if(resultTable[tmp] == 'y'){
            printf("yes\n");
        }else{
            printf("no\n");
        }
    }
}


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

int main() {
  int n;
  cin>>n;
  rep(i,10){
    rep(j,10){
      if(i*j==n){
        cout<<"Yes"<<endl;
        return 0;
      }
    }
  }
  cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 256