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

using namespace std;

#define int long long
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define fi first
#define se second
#define All(a) (a).begin(), (a).end()
#define rAll(a) (a).rbegin(), (a).rend()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CCIN(...)                                                              \
    char __VA_ARGS__;                                                          \
    CIN(__VA_ARGS__)
#define DCIN(...)                                                              \
    double __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"
#define Printv(v)                                                              \
    {                                                                          \
        FOREACH(x, v) { cout << x << " "; }                                    \
        cout << "\n";                                                          \
    }
template <typename T = string> inline void eputs(T s) {
    cout << s << "\n";
    exit(0);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *)array, (T *)(array + N), val);
}
template <typename T> using PQG = priority_queue<T, vector<T>, greater<T>>;
template <typename T> using PQ = priority_queue<T>;

typedef long long ll;
typedef pair<ll, ll> PL;
typedef vector<PL> VPL;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<double> VD;

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
const double PI = atan(1.0) * 4.0;
const ll dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[] = {0, 1, 1, 1, 0, -1, -1, -1};
#define PI 3.141592653589793238

void cinfast() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

ll N;

signed main() {
    LCIN(A, B);
    if(B==1) eputs(0);
    ll cnt = 1, now = A;
    while(B > now) {
        now += A - 1;
        cnt++;
    }
    cout << cnt << "\n";
}


Measured memory_bytes: 256
#include<iostream>
#include<string>

using namespace std;

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

bool used[26];

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

    REP(i, 26) used[i] = false;

    bool flag = false;
    REP(i, s.size()){
        if(used[s[i]-'a']){
            flag = true;
            break;
        } else {
            used[s[i]-'a'] = true;
        }
    }

    if(flag){
        cout << "no" << endl;
    } else {
        cout << "yes" << endl;
    }
}


Measured memory_bytes: 256
//start of jonathanirvings' template v3.0.3 (BETA)

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<LL> vl;
typedef vector<vl> vvl;

double EPS = 1e-9;
int INF = 1000000005;
long long INFF = 1000000000000000005LL;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};

#ifdef TESTING
  #define DEBUG fprintf(stderr,"====TESTING====\n")
  #define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
  #define debug(...) fprintf(stderr, __VA_ARGS__)
#else
  #define DEBUG 
  #define VALUE(x)
  #define debug(...)
#endif

#define FOR(a,b,c) for (int (a)=(b);(a)<(c);++(a))
#define FORN(a,b,c) for (int (a)=(b);(a)<=(c);++(a))
#define FORD(a,b,c) for (int (a)=(b);(a)>=(c);--(a))
#define FORSQ(a,b,c) for (int (a)=(b);(a)*(a)<=(c);++(a))
#define FORC(a,b,c) for (char (a)=(b);(a)<=(c);++(a))
#define FOREACH(a,b) for (auto &(a) : (b))
#define REP(i,n) FOR(i,0,n)
#define REPN(i,n) FORN(i,1,n)
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
#define SQR(x) ((LL)(x) * (x))
#define RESET(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(),v.end()
#define ALLA(arr,sz) arr,arr+sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr,sz) sort(ALLA(arr,sz))
#define REVERSEA(arr,sz) reverse(ALLA(arr,sz))
#define PERMUTE next_permutation
#define TC(t) while(t--)

inline string IntToString(LL a){
  char x[100];
  sprintf(x,"%lld",a); string s = x;
  return s;
}

inline LL StringToInt(string a){
  char x[100]; LL res;
  strcpy(x,a.c_str()); sscanf(x,"%lld",&res);
  return res;
}

inline string GetString(void){
  char x[1000005];
  scanf("%s",x); string s = x;
  return s;
}

inline string uppercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'a' && s[i] <= 'z') s[i] = s[i] - 'a' + 'A';
  return s;
}

inline string lowercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'A' && s[i] <= 'Z') s[i] = s[i] - 'A' + 'a';
  return s;
}

inline void OPEN (string s) {
  #ifndef TESTING
  freopen ((s + ".in").c_str (), "r", stdin);
  freopen ((s + ".out").c_str (), "w", stdout);
  #endif
}

//end of jonathanirvings' template v3.0.3 (BETA)

int n,m;
pii satu[55];
pii dua[55];

int dist(int a,int b)
{
  return abs(satu[a].fi - dua[b].fi) + abs(satu[a].se - dua[b].se);
}

int main()
{
  scanf("%d %d",&n,&m);
  REP(i,n) scanf("%d %d",&satu[i].fi,&satu[i].se);
  REP(i,m) scanf("%d %d",&dua[i].fi,&dua[i].se);
  REP(i,n)
  {
    int risan = 0;
    REP(j,m) if(dist(i,j) < dist(i,risan)) risan = j;
    printf("%d\n",risan+1);
  }
  return 0;
}










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

int main(void){
 int m,n,tmp,i,j,k;
 short *flg;
 int *stack;
 
 scanf("%d%d",&n,&m);
 flg=(short *)calloc(n+1,sizeof(short));
 stack=(int *)calloc(m,sizeof(int));
 for(i=0;i<m;i++){
  scanf("%d",&tmp);
  flg[tmp]=1;
  stack[i]=tmp;
 }
 for(i=m-1;i>=0;i--){
  if(flg[stack[i]]==1) printf("%d\n",stack[i]);
  flg[stack[i]]=2;
 }
 for(i=1;i<=n;i++) if(flg[i]==0) printf("%d\n",i);
 free(flg);
 free(stack);
 return 0;
}

Measured memory_bytes: 1152
# -*- coding: utf-8 -*-S
N = int(input())
p = [int(i) for i in input().split()]

q = sorted(p)
X = 0
for i in range (N):
    if p[i] != q[i]:
        X += 1
if X == 2 or X == 0:    #X <= 2 のかわりに　X == 0 or X == 2 でもできる？？
    print("YES")
else:
    print("NO")

#X=1になることはあるの？　なんでWAになったの？？

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

int main()
{
    int x, y;
    cin >> x >> y;
    int div = __gcd(x, y);
    x /= div, y /= div;
    cout << (x + y - 1) * div + 1 << endl;
    return (0);
}

Measured memory_bytes: 3096
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
using namespace std;

#define abs(N) ((N>0)?N:-1*N)
#define min(A,B) ((A>B)?B:A)
#define max(A,B) ((A<B)?B:A)
#define print(S) (cout << S)
#define println(S) (cout << S << endl)

int main() {
	int a[3];
	cin >> a[0] >> a[1] >> a[2];

	sort(a,a+3);

	printf("%d %d %d\n",a[0],a[1],a[2]);

	return 0;
}



Measured memory_bytes: 3252
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define cbn(x,y) ((ll)fac[x]*inv[y]%mod*inv[(x)-(y)]%mod)
#define N 200009
using namespace std;

int n,m,E,ans,tot=1,tp,eg,q[N],fst[N],pnt[N<<1],len[N<<1],nxt[N<<1];
int fa[N],f[N],sz[N],fac[N],inv[N],vis[N]; bool bo[N];
void add(int x,int y,int z){
	pnt[++tot]=y; len[tot]=z; nxt[tot]=fst[x]; fst[x]=tot;
}
void dfs1(int x,int p){
	int i,y; vis[x]=1; q[++tp]=x;
	for (i=fst[x]; i; i=nxt[i]) if (i^p^1){
		y=pnt[i];
		if (!bo[i>>1]){ bo[i>>1]=1; eg++; }
		if (!vis[y]) dfs1(y,i);
	}
}
void dfs2(int x,int p){
	int i,y,z; vis[x]=2;
	for (i=fst[x]; i; i=nxt[i]) if (i^p^1){
		y=pnt[i];
		if (vis[y]!=2){
			fa[y]=i; dfs2(y,i);
		} else if (!E)
			for (z=x,E=i; z!=y; z=pnt[fa[z]^1])
				if (len[fa[z]]>len[E]) E=fa[z];
	}
}
void dfs3(int x,int p){
	int i,y; sz[x]=f[x]=1;
	for (i=fst[x]; i; i=nxt[i]) if ((i^p^1) && i!=E && (i^E^1)){
		y=pnt[i];
		dfs3(y,i);
		if (len[i]>len[p]) ans=(ll)ans*f[y]%mod*inv[sz[y]]%mod; else{
			sz[x]+=sz[y];
			f[x]=(ll)f[x]*f[y]%mod*cbn(sz[x]-1,sz[y])%mod;
		}
	}
	if (p==E) ans=(ll)ans*f[x]%mod*inv[sz[x]]%mod;
}
int main(){
	scanf("%d",&n);
	int i,x,y;
	for (i=1; i<=(n<<1); i++){
		scanf("%d%d",&x,&y);
		add(x,y+n,x+y); add(y+n,x,x+y);
	}
	fac[0]=inv[0]=inv[1]=1;
	for (i=1; i<=(n<<1); i++) fac[i]=(ll)fac[i-1]*i%mod;
	for (i=2; i<=(n<<1); i++) inv[i]=mod-(ll)inv[mod%i]*(mod/i)%mod;
	for (i=2; i<=(n<<1); i++) inv[i]=(ll)inv[i-1]*inv[i]%mod;
	int sum=fac[n<<1],tmp;
	for (i=(n<<1); i; i--) if (!vis[i]){
		eg=tp=0; dfs1(i,0);
		if (eg!=tp){ puts("0"); return 0; }
		E=0; dfs2(i,0);
		ans=1; dfs3(pnt[E],E); tmp=ans;
		ans=1; dfs3(pnt[E^1],E); tmp+=ans;
		sum=(ll)sum*tmp%mod;
	}
	printf("%d\n",sum);
	return 0;
}


Measured memory_bytes: 14720
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  string s;
  cin >> s;

  rep(i, s.size()) {
    if (i&1) {
      if (s[i] == 'R') {
        cout << "No" << endl;
        return 0;
      }
    } else {
      if (s[i] == 'L') {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
}


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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int mod = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  
template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

int main(){
	int n, ans=0;
	cin >>n;
	if(n==1) cout <<"Hello World\n";
	else{
		int a,b;
		cin >>a >>b;
		cout << a+b <<"\n";
	}
}


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

int main(){
	double x,y,dx,dy,pi,d,rad,prad;
	char camma;
	x=y=0;
	pi=3.14159265359;
	prad=90;
	while(cin>>d>>camma>>rad){
		if(d==0 && rad==0)break;
		dx=d*cos(prad*pi/180);
		dy=d*sin(prad*pi/180);
		x+=dx;
		y+=dy;
		prad=prad-rad;
	//	cout<<"x:"<<x<<endl;
		//cout<<"y:"<<y<<endl;
	}
	cout<<(int)x<<endl;
	cout<<(int)y<<endl;
	//while(1);
	return 0;
}

Measured memory_bytes: 1228
# -*- coding: utf-8 -*-
import math
import sys

import math
import sys


S = str(sys.stdin.readline().rstrip())
K = int(sys.stdin.readline().rstrip())


def solve(s, k):
  keta = 0
  for c in s:
    keta += int(c)**(5*10**5)
    if keta >= k:
      return(int(c))

if __name__ == "__main__":
  print(solve(S,K))


Measured memory_bytes: 3736
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        if (x == 3 || x == 5 || x==7) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}


Measured memory_bytes: 23636
import std.stdio, std.string, std.conv;
import std.algorithm;

void main() {
    auto inputs = getStdin!(int[]).sort!("a > b")[0..3];
    foreach (n; inputs) n.writeln;
}

T getStdin(T)() {
    string[] cmd;
    string line;
    while ((line = chomp(stdin.readln())) != "") cmd ~= line;
    return to!(T)(cmd);
}

Measured memory_bytes: 2472
x=int(input())
list1=[1,2,3,4,5,6,7,8,9,10,11,12,13]
list2=[1,2,3,4,5,6,7,8,9,10,11,12,13]
list3=[1,2,3,4,5,6,7,8,9,10,11,12,13]
list4=[1,2,3,4,5,6,7,8,9,10,11,12,13]
for i in range(x):
    a,b=map(str,input().split())
    b=int(b)
    if a=="S":
        list1.remove(b)
    if a=="H":
        list2.remove(b)
    if a=="C":
        list3.remove(b)
    if a=="D":
        list4.remove(b)
for j in range(len(list1)):
    print("S",list1[j])
for j in range(len(list2)):
    print("H",list2[j])
for j in range(len(list3)):
    print("C",list3[j])
for j in range(len(list4)):
    print("D",list4[j])


Measured memory_bytes: 5620
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }



int main() {
  int n, h, w;
  cin >> n >> h >> w;

  cout << (n - h + 1) * (n - w + 1) << endl;


  
  return 0;
}

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

int main(void){
	int n,card[4][14]={},num,efda;
	char ch;
  cin>>n;
  for (int i=0;i<n;i++){
      cin>>ch>> num;;
      switch (ch){
        case 'S':
         card[0][num]=1;
          break;
        case 'H':
         card[1][num]=1;
          break;
        case 'C':
         card[2][num]=1;
          break;
        case 'D':
         card[3][num]=1; 
          break;
      }
    
     
  }
//    for (int i=0;i<4;i++){
//    	for (int j=0;j<13;j++){
//    		if(j!=0)cout<<" ";
//          		cout<<card[i][j];
//       }
//          cout<<endl;
//    }
  	for (int i=0;i<4;i++){
    	for (int j=1;j<14;j++){
    		if(card[i][j]==0){
              switch (i){
                case 0:
                 ch='S';
                  break;
                case 1:
                 ch='H';
                  break;
                case 2:
                 ch= 'C';
                  break;
                case 3:
                 ch='D'; 
                  break;
      			}
              cout<<ch<<' '<<j<<endl;
       }
        }
    }
  
  
  
	return 0;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
 
using namespace std;
typedef unsigned long long uwl;
 
int main() {
#ifdef  DEBUG
  ifstream in("input.txt");
  cin.rdbuf(in.rdbuf());
#endif  // for local.
  uwl a, b, k;
  uwl ans_a, ans_b;
  cin >> a >> b >> k;
  ans_a = a < k ? 0 : a-k;
  k = a > k ? 0 : k-a;
  ans_b = b < k ? 0 : b-k;
 
  cout << ans_a << " " << ans_b << endl;
  
  return 0;
}

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

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

    int num_v = 0;
    for (int i = 0; i < S.size(); i ++)
        if (S[i] == 'o')
            num_v += 1;
    int max_v = num_v + 15 - S.size();

    if (max_v >= 8)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
   	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <fstream>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;
typedef pair<int,int> PI;
typedef vector<PI> VPI;
typedef unsigned long long ull;
typedef long long ll;

#define FOR(i, n) for(int i=0;i<(n);++i)
#define REP(i,s,n) for(int i=s;i<=n;++i)
#define SZ(x) ((int)(x).size())
#define LOOP(i,x) FOR(i,SZ(x))
#define IT(it,x) for(typeof((x).begin()) it = (x).begin();it!=(x).end();++it)
#define ALL(x) (x).begin(), (x).end()
#define ST first
#define ND second
#define MP make_pair
#define PB push_back
#define gc getchar

#define MAXN 100 * 1000 + 7

int stones[MAXN], dp[MAXN];

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

	int n;
	cin >> n;

	for (int i = 1; i <= n; i++) cin >> stones[i];

	dp[1] = 0;
	dp[2] = abs(stones[1] - stones[2]);

	for (int i = 3; i <= n; i++) dp[i] = min(dp[i - 1] + abs(stones[i] - stones[i - 1]), dp[i - 2] + abs(stones[i] - stones[i - 2]));

	cout << dp[n] << endl;

	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
int n,T;
int a[maxn],mx[maxn];
int main(){
	scanf("%d%d",&n,&T);
	T/=2;
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	mx[n]=a[n];
	for(int i=n-1;i>=1;i--)
		mx[i]=max(mx[i+1],a[i]);
	int ans=1,cnt=0;
	for(int i=1;i<=n;i++){
		if(mx[i+1]-a[i]>=ans){
			if(mx[i+1]-a[i]>ans){
				ans=mx[i+1]-a[i];
				cnt=1;
			}else{
				cnt++;
			}
		}
	}
	cout<<cnt<<endl;
	
	return 0;
}

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

using namespace std;

int main()
{	
	string s1, s2;
	int  a, b;
	string u;
	cin >> s1 >> s2;
	cin >> a >> b;
	cin >> u;
	
	if (u == s1)
	{
		a--;
	} else {
		b--;
	}
	cout << a << " " << b;
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (1LL<<60)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
typedef unsigned long long int ull;
typedef long long lint;
 
int main(void){
  string S;
  cin >> S;
  int L=S.length();
  int ans=L,count=0;
  rep(i,L){
    if(S[i]=='S') count++;
    else if(count>0) count--,ans-=2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 720
#include<iostream>
#include<vector>
#include<queue>
#include<functional>
#include<boost/optional.hpp>

template<class T>using p_queue = std::priority_queue<T, std::vector<T>, std::greater<>>;

int main()
{
	boost::optional<std::uint64_t> first;
	p_queue<std::uint64_t> queue;
	std::uint64_t N, C, K;
	std::cin >> N >> C >> K;
	for (int i{}; i < N; ++i) 
	{
		std::uint64_t v;
		std::cin >> v;
		queue.emplace(v);
	}
	int count{};
	int size{};
	while (queue.size())
	{
		auto top = queue.top();
		queue.pop();
		if (!first)
		{
			first = top;
			size = 1;
		}
		else
		{
			if (*first + K < top)
			{
				++count;
				first = top;
				size = 1;
			}
			else if (size == C)
			{
				++count;
				first = top;
				size = 1;
			}
			else
			{
				++size;
			}
		}
	}
	++count;
	std::cout << count << std::endl;
}

Measured memory_bytes: 1400
"use strict"
function main(arg) {
    var data = arg.trim().split("\n")[1].split(" ").map(Number)
    var N = data.length
    data = data.sort((a,b) => b - a )
    var sum = 0
    for (var i = 0; i < data.length; i++) {
        sum += data[i]
    }
    var tmp = Math.floor(sum / N)
    // console.log(tmp)
    console.log(Math.min(
        calc(data, tmp),
        calc(data, tmp + 1)
    ))
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

function calc(data, p) {
    var sum = 0
    for (var i = 0; i < data.length; i++) {
        sum += Math.pow((data[i] - p), 2)
    }
    return sum
}

Measured memory_bytes: 21064
n = int(input())
a = set()
i = 2
res = 0
while i * i <= n:
    if (n % i) == 0:
        count = 0
        while n % i == 0:
            count += 1
            n //= i
        dif = 1
        while count >= dif:
            res += 1
            count -= dif
            dif += 1
    i += 1
if n != 1:
    res += 1
print(res)


Measured memory_bytes: 62956
#include <bits/stdc++.h>
#include <vector>
#include <queue>
#include <set>
#include <iostream>
#include <iomanip>
using namespace std;
typedef long long LL;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

int main(){
    LL x, y;
    cin >> x >> y;

    LL absDiff = abs(abs(y) - abs(x));

    LL ans = absDiff;
    if(x + absDiff == y){}
    else if(-x + absDiff == y){ans++;}
    else if(-x - absDiff == y){ans++;}
    else if(x - absDiff == y){ans+=2;}
    
    
    cout << ans << endl;
    return 0;
}

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

using namespace std;

#define fi first
#define se second
#define eb emplace_back
#define mt make_tuple
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

ll INF=LLONG_MAX;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	int a,b; 
	cin >> a >> b;
	if(a>b)swap(a,b);
	for(int i=0; i<b; i++)cout << a;
}
	
// READ & UNDERSTAND
// ll, int overflow, array bounds, memset(0)
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN


Measured memory_bytes: 256
#include<cstdio>
#include<bits/stdc++.h>
typedef long long int ll;
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR_IN(i, a, b) for(int i = (a); i < (b); i++)
#define BETWEEN(x, a, b) ((x) >= (a) && (x) <= (b))
#define BIT(b, i) (((b) >> (i)) & 1)
#define LOG_F 1
#define LOG(...) if(LOG_F) fprintf(stderr, __VA_ARGS__)

using namespace std;

ll pow(int x, int n){
  return n == 0 ? 1 : x * pow(x, n - 1);
}


/*
a1 b1
..
a3 b3

YES NO
 */
int v[4];


int main(){
  REP(i,3){
    int a,b;
    cin>>a>>b;
    a--;b--;
    v[a]++;
    v[b]++;
  }

  int odd=0;
  REP(i,4){
    if(v[i]%2) odd++;
  }

  if(odd<=2)
    cout<<"YES\n";
  else
    cout<<"NO\n";

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int max2(int a, int b, int c)
{
	int max=a;
		if  (b>max)max=b;
		if (c>max)max=c;
		return max;
	}

int main()
{
	int p, q, r;
	
	scanf("%d %d %d", &p, &q, &r);
	
	int sum=p+q+r;
	
	printf("%d", sum-max2(p, q, r));
	
	return 0;
}

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

ll choose2(ll n) {
  return n*(n-1)/2;
}

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

  // 入力
  vector<int> A(N);
  rep(i, N) {
    cin >> A[i];
    A[i]--;
  }

  // 分布
  vector<int> cnt(N);
  rep(i, N) {
    cnt[A[i]]++;
  }

  // 消さないときの答え
  ll total = 0;
  rep(i, N) {
    total += choose2(cnt[i]);
  }

  // 答えを計算して出力
  rep(i, N) {
    ll minus = choose2(cnt[A[i]]);
    ll plus = choose2(cnt[A[i]] - 1);
    ll ans = total - minus + plus;
    cout << ans << endl;
  }

}


Measured memory_bytes: 4096
# ABC159d


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    # 再帰関数を使わない限りPypyで出すこと

    def dump(*args):
        sys.stderr.write(str(args))

    from collections import Counter
    import math

    def c_count(n, r):  # 組み合わせ
        if n - r < 0:
            return 0
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

    class Combination:  # メモ化組み合わせ
        def __init__(self):
            super().__init__()
            self.dp = dict()

        def count(self, n, r):
            if self.dp.get((n, r)) != None:
                return self.dp[(n, r)]
            self.dp[(n, r)] = c_count(n, r)
            return self.dp[(n, r)]

    n = int(input())
    a = list(map(int, input().split()))
    c = Counter(a)
    d = Combination()
    e = dict()

    ss = 0

    for i in c:
        #print(i, c[i])
        e[i] = d.count(c[i], 2)
        # print(e[i])
        ss += e[i]

    for i in range(n):
        t = e[a[i]]
        w = t * (c[a[i]] - 2) // c[a[i]]
        #print(a[i], t, w)
        w = w if w >= 0 else 0
        print(ss-t+w)


if __name__ == '__main__':
    main()


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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

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

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#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 range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

// s n m
// xi

// ti
// pi

// ??????S??????????????????????????????  sum (ti-S-x[pi]) ti-S-x[pi]>=0

// ??????ti-x[pi]????????£??????????????????????????????

// dp[i][d] i???????????§????????¢???d??????????????§??????

// cost[k]=tk-x[pk]
// sum(j,i)=sum_{j+1<=k<=i}{cost[k]-cost[j+1]}

// sum(i,l)+sum(j,k)= (cost[l]-cost[i+1])+(cost[k]-cost[j+1])

//  (cost[k+1]+cost[k+2]+...cost[l-1]+cost[l]-cost[i+1]*(l-k))
// -(cost[k+1]+cost[k+2]+...cost[l-1]+cost[l]-cost[j+1]*(l-k))
// (cost[j+1]-cost[i+1])*(l-k)>=0

// sum(i,k)+sum(j,l)= (cost[k]-cost[i+1])+(cost[l]-cost[j+1])

// dp[i][d]=min_{0<=j<i} {dp[j][d-1]+sum(j,i)}

// O(N^2M)


// Monge property
// i<=j k<=l
// dp[i][l]+dp[j][k]>=dp[min(i,j)][min(l,k)]+dp[max(i,j)][max(l,k)]=dp[i][l]+dp[j][k]

// O(NM)

int s,n,m;
int x[2010];
int t[2010],p[2010];
int len[2010];
int cost[2010][2010];
ll dp[2010][2010];

void solve(int d,int l,int r,int optl,int optr){
	if(r-l<=0) return;
	int mid=(l+r)/2;
	int index=-1;
	for(int i=optl;i<optr;++i){
		int cur=dp[d][i]+cost[i][mid-1];
		if(dp[d+1][mid]>cur) dp[d+1][mid]=cur,index=i;
	}
	solve(d,l,mid,optl,index+1);
	solve(d,mid+1,r,index,optr);
}

int main(void){
	cin >> s >> n >> m;
	rep(i,s) cin >> x[i+1];
	rep(i,n) cin >> t[i] >> p[i];
	rep(i,n) len[i]=t[i]-x[p[i]];
	sort(len,len+n);
	for(int i=n-1;i>=0;--i) range(j,i,n) cost[i][j]+=cost[i+1][j]+len[j]-len[i];
	rep(i,m+1)rep(j,n+1) dp[i][j]=inf;
	rep(i,m+1) dp[i][0]=0;
	rep(d,m) solve(d,1,n+1,0,n+1);
	cout << dp[m][n] << endl;
	return 0;
}

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

using namespace std;

#define ll long long

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

    vector<int> a(n, 0);

    for(int i = 0;i < k;++i){
        int d;
        cin >> d;
        for(int j = 0;j < d;++j){
            int tmp_a;
            cin >> tmp_a;
            a[tmp_a-1] = 1;
        }
    }

    int ans = 0;
    for(int i = 0;i < a.size();++i){
        if(a[i] == 0){
            ans += 1;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
#define per(i,x,y) for (int i=(x);i>=(y);i--)
#define ll long long
#define ull unsigned long long
#define ld long double
#define inf 1000000001
#define INF 1000000000000000001ll
#define pii pair<int,int>
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define sqr(x) ((x)*(x))
#define y1 y1_
#define mset(x,y) memset((x),(y),sizeof(x))
#define mcpy(x,y) memcpy((x),(y),sizeof(y))
using namespace std;
const ld pi=acos(-1);
const ld eps=1e-8;
template<typename T> void cmin(T &x,T y){x=y<x?y:x;}
template<typename T> void cmax(T &x,T y){x=y>x?y:x;}
//////////////////////// header files ////////////////////////
ll read(){
	char ch=getchar();ll x=0;int op=1;
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') op=-1;
	for (;isdigit(ch);ch=getchar()) x=(x<<1)+(x<<3)+ch-'0';
	return x*op;
}
void write(ll a){
	if (a<0) putchar('-'),a=-a;
	if (a>=10) write(a/10);putchar(a%10+'0');
}
////////////////////////// fast i/o //////////////////////////
#ifdef mod
ll ksm(ll x,ll p){
	ll ret=1;
	for (;p;p>>=1,x=x*x%mod) if (p&1) ret=ret*x%mod;
	return ret;
}
ll getinv(ll x){return ksm(x,mod-2);}
#else
ll ksm(ll x,ll p){
	ll ret=1;
	for (;p;p>>=1,x=x*x) if (p&1) ret=ret*x;
	return ret;
}
#endif
//////////////////////////// qpow ////////////////////////////
#define N 300005
int n,pre[N][2],suf[N][2];char s[N];
//#define local
int main(){
#ifdef local
	freopen("test.in","r",stdin);freopen("test.out","w",stdout);
#endif
	n=read();scanf("%s",s+1);
	rep (i,1,n){
		pre[i][0]=pre[i-1][0];pre[i][1]=pre[i-1][1];
		pre[i][0]+=s[i]=='W';pre[i][1]+=s[i]=='E';
	}
	per (i,n,1){
		suf[i][0]=suf[i+1][0];suf[i][1]=suf[i+1][1];
		suf[i][0]+=s[i]=='W';suf[i][1]+=s[i]=='E';
	}
	int ans=inf;
	rep (i,1,n){
		ans=min(ans,pre[i-1][0]+suf[i+1][1]);
		//cerr<<"i="<<i<<": "<<pre[i-1][0]+suf[i+1][1]<<'\n';
	}
	cout<<ans<<'\n';
	return 0;
}
// sample data:
/*

*/

// rest:
/*

*/

Measured memory_bytes: 5248
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int N = sc.nextInt();
   String[] words = new String[N];
   String ss = "";
   boolean flg = false;
   for(int i =0;i<N;i++) 
   {
     ss = sc.next();
     if(Arrays.asList(words).contains(ss))
     {
       flg = true;
       break;
     }
     words[i] = ss;
   }
   char start = words[0].charAt(words[0].length()-1);
   if(!flg)
   {
   		for(int i =1;i<N;i++) 
  		{
			if(start!=words[i].charAt(0))
            {
            	flg=true;
              	break;
            }
           	start = words[i].charAt(words[i].length()-1);
	  	}
   }
   if(flg) System.out.println("No");
   else System.out.println("Yes");
 }
}

Measured memory_bytes: 23636
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

      Scanner sc = new Scanner(System.in);
		
      int n = sc.nextInt();
	  int k = sc.nextInt();
	  int x = sc.nextInt();
	  int y = sc.nextInt();
	  
      System.out.println(n<k ? x*n : x*k+y*(n-k));
    }
}

Measured memory_bytes: 35700
#include <bits/stdc++.h>
int h,n,a[10005],b[10005],f[10005];
int main(){
	scanf("%d%d",&h,&n);
	for(int i=1;i<=n;++i)
		scanf("%d%d",&a[i],&b[i]);
	f[0]=0;
	for(int i=1;i<=h;++i){
		f[i]=1e9;
		for(int j=1;j<=n;++j){
			int d=std::max(0,i-a[j]);
			f[i]=std::min(f[i],f[d]+b[j]);
		}
	}printf("%d",f[h]);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100003,INF=1<<30;

int main(){
    
    int N;cin>>N;
    vector<pair<int,int>> A(N);
    vector<int> mini(N),mini2(N);
    for(int i=0;i<N;i++) cin>>A[i].first>>A[i].second;
    
    sort(all(A));
    mini[N-1]=A[N-1].second;
    
    for(int i=N-2;i>=0;i--){
        mini[i]=min(mini[i+1],A[i].second);
    }
    
    mini2[0]=A[0].second;
    for(int i=1;i<N;i++){
        mini2[i]=min(mini2[i-1],A[i].second);
    }
    
    int ans=0;
    
    for(int i=N-2;i>=0;i--){
        int Aleft=A[N-1].first,Aright=min(A[N-1].second,mini[i+1]);
        int Bleft=A[i].first,Bright=A[i].second;
        
        if(i>0){
            int x,y;
            x=max(min(Aright,mini2[i-1])-Aleft+1,0)+max(Bright-Bleft+1,0);
            y=max(Aright-Aleft+1,0)+max(min(Bright,mini2[i-1])-Bleft+1,0);
            
            ans=max(ans,max(x,y));
        }else{
            ans=max(ans,max(Aright-Aleft+1,0)+max(Bright-Bleft+1,0));
            //cout<<max(Aright-Aleft+1,0)+max(Bright-Bleft+1,0)<<endl;
        }
    }
    
    cout<<ans<<endl;
    
}



Measured memory_bytes: 1792
#include<stdio.h>

int main(void){
	int n,d,x;
	int a;

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

	d--;
	for(;n>0;n--){
		scanf("%d",&a);
		x+=d/a+1;
	}

	printf("%d\n",x);

	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
using namespace std;

typedef long long ll;
#define modulo 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9


int main() {
	int l[3];
	cin >> l[0] >> l[1] >> l[2];
	sort(l, l + 3);
	cout << l[0] * l[1] / 2 << endl;


	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <math.h>

using namespace std;


int main() {

	long long n; cin >> n;
	vector<pair<int, int>> v;
	if (n % 2 == 0) {
		int c = 0;
		while (n % 2 == 0) {
			n /= 2;
			c++;
		}
		v.push_back(make_pair(2, c));
	}
	for (long long i = 3; i * i <= n; i += 2) {
		if (n % i == 0) {
			int c = 0;
			while (n % i == 0) {
				n /= i;
				c++;
			}
			v.push_back(make_pair(i, c));
		}
	}

	int ans = 0;
	for (auto _v : v) {
		for (int i = 1; i * (i-1) / 2 <= _v.second; i++) {
			ans++;
		}
		ans--;
	}

	if (n != 1)
		ans += 1;

	cout << ans << endl;

	return 0;
}

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

using namespace std;

int main() {
	string s;
	int firstPos = -1, lastPos;
	cin >> s;
	for (int i = 0; i < s.length(); ++i){
		if (s[i] == 'Z')
			lastPos = i;
		if (s[i] == 'A' && firstPos == -1)
			firstPos = i;
	}
	cout << lastPos - firstPos + 1;
	return 0;
}

Measured memory_bytes: 640
class PriorityQueue
  def initialize(n = 0, &comp)
    @heap = Array.new(n, 0)
    @node_num = n
    if !block_given?
      @comp = Proc.new { |x, y| x <= y }
    else
      @comp = comp
    end
  end

  attr_reader :heap

  def push(x)
    i = @node_num # 自分のノード番号
    @node_num += 1
    while i > 0
      par = (i - 1) / 2 # 親のノード番号
      break if @comp.call(@heap[par], x) # 逆転してないなら抜ける
      # 親ノードを下ろして自分を上に
      @heap[i] = @heap[par]
      i = par
    end
    @heap[i] = x
  end

  alias_method(:<<, :push)

  def pop
    # 最(小|大)値
    ret = @heap[0]
    # 根にもってくる値
    @node_num -= 1
    x = @heap[@node_num]
    # 根から下ろしていく
    i = 0
    while i * 2 + 1 < @node_num
      # 子どうしを比較
      a, b = i * 2 + 1, i * 2 + 2
      a = b if b < @node_num && !@comp.call(@heap[a], @heap[b])
      break if @comp.call(x, @heap[a])
      @heap[i] = @heap[a]
      i = a
    end
    @heap[i] = x
    return ret
  end

  def get
    @node_num == 0 ? nil : @heap[0]
  end

  def empty?
    return get.nil?
  end
end

n, m = gets.split.map(&:to_i)
a = gets.split.map(&:to_i).sort.reverse
q = PriorityQueue.new(n) { |x, y| x > y }
a.each do |ai|
  q << ai
end
m.times do
  max_n = q.pop()
  q << (max_n / 2)
end
p q.heap.inject(:+)


Measured memory_bytes: 14488
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <climits>
using namespace std;

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

#define INF INT_MAX/3
#define REP(i,n) for(int i=0;i<n;i++)

int main(){
	ll N;
	ll K;
	cin>>N;
	cin>>K;
	vector<ll> arr(N);
	vector<ll> asiato(N);

	REP(i,N){
		cin>>arr[i];
	}

	//閉路検出
	//ダブリングというテクニックでも解ける
	fill(asiato.begin(),asiato.end(),-1);
	
	ll syuuki = 1;
	ll index = 0;
	vector<ll> counts;
	counts.push_back(index);
	asiato[index] = 0;
	
	
	while(asiato[arr[index]-1] == -1){
		ll next_index = arr[index] - 1;
		asiato[next_index] = counts.size();
		index = next_index;
		counts.push_back(index);	//next_indexは新発見なので追加
	}
	syuuki = counts.size() - asiato[arr[index]-1];//ワープ回数- 何番目にワープしたところが閉路スタートか?

	if(K < counts.size()){
		cout<<counts[K]+1<<endl;
	}
	else{
		auto nokori = K - asiato[arr[index]-1];
		auto amari = nokori % syuuki;
		cout<<counts[asiato[arr[index]-1] + amari]+1<<endl;
	}
	return 0;
}



Measured memory_bytes: 8500
import java.util.*;

public class Main {
    public static void main(String[] args) {
        //コード
        Scanner scanner = new Scanner(System.in);
        int N = Integer.parseInt(scanner.next());
        int Q = Integer.parseInt(scanner.next());
        String S = scanner.next();

        int[] ac = new int[N];
        Arrays.fill(ac, 0);

        for (int i = 0; i < S.length()-1; i++) {
            if(S.charAt(i) == 'A' && S.charAt(i+1) == 'C') {
                ac[i+1] = ac[i] + 1;
            } else {
                ac[i+1] = ac[i];
            }
        }
        for (int i = 0; i < Q; i++) {
            Integer l = Integer.parseInt(scanner.next()), r = Integer.parseInt(scanner.next());
            int count = 0;
            if(S.length() < l) continue;
            if(S.length() < r)  r = S.length();
            count = ac[r-1] - ac[l-1];
            System.out.println(count);
        }

    }
}


Measured memory_bytes: 63052
#include<bits/stdc++.h>
using namespace std;int a,b,c,d,ans;int main(){cin>>a>>b>>c>>d;for(int i=0;i<=a&&500*i<=d;i++)for(int j=0;j<=b&&100*j+500*i<=d;j++)for(int k=0;k<=c&&50*k+100*j+500*i<=d;k++)if(500*i+100*j+50*k==d)ans++;cout<<ans<<endl;return 0;}

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

int n,m;
vector<int> a,b;

struct UnionFind {
    vector<int> parent;//-集合のサイズ

    UnionFind(int N) {
        parent=vector<int>(N,-1);
    }

    int root(int x) {
        if (parent[x] < 0) return x;
        return parent[x] = root(parent[x]);
    }

    int size(int x){
        return -parent[root(x)];
    }

    bool unite(int x, int y) {
        x=root(x);
        y=root(y);
        if (x==y) return false;
        if(size(x)<size(y)) swap(x,y);
        parent[x]+=parent[y];
        parent[y]=x;
        return true;
    }

    bool same(int x, int y) {
        return root(x)==root(y);
    }
};

int main(){

    cin >> n >> m;

    a=vector<int>(m);
    b=vector<int>(m);

    rep(i,m){
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
    }

    UnionFind tree(n);
    vector<ll> ans(m);
    ans[m-1]=(ll)n*(n-1)/2;
    for(int i=m-1;i>0;i--){
        ans[i-1]=ans[i];
        if(tree.root(a[i])!=tree.root(b[i])){
            ans[i-1]-=(ll)tree.size(a[i])*tree.size(b[i]);
            tree.unite(a[i],b[i]);
        }
    }

    rep(i,m){
        cout << ans[i] << endl;
    }

    return 0;
}

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

int main(){
    ll n;
    string s;
    ll ans = 0;
    cin >> n >> s;
    ll cnt_r = 0;
    ll cnt_g = 0;
    ll cnt_b = 0;
    for(int i = 0; i < n; i++){
        if(s[i] == 'R'){
            cnt_r++;
        }
        else if(s[i] == 'G'){
            cnt_g++;
        }
        else{
            cnt_b++;
        }
    }
    ans = cnt_b*cnt_g*cnt_r;
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            if(s[i] != s[j] && s[j] != s[2*j-i] && s[2*j-i] != s[i] && 2*j-i < n){
                ans--;
            }
        }
    }
    cout << ans;
}

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }

        int q = in.nextInt();
        int[] m = new int[q];
        for (int i = 0; i < q; i++) {
            m[i] = in.nextInt();
        }

        for (int mi : m) {
            if (solve(0, mi, a)) {
                System.out.println("yes");
            } else {
                System.out.println("no");
            }
        }
    }

    private static boolean solve(int p, int mi, int[] a) {
        if (mi == 0) {
            return true;
        }

        if (p == a.length || mi < 0) {
            return false;
        }

        return solve(p+1, mi, a) || solve(p+1, mi-a[p], a);
    }
}



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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]D - String Equivalence
            int N = int.Parse(Console.ReadLine());

            var chars = GetChars().ToArray();
            
            var ans = new List<string>[N + 1];
            ans[0] = new List<string>();
            ans[0].Add("a");

            for(int i = 1; i < N; i++)
            {
                ans[i] = new List<string>();

                foreach(var a in ans[i - 1])
                {
                    for(int j = 0; j <= i; j++)
                    {
                        if (IsHyojunkei(chars[j], a))
                        {
                            ans[i].Add(a + chars[j]);
                        }                        
                    }
                }
            }

            foreach(var a in ans[N - 1])
            {
                Console.WriteLine(a);
            }
        }

        static bool IsHyojunkei(char c, string substring)
        {
            for(char a = 'a'; a < c; a++)
            {
                if (!substring.Contains(a))
                {
                    return false;
                }
            }

            return true;
        }

        static IEnumerable<char> GetChars()
        {
            for(char c = 'a'; c <= 'j'; c++)
            {
                yield return c;
            }
        }
    }
}


Measured memory_bytes: 23604
#include<bits/stdc++.h>
using namespace std;
map<string,int>mp;
int main()
{
    int n;
    string w,last;
    cin>>n;
    cin>>last;
    mp[last]=1;
    for(int i=1;i<n;i++)
    {
    	cin>>w;
    	if(mp.find(w)!=mp.end())
    	{
    		cout<<"No"<<endl;
    		return 0;
		}
		mp[w]=1;
    	if(w[0]!=last[last.size()-1])
    	{
    		cout<<"No"<<endl;
    		return 0;
		}
		last=w;
	}
	cout<<"Yes"<<endl;
	return 0;
}


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

int main()
{   char t[1001];
    scanf("%s",t);
    int s=0,n=0,w=0,e=0;
    for(int i=0;i<strlen(t);i++){
        if(t[i]=='N')n++;
        if(t[i]=='S')s++;
        if(t[i]=='W')w++;
        if(t[i]=='E')e++;
    }
    if((n>0&&s>0)||(n==0&&s==0)){
    }else{
        printf("No");
        return 0;
    }
    if((w>0&&e>0)||(w==0&&e==0)){
    }else{
        printf("No");
        return 0;
    }
    printf("Yes");

    return 0;
}


Measured memory_bytes: 128
from itertools import product
N = int(input())
A = [[] for i in range(N)]
for i in range(N):
    ai = int(input())
    for j in range(ai):
        x, y = map(int, input().split())
        x = x - 1
        A[i].append([x, y])


ans = 0
flg = False
for pattern in product([0, 1], repeat=N):
    Y = list(pattern)
    Truth = set()

    for i, p in enumerate(pattern):
        if p == 0:
            continue

        for j, yi in A[i]:
            if Y[j] == yi:
                continue
            else:
                flg = True
                break

        if flg:
            flg = False
            break

    else:
        ans = max(ans, sum(pattern))


print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <math.h>
using namespace std;
int main() {
	int n, a, mi = 1e9, ma = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a;
		mi = min(mi, a);
		ma = max(ma, a);
	}
	cout << ma - mi << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>

using namespace std;

int main(){
    int n,y,x;
    int total;
    bool f=false;
    
    cin >> n >> y;
     x=y/10000;
    for(int i=x;i>=0;i--){
        for (int j=n-i;j>=0;j--){
            total = 10000*i + 5000*j + 1000*((n-i)-j);
            //cout << i << " " << j << " " << (n-i)-j << endl;
            //cout << total << endl;
            if (total==y) {
                cout << i << " " << j << " " << (n-i)-j << endl;
                f=true;
            }
        }
        if(f) break;
    }

    if(f==false){
        cout << -1 << " " << -1 << " " << -1 << endl;
    }
    
    return 0;
}

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

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x[11],r,d;
  
  cin>>r>>d>>x[0];
  
  for(int i=1;i<11;i++){
    x[i]=r*x[i-1]-d;
    cout<<x[i]<<endl;
  }
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>


using namespace std;



int main()
{
   
    int h, w, a, b;
    cin >> h >> w >> a >> b;
    vector<string>p(h);

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (i < b) {
                if (j < a) {
                    p[i] = p[i] + '1';
                }
                else p[i] = p[i] + '0';
            }
            else {
                if (j < a) {
                    p[i] = p[i] + '0';
                }
                else p[i] = p[i] + '1';
            }
        }
    }
    for (int i = 0; i < h; i++)cout << p[i] << endl;
    
    return 0;

}


Measured memory_bytes: 2304
A, B, C = map(int, input().split())

cnt = 0
if(A==B==C and A%2 == 0):
    print("-1")
else:
    while(A%2 == 0 and B%2 == 0 and C%2 == 0):
        tmpA = A
        tmpB = B
        tmpC = C
        cnt += 1
        A = tmpB//2+tmpC//2    
        B = tmpA//2+tmpC//2
        C = tmpA//2+tmpB//2
    print(cnt)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long  a ; string b; cin>>a; cin>>b;
  long long num1=0,num2=0,flag=0;
  for(int i=0;i<b.length();i++){
  	if(b[i]=='.')flag=1;
  	else if(flag) num2=num2*10+(b[i]-'0');
  	else num1=num1*10+(b[i]-'0');
  }
  cout<<(a*num1)+(a*num2)/100<<endl;
}
  


Measured memory_bytes: 3588
n = int(input())
amounts = [1, 6, 9, 36, 81, 216, 729, 1296, 6561, 7776, 46656, 59049]

INF = 10 ** 6
dp = [INF] * (n + 1)
dp[0] = 0
dp[1] = 1
for i in range(2, n + 1):
  for a in amounts:
    r = i - a
    if r >= 0:
      dp[i] = min(dp[i], dp[r] + 1)
print(dp[n])

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

int main() {
	int x, y, z;
	char s;
	cin >> s;
	if (s == 'a' || s == 'i' || s == 'o' || s == 'u' || s == 'e')cout << "vowel" << endl;
	else cout << "consonant"<<endl;
	
	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2147483647)
input=sys.stdin.readline

def search(nodes, searched, labels, v):
  searched[v] = 1
  label = labels[v]
  for l in nodes[v]:
    x, w = l
    if not searched[x]:
      if w %2 == 0:
        labels[x] = label
      else:
        labels[x] = (label + 1) % 2
      search(nodes, searched, labels, x)

def solve(n, nodes):
  searched = [0]*n
  labels = [None]*n
  labels[0] = 0
  search(nodes, searched, labels, 0)
  return labels

def main():
  n = int(input())
  nodes = [[] for _ in range(n)]
  for _ in range(n-1):
    v, u, w = map(int, input().split(' '))
    nodes[v-1].append((u-1,w))
    nodes[u-1].append((v-1,w))
  ans = solve(n, nodes)
  for r in ans:
    print(r)
  

if __name__=='__main__':
  main()

Measured memory_bytes: 84672