akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define int long long
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

long double a, b, p, q, r;

signed main() {
	cin >> a >> b >> p >> q >> r;
	long double s = b * p;
	long double t = (b - a)*q;
	printf("%.10Lf", b + (s - t) / (q + r));
}


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

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

    for (int i = 0; i <= x; i++) {
        int j = x - i;
        if ((2 * i + 4 * j) == y) {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
}

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

int main(){
  string S,T;
  cin >> S >> T;
  int n = S.length();
  int count = 0;
  for(int i = 0; i < n; i++){
    if(S[i] != T[i]){
      count += 1;
    }
  }
  cout << count << endl;
}


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

int main() {
  int a,b,count;
  count = 0;
  string str,str1,str2;
  cin >> a >> b;
  for(a;a<=b;a++){
    str = to_string(a);
    str1 = str;
    reverse(str.begin(),str.end());
    str2 = str;
    if (str==str1){
      count += 1;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	int k=0,i;
	for(i=0;i<1000;i++)
	{
		if(a%2==1 || b%2==1 || c%2==1)
			break;
		int a1=a/2,b1=b/2,c1=c/2;
		a=b1+c1;
		b=a1+c1;
		c=a1+b1;
		k++;
	}
	if(i==1000)
		cout<<-1<<endl;
	else
		cout<<k<<endl;
}

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

int main() {
    int i, a=700;
    string s;
    cin >> s;
    for(i=0; i<=2; i++) {
        if(s[i] == 'o') a+=100;
    }
    cout << a << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define fir first
#define sec second
#define rep(i,a,b) for (int i = (a); i <= (b); ++ i)
#define rrp(i,a,b) for (int i = (a); i >= (b); -- i)
#define gc() getchar()
template <typename tp>
inline void read(tp& x) {
  x = 0; char tmp; bool key = 0;
  for (tmp = gc(); !isdigit(tmp); tmp = gc())
    key = (tmp == '-');
  for (; isdigit(tmp); tmp = gc())
    x = (x << 3) + (x << 1) + (tmp ^ '0');
  if (key) x = -x;
}
template <typename tp>
inline void ckmn(tp& x,tp y) {
  x = x < y ? x : y;
}
template <typename tp>
inline void ckmx(tp& x,tp y) {
  x = x < y ? y : x;
}

const int MOD = (int)(1e9 + 7);
inline void Add(int& x,int y) {
  x = x + y >= MOD ? x + y - MOD : x + y;
}
inline void Sub(int& x,int y) {
  x = x - y < 0 ? x - y + MOD : x - y;
}
int power(int a,int b) {
  int ret = 1;
  while (b) {
    if (b&1) ret = (ll)ret * a % MOD;
    a = (ll)a * a % MOD;
    b >>= 1;
  }
  return ret;
}

const int N = 300010;
int per[N], n, h, dfn[N], sz[N], dcnt, val[N], ival[N];
int ans;
void dfs(int pos) {
  dfn[pos] = ++ dcnt;
  sz[pos] = 1;
  if (2 * pos + 1 <= n) {
    rep (a, 0, 1) {
      dfs(2 * pos + a);
      sz[pos] += sz[2 * pos + a];
    }
  }
}
typedef pair<pii,int> piii;
vector<piii> vec;
void fsd(int pos,int sgn) {
  if (2 * pos + 1 <= n) {
    fsd(2 * pos, sgn);
    fsd(2 * pos + 1, sgn);
  } else {
    vec.push_back(
      make_pair(pii((n / 2) + per[pos - (n / 2)], val[pos]), sgn)
      );
  }
}
int sta[N], top, num[N];
bool insub(int a,int b) {
  return dfn[a] >= dfn[b] && dfn[a] < dfn[b] + sz[b];
}
int lca(int a,int b) {
  if (!a || !b) return a + b;
  while (a != b) {
    if (a > b) a >>= 1;
    else b >>= 1;
  }
  return a;
}
int doit(int rt) {
  vec.clear();
  fsd(2 * rt, 0), fsd(2 * rt + 1, 1);
  sort(vec.begin(), vec.end(), [=](piii a,piii b) -> bool {
    return a.fir.fir < b.fir.fir;
  });
  int ret = 0;
  rep (sgn, 0, 1) {
    top = 0;
    rep (i, 0, (int)vec.size()-1) {
      int p = vec[i].fir.fir;
      int las = 0, rec = 0;
      while (top >= 1 && !insub(p, sta[top])) {
        Add(rec, num[top]);
        las = sta[top --];
      }
      int tmp = lca(las, p);
      if (sta[top] == tmp) Add(num[top], rec);
      else {
        sta[++ top] = tmp;
        num[top] = rec;
      }
      if (vec[i].sec == sgn) {
        if (sta[top] != p) sta[++ top] = p, num[top] = 0;
        Add(num[top], (ll)vec[i].fir.sec * val[p] % MOD);
      } else {
        int tv = (ll)vec[i].fir.sec * val[p] % MOD;
        rep (a, 1, top) Add(ret, (ll)tv * num[a] % MOD * ival[sta[a]] % MOD);
      }
    }
  }
  ret = (ll)ret * ival[rt] % MOD;
  return ret;
}
int main() {
  read(h);
  n = (1 << h) - 1;
  rep (i, 1, (n+1)/2) read(per[i]);
  dfs(1);
  rep (i, 1, n) {
    val[i] = i;
    if (i > 1) val[i] = (ll)val[i] * val[i >> 1] % MOD;
    ival[i] = power(val[i], MOD - 2);
  }
  rrp (i, n, 1) {
    if (i > 1) ival[i] = (ll)ival[i] * ival[i >> 1] % MOD;
  }
  rep (i, 1, n / 2)
    Add(ans, doit(i));
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 9760
#ifdef LOCAL
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
#else
#include <bits/stdc++.h>
#endif
using namespace std ;

typedef long long ll ;
#define rep(i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

/*
__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}
*/

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

	string A, B, C;
	
	cin >> A >> B >> C;

	if (A[A.size()-1] == B[0] && (B[B.size()-1] == C[0]))
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int N,M,A,i;
    int X[2019]={0};
    scanf("%d",&N);
    for(i=0;i<N;i++){
        scanf("%d",&X[i]);
    }
    scanf("%d",&M);
    for(i=0;i<M;i++){
        scanf("%d",&A);
        if(X[A-1]+1 == X[A] || X[A-1]==2019){
            continue;
        }else{
            X[A-1]++;
        }
    }
    for(i=0;i<N;i++){
        printf("%d\n",X[i]);
    }
    return 0;
}


Measured memory_bytes: 2108
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define SIZE 200005

ll N,K;
ll A[SIZE],S[SIZE];
map<ll,ll> MAP;

int main(){

	scanf("%lld %lld",&N,&K);

	S[0] = 0;

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

		scanf("%lld",&A[i]);
		A[i]--;
		S[i+1] += S[i]+A[i];
		S[i+1] %= K;
	}

	ll ans = 0;
	queue<ll> Q;

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

		ans += MAP[S[i]];
		MAP[S[i]]++;
		Q.push(S[i]);

		if(Q.size() == K){

			MAP[Q.front()]--;
			Q.pop();
		}
	}

	printf("%lld\n",ans);

	return 0;
}


Measured memory_bytes: 17536
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
using namespace std;

int a[101][101] = {};

int main(){

    int n; cin >> n;

    int h[n];
    for(int i=0; i<n; i++){
        cin >> h[i];
    }

    int hmax = *max_element(h, h+n);

    for(int i=0; i<n; i++){
        for(int ih=1; ih<=hmax; ih++){
            if(ih <= h[i]){
                a[i][ih] = 1;
            }
        }
    }

    int cnt = 0;
    for(int ih=1; ih<=hmax; ih++){
        for(int i=0; i<n-1; i++){
            if(a[i+1][ih] == 0 && a[i][ih] == 1){
                cnt++;
            }
        }
        if(a[n-1][ih] == 1){
            cnt++;
        }
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
const input = require('fs').readFileSync('/dev/stdin', 'utf8');
const lines = input.trim().split('\n');

while (line = lines.shift()) {
    const numbers = line.split(' ').map(Number);

    // Edit from here
    let a = numbers[0];
    let b = numbers[1];

    if ( a === 0 && b === 0 ) { break; }

    if ( a > b ) {
        const tmp = a;
        a = b;
        b = tmp;
    } 

    const output = a + ' ' + b;
    // to here
    
    console.log(output);
    
}


Measured memory_bytes: 19088
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int n = saori.saori_hayami();
		int k = saori.saori_hayami();
		if(k == 1){
			System.out.println(0);
			return;
		}
		System.out.println(n-k);
		
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 21204
#include <stdio.h>

int main()
{   int n;
    scanf("%d",&n);
    int a[n];
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    int ans=0,check=1;
    for(int i=0;i<n;i++){
        if(a[i]==check){
            check++;
        }else{
            ans++;
        }
    }
    if(ans==n)ans=-1;
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 896
//#pragma GCC optimize("O3")
//#pragma GCC target("avx2")
// 293206GT
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <unordered_set>
#include <stack>
#include <string>
#include<algorithm>
#include <random>
#include <bitset>
#include <chrono>

typedef long long ll;

using namespace std;
#define put(a) cout << (a) << '\n'
#define sqr(x) (x) * (x)
typedef pair<ll, ll> pii;
typedef long double ld;

typedef pair<ld, ld> pld;
#define rep(x, y, a) for (int x = (y); x < (int)(a); ++x)
#define all(a) a.begin(), a.end()
#define chkmax(a, b) a = max(a, (b))
#define chkmin(a, b) a = min(a, (b))
#define prev asasdasd
#define next aasdasda
#define left asdasdasdasd
#define right asnabsdkasdl
#define rank asdasdknlasd
#define move asdasdas

typedef vector<ll> vi;
typedef vector<pii> vpii;
namespace IO {
    template<class A, class B>
    ostream &operator<<(ostream &out, pair<A, B> &a) {
        out << a.first << " " << a.second;
        return out;
    }

    template<class A, class B>
    ostream &operator<<(ostream &out, vector<pair<A, B>> &a) {
        for (pair<A, B> x: a)
            out << x.first << " " << x.second << '\n';
    }

    template<class A>
    ostream &operator<<(ostream &out, vector<A> &a) {
        for (A x: a) out << x << ' ';
        return out;
    }

    template<class A, class B>
    istream &operator>>(istream &in, pair<A, B> &a) {
        in >> a.first >> a.second;
        return in;
    }

    template<class A>
    istream &operator>>(istream &in, vector<A> &a) {
        for (A &x: a) in >> x;
        return in;
    }
}
using namespace IO;
#define int ll

void solve() {
    int n, m;
    cin >> n >> m;
    vi h(n);
    cin >> h;
    vector<vi> g(n);
    rep(i, 0, m) {
        int a, b;
        cin >> a >> b;
        --a;--b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vi f(n, 1);
    rep(i, 0, n) {
        for (int j: g[i]) if (h[j] >= h[i]) f[i] = 0;
    }
    put(count(all(f), 1));
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(30);
//    freopen("input.txt", "r", stdin);
    int q = 1;
//    cin >> q;
    while (q--) solve();
}



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

using namespace std;

#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<pii, int> para;
const int inf = 1e9 + 7;
const int maxN = 1e6 + 5;

int n, m, used[maxN];

int main() {
	ios_base::sync_with_stdio(0);
	cin>>n>>m;
	REP(i, m) {
		int a, b;
		cin>>a>>b;
		if (a == n) {
			used[b]++;
		}
		if (b == n) used[a]++;

		if (a == 1) used[b]++;
		if (b == 1) used[a]++;
	}
	FOR(i, 2, n - 1) {
		if (used[i] == 2) {
			cout<<"POSSIBLE";
			return 0;
		}
	}
	cout<<"IMPOSSIBLE";
	return 0;
}


Measured memory_bytes: 1024
n,t,s,i,j,k[999];
main() {
	for(;scanf("%d",&n)*n;){
		memset(k,0,sizeof(k));
		for(i=0;i<n;i++){
			scanf("%d%d",&t,&s);
			k[s]+=t;
		}
		n=0;t=0;
		for(i=0;i<999;i++){
			t+=k[i];
			n|=t>i;
		}
		puts(n?"No":"Yes");
	}
}

Measured memory_bytes: 0
# frozen_string_literal: true

a = gets.to_i
b = gets.to_i
c = gets.to_i
x = gets.to_i

answer = 0
for i in 0..a do
  for j in 0..b do
    for k in 0..c do
      answer += 1 if (500 * i + 100 * j + 50 * k) == x
    end
  end
end

print answer


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n,k;
ll l,r;
ll a[44];
vector<ll> b[41];// 选i个硬币有哪些不同结果 
vector<ll> c[41];
void dfs1(int i,ll v,int cnt){
	if(i==n/2){b[cnt].push_back(v);return;}
	dfs1(i+1,v+a[i],cnt+1);
	dfs1(i+1,v,cnt);
}
void dfs2(int i,ll v,int cnt){
	if(i==n){c[cnt].push_back(v);return;}
	dfs2(i+1,v+a[i],cnt+1);
	dfs2(i+1,v,cnt);
}
void solve(){
	if(n==1){cout<<(k==1&&a[0]>=l&&a[0]<=r)<<"\n";return;}
	dfs1(0,0,0);
	dfs2(n/2,0,0);
	ll res=0;
	for(int i=0;i<=40;i++)sort(b[i].begin(),b[i].end()),sort(c[i].begin(),c[i].end());
	for(int i=0;i<=k;i++){
		int j=k-i;
		for(int t=0;t<b[i].size();t++){
			ll v=b[i][t];
			res+=upper_bound(c[j].begin(),c[j].end(),r-v)-lower_bound(c[j].begin(),c[j].end(),l-v);
		}
	}cout<<res<<"\n";
}
int main(){
	cin>>n>>k>>l>>r;
	for(int i=0;i<n;i++)cin>>a[i];
	solve();
	return 0;
}



Measured memory_bytes: 23336
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    //nextLineとnextを同時に使ったら死ぬ
    val sc = new Scanner(System.in)

    val a, b, c = sc.nextInt()
    val nums = Array(a, b, c).sorted.reverse

    val max = nums.head
    val ans =
      if ((max * 3 - nums.sum) % 2 == 0) (max * 3 - nums.sum) / 2
      else (max * 3 - nums.sum) / 2 + 2

    println(ans)
  }
  def debug(args: Any*): Unit = {
    Console.err.println(args.mkString(" "))
  }
}



Measured memory_bytes: 25548
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
//#include<vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

void pakuri_sort(int N, int A[]) {
	const int b = 8;
	int tmp[100001];
	rep(k, 4) {
		int kazu[1 << b] = {}, kazu2[1 << b] = {};
		rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];
		for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i];
		k++;
		rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];
		for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i];
	}
}

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


	int N = getint();
	int A = getint();
	int B = getint();
	A -= B;
	int H[100000];
	ll goukei = 0;
	rep(i, N) {
		H[i] = getint();
		goukei += H[i];
	}
	pakuri_sort(N, H);


	int L = goukei / (A + (ll)B * N) - 1;
	int R = (1000000000 + B - 1) / B;

	while (L + 1 != R) {
		int m = (L + R) / 2;
		int damage = B * m;
		int cnt = 0;
		auto kaishi = upper_bound(H, H + N, damage);
		for (; kaishi != H + N; kaishi++) {
			cnt += (*kaishi - damage + A - 1) / A;
			if (cnt > m) break;
		}
		if (cnt <= m) R = m;
		else L = m;
	}

	printf("%lld", R);

	Would you please return 0;
}

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

int64_t MOD = 1000000007;
double PI = 3.141592653589793;

int main()
{
    int64_t N, ans = 0;
    cin >> N;
    vector<int> list(N);

    for (int i = 0; i < N; i++)
        cin >> list[i];

    sort(list.begin(), list.end());
    reverse(list.begin(), list.end());

    for (int i = 1; i < N; i++)
    {
        ans += list[i / 2];
    }
    cout << ans;
}

Measured memory_bytes: 4048
#include<bits/stdc++.h>
#define ll long long
using namespace std;
struct UnionFind{
    vector<int> v;
    UnionFind(int n){
        v = vector<int>(n, -1);
    }
    int root(int x){
        if(v[x] < 0)
            return x;
        return v[x] = root(v[x]);
    }
    bool unite(int x, int y){
        x = root(x);
        y = root(y);
        if(x == y)
            return false;
        if(v[x] > v[y])
            swap(x, y);
        v[x] += v[y];
        v[y] = x;
        return true;
    }
    int size(int x){
        return -v[root(x)];
    }
};
int main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(m), b(m);
    for(int i = 0; i < m; i++)
        cin >> a[i] >> b[i];
    UnionFind u(n);
    for(int i = 0; i < m; i++)
        u.unite(a[i] - 1, b[i] - 1);
    int ans = 0;
    for(int i = 0; i < n; i++)
        ans = max(ans, u.size(i));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5600
using System;

class Program
{
    static void Main()
    {
        String[] arr = Console.ReadLine().Split();
        int a = int.Parse(arr[0]), b = int.Parse(arr[1]);
        Console.WriteLine(
            a < b ? new string(arr[0][0], b) : new string(arr[1][0], a));
    }
}

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

int gcd(int m,int n)
{
    if(n==0)
        return m;
    
    return gcd(n ,m%n);
}

int lcm(int m,int n)
{
    return ((m/gcd(m,n))*n);
}

int main()
{
    int m,n;
    
    while(cin>>m>>n){
        cout<<gcd(m,n)<<" "<<lcm(m,n)<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 1160
n, a, b = map(int, input().split())
s = input()

success = 0
foreigner = 0
count = 0

for i in s:
    if i == "a":
        print("Yes")
        success += 1
    elif i == "b" and foreigner < b:
        print("Yes")
        success += 1
        foreigner += 1
    else:
        print("No")
    count += 1
    if success == a + b:
        break

for _ in range(n - count):
    print("No")

Measured memory_bytes: 4016
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
  int k,a,b;
  scanf("%d%d%d",&k,&a,&b);
  if (a%k==0 || b%k==0)
  {
    cout<<"OK"<<endl;
    return 0;
  }
  else
  {
    int init = (a/k);
    int final = (b/k);
    if (final>init)
      cout<<"OK"<<endl;
    else
      cout<<"NG"<<endl;
  }
  return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int oo = 1e9;
int number, k;
const int nx = 1e5+5;
ll ac[nx][2];
ll dyn[105][nx];
ll init(ll i, ll w){
	if(w>k) return -oo;
	if(i == number) return 0;
	if(dyn[i][w] != -1) return dyn[i][w];
	ll& res = dyn[i][w];
	res = max(res, init(i+1,w));
	if(w+ac[i][0]<=k) res = max(res, init(i+1,w+ac[i][0])+ac[i][1]);
	return res;
}
int main(){
	
	cin>>number>>k;
	memset(dyn, -1, sizeof dyn);
	for(int i=0; i<number; i++) cin>>ac[i][0]>>ac[i][1];
	cout<<init(0,0)<<"\n";
}

Measured memory_bytes: 82304
def solve(N, H):
    last_h = float('inf')
    _count = -1
    _max = 0
    for h in H:
        if h <= last_h:
            _count += 1
        else:
            if _max < _count:
                _max = _count
            _count = 0
        last_h = h
    if _max < _count:
        _max = _count
    return _max


if __name__ == '__main__':
    N = int(input())
    H = map(int, input().split())
    
    ans = solve(N, H)
    
    print(ans)

Measured memory_bytes: 11132
#include <stdio.h>

void chohoukei(int h, int w)
{
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            printf("#");
        }
        printf("\n");
    }
    printf("\n");
}

int main(void)
{
    while (1)
    {
        int h, w;
        scanf("%d %d", &h, &w);
        if (h == 0 && w == 0)
        {
            break;
        }
        chohoukei(h, w);
    }
    return 0;
}


Measured memory_bytes: 2668
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
using namespace std;

signed main() {
	string s;
	cin >> s;
	
	for (int i = 0; i < (int)s.length() - 1; i++) {
		if (s[i] == 'A' && s[i + 1] == 'C') {
			cout << "Yes" << endl;
			return 0;
		}
	}
	
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
ll INF = 1LL << 60;

vl z_algorithm(const string& s) {
  vl z(s.size(), 0);
  z[0] = s.size();
  ll lt = 0, rt = 0;
  for (ll k = 1; k < s.size(); k++) {
    if (k > rt) {
      ll n = 0;
      while (k + n < s.size() && s[n] == s[k + n]) {
        n++;
      }
      z[k] = n;
      if (n > 0) {
        lt = k;
        rt = k + n - 1;
      }
    } else {
      ll p = k - lt;
      ll right_len = rt - k + 1;
      if (z[p] < right_len) {
        z[k] = z[p];
      } else {
        ll i = rt + 1;
        while (i < s.size() && s[i] == s[i - k]) {
          i++;
        }
        z[k] = i - k;
        lt = k;
        rt = i - 1;
      }
    }
  }
  return z;
}

int main() {
  //
  ll n;
  cin>>n;
  string s;
  cin >> s;
  ll ans = 0;
  rep(i, n-1) {
    string ss = s.substr(i);
    vl z = z_algorithm(ss);
    REP(j, 1, z.size()) {
      ans = max(ans, min(z[j], (ll)j));
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 888
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    x, y = LI()
    ans = abs(abs(x)-abs(y))
    if x > y and abs(x) != abs(y) and x*y > 0:
        ans += 2
    elif x*y < 0 or (x > y and x == 0) or (x > y and y == 0):
        ans += 1

    print(ans)
    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 38640
#include<bits/stdc++.h>
using namespace std;
#define N 100005
int a[N];
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	a[0]--;
	for(int i=1;i<n;i++)
		if(a[i]<a[i-1])
		{
			cout<<"No\n";
			return 0;
		}
		else a[i]=max(a[i-1],a[i]-1);
	cout<<"Yes\n";
	
	return 0;
}

Measured memory_bytes: 640
n,W=map(int,input().split())
wv=[list(map(int,input().split())) for _ in [0]*n]
d={0:0}
for w,v in wv:
    temp=dict()
    for k,i in d.items():
        if k+w in d.keys():
            temp[k+w]=max(d[k+w],i+v)
        else:
            temp[k+w]=i+v
    d.update(temp)
    s=sorted(d.keys())
    m=-1
    for i in s:
        if d[i]<=m:
            del d[i]
        else:
            m=d[i]
print(max([v for w,v in d.items() if w<=W]+[0]))

Measured memory_bytes: 3572
#include<stdio.h>
#include<string.h>
int main(){
	int a;
	long long int sum = 0;
	scanf("%d", &a);
  for(int i=1;i<=a;i++){
  	if(i % 3 == 0 ||i % 5 == 0){
  		continue;
	}else{
		sum += i;
	}		
}
    printf("%lld", sum);
    
    
return 0;
}

Measured memory_bytes: 1700
let rec solve (a, b) list =
  match list with 
  | [] -> a - b
  | a1::b1::list -> solve (a + a1, b + b1) list
  | a1::list -> solve (a + a1, b) list

stdin.ReadLine()
stdin.ReadLine().Split(" ") 
|> Array.map int 
|> Array.toList
|> List.sortBy (fun x -> -x)
|> solve (0, 0)
|> printfn "%d"

Measured memory_bytes: 30148
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

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

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

int main() {
  string S;
  cin >> S;

  int ans = INF;

  int N = S.size();
  rep(i, N - 2) {
    int X = (S[i] - '0') * 100 + (S[i + 1] - '0') * 10 + (S[i + 2] - '0');
    chmin(ans, abs(X - 753));
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
void main() {
	auto N = ri;
	auto L = readAs!(int[]);
	L.sort();
	long res;
	foreach(i, v; L) {
		if(i % 2 == 0) res += v;
	}
	res.writeln;
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <vector>
#include <stack>
#include <cstdio>
#include <string>
#include <bitset>
#include <list>
#include <set>
#include <algorithm>
#include <numeric>
#include <unordered_map>
#include <functional>
#include <queue>
#include <regex>
#include <cassert>
#include <map>
// #include "bits/stdc++.h"

using namespace std;
//debug

#define rep(i, N, M) for (ll i = N; i < M; ++i)
#define rrep(i, N, M) for (ll i = N; i < M; --i)
#define pb push_back


typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;
typedef priority_queue<ll> pqll;
typedef priority_queue<pll, vector<pll>> pqpll;
typedef priority_queue<ll, vll, greater<ll>> pqll_greater;
typedef priority_queue<pll, vector<pll>, greater<pll>> pqpll_greater;


#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define vec(a) vector<a>
#define _CRT_SECURE_NO_WARNINGS

template<class T, class S>
T atbit(T n, S i) {
	return (n >> i) % i;
}

template<class T>
T getbit(T i) {
	return 1LL << i;
}

//#define TRANSFORM(v,w,func) decltype(v) w ; transform((v).begin(),(v).end(),back_inserter(w),func);

using namespace std;

ll euclidean_gcd(ll a, ll b) {
	if (a < b) euclidean_gcd(b, a);
	ll r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}


int main() {
	ll H,W;
	cin >> H>>W;
	vb a(H*W);
	rep(i, 0, H) {
		rep(j, 0, W)
		{	
			ll x;
			cin>> x;
			if (i% 2 == 0) {
				a[i*W+j] = (x % 2 == 0);

			}
			else {
				a[i*W + W-j-1] = (x % 2 == 0);

			}

		}
	}
	vector<pair<pll, pll>> res;

	pair<bool, bool> state{ 0,0 };
	bool isGoodState = a[0];
	rep(i, 1, H*W) {
	
		
		if (!isGoodState) {
			ll row = i / W;
			if (row % 2 == 0) {
				ll column = i % W;
				if (column != 0) {
					res.push_back({ { row,column - 1 },{row, column } });

				}
				else {//corner
					res.push_back({ { row - 1,column },{ row,column } });

				}

			}
			else {
				ll column = W - 1 - i % W;

				if (W - 1 - column != 0) {
					res.push_back({ { row,column + 1 },{row, column } });

				}
				else {
					res.push_back({ { row - 1,column },{ row,column } });
				}

			}
		}
		
		if (!a[i])isGoodState = !isGoodState;

		
	}



	//rep(i, 0, H) {
	//	if (i % 2 == 0) {
	//		rep(j, 1, W) {
	//			if ()break;
	//			if (a[i][j]) {
	//				res.push_back({ {i,j - 1},{i,j} });

	//			}
	//			else {
	//				res.push_back({ { i,j - 1 },{ i,j } });
	//				isGoodState = true;
	//			}
	//		}
	//	}
	//}


		cout << res.size() << endl;
	rep(i, 0, res.size()) {
		cout << res[i].first.first+1 <<" "<< res[i].first.second +1<<" "<< res[i].second.first+1 <<" "<< res[i].second.second+1 << endl;
	}

}
//ll N;
//cin >> N;
//vll a(N);
//rep(i,0, N) cin >> a[i];

Measured memory_bytes: 6516
using System;
using System.Collections.Generic;

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int fh = (n / 500) * 1000;
            int f = n % 500;
            int f2 = (f / 5) * 5;
            Console.WriteLine(fh + f2);

        }
    }
}

Measured memory_bytes: 13140
N = int(input())
h = list(map(int, input().split()))

i = 0
j = 0
ans = 0
while i < N:
    minh = h[j]
    while True:
        if h[j] == 0:
            if j > 0:
                j -= 1
            break
        if minh > h[j]:
            minh = h[j]
        j += 1
        if j >= N:
            j -= 1
            break
    if minh > 0:
        for k in range(i, j+1):
            h[k] -= minh
        ans += minh
    if h[i] == 0:
        i += 1
    j = i

print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<fstream>
#include<sstream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<cmath>
#include<cstdio>
#include<cassert>
using namespace std;

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)(n-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aut(r,v) __typeof(v) r = (v)
#define each(it,o) for(aut(it,(o).begin()); it!=(o).end(); ++it)
#define reach(it,o) for(aut(it,(o).rbegin()); it!=(o).rend(); ++it)
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T1, typename T2> ostream& operator<<(ostream& o, const pair<T1, T2>& p)
{return o<<"("<<p.first<<", "<<p.second<<")";}
template<typename T>string join(const vector<T>&v, string del=", ")
{stringstream s;rep(i,v.size())s<<del<<v[i];return s.str().substr(del.size());}
template<typename T>ostream& operator<<(ostream& o, const vector<T>&v)
{if(v.size())o<<"["<<join(v)<<"]";return o;}
template<typename T>ostream& operator<<(ostream& o, const vector<vector<T> >&vv)
{int l=vv.size();if(l){o<<endl;rep(i,l){o<<(i==0?"[ ":",\n  ")<<vv[i]<<(i==l-1?" ]":"");}}return o;}
template<typename T>ostream& operator<<(ostream& o, const set<T>& st)
{vector<T> v(st.begin(),st.end());o<<"{ "<<join(v)<<" }";return o;}
template<typename T1, typename T2>ostream& operator<<(ostream& o, const map<T1, T2>& m)
{each(p,m){o<<(p==m.begin()?"{ ":",\n  ")<<*p<<(p==--m.end()?" }":"");}return o;}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

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

const double PI = (1*acos(0.0)); 
const double INF = 0x3f3f3f3f;
const double INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
const int mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

string t = "_ABC";

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");

    string s;
    cin >> s;
    vvl dp = vvl(s.size() + 1, vl(4));
    dp[0][0] = 1;
    rep(i, s.size()){
        rep(j, 4){
            if(s[i] == '?') dp[i+1][j] = (dp[i+1][j] + 3 * dp[i][j]) % mod;
            else dp[i+1][j] = (dp[i+1][j] + dp[i][j]) % mod;
        }
        REP(j, 1, 4){
            if(s[i] == t[j] || s[i] == '?')
                dp[i+1][j] = (dp[i+1][j] + dp[i][j-1]) % mod;
        }
    }
    cout << dp[s.size()][3] << endl;

    return 0;
}


Measured memory_bytes: 7376
#include <iostream>
#include <vector>
#include <queue>
#include <string.h>
using namespace std;
typedef long long ll;

ll INF=1e18;
ll v, e, d[105][105], l[105];
bool flag = true;
struct edge { ll from, to, cost; };
edge es[10000];

void warshall_floyd() {
    for (int k = 0; k < 10; k++) 
        for (int i = 0; i < 10; i++)
            for (int j = 0; j < 10; j++) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
            
}

int main(void){
    int h, w;
    cin >> h >> w;
    
    int c;
    for (int i = 0; i < 100; i++) {
        cin >> c;
        d[i / 10][i % 10] = c;
    }
    
    warshall_floyd();
    
    int ans = 0;
    for (int i = 0; i < h*w; i++) {
        int a;
        cin >> a;
        if (a != -1) ans += d[a][1];
    }
    
    cout << ans << endl;
    
    /*    for (int j = 0; j < 10 - 1; j++) {
            cout << d[j][1] << " ";
        }
        cout << d[9][1];
        cout << endl;
    */
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var a, b, c int
	fmt.Scanln(&a, &b, &c)
	if a > b {
		a, b = b, a
	}
	if b > c {
		b, c = c, b
	}
	if a > b {
		a, b = b, a
	}
	fmt.Println(a, b, c)
}


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

int main(){
    int n, ans;
    cin >> n;
    ans = n;
    string s;
    cin >> s;
    rep(i,n-1){
        if(s[i] == s[i+1]){
            --ans;
        }
    }

    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>

using namespace std;

char decrypto(char c, int n) {
    if (n == 0) {
        return c;
    }
    if (c == 'a') {
        return decrypto('Z', n-1);
    }
    if (c == 'A') {
        return decrypto('z', n-1);
    }
    return decrypto(c-1, n-1);
}

int main() {
    int n;
    int k[100];
    string s;
    while (true) {
        cin >> n;
        if (n == 0) {
            return 0;
        }
        for (int i=0; i<n; i++) {
            cin >> k[i];
        }
        cin >> s;
        for (int i=0; i<(int)s.length(); i++) {
            cout << decrypto(s[i], k[i%n]);
        }
        cout << endl;
    }
}

Measured memory_bytes: 1196
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n, k;
	cin >> n >> k;
	vector<ll> x(n);
	rep(i, n) cin >> x[i];
	ll ans = 1e9;
	rep(i, n - k + 1){
		//start from i
		ll cur = abs(0LL - x[i]);
		cur += abs(x[i] - x[i + k - 1]);
		ans = min(ans, cur);
		ll cur1 = abs(0LL - x[i + k - 1]);
		cur1 += abs(x[i] - x[i + k - 1]);
		ans = min(ans, cur1);
	}
	cout << ans << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		char[] alf = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
		int[] count = new int[26];
		
		StringBuilder str_kari = new StringBuilder();
		while(scan.hasNextLine()) {
			str_kari.append(scan.nextLine());
		}

		String str = str_kari.toString();
		for(int i = 0; i < str.length(); i++) {
			char temp = str.charAt(i);
			// not alfabet
			if(!Character.isLetter(temp)) {
				// nothing
			}
			else {
				// 大文字なら小文字へ
				if(Character.isUpperCase(temp)) {
					temp = Character.toLowerCase(temp);
				}
				for(int j = 0; j < 26; j++) {
					if(temp == alf[j]) count[j]++;
				}
				
			}
		}
		
		for(int i = 0; i < 26; i++) {
			System.out.println(alf[i] + " : " + count[i]);
		}
			
		
		
	}

}



Measured memory_bytes: 26240
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define debug(x) cout << #x << " = " << (x) << endl;
#define pb push_back
#define MOD 1000000007
//#define MOD 998244353
//define MOD 1000000007000000
#define INF 1000000000000
#define EPS 0.00000000001
typedef long long ll;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    //---------------------------------------------

    int n, c, k;
    cin >> n >> c >> k;
    vector<pair<ll, ll>> t(n);
    rep(i, n)
    {
        cin >> t[i].first;
        t[i].second = t[i].first + k;
    }
    ll ans = 0;
    sort(rall(t));
    //rep(i,n){
    //    debug(t[i].first);
    //    debug(t[i].second);
    //}
    rep(i, n)
    {
        ll memo = t[i].first;
        ans++;
        int x = i;
        //cout<<memo<<endl;
        for (int j = x + 1; j < x + c; j++)
        {
            if (t[j].first <= memo && memo <= t[j].second)
            {
                i++;
            }
            else
            {
                break;
            }
        }
    }
    cout << ans << endl;
}


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

int main() {

	int x;
	cin >> x;
	int incre = x;
	int count = 1;
	incre += x;
	while (incre % 360 != 0) {
		incre += x;
		count++;
		// cout << incre << endl;
	}

	cout << count + 1 << endl;

	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  int t;
  if(a<b){
    t = a;
    a = b;
    b = t;
  }
  if(a==b)
    cout<<a*2;
  else
    cout<<a*2-1;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <cctype>
using namespace std;

int main(void){
  int a, b;
  cin >> a >> b;
  if(a >= 13)
    cout << b << endl;
  if(6 <= a && 12 >= a)
    cout << b/2 << endl;
  if(a <= 5)
    cout << '0' << endl;
    return 0;
}

Measured memory_bytes: 256
require 'prime'

n = gets.to_i
if n == 1
  puts '1'
  exit
end
M = 10 ** 9 + 7
h = Hash.new(0)
(1..n).to_a.each do |i|
  Prime.prime_division(i).each do |k, v|
    h[k] += v
  end
end
puts h.values.map{|i| (i + 1) % M}.inject{|u, v| u * v % M}

Measured memory_bytes: 2428
import sys, itertools
f = sys.stdin
        
n = int(f.readline())
q = []
rest_r = set(range(8))
rest_c = [i for i in range(8)]
for _ in range(n):
    r, c = map(int, f.readline().split())
    q.append([r, c, r + c, r - c])
    rest_r.remove(r)
    rest_c.remove(c)

def check(q, rc):
    for qi in q:
        if qi[2] == rc[2] or qi[3] == rc[3] :
            return False
    return True
    
def put_queen(q, rest_r, rest_c):
    if len(q) == 8:
        return q
    c = rest_c[len(rest_r) - 1]
    for r in rest_r:
        rc = [r, c, r + c, r - c]
        if check(q, rc):
            ret = put_queen(q + [rc], rest_r.difference([r]) , rest_c)
            if ret:
                return ret
    return False
q = put_queen(q, rest_r, rest_c)
    
board = [None for _ in range(8)]
for qi in q:
    board[qi[0]] = '.' * qi[1] + 'Q' + '.' * (8 - qi[1] - 1)
for line in board:
    print(line)

Measured memory_bytes: 6760
#include <stdio.h>

/*
status
0: start
1: inputting J
2: inputting O
3: inputting I
*/

int main(void) {
	int mozi;
	int status=0;
	int currentrenzoku=0;
	int jrenzoku=0;
	int orenzoku=0;
	int maxlebel=0;
	while(1) {
		mozi=getchar();
		if(mozi==EOF || mozi=='\n')break;
		switch(mozi) {
			case 'J':
				if(status==1) {
					currentrenzoku++;
				} else {
					status=1;
					currentrenzoku=1;
				}
				break;
			case 'O':
				if(status==1) {
					jrenzoku=currentrenzoku;
					currentrenzoku=1;
					status=2;
				} else if(status==2) {
					currentrenzoku++;
				} else {
					status=0;
					currentrenzoku=0;
				}
				break;
			case 'I':
				if(status==2) {
					orenzoku=currentrenzoku;
					currentrenzoku=1;
					status=3;
					if(jrenzoku>=1 && orenzoku==1) {
						if(maxlebel<1)maxlebel=1;
						status=0;
						currentrenzoku=0;
					}
				} else if(status==3) {
					currentrenzoku++;
					if(jrenzoku>=currentrenzoku && orenzoku==currentrenzoku) {
						if(maxlebel<orenzoku)maxlebel=orenzoku;
						status=0;
						currentrenzoku=0;
					}
				} else {
					status=0;
					currentrenzoku=0;
				}
				break;
		}
	}
	printf("%d\n",maxlebel);
	return 0;
}

Measured memory_bytes: 0
from bisect import bisect_left


def solve(string):
    a, b, q, *stx = map(int, string.split())
    s = [-10**10] + stx[:a] + [2 * 10**10]
    t = [-10**10] + stx[a:a + b] + [2 * 10**10]
    # x = dict([])
    ans = []
    i_s = 0
    i_t = 0
    for _x in stx[-q:]:
        """
        while s[i_s] < _x:
            i_s += 1
        while t[i_t] < _x:
            i_t += 1
        """
        i_s, i_t = bisect_left(s, _x), bisect_left(t, _x)
        ls, rs = _x - s[i_s - 1], s[i_s] - _x
        lt, rt = _x - t[i_t - 1], t[i_t] - _x
        r_max = rs if rs > rt else rt
        l_max = ls if ls > lt else lt
        ans.append(
            str(
                min(r_max, l_max, rt + ls + (rt if rt < ls else ls),
                    rs + lt + (rs if rs < lt else lt))))
    # return "\n".join([str(x[_x]) for _x in stx[-q:]])
    return "\n".join(ans)


if __name__ == '__main__':
    n, m, l = map(int, input().split())
    print(solve('{} {} {}\n'.format(n, m, l) + '\n'.join([input() for _ in range(n + m + l)])))


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

void count(vector<int> &ans, int begin, int end, int loop)
{
    for (int i = begin; i < end; i++)
    {
        if ((abs(loop - i) % 2) == 0)
        {
            ans[loop]++;
        }
        else
        {
            ans[loop - 1]++;
        }
    }
}

int main()
{
    string S;
    cin >> S;
    vector<int> ans(S.size(), 0);
    S += 'R';

    char directrion = 'L';
    int start_idx = 0;
    int loop_idx;
    for (int i = 0; i < S.size(); i++)
    {
        if (directrion != S[i])
        {
            if (directrion == 'R')
            {
                directrion = 'L';
                loop_idx = i;
            }
            else if (directrion == 'L')
            {
                count(ans, start_idx, i, loop_idx);
                directrion = 'R';
                start_idx = i;
            }
        }
    }

    for (int a : ans)
    {
        cout << a << " ";
    }
    cout << endl;
}


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

int n;
int F[45];
int fibo(int i) {
    if (F[i]) {
        return F[i];
    }
    F[i] =  fibo(i - 1) + fibo(i-2);
    return F[i];
}

int main() {
    cin >> n;
    F[0] = F[1] = 1;
    cout << fibo(n) << endl;

    return 0;
}



Measured memory_bytes: 3068