akhauriyash/Code-Regression huggingface dataset:
mod io{
    use std::io::*;
    pub fn read<T: ::std::str::FromStr>()->T{
        let stdin=stdin();
        let ret=stdin.lock().bytes().map(|c|c.unwrap()as char)
        .skip_while(|c|c.is_whitespace())
        .take_while(|c|!c.is_whitespace())
        .collect::<String>().parse().ok().unwrap();
        ret
    }
}
use io::read;
fn main(){
    let h:usize=read();
    let w:usize=read();
    let s=(0..h).map(|_|read::<String>().chars().collect::<Vec<char>>()).collect::<Vec<Vec<char>>>();
    let mut a=vec![];
    for i in 0..h{
        let mut f=0;
        for j in 0..w{
            if s[i][j]=='#'{f+=1}
        }
        a.push(f>0)
    };
    let mut b=vec![];
    for j in 0..w{
        let mut f=0;
        for i in 0..h{
            if s[i][j]=='#'{f+=1}
        }
        b.push(f>0)
    };
    for i in 0..h{
        if !a[i]{continue}
        for j in 0..w{
            if b[j]{print!("{}",s[i][j])}
        }
        println!("")
    }
}


Measured memory_bytes: 4352
n = (int)(input())
A = (list)(map(int, input().split()))
B = (list)(map(int, input().split()))

diff = (list)(map(lambda a, b: a - b, A, B))
sum_diff = sum(diff)


def check(a):
    for i in range(n):
        if a[i] < 0:
            return False
    return True


if sum(diff) < 0:
    print(-1)
    exit()

elif check(diff):
    print(0)
else:
    ans = 0
    pos_diff = (list)(filter(lambda x: x > 0, diff))
    pos_diff = sorted(pos_diff)
    for i in range(len(pos_diff)):
        rm = pos_diff[i]
        if sum_diff-rm > 0:
            ans += 1
            sum_diff -= rm

        else:
            print(n-ans)
            exit()


Measured memory_bytes: 18620
from collections import deque
N, K = map(int, input().split())
H = []
for i in range(N):
    H.append(int(input()))

H = sorted(H)
que = deque()
mi = float('inf')
for i in range(N):
    que.append(H[i])
    if len(que) >= K:
        mi = min(mi, que[-1] - que[0])
        que.popleft()

print(mi)




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

int main() {
    ll N, M; cin >> N >> M;
    ll ans = 0;
    if(N*2>=M) cout << M/2 << endl;
    else {
        ans += N;
        M -= 2*N;
        ans += M/4;
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define db double
using namespace std;
int n;
db x[105],y[105],ans;
db sum(db xp1,db yp1,db xp2,db yp2,db xp3,db yp3){
	db l1=xp2-xp1,r1=yp2-yp1,l2=xp3-xp1,r2=yp3-yp1;
	return((l1*r2-l2*r1)/2);
}
int main(){
	scanf("%d",&n);
	for(int i=1; i<=n; i++){
		scanf("%lf%lf",&x[i],&y[i]);
		if(i>1)ans+=sum(0,0,x[i-1],y[i-1],x[i],y[i]);
	}
	ans+=sum(0,0,x[n],y[n],x[1],y[1]);
	printf("%.1lf\n",ans);
}


Measured memory_bytes: 3212
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    if a == a[::-1]:
        print('Yes')
    else:
        print('No')
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 3684
#include <bits/stdc++.h>
using namespace std;
  
int main(){
  int sum=0; 
  vector<int>A(4);
  for(int i=0;i<6;i++){
    int a; cin>>a;
    if(a==1) A[0]++;
    else if(a==2) A[1]++;
    else if(a==3) A[2]++;
    else A[3]++;
  }
  for(int i=0; i<4;i++){
    if(A[i]==2) sum++;
  }
  if(sum==2) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int n;
int main(){
	scanf("%d", &n);
	if(n & 1 ^ 1) printf("%d\n", n);
	else printf("%d\n", n << 1);
	return 0;
} 

Measured memory_bytes: 256
#include <time.h>

#include <stdlib.h>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <bitset>
#include <iterator>
#include <deque>
#include <string>
#include <queue>
#include <omp.h>
#include <fstream>   // ifstream, ofstream
typedef int64_t ll;
using namespace std;
const ll INF=1e10;
const double EPS=1e-8;
const ll mod = 1000000007;
int main(){
	ll n,d;
	cin>>n>>d;
	cout<<(n+2*d)/(2*d+1)<<endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
int S[2001];
int T[2001];
ll dp[2001][2001];
ll sum[2001][2001];
int main() {
	int N, M;
	cin >> N >> M;
	for (int i = 1; i <= N; i++) cin >> S[i];
	for (int i = 1; i <= M; i++) cin >> T[i];
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= M; j++) {
			if (S[i] == T[j]) dp[i][j] = (sum[i - 1][j - 1] + 1) % MOD;
			sum[i][j] = (sum[i - 1][j] + sum[i][j - 1] + MOD - sum[i - 1][j - 1] + dp[i][j]) % MOD;
		}
	}
	ll ans = (sum[N][M] + 1) % MOD;
	cout << ans << endl;
}

Measured memory_bytes: 62592
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define ifaxb(a, x, b) if (a < x && x < b)  // 比較は昇順
#define vi vector<int>
#define vii vector<vi>
#define vs vector<string>
#define vss vector<vs>
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define pq priority_queue
#define ipair pair<int, int>
#define spair pair<string, string>
#define lpair pair<LL, LL>
#define MP make_pair
#define MM multimap
#define PB push_back
#define INF 2147483647
#define _INF -2147483647
#define pi 3.1415926536
#define MAXN 100004
using namespace std;
typedef long long ll;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (b / a < c) {
        cout << b / a << endl;
    } else {
        cout << c << endl;
    }

    return 0;
}

Measured memory_bytes: 256
N = int(input())
for i in range(N):
    a, b, c = map(int, input().split())
    a2 = a ** 2
    b2 = b ** 2
    c2 = c ** 2
    if a2 + b2 == c2 or a2 + c2 == b2 or b2 + c2 == a2:
        print('YES')
    else:
        print('NO')

Measured memory_bytes: 7572
#include <iostream>
#include <queue>
#include <vector>
#include <stack>
#include <list>
#include <queue>
using namespace std;

int main()
{
    int n,m;
    cin>>n>>m;
    int a[n];
    int sum=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]>=m)
            sum++;
    }
    cout<<sum<<'\n';
    return 0;
}


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

#define PI 3.1415926535900
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = 0; (int)(n) < i; i--)
#define Int long long
using namespace std;


int main() {
    int count;
    string a;
    cin >>count;
    cin >>a;
    if(count < a.size()){
        cout<<a.substr(0,count).append("...")<<endl;
    }else{
        cout<<a<<endl;
    }
}


Measured memory_bytes: 3628
#import numpy as np

H,N=map(int,input().split())
weights=[list(map(int,input().split())) for _ in range(N)]
INF=100100101
#print(weight)
#print(value)

#print(weights)
dp=[INF]*(H+1)
for i in range(H+1):
    if i==0:
        dp[i]=0
    else:
        for j in weights:
            a=j[0]
            b=j[1]
            piv=max(0,i-a)  #use i-a's dp[] value as a pivot (if not exits(i-a<0), return dp[0])
            dp[i]=min(dp[i],dp[piv]+b) #the part which forcely treated as piv=0, returns min([weights]), other is treated as normal dp
    #print(dp)

print(dp[H])


Measured memory_bytes: 42860
#include <iostream>
using namespace std;
#pragma warning (disable: 4996)

int N, A[1 << 18], cnt[1 << 18];

int main() {
	cin >> N;
	for (int i = 2; i <= N; i++) {
		cin >> A[i]; cnt[A[i]]++;
	}
	for (int i = 1; i <= N; i++) {
		if (i >= 2) cout << " "; cout << cnt[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 5196
#include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    #define FAST ios_base::sync_with_stdio(false);cin.tie(0);
    const double EPS = 1e-9;
    const double PI = acos(-1);
    const int knightDir[8][2] = {{-2,-1},{-2,1},{-1,2},{1,2},{2,-1},{2,1},{-1,-2},{1,-2}};
    //const int dx[]={0,0,0,1,1,1,-1,-1,-1};
    //const int dy[]={-1,0,1,-1,0,1,-1,0,1};
    const int dx[] = {0 , 1 , 0 , -1};
    const int dy[] = {1 , 0 , -1 , 0};
    //#define MOD         1000000007LL
    #define MAX         1000005
    const ll MOD = 1000000000 + 7;
    
    int main()
    {
        FAST
        int t;
        t = 1;

        while(t--)
        {
           int x;
           cin >> x;
           
           if(x >= 30)cout << "Yes\n";
           else cout << "No\n";
        }
    }



Measured memory_bytes: 3580
import math

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    return arr

n = int(input())
if n == 1:
  print(0)
  exit()

result = 0
factList = factorization(n)
for fact in factList:
  count = math.floor(math.sqrt(2 * fact[1] + 0.25) - 0.5)
  result += count
print(result)


Measured memory_bytes: 9480
import heapq

K = int(input())

q = [i for i in range(1, 10)]
heapq.heapify(q)
cnt = 0
while cnt < K:
    x = heapq.heappop(q)
    cnt += 1
    heapq.heappush(q, 10 * x + x % 10)
    if x % 10 != 0:
        heapq.heappush(q, 10 * x + x % 10 - 1)
    if x % 10 != 9:
        heapq.heappush(q, 10 * x + x % 10 + 1)
print(x)


Measured memory_bytes: 55004
#pragma GCC optimize(2)
#pragma warning(disable:4996)
#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include<cstring>
#include <stack>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include <string>
#define itn int
#define F(i,a,b) for(int i=a;i<=(b);++i)
#define F2(i,a,b) for(int i=a;i<(b);++i)
#define dF(i,a,b) for(int i=a;i>=(b);--i)
typedef long long ll;
const ll mod = 1000 * 1000 * 1000 + 7;
using namespace std;
int t, n, m, T;
const int maxn = 2000+6;//点数
const int MAXM = 3e5+6;//边数
struct node {
	int i;
	int a;
};
ll dp[maxn][maxn];
int main()
{
#ifdef _DEBUG
	freopen("D:\\input.txt", "r", stdin);
	//	freopen("E:\\output.txt", "w", stdout);
#endif
	int i, j,len;
	std::ios::sync_with_stdio(false); cin.tie(0);	cout.tie(0);
	cin >> n;
	vector<node>a(n+1);
    for (int i = 1; i <= n; i++) {
		cin >> a[i].a;
		a[i].i = i;
	}
	sort(a.begin()+1, a.end(), [](const node& x, const node& y) {
		return x.a < y.a;
		});
	for (int i = 1; i <= n; i++) {
		dp[i][i] = (ll)a[1].a * abs(a[1].i - i);
	}
	for (len = 2; len <= n; len++) {
		for (int i = 1; i + len - 1 <= n; i++) {
			j = i + len - 1;
			dp[i][j] = max(dp[i + 1][j] + (ll)a[len].a*abs(a[len].i - i),
				dp[i][j - 1] + (ll)a[len].a * abs(a[len].i - j));
		}
	}
	cout << dp[1][n]<<"\n";
	return 0;
}

Measured memory_bytes: 26280
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rep3(var, min, max) for (ll (var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll (var) = (max) - 1; (var) + 1 > (min); --(var))
#define Mp(a,b) make_pair((a),(b))
#define F first
#define S second
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; }
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll MOD = 1e9 + 7;
ll INF =1e18;
struct BipartiteMatching {
  vector< vector< int > > graph;
  vector< int > match, alive, used;
  int timestamp;

  BipartiteMatching(int n) : graph(n), alive(n, 1), used(n, 0), match(n, -1), timestamp(0) {}

  void add_edge(int u, int v) {
    graph[u].push_back(v);
    graph[v].push_back(u);
  }

  bool dfs(int idx) {
    used[idx] = timestamp;
    for(auto &to : graph[idx]) {
      int to_match = match[to];
      if(alive[to] == 0) continue;
      if(to_match == -1 || (used[to_match] != timestamp && dfs(to_match))) {
        match[idx] = to;
        match[to] = idx;
        return true;
      }
    }
    return false;
  }

  int bipartite_matching() {
    int ret = 0;
    for(int i = 0; i < graph.size(); i++) {
      if(alive[i] == 0) continue;
      if(match[i] == -1) {
        ++timestamp;
        ret += dfs(i);
      }
    }
    return ret;
  }

  void output() {
    for(int i = 0; i < graph.size(); i++) {
      if(i < match[i]) {
        cout << i << "-" << match[i] << endl;
      }
    }
  }
};
int main() {
    int n;cin>>n;
    BipartiteMatching match(2*n);
    VP vec1(n);
    rep(i,n){
        int x,y;cin>>x>>y;
        x--;y--;
        vec1[i]=make_pair(x,y);
    }
    VP vec2(n);
    rep(i,n){
        int x,y;cin>>x>>y;
        x--;y--;
        vec2[i]=make_pair(x,y);
    }
    rep(i,n)rep(j,n){
        if(vec1[i].first<vec2[j].first&&vec1[i].second<vec2[j].second){
            match.add_edge(i,n+j);
        }
    }
    cout<<match.bipartite_matching()<<endl;
}

Measured memory_bytes: 256
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF (LLONG_MAX - 1e5)
#define fcout cout << fixed << setprecision(10)

using namespace std;

int N, A[100005], sum[100005];

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin >> N;
    REP(i, N) cin >> A[i];
    sort(A, A + N);

    sum[0] = A[0];
    REP(i, N - 1) { sum[i + 1] = sum[i] + A[i + 1]; }

    int ans = 1;
    REV(i, N - 2, 0) {
        if (sum[i] * 2 >= A[i + 1])
            ans++;
        else
            break;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
#include<deque>

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

using namespace std;


//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用


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

	string a;
	cin >> a;
	
	for (int i = 0; i < 3; i++)
	{
		if (a[i] == '1')
		{
			a[i] = '9';
		}
		else if (a[i] == '9')
		{
			a[i] = '1';
		}
	}

	cout << a << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);

ll mod_pow(ll a, ll n, ll m = mod) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }
const int max_n = 10000;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}

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


void solve() {
	int a[3];
	rep(i, 3)cin >> a[i];
	swap(a[0], a[1]);
	swap(a[0], a[2]);
	cout << a[0] << " " << a[1] << " " << a[2] << "\n";
}


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(7);
	//init_f();
	//init();
	//int t; cin >> t; rep(i, t)solve();
	solve();
	stop
		return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define rrep(i,n) for(int i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define pr(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
#define yes "Yes"
#define no "No"
using namespace std;
using ll = long long;
using Edge = pair<int,long long>;
using Graph = vector<vector<Edge>>;
typedef pair<int,int> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

ll N,L;

int main(){
    cin >> N >> L;
    ll ans = 1e9, index = 0, sum = 0;
    rep(i,N) if(ans > abs(L+i)) ans = abs(L+i), index = i;
    rep(i,N) if(i != index) sum += L+i;
    pr(sum);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>  
#include <functional>
#define ll long long int
#define ld long double
#define pb push_back
#define pll pair<ll,ll>
#define pint pair<int,int>
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define mod 1000000007
#define MAX 500010
#define endl '\n'
#define mp make_pair
#define INF INT_MAX
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define ff first
#define ss second
#define ps(x,y) fixed<<setprecision(y)<<x
#define setbits(x) __builtin_popcountll(x)            //counts no of ones in binary representation
#define w(t)     int t; cin>>t; while(t--)
#define pi 3.141592653589793238
#define sortt(v)  sort(v.begin(),v.end())
#define lb(v,x) std::lower_bound(v.begin(),v.end(),x)
#define ub(v,x) std::upper_bound(v.begin(),v.end(),x)

using namespace std;

bool isprime(ll n){			//to check whteher no is prime or not
	if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
  
    // This is checked so that we can skip 
    // middle five numbers in below loop 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
  
    for (int i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
  
    return true; 
}

int main(){
	fast;
	ll n;
	ld d;
	cin>>n>>d;
	ld x[n],y[n];
	forn(i,n)	cin>>x[i]>>y[i];
	forn(i,n){
		ld temp=x[i]*x[i]+y[i]*y[i];
		x[i]=sqrt(temp);
	}
	ll cnt=0;
	forn(i,n){
		if(x[i]<=d)	cnt++;
	}
	cout<<cnt;
	//cout<<"Case #"<<x<<": "<<y<<endl;
}

/*for(int i=2;i<=n;i++){
			if(v[i].size()==0)	break;
			for(int j=0;j<v[i].size();j++){
				cout<<v[i-1][0]<<' '<<v[i][j]<<endl;
			}
		}*/

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

using namespace std;

#define ll long long

ll cost[100010], h[100010];

main()
{
    ll n, i, j, c, c2;

    cin>>n;

    for(i=0; i<n; i++) scanf("%lld", &h[i]);
    c=h[1]-h[0];
    if(c<0) c=-c;
    cost[1]=c;
    for(i=2; i<n; i++)
    {
       c=h[i]-h[i-1];
       if(c<0) c=-c;
       c+=cost[i-1];
       c2=h[i]-h[i-2];
       if(c2<0) c2=-c2;
       c2+=cost[i-2];
       if(c>c2) cost[i]=c2;
       else cost[i]=c;
    }

    cout<<cost[n-1]<<endl;


}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long x = sc.nextLong();

    long yoki = 100;
    for (int i = 1; i <= 3765; i++){
      yoki = yoki + yoki / 100;
      if (yoki >= x) {
        System.out.println(i);
        return;
      }
    }
  }
}


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

int main() {
    int N;
    cin >> N;
    vector<long long> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    sort(A.begin(), A.end(), greater<int>());

    long long ans = A[0];
    N -= 2;
    for (int i = 1; N > 0; i++) {
        if (N >= 2) {
            ans += A[i] * 2;
            N -= 2;
        } else {
            ans += A[i];
            break;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 4836
#include <stdio.h>

int main(){
    int v[100001], n;

    for(int i=0;i<=100001;i++)
        v[i] = 0;

    scanf("%d", &n);

    while(n>0){
        int a, b;
        scanf("%d %d", &a, &b);

        for(int i=a;i<=b;i++)
            v[i]= 1;

        n--;
    }

    int k = 0;

    for(int i=0;i<=100000;i++)
        k += v[i];

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

    return 0;
}


Measured memory_bytes: 512
#!/usr/bin/env python
# coding: utf-8

import sys


def get_class_by_weight(weight):
    class_name = ""
    if weight <= 48.0:
        class_name = "light fly"
    elif weight <= 51.0:
        class_name = "fly"
    elif weight <= 54.0:
        class_name = "bantam"
    elif weight <= 57.0:
        class_name = "feather"
    elif weight <= 60.0:
        class_name = "light"
    elif weight <= 64.0:
        class_name = "light welter"
    elif weight <= 69.0:
        class_name = "welter"
    elif weight <= 75.0:
        class_name = "light middle"
    elif weight <= 81.0:
        class_name = "middle"
    elif weight <= 91.0:
        class_name = "light heavy"
    else:
        class_name = "heavy"
    return class_name


def main():
    params = [float(line) for line in sys.stdin.readlines()]

    for param in params:
        print get_class_by_weight(param)

if __name__ == '__main__':
    main()

Measured memory_bytes: 7256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
namespace ac2
{
    class Program
    {


        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            var k = s.Length;
            var r = (15 - k) + s.Count(x => x == 'o') >= 8
            ? "YES"
            : "NO";
            Console.WriteLine(r);
        }
    }
}


Measured memory_bytes: 11220
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <vector>
#include <map>
#include <stack>
#include <string>
#include <list>
#include <set>
#include <queue>
#include <deque>
#include <math.h>
using namespace std;

typedef pair<int, int> P;
#define ll long long
#define int ll
#define INF (1LL<<60)
#define mod 1000000007
int dx[4] = { 0, 1, 0, -1 };
int dy[4] = { 1, 0, -1, 0 };


signed main(){

	int n;
	vector<int> v;
	deque<int> q, data;

	cin >> n;
	for (int i = 0; i < n; i++){
		int a;
		cin >> a;
		v.push_back(a);
	}
	sort(v.begin(), v.end());
	for (int i = 0; i < n; i++){
		data.push_back(v[i]);
	}

	q.push_back(data.front());
	data.pop_front();
	int sum = 0;
	while (data.size()>0){
		// maxを前に入れる場合
		int m1 = abs(q.front() -  data.back());
		// maxを後ろに入れる場合
		int m2 = abs(q.back() - data.back());
		// minを前に入れる場合
		int m3 = abs(q.front() - data.front());
		// minを後ろに入れる場合
		int m4 = abs(q.back() - data.front());

		int best = max(m1, max(m2, max(m3, m4)));
		sum += best;
		if (best == m1){
			q.push_front(data.back()); data.pop_back();
		}
		else if (best == m2){
			q.push_back(data.back()); data.pop_back();
		}
		else if (best == m3){
			q.push_front(data.front()); data.pop_front();
		}
		else{
			q.push_back(data.front()); data.pop_front();
		}
	}

	cout << sum << endl;

	return 0;
}


Measured memory_bytes: 1912
#include <stdio.h>
#include <iostream>

using namespace std;

int main() {
  int a,b;
  cin>>a>>b;
  if (a == b) cout<<2*a<<endl;
  else if (a > b) cout<<2*a-1<<endl;
  else cout<<2*b-1<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using namespace std;


void solve(long long N){
  long long ret = N;
  for (long long i = 1; i*i <= N; i++) {
    if (N%i == 0) {
      ret = min(ret, i + N/i - 2);
    }
  }
  std::cout << ret << std::endl;
}

int main(){
  long long N;
  scanf("%lld",&N);
  solve(N);
  return 0;
}


Measured memory_bytes: 256
use proconio::input;
use proconio::marker::{Chars, Usize1};
use std::iter::Iterator;
use std::collections::HashSet;
use std::cmp::*;
use itertools::Itertools;

#[allow(unused_macros)]
macro_rules! max {
    ($x:expr) => {
      $x
    };
    ($x:expr, $($xs:tt)+) => {
      max($x,max!($($xs)+))
    };
  }
  
  #[allow(unused_macros)]
  macro_rules! min {
    ($x:expr) => {
      $x
    };
    ($x:expr, $($xs:tt)+) => {
      min($x,min!($($xs)+))
    };
  }

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    input! {
      n: u128,
      a: [u128; n],
    }

    let mut ans : u128 = 1;

    for &i in a.iter() {
        if i == 0 {
          println!("0");
          return;
        }
    }

    for &i in a.iter() {
        ans = ans * i;
        if  ans > 1000_000_000_000_000_000 {
          println!("-1");
          return;
        }
    }

     println!("{}", ans);
}


Measured memory_bytes: 5316
N, W = map(int, input().split())
w = [0]*N
v = [0]*N
for i in range(N):
    w[i],v[i] = map(int, input().split())

def solve(w,v):
    dp = [[0]*(W+1) for i in range(N+1)]
    for i in range(1,N+1):
        for j in range(W+1):
            if j < w[i-1]:
                dp[i][j] = dp[i-1][j]
            else:
                dp[i][j] = max(dp[i-1][j],dp[i-1][j-w[i-1]]+v[i-1])
    ans = dp[-1][-1]
    return ans
print(solve(w,v))

Measured memory_bytes: 118512
#include <iostream>
#include <vector>
#include <string>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
using namespace std;
bool maps[100][100];
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int search(int y,int x){
	int maxim=0;
	maps[y][x]=false;
	REP(i,4)
		if(y+dy[i]>=0 && x+dx[i]>=0 && maps[y+dy[i]][x+dx[i]])
		maxim=max(maxim,search(y+dy[i],x+dx[i]));
	maps[y][x]=true;
	return maxim+1;
}
int main() {
	// your code goes here
	int m,n;
	while(cin >> m >> n && n){
	int maxim=0;
	REP(i,n)
		REP(j,m)
			cin >> maps[i][j];
	REP(i,n)
		REP(j,m)
			if(maps[i][j])
			maxim=max(maxim,search(i,j));
	cout << maxim << endl;
	}
	return 0;
}

Measured memory_bytes: 1168
n = int(input())
a = [int(a) for a in input().split()]

# print(n)
# print(a)

count = 0
for i in range(n):
    # print(str(i+1) + str(a[a[i]-1]) )
    if i+1==a[a[i]-1]:
        count += 1

count = count//2
print(count)

Measured memory_bytes: 13880
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//int h = sc.nextInt();
		String s = sc.next();

		sc.close();
			System.out.println(s.equals("BBB") || s.equals("AAA") ? "No" : "Yes");


	}

}


Measured memory_bytes: 21332
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;




public class Main {

    public static void main(String[] args) {

    	Main main=new Main();

    	main.run();

    }

    void run() {
    	Scanner sc=new Scanner(System.in);

    	String[] A=sc.next().split("");
    	String[] B=sc.next().split("");

    	Arrays.sort(A);
    	Arrays.sort(B,Collections.reverseOrder());

    	String strA=conectchar(A);
    	String strB=conectchar(B);

    	if(strA.compareTo(strB)<0) {
    		System.out.println("Yes");
    	}else {
    		System.out.println("No");
    	}
    }

    static String conectchar(String[] str) {

    	StringBuilder result=new StringBuilder();

    	for(int i=0;i<str.length;i++) {
    		result.append(str[i]);
    	}

    	return result.toString();
    }


}



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


int main(){
  int N, A, B;
  cin >> N >> A >> B;
  int ans = 0;
  for(int ii=1; ii<=N; ii++){
    int sum=0;
    int jj=ii;
    while(jj){
      sum+=jj%10;
      jj/=10;
    }
    if(A <= sum && sum <= B){
      ans += ii;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define clr(x,i) memset(x,i,sizeof(x))
using namespace std;
const LL N=100005,mo=1e9+7;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int n;
LL K;
char s[N];
int main()
{
	scanf("%s",s+1); n=strlen(s+1);
	cin>>K;
	int id=0,val=0;
	for(int i=1;i<=n;i++)
	  if(s[i]!='1') {id=i,val=s[i]-'0';break;}
//	cout<<s[id]<<endl;
	if(K<id||id==0) printf("1\n");
	else printf("%d\n",val);
	return 0;
}

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

using namespace std;
using ll = long long;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}

ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}

ll lcm(ll a, ll b) {
  return a * b / gcd(a, b);
}

const string YES = "Yes";
const string NO = "No";

void solve(long long A, long long B){
  if(A*B%2==0)
    std::cout << NO << std::endl;
  else
    std::cout << YES << std::endl;
}

int main(){
  long long A;
  scanf("%lld",&A);
  long long B;
  scanf("%lld",&B);
  solve(A, B);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	if(n%1000 == 0)
		cout<<"0";
	else
	{
		int c = ((n/1000)+1)*1000 - n;
		cout<<c;
	}
	return 0;
}


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


int main() {
    string N;cin >> N;
    if (N.at(0) == N.at(2)){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }

  }       

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

int main(){
  string s;
  cin>>s;
  if(s=="SSS") cout<<0;
  else if(s=="SSR") cout<<1;
  else if(s=="SRS") cout<<1;
  else if(s=="RSS") cout<<1;
  else if(s=="SRR") cout<<2;
  else if(s=="RSR") cout<<1;
  else if(s=="RRS") cout<<2;
  else if(s=="RRR") cout<<3;
}


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

int main(){
int a,b,c[50],d = 0;
  cin >> a >> b;
  for(int S = 0; S < a;S++){
  cin >> c[S];
  }
  
  sort(c,c+a,greater<int>());
  
  for(int S = 0;S < b;S++){
  d += c[S];
  }
  cout << d << endl;
return 0;
}

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

int main(){
  int x, a, b;
  cin >> x >> a >> b;
  
  if (b <= a) cout << "delicious" << endl;
  else if (b > a+x) cout << "dangerous" << endl;
  else cout << "safe" << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long int
#define pii pair<int,int>
#define pll pair<ll,ll>
#define plll pair<ll,pll>
#define Pb push_back
#define Mp make_pair
#define ff first
#define ss second
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define INF LONG_LONG_MAX
#define MINF LONG_LONG_MIN
#define MOD (ll)1000000007


signed main()
{
    IOS;
    int f[9];
    f[0]=1;
    f[1]=1;
    f[2]=2;
    f[3]=6;
    f[4]=24;
    f[5]=120;
    f[6]=720;
    f[7]=5040;
    f[8]=40320;
    int n;
    cin >> n;
    int x;
    bool vis[n+1];
    int cnt1[n+1];
    memset(vis,false,sizeof(vis));
    for(int i=1;i<=n;i++)
    {
      cin >> x;
      vis[x]=true;
      int cnt=0;
      for(int i=1;i<x;i++)
      {
        if(vis[i]==false)cnt++;
      }
      cnt1[i]=cnt;
    }
    bool vis1[n+1];
    memset(vis1,false,sizeof(vis1));
    int cnt2[n+1];
    for(int i=1;i<=n;i++)
    {
      cin >> x;
      vis1[x]=true;
      int cnt=0;
      for(int i=1;i<x;i++)
      {
        if(vis1[i]==false)cnt++;
      }
      cnt2[i]=cnt;
    }
    int ans=0;
    for(int i=1;i<=n;i++)
    {
      //cout << cnt1[i] << " " << cnt2[i] << endl;
      ans+=(cnt1[i]-cnt2[i])*f[n-i];
    }
    cout << abs(ans);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { -1, 0, 0, 1 };
const ll dy[4] = { 0, -1, 1, 0 };
const ll INF = 1e9 + 7;
const ll inf = 1LL << 50;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
struct Accelerate_Cin {
	Accelerate_Cin() {
		cin.tie(0);
		ios::sync_with_stdio(0);
		cout << fixed << setprecision(20);
	};
};
///////////////////////////////////////


//書かれている整数を直接追うのではなく次のように言い換える
//Mは各Aiの符号を適当に変えたのちに総和をとったもの。
//一番都合の良いことを考えるとAi<0なるiについては全て符号を変え
//Ai>0なるiについては符号を変えない、だがそれは無理。
//帰納法よりk=1,,,N-1が許される値になることがわかる
//どのkの時にMが最大になるのか？
//これは累積和で処理する

int main() {
	int N; cin >> N;
	vector<int>A(N, 0);
	for (int i = 0; i < N; ++i)cin >> A[i];
	sort(A.begin(), A.end());
	vector<int>S(N, 0);//Aの累積和
	S[0] = A[0];
	for (int i = 1; i < N; ++i) {
		S[i] = S[i - 1] + A[i];
	}
	int k = 0;//最大値を得るときに符号を変えたA[i]の数
	int M = -1e9;
	for (int i = 0; i < N; ++i) {
		if (A[i] >= 0) {
			break;
		}
		k++;
	}
	if (k == 0) {
		M = S[N - 1] - S[k] * 2;
		k = 1;
	}
	else if (k < N) M = S[N - 1] - S[k - 1] * 2;
	else {
		M = S[N - 1] - S[N - 2] * 2;
		k = N - 1;
	}
	cout << M << endl;

	//操作１
	for (int i = 1; i < k; ++i) {
		cout << A[N - 1] << " " << A[i] << endl;
		A[N - 1] = A[N - 1] - A[i];
	}
	//操作2
	for (int i = k; i < N - 1; ++i) {
		cout << A[0] << " " << A[i] << endl;
		A[0] = A[0] - A[i];
	}
	//操作3
	cout << A[N - 1] << " " << A[0] << endl;
	return 0;
}


Measured memory_bytes: 2688
def main():
    n = int(input())

    chars = 'zabcdefghijklmnopqrstuvwxy'

    st = ''
    while True:
        a = n % 26
        st += chars[a]
        n = n // 26
        if n == 0 or (a == 0 and n == 1):
            break
        elif a == 0:
            n -= 1


    res = ''.join(list(reversed(st)))
    print(res)


main()


Measured memory_bytes: 9092
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-12;
const double PI = acos(-1.0);
const int INF = INT_MAX/10;

int main() {
	int w, n;
	while(cin >> w) {
		cin >> n;
		vvi bar(n, vi(2));
		
		int a, b;
		char c;
		REP(i, n) {
			cin >> a >> c >> b;
			bar[i][0] = a;
			bar[i][1] = b;
		}

		vi goal(w);
		FOR(i, 1, w) {
			int cur = i;
			REP(j, n) {
				if(bar[j][0] == cur) {
					cur = bar[j][1];
					goto next;
				}
				if(bar[j][1] == cur) {
					cur = bar[j][0];
					goto next;
				}

				next:;
			}
			
			goal[cur-1] = i;
		}

		REP(i, w) {
			cout << goal[i] << endl;
		}
	}
}

Measured memory_bytes: 1212
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
typedef long long ll;
const ll longinf=1LL<<60;
using namespace std;

struct node
{
    int y,next;
};

node e[50000];
int t=1;
int loc[20000];

void add(int x,int y)
{
    e[t].y=y;
    e[t].next=loc[x];
    loc[x]=t;
    t++;
}

int c[20000];

struct node2
{
    int d;
    int idx;
};

node2 d[20000];


bool flag[20000];
int num[20000];
    

int n;

int q[30000];
int l,r;

bool cmp(node2 a, node2 b)
{
    return a.d>b.d;
}

void bfs()
{
    flag[1]=1;
    d[1].d=1;
    d[1].idx=1;
    q[r++]=1;
    while (l<r)
    {
        int x = q[l++];
        for (int now=loc[x];now;now=e[now].next)
        {
            int y = e[now].y;
            if (flag[y]==0)
            {
                flag[y]=1;
                d[y].d = d[x].d+1;
                d[y].idx = y;
                q[r++]=y;
            }
        }
    }
}

int main()
{
    int x,y;
    cin>>n;
    for (int i=1; i<=n-1; ++i)
    {
        cin>>x>>y;
        add(x,y);
        add(y,x);
    }
    for (int i=1; i<=n; ++i)
        cin>>c[i];
    bfs();
    sort(d+1,d+n+1,cmp);
    sort(c+1,c+n+1);
    
    //for(int i=1; i<=n; ++i)
     //   cout<<d[i].idx<<' '<<d[i].d<<endl;
    int ans=0;
    for (int i=1; i<=n; ++i)
    {
        num[d[i].idx]=c[i];
        if (d[i].d!=1)
            ans+=c[i];
    }
    cout<<ans<<endl;
    for (int i=1; i<=n; ++i)
        cout<<num[i]<<' ';
    cout<<endl;



    return 0;
}



Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,N_temp,a,b,c,d;
  cin >> N;
  a=N/1000;
  N_temp=N%1000;
  b=N_temp/100;
  N_temp=N_temp%100;
  c=N_temp/10;
  d=N_temp%10;
  
  if (a==b && a==c) {
    cout << "Yes" << endl;
  }
  else if (b==c && c==d){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... U> void assign(V<T>& v, int n, const U&... u) { v.resize(n); for (auto&& i : v) assign(i, u...); }

struct QU {
  V<> par, rank, _size;

  QU(int n) { 
    par.resize(n);
    iota(par.begin(), par.end(), 0);
    rank.resize(n);
    _size.assign(n, 1);
  }

  int find(int a) {
    if (par[a] == a) return a;
    return par[a] = find(par[a]);
  }

  bool same(int a, int b) { return find(a) == find(b); }

  int size(int a) { return _size[find(a)]; }

  void unite(int a, int b) {
    a = find(a), b = find(b);
    if (a == b) return;
    if (rank[a] < rank[b]) {
      par[a] = b;
      _size[b] += _size[a];
    } else {
      par[b] = a;
      _size[a] += _size[b];
    }
    if (rank[a] == rank[b]) rank[a]++;
  }
};

struct edge { int from, to, w; edge(int a, int b, int w) : from(a), to(b), w(w) {} };


int kruskal(V<edge>& g, int n) {
  int res = 0;
  QU qu(n);
  sort(g.begin(), g.end(), [](edge a, edge b) { return a.w < b.w; });
  for (auto&& e : g) {
    if (!qu.same(e.from, e.to)) {
      qu.unite(e.from, e.to);
      res += e.w;
    }
  }
  return res;
}

int main() {
  cin.tie(NULL); ios::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  V<edge> g;
  for (int i = 0; i < m; i++) {
    int a, b, w; cin >> a >> b >> w;
    g.emplace_back(a, b, w);
  }
  cout << kruskal(g, n) << '\n';
}


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

using namespace std;

const int maxn = 3005;
char s[maxn], t[maxn];

int dp[maxn][maxn];
pair<int, int>  pre[maxn][maxn];
int main(){
    scanf("%s", s + 1);
    scanf("%s", t + 1);
    int n = strlen(s + 1);
    int m = strlen(t + 1);
    memset(dp, 0, sizeof(dp));
    for(int i = 1;i <= n;i++){
        for(int j = 1;j <= m;j++){
            if(s[i] == t[j]){
                if(dp[i - 1][j - 1] + 1 > dp[i][j]){
                    dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1);
                    pre[i][j] = make_pair(i - 1, j - 1);
                }
            }
            if(dp[i - 1][j] > dp[i][j]){
                dp[i][j] = max(dp[i][j], dp[i - 1][j]);
                pre[i][j] = make_pair(i - 1, j);
            }
            if(dp[i][j - 1] > dp[i][j]){
                dp[i][j] = max(dp[i][j], dp[i][j - 1]);
                pre[i][j] = make_pair(i, j - 1);
            }
        }
    } 
    //cout << dp[n][m] << endl;
    int l = n, r = m;
    string ans = "";
    while(ans.length() < dp[n][m]){
        pair<int, int> p = pre[l][r];
        int ll = p.first, rr = p.second;
        if(ll == l - 1 and rr == r - 1){
            ans.push_back(s[l]);
        }
        l = ll, r = rr;
    } 
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 106112
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {//227
	int n,m;
	cin>>n>>m;
	vi arr(m);
	for(int &i:arr)cin>>i;
	sort(arr.begin(),arr.end());
	vi diff(m-1);
	REP(i,0,m-2) {
		diff[i]=abs(arr[i]-arr[i+1]);
	}
	sort(diff.begin(),diff.end());
	ll sum = 0;n--;
	REP(i,0,m-2-n)sum+=diff[i];
	cout<<sum;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 4000
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
#include<map>
#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x) << endl
typedef long long ll;
const ll MOD = 1000000007;
 
using namespace std;

int main(){
    int N, M;   cin >> N >> M;
    vector<int> dp(N+1), a(N,0);
    for(int i=0; i<M; i++){
        int v;  cin >> v;
        a[v] = 1;
    }
    dp[0] = 1;
    for(int i=1; i<=N; i++){
        if(a[i] == 1)   dp[i] = 0;
        else{
            if(i > 1)dp[i] = dp[i-1] + dp[i-2];
            else    dp[i] = dp[i-1];
            dp[i] %= MOD;
        }
    }
    cout << (dp[N]+MOD)%MOD << endl;
    return 0;
}

Measured memory_bytes: 3976
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <utility>
#include <string>
#include <stack>
#include <regex>
#include <numeric>
#include <queue>
 
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
 
using namespace std;
 
typedef long long ll;

int main(int argc, char const *argv[])
{
  vector<ll> a(3);
  REP(i,3) {
    cin >> a[i];
  }
  sort(ALL(a),greater<ll>());
  ll res = 0;
  res += abs(a[0]-a[1]) + abs(a[1]-a[2]);
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
import Control.Monad.Primitive (PrimState)
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Unboxed.Mutable as MV
import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)

main :: IO ()
main = do
    n <- fst . fromJust . B.readInt <$> B.getLine
    as <- V.fromList . map (fst . fromJust . B.readInt) . B.words <$> B.getLine
    mv <- MV.unsafeNew (n + 1) :: IO (MV.MVector (PrimState IO) Int)
    m <- operate as n mv 0 (n `div` 2) (n `div` 2 + 1)
    v <- V.unsafeFreeze $ MV.slice m n mv
    putStrLn $ unwords $ map show $ V.toList v
    where
        operate as n mv i l r
            | i >= n = return (l + 1)
            | i `mod` 2 == (n - 1) `mod` 2 = do
                MV.unsafeWrite mv l (as V.! i)
                operate as n mv (i + 1) (l - 1) r
            | otherwise = do
                MV.unsafeWrite mv r (as V.! i)
                operate as n mv (i + 1) l (r + 1)


Measured memory_bytes: 14076