akhauriyash/Code-Regression huggingface dataset:
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

const int MOD = 1000000007, INF = 1111111111;
using namespace std;
using lint = long long;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (int i = 0; i < (int)vec.size(); i++) {
		os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	}
	return os;
}

#ifdef _DEBUG
template <class Head>
void dump(const char* str, Head &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + 1, t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

class UnionFind {
private:
	vector<int> data;
	int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }

public:
	UnionFind(int size) : data(size, -1) { }
	bool is_same(int x, int y) { return root(x) == root(y); }
	int size(int x) { return -data[root(x)]; }

	void unify(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
};

template<class T = lint>
struct Edge {
	int from, to;
	T cost;
	Edge() {}
	Edge(int from, int to, T cost) : from(from), to(to), cost(cost) {}
	bool operator>(const Edge &r) const { return this->cost > r.cost; }
};

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;

	struct town { int x, y, idx; };
	vector<town> t(N);
	for (int i = 0; i < N; i++) {
		cin >> t[i].x >> t[i].y;
		t[i].idx = i;
	}

	// 辺のをすべてpriority_queに入れる
	priority_queue<Edge<>, vector<Edge<>>, greater<Edge<>>> pq;
	// xが近い同士
	sort(t.begin(), t.end(), [&](town r, town l) {return r.x < l.x; });
	for (int i = 0; i < N - 1; i++) pq.emplace(t[i].idx, t[i + 1].idx, t[i + 1].x - t[i].x);
	sort(t.begin(), t.end(), [&](town r, town l) {return r.y < l.y; });
	for (int i = 0; i < N - 1; i++) pq.emplace(t[i].idx, t[i + 1].idx, t[i + 1].y - t[i].y);

	// kruskal法
	UnionFind uf(N);
	lint ans = 0;
	while (!pq.empty()) {
		
		auto now = pq.top(); pq.pop();

		if (!uf.is_same(now.from, now.to)) {
			uf.unify(now.from, now.to);
			ans += now.cost;
		}
	
	}

	assert(uf.size(0) == N);

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 7664
#include<bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define F first
#define S second
 
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define int long long
#define ll long long
 
 
	
void solve(){
	int n, k;
	cin >> n >> k;
	int a[n + 1], dp[n + 1] = {};
	for(int i = 1 ; i <= n ; i++){
		cin >> a[i];		
	}
	dp[1] = 0;
	for(int i = 2 ; i <= n ; i++){
		dp[i] = LLONG_MAX;
		for(int j = i - 1 ; j >= max(1ll, i - k) ; j--){
			dp[i] = min(dp[i], dp[j] + abs(a[i] - a[j]));
		}	
	}
	cout << dp[n];
}
 
signed main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t = 1;
	//cin >> t;
	while(t--)
		solve();
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define int long long int 
signed main()
{
    int n,k;
    cin>>n>>k;
    int d[k],v[10]={0};
    for(int i=0;i<k;i++)
    {
        cin>>d[i];
        v[d[i]]=1;
    }
    
    for(int i=n;i<1001001;i++)
    {
        int f=0;
        string s=to_string(i);
        for(int j=0;j<s.size();j++)
        {
            if(v[s[j]-'0']==1)
            {
                f=1;
                break;
            }
        }
        if(f)
        continue;
        else
        {
            cout<<i<<endl;
            return 0;
        }
    }
    
}

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

using ll = long long int;

const int MAX_N = (int)1e5 + 5;

int n;
int a[MAX_N], b[MAX_N];
ll c[MAX_N];
int q, k;
int x[MAX_N], y[MAX_N];

vector<vector<pair<int, ll>>> graph(MAX_N);

bool visited[MAX_N];
ll path[MAX_N];
queue<pair<int, ll>> que;

int main(void){
  // Here your code !
  scanf("%d", &n);
  for (int i = 0; i < n - 1; ++i) {
    scanf("%d %d %lld", &a[i], &b[i], &c[i]);
    graph[a[i]].push_back(make_pair(b[i], c[i]));
    graph[b[i]].push_back(make_pair(a[i], c[i]));
  }
  scanf("%d %d", &q, &k);
  for (int i = 0; i < q; ++i) {
    scanf("%d %d", &x[i], &y[i]);
  }

  fill(visited, visited + n + 5, false);

  que.push(make_pair(k, 0));
  while (!que.empty()) {
    int curv = que.front().first;
    ll curc = que.front().second;
    que.pop();

    if (visited[curv]) continue;

    for (int i = 0; i < graph[curv].size(); ++i) {
      que.push(make_pair(graph[curv][i].first, curc + graph[curv][i].second));
    }

    path[curv] = curc;
    visited[curv] = true;
  }

  for (int i = 0; i < q; ++i) {
    printf("%lld\n", (path[x[i]] + path[y[i]]));
  }

  return 0;
}

Measured memory_bytes: 13296
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,p;
    cin>>n;
    std::deque<int> deq;
    for (int i=0;i<n;i++) {
        cin>>p;
        deq.emplace_back(p);
    }
    sort(deq.begin(),deq.end(),greater<int>());
    int sum=0;
    for (int j=0;j<n;j++) {
        if (j==0) {
            sum+=deq[j]/2;
        } else {
            sum+=deq[j];
        }
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using st=string;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
st abc="abcdefghijklmnopqrstuvwxyz";
st ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};


int main() {
    ll D;
    cin >> D;
    vl c(26);
    rep(i,26){
        cin >> c[i];
    }
    ll s[D][26];
    rep(i,D){
        rep(j,26){
            cin >> s[i][j];
        }
    }
    vl latest_t(26,0);
    ll k=0;
    FOR(i,1,D+1){
        vl nt=latest_t;
        ll nk=k;
        ll MX=-INF;
        ll ans;
        rep(j,26){
            nt=latest_t;
            nk=k;
            nk+=s[-1+i][j];
            nt[j]=i;
            rep(l,26){
                nk-=c[l]*(i-nt[l]);
            }
            if(nk>MX){
                MX=nk;
                ans=j;
            }
            if(j==25){
                k=MX;
            }
        }
        cout << ans+1 << endl;
        latest_t[ans]=i;
        //cout << k << endl;
    }
}


Measured memory_bytes: 3716
/// kAAzuki Hoshino
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define inf 1000000000
#define mod 1000000007
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());



signed main(){
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
	
	int n,sum=0,ans=0;
	cin >> n;
	int a[n+2]={0};
	for(int i=1;i<=n;i++){
		cin >> a[i];
		sum+= a[i];
	}
	sort(a+1,a+n+1);
	for(int i=n;i>=1;i--){
		if(2*sum>=a[i+1]){
			ans++;
			sum-=a[i];
		}
		else break;
	}
	cout << ans << endl;

return 0;
}
///....


Measured memory_bytes: 1024
#include <iostream>
#define INF 1e+9
using namespace std;

int main(){
	int n,m;
	while(cin >> n >> m,n){
		int st[100],sh[100],sumt = 0,sumh = 0,mi = INF,a,b;
		for(int i = 0;i < n;i++){
			cin >> st[i];
			sumt += st[i];
		}
		for(int i = 0;i < m;i++){
			cin >> sh[i];
			sumh += sh[i];
		}
		for(int i = 0;i < n;i++){
			for(int j = 0;j < m;j++){
				if((sh[j] - st[i]) * 2 == sumh - sumt){
					if(mi > sh[j] + st[i]){
						a = i;
						b = j;
						mi = sh[j] + st[i];
					}
				}
			}
		}
		if(mi == INF) cout << -1 << endl;
		else cout << st[a] << " " << sh[b] << endl;
	}
	return 0;
}

Measured memory_bytes: 3096
def main() -> None:
    h1, m1, h2, m2, k = map(int, input().split())

    if h1 > h2:
        h2 += 24
    length = (h2*60+m2) - (h1*60+m1)
    print(max(0, length - k))

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9044
import Control.Applicative
import Control.Monad
import Data.List
import qualified Data.Map.Strict as M

f :: String -> [(Char, Int)]
f xs = fmap (\a@(y:_) -> (y, length a)) . group . sort $ xs

g :: String -> M.Map Char Int
g xs = M.fromList (f xs)

main :: IO ()
main = do
    n <- readLn
    xss <- replicateM n getLine
    let m1 = fmap g xss
    let m2 = foldr1 (M.intersectionWith min) m1
    let ans = sort . concat $ M.foldrWithKey (\k a acc -> replicate a k : acc) [] m2
    putStrLn ans

Measured memory_bytes: 1020
n, a, b, c, d = gets.strip.split.map(&:to_i)
s = gets.strip.split("")
s.insert(0,"0")

if s[a,c-a+1].join.match(/.*##.*/)
  puts "No"
  exit
end
if s[b,d-b+1].join.match(/.*##.*/)
  puts "No"
  exit
end

if c < d
  puts "Yes"
else
  if s[b-1,d-b+3].join.match(/.*\.\.\..*/)
    puts "Yes"
  else
    puts "No"
  end
end



Measured memory_bytes: 17972
#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define all(v) (v).begin(), (v).end()
#define eb emplace_back

int main(){
    int H, N;
    cin >> H >> N;
    int sum = 0;
    rep(i,N){
        int a; cin >> a;
        sum += a;
    }

    if(sum >= H) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define vii vector<pair<int,int>>



int main(){
    ios::sync_with_stdio(0);
    int n;
    cin >> n;
    int arr[n];
    bool ans = true;
    for (int i = 0 ; i < n ; ++i){
        cin >> arr[i];
        if (arr[i]%2==0){
            if (arr[i]%3!=0 && arr[i]%5!=0)
                ans = false;
        }
    }
    cout << (ans?"APPROVED":"DENIED");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    string ret = "";
    rep(i, tx - sx) ret += 'R';
    rep(i, ty - sy) ret += 'U';
    rep(i, tx - sx) ret += 'L';
    rep(i, ty - sy) ret += 'D';
    ret += 'D';
    rep(i, tx - sx + 1) ret += 'R';
    rep(i, ty - sy + 1) ret += 'U';
    ret += 'L';
    ret += 'U';
    rep(i, tx - sx + 1) ret += 'L';
    rep(i, ty - sy + 1) ret += 'D';
    ret += 'R';
    output(ret);
    
    return 0;
}


Measured memory_bytes: 256
N = int(input())
L = [1, 9, 30, 76, 141, 267, 400, 624, 885, 1249, 1590, 2208, 2689, 3411, 4248, 5248, 6081, 7485, 8530, 10248, 11889, 13687, 15228, 17988, 20053, 22569, 25242, 28588, 31053, 35463, 38284, 42540, 46581, 50893, 55362, 61824, 65857, 71247, 76884, 84388, 89349, 97881, 103342, 111528, 120141, 128047, 134580, 146316, 154177, 164817, 174438, 185836, 194157, 207927, 218812, 233268, 245277, 257857, 268182, 288216, 299257, 313635, 330204, 347836, 362973, 383709, 397042, 416448, 434025, 456967, 471948, 499740, 515581, 536073, 559758, 583960, 604833, 633651, 652216, 683712, 709065, 734233, 754734, 793188, 818917, 846603, 874512, 909496, 933081, 977145, 1006126, 1041504, 1073385, 1106467, 1138536, 1187112, 1215145, 1255101, 1295142, 1342852, 1373253, 1422195, 1453816, 1502376, 1553361, 1595437, 1629570, 1691292, 1726717, 1782111, 1827492, 1887772, 1925853, 1986837, 2033674, 2089776, 2145333, 2197483, 2246640, 2332104, 2379085, 2434833, 2490534, 2554600, 2609625, 2693919, 2742052, 2813988, 2875245, 2952085, 3003306, 3096024, 3157249, 3224511, 3306240, 3388576, 3444609, 3533637, 3591322, 3693924, 3767085, 3842623, 3912324, 4027884, 4102093, 4181949, 4270422, 4361548, 4427853, 4548003, 4616104, 4718640, 4812789, 4918561, 5003286, 5131848, 5205481, 5299011, 5392008, 5521384, 5610705, 5739009, 5818390, 5930196, 6052893, 6156139, 6239472, 6402720, 6493681, 6623853, 6741078, 6864016, 6953457, 7094451, 7215016, 7359936, 7475145, 7593865, 7689630, 7886244, 7984165, 8130747, 8253888, 8403448, 8523897, 8684853, 8802826, 8949612, 9105537, 9267595, 9376656, 9574704, 9686065, 9827097, 9997134, 10174780, 10290813, 10493367, 10611772, 10813692]
print(L[N-1])

Measured memory_bytes: 9384
program name
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32):: n,k,i,nk,ans
    integer(int32), allocatable:: a(:), cnt(:), num(:)

    read*, n,k
    allocate(a(n))
    read*, a(:)
    allocate(cnt(maxval(a)), source=0)

    do i=1,n
        cnt(a(i))=cnt(a(i))+1
    end do
    deallocate(a)

    nk=0
    do i=1,size(cnt)
        if (cnt(i) /= 0) nk=nk+1
    end do

    allocate(num(nk))
    nk=0

    do i=1,size(cnt)
        if (cnt(i) /= 0) then
            nk=nk+1
            num(nk)=cnt(i)
        end if
    end do
    deallocate(cnt)
    call merge_sort(num,1,nk)
    ans=0
    i=0
    do while (nk-i > k)
        i=i+1
        ans=ans+num(i)
    end do
    print'(i0)',ans
contains
    recursive subroutine merge_sort(ar, fst, lst)
        integer(4),intent(inout):: ar(:)
        integer(4),intent(in):: fst,lst
        integer(4):: mdl

        if (lst-fst < 2) then
            if (ar(fst) > ar(lst)) call swap(ar(fst),ar(lst))
            return
        end if

        mdl = (fst+lst)/2
        call merge_sort(ar, fst, mdl)
        call merge_sort(ar, mdl+1, lst)
        call merge_(ar, fst, mdl, lst)
    end subroutine

    subroutine merge_(ar, fst, mdl, lst)
        integer(4),intent(inout):: ar(:)
        integer(4),intent(in):: fst, mdl, lst
        integer(4),allocatable:: tmp(:)
        integer(4):: li, ri, ti

        allocate(tmp(lst-fst+1))

        li=fst
        ri=mdl+1   
        ti=1

        do while (li <= mdl .and. ri <= lst)
            if (ar(li) <= ar(ri)) then
                tmp(ti) = ar(li)
                li=li+1
            else
                tmp(ti) = ar(ri)
                ri=ri+1
            end if
            ti=ti+1
        end do

        if (li <= mdl) then
            tmp(ti:) = ar(li:mdl)
        else
            tmp(ti:) = ar(ri:lst)
        end if

        ar(fst:lst) = tmp(:)
        deallocate(tmp)
    end subroutine

    subroutine swap(x,y)
        integer(4),intent(inout):: x,y
        integer(4):: tmp
        tmp = x
        x = y
        y = tmp
    end subroutine
end program name

Measured memory_bytes: 2304
#include <cctype>
#include <cstdio>
#include <iostream>
#include <sstream>
#include <stack>
#include <string>
using namespace std;

stack<double>X;
int s2i(string s){
	stringstream ss(s);
	int d;
	ss>>d;
	return d;
}
double f(string s){
	double a,b,x;
	b=X.top();X.pop();
	a=X.top();X.pop();
	if(s=="+")x=a+b;
	else if(s=="-")x=a-b;
	else if(s=="*")x=a*b;
	else if(s=="/")x=a/b;
	return x;
}
int main(){
	string s;
	while(getline(cin,s)){
		stringstream ss(s);
		while(ss>>s)
			if(s=="+"||s=="-"||s=="*"||s=="/")X.push(f(s));
			else X.push(s2i(s));
		printf("%.6f\n", X.top());
		X.pop();
	}
}

Measured memory_bytes: 1288
#include <iostream>
#include <iomanip>
#include <cmath>
#include <queue>
#include <map>
#include <cstdlib>
#include <string>
using namespace std;

long long int fact(int a)
{
	long long int sum = 0;
	for (int i = 1; i <= a; ++i) {
		sum += i;
	}
	return sum;
}

int main()
{
	int i = 1, a;
	cin >> a;
	while (true) {
		if (fact(i) >= a) {
			cout << i << endl;
			break;
		}
		++i;
	}

	return 0;
}

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

#define llint long long int

using namespace std;

int gcd(int a, int b){
    if(a < b){
        return gcd(b, a);
    }
    if(b == 0){
        return a;
    }
    return gcd(b, a % b);
}
int main(){
    int K;

    cin >> K;

    int ans = 0;

    for(int a = 1; a <= K; a ++){
        for(int b = 1; b <= K; b ++){
            for(int c = 1; c <= K; c ++){
                int ab = gcd(a, b);
                int abc = gcd(ab, c);

                ans += abc;
            }
        }
    }
    cout << ans << endl;
}

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

const int mod = 1e9 + 7, mxN = 110, mxK = 1e5 + 5;
int N, K, a[mxN];
ll dp[mxN][mxK];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> N >> K;
	for (int i = 1; i <= N; i++) {
		cin >> a[i];
	}
	dp[0][0] = 1;
	for (int i = 1; i <= N; i++) {
		ll pref[K + 1];
		pref[0] = dp[i - 1][0];
		for (int j = 1; j <= K; j++) {
			pref[j] = (pref[j - 1] + dp[i - 1][j]) % mod;
		}
		for (int j = 0; j <= K; j++) {
			dp[i][j] = pref[j];
			int t = j - a[i] - 1;
			if (t >= 0) {
				dp[i][j] = (dp[i][j] - pref[t] + mod) % mod;
			}
		}
	}
	cout << dp[N][K];
	
	return 0;
}


Measured memory_bytes: 82428
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct {
	char name[24];
	int zikan;
	int syunyu;
} sakumotu_t;

int qsort_comp(const void* x,const void* y) {
	const sakumotu_t* a=(const sakumotu_t*)x;
	const sakumotu_t* b=(const sakumotu_t*)y;
	long long a_koritu=(long long)(a->syunyu)*(b->zikan);
	long long b_koritu=(long long)(b->syunyu)*(a->zikan);
	if(a_koritu<b_koritu)return 1;
	if(a_koritu>b_koritu)return -1;
	return strcmp(a->name,b->name);
}

int main(void) {
	int N;
	sakumotu_t sakumotu[50];
	int P,A,B,C,D,E,F,S,M;
	int i;
	while(1) {
		scanf("%d",&N);
		if(N==0)break;
		for(i=0;i<N;i++) {
			scanf("%s",sakumotu[i].name);
			scanf("%d%d%d%d%d%d%d%d%d",&P,&A,&B,&C,&D,&E,&F,&S,&M);
			sakumotu[i].zikan=A+B+C+D+E+(D+E)*(M-1);
			sakumotu[i].syunyu=F*S*M-P;
		}
		qsort(sakumotu,N,sizeof(sakumotu_t),qsort_comp);
		for(i=0;i<N;i++)puts(sakumotu[i].name);
		puts("#");
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define MAX 10000
#define NIL -1

struct Node { int p, l, r; };
Node T[MAX];
int n;

void preParse(int u) {
  if (u == NIL) return;
  cout << " " << u;
  preParse(T[u].l);
  preParse(T[u].r);
}

void inParse(int u) {
  if (u == NIL) return;
  inParse(T[u].l);
  cout << " " << u;
  inParse(T[u].r);
}

void postParse(int u) {
  if (u == NIL) return;
  postParse(T[u].l);
  postParse(T[u].r);
  cout << " " << u;
}

int main() {
  int v, l, r, root;

  cin >> n;

  for (int i = 0; i < n; i++) T[i].p = NIL;

  for (int i = 0; i < n; i++) {
    cin >> v >> l >> r;
    T[v].l = l;
    T[v].r = r;
    if (l != NIL) T[l].p = v;
    if (r != NIL) T[r].p = v;
  }

  for (int i = 0; i < n; i++) {
    if (T[i].p == NIL) root = i;
  }

  cout << "Preorder" << endl;
  preParse(root);
  cout << endl;
  cout << "Inorder" << endl;
  inParse(root);
  cout << endl;
  cout << "Postorder" << endl;
  postParse(root);
  cout << endl;

  return 0;
}


Measured memory_bytes: 3116
import sys
input = sys.stdin.readline

N = int(input())
As = list(map(int, input().split()))

history = []

positives = []
negatives = []
for A in As:
    if A >= 0:
        positives.append(A)
    else:
        negatives.append(A)

if not positives:
    n = max(negatives)
    negatives.remove(n)
    positives.append(n)

if not negatives:
    p = min(positives)
    positives.remove(p)
    negatives.append(p)

while len(negatives) > 1:
    p = positives.pop()
    n = negatives.pop()
    history.append((p, n))
    positives.append(p-n)

n = negatives[0]
while len(positives) > 1:
    p = positives.pop()
    history.append((n, p))
    n -= p

history.append((positives[0], n))
ans = positives[0] - n

print(ans)
for elem in history:
    print(*elem)

Measured memory_bytes: 19900
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;

void main() {
	string[] inputs = split(readln());
	int a = to!int(inputs[0]);
	int b = to!int(inputs[1]);
	int c = to!int(inputs[2]);
	
	min(a + b, b + c, c + a).writeln;
}


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

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

	if(a < b){
		cout << "a < b" << endl;
	}
	else if(a >b){
		cout << "a > b" << endl;
	}
	else{
		cout << "a == b" << endl;
	}
	return 0;
}

Measured memory_bytes: 3064
s = input()
q = int(input())
rev_flag = False
x_lis = []
y_lis = []
for _ in range(q):
    i = input()
    if i == '1':
        rev_flag = not rev_flag
    else:
        a,b,c = i.split()
        if rev_flag:
            if b == '1':
                #s = s + c
                y_lis.append(c)
            else:
                #s = c + s
                x_lis.append(c)
        else:
            if b == '1':
                #s = c + s
                x_lis.append(c)
            else:
                #s = s + c
                y_lis.append(c)
x = ''.join(reversed(x_lis))
y = ''.join(y_lis)
if rev_flag:
    print(''.join(list(reversed(x+s+y))))
else:
    print(x+s+y)

Measured memory_bytes: 7440
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		int allday = in.nextInt();
		int pasta = in.nextInt();
		int sum = 0;
		int[][]A = new int [3][2];
		int[]B = new int [3];
		int[]C = new int [allday+1];
		for(int i = 1;i <= allday;i++)C[i] = 0;
		for(int i = 0;i < pasta;i++){
			int day = in.nextInt();
			C[day] = in.nextInt();
		}
		for(int i = 0;i < 3;i++)A[i][0]=1;
		switch(C[1] % 4){
		case 0:
			break;
		case 1:
			A[1][0] = 0;
			A[2][0] = 0;
			break;
		case 2:
			A[0][0] = 0;
			A[2][0] = 0;
			break;
		case 3:
			A[0][0] = 0;
			A[1][0] = 0;
			break;
		}
		for(int i = 2;i <= allday;i++){
			B[0]=A[1][0]+A[2][0]+A[1][1]+A[2][1];
			B[1]=A[0][0]+A[2][0]+A[0][1]+A[2][1];
			B[2]=A[0][0]+A[1][0]+A[0][1]+A[1][1];
			switch(C[i] % 4){
			case 0:
				for(int j = 0;j < 3;j++){
					A[j][1]=A[j][0] % 10000;
					A[j][0]=B[j] % 10000;
				}
				break;
			case 1:
				for(int j = 0;j < 3;j++){
					A[j][1]=A[j][0] % 10000;
					A[j][0]=B[j] % 10000;
					if(j != 0){
						A[j][0] = 0;
						A[j][1] = 0;
					}
				}
				break;
			case 2:
				for(int j = 0;j < 3;j++){
					A[j][1]=A[j][0] % 10000;
					A[j][0]=B[j] % 10000;
					if(j != 1){
						A[j][0] = 0;
						A[j][1] = 0;
					}
				}
				break;
			case 3:
				for(int j = 0;j < 3;j++){
					A[j][1]=A[j][0] % 10000;
					A[j][0]=B[j] % 10000;
					if(j != 2){
						A[j][0] = 0;
						A[j][1] = 0;
					}
				}
			}
		}
		for(int i = 0;i < 3;i++){
			sum = sum + A[i][0] + A[i][1];
		}
		sum = sum % 10000;
		System.out.println(sum);
	}
}

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

int main() {
	long long n, m, ans = 0; cin >> n >> m;
	if (n * 2 >= m) { ans += m / 2; m -= m; }
	else { ans = n; m -= n * 2; }
	if (m >= 4)ans += m / 4;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.*
import java.util.*

fun solve(K: Long){
    val offset = K / 50L
    val rest = K % 50L
    val ans = LongArray(50){ it.toLong() + offset - rest }
    for(i in 0 until rest.toInt()){
        ans[i] += 51L
    }
    println(50)
    println(ans.joinToString(separator=" "))
    return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val K = sc.next().toLong()
    solve(K)
}



Measured memory_bytes: 34092
#!/usr/bin/env python3
# N,M = map(int,sys.stdin.readline().split())
# a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
# a = tuple(int(sys.stdin.readline()) for _ in range(N)) # multi line with single param
# a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param
# s = sys.stdin.readline().rstrip()
# N = int(sys.stdin.readline())
# INF = float("inf")
import sys
from functools import reduce
N,K = map(int,sys.stdin.readline().split())

A = tuple(map(int,sys.stdin.readline().split())) # single line with multi param

#pre = reduce((lambda x, y: x * y), [A[i] for i in range(K)])
for i in range(K,N):
    #print(i)
    # cur = (pre//A[i-K])*A[i]
    if A[i-K] < A[i]:
        print("Yes")
    else:
        print("No")
    # if pre < cur:
    #
    # else:
    #     print("No")
    # pre = cur

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

int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if(a+b < c+d) 
    cout << "Right" << endl;
  else if(a+b > c+d)
    cout << "Left" << endl;
  else
    cout << "Balanced" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include<math.h>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main()
{
    int H, W;
    cin >> H >> W;
    vector<string> masu(H);
    vector<string> okikae(H);
    for (int i=0; i<H; i++) {
        cin >> masu.at(i);
        okikae[i] = masu[i];
    }

    int x[8] = {-1, 1, 0, 0, 1, 1, -1, -1};
    int y[8] = {0, 0, -1, 1, 1, -1, -1, 1};

    for (int i=0; i<H; i++) {
        for (int j=0; j<W; j++) {
            if (masu[i][j] == '#') continue;
            int count = 0;
            for (int k=0; k<8; k++) {
                int new_x = j + x[k];
                int new_y = i + y[k];
                if (new_x < 0 || new_x >= W) continue;
                if (new_y < 0 || new_y >= H) continue;
                if (masu[new_y][new_x] == '#') count += 1;
            }

            okikae[i][j] = to_string(count)[0];
        }
    }

    for (int i=0; i<H; i++) {
        cout << okikae[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 3624
#include<stdio.h>

int main() {

	int a, b, c, min, mid, max;

	scanf("%d %d %d", &a, &b, &c);

	if(a <= b && a <= c)
	{
		printf("%d ", a);
		if (b <= c)
			printf("%d %d\n", b, c);
		else
			printf("%d %d\n", c, b);
	}
	
	else if(b <= a && b <= c)
	{
		printf("%d ", b);
		if (a <= c)
			printf("%d %d\n", a, c);
		else
			printf("%d %d\n", c, a);
	}
	
	else if (c <= a && c <= b)
	{
		printf("%d ", c);
		if (a <= b)
			printf("%d %d\n", a, b);
		else
			printf("%d %d\n", b, a);
	}

	return 0;
}

Measured memory_bytes: 1784
package main

import (
	"fmt"
	"strconv"
)

func Max(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}

func Min(a, b int) int {
	if a < b {
		return a
	} else {
		return b
	}
}

func solve() {
	var k, x int
	fmt.Scanf("%d %d", &k, &x)

	left := Max(x-k+1, -1000000)
	right := Min(x+k-1, 1000000)

	ans := ""
	for i := left; i <= right; i++ {
		ans += strconv.Itoa(i) + " "
	}

	fmt.Println(ans)
}

func main() {
	solve()
}


Measured memory_bytes: 640
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {
	Scanner sc = new Scanner(System.in);

	int N, M;
	int[] indeg;
	ArrayList<Integer>[] G;
	ArrayList<Integer> res;
	boolean[] V;
	boolean multi;

	@SuppressWarnings("unchecked")
	void run() {
		N = sc.nextInt();
		M = sc.nextInt();
		indeg = new int[N];
		G = new ArrayList[N];
		res = new ArrayList<Integer>();
		V = new boolean[N];
		multi = false;
		for (int i = 0; i < N; i++) G[i] = new ArrayList<Integer>();
		for (int i = 0; i < M; i++) {
			int v = sc.nextInt() - 1;
			int u = sc.nextInt() - 1;
			G[v].add(u);
			indeg[u]++;
		}

		topologicalSort();

		StringBuilder o = new StringBuilder();
		for (int i = 0; i < N; i++) o.append(res.get(i) + "\n");
		System.out.print(o);
		System.out.println(multi ? 1 : 0);
	}

	void topologicalSort() {
		for (int u = 0; u < N; u++) {
			if (indeg[u] == 0 && !V[u]) {
				bfs(u);
			}
		}
	}

	void bfs(int s) {
		V[s] = true;
		LinkedList<Integer> que = new LinkedList<Integer>();
		que.add(s);
		while (!que.isEmpty()) {
			int u = que.poll();
			res.add(u + 1);
			for (int i = 0; i < G[u].size(); i++) {
				int v = G[u].get(i);
				indeg[v]--;
				if (indeg[v] == 0 && !V[v]) {
					que.add(v);
					V[v] = true;
				}
			}
			if (que.size() > 1) multi = true;
		}
	}

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

Measured memory_bytes: 102512
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#if __cplusplus >= 201103L
#include <chrono>
using namespace std::chrono;
#endif
using namespace std;
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#ifdef LOCAL
#define prln(x) (cout << #x << ' ' << x << endl)
#define pr(x) (cout << #x << ' ' << x << ' ' )
#define prv(x) (cout << x << ' ')
#else
#define prln(x) 
#define pr(x)
#define prv(x)
#endif
#define clr(x) memset((x), 0, sizeof((x)))
#define clr1(x) memset((x), -1, sizeof((x)))
#define endl "\n"
#define pi acos(-1)
#define rep(i, st, ed) for (int i = (st); i <= (ed); ++i)
#define rep0(i, st, ed) for (int i = (st); i < (ed); ++i)
#define per0(i, st, ed) for (int i = (st); i > ed; --i)
#define per(i, st, ed) for (int i = (st); i >= ed; --i)
#define chmin(a, b) (a = a > b ? b : a)
#define chmax(a, b) (a = a < b ? b : a)
template<class T> void _sf(T &x) {cin >> x;}
void _sf(int &x) {scanf("%d", &x);}
void _sf(ll &x) {scanf("%lld", &x);}
void _sf(double &x) {scanf("%lf", &x);}
void _sf(char &x) {scanf(" %c", &x);}
void _sf(char *x) {scanf("%s", x);}
void sf() {}
template <class T, class...U> void sf(T & head, U&... tail) { _sf(head); sf(tail...);}
template<class T> void _out(const T &x) { cout << x; }
void _out(const int &x) { printf("%d", x); }
void _out(const ll &x) { printf("%lld", x); }
void _out(const double &x) { printf("%.16f", x); }
void _out(const char &x) { putchar(x); }
void _out(const char *x) { printf("%s", x); }
template<class T,class U> void _out(const pair<T,U> &x) {_out(x.F); putchar(' '); _out(x.S);}
template<class T> void _out(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _out(*i++)) if (i != x.cbegin()) putchar(' '); }
void out() {}
template<class T, class... U> void out(const T &head, const U &... tail) { _out(head); putchar(sizeof...(tail) ? ' ' : '\n'); out(tail...); }
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;

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 main(){
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    double mx = 100 * 1.0 / 0.08;
    int a, b;
    sf(a, b);
    bool ok = 0;
    int ans = -1;
    for (int i = 0; i <= mx; ++i) {
        int aa = i * 0.08;
        int bb = i * 0.1;
        if (aa == a && bb == b) {
            ok = 1;
            ans = i;
            break;
        }
    }
    out(ans);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;

void calc_m(int *Money, int n){
  int org = 100000;
  Money[0] = org;
  for(int i=1;i<100;i++){
    Money[i] = Money[i-1]*1.05;
    double tmp = ceil((double)Money[i]*pow(10.0, -3));
    Money[i] = (int)tmp*pow(10.0, 3);
  }
}
  

int main(){

  int Money[100];
  calc_m(Money, 100);
  
  int n;
  
  while(cin >> n){
    cout << Money[n] << endl;
  }

} 

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n + 1, 0);
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[a[i]] == i) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define fi(a) scanf("%d",&a);
#define fli(a) scanf("%ld",&a);
#define fll(a) scanf("%lld",&a);
#define pi(a) printf("%d\n",a);
#define ppi(i,a) printf("Case %d: %d\n",i,a);
#define ll long long
//#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

int main()
{
    // fast
    long long n;
    long double a,b;
    cin >> a >> b;
    ll x = b*100+0.01;
    n = (a*x)/100;
    cout << n << endl;
    return 0;
}


Measured memory_bytes: 3708
from itertools import permutations

N, C = map(int, input().split())
D = [list(map(int, input().split())) for _ in range(C)]
X = [list(map(int, input().split())) for _ in range(N)]

memo = [[0] * C for _ in range(3)]
for i in range(N):
    for j in range(N):
        k = (i + j + 2) % 3
        memo[k][X[i][j] - 1] += 1
        
ans = 10 ** 9 + 7
for c in permutations(range(C), 3):
    cost = 0
    for n in range(3):
        for j in range(C):
            cost += D[j][c[n]] * memo[n][j]
            
    ans = min(ans, cost)
    
print(ans)


Measured memory_bytes: 43868
#include<bits/stdc++.h>
 
using namespace std;
 
int main (){
  
 int n,i,c=0;
  
  cin>>n;
  
  for(i=1; i<=n; i++){
    
    if(i & 1) c++;
    
  }
  
  cout<<fixed<<setprecision(10)<<(double)c/(double)n<<endl;
 
  return 0;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < n; i++)
#define reps(i, m, n) for (int i = m; i < n; i++)
#define repr(i, m, n) for (int i = m; i >= n; i--)
#define db(x) cout << #x << "=" << x << endl;
template <class T>
bool maxi(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool mini(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
#define INF2 1000000000000000037
#define INF 1000000007
#define PI (acos(-1))
#define MOD 998244353
#define EPS 1e(-9);
using namespace std;
typedef long long ll;
//--GLOBAL---------------------------------

ll modpow(ll a, ll n, ll mod=MOD){ // a^n % MOD の計算
  ll res = 1;
  while (n > 0){
      if(n & 1) res = res * a % mod;
      a = a * a  % mod;
      n >>= 1;
  }
  return res;
}
//--MAIN-----------------------------------
void Main() {
    int N;
    cin >> N;

    ll dct[N+1]={};

    rep(i,N){
        int x; cin>>x;
        if(i==0 and x!=0){
            cout<< 0 <<"\n";
            return;
        }
        if(i!=0 and x==0){
            cout<< 0<<"\n";
            return;
        }
        ++dct[x];
    }

    ll aru=0;
    reps(i,1,N+1){
        if(dct[i]!=0){
            if(aru!=0){
                cout<< 0<<"\n";
                return;
            }
        }
        else{
            if(aru==0) aru=i;
        }
    }

    ll ans=1;

    reps(i,1,aru){
        ans*=modpow(dct[i-1],dct[i]);
        ans%=MOD;
    }

    cout<< ans<<"\n";


    


}

//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define endl '\n';
#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const ll POSITIVE_INFINITY = 9223372036854775807;
const ll NEGATIVE_INFINITY = -9223372036854775807;
const ll MOD = 1000000007;
const ld PI = acos(-1.0);

template <typename T> inline T bigMod(T A,T B,T M = MOD){A %= M;T ret = 1;while(B){if(B & 1) ret = (ret * A) % M;A = (A * A) % M;B = B >> 1;}return ret;}
template <typename T> inline T invMod (T A,T M = MOD){return bigMod(A,M-2,M);}

const int N = 102;
int W[N], V[N];
int n, w;
ll dp[N][100005];
ll F(int pos, int rem){
  if (rem <= 0){
    return 0;
  }
  if (pos >= n){
    return 1e12;
  }
  if (dp[pos][rem] != -1){
    return dp[pos][rem];
  }
  ll x = F(pos + 1, rem);
  ll y = F(pos + 1, rem - V[pos]) + W[pos];
  return dp[pos][rem] = min(x, y);
}

int main(){
  memset(dp, -1, sizeof dp);
  cin >> n >> w;
  int sum = 0;
  for (int i = 0; i < n; i++){
    cin >> W[i] >> V[i];
    sum += V[i];
  }
  int ans = 0;
  for (int i = sum; i >= 0; i--){
    if (F(0, i) <= w){
      ans = max(i, ans);
    }
  }
  cout << ans << "\n";
  return 0;
}

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

using namespace std;

const int MX = 100000;

namespace dsu {
	int p[MX];
	
	void init(int n) {
		iota(p, p + n, 0);
	}
	
	int get(int v) {
		if (p[v] != v) p[v] = get(p[v]);
		return p[v];
	}
	
	bool merge(int u, int v) {
		u = get(u);
		v = get(v);
		p[u] = v;
		return u != v;
	}
}

int a[MX];
vector<int> v[MX];

int main() {
	int n, m;
	ignore = scanf("%d %d", &n, &m);
	
	if (m == n - 1) {
		printf("0\n");
		return 0;
	}
	
	for (int i = 0; i < n; i++) ignore = scanf("%d", a + i);
	
	dsu::init(n);
	
	while (m--) {
		int u, v;
		ignore = scanf("%d %d", &u, &v);
		dsu::merge(u, v);
	}
	
	for (int i = 0; i < n; i++) v[dsu::get(i)].push_back(a[i]);
	
	long long ans = 0;
	vector<int> vec;
	int cnt = 0;
	for (int i = 0; i < n; i++)
		if (v[i].empty() == false) {
			sort(v[i].begin(), v[i].end());
			reverse(v[i].begin(), v[i].end());
			ans += v[i].back();
			v[i].pop_back();
			copy(v[i].begin(), v[i].end(), back_inserter(vec));
			cnt++;
		}
	
	if (vec.size() < cnt - 2) {
		printf("Impossible\n");
		return 0;
	}
	
	sort(vec.begin(), vec.end());
	for (int i = 0; i < cnt - 2; i++) ans += vec[i];
	
	printf("%lld\n", ans);
	
	return 0;
}


Measured memory_bytes: 6528
N = int(input())
S = list(input())

pre_count = 0
post_count = len([k for k in range(1, N) if S[k] == 'E'])
count = post_count
for i in range(1, N):
    if S[i-1] == 'W':
        pre_count += 1
    if S[i] == 'E':
        post_count -= 1
    if count > pre_count + post_count:
        count = pre_count + post_count

print(count)

Measured memory_bytes: 17528
def main():
  n,k = map(int,input().split())
  h = [int(x) for x in input().split()]
  cnt = 0
  for i in range(n):
    if h[i]>=k:
      cnt +=1
    else:
      pass
  print(cnt)
if __name__ == "__main__":
  main()

Measured memory_bytes: 51440
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;
const int mod=1000000007;

ll x[100001],y[100001];
int main(){
    ll n,m;
    cin>>n>>m;
    rep(i,n) cin>>x[i];
    rep(i,m) cin>>y[i];
    sort(x,x+n);
    sort(y,y+m);
    ll sumx=0,sumy=0;
    FOR(i,1,n) sumx=(sumx+(x[i]-x[i-1])*i%mod*(n-i))%mod;
    FOR(i,1,m) sumy=(sumy+(y[i]-y[i-1])*i%mod*(m-i))%mod;
    cout<<sumx*sumy%mod<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
int main(){
    // Your code here!
    int n;
    scanf("%d",&n);
    int a=1000000000;
    int b=0;
    for(int i=0;i<n;i++){
        int tmp;scanf("%d",&tmp);
        if(tmp<a) a=tmp;
        if(tmp>b) b=tmp;
    }
    printf("%d",b-a);
}


Measured memory_bytes: 128
import sys
from itertools import product

sys.setrecursionlimit(200000)


def input():
    return sys.stdin.readline()[:-1]


def ii(t: type = int):
    return t(input())


def il(t: type = int):
    return list(map(t, input().split()))


def imi(N: int, t: type = int):
    return [ii(t) for _ in range(N)]


def iml(N: int, t: type = int):
    return [il(t) for _ in range(N)]


def solve():
    a, b, c = il()
    return a * b // 2


if __name__ == "__main__":
    print(solve())


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

int main() {
    int n, k;
    cin >> n >> k;
    long ans = 0;
    for (int i = k + 1; i <= n; i++) {
        ans += (n / i) * (i - k);
        ans += max(0, n % i - max(0, k - 1));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
table=[{'L':False, 'R':True, 'U':True, 'D':True,},
       {'L':True, 'R':False, 'U':True, 'D':True,}]
S=input()
if all([table[i%2][c] for i, c in enumerate(S)]):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
let quick_sort (a : (int * char * int) array) =
  let swap i j = let tmp = a.(i) in a.(i) <- a.(j); a.(j) <- tmp in
  let partition p r =
    let rec exchange = function
      | (i, j) when j = r -> swap i r; i
      | (i, j) when (fun (_, _, x) (_, _, y) -> x - y) a.(j) a.(r) <= 0 -> swap i j; exchange (i + 1, j + 1)
      | (i, j) -> exchange (i, j + 1) in
    exchange (p, p) in
  let rec doit p r =
    if p < r then begin
      let q = partition p r in
      doit p (q - 1);
      doit q r
    end in
  doit 0 (Array.length a - 1)

let stable_p (a : (int * char * int) array) n =
  let rec doit i =
    if i = n then true
    else if (fun (xi, _, xd) (yi, _, yd) -> xd = yd && xi > yi) a.(i-1) a.(i) then false
    else doit (i + 1) in
  doit 1

let split str delim =
  let open String in
  let rec doit s acc =
    match
      try Some (rindex s delim) with _ -> None
    with
    | None -> s :: acc
    | Some i -> doit (sub s 0 i) (sub s (i + 1) (length s - i - 1) :: acc) in
  doit str []

let () =
  let n = read_int () in
  let a = Array.init n (fun i ->
    match split (read_line ()) ' ' with
    | [c; d] -> (i, c.[0], int_of_string d)
    | _ -> exit 1) in
  quick_sort a;
  print_endline (if stable_p a n then "Stable" else "Not stable");
  Array.iter (fun (_, c, d) -> Printf.printf "%c %d\n" c d) a

Measured memory_bytes: 8788
N,M = map(int,input().split())
ks = [list(map(int,input().split())) for i in range(M)]
p = list(map(int,input().split()))

import itertools
L = [0, 1] #生成する数字
num = N #生成するビット数
bit_list = list(itertools.product([0, 1], repeat=num))
ans = 0

for i in range(len(bit_list)):
    light = 0
    for j in range(len(ks)):
        count = 0
        for k in range(1,len(ks[j])):
            if bit_list[i][ks[j][k]-1] == 1:
                count += 1
        if count%2 == p[j]:
            light += 1
    if light == M:
        ans += 1
        
print(ans)

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

using namespace std;

int n, t;

void solve() {
	cin >> n;
	int x = n % 10;
	if(x == 3) cout << "bon";
	else if (x == 0 or x == 1 or x == 6 or x == 8) cout << "pon";
	else cout << "hon";
}

int main(){
	t = 1;

	while(t--){
		solve();
	}
}

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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}


typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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 (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { -1,0, 1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
// #define mp make_pair
//#define endl '\n'



int main () {
  int n;
  cin >> n;
  vl a(n);
  bool sei = true, fu = true;
  rep (i, n) {
    cin >> a[i];
    if (a[i] >= 0) fu = false;
    if (a[i] <= 0) sei = false;
  }

  int cnt = 0;
  if (sei) {
    cnt = n - 1;
  }
  else if (fu) {
    cnt = 1;
  }
  else {
    rep (i, n) {
      if (a[i] >= 0) cnt++;
    }
    chmin(cnt, n - 1);
    chmax(cnt, 1);
  }

  cnt = n - cnt;
  sort(all(a));

  ll x = a.back();
  vector<pll> ans;
  rep (i, cnt - 1)  {
    ans.push_back(pll(x, a[i]));
    x = x - a[i];
  }
  ll y = a[cnt - 1];
  for (int i = cnt; i < n - 1; i++) {
    ans.push_back(pll(y, a[i]));
    y = y - a[i];
  }
  ans.push_back(pll(x, y));
  x -= y;
  cout << x << endl;
  rep (i, ans.size()) {
    cout << ans[i].first << " " << ans[i].second << endl;
  }
}


Measured memory_bytes: 4336