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

using namespace std;

int n, arr[100000], memo[100000];

int solve(int i) {
    if (i >= n)
        return 2e9;

    if (i == n - 1)
        return 0;

    int r = 2e9;
    if (memo[i] != -1)
        r = memo[i];
    else
        r = min(r, min(abs(arr[i] - arr[i + 1]) + solve(i + 1), abs(arr[i] - arr[i + 2]) + solve(i + 2)));
    memo[i] = r;
    return r;
}

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

    memset(memo, -1, sizeof memo);
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> arr[i];
    cout << solve(0) << "\n";
}

Measured memory_bytes: 2560
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
c=Counter(a).most_common()
s=[0,0]
for v in c:
  if v[1]>=2:
    for _ in range(v[1]//2):
      s.append(int(v[0]))
s.sort()
print(s[-1]*s[-2])


Measured memory_bytes: 21540
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#define PI 3.14159265359
typedef long long ll;
const int MOD = 1e9+7;
const ll LLINF = 7e18;
using namespace std;


ll llmin(ll x, ll y){
	if (x < y) return x;
	return y;
}

ll llmax(ll x, ll y){
	if (x > y) return x;
	return y;
}



int main(){
	int n, o;
	cin >> n >> o;
	vector<pair<ll, ll> > xy(n);
	for (int i = 0; i < n; i++){
		cin >> xy[i].first >> xy[i].second;
	}

	ll ans = LLINF;
	for (int i = 0; i < n; i++){
		for (int j = 0; j < n; j++){
			for (int k = 0; k < n; k++){
				for (int l = 0; l < n; l++){
					ll xmax = llmax(llmax(xy[i].first, xy[j].first), llmax(xy[k].first, xy[l].first));
					ll xmin = llmin(llmin(xy[i].first, xy[j].first), llmin(xy[k].first, xy[l].first));
					ll ymax = llmax(llmax(xy[i].second, xy[j].second), llmax(xy[k].second, xy[l].second));
					ll ymin = llmin(llmin(xy[i].second, xy[j].second), llmin(xy[k].second, xy[l].second));
					int tmp = 0;
					for (int m = 0; m < n; m++){
						if (xmin <= xy[m].first && xy[m].first <= xmax && ymin <= xy[m].second && xy[m].second <= ymax){
							tmp++;
						}
					}
					if (tmp >= o){
						ans = llmin(ans, (xmax-xmin)*(ymax-ymin));
					}
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3616
#include<iostream>
using namespace std;
int main(){
    int a,b;
    cin >> a >> b;
    
    if(a<b) cout << "a < b" << endl;
    else if(a>b) cout << "a > b" << endl;
    else if(a=b) cout << "a == b" << endl;
    return 0;
}


Measured memory_bytes: 3088
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}

	return i
}
func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()

	list := make([]int, n)
	tmp := 0
	max := -1
	sum := 0

	for i := 0; i < n; i++ {
		tmp = nextInt()
		list[i] = tmp
		sum += tmp
		if tmp > max {
			max = tmp
		}
	}

	if sum-max > max {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}

}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<time.h>
#include<stdlib.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#define pb push_back
#define mp make_pair
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define pll pair<ll,ll>
#define vll vector<ll,ll>
#define all(a) (a).begin(),(a).end()
#define ff first
#define ss second
#define sz(x) (ll)x.size()
#define hell 1000000007
#define repf(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>b;i--)
#define lbnd lower_bound
#define ubnd upper_bound
#define bs binary_search
#define gcd(a,b) __gcd((a),(b))
#define EPS 1e-12
#define lcm(a,b) ((a)*(b))/__gcd((a),(b))
#define sqrt sqrtl
#define cbrt cbrtl
using namespace std;
vector< pair< pair<string,ll>,ll> > v;
ll cmp(pair< pair<string,ll> ,ll> a, pair< pair<string,ll> ,ll> b)
{
   if(a.ff.ff!=b.ff.ff)
    return a.ff.ff<b.ff.ff;
  return a.ff.ss>b.ff.ss;
}
int main()
{
  IOS
  ll n;
  cin>>n;
  ll i;
  for(i=0;i<n;i++)
  {
     string s;
     ll x;
     cin>>s>>x;
     v.pb(mp(mp(s,x),i+1));
  }
  sort(all(v),cmp);
  for(i=0;i<n;i++)
    cout<<v[i].ss<<"\n";
  return 0;
}

Measured memory_bytes: 256
/*  In the name of ALLAH */

#include<bits/stdc++.h>
using namespace std;
/*******  All Required define Pre-Processors and Constants    *******/

#define int long long
#define ull unsigned long long 
#define ld long double
#define mem(a, b) memset(a, (b), sizeof(a))
#define rep(i, j, k) for (int i = j ; i < k ; ++i)
#define rrep(i, j, k) for (int i = j; i > k; --i)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define foreach(i, a) for(auto i: a)
#define forEach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define in(A, B, C) assert( B <= A && A <= C)
#define debug(a) cout << #a << ": " << a << endl
#define Flag(n) cout << "here " << n << endl
#define w(x) int x;cin>>x;while(t--)
#define mp make_pair
#define pb push_back

#define endl '\n';
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const int POSITIVE_INFINITY = 9223372036854775807;
const int NEGATIVE_INFINITY = -9223372036854775807;
const int MOD = 1000000007;
const ld PI = acos(-1.0);
 

#define TRACE
#ifdef TRACE
#define see(...) __f(#__VA_ARGS__,__VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr<<name<<" : "<<arg1<<endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma=strchr(names+1,',');cerr.write(names,comma-names)<<" : "<<arg1<<" | ";__f(comma+1, args...);
}
#else
#endif



int32_t main() {
    io;
    // freopen("input.txt","r",stdin); 
    // freopen("output.txt","w",stdout);
  
    int n,k;
    cin>>n>>k;
    int arr[n];
    rep(i,0,n)cin>>arr[i];
    sort(arr, arr+n);
    int s = 0;
    rep(i,0,k)s+=arr[i];
    cout<<s<<endl;

 
    
 
    return 0;
}


Measured memory_bytes: 3664
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

class Main {
    public static void main(String args[]){
        String[] input=A0();
    }



    public static String[] A0(){

        int i=0;
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        try {
            String nm=reader.readLine();
            String[] sp=nm.split(" ");
            Long n=Long.parseLong( sp[0]);
            int m=Integer.parseInt( sp[1]);

            String[] ret=new String[m];
            for (int j = 0; j < m; j++) {
                ret[j]=reader.readLine();
            }
            reader.close();

            Set<Integer> ok=new HashSet<>();
            Map<Integer,Integer> error=new HashMap<>();
            for (int j = 1; j <= n; j++) {
                error.put(j,0);
            }

            for (int j = 0; j < m; j++) {
               String[] line= ret[j].split(" ");
               int num= Integer.parseInt( line[0]);
               String result=line[1];
               if(result.startsWith("AC")){
                   ok.add(num);
               }else if(!ok.contains(num)){
                   error.put(num,error.get(num)+1);
               }
            }
            long pena=0;
            for (int j = 1; j <=n ; j++) {
                if(!ok.contains(j)){
                    error.remove(j);
                }else {
                   pena+=error.get(j);
                }
            }

            System.out.print(ok.size());
            System.out.print(" ");
            System.out.println(pena);



        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;

    }
}

Measured memory_bytes: 56912
from fractions import gcd

def lcm(a):
    x = a[0]
    for i in range(1, len(a)):
        x = (x * a[i]) // gcd(x, a[i])
    return x

n = int(input())
a = list(map(int, input().split()))

div = 10**9 + 7
lcm_num = lcm(a)
ans = [lcm_num//ai for ai in a]

print(sum(ans)%div)


Measured memory_bytes: 264668
n = int(input())
vl = list(map(int,input().split()))
v1 = vl[::2]
v2 = vl[1::2]

def count(a):
  d = dict()
  for i in a:
    if i not in d:
      d[i] = 1
    else:
      d[i] += 1
  l = []
  for i in d:
    l.append([d[i],i])
  l.append([0,0])
  l.sort(reverse=1)
  return l

v1 = count(v1)
v2 = count(v2)
if v1[0][0] == v1[1][0] or v2[0][0] ==v2[1][0]:
  print(n-v1[0][0]-v2[0][0])
elif v1[0][1] != v2[0][1]:
  print(n-v1[0][0]-v2[0][0])
elif v1[1][0]+v2[0][0] > v1[0][0]+v2[1][0]:
  print(n-v1[1][0]-v2[0][0])
else:
  print(n-v1[0][0]-v2[1][0])

Measured memory_bytes: 21980
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

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

func main() {
	sc.Split(bufio.ScanWords)

	N := getInt()
	s := make([]string, N)
	m := make(map[string]int)
	max := 0
	for i := 0; i < N; i++ {
		s[i] = getString()
		m[s[i]]++
		if max < m[s[i]] {
			max = m[s[i]]
		}
	}
	sel := make([]string, 0)
	for i, v := range m {
		if v == max {
			sel = append(sel, i)
		}
	}

	sort.Strings(sel)
	for _, v := range sel {
		fmt.Println(v)
	}
}


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

using namespace std;

int n, q;
vector<int> A(n);

bool solve( const int p, int t )
{
	if( 0 == t ) { return true; }
	if( p < n ) {
		return solve( p+1, t - A.at( p ) ) | solve( p+1, t );
	} else {
		return false;
	}
}

int main()
{
	cin>>n;
	int num;
	for( int i=0; i<n; i++ ) {
		cin>>num;
		A.push_back( num );
	}
	cin>>q;
	for( int i=0; i<q; i++ ) {
		cin>>num;
		if( solve( 0, num ) ) {
			cout<<"yes"<<'\n';			
		} else {
			cout<<"no"<<'\n';
		}
	}
    return 0;
}		
	

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

int s(int x){
  int ans = 0;
  while(x > 0){
    ans += x % 10;
    x /= 10;
  }
  return ans;
}

int main(void){
  int N, A, B;
  cin >> N >> A >> B;
  int ans = 0;
  for(int i = 1; i <= N; i++){
    if(A <= s(i) && s(i) <= B) ans += i;
  }
  cout << ans << endl;
  return 0;
}


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

int main()
{
	long a, b, x;
	long ans;

	cin >> a >> b >> x;

	if (a != 0)
	{
		ans = b/x - (a-1)/x;
	} else {
		ans = b/x + 1;
	}
	
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#define ll long long
#define rep(i, a, b) for(int i = a; i <= b; i++)
void read(int &x) {
    x = 0; int flag = 1; char ch = ' ';
    while(ch < '0' || ch > '9') { if(ch == '-') flag = -1; ch = getchar(); }
    while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
    x *= flag;
}
void read(ll &x) {
    x = 0; int flag = 1; char ch = ' ';
    while(ch < '0' || ch > '9') { if(ch == '-') flag = -1; ch = getchar(); }
    while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
    x *= flag;
}
using namespace std;
const int maxn = 500010;
char s[maxn];
int n, fail[maxn], fail2[maxn], ans;
int main()
{
    scanf("%s", s + 1);
    n = strlen(s + 1);
    fail[1] = 0;
    for(int i = 2, j = 0; i <= n; i++) {
        while(j && s[j + 1] != s[i]) j = fail[j];
        if(s[j + 1] == s[i]) j++;
        fail[i] = j;
    }
    reverse(s + 1, s + 1 + n);
    fail2[1] = 0;
    for(int i = 2, j = 0; i <= n; i++) {
        while(j && s[j + 1] != s[i]) j = fail2[j];
        if(s[j + 1] == s[i]) j++;
        fail2[i] = j;
    }
    reverse(fail2 + 1, fail2 + 1 + n);
    if(n - fail[n] == 1) {
        printf("%d\n%d\n", n, 1);
        return 0;
    }
    if(n - fail[n] == n) {
        printf("%d\n%d\n", 1, 1);
        return 0;
    }
    else {
        int p = n - fail[n];
        if(n % p == 0) {
            rep(i, 1, n - 1) {
                if(((fail[i] == 0) || i % (i - fail[i]) != 0) && ((fail2[i + 1] == 0) || (n - i) % (n - i - fail2[i + 1]) != 0)) ans++;
            }
            printf("%d\n%d\n", 2, ans);
        }
        else {
            printf("%d\n%d\n", 1, 1);
        }
    }
    return 0;
}

Measured memory_bytes: 4608
#include<bits/stdc++.h>
using namespace std;
#define ll long long
char ss[10004];
int n;
int main()
{
    scanf("%d",&n);
    scanf("%s",ss+1);
    int len = strlen(ss+1);
    for(int i=1;i<=len;i++)
    {
        ss[i] = (ss[i] + n - 'A') % 26 +'A' ;
    }
    printf("%s",ss+1);
    return 0 ;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	char c[3][4];
	scanf("%s", c[0]);
	scanf("%s", c[1]);
	scanf("%s", c[2]);
	printf("%c%c%c\n", c[0][0], c[1][1], c[2][2]);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1660
import math
import queue
import bisect
import heapq
import time
import itertools

mod = int(1e9+7)

def swap(a,b):
    return (b,a)

def my_round(a,dig=0):
    p = 10 ** dig
    return (a * p * 2 + 1) // 2 / p

def gcd(a,b): #最大公約数
    if (a<b):
        a,b = swap(a,b)
    if (b==0):
        return a
    else:
        return gcd(b,a%b)

def lcm(a,b): #最小公倍数
    return a/gcd(a,b)*b

def divisors(a): # 約数列挙
    divisors = []
    for i in range(1,int(a**0.5)+1):
        if a%i==0:
            divisors.append(i)
            if i!=a//i:
                divisors.append(a//i)
    return divisors

def is_prime(a): #素数判定
    if a<2:
        return False
    elif a==2:
        return True
    elif a%2==0:
        return False
    sqrt_num = int(a**0.5)
    for i in range(3,sqrt_num+1,2):
        if a%i==0:
            return False
    return True

def prime_num(a): #素数列挙
    pn = [2]
    for i in range(3,int(a**0.5),2):
        prime = True
        for j in pn:
            if i%j==0:
                prime = False
                break
        if prime:
            pn.append(i)
    return pn

def prime_fact(a): #素因数分解
    sqrt = math.sqrt(a)
    res = []
    i = 2
    if is_prime(a):
        res.append(a)
    else:
        while a!=1:
            while a%i==0:
                res.append(i)
                a //= i
            i += 1
    return res

def main():
    s = input()
    if len(s) < 4:
        print('No')
        return
    if s[0:4] == 'YAKI':
        print('Yes')
    else:
        print('No')
    return

if __name__=='__main__':
    main()


Measured memory_bytes: 38576
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")
    };
}

fn main() {
    input! {
        w: f64,
        h: f64,
        x: f64,
        y: f64
    };
    let ans = w * h / 2.0;
    if w == x || h == y {
        println!("{} {}", ans, 0);
    } else if x == w / 2.0 && y == h / 2.0 {
        println!("{} {}", ans, 1);
    } else {
        println!("{} {}", ans, 0);
    }


    // let vert_divided = if x > w / 2.0 { h * (w - x) } else { h * x };
    // let horizon_divided = if y > h / 2.0 { w * (h - y) } else { w * y };
    // if vert_divided == horizon_divided {
    //     println!("{} {}", vert_divided, 1);
    // } else if vert_divided > horizon_divided {
    //     if y == h / 2.0 {
    //         println!("{} {}", vert_divided, 1);
    //     } else {
    //         println!("{} {}", vert_divided, 0);
    //     }
    // } else if horizon_divided > vert_divided {
    //     if x == w / 2.0 {
    //         println!("{} {}", horizon_divided, 1);
    //     } else {
    //         println!("{} {}", horizon_divided, 0);
    //     }
    // }
}


Measured memory_bytes: 4352
H, W, m = map(int, input().split())
hw = [list(map(int, input().split())) for _ in range(m)]

row, col = [0] * H, [0] * W
for h, w in hw:
    row[h - 1] += 1
    col[w - 1] += 1

rowmax, colmax = max(row), max(col)
cnt = row.count(rowmax) * col.count(colmax)
for h, w in hw:
    if row[h - 1] == rowmax and col[w - 1] == colmax:
        cnt -= 1
print(rowmax + colmax - (cnt == 0))


Measured memory_bytes: 130220
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const int INF = 19191919;

struct SegTree{
    int n; vector<ll> dat;
    // 初期化
    SegTree(int _n){
        n=1;
        while(n<_n) n*=2;
        dat=vector<ll>(2*n-1,INF);
    }
    // k番目(0-indexed)の値をaに変更
    void update(int k, ll a){
        k+=n-1;
        dat[k]=a;
        //更新
        while(k>0){
            k=(k-1)/2;
            dat[k]=min(dat[2*k+1],dat[2*k+2]);
        }
    }
    // 内部的に投げられるクエリ
    ll _query(int a, int b, int k, int l, int r){
        if(r<=a || b<=l) return INF;

        if(a<=l && r<=b) return dat[k];

        ll vl=_query(a,b,2*k+1,l,(l+r)/2);
        ll vr=_query(a,b,2*k+2,(l+r)/2,r);
        return min(vl,vr);
    }
    // [a,b)
    ll query(int a, int b){
        return _query(a,b,0,0,n);
    }
};

vector<int> solve(){
    int n,m;
    string s;
    cin >>n >>m >>s;

    vector<ll> d(n+1,INF);
    d[n] = 0;
    SegTree st(n+1);
    st.update(n, 0);
    for(int i=n-1; i>=0; --i)if(s[i] == '0'){
        ll md = st.query(i+1, i+m+1);
        d[i] = min(d[i], md+1);
        st.update(i,d[i]);
    }
    if(d[0]>=INF) return vector<int>(1,-1);

    int V = d[0];
    vector<int> ans(V);

    vector<int> pos(V+1);
    for(int i=n; i>=0; --i)if(d[i]<=V) pos[d[i]] = i;
    reverse(all(pos));

    rep(i,V) ans[i] = pos[i+1] - pos[i];
    return ans;
}

int main(){
    vector<int> a = solve();
    int n = a.size();
    rep(i,n) cout << a[i] << " \n"[i==n-1];
    return 0;
}


Measured memory_bytes: 4096
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <complex>

#define forin(i, f, t) for(auto i = f; i < t; i++)

using namespace std;
using ll = long long;


int main() {
    string s;
    cin >> s;
    
    int counter = 0;
    for (auto c : s) {
        counter += c == '+' ? 1 : -1;
    }
    cout << counter << endl;
    
    return 0;
}



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

int main(void){
	int A, B;
  	cin >> A >> B;
	if ( A > 12){
		cout << B;
    }else if ( A > 5){
		cout << B/2;
    }else{
      cout << 0;
    }
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int num = n;
    int sod = 0;
    while(num>0){
        int t = num%10;
        num/=10;
        sod+=t;
    }
    printf("%s\n",(n%sod == 0)? "Yes":"No");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
#define MOD 1000000007
#define INF 1000000000
typedef pair<int64_t, int64_t> PII;
typedef vector<int64_t> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

// まずは全探索，次にDP
// 偶奇，逆から，ソート，出現回数，出現位置，DP
// 余事象，包除
// データ構造
// 問題の特徴量
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
int main() {
cin.tie(0);
ios::sync_with_stdio(false);

int N;cin >> N;
VI L(N); rep(i, 0, N) cin >> L[i];
sort(ALL(L));

int cnt = 0;
rep(a, 0, N-2) 
    rep(b, a+1, N-1){
        // cout << distance(L.begin() + b, lower_bound(ALL(L), L[a] + L[b])); 
        cnt += distance(L.begin() + b, lower_bound(ALL(L), L[a] + L[b])) - 1;
    }

cout << cnt << "\n";
}

// 境界，出力文字列 チェック



Measured memory_bytes: 256
def main():
    number = int(input())
    queue = ["a"]
    for i in range(number - 1):
        now_queue = []
        for now in queue:
            limit = ord(max(now)) + 2
            for j in range(ord("a"), limit):
                now_queue.append(now + chr(j))
        queue = now_queue
    for q in queue:
        print(q)


if __name__ == '__main__':
    main()



Measured memory_bytes: 12988
using System;
using System.Collections.Generic;
using System.Linq;

public static class Program
{
    public static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());
        var vals = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        var result = Enumerable.Range(0, n).Select(x => 0).ToArray();
        var cnt = 0;
        for (int i = 1; i <= vals.Max(); i++)
        {
            var aryIdx = vals.Select((val, idx) => new { Idx = idx, Val = val })
                .Where(x => x.Val >= i).Select(x => x.Idx).ToArray();
            if (aryIdx.Length == 0)
                continue;
            var start = aryIdx.Min();
            for (int j = 0; j < aryIdx.Length; j++)
            {
                if (j == aryIdx.Length - 1)
                {
                    for (int k = start; k <= j; k++)
                        result[k]++;
                    cnt++;
                }
                else if (aryIdx[j + 1] - aryIdx[j] > 1)
                {
                    for (int k = start; k <= j; k++)
                        result[k]++;
                    start = aryIdx[j + 1];
                    cnt++;
                }
            }
        }
        Console.WriteLine(cnt);
    }
}

Measured memory_bytes: 11476
/*
    Code by CNH_Tourist
*/
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unrolled-loops")

using namespace std;

/*----------------Define----------------*/
#define inp "TestCode.inp"
#define out "TestCode.out"
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define FileInOut freopen(inp,"r",stdin);freopen(out,"w",stdout);
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define pi acos(-1)
#define pii pair<int,int>
#define ppiii pair< pair <int,int> ,int>
#define INF 1000000
#define endl '\n'
#define ll long long
#define pq priority_queue
const ll mod=1e9+7;
int test=1;
/*--------------------------------------*/

ll n,w;
pair<ll,ll> a[110];
ll f[110][100100];
ll maxx=0;

int main()
{
    FAST
    cin>>n>>w;
    for(int i=1;i<=n;i++)
        cin>>a[i].X>>a[i].Y;
    for(int j=1;j<=w;j++)
    {
        for(int i=1;i<=n;i++)
        {
            if(j>=a[i].X)
                f[i][j]=max(f[i-1][j-a[i].X]+a[i].Y,f[i-1][j]);
            else
                f[i][j]=f[i-1][j];
            maxx=max(f[i][j],maxx);
        }
    }
    cout<<maxx;
}



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

const int N = 2e5 + 10;

int n, m;
vector<int> g[N];
int cnt[N];

int main() {
	cin >> n >> m;
	for(int i = 0; i < m; ++i) {
		int foo, bar;
		cin >> foo >> bar;
		g[foo].push_back(bar);
		g[bar].push_back(foo);
	}

	queue<int> q;
	q.push(1);
	cnt[1] = 0;

	for(int i = 2; i <= n; ++i)
		cnt[i] = -1;



	while(! q.empty()) {
		int u = q.front(); q.pop();
		for(int v : g[u]) {
			if(cnt[v] == -1) {
				cnt[v] = cnt[u] + 1;
				q.push(v);
			}
		}
	}
	if(cnt[n] == 2) puts("POSSIBLE");
	else puts("IMPOSSIBLE");
}

Measured memory_bytes: 13168
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>
#include <string>
#include <numeric>
#include <math.h>
#include <set>
#include <map>
#include <fstream>
#include <sstream>
#include <iterator>
#include <complex>
using namespace std;

typedef struct Node
{
	bool flag = false;
	vector<int> path;
}Node;
int main()
{
	int N,Q;
	cin>>N>>Q;
	vector<Node> node(N);

	//vector<pair<int,int> > r(N);
	vector<int> score(N,0);
	for(int i=0; i<N-1; i++)
	{
		int a,b;
		cin>>a>>b;
		a--;
		b--;
		node[a].path.push_back(b);
		node[b].path.push_back(a);
	}
	for(int i=0; i<Q; i++)
	{
		int p,x;
		cin>>p>>x;

		p--;
		score[p] += x;
	}
	vector<long long> result(N, 0);
	stack<pair<int,long long>> st;
	st.push(make_pair(0,score[0]));
	node[0].flag = true;
	while(!st.empty())
	{
		pair<int, long long> _p = st.top();
		st.pop();
		int index = _p.first;
		result[index] = _p.second;

		int path_size = node[index].path.size();
		for(int i=0; i<path_size; i++)
		{
			int next_index = node[index].path[i];
			if(node[next_index].flag == false)
			{
				node[next_index].flag = true;
				st.push(make_pair(next_index,result[index] + score[next_index]) );
			}
		}
	}

	for(int i=0; i<N-1; i++)
	{
		cout<<result[i]<<" ";
	}
	cout<<result[N-1]<<endl;
}

Measured memory_bytes: 20280
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        long res = 0;

        for (int i = 0; i < (1 << s.length() - 1); i++) {
            int prev = 0;
            for (int j = 0; j < s.length() - 1; j++) {
                if((1 & i >> j) == 1) {
                    res += Long.parseLong(s.substring(prev, j + 1));
                    prev = j + 1;
                }
            }
            if(prev != s.length()) {
                res += Long.parseLong(s.substring(prev));
            }
        }

        System.out.println(res);
    }
}


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

int main() {
  int a, b;
  cin >> a >> b;
  if ((a + b) % 3 == 0 || a % 3 == 0 || b % 3 == 0) cout << "Possible" << endl;
  else cout << "Impossible" << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) ll((a).size())
#define out(a) cout<<(a)<<endl;
const int inf=INT_MAX;
const int MAX = 510000;
const ll MOD = 1000000007;

ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
int main(){
  ll n,k,ans=0;cin>>n>>k;
  vll a(n);
  COMinit();
  rep(i,0,n){
    cin>>a[i];
  }
  sort(a.begin(),a.end());
  rep(i,k-1,n){
    ans+=(COM(i,k-1)*a[i])%MOD;
    ans=mod(ans,MOD);
  }
  
  rep(i,0,n-k+1){
    ans-=(COM(n-i-1,k-1)*a[i])%MOD;
    ans=mod(ans,MOD);
  }
  cout<<ans<<endl;


}



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

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

Measured memory_bytes: 4048
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define pb push_back

void solve() {
    int h, w, k;
    cin >> h >> w >> k;
    string s[10];
    rep(i, h) cin >> s[i];
    int ans = 1 << 20;
    int white[10];
    rep(bit, 1 << (h - 1)) {
        memset(white, 0, sizeof white);

        vector<int> K;
        K.push_back(0);
        rep(i, h - 1) if(bit >> i & 1) K.pb(i + 1);
        K.push_back(h);

        int res = K.size() - 2;
        int last = 0;
        bool flag = 0;

        rep(j, w) {

            rep(t, K.size() - 1){
                for(int i = K[t]; i < K[t + 1]; i++) {
                    if (s[i][j] == '1') white[t]++;
                    if (white[t] > k) {
                        res++;
                        flag = 1;
                        break;
                    }
                }
                if (flag)break;
            }

            if (flag) {
                if (last == j) {
                    break;
                }
                memset(white, 0, sizeof white);
                flag = 0;
                last = j;
                j--;
            }

        }
        if(flag) continue;
        ans = min(ans, res);
    }
    cout << ans << endl;
    return;
}

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


Measured memory_bytes: 384
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <stack>
#include <queue>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
using ll = long long;
using ld = long double;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(void)
{
    ll N, i, j, t, C[500], S[500], F[500], a;

    cin >> N;

    for(i=1; i<=N-1; i++){
        cin >> C[i] >> S[i] >> F[i];
    }

    for(i=1; i<=N; i++){ // 開始時にいる駅
        if(i==N){
            cout << 0 << endl;
        }

        else{
            j = i; // 今いる駅
            t = 0;

            while(j < N){
                if(t < S[j]){
                    t = S[j];
                }

                else if(t % F[j] != 0){
                    a = t/F[j];
                    t += F[j]*(a+1)-t;
                }

                t += C[j];

                j++;
            }

            cout << t << endl;
        }
    }

    return 0;
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

LL n, k;

int main() {
	cin >> n >> k;
	
	LL ans = 1;
	inc(i, n) {
		if(i == 0) { ans *= k; } else { ans *= k - 1; }
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <numeric>

#define F first
#define S second
#define vsort(v) sort((v).begin(), (v).end())
#define vrev(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;

int main(int argc, const char * argv[]) {
    int n;
    cin >> n;
    ll x, sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> x;
        sum += x - 1;
    }
//    vector<ll> v(n);
//    ll x, y = 1;
//    for (int i = 0; i < n; i++) {
//        cin >> x;
//        v[i] = x;
//        y *= x;
//    }
//    ll sum = 0;
//    for (int i = 0; i < n; i++) {
//        sum += (y - 1) % v[i];
//        //cout << i << ' ' << (y - 1) % v[i] << endl;
//    }
    cout << sum << endl;
    
    
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<ll> divisor(ll n) {
	vector<ll> res;
	for (ll i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			res.push_back(i);
			if (i * i != n)
				res.push_back(n / i);
		}
	}
	sort(res.begin(), res.end());
	return res;
}
int main() {
	ll n;
	cin >> n;
	auto f = divisor(n);
	ll ans = 0;
	for (ll v : f) {
		ll m = v - 1;
		ll x = n / v;
		if (x < m) {
			ans += m;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3704
num = int(input())
test = {'AC': 0, 'WA': 0, 'TLE': 0, 'RE': 0}
for i in range(num):
    result = input()
    for j in test.keys():
        if result == j:
            test[result] += 1
for i in test:
    print(i, 'x', str(test[i]))

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

#define LUNCH 0
#define DINNER 1
#define MIDNIGHT 2
#define OUT 3

int time(int h,int m);

int main()
{
  int n,hh,mm,MM;
  int ok[3],num[3];
  string mes[3]={"lunch ","dinner ","midnight "};
  stringstream ss;
  int i,dif,t;
  char c;

  while(cin>>n,n){
    for(i=0;i<3;i++)ok[i]=num[i]=0;
    for(i=0;i<n;i++){
      cin>>hh>>c>>mm>>MM;
      t=time(hh,mm);
      if(t==OUT)continue;
      if(mm<=MM)dif=MM-mm;
      else dif=60+MM-mm;
      num[t]++;
      ok[t]+=(dif<=8);
    }
    ss.str("");
    for(i=0;i<3;i++){
      ss<<mes[i];
      if(num[i])ss<<100*ok[i]/num[i]<<endl;
      else ss<<"no guest\n";
    }
    cout<<ss.str();
  }
}

int time(int h,int m){
  int t;
  if(h<2)h+=24;
  t=h*100+m;
  if(1100<=t&&t<=1459)return LUNCH;
  else if(1800<=t&&t<=2059)return DINNER;
  else if(2100<=t&&t<=2559)return MIDNIGHT;
  else return OUT;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string str,st,stt;
  int i,j,n,m;
  cin>>str>>st;
  cin>>n>>m;
  cin>>stt;
  if(stt==st)cout<<n<<" "<<m-1;
  else cout<<n-1<<" "<<m;
  
 return 0;  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define repeat(i,a,b) for(int i=(a),i##__end=(b);i<i##__end;i++)
#define repeat_back(i,a,b) for(int i=(b)-1,i##__end=(a);i>=i##__end;i--)
#define mst(a,x) memset((a),(x),sizeof(a))
#define pii pair<int,int>
#define maxn 1000010
#define mod 2147483647
#define int ll
int n;
int a[200010],f[200010];
bool work(int m,int k){
	repeat(i,0,n){
		if(a[i]*f[i]>m){
			k-=(a[i]*f[i]-m+f[i]-1)/f[i];
			//(a[i]-?)*f[i]<=m
			//a[i]*f[i]-m<=?*f[i]
		}
		if(k<0)return false;
	}
	return true;
}
signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int k;
	cin>>n>>k;
	repeat(i,0,n)cin>>a[i];
	repeat(i,0,n)cin>>f[i];
	sort(a,a+n);
	sort(f,f+n,greater<int>());
	int l=0,r=1e18,m;
	while(l<=r){
		m=(l+(r-l)/2);
		if(!work(m,k))l=m+1;
		else r=m-1;
	}
	cout<<l<<endl;
	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define forn(i, n) for (int i = 0; i<(int)n; ++i)
#define forr(i, t, n) for (int i = t; i<n; ++i)
#define rmod(x, y) (((x%y)+y)%y)
#define emp emplace_back
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const int maxs = 3e3;

string s, t;
int dp[maxs+1][maxs+1];
void solve()
{
	forn(i, s.size()+1)
	{
		forn(j, t.size()+1)
		{
			if (not i or not j) continue;
			if (s[i-1] == t[j-1]) dp[i][j] = 1+dp[i-1][j-1];
			else dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
		}
	}
	//return dp[s.size()][t.size()];
}
void rec_sol()
{
	vector<char> ans;
	int i = s.size(), j = t.size();
	while(i>0 && j>0)
	{
		if (s[i-1] == t[j-1]) 
		{
			i--; j--;
			ans.emp(s[i]);
		}
		else if (dp[i-1][j]>dp[i][j-1]) i--;
		else j--;
	}
	for(int i = int(ans.size())-1; i>=0; i--) cout << ans[i];
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> s >> t;
	//for(auto&i:dp) i.resize(maxs+1);
	solve();
	rec_sol();
	return 0;
}

Measured memory_bytes: 35456
#include <iostream>
#include <cstdio>
#include <cstring>
#include <climits>
#include <functional>

#define N 100000

using namespace std;

long long parent(long long i){return((i-1)/2);}
long long lchild(long long i){return(2*i+1);}
long long rchild(long long i){return(2*i+2);}

bool gt(long long x, long long y){
  return(x > y);
}

bool lt(long long x, long long y){
  return(x < y);
}

void push(long long x, long long *pq, long long *q_max, function<bool(long long, long long)> f){
  pq[*q_max] = x;
  long long idx = *q_max;
  (*q_max)++;
  while (idx > 0) {
    if (f(pq[idx], pq[parent(idx)])) {
      long long tmp = pq[parent(idx)];
      pq[parent(idx)] = pq[idx];
      pq[idx] = tmp;
      idx = parent(idx);
    } else {
      return;
    }
  }
}

long long pop(long long *pq, long long *q_max, function<bool(long long, long long)> f){
  if (*q_max < 0) {
    cerr << "queue is empty." << endl;
    return 0;
  }
  long long result = pq[0];
  pq[0] = pq[--(*q_max)];
  long long idx = 0;
  while (lchild(idx) < *q_max) {
    if (f(pq[idx], pq[lchild(idx)]) && f(pq[idx], pq[rchild(idx)])) {
      return(result);
    }
    if (f(pq[lchild(idx)], pq[rchild(idx)])) {
      long long tmp = pq[lchild(idx)];
      pq[lchild(idx)] = pq[idx];
      pq[idx] = tmp;
      idx = lchild(idx);
    } else {
      long long tmp = pq[rchild(idx)];
      pq[rchild(idx)] = pq[idx];
      pq[idx] = tmp;
      idx = rchild(idx);
    } 
  }
  return(result);
}


int main(){
  long long n;
  long long a1_pq[N+1], a2[N+1], a3_pq[N+1];
  long long a1_pq_max = 0;
  long long a3_pq_max = 0;
  long long a1_max[N+1], a3_min[N+1];
  cin >> n;
  a1_max[0] = 0;
  a3_min[n] = 0;
  for (int i=0;i<n;i++) {
    long long a;
    cin >> a;
    push(a, a1_pq, &a1_pq_max, lt);
    a1_max[0] += a;
  }
  for (int i=0;i<n;i++) {
    long long a;
    cin >> a;
    a2[i] = a;
  }
  for (int i=0;i<n;i++) {
    long long a;
    cin >> a;
    push(a, a3_pq, &a3_pq_max, gt);
    a3_min[n] += a;
  }
  for (int i=0;i<n;i++) {
    if (a1_pq[0] < a2[i]) {
      a1_max[i+1] = a2[i] - a1_pq[0] + a1_max[i];
      pop(a1_pq, &a1_pq_max, lt);
      push(a2[i], a1_pq, &a1_pq_max, lt);
    } else {
      a1_max[i+1] = a1_max[i];
    }
  }
  for (int i=n;i>0;i--) {
    if (a3_pq[0] > a2[i-1]) {
      a3_min[i-1] = a2[i-1] - a3_pq[0] + a3_min[i];
      pop(a3_pq, &a3_pq_max, gt);
      push(a2[i-1], a3_pq, &a3_pq_max, gt);
    } else {
      a3_min[i-1] = a3_min[i];
    }
  }
  long long result = LLONG_MIN;
  for (int i=0;i<=n;i++) {
    if (a1_max[i] - a3_min[i] > result) {
      result = a1_max[i] - a3_min[i];
    }
  }
  cout << result << endl;  
}


Measured memory_bytes: 4096
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
const int Dx[8] = {0,1,1,1,0,-1,-1,-1}, Dy[8] = {-1,-1,0,1,1,1,0,-1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
int n;
int V;
int a[200], b[200], c[100], d[100];
vector<int> G[200];
int match[200];
bool used[200];
void add_edge(int u,int v){
    G[u].push_back(v);
    G[v].push_back(u);
}
bool dfs(int v){
    used[v]=true;
    for(int i=0;i<G[v].size();i++){
        int u=G[v][i], w=match[u];
        if(w<0||!used[w]&&dfs(w)){
            match[v]=u;
            match[u]=v;
            return true;
        }
    }
    return false;
}
int bipartite_matching(){
    int res=0;
    for(int i=0;i<V;i++){
        match[i]=-1;
    }
    for(int v=0;v<V;v++){
        if(match[v]<0){
            for(int i=0;i<V;i++){
                used[i]=0;
            }
            if(dfs(v)){
                res++;
            }
        }
    }
    return res;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    V=n*2;
    for(int i=0;i<2*n;i++) {
        cin>>a[i]>>b[i];
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(a[i]<a[j+n]&&b[i]<b[j+n]){
                add_edge(i,j+n);
            }
        }
    }
    cout <<bipartite_matching() << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define MAX 100000
void inarray(int a[], int n){
    for(int i = 0; i < n; i++) cin >> a[i];
}

int main(){
    int n; cin >> n;
    int a[n]; inarray(a,n);
    sort(a,a+n);
    cout << a[n/2] - a[n/2-1] << endl;
    return 0;
}

Measured memory_bytes: 640
//In the name of Allah :)
#include <bits/stdc++.h>
using namespace std;
string to_string(char c) { return string(1,c); }
string to_string(bool b) { return b ? "true" : "false"; }
string to_string(const char* s) { return (string)s; }
string to_string(string s) { return s; }
template<class A> string to_string(complex<A> c) { 
	stringstream ss; ss << c; return ss.str(); }
string to_string(vector<bool> v) { 
	string res = "{"; for(int i = 0; i < (int)v.size(); i++) res += char('0'+v[i]);
	res += "}"; return res; }
template<size_t SZ> string to_string(bitset<SZ> b) {
	string res = ""; for(size_t i = 0; i < SZ; i++) res += char('0'+b[i]);
	return res; }
template<class A, class B> string to_string(pair<A,B> p);
template<class T> string to_string(T v) { // containers with begin(), end()
	bool fst = 1; string res = "{";
	for (const auto& x: v) {
		if (!fst) res += ", ";
		fst = 0; res += to_string(x);
	}
	res += "}"; return res;
}
template<class A, class B> string to_string(pair<A,B> p) {
	return "("+to_string(p.first)+", "+to_string(p.second)+")"; }
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {
	cerr << to_string(h); if (sizeof...(t)) cerr << ", ";
	DBG(t...); }
#ifdef LOCAL // compile with -DLOCAL
#define wis(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "] : [", DBG(__VA_ARGS__)
#else
#define wis(...) 0
#endif
typedef long long ll;
const int MOD = 1e9 + 7, INF = 1e9 + 5;
const ll LONG_INF = 1e18 + 10;
inline ll powmod(ll a, ll b){ll res=1;for(;b;b>>=1,a=a*a%MOD)if(b&1)res=res*a%MOD;return res;}
inline ll power(ll a, ll b){ll res=1;for(;b;b>>=1,a=a*a)if(b&1)res=res*a;return res;}

const int MAXN = 2e5 + 10;
ll n, k;
vector <ll> a;

bool ok(ll mid){
        ll need = 0;
        for(ll i : a){
                need += i / mid;
                if(i % mid == 0)
                        need--;
        }
        return need <= k;
}

int main(){
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
        cin >> n >> k;
        a.resize(n);
        for(ll& i : a){
                cin >> i;
        }
        int l = 0, r = 1e9 + 5;
        while(r - l > 1){
                int mid = (r + l) / 2;
                if(ok(mid))
                        r = mid;
                else
                        l = mid;
        }
        cout << r << '\n';
}


Measured memory_bytes: 4728
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<set>
#include<cstring>
using namespace std;
long long int mod = 1e9 + 7;
template <class T>
void inputV(vector<T> &x, int n){
  for(int i=0; i<n; i++) cin >> x[i];
}

int main() {
  int x, y; cin >> x >> y; cout << x + y / 2 << endl;
  return 0;
}


///


Measured memory_bytes: 256
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}


macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let t: usize = sc.cin();
    let mut dp_b = vec![0; 7000]; // dp_b[t] = (t までの美味しさの合計最大)
    let mut qs: Vec<_> = (0..n).map(|_| {
        let a: usize = sc.cin();
        let b: usize = sc.cin();
        (a, b)
    }).collect();
    qs.sort();
    let mut ans = 0;
    for &(a, b) in qs.iter() {
        for i in 0..t {
            ans = max!(ans, dp_b[i] + b);
        }
        for i in (0..7000).rev() {
            if i + a >= 7000 { continue }
            if dp_b[i] + b > dp_b[i + a] {
                dp_b[i + a] = dp_b[i] + b;
            }
        }
    }
    put!(ans);
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> { self.cin::<String>().chars().collect() }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> { (0..n).map(|_| self.cin()).collect() }
}


Measured memory_bytes: 4352