akhauriyash/Code-Regression huggingface dataset:
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
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);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

const int mod = 1000000007;
//const int mod = 998244353;

struct mint {
	int64_t x;
	mint(int64_t x=0):x((x%mod+mod)%mod){}
	mint operator-() const { return mint(-x);}
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod-a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
	mint operator+(const mint a) const { return mint(*this) += a;}
	mint operator-(const mint a) const { return mint(*this) -= a;}
	mint operator*(const mint a) const { return mint(*this) *= a;}
	mint pow(int64_t t) const {
		if (!t) return 1;
		mint a = pow(t>>1);
		a *= a;
		if (t&1) a *= *this;
		return a;
	}

	//for prime mod
	mint inv() const { return pow(mod-2);}
	mint& operator/=(const mint a) { return *this *= a.inv();}
	mint operator/(const mint a) {return mint(*this) /= a;}
};

istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, x;
	cin >> n >> x;
	vi a(n);
	rep(i, n) cin >> a[i];

	sort(all(a));
	if(x < a[0]) {
		mint ans(x);
		rep(i, n) ans *= i+1;
		cout << ans << endl;
		return 0;
	}
	vector<mint> dp((x+1)>>1);
	vector<mint> mm(n+1, 1);
	rep(i, n) mm[i+1] = mm[i]*(i+1);
	rep(i, (x+1)>>1) {
		auto itr = upper_bound(all(a), i);
		int num = itr-a.begin();
		if(!num) {
			dp[i] = i;
		} else {
			for(int j = num-1; j >= 0; j--) {
				itr = upper_bound(all(a), i%a[j]);
				mint mul = mm[num-1]/mm[itr-a.begin()];
				dp[i] += mul * dp[i%a[j]];
			}
		}
	}
	mint ans;
	auto itr = upper_bound(all(a), x);
	int num = itr-a.begin();
	for(int j = num-1; j >= 0; j--) {
		itr = upper_bound(all(a), x%a[j]);
		mint mul = mm[num-1]/mm[itr-a.begin()];
		ans += mul * dp[x%a[j]];
	}
	cout << ans*mm[n]/mm[num] << endl;
}

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

using ll = long long;
using P = pair<ll,ll>;
constexpr int INF = 1<<30;

int main(){
    ll N, D, A;
    cin >> N >> D >> A;
    vector<P> v;
    for(int i=0;i<N;i++){
        ll x, h;
        cin >> x >> h;
        v.emplace_back(P(x,h));
    }
    sort(v.begin(),v.end());
    queue<P> que;
    ll sum = 0, cnt = 0;
    for(int i=0;i<N;i++){
        ll x = v[i].first, h = v[i].second;
        while(!que.empty()){
            P p = que.front();
            if(abs(p.first-x) > D){
                sum -= p.second;
                que.pop();
            }
            else break;
        }
        h -= sum;
        if(h > 0){
            ll c = (h-1)/A+1;
            cnt += c;
            sum += c*A;
            que.push(P(x+D, c*A));
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 6256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;
const int MOD = 998244353;

int main() {
	cin.tie(0)->sync_with_stdio(false);

	int n, k; cin >> n >> k;
	vector<int> l(k), r(k);
	REP(i, k) cin >> l[i] >> r[i];
	vector<int> dp(n + 1, 0);
	dp[0] = 1;
	dp[1] = -1;
	REP(i, n) { // 配る DP
		dp[i+1] += dp[i];
		dp[i+1] %= MOD;
		REP(j, k) {
			if (i + l[j] < n) {
				dp[i+l[j]] += dp[i];
				dp[i+l[j]] %= MOD;
			}
			if (i + r[j] + 1 < n) {
				dp[i+r[j]+1] -= dp[i];
				dp[i+r[j]+1] %= MOD;
				dp[i+r[j]+1] += MOD;
				dp[i+r[j]+1] %= MOD;
			}
		}
	}
	cout << dp[n-1] << '\n';
	return 0;
}


Measured memory_bytes: 3912
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <utility>
#define ll long long int
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()
#define NMAX 100005
using namespace std;

ll ranges[NMAX] = {};
vector<pair<int,ll>> graph[NMAX]; //first is ngh. second is ranges.
bool used[NMAX] = {};


void dfs(int v,ll range){
	ranges[v] = range;
	used[v] = true;
	rep(i,0,graph[v].size()){
		if(!used[graph[v][i].first]){
			dfs(graph[v][i].first,range+graph[v][i].second);
		}
	}
}

int main(){
	int N;
	cin >> N;
	int tmp1,tmp2,tmp3;
	rep(i,0,N-1){
		cin >> tmp1 >> tmp2 >> tmp3;
		graph[tmp1].push_back(make_pair(tmp2,tmp3));
		graph[tmp2].push_back(make_pair(tmp1,tmp3));
	}
	int Q,K;
	int x,y;
	cin >> Q >> K;
	dfs(K,0);
	rep(i,0,Q){
		cin >> x >> y;
		cout << ranges[x] + ranges[y] << endl;
	}
}


Measured memory_bytes: 14336
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<ll, int> plli;
typedef vector<pii> vpii;
typedef tree<pii, null_type, less<pii>, rb_tree_tag,
    tree_order_statistics_node_update> ost;

const int N=110000;
const int C=3;
int n, x[C], w[N], a[N][C];
set<pii, greater<pii>> t[C][C];
ll ans;

void insert(int w, int i) {
    int j;
    for(j=0; j<C; j++) if(i!=j)
        t[i][j].insert(pii(a[w][j]-a[w][i], w));
}

void erase(int w, int i) {
    int j;
    for(j=0; j<C; j++) if(i!=j)
        t[i][j].erase(pii(a[w][j]-a[w][i], w));
}

int cycle(int i, int j, int k) {
    int moved=0;
    auto zij=*t[i][j].begin();
    auto zjk=*t[j][k].begin();
    auto zki=*t[k][i].begin();
    if((ll)zij.fs+(ll)zjk.fs+(ll)zki.fs>0) {
        erase(zij.sc, i);
        erase(zjk.sc, j);
        erase(zki.sc, k);
        insert(zij.sc, j);
        insert(zjk.sc, k);
        insert(zki.sc, i);
        ans+=(ll)zij.fs+(ll)zjk.fs+(ll)zki.fs;
        moved=1;
    }
    return moved;
}


int main() {
    int i, j, k, moved;
    for(i=0; i<C; i++) {
        scanf("%d", &x[i]);
        n+=x[i];
    }
    for(i=0; i<n; i++) for(j=0; j<C; j++)
        scanf("%d", &a[i][j]);
    for(k=i=0; i<C; i++) for(j=0; j<x[i]; j++) {
        ans+=a[k][i];
        insert(k++, i);
    }
    do {
        moved=0;
        for(i=0; i<C; i++) for(j=0; j<C; j++) {
            if(i==j) continue;
            auto zi=*t[i][j].begin();
            auto zj=*t[j][i].begin();
            if(zi.fs+zj.fs>0) {
                erase(zi.sc, i);
                erase(zj.sc, j);
                insert(zi.sc, j);
                insert(zj.sc, i);
                ans+=zi.fs+zj.fs;
                moved=1;
            }
        }
        moved|=cycle(0, 1, 2);
        moved|=cycle(0, 2, 1);
    } while(moved);
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 10880
#include<bits/stdc++.h>
#define endl '\n'
#define pb push_back
#define fr first
#define sc second
#define ll long long int
#define bit(idx) idx&(-idx)
#define bin(x, a) bitset<a>(x)
#define all(A) A.begin(), A.end()
#define debug(x) cout << #x << " = " << x << endl;
using namespace std;



int main(){
	ios_base::sync_with_stdio(NULL); cin.tie(); cout.tie();
	int n, k; cin >> n >> k;
	for(int i = 0; i < k; i ++){
		int x; cin >> x;
		n -= x;
	}
	if(n >= 0) cout << n << endl;
	else cout << -1 << endl;
}
/**

*/

Measured memory_bytes: 3652
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Queue;

public class Main {

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		while (true) {
			int n = Integer.parseInt(br.readLine());

			if (n == 0)
				break;

			boolean matrix[][] = new boolean[21][21];

			for (int i = 0; i < n; i++) {
				String str[] = br.readLine().split(" ");
				int x = Integer.parseInt(str[0]);
				int y = Integer.parseInt(str[1]);
				matrix[y][x] = true;
			}

			int x = 10;
			int y = 10;
			int ans = 0;

			int m = Integer.parseInt(br.readLine());

			for (int i = 0; i < m; i++) {
				String str[] = br.readLine().split(" ");
				int dist = Integer.parseInt(str[1]);
				int dx = 0;
				int dy = 0;
				if (str[0].equals("N")) {
					dy = 1;
				} else if (str[0].equals("S")) {
					dy = -1;
				} else if (str[0].equals("E")) {
					dx = 1;
				} else if (str[0].equals("W")) {
					dx = -1;
				}
				for (int j = 0; j < dist; j++) {
					x += dx;
					y += dy;
					if (matrix[y][x])
						ans++;
					matrix[y][x] = false;
				}
			}
			if (ans == n)
				System.out.println("Yes");
			else
				System.out.println("No");
		}
	}
}


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

int main() {
    int n, d;
    cin>>n>>d;
    vector<vector<int>> x(n, vector<int>(d));
    for(int i=0;i<n;i++) {
        for(int j=0;j<d;j++) cin>>x.at(i).at(j);
    }
    
    int ans=0;
    for(int i=0;i<n-1;i++) {
        for(int j=i+1;j<n;j++) {
            float dist=0;
            for(int k=0;k<d;k++) {
                dist+=pow(x.at(i).at(k)-x.at(j).at(k), 2);
            }
            float e=sqrt(dist);
            if((int)e*(int)e==dist) ans++;
        }
    }

    cout<<ans<<endl;
}

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

#define REMNUM 1000000007

long long int dfs(int cur, int from, vector<vector<int>> &graph, long colors) {
  long long int remaincolors;
  if (from == -1)
    remaincolors = colors - 1;
  else
    remaincolors = colors - 2;

  if (colors < graph[cur].size()) {
    return 0;
  } else {
    long long int totals = 1;
    for (auto itr : graph[cur]) {
      if (itr == from)
        continue;
      totals *= remaincolors;
      totals %= REMNUM;
      remaincolors--;
    }

    for (auto itr : graph[cur]) {
      if (itr == from)
        continue;
      totals *= dfs(itr, cur, graph, colors);
      totals %= REMNUM;
    }

    return totals;
  }
}

int main(int argc, char **argv) {
  long N, K;
  cin >> N >> K;
  vector<vector<int>> graph(N);

  int a, b;
  for (int i = 0; i < N - 1; i++) {
    cin >> a >> b;
    a --;
    b --;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }

  long long int ans = (K * dfs(0, -1, graph, K)) % REMNUM;
  ans %= REMNUM;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 11520
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define ll long long

const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-8;
const ll DIV =1e9+7;
//const double PI = M_PI;
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}
#define chmax(a,b) a=max(a,b)

/*Coding Space*/
int main(){
  int a,b,c; cin >> a >> b >> c;
  vector<int> in;
  in.pb(a),in.pb(b),in.pb(c);
  sort(ALL(in));
  if((in[0] == in[1] && in[1] != in[2]) || (in[1] == in[2] && in[0] != in[1]))
      cout << "Yes" << endl;
  else
      cout << "No" << endl;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
using ll = long long;
int main()
{
    int A,B,M;
    cin >> A >> B >> M;
    int a[A],b[B],A_min = INT_MAX,B_min = INT_MAX;
    for(int i = 0;i < A;i++)
    {
        cin >> a[i];
        if(a[i] < A_min)
        {
            A_min = a[i];
        }
    }
    for(int i = 0;i < B;i++)
    {
        cin >> b[i];
        if(b[i] < B_min)
        {
            B_min = b[i];
        }
    }
    int ans = A_min + B_min;
    for(int i = 0;i < M;i++)
    {
        int x,y,c;
        cin >> x >> y >> c;
        if(a[x - 1] + b[y - 1] - c < ans)
        {
            ans = a[x - 1] + b[y - 1] - c;
        }
    }
    cout << ans << "\n";
    
    return 0;
}

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

vector<long long> v;

main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<3*n;i++)
	{
		long long a;
		scanf("%lld",&a);
		v.push_back(a);
	}
	long long ans=0;
	sort(v.begin(),v.end());
	for(int i=0;i<n;i++)
	{
		ans+=v[3*n-i*2-1-1];
		//printf("%d\n",3*n-i*2-1-1);
	}
	printf("%lld",ans);
}


Measured memory_bytes: 6512
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>
#include<ext/pb_ds/priority_queue.hpp>
using namespace std;

const int maxn = 1E5 + 10;
const int T = 4;
typedef long long LL;

int n,Q;
LL x,y,Sum[maxn*T],Cov[maxn*T];

LL getLL()
{
	char ch = getchar(); LL ret = 0;
	while (ch < '0' || '9' < ch) ch = getchar();
	while ('0' <= ch && ch <= '9')
		ret = ret * 10LL + 1LL * (ch - '0'),ch = getchar();
	return ret;
}

char s[20];
void Print(LL k)
{
	if (!k) {puts("0"); return;} int len = 0;
	while (k) s[++len] = k % 10LL,k /= 10LL;
	for (int i = len; i; i--) putchar(s[i] + '0'); puts("");
}

void pushdown(int o,int l,int r)
{
	if (!Cov[o]) return;
	Sum[o] = 1LL * (r - l + 1) * Cov[o];
	if (l == r) {Cov[o] = 0; return;}
	Cov[o<<1] = Cov[o<<1|1] = Cov[o]; Cov[o] = 0;
}

void Search(int o,int l,int r,int pos)
{
	pushdown(o,l,r);
	if (l == r) {x = Sum[o]; return;}
	int mid = l + r >> 1;
	if (pos <= mid) Search(o<<1,l,mid,pos);
	else Search(o<<1|1,mid+1,r,pos);
}

void Query(int o,int l,int r,int ql,int qr)
{
	pushdown(o,l,r);
	if (ql <= l && r <= qr)
	{
		if (l == ql) Search(o,l,r,ql);
		y += Sum[o]; return;
	}
	int mid = l + r >> 1;
	if (ql <= mid) Query(o<<1,l,mid,ql,qr);
	if (qr > mid) Query(o<<1|1,mid+1,r,ql,qr);
}

void Cover(int o,int l,int r,int ql,int qr,LL k)
{
	if (ql <= l && r <= qr)
	{
		Cov[o] = k; pushdown(o,l,r); return;
	}
	int mid = l + r >> 1; pushdown(o,l,r);
	if (ql <= mid) Cover(o<<1,l,mid,ql,qr,k); else pushdown(o<<1,l,mid);
	if (qr > mid) Cover(o<<1|1,mid+1,r,ql,qr,k); else pushdown(o<<1|1,mid+1,r);
	Sum[o] = Sum[o<<1] + Sum[o<<1|1];
}

void Print_All(int o,int l,int r)
{
	pushdown(o,l,r);
	if (l == r) {Print(Sum[o]); return;}
	int mid = l + r >> 1;
	Print_All(o<<1,l,mid); Print_All(o<<1|1,mid+1,r);
}

bool Judge(int now,int pos,LL tot)
{
	y = 0; Query(1,1,n,now,pos);
	LL sum = 1LL * (pos - now + 1) * x;
	return sum - y <= tot;
}

void Work(int now,int pos,LL &tot)
{
	y = 0; Query(1,1,n,now,pos);
	LL sum = 1LL * (pos - now + 1) * x;
	tot -= (sum - y); Cover(1,1,n,now,pos,x);
}

int main()
{
	#ifdef DMC
		freopen("DMC.txt","r",stdin);
	#endif
	
	n = getLL(); Q = getLL();
	while (Q--)
	{
		int pos = getLL();
		LL tot = getLL(); int l = 1,r = pos;
		while (r - l > 1)
		{
			int mid = l + r >> 1;
			if (Judge(mid,pos,tot)) r = mid;
			else l = mid;
		}
		int now = Judge(l,pos,tot) ? l : r;
		Work(now,pos,tot); if (!tot) continue;
		LL len = pos - now + 1; Search(1,1,n,now);
		if (tot >= len) Cover(1,1,n,now,pos,x + tot / len);
		if (tot % len != 0)
		{
			Search(1,1,n,now);
			Cover(1,1,n,now,now + (tot % len) - 1,x + 1LL);
		}
	}
	Print_All(1,1,n);
	return 0;
}

Measured memory_bytes: 7680
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;
const int MOD=1000000007;
const int nmax=101234;

int n,x,y;
ll m,dp[nmax];
vector<vector<int> > v2(nmax);

void dfs(int s,int f)
{
    dp[s]=1;
    for(int i=0; i<v2[s].size(); ++i)
        if(v2[s][i]!=f)
        {
            dfs(v2[s][i],s);
            dp[s]=dp[s]*(dp[v2[s][i]]+1)%m;
        }
}

void dfs2(int s,int f,ll now)
{
    ll pre[v2[s].size()];
    ll nxt[v2[s].size()];
    for(int i=(int)v2[s].size()-1; i>=0; --i)
    {
        if(v2[s][i]!=f) nxt[i]=dp[v2[s][i]]+1;
        else nxt[i]=now;
        if(i+1<v2[s].size()) nxt[i]=nxt[i]*nxt[i+1]%m;
    }
    ll ans=now;
    for(int i=0; i<v2[s].size(); ++i)
    {
        if(v2[s][i]!=f)
        {
            if(v2[s].size()!=1){
                pre[i]=dp[v2[s][i]]+1;
                if(i==0) ans=(nxt[i+1]+1)%m;
                else{
                    pre[i]=pre[i]*pre[i-1]%m;
                    if(i+1==v2[s].size()) ans=(pre[i-1]+1)%m;
                    else ans=(pre[i-1]*nxt[i+1]+1)%m;
                }
            }
            dp[v2[s][i]]=dp[v2[s][i]]*ans%m;
            dfs2(v2[s][i],s,ans);
        }
        else pre[i]=i?now*pre[i-1]%m:now;
    }
}

int main()
{
    scanf("%d %lld",&n,&m);
    for(int i=1; i<n; ++i)
    {
        scanf("%d %d",&x,&y);
        v2[x].pb(y);
        v2[y].pb(x);
    }
    dfs(1,0);
    dfs2(1,0,2);
    for(int i=1; i<=n; ++i)
        printf("%lld\n",dp[i]);
    return 0;
}


Measured memory_bytes: 20992
n = gets.to_i
d = gets.chomp.split.map(&:to_i)
m = gets.to_i
t = gets.chomp.split.map(&:to_i)

hs = Hash.new(0)
n.times do |i|
  hs[d[i]] += 1
end

res = true
m.times do |i|
  hs[t[i]] -= 1
  if hs[t[i]] < 0
    res = false
    break
  end
end

puts (res)? "YES" : "NO"

Measured memory_bytes: 54772
#include "bits/stdc++.h"
using namespace std;
#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define MOD 998244353
#define PI 3.1415926535
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<Pll> vPll;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<double>> vvd;
typedef vector<vector<Pi>> vvPi;
typedef priority_queue<int, vector<int>, greater<int>> pqli;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi>> pqlP;
string YN(bool y) { return (y?"YES":"NO"); }
string yn(bool y) { return (y?"Yes":"No"); }
string ON(bool y) { return (y?"OK":"NG"); }
int main(void)
{
	ll n, m, ans=-1e18;

	cin>>n>>m;

	vll x(n), y(n), z(n), sum(n);

	rep(i, n) cin>>x[i]>>y[i]>>z[i];

	vll flag(3);
	rep(i, 8){
		rep(j, 3) flag[j]=((i>>j)&1)?1:-1;
		
		rep(j, n) sum[j]=x[j]*flag[0]+y[j]*flag[1]+z[j]*flag[2];

		sort(all(sum)); reverse(all(sum));

		ll temp=0;
		rep(j, m) temp+=sum[j];
		
		if(ans<temp) ans=temp;
	}
	cout<<ans<<endl;
}


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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

vector<int> f(lli pos, const vector<lli>& v)
{
  const int i = lower_bound(v.begin(), v.end(), pos) - v.begin();
  vector<int> u;
  for (int j = max(0, i - 2); j <= min<int>(i + 2, v.size()) - 1; ++j) {
    u.push_back(j);
  }
  return u;
}

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int a, b, q;
  while (cin >> a >> b >> q) {
    vector<lli> s(a), t(b);
    cin >> s >> t;
    
    while (q--) {
      lli x;
      cin >> x;
      lli mn = 1LL << 62;

      for (int _ = 0; _ < 2; ++_) {
        vector<int> p = f(x, s);
        vector<int> q;
        each (i, p) {
          vector<int> r = f(s[i], t);
          q.insert(q.end(), r.begin(), r.end());
        }
        each (i, p) {
          each (j, q) {
            setmin(mn, abs(x - s[i]) + abs(s[i] - t[j]));
          }
        }
        swap(s, t);
      }
      cout << mn << endl;
    }
  }
  
  return 0;
}




Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
 ll N;
  cin>>N;
 ll total=0;
 vector<ll> W(N);
  for(ll i=0;i<N;i++) {
cin>>W[i];
    total+=W[i];
  }
  ll i=0;
  ll k=0;
  while(total>k) {
    k+=W[i];
    total-=W[i];
    i++;
  }
  i--;
  
  ll ans=min(k-total,total+W[i]-k+W[i]);
  cout<<ans<<endl;
}
  
  

  
  


Measured memory_bytes: 3584
// 解き直し.
// ABC 128解説.
// https://img.atcoder.jp/abc128/editorial.pdf
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
LL V[51];
typedef priority_queue<LL, vector<LL>, greater<LL>> PQ;

int main() {
    
    // 1. 入力情報取得.
    LL N, K;
    scanf("%lld %lld", &N, &K);
    for(int i = 1; i <= N; i++) scanf("%lld", V + i);
    
    // 2. 解説通り.
    // 操作A, B を 行って, K - (A + B)回 捨てる操作.
    LL ans = 0;
    int upper = min(N, K);
    PQ pq0;

    // 2-1. 操作A で 宝石取り出す.
    for(int a = 0; a <= upper; a++){
        if(a > 0) pq0.push(V[a]);
        PQ pq1 = pq0;
        // cout << "a=" << a << " pq1=" << pq1.size() << endl;

        // 2-2. 操作B で 宝石取り出す.
        for(int b = 0; b <= upper - a; b++){
            if(b > 0) pq1.push(V[N + 1 - b]);
            PQ pq2 = pq1;
            int ret = K - (a + b);
            // cout << "b=" << b << " pq2=" << pq2.size() << endl;

            // 2-3. なるべく小さな負の価値の宝石を, 操作C, D で 戻す.
            LL total = 0;
            while(!pq2.empty()){
                LL v = pq2.top();
                pq2.pop();
                if(v < 0 && ret > 0) ret--;      // なるべく小さな負の価値の宝石を戻す.
                else                 total += v; // 宝石を戻さない場合は, キューが無くなるまで, 宝石の価値を加算.
            }
            // 2-4. 最大値を更新.
            ans = max(ans, total);
        }
        
    }

    // 3. 出力 ～ 後処理.
    printf("%lld\n", ans);
    return 0;
    
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10 ** 6)
# MOD = 10 ** 9 + 7
INF = float("inf")


def main():
    n, m = map(int, input().split())
    l = [tuple(map(int, input().split())) for _ in range(n)]
    ans = -INF
    for bit in range(1 << 3):
        sign = [0] * 3
        for i in range(3):
            if bit >> i & 1:
                sign[i] = 1
        sign = [i if i else -1 for i in sign]
        total = []
        for x, y, z in l:
            total.append(sign[0] * x + sign[1] * y + sign[2] * z)
        total.sort(reverse=True)
        ans = max(ans, sum(total[:m]))
    print(ans)


if __name__ == '__main__':
    main()


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

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

  if(N==1&&M==1){
    cout << 1 << endl;
  }else if(N==1||M==1){
    cout << max(N-2,M-2) << endl;
  }else{
    cout << (long long)(N-2)*(M-2) << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<queue>
#define ll long long
#define maxn ((1<<10)+5)
inline ll read()
{
	ll x=0; char c=getchar(),f=1;
	for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1;
	for(;'0'<=c&&c<='9';c=getchar())x=x*10+c-'0';
	return x*f;
}
inline void write(ll x)
{
	static int buf[20],len; len=0;
	if(x<0)x=-x,putchar('-');
	for(;x;x/=10)buf[len++]=x%10;
	if(!len)putchar('0');
	else while(len)putchar(buf[--len]+'0');
}
inline void writeln(ll x){write(x); putchar('\n');}
inline void writesp(ll x){write(x); putchar(' ');}
int mp[maxn][maxn];
int n,m;
void solve(int n,int x,int y)
{
	if(n==1)mp[x][y]=1;
	else{
		solve(n-1,x,y);
		solve(n-1,x+(1<<n>>1),y);
		solve(n-1,x,y+(1<<n>>1));
		solve(n-1,x+(1<<n>>1),y+(1<<n>>1));
		mp[x+(1<<n>>1)-1][y+(1<<n>>1)-1]=1;
	}
}
int main()
{
	n=read(); m=read();
	solve(std::max(n,m),1,1);
	for(int i=1;i<1<<n;i++){
		for(int j=1;j<1<<m;j++)
			putchar(mp[i][j]+'0');
		putchar('\n');
	}
	return 0;
}

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

#define ll long long
#define ld long double
#define ull unsigned long long
#define endl "\n"
#define MohamedMotaz ios::sync_with_stdio(0); cin.tie(0); ios_base::sync_with_stdio(0);
#define f(a, b, c) for(int a = b; a < c; a++)
using namespace std;
const ll mod = 1e9 + 7;



//ll fact[1000001]; ll inv[1000001];
//ll primes[100007];
//ll arr[1000007];
//ll modPower(ll b, ll p) {
//	if (p == 0)
//		return 1;
//
//	ll halfpow = modPower(b, p / 2);
//	ll toReturn = (halfpow * halfpow) % mod;
//	if (p % 2)
//		toReturn = (toReturn * b) % mod;
//
//	return toReturn;
//}
//
//ll fastPower(ll b, ll p) {
//	if (p == 0)
//		return 1;
//	ll ans = fastPower(b, p / 2);
//	ans = (ans * ans);
//	if (p % 2 != 0)
//		ans = (ans * b);
//	return ans;
//}
//ll GcdRecursive(ll a, ll b) {
//	if (b == 0) return a;
//	return GcdRecursive(b, a % b);
//}
//ll modLCM(ll a, ll b) {
//	ll val = GcdRecursive(a, b);
//	ll tmp = ((a % mod) * (b % mod)) % mod;
//	ll finalVal = ((tmp % mod) * (arr[val] % mod)) % mod;
//	return finalVal;
//
//}
//ll LCM(ll a, ll b) {
//	return (a * b) / GcdRecursive(a, b);
//}
//void move1step(ll& a, ll& b, ll q) { // a and b by reference
//	ll c = a - q * b;
//	a = b;
//	b = c;
//}
//ll GcdIterative(ll a, ll b) {
//	while (b) move1step(a, b, a / b);
//	return a;
//}
//
//void pre(ll n) {
//
//	fact[0] = 1;
//	inv[0] = 1;
//
//	for (ll i = 1; i <= n; i++) {
//		fact[i] = (i * fact[i - 1]) % mod;
//		inv[i] = modPower(fact[i], mod - 2);
//		arr[i] = modPower(i, mod - 2);
//	}
//}
//
//ll npr(ll n, ll r) {
//	return ((fact[n] * inv[n - r]) % mod);
//}
//
//ll ncr(ll n, ll r) {
//	return ((((fact[n] * inv[n - r]) % mod) * inv[r]) % mod);
//}
//
//void sieve(ll val) {
//	memset(primes, 1, sizeof primes);
//	primes[0] = primes[1] = false;
//	for (int i = 2; i <= val; i++) {
//		if (primes[i]) {
//			for (int j = i * i; j <= val; j += i) {
//				primes[j] = 0;
//			}
//		}
//	}
//
//}


const ll N = 1e5 + 7;

ll x;
ll a[N] = {};
ll dp[N] = {};

int main()
{
    MohamedMotaz;
    
    cin >> x;

    f(i, 0, x) cin >> a[i];
    dp[0] = 0;
    dp[1] = abs(a[1] - a[0]);
    f(i, 2, x) dp[i] = min(dp[i - 1] + abs(a[i] - a[i - 1]), dp[i - 2] + abs(a[i] - a[i - 2]));
    cout << dp[x - 1];

   

}








Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    int n;
    cin >> n;
    vector<int> r(n);
    rep(i,n) cin >> r[i];
    int minv = r[0];
    int maxv = -1000000000;
    for (size_t i = 1; i < n; i++)
    {
        maxv = max(maxv, r[i]-minv);
        minv = min(minv,r[i]);
    }
    cout << maxv << endl;
    
    return 0;
}


Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> a(n);
	map<int,int> cnt;
	rep(i,n){
		cin >> a[i];
		++cnt[a[i]];
	}
	if(cnt[0] == n){
		cout << "Yes" << endl;
		return 0;
	}
	if(n % 3 !=0){
		cout << "No" << endl;
		return 0;
	}
	vector<int> all;
	for(auto &p:cnt){
		//cout << p.first << " " << p.second << endl;
		//p.second は p.first の数
		for(int i = 0;i< p.second /(n/3);i++){
			all.push_back(p.first);
		}
	}
	if(all.size() == 3 && (all[0]^all[1]^all[2]) == 0 ){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 4224
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    long K = sc.nextLong();
    
    System.out.println(K%2 == 0 ? A-B : B-A);
  }
}

Measured memory_bytes: 21716
#include <iostream>
#include <cmath>

using namespace std;

int main() {
	int a, b, c, d;
	c = d = 0;
	for (int i = 0; i < 4; i++) {
		cin >> a;
		c += a;
	}
	for (int i = 0; i < 4; i++) {
		cin >> a;
		d += a;
	}
	cout << max(c, d) << endl;
	return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 998244353
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
bool used[100005];
priority_queue<P1>que[2];
int n;
int L[100005],R[100005];
ll ans,ans2;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d%d",&L[i],&R[i]);
		que[0].push(mp(-R[i],mp(L[i],i)));
		que[1].push(mp(L[i],mp(R[i],i)));
	}
	//0 first
	int zan = n;
	int cur = 0;
	while(1){
		while(!que[0].empty() && used[que[0].top().sc.sc]) que[0].pop();
		used[que[0].top().sc.sc] = 1;
		zan--;
		int x = que[0].top().sc.fi,y = -(que[0].top().fi);
		if(cur<x){
			ans+=x-cur;
			cur=x;
		}
		else if(y<cur){
			ans+=cur-y;
			cur=y;
		}
		que[0].pop();
		if(!zan) break;
		while(!que[1].empty() && used[que[1].top().sc.sc]) que[1].pop();
		used[que[1].top().sc.sc] = 1;
		zan--;
		x = que[1].top().fi,y = que[1].top().sc.fi;
		if(cur<x){
			ans+=x-cur;
			cur=x;
		}
		else if(y<cur){
			ans+=cur-y;
			cur=y;
		}
		que[1].pop();
		if(!zan) break;
	}
	ans += abs(cur);
	while(que[0].size()) que[0].pop();
	while(que[1].size()) que[1].pop();
	
	for(int i=1;i<=n;i++){
		que[0].push(mp(-R[i],mp(L[i],i)));
		que[1].push(mp(L[i],mp(R[i],i)));
	}
	//1 first
	zan = n;
	cur = 0;
	memset(used,0,sizeof(used));
	while(1){
		while(!que[1].empty() && used[que[1].top().sc.sc]) que[1].pop();
		used[que[1].top().sc.sc] = 1;
		zan--;
		int x = que[1].top().fi,y = que[1].top().sc.fi;
		if(cur<x){
			ans2+=x-cur;
			cur=x;
		}
		else if(y<cur){
			ans2+=cur-y;
			cur=y;
		}
		que[1].pop();
		if(!zan) break;
		while(!que[0].empty() && used[que[0].top().sc.sc]) que[0].pop();
		used[que[0].top().sc.sc] = 1;
		zan--;
		x = que[0].top().sc.fi,y = -(que[0].top().fi);
		if(cur<x){
			ans2+=x-cur;
			cur=x;
		}
		else if(y<cur){
			ans2+=cur-y;
			cur=y;
		}
		que[0].pop();
		if(!zan) break;
	}
	ans2 += abs(cur);
	while(que[0].size()) que[0].pop();
	while(que[1].size()) que[1].pop();
	
	cout<<max(ans,ans2)<<endl;
}

Measured memory_bytes: 3884
from collections import deque


def lunlun():
    k = int(input())
    q = deque(list(range(1, 10)))

    while k > 0:
        k -= 1
        n = q.popleft()
        # print('====== popleft:', n)

        if n % 10 != 0:
            n0 = int(str(n) + str(n % 10 - 1))
            q.append(n0)
            # print('=== append:', n0)

        n1 = int(str(n) + str(n % 10))
        q.append(n1)
        # print('=== append:', n1)

        if n % 10 != 9:
            n2 = int(str(n) + str(n % 10 + 1))
            q.append(n2)
            # print('=== append:', n2)

    print(n)


##########
if __name__ == "__main__":
    lunlun()


Measured memory_bytes: 10840
x, y = map(int, input().split())
if x in (4, 6, 9, 11) and y in (4, 6, 9, 11):
    print("Yes")
elif x in (1, 3, 5, 7, 8, 10, 12) and y in (1, 3, 5, 7, 8, 10, 12):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
// +build ignore
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []byte {
	return []byte(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

func gcd(x, y int) int {
	if x%y != 0 {
		return gcd(y, x%y)
	}
	return y
}

func run(input io.Reader, output io.Writer) int {
	sc := NewScanner()
	X := sc.nextInt()
	A := sc.nextInt()
	B := sc.nextInt()

	if B <= A {
		fmt.Println("delicious")
	} else {
		if X >= B-A {
			fmt.Println("safe")
		} else {
			fmt.Println("dangerous")
		}
	}

	return 0
}

func main() {
	os.Exit(run(os.Stdin, os.Stdout))
}


Measured memory_bytes: 640
#include<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i;
  int a[1000],m,n,x,y;
  cin>>n>>m;
  for(i=0;i<m;i++){
    cin>>x>>y;
    if((n+1)/2.0==x){
      if((n+1)/2.0>y)
	a[i]=(n-x)%3+1;
      else
	a[i]=(x-1)%3+1;
    }else if((n+1)/2.0>x){
      if(x>y)
	a[i]=(y-1)%3+1;
      else if(n+1-x<y)
	a[i]=(n-y)%3+1;
      else
	a[i]=(x-1)%3+1;
    }else if((n+1)/2.0<x){
      if(n-x+1>y)
	a[i]=(y-1)%3+1;
      else if(x<y)
	a[i]=(n-y)%3+1;
      else
	a[i]=(n-x)%3+1;
    }
  }
  for(i=0;i<m;i++)
    cout<<a[i]<<endl;
  return 0;
}

Measured memory_bytes: 0
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		int a = Integer.parseInt(S.substring(0, 2));
		int b = Integer.parseInt(S.substring(2, 4));
		if(1 <= a && a <= 12 && 1 <= b && b <= 12) {
			System.out.println("AMBIGUOUS");
		} else if(1 <= a && a <= 12) {
			System.out.println("MMYY");
		} else if(1 <= b && b <= 12) {
			System.out.println("YYMM");
		} else {
			System.out.println("NA");
		}
	}
}


Measured memory_bytes: 22996
n,m = map(int,input().split())
ps = []
ans = [0,0]
wa = [0]*(n+1)
solved = [0]*(n+1)
for i in range(m):
  p,s = input().split()
  p = int(p)
  if not solved[p]:
    if s=="AC":
      ans[0]+=1
      ans[1]+=wa[p]
      solved[p]=1
    else:
      wa[p]+=1

print(ans[0],ans[1])

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

int main(){
	int A, B, C, X;
	cin >> A >> B >> C >> X;
	int res = 0;
	for(int a = 0; a <= A; a++){
		for(int b = 0; b <= B; b++){
			for(int c = 0; c <= C; c++){
				int total = a * 500 + b * 100 + c * 50;
				if(X == total) res++;
			}
		}
	}
	cout << res << endl;
}


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

using namespace std;

vector<map<int,int>> known;
vector<int> leak;

int main(){
	int n;
	while(cin>>n, n){
		//M
		for(int i=0;i<n;i++){
			known.push_back(map<int,int>());
			int nknow;
			cin >> nknow;
			for(int j=0;j<nknow;j++){
				int tmp;
				cin >> tmp;
				known[i].insert(make_pair(tmp,j));
			}
		}
		//K
		int k;
		cin >> k;
		leak = vector<int>(k);
		for(int ik=0;ik<k;ik++){
			int tmp;
			cin >> tmp;
			leak[ik] = tmp;
		}

		//??¢?´¢
		int flag = 1;
		int targ = -2;
		for(int i=0;i<n;i++){
			for(int num: leak){
				auto it = known[i].find(num);
				if(it == known[i].end()){
					flag = 0;
					break;
				}else{
					//cout << it->second << endl;
				}
			}
			if(targ == -2 && flag == 1){
				targ = i;
			}
			else if(targ != -2 && flag == 1){
				targ = -1;
				break;
			}
			flag = 1;
		}
		if(targ == -1) targ = -2;
		cout << targ+1 << endl;
		known.clear();
		leak.clear();
	}

	return 0;
}

Measured memory_bytes: 3380
/* Author rumoisen */
/* date 2018/10/08 */

#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <numeric>
#include <iostream>

using namespace std;
 
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define INF (ll)1e18
#define MOD (ll)1e9 + 7
#define pb push_back

void no(){cout<<"No"<<endl;exit(0);}
void yes(){cout<<"Yes"<<endl;exit(0);}

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;
using namespace std;

int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int m=max(a,c),l=min(b,d);
    if(l-m<=0) cout<<0<<endl;
    else cout<<l-m<<endl;
    return 0;
}

Measured memory_bytes: 256
var n,k,i,aa:longint;
min,count:int64;
a:array[0..100010]of longint;
function m(x,y:int64):int64;
begin 
	if x<y then exit(x)
		else exit(y);
end;
begin 
	readln(n,k);
	aa:=0;
	min:=maxlongint;
	for i:=1 to n do 
	begin
		read(a[i]);
		if a[i]<=0 then 
		begin 
			a[i]:=-a[i];aa:=i;
		end;
	end;
	if aa>=k then min:=m(min,a[aa-k+1]);
	if n-aa>=k then min:=m(min,a[aa+k]);
	for i:=0 to m(n-aa,k) do 
		if (aa>=k-i) then
		begin 
			if a[aa-k+i+1]>a[aa+i] then count:=a[aa-k+i+1]+2*a[aa+i]
				else count:=2*a[aa-k+i+1]+a[aa+i];
			min:=m(min,count);
		end;
	write(min);
end.

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define rep(i, l, r) for(int i = (l), i##end = (r);i <= i##end;++i)
using std::cin; using std::cout;
const int maxn = 2000200;
typedef long long ll;
const int mod = 1e9 + 7;
inline ll pow(ll a,int b,int ans = 1) {
	for(;b;b >>= 1,a = a * a % mod) if(b & 1)
		ans = ans * a % mod;
	return ans;
}
inline ll inverse(int x){ return pow(x, mod - 2); }
#define y0 wwj
#define y1 ytx
int x0, y0, x1, y1, x2, y2, x3, y3, x4, y4, x5, y5;
int fac[maxn], ifac[maxn], inv[maxn];
inline int get(int x0,int y0) {
	return (ll) fac[x0 + y0] * ifac[x0] % mod * ifac[y0] % mod;
}
inline int go(int x0,int y0,int x1,int y1) {
	return unsigned(get(x1 + 1, y1 + 1) - get(x1 + 1, y0) - get(x0, y1 + 1) + get(x0, y0) + mod + mod) % mod;
}
inline int calc(int x,int y,int dx0, int dy0, int dx1, int dy1) {
	return (ll) go(x4 - x - dx1, y4 - y - dy1, x5 - x - dx1, y5 - y - dy1) * go(x - x1 - dx0, y - y1 - dy0, x - x0 - dx0, y - y0 - dy0) % mod;
}
int main() {
	std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	fac[0] = ifac[0] = fac[1] = ifac[1] = inv[1] = 1;
	for(int i = 2;i < maxn;++i) {
		inv[i] = ll(mod - mod / i) * inv[mod % i] % mod;
		fac[i] = (ll) fac[i - 1] * i % mod;
		ifac[i] = (ll) ifac[i - 1] * inv[i] % mod;
	}
	cin >> x0 >> x1 >> x2 >> x3 >> x4 >> x5;
	cin >> y0 >> y1 >> y2 >> y3 >> y4 >> y5;
	int ans = 0;
	for(int i = x2;i <= x3;++i) {
		ans = (ans + (ll) calc(i, y2, 0, 1, 0, 0) * (mod - i - y2 + 1)) % mod;
		ans = (ans + (ll) calc(i, y3, 0, 0, 0, 1) * (i + y3)) % mod;
	}
	for(int i = y2;i <= y3;++i) {
		ans = (ans + (ll) calc(x2, i, 1, 0, 0, 0) * (mod - x2 - i + 1)) % mod;
		ans = (ans + (ll) calc(x3, i, 0, 0, 1, 0) * (x3 + i)) % mod;
	}
	cout << ans << '\n';
}


Measured memory_bytes: 23680
import java.util.Scanner;
import java.util.Arrays;
import java.util.List;

public class Main {
	public static void main(String[] args) {
	    Scanner sc = new Scanner(System.in);
	    String input = sc.nextLine();
		String ichi = input.substring(input.length() - 1);
		String result = "";
		switch (ichi) {
			case "3":
				result = "bon";
				break;
			case "0":
			case "1":
			case "6":
			case "8":
				result = "pon";
				break;
			default:
				result = "hon";
		}
	    System.out.println(result);
	}
}


Measured memory_bytes: 35812
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int h = sc.nextInt();
    int w = sc.nextInt();
    char[][] path = new char[h][w];
    int[][] cnt = new int[h][w];
    int[] dx = {1,0,-1,0};
    int[] dy = {0,1,0,-1};
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++)cnt[i][j]=-1;
      path[i]=sc.next().toCharArray();
    }
    int res = 0;
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++)if(path[i][j]=='#')res++;
    cnt[0][0]=1;
    Queue<pair> que = new ArrayDeque<pair>();
    que.add(new pair(0,0));
    while(!que.isEmpty()){
      pair p = que.poll();
      if(p.x==h-1&&p.y==w-1)break;
      for(int i=0;i<4;i++){
        int cx = p.x+dx[i];
        int cy = p.y+dy[i];
        if(cx>=0&&cx<=h-1&&cy>=0&&cy<=w-1&&path[cx][cy]=='.'&&cnt[cx][cy]==-1){
          cnt[cx][cy]=cnt[p.x][p.y]+1;
          que.add(new pair(cx,cy));
        }
      }
    }
    if(cnt[h-1][w-1]!=-1)System.out.println(h*w-cnt[h-1][w-1]-res);
    else System.out.println(-1);
  }
  public static class pair{
    int x;
    int y;
    pair(int x,int y){
      this.x = x;
      this.y = y;
    }
  }
}

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

//--MAIN-----------------------------------
void Main() {
    char c; cin>>c;
    cout<< ++c <<"\n";
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=1;i<=(n);i++)
using namespace std;
typedef long long ll;
int n;
int main(){
  cin >> n;
  rep(i,50000){
    if(floor(i*1.08)==n){
      cout << i << endl;
      return 0;
    }
  }
  cout << ":(" <<endl;
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC091A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, c;
            var word = Console.ReadLine().Split(' ');

            a = int.Parse(word[0]);
            b = int.Parse(word[1]);
            c = int.Parse(word[2]);

            if (c <= a + b)
                Console.WriteLine("Yes");
            else
                Console.WriteLine("No");

            Console.ReadKey();
         }
    }
}

Measured memory_bytes: 11092
N,M=map(int,input().split())
l=sorted(list(tuple(map(int,input().split()))for i in range(N)),key=lambda x:x[0])
c=0
ans=0
for v,k in l:
    ans+=min(k,M-c)*v
    c+=min(k,M-c)
    if c==M:
        print(ans);exit()


Measured memory_bytes: 87664
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, n) for(int i = 1; i <= (int)(n); i++)
const long long INF = 1LL << 60;
const double PI=3.14159265358979323846;
int main() 
{
    int m1,d1,m2,d2;
    cin >> m1 >> d1 >> m2 >> d2;

    if(m1 != m2){
        cout << 1 <<endl;
    }
    else
        cout << 0 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i,m,n) for(ll i = (m); i < (n); i++)
#define all(v) v.begin(), v.end()
#define print(x) cout << (x) << endl
//宣言
int N,A;
vector<vector<int>> buka;

void solve(){
    for(int i=1; i<=N;i++){
        cout << buka[i].size() << endl;
    }
}

int main() {
    cin >> N;
    buka = vector<vector<int>>(N+1,vector<int>());

    for(int i=2; i<=N;i++){
        cin >> A;
        buka[A].push_back(i);
    }

    solve();
    return 0;
}


Measured memory_bytes: 13964
#include <iostream>
#include <string>
#include <cctype>
using namespace std ;
int main(){
	int n , i , s ;
	string str ;
	while( 1 ){
		cin >> str ;
		int num = 0 ;
		if( str == "0" ) break ;
		for( i=0 ; i<str.size() ; i++ ){
			n = str[i] - '0' ;
			num += n ;
		}
		cout << num << endl ;
	}
}

Measured memory_bytes: 1188
#include<iostream>
#include<vector>
#include<math.h>
#include<algorithm>
using namespace std;

int main() {
	int a,b;
	int x = 0;
	cin >> a >> b;
	if (a >= 2 && a <= 100 && b >= 2 && b <= 100) {
		x = a*b - (a * 1 + b * 1 - 1 * 1);
	}
	cout << x << endl;
	getchar();
	getchar();
}

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

int main()
{
		string s;
		cin>>s;
		
		long long ans=0;
		for(int i=0;i<s.size();i++)
		{
			ans+=(s[i]-'0');
		}
		if(ans%9==0)
		cout<<"Yes";
		else
		cout<<"No";
}


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

const ll INF = 1001001001;

const double PI=3.141592653;

const ll sosu = 1000000007;//大きい素数

//提出のときに言語がc＋＋似合っていることを確認する

ll f(ll x){
  if(x==1) return 1;
  return 2*f(x/2)+1;
}
int main(){
  int n,m;
  cin>>n>>m;
  int a=1;
  for(int i=0;i<m;i++){
    a=a*2;
  }
 cout<<a*(100*(n-m)+1900*m)<<endl;
 return 0;
 
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int R,G,B,n;
    
    cin >> R >> G >> B >> n;
    
    int res = 0;
    
    for(int r = 0; r <= 3000; r++){
        for(int g = 0; g <= 3000; g++){
            int b = (n-(r*R+g*G))/B;
            
            if(b >= 0){
                if(r*R+g*G+b*B==n) res++;
            }
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll a,b,h;
    cin >>a>>b>>h;
    
    cout << (a+b)*h/2 << endl;


    return 0;
    

}

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

int solve(int query,int currentIndex,int *list,int length){
  if ( currentIndex == length )
    return 0;
  if ( query - list[currentIndex] == 0 )
    return 1;
  else if ( query - list[currentIndex] > 0 )
    return solve(query-list[currentIndex],currentIndex+1,list,length)
      || solve(query,currentIndex+1,list,length);
  return solve(query,currentIndex+1,list,length);
}

int main(){
  int n, q, i, currentQuery;
  scanf(" %d",&n);
  int *toSum = (int *) malloc(sizeof(int[n]));
  for ( i = 0; i < n; i++ )
    scanf(" %d",toSum+i);
  scanf(" %d",&q);
  for ( i = 0; i < q; i++ ){
    scanf(" %d",&currentQuery);
    printf("%s\n",solve(currentQuery,0,toSum,n) ? "yes" : "no");
  }
  return 0;
}



Measured memory_bytes: 2076