akhauriyash/Code-Regression huggingface dataset:
package main

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

var sc = bufio.NewScanner(os.Stdin)

func rcvInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	n, m := rcvInt(), rcvInt()

	var k int
	bucket := make(map[int]int, m)
	for i := 0; i < n; i++ {
		k = rcvInt()
		for j := 0; j < k; j++ {
			bucket[rcvInt()]++
		}
	}

	var ans int
	for _, v := range bucket {
		if v == n {
			ans++
		}
	}
	fmt.Println(ans)
}


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

struct UnionFind {
  vector<int> d;
  UnionFind(int n=0): d(n,-1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y);}
  int size(int x) { return -d[find(x)];}
};

int main(void){
    int N, M;
    cin >> N >> M;

    UnionFind union_find = UnionFind(N);

    rep(i, M){
        int A, B;
        cin >> A >> B;
        union_find.unite(A, B);
    }

    int max_group = 0;
    rep(i, N){
        if(union_find.size(i)>max_group){
            max_group = union_find.size(i);
        }
    }

    cout << max_group << endl;


}


Measured memory_bytes: 4028
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <sstream>
#include <istream>

using namespace std;

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

int main(){
	int n;
	int a[1000];
	cin >> n;
	for(int i=0;i<n;i++) cin >> a[i];
	sort(a,a+n);

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

	if(sum>a[n-1]){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
<?php
# 整数の入
fscanf(STDIN, "%d", $a);


$array = [];

for($i=0;$i <$a ; $i++){
# スペース区切りの整数の入力
// fscanf(STDIN,"%s %d", $array[$i]["city"], $array[$i]["no"]);
fscanf(STDIN,"%s %d", $b, $c);

$temp = [
        'city' => $b,
        'point' => $c,
        'id' => $i+1
                ];
array_push($array, $temp);
//echo    (print_r($temp));

}


//echo    (print_r($array));

foreach ($array as $key => $value) {
    $city[$key] = $value["city"];
    $no[$key] = $value["point"];
}
//
//array_multisort($array, SORT_ASC, $city);
array_multisort($city, SORT_ASC,
$no, SORT_DESC,
$array);

// echo    (print_r($array))

foreach ($array as $key => $value) {
    echo ($value['id']."\n");
}


# 文字列の入力
//fscanf(STDIN, "%s", $s);
//# 出力
//echo ($a+$b+$c)." ".$s."\n";
?>

Measured memory_bytes: 4604
package main

import (
	"fmt"
)

func main() {
	var s string
	fmt.Scan(&s)

	if s[0] != s[1] && s[1] != s[2] && s[2] != s[0] {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;
const int MOD = 1000000009;
const double pi = acos(-1);

int main() {
    int N,A,B; cin >> N >> A >> B;
    cout << min(B,A*N) << endl;
}

Measured memory_bytes: 3636
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;

using Weight=long long;
static const Weight INF=1LL<<57;

struct Arc {
    // accessible to the reverse edge
    size_t src, dst;
    Weight capacity, flow;
    size_t rev;
    Arc() {}
    Arc(size_t src, size_t dst, Weight capacity):
        src(src), dst(dst), capacity(capacity), flow(0), rev(-1)
    {}
    Weight residue() const {
        return capacity - flow;
    }
};

bool operator<(const Arc &e, const Arc &f) {
    if (e.capacity != f.capacity) {
        return e.capacity > f.capacity;
    } else {
        return e.src!=f.src? e.src<f.src : e.dst<f.dst;
    }
}

using Arcs=vector<Arc>;
using Node=vector<Arc>;
using FlowNetwork=vector<Node>;

void connect(FlowNetwork &g, size_t s, size_t d, Weight c=1) {
    g[s].push_back(Arc(s, d, c));
    g[d].push_back(Arc(d, s, 0));

    g[s].back().rev = g[d].size()-1;
    g[d].back().rev = g[s].size()-1;
}

void join(FlowNetwork &g, size_t s, size_t d, Weight c=1) {
    g[s].push_back(Arc(s, d, c));
    g[d].push_back(Arc(d, s, c));

    g[s].back().rev = g[d].size()-1;
    g[d].back().rev = g[s].size()-1;
}

Weight max_flow(FlowNetwork &g, size_t s, size_t t) {
    /* Edmonds-Karp */
    size_t V=g.size();

    Weight mflow=0;
    while (true) {
        queue<size_t> q; q.push(s);
        vector<Arc *> prev_(V, NULL);
        while (!q.empty() && prev_[t]==NULL) {
            size_t u=q.front(); q.pop();
            for (Arc &e: g[u]) {
                if (e.dst!=s && prev_[e.dst]==NULL && e.residue()>0) {
                    prev_[e.dst] = &e;
                    q.push(e.dst);
                }
            }
        }
        if (prev_[t] == NULL) return mflow;

        Weight incr=INF;
        for (Arc *e=prev_[t]; e!=NULL; e=prev_[e->src])
            incr = min(incr, e->residue());

        mflow += incr;
        for (Arc *e=prev_[t]; e!=NULL; e=prev_[e->src]) {
            e->flow += incr;
            g[e->dst][e->rev].flow -= incr;
        }
    }
}

int main() {
    size_t V, E;
    scanf("%zu %zu", &V, &E);

    FlowNetwork g(V);
    for (size_t i=0; i<E; ++i) {
        size_t u, v;
        Weight c;
        scanf("%zu %zu %lld", &u, &v, &c);

        connect(g, u, v, c);
    }

    printf("%lld\n", max_flow(g, 0, V-1));
    return 0;
}

Measured memory_bytes: 2824
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=1e5+5;
const int mod=1e9+7;
ll f[maxn],n,k,ans;
ll fast(ll m,ll c){
    ll a=1;
    while(c)
	{
        if(c%2==1) a=a*m%mod;
        m=m*m%mod;
        c=c/2;
    }
    return a;
}
int main(){
    cin>>n>>k;
    for(int i=k;i>=1;i--)
	{
        f[i]=fast(k/i,n);
        for(int j=i+i;j<=k;j+=i)
            f[i]=(f[i]-f[j]+mod)%mod;
        ans=(ans+f[i]*i)%mod;
    }
    cout<<ans;
    return 0;
}

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

int main()
{
    int N, M, Q;
    cin >> N >> M >> Q;
    vector<vector<int>> LR(N, vector<int>(N, 0));
    int Li, Ri, pi, qi;
    for(int i=0;i<M;i++){
        cin >> Li >> Ri;
        LR[Li-1][Ri-1]++;
    }
    vector<vector<int>> LR2(N, vector<int>(N, 0));
    for(int i=0;i<N;i++){
        LR2[i][i] += LR[i][i];
        for(int j=i+1;j<N;j++){
            LR2[i][j] += LR2[i][j-1] + LR[i][j];
        }
    }
    for(int i=N-2;i>=0;i--){
        for(int j=i+1;j<N;j++){
            LR2[i][j] += LR2[i+1][j];
        }
    }

    vector<int> res(Q, 0);
    for(int i=0;i<Q;i++){
        cin >> pi >> qi;
        res[i] = LR2[pi-1][qi-1];
    }
    for(auto v : res) cout << v << endl;

    return 0;
}

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

int main(){
  int A,B,X;
  cin>>A>>B>>X;
  if(A>X){
    cout<<"NO"<<endl;
  }
 else if(X-A<=B){
    cout<<"YES"<<endl;
  }
  else{
    cout<<"NO"<<endl;
  }
}
  

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

int main(){
	int a,b,k; cin >> a >> b >> k;
	for(int i=0;i<k && i<=b-a;i++){
		cout << a+i << endl;
	}
	for(int i=k-1;i>=0 ;i--){
		if(b-i>a+k-1)
		cout << b-i << endl;
	}

}

Measured memory_bytes: 256
/*author : Yashvardhan
Saturday, May 02, 2020
7:06 PM
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

using ll = long long;

#define pb push_back
#define vi vector<int>
#define pi pair<int,int>
#define vpi vector<pi>
#define ff first
#define ss second
#define mp make_pair
#define endl '\n'
#define all(a) a.begin(), a.end()
#define initialise(a, x) memset(a, x, sizeof(a))
#define rev(Y) reverse(all(Y))

#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS

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

template <typename T> ostream& operator << (ostream& os,const vector<T>& v){for(int i=0;i<v.size();++i) os<<v[i]<<" ";return os;} 
template <typename T> ostream& operator << (ostream& os,const set<T>& v){for(auto it:v) os<<it<<" ";return os;} 
template <typename T, typename S> ostream& operator << (ostream& os, const pair<T,S>& v) {os<<v.ff<<" "<<v.ss;return os;}

typedef tree<pair<int,int>, null_type, less<pi>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int mod = 1e9 + 7;
const int inf = 2e9;
const int ninf = -2e9;

int takemod(int a){return ((a%mod)+mod)%mod;}

int pow(int a, int b, int m)
{
	int ans = 1;
	a %= m;
	while (b)
	{
		if (b & 1)
			ans = (ans * a) % m;
		b /= 2;
		a = (a * a) % m;
	}
	return ans;
}

int modinv(int a){return takemod( pow( takemod(a), mod-2,mod ) );}

const int N = 2e5 + 5;

vi g[N];
int arr[N];
int vis[N];
int ans[N];

set<int> s;
set<int>::iterator it;

void dfs(int source){
	vis[source] = 1;

	it = s.lower_bound(arr[source]);
	int rem = -1;
	if(it != s.end()){
		rem = *it;
		s.erase(it);
	} 
	s.insert(arr[source]);

	ans[source] = s.size();

	for(auto i : g[source]){
		if(!vis[i]) dfs(i);
	}
	if(s.find(arr[source]) != s.end()) s.erase(arr[source]);
	if(rem != -1) s.insert(rem);

}

signed main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(0);

	#ifdef __APPLE__
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
		freopen("error.txt","w",stderr);
	#endif

	time_t t1, t2;
	t1 = clock();
	
	int n;
	cin >> n;

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

	for(int i = 0; i < n - 1; i++){
		int u,v;
		cin >> u >> v;
		g[u].pb(v);
		g[v].pb(u);
	}

	dfs(1);

	for(int i = 1; i <= n; i++) cout << ans[i] << endl;
	
	t2 = clock();
	cerr << endl << t2-t1 << endl;
	
	return 0;
}



Measured memory_bytes: 34136
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define MAX 510000
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
#define uni(q) unique(all(q)),q.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;



int main(){
    ll n; cin >> n;
    string s; cin >> s;
    ll dp[n+1][n+1] = {};
    for(ll i=n-1; i>=0; i--){
        for(ll j=n-1; j>=i; j--){
            if(s[i] != s[j]) dp[i][j] = 0;
            else{
                dp[i][j] = dp[i+1][j+1] + 1;
            }
        }
    }
    ll ans = 0;
    rep(i,n){
        rep(j,n){
            ans = max(ans, min(dp[i][j], j-i));
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 195712
//eratosurenesu
#include<stdio.h>
#define MAX_V 10000
int prime[MAX_V+1];
int main(){
	int i,k,v;
	for(i=2;i<=MAX_V;i++){
		prime[i]=1;
	}
	for(i=2;i*i<=MAX_V;i++){
		if(prime[i]){
			for(k=2*i;k<=MAX_V;k+=i){
				prime[k]=0;
			}
		}
	}
	while(1){
		scanf("%d",&v);
		if(v==0)	break;
		for(i=v;i>=2;i--){
			if(prime[i]==1 && prime[i-2]==1){
				printf("%d %d\n",i-2,i);
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1804
using System;
using System.Linq;
using System.Collections.Generic;

namespace ABC
{
    class ProgramA
    {
        static void Main(string[] args)
        {
            var a = int.Parse(Console.ReadLine());
            var a0 = a / 1000;
            a = a % 1000;
            var a1 = a / 100;
            a = a % 100;
            var a2 = a / 10;
            var a3 = a % 10;

            var result = (a0 == a1 && a1 == a2) || (a1 == a2 && a2 == a3);
            Console.WriteLine(result ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 27416
import sys
sys.setrecursionlimit(10 ** 7)

N, X = map(int, input().split())

if X < N :
    print(0)
else :
    pat = [0] * (N + 1)  # パティ数
    ban = [0] * (N + 1)  # バンズ数
    pat[0] = 1
    for i in range(1, N + 1) :
        pat[i] = 2 * pat[i - 1] + 1
        ban[i] = 2 * ban[i - 1] + 2
    def sol(level, height) :
        if height <= 0 :
            return 0
        if level == 0 :
            return 1
        if height <= 1 :
            return 0
        if height < pat[level - 1] + ban[level - 1] :
            return sol(level - 1, height - 1)
        if height == pat[level - 1] + ban[level - 1] + 1 :
            return pat[level - 1]
        if height == pat[level - 1] + ban[level - 1] + 2 :
            return pat[level - 1] + 1
        return pat[level - 1] + 1 + sol(level - 1, height - (pat[level - 1] + ban[level - 1] + 2))

    ans = sol(N, X)
    print(ans)

Measured memory_bytes: 3064
let longer s1 s2 =
    if fst s1 >= fst s2
    then s1
    else s2

let rec update t_i s dp dp_i_j1 dp_i1_j1 =
    match s, dp with
    | s_j :: s', dp_i1_j :: dp' ->
        let dp_i_j =
            if s_j = t_i
            then (1 + fst dp_i1_j1, s_j :: snd dp_i1_j1)
            else longer dp_i1_j dp_i_j1
        in dp_i_j :: update t_i s' dp' dp_i_j dp_i1_j
    | _ -> dp

let rec solve s t dp =
    match t with
    | t_i :: t' -> solve s t' @@ update t_i s dp (0, []) (0, [])
    | [] -> dp

let () =
    let s = read_line () |> Str.split (Str.regexp "") |> List.map (fun s -> s.[0]) in
    let t = read_line () |> Str.split (Str.regexp "") |> List.map (fun s -> s.[0]) in
    let rec init n =
        if n = 0 then []
        else (0, []) :: init (n - 1)
    in
    let s_len = List.length s in
    solve s t (init s_len)
    |> (fun ls -> List.nth ls (s_len - 1))
    |> snd
    |> List.rev
    |> List.iter print_char;
    print_newline ()


Measured memory_bytes: 171708
#include<iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <functional>
#include <ctime>
#include <iomanip>
#include <sstream>
#include <algorithm>
#define ll long long
#define PI acos(-1)
#define mes(x,y) memset(x,y,sizeof(x))
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
ll GCD(ll a, ll b) {//最大公约数
	return b == 0 ? a : GCD(b, a % b);
}
ll Power(ll a, ll b, ll p) { //计算(a^b)%p;
	ll ans = 1;
	while (b) {
		if (b & 1) //等价于b%2，判断b的奇偶性
			ans = ans * a % p; //如果为奇数，证明该位为1，需要乘上a
		a = a * a % p; //计算a^(2^i)
		b >>= 1; //等价于b/=2;
	}
	return ans;
}
bool isprime(ll num)
{
	if (num == 2 || num == 3)
		return true;
	if (num % 6 != 1 && num % 6 != 5)
		return false;
	ll t = sqrt((double)num);
	for (ll i = 5; i <= t; i += 6)
		if (num % i == 0 || num % (i + 2) == 0)
			return false;
	return true;
}
string sum(string s1, string s2)
{
	if (s1.length() < s2.length())
	{
		string temp = s1;
		s1 = s2;
		s2 = temp;
	}
	int i, j;
	for (i = s1.length() - 1, j = s2.length() - 1; i >= 0; i--, j--)
	{
		s1[i] = char(s1[i] + (j >= 0 ? s2[j] - '0' : 0));   //注意细节
		if (s1[i] - '0' >= 10)
		{
			s1[i] = char((s1[i] - '0') % 10 + '0');
			if (i) s1[i - 1]++;
			else s1 = '1' + s1;
		}
	}
	return s1;
}
bool isRunyear(int year)
{
	if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
	{
		return true;
	}
	else {
		return false;
	}
}
ll n, m, i, j, k, t;
const ll INF = 1e9 + 10;

int main() {
	FAST_IO;
	double r;
	while (cin >> n >> m) {
		for (i = 0, j = 0; i < m; i++) {
			cin >> k;
			j += k;
		}
		n -= j;
		cout << (n >= 0 ? n : -1) << endl;
	}
}

Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL << 60; //intじゃ扱えないことに注意！
#define mod 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++) //範囲外参照とループの初期化に注意！

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

  A[0] = B[0];
  A[N-1] = B[N-2];
  for(int i = 1; i < N-1; i++){
    A[i] = min(B[i-1],B[i]);
  }

  int ans = 0;
  for(int i = 0; i < N; i++){
    ans += A[i];
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
import numpy as np

n, m = map(int,input().split())
a = list(map(int,input().split()))

na = np.zeros(2**18)
for i in a:
    na[i] += 1

fa = np.fft.fft(na)

c = np.round(np.fft.ifft(fa*fa)).astype(int)

ans = 0
cm = 0
for i in range(2**18 - 1, 1, -1):
    cm += c[i]
    ans += i*c[i]
    if cm > m:
        ans -= i * (cm - m)
    if cm >= m:
        break

print(ans)


Measured memory_bytes: 52828
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
typedef long long ll;
#define PB	push_back
#define FOR(n)			for(int i = 0; i < n; ++i)
#define RFOR(n)			for(int i = n; i >= 0; --i)
#define FORR(start,end) for(int i = start; i < end; ++i)
#define COUT(n)			cout << n << " " << flush
#define vi(v)			vector<int> v
#define vii(v)			vector<pair<int,int>> v
#define mkp(a,b)		make_pair(a,b)
#define ALL(obj)		obj.begin(), obj.end()
using namespace std;

int main() {
	int n;
	vector<int> L(2000);
	int cou = 0;
	cin >> n;
	FOR(n)
		cin >> L[i];

	sort(ALL(L), greater<int>());
	FOR(n - 2)
	{
		int longest = L[i];
		for (int j = i + 1; j < n - 1; ++j) {
			for (int k = j + 1; k < n; ++k)
				if (longest < L[j] + L[k])
				{
					++cou;
				}
				else {
					break;
				}
		}
	}

	cout << cou << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
void judge(char bubble[][3],char selection[][3],int n);

int main(){
  int n;
  int i,j,minj;
  char a[36][3],b[36][3],temp[3];
 

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

  /* BubbleSort */
  for(i=0;i<n;i++){
    for(j=n-1;j>i;j--){
      if(a[j][1]<a[j-1][1]){
	strcpy(temp,a[j]);
	strcpy(a[j],a[j-1]);
	strcpy(a[j-1],temp);
      }
    }
  }
  for(i=0;i<n;i++){
    printf("%s",a[i]);
    if(i!=n-1) printf(" ");
    else printf("\n");
  }
  printf("Stable\n");

  /* SelectionSort */
  for(i=0;i<n;i++){
    minj = i;
    for(j=i;j<n;j++){
      if(b[j][1]<b[minj][1]) minj = j;
    }
    if(minj != i){
	strcpy(temp,b[i]);
	strcpy(b[i],b[minj]);
	strcpy(b[minj],temp);
    }
  }
    for(i=0;i<n;i++){
    printf("%s",b[i]);
    if(i!=n-1) printf(" ");
    else printf("\n");
  }
    judge(a,b,n);
  
  return 0;
}

void judge(char bubble[][3],char selection[][3],int n){
  int i,count=0;
  for(i=0;i<n;i++)
    if(strcmp(bubble[i],selection[i])!=0) count++;
    if(count==0) printf("Stable\n");
    else printf("Not stable\n");
}




Measured memory_bytes: 2140
N = int(input())
a = list(map(int, input().split()))
if N == 2:
    print(max(a), min(a))
    quit()
a.sort()
from bisect import bisect_left
#for i in range(N):
cur = a[N - 1] // 2
s = bisect_left(a, cur)
min_ = float('Inf')
for i in range(-1, 2):
    #print(i)
    if min_ > abs(a[N - 1] - 2 * a[s + i]):
        min_ = abs(a[N - 1] - 2 * a[s + i])
        arg = i
print(a[N - 1], a[s + arg])

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

int main(){
	// sengen
	int n;
	// nyuryoku
	cin >> n;
	int a[n];
	int ans = 0;
	for(int i=0;i<n;i++){
		cin >> a[i];
		if(i%2 == 0 && a[i]%2 != 0){
			ans++;
		}
	}
	// keisan
	cout << ans;
	// syutsuryoku
}

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

#define ll long long

int n;
vector<ll> arr (50);

ll max(ll a, ll b) {
	if(a > b) {
		return a;
	}
	return b;
}

bool check(ll num) { //a[i]-x*n+(num-x) <= n-1       a[i]+num-n+1 >= (n+1)*x;         (a[i]+num-n+1)/(n+1) <= x
	ll count = 0;
	for(int i = 0; i < n; i++) {
		ll div = arr[i]+num-n+1;
		ll x;
		if(div <= 0) {
			x = 0;
		} else {
			x = div/(n+1);
			if(div%(n+1) != 0) {
				x++;
			}
		}
		count+= x;
	}
	return (num >= count);
}

ll binary(ll from, ll to) {
	if(from >= to) {
		return from;
	}
	ll mid = (from+to)/2;
	if(check(mid)) {
		return binary(from,mid);
	} else {
		return binary(mid+1,to);
	}
}

int main() {
	cin >> n;
	ll sum = 0;
	for(int i = 0; i < n; i++) {
		cin >> arr[i];
		sum+= arr[i];
	}
	ll ans = binary(max(0,sum-n*(n-1)),600000000000000000);
	for(ll i = max(0,ans-5000); i < ans+5000; i++) {
		if(check(i)) {
			cout << i;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 256
d = int(input())
"""
とある世界では、今日は 12 月 D 日です。
D=25 なら Christmas,
D=24 なら Christmas Eve,
 D=23 なら Christmas Eve Eve,
 D=22 なら Christmas Eve Eve Eve と出力するプログラムを作ってください。
"""

print("Christmas"+" Eve" * (25 - d))


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
using P=pair<int,int>;
typedef unsigned long long ull;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const ll MOD=1e9+7;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);  
  
  int a,b,c;
  cin >> a >> b >> c;
  swap(a,b);
  swap(a,c);
  cout << a << " " << b << "  "<< c << endl;
  
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;
int main(){
  int n , a , m = 1;
  cin >> n;
  for (int i = 0 ; i < n ; i ++) {
    cin >> a;
    if (a % 2 == 0) {
      m *= 2;
    }
  }
  int ans = pow(3 , n) - m;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <deque>
#include <functional>
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#define ll long long int
#define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, n)

using namespace std;

int main() {
    int x, y, z;
    cin >> x >> y >> z;
    cout << z << " " << x << " " << y << endl;
    return 0;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

ll beki(ll x){
	if(x==0) return 1;
	return 2*beki(x-1);
}

int main(){
	ll L;
	cin >> L;

	ll t = 0;
	ll pro = 1;
	while(pro <= L){
		pro *= 2;
		t++;
	}
	t--;
	pro /= 2;

	ll X = L - pro;
	ll m = 0;
	REP(i, t){
		if ((X>>i)&1) m++;
	}

	cout << t+1 << " " << 2*t+m << endl;
	REP(i, t){
		cout << i+1 << " " << i+2 << " " << 0 << endl;
		cout << i+1 << " " << i+2 << " " << beki(i) << endl;
	}


	ll tmp = pro;
	REP(i, t){
		if ((X>>i)&1){
			cout << i+1 << " " << t+1 << " " << tmp << endl;
			tmp += beki(i);
		}
	}

    return 0;
}

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

int N;
int W;
int w[100];
long long v[100];
long long dp[101][100001];

int main(){
    cin >> N >> W;
    for(int i = 0; i < N; i++){
        cin >> w[i] >> v[i];
    }

    for(int i = 0; i < N; i++){
        for(int j = 0; j < W; j++){
            dp[i][j] = 0;
        }
    }

    for(int i = 1; i <= N; i++){
        for(int j = 0; j <= W; j++){
            dp[i][j] = dp[i - 1][j];
            if(j - w[i-1] >= 0){
                dp[i][j] = max(dp[i-1][j], dp[i - 1][j - w[i-1]] + v[i-1]);
            }
        }
    }

    /*for(int i = 0; i <= N; i++){
        for(int j = 0; j <= W; j++){
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }*/
    cout << *max_element(dp[N], dp[N]+ W+1) << endl;
    return 0;

}

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

using namespace std;

const int N = 5e5 + 5;
int _w;

char str[N];
int n , dat[N];
long long ans;

int main( void ) {
  _w = scanf("%s",str+1);
  n = strlen( str + 1 ) + 1;
  str[0] = '>';
  str[n] = '<';
  for( int i = 1 , r ; i <= n ; i = r + 1 ) {
    r = i;
    if( str[i - 1] == '>' && str[i] == '<' ) {
      for( int j = i - 1 ; j ; --j ) {
        dat[j] = max( dat[j] , i - j );
        if( str[j - 1] == '<' ) break;
      }
      while( r <= n && str[r] == '<' ) {
        ++r;
        dat[r] = max( dat[r] , r - i );
      }
    }
  }
  for( int i = 1 ; i <= n ; ++i )
    ans += dat[i];
  cout << ans;
  return 0;
}


Measured memory_bytes: 2688
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <bitset>
#include <vector>
#include <queue>
#include <map>
#include <set>

#define i64 int64_t
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define st(vvv) sort(vvv.begin(),vvv.end())
#define rvs(vvv) reverse(vvv.begin(),vvv.end())
int inf = 1000000007;
i64 giant = 4000000000000000000;

using namespace std;



int main() {
	i64 a, b, k;
	cin >> a >> b >> k;
	if (a < k) {
		k -= a;
		a = 0;
	}
	else {
		a -= k;
		k = 0;
	}
	if (b < k) {
		b = 0;
	}
	else {
		b -= k;
	}
	cout << a << " " << b << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int h,w,ans=0;
    cin>>h>>w;
    char ch[8][8];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>ch[i][j];
            if(ch[i][j]=='#')ans++;
        }
    }
    if(ans==h+w-1)cout<<"Possible"<<endl;
    else cout<<"Impossible"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
    ll n;
    cin>>n;
    double arr[n+1];
    for(ll i = 0;i<n;i++){
        cin>>arr[i];
    }
   sort(arr,arr+n);
   ll j = 1;
   double ans = 0;
   for(ll i = j;i<n;i++){
       ans = (arr[i] + arr[i-1])/2;
       arr[i] =  ans;
       j = i+1;
       sort(arr+i,arr+n);
   }
   cout<<fixed;
  cout<<setprecision(25)<<arr[n-1]<<"\n";
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int h = sc.nextInt();
		int[] arr = new int[n];
		int max = 0;
		for (int i = 0; i < n; i++) {
		    max = Math.max(max, sc.nextInt());
		    arr[i] = - sc.nextInt();
		}
		Arrays.sort(arr);
		int count = 0;
		for (int i = 0; i < n && h > 0 && -arr[i] > max; i++) {
		    h += arr[i];
		    count++;
		}
	    count += (Math.max(h, 0) + max - 1) / max;
        System.out.println(count);
    }
}



Measured memory_bytes: 63076
/************************************************
 *Author* :zzy
**Problem**:
**Analyse**:
**Get**:
**Code**:
*********************************************/

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <stack>
using namespace std;
typedef long long ll;
typedef long long LL;
typedef unsigned long long ull;
typedef double db;
#define re register
#define push_back pb
#define pri(a) printf("%d",(int)(a))
#define sa(n) scanf("%d", &(n))
#define IOS ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define vep(c) for(decltype((c).begin() ) it = (c).begin(); it != (c).end(); it++)
const int INF = 0x3f3f3f3f;
const int maxn = 2e5+7;
const double eps = 1e-7;
const double pi = acos(-1.0);

string s,t;
int main(void)
{
    IOS;
    cin>>s;
    int ans = 1;
    int flag = 0;
    for(int i=1; i<s.length(); i++)
    {
        if(flag == 0 && s[i] == s[i-1]) flag = 1,i++;
        else if(flag == 1) flag = 0;
        if(i<s.length())ans++;
    }
    cout<<ans<<endl;
    return 0;
}







Measured memory_bytes: 720
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define dofloat cout<<fixed<<setprecision(8)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bitcount __builtin_popcount
#define all(vec) vec.begin(),vec.end()
#define rall(vec) vec.rbegin(),vec.rend()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vll;
typedef vector<pair<int,int> > vii;
typedef vector<int> vi;
typedef pair<int,int> ii;
const long long MOD=1000000007;
const long long MAX=100005;
const long double PI=3.14159265359;
const long double G=9.807;
const long long INF=1e18;
const long double EPS=1e-6;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
bool isprime(ll a){
  if(a==2)return 1;
  if(!(a&1))return 0;
  for(ll i=3;i*i<=a;i+=2)
    if(a%i==0)return 0;
  return 1;
}
ll mpow(ll base,ll exponent,ll modulus){
  if(modulus==1)return 0;
  long long result = 1;
  base=base%modulus;
  while(exponent){
    if(exponent%2 == 1)
	  result=(result*base)%modulus;
	  exponent=exponent>>1;
	  base=(base*base)%modulus;
  }
  return result;
}
ll minv(ll a,ll mod){
  ll _gcd=gcd(a,mod);
  assert(_gcd==1);
  return mpow(a,mod-2,mod);
}


/*
ll ncr(ll N,ll K){
	if(N<K)return 0;
	if(K==0)return 1;
	if(N==0)return 0;

	ll den=1;
	for(ll i=1;i<=K;i++)den*=i;
	ll num=1;
	while(K--){
		num*=N;
		if(num%den==0){
			num/=den;
			den=1;
		}
		N--;
	}

	return num;
}
*/
ll n;
vl a;
multiset<ll>f;
int main(){FAST;
cin>>n;
for(ll i=0;i<n;i++){
	ll x;cin>>x;
	a.pb(x);
	f.insert(x);
}
for(auto it:a){
	ll x = it;
	f.erase(f.find(x));
	cout<<*f.rbegin()<<"\n";
	f.insert(x);
}
return 0;
}

Measured memory_bytes: 12656
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <queue>
#include <numeric>


using namespace std;


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

	int ans = 0;
	for (int i = 1; i < N; i++) {
		int cnt = 0;

		for (char c = 'a'; c <= 'z'; c++) {
			bool left = false, right = false;

			for (int j = 0; j < i; j++)
				if (S[j] == c) {
					left = true;
				}

			for (int j = i; j < N; j++) {
				if (S[j] == c) {
					right = true;
				}
			}
			if (left && right) {
				cnt++;
			}
		}
		if (ans < cnt) {
			ans = cnt;
		}
	}
		cout << ans << "\n";

		return 0;
}


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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
bool chmin(T &a,T b){if(a>b){a=b;return true;}else return false;}
template<typename T>
bool chmax(T &a,T b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2>&p){
  return os << p.first << " " << p.second;
}  
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll n;cin>>n;
  vector<vector<ll>>v((n+1)/2);
  rep(i,0,n/2){
    v[i].PB(i+1);
    v[i].PB(n-i-(n&1));
  }
  if(n&1)v.back().PB(n);
  ll sz=v.size();
  vector<P>ret;
  rep(i,0,sz-1){
    for(auto v1:v[i])for(auto v2:v[i+1]){
      ret.EB(v1,v2);
    }
  }
  if(sz!=2){
    for(auto v1:v[sz-1])for(auto v2:v[0])ret.EB(v1,v2);
  }
  cout<<ret.size()<<endl;
  rep(i,0,ret.size())cout<<ret[i]<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<vector>
#include <algorithm>
using namespace std;
int main(void){
    string S;
    cin >> S;
    
    vector<string> SS;
    for(int i = 0; i < 4 ; i++){
        SS.push_back(S.substr(i,1));
    }
    sort(SS.begin(),SS.end());
    
    if(SS[0]==SS[1]&&SS[2]==SS[3]&&SS[0]!=SS[3]){
        cout <<"Yes"<<endl;
        return 0;
    }
    cout <<"No"<<endl;
}


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

using namespace std;

int main()
{
    int N, T;
    cin >> N >> T;
    int ans = 2000;
    int c, t;
    for(int i=0; i<N; i++){
        cin >> c >> t;
        if(t<=T){
            ans = min(c,ans);
        }
    }
    if(ans>=2000){
        cout << "TLE" << endl;
    }else{
        cout << ans << endl;
    }
}

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

long N, i, j, mod=1e9+7, ans;

int main() {
  cin >> N;

  vector<long> A(N);

  for(auto& a : A)
    cin >> a;

  for(i = 0; i < 60; i++) {
    long cnt = 0; // counts the number of 1s
                  // those come from each number
                  // at position i

    for(auto a : A)
      cnt += a >> i&1;

    cnt = cnt * (N - cnt) % mod; // cnt = (num_of_1s * num_of_0s)(mod 1e9+7)

    for(j = 0; j < i; j++)
      cnt = cnt * 2 % mod;

    ans += cnt;
  }
  cout << ans % mod << endl;

  return 0;
}


Measured memory_bytes: 2560
import java.util.Scanner;
import java.util.Random;
import java.io.PrintWriter;

public class Main{
    public static Random rand = new Random();
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        long start = System.currentTimeMillis();
        int D = Integer.parseInt(sc.next());
        int[] C = new int[26];
        int[] L = new int[26];
        for (int i = 0; i < 26; i++){
            C[i] = Integer.parseInt(sc.next());
            L[i] = 0;
        }
        int[][] S = new int[D][26];
        int[] Ans = new int[D];
        for (int i = 0; i < D; i++){
            int maxS = 0;
            for (int j = 0; j < 26; j++){
                S[i][j] = Integer.parseInt(sc.next());
                if (S[i][j] > maxS){
                    maxS = S[i][j];
                    Ans[i] = j + 1;
                }
            }
        }
        int maxPoint = calcPoint(Ans, S, C, L, D);
        

        while (System.currentTimeMillis() - start < 1850){
            maxPoint = change(Ans, S, C, L, D, maxPoint, 1500 - (System.currentTimeMillis() - start));
        }

        for (int i = 0; i < D; i++){
            out.print(Ans[i]);
            out.print("\n");
        }
        //out.println(maxPoint);
        //template
        sc.close();
        out.flush();
    }

    public static int calcPoint(int[] Ans, int[][] S, int[] C, int[] L, int D){
        int point = 0;
        for (int i = 0; i < 26; i++){
            L[i] = 0;
        }
        for (int i = 0; i < D; i++){
            point += S[i][Ans[i] - 1];
            L[Ans[i] - 1] = i + 1;
            for (int j = 0; j < 26; j++){
                point -= C[j] * (i + 1 - L[j]);
            }
        }
        return point;
    }

    public static int change(int[] Ans, int[][] S, int[] C, int[] L, int D, int maxPoint, long t){
        int ci = rand.nextInt(D);
        int before = Ans[ci];
        Ans[ci] = rand.nextInt(26) + 1;
        int newPoint = calcPoint(Ans, S, C, L, D);
        if (newPoint < maxPoint){
            if (rand.nextInt(1900) < t){
                return newPoint;
            }
            else{
                Ans[ci] = before;
            return maxPoint;
            }    
        }
        else{
            return newPoint;
        }
    }
}

Measured memory_bytes: 42304
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

int main() {
	int h, w;
	cin >> h >> w;
	
	vector<string> a(h);
	
	for(int i = 0; i < h; ++i) {
		cin >> a[i];
	}
	
	for(int i = 0; i < h; ++i) {
		for(int j = 0; j < w; ++j) {
			if(a[i][j] == '#') {
				cout << '#';
				continue;
			}
			
			int cnt = 0;
			
			for(int dx : {-1, 0, 1}) {
				for(int dy : {-1, 0, 1}) {
					int x = j + dx;
					int y = i + dy;
					
					if(x < 0 || w <= x) {
						continue;
					}
					if(y < 0 || h <= y) {
						continue;
					}
					
					cnt += a[y][x] == '#';
				}
			}
			
			cout << cnt;
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 888
#include<stdio.h>
int main()
{
 int n,i,m,x,s=0,j;
  scanf("%d%d",&n,&x);
  int ar[n];
  for(i=0;i<n;i++)
  {
    scanf("%d",&ar[i]);
    s+=ar[i];
   }  
    m=ar[0];
  for(i=0;i<n;i++)
  {
    if(m>ar[i])
    {
      m=ar[i];
    }
  }
   if(s==x)
  { 
    printf("%d\n",n);
  }
  else if(s<x)
  {
       
      j=(x-s)/m; 
    printf("%d\n",n+j);
  }
  return 0 ;
}

Measured memory_bytes: 1676
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String S = sc.next();


		if(S.equals("ABC")) {
			System.out.println("ARC");
		}else {
			System.out.println("ABC");
		}
	}

}

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

const int maxn = 100100;
int l[maxn];
int r[maxn];
int n;

ll solve(bool fw) {
  set<pair<int, int>> byl, byr;
  for (int i = 0; i < n; ++i) {
    byl.emplace(l[i], i);
    byr.emplace(r[i], i);
  }
  int pos = 0;
  ll res = 0;
  for (int i = 0; i < n; ++i) {
    int id;
    if (fw) {
      id = byl.rbegin()->second;
    } else {
      id = byr.begin()->second;
    }
    //cerr << "to " << id+1 << '\n';
    byl.erase({l[id], id});
    byr.erase({r[id], id});
    if (pos < l[id]) {
      res += l[id] - pos;
      pos = l[id];
    }
    if (pos > r[id]) {
      res += pos - r[id];
      pos = r[id];
    }
    fw ^= 1;
  }
  res += abs(pos);
  return res;
}

signed main() {
#ifdef LOCAL
  assert(freopen("c.in", "r", stdin));
#endif
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> l[i] >> r[i];
  }
  ll res1 = solve(false);
  ll res2 = solve(true);
  cerr << res1 << ' ' << res2 << '\n';
  cout << max(res1, res2) << '\n';
}


Measured memory_bytes: 12416
// Problem : A - Frog 1
// Contest : AtCoder - Educational DP Contest
// URL : https://atcoder.jp/contests/dp/tasks/dp_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define int long long
#define db double
#define mod 1000000007
#define pb push_back
#define pp pair<int,int>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repe(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=b;i>=a;i--)
#define maxn 200005
#define ss second
#define ff first
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
int inv(int a, int b){
 return 1<a ? b - inv(b%a,a)*b/a : 1;
}
void solve()
{
	int n,k;
	cin >> n>>k;
	int a[n],dp[n];
	rep(i,0,n)
		dp[i]=INT_MAX;
	rep(i,0,n)
		cin >> a[i];
	dp[0]=0;
	rep(i,1,n)
	{
		dp[i]=dp[i-1]+abs(a[i]-a[i-1]);
		int j=i-2;
		while(j >= 0 and i-j <= k)
			dp[i]=min(dp[i],dp[j]+abs(a[i]-a[j--]));
	}
	cout << dp[n-1];
}
signed main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin >> t;
    while(t--)
    solve();
    return 0;
}


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

#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif
#if __cplusplus <= 201402L
template <typename T>
T gcd(T a, T b) { return ((a % b == 0) ? b : gcd(b, a % b)); }
template <typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }
#endif
using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;

namespace Problem {
using namespace std;

class Solver {
 public:
  int n;
  vector<LL> w, v, s;
  Solver(LL n) : n(n), w(n), v(n), s(n){};
  bool chmax(LL& a, LL b) {
    bool ret = a < b;
    a = max(a, b);
    return ret;
  }
  void solve() {
    for (int i = 0; i < n; ++i) {
      cin >> w[i] >> s[i] >> v[i];
    }
    vector<int> perm(n);
    iota(perm.begin(), perm.end(), 0);
    sort(perm.begin(), perm.end(), [&](int a, int b) { return s[a] + w[a] < s[b] + w[b]; });
    //perm: ブロックの添字を上に置くべき順に並べた配列
    vector<vector<LL>> dp(n + 1, vector<LL>(20001));
    for (int i = 1; i <= n; ++i) {
      int now = perm[i - 1];
      for (int weight = 0; weight <= s[now]; ++weight) {
        chmax(dp[i][weight + w[now]], dp[i - 1][weight] + v[now]);
      }
      for (int weight = 0; weight <= 20000; ++weight) {
        chmax(dp[i][weight], dp[i - 1][weight]);
      }
    }
    cout << *max_element(dp[n].begin(), dp[n].end()) << endl;
  }
};
}  // namespace Problem

int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(12);
  long long n = 0;
  std::cin >> n;

  Problem::Solver sol(n);
  sol.solve();
  return 0;
}


Measured memory_bytes: 160640
#include <stdio.h>
int main(){
    int n, i,  a[100];

    scanf("%d",&n);
    for(i = 0; i < n; i++){
        scanf("%d",&a[i]);
    }
    for(i = n-1; i >= 0; i--){
        printf("%d",a[i]);
        if(i != 0) printf(" ");
    }
    printf("\n");

    return 0;
}


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

int dp[(int)1e5+5][3];

int main() {
	int n, k, r, s, p; cin >> n >> k;
  cin >> r >> s >> p;
  string t; cin >> t;
  for(int i = 0; i < k; i++) {
    if(t[i] == 'r') dp[i][2] += p;
    else if(t[i] == 's') dp[i][0] += r;
    else if(t[i] == 'p') dp[i][1] += s;
  }
  for(int i = k; i < n;i++) {
    if(t[i] == 'r') {
      dp[i][2] = max(dp[i-k][0], dp[i-k][1]) + p;
      dp[i][1] = max(dp[i-k][2], dp[i-k][0]);
      dp[i][0] = max(dp[i-k][1], dp[i-k][2]);
    }
    else if(t[i] == 's') {
      dp[i][0] = max(dp[i-k][1], dp[i-k][2]) + r;
      dp[i][1] = max(dp[i-k][2], dp[i-k][0]);
      dp[i][2] = max(dp[i-k][0], dp[i-k][1]);
    }
    else if(t[i] == 'p') {
      dp[i][1] = max(dp[i-k][0], dp[i-k][2]) + s;
      dp[i][2] = max(dp[i-k][1], dp[i-k][0]);
      dp[i][0] = max(dp[i-k][1], dp[i-k][2]);
    }
  }
  int ans = 0;
  for(int i = 0; i < k; i++) {
    int ind = ((n-i)/k)*k + i;
    if(ind == n) ind-=k;
    ans += max({dp[ind][1], dp[ind][2], dp[ind][0]});
  }
  cout << ans <<endl;


}


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

int n,m;

const int MAXN = 10010;
int par[MAXN],sz[MAXN];
vector<int> comps,orders,grf[MAXN],rev_grf[MAXN];
bool visited[MAXN];

int findcc(int x){
    return (x==par[x]) ? x : par[x]=findcc(par[x]);
}
bool unite(int a,int b){
    a = findcc(a);
    b = findcc(b);
    if(a==b){return false;}
    if( sz[a]<sz[b]){ swap(a,b);}
    par[b] = a;
    sz[a]+=sz[b];
    return true;
}

void dfs(int u){
    visited[u]=true;
    for(auto nbr: grf[u]){
        if(!visited[nbr]){
            dfs(nbr);
        }
    }
    orders.push_back(u);
}

void dfs2(int u){
    visited[u]=true;
    comps.push_back(u);
    for(auto nbr: rev_grf[u]){
        if(!visited[nbr]){
            dfs2(nbr);
        }
    }
}

void init()
{
    for(int i=0; i<n; i++){
        par[i]=i; sz[i]=1;
    }
    memset(visited,false,sizeof visited);
    for(int i=0; i<n; i++){
        if(!visited[i]){
            dfs(i);
        }
    }
    memset(visited,false,sizeof visited);
    
    while(!orders.empty()){
        int x = orders.back(); orders.pop_back();
        if(!visited[x]){
            comps.clear();
            dfs2(x);
            for(auto c: comps){
                unite(x,c);
            }
        }
    }
}

int main() {
    // freopen("./input.txt","r",stdin);
    // freopen("./output.txt","w",stdout);
    
    cin>>n>>m;
    for(int i=0; i<m; i++){
        int x,y; cin>>x>>y;
        grf[x].push_back(y);
        rev_grf[y].push_back(x);
    }
    init();
    int q; cin>>q;
    while(q--){
        int x,y; cin>>x>>y;
        if( findcc(x)==findcc(y)){
            cout<<"1\n";
        }
        else {
            cout<<"0\n";
        }
    }
    
    
}


Measured memory_bytes: 4700
import java.util.*;

public class Main {
	public static void main(String args[]){
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		for(int i=0; i<n; i++){
			double xa = in.nextDouble();
			double ya = in.nextDouble();
			double ra = in.nextDouble();
			double xb = in.nextDouble();
			double yb = in.nextDouble();
			double rb = in.nextDouble();
			int ans = 0;
			if(Math.sqrt((xa-xb)*(xa-xb)+(ya-yb)*(ya-yb))+rb<ra) ans=2;
			else if(Math.sqrt((xa-xb)*(xa-xb)+(ya-yb)*(ya-yb))+ra<rb) ans=-2;
			else if(Math.sqrt((xa-xb)*(xa-xb)+(ya-yb)*(ya-yb))>ra+rb) ans=0;
			else ans=1;
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

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

const int MAX = 8005;
const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

bitset<2*MAX> dp[2];

int main() {
  // 入力
  string s;
  cin >> s;
  int x, y;
  cin >> x >> y;

  vector<int> v; // sをTで区切ったその間のFの数
  vector<int> t; // sを区切るTの数
  int c = 0;
  if (s[0] == 'T') v.push_back(0);
  for (int i = 0; i < s.size(); ) {
    while (i < s.size() && s[i] == 'F') {
      c++;
      i++;
    }
    if (c > 0) v.push_back(c);
    c = 0;

    while (i < s.size() && s[i] == 'T') {
      c++;
      i++;
    }
    if (c > 0) t.push_back(c);
    c = 0;
  }
  if (t.empty()) t.push_back(0);

  // bitDP
  // 初期値設定
  dp[0].set(v[0]+MAX);
  dp[1].set(MAX);

  int dir = 0; // 0:x軸、1:y軸
  c = 0;
  vector<int> tmp;
  for (int i = 1; i < v.size(); i++) {
    tmp.clear();
    if (t[c] & 1) dir ^= 1;

    for (int j = 0; j < 2 * MAX; j++) if (dp[dir][j]) {
      tmp.push_back(j);
      dp[dir].reset(j);
    }
    for (int j = 0; j < tmp.size(); j++) {
      dp[dir].set(tmp[j]-v[i]);
      dp[dir].set(tmp[j]+v[i]);
    }

    c++;
  }

  // 解答
  cout << (dp[0][x+MAX] && dp[1][y+MAX] ? "Yes" : "No") << endl;

  return 0;
}


Measured memory_bytes: 384