akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 62;
const int INF = 1e9 + 7;

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

    vector<ll> ans(10010, 0);

    for(ll i = 1; i <= 105; ++i){
        for(ll j = 1; j <= 105; ++j){
            if(i*i + j*j + i*j > 10000)break;
            for(ll k = 1; k <= 105; ++k){
                ll res = i*i + j*j + k*k + i*j + i*k + j*k;
                if(res > 10000)break;
                ans[res]++;
            }
        }
    }

    rep(i, n)cout << ans[i+1] << endl;
}

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

#define MAX_N 2020

vector<vector<ll>> dp;
int main(){
  ll N;
  cin >> N;
  vector<pair<ll, int>> A;

  ll t;
  for(int i=0; i<N; i++){
    cin >> t;
    A.push_back(make_pair(t, i));
  }
  sort(A.begin(), A.end(), greater<pair<ll, int>>());


  dp.assign(MAX_N, vector<ll>(MAX_N, 0));

  ll ans = 0;
  for(int i=0; i<N; i++){
    for(int j=0; j<N; j++){
      if(i+j >= N){
        ans = max(ans, dp[i][j]);
        break;
      }
      dp[i+1][j] = max(dp[i][j]+A[i+j].first * abs(A[i+j].second - i), dp[i+1][j]);
      dp[i][j+1] = max(dp[i][j]+A[i+j].first * abs(A[i+j].second -(N-1-j)), dp[i][j+1]);
    }
  }
  cout << ans << endl;;
}

Measured memory_bytes: 35224
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define v(x) vector<x>
#define pb push_back 
#define mp make_pair
#define maxint 1e18
#define mint -1e18

int main(){
	int n,x,t;
	cin>>n>>x>>t;
	
	int cnt = ceil((double)n/x);
	cout<<cnt*t<<'\n';


	return 0;
}

Measured memory_bytes: 3644
<?php
fscanf(STDIN,'%s',$s);
$a=str_split($s);
$sa= 10000;
for ($i=0; $i <= count($a)-3 ; $i++) {
  // code...
  $i1=$a[$i];
  $i2=$a[$i+1];
  $i3=$a[$i+2];
  $n=$i1*100+$i2*10+$i3;

  if($n-753<0){
    $saz= 753-$n;
  }else {
    $saz = $n -753;
  }
  if($sa>$saz){
    $sa = $saz;
  }
}
echo $sa;

 ?>


Measured memory_bytes: 3576
import java.io.PrintWriter;
import java.util.Random;
import java.util.Scanner;

public class Main  implements Runnable {
	Random rnd = new Random();
	public static void main(String[] args) {
		new Thread(null, new Main(), "", 32 * 1024 * 1024).start(); //
	}
	public void run() {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n = Integer.parseInt(sc.next());
		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		int[] h = new int[n];
		for (int i = 0; i < n; i++) {
			h[i] = Integer.parseInt(sc.next());
		}
		
		out.println(bs(h, 0, 1000000000, a, b));
		out.flush();
	}
	int bs(int[] ar, int min, int max, int a, int b) {
		int ans = 0;
		if(chk(ar,a,b,min)==true)
		{
			return min;
		}
		if(chk(ar,a,b,max)==false)
		{
			return max;
		}
		int mid= (max+min)/2;;
		while(min+1<max)
		{
			mid = (max+min)/2;
			if(chk(ar,a,b,mid)==false)
			{
				min = mid;
			}
			else {
				max = mid;
			}
		}
		if(chk(ar,a,b,min)==true)
		{
			ans = min;
		}
		else {
			ans = min + 1;
		}
		return ans;
	}
	boolean chk(int[] ar, int a, int b, int m)
	{
		boolean ans = true;
		int n = ar.length;
		long remain = m;
		for (int i = 0; i < n; i++) {
			long tmp = (long)ar[i]-(long)m*(long)b;
			if(tmp>0)
			{
				remain -= (tmp+a-b-1)/(a-b);
			}
		}
		if(remain >= 0)
		{
			ans = true;
		}
		else {
			ans = false;
		}
		return ans;
	}
}

Measured memory_bytes: 48332
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};
 
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; }
 
struct Timer{
    chrono::system_clock::time_point start, end;
    Timer(){ start = chrono::system_clock::now(); }
    ~Timer(){
        end = chrono::system_clock::now();
        auto msec = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cerr<<"time : "<<msec<<" ms"<<endl;
    }
};


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    // Timer TM;

    while(true){
        ll n,r;
        cin>>n>>r;
        if(n==0&&r==0) break;
        vll v(n);
        rep(i,n) v[i]=n-i;
        rep(i,r){
            ll p,c;
            cin>>p>>c;
            vll t(p-1),s(c);
            rep(i,p-1) t[i]=v[i];
            rep(i,c) s[i]=v[p-1+i];
            rep(i,c) v[i]=s[i];
            rep(i,p-1) v[c+i]=t[i];
        }
        cout<<v[0]<<endl;
    }

    
    return 0;
}


Measured memory_bytes: 3040
import sys
from math import ceil

def read():
    return sys.stdin.readline().rstrip()

def main():
    n, h = map(int, read().split())
    a = 0
    b = [0] * n
    c = 0
    for i in range(n):
        ai, bi = map(int, read().split())
        a = max(ai, a)
        b[i] = bi
    for d in sorted([bi for bi in b if bi > a] + [a], reverse=True):
        h -= d
        c += 1
        if h <= 0:
            break
    else:
        c += ceil(h / a)
    print(c)

if __name__ == '__main__':
    main()

Measured memory_bytes: 8864
N = int(input())
K = int(input())
X = list(map(int, input().split()))

ans = 0
for i in range(N):
    if abs(X[i]) <= abs(X[i]-K):
        ans += abs(X[i])*2
    else:
        ans += abs(X[i]-K)*2
print(ans)


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

using namespace std;

int main() {
    long long int n, m;
    cin >> n >> m;
    long long int result = 0;
    if(n == 1 && m == 1) {
        result = 1;
    }
    else if(n == 1) {
        result = m - 2;
    }
    else if(m == 1) {
        result = n - 2;
    }
    else if(n == 2 || m == 2) {
        result = 0;
    }
    else {
        result = (n - 2) * (m - 2);
    }
    cout << result << endl;
}


Measured memory_bytes: 256
using System;

class Test01
{
    public static void Main()
    {
        string str;
        int t;
        //string test;
        char i1; //先頭の文字
        char i2; //半角スペースの1文字後ろの文字
        char i3; //文字列の末尾から最初の半角スペースの後ろの文字

        t = 0;

        str = Console.ReadLine();

        i1 = str[0];
        t = str.IndexOf(' ');
        t = t + 1;
        i2 = str[t];
        t = str.LastIndexOf(' ');
        t = t + 1;
        i3 = str[t];

        i1 = Char.ToUpper(i1);
        i2 = Char.ToUpper(i2);
        i3 = Char.ToUpper(i3);

        String a = i1.ToString();
        String b = i2.ToString();
        String c = i3.ToString();


        Console.WriteLine(a + b + c);
        //test = Console.ReadLine();
    }
}

Measured memory_bytes: 13140
a,b,m=map(int,input().split())
aa=list(map(int,input().split()))
bb=list(map(int,input().split()))
ans=min(aa)+min(bb)
for i in range(m):
    x,y,z=map(int,input().split())
    ans=min(ans,max(0,aa[x-1]+bb[y-1]-z))
print(ans)


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

bool search(int s, vector<int> p){
    for(int i = 0; i < p.size(); i++){
        if(s == p[i]){
            return true;
        }
    }
    return false;
}

int main(){
    int X, N;
    cin >> X >> N;
    vector<int> p(N);
    for(int i = 0; i < N; i++){
        cin >> p[i];
    }
    int ans;
    int cnt = 0;
    bool flag_dec = false;
    while(true){
        if(!search(X + cnt, p)){
            ans = X + cnt;
            break;
        }
        cnt = -1 * cnt;     
        if(flag_dec){
            cnt--;
        }
        flag_dec = !flag_dec;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
module A = Array
module C = Char
module I = Int64
module L = List
module Q = Queue

let pf = Printf.printf
let sf = Scanf.scanf
let ssf = Scanf.sscanf

let read_int () = sf "%d " (fun x -> x)
let read_float () = sf "%f " (fun x -> x)
let read_str () = sf "%s " (fun x -> x)
let read_array n read () = A.init n (fun _ -> read ())
let err s = raise (Failure s)

let range s t = A.init (t - s) @@ (+) s
let foreach fold_f init s t map_f =
  range s t |> A.map map_f |> A.fold_left fold_f init

let inf = int_of_float 1e18
let eps = 1e-11

module S = struct
  include String
  let of_array a = String.init (A.length a) (A.get a)
  let to_array s = A.init (String.length s) (String.get s)
end;;

let () =
  let n = read_int () in
  let a = read_int () in
  let b = read_int () in
  let res = min (n * a) b in
  pf "%d\n" res


Measured memory_bytes: 384
#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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)*}
    };

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

#[allow(unused_macros)]
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, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap};

#[allow(dead_code)]
type Graph = Vec<Vec<usize>>;

const M: usize = 1000000007;

fn main() {
    input! {
        h: usize, w: usize, k: usize,
    }
    let mut dp = vec![vec![0; w]; h + 1];
    dp[0][0] = 1;
    let mut next = vec![];
    for i in 0..(1 << (w - 1)) {
        let mut ok = true;
        for j in 1..(w - 1) {
            if i & 1 << j > 0 && i & 1 << (j - 1) > 0 {
                ok = false;
                break;
            }
        }
        if ok {
            next.push(i);
        }
    }
    for i in 1..h + 1 {
        for &n in &next {
            for j in 0..w {
                if j + 1 < w && n & (1 << j) > 0 {
                    dp[i][j] += dp[i - 1][j + 1];
                }
                if j > 0 && n & (1 << (j - 1)) > 0 {
                    dp[i][j] += dp[i - 1][j - 1];
                }
                if (j == 0 || n & (1 << (j - 1)) == 0) && (j == w - 1 || n & (1 << j) == 0) {
                    dp[i][j] += dp[i - 1][j];
                }
                dp[i][j] %= M;
            }
        }
    }
    println!("{}", dp[h][k - 1]);
}


Measured memory_bytes: 4352
#include<stdio.h>

int main(void){
  int x , i ,j;
  int data[100];
  int num;

  scanf("%d", &x);
  for(i = 0; i < x; i++){
    scanf("%d",&num);
    data[i] = num;
  }

  for(j = i-1; j >= 0; j--){
    printf("%d", data[j]);
    if(j != 0){
      printf(" ");
    }
  }
  printf("\n");
  
  return 0;
}



Measured memory_bytes: 2044
import heapq
n,k=map(int,input().split())
data=[]
for i in range(n):
    t,d=map(int,input().split())
    data.append((-d,t))
data=sorted(data)
neta=set()
que1=[]
p,x=0,0
for i in range(k):
    if data[i][1] in neta:
        heapq.heappush(que1,(-data[i][0],data[i][1]))
        x-=data[i][0]
    else:
        x-=data[i][0]
        p+=1
        neta.add(data[i][1])
mx=x+p*p
for i in range(k,n):
    if data[i][1] in neta:
        pass
    else:
        if que1:
            a=heapq.heappop(que1)
            x=x-a[0]-data[i][0]
            p+=1
            neta.add(data[i][1])
            mx=max(mx,x+p*p)
        else:
            break
print(mx)


Measured memory_bytes: 64472
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)


void solve(long long X, long long A){
    if(X< A){
        cout << 0 << "\n";
    } else{
        cout << 10 << "\n";
    }
}

int main(){

    long long X;
    scanf("%lld",&X);
    long long A;
    scanf("%lld",&A);
    solve(X, A);
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x)+modulo)%modulo)
#define Inf 100000000000000000

#define init_value 0

int beki(int a,int b){
	int x = 1;
	while(b!=0){
		if(b&1){
			x=mod(x*a);
		}
		a=mod(a*a);
		b>>=1;
	}
	return x;
}

template <typename T>
struct segtree{
	//元データx[i]はv[n+i]
	//v[i]の親はv[i/2],子はv[i*2]とv[i*2+1]
	vector<T> v;
	int n;
	
	segtree(vector<T> &x){
		n=1;
		while(true){
			if(n>=x.size())break;
			n*=2;
		}
		v.resize(2*n,init_value);
		
		for(int i=0;i<x.size();i++){
			v[n+i]=x[i];
		}
		for(int i=n-1;i>=0;i--){
			v[i]=func(v[i*2],v[i*2+1]);
		}
	}
	
	
	void update(int x,T val){
		x+=n;
		v[x]=val;
		while(true){
			x=(x)/2;
			v[x]=func(v[x*2],v[x*2+1]);
			if(x<=0)break;
		}
	}
	
	//区間[l,r)におけるクエリ処理
	T query(int l,int r){
		T res = init_value;
		l+=n;r+=n;
		while(true){
			if(l%2==1){
				res=func(v[l],res);
				l++;
			}
			if(r%2==1){
				res=func(v[r-1],res);
				r--;
			}
			if(l>=r)break;
			l/=2;r/=2;
		}
		return res;
	}
	T func(T a,T b){
		return a+b;
	}
	
	void show(){
		int n = 1;
		for(int i=1;i<v.size();i++){
			for(int j=0;j<n;j++){
				if(j!=0)cout<<' ';
				cout<<v[i+j];
			}
			cout<<endl;
			i+=n-1;
			n*=2;
		}
	}
	
};

int main(){
	int N;
	cin>>N;
	map<int,int> mp;
	vector<pair<long long,long long>> V(N);
	for(int i=0;i<N;i++){
		cin>>V[i].first>>V[i].second;
		mp[V[i].second]=-1;
	}
	
	sort(V.begin(),V.end());
	
	int cnt = 0;
	for(auto &a:mp){
		a.second=cnt;
		cnt++;
	}
	
	vector<int> x(N,0);
	segtree<int> S1(x);
	for(int i=0;i<N;i++)x[i]=1;
	segtree<int> S2(x);
	
	int ans = mod(beki(2,N)*N);
	for(int i=0;i<N;i++){
		S2.update(mp[V[i].second],0);
		int RU = S2.query(mp[V[i].second],N);
		int RD = S2.query(0,mp[V[i].second]);
		int LU = S1.query(mp[V[i].second],N);
		int LD = S1.query(0,mp[V[i].second]);
		
		ans = mod(ans - beki(2,RU+RD));
		ans = mod(ans - beki(2,RU+LU));
		ans = mod(ans - beki(2,LU+LD));
		ans = mod(ans - beki(2,RD+LD));
		
		ans = mod(ans + beki(2,RU));
		ans = mod(ans + beki(2,RD));
		ans = mod(ans + beki(2,LU));
		ans = mod(ans + beki(2,LD));
		
		S1.update(mp[V[i].second],1);
		
		ans = mod(ans-1);
		
	}
	if(N==1)ans = 1;
	cout<<ans<<endl;
	
	
	return 0;
}




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

typedef long long ll;
 
using tpl = tuple<int, int, int>;
typedef pair<int,int> pii;

void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}

int N;
int D[51];
int freq[13];

int main(){

    cin >> N;
    for(int i = 0; i < N; i++) cin >> D[i];
    for(int i = 0; i < N; i++) freq[D[i]]++;
    
    if(freq[0] >= 1 || freq[12] > 1){
        cout << 0 << endl;
        return 0;
    }
    for(int i = 1; i < 12; i++){
        if(freq[i] > 2){
            cout << 0 << endl;
            return 0;
        }
    }


    int ans = 0;
    for(int mask = 0; mask < (1 << 22); mask++){
        int cnts[13] = {};
        // 0-23に値を割り当てて、計算する
        int table[50] = {};
        for(int i = 0; i < 22; i++){
            if((mask >> i) & 1){
                int idx = -1;
                // 1-11
                if(i < 11){
                    idx = i + 1;
                    table[i + 1]++;
                }
                // 13-23
                else{
                    table[(i + 2)]++;
                    idx = 24 - (i + 2);
                }
                cnts[idx]++;
            }
        }
        bool ok = true;
        for(int i = 1; i < 12; i++){
            if(cnts[i] > 0){
                if(freq[i] != cnts[i]){
                    ok = false;
                }
            }
            else{
                if(freq[i] != 0){
                    ok = false;
                }
            }
        }
        if(!ok) continue;
        table[0 ]++;
        table[12] += freq[12];
        int ptime = -1;
        int minv = 1<<29;
        for(int i = 0; i < 24; i++){
            table[i+24]=table[i];
        }
        for(int i = 0; i < 48; i++){
            if(table[i]){
                // cout << i << " ";
                if(ptime != -1){
                    minv = min(minv, (i - ptime));
                }
                ptime = i;
            }
        }
        // cout << endl;
        ans = max(ans, minv);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
N=int(input())
B = list(map(int, input().split()))
B.append(10**5+1)
t=0
for i in range(N-1):
  if B[i]>B[i+1]:
    t+=B[i+1]
  else:
    t+=B[i]
t+=B[0]
print(t)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>
#include <random>
#include <complex>
#include <functional>
#include <tuple>
#include <new>

//#include "All.h"

using namespace std;

#define EPS (1e-9)
#define INF (1e9)
#define MOD (ll)(1e9 + 7)
#define PI (acos(-1))
#define REP(i,a,n) for(int i=a;i<n;i++)
#define rep(i, n) REP(i,0,n)
#define allof(a) (a).begin(), (a).end()

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" ; "IMPOSSIBLE")

using ll = long long int;

ll gcd(ll a, ll b) {
    if (a < b) swap(a, b);
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll beki(ll a, ll b) {
    ll tmp = 1;
    rep(i, b) tmp *= a;
    return tmp;
}

int N;

int main() {
    cin >> N;
    int n = N % 10;
    switch (n) {
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
        cout << "hon" << endl;
        break;
    case 0:
    case 1:
    case 6:
    case 8:
        cout << "pon" << endl;
        break;
    case 3:
        cout << "bon" << endl;
        break;
    }
}

/*
10 5
0 -1 -2 -3 -4 -5 6 7 8 9

8 5
-1 -2 -3 -4 -5 6 7 8
*/

Measured memory_bytes: 3644
# 大きさがsum(a)のスライムが1匹いる
# dp[l][r]=min(区間[l,r]を分解するための最小コスト)
n=int(input())
a=list(map(int,input().split()))
INF=10**15
dp=[[0]*n for i in range(n)]
for i in range(n):
    dp[i][i]=a[i]
for i in range(n-1):
    for j in range(i+1,n):
        dp[i][j]=dp[i][j-1]+a[j]

for i in range(n-1):
    for j in range(i+1,n):
        ans=INF
        # print(j-i-1,j)
        for k in range(j-i-1,j):
            ans=min(ans,dp[j-i-1][k]+dp[k+1][j])
        if i<n-2:
            dp[j-i-1][j]+=ans
        else:
            print(ans)

Measured memory_bytes: 43244
import java.util.*;
class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int[] a = new int[10];
		for(int i=0; i<10; i++){
			a[i] = sc.nextInt();
		}
		Arrays.sort(a);
		for(int i=0; i<3; i++){
			System.out.println(a[9-i]);
		}
    }
}

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


int main(){
    int N;cin>>N;
    vector<int> A(N);
    A[0]=N+5;
    for(int i=1;i<N;i++)
    {cin>>A[i];}
    vector<int>answer(N+5);
    for(int i=0;i<N;i++){answer[i]=0;}
    for(int i=0;i<N;i++){answer[A[i]-1]++;}
    for(int i=0;i<N;i++){cout<<answer[i]<<endl;}
}




Measured memory_bytes: 4808
///
// File:  b.cpp
// Author: ymiyamoto
//
// Created on Sat Oct 14 21:28:00 2017
//

#include <cstdint>
#include <iostream>
#include <string>

using namespace std;
#define SIZE 100

static string table[SIZE];

int32_t main()
{
  int32_t H, W;
  cin >> H >> W;

  for (int32_t i = 0; i < H; i++) {
    string str;
    cin >> table[i];
  }

  for (int32_t i = 0; i < H; i++) {
    for (int32_t j = 0; j < W; j++) {
      if (table[i][j] == '.') {
        uint32_t count = 0;
        for (int32_t k = -1; k <= 1; k++) {
          for (int32_t l = -1; l <= 1; l++) {
            if (0 <= i + k && i + k <= (H - 1) && 0 <= j + l && j + l <= (W - 1) && table[i + k][j + l] == '#') {
              count++;
            }
          }
        }
        table[i][j] = count + '0';
      }
    }
  }

  for (int32_t i = 0; i < H; i++) {
    cout << table[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 256
//file_name:ABC107_B.cpp
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts()
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 200005;

    // 整数スキャン（複数）
    /*
    int x;
    scanf("%d",&x);
    int y;
    scanf("%d",&y);
    int z;
    scanf("%d",&y);

    // n個の整数のスキャン
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // 文字列スキャン
    /*
    string s;
    cin >> s;
    */


int main() {
    int n;
    scanf("%d",&n);
    ll k;
    scanf("%lld",&k);
    ll ans = 99999999999;
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    rep(i,n-k+1){
        if(a[i]>=0){
            mins(ans,a[i+k-1]);
        }else if(a[i+k-1]<=0){
            mins(ans,abs(a[i]));
        }else{
            mins(ans,-a[i]+2*a[i+k-1]);
            mins(ans,-2*a[i]+a[i+k-1]);
        }
    }


    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 1024
#include<cstdio>
#include<algorithm>
#include<cstdio>
#include<iostream>
using namespace std;
struct edge{
	int x,y;
};edge e[200];
int a[200];
int n,m;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	cin>>m;
	for(int i=1;i<=m;i++){
		cin>>e[i].x>>e[i].y;
	}
	for(int j=1;j<=m;j++){
		int tot=0;
		for(int i=1;i<=n;i++){
			if(e[j].x==i){
				tot+=e[j].y;
			}
			else{
				tot+=a[i];
			}
		}
		cout<<tot<<endl;
	}
	return 0;	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll N, K;
  cin >> N >> K;
  vl lvec(N);
  rep(i, N) cin >> lvec[i];

  stable_sort(lvec.begin(), lvec.end(), greater<ll>());

  ll ans = 0;
  rep(i, K) ans += lvec[i];

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


Measured memory_bytes: 256
<?php

fscanf(STDIN, "%d %d", $h, $w);
$map = [];
for ($i = 0; $i < $h; ++$i) {
    $map[] = str_split(trim(fgets(STDIN)));
}

$b_cnt = 0;
foreach ($map as $row) {
    foreach ($row as $cell) {
        if ($cell === '#') ++$b_cnt;
    }
}
$w_cnt = $h * $w - $b_cnt;

$gy = $h - 1;
$gx = $w - 1;

$q = new SplQueue();
$q->enqueue([0, 0]);
$map[0][0] = 0;

$patterns = [
    [0, 1],
    [0, -1],
    [1, 0],
    [-1, 0],
];

while (!$q->isEmpty()) {
    $u = $q->dequeue();
    $uy = $u[0];
    $ux = $u[1];

    foreach ($patterns as $p) {
        $ny = $uy + $p[0];
        $nx = $ux + $p[1];

        if ($ny < 0 || $ny > $h - 1) continue;
        if ($nx < 0 || $nx > $w - 1) continue;
        if ($map[$ny][$nx] !== '.') continue;

        $map[$ny][$nx] = $map[$uy][$ux] + 1;

        $q->enqueue([$ny, $nx]);
    }
}

if ($map[$gy][$gx] === '.') {
    echo -1, PHP_EOL;
    return;
}

echo $w_cnt - ($map[$gy][$gx] + 1);

/* foreach ($map as $row) { */
/*     echo implode(' ', $row), PHP_EOL; */
/* } */


Measured memory_bytes: 4728
#![allow(unused_imports)]
// use itertools::Itertools;
use proconio::{input, marker::*};
use std::cmp;

fn main() {
    input! {
        n: isize,
        k: isize,
        x: isize,
        y: isize
    };
    println!("{}", x * cmp::min(n, k) + y * cmp::max(n - k, 0));
}


Measured memory_bytes: 2096
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e9+7;
const int siz=2e5;
const long inf=1e9;
int main(){
	int L,R,d; cin>>L>>R>>d;
	cout<<R / d - (L-1) / d<<endl;
}

Measured memory_bytes: 3592
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <utility>
using namespace std;
typedef pair<int, int> P;
int main()
{
    int h, w;
    cin >> h >> w;
    vector<string> grid(h);
    int allwhite = 0;
    for (int i = 0; i < h; i++)
    {
        string stg;
        cin >> stg;
        grid[i] = stg;
        for(int j = 0; j < w; j++)
        {
            if (stg[j]=='.') {
                allwhite++;
            }
        }
    }
    vector<vector<int>> d(h, vector<int>(w, -1));
    vector<int> dx = {-1, 0, 0, 1}, dy = {0, 1, -1, 0};
    queue<P> que;
    que.push(P(0, 0));
    d[0][0] = 1;
    while (que.size() > 0)
    {
        P p = que.front();
        que.pop();
        if (p.first == h - 1 && p.second == w - 1)
        {
            break;
        }
        else
        {
            for (int i = 0; i < 4; i++)
            {
                int nx = p.first + dx[i], ny = p.second + dy[i];
                if (nx>=0 && nx<h && ny>=0 && ny<w && grid[nx][ny]!='#' && d[nx][ny]==-1) {
                    d[nx][ny] = d[p.first][p.second] + 1;
                    que.push(P(nx,ny));
                }
            }
        }
    }
    if (d[h-1][w-1]==-1) {
        cout << -1 << endl;
    }
    else
    {
        cout << allwhite-d[h-1][w-1] << endl;
    }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
vector<int> b[10];
int dp[2][2001];
int max(int a,int b){return a>b?a:b;}
int main(){
	int n,m;
	int i,j,k;
	scanf("%d %d",&n,&m);
	for(i=0;i<n;i++){
		int c,g;
		scanf("%d %d",&c,&g);
		g--;
		b[g].push_back(c);
	}
	for(i=0;i<10;i++){
		sort(b[i].begin(),b[i].end());
		reverse(b[i].begin(),b[i].end());
	}
	for(i=0;i<=m;i++)dp[1][i]=0;
	for(i=0;i<10;i++){
		for(j=0;j<=m;j++){
			dp[i%2][j]=max(dp[i%2][j],dp[(i+1)%2][j]);
			int s=0;
			for(k=0;k<b[i].size();k++){
				if(j+k+1>m)break;
				s+=b[i][k];
				dp[i%2][j+k+1]=max(dp[i%2][j+k+1],dp[(i+1)%2][j]+s+k*(k+1));
			}
		}
	}
	printf("%d\n",dp[1][m]);
	return 0;
}

Measured memory_bytes: 1084
# coding: utf-8
import sys


def main(argv=sys.argv):
  
  code = list(input())
  list1 = []
  
  for i in range(len(code)):
    if code[i] == '0':
      list1.append(0)
      
    elif code[i] == '1':
      list1.append(1)
      
    elif len(list1) == 0 and code[i] == 'B':
      pass
      
    elif code[i] == 'B':
      list1.pop(-1)     
      
  print(''.join(map(str, list1)))
    
  
  return 0


if __name__ == '__main__':
  sys.exit(main())

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    ios_base::sync_with_stdio(0);
    int x; cin >> x;
    ll res = 1;
    for (int i=1;i<=x;i++) res = res*i%1000000007;
    cout << res << endl;
}


Measured memory_bytes: 3580
N=int(input())
D=[list(map(int, input().split())) for i in range(N)]
count=0
for j in range(N-2):
    if D[j][0]==D[j][1]:
        if D[j+1][0]==D[j+1][1]:
            if D[j+2][0]==D[j+2][1]:
                count = 1
if count==0:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 62504
import sys
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

a = ni()
b = ni()
c = ni()
d = ni()
e = ni()

f = min((a-1)%10,(b-1)%10,(c-1)%10,(d-1)%10,(e-1)%10)

ans = (a+9)//10+(b+9)//10+(c+9)//10+(d+9)//10+(e+9)//10

print(ans*10+f-9)

Measured memory_bytes: 3064
package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
)

const Inf = 1 << 60

func main() {
	H, W, K := ReadInt(), ReadInt(), ReadInt()
	x1, y1, x2, y2 := ReadInt()-1, ReadInt()-1, ReadInt()-1, ReadInt()-1
	x1, y1 = y1, x1
	x2, y2 = y2, x2
	c := make([]string, H)
	for y := 0; y < H; y++ {
		c[y] = ReadString()
	}

	var dx = []int{1, 0, -1, 0}
	var dy = []int{0, 1, 0, -1}

	toID := func(x, y, dir int) int {
		return 4*(W*y+x) + dir
	}
	splatID := func(id int) (x, y, dir int) {
		return id / 4 % W, id / 4 / W, id % 4
	}

	dist := make([]int, W*H*4)
	for i := 0; i < W*H*4; i++ {
		dist[i] = Inf
	}

	q := Heap{}
	for i := 0; i < 4; i++ {
		q = append(q, State{
			Cost: 0,
			ID:   toID(x1, y1, i),
		})
	}
	for len(q) > 0 {
		now := q.pop()
		x, y, dir := splatID(now.ID)
		if c[y][x] == '@' {
			continue
		}
		if dist[now.ID] <= now.Cost {
			continue
		}
		dist[now.ID] = now.Cost
		if x == x2 && y == y2 {
			break
		}
		for i := 0; i < 4; i++ {
			nCost := (now.Cost + K - 1) / K * K
			nID := toID(x, y, i)
			if dist[nID] <= nCost {
				continue
			}
			q.push(State{
				Cost: nCost,
				ID:   nID,
			})
		}
		nx := x + dx[dir]
		ny := y + dy[dir]
		if 0 <= nx && nx < W && 0 <= ny && ny < H {
			nCost := now.Cost + 1
			nID := toID(nx, ny, dir)
			if dist[nID] <= nCost {
				continue
			}
			q.push(State{
				Cost: nCost,
				ID:   nID,
			})
		}
	}
	ans := Inf
	for i := 0; i < 4; i++ {
		id := toID(x2, y2, i)
		if dist[id] < ans {
			d2 := (dist[id] + K - 1) / K
			if d2 < ans {
				ans = d2
			}
		}
	}
	if ans < Inf {
		fmt.Println(ans)
	} else {
		fmt.Println(-1)
	}
}

type State struct {
	Cost, ID int
}

type HeapElement = State
type Heap []HeapElement

func (h Heap) Less(i, j int) bool    { return h[i].Cost < h[j].Cost }
func (h Heap) Len() int              { return len(h) }
func (h Heap) Swap(i, j int)         { h[i], h[j] = h[j], h[i] }
func (h *Heap) Push(x interface{})   { *h = append(*h, x.(HeapElement)) }
func (h *Heap) Pop() (x interface{}) { *h, x = (*h)[:len(*h)-1], (*h)[len(*h)-1]; return }
func (h *Heap) push(v HeapElement)   { heap.Push(h, v) }
func (h *Heap) pop() HeapElement     { return heap.Pop(h).(HeapElement) }

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


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

namespace ABC125C
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            //N個の整数 新しい入力処理の書き方 int.Parseを１回しか使わなくてよい
            int[] A = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            int[] L = new int[N+1];//Aよりも左側の最大公約数
            int[] R = new int[N+1];//Aよりも右側の最大公約数
            int ans = 0;
            L[0] = 0;
            R[N] = 0;
            for (int i = 0; i < N; i++)
            {
                L[i + 1] = gcd(L[i], A[i]);
            }
            for (int i = N-1; i >= 0; i--)
            {
                R[i] = gcd(R[i + 1], A[i]);
            }
            for (int i = 0; i < N; i++)
            {
                ans = Math.Max(gcd(L[i], R[i + 1]), ans);
            }
            Console.WriteLine(ans);
        }
        public static int gcd(int x,int y)
        {
            if (x < y)
            {
                int tmp = x;
                x = y;
                y = tmp;
            }
            while (y > 0)
            {
                int r = x % y;
                x = y;
                y = r;
                gcd(x, y);
            }
            return x;
        }
    }
}


Measured memory_bytes: 27740
import std.stdio, std.conv, std.string, std.algorithm.searching, std.algorithm.iteration;

void main()
{
    auto N = readln().strip.to!int;
    int[] pList = [];
    foreach(i; 0..N)
    {
        pList ~= readln().strip.to!int;
    }
    writeln(pList.sum - pList.reduce!"a<b?b:a" / 2);
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n,y;
  cin>>n>>y;
  y=y/1000-n;
  int x=y%4;
  int r=x+(y-9*x)/36*4;
  int q=(y-9*r)/4;
  if(r>=0&&q>=0&&q+r<=n)
    {cout<<r<<" "<<q<<" "<<n-q-r<<endl;
     }
  else
    {cout <<"-1 -1 -1"<<endl;}
return 0;
}


Measured memory_bytes: 256
//2736　問四　渡辺彩子
import java.util.Scanner;

public class Main{

public void solve(){
    Scanner sc=new Scanner(System.in);
    int ijyo,i,n,k;
    ijyo=1;
    i=0;
    
    n=sc.nextInt();
    while(n!=0){
        for(int h=0;h<n;h++){
        k=sc.nextInt();
            
            if(k>=2){
              ijyo++;
            }else{
            }
            if(k==1){
              i++;
            }
        }

        if(ijyo>=2){
          System.out.println(ijyo+i);
        }else{
          System.out.println("NA");
        }
        
        ijyo=1;
        i=0;
        n=sc.nextInt();
    }
}


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


            
    

Measured memory_bytes: 158508
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    int n, x;

    cin >> n >> x;

    int cou = 1, D = 0;

    int l;

    for(int i = 0; i < n; i++){
        cin >> l;
        D += l;
        if(D <= x){
            cou += 1;
        }else
        {
            break;
        }
    }

    cout << cou << endl;
    return 0;
}

Measured memory_bytes: 888
from collections import defaultdict

N = int(input())
A = list(map(int,input().split()))
Q = int(input())
dic = defaultdict(int)
s = 0
for n in A:
    dic[n] += 1
    s += n
for _ in range(Q):
    b,c = map(int,input().split())
    s += (c-b)*dic[b]
    dic[c] += dic[b]
    dic[b] = 0
    print(s)


Measured memory_bytes: 88336
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
typedef long long ll;
int main()
{
  ll a,b;
  cin >> a >> b;
  if(a*b<=0) cout << "Zero" << "\n";
  else if(a>0) cout << "Positive" << "\n";
  else if((b-a)%2==1) cout << "Positive" << "\n";
  else cout << "Negative" << "\n";
  
  return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(System.out);
		Scanner s = new Scanner(System.in);
		
		String[] split = f.readLine().split("\\s+");
		String res = "";
		for(int i= 0; i < split.length; i++) {
			res += Character.toUpperCase(split[i].charAt(0));
		}
		System.out.println(res);
	}
}

Measured memory_bytes: 10320
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>

using namespace std;
typedef long long ll;

int main(){
  int n,m;
  cin>>n>>m;
  vector<int> x(m);
  for(int i = 0; i < m;i++) {
    cin>>x[i];
  }
  if(n>=m) cout<<0<<endl;
  else{
    sort(x.begin(),x.end());
    vector<int> l(m-1,0);
      for(int i = 0; i < m-1; i++){
      l[i] = x[i+1]-x[i];
    }
    
    sort(l.begin(),l.end());
    reverse(l.begin(),l.end());
    int sum = 0;
    for(int i = 0; i < n-1; i++){
      sum+=l[i];
    }
  
    cout<<x[m-1]-x[0]-sum<<endl;
  }
  return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<complex>

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

using namespace std;

int n,m;
long long x[1002],y[1002],z[1002];

int main(){
cin >> n >> m;
rep(i,n){
  cin >> x[i] >> y[i] >> z[i];
}
long long s[8][n];
rep(i,n) rep(j,8) s[j][i]=0;

rep(i,n){
  s[0][i] += x[i]+y[i]+z[i];
  s[1][i] += x[i]+y[i]-z[i];
  s[2][i] += x[i]-y[i]+z[i];
  s[3][i] += x[i]-y[i]-z[i];
  s[4][i] += -x[i]+y[i]+z[i];
  s[5][i] += -x[i]+y[i]-z[i];
  s[6][i] += -x[i]-y[i]+z[i];
  s[7][i] += -x[i]-y[i]-z[i];
}

long long a=0,a1=0;
rep(i,8){
  a1=0;
  sort(s[i],s[i]+n);
  for(int j = n-m;j<n;j++){
    a1+=s[i][j];
  }
  a = max(a,a1);
}

cout << a << endl;


  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long int
#define FASTIO std::ios::sync_with_stdio(false);
#define pb push_back
#define mp make_pair
#define ld long double
#define F first
#define S second
#define input_from_file  freopen("input.txt", "r", stdin);
#define inf 1000000000000000
using namespace std;
ll val[101];
ll w[101];
ll dp[101][200001];
int main()
{
FASTIO

ll n,W;
cin >> n >> W;
for(ll i=1;i<=n;i++)
{
  cin >> w[i] >> val[i];
}

for(ll i=0;i<=n;i++){
  for(ll j=0;j<=200000;j++)dp[i][j] = inf;
}
dp[0][0] = 0;
for(ll i=1;i<=n;i++)
{
  for(ll j=0;j<=200000;j++)
  {
    dp[i][j] = min(dp[i][j],dp[i-1][j]);
    if(dp[i][j] == inf)continue;
    dp[i][j+val[i]] = min(dp[i][j+val[i]],dp[i-1][j] + w[i]);
  }
}
ll ans = 0;


for(ll i=1;i<=200000;i++)
{
  if(dp[n][i] <= W)ans = i;
}
cout << ans;
}


Measured memory_bytes: 158080
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 998244353
#define INF63 1061109567
#define INF127 9187201950435737471
#define UINF 18446744073709551615
#define F first
#define S second
#define ll long long
#define N 55 
using namespace std;
ll n,m,u[N],v[N],w[N],dif[N],ans=0,pow2[N],dp[N],av[N],tres,f[N][12];
vector<ll> vt[N];
vector<pair<ll,ll> > ed;
void dfs(ll x,ll lst,ll d)
{
	ll i;
	dp[x]=d;
	for(i=0;i<10;i++)
	{
		f[x][i+1]=f[f[x][i]][i];
	}
	for(i=0;i<vt[x].size();i++)
	{
		if(vt[x][i]!=lst)
		{
			f[vt[x][i]][0]=x;
			dfs(vt[x][i],x,d+1);
		}
	}
	return;
}
ll glca(ll x,ll y)
{
	ll i;
	if(dp[x]<dp[y])
	{
		swap(x,y);
	}
	for(i=10;i>=0;i--)
	{
		if(dp[f[x][i]]>=dp[y])
		{
			x=f[x][i];
		}
		if(x==y)
		{
			return x;
		}
	}
    for(i=10;i>=0;i--)
    {
        if(f[x][i]!=f[y][i])
        {
            x=f[x][i];
            y=f[y][i];
        }
    }
    return f[x][0];
}
void dfs2(ll x,ll lst)
{
	ll i;
	av[x]=dif[x];
	for(i=0;i<vt[x].size();i++)
	{
		if(vt[x][i]!=lst)
		{
			dfs2(vt[x][i],x);
			av[x]+=av[vt[x][i]];
		}
	}
	if(av[x]>0&&x!=0)
	{
		tres++;
	}
	return;
}
int main(){
	ll i,mask,x,y;
	cin>>n;
	for(i=1;i<n;i++)
	{
		cin>>x>>y;
		x--;
		y--;
		vt[x].push_back(y);
		vt[y].push_back(x);
		ed.push_back(make_pair(x,y));
	}
	dfs(0,-1,0);
	cin>>m;
	for(i=0;i<m;i++)
	{
		cin>>u[i]>>v[i];
		u[i]--;
		v[i]--;
		w[i]=glca(u[i],v[i]);
	}
	pow2[0]=1;
	for(i=1;i<50;i++)
	{
		pow2[i]=pow2[i-1]*2;
	}
	for(mask=0;mask<(1<<m);mask++)
	{
		for(i=0;i<n;i++)
		{
			dif[i]=0;
		}
		for(i=0;i<m;i++)
		{
			if(mask&(1<<i))
			{
				dif[w[i]]-=2;
				dif[u[i]]++;
				dif[v[i]]++;
			}
		}
		tres=1;
		dfs2(0,-1);
		//cout<<tres<<endl;
		if(__builtin_popcount(mask)%2==0)
		{
			ans+=pow2[n-tres];
		}
		else
		{
			ans-=pow2[n-tres];
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3728
#include <stdio.h>
int main(){
	int m,f,r,score[51];
	int i = 0;
	while(1){
		scanf("%d %d %d",&m,&f,&r);
		if(m == -1 && f == -1 && r == -1)break;
		if(m + f >= 50 && m + f < 65)score[i]=2;//C
		if(m + f >= 30 && m + f < 50){
			if(r >= 50) score[i]=2;//C
			else score[i]=1;//D
		}
		if(m + f >= 65 && m + f < 80)score[i]=3;//B
		if(m + f >= 80)score[i]=4;//A
		if((m == -1 || f == -1)||(m + f < 30))score[i] = 0;//F
		i++;
	}
	for (int j = 0; j < i; j++)
	{
		switch (score[j]){
			case 0:
				printf("F\n");
				break;
			case 1:
				printf("D\n");
				break;
			case 2:
				printf("C\n");
				break;
			case 3:
				printf("B\n");
				break;
			case 4:
				printf("A\n");
				break;

		}
	}
	return 0;
}


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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set
#define pll pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>

using namespace std;

const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);

int main() {
  ll N;
  scanf("%lld", &N);

  vector<pair<ll, ll>> list1(N);
  vector<pair<ll, ll>> list2(N);
  for (ll i = 0; i < N; i++) {
    ll a, b;
    scanf("%lld %lld", &a, &b);
    list1[i] = make_pair(a, b);
    list2[i] = make_pair(b, a);
  }

  sort(list1.begin(), list1.end());
  sort(list2.begin(), list2.end());

  if (N % 2 == 1) {
    ll v1 = list1[N / 2].first;
    ll v2 = list2[N / 2].first;

    // cout << v1 << endl;
    // cout << v2 << endl;

    ll a = (v2 - v1) + 1;
    cout << a << endl;
  } else {
    ll v1p = list1[N / 2 - 1].first + list1[N / 2].first;
    ll v2p = list2[N / 2 - 1].first + list2[N / 2].first;

    double v1 = v1p / 2.0;
    double v2 = v2p / 2.0;

    ll a = (v2 - v1 + 0.5) * 2;
    cout << a << endl;
  }
}


Measured memory_bytes: 9596
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n,k;
	scanf("%lld %lld",&n,&k);
	n=n%k;
	if(k-n<n){
		n=k-n;
	}
	printf("%lld\n",n);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define All(v) v.begin(), v.end()
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;

int main(){
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int a, b; cin >> a >> b;
    if(a<=5) cout << 0 << endl;
    else if(a<=12) cout << b / 2 << endl;
    else cout << b << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define OUT(x) cout << (x) << endl;
#define OUTA(a, n) \
    REP(i, n) { cout << (a[i]) << (i == n - 1 ? "\n" : " "); }
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

ll N;
vi P;

int main()
{
    cin >> N;
    P = vi(N);
    REP(i, N)
    {
        cin >> P[i];
    }

    vi Q = vi(N + 1);
    REP(i, N)
    {
        Q[P[i]] = i + 1;
    }

    ll ans = 0;
    set<ll> L = set<ll>();
    set<ll> R = set<ll>();
    L.insert(0);
    L.insert(1);
    L.insert(-Q[N]);
    R.insert(N + 1);
    R.insert(N + 2);
    R.insert(Q[N]);
    for (ll i = N - 1; i > 0; --i)
    {
        ll j = Q[i];
        ll l1 = -(*L.upper_bound(-j));
        ll l2 = -(*L.upper_bound(-l1));
        ll r1 = *R.upper_bound(j);
        ll r2 = *R.upper_bound(r1);
        if (r1 <= N)
        {
            ans += i * (j - l1) * (r2 - r1);
        }
        if (l1 >= 1)
        {
            ans += i * (r1 - j) * (l1 - l2);
        }
        L.insert(-j);
        R.insert(j);
    }

    OUT(ans);
}

Measured memory_bytes: 11136