akhauriyash/Code-Regression huggingface dataset:
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
int n, pre[2009], nxt[2009], val[2009], v1[2009], v2[2009]; string a, b;
int main() {
	cin >> a >> b; n = a.size();
	if (b.find('1') == string::npos) cout << (a == b ? 0 : -1) << endl;
	else {
		int ret = 1 << 30;
		for (int i = 0; i < 2; i++) {
			for (int j = 0; j < n; j++) {
				if (b[j] == '1') {
					a = a.substr(j) + a.substr(0, j);
					b = b.substr(j) + b.substr(0, j);
					break;
				}
			}
			for (int j = 0; j < n; j++) pre[j] = (b[j] == '1' ? 0 : pre[j - 1] + 1);
			for (int j = n - 1; j >= 0; j--) nxt[j] = (b[j] == '1' ? 0 : nxt[j + 1] + 1);
			fill(val, val + n, 0);
			for (int j = 0; j < n; j++) {
				if (a[j] == '0') pre[j] = nxt[j] = 0;
				val[pre[j]] = max(val[pre[j]], nxt[j]);
			}
			for (int j = n - 1; j >= 0; j--) val[j] = max(val[j], val[j + 1]);
			fill(v1, v1 + n, 1 << 30);
			fill(v2, v2 + n, 1 << 30);
			for (int j = 1; j <= n; j++) {
				v1[val[j]] = min(v1[val[j]], (j - 1) * 2 + val[j] * 2);
				v2[val[j]] = min(v2[val[j]], (j - 1) * 2);
			}
			for (int j = n - 2; j >= 0; j--) v1[j] = min(v1[j], v1[j + 1]);
			int cl = 1 << 30;
			for (int j = 0; j < n; j++) {
				int cnt = 0;
				for (int k = 0; k < n; k++) {
					if (a[k] != b[(j + k) % n]) cnt++;
				}
				cl = min(cl, v2[j]);
				ret = min(ret, cnt + cl + j);
				ret = min(ret, cnt + v1[j] - j);
			}
			reverse(a.begin(), a.end());
			reverse(b.begin(), b.end());
		}
		cout << ret << endl;
	}
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
count = 0
back = 0
for i in range(0, n):
  count += b[a[i]-1]
  if back+1 == a[i] and back != 0:
    count += c[a[i]-2]
  back = a[i]
print(count)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
#define MOD 998244353LL
#define endl "\n"

ll modbeki(ll x, ll n){
  ll res = 1LL;
  while(n > 0){
    if(n & 1){
      res *= x % MOD;
      res %= MOD;
    }
    x = x * x % MOD;
    n >>= 1;
  }
  return res % MOD;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N;
  cin >> N;
  vll D(N);
  bool ng = false;
  vll count(N, 0);
  for(int i = 0; i < N; i++){
    cin >> D.at(i);
    count.at(D.at(i))++;
    if((i == 0 && D.at(i) != 0) || (i != 0 && D.at(i) == 0)) ng = true;
  }
  if(ng){
    cout << 0 << endl;
    return 0;
  }
  ll counter = 1;
  ll ans = 1LL;
  for(int i = 1; i < N; i++){
    if(count.at(i) == 0) break;
    ans *= modbeki(count.at(i-1), count.at(i));
    ans %= MOD;
    counter += count.at(i);
  }
  if(counter == N) cout << ans << endl;
  else cout << 0 << endl;
}

Measured memory_bytes: 1792
def dist (s1,s2):
    x1=s1[0]
    y1=s1[1]
    x2=s2[0]
    y2=s2[1]
    a=(x1-x2)**2+(y1-y2)**2
    return pow(a,0.5)
arr=[]
n=int(input())
for _ in range(n):
    inp=list(map(int,input().split()))
    arr.append((inp[0],inp[1]))
ans=0
for i in range(len(arr)):
    for j in range(len(arr)):
        ans+=dist(arr[i],arr[j])
print (ans/n)

Measured memory_bytes: 9324
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>

using namespace std;
using ll = long long int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i, a, b)  for(int i = (a); i < (b) ; i++)
#define pb push_back
#define SORT(v,n) sort(v, v+n)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define elif else if
#define itn ll
#define int ll
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;

class Node {
public:
	int location;
	int p, l, r;
	Node() {};
};

class Point {
public:
	int id, x, y;
	Point(){}
	Point(int id, int x, int y) : id(id),x(x),y(y){}
	bool operator < (const Point& p) const {
		return id < p.id;
	}
	void Print() {
		cout << id << '\n';
	}
};


static const int MAX = 1000000;
static const int NIL = -1;
int N;
Point P[MAX];
Node T[MAX];
int np;

bool lessX(const Point& p1, const Point& p2) { return p1.x < p2.x;}
bool lessY(const Point& p1, const Point& p2) { return p1.y < p2.y;}

int makeKDTree(int l, int r, int depth) {
	if (!(l < r)) return NIL;
	int mid = (l + r) / 2;
	int t = np++;
	if (depth % 2 == 0) {
		sort(P + l, P + r, lessX);
	}
	else {
		sort(P + l, P + r, lessY);
	}
	T[t].location = mid;
	T[t].l = makeKDTree(l, mid, depth + 1);
	T[t].r = makeKDTree(mid + 1, r, depth + 1);
	return t;
}

void find(int v, int sx, int tx, int sy, int ty, int depth, vector<Point>& ans) {
	int x = P[T[v].location].x;
	int y = P[T[v].location].y;
	int id = P[T[v].location].id;
	if(sx <= x && x <= tx && sy <= y && y <= ty){
		ans.pb(P[T[v].location]);
	}

	if (depth % 2 == 0) {
		if (T[v].l != NIL) {
			if (sx <= x)
				find(T[v].l, sx, tx, sy, ty, depth+1, ans);
		}
		if (T[v].r != NIL) {
			if(x <= tx)
				find(T[v].r, sx, tx, sy, ty, depth + 1, ans);
		}
	}
	else {
		if (T[v].l != NIL) {
			if(sy <= y)
				find(T[v].l, sx, tx, sy, ty, depth + 1, ans);
		}
		if (T[v].r != NIL) {
			if (y <= ty)
				find(T[v].r, sx, tx, sy, ty, depth + 1, ans);
		}
	}
}

signed main() {
	ios::sync_with_stdio(false);
	int x, y, i, j;
	cin >> N;
	rep(i, N) {
		cin >> x >> y;
		P[i] = Point(i, x, y);
		T[i].l = T[i].r = T[i].p = NIL;
	}
	np = 0;
	int root = makeKDTree(0, N, 0);
	int q;
	cin >> q;
	vector<Point> ans;
	int sx, tx, sy, ty;
	rep(i, q) {
		cin >> sx >> tx >> sy >> ty;
		ans.clear();
		find(root, sx, tx, sy, ty, 0, ans);
		sort(ALL(ans));
		rep(j, ans.size()) {
			ans[j].Print();
		}
		cout << '\n';
	}
	return 0;
}


Measured memory_bytes: 29712
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

const ll MOD = 1e9 + 7;

class Matrix{
public:
  int m, n;
  vector<vector<ll>> a;

  Matrix(int s, int t){
    m = s;
    n = t;
    a = vector<vector<ll>>(m, vector<ll>(n, 0));
  }

  void print(){
    for(int i = 0; i < m; i++){
      for(int j = 0; j < n; j++){
        cout << a[i][j] << " ";
      }
      cout << endl;
    }
  }
};

Matrix mulMatrix(Matrix m1, Matrix m2){
  int m = m1.m;
  int n = m2.n;
  int len = m1.n;

  Matrix ans = Matrix(m, n);
  for(int i = 0; i < m; i++){
    for(int j = 0; j < n; j++){
      for(int k = 0; k < len; k++){
        ans.a[i][j] += m1.a[i][k] * m2.a[k][j];
        ans.a[i][j] %= MOD;
      }
    }
  }

  return ans;
}

Matrix mulMatrix_pow(Matrix M, ll N){
  if(N == 1) return M;
  else{
    if(N % 2 == 0){
      Matrix tmp = mulMatrix_pow(M, N / 2);
      return mulMatrix(tmp, tmp);
    } else {
      Matrix tmp = mulMatrix_pow(M, (N - 1) / 2);
      return mulMatrix(M, mulMatrix(tmp, tmp));
    }
  }
}

//==================================================
int main(){
  int N;
  ll K;
  cin >> N >> K;

  Matrix A = Matrix(N, N);
  for(int i = 0; i < N; i++){
    for(int j = 0; j < N; j++){
      cin >> A.a[j][i];
    }
  }

  //ANS = A^k * B
  Matrix B = Matrix(N, 1);
  for(int i = 0; i < N; i++) B.a[i][0] = 1;
  Matrix ANS = mulMatrix(mulMatrix_pow(A, K), B);

  ll ans = 0;
  for(int i = 0; i < N; i++) ans += ANS.a[i][0];

  cout << ans % MOD << endl;
  return 0;

}


Measured memory_bytes: 1664
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! 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")
    };
}
 
//
// # Examples
//
// # integers
// input! { n: usize, m: usize, ... }
//
// # array
// input! { n: usize, v: [u64; n], }
//
// # matrix
// input! { n: usize, m: usize, mat: [[]] }
//
// # string
// input! { s: chars }
//
// 3 4
// ####
// #..#
// .#.#
//
// input!{
//     h: usize,
//     w: usize,
//     board: [chars; h],
// }
 
// https://practice.contest.atcoder.jp/tasks/practice_1

fn main() {
    input! {
        n: usize
    }

    let mut dp = vec![vec![vec![vec![0;4];4];4]; n+1];
    dp[0][3][3][3] = 1;
    for len in 0..n {
        for i in 0..4 { // 1文字前
            for j in 0..4 { // 2文字前
                for k in 0..4 { // 3文字前
                    for new in 0..4 {
                        if new == 2 && i == 1 && j == 0 { continue; } 
                        if new == 2 && i == 0 && j == 1 { continue; } 
                        if new == 1 && i == 2 && j == 0 { continue; } 
                        if new == 2 && i == 1 && k == 0 { continue; } 
                        if new == 2 && j == 1 && k == 0 { continue; } 
                        dp[len+1][new][i][j] += dp[len][i][j][k];
                        dp[len+1][new][i][j] %= 1_000_000_007
                    }
                }
            }
        }
    }
    let mut ans = 0;
    for i in 0..4 { // 1文字前
        for j in 0..4 { // 2文字前
            for k in 0..4 { // 3文字前
                ans += dp[n][i][j][k];
                ans %= 1_000_000_007;
            }
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstdlib>

using namespace std;
//DP用
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;
}

//a^n mod を計算する関数
long long modpow(long long a,long long n,long long mod) {
    long long res = 1;
    while(n > 0) {
        if(n % 2 == 1) {
            res = res * a % mod;
        }
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//a^(-1) mod すなわちaの逆元を返す関数
long long modinv(long long a,long long mod) {
    return modpow(a,mod-2,mod);
}

//最大公約数をを返す関数
long long gcd (long long a,long long b) {
    if(a % b == 0) {
        return b;
    }else {
        return (gcd(b,a%b));
    }
}

const long long INF = 1LL << 60;
const long long P = 1000000007;

//nCkを求める関数
long long conbi (long long n,long long k) {
    long long res = 1;
    long long inv;
    for(long long i = n-k+1; i <= n; i++) {
        res *= i;
        res %= P;
    }
    for(long long i = 1; i <= k; i++) {
        inv = modinv(i,P);
        res *= inv;
        res %= P;
    }
    return res;
}

int main() {
    int a,b,h;
    cin >> a >> b >> h;
    cout << (a+b)*h/2;
    return 0;
}


Measured memory_bytes: 256
Q=int(input())
LR=[]
for i in range(Q):
    LR.append(list(map(int,input().split())))
L=[]
R=[]
for i in range(Q):
    L.append(LR[i][0])
    R.append(LR[i][1])

def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

PL=primes(10**5)
LN=[]
for i in PL:
    if (i+1)//2 in PL:
        LN.append(i)

A=[0]*10**5
for i in LN:
    A[i]+=1

for i in range(1,10**5):
    A[i]+=A[i-1]
    
for i in range(Q):
    print(A[R[i]]-A[L[i]-1])

Measured memory_bytes: 33184
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e18;
template<typename T> void cmax(T &a, T b) { a = max(a, b); }
template<typename T> void cmin(T &a, T b) { a = min(a, b); }

signed main() {
  string s;
  cin >> s;
  stack<char> st;
  int ans = 0;
  rep(i, s.size()) {
    if (st.empty()) {
      st.push(s[i]);
    } else {
      char t = st.top();
      if (t == '0' && s[i] == '1' || t == '1' && s[i] == '0') {
        ans += 2;
        st.pop();
      } else {
        st.push(s[i]);  
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 512
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
	mod            = 998244353
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

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

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

func nextInt4() (int, int, int, int) {
	return nextInt(), nextInt(), nextInt(), nextInt()
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	a, b, c, d := nextInt4()

	dp := make([][]int, c+1)
	for i := range dp {
		dp[i] = make([]int, d+1)
	}

	dp[a][b] = 1
	for i := a; i <= c; i++ {
		for j := b; j <= d; j++ {
			dp[i][j] += (dp[i-1][j] * j) % mod
			dp[i][j] += (dp[i][j-1] * i) % mod
			dp[i][j] -= (dp[i-1][j-1] * (i - 1) * (j - 1)) % mod
			dp[i][j] = (dp[i][j] + mod) % mod
		}
	}

	puts(dp[c][d])
}


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

using namespace std;

typedef long long ll;

#define MOD (int)1e9+7
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>b;--i)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()

ll powM(ll a,ll b,ll m )
{ 
  a%=m;
  ll ans=1;
  while(b>0)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }

return ans;
}

ll c(ll a,ll b)
{
  if(a==0)return b==0?1:0;

if(b>a)return 0;

  ll val=1;
ll fac=1;
for(int i=1;i<=b;i++)fac*=i;
for(int i=a;i>=a-b+1;i--)val*=i;

  return val/fac;

}

ll f(ll n)
{
  ll ans=1LL;
  while(ans<=n)ans<<=1;

return ans;
}

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


    ll n;cin>>n;

 vl dp(101,0);

 for(ll i=1;i<=100;i++)
 {
  if(i==4||i==7)dp[i]=1;
  else 
  {
    ll temp1=max(i-4,0LL);
    ll temp2=max(i-7,0LL);
     if(dp[temp1]||dp[temp2])dp[i]=1;

  }
 }

 if(dp[n])cout<<"Yes"<<"\n";
 else cout<<"No"<<"\n";

return 0;

}


Measured memory_bytes: 256
object Main extends App {
  val amount = Array(500,100,50)
  val in = Iterator.continually(io.StdIn.readLine.toInt)
    .take(4).toArray

  val ans = {
      for {
        i <- 0 to in(0)
        if amount(0)*i <= in(3)
        j <- 0 to in(1)
        if amount(1)*j <= in(3)
        k <- 0 to in(2)
      } yield  amount(0)*i + amount(1)*j + amount(2)*k == in(3)
    }.count(_ == true)

  println(ans)
}

Measured memory_bytes: 28404
// dp(n) = dp(n-1) + dp(n-2) で, a の値によって分岐する.
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const int inf = (1 << 30) - 1;
const ll MOD = 1000000007;

int main()
{
  int N, M; cin >> N >> M;
  // 0 ~ N 段目を考えるので N+1
  vector<int> oks(N+1, true);
  for (int i = 0; i < M; i++) {
    int a; cin >> a;
    oks[a] = false;
  }

  vector<ll> dp(N+2);
  dp[0] = 1;
  for (int i = 0; i < N; i++) {
    if (!oks[i]) dp[i] = 0;
    (dp[i+1] += dp[i]) %= MOD;
    (dp[i+2] += dp[i]) %= MOD;
  }
  cout << dp[N] << endl;
  return 0;
}

Measured memory_bytes: 1408
#include<stdio.h>
int main(){
  int N;
  scanf("%d",&N);
  
  long int ans=0;
  
  for (int i=1;i<=N;i++){
    if (i%3!=0&&i%5!=0)
        ans+=i;
  }
  
  printf("%ld",ans);
  return 0;
  }
  


Measured memory_bytes: 1728
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <sstream>
#include <functional>
#include <numeric>
#include <cmath>
#include <cstring>
#include <queue>

using namespace std;
int n;

const int INF = 1 << 29;

int main(void)
{
	int sum = 0;
	for (int i = 0; i < 4; i++)
	{
		int a;
		cin >> a;
		sum += a;
	}
	cout << (sum / 60) << endl << (sum % 60) << endl;
	cin >> sum;
	return 0;
}

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

using namespace std;

#define x first
#define y second

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, k;
	cin >> n >> k;
	if  ((n-1)*(n-2)/2 < k){
		cout << -1;
		return 0;
	}
	vector <pair<int,int>> edge;
	for (int i = 1; i < n; ++i){
		edge.emplace_back(make_pair(i,n));
	}
	int limit = (n-1)*(n-2)/2 - k;
 	for (int i = 1; i < n && limit; ++i){
		for (int j = i + 1; j <n && limit; ++j){
			edge.emplace_back(make_pair(i,j));	
			--limit;
		}
	}
	cout << edge.size() << "\n";
	for (auto c : edge){
		cout << c.x << " " << c.y << "\n";
	}
	return 0;
}



Measured memory_bytes: 384
package main

import (
    "fmt"
)

func main() {
    var n, k int
    fmt.Scan(&n, &k)
    var s []byte
    fmt.Scan(&s)

    ns := make([]int, 0)
    ns = append(ns, 0)
    pb := byte('1')
    for _, b := range s {
        if b == pb {
            ns[len(ns)-1]++
        } else {
            ns = append(ns, 1)
            pb = b
        }
    }
    if s[len(s)-1] == '0' {
        ns = append(ns, 0)
    }

    var sum int
    sums := make([]int, len(ns)+1)
    sums[0] = 0
    for i := range ns {
        sum += ns[i]
        sums[i+1] = sum
    }

    gap := (len(ns) - 1) / 2
    if k >= gap {
        k = gap
    }
    mi := gap - k + 1
    var max int
    for i := 0; i < mi; i++ {
        v := sums[i*2+2*k+1] - sums[i*2]
        if v > max {
            max = v
        }
    }
    fmt.Println(max)
}


Measured memory_bytes: 6784
import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws IOException {
        init();

        int h = nextInt(), n = nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextInt();
            b[i] = nextInt();
        }

        int[] minPoints = new int[h + 1];
        Arrays.fill(minPoints, Integer.MAX_VALUE);
        minPoints[0] = 0;
        for (int i = 1; i < minPoints.length; i++) {
            for (int j = 0; j < n; j++) {
                minPoints[i] = Math.min(minPoints[i], b[j] + minPoints[Math.max(0, i - a[j])]);
            }
        }

        System.out.println(minPoints[h]);
    }

    //Input Reader
    private static BufferedReader reader;
    private static StringTokenizer tokenizer;

    private static void init() {
        reader = new BufferedReader(new InputStreamReader(System.in));
        tokenizer = new StringTokenizer("");
    }

    private static String next() throws IOException {
        String read;
        while (!tokenizer.hasMoreTokens()) {
            read = reader.readLine();
            if (read == null || read.equals(""))
                return "-1";
            tokenizer = new StringTokenizer(read);
        }

        return tokenizer.nextToken();
    }

    private static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }
}

Measured memory_bytes: 22740
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<bitset>
using namespace std;
int pd[410],u[110000],v[110000],n,m;
bitset<410>A[410],x[110000],ans,y[110000];
int main(){
	scanf("%d%d",&n,&m);
	for (int i=1;i<=m;i++) scanf("%d%d",&u[i],&v[i]);
	for (int i=1;i<=n;i++) A[i][i]=1;
	for (int i=m;i;i--){
		x[i]=A[u[i]];
		y[i]=A[v[i]];
		A[u[i]]|=A[v[i]];
		A[v[i]]=A[u[i]];
	}
	int num=0;
	for (int i=1;i<=m;i++)
		for (int j=1;j<=n;j++)
			if (x[i][j]&&y[i][j]) pd[j]=1;
	for (int i=1;i<=n;i++){
		ans=0; if (pd[i]) continue;
		for (int j=1;j<=m;j++){
			if (x[j][i]) ans|=y[j];
			if (y[j][i]) ans|=x[j];
		}
		for (int j=i+1;j<=n;j++) if (ans[j]==0&&pd[j]==0) num++;
	//	for (int j=1;j<=n;j++) cout<<ans[j]; cout<<endl;
	}
	cout<<num<<endl;
	return 0;
}

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



int main(){
	int a,b,cnt=0;
	string s,s2;
	cin >> a >> b;
	for(int i=a;i<=b;i++){
		s=to_string(i);
		s2=s;
		reverse(s2.begin(),s2.end());
		if(s==s2) cnt++;
	}
	cout << cnt << endl;
	return 0;
}

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

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> a(M), b(M);
    vector<bool> ok1(N, false), ok2(N, false);
    for (int i = 0; i < M; i++) {
        cin >> a[i] >> b[i];
        if (a[i] == 1) ok1[b[i]] = true;
        if (b[i] == N) ok2[a[i]] = true;
    }

    for (int i = 2; i < N; i++) {
        if (ok1[i] && ok2[i]) {
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }

    cout << "IMPOSSIBLE" << endl;
    return 0;
}

Measured memory_bytes: 1920
N = int(input())
A = list(map(int, input().split()))
L = [[] for x in range(N)]

for i in range(N):
    L[i] = [A[i], i+1]
L.sort()

ANS = [0 for i in range(N)]
for i in range(N):
    ANS[i] = L[i][1]
print(*ANS)

Measured memory_bytes: 26444
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, a, b) for(int i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define int long long
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define MAXN 2020
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef pair<ll,ll> pll;
typedef vector<string> vs;
typedef vector<pll> vpl;
typedef vector<int> vi;
inline int mod(int n, int m){ int ret = n%m; if(ret < 0) ret += m; return ret; }
int gcd(int a, int b){return (b == 0 ? a : gcd(b, a%b));}
int exp(int a,int b,int m){
    if(b==0) return 1;
    if(b==1) return mod(a,m);
    int k = mod(exp(a,b/2,m),m);
    if(b&1){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);

}

int dist[MAXN][MAXN];
vector<int> adj[MAXN];
int vis[MAXN];
int res[MAXN];
int32_t main(){
	fastio;
    int n,x,y;
    cin>>n>>x>>y;
    for(int i=1;i<n;i++){
        adj[i].pb(i+1);
        adj[i+1].pb(i);
    }
    adj[x].pb(y);
    adj[y].pb(x);


    for(int i=1;i<=n;i++){
        memset(vis,false,sizeof(vis));
        dist[i][i] = 0;
        queue<int> q;
        q.push(i);
        vis[i] = 1;
        while(!q.empty()){
            int cur = q.front();
            q.pop();
            for(int x : adj[cur]){
                if(!vis[x]){
                    vis[x] = 1;
                    dist[x][i] = dist[cur][i] + 1;
                    q.push(x);
                }
            }
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            res[dist[i][j]]++;
        }
    }
    for(int i=1;i<n;i++){
        cout<<res[i]<<endl;
    }

	// Math -> gcd it all
	//did you check N=1? Did you mix up N,M?
}

Measured memory_bytes: 32000
#include <math.h>

#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  int ret = A-B;
  cout << max(0,C-ret) << endl;
  return 0;
}


Measured memory_bytes: 256
// /usr/local/bin/g++ Main.cpp -std=c++14
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
ll N, K;

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

	cin >> N >> K;
	ll res = 0;
	for (int
	 i = 2; i <= 12; i++) {
		for (int j = 2; j <= 6; j++) {
			if (((7*i+j-7)*9)%11 == K) res++;
		}
	}
	res = res*((N-2)/11);
	for (ll i = 2; i <= (N-2)%11+1; i++) {
		for (int j = 2; j <= 6; j++) {
			if (((7*i+j-7)*9)%11 == K) res++;
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <stack>
#include <math.h>
#include <map>
#define Z class
#define ln cout<<'\n'
#define ll long long
#define rep(i, n) for(int i = 0; i < (n); ++i)
//ASCII a=97, A=65
// int H[N]; rep(i,N) scanf("%d", &H[i]);
// int max_x = *std::max_element(x.begin(), x.end());
// int min_y = *std::min_element(y.begin(), y.end());
using namespace std;
template<class T> inline bool chmax(T& a, T b){ if(a < b) { a=b; return 1; }return 0;}
template<class T> inline bool chmin(T& a, T b){ if(a > b) { a=b; return 1; }return 0;}
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
const long long INF = 1LL << 60;

int main(){
    string s; cin >> s;
    s[5]=' ';
    s[13]=' ';
    pr(s);
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(void){

	int a, b, c, k;
	
	cin >> a >> b >> c >> k;
	
	if(a >= k) cout << k;
	else if(a + b >= k) cout << a;
	else cout << a - (k - (a + b));



	return 0;
}

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

int main() {
	for (int i = 0; i < 81; i++) {
		cout << i / 9 + 1 << "x" << i % 9 + 1 << "=" << (i/9+1)*(i%9+1) << endl;
	}

	return 0;
}


Measured memory_bytes: 3052
#include<bits/stdc++.h>
#define fo(i,a,b) for((i)=(a);i<=(b);i++)
#define rfo(i,a,b) for((i)=(a);i>=(b);i--)
#define inrange(x,y,z) (((x)>=(y))&&((x)<=(z)))
#define ALL(vec) ((vec).begin(),(vec).end())
#define SOR(vec) sort(ALL(vec))
#define UNI(vec) (vec).erase(unique(ALL(vec)),(vec).end())
using namespace std;
int n,m,eu,ev,low[60],dfn[60],clo,answer;
vector<int> ga[60];
void tarjan(int u,int par){
	dfn[u]=++clo;
	low[u]=dfn[u];
	for(int v:ga[u]){
		if(v==par) continue;
		if(!dfn[v]){
			tarjan(v,u);
			low[u]=min(low[u],low[v]);
		}
		else low[u]=min(low[u],dfn[v]);
	}
	if(low[u]==dfn[u]) answer++;
}
int main(){
	#ifdef FILIN
		#ifndef DavidDesktop
			freopen(FILIN,"r",stdin);
			freopen(FILOUT,"w",stdout);
		#endif
	#endif
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>m;
	while(m--){
		cin>>eu>>ev;
		ga[eu].push_back(ev);
		ga[ev].push_back(eu);
	}
	tarjan(1,-1);
	cout<<answer-1<<endl;
	return 0;
}


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


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    char c[3][3];
    rep(i, 3) rep(j, 3) cin >> c[i][j];
    rep(i, 3) cout << c[i][i];
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<string>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef vector<int> VI;
#define fast ios::sync_with_stdio(0),cin.tie(0)
#define fi first
#define se second
#define pb push_back
#define mk make_pair
#define ls (rt<<1)
#define rs (rt<<1|1)
#define All(a) (a).begin(),(a).end()
#define clr(a) memset((a),0,sizeof(a))
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,a,b) for(int i=(a);i>=(b);--i)
#define FOR_edge(i,u)  for(int i=hd[u];i;i=e[i].nxt)
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int dx[]={1,-1,0,0};
const int dy[]={0,0,-1,1};

inline char in() {
	static char buf[10001],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,10000,stdin),p1==p2)?EOF:*p1++;
}
template <class Tp> inline void read(register Tp &s) {
	s=0;
	register bool neg=0;
	register char c;
	while(!isdigit(c=in())) if(c=='-') neg=1;
	while(s=(s<<3)+(s<<1)+c-48,isdigit(c=in()));
	s=(neg?-s:s);
}
template <class Tp> inline void write(register Tp x) {
	if(x<0) putchar('-'),x=-x;
	if(x>9) write(x/10);
	putchar(x%10+'0');
}
template <class Tp> inline void print(const Tp &x,const char &end) {write(x); putchar(end);}
template <class Tp> inline Tp pow(register Tp x,register Tp p,const Tp &mod) {
	register Tp res=1;
	for(;p;p>>=1,x=(x*x)%mod) if(p&1) res=(res*x)%mod;
	return res;
}
inline int comp(const double &x,const double &y) {
	const double d=x-y,eps=1e-8;
	return (d<=eps&&d>=-eps)?0:(d>eps?1:-1);
}
template <class Tp> inline Tp sqr(const Tp &x) {return x*x;}
template <class Tp> inline Tp gcd(const Tp &x,const Tp &y) {return(y==0?x:gcd(y,x%y));}
template <class Tp> inline Tp inv(const Tp &x,const Tp &MOD) {return POW(x,MOD-2,MOD);}
template <class Tp> inline Tp lowbit(const Tp &x) {return x&-x;}

int n,m;
struct node{
	int l,r;
}a[100005];

inline bool cmp(node a,node b) {
	if(a.l==b.l) return a.r<b.r;
	return a.l<b.l;
}
int main() {
	scanf("%d%d",&n,&m);
	FOR(i,1,m) {
		scanf("%d%d",&a[i].l,&a[i].r);
		a[i].r--;
	}
	sort(a+1,a+m+1,cmp);
	int ans=1;
	int x=a[1].l,y=a[1].r;
	FOR(i,2,m) {
		if(max(x,a[i].l)<=min(y,a[i].r)) {
			x=max(x,a[i].l);
			y=min(y,a[i].r);
		} else {
			x=a[i].l;
			y=a[i].r;
			ans++;
		}
	}
	printf("%d\n",ans);
	return 0;
}

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

#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long

const int INF = 1e18;
const int MOD = 1e9+7;
//const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで

using namespace std;

//typedef pair<int, int> P;
//priority_queue< P, vector<P>, greater<P> > q;//ダイクストラの時、greaterで小さい順
//cout << fixed << setprecision(10) << ans << endl;

int a[200000];
int n;
signed main(){
    cin >> n;
    REP(i,n){
        int a1;
        cin >> a1;
        a[a1] = i+1;
    }
    REP(i,n-1){
        cout << a[i+1] << " ";
    }
    cout << a[n] << endl;
    



    return 0;
}

Measured memory_bytes: 1536
def inpl(): return list(map(int, input().split()))
a = inpl()
a = sorted(a)

mid_count, min_count = (a[2]-a[1])//2, (a[2]-a[0])//2

if a[0]+min_count*2==a[1]+mid_count*2:
    if a[0]+min_count*2==a[2]:
        diff = 0
    else:
        diff = 1
else:
    diff = 2

print(mid_count+min_count+diff)

Measured memory_bytes: 3060
#include <stdio.h>

int main(){
  int a,b,c;

  scanf("%d %d %d",&a,&b,&c);

  if((a-b)==0)
    printf("%d\n",c);
  else
    if((a-c)==0)
      printf("%d\n",b);
    else
      printf("%d\n",a);

  return 0;
}




Measured memory_bytes: 128
#include<stdio.h>

int main(void) {

	int a = 0;
	int b = 0;
	int c = 0;
	int tmp;

	scanf("%d %d %d", &a, &b ,&c);

	if (c < b) {
		tmp = c;
		c = b;
		b = tmp;
	}
	if (b < a) {
		tmp = b;
		b = a;
		a = tmp;
		if (c < b) {
			tmp = c;
			c = b;
			b = tmp;
		}
	}
	if (c < a) {
		tmp = c;
		c = a;
		a = tmp;
		if (c < b) {
			tmp = c;
			c = b;
			b = tmp;
		}
	}

	printf("%d %d %d\n", a, b, c);

	return 0;
}


Measured memory_bytes: 2148
N, K, Q = map(int, input().strip().split())
# A=[0]*Q
score=[K]*N
for i in range(Q):
    A=int(input().strip())
    score[A-1]+=1
score=list(map(lambda x: x-Q,score))

for i in range(N):
    if score[i]>0:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 9844
#pragma GCC optimize("Ofast")
#include<stdio.h>
int main(void)
{
    int n = 5;
    int a[7] = {0};
    char c=getchar_unlocked();
    while(c<='9'&&c>='0') {a[--n] = c - '0'; c=getchar_unlocked();}
    int v = a[n+2] * 100 + a[n+1] * 10 + a[n];
    if(v) {
        printf("%d", 1000 - v);
        return 0;
    }
    puts("0");
    return 0;
}


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

int main(){
	int n, k, q;
	cin >> n >> k >> q;
	vector<int> a(n);
	rep(i,q){
		int x;
		cin >> x;
      	x--;
		a[x]++;
	}
	rep(i,n){
		if(k > q-a[i]) puts("Yes");
		else puts("No");
	}
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
// std::cout << std::setprecision(2) << 3.141; // "3.1"
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>
// #include <bits/stdc++.h> all

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;

static const int giga = pow(10,9);
// double pi = 3.141592653589793238463;

int main(void){
  long long int n,k,q; cin >> n >> k >> q;

  vector<int> a(q);
  vector<int> p(n, k-q);
  for(int i = 0; i< q; i++){
    int temp; cin >> temp;
    p[temp-1]++;
  }


  for(int i = 0; i<n; i++){
    if(p[i] > 0){
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

int N,K;

int main(){
  cin >> N >> K;
  vector<int> a(N);
  rep(i,0,N - 1){
    cin >> a[i];
  }

  vector<int> pp,nn;
  rep(i,0,N - 1){
    if(a[i] >= 0){
      pp.push_back(a[i]);
    }
    else{
      nn.push_back(a[i]);
    }
  }
  sort(all(pp));
  sort(all(nn));
  reverse(all(nn));
  i64 ans = 1e18;
  for(int i = 0;i <= K;i++){
    int j = K - i;
    if(i > pp.size() || j > nn.size()) continue;
    int left = (j == 0) ? 0 : abs(nn[j - 1]);
    int right = (i == 0) ? 0 : pp[i - 1];
    i64 res = min(left * 2 + right , left + right * 2);
    ans = min(ans , res);
  }
  cout << ans << endl;
}


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




int N, M;
int E[10][10];
int idx[10];
//-----------------------------------------------------------------
int main() {
	cin >> N >> M;
	rep(i, 0, M) {
		int a, b; cin >> a >> b;
		E[a][b] = E[b][a] = 1;
	}
	
	int ans = 0;
	idx[0] = 1;
	rep(i, 1, N) idx[i] = i + 1;
	do {
		ans++;
		rep(i, 0, N - 1) {
			int a = idx[i];
			int b = idx[i + 1];
			if (!E[a][b]) {
				ans--;
				break;
			}
		}
	} while (next_permutation(idx + 1, idx + N));
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL


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

    int N, K;
    cin >> N >> K;

    vs32 h(N);
    rep (i, N) cin >> h[i];
    sort(h.begin(), h.end(), greater<int>());

    int ans = 1e9;
    rep (i, N)
    {
        if (i + K - 1 >= N) break;
        ans = MIN(h[i] - h[i + K - 1], ans);        
    }
    cout << ans << "\n";

    return 0;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
#define int long long
#define bp __builtin_popcountll
#define pb push_back
#define in(s) freopen(s, "r", stdin);
#define inout(s, end1, end2) freopen((string(s) + "." + end1).c_str(), "r", stdin),\
		freopen((string(s) + "." + end2).c_str(), "w", stdout);
#define fi first
#define se second
#define bw(i, r, l) for (int i = r - 1; i >= l; i--)
#define fw(i, l, r) for (int i = l; i < r; i++)
#define fa(i, x) for (auto i: x)
using namespace std;
const int mod = 1e9 + 7, inf = 1061109567;
const long long infll = 4557430888798830399;
const int N = 1e5 + 5;
struct thing {
	int val, ind;
	bool isa;
	bool operator<(const thing &rhs) const { return val < rhs.val; }
};
int n, a[N], b[N], suma = 0, sumb = 0, ans, psum[N], posa[N], posb[N], extra[N];
vector<thing> v;
signed main() {
	#ifdef BLU
	in("blu.inp");
	#endif
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	fw (i, 0, n) cin >> a[i] >> b[i], suma += a[i], sumb += b[i], v.pb({a[i], i, 1}), v.pb({b[i], i, 0});
	ans = min(suma, sumb);
	//Take n - 2 smallest elements along with a[i] and b[i] for each i
	sort(v.begin(), v.end());
	fw (i, 0, v.size()) {
		if (v[i].isa) posa[v[i].ind] = i;
		else posb[v[i].ind] = i;
	}
	fw (i, 0, n + 1) psum[i] = (i ? psum[i - 1] : 0) + v[i].val;
	int og = 0;
	fw (i, 0, n - 2) og += v[i].val;
	fw (i, 0, n) {
		int res = psum[n - 1], cur = n;
		//cout << "posa["<<i<<"] = " << posa[i] << " posb = " << posb[i] << "\n";
		if (posa[i] >= cur) {
			res -= v[cur - 1].val;
			res += a[i];
			cur--;
		}
		if (posb[i] >= cur) {
			if (!v[cur - 1].isa || v[cur - 1].ind != i) {
				res -= v[cur - 1].val;
				res += b[i];
				cur--;
			} else {
				res -= v[cur - 2].val;
				res += b[i];
			}
		}
		//cout << "res for " << i << " is " << res << " cur = " << cur << "\n";
		ans = min(ans, res);
	}
	/*
	fw (i, 0, n) {
		int res = a[i] + b[i], need = n - 2;
		fw (j, 0, need) {
			if (v[j].ind == i) need++;
			else res += v[j].val;
		}
		cout << "Res for " << i << " = " << res << " cur = " << need << "\n";
		ans = min(ans, res);
	}
	*/
	cout << ans;
	return 0;
}

Measured memory_bytes: 10736
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
/*--Input//////////////////////////////////////////////////*/
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
#define SS(T, ...)      T __VA_ARGS__; IN(__VA_ARGS__);
#define SV(type,c,n) vector<type> c(n);for(auto& i:c)cin >> i;
/*--Output/////////////////////////////////////////////////*/
inline int p(void){cout << endl; return 0;}
template<class Head> int p(Head&& head){cout << head;p();return 0;} template<class Head,class... Tail> int p(Head&& head,Tail&&... tail){cout<<head<<" ";p(forward<Tail>(tail)...);return 0;}
struct ProconInit {
    static constexpr bool AUTOFLUSH = false;
    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define vl vector<ll>
#define debug(x) cerr<<#x<<" "<<x<<'\n';
#define all(x) (x).begin(),(x).end()
#define bit(n) (1LL<<(n))
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
bool cmp(pair<ll,ll> a, pair<ll,ll> b) { return a.first+a.second > b.first+b.second; }
const ll MOD = 1000000007;

signed main() {
    SS(int,n,k);
	SV(ll,h,n);
	vector<bool>ans(n,true);
	rep(i,k){
		SS(int,p,q);
		p--;q--;
		if(h[p]<=h[q])ans[p]=false;
		if(h[p]>=h[q])ans[q]=false;
	}
	int res=0;
	rep(i,n){
		if(ans[i]==true)res++;
	}
	p(res);
}


Measured memory_bytes: 3988
#! /usr/bin/env python3
# -*- coding:utf-8 -*-
def max_sum(A, B, C, K):
    if K < A: return K
    elif K < A+B :  return A
    else: return A - (K-(A+B))

def main():
    A, B, C, K = map(int, input().split())
    print(max_sum(A, B, C, K))

if __name__ == "__main__":
    main()


Measured memory_bytes: 9152
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;

int main() {
	ll n;
	cin >> n;
	for (ll a = 1; a <= 3500; a++) {
		for (ll b = 1; b <= 3500; b++) {
			ll x, y;
			x = n * a * b;
			y = 4 * a * b - n * a - n * b;
			if (y == 0)continue;
			if (1 <= x / y and x / y <= 3500 and x % y == 0) {
				cout << a << ' ' << b << ' ' << x / y << endl;
				return 0;
			}
		}
	}
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var a int
	fmt.Scan(&a)
	var b int
	fmt.Scan(&b)
	var c int
	fmt.Scan(&c)
	var k int
	fmt.Scan(&k)

	var sum int
	if k-a >= 0 {
		sum += 1 * a
	} else {
		sum += 1 * k
		fmt.Println(sum)
		return
	}
	k -= a
	k -= b
	if k <= 0 {
		fmt.Println(sum)
		return
	}
	if k-c >= 0 {
		sum += -1 * c
	} else {
		sum += -1 * k
		fmt.Println(sum)
		return
	}
	fmt.Println(sum)
	return
}


Measured memory_bytes: 1752
#!/usr/bin/env python3

N, M = map(int, input().split())

l_k = []
switches = []
for _ in range(M):
    line = list(map(int, input().split()))
    l_k.append(line[0])
    s = [i - 1 for i in line[1:]]
    switches.append(s)
l_p = list(map(int, input().split()))

# print(N, M)
# print(l_k, switches, l_p)

res = 0
for num in range(2 ** N):
    on_all = True
    for i in range(M):
        n_on = 0
        for s in switches[i]:
            if num & (1 << s):
                n_on += 1
        if n_on % 2 != l_p[i]:
            on_all = False
    if on_all:
        res += 1

print(res)


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

int max(int a,int b){
    return a<b ? b :a;
}

int main(){
    int k,n,a[1000010],i,m;
    cin >> k >> n;
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    for(i=0;i<n-1;i++){
        m=max(m,a[i+1]-a[i]);
    }
    cout << k-(max(m,k-a[n-1]+a[0])) << endl;
    return 0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define mod 1000000007

// F_mod 上でのべき乗, 蟻本p115
ll modPow(ll x, ll n) {
    ll res = 1;
    while(n > 0){
        if(n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

// Fermat の小定理を用いた F_mod 上での逆元計算x^(mod-2)
inline ll Inverse(ll x){
    return modPow(x, mod - 2);
}

#define MAX_N 100005
ll sum_div[MAX_N];
void sum_init(){
    sum_div[1] = 1;
    for (int i = 2; i < MAX_N; ++i) {
        sum_div[i] = sum_div[i-1] + Inverse(i);
        sum_div[i] %= mod;
    }
}

// iの階乗 = fact[i]
// fact_init(); を追加
#define MAX_FACT 300001
ll fact[MAX_FACT];
void fact_init(){
    fact[0]=1;
    for(int i = 1; i < MAX_FACT; ++i) {
        fact[i] = fact[i-1] * i % mod;
    }
}

int main() {
    sum_init();
    fact_init();
    int N;
    cin >> N;
    vector<int>X(N);
    for (int i = 0; i < N; ++i) {
        cin >> X[i];
    }

    vector<int>dist(N-1);
    for (int i = 0; i < N - 1; ++i) {
        dist[i] = X[i+1] - X[i];
    }

    ll ans = 0;
    for (int i = 0; i < N - 1; ++i) {
        ll temp = dist[i] * fact[N-1] % mod;
        temp *= sum_div[i+1];
        temp %= mod;
        ans += temp;
        ans %= mod;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define NCLR(a) memset((a), -1 ,sizeof(a))
#define dump(x) cout << #x << " = " << (x) << "\n";
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
typedef complex<double> P;
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 1000000007;
static const int INF = 1 << 29;
static const LL LL_INF = 1152921504606846976;
static const int dx[] = { -1, 0, 1, 0, 1, -1, 1, -1 };
static const int dy[] = { 0, -1, 0, 1, 1, 1, -1, -1 };

int main() {
	int n;
	while ( ~scanf( "%d", &n ) && n != -1 ) {
		double x = 0, y = 0;
		double r = PI / 2;
		for ( int i = 0; i < n; i++ ) {
			r -= PI / 2;
			x += cos( r );
			y += sin( r );
			r = atan2( -y, -x );
		}
		printf( "%f\n%f\n", x, y );
	}
	return 0;
}

Measured memory_bytes: 1304
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
#define mod 1000000007
ll mypower(ll a, ll b, ll N)
{
    ll ans = 1;
    while(b)
    {
        if(b%2)
            ans = ans*a%N;
        b=b/2;
        a=a*a%N;
    }
    return ans;
}
void bfs(vector<int> graph[], int v, int par[], int vis[])
{
    queue<int> q;
    q.push(v);
    vis[v] = 1;
    while(q.empty() == false)
    {
        int tp = q.front();
        q.pop();
        for(auto j : graph[tp])
        {
            if(!vis[j])
            {
                vis[j] = 1;
                par[j] = tp;
                q.push(j);
            }
        }
    }
}
#define PI acos(-1)
int main() {
    int a, b, h, m;
    cin >> a >> b >> h >> m;
    long double ah, am;
    am = m*PI/30.0;
    ah = (h/6.0 + m/360.0)*PI;
    //cout << am << " " << ah << " " << cos(ah-am) << '\n';
    long double dist = a*a + b*b - 2*a*b*cos(ah-am);
    //cout << dist << '\n';
    dist = sqrt(dist);
    //cout << dist << '\n';
    cout << fixed << setprecision(14) << dist << '\n';
    //printf("%0.9lf", dist);
    
}

Measured memory_bytes: 4188
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){//main_program
  int64_t a,b,c,d;
  int64_t k,l,m,n;
  cin >> a >> b >> c >> d;
  
  k = a * c;
  l = a * d;
  m = b * c;
  n = b * d;
  cout << max(max(k,l),max(m,n)) <<endl;
}


Measured memory_bytes: 3632