akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
    string S;  cin >> S;
    ll N = S.length();
    ll nB = 0;
    ll ans = 0;
    for(ll i=N-1; i>=0; i--){
        if(S[i]=='B'){
            ans += (N-1) - i - nB;
            nB++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
import heapq

n, m = map(int, input().split())

item_list = list(map(lambda x: -1 * int(x), input().split()))
heapq.heapify(item_list)

for discount_i in range(m):
  target = -1*(-1*heapq.heappop(item_list)//2)
  heapq.heappush(item_list, target)

print(-1*sum(item_list))

Measured memory_bytes: 14180
#include "bits/stdc++.h"

using namespace std;

void solve()
{
    int n;
    cin >> n;
    deque<int> cs;
    set<int> s;
    for (int i = 0; i < n; i++)
    {
        int c;
        cin >> c;
        if (c > 0)
        {
            if (s.find(c) != s.end())
            {
                cout << i + 1 << endl;
                return;
            }
            s.insert(c);
            cs.push_back(c);
        }
        else
        {
            if (cs.empty() || cs.back() != -c)
            {
                cout << i + 1 << endl;
                return;
            }
            cs.pop_back();
            s.erase(s.find(-c));
        }
    }
    cout << "OK" << endl;
}

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



Measured memory_bytes: 3112
import java.util.*;

import java.lang.*;

import java.math.*;



public class Main {

	Scanner sc = new Scanner(System.in);

	void run(){

		int[] mga = {1,2,1,2,1,4,1,4};

		for(;sc.hasNextInt();){

			int[] machi = new int[8];

			for(int i=0;i<8;i++){

				machi[i] = sc.nextInt();

			}

			int min1 = Integer.MAX_VALUE;

			int min2 = Integer.MAX_VALUE;

			for(int i = 0; i < 8 ;i++){

				int sum = 0;

				int num = 0;

				for(int j = 0; j < 8 ; j++){

					sum += Math.max(0, machi[j]-mga[(i+j)&7]);

					num = num*10+mga[(i+j)&7];

				}

//				System.out.println(sum + " "+ num);

				if(sum < min1){

					min1 = sum;

					min2 = num;

				}else if(sum == min1){

					if(min2 > num){

						min2 = num;

					}

				}

			}

			char[] ch = String.valueOf(min2).toCharArray();

			String str = "";

			for(int i=0;i<8;i++){

				str += ch[i];

				str +=" ";

			}

			System.out.println(str.trim());

		}

		

	}

	public static void main(String[] args){

		Main m = new Main();

		m.run();

	}

}

Measured memory_bytes: 12000
#include <iostream>

using namespace std;

int a[500000],num=0;
int l[250005],r[250005];

void merg(int s,int e){
    int mid=(s+e)/2;
    int n1=mid-s+1,n2=e-mid;
    int i;
    for(i=0;i<n1;i++){
        l[i]=a[s+i];
    }
    for(i=0;i<n2;i++){
        r[i]=a[mid+i+1];
    }
    int m1=0,m2=0;
    for(i=0;i<e-s+1;i++){
        l[n1]=r[n2]=1000000005;
        if(l[m1]<=r[m2])a[s+i]=l[m1++];
        else a[s+i]=r[m2++];
    }
    num+=(e-s+1);
}

void mergesort(int s,int e){
    if(s==e)return;
    int mid=(s+e)/2;
    mergesort(s,mid);
    mergesort(mid+1,e);
    merg(s,e);
}

int main()
{
    int n;
    cin>>n;
    int i;
    for(i=0;i<n;i++){
        cin>>a[i];
    }
    mergesort(0,n-1);
    for(i=0;i<n;i++){
        cout<<a[i];
        if(i!=n-1)cout<<" ";
    }
    cout<<endl;
    cout<<num<<endl;
    return 0;
}



Measured memory_bytes: 6996
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
  unsigned short *A, *B;

  int C[VMAX+1];
  int n, i, j;
  scanf("%d", &n);

  A = malloc(sizeof(short)*n + 1);
  B = malloc(sizeof(short)*n + 1);
  for(i=0; i<=VMAX; i++) C[i]=0;

  for(i=0; i<n; i++){
    scanf("%hu", &A[i+1]);
    C[A[i+1]]++;
  }
  for(i=1; i<=VMAX; i++) C[i] = C[i] + C[i-1];
  for(j=1; j<=n; j++){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }
  for(i=1; i<=n; i++){
    if(i>1) printf(" ");
    printf("%d", B[i]);
  }
  printf("\n");
  return 0;
}



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

int n;
vector<long long> a;

int main(void) {
	cin >> n;
	a = vector<long long>(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	long long ret = 0;

	int i;
	for (i = 0; i<int(n / 2); i++) {
		ret += 2 * a[n - i - 1];
		ret -= 2 * a[i];
	}
	if (n % 2 == 0) {
		ret -= a[n - i];
		ret += a[i - 1];
	}
	else {
		if (abs(a[i] - a[i - 1]) > abs(a[i + 1] - a[i])) {
			ret += a[n - i - 1];
			ret -= a[n - i];
		}
		else {
			ret += a[i - 1];
			ret -= a[i];
		}
	}

	cout << ret << endl;
	return 0;
}

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

#define range(i, l, r) for (int i = (int)l; i < (int)(r); ++(i))
#define rrange(i, l, r) for (int i = ((int)(r) - 1); i >= (int)l; --(i))

#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#define rwhole(f,x,...) ([&](decltype((x)) whole) { return (f)(rbegin(whole), rend(whole), ## __VA_ARGS__); })(x)

#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using int32 = int;
using int64 = long long;

const int mod     = 1e9 + 7;
const int32 inf   = 1001001001;
const int64 infll = 1001001001001001001ll;

const int dx[] = {0, -1, 1, 0, -1, 1, -1, 1}, dy[] = {-1, 0, 0, 1, -1, -1, 1, 1};
const string YES = "YES", NO = "NO", Yes = "Yes", No = "No", yes = "yes", no = "no";

struct IoSetup { IoSetup(){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(16); cerr << fixed << setprecision(16); } } iosetup;

template <typename T = int64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } 
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << p.fs << " " << p.sc; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.fs >> p.sc; return is; }

template <typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

void solver() {
  int A = input(), B = input(), C = input();

  cout << max(0, C - (A - B)) << endl;
}

signed main(int argc, char *argv[]) {
  solver();
}


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

using namespace std;

const int N = 1234567;
const int inf = (int) 1e9;

int n;
int a[N];
int f[N];
vector<int> g[N];

bool dfs(int v, int pv, int r) {
  int sum = 0;
  int mx = 0;
  for (int to : g[v]) {
    if (to == pv) {
      continue;
    }
    if (!dfs(to, v, r)) {
      return false;
    }
    mx = max(mx, f[to]);
    sum += f[to];
  }
  if ((int) g[v].size() == 1) {
    f[v] = a[v];
    return true;
  } else {
    f[v] = 2 * a[v] - sum;
  }
  if (f[v] < 0 || sum < a[v] || mx > a[v]) {
    return false;
  }
  if (v == r) {
    return f[v] == 0;
  }
  return true;
}

bool ok() {
  int sum_a = 0;
  vector<int> all;
  for (int i = 0; i < n; i++) {
    if ((int) g[i].size() == 1) {
      sum_a += f[i];
      all.push_back(f[i]);
    }
  }
  if (sum_a % 2) {
    return false;
  }
  for (auto& x : all) {
    if (x + x > sum_a) {
      return false;
    }
  }
  return true;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);                	
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    f[i] = a[i];
  }
  for (int i = 0; i + 1 < n; i++) {
    int x, y;
    cin >> x >> y;
    x--; y--;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  for (int i = 0; i < n; i++) {
    if ((int) g[i].size() > 1) {
      if (dfs(i, -1, i) && ok()) {
        cout << "YES\n";
      } else {
        cout << "NO\n";
      }
      return 0;
    }
  }
  if (n <= 2) {
    if (a[0] == a[1]) {
      cout << "YES\n";
    } else {
      cout << "NO\n";
    }
    return 0;
  }
  assert(false);
  return 0;
}

Measured memory_bytes: 42880
#include <bits/stdc++.h>
using namespace std;
template<typename T>
void fin(T a){
  cout<<a<<endl;
  exit(0);
}
struct tree{
  vector<vector<int>> G,son,ancestor;
  vector<int> depth,parent;
  queue<int> que;
  int root=-1;
  bool made_lca=false;

  tree(int n):G(n),son(n),parent(n,-1),depth(n,-1),ancestor(n){
    for(int i=0;i<n;i++)ancestor[i].resize(30);
  }

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

  inline void reset_root(){
    root=-1;
    fill(depth.begin(),depth.end(),-1);
    fill(parent.begin(),parent.end(),-1);
    for(auto &p:ancestor)for(int &q:p)q=-1;
    for(auto &p:son)p.resize(0);
    made_lca=false;
  }

  void have_root(int r){
    reset_root();
    root=r;
    que.push(r);
    while(que.size()){
      int p=que.front();que.pop();
      for(int q:G[p]){
        if(parent[p]==q)continue;
        son[p].push_back(q);
        parent[q]=p;
        que.push(q);
      }
    }
  }

  void set_depth(){
    assert(~root);
    depth[root]=0;
    que.push(root);
    while(que.size()){
      int p=que.front();que.pop();
      for(int q:son[p]){
        depth[q]=depth[p]+1;
        que.push(q);
      }
    }
  }

  inline void make_lca(){
    assert(~root);
    if(depth[root]<0)set_depth();
    for(int i=0;i<G.size();i++)ancestor[i][0]=parent[i];
    for(int j=1;j<30;j++)
      for(int i=0;i<G.size();i++)
        if(~ancestor[i][j-1])
          ancestor[i][j]=ancestor[ancestor[i][j-1]][j-1];
    made_lca=1;
  }

  int lca(int u,int v){
    if(!made_lca)make_lca();
    if(depth[u]>depth[v])swap(u,v);
    int diff=depth[v]-depth[u],cnt=0;
    while(diff){
      if(diff&1)v=ancestor[v][cnt];
      cnt++;
      diff>>=1;
    }
    if(u==v)return u;
    for(int k=28;k>=0;k--)
      if(ancestor[u][k]!=ancestor[v][k])
        u=ancestor[u][k],v=ancestor[v][k];
    return ancestor[u][0];
  }
};
int n,odd,now1,now2,now3,ans[223456];
int one(int a){
  if(now1*3+1<=n)return now1++*3+1;
  return -1;
}
int two(int a){
  if(now2*3+2<=n)return now2++*3+2;
  return -1;
}
int three(int a){
  return now3++*3+3;
}

signed main(){
  cin>>n;
  tree t(n);
  for(int i=1;i<n;i++){
    int u,v;cin>>u>>v;u--;v--;
    t.add_edge(u,v);
  }
  t.have_root(0);
  t.set_depth();
  for(int i=0;i<n;i++)odd+=t.depth[i]&1;
  if(odd<=n/3){
    for(int i=0;i<n;i++){
      if(t.depth[i]&1)ans[i]=three(i);
      else ans[i]=one(i);
      if(!~ans[i])ans[i]=two(i);
      if(!~ans[i])ans[i]=three(i);
    }
  }
  else if(n-odd<=n/3){
    for(int i=0;i<n;i++){
      if(!(t.depth[i]&1))ans[i]=three(i);
      else ans[i]=one(i);
      if(!~ans[i])ans[i]=two(i);
      if(!~ans[i])ans[i]=three(i);
    }
  }
  else{
    for(int i=0;i<n;i++){
      if(t.depth[i]&1)ans[i]=one(i);
      else ans[i]=two(i);
      if(!~ans[i])ans[i]=three(i);
    }
  }
  for(int i=0;i<n;i++)cout<<ans[i]<<endl;
}


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

typedef long long i64;
#define put(n) cout<<(n)<<"\n"
#define FOR(i,num,N) for(int(i)=(num);(i)<(N);(i)++)
#define RFOR(i,num,N) for(int (i)=(num);(i)>(N);(i)--)
#define all(v) (v).begin() , (v).end()
#define rall(v) (v).rbegin() , (v).rend()

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

    vector<pair<int,int>> BA(M);
    FOR(i,0,M) cin>>BA[i].second>>BA[i].first;//firstがBの値,secondがAの値

    sort(all(BA));

    int bridge = -1;

    FOR(i,0,M){
        if(bridge <= BA[i].second){
            bridge = BA[i].first;
            ans++;
        }
    }
    put(ans);
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <math.h>
int main(void){
    double x1,x2,y1,y2,a,d;
    scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
    
    a = ((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
    d = sqrt(a);
    
    printf("%f\n",d);
    
    return 0;
}



Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first
#define se second
#define co(a) cout<<a<<endl
#define sz size()
#define bgn begin()
#define en end()
#define pb(a) push_back(a)
#define pp() pop_back()
#define V vector
#define P pair
#define V2(a,b,c) V<V<int>> a(b,V<int>(c))
#define V2a(a,b,c,d) V<V<int>> a(b,V<int>(c,d))
#define incin(a) int a; cin>>a
#define yuko(a) setprecision(a)
#define uni(a) a.erase(unique(a.begin(),a.end()),a.end())
//#define min min<int>
//#define max max<int>
template<class T>
 void cou(vector<vector<T>> a){
  int b=a.size();
  int c=a[0].size();
  fo(i,b){
    fo(j,c){
      cout<<a[i][j];
      if(j==c-1)
        cout<<endl;
      else
        cout<<' ';
    }
  }
}
/*template<>
 void cou(vector<vector<char>> a){
  int b=a.size();
  int c=a[0].size();
  fo(i,b){
    fo(j,c){
      cout<<a[i][j];
      if(j==c-1)
        cout<<endl;
      else
        cout<<' ';
    }
  }
}*/
 int wari(int a,int b) {
   if(a%b==0)
     return a/b;
   else
     return a/b+1;
 }
 int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
 }
 int souwa(int a){
  return a*(a+1)/2;
 }
 /*int lcm(int a,int b){
  int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return d*e/f;
    }
  int gcm(int a,int b){
      int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return f;
  }*/
 bool prime(int a){
   if(a<2)
     return false;
   else if(a==2)
     return true;
   else if(a%2==0)
     return false;
   double b=sqrt(a);
    for(int i=3;i<=b;i+=2){
      if(a%i==0){
        return false;
      }
    }
   return true;
 }
struct Union{
  vector<int> par;
  Union(int a){
	par= vector<int>(a,-1);
  }
  int find(int a){
    if(par[a]<0)
      return a;
    else
      return par[a]=find(par[a]);
  }
  bool same(int a,int b){
    return find(a)==find(b);
  }
  int Size(int a){
    return -par[find(a)];
  }
  void unite(int a,int b){
    a=find(a);
    b=find(b);
    if(a==b)
      return;
    if(Size(b)>Size(a))
      swap<int>(a,b);
    par[a]+=par[b];
    par[b]=a;
  }
};
int ketas(int a){
  string b=to_string(a);
  int c=0;
  fo(i,keta(a)){
    c+=b[i]-'0';
  }
  return c;
}
int gcm(int a,int b){
    if(b==0)
        return a;
    return gcm(b,a%b);
}
int lcm(int a,int b){
    return a/gcm(a,b)*b;
}
/*struct aa{
	vector<int> gt;
  aa(int n){
	gt= vector<int>(n, 1);
  }
	void c(V<int> d,int b){
	if(d[b]==0){
		gt[d[b]-1]++;
		gt[gt.sz-1]++;
	}
	else{
		gt[d[b]-1]++;
		c(d,d[d[b]]-1);
	}
}
void cok(int a){
	cout<<gt[a-1]<<endl;
	fo(i,a-1)
	cout<<gt[i]<<endl;
}
};
*/
/*struct dfs(){

}*/
signed main(){
	int a,b,c;
	cin>>a>>b>>c;
	V<int> d(a);
	fo(i,a)
	cin>>d[i];
	fo(i,a){
		c+=(b-1)/d[i]+1;
	}
	cout<<c<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
typedef long long ll;
typedef long double ld;
int main() {
	int a, b, c;
	scanf("%d%d%d", &a, &b, &c);
	printf("%d\n", min(c, a + b + 1) + b);
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long ll;

map<ll, ll> prime_factor(ll n){
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ++res[i];
      n /= i;
    }
  }
  if (n != 1) res[n] = 1;
  return res;
}

int main(int argc, char const *argv[])
{
    ll n;
    map<ll, ll> mp;
    cin >> n;
    mp = prime_factor(n);
    vector<ll> vec;
    for(auto x: mp){
        ll num = x.first, cnt = x.second;
        for (int i = 0; i < cnt; ++i) vec.emplace_back(num);
    }
    sort(vec.begin(), vec.end());

    cout << n << ':';

    for (int i = 0; i < vec.size(); ++i) {
        cout << ' ' << vec[i];
    }

    cout << endl;

    return 0;
}


Measured memory_bytes: 3164
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pp pair<ll,ll>
#define ppp pair<ll,pp >
#define trace(...) cout<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cout<<name<<" : "<<arg1<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma=strchr(names+1,',');
	cout.write(names,comma-names)<<" : "<<arg1<<" | ";
	__f(comma+1,args...);
}
typedef tree<pp,null_type,less<pp>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
#define ld long double
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rep(i,a,b) for(ll i=a;i<b;i+=1)
#define sz(v) (ll)(v.size())
//#define hell (ll)1000000007
#define slld(x) scanf("%lld",&x)
ll t=1, tt;
const ll N=100005;
vector<ll> adj[N], pref[N], suf[N], ways(N), sub(N), child[N];
ll hell=1e18+5;
inline ll mult(ll x,ll y){x%=hell;y%=hell;return (1LL*x*y)%hell;}
inline ll add(ll x,ll y){x+=y;return x%hell;}
inline ll powMod(ll base,ll expo){
	if(base==0)return 0;
	ll ans=1;
	while(expo){
		if(expo&1)ans=mult(ans,base);
		base=mult(base,base); 
		expo>>=1;
	}
	return ans;
}
void dfs(ll node,ll par){
	sub[node]=1;
	ll x=1;
	for(auto u : adj[node]){
		if(u==par)continue;
		child[node].pb(u);
		dfs(u,node);
		sub[node]=mult(sub[node],sub[u]+1);
		x=mult(x,sub[u]+1);
		pref[node].pb(x);
	}
	x=1;
	for(ll i=sz(adj[node])-1;i>=0;i--){
		if(adj[node][i]==par)continue;
		x=mult(x,sub[adj[node][i]]+1);
		suf[node].pb(x);
	}
	reverse(all(suf[node]));
}
void dfs2(ll node,ll up){
	ways[node]=(up+1)%hell;
	rep(i,0,sz(child[node])){
		ll newUp=(up+1);
		if(i!=0)newUp=mult(newUp,pref[node][i-1]);
		if(i!=sz(child[node])-1)newUp=mult(newUp,suf[node][i+1]);
		dfs2(child[node][i],newUp);
		ways[node]=mult(ways[node],(sub[child[node][i]]+1));
	}
}
void solve(){
	ll n, x, y;
	cin>>n>>hell;
	rep(i,1,n){
		cin>>x>>y;
		adj[x].pb(y);
		adj[y].pb(x);
	}
	dfs(1,0);
	dfs2(1,0);
	rep(i,1,n+1){
		if(i>1)cout<<"\n";
		cout<<ways[i]%hell;
	}
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
   	//cin>>t;
   	//tt=t;
    while(t--){
        solve();
        if(t)cout<<"\n";
    }
    return 0 ;
}


Measured memory_bytes: 30464
'use strict';
(function(stdin) {
 
  var inputs  = stdin.toString().trim().split('\n');
  var cols = inputs[0].split(' ');
  var colsNumber = cols.map(Number);
  var Ascending_order = colsNumber.sort(function(a, b){return a > b;}).join(' ');
   
  console.log(Ascending_order);
 
}(require('fs').readFileSync('/dev/stdin', 'utf8')));

Measured memory_bytes: 15528
#include <iostream>
#include <iomanip>
#include <array>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <tuple>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <numeric>
#include <cassert>
#include <functional>
using namespace std;

typedef unsigned long long int llui;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
constexpr double pi = 3.141592653589793238462643383279502884L;

// TODO: Mod class

const int sz = 1e5 + 5;
int group[sz];
typedef pair<int, pii> piii;

int Find(int n) {
  int g = group[n];
  if (g != n) {
    group[n] = Find(g);
  }
  return group[n];
}

void Union(int n, int m) {
  int g1 = Find(n);
  int g2 = Find(m);
  if (g1 != g2) {
    group[g1] = g2;
  }
}

piii make_piii(int a, int b, int c) {
  return make_pair(a, make_pair(b, c));
}

int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<pii> ori(n);
  for (int i = 0; i < n; ++i) {
    cin >> ori[i].first >> ori[i].second;
  }
  sort(ori.begin(), ori.end());
  ori.resize(unique(ori.begin(), ori.end()) - ori.begin());

  vector<pii> x;
  vector<pii> y;
  for (int i = 0; i < ori.size(); ++i) {
    int a, b;
    a = ori[i].first;
    b = ori[i].second;
    x.push_back(make_pair(a, i));
    y.push_back(make_pair(b, i));
  }

  sort(x.begin(), x.end());
  sort(y.begin(), y.end());

  vector<piii> xdiff;
  vector<piii> ydiff;

  for (int i = 0; i < x.size(); ++i) {
    xdiff.push_back(make_piii(abs(x[i].first - x[i + 1].first), x[i].second, x[i + 1].second));
    ydiff.push_back(make_piii(abs(y[i].first - y[i + 1].first), y[i].second, y[i + 1].second));
  }

  sort(xdiff.begin(), xdiff.end());
  sort(ydiff.begin(), ydiff.end());

  for (int i = 0; i < n; ++i) {
    group[i] = i;
  }

  int fx = 0;
  int fy = 0;
  ll cost = 0;
  for (int i = 0; i < ori.size() - 1; ++i) {
    piii now;
    if (fx == xdiff.size() && fy == ydiff.size()) {
      break;
    }
    if (fx == xdiff.size()) {
      now = ydiff[fy++];
    } else if (fy == ydiff.size()) {
      now = xdiff[fx++];
    } else {
      if (xdiff[fx].first < ydiff[fy].first) {
        now = xdiff[fx++];
      } else {
        now = ydiff[fy++];
      }
    }
    
    if (Find(now.second.first) == Find(now.second.second)) {
      --i;
      continue;
    }
    Union(now.second.first, now.second.second);
    cost += now.first;
  }

  cout << cost << endl;
}


Measured memory_bytes: 6632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll a, b, k;
    cin >> a >> b >> k;
    ll ae = min(a, k);
    a -= ae;
    k -= ae;
    b = max(0LL, b - k);
    printf("%lld %lld\n", a, b);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const long long INFLL = LLONG_MAX / 3;
const double eps = (1e-9);


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

  ll n, h;
  cin >> n >> h;
  vector<ll> a(n), b(n);
  rep(i, n) cin >> a[i] >> b[i];

  ll a_max = MAX(a);
  sort(ALL(b));

  ll ans = 0;
  while (h > 0) {
    if (!b.empty() && b.back() > a_max) {
      h -= b.back();
      b.pop_back();
      ans++;
    } else {
      ans += (h + a_max - 1) / a_max;
      break;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <numeric>
using namespace std;

int W, N;
int X[50010];
int f[50010], s[50010];

void read();
void soups_on();
bool yee_haw(int);

int main() {
  ios::sync_with_stdio(false);
  while (cin >> W >> N, W + N)
    read(), soups_on();

  return 0;
}

void read() {
  X[0] = W, X[N + 1] = W;
  for (int i = 1; i <= N; ++i)
    cin >> X[i];
  partial_sum(X, X + (N + 2), X);
}

void soups_on() {
  int low = 1, up = W, mid;

  while (low < up) {
    mid = (low + up) / 2;
    if (yee_haw(mid))
      up = mid;
    else
      low = mid + 1;
  }

  cout << low << "\n";
}

bool yee_haw(int lm) {
  int lb, ub, sum = 0, p;

  fill(&f[0], &f[N + 2], 0), lb = ub = 0;
  for (int i = 0; i <= N; ++i) {
    sum += f[i], s[i] = sum;
    if (i == 0 || sum > 0) {
      lb = max(lb, i + 1);
      while (lb <= N && (X[lb] - X[i]) + lm * (lb - i - 1) < W)
        ++lb;
      ub = max(ub, i + 1);
      while (ub <= N && (X[ub] - X[i]) + (ub - i - 1) <= W)
        ++ub;
      ++f[lb], --f[ub];
    }
  }

  p = 0, s[0] = 1;
  for (int i = N; i >= 0 && p <= W; --i) {
    if (s[i] > 0)
      return true;
    p = (X[N] - X[i - 1]) + (N - i);
  }

  return false;
}

Measured memory_bytes: 1780
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

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

using namespace std;
typedef long long ll;

int main()
{
    // Input
    string s, t;
    cin >> s;
    cin >> t;

    int ans = 0;

    for (int i = 0; i < s.length(); i++) {
        if (s[i] != t[i]) {
            ans++;
        }
    }
    cout << ans;

    return 0;
}


Measured memory_bytes: 3468
#include <bits/stdc++.h>
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

int main() {
	int a, b; scanf("%d%d", &a, &b);
	
	if(b % a == 0) printf("%d\n", a + b);
	else printf("%d\n", b - a);
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {

//    	File file = new File("test.txt");
//    	Scanner sc = new Scanner(file);
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] ary = new int[N];
        for(int i = 0; i < N; i++){
        	ary[i] = 0;
        }
        for(int i = 0; i < K; i++){
        	int d = sc.nextInt();
        	for(int l = 0; l < d; l++){
        		int A = sc.nextInt();
        		ary[A-1]++;
            }
        }
        sc.close();
        int ans = 0;
        for(int i = 0; i < N; i++){
        	if(ary[i] == 0) ans++;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 46192
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int N,a,b,c;
    cin>>a;
    cin>>b;
    cin>>c;
    cin>>N;
    int count =0;
    for (int i=0; i<=a; i++){
        for (int k=0; k<=b; k++){
            for (int j=0; j<=c; j++){
                if(i*500+k*100+j*50==N) count+=1;
            }
        }
    }
    cout<<count<<endl;
}


Measured memory_bytes: 256
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
# define MSG(x) std::cout << #x << " : " << x << "\n";
using namespace std;
using lint = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main()
{
    int N, X;
    cin >> N >> X;
    vector<int> L(N);
    rep (i, N)
    {
        cin >> L[i];
    }

    vector<int> D;
    D.push_back(0);
    for (int i = 1; i < N+1; ++i)
    {
        D.push_back(D[i-1] + L[i-1]);
    }

    int cnt = 0;
    rep (i, SZ(D))
    {
        if (D[i] <= X)
        {
            cnt++;
        }
    }

    cout << cnt << "\n";


    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define rep(i,n) for(int i=0;i<n;i++)
int gcd(int a, int b){
    int r=1;
    while(r!=0){
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}
void revStr(char* str){
    int size = strlen(str);
    int i,j;
    char tmp = {0};
    for(i = 0, j = size - 1; i < size / 2; i++, j--){
        tmp = str[i];
        str[i] = str[j];
        str[j] = tmp;
    }return;
}
struct data{
    int a,b,c;
};

//降順
int compare_int(const void *a, const void *b)
{
    return *(int*)b - *(int*)a;
}
#define MAXSIZE 200000
int list[MAXSIZE];
int tail;

void Init(void){
    tail=0;
}
int Top(void){
    return 0;
}

int Next(int pos){
    if(pos<tail-1){
        return pos+1;
    }else{
        return -1;
    }
}
int Count(void){
    return tail;
}

int Item(int pos){
    if((pos>=0)&&(pos<tail)){
        return list[pos];
    }else{
        return 0;
    }
}
void Add(int value){
    if(tail<MAXSIZE){
        list[tail]=value;
        tail++;
    }
}
void Delete(int pos){
    if((pos>=0)&&(pos<tail)){
        int i;
        for(i=pos;i<tail-1;i++){
            list[i]=list[i+1];
        }
        tail--;
    }
}

int main(){
    int N,K;
    scanf("%d%d",&N,&K);
    int pos[N];
    rep(i,N){
        scanf("%d",&pos[i]);
    }
    int sum=0;
    rep(i,N){
        if(abs(K-pos[i])<abs(pos[i])){
            sum+=abs(K-pos[i])*2;
        }else{
            sum+=abs(pos[i])*2;
        }
    }
    printf("%d",sum);
}


Measured memory_bytes: 1732
#define _USE_MATH_DEFINES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1000000007; 
const int INF = 1000000000; //1e9
const int NIL = -1;
const long long LINF = 1000000000000000000; // 1e18
const double EPS = 1E-10;

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




int main(){
    int R; std::cin >> R;
    std::cout << std::fixed << std::setprecision(10) << 2 * R * M_PI << std::endl;
    return 0;
}


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

#define IO  ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
#define endl '\n'
#define ll long long
#define f first
#define s second
#define mod 1000000007
#define INF 0x3f3f3f3f3f3f3f3f
using namespace std;

int main()
{
    IO
    int n;
    cin>>n;
    ll a[n+5],b[n+5],ans=0;
    for(int i=0;i<=n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        cin>>b[i];
    }
    for(int i=0;i<n;i++){
        if(a[i]<=b[i]){
           ans+=a[i];
           b[i]-=a[i];
           a[i]=0;
        }
        else {
            ans+=b[i];
            a[i]-=b[i];
            continue;
        }
        if(i+1<=n){
            if(a[i+1]<=b[i]){
                ans+=a[i+1];
                b[i]-=a[i+1];
                a[i+1]=0;
            }
            else {
                ans+=b[i];
                a[i+1]-=b[i];
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 5212
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvv vector<vvl>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvvl(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

char c;
vll detect(vll d, ll k, ll mode = -1){
  ll l = (mode==1?1:0), r = 10;
  ll tmp = 0;
  for(int i=0;i<d.size();i++) tmp*=10, tmp+=d[i];
  while(r-l>1){
    ll mid = (l+r)/2;
    ll now = tmp * 10 + mid;
    for(int i=0;i<k-d.size()-1;i++) now *= 10;
    now *= 10;
    std::cout << "? " << now << '\n' << flush;
    std::cin >> c;
    if(c=='Y') r = mid;
    else l = mid;
  }
  d.push_back(l);
  return d;
}

int main(int argc, char const *argv[]) {
  ll l = 1, r = 11;
  while(r-l>1){
    ll mid = (l+r)/2;
    ll tmp = 1;
    for(int i=0;i<mid-1;i++) tmp *= 10;
    std::cout << "? " << tmp << '\n' << flush;
    std::cin >> c;
    if(c=='Y') l = mid;
    else r = mid;
  }
  bool flag = false;
  if(l==10){
    l = 1, r = 11;
    while(r-l>1){
      ll mid = (l+r)/2;
      ll tmp = 1;
      for(int i=0;i<mid-1;i++) tmp *= 10;
      tmp -= 1;
      std::cout << "? " << tmp << '\n' << flush;
      std::cin >> c;
      if(c=='Y') r = mid;
      else l = mid;
    }
    flag = true;
  }
  vll d;
  for(int i=0;i<l;i++) d = detect(d, l, (i==0?1:-1));
  ll ans = 0;
  re(i, d.size()) ans = ans * 10 + d[i];
  std::cout << "! " << ans+(flag?0:1) << '\n' << flush;
  return 0;
}


Measured memory_bytes: 596
using System;
using System.Linq;
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ').Select(s=>int.Parse(s)).ToArray();
            var W = input[0];
            var a = Math.Min(input[1], input[2]);
            var b = Math.Max(input[1], input[2]);
            Console.WriteLine(b - a - W <= 0 ? 0 : b - a - W);
        }
    }

Measured memory_bytes: 13268
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		int m = sc.nextInt();
		int a[] = new int[n];
		boolean b[] = new boolean[n];
		b[0] = true;
		Arrays.fill(a, 1);
		int x, y;
		for (int i = 0; i < m; i++) {
			x = sc.nextInt() - 1;
			y = sc.nextInt() - 1;
			if (b[x]) {
				a[x]--;
				a[y]++;
				b[y] = true;
				if (a[x] == 0) {
					b[x] = false;
				}
			} else {
				a[x]--;
				a[y]++;
			}
		}

		int cnt = 0;
		for (int i = 0; i < n; i++) {
			if (b[i] && a[i] > 0) {
				cnt++;
			}
		}
		System.out.println(cnt);
	}
}

Measured memory_bytes: 63360
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,k;
int main()
{
    cin>>a>>b>>c>>k;
    if(k<a)
        cout<<k;
    else if(k<=a+b)
        cout<<a;
    else
        cout<<a-k+a+b;
}


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

int main() {
  int64_t A;
  double B;
  cin >> A >> B;
  
  double s = B * 100 + 0.5;
   int k = (int)s;
  int64_t t = A * k / 100;
  cout << t;
    
  
}
        


Measured memory_bytes: 3728
//Be Name Khoda
//me and who? :|
/*
ID: aminra81
PROG: gift1
LANG: C++11
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9 + 7;
const ll inf = (ll)1e18;
const int infint = (int)2e9;
const int MAXN = (int)3e5 + 10;
ll a[MAXN], pre[MAXN], nxt[MAXN];
int main()
{
	ll sum = 0, n;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	stack<int> T;
	for (int i = 0; i < n; i++)
	{
		while(T.size() > 0 and a[i] <= a[T.top()])
			T.pop();
		if(T.size() == 0)
			pre[i] = -1;
		else
			pre[i] = T.top();
		T.push(i);
	}
	while(T.size())
		T.pop();
	for (int i = n - 1; i >= 0; i--)
	{
		while(T.size() > 0 and a[i] < a[T.top()])
			T.pop();
		if(T.size() == 0)
			nxt[i] = n;
		else
			nxt[i] = T.top();
		T.push(i);
	}
	for (int i = 0; i < n; i++)
	{
		sum += (i - pre[i]) * (nxt[i] - i) * a[i];
	}
	cout << sum;
}

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

int N, M;
int dp[5010][5010];

int main() {
  cin >> N >> M;
  for (int i=0; i<M; i++) {
    int a, b, x;
    cin >> a >> b >> x;
    dp[a-1][b-1] = max(dp[a-1][b-1], x + 1);
  }

  for (int i=0; i<N; i++) {
    for (int j=0; j<=i; j++) {
      dp[i+1][j]   = max(dp[i+1][j],   dp[i][j] - 1);
      dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] - 1);
    }
  }
  int ans = 0;
  for (int i=0; i<N; i++) {
    for (int j=0; j<=i; j++) {
      ans += dp[i][j] != 0;
    }
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 69860
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;

int main(void)
{
	int N;
	cin >> N;
	LL ans = 0;
	bool same = true;
	LL Bmin = LLONG_MAX;
	for (int i = 0; i < N; ++i) {
		LL A, B;
		cin >> A >> B;
		if (A != B)same = false;
		ans += A + B;
		if (A > B) {
			Bmin = min(Bmin, B);
		}
	}
	if (same)cout << 0 << endl;
	else cout << ans / 2 - Bmin << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int X, A, B;
    cin >> X >> A >> B;
    X -= A;
    X = X % B;
    cout << X << endl;

    return 0;
}


Measured memory_bytes: 256
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>

using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f3f3f3f3fLL
#define SIZE 8080
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
ll MOD=1e9+7;
typedef ll Weight;
struct Edge {
	int src, dst;
	Weight weight;
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
int check(int now){
	int ret=0;
	while(now%2==0){
		now/=2;
		ret++;
	}
	return ret;
}

int main(){
	int N,M;
	cin>>N>>M;
	vector<ll> data[1111];
	for(int i=0;i<N;i++){
		ll x,y,z;
		cin>>x>>y>>z;
		data[i].pb(x);
		data[i].pb(y);
		data[i].pb(z);
	}
	ll ans=0;
	for(int i=0;i<(1<<3);i++){
		int wh = i;
		int ret[3]={1,1,1};
		rep(j,3){
			if(wh%2==1)ret[j]=-1;
			wh/=2;
		}
		vector<ll> hoge;
		for(int k=0;k<N;k++){
			hoge.pb(ret[0]*data[k][0]+ret[1]*data[k][1]+ret[2]*data[k][2]);
		}
		sort(hoge.begin(),hoge.end());
		reverse(hoge.begin(),hoge.end());
		ll sum=0;
		for(int k=0;k<M;k++){
			sum+=hoge[k];
		}
		ans=max(ans,sum);
	}
	cout<<ans<<endl;
	
}




















Measured memory_bytes: 384
#include "bits/stdc++.h"
#define int long long
#define endl '\n'
using namespace std;
 
typedef long long ll;
#define db(x) cerr << #x << ": " << x << '\n';
#define read(a) int a; cin >> a;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define readarr(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}

#define print(a) cout << a << endl;
#define printarr(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;} cout << endl;
#define all(v) v.begin(), v.end()
#define sz(v) (int)(v.size())
#define rz(v, n) v.resize((n) + 1);
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define vvi vector <vi>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll N = 2e5 + 1;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	readb(n, k);
	set <int> s;
	FOR (i, 1, k)
	{
	    read(x);
	    FOR (j, 1, x)
	    {
	        read(y);
	        s.insert(y);
	    }
	}
	
	cout << n - sz(s);
	
}















Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define SZ(x) ((int)(x).size())
int gcd(int a,int b){return b?gcd(b,a%b):a;}
const double pi=acos(-1);


int main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
  
  rep (i, 300) {
  if (A<1) {
  cout << "No" << endl;
  return 0;
  }
  if (C<1) {
  cout << "Yes" << endl;
  return 0;
  }
    if (i%2==0) {
    C -= B;
    }
    if (i%2==1) {
    A -= D;
    }
  }
}


Measured memory_bytes: 3596
N, Q = map(int, input().split())
S = input()
l = [0 for i in range(Q)]
r = [0 for i in range(Q)]
t = [0 for i in range(N)]


for i in range(Q):
    l[i], r[i] = map(int,input().split())
    
for x in range(1,N):
    if S[x-1]=='A' and S[x]=='C':
        t[x] = t[x-1] + 1
    else:
        t[x] = t[x-1] + 0
        
for i in range(Q):
    print(t[r[i]-1]-t[l[i]-1])

Measured memory_bytes: 15768
#include<iostream>
#include<cstdio>
#include<vector>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
#define  endl '\n'
#define all(s) s.begin(),s.end()
#define lowbit(x) (x&-x)
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mem(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define pb push_back
#define PI acos(-1.0)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int mod=1e9+7;
const double eps=1e-8;
const int inf=0x3f3f3f3f;
const int N=2e5+10;
int main()
{
	int n,m,q,k;
	cin>>n>>m;
	vector<int>v1,v2;
	n=2*m+1;
	if(m&1){
		int l=1,r=m+1;
		while(l<r){
			v1.pb(l);
			v2.pb(r);
			l++,r--;
		}
		l=m+2,r=n;
		while(l<r){
			v1.pb(l);
			v2.pb(r);
			l++,r--;
		}
	}else{
		int l=1,r=m+1;
		while(l<r){
			v1.pb(l);
			v2.pb(r);
			l++,r--;
		}
		l=m+2,r=n;
		while(l<r){
			v1.pb(l);
			v2.pb(r);
			l++,r--;
		}		
	}
	for(int i=0;i<m;i++){
		cout<<v1[i]<<' '<<v2[i]<<endl;
	}
}


Measured memory_bytes: 3972
#include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
typedef pair<int,int> P;
int main(void)
{
	int i,n,flg;
	P pp[200000];
	long long sum;
	scanf("%d",&n);
	for(i=0;i<n;i++)	{
		scanf("%d %d",&pp[i].second,&pp[i].first);
	}
	sort(pp,pp+n);
	sum=0;
	flg=1;
	for(i=0;i<n;i++)	{
		sum+=pp[i].second;
		if(sum>pp[i].first)	{
			flg=0;
			break;
		}
	}
	if(flg==1)	printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 1664
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define ENDL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
/* libraries */

signed main() {
	int n,k;
	std::cin >> n >> k;
	std::vector<int> a(n);
	for(auto&&x:a) std::cin >> x;
	std::vector<int> dp(k+1,0); // 1: at least 1 coming from 0 , 0: all coming from 1
	rep(i,k) {
		rep(j,n) {
			if(a[j]+i<=k) {
				if(dp[i]==0) dp[i+a[j]]=1;
			}
		}
	}
	if(dp[k]) print("First");
	else print("Second");

	return 0;
}


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

using i64 = int64_t;

const i64 MOD = 1e9+7;

const i64 INF = 1e15+7;

signed main(){
	int n;
	cin >> n;
	double ans = 0;
	for(int i = 0; i < n; ++i){
		double x;
		string y;
		cin >> x >> y;
		if(y == "JPY"){
			ans += x;
		}else{
			ans += 380000.0 * x;
		}
	}
	printf("%.20lf\n", ans);
}


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

template<class T> inline void chmin(T& a, T b) {if (a > b) a = b;}
template<class T> inline void chmax(T& a, T b) {if (a < b) a = b;}

ll const mod = 1e9+7;

int main() {
  string S,T;
  cin >> S >> T;
  bool con = false;
  rep(i,S.size()-T.size()+1) {
    rep(j,T.size()) {
      if (S[i+j]==T[j]) {
        if (j==T.size()-1) con = true;
      }
      else break;
    }
  }
  bool ans = false;
  int mi;
  if (!con){  
    rep(i,S.size()-T.size()+1) {
      rep(j,T.size()) {
        if (S[i+j]=='?' || S[i+j]==T[j]) {
          if (j==T.size()-1) {
            ans = true;
            mi = i;
          }
        }
        else break;
      }
    }
    if (ans) {
      S = S.substr(0,mi) + T + S.substr(mi+T.size(),S.size()-mi-T.size());
    }
  }
  if (con || ans) {
    for (auto c:S) {
      char rc = c!='?'?c:'a';
      cout << rc;
    }
    cout << endl;
  }
  else cout << "UNRESTORABLE" << endl;
}

Measured memory_bytes: 256
n=int(input())
a=[int(s) for s in input().split()]
b=[0]*n
b[1]=abs(a[0]-a[1])
for i in range(2,n):
    b[i]=min(b[i-1]+abs(a[i]-a[i-1]),b[i-2]+abs(a[i]-a[i-2]))
print(b[n-1])  

Measured memory_bytes: 20416
import java.util.*;
import java.io.*;
public class Main{
    public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter ou = new PrintWriter(System.out);
		int n = Integer.parseInt(sc.next());
		int OO = 0 , OX = 0 , XO = 0;
		int yono = 0;
		for(int i = 0 ; i < n ; i++){
			String s = sc.next();
			if(s.charAt(0) == 'B' && s.charAt(s.length() - 1) == 'A') OO++;
			else if(s.charAt(0) == 'B') OX++;
			else if(s.charAt(s.length() - 1) == 'A') XO++;
			for(int ii = 0 ; ii < s.length() - 1 ; ii++){
				if(s.charAt(ii) == 'A' && s.charAt(ii + 1) == 'B') yono++;
			}
		}
		yono += OO + Math.min(OX , XO);
		if(OX == XO && OX == 0 && OO != 0) yono--;
		ou.print(yono + "\n");
		ou.flush();
    }
}

Measured memory_bytes: 43856