akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;
typedef long long LL;

#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}
}star;
#define DEBUG if(0)
#endif

#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}

class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};

vector<LL> latte(LL piv, set<pair<LL, LL>>& pts) {
	vector<LL> ret;
	auto it = pts.lower_bound({ piv ,-1 });
	{
		auto i = it;
		int cnt = 2;
		while (i != pts.end()&&cnt>0) {
			cnt--;
			ret.push_back(i->first);
			i++;
		}
	}
	it--;
	{
		auto i = it;
		int cnt = 2;
		while (i != pts.begin() && cnt>0) {
			cnt--;
			ret.push_back(i->first);
			i--;
		}
	}

	return ret;
}
int main() {
	int N;
	cin >> N;
	vector<LL> A(N);
	cin >> A;
	auto B = A;
	auto C = A;
	for (int i : range(1, N))B[i] += B[i - 1];
	reverse(ALL(C));
	for (int i : range(1, N))C[i] += C[i - 1];
	reverse(ALL(C));
	set<pair<LL, LL>> left, right;
	left.insert({ -1, -1 });
	right.insert({ -1, -1 });
	for (int i : range(2,N)) {
		right.insert({ C[i],i });
	}
	LL ret = 1e18;
	for (int i : range(2, N - 1)) {
		left.insert({ B[i - 2],i - 2 });
		right.erase({ C[i],i });
		LL lsum = B[i - 1];
		LL rsum = C[i];
		auto l = latte(lsum / 2, left);
		auto r = latte(rsum / 2, right);
		for (auto L : l) {
			for (auto R : r) {
				vector<LL> v = { L,lsum - L,R,rsum - R };
				chmin(ret, *max_element(ALL(v)) - *min_element(ALL(v)));
			}
		}
	}
	cout << ret << endl;
	return 0;
}


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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))

const long long mod = 1e9 + 7;
const double pi = acos(-1.0);
typedef string ss;
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll x,ll y)
{
    x /= gcd(x,y);
    y /= gcd(x,y);
    return (x*y);
}

int main()
{
    string s;
    cin >> s;
    ll n = SIZE(s);
    
    vvll dp(n+1, vll(13, 0));
    dp[0][0] = 1;
    rep(i,n){
        ll c = ((s[i] == '?')?-1: s[i]-'0');
        rep(j,10){
            if(c != -1 && c != j)continue;
            rep(ki,13)dp[i+1][(ki*10 + j) % 13] += dp[i][ki];
        }

        rep(j,13)dp[i+1][j] %= mod;
    }
    

    /*rep(i,n+1){
        rep(j,13)printf("%5d ", dp[i][j]);
        cout << endl;
    }*/

    cout << dp[n][5] << endl;
    return 0;
}

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

int main() {
    vector<int> a(5);
    rep(i, 5) cin >> a.at(i);
    int k; cin >> k;
    bool ans = false;

    if (a.at(4) - a.at(0) > k) ans = true;

    cout << (ans ? ":(" : "Yay!") << endl;
}

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

using namespace std;
int INF = 1e9;
int N;
vector<int> sy[4][220000], sx[4][220000], ty[4][420000], tx[4][420000];
unordered_map<char, int> od;

void input(){
	cin >> N;
	od['R'] = 0;
	od['L'] = 1;
	od['U'] = 2;
	od['D'] = 3;

	for (int i = 0; i < N; i++)
	{
		int _x, _y;
		char _u;
		cin >> _x >> _y >> _u;
		int _tx = _x - _y + 200000;
		int _ty = _x + _y;
		sx[od[_u]][_x].push_back(_y);
		sy[od[_u]][_y].push_back(_x);
		tx[od[_u]][_tx].push_back(_ty);
		ty[od[_u]][_ty].push_back(_tx);
	}
}

inline void chmin(int &a, int b){if(a>b)a=b;}

int cof(vector<int> toR, vector<int> toL){
	int ret = INF;
	if(toL.size()==0 || toL.size()==0) return ret;
	toL.push_back(INF);
	sort(toL.begin(), toL.end());
	for(auto x_tor:toR) {
		int x_tol = *lower_bound(toL.begin(), toL.end(), x_tor);
		if(x_tol == INF) continue;
		chmin(ret, (x_tol - x_tor)*5 );
	}
	return ret;
}

int solve(){
	int ans = INF;
	// yが同じもの同士

	for (int y = 0; y <= 200000; y++)
	{
		chmin(ans, cof(sy[od['R']][y], sy[od['L']][y]));
	}
	// xが同じもの同士
	for (int x = 0; x <= 200000; x++)
	{
		chmin(ans, cof(sx[od['U']][x], sx[od['D']][x]));
	}
	// 45度回転
	// yが同じもの同士
	for (int y = 0; y <= 400000; y++)
	{
		chmin(ans, cof(ty[od['R']][y], ty[od['U']][y]));
		chmin(ans, cof(ty[od['D']][y], ty[od['L']][y]));
	}
	// xが同じもの同士
	for (int x = 0; x <= 400000; x++)
	{
		chmin(ans, cof(tx[od['R']][x], tx[od['D']][x]));
		chmin(ans, cof(tx[od['U']][x], tx[od['L']][x]));
	}

	if(ans == INF) cout << "SAFE" << endl;
	else cout << ans << endl;
	return 0;
}

int main() {
	input();
	solve();
	return 0;
}

Measured memory_bytes: 146180
use proconio::{input, fastout};
use std::collections::HashMap;

#[fastout]
fn main() {
    input!{
        n:u32,
    }

    let mut a: HashMap<u32, u32> = HashMap::new();

    for _i in 2..n+1 {
        input!{
            ai:u32,
        }
        match a.get_mut(&ai) {
            Some(x) => {*x += 1;},
            None => {a.insert(ai, 1);},
        }
    }

    for i in 1..n+1 {
        match a.get(&i) {
            Some(x) => println!("{}", x),
            None => println!("{}", 0),
        }
    }

}


Measured memory_bytes: 6700
#include<cstdio>
#include<iostream>
#include<list>
#include<cstring>

using namespace std;
list<int> lst;
int main()
{
	int n;
	scanf("%d", &n);
	while (n--)
	{
		char str[100];
		scanf("%s", str);
		if (str[0] == 'i')
		{
			int num;
			scanf("%d", &num);
			lst.push_front(num);
		}
		else if (strlen(str) == 6)
		{
			int num,find=0;
			scanf("%d", &num);
			list<int>::iterator pp;
			for (auto it = lst.begin(); it != lst.end(); it++)
				if (*it == num)
				{
					find = 1;
					pp = it;
					break;
				}
			if (pp != lst.end()&&find)
				lst.erase(pp);

		}
		else if (strlen(str) > 6 && str[6] == 'F')
		{
			lst.pop_front();
		}
		else
			lst.pop_back();
	}
	int len = lst.size(),cur=0;
	for (auto it = lst.begin(); it != lst.end(); it++,cur++)
	{
		printf("%d%c", *it,cur!=len-1?' ':'\n');
	}

	return 0;
}


Measured memory_bytes: 34452
N = int(input())
lst_A = list(map(int, input().split()))
lst_A.sort(reverse=True)
cur_a = -1
lst_ans = []


for a in lst_A:
    if cur_a == a:
        lst_ans.append(a)
        cur_a = -1
        if len(lst_ans) == 2:
            break
    else:
        cur_a = a


ans = lst_ans[0] * lst_ans[1] if len(lst_ans) else 0
print(ans)


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

int main(){
    
    int N;
    cin >> N;
    long long ans = 0;
    long long x;
    rep(i, N){
        cin >> x;
        while(x %2 ==0){
            ans++;
            x /= 2;
        }
    }
   
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(arr) (int)arr.size()
#define All(arr) arr.begin(), arr.end()

using namespace std;
typedef long long ll;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

#define Cins(T, n, xs) \
  vector<T> xs(n);     \
  for (int i = 0; i < n; ++i) cin >> xs[i]

void Main() {
  Cin(string, s);

  bool good = true;
  for (int i = 0; i < sz(s); ++i) {
    if ((i + 1) % 2 == 1) {
      if (!(s[i] == 'R' or s[i] == 'U' or s[i] == 'D')) good = false;
    } else {
      if (!(s[i] == 'L' or s[i] == 'U' or s[i] == 'D')) good = false;
    }
  }

  puts(good ? "Yes" : "No");
}

int main() {
  cout << fixed << setprecision(15);
  Main();
  return 0;
}

Measured memory_bytes: 256
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from itertools import accumulate
from bisect import bisect_left

n = ni()
a = list(li())
b = list(li())

if sum(a) < sum(b):
    print(-1)
    
else:
    over = []
    lack = 0
    ans = 0
    for ai, bi in zip(a,b):
        if ai < bi:
            ans += 1
            lack += (bi-ai)
        else:
            over.append(ai-bi)
            
    over.sort(reverse=True)
    over = [0] + over
    over = list(accumulate(over))
    cnt = bisect_left(over, lack)
    
    ans += cnt
    print(ans)
            

Measured memory_bytes: 18772
a,b = map(int,input().split())
if a >= 1 and  b <=1000000000:
    c = a * b
    if b <= 0:
        print(0)
    elif a == 1 or b == 1:
        print(1)
    else:
        if c % 2 == 0:
            ans = c // 2
            print(ans)
        else:
            ans = (c // 2) + 1
            print(ans)
else:
    print(0)

Measured memory_bytes: 38384
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
using namespace std;
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;
}
inline void write(int x)
{
    if(x<0)putchar('-'),x=-x;
    if(x>9)write(x/10);
    putchar(x%10+'0');
}
inline void pr1(int x){write(x),putchar(' ');}
inline void pr2(int x){write(x),puts("");}
int a[200010],f[200010][50];
int p[200010],nex[200010];
int top,sta[200010];
bool v[200010];
int main()
{
    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    int n=read();long long m;scanf("%lld",&m);m--;
    for(int i=1;i<=n;i++){a[i]=read();if(!p[a[i]])p[a[i]]=i;}
	f[n+1][0]=1;
    for(int i=n;i>=1;i--)
    {
    	if(!nex[a[i]])f[i][0]=p[a[i]]+1;
    	else f[i][0]=f[nex[a[i]]+1][0];
    	nex[a[i]]=i;
    }
    for(int j=1;j<=40;j++)
    {
    	for(int i=1;i<=n+1;i++)f[i][j]=f[f[i][j-1]][j-1];
    }int now=1;
    for(int i=40;i>=0;i--){if(m>=(1LL<<i))now=f[now][i],m-=(1LL<<i);}
    for(int i=now;i<=n;i++)
    {
    	if(v[a[i]]==false)sta[++top]=a[i],v[a[i]]=true;
    	else {while(v[a[i]]==true)v[sta[top--]]=false;}
    }
    for(int i=1;i<=top;i++)pr1(sta[i]);
   	return 0;
}

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

namespace abc142_c
{
    class Program
    {
        static void Main()
        {
            var n = int.Parse(Console.ReadLine());
            var tmpA = Console.ReadLine().Split();
            var aList = new SortedDictionary<int,int>();
            for (var i = 1; i <= n; i++)
            {
                aList[int.Parse(tmpA[i - 1])] = i;
            }

            Console.WriteLine(string.Join(" ", aList.Values.ToList()));

        }
    }
}


Measured memory_bytes: 33292
N = int(input())
ans = 0
for i in range(1, N + 1):
    n = N // i  # 項数n
    cnt = (n * (2 * i + (n - 1) * i)) // 2  # 初項i, 項数n の等差数列の和の公式
    ans += cnt
print(ans)

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

using namespace std;

#define int long long

int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);

    int a,b,c,k;
    cin>>a>>b>>c>>k;
    int ans=0;
    if(a>=k){
        cout<<k<<endl;
        return 0;
    }
    ans+=a;
    k-=a;
    if(b>=k){
        cout<<ans<<endl;
        return 0;
    }
    k-=b;
    if(c>=k){
        cout<<ans-k<<endl;
        return 0;
    }
    ans-=c;
    cout<<max(0ll,ans)<<endl;
}


Measured memory_bytes: 3652
/*
 * FileName:     depth_first_search_fix
 * CreatedDate:  2020-04-23 23:10:09 +0900
 * LastModified: 2020-04-24 00:14:45 +0900
 */

#include <stdio.h>
#include <string.h>

void dfs(int u,int *order,int *din,int *matrix,int *color,int n){
    color[u]=1;
    din[u]=*order;
    *order=*order+1;
    for(int v=0;v<n;v++){
        if(matrix[u*n+v]==1&&color[v]==0){
//            printf("%d->%d\n",u+1,v+1);
            din[v]=*order;
//            *order=*order+1;
            dfs(v,order,din,matrix,color,n);
            din[n+v]=*order;
            *order=*order+1;
        }
    }
}
int main(void){
    int n;
    scanf("%d",&n);
    int matrix[n*n];
    memset(matrix,0,sizeof(matrix));
    for(int i=0;i<n;i++){
        int u,k;
        scanf("%d",&u);
        scanf("%d",&k);
        for(int j=0;j<k;j++){
            int v;
            scanf("%d",&v);
            matrix[(u-1)*n+v-1]=1;
        }
    }
/*    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            printf("%d ",matrix[i*n+j]);
        }
        printf("\n");
    }*/
    int color[n];
    for(int i=0;i<n;i++){
        color[i]=0;
    }
    int din[n*2],a=1;
    int *order=&a;
    for(int i=0;i<n;i++){
        if(color[i]==0){
//            printf("%d\n",i);
            dfs(i,order,din,matrix,color,n);
            din[n+i]=*order;
            *order+=1;
        }
    }
    for(int i=0;i<n;i++){
        printf("%d %d %d\n",i+1,din[i],din[n+i]);
    }
/*    for(int i=0;i<n;i++){
        printf("%d ",din[i]);
    }
    printf("\n");
    for(int i=0;i<n;i++){
        printf("%d ",din[n+i]);
    }*/
    return 0;
}



Measured memory_bytes: 2052
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>

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

using namespace std;
typedef long long int ll;
const int INF = 100000000;

int main()
{
    int n;
    int a[100];
    cin >> n;
    rep(i, n) cin >> a[i];

    double denominator = 0.0;
    rep(i, n) {
        denominator += 1.0 / static_cast<double>(a[i]);
    }
    cout << 1.0 / denominator << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<string>
#include<vector>
using namespace std;

int main(void){
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a + 3);
	cout << abs(a[0] - a[1]) + abs(a[1] - a[2]);
	
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cfloat>
#include <vector>
using namespace std;

#define v vector

struct OBST {
	typedef vector<double> vd;
	vd p, q;
	v<vd> e, w;

	void read(int n) {
		p.resize(n + 1);
		q.resize(n + 1);
		for (int i = 1; i <= n; i++)
			scanf("%lf", &p[i]);
		for (int i = 0; i <= n; i++)
			scanf("%lf", &q[i]);
	}

	double cost(int n) {
		e = v<vd>(n + 2, vd(n + 1));
		w = v<vd>(n + 2, vd(n + 1));
		for (int i = 0; i <= n; i++) {
			e[i + 1][i] = q[i];
			w[i + 1][i] = q[i];
		}
		for (int l = 1; l <= n; l++)
			for (int i = 1; i <= n - l + 1; i++) {
				int j = i + l - 1;
				e[i][j] = DBL_MAX;
				w[i][j] = w[i][j - 1] + p[j] + q[j];
				for (int r = i; r <= j; r++)
					e[i][j] = min(e[i][j], e[i][r - 1] + e[r + 1][j] + w[i][j]);
			}
		return e[1][n];
	}
};

int main() {
	int n;
	scanf("%d", &n);
	OBST obst;
	obst.read(n);
	printf("%.8lf\n", obst.cost(n));
}



Measured memory_bytes: 6432
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <string>

using namespace std;

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

	int num = 0;
	for (int i = 1; i < 1e8; i++) {
		num = num * 10 + 7;
		num %= k;

		if (num == 0) {
			cout << i << endl;
			return 0;
		}

	}
	cout << -1 << endl;
	return 0;
}


Measured memory_bytes: 3192
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;

pub fn gcd(a: u64, b: u64) -> u64 {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}
pub fn lcm(a: u64, b: u64) -> u64 {
    a / gcd(a, b) * b
}

fn count(a: u64, b:u64, c:u64) -> u64 {
    let lb = b/c;
    let la = (a-1)/c;
    return lb-la;
}

fn main() {
    input!{
      a: u64,
      b: u64,
      c: u64,
      d: u64,
    }
    let e = lcm(c, d);

    let v1 = count(a, b, c);
    let v2 = count(a, b, d);
    let v3 = count(a, b, e);
    let ans = v1+v2-v3;
    println!("{}", b-a+1-ans);
}


Measured memory_bytes: 4352
#include <algorithm>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

vector<vector<LL>> d;

void warshal_floyd(int V) {
  for (int k = 0; k < V; ++k) {
    for (int i = 0; i < V; ++i) {
      for (int j = 0; j < V; ++j) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
}

int main() {
  int N, M, R; cin >> N >> M >> R;
  d.resize(N, vector<LL>(N, 1e18));

  vector<int> r(R);
  for (int i = 0; i < R; ++i) {
    cin >> r[i];
    --r[i];
  }

  for (int i = 0; i < N; ++i) d[i][i] = 0;
  for (int i = 0; i < M; ++i) {
    LL a, b, t; cin >> a >> b >> t;
    --a, --b;
    d[a][b] = min(d[a][b], t);
    d[b][a] = min(d[b][a], t);
  }

  warshal_floyd(N);

  LL vmin = LLONG_MAX;

  sort(r.begin(), r.end());
  do {
    LL cost = 0;
    for (int j = 1; j < R; ++j) cost += d[r[j-1]][r[j]];
    vmin = min(vmin, cost);
  } while(next_permutation(r.begin(), r.end()));

  cout << vmin << endl;
}


Measured memory_bytes: 512
#include <cstdio>
#include <cstdlib>
#include <cstring>

struct Node
{
    int key;
    Node *next, *prev;
};

Node *nil;

Node *listSearch(int key)
{
    Node *cur = nil->next;
    while (cur != nil && cur->key != key)
    {
        cur = cur->next;
    }
    return cur;
}

void init()
{
    nil = (Node *)malloc(sizeof(Node));
    nil->next = nil;
    nil->prev = nil;
}

void printList()
{
    Node *cur = nil->next;
    int isf = 0;
    while (1)
    {
        if (cur == nil)
            break;
        if (isf++ > 0)
            printf(" ");
        printf("%d", cur->key);
        cur = cur->next;
    }
    printf("\n");
}

void deleteNode(Node *t)
{
    if (t == nil)
        return;
    t->prev->next = t->next;
    t->next->prev = t->prev;
    free(t);
}

void deleteFirst()
{
    deleteNode(nil->next);
}

void deleteLast()
{
    deleteNode(nil->prev);
}

void deleteKey(int key)
{
    deleteNode(listSearch(key));
}

void insert(int key)
{
    Node *x = (Node *)malloc(sizeof(Node));
    x->key = key;
    x->next = nil->next;
    nil->next->prev = x;
    nil->next = x;
    x->prev = nil;
}

int main()
{
    int key, n, i;
    int size = 0;
    char com[20];
    int np = 0, nd = 0;
    scanf("%d", &n);
    init();
    for (i = 0; i < n; i++)
    {
        scanf("%s%d", com, &key);
        if (com[0] == 'i')
        {
            insert(key);
            np++;
            size++;
        }
        else if (com[0] == 'd')
        {
            if (strlen(com) > 6)
            {
                if (com[6] == 'F')
                    deleteFirst();
                else if (com[6] == 'L')
                    deleteLast();
            }
            else
            {
                deleteKey(key);
                nd++;
            }
            size--;
        }
    }

    printList();
    return 0;
}


Measured memory_bytes: 34016
package main
import (
   "fmt"
   "os"
   "bufio"
   "strconv"
)
var sc = bufio.NewScanner(os.Stdin)

func main() {
  sc.Split(bufio.ScanWords)
  n := nextInt()
  i := 1
  result := ""
  for i <= n {
    x := i
    if x % 3 == 0 {
		result = result + " " + strconv.Itoa(i)
		i++
		continue
    }
	if x % 10 == 3 {
		result = result + " " + strconv.Itoa(i)
		i++
		continue
    }
	x = x / 10
	for x > 0 {
        if x % 10 == 3 {
	        result = result + " " + strconv.Itoa(i)
			break
        } else {
	        x = x / 10
		}
	}
	i++
  }
  fmt.Println(result)

}

func getStdin() (string) {
	sc.Scan()
	v := sc.Text()
	return v
}

func nextInt() (int) {
	sc.Scan()
	v, e := strconv.Atoi(sc.Text())
    if e != nil { panic(e) }
    return v
}

func nextFloat() (float64) {
	sc.Scan()
	v, e := strconv.ParseFloat(sc.Text(), 64)
    if e != nil { panic(e) }
    return v
}



Measured memory_bytes: 7204
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())

D = float(abs(A-B))
E = float(V - W)

if E <= 0:
	print("NO")
	exit()
time = D/E
if time <= T:
	print("YES")
else:
	print("NO")

Measured memory_bytes: 9180
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const double PI = 3.14159265358979323846;

int main() {
  char x, y;
  cin >> x >> y;
  if(x == y) cout << "=" << endl;
  else if(x > y) cout << ">" << endl;
  else if(x < y) cout << "<" << endl;
}

Measured memory_bytes: 3588
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

void dfs(vector<string>& m,int i,int j,int w,int h,bool isb){
  int di[]={1,0,-1,0};
  int dj[]={0,1,0,-1};
  for(int k=0;k<4;++k){
    int ni=i+di[k];
    int nj=j+dj[k];
    if(ni<0||ni>=h||nj<0||nj>=w)continue;
    if(m[ni][nj] == '.'){
      if(isb){
        m[ni][nj] = 'b';
      }else{
        m[ni][nj] = 'w';
      }
      dfs(m,ni,nj,w,h,isb);
    }else if(isb && m[ni][nj] == 'w'){
      m[ni][nj] = '*';
      dfs(m,ni,nj,w,h,isb);
    }else if(!isb && m[ni][nj] == 'b'){
      m[ni][nj] = '*';
      dfs(m,ni,nj,w,h,isb);
    }
  }
}

int main() {
  while(1){
    int w,h;
    cin>>w>>h;
    if(w==0)break;
    vector<string> m(h);
    for(int i=0;i<h;++i)
      cin>>m[i];
    for(int i=0;i<h;++i)
      for(int j=0;j<w;++j)
        if(m[i][j]=='W' || m[i][j]=='B')
          dfs(m,i,j,w,h,m[i][j]=='B');
    int bn=0,wn=0;
    for(int i=0;i<h;++i)
      for(int j=0;j<w;++j){
        if(m[i][j]=='b')
          ++bn;
        else if(m[i][j]=='w')
          ++wn;
      }
    cout<<bn<<' '<<wn<<endl;
  }
  return 0;
}

Measured memory_bytes: 1384
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            int SN = S(N);
            System.out.println(N % SN == 0 ? "Yes" : "No");
        }
    }

    private static int S(int n) {
        int s = 0;
        while (n != 0) {
            s += n % 10;
            n /= 10;
        }
        return s;
    }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
#define fr(i,a,b) for(ll i=a; i<b; i++)
#define rf(i,a,b) for(ll i=a; i>=b; i--)
#define pb push_back
#define mp make_pair
#define show(a) for(auto el:a)cout<<el<<" "
#define ff first
#define ss second
#define pair vector<pair<ll,ll>>
#define vec vector <ll> 
#define all(a) a.begin(),a.end()
#define mo 1000000007




int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
   
        char s[10001];
        ll n,i,j=0;
        cin>>s;
        n=strlen(s);
        ll su;
        vector<ll> v;
         ll c=0;
        for(i=0;i<n;i++)
        {
           c=0;
            if(s[i]=='R')
            {
                for(j=i;j<n;j++)
                {
                     if(s[j]=='S')
                   {
                       v.pb(c);
                       c=0;
                       break;
                   }
                    c++;
                   // cout<<j<<" ";
                  
                }
    
                i=j-1;
            }
            if(j==n && s[n-1]=='R')
            {
                v.pb(c);
                break;
            }
        }
        sort(all(v));
        reverse(all(v));
        ll k=v.size();
        if(k==0)
        su=0;
        else
        su=v[0];
     
        cout<<su<<"\n";
        
        

    
     return 0;
}


Measured memory_bytes: 3612
#include<iostream>
#include <cassert>
using namespace std;
#define N 8
#define FREE -1
#define NOT_FREE 1

int row[N],col[N],dpos[2*N-1],dneg[2*N-1];
bool X[N][N];

void initialize(){
  for(int i=0;i<N; i++){row[i]=FREE,col[i]=FREE;}
  for(int i=0;i<2*N-1;i++){dpos[i]=FREE;dneg[i]=FREE;}
}

void printBoard(){
  for(int i=0;i<N;i++){
	for(int j=0;j<N;j++){
	  if(X[i][j]){
		if(row[i]!=j) return;
	  }
	}
  }
  for(int i=0;i<N;i++){
	for(int j=0;j<N;j++){
	  cout <<((row[i]==j)? "Q":".");
	}
	cout<<endl;
  }
}
void recursive(int i){
  if(i==N){
	printBoard(); return;
}

for(int j=0;j<N;j++){
  if(NOT_FREE==col[j] ||
	 NOT_FREE==dpos[i+j] ||
	 NOT_FREE==dneg[i-j+N-1]) continue;
  row[i]=j; col[j]=dpos[i+j]=dneg[i-j+N-1]=NOT_FREE;
  recursive(i+1);
  row[i]=col[j]=dpos[i+j]=dneg[i-j+N-1]=FREE;
 }
}

int main(){
  initialize();
  for(int i=0;i<N;i++)
	for(int j=0;j<N;j++) X[i][j]=false;
  int k; cin >> k;
  for(int i=0;i<k;i++){
	int r,c; cin>>r>>c;
	X[r][c]=true;
  }
  recursive(0);
  return 0;
}



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

int main(){
    int i;
    int K,N;
    cin >> K >> N;
    int A[N];
    int tmp = 0;
    for(i=0;i<N;i++)cin >> A[i];
    for(i=1;i<N;i++)if(tmp<A[i]-A[i-1])tmp=(A[i]-A[i-1]);
    if(tmp<K-A[N-1]+A[0])tmp=K-A[N-1]+A[0];
    cout << K-tmp << endl;
    }

Measured memory_bytes: 1024
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<chrono>//実行時間計測
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm,accumulate
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//順序保持しないmap
#include<unordered_set>//順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() 
#define SIZE(x) ll(x.size()) 
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

#define int long long

#define VI vector<int> 
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//ここに関数定義や変数宣言



//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
signed main(){
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int x[10],y[10],N;

long double didi=0; //距離の２乗

cin>>N;

int num[N];

REP(i,N){cin>>x[i]>>y[i];    num[i]=i;}

do{
REP(i,N-1){

	didi +=  sqrt(  (x[  num[i+1] ]-x[  num[i] ]) * (x[  num[i+1] ]-x[  num[i] ]) + (y[  num[i+1] ]-y[  num[i] ]) * (y[  num[i+1] ]-y[  num[i] ]) ) ;
	
} } while(next_permutation(num,num+N));

long double all=1;
long double avr=0;
for (int i = 1; i <= N; ++i)
{
	all*=i;
}


avr = didi/all;


printf("%.10Lf\n\n", avr);






}

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

int main(){
 int n;
 cin>>n;
 if (n>=1000)
 {
     cout<<"ABD"<<endl;
 }
 else
 {
     cout<<"ABC"<<endl;
 }
 
 

}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <functional>
#include <cstring>

using namespace std;

template <class T> bool chmax(T &a, const T &b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
template <class T> bool chmin(T &a, const T &b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

typedef pair<int, int> P;
#define mp make_pair
#define FOR(i, a, b) for(int (i)=a;(i)<(b);++(i))
#define rep(i, n)  FOR(i,0,n)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort((v).begin(), (v).end());					//小さい順
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());		//大きい順
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define all(c) (c).begin(),(c).end()
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define Print(p) cout<<(p)<<endl
#define F first
#define S second
#define pb push_back
#define mod 1000000007LL
#define INF 12345678901234567

const int maxn = 1e5 + 10;
ll x[maxn];
ll y[maxn];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	// your code is here

	string a, b; cin >> a >> b;
	
	if (a == b) Print('H');
	else Print('D');

	return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <limits>
#include <algorithm>
#include <utility>
#include <sstream>
#include <numeric>
#include <iterator>

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef pair<int, int> P;

int main(int argc, const char * argv[]) {
  vector<int> abc(3);
  cin >> abc[0] >> abc[1] >> abc[2]; 
  // rep(i, 3){
    // cin >> abc[i];
  // }
  sort(abc.begin(), abc.end());
  // rep(i, 3){
  //   cout << abc[i] << endl;
  // }

  if (abc[0] == abc[1]){
    if(abc[1] != abc[2]){
      cout << "Yes" << endl;
      return 0;
    }
  }
  if (abc[1] == abc[2]){
    if(abc[1] != abc[0]){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 888
n = int(input())
weight_list = [ int(v) for v in input().split() ]
s1 = weight_list[0]
s2 = sum(weight_list) - s1

ans = abs(s2-s1)

for i in range(n-2):
	a = weight_list[i+1]
	s1 += a
	s2 -= a

	ans = min(ans,abs(s2-s1))
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;

int main(){
   int n;
   cin >> n;
   for(int i=1; i<=n; i++){
      if(i%3 == 0){
         printf(" %d",i);
      }
      else if(i%10 == 3){
         printf(" %d",i);
      }
      else{
         for(int x=i; x>10;){
            x = x/10;
            if(x == 3 || x%10 == 3){
               printf(" %d",i);
               break;
            }
         }
      }
   }
   printf("\n");

   return 0;
}



Measured memory_bytes: 3236
n,m=map(int,input().split())
py=[[-1,-1,-1]]
for i in range(m):
	x,y=map(int,input().split())
	py.append([x,y,i])
py.sort()
x=[]
cnt=1
for i in range(1,m+1):
	d=""
	if py[i-1][0]==py[i][0]:
		cnt+=1
	else:
		cnt=1
	d+="0"*+(6-len(str(py[i][0])))+str(py[i][0])
	d+="0"*(6-len(str(cnt)))+str(cnt)
	x.append([d,py[i][2]])
x.sort(key=lambda x:x[1])
for i in range(m):
	print(x[i][0])



Measured memory_bytes: 41340
n,m,c=map(int,input().split())
b=[int(i) for i in input().split()]
ans=0
for i in range(n):
    a=[int(i) for i in input().split()]
    chk=c
    for  j in range(m):
       chk+=b[j]*a[j]
    if chk>0: ans+=1
print(ans)

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

long long int mod = pow(10,9)+7;

int main(){
    int N,K;
    cin >> N >> K;

    long long int u=0;
    long long int o=0;
    long long int sum=0;
    for(int i=1;i<=N+1;i++){
        u=((u+i)%mod-1)%mod;
        o=(((o+N)%mod+1)%mod-i)%mod;
        if(i>=K){
            sum = (((sum + o)%mod-u)%mod+1)%mod;
        }
    }

    if(sum<0){sum = sum + mod;}

    cout << sum << endl;

    return 0;

}

Measured memory_bytes: 3636
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	
	void run() throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int N = Integer.parseInt(br.readLine());
		String[] stringArray = br.readLine().split(" ");
		int[] lineArray = new int[N];
		for(int i = 0; i < lineArray.length; i++) {
			lineArray[i] = Integer.parseInt(stringArray[i]);
		}
		editLine(lineArray);
		insertionSort(lineArray, N);
	}
	
	void insertionSort(int[] A, int N) {
	   for(int i = 1; i <= N - 1; i++) { 
	     int v = A[i];
	     int j = i - 1;
	     while(j >= 0 && A[j] > v) {
	     	A[j+1] = A[j];
	     	j--;
	     	A[j+1] = v;
	     }
	   editLine(A);
	   }
	}
	
	void editLine(int[] A) {
		for(int k = 0; k < A.length; k++) { 
			if(k != A.length - 1) {
				System.out.print(A[k] + " ");
			} else {
				System.out.println(A[k]);
			}
		}
	}

	public static void main(String[] args) throws IOException {
		new Main().run();
	}
}

Measured memory_bytes: 31432
#include<bits/stdc++.h>
//#include<atcoder/all>

using namespace std;
//using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007

template<typename T,typename E>
class LazySegtree{
  public:
  using F = function<T(T,T)>;
  using G = function<T(T,E)>;
  using H = function<E(E,E)>;
  int n,height;
  F f;
  G g;
  H h;
  T ti;
  E ei;
  vector<T> dat;
  vector<E> laz;
  LazySegtree(F f,G g,H h,T ti,E ei) : f(f),g(g),h(h),ti(ti),ei(ei){}
  void init(int N){
    n = 1;height = 0;
    while(n < N)n <<= 1,height++;
    dat.assign(n << 1,ti);
    laz.assign(n << 1,ei);
  }
  void build(const vector<T> &v){
    int N = v.size();
    init(N);
    rep(i,N)dat[i+n] = v[i];
    for(int i = n-1;i > 0;i--)dat[i] = f(dat[(i << 1)|0],dat[(i << 1)|1]);
  }
  inline void eval(int k){
    if(laz[k] == ei)return ;
    laz[(k<<1)|0] = h(laz[(k << 1)|0],laz[k]);
    laz[(k<<1)|1] = h(laz[(k << 1)|1],laz[k]);
    dat[k] = reflect(k);
    laz[k] = ei;
  }
  inline void thrust(int k){
    for(int i = height;i > 0;i--)eval(k>>i);
  }
  inline T reflect(int k){
    return laz[k] == ei ? dat[k] : g(dat[k],laz[k]);
  }
  inline void recalc(int k){
    while(k >>= 1)dat[k] = f(reflect((k<<1)|0),reflect((k<<1)|1));
  }
  void update(int a,int b,E x){
    thrust(a+=n);
    thrust(b+=n-1);
    for(int l = a,r = b+1;l < r;l >>= 1,r >>= 1){
      if(l & 1)laz[l] = h(laz[l],x),l++;
      if(r & 1)r--,laz[r] = h(laz[r],x);
    }
    recalc(a);
    recalc(b);
  }
  void set_val(int k,T x){
    thrust(k+=n);
    dat[k] = x;laz[k] = ei;
    recalc(k);
  }
  T get(int a,int b){
    thrust(a+=n);
    thrust(b+=n-1);
    T vl = ti,vr = ti;
    for(int l = a,r = b+1;l < r;l >>= 1,r >>= 1){
      if(l & 1)vl = f(vl,reflect(l++));
      if(r & 1)vr = f(reflect(--r),vr);
    }
    return f(vl,vr);
  }
};

struct info{
  ll cnt,bit,len;
};

int main(){
  
  int n,Q;
  cin >> n >> Q;
  vector<info> v(n,info{0,0,1});
  rep(i,n)cin >> v[i].bit;
  auto f = [](info a,info b){
    ll cnt = a.cnt+b.cnt;
    cnt += (b.len-b.bit)*a.bit;
    return info{cnt,a.bit+b.bit,a.len+b.len};
  };
  auto g = [](info a,bool b){
    if(b){
      a.bit = a.len-a.bit;
      a.cnt = (a.len-a.bit)*a.bit-a.cnt;
    }
    return a;
  };
  LazySegtree<info,bool> seg(f,g,
    [](bool a,bool b){return ((a && b) ? false : (a || b));},
    info{0,0,0},false
    );
  seg.build(v);
  while(Q--){
    int t,l,r;cin >> t >> l >> r;
    if(t == 1){
      seg.update(--l,r,true);
    }else{
      cout << seg.get(--l,r).cnt << "\n";
    }
  }


  return 0;
}

Measured memory_bytes: 20412
module Main where

import Data.List

main = do
    getLine
    putStrLn =<< solve <$> readInts

readInts :: IO [Int]
readInts = (sort . (map read) . words) <$> getLine

solve :: [Int] -> String
solve [] = "APPROVED"
solve (x:xs)
    | mod x 2 == 1 = solve xs
    | mod x 3 == 0 = solve xs
    | mod x 5 == 0 = solve xs
    | otherwise = "DENIED"



Measured memory_bytes: 1020
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int N,K;
    cin >>N >> K;
    if(N>=K)
    {
        cout << 0 <<endl;
        return 0;
    }
    double answer;
    int h[K];
    int dis[K-1];
    int max_dis =0;
    int sum_dis = 0;

    for (int i = 0;i<K;i++)
    {
        cin >> h[i];
     
    }
    sort(h,h+K);
   for(int i=0;i<K-1;i++)
   {
       dis[i] = h[i+1]-h[i];
       
       sum_dis += dis[i];
   }
   sort(dis,dis+K-1);
   for (int i = K-N;i<K-1;i++)
   {
       max_dis += dis[i];
   }
    cout << sum_dis - max_dis;
    
return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include<numeric>
#include<cmath>
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    //cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	//cout << fixed << setprecision(15);
    int N,W; cin>>N>>W;
    vector<int> v(N), w(N);
    REP(i,N) cin>>v[i]>>w[i];

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


Measured memory_bytes: 6836
// Ver19.03
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF (1 << 29) * 2
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  char s[110], t[110], u[1100];
  scanf("%s%s", s, t);
  sprintf(u, "%s%s", t, s);
  printf("%s\n", u);
}

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

int main(void){
    int H,W;
    while(true){
        cin >> H >> W;
        if(H==0 && W==0){
            break;
        }
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                cout << '#';
            }
            cout << endl;
        }
        cout << endl;
    }
}


Measured memory_bytes: 3072
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
signed main(){
  string s;
  cin >> s;
  ll c=0;
  if(s=="SAT"){
    c=1;
  }
  if(s=="FRI"){
    c=2;
  }
  if(s=="THU"){
    c=3;
  }
  if(s=="WED"){
    c=4;
  }
  if(s=="TUE"){
    c=5;
  }
  if(s=="MON"){
    c=6;
  }
  if(s=="SUN"){
    c=7;
  }
  cout << c << endl;
}


Measured memory_bytes: 256
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

int main() {
  int N, K;
  cin >> N >> K;

  vector<ll> lst(N);
  for (int i = 0; i < N; i++) {
    cin >> lst[i];
  }

  vector<ll> dp(N, 0);

  for (int i = 1; i < N; i++) {
    ll m = LONG_LONG_MAX;
    for (int j = 1; j <= K; j++) {
      if (i >= j) {
        ll tmp = abs(lst[i] - lst[i - j]) + dp[i - j];
        m = min(tmp, m);
      }
    }
    dp[i] = m;
  }

  cout << dp[N-1] << endl;

  return 0;
}


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

int main(){
    ll n, a, b;
    cin >> n >> a >> b;
    ll ans = 0;
    ans += n / (a + b) * a;
    ans += min(n % (a + b), a);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
import numpy as np

a, v = map(int, input().strip().split())
b, w = map(int, input().strip().split())
t = int(input())

dis = abs(b-a)
hayasa = v-w
ikeru = 0
if hayasa<= 0:
    pass
else:
    if t*hayasa >= dis:
        ikeru = 1
    else:
        pass

if ikeru == 1:
    print("YES")
else:
    print("NO")


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

int main() {
	int N;
	cin >> N;
	int ans = 0, t = 0;

	for (int i = 0; i < N; i++) {
		int D1, D2;
		cin >> D1 >> D2;
		if (D1 == D2) {
			ans++; 
			if (ans >= 3) t = 1;
		}else ans = 0;
	}

	if (t == 1) cout << "Yes" << endl;
	else cout << "No" << endl;
	

	return 0;

}

Measured memory_bytes: 3620
from math import hypot
N, K = map(int, input().split())
def count(x, y, T, cs):
    r = 0
    for a, b, c in cs:
        r += int(hypot(x-a, y-b) <= T/c + 10**-8)
#    print(x, y, r)
    return r

def ko(x1, y1, r1, r2):
    # x^2+y^2=r1, (x-x1)^2+(y-y1)^2=r2
    a = (x1**2 + y1**2 + r1**2 - r2**2)/2

    t = (x1**2+y1**2)*r1**2-a**2
    if t < 0:
        return -1

    x = a*x1
    xb = y1*t**(1/2)
    y = a*y1
    yb = x1*t**(1/2)
    b = x1**2+y1**2
    return ((x+xb)/b, (y-yb)/b), ((x-xb)/b, (y+yb)/b)

def zko(x1, y1, r1, x2, y2, r2):
    r = ko(x2-x1, y2-y1, r1, r2)
    if r == -1:
        return -1
    (xp, yp), (xm, ym) = ko(x2-x1, y2-y1, r1, r2)
    return (xp+x1, yp+y1), (xm+x1, ym+y1)

def f(T, cs):
    ccs = []
    for i in range(N):
        (xi, yi, ci) = cs[i]
        for j in range(i+1, N):
            (xj, yj, cj) = cs[j]
            r = zko(xi, yi, T/ci, xj, yj, T/cj)
#            r =  gm.get_cross_pointCC((xi, yi, T/ci), (xj, yj, T/cj))
            if r == -1:
                continue
            (x1, y1), (x2, y2) = r
#            print(x1, y1, x2, y2)
            ccs.append((x1, y1))
            ccs.append((x2, y2))
    for a, b, c in cs:
        ccs.append((a, b))
#    print(ccs)
    for x, y in ccs:
        if count(x, y, T, cs) >= K:
            return True
    return False

#print(ko(0, 1, 1, 1))
#print(zko(1, 0, 1, 1, 1, 1))
#print(zko(0,1,5,4,3,5**0.5))
cs = []
for i in range(N):
    x, y, c = map(int, input().split())
    cs.append((x, y, c))
mx, mn = 10**9, -1
idx = mx/2
for _ in range(100):
    if f(idx, cs):
        idx, mx = (idx+mn)/2, idx
        continue
    idx, mn = (idx+mx)/2, idx
print(idx)

#print(f(2.97, cs))
#
#for i in range(741100,741200):
#    j = i * 100
#    j = i/100
#    print(j, f(j, cs))

#print(f(10411.3, cs))
#for i in range(N):
#    (xi, yi, ci) = cs[i]
#    for j in range(i+1, N):
#        (xj, yj, cj) = cs[j]


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

lint gcd(lint x, lint y) {
  if(x == 0) { return y; }
  else { return gcd(y%x,x); }
}

lint lcm(lint x, lint y) { return x/gcd(x,y)*y; }

lint C(lint n, lint k) {
  if(n == k) { return 1; }
  else if(n < k) { return 0; }
  else if(k == 0) { return 1; }
  else if(k == 1) { return n; }
  else return C(n-1,k-1) + C(n-1,k);
}

lint P(lint n, lint k) {
  if(k == 1) { return n; }
  return (n*(P(n-1,k-1)%1000000007)%1000000007);
}


int main() {
  lint n; cin >> n;
  
  lint ans=10;
  for(lint i=1;i*i<=n;i++) {
    if(n%i == 0) {
      stringstream ss;
      ss << n/i;
      ans = min(ans,(lint)ss.str().size());
    }
  }

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


Measured memory_bytes: 256
n = int(input())
h = list(map(int,input().split()))
ans = 0
temp = 0
for i in range(n-1):
    if h[i] >= h[i+1]:
        temp += 1
    else:
        if temp > ans:
            ans = temp
        temp = 0
if temp > ans:
    ans = temp
print(ans)


Measured memory_bytes: 14252
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b,c,d;
    int e[55]={};
    cin>>a>>b;
    for(int z=0;z<b;z++){
        cin>>c>>d;
        e[c]++;
        e[d]++;
    }
    for(int z=1;z<a+1;z++){
        cout<<e[z]<<endl;
    }
}


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

int heap_size = 0;

void maxHeapify(int* array, int i) {
    int l, r, largest;
    int work;
     
    l = i * 2;
    r = i * 2 + 1;
     
    if (l <= heap_size && array[l] > array[i]) {
        largest = l;
    } else {
        largest = i;
    }
     
    if (r <= heap_size && array[r] > array[largest]) {
        largest = r;
    }
     
    if (largest != i) {
        work = array[i];
        array[i] = array[largest];
        array[largest] = work;
        maxHeapify(array, largest);
    }
}

void heapIncreaseKey(int* array, int i, int key) {
	int work;
	
	array[i] = key;
	while (i > 1 && array[i / 2] < array[i]) {
		work = array[i];
		array[i] = array[i / 2];
		array[i / 2] = work;
		i = i / 2;
	}
}

void maxHeapInsert(int* array, int key) {
	
	heap_size++;
	array[heap_size] = -1;
	heapIncreaseKey(array, heap_size, key);
}

int heapExtractMax(int* array) {
	long max;
	max = array[1];
	array[1] = array[heap_size];
	heap_size--;
	maxHeapify(array, 1);
	return max;
}

int main(void) {
	char com[10];
	int heap[2000000];
	int arg;
	
	
	while (1) {
		scanf("%s", com);
		if (com[0] == 'i') {
			scanf("%d", &arg);
			maxHeapInsert(heap, arg);
		} else if (com[1] == 'x') {
			printf("%d\n", heapExtractMax(heap));
		} else {
			break;
		}
	}
	
	return 0;
}

Measured memory_bytes: 5700