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

string S;
int Q;
deque<char> dq;

int main() {
    cin >> S;
    for (int i = 0; i < S.length(); i++) {
        dq.push_back(S[i]);
    }

    bool fr_is_fr = true;

    cin >> Q;
    for (int i = 0; i < Q; i++) {
        int t;
        cin >> t;
        
        if (t == 1) {
            fr_is_fr = !fr_is_fr;
        }
        else {
            int f;
            char c;
            cin >> f >> c;

            if (fr_is_fr) {
                if (f == 1) {
                    dq.push_front(c);
                }
                else {
                    dq.push_back(c);
                }
            }
            else {
                if (f == 2) {
                    dq.push_front(c);
                }
                else {
                    dq.push_back(c);
                }
            }
        }
    }

    if (fr_is_fr) {
        while (!dq.empty()) {
            char tmp = dq.front();
            dq.pop_front();
            cout << tmp;
        }
    }
    else {
        while (!dq.empty()) {
            char tmp = dq.back();
            dq.pop_back();
            cout << tmp;
        }
    }

    cout << endl;
    

    

    return 0;
}

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

int main(){
  int N,K;
  cin >> N >> K;
  set <int> check;
  for(int i=0;i<K;i++){
    int d;
    cin >> d;
    for(int j=0;j<d;j++){
      int num;
      cin >> num;
      check.insert(num);
    }
  }
  
  cout << N - check.size() << endl;
}
  

Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <iomanip>
#include <cstdlib>
#include <cctype>
#define ll long long
#define PI 3.14159265358979323846
using namespace std;
const int maxn = 1e6+7;

int main() {
	int n;
	string str;
	cin>>n>>str;
	int totl=0,totr=0;
	for(int i=0; i<str.length(); i++) {
		if(str[i]=='(') {
			totl++;
		} else {
			if(totl>0) {
				totl--;
			} else {
				totr++;
			}
		}
	}
	for(int i=0; i<totl; i++) {
		str=str+')';
	}
	for(int i=0; i<totr; i++) {
		str='('+str;
	}
	cout<<str<<endl;
	return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

type contest struct {
	in  io.Reader
	out io.Writer
}

func (con *contest) Scan(a ...interface{}) (int, error) {
	return fmt.Fscan(con.in, a...)
}
func (con *contest) Scanln(a ...interface{}) (int, error) {
	return fmt.Fscanln(con.in, a...)
}
func (con *contest) Scanf(f string, a ...interface{}) (int, error) {
	return fmt.Fscanf(con.in, f, a...)
}
func (con *contest) Print(a ...interface{}) (int, error) {
	return fmt.Fprint(con.out, a...)
}
func (con *contest) Println(a ...interface{}) (int, error) {
	return fmt.Fprintln(con.out, a...)
}
func (con *contest) Printf(f string, a ...interface{}) (int, error) {
	return fmt.Fprintf(con.out, f, a...)
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	con := &contest{in: in, out: out}
	con.main()
}

func (con *contest) main() error {
	var x, a, b int
	con.Scan(&x, &a, &b)
	if -a+b <= 0 {
		con.Println("delicious")
	} else if -a+b <= x {
		con.Println("safe")
	} else {
		con.Println("dangerous")
	}
	return nil
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
// #include <numeric>
#include <complex>

#define FAST ios_base::sync_with_stdio(false); cin.tie(0)
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define repr(i, a, b) for(int i=int(a); i>=int(b); i--)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
typedef long long int ll;
#define iceil(x,y) (x+y-1)/y

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

bool is_prime(const unsigned n){
    switch(n){
        case 0: // fall-through
        case 1: return false;
        case 2: // fall-through
        case 3: return true;
    } // check n > 3 

    if(n%2 == 0) return false;
    if(n%3 == 0) return false;
    // n is not multiple of 2 and 3 -> n is not multiple of 6

    if(n%6 != 1 && n%6 != 5) return false;
    // 6k+1 and 6k+5(6k-1) may be prime
	
    for(unsigned i=5;i*i<=n;i+=6){
        if(n%i     == 0) return false; // 6n-1
        if(n%(i+2) == 0) return false; // 6n+1
    }

    return true;
}

int main() {
	FAST;

	int n;
	cin >> n;
	int cnt=0;
	rep(i,1,55556) {
		if (is_prime(i) && (i%5==1)) {
			cout << i << " ";
			cnt++;
		}
		if (cnt == n) {
			cout << "\n";
			return 0;
		}
	}

}

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

int main() {
  int N;
  cin >> N;
  int b = N % 2;
  double a = 0;
  if (N == 1)
  {
    a = 1;
  }
  else if(b == 1)
  {
    int c = (N / 2) +1;
    a = ((double)c)/N ;
  }
  else
  {
    a = 0.5;
  }
  cout << a << endl;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
	public static void main(String[] args){
		int n;
		Scanner scan = new Scanner(System.in);
		while(true){
			n = scan.nextInt();
			if(n == 0){
				break;
			}
			System.out.println("" + aoj0052(n));
		}
	}
	static int aoj0052(int n){
		int res = 0, m = 0;
		for(int i = n;i / 5 != 0;i/=5){
			m++;
		}
		while(m > 0){
			res += n / (int)Math.pow(5.0, (double)m);
			m--;
		}
		return res;
	}
}

Measured memory_bytes: 17172
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<set>
typedef int ll;
typedef unsigned un;
typedef std::string str;
typedef std::pair<ll,ll> pll;
ll read(){ll x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}return f*x;}
ll max(ll a,ll b){return a>b?a:b;}
ll min(ll a,ll b){return a<b?a:b;}
void umax(ll& a,ll t){if(t>a)a=t;}
void umin(ll& a,ll t){if(t<a)a=t;}
const ll INF=1ll<<28;
#define MAXN 200011
std::vector<ll>g[MAXN];
ll dfn[MAXN],low[MAXN],scnt=0,scc[MAXN],cur=0;
ll s[MAXN],top=0;
bool ins[MAXN];
void tarjan(ll u)
{
	s[++top]=u,ins[u]=1;
	dfn[u]=low[u]=++cur;
	for(auto v:g[u])
	{
		if(!dfn[v])tarjan(v),umin(low[u],low[v]);
		else if(ins[v])umin(low[u],dfn[v]);
	}
	if(dfn[u]==low[u])
	{
		++scnt;
		while(s[top]!=u)scc[s[top]]=scnt,ins[s[top--]]=0;
		scc[s[top]]=scnt,ins[s[top--]]=0;
	}
}
ll all;
int main()
{
	ll n=read(),Xor=read(),And=read(),Or=read();
	all=(1<<(n+1))-1;
	for(ll s=0;s<=all;++s)
	{
		if((And&s)==And)
			for(ll t=all^s;;t=(t-1)&(all^s))
			{
				ll p=And|t;
				g[p].push_back(s^Xor);
				g[s].push_back(p^Xor);
				if(!t)break;
			}
		if((Or&s)==s)
			for(ll t=s;;t=(t-1)&s)
			{
				ll p=(Or^s)|t;
				g[p].push_back(s^Xor);
				g[s].push_back(p^Xor);
				if(!t)break;
			}
	}
	for(ll s=0;s<=all;++s)
		if(!dfn[s])tarjan(s);
	ll c=0;
	std::vector<ll>ans;
	for(ll s=0;s<=all;++s)
	{
		if(scc[s]==scc[s^Xor])return puts("No"),0;
		else if(c<(1<<n)&&scc[s]<scc[s^Xor])ans.push_back(s),++c;
	}
		
	puts("Yes");
	for(ll i=0;i<ans.size();++i)
	{
		if(i)putchar(' ');
		printf("%d",ans[i]);
	}
	puts("");
	return 0;
}


Measured memory_bytes: 143544
def main():
    from builtins import int, str, map, list, dict, float, print, len, sorted, max, min
    from itertools import accumulate, permutations, combinations
    from collections import deque, defaultdict, Counter
    from operator import itemgetter
    from bisect import bisect_left, bisect_right, bisect
    from heapq import heappop, heappush
    from fractions import gcd
    import sys, re, math, copy
    sys.setrecursionlimit(10 ** 6)

    input = sys.stdin.readline
    input_str = (lambda: input().rstrip())
    input_list = (lambda: input().rstrip().split())
    input_number = (lambda: int(input()))
    input_number_list = (lambda: list(map(int, input_list())))

    alphabet = 'abcdefghijklmnopqrstuvwxyz'
    N = input_number()
    S = [None] * N
    for i in range(N):
        S[i] = list(input_str())

    ans = ""
    for c in alphabet:
        t = 10**9
        for i in range(N):
            t = min(t,int(Counter(S[i])[c]))
        ans += c*t
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5160
#include <bits/stdc++.h>
using  namespace std;
typedef long long ll;
#define RAP(i, n) for(ll i=0;i<(n);i++)
#define FOR(i, a, b) for(ll i=(a);i<(b);i++)

#include <iostream>
#include <vector>
using namespace std;

//重複順列
vector<ll> buf;
void permutation(ll i, const ll size, const ll range_start, const ll range_end)
{
    if (i == size) {
      // ここで所望の作業を行う
      for(ll itr:buf){
        cout << itr;
      }
    }
    else{
        for(ll j = range_start; j <= range_end; ++j){
            buf[i] = j;
            permutation(i + 1, size, range_start, range_end);
        }
    }
}

int main(void)
{
 ll n, k, d, a, ans=0;
 cin >> n >> k;
 vector<ll> A(n);
 RAP(i,k){
   cin >> d;
   RAP(j,d){
    cin >> a;
    A[a-1]++;
   }
 }
 RAP(i,n){
   if(A[i] == 0){
     ans++;
   }
 }
 cout << ans << endl;
 return 0;
}


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

using namespace std;
const int N=2e5+5,mod=1e9+7;
#define ll long long
bool vis[N];
int a[N];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    vector<int>v(n),a(n),b(n);
    int A,B;
    for(int i=0;i<n;i++)
        cin>>a[i],v[i]=i+1;
    for(int i=0;i<n;i++)
        cin>>b[i];
    int cnt=0;
    do
    {
        cnt++;
        if(a==v) A=cnt;
        if(b==v) B=cnt;

    }while(next_permutation(v.begin(),v.end()));
    cout<<abs(A-B)<<endl;
    return 0;
}


Measured memory_bytes: 256
main :: IO ()
main = do
  [a,t] <- concat . words <$> getLine
  let (a',t') =(toBool a,toBool t)
  putStrLn $ [toHonest (if a' then t' else not t'), '\n']

toBool :: Char -> Bool
toBool 'H' = True
toBool 'D' = False
toBool _ = False

toHonest :: Bool -> Char
toHonest f = if f then 'H' else 'D'


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

const int MAXK = 1e5 + 10;
const int MOD = 1e9 + 7;

int pref[MAXK],dp[MAXK],N,K;

int calc(int a,int b){
	if(a < 0) a = 0;
	int ans = pref[b];
	if(a != 0) ans -= pref[a-1];
	return ans % MOD;
}

int main(){

	cin >> N >> K;

	dp[0] = 1;

	for(int kid = 1;kid<=N;kid++){

		int c;
		cin >> c;

		pref[0] = dp[0];
		dp[0] = 0;
		for(int i = 1;i<=K;i++){
			pref[i] = (pref[i-1] + dp[i]) % MOD;
		}

		for(int i = 0;i<=K;i++){
			dp[i] = calc(i-c,i);
		}

	}

	int ans = dp[K];
	if(ans < 0) ans += MOD; 
	printf("%d\n",ans);

	return 0;

}

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

int main()
{
ll n , d ;
cin >> n >> d ;
rep(i,n){
  ll x , y ;
  cin >> x >> y ;
  if(x*x+y*y<=d*d)ans++;
}
cout << ans << endl;
return 0;
}

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

using namespace std;

int main(int argc, char *argv[])
{
    
    
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);

    int n,rank,used[13][4]={0};
    char suit;
    string suit_text = "SHCD";
    map<char, int> suits = {{'S', 0}, {'H', 1}, {'C', 2}, {'D', 3}};
    
    
    cin >> n;
    
    while (n--) {
        cin >> suit >> rank;
        used[rank-1][suits[suit]]=1;
    }
    
    for (int j = 0; j<4; j++) {
        for (int i = 0; i<13; i++) {
            if (!used[i][j]) {
                cout << suit_text[j] << " " << i+1 << endl;
            }
        }
    }
    
    return 0;
}


Measured memory_bytes: 3192
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
#include<numeric>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define REP(i, n) for(int i = 0;i < (n);i++)
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=998244353;
const llint inf=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-10;
template <class T,class U>bool chmin(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool chmax(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(const vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(const vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}

int main(void){
	int i,j,A,B,C,D;
	cin>>A>>B>>C>>D;
	static llint dp[3001][3001]={};//前がyoko
	static llint ep[3001][3001]={};//前がue
	dp[A][B]=1;
	for(i=A;i<=C;i++){
		for(j=B;j<=D;j++){
			if(i==A&&j==B){continue;}
			dp[i][j]=(ep[i-1][j]+dp[i-1][j]*j)%mod;
			ep[i][j]=(dp[i][j-1]*i+ep[i][j-1]*i)%mod;
		}
	}
	cout<<(dp[C][D]+ep[C][D])%mod<<endl;
	return 0;
}


Measured memory_bytes: 144268
from collections import deque

n, q = map(int, input().split())
d = deque([input().split() for _ in range(n)])
a = []
tt = 0

while d:
    t = int(d[0][1])
    if t > q:
        tt += q
        d.append([d[0][0], str(t-q)])
        d.popleft()
    else:
        tt += t
        p = d.popleft()
        a.append([p[0], tt])

for n, t in a:
    print(n, t)


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

#define HEAP priority_queue
#define rep(i, n) for(int i = 0, _end_ = (n); i < _end_; ++i)
#define per(i, n) for(int i = (n) - 1; i >= 0 ; --i)
#define forn(i, l, r) for(int i = (l), _end_ = (r); i <= _end_; ++i)
#define nrof(i, r, l) for(int i = (r), _end_ = (l); i >= _end_; --i)
#define FOR(a, b) for(auto (a): (b))
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define X first
#define Y second
#define eps 1e-6
#define pi 3.1415926535897932384626433832795
#define SZ(x) (int)x.size()
#define ALL(x) x.begin(), x.end()
#define FILL(a, b) memset((a), (b), sizeof((a)))
#define MCPY(a, b) memcpy((a), (b), sizeof((b)))

using namespace std;

typedef long long LL;
typedef double flt;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef pair<int,int> pii;
typedef pair<int,LL> pil;
typedef pair<LL,int> pli;
typedef pair<LL,LL> pll;
typedef vector<pil> vil;
typedef vector<pii> vii;
typedef vector<pli> vli;
typedef vector<pll> vll;

const int iinf = 1e9 + 7;
const int oo = 0x3f3f3f3f;
const LL linf = 1ll << 60;
const flt dinf = 1e60;

template <typename T>
inline void scf(T &x)
{
	bool f = 0; x = 0; char c = getchar();
	while((c < '0' || c > '9') && c != '-') c = getchar();
	if(c == '-') { f = 1; c = getchar(); }
	while(c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); }
	if(f) x = -x; return;
}
template <typename T1, typename T2>
void scf(T1 &x, T2 &y) { scf(x); return scf(y); }
template <typename T1, typename T2, typename T3>
void scf(T1 &x, T2 &y, T3 &z) { scf(x); scf(y); return scf(z); }
template <typename T1, typename T2, typename T3, typename T4>
void scf(T1 &x, T2 &y, T3 &z, T4 &w) { scf(x); scf(y); scf(z); return scf(w); }

inline char mygetchar(){ char c = getchar(); while(c == ' ' || c == '\n') c = getchar(); return c; }

template <typename T> inline bool chkmax(T &x, const T &y){ return y > x ? x = y, 1 : 0; }
template <typename T> inline bool chkmin(T &x, const T &y){ return y < x ? x = y, 1 : 0; }

#ifdef ONLINE_JUDGE
#define debug(...) ;
#else
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define DEBUG
#endif

//---------------------------------------------------------head----------------------------------------------------

const int maxn = 1e5 + 100;

int n;
int a[3][maxn];
bool f[2], g[2];
vi b[2];

namespace BIT
{
	int num[maxn];
	int lowbit(int i){ return i & (-i); }
	void M(int i, int x)
	{
		for(; i; i ^= lowbit(i)) num[i] += x;
		return;
	}
	int Q(int i)
	{
		int ret = 0;
		for(; i <= n; i += lowbit(i)) ret += num[i];
		return ret;
	}
	void C(){ FILL(num, 0); }
}

void solve(vi &a, bool &f)
{
	BIT::C();
	for(int x: a)
	{
		f ^= (BIT::Q(x) & 1);
		BIT::M(x, 1);
	}
	return;
}

int main()
{
	scf(n);
	rep(i, 3) forn(j, 1, n) scf(a[i][j]);
	forn(i, 1, n)
	{
		int x = a[1][i] - a[0][i], y = a[2][i] - a[1][i];
		if(x != y || abs(x) != 1){ puts("No"); return 0; }
		if(x == -1) f[i & 1] ^= 1;
		a[1][i] -= 2;
		if(a[1][i] % 3 != 0){ puts("No"); return 0; }
		a[1][i] /= 3;
		if(!((a[1][i] ^ i) & 1)){ puts("No"); return 0; }
		b[i & 1].pb(a[1][i] + 1);
	}
	rep(_, 2) solve(b[_], g[_]);
	puts(g[0] == f[1] && g[1] == f[0] ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 2556
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		String T = sc.next();
		if(T.substring(0, T.length()-1).equals(S)){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}

	}

}

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

using namespace std;

int main(){
	ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    string n;
    cin >> n;

    long long s = 0LL;
    int l = n.size();
    for(int i = 0; i < l; ++i){
    	s += (n[i] - '0');
    }

    cout << (s%9?"No":"Yes");
    
	return 0;
}

Measured memory_bytes: 3740
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
//#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

signed main(void){
    int N,K;
    cin >> N >> K;
    int Ans=0;
    while(N>0){
        Ans++;
        N/=K;
    }
    cout << Ans << endl;
}



Measured memory_bytes: 256
def resolve():
    N = int(input())
    s = [input() for _ in range(N)]
    M = int(input())
    t = [input() for _ in range(M)]
    sdict = {k: 0 for k in set(s)}
    tdict = {k: 0 for k in set(t)}
    for w in s:
        sdict[w] += 1
    for w in t:
        tdict[w] += 1
    ks = set(s) | set(t)
    ans = 0
    for key in ks:
        ans = max(ans, sdict.get(key, 0) - tdict.get(key, 0))

    print(ans)

    return
resolve()

Measured memory_bytes: 9116
def main():
    K = int(input())
    A = list(map(int, input().split()))
    A = A[::-1]
    if A[0] != 2:
        print(-1)
        return
    n = 2
    lower_n, upper_n = 2, 3
    for a in A:
        # [lower_n, upper_n]内にaの倍数が無ければNG
        if upper_n // a - (lower_n - 1) // a == 0:
            print(-1)
            return
        lower_n = (lower_n + a - 1) // a * a  # ceil(lower_n/a) * a
        upper_n = upper_n // a * a + a - 1  # # floor(upper_n/a) * a + a - 1
    print('{} {}'.format(lower_n, upper_n))


if __name__ == '__main__':
    main()

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

int main(){
  int n, cnt=0; cin>>n;
  map<string, int> ma;
  string s;
  for(int i=0;i<n;i++){
    cin>>s;
    ma[s]++;
    cnt=max(cnt, ma[s]);
  }
  
  for(auto m:ma){
    if(cnt==m.second){
      cout<<m.first<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 25216
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<vector<int>> v(2, vector<int>(n));
  for(int i = 0; i < 2; ++i){
    for(int j = 0; j < n; ++j){
      cin >> v[i][j];
    }
  }
  vector<int> acc0(n + 1, 0), acc1(n + 1, 0);
  for(int i = 1; i < n + 1; ++i){
    acc0[i] = v[0][i - 1] + acc0[i - 1];
    acc1[i] = v[1][i - 1] + acc1[i - 1];
  }
  int ans = 0;
  for(int i = 1; i < n + 1; ++i){
    ans = max(ans, (acc0[i] - acc0[0]) + (acc1[n] - acc1[i - 1]));
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
a[1<<20];
n=1<<20;
main(i,c){
	*a=a[1]=1;
	for(;++i<n;)
		if(!a[i])
			for(c=1;++c*i<n;)
				a[i*c]=1;
	for(;scanf("%d",&n),n;){
		c=0;
		for(i=n;++i<=2*n;)
			!a[i]&&c++;
		printf("%d\n",c);
	}
	exit(0);
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define pb push_back
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define SZ(n) ((int)(n).size())
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;

ll dp[200000];
pair<ii,ll> a[1001];

bool cmp(pair<ii,ll> &x, pair<ii,ll> &y){
    return x.fst.fst+x.fst.snd < y.fst.fst+y.fst.snd;
}

int main(){FIN;
    ll n,ans=0; cin >> n;
    fore(i,0,n) cin >> a[i].fst.fst >> a[i].fst.snd >> a[i].snd;
    sort(a,a+n,cmp);
    fore(i,0,n){
        for(int j = a[i].fst.snd; j >= 0; j--){
            dp[j+a[i].fst.fst] = max(dp[j+a[i].fst.fst], dp[j]+a[i].snd);
        }
    }
    fore(i,0,200000) ans = max(ans,dp[i]);
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rep1(i, n) for (ll i = 1; i < n; i++)
using P = pair<ll, ll>;

int main()
{
    double w, h, x, y;
    cin >> w >> h >> x >> y;
    cout << w * h / 2 << " ";
    if (x == w / 2 && y == h / 2)
        cout << 1 << endl;
    else
        cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 3796
main = do
  getLine
  a <- getLine
  putStrLn $ ans a

ans :: String -> String
ans s 
  | (length s) `mod` 2 == 1 = "No"
  | take ((length s) `div` 2) s == drop ((length s) `div` 2) s = "Yes"
  | otherwise ="No"


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

using namespace std;
#define endl "\n"
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
typedef long long ll;
const double PI = acos(-1);
const int mod = 1e9 + 7;
const int INF = 2e9;
const int MAX=505;

struct MaximumMatching {
	vector<int> m1, m2, seen;
	vector<vector<int> > g;
	int seen_id;
	MaximumMatching(int numNodesLeft, int numNodesRight) {
		g = vector<vector<int> >(numNodesLeft, vector<int>());
		m1 = vector<int>(numNodesLeft, -1);
		m2 = vector<int>(numNodesRight, -1);
		seen_id = 0;
		seen = vector<int>(numNodesRight, 0);
	}
	void addEdge(int leftNode, int rightNode) {
		assert(leftNode < int(m1.size()));
		assert(rightNode < int(m2.size()));
		g[leftNode].push_back(rightNode);
	}
	int getMaxMatching() {
		int ans = 0;
		for (int node = 0; node < int(m1.size()); node++) {
			seen_id++;
			if (dfs(node)) ans++;
		}
		return ans;
	}
	bool dfs(int node) {
		for (int i = 0; i < int(g[node].size()); i++) {
			int child = g[node][i];
			// if the child is not matched yet, match it with me
			if (m2[child] == -1) {
				m2[child] = node;
				m1[node] = child;
				return true;
			}

			// if the child was seen before (some other node tried to take it), leave it
			if (seen[child] == seen_id) continue;
			seen[child] = seen_id;

			// if the child is already matched with some other node, try to match that other node is some other way
			int enemy = m2[child];
			// take the child for me
			m1[enemy] = -1; m1[node] = child; m2[child] = node;
			// try to match the enemy
			if (dfs(enemy)) return true;
			// match the child with the enemy if not successful
			m1[enemy] = child; m1[node] = -1; m2[child] = enemy;
		}
		return  false;
	}

};

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

	int n;
	cin>>n;
	vector<pair<int,int>>r(n),b(n);
	for(int i=0;i<n;i++)
		cin>>r[i].first>>r[i].second;
	for(int i=0;i<n;i++)
		cin>>b[i].first>>b[i].second;
	MaximumMatching mm(n,2*n);
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(r[i].first<b[j].first&&r[i].second<b[j].second)
				mm.addEdge(i,j+n);
		}
	}
	mm.getMaxMatching();
	int ans=0;
	for(int i=0;i<mm.m1.size();i++)
		if(mm.m1[i]!=-1)
			ans++;
	cout<<ans<<endl;
	return 0;
}


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

int main()
{
    int x;
    cin >> x;

    if (x == 7 || x == 5 || x == 3) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<ctype.h>

int main() {
	int i;
	char str[1200];
	
	fgets(str, 1200, stdin);

	for (i = 0;i < strlen(str);i++) {
		if (islower(str[i])) {
			str[i] = toupper(str[i]);
		}
		else if (isupper(str[i])) {
			str[i] = tolower(str[i]);
		}
	}

	printf("%s", str);

	return 0;
}

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

#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define trav(a, x) for (auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
	cin.sync_with_stdio(false);
	cin.exceptions(cin.failbit);
	int A, B, C;
	cin >> A >> B >> C;
	int it = 0;
	while (A%2==0 && B%2==0 && C%2==0) {
		int a = A/2, b = B/2, c = C/2;
		A = b+c;
		B = a+c;
		C = a+b;
		++it;
		if (it > 1000000) {
			cout << -1 << endl;
			return 0;
		}
	}
	cout << it << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/******************************************
* AUTHOR : PANDRAVISAM SHIVA SANTHOSH *
* Handle : santhosh_80 *
* INSTITUTION : IIT Palakkad *
******************************************/
#define ll long long int 
#define rep(i,a,b) for(int i=a;i<b;i++)
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define f first
#define s second

const ll mod = 1000000007;
const ll N = 1e6;


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll a,b,c,k;
	cin >> a >> b >> c >> k;
	if(a >= k){
		cout << k << "\n";
	}
	else if( (a+b) >= k){
		cout << a << "\n";
	}
	else{
		cout << a - (k-a-b); 
	}
 	return 0;
}

Measured memory_bytes: 3592
use std::io;
use std::collections::HashMap;
use std::collections::BinaryHeap;
use std::mem;
use std::cmp;


fn read_line() -> String{
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn read_ints() -> Vec<i64>{
    let s = read_line();
    let split:Vec<&str> = s.split(" ").collect();
    split.iter().map(|&x| x.to_string().parse().unwrap()).collect()
}

fn read_int() -> i64{
    read_ints()[0]
}

fn getn(n:i64) -> i64{
    for i in  0..32 as i64{
        if (n>>i)%2 == 1{
            return i;
        }
    }
    return 0;
}

fn main(){
    let n = read_int();

    let xs = read_ints();

    let mut ys = xs.iter().map(|a|getn(*a));
    let y = ys.fold(1<<32,|x,y| cmp::min(x,y));
    println!("{}",y);
}



/*
DOCS


let mut h = HashMap::new();
let a = 5;
h.insert(a,true);
match h.get(&a){
    Some(v) => println!("{}",v),
    None    => println!("none"),
}


use std::mem;

let mut x = 5;
let mut y = 1;
mem::swap(&mut x,&mut y);


let v = vec![0;2]; // [0,0]

s.chars().nth(i as usize).unwrap();


// priority queue
// https://doc.rust-lang.org/std/collections/struct.BinaryHeap.html
use std::collections::BinaryHeap;
let mut heap = BinaryHeap::new();

heap.push(1);
heap.push(5);
heap.push(2);

assert_eq!(heap.pop(), Some(5));
assert_eq!(heap.pop(), Some(2));
assert_eq!(heap.pop(), Some(1));
assert_eq!(heap.pop(), None);


let mut vs = heap.into_vec();
vs.reverse();



*/


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

#define sswap(x, y) { x+=y; y=x-y; x-=y; }
#define LSOne(S) ((S) & (-S))

#define EPS 1e-6
#define MOD 1000000007

#define fi first
#define se second
#define pb push_back
#define ende '\n'

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define mset(x, y) memset(&x, (y), sizeof(x))

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if (c/b + (c%b ? 1 : 0) > a/d + (a%d ? 1 : 0)) cout << "No" << ende;
	else cout << "Yes" << ende;
  return 0;
}


Measured memory_bytes: 3648
/*****************************************************

*****************************************************/

#include<bits/stdc++.h>
#define MAX 9223372036854775807
#define endl "\n"
#define ll long long
#define int long long
#define pb push_back
#define pf push_front
#define ppf pop_front
#define mp make_pair
#define ip pair<int, int>
#define ff first
#define ss second

#define loop(i,n) for(int i=0;i<n;i++)
#define fast ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL)
using namespace std;

const ll MOD = 1e9+7;
const ll SZ = 107;
const ll N = 1e5+7;
const ll inf = 1e17;

int pwr(int x, int y)
{
    ll r = 1LL;
    while(y)
    {
        if(y&1)
            r = (r * x) % MOD;
        y >>= 1;
        x = (x * x) % MOD;
    }
    return r % MOD;
}

int inv(int x)
{
    return pow(x, MOD-2);
}


void solve()
{
    int n; cin>>n;
    int p[n];
    for(int i=0;i<n;i++) 
        cin>>p[i];
    int ans = 0;
    for(int i=1;i<n-1;i++)
    {
        std::vector<int> v;
        v.pb(p[i]);
        v.pb(p[i-1]);
        v.pb(p[i+1]);
        sort(v.begin(), v.end());

        if(p[i]==v[1])
            ans++;
    }
    cout<<ans;
}

signed main()
{
    int t=1;
    // cin >>t;
    while(t--){
        solve();
    }
    return 0;
}

/*****************************


****************************/

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define TRUE 1
#define FALSE 0
#define MAX 101

int isEmpty(void);
int isFull(void);
void push(int);
int pop();

int top=0;
char s[100];
int c[101];

int main(){
  int x,y,z;

  while(scanf("%s",s) != EOF){
    if(s[0] == '+'){
      x = pop() + pop();
      push(x);
    }
    else if(s[0] == '-'){
      y = pop();
      z = pop();
      x = z - y;
      push(x);
    }
    else if(s[0] == '*'){
      x = pop() * pop();
      push(x);
    }
    else{
      x = atoi(s);
      push(x);
    }
  }

  printf("%d\n",c[top]);

  return 0;
}

int isEmpty(){
  if(top == 0){
    return TRUE;
  }
  else{
    return FALSE;
  }
}

int isFull(){
  if(top >= MAX - 1){
    return TRUE;
  }
  else{
    return FALSE;
  }
}

void push(int x){
  int a;
  a = isFull();

  if(a == 1){
    printf("error\n");
  }
  else{
    top++;
    c[top] = x;
  }
}

int pop(){
  int b,re;
  b = isEmpty();

  if(b == 1){
    printf("error\n");
  }
  else{
    top--;
    re = c[top+1];
    return re;
  }
}

Measured memory_bytes: 548
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String str01 = sc.next();
    String str02 = sc.next();
    
    int count = 0;
    if(str01.equals(str02)){
    	System.out.println(count);
    }else{
    	for(int i = 0; i < str01.length(); i++){
        	if(str01.charAt(i) != str02.charAt(i)){
		 		count++;
            }
        }
      System.out.println(count);
    }
    
  }
}

Measured memory_bytes: 41172
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[4]={1,0,-1,0} , dy[4]={0,1,0,-1} ;

int cnt[600][600];
int main(){
    string s;
    cin>>s;
    int k;cin>>k;
    k--;
    int idx=0;
    while(1){
        if(s[idx]!='1'){
            cout<<s[idx]<<endl;
            return 0;
        }
        else {
            if(k==idx){
                cout<<1<<endl;
                return 0;
            }
        }
        idx++;
    }
   return 0;
}

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

using namespace std;

int dp[3005][3005];

int main(){
    //freopen("LCS.INP", "r", stdin);

    string s, t;
    getline(cin, s);
    getline(cin, t);
    int lens = s.size();
    int lent = t.size();
    s = " " + s;
    t = " " + t;

    for (int i = 0; i <= lens; i++){
        dp[i][0] = 0;
    }
    for (int i = 0; i <= lent; i++){
        dp[0][i] = 0;
    }
    for (int i = 1; i <= lens; i++){
        for (int j = 1; j <= lent; j++){
            dp[i][j] = 0;
            if (s[i] == t[j]){
                dp[i][j] = dp[i - 1][j - 1] + 1;
            }
            else {
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            }
        }
    }
    string res;
    while (lens > 0 && lent > 0){
        if (s[lens] == t[lent]){
            res += s[lens];
            lens--;
            lent--;
        }
        else if (dp[lens - 1][lent] > dp[lens][lent - 1]){
            lens--;
        }
        else {
            lent--;
        }
    }
    for (int i = res.size() - 1; i >= 0; i--){
        cout << res[i];
    }
    return 0;
}


Measured memory_bytes: 35456
import java.util.*;
import java.awt.*;
import static java.lang.System.*;
import static java.lang.Math.*;
//Loopで使う文字列の長さは固定！
//intで大丈夫？オーバーフローしない？
//Loop回数は本当に10⁹以内になってる？Loopは回る？？
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(in);
        int W=sc.nextInt();
        int H=sc.nextInt();
        int n=sc.nextInt();
        int[][] map=new int[W][H];
        for (int i = 0; i <W; i++) {
            for (int j = 0; j < H; j++) {
                map[i][j]=1;
            }
        }
        for (int i = 0; i < n; i++) {
            int x=sc.nextInt();
            int y=sc.nextInt();
            int a=sc.nextInt();
            if(a==1){
                for (int j = 0; j < x; j++) {
                    for (int k = 0; k <H; k++) {
                        map[j][k]=0;
                    }
                }
            }else if(a==2){
                for (int j = x; j < W; j++) {
                    for (int k = 0; k < H; k++) {
                        map[j][k]=0;
                    }
                }
            }else if(a==3){
                for (int j = 0; j < W; j++) {
                    for (int k = 0; k < y; k++) {
                        map[j][k]=0;
                    }
                }
            }else{
                for (int j = 0; j < W; j++) {
                    for (int k = y; k < H; k++) {
                        map[j][k]=0;
                    }
                }
            }
        }
        int ans=0;
        for (int i = 0; i < W; i++) {
            for (int j = 0; j < H; j++) {
                ans+=map[i][j];
            }
        }
        out.println(ans);
    }
}

Measured memory_bytes: 24868
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<time.h>
#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=n-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin>>s;
	ll ret=0,g=0,p=0;
	REP(i,(ll)s.size()) {
		if(s[i]=='g') {
			if(p+1<=g) {
				p++;
				ret++;
			} else {
				g++;
			}
		}
		if(s[i]=='p') {
			if(p+1<=g) {
				p++;
			} else {
				g++;
				ret--;
			}
		}
	}
	cout<<ret<<endl;
}


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

using namespace std ;

#define N 100010
#define inf 0x3f3f3f3f

int n , K , d[ N ] ;
int head[ N << 1 ] , cnt , vis[ N ] ;
struct edge {
	int to , nxt ;
}e[ N << 1 ] ; 
priority_queue< pair<int,int> , vector< pair<int,int> > , greater< pair<int,int> > > q ;

void ins( int u , int v ) {
	e[ ++ cnt ].to = v ;
	e[ cnt ].nxt = head[ u ] ;
	head[ u ] = cnt ;
}

int main() {
	for( int i = 0 ; i < N ; i ++ ) d[ i ] = inf ;
	scanf( "%d" , &n ) ;
	for( int i = 1 ; i < n ; i ++ ) {
		int u , v ;
		scanf( "%d%d" , &u , &v ) ;
		ins( u , v ) ; ins( v , u ) ;
	}
	scanf( "%d" , &K ) ;
	for( int i = 1 ; i <= K ; i ++ ) {
		int p , v ;
		scanf( "%d%d" , &v , &p ) ;
		d[ v ] = p ;
		q.push( make_pair( p , v ) ) ;
	}
	while( !q.empty() ) {
		int u = q.top().second , val = q.top().first ;
		q.pop() ; 
		for( int i = head[ u ] ; i ; i =e[ i ].nxt ) {
			int v = e[ i ].to ;
			if( d[ v ] == inf ) d[ v ] = val + 1 , q.push( make_pair( d[ v ] , v ) ) ;
			if( fabs( d[ v ] - d[ u ] ) != 1 ) {
				puts( "No" ) ;
				return 0 ;
			}
		}
	}
	puts( "Yes" ) ;
	for( int i = 1 ; i <= n ; i ++ ) {
		printf( "%d\n" , d[ i ] ) ;
	}
	return 0 ;
}

Measured memory_bytes: 4212
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;

int main() {
    ll x, k, d;
    cin >> x >> k >> d;
    ll d1 = abs(x) / d;
    ll d2 = abs(x) % d;
    ll d3 = k - abs(x) / d;
    if (k <= d1) {
        cout << abs(x) - k * d << endl;
    }
    else if (d3 % 2 == 0) {
            cout << d2 << endl;
    }
    else {
        cout << abs(d2 - d) << endl;
    }
}


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

const int maxn = 1005;

#define LL long long

int a, b, c;
int K;

LL A[maxn], B[maxn], C[maxn];
LL AB[maxn * maxn];

priority_queue< pair<LL, pair<int, int> > > pq;

void work()
{
    cin >>a >>b >>c >>K;

    for(int i = 0; i < a; i++) cin >>A[i];
    for(int i = 0; i < b; i++) cin >>B[i];
    for(int i = 0; i < c; i++) cin >>C[i];

    for(int i = 0; i < a; i++)
        for(int j = 0; j < b; j++)
            AB[i * b + j] = A[i] + B[j];

    AB[a * b] = -INT_MAX;
    C[c] = -INT_MAX;

//    sort(AB, AB + a * b, [](int x, int y){return x > y;});
//    sort(C, C + c, [](int x, int y){return x > y;});
    sort(AB, AB + a * b);
    sort(C, C + c);
    reverse(AB, AB + a * b);
    reverse(C, C + c);

    for(int i = 0; i < c; i++) pq.push(make_pair(AB[0] + C[i], make_pair(0, i)));

    while(K--)
    {
        pair<LL, pair<int, int> > p = pq.top();
        pq.pop();

        cout <<p.first <<endl;

        int u = p.second.first, v = p.second.second;

        pq.push(make_pair(AB[u + 1] + C[v], make_pair(u + 1, v)));
    }
}

int main()
{
#ifdef yukihana0416
freopen("in.txt","r",stdin);
#endif // yukihana0416
    work();
    return 0;
}


Measured memory_bytes: 8192
from bisect import bisect
N = int(input())
A = list(map(int,input().split()))
cums = [0]
for a in A:
    cums.append(cums[-1] + a)

lmx = []
lmn = []
for i in range(2,N-1):
    j = bisect(cums,(cums[i]+1)//2)
    a1,b1 = cums[j], cums[i]-cums[j]
    a2,b2 = cums[j-1], cums[i]-cums[j-1]
    if abs(a1-b1) < abs(a2-b2):
        a,b = (a1,b1) if a1<b1 else (b1,a1)
    else:
        a,b = (a2,b2) if a2<b2 else (b2,a2)
    lmn.append(a)
    lmx.append(b)

rmx = []
rmn = []
MX = cums[-1]
for i in range(2,N-1):
    j = bisect(cums, cums[i] + (MX-cums[i])//2)
    a1,b1 = cums[j]-cums[i], MX-cums[j]
    a2,b2 = cums[j-1]-cums[i], MX-cums[j-1]
    if abs(a1-b1) < abs(a2-b2):
        a,b = (a1,b1) if a1<b1 else (b1,a1)
    else:
        a,b = (a2,b2) if a2<b2 else (b2,a2)
    rmn.append(a)
    rmx.append(b)

ans = MX
for ln,lx,rn,rx in zip(lmn,lmx,rmn,rmx):
    d = max(lx,rx) - min(ln,rn)
    ans = min(ans, d)
print(ans)

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

const int MAXN = 100010;
int dis[MAXN];
std::map<int, std::vector<int> > es[MAXN];
std::set<int> vis[MAXN];
std::vector<int> upd, tmp;
void extend(int u, int c, int s) {
	if (s > dis[u] || vis[u].count(c)) return ;
	vis[u].insert(c);
	if (s < dis[u]) dis[u] = s, upd.push_back(u);
	for (auto t : es[u][c]) extend(t, c, s);
}
int n, m;
int main() {
	std::ios_base::sync_with_stdio(false), std::cin.tie(0);
	std::cin >> n >> m;
	for (int i = 1; i <= m; ++i) {
		int u, v, w;
		std::cin >> u >> v >> w;
		es[u][w].push_back(v);
		es[v][w].push_back(u);
	}
	memset(dis, 0x3f, sizeof dis);
	upd.push_back(1); dis[1] = 0;
	int S = 0;
	while (!upd.empty()) {
		++S;
		std::swap(upd, tmp);
		for (auto u : tmp)
			for (auto t : es[u])
				for (auto v : t.second)
					extend(v, t.first, S);
		tmp.clear();
	}
	std::cout << (dis[n] <= n ? dis[n] : -1) << std::endl;
	return 0;
}


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

int main(){
    int a, b, c, d, e;
    while (cin >> a >> b >> c >> d >> e) {
        if (a == 0) {
            break;
        }
        int na, nb, nc, res = 0;
        cin >> na >> nb >> nc;
        if (nc >= d) {
            cout << e * nc + b * nb + a * na << endl;
        } else {
            res = c * nc + b * nb + a * na;

            int stn = d;
            stn -= nc;

            if (stn > nb) {
                stn -= nb;
                nb = 0;
            } else {
                nb -= stn;
                stn = 0;
            }

            if (stn > na) {
                stn -= na;
                na = 0;
            } else {
                na -= stn;
                stn = 0;
            }

            cout << min(res, e * d + b * nb + a * na) << endl;
        }
    }
    return 0;
}

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

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cout << #a << " = " << a << endl;

const double PI = acos(-1.0);
const LL INF = 1e9 + 47;
const LL LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	int n;
	cin >> n;
	map<VI, int> mp;
	VI a(n);
	iota(ALL(a), 1);
	int sz = 0;
	do
	{
		mp[a] = sz++;
	}while(next_permutation(ALL(a)));
	
	VI b(n), c(n);
	FOR(i, 0, n) cin >> b[i];
	FOR(i, 0, n) cin >> c[i];
	cout << abs(mp[b] - mp[c]);
	
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
	return 0;
}



Measured memory_bytes: 5248
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

const int INF = 1e9;
const long long LINF = 1e18;

int main() {
    long long N, K;
    cin >> N >> K;

    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    int s = -1;
    int e = -1;
    int current = 0;
    vector<int> stamp(N + 1, -1);
    vector<int> dist(N, -1);
    for (long long i = 0; i < K; i++) {
        if (dist[current] != -1)  {
            s = dist[current];
            e = i - 1;
            break;
        }
        dist[current] = i;
        stamp[i] = current;
        // cout << "stamp[i] = " << stamp[i] << endl;
        current = A[current] - 1;
    }

    // cout << "s: " << s << ", e: " << e << endl;

    if (s == -1) {
        cout << current + 1 << endl;
        return 0;
    }

    if (K <= e) {
        cout << stamp[K] + 1 << endl;
    } else {
        int d = (K - e - 1) % (e - s + 1);
        // cout << "d: " << d << endl;
        cout << stamp[s + d] + 1 << endl;
    }

    return 0;
}


Measured memory_bytes: 5260
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define bitrep(X,N) for(ll X = 0; X < (1 << (N)); X++)
#define PI (acos(-1.0))
#define sorta(V) sort(V.begin(), V.end())
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end() 


using namespace std;

int main(){

    int n,m;
    cin >> n >> m;
    int maxnum[] = {0,0,0,0,0,0,0,0,0,0};
    rep(i,m){
        int tmp;
        cin >> tmp;
        
        if(tmp == 1){
            maxnum[2] = 1;
        }else if(tmp == 7){
            maxnum[3] = 7;
        }else if(tmp == 4){
            maxnum[4] = 4;
        }else if(tmp == 2 || tmp == 3 || tmp == 5){
            maxnum[5] = max(maxnum[5], tmp);
        }else if(tmp == 6 || tmp == 9){
            maxnum[6] = max(maxnum[6], tmp);
        }else{
            maxnum[7] = 8;
        }
    }

    vector<int> index;

    rep(i,10){
        if(maxnum[i] != 0){
            index.pback(i);
        }
    }

    vector<string> dp(n + 1, "");

    function<string(string,string)> mymax = [](string a, string b) -> string{

        if(a.size() == b.size()){

            rep(i,a.size()){
                if(a[i] > b[i]){
                    return a;
                }else if(a[i] < b[i]){
                    return b;
                }
            }

            return a;

        }else{
            if(a.size() > b.size()){
                return a;
            }else return b;
        }

    };

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

        rep(j,index.size()){
            if(i == index[j]){
                string tmp;
                tmp.pback('0' + maxnum[index[j]]);
                dp[i] = mymax(dp[i], tmp);
            }
            if(i - index[j] >= 0 && dp[i - index[j]].size() > 0){
                string tmp = dp[i - index[j]];

                tmp.pback('0' + maxnum[index[j]]);
                sort(ALL(tmp));
                reverse(ALL(tmp));

                dp[i] = mymax(dp[i], tmp);
            }
        }

    }

    if(false){
        rep(i, n + 1){
            cerr << dp[i] << " ";
        }
        cerr << endl;
    }

    cout << dp[n] << endl;
    
    return 0;
}

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

using namespace std;

int main(){
    long long ans = 1e18;
    long long w,h;
    cin>>w>>h;
    for(long long i=1;i<=h;i++){
        long long a = 1LL*w*i;
        long long b = 1LL*((h-i)/2)*w;
        long long c = 1LL*w*h-(a+b);
        ans = min(ans,max(a,max(b,c))-min(a,min(b,c)));
    }
    
    for(long long i=1;i<=h;i++){
        long long a = 1LL*w*i;
        long long b = 1LL*((h-i))*(w/2);
        long long c = 1LL*w*h-(a+b);
        ans = min(ans,max(a,max(b,c))-min(a,min(b,c)));
    }
    swap(h,w);
    for(long long i=1;i<=h;i++){
        long long a = 1LL*w*i;
        long long b = 1LL*((h-i)/2)*w;
        long long c = 1LL*w*h-(a+b);
        ans = min(ans,max(a,max(b,c))-min(a,min(b,c)));
    }
    
    for(long long i=1;i<=h;i++){
        long long a = 1LL*w*i;
        long long b = 1LL*((h-i))*(w/2);
        long long c = 1LL*w*h-(a+b);
        ans = min(ans,max(a,max(b,c))-min(a,min(b,c)));
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
MAX_N = int(1e5) + 1
cnts = [0 for i in range(MAX_N)]
for a in A:
  cnts[a] += 1
res = 0
for idx in range(1, len(cnts) + 1):
  tmp = sum(cnts[idx-1:idx+2])
  if tmp > res:
    res = tmp
print(res)

Measured memory_bytes: 13964