akhauriyash/Code-Regression huggingface dataset:
import sys
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces

import collections
import itertools
import operator

class UnionFind:
  def __init__(self, elems=None):
    class KeyDict(dict):
      def __missing__(self, key):
        self[key] = key
        return key

    self.parent = KeyDict()
    self.rank = collections.defaultdict(int)
    self.size_ = collections.defaultdict(lambda: 1)

    if elems is not None:
      for elem in elems:
        _, _, _ = self.parent[elem], self.rank[elem], self.size_[elem]

  def find(self, x):
    if self.parent[x] == x:
      return x
    else:
      self.parent[x] = self.find(self.parent[x])
      return self.parent[x]

  def unite(self, x, y):
    x = self.find(x)
    y = self.find(y)
    if x == y:
      return
    if self.rank[x] < self.rank[y]:
      self.parent[x] = y
      self.size_[y] += self.size_[x]
    else:
      self.parent[y] = x
      self.size_[x] += self.size_[y]
    if self.rank[x] == self.rank[y]:
      self.rank[x] += 1

  def are_same(self, x, y):
    return self.find(x) == self.find(y)

  def grouper(self):
    roots = [(x, self.find(x_par)) for x, x_par in self.parent.items()]
    root = operator.itemgetter(1)
    for _, group in itertools.groupby(sorted(roots, key=root), root):
      yield [x for x, _ in group]

  def size(self,x):
    return self.size_[self.find(x)]

n,m = na()
ab = [na() for c in range(m)]
uf = UnionFind()
ans = [n*(n-1)//2]

for a,b in reversed(ab):
  if not uf.are_same(a,b):
    ans.append(ans[-1]-uf.size(a)*uf.size(b))
  else:
    ans.append(ans[-1])
  uf.unite(a,b)
  
print('\n'.join(reversed([str(x) for x in ans][:-1])))

Measured memory_bytes: 59472
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <iomanip>
#include <map>
#include <queue>
#include <list>

#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
//#define RREP(i, n ,N) for(ll i = (N-1); i >= (n); i--)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
#define INF 1e9

using namespace std;
typedef long long  ll;

const long long MOD = 1e9+7;

bool is_prime(int x){
    if(x<=1) return false;
    REP(i, 2, x){
        if(x%i==0) return false;
    }
    return true;
}

int main(){
    int x;
    cin >> x;
    while(not is_prime(x)){
        x++;
    }
    p(x);
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include <numeric>
#include<queue>
#include<climits>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
//#define INF LLONG_MAX / 2;
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef long long int ll;
typedef pair<ll,int> LL_IP;

const ll INF = LLONG_MAX;

#define ARRAY_MAX 100005


typedef struct edge{

    int to;
    int cost;
    
}EDGE;

bool map[105][105];


void dijkstra(int n,vector<vector<EDGE> >& G,int x){

    

    vector<ll> d(n,INF);
    d[x] = 0;
    priority_queue<LL_IP,vector<LL_IP>,greater<LL_IP> > que;
    que.push(LL_IP(0,x));

    while(!que.empty()){

        LL_IP p = que.top();
        que.pop();
        int v = p.second;
        if(d[v] < p.first){
            continue;
        }

        for(int i = 0;i < G[v].size(); i++){
            EDGE e = G[v][i];
            if(d[e.to] > d[v] + e.cost){
                d[e.to] = d[v] + e.cost;
                que.push(LL_IP(d[e.to],e.to));
            }
                    
        }
    }

    que.push(LL_IP(0,x));

    while(!que.empty()){

        LL_IP p = que.top();
        que.pop();
        int v = p.second;
        if(d[v] < p.first){
            continue;
        }

        for(int i = 0;i < G[v].size(); i++){
            EDGE e = G[v][i];
            if(d[e.to] == d[v] + e.cost){
                map[v][e.to] = true;
                map[e.to][v] = true;
                que.push(P(d[e.to],e.to));
            }
                    
        }
    }
}


/*ABC070 AC解法*/
int main(){

    int n,m,a,b,c;
    cin >> n >> m;
    REP(i,105){
        REP(j,105){
            map[i][j] = false;
        }
    }

    vector<vector<EDGE> > G(n);/*n個の各頂点からそれ以外の頂点へのコスト*/

    REP(i,m){
        cin >> a >> b >> c;
        a--;
        b--;/*配列の添え字へ合わせる*/
        EDGE e1 = {b,c};
        EDGE e2 = {a,c};
        /*無効グラフなので双方向にコストを保持*/
        G[a].pb(e1);/*頂点aから頂点bへのコストがc*/
        G[b].pb(e2);/*頂点bから頂点aへのコストがc*/
    }
    /*辺の張り終わり*/

    REP(i,n){
        dijkstra(n,G,i);
    }

    int count = 0;/*最短距離の辺の個数*/
    REP(i,n){
        REP(j,n){
            if(map[i][j]){
                count++;
                map[i][j] = false;
                map[j][i] = false;
            }

        }
    }   
    cout << m-count << endl;

    return 0;
}

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

using namespace std;

int main()
{
	vector<string> map;
	vector<string> ans;
	string tmp;
	int h, w;
	bool flag = false;
	
	cin >> h >> w;
	
	for (int i = 0; i < h; i++) {
		cin >> tmp;
		map.push_back(tmp);
	}
	
	for (int i = 0; i < h; i++) {
		ans.push_back(map[i]);
		if (flag == false) {
			i--;
			flag = true;
		}
		else {
			flag = false;
		}
	}
	
	for (int i = 0; i < h * 2; i++) {
		cout << ans[i] << endl;
	}
	
	return (0);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)

int main() {
	//int a,b,x;
	long double a,b,x,ans,c,ans2;
	cin>>a>>b>>x;
	if(x<=a*a*b/2){
	    c=2*x/(a*b);
	    ans=atanl(b/c);
	}
	else{
	    c=2*b-2*x/(a*a);
	    ans=atanl(c/a);
	}
	ans2=ans*180/3.14159265;
	cout<<setprecision(10)<<ans2;
	return 0;
}


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

int main(){
  int a,b;
  cin>>a>>b;
  char c;
  string d;
  for(int i=1;i<a+1;i++){
    for(int j=0;j<b;j++){
    cin>>d;
      if(d=="snuke"){
        c='A'+j;
      cout<<c<<i<<endl;
      }
    }
  }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

struct unionfind_tree{
    int par[500000], rank[500000], num[500000];
    //要素数n(0〜n-1)の初期化されたUnion-Find木を構築
    unionfind_tree(int N){
        rep(i, N){par[i] = i, rank[i] = 0, num[i] = 1;}
    }
    //ノードxの根を取得
    int find(int x){
        if(par[x] == x) return x;
        else return find(par[x]);
    }
    //xとyの属する集合を併合
    void unite(int x, int y){
        x = find(x), y = find(y);
        if(x == y) return;
        elif(rank[x] < rank[y]){par[x] = y, num[y] += num[x];}
        else{
            par[y] = x, num[x] += num[y];
            if(rank[x] == rank[y]) rank[x]++;
        }
    }
    //xの属する集合の要素数を取得
    int size(int x){
        return num[find(x)];
    }
    //xとyが同じ集合に属するか判定
    bool same(int x, int y){
        return find(x) == find(y);
    }
};

int main(){
    int N;
    cin >> N;
    pll p[N];
    rep(i, N){
        ll x, y;
        cin >> x >> y;
        p[i] = pll(x, y);
    }
    pli x[N];
    rep(i, N){
        x[i] = pli(p[i].first, i);
    }
    pli y[N];
    rep(i, N){
        y[i] = pli(p[i].second, i);
    }
    sort(x, x+N);
    sort(y, y+N);
    vector<pli> vx[N], vy[N];
    rep(i, N){
        int v = x[i].second;
        if(i != N-1) vx[v].pb(pli(x[i+1].first - x[i].first, x[i+1].second));
        if(i != 0) vx[v].pb(pli(x[i].first - x[i-1].first, x[i-1].second));
    }
    rep(i, N){
        int v = y[i].second;
        if(i != N-1) vy[v].pb(pli(y[i+1].first - y[i].first, y[i+1].second));
        if(i != 0) vy[v].pb(pli(y[i].first - y[i-1].first, y[i-1].second));
    }
    priority_queue<pli, vector<pli>, greater<pli> > qx, qy;
    for(auto &e: vx[0]){
        qx.push(e);
    }
    for(auto &e: vy[0]){
        qy.push(e);
    }
    ll ans = 0;
    unionfind_tree uft(N);
    while(uft.size(0) < N){
        while(uft.same(0, qx.top().second)){
            qx.pop();
        }
        while(uft.same(0, qy.top().second)){
            qy.pop();
        }
        if(qx.top().first < qy.top().first){
            ans += qx.top().first;
            int v = qx.top().second;
            uft.unite(0, v);
            qx.pop();
            for(auto &e: vx[v]) qx.push(e);
            for(auto &e: vy[v]) qy.push(e);
        }
        else{
            ans += qy.top().first;
            int v = qy.top().second;
            uft.unite(0, v);
            qy.pop();
            for(auto &e: vx[v]) qx.push(e);
            for(auto &e: vy[v]) qy.push(e);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 29560
#include <cstdio>

int main()
{
	int a, b, c;
	int cnt = 0;

	scanf(" %d %d %d", &a, &b, &c);

	for (int i = a; i <= b; ++i)
	{
		if(c % i == 0){
			cnt++;
		}
	}

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

	return 0;
}


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

using namespace std;

int main() {
	int H, W, K;
	cin >> H >> W >> K;

	vector<vector<char>> c(H, vector<char>(W));
	int count = 0;
	int result = 0;

	for(int i = 0; i < H; i++) {
		for(int j = 0; j < W; j++) {
			cin >> c.at(i).at(j);
		}
	}

	for(int biti = 0; biti < (1<<H); biti++) {
		for(int bitj = 0; bitj < (1<<W); bitj++) {
			count = 0;
			for(int i = 0; i < H; i++) {
				for(int j = 0; j < W; j++) {
					if(!(biti & (1<<i)) || !(bitj & (1<<j))) {
						continue;
					}
					if(c.at(i).at(j) == '#') {
						count++;
					}
				}
			}
			if(count == K) {
				result++;
			}
		}
	}

	cout << result << endl;
	return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <utility>

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;

using namespace std;

int n,m;
vector<int> edge[100005];
int dp[100005]={};
bool isvisited[100005]={false};

int search(int x){
    if(isvisited[x]){
	return dp[x];
    }
    isvisited[x]=true;
    
    int nx=0;
    rep(i,edge[x].size()){
	nx=max(search(edge[x][i])+1,nx);
    }
    dp[x]=nx;
    return dp[x];
}

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

    cin>>n>>m;
    int x,y;
    reps(i,m){
	cin>>x>>y;
	edge[x].push_back(y);
    }
    
    int maxv=0;
    reps(i,n){
	maxv=max(maxv,search(i));
    }
    

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


Measured memory_bytes: 8320
def main():
  X_hiki, Y_hon = map(int, input().split())

  for i in range(X_hiki + 1):
    kame_hiki = i
    tsuru_wa = X_hiki - i
  
    if 4 * kame_hiki + 2 * tsuru_wa == Y_hon:
      print('Yes')
      return

  print('No')
  return


main()

Measured memory_bytes: 9176
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <bitset>
#include <stack>
#include <deque>
using namespace std;
typedef pair<int, int> pii;
typedef pair<int, pii> pip;
typedef long long LL;
const int MAXN = 123456;
int par[MAXN];
LL gp[MAXN], postp[MAXN];
bool visit[MAXN];

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

void merge(int x, int y) {
     x = find(x);
     y = find(y);
     if (x == y) return;
     par[y] = x;
     gp[x] += gp[y];
     postp[x] += postp[y];
}

int main() {
    int N, M;
    scanf("%d %d", &N, &M);
    for (int i = 1; i <= N; i++) {
        par[i] = i;
        scanf("%lld", &gp[i]);
    }
    vector<pip> edges;
    for (int i = 0; i < M; i++) {
        int a, b, c;
        scanf("%d %d %d", &a, &b, &c);
        edges.push_back(make_pair(c, make_pair(a, b)));
    }
    sort(edges.begin(), edges.end());
    for (auto i : edges) {
        int c = i.first, a = i.second.first, b = i.second.second;
        merge(a, b);
        int cur = find(a);
        if (c > gp[cur]) postp[cur]++;
        else postp[cur] = 0;
    }
    LL ans = 0;
    for (int i = 1; i <= N; i++) {
        int cur = find(i);
        if (visit[cur]) continue;
        visit[cur] = 1;
        ans += postp[cur];
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 3956
# -*- coding: utf-8 -*-

n = int(input())

# for i in range(1, 10**9):
#     if i % 2 == 0 and i % n == 0:
#         print(i)
#         break

if n % 2 == 0:
    print(n) 
else:
    print(2*n)

Measured memory_bytes: 2940
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;

/*BigInteger
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/rational.hpp>
namespace xxx = boost::multiprecision;
using Bint = xxx::cpp_int;
using Real = xxx::number<xxx::cpp_dec_float<1024>>;
*/

#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0, sizeof(x))
#define mm(x) memset((x), -1, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define bit(n) (1LL << (n))
#define bitset(a, b) (a) |= (1 << (b))
#define bitunset(a, b) (a) &= ~(1 << (b))
#define bitcheck(a, b) ((((a) >> (b)) & 1) == 1)
#define bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
constexpr int INF = (int)1e18;
constexpr int MOD = (int)1e9 + 7;
constexpr double PI = (double)acos(-1);
constexpr double EPS = (double)1e-10;
constexpr int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
constexpr int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
template <typename T>
void chmax(T &a, T b) { a = max(a, b); }
template <typename T>
void chmin(T &a, T b) { a = min(a, b); }
//
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
};

int dp[101010][2];
vector<int> G[101010];

int rec(int n, int pre, int col) {
  if (dp[n][col] > 0) return dp[n][col];

  int res = 1;
  for (auto x : G[n]) {
    if (x != pre) {
      if (col == 0) {
        res *= rec(x, n, 1) % MOD;
        res %= MOD;
      } else if (col == 1) {
        int tmp = (rec(x, n, 0) % MOD + rec(x, n, 1) % MOD) % MOD;
        res *= tmp;
        res %= MOD;
      }
    }
  }

  return dp[n][col] = res % MOD;
}

signed main() {
  int N;
  cin >> N;
  for (int i = 0; i < N - 1; i++) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    G[x].push_back(y);
    G[y].push_back(x);
  }

  cout << (rec(0, -1, 0) + rec(0, -1, 1)) % MOD << endl;
  return 0;
}


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

using lli = long long int;

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

template <class T>ostream &operator<<(ostream &o,const pair<T, T>&p)
{o<<"("<<p.first<<", "<<p.second<<")";return o;}

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

int main(void){
    string s;
    cin >> s;
    if(s[2] == s[3] && s[4] == s[5]) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  int N; cin>>N;
  int ans=2;
  if(N==2) ans--;
  set<int> S;
  REP(i,2,sqrt(N)){
    int X=N;
    while(X%i==0){
      X/=i;
    }
    if((X-1)%i==0){
      S.insert(i);
      if(X==N){
        S.insert((N-1)/i);
      }
    }
  }
  ans+=S.size();
  cout<<ans<<endl;
  }



Measured memory_bytes: 256
/***********************************************************************


    __       ____ ____   ___                 _  __  __           __   
   / /      |  _ \___ \ / _ \               | |/ _|/ _|          \ \  
  / /_____  | |_) |__) | | | |_      ___   _| | |_| |_ ____  _____\ \ 
 < <______| |  _ <|__ <| | | \ \ /\ / / | | | |  _|  _|_  / |______> >
  \ \       | |_) |__) | |_| |\ V  V /| |_| | | | | |  / /        / / 
   \_\      |____/____/ \___/  \_/\_/  \__,_|_|_| |_| /___|      /_/  
                                                                      
                                                                      

************************************************************************/

#include <bits/stdc++.h>

#define loop(i, a, b) for (int i = a; i < b; i++)
#define wh(x) \
    int x;    \
    cin >> x; \
    while (x--)
#define mkar(arr, n) \
    int arr[n];      \
    loop(i, 0, n) { cin >> arr[i]; }
#define print_ar(arr, n)                     \
    loop(i, 0, n) { cout << arr[i] << " "; } \
    cout << endl;
#define pii pair<int, int>
#define mci map<char, int>
#define endl "\n"
#define ll long long
#define ull unsigned long long
#define pb push_back
#define FIO                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)
#define slow(x) this_thread::sleep_for(chrono::milliseconds(x));
#define setbitmsb(x) (int)log2(x)
#define setbitlsb(x) (int)log2(x & -x)
#define OJ                            \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout)

using namespace std;

void setBit(ull &num, int ind)
{
    num |= (1ULL << ind);
}
void unsetBit(ull &num, int ind)
{
    num &= (~(1ULL << ind));
}

int main()
{
    // FIO;
    // OJ;
    int n;
    ull k;
    cin >> n >> k;
    int arr[n + 1];
    loop(i, 1, n + 1)
    {
        cin >> arr[i];
    }
    vector<int> v;
    map<int, bool> m;
    v.pb(1);
    m[1] = true;
    int i = 1;
    while (!m[arr[i]])
    {
        v.pb(arr[i]);
        m[arr[i]] = true;
        i = arr[i];
    }

    int pos = distance(v.begin(), find(v.begin(), v.end(), arr[i]));
    // // v.erase(v.begin(), v.begin() + i - 1);
    // print_ar(v, v.size());
    // cout << pos << endl;

    if (k <= pos)
    {
        cout << v[k] << endl;
    }
    else
    {
        ull ind = pos + (k - pos) % (v.size() - pos);
        cout << v[ind] << endl;
    }
    return 0;
}


Measured memory_bytes: 13912
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
#define fi first
#define se second
#define pii pair<int,int>

signed main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    string s;
    cin >> s;
    bool good = true;
    for(int i = 0; i < sz(s) - 1; i++) {
        if(s[i] == s[i + 1])
            good = false;
    }
    if(good) {
        cout << "Good\n";
    }else {
        cout << "Bad\n";
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>
#include <numeric>
using namespace std;
pair <long long, long long> XH[200000];
int main(){
  int N;
  long long D;
  long long A;
  cin >> N >> D >> A;
  for(int i = 0; i < N; i++){
    cin >> XH[i].first >> XH[i].second;
  }
  sort(XH, XH + N);

  queue <pair <long long, long long> > q;
  long long damage_sum = 0;
  long long ans = 0;
  for(int i = 0; i < N; i++){
    while(!q.empty() && q.front().first < XH[i].first){
      damage_sum -= q.front().second;
      q.pop();
    }

    long long cur_H = XH[i].second - damage_sum;
    if(cur_H > 0){
      int use_bomb_num;
      if(cur_H % A == 0){
        use_bomb_num = cur_H / A;
      } else {
        use_bomb_num = cur_H / A + 1;
      }
      ans += use_bomb_num;
      damage_sum += use_bomb_num * A;
      q.push(make_pair(XH[i].first + 2 * D, use_bomb_num * A));
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4992
import java.util.*;
public class Main {
    public static void main(String [] args){
        Scanner sc = new Scanner(System.in);
        int N,A,B,sum=0;
        N=sc.nextInt();
        A=sc.nextInt();
        B=sc.nextInt();
        for(int a=1;a<=N;a++){
            int num =a;
            int sum_num2=0;
            while(num !=0){
                sum_num2 += num%10;
                num /=10;
            }
            if(A<=sum_num2&&sum_num2<=B){
                sum +=a;
            }
        }
        System.out.println(sum);
    }
}


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

class Proc{
public:
  string nam;
  int tim;
  Proc(){ nam=""; tim=0; }
};

Proc Q[100001];

class Queue{
private:
  int fp;
  int rp;
public:
  Queue(){fp=0;rp=0;}
  int next(int p) const {return (p+1)%100001;}
  bool isFull() const {return (next(rp)==fp);}
  bool isEmpty() const {return(rp==fp);}
  void push(Proc d){
    if(isFull())
      return;
    Q[rp] = d;
    rp = next(rp);
  }
  Proc front(){
    if(isEmpty()){
      Proc er;
      er.tim = -1;
      return er;
    }

    return Q[fp];
  }
  void pop(){
    if(isEmpty())
      return;
    fp = next(fp);
  }
};

int main(){
  Queue que;

  int n,q;
  cin >> n >> q;
  for(int i=0;i<n;i++){
    Proc p;
    cin >> p.nam >> p.tim;
    que.push(p);
  }
  int total_tim = 0;
  while(!que.isEmpty()){
    Proc p =que.front(); que.pop();
    if(p.tim<=q){
      total_tim += p.tim;
      cout << p.nam << " " << total_tim << endl;
    }
    else{
      total_tim += q;
      p.tim-=q;
      que.push(p);
    }
  }
  return 0;
}



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

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


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

int main(){
  int K;
  cin >> K;
  
  int ans=0;
  
  for (int a=1; a<=K; a++){
    for (int b=1; b<=K; b++){
      for (int c=1; c<=K; c++){
        ans += GCD (a, b, c);
      }
    }
  }
  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3192
import collections

N, K, Q = map(int, input().split())

if K > Q:
    for n in range(N):
        print("Yes")
else:
    A = [K] * N
    answer_list = []

    for q in range(Q):
        answer_list.append(int(input()))

    answer_list_counts = collections.Counter(answer_list)

    is_clear = [False] * N
    for key in answer_list_counts:
        if K > Q - answer_list_counts[key]:
            is_clear[key - 1] = True


    for n in range(N):
        if is_clear[n]:
            print("Yes")
        else:
            print("No")

Measured memory_bytes: 12284
#include <algorithm>
#include <iostream>
using namespace std;
using ll = long long;

ll N;
ll A[200010], sum[200010];
// 入力の数列と、その累積和(1-indexed)

// (A_b, ..., A_e)を大体半分にカットし、前半と後半の総和を返す
pair<ll, ll> divide(ll b, ll e) {
    ll ok = b, ng = e;
    ll ds = sum[e] - sum[b - 1];

    // 二分探索で真ん中ちょい手前を探る
    while (ng - ok > 1) {
        ll mid = (ok + ng) / 2;
        ll ps = sum[mid] - sum[b - 1];
        if (ps * 2 <= ds) {
            ok = mid;
        } else {
            ng = mid;
        }
    }

    // ちょっと手前で切った場合の値
    pair<ll, ll> former = make_pair(sum[ok] - sum[b - 1], sum[e] - sum[ok]);

    // ちょっと後ろで切った場合の値
    pair<ll, ll> later = make_pair(sum[ok + 1] - sum[b - 1], sum[e] - sum[ok + 1]);

    // より差の小さい方を選ぶ
    if (abs(former.first - former.second) < abs(later.first - later.second)) {
        return former;
    } else {
        return later;
    }
}

// Aを[0, itr]と(itr, N)で切ったときの解を返す
ll cut(ll itr) {
    pair<ll, ll> res[2] = {divide(1, itr), divide(itr + 1, N)};

    ll elem[4];
    for (ll i = 0; i < 2; ++i) {
        elem[i * 2] = res[i].first;
        elem[i * 2 + 1] = res[i].second;
    }

    sort(elem, elem + 4);
    return elem[3] - elem[0];
}

int main() {
    cin >> N;
    sum[0] = 0;
    for (ll i = 1; i <= N; ++i) {
        cin >> A[i];
        sum[i] = sum[i - 1] + A[i];
    }

    ll ans = sum[N];
    for (ll i = 2; i < N; ++i) {
        ans = min(ans, cut(i));
    }

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


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
int main(){
	double n,a,b,c,d;
	cin>>n>>a>>b>>c>>d;
	int x=((((n/a)*1000)+999)/1000);
	int  y=((((n/c)*1000)+999)/1000);
	int ans=min(x*b,y*d);
	cout<<ans<<endl;
	//cout<<x<<endl;
	//cout<<y<<endl;
}


Measured memory_bytes: 3212
#include <stdio.h>
int main(void) {
	int A, B, C;
	scanf("%d %d %d", &A, &B, &C);

	if(A==B)printf("%d\n", C);
	else if(A==C) printf("%d\n", B);
	else printf("%d\n", A);
	return 0;
}

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

const ll INF = 1LL << 62;
const double PI = acos(-1);
const double eps = 1e-10;

int main() {
  ll h, w, ch, cw, dh, dw;
  cin >> h >> w >> ch >> cw >> dh >> dw;
  ch--, cw--, dh--, dw--;
  vector<string> s(h);
  rep(i, h) cin >> s[i];
  vector<vector<ll>> d(h, vector<ll>(w, INF));

  auto is_range = [&](ll x, ll y) {
    return 0 <= x && x < h && 0 <= y && y < w;
  };

  deque<P> q;
  q.push_back(P(ch, cw));
  d[ch][cw] = 0;
  while (!q.empty()) {
    ll x = q.front().first, y = q.front().second;
    q.pop_front();
    for (ll i = -2; i <= 2; i++) {
      for (ll j = -2; j <= 2; j++) {
        ll nx = x + i, ny = y + j;
        if (!is_range(nx, ny)) continue;
        if (nx == x && ny == y) continue;
        if (s[nx][ny] == '#') continue;
        if (d[nx][ny] <= d[x][y]) continue;

        if (abs(i) + abs(j) <= 1) {
          d[nx][ny] = d[x][y];
          q.push_front(P(nx, ny));
        } else if (d[nx][ny] == INF) {
          d[nx][ny] = d[x][y] + 1;
          q.push_back(P(nx, ny));
        }
      }
    }
  }
  cout << (d[dh][dw] != INF ? d[dh][dw] : -1) << endl;
  return 0;
}


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int[] num = Array.ConvertAll(str, new Converter<string, int>(s=>int.Parse(s)));

            int x = (num[0] >= num[1] ? num[0] : num[1]);
            int y = (num[0] >= num[1] ? num[1] : num[0]);
            
            while(x%y!=0)
            {
                int tem = x % y;
                x = (y>=tem?y:tem);
                y = (y>=tem?tem:y);
            }

            Console.WriteLine(y);

        } 
    }
}

Measured memory_bytes: 9048
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); \
					  cerr << "\n\n" << "Time elapsed: " << \
					  (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; \
					  return 0
#define ll long long int
#define ull unsigned long long int
#define db long double
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound 
#define pii pair<int , int>
#define pdd pair<db , db>
#define pll pair<ll , ll>
#define vpl vector<pll >
#define vll vector<ll >
#define mod 1000000007
#define inf 100000000000000007
#define eps 0.000001
#define stp fixed<<setprecision(20)
#define endl '\n'

int main()
{
	fastio;
	#ifdef APNA_IO
		start_routine();
        freopen("input.txt", "rt", stdin);
        freopen("output.txt", "wt", stdout);
    #endif

	ll n,a,b;cin>>n>>a>>b;
	cout<<min(a,b)<<" ";
	ll w=n-a-b;
	if(w<0)
		cout<<-w;
	else
		cout<<0;

	#ifdef APNA_IO
		end_routine();
    #endif
}

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

int cnt_digits(ll N){ 
  int digits=0;
  while(N>0){
    N/=10;
    digits++;
  }
  return digits;
}
                     
int main(){
  ll N;
  cin >> N;
  int ans=cnt_digits(N);
  for(ll A=1LL;A*A<=N;++A){
    if(N%A!=0) continue;
    const ll B=N/A;
    const int cur=max(cnt_digits(A),cnt_digits(B));
    if(ans>cur){
      ans=cur;
    } 
  }
  cout << ans << endl;
}

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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int a,b;string s;cin>>a>>b>>s;
  bool ok=true;
  for(int i=0;i<a;i++){
    if('0'<=s[i]&&s[i]<='9'){}else{ok=false;}
  }
  if(s[a]!='-')ok=false;
  for(int i=0;i<b;i++){
    if('0'<=s[a+i+1]&&s[a+i+1]<='9'){}else{ok=false;}
  }
  if(ok)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,ll> P;
  
static const double EPS = 1e-8;
static const ll MOD = 1000000007;

int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};

P expr(int pos,const string& str);
P term(int pos,const string& str);
P number(int pos,const string& str);

P expr(int pos,const string& str){
  P p1 = term(pos,str);
  pos = p1.first;

  while(pos + 2 < str.size() 
        && str[pos] == '>'
        && str[pos+1] == '>'
        && (isdigit(str[pos+2]) || str[pos+2] == 'S')){
    while(str[pos] == '>') pos++; //for '>'
    P p2 = term(pos,str);
    p1.second >>= min(p2.second,63LL);
    pos = p2.first;
  }
  return P(pos,p1.second);
}

P term(int pos,const string& str){
  if(str[pos] == 'S'){
    pos+=2; // for "S<"
    P p1 = expr(pos,str);
    pos = p1.first;
    pos++; // for ">"
    return P(pos,((p1.second % MOD) * (p1.second % MOD)) % MOD);
  }
  
  else{
    return number(pos,str);
  }
}

P number(int pos,const string& str){
  
  string tmp = "0";
  while(pos < str.size() && isdigit(str[pos])){
    tmp.push_back(str[pos]);
    pos++;
  }
  return P(pos,atol(tmp.c_str()));
}

int main(){
  string str;
  while(getline(cin,str)){
    if(str == "#") continue;

    string tmp = "";
    for(int i=0;i<str.size();i++){
      if(str[i] != ' '){
        tmp.push_back(str[i]);
      }
    }
    str = tmp;
    P p = expr(0,str);
    cout << p.second % MOD << endl;
  }
}

Measured memory_bytes: 6624
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));

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

	ll N;
	cin>>N;
	
	string ans="";
	while(N!=0){
		if(N%2!=0){
			N--;
			ans="1"+ans;
		}
		else ans="0"+ans;
		N/=-2;
	}
	if(ans=="")ans="0";
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
from bisect import bisect_left

while True:
    d = int(input())
    if not d:
        break
    n = int(input())
    m = int(input())
    stores = {0, d}
    for i in range(2, n + 1):
        stores.add(int(input()))
    sorted_stores = sorted(stores)

    total_dist = 0
    while m:
        k = int(input())
        i = bisect_left(sorted_stores, k)
        if i:
            l, r = sorted_stores[i - 1:i + 1]
            total_dist += min(k - l, r - k)
        m -= 1
    print(total_dist)

Measured memory_bytes: 17500
#include <bits/stdc++.h>
using namespace std;
 
int main(){
     
    int n;
    cin>>n;
    while(n--){
        double x1,y1,x2,y2,x3,y3,x4,y4;
        cin>>x1>>y1>>x2>>y2>>x3>>y3>>x4>>y4;
        if(fabs(x1-x2)<1e-9){
            if(fabs(x3-x4)<1e-9)cout<<"YES"<<endl;
            else cout<<"NO"<<endl;
        }
        else{
            double a=(y1-y2)/(x1-x2);
            double b=(y3-y4)/(x3-x4);
            if(fabs(a-b)<1e-9)cout<<"YES"<<endl;
            else cout<<"NO"<<endl;
        }
    }
     
    return 0;
}


Measured memory_bytes: 3224
#pragma region include
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <cstdio>
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define MOD 1000000007
#define INF 1000000000
#define LLINF 4000000000000000000
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#pragma endregion

//#define __DEBUG__
#ifdef  __DEBUG__
#define dump(x) cerr << #x << " = " << (x) << " [" << __LINE__ << ":" << __FUNCTION__ << "] " << endl;
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& v) {
    os << "{";
    REP(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
    os << "}";
    return os;
}
// pair出力
template<typename T, typename U>
ostream& operator << (ostream& os, pair<T, U>& p) {
    return os << "(" << p.first << ", " << p.second << ")";
}
// map出力
template<typename T, typename U>
ostream& operator << (ostream& os, map<T, U>& map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set 出力
template<typename T>
ostream& operator << (ostream& os, set<T>& set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#endif

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    ll r, D, x; cin >> r >> D >> x;
    for (int i = 0; i < 10; i++) {
        x = r * x - D;
        cout << x << endl;
    }
    getchar(); getchar();
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {

    int N;
    cin >> N;

    int t, x, y;
    int t_, x_, y_;
    int d;

    t_ = x_ = y_ = 0;
    for (int i = 0; i < N; i++) {
        cin >> t >> x >> y;
        d = abs(x - x_) + abs(y - y_);
        if (d <= t - t_ && d % 2 == (t - t_) % 2) {
            continue;
        } else {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
}

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

using namespace std;

int main() {
  
  int n;
  cin >> n;
  
  long long a1;
  cin >> a1;
  
  long long p1 = 0, h1 = a1;
  long long p2 = 0, h2 = a1;
  for (int i = 2; i <= n; ++i) {
    long long a;
    cin >> a;
    
    long long p = min(p1 + abs(h1 - a), p2 + abs(h2 - a));
    
    p1 = p2;
    h1 = h2;
    p2 = p;
    h2 = a;
  }
  
  cout << p2 << endl;
  
  return 0;
}

Measured memory_bytes: 256
K,N = map(int,input().split())
A = list(map(int,input().split()))
def solver(K,N,A):
    distance = [A[0] + (K - A[N-1])]
    for i in range(1,N):
        distance.append(abs(A[i]-A[i-1]))
    max_value = max(distance)
    return K - max_value
print(solver(K,N,A))

Measured memory_bytes: 100852
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())





int n;
int a[200000];
int b[200000];

int c[200000];

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

	cin >> n;
	rep(i, n)cin >> a[i];
	rep(i, n)cin >> b[i];
	int ans = 0;
	rep(i, 29) {
		int c1 = 0;
		rep(j, n) {
			c[j] = a[j] & ((1 << i + 1) - 1);
		}
		sort(c, c + n);
		int x = 0;
		rep(j,n) {
			int cnt = 0;
			int v = b[j] & ((1 << i + 1) - 1);
			cnt += lower_bound(c, c + n, (1 << i + 1) - v) - lower_bound(c, c + n, (1 << i) - v);
			cnt += lower_bound(c, c + n, (1 << i + 2) - v) - lower_bound(c, c + n, (1 << i | 1 << i + 1) - v);
			x ^= cnt & 1;
		}
		ans |= x << i;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 2688
# 解説したb→cを先に計算、その後累積和を取る解法
import bisect
n=int(input())
# 面倒なので最初にソートしちゃいましょう。
a=sorted(list(map(int,input().split())))
b=sorted(list(map(int,input().split())))
c=sorted(list(map(int,input().split())))

# 各bについてcで使えるのが何種類存在するか
cnum=[0 for i in range(n)]
for i in range(n):
    cnum[i] = len(c) - bisect.bisect_right(c,b[i])
# cnumの累積和
accum=[0 for i in range(n+1)]
for i in reversed(range(n)):
    accum[i]=accum[i+1]+cnum[i]
# 各a[i]について、使えるb,cの組み合わせの通り数を答えに加算していく
ret=0
for i in range(n):
    idx=bisect.bisect_right(b,a[i])
    ret+=accum[idx]
print(ret)

Measured memory_bytes: 25544
class Bubblesort():
    def __init__(self,x,n):
        self.C = x
        self.n = n
    def sorting(self):
        for i in range(self.n):
            for j in range(self.n - 1 , i , -1):
                if int(self.C[j][1]) < int(self.C[j - 1][1]):
                    self.C[j], self.C[j - 1] = self.C[j - 1], self.C[j]
        return self.C
    
    def check(self, xx):
        return CheckStable(self.C, xx)

class Selectionsort():
    def __init__(self, x, n):
        self.C = x
        self.n = n
    def sorting(self):
        for i in range(0, self.n):
            minj = i
            for j in range(i+1, self.n):
                if int(self.C[j][1])  < int(self.C[minj][1]):
                    minj = j
            self.C[i], self.C[minj] = self.C[minj], self.C[i]
        return self.C
    
    def check(self, xx):
        return CheckStable(self.C, xx)
    
def CheckStable(x1, xx2):
    ch1 = []
    for i in range(n - 1):
        if x1[i][1] == x1[i + 1][1]:
            ch1.append(x1[i])
            if i + 1 == n - 1:
                ch1.append(x1[i + 1])
        elif x1[i - 1][1] == x1[i][1]:
            ch1.append(x1[i])
    
    ch2 = []
    x2 = xx2
    for i in ch1:
        for j in range(len(x2)):
            if i[1] == x2[j][1]:
                ch2.append(x2[j])
                x2.pop(j)
                break

    if ch1 == ch2:
        return ('Stable')
    else:
        return ('Not stable')

n = int(input())
x = input().split()
xx =x[:]
y =x[:]
yy =x[:]

a = Bubblesort(x, n)
b = Selectionsort(y, n)
print(' '.join(a.sorting()))
print(a.check(xx))
print(' '.join(b.sorting()))
print(b.check(yy))


Measured memory_bytes: 5616
#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
#define FF(i,a,b)           for(int i=a;i<b;i++)
#define BF(i,a,b)           for(int i=a;i>=b;i--)
#define vi                  vector<int>
#define MAP                 map<int,int>
#define pb                  push_back
#define MP                  make_pair
#define F                   first
#define S                   second
#define pi                  pair<int,int>
#define all(v)              v.begin(),v.end()
#define PIE                 3.1415926535897932384626433832795
#define FastIO              ios::sync_with_stdio(0); cin.tie(0);cout.tie(0)
//#define ordered_set         tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
/*

    order_of_key (k) : Number of items strictly smaller than k .
    find_by_order(k) : K-th element in a set (counting from zero).

*/
/**************************************************************************************/
                       /*Global Variables*/
const int mod = 1e9+7;
const int N = 2e5+10;
const int inf = 3e18;

/**************************************************************************************/
template <typename A>istream& operator>>(istream& input,vector<A>& x) {for(auto& i:x)input>>i;return input;}
template<typename A>ostream& operator<<(ostream& output,vector<A>& x) {for(auto& i:x)output<<i<<' ';return output;}
int add(int a, int b){return (a%mod + b%mod + mod)%mod;}
int sub(int a, int b){return (a%mod - b%mod + mod)%mod;}
int mul(int a, int b){return ((a%mod)*(b%mod) + mod)%mod;}
int Power(int a,int b)
{
    int res=1;
    while(b)
    {
        if(b&1)res*=a;
        a*=a;
        b>>=1;
    }
    return res;
}
signed main()
{
    FastIO;
    int T=1;
    //cin>>T;
    while(T--)
    {
        int n;
        cin>>n;
        vi a(n);
        cin>>a;
        vi dp(n);
        
        dp[0]=0;
        dp[1]=abs(a[1]-a[0]);
        
        for( int i=2;i<n;i++)
        {
            dp[i]=dp[i-1]+abs(a[i-1]-a[i]);
            dp[i]=min(dp[i],dp[i-2]+abs(a[i-2]-a[i]));
        }
        cout<<dp[n-1]<<"\n";
    }

}
/*
|| Do what you can with all you have,wherever you are. ||

|| Knowing is not enough, we must apply. Wishing is not enough, we must do. ||

|| A goal is a dream with deadline. ||

|| Whether you think you can or you think you can't, you're right. ||

|| A year from now you may wish you had started today ||
*/



Measured memory_bytes: 1792
i = int(input())
list_a = list(map(int, input().split()))
dict_ans = {}
for number in list_a:
    try:
        dict_ans[number] += 1
    except KeyError:
        dict_ans[number] = 1
if i % 2 == 0:
    dict_prop = {key:2 for key in [j for j in range(i) if j % 2 == 1]}
    if dict_prop == dict_ans:
        ans = 2 ** (i//2)
    else:
        ans = 0
else:
    dict_prop = {key:2 for key in [j for j in range(i) if j % 2 == 0]}
    dict_prop.update({0:1})
    if dict_prop == dict_ans:
        ans = 2 ** (i // 2)
    else:
        ans = 0
print(ans % (10 **9 + 7))


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

int main(){
    int K,N;
    scanf("%d",&K);
    scanf("%d",&N);
    int a[K];
    int i;
    for(i=0;i<N;i++){
       scanf("%d",&a[i]);
    }
    int min= a[N-1]-a[0];
    for(int j=1;j<N;j++){
        if((K-a[j]+a[j-1])<min){
            min = (K-a[j]+a[j-1]);
        }
    }
    for(int k=0;k<N-1;k++){
        if((K-a[k+1]+a[k])<min){
            min = (K-a[k+1]+a[k]);
        }
    }
    printf("%d",min);

    return 0;

}

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

int main()
{
 int N;cin>>N;
 vector<long long int> A(N);

 for(int i=0;i<N;i++)
 {
  cin>>A[i];
 }
  sort(A.begin(),A.end());
  bool judge_St=true;int count=0;
   for(int i=1;i<N;i++)
   {
    if(A[i]==A[i-1])
    {
    judge_St=!judge_St;
    }
    if(A[i]!=A[i-1])
    {
     if(judge_St==true){count++; /*cout<<i<<endl;*/}
      judge_St=true;
    }
     //cout<<judge_St<<endl;
   }
  cout<<count+judge_St<<endl;
}

Measured memory_bytes: 1024
open System


[<EntryPoint>]
let main argv =
    let inputArray = stdin.ReadLine().Split(' ') |> Array.map int

    let combination = [(0,1);(0,2);(1,2)]

    let answer = combination |> List.map(fun (x, y) -> inputArray.[x] + inputArray.[y]) |> List.min

    printfn "%d" answer

    0 // return an integer exit code


Measured memory_bytes: 14044
h,w  = map(int,input().split())
if h== 1 and w == 1:
    ans = 0
    
elif h == 1 or w == 1:
    ans = 2
    
else:
    ans = 2*(h-2)+2*(w-2)+4
ans = (h*w) - ans
print(ans)
    


    

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#include <unistd.h>
#define ll long long
#define inf 1000000007
#define inf16 0x3f3f3f3f
#define INF 1000000000000000007LL
#define VI vector<int>
#define VPII vector<pair<int, int> >
#define VLL vector<ll>
#define PII pair<int, int>
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define endl '\n'
#define ALL(c) (c).begin(), (c).end()
using namespace std;

#define int ll

int h, w, n, k, ans;

int pot[50*50];

int query(int y1, int y2, int x1, int x2)
{
	cout << "? " << y1 << " " << x1 << " " << y2 << " " << x2 << endl;
	int ans;
	cin >> ans;
	return ans;
}

void solve(int y1, int y2, int x1, int x2, int cnt, int split)
{
	if(cnt==0)
		return;

	if(cnt==(y2-y1+1)*(x2-x1+1))
	{
		for(int i = y1; i <= y2; ++i)
		{
			for(int j = x1; j <= x2; ++j)
			{
				ans += pot[i*w+j];
				ans %= k;
			}
		}

		return;
	}

	if(y1!=y2)//split)
	{
		int m = (y1+y2)/2;
		int h = query(y1, m, x1, x2);
		solve(y1, m, x1, x2, h, split^1);
		solve(m+1, y2, x1, x2, cnt-h, split^1);
	}
	else
	{
		int m = (x1+x2)/2;
		int h = query(y1, y2, x1, m);
		solve(y1, y2, x1, m, h, split^1);
		solve(y1, y2, m+1, x2, cnt-h, split^1);
	}
}

int32_t main()
{
	cin >> h >> w >> n >> k;

	pot[0] = 1;

	for(int i = 1; i < 50*50; ++i)
	{
		pot[i] = pot[i-1]*2%k;
	}

	for(int j = 0; j < w; j += 4)
	{
		for(int i = 0; i < h; i += 4)
		{
			solve(i, min(i+3, h-1), j, min(j+3, w-1), query(i, min(i+3, h-1), j, min(j+3, w-1)), 1);
		}
	}

	/*for(int i = 0; i < h; i += 5)
	{
		for(int j = 0; j < w; j += 5)
		{
			solve(i, i+4, j, j+4, query(i, i+4, j, j+4), 1);
		}
	}*/

	//solve(0, h-1, 0, w-1, n, 1);

	cout << "! " << ans << endl;
}

Measured memory_bytes: 720
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    X = [list(map(int,input().split())) for _ in range(N)]

    X.sort(key=lambda X:X[1])
    time = 0
    for i in range(N):
        time += X[i][0]
        if time > X[i][1]:
            print("No")
            exit()

    print("Yes")  

if __name__ == "__main__":
    main()

Measured memory_bytes: 53672