akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <iomanip> 

using ll = long long;
using ull = unsigned long long;
using namespace std;

#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;(i) < ((int)(n));++(i))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

constexpr int INF = 1e9+7;
constexpr ll INFL = 9*1e18;

constexpr int dx[4] = { 1, 0, -1, 0 };
constexpr int dy[4] = { 0, 1, 0, -1 };

// constexpr int dx[8] = {1, 1, 0,-1,-1,-1, 0, 1};
// constexpr int dy[8] = {0, 1, 1, 1, 0,-1,-1,-1};

int inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline T SUM(vector<T> vec){return accumulate(all(vec),(T)0);} // vectorの中身を全部足す
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T>inline void print(T&& x){cout<<setprecision(32)<<x<<endl;}


const ll COM_MAX = (ll)(2000); // combinationの最大値
vector<ll> fac(COM_MAX),finv(COM_MAX),inv(COM_MAX);


// TODO: write
int main() {
  int n;cin>>n;
  vector<pair<ll,ll>> a(n);rep(i,n)cin>>a[i].fi>>a[i].se;
  ll ans = 0;
  sort(all(a),[&](auto a1,auto a2){
    return a1.fi + a1.se > a2.fi + a2.se;
  });
  chmax(ans,abs(a[0].fi - a[n-1].fi) + abs(a[0].se - a[n-1].se));
  sort(all(a),[&](auto a1,auto a2){
    return a1.fi > a2.fi;
  });
  chmax(ans,abs(a[0].fi - a[n-1].fi) + abs(a[0].se - a[n-1].se));
  sort(all(a),[&](auto a1,auto a2){
    return a1.se > a2.se;
  });
  chmax(ans,abs(a[0].fi - a[n-1].fi) + abs(a[0].se - a[n-1].se));
  sort(all(a),[&](auto a1,auto a2){
    return a1.fi - a1.se > a2.fi - a2.se;
  });
  chmax(ans,abs(a[0].fi - a[n-1].fi) + abs(a[0].se - a[n-1].se));
  print(ans);
  return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i];
    if(i == SZ(s)-1) {
      cout << endl;
    } else {
      cout << " ";
    }
  }
}

ll hextobin(string s) {
  ll ans = 0;
  ll now = 1;
  RREP(i, SZ(s)-1) {
    switch(s[i]) {
      case 'a':
      case 'b':
      case 'c':
      case 'd':
      case 'e':
        ans += ((ll)(s[i] - 'a') + 10) * now;
        break;
      default:
        ans += (ll)(s[i] - '0') * now;
        break;
    }
    now *= 16;
  }
  return ans;
}

string bintohex(ll a) {
  if(a == 0) return "0";
  string ans = "";
  vector<char> tmp = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
  while(a > 0) {
    ans += tmp[a % 16];
    a /= 16;
  }
  reverse(ALL(ans));
  return ans;
}

int digit(ll a) {
  int ans = 0;
  while(a > 0) {
    ans++;
    a /= 2;
  }
  return ans;
}

int main () {
  cin.tie(0);
  cout << fixed << setprecision(10);
  int s; cin >> s;
  while(s > 0) {
    int n = 9;

    vll a(n);
    REP(i, n) {
      cin >> hex >> a[i];
    }
    // printv(a);

    ll res = 0;
    for(int i=0;i<32;i++) {
      ll sum = 0;
      for(int j=0;j<8;j++) {
        sum += a[j] ^ res;
      }
      ll bit = (1ll<<i);
      if((sum&bit)!=(a[8]&bit)) {
        res |= bit;
      }
    }
    //printv(a);
    cout << hex << res << endl;

    s--;
  }
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(a) (a).begin(), (a).end()
const ll mod = 998244353;

ll d[100000] = {};

int main() {
  ll n;
  ll ans = 1;
  cin >> n;
  rep(i, n) {
    ll x;
    cin >> x;
    d[x]++;
    if (i == 0 && x != 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  if (d[0] != 1) {
    cout << 0 << endl;
    return 0;
  }
  repi(i, 1, n) {
    ll c = d[i];
    while (c > 0) {
      ans *= d[i - 1];
      ans %= mod;
      c--;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
def debug(*args):
    import sys
    print(*args, file=sys.stderr)

def solve(N, BA):
    BA = sorted(BA)

    t = 0
    for b, a in BA:
        t += a
        if t > b:
            return "No"
    return "Yes"



def main():
    N = int(input())
    BA = []
    for _ in range(N):
        A, B = [int(x) for x in input().split()]
        BA.append(tuple([B, A]))

    print(solve(N, BA))

main()



Measured memory_bytes: 31052
/*
    Author : Nishant Gupta 2.0
*/
#include<bits/stdc++.h>
using namespace std;

#define LL long long int
#define getcx getchar_unlocked
#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define MAX 100005
#define LOG_MAX 20
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL (LL(1e18))
#define chk(a) cerr << endl << #a << " : " << a << endl
#define chk2(a,b) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << endl
#define chk3(a,b,c) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << endl
#define chk4(a,b,c,d) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << "\t" << #d << " : " << d << endl
#define rep(i, a, n) for(i=a;i<n;i++)
#define rev(i, a, n) for(i=a;i>=n;i--)
#define in(x) scanf("%d", &x)
#define inl(x) scanf("%lld", &x)
#define in2(x, y) scanf("%d %d", &x, &y)
#define inl2(x, y) scanf("%lld %lld", &x, &y)
#define MSV(A,a) memset(A, a, sizeof(A))
#define rep_itr(itr, c) for(itr = (c).begin(); itr != (c).end(); itr++)
#define finish(x) {cout<<x<<'\n'; return;}
typedef pair<int, int> pi;
typedef pair<LL, LL> pl;
const char en = '\n';

void solve() {
	int l, r, n;
	in2(l, r);in(n);
	
	int cnt = 0;
	for(int i=l;i<=r;i++) {
		if(i % n == 0) cnt++;
	}
	cout<<cnt<<en;
}

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


Measured memory_bytes: 3656
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX;
#define INFL LLONG_MAX;
typedef long long ll;
using namespace std;

int main(){
  string s; cin >> s;
  vector<ll> a(s.size()+1,0);
  vector<ll> b(s.size()+1,0);

  for(int i=1;i<s.size()+1;i++){
    if(s[i-1]=='<') a.at(i) = a.at(i-1) + 1;
  }

  for(int i=s.size();i>0;i--){
    if(s[i-1]=='>') b.at(i-1) = b.at(i) + 1;
  }

  ll ans = 0;
  rep(i,s.size()+1){
    ans += max(a.at(i),b.at(i));
  }


  cout << ans <<endl;
}

Measured memory_bytes: 8708
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define SZ(i) int(i.size())
#ifdef tmd
#define IOS()
#define debug(...) fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);_do(__VA_ARGS__);
template<typename T> void _do(T &&x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S &&...y){cerr<<x<<", ";_do(y...);}
#else
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define debug(...)
#endif

const int MAXN = 602;
const ll MOD = 1000000007;

struct Edge {
    int des, nxt;
} edge[MAXN*MAXN];
int head[MAXN], ecnt;

int n, m;
double dp[MAXN];

double ans;
void calc (int ban) {
    for (int i=n-1; i>=1; i--) {
        dp[i] = 0;
        int cnt = 0;
        for (int id=head[i]; id!=-1; id=edge[id].nxt) {
            if (id == ban) {
                continue;
            }
            dp[i] += dp[edge[id].des] + 1;
            cnt++;
        }
        dp[i] /= cnt;
    }
    if (dp[1] != 0) {
        ans = min(ans, dp[1]);
    }
}
/*********************GoodLuck***********************/
int main () {
    IOS();
    cin >> n >> m;

    memset(head, -1, sizeof(head));
    REP (i, m) {
        int f, t;
        cin >> f >> t;
        edge[ecnt++] = {t, head[f]};
        head[f] = ecnt - 1;
    }

    ans = n + 3;
    calc(-1);

    vector<int> ban;
    REP1 (i, n-1) {
        int mx = -1;
        double val = -1;
        for (int id=head[i]; id!=-1; id=edge[id].nxt) {
            if (dp[edge[id].des] > val) {
                mx = id;
                val = dp[edge[id].des];
            }
        }
        ban.emplace_back(mx);
    }

    for (auto b : ban) {
        calc(b);
    }

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


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

using P = pair<int,int>;
using P3 = pair<P, int>;
using ll = long long int;
constexpr int INF = 1<<30;

vector<vector<int> > g;

void bfs(int s, vector<int> &d){
    fill(d.begin(), d.end(), INF);
    d[s] = 0;
    queue<int> que;
    que.push(s);
    while(!que.empty()){
        int now = que.front();
        que.pop();
        for(auto nxt : g[now]){
            if(d[nxt] > d[now] + 1){
                d[nxt] = d[now] + 1;
                que.push(nxt);
            }
        }
    }
}

int main() {
    ll n, u, v;
    cin >> n >> u >> v;
    u--; v--;
    g.resize(n);
    for(int i=0;i<n-1;i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vector<int> d1(n), d2(n);
    bfs(u, d1);
    bfs(v, d2);
    int dmax = 0;
    for(int i=0;i<n;i++){
        if(d1[i] < d2[i] && int(g[i].size())==1){
            dmax = max(dmax, d2[i]);
        }
    }
    int ans = dmax-1;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6656
#include<cstdio>
using namespace std;
int m,n;
int main(){
    scanf("%d%d",&n,&m);
    int l1=1,r1=l1+m,l2=r1+1,r2=l2+m-1;
    while(true){
        if(l1>=r1) break;
        printf("%d %d\n",l1,r1);
        if(l2>=r2) break;
        printf("%d %d\n",l2,r2);
        l1++,l2++;
        r1--,r2--;
    }
    return 0;
}


Measured memory_bytes: 1708
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
  int n;
  cin >> n;
  if(n < 105) cout << 0 << endl;
  else if(n < 135) cout << 1 << endl;
  else if(n < 165) cout << 2 << endl;
  else if(n < 189) cout << 3 << endl;
  else if(n < 195) cout << 4 << endl;
  else cout << 5 << endl;
}

Measured memory_bytes: 256
#include <iostream>

int main(){
    int n;
    std::cin >> n;
    std::string s;
    std::cin >> s;

    int counter = 0;
    for(int i=0; i<n; i++){
        if(s[i]!=s[i+1]){
            counter += 1;
        }
    }
    std::cout << counter << std::endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i >= b; i--)
#define fore(i, a) for (auto &i : a)
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

int main() {
  int k;
  string s;
  cin >> k;
  cin >> s;
  if ((int)s.length() > k){
    cout << s.substr(0,k) << "..." << endl;
  } else {
    cout << s << endl;
  }
}


Measured memory_bytes: 3628
#include"bits/stdc++.h"
using namespace std;


int main(){
	vector<int> vec;
	int check;
	for(int i = 0; i < 5; i++){
		int a;
		cin >> a;
		vec.push_back(a);
	}
	cin >> check;
	if((vec[4] - vec[0]) <= check){
		cout << "Yay!" << endl;
	}else{
		cout << ":(" << endl;
	}
	return 0;
}


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

int main(){
   int n, k;
   cin>>n>>k;
   vector<int> p(n), c(n);
   rep(i, n) {cin>>p[i]; p[i]--;}
   rep(i, n) cin>>c[i];

   ll mx=LLONG_MIN;
   rep(s, n){
      vector<ll> mm(n, LLONG_MIN);
      vector<int> mmi(n);
      int cur=s;
      ll sum=0;
      bool red=false;
      rep(i, k){
         cur=p[cur];
         sum+=c[cur];
         if(!red && mm[cur]!=LLONG_MIN){
            int len=mmi[cur]-i;
            ll ct=mm[cur]-sum;
            int kai=(k-1-i)/len;
            sum+=ct*kai;
            i+=len*kai;
            red=true;
         }
         mm[cur]=sum;
         mmi[cur]=i;

         mx=max(mx, sum);
      }
   }

   cout<<mx<<endl;
   return 0;
}


Measured memory_bytes: 3736
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cout<<#x<<" "<<x<<"\n";
#define lli long long int
long long int mod= 1000000007,modd=998244353;
int32_t main()
{
   ios_base::sync_with_stdio(0);
   cin.tie(0);  cout.tie(0);
   lli i,n,ans=0;
   cin>>n;
   lli a[n+1];
   for(i=1;i<=n;i++)
    {   cin>>a[i];
        if(i%2!=0 && a[i]%2!=0)
            ans++;
    }
   cout<<ans<<"\n";
   return 0;
}//main


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

int INF = 100000;

int main() {
  int n, t, a;
  cin >> n >> t >> a;
  double d = INF;
  int c = 0;
  for (int i = 0; i < n; i++) {
    double x;
    int h;
    cin >> h;
    x = (a - (t - h * 0.006)) * (a - (t - h * 0.006));
    if (x < d){
      d = x;
      c = i;
    }
  }
  cout << c + 1 << endl;
}

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

using namespace std;

int main(){

    int N;
    cin >> N;
    std::vector<int> d(N);
    for(int i = 0; i < N; i++) cin >> d.at(i);

    int ans = 0;
    for(int i = 0; i < N; i++) {
        for(int j = i + 1; j < N; j++) {
            ans += d.at(i) * d.at(j);
        }
    }

    cout << ans << endl;

    return 0;
}


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

// first: weight, second: value
int64_t getMaxValue(const std::vector<std::pair<int, int64_t>> &goods,
                    const int max_weight) {
  std::vector<std::vector<int64_t>> dp(goods.size());
  for (int i = 0; i < static_cast<int>(dp.size()); ++i) {
    dp[i].resize(max_weight + 1, 0);
  }
  for (int w = 0; w <= max_weight; ++w) {
    if (w >= goods[0].first) {
      dp[0][w] = goods[0].second;
    }
  }
  for (int i = 1; i < static_cast<int>(goods.size()); ++i) {
    const auto &current = goods[i];
    for (int w = 0; w <= max_weight; ++w) {
      if (w < current.first) {
        dp[i][w] = dp[i - 1][w];
      } else {
        dp[i][w] = std::max(dp[i - 1][w],
                            dp[i - 1][w - current.first] + current.second);
      }
    }
  }
  return dp.back().back();
}

int main() {
  int n, w;
  std::cin >> n >> w;
  std::vector<std::pair<int, int64_t>> goods(n);
  for (int i = 0; i < n; ++i) {
    std::cin >> goods[i].first >> goods[i].second;
  }
  std::cout << getMaxValue(goods, w) << std::endl;
  return 0;
}


Measured memory_bytes: 78592
from collections import Counter
N, M = map(int, input().split())

# Union-Find
parent = [i for i in range(N)]
rank = [1] * N
def get_root(node):
  global parent
  if parent[node] == node:
    return node
  root = get_root(parent[node])
  parent[node] = root
  return root

def union(a, b):
  global parent
  global rank
  root_a = get_root(a)
  rank_a = rank[root_a]
  root_b = get_root(b)
  rank_b = rank[root_b]
  if root_a == root_b:
    return
  if rank_a < rank_b:
    parent[root_a] = root_b
  else:
    parent[root_b] = root_a
    if rank_a == rank_b:
      rank[root_a] += 1

for _ in range(M):
    a, b = map(int, input().split())
    union(a-1, b-1)

for i in range(N):
    get_root(i)

ct = Counter(parent)
print(ct.most_common()[0][1])


Measured memory_bytes: 44684
#include <bits/stdc++.h>
#define LEN 100005
using namespace std;

typedef struct pp {
  char name[100];
  int t;
} P;

P Q[LEN];
int head, tail, n;

void enqueue(P x) {
  Q[tail] = x;
  tail = (tail + 1) % LEN;
}

P dequeue() {
  P x = Q[head];
  head = (head + 1) % LEN;
  return x;
}

int min(int a, int b) { return a < b ? a : b; }

int main() {
  int elaps = 0, c;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);

  for (i = 1; i <= n; i++) {
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  head = 1;
  tail = n + 1;

  while (head != tail) {
    u = dequeue();
    c = min(q, u.t);
    u.t -= c;
    elaps += c;
    if (u.t > 0)
      enqueue(u);
    else {
      printf("%s %d\n", u.name, elaps);
    }
  }

  return 0;
}


Measured memory_bytes: 13300
import math
a,b,h,m = (float(x) for x in input().split())

s = 2.0*math.pi*(60.0*h+m)/720.0
t = 2.0*math.pi*m/60.0
print(math.sqrt((a*math.cos(s)-b*math.cos(t))**2+(a*math.sin(s)-b*math.sin(t))**2))


Measured memory_bytes: 9436
#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 main() {
    string S;
    cin>>S;
    rep(i,S.size()-8){
        cout<<S.at(i);
    }
return 0;}
/*
g++ code.cpp
./a.out
*/

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextLong()

    if (n % 2L == 1L || n == 0L) {
        println(0)
        return
    }

    var twoCount = 0L
    var fiveCount = 0L
    var i = 2L
    while (i <= n) {
        twoCount += n / i
        i *= 2L
    }

    i = 10L
    while (i <= n) {
        fiveCount += n / i
        i *= 5L
    }

    println(Math.min(twoCount, fiveCount))
}


Measured memory_bytes: 31260
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
using namespace std;
#define INF 100000000

typedef long long ll;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

class P {
public:
    int cost;
    vector<int> v, pos, gap;

    P() {}
    P(int cost, vector<int> v, vector<int> pos, vector<int> gap) : cost(cost), v(v), pos(pos), gap(gap) {}
    bool goal(vector<int> &v);
};

bool goal(vector<int> &v) {
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 7; j++) {
            int idx = i*8+j;
            if (v[idx] / 10 != i+1 || v[idx] % 10 != j+1) return false;
        }
    }
    return true;
}

int bfs(P start) {
    queue<P> open;
    set<vector<int> > closed;
    open.push(start);
    closed.insert(start.v);

    while (!open.empty()) {
        P p = open.front(); open.pop();

        for (int i = 0; i < 4; i++) {
            vector<int> nv = p.v;
            vector<int> npos = p.pos;
            vector<int> ngap = p.gap;
            int idx = ngap[i];
            int val = nv[idx-1] + 1;
            if (npos[val] == 0) continue;

            nv[idx] = val;
            nv[npos[val]] = 0;
            ngap[i] = npos[val];
            npos[val] = idx;

            if (closed.find(nv) != closed.end()) continue;
            closed.insert(nv);

            if (goal(nv)) {
                return p.cost+1;
            }
            open.push(P(p.cost+1, nv, npos, ngap));
        }
    }
    return -1;
}

int main() {
    int T;
    cin >> T;
    while (T--) {
        vector<int> v(32);
        vector<int> pos(50);
        vector<int> gap;

        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 7; j++) {
                int idx = i*8+j+1;
                cin >> v[idx];
                if (v[idx] % 10 == 1) {
                    int row = v[idx] / 10 - 1;
                    v[row*8] = v[idx];
                    v[idx] = 0;
                    gap.push_back(idx);
                } else {
                    pos[v[idx]] = idx;
                }
            }
        }
        printf("%d\n", goal(v) ? 0 : bfs(P(0, v, pos, gap)));
    }
}

Measured memory_bytes: 14924
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/
 
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x
 
using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;
 
const ll MODBASE = 1000000007LL;
const int MAXN = 110;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int n, a[MAXN];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n;
    FOR(i,1,n) cin >> a[i];
    sort(a+1, a+n+1);
    int res = 1000000000;
    FOR(x,1,100) {
        int now = 0;
        FOR(i,1,n) now += (x - a[i]) * (x - a[i]);
        res = min(res, now);
    }
    cout << res;
    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() {
  int n; cin >> n;
  int div;
  bool flag = false;

  for(int i=1; i<=9; i++){
    if(n%i==0){
      div = n/i;
      if(div<=9) flag = true;
    }
  }

  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
import numpy as np


N = int(input())
h = np.array(list(map(int, input().split())))
ans = 0
while np.sum(h) != 0:
    last_flg = 0
    water = np.zeros((N), dtype=np.int64)
    for i in range(N):
        # 値がまだある
        if h[i] != 0:
            water[i] = 1
        else:
            # 値がない
            if i == 0:
                # first number
                pass
            elif water[i-1] == 0:
                # 前の値もゼロ
                pass
            elif water[i-1] == 1:
                # 値の切れ目
                ans += 1
                h -= water
                break
        # last number
        if i == N-1:
            last_flg = 1

    if last_flg:
        ans += 1
        h -= water
print(ans)

Measured memory_bytes: 21640
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <queue>
#include <utility>
#include <cmath>
#include <iomanip>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;
typedef pair<int,int> P;

#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

int main()
{

    lint N;
    cin >> N;

    lint T[5];
    REP(i,5) cin >> T[i];


    lint min = pow(10,16);
    int min_num;

    REP(i,5){
    	if(T[i]<min){
    		min = T[i];
    		min_num = i;
    	}
    }


    lint time = 0;

    time+=min_num;

    time+=(N-1)/min+1;

    time+=4-min_num;



    cout << time << endl;

}


/*int main()
{

    int N;
    cin >> N;

    int T[5];
    REP(i,5) cin >> T[i];

    lint time = 0;
    bool con = true;

    int people[6]={0};
    people[0] = N;

    while(con){
    	//5-6 E
    	people[5] += min(T[4],people[4]);
    	people[4] -= min(T[4],people[4]);
    	people[4] += min(T[3],people[3]);
    	people[3] -= min(T[3],people[3]);
    	people[3] += min(T[2],people[2]);
    	people[2] -= min(T[2],people[2]);
    	people[2] += min(T[1],people[1]);
    	people[1] -= min(T[1],people[1]);
    	people[1] += min(T[0],people[0]);
    	people[0] -= min(T[0],people[0]);

    	time ++;
    	if(people[5]==N) con=false;

    }

    cout << time << endl;

}*/


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7/*998244353*/;
const ll INF = 1LL << 60;
ll mod_pow(ll, ll, ll); ll mod_fact(ll, ll); ll mod_inv(ll, ll); ll gcd(ll, ll); ll lcm(ll, ll);
//
int main(){
    string s;
    cin >> s;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == '?') s[i] = 'D';
    }
    cout << s;
}

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

int X;
int cnt[6] = {0};
bool ans = false;

void solve(int Y) {
    if (ans || Y < 0) return;

    if (Y == 0) {
        int total = 0;
        for (int i = 1; i < 6; i++)
            total += cnt[i] * (100 + i);
        ans = total <= X;
        return;
    }

    for (int i = 1; i < 6; i++) {
        cnt[i]++;
        solve(Y - i);
        cnt[i]--;
    }
}

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

    cin >> X;
    cnt[5] = X % 100 / 15 * 3;
    solve(X % 100 % 15);
    cout << ans << '\n';

    return 0;
}

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

using namespace std;

int main(){

	int N, L;
	string str;
	priority_queue < string > pq;
	string STR="";

	cin>>N>>L;

	for(int i=0; i<N; i++){
		cin>>str;
		pq.push(str);
	}


	while(!pq.empty()){
		STR=pq.top()+STR;
		pq.pop();
	}

	cout<<STR<<endl;

	return 0;
}

Measured memory_bytes: 256
search :: Int -> String -> String -> Int
search p s t
  | p < 0 = -1
  | res = p
  | otherwise = search (p - 1) s t
    where res = check $ zip t (drop p s)

check :: [(Char, Char)] -> Bool
check [] = True
check ((t, s):tss)
  | s == '?' = check tss
  | t == s = check tss
  | otherwise = False

solve :: Int -> String -> String -> String
solve p s t = res
  where replaced = take p s ++ t ++ drop (p + length t) s
        res = map (\c -> if c == '?' then 'a' else c) replaced

main :: IO ()
main = do
  s <- getLine
  t <- getLine
  let p = length s - length t
  let res = search p s t
  putStrLn $ if res >= 0
             then solve res s t
             else "UNRESTORABLE"

Measured memory_bytes: 508
from scipy.sparse.csgraph import shortest_path
N, M = map(int, input().split())
dic = [[0]*N for i in range(N)]
Els = []
for i in range(M):
  a, b, c = map(int, input().split())
  dic[a-1][b-1] = c
  dic[b-1][a-1] = c
  Els += [(a-1,b-1,c)]
d, p = shortest_path(dic, return_predecessors=True, method='D')

ans = 0
for a, b, c in Els:
  if p[a][b]!=a:
    ans += 1
print(ans)

Measured memory_bytes: 17244
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	A, B := sc.nextInt(), sc.nextInt()

	fmt.Fprintln(wtr, (A+B)%24)
	wtr.Flush()
}


Measured memory_bytes: 640
package main

import (
	"fmt"
)

func BeginerC(memo []int, from, to int) int {
	return memo[to-1] - memo[from-1]
}

func createMemo(src string, length int) []int {
	memo := make([]int, length)
	for i := 1; i < length; i++ {
		memo[i] = memo[i-1]
		if src[i-1] == 'A' && src[i] == 'C' {
			memo[i]++
		}
	}

	return memo
}

func main() {
	var (
		inputLength   int
		questionCount int
		input         string
	)

	fmt.Scan(&inputLength, &questionCount, &input)

	memo := createMemo(input, inputLength)

	for i := 0; i < questionCount; i++ {
		var from, to int
		fmt.Scan(&from, &to)

		fmt.Println(BeginerC(memo, from, to))
	}
}


Measured memory_bytes: 6144
#include <bits/stdc++.h>
using namespace std;
int main() 
{
  string S;
  int N;
  cin >>N>> S;
  for(int i = 0;i < S.size();i++)
  {
    S[i]+=N;
    if(S[i]>90)
    {
      S[i]-=26;
    }
  }
  cout << S;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>

using namespace std;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define reppe(i,a,b) for(int i = (int)(a) ; i <= (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)
#define repme(i,a,b) for(int i = (int)(a) ; i >= (int)(b) ; --i)

typedef long long ll;

long long GCD(long long a, long long b){if(b==0)return a;return GCD(b,a%b);}

vector< ll > divisor(ll n) {
  vector< ll > ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int main() {
    ll N; cin >> N;
    vector<ll> v = divisor(N);
    sort(v.begin(), v.end());

    ll res = N - 1;
    repp(i,0,v.size()) {
        ll A = v[i];
        ll B = N / v[i];
        res = min(res, A+B-2);
    }
    cout << res << endl;
}


Measured memory_bytes: 384
#include <stdio.h>
int main()
{
	double sum, c, h;
	int d;
	int n, e, i, t;
	double a[100];
	while (scanf("%d", &n) != EOF)
	{
		sum = 0;
		for (e = 0; e < n; e++)
		{
			scanf("%lf", &a[e]);
		}
		for (e = 0; e < n; e++)
		{
			for (i = 0; i < n - 1; i++)
			{
				if(a[i] < a[i + 1])
				{
					t = a[i + 1];
					a[i + 1] = a[i];
					a[i] = t;
				}
			}
		}
		sum = sum + (a[0] / 2.0);
		for (e = 1; e < n; e++)
		{
			sum = sum + a[e];
		}
		d = sum;
		c = sum;
		h = c - d;
		if (h == 0)
		{
			printf("%.0lf\n", sum);
		}
		else
			printf("%.1lf\n", sum);
	
	}

	return 0;
}

Measured memory_bytes: 128
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using P = pair<ll, ll>;

constexpr double PI = 3.14159265358979323846;
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

class EGolf {
public:

    void solve(istream& cin, ostream& cout) {
      SPEED;
      int k; cin >> k;
      int x, y; cin >> x >> y;

      int signx = 1;
      int signy = 1;
      if (x < 0) {
        signx = -1;
        x = -x;
      }
      if (y < 0) {
        signy = -1;
        y = -y;
      }

      bool swapped = false;
      if (x < y) {
        swap(x, y);
        swapped = true;
      }

      if (k%2==0 && (x+y)%2==1) {
        cout << -1 << endl;
        return;
      }

      vector<P> ans;
      if (x+y < k && (x+y)%2 == 1) {
        int s = (k+x-y)/2;
        ans.emplace_back(x, x-k);
        ans.emplace_back(x+s, y-k+s);
        ans.emplace_back(x, y);
      } else if (x+y < k) {
        int r = k-((x+y)/2);
        ans.emplace_back(k-r, -r);
        ans.emplace_back(x, y);
      } else {
        int n = (x+y+k-1)/k;
        if ((n*k-x-y)%2 != 0) {
          n++;
        }
        int r = (n*k-x-y)/2;
        int len = 0;
        rep(i, n) {
          len += k;
          if (len <= r) {
            ans.emplace_back(0, -len);
          } else if (len <= r+x) {
            ans.emplace_back(len-r, -r);
          } else {
            ans.emplace_back(x, len-r-r-x);
          }
        }
      }

      cout << ans.size() << endl;
      for(auto& e: ans) {
        if (swapped) swap(e.first, e.second);
        cout << e.first*signx << ' ' << e.second*signy << '\n';
      }

    }
};

signed main() {
  EGolf solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

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

using namespace std;

int main(){
  int n, x;
  cin >> n >> x;
  int cnt = 1, tot = 0, t;
  for(int i = 0; i < n; i++){
    cin >> t;
    tot += t;
    if( tot <= x )
      cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lli = long long int;
using ulli = unsigned long long int;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl


namespace atcoder {
	template<typename T>
	T ncr(T left, T right) {
		right = min(left - right, right);
		T ans = 1;
		for (T i = 1; i <= right; i++) {
			ans = ans * (left - right + i) / i;
		}
		return ans;
	}

	const int LIMIT = 1000000007;
	const int tenfive = 100000;
}

using namespace atcoder;

int main() {
	int n, k;
	cin >> n >> k;
	n = (n + 1) / 2;
	cout << ((n >= k) ? "YES" : "NO") << endl;

	return 0;
}


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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define VIN(v) for(auto&elem_: (v) )cin>>elem_
#define VOUT(v, sep) for(_loop_int idx=0; idx<(_loop_int)v.size(); idx++) {cout<<v[idx]; if(idx<v.size()-1) cout<<sep;} cout<<endl

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(debugidx,v.size())cout<<" "<<v[debugidx];cout<<endl
#define DEBUG_ARR(v,n) cout<<#v<<":";REP(debugidx,n)cout<<" "<<v[debugidx];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
const int IINF = numeric_limits<int>::max()/2-1;
const ll LINF = numeric_limits<ll>::max()/2-1;
#define FIX(a) ((a)%MOD+MOD)%MOD
ll n;
int ans;
void dfs(ll i, int digit){
    if(i>n) return;

    ll kake = pow(10,digit);
    dfs(i+(7*kake),digit+1);
    dfs(i+(5*kake),digit+1);
    dfs(i+(3*kake),digit+1);

    //DEBUG(i);

    string s = to_string(i);
    bool b[8]={};
    REP(j,s.size()){
        b[s[j]-'0'] = true;
    }

    if(b[7] && b[5] && b[3])
        ans++;
}
int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    cin>>n;
    ans=0;
    dfs(7,1);
    dfs(5,1);
    dfs(3,1);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
def fourcard(card) :
    if card.count(card[0]) == 4 or card.count(card[1]) == 4 :
        return True
    else :
        return False

def fullhouse(card) :
    card.sort()
    if (card[0] ==  card[1] == card[2] and card[3] == card[4]) or (card[0] == card[1] and card[2] == card[3] == card[4]) :
        return True
    else :
        return False
        
def straight(card) :
    card.sort()
    if card[0] == 1 and card[1] == 10 and card[2] == 11 and  card[3] == 12 and card[4] == 13 :
        return True
    else :
        ans = 'True'
        for i in range(4) :
            if card[i] + 1 != card[i + 1] :
                ans = False
        if ans == 'True' :
            return True
        else :
            return False

def threecard(card) :
    if card.count(card[0]) == 3 or card.count(card[1]) == 3 or card.count(card[2]) == 3 :
        return True
    else :
        return False
def twopair(card) :
    card.sort()
    if card[0] == card[1] :
        if card[2] == card[3] or card[3] == card[4]:
            return True
    elif card[1] == card[2] :
        if card[3] == card[4] :
            return True
    else :
        return False
def onepair(card) :
    card.sort()
    if card[0] == card[1] or card[1] == card[2] or card[2] == card[3] or card[3] == card[4] :
        return True
    else :
        return False


while True :
    try :
        card = list(map(int, input().split(',')))
    except EOFError :
        break
    
    if fourcard(card) :
        print('four card')
    elif fullhouse(card) :
        print('full house')
    elif straight(card) :
        print('straight')
    elif threecard(card) :
        print('three card')
    elif twopair(card) :
        print('two pair')
    elif onepair(card) :
        print('one pair')
    else :
        print('null')


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

using namespace std;
typedef vector< vector<int> > vv;
#define INF 1e9

//連続不等号使えると勘違い

void go_next(int I,int J,vv& dp,vector<string> x,int w,int h){
  //cout << 0 << endl;
  if(0<=I and I<h-1){
    //cout << I << endl;
    if(x[I+1][J]=='.' and dp[I+1][J]>dp[I][J]+1){
      dp[I+1][J]=dp[I][J]+1;go_next(I+1,J,dp,x,w,h);
    }
  }
  if(0<I and I<=h-1){
    //cout << 1 << endl;
    if(x[I-1][J]=='.' and dp[I-1][J]>dp[I][J]+1){
      dp[I-1][J]=dp[I][J]+1;go_next(I-1,J,dp,x,w,h);
    }
  }
  if(0<=J and J<w-1){
    //cout << 2 << endl;
    if(x[I][J+1]=='.' and dp[I][J+1]>dp[I][J]+1){
      dp[I][J+1]=dp[I][J]+1;go_next(I,J+1,dp,x,w,h);
    }
  }
  if(0<J and J<=w-1){
    //cout << 3 << endl;
    if(x[I][J-1]=='.' and dp[I][J-1]>dp[I][J]+1){
      dp[I][J-1]=dp[I][J]+1;go_next(I,J-1,dp,x,w,h);
    }
  }
}

int main(){
  int h ,w;cin >> h >> w;
  vv dp(h,vector<int>(w,INF));dp[0][0]=1;
  vector<string> x(h);for(int i=0;i<h;i++)cin >>x[i];
  int c=0;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(x[i][j]=='.'){c+=1;}
    }
  }
  //cout << 0 << endl;
  go_next(0,0,dp,x,w,h);
  //cout << 0 << endl;
  if(dp[h-1][w-1]==INF)cout << -1 << endl;
  else cout << c-dp[h-1][w-1] << endl;
}


Measured memory_bytes: 2560
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  string s;
  cin >> s;
  int len = s.length();
  int c = 0;
  for (int i = 0; i < len / 2; i++) {
    if (s[i] != s[len - 1 - i]) c++;
  }

  cout << c << endl;
  return 0;
}

Measured memory_bytes: 256
class Card
  attr_accessor :kind, :number, :first_index

  def initialize(str, index)
    @kind = str[0]
    @number = str[1].to_i
    @first_index = index
  end

  def Card.selection_sort(array)
    0.upto(array.size-1) do |i1|
      i_min = i1
      (i1+1).upto(array.size-1) do |i2|
        if (array[i2].number < array[i_min].number) then
          i_min = i2
        end
      end

      if (i_min != i1) then
        array[i_min], array[i1] = array[i1], array[i_min]
      end
    end
  end

  def Card.bubble_sort(array)
    for i1 in 0...array.size do
      for i2 in i1...array.size-1 do
        index = array.size - 1 - i2 + i1
        if (array[index].number < array[index-1].number) then
          array[index], array[index-1] = array[index-1], array[index]
        end
      end
    end
  end
end

def check_stability(array)
  prev = nil
  array.each do |item|
    if (prev == nil) then
      prev = item
      next
    end

    if (prev.number == item.number) then
      return false if prev.first_index > item.first_index
    end

    prev = item
  end
  return true
end

n = gets.strip.to_i
array = gets.split(' ').each_with_index.map do |item, index|
  Card.new(item, index)
end

array_bub = Array.new(array)
Card.bubble_sort(array_bub)
puts array_bub.map{|x| x.kind + x.number.to_s}.join(' ')

puts (check_stability(array_bub)) ? "Stable" : "Not stable"

array_sel = Array.new(array)
Card.selection_sort(array_sel)
puts array_sel.map{|x| x.kind + x.number.to_s}.join(' ')

puts (check_stability(array_sel)) ? "Stable" : "Not stable"

Measured memory_bytes: 6144
#include <iostream>
using namespace std;
 
int main() {
    int A, B, C, D;
  	cin >> A >> B >> C >> D;
  	int ans;
  	if(C > A){
    	if (C > B) ans = 0;
  		else if(D > B) ans = B - C;
  		else ans = D - C;
    }
  	else{
      if (D < A) ans = 0;
  		else if(D > B) ans = B - A;
  		else ans = D - A;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import _collections
import string
from functools import lru_cache

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]
    def intListList(n):
        return [cin.mapInt() for i in range(n)]
    def intColsList(n):
        return [int(input()) for i in range(n)]
        
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)
    def lcm(a,b):
        return (a * b) // Math.gcd(a,b)
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Math.roundUp(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

MOD = int(1e09) + 7

def main():
    N = cin.int()
    D = cin.mapInt()
    D.sort()
    print(D[N // 2] - D[N // 2 - 1])
    return

if __name__ == "__main__":
    main()


Measured memory_bytes: 53040
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include<map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
using namespace std;
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
#define LONG_INF 8000000000000000000
vector<int> greed[200000];
int search_ans(int a, int b) {
	vector<int> res;
	for (int i = 0;i < greed[a].size();++i) {
		if (greed[a][i] != b) {
			res.push_back(search_ans(greed[a][i], a));
		}
	}
	sort(res.begin(), res.end(),greater<int>());
	int minner = 0;
	for (int i = 0;i < res.size();++i) {
		minner = max(minner, res[i] + i + 1);
	}
	if (minner == 10000000) return 1;
	return minner;
}
int main(){
	int n;
	cin >> n;
	REP(i, n - 1) {
		int tmp;
		cin >> tmp;
		greed[tmp].push_back(i + 2);
		greed[i + 2].push_back(tmp);
	}
	cout << search_ans(1, -1) << endl;
	return 0;
}

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

int main() {
  int A,B;
  cin>>A>>B;
  int sum = A-2*B;
  if(sum > 0){
    cout << sum << endl;
  }
  else{
    cout << 0 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int h, w;
char c[202][102];

int main()
{
    cin >> h >> w;
    for(int i=0; i<2*h; i+=2)
    {
        for(int j=0; j<w; j++)
        {
            cin >> c[i][j];
            c[i+1][j] = c[i][j];
        }
    }
    for(int i=0; i<2*h; i++)
    {
        for(int j=0; j<w; j++)
        {
            cout << c[i][j];
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Scanner;

/**
 * TITLE : Count Balls
 * URL : https://atcoder.jp/contests/abc158/tasks/abc158_b
 */
public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        String N = sc.next();
        String A = sc.next();
        String B = sc.next();
        BigDecimal NBC = new BigDecimal(N);
        BigDecimal ABC = new BigDecimal(A);
        BigDecimal BBC = new BigDecimal(B);

        BigDecimal answer = NBC.divide(ABC.add(BBC), 0, RoundingMode.DOWN).multiply(ABC);
        if (ABC.compareTo(NBC.remainder(ABC.add(BBC))) >= 0) {
            answer = answer.add(NBC.remainder(ABC.add(BBC)));
        } else {
            answer = answer.add(ABC);
        }
        System.out.println(answer.toString());
        sc.close();
    }
}

Measured memory_bytes: 21972
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int A = scan.nextInt();
		int B = scan.nextInt();
		int C = scan.nextInt();
		
		if (A == 5) {
			if (B == 5 && C == 7) {
				System.out.println("YES");
			} else if (B == 7 && C == 5) {
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}
		} else if (A == 7) {
			if (B == 5 && C == 5) {
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}
		} else {
			System.out.println("NO");
		}
	}

}


Measured memory_bytes: 21332
#include <bits/stdc++.h>
using namespace std;
int main() {
    vector<pair<int, int> > a;
    int enter1, enter2;
    int n, m;
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> enter1 >> enter2;
        a.push_back(make_pair(enter1, enter2));
    }
    cin >> m;
    for(int i = 0; i < m; i++) {
        cin >> enter1 >> enter2;
        a.push_back(make_pair(enter1, enter2));
    }

    sort(a.begin(), a.end());
    a.erase(unique(a.begin(), a.end()), a.end());

    for(int i = 0; i < a.size(); i++) {
        if(a[i].second < 10)
            cout << a[i].first << ":" << 0 << a[i].second;
        else
            cout << a[i].first << ":" << a[i].second;
        if(i != a.size() - 1)
            cout << " ";
        else
            cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3112