akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

ll N, n,m , M, K,a;

vector<ll> v;
int main(){
    cin >> N;
    for (int i = 0; i < N ; ++i) {cin >> a; v.push_back(a);}
    ll key = 1;
    for(int i = 0; i < N; ++i){
        if(v[i] != key) continue;
        ++key;
    }
  if(key == 1) {cout << -1; return 0;}
  cout << N-key+1;
}


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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(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)

int main(){
	int N; cin >> N;
	vector<LL> A(N),B(N);
	LL sa = 0, sb = 0;
	repp(i,0,N){
		cin >> A[i];
		sa += A[i];
	}
	repp(i,0,N){
		cin >> B[i];
		sb += B[i];
		A[i] -= B[i];
	}
	if(sa < sb) return cout << -1 << endl, 0;
	sort(A.begin(),A.end());
	LL z = 0;
	int c = 0;
	repp(i,0,N) if(A[i] < 0){
		z += -A[i];
		++c;
	}
	repm(i,N-1,-1) if(z > 0){
		z -= A[i];
		++c;
	}
	cout << c << endl;
	return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<sstream>
#include<fstream>
#include<algorithm>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<cctype>
#include<vector>
#include<string>
#include<cmath>
#include<ctime>
#include<stack>
#include<queue>
#include<map>
#include<set>
#define mem(a,b) memset(a,b,sizeof(a))
#define random(a,b) (rand()%(b-a+1)+a)
#define ll long long
#define ull unsigned long long
#define e 2.71828182
#define Pi acos(-1.0)
#define ls(rt) (rt<<1)
#define rs(rt) (rt<<1|1)
#define lowbit(x) (x&(-x))
using namespace std;
int read()
{
	int s=1,x=0;
	char ch=getchar();
	while(!isdigit(ch)) {if(ch=='-') s=-1;ch=getchar();}
	while(isdigit(ch)) {x=10*x+ch-'0';ch=getchar();}
	return x*s;
}
int main()
{
	int N=read();
	string str;cin>>str;
	int len=str.size();
	if(len%2){
		cout<<"No\n";
		return 0;
	}
	string str1,str2;
	str1.assign(str.begin(),str.begin()+len/2);
	str2.assign(str.begin()+len/2,str.end());
	if(str1==str2){
		cout<<"Yes\n";
	}
	else {
		cout<<"No\n";
	}
}


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

int main() {
	int a,b,c;
	while(cin >> a){
		b=a/39;
		c=a-b*39;
		cout << "3C";
		if(c==0){
			cout << "39" <<endl;
		}else if(c<10){
			cout << "0" << c <<endl;
		}else{
			cout << c << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 2988
use std::cmp::min;
use std::cmp::max;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    let mut v2 = Vec::new();
    for _ in 0..n {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).ok();
        let v = s.trim().split_whitespace()
            .map(|e| e.parse().ok().unwrap()).collect();
        v2.push(v);
    }
    v2
}

fn main() {
    let nt: Vec<usize> = read_vec();
    let (n, t) = (nt[0], nt[1]);
    let T: Vec<usize> = read_vec();
    let mut counter = t;
    for i in 1..n {
        counter += T[i] + t - std::cmp::max(T[i-1]+t, T[i]);
    }
    println!("{}", counter);
}

Measured memory_bytes: 10492
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <cmath>
#include <iostream>
using namespace std;
void ThreeOrTwo(){
	int N;
	cin >> N;
	long long count = 0;
	for (size_t i = 0; i < N; i++)
	{
		long long v;
		cin >> v;
		while (v % 2 == 0)
		{
			v /= 2;
			count++;
		}
	}
	cout << count;
}
int main() {
	ThreeOrTwo();
	return 0;
}


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

int main() {
  int a, b;
  cin >> a >> b;
  
  if(a >= 13){
    cout << b << endl;
  }
  else if(6 <= a){
    cout << b / 2 << endl;
  }
  else{
    cout << 0 << endl;
  }
}


Measured memory_bytes: 256
n,m=map(int,input().split())
*x,=map(int,input().split())
x.sort()

a=sorted([(x[i+1]-x[i],i) for i in range(m-1)])[::-1]
s=0
v=0
for i,j in sorted(a[:n-1],key=lambda x:x[1]):
    v+=x[j]-x[s]
    s=j+1
if s<m:
    v+=x[-1]-x[s]
print(v)

Measured memory_bytes: 20380
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int N;
int P[200000];
int main(){
  int i;
  int res = 0;
  int mn = 1073709056;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      rd(P[Lj4PdHRW]);
    }
  }
  for(i=(0);i<(N);i++){
    if(mn > P[i]){
      mn = P[i];
      res++;
    }
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20200119-1

// --- original code ---
// int N, P[2d5];
// {
//   int res = 0, mn = int_inf;
//   rd(N,P(N));
//   rep(i,N) if(mn > P[i]) mn = P[i], res++;
//   wt(res);
// }


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
#define sz(x) ((int)(x).size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MEMSET(v, h) memset((v), h, sizeof(v))
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define pb push_back
#define mp make_pair
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const ll INF = 1LL<<58;
 
int main(){
    ll N; cin >> N;
  	vector<ll> A(N);
    for(ll i = 0; i < N; ++i) cin >> A[i];
  	map<ll,ll> nums;
  	ll sum = 0;
  	nums[sum]++;
  		for (int i = 0; i < N; ++i) {
    		sum += A[i];
    		nums[sum]++;
  		}
  		ll res = 0;
  		for (auto it = nums.begin(); it != nums.end(); ++it) {
    		res += it->second * (it->second - 1) / 2;
  		}
  		cout << res << endl;
    	return 0;
  	}

Measured memory_bytes: 14336
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
int main() {
  ll A,B,N; cin>>A>>B>>N;
  if(N<B)cout<<(A*N)/B - A*(N/B)<<endl;
  else cout<<(A*(B-1))/B - A*((B-1)/B)<<endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <istream>
#include <map>
#include <set>
#include <random>
#include <time.h>
#include <queue>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i) 
const long long INF = 1000000007;
typedef long long ll;
using namespace std;
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; }
int main(){
  int a, b;
  cin >> a >> b;
  cout << (b - a) * (b - a + 1) / 2 - b << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <functional>
#include <list>
#include <utility>
#include <map>
#include <vector>
#include <iomanip>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll, ll> Pll;
typedef pair<int, Pii > P1;

#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define mp1(a,b,c) P1(a,P(b,c))
#define get_arsize(a) (sizeof(a)/sizeof(a[0]))
const ll mod = 1000000007;
const double eps = 1e-10;
const int MAX = 200000;

int main() {
	long double a, b, x;
	cin >> a >> b >> x;
  if (x <= a * a * b / 2.0) {
    cout << std::setprecision(10) << 90.000 - 180 * atan(2.0 * x / a / b / b) / 3.14159265358979 << endl;
  } else {
    cout << std::setprecision(10) << 180 * atan(2.0 * (a * a * b - x) / a / a / a) / 3.14159265358979 << endl;
  }
  return 0;
}

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

const int maxn = 2e5 + 3;
using ll = long long;

int h, w;
struct rg {
    int l, r;
    ll val;
    bool operator<(const rg &u) const {
        return l < u.l || (l == u.l && r < u.r || (l == u.l && r == u.r && val < u.val));
    }
};
std::set<rg> s;
std::set<std::pair<ll, rg>> vs;

void addS(const rg &u) {
    s.insert(u);
    vs.emplace(u.val, u);
}

void delS(const rg &u) {
    s.erase(u);
    vs.erase({u.val, u});
}

ll query(ll ch) {
    if(vs.empty())
        return -1;
    return vs.begin()->second.val + ch;
}

int main() {
    scanf("%d%d", &h, &w);
    addS({1, w, 0});
    for(int i = 1; i <= h; ++i) {
        int u, v;
        scanf("%d%d", &u, &v);
        auto it = s.lower_bound({u, -1});
        auto jt = s.upper_bound({v, w * 2});
        if(it != s.begin() && (it->l > u || it == s.end())) {
            --it;
            if(it->r < u)
                ++it;
        }
        std::vector<rg> toproc(it, jt);
        for(auto &&j : toproc)
            delS(j);
        if(!toproc.empty()) {
            ll rminval = LLONG_MAX;
            for(auto &&j : toproc) {
                rminval = std::min(rminval, j.r <= v ? j.val + v + 1 - j.r : j.val);
            }
            int rb = toproc.back().r;
            if(v + 1 <= w) {
                addS({v + 1, std::max(rb, v + 1), rminval});
            }
            int lb = toproc.front().l;
            if(lb < u) {
                addS({lb, u - 1, toproc.front().val});
            }
        }
        printf("%lld\n", query(i));
    }
    return 0;
}

Measured memory_bytes: 4232
S = gets.chomp.split("")
result = "Yes"
for i in 0..(S.length - 1) do
  if (i + 1).odd? then
    # odd  => except for L
    result = "No" if S[i] == "L"
  else
    # even => except for R
    result = "No" if S[i] == "R"
  end
end

puts result

Measured memory_bytes: 3836
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

typedef long long LL;

int bfs(LL d, LL N, int a, int b, int c) {
    int ret = 0;
    if (d > N) return 0;
    if (a && b && c)ret++;
    ret += bfs(d * 10 + 3, N, 1, b, c);
    ret += bfs(d * 10 + 5, N, a, 1, c);
    ret += bfs(d * 10 + 7, N, a, b, 1);
    return ret;
}

int main() {

    LL N;
    cin >> N;

    LL ans = bfs(0, N, 0, 0, 0);
    cout << ans << endl;

    return 0;
}





























































Measured memory_bytes: 256
//arc071_d.cpp
//Sun Jan 12 19:04:15 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	ll MAX = 1000000007;

	ll x[n];
	ll tate = 0;
	ll baset = 0;
	for (ll i=0;i<n;i++){
		cin >> x[i];
		if (i==0){
			baset = x[0];
		}
		x[i] = x[i] - baset;
		if (i>0){
			tate = (tate + (x[i]-x[i-1])*(n-i)*(i))%MAX;
		}
	}

	ll y[m];
	ll yoko = 0;
	ll basey = 0;
	for (ll i=0;i<m;i++){
		cin >> y[i];
		if (i==0){
			basey = y[0];
		}
		y[i] = y[i] - basey;
		if (i>0){
			yoko = (yoko + (y[i]-y[i-1])*(m-i)*(i))%MAX;
		}
	}

	ll ans = (tate*yoko)%MAX;

	cout << ans << endl;
}

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

#define I_AM_SPEED ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
using ll = long long;
#define double long double

int32_t main() {
	I_AM_SPEED
	int n, m;
	cin >> n >> m;
	int k;
	cin >> k;
	vector<string> a(n);
	ll ans = 0;
	for (auto &x : a)cin >> x;
	for (int i = 0; i < (1 << n); i++) {
		for (int j = 0; j < (1 << m); j++) {
			int c = 0;
			for (int x = 0; x < n; x++) {
				for (int y = 0; y < m; y++) {
					if (!((1 << x) & i) && !((1 << y) & j)) {
						c += (a[x][y] == '#');
					}
				}
			}
			if (c == k) {
				ans += (ll)1;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--) 
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define downque(que) priority_queue<ll> que;
#define upque(que) priority_queue<ll, vector<int>, greater<int>> que;
typedef long long ll;
typedef vector<vector<int>> Matrix;
const int MOD = 1e9 + 7;
const int MAX = 1e7;
const int INF = numeric_limits<int>::max();
//16:13

int main(){
  int a,b,res=0; cin>>a>>b;

  FOR(i,a,b+1){
    string s=to_string(i);
    if(s.substr(0,2)==s.substr(4,1)+s.substr(3,1))res++;
  }
cout<<res<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;

int main()
{
	#ifndef ONLINE_JUDGE
	freopen(".in.txt", "r", stdin);
	freopen(".out.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string ans = "";
	map<ll, char> mapp;
	mapp[0] = 'z';
	for(int i = 1; i < 26; i++) mapp[i] = i + 'a' - 1;
	ll n; cin >> n;
	while(n)
	{
		ans = mapp[n % 26] + ans;
		if(!(n % 26))
		{
			n /= 26;
			n--;
		}
		else n /= 26;
	}
	cout << ans;

	return 0;
}

Measured memory_bytes: 3656
var
 s:ansistring;
 i,x,y,z,k:longint;
begin
 readln(s);
 for i:=1 to length(s) do
  begin
   if s[i]='W' then x:=1;
   if s[i]='N' then z:=1;
   if s[i]='E' then y:=1;
   if s[i]='S' then k:=1;
  end;
 if (x=1) and (y=1) and (z=1) and (k=1) then writeln('Yes') else
  if (x=1) and (y=1) and (z=0) and (k=0) then writeln('Yes') else
   if (x=0) and (y=0) and (z=1) and (k=1) then writeln('Yes') else
    if (x=0) and (y=0) and (z=0) and (k=0) then writeln('Yes') else
     writeln('No');
end.

Measured memory_bytes: 128
import java.util.*; 
import java.lang.*; 

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();
                int D = scan.nextInt();
                
                while(A>0 || C>0){
                    C = C - B;
                    if(C<=0){
                        System.out.println("Yes");
                        System.exit(0);
                    }
                    A = A - D;
                    if(A<=0){
                        System.out.println("No");
                        System.exit(0);
                    }
                }
                
	}
}

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

int main()
{
    int i=0,j,x=0,n,id=3070,sum=7,bin[33],y=8;
    cin>>n;
    int ac=0,wa=0,tle=0,re=0;
    while(n--){
        string s;
        cin>>s;
        if(s=="AC") ac++;
        if(s=="WA") wa++;
        if(s=="RE") re++;
        if(s=="TLE") tle++;
    }
    printf("AC x %d\n",ac);
    printf("WA x %d\n",wa);
    printf("TLE x %d\n",tle);
    printf("RE x %d\n",re);

    return 0;
}


Measured memory_bytes: 3716
n=int(input())
a=[int(input()) for i in range(n)]

maxa = max(a[0],a[1])
mina = min(a[0],a[1])

for i in range(2,n):
    if a[i] >= maxa:
        mina = maxa
        maxa = a[i]
    elif a[i] >mina:
        mina = a[i]

for i in range(n):
    if a[i] == maxa:
        print(mina)
    else:
        print(maxa)

Measured memory_bytes: 12532
process.stdin.resume();
process.stdin.setEncoding('utf8');

var lines = []
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

reader.on('line', (line) => {
  lines.push(line);
});

reader.on('close', () => {
 var abcd = lines[0].split(' ');
 var a = Number(abcd[0]);
 var b = Number(abcd[1]);
 var c = Number(abcd[2]);
 var d = Number(abcd[3]);

 while(true){
   c = c - b;
   if(c <= 0){
     console.log("Yes");
     break;
   }
   a = a - d;
   if(a <= 0){
     console.log("No");
     break;
   }
 }
});

Measured memory_bytes: 30068
h,w = map(int,input().split(' '))
S = []
i = 0
while i < h:
    S.append(input())
    i += 1
ans = ''
p = 0
while p < h:
    q = 0
    while q < w:
        s0 = S[p][q]
        if s0 == '#':
            ans += '#'
        else:
            count = 0
            if p-1 >= 0:
                if S[p-1][q] == '#':
                    count += 1
                if q-1 >= 0 and S[p-1][q-1] == '#':
                    count += 1
                if q+1 < w and S[p-1][q+1] == '#':
                    count += 1
            if q-1 >= 0 and S[p][q-1] == '#':
                count += 1
            if q+1 < w and S[p][q+1] == '#':
                count += 1
            if p+1 < h:
                if S[p+1][q] == '#':
                    count += 1
                if q-1 >= 0 and S[p+1][q-1] == '#':
                    count += 1
                if q+1 < w and S[p+1][q+1] == '#':
                    count += 1
            ans += str(count)
        q += 1
    ans += '\n'
    p += 1
print(ans)
                

Measured memory_bytes: 3064
import Control.Monad
import Data.Maybe
import Text.Printf
import qualified Data.ByteString.Char8 as C

parseInt :: C.ByteString -> Int
parseInt = fst . fromJust . C.readInt

toInt :: C.ByteString -> Int
toInt s
  | s == C.pack "BC" = 1
  | s == C.pack "AC" = 2
  | s == C.pack "AB" = 3

solve :: ([String], Int, Int, Int) -> [Int] -> Maybe [String]
solve (xs, _, _, _) [] = Just xs
solve (_, _, 0, 0) (1 : _) = Nothing
solve (_, 0, _, 0) (2 : _) = Nothing
solve (_, 0, 0, _) (3 : _) = Nothing
solve (xs, 0, 1, 1) (1 : p : ps) =
  case p of
    2 -> solve ("C" : xs, 0, 0, 2) (p : ps)
    _ -> solve ("B" : xs, 0, 2, 0) (p : ps)
solve (xs, 1, 0, 1) (2 : p : ps) =
  case p of
    1 -> solve ("C" : xs, 0, 0, 2) (p : ps)
    _ -> solve ("A" : xs, 2, 0, 0) (p : ps)
solve (xs, 1, 1, 0) (3 : p : ps) =
  case p of
    1 -> solve ("B" : xs, 0, 2, 0) (p : ps)
    _ -> solve ("A" : xs, 2, 0, 0) (p : ps)
solve (xs, a, b, c) (1 : ps)
  | b >= c = solve ("C" : xs, a, b - 1, c + 1) ps
  | otherwise = solve ("B" : xs, a, b + 1, c - 1) ps
solve (xs, a, b, c) (2 : ps)
  | a >= c = solve ("C" : xs, a - 1, b, c + 1) ps
  | otherwise = solve ("A" : xs, a + 1, b, c - 1) ps
solve (xs, a, b, c) (3 : ps)
  | a >= b = solve ("B" : xs, a - 1, b + 1, c) ps
  | otherwise = solve ("A" : xs, a + 1, b - 1, c) ps

main :: IO ()
main = do
  [n, a, b, c] <- map parseInt . C.words <$> C.getLine
  ps <- map toInt <$> replicateM n C.getLine
  putStr $ case solve ([], a, b, c) ps of
    Nothing -> "No\n"
    Just as -> "Yes\n" ++ unlines (reverse as)

Measured memory_bytes: 25852
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}
ll gcd(ll(a), ll(b)) {
	ll c = a;
	while (a % b != 0) {
		c = a % b;
		a = b;
		b = c;
	}
	return b;
}




int main() {
	ll N,an=0;
	cin >> N;
	vector<ll> A(100000);
	rep(i, N) {
		ll a;
		cin >> a;
		A.at(a)++;
	
	}
	ll b=0;
	rep(i, 100000) {
		if (A.at(i) > 0) {
			an++;
		}
		if (A.at(i) > 1&&A.at(i)%2==0) {
			b++;
		}

	}
	cout << an - (b % 2) << endl;


}


Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>

using namespace std;

int main() {
    int a,b,r,d; 
    double f;
    cin >>a>>b;
    d= (double)a/b;
    r = a%b;
    f= (double)a/b;
  
    cout<< d<<" "<<r<<" "<< fixed<<setprecision(5)<<f<<endl;
}


Measured memory_bytes: 3244
N = int(input())
l = list(map(int, input().split()))
l_gcd = [None] * N
l_gcd[0] = l[0]


def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)


for i in range(1, N):
    l_gcd[i] = gcd(l_gcd[i-1], l[i])

r_gcd = [None] * N
r_gcd[-1] = l[-1]

for i in range(2, N+1):
    r_gcd[-i] = gcd(r_gcd[-i+1], l[-i])

max_gcd = max(l_gcd[-2], r_gcd[1])

for i in range(1, N-1):
    max_gcd = max(max_gcd, gcd(l_gcd[i-1], r_gcd[i+1]))

print(max_gcd)

Measured memory_bytes: 66412
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>
#include<functional>
#include<deque>

using namespace std;
typedef long long int ll;

#define C cout<<
#define E <<endl

ll n,m,a,b,c,x,y,z,aa[200010],ab[200010],ac[1010][1010];
bool r,ra,rb,rc;
string s,sa,sb,sc;
char ca,cb,cc,cd[1010][1010];
vector<ll> va,vb,vc;

int gcd(ll tara,ll tarb){ //最大公約数
    ll am=1;
    while(am){
        am=tara%tarb;
        tara=tarb;
        tarb=am;
    }
    return tara;
}

int lcm(ll tara,ll tarb){ //最小公倍数
    return tarb/gcd(tara,tarb)*tara;
}



int main(){
    cin>>a>>b>>c;
    x=gcd(a,b);
    for(int i=1;i<=x;i++){
        if(x%i==0)va.push_back(i);
    }
    sort(va.begin(),va.end(),greater<ll>());
    //for(auto it:va)C it E;
    C va[c-1] E;
    
    
}

Measured memory_bytes: 256
#ifdef Prateek
  #include "Prateek.h"
#else
  #include <bits/stdc++.h>
  using namespace std;
  #define debug(...) 42
#endif
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
const int MOD = 1e9+7, N = 1e5 + 10; 

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int n,k;
   cin >> n >> k;
   vector<int> A(n);
   f(i,0,n){
      cin >> A[i];
   }

   auto check = [&](int v){
      int R = 0;
      f(i,0,n){
         R += (A[i]-1)/v;
      }
      return R <= k;
   };


   int ans = 1e10;
   int l = 1, h = 1e10;
   while(l <= h){
      int mid = (l+h)/2;
      // debug(l,h);
      if(check(mid)){
         h = mid-1;
         ans = mid;
      }else{
         l = mid+1;
      }
   }
   cout << ans << '\n';
   return 0;
} 

Measured memory_bytes: 4780
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <cmath>
#include <map>
#include <iomanip>
#include <unordered_map>

using namespace std;
typedef long long  ll;

int main()
{
	ll N;
	cin >> N;
	vector<string> s(N);
	// MARCH
	vector<ll> name(5, 0);
	for (ll i = 0; i < N; i++)
	{
		cin >> s[i];
		switch (s[i][0])
		{
		case 'M':
			name[0]++;
			break;
		case 'A':
			name[1]++;
			break;
		case 'R':
			name[2]++;
			break;
		case 'C':
			name[3]++;
			break;
		case 'H':
			name[4]++;
			break;
		default:
			break;
		}
	}
	ll ans = 0;
	for (ll i = 0; i < 5; i++)
	{
		for (ll j = i + 1; j < 5; j++)
		{
			for (ll k = j + 1; k < 5; k++)
			{
				ans += name[i] * name[j] * name[k];
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6144
#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
ll dp[20][20]; int d[20],cnt;
//tag维护前缀是否小于，ok维护后缀是否小于。维护二者不一样。
ll get(int bg,int l,int r,int tag,bool ok)
{
    if(r>l) return !tag||(tag&&ok);
    if(!tag&&dp[bg][l]) return dp[bg][l];
    int lim=tag?d[l]:9; ll res=0;
    rep(i,0,lim){
        if(bg==l&&i==0) continue;
        bool g=ok;
        if(ok) g=i<=d[r];
        else g=i<d[r];
        res+=get(bg,l-1,r+1,tag&&(i==lim),g);
    }
    return tag?res:dp[bg][l]=res;
}
ll cal(ll x)
{
    if(x<0) return 0LL;if(x==0) return 1LL;
    ll res=1; cnt=0;
    while(x) d[++cnt]=x%10,x/=10;
    rep(i,1,cnt) res+=get(i,i,1,i==cnt,true);
    return res;
}
int main()
{
    int T,C=0;ll L,R;
    scanf("%lld%lld",&L,&R); if(L>R) swap(L,R);
    printf("%lld\n",cal(R)-cal(L-1));
    return 0;
}


Measured memory_bytes: 256
n = gets.chomp.to_i
a = gets.chomp.to_i
b = gets.chomp.to_i
c = gets.chomp.to_i
d = gets.chomp.to_i
e = gets.chomp.to_i
min = [a,b,c,d,e].min
puts (1.0*n/min).ceil+4


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,cnt=0,i,j,k,l,cnt1=0;
    cin>>n;
    vector<int>v;
    for(i=0; i<n; i++)
    {
        cin>>k;
        //v.push_back(k);
        if(k%2==0)
        {
            cnt++;
            v.push_back(k);
            //ar[i]=k;
        }
    }
    sort(v.begin(),v.end());
    for(i=0;i!=v.size(); i++)
    {
        if(v[i]%3==0||v[i]%5==0)
        {
            cnt1++;
        }
    }
    if(cnt1==cnt)
    {
        cout<<"APPROVED"<<endl;
    }
    else
    {
        cout<<"DENIED"<<endl;
    }
    return 0;
}


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

int main () {
  char s1[10], s2[10], s3[10];
  
  std::cin >> s1 >> s2 >> s3;
  
  putchar(toupper(s1[0]));
  putchar(toupper(s2[0]));
  putchar(toupper(s3[0]));
}

Measured memory_bytes: 3632
#include <stdio.h>
#include <math.h>
#define N 10000
int main()
{
  int x[N],n,i=0,j,count=0;
  scanf("%d",&n);
  while(1)
    {
  scanf("%d",&x[i]);
  if(i==n-1) break;
  i++;
    }
  for(i=0;i<n;i++)
    {
      if(x[i]==1) continue;
      if(x[i]==2)
	{
	  count++;
	  continue;
	}
      
      if(x[i]%2==0) continue;
      if(x[i]>2)
	{
	  for(j=3;j<=sqrt(x[i]);j=j+2)
	    {
	      if(x[i]%j==0)
		{
		  count--;
		  break;
		}
	    }
	  count++;
	}
    }
  printf("%d\n",count);
  return 0;
}



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


#define ll long long
#define ull unsigned ll
#define vi vector <int>
#define ii pair <int, int>
#define vii vector <ii>
#define vll vector <ll>
#define vull vector <ull>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define INF (int)1e9
#define EPS 1e-9
#define pb push_back
#define PI acos(-1.0)
#define DEBUG 0


int main ()

{
    fast;
    
    int n, m, sum = 0;
    cin >> n >> m;
    
    vi item(n);
    
    for (int u=0; u<n; u++)
    {
    	cin >> item[u];
    	sum += item[u];
    }
    
    int minimum = sum / (4*m);
    int count = 0;
    
    if (sum % (4*m) != 0)
    minimum++;
    
    sort (item.rbegin(), item.rend());
    
    for (int y=0; y<n; y++)
    {
    	if (item[y] >= minimum)
    	count++;
    	else break;
    }
    
    if (count >= m) cout << "Yes" << endl;
    else cout << "No" << endl;
    	
    	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int a,b;
int acard[5000],bcard[5000];
int main(void){
	scanf("%d %d",&a,&b);
	int i,j;
	for(i=0;i<5000;i++){
		acard[i]=1001;
		bcard[i]=1001;
	}
	for(i=0;i<a;i++){
		scanf("%d",&acard[i]);
	}
	for(i=0;i<b;i++){
		scanf("%d",&bcard[i]);
	}
	int max=0;
	for(i=0;i<b;i++){
		int cnt=0,k=i;
		/*if(i>0){
			bcard[i]=1001;
		}*/
		for(j=0;j<a;j++){
			if(bcard[k]==acard[j]){
				cnt++;
				k++;
			}
			//printf("%d %d %d\n",bcard[k],acard[j],cnt);
		}
		if(cnt>max){
			max=cnt;
		}
	}
	printf("%d\n",max);
	return 0;
}

Measured memory_bytes: 1064
#include <iostream>
using namespace std;
 
int x,y;
 
int main(){
	cin >> x >> y;
	if(x==y) cout << "Yes" << endl;
	else if(x==2||y==2) cout << "No" << endl;
	else if(y==1||y==3||y==5||y==7||y==8||y==10||y==12){
		if(x==4||x==6||x==9||x==11) cout << "No" << endl;
		else cout << "Yes" << endl;
	}else if(x==1||x==3||x==5||x==7||x==8||x==10||x==12){
		if(y==4||y==6||y==9||y==11) cout << "No" << endl;
		else cout << "Yes" << endl;
	}else cout << "Yes" << endl;
	return 0;
}


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

template <int mod = (int)(998244353)>
struct ModInt {
  int x;
  constexpr ModInt() : x(0) {}
  constexpr ModInt(int64_t y)
      : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
  constexpr ModInt &operator+=(const ModInt &p) noexcept {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }
  constexpr ModInt &operator-=(const ModInt &p) noexcept {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }
  constexpr ModInt &operator*=(const ModInt &p) noexcept {
    x = (int)(1LL * x * p.x % mod);
    return *this;
  }
  constexpr ModInt &operator/=(const ModInt &p) noexcept {
    *this *= p.inverse();
    return *this;
  }
  constexpr ModInt operator-() const { return ModInt(-x); }
  constexpr ModInt operator+(const ModInt &p) const
      noexcept {
    return ModInt(*this) += p;
  }
  constexpr ModInt operator-(const ModInt &p) const
      noexcept {
    return ModInt(*this) -= p;
  }
  constexpr ModInt operator*(const ModInt &p) const
      noexcept {
    return ModInt(*this) *= p;
  }
  constexpr ModInt operator/(const ModInt &p) const
      noexcept {
    return ModInt(*this) /= p;
  }
  constexpr bool operator==(const ModInt &p) const
      noexcept {
    return x == p.x;
  }
  constexpr bool operator!=(const ModInt &p) const
      noexcept {
    return x != p.x;
  }
  constexpr ModInt inverse() const noexcept {
    int a = x, b = mod, u = 1, v = 0, t = 0;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }
  constexpr ModInt pow(int64_t n) const {
    ModInt res(1), mul(x);
    while(n) {
      if(n & 1) res *= mul;
      mul *= mul;
      n >>= 1;
    }
    return res;
  }
  friend constexpr ostream &operator<<(
      ostream &os, const ModInt &p) noexcept {
    return os << p.x;
  }
  friend constexpr istream &operator>>(istream &is,
                                       ModInt &a) noexcept {
    int64_t t = 0;
    is >> t;
    a = ModInt<mod>(t);
    return (is);
  }
  constexpr int get_mod() { return mod; }
};

long long n, x;
vector<vector<vector<ModInt<>>>> dp;

ModInt<> solve();

int main() {
  cin >> n >> x;
  cout << solve() << endl;
  return 0;
}

ModInt<> solve() {
  dp.assign(2, vector<vector<ModInt<>>>(
                   n + 1, vector<ModInt<>>(512, 0)));
  for(int i = 0; i <= n; ++i) dp[0][i][0] = 1;
  for(int i = 1; i <= x; ++i) {
    for(int j = 0; j <= n; ++j)
      for(int k = 0; k < 512; ++k) {
        dp[i % 2][j][k] = dp[(i + 1) % 2][j][k];
        if(j != 0)
          dp[i % 2][j][k] += dp[(i + 1) % 2][j - 1][k ^ i];
      }
    for(int j = 2; j <= n; ++j)
      for(int k = 0; k < 512; ++k)
        dp[i % 2][j][k] += dp[i % 2][j - 2][k];
  }
  return dp[x % 2][n][x];
}



Measured memory_bytes: 6020
#include <iostream>
using namespace std;
int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if(a <= b && b <= c)
        cout << a << " " << b << " " << c << endl;
    else if (a <= c && c <= b)
        cout << a << " " << c << " " << b << endl;
    else if (b <= a && a <= c)
        cout << b << " " << a << " " << c << endl;
    else if (b <= c && c <= a)
        cout << b << " " << c << " " << a << endl;
    else if (c <= a && c <= b && b>=a)
        cout << c << " " << a << " " << b << endl;
    else
        cout << c << " " << b << " " << a << endl;
        
return 0;
}



Measured memory_bytes: 3112
def return_biggest_sum(numbers):
    """入力 [int, int, int]
    """
    numbers.sort()
    numbers.reverse() # 降順に並び替え
    return int(str(numbers[0])+str(numbers[1])) + numbers[2]

line = input()
numbers_list = list(map(int, line.split()))
print(return_biggest_sum(numbers_list))

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

using namespace std;

int f[500005][5];

int main(int argc, char *argv[]) {
  int n;
  string s;
  cin >> n >> s;
  s += '0';
  vector<int> a;
  for (int i = 0, cnt = 0; i < s.size(); i++) {
    if (s[i] == '1') {
      cnt++;
    } else {
      a.push_back(cnt);
      cnt = 0;
    }
  }
  for (int i = 1; i < a.size(); i++) {
    f[i][0] = max(max(f[i - 1][0], f[i - 1][3]), max(f[i - 1][1], f[i - 1][2]));
    if (a[i] && a[i - 1]) {
      f[i][1] = max(f[i - 1][0] + a[i - 1], f[i - 1][1] + a[i - 1] - 1);
      f[i][2] = f[i - 1][0] + a[i] - 1;
      f[i][3] = f[i - 1][0] + a[i];
      if (a[i - 1] >= 2) {
        f[i][2] = max(f[i][2], max(f[i - 1][1] + a[i] - 1, f[i - 1][2] + a[i] - 1));
        f[i][3] = max(f[i][3], max(f[i - 1][1] + a[i], f[i - 1][2] + a[i]));
      }
    }
  }
  int mx = 0;
  for (int i = 0; i < 4; i++) {
    mx = max(mx, f[a.size() - 1][i]);
  }
  cout << mx << endl;
  return 0;
}


Measured memory_bytes: 12664
#include<stdio.h>
#include<math.h>

typedef struct{
	double x;
	double y;
}POINT;

double dot(POINT a,POINT b){//??????
	return a.x*b.x + a.y*b.y;
}
double cross(POINT a,POINT b){//??????
	//return (a.x*a.x + a.y*a.y)*(b.x*b.x + b.y*b.y) - dot(a,b)*dot(a,b);
    return a.x*b.y - a.y*b.x;
}
POINT make_vec(POINT a,POINT b){//a->b
	POINT ans;
	ans.x = b.x-a.x;
	ans.y = b.y-a.y;
	return ans;
}

int main(){
	int i,j,k,l,m,n;
	double w,e,r,t,y;
	double rad;
	POINT g[101];//n
	POINT q[10000];//m
	int ans[10000] = {0};

	scanf("%d",&n);
	for(i = 0;i < n;i++){
		scanf("%lf%lf",&g[i].x,&g[i].y);
	}
	g[n] = g[0];
	scanf("%d",&m);
	for(i = 0;i < m;i++){
		scanf("%lf%lf",&q[i].x,&q[i].y);
		for(j = 0;j < n;j++){
			if(g[j].x == q[i].x && g[j].y == q[i].y){
				ans[i] = 1;
			}
		}
	}

	for(j = 0;j < m;j++){
		if(ans[j] == 1)continue;
rad =0;
		for(i = 0;i < n;i++){
			w = atan2(cross(
				make_vec(q[j],g[i]),
				make_vec(q[j],g[i+1]))
				,dot(
				make_vec(q[j],g[i]),
				make_vec(q[j],g[i+1]))
				);//q[j],g[i],g[i+1]
			rad += w;
//printf("%lf\n",w);
			if(fabs(w - 3.1415926535)<=0.000001 || fabs(w +3.1415926535)<=0.000001)ans[j] = 1;
		}
//printf("\n%lf\n\n",rad);
		if(ans[j] != 1){
			if(fabs(rad - 3.1415926535 * 2)<=0.000001){//2??
				ans[j] = 2;//in!
			}
		}
	}
	for(i = 0;i < m;i++)printf("%d\n",ans[i]);
	return 0;
}

Measured memory_bytes: 800
#include <iostream>
#include <string>

#define ll long long

using namespace std;


int main(){

    ll N, AC=0, WA=0, TLE=0, RE=0;
    string caso;
    

    cin >> N;


    for (int i=0; i<N; i++){
        cin >> caso;
        if(caso=="AC")
            AC++;
        else if(caso=="WA")
            WA++;
        else if(caso=="TLE")
            TLE++;
        else if(caso=="RE")
            RE++;
    }


    cout << "AC x " << AC << "\n";
    cout << "WA x " << WA << "\n";
    cout << "TLE x " << TLE << "\n";
    cout << "RE x " << RE << "\n";



    return 0;
}

Measured memory_bytes: 3620
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}
signed main(){
  init_io();
  ll n,x,ans=0,tmp;
  cin >> n >> x;
  vector<ll> a(n);
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  if(a[0]>x){
    ans += a[0]-x;
    a[0] = x;
  }
  for(int i=1;i<n;i++){
    tmp = a[i]+a[i-1];
    if(tmp>x){
      ans += tmp-x;
      a[i] -= tmp-x;
    }
  }
  cout << ans << endl;
}


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

using namespace std;

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

	int ans = 0;

	for (size_t i = 0; i < S.size(); i++) {
		if (S[i] == '+') {
			ans++;
		} else {
			ans--;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
import collections
a=int(input())
b=[input() for i in range(a)]

c=collections.Counter(b)
n,m=zip(*c.most_common())
n=list(n)
m=list(m)
result=[0]*4
for i in range(len(n)):
    if n[i]=='AC':
        result[0]=m[i]
    if n[i]=='WA':
        result[1]=m[i]
    if n[i]=='TLE':
        result[2]=m[i]
    if n[i]=='RE':
        result[3]=m[i]
    
print('AC x',result[0])
print('WA x',result[1])
print('TLE x',result[2])
print('RE x',result[3])


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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int a[3];
  cin >> a[0] >> a[1] >> a[2];
  sort(a, a + 3);
  cout << a[0] + a[1] << endl;
  return 0;
}


Measured memory_bytes: 256
N=gets.to_i
tmp = $<.read.split.map(&:to_i)
abs=tmp[0..(N-1)*2-1].each_slice(2)
cs=tmp[(N-1)*2..-1].sort
sum = cs[0..-2].inject(&:+)

tree = Array.new(N+1) { [] }

abs.each do |a,b|
  tree[a] << b
  tree[b] << a
end

q = tree[1]
ret = Array.new(N+1) { 0 }
ret[1] = cs.pop
while !q.empty?
  e=q.shift
  if ret[e] == 0
    ret[e]=cs.pop
    q+=tree[e]
  end
end

puts sum
puts ret[1..-1].join(' ')


Measured memory_bytes: 77620
from collections import defaultdict
n=int(input())
A=list(map(int,input().split()))
AD=defaultdict(int)
for a in A:
    AD[a]+=1
sumA=sum(A)
q=int(input())
for i in range(q):
    b,c=map(int,input().split())
    sumA=sumA+(c-b)*AD[b]
    AD[c]+=AD[b]
    AD[b]=0
    print(sumA)

Measured memory_bytes: 24096
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <map>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;

using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vvvll = vector<vector<vector<ll>>>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vvvd = vector<vector<vector<double>>>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pint = pair<int, int>;
using Graph = vvi;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

bool cmp(pint a, pint b) {return a.second < b.second;}
void YN(bool flg) {cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg) {cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg) {cout<<(flg?"yes":"no")<<'\n';}

int main(){
    int n, m;
    cin >> n >> m;
    vi s(n);
    rep(i, m) {
        int k;
        cin >> k;
        rep(j, k) {
            int x;
            cin >> x;
            --x;
            s[x] |= 1 << i;
        }
    }
    int p = 0;
    rep(i, m) {
        int x;
        cin >> x;
        p |= x << i;
    }

    int ans = 0;
    for(int bit = 0; bit < (1 << n); bit++) {
        int t = 0;
        for(int i = 0; i < n; i++) {
            if(bit >> i & 1) {
                t ^= s[i];
            }
        }
        if(t == p) ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
const int maxn=1e5+10;
int id1[maxn],id2[maxn],p[maxn];
struct point{
	int l,r;
}a[maxn];
bool cmpr(const int &A,const int &B){
	return a[A].r<a[B].r;
}
bool cmpl(const int &A,const int &B){
	return a[A].l>a[B].l;
}
int main(){
	int n=read();
	REP(i,1,n) a[i].l=read(),a[i].r=read(),id1[i]=id2[i]=i;
	sort(id1+1,id1+n+1,cmpr);
	sort(id2+1,id2+n+1,cmpl);
	ll tmp=0,ans=0;
	int flag=0,i=1,j=1,lst=0;
	REP(k,1,n){
		while(i<=n && p[id1[i]]) ++i;
		while(j<=n && p[id2[j]]) ++j;
		if(flag){
			if(a[id1[i]].r<lst) p[id1[i]]=1,tmp+=lst-a[id1[i]].r,lst=a[id1[i]].r;
		}
		else{
			if(a[id2[j]].l>lst) p[id2[j]]=1,tmp+=a[id2[j]].l-lst,lst=a[id2[j]].l;
		}
		flag^=1;
	}
	tmp+=abs(lst);ans=max(ans,tmp);
	tmp=0;
	flag=1,i=1,j=1,lst=0;
	memset(p,0,sizeof(p));
	REP(k,1,n){
		while(i<=n && p[id1[i]]) ++i;
		while(j<=n && p[id2[j]]) ++j;
		if(flag){
			if(a[id1[i]].r<lst) p[id1[i]]=1,tmp+=lst-a[id1[i]].r,lst=a[id1[i]].r;
		}
		else{
			if(a[id2[j]].l>lst) p[id2[j]]=1,tmp+=a[id2[j]].l-lst,lst=a[id2[j]].l;
		}
		flag^=1;
	}
	tmp+=abs(lst);ans=max(ans,tmp);
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 2304
#include<bits/stdc++.h>
using namespace std;
int main(){
  int X,Y;
  cin>>X>>Y;
  if(((4*X-Y)%2==0&&(4*X-Y)/2<=X)&&0<=(4*X-Y)/2) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 3632
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
      	int[] inputNum = new int[6];
 
		for(int i = 0 ; i < inputNum.length; i++) {
			inputNum[i] = sc.nextInt();
          //コードテスト用
          	//System.out.println(inputNum[i]);
		}
      
    	
      	int min = inputNum[0];
      	int max = inputNum[0];
       	for(int i = 1 ; i < inputNum.length-1; i++) {
			if(inputNum[i] <= min){
            	min = inputNum[i];
            }
            if(inputNum[i] >= max){
            	max = inputNum[i];
            }
		}
      
      	//コードテスト用
      	//int distance = max-min;
      	//System.out.println(distance);
      
      	if(max-min > inputNum[5]){
        	System.out.print(":("); 
        }else{
          	System.out.print("Yay!");
        }
    }
}

Measured memory_bytes: 25428
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main(){
long long int N; 
 cin >> N; 
long long int A[114514], B[114514], C[114514]; 
for(int i = 0; i < N; i++){ 
cin >> A[i]; 
}
for(int i = 0; i < N; i++){ 
cin >> B[i]; 
}
for(int i = 0; i < N; i++){ 
cin >> C[i]; 
}
sort(A, A + N);
sort(B, B + N);
sort(C, C + N);
 
long long int count = 0; 
for(int i = 0; i < N; i++){
  long long int P = lower_bound(A, A+N, B[i]) - A; 
  long long int Q = upper_bound(C, C+N, B[i]) - C; 
  count += P * (N - Q); 
}
cout << count << endl; 
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
/*
struct Edge
{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
*/
using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    if (A + B > C + D)
        cout << "Left" << endl;
    else if (A + B == C + D)
        cout << "Balanced" << endl;
    else
        cout << "Right" << endl;
    return 0;
}


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

int main(){
  int n,two=0,four=0,input;

  cin >> n;

  for(int i = 0; i<n; i++){
    cin >> input;
    if(input % 4 == 0){
      four++;
     }
    else if(input % 2 == 0){
      two++;
     }
  }

  if( (four + two/2 ) >= n/2){
     cout << "Yes" << endl;
  }
 else {
     cout << "No" << endl;
  }

  return 0;

}  

Measured memory_bytes: 256
N, K = map(int, input().split())
cnt = 0

if K > 0:
    for b in range(K+1, N+1):
        u = ((N - b)//b) + 1
        v =  (N - K)//b

        cnt += (b-K)*u + (v-u+1)*(-b*(u+v)+2*N-2*K+2)/2
else:
    for b in range(K+1, N+1):
        u = ((N - b)//b) + 1
        v =  (N - K)//b

        cnt += (b-K)*u + (v-u+1)*(-b*(u+v)+2*N-2*K+2)/2 - 1

print(int(cnt))





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

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

	if (a < 1200) {
		cout << "ABC" << endl;
	}
	else if (1200 <= a&& a< 2800) {
		cout << "ARC" << endl;
	}
	else {
		cout << "AGC" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main() {
    std::ios::sync_with_stdio(false);
    int64_t n, k;
    std::cin >> n >> k;
    int64_t sum = 0;
    if(k ==0){
        std::cout << n *n << '\n';
        return 0;
    }
    for (int b = k+1; b <= n; ++b) {
        long long d = n-k;
        d /= b;
        long long l = k, r = b;
        while(l+1<r){
            long long m = (l+r)/2;
            if(m+d*b <= n){
                l = m;
            }
            else
                r = m;
        }
        long long x = l-k+1;
        long long y = b- l - 1;
        d++;
        sum += x * d + y * (d-1);
//        std::cerr << b << ':' << x << ',' << y << "::"<< d << ',' << sum << std::endl;
    }
    std::cout << sum << std::endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
const int INF = 1000000;

int map[101][101][2];//a, b, cost, time;
int d[101];//始点からの最短距離
bool used[101];//使われたかのフラグ
int V;//頂点数

int dijkstra(int start, int end, bool flag){
	std::fill(d, d + V + 1, INF);
	std::fill(used, used + V + 1, false);
	d[start] = 0;

	while(1){
		int v = -1;
		for(int u=1;u<=V;u++){
			if(!used[u] && (v == -1 || d[u] < d[v]))v = u;
		}
		
		if(v == -1)break;
		
		used[v] = true;

		for(int u=1;u<=V;u++){
			d[u] = std::min(d[u], d[v] + map[v][u][flag]);
		}
	}

	return d[end];
}

int main(){
	int n, m;//track, station
	while(std::cin >> n >> m, n){
		V = m;

		for(int i=0;i<101;i++){
			for(int j=0;j<101;j++){
				map[i][j][0] = (map[i][j][1] = INF);
			}
		}

		for(int i=n;i;i--){
			int a, b, cost, time;
			std::cin >> a >> b >> cost >> time;
			map[a][b][0] = cost;
			map[a][b][1] = time;
			map[b][a][0] = cost;
			map[b][a][1] = time;
		}

		int k;//取り合わせ数
		std::cin >> k;
		while(k--){
			int p, q, r;
			std::cin >> p >> q >> r;//start, end, bool
			std::cout << dijkstra(p, q, r) << '\n';
		}
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int a[110],b,c,d,e,ans;
int main()
{
	scanf("%d%d%d%d",&b,&c,&d,&e);
	for(int i = b + 1;i <= c;i++)a[i] = 1;
	for(int i = d + 1;i <= e;i++)if(a[i])ans++;
	 printf("%d\n",ans);
}

Measured memory_bytes: 256