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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

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

class UnionFind{
private:
	::std::vector<int_fast32_t> par;
	size_t n;

public:
	UnionFind(){}
	UnionFind(size_t n):n(n){
		par.resize(n, -1);
	}

	int_fast32_t find(int_fast32_t x){
		if(x < 0) return -1;
		return par[x] < 0 ? x : par[x] = find(par[x]);
	}

	size_t size(uint_fast32_t x){
		return -par[find(x)];
	}

	bool unite(uint_fast32_t x, uint_fast32_t y){
		x = find(x);
		y = find(y);
		if(x == y) return false;
		if(size(x) < size(y)) std::swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	bool same(uint_fast32_t x, uint_fast32_t y){
		return find(x) == find(y);
	}
};


int64 N, D;
vector<int64> A;

int64 cost(int64 a, int64 b){
	return A[a]+A[b]+abs(a-b)*D;
}

int64 Boruvka(){
	UnionFind uf(N);
	int64 res = 0;
	bool updated = 1;
	while (updated) {
		updated = 0;
		map<int64, PLL> match; // match[v] := (dis(v, u), u)
		array<int64, 3> top({-1, -1, -1});
		REP(i, N){
			int64 v = uf.find(i);
			if (top[0] != -1) {
				if (uf.find(top[0]) == v) {
					if (top[1] != -1 && (match.count(v) == 0 || match[v].fs > cost(i, top[1])))
						match[v] = PLL(cost(i, top[1]), top[1]);
				} else {
					if (match.count(v) == 0 || match[v].fs > cost(i, top[0]))
						match[v] = PLL(cost(i, top[0]), top[0]);
				}
			}
			top[2] = i;
			sort(all(top), [&](int64 a, int64 b){
					if (a == -1) return false;
					if (b == -1) return true;
					return A[a]-a*D < A[b]-b*D;
				});
			if (uf.find(top[0]) == uf.find(top[1])) swap(top[1], top[2]);
		}
		top = {-1, -1, -1};
		for(int32 i = N-1; i >= 0; i--){
			int64 v = uf.find(i);
			if (top[0] != -1) {
				if (uf.find(top[0]) == v) {
					if (top[1] != -1 && (match.count(v) == 0 || match[v].fs > cost(i, top[1])))
						match[v] = PLL(cost(i, top[1]), top[1]);
				} else {
					if (match.count(v) == 0 || match[v].fs > cost(i, top[0]))
						match[v] = PLL(cost(i, top[0]), top[0]);
				}
			}
			top[2] = i;
			sort(all(top), [&](int64 a, int64 b){
					if (a == -1) return false;
					if (b == -1) return true;
					return A[a]+a*D < A[b]+b*D;
				});
			if (uf.find(top[0]) == uf.find(top[1])) swap(top[1], top[2]);
		}
		for (auto x : match) {
			if(uf.unite(x.fs, x.sc.sc)){
				res += x.sc.fs;
				updated = 1;
			}
		}
	}
	REP(i, N){
		assert(uf.find(i) == uf.find(0));
	}
	return res;
}

int main(void){
	cin >> N >> D;
	A.resize(N);
	REP(i, N) cin >> A[i];
	cout << Boruvka() << endl;
}




Measured memory_bytes: 17920
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let k: isize = read();
    let x: isize = read();

    for i in x - k + 1..x + k {
        println!("{}", i);
    }
}

Measured memory_bytes: 4352
import java.util.*;

class Main{
  public static void main(String[] args){
  	Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int max = -1;
    int sum = 0;
    for(int i=0;i<n;i++){
    	int num = sc.nextInt();
      	if(max < num){max = num;}
      	sum += num;
    }
    sum -= max;
    if(max < sum){
    	System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 23252
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.IO;

namespace SolutionCS
{

    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int N = int.Parse(s[0]);
            int A = int.Parse(s[1]);
            int B = int.Parse(s[2]);
            int C = int.Parse(s[3]);

            int maxSW = (int)Math.Pow(4, N);

            int[] len = new int[N];
            int[] map = new int[N];
            for (int i = 0; i < N; i++)
            {
                len[i] = int.Parse(Console.ReadLine());
            }

            int ans = int.MaxValue;
            for (int i = 0; i < maxSW; i++)
            {
                for (int j = 0; j < N; j++)
                {
                    map[j] = (i >> (j * 2)) & 0x03;
                }

                ans = Math.Min(ans, CalcMP(len, map, A, B, C));
            }

            Console.WriteLine(ans);
        }

        static int CalcMP(int[] length, int[] map, int targetA, int targetB, int targetC)
        {
            int[] totalLen = new int[3];

            int MP = 0;
            for (int i = 0; i < length.Length;i++)
            {
                if(map[i] != 0)
                {
                    int index = map[i] - 1;
                    if(totalLen[index] != 0)
                    {
                        MP += 10;
                    }
                    totalLen[index] += length[i];
                }
            }

            for (int i = 0; i < 3; i++)
            {
                if(0 == totalLen[i])
                {
                    return int.MaxValue;
                }
            }

            MP += Math.Abs(totalLen[0] - targetA);
            MP += Math.Abs(totalLen[1] - targetB);
            MP += Math.Abs(totalLen[2] - targetC);

            return MP;
        }
    }
}


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


void solve(unsigned long long X){
  long long acc = X;
  for(long long i = 0; i < X; i++){
    if(acc <= 100) {
      cout << i << endl;
      break;
    }
    long double my = (long double)acc/101;
    acc = ceil(my*100);
  }
  //cout << ceil(log((long double)X/100)/log(1.01)) << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    unsigned long long X;
  scanf("%llu",&X);
    solve(X);
    return 0;
}


Measured memory_bytes: 3764
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();

        int n = sc.nextInt();
        int m = sc.nextInt();

        UnionFind unifin = new UnionFind(n);

        for (int i = 0; i < m; i++) {
            int a = sc.nextInt() - 1;
            int b = sc.nextInt() - 1;
            unifin.unite(a, b);
        }

        int max = 0;
        for (int i = 0; i < n; i++) {
            int tmp = unifin.size(i);
            max = Math.max(tmp, max);
        }

        System.out.println(max);
    }

    static class UnionFind {
        // Parents[i]:iの親の番号 or 根だった場合、ついているノードの数N(-N)
        static List<Integer> Parents = new ArrayList<>();

        // 最初はすべてが根であるとして初期化
        public UnionFind(int N) {
            for (int i = 0; i < N; i++) {
                Parents.add(-1);
            }
        }

        // データが属する木の根を再帰で得る
        public int root(int x) {
            if (Parents.get(x) < 0)
                return x;
            Parents.set(x, root(Parents.get(x)));
            return Parents.get(x);
        }

        // xとyの木を併合
        public void unite(int x, int y) {
            int rx = root(x);
            int ry = root(y);
            if (rx == ry)
                return;

            // yの方が大きい場合は入れ替える
            if (size(rx) < size(ry)) {
                int tmp = rx;
                rx = ry;
                ry = tmp;
            }

            Parents.set(rx, Parents.get(rx) + Parents.get(ry));
            Parents.set(ry, rx);
        }

        // 2つのデータx, yが属する木が同じならtrueを返す
        public boolean same(int x, int y) {
            int rx = root(x);
            int ry = root(y);
            return rx == ry;
        }

        // 頂点の数を返す
        public int size(int x) {
            if (x >= 0)
                x = root(x);
            return -Parents.get(x);
        }
    }

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}

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

#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define endl "\n"
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define rev(a) (a).rbegin(),(a).rend()
#define pll pair<ll,ll>
#define rep(i,a,b) for(long long i = (a); i <= (b); i++)

const int mod = 1e9+7;
const int N = 1e5+5; 

int main(){
	fast;
	ll t = 1; 
// 	cin >> t;
	while(t--){
	    ll n,a,b; cin >> n >> a >> b;
	    cout << min(n*a,b) << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

const ll mod = 998244353;

ll safePow(ll x, ll y){
    ll result = 1;
    rep(i, y){
        result = (result * x) % mod;
    }
    return result;
}

int main() {
    int n;
    cin >> n;
    vector<int> d(n);
    rep(i, n) cin >> d[i];
    if(d[0] != 0){
        cout << 0 << endl;
        return 0;
    }
    sort(d.begin(), d.end());
    if(d[1] != 1){
        cout << 0 << endl;
        return 0;
    }

    ll cnt = 0, cur_d = 0, prev_cnt = 1;
    ll ans = 1;
    rep(i, n){
        if(d[i] == cur_d){
            cnt++;
        } else {
            if(d[i] != cur_d + 1){
                ans = 0;
                break;
            }
            ans = (ans * safePow(prev_cnt, cnt)) % mod;
            prev_cnt = cnt;
            cnt = 1;
            cur_d++;
        }
        if(i == n - 1){
            ans = (ans * safePow(prev_cnt, cnt)) % mod;
        }
    }
    cout << ans << endl;

    
    return 0;
}


Measured memory_bytes: 768
#!/usr/bin/env ruby

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

N, M = get_ints
X = get_ints

X.sort!

if N == 1
  puts X.last - X.first
else
  sa = X.each_cons(2).map { |a, b| b - a }
  sa.sort!

  puts X.last - X.first - sa.reverse[0..(N-2)].sum
end



Measured memory_bytes: 22976
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl "\n"
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define F first
#define S second
#define bitcnt(v) __builtin_popcount(v)
#define all(v) v.begin(), v.end()

int mod = 1e9 + 7;

ll powMod(ll a, ll n){
	ll ans = 1LL;
	a %= mod;
	while(n > 0){
		if(n&1) ans = (ans * a) % mod;
		a = (a * a) % mod;
		n /= 2; 
	}
	return ans % mod;
}

void solution(){

	int n; cin >> n;
	if(n == 1){
		cout << 0 << endl;
		return;
	}
	if(n == 2){
		cout << 2 << endl;
		return;
	}
	cout << (powMod(10LL,n) - 2*powMod(9LL,n) + powMod(8LL,n) + mod + mod) % mod << endl;
	// cout << powMod(32LL,3LL) << endl;




}	


int main(){ 
	fio;
	int t;
	t = 1;
	// cin >> t;
	for(int i = 1; i <= t; i++){
		// cout << "Case #" << i << ": ";
		solution();
	} 
	return 0;
}

Measured memory_bytes: 3648
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    s = input()

    b = [0] * n
    cnt = 0
    for i in range(n):
        if s[i] == "#":
            cnt += 1
        b[i] = cnt

    w = [0] * n
    cnt = 0
    for i in reversed(range(n)):
        if s[i] == ".":
            cnt += 1
        w[i] = cnt

    res = f_inf
    w = w + [0]
    b = [0] + b
    for i, j in zip(w, b):
        res = min(res, i + j)
    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 20232
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin>>s;
  if(s[0]=='A'&&s[1]=='A'&&s[2]=='A')
     cout<<"No";
  else if(s[0]=='B'&&s[1]=='B'&&s[2]=='B')
     cout<<"No";
  else
    cout<<"Yes";
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int n, g;
double ans;
double e = 0.000000001;
double xin[50], yin[50];
double x[3], y[3], z[3], w[3];
double r, rb, rd;
double cx, cy, dx, dy;
int main() {
	ans = 100000;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%lf%lf", xin + i, yin + i);
	}
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			for (int k = j + 1; k < n; k++) {
				g = 0;
				x[0] = xin[i];
				x[1] = xin[j];
				x[2] = xin[k];
				y[0] = yin[i];
				y[1] = yin[j];
				y[2] = yin[k];
				for (int l = 0; l < 3; l++) {
					z[l] = (x[(l + 1) % 3] - x[(l + 2) % 3]) * (x[(l + 1) % 3] - x[(l + 2) % 3]) +
						(y[(l + 1) % 3] - y[(l + 2) % 3]) * (y[(l + 1) % 3] - y[(l + 2) % 3]);
					z[l] = sqrt(z[l]);
				}
				rb = z[0] + z[1] + z[2];
				for (int l = 0; l < 3; l++) {
					rb *= (z[l] + z[(l + 1) % 3] - z[(l + 2) % 3]);
				}
				if (rb > e) {
					r = z[0] * z[1] * z[2] / sqrt(rb);
					for (int l = 0; l < 3; l++) {
						w[l] = z[(l + 2) % 3] * z[(l + 2) % 3] + z[(l + 1) % 3] * z[(l + 1) % 3] - z[l] * z[l];
						w[l] *= z[l] * z[l];
					}
					rb = w[0] + w[1] + w[2];
					cx = (w[0] * x[0] + w[1] * x[1] + w[2] * x[2]) / rb;
					cy = (w[0] * y[0] + w[1] * y[1] + w[2] * y[2]) / rb;
					for (int l = 0; l < n; l++) {
						dx = xin[l] - cx;
						dy = yin[l] - cy;
						rd = sqrt(dx * dx + dy * dy);
						if (rd < r + e) g++;
					}
					if (g == n) {
						if (ans > r)ans = r;
					}
				}
			}
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			cx = (xin[i] + xin[j]) / 2;
			cy = (yin[i] + yin[j]) / 2;
			dx = xin[i] - cx;
			dy = yin[i] - cy;
			g = 0;
			r = sqrt(dx * dx + dy * dy);
			for (int l = 0; l < n; l++) {
				dx = xin[l] - cx;
				dy = yin[l] - cy;
				rd = sqrt(dx * dx + dy * dy);
				if (rd < r + e) g++;
			}
			if (g == n) {
				if (ans > r)ans = r;
			}
		}
	}
	printf("%.20lf\n", ans);
}

Measured memory_bytes: 128
<?php
//整数Nが与えられます。N!の正の約数の個数を10^9 + 7で割った余りを求めてください。
$n    = trim(fgets(STDIN));
$list = [];

// 6! = 2^1 3^1 2^2 5^1 2^1*3^1
// 6! = 2^4 3^2 5^1
for ($i = 2; $i <= $n; $i++) {
    $t = $i;
    for ($j = 2; $j * $j <= $i; $j++) {
        while ($t % $j === 0) {
            $list[$j] = isset($list[$j]) ? $list[$j] + 1 : 1;
            $t        = $t / $j;
        }
    }
    if ($t !== 1) {
        $list[$t] = isset($list[$t]) ? $list[$t] + 1 : 1;
    }
}
const MOD = 1000000007;
$res = 1;
foreach ($list as $value) {
    $res *= $value + 1;
    $res %= MOD;
}

print $res;


Measured memory_bytes: 4856
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;


const double EPS=-1e8;
typedef vector<int> vec;
typedef vector<vec>mat;

//Ax=b????§£??? A?????£?????????
//?§£???????????????????????§????????´????????????0??????????????????
vec gauss_jordan(const mat& A, const vec &b){
    int n=A.size();
    mat B(n,vec(n+1));
    REP(i,n){
        REP(j,n){
            B[i][j]=A[i][j];
        }
    }
    //??????A????????????b????????????????????????????????????
    REP(i,n)B[i][n]=b[i];
    
    REP(i,n){
        //??¨????????????????????°????????°?????¶???????????§????????????i??????????????£?????????
        int pivot =i;
        for(int j=i;j<n;j++){
            if(abs(B[j][i])>abs(B[pivot][i]))pivot=j;
        }
        swap(B[i],B[pivot]);
        
        //?§£????????????????????§??????
        if(abs(B[i][i])<EPS){
            cout<<"i="<<i<<endl;
           return vec();
        }
        //??¨????????????????????°????????°???1?????????
        //for(int j=i+1;j<=n;j++)B[i][j]/=B[i][i];
        REP(j,n){
            if(i!=j){
               //j??????????????????i??????????????°????¶????
               for(int k=i+1; k<=n; k++){
                   if(B[j][i]==1){
                      B[j][k] ^=(B[i][k]);
                   }
               }
            }
        }
    }
    vec x(n);
    //??????????????????b????§£?????????
    REP(i,n)x[i]=B[i][n];
    return x;
}

int main(){
    int m,n,d;
    while(cin>>m>>n>>d,m){
          int S[30][30];
          REP(i,n){
              REP(j,m){
                  cin>>S[i][j];
              }
          }
          mat A(n*m,vec(n*m));
          vec b(n*m);
          
          REP(i,n){
              REP(j,m){
                  REP(k,n){
                      REP(l,m){
                          if(abs(k-i)+abs(j-l)==0||abs(k-i)+abs(j-l)==d){
                               A[i*m+j][k*m+l]=1;
                          }else{
                               A[i*m+j][k*m+l]=0;
                          }
                      }
                  }
                  b[i*m+j]=S[i][j];
              }
          }
          /*REP(i,n*m){
              REP(j,n*m)cout<<A[i][j];
              cout<<b[i];
              cout<<endl;
          }*/
          vec c=gauss_jordan(A,b);
          REP(i,n){
              REP(j,m){
                  if(c[i*m+j]==1){
                     REP(k,n){
                         REP(l,m){
                             if(abs(k-i)+abs(j-l)==0||abs(k-i)+abs(j-l)==d){
                               S[k][l]=1-S[k][l];
                             }
                         }
                     }
                  }
              }
          }
          bool cc=true;
          REP(i,n){
              REP(j,m){
                  if(S[i][j]==1)cc=false;
              }
          }
          
          if(cc){
             cout<<1<<endl;
          }else{
             cout<<0<<endl;
          }
    }
    return(0);
}

Measured memory_bytes: 5936
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <string>
#include <set>
#include <vector>

using namespace std;

int N;
static const int N_MAX = 100000;
int a[N_MAX] = {0};
int main(){
    scanf("%d", &N);
    for (int i = 0; i < N; i++){
        int tmp;
        scanf("%d", &tmp);
        a[tmp]++;
    }
    int ans = 1;
    for (int i = 0; i < N_MAX; i++){
        if (a[i] == 0) continue;

        int count = a[i];
        if (0 <= i - 1 ){
            count += a[i-1];
        }
        if (i+1 < N) {
            count += a[i+1];
        }
        if (ans < count) ans = count;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;
lint p=998244353;
int main(){
  int N,K;
  cin>>N>>K;
  int L[K],R[K];
  REP(i,K){
    cin>>L[i]>>R[i];
  }
  lint dp[N],I[N];
  REP(i,N)dp[i]=0;
  dp[0]=1;
  dp[1]=-1;
  REP(i,N){
    if(i!=0)dp[i]+=dp[i-1];
    dp[i]%=p;
    if(dp[i]<0)dp[i]+=p;
    // REP(j,N)cerr<<dp[j]<<" ";
    // cerr<<endl;
    REP(k,K){
      if(i+L[k]<N){
        dp[i+L[k]]+=dp[i];
        dp[i+L[k]]%=p;
      }
      if(i+R[k]+1<N){
        dp[i+R[k]+1]-=dp[i];
        dp[i+L[k]+1]%=p;
      }
    }
  }
  cout<<dp[N-1]<<endl;
  return 0;
}


Measured memory_bytes: 5128
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()


def main():
    n,m = LI()
    a = LI()
    r = 0
    i = 0
    while True:
        mi = ma = a[i%n]
        for j in range(1,m):
            t = a[(i+j)%n]
            if mi > t:
                mi = t
            elif ma < t:
                ma = t
        r += ma-mi
        i += m
        if i % n == 0:
            break
    return r

print(main())

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

int main() {
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  
  rep(i,ty-sy) cout << "U";
  rep(i,tx-sx) cout << "R";
  rep(i,ty-sy) cout << "D";
  rep(i,tx-sx) cout << "L";

  cout << "L";
  rep(i,ty-sy+1) cout << "U";
  rep(i,tx-sx+1) cout << "R";
  cout << "D";
  cout << "R";
  rep(i,ty-sy+1) cout << "D";
  rep(i,tx-sx+1) cout << "L";
  cout << "U" << endl;

}

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

int main(){
  int N;
  cin >> N;
  
  vector<int> Dnum(N, 0), D(N);
  for (int i = 0; i < N; i++){
    int num;
    cin >> num;
    
    D.at(i) = num;
    Dnum.at(num)++;
  }
  
  if (Dnum.at(0) != 1 || D.at(0) != 0){
    cout << "0" << endl;
    exit(0);
  }
  
  ll ans = 1;
  for (int i = 0; i < N; i++){
    if (D.at(i) == 0){
      continue;
    }
    ans *= Dnum.at(D.at(i) - 1);
    ans %= 998244353;
  }

  cout << ans << endl;
}

Measured memory_bytes: 4300
#include<iostream>
//----NEO----SOLUTION------//
using namespace std;
int main(){
	int n,a=0,b=0,c=0;
	cin>>n;
	for(int i=0;i<n;i++){
		int z;cin>>z;
		if(z%4==0)c++;
		else if(z%2==0)b++;
		else a++;
	}
	if(c>=a||(b==0&&c+1>=a))cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main (void) {
    int n, i;
    scanf("%d", &n);
    int a[n];
    double sum_of_recip = 0;
    for (i = 0; i < n; i++) {
        scanf("%d", &a[i]);
        sum_of_recip += (double) 1 / a[i];
    }

    printf("%.10lf\n", 1 / sum_of_recip);
    return 0;
}

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

using namespace std;

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

    string T[4] = {"dreamer","dream","eraser", "erase"};

    int N = S.length();
    for(int i=N-1;i>=0;){
        bool found = false;
        for(int k=0;k<4;k++){
            if((int)(i-T[k].length())+1 >= 0){
                string Ssub = S.substr(i-T[k].length()+1, T[k].length());
                if(Ssub == T[k]){
                    i -= T[k].length();
                    found = true;
                    break;
                }
            }
        }
        if(!found){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 512
def comp(s, t):
    if len(s) != len(t) - 1:
        return -1
    else:
        for i in range(len(s)):
            if s[i] != t[i]:
                return -1
        return 0
s = input()
t = input()
if comp(s, t) == -1:
    print('No')
else:
    print('Yes')
            
    

Measured memory_bytes: 9116
import java.util.*;
import static java.lang.System.*;

public class Main {

	Scanner sc = new Scanner(in);
	
	void run() {
		int d = sc.nextInt(), n = sc.nextInt();
		int[] t = new int[d];
		int[] a = new int[n];
		int[] b = new int[n];
		int[] c = new int[n];
		for (int i = 0; i < d; i++)
			t[i] = sc.nextInt();
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
			c[i] = sc.nextInt();
		}
		
		int INF = -1;
		int[][] dp = new int[d][n];
		for (int i = 0; i < n; i++) {
			if (!(a[i] <= t[0] && t[0] <= b[i]))
				dp[0][i] = INF;
		}
		
		for (int i = 1; i < d; i++) {
			for (int j = 0; j < n; j++) {
				if (!(a[j] <= t[i] && t[i] <= b[j]))
					dp[i][j] = INF;
				else {
					for (int k = 0; k < n; k++) {
						if (dp[i-1][k] != INF) {
							dp[i][j] = Math.max(dp[i][j], dp[i-1][k] + Math.abs(c[j]-c[k]));
						}
					}
				}
			}
		}
		int res = -1;
		for (int i = 0; i < n; i++) {
			res = Math.max(res, dp[d-1][i]);
		}
		out.println(res);
	}
	
	public static void main(String[] args) {
		new Main().run();
	}

}

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

namespace VirtualAtCorder
{
    class Program
    {



        static void Main(string[] args)
        {
            string[] inputs = Console.ReadLine().Split(' ');

            bool calc = false;

            string output = "";

            calc = Calc(inputs);

            for (int i = 0; i < inputs.Length; i++)
            {
                if(inputs[0].Length > 10)
                {
                    calc = false;
                    break;
                }
            }

            output = (calc) ? "YES" : "NO";

            Console.WriteLine(output);

            Console.ReadKey();
        }

        static bool Calc(string[] inputs)
        {
            bool result = false;

            if (inputs[0].Last() == inputs[1].First())
            {
                result = true;
            }
            else
            {
                return false;
            }
            if (inputs[1].Last() == inputs[2].First())
            {
                result = true;
            }
            else
            {
                result = false;
            }

            return result;
        }


    }
}


Measured memory_bytes: 13268
#include "bits/stdc++.h"
using namespace std;
#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
typedef long long ll;

const int INF = 1e9 + 7;
const long long LLINF = 1e18;

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

    int j;
    REP(i, 0, n){
        bool flag=true;
        REP(j, 0, n-i){
            if(s[i+j]!=t[j]) flag=false;
        }
        if(flag){
            cout<<n+i<<endl;
            return 0;
        }
    }
    cout<<2*n<<endl;
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
 
#define $(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define endl '\n'
#define x first
#define y second
#define int long long
#define double long double
#define pii pair<int, int>
#define pb push_back
#define vec vector
#define beg begin
#define dbg(x) cout << #x << " = " << x << endl;
 
template<class T> ostream& operator<<(ostream &str, vector<T> &a) {
    for (auto &i : a) {
        str << i << " ";
    }
    return str;
}
 
template<class T> istream& operator>>(istream &str, vector<T> &a) {
    for (auto &i : a) {
        str >> i;
    }
    return str;
}
 
template<class T> ostream& operator<<(ostream &str, pair<T, T> &a) {
    str << a.first << " " << a.second;
    return str;
}
 
template<class T> istream& operator>>(istream &str, pair<T, T> &a) {
    str >> a.first >> a.second;
    return str;
}
 
void solve(); signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    srand(time(0));
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout.setf(ios::fixed); cout.precision(6);
    solve();    
    return 0;   
}
 
const int MOD = 1e9 + 7, MAXN = 5e5 + 10, INF = 2e9 + 10, BASE = 37; 

void solve() {
    int n;
    cin >> n;
    int ans = 0;

    for (int i = 0; i < n - 1; ++i) {
        int u, v;
        cin >> u >> v;
        if (v < u) swap(u, v);
        int cnt1 = u, cnt2 = n - v + 1;
        ans += (cnt1 * cnt2);
    }

    int tmp = 0;
    for (int i = 1; i <= n; ++i) {
        tmp += i * (n - (i - 1));
    }

    cout << tmp - ans << endl;
}

Measured memory_bytes: 3632
N, x = map(int, input().split())
a_list = list(map(int, input().split()))
count = 0
if a_list[0] > x:
  count = a_list[0] - x
  a_list[0] = x

for i in range(N-1):
  add = max(a_list[i] + a_list[i+1] - x, 0)
  a_list[i+1] -= add
  count += add

print(count)

Measured memory_bytes: 14540
/*  -*- coding: utf-8 -*-
 *
 * d.cc: D - Dice in Line
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 200000;

/* typedef */

/* global variables */

int ps[MAX_N];

/* subroutines */

inline double expv(int p) { return 0.5 * (p + 1); }

/* main */

int main() {
  int n, k;
  scanf("%d%d", &n, &k);

  for (int i = 0; i < n; i++) scanf("%d", ps + i);

  double maxsum = 0.0, sum = 0.0;
  for (int i = 0; i + 1 < k; i++) sum += expv(ps[i]);

  for (int i = 0, j = k - 1; j < n; i++, j++) {
    sum += expv(ps[j]);
    if (maxsum < sum) maxsum = sum;
    sum -= expv(ps[i]);
  }

  printf("%.12lf\n", maxsum);
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string.h>
typedef long long ll;

#define MAX(x, y)	(((x) > (y))? (x) : (y))
#define MIN(x, y)	(((x) < (y))? (x) : (y))
#define ABS(x)		(((x) < 0)? (-1*(x)) : (x))
#define REPI(x,y)	for (int i=(x);i<(y);i++)
#define REPJ(x,y)	for (int j=(x);j<(y);j++)
#define MEMCLR(X)	memset((X),0,sizeof((X)))

using namespace std;
typedef vector<vector<pair<int, int>>> G;
typedef pair<int, int> P;

int i,j,N,A,B;

int main() {
	cin >> N >> A >> B;
		
	cout << (MIN(N*A,B));
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    long long k;
    cin >> k;
    if (k%7 == 0) {
        k /= 7;
    }
    if (k == 1) {
        cout << 1 << endl;
        return 0;
    }
    long long a[k];
    a[0] = 1;
    long long amari = a[0];
    for (long long i=1; i<k; i++) {
        a[i] = (a[i-1]*10) % k;
        if (a[i] == 0) {
            cout << -1 << endl;
            return 0;
        } else {
            amari = (amari+a[i])%k;
            if (amari == 0) {
                cout << i+1 << endl;
                return 0;
            }
        }
    }
    cout << -1 << endl;
}

Measured memory_bytes: 11384
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)


int main(){
    vector<int> a(3),b(3);

    vector<int> mati(4);

    int dcount=0;

    for(int i = 0;i < 3;i++){
        cin >> a.at(i) >> b.at(i);
    }

    for(int i = 0;i < 4;i++){
        mati.at(i) = 0;
    }

    for(int i = 0;i < 3;i++){
        mati.at(a.at(i) -1)++;
        mati.at(b.at(i) -1)++;
    }

    for(int i = 0;i < 4;i++){
        if(mati.at(i) == 2){
            dcount++;
        }
    }

    if(dcount == 2)
        cout << "YES" << endl;
    else
    {
        cout << "NO" << endl;
    }
    

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int arr[110][110];
int main()
{
	int n,m;
	cin>>m>>n;
	arr[0][0]=1;
	for(int i=1;i<=100;++i)
	{
		for(int j=0;j<=i;++j)
		arr[i][j]=arr[i-1][j]+arr[i-1][j-1];
	}
	cout<<arr[m][2]+arr[n][2]<<endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
p = [int(i) for i in input().split()]

cnt = 0
for i in range(1, n - 1):
    if (p[i - 1] < p[i] and p[i] < p[i + 1]):
        cnt += 1
    if (p[i - 1] > p[i] and p[i] > p[i + 1]):
        cnt += 1
print(cnt)


Measured memory_bytes: 3060
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

// Test Code
macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
}

fn main() {
    println!("{}", solve(&stdin!()));
}

fn solve(src: &str) -> String {
    input!{
        source = src,
        h: usize
    }
    let res = battle(h);

    return res.to_string();
}

fn battle(h: usize) -> usize {
    if h == 1 { return 1; }

    let half = h / 2;
    let c = battle(half);
    return c * 2 + 1;        
}


Measured memory_bytes: 4352
/*
    Created by Ezio112
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define inf ll(10e16)
#define mod ll(10e8+7)
#define ff first
#define ss second
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);


    ll t;
    //cin>>t;
    t=1;
    while(t--)
    {
        ll n,m,x;
        cin>>n>>m>>x;
        ll ar[n][m];
        ll cost[n];
        for(ll i=0;i<n;++i)
        {
            cin>>cost[i];
            for(ll j=0;j<m;++j)
            cin>>ar[i][j];
        }

        ll mn=inf;

        for(ll i=1;i<(1<<n);++i)
        {
            vector<ll> books;
            vector<ll> good(m);
            for(ll j=0;j<n;++j)
            {
                if((1<<j)&i)
                books.push_back(j);
            }
            for(auto x:books)
            {
                for(ll j=0;j<m;++j)
                {
                    good[j]+=ar[x][j];
                }
            }
            ll flag=true;
            for(ll j=0;j<m;++j)
            {
                if(good[j]<x)
                {
                    flag=false;
                    break;
                }
            }
            if(flag)
            {
                ll sum=0;
                for(auto x:books)
                sum+=cost[x];
                mn=min(mn,sum);
            }
        }
        if(mn==inf)
        cout<<-1;
        else
        cout<<mn;
    }
    return 0;
}


Measured memory_bytes: 3660
using System;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            var n = input[0];
            var m = input[1];
            var c = input[2];
            var b = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            var count = 0;
            for (var i = 0; i < n; i++)
            {
                var a = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
                var sum = c;
                for(var j = 0; j < m; j++)
                {
                    sum += a[j] * b[j];
                }

                if (sum > 0)
                {
                    count++;
                }
            }

            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 13268
#include <vector>
#include <iostream>
#include <set>
#include <cstdio>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <ctime>
#include <cmath>
#include <complex>
#include <algorithm>
#include <tuple>
#include <algorithm>
#include <limits>
#include <map>
#include <valarray>
#include <list>

using namespace std;

typedef long long ll;

int main() {
    int t;
    cin >> t;
    while (t--) {
        string s1, s2;
        cin >> s1 >> s2;
        if (s1 == "0" && s2 == "0") {
            cout << "0" << endl;
            continue;
        }
        reverse(s1.begin(), s1.end());
        reverse(s2.begin(), s2.end());
        int n = max(s1.size(), s2.size()) + 1;
        for (int i = s1.size(); i < n; i++) {
            s1 += '0';
        }
        for (int i = s2.size(); i < n; i++) {
            s2 += '0';
        }
        string res;
        int b = 0;
        for (int i = 0; i < max(s1.size(), s2.size()); i++) {
            int u = s1[i]-'0'+s2[i]-'0'+ b;
            b = (u >= 10); u %= 10;
            res += u + '0';
        }
        reverse(res.begin(), res.end());
        string res2;
        int j = 0;
        while (res[j] == '0') j++;
        for (; j < res.size(); j++) {
            res2 += res[j];
        }
        if (res2.size() > 80) {
            cout << "overflow" << endl;
        } else {
            cout << res2 << endl;
        }
    }
}

Measured memory_bytes: 1216
import sys
from collections import defaultdict
sys.setrecursionlimit(10**6)

def main():
    input = sys.stdin.readline
    MOD = 10**9 + 7
    N, K = map(int, input().split())
    G = defaultdict(list)
    for _ in range(N-1):
        a, b = map(int, input().split())
        a, b = a-1, b-1

        G[a].append(b)
        G[b].append(a)

    visited = [False] * N
    def dfs(n, ans):
        child = 1
        if n == 0:
            child = 0

        visited[n] = True
        for c in G[n]:
            if visited[c]:
                continue
            ans = (ans * (K - 1 - child)) % MOD
            ans = dfs(c, ans)
            child += 1

        return ans

    return dfs(0, K)


if __name__ == '__main__':
    print(main())


Measured memory_bytes: 114272
#include<bits/stdc++.h>
#define mod (long long)1000000007
using namespace std;
template<typename T>
inline void read(T &x)
{
	x=0;
	int f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=getchar();
	x*=f;
	return;
}
template<typename T>
void write(T x)
{
	if(x<0) putchar('-'),x=-x;
	if(x>=10) write(x/10);
	putchar(x%10+'0');
	return;
}
long long ext_gcd(long long a,long long b,long long &x,long long &y)
{
	if(b==0)
	{
		x=1,y=0;
		return a;
	}
	long long ret=ext_gcd(b,a%b,y,x);
	y-=x*(a/b);
	return ret;
}
long long inverse(long long a)
{
	long long x,y;
	ext_gcd(a,mod,x,y);
	if(x<0) x+=mod;
	return x;
}
long long n,k;
long long a[100010];
long long b[100010];
long long ans=0;
int main()
{
	read(n),read(k);
	if(k==1)
	{
		cout<<0<<endl;
		return 0;
	}
	for(long long i=1;i<=n;i++) read(a[i]);
	sort(a+1,a+n+1);
	long long x=1;
	b[k]=x; 
	for(long long i=k+1;i<=n;i++)
	{
		x*=(i-2);x%=mod;
		x*=inverse(i-k);x%=mod;
		b[i]=b[i-1]+x,b[i]%=mod;
	}
	for(long long i=1;i<=n-k+1;i++) ans-=b[n-i+1]*a[i],ans%=mod;
	for(long long i=k;i<=n;i++) ans+=b[i]*a[i],ans%=mod;
	printf("%lld\n",ans%mod);
	return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>

using namespace std;

int main(){
    int H,W;
    cin>>H>>W;
    vector<string> S(H);
    for(int i=0;i<H;i++){
        cin>>S[i];
    }
    vector<vector<int> > cnt(H,vector<int>(W));

    for(int i=0;i<H;i++){
        vector<int> check(W);
        for(int j=0;j<W;j++){
            if(S[i][j]=='#')continue;
            if(check[j])continue;
            int l=0;
            while(j+l<W){
                if(S[i][j+l]=='#')break;
                l++;
            }
            for(int k=0;k<l;k++){
                cnt[i][j+k] += l;
                check[j+k] = 1;
            }
        }
    }
    for(int i=0;i<W;i++){
        vector<int> check(H);
        for(int j=0;j<H;j++){
            if(S[j][i]=='#')continue;
            if(check[j])continue;
            int l=0;
            while(j+l<H){
                if(S[j+l][i]=='#')break;
                l++;
            }
            for(int k=0;k<l;k++){
                cnt[j+k][i] += l;
                check[j+k] = 1;
            }
        }
    }
    int ans=0;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            ans = max(ans,cnt[i][j]-1);
        }
    }
    cout<<ans;
}

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

typedef long long ll;

int main(){

    ll n, k; scanf("%lld\n%lld\n", &n, &k);

    ll ans = 1;

    for(int i=1; i<=n; i++){

        ll tmp1 = ans;
        ll tmp2 = ans;

        tmp1 *= 2;
        tmp2 += k;

        ans = min(tmp1, tmp2);

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

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
  long long int n;
  cin>>n;
  vector<pair<long long int,long long int>> hoge(n);
  for(int i=0; i<n; i++){
    long long int s,t;
    cin>>s>>t;
    hoge.at(i).first=s+t;
    hoge.at(i).second=s-t;
  }

  sort(hoge.begin(),hoge.end());
  long long int ans=1;
  long long int last=hoge.at(0).first;
  for(long long int i=1; i<n; i++){
    if(hoge.at(i).second<last){
      
    }else{
      ans++;
      last=hoge.at(i).first;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define ll long long int
#define ld long long double
#define vii vector<ll> 
#define pb push_back
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
const int MOD = 1e9 + 7, N = 1e5 + 3;
 
int main(){
    fast;
    ll n, k;
    cin >> n >> k;
    ll a[n];
    for(int i = 0; i < n; ++i)
        cin >> a[i];
    sort(a, a+n);
    ll sum = 0;
    int j = 0;
    while(k--){
        sum += a[j];
        ++j;
    }
    cout << sum;
    return 0;
}

Measured memory_bytes: 3652
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    a, b = map(int, input().split())
    ans = 0
    for _ in range(2):
        if a > b:
            ans += a
            a -= 1
        else:
            ans += b
            b -= 1

    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include <iostream>
#include <vector>
#include <queue>

int main(){
    std::priority_queue<int, std::vector<int>, std::greater<>> red, green;
    int X, Y, A, B, C;
    std::cin >> X >> Y >> A >> B >> C;
    while(A--){
        int apple;
        std::cin >> apple;
        if(red.size() < X){
            red.emplace(apple);
        }else if(red.top() < apple){
            red.pop();
            red.emplace(apple);
        }
    }
    while(B--){
        int apple;
        std::cin >> apple;
        if(green.size() < Y){
            green.emplace(apple);
        }else if(green.top() < apple){
            green.pop();
            green.emplace(apple);
        }
    }
    while(C--){
        int apple;
        std::cin >> apple;
        if(red.size() < X){
            red.emplace(apple);
            continue;
        }
        if(green.size() < Y){
            green.emplace(apple);
            continue;
        }
        if(red.top() < green.top()){
            if(red.top() > apple)continue;
            red.pop();
            red.emplace(apple);
        }else{
            if(green.top() > apple)continue;
            green.pop();
            green.emplace(apple);
        }
    }
    long long sum = 0;
    while(!red.empty()){
        sum += red.top();
        red.pop();
    }
    while(!green.empty()){
        sum += green.top();
        green.pop();
    }
    std::cout << sum;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
# define ll  long long  int
# define ld  long double
# define pb push_back
# define pp pop_back
# define ff first
# define ss second
# define mp make_pair
# define ac accumulate
# define mod 1000000007
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;     
  
    x = x % p;  
  
    while (y > 0) 
    { 
      
        if (y & 1) 
            res = (res*x) % p; 
  
      
        y = y>>1;
        x = (x*x) % p;   
    } 
    return res; 
} 
bool sortinrev(const pair<ll,ll> &a,  
               const pair<ll,ll> &b) 
{ 
       return (a.first > b.first); 
}
typedef pair<int,int> ii;
// bool cmp(ii a,ii b)
// {
// 	if(a.ff==b.ff)
// 	{
// 		return a.ss>b.ss;
// 	}
// 	else
// 		a.ff<b.ff;
// }
   ll dp[27][200004]={0};

int  main()
{
//    #ifndef ONLINE_JUDGE
//    freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
//    #endif
   IOS;
 	ll n;
 	cin>>n;
 	ll arr[n+2];
 	ll cnt=0,p=1;
 	for(ll i=1;i<=n;i++)
 		cin>>arr[i];
 	for(ll i=1;i<=n;i++)
 	{
 		ll j;
 		//cout<<i<<endl;
 		for( j=i;j<=n;j++)
 		{
 			if(arr[j]==p)
 			{
 				p++;
 				cnt++;
 				i=j;
 				break;
 			}
 		}
 		if(j==n+1)
 			break;
 	}
 	ll k=n-cnt;
 	if(cnt==0)
 	{
 		cout<<"-1";
 		return 0;
 	}
 	cout<<k;
}


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

int main() {
  int N, a[3000];
  cin >> N;
  long ans = 0;
  for(int i = 0;i < N; i++){
    cin >> a[i];
    ans += a[i];
  }
  cout << ans - N << endl;
}

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


int main()
{
    int n,a,las=0;
    scanf("%d",&n);
    cin>>las;
    long long ans=0;
    for(int i=2;i<=n;++i) {
        scanf("%d",&a);
        if(a<las) ans+=las-a;
        else las=a;
    }
    cout<<ans;
}

Measured memory_bytes: 3660