akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long ll;
const int INF=1e9,MOD=1e9+7,ohara=1e6;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(ll (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrrep(i,a,b) for(ll i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt,ans=LINF,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

int main(void){
       cin.tie(0);
    ios::sync_with_stdio(false);
      
    cin>>s;
    rep(i,Size(s)-1){
        rrep(j,i+1,Size(s)){
            string co;
          if(j-i!=2)continue;
            rrep(l,i,j+1)co+=s[l];
            pos=atoi(co.c_str());
            //Cout(pos);
            ans=min(ans,abs(753-pos));
        }
    }
    Cout(ans);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
struct UnionFind{
    vector<int> par, siz;
    void init(int n){
        par.resize(n);
        siz.resize(n);
        for(int i = 0; i < n; i++){
            par[i] = i;
            siz[i] = 1;
        }
    }
    
    int root(int i){
        if(par[i] == i) return i;
        else return par[i] = root(par[i]);
    }

    bool same(int a, int b){
        return root(a) == root(b);
    }

    int size(int i){
        return siz[root(i)];
    }

    void unite(int a, int b){
        a = root(a);
        b = root(b);
        if(a == b) return;
        if(size(a) < size(b)) swap(a, b);
        siz[a] += siz[b];
        par[b] = a;
    }
};
struct state{
    double x, y, z;
    double r;
};
struct edge{
    int i, j;
    double d;
};
vector<state> G;
edge dist(int i, int j){
    double dis = sqrt((G[i].x - G[j].x)*(G[i].x - G[j].x) + (G[i].y - G[j].y)*(G[i].y - G[j].y) + (G[i].z - G[j].z)*(G[i].z - G[j].z));
    dis -= G[i].r + G[j].r;
    if(dis < 0) dis = 0;
    edge e = {i, j, dis};
    return e;
}
bool comp(const edge &e1, const edge &e2){
    return e1.d < e2.d;
}
int main(){
    while(1){
        int n;
        cin >> n;
        if(n == 0) return 0;
        G.resize(n);
        for(int i = 0; i < n; i++){
            double x, y, z, r;
            cin >> x >> y >> z >> r;
            state s = {x, y, z, r};
            G[i] = s;
        }
        vector<edge> es(n*(n-1)/2);
        int u = 0;
        for(int i = 0; i < n; i++){
            for(int j = i + 1; j < n; j++){
                edge e = dist(i, j);
                es[u] = e;
                u++;
            }
        }
        sort(es.begin(), es.end(), comp);
        UnionFind U;
        U.init(n);
        double ans = 0;
        for(int i = 0; i < n*(n-1)/2; i++){
            edge e = es[i];
            if(!U.same(e.i, e.j)){
                U.unite(e.i, e.j);
                ans += e.d;
            }
        }
        printf("%.3lf\n", ans);
    }
}


Measured memory_bytes: 3256
#define _CRT_SECURE_NO_WARNINGS
#pragma target("avx")
#pragma optimize("O3")
#pragma optimize("unroll-loops")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define all(V) V.begin(),V.end()
typedef long long lint;
typedef std::pair<lint, lint> P;
constexpr int INF = INT_MAX / 2;
constexpr lint LINF = LLONG_MAX / 2;
constexpr double eps = 1e-9;
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
	if (lhs < rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
	if (lhs > rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
inline lint gcd(lint a, lint b) {
	while (b) {
		lint c = a;
		a = b; b = c % b;
	}
	return a;
}
inline lint lcm(lint a, lint b) {
	return a / gcd(a, b) * b;
}
bool isprime(lint n) {
	if (n == 1)return false;
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}
	return true;
}
lint mypow(lint a, lint b) {
	if (!b)return 1;
	if (b & 1)return mypow(a, b - 1) * a;
	lint memo = mypow(a, b >> 1);
	return memo * memo;
}
lint modpow(lint a, lint b, lint m) {
	if (!b)return 1;
	if (b & 1)return modpow(a, b - 1, m) * a % m;
	lint memo = modpow(a, b >> 1, m);
	return memo * memo % m;
}
template<typename T>
void printArray(std::vector<T>& vec) {
	rep(i, vec.size() - 1)std::cout << vec[i] << " ";
	std::cout << vec.back() << std::endl;
}
template<typename T>
void printArray(T l, T r) {
	T rprev = r;
	rprev--;
	for (T i = l; i != rprev; i++) {
		std::cout << *i << " ";
	}
	std::cout << *rprev << std::endl;
}
std::string to_string(std::vector<int>& vec) {
	std::string res = "[";
	rep(i, vec.size() - 1)res += std::to_string(vec[i]) + ", ";
	res += std::to_string(vec.back()) + "]";
	return res;
}
int n,k;
int main() {
	std::cin>>n>>k;
	int ans=k;
	rep(i,n-1)ans*=k-1;
	std::cout<<ans<<std::endl;
	return 0;
}

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

int main() {

	char numbers[4];
	for (int i = 0; i < 4; i++) {
		cin >> numbers[i];
	}

	bool is_good = true;
	for (int i = 0; i < 3; i++) {
		if (numbers[i] == numbers[i + 1]) {
			is_good = false;
		}
	}

	if (is_good) {
		cout << "Good";
	}
	else {
		cout << "Bad";
	}
}

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

const int MOD = 1000000007;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

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

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int N;
int ans = 0;
void dfs(ll x, bool flag3, bool flag5, bool flag7){
    if(x > N) return;
    if(flag3 && flag5 && flag7) ans++;

    dfs(10 * x + 3, true, flag5, flag7);
    dfs(10 * x + 5, flag3, true, flag7);
    dfs(10 * x + 7, flag3, flag5, true);

}

  
int main() {

cin >> N;

dfs(0, 0, 0, 0);

print(ans);



}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <list>
#include <queue>
#include <cmath>
#include <numeric>
#include <iomanip>
using namespace std;

int inf = (1 << 30);
int mod = 1e9 + 7;
int64_t inf64 = (1LL << 60);

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

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

bool check(vector<int> a, int index, int key){
    if(a[index] >= key) return true;
    else return false;
}

int lower_bound(vector<int> a, int key){
    int left = -1, right = a.size();
    while(right - left > 1){
        int mid = left + (left + right) / 2;
        if(check(a, mid, key)) right = mid;
        else left = mid;
    }
    return right;
}

int main(){

    int N, X;
    cin >> N >> X;
    vector<int> L(N);
    for(int i = 0; i < N; i++) cin >> L[i];

    int D = 0, count = 1;
    for(int i = 0; i < N; i++){
        D += L[i];
        if(D <= X) count++;
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

    vector<int> cnt(4, 0);
    for (int i = 0; i < N; ++i) {
        string _s;
        cin >> _s;
        if (_s == "AC") {
            cnt[0]++;
        }
        if (_s == "WA") {
            cnt[1]++;
        }
        if (_s == "TLE") {
            cnt[2]++;
        }
        if (_s == "RE") {
            cnt[3]++;
        }
    }

    cout << "AC x " << cnt[0] << endl;
    cout << "WA x " << cnt[1] << endl;
    cout << "TLE x " << cnt[2] << endl;
    cout << "RE x " << cnt[3] << endl;
}


Measured memory_bytes: 3220
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

template <typename TYPE>
void print_vec(const vector<TYPE>& v, int num=0){
  if(num == 0) num = (int)v.size();
	for(int i=0; i<num; i++){
		cout << v[i] << " ";
	}
	cout << endl;
}

template <typename TYPE>
void print_vec2(const vector<vector<TYPE>>& v){
  cout << endl; cout << "       ";
  for(int i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(int j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}


//https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a#4-%E7%B4%AF%E4%B9%97-an
ll modpow(ll a, ll n, ll MOD){// a^n mod を計算する
	//2分累乗法 計算量O(logN)
	ll res = 1;
	// while(n > 0){
	// 	if(n & 1) res = res * a % MOD;
	// 	a = a * a % MOD;
	// 	n = n >> 1;
	// }
	bitset<30> bit(n);//10^9 < 2^30 なので30としました．
	for(int i=0; i<(int)bit.size(); i++){
		if(bit[i]) res = res * a % MOD;
		a = a * a % MOD;
	}
	return res;
}
int main(){
	ll m, n;
	cin >> m >> n;
	const ll MOD = 1e9 + 7;
	// ll ans = 1;
	// for(int i=0; i<n; i++){
	// 	ans = (ans%MOD * m)%MOD;
	// }
	// cout << ans << endl;
	cout << modpow(m, n, MOD) << endl;

	return 0;
}




Measured memory_bytes: 3124
# Aizu Problem 0222: Prime Quadruplet

import sys, math, os, bisect

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")

def primes2(n):
    """ Input n>=6, Returns a list of primes, 2 <= p < n """
    n, correction = n-n%6+6, 2-(n%6>1)
    sieve = [True] * (n//3)
    for i in range(1,int(n**0.5)//3+1):
      if sieve[i]:
        k=3*i+1|1
        sieve[      k*k//3      ::2*k] = [False] * ((n//6-k*k//6-1)//k+1)
        sieve[k*(k-2*(i&1)+4)//3::2*k] = [False] * ((n//6-k*(k-2*(i&1)+4)//6-1)//k+1)
    return [2,3] + [3*i+1|1 for i in range(1,n//3-correction) if sieve[i]]

primes = primes2(10**7)
quad_max = []
for k in range(3, len(primes)):
    p = primes[k]
    if primes[k-3] == p - 8 and primes[k-2] == p - 6 and primes[k-1] == p - 2:
        quad_max.append(p)


while True:
    n = int(input())
    if n == 0:
        break
    idx = bisect.bisect_right(quad_max, n)
    print(quad_max[idx-1])

Measured memory_bytes: 68708
#include<iostream>
#include <algorithm>
#include <cmath>
using namespace std;

int main(){
  int A,B,C;
  bool judge = false;
  cin >> A >> B >> C;
  for(int i=1;i<=B;i++){
    if(A*i%B==C){
      judge = true;
      break;
    }
  }
  if(judge){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}

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

using namespace std;

#define REP(i, n)   for(int i = 0; i < (n); i++)
#define REPS(i, n)  for(int i = 1; i <= (n); i++)
#define RREP(i, n)  for(int i = (n)-1; i >= 0; i--)
#define RREPS(i, n) for(int i = (n); i > 0; i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define mt make_tuple
#define pb push_back

using ll  = long long;
using pi  = pair<int, int>;
using pl  = pair<ll, ll>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vs  = vector<string>;
using vb  = vector<bool>;
using vvi = vector<vi>;

const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const ll  INFL = 1e18;
const double PI = 3.141592653589793;
const double EPS = 1e-9;

template<class T> bool chmax(T &a, const T &b) { if(a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if(a > b) { a = b; return true; } return false; }

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

    string S; cin >> S;
    int ans = 0;
    int count = 0;
    REP(i, 3)
    {
        if(S[i] == 'R') count++;
        else count = 0;
        chmax(ans, count);
    }
    cout << ans << endl;
}

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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];

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

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

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

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

    vector<int> a(n);
    vector<int> a1(n);
    REP(i,n) {
        cin >> a[i];
        a1[i] = a[i];
    }

    sort(all(a));

    int cnt = 0;
    REP(i,n) {
        if(a1[i] != a[i]) cnt++;
    }

    YES((cnt == 2) || (cnt == 0))

    return 0;
}


Measured memory_bytes: 256
//Be Name Khoda
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma optimize O3
using namespace __gnu_pbds;
using namespace std;
template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T> using ordered_multiset =  tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long int LL;
typedef LL ll;
typedef long double ld;
typedef string str;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef stringstream strs;
 
#define X first
#define Y second
#define PB push_back
#define For(i,a,b) for (int i=a;i<b;i++)
#define Ford(i,a,b) for (int i=a;i>=b;i--)
#define smax(a,b) a=max(a,b)
#define smin(a,b) a=min(a,b)
#define SZ(a) ((ll)a.size())
#define ER(a) cout << #a << ' ' << a << endl
#define LB(a,n,x) (lower_bound(a,(a)+(n),x)-(a))
#define RET(x) { cout << x; exit(0); } 
#define RETD(x) { cout << fixed << setprecision(15) << x; exit(0); }
const ll M=2e5+5,LG=32,SM=600+5,inf=1e18+5;
ll mod=1e9+7;



int main()
{
    ll a,b,d,e,t;
    cin >> a >> b >> t >> d >> e >> t >> t;
    swap(a,b);
    ll res=a+b+d+e;
    ll su=b%2+d%2+e%2;
    if (su>1)
    {
        if (e && b && d)
        {
            e--;
            b--;
            d--;
        }
    }
    su=b%2+d%2+e%2;
    RET(res-su);
} 


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using Graph = vector<vector<bool>>;
const int MOD = 1e9 + 7;

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

    int N, K;
    cin >> N >> K;
    vector<pii> xy(N);
    for (int i = 0; i < N; ++i)
        cin >> xy[i].first >> xy[i].second;
    sort(xy.begin(), xy.end());

    ll ans = LLONG_MAX;
    for (int t = 0; t < N; ++t) {
        for (int b = 0; b < N; ++b) {
            if (xy[t].second <= xy[b].second)
                continue;
            int cnt = 0;
            for (int l = 0, r = 0; l < N; ++l) {
                while (r < N && cnt < K) {
                    if (xy[r].second >= xy[b].second && xy[r].second <= xy[t].second)
                        cnt++;
                    r++;
                }
                if (cnt < K)
                    break;
                ans = min(ans, (ll)(xy[r - 1].first - xy[l].first) * (xy[t].second - xy[b].second));
                if (xy[l].second >= xy[b].second && xy[l].second <= xy[t].second)
                    cnt--;
            }
        }
    }

    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x ,n) for(int i = x; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main(){
    int n;
    cin >> n;
    int p[n];
    int c[n];
    rep(i,n)cin >> p[i];
    repr(i,n)c[i-1]=i;
    
    int cnt = 0;
    rep(i,n){
        if(p[i]!=c[i])cnt++;
    }
    
    if(cnt==0 or cnt==2)cout << "YES";
    else cout <<"NO";
	return 0;
}

Measured memory_bytes: 3624
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=50;
const int MAXLIM=100;

int n,mxswaps;
int lim[MAXN];

int rem[MAXN];
int ans[MAXN*MAXLIM],nans;



bool solve() {
	nans=0;
	REP(i,n) rem[i]=lim[i];
	int prv=-1; int remswaps=mxswaps;
	while(true) {
		int cur=-1; REP(i,n) if(i!=prv&&(cur==-1||rem[i]<rem[cur])) cur=i; assert(cur!=-1);
		if(rem[cur]==0) return false;
		REP(i,n) if(i!=prv&&i!=cur) ans[nans++]=i,--rem[i];
		ans[nans++]=cur,--rem[cur];
		prv=cur;
		if(remswaps==0) return true; else --remswaps;
	}
}


void run() {
	scanf("%d%d",&n,&mxswaps);
	REP(i,n) scanf("%d",&lim[i]);
	if(!solve()) { printf("-1\n"); return; }
	printf("%d\n",nans); REP(i,nans) { if(i!=0) printf(" "); printf("%d",ans[i]+1); } puts("");
}

int main() {
	run();
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <set>
#include <cctype>
#include <vector>
#include <map>
#include <queue>
#include <list>
#include <algorithm>
#include <ctime>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <limits>
#include <cmath>
#include <typeinfo>


using namespace std; 

// ||


void sortString(string &str) 
{ 
   sort(str.begin(), str.end()); 
}
  
int main() {
	int n = 0, cnt = 0;
	cin >> n;
	string s;
	cin >> s;
	for(int i = 0; i < n; i++) {
		int j = i+1;
		if(s[i] != s[j]) {
			cnt++;
		}
	}
	cout << cnt << endl;

    return 0;
}  

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

int main(){
    int X,Y,Z;
    int count=0;
    scanf("%d%d%d", &X,&Y,&Z);
    for (int sum=Z; sum<=X; ) {
        count++;
        sum+=(Y+Z);
    }
    printf("%d",count-1);
    return 0;
}



Measured memory_bytes: 128
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    int n; cin >> n;
    vector<int> spot(n + 2),  expect(n + 2), distance(n + 2);
    ll sumall = 0;
    REP(i, n){
        cin >> spot[i + 1];
        distance[i + 1] = abs(spot[i + 1] - spot[i]);
        sumall += abs(spot[i + 1] - spot[i]);
    }
    sumall += abs(spot[n]);
    distance[n + 1] = abs(spot[n]);
    for(int i = 1; i <= n; i++){
        expect[i] = abs(spot[i + 1] - spot[i - 1]);
    }
    REP(i, n){
        cout << sumall - (distance[i + 1] + distance[i + 2]) + expect[i + 1] << endl;
    }
}

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

#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

int main() {
  int r, g, b;
  cin >> r >> g >> b;

  int i = 100 * r + 10 * g + b;
  if (i % 4 == 0) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}


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


typedef long long ll;
typedef long double ld;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;


#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ub upper_bound
#define lb lower_bound
#define asd cout << "ok" << endl;


#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define trav(it, m) for(auto it = m.begin(); it!= m.end(); it++)

const int MOD = 1e9 + 7;
const ll INF = 1e19;
const ld PI = acos((ld)-1);
const int MX = 2e5 +5;
const char nl = '\n';


int main(){

  int n; cin >> n;
  int ans = 0;
  for(int i = 1; i <= n; i+=2){
    int cnt = 0;
    for(int j = 1;j <= i; j++)
    {
      if(i%j ==0)
        cnt++;
    }
    if(cnt == 8)
      ans++;
  }
  cout << ans << nl;


  return 0;
}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
#include <time.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P  = pair<ll,ll>;
using vi = vector<ll>;
using vv = vector<vi>;
const ll INF = 1001001001001001;
const ll NUM = 1<<10;

vector<ll> prime;
vector<ll> p(1000001,0);

void sieve(ll n){
    if(n<2)return;
    for(ll i=2; i<=n; i++){
        if(p[i])continue;
        prime.push_back(i);
        p[i] = i;
        
        for(ll j=i*i; j<=n; j+=i){
            if(!p[j])p[j] = i;
        }
    }
}

int main(){
    sieve(1000000);
    int n;
    cin >> n;
    
    vi plist(1000000,0);
    
    rep(i,n){
        int a;
        cin >> a;
        for(int j=0; prime[j]*prime[j]<=a; j++){
            if(a%prime[j])continue;
            plist[prime[j]]++;
            while(a%prime[j]==0){
                a /= prime[j];
            }
        }
        if(a!=1)plist[a]++;
    }
    
    bool setwise = false;
    rep(i,1000000){
        if(plist[i]==n){
            cout<<"not coprime\n";
            return 0;
        }
        if(plist[i]>1)
            setwise = true;
    }
    if(setwise)
        cout<<"setwise coprime\n";
    else
        cout<<"pairwise coprime\n";
    return 0;
}

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

int main() {
  int n, y, i, j, check = 0;
  cin >> n >> y;
  
  for(i = 0; i <= y / 10000; i++){
    for(j = 0; j <= y / 5000 - i; j++){
      if((10000 * i + 5000 * j + (n - i - j) * 1000 == y) && (n - i - j >= 0)){
        cout << i << " " << j << " " << n - i - j << endl;
        check++;
        break;
      }
    }
    if(check != 0) break;
  }
  
  if(check == 0){
    cout << -1 << " " << -1 << " " << -1 << endl;
  }
}


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

using ll = long long;

int main() {
    int N;
    cin >> N;
    bool dp[10010] = {};
    dp[0] = true;
    for(int i=0; i<N; ++i) {
        int s;
        cin >> s;
        for(int i=10009-s; i>=0; --i) {
            dp[i+s] |= dp[i];
        }
    }
    int res = 0;
    for(int i=0; i<10010; ++i) {
        if(dp[i]) {
            if(i % 10 != 0) {
                res = max(res, i);
            }
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
#include <iomanip>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

int main()
{
	int X, Y;
	while(cin >> X >> Y && X)
	{
		vector<vint> field(Y + 1, vint(X, 0)), dp(Y + 1, vint(X, 0));
		rep(y, Y) rep(x, X)
			cin >> field[y][x];

		fill(ALL(dp[0]), 1);
		rep(y, Y) rep(x, X)
		{
			// y, x ツつゥツづァツづ個配ツづゥDP
			if(field[y][x] == 1) continue;

			if(field[y][x] == 2 || y + 1 == Y)
			{
				dp[min(y + 2, Y)][x] += dp[y][x];
			}
			else
			{
				int dx[] = {-1, 1};

				dp[y + 1][x] += dp[y][x];
				rep(i, 2)
				{
					int nx = x + dx[i];
					if(0 <= nx && nx < X && field[y + 1][nx] != 2)
						dp[y + 1][nx] += dp[y][x];
				}
			}
		}

		cout << accumulate(ALL(dp[Y]), 0) << endl;
	}
}

Measured memory_bytes: 0
N = int(input())
X =[]
for i in range(N):
    Y =list(input())
    Y.sort()
    X.append(Y)
X.sort()
    
ans = 0
count = 1 
for i in range(N-1):
    if X[i] == X[i+1]:
        count += 1
    else:
        if count != 1:
            Z = 1
            Z = Z * count * (count-1)
            Z = Z // 2
            ans = ans + Z
            count = 1

if count != 1:
    Z = 1
    Z = Z * count * (count-1)
    Z = Z // 2
    ans = ans + Z
        
print(ans)

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

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

using namespace std;

int main(){
	int a,b,k; cin>>a>>b>>k;
	vector<int> ans;
	rep(i,k){
		if(a+i<=b) ans.emplace_back(a+i);
		if(a<=b-i) ans.emplace_back(b-i);
	}
	sort(ans.begin(),ans.end());
	ans.erase(unique(ans.begin(),ans.end()),ans.end());

	for(int x:ans) cout<<x<<endl;

	return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Sparsh Sanchorawala
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ATakahashiCalendar solver = new ATakahashiCalendar();
        solver.solve(1, in, out);
        out.close();
    }

    static class ATakahashiCalendar {
        public void solve(int testNumber, InputReader s, PrintWriter w) {
            int m = s.nextInt(), d = s.nextInt();
            int res = 0;
            for (int i = 1; i <= d; i++) {
                int d0 = i % 10;
                int d1 = (i / 10) % 10;
                if (d0 >= 2 && d1 >= 2 && d0 * d1 >= 1 && d0 * d1 <= m)
                    res++;
            }
            w.println(res);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 21460
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
	"unsafe"
)

func main() {
	n := sc.nextInt()
	fmt.Println(math.Ceil(float64(n) / 2.0))
}

var (
	sc scanner
)

func init() {
	sc = scanner{
		buf: make([]string, 0, 0),
		cur: 0,
		r:   bufio.NewReader(os.Stdin),
	}
}

type scanner struct {
	buf []string
	cur int
	r   *bufio.Reader
}

func (s *scanner) readln() {
	rbuf := make([]byte, 0, 0)
	for {
		line, prefix, err := s.r.ReadLine()
		if err != nil {
			panic(err)
		}
		rbuf = append(rbuf, line...)
		if prefix == false {
			break
		}
	}
	s.cur = 0
	s.buf = strings.Split(*(*string)(unsafe.Pointer(&rbuf)), " ")
}
func (s *scanner) isFull() bool {
	if s.cur == len(s.buf) {
		return true
	}
	return false
}
func (s *scanner) resetCur() {
	s.cur = 0
}
func (s *scanner) next() string {
	if s.cur == 0 {
		s.readln()
	}
	res := s.buf[s.cur]
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}
func (s *scanner) nexts() []string {
	s.readln()
	s.resetCur()
	return s.buf
}
func (s *scanner) nextInt() int {
	if s.cur == 0 {
		s.readln()
	}
	res, _ := strconv.Atoi(s.buf[s.cur])
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}
func (s *scanner) nextInts() []int {
	s.readln()
	res := make([]int, len(s.buf))
	for i := range s.buf {
		res[i], _ = strconv.Atoi(s.buf[i])
	}
	s.resetCur()
	return res
}
func (s *scanner) nextFloat() float64 {
	if s.cur == 0 {
		s.readln()
	}
	res, _ := strconv.ParseFloat(s.buf[s.cur],
		64)
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}
func (s *scanner) nextFloats() []float64 {
	s.readln()
	res := make([]float64, len(s.buf))
	for i := range s.buf {
		res[i], _ = strconv.ParseFloat(s.buf[i],
			64)
	}
	s.resetCur()
	return res
}
func digits(x int) int {
	return len(strconv.Itoa(x))
}
func powInt(x, p int) (result int) {
	result = 1
	for i := 0; i < p; i++ {
		result *= x
	}
	return
}
func max(x, y int) int {
	return int(math.Max(float64(x), float64(y)))
}
func min(x, y int) int {
	return int(math.Min(float64(x), float64(y)))
}
func abs(x int) int {
	return int(math.Abs(float64(x)))
}
func varDump(value ...interface{}) {
	for _, v := range value {
		fmt.Fprintf(os.Stderr, "%#v\n", v)
	}
}
func yes() {
	fmt.Println("Yes")
}
func no() {
	fmt.Println("No")
}

// Pair a
type Pair struct {
	first  int
	second int
}

// Queue a
type Queue struct {
	v []Pair
}

// Push for queue
func (q *Queue) Push(v Pair) {
	q.v = append(q.v, v)
}

// Pop for queue
func (q *Queue) Pop() Pair {
	r := q.v[0]
	q.v = q.v[1:]
	return r
}

// Front for queue
func (q Queue) Front() Pair {
	return q.v[0]
}

// Empty return true if empty
func (q Queue) Empty() bool {
	return len(q.v) == 0
}

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

#A = int(A)
#B = int(B)
#print(str(A)+" "+str(B))

ans = 0

for i in range(2):

    if A > B:
        ans += A
        A -= 1
        
    else:
        ans += B
        B -= 1

print(ans)



Measured memory_bytes: 2940
#include "bits/stdc++.h"
using namespace std;
#define long int64_t

int main() {
	ios_base::sync_with_stdio( false );

	int n;
	cin >> n;
	vector<int> a( n );
	for( auto& v: a ) { cin >> v; }

	int m;
	cin >> m;
	vector<int> b( m );
	for( auto& v: b ) { cin >> v; }

	cout << includes( a.begin(), a.end(), b.begin(), b.end() ) << endl;

	return 0;
}



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

int main(){
    int n, flag = 0;
    cin >> n;
    vector<string> a(n);
    for(int i = 0; i < n; i++)
        cin >> a.at(i);
    sort(a.begin(), a.end());
    for(int i = 1; i < n; i++){
        if(a.at(i-1) == a.at(i)) flag++;
    }
    cout << ((flag == 0) ? "YES" : "NO");
}

Measured memory_bytes: 13824
#include<cstdio>
using namespace std;
int n,m,a[505][505];
int f[250005][4],cnt;
int main()
{
	scanf("%d%d",&n,&m);for(int i=1;i<=n;++i) for(int j=1;j<=m;++j) scanf("%d",&a[i][j]);
	for(int i=1;i<n;++i) 
		for(int j=1;j<=m;++j) 
			if(a[i][j]%2) {a[i+1][j]++;f[++cnt][0]=i;f[cnt][1]=j;f[cnt][2]=i+1;f[cnt][3]=j;}
	for(int j=1;j<m;++j) if(a[n][j]%2) {a[n][j+1]++;f[++cnt][0]=n;f[cnt][1]=j;f[cnt][2]=n;f[cnt][3]=j+1;}
	printf("%d\n",cnt);
	for(int i=1;i<=cnt;++i) printf("%d %d %d %d\n",f[i][0],f[i][1],f[i][2],f[i][3]);
	return 0;
}

Measured memory_bytes: 6784
#include<stdio.h>
#define N 10000
#define Q 500

int Search();

int S[N];
int n, key;

int main(){
    int T[Q];
    int q, i;
    int count = 0;

    scanf("%d", &n);
    for(i = 0; i < n; i++){
        scanf("%d", &S[i]);
    }

    scanf("%d", &q);
    for(i = 0; i < q; i++){
        scanf("%d", &T[i]);
    }

    for(i = 0; i < q; i++){
        key = T[i];
        if(Search() == 1) count++;
    }

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

    return 0;
}

int Search(){
    int i = 0;

    S[n] = key;

    while(S[i] != key) i++;

    if(i == n) return 0;

    return 1;
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define ff first
#define ss second
 
const int N=2e5+5;
const int mod=1e9+7;
 
int binpow(int a, int b) {
    int res = 1;
    while (b > 0) {
        if (b & 1LL)
            res = res * a;
        a = a * a;
        b >>= 1LL;
    }
    return res;
}
 
int32_t main()
{
    IOS;
    
    int n;
    cin>>n;
    int r=n%10;
    if(r==3)
        cout<<"bon";
    else if(r<=1 || r==6 || r==8)    
        cout<<"pon";
    else
        cout<<"hon";
}

Measured memory_bytes: 3648
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    string s;
    cin>>s;
    int ans=0;
    string u,v;
    rep(i,s.length()){
        u+=s[i];
        if(u!=v){
            v=u;
            u="";
            ans++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 720
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<vector>
#include<cstdio>

using namespace std;
/*
int find(int x, vector<int> &p) {
if (p[x] == x)return x;
return p[x] = find(p[x], p);
}

void uni(int x, int y, vector<int> &p) {
x = find(x, p);
y = find(y, p);
p[x] = y;
}

int same(int x, int y, vector<int> p) {
if (find(x, p) == find(y, p))return 1;
return 0;
}
*/

//long long a[1002];
/*アホ。全探索でいいのにわざわざメモ化再帰してる
int R, G, B;
long long ans = 0;
const int MAX_N = 300001;

int memo[MAX_N][3];

int fn(int n, int mark) {
if (n == 0) {
return 1;
}
if (mark != 0 && memo[n][mark-1] != -1) return memo[n][mark-1];
int tmp1 = 0, tmp2 = 0, tmp3 = 0;
if (n - R >= 0 && mark < 2) tmp1 = memo[n - R][0] = fn(n - R, 1);
if (n - G >= 0 && mark < 3) tmp2 = memo[n - G][1] = fn(n - G, 2);
if (n - B >= 0 && mark < 4) tmp3 = memo[n - B][2] = fn(n - B, 3);
if (n - R < 0 && n - G < 0 && n - B < 0) return 0;
//return memo[n - R][0] + memo[n - G][1] + memo[n - B][2];
return tmp1 + tmp2 + tmp3;
}

int main()
{
for (int i = 0; i < MAX_N; ++i) {
for (int j = 0; j < 3; j++) {
memo[i][j] = -1;
}
}
long long N, K, cnt = 0, tmp;
cin >> R >> G >> B >> N;
cout << fn(N, 0) << endl;
for (int j = 0; j < 3; j++) {
for (int i = 0; i < N; i++) {
//cout << memo[i][j] << endl;
}
//cout << endl;
}
*/

int main() {
	long long N, M, K, cnt = 0, tmp, ans = 0;

	cin >> N >> M;
	vector<long long> L(M+1), R(M+1);

	for (int i = 0; i < M; i++) {
		cin >> L[i + 1] >> R[i + 1];
	}
	long long Min = 1, Max = 100005;
	for (int i = 1; i <= M; i++) {
		Min = max(Min, L[i]);
		Max = min(Max, R[i]);
	}

	if (Min > Max) {
		cout << 0;
	}
	else {
		cout << Max - Min + 1;
	}

	char qq;
	cin >> qq;
	return 0;
}

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

struct UnionFind{
	vector<ll> rnk,par,num;
	UnionFind(ll N) : rnk(N),par(N),num(N){
		init();
	}
	void init(){
		for(ll i = 0;i < rnk.size();i++){
			rnk[i] = 0;
			par[i] = i;
			num[i] = 1;
		}
	}
	ll find(ll x){
		if(par[x] == x) return x;
		return par[x] = find(par[x]);
	}
	void unite(ll x,ll y){
		x = find(x);
		y = find(y);
		if(x == y) return;
		if(rnk[x] < rnk[y]){
			par[x] = y;
			num[y] += num[x];
		}
		else{
			par[y] = x;
			num[x] += num[y];
			if(rnk[x] == rnk[y]) rnk[x]++;
		}
	}
	bool same(ll x,ll y){
		return (find(x) == find(y));
	}
	ll size(ll x){
		return num[find(x)];
	}
};

signed main(){
 ll n, m; cin >> n >> m;
 vector<ll> a(m), b(m);
 for(int i = 0; i < m; i++){
   scanf("%lld%lld", &a[i], &b[i]); --a[i]; --b[i];
 }
 UnionFind tree(n);
 vector<ll> ans(m);
 ll num = n * (n - 1) / 2;
 for(ll i = m - 1; i >= 0; i--){
   ans[i] = num;
   ll x = a[i], y = b[i];
   if(!tree.same(x, y)){
     num -= tree.size(x) * tree.size(y);
   }
   tree.unite(x, y);
 }
  for(ll i : ans) cout << i << endl;
}


Measured memory_bytes: 6016
import java.util.*
fun main(args: Array<String>){
	val cin = Scanner(System.`in`)
    val n = cin.nextInt()
    val r: MutableList<Int> = mutableListOf()
    for (i in 0..n-1) {
        r.add(cin.nextInt())
    }
    val r_sorted = r.sorted()
    val upper_bottom_idx = n/2
    println(r_sorted[upper_bottom_idx] - r_sorted[upper_bottom_idx - 1])
}

Measured memory_bytes: 58784
#/usr/bin/env python

def main():
    s = input()
    op_cnt = len(s) -1
    for i in range(1<<op_cnt):
        op = ["-"] * op_cnt
        for j in range(op_cnt):
            if ((i >> j) & 1):
                op[op_cnt -1 -j] = "+"

        formula = ""
        for p_n, p_o in zip(s, op+[""]):
            formula += (p_n + p_o)
        if eval(formula) == 7:
            print(formula + "=7")
            break

if __name__ == '__main__':
    main()

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    int a[1000];
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    int ans = 0;
    bool canDivide = true;
    while(1){
        for(int i=0; i<n; i++){
            if(a[i]%2==0){
                a[i]/=2;
            }else{
                canDivide = false;
                break;
            }
        }
        if(!(canDivide)) break;
        ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
object Main extends App {
  override def main(args: Array[String]): Unit = {
    import scala.io.{StdIn => in}
    Iterator
      .continually(in.readInt())
      .takeWhile(_ != 0)
      .map(n =>
        for (x <- 1 to n) yield in.readLine()
      ).map(solve).foreach(println)
  }

  def solve(input: Seq[String]): Int = {
    def toMinutes(input: String): Int = input.substring(6, 8).toInt * 60 + input.substring(9, 11).toInt
    def getDistance(currentNext: (String, String)): Int = toMinutes(currentNext._2) - toMinutes(currentNext._1)

    val sorted = input.sorted
    val range = sorted.zip(sorted.drop(1)).map(getDistance(_))
    val scanned = sorted.scanLeft(Set[String]()){(set,string) => if (string(12) == 'I') set + string.substring(14) else set - string.substring(14)}
    val result = range.zip(scanned.drop(1)).filter(_._2.contains("000")).foldLeft(Map[String, Int]()) {
      (z, data) => data._2.filter(_ != "000").foldLeft(z)((zz, nn) => zz + (nn -> (zz.getOrElse(nn, 0) + data._1)))
    }
    if (result.isEmpty) 0 else result.maxBy(z => z._2)._2
  }
}

Measured memory_bytes: 57620
#include <iostream>
#define N 101
using namespace std;

int main()
{
  int r,c,A[N][N],col=0,row=0,sum=0;
  cin >> r >> c;

  for(int i=0;i<r;i++)
    {
      for(int j=0;j<c;j++)
        {
          cin >> A[i][j];
        }
    }

  for(int i=0;i<r;i++)
    {
      col=0;
      for(int j=0;j<c;j++)
        {
          if(j) cout << " ";
          col+=A[i][j];
          cout << A[i][j];
        }
      cout << " " << col << endl;
    }
  for(int i=0;i<c;i++)
    {
      row=0;
      for(int j=0;j<r;j++)
        {
          row+=A[j][i];
        }
      cout << row << " ";
      sum+=row;
    }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 3120
#include <bits/stdc++.h>
#define ll long long
#define eps 1e-9
#define PI 2 * acos (0.0)
using namespace std;

int ar[100005];


int main()
{

  

	int a,b,c,d,e,x,y,z;

	ll ans = 0;

	int N;

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

	for(a = 0; a < N; a++)
    {
        scanf("%d", &ar[a]);
    }

    for(a = 1; a < N; a++)
    {
        if(ar[a] + ar[a - 1] <= x)
        {
            continue;
        }

        y = ar[a] + ar[a - 1] - x;

        ans = ans + y;

        if(ar[a] >= y)
        {
            ar[a] = ar[a] - y;
        }
        else
        {
            ar[a] = 0;
            y = y - ar[a];

            ar[a-1] = ar[a-1] - y;
        }
    }

    cout<<ans<<endl;



    return 0;
}


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

int main() {
  int a, b, c, d, A, B;
  cin >> a >> b >> c >> d;
  if(c % b == 0) {
    c -= 1;
  }
  if(a % d == 0) {
    a -= 1;
  }
  A = c / b;
  B = a / d;
  if (A > B) {
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }
}


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

          using namespace std;
          typedef long long ll;
          int n, m, a[1111], s, k, fr[5353];
          double p;
          int main()
          {
            cin >> n >> m;
            for(int i = 1; i <= n; i++)
              cin >> a[i], s += a[i];
            p = s/(4.0*m);
            for(int i = 1; i <= n; i++)
            {
              if(a[i] < p)
                k++;
            }  
            if(n-k >= m)
              cout << "Yes";
            else cout << "No";  
          }

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
import java.util.StringTokenizer;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;




public class Main{
	static class MyScanner {
	    BufferedReader br;
	    StringTokenizer st;

	    public MyScanner() {
	       br = new BufferedReader(new InputStreamReader(System.in));
	    }

	    String next() {
	        while (st == null || !st.hasMoreElements()) {
	            try {
	                st = new StringTokenizer(br.readLine());
	            } catch (IOException e) {
	                e.printStackTrace();
	            }
	        }
	        return st.nextToken();
	    } 

	    int nextInt() { return Integer.parseInt(next());}

	    long nextLong() {return Long.parseLong(next());}

	    double nextDouble() {return Double.parseDouble(next());}

	    String nextLine(){
	        String str = "";
		  try {
		     str = br.readLine();
		  } catch (IOException e) {
		     e.printStackTrace();
		  }
		  return str;
	    }
	}
		
	
		 public static void main(String[] args) throws IOException {
			 	PrintWriter out = new PrintWriter(System.out);
			    MyScanner sc = new MyScanner();
			 	Main solver = new Main();
				solver.solve(out, sc);
				out.flush();
				out.close();
			
		 }
	
		
		 
		 
		
 		void solve(PrintWriter out, MyScanner sc) throws IOException{	
 			
 			int n = sc.nextInt();
 			int l = sc.nextInt();
 			
 			String[] s = new String[n];
 			for(int i = 0; i < n ; ++i) s[i] = sc.nextLine();
 			
 			Arrays.sort(s);
 			for(String ss : s) out.print(ss);
 					
 			
 			
 			
 		
 		}
 		
 		

 	
		
	
			
		
		
		
		
		
		
		
		
	
	
}



Measured memory_bytes: 21204
#include <iostream>
#include <vector>

using std::cin;
using std::cout;
using std::endl;

using std::vector;

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

    const int t = 1900 * m + 100 * (n - m);
    cout << t * (1 << m) << endl;

    return 0;
}


Measured memory_bytes: 256