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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MOD 1000000007
#define INF 100100100

typedef long long ll;
typedef pair<ll, ll> p;


int main(){
  int n, m;
  cin >> n >> m;
  vector<p> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i].first >> v[i].second;
  }

  ll res = 0;
  sort(all(v));

  for (int i = 0; i < n; i++) {
    ll val = v[i].first;
    ll num = v[i].second;
    if(num < m){
      res += val * num;
      m -= num;
    }else{
      res += m * val;
      break;
    }
  }

  cout << res << endl;

}


Measured memory_bytes: 1920
# include<iostream>
# include<vector>
# include<time.h>
# include<random>
using namespace std;
using vector1 = vector<int>;
using vector2 = vector<vector1>;
int last(int d, int j, vector1 t){ //d日目から数えてタイプjのコンテストが最後に開催された日を計算
  for(int i=d; i>=1; i--){
    if(t[i] == j) return i;
  }
  return 0;
}
int penalty(vector1 c, int d, vector1 t){ //ペナルティの合計を計算
  int m = 0;
  for(int i=1; i<=26; i++){
    m += c[i] * (d - last(d, i, t));
  }
  return m;
}
int calc_score(int d, int j, int c, vector1 t){ //開催されるコンテストが変更された場合のスコア差を算出
  int s = 1;
  if(d > 1) s = d - last(d-1, j, t);

  int r = s * c; //1日分のスコア差
  int sum = 0;  //スコア差の合計
  int i = d;
  do{
    sum += r;
    i++;
    if((int)t.size() < i) break;
  }while(t[i] != j);
  return sum;
}
void swap_(int d1, int d2, vector1& t){
  int tmp = t[d1]; t[d1] = t[d2]; t[d2] = tmp;
  return;
}
int main(){
  clock_t start = clock();
  int D; cin >> D; //日数d
  vector1 c(26+1, 0); for(int i=1; i<=26; i++) cin >> c[i]; //ペナルティc
  vector2 s(D+1, vector1(26+1)); //あるコンテストが開催された場合の満足度s
  for(int i=1; i<=D; i++){
    for(int j=1; j<=26; j++){
      cin >> s[i][j];
    }
  }
  vector1 t(D+1, 0); for(int i=1; i<=D; i++) t[i] = (i % 26) + 1;
/*  vector1 v(D+1, 0); //スコアv
  for(int i=1; i<=D; i++){
    v[i] = s[i][t[i]];
    v[i] -= penalty(c, i, t);
  }*/
  int score = 0;
  for(int i=1; i<=D; i++){
    score += s[i][t[i]];
    score -= penalty(c, i, t);
  }
  clock_t end = clock();
//  cout << score <<"\n";
  random_device random_a;
  auto num = random_a();
  mt19937 random_b;
  //num = 3180901575;
  random_b.seed(num);
//  cout <<"num: "<< num <<"\n";

  while((double)(end - start) / CLOCKS_PER_SEC < 1.9){
    int r = (int)random_b();
    if(r > 0){
      int p = ((int)random_b() * random_b() % 26) + 1;
      int d = ((int)random_b() * random_b() % D) + 1;
      int old = t[d];
      t[d] = p;
      int up = calc_score(d, p, c[p], t); //増えるスコア
      int down = calc_score(d, old, c[old], t); //減るスコア
      int l = up - down + s[d][p] - s[d][old];
      if(l > 0){
        score += l;
      }else{
        t[d] = old;
      }
    }else{
      int d1 = ((int)random_b() * random_b() % D) + 1;
      int d2 = ((int)random_b() * random_b() % D) + 1;
      int l_old_d1 = calc_score(d1, t[d1], c[t[d1]], t);
      int l_old_d2 = calc_score(d2, t[d2], c[t[d2]], t);
      //cout << t[d1] <<"  "<< t[d2] <<"\n";
      swap_(d1, d2, t);
      //cout << t[d1] <<"  "<<t[d2] <<"\n";
     // break;
      int l_d1 = calc_score(d1, t[d1], c[t[d1]], t);
      int l_d2 = calc_score(d2, t[d2], c[t[d2]], t);
      int l = l_d1 + l_d2 - l_old_d1 - l_old_d2 + s[d1][t[d1]] - s[d1][t[d2]] + s[d2][t[d2]] - s[d2][t[d1]];
      if(l >0){
        score += l;
      }else{
        swap_(d1, d2, t);
      }
    }
    end = clock();
  }
  for(int i=1; i<=D; i++){
    cout << t[i] <<"\n";
  }
  /*cout << score <<"\n";
  int score2=0;
  for(int i=1; i<=D; i++){
    score2 += s[i][t[i]];
    score2 -= penalty(c, i, t);
  }
  cout <<score2 <<"\n";*/
  return 0;
}


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

using namespace std;
typedef long long ll;

int main(void) {
  int n;
  cin >> n;

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

  ll dp[110][30] = {};
  dp[0][a[0]] = 1;
  for (int i = 0; i < b.size(); i++) {
    for (int j = 0; j <= 20; j++) {
      if (j - b[i] >= 0) {
        dp[i + 1][j] += dp[i][j - b[i]];
      }
      if (j + b[i] <= 20) {
        dp[i + 1][j] += dp[i][j + b[i]];
      }
    }
  }

  cout << dp[b.size()][a[n - 1]] << endl;

  return 0;
}


Measured memory_bytes: 3120
#include <iostream>

using namespace std;

int main() {
    char c; cin >> c;
    for (int i = 0; i < 26; i++) {
        if (c  == 'A' + i) {
            cout << "A" << endl;
            return 0;
        }
    }
    for (int i = 0; i < 26; i++) {
        if (c == 'a' + i) {
            cout << 'a' << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3620
package main

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

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func div8(n int) bool {
	if n%2 == 0 {
		return false
	}
	div := 2
	for i := 3; i < n; i++ {
		if n%i == 0 {
			div++
		}
	}
	if div == 8 {
		return true
	}
	return false
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	ans := 0
	for i := 105; i <= n; i++ {
		if div8(i) {
			ans++
		}
	}
	fmt.Println(ans)
}


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

int main(){
    int n, k, i, d, m, t;
    cin >> n >> k;
    int b[10] = {};
    for(i=0; i<k; i++){
        cin >> d;
        b[d]++;
    }
    m = n;
    while(true){
        t = m;
        while(t > 0){
            if(b[t%10] == 1) break;
            t /= 10;
        }
        if(t == 0) break;
        m++;
    }
    cout << m;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
s = str(input())

L = s[0:n]
R = s[n:]
R = list(R)
R.reverse()
R = ''.join(R)

DL = {}
for i in range(2**n):
    p = ''
    q = ''
    for j in range(n):
        if (i >> j)&1:
            p += L[j]
        else:
            q += L[j]
    if (p, q) in DL:
        DL[(p, q)] += 1
    else:
        DL[(p, q)] = 1

DR = {}
for i in range(2**n):
    p = ''
    q = ''
    for j in range(n):
        if (i >> j)&1:
            p += R[j]
        else:
            q += R[j]
    if (p, q) in DR:
        DR[(p, q)] += 1
    else:
        DR[(p, q)] = 1

#print(DL)
#print(DR)
ans = 0
for k, v in DL.items():
    if k in DR:
        ans += v*DR[k]
print(ans)


Measured memory_bytes: 240316
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
using namespace std;
typedef long long int ll;
using ull = unsigned long long;


mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}

int last[26];
int c[26];
int s[365][26];
int a[365];

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int d; cin >> d;
    for(int i=0;i<26;i++){
    	cin >> c[i];
    }
    for(int i=0;i<d;i++){
    	for(int j=0;j<26;j++){
    		cin >> s[i][j];
    	}
    }
    for(int i=0;i<d;i++){
    	a[i]=myRand(26)+1;
    }
    int res=0;
    for(int i=0;i<d;i++){
    	res+=s[i][a[i]-1];
    	last[a[i]-1]=i+1;
    	for(int j=0;j<26;j++){
    		res-=c[j]*(i+1-last[j]);
    	}
    }
    for(int i=0;i<1e5;i++){
    	int day,qq;
    	day=myRand(d)+1;
    	qq=myRand(26)+1;
    	int resres=res;
    	int qqq=a[day-1];
        last[qq-1]=last[qqq-1]=0;
        for(int i=0;i<d;i++){
            if(a[i]==qq){
                last[a[i]-1]=i+1;
            }
            if(a[i]==qqq){
                last[a[i]-1]=i+1;
            }
            resres+=c[qq-1]*(i+1-last[qq-1]);
            resres+=c[qqq-1]*(i+1-last[qqq-1]);
        }
        a[day-1]=qq;
        resres-=s[day-1][qqq-1];
        resres+=s[day-1][qq-1];
        last[qq-1]=last[qqq-1]=0;
        for(int i=0;i<d;i++){
            if(a[i]==qq){
                last[a[i]-1]=i+1;
            }
            if(a[i]==qqq){
                last[a[i]-1]=i+1;
            }
            resres-=c[qq-1]*(i+1-last[qq-1]);
            resres-=c[qqq-1]*(i+1-last[qqq-1]);
        }
        if(resres>=res){

        }
        else{
        	a[day-1]=qqq;
        }
    }
    for(int i=0;i<d;i++){
    	printf("%d\n",a[i]);
    }
}



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

int main(){
int n;
cin >> n;
int x=n;
for (int i=0;i<=n;i++){
  	int b=0;
	int a=i;
	while (a>0) {b+=a%6; a/=6; }
	a=n-i;
  	while (a>0){b+=a%9; a/=9;}
	if (b<=x) x=b;
}

cout << x << endl;
}


Measured memory_bytes: 256
'use strict'

const Main = (input) => {
  const tmp = input.trim().split(' ')
  const H = parseInt(tmp[0])
  const W = parseInt(tmp[1])

  let result = 0

  if (H === 1 || W === 1) {
    result = 1
  } else {
    result = Math.ceil(H * W / 2)
  }

  console.log(result)
  return result
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'))

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, X;
    cin >> N >> X;
    if (X == 1 || X == 2 * N - 1) {
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    if (N == 2) {
        for (int i = 1; i <= 3; i++) cout << i << endl;
        return 0;
    }
    map<int, bool> is_used;
    vector<int> need, head, tail;
    if (X == 2) {
        need.push_back(3);
        is_used[3] = true;
        need.push_back(2);
        is_used[2] = true;
        need.push_back(1);
        is_used[1] = true;
        need.push_back(4);
        is_used[4] = true;
    }
    else {
        need.push_back(X - 1);
        is_used[X - 1] = true;
        need.push_back(X);
        is_used[X] = true;
        need.push_back(X + 1);
        is_used[X + 1] = true;
        need.push_back(X - 2);
        is_used[X - 2] = true;
    }
    for (int i = 1; i <= 2 * N - 1; i++) {
        if (is_used[i]) continue;
        if (head.size() < N - 2) head.push_back(i);
        else tail.push_back(i);
    }
    for (int i = 0; i < head.size(); i++) cout << head[i] << endl;
    for (int i = 0; i < need.size(); i++) cout << need[i] << endl;
    for (int i = 0; i < tail.size(); i++) cout << tail[i] << endl;
    return 0;
}

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

using namespace std;

#define REP(i, N) for (int i = 0; i < (int)N; i++)
#define RREP(i, N) for (int i =(int)N-1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

typedef long long ll;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

int main(){
  double l;
  cin>>l;
  l=l/3.0;
  cout<<fixed<<setprecision(12)<<l*l*l<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(const T a, const T b){return a>=0 ? a/b : (a+1)/b-1;}
template<class T> T div_ceil(const T a, const T b){return a>=0 ? (a-1)/b+1 : a/b;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 100010;

vector<int> min_factor, prime;

void sieve(int n){
    min_factor.resize(n+1, 0);
    For(i, 2, n+1){
        if(min_factor[i] == 0){
            min_factor[i] = i;
            prime.push_back(i);
        }
        for(int x: prime){
            if(x*i > n || x > i) break;
            min_factor[x*i] = x;
        }
    }
}

int main(){
    int m, a, b;
    sieve(MAX);
    while(scanf("%d%d%d", &m, &a, &b) && m){
        int val = 0, p, q;
        rep(i, prime.size()){
            if(prime[i]*prime[i] > m) break;
            For(j, i, prime.size()){
                if(prime[i]*prime[j] > m || prime[i]*b < a*prime[j]) break;
                if(chmax(val, prime[i]*prime[j])) p = prime[i], q = prime[j];
            }
        }
        printf("%d %d\n", p, q);
    }
}


Measured memory_bytes: 3300
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>

static const int MOD = 1000000007;
using ll = int64_t;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }

template<class T> void chmin(T &a, const T &b){ a = (a < b ? a : b); }
template<class T> void chmax(T &a, const T &b){ a = (a > b ? a : b); }

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> v(n), sum(n+1);
    for (auto &&i : v) scanf("%d", &i);
    sort(v.begin(), v.end(), greater<>());
    for (int i = 0; i < n; ++i) {
        sum[i+1] = sum[i] + v[i];

    }
    vector<int> dp(n+1, INF<int>);
    dp[0] = 0;
    for (int i = 0; i < m; ++i) {
        int c, e;
        cin >> c >> e;
        for (int j = n; j >= 0; --j) {
            chmin(dp[min(j+c, n)], dp[j]+e);
        }
    }
    for (int k = n-1; k >= 0; --k) {
        chmin(dp[k], dp[k+1]);
    }
    int ans = 0;
    for (int i = 0; i <= n; ++i) {
        chmax(ans, sum[i]-dp[i]);
    }
    cout << ans << "\n";
    return 0;
}



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

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

    long long current = b - a;
    long long limit = a;

    if (current <= 0) {
        cout << "delicious" << endl;
    }
    else if (current <= x) {
        cout << "safe" << endl;
    }
    else {
        cout << "dangerous" << endl;
    }

    return 0;
}



Measured memory_bytes: 256
n = int(input())
from collections import defaultdict
S = [defaultdict(int) for i in range(n)]
bet = [chr(i) for i in range(97,97+26)]
for i in range(n):
    s = input()
    for j in s:
        S[i][j] += 1
ans = ""
for i in bet:
    tmp = float("inf")
    for j in range(n):
        tmp = min(tmp,S[j][i])
    ans += i*tmp
print(ans)



Measured memory_bytes: 39792
#include <bits/stdc++.h>
#define rep(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define repr(i, n, m) for (int i = (int)(n) - 1; i >= (int)(m); i--)
using namespace std;
using ll = int64_t;
const int MOD = 1000000007; // 10^9+7

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

int main() {
    int N, W;
    cin >> N >> W;
    vector<int> w(N + 1, 0), v(N + 1, 0);
    rep(i, 1, N + 1) cin >> w[i] >> v[i];

    ll MAX = W + 1;
    vector<vector<ll>> dp(N + 1, vector<ll>(100010, MAX));
    dp[0][0] = 0;
    rep(i, 1, N + 1)
    {
        rep(k, 0, 100001)
        {
            if (k < v[i]) dp[i][k] = dp[i - 1][k];
            else dp[i][k] = min(dp[i - 1][k - v[i]] + w[i], dp[i - 1][k]);
        }
    }

    int ans;
    repr(i, dp[0].size(), 1)
    {
        // **DESCENDING ORDER** from (n-1) to m (m is **INCLUDED**)
        if (dp[N][i] <= W)
        {
            ans = i;
            break;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 80256
#include <iostream>
#include <string>
#include <atcoder/all>
#include <vector>
using ll=long long;
using namespace std;
using namespace atcoder;

using mint=modint998244353;
const mint inv9=mint(1)/9;

struct S{
    mint x,w;
    S(mint x=0,mint w=1):x(x),w(w){}
};

S op(S a,S b){return S(a.x*b.w+b.x,a.w*b.w);}
S e(){return S();}
S mapping(int f,S a){
    if(f==0) return a;
    return S((a.w-1)*inv9*f,a.w);
}
int composition(int f,int g){
    if(f==0) return g;
    return f;
}
int id(){return 0;}

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

    lazy_segtree<S,op,e,int,mapping,composition,id> seg(N);
    for(int i=0;i<N;i++){
        seg.set(i,S(1,10));
    }
    int L,R,D;
    for(int i=0;i<Q;i++){
        cin>>L>>R>>D;
        L--;
        seg.apply(L,R,D);

        S ans=seg.prod(0,N);
        cout<<ans.x.val()<<endl;
    }

    return 0;
}

Measured memory_bytes: 9904
#include<bits/stdc++.h>
using namespace std;
long long n,a[100005],s=1,l;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		if(a[i]==0)
		{
			cout<<0;
			return 0;
		}
	} 
	for(int i=1;i<=n;i++)
	{
		s*=a[i];
		if(s<l||s>1000000000000000000)
		{
			cout<<"-1";
			return 0;
		}
		l=s;
	}
	cout<<s<<endl;
}

Measured memory_bytes: 4372
//----------BHAVIK DIWANI(PICT_COMP)---------------
#include<bits/stdc++.h>
#include<stdlib.h>
#include<stdio.h>
#define test ll t; cin>>t; while(t--)
#define FOR(p,n) for(ll i=p;i<(ll)n;i++)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define ll long long
#define int long long
#define ull unsigned long long
#define MAX 1000005
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define endl '\n'
#define vs vector<string>
#define mii map<int,int>
#define msi map<string,int>
#define vpii vector< pair<int, int > >
#define vpsi vector< pair< string ,int > >
#define forci(p,q) for(int i=p;i<q;i++)
ll gcd(ll a,ll b){ if(b==0) return a;    return gcd(b,a%b);}
ll lcm(ll a,ll b) { return (a/gcd(a,b)*b);}
ull power(ull a, ull b) {a %= mod;  ull res = 1;  while (b > 0) { if (b & 1) res = res * a % mod;  a = a * a % mod;  b >>= 1; }  return res%mod; }
ll modmul(ll x, ll y){return (x*y)%mod;}
ll modadd(ll x, ll y){return (x+y)%mod;}
ll modsub(ll x, ll y){return (x-y+mod)%mod;}
ll fact[1000007]={0};
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<100007;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[r],mod-2)))%mod; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
inline long long toint(const std::string &s) {std::stringstream ss; ss << s; long long x; ss >> x; return x;}
inline std::string tostring(long long number) {std::stringstream ss; ss << number; return ss.str();}
inline std::string tobin(long long x) {return std::bitset<63>(x).to_string();}
/*bool prime[MAX];
ull sieve(){memset(prime,true,sizeof(prime));for(ull p=2;p*p<MAX;p++){if(prime[p]==true){for(ull i=2*p;i<MAX;i+=p){prime[i]=false;}}}prime[0]=0;prime[1]=0;
}*/
/*int inv[1000001]={0};
void findinverse(){inv[1] = 1;for(int i = 2; i <=1e6 ; ++i)	inv[i] = (mod - (mod/i) * inv[mod%i] % mod) % mod;}
*/
using namespace std;
int solve()
{
	char x;
	cin>>x;
	if(x>=65 && x<=91)
		cout<<"A"<<endl;
	else
		cout<<"a"<<endl;
	return 0;
}
signed main()
{
	fastio;
//	test
		solve();
}

Measured memory_bytes: 3640
// 500, 100, 50
function main(input) {
  const input_array = input.split("\n");

  const a = parseInt(input_array[0], 10);
  const b = parseInt(input_array[1], 10);
  const c = parseInt(input_array[2], 10);
  const desired_sum = parseInt(input_array[3], 10);
  
  var answer = 0;
  for(i=0; i<=a; ++i){
    for(j=0; j<=b; ++j){
      for(k=0; k<=c; ++k){
        if (500 * i + 100 * j + 50 * k == desired_sum){
          answer+=1;
        }
      }
    }
  }
  
  console.log(answer);
}
 
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 7372
#include <iostream>
using namespace std;
int main()
{
    int z,s,k,sum;
    cin>>k>>s;
    for(int x=0;x<=k;x++)
        for(int y=0;y<=k;y++){
        	
            z=s-(x+y);
            if((z>=0)&&(z<=k))
                sum+=1;
        }
    cout<<sum;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 30;
 
int main() {
  //ll n,a,b,c,d,e;
  //cin>>n>>a>>b>>c>>d>>e;
  ll num[6];
  rep(i,6) cin >> num[i];
  ll n = num[0];
  sort(num, num+6);
  ll ans = n / num[0];
  if (n % num[0] != 0) ans++;
  cout << ans+4 << endl;
  return 0;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
main(){
  int N;
  cin>>N;
  vector<int>T(N);
  for(auto&x:T)cin>>x;
  auto T_sum=T;
  for(int i=1;i<T_sum.size();++i)T_sum[i]+=T_sum[i-1];
  int M;
  cin>>M;
  for(int i=1;i<=M;++i){
    int P,X;
    cin>>P>>X;
    --P;
    int sum=T_sum.back();
    sum-=T[P];
    sum+=X;
    cout<<sum<<endl;
  }
}


Measured memory_bytes: 256
def partition(A, p, r):
    x = A[r][2]
    i = p - 1

    for j in range(p, r):
        if A[j][2] <= x:
            i += 1
            A[i], A[j] = A[j], A[i]

    A[i + 1], A[r] = A[r], A[i + 1]

    return i + 1

def quickSort(A, p, r):
    if p < r:
        q = partition(A, p, r)
        quickSort(A, p, q - 1)
        quickSort(A, q + 1, r)


def IsStable(A):
    for index, a in enumerate(A):
        for i in range(index, len(A)):
            if (a[2] == A[i][2]) and (a[0] > A[i][0]):
                return "Not stable"

    return "Stable"



n = int(input())
A = []
for i in range(n):
    a, b = input().split()
    A.append([i, a, int(b)])

quickSort(A, 0, len(A) - 1)

print(IsStable(A))
[print("{} {}".format(A[i][1], A[i][2])) for i in range(len(A))]


Measured memory_bytes: 22400
N=int(input())
A=list(map(int,input().split()))

count=[0 for i in range(N)]
for i in A:
    count[i-1]+=1
    
def chose(n):
    return int(n*(n-1)/2)

total=0
for i in count:
    total+=chose(i)

for i in range(N):
    ans=total
    ans-=chose(count[A[i]-1])
    count[A[i]-1]-=1
    ans+=chose(count[A[i]-1])
    count[A[i]-1]+=1
    print(ans)

Measured memory_bytes: 33092
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i< (n); i++)
using ll = long long;
using P = pair<int, int>;
int main()
{
    ll x,k,d;
    cin >> x >> k >> d;
    ll ans;
    if ((ll)k < abs((ll)(x/d))) ans = abs(abs((ll)x) - abs((ll)d*k));
    else{
if(x>=0){
    if(abs(x) > d){
        if((ll)(x / d) %2 == 0){
            if(k % 2 == 0) ans = abs((ll) x%d);
            else ans = abs((ll) x%d - d);
        }
        else{
            if(k % 2 == 0) ans = abs((ll) x%d - d);
            else ans = abs((ll)x%d);
        }

    }
    if(abs(x) == d){
        if((ll) k % 2 == 0) ans = abs((ll)x);
        else ans = 0;
    }
    if(abs(x) < d){
        if((ll) k % 2 == 0) ans = abs((ll)x);
        else ans = abs((ll)x - d);
    }
    }
if(x < 0){
    if(abs(x) >d){
        if((ll)(x/d) %2 == 0) {
            if(k %2 == 0) ans = abs((ll) x%d);
            else ans = abs((ll)x%d +d);
        }
    
        else{
            if(k%2 == 0) ans = abs((ll)x%d +d);
            else ans = abs((ll) x%d);
    }

    }
    if(abs(x) == d){
        if((ll) k % 2 == 0) ans = abs((ll)x);
        else ans = 0;
    }
    if(abs(x) < d){
        if((ll) k % 2 == 0) ans = abs((ll)x);
        else ans = abs((ll)x + d);
    }
}    
}
    cout << ans << endl;
return 0;
}

Measured memory_bytes: 3596
package main

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

var (
	n                      int
	x, y                   [2 * 10e5]int
	maxA, maxB, maxC, maxD int = -1e12, -1e12, -1e12, -1e12
)

func main() {
	readVariables()
	var answer int = -1e12
	answer = MaxInt(maxA+maxD, answer)
	answer = MaxInt(maxB+maxC, answer)
	fmt.Println(answer)
}

func readVariables() {
	n = nextInt()
	for i := 0; i < n; i++ {
		x[i] = nextInt()
		y[i] = nextInt()
		maxA = MaxInt(maxA, x[i]+y[i])
		maxD = MaxInt(maxD, -x[i]-y[i])
		maxB = MaxInt(maxB, x[i]-y[i])
		maxC = MaxInt(maxC, -x[i]+y[i])
	}
}

/* Template */

var scanner *bufio.Scanner

func init() {
	Max := 1001001
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]byte, 0, Max), Max)
	scanner.Split(bufio.ScanWords)
}

//nextInt converts next token from stdin and returns integer value.
//nextInt panics when conversion into an integer fails.
func nextInt() int {
	if !scanner.Scan() {
		panic("No more token.")
	}
	num, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic("nextInt(): cannot convert to int: " + scanner.Text())
	}
	return num
}

func nextStr() string {
	if !scanner.Scan() {
		panic("No more token.")
	}
	return scanner.Text()
}

// MinInt returns minimum argument
func MinInt(x, y int) int {
	if x < y {
		return x
	} else {
		return y
	}
}

//MaxInt returns maximum argument
func MaxInt(x, y int) int {
	if x < y {
		return y
	} else {
		return x
	}
}

//AbsInt returns |x| for x
func AbsInt(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

//ModPow calculates integer power with modulo operation
//if modulo <= 1, it powers w/o module operation
//if base < 0, return value might be negative too.
func ModPow(base, exponent, modulo int) (result int) {
	result = 1
	for exponent > 0 {
		if exponent%2 == 1 {
			result *= base
			if modulo > 1 {
				result %= modulo
			}
		}
		base *= base
		if modulo > 1 {
			base %= modulo
		}
		exponent /= 2
	}
	return
}

//Gcd
func Gcd(vals ...int) (result int) {
	if len(vals) == 0 {
		return
	}
	result = vals[0]
	for i := 1; i < len(vals); i++ {
		result = gcd(result, vals[i])
	}
	return
}

func gcd(x, y int) int {
	x, y = AbsInt(x), AbsInt(y)
	for y > 0 {
		x, y = y, x%y
	}
	return x
}

//Lcm
func Lcm(vals ...int) (result int) {
	if len(vals) == 0 {
		return
	}
	result = vals[0]
	for i := 1; i < len(vals); i++ {
		result = lcm(result, vals[i])
	}
	return
}

func lcm(x, y int) int {
	return x * y / gcd(x, y)
}


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

int main()
{
  int h, m, s;
  int n, k, l;

  for (int i = 0; i < 3; i++){
    cin >> h >> m >> s >> n >> k >> l;
    m += h * 60;
    s += m * 60;
    k += n * 60;
    l += k * 60;

    l -= s;
    k = l / 60;
    l = l - k * 60;
    n = k / 60;
    k = k - n * 60;
    cout << n << " " << k << " " << l << endl;
  }

  return 0;
}

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

using namespace std;
typedef long long ll;

int main() {
    ll x, k, d;
    cin >> x >> k >> d;
    ll ans;
    ll t = abs(x) / d;
    if (k <= t) {
        ans = abs(x) - k * d;
    } else {
        if ((k - t) % 2 == 0) {
            ans = abs(x) % d;
        } else {
            ans = d - (abs(x) % d);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3632
# -*- coding: utf-8 -*-
N = int(input())

if N == 1:
    print(1)
    exit()

#
X, Y = [], []
for _ in range(N):
    x, y = map(int, input().split(' '))
    X.append(x)
    Y.append(y)

#
import collections
xy_frq_dict = collections.defaultdict(int)
for i in range(N):
    for j in range(N):
        if i == j:
            continue

        x, y = X[i] - X[j], Y[i] - Y[j]
        xy_frq_dict[(x, y)] += 1

xy_frq_pairs = list(xy_frq_dict.items())
xy_frq_pairs.sort(key=lambda x: x[1])
ret = N - xy_frq_pairs[-1][1]
print(ret)





Measured memory_bytes: 39536
# coding: utf-8
# Your code here!
N = int(input())
l = [[0] * 2 for i in range(N)]
A = list(map(int,input().split()))
for i in range(N):
    l[i][0] = i + 1
    l[i][1] = A[i]
#print(l)
l = sorted(l, key=lambda x:x[1], reverse=False)

for li in l:
    print(str(li[0]) + " ", end="")

Measured memory_bytes: 68384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX 10000001
#define infpos 10e5
#define infneg -10e5
bool sortbysec(const pair<ll,ll> &a, const pair<ll,ll> &b)
{return (a.first-a.second > b.first-b.second);}
int a[100000]={0};
int main(){
ll t,x,n,h,d,j,ans,maxi;
cin>>n;
cout<<ll(pow(n,3))<<endl;
return 0;
}


Measured memory_bytes: 256
import sys

input = sys.stdin.readline


def main():
    N = int(input())
    A = tuple(map(int, input().split()))

    P = 10 ** 9 + 7
    num = [0, 0, 0]
    ans = 1
    for a in A:
        cnt = num.count(a)
        if cnt == 0:
            ans = 0
            break
        ans = (ans * cnt) % P
        num[num.index(a)] += 1

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 19924
#include <stdio.h>
int main(){
  int v,n,a[1000],i,j;
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&a[i]);
  for(j=0;j<n;j++){
      printf("%d",a[j]);
      if(j!=n-1)printf(" ");
      else printf("\n");
    }
  for(i=1;i<n;i++){
    v=a[i];
    j=i-1;
    while(j>=0&&a[j]>v){
      a[j+1]=a[j];
      j--;
    }
    a[j+1]=v;
    for(j=0;j<n;j++){
      printf("%d",a[j]);
      if(j!=n-1)printf(" ");
      else printf("\n");
    }
  }
  return 0;
}



Measured memory_bytes: 2700
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <map>

typedef long long ll;
#define rep(i, a, n) for(ll i = a; i<n; i++)
#define ALL(a) begin(a), end(a)
#define mii map<int, int>
#define msi map<string, int>
#define vi vector<int>
#define vl vector<ll>
#define MOD 1000000007
#define INF 1e9
#define showVector(v) rep(i,0,v.size()){p(v[i]);p(" ")} pl("")
#define p(s) std::cout << s ;
#define pl(s)  std::cout << s << endl;
using namespace std;

// 素数判定 O(√n)
bool is_prime(int n){
    for(int i = 2; i * i <= n; i++){
        if(n % i == 0) return false;
    }
    return true;
}

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

}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
class UnionFind {
public:
    vector<ll> par;
    void init(ll n) {
        rep(i, 0, n) {
            par.push_back(i);
        }
    }

    ll root(ll x) {
        if (par[x] == x) {
            return x;
        } else {
            return par[x] = root(par[x]);
        }
    }

    bool unite(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;

        par[y] = x;
        return true;
    }

    bool isSame(ll x, ll y) {
        return root(x) == root(y);
    }
};
int main() {
    string s;
    ll N, Q;;
    cin >> N >> Q;
    UnionFind T;
    T.init(N);
    rep(i, 0, Q) {
        ll p, b, c;
        cin >> p >> b >> c;
        if (p==0) {
            T.unite(b, c);
        } else {
            if (T.isSame(b, c)) {
                cout << 1 << endl;
            } else {
                cout << 0 << endl;
            }
        }
    }
    return 0;
}



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

#define ll long long
#define ld long double
#define ff first
#define ss second
#define eps 1e-9
#define pi acos(-1.0)
#define all(v) v.begin(),v.end()

#define MAX 500005

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    string s;
    cin >> s;

    ll ans = 0;

    for(char x:s)
        ans+= x-'0';

    if(ans%9 == 0)
        cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3768
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Kein Yukiyoshi
 */

#include "bits/stdc++.h"
#define int long long
#define rep(i, n)           for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b)        for (int i = (int)(a); i < (int)(b); i++)
#define FOR(i, a)           for (auto &i : a)
#define ALL(obj)            begin(obj), end(obj)
#define MAX(x)              *max_element(ALL(x))
#define MIN(x)              *min_element(ALL(x))
#define sum(x)              accumulate(ALL(x), 0LL)
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))

using namespace std;
const int MOD    = (int)(1e9 + 7);
const int INF    = (int)(1e13 + 7);
const double EPS = 1e-14;
const double PI  = acos(-1);

int CEIL(int a, int b) { return (a >= 0 ? (a + (b - 1)) / b : (a - (b - 1)) / b); } //ceil() for int
int mod(int a, int b) { return a >= 0 ? a % b : a - (b * CEIL(a, b)); }             //always return positive num
int bpm(int a, int b) {                                                             //return x^y in order(log(y))
  int res = 1;
  for (a %= MOD; b; a = a * a % MOD, b >>= 1)
    if (b & 1) res = res * a % MOD;
  return res;
}

class DKatanaThrower {
public:
  static void solve(istream &cin, ostream &cout) {
    int N, H;
    cin >> N >> H;
    vector<int> a(N);
    vector<int> b(N);
    rep(i, N) {
      cin >> a[i] >> b[i];
    }
    if (MAX(a) >= MAX(b)) {
      cout << CEIL(H, MAX(a)) << endl;
    } else {
      int ans = 0;
      sort(ALL(a));
      sort(ALL(b));
      while (b[b.size() - 1] > a[a.size() - 1]) {
        H -= b[b.size() - 1];
        b.pop_back();
        ans++;
        if (H <= 0) {
          cout << ans << endl;
          return;
        } else if (b.size() == 0) {
          break;
        }
      }
      ans += CEIL(H, a[a.size() - 1]);
      cout << ans << endl;
    }
  }
};


signed main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
  DKatanaThrower solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}


Measured memory_bytes: 1792
import java.util.*;
import static java.lang.Math.*;

public class Main {

	int INF = 1 << 28;

	void run() {
		Scanner sc = new Scanner(System.in);
		int[] a = new int[5];
		int m=INF;
		for(int i=0;i<5;i++) a[i] = sc.nextInt()-1;
		for(int i=1;i<=a[0]+1;i++) m = min(m, d(a[1], a[2], i) + d(a[3], a[4], i));
		System.out.println(m);
	}
	
	int d(int n1, int n2, int w) {
		return abs(n1/w - n2/w) + abs(n1%w-n2%w);
	}

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

Measured memory_bytes: 17360
#include <iostream>

using namespace std;

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

  int odd_keta_count = 0;
  for (int i=1; i<=N; i++) {
    int num = i;
    int keta = 1;
    num /= 10;
    while (num > 0) {
      num /= 10;
      keta++;
    }

    if (keta % 2 == 1) {
      odd_keta_count++;
    }
  }

  cout << odd_keta_count;

  return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n, a int
	var divisionCounts []int

	fmt.Scan(&n)

	for i := 0; i < n; i++ {
		count := 0
		fmt.Scan(&a)
		for true {
			if a%2 == 0 {
				a = a / 2
				count++
			} else {
				divisionCounts = append(divisionCounts, count)
				break
			}
		}
	}

	min := divisionCounts[0]

	for _, val := range divisionCounts {
		if val < min {
			min = val
		}
	}

	fmt.Println(min)
}


Measured memory_bytes: 1796
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

vint a, f;
int n;
ll k;

bool check(ll x) {
    vll mx(n);
    rep(i,n) mx[i] = x/f[i];
    sort(rall(mx));
    ll ct = 0;
    rep(i,n) ct += max((ll)0,(ll)a[i]-mx[i]);
    return ct <= k;
}

int main() {
    cin >> n >> k;
    a.resize(n); 
    f.resize(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> f[i];
    sort(rall(a));
    ll l = -1;
    ll r = inf_l;
    while (r-l > 1) {
        ll mid = (l+r)/2;
        if (check(mid)) r = mid;
        else l = mid;
    }
    cout << r << endl;
}

Measured memory_bytes: 6360
a, b = gets.split.map(&:to_i)

grid = 50.times.map { Array.new(100, ".") }
grid += 50.times.map { Array.new(100, "#") }

(b-1).times do |i|
  y = i/25
  x = (i%50)*2

  grid[y][x] = "#"
end

(a-1).times do |i|
  y = i/25 + 51
  x = (i%50)*2

  grid[y][x] = "."
end

puts "100 100"
grid.each { |row| puts row.join }


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

vector<long long> step_pattern(30,0);

int steps(int n){
    int s;
    if(step_pattern.at(n-1)!=0){
        s=step_pattern.at(n-1);
    }else{
        s=steps(n-1)+steps(n-2)+steps(n-3);
        step_pattern.at(n-1)=s;
    }
    return s;
}

int main(){
    step_pattern.at(0)=1;
    step_pattern.at(1)=2;
    step_pattern.at(2)=4;
    int n;
    vector<int> answers;
    while(cin >> n && n!=0){
        int years=steps(n)/3650;
        if(steps(n)%3650!=0){
            years++;
        }
        answers.push_back(years);
    }
    for(int i=0;i<answers.size();i++){
        cout << answers.at(i) << endl;
    }
    return 0;
}



Measured memory_bytes: 3124
#include <iostream>
#include <vector>

void solve(int N)
{
  long long sum = 0;
 for (int i = 1; i < N; i++)
 {
   sum+=i;
 }
 std::cout << sum << std::endl;

}

int main(void)
{
  int N;
  std::cin >> N;
  solve(N);
  return 0;
}


Measured memory_bytes: 256
N = int(input())
S = input()
cnt = 0

for i in range(10):
    a = S.find(str(i))
    if a == -1 : continue
    for j in range(10):
        b = S.find(str(j),a+1)
        if b == -1 : continue
        for k in range(10):
            c = S.find(str(k),b+1)
            if c != -1 :
                cnt += 1

print(cnt)


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

#define LINESIZE 81

int main()
{
        char string[LINESIZE];
        char tmp[LINESIZE];
        char *pointer;
        int i = 0;
        int linesize = 0;


        while(  fgets( string, LINESIZE, stdin ) != NULL )
        {
                while( 1 )
                {
                        linesize = strlen( string );
                        if ( strstr( string, "the" ) != NULL || strstr( string, "this" ) != NULL || strstr( string, "that" ) != NULL )
                        {
                                break;
                        }

                        for ( i = 0 ; i < linesize ; i = i + 1 )
                        {
                                if ( string[i] >= 'a' && string[i] <= 'y' )
                                {
                                        string[i] = string[i] + 1;
                                }
                                else if ( string[i] == 'z' )
                                {
                                        string[i] = 'a';
                                }
                        }
                }
                fprintf( stdout, "%s", string );
        }

        return 0;
}

Measured memory_bytes: 524
import java.util.ArrayList;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	Scanner sc = new Scanner(System.in);
	public static void main(String[] args){
		new Main();
	}
	public Main(){
		new ABC105().doIt(); //No_chedck
//		new ABC106().doIt(); //No_chedck
//		new ABC107().doIt();
//		new ABC108().doIt(); //Math
//		new ABC109().doIt(); //LCM
	}
	class ABC105{
		void doIt() {
			long n = sc.nextLong();
			String str = "";
			for(long i = 1; n != 0; i *= -2) {
				if((n % (i*2)) != 0) {
					n -= i;
					str = "1" + str;
				}
				else{
					str = "0" + str;
				}
//				System.out.println(str);
			}
			if(str.isEmpty()) str = "0";
			System.out.println(str);
		}
	}
	class ABC106{
		void doIt() {
			String str = sc.next();
			long K = sc.nextLong();
			int ans = 0;
			for(int i = 0;i < str.length();i++) {
				long pos = i + 1;
				int num = Integer.parseInt(""+str.charAt(i));
				if(pos == K || num > 1) {
					ans = num;
					break;
				}
			}
			System.out.println(ans);
		}
	}
	class ABC107{
		void doIt() {
			int N = sc.nextInt();
			int K = sc.nextInt() - 1;
			long x[] = new long[N];
			long ans = Integer.MAX_VALUE;
			for(int i = 0;i < N ;i++)x[i] = sc.nextLong();
			for(int i = 0;i < N - K;i++) {
				long dist = Math.abs(x[i] - x[i + K]);
				if(x[i + K] < 0)dist = dist + Math.abs(0 - x[i + K]);
				else if(x[i] > 0)dist = dist + Math.abs(0 - x[i]);
				else dist = dist + Math.min(Math.abs(x[i]),x[i+K]);
				ans = Math.min(ans, dist);
			}
			System.out.println(ans);
		}
	}
	class ABC108{
		void doIt() {
			int N = sc.nextInt();
			int K = sc.nextInt();
			long A = 0;
			long A_2 = 0;
			for(int i = 1;i <= N;i++) {
				if(i % K == 0)A++;
				else if(i*2 % K == 0)A_2++;
			}
			long ans = A*A*A + A_2*A_2*A_2;
			System.out.println(ans);
		}
	}
	class ABC109{
		int euqulid(int A,int B) {
			if(B > 0)return euqulid(B,A % B);
			else return A;
		}
		void doIt(){
			int n = sc.nextInt();
			int X = sc.nextInt();
			int ans = Integer.MAX_VALUE;
			for(int i = 0;i < n;i++) {
				int x = sc.nextInt();
				int dist = Math.abs(x - X);
				if(i == 0)ans = dist;
				else ans = euqulid(dist,ans);
			}
			System.out.println(ans);
		}
	}
}


Measured memory_bytes: 21716
H, W=map(int, input().split())
s=[input() for _ in range(H)]
math=[[-2]*W for _ in range(H)]

from collections import deque
q=deque()
qnex=deque()

def f(r, c, num):
  math[r][c]=num
  if s[r][c]=='#':
    if r<H-1 and math[r+1][c]<-1:
      q.append([r+1, c, num])
      math[r+1][c]=-1
    if c<W-1 and math[r][c+1]<-1:
      q.append([r, c+1, num])
      math[r][c+1]=-1
  else:
    if r<H-1 and math[r+1][c]<-1:
      if s[r+1][c]=='.':
        q.append([r+1, c, num])
        math[r+1][c]=-1
      else:
        qnex.append([r+1, c, num+1])
    if c<W-1 and math[r][c+1]<-1:
      if s[r][c+1]=='.':
        q.append([r, c+1, num])
        math[r][c+1]=-1
      else:
        qnex.append([r, c+1, num+1])

if s[0][0]=='.':
  f(0, 0, 0)
else:
  f(0, 0, 1)
  
while math[-1][-1]<0:
  while len(q)>0:
    data=q.popleft()
    f(data[0], data[1], data[2])
    
  while len(qnex)>0:
    data=qnex.popleft()
    if math[data[0]][data[1]]<-1:
      q.append(data)
  
print(math[-1][-1])

Measured memory_bytes: 3444
#include <bits/stdc++.h>
#include <stdio.h>
#include <algorithm>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
#define rn(i,n) for(int i=1;i<=n;i++)

int main(void){
  int a,b,ans=-1;
  cin>>a>>b;

  for(int i=min(a,b);i<max(a,b);i++){
    if(abs(a-i)==abs(b-i))ans=i;
  }
  if(ans==-1)cout<<"IMPOSSIBLE"<<endl;
  else cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll =long long;
using namespace std;
using graph=vector<vector<int>>;
using field=vector<string>;
using p =pair<int,int>;
const ll mod=1000000007;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

int main(){
    ll n,Y;
    cin>>n>>Y;
    for(int x=0;x<=n;++x){
        for(int y=0;y<=n-x;++y){
            int sum=x*10000+y*5000+(n-x-y)*1000;
            if(sum==Y){
                cout<<x<<" "<<y<<" "<<n-x-y<<endl;
                return 0;
            }
        }
    }
    cout<<-1<<" "<<-1<<" "<<-1<<endl;
}

Measured memory_bytes: 3620
import collections
import math
import operator as op
from functools import reduce
from collections import Counter
import numpy as np
import math
import bisect
import heapq

MOD = 1000000007


def get_inputs(cast_func=None):
    if cast_func is None:
        return input().split()
    else:
        return list(map(cast_func, input().split()))


def get_input(cast_func=None):
    if cast_func is None:
        return input()
    else:
        return cast_func(input())


def main():
    A, B, N = get_inputs(int)
    if N >= B-1:
        print(math.floor(A - A/B))
    else:
        print(math.floor(A * N / B))


if __name__ == '__main__':
    main()


Measured memory_bytes: 27140
#include<bits/stdc++.h>
#define LL long long
#define db double
#define il inline
#define re register
#define mkpr make_pair

using namespace std;
const int N=1e6+10,mod=1e9+7;
il LL rd()
{
    LL x=0,w=1;char ch=0;
    while(ch<'0'||ch>'9') {if(ch=='-') w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') {x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
    return x*w;
}
int n,m,f[N],ans;

int main()
{
	n=rd();
	m=(1ll*(n-1)*(n-1))%mod;
	ans=m+1+(n>2);
	int sm=f[0]=1;
	for(int i=1;i<n;++i)
	{
		f[i]=sm;
		if(i-2>=0) f[i]=(f[i]-f[i-2]+mod)%mod;
		sm=(sm+f[i])%mod;
		if(i!=n-1) ans=(ans+1ll*f[i]*(m+min(i+2,n-1))%mod)%mod;
		else ans=(ans+1ll*f[i]*n%mod)%mod;
	}
	printf("%d\n",ans);
    return 0;
}



Measured memory_bytes: 4096
#include<iostream>
#include<vector>
using namespace std;
int main() {
	int n, m; cin >> n >> m;
	vector<int> cnt(m,0);
	for (int i = 0; i < n; i++) {
		int k; cin >> k;
		for (int j = 0; j < k; j++) {
			int a; cin >> a;
			cnt[a-1]++;
		}
	}
	int ans = 0;
	for (int i = 0; i < m; i++) {
		if (cnt[i] == n) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

int main()
{
  int n;
  cin >> n;
  
  int l[10];
  
  for (int i = 0; i < n; i++)
    cin >> l[i];
  
  sort(l, l+n);
  
  int sum = 0;
  for (int i = 0; i < n-1; i++)
    sum += l[i];
  
  if (sum > l[n-1])
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
using Graph = vector<vector<int>>;
using Graphl = vector<vector<ll>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
#define RRep(i, k, n) for (int i = k; i > (int)(n); i--)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define ALL(a)  (a).begin(),(a).end()
#define rALL(a)  (a).rbegin(),(a).rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> void PrintVector(const vector<T> &vec) {for (auto val : vec) cout << val << " "; cout << endl;}
const long long INF = 1LL << 60;
const long long minusINF = -(1LL << 40);
const int MOD = 1000000007;
const double PI = acos(-1); //3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    ll n, k; cin >> n >> k;
    Graphl s(n);
    rep(i, n)
    {
        ll t, d; cin >> t >> d; --t;
        s[t].push_back(d);
    }

    for(auto &v : s)
    {
        sort(rALL(v));
        if (v.empty()) v.push_back(minusINF);
    }

    sort(ALL(s), [&](vector<ll> a, vector<ll> b) {return a[0] > b[0];});

    ll cur = 0;
    priority_queue<ll> q;
    rep(i, k)
    {
        cur += s[i][0];
        Rep(j, 1, s[i].size()) q.push(s[i][j]);
    }
    Rep(i, k, n) rep(j, s[i].size()) q.push(s[i][j]);

    ll ans = cur + k * k;
    for (ll x = k - 1; x >= 1; --x)
    {
        ll v = s[x][0];
        ll w = q.top();
        if (v < w)
        {
            q.pop(); cur += w;
            q.push(v); cur -= v;
        }
        ans = max(ans, cur + x * x);
    }
    cout << ans << endl;
}

Measured memory_bytes: 9720
main :: IO ()
main = do
  [_,w] <- map read . words <$> getLine :: IO [Int]
  rec <- lines <$> getContents :: IO [String]
  putStrLn $ replicate (w+2) '#'
  mapM_ (\l -> putStrLn $ "#" ++ l ++ "#") rec 
  putStrLn $ replicate (w+2) '#'

Measured memory_bytes: 1020