akhauriyash/Code-Regression huggingface dataset:
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

//long mod = 10^^9 + 7;
long mod = 998244353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }

void main()
{
	auto S = RD!string;
	bool ans = true;
	foreach (i; 0..S.length)
	{
		if (i % 2 == 0)
		{
			if (S[i] != 'h')
				ans = false;
		}
		else if (S[i] != 'i')
			ans = false;
	}

	writeln(S.length % 2 == 0 && ans ? "Yes" : "No");
	stdout.flush;
	debug readln;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		String ab = a+b;
		int sum = Integer.parseInt(ab);
		int sqrt = (int)Math.sqrt(sum);
		System.out.println(sqrt*sqrt == sum ? "Yes":"No");
	}
}


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

const int M = 3030;
char C[M][M];
long long I[M][M]; // 'I'の縦累積和
long long O[M][M]; // 'I'の横累積和

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

    int h, w;
    cin >> h >> w;
    
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> C[i][j];
            if(C[i][j] == 'I') I[i + 1][j] = 1;
            if(C[i][j] == 'O') O[i][j + 1] = 1;
        }
    }

    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            I[i + 1][j] += I[i][j];
            O[i][j + 1] += O[i][j];
        }
    }

    long long ans = 0;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(C[i][j] == 'J') ans += (I[h][j] - I[i + 1][j]) * (O[i][w] - O[i][j + 1]);
        }
    }

    cout << ans << endl;

    return 0;
}


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

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

  int n, m, X, Y;
  cin >> n >> m >> X >> Y;
  int x_max = -100;
  rep(i, n) {
    int x;
    cin >> x;
    x_max = max(x_max, x);
  }
  int y_min = 100;
  rep(i, m) {
    int y;
    cin >> y;
    y_min = min(y_min, y);
  }
  for (int z = X + 1; z <= Y; ++z) {
    if (x_max < z && y_min >= z) {
      cout << "No War" << endl;
      return 0;
    }
  }
  cout << "War" << endl;
  return 0;
}


Measured memory_bytes: 256
# ABC158c


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

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

    a, b = map(int, input().split())
    from math import floor

    for i in range(2000):
        if floor(i * 0.08) == a and floor(i * 0.1) == b:
            print(i)
            exit(0)
    print(-1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
L = []
for b in range(1001) :
    for p in range(2,12) :
        l = b**p
        if l <= 2000 :
            L.append(l)
L = sorted(list(set(L)))
X = int(input())
for i in range(len(L)+1) :
    if L[i] <= X < L[i+1] :
        print(L[i])
        break


Measured memory_bytes: 3060
#include<stdio.h>
int main()
{
int a,h,m,s,b;
scanf("%d",&a);
if(a>=3600){
	h=a/3600;
	b=a%3600;	
}
else{
	h=0;
	b=a;
}
if(b>=60){
	m=b/60;
	s=b%60;
}
else{
	m=0;
	s=b;
}
printf("%d:%d:%d\n",h,m,s);
return 0;
}


Measured memory_bytes: 2124
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
using P=pair<long long,long long>;
typedef unsigned long long ull;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

  
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);  
  
  int n;
  cin >> n;
  vector<int>vec(n);
  rep(i,n*(n-1)/2){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    a--;
    b--;
    if(c>d)vec[a]+=3;
    if(c<d)vec[b]+=3;
    if(c==d){
      vec[a]++;
      vec[b]++;
    }
  }
  vector<int>z(n);
  rep(i,n) z[i]=vec[i];
  sort(z.begin(),z.end(),greater<int>());
  rep(i,n){
    rep(j,z.size()){
      if(vec[i]==z[j]){
        vec[i]=j+1;
        break;
      }
    }
  }
  rep(i,n){
    cout << vec[i] << endl;
  }
}



Measured memory_bytes: 3144
#define _CRT_SECURE_NO_WARNINGS
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<functional>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<utility>
#include<vector>

#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define FORR(i,a,b) for(int i=(a);i>=(b);--i)
#define REPR(i,n)   FORR(i,n,0)



using namespace std;

int main() {
	int N, v;
	ll W, w, w0;
	vector<int> v0, v1, v2, v3;

	cin >> N >> W;
	REP(i, N) {
		cin >> w >> v;
		if (i == 0) {
			w0 = w;
			v0.push_back(v);
		}
		else {
			if (w == w0) {
				v0.push_back(v);
			}
			else if (w == w0 + 1) {
				v1.push_back(v);
			}
			else if (w == w0 + 2) {
				v2.push_back(v);
			}
			else {
				v3.push_back(v);
			}
		}
	}
	
	sort(v0.begin(), v0.end(), greater<int>());
	sort(v1.begin(), v1.end(), greater<int>());
	sort(v2.begin(), v2.end(), greater<int>());
	sort(v3.begin(), v3.end(), greater<int>());

	int s0[101] = { 0 }, s1[101] = { 0 }, s2[101] = { 0 }, s3[101] = { 0 };
	int l0 = v0.size(), l1 = v1.size(), l2 = v2.size(), l3 = v3.size();

	REP(i, l0) {
		s0[i + 1] = v0[i] + s0[i];
	}
	REP(i, l1) {
		s1[i + 1] = v1[i] + s1[i];
	}
	REP(i, l2) {
		s2[i + 1] = v2[i] + s2[i];
	}
	REP(i, l3) {
		s3[i + 1] = v3[i] + s3[i];
	}

	int ans = 0;
	REP(i, l0 + 1) {
		REP(j, l1 + 1) {
			REP(k, l2 + 1) {
				REP(l, l3 + 1) {
					if ((i + l + j + k)*w0 + j + 2 * k + 3 * l <= W) {
						ans = max(ans, s0[i] + s1[j] + s2[k] + s3[l]);
					}
				}
			}
		}
	}


	cout << ans << endl;

	return 0;
}

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

int main() {
    int H, W, K;
    cin >> H >> W >> K;
    vector<string> S(H);
    for (int i = 0; i < H; i++) {
        cin >> S[i];
    }

    int ans = 1e9;
    for (int i = 0; i < (1 << (H - 1)); i++) {
        vector<int> group(H);
        int n = i;
        int temp = 0;
        group[0] = 0;
        for (int h = 1; h < H; h++) {
            if (n % 2 == 1) {
                group[h] = group[h - 1] + 1;
                temp++;
            } else {
                group[h] = group[h - 1];
            }
            n /= 2;
        }

        vector<int> cnt(group[H - 1] + 1, 0);
        int l = 0;
        bool ok = true;
        for (int r = 0; r < W; r++) {
            for (int h = 0; h < H; h++) {
                if (S[h][r] == '1') {
                    cnt[group[h]]++;
                }
            }
            bool cut = false;
            for (int c : cnt) {
                if (c > K) {
                    cut = true;
                }
            }

            if (cut) {
                if (r - 1 < l) {
                    ok = false;
                } else {
                    l = r;
                    r--;
                    for (int& c : cnt) {
                        c = 0;
                    }
                    temp++;
                }
            }
        }

        if (ok) {
            ans = min(ans, temp);
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
s=input()
n=len(s)
ans=[0]*n
r=0
l=0
for i in range(n-1):
    if s[i]=="R":
        r+=1
    if s[i+1]=="L":
        ans[i]+=(r+1)//2
        ans[i+1]+=r//2
        r=0
    if s[n-i-1]=="L":
        l+=1
    if s[n-i-2]=="R":
        ans[n-i-1]+=(l+1)//2
        ans[n-i-2]+=l//2
        l=0
print(" ".join(map(str,ans)))

Measured memory_bytes: 10484
#include <iostream>
#include <vector>
#include <string.h>
#include <algorithm>
#include <cstring>
#include <queue>
#include <assert.h>
#include <cmath>
#include <deque>
#include <set>
#include <unordered_map>
#include <complex>
#include <fstream>
#include <map>
using namespace std;
using ll = long long;
using ld = long double;
const double eps = 1e-2;

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n; cin>>n; ll k; cin>>k;
	vector<ll> A(n);
	for(int i=0; i<n; i++) cin>>A[i];

	double r = 1.0*(*max_element(begin(A), end(A))), l = 0;
	while(r-l>eps) {
		double mid = (r+l)/2;
		bool flag = 1; ll div = 0;
		for(int i=0; i<n; i++) if(1.0*A[i]-mid>eps) {
			div+=(ceil(1.0*A[i]/mid)-1);
			if(div>k) {flag = 0; break;}
		}
		if(flag) r = mid;
		else l = mid;
	}

	ll ans = 1ll*ceil(r);
	cout << ans << '\n';

	return 0;
}

Measured memory_bytes: 4780
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, char> Pc;
typedef pair<int, string> Ps;

const int dx[4] = {-1, 0, 0, 1};
const int dy[4] = {0, -1, 1, 0};
const int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
const string dir8[8] = {"U", "RU", "R", "RD", "D", "LD", "L", "LU"};

// Self settings
// clang-format off
#define MAX_N 100000
#define MAX 100000
#define INFTY (1<<30)
#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll fact(ll n) { ll res = 1; for(ll i=2;i<=n;++i) res = res * i; return res;}
ll nCr(ll n, ll r) {return (fact(n)/fact(n-r)*fact(r)) ;}
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;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1000100011;
class Point { public: double x, y; Point(double x = 0, double y = 0) : x(x), y(y) {} Point operator+(Point p) { return Point(x + p.x, y + p.y); } Point operator-(Point p) { return Point(x - p.x, y - p.y); } Point operator*(double a) { return Point(a * x, a * y); } Point operator/(double a) { return Point(x / a, y / a); } double abs() { return sqrt(norm()); } double norm() { return x * x + y * y; } bool operator<(const Point& p) const { return x != p.x ? x < p.x : y < p.y; } bool operator==(const Point& p) const { return fabs(x - p.y) < EPS && fabs(y - p.y) < EPS; } };
typedef Point Vector;
double norm(Vector a) { return a.x * a.x + a.y * a.y; }
double abs(Vector a) { return sqrt(norm(a));}
double dot(Vector a, Vector b) { return a.x * b.x + a.y * b.y; }
double cross(Vector a, Vector b) { return a.x * b.y - a.y * b.x; }
struct Segment { Point p1, p2; };
typedef Segment Line;
struct Node { int data; Node *left, *right; Node(int data) : data(data), left(NULL), right(NULL) {} };
// clang-format on

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int R;
  cin >> R;
  double p = M_PI;

  cout << 2.0 * p * R << endl;

  return 0;
}


Measured memory_bytes: 3236
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define LL_MAX LLONG_MAX
#define ULL_MAX ULLONG_MAX
#define ull unsigned long long
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define pb(x) push_back(x)
#define eb(x) emplace_back(x)
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define fore(i, l, r) for (int i = int(l); i < int(r); ++i)
#define mk make_pair
#define endl '\n'

int main()
{
    IOS;
    int n(0);
    vector<int> a(3,0);
    cin>>n>>a[0]>>a[1]>>a[2];
    bool flag=true;
    vector<char> ans(n);
    vector<string> b(n);
    for (int i = 0; i < n; i++)
    {
        cin>>b[i];
    }
    
    for (int i = 0; i < n; i++)
    {
        string s=b[i];
        if(a[s[0]-'A']==0 && a[s[1]-'A']==0)
        {
            flag=false;
            break;
        }

        char c='A'+'B'+'C'-s[0]-s[1];
        if(a[s[0]-'A']==1 && a[s[1]-'A']==1 && a[c-'A']==0)
        {
            if(i!=n-1 && ((b[i+1][0]==s[0] && b[i+1][1]==c) || (b[i+1][0]==c && b[i+1][1]==s[0])))
            {
                a[s[0]-'A']++;
                a[s[1]-'A']--;
                ans[i]=s[0];
                continue;
            }

            if(i!=n-1 && ((b[i+1][0]==s[1] && b[i+1][1]==c) || (b[i+1][0]==c && b[i+1][1]==s[1])))
            {
                a[s[0]-'A']--;
                a[s[1]-'A']++;
                ans[i]=s[1];
                continue;
            }
        }
        if(a[s[0]-'A']>=a[s[1]-'A'])
        {
            a[s[0]-'A']--;
            a[s[1]-'A']++;
            ans[i]=s[1];
        }
        else
        {
            a[s[0]-'A']++;
            a[s[1]-'A']--;
            ans[i]=s[0];
        }
        
    }
    
    if(flag)
    {
        cout<<"Yes"<<endl;
        for (int i = 0; i < n; i++)
        {
            cout<<ans[i]<<endl;
        }
    }
    else
    {
        cout<<"No"<<endl;
    }
    
}

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

int main(){
    using namespace std;
    unsigned long H, W, K;
    cin >> H >> W >> K;
    vector<unsigned long> mp(H);
    for(auto&& i : mp){
        string s;
        cin >> s;
        for(const auto& c : s)(i <<= 1) |= c & 1;
    }
    unsigned long ans{0};
    const auto& cnt = [&H, &W, &mp](unsigned long x, unsigned long y) -> unsigned long {
        unsigned long ret{0};
        for(unsigned long i{0}; i < H; ++i)if(1 & (x >> i))ret += __builtin_popcountl(mp[i] & y);
        return ret;
    };
    for(unsigned long i{0}; i < 1UL << H; ++i)for(unsigned long j{0}; j < 1UL << W; ++j)ans += cnt(i, j) == K;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>

using namespace std;

long long gcd(long long x, long long y){
    if(x % y == 0) return y;
    return gcd(y, x % y);
}

int main(void){
    long long N, M;
    cin >> N >> M;
    string S, T;
    cin >> S >> T;
    long long g = gcd(N, M);
    long long n = N / g;
    long long m = M / g;
    for(int i = 0; i < g; i++){
        // cout << S[n * i] << " " << T[m * i] << endl;
        if(S[n * i] != T[m * i]){
            cout << -1 << endl;
            return 0;
        }
    }
    cout << N * M / g << endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)n;i++)
#define REP1(j,n) for(int j=0;j<(int)n;j++)
#define REPD(i,n) for(int i=n;i>=0;i--)
#define REPD1(j,n) for(int j=n;j=>0;j--)
#define REPS(i,n) for(int i=1;i<=(int)n;i++)
#define REPS1(j,n) for(int j=1;j<=(int)n;j++)
#define rep(i,a,n) for(int i=a;i<=(int)n;i++)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;

int main(void) {
	string s;
	cin >> s;
	int num = s.size() - 2;
	cout << s[0] << num << s[s.size() - 1] << endl;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <queue>
#include <sstream>
#include <fstream>
#include <cmath>
#include <cstring>

using namespace std;
#define int long long
const int mod = 1000000007;

string base[7] = {"J","O","I","JO","JI","OI","JOI"};
int dp[1001][7] = {};

bool solve(char m,int p) {
	for (int i = 0; i < base[p].length(); i++) {
		if (base[p][i] == m) return 1;
	}
	return 0;
}

signed main()
{
	int N;
	string s;
	cin >> N >> s;
	for (int i = 0; i <= N; i++) {
		for (int j = 0; j < 7; j++) {
			if (i == 0) continue;
			else if (i == 1) {
				if (solve('J', j) && solve(s[0], j)) dp[i][j]++;
			}
			else {
				if (solve(s[i - 1], j)) {
					for (int k = 0; k < 7; k++) {
						bool tmp = 0;
						for (int l = 0; l < base[j].length(); l++) {
							if (solve(base[j][l], k)) tmp = true;
						}
						if (tmp == true) dp[i][j] += dp[i - 1][k];
						dp[i][j] %= 10007;
					}
				}
				dp[i][j] %= 10007;
			}
			dp[i][j] %= 10007;
		}
	}
	/*
	for (int i = 0; i <= N; i++) {
		for (int j = 0; j < 7; j++) {
			cout << dp[i][j] << " ";
		}
		cout << endl;
	}
	*/
	int ans = 0;
	for (int i = 0; i < 7; i++) {
		ans += dp[N][i];
		ans %= 10007;
	}
	cout << ans << endl;


}

Measured memory_bytes: 3196
#include<stdio.h>
int main(void){
    char s[7];
    int i;
    for(i=0;i<7;i++){
        scanf("%c",&s[i]);
    }
    if(s[0] == s[6] && s[1] == s[5] && s[2] == s[4]){
        printf("YES");
    }
    else{
        printf("NO");
    }
    return 0;
}

Measured memory_bytes: 128
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
use std::collections::HashSet;
fn main() {
    input!{
        n: usize,
        s: [String; n],
    }
    println!("{}", s.into_iter().collect::<HashSet<String>>().len());
}


Measured memory_bytes: 21404
def main():
    N, M = map(int, input().split())
    X = [int(x) for x in input().split()]
    X = sorted(X)

    if N >= M: return 0
    
    L = []
    for i in range(M-1):
        L.append(X[i+1] - X[i])
    L = sorted(L)
    return sum(L[:M-N])

if __name__ == '__main__':
    print(main())

Measured memory_bytes: 13840
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
//increase stack size
#pragma comment(linker, "/STACK:16777216")

ll mxm() {return LLONG_MIN;}
template<typename... Args>
ll mxm(ll a, Args... args) { return max(a,mxm(args...)); }

ll mnm() {return LLONG_MAX;}
template<typename... Args>
ll mnm(ll a, Args... args) { return min(a,mnm(args...)); }

template<class T> ostream& operator<<(ostream& os,vector<T> V){
	os<<"[ ";for(auto v:V)os<<v<<" ";return os<<"]";
}
template<class L,class R> ostream& operator<<(ostream& os,pair<L,R> P){
	return os<<"("<<P.first<<","<<P.second<<")";
}

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__,__VA_ARGS__)
template<typename Arg1>
void __f(const char* name,Arg1&& arg1){
	cout<<name<<" : "<<arg1<<endl;
}
template <typename Arg1,typename... Args>
void __f(const char* names,Arg1&& arg1,Args&&... args){
	const char* comma=strchr(names+1,',');cout.write(names,comma-names)<<" : "<<arg1<<" | ";__f(comma+1,args...);
}
#else
#define trace(...) 1
#endif

#define ld long double
#define pll pair<ll,ll>
#define ii pair<int,int>
#define vll vector<ll>
#define vii vector<ii>
#define vi vector<int>
#define vpll vector<pll>
#define vld vector<ld>
#define vvld vector<vld>
#define vvi vector<vi>
#define vvll vector<vll>
#define vvpll vector<vpll>
#define vvii vector<vii>
#define I insert
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define all(x)	x.begin(),x.end()

const int mod=1e9+7;
// 128 bit: __int128
inline int add(int a,int b){a+=b;if(a>=mod)a-=mod;return a;}
inline int sub(int a,int b){a-=b;if(a<0)a+=mod;return a;}
inline int mul(int a,int b){return (a*1ll*b)%mod;}
inline int power(int a,int b){int rt=1;while(b>0){if(b&1)rt=mul(rt,a);a=mul(a,a);b>>=1;}return rt;}
inline int inv(int a){return power(a,mod-2);}

struct compare{
	bool operator() (const int &a,const int &b) const{
		return a>b;
	}
};

int main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout<<setprecision(25);
	string s;
	cin >> s;
	if(s == "ABC")
		s = "ARC";
	else s = "ABC";
	cout << s << endl;			
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,n) for (int i=(n-1);i >= 0;i--)
#define all(v) v.begin(),v.end()
#define sz(v) (int)((v).size())
#define MAX(v) *max_element(all(v))
#define MIN(v) *min_element(all(v))
using namespace std; using ll = long long; using P = pair<int,int>;
using vl = vector<ll>; using vvl = vector<vl>;
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cout << H << " ";
    debug_out(T...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
    for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
    return os;
}
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
template<class T>bool chmax(T &a, const T &b) {if(a<b){a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if(b<a){a=b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll mod = 1000000007;
const int dx[8] = {1,0,-1,0,1,1,-1,-1}; const int dy[8] = {0,1,0,-1,1,1,-1,-1};

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    int n,k;
    cin >> n >> k;
    vector<int> cnt(n);
    set<int> st;
    rep(i,k){
        int d;
        cin >> d;
        rep(j,d){
            int a;
            cin >> a;
            st.insert(a);
        }
    }
    cout << n-st.size() << endl;
}

Measured memory_bytes: 3564
#include <iostream>
#include <cmath>
#include <cstring>

using namespace std;

int pedras[100100];
int dp[100100]; ///Guardo os valores da funcao frog;

int frog(int i,int j){

    if(dp[i] != -1){
        return dp[i];
    }

    if(i==j-1){
        return frog(i+1,j)+abs(pedras[i]-pedras[i+1]);
    }

    if(i==j){
        return 0;
    }
    dp[i] = min(frog(i+1,j)+abs(pedras[i]-pedras[i+1]),
                frog(i+2,j)+abs(pedras[i]-pedras[i+2]));
    return dp[i];
}

int main(){

    memset(dp,-1,sizeof(dp));

    int n;
    cin >> n;

    for(int i=0;i<n;i++){
        cin >> pedras[i];
    }

    cout<<frog(0,n-1);
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

int main(){
    string S;
    cin >> S;
    int N = S.length();

    if(S[N-1] == '1' || S[0] == '0'){
        cout << -1 << endl;
        return 0;
    }

    REP(i,N-1){
        int rem = N-2 - i;
        if(S[i] != S[rem]){
            cout << -1 << endl;
            return 0;
        }
    }

    S[N-1] = '1';
    int par = N-1;
    for(int i = N-2; i >= 0; i--){
        printf("%d %d\n", i+1, par+1);
        if(S[i] == '1'){
            par = i;
        }
    }

    return 0;
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int qmax(int &x,int y) {if (x<y) x=y;}
int qmin(int &x,int y) {if (x>y) x=y;}
int read()
{
    char s;
    int k=0,base=1;
    while((s=getchar())!='-'&&s!=EOF&&!(isdigit(s)));
    if(s=='-')base=-1,s=getchar();
    while(isdigit(s)){k=k*10+(s^'0');s=getchar();}
    return k*base;
}
inline void write(int x)
{
    static char cnt,num[15];cnt=0;
    if (!x)
    {
        putchar('0');
        return;
    }
    for (;x;x/=10) num[++cnt]=x%10;
    for (;cnt;putchar(num[cnt--]+48));
}
int n,f,l,r,mid,x;
string ch;
int main()
{
	cin.sync_with_stdio(false);
	cin>>n;
	cout<<0<<endl;fflush(stdout);
	cin>>ch;
	if (ch[0]=='V') return 0;
	if (ch[0]=='M') f=1;	
	l=1;r=n-1;
	while (l<=r)
	{
		mid=(l+r)>>1;
		if (f==1) x=!(mid&1); else x=mid&1;
		cout<<mid<<endl;fflush(stdout);
		cin>>ch;
		if (ch[0]=='V')	return 0;
		if ((ch[0]=='M'&&x)||(ch[0]=='F'&&!x)) l=mid+1; else r=mid-1;
	}
 	return 0;
} 

Measured memory_bytes: 852
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  s = input().strip()
  n = len(s)
  
  i = 0
  ans = [0] * n
  while i < n:
    rc = 0
    while i < n and s[i] == 'R':
      rc += 1
      i += 1
    rl = i-1
    ans[rl]   += ((rc+1)//2)
    ans[rl+1] += (rc//2)
      
    lc = 0
    while i < n and s[i] == 'L':
      lc += 1
      i+=1
    ans[rl]   += (lc//2)
    ans[rl+1] += ((lc+1)//2)
  print(' '.join(map(str, ans)))

if __name__=='__main__':
  main()



Measured memory_bytes: 10484
#include<bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string s;
  cin>>s;
  string aux="";
  aux+=s[5];
  aux+=s[6];
  int month = stoi(aux);
  aux="";
  aux+=s[8];
  aux+=s[9];
  int day = stoi(aux);
  if(month<=4){
   cout<<"Heisei"<<endl;
  }else if(month>4){
    cout<<"TBD"<<endl;
  }
  return 0;
}


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

int main(){
    char c;
    cin >> c;

        if(c =='a'){
            cout << "vowel" << endl;
        }
        else if(c =='i'){
            cout << "vowel" << endl;
        }
        else if(c =='u'){
            cout << "vowel" << endl;
        }
        else if(c =='e'){
            cout << "vowel" << endl;
        }
        else if(c =='o'){
            cout << "vowel" << endl;
        }
        else{
            cout << "consonant" << endl;
        }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <utility>
#include <string>
#include <stack>
#include <regex>
#include <cctype>

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<long long>
#define vvl vector<vector<long long>>

using namespace std;

typedef long long ll;

int main()
{
  char c[3];
  REP(i, 3)
  {
    cin >> c[i];
  }
  REP(i, 3)
  {
    if (c[i] == '1')
    {
      c[i] = '9';
    }
    else if (c[i] == '9')
    {
      c[i] = '1';
    }
  }
  cout << c[0] << c[1] << c[2] << endl;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<climits>
#include<algorithm>
#include<sstream>
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<unordered_set>
#include<unordered_map>
#include<set>
#include<map>
#include<list>

using namespace std;

#define in(s) cin >> s
#define out(s) cout << s << endl
#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define ll long long
#define MOD 1000000007

#define IMIN INT_MIN;
#define IMAX INT_MAX;


int main(){
    int N;
    in(N);
    vector<int> A(N-1);
    vector<int> ans(N, 0);
    rep(i, N-1) in(A[i]);

    rep(i, N-1) ans[A[i]-1]++;
    for(int i: ans) out(i);




	return 0;
}


Measured memory_bytes: 4844
#include <cassert>
#include <cstddef>
#include <numeric>
#include <utility>
#include <vector>

class UnionFind {

public:
  using size_type = std::size_t;
  using container_type = std::vector<size_type>;

protected:
  container_type p, s;

public:
  UnionFind() : p(), s() {}
  explicit UnionFind(const size_type size) : p(size), s(size, 1) {
    std::iota(p.begin(), p.end(), static_cast<size_type>(0));
  }

  size_type size() const { return p.size(); }
  bool empty() const { return p.empty(); }

  size_type find(size_type x) {
    assert(x < size());
    while (p[x] != x)
      x = p[x] = p[p[x]];
    return x;
  }
  bool same(const size_type x, const size_type y) {
    assert(x < size());
    assert(y < size());
    return find(x) == find(y);
  }
  size_type size(const size_type x) {
    assert(x < size());
    return s[find(x)];
  }

  bool unite(size_type x, size_type y) {
    assert(x < size());
    assert(y < size());
    x = find(x);
    y = find(y);
    if (x == y)
      return false;
    if (s[x] < s[y])
      std::swap(x, y);
    s[x] += s[y];
    p[y] = x;
    return true;
  }
};

#include<iostream>
 
int main() {
    int n, q;
    std::cin >> n >> q;
    UnionFind T(n);
    while (q--) {
        int p, a, b;
        std::cin >> p >> a >> b;
        if (p)
            std::cout << (T.same(a, b) ? "1" : "0") << std::endl;
        else
            T.unite(a, b);
    }
    return 0;
}


Measured memory_bytes: 3248
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<map> 
#define INF 0x3f3f3f3f
using namespace std;
typedef long long LL;
const int maxn=1e5+6;
const int mod=1e9+7;
int read(){        
    int s = 0, f = 1;        
    char ch = getchar();        
    while(!isdigit(ch)) {        
        if(ch == '-') f = -1;        
        ch = getchar();        
    }        
    while(isdigit(ch)) {        
        s = s * 10 + ch - '0';        
        ch = getchar();        
    }        
    return s * f;        
}     
int main(){
	int n;
	cin>>n;
	LL ans=0;
	for(int i=1;i<=n;i++){
		if(i%3!=0&&i%5!=0)
		   ans+=i;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3636
#include<stdio.h>
int main()
{
    int A,B;
    int a,b,c;
    scanf("%d%d",&A,&B);
    a=A+B;
    b=A*B;
    c=A-B;
    if(a>b&&a>c){
        printf("%d",a);
    }
    else if(b>c){
        printf("%d",b);
    }
    else{
        printf("%d",c);
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+1;
const int N = 6e5 + 7;
inline int ls(int p){return p<<1;}
inline int rs(int p){return p<<1|1;}
int n,k,a[N];
struct node{
	int l,r,pre;
}t[4*N];

void update(int pos,int v,int l,int r,int p)
{
	if(l == r){
		t[p].pre = v; 
		return;
	}
	int mid = l+r>>1;
	if(pos <= mid) update(pos,v,l,mid,ls(p));
	else update(pos,v,mid+1,r,rs(p));
	t[p].pre = max(t[ls(p)].pre,t[rs(p)].pre); 
	
}
int query(int x,int y,int l,int r,int p)
{
	if(x<=l&&y>=r){
		return t[p].pre;
	}
	int mid = l+r>>1;
	int ans = 0;
	if(x<=mid) ans = max(ans,query(x,y,l,mid,ls(p)));
	if(y>mid) ans = max(ans,query(x,y,mid+1,r,rs(p)));
	return ans;
}
int main()
{
	scanf("%d %d", &n, &k);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        int res = query(max(a[i] - k, 0), a[i] + k,0 , N, 1) + 1;
        ans = max(ans, res);
        update(a[i], res, 0, N, 1);
    }
    cout << ans << endl;
	return 0;	
} 

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

int main(){
  int a,b,c,d,e,f;
  cin>>a>>b>>c>>d;
  e=(a+b);
  f=(c+d);
  if(e>f)cout<<"Left"<<endl;
  else if(e==f)cout<<"Balanced"<<endl;
  else(e<f),cout<<"Right"<<endl;

}

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

int main(){
    int n;
    string s[2] = {"Three","Four"};

    char ch[4] = {'P','W','G','Y'};
    bool f[4] = {};

    cin >> n;

    for(int i = 0; i < n; ++i){
        char a;
        cin >> a;
        for(int j = 0; j < 4; ++j){
            if(a == ch[j]){
                f[j] = true;
            }
        }
    }

    int ans = 0;
    for(int i = 0; i < 4; ++i){
        if(f[i]) ans++;
    }

    cout << s[ans -3] << endl;


}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>
#include <cassert>
#include <numeric>
#include <string>
#include <cstring>
#include <cmath>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long int int64;


const int N = (int) 2e5 + 100;
vector <int> g[N];

pair <int, int> dfs(int v, int par, int cd)
{
    pair <int, int> ans = make_pair(cd, v);

    for (auto to : g[v])
        if (to != par)
            ans = max(ans, dfs(to, v, cd + 1));

    return ans;
}


int main(int,  char **)
{
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

    int n;
    scanf("%d", &n);
    for (int i = 0; i < n - 1; i++)
    {
        int a, b;
        scanf("%d%d", &a, &b);
        a--;
        b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    pair <int, int> mx = dfs(0, 0, 0);
    pair <int, int> mmx = dfs(mx.second, mx.second, 0);
    int d = mmx.first;

    if (d % 3 == 1)
        printf("Second\n");
    else
        printf("First\n");


	return 0;
}




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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

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

    vector<llint> asum(n+1);
    vector<llint> bsum(m+1);
    llint atmp, btmp;
    for(int in=0;in<n;in++) {
        cin >> atmp;
        asum.at(in+1) = asum.at(in) + atmp;
    }
    for(int im=0;im<m;im++) {
        cin >> btmp;
        bsum.at(im+1) = bsum.at(im) + btmp;
    }

    llint ans = 0, anstmp, kb;
    for(llint in=0;in<=n;in++) {
        kb = k - asum.at(in);
        if(kb<0) continue;
        auto im = upper_bound(bsum.begin(), bsum.end(), kb)- bsum.begin();
        anstmp = in + im  - 1;
        chmax(ans, anstmp);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6328
import java.util.Arrays;
import java.util.Scanner;
public class Main{
@SuppressWarnings("resource")
public static void main(String[] args) {
	Scanner sc =new Scanner(System.in);
	int N=sc.nextInt();
	int[] d=new int[N];
	for(int i=0;i<N;i++) {
		d[i]=sc.nextInt();
	}
	Arrays.sort(d);
	System.out.println(d[d.length/2]-d[d.length/2-1]);
}
}

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

using namespace std;

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

    int w, h, n, x, y, a;

    cin >> w >> h >> n;
    vector<vector<bool>> white(h, vector<bool>(w, true));
    for (int i = 0; i < n; ++i) {
        cin >> x >> y >> a;

        if (a == 1 || a == 2) {
            int l = 0, r = w - 1;
            if (a == 1) r = x - 1;
            else l = x;

            for (int xx = l; xx <= r; ++xx)
                for (int yy = 0; yy < h; ++yy)
                    white[yy][xx] = false;
        }
        else {
            int d = 0, u = h - 1;
            if (a == 3) u = y - 1;
            else d = y;

            for (int yy = d; yy <= u; ++yy)
                for (int xx = 0; xx < w; ++xx)
                    white[yy][xx] = false;
        }
    }

    int cnt = 0;
    for (int yy = 0; yy < h; ++yy)
        for (int xx = 0; xx < w; ++xx)
            if (white[yy][xx]) ++cnt;

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
n=int(input())
A=list(map(int,input().split()))
S=[A[0]]
for i in range(n-1):
  S.append(S[-1]+A[i+1])
ans1=0
s1=0
a=-1
for i in range(n):
  a=a*(-1)
  if a==1:
    ans1=ans1+max(0,1-(S[i]+s1))
    s1=s1+max(0,1-(S[i]+s1))
  else:
    ans1=ans1+max(0,S[i]+s1+1)
    s1=s1-max(0,S[i]+s1+1)
ans2=0
a=1
s2=0
for i in range(n):
  a=a*(-1)
  if a==1:
    ans2=ans2+max(0,1-(S[i]+s2))
    s2=s2+max(0,1-(S[i]+s2))
  else:
    ans2=ans2+max(0,S[i]+s2+1)
    s2=s2-max(0,S[i]+s2+1)
print(min(ans1,ans2))

Measured memory_bytes: 14332
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, begin, end) for(ll i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(ll i=(begin)-1;i>=(end);i--)
#define IREP(i, n) IFOR(i,n,0)
#define SORT(a) sort(a.begin(), a.end())
#define ISORT(a) sort(a.begin(), a.end(),greater<ll>())
#define REVERSE(a) reverse(a.begin(), a.end())
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=(" << v[0]; FOR(i_debug, 1, v.size()){ cout << "," << v[i_debug]; } cout << ")" << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)

#define ll long long
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define INF 1000000000000000000

using vec = vector<ll>;
using mat = vector<vec>;
using Pii = pair<ll, ll>;
using PiP = pair<ll, Pii>;
using PPi = pair<Pii, ll>;
using bvec = vector<bool>;
using Pvec = vector<Pii>;


template<typename T> void readv(vector<T> &a) { REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a) { REP(i, a.size()) {cin >> a[i]; a[i]--;} }

ll mod = 1000000007;

int main()
{
	ll N, A, B;
	cin >> N >> A >> B;
	ll ans = min(N * A, B);

	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>
#include<math.h>
//first
using namespace std;
using ll = long long;

typedef struct {
	int par;
	int hei = 1;
	ll mem = 1;
}node_t;
vector<node_t> node;

int root(int a) {
	if (node[a].par == 0) return a;
	else return root(node[a].par);
}

void unite(int art, int brt) {
	int up, low;
	if (node[art].hei >= node[brt].hei) up = art, low = brt;
	else up = brt, low = art;
	node[low].par = up;
	node[up].hei = max(node[up].hei, node[low].hei + 1);
	node[up].mem += node[low].mem;
}
int main(void) {
	ll N, M;
	cin >> N >> M;

	vector<pair<int, int>> bri(M);
	for (int i = 0; i < M; i++) {
		cin >> bri[i].first >> bri[i].second;
	}

	node = vector<node_t>(N + 1);
	vector<ll> ans(M);
	ans[M - 1] = N * (N - 1) / 2;
	for (int i = M - 1; i >= 1; i--) {
		ans[i - 1] = ans[i];
		int a = bri[i].first, b = bri[i].second;
		int art = root(a), brt = root(b);
		if (art == brt) continue;
		ans[i - 1] -= (node[art].mem * node[brt].mem);
		unite(art, brt);
	}

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

}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

void solve()
{
  ll n, m;
  cin >> n >> m;

  ll ans = 1;
  for(ll i = 1; i * i <= m; ++i)
  {
    if (m % i == 0 && i * n <= m)
    {
      ans = max(ans, i);
      if (m / i * n <= m) ans = max(ans, m / i);
    }
  }
  cout << ans;
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 3648
//Disjoint Set: Union Find Tree
#include <iostream>
#include <vector>

using namespace std;

static const int N = 10000;

class DisjointSet {
public:
    vector<int> rank, p;
    DisjointSet(int size);
    void makeSet(int x);
    void unite(int x, int y);
    void link(int x, int y);
    int findSet(int x);
};

DisjointSet::DisjointSet(int size) {
    rank.resize(size, 0);
    p.resize(size, 0);
    for(int i = 0; i < size; i++) makeSet(i);
}

void DisjointSet::makeSet(int x) {
    p[x] = x;
    rank[x] = 0;
}

void DisjointSet::unite(int x, int y) {
    link(findSet(x), findSet(y));
}

void DisjointSet::link(int x, int y) {
    if(rank[x] > rank[y]) {
        p[y] = x;
    } else {
        p[x] = y;
        if(rank[x] == rank[y]) rank[y]++;
    }
}

int DisjointSet::findSet(int x) {
    if(x != p[x]) {
        p[x] = findSet(p[x]);
    }
    return p[x];
}

int main() {
    int n, q, com, x, y;
    cin >> n >> q;
    DisjointSet S(n);
    for(int i = 0; i < q; i++) {
        cin >> com >> x >> y;
        if(com == 0) S.unite(x, y);
        else if(com == 1) {
            if(S.findSet(x) == S.findSet(y)) cout << 1 << endl;
            else cout << 0 << endl;
        }
    }
}


Measured memory_bytes: 3220
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;
using namespace std;
typedef long long int LL;
typedef unsigned long long int ULL;

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

    vector<int> p(n);
    rep(i, n) {
        cin >> p[i];
    }
    int ans = 0;
    rep(i, n - 2) {
        if (p[i + 1] < max(p[i], p[i + 2]) and p[i + 1] > min(p[i], p[i + 2]))
            ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const LL LLINF = 1e16;

int main(){
    int n, k, q;
    cin >> n >> k >> q;
    vector<int> a(n, 0);
    rep(i, q){
        int x;
        cin >> x;
        x--;
        a[x]++;

    }
    rep(i, n){
        // cout << k-(q-a[i]) <<endl;
        cout<< (k-(q-a[i]) > 0 ? "Yes":"No") << endl;
    }
}

Measured memory_bytes: 1024
#include <stdio.h>
#define mod 1000000007
typedef long long ll;

int main(void) {
  ll i, j, k, n, m = 60, cnt[m], a, ans = 0, tmp;
  scanf("%lld", &n);
  for(i = 0; i < m; ++i) cnt[i] = 0;
  for(i = 0; i < n; ++i) {
    scanf("%lld", &a);
    for(j = 0; j < m; ++j) if((a >> j) & 1) cnt[j]++;
  }
  for(i = 0; i < m; ++i) {
    tmp = 1ll << i, tmp %= mod;
    tmp *= cnt[i], tmp %= mod;
    tmp *= n - cnt[i], tmp %= mod;
    ans += tmp, ans %= mod;
  }
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 128
c=[[int(j) for j in input().split()] for i in range(3)]
for i in range(3):
    c[i][0],c[i][1],c[i][2]=c[i][0]-c[i][0],c[i][1]-c[i][0],c[i][2]-c[i][0]
if c[0]==c[1]==c[2]:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		int m = Integer.parseInt(sc.next());
		
		int [][]land = new int [m][2];
		
		for(int i = 0 ;i < m ;i++) {
			land[i][0] = Integer.parseInt(sc.next());
			land[i][1] = Integer.parseInt(sc.next());
		}
		Arrays.sort(land,(x,y) -> x[1] - y[1]);
		
		int now = -1;
		int ans = 0;
		
		for(int i = 0 ; i < m ;i++) {
			if(now <= land[i][0]) {
				now = land[i][1];
				ans++;
			}
		}
		
		System.out.println(ans);
		

	}
}

Measured memory_bytes: 65756
n,w=map(int,input().split())
a,b=[0]*n,[0]*n
for i in range(n):a[i],b[i]=map(int,input().split())
mv=sum(b)
dp=[[10**10 if j!=0 else 0 for j in range(mv+1)]for i in range(n+1)]
for i in range(1,n+1):
	for j in range(1,mv+1):
		if j<b[i-1]:dp[i][j]=dp[i-1][j]
		else:dp[i][j]=min(dp[i-1][j],a[i-1]+dp[i-1][j-b[i-1]])
ans=0
for i in range(mv+1):
	if dp[-1][i]<=w:ans=i
print(ans)

Measured memory_bytes: 171076
ans=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K=int(input())
print(ans[K-1])


Measured memory_bytes: 2940
/* BISMILLAHIR RAHMANIR RAHIM */
#include<bits/stdc++.h>
using namespace std;
#define ll        long long
#define ull       unsigned long long
#define si(x)     scanf("%d", &x)
#define sll(x)    scanf("%lld", &x)
#define ssll(x,y)    scanf("%lld %lld", &x ,&y)
#define sd(x)     scanf("%lf", &x)
#define l0(i,n)   for(ll i=0; i<n; i++)
#define MAX       100005
#define maxn 	  200002
#define pb 		  push_back
#define mk 		  make_pair
#define endl	  "\n"
#define INF 	  1000000000
#define MOD		  1000000007
#define imie(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

int main ()
{
		ios::sync_with_stdio(0);
		cin.tie(0);
		//CODE TONOY
		int a,b,c;
		cin >> a >> b >> c;
		if(c>min(a,b) && c<max(a,b)) cout << "Yes" << endl;
		else cout << "No" << endl;
		return 0;  
}  


Measured memory_bytes: 3588
#include<bits/stdc++.h>
#define forn(a,n) for(int i = a; i < n; i++)
# define mod 10e9 + 7

using namespace std;

typedef long long int ll;
typedef vector<int> vec;
typedef vector<ll> vecl;
typedef unsigned long long int ull;
typedef vector<ull> vecu;


void print(const vec &a)
{
    forn(0,a.size())
        cout << a[i];
    cout << "\n";
}

int main()
{
    #ifdef WIN32
        freopen("input.txt", "r", stdin);
    #endif
    int n;
    cin >> n;
    int c = 0;
    forn(0, n){
        int x, y;
        cin >> x >> y;
        if(x == y)
            c++;
        else
            c = 0;
        if(c == 3)
        {
            cout << "Yes";
            return 0;
        }
        
    }
    cout << "No";
}

Measured memory_bytes: 3616