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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

const int maxN = 1000010;
const int maxM = 30010;
const int inf = 1000000009;

bitset<32> e;
int a[20];
int main()
{
	int n = 5;
	int k;
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	scanf("%d",&k);
	for(int i=1;i<=n;i++)
	{
		for(int j=i+1;j<=n;j++)
			if(a[j] - a[i]>k)
			{
				puts(":(");
				return 0;
			}
	} 
	puts("Yay!");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (rint i = 1; i <= (n); i ++)
#define re0(i, n) for (rint i = 0; i < (int) n; i ++)
#define travel(i, u) for (rint i = head[u]; i; i = e[i].nxt)
#define rint register int
using namespace std;

typedef long long lo;

template<typename tp> inline void read(tp &x) {
    x = 0; char c = getchar(); int f = 0;
    for (; c < '0' || c > '9'; f |= c == '-', c = getchar());
    for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
    if (f) x = -x;
}
const int N = 3e5 + 233;
int pre[N], id[N], n, m;

inline int find(int x) {
    return pre[x] == x ? x : pre[x] = find(pre[x]);
}

inline void make(int x, int y) {
    pre[find(x)] = find(y);
}

int main(void) {
    read(n); read(m);
    rep (i, m) id[i] = i + n;
    rep (i, m + n) pre[i] = i;
    rep (i, n) {
	int p;
	read(p);
	rep (k, p) {
	    int t; read(t);
	    make(i, id[t]);
	}
    }
    set <int> s;
    rep (i, n) s.insert(find(i));
    cout << (s.size() == 1 ? "YES" : "NO") << "\n";
}


Measured memory_bytes: 1408
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;


public class Main{
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(
			new InputStreamReader(System.in));
		String[] input = br.readLine().split(" ");
		int a = Integer.parseInt(input[0]);
		int b = Integer.parseInt(input[1]);

		if(a<=0|b<=0){
			System.out.println("error");
		} else if(a>=10|b>=10){
			System.out.println("error");

		}else{
			int sum = a + b;
			if(sum >= 10){
				System.out.println("error");

			}else{
				System.out.println(sum);
			}
		}
		br.close();
	}
}

Measured memory_bytes: 20948
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
string x;

int main()
{
	cin>>x;
	char res[200]={0};
	int ofs=0;
	for(int i=0;i<x.length();i++)
	{
		if(x[i]=='B')
		{
			ofs=max(0,ofs-1);
			res[ofs]=0;
		}
		else
			res[ofs++]=x[i];
	}
	puts(res);
	return 0;
}

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

#define Online 1
// #define multitest 1
#define Debug 1
typedef long long ll;
typedef long double ld;
#define f first
#define s second
#define pb push_back
#define mp make_pair
const long long mod = 1000000007;
const long long High = 1e16;
void ControlIO();
void TimerStart();
void TimerStop();
#ifdef Debug
#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void ZZ(const char *name, Arg1 &&arg1)
{
	std::cerr << name << " = " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void ZZ(const char *names, Arg1 &&arg1, Args &&... args)
{
	const char *comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}
#else
#define db(...)
#endif

ll gcd(ll a, ll b)
{
    if(b==0) return a;
    return gcd(b,a%b);
}

vector<ll> Lgcd,Rgcd;

void solve()
{
    int n;
    cin >> n;
    vector<ll> V(n);
    Lgcd.resize(n);
    Rgcd.resize(n);
    for(int i=0;i<n;++i)
        cin >> V[i];
    Lgcd[0] = V[0];
    for(int i=1;i<n;++i)
        Lgcd[i] = gcd(Lgcd[i-1],V[i]);
    Rgcd[n-1] = V[n-1];
    for(int i=n-2;i>=0;--i)
        Rgcd[i] = gcd(Rgcd[i+1],V[i]);
    ll maxi = -mod;
    maxi = Rgcd[1];
    for(int i=1;i<n-1;++i)
        maxi = max(maxi,gcd(Lgcd[i-1],Rgcd[i+1]));
    maxi = max(maxi,Lgcd[n-2]);
    cout << maxi;
}

int main()
{
	ControlIO();
	int t = 1;
#ifdef multitest
	cin >> t;
#endif
	TimerStart();
	while (t--)
		solve();
	TimerStop();
	return 0;
}

void ControlIO()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#ifndef Online
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

auto TimeStart = chrono::steady_clock::now();
auto TimeEnd = chrono::steady_clock::now();

void TimerStart()
{
#ifndef Online
	TimeStart = chrono::steady_clock::now();
#endif
}

void TimerStop()
{
#ifndef Online
	TimeEnd = chrono::steady_clock::now();
	auto ElapsedTime = TimeEnd - TimeStart;
	cout << "\n\nTime elapsed: " << chrono::duration<double>(ElapsedTime).count() << " seconds.\n";
#endif
}


Measured memory_bytes: 2560
#include "bits/stdc++.h"
/* Properties of modulo:
	(a/b)%m ,where m is prime  = (a%m) * (b^(m-2))%m
*/
    /*ROLLING HASH
    Rabin-Karp algorithm for pattern matching in a string in O(n) time
    Calculating the number of different substrings of a string in O(n2logn)
    Calculating the number of palindromic substrings in a string.
    */
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define IOS { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define ll long long
#define pb push_back
#define gcd __gcd
#define nl cout<<"\n"
#define endl "\n"
#define all(c) (c).begin(),(c).end()
#define trav(a,x) for(auto a = x.begin() ; a != x.end() ; a++)
#define lb lower_bound
#define ub upper_bound
#define f first
#define s second
//template<typename T>
//#define o_set(T) tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>
// o_set(ll) name ; -- defining ordered set
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set - returns iterator
bool compare(ll a, ll b){
    return a > b;
}
ll power(ll x, ll ex , ll md) {
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x) % md;
        ex >>= 1ll;
        x = (x * x) % md;
    }
    return ans;
}
void solve(){
    ll n , k;
    cin >> n >> k;
    ll ct[n + 1] = {0};
    for(ll i = 0 ; i < k ; i++){
        ll d;
         cin >> d;
         for(ll j = 0 ; j < d ; j++) {
            ll a;
            cin >> a;
            ct[a]++;
         }
    }
    ll cnt =0 ;
    for(ll i = 1 ; i < n + 1 ; i++){
        if(ct[i] == 0) cnt++;
        //cout << ct[i] <<"  ";
     }
     cout << cnt << endl;
}
int main(){
    IOS;
    ll T=1;
    //cin>>T;
    ll t=0;
    while(t++<T){
        //cout<<"Case #"<<t<<":"<<' ';
        solve();
        //cout<<'\n';
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}


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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
int main()
{
  int n;
  cin >> n;
  n = 10000-n;
  cout << n%1000 << "\n";
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PP;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
#define PI 3.141592653589
#define setdouble setprecision
#define REP(i,n) for(ll i=0;i<(n);++i)
#define OREP(i,n) for(ll i=1;i<=(n);++i)
#define RREP(i,n) for(ll i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug false
#define debug2 false


int main(void){
    int H,W,K;
    string C[10];
    cin >> H >> W >> K;
    REP(i,H){
        cin >> C[i];
    }
    ll sum=0;
    REP(i,H){
        REP(j,W){
            if(C[i][j]=='#'){
                sum++;
            }
        }
    }
    
    ll Ans=0;
    for(ll i=0; i<(1LL<<H);i++){
        for(ll j=0; j<(1LL<<W);j++){
            ll num = 0;
            for(ll k=0;k<H;k++){
                for(ll l=0;l<W;l++){
                    if(((i>>k)%2==1 || (j>>l)%2==1) && C[k][l]=='#'){
                        num++;
                    }
                }
            }
            
            if(sum-num==K){
                //cout << i MM j << endl;
                Ans++;
            }
        }
    }
    
    cout << Ans << endl;
    
    return 0;
}



Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define For(a,b,c) for(int a=b;a<=c;++a)
using namespace std;
const int N=200007;
char S[N],T[N];
int n,c,t;
long long ans;
int main() {
	scanf("%s",S+1);
	n=strlen(S+1);
	For(i,1,n)
	if(S[i]=='A') T[++t]='R';
	else if(S[i]=='B'&&S[i+1]=='C') T[++t]='L',++i;
	else T[++t]='#';
	For(i,1,t)
	if(T[i]=='#') c=0;
	else if(T[i]=='R') ++c;
	else ans+=c;
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 640
### constant

DXYS = [[1, 0], [0, 1], [-1, 0], [0, -1]]

### subroutines

def get_piece(x0, y0, used)
  b0 = $blks[y0][x0]
  return nil if b0 == '.' || used[y0][x0]

  pc = [[x0, y0]]
  used[y0][x0] = true
  q = [[x0, y0]]

  while ! q.empty?
    ux, uy = q.shift

    DXYS.each do |dx, dy|
      vx = ux + dx
      vy = uy + dy
      if vx >= 0 && vx < $w && vy >= 0 && vy < $h &&
          $blks[vy][vx] == b0 && ! used[vy][vx]
        used[vy][vx] = true
        pc << [vx, vy]
        q << [vx, vy]
      end
    end
  end

  pc
end

def find_pieces
  used = $h.times.map{$w.times.map{false}}

  pcs = []

  for y in (0...$h)
    for x in (0...$w)
      b = $blks[y][x]
      if b != '.' && ! used[y][x]
        pcs << get_piece(x, y, used)
      end
    end
  end

  pcs
end

def contact(pc0, pc1)
  cnt = false
  min_x = $w
  max_x = 0

  pc0.each do |x0, y0|
    if pc1.include?([x0, y0 + 1])
      cnt = true
      min_x = x0 if min_x > x0
      max_x = x0 + 1 if max_x <= x0
    end
  end

  cnt ? [min_x, max_x] : nil
end

def cg_piece(pc)
  sum = 0.0
  pc.each do |x, y|
    sum += (x + 0.5)
  end
  [sum, pc.length]
end

def cg_tree(k, min_x, max_x)
  sum, len = cg_piece($pcs[k])

  for i in (0...$npcs)
    cnt = $cnts[k][i]
    if ! cnt.nil?
      sl0 = cg_tree(i, cnt[0], cnt[1])
      return nil if sl0.nil?

      sum += sl0[0]
      len += sl0[1]
    end
  end

  x = sum / len
  (min_x < x && x < max_x) ? [sum, len] : nil
end

### main

loop do
  $w, $h = gets.split.map(&:to_i)
  break if ($w | $h) == 0

  $blks = $h.times.map{gets.strip}.reverse

  $pcs = find_pieces()
  $npcs = $pcs.length

  $cnts = $npcs.times.map{$npcs.times.map{nil}}

  for i in (0...$npcs)
    for j in (0...$npcs)
      $cnts[i][j] = (i != j) ? contact($pcs[i], $pcs[j]) : nil
    end
  end
  #p $cnts

  fpc = (0...$w).map{|x| [x, -1]}
  cnt0 = contact(fpc, $pcs[0])

  sl = cg_tree(0, cnt0[0], cnt0[1])
  puts (sl ? 'STABLE' : 'UNSTABLE')
end

Measured memory_bytes: 6144
#include<iostream>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

struct obj{
	vector<string> key;
	vector<string> property;
	vector<obj*> obj;
};
int n, p;

string ks, in[50000];
obj* parse(int pid = -1){
	obj* res = new obj;
	while(p < n){
		int id = 0;
		for(; isspace(in[p][id]); id++);
		if(id <= pid) break;
		
		int pos = in[p].find(":");
		string key = in[p].substr(id, pos - id);
		if(pos == in[p].size() - 1){
			res->key.pb(key);
			res->property.pb("");
			p++;
			res->obj.pb(parse(id));
		}
		else{
			res->key.pb(key);
			res->property.pb(in[p].substr(pos + 2));
			res->obj.pb(NULL);
			p++;
		}
	}
	return res;
}

int main(){
	getline(cin, ks);
	while(getline(cin, in[n])) n++;
	
	obj *root = parse();
	
	each(i, ks) if(*i == '.') *i = ' ';
	stringstream ss(ks);
	vector<string> v;
	while(ss >> ks) v.pb(ks);
	
	rep(i, v.size() - 1){
		bool ok = 0;
		rep(j, root->key.size()) if(root->key[j] == v[i]){
			if(root->property[j] != "") break;
			
			root = root->obj[j];
			ok = 1;
		}
		if(!ok){
			cout << "no such property" << endl;
			return 0;
		}
	}
	rep(j, root->key.size()) if(root->key[j] == v.back()){
		if(root->property[j] != "") cout << "string \"" << root->property[j] << "\"" << endl;
		else cout << "object" << endl;
		return 0;
	}
	cout << "no such property" << endl;
	
	return 0;
}

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

int main() {
    long long int n,k;

    cin >> n >> k;

    long long int a,b;
    b = n/k;
    if(k % 2 == 0 ){
        a = 2*n/(k) - b;
        cout << a*a*a + b*b*b << endl;
    }
    else{
        cout << b*b*b << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
using namespace std;
using ll = long long;
#define MAX_N 1000001
#define MAX_M 100010
const long long mod = 1e9 + 7;
#define vec vector<int>
#define vecll vector<ll>
#define vecllvec vector<vector<ll>>
#define vecb vector<bool>
#define vecBvec vector<vector<bool>>
#define vecst vector<string>
#define veche vector<char>
#define vecd vector<double>
#define vecvec vector<vector<int>>
#define vecDvec vector<vector<double>>
#define vecHvec vector<vector<char>>
#define all(x) (x).begin(),(x).end()
#define ent cout<<endl
#define printvec(vec) for(int aqw=0;aqw<vec.size();aqw++){cout<<vec[aqw]<<" ";}ent;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define REP(i,m,n) for(int i=m;i<(int)n;++i)
#define INF 1e+9
using P = pair<int, int>;
#define PLL pair<ll, ll>;
#define MAX_V 1000
#define PI 3.141592653589793
// cout << setprecision(15) << std::fixed;

int d[MAX_V][MAX_V];
int V=10;

int main()
{
    int n, i;
    cin >> n >> i;
    cout << n - i+1 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
  int x, a, b;
  cin >> x >> a >> b;
  if (abs(a-x)<abs(b-x)) {
    cout << "A" << endl;
  } else {
    cout << "B" << endl;
  }
  return 0;
}


Measured memory_bytes: 3584
h, w, k = [int(i) for i in input().split()]
lines = [input() for i in range(h)]
ans = 0
# bit search
for h_1 in range(1 << h):
    for w_1 in range(1 << w):
        black = 0

        for i in range(h):
            for j in range(w):
                if (h_1 >> i) & 1 == 0 and (w_1 >> j) & 1 == 0 and lines[i][j] == '#':
                    black += 1
        if black == k:
            ans += 1
print(ans)


Measured memory_bytes: 9128
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<numeric>
#include<utility>
#include<cmath>
#include<iomanip>

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;

int n;
vector<vector<double>> d;

int main(){
    cin >> n;
    vector<double> x(n), y(n);
    for(int i = 0; i < n; i++){
        cin >> x[i] >> y[i];
    }
    int m = 1;
    for(int i = 1; i <= n; i++){
        m *= i;
    }
    d = vector<vector<double>>(n, vector<double>(n));
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j < n; j++){
            double dx = abs(x[i] - x[j]);
            double dy = abs(y[i] - y[j]);
            d[i][j] = d[j][i] = sqrt(dx * dx + dy * dy);
        }
    }
    vector<int> v(n);
    for(int i = 0; i < n; i++){
        v[i] = i;
    }
    double ans = 0;
    do{
        double sum = 0;
        for(int i = 1; i < n; i++){
            sum += d[v[i - 1]][v[i]];
        }
        ans += sum / m;
    }while(next_permutation(begin(v), end(v)));

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


Measured memory_bytes: 256
/// kazuki08
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define ar array
//#define inf 1000000000
#define mod 1000000007
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
    return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
    o<<"{";
    for(const T& v:vc) o<<v<<",";
    o<<"}";
    return o;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n,m,h[202020];
vi adj[320020];

int pp(int x){
  int res = x*x*x*x*x;
  return res;
}

signed main(){
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
  

  
  int x;
  cin >> x;
  for(int i=-5000;i<=5000;i++){
    for(int j=-5000;j<=5000;j++){
      if(pp(i)-pp(j)==x){
        cout << i << " " << j << endl;
        return 0;
      }
    }
  }

  // int n,m;
  // cin >> n >> m;
  // for(int i=1;i<=n;i++){
  //   cin >> h[i];
  // }
  // for(int i=1;i<=m;i++){
  //   int x,y;
  //   cin >> x >> y;
  //   adj[x].pb(y);
  //   adj[y].pb(x);
  // }
  // int ans = 0;
  // for(int i=1;i<=n;i++){
  //   bool f = true;
  //   for(auto t:adj[i]){
  //     if(h[i]>h[t]);
  //     else f = false;
  //   }
  //   if(f)ans++;
  // }
  // cout << ans << endl;


return 0;
}
///....


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

int main() {
  string x, y;
  cin >> x >> y;
  
  if(x < y) cout << "<" << endl;
  else if(x > y) cout << ">" << endl;
  else cout << "=" << endl;
  
  return 0;
}


Measured memory_bytes: 3572
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <bitset>

using namespace std;

const int N=705;
const int P=998244353;

struct edge{
	int v;
	edge *next;
}pool[15*N*N],*h[N];

struct task{
	int x,y;
	inline task(){}
	inline task(int _x,int _y){
		x=_x;
		y=_y;
	}
}c[N];

int n,m,top=-1;
int map[N][N];
int col[N],cnt[2];
int Index,ans=P;
bitset<N> f,_f;

inline void addedge(int u,int v){
	edge *tmp=&pool[++top];
	tmp->v=v;tmp->next=h[u];h[u]=tmp;
}

#define g(x) ((x==1)?1:0)
#define cn2(x) ((x)*((x)-1)/2)

bool dfs(int u,int pre){

	//printf("%d <- %d\n",u,pre);
	
	col[u]=-col[pre]; cnt[g(col[u])]++;
	for(edge *tmp=h[u];tmp!=NULL;tmp=tmp->next){
		int v=tmp->v;
		if(col[v]==0){
			if(dfs(v,u)==false) return false;
		}
		else if(col[u]+col[v]!=0){
			return false;
		}
	}
	return true;
}

void init(){
	int x1,x2,last[2];
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		scanf("%d%d",&x1,&x2);
		map[x1][x2]=map[x2][x1]=1;
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			if(i==j) continue;
			if(map[i][j]==0) addedge(i,j);
		}
	}
	col[0]=-1;
	for(int i=1;i<=n;i++){
		if(col[i]==0){
			last[0]=cnt[0];
			last[1]=cnt[1];
			if(dfs(i,0)==false){
				printf("-1\n");
				return ;
			}
			c[++Index]=task(cnt[0]-last[0],cnt[1]-last[1]);
		}
	}
	/*
	cin>>Index;
	for(int i=1;i<=Index;i++){
		cin>>c[i].x>>c[i].y;
		n+=c[i].x,n+=c[i].y;
	}
	*/
	f[c[1].x]=1;
	f[c[1].y]=1;
	for(int i=2;i<=Index;i++){
		_f=f;
		f=((_f<<c[i].x)|(_f<<c[i].y));
	}
	for(int i=0;i<=n;i++){
		//printf("%d | %d : %d\n",i,(int)f[i],cn2(i)+cn2(n-i));
		if(f[i]==0) continue;
		ans=min(ans,cn2(i)+cn2(n-i));
	}
	printf("%d\n",ans);
}

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

Measured memory_bytes: 8576
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef  long long ll;
typedef  vector<int> vi;
typedef  pair<int,int> ii;
typedef  pair<int,string> pis;
double   pi=3.1415926535898;
#define speed      ios::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
#define lp(i,n)    for(int i=0;i<int(n);i++)
#define ff(i,a,b)  for(int i=a;i<=int(b);++i)
#define fr(i,a,b)  for(int i=a;i>=int(b);i--)
#define ms(x,a)    memset(x,a,sizeof(x))
#define all(x)     (x).begin(),(x).end()
#define sz(x)      int(x.size())
#define pb         push_back
#define r0         return 0;
#define CC         continue;
#define bb(x)      cerr<< x <<endl;
#define F          first
#define S          second       //  __builtin_popcount;
//freopen("input.txt","r",stdin),freopen("output.txt","w",stdout);
string ys = "YES\n";
string no = "NO\n" ;
const double EPS = 1e-9;
const int inf = 1<<30;
const ll M  = 1e9+7 ;
//const int N = 100100;
//////////////////////    Hi    ^_^  hack me if you can :P

int n , x;

int f[100200];

int main()
{
    speed;

    cin >> n;
    ff(i,1,n) {
        cin >> x;
        ++f[x];
    }
    int ans = 0;
    ff(i,0,100100) {
        int tmp = 0;
        if (i)
        tmp += f[i-1];
        tmp += f[i+1];
        tmp += f[i];

        ans = max(ans,tmp);

    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        List<Integer> numList = new ArrayList<>(Arrays.asList(a, b, c));
        Collections.sort(numList);
        String displayNumber = numList.stream().map(Object::toString).collect(Collectors.joining(" "));
        System.out.println(displayNumber);
    }
}


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

signed main() {
	int n;
	cin >> n;
	vector<int> a(n + 2);
	for (int i = 0; i < n; ++i) {
		cin >> a[i + 1];
	}
	int sum = 0;

	for (int i = 0; i < n + 1; ++i) {
		sum += abs(a[i] - a[i + 1]);
	}

	for (int i = 1; i <= n; ++i) {
		if ((a[i - 1] <= a[i] and a[i] >= a[i + 1]) or (a[i - 1] >= a[i] and a[i] <= a[i + 1])) {
			cout << sum - 2 * min(abs(a[i - 1] - a[i]), abs(a[i] - a[i + 1])) << endl;
		}
		else {
			cout << sum << endl;
		}
	}
}


Measured memory_bytes: 1664
MOD=10**9+7
N,K=map(int,input().split())
A=list(map(int,input().split()))
fo=[0]*N
al=[0]*N
for i in range(N):
    for j in range(N):
        if(A[i]>A[j]):
            if(i<j):
                fo[i]+=1
            al[i]+=1
res=0
for i in range(N):
    res=((res+fo[i]*K)%MOD+(al[i]*(K*(K-1)//2))%MOD)%MOD
print(res)

Measured memory_bytes: 41836
import re

def selectionSort(A, N):
    for i in range(N):
        minj = i
        for j in range(i,N):
            if A[j][1] < A[minj][1]:
                minj = j
        if i != minj:        
            ho = A[i]
            A[i] = A[minj]
            A[minj] = ho
    return A
def bubblesort(A,N):
    flag = 1 
    while flag:
        flag = 0
        for j in range(N-1,0,-1):
           if A[j][1] < A[j-1][1]:
                ho = A[j]
                A[j] = A[j-1]
                A[j-1] = ho
                flag = 1
    return A

n = int(input())
a = [i for i in input().split()]
c = a.copy()
e = a.copy()
b = bubblesort(a,n)
for i in range(len(b)):
    if i == len(b)-1:
        print(b[i])
    else:
        print(b[i],end=' ')            
f = sorted(e, key=lambda x:int((re.search(r"[0-9]+", x)).group(0)))
D = 0
for i in range(len(b)):
    if f[i] != b[i]:
        print('Not stable')
        D = 1
        break
if D == 0:
    print('Stable')
d = selectionSort(c,n)
for i in range(len(d)):
    if i == len(d)-1:
        print(d[i])
    else:
        print(d[i],end=' ')            
D = 0
for i in range(len(d)):
    if f[i] != d[i]:
        print('Not stable')
        D = 1
        break
if D == 0:
    print('Stable')


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


using namespace std;

typedef long long ll;
typedef pair<string, string> pss;

const int MAXN = 20;




int n;
string s;
bitset<MAXN> bs;
ll ans;
map<pss, ll> mp1, mp2;



int main() {
	cin >> n >> s;
	reverse(s.begin() + n, s.end());
	do {
		string a, b;
		for (int i = 0; i < n; i++)
			if (bs[i])
				a.push_back(s[i]);
			else
				b.push_back(s[i]);
		mp1[{a, b}]++;
	} while ((bs = bs.to_ulong() + 1) != (1 << n));
	bs = 0;
	do {
		string a, b;
		for (int i = 0; i < n; i++)
			if (bs[i])
				a.push_back(s[n + i]);
			else
				b.push_back(s[n + i]);
		mp2[{a, b}]++;
	} while ((bs = bs.to_ulong() + 1) != (1 << n));
	for (auto i : mp1)
		ans += mp2[i.first] * i.second;
	cout << ans;
	return 0;
}

Measured memory_bytes: 108288
# 最短経路を探す bfs
# (全体の白の数) - (けぬす君が通ったマスの数) = (答え)
from collections import deque
H,W = map(int,input().split())
grid = [[""]*W for i in range(H)]
visited = [[0]*W for i in range(H)]
visited[0][0] = 1
white = 0

for i in range(H):
    s = input()
    for j in range(W):
        grid[i][j] = s[j]
        if grid[i][j] == ".":
            white += 1

q = deque([[0,0]])
d = [[0,1],[1,0],[0,-1],[-1,0]]

while q:
    i,j = q.popleft()
    if (i,j) == (H-1,W-1):
        break
    for di,dj in d:
        ni = i+di; nj = j+dj
        if 0 <= ni <= H-1 and 0 <= nj <= W-1\
             and visited[ni][nj] == 0 and grid[ni][nj] == ".":
            visited[ni][nj] = visited[i][j] + 1
            np = [ni,nj]
            q.append(np)
if visited[H-1][W-1] > 0:
    ans = white - visited[H-1][W-1]
else:
    ans = -1
print(ans)

Measured memory_bytes: 3316
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
using namespace std;
int main()
{
	int num;
	scanf("%d",&num);
	string s1,s2;
	for(;;)
	{
		bool f=false;
		for(int i=0;i<4;i++)
		{
			if(i&1)s1.push_back('#');
			else s1.push_back('.');
			if(i&2)s2.push_back('#');
			else s2.push_back('.');
			cout<<s1<<endl<<s2<<endl;
			fflush(stdout);
			string z;
			cin>>z;
			if(z=="end")return 0;
			if(z=="T")
			{
				f=true;
				break;
			}
			s1.pop_back();
			s2.pop_back();
		}
		if(!f)break;
	}
	for(;;)
	{
		bool f=false;
		for(int i=0;i<4;i++)
		{
			reverse(s1.begin(),s1.end());
			reverse(s2.begin(),s2.end());
			if(i&1)s1.push_back('#');
			else s1.push_back('.');
			if(i&2)s2.push_back('#');
			else s2.push_back('.');
			reverse(s1.begin(),s1.end());
			reverse(s2.begin(),s2.end());
			cout<<s1<<endl<<s2<<endl;
			fflush(stdout);
			string z;
			cin>>z;
			if(z=="end")return 0;
			if(z=="T")
			{
				f=true;
				break;
			}
			reverse(s1.begin(),s1.end());
			reverse(s2.begin(),s2.end());
			s1.pop_back();
			s2.pop_back();
			reverse(s1.begin(),s1.end());
			reverse(s2.begin(),s2.end());
		}
		if(!f)break;
	}
}

Measured memory_bytes: 724
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
using namespace std;
typedef long long LL;
int main()
{
	LL a,b;
	scanf("%lld%lld",&a,&b);
	puts(abs(a-b)<=1?"Brown":"Alice");
	return 0;
}


Measured memory_bytes: 256
import sys
from collections import deque
import copy
import heapq

from math import *

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, M] =  [int(input_raw[0]), int(input_raw[1])]
    graph = {}
    for i in range(M):
        input_raw = read_func().strip().split()
        [a, b, c] =  [int(input_raw[0]), int(input_raw[1]), -long(input_raw[2])]
        if a not in graph:
            graph[a] = [(b, c)]
        else:
            graph[a].append((b, c))

    dummy_inf = long(sys.maxint) * long(sys.maxint)
    dist_list =[dummy_inf for i in range(N + 1)]
    dist_list[1] = 0L

    for i in range(0, 2 * N):
        for j in range(1, N + 1):
            if j not in graph:
                continue
            for edge in graph[j]:
                if dist_list[j] < dummy_inf:
                    new_cost = dist_list[j] + edge[1]
                    if new_cost < dist_list[edge[0]]:
                        dist_list[edge[0]] = new_cost
                        if (i >= N - 1 and edge[0] == N):
                            print "inf"
                            return
    print -dist_list[N]


if __name__ == '__main__':
    main()

Measured memory_bytes: 3400
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
ll dp[122222][14];
ll mo[122222];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;cin>>s;
  ll n=s.size();
  mo[0]=1;
  for(int i=1;i<111111;i++)
    mo[i]=(mo[i-1]*10)%13;
  dp[n][0]=1;
  for(int i=n-1;i>=0;i--){
    if(s[i]=='?'){
      for(int k=0;k<10;k++){
	for(int j=0;j<13;j++){
	  dp[i][((k)*mo[n-i-1]+j)%13]+=dp[i+1][j];
	  dp[i][((k)*mo[n-i-1]+j)%13]%=MOD;
	}
      }
    }else{
      for(int j=0;j<13;j++){
	dp[i][((s[i]-'0')*mo[n-i-1]+j)%13]+=dp[i+1][j];
	dp[i][((s[i]-'0')*mo[n-i-1]+j)%13]%=MOD;
      }
    }
  }
  cout<<dp[0][5]<<endl;
  return 0;
}

Measured memory_bytes: 12624
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
typedef long long ll;
ll mod=1000000007;
int cnt=0;
int n;
vector<vector<int>> v;

void dfs(int val, int id){
  if(id==n){
    if(val%2==0) ++cnt;
    return;
  }
  dfs(val*v[id][0], id+1);
  dfs(val*v[id][1], id+1);
  dfs(val*v[id][2], id+1);
  return;
}

int main() {
  cin>>n;
  for(int i=0;i<n;++i){
    int a;cin>>a;
    vector<int> t;
    t.push_back(a-1);
    t.push_back(a);
    t.push_back(a+1);
    v.push_back(t);
  }
  dfs(1,0);
  cout << cnt << endl;
  return 0;
}


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

int main() {
  set<int> s;
  int N;
  cin >> N;
  rep(i,N) {
    int d;
    cin >> d;
    s.insert(d);
  }

  cout << s.size() << endl;

  return 0;
}


Measured memory_bytes: 256
s = sorted(input())
t = sorted(input(),reverse = True)
flag1 = True
flag2 = False
if len(s) < len(t):
    for i in range(len(s)):
        if s[i] != t[i]:
            flag1 = False
            break
else:
    flag1 = False
for i in range(min(len(s), len(t))):
    if s[i] < t[i]:
        flag2 = True
        break
    elif s[i] > t[i]:
        break
if flag1 or flag2:
    print('Yes')
else:
    print('No')


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

int main()
{
    int A, B;
    cin >> A >> B;

    int ans;
    if (A >= 13)
        ans = B;
    else if (6 <= A)
        ans = B/2;
    else
        ans = 0;
    cout << ans << endl;
  	return 0;
}

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

ll x[200006];
ll ax[200006];

ll comb(ll n,ll r){
  ll res = 1;

  res = (x[n]*ax[r] % MODSIZE)*ax[n - r] % MODSIZE;

  return res;
}

ll reppow(ll x,ll n){
  ll res = 1;
  while(n > 0){
    if(n & 1) res = res*x % MODSIZE;
    x = x*x % MODSIZE;
    n >>= 1;
  }

  return res;
}

int main(){
  ll h,w;
  ll a,b;
  ll ans = 0;

  scanf("%lld %lld %lld %lld", &h, &w, &a, &b);

  ll i;
  x[0] = 1; ax[0] = 1;
  for(i = 1;i <= h + w - 2;i++){
    x[i] = x[i - 1]*i % MODSIZE;
    ax[i] = reppow(x[i],MODSIZE - 2);
  }

  ll t = h - a - 1;
  for(i = b;i < w;i++){
    ans = (ans + comb(t + i,i)*comb(a + w - 2 - i,a - 1) % MODSIZE) % MODSIZE;
  }

  printf("%lld\n", ans);

  return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;


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

int a[12134],b[12345];
int main() {
    int n;
    cin>>n;
    for (int i=1;i<=n;i++)
        cin>>a[i];
    for (int i=1;i<=n;i++)
        cin>>b[i];

    int cc=0,dd=0;
    vector<int> c;
    for (int i=1;i<=n;i++) c.push_back(i);
    int idx=0;
    do {
        idx++;
        bool flag=false;
        for (int i=1;i<=n;i++)
        if (a[i]!=c[i-1]) {
            flag=true;
            break;
        }
        if (!flag) cc=idx;

        flag=false;
        for (int i=1;i<=n;i++)
        if (b[i]!=c[i-1]) {
            flag=true;
            break;
        }
        if (!flag) dd=idx;


    } while (next_permutation(c.begin(), c.end()));

    cout<<abs(cc-dd)<<endl;
    return 0;
}


Measured memory_bytes: 3556
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(25) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 510000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
  lli A,B,C,D,E,L,R,X,Y,W,H,N,M,K,sum=0,num=0,flag=0;string S,T;
  cin >> N;
  Vec(P,pint,N,pint(0,0));
  rep(i,0,N)cin >> P[i].second >> P[i].first;
  Sort(P);
  rep(i,0,N){
    sum+=P[i].second;
    if(sum>P[i].first){
      flag++;
      break;
    }
  }
  if(flag)Out("No");
  else Out("Yes");
}


Measured memory_bytes: 3328
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r;
	cin>>a>>b>>c>>d>>e>>f>>g>>h>>i>>j>>k>>l>>m>>n>>o>>p>>q>>r;
	cout<<(d*3600+e*60+f-a*3600-b*60-c)/3600<<" "<<(d*3600+e*60+f-a*3600-b*60-c)%3600/60<<" "<<(d*3600+e*60+f-a*3600-b*60-c)%3600%60<<endl;
	cout<<(j*3600+k*60+l-g*3600-h*60-i)/3600<<" "<<(j*3600+k*60+l-g*3600-h*60-i)%3600/60<<" "<<(j*3600+k*60+l-g*3600-h*60-i)%3600%60<<endl;
	cout<<(p*3600+q*60+r-m*3600-n*60-o)/3600<<" "<<(p*3600+q*60+r-m*3600-n*60-o)%3600/60<<" "<<(p*3600+q*60+r-m*3600-n*60-o)%3600%60<<endl;
	return 0;
	}



Measured memory_bytes: 3100
#include<bits/stdc++.h>
#define ll long long int
#define N 10000
#define endl '\n'
#define speed        ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

using namespace std;

void solve()
{
    ll a,b,c;
    cin >>a >>b >>c;
    if(c<=(a+b))
    {
        cout <<"No" <<endl;
        return;
    }
    ll x = a*a+b*b+c*c-2*a*c-2*a*b-2*b*c;
    if(x>0)
        cout <<"Yes" <<endl;
    else
        cout <<"No" <<endl;
    return;
}

int main()
{
    speed;
    ll t=1;
    //cin >>t;
    while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env ruby

N = 104_750 # ??¢?´¢???????´???°?????????
elt = Array.new(N, 1) # ??¨????????????????????????????????????
primes = [] # ?´???°???????´???????


# ??¨????????????????????????
elt[0] = 0
elt[1] = 0

N.times do |i|
  next if elt[i].zero?
  primes << i
  k = i * 2
  while k < N
    elt[k] = 0
    k += i
  end
end

while (n = gets.to_i) != 0
  puts (1..n).map{|e| primes[e-1]}.reduce(:+)
end

Measured memory_bytes: 12528
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl;

#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()

ll MAX(ll a){return a;}
ll MIN(ll a){return a;}
template<typename... Args>
ll MAX(ll a,Args... args){return max(a,MAX(args...));}
template<typename... Args>
ll MIN(ll a,Args... args){return min(a,MIN(args...));}

#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

const int MOD=998244353;

int n,k;
int arr[3005];

ll memo[3005][3005];
ll dp(int i,int j){ //i th element j thing taken
	if (i==n){
		if (j==k) return 1;
		else return 0;
	}
	
	if (j>k) return 0;
	if (memo[i][j]!=-1) return memo[i][j];
	
	ll res=(2*dp(i+1,j)+dp(i+1,j+arr[i]))%MOD;
	
	return memo[i][j]=res;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	memset(memo,-1,sizeof(memo));
	
	cin>>n>>k;
	rep(x,0,n) cin>>arr[x];
	
	
	cout<<dp(0,0);
}

Measured memory_bytes: 74416
import sys
import math

def insertion_sort(a, n, g):
    ct = 0
    for i in range(g,n):
        v = a[i]
        j = i-g
        while j >= 0 and a[j] > v:
            a[j+g] = a[j]
            j = j-g
            ct += 1
        a[j+g] = v
    return ct

n = int(input())
a = list(map(int, sys.stdin.readlines()))
b = 701
ct= 0
g = [x for x in [1,4,10,23,57,132,301,701] if x <= n]
while True:
    b = math.floor(2.25*b)
    if b > n:
        break
    g.append(b)
g = g[::-1]

for i in g:
    ct += insertion_sort(a, n, i)

print(len(g))
print(*g, sep=" ")
print(ct)
print(*a, sep="\n")

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

using namespace std;
#define lli long long
#define rep0(i,j) for(lli i = 0; i<j; i++)
#define all(x) (x).begin(),(x).end()

lli edge[1000000][2];

struct UnionFind {
	UnionFind() {};
	vector<lli> data;
	UnionFind(lli size) : data(size, -1) { }
	//UnionFindのコンストラクタdataをsizeだけ確保してすべて-1で初期化する.

	bool unionSet(lli x, lli y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}

		return x != y;
	}//xとyが入ってる集合を併合する

	bool findSet(lli x, lli y) {
		return root(x) == root(y);
	}//xとyが同じ集合に入っているかを判定する

	lli root(lli x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}//親の番号を返す(自分自身が親の場合は自分の番号)

	lli size(lli x) {
		return -data[root(x)];
	}//木のサイズ？
};
/*親が-1, 子は親の子もしくは親の番号を持つ*/


int main() {
	lli N, M;
	cin >> N >> M;
	
	vector<lli> ans(M,0);

	UnionFind tree = UnionFind(N);

	rep0(i, M) {
		cin >> edge[i][0] >> edge[i][1];
		edge[i][0]--; edge[i][1]--;
	}

	tree.unionSet(edge[M - 1][0], edge[M - 1][1]);
	ans[0] = N * (N - 1) / 2;
	if(M!=1)ans[1] = ans[0] - 1;

	for (lli i = 1; i < M-1; i++) {
		if (tree.findSet(edge[M-i-1][0], edge[M-i-1][1])) {
			ans[i+1] = ans[i];
		}else{
			ans[i+1] = ans[i] - tree.size(edge[M - i - 1][0])*tree.size(edge[M - i - 1][1]);
		}
		tree.unionSet(edge[M - i - 1][0], edge[M - i - 1][1]);
	}	
	
	sort(all(ans));
	rep0(i, M) cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 4480
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
 
#define MAX 250002
int n;
 
char buf[MAX];
 
__int128 mod1=1007ll;
__int128 mod2=1000000000000000031LL;
 
inline __int128 mul(__int128 a,__int128 b){
	return (a*b)%mod2;
}
inline __int128 add(__int128 a,__int128 b){
	auto f=a+b;
	if(f>=mod2)f%=mod2;
	return f;
}
inline __int128 sub(__int128 a,__int128 b){
	auto f=a-b;
	if(f<0)f+=mod2;
	f%=mod2;
	return f;
}
__int128 ppow(__int128 a,__int128 b){
	__int128 res=1;
	while(b){
		if(b&1LL)res*=a;
		if(res>=mod2)res%=mod2;
		a*=a;
		a%=mod2;
		b>>=1LL;
	}
	return res;
}
unordered_map<long long int,int> cnt;
vector<pair<__int128,__int128> > v;
int main() {
	cin>>n;
	scanf("%s",buf);
	auto inv = ppow(mod1,mod2-2);
	__int128 cur=1;
	__int128 hs=0;
	int sz=strlen(buf);
	v.push_back(make_pair(0,1));
	for(int i=0;i<sz;i++){
		if(buf[i]=='<'){
			cur=mul(cur,inv);
		}
		if(buf[i]=='>'){
			cur=mul(cur,mod1);
		}
		if(buf[i]=='+'){
			hs=add(hs,cur);
		}
		if(buf[i]=='-'){
			hs=sub(hs,cur);
		}
		v.push_back(make_pair(hs,cur));
	}
	__int128 acieve=v.back().first;
	//(x-c)/second=acieve
	//x-c=acieve/second
	//x = c+ acieve/second
	long long int way=0;
	for(int i=v.size()-1;i>=0;i--){
		__int128 want=add(v[i].first,mul(acieve,v[i].second));
		way+=cnt[want];
		cnt[v[i].first]++;
		//cerr<<i<<" "<<way<<endl;
	}
	printf("%lld\n",way);
	return 0;
}


Measured memory_bytes: 28264
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;
ll h,w;

ll t1() {
    ll ret = LINF;
    for (int i = 1; i < h; ++i) {
        ll p1, p2, p3;
        ll rest_h = h-i;
        ll rest_w = w-(w/2);

        p1 = i*w;
        p2 = rest_h*(w/2);
        p3 = rest_w*rest_h;

        ll max_t1 = max({p1, p2, p3});
        ll min_t1 = min({p1, p2, p3});

        ret = min(ret, (max_t1-min_t1));
    }
    return ret;
}

ll t2() {
    ll ret = LINF;
    for (int i = 1; i < w; ++i) {
        ll p1, p2, p3;
        ll rest_h = h-(h/2);
        ll rest_w = w-i;

        p1 = h*i;
        p2 = rest_w*(h/2);
        p3 = rest_w*rest_h;

        ll max_t1 = max({p1, p2, p3});
        ll min_t1 = min({p1, p2, p3});

        ret = min(ret, (max_t1-min_t1));
    }
    return ret;
}

ll t3() {
    ll ret = LINF;
    for (int i = 1; i < h; ++i) {
        ll p1, p2, p3;
        ll rest_h1 = (h-i)/2;
        ll rest_h2 = h-i-rest_h1;

        p1 = i*w;
        p2 = rest_h1*w;
        p3 = rest_h2*w;

        ll max_t1 = max({p1, p2, p3});
        ll min_t1 = min({p1, p2, p3});
        
        ret = min(ret, max_t1-min_t1);
    }
    return ret;
}

ll t4() {
    ll ret = LINF;
    for (int i = 1; i < w; ++i) {
        ll p1, p2, p3;
        ll rest_w1 = (w-i)/2;
        ll rest_w2 = w-i-rest_w1;

        p1 = h*i;
        p2 = rest_w1*h;
        p3 = rest_w2*h;

        ll max_t1 = max({p1, p2, p3});
        ll min_t1 = min({p1, p2, p3});
        
        ret = min(ret, max_t1-min_t1);
    }
    return ret;
}

int main(int argc, char const *argv[]) {
    cin >> h >> w;
    ll ans = min({t1(), t2(), t3(), t4()});
    cout << ans << endl;
    return 0;
}

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

#define FOR0(i,n) for (int i = 0; i < n; i++)
#define FOR(i,j, n) for (int i = j; i < n; i++)
// bool isEven(ll n) {return (n%2!=0)?false:true;};
#define INF 1000000000 // 1 billion, safer than 2B for Floyd Warshall’s

#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
// #define int ll

using namespace std;

//atcoder
//abc167


int main()
{
    int n;
    long long k;

    cin>>n>>k;

    bool a[n+1] = {false};
    int path[n+1];

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

    int firstRepeatIndex = -1;
    int firstRepeatLength = 1;

    a[1] = true;

    int index = 1;

    while(!a[path[index]]){

        if(k==firstRepeatLength){
            cout<<path[index]<<endl;
            return 0;
        }

        firstRepeatLength++;
        a[path[index]]=true;
        index = path[index];
    }





    firstRepeatIndex = path[index];

    // cout<<"firstrepeastindex: " << firstRepeatIndex<<endl;
    // cout<<"firstrepeastlength: " << firstRepeatLength<<endl;
    
    int roundLength = 1;

    FOR0(i, n+1) a[i] = false;

    a[firstRepeatIndex] = true;
    index = firstRepeatIndex;

    while(!a[path[index]]){
        roundLength++;
        a[path[index]] = true;
        index = path[index];
    }

    // cout<<"roundlength:"<<roundLength<<endl;
    // cout<<"(k - firstRepeatLength) mod firstRepeatLength = "<<(k-firstRepeatLength)%roundLength<<endl;

    long long left = (long long)(k-(long long)firstRepeatLength)%(long long)(roundLength);

    // cout<<"LEFT  = "<<left<<endl;
// 
    FOR0(i, n+1) a[i] = false;

    index = firstRepeatIndex;

    while(left--){
        index = path[index];
    }
    // cout<<"finalpos:"<<index<<endl;
    cout<<index<<endl;
}

Measured memory_bytes: 4624
#include <iostream>
#include <vector>
#include<algorithm>
#include <string>
#include <cmath>
#include<queue>
#define PI 3.141592653589793238
using namespace std;

int main()
{
	int a, b;

	cin >> a >> b;

	for (int i = 1; i < 4; i++) {
		if (i != a && i != b) {
			cout << i;
			break;
		}
	}

	return 0;
}

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

using namespace std;

int main(){
	int n, r;
	
	while(cin >> n >> r, n | r){
		vector<int> p, c;
		int tempp, tempc;
		vector< vector<int> > deck;
		
		deck.resize(r + 1);
		for(int i = 0; i <= r; i++){
			deck[i].resize(n);
		}
		
		for(int i = 0; i < n; i++){
			deck[0][i] = n - i;
		}
		
		for(int i = 0; i < r; i++){
			cin >> tempp >> tempc;
			p.push_back(tempp);
			c.push_back(tempc);
		}
		
		for(int i = 1; i <= r; i++){
			int count = 0;
			for(int j = p[i - 1] - 1; j < p[i - 1] + c[i - 1] - 1; j++){
				deck[i][count] = deck[i - 1][j];
				count++;
			}
			for(int k = 0; k < p[i - 1] - 1; k++){
				deck[i][count] = deck[i - 1][k];
				count++;
			}
			for(int l = p[i - 1] + c[i - 1] - 1; l < n; l++){
				deck[i][count] = deck[i - 1][l];
				count++;
			}
		}
		
		cout << deck[r][0] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1236
from math import gcd, sqrt

n = int(input())
A = [int(x) for x in input().split()]

g = A[0]
for a in A[1:]:
    g = gcd(g, a)

ans = set()

for i in range(1, int(sqrt(g)) + 1):
    if g % i == 0:
        ans.add(i)
        ans.add(g // i)

for a in sorted(ans):
    print(a)



Measured memory_bytes: 5672
#include <bits/stdc++.h>
using longlong=long long;

int main(){
    std::cin.tie(nullptr);std::cin.sync_with_stdio(false);
    int n; std::cin >> n;
    int m=0;
    for(int i=n;i>0;i/=10){
        m+=i%10;
    }
    std::cout << (n%m==0?"Yes":"No") << std::endl;
}

Measured memory_bytes: 256