akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
using namespace std;




int main(){
  while(1){
  int n;
  scanf("%d",&n);
if(n==0)break;
string unko[100];
for(int i=0;i<n;i++)cin >> unko[i] ;
int maxlen=0;
int atai[n];
for(int i=0;i<n;i++)if(unko[i][unko[i].size()-1]>='0'&&unko[i][unko[i].size()-1]<='9')atai[i]=unko[i][unko[i].size()-1]-'0';else atai[i]=-1;
for(int i=0;i<n;i++)if(unko[i].size()>maxlen)maxlen=unko[i].size();
for(int i=maxlen-1;i>=0;i--)for(int j=0;j<n;j++){
  if(unko[j].size()==i&&atai[j]==-1){
    int po;
    if(unko[j][unko[j].size()-1]=='+')po=0;
    else po=1;
    for(int k=j+1;unko[k].size()>unko[j].size()&&k<n;k++){
      if(unko[k].size()==unko[j].size()+1){
        if(unko[j][unko[j].size()-1]=='+')po+=atai[k];
        else po*=atai[k];
      }
    }
    atai[j]=po;
  }
}
//for(int i=0;i<n;i++)printf("%d ",atai[i]);
printf("%d\n",atai[0]);
}
  return 0;
}



Measured memory_bytes: 3204
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;

ll t,l,h,x,y,p,q,mid;

ll chk(ll m)
{
	return (p*m>=x && q*m-p*m>=y-x);
		
}

int main()
{
	
	string s;
	cin>>s;
	if(s[2]==s[3] && s[4]==s[5])
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;

}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>

#define MAX_SIZE 100000000
typedef unsigned long long ull;
using namespace std;

int main() {
  int N; cin >> N;
  int imax = 0;
  int imin = 1000000001;
  for(int i = 0; i < N; i++) {
    int e; cin >> e;
    imax = max(imax, e);
    imin = min(imin, e);
  }
  int ans = abs(imax - imin);
  cout << ans << endl;
}


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

int main() {
  int A, B;
  cin >> A >> B;
  
  int count = 0;
  int i = 0;
  while(A + i <= B){
      int x, dig1, dig10, dig100, dig1000, dig10000;
      x = A + i;
      dig1 = x % 10;
      x /= 10;
      dig10 = x % 10;
      x /= 10;
      dig100 = x % 10;
      x /= 10;
      dig1000 = x % 10;
      x /= 10;
      dig10000 = x % 10;
      
      if (dig1 == dig10000 && dig10 == dig1000) {
        count++;
      }
    i++;
  }
  cout << count << endl;
}


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

int main() {
  int s, w; cin >> s >> w;
  if (w >= s) cout << "unsafe" << endl;
  else cout << "safe" << endl;
  
  return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <string.h>
using namespace std;

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef pair<int,int> pii;
#define uint(n) ((unsigned int)(n))
#define ll(n) ((long long)(n))
#define ull(n) ((unsigned long long)(n))
#define fl(n) ((float)(n))
#define dou(n) ((double)(n))
const int INF=1e9+7;
const ll LINF=1e18;
#define pb push_back
#define pob pop_back
#define m_p make_pair
#define ALL(a) (a).begin(),(a).end()
#define Mod 1000000007
#define SZ(a) ((int)(a).size())
#define FI first
#define SE second

int N;
bool isp[10010];
int cnt[10010];
vector<int> pri;
long long ans=1;

int main()
{
	cin>>N;
	
	memset(isp,1,sizeof(isp));
	isp[0]=isp[1]=0;
	for(int i=2;i<=10000;i++)
		if(isp[i])
		{
			pri.push_back(i);
			for(int j=i*2;j<=10000;j+=i) isp[j]=0;
		}
	
	for(int t=1;t<=N;t++)
	{
		int n=t;
		int k=0;
		while(n>1)
		{
			while(n%pri[k]==0&&k<pri.size()) n/=pri[k],cnt[pri[k]]++;
			k++;
		}
	}
	
	for(int i=0;i<pri.size();i++) 
	{
		if(cnt[pri[i]]==0) continue;
		ans=ans*(cnt[pri[i]]+1)%Mod;
//		cout<<pri[i]<<": "<<cnt[pri[i]]<<endl;
	}
	
	cout<<ans;
	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 20000000
int H,A[MAX];
void maxHeapify(int i);

int main(){
  int i;
  scanf("%d",&H);
  
  for(i=1;i<=H;i++){
    scanf("%d",&A[i]);
  }

  
  for(i=H/2 ; i>=1 ; i--){
    maxHeapify(i);
  }
  for(i=1; i <= H; i++){
    if(i==H){
      printf(" %d\n",A[i]);
    }
    else{
      printf(" %d",A[i]);
    }

  }
  

  return 0;
}

void maxHeapify(int i){
  int l,r;
  int largest,tmp;
  l = 2*i;
  r = 2*i+1;
  if( l<=H && A[l] > A[i]){
    largest = l;
  }
  else {
    largest = i;
  }


  if(r <= H && A[r] > A[largest] ){
    largest = r;
  }

  if(largest != i){
    tmp = A[i];
    A[i] = A[largest];
    A[largest] = tmp;
      maxHeapify(largest);
      }
  }
  
  



Measured memory_bytes: 3652
#include <iostream>

using namespace std;

int a,b,c,d,e,f;

int main(){
    cin >> a >> b >> c >> d >> e >> f;
    a *= 100;
    b *= 100;
    double z = 0.0;
    int W,S;
    W = S = 0;
    for(int i=0;i*a<=f;i++){
        for(int j=0;i*a+j*b<=f;j++){
            int g = (i*a+b*j) * e / 100;
            for(int x=0;x*c<=g;x++){
                for(int y=0;x*c+y*d<=g;y++){
                    int w = i*a+b*j;
                    int s = x*c+y*d;
                    if(w+s == 0) continue;
                    if(z <= (double)s/(w+s) && w+s <= f){
                        z = (double)s/(w+s);
                        W = w;
                        S = s;
                    }
                }
            }
        }
    }
    cout << W+S << " " << S << endl;
    return 0;
}

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

int main(){
    int n;
    scanf("%d",&n);
    vector <int>a(n);
    for (auto&e:a) scanf("%d",&e);
    for (int i=n-1;i>=0;i--) {
        printf("%d",a[i]);
        printf(i!=0?" ":"\n");
    }
    return 0;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,ll>
const ll MOD=998244353;
const int INF=1e9;
const double PI=acos(-1);


int main() {
    ios_base::sync_with_stdio(false);

    int d;
    cin >> d;
    cout << "Christmas";
    rep(i,25-d) cout << " Eve";
    cout << endl;

    return 0;

}


Measured memory_bytes: 3492
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
sys.setrecursionlimit(500*500)
import itertools
from collections import Counter,deque

def main():
    a,b,n = map(int, input().split())

    k = min(n,b-1)
    print(math.floor(a*k/b) - a*math.floor(k/b))

if __name__=="__main__":
    main()


Measured memory_bytes: 65348
def former(array, value)
  array.bsearch do |x|
    x >= value
  end
end

def latter(array, value)
  i = array.bsearch_index do |x|
    x >= value
  end
  i ||= array.size
  if i >= 1
    array[i - 1]
  else
    nil
  end
end

A, B, Q = gets.split.map(&:to_i)
s_list = A.times.map { gets.to_i }.sort
t_list = B.times.map { gets.to_i }.sort
Q.times do
  ans = 10 << 60
  q = gets.to_i
  # s
  2.times do |i|
    s = i == 0 ? former(s_list, q) : latter(s_list, q)
    next unless s
    sd = (s - q).abs
    2.times do |j|
      t = j == 0 ? former(t_list, s) : latter(t_list, s)
      next unless t
      td = (s - t).abs
      ans = sd + td if ans > sd + td
    end
  end
  # t
  2.times do |i|
    t = i == 0 ? former(t_list, q) : latter(t_list, q)
    next unless t
    td = (t - q).abs
    2.times do |j|
      s = j == 0 ? former(s_list, t) : latter(s_list, t)
      next unless s
      sd = (s - t).abs
      ans = sd + td if ans > sd + td
    end
  end
  puts ans
end


Measured memory_bytes: 8616
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <string>
using namespace std;
typedef double  dbl;
typedef long long int lld;
#define PI 3.14159265358979323
#define foi(i,n) for(i = 0; i < n; i+=1)
#define fod(i,n) for(i=n-1; i >=0; i-=1)
#define MAX std::numeric_limits<lld>::max()
#define MIN std::numeric_limits<lld>::min()
#define FastIO  ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int main ()
{
	FastIO
	lld k, x;
	cin >> k;
	cin >> x;
	lld beg = x - (k-1);
	lld end = x + (k-1);
	for(lld i = beg; i <= end; i++){
		cout << i << " ";
	}
	return 0;
}

Measured memory_bytes: 384
import std.stdio, std.conv, std.array, std.string;
import std.algorithm;
import std.container;
import std.range;
import core.stdc.stdlib;
import std.math;
import std.functional;

ulong factorial(int n, int r) {
  if (n <= 0 || r <= 0) return 1;
  return (n * memoize!factorial(n-1, r-1)) % 998244353;
}

ulong calcCombination(int n, int r) {
  if (n - r < r) return memoize!calcCombination(n, n-r);
  return memoize!factorial(n, r) / memoize!factorial(r, r);
}

ulong calcGraphLineCombination(int from, int to) {
  if (from <= 0 || to <= 0) return 1;
  if (from == 1) return 1;
  if (to == 1) return from;

  ulong sum = 0;
  foreach(n; 0..to+1) {
    sum += memoize!calcCombination(to, n) * memoize!calcGraphLineCombination(from-1, to-n);
    sum %= 998244353;
  }
  return sum;
}

void main() {
  auto N = readln.chomp.to!int;
  auto Di = readln.split.to!(int[]);

  if (Di[0] != 0) {
    writeln(0);
    exit(0);
  }

  Di = Di.sort;
  ulong answer = 1;
  int from = 1;
  int index = 1;
  foreach(i; 1..1 + Di[Di.length - 1]) {
    int beforeIndex = index;
    for(; index < N && Di[index] == i; index++) {}
    int to = index - beforeIndex;
    if (to == 0) {
      answer = 0;
      break;
    }
    for(int n = 0; n < to; n++) {
      answer *= from;
      answer %= 998244353;
    }
    if (index == N) break;
    from = to;
  }

  answer.writeln;
}


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

#define REP(i, N) for (int i = 0; i < (N); ++i)
#define fi first
#define se second

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

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

const ll INF = 1LL << 60;
int N;
vector<pair<int, int>> V;

signed main() {
    cin >> N;
    V.resize(N);
    REP(i, N) cin >> V[i].fi >> V[i].se;
    REP(i, N) if (V[i].fi > V[i].se) swap(V[i].fi, V[i].se);
    sort(V.begin(), V.end());

    ll res = INF;
    ll mx = -INF, mn = INF;

    for (auto& [x, y]: V) {
        chmax(mx, y);
        chmin(mn, x);
    }

    {
        pair<ll, ll> red(-INF, INF), blue(-INF, INF);
        for (auto& [x, y]: V) {
            // fi -> red
            chmax(red.fi, x);
            chmin(red.se, x);
            // se -> blue
            chmax(blue.fi, y);
            chmin(blue.se, y);
        }
        chmin(res, (red.fi - red.se) * (blue.fi - blue.se));
        //cerr << res << " : " << red.fi << ' ' << red.se << ' ' << blue.fi << ' ' << blue.se << endl;
    }

    {
        multiset<int> st;
        REP(i, N) st.emplace(V[i].fi);
        chmin(res, (mx - mn) * (*st.rbegin() - *st.begin()));
        for (auto& [x, y]: V) {
            st.erase(st.find(x));
            st.emplace(y);
            chmin(res, (mx - mn) * (*st.rbegin() - *st.begin()));
            //cerr << res << endl;
        }
    }

    cout << res << endl;
}


Measured memory_bytes: 14076
<?php

// define('DEBUG', true);
define('DEBUG', false);

fscanf(STDIN, "%d", $N);
$a = explode(" ", trim(fgets(STDIN)));

$n1 = 0;
$n2 = 0;
$n4 = 0;

foreach ($a as $v) {
    if ($v % 4 == 0) {
        $n4++;
    } else if ($v % 2 == 0) {
        $n2++;
    } else {
        $n1++;
    }
}

// echo "\$n4 : {$n4}\n";
// echo "\$n2 : {$n2}\n";
// echo "\$n1 : {$n1}\n";

if ($n2 == 0 && $n4 >= ($n1 - 1)) {
    echo "Yes\n";
} else if ($n2 != 0 && $n4 >= $n1) {
    echo "Yes\n";
} else {
    echo "No\n";
}


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

struct Card { char suit, value; };

void bubble(struct Card A[], int N) {
  for ( int i = 0; i < N; i++ )
    for ( int j = N - 1; j >= i; j-- )
      if ( A[j].value < A[j - 1].value )
        swap(A[j], A[j - 1]);
}

void selection(struct Card A[], int N) {
  for ( int i = 0; i < N; i++ ) {
    int minj = i;
    for ( int j = i; j < N; j++ )
      if ( A[j].value < A[minj].value ) minj = j;
    Card t = A[i]; A[i] = A[minj]; A[minj] = t;
  }
}

void print(struct Card A[], int N) {
  for ( int i = 0; i < N; i++ ) {
    if ( i > 0 ) cout << " ";
    cout << A[i].suit << A[i].value;
  }
  cout << endl;
}

bool isStable(struct Card C1[], struct Card C2[], int N) {
  for ( int i  = 0; i < N; i++ )
    if ( C1[i].suit != C2[i].suit ) return false;
  return true;
}

int main() {
  Card C1[100], C2[100];
  int N;
  char ch;

  cin >> N;
  for ( int i = 0; i < N; i++ )
    cin >> C1[i].suit >> C1[i].value;

  for ( int i = 0; i < N; i++ ) C2[i] = C1[i];

  bubble(C1, N);
  selection(C2, N);

  print(C1, N);
  cout << "Stable" << endl;
  print(C2, N);
  if ( isStable(C1, C2, N) )
    cout << "Stable" << endl;
  else
    cout << "Not stable" << endl;

  return 0;
}


Measured memory_bytes: 3124
H,W=map(int,raw_input().split())
N=int,raw_input()
a=map(int,raw_input().split())
c=[[0 for i in range(W)] for i in range(H)]
num=0
count=0
d=1
x=0
y=0
s=0
while x<W:
    count+=1
    if a[num]+s<count:
        s+=a[num]
        num+=1
    c[y][x]=num+1
    y+=d
    if d==1 and y==H:
        x+=1
        d=-1
        y-=1
    if d==-1 and y==-1:
        x+=1
        d=1
        y+=1
for i in c:
    for j in i:
        print j,
    print

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

using namespace std;
typedef long long int ll;

#define C(I) cout<<(I)<<endl

ll n,m,a,b,c,x,y,z,aa[100010],ba[100010];
bool r,ra,rb,rc;
string s,sa,sb,sc;
char ca,cb,cc;
vector<ll> va,vb,vc;
set<int> sta;

int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>aa[i];
        sta.insert(aa[i]);
    }
    C(sta.size());
    
}

Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rep2(i, l, r) for (ll i = (l); i < (r); i++)
#define ALL(x) (x).begin(), (x).end()     //昇順
#define RALL(x) (x).rbegin(), (x).rend()  // 降順
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
const long long mod = 1e9 + 7;
typedef long long ll;
typedef priority_queue<int> PQ;
typedef vector<long long> VL; // VL a(n);
typedef vector<bool> VB;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<VS> VSS;
typedef vector<VC> VCC;
typedef vector<VL> VLL; // VII a(n,VI(m)) n * m
typedef pair<ll, ll> PL;
typedef map<ll, ll> MP; // MP a;
typedef vector<pair<ll, ll>> PS; // PS a(n);

template <class T, class U>
bool chmax(T &a, U b) {
  if (a <= b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T, class U>
bool chmin(T &a, U b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
  os << "}";
  return os;
}

// g++ -std=c++11 prac.cpp
// operator << (cout,a);
// chmin(min,a)
ll sum(ll n){return n*(n+1)/2;} 

int main() {
  ll n,k,m,x=0,y=0,z=0,cnt=0,h=0,w=0,sum=0,ans=0,Max=0, Min=3e9+1;
  string s,t;
  cin >> n;
  VL a(n),b(n);
  rep(i,n) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(ALL(b));
  rep(i,n){
    if(a[i] <= b[n/2-1])
      pri(b[n/2]);
    else
      pri(b[n/2-1]);
  }
  return 0;
}

Measured memory_bytes: 6404
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n2;i>=0;i--)

#define PB push_back
#define INF (1<<29)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))
const int dx[] = {2,0,0,1},dy[] = {0,1,2,0};

typedef long long int ll;

using namespace std;

int main(){
    while(true){
	int a,b,c;
	int n;
	cin >> a >> b >> c;
	if(a == 0 && b == 0 && c == 0) break;
	vector<int> v(a+b+c+1,2);
	vector< pair<int , pair<int,int> > > inp;
	cin >> n;
	REP(i,n){
	    int ta,tb,tc,td;
	    cin >> ta >> tb >> tc >> td;
	    if(td == 0){
		inp.PB( pair<int,pair<int,int> >(ta,pair<int,int>(tb,tc) ));
	    }else{
		v[ta] = 1;
		v[tb] = 1;
		v[tc] = 1;
	    }
	}

	REP(j,inp.size())REP(i,inp.size()){
	    int ta = inp[i].first;
	    int tb = inp[i].second.first;
	    int tc = inp[i].second.second;
	    int count = 0;
	    if(v[ta]==1) count++;
	    if(v[tb]==1) count++;
	    if(v[tc]==1) count++;
	    if(count == 2){
		if(v[ta] == 2) v[ta] = 0;
		if(v[tb] == 2) v[tb] = 0;
		if(v[tc] == 2) v[tc] = 0;
	    }
	}
	REP(i,a+b+c){
	    cout << v[i+1] << endl;
	}
    }
    return 0;
}

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

int main() {
  int m, n;
  while (cin >> m >> n, m) {
    bool live[1010];
    int idx = 1, cnt = m;
    memset(live, true, sizeof live);

    for (int i = 1; i <= n; ++i) {
      string s;
      cin >> s;

      if (cnt != 1) {
        string str = to_string(i);
        if (i % 15 == 0)
          str = "FizzBuzz";
        else if (i % 3 == 0)
          str = "Fizz";
        else if (i % 5 == 0)
          str = "Buzz";

        if (str != s) {
          live[idx] = false;
          cnt--;
        }

        idx++;
        if (idx == m + 1) idx = 1;
        while (!live[idx]) {
          idx++;
          if (idx == m + 1) idx = 1;
        }
      }
    }

    vector<int> ans;
    for (int i = 1; i <= m; ++i) {
      if (live[i]) ans.push_back(i);
    }
    for (int i = 0; i < ans.size(); ++i) {
      cout << ans[i] << (i + 1 == ans.size() ? "\n" : " ");
    }
  }
}



Measured memory_bytes: 3256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <climits>
#include<string>
#include<cassert>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

#define INF INT_MAX/3
#define REP(i,n) for(int i=0;i<n;i++)



int main(){

	int N,K,R,S,P;
	string T;
	cin>>N>>K;

	cin>>R>>S>>P;

	cin>>T;

	int n = T.length();

	vector<int> telog(n,0);	
	ll ans = 0;
	for(int i = 0; i < n; i++){
		
			switch(T[i]){

				case 'r':
					if(i - K < 0){
						telog[i] = 3;
						ans += P;
						break;
					}
					if(telog[i-K] == 3){

						telog[i] = 0;
					}
					else{
						telog[i] = 3;
						ans += P;
					}
					break;
				case 's':
					if(i - K < 0){
						telog[i] = 1;
						ans += R;
						break;
					}
					if(telog[i-K] == 1){
						telog[i] = 0;
					}
					else{
						telog[i] = 1;
						ans += R;
					}
					break;
				case 'p':
					if(i - K < 0){
						telog[i] = 2;
						ans += S;
						break;
					}
					if(telog[i-K] == 2){

						telog[i] = 0;
					}
					else{
						telog[i] = 2;
						ans += S;
					}
					break;
			}
	}
	cout<<ans<<endl;


	return 0;
}



Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <array>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    int n;
    cin >> n;

    int m = 1 << n;

    vector<array<int, 2>> a(m);
    for (int i = 0; i < m; i++) {
        cin >> a[i][0];
        a[i][1] = 0;
    }

    for (int k = 0; k < n; k++) {
        int l = 1 << k;
        for (int i = 0; i < m; i++) {
            if (i & l) {
                int j = i ^ l;
                if (a[i][0] >= a[j][0]) {
                    a[i][1] = max(a[i][1], a[j][0]);
                } else {
                    a[i][1] = max(a[j][1], a[i][0]);
                    a[i][0] = a[j][0];
                }
            }
        }
    }

    int r = 0;
    for (int i = 1; i < m; i++) {
        r = max(r, a[i][0] + a[i][1]);
        cout << r << '\n';
    }
    cout << flush;

    return 0;
}

Measured memory_bytes: 5120
N=[int(i) for i in input().split()]
while N[0]!=0 or N[1]!=0:
    h=[]
    for i in range(2):
        h.append([])
   #     print(N)
        for j in range(N[i]):
            h[i].append(int(input()))
     #       print(h)
        s=0
        for j in range(N[i]-1):
            s=h[i][j]
     #       print(j)
            for k in range(j+1,N[i]):
                s+=h[i][k]
          #      print(s)
                h[i].append(s)
        h[i].sort()
    b=0
    i=0
    j=0
    l0=len(h[0])
    l1=len(h[1])
    while i < l0:
        c=0
        while j < l1 and h[0][i]>=h[1][j]:
       #     print(i)
       #     print(j)
            if h[0][i]==h[1][j]:
                c+=1
            j+=1
        b+=c
        k=i+1
     #   print(h)
    #    print(l1)
        while k<l0 and h[0][i]==h[0][k]:
            b+=c
            k+=1
      #  print(k)
        i=k
    print(b)
    N=[int(i) for i in input().split()]

Measured memory_bytes: 81872
(defun main ()
  (let ((n (read))
        (k (read))
        (ans 0)
        p)
    (dotimes (i n)
      (push (read) p))
    (setf p (sort p #'<))
    (dotimes (i k)
      (setf ans (+ ans (pop p))))
    ans))

(format t "~a~%" (main))


Measured memory_bytes: 24996
url = "https://atcoder.jp/contests/abc161/tasks/abc161_b"


def main():
    n, m = list(map(int, input().split()))
    n_li = list(map(int, input().split()))
    n_li = sorted(n_li, reverse=True)
    all_num = sum(n_li)
    for i in range(1, m + 1):
        if all_num / (4 * m) > n_li[i - 1]:
            print('No')
            exit()
    print('Yes')


if __name__ == '__main__':
    main()




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

int main(void){
    string S;
    cin >> S;
    bool ifsp = true;
    int N = S.length();
    for(int i=0; i<(N-1)/2; i++){
        if(S[i]!=S[N-i-1])ifsp=false;
    }
    if(ifsp){
        for(int i=0; i<(N-1)/4; i++){
            if(S[i]!=S[(N-1)/2-i-1])ifsp=false;
        }
    }
    if(ifsp){
        for(int i=0; i<(N-1)/4; i++){
            if(S[(N+1)/2+i]!=S[N-i-1])ifsp=false;
        }
    }
    if(ifsp){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <numeric> // next_parmutation
#define ll long long
#define rep(i, n) for(int i = 0; i < (n); i++)

using namespace std;

int main() {
    int d, g;
    cin >> d >> g;

    vector<int> p(11), c(11);
    rep(i, d) cin >> p[i] >> c[i];

    int ans = 1e9;
    rep(bit, (1 << d)){
        //p[i]を全部解いてコンプリートボーナスを得る問題
        int sum = 0, max = -1, solved = 0;
        rep(i, d){
            if(bit >> i & 1){
                sum += 100*(i+1)*p[i]+c[i];
                solved += p[i];
            } else max = i;
        }
        //上で足りない場合
        if(sum < g){
            int s = 100 * (max + 1);
            int need = (g - sum + s - 1) / s;
            if(need >= p[max]){
                continue;
            }
            solved += need;
        }
        ans = min(ans, solved);
     }

    cout << ans << endl;
    }



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <complex>
#include <tuple>

#define FAST ios_base::sync_with_stdio(false); cin.tie(0)
#define _overload3(_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(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
// #define repr(i, a, b) for(int i=int(a); i>=int(b); i--)
#define reps(i,n) for(int i=1;i<=int(n);++i)
#define repr(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define reprs(i,x) for(int i=((int)(x));i>0;i--)
#define iceil(x,y) (x+y-1)/y
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define all(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define LF "\n"

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef pair<int, PII> PP;

string s,t;



int main(){
	FAST;
	cin >> s >> t;
	sort(s.begin(), s.end());
	sort(t.begin(),t.end(), std::greater<char>());
	// cout << s << LF;
	// cout << t << LF;

	if (s < t) cout << "Yes\n";
	else cout << "No\n"; 

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100
#define INF 9999999
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,M[MAX][MAX];
int prim(){
  int u,min;
  int d[MAX],p[MAX],color[MAX];
  int i,j,sum=0;
  for(i=0;i<n;i++){
    d[i]=INF;
    p[i]=-1;
    color[i]=WHITE;
  }
  d[0]=0;
  while(1){
    min=INF;
    u=-1;
    for(i=0;i<n;i++){
      if(min>d[i]&&color[i]!=BLACK){
        u=i;
        min=d[i];
      }
    }
    if(u==-1)break;
    color[u]=BLACK;
    for(j=0;j<n;j++){
      if(color[j]!=BLACK&&M[u][j]!=INF){
        if(d[j]>M[u][j]){
          d[j]=M[u][j];
          p[j]=u;
          color[j]=GRAY;
        }
      }
    }
  }
  for(i=0;i<n;i++){
    if(p[i]!=-1)sum+=M[i][p[i]];
  }
  return sum;
}

int main(){
  int i,j,e;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&e);
      M[i][j]=(e==-1)?INF:e;
    }
  }
  printf("%d\n",prim());
  return 0;
}



Measured memory_bytes: 2108
n,m,x = map(int,input().split())
ca = [list(map(int,input().split())) for _ in range(n)]

c = []
a = []

for i in range(n):
    c.append(ca[i][0])
    a.append(ca[i][1:])

INF = 10**9
ans = INF

for i in range(1 << n):
    sum_cost = 0
    skill = [0]*m
    for j in range(n):
        if (i >> j)&1:
            sum_cost += c[j]
            for k in range(m):
                skill[k] += a[j][k]
    check_cnt = 0
    for l in range(m):
        if skill[l] >= x:
            check_cnt += 1
    if check_cnt == m:
        ans = min(ans,sum_cost)

if ans == INF:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 9196
from copy import deepcopy
INF = 1 << 32
n, m = map(int, input().split())
d = [[INF] * n for i in range(n)]
# 入力
for i in range(m):
    a, b, c = map(int, input().split())
    a, b = a - 1, b - 1
    d[a][b] = c
    d[b][a] = c # 無向グラフ
for i in range(n):
    d[i][i] = 0

dist = deepcopy(d)
# FloydWarshall
for k in range(n):
    for i in range(n):
        for j in range(n):
            dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
cnt = 0
for i in range(n):
    for j in range(i + 1, n):
        if d[i][j] < INF and d[i][j] != dist[i][j]:
            cnt += 1
print(cnt)

Measured memory_bytes: 75336
#include<bits/stdc++.h> 
using namespace std; 
//python interactive_runner.py python3 local_testing_tool.py 0 -- ./Code
 
#define x first
#define y second
#define rep(i, a,b) for(int i = int(a); i < int(b); ++i)
#define forn(i,b) for(int i = 0; i < int(b); ++i)
int n;
const int MAXN = 200000+9;
vector<vector<int> > adj(MAXN);
int maxa = 0;
int dfs(int node,int parent){
	vector<int> ni;
	forn(j,adj[node].size()){
		int nei = adj[node][j];
		if(nei!=parent){
		   int dis = dfs(nei,node);
		   ni.push_back(dis);
		}
	}
	sort(ni.begin(),ni.end());
	if(ni.size()>1) maxa = max(maxa,ni[ni.size()-1]+ni[ni.size()-2]+2);
	else if(ni.size())maxa = max(maxa,ni[ni.size()-1]+1);
    if(!ni.size()) return 0;
	return ni[ni.size()-1]+1;
	
}
void solve(){
  int n;
  cin>>n;
  forn(j,n-1){
  	int a,b;
  	cin>>a>>b;
  	a--;b--;
  	adj[a].push_back(b);
  	adj[b].push_back(a);
  }
  int a = dfs(0,-1);
  //cout<<maxa<<endl;
  if(maxa%3==1){
  	cout<<"Second"<<'\n';
  }
  else{
  	cout<<"First"<<'\n';
  }
}
int main(){
	 solve();
	return 0;
}

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

int main(){
  int n;

  cin >> n;

  int ans = 1;
  int maxsum = 0;
  for (int i = 1; i <= n; i++) {
    int x = i;
    int sum = 0;
    while (true) {
      if (x % 2 == 0) {
        sum++;
        x /= 2;
      }
      else {
        break;
      }
    }
    if (sum > maxsum) {
      maxsum = sum;
      ans = i;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
N,K=map(int,input().split())
nums=list(input().split())
used_balls=0
dict={}
for n in nums:
  if n not in dict.keys():
    dict[n]=1
  else:
    dict[n]+=1
tmp=0
for d in sorted(dict.items(),key=lambda x: x[1],reverse=True):
  tmp+=1
  if tmp<=K:
    used_balls+=d[1]
  else:
    break
    
print(N-used_balls)
  

Measured memory_bytes: 44800
n, k = gets.chomp.split.map(&:to_i)

ue = (n-1) * (n-2) / 2
# sita = n - 2

if ue < k
    puts -1
else
    kaisu = ue - k
    puts kaisu + n - 1 
    # puts 0
    for i in 2..n
        puts "1 #{i}"
    end
    for i in 2..n
        for j in (i+1)..n
            if kaisu > 0
                puts "#{i} #{j}"
                kaisu -= 1
            end
        end
    end
end



Measured memory_bytes: 1788
#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define rep(i,s,e) for (int64_t i=s; i<e; i++)
#define pi 3.14159265358979323846264338327950L
using namespace std;

int main() {
  int A, B, C, M;
  cin >> A >> B >> C;
  M=max(A,max(B,C));
  if ((3*M)%2==(A+B+C)%2) {
    cout << (3*M-A-B-C)/2 << endl;
  }
  else {
    cout << (3*M-A-B-C)/2+2 << endl;
  }
}

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

#define st first
#define nd second
#define ll long long
#define ld long double
#define pb push_back
#define emp emplace_back
#define pii pair<int, int>
#define usg unsigned
#define sg signed
#define mp make_pair

using namespace std;

void setIO(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
}

const ld PI = 4*atan((ld)1);
const int INF = 1e9+7;
const int MOD = 998244353;
const int mxN = 2e5+7;

ll f[mxN+7];

ll expo(ll x, ll y){
	ll res=1;
	while(y){
		if(y&1) res=(res*x)%MOD;
		x = (x*x)%MOD;
		y>>=1;
	}
	return res%MOD;
}

void fact(){
	f[0]=1;
	for(ll i=1;i<=mxN;i++)
		f[i]=(f[i-1]*i)%MOD;
}

ll com(ll n, ll r){
	return (((f[n]*expo(f[n-r],MOD-2))%MOD)*expo(f[r], MOD-2))%MOD;
}

int main(){
	setIO();
	fact();
	ll n, m, k,ans=0;
	cin>>n>>m>>k;
	for(ll i=0;i<=k;i++){
		ans=(ans+(com(n-1,i)*expo(m-1,n-1-i))%MOD)%MOD;
	}
	cout<<(ans*m)%MOD<<endl;
}

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

int main() {
    Int n; cin >> n;
    set<Int> t;
    rep(i, n) {
        Int tmp;
        cin >> tmp;
        t.insert(tmp);
    }
    Int ans = 1;
    for (auto tt : t) {
        ans = tt / __gcd(tt, ans) * ans;
    }
    cout <<ans << endl;
}

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

template<typename T>
class segTree{
public:
    int n;
    int SZ;
    vector<T> tree;
    T combine(T& a, T& b)
    {
        T res = max(a, b);
        return res;
    }
    segTree(vector<T> &arr) {
        n = arr.size();
        SZ = 2 * n;
        tree.resize(SZ+1-1, 0);
        for (int i = 0; i < n; ++i)
            tree[n + i] = arr[i];
        for (int i = n - 1; i > 0; --i){
            tree[i] = combine(tree[i << 1], tree[i << 1 | 1]);
        }
    }
    segTree(int N, T arr[])
    {
        n = N;
        SZ = 2 * n;
        tree. resize(SZ);
        for (int i = 0; i < n; ++ i)
            tree[n+i] = arr[i];
        for (int i = n - 1; i >= 0; -- i)
            tree[i] = combine(tree[i << 1], tree[i << i | 1]);
    }
    segTree() {}
    void update(int p, T value)
    {
        for (tree[p += n] = value; p > 1; p >>= 1)
            tree[p >> 1] = combine(tree[p], tree[p ^ 1]);
    }
    void update(int left, int right, T value)
    {
        for(left += n, right += n; left < right; left >>= 1, right >>= 1)
        {
            if (left & 1)
            {
                tree[left] = combine(tree[left], value);
                left ++;
            }
            if (right & 1)
            {
                -- right;
                tree[right] = combine(tree[right], value);
            }
        }
    }
    T query(int p)
    {
        T res = 0;
        for (p += n; p > 0; p >>= 1)
        {
            res = combine(res, tree[p]);
        }
        return res;
    }
    T query(int left, int right)
    {
        T res = 0;
        for (left += n, right += n; left < right; left >>= 1, right >>= 1)
        {
            if (left & 1)
                res = combine(res, tree[left ++]);
            if (right & 1)
                res = combine(res, tree[-- right]);
        }
        return res;
    }
};

using ll = long long;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define debug cerr

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    cin >> n;
    vector<int> h(n), a(n);
    for (auto &x: h) cin >> x;
    for (auto &x: a) cin >> x;
    vector<ll> dp(n+1, 0);
    segTree<ll> st(dp);
    for(int i=0; i<n; ++i) {
        ll max_dp = 0;
        max_dp = st.query(0, h[i]+1-1);
        dp[h[i]] = max_dp + a[i];
        st.update(h[i], dp[h[i]]);
    }
    ll answer = st.tree[1];
    cout << answer;
}

Measured memory_bytes: 9480
#include<iostream>
using namespace std;
int n, A[20];

bool solve(int i, int m)
{
	if (m == 0) return true;
	if (i == n) return false;

	bool res = solve(i + 1, m) || solve(i + 1, m - A[i]);
	return res;
}

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

	int m, q;

	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> A[i];

	cin >> q;
	for (int i = 0; i < q; i++)
	{
		cin >> m;
		if (solve(0, m))
			cout << "yes\n";
		else
			cout << "no\n";
	}

	return 0;
}


Measured memory_bytes: 3212
#include <stdio.h>
int main(void)
{
  int n;

  while(1){
    scanf("%d",&n);
    if(n){
      int cnt=0;
      while(n!=1){
        if(n%2==0)
	  n/=2;
        else
	  n=3*n+1;
        cnt++;
      }
      printf("%d\n",cnt);
    }
    else
      break;
  }
  return 0;
}

Measured memory_bytes: 600
from collections import Counter
def solve():
  N = int(input())
  A = list(map(int, input().split()))
  c = Counter(A)
  cnt = 0
  for k,v in c.items():
    cnt += v*(v-1)//2
  ans = [cnt]*N
  for i in range(N):
    ans[i] -= c[A[i]]*(c[A[i]]-1)//2
    ans[i] += (c[A[i]]-1)*(c[A[i]]-2)//2
  
  return ans
print(*solve(),sep='\n')


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

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

const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define DEBUG(x) ;
#define DEBUG(x) std::cerr << #x << " : " << (x) << std::endl;

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



int main(int argc, char **argv)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);


	string s; cin >> s;
	if (s.back() == 's')
		s += "es";
	else
		s += 's';
	std::cout << s << std::endl;
	return 0;
}


Measured memory_bytes: 3660
def main():
    N = int(input())
    A = list(map(int, input().split()))

    cumsum = [[0]*(N-i+1) for i in range(N+1)]

    dp = [[float("inf")]*(N-i+1) for i in range(N+1)]
    dp[1] = [0] * N
    cumsum[1] = A
    for i in range(2, N+1):
        for j in range(N-i+1):
            cumsum[i][j] = cumsum[i-1][j+1] + A[j]
            for k in range(1, i):
                dp[i][j] = min(dp[k][j] + dp[i-k][j+k] +
                               cumsum[i][j], dp[i][j])
    print(dp[N][0])


if __name__ == "__main__":
    main()


Measured memory_bytes: 45788
#include<stdio.h>
#include<stdbool.h>
int main(void)
{
	int card[4][14]={false};
	char e[4]={'S','H','C','D'};
	int n,j,X;
	int i=0;
	char egara;
	
	scanf("%d",&n);
	//printf("test:%d\n",n);
	//for(i=1;i<=n;i++){
	do{
		scanf("%c %d",&egara,&X);
		for(j=0;j<4;j++){
			if(egara==e[j]){
				card[j][X-1]=true;
				//printf("	test:%d %d %d\n",j,i,n);
				i--;
				break;
			}
		}
		i++;
	}while(i<n);
	scanf("%c %d",&egara,&X);
	for(j=0;j<4;j++){
			if(egara==e[j]){
				card[j][X-1]=true;
				//printf("	test:%d %d %d\n",j,i,n);
				break;
			}
	}
		
	//printf("\n");
	for(j=0;j<4;j++){
		for(i=0;i<13;i++){
			if(!card[j][i]){
				printf("%c %d\n",e[j],i+1);
			}
		}
	}
	return 0;
}

Measured memory_bytes: 596
#include <iostream>
using namespace std;
int main(){
int a,b,c,k;
cin>>a>>b>>c;


if (a<=b && b<=c){
	cout<<a<<" "<<b<<" "<<c<<endl;
}
else if(a<=c && c<=b){
	cout<<a<<" "<<c<<" "<<b<<endl;
}
else if(b<=a && a<=c){
	cout<<b<<" "<<a<<" "<<c<<endl;
}
else if(b<=c && c<=a){
	cout<<b<<" "<<c<<" "<<a<<endl;
}
else if(c<=a && a<=b){
	cout<<c<<" "<<a<<" "<<b<<endl;
}
else if(c<=b && b<=a){
	cout<<c<<" "<<b<<" "<<a<<endl;
}



	return 0;
}


Measured memory_bytes: 3080
#include "bits/stdc++.h"
using namespace std;
#define int long long

int n;
const int MXN = 20;
int a[MXN][MXN];
int sc[1<<20];
int f;
int dp[1<<20];

int best(int mask) {
	// mask 1-bits are alr taken
	if (mask == f) return 0;
	if (dp[mask] != -1) return dp[mask];
	int o = f - mask;
	int b = 0;
	for (int t=o; t; t=(t-1)&o) {
		b = max(b, best(mask | t) + sc[t]);
	}
	return dp[mask] = b;
}

signed main() {
	
	for (int i=0; i<(1<<20); i++) dp[i] = -1;
	
	cin >> n;
	
	f = (1 << n) - 1;
	
	for (int i=0; i<n; i++) {
		for (int j=0; j<n; j++) {
			cin >> a[i][j];
		}
	}
	
	for (int mask=0; mask<(1<<n); mask++) {
		int t = 0;
		for (int i=0; i<n; i++) {
			if (mask & (1 << i)) {
				for (int j=i+1; j<n; j++) {
					if (mask & (1 << j)) {
						t += a[i][j];
					}
				}	
			}
		}
		sc[mask] = t;
	}
	
	cout << best(0) << endl;
	
	
}


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


int main()
{
	int w, n, num[32];
	string s;
	cin >> w;
	fill(num, num + 32, 0);
	for (int i = 1; i < w + 1; i++){
		num[i] = i;
	}
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> s;
		string l, r;
		int commapos;

		//カンマの左
		for (int i = 0;; i++){
			if (s[i] == ','){
				commapos = i;
				break;
			}
			else{
				l += s[i];
			}
		}

		//カンマの右
		for (int i = commapos + 1; i < (signed)s.length(); i++){
			r += s[i];
		}
		int left = stoi(l);
		int right = stoi(r);
		int temp = num[left];
		num[left] = num[right];
		num[right] = temp;
	}
	for (int i = 1; i < w + 1; i++){
		cout << num[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 1216
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod= 1e+9+7;

int main(){
    ll N,M; cin>>N>>M;
    vector<ll>x(M);
    rep(i,M)cin>>x[i];
    sort(x.begin(),x.end());
    vector<ll>xx(M-1);
    rep(i,M-1){
        xx[i]=x[i+1]-x[i];
    }
    sort(xx.begin(),xx.end());
    ll ans =0;
    if(M-N<=0)cout<<0<<endl;
    else {
        rep(i,M-N){
            ans+=xx[i];
        }
        cout<<ans<<endl;
    }

    }


Measured memory_bytes: 1792
#include<algorithm>
#include<iostream>
#include<cstring>
#include<iomanip>
#include<sstream>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<cmath>
#include<stack>
#include<set>
#include<map>
#define rep(i,x,n) for(int i=x;i<=n;i++)
#define per(i,n,x) for(int i=n;i>=x;i--)
#define sz(a) int(a.size())
#define rson mid+1,r,p<<1|1
#define pii pair<int,int>
#define lson l,mid,p<<1
#define ll long long
#define pb push_back
#define mp make_pair
#define se second
#define fi first
using namespace std;
const double eps=1e-8;
const int mod=1e9+7;
const int N=1e5+10;
const int inf=1e9;
int n,m,x,y;
int main(){
	//ios::sync_with_stdio(false);
	//freopen("in","r",stdin);
	scanf("%d%d%d%d",&n,&m,&x,&y);
	printf("%.2f %d\n",1.0*n*m/2.0,x+x==n&&y+y==m);
	return 0;
}

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


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        if ((b - a) % 2 == 1) {
            System.out.println("Borys");
        } else {
            System.out.println("Alice");
        }
    }
}


Measured memory_bytes: 22996
#include <cstdio>
#include <algorithm>
using namespace std;
const int N = 2e5 + 7;
int prv[N], c[N];

struct TEdge {
	int u, v, c;
} e[N];

inline bool operator < (const TEdge &e1, const TEdge &e2) {
	return e1.c < e2.c;
}

int root(int u) {
	return prv[u] ? prv[u] = root(prv[u]) : u;
}

bool dsu(int u, int v) {
	return (u = root(u)) != (v = root(v)) ? prv[u] = v, true : false;
}

int main() {
	int n, m, k; scanf("%d%d%d", &n, &m, &k);
	for (int i = 1; i <= n; ++i) {
		scanf("%d", &c[i]);
		if (!c[i]) c[i] = k + i;
	}
	for (int i = 0; i < m; ++i)
		scanf("%d%d%d", &e[i].u, &e[i].v, &e[i].c);
	sort(e, e + m);
	int count_edge = 0;
	long long res = 0;
	for (int i = 0; i < m; ++i)
		if (dsu(c[e[i].u], c[e[i].v])) {
			res += e[i].c;
			if (++count_edge == k - 1) {
				printf("%lld", res);
				return 0;
			}
		}
	printf("-1");
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using namespace std;

int main() {
    fastIO;
    int A, B;
    cin >> A >> B;
    cout << (A * B - (A + B - 1));
}

Measured memory_bytes: 3548
#include <iostream>
#include <string>
#include <cstring>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>

ll powmod(ll a, ll b) {
	a %= MOD;
	ll res = 1;
	while (b > 0) {
		if (b % 2 == 1)res = res * a % MOD;
		a = a * a % MOD;
		b /= 2;
	}
	return res;
}



ll n, ans;
int main() {
	cin >> n;
	vector<ll> s(n);
	REP(i, n)cin >> s[i];
	sort(ALL(s));
	REP(i, n) {
		ll now = powmod(2, n - i) * powmod(4, i) % MOD;
		if(i != n - 1) now *= (n - i + 1) * powmod(2, n - i - 2) % MOD;
		now %= MOD;
		now *= s[i];
		now %= MOD;
		ans += now;
		ans %= MOD;
	}
	cout << ans << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;


int main()
{	
	int n,t[200005];
	vector<int>v;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>t[i];
		v.push_back(t[i]);
	}
	sort(v.begin(),v.end());
	for(int i=1;i<=n;i++)
	{
		if(t[i]<=v[n/2-1])cout<<v[n/2]<<endl;
		else cout<<v[n/2-1]<<endl;
	}
	return 0;
}

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

int main() {
  int A , B , C , D , L , R;
  cin >> A >> B >> C >> D;
  
  L = A + B;
  R = C + D;
  
  if ( L == R ){
    cout << "Balanced" << endl;
  }

   else if ( L > R ){
     cout << "Left" << endl;
  }
  
   else {
     cout << "Right" << endl;
  }
 
}


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

def main():
    A, B, C, D, E, F = map(int, input().split())
    waters = set()
    sugars = set()
    for a in range(0, F+1, 100 * A):
        for b in range(0, F+1, 100 * B):
            if a + b <= F:
                waters.add(a + b)
            else:
                break
    for c in range(0, F+1, C):
        for d in range(0, F+1, D):
            if c + d <= F:
                sugars.add(c + d)
            else:
                break
    waters = sorted(list(waters))[1:]
    sugars = sorted(list(sugars))
    # print(sugars)
    ans = 0
    ans_w = 0
    ans_s = 0
    for w in waters:
        for s in sugars:
            if w + s <= F:
                if s <= (w//100) * E:
                    tmp = (100 * s)/(w + s)
                    # if w == 1700:
                        # print(w, s, (100 * s)/(w + s))
                    if tmp >= ans:
                        ans = tmp
                        ans_w = w
                        ans_s = s
            else:
                break
    print(ans_w + ans_s, ans_s)

if __name__ == "__main__":
    main()

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

using namespace std;

#define DUMP(x) std::cout << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++ i)
#define ALL(r) r.begin(), r.end()
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define IMP puts("IMPOSSIBLE")
#define Imp puts("Impossible")
#define imp puts("impossible")
#define pb push_back

template<typename T> T DUP(T x, T y) { return (x + y - 1) / y; };
template <typename A, size_t N, typename T>
void arrayFill(A(&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using setint = unordered_set<int32_t>;
using setstr = unordered_set<string>;
using qint = queue<int32_t>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

void Main() {
    int n;
    cin >> n;
    vint d(n);
    rep(i, n)cin >> d[i];

    int ans = 0;
    rep(i, n)REP(j, i + 1,  n) {
        ans += d[i] * d[j];
    }
    cout << ans << endl;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N, x, y = MAP()
x -= 1; y -= 1

G = list2d(N, N, 0)
for i in range(N):
    for j in range(i+1, N):
        G[i][j] = min(j - i, abs(i - x) + abs(j - y) + 1, abs(j - x) + abs(i - y) + 1)
ans = [0] * N
for i in range(N):
    for j in range(i+1, N):
        ans[G[i][j]] += 1
[print(a) for a in ans[1:]]


Measured memory_bytes: 80348
#include"bits/stdc++.h"
#include<unordered_set>
#include<unordered_map>
#include<random>
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9+7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
int dx[4]={ 1,0,-1,0 };
int dy[4]={ 0,1,0,-1 };

#define PI 3.141592653897

#define EPS 1e-9

double a, b, x;

signed main(){
    cin >> a >> b >> x;
    x /= a;
    cout << fixed << setprecision(16);
    if(x >= a*b/2-EPS){
        double ans = atan(2*b/a-2*x/a/a);
        cout << ans/2/PI*360 << endl;
    }
    else{
        double ans = atan(b*b/2/x);
        cout << ans/2/PI*360 << endl;
    }
}

Measured memory_bytes: 256